Annotation of loncom/interface/loncommon.pm, revision 1.1114
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1114 ! raeburn 4: # $Id: loncommon.pm,v 1.1113 2013/01/21 02:12:51 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.909 raeburn 534: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 535: my $wintitle = 'Course_Browser';
1.931 raeburn 536: if ($crstype eq 'Community') {
1.932 raeburn 537: $wintitle = 'Community_Browser';
1.909 raeburn 538: }
1.876 raeburn 539: my $id_functions = &javascript_index_functions();
540: my $output = '
1.776 bisitz 541: <script type="text/javascript" language="JavaScript">
1.824 bisitz 542: // <![CDATA[
1.468 raeburn 543: var stdeditbrowser;'."\n";
1.876 raeburn 544:
545: $output .= <<"ENDSTDBRW";
1.909 raeburn 546: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 547: var url = '/adm/pickcourse?';
1.895 raeburn 548: var formid = getFormIdByName(formname);
1.876 raeburn 549: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 550: if (domainfilter != null) {
551: if (domainfilter != '') {
552: url += 'domainfilter='+domainfilter+'&';
553: }
554: }
1.91 www 555: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 556: '&cdomelement='+udom+
557: '&cnameelement='+desc;
1.468 raeburn 558: if (extra_element !=null && extra_element != '') {
1.594 raeburn 559: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 560: url += '&roleelement='+extra_element;
561: if (domainfilter == null || domainfilter == '') {
562: url += '&domainfilter='+extra_element;
563: }
1.234 raeburn 564: }
1.468 raeburn 565: else {
566: if (formname == 'portform') {
567: url += '&setroles='+extra_element;
1.800 raeburn 568: } else {
569: if (formname == 'rules') {
570: url += '&fixeddom='+extra_element;
571: }
1.468 raeburn 572: }
573: }
1.230 raeburn 574: }
1.909 raeburn 575: if (type != null && type != '') {
576: url += '&type='+type;
577: }
578: if (type_elem != null && type_elem != '') {
579: url += '&typeelement='+type_elem;
580: }
1.872 raeburn 581: if (formname == 'ccrs') {
582: var ownername = document.forms[formid].ccuname.value;
583: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
584: url += '&cloner='+ownername+':'+ownerdom;
585: }
1.293 raeburn 586: if (multflag !=null && multflag != '') {
587: url += '&multiple='+multflag;
588: }
1.909 raeburn 589: var title = '$wintitle';
1.91 www 590: var options = 'scrollbars=1,resizable=1,menubar=0';
591: options += ',width=700,height=600';
592: stdeditbrowser = open(url,title,options,'1');
593: stdeditbrowser.focus();
594: }
1.876 raeburn 595: $id_functions
596: ENDSTDBRW
1.905 raeburn 597: if (($sec_element ne '') || ($role_element ne '')) {
598: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 599: }
600: $output .= '
601: // ]]>
602: </script>';
603: return $output;
604: }
605:
606: sub javascript_index_functions {
607: return <<"ENDJS";
608:
609: function getFormIdByName(formname) {
610: for (var i=0;i<document.forms.length;i++) {
611: if (document.forms[i].name == formname) {
612: return i;
613: }
614: }
615: return -1;
616: }
617:
618: function getIndexByName(formid,item) {
619: for (var i=0;i<document.forms[formid].elements.length;i++) {
620: if (document.forms[formid].elements[i].name == item) {
621: return i;
622: }
623: }
624: return -1;
625: }
1.468 raeburn 626:
1.876 raeburn 627: function getDomainFromSelectbox(formname,udom) {
628: var userdom;
629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
631: var domid = getIndexByName(formid,udom);
632: if (domid > -1) {
633: if (document.forms[formid].elements[domid].type == 'select-one') {
634: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
635: }
636: if (document.forms[formid].elements[domid].type == 'hidden') {
637: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 638: }
639: }
640: }
1.876 raeburn 641: return userdom;
642: }
643:
644: ENDJS
1.468 raeburn 645:
1.876 raeburn 646: }
647:
1.1017 raeburn 648: sub javascript_array_indexof {
1.1018 raeburn 649: return <<ENDJS;
1.1017 raeburn 650: <script type="text/javascript" language="JavaScript">
651: // <![CDATA[
652:
653: if (!Array.prototype.indexOf) {
654: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
655: "use strict";
656: if (this === void 0 || this === null) {
657: throw new TypeError();
658: }
659: var t = Object(this);
660: var len = t.length >>> 0;
661: if (len === 0) {
662: return -1;
663: }
664: var n = 0;
665: if (arguments.length > 0) {
666: n = Number(arguments[1]);
1.1088 foxr 667: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 668: n = 0;
669: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
670: n = (n > 0 || -1) * Math.floor(Math.abs(n));
671: }
672: }
673: if (n >= len) {
674: return -1;
675: }
676: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
677: for (; k < len; k++) {
678: if (k in t && t[k] === searchElement) {
679: return k;
680: }
681: }
682: return -1;
683: }
684: }
685:
686: // ]]>
687: </script>
688:
689: ENDJS
690:
691: }
692:
1.876 raeburn 693: sub userbrowser_javascript {
694: my $id_functions = &javascript_index_functions();
695: return <<"ENDUSERBRW";
696:
1.888 raeburn 697: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 698: var url = '/adm/pickuser?';
699: var userdom = getDomainFromSelectbox(formname,udom);
700: if (userdom != null) {
701: if (userdom != '') {
702: url += 'srchdom='+userdom+'&';
703: }
704: }
705: url += 'form=' + formname + '&unameelement='+uname+
706: '&udomelement='+udom+
707: '&ulastelement='+ulast+
708: '&ufirstelement='+ufirst+
709: '&uemailelement='+uemail+
1.881 raeburn 710: '&hideudomelement='+hideudom+
711: '&coursedom='+crsdom;
1.888 raeburn 712: if ((caller != null) && (caller != undefined)) {
713: url += '&caller='+caller;
714: }
1.876 raeburn 715: var title = 'User_Browser';
716: var options = 'scrollbars=1,resizable=1,menubar=0';
717: options += ',width=700,height=600';
718: var stdeditbrowser = open(url,title,options,'1');
719: stdeditbrowser.focus();
720: }
721:
1.888 raeburn 722: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 723: var formid = getFormIdByName(formname);
724: if (formid > -1) {
1.888 raeburn 725: var unameid = getIndexByName(formid,uname);
1.876 raeburn 726: var domid = getIndexByName(formid,udom);
727: var hidedomid = getIndexByName(formid,origdom);
728: if (hidedomid > -1) {
729: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 730: var unameval = document.forms[formid].elements[unameid].value;
731: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
732: if (domid > -1) {
733: var slct = document.forms[formid].elements[domid];
734: if (slct.type == 'select-one') {
735: var i;
736: for (i=0;i<slct.length;i++) {
737: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
738: }
739: }
740: if (slct.type == 'hidden') {
741: slct.value = fixeddom;
1.876 raeburn 742: }
743: }
1.468 raeburn 744: }
745: }
746: }
1.876 raeburn 747: return;
748: }
749:
750: $id_functions
751: ENDUSERBRW
1.468 raeburn 752: }
753:
754: sub setsec_javascript {
1.905 raeburn 755: my ($sec_element,$formname,$role_element) = @_;
756: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
757: $communityrolestr);
758: if ($role_element ne '') {
759: my @allroles = ('st','ta','ep','in','ad');
760: foreach my $crstype ('Course','Community') {
761: if ($crstype eq 'Community') {
762: foreach my $role (@allroles) {
763: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
764: }
765: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
766: } else {
767: foreach my $role (@allroles) {
768: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
769: }
770: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
771: }
772: }
773: $rolestr = '"'.join('","',@allroles).'"';
774: $courserolestr = '"'.join('","',@courserolenames).'"';
775: $communityrolestr = '"'.join('","',@communityrolenames).'"';
776: }
1.468 raeburn 777: my $setsections = qq|
778: function setSect(sectionlist) {
1.629 raeburn 779: var sectionsArray = new Array();
780: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
781: sectionsArray = sectionlist.split(",");
782: }
1.468 raeburn 783: var numSections = sectionsArray.length;
784: document.$formname.$sec_element.length = 0;
785: if (numSections == 0) {
786: document.$formname.$sec_element.multiple=false;
787: document.$formname.$sec_element.size=1;
788: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
789: } else {
790: if (numSections == 1) {
791: document.$formname.$sec_element.multiple=false;
792: document.$formname.$sec_element.size=1;
793: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
794: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
795: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
796: } else {
797: for (var i=0; i<numSections; i++) {
798: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
799: }
800: document.$formname.$sec_element.multiple=true
801: if (numSections < 3) {
802: document.$formname.$sec_element.size=numSections;
803: } else {
804: document.$formname.$sec_element.size=3;
805: }
806: document.$formname.$sec_element.options[0].selected = false
807: }
808: }
1.91 www 809: }
1.905 raeburn 810:
811: function setRole(crstype) {
1.468 raeburn 812: |;
1.905 raeburn 813: if ($role_element eq '') {
814: $setsections .= ' return;
815: }
816: ';
817: } else {
818: $setsections .= qq|
819: var elementLength = document.$formname.$role_element.length;
820: var allroles = Array($rolestr);
821: var courserolenames = Array($courserolestr);
822: var communityrolenames = Array($communityrolestr);
823: if (elementLength != undefined) {
824: if (document.$formname.$role_element.options[5].value == 'cc') {
825: if (crstype == 'Course') {
826: return;
827: } else {
828: allroles[5] = 'co';
829: for (var i=0; i<6; i++) {
830: document.$formname.$role_element.options[i].value = allroles[i];
831: document.$formname.$role_element.options[i].text = communityrolenames[i];
832: }
833: }
834: } else {
835: if (crstype == 'Community') {
836: return;
837: } else {
838: allroles[5] = 'cc';
839: for (var i=0; i<6; i++) {
840: document.$formname.$role_element.options[i].value = allroles[i];
841: document.$formname.$role_element.options[i].text = courserolenames[i];
842: }
843: }
844: }
845: }
846: return;
847: }
848: |;
849: }
1.468 raeburn 850: return $setsections;
851: }
852:
1.91 www 853: sub selectcourse_link {
1.909 raeburn 854: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
855: $typeelement) = @_;
856: my $type = $selecttype;
1.871 raeburn 857: my $linktext = &mt('Select Course');
858: if ($selecttype eq 'Community') {
1.909 raeburn 859: $linktext = &mt('Select Community');
1.906 raeburn 860: } elsif ($selecttype eq 'Course/Community') {
861: $linktext = &mt('Select Course/Community');
1.909 raeburn 862: $type = '';
1.1019 raeburn 863: } elsif ($selecttype eq 'Select') {
864: $linktext = &mt('Select');
865: $type = '';
1.871 raeburn 866: }
1.787 bisitz 867: return '<span class="LC_nobreak">'
868: ."<a href='"
869: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
870: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 871: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 872: ."'>".$linktext.'</a>'
1.787 bisitz 873: .'</span>';
1.74 www 874: }
1.42 matthew 875:
1.653 raeburn 876: sub selectauthor_link {
877: my ($form,$udom)=@_;
878: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
879: &mt('Select Author').'</a>';
880: }
881:
1.876 raeburn 882: sub selectuser_link {
1.881 raeburn 883: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 884: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 885: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 886: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 887: ');">'.$linktext.'</a>';
1.876 raeburn 888: }
889:
1.273 raeburn 890: sub check_uncheck_jscript {
891: my $jscript = <<"ENDSCRT";
892: function checkAll(field) {
893: if (field.length > 0) {
894: for (i = 0; i < field.length; i++) {
1.1093 raeburn 895: if (!field[i].disabled) {
896: field[i].checked = true;
897: }
1.273 raeburn 898: }
899: } else {
1.1093 raeburn 900: if (!field.disabled) {
901: field.checked = true;
902: }
1.273 raeburn 903: }
904: }
905:
906: function uncheckAll(field) {
907: if (field.length > 0) {
908: for (i = 0; i < field.length; i++) {
909: field[i].checked = false ;
1.543 albertel 910: }
911: } else {
1.273 raeburn 912: field.checked = false ;
913: }
914: }
915: ENDSCRT
916: return $jscript;
917: }
918:
1.656 www 919: sub select_timezone {
1.659 raeburn 920: my ($name,$selected,$onchange,$includeempty)=@_;
921: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
922: if ($includeempty) {
923: $output .= '<option value=""';
924: if (($selected eq '') || ($selected eq 'local')) {
925: $output .= ' selected="selected" ';
926: }
927: $output .= '> </option>';
928: }
1.657 raeburn 929: my @timezones = DateTime::TimeZone->all_names;
930: foreach my $tzone (@timezones) {
931: $output.= '<option value="'.$tzone.'"';
932: if ($tzone eq $selected) {
933: $output.=' selected="selected"';
934: }
935: $output.=">$tzone</option>\n";
1.656 www 936: }
937: $output.="</select>";
938: return $output;
939: }
1.273 raeburn 940:
1.687 raeburn 941: sub select_datelocale {
942: my ($name,$selected,$onchange,$includeempty)=@_;
943: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
944: if ($includeempty) {
945: $output .= '<option value=""';
946: if ($selected eq '') {
947: $output .= ' selected="selected" ';
948: }
949: $output .= '> </option>';
950: }
951: my (@possibles,%locale_names);
952: my @locales = DateTime::Locale::Catalog::Locales;
953: foreach my $locale (@locales) {
954: if (ref($locale) eq 'HASH') {
955: my $id = $locale->{'id'};
956: if ($id ne '') {
957: my $en_terr = $locale->{'en_territory'};
958: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 959: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 960: if (grep(/^en$/,@languages) || !@languages) {
961: if ($en_terr ne '') {
962: $locale_names{$id} = '('.$en_terr.')';
963: } elsif ($native_terr ne '') {
964: $locale_names{$id} = $native_terr;
965: }
966: } else {
967: if ($native_terr ne '') {
968: $locale_names{$id} = $native_terr.' ';
969: } elsif ($en_terr ne '') {
970: $locale_names{$id} = '('.$en_terr.')';
971: }
972: }
973: push (@possibles,$id);
974: }
975: }
976: }
977: foreach my $item (sort(@possibles)) {
978: $output.= '<option value="'.$item.'"';
979: if ($item eq $selected) {
980: $output.=' selected="selected"';
981: }
982: $output.=">$item";
983: if ($locale_names{$item} ne '') {
984: $output.=" $locale_names{$item}</option>\n";
985: }
986: $output.="</option>\n";
987: }
988: $output.="</select>";
989: return $output;
990: }
991:
1.792 raeburn 992: sub select_language {
993: my ($name,$selected,$includeempty) = @_;
994: my %langchoices;
995: if ($includeempty) {
1.1112 bisitz 996: %langchoices = ('' => &mt('No language preference'));
1.792 raeburn 997: }
998: foreach my $id (&languageids()) {
999: my $code = &supportedlanguagecode($id);
1000: if ($code) {
1001: $langchoices{$code} = &plainlanguagedescription($id);
1002: }
1003: }
1.970 raeburn 1004: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1005: }
1006:
1.42 matthew 1007: =pod
1.36 matthew 1008:
1.1088 foxr 1009:
1010: =item * &list_languages()
1011:
1012: Returns an array reference that is suitable for use in language prompters.
1013: Each array element is itself a two element array. The first element
1014: is the language code. The second element a descsriptiuon of the
1015: language itself. This is suitable for use in e.g.
1016: &Apache::edit::select_arg (once dereferenced that is).
1017:
1018: =cut
1019:
1020: sub list_languages {
1021: my @lang_choices;
1022:
1023: foreach my $id (&languageids()) {
1024: my $code = &supportedlanguagecode($id);
1025: if ($code) {
1026: my $selector = $supported_codes{$id};
1027: my $description = &plainlanguagedescription($id);
1028: push (@lang_choices, [$selector, $description]);
1029: }
1030: }
1031: return \@lang_choices;
1032: }
1033:
1034: =pod
1035:
1.648 raeburn 1036: =item * &linked_select_forms(...)
1.36 matthew 1037:
1038: linked_select_forms returns a string containing a <script></script> block
1039: and html for two <select> menus. The select menus will be linked in that
1040: changing the value of the first menu will result in new values being placed
1041: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1042: order unless a defined order is provided.
1.36 matthew 1043:
1044: linked_select_forms takes the following ordered inputs:
1045:
1046: =over 4
1047:
1.112 bowersj2 1048: =item * $formname, the name of the <form> tag
1.36 matthew 1049:
1.112 bowersj2 1050: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1051:
1.112 bowersj2 1052: =item * $firstdefault, the default value for the first menu
1.36 matthew 1053:
1.112 bowersj2 1054: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1055:
1.112 bowersj2 1056: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1057:
1.112 bowersj2 1058: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1059:
1.609 raeburn 1060: =item * $menuorder, the order of values in the first menu
1061:
1.41 ng 1062: =back
1063:
1.36 matthew 1064: Below is an example of such a hash. Only the 'text', 'default', and
1065: 'select2' keys must appear as stated. keys(%menu) are the possible
1066: values for the first select menu. The text that coincides with the
1.41 ng 1067: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1068: and text for the second menu are given in the hash pointed to by
1069: $menu{$choice1}->{'select2'}.
1070:
1.112 bowersj2 1071: my %menu = ( A1 => { text =>"Choice A1" ,
1072: default => "B3",
1073: select2 => {
1074: B1 => "Choice B1",
1075: B2 => "Choice B2",
1076: B3 => "Choice B3",
1077: B4 => "Choice B4"
1.609 raeburn 1078: },
1079: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1080: },
1081: A2 => { text =>"Choice A2" ,
1082: default => "C2",
1083: select2 => {
1084: C1 => "Choice C1",
1085: C2 => "Choice C2",
1086: C3 => "Choice C3"
1.609 raeburn 1087: },
1088: order => ['C2','C1','C3'],
1.112 bowersj2 1089: },
1090: A3 => { text =>"Choice A3" ,
1091: default => "D6",
1092: select2 => {
1093: D1 => "Choice D1",
1094: D2 => "Choice D2",
1095: D3 => "Choice D3",
1096: D4 => "Choice D4",
1097: D5 => "Choice D5",
1098: D6 => "Choice D6",
1099: D7 => "Choice D7"
1.609 raeburn 1100: },
1101: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1102: }
1103: );
1.36 matthew 1104:
1105: =cut
1106:
1107: sub linked_select_forms {
1108: my ($formname,
1109: $middletext,
1110: $firstdefault,
1111: $firstselectname,
1112: $secondselectname,
1.609 raeburn 1113: $hashref,
1114: $menuorder,
1.36 matthew 1115: ) = @_;
1116: my $second = "document.$formname.$secondselectname";
1117: my $first = "document.$formname.$firstselectname";
1118: # output the javascript to do the changing
1119: my $result = '';
1.776 bisitz 1120: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1121: $result.="// <![CDATA[\n";
1.36 matthew 1122: $result.="var select2data = new Object();\n";
1123: $" = '","';
1124: my $debug = '';
1125: foreach my $s1 (sort(keys(%$hashref))) {
1126: $result.="select2data.d_$s1 = new Object();\n";
1127: $result.="select2data.d_$s1.def = new String('".
1128: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1129: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1130: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1131: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1132: @s2values = @{$hashref->{$s1}->{'order'}};
1133: }
1.36 matthew 1134: $result.="\"@s2values\");\n";
1135: $result.="select2data.d_$s1.texts = new Array(";
1136: my @s2texts;
1137: foreach my $value (@s2values) {
1138: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1139: }
1140: $result.="\"@s2texts\");\n";
1141: }
1142: $"=' ';
1143: $result.= <<"END";
1144:
1145: function select1_changed() {
1146: // Determine new choice
1147: var newvalue = "d_" + $first.value;
1148: // update select2
1149: var values = select2data[newvalue].values;
1150: var texts = select2data[newvalue].texts;
1151: var select2def = select2data[newvalue].def;
1152: var i;
1153: // out with the old
1154: for (i = 0; i < $second.options.length; i++) {
1155: $second.options[i] = null;
1156: }
1157: // in with the nuclear
1158: for (i=0;i<values.length; i++) {
1159: $second.options[i] = new Option(values[i]);
1.143 matthew 1160: $second.options[i].value = values[i];
1.36 matthew 1161: $second.options[i].text = texts[i];
1162: if (values[i] == select2def) {
1163: $second.options[i].selected = true;
1164: }
1165: }
1166: }
1.824 bisitz 1167: // ]]>
1.36 matthew 1168: </script>
1169: END
1170: # output the initial values for the selection lists
1171: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1172: my @order = sort(keys(%{$hashref}));
1173: if (ref($menuorder) eq 'ARRAY') {
1174: @order = @{$menuorder};
1175: }
1176: foreach my $value (@order) {
1.36 matthew 1177: $result.=" <option value=\"$value\" ";
1.253 albertel 1178: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1179: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1180: }
1181: $result .= "</select>\n";
1182: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1183: $result .= $middletext;
1184: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1185: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1186:
1187: my @secondorder = sort(keys(%select2));
1188: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1189: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1190: }
1191: foreach my $value (@secondorder) {
1.36 matthew 1192: $result.=" <option value=\"$value\" ";
1.253 albertel 1193: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1194: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1195: }
1196: $result .= "</select>\n";
1197: # return $debug;
1198: return $result;
1199: } # end of sub linked_select_forms {
1200:
1.45 matthew 1201: =pod
1.44 bowersj2 1202:
1.973 raeburn 1203: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1204:
1.112 bowersj2 1205: Returns a string corresponding to an HTML link to the given help
1206: $topic, where $topic corresponds to the name of a .tex file in
1207: /home/httpd/html/adm/help/tex, with underscores replaced by
1208: spaces.
1209:
1210: $text will optionally be linked to the same topic, allowing you to
1211: link text in addition to the graphic. If you do not want to link
1212: text, but wish to specify one of the later parameters, pass an
1213: empty string.
1214:
1215: $stayOnPage is a value that will be interpreted as a boolean. If true,
1216: the link will not open a new window. If false, the link will open
1217: a new window using Javascript. (Default is false.)
1218:
1219: $width and $height are optional numerical parameters that will
1220: override the width and height of the popped up window, which may
1.973 raeburn 1221: be useful for certain help topics with big pictures included.
1222:
1223: $imgid is the id of the img tag used for the help icon. This may be
1224: used in a javascript call to switch the image src. See
1225: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1226:
1227: =cut
1228:
1229: sub help_open_topic {
1.973 raeburn 1230: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1231: $text = "" if (not defined $text);
1.44 bowersj2 1232: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1233: $width = 500 if (not defined $width);
1.44 bowersj2 1234: $height = 400 if (not defined $height);
1235: my $filename = $topic;
1236: $filename =~ s/ /_/g;
1237:
1.48 bowersj2 1238: my $template = "";
1239: my $link;
1.572 banghart 1240:
1.159 www 1241: $topic=~s/\W/\_/g;
1.44 bowersj2 1242:
1.572 banghart 1243: if (!$stayOnPage) {
1.1033 www 1244: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1245: } elsif ($stayOnPage eq 'popup') {
1246: $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 1247: } else {
1.48 bowersj2 1248: $link = "/adm/help/${filename}.hlp";
1249: }
1250:
1251: # Add the text
1.755 neumanie 1252: if ($text ne "") {
1.763 bisitz 1253: $template.='<span class="LC_help_open_topic">'
1254: .'<a target="_top" href="'.$link.'">'
1255: .$text.'</a>';
1.48 bowersj2 1256: }
1257:
1.763 bisitz 1258: # (Always) Add the graphic
1.179 matthew 1259: my $title = &mt('Online Help');
1.667 raeburn 1260: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1261: if ($imgid ne '') {
1262: $imgid = ' id="'.$imgid.'"';
1263: }
1.763 bisitz 1264: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1265: .'<img src="'.$helpicon.'" border="0"'
1266: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1267: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1268: .' /></a>';
1269: if ($text ne "") {
1270: $template.='</span>';
1271: }
1.44 bowersj2 1272: return $template;
1273:
1.106 bowersj2 1274: }
1275:
1276: # This is a quicky function for Latex cheatsheet editing, since it
1277: # appears in at least four places
1278: sub helpLatexCheatsheet {
1.1037 www 1279: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1280: my $out;
1.106 bowersj2 1281: my $addOther = '';
1.732 raeburn 1282: if ($topic) {
1.1037 www 1283: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1284: }
1285: $out = '<span>' # Start cheatsheet
1286: .$addOther
1287: .'<span>'
1.1037 www 1288: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1289: .'</span> <span>'
1.1037 www 1290: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1291: .'</span>';
1.732 raeburn 1292: unless ($not_author) {
1.763 bisitz 1293: $out .= ' <span>'
1.1037 www 1294: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1295: .'</span>';
1.732 raeburn 1296: }
1.763 bisitz 1297: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1298: return $out;
1.172 www 1299: }
1300:
1.430 albertel 1301: sub general_help {
1302: my $helptopic='Student_Intro';
1303: if ($env{'request.role'}=~/^(ca|au)/) {
1304: $helptopic='Authoring_Intro';
1.907 raeburn 1305: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1306: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1307: } elsif ($env{'request.role'}=~/^dc/) {
1308: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1309: }
1310: return $helptopic;
1311: }
1312:
1313: sub update_help_link {
1314: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1315: my $origurl = $ENV{'REQUEST_URI'};
1316: $origurl=~s|^/~|/priv/|;
1317: my $timestamp = time;
1318: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1319: $$datum = &escape($$datum);
1320: }
1321:
1322: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1323: my $output .= <<"ENDOUTPUT";
1324: <script type="text/javascript">
1.824 bisitz 1325: // <![CDATA[
1.430 albertel 1326: banner_link = '$banner_link';
1.824 bisitz 1327: // ]]>
1.430 albertel 1328: </script>
1329: ENDOUTPUT
1330: return $output;
1331: }
1332:
1333: # now just updates the help link and generates a blue icon
1.193 raeburn 1334: sub help_open_menu {
1.430 albertel 1335: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1336: = @_;
1.949 droeschl 1337: $stayOnPage = 1;
1.430 albertel 1338: my $output;
1339: if ($component_help) {
1340: if (!$text) {
1341: $output=&help_open_topic($component_help,undef,$stayOnPage,
1342: $width,$height);
1343: } else {
1344: my $help_text;
1345: $help_text=&unescape($topic);
1346: $output='<table><tr><td>'.
1347: &help_open_topic($component_help,$help_text,$stayOnPage,
1348: $width,$height).'</td></tr></table>';
1349: }
1350: }
1351: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1352: return $output.$banner_link;
1353: }
1354:
1355: sub top_nav_help {
1356: my ($text) = @_;
1.436 albertel 1357: $text = &mt($text);
1.949 droeschl 1358: my $stay_on_page = 1;
1359:
1.572 banghart 1360: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1361: : "javascript:helpMenu('open')";
1.572 banghart 1362: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1363:
1.201 raeburn 1364: my $title = &mt('Get help');
1.436 albertel 1365:
1366: return <<"END";
1367: $banner_link
1368: <a href="$link" title="$title">$text</a>
1369: END
1370: }
1371:
1372: sub help_menu_js {
1373: my ($text) = @_;
1.949 droeschl 1374: my $stayOnPage = 1;
1.436 albertel 1375: my $width = 620;
1376: my $height = 600;
1.430 albertel 1377: my $helptopic=&general_help();
1378: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1379: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1380: my $start_page =
1381: &Apache::loncommon::start_page('Help Menu', undef,
1382: {'frameset' => 1,
1383: 'js_ready' => 1,
1384: 'add_entries' => {
1385: 'border' => '0',
1.579 raeburn 1386: 'rows' => "110,*",},});
1.331 albertel 1387: my $end_page =
1388: &Apache::loncommon::end_page({'frameset' => 1,
1389: 'js_ready' => 1,});
1390:
1.436 albertel 1391: my $template .= <<"ENDTEMPLATE";
1392: <script type="text/javascript">
1.877 bisitz 1393: // <![CDATA[
1.253 albertel 1394: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1395: var banner_link = '';
1.243 raeburn 1396: function helpMenu(target) {
1397: var caller = this;
1398: if (target == 'open') {
1399: var newWindow = null;
1400: try {
1.262 albertel 1401: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1402: }
1403: catch(error) {
1404: writeHelp(caller);
1405: return;
1406: }
1407: if (newWindow) {
1408: caller = newWindow;
1409: }
1.193 raeburn 1410: }
1.243 raeburn 1411: writeHelp(caller);
1412: return;
1413: }
1414: function writeHelp(caller) {
1.1072 raeburn 1415: 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 1416: caller.document.close()
1417: caller.focus()
1.193 raeburn 1418: }
1.877 bisitz 1419: // END LON-CAPA Internal -->
1.253 albertel 1420: // ]]>
1.436 albertel 1421: </script>
1.193 raeburn 1422: ENDTEMPLATE
1423: return $template;
1424: }
1425:
1.172 www 1426: sub help_open_bug {
1427: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1428: unless ($env{'user.adv'}) { return ''; }
1.172 www 1429: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1430: $text = "" if (not defined $text);
1431: $stayOnPage=1;
1.184 albertel 1432: $width = 600 if (not defined $width);
1433: $height = 600 if (not defined $height);
1.172 www 1434:
1435: $topic=~s/\W+/\+/g;
1436: my $link='';
1437: my $template='';
1.379 albertel 1438: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1439: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1440: if (!$stayOnPage)
1441: {
1442: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1443: }
1444: else
1445: {
1446: $link = $url;
1447: }
1448: # Add the text
1449: if ($text ne "")
1450: {
1451: $template .=
1452: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1453: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1454: }
1455:
1456: # Add the graphic
1.179 matthew 1457: my $title = &mt('Report a Bug');
1.215 albertel 1458: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1459: $template .= <<"ENDTEMPLATE";
1.436 albertel 1460: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1461: ENDTEMPLATE
1462: if ($text ne '') { $template.='</td></tr></table>' };
1463: return $template;
1464:
1465: }
1466:
1467: sub help_open_faq {
1468: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1469: unless ($env{'user.adv'}) { return ''; }
1.172 www 1470: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1471: $text = "" if (not defined $text);
1472: $stayOnPage=1;
1473: $width = 350 if (not defined $width);
1474: $height = 400 if (not defined $height);
1475:
1476: $topic=~s/\W+/\+/g;
1477: my $link='';
1478: my $template='';
1479: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1480: if (!$stayOnPage)
1481: {
1482: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1483: }
1484: else
1485: {
1486: $link = $url;
1487: }
1488:
1489: # Add the text
1490: if ($text ne "")
1491: {
1492: $template .=
1.173 www 1493: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1494: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1495: }
1496:
1497: # Add the graphic
1.179 matthew 1498: my $title = &mt('View the FAQ');
1.215 albertel 1499: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1500: $template .= <<"ENDTEMPLATE";
1.436 albertel 1501: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1502: ENDTEMPLATE
1503: if ($text ne '') { $template.='</td></tr></table>' };
1504: return $template;
1505:
1.44 bowersj2 1506: }
1.37 matthew 1507:
1.180 matthew 1508: ###############################################################
1509: ###############################################################
1510:
1.45 matthew 1511: =pod
1512:
1.648 raeburn 1513: =item * &change_content_javascript():
1.256 matthew 1514:
1515: This and the next function allow you to create small sections of an
1516: otherwise static HTML page that you can update on the fly with
1517: Javascript, even in Netscape 4.
1518:
1519: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1520: must be written to the HTML page once. It will prove the Javascript
1521: function "change(name, content)". Calling the change function with the
1522: name of the section
1523: you want to update, matching the name passed to C<changable_area>, and
1524: the new content you want to put in there, will put the content into
1525: that area.
1526:
1527: B<Note>: Netscape 4 only reserves enough space for the changable area
1528: to contain room for the original contents. You need to "make space"
1529: for whatever changes you wish to make, and be B<sure> to check your
1530: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1531: it's adequate for updating a one-line status display, but little more.
1532: This script will set the space to 100% width, so you only need to
1533: worry about height in Netscape 4.
1534:
1535: Modern browsers are much less limiting, and if you can commit to the
1536: user not using Netscape 4, this feature may be used freely with
1537: pretty much any HTML.
1538:
1539: =cut
1540:
1541: sub change_content_javascript {
1542: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1543: if ($env{'browser.type'} eq 'netscape' &&
1544: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1545: return (<<NETSCAPE4);
1546: function change(name, content) {
1547: doc = document.layers[name+"___escape"].layers[0].document;
1548: doc.open();
1549: doc.write(content);
1550: doc.close();
1551: }
1552: NETSCAPE4
1553: } else {
1554: # Otherwise, we need to use semi-standards-compliant code
1555: # (technically, "innerHTML" isn't standard but the equivalent
1556: # is really scary, and every useful browser supports it
1557: return (<<DOMBASED);
1558: function change(name, content) {
1559: element = document.getElementById(name);
1560: element.innerHTML = content;
1561: }
1562: DOMBASED
1563: }
1564: }
1565:
1566: =pod
1567:
1.648 raeburn 1568: =item * &changable_area($name,$origContent):
1.256 matthew 1569:
1570: This provides a "changable area" that can be modified on the fly via
1571: the Javascript code provided in C<change_content_javascript>. $name is
1572: the name you will use to reference the area later; do not repeat the
1573: same name on a given HTML page more then once. $origContent is what
1574: the area will originally contain, which can be left blank.
1575:
1576: =cut
1577:
1578: sub changable_area {
1579: my ($name, $origContent) = @_;
1580:
1.258 albertel 1581: if ($env{'browser.type'} eq 'netscape' &&
1582: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1583: # If this is netscape 4, we need to use the Layer tag
1584: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1585: } else {
1586: return "<span id='$name'>$origContent</span>";
1587: }
1588: }
1589:
1590: =pod
1591:
1.648 raeburn 1592: =item * &viewport_geometry_js
1.590 raeburn 1593:
1594: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1595:
1596: =cut
1597:
1598:
1599: sub viewport_geometry_js {
1600: return <<"GEOMETRY";
1601: var Geometry = {};
1602: function init_geometry() {
1603: if (Geometry.init) { return };
1604: Geometry.init=1;
1605: if (window.innerHeight) {
1606: Geometry.getViewportHeight = function() { return window.innerHeight; };
1607: Geometry.getViewportWidth = function() { return window.innerWidth; };
1608: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1609: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1610: }
1611: else if (document.documentElement && document.documentElement.clientHeight) {
1612: Geometry.getViewportHeight =
1613: function() { return document.documentElement.clientHeight; };
1614: Geometry.getViewportWidth =
1615: function() { return document.documentElement.clientWidth; };
1616:
1617: Geometry.getHorizontalScroll =
1618: function() { return document.documentElement.scrollLeft; };
1619: Geometry.getVerticalScroll =
1620: function() { return document.documentElement.scrollTop; };
1621: }
1622: else if (document.body.clientHeight) {
1623: Geometry.getViewportHeight =
1624: function() { return document.body.clientHeight; };
1625: Geometry.getViewportWidth =
1626: function() { return document.body.clientWidth; };
1627: Geometry.getHorizontalScroll =
1628: function() { return document.body.scrollLeft; };
1629: Geometry.getVerticalScroll =
1630: function() { return document.body.scrollTop; };
1631: }
1632: }
1633:
1634: GEOMETRY
1635: }
1636:
1637: =pod
1638:
1.648 raeburn 1639: =item * &viewport_size_js()
1.590 raeburn 1640:
1641: 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.
1642:
1643: =cut
1644:
1645: sub viewport_size_js {
1646: my $geometry = &viewport_geometry_js();
1647: return <<"DIMS";
1648:
1649: $geometry
1650:
1651: function getViewportDims(width,height) {
1652: init_geometry();
1653: width.value = Geometry.getViewportWidth();
1654: height.value = Geometry.getViewportHeight();
1655: return;
1656: }
1657:
1658: DIMS
1659: }
1660:
1661: =pod
1662:
1.648 raeburn 1663: =item * &resize_textarea_js()
1.565 albertel 1664:
1665: emits the needed javascript to resize a textarea to be as big as possible
1666:
1667: creates a function resize_textrea that takes two IDs first should be
1668: the id of the element to resize, second should be the id of a div that
1669: surrounds everything that comes after the textarea, this routine needs
1670: to be attached to the <body> for the onload and onresize events.
1671:
1.648 raeburn 1672: =back
1.565 albertel 1673:
1674: =cut
1675:
1676: sub resize_textarea_js {
1.590 raeburn 1677: my $geometry = &viewport_geometry_js();
1.565 albertel 1678: return <<"RESIZE";
1679: <script type="text/javascript">
1.824 bisitz 1680: // <![CDATA[
1.590 raeburn 1681: $geometry
1.565 albertel 1682:
1.588 albertel 1683: function getX(element) {
1684: var x = 0;
1685: while (element) {
1686: x += element.offsetLeft;
1687: element = element.offsetParent;
1688: }
1689: return x;
1690: }
1691: function getY(element) {
1692: var y = 0;
1693: while (element) {
1694: y += element.offsetTop;
1695: element = element.offsetParent;
1696: }
1697: return y;
1698: }
1699:
1700:
1.565 albertel 1701: function resize_textarea(textarea_id,bottom_id) {
1702: init_geometry();
1703: var textarea = document.getElementById(textarea_id);
1704: //alert(textarea);
1705:
1.588 albertel 1706: var textarea_top = getY(textarea);
1.565 albertel 1707: var textarea_height = textarea.offsetHeight;
1708: var bottom = document.getElementById(bottom_id);
1.588 albertel 1709: var bottom_top = getY(bottom);
1.565 albertel 1710: var bottom_height = bottom.offsetHeight;
1711: var window_height = Geometry.getViewportHeight();
1.588 albertel 1712: var fudge = 23;
1.565 albertel 1713: var new_height = window_height-fudge-textarea_top-bottom_height;
1714: if (new_height < 300) {
1715: new_height = 300;
1716: }
1717: textarea.style.height=new_height+'px';
1718: }
1.824 bisitz 1719: // ]]>
1.565 albertel 1720: </script>
1721: RESIZE
1722:
1723: }
1724:
1725: =pod
1726:
1.256 matthew 1727: =head1 Excel and CSV file utility routines
1728:
1729: =over 4
1730:
1731: =cut
1732:
1733: ###############################################################
1734: ###############################################################
1735:
1736: =pod
1737:
1.648 raeburn 1738: =item * &csv_translate($text)
1.37 matthew 1739:
1.185 www 1740: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1741: format.
1742:
1743: =cut
1744:
1.180 matthew 1745: ###############################################################
1746: ###############################################################
1.37 matthew 1747: sub csv_translate {
1748: my $text = shift;
1749: $text =~ s/\"/\"\"/g;
1.209 albertel 1750: $text =~ s/\n/ /g;
1.37 matthew 1751: return $text;
1752: }
1.180 matthew 1753:
1754: ###############################################################
1755: ###############################################################
1756:
1757: =pod
1758:
1.648 raeburn 1759: =item * &define_excel_formats()
1.180 matthew 1760:
1761: Define some commonly used Excel cell formats.
1762:
1763: Currently supported formats:
1764:
1765: =over 4
1766:
1767: =item header
1768:
1769: =item bold
1770:
1771: =item h1
1772:
1773: =item h2
1774:
1775: =item h3
1776:
1.256 matthew 1777: =item h4
1778:
1779: =item i
1780:
1.180 matthew 1781: =item date
1782:
1783: =back
1784:
1785: Inputs: $workbook
1786:
1787: Returns: $format, a hash reference.
1788:
1.1057 foxr 1789:
1.180 matthew 1790: =cut
1791:
1792: ###############################################################
1793: ###############################################################
1794: sub define_excel_formats {
1795: my ($workbook) = @_;
1796: my $format;
1797: $format->{'header'} = $workbook->add_format(bold => 1,
1798: bottom => 1,
1799: align => 'center');
1800: $format->{'bold'} = $workbook->add_format(bold=>1);
1801: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1802: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1803: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1804: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1805: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1806: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1807: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1808: return $format;
1809: }
1810:
1811: ###############################################################
1812: ###############################################################
1.113 bowersj2 1813:
1814: =pod
1815:
1.648 raeburn 1816: =item * &create_workbook()
1.255 matthew 1817:
1818: Create an Excel worksheet. If it fails, output message on the
1819: request object and return undefs.
1820:
1821: Inputs: Apache request object
1822:
1823: Returns (undef) on failure,
1824: Excel worksheet object, scalar with filename, and formats
1825: from &Apache::loncommon::define_excel_formats on success
1826:
1827: =cut
1828:
1829: ###############################################################
1830: ###############################################################
1831: sub create_workbook {
1832: my ($r) = @_;
1833: #
1834: # Create the excel spreadsheet
1835: my $filename = '/prtspool/'.
1.258 albertel 1836: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1837: time.'_'.rand(1000000000).'.xls';
1838: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1839: if (! defined($workbook)) {
1840: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1841: $r->print(
1842: '<p class="LC_error">'
1843: .&mt('Problems occurred in creating the new Excel file.')
1844: .' '.&mt('This error has been logged.')
1845: .' '.&mt('Please alert your LON-CAPA administrator.')
1846: .'</p>'
1847: );
1.255 matthew 1848: return (undef);
1849: }
1850: #
1.1014 foxr 1851: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1852: #
1853: my $format = &Apache::loncommon::define_excel_formats($workbook);
1854: return ($workbook,$filename,$format);
1855: }
1856:
1857: ###############################################################
1858: ###############################################################
1859:
1860: =pod
1861:
1.648 raeburn 1862: =item * &create_text_file()
1.113 bowersj2 1863:
1.542 raeburn 1864: Create a file to write to and eventually make available to the user.
1.256 matthew 1865: If file creation fails, outputs an error message on the request object and
1866: return undefs.
1.113 bowersj2 1867:
1.256 matthew 1868: Inputs: Apache request object, and file suffix
1.113 bowersj2 1869:
1.256 matthew 1870: Returns (undef) on failure,
1871: Filehandle and filename on success.
1.113 bowersj2 1872:
1873: =cut
1874:
1.256 matthew 1875: ###############################################################
1876: ###############################################################
1877: sub create_text_file {
1878: my ($r,$suffix) = @_;
1879: if (! defined($suffix)) { $suffix = 'txt'; };
1880: my $fh;
1881: my $filename = '/prtspool/'.
1.258 albertel 1882: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1883: time.'_'.rand(1000000000).'.'.$suffix;
1884: $fh = Apache::File->new('>/home/httpd'.$filename);
1885: if (! defined($fh)) {
1886: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1887: $r->print(
1888: '<p class="LC_error">'
1889: .&mt('Problems occurred in creating the output file.')
1890: .' '.&mt('This error has been logged.')
1891: .' '.&mt('Please alert your LON-CAPA administrator.')
1892: .'</p>'
1893: );
1.113 bowersj2 1894: }
1.256 matthew 1895: return ($fh,$filename)
1.113 bowersj2 1896: }
1897:
1898:
1.256 matthew 1899: =pod
1.113 bowersj2 1900:
1901: =back
1902:
1903: =cut
1.37 matthew 1904:
1905: ###############################################################
1.33 matthew 1906: ## Home server <option> list generating code ##
1907: ###############################################################
1.35 matthew 1908:
1.169 www 1909: # ------------------------------------------
1910:
1911: sub domain_select {
1912: my ($name,$value,$multiple)=@_;
1913: my %domains=map {
1.514 albertel 1914: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1915: } &Apache::lonnet::all_domains();
1.169 www 1916: if ($multiple) {
1917: $domains{''}=&mt('Any domain');
1.550 albertel 1918: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1919: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1920: } else {
1.550 albertel 1921: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1922: return &select_form($name,$value,\%domains);
1.169 www 1923: }
1924: }
1925:
1.282 albertel 1926: #-------------------------------------------
1927:
1928: =pod
1929:
1.519 raeburn 1930: =head1 Routines for form select boxes
1931:
1932: =over 4
1933:
1.648 raeburn 1934: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1935:
1936: Returns a string containing a <select> element int multiple mode
1937:
1938:
1939: Args:
1940: $name - name of the <select> element
1.506 raeburn 1941: $value - scalar or array ref of values that should already be selected
1.282 albertel 1942: $size - number of rows long the select element is
1.283 albertel 1943: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1944: (shown text should already have been &mt())
1.506 raeburn 1945: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1946:
1.282 albertel 1947: =cut
1948:
1949: #-------------------------------------------
1.169 www 1950: sub multiple_select_form {
1.284 albertel 1951: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1952: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1953: my $output='';
1.191 matthew 1954: if (! defined($size)) {
1955: $size = 4;
1.283 albertel 1956: if (scalar(keys(%$hash))<4) {
1957: $size = scalar(keys(%$hash));
1.191 matthew 1958: }
1959: }
1.734 bisitz 1960: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1961: my @order;
1.506 raeburn 1962: if (ref($order) eq 'ARRAY') {
1963: @order = @{$order};
1964: } else {
1965: @order = sort(keys(%$hash));
1.501 banghart 1966: }
1967: if (exists($$hash{'select_form_order'})) {
1968: @order = @{$$hash{'select_form_order'}};
1969: }
1970:
1.284 albertel 1971: foreach my $key (@order) {
1.356 albertel 1972: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1973: $output.='selected="selected" ' if ($selected{$key});
1974: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1975: }
1976: $output.="</select>\n";
1977: return $output;
1978: }
1979:
1.88 www 1980: #-------------------------------------------
1981:
1982: =pod
1983:
1.970 raeburn 1984: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1985:
1986: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1987: allow a user to select options from a ref to a hash containing:
1988: option_name => displayed text. An optional $onchange can include
1989: a javascript onchange item, e.g., onchange="this.form.submit();"
1990:
1.88 www 1991: See lonrights.pm for an example invocation and use.
1992:
1993: =cut
1994:
1995: #-------------------------------------------
1996: sub select_form {
1.970 raeburn 1997: my ($def,$name,$hashref,$onchange) = @_;
1998: return unless (ref($hashref) eq 'HASH');
1999: if ($onchange) {
2000: $onchange = ' onchange="'.$onchange.'"';
2001: }
2002: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2003: my @keys;
1.970 raeburn 2004: if (exists($hashref->{'select_form_order'})) {
2005: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2006: } else {
1.970 raeburn 2007: @keys=sort(keys(%{$hashref}));
1.128 albertel 2008: }
1.356 albertel 2009: foreach my $key (@keys) {
2010: $selectform.=
2011: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2012: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2013: ">".$hashref->{$key}."</option>\n";
1.88 www 2014: }
2015: $selectform.="</select>";
2016: return $selectform;
2017: }
2018:
1.475 www 2019: # For display filters
2020:
2021: sub display_filter {
1.1074 raeburn 2022: my ($context) = @_;
1.475 www 2023: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2024: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2025: my $phraseinput = 'hidden';
2026: my $includeinput = 'hidden';
2027: my ($checked,$includetypestext);
2028: if ($env{'form.displayfilter'} eq 'containing') {
2029: $phraseinput = 'text';
2030: if ($context eq 'parmslog') {
2031: $includeinput = 'checkbox';
2032: if ($env{'form.includetypes'}) {
2033: $checked = ' checked="checked"';
2034: }
2035: $includetypestext = &mt('Include parameter types');
2036: }
2037: } else {
2038: $includetypestext = ' ';
2039: }
2040: my ($additional,$secondid,$thirdid);
2041: if ($context eq 'parmslog') {
2042: $additional =
2043: '<label><input type="'.$includeinput.'" name="includetypes"'.
2044: $checked.' name="includetypes" value="1" id="includetypes" />'.
2045: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2046: '</label>';
2047: $secondid = 'includetypes';
2048: $thirdid = 'includetypestext';
2049: }
2050: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2051: '$secondid','$thirdid')";
2052: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2053: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2054: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2055: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2056: &mt('Filter: [_1]',
1.477 www 2057: &select_form($env{'form.displayfilter'},
2058: 'displayfilter',
1.970 raeburn 2059: {'currentfolder' => 'Current folder/page',
1.477 www 2060: 'containing' => 'Containing phrase',
1.1074 raeburn 2061: 'none' => 'None'},$onchange)).' '.
2062: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2063: &HTML::Entities::encode($env{'form.containingphrase'}).
2064: '" />'.$additional;
2065: }
2066:
2067: sub display_filter_js {
2068: my $includetext = &mt('Include parameter types');
2069: return <<"ENDJS";
2070:
2071: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2072: var firstType = 'hidden';
2073: if (setter.options[setter.selectedIndex].value == 'containing') {
2074: firstType = 'text';
2075: }
2076: firstObject = document.getElementById(firstid);
2077: if (typeof(firstObject) == 'object') {
2078: if (firstObject.type != firstType) {
2079: changeInputType(firstObject,firstType);
2080: }
2081: }
2082: if (context == 'parmslog') {
2083: var secondType = 'hidden';
2084: if (firstType == 'text') {
2085: secondType = 'checkbox';
2086: }
2087: secondObject = document.getElementById(secondid);
2088: if (typeof(secondObject) == 'object') {
2089: if (secondObject.type != secondType) {
2090: changeInputType(secondObject,secondType);
2091: }
2092: }
2093: var textItem = document.getElementById(thirdid);
2094: var currtext = textItem.innerHTML;
2095: var newtext;
2096: if (firstType == 'text') {
2097: newtext = '$includetext';
2098: } else {
2099: newtext = ' ';
2100: }
2101: if (currtext != newtext) {
2102: textItem.innerHTML = newtext;
2103: }
2104: }
2105: return;
2106: }
2107:
2108: function changeInputType(oldObject,newType) {
2109: var newObject = document.createElement('input');
2110: newObject.type = newType;
2111: if (oldObject.size) {
2112: newObject.size = oldObject.size;
2113: }
2114: if (oldObject.value) {
2115: newObject.value = oldObject.value;
2116: }
2117: if (oldObject.name) {
2118: newObject.name = oldObject.name;
2119: }
2120: if (oldObject.id) {
2121: newObject.id = oldObject.id;
2122: }
2123: oldObject.parentNode.replaceChild(newObject,oldObject);
2124: return;
2125: }
2126:
2127: ENDJS
1.475 www 2128: }
2129:
1.167 www 2130: sub gradeleveldescription {
2131: my $gradelevel=shift;
2132: my %gradelevels=(0 => 'Not specified',
2133: 1 => 'Grade 1',
2134: 2 => 'Grade 2',
2135: 3 => 'Grade 3',
2136: 4 => 'Grade 4',
2137: 5 => 'Grade 5',
2138: 6 => 'Grade 6',
2139: 7 => 'Grade 7',
2140: 8 => 'Grade 8',
2141: 9 => 'Grade 9',
2142: 10 => 'Grade 10',
2143: 11 => 'Grade 11',
2144: 12 => 'Grade 12',
2145: 13 => 'Grade 13',
2146: 14 => '100 Level',
2147: 15 => '200 Level',
2148: 16 => '300 Level',
2149: 17 => '400 Level',
2150: 18 => 'Graduate Level');
2151: return &mt($gradelevels{$gradelevel});
2152: }
2153:
1.163 www 2154: sub select_level_form {
2155: my ($deflevel,$name)=@_;
2156: unless ($deflevel) { $deflevel=0; }
1.167 www 2157: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2158: for (my $i=0; $i<=18; $i++) {
2159: $selectform.="<option value=\"$i\" ".
1.253 albertel 2160: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2161: ">".&gradeleveldescription($i)."</option>\n";
2162: }
2163: $selectform.="</select>";
2164: return $selectform;
1.163 www 2165: }
1.167 www 2166:
1.35 matthew 2167: #-------------------------------------------
2168:
1.45 matthew 2169: =pod
2170:
1.910 raeburn 2171: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2172:
2173: Returns a string containing a <select name='$name' size='1'> form to
2174: allow a user to select the domain to preform an operation in.
2175: See loncreateuser.pm for an example invocation and use.
2176:
1.90 www 2177: If the $includeempty flag is set, it also includes an empty choice ("no domain
2178: selected");
2179:
1.743 raeburn 2180: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2181:
1.910 raeburn 2182: 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.
2183:
2184: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2185:
1.35 matthew 2186: =cut
2187:
2188: #-------------------------------------------
1.34 matthew 2189: sub select_dom_form {
1.910 raeburn 2190: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2191: if ($onchange) {
1.874 raeburn 2192: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2193: }
1.910 raeburn 2194: my @domains;
2195: if (ref($incdoms) eq 'ARRAY') {
2196: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2197: } else {
2198: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2199: }
1.90 www 2200: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2201: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2202: foreach my $dom (@domains) {
2203: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2204: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2205: if ($showdomdesc) {
2206: if ($dom ne '') {
2207: my $domdesc = &Apache::lonnet::domain($dom,'description');
2208: if ($domdesc ne '') {
2209: $selectdomain .= ' ('.$domdesc.')';
2210: }
2211: }
2212: }
2213: $selectdomain .= "</option>\n";
1.34 matthew 2214: }
2215: $selectdomain.="</select>";
2216: return $selectdomain;
2217: }
2218:
1.35 matthew 2219: #-------------------------------------------
2220:
1.45 matthew 2221: =pod
2222:
1.648 raeburn 2223: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2224:
1.586 raeburn 2225: input: 4 arguments (two required, two optional) -
2226: $domain - domain of new user
2227: $name - name of form element
2228: $default - Value of 'default' causes a default item to be first
2229: option, and selected by default.
2230: $hide - Value of 'hide' causes hiding of the name of the server,
2231: if 1 server found, or default, if 0 found.
1.594 raeburn 2232: output: returns 2 items:
1.586 raeburn 2233: (a) form element which contains either:
2234: (i) <select name="$name">
2235: <option value="$hostid1">$hostid $servers{$hostid}</option>
2236: <option value="$hostid2">$hostid $servers{$hostid}</option>
2237: </select>
2238: form item if there are multiple library servers in $domain, or
2239: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2240: if there is only one library server in $domain.
2241:
2242: (b) number of library servers found.
2243:
2244: See loncreateuser.pm for example of use.
1.35 matthew 2245:
2246: =cut
2247:
2248: #-------------------------------------------
1.586 raeburn 2249: sub home_server_form_item {
2250: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2251: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2252: my $result;
2253: my $numlib = keys(%servers);
2254: if ($numlib > 1) {
2255: $result .= '<select name="'.$name.'" />'."\n";
2256: if ($default) {
1.804 bisitz 2257: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2258: '</option>'."\n";
2259: }
2260: foreach my $hostid (sort(keys(%servers))) {
2261: $result.= '<option value="'.$hostid.'">'.
2262: $hostid.' '.$servers{$hostid}."</option>\n";
2263: }
2264: $result .= '</select>'."\n";
2265: } elsif ($numlib == 1) {
2266: my $hostid;
2267: foreach my $item (keys(%servers)) {
2268: $hostid = $item;
2269: }
2270: $result .= '<input type="hidden" name="'.$name.'" value="'.
2271: $hostid.'" />';
2272: if (!$hide) {
2273: $result .= $hostid.' '.$servers{$hostid};
2274: }
2275: $result .= "\n";
2276: } elsif ($default) {
2277: $result .= '<input type="hidden" name="'.$name.
2278: '" value="default" />';
2279: if (!$hide) {
2280: $result .= &mt('default');
2281: }
2282: $result .= "\n";
1.33 matthew 2283: }
1.586 raeburn 2284: return ($result,$numlib);
1.33 matthew 2285: }
1.112 bowersj2 2286:
2287: =pod
2288:
1.534 albertel 2289: =back
2290:
1.112 bowersj2 2291: =cut
1.87 matthew 2292:
2293: ###############################################################
1.112 bowersj2 2294: ## Decoding User Agent ##
1.87 matthew 2295: ###############################################################
2296:
2297: =pod
2298:
1.112 bowersj2 2299: =head1 Decoding the User Agent
2300:
2301: =over 4
2302:
2303: =item * &decode_user_agent()
1.87 matthew 2304:
2305: Inputs: $r
2306:
2307: Outputs:
2308:
2309: =over 4
2310:
1.112 bowersj2 2311: =item * $httpbrowser
1.87 matthew 2312:
1.112 bowersj2 2313: =item * $clientbrowser
1.87 matthew 2314:
1.112 bowersj2 2315: =item * $clientversion
1.87 matthew 2316:
1.112 bowersj2 2317: =item * $clientmathml
1.87 matthew 2318:
1.112 bowersj2 2319: =item * $clientunicode
1.87 matthew 2320:
1.112 bowersj2 2321: =item * $clientos
1.87 matthew 2322:
2323: =back
2324:
1.157 matthew 2325: =back
2326:
1.87 matthew 2327: =cut
2328:
2329: ###############################################################
2330: ###############################################################
2331: sub decode_user_agent {
1.247 albertel 2332: my ($r)=@_;
1.87 matthew 2333: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2334: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2335: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2336: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2337: my $clientbrowser='unknown';
2338: my $clientversion='0';
2339: my $clientmathml='';
2340: my $clientunicode='0';
2341: for (my $i=0;$i<=$#browsertype;$i++) {
2342: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2343: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2344: $clientbrowser=$bname;
2345: $httpbrowser=~/$vreg/i;
2346: $clientversion=$1;
2347: $clientmathml=($clientversion>=$minv);
2348: $clientunicode=($clientversion>=$univ);
2349: }
2350: }
2351: my $clientos='unknown';
2352: if (($httpbrowser=~/linux/i) ||
2353: ($httpbrowser=~/unix/i) ||
2354: ($httpbrowser=~/ux/i) ||
2355: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2356: if (($httpbrowser=~/vax/i) ||
2357: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2358: if ($httpbrowser=~/next/i) { $clientos='next'; }
2359: if (($httpbrowser=~/mac/i) ||
2360: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2361: if ($httpbrowser=~/win/i) { $clientos='win'; }
2362: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2363: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2364: $clientunicode,$clientos,);
2365: }
2366:
1.32 matthew 2367: ###############################################################
2368: ## Authentication changing form generation subroutines ##
2369: ###############################################################
2370: ##
2371: ## All of the authform_xxxxxxx subroutines take their inputs in a
2372: ## hash, and have reasonable default values.
2373: ##
2374: ## formname = the name given in the <form> tag.
1.35 matthew 2375: #-------------------------------------------
2376:
1.45 matthew 2377: =pod
2378:
1.112 bowersj2 2379: =head1 Authentication Routines
2380:
2381: =over 4
2382:
1.648 raeburn 2383: =item * &authform_xxxxxx()
1.35 matthew 2384:
2385: The authform_xxxxxx subroutines provide javascript and html forms which
2386: handle some of the conveniences required for authentication forms.
2387: This is not an optimal method, but it works.
2388:
2389: =over 4
2390:
1.112 bowersj2 2391: =item * authform_header
1.35 matthew 2392:
1.112 bowersj2 2393: =item * authform_authorwarning
1.35 matthew 2394:
1.112 bowersj2 2395: =item * authform_nochange
1.35 matthew 2396:
1.112 bowersj2 2397: =item * authform_kerberos
1.35 matthew 2398:
1.112 bowersj2 2399: =item * authform_internal
1.35 matthew 2400:
1.112 bowersj2 2401: =item * authform_filesystem
1.35 matthew 2402:
2403: =back
2404:
1.648 raeburn 2405: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2406:
1.35 matthew 2407: =cut
2408:
2409: #-------------------------------------------
1.32 matthew 2410: sub authform_header{
2411: my %in = (
2412: formname => 'cu',
1.80 albertel 2413: kerb_def_dom => '',
1.32 matthew 2414: @_,
2415: );
2416: $in{'formname'} = 'document.' . $in{'formname'};
2417: my $result='';
1.80 albertel 2418:
2419: #---------------------------------------------- Code for upper case translation
2420: my $Javascript_toUpperCase;
2421: unless ($in{kerb_def_dom}) {
2422: $Javascript_toUpperCase =<<"END";
2423: switch (choice) {
2424: case 'krb': currentform.elements[choicearg].value =
2425: currentform.elements[choicearg].value.toUpperCase();
2426: break;
2427: default:
2428: }
2429: END
2430: } else {
2431: $Javascript_toUpperCase = "";
2432: }
2433:
1.165 raeburn 2434: my $radioval = "'nochange'";
1.591 raeburn 2435: if (defined($in{'curr_authtype'})) {
2436: if ($in{'curr_authtype'} ne '') {
2437: $radioval = "'".$in{'curr_authtype'}."arg'";
2438: }
1.174 matthew 2439: }
1.165 raeburn 2440: my $argfield = 'null';
1.591 raeburn 2441: if (defined($in{'mode'})) {
1.165 raeburn 2442: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2443: if (defined($in{'curr_autharg'})) {
2444: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2445: $argfield = "'$in{'curr_autharg'}'";
2446: }
2447: }
2448: }
2449: }
2450:
1.32 matthew 2451: $result.=<<"END";
2452: var current = new Object();
1.165 raeburn 2453: current.radiovalue = $radioval;
2454: current.argfield = $argfield;
1.32 matthew 2455:
2456: function changed_radio(choice,currentform) {
2457: var choicearg = choice + 'arg';
2458: // If a radio button in changed, we need to change the argfield
2459: if (current.radiovalue != choice) {
2460: current.radiovalue = choice;
2461: if (current.argfield != null) {
2462: currentform.elements[current.argfield].value = '';
2463: }
2464: if (choice == 'nochange') {
2465: current.argfield = null;
2466: } else {
2467: current.argfield = choicearg;
2468: switch(choice) {
2469: case 'krb':
2470: currentform.elements[current.argfield].value =
2471: "$in{'kerb_def_dom'}";
2472: break;
2473: default:
2474: break;
2475: }
2476: }
2477: }
2478: return;
2479: }
1.22 www 2480:
1.32 matthew 2481: function changed_text(choice,currentform) {
2482: var choicearg = choice + 'arg';
2483: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2484: $Javascript_toUpperCase
1.32 matthew 2485: // clear old field
2486: if ((current.argfield != choicearg) && (current.argfield != null)) {
2487: currentform.elements[current.argfield].value = '';
2488: }
2489: current.argfield = choicearg;
2490: }
2491: set_auth_radio_buttons(choice,currentform);
2492: return;
1.20 www 2493: }
1.32 matthew 2494:
2495: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2496: var numauthchoices = currentform.login.length;
2497: if (typeof numauthchoices == "undefined") {
2498: return;
2499: }
1.32 matthew 2500: var i=0;
1.986 raeburn 2501: while (i < numauthchoices) {
1.32 matthew 2502: if (currentform.login[i].value == newvalue) { break; }
2503: i++;
2504: }
1.986 raeburn 2505: if (i == numauthchoices) {
1.32 matthew 2506: return;
2507: }
2508: current.radiovalue = newvalue;
2509: currentform.login[i].checked = true;
2510: return;
2511: }
2512: END
2513: return $result;
2514: }
2515:
1.1106 raeburn 2516: sub authform_authorwarning {
1.32 matthew 2517: my $result='';
1.144 matthew 2518: $result='<i>'.
2519: &mt('As a general rule, only authors or co-authors should be '.
2520: 'filesystem authenticated '.
2521: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2522: return $result;
2523: }
2524:
1.1106 raeburn 2525: sub authform_nochange {
1.32 matthew 2526: my %in = (
2527: formname => 'document.cu',
2528: kerb_def_dom => 'MSU.EDU',
2529: @_,
2530: );
1.1106 raeburn 2531: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2532: my $result;
1.1104 raeburn 2533: if (!$authnum) {
1.1105 raeburn 2534: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2535: } else {
2536: $result = '<label>'.&mt('[_1] Do not change login data',
2537: '<input type="radio" name="login" value="nochange" '.
2538: 'checked="checked" onclick="'.
1.281 albertel 2539: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2540: '</label>';
1.586 raeburn 2541: }
1.32 matthew 2542: return $result;
2543: }
2544:
1.591 raeburn 2545: sub authform_kerberos {
1.32 matthew 2546: my %in = (
2547: formname => 'document.cu',
2548: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2549: kerb_def_auth => 'krb4',
1.32 matthew 2550: @_,
2551: );
1.586 raeburn 2552: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2553: $autharg,$jscall);
1.1106 raeburn 2554: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2555: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2556: $check5 = ' checked="checked"';
1.80 albertel 2557: } else {
1.772 bisitz 2558: $check4 = ' checked="checked"';
1.80 albertel 2559: }
1.165 raeburn 2560: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2561: if (defined($in{'curr_authtype'})) {
2562: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2563: $krbcheck = ' checked="checked"';
1.623 raeburn 2564: if (defined($in{'mode'})) {
2565: if ($in{'mode'} eq 'modifyuser') {
2566: $krbcheck = '';
2567: }
2568: }
1.591 raeburn 2569: if (defined($in{'curr_kerb_ver'})) {
2570: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2571: $check5 = ' checked="checked"';
1.591 raeburn 2572: $check4 = '';
2573: } else {
1.772 bisitz 2574: $check4 = ' checked="checked"';
1.591 raeburn 2575: $check5 = '';
2576: }
1.586 raeburn 2577: }
1.591 raeburn 2578: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2579: $krbarg = $in{'curr_autharg'};
2580: }
1.586 raeburn 2581: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2582: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2583: $result =
2584: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2585: $in{'curr_autharg'},$krbver);
2586: } else {
2587: $result =
2588: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2589: }
2590: return $result;
2591: }
2592: }
2593: } else {
2594: if ($authnum == 1) {
1.784 bisitz 2595: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2596: }
2597: }
1.586 raeburn 2598: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2599: return;
1.587 raeburn 2600: } elsif ($authtype eq '') {
1.591 raeburn 2601: if (defined($in{'mode'})) {
1.587 raeburn 2602: if ($in{'mode'} eq 'modifycourse') {
2603: if ($authnum == 1) {
1.1104 raeburn 2604: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2605: }
2606: }
2607: }
1.586 raeburn 2608: }
2609: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2610: if ($authtype eq '') {
2611: $authtype = '<input type="radio" name="login" value="krb" '.
2612: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2613: $krbcheck.' />';
2614: }
2615: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2616: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2617: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2618: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2619: $in{'curr_authtype'} eq 'krb4')) {
2620: $result .= &mt
1.144 matthew 2621: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2622: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2623: '<label>'.$authtype,
1.281 albertel 2624: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2625: 'value="'.$krbarg.'" '.
1.144 matthew 2626: 'onchange="'.$jscall.'" />',
1.281 albertel 2627: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2628: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2629: '</label>');
1.586 raeburn 2630: } elsif ($can_assign{'krb4'}) {
2631: $result .= &mt
2632: ('[_1] Kerberos authenticated with domain [_2] '.
2633: '[_3] Version 4 [_4]',
2634: '<label>'.$authtype,
2635: '</label><input type="text" size="10" name="krbarg" '.
2636: 'value="'.$krbarg.'" '.
2637: 'onchange="'.$jscall.'" />',
2638: '<label><input type="hidden" name="krbver" value="4" />',
2639: '</label>');
2640: } elsif ($can_assign{'krb5'}) {
2641: $result .= &mt
2642: ('[_1] Kerberos authenticated with domain [_2] '.
2643: '[_3] Version 5 [_4]',
2644: '<label>'.$authtype,
2645: '</label><input type="text" size="10" name="krbarg" '.
2646: 'value="'.$krbarg.'" '.
2647: 'onchange="'.$jscall.'" />',
2648: '<label><input type="hidden" name="krbver" value="5" />',
2649: '</label>');
2650: }
1.32 matthew 2651: return $result;
2652: }
2653:
1.1106 raeburn 2654: sub authform_internal {
1.586 raeburn 2655: my %in = (
1.32 matthew 2656: formname => 'document.cu',
2657: kerb_def_dom => 'MSU.EDU',
2658: @_,
2659: );
1.586 raeburn 2660: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2661: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2662: if (defined($in{'curr_authtype'})) {
2663: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2664: if ($can_assign{'int'}) {
1.772 bisitz 2665: $intcheck = 'checked="checked" ';
1.623 raeburn 2666: if (defined($in{'mode'})) {
2667: if ($in{'mode'} eq 'modifyuser') {
2668: $intcheck = '';
2669: }
2670: }
1.591 raeburn 2671: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2672: $intarg = $in{'curr_autharg'};
2673: }
2674: } else {
2675: $result = &mt('Currently internally authenticated.');
2676: return $result;
1.165 raeburn 2677: }
2678: }
1.586 raeburn 2679: } else {
2680: if ($authnum == 1) {
1.784 bisitz 2681: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2682: }
2683: }
2684: if (!$can_assign{'int'}) {
2685: return;
1.587 raeburn 2686: } elsif ($authtype eq '') {
1.591 raeburn 2687: if (defined($in{'mode'})) {
1.587 raeburn 2688: if ($in{'mode'} eq 'modifycourse') {
2689: if ($authnum == 1) {
1.1104 raeburn 2690: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2691: }
2692: }
2693: }
1.165 raeburn 2694: }
1.586 raeburn 2695: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2696: if ($authtype eq '') {
2697: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2698: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2699: }
1.605 bisitz 2700: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2701: $intarg.'" onchange="'.$jscall.'" />';
2702: $result = &mt
1.144 matthew 2703: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2704: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2705: $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 2706: return $result;
2707: }
2708:
1.1104 raeburn 2709: sub authform_local {
1.32 matthew 2710: my %in = (
2711: formname => 'document.cu',
2712: kerb_def_dom => 'MSU.EDU',
2713: @_,
2714: );
1.586 raeburn 2715: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2716: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2717: if (defined($in{'curr_authtype'})) {
2718: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2719: if ($can_assign{'loc'}) {
1.772 bisitz 2720: $loccheck = 'checked="checked" ';
1.623 raeburn 2721: if (defined($in{'mode'})) {
2722: if ($in{'mode'} eq 'modifyuser') {
2723: $loccheck = '';
2724: }
2725: }
1.591 raeburn 2726: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2727: $locarg = $in{'curr_autharg'};
2728: }
2729: } else {
2730: $result = &mt('Currently using local (institutional) authentication.');
2731: return $result;
1.165 raeburn 2732: }
2733: }
1.586 raeburn 2734: } else {
2735: if ($authnum == 1) {
1.784 bisitz 2736: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2737: }
2738: }
2739: if (!$can_assign{'loc'}) {
2740: return;
1.587 raeburn 2741: } elsif ($authtype eq '') {
1.591 raeburn 2742: if (defined($in{'mode'})) {
1.587 raeburn 2743: if ($in{'mode'} eq 'modifycourse') {
2744: if ($authnum == 1) {
1.1104 raeburn 2745: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2746: }
2747: }
2748: }
1.165 raeburn 2749: }
1.586 raeburn 2750: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2751: if ($authtype eq '') {
2752: $authtype = '<input type="radio" name="login" value="loc" '.
2753: $loccheck.' onchange="'.$jscall.'" onclick="'.
2754: $jscall.'" />';
2755: }
2756: $autharg = '<input type="text" size="10" name="locarg" value="'.
2757: $locarg.'" onchange="'.$jscall.'" />';
2758: $result = &mt('[_1] Local Authentication with argument [_2]',
2759: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2760: return $result;
2761: }
2762:
1.1106 raeburn 2763: sub authform_filesystem {
1.32 matthew 2764: my %in = (
2765: formname => 'document.cu',
2766: kerb_def_dom => 'MSU.EDU',
2767: @_,
2768: );
1.586 raeburn 2769: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2770: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2771: if (defined($in{'curr_authtype'})) {
2772: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2773: if ($can_assign{'fsys'}) {
1.772 bisitz 2774: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2775: if (defined($in{'mode'})) {
2776: if ($in{'mode'} eq 'modifyuser') {
2777: $fsyscheck = '';
2778: }
2779: }
1.586 raeburn 2780: } else {
2781: $result = &mt('Currently Filesystem Authenticated.');
2782: return $result;
2783: }
2784: }
2785: } else {
2786: if ($authnum == 1) {
1.784 bisitz 2787: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2788: }
2789: }
2790: if (!$can_assign{'fsys'}) {
2791: return;
1.587 raeburn 2792: } elsif ($authtype eq '') {
1.591 raeburn 2793: if (defined($in{'mode'})) {
1.587 raeburn 2794: if ($in{'mode'} eq 'modifycourse') {
2795: if ($authnum == 1) {
1.1104 raeburn 2796: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2797: }
2798: }
2799: }
1.586 raeburn 2800: }
2801: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2802: if ($authtype eq '') {
2803: $authtype = '<input type="radio" name="login" value="fsys" '.
2804: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2805: $jscall.'" />';
2806: }
2807: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2808: ' onchange="'.$jscall.'" />';
2809: $result = &mt
1.144 matthew 2810: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2811: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2812: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2813: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2814: 'onchange="'.$jscall.'" />');
1.32 matthew 2815: return $result;
2816: }
2817:
1.586 raeburn 2818: sub get_assignable_auth {
2819: my ($dom) = @_;
2820: if ($dom eq '') {
2821: $dom = $env{'request.role.domain'};
2822: }
2823: my %can_assign = (
2824: krb4 => 1,
2825: krb5 => 1,
2826: int => 1,
2827: loc => 1,
2828: );
2829: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2830: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2831: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2832: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2833: my $context;
2834: if ($env{'request.role'} =~ /^au/) {
2835: $context = 'author';
2836: } elsif ($env{'request.role'} =~ /^dc/) {
2837: $context = 'domain';
2838: } elsif ($env{'request.course.id'}) {
2839: $context = 'course';
2840: }
2841: if ($context) {
2842: if (ref($authhash->{$context}) eq 'HASH') {
2843: %can_assign = %{$authhash->{$context}};
2844: }
2845: }
2846: }
2847: }
2848: my $authnum = 0;
2849: foreach my $key (keys(%can_assign)) {
2850: if ($can_assign{$key}) {
2851: $authnum ++;
2852: }
2853: }
2854: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2855: $authnum --;
2856: }
2857: return ($authnum,%can_assign);
2858: }
2859:
1.80 albertel 2860: ###############################################################
2861: ## Get Kerberos Defaults for Domain ##
2862: ###############################################################
2863: ##
2864: ## Returns default kerberos version and an associated argument
2865: ## as listed in file domain.tab. If not listed, provides
2866: ## appropriate default domain and kerberos version.
2867: ##
2868: #-------------------------------------------
2869:
2870: =pod
2871:
1.648 raeburn 2872: =item * &get_kerberos_defaults()
1.80 albertel 2873:
2874: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2875: version and domain. If not found, it defaults to version 4 and the
2876: domain of the server.
1.80 albertel 2877:
1.648 raeburn 2878: =over 4
2879:
1.80 albertel 2880: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2881:
1.648 raeburn 2882: =back
2883:
2884: =back
2885:
1.80 albertel 2886: =cut
2887:
2888: #-------------------------------------------
2889: sub get_kerberos_defaults {
2890: my $domain=shift;
1.641 raeburn 2891: my ($krbdef,$krbdefdom);
2892: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2893: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2894: $krbdef = $domdefaults{'auth_def'};
2895: $krbdefdom = $domdefaults{'auth_arg_def'};
2896: } else {
1.80 albertel 2897: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2898: my $krbdefdom=$1;
2899: $krbdefdom=~tr/a-z/A-Z/;
2900: $krbdef = "krb4";
2901: }
2902: return ($krbdef,$krbdefdom);
2903: }
1.112 bowersj2 2904:
1.32 matthew 2905:
1.46 matthew 2906: ###############################################################
2907: ## Thesaurus Functions ##
2908: ###############################################################
1.20 www 2909:
1.46 matthew 2910: =pod
1.20 www 2911:
1.112 bowersj2 2912: =head1 Thesaurus Functions
2913:
2914: =over 4
2915:
1.648 raeburn 2916: =item * &initialize_keywords()
1.46 matthew 2917:
2918: Initializes the package variable %Keywords if it is empty. Uses the
2919: package variable $thesaurus_db_file.
2920:
2921: =cut
2922:
2923: ###################################################
2924:
2925: sub initialize_keywords {
2926: return 1 if (scalar keys(%Keywords));
2927: # If we are here, %Keywords is empty, so fill it up
2928: # Make sure the file we need exists...
2929: if (! -e $thesaurus_db_file) {
2930: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2931: " failed because it does not exist");
2932: return 0;
2933: }
2934: # Set up the hash as a database
2935: my %thesaurus_db;
2936: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2937: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2938: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2939: $thesaurus_db_file);
2940: return 0;
2941: }
2942: # Get the average number of appearances of a word.
2943: my $avecount = $thesaurus_db{'average.count'};
2944: # Put keywords (those that appear > average) into %Keywords
2945: while (my ($word,$data)=each (%thesaurus_db)) {
2946: my ($count,undef) = split /:/,$data;
2947: $Keywords{$word}++ if ($count > $avecount);
2948: }
2949: untie %thesaurus_db;
2950: # Remove special values from %Keywords.
1.356 albertel 2951: foreach my $value ('total.count','average.count') {
2952: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2953: }
1.46 matthew 2954: return 1;
2955: }
2956:
2957: ###################################################
2958:
2959: =pod
2960:
1.648 raeburn 2961: =item * &keyword($word)
1.46 matthew 2962:
2963: Returns true if $word is a keyword. A keyword is a word that appears more
2964: than the average number of times in the thesaurus database. Calls
2965: &initialize_keywords
2966:
2967: =cut
2968:
2969: ###################################################
1.20 www 2970:
2971: sub keyword {
1.46 matthew 2972: return if (!&initialize_keywords());
2973: my $word=lc(shift());
2974: $word=~s/\W//g;
2975: return exists($Keywords{$word});
1.20 www 2976: }
1.46 matthew 2977:
2978: ###############################################################
2979:
2980: =pod
1.20 www 2981:
1.648 raeburn 2982: =item * &get_related_words()
1.46 matthew 2983:
1.160 matthew 2984: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2985: an array of words. If the keyword is not in the thesaurus, an empty array
2986: will be returned. The order of the words returned is determined by the
2987: database which holds them.
2988:
2989: Uses global $thesaurus_db_file.
2990:
1.1057 foxr 2991:
1.46 matthew 2992: =cut
2993:
2994: ###############################################################
2995: sub get_related_words {
2996: my $keyword = shift;
2997: my %thesaurus_db;
2998: if (! -e $thesaurus_db_file) {
2999: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3000: "failed because the file does not exist");
3001: return ();
3002: }
3003: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3004: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3005: return ();
3006: }
3007: my @Words=();
1.429 www 3008: my $count=0;
1.46 matthew 3009: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3010: # The first element is the number of times
3011: # the word appears. We do not need it now.
1.429 www 3012: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3013: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3014: my $threshold=$mostfrequentcount/10;
3015: foreach my $possibleword (@RelatedWords) {
3016: my ($word,$wordcount)=split(/\,/,$possibleword);
3017: if ($wordcount>$threshold) {
3018: push(@Words,$word);
3019: $count++;
3020: if ($count>10) { last; }
3021: }
1.20 www 3022: }
3023: }
1.46 matthew 3024: untie %thesaurus_db;
3025: return @Words;
1.14 harris41 3026: }
1.1090 foxr 3027: ###############################################################
3028: #
3029: # Spell checking
3030: #
3031:
3032: =pod
3033:
3034: =head1 Spell checking
3035:
3036: =over 4
3037:
3038: =item * &check_spelling($wordlist $language)
3039:
3040: Takes a string containing words and feeds it to an external
3041: spellcheck program via a pipeline. Returns a string containing
3042: them mis-spelled words.
3043:
3044: Parameters:
3045:
3046: =over 4
3047:
3048: =item - $wordlist
3049:
3050: String that will be fed into the spellcheck program.
3051:
3052: =item - $language
3053:
3054: Language string that specifies the language for which the spell
3055: check will be performed.
3056:
3057: =back
3058:
3059: =back
3060:
3061: Note: This sub assumes that aspell is installed.
3062:
3063:
3064: =cut
3065:
1.46 matthew 3066:
1.112 bowersj2 3067: =pod
3068:
3069: =back
3070:
3071: =cut
1.61 www 3072:
1.1090 foxr 3073: sub check_spelling {
3074: my ($wordlist, $language) = @_;
1.1091 foxr 3075: my @misspellings;
3076:
3077: # Generate the speller and set the langauge.
3078: # if explicitly selected:
1.1090 foxr 3079:
1.1091 foxr 3080: my $speller = Text::Aspell->new;
1.1090 foxr 3081: if ($language) {
1.1091 foxr 3082: $speller->set_option('lang', $language);
1.1090 foxr 3083: }
3084:
1.1091 foxr 3085: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3086:
1.1091 foxr 3087: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3088:
1.1091 foxr 3089: foreach my $word (@words) {
3090: if(! $speller->check($word)) {
3091: push(@misspellings, $word);
1.1090 foxr 3092: }
3093: }
1.1091 foxr 3094: return join(' ', @misspellings);
3095:
1.1090 foxr 3096: }
3097:
1.61 www 3098: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3099: =pod
3100:
1.112 bowersj2 3101: =head1 User Name Functions
3102:
3103: =over 4
3104:
1.648 raeburn 3105: =item * &plainname($uname,$udom,$first)
1.81 albertel 3106:
1.112 bowersj2 3107: Takes a users logon name and returns it as a string in
1.226 albertel 3108: "first middle last generation" form
3109: if $first is set to 'lastname' then it returns it as
3110: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3111:
3112: =cut
1.61 www 3113:
1.295 www 3114:
1.81 albertel 3115: ###############################################################
1.61 www 3116: sub plainname {
1.226 albertel 3117: my ($uname,$udom,$first)=@_;
1.537 albertel 3118: return if (!defined($uname) || !defined($udom));
1.295 www 3119: my %names=&getnames($uname,$udom);
1.226 albertel 3120: my $name=&Apache::lonnet::format_name($names{'firstname'},
3121: $names{'middlename'},
3122: $names{'lastname'},
3123: $names{'generation'},$first);
3124: $name=~s/^\s+//;
1.62 www 3125: $name=~s/\s+$//;
3126: $name=~s/\s+/ /g;
1.353 albertel 3127: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3128: return $name;
1.61 www 3129: }
1.66 www 3130:
3131: # -------------------------------------------------------------------- Nickname
1.81 albertel 3132: =pod
3133:
1.648 raeburn 3134: =item * &nickname($uname,$udom)
1.81 albertel 3135:
3136: Gets a users name and returns it as a string as
3137:
3138: ""nickname""
1.66 www 3139:
1.81 albertel 3140: if the user has a nickname or
3141:
3142: "first middle last generation"
3143:
3144: if the user does not
3145:
3146: =cut
1.66 www 3147:
3148: sub nickname {
3149: my ($uname,$udom)=@_;
1.537 albertel 3150: return if (!defined($uname) || !defined($udom));
1.295 www 3151: my %names=&getnames($uname,$udom);
1.68 albertel 3152: my $name=$names{'nickname'};
1.66 www 3153: if ($name) {
3154: $name='"'.$name.'"';
3155: } else {
3156: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3157: $names{'lastname'}.' '.$names{'generation'};
3158: $name=~s/\s+$//;
3159: $name=~s/\s+/ /g;
3160: }
3161: return $name;
3162: }
3163:
1.295 www 3164: sub getnames {
3165: my ($uname,$udom)=@_;
1.537 albertel 3166: return if (!defined($uname) || !defined($udom));
1.433 albertel 3167: if ($udom eq 'public' && $uname eq 'public') {
3168: return ('lastname' => &mt('Public'));
3169: }
1.295 www 3170: my $id=$uname.':'.$udom;
3171: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3172: if ($cached) {
3173: return %{$names};
3174: } else {
3175: my %loadnames=&Apache::lonnet::get('environment',
3176: ['firstname','middlename','lastname','generation','nickname'],
3177: $udom,$uname);
3178: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3179: return %loadnames;
3180: }
3181: }
1.61 www 3182:
1.542 raeburn 3183: # -------------------------------------------------------------------- getemails
1.648 raeburn 3184:
1.542 raeburn 3185: =pod
3186:
1.648 raeburn 3187: =item * &getemails($uname,$udom)
1.542 raeburn 3188:
3189: Gets a user's email information and returns it as a hash with keys:
3190: notification, critnotification, permanentemail
3191:
3192: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3193: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3194:
1.648 raeburn 3195:
1.542 raeburn 3196: =cut
3197:
1.648 raeburn 3198:
1.466 albertel 3199: sub getemails {
3200: my ($uname,$udom)=@_;
3201: if ($udom eq 'public' && $uname eq 'public') {
3202: return;
3203: }
1.467 www 3204: if (!$udom) { $udom=$env{'user.domain'}; }
3205: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3206: my $id=$uname.':'.$udom;
3207: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3208: if ($cached) {
3209: return %{$names};
3210: } else {
3211: my %loadnames=&Apache::lonnet::get('environment',
3212: ['notification','critnotification',
3213: 'permanentemail'],
3214: $udom,$uname);
3215: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3216: return %loadnames;
3217: }
3218: }
3219:
1.551 albertel 3220: sub flush_email_cache {
3221: my ($uname,$udom)=@_;
3222: if (!$udom) { $udom =$env{'user.domain'}; }
3223: if (!$uname) { $uname=$env{'user.name'}; }
3224: return if ($udom eq 'public' && $uname eq 'public');
3225: my $id=$uname.':'.$udom;
3226: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3227: }
3228:
1.728 raeburn 3229: # -------------------------------------------------------------------- getlangs
3230:
3231: =pod
3232:
3233: =item * &getlangs($uname,$udom)
3234:
3235: Gets a user's language preference and returns it as a hash with key:
3236: language.
3237:
3238: =cut
3239:
3240:
3241: sub getlangs {
3242: my ($uname,$udom) = @_;
3243: if (!$udom) { $udom =$env{'user.domain'}; }
3244: if (!$uname) { $uname=$env{'user.name'}; }
3245: my $id=$uname.':'.$udom;
3246: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3247: if ($cached) {
3248: return %{$langs};
3249: } else {
3250: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3251: $udom,$uname);
3252: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3253: return %loadlangs;
3254: }
3255: }
3256:
3257: sub flush_langs_cache {
3258: my ($uname,$udom)=@_;
3259: if (!$udom) { $udom =$env{'user.domain'}; }
3260: if (!$uname) { $uname=$env{'user.name'}; }
3261: return if ($udom eq 'public' && $uname eq 'public');
3262: my $id=$uname.':'.$udom;
3263: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3264: }
3265:
1.61 www 3266: # ------------------------------------------------------------------ Screenname
1.81 albertel 3267:
3268: =pod
3269:
1.648 raeburn 3270: =item * &screenname($uname,$udom)
1.81 albertel 3271:
3272: Gets a users screenname and returns it as a string
3273:
3274: =cut
1.61 www 3275:
3276: sub screenname {
3277: my ($uname,$udom)=@_;
1.258 albertel 3278: if ($uname eq $env{'user.name'} &&
3279: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3280: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3281: return $names{'screenname'};
1.62 www 3282: }
3283:
1.212 albertel 3284:
1.802 bisitz 3285: # ------------------------------------------------------------- Confirm Wrapper
3286: =pod
3287:
3288: =item confirmwrapper
3289:
3290: Wrap messages about completion of operation in box
3291:
3292: =cut
3293:
3294: sub confirmwrapper {
3295: my ($message)=@_;
3296: if ($message) {
3297: return "\n".'<div class="LC_confirm_box">'."\n"
3298: .$message."\n"
3299: .'</div>'."\n";
3300: } else {
3301: return $message;
3302: }
3303: }
3304:
1.62 www 3305: # ------------------------------------------------------------- Message Wrapper
3306:
3307: sub messagewrapper {
1.369 www 3308: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3309: return
1.441 albertel 3310: '<a href="/adm/email?compose=individual&'.
3311: 'recname='.$username.'&recdom='.$domain.
3312: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3313: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3314: }
1.802 bisitz 3315:
1.74 www 3316: # --------------------------------------------------------------- Notes Wrapper
3317:
3318: sub noteswrapper {
3319: my ($link,$un,$do)=@_;
3320: return
1.896 amueller 3321: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3322: }
1.802 bisitz 3323:
1.62 www 3324: # ------------------------------------------------------------- Aboutme Wrapper
3325:
3326: sub aboutmewrapper {
1.1070 raeburn 3327: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3328: if (!defined($username) && !defined($domain)) {
3329: return;
3330: }
1.1096 raeburn 3331: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3332: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3333: }
3334:
3335: # ------------------------------------------------------------ Syllabus Wrapper
3336:
3337: sub syllabuswrapper {
1.707 bisitz 3338: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3339: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3340: }
1.14 harris41 3341:
1.802 bisitz 3342: # -----------------------------------------------------------------------------
3343:
1.208 matthew 3344: sub track_student_link {
1.887 raeburn 3345: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3346: my $link ="/adm/trackstudent?";
1.208 matthew 3347: my $title = 'View recent activity';
3348: if (defined($sname) && $sname !~ /^\s*$/ &&
3349: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3350: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3351: $title .= ' of this student';
1.268 albertel 3352: }
1.208 matthew 3353: if (defined($target) && $target !~ /^\s*$/) {
3354: $target = qq{target="$target"};
3355: } else {
3356: $target = '';
3357: }
1.268 albertel 3358: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3359: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3360: $title = &mt($title);
3361: $linktext = &mt($linktext);
1.448 albertel 3362: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3363: &help_open_topic('View_recent_activity');
1.208 matthew 3364: }
3365:
1.781 raeburn 3366: sub slot_reservations_link {
3367: my ($linktext,$sname,$sdom,$target) = @_;
3368: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3369: my $title = 'View slot reservation history';
3370: if (defined($sname) && $sname !~ /^\s*$/ &&
3371: defined($sdom) && $sdom !~ /^\s*$/) {
3372: $link .= "&uname=$sname&udom=$sdom";
3373: $title .= ' of this student';
3374: }
3375: if (defined($target) && $target !~ /^\s*$/) {
3376: $target = qq{target="$target"};
3377: } else {
3378: $target = '';
3379: }
3380: $title = &mt($title);
3381: $linktext = &mt($linktext);
3382: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3383: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3384:
3385: }
3386:
1.508 www 3387: # ===================================================== Display a student photo
3388:
3389:
1.509 albertel 3390: sub student_image_tag {
1.508 www 3391: my ($domain,$user)=@_;
3392: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3393: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3394: return '<img src="'.$imgsrc.'" align="right" />';
3395: } else {
3396: return '';
3397: }
3398: }
3399:
1.112 bowersj2 3400: =pod
3401:
3402: =back
3403:
3404: =head1 Access .tab File Data
3405:
3406: =over 4
3407:
1.648 raeburn 3408: =item * &languageids()
1.112 bowersj2 3409:
3410: returns list of all language ids
3411:
3412: =cut
3413:
1.14 harris41 3414: sub languageids {
1.16 harris41 3415: return sort(keys(%language));
1.14 harris41 3416: }
3417:
1.112 bowersj2 3418: =pod
3419:
1.648 raeburn 3420: =item * &languagedescription()
1.112 bowersj2 3421:
3422: returns description of a specified language id
3423:
3424: =cut
3425:
1.14 harris41 3426: sub languagedescription {
1.125 www 3427: my $code=shift;
3428: return ($supported_language{$code}?'* ':'').
3429: $language{$code}.
1.126 www 3430: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3431: }
3432:
1.1048 foxr 3433: =pod
3434:
3435: =item * &plainlanguagedescription
3436:
3437: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3438: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3439:
3440: =cut
3441:
1.145 www 3442: sub plainlanguagedescription {
3443: my $code=shift;
3444: return $language{$code};
3445: }
3446:
1.1048 foxr 3447: =pod
3448:
3449: =item * &supportedlanguagecode
3450:
3451: Returns the supported language code (e.g. sptutf maps to pt) given a language
3452: code.
3453:
3454: =cut
3455:
1.145 www 3456: sub supportedlanguagecode {
3457: my $code=shift;
3458: return $supported_language{$code};
1.97 www 3459: }
3460:
1.112 bowersj2 3461: =pod
3462:
1.1048 foxr 3463: =item * &latexlanguage()
3464:
3465: Given a language key code returns the correspondnig language to use
3466: to select the correct hyphenation on LaTeX printouts. This is undef if there
3467: is no supported hyphenation for the language code.
3468:
3469: =cut
3470:
3471: sub latexlanguage {
3472: my $code = shift;
3473: return $latex_language{$code};
3474: }
3475:
3476: =pod
3477:
3478: =item * &latexhyphenation()
3479:
3480: Same as above but what's supplied is the language as it might be stored
3481: in the metadata.
3482:
3483: =cut
3484:
3485: sub latexhyphenation {
3486: my $key = shift;
3487: return $latex_language_bykey{$key};
3488: }
3489:
3490: =pod
3491:
1.648 raeburn 3492: =item * ©rightids()
1.112 bowersj2 3493:
3494: returns list of all copyrights
3495:
3496: =cut
3497:
3498: sub copyrightids {
3499: return sort(keys(%cprtag));
3500: }
3501:
3502: =pod
3503:
1.648 raeburn 3504: =item * ©rightdescription()
1.112 bowersj2 3505:
3506: returns description of a specified copyright id
3507:
3508: =cut
3509:
3510: sub copyrightdescription {
1.166 www 3511: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3512: }
1.197 matthew 3513:
3514: =pod
3515:
1.648 raeburn 3516: =item * &source_copyrightids()
1.192 taceyjo1 3517:
3518: returns list of all source copyrights
3519:
3520: =cut
3521:
3522: sub source_copyrightids {
3523: return sort(keys(%scprtag));
3524: }
3525:
3526: =pod
3527:
1.648 raeburn 3528: =item * &source_copyrightdescription()
1.192 taceyjo1 3529:
3530: returns description of a specified source copyright id
3531:
3532: =cut
3533:
3534: sub source_copyrightdescription {
3535: return &mt($scprtag{shift(@_)});
3536: }
1.112 bowersj2 3537:
3538: =pod
3539:
1.648 raeburn 3540: =item * &filecategories()
1.112 bowersj2 3541:
3542: returns list of all file categories
3543:
3544: =cut
3545:
3546: sub filecategories {
3547: return sort(keys(%category_extensions));
3548: }
3549:
3550: =pod
3551:
1.648 raeburn 3552: =item * &filecategorytypes()
1.112 bowersj2 3553:
3554: returns list of file types belonging to a given file
3555: category
3556:
3557: =cut
3558:
3559: sub filecategorytypes {
1.356 albertel 3560: my ($cat) = @_;
3561: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3562: }
3563:
3564: =pod
3565:
1.648 raeburn 3566: =item * &fileembstyle()
1.112 bowersj2 3567:
3568: returns embedding style for a specified file type
3569:
3570: =cut
3571:
3572: sub fileembstyle {
3573: return $fe{lc(shift(@_))};
1.169 www 3574: }
3575:
1.351 www 3576: sub filemimetype {
3577: return $fm{lc(shift(@_))};
3578: }
3579:
1.169 www 3580:
3581: sub filecategoryselect {
3582: my ($name,$value)=@_;
1.189 matthew 3583: return &select_form($value,$name,
1.970 raeburn 3584: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3585: }
3586:
3587: =pod
3588:
1.648 raeburn 3589: =item * &filedescription()
1.112 bowersj2 3590:
3591: returns description for a specified file type
3592:
3593: =cut
3594:
3595: sub filedescription {
1.188 matthew 3596: my $file_description = $fd{lc(shift())};
3597: $file_description =~ s:([\[\]]):~$1:g;
3598: return &mt($file_description);
1.112 bowersj2 3599: }
3600:
3601: =pod
3602:
1.648 raeburn 3603: =item * &filedescriptionex()
1.112 bowersj2 3604:
3605: returns description for a specified file type with
3606: extra formatting
3607:
3608: =cut
3609:
3610: sub filedescriptionex {
3611: my $ex=shift;
1.188 matthew 3612: my $file_description = $fd{lc($ex)};
3613: $file_description =~ s:([\[\]]):~$1:g;
3614: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3615: }
3616:
3617: # End of .tab access
3618: =pod
3619:
3620: =back
3621:
3622: =cut
3623:
3624: # ------------------------------------------------------------------ File Types
3625: sub fileextensions {
3626: return sort(keys(%fe));
3627: }
3628:
1.97 www 3629: # ----------------------------------------------------------- Display Languages
3630: # returns a hash with all desired display languages
3631: #
3632:
3633: sub display_languages {
3634: my %languages=();
1.695 raeburn 3635: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3636: $languages{$lang}=1;
1.97 www 3637: }
3638: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3639: if ($env{'form.displaylanguage'}) {
1.356 albertel 3640: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3641: $languages{$lang}=1;
1.97 www 3642: }
3643: }
3644: return %languages;
1.14 harris41 3645: }
3646:
1.582 albertel 3647: sub languages {
3648: my ($possible_langs) = @_;
1.695 raeburn 3649: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3650: if (!ref($possible_langs)) {
3651: if( wantarray ) {
3652: return @preferred_langs;
3653: } else {
3654: return $preferred_langs[0];
3655: }
3656: }
3657: my %possibilities = map { $_ => 1 } (@$possible_langs);
3658: my @preferred_possibilities;
3659: foreach my $preferred_lang (@preferred_langs) {
3660: if (exists($possibilities{$preferred_lang})) {
3661: push(@preferred_possibilities, $preferred_lang);
3662: }
3663: }
3664: if( wantarray ) {
3665: return @preferred_possibilities;
3666: }
3667: return $preferred_possibilities[0];
3668: }
3669:
1.742 raeburn 3670: sub user_lang {
3671: my ($touname,$toudom,$fromcid) = @_;
3672: my @userlangs;
3673: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3674: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3675: $env{'course.'.$fromcid.'.languages'}));
3676: } else {
3677: my %langhash = &getlangs($touname,$toudom);
3678: if ($langhash{'languages'} ne '') {
3679: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3680: } else {
3681: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3682: if ($domdefs{'lang_def'} ne '') {
3683: @userlangs = ($domdefs{'lang_def'});
3684: }
3685: }
3686: }
3687: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3688: my $user_lh = Apache::localize->get_handle(@languages);
3689: return $user_lh;
3690: }
3691:
3692:
1.112 bowersj2 3693: ###############################################################
3694: ## Student Answer Attempts ##
3695: ###############################################################
3696:
3697: =pod
3698:
3699: =head1 Alternate Problem Views
3700:
3701: =over 4
3702:
1.648 raeburn 3703: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3704: $getattempt, $regexp, $gradesub)
3705:
3706: Return string with previous attempt on problem. Arguments:
3707:
3708: =over 4
3709:
3710: =item * $symb: Problem, including path
3711:
3712: =item * $username: username of the desired student
3713:
3714: =item * $domain: domain of the desired student
1.14 harris41 3715:
1.112 bowersj2 3716: =item * $course: Course ID
1.14 harris41 3717:
1.112 bowersj2 3718: =item * $getattempt: Leave blank for all attempts, otherwise put
3719: something
1.14 harris41 3720:
1.112 bowersj2 3721: =item * $regexp: if string matches this regexp, the string will be
3722: sent to $gradesub
1.14 harris41 3723:
1.112 bowersj2 3724: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3725:
1.112 bowersj2 3726: =back
1.14 harris41 3727:
1.112 bowersj2 3728: The output string is a table containing all desired attempts, if any.
1.16 harris41 3729:
1.112 bowersj2 3730: =cut
1.1 albertel 3731:
3732: sub get_previous_attempt {
1.43 ng 3733: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3734: my $prevattempts='';
1.43 ng 3735: no strict 'refs';
1.1 albertel 3736: if ($symb) {
1.3 albertel 3737: my (%returnhash)=
3738: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3739: if ($returnhash{'version'}) {
3740: my %lasthash=();
3741: my $version;
3742: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3743: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3744: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3745: }
1.1 albertel 3746: }
1.596 albertel 3747: $prevattempts=&start_data_table().&start_data_table_header_row();
3748: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3749: my (%typeparts,%lasthidden);
1.945 raeburn 3750: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3751: foreach my $key (sort(keys(%lasthash))) {
3752: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3753: if ($#parts > 0) {
1.31 albertel 3754: my $data=$parts[-1];
1.989 raeburn 3755: next if ($data eq 'foilorder');
1.31 albertel 3756: pop(@parts);
1.1010 www 3757: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3758: if ($data eq 'type') {
3759: unless ($showsurv) {
3760: my $id = join(',',@parts);
3761: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3762: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3763: $lasthidden{$ign.'.'.$id} = 1;
3764: }
1.945 raeburn 3765: }
1.1010 www 3766: }
1.31 albertel 3767: } else {
1.41 ng 3768: if ($#parts == 0) {
3769: $prevattempts.='<th>'.$parts[0].'</th>';
3770: } else {
3771: $prevattempts.='<th>'.$ign.'</th>';
3772: }
1.31 albertel 3773: }
1.16 harris41 3774: }
1.596 albertel 3775: $prevattempts.=&end_data_table_header_row();
1.40 ng 3776: if ($getattempt eq '') {
3777: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3778: my @hidden;
3779: if (%typeparts) {
3780: foreach my $id (keys(%typeparts)) {
3781: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3782: push(@hidden,$id);
3783: }
3784: }
3785: }
3786: $prevattempts.=&start_data_table_row().
3787: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3788: if (@hidden) {
3789: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3790: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3791: my $hide;
3792: foreach my $id (@hidden) {
3793: if ($key =~ /^\Q$id\E/) {
3794: $hide = 1;
3795: last;
3796: }
3797: }
3798: if ($hide) {
3799: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3800: if (($data eq 'award') || ($data eq 'awarddetail')) {
3801: my $value = &format_previous_attempt_value($key,
3802: $returnhash{$version.':'.$key});
3803: $prevattempts.='<td>'.$value.' </td>';
3804: } else {
3805: $prevattempts.='<td> </td>';
3806: }
3807: } else {
3808: if ($key =~ /\./) {
3809: my $value = &format_previous_attempt_value($key,
3810: $returnhash{$version.':'.$key});
3811: $prevattempts.='<td>'.$value.' </td>';
3812: } else {
3813: $prevattempts.='<td> </td>';
3814: }
3815: }
3816: }
3817: } else {
3818: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3819: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3820: my $value = &format_previous_attempt_value($key,
3821: $returnhash{$version.':'.$key});
3822: $prevattempts.='<td>'.$value.' </td>';
3823: }
3824: }
3825: $prevattempts.=&end_data_table_row();
1.40 ng 3826: }
1.1 albertel 3827: }
1.945 raeburn 3828: my @currhidden = keys(%lasthidden);
1.596 albertel 3829: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3830: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3831: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3832: if (%typeparts) {
3833: my $hidden;
3834: foreach my $id (@currhidden) {
3835: if ($key =~ /^\Q$id\E/) {
3836: $hidden = 1;
3837: last;
3838: }
3839: }
3840: if ($hidden) {
3841: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3842: if (($data eq 'award') || ($data eq 'awarddetail')) {
3843: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3844: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3845: $value = &$gradesub($value);
3846: }
3847: $prevattempts.='<td>'.$value.' </td>';
3848: } else {
3849: $prevattempts.='<td> </td>';
3850: }
3851: } else {
3852: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3853: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3854: $value = &$gradesub($value);
3855: }
3856: $prevattempts.='<td>'.$value.' </td>';
3857: }
3858: } else {
3859: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3860: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3861: $value = &$gradesub($value);
3862: }
3863: $prevattempts.='<td>'.$value.' </td>';
3864: }
1.16 harris41 3865: }
1.596 albertel 3866: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3867: } else {
1.596 albertel 3868: $prevattempts=
3869: &start_data_table().&start_data_table_row().
3870: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3871: &end_data_table_row().&end_data_table();
1.1 albertel 3872: }
3873: } else {
1.596 albertel 3874: $prevattempts=
3875: &start_data_table().&start_data_table_row().
3876: '<td>'.&mt('No data.').'</td>'.
3877: &end_data_table_row().&end_data_table();
1.1 albertel 3878: }
1.10 albertel 3879: }
3880:
1.581 albertel 3881: sub format_previous_attempt_value {
3882: my ($key,$value) = @_;
1.1011 www 3883: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3884: $value = &Apache::lonlocal::locallocaltime($value);
3885: } elsif (ref($value) eq 'ARRAY') {
3886: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3887: } elsif ($key =~ /answerstring$/) {
3888: my %answers = &Apache::lonnet::str2hash($value);
3889: my @anskeys = sort(keys(%answers));
3890: if (@anskeys == 1) {
3891: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3892: if ($answer =~ m{\0}) {
3893: $answer =~ s{\0}{,}g;
1.988 raeburn 3894: }
3895: my $tag_internal_answer_name = 'INTERNAL';
3896: if ($anskeys[0] eq $tag_internal_answer_name) {
3897: $value = $answer;
3898: } else {
3899: $value = $anskeys[0].'='.$answer;
3900: }
3901: } else {
3902: foreach my $ans (@anskeys) {
3903: my $answer = $answers{$ans};
1.1001 raeburn 3904: if ($answer =~ m{\0}) {
3905: $answer =~ s{\0}{,}g;
1.988 raeburn 3906: }
3907: $value .= $ans.'='.$answer.'<br />';;
3908: }
3909: }
1.581 albertel 3910: } else {
3911: $value = &unescape($value);
3912: }
3913: return $value;
3914: }
3915:
3916:
1.107 albertel 3917: sub relative_to_absolute {
3918: my ($url,$output)=@_;
3919: my $parser=HTML::TokeParser->new(\$output);
3920: my $token;
3921: my $thisdir=$url;
3922: my @rlinks=();
3923: while ($token=$parser->get_token) {
3924: if ($token->[0] eq 'S') {
3925: if ($token->[1] eq 'a') {
3926: if ($token->[2]->{'href'}) {
3927: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3928: }
3929: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3930: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3931: } elsif ($token->[1] eq 'base') {
3932: $thisdir=$token->[2]->{'href'};
3933: }
3934: }
3935: }
3936: $thisdir=~s-/[^/]*$--;
1.356 albertel 3937: foreach my $link (@rlinks) {
1.726 raeburn 3938: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3939: ($link=~/^\//) ||
3940: ($link=~/^javascript:/i) ||
3941: ($link=~/^mailto:/i) ||
3942: ($link=~/^\#/)) {
3943: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3944: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3945: }
3946: }
3947: # -------------------------------------------------- Deal with Applet codebases
3948: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3949: return $output;
3950: }
3951:
1.112 bowersj2 3952: =pod
3953:
1.648 raeburn 3954: =item * &get_student_view()
1.112 bowersj2 3955:
3956: show a snapshot of what student was looking at
3957:
3958: =cut
3959:
1.10 albertel 3960: sub get_student_view {
1.186 albertel 3961: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3962: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3963: my (%form);
1.10 albertel 3964: my @elements=('symb','courseid','domain','username');
3965: foreach my $element (@elements) {
1.186 albertel 3966: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3967: }
1.186 albertel 3968: if (defined($moreenv)) {
3969: %form=(%form,%{$moreenv});
3970: }
1.236 albertel 3971: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3972: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3973: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3974: $userview=~s/\<body[^\>]*\>//gi;
3975: $userview=~s/\<\/body\>//gi;
3976: $userview=~s/\<html\>//gi;
3977: $userview=~s/\<\/html\>//gi;
3978: $userview=~s/\<head\>//gi;
3979: $userview=~s/\<\/head\>//gi;
3980: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3981: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3982: if (wantarray) {
3983: return ($userview,$response);
3984: } else {
3985: return $userview;
3986: }
3987: }
3988:
3989: sub get_student_view_with_retries {
3990: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3991:
3992: my $ok = 0; # True if we got a good response.
3993: my $content;
3994: my $response;
3995:
3996: # Try to get the student_view done. within the retries count:
3997:
3998: do {
3999: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4000: $ok = $response->is_success;
4001: if (!$ok) {
4002: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4003: }
4004: $retries--;
4005: } while (!$ok && ($retries > 0));
4006:
4007: if (!$ok) {
4008: $content = ''; # On error return an empty content.
4009: }
1.651 www 4010: if (wantarray) {
4011: return ($content, $response);
4012: } else {
4013: return $content;
4014: }
1.11 albertel 4015: }
4016:
1.112 bowersj2 4017: =pod
4018:
1.648 raeburn 4019: =item * &get_student_answers()
1.112 bowersj2 4020:
4021: show a snapshot of how student was answering problem
4022:
4023: =cut
4024:
1.11 albertel 4025: sub get_student_answers {
1.100 sakharuk 4026: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4027: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4028: my (%moreenv);
1.11 albertel 4029: my @elements=('symb','courseid','domain','username');
4030: foreach my $element (@elements) {
1.186 albertel 4031: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4032: }
1.186 albertel 4033: $moreenv{'grade_target'}='answer';
4034: %moreenv=(%form,%moreenv);
1.497 raeburn 4035: $feedurl = &Apache::lonnet::clutter($feedurl);
4036: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4037: return $userview;
1.1 albertel 4038: }
1.116 albertel 4039:
4040: =pod
4041:
4042: =item * &submlink()
4043:
1.242 albertel 4044: Inputs: $text $uname $udom $symb $target
1.116 albertel 4045:
4046: Returns: A link to grades.pm such as to see the SUBM view of a student
4047:
4048: =cut
4049:
4050: ###############################################
4051: sub submlink {
1.242 albertel 4052: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4053: if (!($uname && $udom)) {
4054: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4055: &Apache::lonnet::whichuser($symb);
1.116 albertel 4056: if (!$symb) { $symb=$cursymb; }
4057: }
1.254 matthew 4058: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4059: $symb=&escape($symb);
1.960 bisitz 4060: if ($target) { $target=" target=\"$target\""; }
4061: return
4062: '<a href="/adm/grades?command=submission'.
4063: '&symb='.$symb.
4064: '&student='.$uname.
4065: '&userdom='.$udom.'"'.
4066: $target.'>'.$text.'</a>';
1.242 albertel 4067: }
4068: ##############################################
4069:
4070: =pod
4071:
4072: =item * &pgrdlink()
4073:
4074: Inputs: $text $uname $udom $symb $target
4075:
4076: Returns: A link to grades.pm such as to see the PGRD view of a student
4077:
4078: =cut
4079:
4080: ###############################################
4081: sub pgrdlink {
4082: my $link=&submlink(@_);
4083: $link=~s/(&command=submission)/$1&showgrading=yes/;
4084: return $link;
4085: }
4086: ##############################################
4087:
4088: =pod
4089:
4090: =item * &pprmlink()
4091:
4092: Inputs: $text $uname $udom $symb $target
4093:
4094: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4095: student and a specific resource
1.242 albertel 4096:
4097: =cut
4098:
4099: ###############################################
4100: sub pprmlink {
4101: my ($text,$uname,$udom,$symb,$target)=@_;
4102: if (!($uname && $udom)) {
4103: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4104: &Apache::lonnet::whichuser($symb);
1.242 albertel 4105: if (!$symb) { $symb=$cursymb; }
4106: }
1.254 matthew 4107: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4108: $symb=&escape($symb);
1.242 albertel 4109: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4110: return '<a href="/adm/parmset?command=set&'.
4111: 'symb='.$symb.'&uname='.$uname.
4112: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4113: }
4114: ##############################################
1.37 matthew 4115:
1.112 bowersj2 4116: =pod
4117:
4118: =back
4119:
4120: =cut
4121:
1.37 matthew 4122: ###############################################
1.51 www 4123:
4124:
4125: sub timehash {
1.687 raeburn 4126: my ($thistime) = @_;
4127: my $timezone = &Apache::lonlocal::gettimezone();
4128: my $dt = DateTime->from_epoch(epoch => $thistime)
4129: ->set_time_zone($timezone);
4130: my $wday = $dt->day_of_week();
4131: if ($wday == 7) { $wday = 0; }
4132: return ( 'second' => $dt->second(),
4133: 'minute' => $dt->minute(),
4134: 'hour' => $dt->hour(),
4135: 'day' => $dt->day_of_month(),
4136: 'month' => $dt->month(),
4137: 'year' => $dt->year(),
4138: 'weekday' => $wday,
4139: 'dayyear' => $dt->day_of_year(),
4140: 'dlsav' => $dt->is_dst() );
1.51 www 4141: }
4142:
1.370 www 4143: sub utc_string {
4144: my ($date)=@_;
1.371 www 4145: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4146: }
4147:
1.51 www 4148: sub maketime {
4149: my %th=@_;
1.687 raeburn 4150: my ($epoch_time,$timezone,$dt);
4151: $timezone = &Apache::lonlocal::gettimezone();
4152: eval {
4153: $dt = DateTime->new( year => $th{'year'},
4154: month => $th{'month'},
4155: day => $th{'day'},
4156: hour => $th{'hour'},
4157: minute => $th{'minute'},
4158: second => $th{'second'},
4159: time_zone => $timezone,
4160: );
4161: };
4162: if (!$@) {
4163: $epoch_time = $dt->epoch;
4164: if ($epoch_time) {
4165: return $epoch_time;
4166: }
4167: }
1.51 www 4168: return POSIX::mktime(
4169: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4170: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4171: }
4172:
4173: #########################################
1.51 www 4174:
4175: sub findallcourses {
1.482 raeburn 4176: my ($roles,$uname,$udom) = @_;
1.355 albertel 4177: my %roles;
4178: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4179: my %courses;
1.51 www 4180: my $now=time;
1.482 raeburn 4181: if (!defined($uname)) {
4182: $uname = $env{'user.name'};
4183: }
4184: if (!defined($udom)) {
4185: $udom = $env{'user.domain'};
4186: }
4187: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4188: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4189: if (!%roles) {
4190: %roles = (
4191: cc => 1,
1.907 raeburn 4192: co => 1,
1.482 raeburn 4193: in => 1,
4194: ep => 1,
4195: ta => 1,
4196: cr => 1,
4197: st => 1,
4198: );
4199: }
4200: foreach my $entry (keys(%roleshash)) {
4201: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4202: if ($trole =~ /^cr/) {
4203: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4204: } else {
4205: next if (!exists($roles{$trole}));
4206: }
4207: if ($tend) {
4208: next if ($tend < $now);
4209: }
4210: if ($tstart) {
4211: next if ($tstart > $now);
4212: }
1.1058 raeburn 4213: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4214: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4215: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4216: if ($secpart eq '') {
4217: ($cnum,$role) = split(/_/,$cnumpart);
4218: $sec = 'none';
1.1058 raeburn 4219: $value .= $cnum.'/';
1.482 raeburn 4220: } else {
4221: $cnum = $cnumpart;
4222: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4223: $value .= $cnum.'/'.$sec;
4224: }
4225: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4226: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4227: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4228: }
4229: } else {
4230: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4231: }
1.482 raeburn 4232: }
4233: } else {
4234: foreach my $key (keys(%env)) {
1.483 albertel 4235: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4236: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4237: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4238: next if ($role eq 'ca' || $role eq 'aa');
4239: next if (%roles && !exists($roles{$role}));
4240: my ($starttime,$endtime)=split(/\./,$env{$key});
4241: my $active=1;
4242: if ($starttime) {
4243: if ($now<$starttime) { $active=0; }
4244: }
4245: if ($endtime) {
4246: if ($now>$endtime) { $active=0; }
4247: }
4248: if ($active) {
1.1058 raeburn 4249: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4250: if ($sec eq '') {
4251: $sec = 'none';
1.1058 raeburn 4252: } else {
4253: $value .= $sec;
4254: }
4255: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4256: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4257: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4258: }
4259: } else {
4260: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4261: }
1.474 raeburn 4262: }
4263: }
1.51 www 4264: }
4265: }
1.474 raeburn 4266: return %courses;
1.51 www 4267: }
1.37 matthew 4268:
1.54 www 4269: ###############################################
1.474 raeburn 4270:
4271: sub blockcheck {
1.1062 raeburn 4272: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4273:
4274: if (!defined($udom)) {
4275: $udom = $env{'user.domain'};
4276: }
4277: if (!defined($uname)) {
4278: $uname = $env{'user.name'};
4279: }
4280:
4281: # If uname and udom are for a course, check for blocks in the course.
4282:
4283: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4284: my ($startblock,$endblock,$triggerblock) =
4285: &get_blocks($setters,$activity,$udom,$uname,$url);
4286: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4287: }
1.474 raeburn 4288:
1.502 raeburn 4289: my $startblock = 0;
4290: my $endblock = 0;
1.1062 raeburn 4291: my $triggerblock = '';
1.482 raeburn 4292: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4293:
1.490 raeburn 4294: # If uname is for a user, and activity is course-specific, i.e.,
4295: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4296:
1.490 raeburn 4297: if (($activity eq 'boards' || $activity eq 'chat' ||
4298: $activity eq 'groups') && ($env{'request.course.id'})) {
4299: foreach my $key (keys(%live_courses)) {
4300: if ($key ne $env{'request.course.id'}) {
4301: delete($live_courses{$key});
4302: }
4303: }
4304: }
4305:
4306: my $otheruser = 0;
4307: my %own_courses;
4308: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4309: # Resource belongs to user other than current user.
4310: $otheruser = 1;
4311: # Gather courses for current user
4312: %own_courses =
4313: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4314: }
4315:
4316: # Gather active course roles - course coordinator, instructor,
4317: # exam proctor, ta, student, or custom role.
1.474 raeburn 4318:
4319: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4320: my ($cdom,$cnum);
4321: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4322: $cdom = $env{'course.'.$course.'.domain'};
4323: $cnum = $env{'course.'.$course.'.num'};
4324: } else {
1.490 raeburn 4325: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4326: }
4327: my $no_ownblock = 0;
4328: my $no_userblock = 0;
1.533 raeburn 4329: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4330: # Check if current user has 'evb' priv for this
4331: if (defined($own_courses{$course})) {
4332: foreach my $sec (keys(%{$own_courses{$course}})) {
4333: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4334: if ($sec ne 'none') {
4335: $checkrole .= '/'.$sec;
4336: }
4337: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4338: $no_ownblock = 1;
4339: last;
4340: }
4341: }
4342: }
4343: # if they have 'evb' priv and are currently not playing student
4344: next if (($no_ownblock) &&
4345: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4346: }
1.474 raeburn 4347: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4348: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4349: if ($sec ne 'none') {
1.482 raeburn 4350: $checkrole .= '/'.$sec;
1.474 raeburn 4351: }
1.490 raeburn 4352: if ($otheruser) {
4353: # Resource belongs to user other than current user.
4354: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4355: my (%allroles,%userroles);
4356: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4357: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4358: my ($trole,$tdom,$tnum,$tsec);
4359: if ($entry =~ /^cr/) {
4360: ($trole,$tdom,$tnum,$tsec) =
4361: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4362: } else {
4363: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4364: }
4365: my ($spec,$area,$trest);
4366: $area = '/'.$tdom.'/'.$tnum;
4367: $trest = $tnum;
4368: if ($tsec ne '') {
4369: $area .= '/'.$tsec;
4370: $trest .= '/'.$tsec;
4371: }
4372: $spec = $trole.'.'.$area;
4373: if ($trole =~ /^cr/) {
4374: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4375: $tdom,$spec,$trest,$area);
4376: } else {
4377: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4378: $tdom,$spec,$trest,$area);
4379: }
4380: }
4381: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4382: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4383: if ($1) {
4384: $no_userblock = 1;
4385: last;
4386: }
1.486 raeburn 4387: }
4388: }
1.490 raeburn 4389: } else {
4390: # Resource belongs to current user
4391: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4392: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4393: $no_ownblock = 1;
4394: last;
4395: }
1.474 raeburn 4396: }
4397: }
4398: # if they have the evb priv and are currently not playing student
1.482 raeburn 4399: next if (($no_ownblock) &&
1.491 albertel 4400: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4401: next if ($no_userblock);
1.474 raeburn 4402:
1.866 kalberla 4403: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4404: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4405:
1.1062 raeburn 4406: my ($start,$end,$trigger) =
4407: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4408: if (($start != 0) &&
4409: (($startblock == 0) || ($startblock > $start))) {
4410: $startblock = $start;
1.1062 raeburn 4411: if ($trigger ne '') {
4412: $triggerblock = $trigger;
4413: }
1.502 raeburn 4414: }
4415: if (($end != 0) &&
4416: (($endblock == 0) || ($endblock < $end))) {
4417: $endblock = $end;
1.1062 raeburn 4418: if ($trigger ne '') {
4419: $triggerblock = $trigger;
4420: }
1.502 raeburn 4421: }
1.490 raeburn 4422: }
1.1062 raeburn 4423: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4424: }
4425:
4426: sub get_blocks {
1.1062 raeburn 4427: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4428: my $startblock = 0;
4429: my $endblock = 0;
1.1062 raeburn 4430: my $triggerblock = '';
1.490 raeburn 4431: my $course = $cdom.'_'.$cnum;
4432: $setters->{$course} = {};
4433: $setters->{$course}{'staff'} = [];
4434: $setters->{$course}{'times'} = [];
1.1062 raeburn 4435: $setters->{$course}{'triggers'} = [];
4436: my (@blockers,%triggered);
4437: my $now = time;
4438: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4439: if ($activity eq 'docs') {
4440: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4441: foreach my $block (@blockers) {
4442: if ($block =~ /^firstaccess____(.+)$/) {
4443: my $item = $1;
4444: my $type = 'map';
4445: my $timersymb = $item;
4446: if ($item eq 'course') {
4447: $type = 'course';
4448: } elsif ($item =~ /___\d+___/) {
4449: $type = 'resource';
4450: } else {
4451: $timersymb = &Apache::lonnet::symbread($item);
4452: }
4453: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4454: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4455: $triggered{$block} = {
4456: start => $start,
4457: end => $end,
4458: type => $type,
4459: };
4460: }
4461: }
4462: } else {
4463: foreach my $block (keys(%commblocks)) {
4464: if ($block =~ m/^(\d+)____(\d+)$/) {
4465: my ($start,$end) = ($1,$2);
4466: if ($start <= time && $end >= time) {
4467: if (ref($commblocks{$block}) eq 'HASH') {
4468: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4469: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4470: unless(grep(/^\Q$block\E$/,@blockers)) {
4471: push(@blockers,$block);
4472: }
4473: }
4474: }
4475: }
4476: }
4477: } elsif ($block =~ /^firstaccess____(.+)$/) {
4478: my $item = $1;
4479: my $timersymb = $item;
4480: my $type = 'map';
4481: if ($item eq 'course') {
4482: $type = 'course';
4483: } elsif ($item =~ /___\d+___/) {
4484: $type = 'resource';
4485: } else {
4486: $timersymb = &Apache::lonnet::symbread($item);
4487: }
4488: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4489: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4490: if ($start && $end) {
4491: if (($start <= time) && ($end >= time)) {
4492: unless (grep(/^\Q$block\E$/,@blockers)) {
4493: push(@blockers,$block);
4494: $triggered{$block} = {
4495: start => $start,
4496: end => $end,
4497: type => $type,
4498: };
4499: }
4500: }
1.490 raeburn 4501: }
1.1062 raeburn 4502: }
4503: }
4504: }
4505: foreach my $blocker (@blockers) {
4506: my ($staff_name,$staff_dom,$title,$blocks) =
4507: &parse_block_record($commblocks{$blocker});
4508: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4509: my ($start,$end,$triggertype);
4510: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4511: ($start,$end) = ($1,$2);
4512: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4513: $start = $triggered{$blocker}{'start'};
4514: $end = $triggered{$blocker}{'end'};
4515: $triggertype = $triggered{$blocker}{'type'};
4516: }
4517: if ($start) {
4518: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4519: if ($triggertype) {
4520: push(@{$$setters{$course}{'triggers'}},$triggertype);
4521: } else {
4522: push(@{$$setters{$course}{'triggers'}},0);
4523: }
4524: if ( ($startblock == 0) || ($startblock > $start) ) {
4525: $startblock = $start;
4526: if ($triggertype) {
4527: $triggerblock = $blocker;
1.474 raeburn 4528: }
4529: }
1.1062 raeburn 4530: if ( ($endblock == 0) || ($endblock < $end) ) {
4531: $endblock = $end;
4532: if ($triggertype) {
4533: $triggerblock = $blocker;
4534: }
4535: }
1.474 raeburn 4536: }
4537: }
1.1062 raeburn 4538: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4539: }
4540:
4541: sub parse_block_record {
4542: my ($record) = @_;
4543: my ($setuname,$setudom,$title,$blocks);
4544: if (ref($record) eq 'HASH') {
4545: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4546: $title = &unescape($record->{'event'});
4547: $blocks = $record->{'blocks'};
4548: } else {
4549: my @data = split(/:/,$record,3);
4550: if (scalar(@data) eq 2) {
4551: $title = $data[1];
4552: ($setuname,$setudom) = split(/@/,$data[0]);
4553: } else {
4554: ($setuname,$setudom,$title) = @data;
4555: }
4556: $blocks = { 'com' => 'on' };
4557: }
4558: return ($setuname,$setudom,$title,$blocks);
4559: }
4560:
1.854 kalberla 4561: sub blocking_status {
1.1062 raeburn 4562: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4563: my %setters;
1.890 droeschl 4564:
1.1061 raeburn 4565: # check for active blocking
1.1062 raeburn 4566: my ($startblock,$endblock,$triggerblock) =
4567: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4568: my $blocked = 0;
4569: if ($startblock && $endblock) {
4570: $blocked = 1;
4571: }
1.890 droeschl 4572:
1.1061 raeburn 4573: # caller just wants to know whether a block is active
4574: if (!wantarray) { return $blocked; }
4575:
4576: # build a link to a popup window containing the details
4577: my $querystring = "?activity=$activity";
4578: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4579: if ($activity eq 'port') {
4580: $querystring .= "&udom=$udom" if $udom;
4581: $querystring .= "&uname=$uname" if $uname;
4582: } elsif ($activity eq 'docs') {
4583: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4584: }
1.1061 raeburn 4585:
4586: my $output .= <<'END_MYBLOCK';
4587: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4588: var options = "width=" + w + ",height=" + h + ",";
4589: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4590: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4591: var newWin = window.open(url, wdwName, options);
4592: newWin.focus();
4593: }
1.890 droeschl 4594: END_MYBLOCK
1.854 kalberla 4595:
1.1061 raeburn 4596: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4597:
1.1061 raeburn 4598: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4599: my $text = &mt('Communication Blocked');
4600: if ($activity eq 'docs') {
4601: $text = &mt('Content Access Blocked');
1.1063 raeburn 4602: } elsif ($activity eq 'printout') {
4603: $text = &mt('Printing Blocked');
1.1062 raeburn 4604: }
1.1061 raeburn 4605: $output .= <<"END_BLOCK";
1.867 kalberla 4606: <div class='LC_comblock'>
1.869 kalberla 4607: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4608: title='$text'>
4609: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4610: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4611: title='$text'>$text</a>
1.867 kalberla 4612: </div>
4613:
4614: END_BLOCK
1.474 raeburn 4615:
1.1061 raeburn 4616: return ($blocked, $output);
1.854 kalberla 4617: }
1.490 raeburn 4618:
1.60 matthew 4619: ###############################################
4620:
1.682 raeburn 4621: sub check_ip_acc {
4622: my ($acc)=@_;
4623: &Apache::lonxml::debug("acc is $acc");
4624: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4625: return 1;
4626: }
4627: my $allowed=0;
4628: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4629:
4630: my $name;
4631: foreach my $pattern (split(',',$acc)) {
4632: $pattern =~ s/^\s*//;
4633: $pattern =~ s/\s*$//;
4634: if ($pattern =~ /\*$/) {
4635: #35.8.*
4636: $pattern=~s/\*//;
4637: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4638: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4639: #35.8.3.[34-56]
4640: my $low=$2;
4641: my $high=$3;
4642: $pattern=$1;
4643: if ($ip =~ /^\Q$pattern\E/) {
4644: my $last=(split(/\./,$ip))[3];
4645: if ($last <=$high && $last >=$low) { $allowed=1; }
4646: }
4647: } elsif ($pattern =~ /^\*/) {
4648: #*.msu.edu
4649: $pattern=~s/\*//;
4650: if (!defined($name)) {
4651: use Socket;
4652: my $netaddr=inet_aton($ip);
4653: ($name)=gethostbyaddr($netaddr,AF_INET);
4654: }
4655: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4656: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4657: #127.0.0.1
4658: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4659: } else {
4660: #some.name.com
4661: if (!defined($name)) {
4662: use Socket;
4663: my $netaddr=inet_aton($ip);
4664: ($name)=gethostbyaddr($netaddr,AF_INET);
4665: }
4666: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4667: }
4668: if ($allowed) { last; }
4669: }
4670: return $allowed;
4671: }
4672:
4673: ###############################################
4674:
1.60 matthew 4675: =pod
4676:
1.112 bowersj2 4677: =head1 Domain Template Functions
4678:
4679: =over 4
4680:
4681: =item * &determinedomain()
1.60 matthew 4682:
4683: Inputs: $domain (usually will be undef)
4684:
1.63 www 4685: Returns: Determines which domain should be used for designs
1.60 matthew 4686:
4687: =cut
1.54 www 4688:
1.60 matthew 4689: ###############################################
1.63 www 4690: sub determinedomain {
4691: my $domain=shift;
1.531 albertel 4692: if (! $domain) {
1.60 matthew 4693: # Determine domain if we have not been given one
1.893 raeburn 4694: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4695: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4696: if ($env{'request.role.domain'}) {
4697: $domain=$env{'request.role.domain'};
1.60 matthew 4698: }
4699: }
1.63 www 4700: return $domain;
4701: }
4702: ###############################################
1.517 raeburn 4703:
1.518 albertel 4704: sub devalidate_domconfig_cache {
4705: my ($udom)=@_;
4706: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4707: }
4708:
4709: # ---------------------- Get domain configuration for a domain
4710: sub get_domainconf {
4711: my ($udom) = @_;
4712: my $cachetime=1800;
4713: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4714: if (defined($cached)) { return %{$result}; }
4715:
4716: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4717: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4718: my (%designhash,%legacy);
1.518 albertel 4719: if (keys(%domconfig) > 0) {
4720: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4721: if (keys(%{$domconfig{'login'}})) {
4722: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4723: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4724: if ($key eq 'loginvia') {
4725: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4726: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4727: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4728: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4729: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4730: $designhash{$udom.'.login.loginvia'} = $server;
4731: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4732:
4733: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4734: } else {
1.1013 raeburn 4735: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4736: }
4737: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4738: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4739: }
1.946 raeburn 4740: }
4741: }
4742: }
4743: }
4744: } else {
4745: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4746: $designhash{$udom.'.login.'.$key.'_'.$img} =
4747: $domconfig{'login'}{$key}{$img};
4748: }
1.699 raeburn 4749: }
4750: } else {
4751: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4752: }
1.632 raeburn 4753: }
4754: } else {
4755: $legacy{'login'} = 1;
1.518 albertel 4756: }
1.632 raeburn 4757: } else {
4758: $legacy{'login'} = 1;
1.518 albertel 4759: }
4760: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4761: if (keys(%{$domconfig{'rolecolors'}})) {
4762: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4763: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4764: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4765: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4766: }
1.518 albertel 4767: }
4768: }
1.632 raeburn 4769: } else {
4770: $legacy{'rolecolors'} = 1;
1.518 albertel 4771: }
1.632 raeburn 4772: } else {
4773: $legacy{'rolecolors'} = 1;
1.518 albertel 4774: }
1.948 raeburn 4775: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4776: if ($domconfig{'autoenroll'}{'co-owners'}) {
4777: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4778: }
4779: }
1.632 raeburn 4780: if (keys(%legacy) > 0) {
4781: my %legacyhash = &get_legacy_domconf($udom);
4782: foreach my $item (keys(%legacyhash)) {
4783: if ($item =~ /^\Q$udom\E\.login/) {
4784: if ($legacy{'login'}) {
4785: $designhash{$item} = $legacyhash{$item};
4786: }
4787: } else {
4788: if ($legacy{'rolecolors'}) {
4789: $designhash{$item} = $legacyhash{$item};
4790: }
1.518 albertel 4791: }
4792: }
4793: }
1.632 raeburn 4794: } else {
4795: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4796: }
4797: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4798: $cachetime);
4799: return %designhash;
4800: }
4801:
1.632 raeburn 4802: sub get_legacy_domconf {
4803: my ($udom) = @_;
4804: my %legacyhash;
4805: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4806: my $designfile = $designdir.'/'.$udom.'.tab';
4807: if (-e $designfile) {
4808: if ( open (my $fh,"<$designfile") ) {
4809: while (my $line = <$fh>) {
4810: next if ($line =~ /^\#/);
4811: chomp($line);
4812: my ($key,$val)=(split(/\=/,$line));
4813: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4814: }
4815: close($fh);
4816: }
4817: }
1.1026 raeburn 4818: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4819: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4820: }
4821: return %legacyhash;
4822: }
4823:
1.63 www 4824: =pod
4825:
1.112 bowersj2 4826: =item * &domainlogo()
1.63 www 4827:
4828: Inputs: $domain (usually will be undef)
4829:
4830: Returns: A link to a domain logo, if the domain logo exists.
4831: If the domain logo does not exist, a description of the domain.
4832:
4833: =cut
1.112 bowersj2 4834:
1.63 www 4835: ###############################################
4836: sub domainlogo {
1.517 raeburn 4837: my $domain = &determinedomain(shift);
1.518 albertel 4838: my %designhash = &get_domainconf($domain);
1.517 raeburn 4839: # See if there is a logo
4840: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4841: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4842: if ($imgsrc =~ m{^/(adm|res)/}) {
4843: if ($imgsrc =~ m{^/res/}) {
4844: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4845: &Apache::lonnet::repcopy($local_name);
4846: }
4847: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4848: }
4849: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4850: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4851: return &Apache::lonnet::domain($domain,'description');
1.59 www 4852: } else {
1.60 matthew 4853: return '';
1.59 www 4854: }
4855: }
1.63 www 4856: ##############################################
4857:
4858: =pod
4859:
1.112 bowersj2 4860: =item * &designparm()
1.63 www 4861:
4862: Inputs: $which parameter; $domain (usually will be undef)
4863:
4864: Returns: value of designparamter $which
4865:
4866: =cut
1.112 bowersj2 4867:
1.397 albertel 4868:
1.400 albertel 4869: ##############################################
1.397 albertel 4870: sub designparm {
4871: my ($which,$domain)=@_;
4872: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4873: return $env{'environment.color.'.$which};
1.96 www 4874: }
1.63 www 4875: $domain=&determinedomain($domain);
1.1016 raeburn 4876: my %domdesign;
4877: unless ($domain eq 'public') {
4878: %domdesign = &get_domainconf($domain);
4879: }
1.520 raeburn 4880: my $output;
1.517 raeburn 4881: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4882: $output = $domdesign{$domain.'.'.$which};
1.63 www 4883: } else {
1.520 raeburn 4884: $output = $defaultdesign{$which};
4885: }
4886: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4887: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4888: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4889: if ($output =~ m{^/res/}) {
4890: my $local_name = &Apache::lonnet::filelocation('',$output);
4891: &Apache::lonnet::repcopy($local_name);
4892: }
1.520 raeburn 4893: $output = &lonhttpdurl($output);
4894: }
1.63 www 4895: }
1.520 raeburn 4896: return $output;
1.63 www 4897: }
1.59 www 4898:
1.822 bisitz 4899: ##############################################
4900: =pod
4901:
1.832 bisitz 4902: =item * &authorspace()
4903:
1.1028 raeburn 4904: Inputs: $url (usually will be undef).
1.832 bisitz 4905:
1.1028 raeburn 4906: Returns: Path to Construction Space containing the resource or
4907: directory being viewed (or for which action is being taken).
4908: If $url is provided, and begins /priv/<domain>/<uname>
4909: the path will be that portion of the $context argument.
4910: Otherwise the path will be for the author space of the current
4911: user when the current role is author, or for that of the
4912: co-author/assistant co-author space when the current role
4913: is co-author or assistant co-author.
1.832 bisitz 4914:
4915: =cut
4916:
4917: sub authorspace {
1.1028 raeburn 4918: my ($url) = @_;
4919: if ($url ne '') {
4920: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4921: return $1;
4922: }
4923: }
1.832 bisitz 4924: my $caname = '';
1.1024 www 4925: my $cadom = '';
1.1028 raeburn 4926: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4927: ($cadom,$caname) =
1.832 bisitz 4928: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4929: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4930: $caname = $env{'user.name'};
1.1024 www 4931: $cadom = $env{'user.domain'};
1.832 bisitz 4932: }
1.1028 raeburn 4933: if (($caname ne '') && ($cadom ne '')) {
4934: return "/priv/$cadom/$caname/";
4935: }
4936: return;
1.832 bisitz 4937: }
4938:
4939: ##############################################
4940: =pod
4941:
1.822 bisitz 4942: =item * &head_subbox()
4943:
4944: Inputs: $content (contains HTML code with page functions, etc.)
4945:
4946: Returns: HTML div with $content
4947: To be included in page header
4948:
4949: =cut
4950:
4951: sub head_subbox {
4952: my ($content)=@_;
4953: my $output =
1.993 raeburn 4954: '<div class="LC_head_subbox">'
1.822 bisitz 4955: .$content
4956: .'</div>'
4957: }
4958:
4959: ##############################################
4960: =pod
4961:
4962: =item * &CSTR_pageheader()
4963:
1.1026 raeburn 4964: Input: (optional) filename from which breadcrumb trail is built.
4965: In most cases no input as needed, as $env{'request.filename'}
4966: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4967:
4968: Returns: HTML div with CSTR path and recent box
4969: To be included on Construction Space pages
4970:
4971: =cut
4972:
4973: sub CSTR_pageheader {
1.1026 raeburn 4974: my ($trailfile) = @_;
4975: if ($trailfile eq '') {
4976: $trailfile = $env{'request.filename'};
4977: }
4978:
4979: # this is for resources; directories have customtitle, and crumbs
4980: # and select recent are created in lonpubdir.pm
4981:
4982: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4983: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 4984: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4985: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4986: $formaction =~ s{/+}{/}g;
1.822 bisitz 4987:
4988: my $parentpath = '';
4989: my $lastitem = '';
4990: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4991: $parentpath = $1;
4992: $lastitem = $2;
4993: } else {
4994: $lastitem = $thisdisfn;
4995: }
1.921 bisitz 4996:
4997: my $output =
1.822 bisitz 4998: '<div>'
4999: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
5000: .'<b>'.&mt('Construction Space:').'</b> '
5001: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5002: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5003: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5004:
5005: if ($lastitem) {
5006: $output .=
5007: '<span class="LC_filename">'
5008: .$lastitem
5009: .'</span>';
5010: }
5011: $output .=
5012: '<br />'
1.822 bisitz 5013: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5014: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5015: .'</form>'
5016: .&Apache::lonmenu::constspaceform()
5017: .'</div>';
1.921 bisitz 5018:
5019: return $output;
1.822 bisitz 5020: }
5021:
1.60 matthew 5022: ###############################################
5023: ###############################################
5024:
5025: =pod
5026:
1.112 bowersj2 5027: =back
5028:
1.549 albertel 5029: =head1 HTML Helpers
1.112 bowersj2 5030:
5031: =over 4
5032:
5033: =item * &bodytag()
1.60 matthew 5034:
5035: Returns a uniform header for LON-CAPA web pages.
5036:
5037: Inputs:
5038:
1.112 bowersj2 5039: =over 4
5040:
5041: =item * $title, A title to be displayed on the page.
5042:
5043: =item * $function, the current role (can be undef).
5044:
5045: =item * $addentries, extra parameters for the <body> tag.
5046:
5047: =item * $bodyonly, if defined, only return the <body> tag.
5048:
5049: =item * $domain, if defined, force a given domain.
5050:
5051: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5052: text interface only)
1.60 matthew 5053:
1.814 bisitz 5054: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5055: navigational links
1.317 albertel 5056:
1.338 albertel 5057: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5058:
1.460 albertel 5059: =item * $args, optional argument valid values are
5060: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5061: inherit_jsmath -> when creating popup window in a page,
5062: should it have jsmath forced on by the
5063: current page
1.460 albertel 5064:
1.1096 raeburn 5065: =item * $advtoolsref, optional argument, ref to an array containing
5066: inlineremote items to be added in "Functions" menu below
5067: breadcrumbs.
5068:
1.112 bowersj2 5069: =back
5070:
1.60 matthew 5071: Returns: A uniform header for LON-CAPA web pages.
5072: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5073: If $bodyonly is undef or zero, an html string containing a <body> tag and
5074: other decorations will be returned.
5075:
5076: =cut
5077:
1.54 www 5078: sub bodytag {
1.831 bisitz 5079: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5080: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5081:
1.954 raeburn 5082: my $public;
5083: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5084: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5085: $public = 1;
5086: }
1.460 albertel 5087: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5088:
1.183 matthew 5089: $function = &get_users_function() if (!$function);
1.339 albertel 5090: my $img = &designparm($function.'.img',$domain);
5091: my $font = &designparm($function.'.font',$domain);
5092: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5093:
1.803 bisitz 5094: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5095: 'bgcolor' => $pgbg,
1.339 albertel 5096: 'text' => $font,
5097: 'alink' => &designparm($function.'.alink',$domain),
5098: 'vlink' => &designparm($function.'.vlink',$domain),
5099: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5100: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5101:
1.63 www 5102: # role and realm
1.378 raeburn 5103: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5104: if ($role eq 'ca') {
1.479 albertel 5105: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5106: $realm = &plainname($rname,$rdom);
1.378 raeburn 5107: }
1.55 www 5108: # realm
1.258 albertel 5109: if ($env{'request.course.id'}) {
1.378 raeburn 5110: if ($env{'request.role'} !~ /^cr/) {
5111: $role = &Apache::lonnet::plaintext($role,&course_type());
5112: }
1.898 raeburn 5113: if ($env{'request.course.sec'}) {
5114: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5115: }
1.359 albertel 5116: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5117: } else {
5118: $role = &Apache::lonnet::plaintext($role);
1.54 www 5119: }
1.433 albertel 5120:
1.359 albertel 5121: if (!$realm) { $realm=' '; }
1.330 albertel 5122:
1.438 albertel 5123: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5124:
1.101 www 5125: # construct main body tag
1.359 albertel 5126: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5127: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5128:
1.530 albertel 5129: if ($bodyonly) {
1.60 matthew 5130: return $bodytag;
1.798 tempelho 5131: }
1.359 albertel 5132:
1.410 albertel 5133: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 5134: if ($public) {
1.433 albertel 5135: undef($role);
1.434 albertel 5136: } else {
1.1070 raeburn 5137: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5138: undef,'LC_menubuttons_link');
1.433 albertel 5139: }
1.359 albertel 5140:
1.762 bisitz 5141: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5142: #
5143: # Extra info if you are the DC
5144: my $dc_info = '';
5145: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5146: $env{'course.'.$env{'request.course.id'}.
5147: '.domain'}.'/'})) {
5148: my $cid = $env{'request.course.id'};
1.917 raeburn 5149: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5150: $dc_info =~ s/\s+$//;
1.359 albertel 5151: }
5152:
1.898 raeburn 5153: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5154: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5155:
1.916 droeschl 5156: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
5157: return $bodytag;
5158: }
1.903 droeschl 5159:
5160: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5161:
5162: # if ($env{'request.state'} eq 'construct') {
5163: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5164: # }
5165:
1.359 albertel 5166:
5167:
1.916 droeschl 5168: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5169: if ($dc_info) {
5170: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5171: }
1.916 droeschl 5172: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
5173: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5174: return $bodytag;
5175: }
1.894 droeschl 5176:
1.927 raeburn 5177: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5178: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
5179: }
1.916 droeschl 5180:
1.903 droeschl 5181: $bodytag .= Apache::lonhtmlcommon::scripttag(
5182: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 5183:
1.903 droeschl 5184: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 5185:
1.917 raeburn 5186: if ($dc_info) {
5187: $dc_info = &dc_courseid_toggle($dc_info);
5188: }
5189: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5190:
1.903 droeschl 5191: #don't show menus for public users
1.954 raeburn 5192: if (!$public){
1.903 droeschl 5193: $bodytag .= Apache::lonmenu::secondary_menu();
5194: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5195: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5196: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5197: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5198: $args->{'bread_crumbs'});
1.1096 raeburn 5199: } elsif ($forcereg) {
5200: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5201: $args->{'group'});
5202: } else {
5203: $bodytag .=
5204: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5205: $forcereg,$args->{'group'},
5206: $args->{'bread_crumbs'},
5207: $advtoolsref);
1.920 raeburn 5208: }
1.903 droeschl 5209: }else{
5210: # this is to seperate menu from content when there's no secondary
5211: # menu. Especially needed for public accessible ressources.
5212: $bodytag .= '<hr style="clear:both" />';
5213: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5214: }
1.903 droeschl 5215:
1.235 raeburn 5216: return $bodytag;
1.182 matthew 5217: }
5218:
1.917 raeburn 5219: sub dc_courseid_toggle {
5220: my ($dc_info) = @_;
1.980 raeburn 5221: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5222: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5223: &mt('(More ...)').'</a></span>'.
5224: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5225: }
5226:
1.330 albertel 5227: sub make_attr_string {
5228: my ($register,$attr_ref) = @_;
5229:
5230: if ($attr_ref && !ref($attr_ref)) {
5231: die("addentries Must be a hash ref ".
5232: join(':',caller(1))." ".
5233: join(':',caller(0))." ");
5234: }
5235:
5236: if ($register) {
1.339 albertel 5237: my ($on_load,$on_unload);
5238: foreach my $key (keys(%{$attr_ref})) {
5239: if (lc($key) eq 'onload') {
5240: $on_load.=$attr_ref->{$key}.';';
5241: delete($attr_ref->{$key});
5242:
5243: } elsif (lc($key) eq 'onunload') {
5244: $on_unload.=$attr_ref->{$key}.';';
5245: delete($attr_ref->{$key});
5246: }
5247: }
1.953 droeschl 5248: $attr_ref->{'onload'} = $on_load;
5249: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5250: }
1.339 albertel 5251:
1.330 albertel 5252: my $attr_string;
5253: foreach my $attr (keys(%$attr_ref)) {
5254: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5255: }
5256: return $attr_string;
5257: }
5258:
5259:
1.182 matthew 5260: ###############################################
1.251 albertel 5261: ###############################################
5262:
5263: =pod
5264:
5265: =item * &endbodytag()
5266:
5267: Returns a uniform footer for LON-CAPA web pages.
5268:
1.635 raeburn 5269: Inputs: 1 - optional reference to an args hash
5270: If in the hash, key for noredirectlink has a value which evaluates to true,
5271: a 'Continue' link is not displayed if the page contains an
5272: internal redirect in the <head></head> section,
5273: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5274:
5275: =cut
5276:
5277: sub endbodytag {
1.635 raeburn 5278: my ($args) = @_;
1.1080 raeburn 5279: my $endbodytag;
5280: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5281: $endbodytag='</body>';
5282: }
1.269 albertel 5283: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5284: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5285: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5286: $endbodytag=
5287: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5288: &mt('Continue').'</a>'.
5289: $endbodytag;
5290: }
1.315 albertel 5291: }
1.251 albertel 5292: return $endbodytag;
5293: }
5294:
1.352 albertel 5295: =pod
5296:
5297: =item * &standard_css()
5298:
5299: Returns a style sheet
5300:
5301: Inputs: (all optional)
5302: domain -> force to color decorate a page for a specific
5303: domain
5304: function -> force usage of a specific rolish color scheme
5305: bgcolor -> override the default page bgcolor
5306:
5307: =cut
5308:
1.343 albertel 5309: sub standard_css {
1.345 albertel 5310: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5311: $function = &get_users_function() if (!$function);
5312: my $img = &designparm($function.'.img', $domain);
5313: my $tabbg = &designparm($function.'.tabbg', $domain);
5314: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5315: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5316: #second colour for later usage
1.345 albertel 5317: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5318: my $pgbg_or_bgcolor =
5319: $bgcolor ||
1.352 albertel 5320: &designparm($function.'.pgbg', $domain);
1.382 albertel 5321: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5322: my $alink = &designparm($function.'.alink', $domain);
5323: my $vlink = &designparm($function.'.vlink', $domain);
5324: my $link = &designparm($function.'.link', $domain);
5325:
1.602 albertel 5326: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5327: my $mono = 'monospace';
1.850 bisitz 5328: my $data_table_head = $sidebg;
5329: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5330: my $data_table_dark = '#E0E0E0';
1.470 banghart 5331: my $data_table_darker = '#CCCCCC';
1.349 albertel 5332: my $data_table_highlight = '#FFFF00';
1.352 albertel 5333: my $mail_new = '#FFBB77';
5334: my $mail_new_hover = '#DD9955';
5335: my $mail_read = '#BBBB77';
5336: my $mail_read_hover = '#999944';
5337: my $mail_replied = '#AAAA88';
5338: my $mail_replied_hover = '#888855';
5339: my $mail_other = '#99BBBB';
5340: my $mail_other_hover = '#669999';
1.391 albertel 5341: my $table_header = '#DDDDDD';
1.489 raeburn 5342: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5343: my $lg_border_color = '#C8C8C8';
1.952 onken 5344: my $button_hover = '#BF2317';
1.392 albertel 5345:
1.608 albertel 5346: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5347: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5348: : '0 3px 0 4px';
1.448 albertel 5349:
1.523 albertel 5350:
1.343 albertel 5351: return <<END;
1.947 droeschl 5352:
5353: /* needed for iframe to allow 100% height in FF */
5354: body, html {
5355: margin: 0;
5356: padding: 0 0.5%;
5357: height: 99%; /* to avoid scrollbars */
5358: }
5359:
1.795 www 5360: body {
1.911 bisitz 5361: font-family: $sans;
5362: line-height:130%;
5363: font-size:0.83em;
5364: color:$font;
1.795 www 5365: }
5366:
1.959 onken 5367: a:focus,
5368: a:focus img {
1.795 www 5369: color: red;
5370: }
1.698 harmsja 5371:
1.911 bisitz 5372: form, .inline {
5373: display: inline;
1.795 www 5374: }
1.721 harmsja 5375:
1.795 www 5376: .LC_right {
1.911 bisitz 5377: text-align:right;
1.795 www 5378: }
5379:
5380: .LC_middle {
1.911 bisitz 5381: vertical-align:middle;
1.795 www 5382: }
1.721 harmsja 5383:
1.911 bisitz 5384: .LC_400Box {
5385: width:400px;
5386: }
1.721 harmsja 5387:
1.947 droeschl 5388: .LC_iframecontainer {
5389: width: 98%;
5390: margin: 0;
5391: position: fixed;
5392: top: 8.5em;
5393: bottom: 0;
5394: }
5395:
5396: .LC_iframecontainer iframe{
5397: border: none;
5398: width: 100%;
5399: height: 100%;
5400: }
5401:
1.778 bisitz 5402: .LC_filename {
5403: font-family: $mono;
5404: white-space:pre;
1.921 bisitz 5405: font-size: 120%;
1.778 bisitz 5406: }
5407:
5408: .LC_fileicon {
5409: border: none;
5410: height: 1.3em;
5411: vertical-align: text-bottom;
5412: margin-right: 0.3em;
5413: text-decoration:none;
5414: }
5415:
1.1008 www 5416: .LC_setting {
5417: text-decoration:underline;
5418: }
5419:
1.350 albertel 5420: .LC_error {
5421: color: red;
5422: }
1.795 www 5423:
1.1097 bisitz 5424: .LC_warning {
5425: color: darkorange;
5426: }
5427:
1.457 albertel 5428: .LC_diff_removed {
1.733 bisitz 5429: color: red;
1.394 albertel 5430: }
1.532 albertel 5431:
5432: .LC_info,
1.457 albertel 5433: .LC_success,
5434: .LC_diff_added {
1.350 albertel 5435: color: green;
5436: }
1.795 www 5437:
1.802 bisitz 5438: div.LC_confirm_box {
5439: background-color: #FAFAFA;
5440: border: 1px solid $lg_border_color;
5441: margin-right: 0;
5442: padding: 5px;
5443: }
5444:
5445: div.LC_confirm_box .LC_error img,
5446: div.LC_confirm_box .LC_success img {
5447: vertical-align: middle;
5448: }
5449:
1.440 albertel 5450: .LC_icon {
1.771 droeschl 5451: border: none;
1.790 droeschl 5452: vertical-align: middle;
1.771 droeschl 5453: }
5454:
1.543 albertel 5455: .LC_docs_spacer {
5456: width: 25px;
5457: height: 1px;
1.771 droeschl 5458: border: none;
1.543 albertel 5459: }
1.346 albertel 5460:
1.532 albertel 5461: .LC_internal_info {
1.735 bisitz 5462: color: #999999;
1.532 albertel 5463: }
5464:
1.794 www 5465: .LC_discussion {
1.1050 www 5466: background: $data_table_dark;
1.911 bisitz 5467: border: 1px solid black;
5468: margin: 2px;
1.794 www 5469: }
5470:
5471: .LC_disc_action_left {
1.1050 www 5472: background: $sidebg;
1.911 bisitz 5473: text-align: left;
1.1050 www 5474: padding: 4px;
5475: margin: 2px;
1.794 www 5476: }
5477:
5478: .LC_disc_action_right {
1.1050 www 5479: background: $sidebg;
1.911 bisitz 5480: text-align: right;
1.1050 www 5481: padding: 4px;
5482: margin: 2px;
1.794 www 5483: }
5484:
5485: .LC_disc_new_item {
1.911 bisitz 5486: background: white;
5487: border: 2px solid red;
1.1050 www 5488: margin: 4px;
5489: padding: 4px;
1.794 www 5490: }
5491:
5492: .LC_disc_old_item {
1.911 bisitz 5493: background: white;
1.1050 www 5494: margin: 4px;
5495: padding: 4px;
1.794 www 5496: }
5497:
1.458 albertel 5498: table.LC_pastsubmission {
5499: border: 1px solid black;
5500: margin: 2px;
5501: }
5502:
1.924 bisitz 5503: table#LC_menubuttons {
1.345 albertel 5504: width: 100%;
5505: background: $pgbg;
1.392 albertel 5506: border: 2px;
1.402 albertel 5507: border-collapse: separate;
1.803 bisitz 5508: padding: 0;
1.345 albertel 5509: }
1.392 albertel 5510:
1.801 tempelho 5511: table#LC_title_bar a {
5512: color: $fontmenu;
5513: }
1.836 bisitz 5514:
1.807 droeschl 5515: table#LC_title_bar {
1.819 tempelho 5516: clear: both;
1.836 bisitz 5517: display: none;
1.807 droeschl 5518: }
5519:
1.795 www 5520: table#LC_title_bar,
1.933 droeschl 5521: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5522: table#LC_title_bar.LC_with_remote {
1.359 albertel 5523: width: 100%;
1.392 albertel 5524: border-color: $pgbg;
5525: border-style: solid;
5526: border-width: $border;
1.379 albertel 5527: background: $pgbg;
1.801 tempelho 5528: color: $fontmenu;
1.392 albertel 5529: border-collapse: collapse;
1.803 bisitz 5530: padding: 0;
1.819 tempelho 5531: margin: 0;
1.359 albertel 5532: }
1.795 www 5533:
1.933 droeschl 5534: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5535: margin: 0;
5536: padding: 0;
1.933 droeschl 5537: position: relative;
5538: list-style: none;
1.913 droeschl 5539: }
1.933 droeschl 5540: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5541: display: inline;
5542: }
1.933 droeschl 5543:
5544: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5545: padding: 0;
1.933 droeschl 5546: margin: 0;
5547: float: left;
1.913 droeschl 5548: }
1.933 droeschl 5549: .LC_breadcrumb_tools_tools {
5550: padding: 0;
5551: margin: 0;
1.913 droeschl 5552: float: right;
5553: }
5554:
1.359 albertel 5555: table#LC_title_bar td {
5556: background: $tabbg;
5557: }
1.795 www 5558:
1.911 bisitz 5559: table#LC_menubuttons img {
1.803 bisitz 5560: border: none;
1.346 albertel 5561: }
1.795 www 5562:
1.842 droeschl 5563: .LC_breadcrumbs_component {
1.911 bisitz 5564: float: right;
5565: margin: 0 1em;
1.357 albertel 5566: }
1.842 droeschl 5567: .LC_breadcrumbs_component img {
1.911 bisitz 5568: vertical-align: middle;
1.777 tempelho 5569: }
1.795 www 5570:
1.383 albertel 5571: td.LC_table_cell_checkbox {
5572: text-align: center;
5573: }
1.795 www 5574:
5575: .LC_fontsize_small {
1.911 bisitz 5576: font-size: 70%;
1.705 tempelho 5577: }
5578:
1.844 bisitz 5579: #LC_breadcrumbs {
1.911 bisitz 5580: clear:both;
5581: background: $sidebg;
5582: border-bottom: 1px solid $lg_border_color;
5583: line-height: 2.5em;
1.933 droeschl 5584: overflow: hidden;
1.911 bisitz 5585: margin: 0;
5586: padding: 0;
1.995 raeburn 5587: text-align: left;
1.819 tempelho 5588: }
1.862 bisitz 5589:
1.1098 bisitz 5590: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5591: clear:both;
5592: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5593: border: 1px solid $sidebg;
1.1098 bisitz 5594: margin: 0 0 10px 0;
1.966 bisitz 5595: padding: 3px;
1.995 raeburn 5596: text-align: left;
1.822 bisitz 5597: }
5598:
1.795 www 5599: .LC_fontsize_medium {
1.911 bisitz 5600: font-size: 85%;
1.705 tempelho 5601: }
5602:
1.795 www 5603: .LC_fontsize_large {
1.911 bisitz 5604: font-size: 120%;
1.705 tempelho 5605: }
5606:
1.346 albertel 5607: .LC_menubuttons_inline_text {
5608: color: $font;
1.698 harmsja 5609: font-size: 90%;
1.701 harmsja 5610: padding-left:3px;
1.346 albertel 5611: }
5612:
1.934 droeschl 5613: .LC_menubuttons_inline_text img{
5614: vertical-align: middle;
5615: }
5616:
1.1051 www 5617: li.LC_menubuttons_inline_text img {
1.951 onken 5618: cursor:pointer;
1.1002 droeschl 5619: text-decoration: none;
1.951 onken 5620: }
5621:
1.526 www 5622: .LC_menubuttons_link {
5623: text-decoration: none;
5624: }
1.795 www 5625:
1.522 albertel 5626: .LC_menubuttons_category {
1.521 www 5627: color: $font;
1.526 www 5628: background: $pgbg;
1.521 www 5629: font-size: larger;
5630: font-weight: bold;
5631: }
5632:
1.346 albertel 5633: td.LC_menubuttons_text {
1.911 bisitz 5634: color: $font;
1.346 albertel 5635: }
1.706 harmsja 5636:
1.346 albertel 5637: .LC_current_location {
5638: background: $tabbg;
5639: }
1.795 www 5640:
1.938 bisitz 5641: table.LC_data_table {
1.347 albertel 5642: border: 1px solid #000000;
1.402 albertel 5643: border-collapse: separate;
1.426 albertel 5644: border-spacing: 1px;
1.610 albertel 5645: background: $pgbg;
1.347 albertel 5646: }
1.795 www 5647:
1.422 albertel 5648: .LC_data_table_dense {
5649: font-size: small;
5650: }
1.795 www 5651:
1.507 raeburn 5652: table.LC_nested_outer {
5653: border: 1px solid #000000;
1.589 raeburn 5654: border-collapse: collapse;
1.803 bisitz 5655: border-spacing: 0;
1.507 raeburn 5656: width: 100%;
5657: }
1.795 www 5658:
1.879 raeburn 5659: table.LC_innerpickbox,
1.507 raeburn 5660: table.LC_nested {
1.803 bisitz 5661: border: none;
1.589 raeburn 5662: border-collapse: collapse;
1.803 bisitz 5663: border-spacing: 0;
1.507 raeburn 5664: width: 100%;
5665: }
1.795 www 5666:
1.911 bisitz 5667: table.LC_data_table tr th,
5668: table.LC_calendar tr th,
1.879 raeburn 5669: table.LC_prior_tries tr th,
5670: table.LC_innerpickbox tr th {
1.349 albertel 5671: font-weight: bold;
5672: background-color: $data_table_head;
1.801 tempelho 5673: color:$fontmenu;
1.701 harmsja 5674: font-size:90%;
1.347 albertel 5675: }
1.795 www 5676:
1.879 raeburn 5677: table.LC_innerpickbox tr th,
5678: table.LC_innerpickbox tr td {
5679: vertical-align: top;
5680: }
5681:
1.711 raeburn 5682: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5683: background-color: #CCCCCC;
1.711 raeburn 5684: font-weight: bold;
5685: text-align: left;
5686: }
1.795 www 5687:
1.912 bisitz 5688: table.LC_data_table tr.LC_odd_row > td {
5689: background-color: $data_table_light;
5690: padding: 2px;
5691: vertical-align: top;
5692: }
5693:
1.809 bisitz 5694: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5695: background-color: $data_table_light;
1.912 bisitz 5696: vertical-align: top;
5697: }
5698:
5699: table.LC_data_table tr.LC_even_row > td {
5700: background-color: $data_table_dark;
1.425 albertel 5701: padding: 2px;
1.900 bisitz 5702: vertical-align: top;
1.347 albertel 5703: }
1.795 www 5704:
1.809 bisitz 5705: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5706: background-color: $data_table_dark;
1.900 bisitz 5707: vertical-align: top;
1.347 albertel 5708: }
1.795 www 5709:
1.425 albertel 5710: table.LC_data_table tr.LC_data_table_highlight td {
5711: background-color: $data_table_darker;
5712: }
1.795 www 5713:
1.639 raeburn 5714: table.LC_data_table tr td.LC_leftcol_header {
5715: background-color: $data_table_head;
5716: font-weight: bold;
5717: }
1.795 www 5718:
1.451 albertel 5719: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5720: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5721: font-weight: bold;
5722: font-style: italic;
5723: text-align: center;
5724: padding: 8px;
1.347 albertel 5725: }
1.795 www 5726:
1.1114 ! raeburn 5727: table.LC_data_table tr.LC_empty_row td,
! 5728: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5729: background-color: $sidebg;
5730: }
5731:
5732: table.LC_nested tr.LC_empty_row td {
5733: background-color: #FFFFFF;
5734: }
5735:
1.890 droeschl 5736: table.LC_caption {
5737: }
5738:
1.507 raeburn 5739: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5740: padding: 4ex
5741: }
1.795 www 5742:
1.507 raeburn 5743: table.LC_nested_outer tr th {
5744: font-weight: bold;
1.801 tempelho 5745: color:$fontmenu;
1.507 raeburn 5746: background-color: $data_table_head;
1.701 harmsja 5747: font-size: small;
1.507 raeburn 5748: border-bottom: 1px solid #000000;
5749: }
1.795 www 5750:
1.507 raeburn 5751: table.LC_nested_outer tr td.LC_subheader {
5752: background-color: $data_table_head;
5753: font-weight: bold;
5754: font-size: small;
5755: border-bottom: 1px solid #000000;
5756: text-align: right;
1.451 albertel 5757: }
1.795 www 5758:
1.507 raeburn 5759: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5760: background-color: #CCCCCC;
1.451 albertel 5761: font-weight: bold;
5762: font-size: small;
1.507 raeburn 5763: text-align: center;
5764: }
1.795 www 5765:
1.589 raeburn 5766: table.LC_nested tr.LC_info_row td.LC_left_item,
5767: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5768: text-align: left;
1.451 albertel 5769: }
1.795 www 5770:
1.507 raeburn 5771: table.LC_nested td {
1.735 bisitz 5772: background-color: #FFFFFF;
1.451 albertel 5773: font-size: small;
1.507 raeburn 5774: }
1.795 www 5775:
1.507 raeburn 5776: table.LC_nested_outer tr th.LC_right_item,
5777: table.LC_nested tr.LC_info_row td.LC_right_item,
5778: table.LC_nested tr.LC_odd_row td.LC_right_item,
5779: table.LC_nested tr td.LC_right_item {
1.451 albertel 5780: text-align: right;
5781: }
5782:
1.507 raeburn 5783: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5784: background-color: #EEEEEE;
1.451 albertel 5785: }
5786:
1.473 raeburn 5787: table.LC_createuser {
5788: }
5789:
5790: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5791: font-size: small;
1.473 raeburn 5792: }
5793:
5794: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5795: background-color: #CCCCCC;
1.473 raeburn 5796: font-weight: bold;
5797: text-align: center;
5798: }
5799:
1.349 albertel 5800: table.LC_calendar {
5801: border: 1px solid #000000;
5802: border-collapse: collapse;
1.917 raeburn 5803: width: 98%;
1.349 albertel 5804: }
1.795 www 5805:
1.349 albertel 5806: table.LC_calendar_pickdate {
5807: font-size: xx-small;
5808: }
1.795 www 5809:
1.349 albertel 5810: table.LC_calendar tr td {
5811: border: 1px solid #000000;
5812: vertical-align: top;
1.917 raeburn 5813: width: 14%;
1.349 albertel 5814: }
1.795 www 5815:
1.349 albertel 5816: table.LC_calendar tr td.LC_calendar_day_empty {
5817: background-color: $data_table_dark;
5818: }
1.795 www 5819:
1.779 bisitz 5820: table.LC_calendar tr td.LC_calendar_day_current {
5821: background-color: $data_table_highlight;
1.777 tempelho 5822: }
1.795 www 5823:
1.938 bisitz 5824: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5825: background-color: $mail_new;
5826: }
1.795 www 5827:
1.938 bisitz 5828: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5829: background-color: $mail_new_hover;
5830: }
1.795 www 5831:
1.938 bisitz 5832: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5833: background-color: $mail_read;
5834: }
1.795 www 5835:
1.938 bisitz 5836: /*
5837: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5838: background-color: $mail_read_hover;
5839: }
1.938 bisitz 5840: */
1.795 www 5841:
1.938 bisitz 5842: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5843: background-color: $mail_replied;
5844: }
1.795 www 5845:
1.938 bisitz 5846: /*
5847: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5848: background-color: $mail_replied_hover;
5849: }
1.938 bisitz 5850: */
1.795 www 5851:
1.938 bisitz 5852: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5853: background-color: $mail_other;
5854: }
1.795 www 5855:
1.938 bisitz 5856: /*
5857: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5858: background-color: $mail_other_hover;
5859: }
1.938 bisitz 5860: */
1.494 raeburn 5861:
1.777 tempelho 5862: table.LC_data_table tr > td.LC_browser_file,
5863: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5864: background: #AAEE77;
1.389 albertel 5865: }
1.795 www 5866:
1.777 tempelho 5867: table.LC_data_table tr > td.LC_browser_file_locked,
5868: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5869: background: #FFAA99;
1.387 albertel 5870: }
1.795 www 5871:
1.777 tempelho 5872: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5873: background: #888888;
1.779 bisitz 5874: }
1.795 www 5875:
1.777 tempelho 5876: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5877: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5878: background: #F8F866;
1.777 tempelho 5879: }
1.795 www 5880:
1.696 bisitz 5881: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5882: background: #E0E8FF;
1.387 albertel 5883: }
1.696 bisitz 5884:
1.707 bisitz 5885: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5886: /* background: #77FF77; */
1.707 bisitz 5887: }
1.795 www 5888:
1.707 bisitz 5889: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5890: border-right: 8px solid #FFFF77;
1.707 bisitz 5891: }
1.795 www 5892:
1.707 bisitz 5893: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5894: border-right: 8px solid #FFAA77;
1.707 bisitz 5895: }
1.795 www 5896:
1.707 bisitz 5897: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5898: border-right: 8px solid #FF7777;
1.707 bisitz 5899: }
1.795 www 5900:
1.707 bisitz 5901: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5902: border-right: 8px solid #AAFF77;
1.707 bisitz 5903: }
1.795 www 5904:
1.707 bisitz 5905: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5906: border-right: 8px solid #11CC55;
1.707 bisitz 5907: }
5908:
1.388 albertel 5909: span.LC_current_location {
1.701 harmsja 5910: font-size:larger;
1.388 albertel 5911: background: $pgbg;
5912: }
1.387 albertel 5913:
1.1029 www 5914: span.LC_current_nav_location {
5915: font-weight:bold;
5916: background: $sidebg;
5917: }
5918:
1.395 albertel 5919: span.LC_parm_menu_item {
5920: font-size: larger;
5921: }
1.795 www 5922:
1.395 albertel 5923: span.LC_parm_scope_all {
5924: color: red;
5925: }
1.795 www 5926:
1.395 albertel 5927: span.LC_parm_scope_folder {
5928: color: green;
5929: }
1.795 www 5930:
1.395 albertel 5931: span.LC_parm_scope_resource {
5932: color: orange;
5933: }
1.795 www 5934:
1.395 albertel 5935: span.LC_parm_part {
5936: color: blue;
5937: }
1.795 www 5938:
1.911 bisitz 5939: span.LC_parm_folder,
5940: span.LC_parm_symb {
1.395 albertel 5941: font-size: x-small;
5942: font-family: $mono;
5943: color: #AAAAAA;
5944: }
5945:
1.977 bisitz 5946: ul.LC_parm_parmlist li {
5947: display: inline-block;
5948: padding: 0.3em 0.8em;
5949: vertical-align: top;
5950: width: 150px;
5951: border-top:1px solid $lg_border_color;
5952: }
5953:
1.795 www 5954: td.LC_parm_overview_level_menu,
5955: td.LC_parm_overview_map_menu,
5956: td.LC_parm_overview_parm_selectors,
5957: td.LC_parm_overview_restrictions {
1.396 albertel 5958: border: 1px solid black;
5959: border-collapse: collapse;
5960: }
1.795 www 5961:
1.396 albertel 5962: table.LC_parm_overview_restrictions td {
5963: border-width: 1px 4px 1px 4px;
5964: border-style: solid;
5965: border-color: $pgbg;
5966: text-align: center;
5967: }
1.795 www 5968:
1.396 albertel 5969: table.LC_parm_overview_restrictions th {
5970: background: $tabbg;
5971: border-width: 1px 4px 1px 4px;
5972: border-style: solid;
5973: border-color: $pgbg;
5974: }
1.795 www 5975:
1.398 albertel 5976: table#LC_helpmenu {
1.803 bisitz 5977: border: none;
1.398 albertel 5978: height: 55px;
1.803 bisitz 5979: border-spacing: 0;
1.398 albertel 5980: }
5981:
5982: table#LC_helpmenu fieldset legend {
5983: font-size: larger;
5984: }
1.795 www 5985:
1.397 albertel 5986: table#LC_helpmenu_links {
5987: width: 100%;
5988: border: 1px solid black;
5989: background: $pgbg;
1.803 bisitz 5990: padding: 0;
1.397 albertel 5991: border-spacing: 1px;
5992: }
1.795 www 5993:
1.397 albertel 5994: table#LC_helpmenu_links tr td {
5995: padding: 1px;
5996: background: $tabbg;
1.399 albertel 5997: text-align: center;
5998: font-weight: bold;
1.397 albertel 5999: }
1.396 albertel 6000:
1.795 www 6001: table#LC_helpmenu_links a:link,
6002: table#LC_helpmenu_links a:visited,
1.397 albertel 6003: table#LC_helpmenu_links a:active {
6004: text-decoration: none;
6005: color: $font;
6006: }
1.795 www 6007:
1.397 albertel 6008: table#LC_helpmenu_links a:hover {
6009: text-decoration: underline;
6010: color: $vlink;
6011: }
1.396 albertel 6012:
1.417 albertel 6013: .LC_chrt_popup_exists {
6014: border: 1px solid #339933;
6015: margin: -1px;
6016: }
1.795 www 6017:
1.417 albertel 6018: .LC_chrt_popup_up {
6019: border: 1px solid yellow;
6020: margin: -1px;
6021: }
1.795 www 6022:
1.417 albertel 6023: .LC_chrt_popup {
6024: border: 1px solid #8888FF;
6025: background: #CCCCFF;
6026: }
1.795 www 6027:
1.421 albertel 6028: table.LC_pick_box {
6029: border-collapse: separate;
6030: background: white;
6031: border: 1px solid black;
6032: border-spacing: 1px;
6033: }
1.795 www 6034:
1.421 albertel 6035: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6036: background: $sidebg;
1.421 albertel 6037: font-weight: bold;
1.900 bisitz 6038: text-align: left;
1.740 bisitz 6039: vertical-align: top;
1.421 albertel 6040: width: 184px;
6041: padding: 8px;
6042: }
1.795 www 6043:
1.579 raeburn 6044: table.LC_pick_box td.LC_pick_box_value {
6045: text-align: left;
6046: padding: 8px;
6047: }
1.795 www 6048:
1.579 raeburn 6049: table.LC_pick_box td.LC_pick_box_select {
6050: text-align: left;
6051: padding: 8px;
6052: }
1.795 www 6053:
1.424 albertel 6054: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6055: padding: 0;
1.421 albertel 6056: height: 1px;
6057: background: black;
6058: }
1.795 www 6059:
1.421 albertel 6060: table.LC_pick_box td.LC_pick_box_submit {
6061: text-align: right;
6062: }
1.795 www 6063:
1.579 raeburn 6064: table.LC_pick_box td.LC_evenrow_value {
6065: text-align: left;
6066: padding: 8px;
6067: background-color: $data_table_light;
6068: }
1.795 www 6069:
1.579 raeburn 6070: table.LC_pick_box td.LC_oddrow_value {
6071: text-align: left;
6072: padding: 8px;
6073: background-color: $data_table_light;
6074: }
1.795 www 6075:
1.579 raeburn 6076: span.LC_helpform_receipt_cat {
6077: font-weight: bold;
6078: }
1.795 www 6079:
1.424 albertel 6080: table.LC_group_priv_box {
6081: background: white;
6082: border: 1px solid black;
6083: border-spacing: 1px;
6084: }
1.795 www 6085:
1.424 albertel 6086: table.LC_group_priv_box td.LC_pick_box_title {
6087: background: $tabbg;
6088: font-weight: bold;
6089: text-align: right;
6090: width: 184px;
6091: }
1.795 www 6092:
1.424 albertel 6093: table.LC_group_priv_box td.LC_groups_fixed {
6094: background: $data_table_light;
6095: text-align: center;
6096: }
1.795 www 6097:
1.424 albertel 6098: table.LC_group_priv_box td.LC_groups_optional {
6099: background: $data_table_dark;
6100: text-align: center;
6101: }
1.795 www 6102:
1.424 albertel 6103: table.LC_group_priv_box td.LC_groups_functionality {
6104: background: $data_table_darker;
6105: text-align: center;
6106: font-weight: bold;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv td {
6110: text-align: left;
1.803 bisitz 6111: padding: 0;
1.424 albertel 6112: }
6113:
6114: .LC_navbuttons {
6115: margin: 2ex 0ex 2ex 0ex;
6116: }
1.795 www 6117:
1.423 albertel 6118: .LC_topic_bar {
6119: font-weight: bold;
6120: background: $tabbg;
1.918 wenzelju 6121: margin: 1em 0em 1em 2em;
1.805 bisitz 6122: padding: 3px;
1.918 wenzelju 6123: font-size: 1.2em;
1.423 albertel 6124: }
1.795 www 6125:
1.423 albertel 6126: .LC_topic_bar span {
1.918 wenzelju 6127: left: 0.5em;
6128: position: absolute;
1.423 albertel 6129: vertical-align: middle;
1.918 wenzelju 6130: font-size: 1.2em;
1.423 albertel 6131: }
1.795 www 6132:
1.423 albertel 6133: table.LC_course_group_status {
6134: margin: 20px;
6135: }
1.795 www 6136:
1.423 albertel 6137: table.LC_status_selector td {
6138: vertical-align: top;
6139: text-align: center;
1.424 albertel 6140: padding: 4px;
6141: }
1.795 www 6142:
1.599 albertel 6143: div.LC_feedback_link {
1.616 albertel 6144: clear: both;
1.829 kalberla 6145: background: $sidebg;
1.779 bisitz 6146: width: 100%;
1.829 kalberla 6147: padding-bottom: 10px;
6148: border: 1px $tabbg solid;
1.833 kalberla 6149: height: 22px;
6150: line-height: 22px;
6151: padding-top: 5px;
6152: }
6153:
6154: div.LC_feedback_link img {
6155: height: 22px;
1.867 kalberla 6156: vertical-align:middle;
1.829 kalberla 6157: }
6158:
1.911 bisitz 6159: div.LC_feedback_link a {
1.829 kalberla 6160: text-decoration: none;
1.489 raeburn 6161: }
1.795 www 6162:
1.867 kalberla 6163: div.LC_comblock {
1.911 bisitz 6164: display:inline;
1.867 kalberla 6165: color:$font;
6166: font-size:90%;
6167: }
6168:
6169: div.LC_feedback_link div.LC_comblock {
6170: padding-left:5px;
6171: }
6172:
6173: div.LC_feedback_link div.LC_comblock a {
6174: color:$font;
6175: }
6176:
1.489 raeburn 6177: span.LC_feedback_link {
1.858 bisitz 6178: /* background: $feedback_link_bg; */
1.599 albertel 6179: font-size: larger;
6180: }
1.795 www 6181:
1.599 albertel 6182: span.LC_message_link {
1.858 bisitz 6183: /* background: $feedback_link_bg; */
1.599 albertel 6184: font-size: larger;
6185: position: absolute;
6186: right: 1em;
1.489 raeburn 6187: }
1.421 albertel 6188:
1.515 albertel 6189: table.LC_prior_tries {
1.524 albertel 6190: border: 1px solid #000000;
6191: border-collapse: separate;
6192: border-spacing: 1px;
1.515 albertel 6193: }
1.523 albertel 6194:
1.515 albertel 6195: table.LC_prior_tries td {
1.524 albertel 6196: padding: 2px;
1.515 albertel 6197: }
1.523 albertel 6198:
6199: .LC_answer_correct {
1.795 www 6200: background: lightgreen;
6201: color: darkgreen;
6202: padding: 6px;
1.523 albertel 6203: }
1.795 www 6204:
1.523 albertel 6205: .LC_answer_charged_try {
1.797 www 6206: background: #FFAAAA;
1.795 www 6207: color: darkred;
6208: padding: 6px;
1.523 albertel 6209: }
1.795 www 6210:
1.779 bisitz 6211: .LC_answer_not_charged_try,
1.523 albertel 6212: .LC_answer_no_grade,
6213: .LC_answer_late {
1.795 www 6214: background: lightyellow;
1.523 albertel 6215: color: black;
1.795 www 6216: padding: 6px;
1.523 albertel 6217: }
1.795 www 6218:
1.523 albertel 6219: .LC_answer_previous {
1.795 www 6220: background: lightblue;
6221: color: darkblue;
6222: padding: 6px;
1.523 albertel 6223: }
1.795 www 6224:
1.779 bisitz 6225: .LC_answer_no_message {
1.777 tempelho 6226: background: #FFFFFF;
6227: color: black;
1.795 www 6228: padding: 6px;
1.779 bisitz 6229: }
1.795 www 6230:
1.779 bisitz 6231: .LC_answer_unknown {
6232: background: orange;
6233: color: black;
1.795 www 6234: padding: 6px;
1.777 tempelho 6235: }
1.795 www 6236:
1.529 albertel 6237: span.LC_prior_numerical,
6238: span.LC_prior_string,
6239: span.LC_prior_custom,
6240: span.LC_prior_reaction,
6241: span.LC_prior_math {
1.925 bisitz 6242: font-family: $mono;
1.523 albertel 6243: white-space: pre;
6244: }
6245:
1.525 albertel 6246: span.LC_prior_string {
1.925 bisitz 6247: font-family: $mono;
1.525 albertel 6248: white-space: pre;
6249: }
6250:
1.523 albertel 6251: table.LC_prior_option {
6252: width: 100%;
6253: border-collapse: collapse;
6254: }
1.795 www 6255:
1.911 bisitz 6256: table.LC_prior_rank,
1.795 www 6257: table.LC_prior_match {
1.528 albertel 6258: border-collapse: collapse;
6259: }
1.795 www 6260:
1.528 albertel 6261: table.LC_prior_option tr td,
6262: table.LC_prior_rank tr td,
6263: table.LC_prior_match tr td {
1.524 albertel 6264: border: 1px solid #000000;
1.515 albertel 6265: }
6266:
1.855 bisitz 6267: .LC_nobreak {
1.544 albertel 6268: white-space: nowrap;
1.519 raeburn 6269: }
6270:
1.576 raeburn 6271: span.LC_cusr_emph {
6272: font-style: italic;
6273: }
6274:
1.633 raeburn 6275: span.LC_cusr_subheading {
6276: font-weight: normal;
6277: font-size: 85%;
6278: }
6279:
1.861 bisitz 6280: div.LC_docs_entry_move {
1.859 bisitz 6281: border: 1px solid #BBBBBB;
1.545 albertel 6282: background: #DDDDDD;
1.861 bisitz 6283: width: 22px;
1.859 bisitz 6284: padding: 1px;
6285: margin: 0;
1.545 albertel 6286: }
6287:
1.861 bisitz 6288: table.LC_data_table tr > td.LC_docs_entry_commands,
6289: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6290: font-size: x-small;
6291: }
1.795 www 6292:
1.861 bisitz 6293: .LC_docs_entry_parameter {
6294: white-space: nowrap;
6295: }
6296:
1.544 albertel 6297: .LC_docs_copy {
1.545 albertel 6298: color: #000099;
1.544 albertel 6299: }
1.795 www 6300:
1.544 albertel 6301: .LC_docs_cut {
1.545 albertel 6302: color: #550044;
1.544 albertel 6303: }
1.795 www 6304:
1.544 albertel 6305: .LC_docs_rename {
1.545 albertel 6306: color: #009900;
1.544 albertel 6307: }
1.795 www 6308:
1.544 albertel 6309: .LC_docs_remove {
1.545 albertel 6310: color: #990000;
6311: }
6312:
1.547 albertel 6313: .LC_docs_reinit_warn,
6314: .LC_docs_ext_edit {
6315: font-size: x-small;
6316: }
6317:
1.545 albertel 6318: table.LC_docs_adddocs td,
6319: table.LC_docs_adddocs th {
6320: border: 1px solid #BBBBBB;
6321: padding: 4px;
6322: background: #DDDDDD;
1.543 albertel 6323: }
6324:
1.584 albertel 6325: table.LC_sty_begin {
6326: background: #BBFFBB;
6327: }
1.795 www 6328:
1.584 albertel 6329: table.LC_sty_end {
6330: background: #FFBBBB;
6331: }
6332:
1.589 raeburn 6333: table.LC_double_column {
1.803 bisitz 6334: border-width: 0;
1.589 raeburn 6335: border-collapse: collapse;
6336: width: 100%;
6337: padding: 2px;
6338: }
6339:
6340: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6341: top: 2px;
1.589 raeburn 6342: left: 2px;
6343: width: 47%;
6344: vertical-align: top;
6345: }
6346:
6347: table.LC_double_column tr td.LC_right_col {
6348: top: 2px;
1.779 bisitz 6349: right: 2px;
1.589 raeburn 6350: width: 47%;
6351: vertical-align: top;
6352: }
6353:
1.591 raeburn 6354: div.LC_left_float {
6355: float: left;
6356: padding-right: 5%;
1.597 albertel 6357: padding-bottom: 4px;
1.591 raeburn 6358: }
6359:
6360: div.LC_clear_float_header {
1.597 albertel 6361: padding-bottom: 2px;
1.591 raeburn 6362: }
6363:
6364: div.LC_clear_float_footer {
1.597 albertel 6365: padding-top: 10px;
1.591 raeburn 6366: clear: both;
6367: }
6368:
1.597 albertel 6369: div.LC_grade_show_user {
1.941 bisitz 6370: /* border-left: 5px solid $sidebg; */
6371: border-top: 5px solid #000000;
6372: margin: 50px 0 0 0;
1.936 bisitz 6373: padding: 15px 0 5px 10px;
1.597 albertel 6374: }
1.795 www 6375:
1.936 bisitz 6376: div.LC_grade_show_user_odd_row {
1.941 bisitz 6377: /* border-left: 5px solid #000000; */
6378: }
6379:
6380: div.LC_grade_show_user div.LC_Box {
6381: margin-right: 50px;
1.597 albertel 6382: }
6383:
6384: div.LC_grade_submissions,
6385: div.LC_grade_message_center,
1.936 bisitz 6386: div.LC_grade_info_links {
1.597 albertel 6387: margin: 5px;
6388: width: 99%;
6389: background: #FFFFFF;
6390: }
1.795 www 6391:
1.597 albertel 6392: div.LC_grade_submissions_header,
1.936 bisitz 6393: div.LC_grade_message_center_header {
1.705 tempelho 6394: font-weight: bold;
6395: font-size: large;
1.597 albertel 6396: }
1.795 www 6397:
1.597 albertel 6398: div.LC_grade_submissions_body,
1.936 bisitz 6399: div.LC_grade_message_center_body {
1.597 albertel 6400: border: 1px solid black;
6401: width: 99%;
6402: background: #FFFFFF;
6403: }
1.795 www 6404:
1.613 albertel 6405: table.LC_scantron_action {
6406: width: 100%;
6407: }
1.795 www 6408:
1.613 albertel 6409: table.LC_scantron_action tr th {
1.698 harmsja 6410: font-weight:bold;
6411: font-style:normal;
1.613 albertel 6412: }
1.795 www 6413:
1.779 bisitz 6414: .LC_edit_problem_header,
1.614 albertel 6415: div.LC_edit_problem_footer {
1.705 tempelho 6416: font-weight: normal;
6417: font-size: medium;
1.602 albertel 6418: margin: 2px;
1.1060 bisitz 6419: background-color: $sidebg;
1.600 albertel 6420: }
1.795 www 6421:
1.600 albertel 6422: div.LC_edit_problem_header,
1.602 albertel 6423: div.LC_edit_problem_header div,
1.614 albertel 6424: div.LC_edit_problem_footer,
6425: div.LC_edit_problem_footer div,
1.602 albertel 6426: div.LC_edit_problem_editxml_header,
6427: div.LC_edit_problem_editxml_header div {
1.600 albertel 6428: margin-top: 5px;
6429: }
1.795 www 6430:
1.600 albertel 6431: div.LC_edit_problem_header_title {
1.705 tempelho 6432: font-weight: bold;
6433: font-size: larger;
1.602 albertel 6434: background: $tabbg;
6435: padding: 3px;
1.1060 bisitz 6436: margin: 0 0 5px 0;
1.602 albertel 6437: }
1.795 www 6438:
1.602 albertel 6439: table.LC_edit_problem_header_title {
6440: width: 100%;
1.600 albertel 6441: background: $tabbg;
1.602 albertel 6442: }
6443:
6444: div.LC_edit_problem_discards {
6445: float: left;
6446: padding-bottom: 5px;
6447: }
1.795 www 6448:
1.602 albertel 6449: div.LC_edit_problem_saves {
6450: float: right;
6451: padding-bottom: 5px;
1.600 albertel 6452: }
1.795 www 6453:
1.911 bisitz 6454: img.stift {
1.803 bisitz 6455: border-width: 0;
6456: vertical-align: middle;
1.677 riegler 6457: }
1.680 riegler 6458:
1.923 bisitz 6459: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6460: vertical-align: top;
1.777 tempelho 6461: }
1.795 www 6462:
1.716 raeburn 6463: div.LC_createcourse {
1.911 bisitz 6464: margin: 10px 10px 10px 10px;
1.716 raeburn 6465: }
6466:
1.917 raeburn 6467: .LC_dccid {
6468: margin: 0.2em 0 0 0;
6469: padding: 0;
6470: font-size: 90%;
6471: display:none;
6472: }
6473:
1.897 wenzelju 6474: ol.LC_primary_menu a:hover,
1.721 harmsja 6475: ol#LC_MenuBreadcrumbs a:hover,
6476: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6477: ul#LC_secondary_menu a:hover,
1.721 harmsja 6478: .LC_FormSectionClearButton input:hover
1.795 www 6479: ul.LC_TabContent li:hover a {
1.952 onken 6480: color:$button_hover;
1.911 bisitz 6481: text-decoration:none;
1.693 droeschl 6482: }
6483:
1.779 bisitz 6484: h1 {
1.911 bisitz 6485: padding: 0;
6486: line-height:130%;
1.693 droeschl 6487: }
1.698 harmsja 6488:
1.911 bisitz 6489: h2,
6490: h3,
6491: h4,
6492: h5,
6493: h6 {
6494: margin: 5px 0 5px 0;
6495: padding: 0;
6496: line-height:130%;
1.693 droeschl 6497: }
1.795 www 6498:
6499: .LC_hcell {
1.911 bisitz 6500: padding:3px 15px 3px 15px;
6501: margin: 0;
6502: background-color:$tabbg;
6503: color:$fontmenu;
6504: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6505: }
1.795 www 6506:
1.840 bisitz 6507: .LC_Box > .LC_hcell {
1.911 bisitz 6508: margin: 0 -10px 10px -10px;
1.835 bisitz 6509: }
6510:
1.721 harmsja 6511: .LC_noBorder {
1.911 bisitz 6512: border: 0;
1.698 harmsja 6513: }
1.693 droeschl 6514:
1.721 harmsja 6515: .LC_FormSectionClearButton input {
1.911 bisitz 6516: background-color:transparent;
6517: border: none;
6518: cursor:pointer;
6519: text-decoration:underline;
1.693 droeschl 6520: }
1.763 bisitz 6521:
6522: .LC_help_open_topic {
1.911 bisitz 6523: color: #FFFFFF;
6524: background-color: #EEEEFF;
6525: margin: 1px;
6526: padding: 4px;
6527: border: 1px solid #000033;
6528: white-space: nowrap;
6529: /* vertical-align: middle; */
1.759 neumanie 6530: }
1.693 droeschl 6531:
1.911 bisitz 6532: dl,
6533: ul,
6534: div,
6535: fieldset {
6536: margin: 10px 10px 10px 0;
6537: /* overflow: hidden; */
1.693 droeschl 6538: }
1.795 www 6539:
1.838 bisitz 6540: fieldset > legend {
1.911 bisitz 6541: font-weight: bold;
6542: padding: 0 5px 0 5px;
1.838 bisitz 6543: }
6544:
1.813 bisitz 6545: #LC_nav_bar {
1.911 bisitz 6546: float: left;
1.995 raeburn 6547: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6548: margin: 0 0 2px 0;
1.807 droeschl 6549: }
6550:
1.916 droeschl 6551: #LC_realm {
6552: margin: 0.2em 0 0 0;
6553: padding: 0;
6554: font-weight: bold;
6555: text-align: center;
1.995 raeburn 6556: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6557: }
6558:
1.911 bisitz 6559: #LC_nav_bar em {
6560: font-weight: bold;
6561: font-style: normal;
1.807 droeschl 6562: }
6563:
1.897 wenzelju 6564: ol.LC_primary_menu {
1.911 bisitz 6565: float: right;
1.934 droeschl 6566: margin: 0;
1.1076 raeburn 6567: padding: 0;
1.995 raeburn 6568: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6569: }
6570:
1.852 droeschl 6571: ol#LC_PathBreadcrumbs {
1.911 bisitz 6572: margin: 0;
1.693 droeschl 6573: }
6574:
1.897 wenzelju 6575: ol.LC_primary_menu li {
1.1076 raeburn 6576: color: RGB(80, 80, 80);
6577: vertical-align: middle;
6578: text-align: left;
6579: list-style: none;
6580: float: left;
6581: }
6582:
6583: ol.LC_primary_menu li a {
6584: display: block;
6585: margin: 0;
6586: padding: 0 5px 0 10px;
6587: text-decoration: none;
6588: }
6589:
6590: ol.LC_primary_menu li ul {
6591: display: none;
6592: width: 10em;
6593: background-color: $data_table_light;
6594: }
6595:
6596: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6597: display: block;
6598: position: absolute;
6599: margin: 0;
6600: padding: 0;
1.1078 raeburn 6601: z-index: 2;
1.1076 raeburn 6602: }
6603:
6604: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6605: font-size: 90%;
1.911 bisitz 6606: vertical-align: top;
1.1076 raeburn 6607: float: none;
1.1079 raeburn 6608: border-left: 1px solid black;
6609: border-right: 1px solid black;
1.1076 raeburn 6610: }
6611:
6612: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6613: background-color:$data_table_light;
1.1076 raeburn 6614: }
6615:
6616: ol.LC_primary_menu li li a:hover {
6617: color:$button_hover;
6618: background-color:$data_table_dark;
1.693 droeschl 6619: }
6620:
1.897 wenzelju 6621: ol.LC_primary_menu li img {
1.911 bisitz 6622: vertical-align: bottom;
1.934 droeschl 6623: height: 1.1em;
1.1077 raeburn 6624: margin: 0.2em 0 0 0;
1.693 droeschl 6625: }
6626:
1.897 wenzelju 6627: ol.LC_primary_menu a {
1.911 bisitz 6628: color: RGB(80, 80, 80);
6629: text-decoration: none;
1.693 droeschl 6630: }
1.795 www 6631:
1.949 droeschl 6632: ol.LC_primary_menu a.LC_new_message {
6633: font-weight:bold;
6634: color: darkred;
6635: }
6636:
1.975 raeburn 6637: ol.LC_docs_parameters {
6638: margin-left: 0;
6639: padding: 0;
6640: list-style: none;
6641: }
6642:
6643: ol.LC_docs_parameters li {
6644: margin: 0;
6645: padding-right: 20px;
6646: display: inline;
6647: }
6648:
1.976 raeburn 6649: ol.LC_docs_parameters li:before {
6650: content: "\\002022 \\0020";
6651: }
6652:
6653: li.LC_docs_parameters_title {
6654: font-weight: bold;
6655: }
6656:
6657: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6658: content: "";
6659: }
6660:
1.897 wenzelju 6661: ul#LC_secondary_menu {
1.1107 raeburn 6662: clear: right;
1.911 bisitz 6663: color: $fontmenu;
6664: background: $tabbg;
6665: list-style: none;
6666: padding: 0;
6667: margin: 0;
6668: width: 100%;
1.995 raeburn 6669: text-align: left;
1.1107 raeburn 6670: float: left;
1.808 droeschl 6671: }
6672:
1.897 wenzelju 6673: ul#LC_secondary_menu li {
1.911 bisitz 6674: font-weight: bold;
6675: line-height: 1.8em;
1.1107 raeburn 6676: border-right: 1px solid black;
6677: float: left;
6678: }
6679:
6680: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6681: background-color: $data_table_light;
6682: }
6683:
6684: ul#LC_secondary_menu li a {
1.911 bisitz 6685: padding: 0 0.8em;
1.1107 raeburn 6686: }
6687:
6688: ul#LC_secondary_menu li ul {
6689: display: none;
6690: }
6691:
6692: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6693: display: block;
6694: position: absolute;
6695: margin: 0;
6696: padding: 0;
6697: list-style:none;
6698: float: none;
6699: background-color: $data_table_light;
6700: z-index: 2;
6701: margin-left: -1px;
6702: }
6703:
6704: ul#LC_secondary_menu li ul li {
6705: font-size: 90%;
6706: vertical-align: top;
6707: border-left: 1px solid black;
1.911 bisitz 6708: border-right: 1px solid black;
1.1107 raeburn 6709: background-color: $data_table_light
6710: list-style:none;
6711: float: none;
6712: }
6713:
6714: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6715: background-color: $data_table_dark;
1.807 droeschl 6716: }
6717:
1.847 tempelho 6718: ul.LC_TabContent {
1.911 bisitz 6719: display:block;
6720: background: $sidebg;
6721: border-bottom: solid 1px $lg_border_color;
6722: list-style:none;
1.1020 raeburn 6723: margin: -1px -10px 0 -10px;
1.911 bisitz 6724: padding: 0;
1.693 droeschl 6725: }
6726:
1.795 www 6727: ul.LC_TabContent li,
6728: ul.LC_TabContentBigger li {
1.911 bisitz 6729: float:left;
1.741 harmsja 6730: }
1.795 www 6731:
1.897 wenzelju 6732: ul#LC_secondary_menu li a {
1.911 bisitz 6733: color: $fontmenu;
6734: text-decoration: none;
1.693 droeschl 6735: }
1.795 www 6736:
1.721 harmsja 6737: ul.LC_TabContent {
1.952 onken 6738: min-height:20px;
1.721 harmsja 6739: }
1.795 www 6740:
6741: ul.LC_TabContent li {
1.911 bisitz 6742: vertical-align:middle;
1.959 onken 6743: padding: 0 16px 0 10px;
1.911 bisitz 6744: background-color:$tabbg;
6745: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6746: border-left: solid 1px $font;
1.721 harmsja 6747: }
1.795 www 6748:
1.847 tempelho 6749: ul.LC_TabContent .right {
1.911 bisitz 6750: float:right;
1.847 tempelho 6751: }
6752:
1.911 bisitz 6753: ul.LC_TabContent li a,
6754: ul.LC_TabContent li {
6755: color:rgb(47,47,47);
6756: text-decoration:none;
6757: font-size:95%;
6758: font-weight:bold;
1.952 onken 6759: min-height:20px;
6760: }
6761:
1.959 onken 6762: ul.LC_TabContent li a:hover,
6763: ul.LC_TabContent li a:focus {
1.952 onken 6764: color: $button_hover;
1.959 onken 6765: background:none;
6766: outline:none;
1.952 onken 6767: }
6768:
6769: ul.LC_TabContent li:hover {
6770: color: $button_hover;
6771: cursor:pointer;
1.721 harmsja 6772: }
1.795 www 6773:
1.911 bisitz 6774: ul.LC_TabContent li.active {
1.952 onken 6775: color: $font;
1.911 bisitz 6776: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6777: border-bottom:solid 1px #FFFFFF;
6778: cursor: default;
1.744 ehlerst 6779: }
1.795 www 6780:
1.959 onken 6781: ul.LC_TabContent li.active a {
6782: color:$font;
6783: background:#FFFFFF;
6784: outline: none;
6785: }
1.1047 raeburn 6786:
6787: ul.LC_TabContent li.goback {
6788: float: left;
6789: border-left: none;
6790: }
6791:
1.870 tempelho 6792: #maincoursedoc {
1.911 bisitz 6793: clear:both;
1.870 tempelho 6794: }
6795:
6796: ul.LC_TabContentBigger {
1.911 bisitz 6797: display:block;
6798: list-style:none;
6799: padding: 0;
1.870 tempelho 6800: }
6801:
1.795 www 6802: ul.LC_TabContentBigger li {
1.911 bisitz 6803: vertical-align:bottom;
6804: height: 30px;
6805: font-size:110%;
6806: font-weight:bold;
6807: color: #737373;
1.841 tempelho 6808: }
6809:
1.957 onken 6810: ul.LC_TabContentBigger li.active {
6811: position: relative;
6812: top: 1px;
6813: }
6814:
1.870 tempelho 6815: ul.LC_TabContentBigger li a {
1.911 bisitz 6816: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6817: height: 30px;
6818: line-height: 30px;
6819: text-align: center;
6820: display: block;
6821: text-decoration: none;
1.958 onken 6822: outline: none;
1.741 harmsja 6823: }
1.795 www 6824:
1.870 tempelho 6825: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6826: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6827: color:$font;
1.744 ehlerst 6828: }
1.795 www 6829:
1.870 tempelho 6830: ul.LC_TabContentBigger li b {
1.911 bisitz 6831: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6832: display: block;
6833: float: left;
6834: padding: 0 30px;
1.957 onken 6835: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6836: }
6837:
1.956 onken 6838: ul.LC_TabContentBigger li:hover b {
6839: color:$button_hover;
6840: }
6841:
1.870 tempelho 6842: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6843: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6844: color:$font;
1.957 onken 6845: border: 0;
1.741 harmsja 6846: }
1.693 droeschl 6847:
1.870 tempelho 6848:
1.862 bisitz 6849: ul.LC_CourseBreadcrumbs {
6850: background: $sidebg;
1.1020 raeburn 6851: height: 2em;
1.862 bisitz 6852: padding-left: 10px;
1.1020 raeburn 6853: margin: 0;
1.862 bisitz 6854: list-style-position: inside;
6855: }
6856:
1.911 bisitz 6857: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6858: ol#LC_PathBreadcrumbs {
1.911 bisitz 6859: padding-left: 10px;
6860: margin: 0;
1.933 droeschl 6861: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6862: }
6863:
1.911 bisitz 6864: ol#LC_MenuBreadcrumbs li,
6865: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6866: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6867: display: inline;
1.933 droeschl 6868: white-space: normal;
1.693 droeschl 6869: }
6870:
1.823 bisitz 6871: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6872: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6873: text-decoration: none;
6874: font-size:90%;
1.693 droeschl 6875: }
1.795 www 6876:
1.969 droeschl 6877: ol#LC_MenuBreadcrumbs h1 {
6878: display: inline;
6879: font-size: 90%;
6880: line-height: 2.5em;
6881: margin: 0;
6882: padding: 0;
6883: }
6884:
1.795 www 6885: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6886: text-decoration:none;
6887: font-size:100%;
6888: font-weight:bold;
1.693 droeschl 6889: }
1.795 www 6890:
1.840 bisitz 6891: .LC_Box {
1.911 bisitz 6892: border: solid 1px $lg_border_color;
6893: padding: 0 10px 10px 10px;
1.746 neumanie 6894: }
1.795 www 6895:
1.1020 raeburn 6896: .LC_DocsBox {
6897: border: solid 1px $lg_border_color;
6898: padding: 0 0 10px 10px;
6899: }
6900:
1.795 www 6901: .LC_AboutMe_Image {
1.911 bisitz 6902: float:left;
6903: margin-right:10px;
1.747 neumanie 6904: }
1.795 www 6905:
6906: .LC_Clear_AboutMe_Image {
1.911 bisitz 6907: clear:left;
1.747 neumanie 6908: }
1.795 www 6909:
1.721 harmsja 6910: dl.LC_ListStyleClean dt {
1.911 bisitz 6911: padding-right: 5px;
6912: display: table-header-group;
1.693 droeschl 6913: }
6914:
1.721 harmsja 6915: dl.LC_ListStyleClean dd {
1.911 bisitz 6916: display: table-row;
1.693 droeschl 6917: }
6918:
1.721 harmsja 6919: .LC_ListStyleClean,
6920: .LC_ListStyleSimple,
6921: .LC_ListStyleNormal,
1.795 www 6922: .LC_ListStyleSpecial {
1.911 bisitz 6923: /* display:block; */
6924: list-style-position: inside;
6925: list-style-type: none;
6926: overflow: hidden;
6927: padding: 0;
1.693 droeschl 6928: }
6929:
1.721 harmsja 6930: .LC_ListStyleSimple li,
6931: .LC_ListStyleSimple dd,
6932: .LC_ListStyleNormal li,
6933: .LC_ListStyleNormal dd,
6934: .LC_ListStyleSpecial li,
1.795 www 6935: .LC_ListStyleSpecial dd {
1.911 bisitz 6936: margin: 0;
6937: padding: 5px 5px 5px 10px;
6938: clear: both;
1.693 droeschl 6939: }
6940:
1.721 harmsja 6941: .LC_ListStyleClean li,
6942: .LC_ListStyleClean dd {
1.911 bisitz 6943: padding-top: 0;
6944: padding-bottom: 0;
1.693 droeschl 6945: }
6946:
1.721 harmsja 6947: .LC_ListStyleSimple dd,
1.795 www 6948: .LC_ListStyleSimple li {
1.911 bisitz 6949: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6950: }
6951:
1.721 harmsja 6952: .LC_ListStyleSpecial li,
6953: .LC_ListStyleSpecial dd {
1.911 bisitz 6954: list-style-type: none;
6955: background-color: RGB(220, 220, 220);
6956: margin-bottom: 4px;
1.693 droeschl 6957: }
6958:
1.721 harmsja 6959: table.LC_SimpleTable {
1.911 bisitz 6960: margin:5px;
6961: border:solid 1px $lg_border_color;
1.795 www 6962: }
1.693 droeschl 6963:
1.721 harmsja 6964: table.LC_SimpleTable tr {
1.911 bisitz 6965: padding: 0;
6966: border:solid 1px $lg_border_color;
1.693 droeschl 6967: }
1.795 www 6968:
6969: table.LC_SimpleTable thead {
1.911 bisitz 6970: background:rgb(220,220,220);
1.693 droeschl 6971: }
6972:
1.721 harmsja 6973: div.LC_columnSection {
1.911 bisitz 6974: display: block;
6975: clear: both;
6976: overflow: hidden;
6977: margin: 0;
1.693 droeschl 6978: }
6979:
1.721 harmsja 6980: div.LC_columnSection>* {
1.911 bisitz 6981: float: left;
6982: margin: 10px 20px 10px 0;
6983: overflow:hidden;
1.693 droeschl 6984: }
1.721 harmsja 6985:
1.795 www 6986: table em {
1.911 bisitz 6987: font-weight: bold;
6988: font-style: normal;
1.748 schulted 6989: }
1.795 www 6990:
1.779 bisitz 6991: table.LC_tableBrowseRes,
1.795 www 6992: table.LC_tableOfContent {
1.911 bisitz 6993: border:none;
6994: border-spacing: 1px;
6995: padding: 3px;
6996: background-color: #FFFFFF;
6997: font-size: 90%;
1.753 droeschl 6998: }
1.789 droeschl 6999:
1.911 bisitz 7000: table.LC_tableOfContent {
7001: border-collapse: collapse;
1.789 droeschl 7002: }
7003:
1.771 droeschl 7004: table.LC_tableBrowseRes a,
1.768 schulted 7005: table.LC_tableOfContent a {
1.911 bisitz 7006: background-color: transparent;
7007: text-decoration: none;
1.753 droeschl 7008: }
7009:
1.795 www 7010: table.LC_tableOfContent img {
1.911 bisitz 7011: border: none;
7012: height: 1.3em;
7013: vertical-align: text-bottom;
7014: margin-right: 0.3em;
1.753 droeschl 7015: }
1.757 schulted 7016:
1.795 www 7017: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7018: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7019: }
7020:
1.795 www 7021: a#LC_content_toolbar_everything {
1.911 bisitz 7022: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7023: }
7024:
1.795 www 7025: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7026: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7027: }
7028:
1.795 www 7029: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7030: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7031: }
7032:
1.795 www 7033: a#LC_content_toolbar_changefolder {
1.911 bisitz 7034: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7035: }
7036:
1.795 www 7037: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7038: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7039: }
7040:
1.1043 raeburn 7041: a#LC_content_toolbar_edittoplevel {
7042: background-image:url(/res/adm/pages/edittoplevel.gif);
7043: }
7044:
1.795 www 7045: ul#LC_toolbar li a:hover {
1.911 bisitz 7046: background-position: bottom center;
1.757 schulted 7047: }
7048:
1.795 www 7049: ul#LC_toolbar {
1.911 bisitz 7050: padding: 0;
7051: margin: 2px;
7052: list-style:none;
7053: position:relative;
7054: background-color:white;
1.1082 raeburn 7055: overflow: auto;
1.757 schulted 7056: }
7057:
1.795 www 7058: ul#LC_toolbar li {
1.911 bisitz 7059: border:1px solid white;
7060: padding: 0;
7061: margin: 0;
7062: float: left;
7063: display:inline;
7064: vertical-align:middle;
1.1082 raeburn 7065: white-space: nowrap;
1.911 bisitz 7066: }
1.757 schulted 7067:
1.783 amueller 7068:
1.795 www 7069: a.LC_toolbarItem {
1.911 bisitz 7070: display:block;
7071: padding: 0;
7072: margin: 0;
7073: height: 32px;
7074: width: 32px;
7075: color:white;
7076: border: none;
7077: background-repeat:no-repeat;
7078: background-color:transparent;
1.757 schulted 7079: }
7080:
1.915 droeschl 7081: ul.LC_funclist {
7082: margin: 0;
7083: padding: 0.5em 1em 0.5em 0;
7084: }
7085:
1.933 droeschl 7086: ul.LC_funclist > li:first-child {
7087: font-weight:bold;
7088: margin-left:0.8em;
7089: }
7090:
1.915 droeschl 7091: ul.LC_funclist + ul.LC_funclist {
7092: /*
7093: left border as a seperator if we have more than
7094: one list
7095: */
7096: border-left: 1px solid $sidebg;
7097: /*
7098: this hides the left border behind the border of the
7099: outer box if element is wrapped to the next 'line'
7100: */
7101: margin-left: -1px;
7102: }
7103:
1.843 bisitz 7104: ul.LC_funclist li {
1.915 droeschl 7105: display: inline;
1.782 bisitz 7106: white-space: nowrap;
1.915 droeschl 7107: margin: 0 0 0 25px;
7108: line-height: 150%;
1.782 bisitz 7109: }
7110:
1.974 wenzelju 7111: .LC_hidden {
7112: display: none;
7113: }
7114:
1.1030 www 7115: .LCmodal-overlay {
7116: position:fixed;
7117: top:0;
7118: right:0;
7119: bottom:0;
7120: left:0;
7121: height:100%;
7122: width:100%;
7123: margin:0;
7124: padding:0;
7125: background:#999;
7126: opacity:.75;
7127: filter: alpha(opacity=75);
7128: -moz-opacity: 0.75;
7129: z-index:101;
7130: }
7131:
7132: * html .LCmodal-overlay {
7133: position: absolute;
7134: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7135: }
7136:
7137: .LCmodal-window {
7138: position:fixed;
7139: top:50%;
7140: left:50%;
7141: margin:0;
7142: padding:0;
7143: z-index:102;
7144: }
7145:
7146: * html .LCmodal-window {
7147: position:absolute;
7148: }
7149:
7150: .LCclose-window {
7151: position:absolute;
7152: width:32px;
7153: height:32px;
7154: right:8px;
7155: top:8px;
7156: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7157: text-indent:-99999px;
7158: overflow:hidden;
7159: cursor:pointer;
7160: }
7161:
1.1100 raeburn 7162: /*
7163: styles used by TTH when "Default set of options to pass to tth/m
7164: when converting TeX" in course settings has been set
7165:
7166: option passed: -t
7167:
7168: */
7169:
7170: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7171: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7172: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7173: td div.norm {line-height:normal;}
7174:
7175: /*
7176: option passed -y3
7177: */
7178:
7179: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7180: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7181: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7182:
1.343 albertel 7183: END
7184: }
7185:
1.306 albertel 7186: =pod
7187:
7188: =item * &headtag()
7189:
7190: Returns a uniform footer for LON-CAPA web pages.
7191:
1.307 albertel 7192: Inputs: $title - optional title for the head
7193: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7194: $args - optional arguments
1.319 albertel 7195: force_register - if is true call registerurl so the remote is
7196: informed
1.415 albertel 7197: redirect -> array ref of
7198: 1- seconds before redirect occurs
7199: 2- url to redirect to
7200: 3- whether the side effect should occur
1.315 albertel 7201: (side effect of setting
7202: $env{'internal.head.redirect'} to the url
7203: redirected too)
1.352 albertel 7204: domain -> force to color decorate a page for a specific
7205: domain
7206: function -> force usage of a specific rolish color scheme
7207: bgcolor -> override the default page bgcolor
1.460 albertel 7208: no_auto_mt_title
7209: -> prevent &mt()ing the title arg
1.464 albertel 7210:
1.306 albertel 7211: =cut
7212:
7213: sub headtag {
1.313 albertel 7214: my ($title,$head_extra,$args) = @_;
1.306 albertel 7215:
1.363 albertel 7216: my $function = $args->{'function'} || &get_users_function();
7217: my $domain = $args->{'domain'} || &determinedomain();
7218: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7219: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7220: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7221: #time(),
1.418 albertel 7222: $env{'environment.color.timestamp'},
1.363 albertel 7223: $function,$domain,$bgcolor);
7224:
1.369 www 7225: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7226:
1.308 albertel 7227: my $result =
7228: '<head>'.
1.461 albertel 7229: &font_settings();
1.319 albertel 7230:
1.1064 raeburn 7231: my $inhibitprint = &print_suppression();
7232:
1.461 albertel 7233: if (!$args->{'frameset'}) {
7234: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7235: }
1.962 droeschl 7236: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7237: $result .= Apache::lonxml::display_title();
1.319 albertel 7238: }
1.436 albertel 7239: if (!$args->{'no_nav_bar'}
7240: && !$args->{'only_body'}
7241: && !$args->{'frameset'}) {
7242: $result .= &help_menu_js();
1.1032 www 7243: $result.=&modal_window();
1.1038 www 7244: $result.=&togglebox_script();
1.1034 www 7245: $result.=&wishlist_window();
1.1041 www 7246: $result.=&LCprogressbarUpdate_script();
1.1034 www 7247: } else {
7248: if ($args->{'add_modal'}) {
7249: $result.=&modal_window();
7250: }
7251: if ($args->{'add_wishlist'}) {
7252: $result.=&wishlist_window();
7253: }
1.1038 www 7254: if ($args->{'add_togglebox'}) {
7255: $result.=&togglebox_script();
7256: }
1.1041 www 7257: if ($args->{'add_progressbar'}) {
7258: $result.=&LCprogressbarUpdate_script();
7259: }
1.436 albertel 7260: }
1.314 albertel 7261: if (ref($args->{'redirect'})) {
1.414 albertel 7262: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7263: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7264: if (!$inhibit_continue) {
7265: $env{'internal.head.redirect'} = $url;
7266: }
1.313 albertel 7267: $result.=<<ADDMETA
7268: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7269: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7270: ADDMETA
7271: }
1.306 albertel 7272: if (!defined($title)) {
7273: $title = 'The LearningOnline Network with CAPA';
7274: }
1.460 albertel 7275: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7276: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7277: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7278: .$inhibitprint
1.414 albertel 7279: .$head_extra;
1.962 droeschl 7280: return $result.'</head>';
1.306 albertel 7281: }
7282:
7283: =pod
7284:
1.340 albertel 7285: =item * &font_settings()
7286:
7287: Returns neccessary <meta> to set the proper encoding
7288:
7289: Inputs: none
7290:
7291: =cut
7292:
7293: sub font_settings {
7294: my $headerstring='';
1.647 www 7295: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7296: $headerstring.=
7297: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7298: }
7299: return $headerstring;
7300: }
7301:
1.341 albertel 7302: =pod
7303:
1.1064 raeburn 7304: =item * &print_suppression()
7305:
7306: In course context returns css which causes the body to be blank when media="print",
7307: if printout generation is unavailable for the current resource.
7308:
7309: This could be because:
7310:
7311: (a) printstartdate is in the future
7312:
7313: (b) printenddate is in the past
7314:
7315: (c) there is an active exam block with "printout"
7316: functionality blocked
7317:
7318: Users with pav, pfo or evb privileges are exempt.
7319:
7320: Inputs: none
7321:
7322: =cut
7323:
7324:
7325: sub print_suppression {
7326: my $noprint;
7327: if ($env{'request.course.id'}) {
7328: my $scope = $env{'request.course.id'};
7329: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7330: (&Apache::lonnet::allowed('pfo',$scope))) {
7331: return;
7332: }
7333: if ($env{'request.course.sec'} ne '') {
7334: $scope .= "/$env{'request.course.sec'}";
7335: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7336: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7337: return;
1.1064 raeburn 7338: }
7339: }
7340: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7341: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7342: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7343: if ($blocked) {
7344: my $checkrole = "cm./$cdom/$cnum";
7345: if ($env{'request.course.sec'} ne '') {
7346: $checkrole .= "/$env{'request.course.sec'}";
7347: }
7348: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7349: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7350: $noprint = 1;
7351: }
7352: }
7353: unless ($noprint) {
7354: my $symb = &Apache::lonnet::symbread();
7355: if ($symb ne '') {
7356: my $navmap = Apache::lonnavmaps::navmap->new();
7357: if (ref($navmap)) {
7358: my $res = $navmap->getBySymb($symb);
7359: if (ref($res)) {
7360: if (!$res->resprintable()) {
7361: $noprint = 1;
7362: }
7363: }
7364: }
7365: }
7366: }
7367: if ($noprint) {
7368: return <<"ENDSTYLE";
7369: <style type="text/css" media="print">
7370: body { display:none }
7371: </style>
7372: ENDSTYLE
7373: }
7374: }
7375: return;
7376: }
7377:
7378: =pod
7379:
1.341 albertel 7380: =item * &xml_begin()
7381:
7382: Returns the needed doctype and <html>
7383:
7384: Inputs: none
7385:
7386: =cut
7387:
7388: sub xml_begin {
7389: my $output='';
7390:
7391: if ($env{'browser.mathml'}) {
7392: $output='<?xml version="1.0"?>'
7393: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7394: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7395:
7396: # .'<!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">] >'
7397: .'<!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">'
7398: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7399: .'xmlns="http://www.w3.org/1999/xhtml">';
7400: } else {
1.849 bisitz 7401: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7402: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7403: }
7404: return $output;
7405: }
1.340 albertel 7406:
7407: =pod
7408:
1.306 albertel 7409: =item * &start_page()
7410:
7411: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7412:
1.648 raeburn 7413: Inputs:
7414:
7415: =over 4
7416:
7417: $title - optional title for the page
7418:
7419: $head_extra - optional extra HTML to incude inside the <head>
7420:
7421: $args - additional optional args supported are:
7422:
7423: =over 8
7424:
7425: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7426: arg on
1.814 bisitz 7427: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7428: add_entries -> additional attributes to add to the <body>
7429: domain -> force to color decorate a page for a
1.317 albertel 7430: specific domain
1.648 raeburn 7431: function -> force usage of a specific rolish color
1.317 albertel 7432: scheme
1.648 raeburn 7433: redirect -> see &headtag()
7434: bgcolor -> override the default page bg color
7435: js_ready -> return a string ready for being used in
1.317 albertel 7436: a javascript writeln
1.648 raeburn 7437: html_encode -> return a string ready for being used in
1.320 albertel 7438: a html attribute
1.648 raeburn 7439: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7440: $forcereg arg
1.648 raeburn 7441: frameset -> if true will start with a <frameset>
1.330 albertel 7442: rather than <body>
1.648 raeburn 7443: skip_phases -> hash ref of
1.338 albertel 7444: head -> skip the <html><head> generation
7445: body -> skip all <body> generation
1.648 raeburn 7446: no_auto_mt_title -> prevent &mt()ing the title arg
7447: inherit_jsmath -> when creating popup window in a page,
7448: should it have jsmath forced on by the
7449: current page
1.867 kalberla 7450: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7451: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7452: group -> includes the current group, if page is for a
7453: specific group
1.361 albertel 7454:
1.648 raeburn 7455: =back
1.460 albertel 7456:
1.648 raeburn 7457: =back
1.562 albertel 7458:
1.306 albertel 7459: =cut
7460:
7461: sub start_page {
1.309 albertel 7462: my ($title,$head_extra,$args) = @_;
1.318 albertel 7463: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7464:
1.315 albertel 7465: $env{'internal.start_page'}++;
1.1096 raeburn 7466: my ($result,@advtools);
1.964 droeschl 7467:
1.338 albertel 7468: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7469: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7470: }
7471:
7472: if (! exists($args->{'skip_phases'}{'body'}) ) {
7473: if ($args->{'frameset'}) {
7474: my $attr_string = &make_attr_string($args->{'force_register'},
7475: $args->{'add_entries'});
7476: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7477: } else {
7478: $result .=
7479: &bodytag($title,
7480: $args->{'function'}, $args->{'add_entries'},
7481: $args->{'only_body'}, $args->{'domain'},
7482: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7483: $args->{'bgcolor'}, $args,
7484: \@advtools);
1.831 bisitz 7485: }
1.330 albertel 7486: }
1.338 albertel 7487:
1.315 albertel 7488: if ($args->{'js_ready'}) {
1.713 kaisler 7489: $result = &js_ready($result);
1.315 albertel 7490: }
1.320 albertel 7491: if ($args->{'html_encode'}) {
1.713 kaisler 7492: $result = &html_encode($result);
7493: }
7494:
1.813 bisitz 7495: # Preparation for new and consistent functionlist at top of screen
7496: # if ($args->{'functionlist'}) {
7497: # $result .= &build_functionlist();
7498: #}
7499:
1.964 droeschl 7500: # Don't add anything more if only_body wanted or in const space
7501: return $result if $args->{'only_body'}
7502: || $env{'request.state'} eq 'construct';
1.813 bisitz 7503:
7504: #Breadcrumbs
1.758 kaisler 7505: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7506: &Apache::lonhtmlcommon::clear_breadcrumbs();
7507: #if any br links exists, add them to the breadcrumbs
7508: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7509: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7510: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7511: }
7512: }
1.1096 raeburn 7513: # if @advtools array contains items add then to the breadcrumbs
7514: if (@advtools > 0) {
7515: &Apache::lonmenu::advtools_crumbs(@advtools);
7516: }
1.758 kaisler 7517:
7518: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7519: if(exists($args->{'bread_crumbs_component'})){
7520: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7521: }else{
7522: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7523: }
1.320 albertel 7524: }
1.315 albertel 7525: return $result;
1.306 albertel 7526: }
7527:
7528: sub end_page {
1.315 albertel 7529: my ($args) = @_;
7530: $env{'internal.end_page'}++;
1.330 albertel 7531: my $result;
1.335 albertel 7532: if ($args->{'discussion'}) {
7533: my ($target,$parser);
7534: if (ref($args->{'discussion'})) {
7535: ($target,$parser) =($args->{'discussion'}{'target'},
7536: $args->{'discussion'}{'parser'});
7537: }
7538: $result .= &Apache::lonxml::xmlend($target,$parser);
7539: }
1.330 albertel 7540: if ($args->{'frameset'}) {
7541: $result .= '</frameset>';
7542: } else {
1.635 raeburn 7543: $result .= &endbodytag($args);
1.330 albertel 7544: }
1.1080 raeburn 7545: unless ($args->{'notbody'}) {
7546: $result .= "\n</html>";
7547: }
1.330 albertel 7548:
1.315 albertel 7549: if ($args->{'js_ready'}) {
1.317 albertel 7550: $result = &js_ready($result);
1.315 albertel 7551: }
1.335 albertel 7552:
1.320 albertel 7553: if ($args->{'html_encode'}) {
7554: $result = &html_encode($result);
7555: }
1.335 albertel 7556:
1.315 albertel 7557: return $result;
7558: }
7559:
1.1034 www 7560: sub wishlist_window {
7561: return(<<'ENDWISHLIST');
1.1046 raeburn 7562: <script type="text/javascript">
1.1034 www 7563: // <![CDATA[
7564: // <!-- BEGIN LON-CAPA Internal
7565: function set_wishlistlink(title, path) {
7566: if (!title) {
7567: title = document.title;
7568: title = title.replace(/^LON-CAPA /,'');
7569: }
7570: if (!path) {
7571: path = location.pathname;
7572: }
7573: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7574: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7575: }
7576: // END LON-CAPA Internal -->
7577: // ]]>
7578: </script>
7579: ENDWISHLIST
7580: }
7581:
1.1030 www 7582: sub modal_window {
7583: return(<<'ENDMODAL');
1.1046 raeburn 7584: <script type="text/javascript">
1.1030 www 7585: // <![CDATA[
7586: // <!-- BEGIN LON-CAPA Internal
7587: var modalWindow = {
7588: parent:"body",
7589: windowId:null,
7590: content:null,
7591: width:null,
7592: height:null,
7593: close:function()
7594: {
7595: $(".LCmodal-window").remove();
7596: $(".LCmodal-overlay").remove();
7597: },
7598: open:function()
7599: {
7600: var modal = "";
7601: modal += "<div class=\"LCmodal-overlay\"></div>";
7602: 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;\">";
7603: modal += this.content;
7604: modal += "</div>";
7605:
7606: $(this.parent).append(modal);
7607:
7608: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7609: $(".LCclose-window").click(function(){modalWindow.close();});
7610: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7611: }
7612: };
1.1031 www 7613: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7614: {
7615: modalWindow.windowId = "myModal";
7616: modalWindow.width = width;
7617: modalWindow.height = height;
1.1031 www 7618: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7619: modalWindow.open();
7620: };
7621: // END LON-CAPA Internal -->
7622: // ]]>
7623: </script>
7624: ENDMODAL
7625: }
7626:
7627: sub modal_link {
1.1052 www 7628: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7629: unless ($width) { $width=480; }
7630: unless ($height) { $height=400; }
1.1031 www 7631: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7632: my $target_attr;
7633: if (defined($target)) {
7634: $target_attr = 'target="'.$target.'"';
7635: }
7636: return <<"ENDLINK";
7637: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7638: $linktext</a>
7639: ENDLINK
1.1030 www 7640: }
7641:
1.1032 www 7642: sub modal_adhoc_script {
7643: my ($funcname,$width,$height,$content)=@_;
7644: return (<<ENDADHOC);
1.1046 raeburn 7645: <script type="text/javascript">
1.1032 www 7646: // <![CDATA[
7647: var $funcname = function()
7648: {
7649: modalWindow.windowId = "myModal";
7650: modalWindow.width = $width;
7651: modalWindow.height = $height;
7652: modalWindow.content = '$content';
7653: modalWindow.open();
7654: };
7655: // ]]>
7656: </script>
7657: ENDADHOC
7658: }
7659:
1.1041 www 7660: sub modal_adhoc_inner {
7661: my ($funcname,$width,$height,$content)=@_;
7662: my $innerwidth=$width-20;
7663: $content=&js_ready(
1.1042 www 7664: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041 www 7665: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
7666: $content.
7667: &end_scrollbox().
7668: &end_page()
7669: );
7670: return &modal_adhoc_script($funcname,$width,$height,$content);
7671: }
7672:
7673: sub modal_adhoc_window {
7674: my ($funcname,$width,$height,$content,$linktext)=@_;
7675: return &modal_adhoc_inner($funcname,$width,$height,$content).
7676: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7677: }
7678:
7679: sub modal_adhoc_launch {
7680: my ($funcname,$width,$height,$content)=@_;
7681: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7682: <script type="text/javascript">
7683: // <![CDATA[
7684: $funcname();
7685: // ]]>
7686: </script>
7687: ENDLAUNCH
7688: }
7689:
7690: sub modal_adhoc_close {
7691: return (<<ENDCLOSE);
7692: <script type="text/javascript">
7693: // <![CDATA[
7694: modalWindow.close();
7695: // ]]>
7696: </script>
7697: ENDCLOSE
7698: }
7699:
1.1038 www 7700: sub togglebox_script {
7701: return(<<ENDTOGGLE);
7702: <script type="text/javascript">
7703: // <![CDATA[
7704: function LCtoggleDisplay(id,hidetext,showtext) {
7705: link = document.getElementById(id + "link").childNodes[0];
7706: with (document.getElementById(id).style) {
7707: if (display == "none" ) {
7708: display = "inline";
7709: link.nodeValue = hidetext;
7710: } else {
7711: display = "none";
7712: link.nodeValue = showtext;
7713: }
7714: }
7715: }
7716: // ]]>
7717: </script>
7718: ENDTOGGLE
7719: }
7720:
1.1039 www 7721: sub start_togglebox {
7722: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7723: unless ($heading) { $heading=''; } else { $heading.=' '; }
7724: unless ($showtext) { $showtext=&mt('show'); }
7725: unless ($hidetext) { $hidetext=&mt('hide'); }
7726: unless ($headerbg) { $headerbg='#FFFFFF'; }
7727: return &start_data_table().
7728: &start_data_table_header_row().
7729: '<td bgcolor="'.$headerbg.'">'.$heading.
7730: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7731: $showtext.'\')">'.$showtext.'</a>]</td>'.
7732: &end_data_table_header_row().
7733: '<tr id="'.$id.'" style="display:none""><td>';
7734: }
7735:
7736: sub end_togglebox {
7737: return '</td></tr>'.&end_data_table();
7738: }
7739:
1.1041 www 7740: sub LCprogressbar_script {
1.1045 www 7741: my ($id)=@_;
1.1041 www 7742: return(<<ENDPROGRESS);
7743: <script type="text/javascript">
7744: // <![CDATA[
1.1045 www 7745: \$('#progressbar$id').progressbar({
1.1041 www 7746: value: 0,
7747: change: function(event, ui) {
7748: var newVal = \$(this).progressbar('option', 'value');
7749: \$('.pblabel', this).text(LCprogressTxt);
7750: }
7751: });
7752: // ]]>
7753: </script>
7754: ENDPROGRESS
7755: }
7756:
7757: sub LCprogressbarUpdate_script {
7758: return(<<ENDPROGRESSUPDATE);
7759: <style type="text/css">
7760: .ui-progressbar { position:relative; }
7761: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7762: </style>
7763: <script type="text/javascript">
7764: // <![CDATA[
1.1045 www 7765: var LCprogressTxt='---';
7766:
7767: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7768: LCprogressTxt=progresstext;
1.1045 www 7769: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7770: }
7771: // ]]>
7772: </script>
7773: ENDPROGRESSUPDATE
7774: }
7775:
1.1042 www 7776: my $LClastpercent;
1.1045 www 7777: my $LCidcnt;
7778: my $LCcurrentid;
1.1042 www 7779:
1.1041 www 7780: sub LCprogressbar {
1.1042 www 7781: my ($r)=(@_);
7782: $LClastpercent=0;
1.1045 www 7783: $LCidcnt++;
7784: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7785: my $starting=&mt('Starting');
7786: my $content=(<<ENDPROGBAR);
7787: <p>
1.1045 www 7788: <div id="progressbar$LCcurrentid">
1.1041 www 7789: <span class="pblabel">$starting</span>
7790: </div>
7791: </p>
7792: ENDPROGBAR
1.1045 www 7793: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7794: }
7795:
7796: sub LCprogressbarUpdate {
1.1042 www 7797: my ($r,$val,$text)=@_;
7798: unless ($val) {
7799: if ($LClastpercent) {
7800: $val=$LClastpercent;
7801: } else {
7802: $val=0;
7803: }
7804: }
1.1041 www 7805: if ($val<0) { $val=0; }
7806: if ($val>100) { $val=0; }
1.1042 www 7807: $LClastpercent=$val;
1.1041 www 7808: unless ($text) { $text=$val.'%'; }
7809: $text=&js_ready($text);
1.1044 www 7810: &r_print($r,<<ENDUPDATE);
1.1041 www 7811: <script type="text/javascript">
7812: // <![CDATA[
1.1045 www 7813: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7814: // ]]>
7815: </script>
7816: ENDUPDATE
1.1035 www 7817: }
7818:
1.1042 www 7819: sub LCprogressbarClose {
7820: my ($r)=@_;
7821: $LClastpercent=0;
1.1044 www 7822: &r_print($r,<<ENDCLOSE);
1.1042 www 7823: <script type="text/javascript">
7824: // <![CDATA[
1.1045 www 7825: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7826: // ]]>
7827: </script>
7828: ENDCLOSE
1.1044 www 7829: }
7830:
7831: sub r_print {
7832: my ($r,$to_print)=@_;
7833: if ($r) {
7834: $r->print($to_print);
7835: $r->rflush();
7836: } else {
7837: print($to_print);
7838: }
1.1042 www 7839: }
7840:
1.320 albertel 7841: sub html_encode {
7842: my ($result) = @_;
7843:
1.322 albertel 7844: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7845:
7846: return $result;
7847: }
1.1044 www 7848:
1.317 albertel 7849: sub js_ready {
7850: my ($result) = @_;
7851:
1.323 albertel 7852: $result =~ s/[\n\r]/ /xmsg;
7853: $result =~ s/\\/\\\\/xmsg;
7854: $result =~ s/'/\\'/xmsg;
1.372 albertel 7855: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7856:
7857: return $result;
7858: }
7859:
1.315 albertel 7860: sub validate_page {
7861: if ( exists($env{'internal.start_page'})
1.316 albertel 7862: && $env{'internal.start_page'} > 1) {
7863: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7864: $env{'internal.start_page'}.' '.
1.316 albertel 7865: $ENV{'request.filename'});
1.315 albertel 7866: }
7867: if ( exists($env{'internal.end_page'})
1.316 albertel 7868: && $env{'internal.end_page'} > 1) {
7869: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7870: $env{'internal.end_page'}.' '.
1.316 albertel 7871: $env{'request.filename'});
1.315 albertel 7872: }
7873: if ( exists($env{'internal.start_page'})
7874: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7875: &Apache::lonnet::logthis('start_page called without end_page '.
7876: $env{'request.filename'});
1.315 albertel 7877: }
7878: if ( ! exists($env{'internal.start_page'})
7879: && exists($env{'internal.end_page'})) {
1.316 albertel 7880: &Apache::lonnet::logthis('end_page called without start_page'.
7881: $env{'request.filename'});
1.315 albertel 7882: }
1.306 albertel 7883: }
1.315 albertel 7884:
1.996 www 7885:
7886: sub start_scrollbox {
1.1075 raeburn 7887: my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998 raeburn 7888: unless ($outerwidth) { $outerwidth='520px'; }
7889: unless ($width) { $width='500px'; }
7890: unless ($height) { $height='200px'; }
1.1075 raeburn 7891: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7892: if ($id ne '') {
1.1020 raeburn 7893: $table_id = " id='table_$id'";
7894: $div_id = " id='div_$id'";
1.1018 raeburn 7895: }
1.1075 raeburn 7896: if ($bgcolor ne '') {
7897: $tdcol = "background-color: $bgcolor;";
7898: }
7899: return <<"END";
7900: <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>
7901: END
1.996 www 7902: }
7903:
7904: sub end_scrollbox {
1.1036 www 7905: return '</div></td></tr></table>';
1.996 www 7906: }
7907:
1.318 albertel 7908: sub simple_error_page {
7909: my ($r,$title,$msg) = @_;
7910: my $page =
7911: &Apache::loncommon::start_page($title).
1.1097 bisitz 7912: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 7913: &Apache::loncommon::end_page();
7914: if (ref($r)) {
7915: $r->print($page);
1.327 albertel 7916: return;
1.318 albertel 7917: }
7918: return $page;
7919: }
1.347 albertel 7920:
7921: {
1.610 albertel 7922: my @row_count;
1.961 onken 7923:
7924: sub start_data_table_count {
7925: unshift(@row_count, 0);
7926: return;
7927: }
7928:
7929: sub end_data_table_count {
7930: shift(@row_count);
7931: return;
7932: }
7933:
1.347 albertel 7934: sub start_data_table {
1.1018 raeburn 7935: my ($add_class,$id) = @_;
1.422 albertel 7936: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7937: my $table_id;
7938: if (defined($id)) {
7939: $table_id = ' id="'.$id.'"';
7940: }
1.961 onken 7941: &start_data_table_count();
1.1018 raeburn 7942: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7943: }
7944:
7945: sub end_data_table {
1.961 onken 7946: &end_data_table_count();
1.389 albertel 7947: return '</table>'."\n";;
1.347 albertel 7948: }
7949:
7950: sub start_data_table_row {
1.974 wenzelju 7951: my ($add_class, $id) = @_;
1.610 albertel 7952: $row_count[0]++;
7953: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7954: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7955: $id = (' id="'.$id.'"') unless ($id eq '');
7956: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7957: }
1.471 banghart 7958:
7959: sub continue_data_table_row {
1.974 wenzelju 7960: my ($add_class, $id) = @_;
1.610 albertel 7961: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7962: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7963: $id = (' id="'.$id.'"') unless ($id eq '');
7964: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7965: }
1.347 albertel 7966:
7967: sub end_data_table_row {
1.389 albertel 7968: return '</tr>'."\n";;
1.347 albertel 7969: }
1.367 www 7970:
1.421 albertel 7971: sub start_data_table_empty_row {
1.707 bisitz 7972: # $row_count[0]++;
1.421 albertel 7973: return '<tr class="LC_empty_row" >'."\n";;
7974: }
7975:
7976: sub end_data_table_empty_row {
7977: return '</tr>'."\n";;
7978: }
7979:
1.367 www 7980: sub start_data_table_header_row {
1.389 albertel 7981: return '<tr class="LC_header_row">'."\n";;
1.367 www 7982: }
7983:
7984: sub end_data_table_header_row {
1.389 albertel 7985: return '</tr>'."\n";;
1.367 www 7986: }
1.890 droeschl 7987:
7988: sub data_table_caption {
7989: my $caption = shift;
7990: return "<caption class=\"LC_caption\">$caption</caption>";
7991: }
1.347 albertel 7992: }
7993:
1.548 albertel 7994: =pod
7995:
7996: =item * &inhibit_menu_check($arg)
7997:
7998: Checks for a inhibitmenu state and generates output to preserve it
7999:
8000: Inputs: $arg - can be any of
8001: - undef - in which case the return value is a string
8002: to add into arguments list of a uri
8003: - 'input' - in which case the return value is a HTML
8004: <form> <input> field of type hidden to
8005: preserve the value
8006: - a url - in which case the return value is the url with
8007: the neccesary cgi args added to preserve the
8008: inhibitmenu state
8009: - a ref to a url - no return value, but the string is
8010: updated to include the neccessary cgi
8011: args to preserve the inhibitmenu state
8012:
8013: =cut
8014:
8015: sub inhibit_menu_check {
8016: my ($arg) = @_;
8017: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8018: if ($arg eq 'input') {
8019: if ($env{'form.inhibitmenu'}) {
8020: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8021: } else {
8022: return
8023: }
8024: }
8025: if ($env{'form.inhibitmenu'}) {
8026: if (ref($arg)) {
8027: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8028: } elsif ($arg eq '') {
8029: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8030: } else {
8031: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8032: }
8033: }
8034: if (!ref($arg)) {
8035: return $arg;
8036: }
8037: }
8038:
1.251 albertel 8039: ###############################################
1.182 matthew 8040:
8041: =pod
8042:
1.549 albertel 8043: =back
8044:
8045: =head1 User Information Routines
8046:
8047: =over 4
8048:
1.405 albertel 8049: =item * &get_users_function()
1.182 matthew 8050:
8051: Used by &bodytag to determine the current users primary role.
8052: Returns either 'student','coordinator','admin', or 'author'.
8053:
8054: =cut
8055:
8056: ###############################################
8057: sub get_users_function {
1.815 tempelho 8058: my $function = 'norole';
1.818 tempelho 8059: if ($env{'request.role'}=~/^(st)/) {
8060: $function='student';
8061: }
1.907 raeburn 8062: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8063: $function='coordinator';
8064: }
1.258 albertel 8065: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8066: $function='admin';
8067: }
1.826 bisitz 8068: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8069: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8070: $function='author';
8071: }
8072: return $function;
1.54 www 8073: }
1.99 www 8074:
8075: ###############################################
8076:
1.233 raeburn 8077: =pod
8078:
1.821 raeburn 8079: =item * &show_course()
8080:
8081: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8082: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8083:
8084: Inputs:
8085: None
8086:
8087: Outputs:
8088: Scalar: 1 if 'Course' to be used, 0 otherwise.
8089:
8090: =cut
8091:
8092: ###############################################
8093: sub show_course {
8094: my $course = !$env{'user.adv'};
8095: if (!$env{'user.adv'}) {
8096: foreach my $env (keys(%env)) {
8097: next if ($env !~ m/^user\.priv\./);
8098: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8099: $course = 0;
8100: last;
8101: }
8102: }
8103: }
8104: return $course;
8105: }
8106:
8107: ###############################################
8108:
8109: =pod
8110:
1.542 raeburn 8111: =item * &check_user_status()
1.274 raeburn 8112:
8113: Determines current status of supplied role for a
8114: specific user. Roles can be active, previous or future.
8115:
8116: Inputs:
8117: user's domain, user's username, course's domain,
1.375 raeburn 8118: course's number, optional section ID.
1.274 raeburn 8119:
8120: Outputs:
8121: role status: active, previous or future.
8122:
8123: =cut
8124:
8125: sub check_user_status {
1.412 raeburn 8126: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8127: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8128: my @uroles = keys %userinfo;
8129: my $srchstr;
8130: my $active_chk = 'none';
1.412 raeburn 8131: my $now = time;
1.274 raeburn 8132: if (@uroles > 0) {
1.908 raeburn 8133: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8134: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8135: } else {
1.412 raeburn 8136: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8137: }
8138: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8139: my $role_end = 0;
8140: my $role_start = 0;
8141: $active_chk = 'active';
1.412 raeburn 8142: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8143: $role_end = $1;
8144: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8145: $role_start = $1;
1.274 raeburn 8146: }
8147: }
8148: if ($role_start > 0) {
1.412 raeburn 8149: if ($now < $role_start) {
1.274 raeburn 8150: $active_chk = 'future';
8151: }
8152: }
8153: if ($role_end > 0) {
1.412 raeburn 8154: if ($now > $role_end) {
1.274 raeburn 8155: $active_chk = 'previous';
8156: }
8157: }
8158: }
8159: }
8160: return $active_chk;
8161: }
8162:
8163: ###############################################
8164:
8165: =pod
8166:
1.405 albertel 8167: =item * &get_sections()
1.233 raeburn 8168:
8169: Determines all the sections for a course including
8170: sections with students and sections containing other roles.
1.419 raeburn 8171: Incoming parameters:
8172:
8173: 1. domain
8174: 2. course number
8175: 3. reference to array containing roles for which sections should
8176: be gathered (optional).
8177: 4. reference to array containing status types for which sections
8178: should be gathered (optional).
8179:
8180: If the third argument is undefined, sections are gathered for any role.
8181: If the fourth argument is undefined, sections are gathered for any status.
8182: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8183:
1.374 raeburn 8184: Returns section hash (keys are section IDs, values are
8185: number of users in each section), subject to the
1.419 raeburn 8186: optional roles filter, optional status filter
1.233 raeburn 8187:
8188: =cut
8189:
8190: ###############################################
8191: sub get_sections {
1.419 raeburn 8192: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8193: if (!defined($cdom) || !defined($cnum)) {
8194: my $cid = $env{'request.course.id'};
8195:
8196: return if (!defined($cid));
8197:
8198: $cdom = $env{'course.'.$cid.'.domain'};
8199: $cnum = $env{'course.'.$cid.'.num'};
8200: }
8201:
8202: my %sectioncount;
1.419 raeburn 8203: my $now = time;
1.240 albertel 8204:
1.366 albertel 8205: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 8206: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8207: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8208: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8209: my $start_index = &Apache::loncoursedata::CL_START();
8210: my $end_index = &Apache::loncoursedata::CL_END();
8211: my $status;
1.366 albertel 8212: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8213: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8214: $data->[$status_index],
8215: $data->[$start_index],
8216: $data->[$end_index]);
8217: if ($stu_status eq 'Active') {
8218: $status = 'active';
8219: } elsif ($end < $now) {
8220: $status = 'previous';
8221: } elsif ($start > $now) {
8222: $status = 'future';
8223: }
8224: if ($section ne '-1' && $section !~ /^\s*$/) {
8225: if ((!defined($possible_status)) || (($status ne '') &&
8226: (grep/^\Q$status\E$/,@{$possible_status}))) {
8227: $sectioncount{$section}++;
8228: }
1.240 albertel 8229: }
8230: }
8231: }
8232: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8233: foreach my $user (sort(keys(%courseroles))) {
8234: if ($user !~ /^(\w{2})/) { next; }
8235: my ($role) = ($user =~ /^(\w{2})/);
8236: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8237: my ($section,$status);
1.240 albertel 8238: if ($role eq 'cr' &&
8239: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8240: $section=$1;
8241: }
8242: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8243: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8244: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8245: if ($end == -1 && $start == -1) {
8246: next; #deleted role
8247: }
8248: if (!defined($possible_status)) {
8249: $sectioncount{$section}++;
8250: } else {
8251: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8252: $status = 'active';
8253: } elsif ($end < $now) {
8254: $status = 'future';
8255: } elsif ($start > $now) {
8256: $status = 'previous';
8257: }
8258: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8259: $sectioncount{$section}++;
8260: }
8261: }
1.233 raeburn 8262: }
1.366 albertel 8263: return %sectioncount;
1.233 raeburn 8264: }
8265:
1.274 raeburn 8266: ###############################################
1.294 raeburn 8267:
8268: =pod
1.405 albertel 8269:
8270: =item * &get_course_users()
8271:
1.275 raeburn 8272: Retrieves usernames:domains for users in the specified course
8273: with specific role(s), and access status.
8274:
8275: Incoming parameters:
1.277 albertel 8276: 1. course domain
8277: 2. course number
8278: 3. access status: users must have - either active,
1.275 raeburn 8279: previous, future, or all.
1.277 albertel 8280: 4. reference to array of permissible roles
1.288 raeburn 8281: 5. reference to array of section restrictions (optional)
8282: 6. reference to results object (hash of hashes).
8283: 7. reference to optional userdata hash
1.609 raeburn 8284: 8. reference to optional statushash
1.630 raeburn 8285: 9. flag if privileged users (except those set to unhide in
8286: course settings) should be excluded
1.609 raeburn 8287: Keys of top level results hash are roles.
1.275 raeburn 8288: Keys of inner hashes are username:domain, with
8289: values set to access type.
1.288 raeburn 8290: Optional userdata hash returns an array with arguments in the
8291: same order as loncoursedata::get_classlist() for student data.
8292:
1.609 raeburn 8293: Optional statushash returns
8294:
1.288 raeburn 8295: Entries for end, start, section and status are blank because
8296: of the possibility of multiple values for non-student roles.
8297:
1.275 raeburn 8298: =cut
1.405 albertel 8299:
1.275 raeburn 8300: ###############################################
1.405 albertel 8301:
1.275 raeburn 8302: sub get_course_users {
1.630 raeburn 8303: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8304: my %idx = ();
1.419 raeburn 8305: my %seclists;
1.288 raeburn 8306:
8307: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8308: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8309: $idx{end} = &Apache::loncoursedata::CL_END();
8310: $idx{start} = &Apache::loncoursedata::CL_START();
8311: $idx{id} = &Apache::loncoursedata::CL_ID();
8312: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8313: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8314: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8315:
1.290 albertel 8316: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8317: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8318: my $now = time;
1.277 albertel 8319: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8320: my $match = 0;
1.412 raeburn 8321: my $secmatch = 0;
1.419 raeburn 8322: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8323: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8324: if ($section eq '') {
8325: $section = 'none';
8326: }
1.291 albertel 8327: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8328: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8329: $secmatch = 1;
8330: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8331: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8332: $secmatch = 1;
8333: }
8334: } else {
1.419 raeburn 8335: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8336: $secmatch = 1;
8337: }
1.290 albertel 8338: }
1.412 raeburn 8339: if (!$secmatch) {
8340: next;
8341: }
1.419 raeburn 8342: }
1.275 raeburn 8343: if (defined($$types{'active'})) {
1.288 raeburn 8344: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8345: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8346: $match = 1;
1.275 raeburn 8347: }
8348: }
8349: if (defined($$types{'previous'})) {
1.609 raeburn 8350: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8351: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8352: $match = 1;
1.275 raeburn 8353: }
8354: }
8355: if (defined($$types{'future'})) {
1.609 raeburn 8356: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8357: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8358: $match = 1;
1.275 raeburn 8359: }
8360: }
1.609 raeburn 8361: if ($match) {
8362: push(@{$seclists{$student}},$section);
8363: if (ref($userdata) eq 'HASH') {
8364: $$userdata{$student} = $$classlist{$student};
8365: }
8366: if (ref($statushash) eq 'HASH') {
8367: $statushash->{$student}{'st'}{$section} = $status;
8368: }
1.288 raeburn 8369: }
1.275 raeburn 8370: }
8371: }
1.412 raeburn 8372: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8373: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8374: my $now = time;
1.609 raeburn 8375: my %displaystatus = ( previous => 'Expired',
8376: active => 'Active',
8377: future => 'Future',
8378: );
1.630 raeburn 8379: my %nothide;
8380: if ($hidepriv) {
8381: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8382: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8383: if ($user !~ /:/) {
8384: $nothide{join(':',split(/[\@]/,$user))}=1;
8385: } else {
8386: $nothide{$user} = 1;
8387: }
8388: }
8389: }
1.439 raeburn 8390: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8391: my $match = 0;
1.412 raeburn 8392: my $secmatch = 0;
1.439 raeburn 8393: my $status;
1.412 raeburn 8394: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8395: $user =~ s/:$//;
1.439 raeburn 8396: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8397: if ($end == -1 || $start == -1) {
8398: next;
8399: }
8400: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8401: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8402: my ($uname,$udom) = split(/:/,$user);
8403: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8404: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8405: $secmatch = 1;
8406: } elsif ($usec eq '') {
1.420 albertel 8407: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8408: $secmatch = 1;
8409: }
8410: } else {
8411: if (grep(/^\Q$usec\E$/,@{$sections})) {
8412: $secmatch = 1;
8413: }
8414: }
8415: if (!$secmatch) {
8416: next;
8417: }
1.288 raeburn 8418: }
1.419 raeburn 8419: if ($usec eq '') {
8420: $usec = 'none';
8421: }
1.275 raeburn 8422: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8423: if ($hidepriv) {
8424: if ((&Apache::lonnet::privileged($uname,$udom)) &&
8425: (!$nothide{$uname.':'.$udom})) {
8426: next;
8427: }
8428: }
1.503 raeburn 8429: if ($end > 0 && $end < $now) {
1.439 raeburn 8430: $status = 'previous';
8431: } elsif ($start > $now) {
8432: $status = 'future';
8433: } else {
8434: $status = 'active';
8435: }
1.277 albertel 8436: foreach my $type (keys(%{$types})) {
1.275 raeburn 8437: if ($status eq $type) {
1.420 albertel 8438: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8439: push(@{$$users{$role}{$user}},$type);
8440: }
1.288 raeburn 8441: $match = 1;
8442: }
8443: }
1.419 raeburn 8444: if (($match) && (ref($userdata) eq 'HASH')) {
8445: if (!exists($$userdata{$uname.':'.$udom})) {
8446: &get_user_info($udom,$uname,\%idx,$userdata);
8447: }
1.420 albertel 8448: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8449: push(@{$seclists{$uname.':'.$udom}},$usec);
8450: }
1.609 raeburn 8451: if (ref($statushash) eq 'HASH') {
8452: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8453: }
1.275 raeburn 8454: }
8455: }
8456: }
8457: }
1.290 albertel 8458: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8459: if ((defined($cdom)) && (defined($cnum))) {
8460: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8461: if ( defined($csettings{'internal.courseowner'}) ) {
8462: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8463: next if ($owner eq '');
8464: my ($ownername,$ownerdom);
8465: if ($owner =~ /^([^:]+):([^:]+)$/) {
8466: $ownername = $1;
8467: $ownerdom = $2;
8468: } else {
8469: $ownername = $owner;
8470: $ownerdom = $cdom;
8471: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8472: }
8473: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8474: if (defined($userdata) &&
1.609 raeburn 8475: !exists($$userdata{$owner})) {
8476: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8477: if (!grep(/^none$/,@{$seclists{$owner}})) {
8478: push(@{$seclists{$owner}},'none');
8479: }
8480: if (ref($statushash) eq 'HASH') {
8481: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8482: }
1.290 albertel 8483: }
1.279 raeburn 8484: }
8485: }
8486: }
1.419 raeburn 8487: foreach my $user (keys(%seclists)) {
8488: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8489: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8490: }
1.275 raeburn 8491: }
8492: return;
8493: }
8494:
1.288 raeburn 8495: sub get_user_info {
8496: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8497: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8498: &plainname($uname,$udom,'lastname');
1.291 albertel 8499: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8500: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8501: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8502: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8503: return;
8504: }
1.275 raeburn 8505:
1.472 raeburn 8506: ###############################################
8507:
8508: =pod
8509:
8510: =item * &get_user_quota()
8511:
8512: Retrieves quota assigned for storage of portfolio files for a user
8513:
8514: Incoming parameters:
8515: 1. user's username
8516: 2. user's domain
8517:
8518: Returns:
1.536 raeburn 8519: 1. Disk quota (in Mb) assigned to student.
8520: 2. (Optional) Type of setting: custom or default
8521: (individually assigned or default for user's
8522: institutional status).
8523: 3. (Optional) - User's institutional status (e.g., faculty, staff
8524: or student - types as defined in localenroll::inst_usertypes
8525: for user's domain, which determines default quota for user.
8526: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8527:
8528: If a value has been stored in the user's environment,
1.536 raeburn 8529: it will return that, otherwise it returns the maximal default
8530: defined for the user's instituional status(es) in the domain.
1.472 raeburn 8531:
8532: =cut
8533:
8534: ###############################################
8535:
8536:
8537: sub get_user_quota {
8538: my ($uname,$udom) = @_;
1.536 raeburn 8539: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8540: if (!defined($udom)) {
8541: $udom = $env{'user.domain'};
8542: }
8543: if (!defined($uname)) {
8544: $uname = $env{'user.name'};
8545: }
8546: if (($udom eq '' || $uname eq '') ||
8547: ($udom eq 'public') && ($uname eq 'public')) {
8548: $quota = 0;
1.536 raeburn 8549: $quotatype = 'default';
8550: $defquota = 0;
1.472 raeburn 8551: } else {
1.536 raeburn 8552: my $inststatus;
1.472 raeburn 8553: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8554: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 8555: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 8556: } else {
1.536 raeburn 8557: my %userenv =
8558: &Apache::lonnet::get('environment',['portfolioquota',
8559: 'inststatus'],$udom,$uname);
1.472 raeburn 8560: my ($tmp) = keys(%userenv);
8561: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8562: $quota = $userenv{'portfolioquota'};
1.536 raeburn 8563: $inststatus = $userenv{'inststatus'};
1.472 raeburn 8564: } else {
8565: undef(%userenv);
8566: }
8567: }
1.536 raeburn 8568: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 8569: if ($quota eq '') {
1.536 raeburn 8570: $quota = $defquota;
8571: $quotatype = 'default';
8572: } else {
8573: $quotatype = 'custom';
1.472 raeburn 8574: }
8575: }
1.536 raeburn 8576: if (wantarray) {
8577: return ($quota,$quotatype,$settingstatus,$defquota);
8578: } else {
8579: return $quota;
8580: }
1.472 raeburn 8581: }
8582:
8583: ###############################################
8584:
8585: =pod
8586:
8587: =item * &default_quota()
8588:
1.536 raeburn 8589: Retrieves default quota assigned for storage of user portfolio files,
8590: given an (optional) user's institutional status.
1.472 raeburn 8591:
8592: Incoming parameters:
8593: 1. domain
1.536 raeburn 8594: 2. (Optional) institutional status(es). This is a : separated list of
8595: status types (e.g., faculty, staff, student etc.)
8596: which apply to the user for whom the default is being retrieved.
8597: If the institutional status string in undefined, the domain
8598: default quota will be returned.
1.472 raeburn 8599:
8600: Returns:
8601: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8602: 2. (Optional) institutional type which determined the value of the
8603: default quota.
1.472 raeburn 8604:
8605: If a value has been stored in the domain's configuration db,
8606: it will return that, otherwise it returns 20 (for backwards
8607: compatibility with domains which have not set up a configuration
8608: db file; the original statically defined portfolio quota was 20 Mb).
8609:
1.536 raeburn 8610: If the user's status includes multiple types (e.g., staff and student),
8611: the largest default quota which applies to the user determines the
8612: default quota returned.
8613:
1.780 raeburn 8614: =back
8615:
1.472 raeburn 8616: =cut
8617:
8618: ###############################################
8619:
8620:
8621: sub default_quota {
1.536 raeburn 8622: my ($udom,$inststatus) = @_;
8623: my ($defquota,$settingstatus);
8624: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8625: ['quotas'],$udom);
8626: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8627: if ($inststatus ne '') {
1.765 raeburn 8628: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8629: foreach my $item (@statuses) {
1.711 raeburn 8630: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8631: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
8632: if ($defquota eq '') {
8633: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8634: $settingstatus = $item;
8635: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
8636: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8637: $settingstatus = $item;
8638: }
8639: }
8640: } else {
8641: if ($quotahash{'quotas'}{$item} ne '') {
8642: if ($defquota eq '') {
8643: $defquota = $quotahash{'quotas'}{$item};
8644: $settingstatus = $item;
8645: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8646: $defquota = $quotahash{'quotas'}{$item};
8647: $settingstatus = $item;
8648: }
1.536 raeburn 8649: }
8650: }
8651: }
8652: }
8653: if ($defquota eq '') {
1.711 raeburn 8654: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8655: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
8656: } else {
8657: $defquota = $quotahash{'quotas'}{'default'};
8658: }
1.536 raeburn 8659: $settingstatus = 'default';
8660: }
8661: } else {
8662: $settingstatus = 'default';
8663: $defquota = 20;
8664: }
8665: if (wantarray) {
8666: return ($defquota,$settingstatus);
1.472 raeburn 8667: } else {
1.536 raeburn 8668: return $defquota;
1.472 raeburn 8669: }
8670: }
8671:
1.384 raeburn 8672: sub get_secgrprole_info {
8673: my ($cdom,$cnum,$needroles,$type) = @_;
8674: my %sections_count = &get_sections($cdom,$cnum);
8675: my @sections = (sort {$a <=> $b} keys(%sections_count));
8676: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8677: my @groups = sort(keys(%curr_groups));
8678: my $allroles = [];
8679: my $rolehash;
8680: my $accesshash = {
8681: active => 'Currently has access',
8682: future => 'Will have future access',
8683: previous => 'Previously had access',
8684: };
8685: if ($needroles) {
8686: $rolehash = {'all' => 'all'};
1.385 albertel 8687: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8688: if (&Apache::lonnet::error(%user_roles)) {
8689: undef(%user_roles);
8690: }
8691: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8692: my ($role)=split(/\:/,$item,2);
8693: if ($role eq 'cr') { next; }
8694: if ($role =~ /^cr/) {
8695: $$rolehash{$role} = (split('/',$role))[3];
8696: } else {
8697: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8698: }
8699: }
8700: foreach my $key (sort(keys(%{$rolehash}))) {
8701: push(@{$allroles},$key);
8702: }
8703: push (@{$allroles},'st');
8704: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8705: }
8706: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8707: }
8708:
1.555 raeburn 8709: sub user_picker {
1.994 raeburn 8710: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8711: my $currdom = $dom;
8712: my %curr_selected = (
8713: srchin => 'dom',
1.580 raeburn 8714: srchby => 'lastname',
1.555 raeburn 8715: );
8716: my $srchterm;
1.625 raeburn 8717: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8718: if ($srch->{'srchby'} ne '') {
8719: $curr_selected{'srchby'} = $srch->{'srchby'};
8720: }
8721: if ($srch->{'srchin'} ne '') {
8722: $curr_selected{'srchin'} = $srch->{'srchin'};
8723: }
8724: if ($srch->{'srchtype'} ne '') {
8725: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8726: }
8727: if ($srch->{'srchdomain'} ne '') {
8728: $currdom = $srch->{'srchdomain'};
8729: }
8730: $srchterm = $srch->{'srchterm'};
8731: }
8732: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8733: 'usr' => 'Search criteria',
1.563 raeburn 8734: 'doma' => 'Domain/institution to search',
1.558 albertel 8735: 'uname' => 'username',
8736: 'lastname' => 'last name',
1.555 raeburn 8737: 'lastfirst' => 'last name, first name',
1.558 albertel 8738: 'crs' => 'in this course',
1.576 raeburn 8739: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8740: 'alc' => 'all LON-CAPA',
1.573 raeburn 8741: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8742: 'exact' => 'is',
8743: 'contains' => 'contains',
1.569 raeburn 8744: 'begins' => 'begins with',
1.571 raeburn 8745: 'youm' => "You must include some text to search for.",
8746: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8747: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8748: 'yomc' => "You must choose a domain when using an institutional directory search.",
8749: 'ymcd' => "You must choose a domain when using a domain search.",
8750: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8751: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8752: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8753: );
1.563 raeburn 8754: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8755: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8756:
8757: my @srchins = ('crs','dom','alc','instd');
8758:
8759: foreach my $option (@srchins) {
8760: # FIXME 'alc' option unavailable until
8761: # loncreateuser::print_user_query_page()
8762: # has been completed.
8763: next if ($option eq 'alc');
1.880 raeburn 8764: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8765: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8766: if ($curr_selected{'srchin'} eq $option) {
8767: $srchinsel .= '
8768: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8769: } else {
8770: $srchinsel .= '
8771: <option value="'.$option.'">'.$lt{$option}.'</option>';
8772: }
1.555 raeburn 8773: }
1.563 raeburn 8774: $srchinsel .= "\n </select>\n";
1.555 raeburn 8775:
8776: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 8777: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 8778: if ($curr_selected{'srchby'} eq $option) {
8779: $srchbysel .= '
8780: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8781: } else {
8782: $srchbysel .= '
8783: <option value="'.$option.'">'.$lt{$option}.'</option>';
8784: }
8785: }
8786: $srchbysel .= "\n </select>\n";
8787:
8788: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 8789: foreach my $option ('begins','contains','exact') {
1.555 raeburn 8790: if ($curr_selected{'srchtype'} eq $option) {
8791: $srchtypesel .= '
8792: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8793: } else {
8794: $srchtypesel .= '
8795: <option value="'.$option.'">'.$lt{$option}.'</option>';
8796: }
8797: }
8798: $srchtypesel .= "\n </select>\n";
8799:
1.558 albertel 8800: my ($newuserscript,$new_user_create);
1.994 raeburn 8801: my $context_dom = $env{'request.role.domain'};
8802: if ($context eq 'requestcrs') {
8803: if ($env{'form.coursedom'} ne '') {
8804: $context_dom = $env{'form.coursedom'};
8805: }
8806: }
1.556 raeburn 8807: if ($forcenewuser) {
1.576 raeburn 8808: if (ref($srch) eq 'HASH') {
1.994 raeburn 8809: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8810: if ($cancreate) {
8811: $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>';
8812: } else {
1.799 bisitz 8813: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8814: my %usertypetext = (
8815: official => 'institutional',
8816: unofficial => 'non-institutional',
8817: );
1.799 bisitz 8818: $new_user_create = '<p class="LC_warning">'
8819: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
8820: .' '
8821: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8822: ,'<a href="'.$helplink.'">','</a>')
8823: .'</p><br />';
1.627 raeburn 8824: }
1.576 raeburn 8825: }
8826: }
8827:
1.556 raeburn 8828: $newuserscript = <<"ENDSCRIPT";
8829:
1.570 raeburn 8830: function setSearch(createnew,callingForm) {
1.556 raeburn 8831: if (createnew == 1) {
1.570 raeburn 8832: for (var i=0; i<callingForm.srchby.length; i++) {
8833: if (callingForm.srchby.options[i].value == 'uname') {
8834: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8835: }
8836: }
1.570 raeburn 8837: for (var i=0; i<callingForm.srchin.length; i++) {
8838: if ( callingForm.srchin.options[i].value == 'dom') {
8839: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8840: }
8841: }
1.570 raeburn 8842: for (var i=0; i<callingForm.srchtype.length; i++) {
8843: if (callingForm.srchtype.options[i].value == 'exact') {
8844: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8845: }
8846: }
1.570 raeburn 8847: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 8848: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8849: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8850: }
8851: }
8852: }
8853: }
8854: ENDSCRIPT
1.558 albertel 8855:
1.556 raeburn 8856: }
8857:
1.555 raeburn 8858: my $output = <<"END_BLOCK";
1.556 raeburn 8859: <script type="text/javascript">
1.824 bisitz 8860: // <![CDATA[
1.570 raeburn 8861: function validateEntry(callingForm) {
1.558 albertel 8862:
1.556 raeburn 8863: var checkok = 1;
1.558 albertel 8864: var srchin;
1.570 raeburn 8865: for (var i=0; i<callingForm.srchin.length; i++) {
8866: if ( callingForm.srchin[i].checked ) {
8867: srchin = callingForm.srchin[i].value;
1.558 albertel 8868: }
8869: }
8870:
1.570 raeburn 8871: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8872: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8873: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8874: var srchterm = callingForm.srchterm.value;
8875: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8876: var msg = "";
8877:
8878: if (srchterm == "") {
8879: checkok = 0;
1.571 raeburn 8880: msg += "$lt{'youm'}\\n";
1.556 raeburn 8881: }
8882:
1.569 raeburn 8883: if (srchtype== 'begins') {
8884: if (srchterm.length < 2) {
8885: checkok = 0;
1.571 raeburn 8886: msg += "$lt{'thte'}\\n";
1.569 raeburn 8887: }
8888: }
8889:
1.556 raeburn 8890: if (srchtype== 'contains') {
8891: if (srchterm.length < 3) {
8892: checkok = 0;
1.571 raeburn 8893: msg += "$lt{'thet'}\\n";
1.556 raeburn 8894: }
8895: }
8896: if (srchin == 'instd') {
8897: if (srchdomain == '') {
8898: checkok = 0;
1.571 raeburn 8899: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8900: }
8901: }
8902: if (srchin == 'dom') {
8903: if (srchdomain == '') {
8904: checkok = 0;
1.571 raeburn 8905: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8906: }
8907: }
8908: if (srchby == 'lastfirst') {
8909: if (srchterm.indexOf(",") == -1) {
8910: checkok = 0;
1.571 raeburn 8911: msg += "$lt{'whus'}\\n";
1.556 raeburn 8912: }
8913: if (srchterm.indexOf(",") == srchterm.length -1) {
8914: checkok = 0;
1.571 raeburn 8915: msg += "$lt{'whse'}\\n";
1.556 raeburn 8916: }
8917: }
8918: if (checkok == 0) {
1.571 raeburn 8919: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8920: return;
8921: }
8922: if (checkok == 1) {
1.570 raeburn 8923: callingForm.submit();
1.556 raeburn 8924: }
8925: }
8926:
8927: $newuserscript
8928:
1.824 bisitz 8929: // ]]>
1.556 raeburn 8930: </script>
1.558 albertel 8931:
8932: $new_user_create
8933:
1.555 raeburn 8934: END_BLOCK
1.558 albertel 8935:
1.876 raeburn 8936: $output .= &Apache::lonhtmlcommon::start_pick_box().
8937: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8938: $domform.
8939: &Apache::lonhtmlcommon::row_closure().
8940: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8941: $srchbysel.
8942: $srchtypesel.
8943: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8944: $srchinsel.
8945: &Apache::lonhtmlcommon::row_closure(1).
8946: &Apache::lonhtmlcommon::end_pick_box().
8947: '<br />';
1.555 raeburn 8948: return $output;
8949: }
8950:
1.612 raeburn 8951: sub user_rule_check {
1.615 raeburn 8952: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8953: my $response;
8954: if (ref($usershash) eq 'HASH') {
8955: foreach my $user (keys(%{$usershash})) {
8956: my ($uname,$udom) = split(/:/,$user);
8957: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8958: my ($id,$newuser);
1.612 raeburn 8959: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8960: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8961: $id = $usershash->{$user}->{'id'};
8962: }
8963: my $inst_response;
8964: if (ref($checks) eq 'HASH') {
8965: if (defined($checks->{'username'})) {
1.615 raeburn 8966: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8967: &Apache::lonnet::get_instuser($udom,$uname);
8968: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8969: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8970: &Apache::lonnet::get_instuser($udom,undef,$id);
8971: }
1.615 raeburn 8972: } else {
8973: ($inst_response,%{$inst_results->{$user}}) =
8974: &Apache::lonnet::get_instuser($udom,$uname);
8975: return;
1.612 raeburn 8976: }
1.615 raeburn 8977: if (!$got_rules->{$udom}) {
1.612 raeburn 8978: my %domconfig = &Apache::lonnet::get_dom('configuration',
8979: ['usercreation'],$udom);
8980: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8981: foreach my $item ('username','id') {
1.612 raeburn 8982: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8983: $$curr_rules{$udom}{$item} =
8984: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8985: }
8986: }
8987: }
1.615 raeburn 8988: $got_rules->{$udom} = 1;
1.585 raeburn 8989: }
1.612 raeburn 8990: foreach my $item (keys(%{$checks})) {
8991: if (ref($$curr_rules{$udom}) eq 'HASH') {
8992: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8993: if (@{$$curr_rules{$udom}{$item}} > 0) {
8994: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8995: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8996: if ($rule_check{$rule}) {
8997: $$rulematch{$user}{$item} = $rule;
8998: if ($inst_response eq 'ok') {
1.615 raeburn 8999: if (ref($inst_results) eq 'HASH') {
9000: if (ref($inst_results->{$user}) eq 'HASH') {
9001: if (keys(%{$inst_results->{$user}}) == 0) {
9002: $$alerts{$item}{$udom}{$uname} = 1;
9003: }
1.612 raeburn 9004: }
9005: }
1.615 raeburn 9006: }
9007: last;
1.585 raeburn 9008: }
9009: }
9010: }
9011: }
9012: }
9013: }
9014: }
9015: }
1.612 raeburn 9016: return;
9017: }
9018:
9019: sub user_rule_formats {
9020: my ($domain,$domdesc,$curr_rules,$check) = @_;
9021: my %text = (
9022: 'username' => 'Usernames',
9023: 'id' => 'IDs',
9024: );
9025: my $output;
9026: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9027: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9028: if (@{$ruleorder} > 0) {
1.1102 raeburn 9029: $output = '<br />'.
9030: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9031: '<span class="LC_cusr_emph">','</span>',$domdesc).
9032: ' <ul>';
1.612 raeburn 9033: foreach my $rule (@{$ruleorder}) {
9034: if (ref($curr_rules) eq 'ARRAY') {
9035: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9036: if (ref($rules->{$rule}) eq 'HASH') {
9037: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9038: $rules->{$rule}{'desc'}.'</li>';
9039: }
9040: }
9041: }
9042: }
9043: $output .= '</ul>';
9044: }
9045: }
9046: return $output;
9047: }
9048:
9049: sub instrule_disallow_msg {
1.615 raeburn 9050: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9051: my $response;
9052: my %text = (
9053: item => 'username',
9054: items => 'usernames',
9055: match => 'matches',
9056: do => 'does',
9057: action => 'a username',
9058: one => 'one',
9059: );
9060: if ($count > 1) {
9061: $text{'item'} = 'usernames';
9062: $text{'match'} ='match';
9063: $text{'do'} = 'do';
9064: $text{'action'} = 'usernames',
9065: $text{'one'} = 'ones';
9066: }
9067: if ($checkitem eq 'id') {
9068: $text{'items'} = 'IDs';
9069: $text{'item'} = 'ID';
9070: $text{'action'} = 'an ID';
1.615 raeburn 9071: if ($count > 1) {
9072: $text{'item'} = 'IDs';
9073: $text{'action'} = 'IDs';
9074: }
1.612 raeburn 9075: }
1.674 bisitz 9076: $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 9077: if ($mode eq 'upload') {
9078: if ($checkitem eq 'username') {
9079: $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'}.");
9080: } elsif ($checkitem eq 'id') {
1.674 bisitz 9081: $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 9082: }
1.669 raeburn 9083: } elsif ($mode eq 'selfcreate') {
9084: if ($checkitem eq 'id') {
9085: $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.");
9086: }
1.615 raeburn 9087: } else {
9088: if ($checkitem eq 'username') {
9089: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9090: } elsif ($checkitem eq 'id') {
9091: $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.");
9092: }
1.612 raeburn 9093: }
9094: return $response;
1.585 raeburn 9095: }
9096:
1.624 raeburn 9097: sub personal_data_fieldtitles {
9098: my %fieldtitles = &Apache::lonlocal::texthash (
9099: id => 'Student/Employee ID',
9100: permanentemail => 'E-mail address',
9101: lastname => 'Last Name',
9102: firstname => 'First Name',
9103: middlename => 'Middle Name',
9104: generation => 'Generation',
9105: gen => 'Generation',
1.765 raeburn 9106: inststatus => 'Affiliation',
1.624 raeburn 9107: );
9108: return %fieldtitles;
9109: }
9110:
1.642 raeburn 9111: sub sorted_inst_types {
9112: my ($dom) = @_;
9113: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9114: my $othertitle = &mt('All users');
9115: if ($env{'request.course.id'}) {
1.668 raeburn 9116: $othertitle = &mt('Any users');
1.642 raeburn 9117: }
9118: my @types;
9119: if (ref($order) eq 'ARRAY') {
9120: @types = @{$order};
9121: }
9122: if (@types == 0) {
9123: if (ref($usertypes) eq 'HASH') {
9124: @types = sort(keys(%{$usertypes}));
9125: }
9126: }
9127: if (keys(%{$usertypes}) > 0) {
9128: $othertitle = &mt('Other users');
9129: }
9130: return ($othertitle,$usertypes,\@types);
9131: }
9132:
1.645 raeburn 9133: sub get_institutional_codes {
9134: my ($settings,$allcourses,$LC_code) = @_;
9135: # Get complete list of course sections to update
9136: my @currsections = ();
9137: my @currxlists = ();
9138: my $coursecode = $$settings{'internal.coursecode'};
9139:
9140: if ($$settings{'internal.sectionnums'} ne '') {
9141: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9142: }
9143:
9144: if ($$settings{'internal.crosslistings'} ne '') {
9145: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9146: }
9147:
9148: if (@currxlists > 0) {
9149: foreach (@currxlists) {
9150: if (m/^([^:]+):(\w*)$/) {
9151: unless (grep/^$1$/,@{$allcourses}) {
9152: push @{$allcourses},$1;
9153: $$LC_code{$1} = $2;
9154: }
9155: }
9156: }
9157: }
9158:
9159: if (@currsections > 0) {
9160: foreach (@currsections) {
9161: if (m/^(\w+):(\w*)$/) {
9162: my $sec = $coursecode.$1;
9163: my $lc_sec = $2;
9164: unless (grep/^$sec$/,@{$allcourses}) {
9165: push @{$allcourses},$sec;
9166: $$LC_code{$sec} = $lc_sec;
9167: }
9168: }
9169: }
9170: }
9171: return;
9172: }
9173:
1.971 raeburn 9174: sub get_standard_codeitems {
9175: return ('Year','Semester','Department','Number','Section');
9176: }
9177:
1.112 bowersj2 9178: =pod
9179:
1.780 raeburn 9180: =head1 Slot Helpers
9181:
9182: =over 4
9183:
9184: =item * sorted_slots()
9185:
1.1040 raeburn 9186: Sorts an array of slot names in order of an optional sort key,
9187: default sort is by slot start time (earliest first).
1.780 raeburn 9188:
9189: Inputs:
9190:
9191: =over 4
9192:
9193: slotsarr - Reference to array of unsorted slot names.
9194:
9195: slots - Reference to hash of hash, where outer hash keys are slot names.
9196:
1.1040 raeburn 9197: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9198:
1.549 albertel 9199: =back
9200:
1.780 raeburn 9201: Returns:
9202:
9203: =over 4
9204:
1.1040 raeburn 9205: sorted - An array of slot names sorted by a specified sort key
9206: (default sort key is start time of the slot).
1.780 raeburn 9207:
9208: =back
9209:
9210: =cut
9211:
9212:
9213: sub sorted_slots {
1.1040 raeburn 9214: my ($slotsarr,$slots,$sortkey) = @_;
9215: if ($sortkey eq '') {
9216: $sortkey = 'starttime';
9217: }
1.780 raeburn 9218: my @sorted;
9219: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9220: @sorted =
9221: sort {
9222: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9223: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9224: }
9225: if (ref($slots->{$a})) { return -1;}
9226: if (ref($slots->{$b})) { return 1;}
9227: return 0;
9228: } @{$slotsarr};
9229: }
9230: return @sorted;
9231: }
9232:
1.1040 raeburn 9233: =pod
9234:
9235: =item * get_future_slots()
9236:
9237: Inputs:
9238:
9239: =over 4
9240:
9241: cnum - course number
9242:
9243: cdom - course domain
9244:
9245: now - current UNIX time
9246:
9247: symb - optional symb
9248:
9249: =back
9250:
9251: Returns:
9252:
9253: =over 4
9254:
9255: sorted_reservable - ref to array of student_schedulable slots currently
9256: reservable, ordered by end date of reservation period.
9257:
9258: reservable_now - ref to hash of student_schedulable slots currently
9259: reservable.
9260:
9261: Keys in inner hash are:
9262: (a) symb: either blank or symb to which slot use is restricted.
9263: (b) endreserve: end date of reservation period.
9264:
9265: sorted_future - ref to array of student_schedulable slots reservable in
9266: the future, ordered by start date of reservation period.
9267:
9268: future_reservable - ref to hash of student_schedulable slots reservable
9269: in the future.
9270:
9271: Keys in inner hash are:
9272: (a) symb: either blank or symb to which slot use is restricted.
9273: (b) startreserve: start date of reservation period.
9274:
9275: =back
9276:
9277: =cut
9278:
9279: sub get_future_slots {
9280: my ($cnum,$cdom,$now,$symb) = @_;
9281: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9282: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9283: foreach my $slot (keys(%slots)) {
9284: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9285: if ($symb) {
9286: next if (($slots{$slot}->{'symb'} ne '') &&
9287: ($slots{$slot}->{'symb'} ne $symb));
9288: }
9289: if (($slots{$slot}->{'starttime'} > $now) &&
9290: ($slots{$slot}->{'endtime'} > $now)) {
9291: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9292: my $userallowed = 0;
9293: if ($slots{$slot}->{'allowedsections'}) {
9294: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9295: if (!defined($env{'request.role.sec'})
9296: && grep(/^No section assigned$/,@allowed_sec)) {
9297: $userallowed=1;
9298: } else {
9299: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9300: $userallowed=1;
9301: }
9302: }
9303: unless ($userallowed) {
9304: if (defined($env{'request.course.groups'})) {
9305: my @groups = split(/:/,$env{'request.course.groups'});
9306: foreach my $group (@groups) {
9307: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9308: $userallowed=1;
9309: last;
9310: }
9311: }
9312: }
9313: }
9314: }
9315: if ($slots{$slot}->{'allowedusers'}) {
9316: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9317: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9318: if (grep(/^\Q$user\E$/,@allowed_users)) {
9319: $userallowed = 1;
9320: }
9321: }
9322: next unless($userallowed);
9323: }
9324: my $startreserve = $slots{$slot}->{'startreserve'};
9325: my $endreserve = $slots{$slot}->{'endreserve'};
9326: my $symb = $slots{$slot}->{'symb'};
9327: if (($startreserve < $now) &&
9328: (!$endreserve || $endreserve > $now)) {
9329: my $lastres = $endreserve;
9330: if (!$lastres) {
9331: $lastres = $slots{$slot}->{'starttime'};
9332: }
9333: $reservable_now{$slot} = {
9334: symb => $symb,
9335: endreserve => $lastres
9336: };
9337: } elsif (($startreserve > $now) &&
9338: (!$endreserve || $endreserve > $startreserve)) {
9339: $future_reservable{$slot} = {
9340: symb => $symb,
9341: startreserve => $startreserve
9342: };
9343: }
9344: }
9345: }
9346: my @unsorted_reservable = keys(%reservable_now);
9347: if (@unsorted_reservable > 0) {
9348: @sorted_reservable =
9349: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9350: }
9351: my @unsorted_future = keys(%future_reservable);
9352: if (@unsorted_future > 0) {
9353: @sorted_future =
9354: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9355: }
9356: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9357: }
1.780 raeburn 9358:
9359: =pod
9360:
1.1057 foxr 9361: =back
9362:
1.549 albertel 9363: =head1 HTTP Helpers
9364:
9365: =over 4
9366:
1.648 raeburn 9367: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9368:
1.258 albertel 9369: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9370: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9371: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9372:
9373: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9374: $possible_names is an ref to an array of form element names. As an example:
9375: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9376: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9377:
9378: =cut
1.1 albertel 9379:
1.6 albertel 9380: sub get_unprocessed_cgi {
1.25 albertel 9381: my ($query,$possible_names)= @_;
1.26 matthew 9382: # $Apache::lonxml::debug=1;
1.356 albertel 9383: foreach my $pair (split(/&/,$query)) {
9384: my ($name, $value) = split(/=/,$pair);
1.369 www 9385: $name = &unescape($name);
1.25 albertel 9386: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9387: $value =~ tr/+/ /;
9388: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9389: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9390: }
1.16 harris41 9391: }
1.6 albertel 9392: }
9393:
1.112 bowersj2 9394: =pod
9395:
1.648 raeburn 9396: =item * &cacheheader()
1.112 bowersj2 9397:
9398: returns cache-controlling header code
9399:
9400: =cut
9401:
1.7 albertel 9402: sub cacheheader {
1.258 albertel 9403: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9404: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9405: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9406: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9407: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9408: return $output;
1.7 albertel 9409: }
9410:
1.112 bowersj2 9411: =pod
9412:
1.648 raeburn 9413: =item * &no_cache($r)
1.112 bowersj2 9414:
9415: specifies header code to not have cache
9416:
9417: =cut
9418:
1.9 albertel 9419: sub no_cache {
1.216 albertel 9420: my ($r) = @_;
9421: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9422: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9423: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9424: $r->no_cache(1);
9425: $r->header_out("Expires" => $date);
9426: $r->header_out("Pragma" => "no-cache");
1.123 www 9427: }
9428:
9429: sub content_type {
1.181 albertel 9430: my ($r,$type,$charset) = @_;
1.299 foxr 9431: if ($r) {
9432: # Note that printout.pl calls this with undef for $r.
9433: &no_cache($r);
9434: }
1.258 albertel 9435: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9436: unless ($charset) {
9437: $charset=&Apache::lonlocal::current_encoding;
9438: }
9439: if ($charset) { $type.='; charset='.$charset; }
9440: if ($r) {
9441: $r->content_type($type);
9442: } else {
9443: print("Content-type: $type\n\n");
9444: }
1.9 albertel 9445: }
1.25 albertel 9446:
1.112 bowersj2 9447: =pod
9448:
1.648 raeburn 9449: =item * &add_to_env($name,$value)
1.112 bowersj2 9450:
1.258 albertel 9451: adds $name to the %env hash with value
1.112 bowersj2 9452: $value, if $name already exists, the entry is converted to an array
9453: reference and $value is added to the array.
9454:
9455: =cut
9456:
1.25 albertel 9457: sub add_to_env {
9458: my ($name,$value)=@_;
1.258 albertel 9459: if (defined($env{$name})) {
9460: if (ref($env{$name})) {
1.25 albertel 9461: #already have multiple values
1.258 albertel 9462: push(@{ $env{$name} },$value);
1.25 albertel 9463: } else {
9464: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9465: my $first=$env{$name};
9466: undef($env{$name});
9467: push(@{ $env{$name} },$first,$value);
1.25 albertel 9468: }
9469: } else {
1.258 albertel 9470: $env{$name}=$value;
1.25 albertel 9471: }
1.31 albertel 9472: }
1.149 albertel 9473:
9474: =pod
9475:
1.648 raeburn 9476: =item * &get_env_multiple($name)
1.149 albertel 9477:
1.258 albertel 9478: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9479: values may be defined and end up as an array ref.
9480:
9481: returns an array of values
9482:
9483: =cut
9484:
9485: sub get_env_multiple {
9486: my ($name) = @_;
9487: my @values;
1.258 albertel 9488: if (defined($env{$name})) {
1.149 albertel 9489: # exists is it an array
1.258 albertel 9490: if (ref($env{$name})) {
9491: @values=@{ $env{$name} };
1.149 albertel 9492: } else {
1.258 albertel 9493: $values[0]=$env{$name};
1.149 albertel 9494: }
9495: }
9496: return(@values);
9497: }
9498:
1.660 raeburn 9499: sub ask_for_embedded_content {
9500: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9501: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9502: %currsubfile,%unused,$rem);
1.1071 raeburn 9503: my $counter = 0;
9504: my $numnew = 0;
1.987 raeburn 9505: my $numremref = 0;
9506: my $numinvalid = 0;
9507: my $numpathchg = 0;
9508: my $numexisting = 0;
1.1071 raeburn 9509: my $numunused = 0;
9510: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9511: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9512: my $heading = &mt('Upload embedded files');
9513: my $buttontext = &mt('Upload');
9514:
1.1085 raeburn 9515: my $navmap;
9516: if ($env{'request.course.id'}) {
9517: $navmap = Apache::lonnavmaps::navmap->new();
9518: }
1.984 raeburn 9519: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9520: my $current_path='/';
9521: if ($env{'form.currentpath'}) {
9522: $current_path = $env{'form.currentpath'};
9523: }
9524: if ($actionurl eq '/adm/coursegrp_portfolio') {
9525: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9526: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
9527: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9528: } else {
9529: $udom = $env{'user.domain'};
9530: $uname = $env{'user.name'};
9531: $url = '/userfiles/portfolio';
9532: }
1.987 raeburn 9533: $toplevel = $url.'/';
1.984 raeburn 9534: $url .= $current_path;
9535: $getpropath = 1;
1.987 raeburn 9536: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9537: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9538: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9539: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9540: $toplevel = $url;
1.984 raeburn 9541: if ($rest ne '') {
1.987 raeburn 9542: $url .= $rest;
9543: }
9544: } elsif ($actionurl eq '/adm/coursedocs') {
9545: if (ref($args) eq 'HASH') {
1.1071 raeburn 9546: $url = $args->{'docs_url'};
9547: $toplevel = $url;
1.1084 raeburn 9548: if ($args->{'context'} eq 'paste') {
9549: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9550: ($path) =
9551: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9552: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9553: $fileloc =~ s{^/}{};
9554: }
1.1071 raeburn 9555: }
1.1084 raeburn 9556: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9557: if ($env{'request.course.id'} ne '') {
9558: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9559: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9560: if (ref($args) eq 'HASH') {
9561: $url = $args->{'docs_url'};
9562: $title = $args->{'docs_title'};
9563: $toplevel = "/$url";
1.1085 raeburn 9564: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071 raeburn 9565: ($path) =
9566: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9567: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9568: $fileloc =~ s{^/}{};
9569: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9570: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9571: }
1.987 raeburn 9572: }
9573: }
9574: my $now = time();
9575: foreach my $embed_file (keys(%{$allfiles})) {
9576: my $absolutepath;
9577: if ($embed_file =~ m{^\w+://}) {
9578: $newfiles{$embed_file} = 1;
9579: $mapping{$embed_file} = $embed_file;
9580: } else {
9581: if ($embed_file =~ m{^/}) {
9582: $absolutepath = $embed_file;
9583: $embed_file =~ s{^(/+)}{};
9584: }
9585: if ($embed_file =~ m{/}) {
9586: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9587: $path = &check_for_traversal($path,$url,$toplevel);
9588: my $item = $fname;
9589: if ($path ne '') {
9590: $item = $path.'/'.$fname;
9591: $subdependencies{$path}{$fname} = 1;
9592: } else {
9593: $dependencies{$item} = 1;
9594: }
9595: if ($absolutepath) {
9596: $mapping{$item} = $absolutepath;
9597: } else {
9598: $mapping{$item} = $embed_file;
9599: }
9600: } else {
9601: $dependencies{$embed_file} = 1;
9602: if ($absolutepath) {
9603: $mapping{$embed_file} = $absolutepath;
9604: } else {
9605: $mapping{$embed_file} = $embed_file;
9606: }
9607: }
1.984 raeburn 9608: }
9609: }
1.1071 raeburn 9610: my $dirptr = 16384;
1.984 raeburn 9611: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9612: $currsubfile{$path} = {};
1.984 raeburn 9613: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9614: my ($sublistref,$listerror) =
9615: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9616: if (ref($sublistref) eq 'ARRAY') {
9617: foreach my $line (@{$sublistref}) {
9618: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9619: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9620: }
1.984 raeburn 9621: }
1.987 raeburn 9622: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9623: if (opendir(my $dir,$url.'/'.$path)) {
9624: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9625: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9626: }
1.1084 raeburn 9627: } elsif (($actionurl eq '/adm/dependencies') ||
9628: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9629: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9630: if ($env{'request.course.id'} ne '') {
9631: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9632: if ($dir ne '') {
9633: my ($sublistref,$listerror) =
9634: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9635: if (ref($sublistref) eq 'ARRAY') {
9636: foreach my $line (@{$sublistref}) {
9637: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9638: undef,$mtime)=split(/\&/,$line,12);
9639: unless (($testdir&$dirptr) ||
9640: ($file_name =~ /^\.\.?$/)) {
9641: $currsubfile{$path}{$file_name} = [$size,$mtime];
9642: }
9643: }
9644: }
9645: }
1.984 raeburn 9646: }
9647: }
9648: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9649: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9650: my $item = $path.'/'.$file;
9651: unless ($mapping{$item} eq $item) {
9652: $pathchanges{$item} = 1;
9653: }
9654: $existing{$item} = 1;
9655: $numexisting ++;
9656: } else {
9657: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9658: }
9659: }
1.1071 raeburn 9660: if ($actionurl eq '/adm/dependencies') {
9661: foreach my $path (keys(%currsubfile)) {
9662: if (ref($currsubfile{$path}) eq 'HASH') {
9663: foreach my $file (keys(%{$currsubfile{$path}})) {
9664: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9665: next if (($rem ne '') &&
9666: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9667: (ref($navmap) &&
9668: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9669: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9670: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9671: $unused{$path.'/'.$file} = 1;
9672: }
9673: }
9674: }
9675: }
9676: }
1.984 raeburn 9677: }
1.987 raeburn 9678: my %currfile;
1.984 raeburn 9679: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9680: my ($dirlistref,$listerror) =
9681: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9682: if (ref($dirlistref) eq 'ARRAY') {
9683: foreach my $line (@{$dirlistref}) {
9684: my ($file_name,$rest) = split(/\&/,$line,2);
9685: $currfile{$file_name} = 1;
9686: }
1.984 raeburn 9687: }
1.987 raeburn 9688: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9689: if (opendir(my $dir,$url)) {
1.987 raeburn 9690: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9691: map {$currfile{$_} = 1;} @dir_list;
9692: }
1.1084 raeburn 9693: } elsif (($actionurl eq '/adm/dependencies') ||
9694: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9695: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9696: if ($env{'request.course.id'} ne '') {
9697: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9698: if ($dir ne '') {
9699: my ($dirlistref,$listerror) =
9700: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9701: if (ref($dirlistref) eq 'ARRAY') {
9702: foreach my $line (@{$dirlistref}) {
9703: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9704: $size,undef,$mtime)=split(/\&/,$line,12);
9705: unless (($testdir&$dirptr) ||
9706: ($file_name =~ /^\.\.?$/)) {
9707: $currfile{$file_name} = [$size,$mtime];
9708: }
9709: }
9710: }
9711: }
9712: }
1.984 raeburn 9713: }
9714: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9715: if (exists($currfile{$file})) {
1.987 raeburn 9716: unless ($mapping{$file} eq $file) {
9717: $pathchanges{$file} = 1;
9718: }
9719: $existing{$file} = 1;
9720: $numexisting ++;
9721: } else {
1.984 raeburn 9722: $newfiles{$file} = 1;
9723: }
9724: }
1.1071 raeburn 9725: foreach my $file (keys(%currfile)) {
9726: unless (($file eq $filename) ||
9727: ($file eq $filename.'.bak') ||
9728: ($dependencies{$file})) {
1.1085 raeburn 9729: if ($actionurl eq '/adm/dependencies') {
9730: next if (($rem ne '') &&
9731: (($env{"httpref.$rem".$file} ne '') ||
9732: (ref($navmap) &&
9733: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9734: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9735: ($navmap->getResourceByUrl($rem.$1)))))));
9736: }
1.1071 raeburn 9737: $unused{$file} = 1;
9738: }
9739: }
1.1084 raeburn 9740: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9741: ($args->{'context'} eq 'paste')) {
9742: $counter = scalar(keys(%existing));
9743: $numpathchg = scalar(keys(%pathchanges));
9744: return ($output,$counter,$numpathchg,\%existing);
9745: }
1.984 raeburn 9746: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 9747: if ($actionurl eq '/adm/dependencies') {
9748: next if ($embed_file =~ m{^\w+://});
9749: }
1.660 raeburn 9750: $upload_output .= &start_data_table_row().
1.1071 raeburn 9751: '<td><img src="'.&icon($embed_file).'" /> '.
9752: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 9753: unless ($mapping{$embed_file} eq $embed_file) {
9754: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
9755: }
9756: $upload_output .= '</td><td>';
1.1071 raeburn 9757: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.660 raeburn 9758: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 9759: $numremref++;
1.660 raeburn 9760: } elsif ($args->{'error_on_invalid_names'}
9761: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987 raeburn 9762: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
9763: $numinvalid++;
1.660 raeburn 9764: } else {
1.1071 raeburn 9765: $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 9766: $embed_file,\%mapping,
1.1071 raeburn 9767: $allfiles,$codebase,'upload');
9768: $counter ++;
9769: $numnew ++;
1.987 raeburn 9770: }
9771: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
9772: }
9773: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 9774: if ($actionurl eq '/adm/dependencies') {
9775: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
9776: $modify_output .= &start_data_table_row().
9777: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
9778: '<img src="'.&icon($embed_file).'" border="0" />'.
9779: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
9780: '<td>'.$size.'</td>'.
9781: '<td>'.$mtime.'</td>'.
9782: '<td><label><input type="checkbox" name="mod_upload_dep" '.
9783: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
9784: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
9785: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
9786: &embedded_file_element('upload_embedded',$counter,
9787: $embed_file,\%mapping,
9788: $allfiles,$codebase,'modify').
9789: '</div></td>'.
9790: &end_data_table_row()."\n";
9791: $counter ++;
9792: } else {
9793: $upload_output .= &start_data_table_row().
9794: '<td><span class="LC_filename">'.$embed_file.'</span></td>';
9795: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
9796: &Apache::loncommon::end_data_table_row()."\n";
9797: }
9798: }
9799: my $delidx = $counter;
9800: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
9801: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
9802: $delete_output .= &start_data_table_row().
9803: '<td><img src="'.&icon($oldfile).'" />'.
9804: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
9805: '<td>'.$size.'</td>'.
9806: '<td>'.$mtime.'</td>'.
9807: '<td><label><input type="checkbox" name="del_upload_dep" '.
9808: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
9809: &embedded_file_element('upload_embedded',$delidx,
9810: $oldfile,\%mapping,$allfiles,
9811: $codebase,'delete').'</td>'.
9812: &end_data_table_row()."\n";
9813: $numunused ++;
9814: $delidx ++;
1.987 raeburn 9815: }
9816: if ($upload_output) {
9817: $upload_output = &start_data_table().
9818: $upload_output.
9819: &end_data_table()."\n";
9820: }
1.1071 raeburn 9821: if ($modify_output) {
9822: $modify_output = &start_data_table().
9823: &start_data_table_header_row().
9824: '<th>'.&mt('File').'</th>'.
9825: '<th>'.&mt('Size (KB)').'</th>'.
9826: '<th>'.&mt('Modified').'</th>'.
9827: '<th>'.&mt('Upload replacement?').'</th>'.
9828: &end_data_table_header_row().
9829: $modify_output.
9830: &end_data_table()."\n";
9831: }
9832: if ($delete_output) {
9833: $delete_output = &start_data_table().
9834: &start_data_table_header_row().
9835: '<th>'.&mt('File').'</th>'.
9836: '<th>'.&mt('Size (KB)').'</th>'.
9837: '<th>'.&mt('Modified').'</th>'.
9838: '<th>'.&mt('Delete?').'</th>'.
9839: &end_data_table_header_row().
9840: $delete_output.
9841: &end_data_table()."\n";
9842: }
1.987 raeburn 9843: my $applies = 0;
9844: if ($numremref) {
9845: $applies ++;
9846: }
9847: if ($numinvalid) {
9848: $applies ++;
9849: }
9850: if ($numexisting) {
9851: $applies ++;
9852: }
1.1071 raeburn 9853: if ($counter || $numunused) {
1.987 raeburn 9854: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
9855: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 9856: $state.'<h3>'.$heading.'</h3>';
9857: if ($actionurl eq '/adm/dependencies') {
9858: if ($numnew) {
9859: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
9860: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
9861: $upload_output.'<br />'."\n";
9862: }
9863: if ($numexisting) {
9864: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
9865: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
9866: $modify_output.'<br />'."\n";
9867: $buttontext = &mt('Save changes');
9868: }
9869: if ($numunused) {
9870: $output .= '<h4>'.&mt('Unused files').'</h4>'.
9871: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
9872: $delete_output.'<br />'."\n";
9873: $buttontext = &mt('Save changes');
9874: }
9875: } else {
9876: $output .= $upload_output.'<br />'."\n";
9877: }
9878: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
9879: $counter.'" />'."\n";
9880: if ($actionurl eq '/adm/dependencies') {
9881: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
9882: $numnew.'" />'."\n";
9883: } elsif ($actionurl eq '') {
1.987 raeburn 9884: $output .= '<input type="hidden" name="phase" value="three" />';
9885: }
9886: } elsif ($applies) {
9887: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
9888: if ($applies > 1) {
9889: $output .=
9890: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
9891: if ($numremref) {
9892: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
9893: }
9894: if ($numinvalid) {
9895: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
9896: }
9897: if ($numexisting) {
9898: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
9899: }
9900: $output .= '</ul><br />';
9901: } elsif ($numremref) {
9902: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
9903: } elsif ($numinvalid) {
9904: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
9905: } elsif ($numexisting) {
9906: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
9907: }
9908: $output .= $upload_output.'<br />';
9909: }
9910: my ($pathchange_output,$chgcount);
1.1071 raeburn 9911: $chgcount = $counter;
1.987 raeburn 9912: if (keys(%pathchanges) > 0) {
9913: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 9914: if ($counter) {
1.987 raeburn 9915: $output .= &embedded_file_element('pathchange',$chgcount,
9916: $embed_file,\%mapping,
1.1071 raeburn 9917: $allfiles,$codebase,'change');
1.987 raeburn 9918: } else {
9919: $pathchange_output .=
9920: &start_data_table_row().
9921: '<td><input type ="checkbox" name="namechange" value="'.
9922: $chgcount.'" checked="checked" /></td>'.
9923: '<td>'.$mapping{$embed_file}.'</td>'.
9924: '<td>'.$embed_file.
9925: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 9926: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 9927: '</td>'.&end_data_table_row();
1.660 raeburn 9928: }
1.987 raeburn 9929: $numpathchg ++;
9930: $chgcount ++;
1.660 raeburn 9931: }
9932: }
1.1071 raeburn 9933: if ($counter) {
1.987 raeburn 9934: if ($numpathchg) {
9935: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
9936: $numpathchg.'" />'."\n";
9937: }
9938: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9939: ($actionurl eq '/adm/imsimport')) {
9940: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
9941: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
9942: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 9943: } elsif ($actionurl eq '/adm/dependencies') {
9944: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 9945: }
1.1071 raeburn 9946: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 9947: } elsif ($numpathchg) {
9948: my %pathchange = ();
9949: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
9950: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9951: $output .= '<p>'.&mt('or').'</p>';
9952: }
9953: }
1.1071 raeburn 9954: return ($output,$counter,$numpathchg);
1.987 raeburn 9955: }
9956:
9957: sub embedded_file_element {
1.1071 raeburn 9958: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 9959: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
9960: (ref($codebase) eq 'HASH'));
9961: my $output;
1.1071 raeburn 9962: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 9963: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
9964: }
9965: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
9966: &escape($embed_file).'" />';
9967: unless (($context eq 'upload_embedded') &&
9968: ($mapping->{$embed_file} eq $embed_file)) {
9969: $output .='
9970: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
9971: }
9972: my $attrib;
9973: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
9974: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
9975: }
9976: $output .=
9977: "\n\t\t".
9978: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
9979: $attrib.'" />';
9980: if (exists($codebase->{$mapping->{$embed_file}})) {
9981: $output .=
9982: "\n\t\t".
9983: '<input name="codebase_'.$num.'" type="hidden" value="'.
9984: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 9985: }
1.987 raeburn 9986: return $output;
1.660 raeburn 9987: }
9988:
1.1071 raeburn 9989: sub get_dependency_details {
9990: my ($currfile,$currsubfile,$embed_file) = @_;
9991: my ($size,$mtime,$showsize,$showmtime);
9992: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
9993: if ($embed_file =~ m{/}) {
9994: my ($path,$fname) = split(/\//,$embed_file);
9995: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
9996: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
9997: }
9998: } else {
9999: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10000: ($size,$mtime) = @{$currfile->{$embed_file}};
10001: }
10002: }
10003: $showsize = $size/1024.0;
10004: $showsize = sprintf("%.1f",$showsize);
10005: if ($mtime > 0) {
10006: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10007: }
10008: }
10009: return ($showsize,$showmtime);
10010: }
10011:
10012: sub ask_embedded_js {
10013: return <<"END";
10014: <script type="text/javascript"">
10015: // <![CDATA[
10016: function toggleBrowse(counter) {
10017: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10018: var fileid = document.getElementById('embedded_item_'+counter);
10019: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10020: if (chkboxid.checked == true) {
10021: uploaddivid.style.display='block';
10022: } else {
10023: uploaddivid.style.display='none';
10024: fileid.value = '';
10025: }
10026: }
10027: // ]]>
10028: </script>
10029:
10030: END
10031: }
10032:
1.661 raeburn 10033: sub upload_embedded {
10034: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10035: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10036: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10037: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10038: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10039: my $orig_uploaded_filename =
10040: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10041: foreach my $type ('orig','ref','attrib','codebase') {
10042: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10043: $env{'form.embedded_'.$type.'_'.$i} =
10044: &unescape($env{'form.embedded_'.$type.'_'.$i});
10045: }
10046: }
1.661 raeburn 10047: my ($path,$fname) =
10048: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10049: # no path, whole string is fname
10050: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10051: $fname = &Apache::lonnet::clean_filename($fname);
10052: # See if there is anything left
10053: next if ($fname eq '');
10054:
10055: # Check if file already exists as a file or directory.
10056: my ($state,$msg);
10057: if ($context eq 'portfolio') {
10058: my $port_path = $dirpath;
10059: if ($group ne '') {
10060: $port_path = "groups/$group/$port_path";
10061: }
1.987 raeburn 10062: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10063: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10064: $dir_root,$port_path,$disk_quota,
10065: $current_disk_usage,$uname,$udom);
10066: if ($state eq 'will_exceed_quota'
1.984 raeburn 10067: || $state eq 'file_locked') {
1.661 raeburn 10068: $output .= $msg;
10069: next;
10070: }
10071: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10072: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10073: if ($state eq 'exists') {
10074: $output .= $msg;
10075: next;
10076: }
10077: }
10078: # Check if extension is valid
10079: if (($fname =~ /\.(\w+)$/) &&
10080: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10081: $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 10082: next;
10083: } elsif (($fname =~ /\.(\w+)$/) &&
10084: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10085: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10086: next;
10087: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 10088: $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 10089: next;
10090: }
10091: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
10092: if ($context eq 'portfolio') {
1.984 raeburn 10093: my $result;
10094: if ($state eq 'existingfile') {
10095: $result=
10096: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 10097: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 10098: } else {
1.984 raeburn 10099: $result=
10100: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10101: $dirpath.
10102: $env{'form.currentpath'}.$path);
1.984 raeburn 10103: if ($result !~ m|^/uploaded/|) {
10104: $output .= '<span class="LC_error">'
10105: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10106: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10107: .'</span><br />';
10108: next;
10109: } else {
1.987 raeburn 10110: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10111: $path.$fname.'</span>').'<br />';
1.984 raeburn 10112: }
1.661 raeburn 10113: }
1.987 raeburn 10114: } elsif ($context eq 'coursedoc') {
10115: my $result =
10116: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
10117: $dirpath.'/'.$path);
10118: if ($result !~ m|^/uploaded/|) {
10119: $output .= '<span class="LC_error">'
10120: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10121: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10122: .'</span><br />';
10123: next;
10124: } else {
10125: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10126: $path.$fname.'</span>').'<br />';
10127: }
1.661 raeburn 10128: } else {
10129: # Save the file
10130: my $target = $env{'form.embedded_item_'.$i};
10131: my $fullpath = $dir_root.$dirpath.'/'.$path;
10132: my $dest = $fullpath.$fname;
10133: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10134: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10135: my $count;
10136: my $filepath = $dir_root;
1.1027 raeburn 10137: foreach my $subdir (@parts) {
10138: $filepath .= "/$subdir";
10139: if (!-e $filepath) {
1.661 raeburn 10140: mkdir($filepath,0770);
10141: }
10142: }
10143: my $fh;
10144: if (!open($fh,'>'.$dest)) {
10145: &Apache::lonnet::logthis('Failed to create '.$dest);
10146: $output .= '<span class="LC_error">'.
1.1071 raeburn 10147: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10148: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10149: '</span><br />';
10150: } else {
10151: if (!print $fh $env{'form.embedded_item_'.$i}) {
10152: &Apache::lonnet::logthis('Failed to write to '.$dest);
10153: $output .= '<span class="LC_error">'.
1.1071 raeburn 10154: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10155: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10156: '</span><br />';
10157: } else {
1.987 raeburn 10158: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10159: $url.'</span>').'<br />';
10160: unless ($context eq 'testbank') {
10161: $footer .= &mt('View embedded file: [_1]',
10162: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10163: }
10164: }
10165: close($fh);
10166: }
10167: }
10168: if ($env{'form.embedded_ref_'.$i}) {
10169: $pathchange{$i} = 1;
10170: }
10171: }
10172: if ($output) {
10173: $output = '<p>'.$output.'</p>';
10174: }
10175: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10176: $returnflag = 'ok';
1.1071 raeburn 10177: my $numpathchgs = scalar(keys(%pathchange));
10178: if ($numpathchgs > 0) {
1.987 raeburn 10179: if ($context eq 'portfolio') {
10180: $output .= '<p>'.&mt('or').'</p>';
10181: } elsif ($context eq 'testbank') {
1.1071 raeburn 10182: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10183: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10184: $returnflag = 'modify_orightml';
10185: }
10186: }
1.1071 raeburn 10187: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10188: }
10189:
10190: sub modify_html_form {
10191: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10192: my $end = 0;
10193: my $modifyform;
10194: if ($context eq 'upload_embedded') {
10195: return unless (ref($pathchange) eq 'HASH');
10196: if ($env{'form.number_embedded_items'}) {
10197: $end += $env{'form.number_embedded_items'};
10198: }
10199: if ($env{'form.number_pathchange_items'}) {
10200: $end += $env{'form.number_pathchange_items'};
10201: }
10202: if ($end) {
10203: for (my $i=0; $i<$end; $i++) {
10204: if ($i < $env{'form.number_embedded_items'}) {
10205: next unless($pathchange->{$i});
10206: }
10207: $modifyform .=
10208: &start_data_table_row().
10209: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10210: 'checked="checked" /></td>'.
10211: '<td>'.$env{'form.embedded_ref_'.$i}.
10212: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10213: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10214: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10215: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10216: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10217: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10218: '<td>'.$env{'form.embedded_orig_'.$i}.
10219: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10220: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10221: &end_data_table_row();
1.1071 raeburn 10222: }
1.987 raeburn 10223: }
10224: } else {
10225: $modifyform = $pathchgtable;
10226: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10227: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10228: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10229: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10230: }
10231: }
10232: if ($modifyform) {
1.1071 raeburn 10233: if ($actionurl eq '/adm/dependencies') {
10234: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10235: }
1.987 raeburn 10236: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10237: '<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".
10238: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10239: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10240: '</ol></p>'."\n".'<p>'.
10241: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10242: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10243: &start_data_table()."\n".
10244: &start_data_table_header_row().
10245: '<th>'.&mt('Change?').'</th>'.
10246: '<th>'.&mt('Current reference').'</th>'.
10247: '<th>'.&mt('Required reference').'</th>'.
10248: &end_data_table_header_row()."\n".
10249: $modifyform.
10250: &end_data_table().'<br />'."\n".$hiddenstate.
10251: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10252: '</form>'."\n";
10253: }
10254: return;
10255: }
10256:
10257: sub modify_html_refs {
10258: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
10259: my $container;
10260: if ($context eq 'portfolio') {
10261: $container = $env{'form.container'};
10262: } elsif ($context eq 'coursedoc') {
10263: $container = $env{'form.primaryurl'};
1.1071 raeburn 10264: } elsif ($context eq 'manage_dependencies') {
10265: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10266: $container = "/$container";
1.987 raeburn 10267: } else {
1.1027 raeburn 10268: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10269: }
10270: my (%allfiles,%codebase,$output,$content);
10271: my @changes = &get_env_multiple('form.namechange');
1.1071 raeburn 10272: unless (@changes > 0) {
10273: if (wantarray) {
10274: return ('',0,0);
10275: } else {
10276: return;
10277: }
10278: }
10279: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10280: ($context eq 'manage_dependencies')) {
10281: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10282: if (wantarray) {
10283: return ('',0,0);
10284: } else {
10285: return;
10286: }
10287: }
1.987 raeburn 10288: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10289: if ($content eq '-1') {
10290: if (wantarray) {
10291: return ('',0,0);
10292: } else {
10293: return;
10294: }
10295: }
1.987 raeburn 10296: } else {
1.1071 raeburn 10297: unless ($container =~ /^\Q$dir_root\E/) {
10298: if (wantarray) {
10299: return ('',0,0);
10300: } else {
10301: return;
10302: }
10303: }
1.987 raeburn 10304: if (open(my $fh,"<$container")) {
10305: $content = join('', <$fh>);
10306: close($fh);
10307: } else {
1.1071 raeburn 10308: if (wantarray) {
10309: return ('',0,0);
10310: } else {
10311: return;
10312: }
1.987 raeburn 10313: }
10314: }
10315: my ($count,$codebasecount) = (0,0);
10316: my $mm = new File::MMagic;
10317: my $mime_type = $mm->checktype_contents($content);
10318: if ($mime_type eq 'text/html') {
10319: my $parse_result =
10320: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10321: \%codebase,\$content);
10322: if ($parse_result eq 'ok') {
10323: foreach my $i (@changes) {
10324: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10325: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10326: if ($allfiles{$ref}) {
10327: my $newname = $orig;
10328: my ($attrib_regexp,$codebase);
1.1006 raeburn 10329: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10330: if ($attrib_regexp =~ /:/) {
10331: $attrib_regexp =~ s/\:/|/g;
10332: }
10333: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10334: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10335: $count += $numchg;
10336: }
10337: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10338: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10339: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10340: $codebasecount ++;
10341: }
10342: }
10343: }
10344: if ($count || $codebasecount) {
10345: my $saveresult;
1.1071 raeburn 10346: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10347: ($context eq 'manage_dependencies')) {
1.987 raeburn 10348: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10349: if ($url eq $container) {
10350: my ($fname) = ($container =~ m{/([^/]+)$});
10351: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10352: $count,'<span class="LC_filename">'.
1.1071 raeburn 10353: $fname.'</span>').'</p>';
1.987 raeburn 10354: } else {
10355: $output = '<p class="LC_error">'.
10356: &mt('Error: update failed for: [_1].',
10357: '<span class="LC_filename">'.
10358: $container.'</span>').'</p>';
10359: }
10360: } else {
10361: if (open(my $fh,">$container")) {
10362: print $fh $content;
10363: close($fh);
10364: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10365: $count,'<span class="LC_filename">'.
10366: $container.'</span>').'</p>';
1.661 raeburn 10367: } else {
1.987 raeburn 10368: $output = '<p class="LC_error">'.
10369: &mt('Error: could not update [_1].',
10370: '<span class="LC_filename">'.
10371: $container.'</span>').'</p>';
1.661 raeburn 10372: }
10373: }
10374: }
1.987 raeburn 10375: } else {
10376: &logthis('Failed to parse '.$container.
10377: ' to modify references: '.$parse_result);
1.661 raeburn 10378: }
10379: }
1.1071 raeburn 10380: if (wantarray) {
10381: return ($output,$count,$codebasecount);
10382: } else {
10383: return $output;
10384: }
1.661 raeburn 10385: }
10386:
10387: sub check_for_existing {
10388: my ($path,$fname,$element) = @_;
10389: my ($state,$msg);
10390: if (-d $path.'/'.$fname) {
10391: $state = 'exists';
10392: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10393: } elsif (-e $path.'/'.$fname) {
10394: $state = 'exists';
10395: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10396: }
10397: if ($state eq 'exists') {
10398: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10399: }
10400: return ($state,$msg);
10401: }
10402:
10403: sub check_for_upload {
10404: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10405: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10406: my $filesize = length($env{'form.'.$element});
10407: if (!$filesize) {
10408: my $msg = '<span class="LC_error">'.
10409: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10410: '<span class="LC_filename">'.$fname.'</span>',
10411: $filesize).'<br />'.
1.1007 raeburn 10412: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10413: '</span>';
10414: return ('zero_bytes',$msg);
10415: }
10416: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10417: my $getpropath = 1;
1.1021 raeburn 10418: my ($dirlistref,$listerror) =
10419: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10420: my $found_file = 0;
10421: my $locked_file = 0;
1.991 raeburn 10422: my @lockers;
10423: my $navmap;
10424: if ($env{'request.course.id'}) {
10425: $navmap = Apache::lonnavmaps::navmap->new();
10426: }
1.1021 raeburn 10427: if (ref($dirlistref) eq 'ARRAY') {
10428: foreach my $line (@{$dirlistref}) {
10429: my ($file_name,$rest)=split(/\&/,$line,2);
10430: if ($file_name eq $fname){
10431: $file_name = $path.$file_name;
10432: if ($group ne '') {
10433: $file_name = $group.$file_name;
10434: }
10435: $found_file = 1;
10436: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10437: foreach my $lock (@lockers) {
10438: if (ref($lock) eq 'ARRAY') {
10439: my ($symb,$crsid) = @{$lock};
10440: if ($crsid eq $env{'request.course.id'}) {
10441: if (ref($navmap)) {
10442: my $res = $navmap->getBySymb($symb);
10443: foreach my $part (@{$res->parts()}) {
10444: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10445: unless (($slot_status == $res->RESERVED) ||
10446: ($slot_status == $res->RESERVED_LOCATION)) {
10447: $locked_file = 1;
10448: }
1.991 raeburn 10449: }
1.1021 raeburn 10450: } else {
10451: $locked_file = 1;
1.991 raeburn 10452: }
10453: } else {
10454: $locked_file = 1;
10455: }
10456: }
1.1021 raeburn 10457: }
10458: } else {
10459: my @info = split(/\&/,$rest);
10460: my $currsize = $info[6]/1000;
10461: if ($currsize < $filesize) {
10462: my $extra = $filesize - $currsize;
10463: if (($current_disk_usage + $extra) > $disk_quota) {
10464: my $msg = '<span class="LC_error">'.
10465: &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.',
10466: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10467: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10468: $disk_quota,$current_disk_usage);
10469: return ('will_exceed_quota',$msg);
10470: }
1.984 raeburn 10471: }
10472: }
1.661 raeburn 10473: }
10474: }
10475: }
10476: if (($current_disk_usage + $filesize) > $disk_quota){
10477: my $msg = '<span class="LC_error">'.
10478: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10479: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10480: return ('will_exceed_quota',$msg);
10481: } elsif ($found_file) {
10482: if ($locked_file) {
10483: my $msg = '<span class="LC_error">';
10484: $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>');
10485: $msg .= '</span><br />';
10486: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10487: return ('file_locked',$msg);
10488: } else {
10489: my $msg = '<span class="LC_error">';
1.984 raeburn 10490: $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 10491: $msg .= '</span>';
1.984 raeburn 10492: return ('existingfile',$msg);
1.661 raeburn 10493: }
10494: }
10495: }
10496:
1.987 raeburn 10497: sub check_for_traversal {
10498: my ($path,$url,$toplevel) = @_;
10499: my @parts=split(/\//,$path);
10500: my $cleanpath;
10501: my $fullpath = $url;
10502: for (my $i=0;$i<@parts;$i++) {
10503: next if ($parts[$i] eq '.');
10504: if ($parts[$i] eq '..') {
10505: $fullpath =~ s{([^/]+/)$}{};
10506: } else {
10507: $fullpath .= $parts[$i].'/';
10508: }
10509: }
10510: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10511: $cleanpath = $1;
10512: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10513: my $curr_toprel = $1;
10514: my @parts = split(/\//,$curr_toprel);
10515: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10516: my @urlparts = split(/\//,$url_toprel);
10517: my $doubledots;
10518: my $startdiff = -1;
10519: for (my $i=0; $i<@urlparts; $i++) {
10520: if ($startdiff == -1) {
10521: unless ($urlparts[$i] eq $parts[$i]) {
10522: $startdiff = $i;
10523: $doubledots .= '../';
10524: }
10525: } else {
10526: $doubledots .= '../';
10527: }
10528: }
10529: if ($startdiff > -1) {
10530: $cleanpath = $doubledots;
10531: for (my $i=$startdiff; $i<@parts; $i++) {
10532: $cleanpath .= $parts[$i].'/';
10533: }
10534: }
10535: }
10536: $cleanpath =~ s{(/)$}{};
10537: return $cleanpath;
10538: }
1.31 albertel 10539:
1.1053 raeburn 10540: sub is_archive_file {
10541: my ($mimetype) = @_;
10542: if (($mimetype eq 'application/octet-stream') ||
10543: ($mimetype eq 'application/x-stuffit') ||
10544: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10545: return 1;
10546: }
10547: return;
10548: }
10549:
10550: sub decompress_form {
1.1065 raeburn 10551: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10552: my %lt = &Apache::lonlocal::texthash (
10553: this => 'This file is an archive file.',
1.1067 raeburn 10554: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10555: itsc => 'Its contents are as follows:',
1.1053 raeburn 10556: youm => 'You may wish to extract its contents.',
10557: extr => 'Extract contents',
1.1067 raeburn 10558: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10559: proa => 'Process automatically?',
1.1053 raeburn 10560: yes => 'Yes',
10561: no => 'No',
1.1067 raeburn 10562: fold => 'Title for folder containing movie',
10563: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10564: );
1.1065 raeburn 10565: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10566: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10567: my $info = &list_archive_contents($fileloc,\@paths);
10568: if (@paths) {
10569: foreach my $path (@paths) {
10570: $path =~ s{^/}{};
1.1067 raeburn 10571: if ($path =~ m{^([^/]+)/$}) {
10572: $topdir = $1;
10573: }
1.1065 raeburn 10574: if ($path =~ m{^([^/]+)/}) {
10575: $toplevel{$1} = $path;
10576: } else {
10577: $toplevel{$path} = $path;
10578: }
10579: }
10580: }
1.1067 raeburn 10581: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10582: my @camtasia = ("$topdir/","$topdir/index.html",
10583: "$topdir/media/",
10584: "$topdir/media/$topdir.mp4",
10585: "$topdir/media/FirstFrame.png",
10586: "$topdir/media/player.swf",
10587: "$topdir/media/swfobject.js",
10588: "$topdir/media/expressInstall.swf");
10589: my @diffs = &compare_arrays(\@paths,\@camtasia);
10590: if (@diffs == 0) {
10591: $is_camtasia = 1;
10592: }
10593: }
10594: my $output;
10595: if ($is_camtasia) {
10596: $output = <<"ENDCAM";
10597: <script type="text/javascript" language="Javascript">
10598: // <![CDATA[
10599:
10600: function camtasiaToggle() {
10601: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10602: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10603: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10604:
10605: document.getElementById('camtasia_titles').style.display='block';
10606: } else {
10607: document.getElementById('camtasia_titles').style.display='none';
10608: }
10609: }
10610: }
10611: return;
10612: }
10613:
10614: // ]]>
10615: </script>
10616: <p>$lt{'camt'}</p>
10617: ENDCAM
1.1065 raeburn 10618: } else {
1.1067 raeburn 10619: $output = '<p>'.$lt{'this'};
10620: if ($info eq '') {
10621: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10622: } else {
10623: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10624: '<div><pre>'.$info.'</pre></div>';
10625: }
1.1065 raeburn 10626: }
1.1067 raeburn 10627: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10628: my $duplicates;
10629: my $num = 0;
10630: if (ref($dirlist) eq 'ARRAY') {
10631: foreach my $item (@{$dirlist}) {
10632: if (ref($item) eq 'ARRAY') {
10633: if (exists($toplevel{$item->[0]})) {
10634: $duplicates .=
10635: &start_data_table_row().
10636: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10637: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10638: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10639: 'value="1" />'.&mt('Yes').'</label>'.
10640: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10641: '<td>'.$item->[0].'</td>';
10642: if ($item->[2]) {
10643: $duplicates .= '<td>'.&mt('Directory').'</td>';
10644: } else {
10645: $duplicates .= '<td>'.&mt('File').'</td>';
10646: }
10647: $duplicates .= '<td>'.$item->[3].'</td>'.
10648: '<td>'.
10649: &Apache::lonlocal::locallocaltime($item->[4]).
10650: '</td>'.
10651: &end_data_table_row();
10652: $num ++;
10653: }
10654: }
10655: }
10656: }
10657: my $itemcount;
10658: if (@paths > 0) {
10659: $itemcount = scalar(@paths);
10660: } else {
10661: $itemcount = 1;
10662: }
1.1067 raeburn 10663: if ($is_camtasia) {
10664: $output .= $lt{'auto'}.'<br />'.
10665: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10666: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10667: $lt{'yes'}.'</label> <label>'.
10668: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10669: $lt{'no'}.'</label></span><br />'.
10670: '<div id="camtasia_titles" style="display:block">'.
10671: &Apache::lonhtmlcommon::start_pick_box().
10672: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10673: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10674: &Apache::lonhtmlcommon::row_closure().
10675: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
10676: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
10677: &Apache::lonhtmlcommon::row_closure(1).
10678: &Apache::lonhtmlcommon::end_pick_box().
10679: '</div>';
10680: }
1.1065 raeburn 10681: $output .=
10682: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 10683: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
10684: "\n";
1.1065 raeburn 10685: if ($duplicates ne '') {
10686: $output .= '<p><span class="LC_warning">'.
10687: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
10688: &start_data_table().
10689: &start_data_table_header_row().
10690: '<th>'.&mt('Overwrite?').'</th>'.
10691: '<th>'.&mt('Name').'</th>'.
10692: '<th>'.&mt('Type').'</th>'.
10693: '<th>'.&mt('Size').'</th>'.
10694: '<th>'.&mt('Last modified').'</th>'.
10695: &end_data_table_header_row().
10696: $duplicates.
10697: &end_data_table().
10698: '</p>';
10699: }
1.1067 raeburn 10700: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 10701: if (ref($hiddenelements) eq 'HASH') {
10702: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
10703: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
10704: }
10705: }
10706: $output .= <<"END";
1.1067 raeburn 10707: <br />
1.1053 raeburn 10708: <input type="submit" name="decompress" value="$lt{'extr'}" />
10709: </form>
10710: $noextract
10711: END
10712: return $output;
10713: }
10714:
1.1065 raeburn 10715: sub decompression_utility {
10716: my ($program) = @_;
10717: my @utilities = ('tar','gunzip','bunzip2','unzip');
10718: my $location;
10719: if (grep(/^\Q$program\E$/,@utilities)) {
10720: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
10721: '/usr/sbin/') {
10722: if (-x $dir.$program) {
10723: $location = $dir.$program;
10724: last;
10725: }
10726: }
10727: }
10728: return $location;
10729: }
10730:
10731: sub list_archive_contents {
10732: my ($file,$pathsref) = @_;
10733: my (@cmd,$output);
10734: my $needsregexp;
10735: if ($file =~ /\.zip$/) {
10736: @cmd = (&decompression_utility('unzip'),"-l");
10737: $needsregexp = 1;
10738: } elsif (($file =~ m/\.tar\.gz$/) ||
10739: ($file =~ /\.tgz$/)) {
10740: @cmd = (&decompression_utility('tar'),"-ztf");
10741: } elsif ($file =~ /\.tar\.bz2$/) {
10742: @cmd = (&decompression_utility('tar'),"-jtf");
10743: } elsif ($file =~ m|\.tar$|) {
10744: @cmd = (&decompression_utility('tar'),"-tf");
10745: }
10746: if (@cmd) {
10747: undef($!);
10748: undef($@);
10749: if (open(my $fh,"-|", @cmd, $file)) {
10750: while (my $line = <$fh>) {
10751: $output .= $line;
10752: chomp($line);
10753: my $item;
10754: if ($needsregexp) {
10755: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
10756: } else {
10757: $item = $line;
10758: }
10759: if ($item ne '') {
10760: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
10761: push(@{$pathsref},$item);
10762: }
10763: }
10764: }
10765: close($fh);
10766: }
10767: }
10768: return $output;
10769: }
10770:
1.1053 raeburn 10771: sub decompress_uploaded_file {
10772: my ($file,$dir) = @_;
10773: &Apache::lonnet::appenv({'cgi.file' => $file});
10774: &Apache::lonnet::appenv({'cgi.dir' => $dir});
10775: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
10776: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
10777: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
10778: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
10779: my $decompressed = $env{'cgi.decompressed'};
10780: &Apache::lonnet::delenv('cgi.file');
10781: &Apache::lonnet::delenv('cgi.dir');
10782: &Apache::lonnet::delenv('cgi.decompressed');
10783: return ($decompressed,$result);
10784: }
10785:
1.1055 raeburn 10786: sub process_decompression {
10787: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
10788: my ($dir,$error,$warning,$output);
10789: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
10790: $error = &mt('File name not a supported archive file type.').
10791: '<br />'.&mt('File name should end with one of: [_1].',
10792: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
10793: } else {
10794: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
10795: if ($docuhome eq 'no_host') {
10796: $error = &mt('Could not determine home server for course.');
10797: } else {
10798: my @ids=&Apache::lonnet::current_machine_ids();
10799: my $currdir = "$dir_root/$destination";
10800: if (grep(/^\Q$docuhome\E$/,@ids)) {
10801: $dir = &LONCAPA::propath($docudom,$docuname).
10802: "$dir_root/$destination";
10803: } else {
10804: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
10805: "$dir_root/$docudom/$docuname/$destination";
10806: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
10807: $error = &mt('Archive file not found.');
10808: }
10809: }
1.1065 raeburn 10810: my (@to_overwrite,@to_skip);
10811: if ($env{'form.archive_overwrite_total'} > 0) {
10812: my $total = $env{'form.archive_overwrite_total'};
10813: for (my $i=0; $i<$total; $i++) {
10814: if ($env{'form.archive_overwrite_'.$i} == 1) {
10815: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
10816: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
10817: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
10818: }
10819: }
10820: }
10821: my $numskip = scalar(@to_skip);
10822: if (($numskip > 0) &&
10823: ($numskip == $env{'form.archive_itemcount'})) {
10824: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
10825: } elsif ($dir eq '') {
1.1055 raeburn 10826: $error = &mt('Directory containing archive file unavailable.');
10827: } elsif (!$error) {
1.1065 raeburn 10828: my ($decompressed,$display);
10829: if ($numskip > 0) {
10830: my $tempdir = time.'_'.$$.int(rand(10000));
10831: mkdir("$dir/$tempdir",0755);
10832: system("mv $dir/$file $dir/$tempdir/$file");
10833: ($decompressed,$display) =
10834: &decompress_uploaded_file($file,"$dir/$tempdir");
10835: foreach my $item (@to_skip) {
10836: if (($item ne '') && ($item !~ /\.\./)) {
10837: if (-f "$dir/$tempdir/$item") {
10838: unlink("$dir/$tempdir/$item");
10839: } elsif (-d "$dir/$tempdir/$item") {
10840: system("rm -rf $dir/$tempdir/$item");
10841: }
10842: }
10843: }
10844: system("mv $dir/$tempdir/* $dir");
10845: rmdir("$dir/$tempdir");
10846: } else {
10847: ($decompressed,$display) =
10848: &decompress_uploaded_file($file,$dir);
10849: }
1.1055 raeburn 10850: if ($decompressed eq 'ok') {
1.1065 raeburn 10851: $output = '<p class="LC_info">'.
10852: &mt('Files extracted successfully from archive.').
10853: '</p>'."\n";
1.1055 raeburn 10854: my ($warning,$result,@contents);
10855: my ($newdirlistref,$newlisterror) =
10856: &Apache::lonnet::dirlist($currdir,$docudom,
10857: $docuname,1);
10858: my (%is_dir,%changes,@newitems);
10859: my $dirptr = 16384;
1.1065 raeburn 10860: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 10861: foreach my $dir_line (@{$newdirlistref}) {
10862: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 10863: unless (($item =~ /^\.+$/) || ($item eq $file) ||
10864: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 10865: push(@newitems,$item);
10866: if ($dirptr&$testdir) {
10867: $is_dir{$item} = 1;
10868: }
10869: $changes{$item} = 1;
10870: }
10871: }
10872: }
10873: if (keys(%changes) > 0) {
10874: foreach my $item (sort(@newitems)) {
10875: if ($changes{$item}) {
10876: push(@contents,$item);
10877: }
10878: }
10879: }
10880: if (@contents > 0) {
1.1067 raeburn 10881: my $wantform;
10882: unless ($env{'form.autoextract_camtasia'}) {
10883: $wantform = 1;
10884: }
1.1056 raeburn 10885: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 10886: my ($count,$datatable) = &get_extracted($docudom,$docuname,
10887: $currdir,\%is_dir,
10888: \%children,\%parent,
1.1056 raeburn 10889: \@contents,\%dirorder,
10890: \%titles,$wantform);
1.1055 raeburn 10891: if ($datatable ne '') {
10892: $output .= &archive_options_form('decompressed',$datatable,
10893: $count,$hiddenelem);
1.1065 raeburn 10894: my $startcount = 6;
1.1055 raeburn 10895: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 10896: \%titles,\%children);
1.1055 raeburn 10897: }
1.1067 raeburn 10898: if ($env{'form.autoextract_camtasia'}) {
10899: my %displayed;
10900: my $total = 1;
10901: $env{'form.archive_directory'} = [];
10902: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
10903: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
10904: $path =~ s{/$}{};
10905: my $item;
10906: if ($path ne '') {
10907: $item = "$path/$titles{$i}";
10908: } else {
10909: $item = $titles{$i};
10910: }
10911: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
10912: if ($item eq $contents[0]) {
10913: push(@{$env{'form.archive_directory'}},$i);
10914: $env{'form.archive_'.$i} = 'display';
10915: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
10916: $displayed{'folder'} = $i;
10917: } elsif ($item eq "$contents[0]/index.html") {
10918: $env{'form.archive_'.$i} = 'display';
10919: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
10920: $displayed{'web'} = $i;
10921: } else {
10922: if ($item eq "$contents[0]/media") {
10923: push(@{$env{'form.archive_directory'}},$i);
10924: }
10925: $env{'form.archive_'.$i} = 'dependency';
10926: }
10927: $total ++;
10928: }
10929: for (my $i=1; $i<$total; $i++) {
10930: next if ($i == $displayed{'web'});
10931: next if ($i == $displayed{'folder'});
10932: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
10933: }
10934: $env{'form.phase'} = 'decompress_cleanup';
10935: $env{'form.archivedelete'} = 1;
10936: $env{'form.archive_count'} = $total-1;
10937: $output .=
10938: &process_extracted_files('coursedocs',$docudom,
10939: $docuname,$destination,
10940: $dir_root,$hiddenelem);
10941: }
1.1055 raeburn 10942: } else {
10943: $warning = &mt('No new items extracted from archive file.');
10944: }
10945: } else {
10946: $output = $display;
10947: $error = &mt('An error occurred during extraction from the archive file.');
10948: }
10949: }
10950: }
10951: }
10952: if ($error) {
10953: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
10954: $error.'</p>'."\n";
10955: }
10956: if ($warning) {
10957: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
10958: }
10959: return $output;
10960: }
10961:
10962: sub get_extracted {
1.1056 raeburn 10963: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
10964: $titles,$wantform) = @_;
1.1055 raeburn 10965: my $count = 0;
10966: my $depth = 0;
10967: my $datatable;
1.1056 raeburn 10968: my @hierarchy;
1.1055 raeburn 10969: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 10970: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
10971: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 10972: foreach my $item (@{$contents}) {
10973: $count ++;
1.1056 raeburn 10974: @{$dirorder->{$count}} = @hierarchy;
10975: $titles->{$count} = $item;
1.1055 raeburn 10976: &archive_hierarchy($depth,$count,$parent,$children);
10977: if ($wantform) {
10978: $datatable .= &archive_row($is_dir->{$item},$item,
10979: $currdir,$depth,$count);
10980: }
10981: if ($is_dir->{$item}) {
10982: $depth ++;
1.1056 raeburn 10983: push(@hierarchy,$count);
10984: $parent->{$depth} = $count;
1.1055 raeburn 10985: $datatable .=
10986: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 10987: \$depth,\$count,\@hierarchy,$dirorder,
10988: $children,$parent,$titles,$wantform);
1.1055 raeburn 10989: $depth --;
1.1056 raeburn 10990: pop(@hierarchy);
1.1055 raeburn 10991: }
10992: }
10993: return ($count,$datatable);
10994: }
10995:
10996: sub recurse_extracted_archive {
1.1056 raeburn 10997: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
10998: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 10999: my $result='';
1.1056 raeburn 11000: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11001: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11002: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11003: return $result;
11004: }
11005: my $dirptr = 16384;
11006: my ($newdirlistref,$newlisterror) =
11007: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11008: if (ref($newdirlistref) eq 'ARRAY') {
11009: foreach my $dir_line (@{$newdirlistref}) {
11010: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11011: unless ($item =~ /^\.+$/) {
11012: $$count ++;
1.1056 raeburn 11013: @{$dirorder->{$$count}} = @{$hierarchy};
11014: $titles->{$$count} = $item;
1.1055 raeburn 11015: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11016:
1.1055 raeburn 11017: my $is_dir;
11018: if ($dirptr&$testdir) {
11019: $is_dir = 1;
11020: }
11021: if ($wantform) {
11022: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11023: }
11024: if ($is_dir) {
11025: $$depth ++;
1.1056 raeburn 11026: push(@{$hierarchy},$$count);
11027: $parent->{$$depth} = $$count;
1.1055 raeburn 11028: $result .=
11029: &recurse_extracted_archive("$currdir/$item",$docudom,
11030: $docuname,$depth,$count,
1.1056 raeburn 11031: $hierarchy,$dirorder,$children,
11032: $parent,$titles,$wantform);
1.1055 raeburn 11033: $$depth --;
1.1056 raeburn 11034: pop(@{$hierarchy});
1.1055 raeburn 11035: }
11036: }
11037: }
11038: }
11039: return $result;
11040: }
11041:
11042: sub archive_hierarchy {
11043: my ($depth,$count,$parent,$children) =@_;
11044: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11045: if (exists($parent->{$depth})) {
11046: $children->{$parent->{$depth}} .= $count.':';
11047: }
11048: }
11049: return;
11050: }
11051:
11052: sub archive_row {
11053: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11054: my ($name) = ($item =~ m{([^/]+)$});
11055: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11056: 'display' => 'Add as file',
1.1055 raeburn 11057: 'dependency' => 'Include as dependency',
11058: 'discard' => 'Discard',
11059: );
11060: if ($is_dir) {
1.1059 raeburn 11061: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11062: }
1.1056 raeburn 11063: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11064: my $offset = 0;
1.1055 raeburn 11065: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11066: $offset ++;
1.1065 raeburn 11067: if ($action ne 'display') {
11068: $offset ++;
11069: }
1.1055 raeburn 11070: $output .= '<td><span class="LC_nobreak">'.
11071: '<label><input type="radio" name="archive_'.$count.
11072: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11073: my $text = $choices{$action};
11074: if ($is_dir) {
11075: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11076: if ($action eq 'display') {
1.1059 raeburn 11077: $text = &mt('Add as folder');
1.1055 raeburn 11078: }
1.1056 raeburn 11079: } else {
11080: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11081:
11082: }
11083: $output .= ' /> '.$choices{$action}.'</label></span>';
11084: if ($action eq 'dependency') {
11085: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11086: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11087: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11088: '<option value=""></option>'."\n".
11089: '</select>'."\n".
11090: '</div>';
1.1059 raeburn 11091: } elsif ($action eq 'display') {
11092: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11093: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11094: '</div>';
1.1055 raeburn 11095: }
1.1056 raeburn 11096: $output .= '</td>';
1.1055 raeburn 11097: }
11098: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11099: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11100: for (my $i=0; $i<$depth; $i++) {
11101: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11102: }
11103: if ($is_dir) {
11104: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11105: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11106: } else {
11107: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11108: }
11109: $output .= ' '.$name.'</td>'."\n".
11110: &end_data_table_row();
11111: return $output;
11112: }
11113:
11114: sub archive_options_form {
1.1065 raeburn 11115: my ($form,$display,$count,$hiddenelem) = @_;
11116: my %lt = &Apache::lonlocal::texthash(
11117: perm => 'Permanently remove archive file?',
11118: hows => 'How should each extracted item be incorporated in the course?',
11119: cont => 'Content actions for all',
11120: addf => 'Add as folder/file',
11121: incd => 'Include as dependency for a displayed file',
11122: disc => 'Discard',
11123: no => 'No',
11124: yes => 'Yes',
11125: save => 'Save',
11126: );
11127: my $output = <<"END";
11128: <form name="$form" method="post" action="">
11129: <p><span class="LC_nobreak">$lt{'perm'}
11130: <label>
11131: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11132: </label>
11133:
11134: <label>
11135: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11136: </span>
11137: </p>
11138: <input type="hidden" name="phase" value="decompress_cleanup" />
11139: <br />$lt{'hows'}
11140: <div class="LC_columnSection">
11141: <fieldset>
11142: <legend>$lt{'cont'}</legend>
11143: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11144: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11145: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11146: </fieldset>
11147: </div>
11148: END
11149: return $output.
1.1055 raeburn 11150: &start_data_table()."\n".
1.1065 raeburn 11151: $display."\n".
1.1055 raeburn 11152: &end_data_table()."\n".
11153: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11154: $hiddenelem.
1.1065 raeburn 11155: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11156: '</form>';
11157: }
11158:
11159: sub archive_javascript {
1.1056 raeburn 11160: my ($startcount,$numitems,$titles,$children) = @_;
11161: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11162: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11163: my $scripttag = <<START;
11164: <script type="text/javascript">
11165: // <![CDATA[
11166:
11167: function checkAll(form,prefix) {
11168: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11169: for (var i=0; i < form.elements.length; i++) {
11170: var id = form.elements[i].id;
11171: if ((id != '') && (id != undefined)) {
11172: if (idstr.test(id)) {
11173: if (form.elements[i].type == 'radio') {
11174: form.elements[i].checked = true;
1.1056 raeburn 11175: var nostart = i-$startcount;
1.1059 raeburn 11176: var offset = nostart%7;
11177: var count = (nostart-offset)/7;
1.1056 raeburn 11178: dependencyCheck(form,count,offset);
1.1055 raeburn 11179: }
11180: }
11181: }
11182: }
11183: }
11184:
11185: function propagateCheck(form,count) {
11186: if (count > 0) {
1.1059 raeburn 11187: var startelement = $startcount + ((count-1) * 7);
11188: for (var j=1; j<6; j++) {
11189: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11190: var item = startelement + j;
11191: if (form.elements[item].type == 'radio') {
11192: if (form.elements[item].checked) {
11193: containerCheck(form,count,j);
11194: break;
11195: }
1.1055 raeburn 11196: }
11197: }
11198: }
11199: }
11200: }
11201:
11202: numitems = $numitems
1.1056 raeburn 11203: var titles = new Array(numitems);
11204: var parents = new Array(numitems);
1.1055 raeburn 11205: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11206: parents[i] = new Array;
1.1055 raeburn 11207: }
1.1059 raeburn 11208: var maintitle = '$maintitle';
1.1055 raeburn 11209:
11210: START
11211:
1.1056 raeburn 11212: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11213: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11214: for (my $i=0; $i<@contents; $i ++) {
11215: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11216: }
11217: }
11218:
1.1056 raeburn 11219: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11220: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11221: }
11222:
1.1055 raeburn 11223: $scripttag .= <<END;
11224:
11225: function containerCheck(form,count,offset) {
11226: if (count > 0) {
1.1056 raeburn 11227: dependencyCheck(form,count,offset);
1.1059 raeburn 11228: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11229: form.elements[item].checked = true;
11230: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11231: if (parents[count].length > 0) {
11232: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11233: containerCheck(form,parents[count][j],offset);
11234: }
11235: }
11236: }
11237: }
11238: }
11239:
11240: function dependencyCheck(form,count,offset) {
11241: if (count > 0) {
1.1059 raeburn 11242: var chosen = (offset+$startcount)+7*(count-1);
11243: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11244: var currtype = form.elements[depitem].type;
11245: if (form.elements[chosen].value == 'dependency') {
11246: document.getElementById('arc_depon_'+count).style.display='block';
11247: form.elements[depitem].options.length = 0;
11248: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11249: for (var i=1; i<=numitems; i++) {
11250: if (i == count) {
11251: continue;
11252: }
1.1059 raeburn 11253: var startelement = $startcount + (i-1) * 7;
11254: for (var j=1; j<6; j++) {
11255: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11256: var item = startelement + j;
11257: if (form.elements[item].type == 'radio') {
11258: if (form.elements[item].checked) {
11259: if (form.elements[item].value == 'display') {
11260: var n = form.elements[depitem].options.length;
11261: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11262: }
11263: }
11264: }
11265: }
11266: }
11267: }
11268: } else {
11269: document.getElementById('arc_depon_'+count).style.display='none';
11270: form.elements[depitem].options.length = 0;
11271: form.elements[depitem].options[0] = new Option('Select','',true,true);
11272: }
1.1059 raeburn 11273: titleCheck(form,count,offset);
1.1056 raeburn 11274: }
11275: }
11276:
11277: function propagateSelect(form,count,offset) {
11278: if (count > 0) {
1.1065 raeburn 11279: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11280: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11281: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11282: if (parents[count].length > 0) {
11283: for (var j=0; j<parents[count].length; j++) {
11284: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11285: }
11286: }
11287: }
11288: }
11289: }
1.1056 raeburn 11290:
11291: function containerSelect(form,count,offset,picked) {
11292: if (count > 0) {
1.1065 raeburn 11293: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11294: if (form.elements[item].type == 'radio') {
11295: if (form.elements[item].value == 'dependency') {
11296: if (form.elements[item+1].type == 'select-one') {
11297: for (var i=0; i<form.elements[item+1].options.length; i++) {
11298: if (form.elements[item+1].options[i].value == picked) {
11299: form.elements[item+1].selectedIndex = i;
11300: break;
11301: }
11302: }
11303: }
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);
11308: }
11309: }
11310: }
11311: }
11312: }
11313: }
11314: }
11315:
1.1059 raeburn 11316: function titleCheck(form,count,offset) {
11317: if (count > 0) {
11318: var chosen = (offset+$startcount)+7*(count-1);
11319: var depitem = $startcount + ((count-1) * 7) + 2;
11320: var currtype = form.elements[depitem].type;
11321: if (form.elements[chosen].value == 'display') {
11322: document.getElementById('arc_title_'+count).style.display='block';
11323: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11324: document.getElementById('archive_title_'+count).value=maintitle;
11325: }
11326: } else {
11327: document.getElementById('arc_title_'+count).style.display='none';
11328: if (currtype == 'text') {
11329: document.getElementById('archive_title_'+count).value='';
11330: }
11331: }
11332: }
11333: return;
11334: }
11335:
1.1055 raeburn 11336: // ]]>
11337: </script>
11338: END
11339: return $scripttag;
11340: }
11341:
11342: sub process_extracted_files {
1.1067 raeburn 11343: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11344: my $numitems = $env{'form.archive_count'};
11345: return unless ($numitems);
11346: my @ids=&Apache::lonnet::current_machine_ids();
11347: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11348: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11349: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11350: if (grep(/^\Q$docuhome\E$/,@ids)) {
11351: $prefix = &LONCAPA::propath($docudom,$docuname);
11352: $pathtocheck = "$dir_root/$destination";
11353: $dir = $dir_root;
11354: $ishome = 1;
11355: } else {
11356: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11357: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11358: $dir = "$dir_root/$docudom/$docuname";
11359: }
11360: my $currdir = "$dir_root/$destination";
11361: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11362: if ($env{'form.folderpath'}) {
11363: my @items = split('&',$env{'form.folderpath'});
11364: $folders{'0'} = $items[-2];
1.1099 raeburn 11365: if ($env{'form.folderpath'} =~ /\:1$/) {
11366: $containers{'0'}='page';
11367: } else {
11368: $containers{'0'}='sequence';
11369: }
1.1055 raeburn 11370: }
11371: my @archdirs = &get_env_multiple('form.archive_directory');
11372: if ($numitems) {
11373: for (my $i=1; $i<=$numitems; $i++) {
11374: my $path = $env{'form.archive_content_'.$i};
11375: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11376: my $item = $1;
11377: $toplevelitems{$item} = $i;
11378: if (grep(/^\Q$i\E$/,@archdirs)) {
11379: $is_dir{$item} = 1;
11380: }
11381: }
11382: }
11383: }
1.1067 raeburn 11384: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11385: if (keys(%toplevelitems) > 0) {
11386: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11387: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11388: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11389: }
1.1066 raeburn 11390: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11391: if ($numitems) {
11392: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11393: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11394: my $path = $env{'form.archive_content_'.$i};
11395: if ($path =~ /^\Q$pathtocheck\E/) {
11396: if ($env{'form.archive_'.$i} eq 'discard') {
11397: if ($prefix ne '' && $path ne '') {
11398: if (-e $prefix.$path) {
1.1066 raeburn 11399: if ((@archdirs > 0) &&
11400: (grep(/^\Q$i\E$/,@archdirs))) {
11401: $todeletedir{$prefix.$path} = 1;
11402: } else {
11403: $todelete{$prefix.$path} = 1;
11404: }
1.1055 raeburn 11405: }
11406: }
11407: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11408: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11409: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11410: $docstitle = $env{'form.archive_title_'.$i};
11411: if ($docstitle eq '') {
11412: $docstitle = $title;
11413: }
1.1055 raeburn 11414: $outer = 0;
1.1056 raeburn 11415: if (ref($dirorder{$i}) eq 'ARRAY') {
11416: if (@{$dirorder{$i}} > 0) {
11417: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11418: if ($env{'form.archive_'.$item} eq 'display') {
11419: $outer = $item;
11420: last;
11421: }
11422: }
11423: }
11424: }
11425: my ($errtext,$fatal) =
11426: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11427: '/'.$folders{$outer}.'.'.
11428: $containers{$outer});
11429: next if ($fatal);
11430: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11431: if ($context eq 'coursedocs') {
1.1056 raeburn 11432: $mapinner{$i} = time;
1.1055 raeburn 11433: $folders{$i} = 'default_'.$mapinner{$i};
11434: $containers{$i} = 'sequence';
11435: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11436: $folders{$i}.'.'.$containers{$i};
11437: my $newidx = &LONCAPA::map::getresidx();
11438: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11439: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11440: push(@LONCAPA::map::order,$newidx);
11441: my ($outtext,$errtext) =
11442: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11443: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11444: '.'.$containers{$outer},1,1);
1.1056 raeburn 11445: $newseqid{$i} = $newidx;
1.1067 raeburn 11446: unless ($errtext) {
11447: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11448: }
1.1055 raeburn 11449: }
11450: } else {
11451: if ($context eq 'coursedocs') {
11452: my $newidx=&LONCAPA::map::getresidx();
11453: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11454: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11455: $title;
11456: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11457: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11458: }
11459: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11460: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11461: }
11462: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11463: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11464: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11465: unless ($ishome) {
11466: my $fetch = "$newdest{$i}/$title";
11467: $fetch =~ s/^\Q$prefix$dir\E//;
11468: $prompttofetch{$fetch} = 1;
11469: }
1.1055 raeburn 11470: }
11471: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11472: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11473: push(@LONCAPA::map::order, $newidx);
11474: my ($outtext,$errtext)=
11475: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11476: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11477: '.'.$containers{$outer},1,1);
1.1067 raeburn 11478: unless ($errtext) {
11479: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11480: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11481: }
11482: }
1.1055 raeburn 11483: }
11484: }
1.1086 raeburn 11485: }
11486: } else {
11487: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11488: }
11489: }
11490: for (my $i=1; $i<=$numitems; $i++) {
11491: next unless ($env{'form.archive_'.$i} eq 'dependency');
11492: my $path = $env{'form.archive_content_'.$i};
11493: if ($path =~ /^\Q$pathtocheck\E/) {
11494: my ($title) = ($path =~ m{/([^/]+)$});
11495: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11496: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11497: if (ref($dirorder{$i}) eq 'ARRAY') {
11498: my ($itemidx,$fullpath,$relpath);
11499: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11500: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11501: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11502: if ($dirorder{$i}->[$j] eq $container) {
11503: $itemidx = $j;
1.1056 raeburn 11504: }
11505: }
1.1086 raeburn 11506: }
11507: if ($itemidx eq '') {
11508: $itemidx = 0;
11509: }
11510: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11511: if ($mapinner{$referrer{$i}}) {
11512: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11513: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11514: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11515: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11516: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11517: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11518: if (!-e $fullpath) {
11519: mkdir($fullpath,0755);
1.1056 raeburn 11520: }
11521: }
1.1086 raeburn 11522: } else {
11523: last;
1.1056 raeburn 11524: }
1.1086 raeburn 11525: }
11526: }
11527: } elsif ($newdest{$referrer{$i}}) {
11528: $fullpath = $newdest{$referrer{$i}};
11529: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11530: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11531: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11532: last;
11533: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11534: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11535: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11536: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11537: if (!-e $fullpath) {
11538: mkdir($fullpath,0755);
1.1056 raeburn 11539: }
11540: }
1.1086 raeburn 11541: } else {
11542: last;
1.1056 raeburn 11543: }
1.1055 raeburn 11544: }
11545: }
1.1086 raeburn 11546: if ($fullpath ne '') {
11547: if (-e "$prefix$path") {
11548: system("mv $prefix$path $fullpath/$title");
11549: }
11550: if (-e "$fullpath/$title") {
11551: my $showpath;
11552: if ($relpath ne '') {
11553: $showpath = "$relpath/$title";
11554: } else {
11555: $showpath = "/$title";
11556: }
11557: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11558: }
11559: unless ($ishome) {
11560: my $fetch = "$fullpath/$title";
11561: $fetch =~ s/^\Q$prefix$dir\E//;
11562: $prompttofetch{$fetch} = 1;
11563: }
11564: }
1.1055 raeburn 11565: }
1.1086 raeburn 11566: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11567: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11568: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11569: }
11570: } else {
11571: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11572: }
11573: }
11574: if (keys(%todelete)) {
11575: foreach my $key (keys(%todelete)) {
11576: unlink($key);
1.1066 raeburn 11577: }
11578: }
11579: if (keys(%todeletedir)) {
11580: foreach my $key (keys(%todeletedir)) {
11581: rmdir($key);
11582: }
11583: }
11584: foreach my $dir (sort(keys(%is_dir))) {
11585: if (($pathtocheck ne '') && ($dir ne '')) {
11586: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11587: }
11588: }
1.1067 raeburn 11589: if ($result ne '') {
11590: $output .= '<ul>'."\n".
11591: $result."\n".
11592: '</ul>';
11593: }
11594: unless ($ishome) {
11595: my $replicationfail;
11596: foreach my $item (keys(%prompttofetch)) {
11597: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11598: unless ($fetchresult eq 'ok') {
11599: $replicationfail .= '<li>'.$item.'</li>'."\n";
11600: }
11601: }
11602: if ($replicationfail) {
11603: $output .= '<p class="LC_error">'.
11604: &mt('Course home server failed to retrieve:').'<ul>'.
11605: $replicationfail.
11606: '</ul></p>';
11607: }
11608: }
1.1055 raeburn 11609: } else {
11610: $warning = &mt('No items found in archive.');
11611: }
11612: if ($error) {
11613: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11614: $error.'</p>'."\n";
11615: }
11616: if ($warning) {
11617: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11618: }
11619: return $output;
11620: }
11621:
1.1066 raeburn 11622: sub cleanup_empty_dirs {
11623: my ($path) = @_;
11624: if (($path ne '') && (-d $path)) {
11625: if (opendir(my $dirh,$path)) {
11626: my @dircontents = grep(!/^\./,readdir($dirh));
11627: my $numitems = 0;
11628: foreach my $item (@dircontents) {
11629: if (-d "$path/$item") {
1.1111 raeburn 11630: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11631: if (-e "$path/$item") {
11632: $numitems ++;
11633: }
11634: } else {
11635: $numitems ++;
11636: }
11637: }
11638: if ($numitems == 0) {
11639: rmdir($path);
11640: }
11641: closedir($dirh);
11642: }
11643: }
11644: return;
11645: }
11646:
1.41 ng 11647: =pod
1.45 matthew 11648:
1.1068 raeburn 11649: =item &get_folder_hierarchy()
11650:
11651: Provides hierarchy of names of folders/sub-folders containing the current
11652: item,
11653:
11654: Inputs: 3
11655: - $navmap - navmaps object
11656:
11657: - $map - url for map (either the trigger itself, or map containing
11658: the resource, which is the trigger).
11659:
11660: - $showitem - 1 => show title for map itself; 0 => do not show.
11661:
11662: Outputs: 1 @pathitems - array of folder/subfolder names.
11663:
11664: =cut
11665:
11666: sub get_folder_hierarchy {
11667: my ($navmap,$map,$showitem) = @_;
11668: my @pathitems;
11669: if (ref($navmap)) {
11670: my $mapres = $navmap->getResourceByUrl($map);
11671: if (ref($mapres)) {
11672: my $pcslist = $mapres->map_hierarchy();
11673: if ($pcslist ne '') {
11674: my @pcs = split(/,/,$pcslist);
11675: foreach my $pc (@pcs) {
11676: if ($pc == 1) {
11677: push(@pathitems,&mt('Main Course Documents'));
11678: } else {
11679: my $res = $navmap->getByMapPc($pc);
11680: if (ref($res)) {
11681: my $title = $res->compTitle();
11682: $title =~ s/\W+/_/g;
11683: if ($title ne '') {
11684: push(@pathitems,$title);
11685: }
11686: }
11687: }
11688: }
11689: }
1.1071 raeburn 11690: if ($showitem) {
11691: if ($mapres->{ID} eq '0.0') {
11692: push(@pathitems,&mt('Main Course Documents'));
11693: } else {
11694: my $maptitle = $mapres->compTitle();
11695: $maptitle =~ s/\W+/_/g;
11696: if ($maptitle ne '') {
11697: push(@pathitems,$maptitle);
11698: }
1.1068 raeburn 11699: }
11700: }
11701: }
11702: }
11703: return @pathitems;
11704: }
11705:
11706: =pod
11707:
1.1015 raeburn 11708: =item * &get_turnedin_filepath()
11709:
11710: Determines path in a user's portfolio file for storage of files uploaded
11711: to a specific essayresponse or dropbox item.
11712:
11713: Inputs: 3 required + 1 optional.
11714: $symb is symb for resource, $uname and $udom are for current user (required).
11715: $caller is optional (can be "submission", if routine is called when storing
11716: an upoaded file when "Submit Answer" button was pressed).
11717:
11718: Returns array containing $path and $multiresp.
11719: $path is path in portfolio. $multiresp is 1 if this resource contains more
11720: than one file upload item. Callers of routine should append partid as a
11721: subdirectory to $path in cases where $multiresp is 1.
11722:
11723: Called by: homework/essayresponse.pm and homework/structuretags.pm
11724:
11725: =cut
11726:
11727: sub get_turnedin_filepath {
11728: my ($symb,$uname,$udom,$caller) = @_;
11729: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
11730: my $turnindir;
11731: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
11732: $turnindir = $userhash{'turnindir'};
11733: my ($path,$multiresp);
11734: if ($turnindir eq '') {
11735: if ($caller eq 'submission') {
11736: $turnindir = &mt('turned in');
11737: $turnindir =~ s/\W+/_/g;
11738: my %newhash = (
11739: 'turnindir' => $turnindir,
11740: );
11741: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
11742: }
11743: }
11744: if ($turnindir ne '') {
11745: $path = '/'.$turnindir.'/';
11746: my ($multipart,$turnin,@pathitems);
11747: my $navmap = Apache::lonnavmaps::navmap->new();
11748: if (defined($navmap)) {
11749: my $mapres = $navmap->getResourceByUrl($map);
11750: if (ref($mapres)) {
11751: my $pcslist = $mapres->map_hierarchy();
11752: if ($pcslist ne '') {
11753: foreach my $pc (split(/,/,$pcslist)) {
11754: my $res = $navmap->getByMapPc($pc);
11755: if (ref($res)) {
11756: my $title = $res->compTitle();
11757: $title =~ s/\W+/_/g;
11758: if ($title ne '') {
11759: push(@pathitems,$title);
11760: }
11761: }
11762: }
11763: }
11764: my $maptitle = $mapres->compTitle();
11765: $maptitle =~ s/\W+/_/g;
11766: if ($maptitle ne '') {
11767: push(@pathitems,$maptitle);
11768: }
11769: unless ($env{'request.state'} eq 'construct') {
11770: my $res = $navmap->getBySymb($symb);
11771: if (ref($res)) {
11772: my $partlist = $res->parts();
11773: my $totaluploads = 0;
11774: if (ref($partlist) eq 'ARRAY') {
11775: foreach my $part (@{$partlist}) {
11776: my @types = $res->responseType($part);
11777: my @ids = $res->responseIds($part);
11778: for (my $i=0; $i < scalar(@ids); $i++) {
11779: if ($types[$i] eq 'essay') {
11780: my $partid = $part.'_'.$ids[$i];
11781: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
11782: $totaluploads ++;
11783: }
11784: }
11785: }
11786: }
11787: if ($totaluploads > 1) {
11788: $multiresp = 1;
11789: }
11790: }
11791: }
11792: }
11793: } else {
11794: return;
11795: }
11796: } else {
11797: return;
11798: }
11799: my $restitle=&Apache::lonnet::gettitle($symb);
11800: $restitle =~ s/\W+/_/g;
11801: if ($restitle eq '') {
11802: $restitle = ($resurl =~ m{/[^/]+$});
11803: if ($restitle eq '') {
11804: $restitle = time;
11805: }
11806: }
11807: push(@pathitems,$restitle);
11808: $path .= join('/',@pathitems);
11809: }
11810: return ($path,$multiresp);
11811: }
11812:
11813: =pod
11814:
1.464 albertel 11815: =back
1.41 ng 11816:
1.112 bowersj2 11817: =head1 CSV Upload/Handling functions
1.38 albertel 11818:
1.41 ng 11819: =over 4
11820:
1.648 raeburn 11821: =item * &upfile_store($r)
1.41 ng 11822:
11823: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 11824: needs $env{'form.upfile'}
1.41 ng 11825: returns $datatoken to be put into hidden field
11826:
11827: =cut
1.31 albertel 11828:
11829: sub upfile_store {
11830: my $r=shift;
1.258 albertel 11831: $env{'form.upfile'}=~s/\r/\n/gs;
11832: $env{'form.upfile'}=~s/\f/\n/gs;
11833: $env{'form.upfile'}=~s/\n+/\n/gs;
11834: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 11835:
1.258 albertel 11836: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
11837: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 11838: {
1.158 raeburn 11839: my $datafile = $r->dir_config('lonDaemons').
11840: '/tmp/'.$datatoken.'.tmp';
11841: if ( open(my $fh,">$datafile") ) {
1.258 albertel 11842: print $fh $env{'form.upfile'};
1.158 raeburn 11843: close($fh);
11844: }
1.31 albertel 11845: }
11846: return $datatoken;
11847: }
11848:
1.56 matthew 11849: =pod
11850:
1.648 raeburn 11851: =item * &load_tmp_file($r)
1.41 ng 11852:
11853: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 11854: needs $env{'form.datatoken'},
11855: sets $env{'form.upfile'} to the contents of the file
1.41 ng 11856:
11857: =cut
1.31 albertel 11858:
11859: sub load_tmp_file {
11860: my $r=shift;
11861: my @studentdata=();
11862: {
1.158 raeburn 11863: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 11864: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 11865: if ( open(my $fh,"<$studentfile") ) {
11866: @studentdata=<$fh>;
11867: close($fh);
11868: }
1.31 albertel 11869: }
1.258 albertel 11870: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 11871: }
11872:
1.56 matthew 11873: =pod
11874:
1.648 raeburn 11875: =item * &upfile_record_sep()
1.41 ng 11876:
11877: Separate uploaded file into records
11878: returns array of records,
1.258 albertel 11879: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 11880:
11881: =cut
1.31 albertel 11882:
11883: sub upfile_record_sep {
1.258 albertel 11884: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 11885: } else {
1.248 albertel 11886: my @records;
1.258 albertel 11887: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 11888: if ($line=~/^\s*$/) { next; }
11889: push(@records,$line);
11890: }
11891: return @records;
1.31 albertel 11892: }
11893: }
11894:
1.56 matthew 11895: =pod
11896:
1.648 raeburn 11897: =item * &record_sep($record)
1.41 ng 11898:
1.258 albertel 11899: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 11900:
11901: =cut
11902:
1.263 www 11903: sub takeleft {
11904: my $index=shift;
11905: return substr('0000'.$index,-4,4);
11906: }
11907:
1.31 albertel 11908: sub record_sep {
11909: my $record=shift;
11910: my %components=();
1.258 albertel 11911: if ($env{'form.upfiletype'} eq 'xml') {
11912: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 11913: my $i=0;
1.356 albertel 11914: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 11915: $field=~s/^(\"|\')//;
11916: $field=~s/(\"|\')$//;
1.263 www 11917: $components{&takeleft($i)}=$field;
1.31 albertel 11918: $i++;
11919: }
1.258 albertel 11920: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 11921: my $i=0;
1.356 albertel 11922: foreach my $field (split(/\t/,$record)) {
1.31 albertel 11923: $field=~s/^(\"|\')//;
11924: $field=~s/(\"|\')$//;
1.263 www 11925: $components{&takeleft($i)}=$field;
1.31 albertel 11926: $i++;
11927: }
11928: } else {
1.561 www 11929: my $separator=',';
1.480 banghart 11930: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 11931: $separator=';';
1.480 banghart 11932: }
1.31 albertel 11933: my $i=0;
1.561 www 11934: # the character we are looking for to indicate the end of a quote or a record
11935: my $looking_for=$separator;
11936: # do not add the characters to the fields
11937: my $ignore=0;
11938: # we just encountered a separator (or the beginning of the record)
11939: my $just_found_separator=1;
11940: # store the field we are working on here
11941: my $field='';
11942: # work our way through all characters in record
11943: foreach my $character ($record=~/(.)/g) {
11944: if ($character eq $looking_for) {
11945: if ($character ne $separator) {
11946: # Found the end of a quote, again looking for separator
11947: $looking_for=$separator;
11948: $ignore=1;
11949: } else {
11950: # Found a separator, store away what we got
11951: $components{&takeleft($i)}=$field;
11952: $i++;
11953: $just_found_separator=1;
11954: $ignore=0;
11955: $field='';
11956: }
11957: next;
11958: }
11959: # single or double quotation marks after a separator indicate beginning of a quote
11960: # we are now looking for the end of the quote and need to ignore separators
11961: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
11962: $looking_for=$character;
11963: next;
11964: }
11965: # ignore would be true after we reached the end of a quote
11966: if ($ignore) { next; }
11967: if (($just_found_separator) && ($character=~/\s/)) { next; }
11968: $field.=$character;
11969: $just_found_separator=0;
1.31 albertel 11970: }
1.561 www 11971: # catch the very last entry, since we never encountered the separator
11972: $components{&takeleft($i)}=$field;
1.31 albertel 11973: }
11974: return %components;
11975: }
11976:
1.144 matthew 11977: ######################################################
11978: ######################################################
11979:
1.56 matthew 11980: =pod
11981:
1.648 raeburn 11982: =item * &upfile_select_html()
1.41 ng 11983:
1.144 matthew 11984: Return HTML code to select a file from the users machine and specify
11985: the file type.
1.41 ng 11986:
11987: =cut
11988:
1.144 matthew 11989: ######################################################
11990: ######################################################
1.31 albertel 11991: sub upfile_select_html {
1.144 matthew 11992: my %Types = (
11993: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 11994: semisv => &mt('Semicolon separated values'),
1.144 matthew 11995: space => &mt('Space separated'),
11996: tab => &mt('Tabulator separated'),
11997: # xml => &mt('HTML/XML'),
11998: );
11999: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12000: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12001: foreach my $type (sort(keys(%Types))) {
12002: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12003: }
12004: $Str .= "</select>\n";
12005: return $Str;
1.31 albertel 12006: }
12007:
1.301 albertel 12008: sub get_samples {
12009: my ($records,$toget) = @_;
12010: my @samples=({});
12011: my $got=0;
12012: foreach my $rec (@$records) {
12013: my %temp = &record_sep($rec);
12014: if (! grep(/\S/, values(%temp))) { next; }
12015: if (%temp) {
12016: $samples[$got]=\%temp;
12017: $got++;
12018: if ($got == $toget) { last; }
12019: }
12020: }
12021: return \@samples;
12022: }
12023:
1.144 matthew 12024: ######################################################
12025: ######################################################
12026:
1.56 matthew 12027: =pod
12028:
1.648 raeburn 12029: =item * &csv_print_samples($r,$records)
1.41 ng 12030:
12031: Prints a table of sample values from each column uploaded $r is an
12032: Apache Request ref, $records is an arrayref from
12033: &Apache::loncommon::upfile_record_sep
12034:
12035: =cut
12036:
1.144 matthew 12037: ######################################################
12038: ######################################################
1.31 albertel 12039: sub csv_print_samples {
12040: my ($r,$records) = @_;
1.662 bisitz 12041: my $samples = &get_samples($records,5);
1.301 albertel 12042:
1.594 raeburn 12043: $r->print(&mt('Samples').'<br />'.&start_data_table().
12044: &start_data_table_header_row());
1.356 albertel 12045: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12046: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12047: $r->print(&end_data_table_header_row());
1.301 albertel 12048: foreach my $hash (@$samples) {
1.594 raeburn 12049: $r->print(&start_data_table_row());
1.356 albertel 12050: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12051: $r->print('<td>');
1.356 albertel 12052: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12053: $r->print('</td>');
12054: }
1.594 raeburn 12055: $r->print(&end_data_table_row());
1.31 albertel 12056: }
1.594 raeburn 12057: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12058: }
12059:
1.144 matthew 12060: ######################################################
12061: ######################################################
12062:
1.56 matthew 12063: =pod
12064:
1.648 raeburn 12065: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12066:
12067: Prints a table to create associations between values and table columns.
1.144 matthew 12068:
1.41 ng 12069: $r is an Apache Request ref,
12070: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12071: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12072:
12073: =cut
12074:
1.144 matthew 12075: ######################################################
12076: ######################################################
1.31 albertel 12077: sub csv_print_select_table {
12078: my ($r,$records,$d) = @_;
1.301 albertel 12079: my $i=0;
12080: my $samples = &get_samples($records,1);
1.144 matthew 12081: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12082: &start_data_table().&start_data_table_header_row().
1.144 matthew 12083: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12084: '<th>'.&mt('Column').'</th>'.
12085: &end_data_table_header_row()."\n");
1.356 albertel 12086: foreach my $array_ref (@$d) {
12087: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12088: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12089:
1.875 bisitz 12090: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12091: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12092: $r->print('<option value="none"></option>');
1.356 albertel 12093: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12094: $r->print('<option value="'.$sample.'"'.
12095: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12096: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12097: }
1.594 raeburn 12098: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12099: $i++;
12100: }
1.594 raeburn 12101: $r->print(&end_data_table());
1.31 albertel 12102: $i--;
12103: return $i;
12104: }
1.56 matthew 12105:
1.144 matthew 12106: ######################################################
12107: ######################################################
12108:
1.56 matthew 12109: =pod
1.31 albertel 12110:
1.648 raeburn 12111: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12112:
12113: Prints a table of sample values from the upload and can make associate samples to internal names.
12114:
12115: $r is an Apache Request ref,
12116: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12117: $d is an array of 2 element arrays (internal name, displayed name)
12118:
12119: =cut
12120:
1.144 matthew 12121: ######################################################
12122: ######################################################
1.31 albertel 12123: sub csv_samples_select_table {
12124: my ($r,$records,$d) = @_;
12125: my $i=0;
1.144 matthew 12126: #
1.662 bisitz 12127: my $max_samples = 5;
12128: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12129: $r->print(&start_data_table().
12130: &start_data_table_header_row().'<th>'.
12131: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12132: &end_data_table_header_row());
1.301 albertel 12133:
12134: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12135: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12136: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12137: foreach my $option (@$d) {
12138: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12139: $r->print('<option value="'.$value.'"'.
1.253 albertel 12140: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12141: $display.'</option>');
1.31 albertel 12142: }
12143: $r->print('</select></td><td>');
1.662 bisitz 12144: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12145: if (defined($samples->[$line]{$key})) {
12146: $r->print($samples->[$line]{$key}."<br />\n");
12147: }
12148: }
1.594 raeburn 12149: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12150: $i++;
12151: }
1.594 raeburn 12152: $r->print(&end_data_table());
1.31 albertel 12153: $i--;
12154: return($i);
1.115 matthew 12155: }
12156:
1.144 matthew 12157: ######################################################
12158: ######################################################
12159:
1.115 matthew 12160: =pod
12161:
1.648 raeburn 12162: =item * &clean_excel_name($name)
1.115 matthew 12163:
12164: Returns a replacement for $name which does not contain any illegal characters.
12165:
12166: =cut
12167:
1.144 matthew 12168: ######################################################
12169: ######################################################
1.115 matthew 12170: sub clean_excel_name {
12171: my ($name) = @_;
12172: $name =~ s/[:\*\?\/\\]//g;
12173: if (length($name) > 31) {
12174: $name = substr($name,0,31);
12175: }
12176: return $name;
1.25 albertel 12177: }
1.84 albertel 12178:
1.85 albertel 12179: =pod
12180:
1.648 raeburn 12181: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12182:
12183: Returns either 1 or undef
12184:
12185: 1 if the part is to be hidden, undef if it is to be shown
12186:
12187: Arguments are:
12188:
12189: $id the id of the part to be checked
12190: $symb, optional the symb of the resource to check
12191: $udom, optional the domain of the user to check for
12192: $uname, optional the username of the user to check for
12193:
12194: =cut
1.84 albertel 12195:
12196: sub check_if_partid_hidden {
12197: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12198: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12199: $symb,$udom,$uname);
1.141 albertel 12200: my $truth=1;
12201: #if the string starts with !, then the list is the list to show not hide
12202: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12203: my @hiddenlist=split(/,/,$hiddenparts);
12204: foreach my $checkid (@hiddenlist) {
1.141 albertel 12205: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12206: }
1.141 albertel 12207: return !$truth;
1.84 albertel 12208: }
1.127 matthew 12209:
1.138 matthew 12210:
12211: ############################################################
12212: ############################################################
12213:
12214: =pod
12215:
1.157 matthew 12216: =back
12217:
1.138 matthew 12218: =head1 cgi-bin script and graphing routines
12219:
1.157 matthew 12220: =over 4
12221:
1.648 raeburn 12222: =item * &get_cgi_id()
1.138 matthew 12223:
12224: Inputs: none
12225:
12226: Returns an id which can be used to pass environment variables
12227: to various cgi-bin scripts. These environment variables will
12228: be removed from the users environment after a given time by
12229: the routine &Apache::lonnet::transfer_profile_to_env.
12230:
12231: =cut
12232:
12233: ############################################################
12234: ############################################################
1.152 albertel 12235: my $uniq=0;
1.136 matthew 12236: sub get_cgi_id {
1.154 albertel 12237: $uniq=($uniq+1)%100000;
1.280 albertel 12238: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12239: }
12240:
1.127 matthew 12241: ############################################################
12242: ############################################################
12243:
12244: =pod
12245:
1.648 raeburn 12246: =item * &DrawBarGraph()
1.127 matthew 12247:
1.138 matthew 12248: Facilitates the plotting of data in a (stacked) bar graph.
12249: Puts plot definition data into the users environment in order for
12250: graph.png to plot it. Returns an <img> tag for the plot.
12251: The bars on the plot are labeled '1','2',...,'n'.
12252:
12253: Inputs:
12254:
12255: =over 4
12256:
12257: =item $Title: string, the title of the plot
12258:
12259: =item $xlabel: string, text describing the X-axis of the plot
12260:
12261: =item $ylabel: string, text describing the Y-axis of the plot
12262:
12263: =item $Max: scalar, the maximum Y value to use in the plot
12264: If $Max is < any data point, the graph will not be rendered.
12265:
1.140 matthew 12266: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12267: they are plotted. If undefined, default values will be used.
12268:
1.178 matthew 12269: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12270:
1.138 matthew 12271: =item @Values: An array of array references. Each array reference holds data
12272: to be plotted in a stacked bar chart.
12273:
1.239 matthew 12274: =item If the final element of @Values is a hash reference the key/value
12275: pairs will be added to the graph definition.
12276:
1.138 matthew 12277: =back
12278:
12279: Returns:
12280:
12281: An <img> tag which references graph.png and the appropriate identifying
12282: information for the plot.
12283:
1.127 matthew 12284: =cut
12285:
12286: ############################################################
12287: ############################################################
1.134 matthew 12288: sub DrawBarGraph {
1.178 matthew 12289: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12290: #
12291: if (! defined($colors)) {
12292: $colors = ['#33ff00',
12293: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12294: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12295: ];
12296: }
1.228 matthew 12297: my $extra_settings = {};
12298: if (ref($Values[-1]) eq 'HASH') {
12299: $extra_settings = pop(@Values);
12300: }
1.127 matthew 12301: #
1.136 matthew 12302: my $identifier = &get_cgi_id();
12303: my $id = 'cgi.'.$identifier;
1.129 matthew 12304: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12305: return '';
12306: }
1.225 matthew 12307: #
12308: my @Labels;
12309: if (defined($labels)) {
12310: @Labels = @$labels;
12311: } else {
12312: for (my $i=0;$i<@{$Values[0]};$i++) {
12313: push (@Labels,$i+1);
12314: }
12315: }
12316: #
1.129 matthew 12317: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12318: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12319: my %ValuesHash;
12320: my $NumSets=1;
12321: foreach my $array (@Values) {
12322: next if (! ref($array));
1.136 matthew 12323: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12324: join(',',@$array);
1.129 matthew 12325: }
1.127 matthew 12326: #
1.136 matthew 12327: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12328: if ($NumBars < 3) {
12329: $width = 120+$NumBars*32;
1.220 matthew 12330: $xskip = 1;
1.225 matthew 12331: $bar_width = 30;
12332: } elsif ($NumBars < 5) {
12333: $width = 120+$NumBars*20;
12334: $xskip = 1;
12335: $bar_width = 20;
1.220 matthew 12336: } elsif ($NumBars < 10) {
1.136 matthew 12337: $width = 120+$NumBars*15;
12338: $xskip = 1;
12339: $bar_width = 15;
12340: } elsif ($NumBars <= 25) {
12341: $width = 120+$NumBars*11;
12342: $xskip = 5;
12343: $bar_width = 8;
12344: } elsif ($NumBars <= 50) {
12345: $width = 120+$NumBars*8;
12346: $xskip = 5;
12347: $bar_width = 4;
12348: } else {
12349: $width = 120+$NumBars*8;
12350: $xskip = 5;
12351: $bar_width = 4;
12352: }
12353: #
1.137 matthew 12354: $Max = 1 if ($Max < 1);
12355: if ( int($Max) < $Max ) {
12356: $Max++;
12357: $Max = int($Max);
12358: }
1.127 matthew 12359: $Title = '' if (! defined($Title));
12360: $xlabel = '' if (! defined($xlabel));
12361: $ylabel = '' if (! defined($ylabel));
1.369 www 12362: $ValuesHash{$id.'.title'} = &escape($Title);
12363: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12364: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12365: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12366: $ValuesHash{$id.'.NumBars'} = $NumBars;
12367: $ValuesHash{$id.'.NumSets'} = $NumSets;
12368: $ValuesHash{$id.'.PlotType'} = 'bar';
12369: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12370: $ValuesHash{$id.'.height'} = $height;
12371: $ValuesHash{$id.'.width'} = $width;
12372: $ValuesHash{$id.'.xskip'} = $xskip;
12373: $ValuesHash{$id.'.bar_width'} = $bar_width;
12374: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12375: #
1.228 matthew 12376: # Deal with other parameters
12377: while (my ($key,$value) = each(%$extra_settings)) {
12378: $ValuesHash{$id.'.'.$key} = $value;
12379: }
12380: #
1.646 raeburn 12381: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12382: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12383: }
12384:
12385: ############################################################
12386: ############################################################
12387:
12388: =pod
12389:
1.648 raeburn 12390: =item * &DrawXYGraph()
1.137 matthew 12391:
1.138 matthew 12392: Facilitates the plotting of data in an XY graph.
12393: Puts plot definition data into the users environment in order for
12394: graph.png to plot it. Returns an <img> tag for the plot.
12395:
12396: Inputs:
12397:
12398: =over 4
12399:
12400: =item $Title: string, the title of the plot
12401:
12402: =item $xlabel: string, text describing the X-axis of the plot
12403:
12404: =item $ylabel: string, text describing the Y-axis of the plot
12405:
12406: =item $Max: scalar, the maximum Y value to use in the plot
12407: If $Max is < any data point, the graph will not be rendered.
12408:
12409: =item $colors: Array ref containing the hex color codes for the data to be
12410: plotted in. If undefined, default values will be used.
12411:
12412: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12413:
12414: =item $Ydata: Array ref containing Array refs.
1.185 www 12415: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12416:
12417: =item %Values: hash indicating or overriding any default values which are
12418: passed to graph.png.
12419: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12420:
12421: =back
12422:
12423: Returns:
12424:
12425: An <img> tag which references graph.png and the appropriate identifying
12426: information for the plot.
12427:
1.137 matthew 12428: =cut
12429:
12430: ############################################################
12431: ############################################################
12432: sub DrawXYGraph {
12433: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12434: #
12435: # Create the identifier for the graph
12436: my $identifier = &get_cgi_id();
12437: my $id = 'cgi.'.$identifier;
12438: #
12439: $Title = '' if (! defined($Title));
12440: $xlabel = '' if (! defined($xlabel));
12441: $ylabel = '' if (! defined($ylabel));
12442: my %ValuesHash =
12443: (
1.369 www 12444: $id.'.title' => &escape($Title),
12445: $id.'.xlabel' => &escape($xlabel),
12446: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12447: $id.'.y_max_value'=> $Max,
12448: $id.'.labels' => join(',',@$Xlabels),
12449: $id.'.PlotType' => 'XY',
12450: );
12451: #
12452: if (defined($colors) && ref($colors) eq 'ARRAY') {
12453: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12454: }
12455: #
12456: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12457: return '';
12458: }
12459: my $NumSets=1;
1.138 matthew 12460: foreach my $array (@{$Ydata}){
1.137 matthew 12461: next if (! ref($array));
12462: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12463: }
1.138 matthew 12464: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12465: #
12466: # Deal with other parameters
12467: while (my ($key,$value) = each(%Values)) {
12468: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12469: }
12470: #
1.646 raeburn 12471: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12472: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12473: }
12474:
12475: ############################################################
12476: ############################################################
12477:
12478: =pod
12479:
1.648 raeburn 12480: =item * &DrawXYYGraph()
1.138 matthew 12481:
12482: Facilitates the plotting of data in an XY graph with two Y axes.
12483: Puts plot definition data into the users environment in order for
12484: graph.png to plot it. Returns an <img> tag for the plot.
12485:
12486: Inputs:
12487:
12488: =over 4
12489:
12490: =item $Title: string, the title of the plot
12491:
12492: =item $xlabel: string, text describing the X-axis of the plot
12493:
12494: =item $ylabel: string, text describing the Y-axis of the plot
12495:
12496: =item $colors: Array ref containing the hex color codes for the data to be
12497: plotted in. If undefined, default values will be used.
12498:
12499: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12500:
12501: =item $Ydata1: The first data set
12502:
12503: =item $Min1: The minimum value of the left Y-axis
12504:
12505: =item $Max1: The maximum value of the left Y-axis
12506:
12507: =item $Ydata2: The second data set
12508:
12509: =item $Min2: The minimum value of the right Y-axis
12510:
12511: =item $Max2: The maximum value of the left Y-axis
12512:
12513: =item %Values: hash indicating or overriding any default values which are
12514: passed to graph.png.
12515: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12516:
12517: =back
12518:
12519: Returns:
12520:
12521: An <img> tag which references graph.png and the appropriate identifying
12522: information for the plot.
1.136 matthew 12523:
12524: =cut
12525:
12526: ############################################################
12527: ############################################################
1.137 matthew 12528: sub DrawXYYGraph {
12529: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12530: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12531: #
12532: # Create the identifier for the graph
12533: my $identifier = &get_cgi_id();
12534: my $id = 'cgi.'.$identifier;
12535: #
12536: $Title = '' if (! defined($Title));
12537: $xlabel = '' if (! defined($xlabel));
12538: $ylabel = '' if (! defined($ylabel));
12539: my %ValuesHash =
12540: (
1.369 www 12541: $id.'.title' => &escape($Title),
12542: $id.'.xlabel' => &escape($xlabel),
12543: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12544: $id.'.labels' => join(',',@$Xlabels),
12545: $id.'.PlotType' => 'XY',
12546: $id.'.NumSets' => 2,
1.137 matthew 12547: $id.'.two_axes' => 1,
12548: $id.'.y1_max_value' => $Max1,
12549: $id.'.y1_min_value' => $Min1,
12550: $id.'.y2_max_value' => $Max2,
12551: $id.'.y2_min_value' => $Min2,
1.136 matthew 12552: );
12553: #
1.137 matthew 12554: if (defined($colors) && ref($colors) eq 'ARRAY') {
12555: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12556: }
12557: #
12558: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12559: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12560: return '';
12561: }
12562: my $NumSets=1;
1.137 matthew 12563: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12564: next if (! ref($array));
12565: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12566: }
12567: #
12568: # Deal with other parameters
12569: while (my ($key,$value) = each(%Values)) {
12570: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12571: }
12572: #
1.646 raeburn 12573: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12574: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12575: }
12576:
12577: ############################################################
12578: ############################################################
12579:
12580: =pod
12581:
1.157 matthew 12582: =back
12583:
1.139 matthew 12584: =head1 Statistics helper routines?
12585:
12586: Bad place for them but what the hell.
12587:
1.157 matthew 12588: =over 4
12589:
1.648 raeburn 12590: =item * &chartlink()
1.139 matthew 12591:
12592: Returns a link to the chart for a specific student.
12593:
12594: Inputs:
12595:
12596: =over 4
12597:
12598: =item $linktext: The text of the link
12599:
12600: =item $sname: The students username
12601:
12602: =item $sdomain: The students domain
12603:
12604: =back
12605:
1.157 matthew 12606: =back
12607:
1.139 matthew 12608: =cut
12609:
12610: ############################################################
12611: ############################################################
12612: sub chartlink {
12613: my ($linktext, $sname, $sdomain) = @_;
12614: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12615: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12616: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12617: '">'.$linktext.'</a>';
1.153 matthew 12618: }
12619:
12620: #######################################################
12621: #######################################################
12622:
12623: =pod
12624:
12625: =head1 Course Environment Routines
1.157 matthew 12626:
12627: =over 4
1.153 matthew 12628:
1.648 raeburn 12629: =item * &restore_course_settings()
1.153 matthew 12630:
1.648 raeburn 12631: =item * &store_course_settings()
1.153 matthew 12632:
12633: Restores/Store indicated form parameters from the course environment.
12634: Will not overwrite existing values of the form parameters.
12635:
12636: Inputs:
12637: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12638:
12639: a hash ref describing the data to be stored. For example:
12640:
12641: %Save_Parameters = ('Status' => 'scalar',
12642: 'chartoutputmode' => 'scalar',
12643: 'chartoutputdata' => 'scalar',
12644: 'Section' => 'array',
1.373 raeburn 12645: 'Group' => 'array',
1.153 matthew 12646: 'StudentData' => 'array',
12647: 'Maps' => 'array');
12648:
12649: Returns: both routines return nothing
12650:
1.631 raeburn 12651: =back
12652:
1.153 matthew 12653: =cut
12654:
12655: #######################################################
12656: #######################################################
12657: sub store_course_settings {
1.496 albertel 12658: return &store_settings($env{'request.course.id'},@_);
12659: }
12660:
12661: sub store_settings {
1.153 matthew 12662: # save to the environment
12663: # appenv the same items, just to be safe
1.300 albertel 12664: my $udom = $env{'user.domain'};
12665: my $uname = $env{'user.name'};
1.496 albertel 12666: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12667: my %SaveHash;
12668: my %AppHash;
12669: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12670: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12671: my $envname = 'environment.'.$basename;
1.258 albertel 12672: if (exists($env{'form.'.$setting})) {
1.153 matthew 12673: # Save this value away
12674: if ($type eq 'scalar' &&
1.258 albertel 12675: (! exists($env{$envname}) ||
12676: $env{$envname} ne $env{'form.'.$setting})) {
12677: $SaveHash{$basename} = $env{'form.'.$setting};
12678: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 12679: } elsif ($type eq 'array') {
12680: my $stored_form;
1.258 albertel 12681: if (ref($env{'form.'.$setting})) {
1.153 matthew 12682: $stored_form = join(',',
12683: map {
1.369 www 12684: &escape($_);
1.258 albertel 12685: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 12686: } else {
12687: $stored_form =
1.369 www 12688: &escape($env{'form.'.$setting});
1.153 matthew 12689: }
12690: # Determine if the array contents are the same.
1.258 albertel 12691: if ($stored_form ne $env{$envname}) {
1.153 matthew 12692: $SaveHash{$basename} = $stored_form;
12693: $AppHash{$envname} = $stored_form;
12694: }
12695: }
12696: }
12697: }
12698: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 12699: $udom,$uname);
1.153 matthew 12700: if ($put_result !~ /^(ok|delayed)/) {
12701: &Apache::lonnet::logthis('unable to save form parameters, '.
12702: 'got error:'.$put_result);
12703: }
12704: # Make sure these settings stick around in this session, too
1.646 raeburn 12705: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 12706: return;
12707: }
12708:
12709: sub restore_course_settings {
1.499 albertel 12710: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 12711: }
12712:
12713: sub restore_settings {
12714: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12715: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 12716: next if (exists($env{'form.'.$setting}));
1.496 albertel 12717: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 12718: '.'.$setting;
1.258 albertel 12719: if (exists($env{$envname})) {
1.153 matthew 12720: if ($type eq 'scalar') {
1.258 albertel 12721: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 12722: } elsif ($type eq 'array') {
1.258 albertel 12723: $env{'form.'.$setting} = [
1.153 matthew 12724: map {
1.369 www 12725: &unescape($_);
1.258 albertel 12726: } split(',',$env{$envname})
1.153 matthew 12727: ];
12728: }
12729: }
12730: }
1.127 matthew 12731: }
12732:
1.618 raeburn 12733: #######################################################
12734: #######################################################
12735:
12736: =pod
12737:
12738: =head1 Domain E-mail Routines
12739:
12740: =over 4
12741:
1.648 raeburn 12742: =item * &build_recipient_list()
1.618 raeburn 12743:
1.884 raeburn 12744: Build recipient lists for five types of e-mail:
1.766 raeburn 12745: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 12746: (d) Help requests, (e) Course requests needing approval, generated by
12747: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
12748: loncoursequeueadmin.pm respectively.
1.618 raeburn 12749:
12750: Inputs:
1.619 raeburn 12751: defmail (scalar - email address of default recipient),
1.618 raeburn 12752: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 12753: defdom (domain for which to retrieve configuration settings),
12754: origmail (scalar - email address of recipient from loncapa.conf,
12755: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 12756:
1.655 raeburn 12757: Returns: comma separated list of addresses to which to send e-mail.
12758:
12759: =back
1.618 raeburn 12760:
12761: =cut
12762:
12763: ############################################################
12764: ############################################################
12765: sub build_recipient_list {
1.619 raeburn 12766: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 12767: my @recipients;
12768: my $otheremails;
12769: my %domconfig =
12770: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
12771: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 12772: if (exists($domconfig{'contacts'}{$mailing})) {
12773: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
12774: my @contacts = ('adminemail','supportemail');
12775: foreach my $item (@contacts) {
12776: if ($domconfig{'contacts'}{$mailing}{$item}) {
12777: my $addr = $domconfig{'contacts'}{$item};
12778: if (!grep(/^\Q$addr\E$/,@recipients)) {
12779: push(@recipients,$addr);
12780: }
1.619 raeburn 12781: }
1.766 raeburn 12782: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 12783: }
12784: }
1.766 raeburn 12785: } elsif ($origmail ne '') {
12786: push(@recipients,$origmail);
1.618 raeburn 12787: }
1.619 raeburn 12788: } elsif ($origmail ne '') {
12789: push(@recipients,$origmail);
1.618 raeburn 12790: }
1.688 raeburn 12791: if (defined($defmail)) {
12792: if ($defmail ne '') {
12793: push(@recipients,$defmail);
12794: }
1.618 raeburn 12795: }
12796: if ($otheremails) {
1.619 raeburn 12797: my @others;
12798: if ($otheremails =~ /,/) {
12799: @others = split(/,/,$otheremails);
1.618 raeburn 12800: } else {
1.619 raeburn 12801: push(@others,$otheremails);
12802: }
12803: foreach my $addr (@others) {
12804: if (!grep(/^\Q$addr\E$/,@recipients)) {
12805: push(@recipients,$addr);
12806: }
1.618 raeburn 12807: }
12808: }
1.619 raeburn 12809: my $recipientlist = join(',',@recipients);
1.618 raeburn 12810: return $recipientlist;
12811: }
12812:
1.127 matthew 12813: ############################################################
12814: ############################################################
1.154 albertel 12815:
1.655 raeburn 12816: =pod
12817:
12818: =head1 Course Catalog Routines
12819:
12820: =over 4
12821:
12822: =item * &gather_categories()
12823:
12824: Converts category definitions - keys of categories hash stored in
12825: coursecategories in configuration.db on the primary library server in a
12826: domain - to an array. Also generates javascript and idx hash used to
12827: generate Domain Coordinator interface for editing Course Categories.
12828:
12829: Inputs:
1.663 raeburn 12830:
1.655 raeburn 12831: categories (reference to hash of category definitions).
1.663 raeburn 12832:
1.655 raeburn 12833: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12834: categories and subcategories).
1.663 raeburn 12835:
1.655 raeburn 12836: idx (reference to hash of counters used in Domain Coordinator interface for
12837: editing Course Categories).
1.663 raeburn 12838:
1.655 raeburn 12839: jsarray (reference to array of categories used to create Javascript arrays for
12840: Domain Coordinator interface for editing Course Categories).
12841:
12842: Returns: nothing
12843:
12844: Side effects: populates cats, idx and jsarray.
12845:
12846: =cut
12847:
12848: sub gather_categories {
12849: my ($categories,$cats,$idx,$jsarray) = @_;
12850: my %counters;
12851: my $num = 0;
12852: foreach my $item (keys(%{$categories})) {
12853: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12854: if ($container eq '' && $depth == 0) {
12855: $cats->[$depth][$categories->{$item}] = $cat;
12856: } else {
12857: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
12858: }
12859: my ($escitem,$tail) = split(/:/,$item,2);
12860: if ($counters{$tail} eq '') {
12861: $counters{$tail} = $num;
12862: $num ++;
12863: }
12864: if (ref($idx) eq 'HASH') {
12865: $idx->{$item} = $counters{$tail};
12866: }
12867: if (ref($jsarray) eq 'ARRAY') {
12868: push(@{$jsarray->[$counters{$tail}]},$item);
12869: }
12870: }
12871: return;
12872: }
12873:
12874: =pod
12875:
12876: =item * &extract_categories()
12877:
12878: Used to generate breadcrumb trails for course categories.
12879:
12880: Inputs:
1.663 raeburn 12881:
1.655 raeburn 12882: categories (reference to hash of category definitions).
1.663 raeburn 12883:
1.655 raeburn 12884: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12885: categories and subcategories).
1.663 raeburn 12886:
1.655 raeburn 12887: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 12888:
1.655 raeburn 12889: allitems (reference to hash - key is category key
12890: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12891:
1.655 raeburn 12892: idx (reference to hash of counters used in Domain Coordinator interface for
12893: editing Course Categories).
1.663 raeburn 12894:
1.655 raeburn 12895: jsarray (reference to array of categories used to create Javascript arrays for
12896: Domain Coordinator interface for editing Course Categories).
12897:
1.665 raeburn 12898: subcats (reference to hash of arrays containing all subcategories within each
12899: category, -recursive)
12900:
1.655 raeburn 12901: Returns: nothing
12902:
12903: Side effects: populates trails and allitems hash references.
12904:
12905: =cut
12906:
12907: sub extract_categories {
1.665 raeburn 12908: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 12909: if (ref($categories) eq 'HASH') {
12910: &gather_categories($categories,$cats,$idx,$jsarray);
12911: if (ref($cats->[0]) eq 'ARRAY') {
12912: for (my $i=0; $i<@{$cats->[0]}; $i++) {
12913: my $name = $cats->[0][$i];
12914: my $item = &escape($name).'::0';
12915: my $trailstr;
12916: if ($name eq 'instcode') {
12917: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 12918: } elsif ($name eq 'communities') {
12919: $trailstr = &mt('Communities');
1.655 raeburn 12920: } else {
12921: $trailstr = $name;
12922: }
12923: if ($allitems->{$item} eq '') {
12924: push(@{$trails},$trailstr);
12925: $allitems->{$item} = scalar(@{$trails})-1;
12926: }
12927: my @parents = ($name);
12928: if (ref($cats->[1]{$name}) eq 'ARRAY') {
12929: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
12930: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 12931: if (ref($subcats) eq 'HASH') {
12932: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
12933: }
12934: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
12935: }
12936: } else {
12937: if (ref($subcats) eq 'HASH') {
12938: $subcats->{$item} = [];
1.655 raeburn 12939: }
12940: }
12941: }
12942: }
12943: }
12944: return;
12945: }
12946:
12947: =pod
12948:
12949: =item *&recurse_categories()
12950:
12951: Recursively used to generate breadcrumb trails for course categories.
12952:
12953: Inputs:
1.663 raeburn 12954:
1.655 raeburn 12955: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12956: categories and subcategories).
1.663 raeburn 12957:
1.655 raeburn 12958: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 12959:
12960: category (current course category, for which breadcrumb trail is being generated).
12961:
12962: trails (reference to array of breadcrumb trails for each category).
12963:
1.655 raeburn 12964: allitems (reference to hash - key is category key
12965: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12966:
1.655 raeburn 12967: parents (array containing containers directories for current category,
12968: back to top level).
12969:
12970: Returns: nothing
12971:
12972: Side effects: populates trails and allitems hash references
12973:
12974: =cut
12975:
12976: sub recurse_categories {
1.665 raeburn 12977: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 12978: my $shallower = $depth - 1;
12979: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
12980: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
12981: my $name = $cats->[$depth]{$category}[$k];
12982: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
12983: my $trailstr = join(' -> ',(@{$parents},$category));
12984: if ($allitems->{$item} eq '') {
12985: push(@{$trails},$trailstr);
12986: $allitems->{$item} = scalar(@{$trails})-1;
12987: }
12988: my $deeper = $depth+1;
12989: push(@{$parents},$category);
1.665 raeburn 12990: if (ref($subcats) eq 'HASH') {
12991: my $subcat = &escape($name).':'.$category.':'.$depth;
12992: for (my $j=@{$parents}; $j>=0; $j--) {
12993: my $higher;
12994: if ($j > 0) {
12995: $higher = &escape($parents->[$j]).':'.
12996: &escape($parents->[$j-1]).':'.$j;
12997: } else {
12998: $higher = &escape($parents->[$j]).'::'.$j;
12999: }
13000: push(@{$subcats->{$higher}},$subcat);
13001: }
13002: }
13003: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13004: $subcats);
1.655 raeburn 13005: pop(@{$parents});
13006: }
13007: } else {
13008: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13009: my $trailstr = join(' -> ',(@{$parents},$category));
13010: if ($allitems->{$item} eq '') {
13011: push(@{$trails},$trailstr);
13012: $allitems->{$item} = scalar(@{$trails})-1;
13013: }
13014: }
13015: return;
13016: }
13017:
1.663 raeburn 13018: =pod
13019:
13020: =item *&assign_categories_table()
13021:
13022: Create a datatable for display of hierarchical categories in a domain,
13023: with checkboxes to allow a course to be categorized.
13024:
13025: Inputs:
13026:
13027: cathash - reference to hash of categories defined for the domain (from
13028: configuration.db)
13029:
13030: currcat - scalar with an & separated list of categories assigned to a course.
13031:
1.919 raeburn 13032: type - scalar contains course type (Course or Community).
13033:
1.663 raeburn 13034: Returns: $output (markup to be displayed)
13035:
13036: =cut
13037:
13038: sub assign_categories_table {
1.919 raeburn 13039: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13040: my $output;
13041: if (ref($cathash) eq 'HASH') {
13042: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13043: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13044: $maxdepth = scalar(@cats);
13045: if (@cats > 0) {
13046: my $itemcount = 0;
13047: if (ref($cats[0]) eq 'ARRAY') {
13048: my @currcategories;
13049: if ($currcat ne '') {
13050: @currcategories = split('&',$currcat);
13051: }
1.919 raeburn 13052: my $table;
1.663 raeburn 13053: for (my $i=0; $i<@{$cats[0]}; $i++) {
13054: my $parent = $cats[0][$i];
1.919 raeburn 13055: next if ($parent eq 'instcode');
13056: if ($type eq 'Community') {
13057: next unless ($parent eq 'communities');
13058: } else {
13059: next if ($parent eq 'communities');
13060: }
1.663 raeburn 13061: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13062: my $item = &escape($parent).'::0';
13063: my $checked = '';
13064: if (@currcategories > 0) {
13065: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13066: $checked = ' checked="checked"';
1.663 raeburn 13067: }
13068: }
1.919 raeburn 13069: my $parent_title = $parent;
13070: if ($parent eq 'communities') {
13071: $parent_title = &mt('Communities');
13072: }
13073: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13074: '<input type="checkbox" name="usecategory" value="'.
13075: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13076: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13077: my $depth = 1;
13078: push(@path,$parent);
1.919 raeburn 13079: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13080: pop(@path);
1.919 raeburn 13081: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13082: $itemcount ++;
13083: }
1.919 raeburn 13084: if ($itemcount) {
13085: $output = &Apache::loncommon::start_data_table().
13086: $table.
13087: &Apache::loncommon::end_data_table();
13088: }
1.663 raeburn 13089: }
13090: }
13091: }
13092: return $output;
13093: }
13094:
13095: =pod
13096:
13097: =item *&assign_category_rows()
13098:
13099: Create a datatable row for display of nested categories in a domain,
13100: with checkboxes to allow a course to be categorized,called recursively.
13101:
13102: Inputs:
13103:
13104: itemcount - track row number for alternating colors
13105:
13106: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13107: categories and subcategories.
13108:
13109: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13110:
13111: parent - parent of current category item
13112:
13113: path - Array containing all categories back up through the hierarchy from the
13114: current category to the top level.
13115:
13116: currcategories - reference to array of current categories assigned to the course
13117:
13118: Returns: $output (markup to be displayed).
13119:
13120: =cut
13121:
13122: sub assign_category_rows {
13123: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13124: my ($text,$name,$item,$chgstr);
13125: if (ref($cats) eq 'ARRAY') {
13126: my $maxdepth = scalar(@{$cats});
13127: if (ref($cats->[$depth]) eq 'HASH') {
13128: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13129: my $numchildren = @{$cats->[$depth]{$parent}};
13130: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13131: $text .= '<td><table class="LC_datatable">';
13132: for (my $j=0; $j<$numchildren; $j++) {
13133: $name = $cats->[$depth]{$parent}[$j];
13134: $item = &escape($name).':'.&escape($parent).':'.$depth;
13135: my $deeper = $depth+1;
13136: my $checked = '';
13137: if (ref($currcategories) eq 'ARRAY') {
13138: if (@{$currcategories} > 0) {
13139: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13140: $checked = ' checked="checked"';
1.663 raeburn 13141: }
13142: }
13143: }
1.664 raeburn 13144: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13145: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13146: $item.'"'.$checked.' />'.$name.'</label></span>'.
13147: '<input type="hidden" name="catname" value="'.$name.'" />'.
13148: '</td><td>';
1.663 raeburn 13149: if (ref($path) eq 'ARRAY') {
13150: push(@{$path},$name);
13151: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13152: pop(@{$path});
13153: }
13154: $text .= '</td></tr>';
13155: }
13156: $text .= '</table></td>';
13157: }
13158: }
13159: }
13160: return $text;
13161: }
13162:
1.655 raeburn 13163: ############################################################
13164: ############################################################
13165:
13166:
1.443 albertel 13167: sub commit_customrole {
1.664 raeburn 13168: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13169: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13170: ($start?', '.&mt('starting').' '.localtime($start):'').
13171: ($end?', ending '.localtime($end):'').': <b>'.
13172: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13173: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13174: '</b><br />';
13175: return $output;
13176: }
13177:
13178: sub commit_standardrole {
1.541 raeburn 13179: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
13180: my ($output,$logmsg,$linefeed);
13181: if ($context eq 'auto') {
13182: $linefeed = "\n";
13183: } else {
13184: $linefeed = "<br />\n";
13185: }
1.443 albertel 13186: if ($three eq 'st') {
1.541 raeburn 13187: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
13188: $one,$two,$sec,$context);
13189: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13190: ($result eq 'unknown_course') || ($result eq 'refused')) {
13191: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13192: } else {
1.541 raeburn 13193: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13194: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13195: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13196: if ($context eq 'auto') {
13197: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13198: } else {
13199: $output .= '<b>'.$result.'</b>'.$linefeed.
13200: &mt('Add to classlist').': <b>ok</b>';
13201: }
13202: $output .= $linefeed;
1.443 albertel 13203: }
13204: } else {
13205: $output = &mt('Assigning').' '.$three.' in '.$url.
13206: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13207: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13208: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13209: if ($context eq 'auto') {
13210: $output .= $result.$linefeed;
13211: } else {
13212: $output .= '<b>'.$result.'</b>'.$linefeed;
13213: }
1.443 albertel 13214: }
13215: return $output;
13216: }
13217:
13218: sub commit_studentrole {
1.541 raeburn 13219: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 13220: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13221: if ($context eq 'auto') {
13222: $linefeed = "\n";
13223: } else {
13224: $linefeed = '<br />'."\n";
13225: }
1.443 albertel 13226: if (defined($one) && defined($two)) {
13227: my $cid=$one.'_'.$two;
13228: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13229: my $secchange = 0;
13230: my $expire_role_result;
13231: my $modify_section_result;
1.628 raeburn 13232: if ($oldsec ne '-1') {
13233: if ($oldsec ne $sec) {
1.443 albertel 13234: $secchange = 1;
1.628 raeburn 13235: my $now = time;
1.443 albertel 13236: my $uurl='/'.$cid;
13237: $uurl=~s/\_/\//g;
13238: if ($oldsec) {
13239: $uurl.='/'.$oldsec;
13240: }
1.626 raeburn 13241: $oldsecurl = $uurl;
1.628 raeburn 13242: $expire_role_result =
1.652 raeburn 13243: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13244: if ($env{'request.course.sec'} ne '') {
13245: if ($expire_role_result eq 'refused') {
13246: my @roles = ('st');
13247: my @statuses = ('previous');
13248: my @roledoms = ($one);
13249: my $withsec = 1;
13250: my %roleshash =
13251: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13252: \@statuses,\@roles,\@roledoms,$withsec);
13253: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13254: my ($oldstart,$oldend) =
13255: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13256: if ($oldend > 0 && $oldend <= $now) {
13257: $expire_role_result = 'ok';
13258: }
13259: }
13260: }
13261: }
1.443 albertel 13262: $result = $expire_role_result;
13263: }
13264: }
13265: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 13266: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 13267: if ($modify_section_result =~ /^ok/) {
13268: if ($secchange == 1) {
1.628 raeburn 13269: if ($sec eq '') {
13270: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13271: } else {
13272: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13273: }
1.443 albertel 13274: } elsif ($oldsec eq '-1') {
1.628 raeburn 13275: if ($sec eq '') {
13276: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13277: } else {
13278: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13279: }
1.443 albertel 13280: } else {
1.628 raeburn 13281: if ($sec eq '') {
13282: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13283: } else {
13284: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13285: }
1.443 albertel 13286: }
13287: } else {
1.628 raeburn 13288: if ($secchange) {
13289: $$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;
13290: } else {
13291: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13292: }
1.443 albertel 13293: }
13294: $result = $modify_section_result;
13295: } elsif ($secchange == 1) {
1.628 raeburn 13296: if ($oldsec eq '') {
1.1103 raeburn 13297: $$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 13298: } else {
13299: $$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;
13300: }
1.626 raeburn 13301: if ($expire_role_result eq 'refused') {
13302: my $newsecurl = '/'.$cid;
13303: $newsecurl =~ s/\_/\//g;
13304: if ($sec ne '') {
13305: $newsecurl.='/'.$sec;
13306: }
13307: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13308: if ($sec eq '') {
13309: $$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;
13310: } else {
13311: $$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;
13312: }
13313: }
13314: }
1.443 albertel 13315: }
13316: } else {
1.626 raeburn 13317: $$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 13318: $result = "error: incomplete course id\n";
13319: }
13320: return $result;
13321: }
13322:
1.1108 raeburn 13323: sub show_role_extent {
13324: my ($scope,$context,$role) = @_;
13325: $scope =~ s{^/}{};
13326: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13327: push(@courseroles,'co');
13328: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13329: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13330: $scope =~ s{/}{_};
13331: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13332: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13333: my ($audom,$auname) = split(/\//,$scope);
13334: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13335: &Apache::loncommon::plainname($auname,$audom).'</span>');
13336: } else {
13337: $scope =~ s{/$}{};
13338: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13339: &Apache::lonnet::domain($scope,'description').'</span>');
13340: }
13341: }
13342:
1.443 albertel 13343: ############################################################
13344: ############################################################
13345:
1.566 albertel 13346: sub check_clone {
1.578 raeburn 13347: my ($args,$linefeed) = @_;
1.566 albertel 13348: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13349: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13350: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13351: my $clonemsg;
13352: my $can_clone = 0;
1.944 raeburn 13353: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13354: if ($lctype ne 'community') {
13355: $lctype = 'course';
13356: }
1.566 albertel 13357: if ($clonehome eq 'no_host') {
1.944 raeburn 13358: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13359: $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'});
13360: } else {
13361: $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'});
13362: }
1.566 albertel 13363: } else {
13364: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13365: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13366: if ($clonedesc{'type'} ne 'Community') {
13367: $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'});
13368: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13369: }
13370: }
1.882 raeburn 13371: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13372: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13373: $can_clone = 1;
13374: } else {
13375: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13376: $args->{'clonedomain'},$args->{'clonecourse'});
13377: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13378: if (grep(/^\*$/,@cloners)) {
13379: $can_clone = 1;
13380: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13381: $can_clone = 1;
13382: } else {
1.908 raeburn 13383: my $ccrole = 'cc';
1.944 raeburn 13384: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13385: $ccrole = 'co';
13386: }
1.578 raeburn 13387: my %roleshash =
13388: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13389: $args->{'ccdomain'},
1.908 raeburn 13390: 'userroles',['active'],[$ccrole],
1.578 raeburn 13391: [$args->{'clonedomain'}]);
1.908 raeburn 13392: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13393: $can_clone = 1;
13394: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13395: $can_clone = 1;
13396: } else {
1.944 raeburn 13397: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13398: $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'});
13399: } else {
13400: $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'});
13401: }
1.578 raeburn 13402: }
1.566 albertel 13403: }
1.578 raeburn 13404: }
1.566 albertel 13405: }
13406: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13407: }
13408:
1.444 albertel 13409: sub construct_course {
1.885 raeburn 13410: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13411: my $outcome;
1.541 raeburn 13412: my $linefeed = '<br />'."\n";
13413: if ($context eq 'auto') {
13414: $linefeed = "\n";
13415: }
1.566 albertel 13416:
13417: #
13418: # Are we cloning?
13419: #
13420: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13421: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13422: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13423: if ($context ne 'auto') {
1.578 raeburn 13424: if ($clonemsg ne '') {
13425: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13426: }
1.566 albertel 13427: }
13428: $outcome .= $clonemsg.$linefeed;
13429:
13430: if (!$can_clone) {
13431: return (0,$outcome);
13432: }
13433: }
13434:
1.444 albertel 13435: #
13436: # Open course
13437: #
13438: my $crstype = lc($args->{'crstype'});
13439: my %cenv=();
13440: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13441: $args->{'cdescr'},
13442: $args->{'curl'},
13443: $args->{'course_home'},
13444: $args->{'nonstandard'},
13445: $args->{'crscode'},
13446: $args->{'ccuname'}.':'.
13447: $args->{'ccdomain'},
1.882 raeburn 13448: $args->{'crstype'},
1.885 raeburn 13449: $cnum,$context,$category);
1.444 albertel 13450:
13451: # Note: The testing routines depend on this being output; see
13452: # Utils::Course. This needs to at least be output as a comment
13453: # if anyone ever decides to not show this, and Utils::Course::new
13454: # will need to be suitably modified.
1.541 raeburn 13455: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13456: if ($$courseid =~ /^error:/) {
13457: return (0,$outcome);
13458: }
13459:
1.444 albertel 13460: #
13461: # Check if created correctly
13462: #
1.479 albertel 13463: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13464: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13465: if ($crsuhome eq 'no_host') {
13466: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13467: return (0,$outcome);
13468: }
1.541 raeburn 13469: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13470:
1.444 albertel 13471: #
1.566 albertel 13472: # Do the cloning
13473: #
13474: if ($can_clone && $cloneid) {
13475: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13476: if ($context ne 'auto') {
13477: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13478: }
13479: $outcome .= $clonemsg.$linefeed;
13480: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13481: # Copy all files
1.637 www 13482: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13483: # Restore URL
1.566 albertel 13484: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13485: # Restore title
1.566 albertel 13486: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13487: # Restore creation date, creator and creation context.
13488: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13489: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13490: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13491: # Mark as cloned
1.566 albertel 13492: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13493: # Need to clone grading mode
13494: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13495: $cenv{'grading'}=$newenv{'grading'};
13496: # Do not clone these environment entries
13497: &Apache::lonnet::del('environment',
13498: ['default_enrollment_start_date',
13499: 'default_enrollment_end_date',
13500: 'question.email',
13501: 'policy.email',
13502: 'comment.email',
13503: 'pch.users.denied',
1.725 raeburn 13504: 'plc.users.denied',
13505: 'hidefromcat',
13506: 'categories'],
1.638 www 13507: $$crsudom,$$crsunum);
1.444 albertel 13508: }
1.566 albertel 13509:
1.444 albertel 13510: #
13511: # Set environment (will override cloned, if existing)
13512: #
13513: my @sections = ();
13514: my @xlists = ();
13515: if ($args->{'crstype'}) {
13516: $cenv{'type'}=$args->{'crstype'};
13517: }
13518: if ($args->{'crsid'}) {
13519: $cenv{'courseid'}=$args->{'crsid'};
13520: }
13521: if ($args->{'crscode'}) {
13522: $cenv{'internal.coursecode'}=$args->{'crscode'};
13523: }
13524: if ($args->{'crsquota'} ne '') {
13525: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13526: } else {
13527: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13528: }
13529: if ($args->{'ccuname'}) {
13530: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13531: ':'.$args->{'ccdomain'};
13532: } else {
13533: $cenv{'internal.courseowner'} = $args->{'curruser'};
13534: }
13535: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13536: if ($args->{'crssections'}) {
13537: $cenv{'internal.sectionnums'} = '';
13538: if ($args->{'crssections'} =~ m/,/) {
13539: @sections = split/,/,$args->{'crssections'};
13540: } else {
13541: $sections[0] = $args->{'crssections'};
13542: }
13543: if (@sections > 0) {
13544: foreach my $item (@sections) {
13545: my ($sec,$gp) = split/:/,$item;
13546: my $class = $args->{'crscode'}.$sec;
13547: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13548: $cenv{'internal.sectionnums'} .= $item.',';
13549: unless ($addcheck eq 'ok') {
13550: push @badclasses, $class;
13551: }
13552: }
13553: $cenv{'internal.sectionnums'} =~ s/,$//;
13554: }
13555: }
13556: # do not hide course coordinator from staff listing,
13557: # even if privileged
13558: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13559: # add crosslistings
13560: if ($args->{'crsxlist'}) {
13561: $cenv{'internal.crosslistings'}='';
13562: if ($args->{'crsxlist'} =~ m/,/) {
13563: @xlists = split/,/,$args->{'crsxlist'};
13564: } else {
13565: $xlists[0] = $args->{'crsxlist'};
13566: }
13567: if (@xlists > 0) {
13568: foreach my $item (@xlists) {
13569: my ($xl,$gp) = split/:/,$item;
13570: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13571: $cenv{'internal.crosslistings'} .= $item.',';
13572: unless ($addcheck eq 'ok') {
13573: push @badclasses, $xl;
13574: }
13575: }
13576: $cenv{'internal.crosslistings'} =~ s/,$//;
13577: }
13578: }
13579: if ($args->{'autoadds'}) {
13580: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13581: }
13582: if ($args->{'autodrops'}) {
13583: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13584: }
13585: # check for notification of enrollment changes
13586: my @notified = ();
13587: if ($args->{'notify_owner'}) {
13588: if ($args->{'ccuname'} ne '') {
13589: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13590: }
13591: }
13592: if ($args->{'notify_dc'}) {
13593: if ($uname ne '') {
1.630 raeburn 13594: push(@notified,$uname.':'.$udom);
1.444 albertel 13595: }
13596: }
13597: if (@notified > 0) {
13598: my $notifylist;
13599: if (@notified > 1) {
13600: $notifylist = join(',',@notified);
13601: } else {
13602: $notifylist = $notified[0];
13603: }
13604: $cenv{'internal.notifylist'} = $notifylist;
13605: }
13606: if (@badclasses > 0) {
13607: my %lt=&Apache::lonlocal::texthash(
13608: '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',
13609: 'dnhr' => 'does not have rights to access enrollment in these classes',
13610: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13611: );
1.541 raeburn 13612: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13613: ' ('.$lt{'adby'}.')';
13614: if ($context eq 'auto') {
13615: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13616: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13617: foreach my $item (@badclasses) {
13618: if ($context eq 'auto') {
13619: $outcome .= " - $item\n";
13620: } else {
13621: $outcome .= "<li>$item</li>\n";
13622: }
13623: }
13624: if ($context eq 'auto') {
13625: $outcome .= $linefeed;
13626: } else {
1.566 albertel 13627: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13628: }
13629: }
1.444 albertel 13630: }
13631: if ($args->{'no_end_date'}) {
13632: $args->{'endaccess'} = 0;
13633: }
13634: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13635: $cenv{'internal.autoend'}=$args->{'enrollend'};
13636: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13637: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13638: if ($args->{'showphotos'}) {
13639: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13640: }
13641: $cenv{'internal.authtype'} = $args->{'authtype'};
13642: $cenv{'internal.autharg'} = $args->{'autharg'};
13643: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13644: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13645: 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');
13646: if ($context eq 'auto') {
13647: $outcome .= $krb_msg;
13648: } else {
1.566 albertel 13649: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13650: }
13651: $outcome .= $linefeed;
1.444 albertel 13652: }
13653: }
13654: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13655: if ($args->{'setpolicy'}) {
13656: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13657: }
13658: if ($args->{'setcontent'}) {
13659: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13660: }
13661: }
13662: if ($args->{'reshome'}) {
13663: $cenv{'reshome'}=$args->{'reshome'}.'/';
13664: $cenv{'reshome'}=~s/\/+$/\//;
13665: }
13666: #
13667: # course has keyed access
13668: #
13669: if ($args->{'setkeys'}) {
13670: $cenv{'keyaccess'}='yes';
13671: }
13672: # if specified, key authority is not course, but user
13673: # only active if keyaccess is yes
13674: if ($args->{'keyauth'}) {
1.487 albertel 13675: my ($user,$domain) = split(':',$args->{'keyauth'});
13676: $user = &LONCAPA::clean_username($user);
13677: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 13678: if ($user ne '' && $domain ne '') {
1.487 albertel 13679: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 13680: }
13681: }
13682:
13683: if ($args->{'disresdis'}) {
13684: $cenv{'pch.roles.denied'}='st';
13685: }
13686: if ($args->{'disablechat'}) {
13687: $cenv{'plc.roles.denied'}='st';
13688: }
13689:
13690: # Record we've not yet viewed the Course Initialization Helper for this
13691: # course
13692: $cenv{'course.helper.not.run'} = 1;
13693: #
13694: # Use new Randomseed
13695: #
13696: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
13697: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
13698: #
13699: # The encryption code and receipt prefix for this course
13700: #
13701: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
13702: $cenv{'internal.encpref'}=100+int(9*rand(99));
13703: #
13704: # By default, use standard grading
13705: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
13706:
1.541 raeburn 13707: $outcome .= $linefeed.&mt('Setting environment').': '.
13708: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13709: #
13710: # Open all assignments
13711: #
13712: if ($args->{'openall'}) {
13713: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
13714: my %storecontent = ($storeunder => time,
13715: $storeunder.'.type' => 'date_start');
13716:
13717: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 13718: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13719: }
13720: #
13721: # Set first page
13722: #
13723: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
13724: || ($cloneid)) {
1.445 albertel 13725: use LONCAPA::map;
1.444 albertel 13726: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 13727:
13728: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
13729: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
13730:
1.444 albertel 13731: $outcome .= ($fatal?$errtext:'read ok').' - ';
13732: my $title; my $url;
13733: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 13734: $title=&mt('Syllabus');
1.444 albertel 13735: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
13736: } else {
1.963 raeburn 13737: $title=&mt('Table of Contents');
1.444 albertel 13738: $url='/adm/navmaps';
13739: }
1.445 albertel 13740:
13741: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
13742: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
13743:
13744: if ($errtext) { $fatal=2; }
1.541 raeburn 13745: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 13746: }
1.566 albertel 13747:
13748: return (1,$outcome);
1.444 albertel 13749: }
13750:
13751: ############################################################
13752: ############################################################
13753:
1.953 droeschl 13754: #SD
13755: # only Community and Course, or anything else?
1.378 raeburn 13756: sub course_type {
13757: my ($cid) = @_;
13758: if (!defined($cid)) {
13759: $cid = $env{'request.course.id'};
13760: }
1.404 albertel 13761: if (defined($env{'course.'.$cid.'.type'})) {
13762: return $env{'course.'.$cid.'.type'};
1.378 raeburn 13763: } else {
13764: return 'Course';
1.377 raeburn 13765: }
13766: }
1.156 albertel 13767:
1.406 raeburn 13768: sub group_term {
13769: my $crstype = &course_type();
13770: my %names = (
13771: 'Course' => 'group',
1.865 raeburn 13772: 'Community' => 'group',
1.406 raeburn 13773: );
13774: return $names{$crstype};
13775: }
13776:
1.902 raeburn 13777: sub course_types {
13778: my @types = ('official','unofficial','community');
13779: my %typename = (
13780: official => 'Official course',
13781: unofficial => 'Unofficial course',
13782: community => 'Community',
13783: );
13784: return (\@types,\%typename);
13785: }
13786:
1.156 albertel 13787: sub icon {
13788: my ($file)=@_;
1.505 albertel 13789: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 13790: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 13791: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 13792: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
13793: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
13794: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13795: $curfext.".gif") {
13796: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13797: $curfext.".gif";
13798: }
13799: }
1.249 albertel 13800: return &lonhttpdurl($iconname);
1.154 albertel 13801: }
1.84 albertel 13802:
1.575 albertel 13803: sub lonhttpdurl {
1.692 www 13804: #
13805: # Had been used for "small fry" static images on separate port 8080.
13806: # Modify here if lightweight http functionality desired again.
13807: # Currently eliminated due to increasing firewall issues.
13808: #
1.575 albertel 13809: my ($url)=@_;
1.692 www 13810: return $url;
1.215 albertel 13811: }
13812:
1.213 albertel 13813: sub connection_aborted {
13814: my ($r)=@_;
13815: $r->print(" ");$r->rflush();
13816: my $c = $r->connection;
13817: return $c->aborted();
13818: }
13819:
1.221 foxr 13820: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 13821: # strings as 'strings'.
13822: sub escape_single {
1.221 foxr 13823: my ($input) = @_;
1.223 albertel 13824: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 13825: $input =~ s/\'/\\\'/g; # Esacpe the 's....
13826: return $input;
13827: }
1.223 albertel 13828:
1.222 foxr 13829: # Same as escape_single, but escape's "'s This
13830: # can be used for "strings"
13831: sub escape_double {
13832: my ($input) = @_;
13833: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
13834: $input =~ s/\"/\\\"/g; # Esacpe the "s....
13835: return $input;
13836: }
1.223 albertel 13837:
1.222 foxr 13838: # Escapes the last element of a full URL.
13839: sub escape_url {
13840: my ($url) = @_;
1.238 raeburn 13841: my @urlslices = split(/\//, $url,-1);
1.369 www 13842: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 13843: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 13844: }
1.462 albertel 13845:
1.820 raeburn 13846: sub compare_arrays {
13847: my ($arrayref1,$arrayref2) = @_;
13848: my (@difference,%count);
13849: @difference = ();
13850: %count = ();
13851: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
13852: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
13853: foreach my $element (keys(%count)) {
13854: if ($count{$element} == 1) {
13855: push(@difference,$element);
13856: }
13857: }
13858: }
13859: return @difference;
13860: }
13861:
1.817 bisitz 13862: # -------------------------------------------------------- Initialize user login
1.462 albertel 13863: sub init_user_environment {
1.463 albertel 13864: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 13865: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
13866:
13867: my $public=($username eq 'public' && $domain eq 'public');
13868:
13869: # See if old ID present, if so, remove
13870:
1.1062 raeburn 13871: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 13872: my $now=time;
13873:
13874: if ($public) {
13875: my $max_public=100;
13876: my $oldest;
13877: my $oldest_time=0;
13878: for(my $next=1;$next<=$max_public;$next++) {
13879: if (-e $lonids."/publicuser_$next.id") {
13880: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
13881: if ($mtime<$oldest_time || !$oldest_time) {
13882: $oldest_time=$mtime;
13883: $oldest=$next;
13884: }
13885: } else {
13886: $cookie="publicuser_$next";
13887: last;
13888: }
13889: }
13890: if (!$cookie) { $cookie="publicuser_$oldest"; }
13891: } else {
1.463 albertel 13892: # if this isn't a robot, kill any existing non-robot sessions
13893: if (!$args->{'robot'}) {
13894: opendir(DIR,$lonids);
13895: while ($filename=readdir(DIR)) {
13896: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
13897: unlink($lonids.'/'.$filename);
13898: }
1.462 albertel 13899: }
1.463 albertel 13900: closedir(DIR);
1.462 albertel 13901: }
13902: # Give them a new cookie
1.463 albertel 13903: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 13904: : $now.$$.int(rand(10000)));
1.463 albertel 13905: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 13906:
13907: # Initialize roles
13908:
1.1062 raeburn 13909: ($userroles,$firstaccenv,$timerintenv) =
13910: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 13911: }
13912: # ------------------------------------ Check browser type and MathML capability
13913:
13914: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
13915: $clientunicode,$clientos) = &decode_user_agent($r);
13916:
13917: # ------------------------------------------------------------- Get environment
13918:
13919: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
13920: my ($tmp) = keys(%userenv);
13921: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
13922: } else {
13923: undef(%userenv);
13924: }
13925: if (($userenv{'interface'}) && (!$form->{'interface'})) {
13926: $form->{'interface'}=$userenv{'interface'};
13927: }
13928: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
13929:
13930: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 13931: foreach my $option ('interface','localpath','localres') {
13932: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 13933: }
13934: # --------------------------------------------------------- Write first profile
13935:
13936: {
13937: my %initial_env =
13938: ("user.name" => $username,
13939: "user.domain" => $domain,
13940: "user.home" => $authhost,
13941: "browser.type" => $clientbrowser,
13942: "browser.version" => $clientversion,
13943: "browser.mathml" => $clientmathml,
13944: "browser.unicode" => $clientunicode,
13945: "browser.os" => $clientos,
13946: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
13947: "request.course.fn" => '',
13948: "request.course.uri" => '',
13949: "request.course.sec" => '',
13950: "request.role" => 'cm',
13951: "request.role.adv" => $env{'user.adv'},
13952: "request.host" => $ENV{'REMOTE_ADDR'},);
13953:
13954: if ($form->{'localpath'}) {
13955: $initial_env{"browser.localpath"} = $form->{'localpath'};
13956: $initial_env{"browser.localres"} = $form->{'localres'};
13957: }
13958:
13959: if ($form->{'interface'}) {
13960: $form->{'interface'}=~s/\W//gs;
13961: $initial_env{"browser.interface"} = $form->{'interface'};
13962: $env{'browser.interface'}=$form->{'interface'};
13963: }
13964:
1.981 raeburn 13965: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 13966: my %domdef;
13967: unless ($domain eq 'public') {
13968: %domdef = &Apache::lonnet::get_domain_defaults($domain);
13969: }
1.980 raeburn 13970:
1.1081 raeburn 13971: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 13972: $userenv{'availabletools.'.$tool} =
1.980 raeburn 13973: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
13974: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 13975: }
13976:
1.864 raeburn 13977: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 13978: $userenv{'canrequest.'.$crstype} =
13979: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 13980: 'reload','requestcourses',
13981: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 13982: }
13983:
1.1092 raeburn 13984: $userenv{'canrequest.author'} =
13985: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
13986: 'reload','requestauthor',
13987: \%userenv,\%domdef,\%is_adv);
13988: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
13989: $domain,$username);
13990: my $reqstatus = $reqauthor{'author_status'};
13991: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
13992: if (ref($reqauthor{'author'}) eq 'HASH') {
13993: $userenv{'requestauthorqueued'} = $reqstatus.':'.
13994: $reqauthor{'author'}{'timestamp'};
13995: }
13996: }
13997:
1.462 albertel 13998: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 13999:
1.462 albertel 14000: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14001: &GDBM_WRCREAT(),0640)) {
14002: &_add_to_env(\%disk_env,\%initial_env);
14003: &_add_to_env(\%disk_env,\%userenv,'environment.');
14004: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14005: if (ref($firstaccenv) eq 'HASH') {
14006: &_add_to_env(\%disk_env,$firstaccenv);
14007: }
14008: if (ref($timerintenv) eq 'HASH') {
14009: &_add_to_env(\%disk_env,$timerintenv);
14010: }
1.463 albertel 14011: if (ref($args->{'extra_env'})) {
14012: &_add_to_env(\%disk_env,$args->{'extra_env'});
14013: }
1.462 albertel 14014: untie(%disk_env);
14015: } else {
1.705 tempelho 14016: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14017: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14018: return 'error: '.$!;
14019: }
14020: }
14021: $env{'request.role'}='cm';
14022: $env{'request.role.adv'}=$env{'user.adv'};
14023: $env{'browser.type'}=$clientbrowser;
14024:
14025: return $cookie;
14026:
14027: }
14028:
14029: sub _add_to_env {
14030: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14031: if (ref($env_data) eq 'HASH') {
14032: while (my ($key,$value) = each(%$env_data)) {
14033: $idf->{$prefix.$key} = $value;
14034: $env{$prefix.$key} = $value;
14035: }
1.462 albertel 14036: }
14037: }
14038:
1.685 tempelho 14039: # --- Get the symbolic name of a problem and the url
14040: sub get_symb {
14041: my ($request,$silent) = @_;
1.726 raeburn 14042: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14043: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14044: if ($symb eq '') {
14045: if (!$silent) {
1.1071 raeburn 14046: if (ref($request)) {
14047: $request->print("Unable to handle ambiguous references:$url:.");
14048: }
1.685 tempelho 14049: return ();
14050: }
14051: }
14052: &Apache::lonenc::check_decrypt(\$symb);
14053: return ($symb);
14054: }
14055:
14056: # --------------------------------------------------------------Get annotation
14057:
14058: sub get_annotation {
14059: my ($symb,$enc) = @_;
14060:
14061: my $key = $symb;
14062: if (!$enc) {
14063: $key =
14064: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14065: }
14066: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14067: return $annotation{$key};
14068: }
14069:
14070: sub clean_symb {
1.731 raeburn 14071: my ($symb,$delete_enc) = @_;
1.685 tempelho 14072:
14073: &Apache::lonenc::check_decrypt(\$symb);
14074: my $enc = $env{'request.enc'};
1.731 raeburn 14075: if ($delete_enc) {
1.730 raeburn 14076: delete($env{'request.enc'});
14077: }
1.685 tempelho 14078:
14079: return ($symb,$enc);
14080: }
1.462 albertel 14081:
1.990 raeburn 14082: sub build_release_hashes {
14083: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14084: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14085: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14086: (ref($randomizetry) eq 'HASH'));
14087: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14088: my ($item,$name,$value) = split(/:/,$key);
14089: if ($item eq 'parameter') {
14090: if (ref($checkparms->{$name}) eq 'ARRAY') {
14091: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14092: push(@{$checkparms->{$name}},$value);
14093: }
14094: } else {
14095: push(@{$checkparms->{$name}},$value);
14096: }
14097: } elsif ($item eq 'resourcetag') {
14098: if ($name eq 'responsetype') {
14099: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14100: }
14101: } elsif ($item eq 'course') {
14102: if ($name eq 'crstype') {
14103: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14104: }
14105: }
14106: }
14107: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14108: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14109: return;
14110: }
14111:
1.1083 raeburn 14112: sub update_content_constraints {
14113: my ($cdom,$cnum,$chome,$cid) = @_;
14114: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14115: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14116: my %checkresponsetypes;
14117: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14118: my ($item,$name,$value) = split(/:/,$key);
14119: if ($item eq 'resourcetag') {
14120: if ($name eq 'responsetype') {
14121: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14122: }
14123: }
14124: }
14125: my $navmap = Apache::lonnavmaps::navmap->new();
14126: if (defined($navmap)) {
14127: my %allresponses;
14128: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14129: my %responses = $res->responseTypes();
14130: foreach my $key (keys(%responses)) {
14131: next unless(exists($checkresponsetypes{$key}));
14132: $allresponses{$key} += $responses{$key};
14133: }
14134: }
14135: foreach my $key (keys(%allresponses)) {
14136: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14137: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14138: ($reqdmajor,$reqdminor) = ($major,$minor);
14139: }
14140: }
14141: undef($navmap);
14142: }
14143: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14144: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14145: }
14146: return;
14147: }
14148:
1.1110 raeburn 14149: sub allmaps_incourse {
14150: my ($cdom,$cnum,$chome,$cid) = @_;
14151: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14152: $cid = $env{'request.course.id'};
14153: $cdom = $env{'course.'.$cid.'.domain'};
14154: $cnum = $env{'course.'.$cid.'.num'};
14155: $chome = $env{'course.'.$cid.'.home'};
14156: }
14157: my %allmaps = ();
14158: my $lastchange =
14159: &Apache::lonnet::get_coursechange($cdom,$cnum);
14160: if ($lastchange > $env{'request.course.tied'}) {
14161: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14162: unless ($ferr) {
14163: &update_content_constraints($cdom,$cnum,$chome,$cid);
14164: }
14165: }
14166: my $navmap = Apache::lonnavmaps::navmap->new();
14167: if (defined($navmap)) {
14168: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14169: $allmaps{$res->src()} = 1;
14170: }
14171: }
14172: return \%allmaps;
14173: }
14174:
1.1083 raeburn 14175: sub parse_supplemental_title {
14176: my ($title) = @_;
14177:
14178: my ($foldertitle,$renametitle);
14179: if ($title =~ /&&&/) {
14180: $title = &HTML::Entites::decode($title);
14181: }
14182: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14183: $renametitle=$4;
14184: my ($time,$uname,$udom) = ($1,$2,$3);
14185: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14186: my $name = &plainname($uname,$udom);
14187: $name = &HTML::Entities::encode($name,'"<>&\'');
14188: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14189: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14190: $name.': <br />'.$foldertitle;
14191: }
14192: if (wantarray) {
14193: return ($title,$foldertitle,$renametitle);
14194: }
14195: return $title;
14196: }
14197:
1.1101 raeburn 14198: sub symb_to_docspath {
14199: my ($symb) = @_;
14200: return unless ($symb);
14201: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14202: if ($resurl=~/\.(sequence|page)$/) {
14203: $mapurl=$resurl;
14204: } elsif ($resurl eq 'adm/navmaps') {
14205: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14206: }
14207: my $mapresobj;
14208: my $navmap = Apache::lonnavmaps::navmap->new();
14209: if (ref($navmap)) {
14210: $mapresobj = $navmap->getResourceByUrl($mapurl);
14211: }
14212: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14213: my $type=$2;
14214: my $path;
14215: if (ref($mapresobj)) {
14216: my $pcslist = $mapresobj->map_hierarchy();
14217: if ($pcslist ne '') {
14218: foreach my $pc (split(/,/,$pcslist)) {
14219: next if ($pc <= 1);
14220: my $res = $navmap->getByMapPc($pc);
14221: if (ref($res)) {
14222: my $thisurl = $res->src();
14223: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14224: my $thistitle = $res->title();
14225: $path .= '&'.
14226: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14227: &Apache::lonhtmlcommon::entity_encode($thistitle).
14228: ':'.$res->randompick().
14229: ':'.$res->randomout().
14230: ':'.$res->encrypted().
14231: ':'.$res->randomorder().
14232: ':'.$res->is_page();
14233: }
14234: }
14235: }
14236: $path =~ s/^\&//;
14237: my $maptitle = $mapresobj->title();
14238: if ($mapurl eq 'default') {
14239: $maptitle = 'Main Course Documents';
14240: }
14241: $path .= (($path ne '')? '&' : '').
14242: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14243: &Apache::lonhtmlcommon::entity_encode($maptitle).
14244: ':'.$mapresobj->randompick().
14245: ':'.$mapresobj->randomout().
14246: ':'.$mapresobj->encrypted().
14247: ':'.$mapresobj->randomorder().
14248: ':'.$mapresobj->is_page();
14249: } else {
14250: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14251: my $ispage = (($type eq 'page')? 1 : '');
14252: if ($mapurl eq 'default') {
14253: $maptitle = 'Main Course Documents';
14254: }
14255: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14256: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14257: }
14258: unless ($mapurl eq 'default') {
14259: $path = 'default&'.
14260: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
14261: ':::::&'.$path;
14262: }
14263: return $path;
14264: }
14265:
1.1094 raeburn 14266: sub captcha_display {
14267: my ($context,$lonhost) = @_;
14268: my ($output,$error);
14269: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14270: if ($captcha eq 'original') {
1.1094 raeburn 14271: $output = &create_captcha();
14272: unless ($output) {
14273: $error = 'captcha';
14274: }
14275: } elsif ($captcha eq 'recaptcha') {
14276: $output = &create_recaptcha($pubkey);
14277: unless ($output) {
1.1095 raeburn 14278: $error = 'recaptcha';
1.1094 raeburn 14279: }
14280: }
14281: return ($output,$error);
14282: }
14283:
14284: sub captcha_response {
14285: my ($context,$lonhost) = @_;
14286: my ($captcha_chk,$captcha_error);
14287: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14288: if ($captcha eq 'original') {
1.1094 raeburn 14289: ($captcha_chk,$captcha_error) = &check_captcha();
14290: } elsif ($captcha eq 'recaptcha') {
14291: $captcha_chk = &check_recaptcha($privkey);
14292: } else {
14293: $captcha_chk = 1;
14294: }
14295: return ($captcha_chk,$captcha_error);
14296: }
14297:
14298: sub get_captcha_config {
14299: my ($context,$lonhost) = @_;
1.1095 raeburn 14300: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14301: my $hostname = &Apache::lonnet::hostname($lonhost);
14302: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14303: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14304: if ($context eq 'usercreation') {
14305: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14306: if (ref($domconfig{$context}) eq 'HASH') {
14307: $hashtocheck = $domconfig{$context}{'cancreate'};
14308: if (ref($hashtocheck) eq 'HASH') {
14309: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14310: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14311: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14312: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14313: }
14314: if ($privkey && $pubkey) {
14315: $captcha = 'recaptcha';
14316: } else {
14317: $captcha = 'original';
14318: }
14319: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14320: $captcha = 'original';
14321: }
1.1094 raeburn 14322: }
1.1095 raeburn 14323: } else {
14324: $captcha = 'captcha';
14325: }
14326: } elsif ($context eq 'login') {
14327: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14328: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14329: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14330: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14331: if ($privkey && $pubkey) {
14332: $captcha = 'recaptcha';
1.1095 raeburn 14333: } else {
14334: $captcha = 'original';
1.1094 raeburn 14335: }
1.1095 raeburn 14336: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14337: $captcha = 'original';
1.1094 raeburn 14338: }
14339: }
14340: return ($captcha,$pubkey,$privkey);
14341: }
14342:
14343: sub create_captcha {
14344: my %captcha_params = &captcha_settings();
14345: my ($output,$maxtries,$tries) = ('',10,0);
14346: while ($tries < $maxtries) {
14347: $tries ++;
14348: my $captcha = Authen::Captcha->new (
14349: output_folder => $captcha_params{'output_dir'},
14350: data_folder => $captcha_params{'db_dir'},
14351: );
14352: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14353:
14354: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14355: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14356: &mt('Type in the letters/numbers shown below').' '.
14357: '<input type="text" size="5" name="code" value="" /><br />'.
14358: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14359: last;
14360: }
14361: }
14362: return $output;
14363: }
14364:
14365: sub captcha_settings {
14366: my %captcha_params = (
14367: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14368: www_output_dir => "/captchaspool",
14369: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14370: numchars => '5',
14371: );
14372: return %captcha_params;
14373: }
14374:
14375: sub check_captcha {
14376: my ($captcha_chk,$captcha_error);
14377: my $code = $env{'form.code'};
14378: my $md5sum = $env{'form.crypt'};
14379: my %captcha_params = &captcha_settings();
14380: my $captcha = Authen::Captcha->new(
14381: output_folder => $captcha_params{'output_dir'},
14382: data_folder => $captcha_params{'db_dir'},
14383: );
1.1109 raeburn 14384: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14385: my %captcha_hash = (
14386: 0 => 'Code not checked (file error)',
14387: -1 => 'Failed: code expired',
14388: -2 => 'Failed: invalid code (not in database)',
14389: -3 => 'Failed: invalid code (code does not match crypt)',
14390: );
14391: if ($captcha_chk != 1) {
14392: $captcha_error = $captcha_hash{$captcha_chk}
14393: }
14394: return ($captcha_chk,$captcha_error);
14395: }
14396:
14397: sub create_recaptcha {
14398: my ($pubkey) = @_;
14399: my $captcha = Captcha::reCAPTCHA->new;
14400: return $captcha->get_options_setter({theme => 'white'})."\n".
14401: $captcha->get_html($pubkey).
14402: &mt('If either word is hard to read, [_1] will replace them.',
14403: '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
14404: '<br /><br />';
14405: }
14406:
14407: sub check_recaptcha {
14408: my ($privkey) = @_;
14409: my $captcha_chk;
14410: my $captcha = Captcha::reCAPTCHA->new;
14411: my $captcha_result =
14412: $captcha->check_answer(
14413: $privkey,
14414: $ENV{'REMOTE_ADDR'},
14415: $env{'form.recaptcha_challenge_field'},
14416: $env{'form.recaptcha_response_field'},
14417: );
14418: if ($captcha_result->{is_valid}) {
14419: $captcha_chk = 1;
14420: }
14421: return $captcha_chk;
14422: }
14423:
1.41 ng 14424: =pod
14425:
14426: =back
14427:
1.112 bowersj2 14428: =cut
1.41 ng 14429:
1.112 bowersj2 14430: 1;
14431: __END__;
1.41 ng 14432:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>