Annotation of loncom/interface/loncommon.pm, revision 1.1140
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1140 ! raeburn 4: # $Id: loncommon.pm,v 1.1139 2013/07/12 00:15:40 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.1121 raeburn 2194: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
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:
1.1121 raeburn 2207: The optional $incdoms is a reference to an array of domains which will be the only available options.
2208:
2209: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2210:
1.35 matthew 2211: =cut
2212:
2213: #-------------------------------------------
1.34 matthew 2214: sub select_dom_form {
1.1121 raeburn 2215: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2216: if ($onchange) {
1.874 raeburn 2217: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2218: }
1.1121 raeburn 2219: my (@domains,%exclude);
1.910 raeburn 2220: if (ref($incdoms) eq 'ARRAY') {
2221: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2222: } else {
2223: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2224: }
1.90 www 2225: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2226: if (ref($excdoms) eq 'ARRAY') {
2227: map { $exclude{$_} = 1; } @{$excdoms};
2228: }
1.743 raeburn 2229: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2230: foreach my $dom (@domains) {
1.1121 raeburn 2231: next if ($exclude{$dom});
1.356 albertel 2232: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2233: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2234: if ($showdomdesc) {
2235: if ($dom ne '') {
2236: my $domdesc = &Apache::lonnet::domain($dom,'description');
2237: if ($domdesc ne '') {
2238: $selectdomain .= ' ('.$domdesc.')';
2239: }
2240: }
2241: }
2242: $selectdomain .= "</option>\n";
1.34 matthew 2243: }
2244: $selectdomain.="</select>";
2245: return $selectdomain;
2246: }
2247:
1.35 matthew 2248: #-------------------------------------------
2249:
1.45 matthew 2250: =pod
2251:
1.648 raeburn 2252: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2253:
1.586 raeburn 2254: input: 4 arguments (two required, two optional) -
2255: $domain - domain of new user
2256: $name - name of form element
2257: $default - Value of 'default' causes a default item to be first
2258: option, and selected by default.
2259: $hide - Value of 'hide' causes hiding of the name of the server,
2260: if 1 server found, or default, if 0 found.
1.594 raeburn 2261: output: returns 2 items:
1.586 raeburn 2262: (a) form element which contains either:
2263: (i) <select name="$name">
2264: <option value="$hostid1">$hostid $servers{$hostid}</option>
2265: <option value="$hostid2">$hostid $servers{$hostid}</option>
2266: </select>
2267: form item if there are multiple library servers in $domain, or
2268: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2269: if there is only one library server in $domain.
2270:
2271: (b) number of library servers found.
2272:
2273: See loncreateuser.pm for example of use.
1.35 matthew 2274:
2275: =cut
2276:
2277: #-------------------------------------------
1.586 raeburn 2278: sub home_server_form_item {
2279: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2280: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2281: my $result;
2282: my $numlib = keys(%servers);
2283: if ($numlib > 1) {
2284: $result .= '<select name="'.$name.'" />'."\n";
2285: if ($default) {
1.804 bisitz 2286: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2287: '</option>'."\n";
2288: }
2289: foreach my $hostid (sort(keys(%servers))) {
2290: $result.= '<option value="'.$hostid.'">'.
2291: $hostid.' '.$servers{$hostid}."</option>\n";
2292: }
2293: $result .= '</select>'."\n";
2294: } elsif ($numlib == 1) {
2295: my $hostid;
2296: foreach my $item (keys(%servers)) {
2297: $hostid = $item;
2298: }
2299: $result .= '<input type="hidden" name="'.$name.'" value="'.
2300: $hostid.'" />';
2301: if (!$hide) {
2302: $result .= $hostid.' '.$servers{$hostid};
2303: }
2304: $result .= "\n";
2305: } elsif ($default) {
2306: $result .= '<input type="hidden" name="'.$name.
2307: '" value="default" />';
2308: if (!$hide) {
2309: $result .= &mt('default');
2310: }
2311: $result .= "\n";
1.33 matthew 2312: }
1.586 raeburn 2313: return ($result,$numlib);
1.33 matthew 2314: }
1.112 bowersj2 2315:
2316: =pod
2317:
1.534 albertel 2318: =back
2319:
1.112 bowersj2 2320: =cut
1.87 matthew 2321:
2322: ###############################################################
1.112 bowersj2 2323: ## Decoding User Agent ##
1.87 matthew 2324: ###############################################################
2325:
2326: =pod
2327:
1.112 bowersj2 2328: =head1 Decoding the User Agent
2329:
2330: =over 4
2331:
2332: =item * &decode_user_agent()
1.87 matthew 2333:
2334: Inputs: $r
2335:
2336: Outputs:
2337:
2338: =over 4
2339:
1.112 bowersj2 2340: =item * $httpbrowser
1.87 matthew 2341:
1.112 bowersj2 2342: =item * $clientbrowser
1.87 matthew 2343:
1.112 bowersj2 2344: =item * $clientversion
1.87 matthew 2345:
1.112 bowersj2 2346: =item * $clientmathml
1.87 matthew 2347:
1.112 bowersj2 2348: =item * $clientunicode
1.87 matthew 2349:
1.112 bowersj2 2350: =item * $clientos
1.87 matthew 2351:
1.1137 raeburn 2352: =item * $clientmobile
2353:
1.87 matthew 2354: =back
2355:
1.157 matthew 2356: =back
2357:
1.87 matthew 2358: =cut
2359:
2360: ###############################################################
2361: ###############################################################
2362: sub decode_user_agent {
1.247 albertel 2363: my ($r)=@_;
1.87 matthew 2364: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2365: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2366: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2367: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2368: my $clientbrowser='unknown';
2369: my $clientversion='0';
2370: my $clientmathml='';
2371: my $clientunicode='0';
1.1137 raeburn 2372: my $clientmobile=0;
1.87 matthew 2373: for (my $i=0;$i<=$#browsertype;$i++) {
2374: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2375: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2376: $clientbrowser=$bname;
2377: $httpbrowser=~/$vreg/i;
2378: $clientversion=$1;
2379: $clientmathml=($clientversion>=$minv);
2380: $clientunicode=($clientversion>=$univ);
2381: }
2382: }
2383: my $clientos='unknown';
2384: if (($httpbrowser=~/linux/i) ||
2385: ($httpbrowser=~/unix/i) ||
2386: ($httpbrowser=~/ux/i) ||
2387: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2388: if (($httpbrowser=~/vax/i) ||
2389: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2390: if ($httpbrowser=~/next/i) { $clientos='next'; }
2391: if (($httpbrowser=~/mac/i) ||
2392: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2393: if ($httpbrowser=~/win/i) { $clientos='win'; }
2394: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2395: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2396: $clientmobile=lc($1);
2397: }
1.87 matthew 2398: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1137 raeburn 2399: $clientunicode,$clientos,$clientmobile);
1.87 matthew 2400: }
2401:
1.32 matthew 2402: ###############################################################
2403: ## Authentication changing form generation subroutines ##
2404: ###############################################################
2405: ##
2406: ## All of the authform_xxxxxxx subroutines take their inputs in a
2407: ## hash, and have reasonable default values.
2408: ##
2409: ## formname = the name given in the <form> tag.
1.35 matthew 2410: #-------------------------------------------
2411:
1.45 matthew 2412: =pod
2413:
1.112 bowersj2 2414: =head1 Authentication Routines
2415:
2416: =over 4
2417:
1.648 raeburn 2418: =item * &authform_xxxxxx()
1.35 matthew 2419:
2420: The authform_xxxxxx subroutines provide javascript and html forms which
2421: handle some of the conveniences required for authentication forms.
2422: This is not an optimal method, but it works.
2423:
2424: =over 4
2425:
1.112 bowersj2 2426: =item * authform_header
1.35 matthew 2427:
1.112 bowersj2 2428: =item * authform_authorwarning
1.35 matthew 2429:
1.112 bowersj2 2430: =item * authform_nochange
1.35 matthew 2431:
1.112 bowersj2 2432: =item * authform_kerberos
1.35 matthew 2433:
1.112 bowersj2 2434: =item * authform_internal
1.35 matthew 2435:
1.112 bowersj2 2436: =item * authform_filesystem
1.35 matthew 2437:
2438: =back
2439:
1.648 raeburn 2440: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2441:
1.35 matthew 2442: =cut
2443:
2444: #-------------------------------------------
1.32 matthew 2445: sub authform_header{
2446: my %in = (
2447: formname => 'cu',
1.80 albertel 2448: kerb_def_dom => '',
1.32 matthew 2449: @_,
2450: );
2451: $in{'formname'} = 'document.' . $in{'formname'};
2452: my $result='';
1.80 albertel 2453:
2454: #---------------------------------------------- Code for upper case translation
2455: my $Javascript_toUpperCase;
2456: unless ($in{kerb_def_dom}) {
2457: $Javascript_toUpperCase =<<"END";
2458: switch (choice) {
2459: case 'krb': currentform.elements[choicearg].value =
2460: currentform.elements[choicearg].value.toUpperCase();
2461: break;
2462: default:
2463: }
2464: END
2465: } else {
2466: $Javascript_toUpperCase = "";
2467: }
2468:
1.165 raeburn 2469: my $radioval = "'nochange'";
1.591 raeburn 2470: if (defined($in{'curr_authtype'})) {
2471: if ($in{'curr_authtype'} ne '') {
2472: $radioval = "'".$in{'curr_authtype'}."arg'";
2473: }
1.174 matthew 2474: }
1.165 raeburn 2475: my $argfield = 'null';
1.591 raeburn 2476: if (defined($in{'mode'})) {
1.165 raeburn 2477: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2478: if (defined($in{'curr_autharg'})) {
2479: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2480: $argfield = "'$in{'curr_autharg'}'";
2481: }
2482: }
2483: }
2484: }
2485:
1.32 matthew 2486: $result.=<<"END";
2487: var current = new Object();
1.165 raeburn 2488: current.radiovalue = $radioval;
2489: current.argfield = $argfield;
1.32 matthew 2490:
2491: function changed_radio(choice,currentform) {
2492: var choicearg = choice + 'arg';
2493: // If a radio button in changed, we need to change the argfield
2494: if (current.radiovalue != choice) {
2495: current.radiovalue = choice;
2496: if (current.argfield != null) {
2497: currentform.elements[current.argfield].value = '';
2498: }
2499: if (choice == 'nochange') {
2500: current.argfield = null;
2501: } else {
2502: current.argfield = choicearg;
2503: switch(choice) {
2504: case 'krb':
2505: currentform.elements[current.argfield].value =
2506: "$in{'kerb_def_dom'}";
2507: break;
2508: default:
2509: break;
2510: }
2511: }
2512: }
2513: return;
2514: }
1.22 www 2515:
1.32 matthew 2516: function changed_text(choice,currentform) {
2517: var choicearg = choice + 'arg';
2518: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2519: $Javascript_toUpperCase
1.32 matthew 2520: // clear old field
2521: if ((current.argfield != choicearg) && (current.argfield != null)) {
2522: currentform.elements[current.argfield].value = '';
2523: }
2524: current.argfield = choicearg;
2525: }
2526: set_auth_radio_buttons(choice,currentform);
2527: return;
1.20 www 2528: }
1.32 matthew 2529:
2530: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2531: var numauthchoices = currentform.login.length;
2532: if (typeof numauthchoices == "undefined") {
2533: return;
2534: }
1.32 matthew 2535: var i=0;
1.986 raeburn 2536: while (i < numauthchoices) {
1.32 matthew 2537: if (currentform.login[i].value == newvalue) { break; }
2538: i++;
2539: }
1.986 raeburn 2540: if (i == numauthchoices) {
1.32 matthew 2541: return;
2542: }
2543: current.radiovalue = newvalue;
2544: currentform.login[i].checked = true;
2545: return;
2546: }
2547: END
2548: return $result;
2549: }
2550:
1.1106 raeburn 2551: sub authform_authorwarning {
1.32 matthew 2552: my $result='';
1.144 matthew 2553: $result='<i>'.
2554: &mt('As a general rule, only authors or co-authors should be '.
2555: 'filesystem authenticated '.
2556: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2557: return $result;
2558: }
2559:
1.1106 raeburn 2560: sub authform_nochange {
1.32 matthew 2561: my %in = (
2562: formname => 'document.cu',
2563: kerb_def_dom => 'MSU.EDU',
2564: @_,
2565: );
1.1106 raeburn 2566: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2567: my $result;
1.1104 raeburn 2568: if (!$authnum) {
1.1105 raeburn 2569: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2570: } else {
2571: $result = '<label>'.&mt('[_1] Do not change login data',
2572: '<input type="radio" name="login" value="nochange" '.
2573: 'checked="checked" onclick="'.
1.281 albertel 2574: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2575: '</label>';
1.586 raeburn 2576: }
1.32 matthew 2577: return $result;
2578: }
2579:
1.591 raeburn 2580: sub authform_kerberos {
1.32 matthew 2581: my %in = (
2582: formname => 'document.cu',
2583: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2584: kerb_def_auth => 'krb4',
1.32 matthew 2585: @_,
2586: );
1.586 raeburn 2587: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2588: $autharg,$jscall);
1.1106 raeburn 2589: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2590: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2591: $check5 = ' checked="checked"';
1.80 albertel 2592: } else {
1.772 bisitz 2593: $check4 = ' checked="checked"';
1.80 albertel 2594: }
1.165 raeburn 2595: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2596: if (defined($in{'curr_authtype'})) {
2597: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2598: $krbcheck = ' checked="checked"';
1.623 raeburn 2599: if (defined($in{'mode'})) {
2600: if ($in{'mode'} eq 'modifyuser') {
2601: $krbcheck = '';
2602: }
2603: }
1.591 raeburn 2604: if (defined($in{'curr_kerb_ver'})) {
2605: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2606: $check5 = ' checked="checked"';
1.591 raeburn 2607: $check4 = '';
2608: } else {
1.772 bisitz 2609: $check4 = ' checked="checked"';
1.591 raeburn 2610: $check5 = '';
2611: }
1.586 raeburn 2612: }
1.591 raeburn 2613: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2614: $krbarg = $in{'curr_autharg'};
2615: }
1.586 raeburn 2616: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2617: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2618: $result =
2619: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2620: $in{'curr_autharg'},$krbver);
2621: } else {
2622: $result =
2623: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2624: }
2625: return $result;
2626: }
2627: }
2628: } else {
2629: if ($authnum == 1) {
1.784 bisitz 2630: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2631: }
2632: }
1.586 raeburn 2633: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2634: return;
1.587 raeburn 2635: } elsif ($authtype eq '') {
1.591 raeburn 2636: if (defined($in{'mode'})) {
1.587 raeburn 2637: if ($in{'mode'} eq 'modifycourse') {
2638: if ($authnum == 1) {
1.1104 raeburn 2639: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2640: }
2641: }
2642: }
1.586 raeburn 2643: }
2644: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2645: if ($authtype eq '') {
2646: $authtype = '<input type="radio" name="login" value="krb" '.
2647: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2648: $krbcheck.' />';
2649: }
2650: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2651: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2652: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2653: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2654: $in{'curr_authtype'} eq 'krb4')) {
2655: $result .= &mt
1.144 matthew 2656: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2657: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2658: '<label>'.$authtype,
1.281 albertel 2659: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2660: 'value="'.$krbarg.'" '.
1.144 matthew 2661: 'onchange="'.$jscall.'" />',
1.281 albertel 2662: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2663: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2664: '</label>');
1.586 raeburn 2665: } elsif ($can_assign{'krb4'}) {
2666: $result .= &mt
2667: ('[_1] Kerberos authenticated with domain [_2] '.
2668: '[_3] Version 4 [_4]',
2669: '<label>'.$authtype,
2670: '</label><input type="text" size="10" name="krbarg" '.
2671: 'value="'.$krbarg.'" '.
2672: 'onchange="'.$jscall.'" />',
2673: '<label><input type="hidden" name="krbver" value="4" />',
2674: '</label>');
2675: } elsif ($can_assign{'krb5'}) {
2676: $result .= &mt
2677: ('[_1] Kerberos authenticated with domain [_2] '.
2678: '[_3] Version 5 [_4]',
2679: '<label>'.$authtype,
2680: '</label><input type="text" size="10" name="krbarg" '.
2681: 'value="'.$krbarg.'" '.
2682: 'onchange="'.$jscall.'" />',
2683: '<label><input type="hidden" name="krbver" value="5" />',
2684: '</label>');
2685: }
1.32 matthew 2686: return $result;
2687: }
2688:
1.1106 raeburn 2689: sub authform_internal {
1.586 raeburn 2690: my %in = (
1.32 matthew 2691: formname => 'document.cu',
2692: kerb_def_dom => 'MSU.EDU',
2693: @_,
2694: );
1.586 raeburn 2695: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2696: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2697: if (defined($in{'curr_authtype'})) {
2698: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2699: if ($can_assign{'int'}) {
1.772 bisitz 2700: $intcheck = 'checked="checked" ';
1.623 raeburn 2701: if (defined($in{'mode'})) {
2702: if ($in{'mode'} eq 'modifyuser') {
2703: $intcheck = '';
2704: }
2705: }
1.591 raeburn 2706: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2707: $intarg = $in{'curr_autharg'};
2708: }
2709: } else {
2710: $result = &mt('Currently internally authenticated.');
2711: return $result;
1.165 raeburn 2712: }
2713: }
1.586 raeburn 2714: } else {
2715: if ($authnum == 1) {
1.784 bisitz 2716: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2717: }
2718: }
2719: if (!$can_assign{'int'}) {
2720: return;
1.587 raeburn 2721: } elsif ($authtype eq '') {
1.591 raeburn 2722: if (defined($in{'mode'})) {
1.587 raeburn 2723: if ($in{'mode'} eq 'modifycourse') {
2724: if ($authnum == 1) {
1.1104 raeburn 2725: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2726: }
2727: }
2728: }
1.165 raeburn 2729: }
1.586 raeburn 2730: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2731: if ($authtype eq '') {
2732: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2733: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2734: }
1.605 bisitz 2735: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2736: $intarg.'" onchange="'.$jscall.'" />';
2737: $result = &mt
1.144 matthew 2738: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2739: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2740: $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 2741: return $result;
2742: }
2743:
1.1104 raeburn 2744: sub authform_local {
1.32 matthew 2745: my %in = (
2746: formname => 'document.cu',
2747: kerb_def_dom => 'MSU.EDU',
2748: @_,
2749: );
1.586 raeburn 2750: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2751: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2752: if (defined($in{'curr_authtype'})) {
2753: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2754: if ($can_assign{'loc'}) {
1.772 bisitz 2755: $loccheck = 'checked="checked" ';
1.623 raeburn 2756: if (defined($in{'mode'})) {
2757: if ($in{'mode'} eq 'modifyuser') {
2758: $loccheck = '';
2759: }
2760: }
1.591 raeburn 2761: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2762: $locarg = $in{'curr_autharg'};
2763: }
2764: } else {
2765: $result = &mt('Currently using local (institutional) authentication.');
2766: return $result;
1.165 raeburn 2767: }
2768: }
1.586 raeburn 2769: } else {
2770: if ($authnum == 1) {
1.784 bisitz 2771: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2772: }
2773: }
2774: if (!$can_assign{'loc'}) {
2775: return;
1.587 raeburn 2776: } elsif ($authtype eq '') {
1.591 raeburn 2777: if (defined($in{'mode'})) {
1.587 raeburn 2778: if ($in{'mode'} eq 'modifycourse') {
2779: if ($authnum == 1) {
1.1104 raeburn 2780: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2781: }
2782: }
2783: }
1.165 raeburn 2784: }
1.586 raeburn 2785: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2786: if ($authtype eq '') {
2787: $authtype = '<input type="radio" name="login" value="loc" '.
2788: $loccheck.' onchange="'.$jscall.'" onclick="'.
2789: $jscall.'" />';
2790: }
2791: $autharg = '<input type="text" size="10" name="locarg" value="'.
2792: $locarg.'" onchange="'.$jscall.'" />';
2793: $result = &mt('[_1] Local Authentication with argument [_2]',
2794: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2795: return $result;
2796: }
2797:
1.1106 raeburn 2798: sub authform_filesystem {
1.32 matthew 2799: my %in = (
2800: formname => 'document.cu',
2801: kerb_def_dom => 'MSU.EDU',
2802: @_,
2803: );
1.586 raeburn 2804: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2805: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2806: if (defined($in{'curr_authtype'})) {
2807: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2808: if ($can_assign{'fsys'}) {
1.772 bisitz 2809: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2810: if (defined($in{'mode'})) {
2811: if ($in{'mode'} eq 'modifyuser') {
2812: $fsyscheck = '';
2813: }
2814: }
1.586 raeburn 2815: } else {
2816: $result = &mt('Currently Filesystem Authenticated.');
2817: return $result;
2818: }
2819: }
2820: } else {
2821: if ($authnum == 1) {
1.784 bisitz 2822: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2823: }
2824: }
2825: if (!$can_assign{'fsys'}) {
2826: return;
1.587 raeburn 2827: } elsif ($authtype eq '') {
1.591 raeburn 2828: if (defined($in{'mode'})) {
1.587 raeburn 2829: if ($in{'mode'} eq 'modifycourse') {
2830: if ($authnum == 1) {
1.1104 raeburn 2831: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2832: }
2833: }
2834: }
1.586 raeburn 2835: }
2836: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2837: if ($authtype eq '') {
2838: $authtype = '<input type="radio" name="login" value="fsys" '.
2839: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2840: $jscall.'" />';
2841: }
2842: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2843: ' onchange="'.$jscall.'" />';
2844: $result = &mt
1.144 matthew 2845: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2846: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2847: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2848: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2849: 'onchange="'.$jscall.'" />');
1.32 matthew 2850: return $result;
2851: }
2852:
1.586 raeburn 2853: sub get_assignable_auth {
2854: my ($dom) = @_;
2855: if ($dom eq '') {
2856: $dom = $env{'request.role.domain'};
2857: }
2858: my %can_assign = (
2859: krb4 => 1,
2860: krb5 => 1,
2861: int => 1,
2862: loc => 1,
2863: );
2864: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2865: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2866: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2867: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2868: my $context;
2869: if ($env{'request.role'} =~ /^au/) {
2870: $context = 'author';
2871: } elsif ($env{'request.role'} =~ /^dc/) {
2872: $context = 'domain';
2873: } elsif ($env{'request.course.id'}) {
2874: $context = 'course';
2875: }
2876: if ($context) {
2877: if (ref($authhash->{$context}) eq 'HASH') {
2878: %can_assign = %{$authhash->{$context}};
2879: }
2880: }
2881: }
2882: }
2883: my $authnum = 0;
2884: foreach my $key (keys(%can_assign)) {
2885: if ($can_assign{$key}) {
2886: $authnum ++;
2887: }
2888: }
2889: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2890: $authnum --;
2891: }
2892: return ($authnum,%can_assign);
2893: }
2894:
1.80 albertel 2895: ###############################################################
2896: ## Get Kerberos Defaults for Domain ##
2897: ###############################################################
2898: ##
2899: ## Returns default kerberos version and an associated argument
2900: ## as listed in file domain.tab. If not listed, provides
2901: ## appropriate default domain and kerberos version.
2902: ##
2903: #-------------------------------------------
2904:
2905: =pod
2906:
1.648 raeburn 2907: =item * &get_kerberos_defaults()
1.80 albertel 2908:
2909: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2910: version and domain. If not found, it defaults to version 4 and the
2911: domain of the server.
1.80 albertel 2912:
1.648 raeburn 2913: =over 4
2914:
1.80 albertel 2915: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2916:
1.648 raeburn 2917: =back
2918:
2919: =back
2920:
1.80 albertel 2921: =cut
2922:
2923: #-------------------------------------------
2924: sub get_kerberos_defaults {
2925: my $domain=shift;
1.641 raeburn 2926: my ($krbdef,$krbdefdom);
2927: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2928: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2929: $krbdef = $domdefaults{'auth_def'};
2930: $krbdefdom = $domdefaults{'auth_arg_def'};
2931: } else {
1.80 albertel 2932: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2933: my $krbdefdom=$1;
2934: $krbdefdom=~tr/a-z/A-Z/;
2935: $krbdef = "krb4";
2936: }
2937: return ($krbdef,$krbdefdom);
2938: }
1.112 bowersj2 2939:
1.32 matthew 2940:
1.46 matthew 2941: ###############################################################
2942: ## Thesaurus Functions ##
2943: ###############################################################
1.20 www 2944:
1.46 matthew 2945: =pod
1.20 www 2946:
1.112 bowersj2 2947: =head1 Thesaurus Functions
2948:
2949: =over 4
2950:
1.648 raeburn 2951: =item * &initialize_keywords()
1.46 matthew 2952:
2953: Initializes the package variable %Keywords if it is empty. Uses the
2954: package variable $thesaurus_db_file.
2955:
2956: =cut
2957:
2958: ###################################################
2959:
2960: sub initialize_keywords {
2961: return 1 if (scalar keys(%Keywords));
2962: # If we are here, %Keywords is empty, so fill it up
2963: # Make sure the file we need exists...
2964: if (! -e $thesaurus_db_file) {
2965: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2966: " failed because it does not exist");
2967: return 0;
2968: }
2969: # Set up the hash as a database
2970: my %thesaurus_db;
2971: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2972: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2973: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2974: $thesaurus_db_file);
2975: return 0;
2976: }
2977: # Get the average number of appearances of a word.
2978: my $avecount = $thesaurus_db{'average.count'};
2979: # Put keywords (those that appear > average) into %Keywords
2980: while (my ($word,$data)=each (%thesaurus_db)) {
2981: my ($count,undef) = split /:/,$data;
2982: $Keywords{$word}++ if ($count > $avecount);
2983: }
2984: untie %thesaurus_db;
2985: # Remove special values from %Keywords.
1.356 albertel 2986: foreach my $value ('total.count','average.count') {
2987: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2988: }
1.46 matthew 2989: return 1;
2990: }
2991:
2992: ###################################################
2993:
2994: =pod
2995:
1.648 raeburn 2996: =item * &keyword($word)
1.46 matthew 2997:
2998: Returns true if $word is a keyword. A keyword is a word that appears more
2999: than the average number of times in the thesaurus database. Calls
3000: &initialize_keywords
3001:
3002: =cut
3003:
3004: ###################################################
1.20 www 3005:
3006: sub keyword {
1.46 matthew 3007: return if (!&initialize_keywords());
3008: my $word=lc(shift());
3009: $word=~s/\W//g;
3010: return exists($Keywords{$word});
1.20 www 3011: }
1.46 matthew 3012:
3013: ###############################################################
3014:
3015: =pod
1.20 www 3016:
1.648 raeburn 3017: =item * &get_related_words()
1.46 matthew 3018:
1.160 matthew 3019: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3020: an array of words. If the keyword is not in the thesaurus, an empty array
3021: will be returned. The order of the words returned is determined by the
3022: database which holds them.
3023:
3024: Uses global $thesaurus_db_file.
3025:
1.1057 foxr 3026:
1.46 matthew 3027: =cut
3028:
3029: ###############################################################
3030: sub get_related_words {
3031: my $keyword = shift;
3032: my %thesaurus_db;
3033: if (! -e $thesaurus_db_file) {
3034: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3035: "failed because the file does not exist");
3036: return ();
3037: }
3038: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3039: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3040: return ();
3041: }
3042: my @Words=();
1.429 www 3043: my $count=0;
1.46 matthew 3044: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3045: # The first element is the number of times
3046: # the word appears. We do not need it now.
1.429 www 3047: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3048: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3049: my $threshold=$mostfrequentcount/10;
3050: foreach my $possibleword (@RelatedWords) {
3051: my ($word,$wordcount)=split(/\,/,$possibleword);
3052: if ($wordcount>$threshold) {
3053: push(@Words,$word);
3054: $count++;
3055: if ($count>10) { last; }
3056: }
1.20 www 3057: }
3058: }
1.46 matthew 3059: untie %thesaurus_db;
3060: return @Words;
1.14 harris41 3061: }
1.1090 foxr 3062: ###############################################################
3063: #
3064: # Spell checking
3065: #
3066:
3067: =pod
3068:
3069: =head1 Spell checking
3070:
3071: =over 4
3072:
3073: =item * &check_spelling($wordlist $language)
3074:
3075: Takes a string containing words and feeds it to an external
3076: spellcheck program via a pipeline. Returns a string containing
3077: them mis-spelled words.
3078:
3079: Parameters:
3080:
3081: =over 4
3082:
3083: =item - $wordlist
3084:
3085: String that will be fed into the spellcheck program.
3086:
3087: =item - $language
3088:
3089: Language string that specifies the language for which the spell
3090: check will be performed.
3091:
3092: =back
3093:
3094: =back
3095:
3096: Note: This sub assumes that aspell is installed.
3097:
3098:
3099: =cut
3100:
1.46 matthew 3101:
1.112 bowersj2 3102: =pod
3103:
3104: =back
3105:
3106: =cut
1.61 www 3107:
1.1090 foxr 3108: sub check_spelling {
3109: my ($wordlist, $language) = @_;
1.1091 foxr 3110: my @misspellings;
3111:
3112: # Generate the speller and set the langauge.
3113: # if explicitly selected:
1.1090 foxr 3114:
1.1091 foxr 3115: my $speller = Text::Aspell->new;
1.1090 foxr 3116: if ($language) {
1.1091 foxr 3117: $speller->set_option('lang', $language);
1.1090 foxr 3118: }
3119:
1.1091 foxr 3120: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3121:
1.1091 foxr 3122: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3123:
1.1091 foxr 3124: foreach my $word (@words) {
3125: if(! $speller->check($word)) {
3126: push(@misspellings, $word);
1.1090 foxr 3127: }
3128: }
1.1091 foxr 3129: return join(' ', @misspellings);
3130:
1.1090 foxr 3131: }
3132:
1.61 www 3133: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3134: =pod
3135:
1.112 bowersj2 3136: =head1 User Name Functions
3137:
3138: =over 4
3139:
1.648 raeburn 3140: =item * &plainname($uname,$udom,$first)
1.81 albertel 3141:
1.112 bowersj2 3142: Takes a users logon name and returns it as a string in
1.226 albertel 3143: "first middle last generation" form
3144: if $first is set to 'lastname' then it returns it as
3145: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3146:
3147: =cut
1.61 www 3148:
1.295 www 3149:
1.81 albertel 3150: ###############################################################
1.61 www 3151: sub plainname {
1.226 albertel 3152: my ($uname,$udom,$first)=@_;
1.537 albertel 3153: return if (!defined($uname) || !defined($udom));
1.295 www 3154: my %names=&getnames($uname,$udom);
1.226 albertel 3155: my $name=&Apache::lonnet::format_name($names{'firstname'},
3156: $names{'middlename'},
3157: $names{'lastname'},
3158: $names{'generation'},$first);
3159: $name=~s/^\s+//;
1.62 www 3160: $name=~s/\s+$//;
3161: $name=~s/\s+/ /g;
1.353 albertel 3162: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3163: return $name;
1.61 www 3164: }
1.66 www 3165:
3166: # -------------------------------------------------------------------- Nickname
1.81 albertel 3167: =pod
3168:
1.648 raeburn 3169: =item * &nickname($uname,$udom)
1.81 albertel 3170:
3171: Gets a users name and returns it as a string as
3172:
3173: ""nickname""
1.66 www 3174:
1.81 albertel 3175: if the user has a nickname or
3176:
3177: "first middle last generation"
3178:
3179: if the user does not
3180:
3181: =cut
1.66 www 3182:
3183: sub nickname {
3184: my ($uname,$udom)=@_;
1.537 albertel 3185: return if (!defined($uname) || !defined($udom));
1.295 www 3186: my %names=&getnames($uname,$udom);
1.68 albertel 3187: my $name=$names{'nickname'};
1.66 www 3188: if ($name) {
3189: $name='"'.$name.'"';
3190: } else {
3191: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3192: $names{'lastname'}.' '.$names{'generation'};
3193: $name=~s/\s+$//;
3194: $name=~s/\s+/ /g;
3195: }
3196: return $name;
3197: }
3198:
1.295 www 3199: sub getnames {
3200: my ($uname,$udom)=@_;
1.537 albertel 3201: return if (!defined($uname) || !defined($udom));
1.433 albertel 3202: if ($udom eq 'public' && $uname eq 'public') {
3203: return ('lastname' => &mt('Public'));
3204: }
1.295 www 3205: my $id=$uname.':'.$udom;
3206: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3207: if ($cached) {
3208: return %{$names};
3209: } else {
3210: my %loadnames=&Apache::lonnet::get('environment',
3211: ['firstname','middlename','lastname','generation','nickname'],
3212: $udom,$uname);
3213: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3214: return %loadnames;
3215: }
3216: }
1.61 www 3217:
1.542 raeburn 3218: # -------------------------------------------------------------------- getemails
1.648 raeburn 3219:
1.542 raeburn 3220: =pod
3221:
1.648 raeburn 3222: =item * &getemails($uname,$udom)
1.542 raeburn 3223:
3224: Gets a user's email information and returns it as a hash with keys:
3225: notification, critnotification, permanentemail
3226:
3227: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3228: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3229:
1.648 raeburn 3230:
1.542 raeburn 3231: =cut
3232:
1.648 raeburn 3233:
1.466 albertel 3234: sub getemails {
3235: my ($uname,$udom)=@_;
3236: if ($udom eq 'public' && $uname eq 'public') {
3237: return;
3238: }
1.467 www 3239: if (!$udom) { $udom=$env{'user.domain'}; }
3240: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3241: my $id=$uname.':'.$udom;
3242: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3243: if ($cached) {
3244: return %{$names};
3245: } else {
3246: my %loadnames=&Apache::lonnet::get('environment',
3247: ['notification','critnotification',
3248: 'permanentemail'],
3249: $udom,$uname);
3250: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3251: return %loadnames;
3252: }
3253: }
3254:
1.551 albertel 3255: sub flush_email_cache {
3256: my ($uname,$udom)=@_;
3257: if (!$udom) { $udom =$env{'user.domain'}; }
3258: if (!$uname) { $uname=$env{'user.name'}; }
3259: return if ($udom eq 'public' && $uname eq 'public');
3260: my $id=$uname.':'.$udom;
3261: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3262: }
3263:
1.728 raeburn 3264: # -------------------------------------------------------------------- getlangs
3265:
3266: =pod
3267:
3268: =item * &getlangs($uname,$udom)
3269:
3270: Gets a user's language preference and returns it as a hash with key:
3271: language.
3272:
3273: =cut
3274:
3275:
3276: sub getlangs {
3277: my ($uname,$udom) = @_;
3278: if (!$udom) { $udom =$env{'user.domain'}; }
3279: if (!$uname) { $uname=$env{'user.name'}; }
3280: my $id=$uname.':'.$udom;
3281: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3282: if ($cached) {
3283: return %{$langs};
3284: } else {
3285: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3286: $udom,$uname);
3287: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3288: return %loadlangs;
3289: }
3290: }
3291:
3292: sub flush_langs_cache {
3293: my ($uname,$udom)=@_;
3294: if (!$udom) { $udom =$env{'user.domain'}; }
3295: if (!$uname) { $uname=$env{'user.name'}; }
3296: return if ($udom eq 'public' && $uname eq 'public');
3297: my $id=$uname.':'.$udom;
3298: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3299: }
3300:
1.61 www 3301: # ------------------------------------------------------------------ Screenname
1.81 albertel 3302:
3303: =pod
3304:
1.648 raeburn 3305: =item * &screenname($uname,$udom)
1.81 albertel 3306:
3307: Gets a users screenname and returns it as a string
3308:
3309: =cut
1.61 www 3310:
3311: sub screenname {
3312: my ($uname,$udom)=@_;
1.258 albertel 3313: if ($uname eq $env{'user.name'} &&
3314: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3315: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3316: return $names{'screenname'};
1.62 www 3317: }
3318:
1.212 albertel 3319:
1.802 bisitz 3320: # ------------------------------------------------------------- Confirm Wrapper
3321: =pod
3322:
3323: =item confirmwrapper
3324:
3325: Wrap messages about completion of operation in box
3326:
3327: =cut
3328:
3329: sub confirmwrapper {
3330: my ($message)=@_;
3331: if ($message) {
3332: return "\n".'<div class="LC_confirm_box">'."\n"
3333: .$message."\n"
3334: .'</div>'."\n";
3335: } else {
3336: return $message;
3337: }
3338: }
3339:
1.62 www 3340: # ------------------------------------------------------------- Message Wrapper
3341:
3342: sub messagewrapper {
1.369 www 3343: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3344: return
1.441 albertel 3345: '<a href="/adm/email?compose=individual&'.
3346: 'recname='.$username.'&recdom='.$domain.
3347: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3348: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3349: }
1.802 bisitz 3350:
1.74 www 3351: # --------------------------------------------------------------- Notes Wrapper
3352:
3353: sub noteswrapper {
3354: my ($link,$un,$do)=@_;
3355: return
1.896 amueller 3356: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3357: }
1.802 bisitz 3358:
1.62 www 3359: # ------------------------------------------------------------- Aboutme Wrapper
3360:
3361: sub aboutmewrapper {
1.1070 raeburn 3362: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3363: if (!defined($username) && !defined($domain)) {
3364: return;
3365: }
1.1096 raeburn 3366: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3367: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3368: }
3369:
3370: # ------------------------------------------------------------ Syllabus Wrapper
3371:
3372: sub syllabuswrapper {
1.707 bisitz 3373: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3374: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3375: }
1.14 harris41 3376:
1.802 bisitz 3377: # -----------------------------------------------------------------------------
3378:
1.208 matthew 3379: sub track_student_link {
1.887 raeburn 3380: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3381: my $link ="/adm/trackstudent?";
1.208 matthew 3382: my $title = 'View recent activity';
3383: if (defined($sname) && $sname !~ /^\s*$/ &&
3384: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3385: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3386: $title .= ' of this student';
1.268 albertel 3387: }
1.208 matthew 3388: if (defined($target) && $target !~ /^\s*$/) {
3389: $target = qq{target="$target"};
3390: } else {
3391: $target = '';
3392: }
1.268 albertel 3393: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3394: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3395: $title = &mt($title);
3396: $linktext = &mt($linktext);
1.448 albertel 3397: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3398: &help_open_topic('View_recent_activity');
1.208 matthew 3399: }
3400:
1.781 raeburn 3401: sub slot_reservations_link {
3402: my ($linktext,$sname,$sdom,$target) = @_;
3403: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3404: my $title = 'View slot reservation history';
3405: if (defined($sname) && $sname !~ /^\s*$/ &&
3406: defined($sdom) && $sdom !~ /^\s*$/) {
3407: $link .= "&uname=$sname&udom=$sdom";
3408: $title .= ' of this student';
3409: }
3410: if (defined($target) && $target !~ /^\s*$/) {
3411: $target = qq{target="$target"};
3412: } else {
3413: $target = '';
3414: }
3415: $title = &mt($title);
3416: $linktext = &mt($linktext);
3417: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3418: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3419:
3420: }
3421:
1.508 www 3422: # ===================================================== Display a student photo
3423:
3424:
1.509 albertel 3425: sub student_image_tag {
1.508 www 3426: my ($domain,$user)=@_;
3427: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3428: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3429: return '<img src="'.$imgsrc.'" align="right" />';
3430: } else {
3431: return '';
3432: }
3433: }
3434:
1.112 bowersj2 3435: =pod
3436:
3437: =back
3438:
3439: =head1 Access .tab File Data
3440:
3441: =over 4
3442:
1.648 raeburn 3443: =item * &languageids()
1.112 bowersj2 3444:
3445: returns list of all language ids
3446:
3447: =cut
3448:
1.14 harris41 3449: sub languageids {
1.16 harris41 3450: return sort(keys(%language));
1.14 harris41 3451: }
3452:
1.112 bowersj2 3453: =pod
3454:
1.648 raeburn 3455: =item * &languagedescription()
1.112 bowersj2 3456:
3457: returns description of a specified language id
3458:
3459: =cut
3460:
1.14 harris41 3461: sub languagedescription {
1.125 www 3462: my $code=shift;
3463: return ($supported_language{$code}?'* ':'').
3464: $language{$code}.
1.126 www 3465: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3466: }
3467:
1.1048 foxr 3468: =pod
3469:
3470: =item * &plainlanguagedescription
3471:
3472: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3473: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3474:
3475: =cut
3476:
1.145 www 3477: sub plainlanguagedescription {
3478: my $code=shift;
3479: return $language{$code};
3480: }
3481:
1.1048 foxr 3482: =pod
3483:
3484: =item * &supportedlanguagecode
3485:
3486: Returns the supported language code (e.g. sptutf maps to pt) given a language
3487: code.
3488:
3489: =cut
3490:
1.145 www 3491: sub supportedlanguagecode {
3492: my $code=shift;
3493: return $supported_language{$code};
1.97 www 3494: }
3495:
1.112 bowersj2 3496: =pod
3497:
1.1048 foxr 3498: =item * &latexlanguage()
3499:
3500: Given a language key code returns the correspondnig language to use
3501: to select the correct hyphenation on LaTeX printouts. This is undef if there
3502: is no supported hyphenation for the language code.
3503:
3504: =cut
3505:
3506: sub latexlanguage {
3507: my $code = shift;
3508: return $latex_language{$code};
3509: }
3510:
3511: =pod
3512:
3513: =item * &latexhyphenation()
3514:
3515: Same as above but what's supplied is the language as it might be stored
3516: in the metadata.
3517:
3518: =cut
3519:
3520: sub latexhyphenation {
3521: my $key = shift;
3522: return $latex_language_bykey{$key};
3523: }
3524:
3525: =pod
3526:
1.648 raeburn 3527: =item * ©rightids()
1.112 bowersj2 3528:
3529: returns list of all copyrights
3530:
3531: =cut
3532:
3533: sub copyrightids {
3534: return sort(keys(%cprtag));
3535: }
3536:
3537: =pod
3538:
1.648 raeburn 3539: =item * ©rightdescription()
1.112 bowersj2 3540:
3541: returns description of a specified copyright id
3542:
3543: =cut
3544:
3545: sub copyrightdescription {
1.166 www 3546: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3547: }
1.197 matthew 3548:
3549: =pod
3550:
1.648 raeburn 3551: =item * &source_copyrightids()
1.192 taceyjo1 3552:
3553: returns list of all source copyrights
3554:
3555: =cut
3556:
3557: sub source_copyrightids {
3558: return sort(keys(%scprtag));
3559: }
3560:
3561: =pod
3562:
1.648 raeburn 3563: =item * &source_copyrightdescription()
1.192 taceyjo1 3564:
3565: returns description of a specified source copyright id
3566:
3567: =cut
3568:
3569: sub source_copyrightdescription {
3570: return &mt($scprtag{shift(@_)});
3571: }
1.112 bowersj2 3572:
3573: =pod
3574:
1.648 raeburn 3575: =item * &filecategories()
1.112 bowersj2 3576:
3577: returns list of all file categories
3578:
3579: =cut
3580:
3581: sub filecategories {
3582: return sort(keys(%category_extensions));
3583: }
3584:
3585: =pod
3586:
1.648 raeburn 3587: =item * &filecategorytypes()
1.112 bowersj2 3588:
3589: returns list of file types belonging to a given file
3590: category
3591:
3592: =cut
3593:
3594: sub filecategorytypes {
1.356 albertel 3595: my ($cat) = @_;
3596: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3597: }
3598:
3599: =pod
3600:
1.648 raeburn 3601: =item * &fileembstyle()
1.112 bowersj2 3602:
3603: returns embedding style for a specified file type
3604:
3605: =cut
3606:
3607: sub fileembstyle {
3608: return $fe{lc(shift(@_))};
1.169 www 3609: }
3610:
1.351 www 3611: sub filemimetype {
3612: return $fm{lc(shift(@_))};
3613: }
3614:
1.169 www 3615:
3616: sub filecategoryselect {
3617: my ($name,$value)=@_;
1.189 matthew 3618: return &select_form($value,$name,
1.970 raeburn 3619: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3620: }
3621:
3622: =pod
3623:
1.648 raeburn 3624: =item * &filedescription()
1.112 bowersj2 3625:
3626: returns description for a specified file type
3627:
3628: =cut
3629:
3630: sub filedescription {
1.188 matthew 3631: my $file_description = $fd{lc(shift())};
3632: $file_description =~ s:([\[\]]):~$1:g;
3633: return &mt($file_description);
1.112 bowersj2 3634: }
3635:
3636: =pod
3637:
1.648 raeburn 3638: =item * &filedescriptionex()
1.112 bowersj2 3639:
3640: returns description for a specified file type with
3641: extra formatting
3642:
3643: =cut
3644:
3645: sub filedescriptionex {
3646: my $ex=shift;
1.188 matthew 3647: my $file_description = $fd{lc($ex)};
3648: $file_description =~ s:([\[\]]):~$1:g;
3649: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3650: }
3651:
3652: # End of .tab access
3653: =pod
3654:
3655: =back
3656:
3657: =cut
3658:
3659: # ------------------------------------------------------------------ File Types
3660: sub fileextensions {
3661: return sort(keys(%fe));
3662: }
3663:
1.97 www 3664: # ----------------------------------------------------------- Display Languages
3665: # returns a hash with all desired display languages
3666: #
3667:
3668: sub display_languages {
3669: my %languages=();
1.695 raeburn 3670: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3671: $languages{$lang}=1;
1.97 www 3672: }
3673: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3674: if ($env{'form.displaylanguage'}) {
1.356 albertel 3675: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3676: $languages{$lang}=1;
1.97 www 3677: }
3678: }
3679: return %languages;
1.14 harris41 3680: }
3681:
1.582 albertel 3682: sub languages {
3683: my ($possible_langs) = @_;
1.695 raeburn 3684: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3685: if (!ref($possible_langs)) {
3686: if( wantarray ) {
3687: return @preferred_langs;
3688: } else {
3689: return $preferred_langs[0];
3690: }
3691: }
3692: my %possibilities = map { $_ => 1 } (@$possible_langs);
3693: my @preferred_possibilities;
3694: foreach my $preferred_lang (@preferred_langs) {
3695: if (exists($possibilities{$preferred_lang})) {
3696: push(@preferred_possibilities, $preferred_lang);
3697: }
3698: }
3699: if( wantarray ) {
3700: return @preferred_possibilities;
3701: }
3702: return $preferred_possibilities[0];
3703: }
3704:
1.742 raeburn 3705: sub user_lang {
3706: my ($touname,$toudom,$fromcid) = @_;
3707: my @userlangs;
3708: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3709: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3710: $env{'course.'.$fromcid.'.languages'}));
3711: } else {
3712: my %langhash = &getlangs($touname,$toudom);
3713: if ($langhash{'languages'} ne '') {
3714: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3715: } else {
3716: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3717: if ($domdefs{'lang_def'} ne '') {
3718: @userlangs = ($domdefs{'lang_def'});
3719: }
3720: }
3721: }
3722: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3723: my $user_lh = Apache::localize->get_handle(@languages);
3724: return $user_lh;
3725: }
3726:
3727:
1.112 bowersj2 3728: ###############################################################
3729: ## Student Answer Attempts ##
3730: ###############################################################
3731:
3732: =pod
3733:
3734: =head1 Alternate Problem Views
3735:
3736: =over 4
3737:
1.648 raeburn 3738: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3739: $getattempt, $regexp, $gradesub)
3740:
3741: Return string with previous attempt on problem. Arguments:
3742:
3743: =over 4
3744:
3745: =item * $symb: Problem, including path
3746:
3747: =item * $username: username of the desired student
3748:
3749: =item * $domain: domain of the desired student
1.14 harris41 3750:
1.112 bowersj2 3751: =item * $course: Course ID
1.14 harris41 3752:
1.112 bowersj2 3753: =item * $getattempt: Leave blank for all attempts, otherwise put
3754: something
1.14 harris41 3755:
1.112 bowersj2 3756: =item * $regexp: if string matches this regexp, the string will be
3757: sent to $gradesub
1.14 harris41 3758:
1.112 bowersj2 3759: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3760:
1.112 bowersj2 3761: =back
1.14 harris41 3762:
1.112 bowersj2 3763: The output string is a table containing all desired attempts, if any.
1.16 harris41 3764:
1.112 bowersj2 3765: =cut
1.1 albertel 3766:
3767: sub get_previous_attempt {
1.43 ng 3768: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3769: my $prevattempts='';
1.43 ng 3770: no strict 'refs';
1.1 albertel 3771: if ($symb) {
1.3 albertel 3772: my (%returnhash)=
3773: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3774: if ($returnhash{'version'}) {
3775: my %lasthash=();
3776: my $version;
3777: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3778: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3779: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3780: }
1.1 albertel 3781: }
1.596 albertel 3782: $prevattempts=&start_data_table().&start_data_table_header_row();
3783: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3784: my (%typeparts,%lasthidden);
1.945 raeburn 3785: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3786: foreach my $key (sort(keys(%lasthash))) {
3787: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3788: if ($#parts > 0) {
1.31 albertel 3789: my $data=$parts[-1];
1.989 raeburn 3790: next if ($data eq 'foilorder');
1.31 albertel 3791: pop(@parts);
1.1010 www 3792: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3793: if ($data eq 'type') {
3794: unless ($showsurv) {
3795: my $id = join(',',@parts);
3796: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3797: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3798: $lasthidden{$ign.'.'.$id} = 1;
3799: }
1.945 raeburn 3800: }
1.1010 www 3801: }
1.31 albertel 3802: } else {
1.41 ng 3803: if ($#parts == 0) {
3804: $prevattempts.='<th>'.$parts[0].'</th>';
3805: } else {
3806: $prevattempts.='<th>'.$ign.'</th>';
3807: }
1.31 albertel 3808: }
1.16 harris41 3809: }
1.596 albertel 3810: $prevattempts.=&end_data_table_header_row();
1.40 ng 3811: if ($getattempt eq '') {
3812: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3813: my @hidden;
3814: if (%typeparts) {
3815: foreach my $id (keys(%typeparts)) {
3816: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3817: push(@hidden,$id);
3818: }
3819: }
3820: }
3821: $prevattempts.=&start_data_table_row().
3822: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3823: if (@hidden) {
3824: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3825: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3826: my $hide;
3827: foreach my $id (@hidden) {
3828: if ($key =~ /^\Q$id\E/) {
3829: $hide = 1;
3830: last;
3831: }
3832: }
3833: if ($hide) {
3834: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3835: if (($data eq 'award') || ($data eq 'awarddetail')) {
3836: my $value = &format_previous_attempt_value($key,
3837: $returnhash{$version.':'.$key});
3838: $prevattempts.='<td>'.$value.' </td>';
3839: } else {
3840: $prevattempts.='<td> </td>';
3841: }
3842: } else {
3843: if ($key =~ /\./) {
3844: my $value = &format_previous_attempt_value($key,
3845: $returnhash{$version.':'.$key});
3846: $prevattempts.='<td>'.$value.' </td>';
3847: } else {
3848: $prevattempts.='<td> </td>';
3849: }
3850: }
3851: }
3852: } else {
3853: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3854: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3855: my $value = &format_previous_attempt_value($key,
3856: $returnhash{$version.':'.$key});
3857: $prevattempts.='<td>'.$value.' </td>';
3858: }
3859: }
3860: $prevattempts.=&end_data_table_row();
1.40 ng 3861: }
1.1 albertel 3862: }
1.945 raeburn 3863: my @currhidden = keys(%lasthidden);
1.596 albertel 3864: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3865: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3866: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3867: if (%typeparts) {
3868: my $hidden;
3869: foreach my $id (@currhidden) {
3870: if ($key =~ /^\Q$id\E/) {
3871: $hidden = 1;
3872: last;
3873: }
3874: }
3875: if ($hidden) {
3876: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3877: if (($data eq 'award') || ($data eq 'awarddetail')) {
3878: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3879: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3880: $value = &$gradesub($value);
3881: }
3882: $prevattempts.='<td>'.$value.' </td>';
3883: } else {
3884: $prevattempts.='<td> </td>';
3885: }
3886: } else {
3887: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3888: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3889: $value = &$gradesub($value);
3890: }
3891: $prevattempts.='<td>'.$value.' </td>';
3892: }
3893: } else {
3894: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3895: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3896: $value = &$gradesub($value);
3897: }
3898: $prevattempts.='<td>'.$value.' </td>';
3899: }
1.16 harris41 3900: }
1.596 albertel 3901: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3902: } else {
1.596 albertel 3903: $prevattempts=
3904: &start_data_table().&start_data_table_row().
3905: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3906: &end_data_table_row().&end_data_table();
1.1 albertel 3907: }
3908: } else {
1.596 albertel 3909: $prevattempts=
3910: &start_data_table().&start_data_table_row().
3911: '<td>'.&mt('No data.').'</td>'.
3912: &end_data_table_row().&end_data_table();
1.1 albertel 3913: }
1.10 albertel 3914: }
3915:
1.581 albertel 3916: sub format_previous_attempt_value {
3917: my ($key,$value) = @_;
1.1011 www 3918: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3919: $value = &Apache::lonlocal::locallocaltime($value);
3920: } elsif (ref($value) eq 'ARRAY') {
3921: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3922: } elsif ($key =~ /answerstring$/) {
3923: my %answers = &Apache::lonnet::str2hash($value);
3924: my @anskeys = sort(keys(%answers));
3925: if (@anskeys == 1) {
3926: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3927: if ($answer =~ m{\0}) {
3928: $answer =~ s{\0}{,}g;
1.988 raeburn 3929: }
3930: my $tag_internal_answer_name = 'INTERNAL';
3931: if ($anskeys[0] eq $tag_internal_answer_name) {
3932: $value = $answer;
3933: } else {
3934: $value = $anskeys[0].'='.$answer;
3935: }
3936: } else {
3937: foreach my $ans (@anskeys) {
3938: my $answer = $answers{$ans};
1.1001 raeburn 3939: if ($answer =~ m{\0}) {
3940: $answer =~ s{\0}{,}g;
1.988 raeburn 3941: }
3942: $value .= $ans.'='.$answer.'<br />';;
3943: }
3944: }
1.581 albertel 3945: } else {
3946: $value = &unescape($value);
3947: }
3948: return $value;
3949: }
3950:
3951:
1.107 albertel 3952: sub relative_to_absolute {
3953: my ($url,$output)=@_;
3954: my $parser=HTML::TokeParser->new(\$output);
3955: my $token;
3956: my $thisdir=$url;
3957: my @rlinks=();
3958: while ($token=$parser->get_token) {
3959: if ($token->[0] eq 'S') {
3960: if ($token->[1] eq 'a') {
3961: if ($token->[2]->{'href'}) {
3962: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3963: }
3964: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3965: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3966: } elsif ($token->[1] eq 'base') {
3967: $thisdir=$token->[2]->{'href'};
3968: }
3969: }
3970: }
3971: $thisdir=~s-/[^/]*$--;
1.356 albertel 3972: foreach my $link (@rlinks) {
1.726 raeburn 3973: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3974: ($link=~/^\//) ||
3975: ($link=~/^javascript:/i) ||
3976: ($link=~/^mailto:/i) ||
3977: ($link=~/^\#/)) {
3978: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3979: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3980: }
3981: }
3982: # -------------------------------------------------- Deal with Applet codebases
3983: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3984: return $output;
3985: }
3986:
1.112 bowersj2 3987: =pod
3988:
1.648 raeburn 3989: =item * &get_student_view()
1.112 bowersj2 3990:
3991: show a snapshot of what student was looking at
3992:
3993: =cut
3994:
1.10 albertel 3995: sub get_student_view {
1.186 albertel 3996: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3997: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3998: my (%form);
1.10 albertel 3999: my @elements=('symb','courseid','domain','username');
4000: foreach my $element (@elements) {
1.186 albertel 4001: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4002: }
1.186 albertel 4003: if (defined($moreenv)) {
4004: %form=(%form,%{$moreenv});
4005: }
1.236 albertel 4006: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4007: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4008: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4009: $userview=~s/\<body[^\>]*\>//gi;
4010: $userview=~s/\<\/body\>//gi;
4011: $userview=~s/\<html\>//gi;
4012: $userview=~s/\<\/html\>//gi;
4013: $userview=~s/\<head\>//gi;
4014: $userview=~s/\<\/head\>//gi;
4015: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4016: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4017: if (wantarray) {
4018: return ($userview,$response);
4019: } else {
4020: return $userview;
4021: }
4022: }
4023:
4024: sub get_student_view_with_retries {
4025: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4026:
4027: my $ok = 0; # True if we got a good response.
4028: my $content;
4029: my $response;
4030:
4031: # Try to get the student_view done. within the retries count:
4032:
4033: do {
4034: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4035: $ok = $response->is_success;
4036: if (!$ok) {
4037: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4038: }
4039: $retries--;
4040: } while (!$ok && ($retries > 0));
4041:
4042: if (!$ok) {
4043: $content = ''; # On error return an empty content.
4044: }
1.651 www 4045: if (wantarray) {
4046: return ($content, $response);
4047: } else {
4048: return $content;
4049: }
1.11 albertel 4050: }
4051:
1.112 bowersj2 4052: =pod
4053:
1.648 raeburn 4054: =item * &get_student_answers()
1.112 bowersj2 4055:
4056: show a snapshot of how student was answering problem
4057:
4058: =cut
4059:
1.11 albertel 4060: sub get_student_answers {
1.100 sakharuk 4061: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4062: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4063: my (%moreenv);
1.11 albertel 4064: my @elements=('symb','courseid','domain','username');
4065: foreach my $element (@elements) {
1.186 albertel 4066: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4067: }
1.186 albertel 4068: $moreenv{'grade_target'}='answer';
4069: %moreenv=(%form,%moreenv);
1.497 raeburn 4070: $feedurl = &Apache::lonnet::clutter($feedurl);
4071: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4072: return $userview;
1.1 albertel 4073: }
1.116 albertel 4074:
4075: =pod
4076:
4077: =item * &submlink()
4078:
1.242 albertel 4079: Inputs: $text $uname $udom $symb $target
1.116 albertel 4080:
4081: Returns: A link to grades.pm such as to see the SUBM view of a student
4082:
4083: =cut
4084:
4085: ###############################################
4086: sub submlink {
1.242 albertel 4087: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4088: if (!($uname && $udom)) {
4089: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4090: &Apache::lonnet::whichuser($symb);
1.116 albertel 4091: if (!$symb) { $symb=$cursymb; }
4092: }
1.254 matthew 4093: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4094: $symb=&escape($symb);
1.960 bisitz 4095: if ($target) { $target=" target=\"$target\""; }
4096: return
4097: '<a href="/adm/grades?command=submission'.
4098: '&symb='.$symb.
4099: '&student='.$uname.
4100: '&userdom='.$udom.'"'.
4101: $target.'>'.$text.'</a>';
1.242 albertel 4102: }
4103: ##############################################
4104:
4105: =pod
4106:
4107: =item * &pgrdlink()
4108:
4109: Inputs: $text $uname $udom $symb $target
4110:
4111: Returns: A link to grades.pm such as to see the PGRD view of a student
4112:
4113: =cut
4114:
4115: ###############################################
4116: sub pgrdlink {
4117: my $link=&submlink(@_);
4118: $link=~s/(&command=submission)/$1&showgrading=yes/;
4119: return $link;
4120: }
4121: ##############################################
4122:
4123: =pod
4124:
4125: =item * &pprmlink()
4126:
4127: Inputs: $text $uname $udom $symb $target
4128:
4129: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4130: student and a specific resource
1.242 albertel 4131:
4132: =cut
4133:
4134: ###############################################
4135: sub pprmlink {
4136: my ($text,$uname,$udom,$symb,$target)=@_;
4137: if (!($uname && $udom)) {
4138: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4139: &Apache::lonnet::whichuser($symb);
1.242 albertel 4140: if (!$symb) { $symb=$cursymb; }
4141: }
1.254 matthew 4142: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4143: $symb=&escape($symb);
1.242 albertel 4144: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4145: return '<a href="/adm/parmset?command=set&'.
4146: 'symb='.$symb.'&uname='.$uname.
4147: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4148: }
4149: ##############################################
1.37 matthew 4150:
1.112 bowersj2 4151: =pod
4152:
4153: =back
4154:
4155: =cut
4156:
1.37 matthew 4157: ###############################################
1.51 www 4158:
4159:
4160: sub timehash {
1.687 raeburn 4161: my ($thistime) = @_;
4162: my $timezone = &Apache::lonlocal::gettimezone();
4163: my $dt = DateTime->from_epoch(epoch => $thistime)
4164: ->set_time_zone($timezone);
4165: my $wday = $dt->day_of_week();
4166: if ($wday == 7) { $wday = 0; }
4167: return ( 'second' => $dt->second(),
4168: 'minute' => $dt->minute(),
4169: 'hour' => $dt->hour(),
4170: 'day' => $dt->day_of_month(),
4171: 'month' => $dt->month(),
4172: 'year' => $dt->year(),
4173: 'weekday' => $wday,
4174: 'dayyear' => $dt->day_of_year(),
4175: 'dlsav' => $dt->is_dst() );
1.51 www 4176: }
4177:
1.370 www 4178: sub utc_string {
4179: my ($date)=@_;
1.371 www 4180: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4181: }
4182:
1.51 www 4183: sub maketime {
4184: my %th=@_;
1.687 raeburn 4185: my ($epoch_time,$timezone,$dt);
4186: $timezone = &Apache::lonlocal::gettimezone();
4187: eval {
4188: $dt = DateTime->new( year => $th{'year'},
4189: month => $th{'month'},
4190: day => $th{'day'},
4191: hour => $th{'hour'},
4192: minute => $th{'minute'},
4193: second => $th{'second'},
4194: time_zone => $timezone,
4195: );
4196: };
4197: if (!$@) {
4198: $epoch_time = $dt->epoch;
4199: if ($epoch_time) {
4200: return $epoch_time;
4201: }
4202: }
1.51 www 4203: return POSIX::mktime(
4204: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4205: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4206: }
4207:
4208: #########################################
1.51 www 4209:
4210: sub findallcourses {
1.482 raeburn 4211: my ($roles,$uname,$udom) = @_;
1.355 albertel 4212: my %roles;
4213: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4214: my %courses;
1.51 www 4215: my $now=time;
1.482 raeburn 4216: if (!defined($uname)) {
4217: $uname = $env{'user.name'};
4218: }
4219: if (!defined($udom)) {
4220: $udom = $env{'user.domain'};
4221: }
4222: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4223: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4224: if (!%roles) {
4225: %roles = (
4226: cc => 1,
1.907 raeburn 4227: co => 1,
1.482 raeburn 4228: in => 1,
4229: ep => 1,
4230: ta => 1,
4231: cr => 1,
4232: st => 1,
4233: );
4234: }
4235: foreach my $entry (keys(%roleshash)) {
4236: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4237: if ($trole =~ /^cr/) {
4238: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4239: } else {
4240: next if (!exists($roles{$trole}));
4241: }
4242: if ($tend) {
4243: next if ($tend < $now);
4244: }
4245: if ($tstart) {
4246: next if ($tstart > $now);
4247: }
1.1058 raeburn 4248: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4249: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4250: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4251: if ($secpart eq '') {
4252: ($cnum,$role) = split(/_/,$cnumpart);
4253: $sec = 'none';
1.1058 raeburn 4254: $value .= $cnum.'/';
1.482 raeburn 4255: } else {
4256: $cnum = $cnumpart;
4257: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4258: $value .= $cnum.'/'.$sec;
4259: }
4260: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4261: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4262: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4263: }
4264: } else {
4265: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4266: }
1.482 raeburn 4267: }
4268: } else {
4269: foreach my $key (keys(%env)) {
1.483 albertel 4270: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4271: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4272: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4273: next if ($role eq 'ca' || $role eq 'aa');
4274: next if (%roles && !exists($roles{$role}));
4275: my ($starttime,$endtime)=split(/\./,$env{$key});
4276: my $active=1;
4277: if ($starttime) {
4278: if ($now<$starttime) { $active=0; }
4279: }
4280: if ($endtime) {
4281: if ($now>$endtime) { $active=0; }
4282: }
4283: if ($active) {
1.1058 raeburn 4284: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4285: if ($sec eq '') {
4286: $sec = 'none';
1.1058 raeburn 4287: } else {
4288: $value .= $sec;
4289: }
4290: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4291: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4292: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4293: }
4294: } else {
4295: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4296: }
1.474 raeburn 4297: }
4298: }
1.51 www 4299: }
4300: }
1.474 raeburn 4301: return %courses;
1.51 www 4302: }
1.37 matthew 4303:
1.54 www 4304: ###############################################
1.474 raeburn 4305:
4306: sub blockcheck {
1.1062 raeburn 4307: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4308:
4309: if (!defined($udom)) {
4310: $udom = $env{'user.domain'};
4311: }
4312: if (!defined($uname)) {
4313: $uname = $env{'user.name'};
4314: }
4315:
4316: # If uname and udom are for a course, check for blocks in the course.
4317:
4318: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4319: my ($startblock,$endblock,$triggerblock) =
4320: &get_blocks($setters,$activity,$udom,$uname,$url);
4321: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4322: }
1.474 raeburn 4323:
1.502 raeburn 4324: my $startblock = 0;
4325: my $endblock = 0;
1.1062 raeburn 4326: my $triggerblock = '';
1.482 raeburn 4327: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4328:
1.490 raeburn 4329: # If uname is for a user, and activity is course-specific, i.e.,
4330: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4331:
1.490 raeburn 4332: if (($activity eq 'boards' || $activity eq 'chat' ||
4333: $activity eq 'groups') && ($env{'request.course.id'})) {
4334: foreach my $key (keys(%live_courses)) {
4335: if ($key ne $env{'request.course.id'}) {
4336: delete($live_courses{$key});
4337: }
4338: }
4339: }
4340:
4341: my $otheruser = 0;
4342: my %own_courses;
4343: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4344: # Resource belongs to user other than current user.
4345: $otheruser = 1;
4346: # Gather courses for current user
4347: %own_courses =
4348: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4349: }
4350:
4351: # Gather active course roles - course coordinator, instructor,
4352: # exam proctor, ta, student, or custom role.
1.474 raeburn 4353:
4354: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4355: my ($cdom,$cnum);
4356: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4357: $cdom = $env{'course.'.$course.'.domain'};
4358: $cnum = $env{'course.'.$course.'.num'};
4359: } else {
1.490 raeburn 4360: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4361: }
4362: my $no_ownblock = 0;
4363: my $no_userblock = 0;
1.533 raeburn 4364: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4365: # Check if current user has 'evb' priv for this
4366: if (defined($own_courses{$course})) {
4367: foreach my $sec (keys(%{$own_courses{$course}})) {
4368: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4369: if ($sec ne 'none') {
4370: $checkrole .= '/'.$sec;
4371: }
4372: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4373: $no_ownblock = 1;
4374: last;
4375: }
4376: }
4377: }
4378: # if they have 'evb' priv and are currently not playing student
4379: next if (($no_ownblock) &&
4380: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4381: }
1.474 raeburn 4382: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4383: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4384: if ($sec ne 'none') {
1.482 raeburn 4385: $checkrole .= '/'.$sec;
1.474 raeburn 4386: }
1.490 raeburn 4387: if ($otheruser) {
4388: # Resource belongs to user other than current user.
4389: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4390: my (%allroles,%userroles);
4391: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4392: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4393: my ($trole,$tdom,$tnum,$tsec);
4394: if ($entry =~ /^cr/) {
4395: ($trole,$tdom,$tnum,$tsec) =
4396: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4397: } else {
4398: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4399: }
4400: my ($spec,$area,$trest);
4401: $area = '/'.$tdom.'/'.$tnum;
4402: $trest = $tnum;
4403: if ($tsec ne '') {
4404: $area .= '/'.$tsec;
4405: $trest .= '/'.$tsec;
4406: }
4407: $spec = $trole.'.'.$area;
4408: if ($trole =~ /^cr/) {
4409: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4410: $tdom,$spec,$trest,$area);
4411: } else {
4412: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4413: $tdom,$spec,$trest,$area);
4414: }
4415: }
4416: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4417: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4418: if ($1) {
4419: $no_userblock = 1;
4420: last;
4421: }
1.486 raeburn 4422: }
4423: }
1.490 raeburn 4424: } else {
4425: # Resource belongs to current user
4426: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4427: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4428: $no_ownblock = 1;
4429: last;
4430: }
1.474 raeburn 4431: }
4432: }
4433: # if they have the evb priv and are currently not playing student
1.482 raeburn 4434: next if (($no_ownblock) &&
1.491 albertel 4435: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4436: next if ($no_userblock);
1.474 raeburn 4437:
1.866 kalberla 4438: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4439: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4440:
1.1062 raeburn 4441: my ($start,$end,$trigger) =
4442: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4443: if (($start != 0) &&
4444: (($startblock == 0) || ($startblock > $start))) {
4445: $startblock = $start;
1.1062 raeburn 4446: if ($trigger ne '') {
4447: $triggerblock = $trigger;
4448: }
1.502 raeburn 4449: }
4450: if (($end != 0) &&
4451: (($endblock == 0) || ($endblock < $end))) {
4452: $endblock = $end;
1.1062 raeburn 4453: if ($trigger ne '') {
4454: $triggerblock = $trigger;
4455: }
1.502 raeburn 4456: }
1.490 raeburn 4457: }
1.1062 raeburn 4458: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4459: }
4460:
4461: sub get_blocks {
1.1062 raeburn 4462: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4463: my $startblock = 0;
4464: my $endblock = 0;
1.1062 raeburn 4465: my $triggerblock = '';
1.490 raeburn 4466: my $course = $cdom.'_'.$cnum;
4467: $setters->{$course} = {};
4468: $setters->{$course}{'staff'} = [];
4469: $setters->{$course}{'times'} = [];
1.1062 raeburn 4470: $setters->{$course}{'triggers'} = [];
4471: my (@blockers,%triggered);
4472: my $now = time;
4473: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4474: if ($activity eq 'docs') {
4475: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4476: foreach my $block (@blockers) {
4477: if ($block =~ /^firstaccess____(.+)$/) {
4478: my $item = $1;
4479: my $type = 'map';
4480: my $timersymb = $item;
4481: if ($item eq 'course') {
4482: $type = 'course';
4483: } elsif ($item =~ /___\d+___/) {
4484: $type = 'resource';
4485: } else {
4486: $timersymb = &Apache::lonnet::symbread($item);
4487: }
4488: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4489: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4490: $triggered{$block} = {
4491: start => $start,
4492: end => $end,
4493: type => $type,
4494: };
4495: }
4496: }
4497: } else {
4498: foreach my $block (keys(%commblocks)) {
4499: if ($block =~ m/^(\d+)____(\d+)$/) {
4500: my ($start,$end) = ($1,$2);
4501: if ($start <= time && $end >= time) {
4502: if (ref($commblocks{$block}) eq 'HASH') {
4503: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4504: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4505: unless(grep(/^\Q$block\E$/,@blockers)) {
4506: push(@blockers,$block);
4507: }
4508: }
4509: }
4510: }
4511: }
4512: } elsif ($block =~ /^firstaccess____(.+)$/) {
4513: my $item = $1;
4514: my $timersymb = $item;
4515: my $type = 'map';
4516: if ($item eq 'course') {
4517: $type = 'course';
4518: } elsif ($item =~ /___\d+___/) {
4519: $type = 'resource';
4520: } else {
4521: $timersymb = &Apache::lonnet::symbread($item);
4522: }
4523: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4524: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4525: if ($start && $end) {
4526: if (($start <= time) && ($end >= time)) {
4527: unless (grep(/^\Q$block\E$/,@blockers)) {
4528: push(@blockers,$block);
4529: $triggered{$block} = {
4530: start => $start,
4531: end => $end,
4532: type => $type,
4533: };
4534: }
4535: }
1.490 raeburn 4536: }
1.1062 raeburn 4537: }
4538: }
4539: }
4540: foreach my $blocker (@blockers) {
4541: my ($staff_name,$staff_dom,$title,$blocks) =
4542: &parse_block_record($commblocks{$blocker});
4543: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4544: my ($start,$end,$triggertype);
4545: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4546: ($start,$end) = ($1,$2);
4547: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4548: $start = $triggered{$blocker}{'start'};
4549: $end = $triggered{$blocker}{'end'};
4550: $triggertype = $triggered{$blocker}{'type'};
4551: }
4552: if ($start) {
4553: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4554: if ($triggertype) {
4555: push(@{$$setters{$course}{'triggers'}},$triggertype);
4556: } else {
4557: push(@{$$setters{$course}{'triggers'}},0);
4558: }
4559: if ( ($startblock == 0) || ($startblock > $start) ) {
4560: $startblock = $start;
4561: if ($triggertype) {
4562: $triggerblock = $blocker;
1.474 raeburn 4563: }
4564: }
1.1062 raeburn 4565: if ( ($endblock == 0) || ($endblock < $end) ) {
4566: $endblock = $end;
4567: if ($triggertype) {
4568: $triggerblock = $blocker;
4569: }
4570: }
1.474 raeburn 4571: }
4572: }
1.1062 raeburn 4573: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4574: }
4575:
4576: sub parse_block_record {
4577: my ($record) = @_;
4578: my ($setuname,$setudom,$title,$blocks);
4579: if (ref($record) eq 'HASH') {
4580: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4581: $title = &unescape($record->{'event'});
4582: $blocks = $record->{'blocks'};
4583: } else {
4584: my @data = split(/:/,$record,3);
4585: if (scalar(@data) eq 2) {
4586: $title = $data[1];
4587: ($setuname,$setudom) = split(/@/,$data[0]);
4588: } else {
4589: ($setuname,$setudom,$title) = @data;
4590: }
4591: $blocks = { 'com' => 'on' };
4592: }
4593: return ($setuname,$setudom,$title,$blocks);
4594: }
4595:
1.854 kalberla 4596: sub blocking_status {
1.1062 raeburn 4597: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4598: my %setters;
1.890 droeschl 4599:
1.1061 raeburn 4600: # check for active blocking
1.1062 raeburn 4601: my ($startblock,$endblock,$triggerblock) =
4602: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4603: my $blocked = 0;
4604: if ($startblock && $endblock) {
4605: $blocked = 1;
4606: }
1.890 droeschl 4607:
1.1061 raeburn 4608: # caller just wants to know whether a block is active
4609: if (!wantarray) { return $blocked; }
4610:
4611: # build a link to a popup window containing the details
4612: my $querystring = "?activity=$activity";
4613: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4614: if ($activity eq 'port') {
4615: $querystring .= "&udom=$udom" if $udom;
4616: $querystring .= "&uname=$uname" if $uname;
4617: } elsif ($activity eq 'docs') {
4618: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4619: }
1.1061 raeburn 4620:
4621: my $output .= <<'END_MYBLOCK';
4622: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4623: var options = "width=" + w + ",height=" + h + ",";
4624: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4625: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4626: var newWin = window.open(url, wdwName, options);
4627: newWin.focus();
4628: }
1.890 droeschl 4629: END_MYBLOCK
1.854 kalberla 4630:
1.1061 raeburn 4631: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4632:
1.1061 raeburn 4633: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4634: my $text = &mt('Communication Blocked');
4635: if ($activity eq 'docs') {
4636: $text = &mt('Content Access Blocked');
1.1063 raeburn 4637: } elsif ($activity eq 'printout') {
4638: $text = &mt('Printing Blocked');
1.1062 raeburn 4639: }
1.1061 raeburn 4640: $output .= <<"END_BLOCK";
1.867 kalberla 4641: <div class='LC_comblock'>
1.869 kalberla 4642: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4643: title='$text'>
4644: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4645: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4646: title='$text'>$text</a>
1.867 kalberla 4647: </div>
4648:
4649: END_BLOCK
1.474 raeburn 4650:
1.1061 raeburn 4651: return ($blocked, $output);
1.854 kalberla 4652: }
1.490 raeburn 4653:
1.60 matthew 4654: ###############################################
4655:
1.682 raeburn 4656: sub check_ip_acc {
4657: my ($acc)=@_;
4658: &Apache::lonxml::debug("acc is $acc");
4659: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4660: return 1;
4661: }
4662: my $allowed=0;
4663: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4664:
4665: my $name;
4666: foreach my $pattern (split(',',$acc)) {
4667: $pattern =~ s/^\s*//;
4668: $pattern =~ s/\s*$//;
4669: if ($pattern =~ /\*$/) {
4670: #35.8.*
4671: $pattern=~s/\*//;
4672: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4673: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4674: #35.8.3.[34-56]
4675: my $low=$2;
4676: my $high=$3;
4677: $pattern=$1;
4678: if ($ip =~ /^\Q$pattern\E/) {
4679: my $last=(split(/\./,$ip))[3];
4680: if ($last <=$high && $last >=$low) { $allowed=1; }
4681: }
4682: } elsif ($pattern =~ /^\*/) {
4683: #*.msu.edu
4684: $pattern=~s/\*//;
4685: if (!defined($name)) {
4686: use Socket;
4687: my $netaddr=inet_aton($ip);
4688: ($name)=gethostbyaddr($netaddr,AF_INET);
4689: }
4690: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4691: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4692: #127.0.0.1
4693: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4694: } else {
4695: #some.name.com
4696: if (!defined($name)) {
4697: use Socket;
4698: my $netaddr=inet_aton($ip);
4699: ($name)=gethostbyaddr($netaddr,AF_INET);
4700: }
4701: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4702: }
4703: if ($allowed) { last; }
4704: }
4705: return $allowed;
4706: }
4707:
4708: ###############################################
4709:
1.60 matthew 4710: =pod
4711:
1.112 bowersj2 4712: =head1 Domain Template Functions
4713:
4714: =over 4
4715:
4716: =item * &determinedomain()
1.60 matthew 4717:
4718: Inputs: $domain (usually will be undef)
4719:
1.63 www 4720: Returns: Determines which domain should be used for designs
1.60 matthew 4721:
4722: =cut
1.54 www 4723:
1.60 matthew 4724: ###############################################
1.63 www 4725: sub determinedomain {
4726: my $domain=shift;
1.531 albertel 4727: if (! $domain) {
1.60 matthew 4728: # Determine domain if we have not been given one
1.893 raeburn 4729: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4730: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4731: if ($env{'request.role.domain'}) {
4732: $domain=$env{'request.role.domain'};
1.60 matthew 4733: }
4734: }
1.63 www 4735: return $domain;
4736: }
4737: ###############################################
1.517 raeburn 4738:
1.518 albertel 4739: sub devalidate_domconfig_cache {
4740: my ($udom)=@_;
4741: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4742: }
4743:
4744: # ---------------------- Get domain configuration for a domain
4745: sub get_domainconf {
4746: my ($udom) = @_;
4747: my $cachetime=1800;
4748: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4749: if (defined($cached)) { return %{$result}; }
4750:
4751: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4752: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4753: my (%designhash,%legacy);
1.518 albertel 4754: if (keys(%domconfig) > 0) {
4755: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4756: if (keys(%{$domconfig{'login'}})) {
4757: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4758: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4759: if ($key eq 'loginvia') {
4760: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4761: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4762: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4763: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4764: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4765: $designhash{$udom.'.login.loginvia'} = $server;
4766: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4767:
4768: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4769: } else {
1.1013 raeburn 4770: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4771: }
4772: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4773: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4774: }
1.946 raeburn 4775: }
4776: }
4777: }
4778: }
4779: } else {
4780: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4781: $designhash{$udom.'.login.'.$key.'_'.$img} =
4782: $domconfig{'login'}{$key}{$img};
4783: }
1.699 raeburn 4784: }
4785: } else {
4786: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4787: }
1.632 raeburn 4788: }
4789: } else {
4790: $legacy{'login'} = 1;
1.518 albertel 4791: }
1.632 raeburn 4792: } else {
4793: $legacy{'login'} = 1;
1.518 albertel 4794: }
4795: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4796: if (keys(%{$domconfig{'rolecolors'}})) {
4797: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4798: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4799: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4800: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4801: }
1.518 albertel 4802: }
4803: }
1.632 raeburn 4804: } else {
4805: $legacy{'rolecolors'} = 1;
1.518 albertel 4806: }
1.632 raeburn 4807: } else {
4808: $legacy{'rolecolors'} = 1;
1.518 albertel 4809: }
1.948 raeburn 4810: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4811: if ($domconfig{'autoenroll'}{'co-owners'}) {
4812: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4813: }
4814: }
1.632 raeburn 4815: if (keys(%legacy) > 0) {
4816: my %legacyhash = &get_legacy_domconf($udom);
4817: foreach my $item (keys(%legacyhash)) {
4818: if ($item =~ /^\Q$udom\E\.login/) {
4819: if ($legacy{'login'}) {
4820: $designhash{$item} = $legacyhash{$item};
4821: }
4822: } else {
4823: if ($legacy{'rolecolors'}) {
4824: $designhash{$item} = $legacyhash{$item};
4825: }
1.518 albertel 4826: }
4827: }
4828: }
1.632 raeburn 4829: } else {
4830: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4831: }
4832: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4833: $cachetime);
4834: return %designhash;
4835: }
4836:
1.632 raeburn 4837: sub get_legacy_domconf {
4838: my ($udom) = @_;
4839: my %legacyhash;
4840: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4841: my $designfile = $designdir.'/'.$udom.'.tab';
4842: if (-e $designfile) {
4843: if ( open (my $fh,"<$designfile") ) {
4844: while (my $line = <$fh>) {
4845: next if ($line =~ /^\#/);
4846: chomp($line);
4847: my ($key,$val)=(split(/\=/,$line));
4848: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4849: }
4850: close($fh);
4851: }
4852: }
1.1026 raeburn 4853: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4854: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4855: }
4856: return %legacyhash;
4857: }
4858:
1.63 www 4859: =pod
4860:
1.112 bowersj2 4861: =item * &domainlogo()
1.63 www 4862:
4863: Inputs: $domain (usually will be undef)
4864:
4865: Returns: A link to a domain logo, if the domain logo exists.
4866: If the domain logo does not exist, a description of the domain.
4867:
4868: =cut
1.112 bowersj2 4869:
1.63 www 4870: ###############################################
4871: sub domainlogo {
1.517 raeburn 4872: my $domain = &determinedomain(shift);
1.518 albertel 4873: my %designhash = &get_domainconf($domain);
1.517 raeburn 4874: # See if there is a logo
4875: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4876: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4877: if ($imgsrc =~ m{^/(adm|res)/}) {
4878: if ($imgsrc =~ m{^/res/}) {
4879: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4880: &Apache::lonnet::repcopy($local_name);
4881: }
4882: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4883: }
4884: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4885: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4886: return &Apache::lonnet::domain($domain,'description');
1.59 www 4887: } else {
1.60 matthew 4888: return '';
1.59 www 4889: }
4890: }
1.63 www 4891: ##############################################
4892:
4893: =pod
4894:
1.112 bowersj2 4895: =item * &designparm()
1.63 www 4896:
4897: Inputs: $which parameter; $domain (usually will be undef)
4898:
4899: Returns: value of designparamter $which
4900:
4901: =cut
1.112 bowersj2 4902:
1.397 albertel 4903:
1.400 albertel 4904: ##############################################
1.397 albertel 4905: sub designparm {
4906: my ($which,$domain)=@_;
4907: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4908: return $env{'environment.color.'.$which};
1.96 www 4909: }
1.63 www 4910: $domain=&determinedomain($domain);
1.1016 raeburn 4911: my %domdesign;
4912: unless ($domain eq 'public') {
4913: %domdesign = &get_domainconf($domain);
4914: }
1.520 raeburn 4915: my $output;
1.517 raeburn 4916: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4917: $output = $domdesign{$domain.'.'.$which};
1.63 www 4918: } else {
1.520 raeburn 4919: $output = $defaultdesign{$which};
4920: }
4921: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4922: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4923: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4924: if ($output =~ m{^/res/}) {
4925: my $local_name = &Apache::lonnet::filelocation('',$output);
4926: &Apache::lonnet::repcopy($local_name);
4927: }
1.520 raeburn 4928: $output = &lonhttpdurl($output);
4929: }
1.63 www 4930: }
1.520 raeburn 4931: return $output;
1.63 www 4932: }
1.59 www 4933:
1.822 bisitz 4934: ##############################################
4935: =pod
4936:
1.832 bisitz 4937: =item * &authorspace()
4938:
1.1028 raeburn 4939: Inputs: $url (usually will be undef).
1.832 bisitz 4940:
1.1132 raeburn 4941: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4942: directory being viewed (or for which action is being taken).
4943: If $url is provided, and begins /priv/<domain>/<uname>
4944: the path will be that portion of the $context argument.
4945: Otherwise the path will be for the author space of the current
4946: user when the current role is author, or for that of the
4947: co-author/assistant co-author space when the current role
4948: is co-author or assistant co-author.
1.832 bisitz 4949:
4950: =cut
4951:
4952: sub authorspace {
1.1028 raeburn 4953: my ($url) = @_;
4954: if ($url ne '') {
4955: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4956: return $1;
4957: }
4958: }
1.832 bisitz 4959: my $caname = '';
1.1024 www 4960: my $cadom = '';
1.1028 raeburn 4961: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4962: ($cadom,$caname) =
1.832 bisitz 4963: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4964: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4965: $caname = $env{'user.name'};
1.1024 www 4966: $cadom = $env{'user.domain'};
1.832 bisitz 4967: }
1.1028 raeburn 4968: if (($caname ne '') && ($cadom ne '')) {
4969: return "/priv/$cadom/$caname/";
4970: }
4971: return;
1.832 bisitz 4972: }
4973:
4974: ##############################################
4975: =pod
4976:
1.822 bisitz 4977: =item * &head_subbox()
4978:
4979: Inputs: $content (contains HTML code with page functions, etc.)
4980:
4981: Returns: HTML div with $content
4982: To be included in page header
4983:
4984: =cut
4985:
4986: sub head_subbox {
4987: my ($content)=@_;
4988: my $output =
1.993 raeburn 4989: '<div class="LC_head_subbox">'
1.822 bisitz 4990: .$content
4991: .'</div>'
4992: }
4993:
4994: ##############################################
4995: =pod
4996:
4997: =item * &CSTR_pageheader()
4998:
1.1026 raeburn 4999: Input: (optional) filename from which breadcrumb trail is built.
5000: In most cases no input as needed, as $env{'request.filename'}
5001: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5002:
5003: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5004: To be included on Authoring Space pages
1.822 bisitz 5005:
5006: =cut
5007:
5008: sub CSTR_pageheader {
1.1026 raeburn 5009: my ($trailfile) = @_;
5010: if ($trailfile eq '') {
5011: $trailfile = $env{'request.filename'};
5012: }
5013:
5014: # this is for resources; directories have customtitle, and crumbs
5015: # and select recent are created in lonpubdir.pm
5016:
5017: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5018: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5019: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5020: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5021: $formaction =~ s{/+}{/}g;
1.822 bisitz 5022:
5023: my $parentpath = '';
5024: my $lastitem = '';
5025: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5026: $parentpath = $1;
5027: $lastitem = $2;
5028: } else {
5029: $lastitem = $thisdisfn;
5030: }
1.921 bisitz 5031:
5032: my $output =
1.822 bisitz 5033: '<div>'
5034: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5035: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5036: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5037: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5038: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5039:
5040: if ($lastitem) {
5041: $output .=
5042: '<span class="LC_filename">'
5043: .$lastitem
5044: .'</span>';
5045: }
5046: $output .=
5047: '<br />'
1.822 bisitz 5048: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5049: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5050: .'</form>'
5051: .&Apache::lonmenu::constspaceform()
5052: .'</div>';
1.921 bisitz 5053:
5054: return $output;
1.822 bisitz 5055: }
5056:
1.60 matthew 5057: ###############################################
5058: ###############################################
5059:
5060: =pod
5061:
1.112 bowersj2 5062: =back
5063:
1.549 albertel 5064: =head1 HTML Helpers
1.112 bowersj2 5065:
5066: =over 4
5067:
5068: =item * &bodytag()
1.60 matthew 5069:
5070: Returns a uniform header for LON-CAPA web pages.
5071:
5072: Inputs:
5073:
1.112 bowersj2 5074: =over 4
5075:
5076: =item * $title, A title to be displayed on the page.
5077:
5078: =item * $function, the current role (can be undef).
5079:
5080: =item * $addentries, extra parameters for the <body> tag.
5081:
5082: =item * $bodyonly, if defined, only return the <body> tag.
5083:
5084: =item * $domain, if defined, force a given domain.
5085:
5086: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5087: text interface only)
1.60 matthew 5088:
1.814 bisitz 5089: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5090: navigational links
1.317 albertel 5091:
1.338 albertel 5092: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5093:
1.460 albertel 5094: =item * $args, optional argument valid values are
5095: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5096: inherit_jsmath -> when creating popup window in a page,
5097: should it have jsmath forced on by the
5098: current page
1.460 albertel 5099:
1.1096 raeburn 5100: =item * $advtoolsref, optional argument, ref to an array containing
5101: inlineremote items to be added in "Functions" menu below
5102: breadcrumbs.
5103:
1.112 bowersj2 5104: =back
5105:
1.60 matthew 5106: Returns: A uniform header for LON-CAPA web pages.
5107: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5108: If $bodyonly is undef or zero, an html string containing a <body> tag and
5109: other decorations will be returned.
5110:
5111: =cut
5112:
1.54 www 5113: sub bodytag {
1.831 bisitz 5114: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5115: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5116:
1.954 raeburn 5117: my $public;
5118: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5119: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5120: $public = 1;
5121: }
1.460 albertel 5122: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5123:
1.183 matthew 5124: $function = &get_users_function() if (!$function);
1.339 albertel 5125: my $img = &designparm($function.'.img',$domain);
5126: my $font = &designparm($function.'.font',$domain);
5127: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5128:
1.803 bisitz 5129: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5130: 'bgcolor' => $pgbg,
1.339 albertel 5131: 'text' => $font,
5132: 'alink' => &designparm($function.'.alink',$domain),
5133: 'vlink' => &designparm($function.'.vlink',$domain),
5134: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5135: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5136:
1.63 www 5137: # role and realm
1.378 raeburn 5138: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5139: if ($role eq 'ca') {
1.479 albertel 5140: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5141: $realm = &plainname($rname,$rdom);
1.378 raeburn 5142: }
1.55 www 5143: # realm
1.258 albertel 5144: if ($env{'request.course.id'}) {
1.378 raeburn 5145: if ($env{'request.role'} !~ /^cr/) {
5146: $role = &Apache::lonnet::plaintext($role,&course_type());
5147: }
1.898 raeburn 5148: if ($env{'request.course.sec'}) {
5149: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5150: }
1.359 albertel 5151: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5152: } else {
5153: $role = &Apache::lonnet::plaintext($role);
1.54 www 5154: }
1.433 albertel 5155:
1.359 albertel 5156: if (!$realm) { $realm=' '; }
1.330 albertel 5157:
1.438 albertel 5158: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5159:
1.101 www 5160: # construct main body tag
1.359 albertel 5161: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5162: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5163:
1.1131 raeburn 5164: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5165:
1.1130 raeburn 5166: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5167: return $bodytag;
1.1130 raeburn 5168: }
1.359 albertel 5169:
1.954 raeburn 5170: if ($public) {
1.433 albertel 5171: undef($role);
5172: }
1.359 albertel 5173:
1.762 bisitz 5174: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5175: #
5176: # Extra info if you are the DC
5177: my $dc_info = '';
5178: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5179: $env{'course.'.$env{'request.course.id'}.
5180: '.domain'}.'/'})) {
5181: my $cid = $env{'request.course.id'};
1.917 raeburn 5182: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5183: $dc_info =~ s/\s+$//;
1.359 albertel 5184: }
5185:
1.898 raeburn 5186: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5187:
1.903 droeschl 5188: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5189:
5190: # if ($env{'request.state'} eq 'construct') {
5191: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5192: # }
5193:
1.1130 raeburn 5194: $bodytag .= Apache::lonhtmlcommon::scripttag(
5195: Apache::lonmenu::utilityfunctions(), 'start');
1.359 albertel 5196:
1.1130 raeburn 5197: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5198:
1.916 droeschl 5199: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5200: if ($dc_info) {
5201: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5202: }
1.1130 raeburn 5203: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5204: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5205: return $bodytag;
5206: }
1.894 droeschl 5207:
1.927 raeburn 5208: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5209: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5210: }
1.916 droeschl 5211:
1.1130 raeburn 5212: $bodytag .= $right;
1.852 droeschl 5213:
1.917 raeburn 5214: if ($dc_info) {
5215: $dc_info = &dc_courseid_toggle($dc_info);
5216: }
5217: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5218:
1.903 droeschl 5219: #don't show menus for public users
1.954 raeburn 5220: if (!$public){
1.903 droeschl 5221: $bodytag .= Apache::lonmenu::secondary_menu();
5222: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5223: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5224: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5225: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5226: $args->{'bread_crumbs'});
1.1096 raeburn 5227: } elsif ($forcereg) {
5228: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5229: $args->{'group'});
5230: } else {
5231: $bodytag .=
5232: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5233: $forcereg,$args->{'group'},
5234: $args->{'bread_crumbs'},
5235: $advtoolsref);
1.920 raeburn 5236: }
1.903 droeschl 5237: }else{
5238: # this is to seperate menu from content when there's no secondary
5239: # menu. Especially needed for public accessible ressources.
5240: $bodytag .= '<hr style="clear:both" />';
5241: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5242: }
1.903 droeschl 5243:
1.235 raeburn 5244: return $bodytag;
1.182 matthew 5245: }
5246:
1.917 raeburn 5247: sub dc_courseid_toggle {
5248: my ($dc_info) = @_;
1.980 raeburn 5249: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5250: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5251: &mt('(More ...)').'</a></span>'.
5252: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5253: }
5254:
1.330 albertel 5255: sub make_attr_string {
5256: my ($register,$attr_ref) = @_;
5257:
5258: if ($attr_ref && !ref($attr_ref)) {
5259: die("addentries Must be a hash ref ".
5260: join(':',caller(1))." ".
5261: join(':',caller(0))." ");
5262: }
5263:
5264: if ($register) {
1.339 albertel 5265: my ($on_load,$on_unload);
5266: foreach my $key (keys(%{$attr_ref})) {
5267: if (lc($key) eq 'onload') {
5268: $on_load.=$attr_ref->{$key}.';';
5269: delete($attr_ref->{$key});
5270:
5271: } elsif (lc($key) eq 'onunload') {
5272: $on_unload.=$attr_ref->{$key}.';';
5273: delete($attr_ref->{$key});
5274: }
5275: }
1.953 droeschl 5276: $attr_ref->{'onload'} = $on_load;
5277: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5278: }
1.339 albertel 5279:
1.330 albertel 5280: my $attr_string;
5281: foreach my $attr (keys(%$attr_ref)) {
5282: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5283: }
5284: return $attr_string;
5285: }
5286:
5287:
1.182 matthew 5288: ###############################################
1.251 albertel 5289: ###############################################
5290:
5291: =pod
5292:
5293: =item * &endbodytag()
5294:
5295: Returns a uniform footer for LON-CAPA web pages.
5296:
1.635 raeburn 5297: Inputs: 1 - optional reference to an args hash
5298: If in the hash, key for noredirectlink has a value which evaluates to true,
5299: a 'Continue' link is not displayed if the page contains an
5300: internal redirect in the <head></head> section,
5301: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5302:
5303: =cut
5304:
5305: sub endbodytag {
1.635 raeburn 5306: my ($args) = @_;
1.1080 raeburn 5307: my $endbodytag;
5308: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5309: $endbodytag='</body>';
5310: }
1.269 albertel 5311: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5312: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5313: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5314: $endbodytag=
5315: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5316: &mt('Continue').'</a>'.
5317: $endbodytag;
5318: }
1.315 albertel 5319: }
1.251 albertel 5320: return $endbodytag;
5321: }
5322:
1.352 albertel 5323: =pod
5324:
5325: =item * &standard_css()
5326:
5327: Returns a style sheet
5328:
5329: Inputs: (all optional)
5330: domain -> force to color decorate a page for a specific
5331: domain
5332: function -> force usage of a specific rolish color scheme
5333: bgcolor -> override the default page bgcolor
5334:
5335: =cut
5336:
1.343 albertel 5337: sub standard_css {
1.345 albertel 5338: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5339: $function = &get_users_function() if (!$function);
5340: my $img = &designparm($function.'.img', $domain);
5341: my $tabbg = &designparm($function.'.tabbg', $domain);
5342: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5343: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5344: #second colour for later usage
1.345 albertel 5345: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5346: my $pgbg_or_bgcolor =
5347: $bgcolor ||
1.352 albertel 5348: &designparm($function.'.pgbg', $domain);
1.382 albertel 5349: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5350: my $alink = &designparm($function.'.alink', $domain);
5351: my $vlink = &designparm($function.'.vlink', $domain);
5352: my $link = &designparm($function.'.link', $domain);
5353:
1.602 albertel 5354: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5355: my $mono = 'monospace';
1.850 bisitz 5356: my $data_table_head = $sidebg;
5357: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5358: my $data_table_dark = '#E0E0E0';
1.470 banghart 5359: my $data_table_darker = '#CCCCCC';
1.349 albertel 5360: my $data_table_highlight = '#FFFF00';
1.352 albertel 5361: my $mail_new = '#FFBB77';
5362: my $mail_new_hover = '#DD9955';
5363: my $mail_read = '#BBBB77';
5364: my $mail_read_hover = '#999944';
5365: my $mail_replied = '#AAAA88';
5366: my $mail_replied_hover = '#888855';
5367: my $mail_other = '#99BBBB';
5368: my $mail_other_hover = '#669999';
1.391 albertel 5369: my $table_header = '#DDDDDD';
1.489 raeburn 5370: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5371: my $lg_border_color = '#C8C8C8';
1.952 onken 5372: my $button_hover = '#BF2317';
1.392 albertel 5373:
1.608 albertel 5374: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5375: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5376: : '0 3px 0 4px';
1.448 albertel 5377:
1.523 albertel 5378:
1.343 albertel 5379: return <<END;
1.947 droeschl 5380:
5381: /* needed for iframe to allow 100% height in FF */
5382: body, html {
5383: margin: 0;
5384: padding: 0 0.5%;
5385: height: 99%; /* to avoid scrollbars */
5386: }
5387:
1.795 www 5388: body {
1.911 bisitz 5389: font-family: $sans;
5390: line-height:130%;
5391: font-size:0.83em;
5392: color:$font;
1.795 www 5393: }
5394:
1.959 onken 5395: a:focus,
5396: a:focus img {
1.795 www 5397: color: red;
5398: }
1.698 harmsja 5399:
1.911 bisitz 5400: form, .inline {
5401: display: inline;
1.795 www 5402: }
1.721 harmsja 5403:
1.795 www 5404: .LC_right {
1.911 bisitz 5405: text-align:right;
1.795 www 5406: }
5407:
5408: .LC_middle {
1.911 bisitz 5409: vertical-align:middle;
1.795 www 5410: }
1.721 harmsja 5411:
1.1130 raeburn 5412: .LC_floatleft {
5413: float: left;
5414: }
5415:
5416: .LC_floatright {
5417: float: right;
5418: }
5419:
1.911 bisitz 5420: .LC_400Box {
5421: width:400px;
5422: }
1.721 harmsja 5423:
1.947 droeschl 5424: .LC_iframecontainer {
5425: width: 98%;
5426: margin: 0;
5427: position: fixed;
5428: top: 8.5em;
5429: bottom: 0;
5430: }
5431:
5432: .LC_iframecontainer iframe{
5433: border: none;
5434: width: 100%;
5435: height: 100%;
5436: }
5437:
1.778 bisitz 5438: .LC_filename {
5439: font-family: $mono;
5440: white-space:pre;
1.921 bisitz 5441: font-size: 120%;
1.778 bisitz 5442: }
5443:
5444: .LC_fileicon {
5445: border: none;
5446: height: 1.3em;
5447: vertical-align: text-bottom;
5448: margin-right: 0.3em;
5449: text-decoration:none;
5450: }
5451:
1.1008 www 5452: .LC_setting {
5453: text-decoration:underline;
5454: }
5455:
1.350 albertel 5456: .LC_error {
5457: color: red;
5458: }
1.795 www 5459:
1.1097 bisitz 5460: .LC_warning {
5461: color: darkorange;
5462: }
5463:
1.457 albertel 5464: .LC_diff_removed {
1.733 bisitz 5465: color: red;
1.394 albertel 5466: }
1.532 albertel 5467:
5468: .LC_info,
1.457 albertel 5469: .LC_success,
5470: .LC_diff_added {
1.350 albertel 5471: color: green;
5472: }
1.795 www 5473:
1.802 bisitz 5474: div.LC_confirm_box {
5475: background-color: #FAFAFA;
5476: border: 1px solid $lg_border_color;
5477: margin-right: 0;
5478: padding: 5px;
5479: }
5480:
5481: div.LC_confirm_box .LC_error img,
5482: div.LC_confirm_box .LC_success img {
5483: vertical-align: middle;
5484: }
5485:
1.440 albertel 5486: .LC_icon {
1.771 droeschl 5487: border: none;
1.790 droeschl 5488: vertical-align: middle;
1.771 droeschl 5489: }
5490:
1.543 albertel 5491: .LC_docs_spacer {
5492: width: 25px;
5493: height: 1px;
1.771 droeschl 5494: border: none;
1.543 albertel 5495: }
1.346 albertel 5496:
1.532 albertel 5497: .LC_internal_info {
1.735 bisitz 5498: color: #999999;
1.532 albertel 5499: }
5500:
1.794 www 5501: .LC_discussion {
1.1050 www 5502: background: $data_table_dark;
1.911 bisitz 5503: border: 1px solid black;
5504: margin: 2px;
1.794 www 5505: }
5506:
5507: .LC_disc_action_left {
1.1050 www 5508: background: $sidebg;
1.911 bisitz 5509: text-align: left;
1.1050 www 5510: padding: 4px;
5511: margin: 2px;
1.794 www 5512: }
5513:
5514: .LC_disc_action_right {
1.1050 www 5515: background: $sidebg;
1.911 bisitz 5516: text-align: right;
1.1050 www 5517: padding: 4px;
5518: margin: 2px;
1.794 www 5519: }
5520:
5521: .LC_disc_new_item {
1.911 bisitz 5522: background: white;
5523: border: 2px solid red;
1.1050 www 5524: margin: 4px;
5525: padding: 4px;
1.794 www 5526: }
5527:
5528: .LC_disc_old_item {
1.911 bisitz 5529: background: white;
1.1050 www 5530: margin: 4px;
5531: padding: 4px;
1.794 www 5532: }
5533:
1.458 albertel 5534: table.LC_pastsubmission {
5535: border: 1px solid black;
5536: margin: 2px;
5537: }
5538:
1.924 bisitz 5539: table#LC_menubuttons {
1.345 albertel 5540: width: 100%;
5541: background: $pgbg;
1.392 albertel 5542: border: 2px;
1.402 albertel 5543: border-collapse: separate;
1.803 bisitz 5544: padding: 0;
1.345 albertel 5545: }
1.392 albertel 5546:
1.801 tempelho 5547: table#LC_title_bar a {
5548: color: $fontmenu;
5549: }
1.836 bisitz 5550:
1.807 droeschl 5551: table#LC_title_bar {
1.819 tempelho 5552: clear: both;
1.836 bisitz 5553: display: none;
1.807 droeschl 5554: }
5555:
1.795 www 5556: table#LC_title_bar,
1.933 droeschl 5557: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5558: table#LC_title_bar.LC_with_remote {
1.359 albertel 5559: width: 100%;
1.392 albertel 5560: border-color: $pgbg;
5561: border-style: solid;
5562: border-width: $border;
1.379 albertel 5563: background: $pgbg;
1.801 tempelho 5564: color: $fontmenu;
1.392 albertel 5565: border-collapse: collapse;
1.803 bisitz 5566: padding: 0;
1.819 tempelho 5567: margin: 0;
1.359 albertel 5568: }
1.795 www 5569:
1.933 droeschl 5570: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5571: margin: 0;
5572: padding: 0;
1.933 droeschl 5573: position: relative;
5574: list-style: none;
1.913 droeschl 5575: }
1.933 droeschl 5576: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5577: display: inline;
5578: }
1.933 droeschl 5579:
5580: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5581: padding: 0;
1.933 droeschl 5582: margin: 0;
5583: float: left;
1.913 droeschl 5584: }
1.933 droeschl 5585: .LC_breadcrumb_tools_tools {
5586: padding: 0;
5587: margin: 0;
1.913 droeschl 5588: float: right;
5589: }
5590:
1.359 albertel 5591: table#LC_title_bar td {
5592: background: $tabbg;
5593: }
1.795 www 5594:
1.911 bisitz 5595: table#LC_menubuttons img {
1.803 bisitz 5596: border: none;
1.346 albertel 5597: }
1.795 www 5598:
1.842 droeschl 5599: .LC_breadcrumbs_component {
1.911 bisitz 5600: float: right;
5601: margin: 0 1em;
1.357 albertel 5602: }
1.842 droeschl 5603: .LC_breadcrumbs_component img {
1.911 bisitz 5604: vertical-align: middle;
1.777 tempelho 5605: }
1.795 www 5606:
1.383 albertel 5607: td.LC_table_cell_checkbox {
5608: text-align: center;
5609: }
1.795 www 5610:
5611: .LC_fontsize_small {
1.911 bisitz 5612: font-size: 70%;
1.705 tempelho 5613: }
5614:
1.844 bisitz 5615: #LC_breadcrumbs {
1.911 bisitz 5616: clear:both;
5617: background: $sidebg;
5618: border-bottom: 1px solid $lg_border_color;
5619: line-height: 2.5em;
1.933 droeschl 5620: overflow: hidden;
1.911 bisitz 5621: margin: 0;
5622: padding: 0;
1.995 raeburn 5623: text-align: left;
1.819 tempelho 5624: }
1.862 bisitz 5625:
1.1098 bisitz 5626: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5627: clear:both;
5628: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5629: border: 1px solid $sidebg;
1.1098 bisitz 5630: margin: 0 0 10px 0;
1.966 bisitz 5631: padding: 3px;
1.995 raeburn 5632: text-align: left;
1.822 bisitz 5633: }
5634:
1.795 www 5635: .LC_fontsize_medium {
1.911 bisitz 5636: font-size: 85%;
1.705 tempelho 5637: }
5638:
1.795 www 5639: .LC_fontsize_large {
1.911 bisitz 5640: font-size: 120%;
1.705 tempelho 5641: }
5642:
1.346 albertel 5643: .LC_menubuttons_inline_text {
5644: color: $font;
1.698 harmsja 5645: font-size: 90%;
1.701 harmsja 5646: padding-left:3px;
1.346 albertel 5647: }
5648:
1.934 droeschl 5649: .LC_menubuttons_inline_text img{
5650: vertical-align: middle;
5651: }
5652:
1.1051 www 5653: li.LC_menubuttons_inline_text img {
1.951 onken 5654: cursor:pointer;
1.1002 droeschl 5655: text-decoration: none;
1.951 onken 5656: }
5657:
1.526 www 5658: .LC_menubuttons_link {
5659: text-decoration: none;
5660: }
1.795 www 5661:
1.522 albertel 5662: .LC_menubuttons_category {
1.521 www 5663: color: $font;
1.526 www 5664: background: $pgbg;
1.521 www 5665: font-size: larger;
5666: font-weight: bold;
5667: }
5668:
1.346 albertel 5669: td.LC_menubuttons_text {
1.911 bisitz 5670: color: $font;
1.346 albertel 5671: }
1.706 harmsja 5672:
1.346 albertel 5673: .LC_current_location {
5674: background: $tabbg;
5675: }
1.795 www 5676:
1.938 bisitz 5677: table.LC_data_table {
1.347 albertel 5678: border: 1px solid #000000;
1.402 albertel 5679: border-collapse: separate;
1.426 albertel 5680: border-spacing: 1px;
1.610 albertel 5681: background: $pgbg;
1.347 albertel 5682: }
1.795 www 5683:
1.422 albertel 5684: .LC_data_table_dense {
5685: font-size: small;
5686: }
1.795 www 5687:
1.507 raeburn 5688: table.LC_nested_outer {
5689: border: 1px solid #000000;
1.589 raeburn 5690: border-collapse: collapse;
1.803 bisitz 5691: border-spacing: 0;
1.507 raeburn 5692: width: 100%;
5693: }
1.795 www 5694:
1.879 raeburn 5695: table.LC_innerpickbox,
1.507 raeburn 5696: table.LC_nested {
1.803 bisitz 5697: border: none;
1.589 raeburn 5698: border-collapse: collapse;
1.803 bisitz 5699: border-spacing: 0;
1.507 raeburn 5700: width: 100%;
5701: }
1.795 www 5702:
1.911 bisitz 5703: table.LC_data_table tr th,
5704: table.LC_calendar tr th,
1.879 raeburn 5705: table.LC_prior_tries tr th,
5706: table.LC_innerpickbox tr th {
1.349 albertel 5707: font-weight: bold;
5708: background-color: $data_table_head;
1.801 tempelho 5709: color:$fontmenu;
1.701 harmsja 5710: font-size:90%;
1.347 albertel 5711: }
1.795 www 5712:
1.879 raeburn 5713: table.LC_innerpickbox tr th,
5714: table.LC_innerpickbox tr td {
5715: vertical-align: top;
5716: }
5717:
1.711 raeburn 5718: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5719: background-color: #CCCCCC;
1.711 raeburn 5720: font-weight: bold;
5721: text-align: left;
5722: }
1.795 www 5723:
1.912 bisitz 5724: table.LC_data_table tr.LC_odd_row > td {
5725: background-color: $data_table_light;
5726: padding: 2px;
5727: vertical-align: top;
5728: }
5729:
1.809 bisitz 5730: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5731: background-color: $data_table_light;
1.912 bisitz 5732: vertical-align: top;
5733: }
5734:
5735: table.LC_data_table tr.LC_even_row > td {
5736: background-color: $data_table_dark;
1.425 albertel 5737: padding: 2px;
1.900 bisitz 5738: vertical-align: top;
1.347 albertel 5739: }
1.795 www 5740:
1.809 bisitz 5741: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5742: background-color: $data_table_dark;
1.900 bisitz 5743: vertical-align: top;
1.347 albertel 5744: }
1.795 www 5745:
1.425 albertel 5746: table.LC_data_table tr.LC_data_table_highlight td {
5747: background-color: $data_table_darker;
5748: }
1.795 www 5749:
1.639 raeburn 5750: table.LC_data_table tr td.LC_leftcol_header {
5751: background-color: $data_table_head;
5752: font-weight: bold;
5753: }
1.795 www 5754:
1.451 albertel 5755: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5756: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5757: font-weight: bold;
5758: font-style: italic;
5759: text-align: center;
5760: padding: 8px;
1.347 albertel 5761: }
1.795 www 5762:
1.1114 raeburn 5763: table.LC_data_table tr.LC_empty_row td,
5764: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5765: background-color: $sidebg;
5766: }
5767:
5768: table.LC_nested tr.LC_empty_row td {
5769: background-color: #FFFFFF;
5770: }
5771:
1.890 droeschl 5772: table.LC_caption {
5773: }
5774:
1.507 raeburn 5775: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5776: padding: 4ex
5777: }
1.795 www 5778:
1.507 raeburn 5779: table.LC_nested_outer tr th {
5780: font-weight: bold;
1.801 tempelho 5781: color:$fontmenu;
1.507 raeburn 5782: background-color: $data_table_head;
1.701 harmsja 5783: font-size: small;
1.507 raeburn 5784: border-bottom: 1px solid #000000;
5785: }
1.795 www 5786:
1.507 raeburn 5787: table.LC_nested_outer tr td.LC_subheader {
5788: background-color: $data_table_head;
5789: font-weight: bold;
5790: font-size: small;
5791: border-bottom: 1px solid #000000;
5792: text-align: right;
1.451 albertel 5793: }
1.795 www 5794:
1.507 raeburn 5795: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5796: background-color: #CCCCCC;
1.451 albertel 5797: font-weight: bold;
5798: font-size: small;
1.507 raeburn 5799: text-align: center;
5800: }
1.795 www 5801:
1.589 raeburn 5802: table.LC_nested tr.LC_info_row td.LC_left_item,
5803: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5804: text-align: left;
1.451 albertel 5805: }
1.795 www 5806:
1.507 raeburn 5807: table.LC_nested td {
1.735 bisitz 5808: background-color: #FFFFFF;
1.451 albertel 5809: font-size: small;
1.507 raeburn 5810: }
1.795 www 5811:
1.507 raeburn 5812: table.LC_nested_outer tr th.LC_right_item,
5813: table.LC_nested tr.LC_info_row td.LC_right_item,
5814: table.LC_nested tr.LC_odd_row td.LC_right_item,
5815: table.LC_nested tr td.LC_right_item {
1.451 albertel 5816: text-align: right;
5817: }
5818:
1.507 raeburn 5819: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5820: background-color: #EEEEEE;
1.451 albertel 5821: }
5822:
1.473 raeburn 5823: table.LC_createuser {
5824: }
5825:
5826: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5827: font-size: small;
1.473 raeburn 5828: }
5829:
5830: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5831: background-color: #CCCCCC;
1.473 raeburn 5832: font-weight: bold;
5833: text-align: center;
5834: }
5835:
1.349 albertel 5836: table.LC_calendar {
5837: border: 1px solid #000000;
5838: border-collapse: collapse;
1.917 raeburn 5839: width: 98%;
1.349 albertel 5840: }
1.795 www 5841:
1.349 albertel 5842: table.LC_calendar_pickdate {
5843: font-size: xx-small;
5844: }
1.795 www 5845:
1.349 albertel 5846: table.LC_calendar tr td {
5847: border: 1px solid #000000;
5848: vertical-align: top;
1.917 raeburn 5849: width: 14%;
1.349 albertel 5850: }
1.795 www 5851:
1.349 albertel 5852: table.LC_calendar tr td.LC_calendar_day_empty {
5853: background-color: $data_table_dark;
5854: }
1.795 www 5855:
1.779 bisitz 5856: table.LC_calendar tr td.LC_calendar_day_current {
5857: background-color: $data_table_highlight;
1.777 tempelho 5858: }
1.795 www 5859:
1.938 bisitz 5860: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5861: background-color: $mail_new;
5862: }
1.795 www 5863:
1.938 bisitz 5864: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5865: background-color: $mail_new_hover;
5866: }
1.795 www 5867:
1.938 bisitz 5868: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5869: background-color: $mail_read;
5870: }
1.795 www 5871:
1.938 bisitz 5872: /*
5873: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5874: background-color: $mail_read_hover;
5875: }
1.938 bisitz 5876: */
1.795 www 5877:
1.938 bisitz 5878: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5879: background-color: $mail_replied;
5880: }
1.795 www 5881:
1.938 bisitz 5882: /*
5883: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5884: background-color: $mail_replied_hover;
5885: }
1.938 bisitz 5886: */
1.795 www 5887:
1.938 bisitz 5888: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5889: background-color: $mail_other;
5890: }
1.795 www 5891:
1.938 bisitz 5892: /*
5893: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5894: background-color: $mail_other_hover;
5895: }
1.938 bisitz 5896: */
1.494 raeburn 5897:
1.777 tempelho 5898: table.LC_data_table tr > td.LC_browser_file,
5899: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5900: background: #AAEE77;
1.389 albertel 5901: }
1.795 www 5902:
1.777 tempelho 5903: table.LC_data_table tr > td.LC_browser_file_locked,
5904: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5905: background: #FFAA99;
1.387 albertel 5906: }
1.795 www 5907:
1.777 tempelho 5908: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5909: background: #888888;
1.779 bisitz 5910: }
1.795 www 5911:
1.777 tempelho 5912: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5913: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5914: background: #F8F866;
1.777 tempelho 5915: }
1.795 www 5916:
1.696 bisitz 5917: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5918: background: #E0E8FF;
1.387 albertel 5919: }
1.696 bisitz 5920:
1.707 bisitz 5921: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5922: /* background: #77FF77; */
1.707 bisitz 5923: }
1.795 www 5924:
1.707 bisitz 5925: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5926: border-right: 8px solid #FFFF77;
1.707 bisitz 5927: }
1.795 www 5928:
1.707 bisitz 5929: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5930: border-right: 8px solid #FFAA77;
1.707 bisitz 5931: }
1.795 www 5932:
1.707 bisitz 5933: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5934: border-right: 8px solid #FF7777;
1.707 bisitz 5935: }
1.795 www 5936:
1.707 bisitz 5937: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5938: border-right: 8px solid #AAFF77;
1.707 bisitz 5939: }
1.795 www 5940:
1.707 bisitz 5941: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5942: border-right: 8px solid #11CC55;
1.707 bisitz 5943: }
5944:
1.388 albertel 5945: span.LC_current_location {
1.701 harmsja 5946: font-size:larger;
1.388 albertel 5947: background: $pgbg;
5948: }
1.387 albertel 5949:
1.1029 www 5950: span.LC_current_nav_location {
5951: font-weight:bold;
5952: background: $sidebg;
5953: }
5954:
1.395 albertel 5955: span.LC_parm_menu_item {
5956: font-size: larger;
5957: }
1.795 www 5958:
1.395 albertel 5959: span.LC_parm_scope_all {
5960: color: red;
5961: }
1.795 www 5962:
1.395 albertel 5963: span.LC_parm_scope_folder {
5964: color: green;
5965: }
1.795 www 5966:
1.395 albertel 5967: span.LC_parm_scope_resource {
5968: color: orange;
5969: }
1.795 www 5970:
1.395 albertel 5971: span.LC_parm_part {
5972: color: blue;
5973: }
1.795 www 5974:
1.911 bisitz 5975: span.LC_parm_folder,
5976: span.LC_parm_symb {
1.395 albertel 5977: font-size: x-small;
5978: font-family: $mono;
5979: color: #AAAAAA;
5980: }
5981:
1.977 bisitz 5982: ul.LC_parm_parmlist li {
5983: display: inline-block;
5984: padding: 0.3em 0.8em;
5985: vertical-align: top;
5986: width: 150px;
5987: border-top:1px solid $lg_border_color;
5988: }
5989:
1.795 www 5990: td.LC_parm_overview_level_menu,
5991: td.LC_parm_overview_map_menu,
5992: td.LC_parm_overview_parm_selectors,
5993: td.LC_parm_overview_restrictions {
1.396 albertel 5994: border: 1px solid black;
5995: border-collapse: collapse;
5996: }
1.795 www 5997:
1.396 albertel 5998: table.LC_parm_overview_restrictions td {
5999: border-width: 1px 4px 1px 4px;
6000: border-style: solid;
6001: border-color: $pgbg;
6002: text-align: center;
6003: }
1.795 www 6004:
1.396 albertel 6005: table.LC_parm_overview_restrictions th {
6006: background: $tabbg;
6007: border-width: 1px 4px 1px 4px;
6008: border-style: solid;
6009: border-color: $pgbg;
6010: }
1.795 www 6011:
1.398 albertel 6012: table#LC_helpmenu {
1.803 bisitz 6013: border: none;
1.398 albertel 6014: height: 55px;
1.803 bisitz 6015: border-spacing: 0;
1.398 albertel 6016: }
6017:
6018: table#LC_helpmenu fieldset legend {
6019: font-size: larger;
6020: }
1.795 www 6021:
1.397 albertel 6022: table#LC_helpmenu_links {
6023: width: 100%;
6024: border: 1px solid black;
6025: background: $pgbg;
1.803 bisitz 6026: padding: 0;
1.397 albertel 6027: border-spacing: 1px;
6028: }
1.795 www 6029:
1.397 albertel 6030: table#LC_helpmenu_links tr td {
6031: padding: 1px;
6032: background: $tabbg;
1.399 albertel 6033: text-align: center;
6034: font-weight: bold;
1.397 albertel 6035: }
1.396 albertel 6036:
1.795 www 6037: table#LC_helpmenu_links a:link,
6038: table#LC_helpmenu_links a:visited,
1.397 albertel 6039: table#LC_helpmenu_links a:active {
6040: text-decoration: none;
6041: color: $font;
6042: }
1.795 www 6043:
1.397 albertel 6044: table#LC_helpmenu_links a:hover {
6045: text-decoration: underline;
6046: color: $vlink;
6047: }
1.396 albertel 6048:
1.417 albertel 6049: .LC_chrt_popup_exists {
6050: border: 1px solid #339933;
6051: margin: -1px;
6052: }
1.795 www 6053:
1.417 albertel 6054: .LC_chrt_popup_up {
6055: border: 1px solid yellow;
6056: margin: -1px;
6057: }
1.795 www 6058:
1.417 albertel 6059: .LC_chrt_popup {
6060: border: 1px solid #8888FF;
6061: background: #CCCCFF;
6062: }
1.795 www 6063:
1.421 albertel 6064: table.LC_pick_box {
6065: border-collapse: separate;
6066: background: white;
6067: border: 1px solid black;
6068: border-spacing: 1px;
6069: }
1.795 www 6070:
1.421 albertel 6071: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6072: background: $sidebg;
1.421 albertel 6073: font-weight: bold;
1.900 bisitz 6074: text-align: left;
1.740 bisitz 6075: vertical-align: top;
1.421 albertel 6076: width: 184px;
6077: padding: 8px;
6078: }
1.795 www 6079:
1.579 raeburn 6080: table.LC_pick_box td.LC_pick_box_value {
6081: text-align: left;
6082: padding: 8px;
6083: }
1.795 www 6084:
1.579 raeburn 6085: table.LC_pick_box td.LC_pick_box_select {
6086: text-align: left;
6087: padding: 8px;
6088: }
1.795 www 6089:
1.424 albertel 6090: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6091: padding: 0;
1.421 albertel 6092: height: 1px;
6093: background: black;
6094: }
1.795 www 6095:
1.421 albertel 6096: table.LC_pick_box td.LC_pick_box_submit {
6097: text-align: right;
6098: }
1.795 www 6099:
1.579 raeburn 6100: table.LC_pick_box td.LC_evenrow_value {
6101: text-align: left;
6102: padding: 8px;
6103: background-color: $data_table_light;
6104: }
1.795 www 6105:
1.579 raeburn 6106: table.LC_pick_box td.LC_oddrow_value {
6107: text-align: left;
6108: padding: 8px;
6109: background-color: $data_table_light;
6110: }
1.795 www 6111:
1.579 raeburn 6112: span.LC_helpform_receipt_cat {
6113: font-weight: bold;
6114: }
1.795 www 6115:
1.424 albertel 6116: table.LC_group_priv_box {
6117: background: white;
6118: border: 1px solid black;
6119: border-spacing: 1px;
6120: }
1.795 www 6121:
1.424 albertel 6122: table.LC_group_priv_box td.LC_pick_box_title {
6123: background: $tabbg;
6124: font-weight: bold;
6125: text-align: right;
6126: width: 184px;
6127: }
1.795 www 6128:
1.424 albertel 6129: table.LC_group_priv_box td.LC_groups_fixed {
6130: background: $data_table_light;
6131: text-align: center;
6132: }
1.795 www 6133:
1.424 albertel 6134: table.LC_group_priv_box td.LC_groups_optional {
6135: background: $data_table_dark;
6136: text-align: center;
6137: }
1.795 www 6138:
1.424 albertel 6139: table.LC_group_priv_box td.LC_groups_functionality {
6140: background: $data_table_darker;
6141: text-align: center;
6142: font-weight: bold;
6143: }
1.795 www 6144:
1.424 albertel 6145: table.LC_group_priv td {
6146: text-align: left;
1.803 bisitz 6147: padding: 0;
1.424 albertel 6148: }
6149:
6150: .LC_navbuttons {
6151: margin: 2ex 0ex 2ex 0ex;
6152: }
1.795 www 6153:
1.423 albertel 6154: .LC_topic_bar {
6155: font-weight: bold;
6156: background: $tabbg;
1.918 wenzelju 6157: margin: 1em 0em 1em 2em;
1.805 bisitz 6158: padding: 3px;
1.918 wenzelju 6159: font-size: 1.2em;
1.423 albertel 6160: }
1.795 www 6161:
1.423 albertel 6162: .LC_topic_bar span {
1.918 wenzelju 6163: left: 0.5em;
6164: position: absolute;
1.423 albertel 6165: vertical-align: middle;
1.918 wenzelju 6166: font-size: 1.2em;
1.423 albertel 6167: }
1.795 www 6168:
1.423 albertel 6169: table.LC_course_group_status {
6170: margin: 20px;
6171: }
1.795 www 6172:
1.423 albertel 6173: table.LC_status_selector td {
6174: vertical-align: top;
6175: text-align: center;
1.424 albertel 6176: padding: 4px;
6177: }
1.795 www 6178:
1.599 albertel 6179: div.LC_feedback_link {
1.616 albertel 6180: clear: both;
1.829 kalberla 6181: background: $sidebg;
1.779 bisitz 6182: width: 100%;
1.829 kalberla 6183: padding-bottom: 10px;
6184: border: 1px $tabbg solid;
1.833 kalberla 6185: height: 22px;
6186: line-height: 22px;
6187: padding-top: 5px;
6188: }
6189:
6190: div.LC_feedback_link img {
6191: height: 22px;
1.867 kalberla 6192: vertical-align:middle;
1.829 kalberla 6193: }
6194:
1.911 bisitz 6195: div.LC_feedback_link a {
1.829 kalberla 6196: text-decoration: none;
1.489 raeburn 6197: }
1.795 www 6198:
1.867 kalberla 6199: div.LC_comblock {
1.911 bisitz 6200: display:inline;
1.867 kalberla 6201: color:$font;
6202: font-size:90%;
6203: }
6204:
6205: div.LC_feedback_link div.LC_comblock {
6206: padding-left:5px;
6207: }
6208:
6209: div.LC_feedback_link div.LC_comblock a {
6210: color:$font;
6211: }
6212:
1.489 raeburn 6213: span.LC_feedback_link {
1.858 bisitz 6214: /* background: $feedback_link_bg; */
1.599 albertel 6215: font-size: larger;
6216: }
1.795 www 6217:
1.599 albertel 6218: span.LC_message_link {
1.858 bisitz 6219: /* background: $feedback_link_bg; */
1.599 albertel 6220: font-size: larger;
6221: position: absolute;
6222: right: 1em;
1.489 raeburn 6223: }
1.421 albertel 6224:
1.515 albertel 6225: table.LC_prior_tries {
1.524 albertel 6226: border: 1px solid #000000;
6227: border-collapse: separate;
6228: border-spacing: 1px;
1.515 albertel 6229: }
1.523 albertel 6230:
1.515 albertel 6231: table.LC_prior_tries td {
1.524 albertel 6232: padding: 2px;
1.515 albertel 6233: }
1.523 albertel 6234:
6235: .LC_answer_correct {
1.795 www 6236: background: lightgreen;
6237: color: darkgreen;
6238: padding: 6px;
1.523 albertel 6239: }
1.795 www 6240:
1.523 albertel 6241: .LC_answer_charged_try {
1.797 www 6242: background: #FFAAAA;
1.795 www 6243: color: darkred;
6244: padding: 6px;
1.523 albertel 6245: }
1.795 www 6246:
1.779 bisitz 6247: .LC_answer_not_charged_try,
1.523 albertel 6248: .LC_answer_no_grade,
6249: .LC_answer_late {
1.795 www 6250: background: lightyellow;
1.523 albertel 6251: color: black;
1.795 www 6252: padding: 6px;
1.523 albertel 6253: }
1.795 www 6254:
1.523 albertel 6255: .LC_answer_previous {
1.795 www 6256: background: lightblue;
6257: color: darkblue;
6258: padding: 6px;
1.523 albertel 6259: }
1.795 www 6260:
1.779 bisitz 6261: .LC_answer_no_message {
1.777 tempelho 6262: background: #FFFFFF;
6263: color: black;
1.795 www 6264: padding: 6px;
1.779 bisitz 6265: }
1.795 www 6266:
1.779 bisitz 6267: .LC_answer_unknown {
6268: background: orange;
6269: color: black;
1.795 www 6270: padding: 6px;
1.777 tempelho 6271: }
1.795 www 6272:
1.529 albertel 6273: span.LC_prior_numerical,
6274: span.LC_prior_string,
6275: span.LC_prior_custom,
6276: span.LC_prior_reaction,
6277: span.LC_prior_math {
1.925 bisitz 6278: font-family: $mono;
1.523 albertel 6279: white-space: pre;
6280: }
6281:
1.525 albertel 6282: span.LC_prior_string {
1.925 bisitz 6283: font-family: $mono;
1.525 albertel 6284: white-space: pre;
6285: }
6286:
1.523 albertel 6287: table.LC_prior_option {
6288: width: 100%;
6289: border-collapse: collapse;
6290: }
1.795 www 6291:
1.911 bisitz 6292: table.LC_prior_rank,
1.795 www 6293: table.LC_prior_match {
1.528 albertel 6294: border-collapse: collapse;
6295: }
1.795 www 6296:
1.528 albertel 6297: table.LC_prior_option tr td,
6298: table.LC_prior_rank tr td,
6299: table.LC_prior_match tr td {
1.524 albertel 6300: border: 1px solid #000000;
1.515 albertel 6301: }
6302:
1.855 bisitz 6303: .LC_nobreak {
1.544 albertel 6304: white-space: nowrap;
1.519 raeburn 6305: }
6306:
1.576 raeburn 6307: span.LC_cusr_emph {
6308: font-style: italic;
6309: }
6310:
1.633 raeburn 6311: span.LC_cusr_subheading {
6312: font-weight: normal;
6313: font-size: 85%;
6314: }
6315:
1.861 bisitz 6316: div.LC_docs_entry_move {
1.859 bisitz 6317: border: 1px solid #BBBBBB;
1.545 albertel 6318: background: #DDDDDD;
1.861 bisitz 6319: width: 22px;
1.859 bisitz 6320: padding: 1px;
6321: margin: 0;
1.545 albertel 6322: }
6323:
1.861 bisitz 6324: table.LC_data_table tr > td.LC_docs_entry_commands,
6325: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6326: font-size: x-small;
6327: }
1.795 www 6328:
1.861 bisitz 6329: .LC_docs_entry_parameter {
6330: white-space: nowrap;
6331: }
6332:
1.544 albertel 6333: .LC_docs_copy {
1.545 albertel 6334: color: #000099;
1.544 albertel 6335: }
1.795 www 6336:
1.544 albertel 6337: .LC_docs_cut {
1.545 albertel 6338: color: #550044;
1.544 albertel 6339: }
1.795 www 6340:
1.544 albertel 6341: .LC_docs_rename {
1.545 albertel 6342: color: #009900;
1.544 albertel 6343: }
1.795 www 6344:
1.544 albertel 6345: .LC_docs_remove {
1.545 albertel 6346: color: #990000;
6347: }
6348:
1.547 albertel 6349: .LC_docs_reinit_warn,
6350: .LC_docs_ext_edit {
6351: font-size: x-small;
6352: }
6353:
1.545 albertel 6354: table.LC_docs_adddocs td,
6355: table.LC_docs_adddocs th {
6356: border: 1px solid #BBBBBB;
6357: padding: 4px;
6358: background: #DDDDDD;
1.543 albertel 6359: }
6360:
1.584 albertel 6361: table.LC_sty_begin {
6362: background: #BBFFBB;
6363: }
1.795 www 6364:
1.584 albertel 6365: table.LC_sty_end {
6366: background: #FFBBBB;
6367: }
6368:
1.589 raeburn 6369: table.LC_double_column {
1.803 bisitz 6370: border-width: 0;
1.589 raeburn 6371: border-collapse: collapse;
6372: width: 100%;
6373: padding: 2px;
6374: }
6375:
6376: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6377: top: 2px;
1.589 raeburn 6378: left: 2px;
6379: width: 47%;
6380: vertical-align: top;
6381: }
6382:
6383: table.LC_double_column tr td.LC_right_col {
6384: top: 2px;
1.779 bisitz 6385: right: 2px;
1.589 raeburn 6386: width: 47%;
6387: vertical-align: top;
6388: }
6389:
1.591 raeburn 6390: div.LC_left_float {
6391: float: left;
6392: padding-right: 5%;
1.597 albertel 6393: padding-bottom: 4px;
1.591 raeburn 6394: }
6395:
6396: div.LC_clear_float_header {
1.597 albertel 6397: padding-bottom: 2px;
1.591 raeburn 6398: }
6399:
6400: div.LC_clear_float_footer {
1.597 albertel 6401: padding-top: 10px;
1.591 raeburn 6402: clear: both;
6403: }
6404:
1.597 albertel 6405: div.LC_grade_show_user {
1.941 bisitz 6406: /* border-left: 5px solid $sidebg; */
6407: border-top: 5px solid #000000;
6408: margin: 50px 0 0 0;
1.936 bisitz 6409: padding: 15px 0 5px 10px;
1.597 albertel 6410: }
1.795 www 6411:
1.936 bisitz 6412: div.LC_grade_show_user_odd_row {
1.941 bisitz 6413: /* border-left: 5px solid #000000; */
6414: }
6415:
6416: div.LC_grade_show_user div.LC_Box {
6417: margin-right: 50px;
1.597 albertel 6418: }
6419:
6420: div.LC_grade_submissions,
6421: div.LC_grade_message_center,
1.936 bisitz 6422: div.LC_grade_info_links {
1.597 albertel 6423: margin: 5px;
6424: width: 99%;
6425: background: #FFFFFF;
6426: }
1.795 www 6427:
1.597 albertel 6428: div.LC_grade_submissions_header,
1.936 bisitz 6429: div.LC_grade_message_center_header {
1.705 tempelho 6430: font-weight: bold;
6431: font-size: large;
1.597 albertel 6432: }
1.795 www 6433:
1.597 albertel 6434: div.LC_grade_submissions_body,
1.936 bisitz 6435: div.LC_grade_message_center_body {
1.597 albertel 6436: border: 1px solid black;
6437: width: 99%;
6438: background: #FFFFFF;
6439: }
1.795 www 6440:
1.613 albertel 6441: table.LC_scantron_action {
6442: width: 100%;
6443: }
1.795 www 6444:
1.613 albertel 6445: table.LC_scantron_action tr th {
1.698 harmsja 6446: font-weight:bold;
6447: font-style:normal;
1.613 albertel 6448: }
1.795 www 6449:
1.779 bisitz 6450: .LC_edit_problem_header,
1.614 albertel 6451: div.LC_edit_problem_footer {
1.705 tempelho 6452: font-weight: normal;
6453: font-size: medium;
1.602 albertel 6454: margin: 2px;
1.1060 bisitz 6455: background-color: $sidebg;
1.600 albertel 6456: }
1.795 www 6457:
1.600 albertel 6458: div.LC_edit_problem_header,
1.602 albertel 6459: div.LC_edit_problem_header div,
1.614 albertel 6460: div.LC_edit_problem_footer,
6461: div.LC_edit_problem_footer div,
1.602 albertel 6462: div.LC_edit_problem_editxml_header,
6463: div.LC_edit_problem_editxml_header div {
1.600 albertel 6464: margin-top: 5px;
6465: }
1.795 www 6466:
1.600 albertel 6467: div.LC_edit_problem_header_title {
1.705 tempelho 6468: font-weight: bold;
6469: font-size: larger;
1.602 albertel 6470: background: $tabbg;
6471: padding: 3px;
1.1060 bisitz 6472: margin: 0 0 5px 0;
1.602 albertel 6473: }
1.795 www 6474:
1.602 albertel 6475: table.LC_edit_problem_header_title {
6476: width: 100%;
1.600 albertel 6477: background: $tabbg;
1.602 albertel 6478: }
6479:
6480: div.LC_edit_problem_discards {
6481: float: left;
6482: padding-bottom: 5px;
6483: }
1.795 www 6484:
1.602 albertel 6485: div.LC_edit_problem_saves {
6486: float: right;
6487: padding-bottom: 5px;
1.600 albertel 6488: }
1.795 www 6489:
1.1124 bisitz 6490: .LC_edit_opt {
6491: padding-left: 1em;
6492: white-space: nowrap;
6493: }
6494:
1.911 bisitz 6495: img.stift {
1.803 bisitz 6496: border-width: 0;
6497: vertical-align: middle;
1.677 riegler 6498: }
1.680 riegler 6499:
1.923 bisitz 6500: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6501: vertical-align: top;
1.777 tempelho 6502: }
1.795 www 6503:
1.716 raeburn 6504: div.LC_createcourse {
1.911 bisitz 6505: margin: 10px 10px 10px 10px;
1.716 raeburn 6506: }
6507:
1.917 raeburn 6508: .LC_dccid {
1.1130 raeburn 6509: float: right;
1.917 raeburn 6510: margin: 0.2em 0 0 0;
6511: padding: 0;
6512: font-size: 90%;
6513: display:none;
6514: }
6515:
1.897 wenzelju 6516: ol.LC_primary_menu a:hover,
1.721 harmsja 6517: ol#LC_MenuBreadcrumbs a:hover,
6518: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6519: ul#LC_secondary_menu a:hover,
1.721 harmsja 6520: .LC_FormSectionClearButton input:hover
1.795 www 6521: ul.LC_TabContent li:hover a {
1.952 onken 6522: color:$button_hover;
1.911 bisitz 6523: text-decoration:none;
1.693 droeschl 6524: }
6525:
1.779 bisitz 6526: h1 {
1.911 bisitz 6527: padding: 0;
6528: line-height:130%;
1.693 droeschl 6529: }
1.698 harmsja 6530:
1.911 bisitz 6531: h2,
6532: h3,
6533: h4,
6534: h5,
6535: h6 {
6536: margin: 5px 0 5px 0;
6537: padding: 0;
6538: line-height:130%;
1.693 droeschl 6539: }
1.795 www 6540:
6541: .LC_hcell {
1.911 bisitz 6542: padding:3px 15px 3px 15px;
6543: margin: 0;
6544: background-color:$tabbg;
6545: color:$fontmenu;
6546: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6547: }
1.795 www 6548:
1.840 bisitz 6549: .LC_Box > .LC_hcell {
1.911 bisitz 6550: margin: 0 -10px 10px -10px;
1.835 bisitz 6551: }
6552:
1.721 harmsja 6553: .LC_noBorder {
1.911 bisitz 6554: border: 0;
1.698 harmsja 6555: }
1.693 droeschl 6556:
1.721 harmsja 6557: .LC_FormSectionClearButton input {
1.911 bisitz 6558: background-color:transparent;
6559: border: none;
6560: cursor:pointer;
6561: text-decoration:underline;
1.693 droeschl 6562: }
1.763 bisitz 6563:
6564: .LC_help_open_topic {
1.911 bisitz 6565: color: #FFFFFF;
6566: background-color: #EEEEFF;
6567: margin: 1px;
6568: padding: 4px;
6569: border: 1px solid #000033;
6570: white-space: nowrap;
6571: /* vertical-align: middle; */
1.759 neumanie 6572: }
1.693 droeschl 6573:
1.911 bisitz 6574: dl,
6575: ul,
6576: div,
6577: fieldset {
6578: margin: 10px 10px 10px 0;
6579: /* overflow: hidden; */
1.693 droeschl 6580: }
1.795 www 6581:
1.838 bisitz 6582: fieldset > legend {
1.911 bisitz 6583: font-weight: bold;
6584: padding: 0 5px 0 5px;
1.838 bisitz 6585: }
6586:
1.813 bisitz 6587: #LC_nav_bar {
1.911 bisitz 6588: float: left;
1.995 raeburn 6589: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6590: margin: 0 0 2px 0;
1.807 droeschl 6591: }
6592:
1.916 droeschl 6593: #LC_realm {
6594: margin: 0.2em 0 0 0;
6595: padding: 0;
6596: font-weight: bold;
6597: text-align: center;
1.995 raeburn 6598: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6599: }
6600:
1.911 bisitz 6601: #LC_nav_bar em {
6602: font-weight: bold;
6603: font-style: normal;
1.807 droeschl 6604: }
6605:
1.897 wenzelju 6606: ol.LC_primary_menu {
1.934 droeschl 6607: margin: 0;
1.1076 raeburn 6608: padding: 0;
1.995 raeburn 6609: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6610: }
6611:
1.852 droeschl 6612: ol#LC_PathBreadcrumbs {
1.911 bisitz 6613: margin: 0;
1.693 droeschl 6614: }
6615:
1.897 wenzelju 6616: ol.LC_primary_menu li {
1.1076 raeburn 6617: color: RGB(80, 80, 80);
6618: vertical-align: middle;
6619: text-align: left;
6620: list-style: none;
6621: float: left;
6622: }
6623:
6624: ol.LC_primary_menu li a {
6625: display: block;
6626: margin: 0;
6627: padding: 0 5px 0 10px;
6628: text-decoration: none;
6629: }
6630:
6631: ol.LC_primary_menu li ul {
6632: display: none;
6633: width: 10em;
6634: background-color: $data_table_light;
6635: }
6636:
6637: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6638: display: block;
6639: position: absolute;
6640: margin: 0;
6641: padding: 0;
1.1078 raeburn 6642: z-index: 2;
1.1076 raeburn 6643: }
6644:
6645: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6646: font-size: 90%;
1.911 bisitz 6647: vertical-align: top;
1.1076 raeburn 6648: float: none;
1.1079 raeburn 6649: border-left: 1px solid black;
6650: border-right: 1px solid black;
1.1076 raeburn 6651: }
6652:
6653: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6654: background-color:$data_table_light;
1.1076 raeburn 6655: }
6656:
6657: ol.LC_primary_menu li li a:hover {
6658: color:$button_hover;
6659: background-color:$data_table_dark;
1.693 droeschl 6660: }
6661:
1.897 wenzelju 6662: ol.LC_primary_menu li img {
1.911 bisitz 6663: vertical-align: bottom;
1.934 droeschl 6664: height: 1.1em;
1.1077 raeburn 6665: margin: 0.2em 0 0 0;
1.693 droeschl 6666: }
6667:
1.897 wenzelju 6668: ol.LC_primary_menu a {
1.911 bisitz 6669: color: RGB(80, 80, 80);
6670: text-decoration: none;
1.693 droeschl 6671: }
1.795 www 6672:
1.949 droeschl 6673: ol.LC_primary_menu a.LC_new_message {
6674: font-weight:bold;
6675: color: darkred;
6676: }
6677:
1.975 raeburn 6678: ol.LC_docs_parameters {
6679: margin-left: 0;
6680: padding: 0;
6681: list-style: none;
6682: }
6683:
6684: ol.LC_docs_parameters li {
6685: margin: 0;
6686: padding-right: 20px;
6687: display: inline;
6688: }
6689:
1.976 raeburn 6690: ol.LC_docs_parameters li:before {
6691: content: "\\002022 \\0020";
6692: }
6693:
6694: li.LC_docs_parameters_title {
6695: font-weight: bold;
6696: }
6697:
6698: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6699: content: "";
6700: }
6701:
1.897 wenzelju 6702: ul#LC_secondary_menu {
1.1107 raeburn 6703: clear: right;
1.911 bisitz 6704: color: $fontmenu;
6705: background: $tabbg;
6706: list-style: none;
6707: padding: 0;
6708: margin: 0;
6709: width: 100%;
1.995 raeburn 6710: text-align: left;
1.1107 raeburn 6711: float: left;
1.808 droeschl 6712: }
6713:
1.897 wenzelju 6714: ul#LC_secondary_menu li {
1.911 bisitz 6715: font-weight: bold;
6716: line-height: 1.8em;
1.1107 raeburn 6717: border-right: 1px solid black;
6718: float: left;
6719: }
6720:
6721: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6722: background-color: $data_table_light;
6723: }
6724:
6725: ul#LC_secondary_menu li a {
1.911 bisitz 6726: padding: 0 0.8em;
1.1107 raeburn 6727: }
6728:
6729: ul#LC_secondary_menu li ul {
6730: display: none;
6731: }
6732:
6733: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6734: display: block;
6735: position: absolute;
6736: margin: 0;
6737: padding: 0;
6738: list-style:none;
6739: float: none;
6740: background-color: $data_table_light;
6741: z-index: 2;
6742: margin-left: -1px;
6743: }
6744:
6745: ul#LC_secondary_menu li ul li {
6746: font-size: 90%;
6747: vertical-align: top;
6748: border-left: 1px solid black;
1.911 bisitz 6749: border-right: 1px solid black;
1.1119 raeburn 6750: background-color: $data_table_light;
1.1107 raeburn 6751: list-style:none;
6752: float: none;
6753: }
6754:
6755: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6756: background-color: $data_table_dark;
1.807 droeschl 6757: }
6758:
1.847 tempelho 6759: ul.LC_TabContent {
1.911 bisitz 6760: display:block;
6761: background: $sidebg;
6762: border-bottom: solid 1px $lg_border_color;
6763: list-style:none;
1.1020 raeburn 6764: margin: -1px -10px 0 -10px;
1.911 bisitz 6765: padding: 0;
1.693 droeschl 6766: }
6767:
1.795 www 6768: ul.LC_TabContent li,
6769: ul.LC_TabContentBigger li {
1.911 bisitz 6770: float:left;
1.741 harmsja 6771: }
1.795 www 6772:
1.897 wenzelju 6773: ul#LC_secondary_menu li a {
1.911 bisitz 6774: color: $fontmenu;
6775: text-decoration: none;
1.693 droeschl 6776: }
1.795 www 6777:
1.721 harmsja 6778: ul.LC_TabContent {
1.952 onken 6779: min-height:20px;
1.721 harmsja 6780: }
1.795 www 6781:
6782: ul.LC_TabContent li {
1.911 bisitz 6783: vertical-align:middle;
1.959 onken 6784: padding: 0 16px 0 10px;
1.911 bisitz 6785: background-color:$tabbg;
6786: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6787: border-left: solid 1px $font;
1.721 harmsja 6788: }
1.795 www 6789:
1.847 tempelho 6790: ul.LC_TabContent .right {
1.911 bisitz 6791: float:right;
1.847 tempelho 6792: }
6793:
1.911 bisitz 6794: ul.LC_TabContent li a,
6795: ul.LC_TabContent li {
6796: color:rgb(47,47,47);
6797: text-decoration:none;
6798: font-size:95%;
6799: font-weight:bold;
1.952 onken 6800: min-height:20px;
6801: }
6802:
1.959 onken 6803: ul.LC_TabContent li a:hover,
6804: ul.LC_TabContent li a:focus {
1.952 onken 6805: color: $button_hover;
1.959 onken 6806: background:none;
6807: outline:none;
1.952 onken 6808: }
6809:
6810: ul.LC_TabContent li:hover {
6811: color: $button_hover;
6812: cursor:pointer;
1.721 harmsja 6813: }
1.795 www 6814:
1.911 bisitz 6815: ul.LC_TabContent li.active {
1.952 onken 6816: color: $font;
1.911 bisitz 6817: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6818: border-bottom:solid 1px #FFFFFF;
6819: cursor: default;
1.744 ehlerst 6820: }
1.795 www 6821:
1.959 onken 6822: ul.LC_TabContent li.active a {
6823: color:$font;
6824: background:#FFFFFF;
6825: outline: none;
6826: }
1.1047 raeburn 6827:
6828: ul.LC_TabContent li.goback {
6829: float: left;
6830: border-left: none;
6831: }
6832:
1.870 tempelho 6833: #maincoursedoc {
1.911 bisitz 6834: clear:both;
1.870 tempelho 6835: }
6836:
6837: ul.LC_TabContentBigger {
1.911 bisitz 6838: display:block;
6839: list-style:none;
6840: padding: 0;
1.870 tempelho 6841: }
6842:
1.795 www 6843: ul.LC_TabContentBigger li {
1.911 bisitz 6844: vertical-align:bottom;
6845: height: 30px;
6846: font-size:110%;
6847: font-weight:bold;
6848: color: #737373;
1.841 tempelho 6849: }
6850:
1.957 onken 6851: ul.LC_TabContentBigger li.active {
6852: position: relative;
6853: top: 1px;
6854: }
6855:
1.870 tempelho 6856: ul.LC_TabContentBigger li a {
1.911 bisitz 6857: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6858: height: 30px;
6859: line-height: 30px;
6860: text-align: center;
6861: display: block;
6862: text-decoration: none;
1.958 onken 6863: outline: none;
1.741 harmsja 6864: }
1.795 www 6865:
1.870 tempelho 6866: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6867: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6868: color:$font;
1.744 ehlerst 6869: }
1.795 www 6870:
1.870 tempelho 6871: ul.LC_TabContentBigger li b {
1.911 bisitz 6872: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6873: display: block;
6874: float: left;
6875: padding: 0 30px;
1.957 onken 6876: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6877: }
6878:
1.956 onken 6879: ul.LC_TabContentBigger li:hover b {
6880: color:$button_hover;
6881: }
6882:
1.870 tempelho 6883: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6884: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6885: color:$font;
1.957 onken 6886: border: 0;
1.741 harmsja 6887: }
1.693 droeschl 6888:
1.870 tempelho 6889:
1.862 bisitz 6890: ul.LC_CourseBreadcrumbs {
6891: background: $sidebg;
1.1020 raeburn 6892: height: 2em;
1.862 bisitz 6893: padding-left: 10px;
1.1020 raeburn 6894: margin: 0;
1.862 bisitz 6895: list-style-position: inside;
6896: }
6897:
1.911 bisitz 6898: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6899: ol#LC_PathBreadcrumbs {
1.911 bisitz 6900: padding-left: 10px;
6901: margin: 0;
1.933 droeschl 6902: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6903: }
6904:
1.911 bisitz 6905: ol#LC_MenuBreadcrumbs li,
6906: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6907: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6908: display: inline;
1.933 droeschl 6909: white-space: normal;
1.693 droeschl 6910: }
6911:
1.823 bisitz 6912: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6913: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6914: text-decoration: none;
6915: font-size:90%;
1.693 droeschl 6916: }
1.795 www 6917:
1.969 droeschl 6918: ol#LC_MenuBreadcrumbs h1 {
6919: display: inline;
6920: font-size: 90%;
6921: line-height: 2.5em;
6922: margin: 0;
6923: padding: 0;
6924: }
6925:
1.795 www 6926: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6927: text-decoration:none;
6928: font-size:100%;
6929: font-weight:bold;
1.693 droeschl 6930: }
1.795 www 6931:
1.840 bisitz 6932: .LC_Box {
1.911 bisitz 6933: border: solid 1px $lg_border_color;
6934: padding: 0 10px 10px 10px;
1.746 neumanie 6935: }
1.795 www 6936:
1.1020 raeburn 6937: .LC_DocsBox {
6938: border: solid 1px $lg_border_color;
6939: padding: 0 0 10px 10px;
6940: }
6941:
1.795 www 6942: .LC_AboutMe_Image {
1.911 bisitz 6943: float:left;
6944: margin-right:10px;
1.747 neumanie 6945: }
1.795 www 6946:
6947: .LC_Clear_AboutMe_Image {
1.911 bisitz 6948: clear:left;
1.747 neumanie 6949: }
1.795 www 6950:
1.721 harmsja 6951: dl.LC_ListStyleClean dt {
1.911 bisitz 6952: padding-right: 5px;
6953: display: table-header-group;
1.693 droeschl 6954: }
6955:
1.721 harmsja 6956: dl.LC_ListStyleClean dd {
1.911 bisitz 6957: display: table-row;
1.693 droeschl 6958: }
6959:
1.721 harmsja 6960: .LC_ListStyleClean,
6961: .LC_ListStyleSimple,
6962: .LC_ListStyleNormal,
1.795 www 6963: .LC_ListStyleSpecial {
1.911 bisitz 6964: /* display:block; */
6965: list-style-position: inside;
6966: list-style-type: none;
6967: overflow: hidden;
6968: padding: 0;
1.693 droeschl 6969: }
6970:
1.721 harmsja 6971: .LC_ListStyleSimple li,
6972: .LC_ListStyleSimple dd,
6973: .LC_ListStyleNormal li,
6974: .LC_ListStyleNormal dd,
6975: .LC_ListStyleSpecial li,
1.795 www 6976: .LC_ListStyleSpecial dd {
1.911 bisitz 6977: margin: 0;
6978: padding: 5px 5px 5px 10px;
6979: clear: both;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: .LC_ListStyleClean li,
6983: .LC_ListStyleClean dd {
1.911 bisitz 6984: padding-top: 0;
6985: padding-bottom: 0;
1.693 droeschl 6986: }
6987:
1.721 harmsja 6988: .LC_ListStyleSimple dd,
1.795 www 6989: .LC_ListStyleSimple li {
1.911 bisitz 6990: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6991: }
6992:
1.721 harmsja 6993: .LC_ListStyleSpecial li,
6994: .LC_ListStyleSpecial dd {
1.911 bisitz 6995: list-style-type: none;
6996: background-color: RGB(220, 220, 220);
6997: margin-bottom: 4px;
1.693 droeschl 6998: }
6999:
1.721 harmsja 7000: table.LC_SimpleTable {
1.911 bisitz 7001: margin:5px;
7002: border:solid 1px $lg_border_color;
1.795 www 7003: }
1.693 droeschl 7004:
1.721 harmsja 7005: table.LC_SimpleTable tr {
1.911 bisitz 7006: padding: 0;
7007: border:solid 1px $lg_border_color;
1.693 droeschl 7008: }
1.795 www 7009:
7010: table.LC_SimpleTable thead {
1.911 bisitz 7011: background:rgb(220,220,220);
1.693 droeschl 7012: }
7013:
1.721 harmsja 7014: div.LC_columnSection {
1.911 bisitz 7015: display: block;
7016: clear: both;
7017: overflow: hidden;
7018: margin: 0;
1.693 droeschl 7019: }
7020:
1.721 harmsja 7021: div.LC_columnSection>* {
1.911 bisitz 7022: float: left;
7023: margin: 10px 20px 10px 0;
7024: overflow:hidden;
1.693 droeschl 7025: }
1.721 harmsja 7026:
1.795 www 7027: table em {
1.911 bisitz 7028: font-weight: bold;
7029: font-style: normal;
1.748 schulted 7030: }
1.795 www 7031:
1.779 bisitz 7032: table.LC_tableBrowseRes,
1.795 www 7033: table.LC_tableOfContent {
1.911 bisitz 7034: border:none;
7035: border-spacing: 1px;
7036: padding: 3px;
7037: background-color: #FFFFFF;
7038: font-size: 90%;
1.753 droeschl 7039: }
1.789 droeschl 7040:
1.911 bisitz 7041: table.LC_tableOfContent {
7042: border-collapse: collapse;
1.789 droeschl 7043: }
7044:
1.771 droeschl 7045: table.LC_tableBrowseRes a,
1.768 schulted 7046: table.LC_tableOfContent a {
1.911 bisitz 7047: background-color: transparent;
7048: text-decoration: none;
1.753 droeschl 7049: }
7050:
1.795 www 7051: table.LC_tableOfContent img {
1.911 bisitz 7052: border: none;
7053: height: 1.3em;
7054: vertical-align: text-bottom;
7055: margin-right: 0.3em;
1.753 droeschl 7056: }
1.757 schulted 7057:
1.795 www 7058: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7059: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7060: }
7061:
1.795 www 7062: a#LC_content_toolbar_everything {
1.911 bisitz 7063: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7064: }
7065:
1.795 www 7066: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7067: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7068: }
7069:
1.795 www 7070: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7071: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7072: }
7073:
1.795 www 7074: a#LC_content_toolbar_changefolder {
1.911 bisitz 7075: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7076: }
7077:
1.795 www 7078: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7079: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7080: }
7081:
1.1043 raeburn 7082: a#LC_content_toolbar_edittoplevel {
7083: background-image:url(/res/adm/pages/edittoplevel.gif);
7084: }
7085:
1.795 www 7086: ul#LC_toolbar li a:hover {
1.911 bisitz 7087: background-position: bottom center;
1.757 schulted 7088: }
7089:
1.795 www 7090: ul#LC_toolbar {
1.911 bisitz 7091: padding: 0;
7092: margin: 2px;
7093: list-style:none;
7094: position:relative;
7095: background-color:white;
1.1082 raeburn 7096: overflow: auto;
1.757 schulted 7097: }
7098:
1.795 www 7099: ul#LC_toolbar li {
1.911 bisitz 7100: border:1px solid white;
7101: padding: 0;
7102: margin: 0;
7103: float: left;
7104: display:inline;
7105: vertical-align:middle;
1.1082 raeburn 7106: white-space: nowrap;
1.911 bisitz 7107: }
1.757 schulted 7108:
1.783 amueller 7109:
1.795 www 7110: a.LC_toolbarItem {
1.911 bisitz 7111: display:block;
7112: padding: 0;
7113: margin: 0;
7114: height: 32px;
7115: width: 32px;
7116: color:white;
7117: border: none;
7118: background-repeat:no-repeat;
7119: background-color:transparent;
1.757 schulted 7120: }
7121:
1.915 droeschl 7122: ul.LC_funclist {
7123: margin: 0;
7124: padding: 0.5em 1em 0.5em 0;
7125: }
7126:
1.933 droeschl 7127: ul.LC_funclist > li:first-child {
7128: font-weight:bold;
7129: margin-left:0.8em;
7130: }
7131:
1.915 droeschl 7132: ul.LC_funclist + ul.LC_funclist {
7133: /*
7134: left border as a seperator if we have more than
7135: one list
7136: */
7137: border-left: 1px solid $sidebg;
7138: /*
7139: this hides the left border behind the border of the
7140: outer box if element is wrapped to the next 'line'
7141: */
7142: margin-left: -1px;
7143: }
7144:
1.843 bisitz 7145: ul.LC_funclist li {
1.915 droeschl 7146: display: inline;
1.782 bisitz 7147: white-space: nowrap;
1.915 droeschl 7148: margin: 0 0 0 25px;
7149: line-height: 150%;
1.782 bisitz 7150: }
7151:
1.974 wenzelju 7152: .LC_hidden {
7153: display: none;
7154: }
7155:
1.1030 www 7156: .LCmodal-overlay {
7157: position:fixed;
7158: top:0;
7159: right:0;
7160: bottom:0;
7161: left:0;
7162: height:100%;
7163: width:100%;
7164: margin:0;
7165: padding:0;
7166: background:#999;
7167: opacity:.75;
7168: filter: alpha(opacity=75);
7169: -moz-opacity: 0.75;
7170: z-index:101;
7171: }
7172:
7173: * html .LCmodal-overlay {
7174: position: absolute;
7175: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7176: }
7177:
7178: .LCmodal-window {
7179: position:fixed;
7180: top:50%;
7181: left:50%;
7182: margin:0;
7183: padding:0;
7184: z-index:102;
7185: }
7186:
7187: * html .LCmodal-window {
7188: position:absolute;
7189: }
7190:
7191: .LCclose-window {
7192: position:absolute;
7193: width:32px;
7194: height:32px;
7195: right:8px;
7196: top:8px;
7197: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7198: text-indent:-99999px;
7199: overflow:hidden;
7200: cursor:pointer;
7201: }
7202:
1.1100 raeburn 7203: /*
7204: styles used by TTH when "Default set of options to pass to tth/m
7205: when converting TeX" in course settings has been set
7206:
7207: option passed: -t
7208:
7209: */
7210:
7211: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7212: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7213: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7214: td div.norm {line-height:normal;}
7215:
7216: /*
7217: option passed -y3
7218: */
7219:
7220: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7221: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7222: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7223:
1.343 albertel 7224: END
7225: }
7226:
1.306 albertel 7227: =pod
7228:
7229: =item * &headtag()
7230:
7231: Returns a uniform footer for LON-CAPA web pages.
7232:
1.307 albertel 7233: Inputs: $title - optional title for the head
7234: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7235: $args - optional arguments
1.319 albertel 7236: force_register - if is true call registerurl so the remote is
7237: informed
1.415 albertel 7238: redirect -> array ref of
7239: 1- seconds before redirect occurs
7240: 2- url to redirect to
7241: 3- whether the side effect should occur
1.315 albertel 7242: (side effect of setting
7243: $env{'internal.head.redirect'} to the url
7244: redirected too)
1.352 albertel 7245: domain -> force to color decorate a page for a specific
7246: domain
7247: function -> force usage of a specific rolish color scheme
7248: bgcolor -> override the default page bgcolor
1.460 albertel 7249: no_auto_mt_title
7250: -> prevent &mt()ing the title arg
1.464 albertel 7251:
1.306 albertel 7252: =cut
7253:
7254: sub headtag {
1.313 albertel 7255: my ($title,$head_extra,$args) = @_;
1.306 albertel 7256:
1.363 albertel 7257: my $function = $args->{'function'} || &get_users_function();
7258: my $domain = $args->{'domain'} || &determinedomain();
7259: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7260: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7261: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7262: #time(),
1.418 albertel 7263: $env{'environment.color.timestamp'},
1.363 albertel 7264: $function,$domain,$bgcolor);
7265:
1.369 www 7266: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7267:
1.308 albertel 7268: my $result =
7269: '<head>'.
1.461 albertel 7270: &font_settings();
1.319 albertel 7271:
1.1064 raeburn 7272: my $inhibitprint = &print_suppression();
7273:
1.461 albertel 7274: if (!$args->{'frameset'}) {
7275: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7276: }
1.962 droeschl 7277: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7278: $result .= Apache::lonxml::display_title();
1.319 albertel 7279: }
1.436 albertel 7280: if (!$args->{'no_nav_bar'}
7281: && !$args->{'only_body'}
7282: && !$args->{'frameset'}) {
7283: $result .= &help_menu_js();
1.1032 www 7284: $result.=&modal_window();
1.1038 www 7285: $result.=&togglebox_script();
1.1034 www 7286: $result.=&wishlist_window();
1.1041 www 7287: $result.=&LCprogressbarUpdate_script();
1.1034 www 7288: } else {
7289: if ($args->{'add_modal'}) {
7290: $result.=&modal_window();
7291: }
7292: if ($args->{'add_wishlist'}) {
7293: $result.=&wishlist_window();
7294: }
1.1038 www 7295: if ($args->{'add_togglebox'}) {
7296: $result.=&togglebox_script();
7297: }
1.1041 www 7298: if ($args->{'add_progressbar'}) {
7299: $result.=&LCprogressbarUpdate_script();
7300: }
1.436 albertel 7301: }
1.314 albertel 7302: if (ref($args->{'redirect'})) {
1.414 albertel 7303: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7304: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7305: if (!$inhibit_continue) {
7306: $env{'internal.head.redirect'} = $url;
7307: }
1.313 albertel 7308: $result.=<<ADDMETA
7309: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7310: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7311: ADDMETA
7312: }
1.306 albertel 7313: if (!defined($title)) {
7314: $title = 'The LearningOnline Network with CAPA';
7315: }
1.460 albertel 7316: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7317: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7318: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7319: .$inhibitprint
1.414 albertel 7320: .$head_extra;
1.1137 raeburn 7321: if ($env{'browser.mobile'}) {
7322: $result .= '
7323: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7324: <meta name="apple-mobile-web-app-capable" content="yes" />';
7325: }
1.962 droeschl 7326: return $result.'</head>';
1.306 albertel 7327: }
7328:
7329: =pod
7330:
1.340 albertel 7331: =item * &font_settings()
7332:
7333: Returns neccessary <meta> to set the proper encoding
7334:
7335: Inputs: none
7336:
7337: =cut
7338:
7339: sub font_settings {
7340: my $headerstring='';
1.647 www 7341: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7342: $headerstring.=
7343: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7344: }
7345: return $headerstring;
7346: }
7347:
1.341 albertel 7348: =pod
7349:
1.1064 raeburn 7350: =item * &print_suppression()
7351:
7352: In course context returns css which causes the body to be blank when media="print",
7353: if printout generation is unavailable for the current resource.
7354:
7355: This could be because:
7356:
7357: (a) printstartdate is in the future
7358:
7359: (b) printenddate is in the past
7360:
7361: (c) there is an active exam block with "printout"
7362: functionality blocked
7363:
7364: Users with pav, pfo or evb privileges are exempt.
7365:
7366: Inputs: none
7367:
7368: =cut
7369:
7370:
7371: sub print_suppression {
7372: my $noprint;
7373: if ($env{'request.course.id'}) {
7374: my $scope = $env{'request.course.id'};
7375: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7376: (&Apache::lonnet::allowed('pfo',$scope))) {
7377: return;
7378: }
7379: if ($env{'request.course.sec'} ne '') {
7380: $scope .= "/$env{'request.course.sec'}";
7381: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7382: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7383: return;
1.1064 raeburn 7384: }
7385: }
7386: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7387: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7388: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7389: if ($blocked) {
7390: my $checkrole = "cm./$cdom/$cnum";
7391: if ($env{'request.course.sec'} ne '') {
7392: $checkrole .= "/$env{'request.course.sec'}";
7393: }
7394: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7395: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7396: $noprint = 1;
7397: }
7398: }
7399: unless ($noprint) {
7400: my $symb = &Apache::lonnet::symbread();
7401: if ($symb ne '') {
7402: my $navmap = Apache::lonnavmaps::navmap->new();
7403: if (ref($navmap)) {
7404: my $res = $navmap->getBySymb($symb);
7405: if (ref($res)) {
7406: if (!$res->resprintable()) {
7407: $noprint = 1;
7408: }
7409: }
7410: }
7411: }
7412: }
7413: if ($noprint) {
7414: return <<"ENDSTYLE";
7415: <style type="text/css" media="print">
7416: body { display:none }
7417: </style>
7418: ENDSTYLE
7419: }
7420: }
7421: return;
7422: }
7423:
7424: =pod
7425:
1.341 albertel 7426: =item * &xml_begin()
7427:
7428: Returns the needed doctype and <html>
7429:
7430: Inputs: none
7431:
7432: =cut
7433:
7434: sub xml_begin {
7435: my $output='';
7436:
7437: if ($env{'browser.mathml'}) {
7438: $output='<?xml version="1.0"?>'
7439: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7440: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7441:
7442: # .'<!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">] >'
7443: .'<!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">'
7444: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7445: .'xmlns="http://www.w3.org/1999/xhtml">';
7446: } else {
1.849 bisitz 7447: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7448: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7449: }
7450: return $output;
7451: }
1.340 albertel 7452:
7453: =pod
7454:
1.306 albertel 7455: =item * &start_page()
7456:
7457: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7458:
1.648 raeburn 7459: Inputs:
7460:
7461: =over 4
7462:
7463: $title - optional title for the page
7464:
7465: $head_extra - optional extra HTML to incude inside the <head>
7466:
7467: $args - additional optional args supported are:
7468:
7469: =over 8
7470:
7471: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7472: arg on
1.814 bisitz 7473: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7474: add_entries -> additional attributes to add to the <body>
7475: domain -> force to color decorate a page for a
1.317 albertel 7476: specific domain
1.648 raeburn 7477: function -> force usage of a specific rolish color
1.317 albertel 7478: scheme
1.648 raeburn 7479: redirect -> see &headtag()
7480: bgcolor -> override the default page bg color
7481: js_ready -> return a string ready for being used in
1.317 albertel 7482: a javascript writeln
1.648 raeburn 7483: html_encode -> return a string ready for being used in
1.320 albertel 7484: a html attribute
1.648 raeburn 7485: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7486: $forcereg arg
1.648 raeburn 7487: frameset -> if true will start with a <frameset>
1.330 albertel 7488: rather than <body>
1.648 raeburn 7489: skip_phases -> hash ref of
1.338 albertel 7490: head -> skip the <html><head> generation
7491: body -> skip all <body> generation
1.648 raeburn 7492: no_auto_mt_title -> prevent &mt()ing the title arg
7493: inherit_jsmath -> when creating popup window in a page,
7494: should it have jsmath forced on by the
7495: current page
1.867 kalberla 7496: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7497: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7498: group -> includes the current group, if page is for a
7499: specific group
1.361 albertel 7500:
1.648 raeburn 7501: =back
1.460 albertel 7502:
1.648 raeburn 7503: =back
1.562 albertel 7504:
1.306 albertel 7505: =cut
7506:
7507: sub start_page {
1.309 albertel 7508: my ($title,$head_extra,$args) = @_;
1.318 albertel 7509: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7510:
1.315 albertel 7511: $env{'internal.start_page'}++;
1.1096 raeburn 7512: my ($result,@advtools);
1.964 droeschl 7513:
1.338 albertel 7514: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7515: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7516: }
7517:
7518: if (! exists($args->{'skip_phases'}{'body'}) ) {
7519: if ($args->{'frameset'}) {
7520: my $attr_string = &make_attr_string($args->{'force_register'},
7521: $args->{'add_entries'});
7522: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7523: } else {
7524: $result .=
7525: &bodytag($title,
7526: $args->{'function'}, $args->{'add_entries'},
7527: $args->{'only_body'}, $args->{'domain'},
7528: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7529: $args->{'bgcolor'}, $args,
7530: \@advtools);
1.831 bisitz 7531: }
1.330 albertel 7532: }
1.338 albertel 7533:
1.315 albertel 7534: if ($args->{'js_ready'}) {
1.713 kaisler 7535: $result = &js_ready($result);
1.315 albertel 7536: }
1.320 albertel 7537: if ($args->{'html_encode'}) {
1.713 kaisler 7538: $result = &html_encode($result);
7539: }
7540:
1.813 bisitz 7541: # Preparation for new and consistent functionlist at top of screen
7542: # if ($args->{'functionlist'}) {
7543: # $result .= &build_functionlist();
7544: #}
7545:
1.964 droeschl 7546: # Don't add anything more if only_body wanted or in const space
7547: return $result if $args->{'only_body'}
7548: || $env{'request.state'} eq 'construct';
1.813 bisitz 7549:
7550: #Breadcrumbs
1.758 kaisler 7551: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7552: &Apache::lonhtmlcommon::clear_breadcrumbs();
7553: #if any br links exists, add them to the breadcrumbs
7554: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7555: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7556: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7557: }
7558: }
1.1096 raeburn 7559: # if @advtools array contains items add then to the breadcrumbs
7560: if (@advtools > 0) {
7561: &Apache::lonmenu::advtools_crumbs(@advtools);
7562: }
1.758 kaisler 7563:
7564: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7565: if(exists($args->{'bread_crumbs_component'})){
7566: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7567: }else{
7568: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7569: }
1.320 albertel 7570: }
1.315 albertel 7571: return $result;
1.306 albertel 7572: }
7573:
7574: sub end_page {
1.315 albertel 7575: my ($args) = @_;
7576: $env{'internal.end_page'}++;
1.330 albertel 7577: my $result;
1.335 albertel 7578: if ($args->{'discussion'}) {
7579: my ($target,$parser);
7580: if (ref($args->{'discussion'})) {
7581: ($target,$parser) =($args->{'discussion'}{'target'},
7582: $args->{'discussion'}{'parser'});
7583: }
7584: $result .= &Apache::lonxml::xmlend($target,$parser);
7585: }
1.330 albertel 7586: if ($args->{'frameset'}) {
7587: $result .= '</frameset>';
7588: } else {
1.635 raeburn 7589: $result .= &endbodytag($args);
1.330 albertel 7590: }
1.1080 raeburn 7591: unless ($args->{'notbody'}) {
7592: $result .= "\n</html>";
7593: }
1.330 albertel 7594:
1.315 albertel 7595: if ($args->{'js_ready'}) {
1.317 albertel 7596: $result = &js_ready($result);
1.315 albertel 7597: }
1.335 albertel 7598:
1.320 albertel 7599: if ($args->{'html_encode'}) {
7600: $result = &html_encode($result);
7601: }
1.335 albertel 7602:
1.315 albertel 7603: return $result;
7604: }
7605:
1.1034 www 7606: sub wishlist_window {
7607: return(<<'ENDWISHLIST');
1.1046 raeburn 7608: <script type="text/javascript">
1.1034 www 7609: // <![CDATA[
7610: // <!-- BEGIN LON-CAPA Internal
7611: function set_wishlistlink(title, path) {
7612: if (!title) {
7613: title = document.title;
7614: title = title.replace(/^LON-CAPA /,'');
7615: }
7616: if (!path) {
7617: path = location.pathname;
7618: }
7619: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7620: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7621: }
7622: // END LON-CAPA Internal -->
7623: // ]]>
7624: </script>
7625: ENDWISHLIST
7626: }
7627:
1.1030 www 7628: sub modal_window {
7629: return(<<'ENDMODAL');
1.1046 raeburn 7630: <script type="text/javascript">
1.1030 www 7631: // <![CDATA[
7632: // <!-- BEGIN LON-CAPA Internal
7633: var modalWindow = {
7634: parent:"body",
7635: windowId:null,
7636: content:null,
7637: width:null,
7638: height:null,
7639: close:function()
7640: {
7641: $(".LCmodal-window").remove();
7642: $(".LCmodal-overlay").remove();
7643: },
7644: open:function()
7645: {
7646: var modal = "";
7647: modal += "<div class=\"LCmodal-overlay\"></div>";
7648: 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;\">";
7649: modal += this.content;
7650: modal += "</div>";
7651:
7652: $(this.parent).append(modal);
7653:
7654: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7655: $(".LCclose-window").click(function(){modalWindow.close();});
7656: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7657: }
7658: };
1.1140 ! raeburn 7659: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7660: {
7661: modalWindow.windowId = "myModal";
7662: modalWindow.width = width;
7663: modalWindow.height = height;
1.1140 ! raeburn 7664: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7665: modalWindow.open();
7666: };
7667: // END LON-CAPA Internal -->
7668: // ]]>
7669: </script>
7670: ENDMODAL
7671: }
7672:
7673: sub modal_link {
1.1140 ! raeburn 7674: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7675: unless ($width) { $width=480; }
7676: unless ($height) { $height=400; }
1.1031 www 7677: unless ($scrolling) { $scrolling='yes'; }
1.1140 ! raeburn 7678: unless ($transparency) { $transparency='true'; }
! 7679:
1.1074 raeburn 7680: my $target_attr;
7681: if (defined($target)) {
7682: $target_attr = 'target="'.$target.'"';
7683: }
7684: return <<"ENDLINK";
1.1140 ! raeburn 7685: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7686: $linktext</a>
7687: ENDLINK
1.1030 www 7688: }
7689:
1.1032 www 7690: sub modal_adhoc_script {
7691: my ($funcname,$width,$height,$content)=@_;
7692: return (<<ENDADHOC);
1.1046 raeburn 7693: <script type="text/javascript">
1.1032 www 7694: // <![CDATA[
7695: var $funcname = function()
7696: {
7697: modalWindow.windowId = "myModal";
7698: modalWindow.width = $width;
7699: modalWindow.height = $height;
7700: modalWindow.content = '$content';
7701: modalWindow.open();
7702: };
7703: // ]]>
7704: </script>
7705: ENDADHOC
7706: }
7707:
1.1041 www 7708: sub modal_adhoc_inner {
7709: my ($funcname,$width,$height,$content)=@_;
7710: my $innerwidth=$width-20;
7711: $content=&js_ready(
1.1140 ! raeburn 7712: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
! 7713: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
! 7714: $content.
1.1041 www 7715: &end_scrollbox().
1.1140 ! raeburn 7716: &end_page()
1.1041 www 7717: );
7718: return &modal_adhoc_script($funcname,$width,$height,$content);
7719: }
7720:
7721: sub modal_adhoc_window {
7722: my ($funcname,$width,$height,$content,$linktext)=@_;
7723: return &modal_adhoc_inner($funcname,$width,$height,$content).
7724: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7725: }
7726:
7727: sub modal_adhoc_launch {
7728: my ($funcname,$width,$height,$content)=@_;
7729: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7730: <script type="text/javascript">
7731: // <![CDATA[
7732: $funcname();
7733: // ]]>
7734: </script>
7735: ENDLAUNCH
7736: }
7737:
7738: sub modal_adhoc_close {
7739: return (<<ENDCLOSE);
7740: <script type="text/javascript">
7741: // <![CDATA[
7742: modalWindow.close();
7743: // ]]>
7744: </script>
7745: ENDCLOSE
7746: }
7747:
1.1038 www 7748: sub togglebox_script {
7749: return(<<ENDTOGGLE);
7750: <script type="text/javascript">
7751: // <![CDATA[
7752: function LCtoggleDisplay(id,hidetext,showtext) {
7753: link = document.getElementById(id + "link").childNodes[0];
7754: with (document.getElementById(id).style) {
7755: if (display == "none" ) {
7756: display = "inline";
7757: link.nodeValue = hidetext;
7758: } else {
7759: display = "none";
7760: link.nodeValue = showtext;
7761: }
7762: }
7763: }
7764: // ]]>
7765: </script>
7766: ENDTOGGLE
7767: }
7768:
1.1039 www 7769: sub start_togglebox {
7770: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7771: unless ($heading) { $heading=''; } else { $heading.=' '; }
7772: unless ($showtext) { $showtext=&mt('show'); }
7773: unless ($hidetext) { $hidetext=&mt('hide'); }
7774: unless ($headerbg) { $headerbg='#FFFFFF'; }
7775: return &start_data_table().
7776: &start_data_table_header_row().
7777: '<td bgcolor="'.$headerbg.'">'.$heading.
7778: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7779: $showtext.'\')">'.$showtext.'</a>]</td>'.
7780: &end_data_table_header_row().
7781: '<tr id="'.$id.'" style="display:none""><td>';
7782: }
7783:
7784: sub end_togglebox {
7785: return '</td></tr>'.&end_data_table();
7786: }
7787:
1.1041 www 7788: sub LCprogressbar_script {
1.1045 www 7789: my ($id)=@_;
1.1041 www 7790: return(<<ENDPROGRESS);
7791: <script type="text/javascript">
7792: // <![CDATA[
1.1045 www 7793: \$('#progressbar$id').progressbar({
1.1041 www 7794: value: 0,
7795: change: function(event, ui) {
7796: var newVal = \$(this).progressbar('option', 'value');
7797: \$('.pblabel', this).text(LCprogressTxt);
7798: }
7799: });
7800: // ]]>
7801: </script>
7802: ENDPROGRESS
7803: }
7804:
7805: sub LCprogressbarUpdate_script {
7806: return(<<ENDPROGRESSUPDATE);
7807: <style type="text/css">
7808: .ui-progressbar { position:relative; }
7809: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7810: </style>
7811: <script type="text/javascript">
7812: // <![CDATA[
1.1045 www 7813: var LCprogressTxt='---';
7814:
7815: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7816: LCprogressTxt=progresstext;
1.1045 www 7817: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7818: }
7819: // ]]>
7820: </script>
7821: ENDPROGRESSUPDATE
7822: }
7823:
1.1042 www 7824: my $LClastpercent;
1.1045 www 7825: my $LCidcnt;
7826: my $LCcurrentid;
1.1042 www 7827:
1.1041 www 7828: sub LCprogressbar {
1.1042 www 7829: my ($r)=(@_);
7830: $LClastpercent=0;
1.1045 www 7831: $LCidcnt++;
7832: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7833: my $starting=&mt('Starting');
7834: my $content=(<<ENDPROGBAR);
1.1045 www 7835: <div id="progressbar$LCcurrentid">
1.1041 www 7836: <span class="pblabel">$starting</span>
7837: </div>
7838: ENDPROGBAR
1.1045 www 7839: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7840: }
7841:
7842: sub LCprogressbarUpdate {
1.1042 www 7843: my ($r,$val,$text)=@_;
7844: unless ($val) {
7845: if ($LClastpercent) {
7846: $val=$LClastpercent;
7847: } else {
7848: $val=0;
7849: }
7850: }
1.1041 www 7851: if ($val<0) { $val=0; }
7852: if ($val>100) { $val=0; }
1.1042 www 7853: $LClastpercent=$val;
1.1041 www 7854: unless ($text) { $text=$val.'%'; }
7855: $text=&js_ready($text);
1.1044 www 7856: &r_print($r,<<ENDUPDATE);
1.1041 www 7857: <script type="text/javascript">
7858: // <![CDATA[
1.1045 www 7859: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7860: // ]]>
7861: </script>
7862: ENDUPDATE
1.1035 www 7863: }
7864:
1.1042 www 7865: sub LCprogressbarClose {
7866: my ($r)=@_;
7867: $LClastpercent=0;
1.1044 www 7868: &r_print($r,<<ENDCLOSE);
1.1042 www 7869: <script type="text/javascript">
7870: // <![CDATA[
1.1045 www 7871: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7872: // ]]>
7873: </script>
7874: ENDCLOSE
1.1044 www 7875: }
7876:
7877: sub r_print {
7878: my ($r,$to_print)=@_;
7879: if ($r) {
7880: $r->print($to_print);
7881: $r->rflush();
7882: } else {
7883: print($to_print);
7884: }
1.1042 www 7885: }
7886:
1.320 albertel 7887: sub html_encode {
7888: my ($result) = @_;
7889:
1.322 albertel 7890: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7891:
7892: return $result;
7893: }
1.1044 www 7894:
1.317 albertel 7895: sub js_ready {
7896: my ($result) = @_;
7897:
1.323 albertel 7898: $result =~ s/[\n\r]/ /xmsg;
7899: $result =~ s/\\/\\\\/xmsg;
7900: $result =~ s/'/\\'/xmsg;
1.372 albertel 7901: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7902:
7903: return $result;
7904: }
7905:
1.315 albertel 7906: sub validate_page {
7907: if ( exists($env{'internal.start_page'})
1.316 albertel 7908: && $env{'internal.start_page'} > 1) {
7909: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7910: $env{'internal.start_page'}.' '.
1.316 albertel 7911: $ENV{'request.filename'});
1.315 albertel 7912: }
7913: if ( exists($env{'internal.end_page'})
1.316 albertel 7914: && $env{'internal.end_page'} > 1) {
7915: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7916: $env{'internal.end_page'}.' '.
1.316 albertel 7917: $env{'request.filename'});
1.315 albertel 7918: }
7919: if ( exists($env{'internal.start_page'})
7920: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7921: &Apache::lonnet::logthis('start_page called without end_page '.
7922: $env{'request.filename'});
1.315 albertel 7923: }
7924: if ( ! exists($env{'internal.start_page'})
7925: && exists($env{'internal.end_page'})) {
1.316 albertel 7926: &Apache::lonnet::logthis('end_page called without start_page'.
7927: $env{'request.filename'});
1.315 albertel 7928: }
1.306 albertel 7929: }
1.315 albertel 7930:
1.996 www 7931:
7932: sub start_scrollbox {
1.1140 ! raeburn 7933: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7934: unless ($outerwidth) { $outerwidth='520px'; }
7935: unless ($width) { $width='500px'; }
7936: unless ($height) { $height='200px'; }
1.1075 raeburn 7937: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7938: if ($id ne '') {
1.1140 ! raeburn 7939: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 7940: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7941: }
1.1075 raeburn 7942: if ($bgcolor ne '') {
7943: $tdcol = "background-color: $bgcolor;";
7944: }
1.1137 raeburn 7945: my $nicescroll_js;
7946: if ($env{'browser.mobile'}) {
1.1140 ! raeburn 7947: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
! 7948: }
! 7949: return <<"END";
! 7950: $nicescroll_js
! 7951:
! 7952: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
! 7953: <div style="overflow:auto; width:$width; height:$height;"$div_id>
! 7954: END
! 7955: }
! 7956:
! 7957: sub end_scrollbox {
! 7958: return '</div></td></tr></table>';
! 7959: }
! 7960:
! 7961: sub nicescroll_javascript {
! 7962: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
! 7963: my %options;
! 7964: if (ref($cursor) eq 'HASH') {
! 7965: %options = %{$cursor};
! 7966: }
! 7967: unless ($options{'railalign'} =~ /^left|right$/) {
! 7968: $options{'railalign'} = 'left';
! 7969: }
! 7970: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
! 7971: my $function = &get_users_function();
! 7972: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 7973: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 ! raeburn 7974: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 7975: }
1.1140 ! raeburn 7976: }
! 7977: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
! 7978: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 7979: $options{'cursoropacity'}='1.0';
7980: }
1.1140 ! raeburn 7981: } else {
! 7982: $options{'cursoropacity'}='1.0';
! 7983: }
! 7984: if ($options{'cursorfixedheight'} eq 'none') {
! 7985: delete($options{'cursorfixedheight'});
! 7986: } else {
! 7987: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
! 7988: }
! 7989: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
! 7990: delete($options{'railoffset'});
! 7991: }
! 7992: my @niceoptions;
! 7993: while (my($key,$value) = each(%options)) {
! 7994: if ($value =~ /^\{.+\}$/) {
! 7995: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 7996: } else {
1.1140 ! raeburn 7997: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 7998: }
1.1140 ! raeburn 7999: }
! 8000: my $nicescroll_js = '
1.1137 raeburn 8001: $(document).ready(
1.1140 ! raeburn 8002: function() {
! 8003: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
! 8004: }
1.1137 raeburn 8005: );
8006: ';
1.1140 ! raeburn 8007: if ($framecheck) {
! 8008: $nicescroll_js .= '
! 8009: function expand_div(caller) {
! 8010: if (top === self) {
! 8011: document.getElementById("'.$id.'").style.width = "auto";
! 8012: document.getElementById("'.$id.'").style.height = "auto";
! 8013: } else {
! 8014: try {
! 8015: if (parent.frames) {
! 8016: if (parent.frames.length > 1) {
! 8017: var framesrc = parent.frames[1].location.href;
! 8018: var currsrc = framesrc.replace(/\#.*$/,"");
! 8019: if ((caller == "search") || (currsrc == "'.$location.'")) {
! 8020: document.getElementById("'.$id.'").style.width = "auto";
! 8021: document.getElementById("'.$id.'").style.height = "auto";
! 8022: }
! 8023: }
! 8024: }
! 8025: } catch (e) {
! 8026: return;
! 8027: }
1.1137 raeburn 8028: }
1.1140 ! raeburn 8029: return;
1.996 www 8030: }
1.1140 ! raeburn 8031: ';
! 8032: }
! 8033: if ($needjsready) {
! 8034: $nicescroll_js = '
! 8035: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
! 8036: } else {
! 8037: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
! 8038: }
! 8039: return $nicescroll_js;
1.996 www 8040: }
8041:
1.318 albertel 8042: sub simple_error_page {
8043: my ($r,$title,$msg) = @_;
8044: my $page =
8045: &Apache::loncommon::start_page($title).
1.1097 bisitz 8046: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 8047: &Apache::loncommon::end_page();
8048: if (ref($r)) {
8049: $r->print($page);
1.327 albertel 8050: return;
1.318 albertel 8051: }
8052: return $page;
8053: }
1.347 albertel 8054:
8055: {
1.610 albertel 8056: my @row_count;
1.961 onken 8057:
8058: sub start_data_table_count {
8059: unshift(@row_count, 0);
8060: return;
8061: }
8062:
8063: sub end_data_table_count {
8064: shift(@row_count);
8065: return;
8066: }
8067:
1.347 albertel 8068: sub start_data_table {
1.1018 raeburn 8069: my ($add_class,$id) = @_;
1.422 albertel 8070: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8071: my $table_id;
8072: if (defined($id)) {
8073: $table_id = ' id="'.$id.'"';
8074: }
1.961 onken 8075: &start_data_table_count();
1.1018 raeburn 8076: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8077: }
8078:
8079: sub end_data_table {
1.961 onken 8080: &end_data_table_count();
1.389 albertel 8081: return '</table>'."\n";;
1.347 albertel 8082: }
8083:
8084: sub start_data_table_row {
1.974 wenzelju 8085: my ($add_class, $id) = @_;
1.610 albertel 8086: $row_count[0]++;
8087: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8088: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8089: $id = (' id="'.$id.'"') unless ($id eq '');
8090: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8091: }
1.471 banghart 8092:
8093: sub continue_data_table_row {
1.974 wenzelju 8094: my ($add_class, $id) = @_;
1.610 albertel 8095: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8096: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8097: $id = (' id="'.$id.'"') unless ($id eq '');
8098: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8099: }
1.347 albertel 8100:
8101: sub end_data_table_row {
1.389 albertel 8102: return '</tr>'."\n";;
1.347 albertel 8103: }
1.367 www 8104:
1.421 albertel 8105: sub start_data_table_empty_row {
1.707 bisitz 8106: # $row_count[0]++;
1.421 albertel 8107: return '<tr class="LC_empty_row" >'."\n";;
8108: }
8109:
8110: sub end_data_table_empty_row {
8111: return '</tr>'."\n";;
8112: }
8113:
1.367 www 8114: sub start_data_table_header_row {
1.389 albertel 8115: return '<tr class="LC_header_row">'."\n";;
1.367 www 8116: }
8117:
8118: sub end_data_table_header_row {
1.389 albertel 8119: return '</tr>'."\n";;
1.367 www 8120: }
1.890 droeschl 8121:
8122: sub data_table_caption {
8123: my $caption = shift;
8124: return "<caption class=\"LC_caption\">$caption</caption>";
8125: }
1.347 albertel 8126: }
8127:
1.548 albertel 8128: =pod
8129:
8130: =item * &inhibit_menu_check($arg)
8131:
8132: Checks for a inhibitmenu state and generates output to preserve it
8133:
8134: Inputs: $arg - can be any of
8135: - undef - in which case the return value is a string
8136: to add into arguments list of a uri
8137: - 'input' - in which case the return value is a HTML
8138: <form> <input> field of type hidden to
8139: preserve the value
8140: - a url - in which case the return value is the url with
8141: the neccesary cgi args added to preserve the
8142: inhibitmenu state
8143: - a ref to a url - no return value, but the string is
8144: updated to include the neccessary cgi
8145: args to preserve the inhibitmenu state
8146:
8147: =cut
8148:
8149: sub inhibit_menu_check {
8150: my ($arg) = @_;
8151: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8152: if ($arg eq 'input') {
8153: if ($env{'form.inhibitmenu'}) {
8154: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8155: } else {
8156: return
8157: }
8158: }
8159: if ($env{'form.inhibitmenu'}) {
8160: if (ref($arg)) {
8161: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8162: } elsif ($arg eq '') {
8163: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8164: } else {
8165: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8166: }
8167: }
8168: if (!ref($arg)) {
8169: return $arg;
8170: }
8171: }
8172:
1.251 albertel 8173: ###############################################
1.182 matthew 8174:
8175: =pod
8176:
1.549 albertel 8177: =back
8178:
8179: =head1 User Information Routines
8180:
8181: =over 4
8182:
1.405 albertel 8183: =item * &get_users_function()
1.182 matthew 8184:
8185: Used by &bodytag to determine the current users primary role.
8186: Returns either 'student','coordinator','admin', or 'author'.
8187:
8188: =cut
8189:
8190: ###############################################
8191: sub get_users_function {
1.815 tempelho 8192: my $function = 'norole';
1.818 tempelho 8193: if ($env{'request.role'}=~/^(st)/) {
8194: $function='student';
8195: }
1.907 raeburn 8196: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8197: $function='coordinator';
8198: }
1.258 albertel 8199: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8200: $function='admin';
8201: }
1.826 bisitz 8202: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8203: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8204: $function='author';
8205: }
8206: return $function;
1.54 www 8207: }
1.99 www 8208:
8209: ###############################################
8210:
1.233 raeburn 8211: =pod
8212:
1.821 raeburn 8213: =item * &show_course()
8214:
8215: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8216: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8217:
8218: Inputs:
8219: None
8220:
8221: Outputs:
8222: Scalar: 1 if 'Course' to be used, 0 otherwise.
8223:
8224: =cut
8225:
8226: ###############################################
8227: sub show_course {
8228: my $course = !$env{'user.adv'};
8229: if (!$env{'user.adv'}) {
8230: foreach my $env (keys(%env)) {
8231: next if ($env !~ m/^user\.priv\./);
8232: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8233: $course = 0;
8234: last;
8235: }
8236: }
8237: }
8238: return $course;
8239: }
8240:
8241: ###############################################
8242:
8243: =pod
8244:
1.542 raeburn 8245: =item * &check_user_status()
1.274 raeburn 8246:
8247: Determines current status of supplied role for a
8248: specific user. Roles can be active, previous or future.
8249:
8250: Inputs:
8251: user's domain, user's username, course's domain,
1.375 raeburn 8252: course's number, optional section ID.
1.274 raeburn 8253:
8254: Outputs:
8255: role status: active, previous or future.
8256:
8257: =cut
8258:
8259: sub check_user_status {
1.412 raeburn 8260: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8261: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8262: my @uroles = keys %userinfo;
8263: my $srchstr;
8264: my $active_chk = 'none';
1.412 raeburn 8265: my $now = time;
1.274 raeburn 8266: if (@uroles > 0) {
1.908 raeburn 8267: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8268: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8269: } else {
1.412 raeburn 8270: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8271: }
8272: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8273: my $role_end = 0;
8274: my $role_start = 0;
8275: $active_chk = 'active';
1.412 raeburn 8276: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8277: $role_end = $1;
8278: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8279: $role_start = $1;
1.274 raeburn 8280: }
8281: }
8282: if ($role_start > 0) {
1.412 raeburn 8283: if ($now < $role_start) {
1.274 raeburn 8284: $active_chk = 'future';
8285: }
8286: }
8287: if ($role_end > 0) {
1.412 raeburn 8288: if ($now > $role_end) {
1.274 raeburn 8289: $active_chk = 'previous';
8290: }
8291: }
8292: }
8293: }
8294: return $active_chk;
8295: }
8296:
8297: ###############################################
8298:
8299: =pod
8300:
1.405 albertel 8301: =item * &get_sections()
1.233 raeburn 8302:
8303: Determines all the sections for a course including
8304: sections with students and sections containing other roles.
1.419 raeburn 8305: Incoming parameters:
8306:
8307: 1. domain
8308: 2. course number
8309: 3. reference to array containing roles for which sections should
8310: be gathered (optional).
8311: 4. reference to array containing status types for which sections
8312: should be gathered (optional).
8313:
8314: If the third argument is undefined, sections are gathered for any role.
8315: If the fourth argument is undefined, sections are gathered for any status.
8316: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8317:
1.374 raeburn 8318: Returns section hash (keys are section IDs, values are
8319: number of users in each section), subject to the
1.419 raeburn 8320: optional roles filter, optional status filter
1.233 raeburn 8321:
8322: =cut
8323:
8324: ###############################################
8325: sub get_sections {
1.419 raeburn 8326: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8327: if (!defined($cdom) || !defined($cnum)) {
8328: my $cid = $env{'request.course.id'};
8329:
8330: return if (!defined($cid));
8331:
8332: $cdom = $env{'course.'.$cid.'.domain'};
8333: $cnum = $env{'course.'.$cid.'.num'};
8334: }
8335:
8336: my %sectioncount;
1.419 raeburn 8337: my $now = time;
1.240 albertel 8338:
1.1118 raeburn 8339: my $check_students = 1;
8340: my $only_students = 0;
8341: if (ref($possible_roles) eq 'ARRAY') {
8342: if (grep(/^st$/,@{$possible_roles})) {
8343: if (@{$possible_roles} == 1) {
8344: $only_students = 1;
8345: }
8346: } else {
8347: $check_students = 0;
8348: }
8349: }
8350:
8351: if ($check_students) {
1.276 albertel 8352: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8353: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8354: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8355: my $start_index = &Apache::loncoursedata::CL_START();
8356: my $end_index = &Apache::loncoursedata::CL_END();
8357: my $status;
1.366 albertel 8358: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8359: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8360: $data->[$status_index],
8361: $data->[$start_index],
8362: $data->[$end_index]);
8363: if ($stu_status eq 'Active') {
8364: $status = 'active';
8365: } elsif ($end < $now) {
8366: $status = 'previous';
8367: } elsif ($start > $now) {
8368: $status = 'future';
8369: }
8370: if ($section ne '-1' && $section !~ /^\s*$/) {
8371: if ((!defined($possible_status)) || (($status ne '') &&
8372: (grep/^\Q$status\E$/,@{$possible_status}))) {
8373: $sectioncount{$section}++;
8374: }
1.240 albertel 8375: }
8376: }
8377: }
1.1118 raeburn 8378: if ($only_students) {
8379: return %sectioncount;
8380: }
1.240 albertel 8381: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8382: foreach my $user (sort(keys(%courseroles))) {
8383: if ($user !~ /^(\w{2})/) { next; }
8384: my ($role) = ($user =~ /^(\w{2})/);
8385: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8386: my ($section,$status);
1.240 albertel 8387: if ($role eq 'cr' &&
8388: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8389: $section=$1;
8390: }
8391: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8392: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8393: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8394: if ($end == -1 && $start == -1) {
8395: next; #deleted role
8396: }
8397: if (!defined($possible_status)) {
8398: $sectioncount{$section}++;
8399: } else {
8400: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8401: $status = 'active';
8402: } elsif ($end < $now) {
8403: $status = 'future';
8404: } elsif ($start > $now) {
8405: $status = 'previous';
8406: }
8407: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8408: $sectioncount{$section}++;
8409: }
8410: }
1.233 raeburn 8411: }
1.366 albertel 8412: return %sectioncount;
1.233 raeburn 8413: }
8414:
1.274 raeburn 8415: ###############################################
1.294 raeburn 8416:
8417: =pod
1.405 albertel 8418:
8419: =item * &get_course_users()
8420:
1.275 raeburn 8421: Retrieves usernames:domains for users in the specified course
8422: with specific role(s), and access status.
8423:
8424: Incoming parameters:
1.277 albertel 8425: 1. course domain
8426: 2. course number
8427: 3. access status: users must have - either active,
1.275 raeburn 8428: previous, future, or all.
1.277 albertel 8429: 4. reference to array of permissible roles
1.288 raeburn 8430: 5. reference to array of section restrictions (optional)
8431: 6. reference to results object (hash of hashes).
8432: 7. reference to optional userdata hash
1.609 raeburn 8433: 8. reference to optional statushash
1.630 raeburn 8434: 9. flag if privileged users (except those set to unhide in
8435: course settings) should be excluded
1.609 raeburn 8436: Keys of top level results hash are roles.
1.275 raeburn 8437: Keys of inner hashes are username:domain, with
8438: values set to access type.
1.288 raeburn 8439: Optional userdata hash returns an array with arguments in the
8440: same order as loncoursedata::get_classlist() for student data.
8441:
1.609 raeburn 8442: Optional statushash returns
8443:
1.288 raeburn 8444: Entries for end, start, section and status are blank because
8445: of the possibility of multiple values for non-student roles.
8446:
1.275 raeburn 8447: =cut
1.405 albertel 8448:
1.275 raeburn 8449: ###############################################
1.405 albertel 8450:
1.275 raeburn 8451: sub get_course_users {
1.630 raeburn 8452: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8453: my %idx = ();
1.419 raeburn 8454: my %seclists;
1.288 raeburn 8455:
8456: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8457: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8458: $idx{end} = &Apache::loncoursedata::CL_END();
8459: $idx{start} = &Apache::loncoursedata::CL_START();
8460: $idx{id} = &Apache::loncoursedata::CL_ID();
8461: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8462: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8463: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8464:
1.290 albertel 8465: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8466: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8467: my $now = time;
1.277 albertel 8468: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8469: my $match = 0;
1.412 raeburn 8470: my $secmatch = 0;
1.419 raeburn 8471: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8472: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8473: if ($section eq '') {
8474: $section = 'none';
8475: }
1.291 albertel 8476: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8477: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8478: $secmatch = 1;
8479: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8480: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8481: $secmatch = 1;
8482: }
8483: } else {
1.419 raeburn 8484: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8485: $secmatch = 1;
8486: }
1.290 albertel 8487: }
1.412 raeburn 8488: if (!$secmatch) {
8489: next;
8490: }
1.419 raeburn 8491: }
1.275 raeburn 8492: if (defined($$types{'active'})) {
1.288 raeburn 8493: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8494: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8495: $match = 1;
1.275 raeburn 8496: }
8497: }
8498: if (defined($$types{'previous'})) {
1.609 raeburn 8499: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8500: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8501: $match = 1;
1.275 raeburn 8502: }
8503: }
8504: if (defined($$types{'future'})) {
1.609 raeburn 8505: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8506: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8507: $match = 1;
1.275 raeburn 8508: }
8509: }
1.609 raeburn 8510: if ($match) {
8511: push(@{$seclists{$student}},$section);
8512: if (ref($userdata) eq 'HASH') {
8513: $$userdata{$student} = $$classlist{$student};
8514: }
8515: if (ref($statushash) eq 'HASH') {
8516: $statushash->{$student}{'st'}{$section} = $status;
8517: }
1.288 raeburn 8518: }
1.275 raeburn 8519: }
8520: }
1.412 raeburn 8521: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8522: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8523: my $now = time;
1.609 raeburn 8524: my %displaystatus = ( previous => 'Expired',
8525: active => 'Active',
8526: future => 'Future',
8527: );
1.1121 raeburn 8528: my (%nothide,@possdoms);
1.630 raeburn 8529: if ($hidepriv) {
8530: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8531: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8532: if ($user !~ /:/) {
8533: $nothide{join(':',split(/[\@]/,$user))}=1;
8534: } else {
8535: $nothide{$user} = 1;
8536: }
8537: }
1.1121 raeburn 8538: my @possdoms = ($cdom);
8539: if ($coursehash{'checkforpriv'}) {
8540: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8541: }
1.630 raeburn 8542: }
1.439 raeburn 8543: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8544: my $match = 0;
1.412 raeburn 8545: my $secmatch = 0;
1.439 raeburn 8546: my $status;
1.412 raeburn 8547: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8548: $user =~ s/:$//;
1.439 raeburn 8549: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8550: if ($end == -1 || $start == -1) {
8551: next;
8552: }
8553: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8554: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8555: my ($uname,$udom) = split(/:/,$user);
8556: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8557: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8558: $secmatch = 1;
8559: } elsif ($usec eq '') {
1.420 albertel 8560: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8561: $secmatch = 1;
8562: }
8563: } else {
8564: if (grep(/^\Q$usec\E$/,@{$sections})) {
8565: $secmatch = 1;
8566: }
8567: }
8568: if (!$secmatch) {
8569: next;
8570: }
1.288 raeburn 8571: }
1.419 raeburn 8572: if ($usec eq '') {
8573: $usec = 'none';
8574: }
1.275 raeburn 8575: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8576: if ($hidepriv) {
1.1121 raeburn 8577: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8578: (!$nothide{$uname.':'.$udom})) {
8579: next;
8580: }
8581: }
1.503 raeburn 8582: if ($end > 0 && $end < $now) {
1.439 raeburn 8583: $status = 'previous';
8584: } elsif ($start > $now) {
8585: $status = 'future';
8586: } else {
8587: $status = 'active';
8588: }
1.277 albertel 8589: foreach my $type (keys(%{$types})) {
1.275 raeburn 8590: if ($status eq $type) {
1.420 albertel 8591: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8592: push(@{$$users{$role}{$user}},$type);
8593: }
1.288 raeburn 8594: $match = 1;
8595: }
8596: }
1.419 raeburn 8597: if (($match) && (ref($userdata) eq 'HASH')) {
8598: if (!exists($$userdata{$uname.':'.$udom})) {
8599: &get_user_info($udom,$uname,\%idx,$userdata);
8600: }
1.420 albertel 8601: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8602: push(@{$seclists{$uname.':'.$udom}},$usec);
8603: }
1.609 raeburn 8604: if (ref($statushash) eq 'HASH') {
8605: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8606: }
1.275 raeburn 8607: }
8608: }
8609: }
8610: }
1.290 albertel 8611: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8612: if ((defined($cdom)) && (defined($cnum))) {
8613: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8614: if ( defined($csettings{'internal.courseowner'}) ) {
8615: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8616: next if ($owner eq '');
8617: my ($ownername,$ownerdom);
8618: if ($owner =~ /^([^:]+):([^:]+)$/) {
8619: $ownername = $1;
8620: $ownerdom = $2;
8621: } else {
8622: $ownername = $owner;
8623: $ownerdom = $cdom;
8624: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8625: }
8626: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8627: if (defined($userdata) &&
1.609 raeburn 8628: !exists($$userdata{$owner})) {
8629: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8630: if (!grep(/^none$/,@{$seclists{$owner}})) {
8631: push(@{$seclists{$owner}},'none');
8632: }
8633: if (ref($statushash) eq 'HASH') {
8634: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8635: }
1.290 albertel 8636: }
1.279 raeburn 8637: }
8638: }
8639: }
1.419 raeburn 8640: foreach my $user (keys(%seclists)) {
8641: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8642: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8643: }
1.275 raeburn 8644: }
8645: return;
8646: }
8647:
1.288 raeburn 8648: sub get_user_info {
8649: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8650: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8651: &plainname($uname,$udom,'lastname');
1.291 albertel 8652: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8653: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8654: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8655: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8656: return;
8657: }
1.275 raeburn 8658:
1.472 raeburn 8659: ###############################################
8660:
8661: =pod
8662:
8663: =item * &get_user_quota()
8664:
1.1134 raeburn 8665: Retrieves quota assigned for storage of user files.
8666: Default is to report quota for portfolio files.
1.472 raeburn 8667:
8668: Incoming parameters:
8669: 1. user's username
8670: 2. user's domain
1.1134 raeburn 8671: 3. quota name - portfolio, author, or course
1.1136 raeburn 8672: (if no quota name provided, defaults to portfolio).
8673: 4. crstype - official, unofficial or community, if quota name is
8674: course
1.472 raeburn 8675:
8676: Returns:
1.536 raeburn 8677: 1. Disk quota (in Mb) assigned to student.
8678: 2. (Optional) Type of setting: custom or default
8679: (individually assigned or default for user's
8680: institutional status).
8681: 3. (Optional) - User's institutional status (e.g., faculty, staff
8682: or student - types as defined in localenroll::inst_usertypes
8683: for user's domain, which determines default quota for user.
8684: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8685:
8686: If a value has been stored in the user's environment,
1.536 raeburn 8687: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8688: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8689:
8690: =cut
8691:
8692: ###############################################
8693:
8694:
8695: sub get_user_quota {
1.1136 raeburn 8696: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8697: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8698: if (!defined($udom)) {
8699: $udom = $env{'user.domain'};
8700: }
8701: if (!defined($uname)) {
8702: $uname = $env{'user.name'};
8703: }
8704: if (($udom eq '' || $uname eq '') ||
8705: ($udom eq 'public') && ($uname eq 'public')) {
8706: $quota = 0;
1.536 raeburn 8707: $quotatype = 'default';
8708: $defquota = 0;
1.472 raeburn 8709: } else {
1.536 raeburn 8710: my $inststatus;
1.1134 raeburn 8711: if ($quotaname eq 'course') {
8712: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8713: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8714: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8715: } else {
8716: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8717: $quota = $cenv{'internal.uploadquota'};
8718: }
1.536 raeburn 8719: } else {
1.1134 raeburn 8720: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8721: if ($quotaname eq 'author') {
8722: $quota = $env{'environment.authorquota'};
8723: } else {
8724: $quota = $env{'environment.portfolioquota'};
8725: }
8726: $inststatus = $env{'environment.inststatus'};
8727: } else {
8728: my %userenv =
8729: &Apache::lonnet::get('environment',['portfolioquota',
8730: 'authorquota','inststatus'],$udom,$uname);
8731: my ($tmp) = keys(%userenv);
8732: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8733: if ($quotaname eq 'author') {
8734: $quota = $userenv{'authorquota'};
8735: } else {
8736: $quota = $userenv{'portfolioquota'};
8737: }
8738: $inststatus = $userenv{'inststatus'};
8739: } else {
8740: undef(%userenv);
8741: }
8742: }
8743: }
8744: if ($quota eq '' || wantarray) {
8745: if ($quotaname eq 'course') {
8746: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1136 raeburn 8747: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8748: $defquota = $domdefs{$crstype.'quota'};
8749: }
8750: if ($defquota eq '') {
8751: $defquota = 500;
8752: }
1.1134 raeburn 8753: } else {
8754: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8755: }
8756: if ($quota eq '') {
8757: $quota = $defquota;
8758: $quotatype = 'default';
8759: } else {
8760: $quotatype = 'custom';
8761: }
1.472 raeburn 8762: }
8763: }
1.536 raeburn 8764: if (wantarray) {
8765: return ($quota,$quotatype,$settingstatus,$defquota);
8766: } else {
8767: return $quota;
8768: }
1.472 raeburn 8769: }
8770:
8771: ###############################################
8772:
8773: =pod
8774:
8775: =item * &default_quota()
8776:
1.536 raeburn 8777: Retrieves default quota assigned for storage of user portfolio files,
8778: given an (optional) user's institutional status.
1.472 raeburn 8779:
8780: Incoming parameters:
8781: 1. domain
1.536 raeburn 8782: 2. (Optional) institutional status(es). This is a : separated list of
8783: status types (e.g., faculty, staff, student etc.)
8784: which apply to the user for whom the default is being retrieved.
8785: If the institutional status string in undefined, the domain
1.1134 raeburn 8786: default quota will be returned.
8787: 3. quota name - portfolio, author, or course
8788: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8789:
8790: Returns:
8791: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8792: 2. (Optional) institutional type which determined the value of the
8793: default quota.
1.472 raeburn 8794:
8795: If a value has been stored in the domain's configuration db,
8796: it will return that, otherwise it returns 20 (for backwards
8797: compatibility with domains which have not set up a configuration
8798: db file; the original statically defined portfolio quota was 20 Mb).
8799:
1.536 raeburn 8800: If the user's status includes multiple types (e.g., staff and student),
8801: the largest default quota which applies to the user determines the
8802: default quota returned.
8803:
1.780 raeburn 8804: =back
8805:
1.472 raeburn 8806: =cut
8807:
8808: ###############################################
8809:
8810:
8811: sub default_quota {
1.1134 raeburn 8812: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8813: my ($defquota,$settingstatus);
8814: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8815: ['quotas'],$udom);
1.1134 raeburn 8816: my $key = 'defaultquota';
8817: if ($quotaname eq 'author') {
8818: $key = 'authorquota';
8819: }
1.622 raeburn 8820: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8821: if ($inststatus ne '') {
1.765 raeburn 8822: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8823: foreach my $item (@statuses) {
1.1134 raeburn 8824: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8825: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8826: if ($defquota eq '') {
1.1134 raeburn 8827: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8828: $settingstatus = $item;
1.1134 raeburn 8829: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8830: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8831: $settingstatus = $item;
8832: }
8833: }
1.1134 raeburn 8834: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8835: if ($quotahash{'quotas'}{$item} ne '') {
8836: if ($defquota eq '') {
8837: $defquota = $quotahash{'quotas'}{$item};
8838: $settingstatus = $item;
8839: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8840: $defquota = $quotahash{'quotas'}{$item};
8841: $settingstatus = $item;
8842: }
1.536 raeburn 8843: }
8844: }
8845: }
8846: }
8847: if ($defquota eq '') {
1.1134 raeburn 8848: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8849: $defquota = $quotahash{'quotas'}{$key}{'default'};
8850: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8851: $defquota = $quotahash{'quotas'}{'default'};
8852: }
1.536 raeburn 8853: $settingstatus = 'default';
1.1139 raeburn 8854: if ($defquota eq '') {
8855: if ($quotaname eq 'author') {
8856: $defquota = 500;
8857: }
8858: }
1.536 raeburn 8859: }
8860: } else {
8861: $settingstatus = 'default';
1.1134 raeburn 8862: if ($quotaname eq 'author') {
8863: $defquota = 500;
8864: } else {
8865: $defquota = 20;
8866: }
1.536 raeburn 8867: }
8868: if (wantarray) {
8869: return ($defquota,$settingstatus);
1.472 raeburn 8870: } else {
1.536 raeburn 8871: return $defquota;
1.472 raeburn 8872: }
8873: }
8874:
1.1135 raeburn 8875: ###############################################
8876:
8877: =pod
8878:
1.1136 raeburn 8879: =item * &excess_filesize_warning()
1.1135 raeburn 8880:
8881: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8882: of existing file within authoring space will cause quota for the authoring
8883: space to be exceeded,
8884:
8885: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8886: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8887:
8888: Inputs: 6
1.1136 raeburn 8889: 1. username or coursenum
1.1135 raeburn 8890: 2. domain
1.1136 raeburn 8891: 3. context ('author' or 'course')
1.1135 raeburn 8892: 4. filename of file for which action is being requested
8893: 5. filesize (kB) of file
8894: 6. action being taken: copy or upload.
8895:
8896: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8897: otherwise return null.
8898:
8899: =cut
8900:
1.1136 raeburn 8901: sub excess_filesize_warning {
8902: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8903: my $current_disk_usage = 0;
8904: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8905: if ($context eq 'author') {
8906: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8907: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8908: } else {
8909: foreach my $subdir ('docs','supplemental') {
8910: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8911: }
8912: }
1.1135 raeburn 8913: $disk_quota = int($disk_quota * 1000);
8914: if (($current_disk_usage + $filesize) > $disk_quota) {
8915: return '<p><span class="LC_warning">'.
8916: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8917: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8918: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8919: $disk_quota,$current_disk_usage).
8920: '</p>';
8921: }
8922: return;
8923: }
8924:
8925: ###############################################
8926:
8927:
1.1136 raeburn 8928:
8929:
1.384 raeburn 8930: sub get_secgrprole_info {
8931: my ($cdom,$cnum,$needroles,$type) = @_;
8932: my %sections_count = &get_sections($cdom,$cnum);
8933: my @sections = (sort {$a <=> $b} keys(%sections_count));
8934: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8935: my @groups = sort(keys(%curr_groups));
8936: my $allroles = [];
8937: my $rolehash;
8938: my $accesshash = {
8939: active => 'Currently has access',
8940: future => 'Will have future access',
8941: previous => 'Previously had access',
8942: };
8943: if ($needroles) {
8944: $rolehash = {'all' => 'all'};
1.385 albertel 8945: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8946: if (&Apache::lonnet::error(%user_roles)) {
8947: undef(%user_roles);
8948: }
8949: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8950: my ($role)=split(/\:/,$item,2);
8951: if ($role eq 'cr') { next; }
8952: if ($role =~ /^cr/) {
8953: $$rolehash{$role} = (split('/',$role))[3];
8954: } else {
8955: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8956: }
8957: }
8958: foreach my $key (sort(keys(%{$rolehash}))) {
8959: push(@{$allroles},$key);
8960: }
8961: push (@{$allroles},'st');
8962: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8963: }
8964: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8965: }
8966:
1.555 raeburn 8967: sub user_picker {
1.994 raeburn 8968: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8969: my $currdom = $dom;
8970: my %curr_selected = (
8971: srchin => 'dom',
1.580 raeburn 8972: srchby => 'lastname',
1.555 raeburn 8973: );
8974: my $srchterm;
1.625 raeburn 8975: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8976: if ($srch->{'srchby'} ne '') {
8977: $curr_selected{'srchby'} = $srch->{'srchby'};
8978: }
8979: if ($srch->{'srchin'} ne '') {
8980: $curr_selected{'srchin'} = $srch->{'srchin'};
8981: }
8982: if ($srch->{'srchtype'} ne '') {
8983: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8984: }
8985: if ($srch->{'srchdomain'} ne '') {
8986: $currdom = $srch->{'srchdomain'};
8987: }
8988: $srchterm = $srch->{'srchterm'};
8989: }
8990: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8991: 'usr' => 'Search criteria',
1.563 raeburn 8992: 'doma' => 'Domain/institution to search',
1.558 albertel 8993: 'uname' => 'username',
8994: 'lastname' => 'last name',
1.555 raeburn 8995: 'lastfirst' => 'last name, first name',
1.558 albertel 8996: 'crs' => 'in this course',
1.576 raeburn 8997: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8998: 'alc' => 'all LON-CAPA',
1.573 raeburn 8999: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9000: 'exact' => 'is',
9001: 'contains' => 'contains',
1.569 raeburn 9002: 'begins' => 'begins with',
1.571 raeburn 9003: 'youm' => "You must include some text to search for.",
9004: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9005: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9006: 'yomc' => "You must choose a domain when using an institutional directory search.",
9007: 'ymcd' => "You must choose a domain when using a domain search.",
9008: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9009: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9010: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9011: );
1.563 raeburn 9012: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9013: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9014:
9015: my @srchins = ('crs','dom','alc','instd');
9016:
9017: foreach my $option (@srchins) {
9018: # FIXME 'alc' option unavailable until
9019: # loncreateuser::print_user_query_page()
9020: # has been completed.
9021: next if ($option eq 'alc');
1.880 raeburn 9022: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9023: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9024: if ($curr_selected{'srchin'} eq $option) {
9025: $srchinsel .= '
9026: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9027: } else {
9028: $srchinsel .= '
9029: <option value="'.$option.'">'.$lt{$option}.'</option>';
9030: }
1.555 raeburn 9031: }
1.563 raeburn 9032: $srchinsel .= "\n </select>\n";
1.555 raeburn 9033:
9034: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9035: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9036: if ($curr_selected{'srchby'} eq $option) {
9037: $srchbysel .= '
9038: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9039: } else {
9040: $srchbysel .= '
9041: <option value="'.$option.'">'.$lt{$option}.'</option>';
9042: }
9043: }
9044: $srchbysel .= "\n </select>\n";
9045:
9046: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9047: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9048: if ($curr_selected{'srchtype'} eq $option) {
9049: $srchtypesel .= '
9050: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9051: } else {
9052: $srchtypesel .= '
9053: <option value="'.$option.'">'.$lt{$option}.'</option>';
9054: }
9055: }
9056: $srchtypesel .= "\n </select>\n";
9057:
1.558 albertel 9058: my ($newuserscript,$new_user_create);
1.994 raeburn 9059: my $context_dom = $env{'request.role.domain'};
9060: if ($context eq 'requestcrs') {
9061: if ($env{'form.coursedom'} ne '') {
9062: $context_dom = $env{'form.coursedom'};
9063: }
9064: }
1.556 raeburn 9065: if ($forcenewuser) {
1.576 raeburn 9066: if (ref($srch) eq 'HASH') {
1.994 raeburn 9067: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9068: if ($cancreate) {
9069: $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>';
9070: } else {
1.799 bisitz 9071: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9072: my %usertypetext = (
9073: official => 'institutional',
9074: unofficial => 'non-institutional',
9075: );
1.799 bisitz 9076: $new_user_create = '<p class="LC_warning">'
9077: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9078: .' '
9079: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9080: ,'<a href="'.$helplink.'">','</a>')
9081: .'</p><br />';
1.627 raeburn 9082: }
1.576 raeburn 9083: }
9084: }
9085:
1.556 raeburn 9086: $newuserscript = <<"ENDSCRIPT";
9087:
1.570 raeburn 9088: function setSearch(createnew,callingForm) {
1.556 raeburn 9089: if (createnew == 1) {
1.570 raeburn 9090: for (var i=0; i<callingForm.srchby.length; i++) {
9091: if (callingForm.srchby.options[i].value == 'uname') {
9092: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9093: }
9094: }
1.570 raeburn 9095: for (var i=0; i<callingForm.srchin.length; i++) {
9096: if ( callingForm.srchin.options[i].value == 'dom') {
9097: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9098: }
9099: }
1.570 raeburn 9100: for (var i=0; i<callingForm.srchtype.length; i++) {
9101: if (callingForm.srchtype.options[i].value == 'exact') {
9102: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9103: }
9104: }
1.570 raeburn 9105: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9106: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9107: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9108: }
9109: }
9110: }
9111: }
9112: ENDSCRIPT
1.558 albertel 9113:
1.556 raeburn 9114: }
9115:
1.555 raeburn 9116: my $output = <<"END_BLOCK";
1.556 raeburn 9117: <script type="text/javascript">
1.824 bisitz 9118: // <![CDATA[
1.570 raeburn 9119: function validateEntry(callingForm) {
1.558 albertel 9120:
1.556 raeburn 9121: var checkok = 1;
1.558 albertel 9122: var srchin;
1.570 raeburn 9123: for (var i=0; i<callingForm.srchin.length; i++) {
9124: if ( callingForm.srchin[i].checked ) {
9125: srchin = callingForm.srchin[i].value;
1.558 albertel 9126: }
9127: }
9128:
1.570 raeburn 9129: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9130: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9131: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9132: var srchterm = callingForm.srchterm.value;
9133: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9134: var msg = "";
9135:
9136: if (srchterm == "") {
9137: checkok = 0;
1.571 raeburn 9138: msg += "$lt{'youm'}\\n";
1.556 raeburn 9139: }
9140:
1.569 raeburn 9141: if (srchtype== 'begins') {
9142: if (srchterm.length < 2) {
9143: checkok = 0;
1.571 raeburn 9144: msg += "$lt{'thte'}\\n";
1.569 raeburn 9145: }
9146: }
9147:
1.556 raeburn 9148: if (srchtype== 'contains') {
9149: if (srchterm.length < 3) {
9150: checkok = 0;
1.571 raeburn 9151: msg += "$lt{'thet'}\\n";
1.556 raeburn 9152: }
9153: }
9154: if (srchin == 'instd') {
9155: if (srchdomain == '') {
9156: checkok = 0;
1.571 raeburn 9157: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9158: }
9159: }
9160: if (srchin == 'dom') {
9161: if (srchdomain == '') {
9162: checkok = 0;
1.571 raeburn 9163: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9164: }
9165: }
9166: if (srchby == 'lastfirst') {
9167: if (srchterm.indexOf(",") == -1) {
9168: checkok = 0;
1.571 raeburn 9169: msg += "$lt{'whus'}\\n";
1.556 raeburn 9170: }
9171: if (srchterm.indexOf(",") == srchterm.length -1) {
9172: checkok = 0;
1.571 raeburn 9173: msg += "$lt{'whse'}\\n";
1.556 raeburn 9174: }
9175: }
9176: if (checkok == 0) {
1.571 raeburn 9177: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9178: return;
9179: }
9180: if (checkok == 1) {
1.570 raeburn 9181: callingForm.submit();
1.556 raeburn 9182: }
9183: }
9184:
9185: $newuserscript
9186:
1.824 bisitz 9187: // ]]>
1.556 raeburn 9188: </script>
1.558 albertel 9189:
9190: $new_user_create
9191:
1.555 raeburn 9192: END_BLOCK
1.558 albertel 9193:
1.876 raeburn 9194: $output .= &Apache::lonhtmlcommon::start_pick_box().
9195: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9196: $domform.
9197: &Apache::lonhtmlcommon::row_closure().
9198: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9199: $srchbysel.
9200: $srchtypesel.
9201: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9202: $srchinsel.
9203: &Apache::lonhtmlcommon::row_closure(1).
9204: &Apache::lonhtmlcommon::end_pick_box().
9205: '<br />';
1.555 raeburn 9206: return $output;
9207: }
9208:
1.612 raeburn 9209: sub user_rule_check {
1.615 raeburn 9210: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9211: my $response;
9212: if (ref($usershash) eq 'HASH') {
9213: foreach my $user (keys(%{$usershash})) {
9214: my ($uname,$udom) = split(/:/,$user);
9215: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9216: my ($id,$newuser);
1.612 raeburn 9217: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9218: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9219: $id = $usershash->{$user}->{'id'};
9220: }
9221: my $inst_response;
9222: if (ref($checks) eq 'HASH') {
9223: if (defined($checks->{'username'})) {
1.615 raeburn 9224: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9225: &Apache::lonnet::get_instuser($udom,$uname);
9226: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9227: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9228: &Apache::lonnet::get_instuser($udom,undef,$id);
9229: }
1.615 raeburn 9230: } else {
9231: ($inst_response,%{$inst_results->{$user}}) =
9232: &Apache::lonnet::get_instuser($udom,$uname);
9233: return;
1.612 raeburn 9234: }
1.615 raeburn 9235: if (!$got_rules->{$udom}) {
1.612 raeburn 9236: my %domconfig = &Apache::lonnet::get_dom('configuration',
9237: ['usercreation'],$udom);
9238: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9239: foreach my $item ('username','id') {
1.612 raeburn 9240: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9241: $$curr_rules{$udom}{$item} =
9242: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9243: }
9244: }
9245: }
1.615 raeburn 9246: $got_rules->{$udom} = 1;
1.585 raeburn 9247: }
1.612 raeburn 9248: foreach my $item (keys(%{$checks})) {
9249: if (ref($$curr_rules{$udom}) eq 'HASH') {
9250: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9251: if (@{$$curr_rules{$udom}{$item}} > 0) {
9252: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9253: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9254: if ($rule_check{$rule}) {
9255: $$rulematch{$user}{$item} = $rule;
9256: if ($inst_response eq 'ok') {
1.615 raeburn 9257: if (ref($inst_results) eq 'HASH') {
9258: if (ref($inst_results->{$user}) eq 'HASH') {
9259: if (keys(%{$inst_results->{$user}}) == 0) {
9260: $$alerts{$item}{$udom}{$uname} = 1;
9261: }
1.612 raeburn 9262: }
9263: }
1.615 raeburn 9264: }
9265: last;
1.585 raeburn 9266: }
9267: }
9268: }
9269: }
9270: }
9271: }
9272: }
9273: }
1.612 raeburn 9274: return;
9275: }
9276:
9277: sub user_rule_formats {
9278: my ($domain,$domdesc,$curr_rules,$check) = @_;
9279: my %text = (
9280: 'username' => 'Usernames',
9281: 'id' => 'IDs',
9282: );
9283: my $output;
9284: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9285: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9286: if (@{$ruleorder} > 0) {
1.1102 raeburn 9287: $output = '<br />'.
9288: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9289: '<span class="LC_cusr_emph">','</span>',$domdesc).
9290: ' <ul>';
1.612 raeburn 9291: foreach my $rule (@{$ruleorder}) {
9292: if (ref($curr_rules) eq 'ARRAY') {
9293: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9294: if (ref($rules->{$rule}) eq 'HASH') {
9295: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9296: $rules->{$rule}{'desc'}.'</li>';
9297: }
9298: }
9299: }
9300: }
9301: $output .= '</ul>';
9302: }
9303: }
9304: return $output;
9305: }
9306:
9307: sub instrule_disallow_msg {
1.615 raeburn 9308: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9309: my $response;
9310: my %text = (
9311: item => 'username',
9312: items => 'usernames',
9313: match => 'matches',
9314: do => 'does',
9315: action => 'a username',
9316: one => 'one',
9317: );
9318: if ($count > 1) {
9319: $text{'item'} = 'usernames';
9320: $text{'match'} ='match';
9321: $text{'do'} = 'do';
9322: $text{'action'} = 'usernames',
9323: $text{'one'} = 'ones';
9324: }
9325: if ($checkitem eq 'id') {
9326: $text{'items'} = 'IDs';
9327: $text{'item'} = 'ID';
9328: $text{'action'} = 'an ID';
1.615 raeburn 9329: if ($count > 1) {
9330: $text{'item'} = 'IDs';
9331: $text{'action'} = 'IDs';
9332: }
1.612 raeburn 9333: }
1.674 bisitz 9334: $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 9335: if ($mode eq 'upload') {
9336: if ($checkitem eq 'username') {
9337: $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'}.");
9338: } elsif ($checkitem eq 'id') {
1.674 bisitz 9339: $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 9340: }
1.669 raeburn 9341: } elsif ($mode eq 'selfcreate') {
9342: if ($checkitem eq 'id') {
9343: $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.");
9344: }
1.615 raeburn 9345: } else {
9346: if ($checkitem eq 'username') {
9347: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9348: } elsif ($checkitem eq 'id') {
9349: $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.");
9350: }
1.612 raeburn 9351: }
9352: return $response;
1.585 raeburn 9353: }
9354:
1.624 raeburn 9355: sub personal_data_fieldtitles {
9356: my %fieldtitles = &Apache::lonlocal::texthash (
9357: id => 'Student/Employee ID',
9358: permanentemail => 'E-mail address',
9359: lastname => 'Last Name',
9360: firstname => 'First Name',
9361: middlename => 'Middle Name',
9362: generation => 'Generation',
9363: gen => 'Generation',
1.765 raeburn 9364: inststatus => 'Affiliation',
1.624 raeburn 9365: );
9366: return %fieldtitles;
9367: }
9368:
1.642 raeburn 9369: sub sorted_inst_types {
9370: my ($dom) = @_;
9371: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9372: my $othertitle = &mt('All users');
9373: if ($env{'request.course.id'}) {
1.668 raeburn 9374: $othertitle = &mt('Any users');
1.642 raeburn 9375: }
9376: my @types;
9377: if (ref($order) eq 'ARRAY') {
9378: @types = @{$order};
9379: }
9380: if (@types == 0) {
9381: if (ref($usertypes) eq 'HASH') {
9382: @types = sort(keys(%{$usertypes}));
9383: }
9384: }
9385: if (keys(%{$usertypes}) > 0) {
9386: $othertitle = &mt('Other users');
9387: }
9388: return ($othertitle,$usertypes,\@types);
9389: }
9390:
1.645 raeburn 9391: sub get_institutional_codes {
9392: my ($settings,$allcourses,$LC_code) = @_;
9393: # Get complete list of course sections to update
9394: my @currsections = ();
9395: my @currxlists = ();
9396: my $coursecode = $$settings{'internal.coursecode'};
9397:
9398: if ($$settings{'internal.sectionnums'} ne '') {
9399: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9400: }
9401:
9402: if ($$settings{'internal.crosslistings'} ne '') {
9403: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9404: }
9405:
9406: if (@currxlists > 0) {
9407: foreach (@currxlists) {
9408: if (m/^([^:]+):(\w*)$/) {
9409: unless (grep/^$1$/,@{$allcourses}) {
9410: push @{$allcourses},$1;
9411: $$LC_code{$1} = $2;
9412: }
9413: }
9414: }
9415: }
9416:
9417: if (@currsections > 0) {
9418: foreach (@currsections) {
9419: if (m/^(\w+):(\w*)$/) {
9420: my $sec = $coursecode.$1;
9421: my $lc_sec = $2;
9422: unless (grep/^$sec$/,@{$allcourses}) {
9423: push @{$allcourses},$sec;
9424: $$LC_code{$sec} = $lc_sec;
9425: }
9426: }
9427: }
9428: }
9429: return;
9430: }
9431:
1.971 raeburn 9432: sub get_standard_codeitems {
9433: return ('Year','Semester','Department','Number','Section');
9434: }
9435:
1.112 bowersj2 9436: =pod
9437:
1.780 raeburn 9438: =head1 Slot Helpers
9439:
9440: =over 4
9441:
9442: =item * sorted_slots()
9443:
1.1040 raeburn 9444: Sorts an array of slot names in order of an optional sort key,
9445: default sort is by slot start time (earliest first).
1.780 raeburn 9446:
9447: Inputs:
9448:
9449: =over 4
9450:
9451: slotsarr - Reference to array of unsorted slot names.
9452:
9453: slots - Reference to hash of hash, where outer hash keys are slot names.
9454:
1.1040 raeburn 9455: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9456:
1.549 albertel 9457: =back
9458:
1.780 raeburn 9459: Returns:
9460:
9461: =over 4
9462:
1.1040 raeburn 9463: sorted - An array of slot names sorted by a specified sort key
9464: (default sort key is start time of the slot).
1.780 raeburn 9465:
9466: =back
9467:
9468: =cut
9469:
9470:
9471: sub sorted_slots {
1.1040 raeburn 9472: my ($slotsarr,$slots,$sortkey) = @_;
9473: if ($sortkey eq '') {
9474: $sortkey = 'starttime';
9475: }
1.780 raeburn 9476: my @sorted;
9477: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9478: @sorted =
9479: sort {
9480: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9481: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9482: }
9483: if (ref($slots->{$a})) { return -1;}
9484: if (ref($slots->{$b})) { return 1;}
9485: return 0;
9486: } @{$slotsarr};
9487: }
9488: return @sorted;
9489: }
9490:
1.1040 raeburn 9491: =pod
9492:
9493: =item * get_future_slots()
9494:
9495: Inputs:
9496:
9497: =over 4
9498:
9499: cnum - course number
9500:
9501: cdom - course domain
9502:
9503: now - current UNIX time
9504:
9505: symb - optional symb
9506:
9507: =back
9508:
9509: Returns:
9510:
9511: =over 4
9512:
9513: sorted_reservable - ref to array of student_schedulable slots currently
9514: reservable, ordered by end date of reservation period.
9515:
9516: reservable_now - ref to hash of student_schedulable slots currently
9517: reservable.
9518:
9519: Keys in inner hash are:
9520: (a) symb: either blank or symb to which slot use is restricted.
9521: (b) endreserve: end date of reservation period.
9522:
9523: sorted_future - ref to array of student_schedulable slots reservable in
9524: the future, ordered by start date of reservation period.
9525:
9526: future_reservable - ref to hash of student_schedulable slots reservable
9527: in the future.
9528:
9529: Keys in inner hash are:
9530: (a) symb: either blank or symb to which slot use is restricted.
9531: (b) startreserve: start date of reservation period.
9532:
9533: =back
9534:
9535: =cut
9536:
9537: sub get_future_slots {
9538: my ($cnum,$cdom,$now,$symb) = @_;
9539: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9540: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9541: foreach my $slot (keys(%slots)) {
9542: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9543: if ($symb) {
9544: next if (($slots{$slot}->{'symb'} ne '') &&
9545: ($slots{$slot}->{'symb'} ne $symb));
9546: }
9547: if (($slots{$slot}->{'starttime'} > $now) &&
9548: ($slots{$slot}->{'endtime'} > $now)) {
9549: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9550: my $userallowed = 0;
9551: if ($slots{$slot}->{'allowedsections'}) {
9552: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9553: if (!defined($env{'request.role.sec'})
9554: && grep(/^No section assigned$/,@allowed_sec)) {
9555: $userallowed=1;
9556: } else {
9557: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9558: $userallowed=1;
9559: }
9560: }
9561: unless ($userallowed) {
9562: if (defined($env{'request.course.groups'})) {
9563: my @groups = split(/:/,$env{'request.course.groups'});
9564: foreach my $group (@groups) {
9565: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9566: $userallowed=1;
9567: last;
9568: }
9569: }
9570: }
9571: }
9572: }
9573: if ($slots{$slot}->{'allowedusers'}) {
9574: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9575: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9576: if (grep(/^\Q$user\E$/,@allowed_users)) {
9577: $userallowed = 1;
9578: }
9579: }
9580: next unless($userallowed);
9581: }
9582: my $startreserve = $slots{$slot}->{'startreserve'};
9583: my $endreserve = $slots{$slot}->{'endreserve'};
9584: my $symb = $slots{$slot}->{'symb'};
9585: if (($startreserve < $now) &&
9586: (!$endreserve || $endreserve > $now)) {
9587: my $lastres = $endreserve;
9588: if (!$lastres) {
9589: $lastres = $slots{$slot}->{'starttime'};
9590: }
9591: $reservable_now{$slot} = {
9592: symb => $symb,
9593: endreserve => $lastres
9594: };
9595: } elsif (($startreserve > $now) &&
9596: (!$endreserve || $endreserve > $startreserve)) {
9597: $future_reservable{$slot} = {
9598: symb => $symb,
9599: startreserve => $startreserve
9600: };
9601: }
9602: }
9603: }
9604: my @unsorted_reservable = keys(%reservable_now);
9605: if (@unsorted_reservable > 0) {
9606: @sorted_reservable =
9607: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9608: }
9609: my @unsorted_future = keys(%future_reservable);
9610: if (@unsorted_future > 0) {
9611: @sorted_future =
9612: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9613: }
9614: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9615: }
1.780 raeburn 9616:
9617: =pod
9618:
1.1057 foxr 9619: =back
9620:
1.549 albertel 9621: =head1 HTTP Helpers
9622:
9623: =over 4
9624:
1.648 raeburn 9625: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9626:
1.258 albertel 9627: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9628: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9629: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9630:
9631: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9632: $possible_names is an ref to an array of form element names. As an example:
9633: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9634: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9635:
9636: =cut
1.1 albertel 9637:
1.6 albertel 9638: sub get_unprocessed_cgi {
1.25 albertel 9639: my ($query,$possible_names)= @_;
1.26 matthew 9640: # $Apache::lonxml::debug=1;
1.356 albertel 9641: foreach my $pair (split(/&/,$query)) {
9642: my ($name, $value) = split(/=/,$pair);
1.369 www 9643: $name = &unescape($name);
1.25 albertel 9644: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9645: $value =~ tr/+/ /;
9646: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9647: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9648: }
1.16 harris41 9649: }
1.6 albertel 9650: }
9651:
1.112 bowersj2 9652: =pod
9653:
1.648 raeburn 9654: =item * &cacheheader()
1.112 bowersj2 9655:
9656: returns cache-controlling header code
9657:
9658: =cut
9659:
1.7 albertel 9660: sub cacheheader {
1.258 albertel 9661: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9662: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9663: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9664: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9665: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9666: return $output;
1.7 albertel 9667: }
9668:
1.112 bowersj2 9669: =pod
9670:
1.648 raeburn 9671: =item * &no_cache($r)
1.112 bowersj2 9672:
9673: specifies header code to not have cache
9674:
9675: =cut
9676:
1.9 albertel 9677: sub no_cache {
1.216 albertel 9678: my ($r) = @_;
9679: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9680: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9681: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9682: $r->no_cache(1);
9683: $r->header_out("Expires" => $date);
9684: $r->header_out("Pragma" => "no-cache");
1.123 www 9685: }
9686:
9687: sub content_type {
1.181 albertel 9688: my ($r,$type,$charset) = @_;
1.299 foxr 9689: if ($r) {
9690: # Note that printout.pl calls this with undef for $r.
9691: &no_cache($r);
9692: }
1.258 albertel 9693: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9694: unless ($charset) {
9695: $charset=&Apache::lonlocal::current_encoding;
9696: }
9697: if ($charset) { $type.='; charset='.$charset; }
9698: if ($r) {
9699: $r->content_type($type);
9700: } else {
9701: print("Content-type: $type\n\n");
9702: }
1.9 albertel 9703: }
1.25 albertel 9704:
1.112 bowersj2 9705: =pod
9706:
1.648 raeburn 9707: =item * &add_to_env($name,$value)
1.112 bowersj2 9708:
1.258 albertel 9709: adds $name to the %env hash with value
1.112 bowersj2 9710: $value, if $name already exists, the entry is converted to an array
9711: reference and $value is added to the array.
9712:
9713: =cut
9714:
1.25 albertel 9715: sub add_to_env {
9716: my ($name,$value)=@_;
1.258 albertel 9717: if (defined($env{$name})) {
9718: if (ref($env{$name})) {
1.25 albertel 9719: #already have multiple values
1.258 albertel 9720: push(@{ $env{$name} },$value);
1.25 albertel 9721: } else {
9722: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9723: my $first=$env{$name};
9724: undef($env{$name});
9725: push(@{ $env{$name} },$first,$value);
1.25 albertel 9726: }
9727: } else {
1.258 albertel 9728: $env{$name}=$value;
1.25 albertel 9729: }
1.31 albertel 9730: }
1.149 albertel 9731:
9732: =pod
9733:
1.648 raeburn 9734: =item * &get_env_multiple($name)
1.149 albertel 9735:
1.258 albertel 9736: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9737: values may be defined and end up as an array ref.
9738:
9739: returns an array of values
9740:
9741: =cut
9742:
9743: sub get_env_multiple {
9744: my ($name) = @_;
9745: my @values;
1.258 albertel 9746: if (defined($env{$name})) {
1.149 albertel 9747: # exists is it an array
1.258 albertel 9748: if (ref($env{$name})) {
9749: @values=@{ $env{$name} };
1.149 albertel 9750: } else {
1.258 albertel 9751: $values[0]=$env{$name};
1.149 albertel 9752: }
9753: }
9754: return(@values);
9755: }
9756:
1.660 raeburn 9757: sub ask_for_embedded_content {
9758: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9759: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9760: %currsubfile,%unused,$rem);
1.1071 raeburn 9761: my $counter = 0;
9762: my $numnew = 0;
1.987 raeburn 9763: my $numremref = 0;
9764: my $numinvalid = 0;
9765: my $numpathchg = 0;
9766: my $numexisting = 0;
1.1071 raeburn 9767: my $numunused = 0;
9768: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9769: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9770: my $heading = &mt('Upload embedded files');
9771: my $buttontext = &mt('Upload');
9772:
1.1123 raeburn 9773: my ($navmap,$cdom,$cnum);
1.1085 raeburn 9774: if ($env{'request.course.id'}) {
1.1123 raeburn 9775: if ($actionurl eq '/adm/dependencies') {
9776: $navmap = Apache::lonnavmaps::navmap->new();
9777: }
9778: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9779: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9780: }
1.1123 raeburn 9781: if (($actionurl eq '/adm/portfolio') ||
9782: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9783: my $current_path='/';
9784: if ($env{'form.currentpath'}) {
9785: $current_path = $env{'form.currentpath'};
9786: }
9787: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9788: $udom = $cdom;
9789: $uname = $cnum;
1.984 raeburn 9790: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9791: } else {
9792: $udom = $env{'user.domain'};
9793: $uname = $env{'user.name'};
9794: $url = '/userfiles/portfolio';
9795: }
1.987 raeburn 9796: $toplevel = $url.'/';
1.984 raeburn 9797: $url .= $current_path;
9798: $getpropath = 1;
1.987 raeburn 9799: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9800: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9801: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9802: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9803: $toplevel = $url;
1.984 raeburn 9804: if ($rest ne '') {
1.987 raeburn 9805: $url .= $rest;
9806: }
9807: } elsif ($actionurl eq '/adm/coursedocs') {
9808: if (ref($args) eq 'HASH') {
1.1071 raeburn 9809: $url = $args->{'docs_url'};
9810: $toplevel = $url;
1.1084 raeburn 9811: if ($args->{'context'} eq 'paste') {
9812: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9813: ($path) =
9814: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9815: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9816: $fileloc =~ s{^/}{};
9817: }
1.1071 raeburn 9818: }
1.1084 raeburn 9819: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9820: if ($env{'request.course.id'} ne '') {
9821: if (ref($args) eq 'HASH') {
9822: $url = $args->{'docs_url'};
9823: $title = $args->{'docs_title'};
1.1126 raeburn 9824: $toplevel = $url;
9825: unless ($toplevel =~ m{^/}) {
9826: $toplevel = "/$url";
9827: }
1.1085 raeburn 9828: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9829: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9830: $path = $1;
9831: } else {
9832: ($path) =
9833: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9834: }
1.1071 raeburn 9835: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9836: $fileloc =~ s{^/}{};
9837: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9838: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9839: }
1.987 raeburn 9840: }
1.1123 raeburn 9841: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9842: $udom = $cdom;
9843: $uname = $cnum;
9844: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9845: $toplevel = $url;
9846: $path = $url;
9847: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9848: $fileloc =~ s{^/}{};
1.987 raeburn 9849: }
1.1126 raeburn 9850: foreach my $file (keys(%{$allfiles})) {
9851: my $embed_file;
9852: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9853: $embed_file = $1;
9854: } else {
9855: $embed_file = $file;
9856: }
1.987 raeburn 9857: my $absolutepath;
9858: if ($embed_file =~ m{^\w+://}) {
9859: $newfiles{$embed_file} = 1;
9860: $mapping{$embed_file} = $embed_file;
9861: } else {
9862: if ($embed_file =~ m{^/}) {
9863: $absolutepath = $embed_file;
9864: $embed_file =~ s{^(/+)}{};
9865: }
9866: if ($embed_file =~ m{/}) {
9867: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9868: $path = &check_for_traversal($path,$url,$toplevel);
9869: my $item = $fname;
9870: if ($path ne '') {
9871: $item = $path.'/'.$fname;
9872: $subdependencies{$path}{$fname} = 1;
9873: } else {
9874: $dependencies{$item} = 1;
9875: }
9876: if ($absolutepath) {
9877: $mapping{$item} = $absolutepath;
9878: } else {
9879: $mapping{$item} = $embed_file;
9880: }
9881: } else {
9882: $dependencies{$embed_file} = 1;
9883: if ($absolutepath) {
9884: $mapping{$embed_file} = $absolutepath;
9885: } else {
9886: $mapping{$embed_file} = $embed_file;
9887: }
9888: }
1.984 raeburn 9889: }
9890: }
1.1071 raeburn 9891: my $dirptr = 16384;
1.984 raeburn 9892: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9893: $currsubfile{$path} = {};
1.1123 raeburn 9894: if (($actionurl eq '/adm/portfolio') ||
9895: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9896: my ($sublistref,$listerror) =
9897: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9898: if (ref($sublistref) eq 'ARRAY') {
9899: foreach my $line (@{$sublistref}) {
9900: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9901: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9902: }
1.984 raeburn 9903: }
1.987 raeburn 9904: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9905: if (opendir(my $dir,$url.'/'.$path)) {
9906: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9907: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9908: }
1.1084 raeburn 9909: } elsif (($actionurl eq '/adm/dependencies') ||
9910: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9911: ($args->{'context'} eq 'paste')) ||
9912: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9913: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9914: my $dir;
9915: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9916: $dir = $fileloc;
9917: } else {
9918: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9919: }
1.1071 raeburn 9920: if ($dir ne '') {
9921: my ($sublistref,$listerror) =
9922: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9923: if (ref($sublistref) eq 'ARRAY') {
9924: foreach my $line (@{$sublistref}) {
9925: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9926: undef,$mtime)=split(/\&/,$line,12);
9927: unless (($testdir&$dirptr) ||
9928: ($file_name =~ /^\.\.?$/)) {
9929: $currsubfile{$path}{$file_name} = [$size,$mtime];
9930: }
9931: }
9932: }
9933: }
1.984 raeburn 9934: }
9935: }
9936: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9937: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9938: my $item = $path.'/'.$file;
9939: unless ($mapping{$item} eq $item) {
9940: $pathchanges{$item} = 1;
9941: }
9942: $existing{$item} = 1;
9943: $numexisting ++;
9944: } else {
9945: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9946: }
9947: }
1.1071 raeburn 9948: if ($actionurl eq '/adm/dependencies') {
9949: foreach my $path (keys(%currsubfile)) {
9950: if (ref($currsubfile{$path}) eq 'HASH') {
9951: foreach my $file (keys(%{$currsubfile{$path}})) {
9952: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9953: next if (($rem ne '') &&
9954: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9955: (ref($navmap) &&
9956: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9957: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9958: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9959: $unused{$path.'/'.$file} = 1;
9960: }
9961: }
9962: }
9963: }
9964: }
1.984 raeburn 9965: }
1.987 raeburn 9966: my %currfile;
1.1123 raeburn 9967: if (($actionurl eq '/adm/portfolio') ||
9968: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9969: my ($dirlistref,$listerror) =
9970: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9971: if (ref($dirlistref) eq 'ARRAY') {
9972: foreach my $line (@{$dirlistref}) {
9973: my ($file_name,$rest) = split(/\&/,$line,2);
9974: $currfile{$file_name} = 1;
9975: }
1.984 raeburn 9976: }
1.987 raeburn 9977: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9978: if (opendir(my $dir,$url)) {
1.987 raeburn 9979: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9980: map {$currfile{$_} = 1;} @dir_list;
9981: }
1.1084 raeburn 9982: } elsif (($actionurl eq '/adm/dependencies') ||
9983: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9984: ($args->{'context'} eq 'paste')) ||
9985: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9986: if ($env{'request.course.id'} ne '') {
9987: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9988: if ($dir ne '') {
9989: my ($dirlistref,$listerror) =
9990: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9991: if (ref($dirlistref) eq 'ARRAY') {
9992: foreach my $line (@{$dirlistref}) {
9993: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9994: $size,undef,$mtime)=split(/\&/,$line,12);
9995: unless (($testdir&$dirptr) ||
9996: ($file_name =~ /^\.\.?$/)) {
9997: $currfile{$file_name} = [$size,$mtime];
9998: }
9999: }
10000: }
10001: }
10002: }
1.984 raeburn 10003: }
10004: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10005: if (exists($currfile{$file})) {
1.987 raeburn 10006: unless ($mapping{$file} eq $file) {
10007: $pathchanges{$file} = 1;
10008: }
10009: $existing{$file} = 1;
10010: $numexisting ++;
10011: } else {
1.984 raeburn 10012: $newfiles{$file} = 1;
10013: }
10014: }
1.1071 raeburn 10015: foreach my $file (keys(%currfile)) {
10016: unless (($file eq $filename) ||
10017: ($file eq $filename.'.bak') ||
10018: ($dependencies{$file})) {
1.1085 raeburn 10019: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10020: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10021: next if (($rem ne '') &&
10022: (($env{"httpref.$rem".$file} ne '') ||
10023: (ref($navmap) &&
10024: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10025: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10026: ($navmap->getResourceByUrl($rem.$1)))))));
10027: }
1.1085 raeburn 10028: }
1.1071 raeburn 10029: $unused{$file} = 1;
10030: }
10031: }
1.1084 raeburn 10032: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10033: ($args->{'context'} eq 'paste')) {
10034: $counter = scalar(keys(%existing));
10035: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10036: return ($output,$counter,$numpathchg,\%existing);
10037: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10038: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10039: $counter = scalar(keys(%existing));
10040: $numpathchg = scalar(keys(%pathchanges));
10041: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10042: }
1.984 raeburn 10043: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10044: if ($actionurl eq '/adm/dependencies') {
10045: next if ($embed_file =~ m{^\w+://});
10046: }
1.660 raeburn 10047: $upload_output .= &start_data_table_row().
1.1123 raeburn 10048: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10049: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10050: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10051: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10052: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10053: }
1.1123 raeburn 10054: $upload_output .= '</td>';
1.1071 raeburn 10055: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10056: $upload_output.='<td align="right">'.
10057: '<span class="LC_info LC_fontsize_medium">'.
10058: &mt("URL points to web address").'</span>';
1.987 raeburn 10059: $numremref++;
1.660 raeburn 10060: } elsif ($args->{'error_on_invalid_names'}
10061: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10062: $upload_output.='<td align="right"><span class="LC_warning">'.
10063: &mt('Invalid characters').'</span>';
1.987 raeburn 10064: $numinvalid++;
1.660 raeburn 10065: } else {
1.1123 raeburn 10066: $upload_output .= '<td>'.
10067: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10068: $embed_file,\%mapping,
1.1071 raeburn 10069: $allfiles,$codebase,'upload');
10070: $counter ++;
10071: $numnew ++;
1.987 raeburn 10072: }
10073: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10074: }
10075: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10076: if ($actionurl eq '/adm/dependencies') {
10077: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10078: $modify_output .= &start_data_table_row().
10079: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10080: '<img src="'.&icon($embed_file).'" border="0" />'.
10081: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10082: '<td>'.$size.'</td>'.
10083: '<td>'.$mtime.'</td>'.
10084: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10085: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10086: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10087: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10088: &embedded_file_element('upload_embedded',$counter,
10089: $embed_file,\%mapping,
10090: $allfiles,$codebase,'modify').
10091: '</div></td>'.
10092: &end_data_table_row()."\n";
10093: $counter ++;
10094: } else {
10095: $upload_output .= &start_data_table_row().
1.1123 raeburn 10096: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10097: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10098: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10099: &Apache::loncommon::end_data_table_row()."\n";
10100: }
10101: }
10102: my $delidx = $counter;
10103: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10104: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10105: $delete_output .= &start_data_table_row().
10106: '<td><img src="'.&icon($oldfile).'" />'.
10107: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10108: '<td>'.$size.'</td>'.
10109: '<td>'.$mtime.'</td>'.
10110: '<td><label><input type="checkbox" name="del_upload_dep" '.
10111: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10112: &embedded_file_element('upload_embedded',$delidx,
10113: $oldfile,\%mapping,$allfiles,
10114: $codebase,'delete').'</td>'.
10115: &end_data_table_row()."\n";
10116: $numunused ++;
10117: $delidx ++;
1.987 raeburn 10118: }
10119: if ($upload_output) {
10120: $upload_output = &start_data_table().
10121: $upload_output.
10122: &end_data_table()."\n";
10123: }
1.1071 raeburn 10124: if ($modify_output) {
10125: $modify_output = &start_data_table().
10126: &start_data_table_header_row().
10127: '<th>'.&mt('File').'</th>'.
10128: '<th>'.&mt('Size (KB)').'</th>'.
10129: '<th>'.&mt('Modified').'</th>'.
10130: '<th>'.&mt('Upload replacement?').'</th>'.
10131: &end_data_table_header_row().
10132: $modify_output.
10133: &end_data_table()."\n";
10134: }
10135: if ($delete_output) {
10136: $delete_output = &start_data_table().
10137: &start_data_table_header_row().
10138: '<th>'.&mt('File').'</th>'.
10139: '<th>'.&mt('Size (KB)').'</th>'.
10140: '<th>'.&mt('Modified').'</th>'.
10141: '<th>'.&mt('Delete?').'</th>'.
10142: &end_data_table_header_row().
10143: $delete_output.
10144: &end_data_table()."\n";
10145: }
1.987 raeburn 10146: my $applies = 0;
10147: if ($numremref) {
10148: $applies ++;
10149: }
10150: if ($numinvalid) {
10151: $applies ++;
10152: }
10153: if ($numexisting) {
10154: $applies ++;
10155: }
1.1071 raeburn 10156: if ($counter || $numunused) {
1.987 raeburn 10157: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10158: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10159: $state.'<h3>'.$heading.'</h3>';
10160: if ($actionurl eq '/adm/dependencies') {
10161: if ($numnew) {
10162: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10163: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10164: $upload_output.'<br />'."\n";
10165: }
10166: if ($numexisting) {
10167: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10168: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10169: $modify_output.'<br />'."\n";
10170: $buttontext = &mt('Save changes');
10171: }
10172: if ($numunused) {
10173: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10174: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10175: $delete_output.'<br />'."\n";
10176: $buttontext = &mt('Save changes');
10177: }
10178: } else {
10179: $output .= $upload_output.'<br />'."\n";
10180: }
10181: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10182: $counter.'" />'."\n";
10183: if ($actionurl eq '/adm/dependencies') {
10184: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10185: $numnew.'" />'."\n";
10186: } elsif ($actionurl eq '') {
1.987 raeburn 10187: $output .= '<input type="hidden" name="phase" value="three" />';
10188: }
10189: } elsif ($applies) {
10190: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10191: if ($applies > 1) {
10192: $output .=
1.1123 raeburn 10193: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10194: if ($numremref) {
10195: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10196: }
10197: if ($numinvalid) {
10198: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10199: }
10200: if ($numexisting) {
10201: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10202: }
10203: $output .= '</ul><br />';
10204: } elsif ($numremref) {
10205: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10206: } elsif ($numinvalid) {
10207: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10208: } elsif ($numexisting) {
10209: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10210: }
10211: $output .= $upload_output.'<br />';
10212: }
10213: my ($pathchange_output,$chgcount);
1.1071 raeburn 10214: $chgcount = $counter;
1.987 raeburn 10215: if (keys(%pathchanges) > 0) {
10216: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10217: if ($counter) {
1.987 raeburn 10218: $output .= &embedded_file_element('pathchange',$chgcount,
10219: $embed_file,\%mapping,
1.1071 raeburn 10220: $allfiles,$codebase,'change');
1.987 raeburn 10221: } else {
10222: $pathchange_output .=
10223: &start_data_table_row().
10224: '<td><input type ="checkbox" name="namechange" value="'.
10225: $chgcount.'" checked="checked" /></td>'.
10226: '<td>'.$mapping{$embed_file}.'</td>'.
10227: '<td>'.$embed_file.
10228: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10229: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10230: '</td>'.&end_data_table_row();
1.660 raeburn 10231: }
1.987 raeburn 10232: $numpathchg ++;
10233: $chgcount ++;
1.660 raeburn 10234: }
10235: }
1.1127 raeburn 10236: if (($counter) || ($numunused)) {
1.987 raeburn 10237: if ($numpathchg) {
10238: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10239: $numpathchg.'" />'."\n";
10240: }
10241: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10242: ($actionurl eq '/adm/imsimport')) {
10243: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10244: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10245: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10246: } elsif ($actionurl eq '/adm/dependencies') {
10247: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10248: }
1.1123 raeburn 10249: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10250: } elsif ($numpathchg) {
10251: my %pathchange = ();
10252: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10253: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10254: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10255: }
1.987 raeburn 10256: }
1.1071 raeburn 10257: return ($output,$counter,$numpathchg);
1.987 raeburn 10258: }
10259:
10260: sub embedded_file_element {
1.1071 raeburn 10261: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10262: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10263: (ref($codebase) eq 'HASH'));
10264: my $output;
1.1071 raeburn 10265: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10266: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10267: }
10268: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10269: &escape($embed_file).'" />';
10270: unless (($context eq 'upload_embedded') &&
10271: ($mapping->{$embed_file} eq $embed_file)) {
10272: $output .='
10273: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10274: }
10275: my $attrib;
10276: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10277: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10278: }
10279: $output .=
10280: "\n\t\t".
10281: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10282: $attrib.'" />';
10283: if (exists($codebase->{$mapping->{$embed_file}})) {
10284: $output .=
10285: "\n\t\t".
10286: '<input name="codebase_'.$num.'" type="hidden" value="'.
10287: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10288: }
1.987 raeburn 10289: return $output;
1.660 raeburn 10290: }
10291:
1.1071 raeburn 10292: sub get_dependency_details {
10293: my ($currfile,$currsubfile,$embed_file) = @_;
10294: my ($size,$mtime,$showsize,$showmtime);
10295: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10296: if ($embed_file =~ m{/}) {
10297: my ($path,$fname) = split(/\//,$embed_file);
10298: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10299: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10300: }
10301: } else {
10302: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10303: ($size,$mtime) = @{$currfile->{$embed_file}};
10304: }
10305: }
10306: $showsize = $size/1024.0;
10307: $showsize = sprintf("%.1f",$showsize);
10308: if ($mtime > 0) {
10309: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10310: }
10311: }
10312: return ($showsize,$showmtime);
10313: }
10314:
10315: sub ask_embedded_js {
10316: return <<"END";
10317: <script type="text/javascript"">
10318: // <![CDATA[
10319: function toggleBrowse(counter) {
10320: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10321: var fileid = document.getElementById('embedded_item_'+counter);
10322: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10323: if (chkboxid.checked == true) {
10324: uploaddivid.style.display='block';
10325: } else {
10326: uploaddivid.style.display='none';
10327: fileid.value = '';
10328: }
10329: }
10330: // ]]>
10331: </script>
10332:
10333: END
10334: }
10335:
1.661 raeburn 10336: sub upload_embedded {
10337: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10338: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10339: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10340: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10341: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10342: my $orig_uploaded_filename =
10343: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10344: foreach my $type ('orig','ref','attrib','codebase') {
10345: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10346: $env{'form.embedded_'.$type.'_'.$i} =
10347: &unescape($env{'form.embedded_'.$type.'_'.$i});
10348: }
10349: }
1.661 raeburn 10350: my ($path,$fname) =
10351: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10352: # no path, whole string is fname
10353: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10354: $fname = &Apache::lonnet::clean_filename($fname);
10355: # See if there is anything left
10356: next if ($fname eq '');
10357:
10358: # Check if file already exists as a file or directory.
10359: my ($state,$msg);
10360: if ($context eq 'portfolio') {
10361: my $port_path = $dirpath;
10362: if ($group ne '') {
10363: $port_path = "groups/$group/$port_path";
10364: }
1.987 raeburn 10365: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10366: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10367: $dir_root,$port_path,$disk_quota,
10368: $current_disk_usage,$uname,$udom);
10369: if ($state eq 'will_exceed_quota'
1.984 raeburn 10370: || $state eq 'file_locked') {
1.661 raeburn 10371: $output .= $msg;
10372: next;
10373: }
10374: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10375: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10376: if ($state eq 'exists') {
10377: $output .= $msg;
10378: next;
10379: }
10380: }
10381: # Check if extension is valid
10382: if (($fname =~ /\.(\w+)$/) &&
10383: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10384: $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 10385: next;
10386: } elsif (($fname =~ /\.(\w+)$/) &&
10387: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10388: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10389: next;
10390: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10391: $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10392: next;
10393: }
10394: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10395: my $subdir = $path;
10396: $subdir =~ s{/+$}{};
1.661 raeburn 10397: if ($context eq 'portfolio') {
1.984 raeburn 10398: my $result;
10399: if ($state eq 'existingfile') {
10400: $result=
10401: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10402: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10403: } else {
1.984 raeburn 10404: $result=
10405: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10406: $dirpath.
1.1123 raeburn 10407: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10408: if ($result !~ m|^/uploaded/|) {
10409: $output .= '<span class="LC_error">'
10410: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10411: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10412: .'</span><br />';
10413: next;
10414: } else {
1.987 raeburn 10415: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10416: $path.$fname.'</span>').'<br />';
1.984 raeburn 10417: }
1.661 raeburn 10418: }
1.1123 raeburn 10419: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10420: my $extendedsubdir = $dirpath.'/'.$subdir;
10421: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10422: my $result =
1.1126 raeburn 10423: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10424: if ($result !~ m|^/uploaded/|) {
10425: $output .= '<span class="LC_error">'
10426: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10427: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10428: .'</span><br />';
10429: next;
10430: } else {
10431: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10432: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10433: if ($context eq 'syllabus') {
10434: &Apache::lonnet::make_public_indefinitely($result);
10435: }
1.987 raeburn 10436: }
1.661 raeburn 10437: } else {
10438: # Save the file
10439: my $target = $env{'form.embedded_item_'.$i};
10440: my $fullpath = $dir_root.$dirpath.'/'.$path;
10441: my $dest = $fullpath.$fname;
10442: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10443: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10444: my $count;
10445: my $filepath = $dir_root;
1.1027 raeburn 10446: foreach my $subdir (@parts) {
10447: $filepath .= "/$subdir";
10448: if (!-e $filepath) {
1.661 raeburn 10449: mkdir($filepath,0770);
10450: }
10451: }
10452: my $fh;
10453: if (!open($fh,'>'.$dest)) {
10454: &Apache::lonnet::logthis('Failed to create '.$dest);
10455: $output .= '<span class="LC_error">'.
1.1071 raeburn 10456: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10457: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10458: '</span><br />';
10459: } else {
10460: if (!print $fh $env{'form.embedded_item_'.$i}) {
10461: &Apache::lonnet::logthis('Failed to write to '.$dest);
10462: $output .= '<span class="LC_error">'.
1.1071 raeburn 10463: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10464: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10465: '</span><br />';
10466: } else {
1.987 raeburn 10467: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10468: $url.'</span>').'<br />';
10469: unless ($context eq 'testbank') {
10470: $footer .= &mt('View embedded file: [_1]',
10471: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10472: }
10473: }
10474: close($fh);
10475: }
10476: }
10477: if ($env{'form.embedded_ref_'.$i}) {
10478: $pathchange{$i} = 1;
10479: }
10480: }
10481: if ($output) {
10482: $output = '<p>'.$output.'</p>';
10483: }
10484: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10485: $returnflag = 'ok';
1.1071 raeburn 10486: my $numpathchgs = scalar(keys(%pathchange));
10487: if ($numpathchgs > 0) {
1.987 raeburn 10488: if ($context eq 'portfolio') {
10489: $output .= '<p>'.&mt('or').'</p>';
10490: } elsif ($context eq 'testbank') {
1.1071 raeburn 10491: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10492: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10493: $returnflag = 'modify_orightml';
10494: }
10495: }
1.1071 raeburn 10496: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10497: }
10498:
10499: sub modify_html_form {
10500: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10501: my $end = 0;
10502: my $modifyform;
10503: if ($context eq 'upload_embedded') {
10504: return unless (ref($pathchange) eq 'HASH');
10505: if ($env{'form.number_embedded_items'}) {
10506: $end += $env{'form.number_embedded_items'};
10507: }
10508: if ($env{'form.number_pathchange_items'}) {
10509: $end += $env{'form.number_pathchange_items'};
10510: }
10511: if ($end) {
10512: for (my $i=0; $i<$end; $i++) {
10513: if ($i < $env{'form.number_embedded_items'}) {
10514: next unless($pathchange->{$i});
10515: }
10516: $modifyform .=
10517: &start_data_table_row().
10518: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10519: 'checked="checked" /></td>'.
10520: '<td>'.$env{'form.embedded_ref_'.$i}.
10521: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10522: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10523: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10524: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10525: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10526: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10527: '<td>'.$env{'form.embedded_orig_'.$i}.
10528: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10529: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10530: &end_data_table_row();
1.1071 raeburn 10531: }
1.987 raeburn 10532: }
10533: } else {
10534: $modifyform = $pathchgtable;
10535: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10536: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10537: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10538: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10539: }
10540: }
10541: if ($modifyform) {
1.1071 raeburn 10542: if ($actionurl eq '/adm/dependencies') {
10543: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10544: }
1.987 raeburn 10545: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10546: '<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".
10547: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10548: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10549: '</ol></p>'."\n".'<p>'.
10550: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10551: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10552: &start_data_table()."\n".
10553: &start_data_table_header_row().
10554: '<th>'.&mt('Change?').'</th>'.
10555: '<th>'.&mt('Current reference').'</th>'.
10556: '<th>'.&mt('Required reference').'</th>'.
10557: &end_data_table_header_row()."\n".
10558: $modifyform.
10559: &end_data_table().'<br />'."\n".$hiddenstate.
10560: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10561: '</form>'."\n";
10562: }
10563: return;
10564: }
10565:
10566: sub modify_html_refs {
1.1123 raeburn 10567: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10568: my $container;
10569: if ($context eq 'portfolio') {
10570: $container = $env{'form.container'};
10571: } elsif ($context eq 'coursedoc') {
10572: $container = $env{'form.primaryurl'};
1.1071 raeburn 10573: } elsif ($context eq 'manage_dependencies') {
10574: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10575: $container = "/$container";
1.1123 raeburn 10576: } elsif ($context eq 'syllabus') {
10577: $container = $url;
1.987 raeburn 10578: } else {
1.1027 raeburn 10579: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10580: }
10581: my (%allfiles,%codebase,$output,$content);
10582: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10583: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10584: if (wantarray) {
10585: return ('',0,0);
10586: } else {
10587: return;
10588: }
10589: }
10590: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10591: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10592: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10593: if (wantarray) {
10594: return ('',0,0);
10595: } else {
10596: return;
10597: }
10598: }
1.987 raeburn 10599: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10600: if ($content eq '-1') {
10601: if (wantarray) {
10602: return ('',0,0);
10603: } else {
10604: return;
10605: }
10606: }
1.987 raeburn 10607: } else {
1.1071 raeburn 10608: unless ($container =~ /^\Q$dir_root\E/) {
10609: if (wantarray) {
10610: return ('',0,0);
10611: } else {
10612: return;
10613: }
10614: }
1.987 raeburn 10615: if (open(my $fh,"<$container")) {
10616: $content = join('', <$fh>);
10617: close($fh);
10618: } else {
1.1071 raeburn 10619: if (wantarray) {
10620: return ('',0,0);
10621: } else {
10622: return;
10623: }
1.987 raeburn 10624: }
10625: }
10626: my ($count,$codebasecount) = (0,0);
10627: my $mm = new File::MMagic;
10628: my $mime_type = $mm->checktype_contents($content);
10629: if ($mime_type eq 'text/html') {
10630: my $parse_result =
10631: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10632: \%codebase,\$content);
10633: if ($parse_result eq 'ok') {
10634: foreach my $i (@changes) {
10635: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10636: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10637: if ($allfiles{$ref}) {
10638: my $newname = $orig;
10639: my ($attrib_regexp,$codebase);
1.1006 raeburn 10640: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10641: if ($attrib_regexp =~ /:/) {
10642: $attrib_regexp =~ s/\:/|/g;
10643: }
10644: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10645: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10646: $count += $numchg;
1.1123 raeburn 10647: $allfiles{$newname} = $allfiles{$ref};
1.987 raeburn 10648: }
10649: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10650: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10651: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10652: $codebasecount ++;
10653: }
10654: }
10655: }
1.1123 raeburn 10656: my $skiprewrites;
1.987 raeburn 10657: if ($count || $codebasecount) {
10658: my $saveresult;
1.1071 raeburn 10659: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10660: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10661: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10662: if ($url eq $container) {
10663: my ($fname) = ($container =~ m{/([^/]+)$});
10664: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10665: $count,'<span class="LC_filename">'.
1.1071 raeburn 10666: $fname.'</span>').'</p>';
1.987 raeburn 10667: } else {
10668: $output = '<p class="LC_error">'.
10669: &mt('Error: update failed for: [_1].',
10670: '<span class="LC_filename">'.
10671: $container.'</span>').'</p>';
10672: }
1.1123 raeburn 10673: if ($context eq 'syllabus') {
10674: unless ($saveresult eq 'ok') {
10675: $skiprewrites = 1;
10676: }
10677: }
1.987 raeburn 10678: } else {
10679: if (open(my $fh,">$container")) {
10680: print $fh $content;
10681: close($fh);
10682: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10683: $count,'<span class="LC_filename">'.
10684: $container.'</span>').'</p>';
1.661 raeburn 10685: } else {
1.987 raeburn 10686: $output = '<p class="LC_error">'.
10687: &mt('Error: could not update [_1].',
10688: '<span class="LC_filename">'.
10689: $container.'</span>').'</p>';
1.661 raeburn 10690: }
10691: }
10692: }
1.1123 raeburn 10693: if (($context eq 'syllabus') && (!$skiprewrites)) {
10694: my ($actionurl,$state);
10695: $actionurl = "/public/$udom/$uname/syllabus";
10696: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10697: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10698: \%codebase,
10699: {'context' => 'rewrites',
10700: 'ignore_remote_references' => 1,});
10701: if (ref($mapping) eq 'HASH') {
10702: my $rewrites = 0;
10703: foreach my $key (keys(%{$mapping})) {
10704: next if ($key =~ m{^https?://});
10705: my $ref = $mapping->{$key};
10706: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10707: my $attrib;
10708: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10709: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10710: }
10711: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10712: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10713: $rewrites += $numchg;
10714: }
10715: }
10716: if ($rewrites) {
10717: my $saveresult;
10718: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10719: if ($url eq $container) {
10720: my ($fname) = ($container =~ m{/([^/]+)$});
10721: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10722: $count,'<span class="LC_filename">'.
10723: $fname.'</span>').'</p>';
10724: } else {
10725: $output .= '<p class="LC_error">'.
10726: &mt('Error: could not update links in [_1].',
10727: '<span class="LC_filename">'.
10728: $container.'</span>').'</p>';
10729:
10730: }
10731: }
10732: }
10733: }
1.987 raeburn 10734: } else {
10735: &logthis('Failed to parse '.$container.
10736: ' to modify references: '.$parse_result);
1.661 raeburn 10737: }
10738: }
1.1071 raeburn 10739: if (wantarray) {
10740: return ($output,$count,$codebasecount);
10741: } else {
10742: return $output;
10743: }
1.661 raeburn 10744: }
10745:
10746: sub check_for_existing {
10747: my ($path,$fname,$element) = @_;
10748: my ($state,$msg);
10749: if (-d $path.'/'.$fname) {
10750: $state = 'exists';
10751: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10752: } elsif (-e $path.'/'.$fname) {
10753: $state = 'exists';
10754: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10755: }
10756: if ($state eq 'exists') {
10757: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10758: }
10759: return ($state,$msg);
10760: }
10761:
10762: sub check_for_upload {
10763: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10764: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10765: my $filesize = length($env{'form.'.$element});
10766: if (!$filesize) {
10767: my $msg = '<span class="LC_error">'.
10768: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10769: '<span class="LC_filename">'.$fname.'</span>',
10770: $filesize).'<br />'.
1.1007 raeburn 10771: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10772: '</span>';
10773: return ('zero_bytes',$msg);
10774: }
10775: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10776: my $getpropath = 1;
1.1021 raeburn 10777: my ($dirlistref,$listerror) =
10778: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10779: my $found_file = 0;
10780: my $locked_file = 0;
1.991 raeburn 10781: my @lockers;
10782: my $navmap;
10783: if ($env{'request.course.id'}) {
10784: $navmap = Apache::lonnavmaps::navmap->new();
10785: }
1.1021 raeburn 10786: if (ref($dirlistref) eq 'ARRAY') {
10787: foreach my $line (@{$dirlistref}) {
10788: my ($file_name,$rest)=split(/\&/,$line,2);
10789: if ($file_name eq $fname){
10790: $file_name = $path.$file_name;
10791: if ($group ne '') {
10792: $file_name = $group.$file_name;
10793: }
10794: $found_file = 1;
10795: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10796: foreach my $lock (@lockers) {
10797: if (ref($lock) eq 'ARRAY') {
10798: my ($symb,$crsid) = @{$lock};
10799: if ($crsid eq $env{'request.course.id'}) {
10800: if (ref($navmap)) {
10801: my $res = $navmap->getBySymb($symb);
10802: foreach my $part (@{$res->parts()}) {
10803: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10804: unless (($slot_status == $res->RESERVED) ||
10805: ($slot_status == $res->RESERVED_LOCATION)) {
10806: $locked_file = 1;
10807: }
1.991 raeburn 10808: }
1.1021 raeburn 10809: } else {
10810: $locked_file = 1;
1.991 raeburn 10811: }
10812: } else {
10813: $locked_file = 1;
10814: }
10815: }
1.1021 raeburn 10816: }
10817: } else {
10818: my @info = split(/\&/,$rest);
10819: my $currsize = $info[6]/1000;
10820: if ($currsize < $filesize) {
10821: my $extra = $filesize - $currsize;
10822: if (($current_disk_usage + $extra) > $disk_quota) {
10823: my $msg = '<span class="LC_error">'.
10824: &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.',
10825: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10826: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10827: $disk_quota,$current_disk_usage);
10828: return ('will_exceed_quota',$msg);
10829: }
1.984 raeburn 10830: }
10831: }
1.661 raeburn 10832: }
10833: }
10834: }
10835: if (($current_disk_usage + $filesize) > $disk_quota){
10836: my $msg = '<span class="LC_error">'.
10837: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10838: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10839: return ('will_exceed_quota',$msg);
10840: } elsif ($found_file) {
10841: if ($locked_file) {
10842: my $msg = '<span class="LC_error">';
10843: $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>');
10844: $msg .= '</span><br />';
10845: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10846: return ('file_locked',$msg);
10847: } else {
10848: my $msg = '<span class="LC_error">';
1.984 raeburn 10849: $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 10850: $msg .= '</span>';
1.984 raeburn 10851: return ('existingfile',$msg);
1.661 raeburn 10852: }
10853: }
10854: }
10855:
1.987 raeburn 10856: sub check_for_traversal {
10857: my ($path,$url,$toplevel) = @_;
10858: my @parts=split(/\//,$path);
10859: my $cleanpath;
10860: my $fullpath = $url;
10861: for (my $i=0;$i<@parts;$i++) {
10862: next if ($parts[$i] eq '.');
10863: if ($parts[$i] eq '..') {
10864: $fullpath =~ s{([^/]+/)$}{};
10865: } else {
10866: $fullpath .= $parts[$i].'/';
10867: }
10868: }
10869: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10870: $cleanpath = $1;
10871: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10872: my $curr_toprel = $1;
10873: my @parts = split(/\//,$curr_toprel);
10874: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10875: my @urlparts = split(/\//,$url_toprel);
10876: my $doubledots;
10877: my $startdiff = -1;
10878: for (my $i=0; $i<@urlparts; $i++) {
10879: if ($startdiff == -1) {
10880: unless ($urlparts[$i] eq $parts[$i]) {
10881: $startdiff = $i;
10882: $doubledots .= '../';
10883: }
10884: } else {
10885: $doubledots .= '../';
10886: }
10887: }
10888: if ($startdiff > -1) {
10889: $cleanpath = $doubledots;
10890: for (my $i=$startdiff; $i<@parts; $i++) {
10891: $cleanpath .= $parts[$i].'/';
10892: }
10893: }
10894: }
10895: $cleanpath =~ s{(/)$}{};
10896: return $cleanpath;
10897: }
1.31 albertel 10898:
1.1053 raeburn 10899: sub is_archive_file {
10900: my ($mimetype) = @_;
10901: if (($mimetype eq 'application/octet-stream') ||
10902: ($mimetype eq 'application/x-stuffit') ||
10903: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10904: return 1;
10905: }
10906: return;
10907: }
10908:
10909: sub decompress_form {
1.1065 raeburn 10910: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10911: my %lt = &Apache::lonlocal::texthash (
10912: this => 'This file is an archive file.',
1.1067 raeburn 10913: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10914: itsc => 'Its contents are as follows:',
1.1053 raeburn 10915: youm => 'You may wish to extract its contents.',
10916: extr => 'Extract contents',
1.1067 raeburn 10917: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10918: proa => 'Process automatically?',
1.1053 raeburn 10919: yes => 'Yes',
10920: no => 'No',
1.1067 raeburn 10921: fold => 'Title for folder containing movie',
10922: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10923: );
1.1065 raeburn 10924: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10925: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10926: my $info = &list_archive_contents($fileloc,\@paths);
10927: if (@paths) {
10928: foreach my $path (@paths) {
10929: $path =~ s{^/}{};
1.1067 raeburn 10930: if ($path =~ m{^([^/]+)/$}) {
10931: $topdir = $1;
10932: }
1.1065 raeburn 10933: if ($path =~ m{^([^/]+)/}) {
10934: $toplevel{$1} = $path;
10935: } else {
10936: $toplevel{$path} = $path;
10937: }
10938: }
10939: }
1.1067 raeburn 10940: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10941: my @camtasia = ("$topdir/","$topdir/index.html",
10942: "$topdir/media/",
10943: "$topdir/media/$topdir.mp4",
10944: "$topdir/media/FirstFrame.png",
10945: "$topdir/media/player.swf",
10946: "$topdir/media/swfobject.js",
10947: "$topdir/media/expressInstall.swf");
10948: my @diffs = &compare_arrays(\@paths,\@camtasia);
10949: if (@diffs == 0) {
10950: $is_camtasia = 1;
10951: }
10952: }
10953: my $output;
10954: if ($is_camtasia) {
10955: $output = <<"ENDCAM";
10956: <script type="text/javascript" language="Javascript">
10957: // <![CDATA[
10958:
10959: function camtasiaToggle() {
10960: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10961: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10962: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10963:
10964: document.getElementById('camtasia_titles').style.display='block';
10965: } else {
10966: document.getElementById('camtasia_titles').style.display='none';
10967: }
10968: }
10969: }
10970: return;
10971: }
10972:
10973: // ]]>
10974: </script>
10975: <p>$lt{'camt'}</p>
10976: ENDCAM
1.1065 raeburn 10977: } else {
1.1067 raeburn 10978: $output = '<p>'.$lt{'this'};
10979: if ($info eq '') {
10980: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10981: } else {
10982: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10983: '<div><pre>'.$info.'</pre></div>';
10984: }
1.1065 raeburn 10985: }
1.1067 raeburn 10986: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10987: my $duplicates;
10988: my $num = 0;
10989: if (ref($dirlist) eq 'ARRAY') {
10990: foreach my $item (@{$dirlist}) {
10991: if (ref($item) eq 'ARRAY') {
10992: if (exists($toplevel{$item->[0]})) {
10993: $duplicates .=
10994: &start_data_table_row().
10995: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10996: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10997: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10998: 'value="1" />'.&mt('Yes').'</label>'.
10999: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11000: '<td>'.$item->[0].'</td>';
11001: if ($item->[2]) {
11002: $duplicates .= '<td>'.&mt('Directory').'</td>';
11003: } else {
11004: $duplicates .= '<td>'.&mt('File').'</td>';
11005: }
11006: $duplicates .= '<td>'.$item->[3].'</td>'.
11007: '<td>'.
11008: &Apache::lonlocal::locallocaltime($item->[4]).
11009: '</td>'.
11010: &end_data_table_row();
11011: $num ++;
11012: }
11013: }
11014: }
11015: }
11016: my $itemcount;
11017: if (@paths > 0) {
11018: $itemcount = scalar(@paths);
11019: } else {
11020: $itemcount = 1;
11021: }
1.1067 raeburn 11022: if ($is_camtasia) {
11023: $output .= $lt{'auto'}.'<br />'.
11024: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
11025: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
11026: $lt{'yes'}.'</label> <label>'.
11027: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11028: $lt{'no'}.'</label></span><br />'.
11029: '<div id="camtasia_titles" style="display:block">'.
11030: &Apache::lonhtmlcommon::start_pick_box().
11031: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11032: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11033: &Apache::lonhtmlcommon::row_closure().
11034: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11035: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11036: &Apache::lonhtmlcommon::row_closure(1).
11037: &Apache::lonhtmlcommon::end_pick_box().
11038: '</div>';
11039: }
1.1065 raeburn 11040: $output .=
11041: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11042: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11043: "\n";
1.1065 raeburn 11044: if ($duplicates ne '') {
11045: $output .= '<p><span class="LC_warning">'.
11046: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11047: &start_data_table().
11048: &start_data_table_header_row().
11049: '<th>'.&mt('Overwrite?').'</th>'.
11050: '<th>'.&mt('Name').'</th>'.
11051: '<th>'.&mt('Type').'</th>'.
11052: '<th>'.&mt('Size').'</th>'.
11053: '<th>'.&mt('Last modified').'</th>'.
11054: &end_data_table_header_row().
11055: $duplicates.
11056: &end_data_table().
11057: '</p>';
11058: }
1.1067 raeburn 11059: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11060: if (ref($hiddenelements) eq 'HASH') {
11061: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11062: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11063: }
11064: }
11065: $output .= <<"END";
1.1067 raeburn 11066: <br />
1.1053 raeburn 11067: <input type="submit" name="decompress" value="$lt{'extr'}" />
11068: </form>
11069: $noextract
11070: END
11071: return $output;
11072: }
11073:
1.1065 raeburn 11074: sub decompression_utility {
11075: my ($program) = @_;
11076: my @utilities = ('tar','gunzip','bunzip2','unzip');
11077: my $location;
11078: if (grep(/^\Q$program\E$/,@utilities)) {
11079: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11080: '/usr/sbin/') {
11081: if (-x $dir.$program) {
11082: $location = $dir.$program;
11083: last;
11084: }
11085: }
11086: }
11087: return $location;
11088: }
11089:
11090: sub list_archive_contents {
11091: my ($file,$pathsref) = @_;
11092: my (@cmd,$output);
11093: my $needsregexp;
11094: if ($file =~ /\.zip$/) {
11095: @cmd = (&decompression_utility('unzip'),"-l");
11096: $needsregexp = 1;
11097: } elsif (($file =~ m/\.tar\.gz$/) ||
11098: ($file =~ /\.tgz$/)) {
11099: @cmd = (&decompression_utility('tar'),"-ztf");
11100: } elsif ($file =~ /\.tar\.bz2$/) {
11101: @cmd = (&decompression_utility('tar'),"-jtf");
11102: } elsif ($file =~ m|\.tar$|) {
11103: @cmd = (&decompression_utility('tar'),"-tf");
11104: }
11105: if (@cmd) {
11106: undef($!);
11107: undef($@);
11108: if (open(my $fh,"-|", @cmd, $file)) {
11109: while (my $line = <$fh>) {
11110: $output .= $line;
11111: chomp($line);
11112: my $item;
11113: if ($needsregexp) {
11114: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11115: } else {
11116: $item = $line;
11117: }
11118: if ($item ne '') {
11119: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11120: push(@{$pathsref},$item);
11121: }
11122: }
11123: }
11124: close($fh);
11125: }
11126: }
11127: return $output;
11128: }
11129:
1.1053 raeburn 11130: sub decompress_uploaded_file {
11131: my ($file,$dir) = @_;
11132: &Apache::lonnet::appenv({'cgi.file' => $file});
11133: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11134: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11135: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11136: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11137: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11138: my $decompressed = $env{'cgi.decompressed'};
11139: &Apache::lonnet::delenv('cgi.file');
11140: &Apache::lonnet::delenv('cgi.dir');
11141: &Apache::lonnet::delenv('cgi.decompressed');
11142: return ($decompressed,$result);
11143: }
11144:
1.1055 raeburn 11145: sub process_decompression {
11146: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11147: my ($dir,$error,$warning,$output);
11148: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1120 bisitz 11149: $error = &mt('Filename not a supported archive file type.').
11150: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11151: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11152: } else {
11153: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11154: if ($docuhome eq 'no_host') {
11155: $error = &mt('Could not determine home server for course.');
11156: } else {
11157: my @ids=&Apache::lonnet::current_machine_ids();
11158: my $currdir = "$dir_root/$destination";
11159: if (grep(/^\Q$docuhome\E$/,@ids)) {
11160: $dir = &LONCAPA::propath($docudom,$docuname).
11161: "$dir_root/$destination";
11162: } else {
11163: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11164: "$dir_root/$docudom/$docuname/$destination";
11165: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11166: $error = &mt('Archive file not found.');
11167: }
11168: }
1.1065 raeburn 11169: my (@to_overwrite,@to_skip);
11170: if ($env{'form.archive_overwrite_total'} > 0) {
11171: my $total = $env{'form.archive_overwrite_total'};
11172: for (my $i=0; $i<$total; $i++) {
11173: if ($env{'form.archive_overwrite_'.$i} == 1) {
11174: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11175: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11176: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11177: }
11178: }
11179: }
11180: my $numskip = scalar(@to_skip);
11181: if (($numskip > 0) &&
11182: ($numskip == $env{'form.archive_itemcount'})) {
11183: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11184: } elsif ($dir eq '') {
1.1055 raeburn 11185: $error = &mt('Directory containing archive file unavailable.');
11186: } elsif (!$error) {
1.1065 raeburn 11187: my ($decompressed,$display);
11188: if ($numskip > 0) {
11189: my $tempdir = time.'_'.$$.int(rand(10000));
11190: mkdir("$dir/$tempdir",0755);
11191: system("mv $dir/$file $dir/$tempdir/$file");
11192: ($decompressed,$display) =
11193: &decompress_uploaded_file($file,"$dir/$tempdir");
11194: foreach my $item (@to_skip) {
11195: if (($item ne '') && ($item !~ /\.\./)) {
11196: if (-f "$dir/$tempdir/$item") {
11197: unlink("$dir/$tempdir/$item");
11198: } elsif (-d "$dir/$tempdir/$item") {
11199: system("rm -rf $dir/$tempdir/$item");
11200: }
11201: }
11202: }
11203: system("mv $dir/$tempdir/* $dir");
11204: rmdir("$dir/$tempdir");
11205: } else {
11206: ($decompressed,$display) =
11207: &decompress_uploaded_file($file,$dir);
11208: }
1.1055 raeburn 11209: if ($decompressed eq 'ok') {
1.1065 raeburn 11210: $output = '<p class="LC_info">'.
11211: &mt('Files extracted successfully from archive.').
11212: '</p>'."\n";
1.1055 raeburn 11213: my ($warning,$result,@contents);
11214: my ($newdirlistref,$newlisterror) =
11215: &Apache::lonnet::dirlist($currdir,$docudom,
11216: $docuname,1);
11217: my (%is_dir,%changes,@newitems);
11218: my $dirptr = 16384;
1.1065 raeburn 11219: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11220: foreach my $dir_line (@{$newdirlistref}) {
11221: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11222: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11223: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11224: push(@newitems,$item);
11225: if ($dirptr&$testdir) {
11226: $is_dir{$item} = 1;
11227: }
11228: $changes{$item} = 1;
11229: }
11230: }
11231: }
11232: if (keys(%changes) > 0) {
11233: foreach my $item (sort(@newitems)) {
11234: if ($changes{$item}) {
11235: push(@contents,$item);
11236: }
11237: }
11238: }
11239: if (@contents > 0) {
1.1067 raeburn 11240: my $wantform;
11241: unless ($env{'form.autoextract_camtasia'}) {
11242: $wantform = 1;
11243: }
1.1056 raeburn 11244: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11245: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11246: $currdir,\%is_dir,
11247: \%children,\%parent,
1.1056 raeburn 11248: \@contents,\%dirorder,
11249: \%titles,$wantform);
1.1055 raeburn 11250: if ($datatable ne '') {
11251: $output .= &archive_options_form('decompressed',$datatable,
11252: $count,$hiddenelem);
1.1065 raeburn 11253: my $startcount = 6;
1.1055 raeburn 11254: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11255: \%titles,\%children);
1.1055 raeburn 11256: }
1.1067 raeburn 11257: if ($env{'form.autoextract_camtasia'}) {
11258: my %displayed;
11259: my $total = 1;
11260: $env{'form.archive_directory'} = [];
11261: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11262: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11263: $path =~ s{/$}{};
11264: my $item;
11265: if ($path ne '') {
11266: $item = "$path/$titles{$i}";
11267: } else {
11268: $item = $titles{$i};
11269: }
11270: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11271: if ($item eq $contents[0]) {
11272: push(@{$env{'form.archive_directory'}},$i);
11273: $env{'form.archive_'.$i} = 'display';
11274: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11275: $displayed{'folder'} = $i;
11276: } elsif ($item eq "$contents[0]/index.html") {
11277: $env{'form.archive_'.$i} = 'display';
11278: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11279: $displayed{'web'} = $i;
11280: } else {
11281: if ($item eq "$contents[0]/media") {
11282: push(@{$env{'form.archive_directory'}},$i);
11283: }
11284: $env{'form.archive_'.$i} = 'dependency';
11285: }
11286: $total ++;
11287: }
11288: for (my $i=1; $i<$total; $i++) {
11289: next if ($i == $displayed{'web'});
11290: next if ($i == $displayed{'folder'});
11291: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11292: }
11293: $env{'form.phase'} = 'decompress_cleanup';
11294: $env{'form.archivedelete'} = 1;
11295: $env{'form.archive_count'} = $total-1;
11296: $output .=
11297: &process_extracted_files('coursedocs',$docudom,
11298: $docuname,$destination,
11299: $dir_root,$hiddenelem);
11300: }
1.1055 raeburn 11301: } else {
11302: $warning = &mt('No new items extracted from archive file.');
11303: }
11304: } else {
11305: $output = $display;
11306: $error = &mt('An error occurred during extraction from the archive file.');
11307: }
11308: }
11309: }
11310: }
11311: if ($error) {
11312: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11313: $error.'</p>'."\n";
11314: }
11315: if ($warning) {
11316: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11317: }
11318: return $output;
11319: }
11320:
11321: sub get_extracted {
1.1056 raeburn 11322: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11323: $titles,$wantform) = @_;
1.1055 raeburn 11324: my $count = 0;
11325: my $depth = 0;
11326: my $datatable;
1.1056 raeburn 11327: my @hierarchy;
1.1055 raeburn 11328: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11329: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11330: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11331: foreach my $item (@{$contents}) {
11332: $count ++;
1.1056 raeburn 11333: @{$dirorder->{$count}} = @hierarchy;
11334: $titles->{$count} = $item;
1.1055 raeburn 11335: &archive_hierarchy($depth,$count,$parent,$children);
11336: if ($wantform) {
11337: $datatable .= &archive_row($is_dir->{$item},$item,
11338: $currdir,$depth,$count);
11339: }
11340: if ($is_dir->{$item}) {
11341: $depth ++;
1.1056 raeburn 11342: push(@hierarchy,$count);
11343: $parent->{$depth} = $count;
1.1055 raeburn 11344: $datatable .=
11345: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11346: \$depth,\$count,\@hierarchy,$dirorder,
11347: $children,$parent,$titles,$wantform);
1.1055 raeburn 11348: $depth --;
1.1056 raeburn 11349: pop(@hierarchy);
1.1055 raeburn 11350: }
11351: }
11352: return ($count,$datatable);
11353: }
11354:
11355: sub recurse_extracted_archive {
1.1056 raeburn 11356: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11357: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11358: my $result='';
1.1056 raeburn 11359: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11360: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11361: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11362: return $result;
11363: }
11364: my $dirptr = 16384;
11365: my ($newdirlistref,$newlisterror) =
11366: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11367: if (ref($newdirlistref) eq 'ARRAY') {
11368: foreach my $dir_line (@{$newdirlistref}) {
11369: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11370: unless ($item =~ /^\.+$/) {
11371: $$count ++;
1.1056 raeburn 11372: @{$dirorder->{$$count}} = @{$hierarchy};
11373: $titles->{$$count} = $item;
1.1055 raeburn 11374: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11375:
1.1055 raeburn 11376: my $is_dir;
11377: if ($dirptr&$testdir) {
11378: $is_dir = 1;
11379: }
11380: if ($wantform) {
11381: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11382: }
11383: if ($is_dir) {
11384: $$depth ++;
1.1056 raeburn 11385: push(@{$hierarchy},$$count);
11386: $parent->{$$depth} = $$count;
1.1055 raeburn 11387: $result .=
11388: &recurse_extracted_archive("$currdir/$item",$docudom,
11389: $docuname,$depth,$count,
1.1056 raeburn 11390: $hierarchy,$dirorder,$children,
11391: $parent,$titles,$wantform);
1.1055 raeburn 11392: $$depth --;
1.1056 raeburn 11393: pop(@{$hierarchy});
1.1055 raeburn 11394: }
11395: }
11396: }
11397: }
11398: return $result;
11399: }
11400:
11401: sub archive_hierarchy {
11402: my ($depth,$count,$parent,$children) =@_;
11403: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11404: if (exists($parent->{$depth})) {
11405: $children->{$parent->{$depth}} .= $count.':';
11406: }
11407: }
11408: return;
11409: }
11410:
11411: sub archive_row {
11412: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11413: my ($name) = ($item =~ m{([^/]+)$});
11414: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11415: 'display' => 'Add as file',
1.1055 raeburn 11416: 'dependency' => 'Include as dependency',
11417: 'discard' => 'Discard',
11418: );
11419: if ($is_dir) {
1.1059 raeburn 11420: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11421: }
1.1056 raeburn 11422: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11423: my $offset = 0;
1.1055 raeburn 11424: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11425: $offset ++;
1.1065 raeburn 11426: if ($action ne 'display') {
11427: $offset ++;
11428: }
1.1055 raeburn 11429: $output .= '<td><span class="LC_nobreak">'.
11430: '<label><input type="radio" name="archive_'.$count.
11431: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11432: my $text = $choices{$action};
11433: if ($is_dir) {
11434: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11435: if ($action eq 'display') {
1.1059 raeburn 11436: $text = &mt('Add as folder');
1.1055 raeburn 11437: }
1.1056 raeburn 11438: } else {
11439: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11440:
11441: }
11442: $output .= ' /> '.$choices{$action}.'</label></span>';
11443: if ($action eq 'dependency') {
11444: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11445: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11446: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11447: '<option value=""></option>'."\n".
11448: '</select>'."\n".
11449: '</div>';
1.1059 raeburn 11450: } elsif ($action eq 'display') {
11451: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11452: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11453: '</div>';
1.1055 raeburn 11454: }
1.1056 raeburn 11455: $output .= '</td>';
1.1055 raeburn 11456: }
11457: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11458: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11459: for (my $i=0; $i<$depth; $i++) {
11460: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11461: }
11462: if ($is_dir) {
11463: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11464: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11465: } else {
11466: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11467: }
11468: $output .= ' '.$name.'</td>'."\n".
11469: &end_data_table_row();
11470: return $output;
11471: }
11472:
11473: sub archive_options_form {
1.1065 raeburn 11474: my ($form,$display,$count,$hiddenelem) = @_;
11475: my %lt = &Apache::lonlocal::texthash(
11476: perm => 'Permanently remove archive file?',
11477: hows => 'How should each extracted item be incorporated in the course?',
11478: cont => 'Content actions for all',
11479: addf => 'Add as folder/file',
11480: incd => 'Include as dependency for a displayed file',
11481: disc => 'Discard',
11482: no => 'No',
11483: yes => 'Yes',
11484: save => 'Save',
11485: );
11486: my $output = <<"END";
11487: <form name="$form" method="post" action="">
11488: <p><span class="LC_nobreak">$lt{'perm'}
11489: <label>
11490: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11491: </label>
11492:
11493: <label>
11494: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11495: </span>
11496: </p>
11497: <input type="hidden" name="phase" value="decompress_cleanup" />
11498: <br />$lt{'hows'}
11499: <div class="LC_columnSection">
11500: <fieldset>
11501: <legend>$lt{'cont'}</legend>
11502: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11503: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11504: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11505: </fieldset>
11506: </div>
11507: END
11508: return $output.
1.1055 raeburn 11509: &start_data_table()."\n".
1.1065 raeburn 11510: $display."\n".
1.1055 raeburn 11511: &end_data_table()."\n".
11512: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11513: $hiddenelem.
1.1065 raeburn 11514: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11515: '</form>';
11516: }
11517:
11518: sub archive_javascript {
1.1056 raeburn 11519: my ($startcount,$numitems,$titles,$children) = @_;
11520: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11521: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11522: my $scripttag = <<START;
11523: <script type="text/javascript">
11524: // <![CDATA[
11525:
11526: function checkAll(form,prefix) {
11527: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11528: for (var i=0; i < form.elements.length; i++) {
11529: var id = form.elements[i].id;
11530: if ((id != '') && (id != undefined)) {
11531: if (idstr.test(id)) {
11532: if (form.elements[i].type == 'radio') {
11533: form.elements[i].checked = true;
1.1056 raeburn 11534: var nostart = i-$startcount;
1.1059 raeburn 11535: var offset = nostart%7;
11536: var count = (nostart-offset)/7;
1.1056 raeburn 11537: dependencyCheck(form,count,offset);
1.1055 raeburn 11538: }
11539: }
11540: }
11541: }
11542: }
11543:
11544: function propagateCheck(form,count) {
11545: if (count > 0) {
1.1059 raeburn 11546: var startelement = $startcount + ((count-1) * 7);
11547: for (var j=1; j<6; j++) {
11548: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11549: var item = startelement + j;
11550: if (form.elements[item].type == 'radio') {
11551: if (form.elements[item].checked) {
11552: containerCheck(form,count,j);
11553: break;
11554: }
1.1055 raeburn 11555: }
11556: }
11557: }
11558: }
11559: }
11560:
11561: numitems = $numitems
1.1056 raeburn 11562: var titles = new Array(numitems);
11563: var parents = new Array(numitems);
1.1055 raeburn 11564: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11565: parents[i] = new Array;
1.1055 raeburn 11566: }
1.1059 raeburn 11567: var maintitle = '$maintitle';
1.1055 raeburn 11568:
11569: START
11570:
1.1056 raeburn 11571: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11572: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11573: for (my $i=0; $i<@contents; $i ++) {
11574: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11575: }
11576: }
11577:
1.1056 raeburn 11578: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11579: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11580: }
11581:
1.1055 raeburn 11582: $scripttag .= <<END;
11583:
11584: function containerCheck(form,count,offset) {
11585: if (count > 0) {
1.1056 raeburn 11586: dependencyCheck(form,count,offset);
1.1059 raeburn 11587: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11588: form.elements[item].checked = true;
11589: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11590: if (parents[count].length > 0) {
11591: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11592: containerCheck(form,parents[count][j],offset);
11593: }
11594: }
11595: }
11596: }
11597: }
11598:
11599: function dependencyCheck(form,count,offset) {
11600: if (count > 0) {
1.1059 raeburn 11601: var chosen = (offset+$startcount)+7*(count-1);
11602: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11603: var currtype = form.elements[depitem].type;
11604: if (form.elements[chosen].value == 'dependency') {
11605: document.getElementById('arc_depon_'+count).style.display='block';
11606: form.elements[depitem].options.length = 0;
11607: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11608: for (var i=1; i<=numitems; i++) {
11609: if (i == count) {
11610: continue;
11611: }
1.1059 raeburn 11612: var startelement = $startcount + (i-1) * 7;
11613: for (var j=1; j<6; j++) {
11614: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11615: var item = startelement + j;
11616: if (form.elements[item].type == 'radio') {
11617: if (form.elements[item].checked) {
11618: if (form.elements[item].value == 'display') {
11619: var n = form.elements[depitem].options.length;
11620: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11621: }
11622: }
11623: }
11624: }
11625: }
11626: }
11627: } else {
11628: document.getElementById('arc_depon_'+count).style.display='none';
11629: form.elements[depitem].options.length = 0;
11630: form.elements[depitem].options[0] = new Option('Select','',true,true);
11631: }
1.1059 raeburn 11632: titleCheck(form,count,offset);
1.1056 raeburn 11633: }
11634: }
11635:
11636: function propagateSelect(form,count,offset) {
11637: if (count > 0) {
1.1065 raeburn 11638: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11639: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11640: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11641: if (parents[count].length > 0) {
11642: for (var j=0; j<parents[count].length; j++) {
11643: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11644: }
11645: }
11646: }
11647: }
11648: }
1.1056 raeburn 11649:
11650: function containerSelect(form,count,offset,picked) {
11651: if (count > 0) {
1.1065 raeburn 11652: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11653: if (form.elements[item].type == 'radio') {
11654: if (form.elements[item].value == 'dependency') {
11655: if (form.elements[item+1].type == 'select-one') {
11656: for (var i=0; i<form.elements[item+1].options.length; i++) {
11657: if (form.elements[item+1].options[i].value == picked) {
11658: form.elements[item+1].selectedIndex = i;
11659: break;
11660: }
11661: }
11662: }
11663: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11664: if (parents[count].length > 0) {
11665: for (var j=0; j<parents[count].length; j++) {
11666: containerSelect(form,parents[count][j],offset,picked);
11667: }
11668: }
11669: }
11670: }
11671: }
11672: }
11673: }
11674:
1.1059 raeburn 11675: function titleCheck(form,count,offset) {
11676: if (count > 0) {
11677: var chosen = (offset+$startcount)+7*(count-1);
11678: var depitem = $startcount + ((count-1) * 7) + 2;
11679: var currtype = form.elements[depitem].type;
11680: if (form.elements[chosen].value == 'display') {
11681: document.getElementById('arc_title_'+count).style.display='block';
11682: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11683: document.getElementById('archive_title_'+count).value=maintitle;
11684: }
11685: } else {
11686: document.getElementById('arc_title_'+count).style.display='none';
11687: if (currtype == 'text') {
11688: document.getElementById('archive_title_'+count).value='';
11689: }
11690: }
11691: }
11692: return;
11693: }
11694:
1.1055 raeburn 11695: // ]]>
11696: </script>
11697: END
11698: return $scripttag;
11699: }
11700:
11701: sub process_extracted_files {
1.1067 raeburn 11702: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11703: my $numitems = $env{'form.archive_count'};
11704: return unless ($numitems);
11705: my @ids=&Apache::lonnet::current_machine_ids();
11706: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11707: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11708: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11709: if (grep(/^\Q$docuhome\E$/,@ids)) {
11710: $prefix = &LONCAPA::propath($docudom,$docuname);
11711: $pathtocheck = "$dir_root/$destination";
11712: $dir = $dir_root;
11713: $ishome = 1;
11714: } else {
11715: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11716: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11717: $dir = "$dir_root/$docudom/$docuname";
11718: }
11719: my $currdir = "$dir_root/$destination";
11720: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11721: if ($env{'form.folderpath'}) {
11722: my @items = split('&',$env{'form.folderpath'});
11723: $folders{'0'} = $items[-2];
1.1099 raeburn 11724: if ($env{'form.folderpath'} =~ /\:1$/) {
11725: $containers{'0'}='page';
11726: } else {
11727: $containers{'0'}='sequence';
11728: }
1.1055 raeburn 11729: }
11730: my @archdirs = &get_env_multiple('form.archive_directory');
11731: if ($numitems) {
11732: for (my $i=1; $i<=$numitems; $i++) {
11733: my $path = $env{'form.archive_content_'.$i};
11734: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11735: my $item = $1;
11736: $toplevelitems{$item} = $i;
11737: if (grep(/^\Q$i\E$/,@archdirs)) {
11738: $is_dir{$item} = 1;
11739: }
11740: }
11741: }
11742: }
1.1067 raeburn 11743: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11744: if (keys(%toplevelitems) > 0) {
11745: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11746: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11747: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11748: }
1.1066 raeburn 11749: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11750: if ($numitems) {
11751: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11752: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11753: my $path = $env{'form.archive_content_'.$i};
11754: if ($path =~ /^\Q$pathtocheck\E/) {
11755: if ($env{'form.archive_'.$i} eq 'discard') {
11756: if ($prefix ne '' && $path ne '') {
11757: if (-e $prefix.$path) {
1.1066 raeburn 11758: if ((@archdirs > 0) &&
11759: (grep(/^\Q$i\E$/,@archdirs))) {
11760: $todeletedir{$prefix.$path} = 1;
11761: } else {
11762: $todelete{$prefix.$path} = 1;
11763: }
1.1055 raeburn 11764: }
11765: }
11766: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11767: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11768: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11769: $docstitle = $env{'form.archive_title_'.$i};
11770: if ($docstitle eq '') {
11771: $docstitle = $title;
11772: }
1.1055 raeburn 11773: $outer = 0;
1.1056 raeburn 11774: if (ref($dirorder{$i}) eq 'ARRAY') {
11775: if (@{$dirorder{$i}} > 0) {
11776: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11777: if ($env{'form.archive_'.$item} eq 'display') {
11778: $outer = $item;
11779: last;
11780: }
11781: }
11782: }
11783: }
11784: my ($errtext,$fatal) =
11785: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11786: '/'.$folders{$outer}.'.'.
11787: $containers{$outer});
11788: next if ($fatal);
11789: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11790: if ($context eq 'coursedocs') {
1.1056 raeburn 11791: $mapinner{$i} = time;
1.1055 raeburn 11792: $folders{$i} = 'default_'.$mapinner{$i};
11793: $containers{$i} = 'sequence';
11794: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11795: $folders{$i}.'.'.$containers{$i};
11796: my $newidx = &LONCAPA::map::getresidx();
11797: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11798: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11799: push(@LONCAPA::map::order,$newidx);
11800: my ($outtext,$errtext) =
11801: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11802: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11803: '.'.$containers{$outer},1,1);
1.1056 raeburn 11804: $newseqid{$i} = $newidx;
1.1067 raeburn 11805: unless ($errtext) {
11806: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11807: }
1.1055 raeburn 11808: }
11809: } else {
11810: if ($context eq 'coursedocs') {
11811: my $newidx=&LONCAPA::map::getresidx();
11812: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11813: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11814: $title;
11815: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11816: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11817: }
11818: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11819: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11820: }
11821: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11822: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11823: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11824: unless ($ishome) {
11825: my $fetch = "$newdest{$i}/$title";
11826: $fetch =~ s/^\Q$prefix$dir\E//;
11827: $prompttofetch{$fetch} = 1;
11828: }
1.1055 raeburn 11829: }
11830: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11831: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11832: push(@LONCAPA::map::order, $newidx);
11833: my ($outtext,$errtext)=
11834: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11835: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11836: '.'.$containers{$outer},1,1);
1.1067 raeburn 11837: unless ($errtext) {
11838: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11839: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11840: }
11841: }
1.1055 raeburn 11842: }
11843: }
1.1086 raeburn 11844: }
11845: } else {
11846: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11847: }
11848: }
11849: for (my $i=1; $i<=$numitems; $i++) {
11850: next unless ($env{'form.archive_'.$i} eq 'dependency');
11851: my $path = $env{'form.archive_content_'.$i};
11852: if ($path =~ /^\Q$pathtocheck\E/) {
11853: my ($title) = ($path =~ m{/([^/]+)$});
11854: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11855: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11856: if (ref($dirorder{$i}) eq 'ARRAY') {
11857: my ($itemidx,$fullpath,$relpath);
11858: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11859: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11860: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11861: if ($dirorder{$i}->[$j] eq $container) {
11862: $itemidx = $j;
1.1056 raeburn 11863: }
11864: }
1.1086 raeburn 11865: }
11866: if ($itemidx eq '') {
11867: $itemidx = 0;
11868: }
11869: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11870: if ($mapinner{$referrer{$i}}) {
11871: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11872: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11873: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11874: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11875: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11876: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11877: if (!-e $fullpath) {
11878: mkdir($fullpath,0755);
1.1056 raeburn 11879: }
11880: }
1.1086 raeburn 11881: } else {
11882: last;
1.1056 raeburn 11883: }
1.1086 raeburn 11884: }
11885: }
11886: } elsif ($newdest{$referrer{$i}}) {
11887: $fullpath = $newdest{$referrer{$i}};
11888: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11889: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11890: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11891: last;
11892: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11893: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11894: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11895: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11896: if (!-e $fullpath) {
11897: mkdir($fullpath,0755);
1.1056 raeburn 11898: }
11899: }
1.1086 raeburn 11900: } else {
11901: last;
1.1056 raeburn 11902: }
1.1055 raeburn 11903: }
11904: }
1.1086 raeburn 11905: if ($fullpath ne '') {
11906: if (-e "$prefix$path") {
11907: system("mv $prefix$path $fullpath/$title");
11908: }
11909: if (-e "$fullpath/$title") {
11910: my $showpath;
11911: if ($relpath ne '') {
11912: $showpath = "$relpath/$title";
11913: } else {
11914: $showpath = "/$title";
11915: }
11916: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11917: }
11918: unless ($ishome) {
11919: my $fetch = "$fullpath/$title";
11920: $fetch =~ s/^\Q$prefix$dir\E//;
11921: $prompttofetch{$fetch} = 1;
11922: }
11923: }
1.1055 raeburn 11924: }
1.1086 raeburn 11925: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11926: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11927: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11928: }
11929: } else {
11930: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11931: }
11932: }
11933: if (keys(%todelete)) {
11934: foreach my $key (keys(%todelete)) {
11935: unlink($key);
1.1066 raeburn 11936: }
11937: }
11938: if (keys(%todeletedir)) {
11939: foreach my $key (keys(%todeletedir)) {
11940: rmdir($key);
11941: }
11942: }
11943: foreach my $dir (sort(keys(%is_dir))) {
11944: if (($pathtocheck ne '') && ($dir ne '')) {
11945: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11946: }
11947: }
1.1067 raeburn 11948: if ($result ne '') {
11949: $output .= '<ul>'."\n".
11950: $result."\n".
11951: '</ul>';
11952: }
11953: unless ($ishome) {
11954: my $replicationfail;
11955: foreach my $item (keys(%prompttofetch)) {
11956: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11957: unless ($fetchresult eq 'ok') {
11958: $replicationfail .= '<li>'.$item.'</li>'."\n";
11959: }
11960: }
11961: if ($replicationfail) {
11962: $output .= '<p class="LC_error">'.
11963: &mt('Course home server failed to retrieve:').'<ul>'.
11964: $replicationfail.
11965: '</ul></p>';
11966: }
11967: }
1.1055 raeburn 11968: } else {
11969: $warning = &mt('No items found in archive.');
11970: }
11971: if ($error) {
11972: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11973: $error.'</p>'."\n";
11974: }
11975: if ($warning) {
11976: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11977: }
11978: return $output;
11979: }
11980:
1.1066 raeburn 11981: sub cleanup_empty_dirs {
11982: my ($path) = @_;
11983: if (($path ne '') && (-d $path)) {
11984: if (opendir(my $dirh,$path)) {
11985: my @dircontents = grep(!/^\./,readdir($dirh));
11986: my $numitems = 0;
11987: foreach my $item (@dircontents) {
11988: if (-d "$path/$item") {
1.1111 raeburn 11989: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11990: if (-e "$path/$item") {
11991: $numitems ++;
11992: }
11993: } else {
11994: $numitems ++;
11995: }
11996: }
11997: if ($numitems == 0) {
11998: rmdir($path);
11999: }
12000: closedir($dirh);
12001: }
12002: }
12003: return;
12004: }
12005:
1.41 ng 12006: =pod
1.45 matthew 12007:
1.1068 raeburn 12008: =item &get_folder_hierarchy()
12009:
12010: Provides hierarchy of names of folders/sub-folders containing the current
12011: item,
12012:
12013: Inputs: 3
12014: - $navmap - navmaps object
12015:
12016: - $map - url for map (either the trigger itself, or map containing
12017: the resource, which is the trigger).
12018:
12019: - $showitem - 1 => show title for map itself; 0 => do not show.
12020:
12021: Outputs: 1 @pathitems - array of folder/subfolder names.
12022:
12023: =cut
12024:
12025: sub get_folder_hierarchy {
12026: my ($navmap,$map,$showitem) = @_;
12027: my @pathitems;
12028: if (ref($navmap)) {
12029: my $mapres = $navmap->getResourceByUrl($map);
12030: if (ref($mapres)) {
12031: my $pcslist = $mapres->map_hierarchy();
12032: if ($pcslist ne '') {
12033: my @pcs = split(/,/,$pcslist);
12034: foreach my $pc (@pcs) {
12035: if ($pc == 1) {
1.1129 raeburn 12036: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12037: } else {
12038: my $res = $navmap->getByMapPc($pc);
12039: if (ref($res)) {
12040: my $title = $res->compTitle();
12041: $title =~ s/\W+/_/g;
12042: if ($title ne '') {
12043: push(@pathitems,$title);
12044: }
12045: }
12046: }
12047: }
12048: }
1.1071 raeburn 12049: if ($showitem) {
12050: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12051: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12052: } else {
12053: my $maptitle = $mapres->compTitle();
12054: $maptitle =~ s/\W+/_/g;
12055: if ($maptitle ne '') {
12056: push(@pathitems,$maptitle);
12057: }
1.1068 raeburn 12058: }
12059: }
12060: }
12061: }
12062: return @pathitems;
12063: }
12064:
12065: =pod
12066:
1.1015 raeburn 12067: =item * &get_turnedin_filepath()
12068:
12069: Determines path in a user's portfolio file for storage of files uploaded
12070: to a specific essayresponse or dropbox item.
12071:
12072: Inputs: 3 required + 1 optional.
12073: $symb is symb for resource, $uname and $udom are for current user (required).
12074: $caller is optional (can be "submission", if routine is called when storing
12075: an upoaded file when "Submit Answer" button was pressed).
12076:
12077: Returns array containing $path and $multiresp.
12078: $path is path in portfolio. $multiresp is 1 if this resource contains more
12079: than one file upload item. Callers of routine should append partid as a
12080: subdirectory to $path in cases where $multiresp is 1.
12081:
12082: Called by: homework/essayresponse.pm and homework/structuretags.pm
12083:
12084: =cut
12085:
12086: sub get_turnedin_filepath {
12087: my ($symb,$uname,$udom,$caller) = @_;
12088: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12089: my $turnindir;
12090: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12091: $turnindir = $userhash{'turnindir'};
12092: my ($path,$multiresp);
12093: if ($turnindir eq '') {
12094: if ($caller eq 'submission') {
12095: $turnindir = &mt('turned in');
12096: $turnindir =~ s/\W+/_/g;
12097: my %newhash = (
12098: 'turnindir' => $turnindir,
12099: );
12100: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12101: }
12102: }
12103: if ($turnindir ne '') {
12104: $path = '/'.$turnindir.'/';
12105: my ($multipart,$turnin,@pathitems);
12106: my $navmap = Apache::lonnavmaps::navmap->new();
12107: if (defined($navmap)) {
12108: my $mapres = $navmap->getResourceByUrl($map);
12109: if (ref($mapres)) {
12110: my $pcslist = $mapres->map_hierarchy();
12111: if ($pcslist ne '') {
12112: foreach my $pc (split(/,/,$pcslist)) {
12113: my $res = $navmap->getByMapPc($pc);
12114: if (ref($res)) {
12115: my $title = $res->compTitle();
12116: $title =~ s/\W+/_/g;
12117: if ($title ne '') {
12118: push(@pathitems,$title);
12119: }
12120: }
12121: }
12122: }
12123: my $maptitle = $mapres->compTitle();
12124: $maptitle =~ s/\W+/_/g;
12125: if ($maptitle ne '') {
12126: push(@pathitems,$maptitle);
12127: }
12128: unless ($env{'request.state'} eq 'construct') {
12129: my $res = $navmap->getBySymb($symb);
12130: if (ref($res)) {
12131: my $partlist = $res->parts();
12132: my $totaluploads = 0;
12133: if (ref($partlist) eq 'ARRAY') {
12134: foreach my $part (@{$partlist}) {
12135: my @types = $res->responseType($part);
12136: my @ids = $res->responseIds($part);
12137: for (my $i=0; $i < scalar(@ids); $i++) {
12138: if ($types[$i] eq 'essay') {
12139: my $partid = $part.'_'.$ids[$i];
12140: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12141: $totaluploads ++;
12142: }
12143: }
12144: }
12145: }
12146: if ($totaluploads > 1) {
12147: $multiresp = 1;
12148: }
12149: }
12150: }
12151: }
12152: } else {
12153: return;
12154: }
12155: } else {
12156: return;
12157: }
12158: my $restitle=&Apache::lonnet::gettitle($symb);
12159: $restitle =~ s/\W+/_/g;
12160: if ($restitle eq '') {
12161: $restitle = ($resurl =~ m{/[^/]+$});
12162: if ($restitle eq '') {
12163: $restitle = time;
12164: }
12165: }
12166: push(@pathitems,$restitle);
12167: $path .= join('/',@pathitems);
12168: }
12169: return ($path,$multiresp);
12170: }
12171:
12172: =pod
12173:
1.464 albertel 12174: =back
1.41 ng 12175:
1.112 bowersj2 12176: =head1 CSV Upload/Handling functions
1.38 albertel 12177:
1.41 ng 12178: =over 4
12179:
1.648 raeburn 12180: =item * &upfile_store($r)
1.41 ng 12181:
12182: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12183: needs $env{'form.upfile'}
1.41 ng 12184: returns $datatoken to be put into hidden field
12185:
12186: =cut
1.31 albertel 12187:
12188: sub upfile_store {
12189: my $r=shift;
1.258 albertel 12190: $env{'form.upfile'}=~s/\r/\n/gs;
12191: $env{'form.upfile'}=~s/\f/\n/gs;
12192: $env{'form.upfile'}=~s/\n+/\n/gs;
12193: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12194:
1.258 albertel 12195: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12196: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12197: {
1.158 raeburn 12198: my $datafile = $r->dir_config('lonDaemons').
12199: '/tmp/'.$datatoken.'.tmp';
12200: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12201: print $fh $env{'form.upfile'};
1.158 raeburn 12202: close($fh);
12203: }
1.31 albertel 12204: }
12205: return $datatoken;
12206: }
12207:
1.56 matthew 12208: =pod
12209:
1.648 raeburn 12210: =item * &load_tmp_file($r)
1.41 ng 12211:
12212: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12213: needs $env{'form.datatoken'},
12214: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12215:
12216: =cut
1.31 albertel 12217:
12218: sub load_tmp_file {
12219: my $r=shift;
12220: my @studentdata=();
12221: {
1.158 raeburn 12222: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12223: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12224: if ( open(my $fh,"<$studentfile") ) {
12225: @studentdata=<$fh>;
12226: close($fh);
12227: }
1.31 albertel 12228: }
1.258 albertel 12229: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12230: }
12231:
1.56 matthew 12232: =pod
12233:
1.648 raeburn 12234: =item * &upfile_record_sep()
1.41 ng 12235:
12236: Separate uploaded file into records
12237: returns array of records,
1.258 albertel 12238: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12239:
12240: =cut
1.31 albertel 12241:
12242: sub upfile_record_sep {
1.258 albertel 12243: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12244: } else {
1.248 albertel 12245: my @records;
1.258 albertel 12246: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12247: if ($line=~/^\s*$/) { next; }
12248: push(@records,$line);
12249: }
12250: return @records;
1.31 albertel 12251: }
12252: }
12253:
1.56 matthew 12254: =pod
12255:
1.648 raeburn 12256: =item * &record_sep($record)
1.41 ng 12257:
1.258 albertel 12258: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12259:
12260: =cut
12261:
1.263 www 12262: sub takeleft {
12263: my $index=shift;
12264: return substr('0000'.$index,-4,4);
12265: }
12266:
1.31 albertel 12267: sub record_sep {
12268: my $record=shift;
12269: my %components=();
1.258 albertel 12270: if ($env{'form.upfiletype'} eq 'xml') {
12271: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12272: my $i=0;
1.356 albertel 12273: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12274: $field=~s/^(\"|\')//;
12275: $field=~s/(\"|\')$//;
1.263 www 12276: $components{&takeleft($i)}=$field;
1.31 albertel 12277: $i++;
12278: }
1.258 albertel 12279: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12280: my $i=0;
1.356 albertel 12281: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12282: $field=~s/^(\"|\')//;
12283: $field=~s/(\"|\')$//;
1.263 www 12284: $components{&takeleft($i)}=$field;
1.31 albertel 12285: $i++;
12286: }
12287: } else {
1.561 www 12288: my $separator=',';
1.480 banghart 12289: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12290: $separator=';';
1.480 banghart 12291: }
1.31 albertel 12292: my $i=0;
1.561 www 12293: # the character we are looking for to indicate the end of a quote or a record
12294: my $looking_for=$separator;
12295: # do not add the characters to the fields
12296: my $ignore=0;
12297: # we just encountered a separator (or the beginning of the record)
12298: my $just_found_separator=1;
12299: # store the field we are working on here
12300: my $field='';
12301: # work our way through all characters in record
12302: foreach my $character ($record=~/(.)/g) {
12303: if ($character eq $looking_for) {
12304: if ($character ne $separator) {
12305: # Found the end of a quote, again looking for separator
12306: $looking_for=$separator;
12307: $ignore=1;
12308: } else {
12309: # Found a separator, store away what we got
12310: $components{&takeleft($i)}=$field;
12311: $i++;
12312: $just_found_separator=1;
12313: $ignore=0;
12314: $field='';
12315: }
12316: next;
12317: }
12318: # single or double quotation marks after a separator indicate beginning of a quote
12319: # we are now looking for the end of the quote and need to ignore separators
12320: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12321: $looking_for=$character;
12322: next;
12323: }
12324: # ignore would be true after we reached the end of a quote
12325: if ($ignore) { next; }
12326: if (($just_found_separator) && ($character=~/\s/)) { next; }
12327: $field.=$character;
12328: $just_found_separator=0;
1.31 albertel 12329: }
1.561 www 12330: # catch the very last entry, since we never encountered the separator
12331: $components{&takeleft($i)}=$field;
1.31 albertel 12332: }
12333: return %components;
12334: }
12335:
1.144 matthew 12336: ######################################################
12337: ######################################################
12338:
1.56 matthew 12339: =pod
12340:
1.648 raeburn 12341: =item * &upfile_select_html()
1.41 ng 12342:
1.144 matthew 12343: Return HTML code to select a file from the users machine and specify
12344: the file type.
1.41 ng 12345:
12346: =cut
12347:
1.144 matthew 12348: ######################################################
12349: ######################################################
1.31 albertel 12350: sub upfile_select_html {
1.144 matthew 12351: my %Types = (
12352: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12353: semisv => &mt('Semicolon separated values'),
1.144 matthew 12354: space => &mt('Space separated'),
12355: tab => &mt('Tabulator separated'),
12356: # xml => &mt('HTML/XML'),
12357: );
12358: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12359: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12360: foreach my $type (sort(keys(%Types))) {
12361: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12362: }
12363: $Str .= "</select>\n";
12364: return $Str;
1.31 albertel 12365: }
12366:
1.301 albertel 12367: sub get_samples {
12368: my ($records,$toget) = @_;
12369: my @samples=({});
12370: my $got=0;
12371: foreach my $rec (@$records) {
12372: my %temp = &record_sep($rec);
12373: if (! grep(/\S/, values(%temp))) { next; }
12374: if (%temp) {
12375: $samples[$got]=\%temp;
12376: $got++;
12377: if ($got == $toget) { last; }
12378: }
12379: }
12380: return \@samples;
12381: }
12382:
1.144 matthew 12383: ######################################################
12384: ######################################################
12385:
1.56 matthew 12386: =pod
12387:
1.648 raeburn 12388: =item * &csv_print_samples($r,$records)
1.41 ng 12389:
12390: Prints a table of sample values from each column uploaded $r is an
12391: Apache Request ref, $records is an arrayref from
12392: &Apache::loncommon::upfile_record_sep
12393:
12394: =cut
12395:
1.144 matthew 12396: ######################################################
12397: ######################################################
1.31 albertel 12398: sub csv_print_samples {
12399: my ($r,$records) = @_;
1.662 bisitz 12400: my $samples = &get_samples($records,5);
1.301 albertel 12401:
1.594 raeburn 12402: $r->print(&mt('Samples').'<br />'.&start_data_table().
12403: &start_data_table_header_row());
1.356 albertel 12404: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12405: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12406: $r->print(&end_data_table_header_row());
1.301 albertel 12407: foreach my $hash (@$samples) {
1.594 raeburn 12408: $r->print(&start_data_table_row());
1.356 albertel 12409: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12410: $r->print('<td>');
1.356 albertel 12411: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12412: $r->print('</td>');
12413: }
1.594 raeburn 12414: $r->print(&end_data_table_row());
1.31 albertel 12415: }
1.594 raeburn 12416: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12417: }
12418:
1.144 matthew 12419: ######################################################
12420: ######################################################
12421:
1.56 matthew 12422: =pod
12423:
1.648 raeburn 12424: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12425:
12426: Prints a table to create associations between values and table columns.
1.144 matthew 12427:
1.41 ng 12428: $r is an Apache Request ref,
12429: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12430: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12431:
12432: =cut
12433:
1.144 matthew 12434: ######################################################
12435: ######################################################
1.31 albertel 12436: sub csv_print_select_table {
12437: my ($r,$records,$d) = @_;
1.301 albertel 12438: my $i=0;
12439: my $samples = &get_samples($records,1);
1.144 matthew 12440: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12441: &start_data_table().&start_data_table_header_row().
1.144 matthew 12442: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12443: '<th>'.&mt('Column').'</th>'.
12444: &end_data_table_header_row()."\n");
1.356 albertel 12445: foreach my $array_ref (@$d) {
12446: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12447: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12448:
1.875 bisitz 12449: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12450: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12451: $r->print('<option value="none"></option>');
1.356 albertel 12452: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12453: $r->print('<option value="'.$sample.'"'.
12454: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12455: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12456: }
1.594 raeburn 12457: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12458: $i++;
12459: }
1.594 raeburn 12460: $r->print(&end_data_table());
1.31 albertel 12461: $i--;
12462: return $i;
12463: }
1.56 matthew 12464:
1.144 matthew 12465: ######################################################
12466: ######################################################
12467:
1.56 matthew 12468: =pod
1.31 albertel 12469:
1.648 raeburn 12470: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12471:
12472: Prints a table of sample values from the upload and can make associate samples to internal names.
12473:
12474: $r is an Apache Request ref,
12475: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12476: $d is an array of 2 element arrays (internal name, displayed name)
12477:
12478: =cut
12479:
1.144 matthew 12480: ######################################################
12481: ######################################################
1.31 albertel 12482: sub csv_samples_select_table {
12483: my ($r,$records,$d) = @_;
12484: my $i=0;
1.144 matthew 12485: #
1.662 bisitz 12486: my $max_samples = 5;
12487: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12488: $r->print(&start_data_table().
12489: &start_data_table_header_row().'<th>'.
12490: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12491: &end_data_table_header_row());
1.301 albertel 12492:
12493: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12494: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12495: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12496: foreach my $option (@$d) {
12497: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12498: $r->print('<option value="'.$value.'"'.
1.253 albertel 12499: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12500: $display.'</option>');
1.31 albertel 12501: }
12502: $r->print('</select></td><td>');
1.662 bisitz 12503: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12504: if (defined($samples->[$line]{$key})) {
12505: $r->print($samples->[$line]{$key}."<br />\n");
12506: }
12507: }
1.594 raeburn 12508: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12509: $i++;
12510: }
1.594 raeburn 12511: $r->print(&end_data_table());
1.31 albertel 12512: $i--;
12513: return($i);
1.115 matthew 12514: }
12515:
1.144 matthew 12516: ######################################################
12517: ######################################################
12518:
1.115 matthew 12519: =pod
12520:
1.648 raeburn 12521: =item * &clean_excel_name($name)
1.115 matthew 12522:
12523: Returns a replacement for $name which does not contain any illegal characters.
12524:
12525: =cut
12526:
1.144 matthew 12527: ######################################################
12528: ######################################################
1.115 matthew 12529: sub clean_excel_name {
12530: my ($name) = @_;
12531: $name =~ s/[:\*\?\/\\]//g;
12532: if (length($name) > 31) {
12533: $name = substr($name,0,31);
12534: }
12535: return $name;
1.25 albertel 12536: }
1.84 albertel 12537:
1.85 albertel 12538: =pod
12539:
1.648 raeburn 12540: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12541:
12542: Returns either 1 or undef
12543:
12544: 1 if the part is to be hidden, undef if it is to be shown
12545:
12546: Arguments are:
12547:
12548: $id the id of the part to be checked
12549: $symb, optional the symb of the resource to check
12550: $udom, optional the domain of the user to check for
12551: $uname, optional the username of the user to check for
12552:
12553: =cut
1.84 albertel 12554:
12555: sub check_if_partid_hidden {
12556: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12557: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12558: $symb,$udom,$uname);
1.141 albertel 12559: my $truth=1;
12560: #if the string starts with !, then the list is the list to show not hide
12561: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12562: my @hiddenlist=split(/,/,$hiddenparts);
12563: foreach my $checkid (@hiddenlist) {
1.141 albertel 12564: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12565: }
1.141 albertel 12566: return !$truth;
1.84 albertel 12567: }
1.127 matthew 12568:
1.138 matthew 12569:
12570: ############################################################
12571: ############################################################
12572:
12573: =pod
12574:
1.157 matthew 12575: =back
12576:
1.138 matthew 12577: =head1 cgi-bin script and graphing routines
12578:
1.157 matthew 12579: =over 4
12580:
1.648 raeburn 12581: =item * &get_cgi_id()
1.138 matthew 12582:
12583: Inputs: none
12584:
12585: Returns an id which can be used to pass environment variables
12586: to various cgi-bin scripts. These environment variables will
12587: be removed from the users environment after a given time by
12588: the routine &Apache::lonnet::transfer_profile_to_env.
12589:
12590: =cut
12591:
12592: ############################################################
12593: ############################################################
1.152 albertel 12594: my $uniq=0;
1.136 matthew 12595: sub get_cgi_id {
1.154 albertel 12596: $uniq=($uniq+1)%100000;
1.280 albertel 12597: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12598: }
12599:
1.127 matthew 12600: ############################################################
12601: ############################################################
12602:
12603: =pod
12604:
1.648 raeburn 12605: =item * &DrawBarGraph()
1.127 matthew 12606:
1.138 matthew 12607: Facilitates the plotting of data in a (stacked) bar graph.
12608: Puts plot definition data into the users environment in order for
12609: graph.png to plot it. Returns an <img> tag for the plot.
12610: The bars on the plot are labeled '1','2',...,'n'.
12611:
12612: Inputs:
12613:
12614: =over 4
12615:
12616: =item $Title: string, the title of the plot
12617:
12618: =item $xlabel: string, text describing the X-axis of the plot
12619:
12620: =item $ylabel: string, text describing the Y-axis of the plot
12621:
12622: =item $Max: scalar, the maximum Y value to use in the plot
12623: If $Max is < any data point, the graph will not be rendered.
12624:
1.140 matthew 12625: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12626: they are plotted. If undefined, default values will be used.
12627:
1.178 matthew 12628: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12629:
1.138 matthew 12630: =item @Values: An array of array references. Each array reference holds data
12631: to be plotted in a stacked bar chart.
12632:
1.239 matthew 12633: =item If the final element of @Values is a hash reference the key/value
12634: pairs will be added to the graph definition.
12635:
1.138 matthew 12636: =back
12637:
12638: Returns:
12639:
12640: An <img> tag which references graph.png and the appropriate identifying
12641: information for the plot.
12642:
1.127 matthew 12643: =cut
12644:
12645: ############################################################
12646: ############################################################
1.134 matthew 12647: sub DrawBarGraph {
1.178 matthew 12648: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12649: #
12650: if (! defined($colors)) {
12651: $colors = ['#33ff00',
12652: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12653: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12654: ];
12655: }
1.228 matthew 12656: my $extra_settings = {};
12657: if (ref($Values[-1]) eq 'HASH') {
12658: $extra_settings = pop(@Values);
12659: }
1.127 matthew 12660: #
1.136 matthew 12661: my $identifier = &get_cgi_id();
12662: my $id = 'cgi.'.$identifier;
1.129 matthew 12663: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12664: return '';
12665: }
1.225 matthew 12666: #
12667: my @Labels;
12668: if (defined($labels)) {
12669: @Labels = @$labels;
12670: } else {
12671: for (my $i=0;$i<@{$Values[0]};$i++) {
12672: push (@Labels,$i+1);
12673: }
12674: }
12675: #
1.129 matthew 12676: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12677: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12678: my %ValuesHash;
12679: my $NumSets=1;
12680: foreach my $array (@Values) {
12681: next if (! ref($array));
1.136 matthew 12682: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12683: join(',',@$array);
1.129 matthew 12684: }
1.127 matthew 12685: #
1.136 matthew 12686: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12687: if ($NumBars < 3) {
12688: $width = 120+$NumBars*32;
1.220 matthew 12689: $xskip = 1;
1.225 matthew 12690: $bar_width = 30;
12691: } elsif ($NumBars < 5) {
12692: $width = 120+$NumBars*20;
12693: $xskip = 1;
12694: $bar_width = 20;
1.220 matthew 12695: } elsif ($NumBars < 10) {
1.136 matthew 12696: $width = 120+$NumBars*15;
12697: $xskip = 1;
12698: $bar_width = 15;
12699: } elsif ($NumBars <= 25) {
12700: $width = 120+$NumBars*11;
12701: $xskip = 5;
12702: $bar_width = 8;
12703: } elsif ($NumBars <= 50) {
12704: $width = 120+$NumBars*8;
12705: $xskip = 5;
12706: $bar_width = 4;
12707: } else {
12708: $width = 120+$NumBars*8;
12709: $xskip = 5;
12710: $bar_width = 4;
12711: }
12712: #
1.137 matthew 12713: $Max = 1 if ($Max < 1);
12714: if ( int($Max) < $Max ) {
12715: $Max++;
12716: $Max = int($Max);
12717: }
1.127 matthew 12718: $Title = '' if (! defined($Title));
12719: $xlabel = '' if (! defined($xlabel));
12720: $ylabel = '' if (! defined($ylabel));
1.369 www 12721: $ValuesHash{$id.'.title'} = &escape($Title);
12722: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12723: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12724: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12725: $ValuesHash{$id.'.NumBars'} = $NumBars;
12726: $ValuesHash{$id.'.NumSets'} = $NumSets;
12727: $ValuesHash{$id.'.PlotType'} = 'bar';
12728: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12729: $ValuesHash{$id.'.height'} = $height;
12730: $ValuesHash{$id.'.width'} = $width;
12731: $ValuesHash{$id.'.xskip'} = $xskip;
12732: $ValuesHash{$id.'.bar_width'} = $bar_width;
12733: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12734: #
1.228 matthew 12735: # Deal with other parameters
12736: while (my ($key,$value) = each(%$extra_settings)) {
12737: $ValuesHash{$id.'.'.$key} = $value;
12738: }
12739: #
1.646 raeburn 12740: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12741: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12742: }
12743:
12744: ############################################################
12745: ############################################################
12746:
12747: =pod
12748:
1.648 raeburn 12749: =item * &DrawXYGraph()
1.137 matthew 12750:
1.138 matthew 12751: Facilitates the plotting of data in an XY graph.
12752: Puts plot definition data into the users environment in order for
12753: graph.png to plot it. Returns an <img> tag for the plot.
12754:
12755: Inputs:
12756:
12757: =over 4
12758:
12759: =item $Title: string, the title of the plot
12760:
12761: =item $xlabel: string, text describing the X-axis of the plot
12762:
12763: =item $ylabel: string, text describing the Y-axis of the plot
12764:
12765: =item $Max: scalar, the maximum Y value to use in the plot
12766: If $Max is < any data point, the graph will not be rendered.
12767:
12768: =item $colors: Array ref containing the hex color codes for the data to be
12769: plotted in. If undefined, default values will be used.
12770:
12771: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12772:
12773: =item $Ydata: Array ref containing Array refs.
1.185 www 12774: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12775:
12776: =item %Values: hash indicating or overriding any default values which are
12777: passed to graph.png.
12778: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12779:
12780: =back
12781:
12782: Returns:
12783:
12784: An <img> tag which references graph.png and the appropriate identifying
12785: information for the plot.
12786:
1.137 matthew 12787: =cut
12788:
12789: ############################################################
12790: ############################################################
12791: sub DrawXYGraph {
12792: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12793: #
12794: # Create the identifier for the graph
12795: my $identifier = &get_cgi_id();
12796: my $id = 'cgi.'.$identifier;
12797: #
12798: $Title = '' if (! defined($Title));
12799: $xlabel = '' if (! defined($xlabel));
12800: $ylabel = '' if (! defined($ylabel));
12801: my %ValuesHash =
12802: (
1.369 www 12803: $id.'.title' => &escape($Title),
12804: $id.'.xlabel' => &escape($xlabel),
12805: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12806: $id.'.y_max_value'=> $Max,
12807: $id.'.labels' => join(',',@$Xlabels),
12808: $id.'.PlotType' => 'XY',
12809: );
12810: #
12811: if (defined($colors) && ref($colors) eq 'ARRAY') {
12812: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12813: }
12814: #
12815: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12816: return '';
12817: }
12818: my $NumSets=1;
1.138 matthew 12819: foreach my $array (@{$Ydata}){
1.137 matthew 12820: next if (! ref($array));
12821: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12822: }
1.138 matthew 12823: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12824: #
12825: # Deal with other parameters
12826: while (my ($key,$value) = each(%Values)) {
12827: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12828: }
12829: #
1.646 raeburn 12830: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12831: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12832: }
12833:
12834: ############################################################
12835: ############################################################
12836:
12837: =pod
12838:
1.648 raeburn 12839: =item * &DrawXYYGraph()
1.138 matthew 12840:
12841: Facilitates the plotting of data in an XY graph with two Y axes.
12842: Puts plot definition data into the users environment in order for
12843: graph.png to plot it. Returns an <img> tag for the plot.
12844:
12845: Inputs:
12846:
12847: =over 4
12848:
12849: =item $Title: string, the title of the plot
12850:
12851: =item $xlabel: string, text describing the X-axis of the plot
12852:
12853: =item $ylabel: string, text describing the Y-axis of the plot
12854:
12855: =item $colors: Array ref containing the hex color codes for the data to be
12856: plotted in. If undefined, default values will be used.
12857:
12858: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12859:
12860: =item $Ydata1: The first data set
12861:
12862: =item $Min1: The minimum value of the left Y-axis
12863:
12864: =item $Max1: The maximum value of the left Y-axis
12865:
12866: =item $Ydata2: The second data set
12867:
12868: =item $Min2: The minimum value of the right Y-axis
12869:
12870: =item $Max2: The maximum value of the left Y-axis
12871:
12872: =item %Values: hash indicating or overriding any default values which are
12873: passed to graph.png.
12874: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12875:
12876: =back
12877:
12878: Returns:
12879:
12880: An <img> tag which references graph.png and the appropriate identifying
12881: information for the plot.
1.136 matthew 12882:
12883: =cut
12884:
12885: ############################################################
12886: ############################################################
1.137 matthew 12887: sub DrawXYYGraph {
12888: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12889: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12890: #
12891: # Create the identifier for the graph
12892: my $identifier = &get_cgi_id();
12893: my $id = 'cgi.'.$identifier;
12894: #
12895: $Title = '' if (! defined($Title));
12896: $xlabel = '' if (! defined($xlabel));
12897: $ylabel = '' if (! defined($ylabel));
12898: my %ValuesHash =
12899: (
1.369 www 12900: $id.'.title' => &escape($Title),
12901: $id.'.xlabel' => &escape($xlabel),
12902: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12903: $id.'.labels' => join(',',@$Xlabels),
12904: $id.'.PlotType' => 'XY',
12905: $id.'.NumSets' => 2,
1.137 matthew 12906: $id.'.two_axes' => 1,
12907: $id.'.y1_max_value' => $Max1,
12908: $id.'.y1_min_value' => $Min1,
12909: $id.'.y2_max_value' => $Max2,
12910: $id.'.y2_min_value' => $Min2,
1.136 matthew 12911: );
12912: #
1.137 matthew 12913: if (defined($colors) && ref($colors) eq 'ARRAY') {
12914: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12915: }
12916: #
12917: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12918: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12919: return '';
12920: }
12921: my $NumSets=1;
1.137 matthew 12922: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12923: next if (! ref($array));
12924: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12925: }
12926: #
12927: # Deal with other parameters
12928: while (my ($key,$value) = each(%Values)) {
12929: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12930: }
12931: #
1.646 raeburn 12932: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12933: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12934: }
12935:
12936: ############################################################
12937: ############################################################
12938:
12939: =pod
12940:
1.157 matthew 12941: =back
12942:
1.139 matthew 12943: =head1 Statistics helper routines?
12944:
12945: Bad place for them but what the hell.
12946:
1.157 matthew 12947: =over 4
12948:
1.648 raeburn 12949: =item * &chartlink()
1.139 matthew 12950:
12951: Returns a link to the chart for a specific student.
12952:
12953: Inputs:
12954:
12955: =over 4
12956:
12957: =item $linktext: The text of the link
12958:
12959: =item $sname: The students username
12960:
12961: =item $sdomain: The students domain
12962:
12963: =back
12964:
1.157 matthew 12965: =back
12966:
1.139 matthew 12967: =cut
12968:
12969: ############################################################
12970: ############################################################
12971: sub chartlink {
12972: my ($linktext, $sname, $sdomain) = @_;
12973: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12974: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12975: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12976: '">'.$linktext.'</a>';
1.153 matthew 12977: }
12978:
12979: #######################################################
12980: #######################################################
12981:
12982: =pod
12983:
12984: =head1 Course Environment Routines
1.157 matthew 12985:
12986: =over 4
1.153 matthew 12987:
1.648 raeburn 12988: =item * &restore_course_settings()
1.153 matthew 12989:
1.648 raeburn 12990: =item * &store_course_settings()
1.153 matthew 12991:
12992: Restores/Store indicated form parameters from the course environment.
12993: Will not overwrite existing values of the form parameters.
12994:
12995: Inputs:
12996: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12997:
12998: a hash ref describing the data to be stored. For example:
12999:
13000: %Save_Parameters = ('Status' => 'scalar',
13001: 'chartoutputmode' => 'scalar',
13002: 'chartoutputdata' => 'scalar',
13003: 'Section' => 'array',
1.373 raeburn 13004: 'Group' => 'array',
1.153 matthew 13005: 'StudentData' => 'array',
13006: 'Maps' => 'array');
13007:
13008: Returns: both routines return nothing
13009:
1.631 raeburn 13010: =back
13011:
1.153 matthew 13012: =cut
13013:
13014: #######################################################
13015: #######################################################
13016: sub store_course_settings {
1.496 albertel 13017: return &store_settings($env{'request.course.id'},@_);
13018: }
13019:
13020: sub store_settings {
1.153 matthew 13021: # save to the environment
13022: # appenv the same items, just to be safe
1.300 albertel 13023: my $udom = $env{'user.domain'};
13024: my $uname = $env{'user.name'};
1.496 albertel 13025: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13026: my %SaveHash;
13027: my %AppHash;
13028: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13029: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13030: my $envname = 'environment.'.$basename;
1.258 albertel 13031: if (exists($env{'form.'.$setting})) {
1.153 matthew 13032: # Save this value away
13033: if ($type eq 'scalar' &&
1.258 albertel 13034: (! exists($env{$envname}) ||
13035: $env{$envname} ne $env{'form.'.$setting})) {
13036: $SaveHash{$basename} = $env{'form.'.$setting};
13037: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13038: } elsif ($type eq 'array') {
13039: my $stored_form;
1.258 albertel 13040: if (ref($env{'form.'.$setting})) {
1.153 matthew 13041: $stored_form = join(',',
13042: map {
1.369 www 13043: &escape($_);
1.258 albertel 13044: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13045: } else {
13046: $stored_form =
1.369 www 13047: &escape($env{'form.'.$setting});
1.153 matthew 13048: }
13049: # Determine if the array contents are the same.
1.258 albertel 13050: if ($stored_form ne $env{$envname}) {
1.153 matthew 13051: $SaveHash{$basename} = $stored_form;
13052: $AppHash{$envname} = $stored_form;
13053: }
13054: }
13055: }
13056: }
13057: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13058: $udom,$uname);
1.153 matthew 13059: if ($put_result !~ /^(ok|delayed)/) {
13060: &Apache::lonnet::logthis('unable to save form parameters, '.
13061: 'got error:'.$put_result);
13062: }
13063: # Make sure these settings stick around in this session, too
1.646 raeburn 13064: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13065: return;
13066: }
13067:
13068: sub restore_course_settings {
1.499 albertel 13069: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13070: }
13071:
13072: sub restore_settings {
13073: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13074: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13075: next if (exists($env{'form.'.$setting}));
1.496 albertel 13076: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13077: '.'.$setting;
1.258 albertel 13078: if (exists($env{$envname})) {
1.153 matthew 13079: if ($type eq 'scalar') {
1.258 albertel 13080: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13081: } elsif ($type eq 'array') {
1.258 albertel 13082: $env{'form.'.$setting} = [
1.153 matthew 13083: map {
1.369 www 13084: &unescape($_);
1.258 albertel 13085: } split(',',$env{$envname})
1.153 matthew 13086: ];
13087: }
13088: }
13089: }
1.127 matthew 13090: }
13091:
1.618 raeburn 13092: #######################################################
13093: #######################################################
13094:
13095: =pod
13096:
13097: =head1 Domain E-mail Routines
13098:
13099: =over 4
13100:
1.648 raeburn 13101: =item * &build_recipient_list()
1.618 raeburn 13102:
1.884 raeburn 13103: Build recipient lists for five types of e-mail:
1.766 raeburn 13104: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 13105: (d) Help requests, (e) Course requests needing approval, generated by
13106: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
13107: loncoursequeueadmin.pm respectively.
1.618 raeburn 13108:
13109: Inputs:
1.619 raeburn 13110: defmail (scalar - email address of default recipient),
1.618 raeburn 13111: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 13112: defdom (domain for which to retrieve configuration settings),
13113: origmail (scalar - email address of recipient from loncapa.conf,
13114: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13115:
1.655 raeburn 13116: Returns: comma separated list of addresses to which to send e-mail.
13117:
13118: =back
1.618 raeburn 13119:
13120: =cut
13121:
13122: ############################################################
13123: ############################################################
13124: sub build_recipient_list {
1.619 raeburn 13125: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13126: my @recipients;
13127: my $otheremails;
13128: my %domconfig =
13129: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13130: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13131: if (exists($domconfig{'contacts'}{$mailing})) {
13132: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13133: my @contacts = ('adminemail','supportemail');
13134: foreach my $item (@contacts) {
13135: if ($domconfig{'contacts'}{$mailing}{$item}) {
13136: my $addr = $domconfig{'contacts'}{$item};
13137: if (!grep(/^\Q$addr\E$/,@recipients)) {
13138: push(@recipients,$addr);
13139: }
1.619 raeburn 13140: }
1.766 raeburn 13141: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13142: }
13143: }
1.766 raeburn 13144: } elsif ($origmail ne '') {
13145: push(@recipients,$origmail);
1.618 raeburn 13146: }
1.619 raeburn 13147: } elsif ($origmail ne '') {
13148: push(@recipients,$origmail);
1.618 raeburn 13149: }
1.688 raeburn 13150: if (defined($defmail)) {
13151: if ($defmail ne '') {
13152: push(@recipients,$defmail);
13153: }
1.618 raeburn 13154: }
13155: if ($otheremails) {
1.619 raeburn 13156: my @others;
13157: if ($otheremails =~ /,/) {
13158: @others = split(/,/,$otheremails);
1.618 raeburn 13159: } else {
1.619 raeburn 13160: push(@others,$otheremails);
13161: }
13162: foreach my $addr (@others) {
13163: if (!grep(/^\Q$addr\E$/,@recipients)) {
13164: push(@recipients,$addr);
13165: }
1.618 raeburn 13166: }
13167: }
1.619 raeburn 13168: my $recipientlist = join(',',@recipients);
1.618 raeburn 13169: return $recipientlist;
13170: }
13171:
1.127 matthew 13172: ############################################################
13173: ############################################################
1.154 albertel 13174:
1.655 raeburn 13175: =pod
13176:
13177: =head1 Course Catalog Routines
13178:
13179: =over 4
13180:
13181: =item * &gather_categories()
13182:
13183: Converts category definitions - keys of categories hash stored in
13184: coursecategories in configuration.db on the primary library server in a
13185: domain - to an array. Also generates javascript and idx hash used to
13186: generate Domain Coordinator interface for editing Course Categories.
13187:
13188: Inputs:
1.663 raeburn 13189:
1.655 raeburn 13190: categories (reference to hash of category definitions).
1.663 raeburn 13191:
1.655 raeburn 13192: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13193: categories and subcategories).
1.663 raeburn 13194:
1.655 raeburn 13195: idx (reference to hash of counters used in Domain Coordinator interface for
13196: editing Course Categories).
1.663 raeburn 13197:
1.655 raeburn 13198: jsarray (reference to array of categories used to create Javascript arrays for
13199: Domain Coordinator interface for editing Course Categories).
13200:
13201: Returns: nothing
13202:
13203: Side effects: populates cats, idx and jsarray.
13204:
13205: =cut
13206:
13207: sub gather_categories {
13208: my ($categories,$cats,$idx,$jsarray) = @_;
13209: my %counters;
13210: my $num = 0;
13211: foreach my $item (keys(%{$categories})) {
13212: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13213: if ($container eq '' && $depth == 0) {
13214: $cats->[$depth][$categories->{$item}] = $cat;
13215: } else {
13216: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13217: }
13218: my ($escitem,$tail) = split(/:/,$item,2);
13219: if ($counters{$tail} eq '') {
13220: $counters{$tail} = $num;
13221: $num ++;
13222: }
13223: if (ref($idx) eq 'HASH') {
13224: $idx->{$item} = $counters{$tail};
13225: }
13226: if (ref($jsarray) eq 'ARRAY') {
13227: push(@{$jsarray->[$counters{$tail}]},$item);
13228: }
13229: }
13230: return;
13231: }
13232:
13233: =pod
13234:
13235: =item * &extract_categories()
13236:
13237: Used to generate breadcrumb trails for course categories.
13238:
13239: Inputs:
1.663 raeburn 13240:
1.655 raeburn 13241: categories (reference to hash of category definitions).
1.663 raeburn 13242:
1.655 raeburn 13243: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13244: categories and subcategories).
1.663 raeburn 13245:
1.655 raeburn 13246: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13247:
1.655 raeburn 13248: allitems (reference to hash - key is category key
13249: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13250:
1.655 raeburn 13251: idx (reference to hash of counters used in Domain Coordinator interface for
13252: editing Course Categories).
1.663 raeburn 13253:
1.655 raeburn 13254: jsarray (reference to array of categories used to create Javascript arrays for
13255: Domain Coordinator interface for editing Course Categories).
13256:
1.665 raeburn 13257: subcats (reference to hash of arrays containing all subcategories within each
13258: category, -recursive)
13259:
1.655 raeburn 13260: Returns: nothing
13261:
13262: Side effects: populates trails and allitems hash references.
13263:
13264: =cut
13265:
13266: sub extract_categories {
1.665 raeburn 13267: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13268: if (ref($categories) eq 'HASH') {
13269: &gather_categories($categories,$cats,$idx,$jsarray);
13270: if (ref($cats->[0]) eq 'ARRAY') {
13271: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13272: my $name = $cats->[0][$i];
13273: my $item = &escape($name).'::0';
13274: my $trailstr;
13275: if ($name eq 'instcode') {
13276: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13277: } elsif ($name eq 'communities') {
13278: $trailstr = &mt('Communities');
1.655 raeburn 13279: } else {
13280: $trailstr = $name;
13281: }
13282: if ($allitems->{$item} eq '') {
13283: push(@{$trails},$trailstr);
13284: $allitems->{$item} = scalar(@{$trails})-1;
13285: }
13286: my @parents = ($name);
13287: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13288: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13289: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13290: if (ref($subcats) eq 'HASH') {
13291: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13292: }
13293: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13294: }
13295: } else {
13296: if (ref($subcats) eq 'HASH') {
13297: $subcats->{$item} = [];
1.655 raeburn 13298: }
13299: }
13300: }
13301: }
13302: }
13303: return;
13304: }
13305:
13306: =pod
13307:
13308: =item *&recurse_categories()
13309:
13310: Recursively used to generate breadcrumb trails for course categories.
13311:
13312: Inputs:
1.663 raeburn 13313:
1.655 raeburn 13314: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13315: categories and subcategories).
1.663 raeburn 13316:
1.655 raeburn 13317: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13318:
13319: category (current course category, for which breadcrumb trail is being generated).
13320:
13321: trails (reference to array of breadcrumb trails for each category).
13322:
1.655 raeburn 13323: allitems (reference to hash - key is category key
13324: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13325:
1.655 raeburn 13326: parents (array containing containers directories for current category,
13327: back to top level).
13328:
13329: Returns: nothing
13330:
13331: Side effects: populates trails and allitems hash references
13332:
13333: =cut
13334:
13335: sub recurse_categories {
1.665 raeburn 13336: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13337: my $shallower = $depth - 1;
13338: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13339: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13340: my $name = $cats->[$depth]{$category}[$k];
13341: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13342: my $trailstr = join(' -> ',(@{$parents},$category));
13343: if ($allitems->{$item} eq '') {
13344: push(@{$trails},$trailstr);
13345: $allitems->{$item} = scalar(@{$trails})-1;
13346: }
13347: my $deeper = $depth+1;
13348: push(@{$parents},$category);
1.665 raeburn 13349: if (ref($subcats) eq 'HASH') {
13350: my $subcat = &escape($name).':'.$category.':'.$depth;
13351: for (my $j=@{$parents}; $j>=0; $j--) {
13352: my $higher;
13353: if ($j > 0) {
13354: $higher = &escape($parents->[$j]).':'.
13355: &escape($parents->[$j-1]).':'.$j;
13356: } else {
13357: $higher = &escape($parents->[$j]).'::'.$j;
13358: }
13359: push(@{$subcats->{$higher}},$subcat);
13360: }
13361: }
13362: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13363: $subcats);
1.655 raeburn 13364: pop(@{$parents});
13365: }
13366: } else {
13367: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13368: my $trailstr = join(' -> ',(@{$parents},$category));
13369: if ($allitems->{$item} eq '') {
13370: push(@{$trails},$trailstr);
13371: $allitems->{$item} = scalar(@{$trails})-1;
13372: }
13373: }
13374: return;
13375: }
13376:
1.663 raeburn 13377: =pod
13378:
13379: =item *&assign_categories_table()
13380:
13381: Create a datatable for display of hierarchical categories in a domain,
13382: with checkboxes to allow a course to be categorized.
13383:
13384: Inputs:
13385:
13386: cathash - reference to hash of categories defined for the domain (from
13387: configuration.db)
13388:
13389: currcat - scalar with an & separated list of categories assigned to a course.
13390:
1.919 raeburn 13391: type - scalar contains course type (Course or Community).
13392:
1.663 raeburn 13393: Returns: $output (markup to be displayed)
13394:
13395: =cut
13396:
13397: sub assign_categories_table {
1.919 raeburn 13398: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13399: my $output;
13400: if (ref($cathash) eq 'HASH') {
13401: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13402: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13403: $maxdepth = scalar(@cats);
13404: if (@cats > 0) {
13405: my $itemcount = 0;
13406: if (ref($cats[0]) eq 'ARRAY') {
13407: my @currcategories;
13408: if ($currcat ne '') {
13409: @currcategories = split('&',$currcat);
13410: }
1.919 raeburn 13411: my $table;
1.663 raeburn 13412: for (my $i=0; $i<@{$cats[0]}; $i++) {
13413: my $parent = $cats[0][$i];
1.919 raeburn 13414: next if ($parent eq 'instcode');
13415: if ($type eq 'Community') {
13416: next unless ($parent eq 'communities');
13417: } else {
13418: next if ($parent eq 'communities');
13419: }
1.663 raeburn 13420: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13421: my $item = &escape($parent).'::0';
13422: my $checked = '';
13423: if (@currcategories > 0) {
13424: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13425: $checked = ' checked="checked"';
1.663 raeburn 13426: }
13427: }
1.919 raeburn 13428: my $parent_title = $parent;
13429: if ($parent eq 'communities') {
13430: $parent_title = &mt('Communities');
13431: }
13432: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13433: '<input type="checkbox" name="usecategory" value="'.
13434: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13435: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13436: my $depth = 1;
13437: push(@path,$parent);
1.919 raeburn 13438: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13439: pop(@path);
1.919 raeburn 13440: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13441: $itemcount ++;
13442: }
1.919 raeburn 13443: if ($itemcount) {
13444: $output = &Apache::loncommon::start_data_table().
13445: $table.
13446: &Apache::loncommon::end_data_table();
13447: }
1.663 raeburn 13448: }
13449: }
13450: }
13451: return $output;
13452: }
13453:
13454: =pod
13455:
13456: =item *&assign_category_rows()
13457:
13458: Create a datatable row for display of nested categories in a domain,
13459: with checkboxes to allow a course to be categorized,called recursively.
13460:
13461: Inputs:
13462:
13463: itemcount - track row number for alternating colors
13464:
13465: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13466: categories and subcategories.
13467:
13468: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13469:
13470: parent - parent of current category item
13471:
13472: path - Array containing all categories back up through the hierarchy from the
13473: current category to the top level.
13474:
13475: currcategories - reference to array of current categories assigned to the course
13476:
13477: Returns: $output (markup to be displayed).
13478:
13479: =cut
13480:
13481: sub assign_category_rows {
13482: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13483: my ($text,$name,$item,$chgstr);
13484: if (ref($cats) eq 'ARRAY') {
13485: my $maxdepth = scalar(@{$cats});
13486: if (ref($cats->[$depth]) eq 'HASH') {
13487: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13488: my $numchildren = @{$cats->[$depth]{$parent}};
13489: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13490: $text .= '<td><table class="LC_datatable">';
13491: for (my $j=0; $j<$numchildren; $j++) {
13492: $name = $cats->[$depth]{$parent}[$j];
13493: $item = &escape($name).':'.&escape($parent).':'.$depth;
13494: my $deeper = $depth+1;
13495: my $checked = '';
13496: if (ref($currcategories) eq 'ARRAY') {
13497: if (@{$currcategories} > 0) {
13498: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13499: $checked = ' checked="checked"';
1.663 raeburn 13500: }
13501: }
13502: }
1.664 raeburn 13503: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13504: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13505: $item.'"'.$checked.' />'.$name.'</label></span>'.
13506: '<input type="hidden" name="catname" value="'.$name.'" />'.
13507: '</td><td>';
1.663 raeburn 13508: if (ref($path) eq 'ARRAY') {
13509: push(@{$path},$name);
13510: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13511: pop(@{$path});
13512: }
13513: $text .= '</td></tr>';
13514: }
13515: $text .= '</table></td>';
13516: }
13517: }
13518: }
13519: return $text;
13520: }
13521:
1.655 raeburn 13522: ############################################################
13523: ############################################################
13524:
13525:
1.443 albertel 13526: sub commit_customrole {
1.664 raeburn 13527: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13528: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13529: ($start?', '.&mt('starting').' '.localtime($start):'').
13530: ($end?', ending '.localtime($end):'').': <b>'.
13531: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13532: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13533: '</b><br />';
13534: return $output;
13535: }
13536:
13537: sub commit_standardrole {
1.1116 raeburn 13538: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13539: my ($output,$logmsg,$linefeed);
13540: if ($context eq 'auto') {
13541: $linefeed = "\n";
13542: } else {
13543: $linefeed = "<br />\n";
13544: }
1.443 albertel 13545: if ($three eq 'st') {
1.541 raeburn 13546: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13547: $one,$two,$sec,$context,$credits);
1.541 raeburn 13548: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13549: ($result eq 'unknown_course') || ($result eq 'refused')) {
13550: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13551: } else {
1.541 raeburn 13552: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13553: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13554: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13555: if ($context eq 'auto') {
13556: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13557: } else {
13558: $output .= '<b>'.$result.'</b>'.$linefeed.
13559: &mt('Add to classlist').': <b>ok</b>';
13560: }
13561: $output .= $linefeed;
1.443 albertel 13562: }
13563: } else {
13564: $output = &mt('Assigning').' '.$three.' in '.$url.
13565: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13566: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13567: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13568: if ($context eq 'auto') {
13569: $output .= $result.$linefeed;
13570: } else {
13571: $output .= '<b>'.$result.'</b>'.$linefeed;
13572: }
1.443 albertel 13573: }
13574: return $output;
13575: }
13576:
13577: sub commit_studentrole {
1.1116 raeburn 13578: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13579: $credits) = @_;
1.626 raeburn 13580: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13581: if ($context eq 'auto') {
13582: $linefeed = "\n";
13583: } else {
13584: $linefeed = '<br />'."\n";
13585: }
1.443 albertel 13586: if (defined($one) && defined($two)) {
13587: my $cid=$one.'_'.$two;
13588: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13589: my $secchange = 0;
13590: my $expire_role_result;
13591: my $modify_section_result;
1.628 raeburn 13592: if ($oldsec ne '-1') {
13593: if ($oldsec ne $sec) {
1.443 albertel 13594: $secchange = 1;
1.628 raeburn 13595: my $now = time;
1.443 albertel 13596: my $uurl='/'.$cid;
13597: $uurl=~s/\_/\//g;
13598: if ($oldsec) {
13599: $uurl.='/'.$oldsec;
13600: }
1.626 raeburn 13601: $oldsecurl = $uurl;
1.628 raeburn 13602: $expire_role_result =
1.652 raeburn 13603: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13604: if ($env{'request.course.sec'} ne '') {
13605: if ($expire_role_result eq 'refused') {
13606: my @roles = ('st');
13607: my @statuses = ('previous');
13608: my @roledoms = ($one);
13609: my $withsec = 1;
13610: my %roleshash =
13611: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13612: \@statuses,\@roles,\@roledoms,$withsec);
13613: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13614: my ($oldstart,$oldend) =
13615: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13616: if ($oldend > 0 && $oldend <= $now) {
13617: $expire_role_result = 'ok';
13618: }
13619: }
13620: }
13621: }
1.443 albertel 13622: $result = $expire_role_result;
13623: }
13624: }
13625: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13626: $modify_section_result =
13627: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13628: undef,undef,undef,$sec,
13629: $end,$start,'','',$cid,
13630: '',$context,$credits);
1.443 albertel 13631: if ($modify_section_result =~ /^ok/) {
13632: if ($secchange == 1) {
1.628 raeburn 13633: if ($sec eq '') {
13634: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13635: } else {
13636: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13637: }
1.443 albertel 13638: } elsif ($oldsec eq '-1') {
1.628 raeburn 13639: if ($sec eq '') {
13640: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13641: } else {
13642: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13643: }
1.443 albertel 13644: } else {
1.628 raeburn 13645: if ($sec eq '') {
13646: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13647: } else {
13648: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13649: }
1.443 albertel 13650: }
13651: } else {
1.1115 raeburn 13652: if ($secchange) {
1.628 raeburn 13653: $$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;
13654: } else {
13655: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13656: }
1.443 albertel 13657: }
13658: $result = $modify_section_result;
13659: } elsif ($secchange == 1) {
1.628 raeburn 13660: if ($oldsec eq '') {
1.1103 raeburn 13661: $$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 13662: } else {
13663: $$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;
13664: }
1.626 raeburn 13665: if ($expire_role_result eq 'refused') {
13666: my $newsecurl = '/'.$cid;
13667: $newsecurl =~ s/\_/\//g;
13668: if ($sec ne '') {
13669: $newsecurl.='/'.$sec;
13670: }
13671: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13672: if ($sec eq '') {
13673: $$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;
13674: } else {
13675: $$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;
13676: }
13677: }
13678: }
1.443 albertel 13679: }
13680: } else {
1.626 raeburn 13681: $$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 13682: $result = "error: incomplete course id\n";
13683: }
13684: return $result;
13685: }
13686:
1.1108 raeburn 13687: sub show_role_extent {
13688: my ($scope,$context,$role) = @_;
13689: $scope =~ s{^/}{};
13690: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13691: push(@courseroles,'co');
13692: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13693: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13694: $scope =~ s{/}{_};
13695: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13696: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13697: my ($audom,$auname) = split(/\//,$scope);
13698: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13699: &Apache::loncommon::plainname($auname,$audom).'</span>');
13700: } else {
13701: $scope =~ s{/$}{};
13702: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13703: &Apache::lonnet::domain($scope,'description').'</span>');
13704: }
13705: }
13706:
1.443 albertel 13707: ############################################################
13708: ############################################################
13709:
1.566 albertel 13710: sub check_clone {
1.578 raeburn 13711: my ($args,$linefeed) = @_;
1.566 albertel 13712: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13713: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13714: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13715: my $clonemsg;
13716: my $can_clone = 0;
1.944 raeburn 13717: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13718: if ($lctype ne 'community') {
13719: $lctype = 'course';
13720: }
1.566 albertel 13721: if ($clonehome eq 'no_host') {
1.944 raeburn 13722: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13723: $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'});
13724: } else {
13725: $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'});
13726: }
1.566 albertel 13727: } else {
13728: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13729: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13730: if ($clonedesc{'type'} ne 'Community') {
13731: $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'});
13732: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13733: }
13734: }
1.882 raeburn 13735: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13736: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13737: $can_clone = 1;
13738: } else {
13739: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13740: $args->{'clonedomain'},$args->{'clonecourse'});
13741: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13742: if (grep(/^\*$/,@cloners)) {
13743: $can_clone = 1;
13744: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13745: $can_clone = 1;
13746: } else {
1.908 raeburn 13747: my $ccrole = 'cc';
1.944 raeburn 13748: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13749: $ccrole = 'co';
13750: }
1.578 raeburn 13751: my %roleshash =
13752: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13753: $args->{'ccdomain'},
1.908 raeburn 13754: 'userroles',['active'],[$ccrole],
1.578 raeburn 13755: [$args->{'clonedomain'}]);
1.908 raeburn 13756: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13757: $can_clone = 1;
13758: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13759: $can_clone = 1;
13760: } else {
1.944 raeburn 13761: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13762: $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'});
13763: } else {
13764: $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'});
13765: }
1.578 raeburn 13766: }
1.566 albertel 13767: }
1.578 raeburn 13768: }
1.566 albertel 13769: }
13770: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13771: }
13772:
1.444 albertel 13773: sub construct_course {
1.885 raeburn 13774: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13775: my $outcome;
1.541 raeburn 13776: my $linefeed = '<br />'."\n";
13777: if ($context eq 'auto') {
13778: $linefeed = "\n";
13779: }
1.566 albertel 13780:
13781: #
13782: # Are we cloning?
13783: #
13784: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13785: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13786: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13787: if ($context ne 'auto') {
1.578 raeburn 13788: if ($clonemsg ne '') {
13789: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13790: }
1.566 albertel 13791: }
13792: $outcome .= $clonemsg.$linefeed;
13793:
13794: if (!$can_clone) {
13795: return (0,$outcome);
13796: }
13797: }
13798:
1.444 albertel 13799: #
13800: # Open course
13801: #
13802: my $crstype = lc($args->{'crstype'});
13803: my %cenv=();
13804: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13805: $args->{'cdescr'},
13806: $args->{'curl'},
13807: $args->{'course_home'},
13808: $args->{'nonstandard'},
13809: $args->{'crscode'},
13810: $args->{'ccuname'}.':'.
13811: $args->{'ccdomain'},
1.882 raeburn 13812: $args->{'crstype'},
1.885 raeburn 13813: $cnum,$context,$category);
1.444 albertel 13814:
13815: # Note: The testing routines depend on this being output; see
13816: # Utils::Course. This needs to at least be output as a comment
13817: # if anyone ever decides to not show this, and Utils::Course::new
13818: # will need to be suitably modified.
1.541 raeburn 13819: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13820: if ($$courseid =~ /^error:/) {
13821: return (0,$outcome);
13822: }
13823:
1.444 albertel 13824: #
13825: # Check if created correctly
13826: #
1.479 albertel 13827: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13828: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13829: if ($crsuhome eq 'no_host') {
13830: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13831: return (0,$outcome);
13832: }
1.541 raeburn 13833: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13834:
1.444 albertel 13835: #
1.566 albertel 13836: # Do the cloning
13837: #
13838: if ($can_clone && $cloneid) {
13839: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13840: if ($context ne 'auto') {
13841: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13842: }
13843: $outcome .= $clonemsg.$linefeed;
13844: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13845: # Copy all files
1.637 www 13846: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13847: # Restore URL
1.566 albertel 13848: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13849: # Restore title
1.566 albertel 13850: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13851: # Restore creation date, creator and creation context.
13852: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13853: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13854: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13855: # Mark as cloned
1.566 albertel 13856: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13857: # Need to clone grading mode
13858: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13859: $cenv{'grading'}=$newenv{'grading'};
13860: # Do not clone these environment entries
13861: &Apache::lonnet::del('environment',
13862: ['default_enrollment_start_date',
13863: 'default_enrollment_end_date',
13864: 'question.email',
13865: 'policy.email',
13866: 'comment.email',
13867: 'pch.users.denied',
1.725 raeburn 13868: 'plc.users.denied',
13869: 'hidefromcat',
1.1121 raeburn 13870: 'checkforpriv',
1.725 raeburn 13871: 'categories'],
1.638 www 13872: $$crsudom,$$crsunum);
1.444 albertel 13873: }
1.566 albertel 13874:
1.444 albertel 13875: #
13876: # Set environment (will override cloned, if existing)
13877: #
13878: my @sections = ();
13879: my @xlists = ();
13880: if ($args->{'crstype'}) {
13881: $cenv{'type'}=$args->{'crstype'};
13882: }
13883: if ($args->{'crsid'}) {
13884: $cenv{'courseid'}=$args->{'crsid'};
13885: }
13886: if ($args->{'crscode'}) {
13887: $cenv{'internal.coursecode'}=$args->{'crscode'};
13888: }
13889: if ($args->{'crsquota'} ne '') {
13890: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13891: } else {
13892: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13893: }
13894: if ($args->{'ccuname'}) {
13895: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13896: ':'.$args->{'ccdomain'};
13897: } else {
13898: $cenv{'internal.courseowner'} = $args->{'curruser'};
13899: }
1.1116 raeburn 13900: if ($args->{'defaultcredits'}) {
13901: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13902: }
1.444 albertel 13903: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13904: if ($args->{'crssections'}) {
13905: $cenv{'internal.sectionnums'} = '';
13906: if ($args->{'crssections'} =~ m/,/) {
13907: @sections = split/,/,$args->{'crssections'};
13908: } else {
13909: $sections[0] = $args->{'crssections'};
13910: }
13911: if (@sections > 0) {
13912: foreach my $item (@sections) {
13913: my ($sec,$gp) = split/:/,$item;
13914: my $class = $args->{'crscode'}.$sec;
13915: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13916: $cenv{'internal.sectionnums'} .= $item.',';
13917: unless ($addcheck eq 'ok') {
13918: push @badclasses, $class;
13919: }
13920: }
13921: $cenv{'internal.sectionnums'} =~ s/,$//;
13922: }
13923: }
13924: # do not hide course coordinator from staff listing,
13925: # even if privileged
13926: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 13927: # add course coordinator's domain to domains to check for privileged users
13928: # if different to course domain
13929: if ($$crsudom ne $args->{'ccdomain'}) {
13930: $cenv{'checkforpriv'} = $args->{'ccdomain'};
13931: }
1.444 albertel 13932: # add crosslistings
13933: if ($args->{'crsxlist'}) {
13934: $cenv{'internal.crosslistings'}='';
13935: if ($args->{'crsxlist'} =~ m/,/) {
13936: @xlists = split/,/,$args->{'crsxlist'};
13937: } else {
13938: $xlists[0] = $args->{'crsxlist'};
13939: }
13940: if (@xlists > 0) {
13941: foreach my $item (@xlists) {
13942: my ($xl,$gp) = split/:/,$item;
13943: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13944: $cenv{'internal.crosslistings'} .= $item.',';
13945: unless ($addcheck eq 'ok') {
13946: push @badclasses, $xl;
13947: }
13948: }
13949: $cenv{'internal.crosslistings'} =~ s/,$//;
13950: }
13951: }
13952: if ($args->{'autoadds'}) {
13953: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13954: }
13955: if ($args->{'autodrops'}) {
13956: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13957: }
13958: # check for notification of enrollment changes
13959: my @notified = ();
13960: if ($args->{'notify_owner'}) {
13961: if ($args->{'ccuname'} ne '') {
13962: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13963: }
13964: }
13965: if ($args->{'notify_dc'}) {
13966: if ($uname ne '') {
1.630 raeburn 13967: push(@notified,$uname.':'.$udom);
1.444 albertel 13968: }
13969: }
13970: if (@notified > 0) {
13971: my $notifylist;
13972: if (@notified > 1) {
13973: $notifylist = join(',',@notified);
13974: } else {
13975: $notifylist = $notified[0];
13976: }
13977: $cenv{'internal.notifylist'} = $notifylist;
13978: }
13979: if (@badclasses > 0) {
13980: my %lt=&Apache::lonlocal::texthash(
13981: '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',
13982: 'dnhr' => 'does not have rights to access enrollment in these classes',
13983: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13984: );
1.541 raeburn 13985: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13986: ' ('.$lt{'adby'}.')';
13987: if ($context eq 'auto') {
13988: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13989: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13990: foreach my $item (@badclasses) {
13991: if ($context eq 'auto') {
13992: $outcome .= " - $item\n";
13993: } else {
13994: $outcome .= "<li>$item</li>\n";
13995: }
13996: }
13997: if ($context eq 'auto') {
13998: $outcome .= $linefeed;
13999: } else {
1.566 albertel 14000: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14001: }
14002: }
1.444 albertel 14003: }
14004: if ($args->{'no_end_date'}) {
14005: $args->{'endaccess'} = 0;
14006: }
14007: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14008: $cenv{'internal.autoend'}=$args->{'enrollend'};
14009: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14010: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14011: if ($args->{'showphotos'}) {
14012: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14013: }
14014: $cenv{'internal.authtype'} = $args->{'authtype'};
14015: $cenv{'internal.autharg'} = $args->{'autharg'};
14016: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14017: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14018: 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');
14019: if ($context eq 'auto') {
14020: $outcome .= $krb_msg;
14021: } else {
1.566 albertel 14022: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14023: }
14024: $outcome .= $linefeed;
1.444 albertel 14025: }
14026: }
14027: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14028: if ($args->{'setpolicy'}) {
14029: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14030: }
14031: if ($args->{'setcontent'}) {
14032: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14033: }
14034: }
14035: if ($args->{'reshome'}) {
14036: $cenv{'reshome'}=$args->{'reshome'}.'/';
14037: $cenv{'reshome'}=~s/\/+$/\//;
14038: }
14039: #
14040: # course has keyed access
14041: #
14042: if ($args->{'setkeys'}) {
14043: $cenv{'keyaccess'}='yes';
14044: }
14045: # if specified, key authority is not course, but user
14046: # only active if keyaccess is yes
14047: if ($args->{'keyauth'}) {
1.487 albertel 14048: my ($user,$domain) = split(':',$args->{'keyauth'});
14049: $user = &LONCAPA::clean_username($user);
14050: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14051: if ($user ne '' && $domain ne '') {
1.487 albertel 14052: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14053: }
14054: }
14055:
14056: if ($args->{'disresdis'}) {
14057: $cenv{'pch.roles.denied'}='st';
14058: }
14059: if ($args->{'disablechat'}) {
14060: $cenv{'plc.roles.denied'}='st';
14061: }
14062:
14063: # Record we've not yet viewed the Course Initialization Helper for this
14064: # course
14065: $cenv{'course.helper.not.run'} = 1;
14066: #
14067: # Use new Randomseed
14068: #
14069: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14070: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14071: #
14072: # The encryption code and receipt prefix for this course
14073: #
14074: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14075: $cenv{'internal.encpref'}=100+int(9*rand(99));
14076: #
14077: # By default, use standard grading
14078: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14079:
1.541 raeburn 14080: $outcome .= $linefeed.&mt('Setting environment').': '.
14081: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14082: #
14083: # Open all assignments
14084: #
14085: if ($args->{'openall'}) {
14086: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14087: my %storecontent = ($storeunder => time,
14088: $storeunder.'.type' => 'date_start');
14089:
14090: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14091: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14092: }
14093: #
14094: # Set first page
14095: #
14096: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14097: || ($cloneid)) {
1.445 albertel 14098: use LONCAPA::map;
1.444 albertel 14099: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14100:
14101: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14102: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14103:
1.444 albertel 14104: $outcome .= ($fatal?$errtext:'read ok').' - ';
14105: my $title; my $url;
14106: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14107: $title=&mt('Syllabus');
1.444 albertel 14108: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14109: } else {
1.963 raeburn 14110: $title=&mt('Table of Contents');
1.444 albertel 14111: $url='/adm/navmaps';
14112: }
1.445 albertel 14113:
14114: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14115: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14116:
14117: if ($errtext) { $fatal=2; }
1.541 raeburn 14118: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14119: }
1.566 albertel 14120:
14121: return (1,$outcome);
1.444 albertel 14122: }
14123:
14124: ############################################################
14125: ############################################################
14126:
1.953 droeschl 14127: #SD
14128: # only Community and Course, or anything else?
1.378 raeburn 14129: sub course_type {
14130: my ($cid) = @_;
14131: if (!defined($cid)) {
14132: $cid = $env{'request.course.id'};
14133: }
1.404 albertel 14134: if (defined($env{'course.'.$cid.'.type'})) {
14135: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14136: } else {
14137: return 'Course';
1.377 raeburn 14138: }
14139: }
1.156 albertel 14140:
1.406 raeburn 14141: sub group_term {
14142: my $crstype = &course_type();
14143: my %names = (
14144: 'Course' => 'group',
1.865 raeburn 14145: 'Community' => 'group',
1.406 raeburn 14146: );
14147: return $names{$crstype};
14148: }
14149:
1.902 raeburn 14150: sub course_types {
14151: my @types = ('official','unofficial','community');
14152: my %typename = (
14153: official => 'Official course',
14154: unofficial => 'Unofficial course',
14155: community => 'Community',
14156: );
14157: return (\@types,\%typename);
14158: }
14159:
1.156 albertel 14160: sub icon {
14161: my ($file)=@_;
1.505 albertel 14162: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14163: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14164: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14165: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14166: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14167: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14168: $curfext.".gif") {
14169: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14170: $curfext.".gif";
14171: }
14172: }
1.249 albertel 14173: return &lonhttpdurl($iconname);
1.154 albertel 14174: }
1.84 albertel 14175:
1.575 albertel 14176: sub lonhttpdurl {
1.692 www 14177: #
14178: # Had been used for "small fry" static images on separate port 8080.
14179: # Modify here if lightweight http functionality desired again.
14180: # Currently eliminated due to increasing firewall issues.
14181: #
1.575 albertel 14182: my ($url)=@_;
1.692 www 14183: return $url;
1.215 albertel 14184: }
14185:
1.213 albertel 14186: sub connection_aborted {
14187: my ($r)=@_;
14188: $r->print(" ");$r->rflush();
14189: my $c = $r->connection;
14190: return $c->aborted();
14191: }
14192:
1.221 foxr 14193: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14194: # strings as 'strings'.
14195: sub escape_single {
1.221 foxr 14196: my ($input) = @_;
1.223 albertel 14197: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14198: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14199: return $input;
14200: }
1.223 albertel 14201:
1.222 foxr 14202: # Same as escape_single, but escape's "'s This
14203: # can be used for "strings"
14204: sub escape_double {
14205: my ($input) = @_;
14206: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14207: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14208: return $input;
14209: }
1.223 albertel 14210:
1.222 foxr 14211: # Escapes the last element of a full URL.
14212: sub escape_url {
14213: my ($url) = @_;
1.238 raeburn 14214: my @urlslices = split(/\//, $url,-1);
1.369 www 14215: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14216: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14217: }
1.462 albertel 14218:
1.820 raeburn 14219: sub compare_arrays {
14220: my ($arrayref1,$arrayref2) = @_;
14221: my (@difference,%count);
14222: @difference = ();
14223: %count = ();
14224: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14225: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14226: foreach my $element (keys(%count)) {
14227: if ($count{$element} == 1) {
14228: push(@difference,$element);
14229: }
14230: }
14231: }
14232: return @difference;
14233: }
14234:
1.817 bisitz 14235: # -------------------------------------------------------- Initialize user login
1.462 albertel 14236: sub init_user_environment {
1.463 albertel 14237: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14238: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14239:
14240: my $public=($username eq 'public' && $domain eq 'public');
14241:
14242: # See if old ID present, if so, remove
14243:
1.1062 raeburn 14244: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14245: my $now=time;
14246:
14247: if ($public) {
14248: my $max_public=100;
14249: my $oldest;
14250: my $oldest_time=0;
14251: for(my $next=1;$next<=$max_public;$next++) {
14252: if (-e $lonids."/publicuser_$next.id") {
14253: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14254: if ($mtime<$oldest_time || !$oldest_time) {
14255: $oldest_time=$mtime;
14256: $oldest=$next;
14257: }
14258: } else {
14259: $cookie="publicuser_$next";
14260: last;
14261: }
14262: }
14263: if (!$cookie) { $cookie="publicuser_$oldest"; }
14264: } else {
1.463 albertel 14265: # if this isn't a robot, kill any existing non-robot sessions
14266: if (!$args->{'robot'}) {
14267: opendir(DIR,$lonids);
14268: while ($filename=readdir(DIR)) {
14269: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14270: unlink($lonids.'/'.$filename);
14271: }
1.462 albertel 14272: }
1.463 albertel 14273: closedir(DIR);
1.462 albertel 14274: }
14275: # Give them a new cookie
1.463 albertel 14276: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14277: : $now.$$.int(rand(10000)));
1.463 albertel 14278: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14279:
14280: # Initialize roles
14281:
1.1062 raeburn 14282: ($userroles,$firstaccenv,$timerintenv) =
14283: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14284: }
14285: # ------------------------------------ Check browser type and MathML capability
14286:
14287: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1137 raeburn 14288: $clientunicode,$clientos,$clientmobile) = &decode_user_agent($r);
1.462 albertel 14289:
14290: # ------------------------------------------------------------- Get environment
14291:
14292: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14293: my ($tmp) = keys(%userenv);
14294: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14295: } else {
14296: undef(%userenv);
14297: }
14298: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14299: $form->{'interface'}=$userenv{'interface'};
14300: }
14301: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14302:
14303: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14304: foreach my $option ('interface','localpath','localres') {
14305: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14306: }
14307: # --------------------------------------------------------- Write first profile
14308:
14309: {
14310: my %initial_env =
14311: ("user.name" => $username,
14312: "user.domain" => $domain,
14313: "user.home" => $authhost,
14314: "browser.type" => $clientbrowser,
14315: "browser.version" => $clientversion,
14316: "browser.mathml" => $clientmathml,
14317: "browser.unicode" => $clientunicode,
14318: "browser.os" => $clientos,
1.1137 raeburn 14319: "browser.mobile" => $clientmobile,
1.462 albertel 14320: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14321: "request.course.fn" => '',
14322: "request.course.uri" => '',
14323: "request.course.sec" => '',
14324: "request.role" => 'cm',
14325: "request.role.adv" => $env{'user.adv'},
14326: "request.host" => $ENV{'REMOTE_ADDR'},);
14327:
14328: if ($form->{'localpath'}) {
14329: $initial_env{"browser.localpath"} = $form->{'localpath'};
14330: $initial_env{"browser.localres"} = $form->{'localres'};
14331: }
14332:
14333: if ($form->{'interface'}) {
14334: $form->{'interface'}=~s/\W//gs;
14335: $initial_env{"browser.interface"} = $form->{'interface'};
14336: $env{'browser.interface'}=$form->{'interface'};
14337: }
14338:
1.981 raeburn 14339: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14340: my %domdef;
14341: unless ($domain eq 'public') {
14342: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14343: }
1.980 raeburn 14344:
1.1081 raeburn 14345: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14346: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14347: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14348: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14349: }
14350:
1.864 raeburn 14351: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14352: $userenv{'canrequest.'.$crstype} =
14353: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14354: 'reload','requestcourses',
14355: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14356: }
14357:
1.1092 raeburn 14358: $userenv{'canrequest.author'} =
14359: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14360: 'reload','requestauthor',
14361: \%userenv,\%domdef,\%is_adv);
14362: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14363: $domain,$username);
14364: my $reqstatus = $reqauthor{'author_status'};
14365: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14366: if (ref($reqauthor{'author'}) eq 'HASH') {
14367: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14368: $reqauthor{'author'}{'timestamp'};
14369: }
14370: }
14371:
1.462 albertel 14372: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14373:
1.462 albertel 14374: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14375: &GDBM_WRCREAT(),0640)) {
14376: &_add_to_env(\%disk_env,\%initial_env);
14377: &_add_to_env(\%disk_env,\%userenv,'environment.');
14378: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14379: if (ref($firstaccenv) eq 'HASH') {
14380: &_add_to_env(\%disk_env,$firstaccenv);
14381: }
14382: if (ref($timerintenv) eq 'HASH') {
14383: &_add_to_env(\%disk_env,$timerintenv);
14384: }
1.463 albertel 14385: if (ref($args->{'extra_env'})) {
14386: &_add_to_env(\%disk_env,$args->{'extra_env'});
14387: }
1.462 albertel 14388: untie(%disk_env);
14389: } else {
1.705 tempelho 14390: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14391: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14392: return 'error: '.$!;
14393: }
14394: }
14395: $env{'request.role'}='cm';
14396: $env{'request.role.adv'}=$env{'user.adv'};
14397: $env{'browser.type'}=$clientbrowser;
14398:
14399: return $cookie;
14400:
14401: }
14402:
14403: sub _add_to_env {
14404: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14405: if (ref($env_data) eq 'HASH') {
14406: while (my ($key,$value) = each(%$env_data)) {
14407: $idf->{$prefix.$key} = $value;
14408: $env{$prefix.$key} = $value;
14409: }
1.462 albertel 14410: }
14411: }
14412:
1.685 tempelho 14413: # --- Get the symbolic name of a problem and the url
14414: sub get_symb {
14415: my ($request,$silent) = @_;
1.726 raeburn 14416: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14417: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14418: if ($symb eq '') {
14419: if (!$silent) {
1.1071 raeburn 14420: if (ref($request)) {
14421: $request->print("Unable to handle ambiguous references:$url:.");
14422: }
1.685 tempelho 14423: return ();
14424: }
14425: }
14426: &Apache::lonenc::check_decrypt(\$symb);
14427: return ($symb);
14428: }
14429:
14430: # --------------------------------------------------------------Get annotation
14431:
14432: sub get_annotation {
14433: my ($symb,$enc) = @_;
14434:
14435: my $key = $symb;
14436: if (!$enc) {
14437: $key =
14438: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14439: }
14440: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14441: return $annotation{$key};
14442: }
14443:
14444: sub clean_symb {
1.731 raeburn 14445: my ($symb,$delete_enc) = @_;
1.685 tempelho 14446:
14447: &Apache::lonenc::check_decrypt(\$symb);
14448: my $enc = $env{'request.enc'};
1.731 raeburn 14449: if ($delete_enc) {
1.730 raeburn 14450: delete($env{'request.enc'});
14451: }
1.685 tempelho 14452:
14453: return ($symb,$enc);
14454: }
1.462 albertel 14455:
1.990 raeburn 14456: sub build_release_hashes {
14457: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14458: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14459: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14460: (ref($randomizetry) eq 'HASH'));
14461: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14462: my ($item,$name,$value) = split(/:/,$key);
14463: if ($item eq 'parameter') {
14464: if (ref($checkparms->{$name}) eq 'ARRAY') {
14465: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14466: push(@{$checkparms->{$name}},$value);
14467: }
14468: } else {
14469: push(@{$checkparms->{$name}},$value);
14470: }
14471: } elsif ($item eq 'resourcetag') {
14472: if ($name eq 'responsetype') {
14473: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14474: }
14475: } elsif ($item eq 'course') {
14476: if ($name eq 'crstype') {
14477: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14478: }
14479: }
14480: }
14481: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14482: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14483: return;
14484: }
14485:
1.1083 raeburn 14486: sub update_content_constraints {
14487: my ($cdom,$cnum,$chome,$cid) = @_;
14488: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14489: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14490: my %checkresponsetypes;
14491: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14492: my ($item,$name,$value) = split(/:/,$key);
14493: if ($item eq 'resourcetag') {
14494: if ($name eq 'responsetype') {
14495: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14496: }
14497: }
14498: }
14499: my $navmap = Apache::lonnavmaps::navmap->new();
14500: if (defined($navmap)) {
14501: my %allresponses;
14502: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14503: my %responses = $res->responseTypes();
14504: foreach my $key (keys(%responses)) {
14505: next unless(exists($checkresponsetypes{$key}));
14506: $allresponses{$key} += $responses{$key};
14507: }
14508: }
14509: foreach my $key (keys(%allresponses)) {
14510: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14511: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14512: ($reqdmajor,$reqdminor) = ($major,$minor);
14513: }
14514: }
14515: undef($navmap);
14516: }
14517: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14518: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14519: }
14520: return;
14521: }
14522:
1.1110 raeburn 14523: sub allmaps_incourse {
14524: my ($cdom,$cnum,$chome,$cid) = @_;
14525: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14526: $cid = $env{'request.course.id'};
14527: $cdom = $env{'course.'.$cid.'.domain'};
14528: $cnum = $env{'course.'.$cid.'.num'};
14529: $chome = $env{'course.'.$cid.'.home'};
14530: }
14531: my %allmaps = ();
14532: my $lastchange =
14533: &Apache::lonnet::get_coursechange($cdom,$cnum);
14534: if ($lastchange > $env{'request.course.tied'}) {
14535: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14536: unless ($ferr) {
14537: &update_content_constraints($cdom,$cnum,$chome,$cid);
14538: }
14539: }
14540: my $navmap = Apache::lonnavmaps::navmap->new();
14541: if (defined($navmap)) {
14542: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14543: $allmaps{$res->src()} = 1;
14544: }
14545: }
14546: return \%allmaps;
14547: }
14548:
1.1083 raeburn 14549: sub parse_supplemental_title {
14550: my ($title) = @_;
14551:
14552: my ($foldertitle,$renametitle);
14553: if ($title =~ /&&&/) {
14554: $title = &HTML::Entites::decode($title);
14555: }
14556: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14557: $renametitle=$4;
14558: my ($time,$uname,$udom) = ($1,$2,$3);
14559: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14560: my $name = &plainname($uname,$udom);
14561: $name = &HTML::Entities::encode($name,'"<>&\'');
14562: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14563: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14564: $name.': <br />'.$foldertitle;
14565: }
14566: if (wantarray) {
14567: return ($title,$foldertitle,$renametitle);
14568: }
14569: return $title;
14570: }
14571:
1.1101 raeburn 14572: sub symb_to_docspath {
14573: my ($symb) = @_;
14574: return unless ($symb);
14575: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14576: if ($resurl=~/\.(sequence|page)$/) {
14577: $mapurl=$resurl;
14578: } elsif ($resurl eq 'adm/navmaps') {
14579: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14580: }
14581: my $mapresobj;
14582: my $navmap = Apache::lonnavmaps::navmap->new();
14583: if (ref($navmap)) {
14584: $mapresobj = $navmap->getResourceByUrl($mapurl);
14585: }
14586: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14587: my $type=$2;
14588: my $path;
14589: if (ref($mapresobj)) {
14590: my $pcslist = $mapresobj->map_hierarchy();
14591: if ($pcslist ne '') {
14592: foreach my $pc (split(/,/,$pcslist)) {
14593: next if ($pc <= 1);
14594: my $res = $navmap->getByMapPc($pc);
14595: if (ref($res)) {
14596: my $thisurl = $res->src();
14597: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14598: my $thistitle = $res->title();
14599: $path .= '&'.
14600: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14601: &Apache::lonhtmlcommon::entity_encode($thistitle).
14602: ':'.$res->randompick().
14603: ':'.$res->randomout().
14604: ':'.$res->encrypted().
14605: ':'.$res->randomorder().
14606: ':'.$res->is_page();
14607: }
14608: }
14609: }
14610: $path =~ s/^\&//;
14611: my $maptitle = $mapresobj->title();
14612: if ($mapurl eq 'default') {
1.1129 raeburn 14613: $maptitle = 'Main Content';
1.1101 raeburn 14614: }
14615: $path .= (($path ne '')? '&' : '').
14616: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14617: &Apache::lonhtmlcommon::entity_encode($maptitle).
14618: ':'.$mapresobj->randompick().
14619: ':'.$mapresobj->randomout().
14620: ':'.$mapresobj->encrypted().
14621: ':'.$mapresobj->randomorder().
14622: ':'.$mapresobj->is_page();
14623: } else {
14624: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14625: my $ispage = (($type eq 'page')? 1 : '');
14626: if ($mapurl eq 'default') {
1.1129 raeburn 14627: $maptitle = 'Main Content';
1.1101 raeburn 14628: }
14629: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14630: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14631: }
14632: unless ($mapurl eq 'default') {
14633: $path = 'default&'.
1.1129 raeburn 14634: &Apache::lonhtmlcommon::entity_encode('Main Content').
1.1101 raeburn 14635: ':::::&'.$path;
14636: }
14637: return $path;
14638: }
14639:
1.1094 raeburn 14640: sub captcha_display {
14641: my ($context,$lonhost) = @_;
14642: my ($output,$error);
14643: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14644: if ($captcha eq 'original') {
1.1094 raeburn 14645: $output = &create_captcha();
14646: unless ($output) {
14647: $error = 'captcha';
14648: }
14649: } elsif ($captcha eq 'recaptcha') {
14650: $output = &create_recaptcha($pubkey);
14651: unless ($output) {
1.1095 raeburn 14652: $error = 'recaptcha';
1.1094 raeburn 14653: }
14654: }
14655: return ($output,$error);
14656: }
14657:
14658: sub captcha_response {
14659: my ($context,$lonhost) = @_;
14660: my ($captcha_chk,$captcha_error);
14661: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14662: if ($captcha eq 'original') {
1.1094 raeburn 14663: ($captcha_chk,$captcha_error) = &check_captcha();
14664: } elsif ($captcha eq 'recaptcha') {
14665: $captcha_chk = &check_recaptcha($privkey);
14666: } else {
14667: $captcha_chk = 1;
14668: }
14669: return ($captcha_chk,$captcha_error);
14670: }
14671:
14672: sub get_captcha_config {
14673: my ($context,$lonhost) = @_;
1.1095 raeburn 14674: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14675: my $hostname = &Apache::lonnet::hostname($lonhost);
14676: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14677: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14678: if ($context eq 'usercreation') {
14679: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14680: if (ref($domconfig{$context}) eq 'HASH') {
14681: $hashtocheck = $domconfig{$context}{'cancreate'};
14682: if (ref($hashtocheck) eq 'HASH') {
14683: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14684: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14685: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14686: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14687: }
14688: if ($privkey && $pubkey) {
14689: $captcha = 'recaptcha';
14690: } else {
14691: $captcha = 'original';
14692: }
14693: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14694: $captcha = 'original';
14695: }
1.1094 raeburn 14696: }
1.1095 raeburn 14697: } else {
14698: $captcha = 'captcha';
14699: }
14700: } elsif ($context eq 'login') {
14701: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14702: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14703: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14704: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14705: if ($privkey && $pubkey) {
14706: $captcha = 'recaptcha';
1.1095 raeburn 14707: } else {
14708: $captcha = 'original';
1.1094 raeburn 14709: }
1.1095 raeburn 14710: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14711: $captcha = 'original';
1.1094 raeburn 14712: }
14713: }
14714: return ($captcha,$pubkey,$privkey);
14715: }
14716:
14717: sub create_captcha {
14718: my %captcha_params = &captcha_settings();
14719: my ($output,$maxtries,$tries) = ('',10,0);
14720: while ($tries < $maxtries) {
14721: $tries ++;
14722: my $captcha = Authen::Captcha->new (
14723: output_folder => $captcha_params{'output_dir'},
14724: data_folder => $captcha_params{'db_dir'},
14725: );
14726: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14727:
14728: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14729: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14730: &mt('Type in the letters/numbers shown below').' '.
14731: '<input type="text" size="5" name="code" value="" /><br />'.
14732: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14733: last;
14734: }
14735: }
14736: return $output;
14737: }
14738:
14739: sub captcha_settings {
14740: my %captcha_params = (
14741: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14742: www_output_dir => "/captchaspool",
14743: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14744: numchars => '5',
14745: );
14746: return %captcha_params;
14747: }
14748:
14749: sub check_captcha {
14750: my ($captcha_chk,$captcha_error);
14751: my $code = $env{'form.code'};
14752: my $md5sum = $env{'form.crypt'};
14753: my %captcha_params = &captcha_settings();
14754: my $captcha = Authen::Captcha->new(
14755: output_folder => $captcha_params{'output_dir'},
14756: data_folder => $captcha_params{'db_dir'},
14757: );
1.1109 raeburn 14758: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14759: my %captcha_hash = (
14760: 0 => 'Code not checked (file error)',
14761: -1 => 'Failed: code expired',
14762: -2 => 'Failed: invalid code (not in database)',
14763: -3 => 'Failed: invalid code (code does not match crypt)',
14764: );
14765: if ($captcha_chk != 1) {
14766: $captcha_error = $captcha_hash{$captcha_chk}
14767: }
14768: return ($captcha_chk,$captcha_error);
14769: }
14770:
14771: sub create_recaptcha {
14772: my ($pubkey) = @_;
14773: my $captcha = Captcha::reCAPTCHA->new;
14774: return $captcha->get_options_setter({theme => 'white'})."\n".
14775: $captcha->get_html($pubkey).
14776: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 14777: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 14778: '<br /><br />';
14779: }
14780:
14781: sub check_recaptcha {
14782: my ($privkey) = @_;
14783: my $captcha_chk;
14784: my $captcha = Captcha::reCAPTCHA->new;
14785: my $captcha_result =
14786: $captcha->check_answer(
14787: $privkey,
14788: $ENV{'REMOTE_ADDR'},
14789: $env{'form.recaptcha_challenge_field'},
14790: $env{'form.recaptcha_response_field'},
14791: );
14792: if ($captcha_result->{is_valid}) {
14793: $captcha_chk = 1;
14794: }
14795: return $captcha_chk;
14796: }
14797:
1.41 ng 14798: =pod
14799:
14800: =back
14801:
1.112 bowersj2 14802: =cut
1.41 ng 14803:
1.112 bowersj2 14804: 1;
14805: __END__;
1.41 ng 14806:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>