Annotation of loncom/interface/loncommon.pm, revision 1.1119
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1119 ! raeburn 4: # $Id: loncommon.pm,v 1.1118 2013/03/20 01:26:15 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1091 foxr 75: use Text::Aspell;
1.1094 raeburn 76: use Authen::Captcha;
77: use Captcha::reCAPTCHA;
1.117 www 78:
1.517 raeburn 79: # ---------------------------------------------- Designs
80: use vars qw(%defaultdesign);
81:
1.22 www 82: my $readit;
83:
1.517 raeburn 84:
1.157 matthew 85: ##
86: ## Global Variables
87: ##
1.46 matthew 88:
1.643 foxr 89:
90: # ----------------------------------------------- SSI with retries:
91: #
92:
93: =pod
94:
1.648 raeburn 95: =head1 Server Side include with retries:
1.643 foxr 96:
97: =over 4
98:
1.648 raeburn 99: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 100:
101: Performs an ssi with some number of retries. Retries continue either
102: until the result is ok or until the retry count supplied by the
103: caller is exhausted.
104:
105: Inputs:
1.648 raeburn 106:
107: =over 4
108:
1.643 foxr 109: resource - Identifies the resource to insert.
1.648 raeburn 110:
1.643 foxr 111: retries - Count of the number of retries allowed.
1.648 raeburn 112:
1.643 foxr 113: form - Hash that identifies the rendering options.
114:
1.648 raeburn 115: =back
116:
117: Returns:
118:
119: =over 4
120:
1.643 foxr 121: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 122:
1.643 foxr 123: response - The response from the last attempt (which may or may not have been successful.
124:
1.648 raeburn 125: =back
126:
127: =back
128:
1.643 foxr 129: =cut
130:
131: sub ssi_with_retries {
132: my ($resource, $retries, %form) = @_;
133:
134:
135: my $ok = 0; # True if we got a good response.
136: my $content;
137: my $response;
138:
139: # Try to get the ssi done. within the retries count:
140:
141: do {
142: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
143: $ok = $response->is_success;
1.650 www 144: if (!$ok) {
145: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
146: }
1.643 foxr 147: $retries--;
148: } while (!$ok && ($retries > 0));
149:
150: if (!$ok) {
151: $content = ''; # On error return an empty content.
152: }
153: return ($content, $response);
154:
155: }
156:
157:
158:
1.20 www 159: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 160: my %language;
1.124 www 161: my %supported_language;
1.1088 foxr 162: my %supported_codes;
1.1048 foxr 163: my %latex_language; # For choosing hyphenation in <transl..>
164: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 165: my %cprtag;
1.192 taceyjo1 166: my %scprtag;
1.351 www 167: my %fe; my %fd; my %fm;
1.41 ng 168: my %category_extensions;
1.12 harris41 169:
1.46 matthew 170: # ---------------------------------------------- Thesaurus variables
1.144 matthew 171: #
172: # %Keywords:
173: # A hash used by &keyword to determine if a word is considered a keyword.
174: # $thesaurus_db_file
175: # Scalar containing the full path to the thesaurus database.
1.46 matthew 176:
177: my %Keywords;
178: my $thesaurus_db_file;
179:
1.144 matthew 180: #
181: # Initialize values from language.tab, copyright.tab, filetypes.tab,
182: # thesaurus.tab, and filecategories.tab.
183: #
1.18 www 184: BEGIN {
1.46 matthew 185: # Variable initialization
186: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
187: #
1.22 www 188: unless ($readit) {
1.12 harris41 189: # ------------------------------------------------------------------- languages
190: {
1.158 raeburn 191: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
192: '/language.tab';
193: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 194: while (my $line = <$fh>) {
195: next if ($line=~/^\#/);
196: chomp($line);
1.1088 foxr 197: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 198: $language{$key}=$val.' - '.$enc;
199: if ($sup) {
200: $supported_language{$key}=$sup;
1.1088 foxr 201: $supported_codes{$key} = $code;
1.158 raeburn 202: }
1.1048 foxr 203: if ($latex) {
204: $latex_language_bykey{$key} = $latex;
1.1088 foxr 205: $latex_language{$code} = $latex;
1.1048 foxr 206: }
1.158 raeburn 207: }
208: close($fh);
209: }
1.12 harris41 210: }
211: # ------------------------------------------------------------------ copyrights
212: {
1.158 raeburn 213: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
214: '/copyright.tab';
215: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 216: while (my $line = <$fh>) {
217: next if ($line=~/^\#/);
218: chomp($line);
219: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 220: $cprtag{$key}=$val;
221: }
222: close($fh);
223: }
1.12 harris41 224: }
1.351 www 225: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 226: {
227: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/source_copyright.tab';
229: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line =~ /^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 234: $scprtag{$key}=$val;
235: }
236: close($fh);
237: }
238: }
1.63 www 239:
1.517 raeburn 240: # -------------------------------------------------------------- default domain designs
1.63 www 241: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 242: my $designfile = $designdir.'/default.tab';
243: if ( open (my $fh,"<$designfile") ) {
244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\=/,$line));
248: if ($val) { $defaultdesign{$key}=$val; }
249: }
250: close($fh);
1.63 www 251: }
252:
1.15 harris41 253: # ------------------------------------------------------------- file categories
254: {
1.158 raeburn 255: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
256: '/filecategories.tab';
257: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 262: push @{$category_extensions{lc($category)}},$extension;
263: }
264: close($fh);
265: }
266:
1.15 harris41 267: }
1.12 harris41 268: # ------------------------------------------------------------------ file types
269: {
1.158 raeburn 270: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filetypes.tab';
272: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 277: if ($descr ne '') {
278: $fe{$ending}=lc($emb);
279: $fd{$ending}=$descr;
1.351 www 280: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 281: }
282: }
283: close($fh);
284: }
1.12 harris41 285: }
1.22 www 286: &Apache::lonnet::logthis(
1.705 tempelho 287: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 288: $readit=1;
1.46 matthew 289: } # end of unless($readit)
1.32 matthew 290:
291: }
1.112 bowersj2 292:
1.42 matthew 293: ###############################################################
294: ## HTML and Javascript Helper Functions ##
295: ###############################################################
296:
297: =pod
298:
1.112 bowersj2 299: =head1 HTML and Javascript Functions
1.42 matthew 300:
1.112 bowersj2 301: =over 4
302:
1.648 raeburn 303: =item * &browser_and_searcher_javascript()
1.112 bowersj2 304:
305: X<browsing, javascript>X<searching, javascript>Returns a string
306: containing javascript with two functions, C<openbrowser> and
307: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
308: tags.
1.42 matthew 309:
1.648 raeburn 310: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 311:
312: inputs: formname, elementname, only, omit
313:
314: formname and elementname indicate the name of the html form and name of
315: the element that the results of the browsing selection are to be placed in.
316:
317: Specifying 'only' will restrict the browser to displaying only files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
320: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
1.648 raeburn 323: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 324:
325: Inputs: formname, elementname
326:
327: formname and elementname specify the name of the html form and the name
328: of the element the selection from the search results will be placed in.
1.542 raeburn 329:
1.42 matthew 330: =cut
331:
332: sub browser_and_searcher_javascript {
1.199 albertel 333: my ($mode)=@_;
334: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 335: my $resurl=&escape_single(&lastresurl());
1.42 matthew 336: return <<END;
1.219 albertel 337: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 338: var editbrowser = null;
1.135 albertel 339: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 340: var url = '$resurl/?';
1.42 matthew 341: if (editbrowser == null) {
342: url += 'launch=1&';
343: }
344: url += 'catalogmode=interactive&';
1.199 albertel 345: url += 'mode=$mode&';
1.611 albertel 346: url += 'inhibitmenu=yes&';
1.42 matthew 347: url += 'form=' + formname + '&';
348: if (only != null) {
349: url += 'only=' + only + '&';
1.217 albertel 350: } else {
351: url += 'only=&';
352: }
1.42 matthew 353: if (omit != null) {
354: url += 'omit=' + omit + '&';
1.217 albertel 355: } else {
356: url += 'omit=&';
357: }
1.135 albertel 358: if (titleelement != null) {
359: url += 'titleelement=' + titleelement + '&';
1.217 albertel 360: } else {
361: url += 'titleelement=&';
362: }
1.42 matthew 363: url += 'element=' + elementname + '';
364: var title = 'Browser';
1.435 albertel 365: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 366: options += ',width=700,height=600';
367: editbrowser = open(url,title,options,'1');
368: editbrowser.focus();
369: }
370: var editsearcher;
1.135 albertel 371: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 372: var url = '/adm/searchcat?';
373: if (editsearcher == null) {
374: url += 'launch=1&';
375: }
376: url += 'catalogmode=interactive&';
1.199 albertel 377: url += 'mode=$mode&';
1.42 matthew 378: url += 'form=' + formname + '&';
1.135 albertel 379: if (titleelement != null) {
380: url += 'titleelement=' + titleelement + '&';
1.217 albertel 381: } else {
382: url += 'titleelement=&';
383: }
1.42 matthew 384: url += 'element=' + elementname + '';
385: var title = 'Search';
1.435 albertel 386: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 387: options += ',width=700,height=600';
388: editsearcher = open(url,title,options,'1');
389: editsearcher.focus();
390: }
1.219 albertel 391: // END LON-CAPA Internal -->
1.42 matthew 392: END
1.170 www 393: }
394:
395: sub lastresurl {
1.258 albertel 396: if ($env{'environment.lastresurl'}) {
397: return $env{'environment.lastresurl'}
1.170 www 398: } else {
399: return '/res';
400: }
401: }
402:
403: sub storeresurl {
404: my $resurl=&Apache::lonnet::clutter(shift);
405: unless ($resurl=~/^\/res/) { return 0; }
406: $resurl=~s/\/$//;
407: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 408: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 409: return 1;
1.42 matthew 410: }
411:
1.74 www 412: sub studentbrowser_javascript {
1.111 www 413: unless (
1.258 albertel 414: (($env{'request.course.id'}) &&
1.302 albertel 415: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
416: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
417: '/'.$env{'request.course.sec'})
418: ))
1.258 albertel 419: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 420: ) { return ''; }
1.74 www 421: return (<<'ENDSTDBRW');
1.776 bisitz 422: <script type="text/javascript" language="Javascript">
1.824 bisitz 423: // <![CDATA[
1.74 www 424: var stdeditbrowser;
1.999 www 425: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 426: var url = '/adm/pickstudent?';
427: var filter;
1.558 albertel 428: if (!ignorefilter) {
429: eval('filter=document.'+formname+'.'+uname+'.value;');
430: }
1.74 www 431: if (filter != null) {
432: if (filter != '') {
433: url += 'filter='+filter+'&';
434: }
435: }
436: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 437: '&udomelement='+udom+
438: '&clicker='+clicker;
1.111 www 439: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 440: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 441: var title = 'Student_Browser';
1.74 www 442: var options = 'scrollbars=1,resizable=1,menubar=0';
443: options += ',width=700,height=600';
444: stdeditbrowser = open(url,title,options,'1');
445: stdeditbrowser.focus();
446: }
1.824 bisitz 447: // ]]>
1.74 www 448: </script>
449: ENDSTDBRW
450: }
1.42 matthew 451:
1.1003 www 452: sub resourcebrowser_javascript {
453: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 454: return (<<'ENDRESBRW');
1.1003 www 455: <script type="text/javascript" language="Javascript">
456: // <![CDATA[
457: var reseditbrowser;
1.1004 www 458: function openresbrowser(formname,reslink) {
1.1005 www 459: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 460: var title = 'Resource_Browser';
461: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 462: options += ',width=700,height=500';
1.1004 www 463: reseditbrowser = open(url,title,options,'1');
464: reseditbrowser.focus();
1.1003 www 465: }
466: // ]]>
467: </script>
1.1004 www 468: ENDRESBRW
1.1003 www 469: }
470:
1.74 www 471: sub selectstudent_link {
1.999 www 472: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
473: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
474: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
475: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 476: if ($env{'request.course.id'}) {
1.302 albertel 477: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
478: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
479: '/'.$env{'request.course.sec'})) {
1.111 www 480: return '';
481: }
1.999 www 482: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 483: if ($courseadvonly) {
484: $callargs .= ",'',1,1";
485: }
486: return '<span class="LC_nobreak">'.
487: '<a href="javascript:openstdbrowser('.$callargs.');">'.
488: &mt('Select User').'</a></span>';
1.74 www 489: }
1.258 albertel 490: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 491: $callargs .= ",'',1";
1.793 raeburn 492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.111 www 495: }
496: return '';
1.91 www 497: }
498:
1.1004 www 499: sub selectresource_link {
500: my ($form,$reslink,$arg)=@_;
501:
502: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
503: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
504: unless ($env{'request.course.id'}) { return $arg; }
505: return '<span class="LC_nobreak">'.
506: '<a href="javascript:openresbrowser('.$callargs.');">'.
507: $arg.'</a></span>';
508: }
509:
510:
511:
1.653 raeburn 512: sub authorbrowser_javascript {
513: return <<"ENDAUTHORBRW";
1.776 bisitz 514: <script type="text/javascript" language="JavaScript">
1.824 bisitz 515: // <![CDATA[
1.653 raeburn 516: var stdeditbrowser;
517:
518: function openauthorbrowser(formname,udom) {
519: var url = '/adm/pickauthor?';
520: url += 'form='+formname+'&roledom='+udom;
521: var title = 'Author_Browser';
522: var options = 'scrollbars=1,resizable=1,menubar=0';
523: options += ',width=700,height=600';
524: stdeditbrowser = open(url,title,options,'1');
525: stdeditbrowser.focus();
526: }
527:
1.824 bisitz 528: // ]]>
1.653 raeburn 529: </script>
530: ENDAUTHORBRW
531: }
532:
1.91 www 533: sub coursebrowser_javascript {
1.1116 raeburn 534: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
535: $credits_element) = @_;
1.932 raeburn 536: my $wintitle = 'Course_Browser';
1.931 raeburn 537: if ($crstype eq 'Community') {
1.932 raeburn 538: $wintitle = 'Community_Browser';
1.909 raeburn 539: }
1.876 raeburn 540: my $id_functions = &javascript_index_functions();
541: my $output = '
1.776 bisitz 542: <script type="text/javascript" language="JavaScript">
1.824 bisitz 543: // <![CDATA[
1.468 raeburn 544: var stdeditbrowser;'."\n";
1.876 raeburn 545:
546: $output .= <<"ENDSTDBRW";
1.909 raeburn 547: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 548: var url = '/adm/pickcourse?';
1.895 raeburn 549: var formid = getFormIdByName(formname);
1.876 raeburn 550: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 551: if (domainfilter != null) {
552: if (domainfilter != '') {
553: url += 'domainfilter='+domainfilter+'&';
554: }
555: }
1.91 www 556: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 557: '&cdomelement='+udom+
558: '&cnameelement='+desc;
1.468 raeburn 559: if (extra_element !=null && extra_element != '') {
1.594 raeburn 560: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 561: url += '&roleelement='+extra_element;
562: if (domainfilter == null || domainfilter == '') {
563: url += '&domainfilter='+extra_element;
564: }
1.234 raeburn 565: }
1.468 raeburn 566: else {
567: if (formname == 'portform') {
568: url += '&setroles='+extra_element;
1.800 raeburn 569: } else {
570: if (formname == 'rules') {
571: url += '&fixeddom='+extra_element;
572: }
1.468 raeburn 573: }
574: }
1.230 raeburn 575: }
1.909 raeburn 576: if (type != null && type != '') {
577: url += '&type='+type;
578: }
579: if (type_elem != null && type_elem != '') {
580: url += '&typeelement='+type_elem;
581: }
1.872 raeburn 582: if (formname == 'ccrs') {
583: var ownername = document.forms[formid].ccuname.value;
584: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
585: url += '&cloner='+ownername+':'+ownerdom;
586: }
1.293 raeburn 587: if (multflag !=null && multflag != '') {
588: url += '&multiple='+multflag;
589: }
1.909 raeburn 590: var title = '$wintitle';
1.91 www 591: var options = 'scrollbars=1,resizable=1,menubar=0';
592: options += ',width=700,height=600';
593: stdeditbrowser = open(url,title,options,'1');
594: stdeditbrowser.focus();
595: }
1.876 raeburn 596: $id_functions
597: ENDSTDBRW
1.1116 raeburn 598: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
599: $output .= &setsec_javascript($sec_element,$formname,$role_element,
600: $credits_element);
1.876 raeburn 601: }
602: $output .= '
603: // ]]>
604: </script>';
605: return $output;
606: }
607:
608: sub javascript_index_functions {
609: return <<"ENDJS";
610:
611: function getFormIdByName(formname) {
612: for (var i=0;i<document.forms.length;i++) {
613: if (document.forms[i].name == formname) {
614: return i;
615: }
616: }
617: return -1;
618: }
619:
620: function getIndexByName(formid,item) {
621: for (var i=0;i<document.forms[formid].elements.length;i++) {
622: if (document.forms[formid].elements[i].name == item) {
623: return i;
624: }
625: }
626: return -1;
627: }
1.468 raeburn 628:
1.876 raeburn 629: function getDomainFromSelectbox(formname,udom) {
630: var userdom;
631: var formid = getFormIdByName(formname);
632: if (formid > -1) {
633: var domid = getIndexByName(formid,udom);
634: if (domid > -1) {
635: if (document.forms[formid].elements[domid].type == 'select-one') {
636: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
637: }
638: if (document.forms[formid].elements[domid].type == 'hidden') {
639: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 640: }
641: }
642: }
1.876 raeburn 643: return userdom;
644: }
645:
646: ENDJS
1.468 raeburn 647:
1.876 raeburn 648: }
649:
1.1017 raeburn 650: sub javascript_array_indexof {
1.1018 raeburn 651: return <<ENDJS;
1.1017 raeburn 652: <script type="text/javascript" language="JavaScript">
653: // <![CDATA[
654:
655: if (!Array.prototype.indexOf) {
656: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
657: "use strict";
658: if (this === void 0 || this === null) {
659: throw new TypeError();
660: }
661: var t = Object(this);
662: var len = t.length >>> 0;
663: if (len === 0) {
664: return -1;
665: }
666: var n = 0;
667: if (arguments.length > 0) {
668: n = Number(arguments[1]);
1.1088 foxr 669: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 670: n = 0;
671: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
672: n = (n > 0 || -1) * Math.floor(Math.abs(n));
673: }
674: }
675: if (n >= len) {
676: return -1;
677: }
678: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
679: for (; k < len; k++) {
680: if (k in t && t[k] === searchElement) {
681: return k;
682: }
683: }
684: return -1;
685: }
686: }
687:
688: // ]]>
689: </script>
690:
691: ENDJS
692:
693: }
694:
1.876 raeburn 695: sub userbrowser_javascript {
696: my $id_functions = &javascript_index_functions();
697: return <<"ENDUSERBRW";
698:
1.888 raeburn 699: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 700: var url = '/adm/pickuser?';
701: var userdom = getDomainFromSelectbox(formname,udom);
702: if (userdom != null) {
703: if (userdom != '') {
704: url += 'srchdom='+userdom+'&';
705: }
706: }
707: url += 'form=' + formname + '&unameelement='+uname+
708: '&udomelement='+udom+
709: '&ulastelement='+ulast+
710: '&ufirstelement='+ufirst+
711: '&uemailelement='+uemail+
1.881 raeburn 712: '&hideudomelement='+hideudom+
713: '&coursedom='+crsdom;
1.888 raeburn 714: if ((caller != null) && (caller != undefined)) {
715: url += '&caller='+caller;
716: }
1.876 raeburn 717: var title = 'User_Browser';
718: var options = 'scrollbars=1,resizable=1,menubar=0';
719: options += ',width=700,height=600';
720: var stdeditbrowser = open(url,title,options,'1');
721: stdeditbrowser.focus();
722: }
723:
1.888 raeburn 724: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 725: var formid = getFormIdByName(formname);
726: if (formid > -1) {
1.888 raeburn 727: var unameid = getIndexByName(formid,uname);
1.876 raeburn 728: var domid = getIndexByName(formid,udom);
729: var hidedomid = getIndexByName(formid,origdom);
730: if (hidedomid > -1) {
731: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 732: var unameval = document.forms[formid].elements[unameid].value;
733: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
734: if (domid > -1) {
735: var slct = document.forms[formid].elements[domid];
736: if (slct.type == 'select-one') {
737: var i;
738: for (i=0;i<slct.length;i++) {
739: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
740: }
741: }
742: if (slct.type == 'hidden') {
743: slct.value = fixeddom;
1.876 raeburn 744: }
745: }
1.468 raeburn 746: }
747: }
748: }
1.876 raeburn 749: return;
750: }
751:
752: $id_functions
753: ENDUSERBRW
1.468 raeburn 754: }
755:
756: sub setsec_javascript {
1.1116 raeburn 757: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 758: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
759: $communityrolestr);
760: if ($role_element ne '') {
761: my @allroles = ('st','ta','ep','in','ad');
762: foreach my $crstype ('Course','Community') {
763: if ($crstype eq 'Community') {
764: foreach my $role (@allroles) {
765: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
766: }
767: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
768: } else {
769: foreach my $role (@allroles) {
770: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
771: }
772: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
773: }
774: }
775: $rolestr = '"'.join('","',@allroles).'"';
776: $courserolestr = '"'.join('","',@courserolenames).'"';
777: $communityrolestr = '"'.join('","',@communityrolenames).'"';
778: }
1.468 raeburn 779: my $setsections = qq|
780: function setSect(sectionlist) {
1.629 raeburn 781: var sectionsArray = new Array();
782: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
783: sectionsArray = sectionlist.split(",");
784: }
1.468 raeburn 785: var numSections = sectionsArray.length;
786: document.$formname.$sec_element.length = 0;
787: if (numSections == 0) {
788: document.$formname.$sec_element.multiple=false;
789: document.$formname.$sec_element.size=1;
790: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
791: } else {
792: if (numSections == 1) {
793: document.$formname.$sec_element.multiple=false;
794: document.$formname.$sec_element.size=1;
795: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
796: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
797: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
798: } else {
799: for (var i=0; i<numSections; i++) {
800: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
801: }
802: document.$formname.$sec_element.multiple=true
803: if (numSections < 3) {
804: document.$formname.$sec_element.size=numSections;
805: } else {
806: document.$formname.$sec_element.size=3;
807: }
808: document.$formname.$sec_element.options[0].selected = false
809: }
810: }
1.91 www 811: }
1.905 raeburn 812:
813: function setRole(crstype) {
1.468 raeburn 814: |;
1.905 raeburn 815: if ($role_element eq '') {
816: $setsections .= ' return;
817: }
818: ';
819: } else {
820: $setsections .= qq|
821: var elementLength = document.$formname.$role_element.length;
822: var allroles = Array($rolestr);
823: var courserolenames = Array($courserolestr);
824: var communityrolenames = Array($communityrolestr);
825: if (elementLength != undefined) {
826: if (document.$formname.$role_element.options[5].value == 'cc') {
827: if (crstype == 'Course') {
828: return;
829: } else {
830: allroles[5] = 'co';
831: for (var i=0; i<6; i++) {
832: document.$formname.$role_element.options[i].value = allroles[i];
833: document.$formname.$role_element.options[i].text = communityrolenames[i];
834: }
835: }
836: } else {
837: if (crstype == 'Community') {
838: return;
839: } else {
840: allroles[5] = 'cc';
841: for (var i=0; i<6; i++) {
842: document.$formname.$role_element.options[i].value = allroles[i];
843: document.$formname.$role_element.options[i].text = courserolenames[i];
844: }
845: }
846: }
847: }
848: return;
849: }
850: |;
851: }
1.1116 raeburn 852: if ($credits_element) {
853: $setsections .= qq|
854: function setCredits(defaultcredits) {
855: document.$formname.$credits_element.value = defaultcredits;
856: return;
857: }
858: |;
859: }
1.468 raeburn 860: return $setsections;
861: }
862:
1.91 www 863: sub selectcourse_link {
1.909 raeburn 864: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
865: $typeelement) = @_;
866: my $type = $selecttype;
1.871 raeburn 867: my $linktext = &mt('Select Course');
868: if ($selecttype eq 'Community') {
1.909 raeburn 869: $linktext = &mt('Select Community');
1.906 raeburn 870: } elsif ($selecttype eq 'Course/Community') {
871: $linktext = &mt('Select Course/Community');
1.909 raeburn 872: $type = '';
1.1019 raeburn 873: } elsif ($selecttype eq 'Select') {
874: $linktext = &mt('Select');
875: $type = '';
1.871 raeburn 876: }
1.787 bisitz 877: return '<span class="LC_nobreak">'
878: ."<a href='"
879: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
880: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 881: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 882: ."'>".$linktext.'</a>'
1.787 bisitz 883: .'</span>';
1.74 www 884: }
1.42 matthew 885:
1.653 raeburn 886: sub selectauthor_link {
887: my ($form,$udom)=@_;
888: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
889: &mt('Select Author').'</a>';
890: }
891:
1.876 raeburn 892: sub selectuser_link {
1.881 raeburn 893: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 894: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 895: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 896: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 897: ');">'.$linktext.'</a>';
1.876 raeburn 898: }
899:
1.273 raeburn 900: sub check_uncheck_jscript {
901: my $jscript = <<"ENDSCRT";
902: function checkAll(field) {
903: if (field.length > 0) {
904: for (i = 0; i < field.length; i++) {
1.1093 raeburn 905: if (!field[i].disabled) {
906: field[i].checked = true;
907: }
1.273 raeburn 908: }
909: } else {
1.1093 raeburn 910: if (!field.disabled) {
911: field.checked = true;
912: }
1.273 raeburn 913: }
914: }
915:
916: function uncheckAll(field) {
917: if (field.length > 0) {
918: for (i = 0; i < field.length; i++) {
919: field[i].checked = false ;
1.543 albertel 920: }
921: } else {
1.273 raeburn 922: field.checked = false ;
923: }
924: }
925: ENDSCRT
926: return $jscript;
927: }
928:
1.656 www 929: sub select_timezone {
1.659 raeburn 930: my ($name,$selected,$onchange,$includeempty)=@_;
931: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
932: if ($includeempty) {
933: $output .= '<option value=""';
934: if (($selected eq '') || ($selected eq 'local')) {
935: $output .= ' selected="selected" ';
936: }
937: $output .= '> </option>';
938: }
1.657 raeburn 939: my @timezones = DateTime::TimeZone->all_names;
940: foreach my $tzone (@timezones) {
941: $output.= '<option value="'.$tzone.'"';
942: if ($tzone eq $selected) {
943: $output.=' selected="selected"';
944: }
945: $output.=">$tzone</option>\n";
1.656 www 946: }
947: $output.="</select>";
948: return $output;
949: }
1.273 raeburn 950:
1.687 raeburn 951: sub select_datelocale {
952: my ($name,$selected,$onchange,$includeempty)=@_;
953: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
954: if ($includeempty) {
955: $output .= '<option value=""';
956: if ($selected eq '') {
957: $output .= ' selected="selected" ';
958: }
959: $output .= '> </option>';
960: }
961: my (@possibles,%locale_names);
962: my @locales = DateTime::Locale::Catalog::Locales;
963: foreach my $locale (@locales) {
964: if (ref($locale) eq 'HASH') {
965: my $id = $locale->{'id'};
966: if ($id ne '') {
967: my $en_terr = $locale->{'en_territory'};
968: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 969: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 970: if (grep(/^en$/,@languages) || !@languages) {
971: if ($en_terr ne '') {
972: $locale_names{$id} = '('.$en_terr.')';
973: } elsif ($native_terr ne '') {
974: $locale_names{$id} = $native_terr;
975: }
976: } else {
977: if ($native_terr ne '') {
978: $locale_names{$id} = $native_terr.' ';
979: } elsif ($en_terr ne '') {
980: $locale_names{$id} = '('.$en_terr.')';
981: }
982: }
983: push (@possibles,$id);
984: }
985: }
986: }
987: foreach my $item (sort(@possibles)) {
988: $output.= '<option value="'.$item.'"';
989: if ($item eq $selected) {
990: $output.=' selected="selected"';
991: }
992: $output.=">$item";
993: if ($locale_names{$item} ne '') {
994: $output.=" $locale_names{$item}</option>\n";
995: }
996: $output.="</option>\n";
997: }
998: $output.="</select>";
999: return $output;
1000: }
1001:
1.792 raeburn 1002: sub select_language {
1003: my ($name,$selected,$includeempty) = @_;
1004: my %langchoices;
1005: if ($includeempty) {
1.1117 raeburn 1006: %langchoices = ('' => 'No language preference');
1.792 raeburn 1007: }
1008: foreach my $id (&languageids()) {
1009: my $code = &supportedlanguagecode($id);
1010: if ($code) {
1011: $langchoices{$code} = &plainlanguagedescription($id);
1012: }
1013: }
1.1117 raeburn 1014: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1015: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1016: }
1017:
1.42 matthew 1018: =pod
1.36 matthew 1019:
1.1088 foxr 1020:
1021: =item * &list_languages()
1022:
1023: Returns an array reference that is suitable for use in language prompters.
1024: Each array element is itself a two element array. The first element
1025: is the language code. The second element a descsriptiuon of the
1026: language itself. This is suitable for use in e.g.
1027: &Apache::edit::select_arg (once dereferenced that is).
1028:
1029: =cut
1030:
1031: sub list_languages {
1032: my @lang_choices;
1033:
1034: foreach my $id (&languageids()) {
1035: my $code = &supportedlanguagecode($id);
1036: if ($code) {
1037: my $selector = $supported_codes{$id};
1038: my $description = &plainlanguagedescription($id);
1039: push (@lang_choices, [$selector, $description]);
1040: }
1041: }
1042: return \@lang_choices;
1043: }
1044:
1045: =pod
1046:
1.648 raeburn 1047: =item * &linked_select_forms(...)
1.36 matthew 1048:
1049: linked_select_forms returns a string containing a <script></script> block
1050: and html for two <select> menus. The select menus will be linked in that
1051: changing the value of the first menu will result in new values being placed
1052: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1053: order unless a defined order is provided.
1.36 matthew 1054:
1055: linked_select_forms takes the following ordered inputs:
1056:
1057: =over 4
1058:
1.112 bowersj2 1059: =item * $formname, the name of the <form> tag
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $firstdefault, the default value for the first menu
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1066:
1.112 bowersj2 1067: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1068:
1.112 bowersj2 1069: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1070:
1.609 raeburn 1071: =item * $menuorder, the order of values in the first menu
1072:
1.1115 raeburn 1073: =item * $onchangefirst, additional javascript call to execute for an onchange
1074: event for the first <select> tag
1075:
1076: =item * $onchangesecond, additional javascript call to execute for an onchange
1077: event for the second <select> tag
1078:
1.41 ng 1079: =back
1080:
1.36 matthew 1081: Below is an example of such a hash. Only the 'text', 'default', and
1082: 'select2' keys must appear as stated. keys(%menu) are the possible
1083: values for the first select menu. The text that coincides with the
1.41 ng 1084: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1085: and text for the second menu are given in the hash pointed to by
1086: $menu{$choice1}->{'select2'}.
1087:
1.112 bowersj2 1088: my %menu = ( A1 => { text =>"Choice A1" ,
1089: default => "B3",
1090: select2 => {
1091: B1 => "Choice B1",
1092: B2 => "Choice B2",
1093: B3 => "Choice B3",
1094: B4 => "Choice B4"
1.609 raeburn 1095: },
1096: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1097: },
1098: A2 => { text =>"Choice A2" ,
1099: default => "C2",
1100: select2 => {
1101: C1 => "Choice C1",
1102: C2 => "Choice C2",
1103: C3 => "Choice C3"
1.609 raeburn 1104: },
1105: order => ['C2','C1','C3'],
1.112 bowersj2 1106: },
1107: A3 => { text =>"Choice A3" ,
1108: default => "D6",
1109: select2 => {
1110: D1 => "Choice D1",
1111: D2 => "Choice D2",
1112: D3 => "Choice D3",
1113: D4 => "Choice D4",
1114: D5 => "Choice D5",
1115: D6 => "Choice D6",
1116: D7 => "Choice D7"
1.609 raeburn 1117: },
1118: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1119: }
1120: );
1.36 matthew 1121:
1122: =cut
1123:
1124: sub linked_select_forms {
1125: my ($formname,
1126: $middletext,
1127: $firstdefault,
1128: $firstselectname,
1129: $secondselectname,
1.609 raeburn 1130: $hashref,
1131: $menuorder,
1.1115 raeburn 1132: $onchangefirst,
1133: $onchangesecond
1.36 matthew 1134: ) = @_;
1135: my $second = "document.$formname.$secondselectname";
1136: my $first = "document.$formname.$firstselectname";
1137: # output the javascript to do the changing
1138: my $result = '';
1.776 bisitz 1139: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1140: $result.="// <![CDATA[\n";
1.36 matthew 1141: $result.="var select2data = new Object();\n";
1142: $" = '","';
1143: my $debug = '';
1144: foreach my $s1 (sort(keys(%$hashref))) {
1145: $result.="select2data.d_$s1 = new Object();\n";
1146: $result.="select2data.d_$s1.def = new String('".
1147: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1148: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1149: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1150: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1151: @s2values = @{$hashref->{$s1}->{'order'}};
1152: }
1.36 matthew 1153: $result.="\"@s2values\");\n";
1154: $result.="select2data.d_$s1.texts = new Array(";
1155: my @s2texts;
1156: foreach my $value (@s2values) {
1157: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1158: }
1159: $result.="\"@s2texts\");\n";
1160: }
1161: $"=' ';
1162: $result.= <<"END";
1163:
1164: function select1_changed() {
1165: // Determine new choice
1166: var newvalue = "d_" + $first.value;
1167: // update select2
1168: var values = select2data[newvalue].values;
1169: var texts = select2data[newvalue].texts;
1170: var select2def = select2data[newvalue].def;
1171: var i;
1172: // out with the old
1173: for (i = 0; i < $second.options.length; i++) {
1174: $second.options[i] = null;
1175: }
1176: // in with the nuclear
1177: for (i=0;i<values.length; i++) {
1178: $second.options[i] = new Option(values[i]);
1.143 matthew 1179: $second.options[i].value = values[i];
1.36 matthew 1180: $second.options[i].text = texts[i];
1181: if (values[i] == select2def) {
1182: $second.options[i].selected = true;
1183: }
1184: }
1185: }
1.824 bisitz 1186: // ]]>
1.36 matthew 1187: </script>
1188: END
1189: # output the initial values for the selection lists
1.1115 raeburn 1190: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1191: my @order = sort(keys(%{$hashref}));
1192: if (ref($menuorder) eq 'ARRAY') {
1193: @order = @{$menuorder};
1194: }
1195: foreach my $value (@order) {
1.36 matthew 1196: $result.=" <option value=\"$value\" ";
1.253 albertel 1197: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1198: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1199: }
1200: $result .= "</select>\n";
1201: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1202: $result .= $middletext;
1.1115 raeburn 1203: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1204: if ($onchangesecond) {
1205: $result .= ' onchange="'.$onchangesecond.'"';
1206: }
1207: $result .= ">\n";
1.36 matthew 1208: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1209:
1210: my @secondorder = sort(keys(%select2));
1211: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1212: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1213: }
1214: foreach my $value (@secondorder) {
1.36 matthew 1215: $result.=" <option value=\"$value\" ";
1.253 albertel 1216: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1217: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1218: }
1219: $result .= "</select>\n";
1220: # return $debug;
1221: return $result;
1222: } # end of sub linked_select_forms {
1223:
1.45 matthew 1224: =pod
1.44 bowersj2 1225:
1.973 raeburn 1226: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1227:
1.112 bowersj2 1228: Returns a string corresponding to an HTML link to the given help
1229: $topic, where $topic corresponds to the name of a .tex file in
1230: /home/httpd/html/adm/help/tex, with underscores replaced by
1231: spaces.
1232:
1233: $text will optionally be linked to the same topic, allowing you to
1234: link text in addition to the graphic. If you do not want to link
1235: text, but wish to specify one of the later parameters, pass an
1236: empty string.
1237:
1238: $stayOnPage is a value that will be interpreted as a boolean. If true,
1239: the link will not open a new window. If false, the link will open
1240: a new window using Javascript. (Default is false.)
1241:
1242: $width and $height are optional numerical parameters that will
1243: override the width and height of the popped up window, which may
1.973 raeburn 1244: be useful for certain help topics with big pictures included.
1245:
1246: $imgid is the id of the img tag used for the help icon. This may be
1247: used in a javascript call to switch the image src. See
1248: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1249:
1250: =cut
1251:
1252: sub help_open_topic {
1.973 raeburn 1253: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1254: $text = "" if (not defined $text);
1.44 bowersj2 1255: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1256: $width = 500 if (not defined $width);
1.44 bowersj2 1257: $height = 400 if (not defined $height);
1258: my $filename = $topic;
1259: $filename =~ s/ /_/g;
1260:
1.48 bowersj2 1261: my $template = "";
1262: my $link;
1.572 banghart 1263:
1.159 www 1264: $topic=~s/\W/\_/g;
1.44 bowersj2 1265:
1.572 banghart 1266: if (!$stayOnPage) {
1.1033 www 1267: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1268: } elsif ($stayOnPage eq 'popup') {
1269: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1270: } else {
1.48 bowersj2 1271: $link = "/adm/help/${filename}.hlp";
1272: }
1273:
1274: # Add the text
1.755 neumanie 1275: if ($text ne "") {
1.763 bisitz 1276: $template.='<span class="LC_help_open_topic">'
1277: .'<a target="_top" href="'.$link.'">'
1278: .$text.'</a>';
1.48 bowersj2 1279: }
1280:
1.763 bisitz 1281: # (Always) Add the graphic
1.179 matthew 1282: my $title = &mt('Online Help');
1.667 raeburn 1283: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1284: if ($imgid ne '') {
1285: $imgid = ' id="'.$imgid.'"';
1286: }
1.763 bisitz 1287: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1288: .'<img src="'.$helpicon.'" border="0"'
1289: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1290: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1291: .' /></a>';
1292: if ($text ne "") {
1293: $template.='</span>';
1294: }
1.44 bowersj2 1295: return $template;
1296:
1.106 bowersj2 1297: }
1298:
1299: # This is a quicky function for Latex cheatsheet editing, since it
1300: # appears in at least four places
1301: sub helpLatexCheatsheet {
1.1037 www 1302: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1303: my $out;
1.106 bowersj2 1304: my $addOther = '';
1.732 raeburn 1305: if ($topic) {
1.1037 www 1306: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1307: }
1308: $out = '<span>' # Start cheatsheet
1309: .$addOther
1310: .'<span>'
1.1037 www 1311: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1312: .'</span> <span>'
1.1037 www 1313: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span>';
1.732 raeburn 1315: unless ($not_author) {
1.763 bisitz 1316: $out .= ' <span>'
1.1037 www 1317: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1318: .'</span>';
1.732 raeburn 1319: }
1.763 bisitz 1320: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1321: return $out;
1.172 www 1322: }
1323:
1.430 albertel 1324: sub general_help {
1325: my $helptopic='Student_Intro';
1326: if ($env{'request.role'}=~/^(ca|au)/) {
1327: $helptopic='Authoring_Intro';
1.907 raeburn 1328: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1329: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1330: } elsif ($env{'request.role'}=~/^dc/) {
1331: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1332: }
1333: return $helptopic;
1334: }
1335:
1336: sub update_help_link {
1337: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1338: my $origurl = $ENV{'REQUEST_URI'};
1339: $origurl=~s|^/~|/priv/|;
1340: my $timestamp = time;
1341: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1342: $$datum = &escape($$datum);
1343: }
1344:
1345: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1346: my $output .= <<"ENDOUTPUT";
1347: <script type="text/javascript">
1.824 bisitz 1348: // <![CDATA[
1.430 albertel 1349: banner_link = '$banner_link';
1.824 bisitz 1350: // ]]>
1.430 albertel 1351: </script>
1352: ENDOUTPUT
1353: return $output;
1354: }
1355:
1356: # now just updates the help link and generates a blue icon
1.193 raeburn 1357: sub help_open_menu {
1.430 albertel 1358: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1359: = @_;
1.949 droeschl 1360: $stayOnPage = 1;
1.430 albertel 1361: my $output;
1362: if ($component_help) {
1363: if (!$text) {
1364: $output=&help_open_topic($component_help,undef,$stayOnPage,
1365: $width,$height);
1366: } else {
1367: my $help_text;
1368: $help_text=&unescape($topic);
1369: $output='<table><tr><td>'.
1370: &help_open_topic($component_help,$help_text,$stayOnPage,
1371: $width,$height).'</td></tr></table>';
1372: }
1373: }
1374: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1375: return $output.$banner_link;
1376: }
1377:
1378: sub top_nav_help {
1379: my ($text) = @_;
1.436 albertel 1380: $text = &mt($text);
1.949 droeschl 1381: my $stay_on_page = 1;
1382:
1.572 banghart 1383: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1384: : "javascript:helpMenu('open')";
1.572 banghart 1385: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1386:
1.201 raeburn 1387: my $title = &mt('Get help');
1.436 albertel 1388:
1389: return <<"END";
1390: $banner_link
1391: <a href="$link" title="$title">$text</a>
1392: END
1393: }
1394:
1395: sub help_menu_js {
1396: my ($text) = @_;
1.949 droeschl 1397: my $stayOnPage = 1;
1.436 albertel 1398: my $width = 620;
1399: my $height = 600;
1.430 albertel 1400: my $helptopic=&general_help();
1401: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1402: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1403: my $start_page =
1404: &Apache::loncommon::start_page('Help Menu', undef,
1405: {'frameset' => 1,
1406: 'js_ready' => 1,
1407: 'add_entries' => {
1408: 'border' => '0',
1.579 raeburn 1409: 'rows' => "110,*",},});
1.331 albertel 1410: my $end_page =
1411: &Apache::loncommon::end_page({'frameset' => 1,
1412: 'js_ready' => 1,});
1413:
1.436 albertel 1414: my $template .= <<"ENDTEMPLATE";
1415: <script type="text/javascript">
1.877 bisitz 1416: // <![CDATA[
1.253 albertel 1417: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1418: var banner_link = '';
1.243 raeburn 1419: function helpMenu(target) {
1420: var caller = this;
1421: if (target == 'open') {
1422: var newWindow = null;
1423: try {
1.262 albertel 1424: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1425: }
1426: catch(error) {
1427: writeHelp(caller);
1428: return;
1429: }
1430: if (newWindow) {
1431: caller = newWindow;
1432: }
1.193 raeburn 1433: }
1.243 raeburn 1434: writeHelp(caller);
1435: return;
1436: }
1437: function writeHelp(caller) {
1.1072 raeburn 1438: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1439: caller.document.close()
1440: caller.focus()
1.193 raeburn 1441: }
1.877 bisitz 1442: // END LON-CAPA Internal -->
1.253 albertel 1443: // ]]>
1.436 albertel 1444: </script>
1.193 raeburn 1445: ENDTEMPLATE
1446: return $template;
1447: }
1448:
1.172 www 1449: sub help_open_bug {
1450: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1451: unless ($env{'user.adv'}) { return ''; }
1.172 www 1452: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1453: $text = "" if (not defined $text);
1454: $stayOnPage=1;
1.184 albertel 1455: $width = 600 if (not defined $width);
1456: $height = 600 if (not defined $height);
1.172 www 1457:
1458: $topic=~s/\W+/\+/g;
1459: my $link='';
1460: my $template='';
1.379 albertel 1461: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1462: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1463: if (!$stayOnPage)
1464: {
1465: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1466: }
1467: else
1468: {
1469: $link = $url;
1470: }
1471: # Add the text
1472: if ($text ne "")
1473: {
1474: $template .=
1475: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1476: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1477: }
1478:
1479: # Add the graphic
1.179 matthew 1480: my $title = &mt('Report a Bug');
1.215 albertel 1481: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1482: $template .= <<"ENDTEMPLATE";
1.436 albertel 1483: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1484: ENDTEMPLATE
1485: if ($text ne '') { $template.='</td></tr></table>' };
1486: return $template;
1487:
1488: }
1489:
1490: sub help_open_faq {
1491: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1492: unless ($env{'user.adv'}) { return ''; }
1.172 www 1493: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1494: $text = "" if (not defined $text);
1495: $stayOnPage=1;
1496: $width = 350 if (not defined $width);
1497: $height = 400 if (not defined $height);
1498:
1499: $topic=~s/\W+/\+/g;
1500: my $link='';
1501: my $template='';
1502: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1503: if (!$stayOnPage)
1504: {
1505: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1506: }
1507: else
1508: {
1509: $link = $url;
1510: }
1511:
1512: # Add the text
1513: if ($text ne "")
1514: {
1515: $template .=
1.173 www 1516: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1517: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1518: }
1519:
1520: # Add the graphic
1.179 matthew 1521: my $title = &mt('View the FAQ');
1.215 albertel 1522: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1523: $template .= <<"ENDTEMPLATE";
1.436 albertel 1524: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1525: ENDTEMPLATE
1526: if ($text ne '') { $template.='</td></tr></table>' };
1527: return $template;
1528:
1.44 bowersj2 1529: }
1.37 matthew 1530:
1.180 matthew 1531: ###############################################################
1532: ###############################################################
1533:
1.45 matthew 1534: =pod
1535:
1.648 raeburn 1536: =item * &change_content_javascript():
1.256 matthew 1537:
1538: This and the next function allow you to create small sections of an
1539: otherwise static HTML page that you can update on the fly with
1540: Javascript, even in Netscape 4.
1541:
1542: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1543: must be written to the HTML page once. It will prove the Javascript
1544: function "change(name, content)". Calling the change function with the
1545: name of the section
1546: you want to update, matching the name passed to C<changable_area>, and
1547: the new content you want to put in there, will put the content into
1548: that area.
1549:
1550: B<Note>: Netscape 4 only reserves enough space for the changable area
1551: to contain room for the original contents. You need to "make space"
1552: for whatever changes you wish to make, and be B<sure> to check your
1553: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1554: it's adequate for updating a one-line status display, but little more.
1555: This script will set the space to 100% width, so you only need to
1556: worry about height in Netscape 4.
1557:
1558: Modern browsers are much less limiting, and if you can commit to the
1559: user not using Netscape 4, this feature may be used freely with
1560: pretty much any HTML.
1561:
1562: =cut
1563:
1564: sub change_content_javascript {
1565: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1566: if ($env{'browser.type'} eq 'netscape' &&
1567: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1568: return (<<NETSCAPE4);
1569: function change(name, content) {
1570: doc = document.layers[name+"___escape"].layers[0].document;
1571: doc.open();
1572: doc.write(content);
1573: doc.close();
1574: }
1575: NETSCAPE4
1576: } else {
1577: # Otherwise, we need to use semi-standards-compliant code
1578: # (technically, "innerHTML" isn't standard but the equivalent
1579: # is really scary, and every useful browser supports it
1580: return (<<DOMBASED);
1581: function change(name, content) {
1582: element = document.getElementById(name);
1583: element.innerHTML = content;
1584: }
1585: DOMBASED
1586: }
1587: }
1588:
1589: =pod
1590:
1.648 raeburn 1591: =item * &changable_area($name,$origContent):
1.256 matthew 1592:
1593: This provides a "changable area" that can be modified on the fly via
1594: the Javascript code provided in C<change_content_javascript>. $name is
1595: the name you will use to reference the area later; do not repeat the
1596: same name on a given HTML page more then once. $origContent is what
1597: the area will originally contain, which can be left blank.
1598:
1599: =cut
1600:
1601: sub changable_area {
1602: my ($name, $origContent) = @_;
1603:
1.258 albertel 1604: if ($env{'browser.type'} eq 'netscape' &&
1605: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1606: # If this is netscape 4, we need to use the Layer tag
1607: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1608: } else {
1609: return "<span id='$name'>$origContent</span>";
1610: }
1611: }
1612:
1613: =pod
1614:
1.648 raeburn 1615: =item * &viewport_geometry_js
1.590 raeburn 1616:
1617: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1618:
1619: =cut
1620:
1621:
1622: sub viewport_geometry_js {
1623: return <<"GEOMETRY";
1624: var Geometry = {};
1625: function init_geometry() {
1626: if (Geometry.init) { return };
1627: Geometry.init=1;
1628: if (window.innerHeight) {
1629: Geometry.getViewportHeight = function() { return window.innerHeight; };
1630: Geometry.getViewportWidth = function() { return window.innerWidth; };
1631: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1632: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1633: }
1634: else if (document.documentElement && document.documentElement.clientHeight) {
1635: Geometry.getViewportHeight =
1636: function() { return document.documentElement.clientHeight; };
1637: Geometry.getViewportWidth =
1638: function() { return document.documentElement.clientWidth; };
1639:
1640: Geometry.getHorizontalScroll =
1641: function() { return document.documentElement.scrollLeft; };
1642: Geometry.getVerticalScroll =
1643: function() { return document.documentElement.scrollTop; };
1644: }
1645: else if (document.body.clientHeight) {
1646: Geometry.getViewportHeight =
1647: function() { return document.body.clientHeight; };
1648: Geometry.getViewportWidth =
1649: function() { return document.body.clientWidth; };
1650: Geometry.getHorizontalScroll =
1651: function() { return document.body.scrollLeft; };
1652: Geometry.getVerticalScroll =
1653: function() { return document.body.scrollTop; };
1654: }
1655: }
1656:
1657: GEOMETRY
1658: }
1659:
1660: =pod
1661:
1.648 raeburn 1662: =item * &viewport_size_js()
1.590 raeburn 1663:
1664: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1665:
1666: =cut
1667:
1668: sub viewport_size_js {
1669: my $geometry = &viewport_geometry_js();
1670: return <<"DIMS";
1671:
1672: $geometry
1673:
1674: function getViewportDims(width,height) {
1675: init_geometry();
1676: width.value = Geometry.getViewportWidth();
1677: height.value = Geometry.getViewportHeight();
1678: return;
1679: }
1680:
1681: DIMS
1682: }
1683:
1684: =pod
1685:
1.648 raeburn 1686: =item * &resize_textarea_js()
1.565 albertel 1687:
1688: emits the needed javascript to resize a textarea to be as big as possible
1689:
1690: creates a function resize_textrea that takes two IDs first should be
1691: the id of the element to resize, second should be the id of a div that
1692: surrounds everything that comes after the textarea, this routine needs
1693: to be attached to the <body> for the onload and onresize events.
1694:
1.648 raeburn 1695: =back
1.565 albertel 1696:
1697: =cut
1698:
1699: sub resize_textarea_js {
1.590 raeburn 1700: my $geometry = &viewport_geometry_js();
1.565 albertel 1701: return <<"RESIZE";
1702: <script type="text/javascript">
1.824 bisitz 1703: // <![CDATA[
1.590 raeburn 1704: $geometry
1.565 albertel 1705:
1.588 albertel 1706: function getX(element) {
1707: var x = 0;
1708: while (element) {
1709: x += element.offsetLeft;
1710: element = element.offsetParent;
1711: }
1712: return x;
1713: }
1714: function getY(element) {
1715: var y = 0;
1716: while (element) {
1717: y += element.offsetTop;
1718: element = element.offsetParent;
1719: }
1720: return y;
1721: }
1722:
1723:
1.565 albertel 1724: function resize_textarea(textarea_id,bottom_id) {
1725: init_geometry();
1726: var textarea = document.getElementById(textarea_id);
1727: //alert(textarea);
1728:
1.588 albertel 1729: var textarea_top = getY(textarea);
1.565 albertel 1730: var textarea_height = textarea.offsetHeight;
1731: var bottom = document.getElementById(bottom_id);
1.588 albertel 1732: var bottom_top = getY(bottom);
1.565 albertel 1733: var bottom_height = bottom.offsetHeight;
1734: var window_height = Geometry.getViewportHeight();
1.588 albertel 1735: var fudge = 23;
1.565 albertel 1736: var new_height = window_height-fudge-textarea_top-bottom_height;
1737: if (new_height < 300) {
1738: new_height = 300;
1739: }
1740: textarea.style.height=new_height+'px';
1741: }
1.824 bisitz 1742: // ]]>
1.565 albertel 1743: </script>
1744: RESIZE
1745:
1746: }
1747:
1748: =pod
1749:
1.256 matthew 1750: =head1 Excel and CSV file utility routines
1751:
1752: =over 4
1753:
1754: =cut
1755:
1756: ###############################################################
1757: ###############################################################
1758:
1759: =pod
1760:
1.648 raeburn 1761: =item * &csv_translate($text)
1.37 matthew 1762:
1.185 www 1763: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1764: format.
1765:
1766: =cut
1767:
1.180 matthew 1768: ###############################################################
1769: ###############################################################
1.37 matthew 1770: sub csv_translate {
1771: my $text = shift;
1772: $text =~ s/\"/\"\"/g;
1.209 albertel 1773: $text =~ s/\n/ /g;
1.37 matthew 1774: return $text;
1775: }
1.180 matthew 1776:
1777: ###############################################################
1778: ###############################################################
1779:
1780: =pod
1781:
1.648 raeburn 1782: =item * &define_excel_formats()
1.180 matthew 1783:
1784: Define some commonly used Excel cell formats.
1785:
1786: Currently supported formats:
1787:
1788: =over 4
1789:
1790: =item header
1791:
1792: =item bold
1793:
1794: =item h1
1795:
1796: =item h2
1797:
1798: =item h3
1799:
1.256 matthew 1800: =item h4
1801:
1802: =item i
1803:
1.180 matthew 1804: =item date
1805:
1806: =back
1807:
1808: Inputs: $workbook
1809:
1810: Returns: $format, a hash reference.
1811:
1.1057 foxr 1812:
1.180 matthew 1813: =cut
1814:
1815: ###############################################################
1816: ###############################################################
1817: sub define_excel_formats {
1818: my ($workbook) = @_;
1819: my $format;
1820: $format->{'header'} = $workbook->add_format(bold => 1,
1821: bottom => 1,
1822: align => 'center');
1823: $format->{'bold'} = $workbook->add_format(bold=>1);
1824: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1825: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1826: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1827: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1828: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1829: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1830: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1831: return $format;
1832: }
1833:
1834: ###############################################################
1835: ###############################################################
1.113 bowersj2 1836:
1837: =pod
1838:
1.648 raeburn 1839: =item * &create_workbook()
1.255 matthew 1840:
1841: Create an Excel worksheet. If it fails, output message on the
1842: request object and return undefs.
1843:
1844: Inputs: Apache request object
1845:
1846: Returns (undef) on failure,
1847: Excel worksheet object, scalar with filename, and formats
1848: from &Apache::loncommon::define_excel_formats on success
1849:
1850: =cut
1851:
1852: ###############################################################
1853: ###############################################################
1854: sub create_workbook {
1855: my ($r) = @_;
1856: #
1857: # Create the excel spreadsheet
1858: my $filename = '/prtspool/'.
1.258 albertel 1859: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1860: time.'_'.rand(1000000000).'.xls';
1861: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1862: if (! defined($workbook)) {
1863: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1864: $r->print(
1865: '<p class="LC_error">'
1866: .&mt('Problems occurred in creating the new Excel file.')
1867: .' '.&mt('This error has been logged.')
1868: .' '.&mt('Please alert your LON-CAPA administrator.')
1869: .'</p>'
1870: );
1.255 matthew 1871: return (undef);
1872: }
1873: #
1.1014 foxr 1874: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1875: #
1876: my $format = &Apache::loncommon::define_excel_formats($workbook);
1877: return ($workbook,$filename,$format);
1878: }
1879:
1880: ###############################################################
1881: ###############################################################
1882:
1883: =pod
1884:
1.648 raeburn 1885: =item * &create_text_file()
1.113 bowersj2 1886:
1.542 raeburn 1887: Create a file to write to and eventually make available to the user.
1.256 matthew 1888: If file creation fails, outputs an error message on the request object and
1889: return undefs.
1.113 bowersj2 1890:
1.256 matthew 1891: Inputs: Apache request object, and file suffix
1.113 bowersj2 1892:
1.256 matthew 1893: Returns (undef) on failure,
1894: Filehandle and filename on success.
1.113 bowersj2 1895:
1896: =cut
1897:
1.256 matthew 1898: ###############################################################
1899: ###############################################################
1900: sub create_text_file {
1901: my ($r,$suffix) = @_;
1902: if (! defined($suffix)) { $suffix = 'txt'; };
1903: my $fh;
1904: my $filename = '/prtspool/'.
1.258 albertel 1905: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1906: time.'_'.rand(1000000000).'.'.$suffix;
1907: $fh = Apache::File->new('>/home/httpd'.$filename);
1908: if (! defined($fh)) {
1909: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1910: $r->print(
1911: '<p class="LC_error">'
1912: .&mt('Problems occurred in creating the output file.')
1913: .' '.&mt('This error has been logged.')
1914: .' '.&mt('Please alert your LON-CAPA administrator.')
1915: .'</p>'
1916: );
1.113 bowersj2 1917: }
1.256 matthew 1918: return ($fh,$filename)
1.113 bowersj2 1919: }
1920:
1921:
1.256 matthew 1922: =pod
1.113 bowersj2 1923:
1924: =back
1925:
1926: =cut
1.37 matthew 1927:
1928: ###############################################################
1.33 matthew 1929: ## Home server <option> list generating code ##
1930: ###############################################################
1.35 matthew 1931:
1.169 www 1932: # ------------------------------------------
1933:
1934: sub domain_select {
1935: my ($name,$value,$multiple)=@_;
1936: my %domains=map {
1.514 albertel 1937: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1938: } &Apache::lonnet::all_domains();
1.169 www 1939: if ($multiple) {
1940: $domains{''}=&mt('Any domain');
1.550 albertel 1941: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1942: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1943: } else {
1.550 albertel 1944: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1945: return &select_form($name,$value,\%domains);
1.169 www 1946: }
1947: }
1948:
1.282 albertel 1949: #-------------------------------------------
1950:
1951: =pod
1952:
1.519 raeburn 1953: =head1 Routines for form select boxes
1954:
1955: =over 4
1956:
1.648 raeburn 1957: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1958:
1959: Returns a string containing a <select> element int multiple mode
1960:
1961:
1962: Args:
1963: $name - name of the <select> element
1.506 raeburn 1964: $value - scalar or array ref of values that should already be selected
1.282 albertel 1965: $size - number of rows long the select element is
1.283 albertel 1966: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1967: (shown text should already have been &mt())
1.506 raeburn 1968: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1969:
1.282 albertel 1970: =cut
1971:
1972: #-------------------------------------------
1.169 www 1973: sub multiple_select_form {
1.284 albertel 1974: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1975: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1976: my $output='';
1.191 matthew 1977: if (! defined($size)) {
1978: $size = 4;
1.283 albertel 1979: if (scalar(keys(%$hash))<4) {
1980: $size = scalar(keys(%$hash));
1.191 matthew 1981: }
1982: }
1.734 bisitz 1983: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1984: my @order;
1.506 raeburn 1985: if (ref($order) eq 'ARRAY') {
1986: @order = @{$order};
1987: } else {
1988: @order = sort(keys(%$hash));
1.501 banghart 1989: }
1990: if (exists($$hash{'select_form_order'})) {
1991: @order = @{$$hash{'select_form_order'}};
1992: }
1993:
1.284 albertel 1994: foreach my $key (@order) {
1.356 albertel 1995: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1996: $output.='selected="selected" ' if ($selected{$key});
1997: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1998: }
1999: $output.="</select>\n";
2000: return $output;
2001: }
2002:
1.88 www 2003: #-------------------------------------------
2004:
2005: =pod
2006:
1.970 raeburn 2007: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2008:
2009: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2010: allow a user to select options from a ref to a hash containing:
2011: option_name => displayed text. An optional $onchange can include
2012: a javascript onchange item, e.g., onchange="this.form.submit();"
2013:
1.88 www 2014: See lonrights.pm for an example invocation and use.
2015:
2016: =cut
2017:
2018: #-------------------------------------------
2019: sub select_form {
1.970 raeburn 2020: my ($def,$name,$hashref,$onchange) = @_;
2021: return unless (ref($hashref) eq 'HASH');
2022: if ($onchange) {
2023: $onchange = ' onchange="'.$onchange.'"';
2024: }
2025: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2026: my @keys;
1.970 raeburn 2027: if (exists($hashref->{'select_form_order'})) {
2028: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2029: } else {
1.970 raeburn 2030: @keys=sort(keys(%{$hashref}));
1.128 albertel 2031: }
1.356 albertel 2032: foreach my $key (@keys) {
2033: $selectform.=
2034: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2035: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2036: ">".$hashref->{$key}."</option>\n";
1.88 www 2037: }
2038: $selectform.="</select>";
2039: return $selectform;
2040: }
2041:
1.475 www 2042: # For display filters
2043:
2044: sub display_filter {
1.1074 raeburn 2045: my ($context) = @_;
1.475 www 2046: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2047: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2048: my $phraseinput = 'hidden';
2049: my $includeinput = 'hidden';
2050: my ($checked,$includetypestext);
2051: if ($env{'form.displayfilter'} eq 'containing') {
2052: $phraseinput = 'text';
2053: if ($context eq 'parmslog') {
2054: $includeinput = 'checkbox';
2055: if ($env{'form.includetypes'}) {
2056: $checked = ' checked="checked"';
2057: }
2058: $includetypestext = &mt('Include parameter types');
2059: }
2060: } else {
2061: $includetypestext = ' ';
2062: }
2063: my ($additional,$secondid,$thirdid);
2064: if ($context eq 'parmslog') {
2065: $additional =
2066: '<label><input type="'.$includeinput.'" name="includetypes"'.
2067: $checked.' name="includetypes" value="1" id="includetypes" />'.
2068: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2069: '</label>';
2070: $secondid = 'includetypes';
2071: $thirdid = 'includetypestext';
2072: }
2073: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2074: '$secondid','$thirdid')";
2075: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2076: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2077: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2078: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2079: &mt('Filter: [_1]',
1.477 www 2080: &select_form($env{'form.displayfilter'},
2081: 'displayfilter',
1.970 raeburn 2082: {'currentfolder' => 'Current folder/page',
1.477 www 2083: 'containing' => 'Containing phrase',
1.1074 raeburn 2084: 'none' => 'None'},$onchange)).' '.
2085: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2086: &HTML::Entities::encode($env{'form.containingphrase'}).
2087: '" />'.$additional;
2088: }
2089:
2090: sub display_filter_js {
2091: my $includetext = &mt('Include parameter types');
2092: return <<"ENDJS";
2093:
2094: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2095: var firstType = 'hidden';
2096: if (setter.options[setter.selectedIndex].value == 'containing') {
2097: firstType = 'text';
2098: }
2099: firstObject = document.getElementById(firstid);
2100: if (typeof(firstObject) == 'object') {
2101: if (firstObject.type != firstType) {
2102: changeInputType(firstObject,firstType);
2103: }
2104: }
2105: if (context == 'parmslog') {
2106: var secondType = 'hidden';
2107: if (firstType == 'text') {
2108: secondType = 'checkbox';
2109: }
2110: secondObject = document.getElementById(secondid);
2111: if (typeof(secondObject) == 'object') {
2112: if (secondObject.type != secondType) {
2113: changeInputType(secondObject,secondType);
2114: }
2115: }
2116: var textItem = document.getElementById(thirdid);
2117: var currtext = textItem.innerHTML;
2118: var newtext;
2119: if (firstType == 'text') {
2120: newtext = '$includetext';
2121: } else {
2122: newtext = ' ';
2123: }
2124: if (currtext != newtext) {
2125: textItem.innerHTML = newtext;
2126: }
2127: }
2128: return;
2129: }
2130:
2131: function changeInputType(oldObject,newType) {
2132: var newObject = document.createElement('input');
2133: newObject.type = newType;
2134: if (oldObject.size) {
2135: newObject.size = oldObject.size;
2136: }
2137: if (oldObject.value) {
2138: newObject.value = oldObject.value;
2139: }
2140: if (oldObject.name) {
2141: newObject.name = oldObject.name;
2142: }
2143: if (oldObject.id) {
2144: newObject.id = oldObject.id;
2145: }
2146: oldObject.parentNode.replaceChild(newObject,oldObject);
2147: return;
2148: }
2149:
2150: ENDJS
1.475 www 2151: }
2152:
1.167 www 2153: sub gradeleveldescription {
2154: my $gradelevel=shift;
2155: my %gradelevels=(0 => 'Not specified',
2156: 1 => 'Grade 1',
2157: 2 => 'Grade 2',
2158: 3 => 'Grade 3',
2159: 4 => 'Grade 4',
2160: 5 => 'Grade 5',
2161: 6 => 'Grade 6',
2162: 7 => 'Grade 7',
2163: 8 => 'Grade 8',
2164: 9 => 'Grade 9',
2165: 10 => 'Grade 10',
2166: 11 => 'Grade 11',
2167: 12 => 'Grade 12',
2168: 13 => 'Grade 13',
2169: 14 => '100 Level',
2170: 15 => '200 Level',
2171: 16 => '300 Level',
2172: 17 => '400 Level',
2173: 18 => 'Graduate Level');
2174: return &mt($gradelevels{$gradelevel});
2175: }
2176:
1.163 www 2177: sub select_level_form {
2178: my ($deflevel,$name)=@_;
2179: unless ($deflevel) { $deflevel=0; }
1.167 www 2180: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2181: for (my $i=0; $i<=18; $i++) {
2182: $selectform.="<option value=\"$i\" ".
1.253 albertel 2183: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2184: ">".&gradeleveldescription($i)."</option>\n";
2185: }
2186: $selectform.="</select>";
2187: return $selectform;
1.163 www 2188: }
1.167 www 2189:
1.35 matthew 2190: #-------------------------------------------
2191:
1.45 matthew 2192: =pod
2193:
1.910 raeburn 2194: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2195:
2196: Returns a string containing a <select name='$name' size='1'> form to
2197: allow a user to select the domain to preform an operation in.
2198: See loncreateuser.pm for an example invocation and use.
2199:
1.90 www 2200: If the $includeempty flag is set, it also includes an empty choice ("no domain
2201: selected");
2202:
1.743 raeburn 2203: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2204:
1.910 raeburn 2205: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2206:
2207: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2208:
1.35 matthew 2209: =cut
2210:
2211: #-------------------------------------------
1.34 matthew 2212: sub select_dom_form {
1.910 raeburn 2213: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2214: if ($onchange) {
1.874 raeburn 2215: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2216: }
1.910 raeburn 2217: my @domains;
2218: if (ref($incdoms) eq 'ARRAY') {
2219: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2220: } else {
2221: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2222: }
1.90 www 2223: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2224: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2225: foreach my $dom (@domains) {
2226: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2227: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2228: if ($showdomdesc) {
2229: if ($dom ne '') {
2230: my $domdesc = &Apache::lonnet::domain($dom,'description');
2231: if ($domdesc ne '') {
2232: $selectdomain .= ' ('.$domdesc.')';
2233: }
2234: }
2235: }
2236: $selectdomain .= "</option>\n";
1.34 matthew 2237: }
2238: $selectdomain.="</select>";
2239: return $selectdomain;
2240: }
2241:
1.35 matthew 2242: #-------------------------------------------
2243:
1.45 matthew 2244: =pod
2245:
1.648 raeburn 2246: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2247:
1.586 raeburn 2248: input: 4 arguments (two required, two optional) -
2249: $domain - domain of new user
2250: $name - name of form element
2251: $default - Value of 'default' causes a default item to be first
2252: option, and selected by default.
2253: $hide - Value of 'hide' causes hiding of the name of the server,
2254: if 1 server found, or default, if 0 found.
1.594 raeburn 2255: output: returns 2 items:
1.586 raeburn 2256: (a) form element which contains either:
2257: (i) <select name="$name">
2258: <option value="$hostid1">$hostid $servers{$hostid}</option>
2259: <option value="$hostid2">$hostid $servers{$hostid}</option>
2260: </select>
2261: form item if there are multiple library servers in $domain, or
2262: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2263: if there is only one library server in $domain.
2264:
2265: (b) number of library servers found.
2266:
2267: See loncreateuser.pm for example of use.
1.35 matthew 2268:
2269: =cut
2270:
2271: #-------------------------------------------
1.586 raeburn 2272: sub home_server_form_item {
2273: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2274: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2275: my $result;
2276: my $numlib = keys(%servers);
2277: if ($numlib > 1) {
2278: $result .= '<select name="'.$name.'" />'."\n";
2279: if ($default) {
1.804 bisitz 2280: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2281: '</option>'."\n";
2282: }
2283: foreach my $hostid (sort(keys(%servers))) {
2284: $result.= '<option value="'.$hostid.'">'.
2285: $hostid.' '.$servers{$hostid}."</option>\n";
2286: }
2287: $result .= '</select>'."\n";
2288: } elsif ($numlib == 1) {
2289: my $hostid;
2290: foreach my $item (keys(%servers)) {
2291: $hostid = $item;
2292: }
2293: $result .= '<input type="hidden" name="'.$name.'" value="'.
2294: $hostid.'" />';
2295: if (!$hide) {
2296: $result .= $hostid.' '.$servers{$hostid};
2297: }
2298: $result .= "\n";
2299: } elsif ($default) {
2300: $result .= '<input type="hidden" name="'.$name.
2301: '" value="default" />';
2302: if (!$hide) {
2303: $result .= &mt('default');
2304: }
2305: $result .= "\n";
1.33 matthew 2306: }
1.586 raeburn 2307: return ($result,$numlib);
1.33 matthew 2308: }
1.112 bowersj2 2309:
2310: =pod
2311:
1.534 albertel 2312: =back
2313:
1.112 bowersj2 2314: =cut
1.87 matthew 2315:
2316: ###############################################################
1.112 bowersj2 2317: ## Decoding User Agent ##
1.87 matthew 2318: ###############################################################
2319:
2320: =pod
2321:
1.112 bowersj2 2322: =head1 Decoding the User Agent
2323:
2324: =over 4
2325:
2326: =item * &decode_user_agent()
1.87 matthew 2327:
2328: Inputs: $r
2329:
2330: Outputs:
2331:
2332: =over 4
2333:
1.112 bowersj2 2334: =item * $httpbrowser
1.87 matthew 2335:
1.112 bowersj2 2336: =item * $clientbrowser
1.87 matthew 2337:
1.112 bowersj2 2338: =item * $clientversion
1.87 matthew 2339:
1.112 bowersj2 2340: =item * $clientmathml
1.87 matthew 2341:
1.112 bowersj2 2342: =item * $clientunicode
1.87 matthew 2343:
1.112 bowersj2 2344: =item * $clientos
1.87 matthew 2345:
2346: =back
2347:
1.157 matthew 2348: =back
2349:
1.87 matthew 2350: =cut
2351:
2352: ###############################################################
2353: ###############################################################
2354: sub decode_user_agent {
1.247 albertel 2355: my ($r)=@_;
1.87 matthew 2356: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2357: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2358: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2359: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2360: my $clientbrowser='unknown';
2361: my $clientversion='0';
2362: my $clientmathml='';
2363: my $clientunicode='0';
2364: for (my $i=0;$i<=$#browsertype;$i++) {
2365: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2366: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2367: $clientbrowser=$bname;
2368: $httpbrowser=~/$vreg/i;
2369: $clientversion=$1;
2370: $clientmathml=($clientversion>=$minv);
2371: $clientunicode=($clientversion>=$univ);
2372: }
2373: }
2374: my $clientos='unknown';
2375: if (($httpbrowser=~/linux/i) ||
2376: ($httpbrowser=~/unix/i) ||
2377: ($httpbrowser=~/ux/i) ||
2378: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2379: if (($httpbrowser=~/vax/i) ||
2380: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2381: if ($httpbrowser=~/next/i) { $clientos='next'; }
2382: if (($httpbrowser=~/mac/i) ||
2383: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2384: if ($httpbrowser=~/win/i) { $clientos='win'; }
2385: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2386: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2387: $clientunicode,$clientos,);
2388: }
2389:
1.32 matthew 2390: ###############################################################
2391: ## Authentication changing form generation subroutines ##
2392: ###############################################################
2393: ##
2394: ## All of the authform_xxxxxxx subroutines take their inputs in a
2395: ## hash, and have reasonable default values.
2396: ##
2397: ## formname = the name given in the <form> tag.
1.35 matthew 2398: #-------------------------------------------
2399:
1.45 matthew 2400: =pod
2401:
1.112 bowersj2 2402: =head1 Authentication Routines
2403:
2404: =over 4
2405:
1.648 raeburn 2406: =item * &authform_xxxxxx()
1.35 matthew 2407:
2408: The authform_xxxxxx subroutines provide javascript and html forms which
2409: handle some of the conveniences required for authentication forms.
2410: This is not an optimal method, but it works.
2411:
2412: =over 4
2413:
1.112 bowersj2 2414: =item * authform_header
1.35 matthew 2415:
1.112 bowersj2 2416: =item * authform_authorwarning
1.35 matthew 2417:
1.112 bowersj2 2418: =item * authform_nochange
1.35 matthew 2419:
1.112 bowersj2 2420: =item * authform_kerberos
1.35 matthew 2421:
1.112 bowersj2 2422: =item * authform_internal
1.35 matthew 2423:
1.112 bowersj2 2424: =item * authform_filesystem
1.35 matthew 2425:
2426: =back
2427:
1.648 raeburn 2428: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2429:
1.35 matthew 2430: =cut
2431:
2432: #-------------------------------------------
1.32 matthew 2433: sub authform_header{
2434: my %in = (
2435: formname => 'cu',
1.80 albertel 2436: kerb_def_dom => '',
1.32 matthew 2437: @_,
2438: );
2439: $in{'formname'} = 'document.' . $in{'formname'};
2440: my $result='';
1.80 albertel 2441:
2442: #---------------------------------------------- Code for upper case translation
2443: my $Javascript_toUpperCase;
2444: unless ($in{kerb_def_dom}) {
2445: $Javascript_toUpperCase =<<"END";
2446: switch (choice) {
2447: case 'krb': currentform.elements[choicearg].value =
2448: currentform.elements[choicearg].value.toUpperCase();
2449: break;
2450: default:
2451: }
2452: END
2453: } else {
2454: $Javascript_toUpperCase = "";
2455: }
2456:
1.165 raeburn 2457: my $radioval = "'nochange'";
1.591 raeburn 2458: if (defined($in{'curr_authtype'})) {
2459: if ($in{'curr_authtype'} ne '') {
2460: $radioval = "'".$in{'curr_authtype'}."arg'";
2461: }
1.174 matthew 2462: }
1.165 raeburn 2463: my $argfield = 'null';
1.591 raeburn 2464: if (defined($in{'mode'})) {
1.165 raeburn 2465: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2466: if (defined($in{'curr_autharg'})) {
2467: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2468: $argfield = "'$in{'curr_autharg'}'";
2469: }
2470: }
2471: }
2472: }
2473:
1.32 matthew 2474: $result.=<<"END";
2475: var current = new Object();
1.165 raeburn 2476: current.radiovalue = $radioval;
2477: current.argfield = $argfield;
1.32 matthew 2478:
2479: function changed_radio(choice,currentform) {
2480: var choicearg = choice + 'arg';
2481: // If a radio button in changed, we need to change the argfield
2482: if (current.radiovalue != choice) {
2483: current.radiovalue = choice;
2484: if (current.argfield != null) {
2485: currentform.elements[current.argfield].value = '';
2486: }
2487: if (choice == 'nochange') {
2488: current.argfield = null;
2489: } else {
2490: current.argfield = choicearg;
2491: switch(choice) {
2492: case 'krb':
2493: currentform.elements[current.argfield].value =
2494: "$in{'kerb_def_dom'}";
2495: break;
2496: default:
2497: break;
2498: }
2499: }
2500: }
2501: return;
2502: }
1.22 www 2503:
1.32 matthew 2504: function changed_text(choice,currentform) {
2505: var choicearg = choice + 'arg';
2506: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2507: $Javascript_toUpperCase
1.32 matthew 2508: // clear old field
2509: if ((current.argfield != choicearg) && (current.argfield != null)) {
2510: currentform.elements[current.argfield].value = '';
2511: }
2512: current.argfield = choicearg;
2513: }
2514: set_auth_radio_buttons(choice,currentform);
2515: return;
1.20 www 2516: }
1.32 matthew 2517:
2518: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2519: var numauthchoices = currentform.login.length;
2520: if (typeof numauthchoices == "undefined") {
2521: return;
2522: }
1.32 matthew 2523: var i=0;
1.986 raeburn 2524: while (i < numauthchoices) {
1.32 matthew 2525: if (currentform.login[i].value == newvalue) { break; }
2526: i++;
2527: }
1.986 raeburn 2528: if (i == numauthchoices) {
1.32 matthew 2529: return;
2530: }
2531: current.radiovalue = newvalue;
2532: currentform.login[i].checked = true;
2533: return;
2534: }
2535: END
2536: return $result;
2537: }
2538:
1.1106 raeburn 2539: sub authform_authorwarning {
1.32 matthew 2540: my $result='';
1.144 matthew 2541: $result='<i>'.
2542: &mt('As a general rule, only authors or co-authors should be '.
2543: 'filesystem authenticated '.
2544: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2545: return $result;
2546: }
2547:
1.1106 raeburn 2548: sub authform_nochange {
1.32 matthew 2549: my %in = (
2550: formname => 'document.cu',
2551: kerb_def_dom => 'MSU.EDU',
2552: @_,
2553: );
1.1106 raeburn 2554: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2555: my $result;
1.1104 raeburn 2556: if (!$authnum) {
1.1105 raeburn 2557: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2558: } else {
2559: $result = '<label>'.&mt('[_1] Do not change login data',
2560: '<input type="radio" name="login" value="nochange" '.
2561: 'checked="checked" onclick="'.
1.281 albertel 2562: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2563: '</label>';
1.586 raeburn 2564: }
1.32 matthew 2565: return $result;
2566: }
2567:
1.591 raeburn 2568: sub authform_kerberos {
1.32 matthew 2569: my %in = (
2570: formname => 'document.cu',
2571: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2572: kerb_def_auth => 'krb4',
1.32 matthew 2573: @_,
2574: );
1.586 raeburn 2575: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2576: $autharg,$jscall);
1.1106 raeburn 2577: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2578: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2579: $check5 = ' checked="checked"';
1.80 albertel 2580: } else {
1.772 bisitz 2581: $check4 = ' checked="checked"';
1.80 albertel 2582: }
1.165 raeburn 2583: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2584: if (defined($in{'curr_authtype'})) {
2585: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2586: $krbcheck = ' checked="checked"';
1.623 raeburn 2587: if (defined($in{'mode'})) {
2588: if ($in{'mode'} eq 'modifyuser') {
2589: $krbcheck = '';
2590: }
2591: }
1.591 raeburn 2592: if (defined($in{'curr_kerb_ver'})) {
2593: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2594: $check5 = ' checked="checked"';
1.591 raeburn 2595: $check4 = '';
2596: } else {
1.772 bisitz 2597: $check4 = ' checked="checked"';
1.591 raeburn 2598: $check5 = '';
2599: }
1.586 raeburn 2600: }
1.591 raeburn 2601: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2602: $krbarg = $in{'curr_autharg'};
2603: }
1.586 raeburn 2604: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2605: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2606: $result =
2607: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2608: $in{'curr_autharg'},$krbver);
2609: } else {
2610: $result =
2611: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2612: }
2613: return $result;
2614: }
2615: }
2616: } else {
2617: if ($authnum == 1) {
1.784 bisitz 2618: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2619: }
2620: }
1.586 raeburn 2621: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2622: return;
1.587 raeburn 2623: } elsif ($authtype eq '') {
1.591 raeburn 2624: if (defined($in{'mode'})) {
1.587 raeburn 2625: if ($in{'mode'} eq 'modifycourse') {
2626: if ($authnum == 1) {
1.1104 raeburn 2627: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2628: }
2629: }
2630: }
1.586 raeburn 2631: }
2632: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2633: if ($authtype eq '') {
2634: $authtype = '<input type="radio" name="login" value="krb" '.
2635: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2636: $krbcheck.' />';
2637: }
2638: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2639: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2640: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2641: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2642: $in{'curr_authtype'} eq 'krb4')) {
2643: $result .= &mt
1.144 matthew 2644: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2645: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2646: '<label>'.$authtype,
1.281 albertel 2647: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2648: 'value="'.$krbarg.'" '.
1.144 matthew 2649: 'onchange="'.$jscall.'" />',
1.281 albertel 2650: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2651: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2652: '</label>');
1.586 raeburn 2653: } elsif ($can_assign{'krb4'}) {
2654: $result .= &mt
2655: ('[_1] Kerberos authenticated with domain [_2] '.
2656: '[_3] Version 4 [_4]',
2657: '<label>'.$authtype,
2658: '</label><input type="text" size="10" name="krbarg" '.
2659: 'value="'.$krbarg.'" '.
2660: 'onchange="'.$jscall.'" />',
2661: '<label><input type="hidden" name="krbver" value="4" />',
2662: '</label>');
2663: } elsif ($can_assign{'krb5'}) {
2664: $result .= &mt
2665: ('[_1] Kerberos authenticated with domain [_2] '.
2666: '[_3] Version 5 [_4]',
2667: '<label>'.$authtype,
2668: '</label><input type="text" size="10" name="krbarg" '.
2669: 'value="'.$krbarg.'" '.
2670: 'onchange="'.$jscall.'" />',
2671: '<label><input type="hidden" name="krbver" value="5" />',
2672: '</label>');
2673: }
1.32 matthew 2674: return $result;
2675: }
2676:
1.1106 raeburn 2677: sub authform_internal {
1.586 raeburn 2678: my %in = (
1.32 matthew 2679: formname => 'document.cu',
2680: kerb_def_dom => 'MSU.EDU',
2681: @_,
2682: );
1.586 raeburn 2683: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2684: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2685: if (defined($in{'curr_authtype'})) {
2686: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2687: if ($can_assign{'int'}) {
1.772 bisitz 2688: $intcheck = 'checked="checked" ';
1.623 raeburn 2689: if (defined($in{'mode'})) {
2690: if ($in{'mode'} eq 'modifyuser') {
2691: $intcheck = '';
2692: }
2693: }
1.591 raeburn 2694: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2695: $intarg = $in{'curr_autharg'};
2696: }
2697: } else {
2698: $result = &mt('Currently internally authenticated.');
2699: return $result;
1.165 raeburn 2700: }
2701: }
1.586 raeburn 2702: } else {
2703: if ($authnum == 1) {
1.784 bisitz 2704: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2705: }
2706: }
2707: if (!$can_assign{'int'}) {
2708: return;
1.587 raeburn 2709: } elsif ($authtype eq '') {
1.591 raeburn 2710: if (defined($in{'mode'})) {
1.587 raeburn 2711: if ($in{'mode'} eq 'modifycourse') {
2712: if ($authnum == 1) {
1.1104 raeburn 2713: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2714: }
2715: }
2716: }
1.165 raeburn 2717: }
1.586 raeburn 2718: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2719: if ($authtype eq '') {
2720: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2721: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2722: }
1.605 bisitz 2723: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2724: $intarg.'" onchange="'.$jscall.'" />';
2725: $result = &mt
1.144 matthew 2726: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2727: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2728: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2729: return $result;
2730: }
2731:
1.1104 raeburn 2732: sub authform_local {
1.32 matthew 2733: my %in = (
2734: formname => 'document.cu',
2735: kerb_def_dom => 'MSU.EDU',
2736: @_,
2737: );
1.586 raeburn 2738: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2739: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2740: if (defined($in{'curr_authtype'})) {
2741: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2742: if ($can_assign{'loc'}) {
1.772 bisitz 2743: $loccheck = 'checked="checked" ';
1.623 raeburn 2744: if (defined($in{'mode'})) {
2745: if ($in{'mode'} eq 'modifyuser') {
2746: $loccheck = '';
2747: }
2748: }
1.591 raeburn 2749: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2750: $locarg = $in{'curr_autharg'};
2751: }
2752: } else {
2753: $result = &mt('Currently using local (institutional) authentication.');
2754: return $result;
1.165 raeburn 2755: }
2756: }
1.586 raeburn 2757: } else {
2758: if ($authnum == 1) {
1.784 bisitz 2759: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2760: }
2761: }
2762: if (!$can_assign{'loc'}) {
2763: return;
1.587 raeburn 2764: } elsif ($authtype eq '') {
1.591 raeburn 2765: if (defined($in{'mode'})) {
1.587 raeburn 2766: if ($in{'mode'} eq 'modifycourse') {
2767: if ($authnum == 1) {
1.1104 raeburn 2768: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2769: }
2770: }
2771: }
1.165 raeburn 2772: }
1.586 raeburn 2773: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2774: if ($authtype eq '') {
2775: $authtype = '<input type="radio" name="login" value="loc" '.
2776: $loccheck.' onchange="'.$jscall.'" onclick="'.
2777: $jscall.'" />';
2778: }
2779: $autharg = '<input type="text" size="10" name="locarg" value="'.
2780: $locarg.'" onchange="'.$jscall.'" />';
2781: $result = &mt('[_1] Local Authentication with argument [_2]',
2782: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2783: return $result;
2784: }
2785:
1.1106 raeburn 2786: sub authform_filesystem {
1.32 matthew 2787: my %in = (
2788: formname => 'document.cu',
2789: kerb_def_dom => 'MSU.EDU',
2790: @_,
2791: );
1.586 raeburn 2792: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2793: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2794: if (defined($in{'curr_authtype'})) {
2795: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2796: if ($can_assign{'fsys'}) {
1.772 bisitz 2797: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2798: if (defined($in{'mode'})) {
2799: if ($in{'mode'} eq 'modifyuser') {
2800: $fsyscheck = '';
2801: }
2802: }
1.586 raeburn 2803: } else {
2804: $result = &mt('Currently Filesystem Authenticated.');
2805: return $result;
2806: }
2807: }
2808: } else {
2809: if ($authnum == 1) {
1.784 bisitz 2810: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2811: }
2812: }
2813: if (!$can_assign{'fsys'}) {
2814: return;
1.587 raeburn 2815: } elsif ($authtype eq '') {
1.591 raeburn 2816: if (defined($in{'mode'})) {
1.587 raeburn 2817: if ($in{'mode'} eq 'modifycourse') {
2818: if ($authnum == 1) {
1.1104 raeburn 2819: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2820: }
2821: }
2822: }
1.586 raeburn 2823: }
2824: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2825: if ($authtype eq '') {
2826: $authtype = '<input type="radio" name="login" value="fsys" '.
2827: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2828: $jscall.'" />';
2829: }
2830: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2831: ' onchange="'.$jscall.'" />';
2832: $result = &mt
1.144 matthew 2833: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2834: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2835: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2836: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2837: 'onchange="'.$jscall.'" />');
1.32 matthew 2838: return $result;
2839: }
2840:
1.586 raeburn 2841: sub get_assignable_auth {
2842: my ($dom) = @_;
2843: if ($dom eq '') {
2844: $dom = $env{'request.role.domain'};
2845: }
2846: my %can_assign = (
2847: krb4 => 1,
2848: krb5 => 1,
2849: int => 1,
2850: loc => 1,
2851: );
2852: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2853: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2854: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2855: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2856: my $context;
2857: if ($env{'request.role'} =~ /^au/) {
2858: $context = 'author';
2859: } elsif ($env{'request.role'} =~ /^dc/) {
2860: $context = 'domain';
2861: } elsif ($env{'request.course.id'}) {
2862: $context = 'course';
2863: }
2864: if ($context) {
2865: if (ref($authhash->{$context}) eq 'HASH') {
2866: %can_assign = %{$authhash->{$context}};
2867: }
2868: }
2869: }
2870: }
2871: my $authnum = 0;
2872: foreach my $key (keys(%can_assign)) {
2873: if ($can_assign{$key}) {
2874: $authnum ++;
2875: }
2876: }
2877: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2878: $authnum --;
2879: }
2880: return ($authnum,%can_assign);
2881: }
2882:
1.80 albertel 2883: ###############################################################
2884: ## Get Kerberos Defaults for Domain ##
2885: ###############################################################
2886: ##
2887: ## Returns default kerberos version and an associated argument
2888: ## as listed in file domain.tab. If not listed, provides
2889: ## appropriate default domain and kerberos version.
2890: ##
2891: #-------------------------------------------
2892:
2893: =pod
2894:
1.648 raeburn 2895: =item * &get_kerberos_defaults()
1.80 albertel 2896:
2897: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2898: version and domain. If not found, it defaults to version 4 and the
2899: domain of the server.
1.80 albertel 2900:
1.648 raeburn 2901: =over 4
2902:
1.80 albertel 2903: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2904:
1.648 raeburn 2905: =back
2906:
2907: =back
2908:
1.80 albertel 2909: =cut
2910:
2911: #-------------------------------------------
2912: sub get_kerberos_defaults {
2913: my $domain=shift;
1.641 raeburn 2914: my ($krbdef,$krbdefdom);
2915: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2916: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2917: $krbdef = $domdefaults{'auth_def'};
2918: $krbdefdom = $domdefaults{'auth_arg_def'};
2919: } else {
1.80 albertel 2920: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2921: my $krbdefdom=$1;
2922: $krbdefdom=~tr/a-z/A-Z/;
2923: $krbdef = "krb4";
2924: }
2925: return ($krbdef,$krbdefdom);
2926: }
1.112 bowersj2 2927:
1.32 matthew 2928:
1.46 matthew 2929: ###############################################################
2930: ## Thesaurus Functions ##
2931: ###############################################################
1.20 www 2932:
1.46 matthew 2933: =pod
1.20 www 2934:
1.112 bowersj2 2935: =head1 Thesaurus Functions
2936:
2937: =over 4
2938:
1.648 raeburn 2939: =item * &initialize_keywords()
1.46 matthew 2940:
2941: Initializes the package variable %Keywords if it is empty. Uses the
2942: package variable $thesaurus_db_file.
2943:
2944: =cut
2945:
2946: ###################################################
2947:
2948: sub initialize_keywords {
2949: return 1 if (scalar keys(%Keywords));
2950: # If we are here, %Keywords is empty, so fill it up
2951: # Make sure the file we need exists...
2952: if (! -e $thesaurus_db_file) {
2953: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2954: " failed because it does not exist");
2955: return 0;
2956: }
2957: # Set up the hash as a database
2958: my %thesaurus_db;
2959: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2960: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2961: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2962: $thesaurus_db_file);
2963: return 0;
2964: }
2965: # Get the average number of appearances of a word.
2966: my $avecount = $thesaurus_db{'average.count'};
2967: # Put keywords (those that appear > average) into %Keywords
2968: while (my ($word,$data)=each (%thesaurus_db)) {
2969: my ($count,undef) = split /:/,$data;
2970: $Keywords{$word}++ if ($count > $avecount);
2971: }
2972: untie %thesaurus_db;
2973: # Remove special values from %Keywords.
1.356 albertel 2974: foreach my $value ('total.count','average.count') {
2975: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2976: }
1.46 matthew 2977: return 1;
2978: }
2979:
2980: ###################################################
2981:
2982: =pod
2983:
1.648 raeburn 2984: =item * &keyword($word)
1.46 matthew 2985:
2986: Returns true if $word is a keyword. A keyword is a word that appears more
2987: than the average number of times in the thesaurus database. Calls
2988: &initialize_keywords
2989:
2990: =cut
2991:
2992: ###################################################
1.20 www 2993:
2994: sub keyword {
1.46 matthew 2995: return if (!&initialize_keywords());
2996: my $word=lc(shift());
2997: $word=~s/\W//g;
2998: return exists($Keywords{$word});
1.20 www 2999: }
1.46 matthew 3000:
3001: ###############################################################
3002:
3003: =pod
1.20 www 3004:
1.648 raeburn 3005: =item * &get_related_words()
1.46 matthew 3006:
1.160 matthew 3007: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3008: an array of words. If the keyword is not in the thesaurus, an empty array
3009: will be returned. The order of the words returned is determined by the
3010: database which holds them.
3011:
3012: Uses global $thesaurus_db_file.
3013:
1.1057 foxr 3014:
1.46 matthew 3015: =cut
3016:
3017: ###############################################################
3018: sub get_related_words {
3019: my $keyword = shift;
3020: my %thesaurus_db;
3021: if (! -e $thesaurus_db_file) {
3022: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3023: "failed because the file does not exist");
3024: return ();
3025: }
3026: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3027: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3028: return ();
3029: }
3030: my @Words=();
1.429 www 3031: my $count=0;
1.46 matthew 3032: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3033: # The first element is the number of times
3034: # the word appears. We do not need it now.
1.429 www 3035: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3036: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3037: my $threshold=$mostfrequentcount/10;
3038: foreach my $possibleword (@RelatedWords) {
3039: my ($word,$wordcount)=split(/\,/,$possibleword);
3040: if ($wordcount>$threshold) {
3041: push(@Words,$word);
3042: $count++;
3043: if ($count>10) { last; }
3044: }
1.20 www 3045: }
3046: }
1.46 matthew 3047: untie %thesaurus_db;
3048: return @Words;
1.14 harris41 3049: }
1.1090 foxr 3050: ###############################################################
3051: #
3052: # Spell checking
3053: #
3054:
3055: =pod
3056:
3057: =head1 Spell checking
3058:
3059: =over 4
3060:
3061: =item * &check_spelling($wordlist $language)
3062:
3063: Takes a string containing words and feeds it to an external
3064: spellcheck program via a pipeline. Returns a string containing
3065: them mis-spelled words.
3066:
3067: Parameters:
3068:
3069: =over 4
3070:
3071: =item - $wordlist
3072:
3073: String that will be fed into the spellcheck program.
3074:
3075: =item - $language
3076:
3077: Language string that specifies the language for which the spell
3078: check will be performed.
3079:
3080: =back
3081:
3082: =back
3083:
3084: Note: This sub assumes that aspell is installed.
3085:
3086:
3087: =cut
3088:
1.46 matthew 3089:
1.112 bowersj2 3090: =pod
3091:
3092: =back
3093:
3094: =cut
1.61 www 3095:
1.1090 foxr 3096: sub check_spelling {
3097: my ($wordlist, $language) = @_;
1.1091 foxr 3098: my @misspellings;
3099:
3100: # Generate the speller and set the langauge.
3101: # if explicitly selected:
1.1090 foxr 3102:
1.1091 foxr 3103: my $speller = Text::Aspell->new;
1.1090 foxr 3104: if ($language) {
1.1091 foxr 3105: $speller->set_option('lang', $language);
1.1090 foxr 3106: }
3107:
1.1091 foxr 3108: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3109:
1.1091 foxr 3110: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3111:
1.1091 foxr 3112: foreach my $word (@words) {
3113: if(! $speller->check($word)) {
3114: push(@misspellings, $word);
1.1090 foxr 3115: }
3116: }
1.1091 foxr 3117: return join(' ', @misspellings);
3118:
1.1090 foxr 3119: }
3120:
1.61 www 3121: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3122: =pod
3123:
1.112 bowersj2 3124: =head1 User Name Functions
3125:
3126: =over 4
3127:
1.648 raeburn 3128: =item * &plainname($uname,$udom,$first)
1.81 albertel 3129:
1.112 bowersj2 3130: Takes a users logon name and returns it as a string in
1.226 albertel 3131: "first middle last generation" form
3132: if $first is set to 'lastname' then it returns it as
3133: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3134:
3135: =cut
1.61 www 3136:
1.295 www 3137:
1.81 albertel 3138: ###############################################################
1.61 www 3139: sub plainname {
1.226 albertel 3140: my ($uname,$udom,$first)=@_;
1.537 albertel 3141: return if (!defined($uname) || !defined($udom));
1.295 www 3142: my %names=&getnames($uname,$udom);
1.226 albertel 3143: my $name=&Apache::lonnet::format_name($names{'firstname'},
3144: $names{'middlename'},
3145: $names{'lastname'},
3146: $names{'generation'},$first);
3147: $name=~s/^\s+//;
1.62 www 3148: $name=~s/\s+$//;
3149: $name=~s/\s+/ /g;
1.353 albertel 3150: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3151: return $name;
1.61 www 3152: }
1.66 www 3153:
3154: # -------------------------------------------------------------------- Nickname
1.81 albertel 3155: =pod
3156:
1.648 raeburn 3157: =item * &nickname($uname,$udom)
1.81 albertel 3158:
3159: Gets a users name and returns it as a string as
3160:
3161: ""nickname""
1.66 www 3162:
1.81 albertel 3163: if the user has a nickname or
3164:
3165: "first middle last generation"
3166:
3167: if the user does not
3168:
3169: =cut
1.66 www 3170:
3171: sub nickname {
3172: my ($uname,$udom)=@_;
1.537 albertel 3173: return if (!defined($uname) || !defined($udom));
1.295 www 3174: my %names=&getnames($uname,$udom);
1.68 albertel 3175: my $name=$names{'nickname'};
1.66 www 3176: if ($name) {
3177: $name='"'.$name.'"';
3178: } else {
3179: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3180: $names{'lastname'}.' '.$names{'generation'};
3181: $name=~s/\s+$//;
3182: $name=~s/\s+/ /g;
3183: }
3184: return $name;
3185: }
3186:
1.295 www 3187: sub getnames {
3188: my ($uname,$udom)=@_;
1.537 albertel 3189: return if (!defined($uname) || !defined($udom));
1.433 albertel 3190: if ($udom eq 'public' && $uname eq 'public') {
3191: return ('lastname' => &mt('Public'));
3192: }
1.295 www 3193: my $id=$uname.':'.$udom;
3194: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3195: if ($cached) {
3196: return %{$names};
3197: } else {
3198: my %loadnames=&Apache::lonnet::get('environment',
3199: ['firstname','middlename','lastname','generation','nickname'],
3200: $udom,$uname);
3201: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3202: return %loadnames;
3203: }
3204: }
1.61 www 3205:
1.542 raeburn 3206: # -------------------------------------------------------------------- getemails
1.648 raeburn 3207:
1.542 raeburn 3208: =pod
3209:
1.648 raeburn 3210: =item * &getemails($uname,$udom)
1.542 raeburn 3211:
3212: Gets a user's email information and returns it as a hash with keys:
3213: notification, critnotification, permanentemail
3214:
3215: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3216: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3217:
1.648 raeburn 3218:
1.542 raeburn 3219: =cut
3220:
1.648 raeburn 3221:
1.466 albertel 3222: sub getemails {
3223: my ($uname,$udom)=@_;
3224: if ($udom eq 'public' && $uname eq 'public') {
3225: return;
3226: }
1.467 www 3227: if (!$udom) { $udom=$env{'user.domain'}; }
3228: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3229: my $id=$uname.':'.$udom;
3230: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3231: if ($cached) {
3232: return %{$names};
3233: } else {
3234: my %loadnames=&Apache::lonnet::get('environment',
3235: ['notification','critnotification',
3236: 'permanentemail'],
3237: $udom,$uname);
3238: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3239: return %loadnames;
3240: }
3241: }
3242:
1.551 albertel 3243: sub flush_email_cache {
3244: my ($uname,$udom)=@_;
3245: if (!$udom) { $udom =$env{'user.domain'}; }
3246: if (!$uname) { $uname=$env{'user.name'}; }
3247: return if ($udom eq 'public' && $uname eq 'public');
3248: my $id=$uname.':'.$udom;
3249: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3250: }
3251:
1.728 raeburn 3252: # -------------------------------------------------------------------- getlangs
3253:
3254: =pod
3255:
3256: =item * &getlangs($uname,$udom)
3257:
3258: Gets a user's language preference and returns it as a hash with key:
3259: language.
3260:
3261: =cut
3262:
3263:
3264: sub getlangs {
3265: my ($uname,$udom) = @_;
3266: if (!$udom) { $udom =$env{'user.domain'}; }
3267: if (!$uname) { $uname=$env{'user.name'}; }
3268: my $id=$uname.':'.$udom;
3269: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3270: if ($cached) {
3271: return %{$langs};
3272: } else {
3273: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3274: $udom,$uname);
3275: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3276: return %loadlangs;
3277: }
3278: }
3279:
3280: sub flush_langs_cache {
3281: my ($uname,$udom)=@_;
3282: if (!$udom) { $udom =$env{'user.domain'}; }
3283: if (!$uname) { $uname=$env{'user.name'}; }
3284: return if ($udom eq 'public' && $uname eq 'public');
3285: my $id=$uname.':'.$udom;
3286: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3287: }
3288:
1.61 www 3289: # ------------------------------------------------------------------ Screenname
1.81 albertel 3290:
3291: =pod
3292:
1.648 raeburn 3293: =item * &screenname($uname,$udom)
1.81 albertel 3294:
3295: Gets a users screenname and returns it as a string
3296:
3297: =cut
1.61 www 3298:
3299: sub screenname {
3300: my ($uname,$udom)=@_;
1.258 albertel 3301: if ($uname eq $env{'user.name'} &&
3302: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3303: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3304: return $names{'screenname'};
1.62 www 3305: }
3306:
1.212 albertel 3307:
1.802 bisitz 3308: # ------------------------------------------------------------- Confirm Wrapper
3309: =pod
3310:
3311: =item confirmwrapper
3312:
3313: Wrap messages about completion of operation in box
3314:
3315: =cut
3316:
3317: sub confirmwrapper {
3318: my ($message)=@_;
3319: if ($message) {
3320: return "\n".'<div class="LC_confirm_box">'."\n"
3321: .$message."\n"
3322: .'</div>'."\n";
3323: } else {
3324: return $message;
3325: }
3326: }
3327:
1.62 www 3328: # ------------------------------------------------------------- Message Wrapper
3329:
3330: sub messagewrapper {
1.369 www 3331: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3332: return
1.441 albertel 3333: '<a href="/adm/email?compose=individual&'.
3334: 'recname='.$username.'&recdom='.$domain.
3335: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3336: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3337: }
1.802 bisitz 3338:
1.74 www 3339: # --------------------------------------------------------------- Notes Wrapper
3340:
3341: sub noteswrapper {
3342: my ($link,$un,$do)=@_;
3343: return
1.896 amueller 3344: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3345: }
1.802 bisitz 3346:
1.62 www 3347: # ------------------------------------------------------------- Aboutme Wrapper
3348:
3349: sub aboutmewrapper {
1.1070 raeburn 3350: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3351: if (!defined($username) && !defined($domain)) {
3352: return;
3353: }
1.1096 raeburn 3354: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3355: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3356: }
3357:
3358: # ------------------------------------------------------------ Syllabus Wrapper
3359:
3360: sub syllabuswrapper {
1.707 bisitz 3361: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3362: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3363: }
1.14 harris41 3364:
1.802 bisitz 3365: # -----------------------------------------------------------------------------
3366:
1.208 matthew 3367: sub track_student_link {
1.887 raeburn 3368: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3369: my $link ="/adm/trackstudent?";
1.208 matthew 3370: my $title = 'View recent activity';
3371: if (defined($sname) && $sname !~ /^\s*$/ &&
3372: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3373: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3374: $title .= ' of this student';
1.268 albertel 3375: }
1.208 matthew 3376: if (defined($target) && $target !~ /^\s*$/) {
3377: $target = qq{target="$target"};
3378: } else {
3379: $target = '';
3380: }
1.268 albertel 3381: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3382: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3383: $title = &mt($title);
3384: $linktext = &mt($linktext);
1.448 albertel 3385: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3386: &help_open_topic('View_recent_activity');
1.208 matthew 3387: }
3388:
1.781 raeburn 3389: sub slot_reservations_link {
3390: my ($linktext,$sname,$sdom,$target) = @_;
3391: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3392: my $title = 'View slot reservation history';
3393: if (defined($sname) && $sname !~ /^\s*$/ &&
3394: defined($sdom) && $sdom !~ /^\s*$/) {
3395: $link .= "&uname=$sname&udom=$sdom";
3396: $title .= ' of this student';
3397: }
3398: if (defined($target) && $target !~ /^\s*$/) {
3399: $target = qq{target="$target"};
3400: } else {
3401: $target = '';
3402: }
3403: $title = &mt($title);
3404: $linktext = &mt($linktext);
3405: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3406: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3407:
3408: }
3409:
1.508 www 3410: # ===================================================== Display a student photo
3411:
3412:
1.509 albertel 3413: sub student_image_tag {
1.508 www 3414: my ($domain,$user)=@_;
3415: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3416: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3417: return '<img src="'.$imgsrc.'" align="right" />';
3418: } else {
3419: return '';
3420: }
3421: }
3422:
1.112 bowersj2 3423: =pod
3424:
3425: =back
3426:
3427: =head1 Access .tab File Data
3428:
3429: =over 4
3430:
1.648 raeburn 3431: =item * &languageids()
1.112 bowersj2 3432:
3433: returns list of all language ids
3434:
3435: =cut
3436:
1.14 harris41 3437: sub languageids {
1.16 harris41 3438: return sort(keys(%language));
1.14 harris41 3439: }
3440:
1.112 bowersj2 3441: =pod
3442:
1.648 raeburn 3443: =item * &languagedescription()
1.112 bowersj2 3444:
3445: returns description of a specified language id
3446:
3447: =cut
3448:
1.14 harris41 3449: sub languagedescription {
1.125 www 3450: my $code=shift;
3451: return ($supported_language{$code}?'* ':'').
3452: $language{$code}.
1.126 www 3453: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3454: }
3455:
1.1048 foxr 3456: =pod
3457:
3458: =item * &plainlanguagedescription
3459:
3460: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3461: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3462:
3463: =cut
3464:
1.145 www 3465: sub plainlanguagedescription {
3466: my $code=shift;
3467: return $language{$code};
3468: }
3469:
1.1048 foxr 3470: =pod
3471:
3472: =item * &supportedlanguagecode
3473:
3474: Returns the supported language code (e.g. sptutf maps to pt) given a language
3475: code.
3476:
3477: =cut
3478:
1.145 www 3479: sub supportedlanguagecode {
3480: my $code=shift;
3481: return $supported_language{$code};
1.97 www 3482: }
3483:
1.112 bowersj2 3484: =pod
3485:
1.1048 foxr 3486: =item * &latexlanguage()
3487:
3488: Given a language key code returns the correspondnig language to use
3489: to select the correct hyphenation on LaTeX printouts. This is undef if there
3490: is no supported hyphenation for the language code.
3491:
3492: =cut
3493:
3494: sub latexlanguage {
3495: my $code = shift;
3496: return $latex_language{$code};
3497: }
3498:
3499: =pod
3500:
3501: =item * &latexhyphenation()
3502:
3503: Same as above but what's supplied is the language as it might be stored
3504: in the metadata.
3505:
3506: =cut
3507:
3508: sub latexhyphenation {
3509: my $key = shift;
3510: return $latex_language_bykey{$key};
3511: }
3512:
3513: =pod
3514:
1.648 raeburn 3515: =item * ©rightids()
1.112 bowersj2 3516:
3517: returns list of all copyrights
3518:
3519: =cut
3520:
3521: sub copyrightids {
3522: return sort(keys(%cprtag));
3523: }
3524:
3525: =pod
3526:
1.648 raeburn 3527: =item * ©rightdescription()
1.112 bowersj2 3528:
3529: returns description of a specified copyright id
3530:
3531: =cut
3532:
3533: sub copyrightdescription {
1.166 www 3534: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3535: }
1.197 matthew 3536:
3537: =pod
3538:
1.648 raeburn 3539: =item * &source_copyrightids()
1.192 taceyjo1 3540:
3541: returns list of all source copyrights
3542:
3543: =cut
3544:
3545: sub source_copyrightids {
3546: return sort(keys(%scprtag));
3547: }
3548:
3549: =pod
3550:
1.648 raeburn 3551: =item * &source_copyrightdescription()
1.192 taceyjo1 3552:
3553: returns description of a specified source copyright id
3554:
3555: =cut
3556:
3557: sub source_copyrightdescription {
3558: return &mt($scprtag{shift(@_)});
3559: }
1.112 bowersj2 3560:
3561: =pod
3562:
1.648 raeburn 3563: =item * &filecategories()
1.112 bowersj2 3564:
3565: returns list of all file categories
3566:
3567: =cut
3568:
3569: sub filecategories {
3570: return sort(keys(%category_extensions));
3571: }
3572:
3573: =pod
3574:
1.648 raeburn 3575: =item * &filecategorytypes()
1.112 bowersj2 3576:
3577: returns list of file types belonging to a given file
3578: category
3579:
3580: =cut
3581:
3582: sub filecategorytypes {
1.356 albertel 3583: my ($cat) = @_;
3584: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3585: }
3586:
3587: =pod
3588:
1.648 raeburn 3589: =item * &fileembstyle()
1.112 bowersj2 3590:
3591: returns embedding style for a specified file type
3592:
3593: =cut
3594:
3595: sub fileembstyle {
3596: return $fe{lc(shift(@_))};
1.169 www 3597: }
3598:
1.351 www 3599: sub filemimetype {
3600: return $fm{lc(shift(@_))};
3601: }
3602:
1.169 www 3603:
3604: sub filecategoryselect {
3605: my ($name,$value)=@_;
1.189 matthew 3606: return &select_form($value,$name,
1.970 raeburn 3607: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3608: }
3609:
3610: =pod
3611:
1.648 raeburn 3612: =item * &filedescription()
1.112 bowersj2 3613:
3614: returns description for a specified file type
3615:
3616: =cut
3617:
3618: sub filedescription {
1.188 matthew 3619: my $file_description = $fd{lc(shift())};
3620: $file_description =~ s:([\[\]]):~$1:g;
3621: return &mt($file_description);
1.112 bowersj2 3622: }
3623:
3624: =pod
3625:
1.648 raeburn 3626: =item * &filedescriptionex()
1.112 bowersj2 3627:
3628: returns description for a specified file type with
3629: extra formatting
3630:
3631: =cut
3632:
3633: sub filedescriptionex {
3634: my $ex=shift;
1.188 matthew 3635: my $file_description = $fd{lc($ex)};
3636: $file_description =~ s:([\[\]]):~$1:g;
3637: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3638: }
3639:
3640: # End of .tab access
3641: =pod
3642:
3643: =back
3644:
3645: =cut
3646:
3647: # ------------------------------------------------------------------ File Types
3648: sub fileextensions {
3649: return sort(keys(%fe));
3650: }
3651:
1.97 www 3652: # ----------------------------------------------------------- Display Languages
3653: # returns a hash with all desired display languages
3654: #
3655:
3656: sub display_languages {
3657: my %languages=();
1.695 raeburn 3658: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3659: $languages{$lang}=1;
1.97 www 3660: }
3661: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3662: if ($env{'form.displaylanguage'}) {
1.356 albertel 3663: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3664: $languages{$lang}=1;
1.97 www 3665: }
3666: }
3667: return %languages;
1.14 harris41 3668: }
3669:
1.582 albertel 3670: sub languages {
3671: my ($possible_langs) = @_;
1.695 raeburn 3672: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3673: if (!ref($possible_langs)) {
3674: if( wantarray ) {
3675: return @preferred_langs;
3676: } else {
3677: return $preferred_langs[0];
3678: }
3679: }
3680: my %possibilities = map { $_ => 1 } (@$possible_langs);
3681: my @preferred_possibilities;
3682: foreach my $preferred_lang (@preferred_langs) {
3683: if (exists($possibilities{$preferred_lang})) {
3684: push(@preferred_possibilities, $preferred_lang);
3685: }
3686: }
3687: if( wantarray ) {
3688: return @preferred_possibilities;
3689: }
3690: return $preferred_possibilities[0];
3691: }
3692:
1.742 raeburn 3693: sub user_lang {
3694: my ($touname,$toudom,$fromcid) = @_;
3695: my @userlangs;
3696: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3697: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3698: $env{'course.'.$fromcid.'.languages'}));
3699: } else {
3700: my %langhash = &getlangs($touname,$toudom);
3701: if ($langhash{'languages'} ne '') {
3702: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3703: } else {
3704: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3705: if ($domdefs{'lang_def'} ne '') {
3706: @userlangs = ($domdefs{'lang_def'});
3707: }
3708: }
3709: }
3710: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3711: my $user_lh = Apache::localize->get_handle(@languages);
3712: return $user_lh;
3713: }
3714:
3715:
1.112 bowersj2 3716: ###############################################################
3717: ## Student Answer Attempts ##
3718: ###############################################################
3719:
3720: =pod
3721:
3722: =head1 Alternate Problem Views
3723:
3724: =over 4
3725:
1.648 raeburn 3726: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3727: $getattempt, $regexp, $gradesub)
3728:
3729: Return string with previous attempt on problem. Arguments:
3730:
3731: =over 4
3732:
3733: =item * $symb: Problem, including path
3734:
3735: =item * $username: username of the desired student
3736:
3737: =item * $domain: domain of the desired student
1.14 harris41 3738:
1.112 bowersj2 3739: =item * $course: Course ID
1.14 harris41 3740:
1.112 bowersj2 3741: =item * $getattempt: Leave blank for all attempts, otherwise put
3742: something
1.14 harris41 3743:
1.112 bowersj2 3744: =item * $regexp: if string matches this regexp, the string will be
3745: sent to $gradesub
1.14 harris41 3746:
1.112 bowersj2 3747: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3748:
1.112 bowersj2 3749: =back
1.14 harris41 3750:
1.112 bowersj2 3751: The output string is a table containing all desired attempts, if any.
1.16 harris41 3752:
1.112 bowersj2 3753: =cut
1.1 albertel 3754:
3755: sub get_previous_attempt {
1.43 ng 3756: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3757: my $prevattempts='';
1.43 ng 3758: no strict 'refs';
1.1 albertel 3759: if ($symb) {
1.3 albertel 3760: my (%returnhash)=
3761: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3762: if ($returnhash{'version'}) {
3763: my %lasthash=();
3764: my $version;
3765: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3766: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3767: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3768: }
1.1 albertel 3769: }
1.596 albertel 3770: $prevattempts=&start_data_table().&start_data_table_header_row();
3771: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3772: my (%typeparts,%lasthidden);
1.945 raeburn 3773: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3774: foreach my $key (sort(keys(%lasthash))) {
3775: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3776: if ($#parts > 0) {
1.31 albertel 3777: my $data=$parts[-1];
1.989 raeburn 3778: next if ($data eq 'foilorder');
1.31 albertel 3779: pop(@parts);
1.1010 www 3780: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3781: if ($data eq 'type') {
3782: unless ($showsurv) {
3783: my $id = join(',',@parts);
3784: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3785: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3786: $lasthidden{$ign.'.'.$id} = 1;
3787: }
1.945 raeburn 3788: }
1.1010 www 3789: }
1.31 albertel 3790: } else {
1.41 ng 3791: if ($#parts == 0) {
3792: $prevattempts.='<th>'.$parts[0].'</th>';
3793: } else {
3794: $prevattempts.='<th>'.$ign.'</th>';
3795: }
1.31 albertel 3796: }
1.16 harris41 3797: }
1.596 albertel 3798: $prevattempts.=&end_data_table_header_row();
1.40 ng 3799: if ($getattempt eq '') {
3800: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3801: my @hidden;
3802: if (%typeparts) {
3803: foreach my $id (keys(%typeparts)) {
3804: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3805: push(@hidden,$id);
3806: }
3807: }
3808: }
3809: $prevattempts.=&start_data_table_row().
3810: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3811: if (@hidden) {
3812: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3813: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3814: my $hide;
3815: foreach my $id (@hidden) {
3816: if ($key =~ /^\Q$id\E/) {
3817: $hide = 1;
3818: last;
3819: }
3820: }
3821: if ($hide) {
3822: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3823: if (($data eq 'award') || ($data eq 'awarddetail')) {
3824: my $value = &format_previous_attempt_value($key,
3825: $returnhash{$version.':'.$key});
3826: $prevattempts.='<td>'.$value.' </td>';
3827: } else {
3828: $prevattempts.='<td> </td>';
3829: }
3830: } else {
3831: if ($key =~ /\./) {
3832: my $value = &format_previous_attempt_value($key,
3833: $returnhash{$version.':'.$key});
3834: $prevattempts.='<td>'.$value.' </td>';
3835: } else {
3836: $prevattempts.='<td> </td>';
3837: }
3838: }
3839: }
3840: } else {
3841: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3842: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3843: my $value = &format_previous_attempt_value($key,
3844: $returnhash{$version.':'.$key});
3845: $prevattempts.='<td>'.$value.' </td>';
3846: }
3847: }
3848: $prevattempts.=&end_data_table_row();
1.40 ng 3849: }
1.1 albertel 3850: }
1.945 raeburn 3851: my @currhidden = keys(%lasthidden);
1.596 albertel 3852: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3853: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3854: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3855: if (%typeparts) {
3856: my $hidden;
3857: foreach my $id (@currhidden) {
3858: if ($key =~ /^\Q$id\E/) {
3859: $hidden = 1;
3860: last;
3861: }
3862: }
3863: if ($hidden) {
3864: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3865: if (($data eq 'award') || ($data eq 'awarddetail')) {
3866: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3867: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3868: $value = &$gradesub($value);
3869: }
3870: $prevattempts.='<td>'.$value.' </td>';
3871: } else {
3872: $prevattempts.='<td> </td>';
3873: }
3874: } else {
3875: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3876: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3877: $value = &$gradesub($value);
3878: }
3879: $prevattempts.='<td>'.$value.' </td>';
3880: }
3881: } else {
3882: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3883: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3884: $value = &$gradesub($value);
3885: }
3886: $prevattempts.='<td>'.$value.' </td>';
3887: }
1.16 harris41 3888: }
1.596 albertel 3889: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3890: } else {
1.596 albertel 3891: $prevattempts=
3892: &start_data_table().&start_data_table_row().
3893: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3894: &end_data_table_row().&end_data_table();
1.1 albertel 3895: }
3896: } else {
1.596 albertel 3897: $prevattempts=
3898: &start_data_table().&start_data_table_row().
3899: '<td>'.&mt('No data.').'</td>'.
3900: &end_data_table_row().&end_data_table();
1.1 albertel 3901: }
1.10 albertel 3902: }
3903:
1.581 albertel 3904: sub format_previous_attempt_value {
3905: my ($key,$value) = @_;
1.1011 www 3906: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3907: $value = &Apache::lonlocal::locallocaltime($value);
3908: } elsif (ref($value) eq 'ARRAY') {
3909: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3910: } elsif ($key =~ /answerstring$/) {
3911: my %answers = &Apache::lonnet::str2hash($value);
3912: my @anskeys = sort(keys(%answers));
3913: if (@anskeys == 1) {
3914: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3915: if ($answer =~ m{\0}) {
3916: $answer =~ s{\0}{,}g;
1.988 raeburn 3917: }
3918: my $tag_internal_answer_name = 'INTERNAL';
3919: if ($anskeys[0] eq $tag_internal_answer_name) {
3920: $value = $answer;
3921: } else {
3922: $value = $anskeys[0].'='.$answer;
3923: }
3924: } else {
3925: foreach my $ans (@anskeys) {
3926: my $answer = $answers{$ans};
1.1001 raeburn 3927: if ($answer =~ m{\0}) {
3928: $answer =~ s{\0}{,}g;
1.988 raeburn 3929: }
3930: $value .= $ans.'='.$answer.'<br />';;
3931: }
3932: }
1.581 albertel 3933: } else {
3934: $value = &unescape($value);
3935: }
3936: return $value;
3937: }
3938:
3939:
1.107 albertel 3940: sub relative_to_absolute {
3941: my ($url,$output)=@_;
3942: my $parser=HTML::TokeParser->new(\$output);
3943: my $token;
3944: my $thisdir=$url;
3945: my @rlinks=();
3946: while ($token=$parser->get_token) {
3947: if ($token->[0] eq 'S') {
3948: if ($token->[1] eq 'a') {
3949: if ($token->[2]->{'href'}) {
3950: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3951: }
3952: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3953: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3954: } elsif ($token->[1] eq 'base') {
3955: $thisdir=$token->[2]->{'href'};
3956: }
3957: }
3958: }
3959: $thisdir=~s-/[^/]*$--;
1.356 albertel 3960: foreach my $link (@rlinks) {
1.726 raeburn 3961: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3962: ($link=~/^\//) ||
3963: ($link=~/^javascript:/i) ||
3964: ($link=~/^mailto:/i) ||
3965: ($link=~/^\#/)) {
3966: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3967: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3968: }
3969: }
3970: # -------------------------------------------------- Deal with Applet codebases
3971: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3972: return $output;
3973: }
3974:
1.112 bowersj2 3975: =pod
3976:
1.648 raeburn 3977: =item * &get_student_view()
1.112 bowersj2 3978:
3979: show a snapshot of what student was looking at
3980:
3981: =cut
3982:
1.10 albertel 3983: sub get_student_view {
1.186 albertel 3984: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3985: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3986: my (%form);
1.10 albertel 3987: my @elements=('symb','courseid','domain','username');
3988: foreach my $element (@elements) {
1.186 albertel 3989: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3990: }
1.186 albertel 3991: if (defined($moreenv)) {
3992: %form=(%form,%{$moreenv});
3993: }
1.236 albertel 3994: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3995: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3996: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3997: $userview=~s/\<body[^\>]*\>//gi;
3998: $userview=~s/\<\/body\>//gi;
3999: $userview=~s/\<html\>//gi;
4000: $userview=~s/\<\/html\>//gi;
4001: $userview=~s/\<head\>//gi;
4002: $userview=~s/\<\/head\>//gi;
4003: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4004: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4005: if (wantarray) {
4006: return ($userview,$response);
4007: } else {
4008: return $userview;
4009: }
4010: }
4011:
4012: sub get_student_view_with_retries {
4013: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4014:
4015: my $ok = 0; # True if we got a good response.
4016: my $content;
4017: my $response;
4018:
4019: # Try to get the student_view done. within the retries count:
4020:
4021: do {
4022: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4023: $ok = $response->is_success;
4024: if (!$ok) {
4025: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4026: }
4027: $retries--;
4028: } while (!$ok && ($retries > 0));
4029:
4030: if (!$ok) {
4031: $content = ''; # On error return an empty content.
4032: }
1.651 www 4033: if (wantarray) {
4034: return ($content, $response);
4035: } else {
4036: return $content;
4037: }
1.11 albertel 4038: }
4039:
1.112 bowersj2 4040: =pod
4041:
1.648 raeburn 4042: =item * &get_student_answers()
1.112 bowersj2 4043:
4044: show a snapshot of how student was answering problem
4045:
4046: =cut
4047:
1.11 albertel 4048: sub get_student_answers {
1.100 sakharuk 4049: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4050: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4051: my (%moreenv);
1.11 albertel 4052: my @elements=('symb','courseid','domain','username');
4053: foreach my $element (@elements) {
1.186 albertel 4054: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4055: }
1.186 albertel 4056: $moreenv{'grade_target'}='answer';
4057: %moreenv=(%form,%moreenv);
1.497 raeburn 4058: $feedurl = &Apache::lonnet::clutter($feedurl);
4059: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4060: return $userview;
1.1 albertel 4061: }
1.116 albertel 4062:
4063: =pod
4064:
4065: =item * &submlink()
4066:
1.242 albertel 4067: Inputs: $text $uname $udom $symb $target
1.116 albertel 4068:
4069: Returns: A link to grades.pm such as to see the SUBM view of a student
4070:
4071: =cut
4072:
4073: ###############################################
4074: sub submlink {
1.242 albertel 4075: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4076: if (!($uname && $udom)) {
4077: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4078: &Apache::lonnet::whichuser($symb);
1.116 albertel 4079: if (!$symb) { $symb=$cursymb; }
4080: }
1.254 matthew 4081: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4082: $symb=&escape($symb);
1.960 bisitz 4083: if ($target) { $target=" target=\"$target\""; }
4084: return
4085: '<a href="/adm/grades?command=submission'.
4086: '&symb='.$symb.
4087: '&student='.$uname.
4088: '&userdom='.$udom.'"'.
4089: $target.'>'.$text.'</a>';
1.242 albertel 4090: }
4091: ##############################################
4092:
4093: =pod
4094:
4095: =item * &pgrdlink()
4096:
4097: Inputs: $text $uname $udom $symb $target
4098:
4099: Returns: A link to grades.pm such as to see the PGRD view of a student
4100:
4101: =cut
4102:
4103: ###############################################
4104: sub pgrdlink {
4105: my $link=&submlink(@_);
4106: $link=~s/(&command=submission)/$1&showgrading=yes/;
4107: return $link;
4108: }
4109: ##############################################
4110:
4111: =pod
4112:
4113: =item * &pprmlink()
4114:
4115: Inputs: $text $uname $udom $symb $target
4116:
4117: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4118: student and a specific resource
1.242 albertel 4119:
4120: =cut
4121:
4122: ###############################################
4123: sub pprmlink {
4124: my ($text,$uname,$udom,$symb,$target)=@_;
4125: if (!($uname && $udom)) {
4126: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4127: &Apache::lonnet::whichuser($symb);
1.242 albertel 4128: if (!$symb) { $symb=$cursymb; }
4129: }
1.254 matthew 4130: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4131: $symb=&escape($symb);
1.242 albertel 4132: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4133: return '<a href="/adm/parmset?command=set&'.
4134: 'symb='.$symb.'&uname='.$uname.
4135: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4136: }
4137: ##############################################
1.37 matthew 4138:
1.112 bowersj2 4139: =pod
4140:
4141: =back
4142:
4143: =cut
4144:
1.37 matthew 4145: ###############################################
1.51 www 4146:
4147:
4148: sub timehash {
1.687 raeburn 4149: my ($thistime) = @_;
4150: my $timezone = &Apache::lonlocal::gettimezone();
4151: my $dt = DateTime->from_epoch(epoch => $thistime)
4152: ->set_time_zone($timezone);
4153: my $wday = $dt->day_of_week();
4154: if ($wday == 7) { $wday = 0; }
4155: return ( 'second' => $dt->second(),
4156: 'minute' => $dt->minute(),
4157: 'hour' => $dt->hour(),
4158: 'day' => $dt->day_of_month(),
4159: 'month' => $dt->month(),
4160: 'year' => $dt->year(),
4161: 'weekday' => $wday,
4162: 'dayyear' => $dt->day_of_year(),
4163: 'dlsav' => $dt->is_dst() );
1.51 www 4164: }
4165:
1.370 www 4166: sub utc_string {
4167: my ($date)=@_;
1.371 www 4168: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4169: }
4170:
1.51 www 4171: sub maketime {
4172: my %th=@_;
1.687 raeburn 4173: my ($epoch_time,$timezone,$dt);
4174: $timezone = &Apache::lonlocal::gettimezone();
4175: eval {
4176: $dt = DateTime->new( year => $th{'year'},
4177: month => $th{'month'},
4178: day => $th{'day'},
4179: hour => $th{'hour'},
4180: minute => $th{'minute'},
4181: second => $th{'second'},
4182: time_zone => $timezone,
4183: );
4184: };
4185: if (!$@) {
4186: $epoch_time = $dt->epoch;
4187: if ($epoch_time) {
4188: return $epoch_time;
4189: }
4190: }
1.51 www 4191: return POSIX::mktime(
4192: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4193: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4194: }
4195:
4196: #########################################
1.51 www 4197:
4198: sub findallcourses {
1.482 raeburn 4199: my ($roles,$uname,$udom) = @_;
1.355 albertel 4200: my %roles;
4201: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4202: my %courses;
1.51 www 4203: my $now=time;
1.482 raeburn 4204: if (!defined($uname)) {
4205: $uname = $env{'user.name'};
4206: }
4207: if (!defined($udom)) {
4208: $udom = $env{'user.domain'};
4209: }
4210: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4211: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4212: if (!%roles) {
4213: %roles = (
4214: cc => 1,
1.907 raeburn 4215: co => 1,
1.482 raeburn 4216: in => 1,
4217: ep => 1,
4218: ta => 1,
4219: cr => 1,
4220: st => 1,
4221: );
4222: }
4223: foreach my $entry (keys(%roleshash)) {
4224: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4225: if ($trole =~ /^cr/) {
4226: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4227: } else {
4228: next if (!exists($roles{$trole}));
4229: }
4230: if ($tend) {
4231: next if ($tend < $now);
4232: }
4233: if ($tstart) {
4234: next if ($tstart > $now);
4235: }
1.1058 raeburn 4236: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4237: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4238: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4239: if ($secpart eq '') {
4240: ($cnum,$role) = split(/_/,$cnumpart);
4241: $sec = 'none';
1.1058 raeburn 4242: $value .= $cnum.'/';
1.482 raeburn 4243: } else {
4244: $cnum = $cnumpart;
4245: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4246: $value .= $cnum.'/'.$sec;
4247: }
4248: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4249: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4250: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4251: }
4252: } else {
4253: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4254: }
1.482 raeburn 4255: }
4256: } else {
4257: foreach my $key (keys(%env)) {
1.483 albertel 4258: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4259: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4260: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4261: next if ($role eq 'ca' || $role eq 'aa');
4262: next if (%roles && !exists($roles{$role}));
4263: my ($starttime,$endtime)=split(/\./,$env{$key});
4264: my $active=1;
4265: if ($starttime) {
4266: if ($now<$starttime) { $active=0; }
4267: }
4268: if ($endtime) {
4269: if ($now>$endtime) { $active=0; }
4270: }
4271: if ($active) {
1.1058 raeburn 4272: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4273: if ($sec eq '') {
4274: $sec = 'none';
1.1058 raeburn 4275: } else {
4276: $value .= $sec;
4277: }
4278: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4279: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4280: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4281: }
4282: } else {
4283: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4284: }
1.474 raeburn 4285: }
4286: }
1.51 www 4287: }
4288: }
1.474 raeburn 4289: return %courses;
1.51 www 4290: }
1.37 matthew 4291:
1.54 www 4292: ###############################################
1.474 raeburn 4293:
4294: sub blockcheck {
1.1062 raeburn 4295: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4296:
4297: if (!defined($udom)) {
4298: $udom = $env{'user.domain'};
4299: }
4300: if (!defined($uname)) {
4301: $uname = $env{'user.name'};
4302: }
4303:
4304: # If uname and udom are for a course, check for blocks in the course.
4305:
4306: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4307: my ($startblock,$endblock,$triggerblock) =
4308: &get_blocks($setters,$activity,$udom,$uname,$url);
4309: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4310: }
1.474 raeburn 4311:
1.502 raeburn 4312: my $startblock = 0;
4313: my $endblock = 0;
1.1062 raeburn 4314: my $triggerblock = '';
1.482 raeburn 4315: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4316:
1.490 raeburn 4317: # If uname is for a user, and activity is course-specific, i.e.,
4318: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4319:
1.490 raeburn 4320: if (($activity eq 'boards' || $activity eq 'chat' ||
4321: $activity eq 'groups') && ($env{'request.course.id'})) {
4322: foreach my $key (keys(%live_courses)) {
4323: if ($key ne $env{'request.course.id'}) {
4324: delete($live_courses{$key});
4325: }
4326: }
4327: }
4328:
4329: my $otheruser = 0;
4330: my %own_courses;
4331: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4332: # Resource belongs to user other than current user.
4333: $otheruser = 1;
4334: # Gather courses for current user
4335: %own_courses =
4336: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4337: }
4338:
4339: # Gather active course roles - course coordinator, instructor,
4340: # exam proctor, ta, student, or custom role.
1.474 raeburn 4341:
4342: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4343: my ($cdom,$cnum);
4344: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4345: $cdom = $env{'course.'.$course.'.domain'};
4346: $cnum = $env{'course.'.$course.'.num'};
4347: } else {
1.490 raeburn 4348: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4349: }
4350: my $no_ownblock = 0;
4351: my $no_userblock = 0;
1.533 raeburn 4352: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4353: # Check if current user has 'evb' priv for this
4354: if (defined($own_courses{$course})) {
4355: foreach my $sec (keys(%{$own_courses{$course}})) {
4356: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4357: if ($sec ne 'none') {
4358: $checkrole .= '/'.$sec;
4359: }
4360: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4361: $no_ownblock = 1;
4362: last;
4363: }
4364: }
4365: }
4366: # if they have 'evb' priv and are currently not playing student
4367: next if (($no_ownblock) &&
4368: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4369: }
1.474 raeburn 4370: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4371: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4372: if ($sec ne 'none') {
1.482 raeburn 4373: $checkrole .= '/'.$sec;
1.474 raeburn 4374: }
1.490 raeburn 4375: if ($otheruser) {
4376: # Resource belongs to user other than current user.
4377: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4378: my (%allroles,%userroles);
4379: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4380: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4381: my ($trole,$tdom,$tnum,$tsec);
4382: if ($entry =~ /^cr/) {
4383: ($trole,$tdom,$tnum,$tsec) =
4384: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4385: } else {
4386: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4387: }
4388: my ($spec,$area,$trest);
4389: $area = '/'.$tdom.'/'.$tnum;
4390: $trest = $tnum;
4391: if ($tsec ne '') {
4392: $area .= '/'.$tsec;
4393: $trest .= '/'.$tsec;
4394: }
4395: $spec = $trole.'.'.$area;
4396: if ($trole =~ /^cr/) {
4397: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4398: $tdom,$spec,$trest,$area);
4399: } else {
4400: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4401: $tdom,$spec,$trest,$area);
4402: }
4403: }
4404: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4405: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4406: if ($1) {
4407: $no_userblock = 1;
4408: last;
4409: }
1.486 raeburn 4410: }
4411: }
1.490 raeburn 4412: } else {
4413: # Resource belongs to current user
4414: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4415: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4416: $no_ownblock = 1;
4417: last;
4418: }
1.474 raeburn 4419: }
4420: }
4421: # if they have the evb priv and are currently not playing student
1.482 raeburn 4422: next if (($no_ownblock) &&
1.491 albertel 4423: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4424: next if ($no_userblock);
1.474 raeburn 4425:
1.866 kalberla 4426: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4427: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4428:
1.1062 raeburn 4429: my ($start,$end,$trigger) =
4430: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4431: if (($start != 0) &&
4432: (($startblock == 0) || ($startblock > $start))) {
4433: $startblock = $start;
1.1062 raeburn 4434: if ($trigger ne '') {
4435: $triggerblock = $trigger;
4436: }
1.502 raeburn 4437: }
4438: if (($end != 0) &&
4439: (($endblock == 0) || ($endblock < $end))) {
4440: $endblock = $end;
1.1062 raeburn 4441: if ($trigger ne '') {
4442: $triggerblock = $trigger;
4443: }
1.502 raeburn 4444: }
1.490 raeburn 4445: }
1.1062 raeburn 4446: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4447: }
4448:
4449: sub get_blocks {
1.1062 raeburn 4450: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4451: my $startblock = 0;
4452: my $endblock = 0;
1.1062 raeburn 4453: my $triggerblock = '';
1.490 raeburn 4454: my $course = $cdom.'_'.$cnum;
4455: $setters->{$course} = {};
4456: $setters->{$course}{'staff'} = [];
4457: $setters->{$course}{'times'} = [];
1.1062 raeburn 4458: $setters->{$course}{'triggers'} = [];
4459: my (@blockers,%triggered);
4460: my $now = time;
4461: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4462: if ($activity eq 'docs') {
4463: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4464: foreach my $block (@blockers) {
4465: if ($block =~ /^firstaccess____(.+)$/) {
4466: my $item = $1;
4467: my $type = 'map';
4468: my $timersymb = $item;
4469: if ($item eq 'course') {
4470: $type = 'course';
4471: } elsif ($item =~ /___\d+___/) {
4472: $type = 'resource';
4473: } else {
4474: $timersymb = &Apache::lonnet::symbread($item);
4475: }
4476: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4477: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4478: $triggered{$block} = {
4479: start => $start,
4480: end => $end,
4481: type => $type,
4482: };
4483: }
4484: }
4485: } else {
4486: foreach my $block (keys(%commblocks)) {
4487: if ($block =~ m/^(\d+)____(\d+)$/) {
4488: my ($start,$end) = ($1,$2);
4489: if ($start <= time && $end >= time) {
4490: if (ref($commblocks{$block}) eq 'HASH') {
4491: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4492: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4493: unless(grep(/^\Q$block\E$/,@blockers)) {
4494: push(@blockers,$block);
4495: }
4496: }
4497: }
4498: }
4499: }
4500: } elsif ($block =~ /^firstaccess____(.+)$/) {
4501: my $item = $1;
4502: my $timersymb = $item;
4503: my $type = 'map';
4504: if ($item eq 'course') {
4505: $type = 'course';
4506: } elsif ($item =~ /___\d+___/) {
4507: $type = 'resource';
4508: } else {
4509: $timersymb = &Apache::lonnet::symbread($item);
4510: }
4511: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4512: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4513: if ($start && $end) {
4514: if (($start <= time) && ($end >= time)) {
4515: unless (grep(/^\Q$block\E$/,@blockers)) {
4516: push(@blockers,$block);
4517: $triggered{$block} = {
4518: start => $start,
4519: end => $end,
4520: type => $type,
4521: };
4522: }
4523: }
1.490 raeburn 4524: }
1.1062 raeburn 4525: }
4526: }
4527: }
4528: foreach my $blocker (@blockers) {
4529: my ($staff_name,$staff_dom,$title,$blocks) =
4530: &parse_block_record($commblocks{$blocker});
4531: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4532: my ($start,$end,$triggertype);
4533: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4534: ($start,$end) = ($1,$2);
4535: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4536: $start = $triggered{$blocker}{'start'};
4537: $end = $triggered{$blocker}{'end'};
4538: $triggertype = $triggered{$blocker}{'type'};
4539: }
4540: if ($start) {
4541: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4542: if ($triggertype) {
4543: push(@{$$setters{$course}{'triggers'}},$triggertype);
4544: } else {
4545: push(@{$$setters{$course}{'triggers'}},0);
4546: }
4547: if ( ($startblock == 0) || ($startblock > $start) ) {
4548: $startblock = $start;
4549: if ($triggertype) {
4550: $triggerblock = $blocker;
1.474 raeburn 4551: }
4552: }
1.1062 raeburn 4553: if ( ($endblock == 0) || ($endblock < $end) ) {
4554: $endblock = $end;
4555: if ($triggertype) {
4556: $triggerblock = $blocker;
4557: }
4558: }
1.474 raeburn 4559: }
4560: }
1.1062 raeburn 4561: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4562: }
4563:
4564: sub parse_block_record {
4565: my ($record) = @_;
4566: my ($setuname,$setudom,$title,$blocks);
4567: if (ref($record) eq 'HASH') {
4568: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4569: $title = &unescape($record->{'event'});
4570: $blocks = $record->{'blocks'};
4571: } else {
4572: my @data = split(/:/,$record,3);
4573: if (scalar(@data) eq 2) {
4574: $title = $data[1];
4575: ($setuname,$setudom) = split(/@/,$data[0]);
4576: } else {
4577: ($setuname,$setudom,$title) = @data;
4578: }
4579: $blocks = { 'com' => 'on' };
4580: }
4581: return ($setuname,$setudom,$title,$blocks);
4582: }
4583:
1.854 kalberla 4584: sub blocking_status {
1.1062 raeburn 4585: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4586: my %setters;
1.890 droeschl 4587:
1.1061 raeburn 4588: # check for active blocking
1.1062 raeburn 4589: my ($startblock,$endblock,$triggerblock) =
4590: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4591: my $blocked = 0;
4592: if ($startblock && $endblock) {
4593: $blocked = 1;
4594: }
1.890 droeschl 4595:
1.1061 raeburn 4596: # caller just wants to know whether a block is active
4597: if (!wantarray) { return $blocked; }
4598:
4599: # build a link to a popup window containing the details
4600: my $querystring = "?activity=$activity";
4601: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4602: if ($activity eq 'port') {
4603: $querystring .= "&udom=$udom" if $udom;
4604: $querystring .= "&uname=$uname" if $uname;
4605: } elsif ($activity eq 'docs') {
4606: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4607: }
1.1061 raeburn 4608:
4609: my $output .= <<'END_MYBLOCK';
4610: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4611: var options = "width=" + w + ",height=" + h + ",";
4612: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4613: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4614: var newWin = window.open(url, wdwName, options);
4615: newWin.focus();
4616: }
1.890 droeschl 4617: END_MYBLOCK
1.854 kalberla 4618:
1.1061 raeburn 4619: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4620:
1.1061 raeburn 4621: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4622: my $text = &mt('Communication Blocked');
4623: if ($activity eq 'docs') {
4624: $text = &mt('Content Access Blocked');
1.1063 raeburn 4625: } elsif ($activity eq 'printout') {
4626: $text = &mt('Printing Blocked');
1.1062 raeburn 4627: }
1.1061 raeburn 4628: $output .= <<"END_BLOCK";
1.867 kalberla 4629: <div class='LC_comblock'>
1.869 kalberla 4630: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4631: title='$text'>
4632: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4633: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4634: title='$text'>$text</a>
1.867 kalberla 4635: </div>
4636:
4637: END_BLOCK
1.474 raeburn 4638:
1.1061 raeburn 4639: return ($blocked, $output);
1.854 kalberla 4640: }
1.490 raeburn 4641:
1.60 matthew 4642: ###############################################
4643:
1.682 raeburn 4644: sub check_ip_acc {
4645: my ($acc)=@_;
4646: &Apache::lonxml::debug("acc is $acc");
4647: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4648: return 1;
4649: }
4650: my $allowed=0;
4651: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4652:
4653: my $name;
4654: foreach my $pattern (split(',',$acc)) {
4655: $pattern =~ s/^\s*//;
4656: $pattern =~ s/\s*$//;
4657: if ($pattern =~ /\*$/) {
4658: #35.8.*
4659: $pattern=~s/\*//;
4660: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4661: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4662: #35.8.3.[34-56]
4663: my $low=$2;
4664: my $high=$3;
4665: $pattern=$1;
4666: if ($ip =~ /^\Q$pattern\E/) {
4667: my $last=(split(/\./,$ip))[3];
4668: if ($last <=$high && $last >=$low) { $allowed=1; }
4669: }
4670: } elsif ($pattern =~ /^\*/) {
4671: #*.msu.edu
4672: $pattern=~s/\*//;
4673: if (!defined($name)) {
4674: use Socket;
4675: my $netaddr=inet_aton($ip);
4676: ($name)=gethostbyaddr($netaddr,AF_INET);
4677: }
4678: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4679: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4680: #127.0.0.1
4681: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4682: } else {
4683: #some.name.com
4684: if (!defined($name)) {
4685: use Socket;
4686: my $netaddr=inet_aton($ip);
4687: ($name)=gethostbyaddr($netaddr,AF_INET);
4688: }
4689: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4690: }
4691: if ($allowed) { last; }
4692: }
4693: return $allowed;
4694: }
4695:
4696: ###############################################
4697:
1.60 matthew 4698: =pod
4699:
1.112 bowersj2 4700: =head1 Domain Template Functions
4701:
4702: =over 4
4703:
4704: =item * &determinedomain()
1.60 matthew 4705:
4706: Inputs: $domain (usually will be undef)
4707:
1.63 www 4708: Returns: Determines which domain should be used for designs
1.60 matthew 4709:
4710: =cut
1.54 www 4711:
1.60 matthew 4712: ###############################################
1.63 www 4713: sub determinedomain {
4714: my $domain=shift;
1.531 albertel 4715: if (! $domain) {
1.60 matthew 4716: # Determine domain if we have not been given one
1.893 raeburn 4717: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4718: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4719: if ($env{'request.role.domain'}) {
4720: $domain=$env{'request.role.domain'};
1.60 matthew 4721: }
4722: }
1.63 www 4723: return $domain;
4724: }
4725: ###############################################
1.517 raeburn 4726:
1.518 albertel 4727: sub devalidate_domconfig_cache {
4728: my ($udom)=@_;
4729: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4730: }
4731:
4732: # ---------------------- Get domain configuration for a domain
4733: sub get_domainconf {
4734: my ($udom) = @_;
4735: my $cachetime=1800;
4736: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4737: if (defined($cached)) { return %{$result}; }
4738:
4739: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4740: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4741: my (%designhash,%legacy);
1.518 albertel 4742: if (keys(%domconfig) > 0) {
4743: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4744: if (keys(%{$domconfig{'login'}})) {
4745: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4746: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4747: if ($key eq 'loginvia') {
4748: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4749: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4750: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4751: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4752: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4753: $designhash{$udom.'.login.loginvia'} = $server;
4754: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4755:
4756: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4757: } else {
1.1013 raeburn 4758: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4759: }
4760: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4761: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4762: }
1.946 raeburn 4763: }
4764: }
4765: }
4766: }
4767: } else {
4768: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4769: $designhash{$udom.'.login.'.$key.'_'.$img} =
4770: $domconfig{'login'}{$key}{$img};
4771: }
1.699 raeburn 4772: }
4773: } else {
4774: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4775: }
1.632 raeburn 4776: }
4777: } else {
4778: $legacy{'login'} = 1;
1.518 albertel 4779: }
1.632 raeburn 4780: } else {
4781: $legacy{'login'} = 1;
1.518 albertel 4782: }
4783: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4784: if (keys(%{$domconfig{'rolecolors'}})) {
4785: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4786: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4787: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4788: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4789: }
1.518 albertel 4790: }
4791: }
1.632 raeburn 4792: } else {
4793: $legacy{'rolecolors'} = 1;
1.518 albertel 4794: }
1.632 raeburn 4795: } else {
4796: $legacy{'rolecolors'} = 1;
1.518 albertel 4797: }
1.948 raeburn 4798: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4799: if ($domconfig{'autoenroll'}{'co-owners'}) {
4800: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4801: }
4802: }
1.632 raeburn 4803: if (keys(%legacy) > 0) {
4804: my %legacyhash = &get_legacy_domconf($udom);
4805: foreach my $item (keys(%legacyhash)) {
4806: if ($item =~ /^\Q$udom\E\.login/) {
4807: if ($legacy{'login'}) {
4808: $designhash{$item} = $legacyhash{$item};
4809: }
4810: } else {
4811: if ($legacy{'rolecolors'}) {
4812: $designhash{$item} = $legacyhash{$item};
4813: }
1.518 albertel 4814: }
4815: }
4816: }
1.632 raeburn 4817: } else {
4818: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4819: }
4820: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4821: $cachetime);
4822: return %designhash;
4823: }
4824:
1.632 raeburn 4825: sub get_legacy_domconf {
4826: my ($udom) = @_;
4827: my %legacyhash;
4828: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4829: my $designfile = $designdir.'/'.$udom.'.tab';
4830: if (-e $designfile) {
4831: if ( open (my $fh,"<$designfile") ) {
4832: while (my $line = <$fh>) {
4833: next if ($line =~ /^\#/);
4834: chomp($line);
4835: my ($key,$val)=(split(/\=/,$line));
4836: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4837: }
4838: close($fh);
4839: }
4840: }
1.1026 raeburn 4841: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4842: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4843: }
4844: return %legacyhash;
4845: }
4846:
1.63 www 4847: =pod
4848:
1.112 bowersj2 4849: =item * &domainlogo()
1.63 www 4850:
4851: Inputs: $domain (usually will be undef)
4852:
4853: Returns: A link to a domain logo, if the domain logo exists.
4854: If the domain logo does not exist, a description of the domain.
4855:
4856: =cut
1.112 bowersj2 4857:
1.63 www 4858: ###############################################
4859: sub domainlogo {
1.517 raeburn 4860: my $domain = &determinedomain(shift);
1.518 albertel 4861: my %designhash = &get_domainconf($domain);
1.517 raeburn 4862: # See if there is a logo
4863: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4864: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4865: if ($imgsrc =~ m{^/(adm|res)/}) {
4866: if ($imgsrc =~ m{^/res/}) {
4867: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4868: &Apache::lonnet::repcopy($local_name);
4869: }
4870: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4871: }
4872: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4873: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4874: return &Apache::lonnet::domain($domain,'description');
1.59 www 4875: } else {
1.60 matthew 4876: return '';
1.59 www 4877: }
4878: }
1.63 www 4879: ##############################################
4880:
4881: =pod
4882:
1.112 bowersj2 4883: =item * &designparm()
1.63 www 4884:
4885: Inputs: $which parameter; $domain (usually will be undef)
4886:
4887: Returns: value of designparamter $which
4888:
4889: =cut
1.112 bowersj2 4890:
1.397 albertel 4891:
1.400 albertel 4892: ##############################################
1.397 albertel 4893: sub designparm {
4894: my ($which,$domain)=@_;
4895: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4896: return $env{'environment.color.'.$which};
1.96 www 4897: }
1.63 www 4898: $domain=&determinedomain($domain);
1.1016 raeburn 4899: my %domdesign;
4900: unless ($domain eq 'public') {
4901: %domdesign = &get_domainconf($domain);
4902: }
1.520 raeburn 4903: my $output;
1.517 raeburn 4904: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4905: $output = $domdesign{$domain.'.'.$which};
1.63 www 4906: } else {
1.520 raeburn 4907: $output = $defaultdesign{$which};
4908: }
4909: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4910: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4911: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4912: if ($output =~ m{^/res/}) {
4913: my $local_name = &Apache::lonnet::filelocation('',$output);
4914: &Apache::lonnet::repcopy($local_name);
4915: }
1.520 raeburn 4916: $output = &lonhttpdurl($output);
4917: }
1.63 www 4918: }
1.520 raeburn 4919: return $output;
1.63 www 4920: }
1.59 www 4921:
1.822 bisitz 4922: ##############################################
4923: =pod
4924:
1.832 bisitz 4925: =item * &authorspace()
4926:
1.1028 raeburn 4927: Inputs: $url (usually will be undef).
1.832 bisitz 4928:
1.1028 raeburn 4929: Returns: Path to Construction Space containing the resource or
4930: directory being viewed (or for which action is being taken).
4931: If $url is provided, and begins /priv/<domain>/<uname>
4932: the path will be that portion of the $context argument.
4933: Otherwise the path will be for the author space of the current
4934: user when the current role is author, or for that of the
4935: co-author/assistant co-author space when the current role
4936: is co-author or assistant co-author.
1.832 bisitz 4937:
4938: =cut
4939:
4940: sub authorspace {
1.1028 raeburn 4941: my ($url) = @_;
4942: if ($url ne '') {
4943: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4944: return $1;
4945: }
4946: }
1.832 bisitz 4947: my $caname = '';
1.1024 www 4948: my $cadom = '';
1.1028 raeburn 4949: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4950: ($cadom,$caname) =
1.832 bisitz 4951: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4952: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4953: $caname = $env{'user.name'};
1.1024 www 4954: $cadom = $env{'user.domain'};
1.832 bisitz 4955: }
1.1028 raeburn 4956: if (($caname ne '') && ($cadom ne '')) {
4957: return "/priv/$cadom/$caname/";
4958: }
4959: return;
1.832 bisitz 4960: }
4961:
4962: ##############################################
4963: =pod
4964:
1.822 bisitz 4965: =item * &head_subbox()
4966:
4967: Inputs: $content (contains HTML code with page functions, etc.)
4968:
4969: Returns: HTML div with $content
4970: To be included in page header
4971:
4972: =cut
4973:
4974: sub head_subbox {
4975: my ($content)=@_;
4976: my $output =
1.993 raeburn 4977: '<div class="LC_head_subbox">'
1.822 bisitz 4978: .$content
4979: .'</div>'
4980: }
4981:
4982: ##############################################
4983: =pod
4984:
4985: =item * &CSTR_pageheader()
4986:
1.1026 raeburn 4987: Input: (optional) filename from which breadcrumb trail is built.
4988: In most cases no input as needed, as $env{'request.filename'}
4989: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4990:
4991: Returns: HTML div with CSTR path and recent box
4992: To be included on Construction Space pages
4993:
4994: =cut
4995:
4996: sub CSTR_pageheader {
1.1026 raeburn 4997: my ($trailfile) = @_;
4998: if ($trailfile eq '') {
4999: $trailfile = $env{'request.filename'};
5000: }
5001:
5002: # this is for resources; directories have customtitle, and crumbs
5003: # and select recent are created in lonpubdir.pm
5004:
5005: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5006: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5007: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5008: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5009: $formaction =~ s{/+}{/}g;
1.822 bisitz 5010:
5011: my $parentpath = '';
5012: my $lastitem = '';
5013: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5014: $parentpath = $1;
5015: $lastitem = $2;
5016: } else {
5017: $lastitem = $thisdisfn;
5018: }
1.921 bisitz 5019:
5020: my $output =
1.822 bisitz 5021: '<div>'
5022: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
5023: .'<b>'.&mt('Construction Space:').'</b> '
5024: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5025: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5026: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5027:
5028: if ($lastitem) {
5029: $output .=
5030: '<span class="LC_filename">'
5031: .$lastitem
5032: .'</span>';
5033: }
5034: $output .=
5035: '<br />'
1.822 bisitz 5036: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5037: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5038: .'</form>'
5039: .&Apache::lonmenu::constspaceform()
5040: .'</div>';
1.921 bisitz 5041:
5042: return $output;
1.822 bisitz 5043: }
5044:
1.60 matthew 5045: ###############################################
5046: ###############################################
5047:
5048: =pod
5049:
1.112 bowersj2 5050: =back
5051:
1.549 albertel 5052: =head1 HTML Helpers
1.112 bowersj2 5053:
5054: =over 4
5055:
5056: =item * &bodytag()
1.60 matthew 5057:
5058: Returns a uniform header for LON-CAPA web pages.
5059:
5060: Inputs:
5061:
1.112 bowersj2 5062: =over 4
5063:
5064: =item * $title, A title to be displayed on the page.
5065:
5066: =item * $function, the current role (can be undef).
5067:
5068: =item * $addentries, extra parameters for the <body> tag.
5069:
5070: =item * $bodyonly, if defined, only return the <body> tag.
5071:
5072: =item * $domain, if defined, force a given domain.
5073:
5074: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5075: text interface only)
1.60 matthew 5076:
1.814 bisitz 5077: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5078: navigational links
1.317 albertel 5079:
1.338 albertel 5080: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5081:
1.460 albertel 5082: =item * $args, optional argument valid values are
5083: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5084: inherit_jsmath -> when creating popup window in a page,
5085: should it have jsmath forced on by the
5086: current page
1.460 albertel 5087:
1.1096 raeburn 5088: =item * $advtoolsref, optional argument, ref to an array containing
5089: inlineremote items to be added in "Functions" menu below
5090: breadcrumbs.
5091:
1.112 bowersj2 5092: =back
5093:
1.60 matthew 5094: Returns: A uniform header for LON-CAPA web pages.
5095: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5096: If $bodyonly is undef or zero, an html string containing a <body> tag and
5097: other decorations will be returned.
5098:
5099: =cut
5100:
1.54 www 5101: sub bodytag {
1.831 bisitz 5102: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5103: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5104:
1.954 raeburn 5105: my $public;
5106: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5107: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5108: $public = 1;
5109: }
1.460 albertel 5110: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5111:
1.183 matthew 5112: $function = &get_users_function() if (!$function);
1.339 albertel 5113: my $img = &designparm($function.'.img',$domain);
5114: my $font = &designparm($function.'.font',$domain);
5115: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5116:
1.803 bisitz 5117: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5118: 'bgcolor' => $pgbg,
1.339 albertel 5119: 'text' => $font,
5120: 'alink' => &designparm($function.'.alink',$domain),
5121: 'vlink' => &designparm($function.'.vlink',$domain),
5122: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5123: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5124:
1.63 www 5125: # role and realm
1.378 raeburn 5126: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5127: if ($role eq 'ca') {
1.479 albertel 5128: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5129: $realm = &plainname($rname,$rdom);
1.378 raeburn 5130: }
1.55 www 5131: # realm
1.258 albertel 5132: if ($env{'request.course.id'}) {
1.378 raeburn 5133: if ($env{'request.role'} !~ /^cr/) {
5134: $role = &Apache::lonnet::plaintext($role,&course_type());
5135: }
1.898 raeburn 5136: if ($env{'request.course.sec'}) {
5137: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5138: }
1.359 albertel 5139: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5140: } else {
5141: $role = &Apache::lonnet::plaintext($role);
1.54 www 5142: }
1.433 albertel 5143:
1.359 albertel 5144: if (!$realm) { $realm=' '; }
1.330 albertel 5145:
1.438 albertel 5146: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5147:
1.101 www 5148: # construct main body tag
1.359 albertel 5149: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5150: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5151:
1.530 albertel 5152: if ($bodyonly) {
1.60 matthew 5153: return $bodytag;
1.798 tempelho 5154: }
1.359 albertel 5155:
1.410 albertel 5156: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 5157: if ($public) {
1.433 albertel 5158: undef($role);
1.434 albertel 5159: } else {
1.1070 raeburn 5160: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5161: undef,'LC_menubuttons_link');
1.433 albertel 5162: }
1.359 albertel 5163:
1.762 bisitz 5164: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5165: #
5166: # Extra info if you are the DC
5167: my $dc_info = '';
5168: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5169: $env{'course.'.$env{'request.course.id'}.
5170: '.domain'}.'/'})) {
5171: my $cid = $env{'request.course.id'};
1.917 raeburn 5172: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5173: $dc_info =~ s/\s+$//;
1.359 albertel 5174: }
5175:
1.898 raeburn 5176: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5177: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5178:
1.916 droeschl 5179: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
5180: return $bodytag;
5181: }
1.903 droeschl 5182:
5183: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5184:
5185: # if ($env{'request.state'} eq 'construct') {
5186: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5187: # }
5188:
1.359 albertel 5189:
5190:
1.916 droeschl 5191: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5192: if ($dc_info) {
5193: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5194: }
1.916 droeschl 5195: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
5196: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5197: return $bodytag;
5198: }
1.894 droeschl 5199:
1.927 raeburn 5200: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5201: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
5202: }
1.916 droeschl 5203:
1.903 droeschl 5204: $bodytag .= Apache::lonhtmlcommon::scripttag(
5205: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 5206:
1.903 droeschl 5207: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 5208:
1.917 raeburn 5209: if ($dc_info) {
5210: $dc_info = &dc_courseid_toggle($dc_info);
5211: }
5212: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5213:
1.903 droeschl 5214: #don't show menus for public users
1.954 raeburn 5215: if (!$public){
1.903 droeschl 5216: $bodytag .= Apache::lonmenu::secondary_menu();
5217: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5218: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5219: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5220: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5221: $args->{'bread_crumbs'});
1.1096 raeburn 5222: } elsif ($forcereg) {
5223: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5224: $args->{'group'});
5225: } else {
5226: $bodytag .=
5227: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5228: $forcereg,$args->{'group'},
5229: $args->{'bread_crumbs'},
5230: $advtoolsref);
1.920 raeburn 5231: }
1.903 droeschl 5232: }else{
5233: # this is to seperate menu from content when there's no secondary
5234: # menu. Especially needed for public accessible ressources.
5235: $bodytag .= '<hr style="clear:both" />';
5236: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5237: }
1.903 droeschl 5238:
1.235 raeburn 5239: return $bodytag;
1.182 matthew 5240: }
5241:
1.917 raeburn 5242: sub dc_courseid_toggle {
5243: my ($dc_info) = @_;
1.980 raeburn 5244: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5245: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5246: &mt('(More ...)').'</a></span>'.
5247: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5248: }
5249:
1.330 albertel 5250: sub make_attr_string {
5251: my ($register,$attr_ref) = @_;
5252:
5253: if ($attr_ref && !ref($attr_ref)) {
5254: die("addentries Must be a hash ref ".
5255: join(':',caller(1))." ".
5256: join(':',caller(0))." ");
5257: }
5258:
5259: if ($register) {
1.339 albertel 5260: my ($on_load,$on_unload);
5261: foreach my $key (keys(%{$attr_ref})) {
5262: if (lc($key) eq 'onload') {
5263: $on_load.=$attr_ref->{$key}.';';
5264: delete($attr_ref->{$key});
5265:
5266: } elsif (lc($key) eq 'onunload') {
5267: $on_unload.=$attr_ref->{$key}.';';
5268: delete($attr_ref->{$key});
5269: }
5270: }
1.953 droeschl 5271: $attr_ref->{'onload'} = $on_load;
5272: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5273: }
1.339 albertel 5274:
1.330 albertel 5275: my $attr_string;
5276: foreach my $attr (keys(%$attr_ref)) {
5277: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5278: }
5279: return $attr_string;
5280: }
5281:
5282:
1.182 matthew 5283: ###############################################
1.251 albertel 5284: ###############################################
5285:
5286: =pod
5287:
5288: =item * &endbodytag()
5289:
5290: Returns a uniform footer for LON-CAPA web pages.
5291:
1.635 raeburn 5292: Inputs: 1 - optional reference to an args hash
5293: If in the hash, key for noredirectlink has a value which evaluates to true,
5294: a 'Continue' link is not displayed if the page contains an
5295: internal redirect in the <head></head> section,
5296: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5297:
5298: =cut
5299:
5300: sub endbodytag {
1.635 raeburn 5301: my ($args) = @_;
1.1080 raeburn 5302: my $endbodytag;
5303: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5304: $endbodytag='</body>';
5305: }
1.269 albertel 5306: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5307: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5308: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5309: $endbodytag=
5310: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5311: &mt('Continue').'</a>'.
5312: $endbodytag;
5313: }
1.315 albertel 5314: }
1.251 albertel 5315: return $endbodytag;
5316: }
5317:
1.352 albertel 5318: =pod
5319:
5320: =item * &standard_css()
5321:
5322: Returns a style sheet
5323:
5324: Inputs: (all optional)
5325: domain -> force to color decorate a page for a specific
5326: domain
5327: function -> force usage of a specific rolish color scheme
5328: bgcolor -> override the default page bgcolor
5329:
5330: =cut
5331:
1.343 albertel 5332: sub standard_css {
1.345 albertel 5333: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5334: $function = &get_users_function() if (!$function);
5335: my $img = &designparm($function.'.img', $domain);
5336: my $tabbg = &designparm($function.'.tabbg', $domain);
5337: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5338: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5339: #second colour for later usage
1.345 albertel 5340: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5341: my $pgbg_or_bgcolor =
5342: $bgcolor ||
1.352 albertel 5343: &designparm($function.'.pgbg', $domain);
1.382 albertel 5344: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5345: my $alink = &designparm($function.'.alink', $domain);
5346: my $vlink = &designparm($function.'.vlink', $domain);
5347: my $link = &designparm($function.'.link', $domain);
5348:
1.602 albertel 5349: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5350: my $mono = 'monospace';
1.850 bisitz 5351: my $data_table_head = $sidebg;
5352: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5353: my $data_table_dark = '#E0E0E0';
1.470 banghart 5354: my $data_table_darker = '#CCCCCC';
1.349 albertel 5355: my $data_table_highlight = '#FFFF00';
1.352 albertel 5356: my $mail_new = '#FFBB77';
5357: my $mail_new_hover = '#DD9955';
5358: my $mail_read = '#BBBB77';
5359: my $mail_read_hover = '#999944';
5360: my $mail_replied = '#AAAA88';
5361: my $mail_replied_hover = '#888855';
5362: my $mail_other = '#99BBBB';
5363: my $mail_other_hover = '#669999';
1.391 albertel 5364: my $table_header = '#DDDDDD';
1.489 raeburn 5365: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5366: my $lg_border_color = '#C8C8C8';
1.952 onken 5367: my $button_hover = '#BF2317';
1.392 albertel 5368:
1.608 albertel 5369: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5370: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5371: : '0 3px 0 4px';
1.448 albertel 5372:
1.523 albertel 5373:
1.343 albertel 5374: return <<END;
1.947 droeschl 5375:
5376: /* needed for iframe to allow 100% height in FF */
5377: body, html {
5378: margin: 0;
5379: padding: 0 0.5%;
5380: height: 99%; /* to avoid scrollbars */
5381: }
5382:
1.795 www 5383: body {
1.911 bisitz 5384: font-family: $sans;
5385: line-height:130%;
5386: font-size:0.83em;
5387: color:$font;
1.795 www 5388: }
5389:
1.959 onken 5390: a:focus,
5391: a:focus img {
1.795 www 5392: color: red;
5393: }
1.698 harmsja 5394:
1.911 bisitz 5395: form, .inline {
5396: display: inline;
1.795 www 5397: }
1.721 harmsja 5398:
1.795 www 5399: .LC_right {
1.911 bisitz 5400: text-align:right;
1.795 www 5401: }
5402:
5403: .LC_middle {
1.911 bisitz 5404: vertical-align:middle;
1.795 www 5405: }
1.721 harmsja 5406:
1.911 bisitz 5407: .LC_400Box {
5408: width:400px;
5409: }
1.721 harmsja 5410:
1.947 droeschl 5411: .LC_iframecontainer {
5412: width: 98%;
5413: margin: 0;
5414: position: fixed;
5415: top: 8.5em;
5416: bottom: 0;
5417: }
5418:
5419: .LC_iframecontainer iframe{
5420: border: none;
5421: width: 100%;
5422: height: 100%;
5423: }
5424:
1.778 bisitz 5425: .LC_filename {
5426: font-family: $mono;
5427: white-space:pre;
1.921 bisitz 5428: font-size: 120%;
1.778 bisitz 5429: }
5430:
5431: .LC_fileicon {
5432: border: none;
5433: height: 1.3em;
5434: vertical-align: text-bottom;
5435: margin-right: 0.3em;
5436: text-decoration:none;
5437: }
5438:
1.1008 www 5439: .LC_setting {
5440: text-decoration:underline;
5441: }
5442:
1.350 albertel 5443: .LC_error {
5444: color: red;
5445: }
1.795 www 5446:
1.1097 bisitz 5447: .LC_warning {
5448: color: darkorange;
5449: }
5450:
1.457 albertel 5451: .LC_diff_removed {
1.733 bisitz 5452: color: red;
1.394 albertel 5453: }
1.532 albertel 5454:
5455: .LC_info,
1.457 albertel 5456: .LC_success,
5457: .LC_diff_added {
1.350 albertel 5458: color: green;
5459: }
1.795 www 5460:
1.802 bisitz 5461: div.LC_confirm_box {
5462: background-color: #FAFAFA;
5463: border: 1px solid $lg_border_color;
5464: margin-right: 0;
5465: padding: 5px;
5466: }
5467:
5468: div.LC_confirm_box .LC_error img,
5469: div.LC_confirm_box .LC_success img {
5470: vertical-align: middle;
5471: }
5472:
1.440 albertel 5473: .LC_icon {
1.771 droeschl 5474: border: none;
1.790 droeschl 5475: vertical-align: middle;
1.771 droeschl 5476: }
5477:
1.543 albertel 5478: .LC_docs_spacer {
5479: width: 25px;
5480: height: 1px;
1.771 droeschl 5481: border: none;
1.543 albertel 5482: }
1.346 albertel 5483:
1.532 albertel 5484: .LC_internal_info {
1.735 bisitz 5485: color: #999999;
1.532 albertel 5486: }
5487:
1.794 www 5488: .LC_discussion {
1.1050 www 5489: background: $data_table_dark;
1.911 bisitz 5490: border: 1px solid black;
5491: margin: 2px;
1.794 www 5492: }
5493:
5494: .LC_disc_action_left {
1.1050 www 5495: background: $sidebg;
1.911 bisitz 5496: text-align: left;
1.1050 www 5497: padding: 4px;
5498: margin: 2px;
1.794 www 5499: }
5500:
5501: .LC_disc_action_right {
1.1050 www 5502: background: $sidebg;
1.911 bisitz 5503: text-align: right;
1.1050 www 5504: padding: 4px;
5505: margin: 2px;
1.794 www 5506: }
5507:
5508: .LC_disc_new_item {
1.911 bisitz 5509: background: white;
5510: border: 2px solid red;
1.1050 www 5511: margin: 4px;
5512: padding: 4px;
1.794 www 5513: }
5514:
5515: .LC_disc_old_item {
1.911 bisitz 5516: background: white;
1.1050 www 5517: margin: 4px;
5518: padding: 4px;
1.794 www 5519: }
5520:
1.458 albertel 5521: table.LC_pastsubmission {
5522: border: 1px solid black;
5523: margin: 2px;
5524: }
5525:
1.924 bisitz 5526: table#LC_menubuttons {
1.345 albertel 5527: width: 100%;
5528: background: $pgbg;
1.392 albertel 5529: border: 2px;
1.402 albertel 5530: border-collapse: separate;
1.803 bisitz 5531: padding: 0;
1.345 albertel 5532: }
1.392 albertel 5533:
1.801 tempelho 5534: table#LC_title_bar a {
5535: color: $fontmenu;
5536: }
1.836 bisitz 5537:
1.807 droeschl 5538: table#LC_title_bar {
1.819 tempelho 5539: clear: both;
1.836 bisitz 5540: display: none;
1.807 droeschl 5541: }
5542:
1.795 www 5543: table#LC_title_bar,
1.933 droeschl 5544: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5545: table#LC_title_bar.LC_with_remote {
1.359 albertel 5546: width: 100%;
1.392 albertel 5547: border-color: $pgbg;
5548: border-style: solid;
5549: border-width: $border;
1.379 albertel 5550: background: $pgbg;
1.801 tempelho 5551: color: $fontmenu;
1.392 albertel 5552: border-collapse: collapse;
1.803 bisitz 5553: padding: 0;
1.819 tempelho 5554: margin: 0;
1.359 albertel 5555: }
1.795 www 5556:
1.933 droeschl 5557: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5558: margin: 0;
5559: padding: 0;
1.933 droeschl 5560: position: relative;
5561: list-style: none;
1.913 droeschl 5562: }
1.933 droeschl 5563: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5564: display: inline;
5565: }
1.933 droeschl 5566:
5567: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5568: padding: 0;
1.933 droeschl 5569: margin: 0;
5570: float: left;
1.913 droeschl 5571: }
1.933 droeschl 5572: .LC_breadcrumb_tools_tools {
5573: padding: 0;
5574: margin: 0;
1.913 droeschl 5575: float: right;
5576: }
5577:
1.359 albertel 5578: table#LC_title_bar td {
5579: background: $tabbg;
5580: }
1.795 www 5581:
1.911 bisitz 5582: table#LC_menubuttons img {
1.803 bisitz 5583: border: none;
1.346 albertel 5584: }
1.795 www 5585:
1.842 droeschl 5586: .LC_breadcrumbs_component {
1.911 bisitz 5587: float: right;
5588: margin: 0 1em;
1.357 albertel 5589: }
1.842 droeschl 5590: .LC_breadcrumbs_component img {
1.911 bisitz 5591: vertical-align: middle;
1.777 tempelho 5592: }
1.795 www 5593:
1.383 albertel 5594: td.LC_table_cell_checkbox {
5595: text-align: center;
5596: }
1.795 www 5597:
5598: .LC_fontsize_small {
1.911 bisitz 5599: font-size: 70%;
1.705 tempelho 5600: }
5601:
1.844 bisitz 5602: #LC_breadcrumbs {
1.911 bisitz 5603: clear:both;
5604: background: $sidebg;
5605: border-bottom: 1px solid $lg_border_color;
5606: line-height: 2.5em;
1.933 droeschl 5607: overflow: hidden;
1.911 bisitz 5608: margin: 0;
5609: padding: 0;
1.995 raeburn 5610: text-align: left;
1.819 tempelho 5611: }
1.862 bisitz 5612:
1.1098 bisitz 5613: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5614: clear:both;
5615: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5616: border: 1px solid $sidebg;
1.1098 bisitz 5617: margin: 0 0 10px 0;
1.966 bisitz 5618: padding: 3px;
1.995 raeburn 5619: text-align: left;
1.822 bisitz 5620: }
5621:
1.795 www 5622: .LC_fontsize_medium {
1.911 bisitz 5623: font-size: 85%;
1.705 tempelho 5624: }
5625:
1.795 www 5626: .LC_fontsize_large {
1.911 bisitz 5627: font-size: 120%;
1.705 tempelho 5628: }
5629:
1.346 albertel 5630: .LC_menubuttons_inline_text {
5631: color: $font;
1.698 harmsja 5632: font-size: 90%;
1.701 harmsja 5633: padding-left:3px;
1.346 albertel 5634: }
5635:
1.934 droeschl 5636: .LC_menubuttons_inline_text img{
5637: vertical-align: middle;
5638: }
5639:
1.1051 www 5640: li.LC_menubuttons_inline_text img {
1.951 onken 5641: cursor:pointer;
1.1002 droeschl 5642: text-decoration: none;
1.951 onken 5643: }
5644:
1.526 www 5645: .LC_menubuttons_link {
5646: text-decoration: none;
5647: }
1.795 www 5648:
1.522 albertel 5649: .LC_menubuttons_category {
1.521 www 5650: color: $font;
1.526 www 5651: background: $pgbg;
1.521 www 5652: font-size: larger;
5653: font-weight: bold;
5654: }
5655:
1.346 albertel 5656: td.LC_menubuttons_text {
1.911 bisitz 5657: color: $font;
1.346 albertel 5658: }
1.706 harmsja 5659:
1.346 albertel 5660: .LC_current_location {
5661: background: $tabbg;
5662: }
1.795 www 5663:
1.938 bisitz 5664: table.LC_data_table {
1.347 albertel 5665: border: 1px solid #000000;
1.402 albertel 5666: border-collapse: separate;
1.426 albertel 5667: border-spacing: 1px;
1.610 albertel 5668: background: $pgbg;
1.347 albertel 5669: }
1.795 www 5670:
1.422 albertel 5671: .LC_data_table_dense {
5672: font-size: small;
5673: }
1.795 www 5674:
1.507 raeburn 5675: table.LC_nested_outer {
5676: border: 1px solid #000000;
1.589 raeburn 5677: border-collapse: collapse;
1.803 bisitz 5678: border-spacing: 0;
1.507 raeburn 5679: width: 100%;
5680: }
1.795 www 5681:
1.879 raeburn 5682: table.LC_innerpickbox,
1.507 raeburn 5683: table.LC_nested {
1.803 bisitz 5684: border: none;
1.589 raeburn 5685: border-collapse: collapse;
1.803 bisitz 5686: border-spacing: 0;
1.507 raeburn 5687: width: 100%;
5688: }
1.795 www 5689:
1.911 bisitz 5690: table.LC_data_table tr th,
5691: table.LC_calendar tr th,
1.879 raeburn 5692: table.LC_prior_tries tr th,
5693: table.LC_innerpickbox tr th {
1.349 albertel 5694: font-weight: bold;
5695: background-color: $data_table_head;
1.801 tempelho 5696: color:$fontmenu;
1.701 harmsja 5697: font-size:90%;
1.347 albertel 5698: }
1.795 www 5699:
1.879 raeburn 5700: table.LC_innerpickbox tr th,
5701: table.LC_innerpickbox tr td {
5702: vertical-align: top;
5703: }
5704:
1.711 raeburn 5705: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5706: background-color: #CCCCCC;
1.711 raeburn 5707: font-weight: bold;
5708: text-align: left;
5709: }
1.795 www 5710:
1.912 bisitz 5711: table.LC_data_table tr.LC_odd_row > td {
5712: background-color: $data_table_light;
5713: padding: 2px;
5714: vertical-align: top;
5715: }
5716:
1.809 bisitz 5717: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5718: background-color: $data_table_light;
1.912 bisitz 5719: vertical-align: top;
5720: }
5721:
5722: table.LC_data_table tr.LC_even_row > td {
5723: background-color: $data_table_dark;
1.425 albertel 5724: padding: 2px;
1.900 bisitz 5725: vertical-align: top;
1.347 albertel 5726: }
1.795 www 5727:
1.809 bisitz 5728: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5729: background-color: $data_table_dark;
1.900 bisitz 5730: vertical-align: top;
1.347 albertel 5731: }
1.795 www 5732:
1.425 albertel 5733: table.LC_data_table tr.LC_data_table_highlight td {
5734: background-color: $data_table_darker;
5735: }
1.795 www 5736:
1.639 raeburn 5737: table.LC_data_table tr td.LC_leftcol_header {
5738: background-color: $data_table_head;
5739: font-weight: bold;
5740: }
1.795 www 5741:
1.451 albertel 5742: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5743: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5744: font-weight: bold;
5745: font-style: italic;
5746: text-align: center;
5747: padding: 8px;
1.347 albertel 5748: }
1.795 www 5749:
1.1114 raeburn 5750: table.LC_data_table tr.LC_empty_row td,
5751: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5752: background-color: $sidebg;
5753: }
5754:
5755: table.LC_nested tr.LC_empty_row td {
5756: background-color: #FFFFFF;
5757: }
5758:
1.890 droeschl 5759: table.LC_caption {
5760: }
5761:
1.507 raeburn 5762: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5763: padding: 4ex
5764: }
1.795 www 5765:
1.507 raeburn 5766: table.LC_nested_outer tr th {
5767: font-weight: bold;
1.801 tempelho 5768: color:$fontmenu;
1.507 raeburn 5769: background-color: $data_table_head;
1.701 harmsja 5770: font-size: small;
1.507 raeburn 5771: border-bottom: 1px solid #000000;
5772: }
1.795 www 5773:
1.507 raeburn 5774: table.LC_nested_outer tr td.LC_subheader {
5775: background-color: $data_table_head;
5776: font-weight: bold;
5777: font-size: small;
5778: border-bottom: 1px solid #000000;
5779: text-align: right;
1.451 albertel 5780: }
1.795 www 5781:
1.507 raeburn 5782: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5783: background-color: #CCCCCC;
1.451 albertel 5784: font-weight: bold;
5785: font-size: small;
1.507 raeburn 5786: text-align: center;
5787: }
1.795 www 5788:
1.589 raeburn 5789: table.LC_nested tr.LC_info_row td.LC_left_item,
5790: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5791: text-align: left;
1.451 albertel 5792: }
1.795 www 5793:
1.507 raeburn 5794: table.LC_nested td {
1.735 bisitz 5795: background-color: #FFFFFF;
1.451 albertel 5796: font-size: small;
1.507 raeburn 5797: }
1.795 www 5798:
1.507 raeburn 5799: table.LC_nested_outer tr th.LC_right_item,
5800: table.LC_nested tr.LC_info_row td.LC_right_item,
5801: table.LC_nested tr.LC_odd_row td.LC_right_item,
5802: table.LC_nested tr td.LC_right_item {
1.451 albertel 5803: text-align: right;
5804: }
5805:
1.507 raeburn 5806: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5807: background-color: #EEEEEE;
1.451 albertel 5808: }
5809:
1.473 raeburn 5810: table.LC_createuser {
5811: }
5812:
5813: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5814: font-size: small;
1.473 raeburn 5815: }
5816:
5817: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5818: background-color: #CCCCCC;
1.473 raeburn 5819: font-weight: bold;
5820: text-align: center;
5821: }
5822:
1.349 albertel 5823: table.LC_calendar {
5824: border: 1px solid #000000;
5825: border-collapse: collapse;
1.917 raeburn 5826: width: 98%;
1.349 albertel 5827: }
1.795 www 5828:
1.349 albertel 5829: table.LC_calendar_pickdate {
5830: font-size: xx-small;
5831: }
1.795 www 5832:
1.349 albertel 5833: table.LC_calendar tr td {
5834: border: 1px solid #000000;
5835: vertical-align: top;
1.917 raeburn 5836: width: 14%;
1.349 albertel 5837: }
1.795 www 5838:
1.349 albertel 5839: table.LC_calendar tr td.LC_calendar_day_empty {
5840: background-color: $data_table_dark;
5841: }
1.795 www 5842:
1.779 bisitz 5843: table.LC_calendar tr td.LC_calendar_day_current {
5844: background-color: $data_table_highlight;
1.777 tempelho 5845: }
1.795 www 5846:
1.938 bisitz 5847: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5848: background-color: $mail_new;
5849: }
1.795 www 5850:
1.938 bisitz 5851: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5852: background-color: $mail_new_hover;
5853: }
1.795 www 5854:
1.938 bisitz 5855: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5856: background-color: $mail_read;
5857: }
1.795 www 5858:
1.938 bisitz 5859: /*
5860: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5861: background-color: $mail_read_hover;
5862: }
1.938 bisitz 5863: */
1.795 www 5864:
1.938 bisitz 5865: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5866: background-color: $mail_replied;
5867: }
1.795 www 5868:
1.938 bisitz 5869: /*
5870: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5871: background-color: $mail_replied_hover;
5872: }
1.938 bisitz 5873: */
1.795 www 5874:
1.938 bisitz 5875: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5876: background-color: $mail_other;
5877: }
1.795 www 5878:
1.938 bisitz 5879: /*
5880: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5881: background-color: $mail_other_hover;
5882: }
1.938 bisitz 5883: */
1.494 raeburn 5884:
1.777 tempelho 5885: table.LC_data_table tr > td.LC_browser_file,
5886: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5887: background: #AAEE77;
1.389 albertel 5888: }
1.795 www 5889:
1.777 tempelho 5890: table.LC_data_table tr > td.LC_browser_file_locked,
5891: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5892: background: #FFAA99;
1.387 albertel 5893: }
1.795 www 5894:
1.777 tempelho 5895: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5896: background: #888888;
1.779 bisitz 5897: }
1.795 www 5898:
1.777 tempelho 5899: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5900: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5901: background: #F8F866;
1.777 tempelho 5902: }
1.795 www 5903:
1.696 bisitz 5904: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5905: background: #E0E8FF;
1.387 albertel 5906: }
1.696 bisitz 5907:
1.707 bisitz 5908: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5909: /* background: #77FF77; */
1.707 bisitz 5910: }
1.795 www 5911:
1.707 bisitz 5912: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5913: border-right: 8px solid #FFFF77;
1.707 bisitz 5914: }
1.795 www 5915:
1.707 bisitz 5916: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5917: border-right: 8px solid #FFAA77;
1.707 bisitz 5918: }
1.795 www 5919:
1.707 bisitz 5920: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5921: border-right: 8px solid #FF7777;
1.707 bisitz 5922: }
1.795 www 5923:
1.707 bisitz 5924: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5925: border-right: 8px solid #AAFF77;
1.707 bisitz 5926: }
1.795 www 5927:
1.707 bisitz 5928: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5929: border-right: 8px solid #11CC55;
1.707 bisitz 5930: }
5931:
1.388 albertel 5932: span.LC_current_location {
1.701 harmsja 5933: font-size:larger;
1.388 albertel 5934: background: $pgbg;
5935: }
1.387 albertel 5936:
1.1029 www 5937: span.LC_current_nav_location {
5938: font-weight:bold;
5939: background: $sidebg;
5940: }
5941:
1.395 albertel 5942: span.LC_parm_menu_item {
5943: font-size: larger;
5944: }
1.795 www 5945:
1.395 albertel 5946: span.LC_parm_scope_all {
5947: color: red;
5948: }
1.795 www 5949:
1.395 albertel 5950: span.LC_parm_scope_folder {
5951: color: green;
5952: }
1.795 www 5953:
1.395 albertel 5954: span.LC_parm_scope_resource {
5955: color: orange;
5956: }
1.795 www 5957:
1.395 albertel 5958: span.LC_parm_part {
5959: color: blue;
5960: }
1.795 www 5961:
1.911 bisitz 5962: span.LC_parm_folder,
5963: span.LC_parm_symb {
1.395 albertel 5964: font-size: x-small;
5965: font-family: $mono;
5966: color: #AAAAAA;
5967: }
5968:
1.977 bisitz 5969: ul.LC_parm_parmlist li {
5970: display: inline-block;
5971: padding: 0.3em 0.8em;
5972: vertical-align: top;
5973: width: 150px;
5974: border-top:1px solid $lg_border_color;
5975: }
5976:
1.795 www 5977: td.LC_parm_overview_level_menu,
5978: td.LC_parm_overview_map_menu,
5979: td.LC_parm_overview_parm_selectors,
5980: td.LC_parm_overview_restrictions {
1.396 albertel 5981: border: 1px solid black;
5982: border-collapse: collapse;
5983: }
1.795 www 5984:
1.396 albertel 5985: table.LC_parm_overview_restrictions td {
5986: border-width: 1px 4px 1px 4px;
5987: border-style: solid;
5988: border-color: $pgbg;
5989: text-align: center;
5990: }
1.795 www 5991:
1.396 albertel 5992: table.LC_parm_overview_restrictions th {
5993: background: $tabbg;
5994: border-width: 1px 4px 1px 4px;
5995: border-style: solid;
5996: border-color: $pgbg;
5997: }
1.795 www 5998:
1.398 albertel 5999: table#LC_helpmenu {
1.803 bisitz 6000: border: none;
1.398 albertel 6001: height: 55px;
1.803 bisitz 6002: border-spacing: 0;
1.398 albertel 6003: }
6004:
6005: table#LC_helpmenu fieldset legend {
6006: font-size: larger;
6007: }
1.795 www 6008:
1.397 albertel 6009: table#LC_helpmenu_links {
6010: width: 100%;
6011: border: 1px solid black;
6012: background: $pgbg;
1.803 bisitz 6013: padding: 0;
1.397 albertel 6014: border-spacing: 1px;
6015: }
1.795 www 6016:
1.397 albertel 6017: table#LC_helpmenu_links tr td {
6018: padding: 1px;
6019: background: $tabbg;
1.399 albertel 6020: text-align: center;
6021: font-weight: bold;
1.397 albertel 6022: }
1.396 albertel 6023:
1.795 www 6024: table#LC_helpmenu_links a:link,
6025: table#LC_helpmenu_links a:visited,
1.397 albertel 6026: table#LC_helpmenu_links a:active {
6027: text-decoration: none;
6028: color: $font;
6029: }
1.795 www 6030:
1.397 albertel 6031: table#LC_helpmenu_links a:hover {
6032: text-decoration: underline;
6033: color: $vlink;
6034: }
1.396 albertel 6035:
1.417 albertel 6036: .LC_chrt_popup_exists {
6037: border: 1px solid #339933;
6038: margin: -1px;
6039: }
1.795 www 6040:
1.417 albertel 6041: .LC_chrt_popup_up {
6042: border: 1px solid yellow;
6043: margin: -1px;
6044: }
1.795 www 6045:
1.417 albertel 6046: .LC_chrt_popup {
6047: border: 1px solid #8888FF;
6048: background: #CCCCFF;
6049: }
1.795 www 6050:
1.421 albertel 6051: table.LC_pick_box {
6052: border-collapse: separate;
6053: background: white;
6054: border: 1px solid black;
6055: border-spacing: 1px;
6056: }
1.795 www 6057:
1.421 albertel 6058: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6059: background: $sidebg;
1.421 albertel 6060: font-weight: bold;
1.900 bisitz 6061: text-align: left;
1.740 bisitz 6062: vertical-align: top;
1.421 albertel 6063: width: 184px;
6064: padding: 8px;
6065: }
1.795 www 6066:
1.579 raeburn 6067: table.LC_pick_box td.LC_pick_box_value {
6068: text-align: left;
6069: padding: 8px;
6070: }
1.795 www 6071:
1.579 raeburn 6072: table.LC_pick_box td.LC_pick_box_select {
6073: text-align: left;
6074: padding: 8px;
6075: }
1.795 www 6076:
1.424 albertel 6077: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6078: padding: 0;
1.421 albertel 6079: height: 1px;
6080: background: black;
6081: }
1.795 www 6082:
1.421 albertel 6083: table.LC_pick_box td.LC_pick_box_submit {
6084: text-align: right;
6085: }
1.795 www 6086:
1.579 raeburn 6087: table.LC_pick_box td.LC_evenrow_value {
6088: text-align: left;
6089: padding: 8px;
6090: background-color: $data_table_light;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_oddrow_value {
6094: text-align: left;
6095: padding: 8px;
6096: background-color: $data_table_light;
6097: }
1.795 www 6098:
1.579 raeburn 6099: span.LC_helpform_receipt_cat {
6100: font-weight: bold;
6101: }
1.795 www 6102:
1.424 albertel 6103: table.LC_group_priv_box {
6104: background: white;
6105: border: 1px solid black;
6106: border-spacing: 1px;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv_box td.LC_pick_box_title {
6110: background: $tabbg;
6111: font-weight: bold;
6112: text-align: right;
6113: width: 184px;
6114: }
1.795 www 6115:
1.424 albertel 6116: table.LC_group_priv_box td.LC_groups_fixed {
6117: background: $data_table_light;
6118: text-align: center;
6119: }
1.795 www 6120:
1.424 albertel 6121: table.LC_group_priv_box td.LC_groups_optional {
6122: background: $data_table_dark;
6123: text-align: center;
6124: }
1.795 www 6125:
1.424 albertel 6126: table.LC_group_priv_box td.LC_groups_functionality {
6127: background: $data_table_darker;
6128: text-align: center;
6129: font-weight: bold;
6130: }
1.795 www 6131:
1.424 albertel 6132: table.LC_group_priv td {
6133: text-align: left;
1.803 bisitz 6134: padding: 0;
1.424 albertel 6135: }
6136:
6137: .LC_navbuttons {
6138: margin: 2ex 0ex 2ex 0ex;
6139: }
1.795 www 6140:
1.423 albertel 6141: .LC_topic_bar {
6142: font-weight: bold;
6143: background: $tabbg;
1.918 wenzelju 6144: margin: 1em 0em 1em 2em;
1.805 bisitz 6145: padding: 3px;
1.918 wenzelju 6146: font-size: 1.2em;
1.423 albertel 6147: }
1.795 www 6148:
1.423 albertel 6149: .LC_topic_bar span {
1.918 wenzelju 6150: left: 0.5em;
6151: position: absolute;
1.423 albertel 6152: vertical-align: middle;
1.918 wenzelju 6153: font-size: 1.2em;
1.423 albertel 6154: }
1.795 www 6155:
1.423 albertel 6156: table.LC_course_group_status {
6157: margin: 20px;
6158: }
1.795 www 6159:
1.423 albertel 6160: table.LC_status_selector td {
6161: vertical-align: top;
6162: text-align: center;
1.424 albertel 6163: padding: 4px;
6164: }
1.795 www 6165:
1.599 albertel 6166: div.LC_feedback_link {
1.616 albertel 6167: clear: both;
1.829 kalberla 6168: background: $sidebg;
1.779 bisitz 6169: width: 100%;
1.829 kalberla 6170: padding-bottom: 10px;
6171: border: 1px $tabbg solid;
1.833 kalberla 6172: height: 22px;
6173: line-height: 22px;
6174: padding-top: 5px;
6175: }
6176:
6177: div.LC_feedback_link img {
6178: height: 22px;
1.867 kalberla 6179: vertical-align:middle;
1.829 kalberla 6180: }
6181:
1.911 bisitz 6182: div.LC_feedback_link a {
1.829 kalberla 6183: text-decoration: none;
1.489 raeburn 6184: }
1.795 www 6185:
1.867 kalberla 6186: div.LC_comblock {
1.911 bisitz 6187: display:inline;
1.867 kalberla 6188: color:$font;
6189: font-size:90%;
6190: }
6191:
6192: div.LC_feedback_link div.LC_comblock {
6193: padding-left:5px;
6194: }
6195:
6196: div.LC_feedback_link div.LC_comblock a {
6197: color:$font;
6198: }
6199:
1.489 raeburn 6200: span.LC_feedback_link {
1.858 bisitz 6201: /* background: $feedback_link_bg; */
1.599 albertel 6202: font-size: larger;
6203: }
1.795 www 6204:
1.599 albertel 6205: span.LC_message_link {
1.858 bisitz 6206: /* background: $feedback_link_bg; */
1.599 albertel 6207: font-size: larger;
6208: position: absolute;
6209: right: 1em;
1.489 raeburn 6210: }
1.421 albertel 6211:
1.515 albertel 6212: table.LC_prior_tries {
1.524 albertel 6213: border: 1px solid #000000;
6214: border-collapse: separate;
6215: border-spacing: 1px;
1.515 albertel 6216: }
1.523 albertel 6217:
1.515 albertel 6218: table.LC_prior_tries td {
1.524 albertel 6219: padding: 2px;
1.515 albertel 6220: }
1.523 albertel 6221:
6222: .LC_answer_correct {
1.795 www 6223: background: lightgreen;
6224: color: darkgreen;
6225: padding: 6px;
1.523 albertel 6226: }
1.795 www 6227:
1.523 albertel 6228: .LC_answer_charged_try {
1.797 www 6229: background: #FFAAAA;
1.795 www 6230: color: darkred;
6231: padding: 6px;
1.523 albertel 6232: }
1.795 www 6233:
1.779 bisitz 6234: .LC_answer_not_charged_try,
1.523 albertel 6235: .LC_answer_no_grade,
6236: .LC_answer_late {
1.795 www 6237: background: lightyellow;
1.523 albertel 6238: color: black;
1.795 www 6239: padding: 6px;
1.523 albertel 6240: }
1.795 www 6241:
1.523 albertel 6242: .LC_answer_previous {
1.795 www 6243: background: lightblue;
6244: color: darkblue;
6245: padding: 6px;
1.523 albertel 6246: }
1.795 www 6247:
1.779 bisitz 6248: .LC_answer_no_message {
1.777 tempelho 6249: background: #FFFFFF;
6250: color: black;
1.795 www 6251: padding: 6px;
1.779 bisitz 6252: }
1.795 www 6253:
1.779 bisitz 6254: .LC_answer_unknown {
6255: background: orange;
6256: color: black;
1.795 www 6257: padding: 6px;
1.777 tempelho 6258: }
1.795 www 6259:
1.529 albertel 6260: span.LC_prior_numerical,
6261: span.LC_prior_string,
6262: span.LC_prior_custom,
6263: span.LC_prior_reaction,
6264: span.LC_prior_math {
1.925 bisitz 6265: font-family: $mono;
1.523 albertel 6266: white-space: pre;
6267: }
6268:
1.525 albertel 6269: span.LC_prior_string {
1.925 bisitz 6270: font-family: $mono;
1.525 albertel 6271: white-space: pre;
6272: }
6273:
1.523 albertel 6274: table.LC_prior_option {
6275: width: 100%;
6276: border-collapse: collapse;
6277: }
1.795 www 6278:
1.911 bisitz 6279: table.LC_prior_rank,
1.795 www 6280: table.LC_prior_match {
1.528 albertel 6281: border-collapse: collapse;
6282: }
1.795 www 6283:
1.528 albertel 6284: table.LC_prior_option tr td,
6285: table.LC_prior_rank tr td,
6286: table.LC_prior_match tr td {
1.524 albertel 6287: border: 1px solid #000000;
1.515 albertel 6288: }
6289:
1.855 bisitz 6290: .LC_nobreak {
1.544 albertel 6291: white-space: nowrap;
1.519 raeburn 6292: }
6293:
1.576 raeburn 6294: span.LC_cusr_emph {
6295: font-style: italic;
6296: }
6297:
1.633 raeburn 6298: span.LC_cusr_subheading {
6299: font-weight: normal;
6300: font-size: 85%;
6301: }
6302:
1.861 bisitz 6303: div.LC_docs_entry_move {
1.859 bisitz 6304: border: 1px solid #BBBBBB;
1.545 albertel 6305: background: #DDDDDD;
1.861 bisitz 6306: width: 22px;
1.859 bisitz 6307: padding: 1px;
6308: margin: 0;
1.545 albertel 6309: }
6310:
1.861 bisitz 6311: table.LC_data_table tr > td.LC_docs_entry_commands,
6312: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6313: font-size: x-small;
6314: }
1.795 www 6315:
1.861 bisitz 6316: .LC_docs_entry_parameter {
6317: white-space: nowrap;
6318: }
6319:
1.544 albertel 6320: .LC_docs_copy {
1.545 albertel 6321: color: #000099;
1.544 albertel 6322: }
1.795 www 6323:
1.544 albertel 6324: .LC_docs_cut {
1.545 albertel 6325: color: #550044;
1.544 albertel 6326: }
1.795 www 6327:
1.544 albertel 6328: .LC_docs_rename {
1.545 albertel 6329: color: #009900;
1.544 albertel 6330: }
1.795 www 6331:
1.544 albertel 6332: .LC_docs_remove {
1.545 albertel 6333: color: #990000;
6334: }
6335:
1.547 albertel 6336: .LC_docs_reinit_warn,
6337: .LC_docs_ext_edit {
6338: font-size: x-small;
6339: }
6340:
1.545 albertel 6341: table.LC_docs_adddocs td,
6342: table.LC_docs_adddocs th {
6343: border: 1px solid #BBBBBB;
6344: padding: 4px;
6345: background: #DDDDDD;
1.543 albertel 6346: }
6347:
1.584 albertel 6348: table.LC_sty_begin {
6349: background: #BBFFBB;
6350: }
1.795 www 6351:
1.584 albertel 6352: table.LC_sty_end {
6353: background: #FFBBBB;
6354: }
6355:
1.589 raeburn 6356: table.LC_double_column {
1.803 bisitz 6357: border-width: 0;
1.589 raeburn 6358: border-collapse: collapse;
6359: width: 100%;
6360: padding: 2px;
6361: }
6362:
6363: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6364: top: 2px;
1.589 raeburn 6365: left: 2px;
6366: width: 47%;
6367: vertical-align: top;
6368: }
6369:
6370: table.LC_double_column tr td.LC_right_col {
6371: top: 2px;
1.779 bisitz 6372: right: 2px;
1.589 raeburn 6373: width: 47%;
6374: vertical-align: top;
6375: }
6376:
1.591 raeburn 6377: div.LC_left_float {
6378: float: left;
6379: padding-right: 5%;
1.597 albertel 6380: padding-bottom: 4px;
1.591 raeburn 6381: }
6382:
6383: div.LC_clear_float_header {
1.597 albertel 6384: padding-bottom: 2px;
1.591 raeburn 6385: }
6386:
6387: div.LC_clear_float_footer {
1.597 albertel 6388: padding-top: 10px;
1.591 raeburn 6389: clear: both;
6390: }
6391:
1.597 albertel 6392: div.LC_grade_show_user {
1.941 bisitz 6393: /* border-left: 5px solid $sidebg; */
6394: border-top: 5px solid #000000;
6395: margin: 50px 0 0 0;
1.936 bisitz 6396: padding: 15px 0 5px 10px;
1.597 albertel 6397: }
1.795 www 6398:
1.936 bisitz 6399: div.LC_grade_show_user_odd_row {
1.941 bisitz 6400: /* border-left: 5px solid #000000; */
6401: }
6402:
6403: div.LC_grade_show_user div.LC_Box {
6404: margin-right: 50px;
1.597 albertel 6405: }
6406:
6407: div.LC_grade_submissions,
6408: div.LC_grade_message_center,
1.936 bisitz 6409: div.LC_grade_info_links {
1.597 albertel 6410: margin: 5px;
6411: width: 99%;
6412: background: #FFFFFF;
6413: }
1.795 www 6414:
1.597 albertel 6415: div.LC_grade_submissions_header,
1.936 bisitz 6416: div.LC_grade_message_center_header {
1.705 tempelho 6417: font-weight: bold;
6418: font-size: large;
1.597 albertel 6419: }
1.795 www 6420:
1.597 albertel 6421: div.LC_grade_submissions_body,
1.936 bisitz 6422: div.LC_grade_message_center_body {
1.597 albertel 6423: border: 1px solid black;
6424: width: 99%;
6425: background: #FFFFFF;
6426: }
1.795 www 6427:
1.613 albertel 6428: table.LC_scantron_action {
6429: width: 100%;
6430: }
1.795 www 6431:
1.613 albertel 6432: table.LC_scantron_action tr th {
1.698 harmsja 6433: font-weight:bold;
6434: font-style:normal;
1.613 albertel 6435: }
1.795 www 6436:
1.779 bisitz 6437: .LC_edit_problem_header,
1.614 albertel 6438: div.LC_edit_problem_footer {
1.705 tempelho 6439: font-weight: normal;
6440: font-size: medium;
1.602 albertel 6441: margin: 2px;
1.1060 bisitz 6442: background-color: $sidebg;
1.600 albertel 6443: }
1.795 www 6444:
1.600 albertel 6445: div.LC_edit_problem_header,
1.602 albertel 6446: div.LC_edit_problem_header div,
1.614 albertel 6447: div.LC_edit_problem_footer,
6448: div.LC_edit_problem_footer div,
1.602 albertel 6449: div.LC_edit_problem_editxml_header,
6450: div.LC_edit_problem_editxml_header div {
1.600 albertel 6451: margin-top: 5px;
6452: }
1.795 www 6453:
1.600 albertel 6454: div.LC_edit_problem_header_title {
1.705 tempelho 6455: font-weight: bold;
6456: font-size: larger;
1.602 albertel 6457: background: $tabbg;
6458: padding: 3px;
1.1060 bisitz 6459: margin: 0 0 5px 0;
1.602 albertel 6460: }
1.795 www 6461:
1.602 albertel 6462: table.LC_edit_problem_header_title {
6463: width: 100%;
1.600 albertel 6464: background: $tabbg;
1.602 albertel 6465: }
6466:
6467: div.LC_edit_problem_discards {
6468: float: left;
6469: padding-bottom: 5px;
6470: }
1.795 www 6471:
1.602 albertel 6472: div.LC_edit_problem_saves {
6473: float: right;
6474: padding-bottom: 5px;
1.600 albertel 6475: }
1.795 www 6476:
1.911 bisitz 6477: img.stift {
1.803 bisitz 6478: border-width: 0;
6479: vertical-align: middle;
1.677 riegler 6480: }
1.680 riegler 6481:
1.923 bisitz 6482: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6483: vertical-align: top;
1.777 tempelho 6484: }
1.795 www 6485:
1.716 raeburn 6486: div.LC_createcourse {
1.911 bisitz 6487: margin: 10px 10px 10px 10px;
1.716 raeburn 6488: }
6489:
1.917 raeburn 6490: .LC_dccid {
6491: margin: 0.2em 0 0 0;
6492: padding: 0;
6493: font-size: 90%;
6494: display:none;
6495: }
6496:
1.897 wenzelju 6497: ol.LC_primary_menu a:hover,
1.721 harmsja 6498: ol#LC_MenuBreadcrumbs a:hover,
6499: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6500: ul#LC_secondary_menu a:hover,
1.721 harmsja 6501: .LC_FormSectionClearButton input:hover
1.795 www 6502: ul.LC_TabContent li:hover a {
1.952 onken 6503: color:$button_hover;
1.911 bisitz 6504: text-decoration:none;
1.693 droeschl 6505: }
6506:
1.779 bisitz 6507: h1 {
1.911 bisitz 6508: padding: 0;
6509: line-height:130%;
1.693 droeschl 6510: }
1.698 harmsja 6511:
1.911 bisitz 6512: h2,
6513: h3,
6514: h4,
6515: h5,
6516: h6 {
6517: margin: 5px 0 5px 0;
6518: padding: 0;
6519: line-height:130%;
1.693 droeschl 6520: }
1.795 www 6521:
6522: .LC_hcell {
1.911 bisitz 6523: padding:3px 15px 3px 15px;
6524: margin: 0;
6525: background-color:$tabbg;
6526: color:$fontmenu;
6527: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6528: }
1.795 www 6529:
1.840 bisitz 6530: .LC_Box > .LC_hcell {
1.911 bisitz 6531: margin: 0 -10px 10px -10px;
1.835 bisitz 6532: }
6533:
1.721 harmsja 6534: .LC_noBorder {
1.911 bisitz 6535: border: 0;
1.698 harmsja 6536: }
1.693 droeschl 6537:
1.721 harmsja 6538: .LC_FormSectionClearButton input {
1.911 bisitz 6539: background-color:transparent;
6540: border: none;
6541: cursor:pointer;
6542: text-decoration:underline;
1.693 droeschl 6543: }
1.763 bisitz 6544:
6545: .LC_help_open_topic {
1.911 bisitz 6546: color: #FFFFFF;
6547: background-color: #EEEEFF;
6548: margin: 1px;
6549: padding: 4px;
6550: border: 1px solid #000033;
6551: white-space: nowrap;
6552: /* vertical-align: middle; */
1.759 neumanie 6553: }
1.693 droeschl 6554:
1.911 bisitz 6555: dl,
6556: ul,
6557: div,
6558: fieldset {
6559: margin: 10px 10px 10px 0;
6560: /* overflow: hidden; */
1.693 droeschl 6561: }
1.795 www 6562:
1.838 bisitz 6563: fieldset > legend {
1.911 bisitz 6564: font-weight: bold;
6565: padding: 0 5px 0 5px;
1.838 bisitz 6566: }
6567:
1.813 bisitz 6568: #LC_nav_bar {
1.911 bisitz 6569: float: left;
1.995 raeburn 6570: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6571: margin: 0 0 2px 0;
1.807 droeschl 6572: }
6573:
1.916 droeschl 6574: #LC_realm {
6575: margin: 0.2em 0 0 0;
6576: padding: 0;
6577: font-weight: bold;
6578: text-align: center;
1.995 raeburn 6579: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6580: }
6581:
1.911 bisitz 6582: #LC_nav_bar em {
6583: font-weight: bold;
6584: font-style: normal;
1.807 droeschl 6585: }
6586:
1.897 wenzelju 6587: ol.LC_primary_menu {
1.911 bisitz 6588: float: right;
1.934 droeschl 6589: margin: 0;
1.1076 raeburn 6590: padding: 0;
1.995 raeburn 6591: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6592: }
6593:
1.852 droeschl 6594: ol#LC_PathBreadcrumbs {
1.911 bisitz 6595: margin: 0;
1.693 droeschl 6596: }
6597:
1.897 wenzelju 6598: ol.LC_primary_menu li {
1.1076 raeburn 6599: color: RGB(80, 80, 80);
6600: vertical-align: middle;
6601: text-align: left;
6602: list-style: none;
6603: float: left;
6604: }
6605:
6606: ol.LC_primary_menu li a {
6607: display: block;
6608: margin: 0;
6609: padding: 0 5px 0 10px;
6610: text-decoration: none;
6611: }
6612:
6613: ol.LC_primary_menu li ul {
6614: display: none;
6615: width: 10em;
6616: background-color: $data_table_light;
6617: }
6618:
6619: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6620: display: block;
6621: position: absolute;
6622: margin: 0;
6623: padding: 0;
1.1078 raeburn 6624: z-index: 2;
1.1076 raeburn 6625: }
6626:
6627: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6628: font-size: 90%;
1.911 bisitz 6629: vertical-align: top;
1.1076 raeburn 6630: float: none;
1.1079 raeburn 6631: border-left: 1px solid black;
6632: border-right: 1px solid black;
1.1076 raeburn 6633: }
6634:
6635: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6636: background-color:$data_table_light;
1.1076 raeburn 6637: }
6638:
6639: ol.LC_primary_menu li li a:hover {
6640: color:$button_hover;
6641: background-color:$data_table_dark;
1.693 droeschl 6642: }
6643:
1.897 wenzelju 6644: ol.LC_primary_menu li img {
1.911 bisitz 6645: vertical-align: bottom;
1.934 droeschl 6646: height: 1.1em;
1.1077 raeburn 6647: margin: 0.2em 0 0 0;
1.693 droeschl 6648: }
6649:
1.897 wenzelju 6650: ol.LC_primary_menu a {
1.911 bisitz 6651: color: RGB(80, 80, 80);
6652: text-decoration: none;
1.693 droeschl 6653: }
1.795 www 6654:
1.949 droeschl 6655: ol.LC_primary_menu a.LC_new_message {
6656: font-weight:bold;
6657: color: darkred;
6658: }
6659:
1.975 raeburn 6660: ol.LC_docs_parameters {
6661: margin-left: 0;
6662: padding: 0;
6663: list-style: none;
6664: }
6665:
6666: ol.LC_docs_parameters li {
6667: margin: 0;
6668: padding-right: 20px;
6669: display: inline;
6670: }
6671:
1.976 raeburn 6672: ol.LC_docs_parameters li:before {
6673: content: "\\002022 \\0020";
6674: }
6675:
6676: li.LC_docs_parameters_title {
6677: font-weight: bold;
6678: }
6679:
6680: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6681: content: "";
6682: }
6683:
1.897 wenzelju 6684: ul#LC_secondary_menu {
1.1107 raeburn 6685: clear: right;
1.911 bisitz 6686: color: $fontmenu;
6687: background: $tabbg;
6688: list-style: none;
6689: padding: 0;
6690: margin: 0;
6691: width: 100%;
1.995 raeburn 6692: text-align: left;
1.1107 raeburn 6693: float: left;
1.808 droeschl 6694: }
6695:
1.897 wenzelju 6696: ul#LC_secondary_menu li {
1.911 bisitz 6697: font-weight: bold;
6698: line-height: 1.8em;
1.1107 raeburn 6699: border-right: 1px solid black;
6700: float: left;
6701: }
6702:
6703: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6704: background-color: $data_table_light;
6705: }
6706:
6707: ul#LC_secondary_menu li a {
1.911 bisitz 6708: padding: 0 0.8em;
1.1107 raeburn 6709: }
6710:
6711: ul#LC_secondary_menu li ul {
6712: display: none;
6713: }
6714:
6715: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6716: display: block;
6717: position: absolute;
6718: margin: 0;
6719: padding: 0;
6720: list-style:none;
6721: float: none;
6722: background-color: $data_table_light;
6723: z-index: 2;
6724: margin-left: -1px;
6725: }
6726:
6727: ul#LC_secondary_menu li ul li {
6728: font-size: 90%;
6729: vertical-align: top;
6730: border-left: 1px solid black;
1.911 bisitz 6731: border-right: 1px solid black;
1.1119 ! raeburn 6732: background-color: $data_table_light;
1.1107 raeburn 6733: list-style:none;
6734: float: none;
6735: }
6736:
6737: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6738: background-color: $data_table_dark;
1.807 droeschl 6739: }
6740:
1.847 tempelho 6741: ul.LC_TabContent {
1.911 bisitz 6742: display:block;
6743: background: $sidebg;
6744: border-bottom: solid 1px $lg_border_color;
6745: list-style:none;
1.1020 raeburn 6746: margin: -1px -10px 0 -10px;
1.911 bisitz 6747: padding: 0;
1.693 droeschl 6748: }
6749:
1.795 www 6750: ul.LC_TabContent li,
6751: ul.LC_TabContentBigger li {
1.911 bisitz 6752: float:left;
1.741 harmsja 6753: }
1.795 www 6754:
1.897 wenzelju 6755: ul#LC_secondary_menu li a {
1.911 bisitz 6756: color: $fontmenu;
6757: text-decoration: none;
1.693 droeschl 6758: }
1.795 www 6759:
1.721 harmsja 6760: ul.LC_TabContent {
1.952 onken 6761: min-height:20px;
1.721 harmsja 6762: }
1.795 www 6763:
6764: ul.LC_TabContent li {
1.911 bisitz 6765: vertical-align:middle;
1.959 onken 6766: padding: 0 16px 0 10px;
1.911 bisitz 6767: background-color:$tabbg;
6768: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6769: border-left: solid 1px $font;
1.721 harmsja 6770: }
1.795 www 6771:
1.847 tempelho 6772: ul.LC_TabContent .right {
1.911 bisitz 6773: float:right;
1.847 tempelho 6774: }
6775:
1.911 bisitz 6776: ul.LC_TabContent li a,
6777: ul.LC_TabContent li {
6778: color:rgb(47,47,47);
6779: text-decoration:none;
6780: font-size:95%;
6781: font-weight:bold;
1.952 onken 6782: min-height:20px;
6783: }
6784:
1.959 onken 6785: ul.LC_TabContent li a:hover,
6786: ul.LC_TabContent li a:focus {
1.952 onken 6787: color: $button_hover;
1.959 onken 6788: background:none;
6789: outline:none;
1.952 onken 6790: }
6791:
6792: ul.LC_TabContent li:hover {
6793: color: $button_hover;
6794: cursor:pointer;
1.721 harmsja 6795: }
1.795 www 6796:
1.911 bisitz 6797: ul.LC_TabContent li.active {
1.952 onken 6798: color: $font;
1.911 bisitz 6799: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6800: border-bottom:solid 1px #FFFFFF;
6801: cursor: default;
1.744 ehlerst 6802: }
1.795 www 6803:
1.959 onken 6804: ul.LC_TabContent li.active a {
6805: color:$font;
6806: background:#FFFFFF;
6807: outline: none;
6808: }
1.1047 raeburn 6809:
6810: ul.LC_TabContent li.goback {
6811: float: left;
6812: border-left: none;
6813: }
6814:
1.870 tempelho 6815: #maincoursedoc {
1.911 bisitz 6816: clear:both;
1.870 tempelho 6817: }
6818:
6819: ul.LC_TabContentBigger {
1.911 bisitz 6820: display:block;
6821: list-style:none;
6822: padding: 0;
1.870 tempelho 6823: }
6824:
1.795 www 6825: ul.LC_TabContentBigger li {
1.911 bisitz 6826: vertical-align:bottom;
6827: height: 30px;
6828: font-size:110%;
6829: font-weight:bold;
6830: color: #737373;
1.841 tempelho 6831: }
6832:
1.957 onken 6833: ul.LC_TabContentBigger li.active {
6834: position: relative;
6835: top: 1px;
6836: }
6837:
1.870 tempelho 6838: ul.LC_TabContentBigger li a {
1.911 bisitz 6839: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6840: height: 30px;
6841: line-height: 30px;
6842: text-align: center;
6843: display: block;
6844: text-decoration: none;
1.958 onken 6845: outline: none;
1.741 harmsja 6846: }
1.795 www 6847:
1.870 tempelho 6848: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6849: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6850: color:$font;
1.744 ehlerst 6851: }
1.795 www 6852:
1.870 tempelho 6853: ul.LC_TabContentBigger li b {
1.911 bisitz 6854: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6855: display: block;
6856: float: left;
6857: padding: 0 30px;
1.957 onken 6858: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6859: }
6860:
1.956 onken 6861: ul.LC_TabContentBigger li:hover b {
6862: color:$button_hover;
6863: }
6864:
1.870 tempelho 6865: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6866: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6867: color:$font;
1.957 onken 6868: border: 0;
1.741 harmsja 6869: }
1.693 droeschl 6870:
1.870 tempelho 6871:
1.862 bisitz 6872: ul.LC_CourseBreadcrumbs {
6873: background: $sidebg;
1.1020 raeburn 6874: height: 2em;
1.862 bisitz 6875: padding-left: 10px;
1.1020 raeburn 6876: margin: 0;
1.862 bisitz 6877: list-style-position: inside;
6878: }
6879:
1.911 bisitz 6880: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6881: ol#LC_PathBreadcrumbs {
1.911 bisitz 6882: padding-left: 10px;
6883: margin: 0;
1.933 droeschl 6884: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6885: }
6886:
1.911 bisitz 6887: ol#LC_MenuBreadcrumbs li,
6888: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6889: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6890: display: inline;
1.933 droeschl 6891: white-space: normal;
1.693 droeschl 6892: }
6893:
1.823 bisitz 6894: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6895: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6896: text-decoration: none;
6897: font-size:90%;
1.693 droeschl 6898: }
1.795 www 6899:
1.969 droeschl 6900: ol#LC_MenuBreadcrumbs h1 {
6901: display: inline;
6902: font-size: 90%;
6903: line-height: 2.5em;
6904: margin: 0;
6905: padding: 0;
6906: }
6907:
1.795 www 6908: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6909: text-decoration:none;
6910: font-size:100%;
6911: font-weight:bold;
1.693 droeschl 6912: }
1.795 www 6913:
1.840 bisitz 6914: .LC_Box {
1.911 bisitz 6915: border: solid 1px $lg_border_color;
6916: padding: 0 10px 10px 10px;
1.746 neumanie 6917: }
1.795 www 6918:
1.1020 raeburn 6919: .LC_DocsBox {
6920: border: solid 1px $lg_border_color;
6921: padding: 0 0 10px 10px;
6922: }
6923:
1.795 www 6924: .LC_AboutMe_Image {
1.911 bisitz 6925: float:left;
6926: margin-right:10px;
1.747 neumanie 6927: }
1.795 www 6928:
6929: .LC_Clear_AboutMe_Image {
1.911 bisitz 6930: clear:left;
1.747 neumanie 6931: }
1.795 www 6932:
1.721 harmsja 6933: dl.LC_ListStyleClean dt {
1.911 bisitz 6934: padding-right: 5px;
6935: display: table-header-group;
1.693 droeschl 6936: }
6937:
1.721 harmsja 6938: dl.LC_ListStyleClean dd {
1.911 bisitz 6939: display: table-row;
1.693 droeschl 6940: }
6941:
1.721 harmsja 6942: .LC_ListStyleClean,
6943: .LC_ListStyleSimple,
6944: .LC_ListStyleNormal,
1.795 www 6945: .LC_ListStyleSpecial {
1.911 bisitz 6946: /* display:block; */
6947: list-style-position: inside;
6948: list-style-type: none;
6949: overflow: hidden;
6950: padding: 0;
1.693 droeschl 6951: }
6952:
1.721 harmsja 6953: .LC_ListStyleSimple li,
6954: .LC_ListStyleSimple dd,
6955: .LC_ListStyleNormal li,
6956: .LC_ListStyleNormal dd,
6957: .LC_ListStyleSpecial li,
1.795 www 6958: .LC_ListStyleSpecial dd {
1.911 bisitz 6959: margin: 0;
6960: padding: 5px 5px 5px 10px;
6961: clear: both;
1.693 droeschl 6962: }
6963:
1.721 harmsja 6964: .LC_ListStyleClean li,
6965: .LC_ListStyleClean dd {
1.911 bisitz 6966: padding-top: 0;
6967: padding-bottom: 0;
1.693 droeschl 6968: }
6969:
1.721 harmsja 6970: .LC_ListStyleSimple dd,
1.795 www 6971: .LC_ListStyleSimple li {
1.911 bisitz 6972: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6973: }
6974:
1.721 harmsja 6975: .LC_ListStyleSpecial li,
6976: .LC_ListStyleSpecial dd {
1.911 bisitz 6977: list-style-type: none;
6978: background-color: RGB(220, 220, 220);
6979: margin-bottom: 4px;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: table.LC_SimpleTable {
1.911 bisitz 6983: margin:5px;
6984: border:solid 1px $lg_border_color;
1.795 www 6985: }
1.693 droeschl 6986:
1.721 harmsja 6987: table.LC_SimpleTable tr {
1.911 bisitz 6988: padding: 0;
6989: border:solid 1px $lg_border_color;
1.693 droeschl 6990: }
1.795 www 6991:
6992: table.LC_SimpleTable thead {
1.911 bisitz 6993: background:rgb(220,220,220);
1.693 droeschl 6994: }
6995:
1.721 harmsja 6996: div.LC_columnSection {
1.911 bisitz 6997: display: block;
6998: clear: both;
6999: overflow: hidden;
7000: margin: 0;
1.693 droeschl 7001: }
7002:
1.721 harmsja 7003: div.LC_columnSection>* {
1.911 bisitz 7004: float: left;
7005: margin: 10px 20px 10px 0;
7006: overflow:hidden;
1.693 droeschl 7007: }
1.721 harmsja 7008:
1.795 www 7009: table em {
1.911 bisitz 7010: font-weight: bold;
7011: font-style: normal;
1.748 schulted 7012: }
1.795 www 7013:
1.779 bisitz 7014: table.LC_tableBrowseRes,
1.795 www 7015: table.LC_tableOfContent {
1.911 bisitz 7016: border:none;
7017: border-spacing: 1px;
7018: padding: 3px;
7019: background-color: #FFFFFF;
7020: font-size: 90%;
1.753 droeschl 7021: }
1.789 droeschl 7022:
1.911 bisitz 7023: table.LC_tableOfContent {
7024: border-collapse: collapse;
1.789 droeschl 7025: }
7026:
1.771 droeschl 7027: table.LC_tableBrowseRes a,
1.768 schulted 7028: table.LC_tableOfContent a {
1.911 bisitz 7029: background-color: transparent;
7030: text-decoration: none;
1.753 droeschl 7031: }
7032:
1.795 www 7033: table.LC_tableOfContent img {
1.911 bisitz 7034: border: none;
7035: height: 1.3em;
7036: vertical-align: text-bottom;
7037: margin-right: 0.3em;
1.753 droeschl 7038: }
1.757 schulted 7039:
1.795 www 7040: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7041: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7042: }
7043:
1.795 www 7044: a#LC_content_toolbar_everything {
1.911 bisitz 7045: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7046: }
7047:
1.795 www 7048: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7049: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7050: }
7051:
1.795 www 7052: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7053: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7054: }
7055:
1.795 www 7056: a#LC_content_toolbar_changefolder {
1.911 bisitz 7057: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7058: }
7059:
1.795 www 7060: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7061: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7062: }
7063:
1.1043 raeburn 7064: a#LC_content_toolbar_edittoplevel {
7065: background-image:url(/res/adm/pages/edittoplevel.gif);
7066: }
7067:
1.795 www 7068: ul#LC_toolbar li a:hover {
1.911 bisitz 7069: background-position: bottom center;
1.757 schulted 7070: }
7071:
1.795 www 7072: ul#LC_toolbar {
1.911 bisitz 7073: padding: 0;
7074: margin: 2px;
7075: list-style:none;
7076: position:relative;
7077: background-color:white;
1.1082 raeburn 7078: overflow: auto;
1.757 schulted 7079: }
7080:
1.795 www 7081: ul#LC_toolbar li {
1.911 bisitz 7082: border:1px solid white;
7083: padding: 0;
7084: margin: 0;
7085: float: left;
7086: display:inline;
7087: vertical-align:middle;
1.1082 raeburn 7088: white-space: nowrap;
1.911 bisitz 7089: }
1.757 schulted 7090:
1.783 amueller 7091:
1.795 www 7092: a.LC_toolbarItem {
1.911 bisitz 7093: display:block;
7094: padding: 0;
7095: margin: 0;
7096: height: 32px;
7097: width: 32px;
7098: color:white;
7099: border: none;
7100: background-repeat:no-repeat;
7101: background-color:transparent;
1.757 schulted 7102: }
7103:
1.915 droeschl 7104: ul.LC_funclist {
7105: margin: 0;
7106: padding: 0.5em 1em 0.5em 0;
7107: }
7108:
1.933 droeschl 7109: ul.LC_funclist > li:first-child {
7110: font-weight:bold;
7111: margin-left:0.8em;
7112: }
7113:
1.915 droeschl 7114: ul.LC_funclist + ul.LC_funclist {
7115: /*
7116: left border as a seperator if we have more than
7117: one list
7118: */
7119: border-left: 1px solid $sidebg;
7120: /*
7121: this hides the left border behind the border of the
7122: outer box if element is wrapped to the next 'line'
7123: */
7124: margin-left: -1px;
7125: }
7126:
1.843 bisitz 7127: ul.LC_funclist li {
1.915 droeschl 7128: display: inline;
1.782 bisitz 7129: white-space: nowrap;
1.915 droeschl 7130: margin: 0 0 0 25px;
7131: line-height: 150%;
1.782 bisitz 7132: }
7133:
1.974 wenzelju 7134: .LC_hidden {
7135: display: none;
7136: }
7137:
1.1030 www 7138: .LCmodal-overlay {
7139: position:fixed;
7140: top:0;
7141: right:0;
7142: bottom:0;
7143: left:0;
7144: height:100%;
7145: width:100%;
7146: margin:0;
7147: padding:0;
7148: background:#999;
7149: opacity:.75;
7150: filter: alpha(opacity=75);
7151: -moz-opacity: 0.75;
7152: z-index:101;
7153: }
7154:
7155: * html .LCmodal-overlay {
7156: position: absolute;
7157: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7158: }
7159:
7160: .LCmodal-window {
7161: position:fixed;
7162: top:50%;
7163: left:50%;
7164: margin:0;
7165: padding:0;
7166: z-index:102;
7167: }
7168:
7169: * html .LCmodal-window {
7170: position:absolute;
7171: }
7172:
7173: .LCclose-window {
7174: position:absolute;
7175: width:32px;
7176: height:32px;
7177: right:8px;
7178: top:8px;
7179: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7180: text-indent:-99999px;
7181: overflow:hidden;
7182: cursor:pointer;
7183: }
7184:
1.1100 raeburn 7185: /*
7186: styles used by TTH when "Default set of options to pass to tth/m
7187: when converting TeX" in course settings has been set
7188:
7189: option passed: -t
7190:
7191: */
7192:
7193: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7194: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7195: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7196: td div.norm {line-height:normal;}
7197:
7198: /*
7199: option passed -y3
7200: */
7201:
7202: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7203: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7204: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7205:
1.343 albertel 7206: END
7207: }
7208:
1.306 albertel 7209: =pod
7210:
7211: =item * &headtag()
7212:
7213: Returns a uniform footer for LON-CAPA web pages.
7214:
1.307 albertel 7215: Inputs: $title - optional title for the head
7216: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7217: $args - optional arguments
1.319 albertel 7218: force_register - if is true call registerurl so the remote is
7219: informed
1.415 albertel 7220: redirect -> array ref of
7221: 1- seconds before redirect occurs
7222: 2- url to redirect to
7223: 3- whether the side effect should occur
1.315 albertel 7224: (side effect of setting
7225: $env{'internal.head.redirect'} to the url
7226: redirected too)
1.352 albertel 7227: domain -> force to color decorate a page for a specific
7228: domain
7229: function -> force usage of a specific rolish color scheme
7230: bgcolor -> override the default page bgcolor
1.460 albertel 7231: no_auto_mt_title
7232: -> prevent &mt()ing the title arg
1.464 albertel 7233:
1.306 albertel 7234: =cut
7235:
7236: sub headtag {
1.313 albertel 7237: my ($title,$head_extra,$args) = @_;
1.306 albertel 7238:
1.363 albertel 7239: my $function = $args->{'function'} || &get_users_function();
7240: my $domain = $args->{'domain'} || &determinedomain();
7241: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7242: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7243: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7244: #time(),
1.418 albertel 7245: $env{'environment.color.timestamp'},
1.363 albertel 7246: $function,$domain,$bgcolor);
7247:
1.369 www 7248: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7249:
1.308 albertel 7250: my $result =
7251: '<head>'.
1.461 albertel 7252: &font_settings();
1.319 albertel 7253:
1.1064 raeburn 7254: my $inhibitprint = &print_suppression();
7255:
1.461 albertel 7256: if (!$args->{'frameset'}) {
7257: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7258: }
1.962 droeschl 7259: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7260: $result .= Apache::lonxml::display_title();
1.319 albertel 7261: }
1.436 albertel 7262: if (!$args->{'no_nav_bar'}
7263: && !$args->{'only_body'}
7264: && !$args->{'frameset'}) {
7265: $result .= &help_menu_js();
1.1032 www 7266: $result.=&modal_window();
1.1038 www 7267: $result.=&togglebox_script();
1.1034 www 7268: $result.=&wishlist_window();
1.1041 www 7269: $result.=&LCprogressbarUpdate_script();
1.1034 www 7270: } else {
7271: if ($args->{'add_modal'}) {
7272: $result.=&modal_window();
7273: }
7274: if ($args->{'add_wishlist'}) {
7275: $result.=&wishlist_window();
7276: }
1.1038 www 7277: if ($args->{'add_togglebox'}) {
7278: $result.=&togglebox_script();
7279: }
1.1041 www 7280: if ($args->{'add_progressbar'}) {
7281: $result.=&LCprogressbarUpdate_script();
7282: }
1.436 albertel 7283: }
1.314 albertel 7284: if (ref($args->{'redirect'})) {
1.414 albertel 7285: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7286: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7287: if (!$inhibit_continue) {
7288: $env{'internal.head.redirect'} = $url;
7289: }
1.313 albertel 7290: $result.=<<ADDMETA
7291: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7292: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7293: ADDMETA
7294: }
1.306 albertel 7295: if (!defined($title)) {
7296: $title = 'The LearningOnline Network with CAPA';
7297: }
1.460 albertel 7298: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7299: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7300: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7301: .$inhibitprint
1.414 albertel 7302: .$head_extra;
1.962 droeschl 7303: return $result.'</head>';
1.306 albertel 7304: }
7305:
7306: =pod
7307:
1.340 albertel 7308: =item * &font_settings()
7309:
7310: Returns neccessary <meta> to set the proper encoding
7311:
7312: Inputs: none
7313:
7314: =cut
7315:
7316: sub font_settings {
7317: my $headerstring='';
1.647 www 7318: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7319: $headerstring.=
7320: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7321: }
7322: return $headerstring;
7323: }
7324:
1.341 albertel 7325: =pod
7326:
1.1064 raeburn 7327: =item * &print_suppression()
7328:
7329: In course context returns css which causes the body to be blank when media="print",
7330: if printout generation is unavailable for the current resource.
7331:
7332: This could be because:
7333:
7334: (a) printstartdate is in the future
7335:
7336: (b) printenddate is in the past
7337:
7338: (c) there is an active exam block with "printout"
7339: functionality blocked
7340:
7341: Users with pav, pfo or evb privileges are exempt.
7342:
7343: Inputs: none
7344:
7345: =cut
7346:
7347:
7348: sub print_suppression {
7349: my $noprint;
7350: if ($env{'request.course.id'}) {
7351: my $scope = $env{'request.course.id'};
7352: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7353: (&Apache::lonnet::allowed('pfo',$scope))) {
7354: return;
7355: }
7356: if ($env{'request.course.sec'} ne '') {
7357: $scope .= "/$env{'request.course.sec'}";
7358: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7359: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7360: return;
1.1064 raeburn 7361: }
7362: }
7363: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7364: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7365: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7366: if ($blocked) {
7367: my $checkrole = "cm./$cdom/$cnum";
7368: if ($env{'request.course.sec'} ne '') {
7369: $checkrole .= "/$env{'request.course.sec'}";
7370: }
7371: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7372: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7373: $noprint = 1;
7374: }
7375: }
7376: unless ($noprint) {
7377: my $symb = &Apache::lonnet::symbread();
7378: if ($symb ne '') {
7379: my $navmap = Apache::lonnavmaps::navmap->new();
7380: if (ref($navmap)) {
7381: my $res = $navmap->getBySymb($symb);
7382: if (ref($res)) {
7383: if (!$res->resprintable()) {
7384: $noprint = 1;
7385: }
7386: }
7387: }
7388: }
7389: }
7390: if ($noprint) {
7391: return <<"ENDSTYLE";
7392: <style type="text/css" media="print">
7393: body { display:none }
7394: </style>
7395: ENDSTYLE
7396: }
7397: }
7398: return;
7399: }
7400:
7401: =pod
7402:
1.341 albertel 7403: =item * &xml_begin()
7404:
7405: Returns the needed doctype and <html>
7406:
7407: Inputs: none
7408:
7409: =cut
7410:
7411: sub xml_begin {
7412: my $output='';
7413:
7414: if ($env{'browser.mathml'}) {
7415: $output='<?xml version="1.0"?>'
7416: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7417: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7418:
7419: # .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >'
7420: .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
7421: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7422: .'xmlns="http://www.w3.org/1999/xhtml">';
7423: } else {
1.849 bisitz 7424: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7425: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7426: }
7427: return $output;
7428: }
1.340 albertel 7429:
7430: =pod
7431:
1.306 albertel 7432: =item * &start_page()
7433:
7434: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7435:
1.648 raeburn 7436: Inputs:
7437:
7438: =over 4
7439:
7440: $title - optional title for the page
7441:
7442: $head_extra - optional extra HTML to incude inside the <head>
7443:
7444: $args - additional optional args supported are:
7445:
7446: =over 8
7447:
7448: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7449: arg on
1.814 bisitz 7450: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7451: add_entries -> additional attributes to add to the <body>
7452: domain -> force to color decorate a page for a
1.317 albertel 7453: specific domain
1.648 raeburn 7454: function -> force usage of a specific rolish color
1.317 albertel 7455: scheme
1.648 raeburn 7456: redirect -> see &headtag()
7457: bgcolor -> override the default page bg color
7458: js_ready -> return a string ready for being used in
1.317 albertel 7459: a javascript writeln
1.648 raeburn 7460: html_encode -> return a string ready for being used in
1.320 albertel 7461: a html attribute
1.648 raeburn 7462: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7463: $forcereg arg
1.648 raeburn 7464: frameset -> if true will start with a <frameset>
1.330 albertel 7465: rather than <body>
1.648 raeburn 7466: skip_phases -> hash ref of
1.338 albertel 7467: head -> skip the <html><head> generation
7468: body -> skip all <body> generation
1.648 raeburn 7469: no_auto_mt_title -> prevent &mt()ing the title arg
7470: inherit_jsmath -> when creating popup window in a page,
7471: should it have jsmath forced on by the
7472: current page
1.867 kalberla 7473: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7474: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7475: group -> includes the current group, if page is for a
7476: specific group
1.361 albertel 7477:
1.648 raeburn 7478: =back
1.460 albertel 7479:
1.648 raeburn 7480: =back
1.562 albertel 7481:
1.306 albertel 7482: =cut
7483:
7484: sub start_page {
1.309 albertel 7485: my ($title,$head_extra,$args) = @_;
1.318 albertel 7486: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7487:
1.315 albertel 7488: $env{'internal.start_page'}++;
1.1096 raeburn 7489: my ($result,@advtools);
1.964 droeschl 7490:
1.338 albertel 7491: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7492: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7493: }
7494:
7495: if (! exists($args->{'skip_phases'}{'body'}) ) {
7496: if ($args->{'frameset'}) {
7497: my $attr_string = &make_attr_string($args->{'force_register'},
7498: $args->{'add_entries'});
7499: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7500: } else {
7501: $result .=
7502: &bodytag($title,
7503: $args->{'function'}, $args->{'add_entries'},
7504: $args->{'only_body'}, $args->{'domain'},
7505: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7506: $args->{'bgcolor'}, $args,
7507: \@advtools);
1.831 bisitz 7508: }
1.330 albertel 7509: }
1.338 albertel 7510:
1.315 albertel 7511: if ($args->{'js_ready'}) {
1.713 kaisler 7512: $result = &js_ready($result);
1.315 albertel 7513: }
1.320 albertel 7514: if ($args->{'html_encode'}) {
1.713 kaisler 7515: $result = &html_encode($result);
7516: }
7517:
1.813 bisitz 7518: # Preparation for new and consistent functionlist at top of screen
7519: # if ($args->{'functionlist'}) {
7520: # $result .= &build_functionlist();
7521: #}
7522:
1.964 droeschl 7523: # Don't add anything more if only_body wanted or in const space
7524: return $result if $args->{'only_body'}
7525: || $env{'request.state'} eq 'construct';
1.813 bisitz 7526:
7527: #Breadcrumbs
1.758 kaisler 7528: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7529: &Apache::lonhtmlcommon::clear_breadcrumbs();
7530: #if any br links exists, add them to the breadcrumbs
7531: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7532: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7533: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7534: }
7535: }
1.1096 raeburn 7536: # if @advtools array contains items add then to the breadcrumbs
7537: if (@advtools > 0) {
7538: &Apache::lonmenu::advtools_crumbs(@advtools);
7539: }
1.758 kaisler 7540:
7541: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7542: if(exists($args->{'bread_crumbs_component'})){
7543: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7544: }else{
7545: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7546: }
1.320 albertel 7547: }
1.315 albertel 7548: return $result;
1.306 albertel 7549: }
7550:
7551: sub end_page {
1.315 albertel 7552: my ($args) = @_;
7553: $env{'internal.end_page'}++;
1.330 albertel 7554: my $result;
1.335 albertel 7555: if ($args->{'discussion'}) {
7556: my ($target,$parser);
7557: if (ref($args->{'discussion'})) {
7558: ($target,$parser) =($args->{'discussion'}{'target'},
7559: $args->{'discussion'}{'parser'});
7560: }
7561: $result .= &Apache::lonxml::xmlend($target,$parser);
7562: }
1.330 albertel 7563: if ($args->{'frameset'}) {
7564: $result .= '</frameset>';
7565: } else {
1.635 raeburn 7566: $result .= &endbodytag($args);
1.330 albertel 7567: }
1.1080 raeburn 7568: unless ($args->{'notbody'}) {
7569: $result .= "\n</html>";
7570: }
1.330 albertel 7571:
1.315 albertel 7572: if ($args->{'js_ready'}) {
1.317 albertel 7573: $result = &js_ready($result);
1.315 albertel 7574: }
1.335 albertel 7575:
1.320 albertel 7576: if ($args->{'html_encode'}) {
7577: $result = &html_encode($result);
7578: }
1.335 albertel 7579:
1.315 albertel 7580: return $result;
7581: }
7582:
1.1034 www 7583: sub wishlist_window {
7584: return(<<'ENDWISHLIST');
1.1046 raeburn 7585: <script type="text/javascript">
1.1034 www 7586: // <![CDATA[
7587: // <!-- BEGIN LON-CAPA Internal
7588: function set_wishlistlink(title, path) {
7589: if (!title) {
7590: title = document.title;
7591: title = title.replace(/^LON-CAPA /,'');
7592: }
7593: if (!path) {
7594: path = location.pathname;
7595: }
7596: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7597: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7598: }
7599: // END LON-CAPA Internal -->
7600: // ]]>
7601: </script>
7602: ENDWISHLIST
7603: }
7604:
1.1030 www 7605: sub modal_window {
7606: return(<<'ENDMODAL');
1.1046 raeburn 7607: <script type="text/javascript">
1.1030 www 7608: // <![CDATA[
7609: // <!-- BEGIN LON-CAPA Internal
7610: var modalWindow = {
7611: parent:"body",
7612: windowId:null,
7613: content:null,
7614: width:null,
7615: height:null,
7616: close:function()
7617: {
7618: $(".LCmodal-window").remove();
7619: $(".LCmodal-overlay").remove();
7620: },
7621: open:function()
7622: {
7623: var modal = "";
7624: modal += "<div class=\"LCmodal-overlay\"></div>";
7625: modal += "<div id=\"" + this.windowId + "\" class=\"LCmodal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
7626: modal += this.content;
7627: modal += "</div>";
7628:
7629: $(this.parent).append(modal);
7630:
7631: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7632: $(".LCclose-window").click(function(){modalWindow.close();});
7633: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7634: }
7635: };
1.1031 www 7636: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7637: {
7638: modalWindow.windowId = "myModal";
7639: modalWindow.width = width;
7640: modalWindow.height = height;
1.1031 www 7641: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7642: modalWindow.open();
7643: };
7644: // END LON-CAPA Internal -->
7645: // ]]>
7646: </script>
7647: ENDMODAL
7648: }
7649:
7650: sub modal_link {
1.1052 www 7651: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7652: unless ($width) { $width=480; }
7653: unless ($height) { $height=400; }
1.1031 www 7654: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7655: my $target_attr;
7656: if (defined($target)) {
7657: $target_attr = 'target="'.$target.'"';
7658: }
7659: return <<"ENDLINK";
7660: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7661: $linktext</a>
7662: ENDLINK
1.1030 www 7663: }
7664:
1.1032 www 7665: sub modal_adhoc_script {
7666: my ($funcname,$width,$height,$content)=@_;
7667: return (<<ENDADHOC);
1.1046 raeburn 7668: <script type="text/javascript">
1.1032 www 7669: // <![CDATA[
7670: var $funcname = function()
7671: {
7672: modalWindow.windowId = "myModal";
7673: modalWindow.width = $width;
7674: modalWindow.height = $height;
7675: modalWindow.content = '$content';
7676: modalWindow.open();
7677: };
7678: // ]]>
7679: </script>
7680: ENDADHOC
7681: }
7682:
1.1041 www 7683: sub modal_adhoc_inner {
7684: my ($funcname,$width,$height,$content)=@_;
7685: my $innerwidth=$width-20;
7686: $content=&js_ready(
1.1042 www 7687: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041 www 7688: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
7689: $content.
7690: &end_scrollbox().
7691: &end_page()
7692: );
7693: return &modal_adhoc_script($funcname,$width,$height,$content);
7694: }
7695:
7696: sub modal_adhoc_window {
7697: my ($funcname,$width,$height,$content,$linktext)=@_;
7698: return &modal_adhoc_inner($funcname,$width,$height,$content).
7699: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7700: }
7701:
7702: sub modal_adhoc_launch {
7703: my ($funcname,$width,$height,$content)=@_;
7704: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7705: <script type="text/javascript">
7706: // <![CDATA[
7707: $funcname();
7708: // ]]>
7709: </script>
7710: ENDLAUNCH
7711: }
7712:
7713: sub modal_adhoc_close {
7714: return (<<ENDCLOSE);
7715: <script type="text/javascript">
7716: // <![CDATA[
7717: modalWindow.close();
7718: // ]]>
7719: </script>
7720: ENDCLOSE
7721: }
7722:
1.1038 www 7723: sub togglebox_script {
7724: return(<<ENDTOGGLE);
7725: <script type="text/javascript">
7726: // <![CDATA[
7727: function LCtoggleDisplay(id,hidetext,showtext) {
7728: link = document.getElementById(id + "link").childNodes[0];
7729: with (document.getElementById(id).style) {
7730: if (display == "none" ) {
7731: display = "inline";
7732: link.nodeValue = hidetext;
7733: } else {
7734: display = "none";
7735: link.nodeValue = showtext;
7736: }
7737: }
7738: }
7739: // ]]>
7740: </script>
7741: ENDTOGGLE
7742: }
7743:
1.1039 www 7744: sub start_togglebox {
7745: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7746: unless ($heading) { $heading=''; } else { $heading.=' '; }
7747: unless ($showtext) { $showtext=&mt('show'); }
7748: unless ($hidetext) { $hidetext=&mt('hide'); }
7749: unless ($headerbg) { $headerbg='#FFFFFF'; }
7750: return &start_data_table().
7751: &start_data_table_header_row().
7752: '<td bgcolor="'.$headerbg.'">'.$heading.
7753: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7754: $showtext.'\')">'.$showtext.'</a>]</td>'.
7755: &end_data_table_header_row().
7756: '<tr id="'.$id.'" style="display:none""><td>';
7757: }
7758:
7759: sub end_togglebox {
7760: return '</td></tr>'.&end_data_table();
7761: }
7762:
1.1041 www 7763: sub LCprogressbar_script {
1.1045 www 7764: my ($id)=@_;
1.1041 www 7765: return(<<ENDPROGRESS);
7766: <script type="text/javascript">
7767: // <![CDATA[
1.1045 www 7768: \$('#progressbar$id').progressbar({
1.1041 www 7769: value: 0,
7770: change: function(event, ui) {
7771: var newVal = \$(this).progressbar('option', 'value');
7772: \$('.pblabel', this).text(LCprogressTxt);
7773: }
7774: });
7775: // ]]>
7776: </script>
7777: ENDPROGRESS
7778: }
7779:
7780: sub LCprogressbarUpdate_script {
7781: return(<<ENDPROGRESSUPDATE);
7782: <style type="text/css">
7783: .ui-progressbar { position:relative; }
7784: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7785: </style>
7786: <script type="text/javascript">
7787: // <![CDATA[
1.1045 www 7788: var LCprogressTxt='---';
7789:
7790: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7791: LCprogressTxt=progresstext;
1.1045 www 7792: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7793: }
7794: // ]]>
7795: </script>
7796: ENDPROGRESSUPDATE
7797: }
7798:
1.1042 www 7799: my $LClastpercent;
1.1045 www 7800: my $LCidcnt;
7801: my $LCcurrentid;
1.1042 www 7802:
1.1041 www 7803: sub LCprogressbar {
1.1042 www 7804: my ($r)=(@_);
7805: $LClastpercent=0;
1.1045 www 7806: $LCidcnt++;
7807: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7808: my $starting=&mt('Starting');
7809: my $content=(<<ENDPROGBAR);
7810: <p>
1.1045 www 7811: <div id="progressbar$LCcurrentid">
1.1041 www 7812: <span class="pblabel">$starting</span>
7813: </div>
7814: </p>
7815: ENDPROGBAR
1.1045 www 7816: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7817: }
7818:
7819: sub LCprogressbarUpdate {
1.1042 www 7820: my ($r,$val,$text)=@_;
7821: unless ($val) {
7822: if ($LClastpercent) {
7823: $val=$LClastpercent;
7824: } else {
7825: $val=0;
7826: }
7827: }
1.1041 www 7828: if ($val<0) { $val=0; }
7829: if ($val>100) { $val=0; }
1.1042 www 7830: $LClastpercent=$val;
1.1041 www 7831: unless ($text) { $text=$val.'%'; }
7832: $text=&js_ready($text);
1.1044 www 7833: &r_print($r,<<ENDUPDATE);
1.1041 www 7834: <script type="text/javascript">
7835: // <![CDATA[
1.1045 www 7836: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7837: // ]]>
7838: </script>
7839: ENDUPDATE
1.1035 www 7840: }
7841:
1.1042 www 7842: sub LCprogressbarClose {
7843: my ($r)=@_;
7844: $LClastpercent=0;
1.1044 www 7845: &r_print($r,<<ENDCLOSE);
1.1042 www 7846: <script type="text/javascript">
7847: // <![CDATA[
1.1045 www 7848: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7849: // ]]>
7850: </script>
7851: ENDCLOSE
1.1044 www 7852: }
7853:
7854: sub r_print {
7855: my ($r,$to_print)=@_;
7856: if ($r) {
7857: $r->print($to_print);
7858: $r->rflush();
7859: } else {
7860: print($to_print);
7861: }
1.1042 www 7862: }
7863:
1.320 albertel 7864: sub html_encode {
7865: my ($result) = @_;
7866:
1.322 albertel 7867: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7868:
7869: return $result;
7870: }
1.1044 www 7871:
1.317 albertel 7872: sub js_ready {
7873: my ($result) = @_;
7874:
1.323 albertel 7875: $result =~ s/[\n\r]/ /xmsg;
7876: $result =~ s/\\/\\\\/xmsg;
7877: $result =~ s/'/\\'/xmsg;
1.372 albertel 7878: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7879:
7880: return $result;
7881: }
7882:
1.315 albertel 7883: sub validate_page {
7884: if ( exists($env{'internal.start_page'})
1.316 albertel 7885: && $env{'internal.start_page'} > 1) {
7886: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7887: $env{'internal.start_page'}.' '.
1.316 albertel 7888: $ENV{'request.filename'});
1.315 albertel 7889: }
7890: if ( exists($env{'internal.end_page'})
1.316 albertel 7891: && $env{'internal.end_page'} > 1) {
7892: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7893: $env{'internal.end_page'}.' '.
1.316 albertel 7894: $env{'request.filename'});
1.315 albertel 7895: }
7896: if ( exists($env{'internal.start_page'})
7897: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7898: &Apache::lonnet::logthis('start_page called without end_page '.
7899: $env{'request.filename'});
1.315 albertel 7900: }
7901: if ( ! exists($env{'internal.start_page'})
7902: && exists($env{'internal.end_page'})) {
1.316 albertel 7903: &Apache::lonnet::logthis('end_page called without start_page'.
7904: $env{'request.filename'});
1.315 albertel 7905: }
1.306 albertel 7906: }
1.315 albertel 7907:
1.996 www 7908:
7909: sub start_scrollbox {
1.1075 raeburn 7910: my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998 raeburn 7911: unless ($outerwidth) { $outerwidth='520px'; }
7912: unless ($width) { $width='500px'; }
7913: unless ($height) { $height='200px'; }
1.1075 raeburn 7914: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7915: if ($id ne '') {
1.1020 raeburn 7916: $table_id = " id='table_$id'";
7917: $div_id = " id='div_$id'";
1.1018 raeburn 7918: }
1.1075 raeburn 7919: if ($bgcolor ne '') {
7920: $tdcol = "background-color: $bgcolor;";
7921: }
7922: return <<"END";
7923: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
7924: END
1.996 www 7925: }
7926:
7927: sub end_scrollbox {
1.1036 www 7928: return '</div></td></tr></table>';
1.996 www 7929: }
7930:
1.318 albertel 7931: sub simple_error_page {
7932: my ($r,$title,$msg) = @_;
7933: my $page =
7934: &Apache::loncommon::start_page($title).
1.1097 bisitz 7935: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 7936: &Apache::loncommon::end_page();
7937: if (ref($r)) {
7938: $r->print($page);
1.327 albertel 7939: return;
1.318 albertel 7940: }
7941: return $page;
7942: }
1.347 albertel 7943:
7944: {
1.610 albertel 7945: my @row_count;
1.961 onken 7946:
7947: sub start_data_table_count {
7948: unshift(@row_count, 0);
7949: return;
7950: }
7951:
7952: sub end_data_table_count {
7953: shift(@row_count);
7954: return;
7955: }
7956:
1.347 albertel 7957: sub start_data_table {
1.1018 raeburn 7958: my ($add_class,$id) = @_;
1.422 albertel 7959: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7960: my $table_id;
7961: if (defined($id)) {
7962: $table_id = ' id="'.$id.'"';
7963: }
1.961 onken 7964: &start_data_table_count();
1.1018 raeburn 7965: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7966: }
7967:
7968: sub end_data_table {
1.961 onken 7969: &end_data_table_count();
1.389 albertel 7970: return '</table>'."\n";;
1.347 albertel 7971: }
7972:
7973: sub start_data_table_row {
1.974 wenzelju 7974: my ($add_class, $id) = @_;
1.610 albertel 7975: $row_count[0]++;
7976: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7977: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7978: $id = (' id="'.$id.'"') unless ($id eq '');
7979: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7980: }
1.471 banghart 7981:
7982: sub continue_data_table_row {
1.974 wenzelju 7983: my ($add_class, $id) = @_;
1.610 albertel 7984: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7985: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7986: $id = (' id="'.$id.'"') unless ($id eq '');
7987: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7988: }
1.347 albertel 7989:
7990: sub end_data_table_row {
1.389 albertel 7991: return '</tr>'."\n";;
1.347 albertel 7992: }
1.367 www 7993:
1.421 albertel 7994: sub start_data_table_empty_row {
1.707 bisitz 7995: # $row_count[0]++;
1.421 albertel 7996: return '<tr class="LC_empty_row" >'."\n";;
7997: }
7998:
7999: sub end_data_table_empty_row {
8000: return '</tr>'."\n";;
8001: }
8002:
1.367 www 8003: sub start_data_table_header_row {
1.389 albertel 8004: return '<tr class="LC_header_row">'."\n";;
1.367 www 8005: }
8006:
8007: sub end_data_table_header_row {
1.389 albertel 8008: return '</tr>'."\n";;
1.367 www 8009: }
1.890 droeschl 8010:
8011: sub data_table_caption {
8012: my $caption = shift;
8013: return "<caption class=\"LC_caption\">$caption</caption>";
8014: }
1.347 albertel 8015: }
8016:
1.548 albertel 8017: =pod
8018:
8019: =item * &inhibit_menu_check($arg)
8020:
8021: Checks for a inhibitmenu state and generates output to preserve it
8022:
8023: Inputs: $arg - can be any of
8024: - undef - in which case the return value is a string
8025: to add into arguments list of a uri
8026: - 'input' - in which case the return value is a HTML
8027: <form> <input> field of type hidden to
8028: preserve the value
8029: - a url - in which case the return value is the url with
8030: the neccesary cgi args added to preserve the
8031: inhibitmenu state
8032: - a ref to a url - no return value, but the string is
8033: updated to include the neccessary cgi
8034: args to preserve the inhibitmenu state
8035:
8036: =cut
8037:
8038: sub inhibit_menu_check {
8039: my ($arg) = @_;
8040: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8041: if ($arg eq 'input') {
8042: if ($env{'form.inhibitmenu'}) {
8043: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8044: } else {
8045: return
8046: }
8047: }
8048: if ($env{'form.inhibitmenu'}) {
8049: if (ref($arg)) {
8050: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8051: } elsif ($arg eq '') {
8052: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8053: } else {
8054: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8055: }
8056: }
8057: if (!ref($arg)) {
8058: return $arg;
8059: }
8060: }
8061:
1.251 albertel 8062: ###############################################
1.182 matthew 8063:
8064: =pod
8065:
1.549 albertel 8066: =back
8067:
8068: =head1 User Information Routines
8069:
8070: =over 4
8071:
1.405 albertel 8072: =item * &get_users_function()
1.182 matthew 8073:
8074: Used by &bodytag to determine the current users primary role.
8075: Returns either 'student','coordinator','admin', or 'author'.
8076:
8077: =cut
8078:
8079: ###############################################
8080: sub get_users_function {
1.815 tempelho 8081: my $function = 'norole';
1.818 tempelho 8082: if ($env{'request.role'}=~/^(st)/) {
8083: $function='student';
8084: }
1.907 raeburn 8085: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8086: $function='coordinator';
8087: }
1.258 albertel 8088: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8089: $function='admin';
8090: }
1.826 bisitz 8091: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8092: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8093: $function='author';
8094: }
8095: return $function;
1.54 www 8096: }
1.99 www 8097:
8098: ###############################################
8099:
1.233 raeburn 8100: =pod
8101:
1.821 raeburn 8102: =item * &show_course()
8103:
8104: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8105: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8106:
8107: Inputs:
8108: None
8109:
8110: Outputs:
8111: Scalar: 1 if 'Course' to be used, 0 otherwise.
8112:
8113: =cut
8114:
8115: ###############################################
8116: sub show_course {
8117: my $course = !$env{'user.adv'};
8118: if (!$env{'user.adv'}) {
8119: foreach my $env (keys(%env)) {
8120: next if ($env !~ m/^user\.priv\./);
8121: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8122: $course = 0;
8123: last;
8124: }
8125: }
8126: }
8127: return $course;
8128: }
8129:
8130: ###############################################
8131:
8132: =pod
8133:
1.542 raeburn 8134: =item * &check_user_status()
1.274 raeburn 8135:
8136: Determines current status of supplied role for a
8137: specific user. Roles can be active, previous or future.
8138:
8139: Inputs:
8140: user's domain, user's username, course's domain,
1.375 raeburn 8141: course's number, optional section ID.
1.274 raeburn 8142:
8143: Outputs:
8144: role status: active, previous or future.
8145:
8146: =cut
8147:
8148: sub check_user_status {
1.412 raeburn 8149: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8150: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8151: my @uroles = keys %userinfo;
8152: my $srchstr;
8153: my $active_chk = 'none';
1.412 raeburn 8154: my $now = time;
1.274 raeburn 8155: if (@uroles > 0) {
1.908 raeburn 8156: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8157: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8158: } else {
1.412 raeburn 8159: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8160: }
8161: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8162: my $role_end = 0;
8163: my $role_start = 0;
8164: $active_chk = 'active';
1.412 raeburn 8165: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8166: $role_end = $1;
8167: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8168: $role_start = $1;
1.274 raeburn 8169: }
8170: }
8171: if ($role_start > 0) {
1.412 raeburn 8172: if ($now < $role_start) {
1.274 raeburn 8173: $active_chk = 'future';
8174: }
8175: }
8176: if ($role_end > 0) {
1.412 raeburn 8177: if ($now > $role_end) {
1.274 raeburn 8178: $active_chk = 'previous';
8179: }
8180: }
8181: }
8182: }
8183: return $active_chk;
8184: }
8185:
8186: ###############################################
8187:
8188: =pod
8189:
1.405 albertel 8190: =item * &get_sections()
1.233 raeburn 8191:
8192: Determines all the sections for a course including
8193: sections with students and sections containing other roles.
1.419 raeburn 8194: Incoming parameters:
8195:
8196: 1. domain
8197: 2. course number
8198: 3. reference to array containing roles for which sections should
8199: be gathered (optional).
8200: 4. reference to array containing status types for which sections
8201: should be gathered (optional).
8202:
8203: If the third argument is undefined, sections are gathered for any role.
8204: If the fourth argument is undefined, sections are gathered for any status.
8205: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8206:
1.374 raeburn 8207: Returns section hash (keys are section IDs, values are
8208: number of users in each section), subject to the
1.419 raeburn 8209: optional roles filter, optional status filter
1.233 raeburn 8210:
8211: =cut
8212:
8213: ###############################################
8214: sub get_sections {
1.419 raeburn 8215: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8216: if (!defined($cdom) || !defined($cnum)) {
8217: my $cid = $env{'request.course.id'};
8218:
8219: return if (!defined($cid));
8220:
8221: $cdom = $env{'course.'.$cid.'.domain'};
8222: $cnum = $env{'course.'.$cid.'.num'};
8223: }
8224:
8225: my %sectioncount;
1.419 raeburn 8226: my $now = time;
1.240 albertel 8227:
1.1118 raeburn 8228: my $check_students = 1;
8229: my $only_students = 0;
8230: if (ref($possible_roles) eq 'ARRAY') {
8231: if (grep(/^st$/,@{$possible_roles})) {
8232: if (@{$possible_roles} == 1) {
8233: $only_students = 1;
8234: }
8235: } else {
8236: $check_students = 0;
8237: }
8238: }
8239:
8240: if ($check_students) {
1.276 albertel 8241: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8242: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8243: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8244: my $start_index = &Apache::loncoursedata::CL_START();
8245: my $end_index = &Apache::loncoursedata::CL_END();
8246: my $status;
1.366 albertel 8247: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8248: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8249: $data->[$status_index],
8250: $data->[$start_index],
8251: $data->[$end_index]);
8252: if ($stu_status eq 'Active') {
8253: $status = 'active';
8254: } elsif ($end < $now) {
8255: $status = 'previous';
8256: } elsif ($start > $now) {
8257: $status = 'future';
8258: }
8259: if ($section ne '-1' && $section !~ /^\s*$/) {
8260: if ((!defined($possible_status)) || (($status ne '') &&
8261: (grep/^\Q$status\E$/,@{$possible_status}))) {
8262: $sectioncount{$section}++;
8263: }
1.240 albertel 8264: }
8265: }
8266: }
1.1118 raeburn 8267: if ($only_students) {
8268: return %sectioncount;
8269: }
1.240 albertel 8270: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8271: foreach my $user (sort(keys(%courseroles))) {
8272: if ($user !~ /^(\w{2})/) { next; }
8273: my ($role) = ($user =~ /^(\w{2})/);
8274: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8275: my ($section,$status);
1.240 albertel 8276: if ($role eq 'cr' &&
8277: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8278: $section=$1;
8279: }
8280: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8281: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8282: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8283: if ($end == -1 && $start == -1) {
8284: next; #deleted role
8285: }
8286: if (!defined($possible_status)) {
8287: $sectioncount{$section}++;
8288: } else {
8289: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8290: $status = 'active';
8291: } elsif ($end < $now) {
8292: $status = 'future';
8293: } elsif ($start > $now) {
8294: $status = 'previous';
8295: }
8296: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8297: $sectioncount{$section}++;
8298: }
8299: }
1.233 raeburn 8300: }
1.366 albertel 8301: return %sectioncount;
1.233 raeburn 8302: }
8303:
1.274 raeburn 8304: ###############################################
1.294 raeburn 8305:
8306: =pod
1.405 albertel 8307:
8308: =item * &get_course_users()
8309:
1.275 raeburn 8310: Retrieves usernames:domains for users in the specified course
8311: with specific role(s), and access status.
8312:
8313: Incoming parameters:
1.277 albertel 8314: 1. course domain
8315: 2. course number
8316: 3. access status: users must have - either active,
1.275 raeburn 8317: previous, future, or all.
1.277 albertel 8318: 4. reference to array of permissible roles
1.288 raeburn 8319: 5. reference to array of section restrictions (optional)
8320: 6. reference to results object (hash of hashes).
8321: 7. reference to optional userdata hash
1.609 raeburn 8322: 8. reference to optional statushash
1.630 raeburn 8323: 9. flag if privileged users (except those set to unhide in
8324: course settings) should be excluded
1.609 raeburn 8325: Keys of top level results hash are roles.
1.275 raeburn 8326: Keys of inner hashes are username:domain, with
8327: values set to access type.
1.288 raeburn 8328: Optional userdata hash returns an array with arguments in the
8329: same order as loncoursedata::get_classlist() for student data.
8330:
1.609 raeburn 8331: Optional statushash returns
8332:
1.288 raeburn 8333: Entries for end, start, section and status are blank because
8334: of the possibility of multiple values for non-student roles.
8335:
1.275 raeburn 8336: =cut
1.405 albertel 8337:
1.275 raeburn 8338: ###############################################
1.405 albertel 8339:
1.275 raeburn 8340: sub get_course_users {
1.630 raeburn 8341: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8342: my %idx = ();
1.419 raeburn 8343: my %seclists;
1.288 raeburn 8344:
8345: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8346: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8347: $idx{end} = &Apache::loncoursedata::CL_END();
8348: $idx{start} = &Apache::loncoursedata::CL_START();
8349: $idx{id} = &Apache::loncoursedata::CL_ID();
8350: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8351: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8352: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8353:
1.290 albertel 8354: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8355: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8356: my $now = time;
1.277 albertel 8357: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8358: my $match = 0;
1.412 raeburn 8359: my $secmatch = 0;
1.419 raeburn 8360: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8361: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8362: if ($section eq '') {
8363: $section = 'none';
8364: }
1.291 albertel 8365: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8366: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8367: $secmatch = 1;
8368: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8369: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8370: $secmatch = 1;
8371: }
8372: } else {
1.419 raeburn 8373: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8374: $secmatch = 1;
8375: }
1.290 albertel 8376: }
1.412 raeburn 8377: if (!$secmatch) {
8378: next;
8379: }
1.419 raeburn 8380: }
1.275 raeburn 8381: if (defined($$types{'active'})) {
1.288 raeburn 8382: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8383: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8384: $match = 1;
1.275 raeburn 8385: }
8386: }
8387: if (defined($$types{'previous'})) {
1.609 raeburn 8388: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8389: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8390: $match = 1;
1.275 raeburn 8391: }
8392: }
8393: if (defined($$types{'future'})) {
1.609 raeburn 8394: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8395: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8396: $match = 1;
1.275 raeburn 8397: }
8398: }
1.609 raeburn 8399: if ($match) {
8400: push(@{$seclists{$student}},$section);
8401: if (ref($userdata) eq 'HASH') {
8402: $$userdata{$student} = $$classlist{$student};
8403: }
8404: if (ref($statushash) eq 'HASH') {
8405: $statushash->{$student}{'st'}{$section} = $status;
8406: }
1.288 raeburn 8407: }
1.275 raeburn 8408: }
8409: }
1.412 raeburn 8410: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8411: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8412: my $now = time;
1.609 raeburn 8413: my %displaystatus = ( previous => 'Expired',
8414: active => 'Active',
8415: future => 'Future',
8416: );
1.630 raeburn 8417: my %nothide;
8418: if ($hidepriv) {
8419: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8420: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8421: if ($user !~ /:/) {
8422: $nothide{join(':',split(/[\@]/,$user))}=1;
8423: } else {
8424: $nothide{$user} = 1;
8425: }
8426: }
8427: }
1.439 raeburn 8428: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8429: my $match = 0;
1.412 raeburn 8430: my $secmatch = 0;
1.439 raeburn 8431: my $status;
1.412 raeburn 8432: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8433: $user =~ s/:$//;
1.439 raeburn 8434: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8435: if ($end == -1 || $start == -1) {
8436: next;
8437: }
8438: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8439: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8440: my ($uname,$udom) = split(/:/,$user);
8441: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8442: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8443: $secmatch = 1;
8444: } elsif ($usec eq '') {
1.420 albertel 8445: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8446: $secmatch = 1;
8447: }
8448: } else {
8449: if (grep(/^\Q$usec\E$/,@{$sections})) {
8450: $secmatch = 1;
8451: }
8452: }
8453: if (!$secmatch) {
8454: next;
8455: }
1.288 raeburn 8456: }
1.419 raeburn 8457: if ($usec eq '') {
8458: $usec = 'none';
8459: }
1.275 raeburn 8460: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8461: if ($hidepriv) {
8462: if ((&Apache::lonnet::privileged($uname,$udom)) &&
8463: (!$nothide{$uname.':'.$udom})) {
8464: next;
8465: }
8466: }
1.503 raeburn 8467: if ($end > 0 && $end < $now) {
1.439 raeburn 8468: $status = 'previous';
8469: } elsif ($start > $now) {
8470: $status = 'future';
8471: } else {
8472: $status = 'active';
8473: }
1.277 albertel 8474: foreach my $type (keys(%{$types})) {
1.275 raeburn 8475: if ($status eq $type) {
1.420 albertel 8476: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8477: push(@{$$users{$role}{$user}},$type);
8478: }
1.288 raeburn 8479: $match = 1;
8480: }
8481: }
1.419 raeburn 8482: if (($match) && (ref($userdata) eq 'HASH')) {
8483: if (!exists($$userdata{$uname.':'.$udom})) {
8484: &get_user_info($udom,$uname,\%idx,$userdata);
8485: }
1.420 albertel 8486: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8487: push(@{$seclists{$uname.':'.$udom}},$usec);
8488: }
1.609 raeburn 8489: if (ref($statushash) eq 'HASH') {
8490: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8491: }
1.275 raeburn 8492: }
8493: }
8494: }
8495: }
1.290 albertel 8496: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8497: if ((defined($cdom)) && (defined($cnum))) {
8498: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8499: if ( defined($csettings{'internal.courseowner'}) ) {
8500: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8501: next if ($owner eq '');
8502: my ($ownername,$ownerdom);
8503: if ($owner =~ /^([^:]+):([^:]+)$/) {
8504: $ownername = $1;
8505: $ownerdom = $2;
8506: } else {
8507: $ownername = $owner;
8508: $ownerdom = $cdom;
8509: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8510: }
8511: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8512: if (defined($userdata) &&
1.609 raeburn 8513: !exists($$userdata{$owner})) {
8514: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8515: if (!grep(/^none$/,@{$seclists{$owner}})) {
8516: push(@{$seclists{$owner}},'none');
8517: }
8518: if (ref($statushash) eq 'HASH') {
8519: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8520: }
1.290 albertel 8521: }
1.279 raeburn 8522: }
8523: }
8524: }
1.419 raeburn 8525: foreach my $user (keys(%seclists)) {
8526: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8527: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8528: }
1.275 raeburn 8529: }
8530: return;
8531: }
8532:
1.288 raeburn 8533: sub get_user_info {
8534: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8535: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8536: &plainname($uname,$udom,'lastname');
1.291 albertel 8537: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8538: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8539: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8540: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8541: return;
8542: }
1.275 raeburn 8543:
1.472 raeburn 8544: ###############################################
8545:
8546: =pod
8547:
8548: =item * &get_user_quota()
8549:
8550: Retrieves quota assigned for storage of portfolio files for a user
8551:
8552: Incoming parameters:
8553: 1. user's username
8554: 2. user's domain
8555:
8556: Returns:
1.536 raeburn 8557: 1. Disk quota (in Mb) assigned to student.
8558: 2. (Optional) Type of setting: custom or default
8559: (individually assigned or default for user's
8560: institutional status).
8561: 3. (Optional) - User's institutional status (e.g., faculty, staff
8562: or student - types as defined in localenroll::inst_usertypes
8563: for user's domain, which determines default quota for user.
8564: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8565:
8566: If a value has been stored in the user's environment,
1.536 raeburn 8567: it will return that, otherwise it returns the maximal default
8568: defined for the user's instituional status(es) in the domain.
1.472 raeburn 8569:
8570: =cut
8571:
8572: ###############################################
8573:
8574:
8575: sub get_user_quota {
8576: my ($uname,$udom) = @_;
1.536 raeburn 8577: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8578: if (!defined($udom)) {
8579: $udom = $env{'user.domain'};
8580: }
8581: if (!defined($uname)) {
8582: $uname = $env{'user.name'};
8583: }
8584: if (($udom eq '' || $uname eq '') ||
8585: ($udom eq 'public') && ($uname eq 'public')) {
8586: $quota = 0;
1.536 raeburn 8587: $quotatype = 'default';
8588: $defquota = 0;
1.472 raeburn 8589: } else {
1.536 raeburn 8590: my $inststatus;
1.472 raeburn 8591: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8592: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 8593: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 8594: } else {
1.536 raeburn 8595: my %userenv =
8596: &Apache::lonnet::get('environment',['portfolioquota',
8597: 'inststatus'],$udom,$uname);
1.472 raeburn 8598: my ($tmp) = keys(%userenv);
8599: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8600: $quota = $userenv{'portfolioquota'};
1.536 raeburn 8601: $inststatus = $userenv{'inststatus'};
1.472 raeburn 8602: } else {
8603: undef(%userenv);
8604: }
8605: }
1.536 raeburn 8606: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 8607: if ($quota eq '') {
1.536 raeburn 8608: $quota = $defquota;
8609: $quotatype = 'default';
8610: } else {
8611: $quotatype = 'custom';
1.472 raeburn 8612: }
8613: }
1.536 raeburn 8614: if (wantarray) {
8615: return ($quota,$quotatype,$settingstatus,$defquota);
8616: } else {
8617: return $quota;
8618: }
1.472 raeburn 8619: }
8620:
8621: ###############################################
8622:
8623: =pod
8624:
8625: =item * &default_quota()
8626:
1.536 raeburn 8627: Retrieves default quota assigned for storage of user portfolio files,
8628: given an (optional) user's institutional status.
1.472 raeburn 8629:
8630: Incoming parameters:
8631: 1. domain
1.536 raeburn 8632: 2. (Optional) institutional status(es). This is a : separated list of
8633: status types (e.g., faculty, staff, student etc.)
8634: which apply to the user for whom the default is being retrieved.
8635: If the institutional status string in undefined, the domain
8636: default quota will be returned.
1.472 raeburn 8637:
8638: Returns:
8639: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8640: 2. (Optional) institutional type which determined the value of the
8641: default quota.
1.472 raeburn 8642:
8643: If a value has been stored in the domain's configuration db,
8644: it will return that, otherwise it returns 20 (for backwards
8645: compatibility with domains which have not set up a configuration
8646: db file; the original statically defined portfolio quota was 20 Mb).
8647:
1.536 raeburn 8648: If the user's status includes multiple types (e.g., staff and student),
8649: the largest default quota which applies to the user determines the
8650: default quota returned.
8651:
1.780 raeburn 8652: =back
8653:
1.472 raeburn 8654: =cut
8655:
8656: ###############################################
8657:
8658:
8659: sub default_quota {
1.536 raeburn 8660: my ($udom,$inststatus) = @_;
8661: my ($defquota,$settingstatus);
8662: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8663: ['quotas'],$udom);
8664: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8665: if ($inststatus ne '') {
1.765 raeburn 8666: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8667: foreach my $item (@statuses) {
1.711 raeburn 8668: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8669: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
8670: if ($defquota eq '') {
8671: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8672: $settingstatus = $item;
8673: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
8674: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8675: $settingstatus = $item;
8676: }
8677: }
8678: } else {
8679: if ($quotahash{'quotas'}{$item} ne '') {
8680: if ($defquota eq '') {
8681: $defquota = $quotahash{'quotas'}{$item};
8682: $settingstatus = $item;
8683: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8684: $defquota = $quotahash{'quotas'}{$item};
8685: $settingstatus = $item;
8686: }
1.536 raeburn 8687: }
8688: }
8689: }
8690: }
8691: if ($defquota eq '') {
1.711 raeburn 8692: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8693: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
8694: } else {
8695: $defquota = $quotahash{'quotas'}{'default'};
8696: }
1.536 raeburn 8697: $settingstatus = 'default';
8698: }
8699: } else {
8700: $settingstatus = 'default';
8701: $defquota = 20;
8702: }
8703: if (wantarray) {
8704: return ($defquota,$settingstatus);
1.472 raeburn 8705: } else {
1.536 raeburn 8706: return $defquota;
1.472 raeburn 8707: }
8708: }
8709:
1.384 raeburn 8710: sub get_secgrprole_info {
8711: my ($cdom,$cnum,$needroles,$type) = @_;
8712: my %sections_count = &get_sections($cdom,$cnum);
8713: my @sections = (sort {$a <=> $b} keys(%sections_count));
8714: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8715: my @groups = sort(keys(%curr_groups));
8716: my $allroles = [];
8717: my $rolehash;
8718: my $accesshash = {
8719: active => 'Currently has access',
8720: future => 'Will have future access',
8721: previous => 'Previously had access',
8722: };
8723: if ($needroles) {
8724: $rolehash = {'all' => 'all'};
1.385 albertel 8725: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8726: if (&Apache::lonnet::error(%user_roles)) {
8727: undef(%user_roles);
8728: }
8729: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8730: my ($role)=split(/\:/,$item,2);
8731: if ($role eq 'cr') { next; }
8732: if ($role =~ /^cr/) {
8733: $$rolehash{$role} = (split('/',$role))[3];
8734: } else {
8735: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8736: }
8737: }
8738: foreach my $key (sort(keys(%{$rolehash}))) {
8739: push(@{$allroles},$key);
8740: }
8741: push (@{$allroles},'st');
8742: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8743: }
8744: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8745: }
8746:
1.555 raeburn 8747: sub user_picker {
1.994 raeburn 8748: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8749: my $currdom = $dom;
8750: my %curr_selected = (
8751: srchin => 'dom',
1.580 raeburn 8752: srchby => 'lastname',
1.555 raeburn 8753: );
8754: my $srchterm;
1.625 raeburn 8755: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8756: if ($srch->{'srchby'} ne '') {
8757: $curr_selected{'srchby'} = $srch->{'srchby'};
8758: }
8759: if ($srch->{'srchin'} ne '') {
8760: $curr_selected{'srchin'} = $srch->{'srchin'};
8761: }
8762: if ($srch->{'srchtype'} ne '') {
8763: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8764: }
8765: if ($srch->{'srchdomain'} ne '') {
8766: $currdom = $srch->{'srchdomain'};
8767: }
8768: $srchterm = $srch->{'srchterm'};
8769: }
8770: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8771: 'usr' => 'Search criteria',
1.563 raeburn 8772: 'doma' => 'Domain/institution to search',
1.558 albertel 8773: 'uname' => 'username',
8774: 'lastname' => 'last name',
1.555 raeburn 8775: 'lastfirst' => 'last name, first name',
1.558 albertel 8776: 'crs' => 'in this course',
1.576 raeburn 8777: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8778: 'alc' => 'all LON-CAPA',
1.573 raeburn 8779: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8780: 'exact' => 'is',
8781: 'contains' => 'contains',
1.569 raeburn 8782: 'begins' => 'begins with',
1.571 raeburn 8783: 'youm' => "You must include some text to search for.",
8784: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8785: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8786: 'yomc' => "You must choose a domain when using an institutional directory search.",
8787: 'ymcd' => "You must choose a domain when using a domain search.",
8788: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8789: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8790: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8791: );
1.563 raeburn 8792: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8793: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8794:
8795: my @srchins = ('crs','dom','alc','instd');
8796:
8797: foreach my $option (@srchins) {
8798: # FIXME 'alc' option unavailable until
8799: # loncreateuser::print_user_query_page()
8800: # has been completed.
8801: next if ($option eq 'alc');
1.880 raeburn 8802: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8803: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8804: if ($curr_selected{'srchin'} eq $option) {
8805: $srchinsel .= '
8806: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8807: } else {
8808: $srchinsel .= '
8809: <option value="'.$option.'">'.$lt{$option}.'</option>';
8810: }
1.555 raeburn 8811: }
1.563 raeburn 8812: $srchinsel .= "\n </select>\n";
1.555 raeburn 8813:
8814: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 8815: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 8816: if ($curr_selected{'srchby'} eq $option) {
8817: $srchbysel .= '
8818: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8819: } else {
8820: $srchbysel .= '
8821: <option value="'.$option.'">'.$lt{$option}.'</option>';
8822: }
8823: }
8824: $srchbysel .= "\n </select>\n";
8825:
8826: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 8827: foreach my $option ('begins','contains','exact') {
1.555 raeburn 8828: if ($curr_selected{'srchtype'} eq $option) {
8829: $srchtypesel .= '
8830: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8831: } else {
8832: $srchtypesel .= '
8833: <option value="'.$option.'">'.$lt{$option}.'</option>';
8834: }
8835: }
8836: $srchtypesel .= "\n </select>\n";
8837:
1.558 albertel 8838: my ($newuserscript,$new_user_create);
1.994 raeburn 8839: my $context_dom = $env{'request.role.domain'};
8840: if ($context eq 'requestcrs') {
8841: if ($env{'form.coursedom'} ne '') {
8842: $context_dom = $env{'form.coursedom'};
8843: }
8844: }
1.556 raeburn 8845: if ($forcenewuser) {
1.576 raeburn 8846: if (ref($srch) eq 'HASH') {
1.994 raeburn 8847: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8848: if ($cancreate) {
8849: $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>';
8850: } else {
1.799 bisitz 8851: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8852: my %usertypetext = (
8853: official => 'institutional',
8854: unofficial => 'non-institutional',
8855: );
1.799 bisitz 8856: $new_user_create = '<p class="LC_warning">'
8857: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
8858: .' '
8859: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8860: ,'<a href="'.$helplink.'">','</a>')
8861: .'</p><br />';
1.627 raeburn 8862: }
1.576 raeburn 8863: }
8864: }
8865:
1.556 raeburn 8866: $newuserscript = <<"ENDSCRIPT";
8867:
1.570 raeburn 8868: function setSearch(createnew,callingForm) {
1.556 raeburn 8869: if (createnew == 1) {
1.570 raeburn 8870: for (var i=0; i<callingForm.srchby.length; i++) {
8871: if (callingForm.srchby.options[i].value == 'uname') {
8872: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8873: }
8874: }
1.570 raeburn 8875: for (var i=0; i<callingForm.srchin.length; i++) {
8876: if ( callingForm.srchin.options[i].value == 'dom') {
8877: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8878: }
8879: }
1.570 raeburn 8880: for (var i=0; i<callingForm.srchtype.length; i++) {
8881: if (callingForm.srchtype.options[i].value == 'exact') {
8882: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8883: }
8884: }
1.570 raeburn 8885: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 8886: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8887: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8888: }
8889: }
8890: }
8891: }
8892: ENDSCRIPT
1.558 albertel 8893:
1.556 raeburn 8894: }
8895:
1.555 raeburn 8896: my $output = <<"END_BLOCK";
1.556 raeburn 8897: <script type="text/javascript">
1.824 bisitz 8898: // <![CDATA[
1.570 raeburn 8899: function validateEntry(callingForm) {
1.558 albertel 8900:
1.556 raeburn 8901: var checkok = 1;
1.558 albertel 8902: var srchin;
1.570 raeburn 8903: for (var i=0; i<callingForm.srchin.length; i++) {
8904: if ( callingForm.srchin[i].checked ) {
8905: srchin = callingForm.srchin[i].value;
1.558 albertel 8906: }
8907: }
8908:
1.570 raeburn 8909: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8910: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8911: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8912: var srchterm = callingForm.srchterm.value;
8913: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8914: var msg = "";
8915:
8916: if (srchterm == "") {
8917: checkok = 0;
1.571 raeburn 8918: msg += "$lt{'youm'}\\n";
1.556 raeburn 8919: }
8920:
1.569 raeburn 8921: if (srchtype== 'begins') {
8922: if (srchterm.length < 2) {
8923: checkok = 0;
1.571 raeburn 8924: msg += "$lt{'thte'}\\n";
1.569 raeburn 8925: }
8926: }
8927:
1.556 raeburn 8928: if (srchtype== 'contains') {
8929: if (srchterm.length < 3) {
8930: checkok = 0;
1.571 raeburn 8931: msg += "$lt{'thet'}\\n";
1.556 raeburn 8932: }
8933: }
8934: if (srchin == 'instd') {
8935: if (srchdomain == '') {
8936: checkok = 0;
1.571 raeburn 8937: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8938: }
8939: }
8940: if (srchin == 'dom') {
8941: if (srchdomain == '') {
8942: checkok = 0;
1.571 raeburn 8943: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8944: }
8945: }
8946: if (srchby == 'lastfirst') {
8947: if (srchterm.indexOf(",") == -1) {
8948: checkok = 0;
1.571 raeburn 8949: msg += "$lt{'whus'}\\n";
1.556 raeburn 8950: }
8951: if (srchterm.indexOf(",") == srchterm.length -1) {
8952: checkok = 0;
1.571 raeburn 8953: msg += "$lt{'whse'}\\n";
1.556 raeburn 8954: }
8955: }
8956: if (checkok == 0) {
1.571 raeburn 8957: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8958: return;
8959: }
8960: if (checkok == 1) {
1.570 raeburn 8961: callingForm.submit();
1.556 raeburn 8962: }
8963: }
8964:
8965: $newuserscript
8966:
1.824 bisitz 8967: // ]]>
1.556 raeburn 8968: </script>
1.558 albertel 8969:
8970: $new_user_create
8971:
1.555 raeburn 8972: END_BLOCK
1.558 albertel 8973:
1.876 raeburn 8974: $output .= &Apache::lonhtmlcommon::start_pick_box().
8975: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8976: $domform.
8977: &Apache::lonhtmlcommon::row_closure().
8978: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8979: $srchbysel.
8980: $srchtypesel.
8981: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8982: $srchinsel.
8983: &Apache::lonhtmlcommon::row_closure(1).
8984: &Apache::lonhtmlcommon::end_pick_box().
8985: '<br />';
1.555 raeburn 8986: return $output;
8987: }
8988:
1.612 raeburn 8989: sub user_rule_check {
1.615 raeburn 8990: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8991: my $response;
8992: if (ref($usershash) eq 'HASH') {
8993: foreach my $user (keys(%{$usershash})) {
8994: my ($uname,$udom) = split(/:/,$user);
8995: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8996: my ($id,$newuser);
1.612 raeburn 8997: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8998: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8999: $id = $usershash->{$user}->{'id'};
9000: }
9001: my $inst_response;
9002: if (ref($checks) eq 'HASH') {
9003: if (defined($checks->{'username'})) {
1.615 raeburn 9004: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9005: &Apache::lonnet::get_instuser($udom,$uname);
9006: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9007: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9008: &Apache::lonnet::get_instuser($udom,undef,$id);
9009: }
1.615 raeburn 9010: } else {
9011: ($inst_response,%{$inst_results->{$user}}) =
9012: &Apache::lonnet::get_instuser($udom,$uname);
9013: return;
1.612 raeburn 9014: }
1.615 raeburn 9015: if (!$got_rules->{$udom}) {
1.612 raeburn 9016: my %domconfig = &Apache::lonnet::get_dom('configuration',
9017: ['usercreation'],$udom);
9018: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9019: foreach my $item ('username','id') {
1.612 raeburn 9020: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9021: $$curr_rules{$udom}{$item} =
9022: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9023: }
9024: }
9025: }
1.615 raeburn 9026: $got_rules->{$udom} = 1;
1.585 raeburn 9027: }
1.612 raeburn 9028: foreach my $item (keys(%{$checks})) {
9029: if (ref($$curr_rules{$udom}) eq 'HASH') {
9030: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9031: if (@{$$curr_rules{$udom}{$item}} > 0) {
9032: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9033: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9034: if ($rule_check{$rule}) {
9035: $$rulematch{$user}{$item} = $rule;
9036: if ($inst_response eq 'ok') {
1.615 raeburn 9037: if (ref($inst_results) eq 'HASH') {
9038: if (ref($inst_results->{$user}) eq 'HASH') {
9039: if (keys(%{$inst_results->{$user}}) == 0) {
9040: $$alerts{$item}{$udom}{$uname} = 1;
9041: }
1.612 raeburn 9042: }
9043: }
1.615 raeburn 9044: }
9045: last;
1.585 raeburn 9046: }
9047: }
9048: }
9049: }
9050: }
9051: }
9052: }
9053: }
1.612 raeburn 9054: return;
9055: }
9056:
9057: sub user_rule_formats {
9058: my ($domain,$domdesc,$curr_rules,$check) = @_;
9059: my %text = (
9060: 'username' => 'Usernames',
9061: 'id' => 'IDs',
9062: );
9063: my $output;
9064: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9065: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9066: if (@{$ruleorder} > 0) {
1.1102 raeburn 9067: $output = '<br />'.
9068: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9069: '<span class="LC_cusr_emph">','</span>',$domdesc).
9070: ' <ul>';
1.612 raeburn 9071: foreach my $rule (@{$ruleorder}) {
9072: if (ref($curr_rules) eq 'ARRAY') {
9073: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9074: if (ref($rules->{$rule}) eq 'HASH') {
9075: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9076: $rules->{$rule}{'desc'}.'</li>';
9077: }
9078: }
9079: }
9080: }
9081: $output .= '</ul>';
9082: }
9083: }
9084: return $output;
9085: }
9086:
9087: sub instrule_disallow_msg {
1.615 raeburn 9088: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9089: my $response;
9090: my %text = (
9091: item => 'username',
9092: items => 'usernames',
9093: match => 'matches',
9094: do => 'does',
9095: action => 'a username',
9096: one => 'one',
9097: );
9098: if ($count > 1) {
9099: $text{'item'} = 'usernames';
9100: $text{'match'} ='match';
9101: $text{'do'} = 'do';
9102: $text{'action'} = 'usernames',
9103: $text{'one'} = 'ones';
9104: }
9105: if ($checkitem eq 'id') {
9106: $text{'items'} = 'IDs';
9107: $text{'item'} = 'ID';
9108: $text{'action'} = 'an ID';
1.615 raeburn 9109: if ($count > 1) {
9110: $text{'item'} = 'IDs';
9111: $text{'action'} = 'IDs';
9112: }
1.612 raeburn 9113: }
1.674 bisitz 9114: $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 9115: if ($mode eq 'upload') {
9116: if ($checkitem eq 'username') {
9117: $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'}.");
9118: } elsif ($checkitem eq 'id') {
1.674 bisitz 9119: $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 9120: }
1.669 raeburn 9121: } elsif ($mode eq 'selfcreate') {
9122: if ($checkitem eq 'id') {
9123: $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.");
9124: }
1.615 raeburn 9125: } else {
9126: if ($checkitem eq 'username') {
9127: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9128: } elsif ($checkitem eq 'id') {
9129: $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.");
9130: }
1.612 raeburn 9131: }
9132: return $response;
1.585 raeburn 9133: }
9134:
1.624 raeburn 9135: sub personal_data_fieldtitles {
9136: my %fieldtitles = &Apache::lonlocal::texthash (
9137: id => 'Student/Employee ID',
9138: permanentemail => 'E-mail address',
9139: lastname => 'Last Name',
9140: firstname => 'First Name',
9141: middlename => 'Middle Name',
9142: generation => 'Generation',
9143: gen => 'Generation',
1.765 raeburn 9144: inststatus => 'Affiliation',
1.624 raeburn 9145: );
9146: return %fieldtitles;
9147: }
9148:
1.642 raeburn 9149: sub sorted_inst_types {
9150: my ($dom) = @_;
9151: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9152: my $othertitle = &mt('All users');
9153: if ($env{'request.course.id'}) {
1.668 raeburn 9154: $othertitle = &mt('Any users');
1.642 raeburn 9155: }
9156: my @types;
9157: if (ref($order) eq 'ARRAY') {
9158: @types = @{$order};
9159: }
9160: if (@types == 0) {
9161: if (ref($usertypes) eq 'HASH') {
9162: @types = sort(keys(%{$usertypes}));
9163: }
9164: }
9165: if (keys(%{$usertypes}) > 0) {
9166: $othertitle = &mt('Other users');
9167: }
9168: return ($othertitle,$usertypes,\@types);
9169: }
9170:
1.645 raeburn 9171: sub get_institutional_codes {
9172: my ($settings,$allcourses,$LC_code) = @_;
9173: # Get complete list of course sections to update
9174: my @currsections = ();
9175: my @currxlists = ();
9176: my $coursecode = $$settings{'internal.coursecode'};
9177:
9178: if ($$settings{'internal.sectionnums'} ne '') {
9179: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9180: }
9181:
9182: if ($$settings{'internal.crosslistings'} ne '') {
9183: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9184: }
9185:
9186: if (@currxlists > 0) {
9187: foreach (@currxlists) {
9188: if (m/^([^:]+):(\w*)$/) {
9189: unless (grep/^$1$/,@{$allcourses}) {
9190: push @{$allcourses},$1;
9191: $$LC_code{$1} = $2;
9192: }
9193: }
9194: }
9195: }
9196:
9197: if (@currsections > 0) {
9198: foreach (@currsections) {
9199: if (m/^(\w+):(\w*)$/) {
9200: my $sec = $coursecode.$1;
9201: my $lc_sec = $2;
9202: unless (grep/^$sec$/,@{$allcourses}) {
9203: push @{$allcourses},$sec;
9204: $$LC_code{$sec} = $lc_sec;
9205: }
9206: }
9207: }
9208: }
9209: return;
9210: }
9211:
1.971 raeburn 9212: sub get_standard_codeitems {
9213: return ('Year','Semester','Department','Number','Section');
9214: }
9215:
1.112 bowersj2 9216: =pod
9217:
1.780 raeburn 9218: =head1 Slot Helpers
9219:
9220: =over 4
9221:
9222: =item * sorted_slots()
9223:
1.1040 raeburn 9224: Sorts an array of slot names in order of an optional sort key,
9225: default sort is by slot start time (earliest first).
1.780 raeburn 9226:
9227: Inputs:
9228:
9229: =over 4
9230:
9231: slotsarr - Reference to array of unsorted slot names.
9232:
9233: slots - Reference to hash of hash, where outer hash keys are slot names.
9234:
1.1040 raeburn 9235: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9236:
1.549 albertel 9237: =back
9238:
1.780 raeburn 9239: Returns:
9240:
9241: =over 4
9242:
1.1040 raeburn 9243: sorted - An array of slot names sorted by a specified sort key
9244: (default sort key is start time of the slot).
1.780 raeburn 9245:
9246: =back
9247:
9248: =cut
9249:
9250:
9251: sub sorted_slots {
1.1040 raeburn 9252: my ($slotsarr,$slots,$sortkey) = @_;
9253: if ($sortkey eq '') {
9254: $sortkey = 'starttime';
9255: }
1.780 raeburn 9256: my @sorted;
9257: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9258: @sorted =
9259: sort {
9260: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9261: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9262: }
9263: if (ref($slots->{$a})) { return -1;}
9264: if (ref($slots->{$b})) { return 1;}
9265: return 0;
9266: } @{$slotsarr};
9267: }
9268: return @sorted;
9269: }
9270:
1.1040 raeburn 9271: =pod
9272:
9273: =item * get_future_slots()
9274:
9275: Inputs:
9276:
9277: =over 4
9278:
9279: cnum - course number
9280:
9281: cdom - course domain
9282:
9283: now - current UNIX time
9284:
9285: symb - optional symb
9286:
9287: =back
9288:
9289: Returns:
9290:
9291: =over 4
9292:
9293: sorted_reservable - ref to array of student_schedulable slots currently
9294: reservable, ordered by end date of reservation period.
9295:
9296: reservable_now - ref to hash of student_schedulable slots currently
9297: reservable.
9298:
9299: Keys in inner hash are:
9300: (a) symb: either blank or symb to which slot use is restricted.
9301: (b) endreserve: end date of reservation period.
9302:
9303: sorted_future - ref to array of student_schedulable slots reservable in
9304: the future, ordered by start date of reservation period.
9305:
9306: future_reservable - ref to hash of student_schedulable slots reservable
9307: in the future.
9308:
9309: Keys in inner hash are:
9310: (a) symb: either blank or symb to which slot use is restricted.
9311: (b) startreserve: start date of reservation period.
9312:
9313: =back
9314:
9315: =cut
9316:
9317: sub get_future_slots {
9318: my ($cnum,$cdom,$now,$symb) = @_;
9319: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9320: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9321: foreach my $slot (keys(%slots)) {
9322: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9323: if ($symb) {
9324: next if (($slots{$slot}->{'symb'} ne '') &&
9325: ($slots{$slot}->{'symb'} ne $symb));
9326: }
9327: if (($slots{$slot}->{'starttime'} > $now) &&
9328: ($slots{$slot}->{'endtime'} > $now)) {
9329: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9330: my $userallowed = 0;
9331: if ($slots{$slot}->{'allowedsections'}) {
9332: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9333: if (!defined($env{'request.role.sec'})
9334: && grep(/^No section assigned$/,@allowed_sec)) {
9335: $userallowed=1;
9336: } else {
9337: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9338: $userallowed=1;
9339: }
9340: }
9341: unless ($userallowed) {
9342: if (defined($env{'request.course.groups'})) {
9343: my @groups = split(/:/,$env{'request.course.groups'});
9344: foreach my $group (@groups) {
9345: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9346: $userallowed=1;
9347: last;
9348: }
9349: }
9350: }
9351: }
9352: }
9353: if ($slots{$slot}->{'allowedusers'}) {
9354: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9355: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9356: if (grep(/^\Q$user\E$/,@allowed_users)) {
9357: $userallowed = 1;
9358: }
9359: }
9360: next unless($userallowed);
9361: }
9362: my $startreserve = $slots{$slot}->{'startreserve'};
9363: my $endreserve = $slots{$slot}->{'endreserve'};
9364: my $symb = $slots{$slot}->{'symb'};
9365: if (($startreserve < $now) &&
9366: (!$endreserve || $endreserve > $now)) {
9367: my $lastres = $endreserve;
9368: if (!$lastres) {
9369: $lastres = $slots{$slot}->{'starttime'};
9370: }
9371: $reservable_now{$slot} = {
9372: symb => $symb,
9373: endreserve => $lastres
9374: };
9375: } elsif (($startreserve > $now) &&
9376: (!$endreserve || $endreserve > $startreserve)) {
9377: $future_reservable{$slot} = {
9378: symb => $symb,
9379: startreserve => $startreserve
9380: };
9381: }
9382: }
9383: }
9384: my @unsorted_reservable = keys(%reservable_now);
9385: if (@unsorted_reservable > 0) {
9386: @sorted_reservable =
9387: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9388: }
9389: my @unsorted_future = keys(%future_reservable);
9390: if (@unsorted_future > 0) {
9391: @sorted_future =
9392: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9393: }
9394: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9395: }
1.780 raeburn 9396:
9397: =pod
9398:
1.1057 foxr 9399: =back
9400:
1.549 albertel 9401: =head1 HTTP Helpers
9402:
9403: =over 4
9404:
1.648 raeburn 9405: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9406:
1.258 albertel 9407: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9408: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9409: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9410:
9411: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9412: $possible_names is an ref to an array of form element names. As an example:
9413: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9414: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9415:
9416: =cut
1.1 albertel 9417:
1.6 albertel 9418: sub get_unprocessed_cgi {
1.25 albertel 9419: my ($query,$possible_names)= @_;
1.26 matthew 9420: # $Apache::lonxml::debug=1;
1.356 albertel 9421: foreach my $pair (split(/&/,$query)) {
9422: my ($name, $value) = split(/=/,$pair);
1.369 www 9423: $name = &unescape($name);
1.25 albertel 9424: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9425: $value =~ tr/+/ /;
9426: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9427: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9428: }
1.16 harris41 9429: }
1.6 albertel 9430: }
9431:
1.112 bowersj2 9432: =pod
9433:
1.648 raeburn 9434: =item * &cacheheader()
1.112 bowersj2 9435:
9436: returns cache-controlling header code
9437:
9438: =cut
9439:
1.7 albertel 9440: sub cacheheader {
1.258 albertel 9441: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9442: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9443: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9444: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9445: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9446: return $output;
1.7 albertel 9447: }
9448:
1.112 bowersj2 9449: =pod
9450:
1.648 raeburn 9451: =item * &no_cache($r)
1.112 bowersj2 9452:
9453: specifies header code to not have cache
9454:
9455: =cut
9456:
1.9 albertel 9457: sub no_cache {
1.216 albertel 9458: my ($r) = @_;
9459: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9460: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9461: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9462: $r->no_cache(1);
9463: $r->header_out("Expires" => $date);
9464: $r->header_out("Pragma" => "no-cache");
1.123 www 9465: }
9466:
9467: sub content_type {
1.181 albertel 9468: my ($r,$type,$charset) = @_;
1.299 foxr 9469: if ($r) {
9470: # Note that printout.pl calls this with undef for $r.
9471: &no_cache($r);
9472: }
1.258 albertel 9473: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9474: unless ($charset) {
9475: $charset=&Apache::lonlocal::current_encoding;
9476: }
9477: if ($charset) { $type.='; charset='.$charset; }
9478: if ($r) {
9479: $r->content_type($type);
9480: } else {
9481: print("Content-type: $type\n\n");
9482: }
1.9 albertel 9483: }
1.25 albertel 9484:
1.112 bowersj2 9485: =pod
9486:
1.648 raeburn 9487: =item * &add_to_env($name,$value)
1.112 bowersj2 9488:
1.258 albertel 9489: adds $name to the %env hash with value
1.112 bowersj2 9490: $value, if $name already exists, the entry is converted to an array
9491: reference and $value is added to the array.
9492:
9493: =cut
9494:
1.25 albertel 9495: sub add_to_env {
9496: my ($name,$value)=@_;
1.258 albertel 9497: if (defined($env{$name})) {
9498: if (ref($env{$name})) {
1.25 albertel 9499: #already have multiple values
1.258 albertel 9500: push(@{ $env{$name} },$value);
1.25 albertel 9501: } else {
9502: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9503: my $first=$env{$name};
9504: undef($env{$name});
9505: push(@{ $env{$name} },$first,$value);
1.25 albertel 9506: }
9507: } else {
1.258 albertel 9508: $env{$name}=$value;
1.25 albertel 9509: }
1.31 albertel 9510: }
1.149 albertel 9511:
9512: =pod
9513:
1.648 raeburn 9514: =item * &get_env_multiple($name)
1.149 albertel 9515:
1.258 albertel 9516: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9517: values may be defined and end up as an array ref.
9518:
9519: returns an array of values
9520:
9521: =cut
9522:
9523: sub get_env_multiple {
9524: my ($name) = @_;
9525: my @values;
1.258 albertel 9526: if (defined($env{$name})) {
1.149 albertel 9527: # exists is it an array
1.258 albertel 9528: if (ref($env{$name})) {
9529: @values=@{ $env{$name} };
1.149 albertel 9530: } else {
1.258 albertel 9531: $values[0]=$env{$name};
1.149 albertel 9532: }
9533: }
9534: return(@values);
9535: }
9536:
1.660 raeburn 9537: sub ask_for_embedded_content {
9538: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9539: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9540: %currsubfile,%unused,$rem);
1.1071 raeburn 9541: my $counter = 0;
9542: my $numnew = 0;
1.987 raeburn 9543: my $numremref = 0;
9544: my $numinvalid = 0;
9545: my $numpathchg = 0;
9546: my $numexisting = 0;
1.1071 raeburn 9547: my $numunused = 0;
9548: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9549: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9550: my $heading = &mt('Upload embedded files');
9551: my $buttontext = &mt('Upload');
9552:
1.1085 raeburn 9553: my $navmap;
9554: if ($env{'request.course.id'}) {
9555: $navmap = Apache::lonnavmaps::navmap->new();
9556: }
1.984 raeburn 9557: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9558: my $current_path='/';
9559: if ($env{'form.currentpath'}) {
9560: $current_path = $env{'form.currentpath'};
9561: }
9562: if ($actionurl eq '/adm/coursegrp_portfolio') {
9563: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9564: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
9565: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9566: } else {
9567: $udom = $env{'user.domain'};
9568: $uname = $env{'user.name'};
9569: $url = '/userfiles/portfolio';
9570: }
1.987 raeburn 9571: $toplevel = $url.'/';
1.984 raeburn 9572: $url .= $current_path;
9573: $getpropath = 1;
1.987 raeburn 9574: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9575: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9576: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9577: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9578: $toplevel = $url;
1.984 raeburn 9579: if ($rest ne '') {
1.987 raeburn 9580: $url .= $rest;
9581: }
9582: } elsif ($actionurl eq '/adm/coursedocs') {
9583: if (ref($args) eq 'HASH') {
1.1071 raeburn 9584: $url = $args->{'docs_url'};
9585: $toplevel = $url;
1.1084 raeburn 9586: if ($args->{'context'} eq 'paste') {
9587: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9588: ($path) =
9589: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9590: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9591: $fileloc =~ s{^/}{};
9592: }
1.1071 raeburn 9593: }
1.1084 raeburn 9594: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9595: if ($env{'request.course.id'} ne '') {
9596: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9597: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9598: if (ref($args) eq 'HASH') {
9599: $url = $args->{'docs_url'};
9600: $title = $args->{'docs_title'};
9601: $toplevel = "/$url";
1.1085 raeburn 9602: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071 raeburn 9603: ($path) =
9604: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9605: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9606: $fileloc =~ s{^/}{};
9607: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9608: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9609: }
1.987 raeburn 9610: }
9611: }
9612: my $now = time();
9613: foreach my $embed_file (keys(%{$allfiles})) {
9614: my $absolutepath;
9615: if ($embed_file =~ m{^\w+://}) {
9616: $newfiles{$embed_file} = 1;
9617: $mapping{$embed_file} = $embed_file;
9618: } else {
9619: if ($embed_file =~ m{^/}) {
9620: $absolutepath = $embed_file;
9621: $embed_file =~ s{^(/+)}{};
9622: }
9623: if ($embed_file =~ m{/}) {
9624: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9625: $path = &check_for_traversal($path,$url,$toplevel);
9626: my $item = $fname;
9627: if ($path ne '') {
9628: $item = $path.'/'.$fname;
9629: $subdependencies{$path}{$fname} = 1;
9630: } else {
9631: $dependencies{$item} = 1;
9632: }
9633: if ($absolutepath) {
9634: $mapping{$item} = $absolutepath;
9635: } else {
9636: $mapping{$item} = $embed_file;
9637: }
9638: } else {
9639: $dependencies{$embed_file} = 1;
9640: if ($absolutepath) {
9641: $mapping{$embed_file} = $absolutepath;
9642: } else {
9643: $mapping{$embed_file} = $embed_file;
9644: }
9645: }
1.984 raeburn 9646: }
9647: }
1.1071 raeburn 9648: my $dirptr = 16384;
1.984 raeburn 9649: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9650: $currsubfile{$path} = {};
1.984 raeburn 9651: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9652: my ($sublistref,$listerror) =
9653: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9654: if (ref($sublistref) eq 'ARRAY') {
9655: foreach my $line (@{$sublistref}) {
9656: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9657: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9658: }
1.984 raeburn 9659: }
1.987 raeburn 9660: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9661: if (opendir(my $dir,$url.'/'.$path)) {
9662: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9663: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9664: }
1.1084 raeburn 9665: } elsif (($actionurl eq '/adm/dependencies') ||
9666: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9667: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9668: if ($env{'request.course.id'} ne '') {
9669: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9670: if ($dir ne '') {
9671: my ($sublistref,$listerror) =
9672: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9673: if (ref($sublistref) eq 'ARRAY') {
9674: foreach my $line (@{$sublistref}) {
9675: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9676: undef,$mtime)=split(/\&/,$line,12);
9677: unless (($testdir&$dirptr) ||
9678: ($file_name =~ /^\.\.?$/)) {
9679: $currsubfile{$path}{$file_name} = [$size,$mtime];
9680: }
9681: }
9682: }
9683: }
1.984 raeburn 9684: }
9685: }
9686: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9687: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9688: my $item = $path.'/'.$file;
9689: unless ($mapping{$item} eq $item) {
9690: $pathchanges{$item} = 1;
9691: }
9692: $existing{$item} = 1;
9693: $numexisting ++;
9694: } else {
9695: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9696: }
9697: }
1.1071 raeburn 9698: if ($actionurl eq '/adm/dependencies') {
9699: foreach my $path (keys(%currsubfile)) {
9700: if (ref($currsubfile{$path}) eq 'HASH') {
9701: foreach my $file (keys(%{$currsubfile{$path}})) {
9702: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9703: next if (($rem ne '') &&
9704: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9705: (ref($navmap) &&
9706: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9707: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9708: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9709: $unused{$path.'/'.$file} = 1;
9710: }
9711: }
9712: }
9713: }
9714: }
1.984 raeburn 9715: }
1.987 raeburn 9716: my %currfile;
1.984 raeburn 9717: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9718: my ($dirlistref,$listerror) =
9719: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9720: if (ref($dirlistref) eq 'ARRAY') {
9721: foreach my $line (@{$dirlistref}) {
9722: my ($file_name,$rest) = split(/\&/,$line,2);
9723: $currfile{$file_name} = 1;
9724: }
1.984 raeburn 9725: }
1.987 raeburn 9726: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9727: if (opendir(my $dir,$url)) {
1.987 raeburn 9728: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9729: map {$currfile{$_} = 1;} @dir_list;
9730: }
1.1084 raeburn 9731: } elsif (($actionurl eq '/adm/dependencies') ||
9732: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9733: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9734: if ($env{'request.course.id'} ne '') {
9735: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9736: if ($dir ne '') {
9737: my ($dirlistref,$listerror) =
9738: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9739: if (ref($dirlistref) eq 'ARRAY') {
9740: foreach my $line (@{$dirlistref}) {
9741: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9742: $size,undef,$mtime)=split(/\&/,$line,12);
9743: unless (($testdir&$dirptr) ||
9744: ($file_name =~ /^\.\.?$/)) {
9745: $currfile{$file_name} = [$size,$mtime];
9746: }
9747: }
9748: }
9749: }
9750: }
1.984 raeburn 9751: }
9752: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9753: if (exists($currfile{$file})) {
1.987 raeburn 9754: unless ($mapping{$file} eq $file) {
9755: $pathchanges{$file} = 1;
9756: }
9757: $existing{$file} = 1;
9758: $numexisting ++;
9759: } else {
1.984 raeburn 9760: $newfiles{$file} = 1;
9761: }
9762: }
1.1071 raeburn 9763: foreach my $file (keys(%currfile)) {
9764: unless (($file eq $filename) ||
9765: ($file eq $filename.'.bak') ||
9766: ($dependencies{$file})) {
1.1085 raeburn 9767: if ($actionurl eq '/adm/dependencies') {
9768: next if (($rem ne '') &&
9769: (($env{"httpref.$rem".$file} ne '') ||
9770: (ref($navmap) &&
9771: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9772: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9773: ($navmap->getResourceByUrl($rem.$1)))))));
9774: }
1.1071 raeburn 9775: $unused{$file} = 1;
9776: }
9777: }
1.1084 raeburn 9778: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9779: ($args->{'context'} eq 'paste')) {
9780: $counter = scalar(keys(%existing));
9781: $numpathchg = scalar(keys(%pathchanges));
9782: return ($output,$counter,$numpathchg,\%existing);
9783: }
1.984 raeburn 9784: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 9785: if ($actionurl eq '/adm/dependencies') {
9786: next if ($embed_file =~ m{^\w+://});
9787: }
1.660 raeburn 9788: $upload_output .= &start_data_table_row().
1.1071 raeburn 9789: '<td><img src="'.&icon($embed_file).'" /> '.
9790: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 9791: unless ($mapping{$embed_file} eq $embed_file) {
9792: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
9793: }
9794: $upload_output .= '</td><td>';
1.1071 raeburn 9795: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.660 raeburn 9796: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 9797: $numremref++;
1.660 raeburn 9798: } elsif ($args->{'error_on_invalid_names'}
9799: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987 raeburn 9800: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
9801: $numinvalid++;
1.660 raeburn 9802: } else {
1.1071 raeburn 9803: $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 9804: $embed_file,\%mapping,
1.1071 raeburn 9805: $allfiles,$codebase,'upload');
9806: $counter ++;
9807: $numnew ++;
1.987 raeburn 9808: }
9809: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
9810: }
9811: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 9812: if ($actionurl eq '/adm/dependencies') {
9813: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
9814: $modify_output .= &start_data_table_row().
9815: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
9816: '<img src="'.&icon($embed_file).'" border="0" />'.
9817: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
9818: '<td>'.$size.'</td>'.
9819: '<td>'.$mtime.'</td>'.
9820: '<td><label><input type="checkbox" name="mod_upload_dep" '.
9821: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
9822: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
9823: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
9824: &embedded_file_element('upload_embedded',$counter,
9825: $embed_file,\%mapping,
9826: $allfiles,$codebase,'modify').
9827: '</div></td>'.
9828: &end_data_table_row()."\n";
9829: $counter ++;
9830: } else {
9831: $upload_output .= &start_data_table_row().
9832: '<td><span class="LC_filename">'.$embed_file.'</span></td>';
9833: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
9834: &Apache::loncommon::end_data_table_row()."\n";
9835: }
9836: }
9837: my $delidx = $counter;
9838: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
9839: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
9840: $delete_output .= &start_data_table_row().
9841: '<td><img src="'.&icon($oldfile).'" />'.
9842: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
9843: '<td>'.$size.'</td>'.
9844: '<td>'.$mtime.'</td>'.
9845: '<td><label><input type="checkbox" name="del_upload_dep" '.
9846: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
9847: &embedded_file_element('upload_embedded',$delidx,
9848: $oldfile,\%mapping,$allfiles,
9849: $codebase,'delete').'</td>'.
9850: &end_data_table_row()."\n";
9851: $numunused ++;
9852: $delidx ++;
1.987 raeburn 9853: }
9854: if ($upload_output) {
9855: $upload_output = &start_data_table().
9856: $upload_output.
9857: &end_data_table()."\n";
9858: }
1.1071 raeburn 9859: if ($modify_output) {
9860: $modify_output = &start_data_table().
9861: &start_data_table_header_row().
9862: '<th>'.&mt('File').'</th>'.
9863: '<th>'.&mt('Size (KB)').'</th>'.
9864: '<th>'.&mt('Modified').'</th>'.
9865: '<th>'.&mt('Upload replacement?').'</th>'.
9866: &end_data_table_header_row().
9867: $modify_output.
9868: &end_data_table()."\n";
9869: }
9870: if ($delete_output) {
9871: $delete_output = &start_data_table().
9872: &start_data_table_header_row().
9873: '<th>'.&mt('File').'</th>'.
9874: '<th>'.&mt('Size (KB)').'</th>'.
9875: '<th>'.&mt('Modified').'</th>'.
9876: '<th>'.&mt('Delete?').'</th>'.
9877: &end_data_table_header_row().
9878: $delete_output.
9879: &end_data_table()."\n";
9880: }
1.987 raeburn 9881: my $applies = 0;
9882: if ($numremref) {
9883: $applies ++;
9884: }
9885: if ($numinvalid) {
9886: $applies ++;
9887: }
9888: if ($numexisting) {
9889: $applies ++;
9890: }
1.1071 raeburn 9891: if ($counter || $numunused) {
1.987 raeburn 9892: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
9893: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 9894: $state.'<h3>'.$heading.'</h3>';
9895: if ($actionurl eq '/adm/dependencies') {
9896: if ($numnew) {
9897: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
9898: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
9899: $upload_output.'<br />'."\n";
9900: }
9901: if ($numexisting) {
9902: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
9903: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
9904: $modify_output.'<br />'."\n";
9905: $buttontext = &mt('Save changes');
9906: }
9907: if ($numunused) {
9908: $output .= '<h4>'.&mt('Unused files').'</h4>'.
9909: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
9910: $delete_output.'<br />'."\n";
9911: $buttontext = &mt('Save changes');
9912: }
9913: } else {
9914: $output .= $upload_output.'<br />'."\n";
9915: }
9916: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
9917: $counter.'" />'."\n";
9918: if ($actionurl eq '/adm/dependencies') {
9919: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
9920: $numnew.'" />'."\n";
9921: } elsif ($actionurl eq '') {
1.987 raeburn 9922: $output .= '<input type="hidden" name="phase" value="three" />';
9923: }
9924: } elsif ($applies) {
9925: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
9926: if ($applies > 1) {
9927: $output .=
9928: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
9929: if ($numremref) {
9930: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
9931: }
9932: if ($numinvalid) {
9933: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
9934: }
9935: if ($numexisting) {
9936: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
9937: }
9938: $output .= '</ul><br />';
9939: } elsif ($numremref) {
9940: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
9941: } elsif ($numinvalid) {
9942: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
9943: } elsif ($numexisting) {
9944: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
9945: }
9946: $output .= $upload_output.'<br />';
9947: }
9948: my ($pathchange_output,$chgcount);
1.1071 raeburn 9949: $chgcount = $counter;
1.987 raeburn 9950: if (keys(%pathchanges) > 0) {
9951: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 9952: if ($counter) {
1.987 raeburn 9953: $output .= &embedded_file_element('pathchange',$chgcount,
9954: $embed_file,\%mapping,
1.1071 raeburn 9955: $allfiles,$codebase,'change');
1.987 raeburn 9956: } else {
9957: $pathchange_output .=
9958: &start_data_table_row().
9959: '<td><input type ="checkbox" name="namechange" value="'.
9960: $chgcount.'" checked="checked" /></td>'.
9961: '<td>'.$mapping{$embed_file}.'</td>'.
9962: '<td>'.$embed_file.
9963: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 9964: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 9965: '</td>'.&end_data_table_row();
1.660 raeburn 9966: }
1.987 raeburn 9967: $numpathchg ++;
9968: $chgcount ++;
1.660 raeburn 9969: }
9970: }
1.1071 raeburn 9971: if ($counter) {
1.987 raeburn 9972: if ($numpathchg) {
9973: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
9974: $numpathchg.'" />'."\n";
9975: }
9976: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9977: ($actionurl eq '/adm/imsimport')) {
9978: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
9979: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
9980: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 9981: } elsif ($actionurl eq '/adm/dependencies') {
9982: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 9983: }
1.1071 raeburn 9984: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 9985: } elsif ($numpathchg) {
9986: my %pathchange = ();
9987: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
9988: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9989: $output .= '<p>'.&mt('or').'</p>';
9990: }
9991: }
1.1071 raeburn 9992: return ($output,$counter,$numpathchg);
1.987 raeburn 9993: }
9994:
9995: sub embedded_file_element {
1.1071 raeburn 9996: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 9997: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
9998: (ref($codebase) eq 'HASH'));
9999: my $output;
1.1071 raeburn 10000: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10001: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10002: }
10003: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10004: &escape($embed_file).'" />';
10005: unless (($context eq 'upload_embedded') &&
10006: ($mapping->{$embed_file} eq $embed_file)) {
10007: $output .='
10008: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10009: }
10010: my $attrib;
10011: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10012: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10013: }
10014: $output .=
10015: "\n\t\t".
10016: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10017: $attrib.'" />';
10018: if (exists($codebase->{$mapping->{$embed_file}})) {
10019: $output .=
10020: "\n\t\t".
10021: '<input name="codebase_'.$num.'" type="hidden" value="'.
10022: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10023: }
1.987 raeburn 10024: return $output;
1.660 raeburn 10025: }
10026:
1.1071 raeburn 10027: sub get_dependency_details {
10028: my ($currfile,$currsubfile,$embed_file) = @_;
10029: my ($size,$mtime,$showsize,$showmtime);
10030: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10031: if ($embed_file =~ m{/}) {
10032: my ($path,$fname) = split(/\//,$embed_file);
10033: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10034: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10035: }
10036: } else {
10037: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10038: ($size,$mtime) = @{$currfile->{$embed_file}};
10039: }
10040: }
10041: $showsize = $size/1024.0;
10042: $showsize = sprintf("%.1f",$showsize);
10043: if ($mtime > 0) {
10044: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10045: }
10046: }
10047: return ($showsize,$showmtime);
10048: }
10049:
10050: sub ask_embedded_js {
10051: return <<"END";
10052: <script type="text/javascript"">
10053: // <![CDATA[
10054: function toggleBrowse(counter) {
10055: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10056: var fileid = document.getElementById('embedded_item_'+counter);
10057: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10058: if (chkboxid.checked == true) {
10059: uploaddivid.style.display='block';
10060: } else {
10061: uploaddivid.style.display='none';
10062: fileid.value = '';
10063: }
10064: }
10065: // ]]>
10066: </script>
10067:
10068: END
10069: }
10070:
1.661 raeburn 10071: sub upload_embedded {
10072: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10073: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10074: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10075: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10076: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10077: my $orig_uploaded_filename =
10078: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10079: foreach my $type ('orig','ref','attrib','codebase') {
10080: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10081: $env{'form.embedded_'.$type.'_'.$i} =
10082: &unescape($env{'form.embedded_'.$type.'_'.$i});
10083: }
10084: }
1.661 raeburn 10085: my ($path,$fname) =
10086: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10087: # no path, whole string is fname
10088: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10089: $fname = &Apache::lonnet::clean_filename($fname);
10090: # See if there is anything left
10091: next if ($fname eq '');
10092:
10093: # Check if file already exists as a file or directory.
10094: my ($state,$msg);
10095: if ($context eq 'portfolio') {
10096: my $port_path = $dirpath;
10097: if ($group ne '') {
10098: $port_path = "groups/$group/$port_path";
10099: }
1.987 raeburn 10100: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10101: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10102: $dir_root,$port_path,$disk_quota,
10103: $current_disk_usage,$uname,$udom);
10104: if ($state eq 'will_exceed_quota'
1.984 raeburn 10105: || $state eq 'file_locked') {
1.661 raeburn 10106: $output .= $msg;
10107: next;
10108: }
10109: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10110: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10111: if ($state eq 'exists') {
10112: $output .= $msg;
10113: next;
10114: }
10115: }
10116: # Check if extension is valid
10117: if (($fname =~ /\.(\w+)$/) &&
10118: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10119: $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 10120: next;
10121: } elsif (($fname =~ /\.(\w+)$/) &&
10122: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10123: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10124: next;
10125: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 10126: $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 10127: next;
10128: }
10129: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
10130: if ($context eq 'portfolio') {
1.984 raeburn 10131: my $result;
10132: if ($state eq 'existingfile') {
10133: $result=
10134: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 10135: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 10136: } else {
1.984 raeburn 10137: $result=
10138: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10139: $dirpath.
10140: $env{'form.currentpath'}.$path);
1.984 raeburn 10141: if ($result !~ m|^/uploaded/|) {
10142: $output .= '<span class="LC_error">'
10143: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10144: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10145: .'</span><br />';
10146: next;
10147: } else {
1.987 raeburn 10148: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10149: $path.$fname.'</span>').'<br />';
1.984 raeburn 10150: }
1.661 raeburn 10151: }
1.987 raeburn 10152: } elsif ($context eq 'coursedoc') {
10153: my $result =
10154: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
10155: $dirpath.'/'.$path);
10156: if ($result !~ m|^/uploaded/|) {
10157: $output .= '<span class="LC_error">'
10158: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10159: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10160: .'</span><br />';
10161: next;
10162: } else {
10163: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10164: $path.$fname.'</span>').'<br />';
10165: }
1.661 raeburn 10166: } else {
10167: # Save the file
10168: my $target = $env{'form.embedded_item_'.$i};
10169: my $fullpath = $dir_root.$dirpath.'/'.$path;
10170: my $dest = $fullpath.$fname;
10171: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10172: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10173: my $count;
10174: my $filepath = $dir_root;
1.1027 raeburn 10175: foreach my $subdir (@parts) {
10176: $filepath .= "/$subdir";
10177: if (!-e $filepath) {
1.661 raeburn 10178: mkdir($filepath,0770);
10179: }
10180: }
10181: my $fh;
10182: if (!open($fh,'>'.$dest)) {
10183: &Apache::lonnet::logthis('Failed to create '.$dest);
10184: $output .= '<span class="LC_error">'.
1.1071 raeburn 10185: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10186: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10187: '</span><br />';
10188: } else {
10189: if (!print $fh $env{'form.embedded_item_'.$i}) {
10190: &Apache::lonnet::logthis('Failed to write to '.$dest);
10191: $output .= '<span class="LC_error">'.
1.1071 raeburn 10192: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10193: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10194: '</span><br />';
10195: } else {
1.987 raeburn 10196: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10197: $url.'</span>').'<br />';
10198: unless ($context eq 'testbank') {
10199: $footer .= &mt('View embedded file: [_1]',
10200: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10201: }
10202: }
10203: close($fh);
10204: }
10205: }
10206: if ($env{'form.embedded_ref_'.$i}) {
10207: $pathchange{$i} = 1;
10208: }
10209: }
10210: if ($output) {
10211: $output = '<p>'.$output.'</p>';
10212: }
10213: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10214: $returnflag = 'ok';
1.1071 raeburn 10215: my $numpathchgs = scalar(keys(%pathchange));
10216: if ($numpathchgs > 0) {
1.987 raeburn 10217: if ($context eq 'portfolio') {
10218: $output .= '<p>'.&mt('or').'</p>';
10219: } elsif ($context eq 'testbank') {
1.1071 raeburn 10220: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10221: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10222: $returnflag = 'modify_orightml';
10223: }
10224: }
1.1071 raeburn 10225: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10226: }
10227:
10228: sub modify_html_form {
10229: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10230: my $end = 0;
10231: my $modifyform;
10232: if ($context eq 'upload_embedded') {
10233: return unless (ref($pathchange) eq 'HASH');
10234: if ($env{'form.number_embedded_items'}) {
10235: $end += $env{'form.number_embedded_items'};
10236: }
10237: if ($env{'form.number_pathchange_items'}) {
10238: $end += $env{'form.number_pathchange_items'};
10239: }
10240: if ($end) {
10241: for (my $i=0; $i<$end; $i++) {
10242: if ($i < $env{'form.number_embedded_items'}) {
10243: next unless($pathchange->{$i});
10244: }
10245: $modifyform .=
10246: &start_data_table_row().
10247: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10248: 'checked="checked" /></td>'.
10249: '<td>'.$env{'form.embedded_ref_'.$i}.
10250: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10251: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10252: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10253: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10254: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10255: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10256: '<td>'.$env{'form.embedded_orig_'.$i}.
10257: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10258: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10259: &end_data_table_row();
1.1071 raeburn 10260: }
1.987 raeburn 10261: }
10262: } else {
10263: $modifyform = $pathchgtable;
10264: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10265: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10266: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10267: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10268: }
10269: }
10270: if ($modifyform) {
1.1071 raeburn 10271: if ($actionurl eq '/adm/dependencies') {
10272: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10273: }
1.987 raeburn 10274: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10275: '<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".
10276: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10277: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10278: '</ol></p>'."\n".'<p>'.
10279: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10280: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10281: &start_data_table()."\n".
10282: &start_data_table_header_row().
10283: '<th>'.&mt('Change?').'</th>'.
10284: '<th>'.&mt('Current reference').'</th>'.
10285: '<th>'.&mt('Required reference').'</th>'.
10286: &end_data_table_header_row()."\n".
10287: $modifyform.
10288: &end_data_table().'<br />'."\n".$hiddenstate.
10289: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10290: '</form>'."\n";
10291: }
10292: return;
10293: }
10294:
10295: sub modify_html_refs {
10296: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
10297: my $container;
10298: if ($context eq 'portfolio') {
10299: $container = $env{'form.container'};
10300: } elsif ($context eq 'coursedoc') {
10301: $container = $env{'form.primaryurl'};
1.1071 raeburn 10302: } elsif ($context eq 'manage_dependencies') {
10303: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10304: $container = "/$container";
1.987 raeburn 10305: } else {
1.1027 raeburn 10306: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10307: }
10308: my (%allfiles,%codebase,$output,$content);
10309: my @changes = &get_env_multiple('form.namechange');
1.1071 raeburn 10310: unless (@changes > 0) {
10311: if (wantarray) {
10312: return ('',0,0);
10313: } else {
10314: return;
10315: }
10316: }
10317: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10318: ($context eq 'manage_dependencies')) {
10319: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10320: if (wantarray) {
10321: return ('',0,0);
10322: } else {
10323: return;
10324: }
10325: }
1.987 raeburn 10326: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10327: if ($content eq '-1') {
10328: if (wantarray) {
10329: return ('',0,0);
10330: } else {
10331: return;
10332: }
10333: }
1.987 raeburn 10334: } else {
1.1071 raeburn 10335: unless ($container =~ /^\Q$dir_root\E/) {
10336: if (wantarray) {
10337: return ('',0,0);
10338: } else {
10339: return;
10340: }
10341: }
1.987 raeburn 10342: if (open(my $fh,"<$container")) {
10343: $content = join('', <$fh>);
10344: close($fh);
10345: } else {
1.1071 raeburn 10346: if (wantarray) {
10347: return ('',0,0);
10348: } else {
10349: return;
10350: }
1.987 raeburn 10351: }
10352: }
10353: my ($count,$codebasecount) = (0,0);
10354: my $mm = new File::MMagic;
10355: my $mime_type = $mm->checktype_contents($content);
10356: if ($mime_type eq 'text/html') {
10357: my $parse_result =
10358: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10359: \%codebase,\$content);
10360: if ($parse_result eq 'ok') {
10361: foreach my $i (@changes) {
10362: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10363: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10364: if ($allfiles{$ref}) {
10365: my $newname = $orig;
10366: my ($attrib_regexp,$codebase);
1.1006 raeburn 10367: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10368: if ($attrib_regexp =~ /:/) {
10369: $attrib_regexp =~ s/\:/|/g;
10370: }
10371: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10372: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10373: $count += $numchg;
10374: }
10375: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10376: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10377: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10378: $codebasecount ++;
10379: }
10380: }
10381: }
10382: if ($count || $codebasecount) {
10383: my $saveresult;
1.1071 raeburn 10384: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10385: ($context eq 'manage_dependencies')) {
1.987 raeburn 10386: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10387: if ($url eq $container) {
10388: my ($fname) = ($container =~ m{/([^/]+)$});
10389: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10390: $count,'<span class="LC_filename">'.
1.1071 raeburn 10391: $fname.'</span>').'</p>';
1.987 raeburn 10392: } else {
10393: $output = '<p class="LC_error">'.
10394: &mt('Error: update failed for: [_1].',
10395: '<span class="LC_filename">'.
10396: $container.'</span>').'</p>';
10397: }
10398: } else {
10399: if (open(my $fh,">$container")) {
10400: print $fh $content;
10401: close($fh);
10402: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10403: $count,'<span class="LC_filename">'.
10404: $container.'</span>').'</p>';
1.661 raeburn 10405: } else {
1.987 raeburn 10406: $output = '<p class="LC_error">'.
10407: &mt('Error: could not update [_1].',
10408: '<span class="LC_filename">'.
10409: $container.'</span>').'</p>';
1.661 raeburn 10410: }
10411: }
10412: }
1.987 raeburn 10413: } else {
10414: &logthis('Failed to parse '.$container.
10415: ' to modify references: '.$parse_result);
1.661 raeburn 10416: }
10417: }
1.1071 raeburn 10418: if (wantarray) {
10419: return ($output,$count,$codebasecount);
10420: } else {
10421: return $output;
10422: }
1.661 raeburn 10423: }
10424:
10425: sub check_for_existing {
10426: my ($path,$fname,$element) = @_;
10427: my ($state,$msg);
10428: if (-d $path.'/'.$fname) {
10429: $state = 'exists';
10430: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10431: } elsif (-e $path.'/'.$fname) {
10432: $state = 'exists';
10433: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10434: }
10435: if ($state eq 'exists') {
10436: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10437: }
10438: return ($state,$msg);
10439: }
10440:
10441: sub check_for_upload {
10442: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10443: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10444: my $filesize = length($env{'form.'.$element});
10445: if (!$filesize) {
10446: my $msg = '<span class="LC_error">'.
10447: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10448: '<span class="LC_filename">'.$fname.'</span>',
10449: $filesize).'<br />'.
1.1007 raeburn 10450: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10451: '</span>';
10452: return ('zero_bytes',$msg);
10453: }
10454: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10455: my $getpropath = 1;
1.1021 raeburn 10456: my ($dirlistref,$listerror) =
10457: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10458: my $found_file = 0;
10459: my $locked_file = 0;
1.991 raeburn 10460: my @lockers;
10461: my $navmap;
10462: if ($env{'request.course.id'}) {
10463: $navmap = Apache::lonnavmaps::navmap->new();
10464: }
1.1021 raeburn 10465: if (ref($dirlistref) eq 'ARRAY') {
10466: foreach my $line (@{$dirlistref}) {
10467: my ($file_name,$rest)=split(/\&/,$line,2);
10468: if ($file_name eq $fname){
10469: $file_name = $path.$file_name;
10470: if ($group ne '') {
10471: $file_name = $group.$file_name;
10472: }
10473: $found_file = 1;
10474: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10475: foreach my $lock (@lockers) {
10476: if (ref($lock) eq 'ARRAY') {
10477: my ($symb,$crsid) = @{$lock};
10478: if ($crsid eq $env{'request.course.id'}) {
10479: if (ref($navmap)) {
10480: my $res = $navmap->getBySymb($symb);
10481: foreach my $part (@{$res->parts()}) {
10482: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10483: unless (($slot_status == $res->RESERVED) ||
10484: ($slot_status == $res->RESERVED_LOCATION)) {
10485: $locked_file = 1;
10486: }
1.991 raeburn 10487: }
1.1021 raeburn 10488: } else {
10489: $locked_file = 1;
1.991 raeburn 10490: }
10491: } else {
10492: $locked_file = 1;
10493: }
10494: }
1.1021 raeburn 10495: }
10496: } else {
10497: my @info = split(/\&/,$rest);
10498: my $currsize = $info[6]/1000;
10499: if ($currsize < $filesize) {
10500: my $extra = $filesize - $currsize;
10501: if (($current_disk_usage + $extra) > $disk_quota) {
10502: my $msg = '<span class="LC_error">'.
10503: &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.',
10504: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10505: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10506: $disk_quota,$current_disk_usage);
10507: return ('will_exceed_quota',$msg);
10508: }
1.984 raeburn 10509: }
10510: }
1.661 raeburn 10511: }
10512: }
10513: }
10514: if (($current_disk_usage + $filesize) > $disk_quota){
10515: my $msg = '<span class="LC_error">'.
10516: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10517: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10518: return ('will_exceed_quota',$msg);
10519: } elsif ($found_file) {
10520: if ($locked_file) {
10521: my $msg = '<span class="LC_error">';
10522: $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>');
10523: $msg .= '</span><br />';
10524: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10525: return ('file_locked',$msg);
10526: } else {
10527: my $msg = '<span class="LC_error">';
1.984 raeburn 10528: $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 10529: $msg .= '</span>';
1.984 raeburn 10530: return ('existingfile',$msg);
1.661 raeburn 10531: }
10532: }
10533: }
10534:
1.987 raeburn 10535: sub check_for_traversal {
10536: my ($path,$url,$toplevel) = @_;
10537: my @parts=split(/\//,$path);
10538: my $cleanpath;
10539: my $fullpath = $url;
10540: for (my $i=0;$i<@parts;$i++) {
10541: next if ($parts[$i] eq '.');
10542: if ($parts[$i] eq '..') {
10543: $fullpath =~ s{([^/]+/)$}{};
10544: } else {
10545: $fullpath .= $parts[$i].'/';
10546: }
10547: }
10548: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10549: $cleanpath = $1;
10550: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10551: my $curr_toprel = $1;
10552: my @parts = split(/\//,$curr_toprel);
10553: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10554: my @urlparts = split(/\//,$url_toprel);
10555: my $doubledots;
10556: my $startdiff = -1;
10557: for (my $i=0; $i<@urlparts; $i++) {
10558: if ($startdiff == -1) {
10559: unless ($urlparts[$i] eq $parts[$i]) {
10560: $startdiff = $i;
10561: $doubledots .= '../';
10562: }
10563: } else {
10564: $doubledots .= '../';
10565: }
10566: }
10567: if ($startdiff > -1) {
10568: $cleanpath = $doubledots;
10569: for (my $i=$startdiff; $i<@parts; $i++) {
10570: $cleanpath .= $parts[$i].'/';
10571: }
10572: }
10573: }
10574: $cleanpath =~ s{(/)$}{};
10575: return $cleanpath;
10576: }
1.31 albertel 10577:
1.1053 raeburn 10578: sub is_archive_file {
10579: my ($mimetype) = @_;
10580: if (($mimetype eq 'application/octet-stream') ||
10581: ($mimetype eq 'application/x-stuffit') ||
10582: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10583: return 1;
10584: }
10585: return;
10586: }
10587:
10588: sub decompress_form {
1.1065 raeburn 10589: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10590: my %lt = &Apache::lonlocal::texthash (
10591: this => 'This file is an archive file.',
1.1067 raeburn 10592: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10593: itsc => 'Its contents are as follows:',
1.1053 raeburn 10594: youm => 'You may wish to extract its contents.',
10595: extr => 'Extract contents',
1.1067 raeburn 10596: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10597: proa => 'Process automatically?',
1.1053 raeburn 10598: yes => 'Yes',
10599: no => 'No',
1.1067 raeburn 10600: fold => 'Title for folder containing movie',
10601: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10602: );
1.1065 raeburn 10603: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10604: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10605: my $info = &list_archive_contents($fileloc,\@paths);
10606: if (@paths) {
10607: foreach my $path (@paths) {
10608: $path =~ s{^/}{};
1.1067 raeburn 10609: if ($path =~ m{^([^/]+)/$}) {
10610: $topdir = $1;
10611: }
1.1065 raeburn 10612: if ($path =~ m{^([^/]+)/}) {
10613: $toplevel{$1} = $path;
10614: } else {
10615: $toplevel{$path} = $path;
10616: }
10617: }
10618: }
1.1067 raeburn 10619: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10620: my @camtasia = ("$topdir/","$topdir/index.html",
10621: "$topdir/media/",
10622: "$topdir/media/$topdir.mp4",
10623: "$topdir/media/FirstFrame.png",
10624: "$topdir/media/player.swf",
10625: "$topdir/media/swfobject.js",
10626: "$topdir/media/expressInstall.swf");
10627: my @diffs = &compare_arrays(\@paths,\@camtasia);
10628: if (@diffs == 0) {
10629: $is_camtasia = 1;
10630: }
10631: }
10632: my $output;
10633: if ($is_camtasia) {
10634: $output = <<"ENDCAM";
10635: <script type="text/javascript" language="Javascript">
10636: // <![CDATA[
10637:
10638: function camtasiaToggle() {
10639: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10640: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10641: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10642:
10643: document.getElementById('camtasia_titles').style.display='block';
10644: } else {
10645: document.getElementById('camtasia_titles').style.display='none';
10646: }
10647: }
10648: }
10649: return;
10650: }
10651:
10652: // ]]>
10653: </script>
10654: <p>$lt{'camt'}</p>
10655: ENDCAM
1.1065 raeburn 10656: } else {
1.1067 raeburn 10657: $output = '<p>'.$lt{'this'};
10658: if ($info eq '') {
10659: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10660: } else {
10661: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10662: '<div><pre>'.$info.'</pre></div>';
10663: }
1.1065 raeburn 10664: }
1.1067 raeburn 10665: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10666: my $duplicates;
10667: my $num = 0;
10668: if (ref($dirlist) eq 'ARRAY') {
10669: foreach my $item (@{$dirlist}) {
10670: if (ref($item) eq 'ARRAY') {
10671: if (exists($toplevel{$item->[0]})) {
10672: $duplicates .=
10673: &start_data_table_row().
10674: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10675: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10676: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10677: 'value="1" />'.&mt('Yes').'</label>'.
10678: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10679: '<td>'.$item->[0].'</td>';
10680: if ($item->[2]) {
10681: $duplicates .= '<td>'.&mt('Directory').'</td>';
10682: } else {
10683: $duplicates .= '<td>'.&mt('File').'</td>';
10684: }
10685: $duplicates .= '<td>'.$item->[3].'</td>'.
10686: '<td>'.
10687: &Apache::lonlocal::locallocaltime($item->[4]).
10688: '</td>'.
10689: &end_data_table_row();
10690: $num ++;
10691: }
10692: }
10693: }
10694: }
10695: my $itemcount;
10696: if (@paths > 0) {
10697: $itemcount = scalar(@paths);
10698: } else {
10699: $itemcount = 1;
10700: }
1.1067 raeburn 10701: if ($is_camtasia) {
10702: $output .= $lt{'auto'}.'<br />'.
10703: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10704: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10705: $lt{'yes'}.'</label> <label>'.
10706: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10707: $lt{'no'}.'</label></span><br />'.
10708: '<div id="camtasia_titles" style="display:block">'.
10709: &Apache::lonhtmlcommon::start_pick_box().
10710: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10711: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10712: &Apache::lonhtmlcommon::row_closure().
10713: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
10714: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
10715: &Apache::lonhtmlcommon::row_closure(1).
10716: &Apache::lonhtmlcommon::end_pick_box().
10717: '</div>';
10718: }
1.1065 raeburn 10719: $output .=
10720: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 10721: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
10722: "\n";
1.1065 raeburn 10723: if ($duplicates ne '') {
10724: $output .= '<p><span class="LC_warning">'.
10725: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
10726: &start_data_table().
10727: &start_data_table_header_row().
10728: '<th>'.&mt('Overwrite?').'</th>'.
10729: '<th>'.&mt('Name').'</th>'.
10730: '<th>'.&mt('Type').'</th>'.
10731: '<th>'.&mt('Size').'</th>'.
10732: '<th>'.&mt('Last modified').'</th>'.
10733: &end_data_table_header_row().
10734: $duplicates.
10735: &end_data_table().
10736: '</p>';
10737: }
1.1067 raeburn 10738: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 10739: if (ref($hiddenelements) eq 'HASH') {
10740: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
10741: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
10742: }
10743: }
10744: $output .= <<"END";
1.1067 raeburn 10745: <br />
1.1053 raeburn 10746: <input type="submit" name="decompress" value="$lt{'extr'}" />
10747: </form>
10748: $noextract
10749: END
10750: return $output;
10751: }
10752:
1.1065 raeburn 10753: sub decompression_utility {
10754: my ($program) = @_;
10755: my @utilities = ('tar','gunzip','bunzip2','unzip');
10756: my $location;
10757: if (grep(/^\Q$program\E$/,@utilities)) {
10758: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
10759: '/usr/sbin/') {
10760: if (-x $dir.$program) {
10761: $location = $dir.$program;
10762: last;
10763: }
10764: }
10765: }
10766: return $location;
10767: }
10768:
10769: sub list_archive_contents {
10770: my ($file,$pathsref) = @_;
10771: my (@cmd,$output);
10772: my $needsregexp;
10773: if ($file =~ /\.zip$/) {
10774: @cmd = (&decompression_utility('unzip'),"-l");
10775: $needsregexp = 1;
10776: } elsif (($file =~ m/\.tar\.gz$/) ||
10777: ($file =~ /\.tgz$/)) {
10778: @cmd = (&decompression_utility('tar'),"-ztf");
10779: } elsif ($file =~ /\.tar\.bz2$/) {
10780: @cmd = (&decompression_utility('tar'),"-jtf");
10781: } elsif ($file =~ m|\.tar$|) {
10782: @cmd = (&decompression_utility('tar'),"-tf");
10783: }
10784: if (@cmd) {
10785: undef($!);
10786: undef($@);
10787: if (open(my $fh,"-|", @cmd, $file)) {
10788: while (my $line = <$fh>) {
10789: $output .= $line;
10790: chomp($line);
10791: my $item;
10792: if ($needsregexp) {
10793: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
10794: } else {
10795: $item = $line;
10796: }
10797: if ($item ne '') {
10798: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
10799: push(@{$pathsref},$item);
10800: }
10801: }
10802: }
10803: close($fh);
10804: }
10805: }
10806: return $output;
10807: }
10808:
1.1053 raeburn 10809: sub decompress_uploaded_file {
10810: my ($file,$dir) = @_;
10811: &Apache::lonnet::appenv({'cgi.file' => $file});
10812: &Apache::lonnet::appenv({'cgi.dir' => $dir});
10813: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
10814: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
10815: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
10816: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
10817: my $decompressed = $env{'cgi.decompressed'};
10818: &Apache::lonnet::delenv('cgi.file');
10819: &Apache::lonnet::delenv('cgi.dir');
10820: &Apache::lonnet::delenv('cgi.decompressed');
10821: return ($decompressed,$result);
10822: }
10823:
1.1055 raeburn 10824: sub process_decompression {
10825: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
10826: my ($dir,$error,$warning,$output);
10827: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
10828: $error = &mt('File name not a supported archive file type.').
10829: '<br />'.&mt('File name should end with one of: [_1].',
10830: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
10831: } else {
10832: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
10833: if ($docuhome eq 'no_host') {
10834: $error = &mt('Could not determine home server for course.');
10835: } else {
10836: my @ids=&Apache::lonnet::current_machine_ids();
10837: my $currdir = "$dir_root/$destination";
10838: if (grep(/^\Q$docuhome\E$/,@ids)) {
10839: $dir = &LONCAPA::propath($docudom,$docuname).
10840: "$dir_root/$destination";
10841: } else {
10842: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
10843: "$dir_root/$docudom/$docuname/$destination";
10844: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
10845: $error = &mt('Archive file not found.');
10846: }
10847: }
1.1065 raeburn 10848: my (@to_overwrite,@to_skip);
10849: if ($env{'form.archive_overwrite_total'} > 0) {
10850: my $total = $env{'form.archive_overwrite_total'};
10851: for (my $i=0; $i<$total; $i++) {
10852: if ($env{'form.archive_overwrite_'.$i} == 1) {
10853: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
10854: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
10855: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
10856: }
10857: }
10858: }
10859: my $numskip = scalar(@to_skip);
10860: if (($numskip > 0) &&
10861: ($numskip == $env{'form.archive_itemcount'})) {
10862: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
10863: } elsif ($dir eq '') {
1.1055 raeburn 10864: $error = &mt('Directory containing archive file unavailable.');
10865: } elsif (!$error) {
1.1065 raeburn 10866: my ($decompressed,$display);
10867: if ($numskip > 0) {
10868: my $tempdir = time.'_'.$$.int(rand(10000));
10869: mkdir("$dir/$tempdir",0755);
10870: system("mv $dir/$file $dir/$tempdir/$file");
10871: ($decompressed,$display) =
10872: &decompress_uploaded_file($file,"$dir/$tempdir");
10873: foreach my $item (@to_skip) {
10874: if (($item ne '') && ($item !~ /\.\./)) {
10875: if (-f "$dir/$tempdir/$item") {
10876: unlink("$dir/$tempdir/$item");
10877: } elsif (-d "$dir/$tempdir/$item") {
10878: system("rm -rf $dir/$tempdir/$item");
10879: }
10880: }
10881: }
10882: system("mv $dir/$tempdir/* $dir");
10883: rmdir("$dir/$tempdir");
10884: } else {
10885: ($decompressed,$display) =
10886: &decompress_uploaded_file($file,$dir);
10887: }
1.1055 raeburn 10888: if ($decompressed eq 'ok') {
1.1065 raeburn 10889: $output = '<p class="LC_info">'.
10890: &mt('Files extracted successfully from archive.').
10891: '</p>'."\n";
1.1055 raeburn 10892: my ($warning,$result,@contents);
10893: my ($newdirlistref,$newlisterror) =
10894: &Apache::lonnet::dirlist($currdir,$docudom,
10895: $docuname,1);
10896: my (%is_dir,%changes,@newitems);
10897: my $dirptr = 16384;
1.1065 raeburn 10898: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 10899: foreach my $dir_line (@{$newdirlistref}) {
10900: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 10901: unless (($item =~ /^\.+$/) || ($item eq $file) ||
10902: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 10903: push(@newitems,$item);
10904: if ($dirptr&$testdir) {
10905: $is_dir{$item} = 1;
10906: }
10907: $changes{$item} = 1;
10908: }
10909: }
10910: }
10911: if (keys(%changes) > 0) {
10912: foreach my $item (sort(@newitems)) {
10913: if ($changes{$item}) {
10914: push(@contents,$item);
10915: }
10916: }
10917: }
10918: if (@contents > 0) {
1.1067 raeburn 10919: my $wantform;
10920: unless ($env{'form.autoextract_camtasia'}) {
10921: $wantform = 1;
10922: }
1.1056 raeburn 10923: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 10924: my ($count,$datatable) = &get_extracted($docudom,$docuname,
10925: $currdir,\%is_dir,
10926: \%children,\%parent,
1.1056 raeburn 10927: \@contents,\%dirorder,
10928: \%titles,$wantform);
1.1055 raeburn 10929: if ($datatable ne '') {
10930: $output .= &archive_options_form('decompressed',$datatable,
10931: $count,$hiddenelem);
1.1065 raeburn 10932: my $startcount = 6;
1.1055 raeburn 10933: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 10934: \%titles,\%children);
1.1055 raeburn 10935: }
1.1067 raeburn 10936: if ($env{'form.autoextract_camtasia'}) {
10937: my %displayed;
10938: my $total = 1;
10939: $env{'form.archive_directory'} = [];
10940: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
10941: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
10942: $path =~ s{/$}{};
10943: my $item;
10944: if ($path ne '') {
10945: $item = "$path/$titles{$i}";
10946: } else {
10947: $item = $titles{$i};
10948: }
10949: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
10950: if ($item eq $contents[0]) {
10951: push(@{$env{'form.archive_directory'}},$i);
10952: $env{'form.archive_'.$i} = 'display';
10953: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
10954: $displayed{'folder'} = $i;
10955: } elsif ($item eq "$contents[0]/index.html") {
10956: $env{'form.archive_'.$i} = 'display';
10957: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
10958: $displayed{'web'} = $i;
10959: } else {
10960: if ($item eq "$contents[0]/media") {
10961: push(@{$env{'form.archive_directory'}},$i);
10962: }
10963: $env{'form.archive_'.$i} = 'dependency';
10964: }
10965: $total ++;
10966: }
10967: for (my $i=1; $i<$total; $i++) {
10968: next if ($i == $displayed{'web'});
10969: next if ($i == $displayed{'folder'});
10970: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
10971: }
10972: $env{'form.phase'} = 'decompress_cleanup';
10973: $env{'form.archivedelete'} = 1;
10974: $env{'form.archive_count'} = $total-1;
10975: $output .=
10976: &process_extracted_files('coursedocs',$docudom,
10977: $docuname,$destination,
10978: $dir_root,$hiddenelem);
10979: }
1.1055 raeburn 10980: } else {
10981: $warning = &mt('No new items extracted from archive file.');
10982: }
10983: } else {
10984: $output = $display;
10985: $error = &mt('An error occurred during extraction from the archive file.');
10986: }
10987: }
10988: }
10989: }
10990: if ($error) {
10991: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
10992: $error.'</p>'."\n";
10993: }
10994: if ($warning) {
10995: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
10996: }
10997: return $output;
10998: }
10999:
11000: sub get_extracted {
1.1056 raeburn 11001: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11002: $titles,$wantform) = @_;
1.1055 raeburn 11003: my $count = 0;
11004: my $depth = 0;
11005: my $datatable;
1.1056 raeburn 11006: my @hierarchy;
1.1055 raeburn 11007: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11008: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11009: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11010: foreach my $item (@{$contents}) {
11011: $count ++;
1.1056 raeburn 11012: @{$dirorder->{$count}} = @hierarchy;
11013: $titles->{$count} = $item;
1.1055 raeburn 11014: &archive_hierarchy($depth,$count,$parent,$children);
11015: if ($wantform) {
11016: $datatable .= &archive_row($is_dir->{$item},$item,
11017: $currdir,$depth,$count);
11018: }
11019: if ($is_dir->{$item}) {
11020: $depth ++;
1.1056 raeburn 11021: push(@hierarchy,$count);
11022: $parent->{$depth} = $count;
1.1055 raeburn 11023: $datatable .=
11024: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11025: \$depth,\$count,\@hierarchy,$dirorder,
11026: $children,$parent,$titles,$wantform);
1.1055 raeburn 11027: $depth --;
1.1056 raeburn 11028: pop(@hierarchy);
1.1055 raeburn 11029: }
11030: }
11031: return ($count,$datatable);
11032: }
11033:
11034: sub recurse_extracted_archive {
1.1056 raeburn 11035: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11036: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11037: my $result='';
1.1056 raeburn 11038: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11039: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11040: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11041: return $result;
11042: }
11043: my $dirptr = 16384;
11044: my ($newdirlistref,$newlisterror) =
11045: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11046: if (ref($newdirlistref) eq 'ARRAY') {
11047: foreach my $dir_line (@{$newdirlistref}) {
11048: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11049: unless ($item =~ /^\.+$/) {
11050: $$count ++;
1.1056 raeburn 11051: @{$dirorder->{$$count}} = @{$hierarchy};
11052: $titles->{$$count} = $item;
1.1055 raeburn 11053: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11054:
1.1055 raeburn 11055: my $is_dir;
11056: if ($dirptr&$testdir) {
11057: $is_dir = 1;
11058: }
11059: if ($wantform) {
11060: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11061: }
11062: if ($is_dir) {
11063: $$depth ++;
1.1056 raeburn 11064: push(@{$hierarchy},$$count);
11065: $parent->{$$depth} = $$count;
1.1055 raeburn 11066: $result .=
11067: &recurse_extracted_archive("$currdir/$item",$docudom,
11068: $docuname,$depth,$count,
1.1056 raeburn 11069: $hierarchy,$dirorder,$children,
11070: $parent,$titles,$wantform);
1.1055 raeburn 11071: $$depth --;
1.1056 raeburn 11072: pop(@{$hierarchy});
1.1055 raeburn 11073: }
11074: }
11075: }
11076: }
11077: return $result;
11078: }
11079:
11080: sub archive_hierarchy {
11081: my ($depth,$count,$parent,$children) =@_;
11082: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11083: if (exists($parent->{$depth})) {
11084: $children->{$parent->{$depth}} .= $count.':';
11085: }
11086: }
11087: return;
11088: }
11089:
11090: sub archive_row {
11091: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11092: my ($name) = ($item =~ m{([^/]+)$});
11093: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11094: 'display' => 'Add as file',
1.1055 raeburn 11095: 'dependency' => 'Include as dependency',
11096: 'discard' => 'Discard',
11097: );
11098: if ($is_dir) {
1.1059 raeburn 11099: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11100: }
1.1056 raeburn 11101: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11102: my $offset = 0;
1.1055 raeburn 11103: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11104: $offset ++;
1.1065 raeburn 11105: if ($action ne 'display') {
11106: $offset ++;
11107: }
1.1055 raeburn 11108: $output .= '<td><span class="LC_nobreak">'.
11109: '<label><input type="radio" name="archive_'.$count.
11110: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11111: my $text = $choices{$action};
11112: if ($is_dir) {
11113: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11114: if ($action eq 'display') {
1.1059 raeburn 11115: $text = &mt('Add as folder');
1.1055 raeburn 11116: }
1.1056 raeburn 11117: } else {
11118: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11119:
11120: }
11121: $output .= ' /> '.$choices{$action}.'</label></span>';
11122: if ($action eq 'dependency') {
11123: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11124: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11125: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11126: '<option value=""></option>'."\n".
11127: '</select>'."\n".
11128: '</div>';
1.1059 raeburn 11129: } elsif ($action eq 'display') {
11130: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11131: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11132: '</div>';
1.1055 raeburn 11133: }
1.1056 raeburn 11134: $output .= '</td>';
1.1055 raeburn 11135: }
11136: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11137: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11138: for (my $i=0; $i<$depth; $i++) {
11139: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11140: }
11141: if ($is_dir) {
11142: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11143: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11144: } else {
11145: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11146: }
11147: $output .= ' '.$name.'</td>'."\n".
11148: &end_data_table_row();
11149: return $output;
11150: }
11151:
11152: sub archive_options_form {
1.1065 raeburn 11153: my ($form,$display,$count,$hiddenelem) = @_;
11154: my %lt = &Apache::lonlocal::texthash(
11155: perm => 'Permanently remove archive file?',
11156: hows => 'How should each extracted item be incorporated in the course?',
11157: cont => 'Content actions for all',
11158: addf => 'Add as folder/file',
11159: incd => 'Include as dependency for a displayed file',
11160: disc => 'Discard',
11161: no => 'No',
11162: yes => 'Yes',
11163: save => 'Save',
11164: );
11165: my $output = <<"END";
11166: <form name="$form" method="post" action="">
11167: <p><span class="LC_nobreak">$lt{'perm'}
11168: <label>
11169: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11170: </label>
11171:
11172: <label>
11173: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11174: </span>
11175: </p>
11176: <input type="hidden" name="phase" value="decompress_cleanup" />
11177: <br />$lt{'hows'}
11178: <div class="LC_columnSection">
11179: <fieldset>
11180: <legend>$lt{'cont'}</legend>
11181: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11182: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11183: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11184: </fieldset>
11185: </div>
11186: END
11187: return $output.
1.1055 raeburn 11188: &start_data_table()."\n".
1.1065 raeburn 11189: $display."\n".
1.1055 raeburn 11190: &end_data_table()."\n".
11191: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11192: $hiddenelem.
1.1065 raeburn 11193: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11194: '</form>';
11195: }
11196:
11197: sub archive_javascript {
1.1056 raeburn 11198: my ($startcount,$numitems,$titles,$children) = @_;
11199: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11200: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11201: my $scripttag = <<START;
11202: <script type="text/javascript">
11203: // <![CDATA[
11204:
11205: function checkAll(form,prefix) {
11206: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11207: for (var i=0; i < form.elements.length; i++) {
11208: var id = form.elements[i].id;
11209: if ((id != '') && (id != undefined)) {
11210: if (idstr.test(id)) {
11211: if (form.elements[i].type == 'radio') {
11212: form.elements[i].checked = true;
1.1056 raeburn 11213: var nostart = i-$startcount;
1.1059 raeburn 11214: var offset = nostart%7;
11215: var count = (nostart-offset)/7;
1.1056 raeburn 11216: dependencyCheck(form,count,offset);
1.1055 raeburn 11217: }
11218: }
11219: }
11220: }
11221: }
11222:
11223: function propagateCheck(form,count) {
11224: if (count > 0) {
1.1059 raeburn 11225: var startelement = $startcount + ((count-1) * 7);
11226: for (var j=1; j<6; j++) {
11227: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11228: var item = startelement + j;
11229: if (form.elements[item].type == 'radio') {
11230: if (form.elements[item].checked) {
11231: containerCheck(form,count,j);
11232: break;
11233: }
1.1055 raeburn 11234: }
11235: }
11236: }
11237: }
11238: }
11239:
11240: numitems = $numitems
1.1056 raeburn 11241: var titles = new Array(numitems);
11242: var parents = new Array(numitems);
1.1055 raeburn 11243: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11244: parents[i] = new Array;
1.1055 raeburn 11245: }
1.1059 raeburn 11246: var maintitle = '$maintitle';
1.1055 raeburn 11247:
11248: START
11249:
1.1056 raeburn 11250: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11251: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11252: for (my $i=0; $i<@contents; $i ++) {
11253: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11254: }
11255: }
11256:
1.1056 raeburn 11257: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11258: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11259: }
11260:
1.1055 raeburn 11261: $scripttag .= <<END;
11262:
11263: function containerCheck(form,count,offset) {
11264: if (count > 0) {
1.1056 raeburn 11265: dependencyCheck(form,count,offset);
1.1059 raeburn 11266: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11267: form.elements[item].checked = true;
11268: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11269: if (parents[count].length > 0) {
11270: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11271: containerCheck(form,parents[count][j],offset);
11272: }
11273: }
11274: }
11275: }
11276: }
11277:
11278: function dependencyCheck(form,count,offset) {
11279: if (count > 0) {
1.1059 raeburn 11280: var chosen = (offset+$startcount)+7*(count-1);
11281: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11282: var currtype = form.elements[depitem].type;
11283: if (form.elements[chosen].value == 'dependency') {
11284: document.getElementById('arc_depon_'+count).style.display='block';
11285: form.elements[depitem].options.length = 0;
11286: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11287: for (var i=1; i<=numitems; i++) {
11288: if (i == count) {
11289: continue;
11290: }
1.1059 raeburn 11291: var startelement = $startcount + (i-1) * 7;
11292: for (var j=1; j<6; j++) {
11293: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11294: var item = startelement + j;
11295: if (form.elements[item].type == 'radio') {
11296: if (form.elements[item].checked) {
11297: if (form.elements[item].value == 'display') {
11298: var n = form.elements[depitem].options.length;
11299: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11300: }
11301: }
11302: }
11303: }
11304: }
11305: }
11306: } else {
11307: document.getElementById('arc_depon_'+count).style.display='none';
11308: form.elements[depitem].options.length = 0;
11309: form.elements[depitem].options[0] = new Option('Select','',true,true);
11310: }
1.1059 raeburn 11311: titleCheck(form,count,offset);
1.1056 raeburn 11312: }
11313: }
11314:
11315: function propagateSelect(form,count,offset) {
11316: if (count > 0) {
1.1065 raeburn 11317: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11318: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11319: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11320: if (parents[count].length > 0) {
11321: for (var j=0; j<parents[count].length; j++) {
11322: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11323: }
11324: }
11325: }
11326: }
11327: }
1.1056 raeburn 11328:
11329: function containerSelect(form,count,offset,picked) {
11330: if (count > 0) {
1.1065 raeburn 11331: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11332: if (form.elements[item].type == 'radio') {
11333: if (form.elements[item].value == 'dependency') {
11334: if (form.elements[item+1].type == 'select-one') {
11335: for (var i=0; i<form.elements[item+1].options.length; i++) {
11336: if (form.elements[item+1].options[i].value == picked) {
11337: form.elements[item+1].selectedIndex = i;
11338: break;
11339: }
11340: }
11341: }
11342: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11343: if (parents[count].length > 0) {
11344: for (var j=0; j<parents[count].length; j++) {
11345: containerSelect(form,parents[count][j],offset,picked);
11346: }
11347: }
11348: }
11349: }
11350: }
11351: }
11352: }
11353:
1.1059 raeburn 11354: function titleCheck(form,count,offset) {
11355: if (count > 0) {
11356: var chosen = (offset+$startcount)+7*(count-1);
11357: var depitem = $startcount + ((count-1) * 7) + 2;
11358: var currtype = form.elements[depitem].type;
11359: if (form.elements[chosen].value == 'display') {
11360: document.getElementById('arc_title_'+count).style.display='block';
11361: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11362: document.getElementById('archive_title_'+count).value=maintitle;
11363: }
11364: } else {
11365: document.getElementById('arc_title_'+count).style.display='none';
11366: if (currtype == 'text') {
11367: document.getElementById('archive_title_'+count).value='';
11368: }
11369: }
11370: }
11371: return;
11372: }
11373:
1.1055 raeburn 11374: // ]]>
11375: </script>
11376: END
11377: return $scripttag;
11378: }
11379:
11380: sub process_extracted_files {
1.1067 raeburn 11381: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11382: my $numitems = $env{'form.archive_count'};
11383: return unless ($numitems);
11384: my @ids=&Apache::lonnet::current_machine_ids();
11385: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11386: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11387: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11388: if (grep(/^\Q$docuhome\E$/,@ids)) {
11389: $prefix = &LONCAPA::propath($docudom,$docuname);
11390: $pathtocheck = "$dir_root/$destination";
11391: $dir = $dir_root;
11392: $ishome = 1;
11393: } else {
11394: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11395: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11396: $dir = "$dir_root/$docudom/$docuname";
11397: }
11398: my $currdir = "$dir_root/$destination";
11399: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11400: if ($env{'form.folderpath'}) {
11401: my @items = split('&',$env{'form.folderpath'});
11402: $folders{'0'} = $items[-2];
1.1099 raeburn 11403: if ($env{'form.folderpath'} =~ /\:1$/) {
11404: $containers{'0'}='page';
11405: } else {
11406: $containers{'0'}='sequence';
11407: }
1.1055 raeburn 11408: }
11409: my @archdirs = &get_env_multiple('form.archive_directory');
11410: if ($numitems) {
11411: for (my $i=1; $i<=$numitems; $i++) {
11412: my $path = $env{'form.archive_content_'.$i};
11413: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11414: my $item = $1;
11415: $toplevelitems{$item} = $i;
11416: if (grep(/^\Q$i\E$/,@archdirs)) {
11417: $is_dir{$item} = 1;
11418: }
11419: }
11420: }
11421: }
1.1067 raeburn 11422: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11423: if (keys(%toplevelitems) > 0) {
11424: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11425: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11426: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11427: }
1.1066 raeburn 11428: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11429: if ($numitems) {
11430: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11431: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11432: my $path = $env{'form.archive_content_'.$i};
11433: if ($path =~ /^\Q$pathtocheck\E/) {
11434: if ($env{'form.archive_'.$i} eq 'discard') {
11435: if ($prefix ne '' && $path ne '') {
11436: if (-e $prefix.$path) {
1.1066 raeburn 11437: if ((@archdirs > 0) &&
11438: (grep(/^\Q$i\E$/,@archdirs))) {
11439: $todeletedir{$prefix.$path} = 1;
11440: } else {
11441: $todelete{$prefix.$path} = 1;
11442: }
1.1055 raeburn 11443: }
11444: }
11445: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11446: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11447: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11448: $docstitle = $env{'form.archive_title_'.$i};
11449: if ($docstitle eq '') {
11450: $docstitle = $title;
11451: }
1.1055 raeburn 11452: $outer = 0;
1.1056 raeburn 11453: if (ref($dirorder{$i}) eq 'ARRAY') {
11454: if (@{$dirorder{$i}} > 0) {
11455: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11456: if ($env{'form.archive_'.$item} eq 'display') {
11457: $outer = $item;
11458: last;
11459: }
11460: }
11461: }
11462: }
11463: my ($errtext,$fatal) =
11464: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11465: '/'.$folders{$outer}.'.'.
11466: $containers{$outer});
11467: next if ($fatal);
11468: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11469: if ($context eq 'coursedocs') {
1.1056 raeburn 11470: $mapinner{$i} = time;
1.1055 raeburn 11471: $folders{$i} = 'default_'.$mapinner{$i};
11472: $containers{$i} = 'sequence';
11473: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11474: $folders{$i}.'.'.$containers{$i};
11475: my $newidx = &LONCAPA::map::getresidx();
11476: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11477: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11478: push(@LONCAPA::map::order,$newidx);
11479: my ($outtext,$errtext) =
11480: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11481: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11482: '.'.$containers{$outer},1,1);
1.1056 raeburn 11483: $newseqid{$i} = $newidx;
1.1067 raeburn 11484: unless ($errtext) {
11485: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11486: }
1.1055 raeburn 11487: }
11488: } else {
11489: if ($context eq 'coursedocs') {
11490: my $newidx=&LONCAPA::map::getresidx();
11491: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11492: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11493: $title;
11494: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11495: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11496: }
11497: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11498: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11499: }
11500: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11501: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11502: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11503: unless ($ishome) {
11504: my $fetch = "$newdest{$i}/$title";
11505: $fetch =~ s/^\Q$prefix$dir\E//;
11506: $prompttofetch{$fetch} = 1;
11507: }
1.1055 raeburn 11508: }
11509: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11510: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11511: push(@LONCAPA::map::order, $newidx);
11512: my ($outtext,$errtext)=
11513: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11514: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11515: '.'.$containers{$outer},1,1);
1.1067 raeburn 11516: unless ($errtext) {
11517: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11518: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11519: }
11520: }
1.1055 raeburn 11521: }
11522: }
1.1086 raeburn 11523: }
11524: } else {
11525: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11526: }
11527: }
11528: for (my $i=1; $i<=$numitems; $i++) {
11529: next unless ($env{'form.archive_'.$i} eq 'dependency');
11530: my $path = $env{'form.archive_content_'.$i};
11531: if ($path =~ /^\Q$pathtocheck\E/) {
11532: my ($title) = ($path =~ m{/([^/]+)$});
11533: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11534: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11535: if (ref($dirorder{$i}) eq 'ARRAY') {
11536: my ($itemidx,$fullpath,$relpath);
11537: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11538: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11539: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11540: if ($dirorder{$i}->[$j] eq $container) {
11541: $itemidx = $j;
1.1056 raeburn 11542: }
11543: }
1.1086 raeburn 11544: }
11545: if ($itemidx eq '') {
11546: $itemidx = 0;
11547: }
11548: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11549: if ($mapinner{$referrer{$i}}) {
11550: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11551: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11552: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11553: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11554: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11555: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11556: if (!-e $fullpath) {
11557: mkdir($fullpath,0755);
1.1056 raeburn 11558: }
11559: }
1.1086 raeburn 11560: } else {
11561: last;
1.1056 raeburn 11562: }
1.1086 raeburn 11563: }
11564: }
11565: } elsif ($newdest{$referrer{$i}}) {
11566: $fullpath = $newdest{$referrer{$i}};
11567: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11568: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11569: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11570: last;
11571: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11572: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11573: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11574: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11575: if (!-e $fullpath) {
11576: mkdir($fullpath,0755);
1.1056 raeburn 11577: }
11578: }
1.1086 raeburn 11579: } else {
11580: last;
1.1056 raeburn 11581: }
1.1055 raeburn 11582: }
11583: }
1.1086 raeburn 11584: if ($fullpath ne '') {
11585: if (-e "$prefix$path") {
11586: system("mv $prefix$path $fullpath/$title");
11587: }
11588: if (-e "$fullpath/$title") {
11589: my $showpath;
11590: if ($relpath ne '') {
11591: $showpath = "$relpath/$title";
11592: } else {
11593: $showpath = "/$title";
11594: }
11595: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11596: }
11597: unless ($ishome) {
11598: my $fetch = "$fullpath/$title";
11599: $fetch =~ s/^\Q$prefix$dir\E//;
11600: $prompttofetch{$fetch} = 1;
11601: }
11602: }
1.1055 raeburn 11603: }
1.1086 raeburn 11604: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11605: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11606: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11607: }
11608: } else {
11609: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11610: }
11611: }
11612: if (keys(%todelete)) {
11613: foreach my $key (keys(%todelete)) {
11614: unlink($key);
1.1066 raeburn 11615: }
11616: }
11617: if (keys(%todeletedir)) {
11618: foreach my $key (keys(%todeletedir)) {
11619: rmdir($key);
11620: }
11621: }
11622: foreach my $dir (sort(keys(%is_dir))) {
11623: if (($pathtocheck ne '') && ($dir ne '')) {
11624: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11625: }
11626: }
1.1067 raeburn 11627: if ($result ne '') {
11628: $output .= '<ul>'."\n".
11629: $result."\n".
11630: '</ul>';
11631: }
11632: unless ($ishome) {
11633: my $replicationfail;
11634: foreach my $item (keys(%prompttofetch)) {
11635: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11636: unless ($fetchresult eq 'ok') {
11637: $replicationfail .= '<li>'.$item.'</li>'."\n";
11638: }
11639: }
11640: if ($replicationfail) {
11641: $output .= '<p class="LC_error">'.
11642: &mt('Course home server failed to retrieve:').'<ul>'.
11643: $replicationfail.
11644: '</ul></p>';
11645: }
11646: }
1.1055 raeburn 11647: } else {
11648: $warning = &mt('No items found in archive.');
11649: }
11650: if ($error) {
11651: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11652: $error.'</p>'."\n";
11653: }
11654: if ($warning) {
11655: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11656: }
11657: return $output;
11658: }
11659:
1.1066 raeburn 11660: sub cleanup_empty_dirs {
11661: my ($path) = @_;
11662: if (($path ne '') && (-d $path)) {
11663: if (opendir(my $dirh,$path)) {
11664: my @dircontents = grep(!/^\./,readdir($dirh));
11665: my $numitems = 0;
11666: foreach my $item (@dircontents) {
11667: if (-d "$path/$item") {
1.1111 raeburn 11668: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11669: if (-e "$path/$item") {
11670: $numitems ++;
11671: }
11672: } else {
11673: $numitems ++;
11674: }
11675: }
11676: if ($numitems == 0) {
11677: rmdir($path);
11678: }
11679: closedir($dirh);
11680: }
11681: }
11682: return;
11683: }
11684:
1.41 ng 11685: =pod
1.45 matthew 11686:
1.1068 raeburn 11687: =item &get_folder_hierarchy()
11688:
11689: Provides hierarchy of names of folders/sub-folders containing the current
11690: item,
11691:
11692: Inputs: 3
11693: - $navmap - navmaps object
11694:
11695: - $map - url for map (either the trigger itself, or map containing
11696: the resource, which is the trigger).
11697:
11698: - $showitem - 1 => show title for map itself; 0 => do not show.
11699:
11700: Outputs: 1 @pathitems - array of folder/subfolder names.
11701:
11702: =cut
11703:
11704: sub get_folder_hierarchy {
11705: my ($navmap,$map,$showitem) = @_;
11706: my @pathitems;
11707: if (ref($navmap)) {
11708: my $mapres = $navmap->getResourceByUrl($map);
11709: if (ref($mapres)) {
11710: my $pcslist = $mapres->map_hierarchy();
11711: if ($pcslist ne '') {
11712: my @pcs = split(/,/,$pcslist);
11713: foreach my $pc (@pcs) {
11714: if ($pc == 1) {
11715: push(@pathitems,&mt('Main Course Documents'));
11716: } else {
11717: my $res = $navmap->getByMapPc($pc);
11718: if (ref($res)) {
11719: my $title = $res->compTitle();
11720: $title =~ s/\W+/_/g;
11721: if ($title ne '') {
11722: push(@pathitems,$title);
11723: }
11724: }
11725: }
11726: }
11727: }
1.1071 raeburn 11728: if ($showitem) {
11729: if ($mapres->{ID} eq '0.0') {
11730: push(@pathitems,&mt('Main Course Documents'));
11731: } else {
11732: my $maptitle = $mapres->compTitle();
11733: $maptitle =~ s/\W+/_/g;
11734: if ($maptitle ne '') {
11735: push(@pathitems,$maptitle);
11736: }
1.1068 raeburn 11737: }
11738: }
11739: }
11740: }
11741: return @pathitems;
11742: }
11743:
11744: =pod
11745:
1.1015 raeburn 11746: =item * &get_turnedin_filepath()
11747:
11748: Determines path in a user's portfolio file for storage of files uploaded
11749: to a specific essayresponse or dropbox item.
11750:
11751: Inputs: 3 required + 1 optional.
11752: $symb is symb for resource, $uname and $udom are for current user (required).
11753: $caller is optional (can be "submission", if routine is called when storing
11754: an upoaded file when "Submit Answer" button was pressed).
11755:
11756: Returns array containing $path and $multiresp.
11757: $path is path in portfolio. $multiresp is 1 if this resource contains more
11758: than one file upload item. Callers of routine should append partid as a
11759: subdirectory to $path in cases where $multiresp is 1.
11760:
11761: Called by: homework/essayresponse.pm and homework/structuretags.pm
11762:
11763: =cut
11764:
11765: sub get_turnedin_filepath {
11766: my ($symb,$uname,$udom,$caller) = @_;
11767: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
11768: my $turnindir;
11769: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
11770: $turnindir = $userhash{'turnindir'};
11771: my ($path,$multiresp);
11772: if ($turnindir eq '') {
11773: if ($caller eq 'submission') {
11774: $turnindir = &mt('turned in');
11775: $turnindir =~ s/\W+/_/g;
11776: my %newhash = (
11777: 'turnindir' => $turnindir,
11778: );
11779: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
11780: }
11781: }
11782: if ($turnindir ne '') {
11783: $path = '/'.$turnindir.'/';
11784: my ($multipart,$turnin,@pathitems);
11785: my $navmap = Apache::lonnavmaps::navmap->new();
11786: if (defined($navmap)) {
11787: my $mapres = $navmap->getResourceByUrl($map);
11788: if (ref($mapres)) {
11789: my $pcslist = $mapres->map_hierarchy();
11790: if ($pcslist ne '') {
11791: foreach my $pc (split(/,/,$pcslist)) {
11792: my $res = $navmap->getByMapPc($pc);
11793: if (ref($res)) {
11794: my $title = $res->compTitle();
11795: $title =~ s/\W+/_/g;
11796: if ($title ne '') {
11797: push(@pathitems,$title);
11798: }
11799: }
11800: }
11801: }
11802: my $maptitle = $mapres->compTitle();
11803: $maptitle =~ s/\W+/_/g;
11804: if ($maptitle ne '') {
11805: push(@pathitems,$maptitle);
11806: }
11807: unless ($env{'request.state'} eq 'construct') {
11808: my $res = $navmap->getBySymb($symb);
11809: if (ref($res)) {
11810: my $partlist = $res->parts();
11811: my $totaluploads = 0;
11812: if (ref($partlist) eq 'ARRAY') {
11813: foreach my $part (@{$partlist}) {
11814: my @types = $res->responseType($part);
11815: my @ids = $res->responseIds($part);
11816: for (my $i=0; $i < scalar(@ids); $i++) {
11817: if ($types[$i] eq 'essay') {
11818: my $partid = $part.'_'.$ids[$i];
11819: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
11820: $totaluploads ++;
11821: }
11822: }
11823: }
11824: }
11825: if ($totaluploads > 1) {
11826: $multiresp = 1;
11827: }
11828: }
11829: }
11830: }
11831: } else {
11832: return;
11833: }
11834: } else {
11835: return;
11836: }
11837: my $restitle=&Apache::lonnet::gettitle($symb);
11838: $restitle =~ s/\W+/_/g;
11839: if ($restitle eq '') {
11840: $restitle = ($resurl =~ m{/[^/]+$});
11841: if ($restitle eq '') {
11842: $restitle = time;
11843: }
11844: }
11845: push(@pathitems,$restitle);
11846: $path .= join('/',@pathitems);
11847: }
11848: return ($path,$multiresp);
11849: }
11850:
11851: =pod
11852:
1.464 albertel 11853: =back
1.41 ng 11854:
1.112 bowersj2 11855: =head1 CSV Upload/Handling functions
1.38 albertel 11856:
1.41 ng 11857: =over 4
11858:
1.648 raeburn 11859: =item * &upfile_store($r)
1.41 ng 11860:
11861: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 11862: needs $env{'form.upfile'}
1.41 ng 11863: returns $datatoken to be put into hidden field
11864:
11865: =cut
1.31 albertel 11866:
11867: sub upfile_store {
11868: my $r=shift;
1.258 albertel 11869: $env{'form.upfile'}=~s/\r/\n/gs;
11870: $env{'form.upfile'}=~s/\f/\n/gs;
11871: $env{'form.upfile'}=~s/\n+/\n/gs;
11872: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 11873:
1.258 albertel 11874: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
11875: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 11876: {
1.158 raeburn 11877: my $datafile = $r->dir_config('lonDaemons').
11878: '/tmp/'.$datatoken.'.tmp';
11879: if ( open(my $fh,">$datafile") ) {
1.258 albertel 11880: print $fh $env{'form.upfile'};
1.158 raeburn 11881: close($fh);
11882: }
1.31 albertel 11883: }
11884: return $datatoken;
11885: }
11886:
1.56 matthew 11887: =pod
11888:
1.648 raeburn 11889: =item * &load_tmp_file($r)
1.41 ng 11890:
11891: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 11892: needs $env{'form.datatoken'},
11893: sets $env{'form.upfile'} to the contents of the file
1.41 ng 11894:
11895: =cut
1.31 albertel 11896:
11897: sub load_tmp_file {
11898: my $r=shift;
11899: my @studentdata=();
11900: {
1.158 raeburn 11901: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 11902: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 11903: if ( open(my $fh,"<$studentfile") ) {
11904: @studentdata=<$fh>;
11905: close($fh);
11906: }
1.31 albertel 11907: }
1.258 albertel 11908: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 11909: }
11910:
1.56 matthew 11911: =pod
11912:
1.648 raeburn 11913: =item * &upfile_record_sep()
1.41 ng 11914:
11915: Separate uploaded file into records
11916: returns array of records,
1.258 albertel 11917: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 11918:
11919: =cut
1.31 albertel 11920:
11921: sub upfile_record_sep {
1.258 albertel 11922: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 11923: } else {
1.248 albertel 11924: my @records;
1.258 albertel 11925: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 11926: if ($line=~/^\s*$/) { next; }
11927: push(@records,$line);
11928: }
11929: return @records;
1.31 albertel 11930: }
11931: }
11932:
1.56 matthew 11933: =pod
11934:
1.648 raeburn 11935: =item * &record_sep($record)
1.41 ng 11936:
1.258 albertel 11937: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 11938:
11939: =cut
11940:
1.263 www 11941: sub takeleft {
11942: my $index=shift;
11943: return substr('0000'.$index,-4,4);
11944: }
11945:
1.31 albertel 11946: sub record_sep {
11947: my $record=shift;
11948: my %components=();
1.258 albertel 11949: if ($env{'form.upfiletype'} eq 'xml') {
11950: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 11951: my $i=0;
1.356 albertel 11952: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 11953: $field=~s/^(\"|\')//;
11954: $field=~s/(\"|\')$//;
1.263 www 11955: $components{&takeleft($i)}=$field;
1.31 albertel 11956: $i++;
11957: }
1.258 albertel 11958: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 11959: my $i=0;
1.356 albertel 11960: foreach my $field (split(/\t/,$record)) {
1.31 albertel 11961: $field=~s/^(\"|\')//;
11962: $field=~s/(\"|\')$//;
1.263 www 11963: $components{&takeleft($i)}=$field;
1.31 albertel 11964: $i++;
11965: }
11966: } else {
1.561 www 11967: my $separator=',';
1.480 banghart 11968: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 11969: $separator=';';
1.480 banghart 11970: }
1.31 albertel 11971: my $i=0;
1.561 www 11972: # the character we are looking for to indicate the end of a quote or a record
11973: my $looking_for=$separator;
11974: # do not add the characters to the fields
11975: my $ignore=0;
11976: # we just encountered a separator (or the beginning of the record)
11977: my $just_found_separator=1;
11978: # store the field we are working on here
11979: my $field='';
11980: # work our way through all characters in record
11981: foreach my $character ($record=~/(.)/g) {
11982: if ($character eq $looking_for) {
11983: if ($character ne $separator) {
11984: # Found the end of a quote, again looking for separator
11985: $looking_for=$separator;
11986: $ignore=1;
11987: } else {
11988: # Found a separator, store away what we got
11989: $components{&takeleft($i)}=$field;
11990: $i++;
11991: $just_found_separator=1;
11992: $ignore=0;
11993: $field='';
11994: }
11995: next;
11996: }
11997: # single or double quotation marks after a separator indicate beginning of a quote
11998: # we are now looking for the end of the quote and need to ignore separators
11999: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12000: $looking_for=$character;
12001: next;
12002: }
12003: # ignore would be true after we reached the end of a quote
12004: if ($ignore) { next; }
12005: if (($just_found_separator) && ($character=~/\s/)) { next; }
12006: $field.=$character;
12007: $just_found_separator=0;
1.31 albertel 12008: }
1.561 www 12009: # catch the very last entry, since we never encountered the separator
12010: $components{&takeleft($i)}=$field;
1.31 albertel 12011: }
12012: return %components;
12013: }
12014:
1.144 matthew 12015: ######################################################
12016: ######################################################
12017:
1.56 matthew 12018: =pod
12019:
1.648 raeburn 12020: =item * &upfile_select_html()
1.41 ng 12021:
1.144 matthew 12022: Return HTML code to select a file from the users machine and specify
12023: the file type.
1.41 ng 12024:
12025: =cut
12026:
1.144 matthew 12027: ######################################################
12028: ######################################################
1.31 albertel 12029: sub upfile_select_html {
1.144 matthew 12030: my %Types = (
12031: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12032: semisv => &mt('Semicolon separated values'),
1.144 matthew 12033: space => &mt('Space separated'),
12034: tab => &mt('Tabulator separated'),
12035: # xml => &mt('HTML/XML'),
12036: );
12037: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12038: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12039: foreach my $type (sort(keys(%Types))) {
12040: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12041: }
12042: $Str .= "</select>\n";
12043: return $Str;
1.31 albertel 12044: }
12045:
1.301 albertel 12046: sub get_samples {
12047: my ($records,$toget) = @_;
12048: my @samples=({});
12049: my $got=0;
12050: foreach my $rec (@$records) {
12051: my %temp = &record_sep($rec);
12052: if (! grep(/\S/, values(%temp))) { next; }
12053: if (%temp) {
12054: $samples[$got]=\%temp;
12055: $got++;
12056: if ($got == $toget) { last; }
12057: }
12058: }
12059: return \@samples;
12060: }
12061:
1.144 matthew 12062: ######################################################
12063: ######################################################
12064:
1.56 matthew 12065: =pod
12066:
1.648 raeburn 12067: =item * &csv_print_samples($r,$records)
1.41 ng 12068:
12069: Prints a table of sample values from each column uploaded $r is an
12070: Apache Request ref, $records is an arrayref from
12071: &Apache::loncommon::upfile_record_sep
12072:
12073: =cut
12074:
1.144 matthew 12075: ######################################################
12076: ######################################################
1.31 albertel 12077: sub csv_print_samples {
12078: my ($r,$records) = @_;
1.662 bisitz 12079: my $samples = &get_samples($records,5);
1.301 albertel 12080:
1.594 raeburn 12081: $r->print(&mt('Samples').'<br />'.&start_data_table().
12082: &start_data_table_header_row());
1.356 albertel 12083: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12084: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12085: $r->print(&end_data_table_header_row());
1.301 albertel 12086: foreach my $hash (@$samples) {
1.594 raeburn 12087: $r->print(&start_data_table_row());
1.356 albertel 12088: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12089: $r->print('<td>');
1.356 albertel 12090: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12091: $r->print('</td>');
12092: }
1.594 raeburn 12093: $r->print(&end_data_table_row());
1.31 albertel 12094: }
1.594 raeburn 12095: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12096: }
12097:
1.144 matthew 12098: ######################################################
12099: ######################################################
12100:
1.56 matthew 12101: =pod
12102:
1.648 raeburn 12103: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12104:
12105: Prints a table to create associations between values and table columns.
1.144 matthew 12106:
1.41 ng 12107: $r is an Apache Request ref,
12108: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12109: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12110:
12111: =cut
12112:
1.144 matthew 12113: ######################################################
12114: ######################################################
1.31 albertel 12115: sub csv_print_select_table {
12116: my ($r,$records,$d) = @_;
1.301 albertel 12117: my $i=0;
12118: my $samples = &get_samples($records,1);
1.144 matthew 12119: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12120: &start_data_table().&start_data_table_header_row().
1.144 matthew 12121: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12122: '<th>'.&mt('Column').'</th>'.
12123: &end_data_table_header_row()."\n");
1.356 albertel 12124: foreach my $array_ref (@$d) {
12125: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12126: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12127:
1.875 bisitz 12128: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12129: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12130: $r->print('<option value="none"></option>');
1.356 albertel 12131: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12132: $r->print('<option value="'.$sample.'"'.
12133: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12134: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12135: }
1.594 raeburn 12136: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12137: $i++;
12138: }
1.594 raeburn 12139: $r->print(&end_data_table());
1.31 albertel 12140: $i--;
12141: return $i;
12142: }
1.56 matthew 12143:
1.144 matthew 12144: ######################################################
12145: ######################################################
12146:
1.56 matthew 12147: =pod
1.31 albertel 12148:
1.648 raeburn 12149: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12150:
12151: Prints a table of sample values from the upload and can make associate samples to internal names.
12152:
12153: $r is an Apache Request ref,
12154: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12155: $d is an array of 2 element arrays (internal name, displayed name)
12156:
12157: =cut
12158:
1.144 matthew 12159: ######################################################
12160: ######################################################
1.31 albertel 12161: sub csv_samples_select_table {
12162: my ($r,$records,$d) = @_;
12163: my $i=0;
1.144 matthew 12164: #
1.662 bisitz 12165: my $max_samples = 5;
12166: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12167: $r->print(&start_data_table().
12168: &start_data_table_header_row().'<th>'.
12169: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12170: &end_data_table_header_row());
1.301 albertel 12171:
12172: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12173: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12174: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12175: foreach my $option (@$d) {
12176: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12177: $r->print('<option value="'.$value.'"'.
1.253 albertel 12178: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12179: $display.'</option>');
1.31 albertel 12180: }
12181: $r->print('</select></td><td>');
1.662 bisitz 12182: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12183: if (defined($samples->[$line]{$key})) {
12184: $r->print($samples->[$line]{$key}."<br />\n");
12185: }
12186: }
1.594 raeburn 12187: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12188: $i++;
12189: }
1.594 raeburn 12190: $r->print(&end_data_table());
1.31 albertel 12191: $i--;
12192: return($i);
1.115 matthew 12193: }
12194:
1.144 matthew 12195: ######################################################
12196: ######################################################
12197:
1.115 matthew 12198: =pod
12199:
1.648 raeburn 12200: =item * &clean_excel_name($name)
1.115 matthew 12201:
12202: Returns a replacement for $name which does not contain any illegal characters.
12203:
12204: =cut
12205:
1.144 matthew 12206: ######################################################
12207: ######################################################
1.115 matthew 12208: sub clean_excel_name {
12209: my ($name) = @_;
12210: $name =~ s/[:\*\?\/\\]//g;
12211: if (length($name) > 31) {
12212: $name = substr($name,0,31);
12213: }
12214: return $name;
1.25 albertel 12215: }
1.84 albertel 12216:
1.85 albertel 12217: =pod
12218:
1.648 raeburn 12219: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12220:
12221: Returns either 1 or undef
12222:
12223: 1 if the part is to be hidden, undef if it is to be shown
12224:
12225: Arguments are:
12226:
12227: $id the id of the part to be checked
12228: $symb, optional the symb of the resource to check
12229: $udom, optional the domain of the user to check for
12230: $uname, optional the username of the user to check for
12231:
12232: =cut
1.84 albertel 12233:
12234: sub check_if_partid_hidden {
12235: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12236: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12237: $symb,$udom,$uname);
1.141 albertel 12238: my $truth=1;
12239: #if the string starts with !, then the list is the list to show not hide
12240: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12241: my @hiddenlist=split(/,/,$hiddenparts);
12242: foreach my $checkid (@hiddenlist) {
1.141 albertel 12243: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12244: }
1.141 albertel 12245: return !$truth;
1.84 albertel 12246: }
1.127 matthew 12247:
1.138 matthew 12248:
12249: ############################################################
12250: ############################################################
12251:
12252: =pod
12253:
1.157 matthew 12254: =back
12255:
1.138 matthew 12256: =head1 cgi-bin script and graphing routines
12257:
1.157 matthew 12258: =over 4
12259:
1.648 raeburn 12260: =item * &get_cgi_id()
1.138 matthew 12261:
12262: Inputs: none
12263:
12264: Returns an id which can be used to pass environment variables
12265: to various cgi-bin scripts. These environment variables will
12266: be removed from the users environment after a given time by
12267: the routine &Apache::lonnet::transfer_profile_to_env.
12268:
12269: =cut
12270:
12271: ############################################################
12272: ############################################################
1.152 albertel 12273: my $uniq=0;
1.136 matthew 12274: sub get_cgi_id {
1.154 albertel 12275: $uniq=($uniq+1)%100000;
1.280 albertel 12276: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12277: }
12278:
1.127 matthew 12279: ############################################################
12280: ############################################################
12281:
12282: =pod
12283:
1.648 raeburn 12284: =item * &DrawBarGraph()
1.127 matthew 12285:
1.138 matthew 12286: Facilitates the plotting of data in a (stacked) bar graph.
12287: Puts plot definition data into the users environment in order for
12288: graph.png to plot it. Returns an <img> tag for the plot.
12289: The bars on the plot are labeled '1','2',...,'n'.
12290:
12291: Inputs:
12292:
12293: =over 4
12294:
12295: =item $Title: string, the title of the plot
12296:
12297: =item $xlabel: string, text describing the X-axis of the plot
12298:
12299: =item $ylabel: string, text describing the Y-axis of the plot
12300:
12301: =item $Max: scalar, the maximum Y value to use in the plot
12302: If $Max is < any data point, the graph will not be rendered.
12303:
1.140 matthew 12304: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12305: they are plotted. If undefined, default values will be used.
12306:
1.178 matthew 12307: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12308:
1.138 matthew 12309: =item @Values: An array of array references. Each array reference holds data
12310: to be plotted in a stacked bar chart.
12311:
1.239 matthew 12312: =item If the final element of @Values is a hash reference the key/value
12313: pairs will be added to the graph definition.
12314:
1.138 matthew 12315: =back
12316:
12317: Returns:
12318:
12319: An <img> tag which references graph.png and the appropriate identifying
12320: information for the plot.
12321:
1.127 matthew 12322: =cut
12323:
12324: ############################################################
12325: ############################################################
1.134 matthew 12326: sub DrawBarGraph {
1.178 matthew 12327: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12328: #
12329: if (! defined($colors)) {
12330: $colors = ['#33ff00',
12331: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12332: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12333: ];
12334: }
1.228 matthew 12335: my $extra_settings = {};
12336: if (ref($Values[-1]) eq 'HASH') {
12337: $extra_settings = pop(@Values);
12338: }
1.127 matthew 12339: #
1.136 matthew 12340: my $identifier = &get_cgi_id();
12341: my $id = 'cgi.'.$identifier;
1.129 matthew 12342: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12343: return '';
12344: }
1.225 matthew 12345: #
12346: my @Labels;
12347: if (defined($labels)) {
12348: @Labels = @$labels;
12349: } else {
12350: for (my $i=0;$i<@{$Values[0]};$i++) {
12351: push (@Labels,$i+1);
12352: }
12353: }
12354: #
1.129 matthew 12355: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12356: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12357: my %ValuesHash;
12358: my $NumSets=1;
12359: foreach my $array (@Values) {
12360: next if (! ref($array));
1.136 matthew 12361: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12362: join(',',@$array);
1.129 matthew 12363: }
1.127 matthew 12364: #
1.136 matthew 12365: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12366: if ($NumBars < 3) {
12367: $width = 120+$NumBars*32;
1.220 matthew 12368: $xskip = 1;
1.225 matthew 12369: $bar_width = 30;
12370: } elsif ($NumBars < 5) {
12371: $width = 120+$NumBars*20;
12372: $xskip = 1;
12373: $bar_width = 20;
1.220 matthew 12374: } elsif ($NumBars < 10) {
1.136 matthew 12375: $width = 120+$NumBars*15;
12376: $xskip = 1;
12377: $bar_width = 15;
12378: } elsif ($NumBars <= 25) {
12379: $width = 120+$NumBars*11;
12380: $xskip = 5;
12381: $bar_width = 8;
12382: } elsif ($NumBars <= 50) {
12383: $width = 120+$NumBars*8;
12384: $xskip = 5;
12385: $bar_width = 4;
12386: } else {
12387: $width = 120+$NumBars*8;
12388: $xskip = 5;
12389: $bar_width = 4;
12390: }
12391: #
1.137 matthew 12392: $Max = 1 if ($Max < 1);
12393: if ( int($Max) < $Max ) {
12394: $Max++;
12395: $Max = int($Max);
12396: }
1.127 matthew 12397: $Title = '' if (! defined($Title));
12398: $xlabel = '' if (! defined($xlabel));
12399: $ylabel = '' if (! defined($ylabel));
1.369 www 12400: $ValuesHash{$id.'.title'} = &escape($Title);
12401: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12402: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12403: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12404: $ValuesHash{$id.'.NumBars'} = $NumBars;
12405: $ValuesHash{$id.'.NumSets'} = $NumSets;
12406: $ValuesHash{$id.'.PlotType'} = 'bar';
12407: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12408: $ValuesHash{$id.'.height'} = $height;
12409: $ValuesHash{$id.'.width'} = $width;
12410: $ValuesHash{$id.'.xskip'} = $xskip;
12411: $ValuesHash{$id.'.bar_width'} = $bar_width;
12412: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12413: #
1.228 matthew 12414: # Deal with other parameters
12415: while (my ($key,$value) = each(%$extra_settings)) {
12416: $ValuesHash{$id.'.'.$key} = $value;
12417: }
12418: #
1.646 raeburn 12419: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12420: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12421: }
12422:
12423: ############################################################
12424: ############################################################
12425:
12426: =pod
12427:
1.648 raeburn 12428: =item * &DrawXYGraph()
1.137 matthew 12429:
1.138 matthew 12430: Facilitates the plotting of data in an XY graph.
12431: Puts plot definition data into the users environment in order for
12432: graph.png to plot it. Returns an <img> tag for the plot.
12433:
12434: Inputs:
12435:
12436: =over 4
12437:
12438: =item $Title: string, the title of the plot
12439:
12440: =item $xlabel: string, text describing the X-axis of the plot
12441:
12442: =item $ylabel: string, text describing the Y-axis of the plot
12443:
12444: =item $Max: scalar, the maximum Y value to use in the plot
12445: If $Max is < any data point, the graph will not be rendered.
12446:
12447: =item $colors: Array ref containing the hex color codes for the data to be
12448: plotted in. If undefined, default values will be used.
12449:
12450: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12451:
12452: =item $Ydata: Array ref containing Array refs.
1.185 www 12453: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12454:
12455: =item %Values: hash indicating or overriding any default values which are
12456: passed to graph.png.
12457: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12458:
12459: =back
12460:
12461: Returns:
12462:
12463: An <img> tag which references graph.png and the appropriate identifying
12464: information for the plot.
12465:
1.137 matthew 12466: =cut
12467:
12468: ############################################################
12469: ############################################################
12470: sub DrawXYGraph {
12471: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12472: #
12473: # Create the identifier for the graph
12474: my $identifier = &get_cgi_id();
12475: my $id = 'cgi.'.$identifier;
12476: #
12477: $Title = '' if (! defined($Title));
12478: $xlabel = '' if (! defined($xlabel));
12479: $ylabel = '' if (! defined($ylabel));
12480: my %ValuesHash =
12481: (
1.369 www 12482: $id.'.title' => &escape($Title),
12483: $id.'.xlabel' => &escape($xlabel),
12484: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12485: $id.'.y_max_value'=> $Max,
12486: $id.'.labels' => join(',',@$Xlabels),
12487: $id.'.PlotType' => 'XY',
12488: );
12489: #
12490: if (defined($colors) && ref($colors) eq 'ARRAY') {
12491: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12492: }
12493: #
12494: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12495: return '';
12496: }
12497: my $NumSets=1;
1.138 matthew 12498: foreach my $array (@{$Ydata}){
1.137 matthew 12499: next if (! ref($array));
12500: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12501: }
1.138 matthew 12502: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12503: #
12504: # Deal with other parameters
12505: while (my ($key,$value) = each(%Values)) {
12506: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12507: }
12508: #
1.646 raeburn 12509: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12510: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12511: }
12512:
12513: ############################################################
12514: ############################################################
12515:
12516: =pod
12517:
1.648 raeburn 12518: =item * &DrawXYYGraph()
1.138 matthew 12519:
12520: Facilitates the plotting of data in an XY graph with two Y axes.
12521: Puts plot definition data into the users environment in order for
12522: graph.png to plot it. Returns an <img> tag for the plot.
12523:
12524: Inputs:
12525:
12526: =over 4
12527:
12528: =item $Title: string, the title of the plot
12529:
12530: =item $xlabel: string, text describing the X-axis of the plot
12531:
12532: =item $ylabel: string, text describing the Y-axis of the plot
12533:
12534: =item $colors: Array ref containing the hex color codes for the data to be
12535: plotted in. If undefined, default values will be used.
12536:
12537: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12538:
12539: =item $Ydata1: The first data set
12540:
12541: =item $Min1: The minimum value of the left Y-axis
12542:
12543: =item $Max1: The maximum value of the left Y-axis
12544:
12545: =item $Ydata2: The second data set
12546:
12547: =item $Min2: The minimum value of the right Y-axis
12548:
12549: =item $Max2: The maximum value of the left Y-axis
12550:
12551: =item %Values: hash indicating or overriding any default values which are
12552: passed to graph.png.
12553: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12554:
12555: =back
12556:
12557: Returns:
12558:
12559: An <img> tag which references graph.png and the appropriate identifying
12560: information for the plot.
1.136 matthew 12561:
12562: =cut
12563:
12564: ############################################################
12565: ############################################################
1.137 matthew 12566: sub DrawXYYGraph {
12567: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12568: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12569: #
12570: # Create the identifier for the graph
12571: my $identifier = &get_cgi_id();
12572: my $id = 'cgi.'.$identifier;
12573: #
12574: $Title = '' if (! defined($Title));
12575: $xlabel = '' if (! defined($xlabel));
12576: $ylabel = '' if (! defined($ylabel));
12577: my %ValuesHash =
12578: (
1.369 www 12579: $id.'.title' => &escape($Title),
12580: $id.'.xlabel' => &escape($xlabel),
12581: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12582: $id.'.labels' => join(',',@$Xlabels),
12583: $id.'.PlotType' => 'XY',
12584: $id.'.NumSets' => 2,
1.137 matthew 12585: $id.'.two_axes' => 1,
12586: $id.'.y1_max_value' => $Max1,
12587: $id.'.y1_min_value' => $Min1,
12588: $id.'.y2_max_value' => $Max2,
12589: $id.'.y2_min_value' => $Min2,
1.136 matthew 12590: );
12591: #
1.137 matthew 12592: if (defined($colors) && ref($colors) eq 'ARRAY') {
12593: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12594: }
12595: #
12596: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12597: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12598: return '';
12599: }
12600: my $NumSets=1;
1.137 matthew 12601: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12602: next if (! ref($array));
12603: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12604: }
12605: #
12606: # Deal with other parameters
12607: while (my ($key,$value) = each(%Values)) {
12608: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12609: }
12610: #
1.646 raeburn 12611: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12612: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12613: }
12614:
12615: ############################################################
12616: ############################################################
12617:
12618: =pod
12619:
1.157 matthew 12620: =back
12621:
1.139 matthew 12622: =head1 Statistics helper routines?
12623:
12624: Bad place for them but what the hell.
12625:
1.157 matthew 12626: =over 4
12627:
1.648 raeburn 12628: =item * &chartlink()
1.139 matthew 12629:
12630: Returns a link to the chart for a specific student.
12631:
12632: Inputs:
12633:
12634: =over 4
12635:
12636: =item $linktext: The text of the link
12637:
12638: =item $sname: The students username
12639:
12640: =item $sdomain: The students domain
12641:
12642: =back
12643:
1.157 matthew 12644: =back
12645:
1.139 matthew 12646: =cut
12647:
12648: ############################################################
12649: ############################################################
12650: sub chartlink {
12651: my ($linktext, $sname, $sdomain) = @_;
12652: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12653: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12654: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12655: '">'.$linktext.'</a>';
1.153 matthew 12656: }
12657:
12658: #######################################################
12659: #######################################################
12660:
12661: =pod
12662:
12663: =head1 Course Environment Routines
1.157 matthew 12664:
12665: =over 4
1.153 matthew 12666:
1.648 raeburn 12667: =item * &restore_course_settings()
1.153 matthew 12668:
1.648 raeburn 12669: =item * &store_course_settings()
1.153 matthew 12670:
12671: Restores/Store indicated form parameters from the course environment.
12672: Will not overwrite existing values of the form parameters.
12673:
12674: Inputs:
12675: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12676:
12677: a hash ref describing the data to be stored. For example:
12678:
12679: %Save_Parameters = ('Status' => 'scalar',
12680: 'chartoutputmode' => 'scalar',
12681: 'chartoutputdata' => 'scalar',
12682: 'Section' => 'array',
1.373 raeburn 12683: 'Group' => 'array',
1.153 matthew 12684: 'StudentData' => 'array',
12685: 'Maps' => 'array');
12686:
12687: Returns: both routines return nothing
12688:
1.631 raeburn 12689: =back
12690:
1.153 matthew 12691: =cut
12692:
12693: #######################################################
12694: #######################################################
12695: sub store_course_settings {
1.496 albertel 12696: return &store_settings($env{'request.course.id'},@_);
12697: }
12698:
12699: sub store_settings {
1.153 matthew 12700: # save to the environment
12701: # appenv the same items, just to be safe
1.300 albertel 12702: my $udom = $env{'user.domain'};
12703: my $uname = $env{'user.name'};
1.496 albertel 12704: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12705: my %SaveHash;
12706: my %AppHash;
12707: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12708: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12709: my $envname = 'environment.'.$basename;
1.258 albertel 12710: if (exists($env{'form.'.$setting})) {
1.153 matthew 12711: # Save this value away
12712: if ($type eq 'scalar' &&
1.258 albertel 12713: (! exists($env{$envname}) ||
12714: $env{$envname} ne $env{'form.'.$setting})) {
12715: $SaveHash{$basename} = $env{'form.'.$setting};
12716: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 12717: } elsif ($type eq 'array') {
12718: my $stored_form;
1.258 albertel 12719: if (ref($env{'form.'.$setting})) {
1.153 matthew 12720: $stored_form = join(',',
12721: map {
1.369 www 12722: &escape($_);
1.258 albertel 12723: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 12724: } else {
12725: $stored_form =
1.369 www 12726: &escape($env{'form.'.$setting});
1.153 matthew 12727: }
12728: # Determine if the array contents are the same.
1.258 albertel 12729: if ($stored_form ne $env{$envname}) {
1.153 matthew 12730: $SaveHash{$basename} = $stored_form;
12731: $AppHash{$envname} = $stored_form;
12732: }
12733: }
12734: }
12735: }
12736: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 12737: $udom,$uname);
1.153 matthew 12738: if ($put_result !~ /^(ok|delayed)/) {
12739: &Apache::lonnet::logthis('unable to save form parameters, '.
12740: 'got error:'.$put_result);
12741: }
12742: # Make sure these settings stick around in this session, too
1.646 raeburn 12743: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 12744: return;
12745: }
12746:
12747: sub restore_course_settings {
1.499 albertel 12748: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 12749: }
12750:
12751: sub restore_settings {
12752: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12753: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 12754: next if (exists($env{'form.'.$setting}));
1.496 albertel 12755: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 12756: '.'.$setting;
1.258 albertel 12757: if (exists($env{$envname})) {
1.153 matthew 12758: if ($type eq 'scalar') {
1.258 albertel 12759: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 12760: } elsif ($type eq 'array') {
1.258 albertel 12761: $env{'form.'.$setting} = [
1.153 matthew 12762: map {
1.369 www 12763: &unescape($_);
1.258 albertel 12764: } split(',',$env{$envname})
1.153 matthew 12765: ];
12766: }
12767: }
12768: }
1.127 matthew 12769: }
12770:
1.618 raeburn 12771: #######################################################
12772: #######################################################
12773:
12774: =pod
12775:
12776: =head1 Domain E-mail Routines
12777:
12778: =over 4
12779:
1.648 raeburn 12780: =item * &build_recipient_list()
1.618 raeburn 12781:
1.884 raeburn 12782: Build recipient lists for five types of e-mail:
1.766 raeburn 12783: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 12784: (d) Help requests, (e) Course requests needing approval, generated by
12785: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
12786: loncoursequeueadmin.pm respectively.
1.618 raeburn 12787:
12788: Inputs:
1.619 raeburn 12789: defmail (scalar - email address of default recipient),
1.618 raeburn 12790: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 12791: defdom (domain for which to retrieve configuration settings),
12792: origmail (scalar - email address of recipient from loncapa.conf,
12793: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 12794:
1.655 raeburn 12795: Returns: comma separated list of addresses to which to send e-mail.
12796:
12797: =back
1.618 raeburn 12798:
12799: =cut
12800:
12801: ############################################################
12802: ############################################################
12803: sub build_recipient_list {
1.619 raeburn 12804: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 12805: my @recipients;
12806: my $otheremails;
12807: my %domconfig =
12808: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
12809: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 12810: if (exists($domconfig{'contacts'}{$mailing})) {
12811: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
12812: my @contacts = ('adminemail','supportemail');
12813: foreach my $item (@contacts) {
12814: if ($domconfig{'contacts'}{$mailing}{$item}) {
12815: my $addr = $domconfig{'contacts'}{$item};
12816: if (!grep(/^\Q$addr\E$/,@recipients)) {
12817: push(@recipients,$addr);
12818: }
1.619 raeburn 12819: }
1.766 raeburn 12820: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 12821: }
12822: }
1.766 raeburn 12823: } elsif ($origmail ne '') {
12824: push(@recipients,$origmail);
1.618 raeburn 12825: }
1.619 raeburn 12826: } elsif ($origmail ne '') {
12827: push(@recipients,$origmail);
1.618 raeburn 12828: }
1.688 raeburn 12829: if (defined($defmail)) {
12830: if ($defmail ne '') {
12831: push(@recipients,$defmail);
12832: }
1.618 raeburn 12833: }
12834: if ($otheremails) {
1.619 raeburn 12835: my @others;
12836: if ($otheremails =~ /,/) {
12837: @others = split(/,/,$otheremails);
1.618 raeburn 12838: } else {
1.619 raeburn 12839: push(@others,$otheremails);
12840: }
12841: foreach my $addr (@others) {
12842: if (!grep(/^\Q$addr\E$/,@recipients)) {
12843: push(@recipients,$addr);
12844: }
1.618 raeburn 12845: }
12846: }
1.619 raeburn 12847: my $recipientlist = join(',',@recipients);
1.618 raeburn 12848: return $recipientlist;
12849: }
12850:
1.127 matthew 12851: ############################################################
12852: ############################################################
1.154 albertel 12853:
1.655 raeburn 12854: =pod
12855:
12856: =head1 Course Catalog Routines
12857:
12858: =over 4
12859:
12860: =item * &gather_categories()
12861:
12862: Converts category definitions - keys of categories hash stored in
12863: coursecategories in configuration.db on the primary library server in a
12864: domain - to an array. Also generates javascript and idx hash used to
12865: generate Domain Coordinator interface for editing Course Categories.
12866:
12867: Inputs:
1.663 raeburn 12868:
1.655 raeburn 12869: categories (reference to hash of category definitions).
1.663 raeburn 12870:
1.655 raeburn 12871: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12872: categories and subcategories).
1.663 raeburn 12873:
1.655 raeburn 12874: idx (reference to hash of counters used in Domain Coordinator interface for
12875: editing Course Categories).
1.663 raeburn 12876:
1.655 raeburn 12877: jsarray (reference to array of categories used to create Javascript arrays for
12878: Domain Coordinator interface for editing Course Categories).
12879:
12880: Returns: nothing
12881:
12882: Side effects: populates cats, idx and jsarray.
12883:
12884: =cut
12885:
12886: sub gather_categories {
12887: my ($categories,$cats,$idx,$jsarray) = @_;
12888: my %counters;
12889: my $num = 0;
12890: foreach my $item (keys(%{$categories})) {
12891: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12892: if ($container eq '' && $depth == 0) {
12893: $cats->[$depth][$categories->{$item}] = $cat;
12894: } else {
12895: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
12896: }
12897: my ($escitem,$tail) = split(/:/,$item,2);
12898: if ($counters{$tail} eq '') {
12899: $counters{$tail} = $num;
12900: $num ++;
12901: }
12902: if (ref($idx) eq 'HASH') {
12903: $idx->{$item} = $counters{$tail};
12904: }
12905: if (ref($jsarray) eq 'ARRAY') {
12906: push(@{$jsarray->[$counters{$tail}]},$item);
12907: }
12908: }
12909: return;
12910: }
12911:
12912: =pod
12913:
12914: =item * &extract_categories()
12915:
12916: Used to generate breadcrumb trails for course categories.
12917:
12918: Inputs:
1.663 raeburn 12919:
1.655 raeburn 12920: categories (reference to hash of category definitions).
1.663 raeburn 12921:
1.655 raeburn 12922: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12923: categories and subcategories).
1.663 raeburn 12924:
1.655 raeburn 12925: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 12926:
1.655 raeburn 12927: allitems (reference to hash - key is category key
12928: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12929:
1.655 raeburn 12930: idx (reference to hash of counters used in Domain Coordinator interface for
12931: editing Course Categories).
1.663 raeburn 12932:
1.655 raeburn 12933: jsarray (reference to array of categories used to create Javascript arrays for
12934: Domain Coordinator interface for editing Course Categories).
12935:
1.665 raeburn 12936: subcats (reference to hash of arrays containing all subcategories within each
12937: category, -recursive)
12938:
1.655 raeburn 12939: Returns: nothing
12940:
12941: Side effects: populates trails and allitems hash references.
12942:
12943: =cut
12944:
12945: sub extract_categories {
1.665 raeburn 12946: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 12947: if (ref($categories) eq 'HASH') {
12948: &gather_categories($categories,$cats,$idx,$jsarray);
12949: if (ref($cats->[0]) eq 'ARRAY') {
12950: for (my $i=0; $i<@{$cats->[0]}; $i++) {
12951: my $name = $cats->[0][$i];
12952: my $item = &escape($name).'::0';
12953: my $trailstr;
12954: if ($name eq 'instcode') {
12955: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 12956: } elsif ($name eq 'communities') {
12957: $trailstr = &mt('Communities');
1.655 raeburn 12958: } else {
12959: $trailstr = $name;
12960: }
12961: if ($allitems->{$item} eq '') {
12962: push(@{$trails},$trailstr);
12963: $allitems->{$item} = scalar(@{$trails})-1;
12964: }
12965: my @parents = ($name);
12966: if (ref($cats->[1]{$name}) eq 'ARRAY') {
12967: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
12968: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 12969: if (ref($subcats) eq 'HASH') {
12970: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
12971: }
12972: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
12973: }
12974: } else {
12975: if (ref($subcats) eq 'HASH') {
12976: $subcats->{$item} = [];
1.655 raeburn 12977: }
12978: }
12979: }
12980: }
12981: }
12982: return;
12983: }
12984:
12985: =pod
12986:
12987: =item *&recurse_categories()
12988:
12989: Recursively used to generate breadcrumb trails for course categories.
12990:
12991: Inputs:
1.663 raeburn 12992:
1.655 raeburn 12993: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12994: categories and subcategories).
1.663 raeburn 12995:
1.655 raeburn 12996: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 12997:
12998: category (current course category, for which breadcrumb trail is being generated).
12999:
13000: trails (reference to array of breadcrumb trails for each category).
13001:
1.655 raeburn 13002: allitems (reference to hash - key is category key
13003: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13004:
1.655 raeburn 13005: parents (array containing containers directories for current category,
13006: back to top level).
13007:
13008: Returns: nothing
13009:
13010: Side effects: populates trails and allitems hash references
13011:
13012: =cut
13013:
13014: sub recurse_categories {
1.665 raeburn 13015: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13016: my $shallower = $depth - 1;
13017: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13018: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13019: my $name = $cats->[$depth]{$category}[$k];
13020: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13021: my $trailstr = join(' -> ',(@{$parents},$category));
13022: if ($allitems->{$item} eq '') {
13023: push(@{$trails},$trailstr);
13024: $allitems->{$item} = scalar(@{$trails})-1;
13025: }
13026: my $deeper = $depth+1;
13027: push(@{$parents},$category);
1.665 raeburn 13028: if (ref($subcats) eq 'HASH') {
13029: my $subcat = &escape($name).':'.$category.':'.$depth;
13030: for (my $j=@{$parents}; $j>=0; $j--) {
13031: my $higher;
13032: if ($j > 0) {
13033: $higher = &escape($parents->[$j]).':'.
13034: &escape($parents->[$j-1]).':'.$j;
13035: } else {
13036: $higher = &escape($parents->[$j]).'::'.$j;
13037: }
13038: push(@{$subcats->{$higher}},$subcat);
13039: }
13040: }
13041: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13042: $subcats);
1.655 raeburn 13043: pop(@{$parents});
13044: }
13045: } else {
13046: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13047: my $trailstr = join(' -> ',(@{$parents},$category));
13048: if ($allitems->{$item} eq '') {
13049: push(@{$trails},$trailstr);
13050: $allitems->{$item} = scalar(@{$trails})-1;
13051: }
13052: }
13053: return;
13054: }
13055:
1.663 raeburn 13056: =pod
13057:
13058: =item *&assign_categories_table()
13059:
13060: Create a datatable for display of hierarchical categories in a domain,
13061: with checkboxes to allow a course to be categorized.
13062:
13063: Inputs:
13064:
13065: cathash - reference to hash of categories defined for the domain (from
13066: configuration.db)
13067:
13068: currcat - scalar with an & separated list of categories assigned to a course.
13069:
1.919 raeburn 13070: type - scalar contains course type (Course or Community).
13071:
1.663 raeburn 13072: Returns: $output (markup to be displayed)
13073:
13074: =cut
13075:
13076: sub assign_categories_table {
1.919 raeburn 13077: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13078: my $output;
13079: if (ref($cathash) eq 'HASH') {
13080: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13081: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13082: $maxdepth = scalar(@cats);
13083: if (@cats > 0) {
13084: my $itemcount = 0;
13085: if (ref($cats[0]) eq 'ARRAY') {
13086: my @currcategories;
13087: if ($currcat ne '') {
13088: @currcategories = split('&',$currcat);
13089: }
1.919 raeburn 13090: my $table;
1.663 raeburn 13091: for (my $i=0; $i<@{$cats[0]}; $i++) {
13092: my $parent = $cats[0][$i];
1.919 raeburn 13093: next if ($parent eq 'instcode');
13094: if ($type eq 'Community') {
13095: next unless ($parent eq 'communities');
13096: } else {
13097: next if ($parent eq 'communities');
13098: }
1.663 raeburn 13099: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13100: my $item = &escape($parent).'::0';
13101: my $checked = '';
13102: if (@currcategories > 0) {
13103: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13104: $checked = ' checked="checked"';
1.663 raeburn 13105: }
13106: }
1.919 raeburn 13107: my $parent_title = $parent;
13108: if ($parent eq 'communities') {
13109: $parent_title = &mt('Communities');
13110: }
13111: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13112: '<input type="checkbox" name="usecategory" value="'.
13113: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13114: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13115: my $depth = 1;
13116: push(@path,$parent);
1.919 raeburn 13117: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13118: pop(@path);
1.919 raeburn 13119: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13120: $itemcount ++;
13121: }
1.919 raeburn 13122: if ($itemcount) {
13123: $output = &Apache::loncommon::start_data_table().
13124: $table.
13125: &Apache::loncommon::end_data_table();
13126: }
1.663 raeburn 13127: }
13128: }
13129: }
13130: return $output;
13131: }
13132:
13133: =pod
13134:
13135: =item *&assign_category_rows()
13136:
13137: Create a datatable row for display of nested categories in a domain,
13138: with checkboxes to allow a course to be categorized,called recursively.
13139:
13140: Inputs:
13141:
13142: itemcount - track row number for alternating colors
13143:
13144: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13145: categories and subcategories.
13146:
13147: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13148:
13149: parent - parent of current category item
13150:
13151: path - Array containing all categories back up through the hierarchy from the
13152: current category to the top level.
13153:
13154: currcategories - reference to array of current categories assigned to the course
13155:
13156: Returns: $output (markup to be displayed).
13157:
13158: =cut
13159:
13160: sub assign_category_rows {
13161: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13162: my ($text,$name,$item,$chgstr);
13163: if (ref($cats) eq 'ARRAY') {
13164: my $maxdepth = scalar(@{$cats});
13165: if (ref($cats->[$depth]) eq 'HASH') {
13166: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13167: my $numchildren = @{$cats->[$depth]{$parent}};
13168: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13169: $text .= '<td><table class="LC_datatable">';
13170: for (my $j=0; $j<$numchildren; $j++) {
13171: $name = $cats->[$depth]{$parent}[$j];
13172: $item = &escape($name).':'.&escape($parent).':'.$depth;
13173: my $deeper = $depth+1;
13174: my $checked = '';
13175: if (ref($currcategories) eq 'ARRAY') {
13176: if (@{$currcategories} > 0) {
13177: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13178: $checked = ' checked="checked"';
1.663 raeburn 13179: }
13180: }
13181: }
1.664 raeburn 13182: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13183: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13184: $item.'"'.$checked.' />'.$name.'</label></span>'.
13185: '<input type="hidden" name="catname" value="'.$name.'" />'.
13186: '</td><td>';
1.663 raeburn 13187: if (ref($path) eq 'ARRAY') {
13188: push(@{$path},$name);
13189: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13190: pop(@{$path});
13191: }
13192: $text .= '</td></tr>';
13193: }
13194: $text .= '</table></td>';
13195: }
13196: }
13197: }
13198: return $text;
13199: }
13200:
1.655 raeburn 13201: ############################################################
13202: ############################################################
13203:
13204:
1.443 albertel 13205: sub commit_customrole {
1.664 raeburn 13206: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13207: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13208: ($start?', '.&mt('starting').' '.localtime($start):'').
13209: ($end?', ending '.localtime($end):'').': <b>'.
13210: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13211: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13212: '</b><br />';
13213: return $output;
13214: }
13215:
13216: sub commit_standardrole {
1.1116 raeburn 13217: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13218: my ($output,$logmsg,$linefeed);
13219: if ($context eq 'auto') {
13220: $linefeed = "\n";
13221: } else {
13222: $linefeed = "<br />\n";
13223: }
1.443 albertel 13224: if ($three eq 'st') {
1.541 raeburn 13225: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13226: $one,$two,$sec,$context,$credits);
1.541 raeburn 13227: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13228: ($result eq 'unknown_course') || ($result eq 'refused')) {
13229: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13230: } else {
1.541 raeburn 13231: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13232: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13233: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13234: if ($context eq 'auto') {
13235: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13236: } else {
13237: $output .= '<b>'.$result.'</b>'.$linefeed.
13238: &mt('Add to classlist').': <b>ok</b>';
13239: }
13240: $output .= $linefeed;
1.443 albertel 13241: }
13242: } else {
13243: $output = &mt('Assigning').' '.$three.' in '.$url.
13244: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13245: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13246: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13247: if ($context eq 'auto') {
13248: $output .= $result.$linefeed;
13249: } else {
13250: $output .= '<b>'.$result.'</b>'.$linefeed;
13251: }
1.443 albertel 13252: }
13253: return $output;
13254: }
13255:
13256: sub commit_studentrole {
1.1116 raeburn 13257: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13258: $credits) = @_;
1.626 raeburn 13259: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13260: if ($context eq 'auto') {
13261: $linefeed = "\n";
13262: } else {
13263: $linefeed = '<br />'."\n";
13264: }
1.443 albertel 13265: if (defined($one) && defined($two)) {
13266: my $cid=$one.'_'.$two;
13267: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13268: my $secchange = 0;
13269: my $expire_role_result;
13270: my $modify_section_result;
1.628 raeburn 13271: if ($oldsec ne '-1') {
13272: if ($oldsec ne $sec) {
1.443 albertel 13273: $secchange = 1;
1.628 raeburn 13274: my $now = time;
1.443 albertel 13275: my $uurl='/'.$cid;
13276: $uurl=~s/\_/\//g;
13277: if ($oldsec) {
13278: $uurl.='/'.$oldsec;
13279: }
1.626 raeburn 13280: $oldsecurl = $uurl;
1.628 raeburn 13281: $expire_role_result =
1.652 raeburn 13282: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13283: if ($env{'request.course.sec'} ne '') {
13284: if ($expire_role_result eq 'refused') {
13285: my @roles = ('st');
13286: my @statuses = ('previous');
13287: my @roledoms = ($one);
13288: my $withsec = 1;
13289: my %roleshash =
13290: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13291: \@statuses,\@roles,\@roledoms,$withsec);
13292: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13293: my ($oldstart,$oldend) =
13294: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13295: if ($oldend > 0 && $oldend <= $now) {
13296: $expire_role_result = 'ok';
13297: }
13298: }
13299: }
13300: }
1.443 albertel 13301: $result = $expire_role_result;
13302: }
13303: }
13304: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13305: $modify_section_result =
13306: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13307: undef,undef,undef,$sec,
13308: $end,$start,'','',$cid,
13309: '',$context,$credits);
1.443 albertel 13310: if ($modify_section_result =~ /^ok/) {
13311: if ($secchange == 1) {
1.628 raeburn 13312: if ($sec eq '') {
13313: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13314: } else {
13315: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13316: }
1.443 albertel 13317: } elsif ($oldsec eq '-1') {
1.628 raeburn 13318: if ($sec eq '') {
13319: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13320: } else {
13321: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13322: }
1.443 albertel 13323: } else {
1.628 raeburn 13324: if ($sec eq '') {
13325: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13326: } else {
13327: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13328: }
1.443 albertel 13329: }
13330: } else {
1.1115 raeburn 13331: if ($secchange) {
1.628 raeburn 13332: $$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;
13333: } else {
13334: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13335: }
1.443 albertel 13336: }
13337: $result = $modify_section_result;
13338: } elsif ($secchange == 1) {
1.628 raeburn 13339: if ($oldsec eq '') {
1.1103 raeburn 13340: $$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 13341: } else {
13342: $$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;
13343: }
1.626 raeburn 13344: if ($expire_role_result eq 'refused') {
13345: my $newsecurl = '/'.$cid;
13346: $newsecurl =~ s/\_/\//g;
13347: if ($sec ne '') {
13348: $newsecurl.='/'.$sec;
13349: }
13350: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13351: if ($sec eq '') {
13352: $$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;
13353: } else {
13354: $$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;
13355: }
13356: }
13357: }
1.443 albertel 13358: }
13359: } else {
1.626 raeburn 13360: $$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 13361: $result = "error: incomplete course id\n";
13362: }
13363: return $result;
13364: }
13365:
1.1108 raeburn 13366: sub show_role_extent {
13367: my ($scope,$context,$role) = @_;
13368: $scope =~ s{^/}{};
13369: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13370: push(@courseroles,'co');
13371: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13372: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13373: $scope =~ s{/}{_};
13374: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13375: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13376: my ($audom,$auname) = split(/\//,$scope);
13377: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13378: &Apache::loncommon::plainname($auname,$audom).'</span>');
13379: } else {
13380: $scope =~ s{/$}{};
13381: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13382: &Apache::lonnet::domain($scope,'description').'</span>');
13383: }
13384: }
13385:
1.443 albertel 13386: ############################################################
13387: ############################################################
13388:
1.566 albertel 13389: sub check_clone {
1.578 raeburn 13390: my ($args,$linefeed) = @_;
1.566 albertel 13391: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13392: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13393: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13394: my $clonemsg;
13395: my $can_clone = 0;
1.944 raeburn 13396: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13397: if ($lctype ne 'community') {
13398: $lctype = 'course';
13399: }
1.566 albertel 13400: if ($clonehome eq 'no_host') {
1.944 raeburn 13401: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13402: $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'});
13403: } else {
13404: $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'});
13405: }
1.566 albertel 13406: } else {
13407: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13408: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13409: if ($clonedesc{'type'} ne 'Community') {
13410: $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'});
13411: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13412: }
13413: }
1.882 raeburn 13414: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13415: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13416: $can_clone = 1;
13417: } else {
13418: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13419: $args->{'clonedomain'},$args->{'clonecourse'});
13420: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13421: if (grep(/^\*$/,@cloners)) {
13422: $can_clone = 1;
13423: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13424: $can_clone = 1;
13425: } else {
1.908 raeburn 13426: my $ccrole = 'cc';
1.944 raeburn 13427: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13428: $ccrole = 'co';
13429: }
1.578 raeburn 13430: my %roleshash =
13431: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13432: $args->{'ccdomain'},
1.908 raeburn 13433: 'userroles',['active'],[$ccrole],
1.578 raeburn 13434: [$args->{'clonedomain'}]);
1.908 raeburn 13435: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13436: $can_clone = 1;
13437: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13438: $can_clone = 1;
13439: } else {
1.944 raeburn 13440: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13441: $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'});
13442: } else {
13443: $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'});
13444: }
1.578 raeburn 13445: }
1.566 albertel 13446: }
1.578 raeburn 13447: }
1.566 albertel 13448: }
13449: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13450: }
13451:
1.444 albertel 13452: sub construct_course {
1.885 raeburn 13453: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13454: my $outcome;
1.541 raeburn 13455: my $linefeed = '<br />'."\n";
13456: if ($context eq 'auto') {
13457: $linefeed = "\n";
13458: }
1.566 albertel 13459:
13460: #
13461: # Are we cloning?
13462: #
13463: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13464: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13465: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13466: if ($context ne 'auto') {
1.578 raeburn 13467: if ($clonemsg ne '') {
13468: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13469: }
1.566 albertel 13470: }
13471: $outcome .= $clonemsg.$linefeed;
13472:
13473: if (!$can_clone) {
13474: return (0,$outcome);
13475: }
13476: }
13477:
1.444 albertel 13478: #
13479: # Open course
13480: #
13481: my $crstype = lc($args->{'crstype'});
13482: my %cenv=();
13483: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13484: $args->{'cdescr'},
13485: $args->{'curl'},
13486: $args->{'course_home'},
13487: $args->{'nonstandard'},
13488: $args->{'crscode'},
13489: $args->{'ccuname'}.':'.
13490: $args->{'ccdomain'},
1.882 raeburn 13491: $args->{'crstype'},
1.885 raeburn 13492: $cnum,$context,$category);
1.444 albertel 13493:
13494: # Note: The testing routines depend on this being output; see
13495: # Utils::Course. This needs to at least be output as a comment
13496: # if anyone ever decides to not show this, and Utils::Course::new
13497: # will need to be suitably modified.
1.541 raeburn 13498: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13499: if ($$courseid =~ /^error:/) {
13500: return (0,$outcome);
13501: }
13502:
1.444 albertel 13503: #
13504: # Check if created correctly
13505: #
1.479 albertel 13506: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13507: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13508: if ($crsuhome eq 'no_host') {
13509: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13510: return (0,$outcome);
13511: }
1.541 raeburn 13512: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13513:
1.444 albertel 13514: #
1.566 albertel 13515: # Do the cloning
13516: #
13517: if ($can_clone && $cloneid) {
13518: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13519: if ($context ne 'auto') {
13520: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13521: }
13522: $outcome .= $clonemsg.$linefeed;
13523: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13524: # Copy all files
1.637 www 13525: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13526: # Restore URL
1.566 albertel 13527: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13528: # Restore title
1.566 albertel 13529: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13530: # Restore creation date, creator and creation context.
13531: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13532: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13533: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13534: # Mark as cloned
1.566 albertel 13535: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13536: # Need to clone grading mode
13537: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13538: $cenv{'grading'}=$newenv{'grading'};
13539: # Do not clone these environment entries
13540: &Apache::lonnet::del('environment',
13541: ['default_enrollment_start_date',
13542: 'default_enrollment_end_date',
13543: 'question.email',
13544: 'policy.email',
13545: 'comment.email',
13546: 'pch.users.denied',
1.725 raeburn 13547: 'plc.users.denied',
13548: 'hidefromcat',
13549: 'categories'],
1.638 www 13550: $$crsudom,$$crsunum);
1.444 albertel 13551: }
1.566 albertel 13552:
1.444 albertel 13553: #
13554: # Set environment (will override cloned, if existing)
13555: #
13556: my @sections = ();
13557: my @xlists = ();
13558: if ($args->{'crstype'}) {
13559: $cenv{'type'}=$args->{'crstype'};
13560: }
13561: if ($args->{'crsid'}) {
13562: $cenv{'courseid'}=$args->{'crsid'};
13563: }
13564: if ($args->{'crscode'}) {
13565: $cenv{'internal.coursecode'}=$args->{'crscode'};
13566: }
13567: if ($args->{'crsquota'} ne '') {
13568: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13569: } else {
13570: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13571: }
13572: if ($args->{'ccuname'}) {
13573: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13574: ':'.$args->{'ccdomain'};
13575: } else {
13576: $cenv{'internal.courseowner'} = $args->{'curruser'};
13577: }
1.1116 raeburn 13578: if ($args->{'defaultcredits'}) {
13579: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13580: }
1.444 albertel 13581: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13582: if ($args->{'crssections'}) {
13583: $cenv{'internal.sectionnums'} = '';
13584: if ($args->{'crssections'} =~ m/,/) {
13585: @sections = split/,/,$args->{'crssections'};
13586: } else {
13587: $sections[0] = $args->{'crssections'};
13588: }
13589: if (@sections > 0) {
13590: foreach my $item (@sections) {
13591: my ($sec,$gp) = split/:/,$item;
13592: my $class = $args->{'crscode'}.$sec;
13593: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13594: $cenv{'internal.sectionnums'} .= $item.',';
13595: unless ($addcheck eq 'ok') {
13596: push @badclasses, $class;
13597: }
13598: }
13599: $cenv{'internal.sectionnums'} =~ s/,$//;
13600: }
13601: }
13602: # do not hide course coordinator from staff listing,
13603: # even if privileged
13604: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13605: # add crosslistings
13606: if ($args->{'crsxlist'}) {
13607: $cenv{'internal.crosslistings'}='';
13608: if ($args->{'crsxlist'} =~ m/,/) {
13609: @xlists = split/,/,$args->{'crsxlist'};
13610: } else {
13611: $xlists[0] = $args->{'crsxlist'};
13612: }
13613: if (@xlists > 0) {
13614: foreach my $item (@xlists) {
13615: my ($xl,$gp) = split/:/,$item;
13616: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13617: $cenv{'internal.crosslistings'} .= $item.',';
13618: unless ($addcheck eq 'ok') {
13619: push @badclasses, $xl;
13620: }
13621: }
13622: $cenv{'internal.crosslistings'} =~ s/,$//;
13623: }
13624: }
13625: if ($args->{'autoadds'}) {
13626: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13627: }
13628: if ($args->{'autodrops'}) {
13629: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13630: }
13631: # check for notification of enrollment changes
13632: my @notified = ();
13633: if ($args->{'notify_owner'}) {
13634: if ($args->{'ccuname'} ne '') {
13635: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13636: }
13637: }
13638: if ($args->{'notify_dc'}) {
13639: if ($uname ne '') {
1.630 raeburn 13640: push(@notified,$uname.':'.$udom);
1.444 albertel 13641: }
13642: }
13643: if (@notified > 0) {
13644: my $notifylist;
13645: if (@notified > 1) {
13646: $notifylist = join(',',@notified);
13647: } else {
13648: $notifylist = $notified[0];
13649: }
13650: $cenv{'internal.notifylist'} = $notifylist;
13651: }
13652: if (@badclasses > 0) {
13653: my %lt=&Apache::lonlocal::texthash(
13654: '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',
13655: 'dnhr' => 'does not have rights to access enrollment in these classes',
13656: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13657: );
1.541 raeburn 13658: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13659: ' ('.$lt{'adby'}.')';
13660: if ($context eq 'auto') {
13661: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13662: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13663: foreach my $item (@badclasses) {
13664: if ($context eq 'auto') {
13665: $outcome .= " - $item\n";
13666: } else {
13667: $outcome .= "<li>$item</li>\n";
13668: }
13669: }
13670: if ($context eq 'auto') {
13671: $outcome .= $linefeed;
13672: } else {
1.566 albertel 13673: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13674: }
13675: }
1.444 albertel 13676: }
13677: if ($args->{'no_end_date'}) {
13678: $args->{'endaccess'} = 0;
13679: }
13680: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13681: $cenv{'internal.autoend'}=$args->{'enrollend'};
13682: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13683: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13684: if ($args->{'showphotos'}) {
13685: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13686: }
13687: $cenv{'internal.authtype'} = $args->{'authtype'};
13688: $cenv{'internal.autharg'} = $args->{'autharg'};
13689: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13690: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13691: 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');
13692: if ($context eq 'auto') {
13693: $outcome .= $krb_msg;
13694: } else {
1.566 albertel 13695: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13696: }
13697: $outcome .= $linefeed;
1.444 albertel 13698: }
13699: }
13700: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13701: if ($args->{'setpolicy'}) {
13702: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13703: }
13704: if ($args->{'setcontent'}) {
13705: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13706: }
13707: }
13708: if ($args->{'reshome'}) {
13709: $cenv{'reshome'}=$args->{'reshome'}.'/';
13710: $cenv{'reshome'}=~s/\/+$/\//;
13711: }
13712: #
13713: # course has keyed access
13714: #
13715: if ($args->{'setkeys'}) {
13716: $cenv{'keyaccess'}='yes';
13717: }
13718: # if specified, key authority is not course, but user
13719: # only active if keyaccess is yes
13720: if ($args->{'keyauth'}) {
1.487 albertel 13721: my ($user,$domain) = split(':',$args->{'keyauth'});
13722: $user = &LONCAPA::clean_username($user);
13723: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 13724: if ($user ne '' && $domain ne '') {
1.487 albertel 13725: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 13726: }
13727: }
13728:
13729: if ($args->{'disresdis'}) {
13730: $cenv{'pch.roles.denied'}='st';
13731: }
13732: if ($args->{'disablechat'}) {
13733: $cenv{'plc.roles.denied'}='st';
13734: }
13735:
13736: # Record we've not yet viewed the Course Initialization Helper for this
13737: # course
13738: $cenv{'course.helper.not.run'} = 1;
13739: #
13740: # Use new Randomseed
13741: #
13742: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
13743: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
13744: #
13745: # The encryption code and receipt prefix for this course
13746: #
13747: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
13748: $cenv{'internal.encpref'}=100+int(9*rand(99));
13749: #
13750: # By default, use standard grading
13751: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
13752:
1.541 raeburn 13753: $outcome .= $linefeed.&mt('Setting environment').': '.
13754: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13755: #
13756: # Open all assignments
13757: #
13758: if ($args->{'openall'}) {
13759: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
13760: my %storecontent = ($storeunder => time,
13761: $storeunder.'.type' => 'date_start');
13762:
13763: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 13764: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13765: }
13766: #
13767: # Set first page
13768: #
13769: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
13770: || ($cloneid)) {
1.445 albertel 13771: use LONCAPA::map;
1.444 albertel 13772: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 13773:
13774: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
13775: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
13776:
1.444 albertel 13777: $outcome .= ($fatal?$errtext:'read ok').' - ';
13778: my $title; my $url;
13779: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 13780: $title=&mt('Syllabus');
1.444 albertel 13781: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
13782: } else {
1.963 raeburn 13783: $title=&mt('Table of Contents');
1.444 albertel 13784: $url='/adm/navmaps';
13785: }
1.445 albertel 13786:
13787: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
13788: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
13789:
13790: if ($errtext) { $fatal=2; }
1.541 raeburn 13791: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 13792: }
1.566 albertel 13793:
13794: return (1,$outcome);
1.444 albertel 13795: }
13796:
13797: ############################################################
13798: ############################################################
13799:
1.953 droeschl 13800: #SD
13801: # only Community and Course, or anything else?
1.378 raeburn 13802: sub course_type {
13803: my ($cid) = @_;
13804: if (!defined($cid)) {
13805: $cid = $env{'request.course.id'};
13806: }
1.404 albertel 13807: if (defined($env{'course.'.$cid.'.type'})) {
13808: return $env{'course.'.$cid.'.type'};
1.378 raeburn 13809: } else {
13810: return 'Course';
1.377 raeburn 13811: }
13812: }
1.156 albertel 13813:
1.406 raeburn 13814: sub group_term {
13815: my $crstype = &course_type();
13816: my %names = (
13817: 'Course' => 'group',
1.865 raeburn 13818: 'Community' => 'group',
1.406 raeburn 13819: );
13820: return $names{$crstype};
13821: }
13822:
1.902 raeburn 13823: sub course_types {
13824: my @types = ('official','unofficial','community');
13825: my %typename = (
13826: official => 'Official course',
13827: unofficial => 'Unofficial course',
13828: community => 'Community',
13829: );
13830: return (\@types,\%typename);
13831: }
13832:
1.156 albertel 13833: sub icon {
13834: my ($file)=@_;
1.505 albertel 13835: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 13836: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 13837: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 13838: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
13839: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
13840: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13841: $curfext.".gif") {
13842: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13843: $curfext.".gif";
13844: }
13845: }
1.249 albertel 13846: return &lonhttpdurl($iconname);
1.154 albertel 13847: }
1.84 albertel 13848:
1.575 albertel 13849: sub lonhttpdurl {
1.692 www 13850: #
13851: # Had been used for "small fry" static images on separate port 8080.
13852: # Modify here if lightweight http functionality desired again.
13853: # Currently eliminated due to increasing firewall issues.
13854: #
1.575 albertel 13855: my ($url)=@_;
1.692 www 13856: return $url;
1.215 albertel 13857: }
13858:
1.213 albertel 13859: sub connection_aborted {
13860: my ($r)=@_;
13861: $r->print(" ");$r->rflush();
13862: my $c = $r->connection;
13863: return $c->aborted();
13864: }
13865:
1.221 foxr 13866: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 13867: # strings as 'strings'.
13868: sub escape_single {
1.221 foxr 13869: my ($input) = @_;
1.223 albertel 13870: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 13871: $input =~ s/\'/\\\'/g; # Esacpe the 's....
13872: return $input;
13873: }
1.223 albertel 13874:
1.222 foxr 13875: # Same as escape_single, but escape's "'s This
13876: # can be used for "strings"
13877: sub escape_double {
13878: my ($input) = @_;
13879: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
13880: $input =~ s/\"/\\\"/g; # Esacpe the "s....
13881: return $input;
13882: }
1.223 albertel 13883:
1.222 foxr 13884: # Escapes the last element of a full URL.
13885: sub escape_url {
13886: my ($url) = @_;
1.238 raeburn 13887: my @urlslices = split(/\//, $url,-1);
1.369 www 13888: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 13889: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 13890: }
1.462 albertel 13891:
1.820 raeburn 13892: sub compare_arrays {
13893: my ($arrayref1,$arrayref2) = @_;
13894: my (@difference,%count);
13895: @difference = ();
13896: %count = ();
13897: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
13898: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
13899: foreach my $element (keys(%count)) {
13900: if ($count{$element} == 1) {
13901: push(@difference,$element);
13902: }
13903: }
13904: }
13905: return @difference;
13906: }
13907:
1.817 bisitz 13908: # -------------------------------------------------------- Initialize user login
1.462 albertel 13909: sub init_user_environment {
1.463 albertel 13910: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 13911: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
13912:
13913: my $public=($username eq 'public' && $domain eq 'public');
13914:
13915: # See if old ID present, if so, remove
13916:
1.1062 raeburn 13917: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 13918: my $now=time;
13919:
13920: if ($public) {
13921: my $max_public=100;
13922: my $oldest;
13923: my $oldest_time=0;
13924: for(my $next=1;$next<=$max_public;$next++) {
13925: if (-e $lonids."/publicuser_$next.id") {
13926: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
13927: if ($mtime<$oldest_time || !$oldest_time) {
13928: $oldest_time=$mtime;
13929: $oldest=$next;
13930: }
13931: } else {
13932: $cookie="publicuser_$next";
13933: last;
13934: }
13935: }
13936: if (!$cookie) { $cookie="publicuser_$oldest"; }
13937: } else {
1.463 albertel 13938: # if this isn't a robot, kill any existing non-robot sessions
13939: if (!$args->{'robot'}) {
13940: opendir(DIR,$lonids);
13941: while ($filename=readdir(DIR)) {
13942: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
13943: unlink($lonids.'/'.$filename);
13944: }
1.462 albertel 13945: }
1.463 albertel 13946: closedir(DIR);
1.462 albertel 13947: }
13948: # Give them a new cookie
1.463 albertel 13949: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 13950: : $now.$$.int(rand(10000)));
1.463 albertel 13951: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 13952:
13953: # Initialize roles
13954:
1.1062 raeburn 13955: ($userroles,$firstaccenv,$timerintenv) =
13956: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 13957: }
13958: # ------------------------------------ Check browser type and MathML capability
13959:
13960: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
13961: $clientunicode,$clientos) = &decode_user_agent($r);
13962:
13963: # ------------------------------------------------------------- Get environment
13964:
13965: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
13966: my ($tmp) = keys(%userenv);
13967: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
13968: } else {
13969: undef(%userenv);
13970: }
13971: if (($userenv{'interface'}) && (!$form->{'interface'})) {
13972: $form->{'interface'}=$userenv{'interface'};
13973: }
13974: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
13975:
13976: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 13977: foreach my $option ('interface','localpath','localres') {
13978: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 13979: }
13980: # --------------------------------------------------------- Write first profile
13981:
13982: {
13983: my %initial_env =
13984: ("user.name" => $username,
13985: "user.domain" => $domain,
13986: "user.home" => $authhost,
13987: "browser.type" => $clientbrowser,
13988: "browser.version" => $clientversion,
13989: "browser.mathml" => $clientmathml,
13990: "browser.unicode" => $clientunicode,
13991: "browser.os" => $clientos,
13992: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
13993: "request.course.fn" => '',
13994: "request.course.uri" => '',
13995: "request.course.sec" => '',
13996: "request.role" => 'cm',
13997: "request.role.adv" => $env{'user.adv'},
13998: "request.host" => $ENV{'REMOTE_ADDR'},);
13999:
14000: if ($form->{'localpath'}) {
14001: $initial_env{"browser.localpath"} = $form->{'localpath'};
14002: $initial_env{"browser.localres"} = $form->{'localres'};
14003: }
14004:
14005: if ($form->{'interface'}) {
14006: $form->{'interface'}=~s/\W//gs;
14007: $initial_env{"browser.interface"} = $form->{'interface'};
14008: $env{'browser.interface'}=$form->{'interface'};
14009: }
14010:
1.981 raeburn 14011: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14012: my %domdef;
14013: unless ($domain eq 'public') {
14014: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14015: }
1.980 raeburn 14016:
1.1081 raeburn 14017: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14018: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14019: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14020: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14021: }
14022:
1.864 raeburn 14023: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14024: $userenv{'canrequest.'.$crstype} =
14025: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14026: 'reload','requestcourses',
14027: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14028: }
14029:
1.1092 raeburn 14030: $userenv{'canrequest.author'} =
14031: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14032: 'reload','requestauthor',
14033: \%userenv,\%domdef,\%is_adv);
14034: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14035: $domain,$username);
14036: my $reqstatus = $reqauthor{'author_status'};
14037: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14038: if (ref($reqauthor{'author'}) eq 'HASH') {
14039: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14040: $reqauthor{'author'}{'timestamp'};
14041: }
14042: }
14043:
1.462 albertel 14044: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14045:
1.462 albertel 14046: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14047: &GDBM_WRCREAT(),0640)) {
14048: &_add_to_env(\%disk_env,\%initial_env);
14049: &_add_to_env(\%disk_env,\%userenv,'environment.');
14050: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14051: if (ref($firstaccenv) eq 'HASH') {
14052: &_add_to_env(\%disk_env,$firstaccenv);
14053: }
14054: if (ref($timerintenv) eq 'HASH') {
14055: &_add_to_env(\%disk_env,$timerintenv);
14056: }
1.463 albertel 14057: if (ref($args->{'extra_env'})) {
14058: &_add_to_env(\%disk_env,$args->{'extra_env'});
14059: }
1.462 albertel 14060: untie(%disk_env);
14061: } else {
1.705 tempelho 14062: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14063: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14064: return 'error: '.$!;
14065: }
14066: }
14067: $env{'request.role'}='cm';
14068: $env{'request.role.adv'}=$env{'user.adv'};
14069: $env{'browser.type'}=$clientbrowser;
14070:
14071: return $cookie;
14072:
14073: }
14074:
14075: sub _add_to_env {
14076: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14077: if (ref($env_data) eq 'HASH') {
14078: while (my ($key,$value) = each(%$env_data)) {
14079: $idf->{$prefix.$key} = $value;
14080: $env{$prefix.$key} = $value;
14081: }
1.462 albertel 14082: }
14083: }
14084:
1.685 tempelho 14085: # --- Get the symbolic name of a problem and the url
14086: sub get_symb {
14087: my ($request,$silent) = @_;
1.726 raeburn 14088: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14089: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14090: if ($symb eq '') {
14091: if (!$silent) {
1.1071 raeburn 14092: if (ref($request)) {
14093: $request->print("Unable to handle ambiguous references:$url:.");
14094: }
1.685 tempelho 14095: return ();
14096: }
14097: }
14098: &Apache::lonenc::check_decrypt(\$symb);
14099: return ($symb);
14100: }
14101:
14102: # --------------------------------------------------------------Get annotation
14103:
14104: sub get_annotation {
14105: my ($symb,$enc) = @_;
14106:
14107: my $key = $symb;
14108: if (!$enc) {
14109: $key =
14110: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14111: }
14112: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14113: return $annotation{$key};
14114: }
14115:
14116: sub clean_symb {
1.731 raeburn 14117: my ($symb,$delete_enc) = @_;
1.685 tempelho 14118:
14119: &Apache::lonenc::check_decrypt(\$symb);
14120: my $enc = $env{'request.enc'};
1.731 raeburn 14121: if ($delete_enc) {
1.730 raeburn 14122: delete($env{'request.enc'});
14123: }
1.685 tempelho 14124:
14125: return ($symb,$enc);
14126: }
1.462 albertel 14127:
1.990 raeburn 14128: sub build_release_hashes {
14129: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14130: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14131: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14132: (ref($randomizetry) eq 'HASH'));
14133: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14134: my ($item,$name,$value) = split(/:/,$key);
14135: if ($item eq 'parameter') {
14136: if (ref($checkparms->{$name}) eq 'ARRAY') {
14137: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14138: push(@{$checkparms->{$name}},$value);
14139: }
14140: } else {
14141: push(@{$checkparms->{$name}},$value);
14142: }
14143: } elsif ($item eq 'resourcetag') {
14144: if ($name eq 'responsetype') {
14145: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14146: }
14147: } elsif ($item eq 'course') {
14148: if ($name eq 'crstype') {
14149: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14150: }
14151: }
14152: }
14153: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14154: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14155: return;
14156: }
14157:
1.1083 raeburn 14158: sub update_content_constraints {
14159: my ($cdom,$cnum,$chome,$cid) = @_;
14160: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14161: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14162: my %checkresponsetypes;
14163: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14164: my ($item,$name,$value) = split(/:/,$key);
14165: if ($item eq 'resourcetag') {
14166: if ($name eq 'responsetype') {
14167: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14168: }
14169: }
14170: }
14171: my $navmap = Apache::lonnavmaps::navmap->new();
14172: if (defined($navmap)) {
14173: my %allresponses;
14174: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14175: my %responses = $res->responseTypes();
14176: foreach my $key (keys(%responses)) {
14177: next unless(exists($checkresponsetypes{$key}));
14178: $allresponses{$key} += $responses{$key};
14179: }
14180: }
14181: foreach my $key (keys(%allresponses)) {
14182: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14183: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14184: ($reqdmajor,$reqdminor) = ($major,$minor);
14185: }
14186: }
14187: undef($navmap);
14188: }
14189: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14190: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14191: }
14192: return;
14193: }
14194:
1.1110 raeburn 14195: sub allmaps_incourse {
14196: my ($cdom,$cnum,$chome,$cid) = @_;
14197: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14198: $cid = $env{'request.course.id'};
14199: $cdom = $env{'course.'.$cid.'.domain'};
14200: $cnum = $env{'course.'.$cid.'.num'};
14201: $chome = $env{'course.'.$cid.'.home'};
14202: }
14203: my %allmaps = ();
14204: my $lastchange =
14205: &Apache::lonnet::get_coursechange($cdom,$cnum);
14206: if ($lastchange > $env{'request.course.tied'}) {
14207: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14208: unless ($ferr) {
14209: &update_content_constraints($cdom,$cnum,$chome,$cid);
14210: }
14211: }
14212: my $navmap = Apache::lonnavmaps::navmap->new();
14213: if (defined($navmap)) {
14214: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14215: $allmaps{$res->src()} = 1;
14216: }
14217: }
14218: return \%allmaps;
14219: }
14220:
1.1083 raeburn 14221: sub parse_supplemental_title {
14222: my ($title) = @_;
14223:
14224: my ($foldertitle,$renametitle);
14225: if ($title =~ /&&&/) {
14226: $title = &HTML::Entites::decode($title);
14227: }
14228: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14229: $renametitle=$4;
14230: my ($time,$uname,$udom) = ($1,$2,$3);
14231: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14232: my $name = &plainname($uname,$udom);
14233: $name = &HTML::Entities::encode($name,'"<>&\'');
14234: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14235: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14236: $name.': <br />'.$foldertitle;
14237: }
14238: if (wantarray) {
14239: return ($title,$foldertitle,$renametitle);
14240: }
14241: return $title;
14242: }
14243:
1.1101 raeburn 14244: sub symb_to_docspath {
14245: my ($symb) = @_;
14246: return unless ($symb);
14247: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14248: if ($resurl=~/\.(sequence|page)$/) {
14249: $mapurl=$resurl;
14250: } elsif ($resurl eq 'adm/navmaps') {
14251: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14252: }
14253: my $mapresobj;
14254: my $navmap = Apache::lonnavmaps::navmap->new();
14255: if (ref($navmap)) {
14256: $mapresobj = $navmap->getResourceByUrl($mapurl);
14257: }
14258: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14259: my $type=$2;
14260: my $path;
14261: if (ref($mapresobj)) {
14262: my $pcslist = $mapresobj->map_hierarchy();
14263: if ($pcslist ne '') {
14264: foreach my $pc (split(/,/,$pcslist)) {
14265: next if ($pc <= 1);
14266: my $res = $navmap->getByMapPc($pc);
14267: if (ref($res)) {
14268: my $thisurl = $res->src();
14269: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14270: my $thistitle = $res->title();
14271: $path .= '&'.
14272: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14273: &Apache::lonhtmlcommon::entity_encode($thistitle).
14274: ':'.$res->randompick().
14275: ':'.$res->randomout().
14276: ':'.$res->encrypted().
14277: ':'.$res->randomorder().
14278: ':'.$res->is_page();
14279: }
14280: }
14281: }
14282: $path =~ s/^\&//;
14283: my $maptitle = $mapresobj->title();
14284: if ($mapurl eq 'default') {
14285: $maptitle = 'Main Course Documents';
14286: }
14287: $path .= (($path ne '')? '&' : '').
14288: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14289: &Apache::lonhtmlcommon::entity_encode($maptitle).
14290: ':'.$mapresobj->randompick().
14291: ':'.$mapresobj->randomout().
14292: ':'.$mapresobj->encrypted().
14293: ':'.$mapresobj->randomorder().
14294: ':'.$mapresobj->is_page();
14295: } else {
14296: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14297: my $ispage = (($type eq 'page')? 1 : '');
14298: if ($mapurl eq 'default') {
14299: $maptitle = 'Main Course Documents';
14300: }
14301: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14302: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14303: }
14304: unless ($mapurl eq 'default') {
14305: $path = 'default&'.
14306: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
14307: ':::::&'.$path;
14308: }
14309: return $path;
14310: }
14311:
1.1094 raeburn 14312: sub captcha_display {
14313: my ($context,$lonhost) = @_;
14314: my ($output,$error);
14315: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14316: if ($captcha eq 'original') {
1.1094 raeburn 14317: $output = &create_captcha();
14318: unless ($output) {
14319: $error = 'captcha';
14320: }
14321: } elsif ($captcha eq 'recaptcha') {
14322: $output = &create_recaptcha($pubkey);
14323: unless ($output) {
1.1095 raeburn 14324: $error = 'recaptcha';
1.1094 raeburn 14325: }
14326: }
14327: return ($output,$error);
14328: }
14329:
14330: sub captcha_response {
14331: my ($context,$lonhost) = @_;
14332: my ($captcha_chk,$captcha_error);
14333: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14334: if ($captcha eq 'original') {
1.1094 raeburn 14335: ($captcha_chk,$captcha_error) = &check_captcha();
14336: } elsif ($captcha eq 'recaptcha') {
14337: $captcha_chk = &check_recaptcha($privkey);
14338: } else {
14339: $captcha_chk = 1;
14340: }
14341: return ($captcha_chk,$captcha_error);
14342: }
14343:
14344: sub get_captcha_config {
14345: my ($context,$lonhost) = @_;
1.1095 raeburn 14346: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14347: my $hostname = &Apache::lonnet::hostname($lonhost);
14348: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14349: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14350: if ($context eq 'usercreation') {
14351: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14352: if (ref($domconfig{$context}) eq 'HASH') {
14353: $hashtocheck = $domconfig{$context}{'cancreate'};
14354: if (ref($hashtocheck) eq 'HASH') {
14355: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14356: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14357: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14358: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14359: }
14360: if ($privkey && $pubkey) {
14361: $captcha = 'recaptcha';
14362: } else {
14363: $captcha = 'original';
14364: }
14365: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14366: $captcha = 'original';
14367: }
1.1094 raeburn 14368: }
1.1095 raeburn 14369: } else {
14370: $captcha = 'captcha';
14371: }
14372: } elsif ($context eq 'login') {
14373: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14374: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14375: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14376: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14377: if ($privkey && $pubkey) {
14378: $captcha = 'recaptcha';
1.1095 raeburn 14379: } else {
14380: $captcha = 'original';
1.1094 raeburn 14381: }
1.1095 raeburn 14382: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14383: $captcha = 'original';
1.1094 raeburn 14384: }
14385: }
14386: return ($captcha,$pubkey,$privkey);
14387: }
14388:
14389: sub create_captcha {
14390: my %captcha_params = &captcha_settings();
14391: my ($output,$maxtries,$tries) = ('',10,0);
14392: while ($tries < $maxtries) {
14393: $tries ++;
14394: my $captcha = Authen::Captcha->new (
14395: output_folder => $captcha_params{'output_dir'},
14396: data_folder => $captcha_params{'db_dir'},
14397: );
14398: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14399:
14400: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14401: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14402: &mt('Type in the letters/numbers shown below').' '.
14403: '<input type="text" size="5" name="code" value="" /><br />'.
14404: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14405: last;
14406: }
14407: }
14408: return $output;
14409: }
14410:
14411: sub captcha_settings {
14412: my %captcha_params = (
14413: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14414: www_output_dir => "/captchaspool",
14415: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14416: numchars => '5',
14417: );
14418: return %captcha_params;
14419: }
14420:
14421: sub check_captcha {
14422: my ($captcha_chk,$captcha_error);
14423: my $code = $env{'form.code'};
14424: my $md5sum = $env{'form.crypt'};
14425: my %captcha_params = &captcha_settings();
14426: my $captcha = Authen::Captcha->new(
14427: output_folder => $captcha_params{'output_dir'},
14428: data_folder => $captcha_params{'db_dir'},
14429: );
1.1109 raeburn 14430: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14431: my %captcha_hash = (
14432: 0 => 'Code not checked (file error)',
14433: -1 => 'Failed: code expired',
14434: -2 => 'Failed: invalid code (not in database)',
14435: -3 => 'Failed: invalid code (code does not match crypt)',
14436: );
14437: if ($captcha_chk != 1) {
14438: $captcha_error = $captcha_hash{$captcha_chk}
14439: }
14440: return ($captcha_chk,$captcha_error);
14441: }
14442:
14443: sub create_recaptcha {
14444: my ($pubkey) = @_;
14445: my $captcha = Captcha::reCAPTCHA->new;
14446: return $captcha->get_options_setter({theme => 'white'})."\n".
14447: $captcha->get_html($pubkey).
14448: &mt('If either word is hard to read, [_1] will replace them.',
14449: '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
14450: '<br /><br />';
14451: }
14452:
14453: sub check_recaptcha {
14454: my ($privkey) = @_;
14455: my $captcha_chk;
14456: my $captcha = Captcha::reCAPTCHA->new;
14457: my $captcha_result =
14458: $captcha->check_answer(
14459: $privkey,
14460: $ENV{'REMOTE_ADDR'},
14461: $env{'form.recaptcha_challenge_field'},
14462: $env{'form.recaptcha_response_field'},
14463: );
14464: if ($captcha_result->{is_valid}) {
14465: $captcha_chk = 1;
14466: }
14467: return $captcha_chk;
14468: }
14469:
1.41 ng 14470: =pod
14471:
14472: =back
14473:
1.112 bowersj2 14474: =cut
1.41 ng 14475:
1.112 bowersj2 14476: 1;
14477: __END__;
1.41 ng 14478:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>