Annotation of loncom/interface/loncommon.pm, revision 1.1141
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1141 ! raeburn 4: # $Id: loncommon.pm,v 1.1140 2013/07/15 17:42:11 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.1141 ! raeburn 2354: =item * $clientinfo
! 2355:
1.87 matthew 2356: =back
2357:
1.157 matthew 2358: =back
2359:
1.87 matthew 2360: =cut
2361:
2362: ###############################################################
2363: ###############################################################
2364: sub decode_user_agent {
1.247 albertel 2365: my ($r)=@_;
1.87 matthew 2366: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2367: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2368: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2369: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2370: my $clientbrowser='unknown';
2371: my $clientversion='0';
2372: my $clientmathml='';
2373: my $clientunicode='0';
1.1137 raeburn 2374: my $clientmobile=0;
1.87 matthew 2375: for (my $i=0;$i<=$#browsertype;$i++) {
2376: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2377: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2378: $clientbrowser=$bname;
2379: $httpbrowser=~/$vreg/i;
2380: $clientversion=$1;
2381: $clientmathml=($clientversion>=$minv);
2382: $clientunicode=($clientversion>=$univ);
2383: }
2384: }
2385: my $clientos='unknown';
1.1141 ! raeburn 2386: my $clientinfo;
1.87 matthew 2387: if (($httpbrowser=~/linux/i) ||
2388: ($httpbrowser=~/unix/i) ||
2389: ($httpbrowser=~/ux/i) ||
2390: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2391: if (($httpbrowser=~/vax/i) ||
2392: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2393: if ($httpbrowser=~/next/i) { $clientos='next'; }
2394: if (($httpbrowser=~/mac/i) ||
2395: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2396: if ($httpbrowser=~/win/i) { $clientos='win'; }
2397: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2398: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2399: $clientmobile=lc($1);
2400: }
1.1141 ! raeburn 2401: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
! 2402: $clientinfo = 'firefox-'.$1;
! 2403: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
! 2404: $clientinfo = 'chromeframe-'.$1;
! 2405: }
1.87 matthew 2406: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 ! raeburn 2407: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2408: }
2409:
1.32 matthew 2410: ###############################################################
2411: ## Authentication changing form generation subroutines ##
2412: ###############################################################
2413: ##
2414: ## All of the authform_xxxxxxx subroutines take their inputs in a
2415: ## hash, and have reasonable default values.
2416: ##
2417: ## formname = the name given in the <form> tag.
1.35 matthew 2418: #-------------------------------------------
2419:
1.45 matthew 2420: =pod
2421:
1.112 bowersj2 2422: =head1 Authentication Routines
2423:
2424: =over 4
2425:
1.648 raeburn 2426: =item * &authform_xxxxxx()
1.35 matthew 2427:
2428: The authform_xxxxxx subroutines provide javascript and html forms which
2429: handle some of the conveniences required for authentication forms.
2430: This is not an optimal method, but it works.
2431:
2432: =over 4
2433:
1.112 bowersj2 2434: =item * authform_header
1.35 matthew 2435:
1.112 bowersj2 2436: =item * authform_authorwarning
1.35 matthew 2437:
1.112 bowersj2 2438: =item * authform_nochange
1.35 matthew 2439:
1.112 bowersj2 2440: =item * authform_kerberos
1.35 matthew 2441:
1.112 bowersj2 2442: =item * authform_internal
1.35 matthew 2443:
1.112 bowersj2 2444: =item * authform_filesystem
1.35 matthew 2445:
2446: =back
2447:
1.648 raeburn 2448: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2449:
1.35 matthew 2450: =cut
2451:
2452: #-------------------------------------------
1.32 matthew 2453: sub authform_header{
2454: my %in = (
2455: formname => 'cu',
1.80 albertel 2456: kerb_def_dom => '',
1.32 matthew 2457: @_,
2458: );
2459: $in{'formname'} = 'document.' . $in{'formname'};
2460: my $result='';
1.80 albertel 2461:
2462: #---------------------------------------------- Code for upper case translation
2463: my $Javascript_toUpperCase;
2464: unless ($in{kerb_def_dom}) {
2465: $Javascript_toUpperCase =<<"END";
2466: switch (choice) {
2467: case 'krb': currentform.elements[choicearg].value =
2468: currentform.elements[choicearg].value.toUpperCase();
2469: break;
2470: default:
2471: }
2472: END
2473: } else {
2474: $Javascript_toUpperCase = "";
2475: }
2476:
1.165 raeburn 2477: my $radioval = "'nochange'";
1.591 raeburn 2478: if (defined($in{'curr_authtype'})) {
2479: if ($in{'curr_authtype'} ne '') {
2480: $radioval = "'".$in{'curr_authtype'}."arg'";
2481: }
1.174 matthew 2482: }
1.165 raeburn 2483: my $argfield = 'null';
1.591 raeburn 2484: if (defined($in{'mode'})) {
1.165 raeburn 2485: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2486: if (defined($in{'curr_autharg'})) {
2487: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2488: $argfield = "'$in{'curr_autharg'}'";
2489: }
2490: }
2491: }
2492: }
2493:
1.32 matthew 2494: $result.=<<"END";
2495: var current = new Object();
1.165 raeburn 2496: current.radiovalue = $radioval;
2497: current.argfield = $argfield;
1.32 matthew 2498:
2499: function changed_radio(choice,currentform) {
2500: var choicearg = choice + 'arg';
2501: // If a radio button in changed, we need to change the argfield
2502: if (current.radiovalue != choice) {
2503: current.radiovalue = choice;
2504: if (current.argfield != null) {
2505: currentform.elements[current.argfield].value = '';
2506: }
2507: if (choice == 'nochange') {
2508: current.argfield = null;
2509: } else {
2510: current.argfield = choicearg;
2511: switch(choice) {
2512: case 'krb':
2513: currentform.elements[current.argfield].value =
2514: "$in{'kerb_def_dom'}";
2515: break;
2516: default:
2517: break;
2518: }
2519: }
2520: }
2521: return;
2522: }
1.22 www 2523:
1.32 matthew 2524: function changed_text(choice,currentform) {
2525: var choicearg = choice + 'arg';
2526: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2527: $Javascript_toUpperCase
1.32 matthew 2528: // clear old field
2529: if ((current.argfield != choicearg) && (current.argfield != null)) {
2530: currentform.elements[current.argfield].value = '';
2531: }
2532: current.argfield = choicearg;
2533: }
2534: set_auth_radio_buttons(choice,currentform);
2535: return;
1.20 www 2536: }
1.32 matthew 2537:
2538: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2539: var numauthchoices = currentform.login.length;
2540: if (typeof numauthchoices == "undefined") {
2541: return;
2542: }
1.32 matthew 2543: var i=0;
1.986 raeburn 2544: while (i < numauthchoices) {
1.32 matthew 2545: if (currentform.login[i].value == newvalue) { break; }
2546: i++;
2547: }
1.986 raeburn 2548: if (i == numauthchoices) {
1.32 matthew 2549: return;
2550: }
2551: current.radiovalue = newvalue;
2552: currentform.login[i].checked = true;
2553: return;
2554: }
2555: END
2556: return $result;
2557: }
2558:
1.1106 raeburn 2559: sub authform_authorwarning {
1.32 matthew 2560: my $result='';
1.144 matthew 2561: $result='<i>'.
2562: &mt('As a general rule, only authors or co-authors should be '.
2563: 'filesystem authenticated '.
2564: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2565: return $result;
2566: }
2567:
1.1106 raeburn 2568: sub authform_nochange {
1.32 matthew 2569: my %in = (
2570: formname => 'document.cu',
2571: kerb_def_dom => 'MSU.EDU',
2572: @_,
2573: );
1.1106 raeburn 2574: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2575: my $result;
1.1104 raeburn 2576: if (!$authnum) {
1.1105 raeburn 2577: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2578: } else {
2579: $result = '<label>'.&mt('[_1] Do not change login data',
2580: '<input type="radio" name="login" value="nochange" '.
2581: 'checked="checked" onclick="'.
1.281 albertel 2582: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2583: '</label>';
1.586 raeburn 2584: }
1.32 matthew 2585: return $result;
2586: }
2587:
1.591 raeburn 2588: sub authform_kerberos {
1.32 matthew 2589: my %in = (
2590: formname => 'document.cu',
2591: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2592: kerb_def_auth => 'krb4',
1.32 matthew 2593: @_,
2594: );
1.586 raeburn 2595: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2596: $autharg,$jscall);
1.1106 raeburn 2597: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2598: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2599: $check5 = ' checked="checked"';
1.80 albertel 2600: } else {
1.772 bisitz 2601: $check4 = ' checked="checked"';
1.80 albertel 2602: }
1.165 raeburn 2603: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2604: if (defined($in{'curr_authtype'})) {
2605: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2606: $krbcheck = ' checked="checked"';
1.623 raeburn 2607: if (defined($in{'mode'})) {
2608: if ($in{'mode'} eq 'modifyuser') {
2609: $krbcheck = '';
2610: }
2611: }
1.591 raeburn 2612: if (defined($in{'curr_kerb_ver'})) {
2613: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2614: $check5 = ' checked="checked"';
1.591 raeburn 2615: $check4 = '';
2616: } else {
1.772 bisitz 2617: $check4 = ' checked="checked"';
1.591 raeburn 2618: $check5 = '';
2619: }
1.586 raeburn 2620: }
1.591 raeburn 2621: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2622: $krbarg = $in{'curr_autharg'};
2623: }
1.586 raeburn 2624: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2625: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2626: $result =
2627: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2628: $in{'curr_autharg'},$krbver);
2629: } else {
2630: $result =
2631: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2632: }
2633: return $result;
2634: }
2635: }
2636: } else {
2637: if ($authnum == 1) {
1.784 bisitz 2638: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2639: }
2640: }
1.586 raeburn 2641: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2642: return;
1.587 raeburn 2643: } elsif ($authtype eq '') {
1.591 raeburn 2644: if (defined($in{'mode'})) {
1.587 raeburn 2645: if ($in{'mode'} eq 'modifycourse') {
2646: if ($authnum == 1) {
1.1104 raeburn 2647: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2648: }
2649: }
2650: }
1.586 raeburn 2651: }
2652: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2653: if ($authtype eq '') {
2654: $authtype = '<input type="radio" name="login" value="krb" '.
2655: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2656: $krbcheck.' />';
2657: }
2658: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2659: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2660: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2661: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2662: $in{'curr_authtype'} eq 'krb4')) {
2663: $result .= &mt
1.144 matthew 2664: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2665: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2666: '<label>'.$authtype,
1.281 albertel 2667: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2668: 'value="'.$krbarg.'" '.
1.144 matthew 2669: 'onchange="'.$jscall.'" />',
1.281 albertel 2670: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2671: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2672: '</label>');
1.586 raeburn 2673: } elsif ($can_assign{'krb4'}) {
2674: $result .= &mt
2675: ('[_1] Kerberos authenticated with domain [_2] '.
2676: '[_3] Version 4 [_4]',
2677: '<label>'.$authtype,
2678: '</label><input type="text" size="10" name="krbarg" '.
2679: 'value="'.$krbarg.'" '.
2680: 'onchange="'.$jscall.'" />',
2681: '<label><input type="hidden" name="krbver" value="4" />',
2682: '</label>');
2683: } elsif ($can_assign{'krb5'}) {
2684: $result .= &mt
2685: ('[_1] Kerberos authenticated with domain [_2] '.
2686: '[_3] Version 5 [_4]',
2687: '<label>'.$authtype,
2688: '</label><input type="text" size="10" name="krbarg" '.
2689: 'value="'.$krbarg.'" '.
2690: 'onchange="'.$jscall.'" />',
2691: '<label><input type="hidden" name="krbver" value="5" />',
2692: '</label>');
2693: }
1.32 matthew 2694: return $result;
2695: }
2696:
1.1106 raeburn 2697: sub authform_internal {
1.586 raeburn 2698: my %in = (
1.32 matthew 2699: formname => 'document.cu',
2700: kerb_def_dom => 'MSU.EDU',
2701: @_,
2702: );
1.586 raeburn 2703: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2704: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2705: if (defined($in{'curr_authtype'})) {
2706: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2707: if ($can_assign{'int'}) {
1.772 bisitz 2708: $intcheck = 'checked="checked" ';
1.623 raeburn 2709: if (defined($in{'mode'})) {
2710: if ($in{'mode'} eq 'modifyuser') {
2711: $intcheck = '';
2712: }
2713: }
1.591 raeburn 2714: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2715: $intarg = $in{'curr_autharg'};
2716: }
2717: } else {
2718: $result = &mt('Currently internally authenticated.');
2719: return $result;
1.165 raeburn 2720: }
2721: }
1.586 raeburn 2722: } else {
2723: if ($authnum == 1) {
1.784 bisitz 2724: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2725: }
2726: }
2727: if (!$can_assign{'int'}) {
2728: return;
1.587 raeburn 2729: } elsif ($authtype eq '') {
1.591 raeburn 2730: if (defined($in{'mode'})) {
1.587 raeburn 2731: if ($in{'mode'} eq 'modifycourse') {
2732: if ($authnum == 1) {
1.1104 raeburn 2733: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2734: }
2735: }
2736: }
1.165 raeburn 2737: }
1.586 raeburn 2738: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2739: if ($authtype eq '') {
2740: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2741: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2742: }
1.605 bisitz 2743: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2744: $intarg.'" onchange="'.$jscall.'" />';
2745: $result = &mt
1.144 matthew 2746: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2747: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2748: $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 2749: return $result;
2750: }
2751:
1.1104 raeburn 2752: sub authform_local {
1.32 matthew 2753: my %in = (
2754: formname => 'document.cu',
2755: kerb_def_dom => 'MSU.EDU',
2756: @_,
2757: );
1.586 raeburn 2758: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2759: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2760: if (defined($in{'curr_authtype'})) {
2761: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2762: if ($can_assign{'loc'}) {
1.772 bisitz 2763: $loccheck = 'checked="checked" ';
1.623 raeburn 2764: if (defined($in{'mode'})) {
2765: if ($in{'mode'} eq 'modifyuser') {
2766: $loccheck = '';
2767: }
2768: }
1.591 raeburn 2769: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2770: $locarg = $in{'curr_autharg'};
2771: }
2772: } else {
2773: $result = &mt('Currently using local (institutional) authentication.');
2774: return $result;
1.165 raeburn 2775: }
2776: }
1.586 raeburn 2777: } else {
2778: if ($authnum == 1) {
1.784 bisitz 2779: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2780: }
2781: }
2782: if (!$can_assign{'loc'}) {
2783: return;
1.587 raeburn 2784: } elsif ($authtype eq '') {
1.591 raeburn 2785: if (defined($in{'mode'})) {
1.587 raeburn 2786: if ($in{'mode'} eq 'modifycourse') {
2787: if ($authnum == 1) {
1.1104 raeburn 2788: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2789: }
2790: }
2791: }
1.165 raeburn 2792: }
1.586 raeburn 2793: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2794: if ($authtype eq '') {
2795: $authtype = '<input type="radio" name="login" value="loc" '.
2796: $loccheck.' onchange="'.$jscall.'" onclick="'.
2797: $jscall.'" />';
2798: }
2799: $autharg = '<input type="text" size="10" name="locarg" value="'.
2800: $locarg.'" onchange="'.$jscall.'" />';
2801: $result = &mt('[_1] Local Authentication with argument [_2]',
2802: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2803: return $result;
2804: }
2805:
1.1106 raeburn 2806: sub authform_filesystem {
1.32 matthew 2807: my %in = (
2808: formname => 'document.cu',
2809: kerb_def_dom => 'MSU.EDU',
2810: @_,
2811: );
1.586 raeburn 2812: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2813: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2814: if (defined($in{'curr_authtype'})) {
2815: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2816: if ($can_assign{'fsys'}) {
1.772 bisitz 2817: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2818: if (defined($in{'mode'})) {
2819: if ($in{'mode'} eq 'modifyuser') {
2820: $fsyscheck = '';
2821: }
2822: }
1.586 raeburn 2823: } else {
2824: $result = &mt('Currently Filesystem Authenticated.');
2825: return $result;
2826: }
2827: }
2828: } else {
2829: if ($authnum == 1) {
1.784 bisitz 2830: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2831: }
2832: }
2833: if (!$can_assign{'fsys'}) {
2834: return;
1.587 raeburn 2835: } elsif ($authtype eq '') {
1.591 raeburn 2836: if (defined($in{'mode'})) {
1.587 raeburn 2837: if ($in{'mode'} eq 'modifycourse') {
2838: if ($authnum == 1) {
1.1104 raeburn 2839: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2840: }
2841: }
2842: }
1.586 raeburn 2843: }
2844: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2845: if ($authtype eq '') {
2846: $authtype = '<input type="radio" name="login" value="fsys" '.
2847: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2848: $jscall.'" />';
2849: }
2850: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2851: ' onchange="'.$jscall.'" />';
2852: $result = &mt
1.144 matthew 2853: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2854: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2855: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2856: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2857: 'onchange="'.$jscall.'" />');
1.32 matthew 2858: return $result;
2859: }
2860:
1.586 raeburn 2861: sub get_assignable_auth {
2862: my ($dom) = @_;
2863: if ($dom eq '') {
2864: $dom = $env{'request.role.domain'};
2865: }
2866: my %can_assign = (
2867: krb4 => 1,
2868: krb5 => 1,
2869: int => 1,
2870: loc => 1,
2871: );
2872: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2873: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2874: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2875: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2876: my $context;
2877: if ($env{'request.role'} =~ /^au/) {
2878: $context = 'author';
2879: } elsif ($env{'request.role'} =~ /^dc/) {
2880: $context = 'domain';
2881: } elsif ($env{'request.course.id'}) {
2882: $context = 'course';
2883: }
2884: if ($context) {
2885: if (ref($authhash->{$context}) eq 'HASH') {
2886: %can_assign = %{$authhash->{$context}};
2887: }
2888: }
2889: }
2890: }
2891: my $authnum = 0;
2892: foreach my $key (keys(%can_assign)) {
2893: if ($can_assign{$key}) {
2894: $authnum ++;
2895: }
2896: }
2897: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2898: $authnum --;
2899: }
2900: return ($authnum,%can_assign);
2901: }
2902:
1.80 albertel 2903: ###############################################################
2904: ## Get Kerberos Defaults for Domain ##
2905: ###############################################################
2906: ##
2907: ## Returns default kerberos version and an associated argument
2908: ## as listed in file domain.tab. If not listed, provides
2909: ## appropriate default domain and kerberos version.
2910: ##
2911: #-------------------------------------------
2912:
2913: =pod
2914:
1.648 raeburn 2915: =item * &get_kerberos_defaults()
1.80 albertel 2916:
2917: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2918: version and domain. If not found, it defaults to version 4 and the
2919: domain of the server.
1.80 albertel 2920:
1.648 raeburn 2921: =over 4
2922:
1.80 albertel 2923: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2924:
1.648 raeburn 2925: =back
2926:
2927: =back
2928:
1.80 albertel 2929: =cut
2930:
2931: #-------------------------------------------
2932: sub get_kerberos_defaults {
2933: my $domain=shift;
1.641 raeburn 2934: my ($krbdef,$krbdefdom);
2935: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2936: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2937: $krbdef = $domdefaults{'auth_def'};
2938: $krbdefdom = $domdefaults{'auth_arg_def'};
2939: } else {
1.80 albertel 2940: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2941: my $krbdefdom=$1;
2942: $krbdefdom=~tr/a-z/A-Z/;
2943: $krbdef = "krb4";
2944: }
2945: return ($krbdef,$krbdefdom);
2946: }
1.112 bowersj2 2947:
1.32 matthew 2948:
1.46 matthew 2949: ###############################################################
2950: ## Thesaurus Functions ##
2951: ###############################################################
1.20 www 2952:
1.46 matthew 2953: =pod
1.20 www 2954:
1.112 bowersj2 2955: =head1 Thesaurus Functions
2956:
2957: =over 4
2958:
1.648 raeburn 2959: =item * &initialize_keywords()
1.46 matthew 2960:
2961: Initializes the package variable %Keywords if it is empty. Uses the
2962: package variable $thesaurus_db_file.
2963:
2964: =cut
2965:
2966: ###################################################
2967:
2968: sub initialize_keywords {
2969: return 1 if (scalar keys(%Keywords));
2970: # If we are here, %Keywords is empty, so fill it up
2971: # Make sure the file we need exists...
2972: if (! -e $thesaurus_db_file) {
2973: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2974: " failed because it does not exist");
2975: return 0;
2976: }
2977: # Set up the hash as a database
2978: my %thesaurus_db;
2979: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2980: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2981: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2982: $thesaurus_db_file);
2983: return 0;
2984: }
2985: # Get the average number of appearances of a word.
2986: my $avecount = $thesaurus_db{'average.count'};
2987: # Put keywords (those that appear > average) into %Keywords
2988: while (my ($word,$data)=each (%thesaurus_db)) {
2989: my ($count,undef) = split /:/,$data;
2990: $Keywords{$word}++ if ($count > $avecount);
2991: }
2992: untie %thesaurus_db;
2993: # Remove special values from %Keywords.
1.356 albertel 2994: foreach my $value ('total.count','average.count') {
2995: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2996: }
1.46 matthew 2997: return 1;
2998: }
2999:
3000: ###################################################
3001:
3002: =pod
3003:
1.648 raeburn 3004: =item * &keyword($word)
1.46 matthew 3005:
3006: Returns true if $word is a keyword. A keyword is a word that appears more
3007: than the average number of times in the thesaurus database. Calls
3008: &initialize_keywords
3009:
3010: =cut
3011:
3012: ###################################################
1.20 www 3013:
3014: sub keyword {
1.46 matthew 3015: return if (!&initialize_keywords());
3016: my $word=lc(shift());
3017: $word=~s/\W//g;
3018: return exists($Keywords{$word});
1.20 www 3019: }
1.46 matthew 3020:
3021: ###############################################################
3022:
3023: =pod
1.20 www 3024:
1.648 raeburn 3025: =item * &get_related_words()
1.46 matthew 3026:
1.160 matthew 3027: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3028: an array of words. If the keyword is not in the thesaurus, an empty array
3029: will be returned. The order of the words returned is determined by the
3030: database which holds them.
3031:
3032: Uses global $thesaurus_db_file.
3033:
1.1057 foxr 3034:
1.46 matthew 3035: =cut
3036:
3037: ###############################################################
3038: sub get_related_words {
3039: my $keyword = shift;
3040: my %thesaurus_db;
3041: if (! -e $thesaurus_db_file) {
3042: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3043: "failed because the file does not exist");
3044: return ();
3045: }
3046: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3047: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3048: return ();
3049: }
3050: my @Words=();
1.429 www 3051: my $count=0;
1.46 matthew 3052: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3053: # The first element is the number of times
3054: # the word appears. We do not need it now.
1.429 www 3055: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3056: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3057: my $threshold=$mostfrequentcount/10;
3058: foreach my $possibleword (@RelatedWords) {
3059: my ($word,$wordcount)=split(/\,/,$possibleword);
3060: if ($wordcount>$threshold) {
3061: push(@Words,$word);
3062: $count++;
3063: if ($count>10) { last; }
3064: }
1.20 www 3065: }
3066: }
1.46 matthew 3067: untie %thesaurus_db;
3068: return @Words;
1.14 harris41 3069: }
1.1090 foxr 3070: ###############################################################
3071: #
3072: # Spell checking
3073: #
3074:
3075: =pod
3076:
3077: =head1 Spell checking
3078:
3079: =over 4
3080:
3081: =item * &check_spelling($wordlist $language)
3082:
3083: Takes a string containing words and feeds it to an external
3084: spellcheck program via a pipeline. Returns a string containing
3085: them mis-spelled words.
3086:
3087: Parameters:
3088:
3089: =over 4
3090:
3091: =item - $wordlist
3092:
3093: String that will be fed into the spellcheck program.
3094:
3095: =item - $language
3096:
3097: Language string that specifies the language for which the spell
3098: check will be performed.
3099:
3100: =back
3101:
3102: =back
3103:
3104: Note: This sub assumes that aspell is installed.
3105:
3106:
3107: =cut
3108:
1.46 matthew 3109:
1.112 bowersj2 3110: =pod
3111:
3112: =back
3113:
3114: =cut
1.61 www 3115:
1.1090 foxr 3116: sub check_spelling {
3117: my ($wordlist, $language) = @_;
1.1091 foxr 3118: my @misspellings;
3119:
3120: # Generate the speller and set the langauge.
3121: # if explicitly selected:
1.1090 foxr 3122:
1.1091 foxr 3123: my $speller = Text::Aspell->new;
1.1090 foxr 3124: if ($language) {
1.1091 foxr 3125: $speller->set_option('lang', $language);
1.1090 foxr 3126: }
3127:
1.1091 foxr 3128: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3129:
1.1091 foxr 3130: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3131:
1.1091 foxr 3132: foreach my $word (@words) {
3133: if(! $speller->check($word)) {
3134: push(@misspellings, $word);
1.1090 foxr 3135: }
3136: }
1.1091 foxr 3137: return join(' ', @misspellings);
3138:
1.1090 foxr 3139: }
3140:
1.61 www 3141: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3142: =pod
3143:
1.112 bowersj2 3144: =head1 User Name Functions
3145:
3146: =over 4
3147:
1.648 raeburn 3148: =item * &plainname($uname,$udom,$first)
1.81 albertel 3149:
1.112 bowersj2 3150: Takes a users logon name and returns it as a string in
1.226 albertel 3151: "first middle last generation" form
3152: if $first is set to 'lastname' then it returns it as
3153: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3154:
3155: =cut
1.61 www 3156:
1.295 www 3157:
1.81 albertel 3158: ###############################################################
1.61 www 3159: sub plainname {
1.226 albertel 3160: my ($uname,$udom,$first)=@_;
1.537 albertel 3161: return if (!defined($uname) || !defined($udom));
1.295 www 3162: my %names=&getnames($uname,$udom);
1.226 albertel 3163: my $name=&Apache::lonnet::format_name($names{'firstname'},
3164: $names{'middlename'},
3165: $names{'lastname'},
3166: $names{'generation'},$first);
3167: $name=~s/^\s+//;
1.62 www 3168: $name=~s/\s+$//;
3169: $name=~s/\s+/ /g;
1.353 albertel 3170: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3171: return $name;
1.61 www 3172: }
1.66 www 3173:
3174: # -------------------------------------------------------------------- Nickname
1.81 albertel 3175: =pod
3176:
1.648 raeburn 3177: =item * &nickname($uname,$udom)
1.81 albertel 3178:
3179: Gets a users name and returns it as a string as
3180:
3181: ""nickname""
1.66 www 3182:
1.81 albertel 3183: if the user has a nickname or
3184:
3185: "first middle last generation"
3186:
3187: if the user does not
3188:
3189: =cut
1.66 www 3190:
3191: sub nickname {
3192: my ($uname,$udom)=@_;
1.537 albertel 3193: return if (!defined($uname) || !defined($udom));
1.295 www 3194: my %names=&getnames($uname,$udom);
1.68 albertel 3195: my $name=$names{'nickname'};
1.66 www 3196: if ($name) {
3197: $name='"'.$name.'"';
3198: } else {
3199: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3200: $names{'lastname'}.' '.$names{'generation'};
3201: $name=~s/\s+$//;
3202: $name=~s/\s+/ /g;
3203: }
3204: return $name;
3205: }
3206:
1.295 www 3207: sub getnames {
3208: my ($uname,$udom)=@_;
1.537 albertel 3209: return if (!defined($uname) || !defined($udom));
1.433 albertel 3210: if ($udom eq 'public' && $uname eq 'public') {
3211: return ('lastname' => &mt('Public'));
3212: }
1.295 www 3213: my $id=$uname.':'.$udom;
3214: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3215: if ($cached) {
3216: return %{$names};
3217: } else {
3218: my %loadnames=&Apache::lonnet::get('environment',
3219: ['firstname','middlename','lastname','generation','nickname'],
3220: $udom,$uname);
3221: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3222: return %loadnames;
3223: }
3224: }
1.61 www 3225:
1.542 raeburn 3226: # -------------------------------------------------------------------- getemails
1.648 raeburn 3227:
1.542 raeburn 3228: =pod
3229:
1.648 raeburn 3230: =item * &getemails($uname,$udom)
1.542 raeburn 3231:
3232: Gets a user's email information and returns it as a hash with keys:
3233: notification, critnotification, permanentemail
3234:
3235: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3236: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3237:
1.648 raeburn 3238:
1.542 raeburn 3239: =cut
3240:
1.648 raeburn 3241:
1.466 albertel 3242: sub getemails {
3243: my ($uname,$udom)=@_;
3244: if ($udom eq 'public' && $uname eq 'public') {
3245: return;
3246: }
1.467 www 3247: if (!$udom) { $udom=$env{'user.domain'}; }
3248: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3249: my $id=$uname.':'.$udom;
3250: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3251: if ($cached) {
3252: return %{$names};
3253: } else {
3254: my %loadnames=&Apache::lonnet::get('environment',
3255: ['notification','critnotification',
3256: 'permanentemail'],
3257: $udom,$uname);
3258: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3259: return %loadnames;
3260: }
3261: }
3262:
1.551 albertel 3263: sub flush_email_cache {
3264: my ($uname,$udom)=@_;
3265: if (!$udom) { $udom =$env{'user.domain'}; }
3266: if (!$uname) { $uname=$env{'user.name'}; }
3267: return if ($udom eq 'public' && $uname eq 'public');
3268: my $id=$uname.':'.$udom;
3269: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3270: }
3271:
1.728 raeburn 3272: # -------------------------------------------------------------------- getlangs
3273:
3274: =pod
3275:
3276: =item * &getlangs($uname,$udom)
3277:
3278: Gets a user's language preference and returns it as a hash with key:
3279: language.
3280:
3281: =cut
3282:
3283:
3284: sub getlangs {
3285: my ($uname,$udom) = @_;
3286: if (!$udom) { $udom =$env{'user.domain'}; }
3287: if (!$uname) { $uname=$env{'user.name'}; }
3288: my $id=$uname.':'.$udom;
3289: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3290: if ($cached) {
3291: return %{$langs};
3292: } else {
3293: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3294: $udom,$uname);
3295: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3296: return %loadlangs;
3297: }
3298: }
3299:
3300: sub flush_langs_cache {
3301: my ($uname,$udom)=@_;
3302: if (!$udom) { $udom =$env{'user.domain'}; }
3303: if (!$uname) { $uname=$env{'user.name'}; }
3304: return if ($udom eq 'public' && $uname eq 'public');
3305: my $id=$uname.':'.$udom;
3306: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3307: }
3308:
1.61 www 3309: # ------------------------------------------------------------------ Screenname
1.81 albertel 3310:
3311: =pod
3312:
1.648 raeburn 3313: =item * &screenname($uname,$udom)
1.81 albertel 3314:
3315: Gets a users screenname and returns it as a string
3316:
3317: =cut
1.61 www 3318:
3319: sub screenname {
3320: my ($uname,$udom)=@_;
1.258 albertel 3321: if ($uname eq $env{'user.name'} &&
3322: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3323: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3324: return $names{'screenname'};
1.62 www 3325: }
3326:
1.212 albertel 3327:
1.802 bisitz 3328: # ------------------------------------------------------------- Confirm Wrapper
3329: =pod
3330:
3331: =item confirmwrapper
3332:
3333: Wrap messages about completion of operation in box
3334:
3335: =cut
3336:
3337: sub confirmwrapper {
3338: my ($message)=@_;
3339: if ($message) {
3340: return "\n".'<div class="LC_confirm_box">'."\n"
3341: .$message."\n"
3342: .'</div>'."\n";
3343: } else {
3344: return $message;
3345: }
3346: }
3347:
1.62 www 3348: # ------------------------------------------------------------- Message Wrapper
3349:
3350: sub messagewrapper {
1.369 www 3351: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3352: return
1.441 albertel 3353: '<a href="/adm/email?compose=individual&'.
3354: 'recname='.$username.'&recdom='.$domain.
3355: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3356: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3357: }
1.802 bisitz 3358:
1.74 www 3359: # --------------------------------------------------------------- Notes Wrapper
3360:
3361: sub noteswrapper {
3362: my ($link,$un,$do)=@_;
3363: return
1.896 amueller 3364: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3365: }
1.802 bisitz 3366:
1.62 www 3367: # ------------------------------------------------------------- Aboutme Wrapper
3368:
3369: sub aboutmewrapper {
1.1070 raeburn 3370: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3371: if (!defined($username) && !defined($domain)) {
3372: return;
3373: }
1.1096 raeburn 3374: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3375: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3376: }
3377:
3378: # ------------------------------------------------------------ Syllabus Wrapper
3379:
3380: sub syllabuswrapper {
1.707 bisitz 3381: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3382: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3383: }
1.14 harris41 3384:
1.802 bisitz 3385: # -----------------------------------------------------------------------------
3386:
1.208 matthew 3387: sub track_student_link {
1.887 raeburn 3388: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3389: my $link ="/adm/trackstudent?";
1.208 matthew 3390: my $title = 'View recent activity';
3391: if (defined($sname) && $sname !~ /^\s*$/ &&
3392: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3393: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3394: $title .= ' of this student';
1.268 albertel 3395: }
1.208 matthew 3396: if (defined($target) && $target !~ /^\s*$/) {
3397: $target = qq{target="$target"};
3398: } else {
3399: $target = '';
3400: }
1.268 albertel 3401: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3402: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3403: $title = &mt($title);
3404: $linktext = &mt($linktext);
1.448 albertel 3405: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3406: &help_open_topic('View_recent_activity');
1.208 matthew 3407: }
3408:
1.781 raeburn 3409: sub slot_reservations_link {
3410: my ($linktext,$sname,$sdom,$target) = @_;
3411: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3412: my $title = 'View slot reservation history';
3413: if (defined($sname) && $sname !~ /^\s*$/ &&
3414: defined($sdom) && $sdom !~ /^\s*$/) {
3415: $link .= "&uname=$sname&udom=$sdom";
3416: $title .= ' of this student';
3417: }
3418: if (defined($target) && $target !~ /^\s*$/) {
3419: $target = qq{target="$target"};
3420: } else {
3421: $target = '';
3422: }
3423: $title = &mt($title);
3424: $linktext = &mt($linktext);
3425: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3426: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3427:
3428: }
3429:
1.508 www 3430: # ===================================================== Display a student photo
3431:
3432:
1.509 albertel 3433: sub student_image_tag {
1.508 www 3434: my ($domain,$user)=@_;
3435: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3436: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3437: return '<img src="'.$imgsrc.'" align="right" />';
3438: } else {
3439: return '';
3440: }
3441: }
3442:
1.112 bowersj2 3443: =pod
3444:
3445: =back
3446:
3447: =head1 Access .tab File Data
3448:
3449: =over 4
3450:
1.648 raeburn 3451: =item * &languageids()
1.112 bowersj2 3452:
3453: returns list of all language ids
3454:
3455: =cut
3456:
1.14 harris41 3457: sub languageids {
1.16 harris41 3458: return sort(keys(%language));
1.14 harris41 3459: }
3460:
1.112 bowersj2 3461: =pod
3462:
1.648 raeburn 3463: =item * &languagedescription()
1.112 bowersj2 3464:
3465: returns description of a specified language id
3466:
3467: =cut
3468:
1.14 harris41 3469: sub languagedescription {
1.125 www 3470: my $code=shift;
3471: return ($supported_language{$code}?'* ':'').
3472: $language{$code}.
1.126 www 3473: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3474: }
3475:
1.1048 foxr 3476: =pod
3477:
3478: =item * &plainlanguagedescription
3479:
3480: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3481: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3482:
3483: =cut
3484:
1.145 www 3485: sub plainlanguagedescription {
3486: my $code=shift;
3487: return $language{$code};
3488: }
3489:
1.1048 foxr 3490: =pod
3491:
3492: =item * &supportedlanguagecode
3493:
3494: Returns the supported language code (e.g. sptutf maps to pt) given a language
3495: code.
3496:
3497: =cut
3498:
1.145 www 3499: sub supportedlanguagecode {
3500: my $code=shift;
3501: return $supported_language{$code};
1.97 www 3502: }
3503:
1.112 bowersj2 3504: =pod
3505:
1.1048 foxr 3506: =item * &latexlanguage()
3507:
3508: Given a language key code returns the correspondnig language to use
3509: to select the correct hyphenation on LaTeX printouts. This is undef if there
3510: is no supported hyphenation for the language code.
3511:
3512: =cut
3513:
3514: sub latexlanguage {
3515: my $code = shift;
3516: return $latex_language{$code};
3517: }
3518:
3519: =pod
3520:
3521: =item * &latexhyphenation()
3522:
3523: Same as above but what's supplied is the language as it might be stored
3524: in the metadata.
3525:
3526: =cut
3527:
3528: sub latexhyphenation {
3529: my $key = shift;
3530: return $latex_language_bykey{$key};
3531: }
3532:
3533: =pod
3534:
1.648 raeburn 3535: =item * ©rightids()
1.112 bowersj2 3536:
3537: returns list of all copyrights
3538:
3539: =cut
3540:
3541: sub copyrightids {
3542: return sort(keys(%cprtag));
3543: }
3544:
3545: =pod
3546:
1.648 raeburn 3547: =item * ©rightdescription()
1.112 bowersj2 3548:
3549: returns description of a specified copyright id
3550:
3551: =cut
3552:
3553: sub copyrightdescription {
1.166 www 3554: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3555: }
1.197 matthew 3556:
3557: =pod
3558:
1.648 raeburn 3559: =item * &source_copyrightids()
1.192 taceyjo1 3560:
3561: returns list of all source copyrights
3562:
3563: =cut
3564:
3565: sub source_copyrightids {
3566: return sort(keys(%scprtag));
3567: }
3568:
3569: =pod
3570:
1.648 raeburn 3571: =item * &source_copyrightdescription()
1.192 taceyjo1 3572:
3573: returns description of a specified source copyright id
3574:
3575: =cut
3576:
3577: sub source_copyrightdescription {
3578: return &mt($scprtag{shift(@_)});
3579: }
1.112 bowersj2 3580:
3581: =pod
3582:
1.648 raeburn 3583: =item * &filecategories()
1.112 bowersj2 3584:
3585: returns list of all file categories
3586:
3587: =cut
3588:
3589: sub filecategories {
3590: return sort(keys(%category_extensions));
3591: }
3592:
3593: =pod
3594:
1.648 raeburn 3595: =item * &filecategorytypes()
1.112 bowersj2 3596:
3597: returns list of file types belonging to a given file
3598: category
3599:
3600: =cut
3601:
3602: sub filecategorytypes {
1.356 albertel 3603: my ($cat) = @_;
3604: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3605: }
3606:
3607: =pod
3608:
1.648 raeburn 3609: =item * &fileembstyle()
1.112 bowersj2 3610:
3611: returns embedding style for a specified file type
3612:
3613: =cut
3614:
3615: sub fileembstyle {
3616: return $fe{lc(shift(@_))};
1.169 www 3617: }
3618:
1.351 www 3619: sub filemimetype {
3620: return $fm{lc(shift(@_))};
3621: }
3622:
1.169 www 3623:
3624: sub filecategoryselect {
3625: my ($name,$value)=@_;
1.189 matthew 3626: return &select_form($value,$name,
1.970 raeburn 3627: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3628: }
3629:
3630: =pod
3631:
1.648 raeburn 3632: =item * &filedescription()
1.112 bowersj2 3633:
3634: returns description for a specified file type
3635:
3636: =cut
3637:
3638: sub filedescription {
1.188 matthew 3639: my $file_description = $fd{lc(shift())};
3640: $file_description =~ s:([\[\]]):~$1:g;
3641: return &mt($file_description);
1.112 bowersj2 3642: }
3643:
3644: =pod
3645:
1.648 raeburn 3646: =item * &filedescriptionex()
1.112 bowersj2 3647:
3648: returns description for a specified file type with
3649: extra formatting
3650:
3651: =cut
3652:
3653: sub filedescriptionex {
3654: my $ex=shift;
1.188 matthew 3655: my $file_description = $fd{lc($ex)};
3656: $file_description =~ s:([\[\]]):~$1:g;
3657: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3658: }
3659:
3660: # End of .tab access
3661: =pod
3662:
3663: =back
3664:
3665: =cut
3666:
3667: # ------------------------------------------------------------------ File Types
3668: sub fileextensions {
3669: return sort(keys(%fe));
3670: }
3671:
1.97 www 3672: # ----------------------------------------------------------- Display Languages
3673: # returns a hash with all desired display languages
3674: #
3675:
3676: sub display_languages {
3677: my %languages=();
1.695 raeburn 3678: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3679: $languages{$lang}=1;
1.97 www 3680: }
3681: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3682: if ($env{'form.displaylanguage'}) {
1.356 albertel 3683: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3684: $languages{$lang}=1;
1.97 www 3685: }
3686: }
3687: return %languages;
1.14 harris41 3688: }
3689:
1.582 albertel 3690: sub languages {
3691: my ($possible_langs) = @_;
1.695 raeburn 3692: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3693: if (!ref($possible_langs)) {
3694: if( wantarray ) {
3695: return @preferred_langs;
3696: } else {
3697: return $preferred_langs[0];
3698: }
3699: }
3700: my %possibilities = map { $_ => 1 } (@$possible_langs);
3701: my @preferred_possibilities;
3702: foreach my $preferred_lang (@preferred_langs) {
3703: if (exists($possibilities{$preferred_lang})) {
3704: push(@preferred_possibilities, $preferred_lang);
3705: }
3706: }
3707: if( wantarray ) {
3708: return @preferred_possibilities;
3709: }
3710: return $preferred_possibilities[0];
3711: }
3712:
1.742 raeburn 3713: sub user_lang {
3714: my ($touname,$toudom,$fromcid) = @_;
3715: my @userlangs;
3716: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3717: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3718: $env{'course.'.$fromcid.'.languages'}));
3719: } else {
3720: my %langhash = &getlangs($touname,$toudom);
3721: if ($langhash{'languages'} ne '') {
3722: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3723: } else {
3724: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3725: if ($domdefs{'lang_def'} ne '') {
3726: @userlangs = ($domdefs{'lang_def'});
3727: }
3728: }
3729: }
3730: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3731: my $user_lh = Apache::localize->get_handle(@languages);
3732: return $user_lh;
3733: }
3734:
3735:
1.112 bowersj2 3736: ###############################################################
3737: ## Student Answer Attempts ##
3738: ###############################################################
3739:
3740: =pod
3741:
3742: =head1 Alternate Problem Views
3743:
3744: =over 4
3745:
1.648 raeburn 3746: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3747: $getattempt, $regexp, $gradesub)
3748:
3749: Return string with previous attempt on problem. Arguments:
3750:
3751: =over 4
3752:
3753: =item * $symb: Problem, including path
3754:
3755: =item * $username: username of the desired student
3756:
3757: =item * $domain: domain of the desired student
1.14 harris41 3758:
1.112 bowersj2 3759: =item * $course: Course ID
1.14 harris41 3760:
1.112 bowersj2 3761: =item * $getattempt: Leave blank for all attempts, otherwise put
3762: something
1.14 harris41 3763:
1.112 bowersj2 3764: =item * $regexp: if string matches this regexp, the string will be
3765: sent to $gradesub
1.14 harris41 3766:
1.112 bowersj2 3767: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3768:
1.112 bowersj2 3769: =back
1.14 harris41 3770:
1.112 bowersj2 3771: The output string is a table containing all desired attempts, if any.
1.16 harris41 3772:
1.112 bowersj2 3773: =cut
1.1 albertel 3774:
3775: sub get_previous_attempt {
1.43 ng 3776: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3777: my $prevattempts='';
1.43 ng 3778: no strict 'refs';
1.1 albertel 3779: if ($symb) {
1.3 albertel 3780: my (%returnhash)=
3781: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3782: if ($returnhash{'version'}) {
3783: my %lasthash=();
3784: my $version;
3785: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3786: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3787: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3788: }
1.1 albertel 3789: }
1.596 albertel 3790: $prevattempts=&start_data_table().&start_data_table_header_row();
3791: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3792: my (%typeparts,%lasthidden);
1.945 raeburn 3793: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3794: foreach my $key (sort(keys(%lasthash))) {
3795: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3796: if ($#parts > 0) {
1.31 albertel 3797: my $data=$parts[-1];
1.989 raeburn 3798: next if ($data eq 'foilorder');
1.31 albertel 3799: pop(@parts);
1.1010 www 3800: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3801: if ($data eq 'type') {
3802: unless ($showsurv) {
3803: my $id = join(',',@parts);
3804: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3805: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3806: $lasthidden{$ign.'.'.$id} = 1;
3807: }
1.945 raeburn 3808: }
1.1010 www 3809: }
1.31 albertel 3810: } else {
1.41 ng 3811: if ($#parts == 0) {
3812: $prevattempts.='<th>'.$parts[0].'</th>';
3813: } else {
3814: $prevattempts.='<th>'.$ign.'</th>';
3815: }
1.31 albertel 3816: }
1.16 harris41 3817: }
1.596 albertel 3818: $prevattempts.=&end_data_table_header_row();
1.40 ng 3819: if ($getattempt eq '') {
3820: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3821: my @hidden;
3822: if (%typeparts) {
3823: foreach my $id (keys(%typeparts)) {
3824: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3825: push(@hidden,$id);
3826: }
3827: }
3828: }
3829: $prevattempts.=&start_data_table_row().
3830: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3831: if (@hidden) {
3832: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3833: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3834: my $hide;
3835: foreach my $id (@hidden) {
3836: if ($key =~ /^\Q$id\E/) {
3837: $hide = 1;
3838: last;
3839: }
3840: }
3841: if ($hide) {
3842: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3843: if (($data eq 'award') || ($data eq 'awarddetail')) {
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: } else {
3851: if ($key =~ /\./) {
3852: my $value = &format_previous_attempt_value($key,
3853: $returnhash{$version.':'.$key});
3854: $prevattempts.='<td>'.$value.' </td>';
3855: } else {
3856: $prevattempts.='<td> </td>';
3857: }
3858: }
3859: }
3860: } else {
3861: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3862: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3863: my $value = &format_previous_attempt_value($key,
3864: $returnhash{$version.':'.$key});
3865: $prevattempts.='<td>'.$value.' </td>';
3866: }
3867: }
3868: $prevattempts.=&end_data_table_row();
1.40 ng 3869: }
1.1 albertel 3870: }
1.945 raeburn 3871: my @currhidden = keys(%lasthidden);
1.596 albertel 3872: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3873: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3874: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3875: if (%typeparts) {
3876: my $hidden;
3877: foreach my $id (@currhidden) {
3878: if ($key =~ /^\Q$id\E/) {
3879: $hidden = 1;
3880: last;
3881: }
3882: }
3883: if ($hidden) {
3884: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3885: if (($data eq 'award') || ($data eq 'awarddetail')) {
3886: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3887: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3888: $value = &$gradesub($value);
3889: }
3890: $prevattempts.='<td>'.$value.' </td>';
3891: } else {
3892: $prevattempts.='<td> </td>';
3893: }
3894: } else {
3895: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3896: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3897: $value = &$gradesub($value);
3898: }
3899: $prevattempts.='<td>'.$value.' </td>';
3900: }
3901: } else {
3902: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3903: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3904: $value = &$gradesub($value);
3905: }
3906: $prevattempts.='<td>'.$value.' </td>';
3907: }
1.16 harris41 3908: }
1.596 albertel 3909: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3910: } else {
1.596 albertel 3911: $prevattempts=
3912: &start_data_table().&start_data_table_row().
3913: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3914: &end_data_table_row().&end_data_table();
1.1 albertel 3915: }
3916: } else {
1.596 albertel 3917: $prevattempts=
3918: &start_data_table().&start_data_table_row().
3919: '<td>'.&mt('No data.').'</td>'.
3920: &end_data_table_row().&end_data_table();
1.1 albertel 3921: }
1.10 albertel 3922: }
3923:
1.581 albertel 3924: sub format_previous_attempt_value {
3925: my ($key,$value) = @_;
1.1011 www 3926: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3927: $value = &Apache::lonlocal::locallocaltime($value);
3928: } elsif (ref($value) eq 'ARRAY') {
3929: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3930: } elsif ($key =~ /answerstring$/) {
3931: my %answers = &Apache::lonnet::str2hash($value);
3932: my @anskeys = sort(keys(%answers));
3933: if (@anskeys == 1) {
3934: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3935: if ($answer =~ m{\0}) {
3936: $answer =~ s{\0}{,}g;
1.988 raeburn 3937: }
3938: my $tag_internal_answer_name = 'INTERNAL';
3939: if ($anskeys[0] eq $tag_internal_answer_name) {
3940: $value = $answer;
3941: } else {
3942: $value = $anskeys[0].'='.$answer;
3943: }
3944: } else {
3945: foreach my $ans (@anskeys) {
3946: my $answer = $answers{$ans};
1.1001 raeburn 3947: if ($answer =~ m{\0}) {
3948: $answer =~ s{\0}{,}g;
1.988 raeburn 3949: }
3950: $value .= $ans.'='.$answer.'<br />';;
3951: }
3952: }
1.581 albertel 3953: } else {
3954: $value = &unescape($value);
3955: }
3956: return $value;
3957: }
3958:
3959:
1.107 albertel 3960: sub relative_to_absolute {
3961: my ($url,$output)=@_;
3962: my $parser=HTML::TokeParser->new(\$output);
3963: my $token;
3964: my $thisdir=$url;
3965: my @rlinks=();
3966: while ($token=$parser->get_token) {
3967: if ($token->[0] eq 'S') {
3968: if ($token->[1] eq 'a') {
3969: if ($token->[2]->{'href'}) {
3970: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3971: }
3972: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3973: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3974: } elsif ($token->[1] eq 'base') {
3975: $thisdir=$token->[2]->{'href'};
3976: }
3977: }
3978: }
3979: $thisdir=~s-/[^/]*$--;
1.356 albertel 3980: foreach my $link (@rlinks) {
1.726 raeburn 3981: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3982: ($link=~/^\//) ||
3983: ($link=~/^javascript:/i) ||
3984: ($link=~/^mailto:/i) ||
3985: ($link=~/^\#/)) {
3986: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3987: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3988: }
3989: }
3990: # -------------------------------------------------- Deal with Applet codebases
3991: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3992: return $output;
3993: }
3994:
1.112 bowersj2 3995: =pod
3996:
1.648 raeburn 3997: =item * &get_student_view()
1.112 bowersj2 3998:
3999: show a snapshot of what student was looking at
4000:
4001: =cut
4002:
1.10 albertel 4003: sub get_student_view {
1.186 albertel 4004: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4005: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4006: my (%form);
1.10 albertel 4007: my @elements=('symb','courseid','domain','username');
4008: foreach my $element (@elements) {
1.186 albertel 4009: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4010: }
1.186 albertel 4011: if (defined($moreenv)) {
4012: %form=(%form,%{$moreenv});
4013: }
1.236 albertel 4014: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4015: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4016: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4017: $userview=~s/\<body[^\>]*\>//gi;
4018: $userview=~s/\<\/body\>//gi;
4019: $userview=~s/\<html\>//gi;
4020: $userview=~s/\<\/html\>//gi;
4021: $userview=~s/\<head\>//gi;
4022: $userview=~s/\<\/head\>//gi;
4023: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4024: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4025: if (wantarray) {
4026: return ($userview,$response);
4027: } else {
4028: return $userview;
4029: }
4030: }
4031:
4032: sub get_student_view_with_retries {
4033: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4034:
4035: my $ok = 0; # True if we got a good response.
4036: my $content;
4037: my $response;
4038:
4039: # Try to get the student_view done. within the retries count:
4040:
4041: do {
4042: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4043: $ok = $response->is_success;
4044: if (!$ok) {
4045: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4046: }
4047: $retries--;
4048: } while (!$ok && ($retries > 0));
4049:
4050: if (!$ok) {
4051: $content = ''; # On error return an empty content.
4052: }
1.651 www 4053: if (wantarray) {
4054: return ($content, $response);
4055: } else {
4056: return $content;
4057: }
1.11 albertel 4058: }
4059:
1.112 bowersj2 4060: =pod
4061:
1.648 raeburn 4062: =item * &get_student_answers()
1.112 bowersj2 4063:
4064: show a snapshot of how student was answering problem
4065:
4066: =cut
4067:
1.11 albertel 4068: sub get_student_answers {
1.100 sakharuk 4069: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4070: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4071: my (%moreenv);
1.11 albertel 4072: my @elements=('symb','courseid','domain','username');
4073: foreach my $element (@elements) {
1.186 albertel 4074: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4075: }
1.186 albertel 4076: $moreenv{'grade_target'}='answer';
4077: %moreenv=(%form,%moreenv);
1.497 raeburn 4078: $feedurl = &Apache::lonnet::clutter($feedurl);
4079: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4080: return $userview;
1.1 albertel 4081: }
1.116 albertel 4082:
4083: =pod
4084:
4085: =item * &submlink()
4086:
1.242 albertel 4087: Inputs: $text $uname $udom $symb $target
1.116 albertel 4088:
4089: Returns: A link to grades.pm such as to see the SUBM view of a student
4090:
4091: =cut
4092:
4093: ###############################################
4094: sub submlink {
1.242 albertel 4095: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4096: if (!($uname && $udom)) {
4097: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4098: &Apache::lonnet::whichuser($symb);
1.116 albertel 4099: if (!$symb) { $symb=$cursymb; }
4100: }
1.254 matthew 4101: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4102: $symb=&escape($symb);
1.960 bisitz 4103: if ($target) { $target=" target=\"$target\""; }
4104: return
4105: '<a href="/adm/grades?command=submission'.
4106: '&symb='.$symb.
4107: '&student='.$uname.
4108: '&userdom='.$udom.'"'.
4109: $target.'>'.$text.'</a>';
1.242 albertel 4110: }
4111: ##############################################
4112:
4113: =pod
4114:
4115: =item * &pgrdlink()
4116:
4117: Inputs: $text $uname $udom $symb $target
4118:
4119: Returns: A link to grades.pm such as to see the PGRD view of a student
4120:
4121: =cut
4122:
4123: ###############################################
4124: sub pgrdlink {
4125: my $link=&submlink(@_);
4126: $link=~s/(&command=submission)/$1&showgrading=yes/;
4127: return $link;
4128: }
4129: ##############################################
4130:
4131: =pod
4132:
4133: =item * &pprmlink()
4134:
4135: Inputs: $text $uname $udom $symb $target
4136:
4137: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4138: student and a specific resource
1.242 albertel 4139:
4140: =cut
4141:
4142: ###############################################
4143: sub pprmlink {
4144: my ($text,$uname,$udom,$symb,$target)=@_;
4145: if (!($uname && $udom)) {
4146: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4147: &Apache::lonnet::whichuser($symb);
1.242 albertel 4148: if (!$symb) { $symb=$cursymb; }
4149: }
1.254 matthew 4150: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4151: $symb=&escape($symb);
1.242 albertel 4152: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4153: return '<a href="/adm/parmset?command=set&'.
4154: 'symb='.$symb.'&uname='.$uname.
4155: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4156: }
4157: ##############################################
1.37 matthew 4158:
1.112 bowersj2 4159: =pod
4160:
4161: =back
4162:
4163: =cut
4164:
1.37 matthew 4165: ###############################################
1.51 www 4166:
4167:
4168: sub timehash {
1.687 raeburn 4169: my ($thistime) = @_;
4170: my $timezone = &Apache::lonlocal::gettimezone();
4171: my $dt = DateTime->from_epoch(epoch => $thistime)
4172: ->set_time_zone($timezone);
4173: my $wday = $dt->day_of_week();
4174: if ($wday == 7) { $wday = 0; }
4175: return ( 'second' => $dt->second(),
4176: 'minute' => $dt->minute(),
4177: 'hour' => $dt->hour(),
4178: 'day' => $dt->day_of_month(),
4179: 'month' => $dt->month(),
4180: 'year' => $dt->year(),
4181: 'weekday' => $wday,
4182: 'dayyear' => $dt->day_of_year(),
4183: 'dlsav' => $dt->is_dst() );
1.51 www 4184: }
4185:
1.370 www 4186: sub utc_string {
4187: my ($date)=@_;
1.371 www 4188: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4189: }
4190:
1.51 www 4191: sub maketime {
4192: my %th=@_;
1.687 raeburn 4193: my ($epoch_time,$timezone,$dt);
4194: $timezone = &Apache::lonlocal::gettimezone();
4195: eval {
4196: $dt = DateTime->new( year => $th{'year'},
4197: month => $th{'month'},
4198: day => $th{'day'},
4199: hour => $th{'hour'},
4200: minute => $th{'minute'},
4201: second => $th{'second'},
4202: time_zone => $timezone,
4203: );
4204: };
4205: if (!$@) {
4206: $epoch_time = $dt->epoch;
4207: if ($epoch_time) {
4208: return $epoch_time;
4209: }
4210: }
1.51 www 4211: return POSIX::mktime(
4212: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4213: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4214: }
4215:
4216: #########################################
1.51 www 4217:
4218: sub findallcourses {
1.482 raeburn 4219: my ($roles,$uname,$udom) = @_;
1.355 albertel 4220: my %roles;
4221: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4222: my %courses;
1.51 www 4223: my $now=time;
1.482 raeburn 4224: if (!defined($uname)) {
4225: $uname = $env{'user.name'};
4226: }
4227: if (!defined($udom)) {
4228: $udom = $env{'user.domain'};
4229: }
4230: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4231: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4232: if (!%roles) {
4233: %roles = (
4234: cc => 1,
1.907 raeburn 4235: co => 1,
1.482 raeburn 4236: in => 1,
4237: ep => 1,
4238: ta => 1,
4239: cr => 1,
4240: st => 1,
4241: );
4242: }
4243: foreach my $entry (keys(%roleshash)) {
4244: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4245: if ($trole =~ /^cr/) {
4246: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4247: } else {
4248: next if (!exists($roles{$trole}));
4249: }
4250: if ($tend) {
4251: next if ($tend < $now);
4252: }
4253: if ($tstart) {
4254: next if ($tstart > $now);
4255: }
1.1058 raeburn 4256: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4257: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4258: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4259: if ($secpart eq '') {
4260: ($cnum,$role) = split(/_/,$cnumpart);
4261: $sec = 'none';
1.1058 raeburn 4262: $value .= $cnum.'/';
1.482 raeburn 4263: } else {
4264: $cnum = $cnumpart;
4265: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4266: $value .= $cnum.'/'.$sec;
4267: }
4268: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4269: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4270: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4271: }
4272: } else {
4273: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4274: }
1.482 raeburn 4275: }
4276: } else {
4277: foreach my $key (keys(%env)) {
1.483 albertel 4278: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4279: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4280: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4281: next if ($role eq 'ca' || $role eq 'aa');
4282: next if (%roles && !exists($roles{$role}));
4283: my ($starttime,$endtime)=split(/\./,$env{$key});
4284: my $active=1;
4285: if ($starttime) {
4286: if ($now<$starttime) { $active=0; }
4287: }
4288: if ($endtime) {
4289: if ($now>$endtime) { $active=0; }
4290: }
4291: if ($active) {
1.1058 raeburn 4292: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4293: if ($sec eq '') {
4294: $sec = 'none';
1.1058 raeburn 4295: } else {
4296: $value .= $sec;
4297: }
4298: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4299: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4300: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4301: }
4302: } else {
4303: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4304: }
1.474 raeburn 4305: }
4306: }
1.51 www 4307: }
4308: }
1.474 raeburn 4309: return %courses;
1.51 www 4310: }
1.37 matthew 4311:
1.54 www 4312: ###############################################
1.474 raeburn 4313:
4314: sub blockcheck {
1.1062 raeburn 4315: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4316:
4317: if (!defined($udom)) {
4318: $udom = $env{'user.domain'};
4319: }
4320: if (!defined($uname)) {
4321: $uname = $env{'user.name'};
4322: }
4323:
4324: # If uname and udom are for a course, check for blocks in the course.
4325:
4326: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4327: my ($startblock,$endblock,$triggerblock) =
4328: &get_blocks($setters,$activity,$udom,$uname,$url);
4329: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4330: }
1.474 raeburn 4331:
1.502 raeburn 4332: my $startblock = 0;
4333: my $endblock = 0;
1.1062 raeburn 4334: my $triggerblock = '';
1.482 raeburn 4335: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4336:
1.490 raeburn 4337: # If uname is for a user, and activity is course-specific, i.e.,
4338: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4339:
1.490 raeburn 4340: if (($activity eq 'boards' || $activity eq 'chat' ||
4341: $activity eq 'groups') && ($env{'request.course.id'})) {
4342: foreach my $key (keys(%live_courses)) {
4343: if ($key ne $env{'request.course.id'}) {
4344: delete($live_courses{$key});
4345: }
4346: }
4347: }
4348:
4349: my $otheruser = 0;
4350: my %own_courses;
4351: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4352: # Resource belongs to user other than current user.
4353: $otheruser = 1;
4354: # Gather courses for current user
4355: %own_courses =
4356: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4357: }
4358:
4359: # Gather active course roles - course coordinator, instructor,
4360: # exam proctor, ta, student, or custom role.
1.474 raeburn 4361:
4362: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4363: my ($cdom,$cnum);
4364: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4365: $cdom = $env{'course.'.$course.'.domain'};
4366: $cnum = $env{'course.'.$course.'.num'};
4367: } else {
1.490 raeburn 4368: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4369: }
4370: my $no_ownblock = 0;
4371: my $no_userblock = 0;
1.533 raeburn 4372: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4373: # Check if current user has 'evb' priv for this
4374: if (defined($own_courses{$course})) {
4375: foreach my $sec (keys(%{$own_courses{$course}})) {
4376: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4377: if ($sec ne 'none') {
4378: $checkrole .= '/'.$sec;
4379: }
4380: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4381: $no_ownblock = 1;
4382: last;
4383: }
4384: }
4385: }
4386: # if they have 'evb' priv and are currently not playing student
4387: next if (($no_ownblock) &&
4388: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4389: }
1.474 raeburn 4390: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4391: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4392: if ($sec ne 'none') {
1.482 raeburn 4393: $checkrole .= '/'.$sec;
1.474 raeburn 4394: }
1.490 raeburn 4395: if ($otheruser) {
4396: # Resource belongs to user other than current user.
4397: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4398: my (%allroles,%userroles);
4399: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4400: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4401: my ($trole,$tdom,$tnum,$tsec);
4402: if ($entry =~ /^cr/) {
4403: ($trole,$tdom,$tnum,$tsec) =
4404: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4405: } else {
4406: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4407: }
4408: my ($spec,$area,$trest);
4409: $area = '/'.$tdom.'/'.$tnum;
4410: $trest = $tnum;
4411: if ($tsec ne '') {
4412: $area .= '/'.$tsec;
4413: $trest .= '/'.$tsec;
4414: }
4415: $spec = $trole.'.'.$area;
4416: if ($trole =~ /^cr/) {
4417: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4418: $tdom,$spec,$trest,$area);
4419: } else {
4420: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4421: $tdom,$spec,$trest,$area);
4422: }
4423: }
4424: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4425: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4426: if ($1) {
4427: $no_userblock = 1;
4428: last;
4429: }
1.486 raeburn 4430: }
4431: }
1.490 raeburn 4432: } else {
4433: # Resource belongs to current user
4434: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4435: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4436: $no_ownblock = 1;
4437: last;
4438: }
1.474 raeburn 4439: }
4440: }
4441: # if they have the evb priv and are currently not playing student
1.482 raeburn 4442: next if (($no_ownblock) &&
1.491 albertel 4443: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4444: next if ($no_userblock);
1.474 raeburn 4445:
1.866 kalberla 4446: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4447: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4448:
1.1062 raeburn 4449: my ($start,$end,$trigger) =
4450: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4451: if (($start != 0) &&
4452: (($startblock == 0) || ($startblock > $start))) {
4453: $startblock = $start;
1.1062 raeburn 4454: if ($trigger ne '') {
4455: $triggerblock = $trigger;
4456: }
1.502 raeburn 4457: }
4458: if (($end != 0) &&
4459: (($endblock == 0) || ($endblock < $end))) {
4460: $endblock = $end;
1.1062 raeburn 4461: if ($trigger ne '') {
4462: $triggerblock = $trigger;
4463: }
1.502 raeburn 4464: }
1.490 raeburn 4465: }
1.1062 raeburn 4466: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4467: }
4468:
4469: sub get_blocks {
1.1062 raeburn 4470: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4471: my $startblock = 0;
4472: my $endblock = 0;
1.1062 raeburn 4473: my $triggerblock = '';
1.490 raeburn 4474: my $course = $cdom.'_'.$cnum;
4475: $setters->{$course} = {};
4476: $setters->{$course}{'staff'} = [];
4477: $setters->{$course}{'times'} = [];
1.1062 raeburn 4478: $setters->{$course}{'triggers'} = [];
4479: my (@blockers,%triggered);
4480: my $now = time;
4481: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4482: if ($activity eq 'docs') {
4483: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4484: foreach my $block (@blockers) {
4485: if ($block =~ /^firstaccess____(.+)$/) {
4486: my $item = $1;
4487: my $type = 'map';
4488: my $timersymb = $item;
4489: if ($item eq 'course') {
4490: $type = 'course';
4491: } elsif ($item =~ /___\d+___/) {
4492: $type = 'resource';
4493: } else {
4494: $timersymb = &Apache::lonnet::symbread($item);
4495: }
4496: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4497: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4498: $triggered{$block} = {
4499: start => $start,
4500: end => $end,
4501: type => $type,
4502: };
4503: }
4504: }
4505: } else {
4506: foreach my $block (keys(%commblocks)) {
4507: if ($block =~ m/^(\d+)____(\d+)$/) {
4508: my ($start,$end) = ($1,$2);
4509: if ($start <= time && $end >= time) {
4510: if (ref($commblocks{$block}) eq 'HASH') {
4511: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4512: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4513: unless(grep(/^\Q$block\E$/,@blockers)) {
4514: push(@blockers,$block);
4515: }
4516: }
4517: }
4518: }
4519: }
4520: } elsif ($block =~ /^firstaccess____(.+)$/) {
4521: my $item = $1;
4522: my $timersymb = $item;
4523: my $type = 'map';
4524: if ($item eq 'course') {
4525: $type = 'course';
4526: } elsif ($item =~ /___\d+___/) {
4527: $type = 'resource';
4528: } else {
4529: $timersymb = &Apache::lonnet::symbread($item);
4530: }
4531: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4532: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4533: if ($start && $end) {
4534: if (($start <= time) && ($end >= time)) {
4535: unless (grep(/^\Q$block\E$/,@blockers)) {
4536: push(@blockers,$block);
4537: $triggered{$block} = {
4538: start => $start,
4539: end => $end,
4540: type => $type,
4541: };
4542: }
4543: }
1.490 raeburn 4544: }
1.1062 raeburn 4545: }
4546: }
4547: }
4548: foreach my $blocker (@blockers) {
4549: my ($staff_name,$staff_dom,$title,$blocks) =
4550: &parse_block_record($commblocks{$blocker});
4551: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4552: my ($start,$end,$triggertype);
4553: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4554: ($start,$end) = ($1,$2);
4555: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4556: $start = $triggered{$blocker}{'start'};
4557: $end = $triggered{$blocker}{'end'};
4558: $triggertype = $triggered{$blocker}{'type'};
4559: }
4560: if ($start) {
4561: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4562: if ($triggertype) {
4563: push(@{$$setters{$course}{'triggers'}},$triggertype);
4564: } else {
4565: push(@{$$setters{$course}{'triggers'}},0);
4566: }
4567: if ( ($startblock == 0) || ($startblock > $start) ) {
4568: $startblock = $start;
4569: if ($triggertype) {
4570: $triggerblock = $blocker;
1.474 raeburn 4571: }
4572: }
1.1062 raeburn 4573: if ( ($endblock == 0) || ($endblock < $end) ) {
4574: $endblock = $end;
4575: if ($triggertype) {
4576: $triggerblock = $blocker;
4577: }
4578: }
1.474 raeburn 4579: }
4580: }
1.1062 raeburn 4581: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4582: }
4583:
4584: sub parse_block_record {
4585: my ($record) = @_;
4586: my ($setuname,$setudom,$title,$blocks);
4587: if (ref($record) eq 'HASH') {
4588: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4589: $title = &unescape($record->{'event'});
4590: $blocks = $record->{'blocks'};
4591: } else {
4592: my @data = split(/:/,$record,3);
4593: if (scalar(@data) eq 2) {
4594: $title = $data[1];
4595: ($setuname,$setudom) = split(/@/,$data[0]);
4596: } else {
4597: ($setuname,$setudom,$title) = @data;
4598: }
4599: $blocks = { 'com' => 'on' };
4600: }
4601: return ($setuname,$setudom,$title,$blocks);
4602: }
4603:
1.854 kalberla 4604: sub blocking_status {
1.1062 raeburn 4605: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4606: my %setters;
1.890 droeschl 4607:
1.1061 raeburn 4608: # check for active blocking
1.1062 raeburn 4609: my ($startblock,$endblock,$triggerblock) =
4610: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4611: my $blocked = 0;
4612: if ($startblock && $endblock) {
4613: $blocked = 1;
4614: }
1.890 droeschl 4615:
1.1061 raeburn 4616: # caller just wants to know whether a block is active
4617: if (!wantarray) { return $blocked; }
4618:
4619: # build a link to a popup window containing the details
4620: my $querystring = "?activity=$activity";
4621: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4622: if ($activity eq 'port') {
4623: $querystring .= "&udom=$udom" if $udom;
4624: $querystring .= "&uname=$uname" if $uname;
4625: } elsif ($activity eq 'docs') {
4626: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4627: }
1.1061 raeburn 4628:
4629: my $output .= <<'END_MYBLOCK';
4630: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4631: var options = "width=" + w + ",height=" + h + ",";
4632: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4633: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4634: var newWin = window.open(url, wdwName, options);
4635: newWin.focus();
4636: }
1.890 droeschl 4637: END_MYBLOCK
1.854 kalberla 4638:
1.1061 raeburn 4639: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4640:
1.1061 raeburn 4641: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4642: my $text = &mt('Communication Blocked');
4643: if ($activity eq 'docs') {
4644: $text = &mt('Content Access Blocked');
1.1063 raeburn 4645: } elsif ($activity eq 'printout') {
4646: $text = &mt('Printing Blocked');
1.1062 raeburn 4647: }
1.1061 raeburn 4648: $output .= <<"END_BLOCK";
1.867 kalberla 4649: <div class='LC_comblock'>
1.869 kalberla 4650: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4651: title='$text'>
4652: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4653: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4654: title='$text'>$text</a>
1.867 kalberla 4655: </div>
4656:
4657: END_BLOCK
1.474 raeburn 4658:
1.1061 raeburn 4659: return ($blocked, $output);
1.854 kalberla 4660: }
1.490 raeburn 4661:
1.60 matthew 4662: ###############################################
4663:
1.682 raeburn 4664: sub check_ip_acc {
4665: my ($acc)=@_;
4666: &Apache::lonxml::debug("acc is $acc");
4667: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4668: return 1;
4669: }
4670: my $allowed=0;
4671: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4672:
4673: my $name;
4674: foreach my $pattern (split(',',$acc)) {
4675: $pattern =~ s/^\s*//;
4676: $pattern =~ s/\s*$//;
4677: if ($pattern =~ /\*$/) {
4678: #35.8.*
4679: $pattern=~s/\*//;
4680: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4681: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4682: #35.8.3.[34-56]
4683: my $low=$2;
4684: my $high=$3;
4685: $pattern=$1;
4686: if ($ip =~ /^\Q$pattern\E/) {
4687: my $last=(split(/\./,$ip))[3];
4688: if ($last <=$high && $last >=$low) { $allowed=1; }
4689: }
4690: } elsif ($pattern =~ /^\*/) {
4691: #*.msu.edu
4692: $pattern=~s/\*//;
4693: if (!defined($name)) {
4694: use Socket;
4695: my $netaddr=inet_aton($ip);
4696: ($name)=gethostbyaddr($netaddr,AF_INET);
4697: }
4698: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4699: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4700: #127.0.0.1
4701: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4702: } else {
4703: #some.name.com
4704: if (!defined($name)) {
4705: use Socket;
4706: my $netaddr=inet_aton($ip);
4707: ($name)=gethostbyaddr($netaddr,AF_INET);
4708: }
4709: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4710: }
4711: if ($allowed) { last; }
4712: }
4713: return $allowed;
4714: }
4715:
4716: ###############################################
4717:
1.60 matthew 4718: =pod
4719:
1.112 bowersj2 4720: =head1 Domain Template Functions
4721:
4722: =over 4
4723:
4724: =item * &determinedomain()
1.60 matthew 4725:
4726: Inputs: $domain (usually will be undef)
4727:
1.63 www 4728: Returns: Determines which domain should be used for designs
1.60 matthew 4729:
4730: =cut
1.54 www 4731:
1.60 matthew 4732: ###############################################
1.63 www 4733: sub determinedomain {
4734: my $domain=shift;
1.531 albertel 4735: if (! $domain) {
1.60 matthew 4736: # Determine domain if we have not been given one
1.893 raeburn 4737: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4738: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4739: if ($env{'request.role.domain'}) {
4740: $domain=$env{'request.role.domain'};
1.60 matthew 4741: }
4742: }
1.63 www 4743: return $domain;
4744: }
4745: ###############################################
1.517 raeburn 4746:
1.518 albertel 4747: sub devalidate_domconfig_cache {
4748: my ($udom)=@_;
4749: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4750: }
4751:
4752: # ---------------------- Get domain configuration for a domain
4753: sub get_domainconf {
4754: my ($udom) = @_;
4755: my $cachetime=1800;
4756: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4757: if (defined($cached)) { return %{$result}; }
4758:
4759: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4760: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4761: my (%designhash,%legacy);
1.518 albertel 4762: if (keys(%domconfig) > 0) {
4763: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4764: if (keys(%{$domconfig{'login'}})) {
4765: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4766: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4767: if ($key eq 'loginvia') {
4768: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4769: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4770: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4771: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4772: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4773: $designhash{$udom.'.login.loginvia'} = $server;
4774: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4775:
4776: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4777: } else {
1.1013 raeburn 4778: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4779: }
4780: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4781: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4782: }
1.946 raeburn 4783: }
4784: }
4785: }
4786: }
4787: } else {
4788: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4789: $designhash{$udom.'.login.'.$key.'_'.$img} =
4790: $domconfig{'login'}{$key}{$img};
4791: }
1.699 raeburn 4792: }
4793: } else {
4794: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4795: }
1.632 raeburn 4796: }
4797: } else {
4798: $legacy{'login'} = 1;
1.518 albertel 4799: }
1.632 raeburn 4800: } else {
4801: $legacy{'login'} = 1;
1.518 albertel 4802: }
4803: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4804: if (keys(%{$domconfig{'rolecolors'}})) {
4805: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4806: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4807: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4808: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4809: }
1.518 albertel 4810: }
4811: }
1.632 raeburn 4812: } else {
4813: $legacy{'rolecolors'} = 1;
1.518 albertel 4814: }
1.632 raeburn 4815: } else {
4816: $legacy{'rolecolors'} = 1;
1.518 albertel 4817: }
1.948 raeburn 4818: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4819: if ($domconfig{'autoenroll'}{'co-owners'}) {
4820: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4821: }
4822: }
1.632 raeburn 4823: if (keys(%legacy) > 0) {
4824: my %legacyhash = &get_legacy_domconf($udom);
4825: foreach my $item (keys(%legacyhash)) {
4826: if ($item =~ /^\Q$udom\E\.login/) {
4827: if ($legacy{'login'}) {
4828: $designhash{$item} = $legacyhash{$item};
4829: }
4830: } else {
4831: if ($legacy{'rolecolors'}) {
4832: $designhash{$item} = $legacyhash{$item};
4833: }
1.518 albertel 4834: }
4835: }
4836: }
1.632 raeburn 4837: } else {
4838: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4839: }
4840: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4841: $cachetime);
4842: return %designhash;
4843: }
4844:
1.632 raeburn 4845: sub get_legacy_domconf {
4846: my ($udom) = @_;
4847: my %legacyhash;
4848: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4849: my $designfile = $designdir.'/'.$udom.'.tab';
4850: if (-e $designfile) {
4851: if ( open (my $fh,"<$designfile") ) {
4852: while (my $line = <$fh>) {
4853: next if ($line =~ /^\#/);
4854: chomp($line);
4855: my ($key,$val)=(split(/\=/,$line));
4856: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4857: }
4858: close($fh);
4859: }
4860: }
1.1026 raeburn 4861: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4862: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4863: }
4864: return %legacyhash;
4865: }
4866:
1.63 www 4867: =pod
4868:
1.112 bowersj2 4869: =item * &domainlogo()
1.63 www 4870:
4871: Inputs: $domain (usually will be undef)
4872:
4873: Returns: A link to a domain logo, if the domain logo exists.
4874: If the domain logo does not exist, a description of the domain.
4875:
4876: =cut
1.112 bowersj2 4877:
1.63 www 4878: ###############################################
4879: sub domainlogo {
1.517 raeburn 4880: my $domain = &determinedomain(shift);
1.518 albertel 4881: my %designhash = &get_domainconf($domain);
1.517 raeburn 4882: # See if there is a logo
4883: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4884: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4885: if ($imgsrc =~ m{^/(adm|res)/}) {
4886: if ($imgsrc =~ m{^/res/}) {
4887: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4888: &Apache::lonnet::repcopy($local_name);
4889: }
4890: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4891: }
4892: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4893: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4894: return &Apache::lonnet::domain($domain,'description');
1.59 www 4895: } else {
1.60 matthew 4896: return '';
1.59 www 4897: }
4898: }
1.63 www 4899: ##############################################
4900:
4901: =pod
4902:
1.112 bowersj2 4903: =item * &designparm()
1.63 www 4904:
4905: Inputs: $which parameter; $domain (usually will be undef)
4906:
4907: Returns: value of designparamter $which
4908:
4909: =cut
1.112 bowersj2 4910:
1.397 albertel 4911:
1.400 albertel 4912: ##############################################
1.397 albertel 4913: sub designparm {
4914: my ($which,$domain)=@_;
4915: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4916: return $env{'environment.color.'.$which};
1.96 www 4917: }
1.63 www 4918: $domain=&determinedomain($domain);
1.1016 raeburn 4919: my %domdesign;
4920: unless ($domain eq 'public') {
4921: %domdesign = &get_domainconf($domain);
4922: }
1.520 raeburn 4923: my $output;
1.517 raeburn 4924: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4925: $output = $domdesign{$domain.'.'.$which};
1.63 www 4926: } else {
1.520 raeburn 4927: $output = $defaultdesign{$which};
4928: }
4929: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4930: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4931: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4932: if ($output =~ m{^/res/}) {
4933: my $local_name = &Apache::lonnet::filelocation('',$output);
4934: &Apache::lonnet::repcopy($local_name);
4935: }
1.520 raeburn 4936: $output = &lonhttpdurl($output);
4937: }
1.63 www 4938: }
1.520 raeburn 4939: return $output;
1.63 www 4940: }
1.59 www 4941:
1.822 bisitz 4942: ##############################################
4943: =pod
4944:
1.832 bisitz 4945: =item * &authorspace()
4946:
1.1028 raeburn 4947: Inputs: $url (usually will be undef).
1.832 bisitz 4948:
1.1132 raeburn 4949: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4950: directory being viewed (or for which action is being taken).
4951: If $url is provided, and begins /priv/<domain>/<uname>
4952: the path will be that portion of the $context argument.
4953: Otherwise the path will be for the author space of the current
4954: user when the current role is author, or for that of the
4955: co-author/assistant co-author space when the current role
4956: is co-author or assistant co-author.
1.832 bisitz 4957:
4958: =cut
4959:
4960: sub authorspace {
1.1028 raeburn 4961: my ($url) = @_;
4962: if ($url ne '') {
4963: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4964: return $1;
4965: }
4966: }
1.832 bisitz 4967: my $caname = '';
1.1024 www 4968: my $cadom = '';
1.1028 raeburn 4969: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4970: ($cadom,$caname) =
1.832 bisitz 4971: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4972: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4973: $caname = $env{'user.name'};
1.1024 www 4974: $cadom = $env{'user.domain'};
1.832 bisitz 4975: }
1.1028 raeburn 4976: if (($caname ne '') && ($cadom ne '')) {
4977: return "/priv/$cadom/$caname/";
4978: }
4979: return;
1.832 bisitz 4980: }
4981:
4982: ##############################################
4983: =pod
4984:
1.822 bisitz 4985: =item * &head_subbox()
4986:
4987: Inputs: $content (contains HTML code with page functions, etc.)
4988:
4989: Returns: HTML div with $content
4990: To be included in page header
4991:
4992: =cut
4993:
4994: sub head_subbox {
4995: my ($content)=@_;
4996: my $output =
1.993 raeburn 4997: '<div class="LC_head_subbox">'
1.822 bisitz 4998: .$content
4999: .'</div>'
5000: }
5001:
5002: ##############################################
5003: =pod
5004:
5005: =item * &CSTR_pageheader()
5006:
1.1026 raeburn 5007: Input: (optional) filename from which breadcrumb trail is built.
5008: In most cases no input as needed, as $env{'request.filename'}
5009: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5010:
5011: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5012: To be included on Authoring Space pages
1.822 bisitz 5013:
5014: =cut
5015:
5016: sub CSTR_pageheader {
1.1026 raeburn 5017: my ($trailfile) = @_;
5018: if ($trailfile eq '') {
5019: $trailfile = $env{'request.filename'};
5020: }
5021:
5022: # this is for resources; directories have customtitle, and crumbs
5023: # and select recent are created in lonpubdir.pm
5024:
5025: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5026: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5027: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5028: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5029: $formaction =~ s{/+}{/}g;
1.822 bisitz 5030:
5031: my $parentpath = '';
5032: my $lastitem = '';
5033: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5034: $parentpath = $1;
5035: $lastitem = $2;
5036: } else {
5037: $lastitem = $thisdisfn;
5038: }
1.921 bisitz 5039:
5040: my $output =
1.822 bisitz 5041: '<div>'
5042: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5043: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5044: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5045: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5046: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5047:
5048: if ($lastitem) {
5049: $output .=
5050: '<span class="LC_filename">'
5051: .$lastitem
5052: .'</span>';
5053: }
5054: $output .=
5055: '<br />'
1.822 bisitz 5056: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5057: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5058: .'</form>'
5059: .&Apache::lonmenu::constspaceform()
5060: .'</div>';
1.921 bisitz 5061:
5062: return $output;
1.822 bisitz 5063: }
5064:
1.60 matthew 5065: ###############################################
5066: ###############################################
5067:
5068: =pod
5069:
1.112 bowersj2 5070: =back
5071:
1.549 albertel 5072: =head1 HTML Helpers
1.112 bowersj2 5073:
5074: =over 4
5075:
5076: =item * &bodytag()
1.60 matthew 5077:
5078: Returns a uniform header for LON-CAPA web pages.
5079:
5080: Inputs:
5081:
1.112 bowersj2 5082: =over 4
5083:
5084: =item * $title, A title to be displayed on the page.
5085:
5086: =item * $function, the current role (can be undef).
5087:
5088: =item * $addentries, extra parameters for the <body> tag.
5089:
5090: =item * $bodyonly, if defined, only return the <body> tag.
5091:
5092: =item * $domain, if defined, force a given domain.
5093:
5094: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5095: text interface only)
1.60 matthew 5096:
1.814 bisitz 5097: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5098: navigational links
1.317 albertel 5099:
1.338 albertel 5100: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5101:
1.460 albertel 5102: =item * $args, optional argument valid values are
5103: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5104: inherit_jsmath -> when creating popup window in a page,
5105: should it have jsmath forced on by the
5106: current page
1.460 albertel 5107:
1.1096 raeburn 5108: =item * $advtoolsref, optional argument, ref to an array containing
5109: inlineremote items to be added in "Functions" menu below
5110: breadcrumbs.
5111:
1.112 bowersj2 5112: =back
5113:
1.60 matthew 5114: Returns: A uniform header for LON-CAPA web pages.
5115: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5116: If $bodyonly is undef or zero, an html string containing a <body> tag and
5117: other decorations will be returned.
5118:
5119: =cut
5120:
1.54 www 5121: sub bodytag {
1.831 bisitz 5122: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5123: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5124:
1.954 raeburn 5125: my $public;
5126: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5127: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5128: $public = 1;
5129: }
1.460 albertel 5130: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5131:
1.183 matthew 5132: $function = &get_users_function() if (!$function);
1.339 albertel 5133: my $img = &designparm($function.'.img',$domain);
5134: my $font = &designparm($function.'.font',$domain);
5135: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5136:
1.803 bisitz 5137: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5138: 'bgcolor' => $pgbg,
1.339 albertel 5139: 'text' => $font,
5140: 'alink' => &designparm($function.'.alink',$domain),
5141: 'vlink' => &designparm($function.'.vlink',$domain),
5142: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5143: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5144:
1.63 www 5145: # role and realm
1.378 raeburn 5146: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5147: if ($role eq 'ca') {
1.479 albertel 5148: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5149: $realm = &plainname($rname,$rdom);
1.378 raeburn 5150: }
1.55 www 5151: # realm
1.258 albertel 5152: if ($env{'request.course.id'}) {
1.378 raeburn 5153: if ($env{'request.role'} !~ /^cr/) {
5154: $role = &Apache::lonnet::plaintext($role,&course_type());
5155: }
1.898 raeburn 5156: if ($env{'request.course.sec'}) {
5157: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5158: }
1.359 albertel 5159: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5160: } else {
5161: $role = &Apache::lonnet::plaintext($role);
1.54 www 5162: }
1.433 albertel 5163:
1.359 albertel 5164: if (!$realm) { $realm=' '; }
1.330 albertel 5165:
1.438 albertel 5166: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5167:
1.101 www 5168: # construct main body tag
1.359 albertel 5169: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5170: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5171:
1.1131 raeburn 5172: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5173:
1.1130 raeburn 5174: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5175: return $bodytag;
1.1130 raeburn 5176: }
1.359 albertel 5177:
1.954 raeburn 5178: if ($public) {
1.433 albertel 5179: undef($role);
5180: }
1.359 albertel 5181:
1.762 bisitz 5182: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5183: #
5184: # Extra info if you are the DC
5185: my $dc_info = '';
5186: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5187: $env{'course.'.$env{'request.course.id'}.
5188: '.domain'}.'/'})) {
5189: my $cid = $env{'request.course.id'};
1.917 raeburn 5190: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5191: $dc_info =~ s/\s+$//;
1.359 albertel 5192: }
5193:
1.898 raeburn 5194: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5195:
1.903 droeschl 5196: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5197:
5198: # if ($env{'request.state'} eq 'construct') {
5199: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5200: # }
5201:
1.1130 raeburn 5202: $bodytag .= Apache::lonhtmlcommon::scripttag(
5203: Apache::lonmenu::utilityfunctions(), 'start');
1.359 albertel 5204:
1.1130 raeburn 5205: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5206:
1.916 droeschl 5207: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5208: if ($dc_info) {
5209: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5210: }
1.1130 raeburn 5211: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5212: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5213: return $bodytag;
5214: }
1.894 droeschl 5215:
1.927 raeburn 5216: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5217: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5218: }
1.916 droeschl 5219:
1.1130 raeburn 5220: $bodytag .= $right;
1.852 droeschl 5221:
1.917 raeburn 5222: if ($dc_info) {
5223: $dc_info = &dc_courseid_toggle($dc_info);
5224: }
5225: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5226:
1.903 droeschl 5227: #don't show menus for public users
1.954 raeburn 5228: if (!$public){
1.903 droeschl 5229: $bodytag .= Apache::lonmenu::secondary_menu();
5230: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5231: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5232: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5233: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5234: $args->{'bread_crumbs'});
1.1096 raeburn 5235: } elsif ($forcereg) {
5236: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5237: $args->{'group'});
5238: } else {
5239: $bodytag .=
5240: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5241: $forcereg,$args->{'group'},
5242: $args->{'bread_crumbs'},
5243: $advtoolsref);
1.920 raeburn 5244: }
1.903 droeschl 5245: }else{
5246: # this is to seperate menu from content when there's no secondary
5247: # menu. Especially needed for public accessible ressources.
5248: $bodytag .= '<hr style="clear:both" />';
5249: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5250: }
1.903 droeschl 5251:
1.235 raeburn 5252: return $bodytag;
1.182 matthew 5253: }
5254:
1.917 raeburn 5255: sub dc_courseid_toggle {
5256: my ($dc_info) = @_;
1.980 raeburn 5257: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5258: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5259: &mt('(More ...)').'</a></span>'.
5260: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5261: }
5262:
1.330 albertel 5263: sub make_attr_string {
5264: my ($register,$attr_ref) = @_;
5265:
5266: if ($attr_ref && !ref($attr_ref)) {
5267: die("addentries Must be a hash ref ".
5268: join(':',caller(1))." ".
5269: join(':',caller(0))." ");
5270: }
5271:
5272: if ($register) {
1.339 albertel 5273: my ($on_load,$on_unload);
5274: foreach my $key (keys(%{$attr_ref})) {
5275: if (lc($key) eq 'onload') {
5276: $on_load.=$attr_ref->{$key}.';';
5277: delete($attr_ref->{$key});
5278:
5279: } elsif (lc($key) eq 'onunload') {
5280: $on_unload.=$attr_ref->{$key}.';';
5281: delete($attr_ref->{$key});
5282: }
5283: }
1.953 droeschl 5284: $attr_ref->{'onload'} = $on_load;
5285: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5286: }
1.339 albertel 5287:
1.330 albertel 5288: my $attr_string;
5289: foreach my $attr (keys(%$attr_ref)) {
5290: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5291: }
5292: return $attr_string;
5293: }
5294:
5295:
1.182 matthew 5296: ###############################################
1.251 albertel 5297: ###############################################
5298:
5299: =pod
5300:
5301: =item * &endbodytag()
5302:
5303: Returns a uniform footer for LON-CAPA web pages.
5304:
1.635 raeburn 5305: Inputs: 1 - optional reference to an args hash
5306: If in the hash, key for noredirectlink has a value which evaluates to true,
5307: a 'Continue' link is not displayed if the page contains an
5308: internal redirect in the <head></head> section,
5309: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5310:
5311: =cut
5312:
5313: sub endbodytag {
1.635 raeburn 5314: my ($args) = @_;
1.1080 raeburn 5315: my $endbodytag;
5316: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5317: $endbodytag='</body>';
5318: }
1.269 albertel 5319: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5320: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5321: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5322: $endbodytag=
5323: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5324: &mt('Continue').'</a>'.
5325: $endbodytag;
5326: }
1.315 albertel 5327: }
1.251 albertel 5328: return $endbodytag;
5329: }
5330:
1.352 albertel 5331: =pod
5332:
5333: =item * &standard_css()
5334:
5335: Returns a style sheet
5336:
5337: Inputs: (all optional)
5338: domain -> force to color decorate a page for a specific
5339: domain
5340: function -> force usage of a specific rolish color scheme
5341: bgcolor -> override the default page bgcolor
5342:
5343: =cut
5344:
1.343 albertel 5345: sub standard_css {
1.345 albertel 5346: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5347: $function = &get_users_function() if (!$function);
5348: my $img = &designparm($function.'.img', $domain);
5349: my $tabbg = &designparm($function.'.tabbg', $domain);
5350: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5351: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5352: #second colour for later usage
1.345 albertel 5353: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5354: my $pgbg_or_bgcolor =
5355: $bgcolor ||
1.352 albertel 5356: &designparm($function.'.pgbg', $domain);
1.382 albertel 5357: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5358: my $alink = &designparm($function.'.alink', $domain);
5359: my $vlink = &designparm($function.'.vlink', $domain);
5360: my $link = &designparm($function.'.link', $domain);
5361:
1.602 albertel 5362: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5363: my $mono = 'monospace';
1.850 bisitz 5364: my $data_table_head = $sidebg;
5365: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5366: my $data_table_dark = '#E0E0E0';
1.470 banghart 5367: my $data_table_darker = '#CCCCCC';
1.349 albertel 5368: my $data_table_highlight = '#FFFF00';
1.352 albertel 5369: my $mail_new = '#FFBB77';
5370: my $mail_new_hover = '#DD9955';
5371: my $mail_read = '#BBBB77';
5372: my $mail_read_hover = '#999944';
5373: my $mail_replied = '#AAAA88';
5374: my $mail_replied_hover = '#888855';
5375: my $mail_other = '#99BBBB';
5376: my $mail_other_hover = '#669999';
1.391 albertel 5377: my $table_header = '#DDDDDD';
1.489 raeburn 5378: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5379: my $lg_border_color = '#C8C8C8';
1.952 onken 5380: my $button_hover = '#BF2317';
1.392 albertel 5381:
1.608 albertel 5382: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5383: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5384: : '0 3px 0 4px';
1.448 albertel 5385:
1.523 albertel 5386:
1.343 albertel 5387: return <<END;
1.947 droeschl 5388:
5389: /* needed for iframe to allow 100% height in FF */
5390: body, html {
5391: margin: 0;
5392: padding: 0 0.5%;
5393: height: 99%; /* to avoid scrollbars */
5394: }
5395:
1.795 www 5396: body {
1.911 bisitz 5397: font-family: $sans;
5398: line-height:130%;
5399: font-size:0.83em;
5400: color:$font;
1.795 www 5401: }
5402:
1.959 onken 5403: a:focus,
5404: a:focus img {
1.795 www 5405: color: red;
5406: }
1.698 harmsja 5407:
1.911 bisitz 5408: form, .inline {
5409: display: inline;
1.795 www 5410: }
1.721 harmsja 5411:
1.795 www 5412: .LC_right {
1.911 bisitz 5413: text-align:right;
1.795 www 5414: }
5415:
5416: .LC_middle {
1.911 bisitz 5417: vertical-align:middle;
1.795 www 5418: }
1.721 harmsja 5419:
1.1130 raeburn 5420: .LC_floatleft {
5421: float: left;
5422: }
5423:
5424: .LC_floatright {
5425: float: right;
5426: }
5427:
1.911 bisitz 5428: .LC_400Box {
5429: width:400px;
5430: }
1.721 harmsja 5431:
1.947 droeschl 5432: .LC_iframecontainer {
5433: width: 98%;
5434: margin: 0;
5435: position: fixed;
5436: top: 8.5em;
5437: bottom: 0;
5438: }
5439:
5440: .LC_iframecontainer iframe{
5441: border: none;
5442: width: 100%;
5443: height: 100%;
5444: }
5445:
1.778 bisitz 5446: .LC_filename {
5447: font-family: $mono;
5448: white-space:pre;
1.921 bisitz 5449: font-size: 120%;
1.778 bisitz 5450: }
5451:
5452: .LC_fileicon {
5453: border: none;
5454: height: 1.3em;
5455: vertical-align: text-bottom;
5456: margin-right: 0.3em;
5457: text-decoration:none;
5458: }
5459:
1.1008 www 5460: .LC_setting {
5461: text-decoration:underline;
5462: }
5463:
1.350 albertel 5464: .LC_error {
5465: color: red;
5466: }
1.795 www 5467:
1.1097 bisitz 5468: .LC_warning {
5469: color: darkorange;
5470: }
5471:
1.457 albertel 5472: .LC_diff_removed {
1.733 bisitz 5473: color: red;
1.394 albertel 5474: }
1.532 albertel 5475:
5476: .LC_info,
1.457 albertel 5477: .LC_success,
5478: .LC_diff_added {
1.350 albertel 5479: color: green;
5480: }
1.795 www 5481:
1.802 bisitz 5482: div.LC_confirm_box {
5483: background-color: #FAFAFA;
5484: border: 1px solid $lg_border_color;
5485: margin-right: 0;
5486: padding: 5px;
5487: }
5488:
5489: div.LC_confirm_box .LC_error img,
5490: div.LC_confirm_box .LC_success img {
5491: vertical-align: middle;
5492: }
5493:
1.440 albertel 5494: .LC_icon {
1.771 droeschl 5495: border: none;
1.790 droeschl 5496: vertical-align: middle;
1.771 droeschl 5497: }
5498:
1.543 albertel 5499: .LC_docs_spacer {
5500: width: 25px;
5501: height: 1px;
1.771 droeschl 5502: border: none;
1.543 albertel 5503: }
1.346 albertel 5504:
1.532 albertel 5505: .LC_internal_info {
1.735 bisitz 5506: color: #999999;
1.532 albertel 5507: }
5508:
1.794 www 5509: .LC_discussion {
1.1050 www 5510: background: $data_table_dark;
1.911 bisitz 5511: border: 1px solid black;
5512: margin: 2px;
1.794 www 5513: }
5514:
5515: .LC_disc_action_left {
1.1050 www 5516: background: $sidebg;
1.911 bisitz 5517: text-align: left;
1.1050 www 5518: padding: 4px;
5519: margin: 2px;
1.794 www 5520: }
5521:
5522: .LC_disc_action_right {
1.1050 www 5523: background: $sidebg;
1.911 bisitz 5524: text-align: right;
1.1050 www 5525: padding: 4px;
5526: margin: 2px;
1.794 www 5527: }
5528:
5529: .LC_disc_new_item {
1.911 bisitz 5530: background: white;
5531: border: 2px solid red;
1.1050 www 5532: margin: 4px;
5533: padding: 4px;
1.794 www 5534: }
5535:
5536: .LC_disc_old_item {
1.911 bisitz 5537: background: white;
1.1050 www 5538: margin: 4px;
5539: padding: 4px;
1.794 www 5540: }
5541:
1.458 albertel 5542: table.LC_pastsubmission {
5543: border: 1px solid black;
5544: margin: 2px;
5545: }
5546:
1.924 bisitz 5547: table#LC_menubuttons {
1.345 albertel 5548: width: 100%;
5549: background: $pgbg;
1.392 albertel 5550: border: 2px;
1.402 albertel 5551: border-collapse: separate;
1.803 bisitz 5552: padding: 0;
1.345 albertel 5553: }
1.392 albertel 5554:
1.801 tempelho 5555: table#LC_title_bar a {
5556: color: $fontmenu;
5557: }
1.836 bisitz 5558:
1.807 droeschl 5559: table#LC_title_bar {
1.819 tempelho 5560: clear: both;
1.836 bisitz 5561: display: none;
1.807 droeschl 5562: }
5563:
1.795 www 5564: table#LC_title_bar,
1.933 droeschl 5565: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5566: table#LC_title_bar.LC_with_remote {
1.359 albertel 5567: width: 100%;
1.392 albertel 5568: border-color: $pgbg;
5569: border-style: solid;
5570: border-width: $border;
1.379 albertel 5571: background: $pgbg;
1.801 tempelho 5572: color: $fontmenu;
1.392 albertel 5573: border-collapse: collapse;
1.803 bisitz 5574: padding: 0;
1.819 tempelho 5575: margin: 0;
1.359 albertel 5576: }
1.795 www 5577:
1.933 droeschl 5578: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5579: margin: 0;
5580: padding: 0;
1.933 droeschl 5581: position: relative;
5582: list-style: none;
1.913 droeschl 5583: }
1.933 droeschl 5584: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5585: display: inline;
5586: }
1.933 droeschl 5587:
5588: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5589: padding: 0;
1.933 droeschl 5590: margin: 0;
5591: float: left;
1.913 droeschl 5592: }
1.933 droeschl 5593: .LC_breadcrumb_tools_tools {
5594: padding: 0;
5595: margin: 0;
1.913 droeschl 5596: float: right;
5597: }
5598:
1.359 albertel 5599: table#LC_title_bar td {
5600: background: $tabbg;
5601: }
1.795 www 5602:
1.911 bisitz 5603: table#LC_menubuttons img {
1.803 bisitz 5604: border: none;
1.346 albertel 5605: }
1.795 www 5606:
1.842 droeschl 5607: .LC_breadcrumbs_component {
1.911 bisitz 5608: float: right;
5609: margin: 0 1em;
1.357 albertel 5610: }
1.842 droeschl 5611: .LC_breadcrumbs_component img {
1.911 bisitz 5612: vertical-align: middle;
1.777 tempelho 5613: }
1.795 www 5614:
1.383 albertel 5615: td.LC_table_cell_checkbox {
5616: text-align: center;
5617: }
1.795 www 5618:
5619: .LC_fontsize_small {
1.911 bisitz 5620: font-size: 70%;
1.705 tempelho 5621: }
5622:
1.844 bisitz 5623: #LC_breadcrumbs {
1.911 bisitz 5624: clear:both;
5625: background: $sidebg;
5626: border-bottom: 1px solid $lg_border_color;
5627: line-height: 2.5em;
1.933 droeschl 5628: overflow: hidden;
1.911 bisitz 5629: margin: 0;
5630: padding: 0;
1.995 raeburn 5631: text-align: left;
1.819 tempelho 5632: }
1.862 bisitz 5633:
1.1098 bisitz 5634: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5635: clear:both;
5636: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5637: border: 1px solid $sidebg;
1.1098 bisitz 5638: margin: 0 0 10px 0;
1.966 bisitz 5639: padding: 3px;
1.995 raeburn 5640: text-align: left;
1.822 bisitz 5641: }
5642:
1.795 www 5643: .LC_fontsize_medium {
1.911 bisitz 5644: font-size: 85%;
1.705 tempelho 5645: }
5646:
1.795 www 5647: .LC_fontsize_large {
1.911 bisitz 5648: font-size: 120%;
1.705 tempelho 5649: }
5650:
1.346 albertel 5651: .LC_menubuttons_inline_text {
5652: color: $font;
1.698 harmsja 5653: font-size: 90%;
1.701 harmsja 5654: padding-left:3px;
1.346 albertel 5655: }
5656:
1.934 droeschl 5657: .LC_menubuttons_inline_text img{
5658: vertical-align: middle;
5659: }
5660:
1.1051 www 5661: li.LC_menubuttons_inline_text img {
1.951 onken 5662: cursor:pointer;
1.1002 droeschl 5663: text-decoration: none;
1.951 onken 5664: }
5665:
1.526 www 5666: .LC_menubuttons_link {
5667: text-decoration: none;
5668: }
1.795 www 5669:
1.522 albertel 5670: .LC_menubuttons_category {
1.521 www 5671: color: $font;
1.526 www 5672: background: $pgbg;
1.521 www 5673: font-size: larger;
5674: font-weight: bold;
5675: }
5676:
1.346 albertel 5677: td.LC_menubuttons_text {
1.911 bisitz 5678: color: $font;
1.346 albertel 5679: }
1.706 harmsja 5680:
1.346 albertel 5681: .LC_current_location {
5682: background: $tabbg;
5683: }
1.795 www 5684:
1.938 bisitz 5685: table.LC_data_table {
1.347 albertel 5686: border: 1px solid #000000;
1.402 albertel 5687: border-collapse: separate;
1.426 albertel 5688: border-spacing: 1px;
1.610 albertel 5689: background: $pgbg;
1.347 albertel 5690: }
1.795 www 5691:
1.422 albertel 5692: .LC_data_table_dense {
5693: font-size: small;
5694: }
1.795 www 5695:
1.507 raeburn 5696: table.LC_nested_outer {
5697: border: 1px solid #000000;
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.879 raeburn 5703: table.LC_innerpickbox,
1.507 raeburn 5704: table.LC_nested {
1.803 bisitz 5705: border: none;
1.589 raeburn 5706: border-collapse: collapse;
1.803 bisitz 5707: border-spacing: 0;
1.507 raeburn 5708: width: 100%;
5709: }
1.795 www 5710:
1.911 bisitz 5711: table.LC_data_table tr th,
5712: table.LC_calendar tr th,
1.879 raeburn 5713: table.LC_prior_tries tr th,
5714: table.LC_innerpickbox tr th {
1.349 albertel 5715: font-weight: bold;
5716: background-color: $data_table_head;
1.801 tempelho 5717: color:$fontmenu;
1.701 harmsja 5718: font-size:90%;
1.347 albertel 5719: }
1.795 www 5720:
1.879 raeburn 5721: table.LC_innerpickbox tr th,
5722: table.LC_innerpickbox tr td {
5723: vertical-align: top;
5724: }
5725:
1.711 raeburn 5726: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5727: background-color: #CCCCCC;
1.711 raeburn 5728: font-weight: bold;
5729: text-align: left;
5730: }
1.795 www 5731:
1.912 bisitz 5732: table.LC_data_table tr.LC_odd_row > td {
5733: background-color: $data_table_light;
5734: padding: 2px;
5735: vertical-align: top;
5736: }
5737:
1.809 bisitz 5738: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5739: background-color: $data_table_light;
1.912 bisitz 5740: vertical-align: top;
5741: }
5742:
5743: table.LC_data_table tr.LC_even_row > td {
5744: background-color: $data_table_dark;
1.425 albertel 5745: padding: 2px;
1.900 bisitz 5746: vertical-align: top;
1.347 albertel 5747: }
1.795 www 5748:
1.809 bisitz 5749: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5750: background-color: $data_table_dark;
1.900 bisitz 5751: vertical-align: top;
1.347 albertel 5752: }
1.795 www 5753:
1.425 albertel 5754: table.LC_data_table tr.LC_data_table_highlight td {
5755: background-color: $data_table_darker;
5756: }
1.795 www 5757:
1.639 raeburn 5758: table.LC_data_table tr td.LC_leftcol_header {
5759: background-color: $data_table_head;
5760: font-weight: bold;
5761: }
1.795 www 5762:
1.451 albertel 5763: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5764: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5765: font-weight: bold;
5766: font-style: italic;
5767: text-align: center;
5768: padding: 8px;
1.347 albertel 5769: }
1.795 www 5770:
1.1114 raeburn 5771: table.LC_data_table tr.LC_empty_row td,
5772: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5773: background-color: $sidebg;
5774: }
5775:
5776: table.LC_nested tr.LC_empty_row td {
5777: background-color: #FFFFFF;
5778: }
5779:
1.890 droeschl 5780: table.LC_caption {
5781: }
5782:
1.507 raeburn 5783: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5784: padding: 4ex
5785: }
1.795 www 5786:
1.507 raeburn 5787: table.LC_nested_outer tr th {
5788: font-weight: bold;
1.801 tempelho 5789: color:$fontmenu;
1.507 raeburn 5790: background-color: $data_table_head;
1.701 harmsja 5791: font-size: small;
1.507 raeburn 5792: border-bottom: 1px solid #000000;
5793: }
1.795 www 5794:
1.507 raeburn 5795: table.LC_nested_outer tr td.LC_subheader {
5796: background-color: $data_table_head;
5797: font-weight: bold;
5798: font-size: small;
5799: border-bottom: 1px solid #000000;
5800: text-align: right;
1.451 albertel 5801: }
1.795 www 5802:
1.507 raeburn 5803: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5804: background-color: #CCCCCC;
1.451 albertel 5805: font-weight: bold;
5806: font-size: small;
1.507 raeburn 5807: text-align: center;
5808: }
1.795 www 5809:
1.589 raeburn 5810: table.LC_nested tr.LC_info_row td.LC_left_item,
5811: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5812: text-align: left;
1.451 albertel 5813: }
1.795 www 5814:
1.507 raeburn 5815: table.LC_nested td {
1.735 bisitz 5816: background-color: #FFFFFF;
1.451 albertel 5817: font-size: small;
1.507 raeburn 5818: }
1.795 www 5819:
1.507 raeburn 5820: table.LC_nested_outer tr th.LC_right_item,
5821: table.LC_nested tr.LC_info_row td.LC_right_item,
5822: table.LC_nested tr.LC_odd_row td.LC_right_item,
5823: table.LC_nested tr td.LC_right_item {
1.451 albertel 5824: text-align: right;
5825: }
5826:
1.507 raeburn 5827: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5828: background-color: #EEEEEE;
1.451 albertel 5829: }
5830:
1.473 raeburn 5831: table.LC_createuser {
5832: }
5833:
5834: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5835: font-size: small;
1.473 raeburn 5836: }
5837:
5838: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5839: background-color: #CCCCCC;
1.473 raeburn 5840: font-weight: bold;
5841: text-align: center;
5842: }
5843:
1.349 albertel 5844: table.LC_calendar {
5845: border: 1px solid #000000;
5846: border-collapse: collapse;
1.917 raeburn 5847: width: 98%;
1.349 albertel 5848: }
1.795 www 5849:
1.349 albertel 5850: table.LC_calendar_pickdate {
5851: font-size: xx-small;
5852: }
1.795 www 5853:
1.349 albertel 5854: table.LC_calendar tr td {
5855: border: 1px solid #000000;
5856: vertical-align: top;
1.917 raeburn 5857: width: 14%;
1.349 albertel 5858: }
1.795 www 5859:
1.349 albertel 5860: table.LC_calendar tr td.LC_calendar_day_empty {
5861: background-color: $data_table_dark;
5862: }
1.795 www 5863:
1.779 bisitz 5864: table.LC_calendar tr td.LC_calendar_day_current {
5865: background-color: $data_table_highlight;
1.777 tempelho 5866: }
1.795 www 5867:
1.938 bisitz 5868: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5869: background-color: $mail_new;
5870: }
1.795 www 5871:
1.938 bisitz 5872: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5873: background-color: $mail_new_hover;
5874: }
1.795 www 5875:
1.938 bisitz 5876: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5877: background-color: $mail_read;
5878: }
1.795 www 5879:
1.938 bisitz 5880: /*
5881: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5882: background-color: $mail_read_hover;
5883: }
1.938 bisitz 5884: */
1.795 www 5885:
1.938 bisitz 5886: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5887: background-color: $mail_replied;
5888: }
1.795 www 5889:
1.938 bisitz 5890: /*
5891: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5892: background-color: $mail_replied_hover;
5893: }
1.938 bisitz 5894: */
1.795 www 5895:
1.938 bisitz 5896: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5897: background-color: $mail_other;
5898: }
1.795 www 5899:
1.938 bisitz 5900: /*
5901: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5902: background-color: $mail_other_hover;
5903: }
1.938 bisitz 5904: */
1.494 raeburn 5905:
1.777 tempelho 5906: table.LC_data_table tr > td.LC_browser_file,
5907: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5908: background: #AAEE77;
1.389 albertel 5909: }
1.795 www 5910:
1.777 tempelho 5911: table.LC_data_table tr > td.LC_browser_file_locked,
5912: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5913: background: #FFAA99;
1.387 albertel 5914: }
1.795 www 5915:
1.777 tempelho 5916: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5917: background: #888888;
1.779 bisitz 5918: }
1.795 www 5919:
1.777 tempelho 5920: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5921: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5922: background: #F8F866;
1.777 tempelho 5923: }
1.795 www 5924:
1.696 bisitz 5925: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5926: background: #E0E8FF;
1.387 albertel 5927: }
1.696 bisitz 5928:
1.707 bisitz 5929: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5930: /* background: #77FF77; */
1.707 bisitz 5931: }
1.795 www 5932:
1.707 bisitz 5933: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5934: border-right: 8px solid #FFFF77;
1.707 bisitz 5935: }
1.795 www 5936:
1.707 bisitz 5937: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5938: border-right: 8px solid #FFAA77;
1.707 bisitz 5939: }
1.795 www 5940:
1.707 bisitz 5941: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5942: border-right: 8px solid #FF7777;
1.707 bisitz 5943: }
1.795 www 5944:
1.707 bisitz 5945: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5946: border-right: 8px solid #AAFF77;
1.707 bisitz 5947: }
1.795 www 5948:
1.707 bisitz 5949: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5950: border-right: 8px solid #11CC55;
1.707 bisitz 5951: }
5952:
1.388 albertel 5953: span.LC_current_location {
1.701 harmsja 5954: font-size:larger;
1.388 albertel 5955: background: $pgbg;
5956: }
1.387 albertel 5957:
1.1029 www 5958: span.LC_current_nav_location {
5959: font-weight:bold;
5960: background: $sidebg;
5961: }
5962:
1.395 albertel 5963: span.LC_parm_menu_item {
5964: font-size: larger;
5965: }
1.795 www 5966:
1.395 albertel 5967: span.LC_parm_scope_all {
5968: color: red;
5969: }
1.795 www 5970:
1.395 albertel 5971: span.LC_parm_scope_folder {
5972: color: green;
5973: }
1.795 www 5974:
1.395 albertel 5975: span.LC_parm_scope_resource {
5976: color: orange;
5977: }
1.795 www 5978:
1.395 albertel 5979: span.LC_parm_part {
5980: color: blue;
5981: }
1.795 www 5982:
1.911 bisitz 5983: span.LC_parm_folder,
5984: span.LC_parm_symb {
1.395 albertel 5985: font-size: x-small;
5986: font-family: $mono;
5987: color: #AAAAAA;
5988: }
5989:
1.977 bisitz 5990: ul.LC_parm_parmlist li {
5991: display: inline-block;
5992: padding: 0.3em 0.8em;
5993: vertical-align: top;
5994: width: 150px;
5995: border-top:1px solid $lg_border_color;
5996: }
5997:
1.795 www 5998: td.LC_parm_overview_level_menu,
5999: td.LC_parm_overview_map_menu,
6000: td.LC_parm_overview_parm_selectors,
6001: td.LC_parm_overview_restrictions {
1.396 albertel 6002: border: 1px solid black;
6003: border-collapse: collapse;
6004: }
1.795 www 6005:
1.396 albertel 6006: table.LC_parm_overview_restrictions td {
6007: border-width: 1px 4px 1px 4px;
6008: border-style: solid;
6009: border-color: $pgbg;
6010: text-align: center;
6011: }
1.795 www 6012:
1.396 albertel 6013: table.LC_parm_overview_restrictions th {
6014: background: $tabbg;
6015: border-width: 1px 4px 1px 4px;
6016: border-style: solid;
6017: border-color: $pgbg;
6018: }
1.795 www 6019:
1.398 albertel 6020: table#LC_helpmenu {
1.803 bisitz 6021: border: none;
1.398 albertel 6022: height: 55px;
1.803 bisitz 6023: border-spacing: 0;
1.398 albertel 6024: }
6025:
6026: table#LC_helpmenu fieldset legend {
6027: font-size: larger;
6028: }
1.795 www 6029:
1.397 albertel 6030: table#LC_helpmenu_links {
6031: width: 100%;
6032: border: 1px solid black;
6033: background: $pgbg;
1.803 bisitz 6034: padding: 0;
1.397 albertel 6035: border-spacing: 1px;
6036: }
1.795 www 6037:
1.397 albertel 6038: table#LC_helpmenu_links tr td {
6039: padding: 1px;
6040: background: $tabbg;
1.399 albertel 6041: text-align: center;
6042: font-weight: bold;
1.397 albertel 6043: }
1.396 albertel 6044:
1.795 www 6045: table#LC_helpmenu_links a:link,
6046: table#LC_helpmenu_links a:visited,
1.397 albertel 6047: table#LC_helpmenu_links a:active {
6048: text-decoration: none;
6049: color: $font;
6050: }
1.795 www 6051:
1.397 albertel 6052: table#LC_helpmenu_links a:hover {
6053: text-decoration: underline;
6054: color: $vlink;
6055: }
1.396 albertel 6056:
1.417 albertel 6057: .LC_chrt_popup_exists {
6058: border: 1px solid #339933;
6059: margin: -1px;
6060: }
1.795 www 6061:
1.417 albertel 6062: .LC_chrt_popup_up {
6063: border: 1px solid yellow;
6064: margin: -1px;
6065: }
1.795 www 6066:
1.417 albertel 6067: .LC_chrt_popup {
6068: border: 1px solid #8888FF;
6069: background: #CCCCFF;
6070: }
1.795 www 6071:
1.421 albertel 6072: table.LC_pick_box {
6073: border-collapse: separate;
6074: background: white;
6075: border: 1px solid black;
6076: border-spacing: 1px;
6077: }
1.795 www 6078:
1.421 albertel 6079: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6080: background: $sidebg;
1.421 albertel 6081: font-weight: bold;
1.900 bisitz 6082: text-align: left;
1.740 bisitz 6083: vertical-align: top;
1.421 albertel 6084: width: 184px;
6085: padding: 8px;
6086: }
1.795 www 6087:
1.579 raeburn 6088: table.LC_pick_box td.LC_pick_box_value {
6089: text-align: left;
6090: padding: 8px;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_pick_box_select {
6094: text-align: left;
6095: padding: 8px;
6096: }
1.795 www 6097:
1.424 albertel 6098: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6099: padding: 0;
1.421 albertel 6100: height: 1px;
6101: background: black;
6102: }
1.795 www 6103:
1.421 albertel 6104: table.LC_pick_box td.LC_pick_box_submit {
6105: text-align: right;
6106: }
1.795 www 6107:
1.579 raeburn 6108: table.LC_pick_box td.LC_evenrow_value {
6109: text-align: left;
6110: padding: 8px;
6111: background-color: $data_table_light;
6112: }
1.795 www 6113:
1.579 raeburn 6114: table.LC_pick_box td.LC_oddrow_value {
6115: text-align: left;
6116: padding: 8px;
6117: background-color: $data_table_light;
6118: }
1.795 www 6119:
1.579 raeburn 6120: span.LC_helpform_receipt_cat {
6121: font-weight: bold;
6122: }
1.795 www 6123:
1.424 albertel 6124: table.LC_group_priv_box {
6125: background: white;
6126: border: 1px solid black;
6127: border-spacing: 1px;
6128: }
1.795 www 6129:
1.424 albertel 6130: table.LC_group_priv_box td.LC_pick_box_title {
6131: background: $tabbg;
6132: font-weight: bold;
6133: text-align: right;
6134: width: 184px;
6135: }
1.795 www 6136:
1.424 albertel 6137: table.LC_group_priv_box td.LC_groups_fixed {
6138: background: $data_table_light;
6139: text-align: center;
6140: }
1.795 www 6141:
1.424 albertel 6142: table.LC_group_priv_box td.LC_groups_optional {
6143: background: $data_table_dark;
6144: text-align: center;
6145: }
1.795 www 6146:
1.424 albertel 6147: table.LC_group_priv_box td.LC_groups_functionality {
6148: background: $data_table_darker;
6149: text-align: center;
6150: font-weight: bold;
6151: }
1.795 www 6152:
1.424 albertel 6153: table.LC_group_priv td {
6154: text-align: left;
1.803 bisitz 6155: padding: 0;
1.424 albertel 6156: }
6157:
6158: .LC_navbuttons {
6159: margin: 2ex 0ex 2ex 0ex;
6160: }
1.795 www 6161:
1.423 albertel 6162: .LC_topic_bar {
6163: font-weight: bold;
6164: background: $tabbg;
1.918 wenzelju 6165: margin: 1em 0em 1em 2em;
1.805 bisitz 6166: padding: 3px;
1.918 wenzelju 6167: font-size: 1.2em;
1.423 albertel 6168: }
1.795 www 6169:
1.423 albertel 6170: .LC_topic_bar span {
1.918 wenzelju 6171: left: 0.5em;
6172: position: absolute;
1.423 albertel 6173: vertical-align: middle;
1.918 wenzelju 6174: font-size: 1.2em;
1.423 albertel 6175: }
1.795 www 6176:
1.423 albertel 6177: table.LC_course_group_status {
6178: margin: 20px;
6179: }
1.795 www 6180:
1.423 albertel 6181: table.LC_status_selector td {
6182: vertical-align: top;
6183: text-align: center;
1.424 albertel 6184: padding: 4px;
6185: }
1.795 www 6186:
1.599 albertel 6187: div.LC_feedback_link {
1.616 albertel 6188: clear: both;
1.829 kalberla 6189: background: $sidebg;
1.779 bisitz 6190: width: 100%;
1.829 kalberla 6191: padding-bottom: 10px;
6192: border: 1px $tabbg solid;
1.833 kalberla 6193: height: 22px;
6194: line-height: 22px;
6195: padding-top: 5px;
6196: }
6197:
6198: div.LC_feedback_link img {
6199: height: 22px;
1.867 kalberla 6200: vertical-align:middle;
1.829 kalberla 6201: }
6202:
1.911 bisitz 6203: div.LC_feedback_link a {
1.829 kalberla 6204: text-decoration: none;
1.489 raeburn 6205: }
1.795 www 6206:
1.867 kalberla 6207: div.LC_comblock {
1.911 bisitz 6208: display:inline;
1.867 kalberla 6209: color:$font;
6210: font-size:90%;
6211: }
6212:
6213: div.LC_feedback_link div.LC_comblock {
6214: padding-left:5px;
6215: }
6216:
6217: div.LC_feedback_link div.LC_comblock a {
6218: color:$font;
6219: }
6220:
1.489 raeburn 6221: span.LC_feedback_link {
1.858 bisitz 6222: /* background: $feedback_link_bg; */
1.599 albertel 6223: font-size: larger;
6224: }
1.795 www 6225:
1.599 albertel 6226: span.LC_message_link {
1.858 bisitz 6227: /* background: $feedback_link_bg; */
1.599 albertel 6228: font-size: larger;
6229: position: absolute;
6230: right: 1em;
1.489 raeburn 6231: }
1.421 albertel 6232:
1.515 albertel 6233: table.LC_prior_tries {
1.524 albertel 6234: border: 1px solid #000000;
6235: border-collapse: separate;
6236: border-spacing: 1px;
1.515 albertel 6237: }
1.523 albertel 6238:
1.515 albertel 6239: table.LC_prior_tries td {
1.524 albertel 6240: padding: 2px;
1.515 albertel 6241: }
1.523 albertel 6242:
6243: .LC_answer_correct {
1.795 www 6244: background: lightgreen;
6245: color: darkgreen;
6246: padding: 6px;
1.523 albertel 6247: }
1.795 www 6248:
1.523 albertel 6249: .LC_answer_charged_try {
1.797 www 6250: background: #FFAAAA;
1.795 www 6251: color: darkred;
6252: padding: 6px;
1.523 albertel 6253: }
1.795 www 6254:
1.779 bisitz 6255: .LC_answer_not_charged_try,
1.523 albertel 6256: .LC_answer_no_grade,
6257: .LC_answer_late {
1.795 www 6258: background: lightyellow;
1.523 albertel 6259: color: black;
1.795 www 6260: padding: 6px;
1.523 albertel 6261: }
1.795 www 6262:
1.523 albertel 6263: .LC_answer_previous {
1.795 www 6264: background: lightblue;
6265: color: darkblue;
6266: padding: 6px;
1.523 albertel 6267: }
1.795 www 6268:
1.779 bisitz 6269: .LC_answer_no_message {
1.777 tempelho 6270: background: #FFFFFF;
6271: color: black;
1.795 www 6272: padding: 6px;
1.779 bisitz 6273: }
1.795 www 6274:
1.779 bisitz 6275: .LC_answer_unknown {
6276: background: orange;
6277: color: black;
1.795 www 6278: padding: 6px;
1.777 tempelho 6279: }
1.795 www 6280:
1.529 albertel 6281: span.LC_prior_numerical,
6282: span.LC_prior_string,
6283: span.LC_prior_custom,
6284: span.LC_prior_reaction,
6285: span.LC_prior_math {
1.925 bisitz 6286: font-family: $mono;
1.523 albertel 6287: white-space: pre;
6288: }
6289:
1.525 albertel 6290: span.LC_prior_string {
1.925 bisitz 6291: font-family: $mono;
1.525 albertel 6292: white-space: pre;
6293: }
6294:
1.523 albertel 6295: table.LC_prior_option {
6296: width: 100%;
6297: border-collapse: collapse;
6298: }
1.795 www 6299:
1.911 bisitz 6300: table.LC_prior_rank,
1.795 www 6301: table.LC_prior_match {
1.528 albertel 6302: border-collapse: collapse;
6303: }
1.795 www 6304:
1.528 albertel 6305: table.LC_prior_option tr td,
6306: table.LC_prior_rank tr td,
6307: table.LC_prior_match tr td {
1.524 albertel 6308: border: 1px solid #000000;
1.515 albertel 6309: }
6310:
1.855 bisitz 6311: .LC_nobreak {
1.544 albertel 6312: white-space: nowrap;
1.519 raeburn 6313: }
6314:
1.576 raeburn 6315: span.LC_cusr_emph {
6316: font-style: italic;
6317: }
6318:
1.633 raeburn 6319: span.LC_cusr_subheading {
6320: font-weight: normal;
6321: font-size: 85%;
6322: }
6323:
1.861 bisitz 6324: div.LC_docs_entry_move {
1.859 bisitz 6325: border: 1px solid #BBBBBB;
1.545 albertel 6326: background: #DDDDDD;
1.861 bisitz 6327: width: 22px;
1.859 bisitz 6328: padding: 1px;
6329: margin: 0;
1.545 albertel 6330: }
6331:
1.861 bisitz 6332: table.LC_data_table tr > td.LC_docs_entry_commands,
6333: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6334: font-size: x-small;
6335: }
1.795 www 6336:
1.861 bisitz 6337: .LC_docs_entry_parameter {
6338: white-space: nowrap;
6339: }
6340:
1.544 albertel 6341: .LC_docs_copy {
1.545 albertel 6342: color: #000099;
1.544 albertel 6343: }
1.795 www 6344:
1.544 albertel 6345: .LC_docs_cut {
1.545 albertel 6346: color: #550044;
1.544 albertel 6347: }
1.795 www 6348:
1.544 albertel 6349: .LC_docs_rename {
1.545 albertel 6350: color: #009900;
1.544 albertel 6351: }
1.795 www 6352:
1.544 albertel 6353: .LC_docs_remove {
1.545 albertel 6354: color: #990000;
6355: }
6356:
1.547 albertel 6357: .LC_docs_reinit_warn,
6358: .LC_docs_ext_edit {
6359: font-size: x-small;
6360: }
6361:
1.545 albertel 6362: table.LC_docs_adddocs td,
6363: table.LC_docs_adddocs th {
6364: border: 1px solid #BBBBBB;
6365: padding: 4px;
6366: background: #DDDDDD;
1.543 albertel 6367: }
6368:
1.584 albertel 6369: table.LC_sty_begin {
6370: background: #BBFFBB;
6371: }
1.795 www 6372:
1.584 albertel 6373: table.LC_sty_end {
6374: background: #FFBBBB;
6375: }
6376:
1.589 raeburn 6377: table.LC_double_column {
1.803 bisitz 6378: border-width: 0;
1.589 raeburn 6379: border-collapse: collapse;
6380: width: 100%;
6381: padding: 2px;
6382: }
6383:
6384: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6385: top: 2px;
1.589 raeburn 6386: left: 2px;
6387: width: 47%;
6388: vertical-align: top;
6389: }
6390:
6391: table.LC_double_column tr td.LC_right_col {
6392: top: 2px;
1.779 bisitz 6393: right: 2px;
1.589 raeburn 6394: width: 47%;
6395: vertical-align: top;
6396: }
6397:
1.591 raeburn 6398: div.LC_left_float {
6399: float: left;
6400: padding-right: 5%;
1.597 albertel 6401: padding-bottom: 4px;
1.591 raeburn 6402: }
6403:
6404: div.LC_clear_float_header {
1.597 albertel 6405: padding-bottom: 2px;
1.591 raeburn 6406: }
6407:
6408: div.LC_clear_float_footer {
1.597 albertel 6409: padding-top: 10px;
1.591 raeburn 6410: clear: both;
6411: }
6412:
1.597 albertel 6413: div.LC_grade_show_user {
1.941 bisitz 6414: /* border-left: 5px solid $sidebg; */
6415: border-top: 5px solid #000000;
6416: margin: 50px 0 0 0;
1.936 bisitz 6417: padding: 15px 0 5px 10px;
1.597 albertel 6418: }
1.795 www 6419:
1.936 bisitz 6420: div.LC_grade_show_user_odd_row {
1.941 bisitz 6421: /* border-left: 5px solid #000000; */
6422: }
6423:
6424: div.LC_grade_show_user div.LC_Box {
6425: margin-right: 50px;
1.597 albertel 6426: }
6427:
6428: div.LC_grade_submissions,
6429: div.LC_grade_message_center,
1.936 bisitz 6430: div.LC_grade_info_links {
1.597 albertel 6431: margin: 5px;
6432: width: 99%;
6433: background: #FFFFFF;
6434: }
1.795 www 6435:
1.597 albertel 6436: div.LC_grade_submissions_header,
1.936 bisitz 6437: div.LC_grade_message_center_header {
1.705 tempelho 6438: font-weight: bold;
6439: font-size: large;
1.597 albertel 6440: }
1.795 www 6441:
1.597 albertel 6442: div.LC_grade_submissions_body,
1.936 bisitz 6443: div.LC_grade_message_center_body {
1.597 albertel 6444: border: 1px solid black;
6445: width: 99%;
6446: background: #FFFFFF;
6447: }
1.795 www 6448:
1.613 albertel 6449: table.LC_scantron_action {
6450: width: 100%;
6451: }
1.795 www 6452:
1.613 albertel 6453: table.LC_scantron_action tr th {
1.698 harmsja 6454: font-weight:bold;
6455: font-style:normal;
1.613 albertel 6456: }
1.795 www 6457:
1.779 bisitz 6458: .LC_edit_problem_header,
1.614 albertel 6459: div.LC_edit_problem_footer {
1.705 tempelho 6460: font-weight: normal;
6461: font-size: medium;
1.602 albertel 6462: margin: 2px;
1.1060 bisitz 6463: background-color: $sidebg;
1.600 albertel 6464: }
1.795 www 6465:
1.600 albertel 6466: div.LC_edit_problem_header,
1.602 albertel 6467: div.LC_edit_problem_header div,
1.614 albertel 6468: div.LC_edit_problem_footer,
6469: div.LC_edit_problem_footer div,
1.602 albertel 6470: div.LC_edit_problem_editxml_header,
6471: div.LC_edit_problem_editxml_header div {
1.600 albertel 6472: margin-top: 5px;
6473: }
1.795 www 6474:
1.600 albertel 6475: div.LC_edit_problem_header_title {
1.705 tempelho 6476: font-weight: bold;
6477: font-size: larger;
1.602 albertel 6478: background: $tabbg;
6479: padding: 3px;
1.1060 bisitz 6480: margin: 0 0 5px 0;
1.602 albertel 6481: }
1.795 www 6482:
1.602 albertel 6483: table.LC_edit_problem_header_title {
6484: width: 100%;
1.600 albertel 6485: background: $tabbg;
1.602 albertel 6486: }
6487:
6488: div.LC_edit_problem_discards {
6489: float: left;
6490: padding-bottom: 5px;
6491: }
1.795 www 6492:
1.602 albertel 6493: div.LC_edit_problem_saves {
6494: float: right;
6495: padding-bottom: 5px;
1.600 albertel 6496: }
1.795 www 6497:
1.1124 bisitz 6498: .LC_edit_opt {
6499: padding-left: 1em;
6500: white-space: nowrap;
6501: }
6502:
1.911 bisitz 6503: img.stift {
1.803 bisitz 6504: border-width: 0;
6505: vertical-align: middle;
1.677 riegler 6506: }
1.680 riegler 6507:
1.923 bisitz 6508: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6509: vertical-align: top;
1.777 tempelho 6510: }
1.795 www 6511:
1.716 raeburn 6512: div.LC_createcourse {
1.911 bisitz 6513: margin: 10px 10px 10px 10px;
1.716 raeburn 6514: }
6515:
1.917 raeburn 6516: .LC_dccid {
1.1130 raeburn 6517: float: right;
1.917 raeburn 6518: margin: 0.2em 0 0 0;
6519: padding: 0;
6520: font-size: 90%;
6521: display:none;
6522: }
6523:
1.897 wenzelju 6524: ol.LC_primary_menu a:hover,
1.721 harmsja 6525: ol#LC_MenuBreadcrumbs a:hover,
6526: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6527: ul#LC_secondary_menu a:hover,
1.721 harmsja 6528: .LC_FormSectionClearButton input:hover
1.795 www 6529: ul.LC_TabContent li:hover a {
1.952 onken 6530: color:$button_hover;
1.911 bisitz 6531: text-decoration:none;
1.693 droeschl 6532: }
6533:
1.779 bisitz 6534: h1 {
1.911 bisitz 6535: padding: 0;
6536: line-height:130%;
1.693 droeschl 6537: }
1.698 harmsja 6538:
1.911 bisitz 6539: h2,
6540: h3,
6541: h4,
6542: h5,
6543: h6 {
6544: margin: 5px 0 5px 0;
6545: padding: 0;
6546: line-height:130%;
1.693 droeschl 6547: }
1.795 www 6548:
6549: .LC_hcell {
1.911 bisitz 6550: padding:3px 15px 3px 15px;
6551: margin: 0;
6552: background-color:$tabbg;
6553: color:$fontmenu;
6554: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6555: }
1.795 www 6556:
1.840 bisitz 6557: .LC_Box > .LC_hcell {
1.911 bisitz 6558: margin: 0 -10px 10px -10px;
1.835 bisitz 6559: }
6560:
1.721 harmsja 6561: .LC_noBorder {
1.911 bisitz 6562: border: 0;
1.698 harmsja 6563: }
1.693 droeschl 6564:
1.721 harmsja 6565: .LC_FormSectionClearButton input {
1.911 bisitz 6566: background-color:transparent;
6567: border: none;
6568: cursor:pointer;
6569: text-decoration:underline;
1.693 droeschl 6570: }
1.763 bisitz 6571:
6572: .LC_help_open_topic {
1.911 bisitz 6573: color: #FFFFFF;
6574: background-color: #EEEEFF;
6575: margin: 1px;
6576: padding: 4px;
6577: border: 1px solid #000033;
6578: white-space: nowrap;
6579: /* vertical-align: middle; */
1.759 neumanie 6580: }
1.693 droeschl 6581:
1.911 bisitz 6582: dl,
6583: ul,
6584: div,
6585: fieldset {
6586: margin: 10px 10px 10px 0;
6587: /* overflow: hidden; */
1.693 droeschl 6588: }
1.795 www 6589:
1.838 bisitz 6590: fieldset > legend {
1.911 bisitz 6591: font-weight: bold;
6592: padding: 0 5px 0 5px;
1.838 bisitz 6593: }
6594:
1.813 bisitz 6595: #LC_nav_bar {
1.911 bisitz 6596: float: left;
1.995 raeburn 6597: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6598: margin: 0 0 2px 0;
1.807 droeschl 6599: }
6600:
1.916 droeschl 6601: #LC_realm {
6602: margin: 0.2em 0 0 0;
6603: padding: 0;
6604: font-weight: bold;
6605: text-align: center;
1.995 raeburn 6606: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6607: }
6608:
1.911 bisitz 6609: #LC_nav_bar em {
6610: font-weight: bold;
6611: font-style: normal;
1.807 droeschl 6612: }
6613:
1.897 wenzelju 6614: ol.LC_primary_menu {
1.934 droeschl 6615: margin: 0;
1.1076 raeburn 6616: padding: 0;
1.995 raeburn 6617: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6618: }
6619:
1.852 droeschl 6620: ol#LC_PathBreadcrumbs {
1.911 bisitz 6621: margin: 0;
1.693 droeschl 6622: }
6623:
1.897 wenzelju 6624: ol.LC_primary_menu li {
1.1076 raeburn 6625: color: RGB(80, 80, 80);
6626: vertical-align: middle;
6627: text-align: left;
6628: list-style: none;
6629: float: left;
6630: }
6631:
6632: ol.LC_primary_menu li a {
6633: display: block;
6634: margin: 0;
6635: padding: 0 5px 0 10px;
6636: text-decoration: none;
6637: }
6638:
6639: ol.LC_primary_menu li ul {
6640: display: none;
6641: width: 10em;
6642: background-color: $data_table_light;
6643: }
6644:
6645: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6646: display: block;
6647: position: absolute;
6648: margin: 0;
6649: padding: 0;
1.1078 raeburn 6650: z-index: 2;
1.1076 raeburn 6651: }
6652:
6653: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6654: font-size: 90%;
1.911 bisitz 6655: vertical-align: top;
1.1076 raeburn 6656: float: none;
1.1079 raeburn 6657: border-left: 1px solid black;
6658: border-right: 1px solid black;
1.1076 raeburn 6659: }
6660:
6661: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6662: background-color:$data_table_light;
1.1076 raeburn 6663: }
6664:
6665: ol.LC_primary_menu li li a:hover {
6666: color:$button_hover;
6667: background-color:$data_table_dark;
1.693 droeschl 6668: }
6669:
1.897 wenzelju 6670: ol.LC_primary_menu li img {
1.911 bisitz 6671: vertical-align: bottom;
1.934 droeschl 6672: height: 1.1em;
1.1077 raeburn 6673: margin: 0.2em 0 0 0;
1.693 droeschl 6674: }
6675:
1.897 wenzelju 6676: ol.LC_primary_menu a {
1.911 bisitz 6677: color: RGB(80, 80, 80);
6678: text-decoration: none;
1.693 droeschl 6679: }
1.795 www 6680:
1.949 droeschl 6681: ol.LC_primary_menu a.LC_new_message {
6682: font-weight:bold;
6683: color: darkred;
6684: }
6685:
1.975 raeburn 6686: ol.LC_docs_parameters {
6687: margin-left: 0;
6688: padding: 0;
6689: list-style: none;
6690: }
6691:
6692: ol.LC_docs_parameters li {
6693: margin: 0;
6694: padding-right: 20px;
6695: display: inline;
6696: }
6697:
1.976 raeburn 6698: ol.LC_docs_parameters li:before {
6699: content: "\\002022 \\0020";
6700: }
6701:
6702: li.LC_docs_parameters_title {
6703: font-weight: bold;
6704: }
6705:
6706: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6707: content: "";
6708: }
6709:
1.897 wenzelju 6710: ul#LC_secondary_menu {
1.1107 raeburn 6711: clear: right;
1.911 bisitz 6712: color: $fontmenu;
6713: background: $tabbg;
6714: list-style: none;
6715: padding: 0;
6716: margin: 0;
6717: width: 100%;
1.995 raeburn 6718: text-align: left;
1.1107 raeburn 6719: float: left;
1.808 droeschl 6720: }
6721:
1.897 wenzelju 6722: ul#LC_secondary_menu li {
1.911 bisitz 6723: font-weight: bold;
6724: line-height: 1.8em;
1.1107 raeburn 6725: border-right: 1px solid black;
6726: float: left;
6727: }
6728:
6729: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6730: background-color: $data_table_light;
6731: }
6732:
6733: ul#LC_secondary_menu li a {
1.911 bisitz 6734: padding: 0 0.8em;
1.1107 raeburn 6735: }
6736:
6737: ul#LC_secondary_menu li ul {
6738: display: none;
6739: }
6740:
6741: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6742: display: block;
6743: position: absolute;
6744: margin: 0;
6745: padding: 0;
6746: list-style:none;
6747: float: none;
6748: background-color: $data_table_light;
6749: z-index: 2;
6750: margin-left: -1px;
6751: }
6752:
6753: ul#LC_secondary_menu li ul li {
6754: font-size: 90%;
6755: vertical-align: top;
6756: border-left: 1px solid black;
1.911 bisitz 6757: border-right: 1px solid black;
1.1119 raeburn 6758: background-color: $data_table_light;
1.1107 raeburn 6759: list-style:none;
6760: float: none;
6761: }
6762:
6763: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6764: background-color: $data_table_dark;
1.807 droeschl 6765: }
6766:
1.847 tempelho 6767: ul.LC_TabContent {
1.911 bisitz 6768: display:block;
6769: background: $sidebg;
6770: border-bottom: solid 1px $lg_border_color;
6771: list-style:none;
1.1020 raeburn 6772: margin: -1px -10px 0 -10px;
1.911 bisitz 6773: padding: 0;
1.693 droeschl 6774: }
6775:
1.795 www 6776: ul.LC_TabContent li,
6777: ul.LC_TabContentBigger li {
1.911 bisitz 6778: float:left;
1.741 harmsja 6779: }
1.795 www 6780:
1.897 wenzelju 6781: ul#LC_secondary_menu li a {
1.911 bisitz 6782: color: $fontmenu;
6783: text-decoration: none;
1.693 droeschl 6784: }
1.795 www 6785:
1.721 harmsja 6786: ul.LC_TabContent {
1.952 onken 6787: min-height:20px;
1.721 harmsja 6788: }
1.795 www 6789:
6790: ul.LC_TabContent li {
1.911 bisitz 6791: vertical-align:middle;
1.959 onken 6792: padding: 0 16px 0 10px;
1.911 bisitz 6793: background-color:$tabbg;
6794: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6795: border-left: solid 1px $font;
1.721 harmsja 6796: }
1.795 www 6797:
1.847 tempelho 6798: ul.LC_TabContent .right {
1.911 bisitz 6799: float:right;
1.847 tempelho 6800: }
6801:
1.911 bisitz 6802: ul.LC_TabContent li a,
6803: ul.LC_TabContent li {
6804: color:rgb(47,47,47);
6805: text-decoration:none;
6806: font-size:95%;
6807: font-weight:bold;
1.952 onken 6808: min-height:20px;
6809: }
6810:
1.959 onken 6811: ul.LC_TabContent li a:hover,
6812: ul.LC_TabContent li a:focus {
1.952 onken 6813: color: $button_hover;
1.959 onken 6814: background:none;
6815: outline:none;
1.952 onken 6816: }
6817:
6818: ul.LC_TabContent li:hover {
6819: color: $button_hover;
6820: cursor:pointer;
1.721 harmsja 6821: }
1.795 www 6822:
1.911 bisitz 6823: ul.LC_TabContent li.active {
1.952 onken 6824: color: $font;
1.911 bisitz 6825: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6826: border-bottom:solid 1px #FFFFFF;
6827: cursor: default;
1.744 ehlerst 6828: }
1.795 www 6829:
1.959 onken 6830: ul.LC_TabContent li.active a {
6831: color:$font;
6832: background:#FFFFFF;
6833: outline: none;
6834: }
1.1047 raeburn 6835:
6836: ul.LC_TabContent li.goback {
6837: float: left;
6838: border-left: none;
6839: }
6840:
1.870 tempelho 6841: #maincoursedoc {
1.911 bisitz 6842: clear:both;
1.870 tempelho 6843: }
6844:
6845: ul.LC_TabContentBigger {
1.911 bisitz 6846: display:block;
6847: list-style:none;
6848: padding: 0;
1.870 tempelho 6849: }
6850:
1.795 www 6851: ul.LC_TabContentBigger li {
1.911 bisitz 6852: vertical-align:bottom;
6853: height: 30px;
6854: font-size:110%;
6855: font-weight:bold;
6856: color: #737373;
1.841 tempelho 6857: }
6858:
1.957 onken 6859: ul.LC_TabContentBigger li.active {
6860: position: relative;
6861: top: 1px;
6862: }
6863:
1.870 tempelho 6864: ul.LC_TabContentBigger li a {
1.911 bisitz 6865: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6866: height: 30px;
6867: line-height: 30px;
6868: text-align: center;
6869: display: block;
6870: text-decoration: none;
1.958 onken 6871: outline: none;
1.741 harmsja 6872: }
1.795 www 6873:
1.870 tempelho 6874: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6875: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6876: color:$font;
1.744 ehlerst 6877: }
1.795 www 6878:
1.870 tempelho 6879: ul.LC_TabContentBigger li b {
1.911 bisitz 6880: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6881: display: block;
6882: float: left;
6883: padding: 0 30px;
1.957 onken 6884: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6885: }
6886:
1.956 onken 6887: ul.LC_TabContentBigger li:hover b {
6888: color:$button_hover;
6889: }
6890:
1.870 tempelho 6891: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6892: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6893: color:$font;
1.957 onken 6894: border: 0;
1.741 harmsja 6895: }
1.693 droeschl 6896:
1.870 tempelho 6897:
1.862 bisitz 6898: ul.LC_CourseBreadcrumbs {
6899: background: $sidebg;
1.1020 raeburn 6900: height: 2em;
1.862 bisitz 6901: padding-left: 10px;
1.1020 raeburn 6902: margin: 0;
1.862 bisitz 6903: list-style-position: inside;
6904: }
6905:
1.911 bisitz 6906: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6907: ol#LC_PathBreadcrumbs {
1.911 bisitz 6908: padding-left: 10px;
6909: margin: 0;
1.933 droeschl 6910: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6911: }
6912:
1.911 bisitz 6913: ol#LC_MenuBreadcrumbs li,
6914: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6915: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6916: display: inline;
1.933 droeschl 6917: white-space: normal;
1.693 droeschl 6918: }
6919:
1.823 bisitz 6920: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6921: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6922: text-decoration: none;
6923: font-size:90%;
1.693 droeschl 6924: }
1.795 www 6925:
1.969 droeschl 6926: ol#LC_MenuBreadcrumbs h1 {
6927: display: inline;
6928: font-size: 90%;
6929: line-height: 2.5em;
6930: margin: 0;
6931: padding: 0;
6932: }
6933:
1.795 www 6934: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6935: text-decoration:none;
6936: font-size:100%;
6937: font-weight:bold;
1.693 droeschl 6938: }
1.795 www 6939:
1.840 bisitz 6940: .LC_Box {
1.911 bisitz 6941: border: solid 1px $lg_border_color;
6942: padding: 0 10px 10px 10px;
1.746 neumanie 6943: }
1.795 www 6944:
1.1020 raeburn 6945: .LC_DocsBox {
6946: border: solid 1px $lg_border_color;
6947: padding: 0 0 10px 10px;
6948: }
6949:
1.795 www 6950: .LC_AboutMe_Image {
1.911 bisitz 6951: float:left;
6952: margin-right:10px;
1.747 neumanie 6953: }
1.795 www 6954:
6955: .LC_Clear_AboutMe_Image {
1.911 bisitz 6956: clear:left;
1.747 neumanie 6957: }
1.795 www 6958:
1.721 harmsja 6959: dl.LC_ListStyleClean dt {
1.911 bisitz 6960: padding-right: 5px;
6961: display: table-header-group;
1.693 droeschl 6962: }
6963:
1.721 harmsja 6964: dl.LC_ListStyleClean dd {
1.911 bisitz 6965: display: table-row;
1.693 droeschl 6966: }
6967:
1.721 harmsja 6968: .LC_ListStyleClean,
6969: .LC_ListStyleSimple,
6970: .LC_ListStyleNormal,
1.795 www 6971: .LC_ListStyleSpecial {
1.911 bisitz 6972: /* display:block; */
6973: list-style-position: inside;
6974: list-style-type: none;
6975: overflow: hidden;
6976: padding: 0;
1.693 droeschl 6977: }
6978:
1.721 harmsja 6979: .LC_ListStyleSimple li,
6980: .LC_ListStyleSimple dd,
6981: .LC_ListStyleNormal li,
6982: .LC_ListStyleNormal dd,
6983: .LC_ListStyleSpecial li,
1.795 www 6984: .LC_ListStyleSpecial dd {
1.911 bisitz 6985: margin: 0;
6986: padding: 5px 5px 5px 10px;
6987: clear: both;
1.693 droeschl 6988: }
6989:
1.721 harmsja 6990: .LC_ListStyleClean li,
6991: .LC_ListStyleClean dd {
1.911 bisitz 6992: padding-top: 0;
6993: padding-bottom: 0;
1.693 droeschl 6994: }
6995:
1.721 harmsja 6996: .LC_ListStyleSimple dd,
1.795 www 6997: .LC_ListStyleSimple li {
1.911 bisitz 6998: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6999: }
7000:
1.721 harmsja 7001: .LC_ListStyleSpecial li,
7002: .LC_ListStyleSpecial dd {
1.911 bisitz 7003: list-style-type: none;
7004: background-color: RGB(220, 220, 220);
7005: margin-bottom: 4px;
1.693 droeschl 7006: }
7007:
1.721 harmsja 7008: table.LC_SimpleTable {
1.911 bisitz 7009: margin:5px;
7010: border:solid 1px $lg_border_color;
1.795 www 7011: }
1.693 droeschl 7012:
1.721 harmsja 7013: table.LC_SimpleTable tr {
1.911 bisitz 7014: padding: 0;
7015: border:solid 1px $lg_border_color;
1.693 droeschl 7016: }
1.795 www 7017:
7018: table.LC_SimpleTable thead {
1.911 bisitz 7019: background:rgb(220,220,220);
1.693 droeschl 7020: }
7021:
1.721 harmsja 7022: div.LC_columnSection {
1.911 bisitz 7023: display: block;
7024: clear: both;
7025: overflow: hidden;
7026: margin: 0;
1.693 droeschl 7027: }
7028:
1.721 harmsja 7029: div.LC_columnSection>* {
1.911 bisitz 7030: float: left;
7031: margin: 10px 20px 10px 0;
7032: overflow:hidden;
1.693 droeschl 7033: }
1.721 harmsja 7034:
1.795 www 7035: table em {
1.911 bisitz 7036: font-weight: bold;
7037: font-style: normal;
1.748 schulted 7038: }
1.795 www 7039:
1.779 bisitz 7040: table.LC_tableBrowseRes,
1.795 www 7041: table.LC_tableOfContent {
1.911 bisitz 7042: border:none;
7043: border-spacing: 1px;
7044: padding: 3px;
7045: background-color: #FFFFFF;
7046: font-size: 90%;
1.753 droeschl 7047: }
1.789 droeschl 7048:
1.911 bisitz 7049: table.LC_tableOfContent {
7050: border-collapse: collapse;
1.789 droeschl 7051: }
7052:
1.771 droeschl 7053: table.LC_tableBrowseRes a,
1.768 schulted 7054: table.LC_tableOfContent a {
1.911 bisitz 7055: background-color: transparent;
7056: text-decoration: none;
1.753 droeschl 7057: }
7058:
1.795 www 7059: table.LC_tableOfContent img {
1.911 bisitz 7060: border: none;
7061: height: 1.3em;
7062: vertical-align: text-bottom;
7063: margin-right: 0.3em;
1.753 droeschl 7064: }
1.757 schulted 7065:
1.795 www 7066: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7067: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7068: }
7069:
1.795 www 7070: a#LC_content_toolbar_everything {
1.911 bisitz 7071: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7072: }
7073:
1.795 www 7074: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7075: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7076: }
7077:
1.795 www 7078: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7079: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7080: }
7081:
1.795 www 7082: a#LC_content_toolbar_changefolder {
1.911 bisitz 7083: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7084: }
7085:
1.795 www 7086: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7087: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7088: }
7089:
1.1043 raeburn 7090: a#LC_content_toolbar_edittoplevel {
7091: background-image:url(/res/adm/pages/edittoplevel.gif);
7092: }
7093:
1.795 www 7094: ul#LC_toolbar li a:hover {
1.911 bisitz 7095: background-position: bottom center;
1.757 schulted 7096: }
7097:
1.795 www 7098: ul#LC_toolbar {
1.911 bisitz 7099: padding: 0;
7100: margin: 2px;
7101: list-style:none;
7102: position:relative;
7103: background-color:white;
1.1082 raeburn 7104: overflow: auto;
1.757 schulted 7105: }
7106:
1.795 www 7107: ul#LC_toolbar li {
1.911 bisitz 7108: border:1px solid white;
7109: padding: 0;
7110: margin: 0;
7111: float: left;
7112: display:inline;
7113: vertical-align:middle;
1.1082 raeburn 7114: white-space: nowrap;
1.911 bisitz 7115: }
1.757 schulted 7116:
1.783 amueller 7117:
1.795 www 7118: a.LC_toolbarItem {
1.911 bisitz 7119: display:block;
7120: padding: 0;
7121: margin: 0;
7122: height: 32px;
7123: width: 32px;
7124: color:white;
7125: border: none;
7126: background-repeat:no-repeat;
7127: background-color:transparent;
1.757 schulted 7128: }
7129:
1.915 droeschl 7130: ul.LC_funclist {
7131: margin: 0;
7132: padding: 0.5em 1em 0.5em 0;
7133: }
7134:
1.933 droeschl 7135: ul.LC_funclist > li:first-child {
7136: font-weight:bold;
7137: margin-left:0.8em;
7138: }
7139:
1.915 droeschl 7140: ul.LC_funclist + ul.LC_funclist {
7141: /*
7142: left border as a seperator if we have more than
7143: one list
7144: */
7145: border-left: 1px solid $sidebg;
7146: /*
7147: this hides the left border behind the border of the
7148: outer box if element is wrapped to the next 'line'
7149: */
7150: margin-left: -1px;
7151: }
7152:
1.843 bisitz 7153: ul.LC_funclist li {
1.915 droeschl 7154: display: inline;
1.782 bisitz 7155: white-space: nowrap;
1.915 droeschl 7156: margin: 0 0 0 25px;
7157: line-height: 150%;
1.782 bisitz 7158: }
7159:
1.974 wenzelju 7160: .LC_hidden {
7161: display: none;
7162: }
7163:
1.1030 www 7164: .LCmodal-overlay {
7165: position:fixed;
7166: top:0;
7167: right:0;
7168: bottom:0;
7169: left:0;
7170: height:100%;
7171: width:100%;
7172: margin:0;
7173: padding:0;
7174: background:#999;
7175: opacity:.75;
7176: filter: alpha(opacity=75);
7177: -moz-opacity: 0.75;
7178: z-index:101;
7179: }
7180:
7181: * html .LCmodal-overlay {
7182: position: absolute;
7183: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7184: }
7185:
7186: .LCmodal-window {
7187: position:fixed;
7188: top:50%;
7189: left:50%;
7190: margin:0;
7191: padding:0;
7192: z-index:102;
7193: }
7194:
7195: * html .LCmodal-window {
7196: position:absolute;
7197: }
7198:
7199: .LCclose-window {
7200: position:absolute;
7201: width:32px;
7202: height:32px;
7203: right:8px;
7204: top:8px;
7205: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7206: text-indent:-99999px;
7207: overflow:hidden;
7208: cursor:pointer;
7209: }
7210:
1.1100 raeburn 7211: /*
7212: styles used by TTH when "Default set of options to pass to tth/m
7213: when converting TeX" in course settings has been set
7214:
7215: option passed: -t
7216:
7217: */
7218:
7219: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7220: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7221: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7222: td div.norm {line-height:normal;}
7223:
7224: /*
7225: option passed -y3
7226: */
7227:
7228: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7229: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7230: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7231:
1.343 albertel 7232: END
7233: }
7234:
1.306 albertel 7235: =pod
7236:
7237: =item * &headtag()
7238:
7239: Returns a uniform footer for LON-CAPA web pages.
7240:
1.307 albertel 7241: Inputs: $title - optional title for the head
7242: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7243: $args - optional arguments
1.319 albertel 7244: force_register - if is true call registerurl so the remote is
7245: informed
1.415 albertel 7246: redirect -> array ref of
7247: 1- seconds before redirect occurs
7248: 2- url to redirect to
7249: 3- whether the side effect should occur
1.315 albertel 7250: (side effect of setting
7251: $env{'internal.head.redirect'} to the url
7252: redirected too)
1.352 albertel 7253: domain -> force to color decorate a page for a specific
7254: domain
7255: function -> force usage of a specific rolish color scheme
7256: bgcolor -> override the default page bgcolor
1.460 albertel 7257: no_auto_mt_title
7258: -> prevent &mt()ing the title arg
1.464 albertel 7259:
1.306 albertel 7260: =cut
7261:
7262: sub headtag {
1.313 albertel 7263: my ($title,$head_extra,$args) = @_;
1.306 albertel 7264:
1.363 albertel 7265: my $function = $args->{'function'} || &get_users_function();
7266: my $domain = $args->{'domain'} || &determinedomain();
7267: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7268: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7269: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7270: #time(),
1.418 albertel 7271: $env{'environment.color.timestamp'},
1.363 albertel 7272: $function,$domain,$bgcolor);
7273:
1.369 www 7274: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7275:
1.308 albertel 7276: my $result =
7277: '<head>'.
1.461 albertel 7278: &font_settings();
1.319 albertel 7279:
1.1064 raeburn 7280: my $inhibitprint = &print_suppression();
7281:
1.461 albertel 7282: if (!$args->{'frameset'}) {
7283: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7284: }
1.962 droeschl 7285: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7286: $result .= Apache::lonxml::display_title();
1.319 albertel 7287: }
1.436 albertel 7288: if (!$args->{'no_nav_bar'}
7289: && !$args->{'only_body'}
7290: && !$args->{'frameset'}) {
7291: $result .= &help_menu_js();
1.1032 www 7292: $result.=&modal_window();
1.1038 www 7293: $result.=&togglebox_script();
1.1034 www 7294: $result.=&wishlist_window();
1.1041 www 7295: $result.=&LCprogressbarUpdate_script();
1.1034 www 7296: } else {
7297: if ($args->{'add_modal'}) {
7298: $result.=&modal_window();
7299: }
7300: if ($args->{'add_wishlist'}) {
7301: $result.=&wishlist_window();
7302: }
1.1038 www 7303: if ($args->{'add_togglebox'}) {
7304: $result.=&togglebox_script();
7305: }
1.1041 www 7306: if ($args->{'add_progressbar'}) {
7307: $result.=&LCprogressbarUpdate_script();
7308: }
1.436 albertel 7309: }
1.314 albertel 7310: if (ref($args->{'redirect'})) {
1.414 albertel 7311: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7312: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7313: if (!$inhibit_continue) {
7314: $env{'internal.head.redirect'} = $url;
7315: }
1.313 albertel 7316: $result.=<<ADDMETA
7317: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7318: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7319: ADDMETA
7320: }
1.306 albertel 7321: if (!defined($title)) {
7322: $title = 'The LearningOnline Network with CAPA';
7323: }
1.460 albertel 7324: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7325: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7326: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7327: .$inhibitprint
1.414 albertel 7328: .$head_extra;
1.1137 raeburn 7329: if ($env{'browser.mobile'}) {
7330: $result .= '
7331: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7332: <meta name="apple-mobile-web-app-capable" content="yes" />';
7333: }
1.962 droeschl 7334: return $result.'</head>';
1.306 albertel 7335: }
7336:
7337: =pod
7338:
1.340 albertel 7339: =item * &font_settings()
7340:
7341: Returns neccessary <meta> to set the proper encoding
7342:
7343: Inputs: none
7344:
7345: =cut
7346:
7347: sub font_settings {
7348: my $headerstring='';
1.647 www 7349: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7350: $headerstring.=
7351: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7352: }
7353: return $headerstring;
7354: }
7355:
1.341 albertel 7356: =pod
7357:
1.1064 raeburn 7358: =item * &print_suppression()
7359:
7360: In course context returns css which causes the body to be blank when media="print",
7361: if printout generation is unavailable for the current resource.
7362:
7363: This could be because:
7364:
7365: (a) printstartdate is in the future
7366:
7367: (b) printenddate is in the past
7368:
7369: (c) there is an active exam block with "printout"
7370: functionality blocked
7371:
7372: Users with pav, pfo or evb privileges are exempt.
7373:
7374: Inputs: none
7375:
7376: =cut
7377:
7378:
7379: sub print_suppression {
7380: my $noprint;
7381: if ($env{'request.course.id'}) {
7382: my $scope = $env{'request.course.id'};
7383: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7384: (&Apache::lonnet::allowed('pfo',$scope))) {
7385: return;
7386: }
7387: if ($env{'request.course.sec'} ne '') {
7388: $scope .= "/$env{'request.course.sec'}";
7389: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7390: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7391: return;
1.1064 raeburn 7392: }
7393: }
7394: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7395: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7396: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7397: if ($blocked) {
7398: my $checkrole = "cm./$cdom/$cnum";
7399: if ($env{'request.course.sec'} ne '') {
7400: $checkrole .= "/$env{'request.course.sec'}";
7401: }
7402: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7403: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7404: $noprint = 1;
7405: }
7406: }
7407: unless ($noprint) {
7408: my $symb = &Apache::lonnet::symbread();
7409: if ($symb ne '') {
7410: my $navmap = Apache::lonnavmaps::navmap->new();
7411: if (ref($navmap)) {
7412: my $res = $navmap->getBySymb($symb);
7413: if (ref($res)) {
7414: if (!$res->resprintable()) {
7415: $noprint = 1;
7416: }
7417: }
7418: }
7419: }
7420: }
7421: if ($noprint) {
7422: return <<"ENDSTYLE";
7423: <style type="text/css" media="print">
7424: body { display:none }
7425: </style>
7426: ENDSTYLE
7427: }
7428: }
7429: return;
7430: }
7431:
7432: =pod
7433:
1.341 albertel 7434: =item * &xml_begin()
7435:
7436: Returns the needed doctype and <html>
7437:
7438: Inputs: none
7439:
7440: =cut
7441:
7442: sub xml_begin {
7443: my $output='';
7444:
7445: if ($env{'browser.mathml'}) {
7446: $output='<?xml version="1.0"?>'
7447: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7448: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7449:
7450: # .'<!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">] >'
7451: .'<!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">'
7452: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7453: .'xmlns="http://www.w3.org/1999/xhtml">';
7454: } else {
1.849 bisitz 7455: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7456: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7457: }
7458: return $output;
7459: }
1.340 albertel 7460:
7461: =pod
7462:
1.306 albertel 7463: =item * &start_page()
7464:
7465: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7466:
1.648 raeburn 7467: Inputs:
7468:
7469: =over 4
7470:
7471: $title - optional title for the page
7472:
7473: $head_extra - optional extra HTML to incude inside the <head>
7474:
7475: $args - additional optional args supported are:
7476:
7477: =over 8
7478:
7479: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7480: arg on
1.814 bisitz 7481: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7482: add_entries -> additional attributes to add to the <body>
7483: domain -> force to color decorate a page for a
1.317 albertel 7484: specific domain
1.648 raeburn 7485: function -> force usage of a specific rolish color
1.317 albertel 7486: scheme
1.648 raeburn 7487: redirect -> see &headtag()
7488: bgcolor -> override the default page bg color
7489: js_ready -> return a string ready for being used in
1.317 albertel 7490: a javascript writeln
1.648 raeburn 7491: html_encode -> return a string ready for being used in
1.320 albertel 7492: a html attribute
1.648 raeburn 7493: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7494: $forcereg arg
1.648 raeburn 7495: frameset -> if true will start with a <frameset>
1.330 albertel 7496: rather than <body>
1.648 raeburn 7497: skip_phases -> hash ref of
1.338 albertel 7498: head -> skip the <html><head> generation
7499: body -> skip all <body> generation
1.648 raeburn 7500: no_auto_mt_title -> prevent &mt()ing the title arg
7501: inherit_jsmath -> when creating popup window in a page,
7502: should it have jsmath forced on by the
7503: current page
1.867 kalberla 7504: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7505: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7506: group -> includes the current group, if page is for a
7507: specific group
1.361 albertel 7508:
1.648 raeburn 7509: =back
1.460 albertel 7510:
1.648 raeburn 7511: =back
1.562 albertel 7512:
1.306 albertel 7513: =cut
7514:
7515: sub start_page {
1.309 albertel 7516: my ($title,$head_extra,$args) = @_;
1.318 albertel 7517: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7518:
1.315 albertel 7519: $env{'internal.start_page'}++;
1.1096 raeburn 7520: my ($result,@advtools);
1.964 droeschl 7521:
1.338 albertel 7522: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7523: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7524: }
7525:
7526: if (! exists($args->{'skip_phases'}{'body'}) ) {
7527: if ($args->{'frameset'}) {
7528: my $attr_string = &make_attr_string($args->{'force_register'},
7529: $args->{'add_entries'});
7530: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7531: } else {
7532: $result .=
7533: &bodytag($title,
7534: $args->{'function'}, $args->{'add_entries'},
7535: $args->{'only_body'}, $args->{'domain'},
7536: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7537: $args->{'bgcolor'}, $args,
7538: \@advtools);
1.831 bisitz 7539: }
1.330 albertel 7540: }
1.338 albertel 7541:
1.315 albertel 7542: if ($args->{'js_ready'}) {
1.713 kaisler 7543: $result = &js_ready($result);
1.315 albertel 7544: }
1.320 albertel 7545: if ($args->{'html_encode'}) {
1.713 kaisler 7546: $result = &html_encode($result);
7547: }
7548:
1.813 bisitz 7549: # Preparation for new and consistent functionlist at top of screen
7550: # if ($args->{'functionlist'}) {
7551: # $result .= &build_functionlist();
7552: #}
7553:
1.964 droeschl 7554: # Don't add anything more if only_body wanted or in const space
7555: return $result if $args->{'only_body'}
7556: || $env{'request.state'} eq 'construct';
1.813 bisitz 7557:
7558: #Breadcrumbs
1.758 kaisler 7559: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7560: &Apache::lonhtmlcommon::clear_breadcrumbs();
7561: #if any br links exists, add them to the breadcrumbs
7562: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7563: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7564: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7565: }
7566: }
1.1096 raeburn 7567: # if @advtools array contains items add then to the breadcrumbs
7568: if (@advtools > 0) {
7569: &Apache::lonmenu::advtools_crumbs(@advtools);
7570: }
1.758 kaisler 7571:
7572: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7573: if(exists($args->{'bread_crumbs_component'})){
7574: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7575: }else{
7576: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7577: }
1.320 albertel 7578: }
1.315 albertel 7579: return $result;
1.306 albertel 7580: }
7581:
7582: sub end_page {
1.315 albertel 7583: my ($args) = @_;
7584: $env{'internal.end_page'}++;
1.330 albertel 7585: my $result;
1.335 albertel 7586: if ($args->{'discussion'}) {
7587: my ($target,$parser);
7588: if (ref($args->{'discussion'})) {
7589: ($target,$parser) =($args->{'discussion'}{'target'},
7590: $args->{'discussion'}{'parser'});
7591: }
7592: $result .= &Apache::lonxml::xmlend($target,$parser);
7593: }
1.330 albertel 7594: if ($args->{'frameset'}) {
7595: $result .= '</frameset>';
7596: } else {
1.635 raeburn 7597: $result .= &endbodytag($args);
1.330 albertel 7598: }
1.1080 raeburn 7599: unless ($args->{'notbody'}) {
7600: $result .= "\n</html>";
7601: }
1.330 albertel 7602:
1.315 albertel 7603: if ($args->{'js_ready'}) {
1.317 albertel 7604: $result = &js_ready($result);
1.315 albertel 7605: }
1.335 albertel 7606:
1.320 albertel 7607: if ($args->{'html_encode'}) {
7608: $result = &html_encode($result);
7609: }
1.335 albertel 7610:
1.315 albertel 7611: return $result;
7612: }
7613:
1.1034 www 7614: sub wishlist_window {
7615: return(<<'ENDWISHLIST');
1.1046 raeburn 7616: <script type="text/javascript">
1.1034 www 7617: // <![CDATA[
7618: // <!-- BEGIN LON-CAPA Internal
7619: function set_wishlistlink(title, path) {
7620: if (!title) {
7621: title = document.title;
7622: title = title.replace(/^LON-CAPA /,'');
7623: }
7624: if (!path) {
7625: path = location.pathname;
7626: }
7627: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7628: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7629: }
7630: // END LON-CAPA Internal -->
7631: // ]]>
7632: </script>
7633: ENDWISHLIST
7634: }
7635:
1.1030 www 7636: sub modal_window {
7637: return(<<'ENDMODAL');
1.1046 raeburn 7638: <script type="text/javascript">
1.1030 www 7639: // <![CDATA[
7640: // <!-- BEGIN LON-CAPA Internal
7641: var modalWindow = {
7642: parent:"body",
7643: windowId:null,
7644: content:null,
7645: width:null,
7646: height:null,
7647: close:function()
7648: {
7649: $(".LCmodal-window").remove();
7650: $(".LCmodal-overlay").remove();
7651: },
7652: open:function()
7653: {
7654: var modal = "";
7655: modal += "<div class=\"LCmodal-overlay\"></div>";
7656: 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;\">";
7657: modal += this.content;
7658: modal += "</div>";
7659:
7660: $(this.parent).append(modal);
7661:
7662: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7663: $(".LCclose-window").click(function(){modalWindow.close();});
7664: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7665: }
7666: };
1.1140 raeburn 7667: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7668: {
7669: modalWindow.windowId = "myModal";
7670: modalWindow.width = width;
7671: modalWindow.height = height;
1.1140 raeburn 7672: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7673: modalWindow.open();
7674: };
7675: // END LON-CAPA Internal -->
7676: // ]]>
7677: </script>
7678: ENDMODAL
7679: }
7680:
7681: sub modal_link {
1.1140 raeburn 7682: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7683: unless ($width) { $width=480; }
7684: unless ($height) { $height=400; }
1.1031 www 7685: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 7686: unless ($transparency) { $transparency='true'; }
7687:
1.1074 raeburn 7688: my $target_attr;
7689: if (defined($target)) {
7690: $target_attr = 'target="'.$target.'"';
7691: }
7692: return <<"ENDLINK";
1.1140 raeburn 7693: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7694: $linktext</a>
7695: ENDLINK
1.1030 www 7696: }
7697:
1.1032 www 7698: sub modal_adhoc_script {
7699: my ($funcname,$width,$height,$content)=@_;
7700: return (<<ENDADHOC);
1.1046 raeburn 7701: <script type="text/javascript">
1.1032 www 7702: // <![CDATA[
7703: var $funcname = function()
7704: {
7705: modalWindow.windowId = "myModal";
7706: modalWindow.width = $width;
7707: modalWindow.height = $height;
7708: modalWindow.content = '$content';
7709: modalWindow.open();
7710: };
7711: // ]]>
7712: </script>
7713: ENDADHOC
7714: }
7715:
1.1041 www 7716: sub modal_adhoc_inner {
7717: my ($funcname,$width,$height,$content)=@_;
7718: my $innerwidth=$width-20;
7719: $content=&js_ready(
1.1140 raeburn 7720: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
7721: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7722: $content.
1.1041 www 7723: &end_scrollbox().
1.1140 raeburn 7724: &end_page()
1.1041 www 7725: );
7726: return &modal_adhoc_script($funcname,$width,$height,$content);
7727: }
7728:
7729: sub modal_adhoc_window {
7730: my ($funcname,$width,$height,$content,$linktext)=@_;
7731: return &modal_adhoc_inner($funcname,$width,$height,$content).
7732: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7733: }
7734:
7735: sub modal_adhoc_launch {
7736: my ($funcname,$width,$height,$content)=@_;
7737: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7738: <script type="text/javascript">
7739: // <![CDATA[
7740: $funcname();
7741: // ]]>
7742: </script>
7743: ENDLAUNCH
7744: }
7745:
7746: sub modal_adhoc_close {
7747: return (<<ENDCLOSE);
7748: <script type="text/javascript">
7749: // <![CDATA[
7750: modalWindow.close();
7751: // ]]>
7752: </script>
7753: ENDCLOSE
7754: }
7755:
1.1038 www 7756: sub togglebox_script {
7757: return(<<ENDTOGGLE);
7758: <script type="text/javascript">
7759: // <![CDATA[
7760: function LCtoggleDisplay(id,hidetext,showtext) {
7761: link = document.getElementById(id + "link").childNodes[0];
7762: with (document.getElementById(id).style) {
7763: if (display == "none" ) {
7764: display = "inline";
7765: link.nodeValue = hidetext;
7766: } else {
7767: display = "none";
7768: link.nodeValue = showtext;
7769: }
7770: }
7771: }
7772: // ]]>
7773: </script>
7774: ENDTOGGLE
7775: }
7776:
1.1039 www 7777: sub start_togglebox {
7778: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7779: unless ($heading) { $heading=''; } else { $heading.=' '; }
7780: unless ($showtext) { $showtext=&mt('show'); }
7781: unless ($hidetext) { $hidetext=&mt('hide'); }
7782: unless ($headerbg) { $headerbg='#FFFFFF'; }
7783: return &start_data_table().
7784: &start_data_table_header_row().
7785: '<td bgcolor="'.$headerbg.'">'.$heading.
7786: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7787: $showtext.'\')">'.$showtext.'</a>]</td>'.
7788: &end_data_table_header_row().
7789: '<tr id="'.$id.'" style="display:none""><td>';
7790: }
7791:
7792: sub end_togglebox {
7793: return '</td></tr>'.&end_data_table();
7794: }
7795:
1.1041 www 7796: sub LCprogressbar_script {
1.1045 www 7797: my ($id)=@_;
1.1041 www 7798: return(<<ENDPROGRESS);
7799: <script type="text/javascript">
7800: // <![CDATA[
1.1045 www 7801: \$('#progressbar$id').progressbar({
1.1041 www 7802: value: 0,
7803: change: function(event, ui) {
7804: var newVal = \$(this).progressbar('option', 'value');
7805: \$('.pblabel', this).text(LCprogressTxt);
7806: }
7807: });
7808: // ]]>
7809: </script>
7810: ENDPROGRESS
7811: }
7812:
7813: sub LCprogressbarUpdate_script {
7814: return(<<ENDPROGRESSUPDATE);
7815: <style type="text/css">
7816: .ui-progressbar { position:relative; }
7817: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7818: </style>
7819: <script type="text/javascript">
7820: // <![CDATA[
1.1045 www 7821: var LCprogressTxt='---';
7822:
7823: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7824: LCprogressTxt=progresstext;
1.1045 www 7825: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7826: }
7827: // ]]>
7828: </script>
7829: ENDPROGRESSUPDATE
7830: }
7831:
1.1042 www 7832: my $LClastpercent;
1.1045 www 7833: my $LCidcnt;
7834: my $LCcurrentid;
1.1042 www 7835:
1.1041 www 7836: sub LCprogressbar {
1.1042 www 7837: my ($r)=(@_);
7838: $LClastpercent=0;
1.1045 www 7839: $LCidcnt++;
7840: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7841: my $starting=&mt('Starting');
7842: my $content=(<<ENDPROGBAR);
1.1045 www 7843: <div id="progressbar$LCcurrentid">
1.1041 www 7844: <span class="pblabel">$starting</span>
7845: </div>
7846: ENDPROGBAR
1.1045 www 7847: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7848: }
7849:
7850: sub LCprogressbarUpdate {
1.1042 www 7851: my ($r,$val,$text)=@_;
7852: unless ($val) {
7853: if ($LClastpercent) {
7854: $val=$LClastpercent;
7855: } else {
7856: $val=0;
7857: }
7858: }
1.1041 www 7859: if ($val<0) { $val=0; }
7860: if ($val>100) { $val=0; }
1.1042 www 7861: $LClastpercent=$val;
1.1041 www 7862: unless ($text) { $text=$val.'%'; }
7863: $text=&js_ready($text);
1.1044 www 7864: &r_print($r,<<ENDUPDATE);
1.1041 www 7865: <script type="text/javascript">
7866: // <![CDATA[
1.1045 www 7867: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7868: // ]]>
7869: </script>
7870: ENDUPDATE
1.1035 www 7871: }
7872:
1.1042 www 7873: sub LCprogressbarClose {
7874: my ($r)=@_;
7875: $LClastpercent=0;
1.1044 www 7876: &r_print($r,<<ENDCLOSE);
1.1042 www 7877: <script type="text/javascript">
7878: // <![CDATA[
1.1045 www 7879: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7880: // ]]>
7881: </script>
7882: ENDCLOSE
1.1044 www 7883: }
7884:
7885: sub r_print {
7886: my ($r,$to_print)=@_;
7887: if ($r) {
7888: $r->print($to_print);
7889: $r->rflush();
7890: } else {
7891: print($to_print);
7892: }
1.1042 www 7893: }
7894:
1.320 albertel 7895: sub html_encode {
7896: my ($result) = @_;
7897:
1.322 albertel 7898: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7899:
7900: return $result;
7901: }
1.1044 www 7902:
1.317 albertel 7903: sub js_ready {
7904: my ($result) = @_;
7905:
1.323 albertel 7906: $result =~ s/[\n\r]/ /xmsg;
7907: $result =~ s/\\/\\\\/xmsg;
7908: $result =~ s/'/\\'/xmsg;
1.372 albertel 7909: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7910:
7911: return $result;
7912: }
7913:
1.315 albertel 7914: sub validate_page {
7915: if ( exists($env{'internal.start_page'})
1.316 albertel 7916: && $env{'internal.start_page'} > 1) {
7917: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7918: $env{'internal.start_page'}.' '.
1.316 albertel 7919: $ENV{'request.filename'});
1.315 albertel 7920: }
7921: if ( exists($env{'internal.end_page'})
1.316 albertel 7922: && $env{'internal.end_page'} > 1) {
7923: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7924: $env{'internal.end_page'}.' '.
1.316 albertel 7925: $env{'request.filename'});
1.315 albertel 7926: }
7927: if ( exists($env{'internal.start_page'})
7928: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7929: &Apache::lonnet::logthis('start_page called without end_page '.
7930: $env{'request.filename'});
1.315 albertel 7931: }
7932: if ( ! exists($env{'internal.start_page'})
7933: && exists($env{'internal.end_page'})) {
1.316 albertel 7934: &Apache::lonnet::logthis('end_page called without start_page'.
7935: $env{'request.filename'});
1.315 albertel 7936: }
1.306 albertel 7937: }
1.315 albertel 7938:
1.996 www 7939:
7940: sub start_scrollbox {
1.1140 raeburn 7941: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7942: unless ($outerwidth) { $outerwidth='520px'; }
7943: unless ($width) { $width='500px'; }
7944: unless ($height) { $height='200px'; }
1.1075 raeburn 7945: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7946: if ($id ne '') {
1.1140 raeburn 7947: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 7948: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7949: }
1.1075 raeburn 7950: if ($bgcolor ne '') {
7951: $tdcol = "background-color: $bgcolor;";
7952: }
1.1137 raeburn 7953: my $nicescroll_js;
7954: if ($env{'browser.mobile'}) {
1.1140 raeburn 7955: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7956: }
7957: return <<"END";
7958: $nicescroll_js
7959:
7960: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
7961: <div style="overflow:auto; width:$width; height:$height;"$div_id>
7962: END
7963: }
7964:
7965: sub end_scrollbox {
7966: return '</div></td></tr></table>';
7967: }
7968:
7969: sub nicescroll_javascript {
7970: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7971: my %options;
7972: if (ref($cursor) eq 'HASH') {
7973: %options = %{$cursor};
7974: }
7975: unless ($options{'railalign'} =~ /^left|right$/) {
7976: $options{'railalign'} = 'left';
7977: }
7978: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7979: my $function = &get_users_function();
7980: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 7981: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 7982: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 7983: }
1.1140 raeburn 7984: }
7985: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7986: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 7987: $options{'cursoropacity'}='1.0';
7988: }
1.1140 raeburn 7989: } else {
7990: $options{'cursoropacity'}='1.0';
7991: }
7992: if ($options{'cursorfixedheight'} eq 'none') {
7993: delete($options{'cursorfixedheight'});
7994: } else {
7995: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
7996: }
7997: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
7998: delete($options{'railoffset'});
7999: }
8000: my @niceoptions;
8001: while (my($key,$value) = each(%options)) {
8002: if ($value =~ /^\{.+\}$/) {
8003: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8004: } else {
1.1140 raeburn 8005: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8006: }
1.1140 raeburn 8007: }
8008: my $nicescroll_js = '
1.1137 raeburn 8009: $(document).ready(
1.1140 raeburn 8010: function() {
8011: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8012: }
1.1137 raeburn 8013: );
8014: ';
1.1140 raeburn 8015: if ($framecheck) {
8016: $nicescroll_js .= '
8017: function expand_div(caller) {
8018: if (top === self) {
8019: document.getElementById("'.$id.'").style.width = "auto";
8020: document.getElementById("'.$id.'").style.height = "auto";
8021: } else {
8022: try {
8023: if (parent.frames) {
8024: if (parent.frames.length > 1) {
8025: var framesrc = parent.frames[1].location.href;
8026: var currsrc = framesrc.replace(/\#.*$/,"");
8027: if ((caller == "search") || (currsrc == "'.$location.'")) {
8028: document.getElementById("'.$id.'").style.width = "auto";
8029: document.getElementById("'.$id.'").style.height = "auto";
8030: }
8031: }
8032: }
8033: } catch (e) {
8034: return;
8035: }
1.1137 raeburn 8036: }
1.1140 raeburn 8037: return;
1.996 www 8038: }
1.1140 raeburn 8039: ';
8040: }
8041: if ($needjsready) {
8042: $nicescroll_js = '
8043: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8044: } else {
8045: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8046: }
8047: return $nicescroll_js;
1.996 www 8048: }
8049:
1.318 albertel 8050: sub simple_error_page {
8051: my ($r,$title,$msg) = @_;
8052: my $page =
8053: &Apache::loncommon::start_page($title).
1.1097 bisitz 8054: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 8055: &Apache::loncommon::end_page();
8056: if (ref($r)) {
8057: $r->print($page);
1.327 albertel 8058: return;
1.318 albertel 8059: }
8060: return $page;
8061: }
1.347 albertel 8062:
8063: {
1.610 albertel 8064: my @row_count;
1.961 onken 8065:
8066: sub start_data_table_count {
8067: unshift(@row_count, 0);
8068: return;
8069: }
8070:
8071: sub end_data_table_count {
8072: shift(@row_count);
8073: return;
8074: }
8075:
1.347 albertel 8076: sub start_data_table {
1.1018 raeburn 8077: my ($add_class,$id) = @_;
1.422 albertel 8078: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8079: my $table_id;
8080: if (defined($id)) {
8081: $table_id = ' id="'.$id.'"';
8082: }
1.961 onken 8083: &start_data_table_count();
1.1018 raeburn 8084: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8085: }
8086:
8087: sub end_data_table {
1.961 onken 8088: &end_data_table_count();
1.389 albertel 8089: return '</table>'."\n";;
1.347 albertel 8090: }
8091:
8092: sub start_data_table_row {
1.974 wenzelju 8093: my ($add_class, $id) = @_;
1.610 albertel 8094: $row_count[0]++;
8095: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8096: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8097: $id = (' id="'.$id.'"') unless ($id eq '');
8098: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8099: }
1.471 banghart 8100:
8101: sub continue_data_table_row {
1.974 wenzelju 8102: my ($add_class, $id) = @_;
1.610 albertel 8103: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8104: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8105: $id = (' id="'.$id.'"') unless ($id eq '');
8106: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8107: }
1.347 albertel 8108:
8109: sub end_data_table_row {
1.389 albertel 8110: return '</tr>'."\n";;
1.347 albertel 8111: }
1.367 www 8112:
1.421 albertel 8113: sub start_data_table_empty_row {
1.707 bisitz 8114: # $row_count[0]++;
1.421 albertel 8115: return '<tr class="LC_empty_row" >'."\n";;
8116: }
8117:
8118: sub end_data_table_empty_row {
8119: return '</tr>'."\n";;
8120: }
8121:
1.367 www 8122: sub start_data_table_header_row {
1.389 albertel 8123: return '<tr class="LC_header_row">'."\n";;
1.367 www 8124: }
8125:
8126: sub end_data_table_header_row {
1.389 albertel 8127: return '</tr>'."\n";;
1.367 www 8128: }
1.890 droeschl 8129:
8130: sub data_table_caption {
8131: my $caption = shift;
8132: return "<caption class=\"LC_caption\">$caption</caption>";
8133: }
1.347 albertel 8134: }
8135:
1.548 albertel 8136: =pod
8137:
8138: =item * &inhibit_menu_check($arg)
8139:
8140: Checks for a inhibitmenu state and generates output to preserve it
8141:
8142: Inputs: $arg - can be any of
8143: - undef - in which case the return value is a string
8144: to add into arguments list of a uri
8145: - 'input' - in which case the return value is a HTML
8146: <form> <input> field of type hidden to
8147: preserve the value
8148: - a url - in which case the return value is the url with
8149: the neccesary cgi args added to preserve the
8150: inhibitmenu state
8151: - a ref to a url - no return value, but the string is
8152: updated to include the neccessary cgi
8153: args to preserve the inhibitmenu state
8154:
8155: =cut
8156:
8157: sub inhibit_menu_check {
8158: my ($arg) = @_;
8159: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8160: if ($arg eq 'input') {
8161: if ($env{'form.inhibitmenu'}) {
8162: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8163: } else {
8164: return
8165: }
8166: }
8167: if ($env{'form.inhibitmenu'}) {
8168: if (ref($arg)) {
8169: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8170: } elsif ($arg eq '') {
8171: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8172: } else {
8173: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8174: }
8175: }
8176: if (!ref($arg)) {
8177: return $arg;
8178: }
8179: }
8180:
1.251 albertel 8181: ###############################################
1.182 matthew 8182:
8183: =pod
8184:
1.549 albertel 8185: =back
8186:
8187: =head1 User Information Routines
8188:
8189: =over 4
8190:
1.405 albertel 8191: =item * &get_users_function()
1.182 matthew 8192:
8193: Used by &bodytag to determine the current users primary role.
8194: Returns either 'student','coordinator','admin', or 'author'.
8195:
8196: =cut
8197:
8198: ###############################################
8199: sub get_users_function {
1.815 tempelho 8200: my $function = 'norole';
1.818 tempelho 8201: if ($env{'request.role'}=~/^(st)/) {
8202: $function='student';
8203: }
1.907 raeburn 8204: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8205: $function='coordinator';
8206: }
1.258 albertel 8207: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8208: $function='admin';
8209: }
1.826 bisitz 8210: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8211: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8212: $function='author';
8213: }
8214: return $function;
1.54 www 8215: }
1.99 www 8216:
8217: ###############################################
8218:
1.233 raeburn 8219: =pod
8220:
1.821 raeburn 8221: =item * &show_course()
8222:
8223: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8224: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8225:
8226: Inputs:
8227: None
8228:
8229: Outputs:
8230: Scalar: 1 if 'Course' to be used, 0 otherwise.
8231:
8232: =cut
8233:
8234: ###############################################
8235: sub show_course {
8236: my $course = !$env{'user.adv'};
8237: if (!$env{'user.adv'}) {
8238: foreach my $env (keys(%env)) {
8239: next if ($env !~ m/^user\.priv\./);
8240: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8241: $course = 0;
8242: last;
8243: }
8244: }
8245: }
8246: return $course;
8247: }
8248:
8249: ###############################################
8250:
8251: =pod
8252:
1.542 raeburn 8253: =item * &check_user_status()
1.274 raeburn 8254:
8255: Determines current status of supplied role for a
8256: specific user. Roles can be active, previous or future.
8257:
8258: Inputs:
8259: user's domain, user's username, course's domain,
1.375 raeburn 8260: course's number, optional section ID.
1.274 raeburn 8261:
8262: Outputs:
8263: role status: active, previous or future.
8264:
8265: =cut
8266:
8267: sub check_user_status {
1.412 raeburn 8268: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8269: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8270: my @uroles = keys %userinfo;
8271: my $srchstr;
8272: my $active_chk = 'none';
1.412 raeburn 8273: my $now = time;
1.274 raeburn 8274: if (@uroles > 0) {
1.908 raeburn 8275: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8276: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8277: } else {
1.412 raeburn 8278: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8279: }
8280: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8281: my $role_end = 0;
8282: my $role_start = 0;
8283: $active_chk = 'active';
1.412 raeburn 8284: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8285: $role_end = $1;
8286: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8287: $role_start = $1;
1.274 raeburn 8288: }
8289: }
8290: if ($role_start > 0) {
1.412 raeburn 8291: if ($now < $role_start) {
1.274 raeburn 8292: $active_chk = 'future';
8293: }
8294: }
8295: if ($role_end > 0) {
1.412 raeburn 8296: if ($now > $role_end) {
1.274 raeburn 8297: $active_chk = 'previous';
8298: }
8299: }
8300: }
8301: }
8302: return $active_chk;
8303: }
8304:
8305: ###############################################
8306:
8307: =pod
8308:
1.405 albertel 8309: =item * &get_sections()
1.233 raeburn 8310:
8311: Determines all the sections for a course including
8312: sections with students and sections containing other roles.
1.419 raeburn 8313: Incoming parameters:
8314:
8315: 1. domain
8316: 2. course number
8317: 3. reference to array containing roles for which sections should
8318: be gathered (optional).
8319: 4. reference to array containing status types for which sections
8320: should be gathered (optional).
8321:
8322: If the third argument is undefined, sections are gathered for any role.
8323: If the fourth argument is undefined, sections are gathered for any status.
8324: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8325:
1.374 raeburn 8326: Returns section hash (keys are section IDs, values are
8327: number of users in each section), subject to the
1.419 raeburn 8328: optional roles filter, optional status filter
1.233 raeburn 8329:
8330: =cut
8331:
8332: ###############################################
8333: sub get_sections {
1.419 raeburn 8334: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8335: if (!defined($cdom) || !defined($cnum)) {
8336: my $cid = $env{'request.course.id'};
8337:
8338: return if (!defined($cid));
8339:
8340: $cdom = $env{'course.'.$cid.'.domain'};
8341: $cnum = $env{'course.'.$cid.'.num'};
8342: }
8343:
8344: my %sectioncount;
1.419 raeburn 8345: my $now = time;
1.240 albertel 8346:
1.1118 raeburn 8347: my $check_students = 1;
8348: my $only_students = 0;
8349: if (ref($possible_roles) eq 'ARRAY') {
8350: if (grep(/^st$/,@{$possible_roles})) {
8351: if (@{$possible_roles} == 1) {
8352: $only_students = 1;
8353: }
8354: } else {
8355: $check_students = 0;
8356: }
8357: }
8358:
8359: if ($check_students) {
1.276 albertel 8360: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8361: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8362: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8363: my $start_index = &Apache::loncoursedata::CL_START();
8364: my $end_index = &Apache::loncoursedata::CL_END();
8365: my $status;
1.366 albertel 8366: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8367: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8368: $data->[$status_index],
8369: $data->[$start_index],
8370: $data->[$end_index]);
8371: if ($stu_status eq 'Active') {
8372: $status = 'active';
8373: } elsif ($end < $now) {
8374: $status = 'previous';
8375: } elsif ($start > $now) {
8376: $status = 'future';
8377: }
8378: if ($section ne '-1' && $section !~ /^\s*$/) {
8379: if ((!defined($possible_status)) || (($status ne '') &&
8380: (grep/^\Q$status\E$/,@{$possible_status}))) {
8381: $sectioncount{$section}++;
8382: }
1.240 albertel 8383: }
8384: }
8385: }
1.1118 raeburn 8386: if ($only_students) {
8387: return %sectioncount;
8388: }
1.240 albertel 8389: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8390: foreach my $user (sort(keys(%courseroles))) {
8391: if ($user !~ /^(\w{2})/) { next; }
8392: my ($role) = ($user =~ /^(\w{2})/);
8393: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8394: my ($section,$status);
1.240 albertel 8395: if ($role eq 'cr' &&
8396: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8397: $section=$1;
8398: }
8399: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8400: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8401: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8402: if ($end == -1 && $start == -1) {
8403: next; #deleted role
8404: }
8405: if (!defined($possible_status)) {
8406: $sectioncount{$section}++;
8407: } else {
8408: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8409: $status = 'active';
8410: } elsif ($end < $now) {
8411: $status = 'future';
8412: } elsif ($start > $now) {
8413: $status = 'previous';
8414: }
8415: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8416: $sectioncount{$section}++;
8417: }
8418: }
1.233 raeburn 8419: }
1.366 albertel 8420: return %sectioncount;
1.233 raeburn 8421: }
8422:
1.274 raeburn 8423: ###############################################
1.294 raeburn 8424:
8425: =pod
1.405 albertel 8426:
8427: =item * &get_course_users()
8428:
1.275 raeburn 8429: Retrieves usernames:domains for users in the specified course
8430: with specific role(s), and access status.
8431:
8432: Incoming parameters:
1.277 albertel 8433: 1. course domain
8434: 2. course number
8435: 3. access status: users must have - either active,
1.275 raeburn 8436: previous, future, or all.
1.277 albertel 8437: 4. reference to array of permissible roles
1.288 raeburn 8438: 5. reference to array of section restrictions (optional)
8439: 6. reference to results object (hash of hashes).
8440: 7. reference to optional userdata hash
1.609 raeburn 8441: 8. reference to optional statushash
1.630 raeburn 8442: 9. flag if privileged users (except those set to unhide in
8443: course settings) should be excluded
1.609 raeburn 8444: Keys of top level results hash are roles.
1.275 raeburn 8445: Keys of inner hashes are username:domain, with
8446: values set to access type.
1.288 raeburn 8447: Optional userdata hash returns an array with arguments in the
8448: same order as loncoursedata::get_classlist() for student data.
8449:
1.609 raeburn 8450: Optional statushash returns
8451:
1.288 raeburn 8452: Entries for end, start, section and status are blank because
8453: of the possibility of multiple values for non-student roles.
8454:
1.275 raeburn 8455: =cut
1.405 albertel 8456:
1.275 raeburn 8457: ###############################################
1.405 albertel 8458:
1.275 raeburn 8459: sub get_course_users {
1.630 raeburn 8460: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8461: my %idx = ();
1.419 raeburn 8462: my %seclists;
1.288 raeburn 8463:
8464: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8465: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8466: $idx{end} = &Apache::loncoursedata::CL_END();
8467: $idx{start} = &Apache::loncoursedata::CL_START();
8468: $idx{id} = &Apache::loncoursedata::CL_ID();
8469: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8470: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8471: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8472:
1.290 albertel 8473: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8474: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8475: my $now = time;
1.277 albertel 8476: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8477: my $match = 0;
1.412 raeburn 8478: my $secmatch = 0;
1.419 raeburn 8479: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8480: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8481: if ($section eq '') {
8482: $section = 'none';
8483: }
1.291 albertel 8484: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8485: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8486: $secmatch = 1;
8487: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8488: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8489: $secmatch = 1;
8490: }
8491: } else {
1.419 raeburn 8492: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8493: $secmatch = 1;
8494: }
1.290 albertel 8495: }
1.412 raeburn 8496: if (!$secmatch) {
8497: next;
8498: }
1.419 raeburn 8499: }
1.275 raeburn 8500: if (defined($$types{'active'})) {
1.288 raeburn 8501: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8502: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8503: $match = 1;
1.275 raeburn 8504: }
8505: }
8506: if (defined($$types{'previous'})) {
1.609 raeburn 8507: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8508: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8509: $match = 1;
1.275 raeburn 8510: }
8511: }
8512: if (defined($$types{'future'})) {
1.609 raeburn 8513: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8514: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8515: $match = 1;
1.275 raeburn 8516: }
8517: }
1.609 raeburn 8518: if ($match) {
8519: push(@{$seclists{$student}},$section);
8520: if (ref($userdata) eq 'HASH') {
8521: $$userdata{$student} = $$classlist{$student};
8522: }
8523: if (ref($statushash) eq 'HASH') {
8524: $statushash->{$student}{'st'}{$section} = $status;
8525: }
1.288 raeburn 8526: }
1.275 raeburn 8527: }
8528: }
1.412 raeburn 8529: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8530: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8531: my $now = time;
1.609 raeburn 8532: my %displaystatus = ( previous => 'Expired',
8533: active => 'Active',
8534: future => 'Future',
8535: );
1.1121 raeburn 8536: my (%nothide,@possdoms);
1.630 raeburn 8537: if ($hidepriv) {
8538: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8539: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8540: if ($user !~ /:/) {
8541: $nothide{join(':',split(/[\@]/,$user))}=1;
8542: } else {
8543: $nothide{$user} = 1;
8544: }
8545: }
1.1121 raeburn 8546: my @possdoms = ($cdom);
8547: if ($coursehash{'checkforpriv'}) {
8548: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8549: }
1.630 raeburn 8550: }
1.439 raeburn 8551: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8552: my $match = 0;
1.412 raeburn 8553: my $secmatch = 0;
1.439 raeburn 8554: my $status;
1.412 raeburn 8555: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8556: $user =~ s/:$//;
1.439 raeburn 8557: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8558: if ($end == -1 || $start == -1) {
8559: next;
8560: }
8561: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8562: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8563: my ($uname,$udom) = split(/:/,$user);
8564: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8565: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8566: $secmatch = 1;
8567: } elsif ($usec eq '') {
1.420 albertel 8568: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8569: $secmatch = 1;
8570: }
8571: } else {
8572: if (grep(/^\Q$usec\E$/,@{$sections})) {
8573: $secmatch = 1;
8574: }
8575: }
8576: if (!$secmatch) {
8577: next;
8578: }
1.288 raeburn 8579: }
1.419 raeburn 8580: if ($usec eq '') {
8581: $usec = 'none';
8582: }
1.275 raeburn 8583: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8584: if ($hidepriv) {
1.1121 raeburn 8585: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8586: (!$nothide{$uname.':'.$udom})) {
8587: next;
8588: }
8589: }
1.503 raeburn 8590: if ($end > 0 && $end < $now) {
1.439 raeburn 8591: $status = 'previous';
8592: } elsif ($start > $now) {
8593: $status = 'future';
8594: } else {
8595: $status = 'active';
8596: }
1.277 albertel 8597: foreach my $type (keys(%{$types})) {
1.275 raeburn 8598: if ($status eq $type) {
1.420 albertel 8599: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8600: push(@{$$users{$role}{$user}},$type);
8601: }
1.288 raeburn 8602: $match = 1;
8603: }
8604: }
1.419 raeburn 8605: if (($match) && (ref($userdata) eq 'HASH')) {
8606: if (!exists($$userdata{$uname.':'.$udom})) {
8607: &get_user_info($udom,$uname,\%idx,$userdata);
8608: }
1.420 albertel 8609: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8610: push(@{$seclists{$uname.':'.$udom}},$usec);
8611: }
1.609 raeburn 8612: if (ref($statushash) eq 'HASH') {
8613: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8614: }
1.275 raeburn 8615: }
8616: }
8617: }
8618: }
1.290 albertel 8619: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8620: if ((defined($cdom)) && (defined($cnum))) {
8621: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8622: if ( defined($csettings{'internal.courseowner'}) ) {
8623: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8624: next if ($owner eq '');
8625: my ($ownername,$ownerdom);
8626: if ($owner =~ /^([^:]+):([^:]+)$/) {
8627: $ownername = $1;
8628: $ownerdom = $2;
8629: } else {
8630: $ownername = $owner;
8631: $ownerdom = $cdom;
8632: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8633: }
8634: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8635: if (defined($userdata) &&
1.609 raeburn 8636: !exists($$userdata{$owner})) {
8637: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8638: if (!grep(/^none$/,@{$seclists{$owner}})) {
8639: push(@{$seclists{$owner}},'none');
8640: }
8641: if (ref($statushash) eq 'HASH') {
8642: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8643: }
1.290 albertel 8644: }
1.279 raeburn 8645: }
8646: }
8647: }
1.419 raeburn 8648: foreach my $user (keys(%seclists)) {
8649: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8650: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8651: }
1.275 raeburn 8652: }
8653: return;
8654: }
8655:
1.288 raeburn 8656: sub get_user_info {
8657: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8658: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8659: &plainname($uname,$udom,'lastname');
1.291 albertel 8660: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8661: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8662: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8663: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8664: return;
8665: }
1.275 raeburn 8666:
1.472 raeburn 8667: ###############################################
8668:
8669: =pod
8670:
8671: =item * &get_user_quota()
8672:
1.1134 raeburn 8673: Retrieves quota assigned for storage of user files.
8674: Default is to report quota for portfolio files.
1.472 raeburn 8675:
8676: Incoming parameters:
8677: 1. user's username
8678: 2. user's domain
1.1134 raeburn 8679: 3. quota name - portfolio, author, or course
1.1136 raeburn 8680: (if no quota name provided, defaults to portfolio).
8681: 4. crstype - official, unofficial or community, if quota name is
8682: course
1.472 raeburn 8683:
8684: Returns:
1.536 raeburn 8685: 1. Disk quota (in Mb) assigned to student.
8686: 2. (Optional) Type of setting: custom or default
8687: (individually assigned or default for user's
8688: institutional status).
8689: 3. (Optional) - User's institutional status (e.g., faculty, staff
8690: or student - types as defined in localenroll::inst_usertypes
8691: for user's domain, which determines default quota for user.
8692: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8693:
8694: If a value has been stored in the user's environment,
1.536 raeburn 8695: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8696: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8697:
8698: =cut
8699:
8700: ###############################################
8701:
8702:
8703: sub get_user_quota {
1.1136 raeburn 8704: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8705: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8706: if (!defined($udom)) {
8707: $udom = $env{'user.domain'};
8708: }
8709: if (!defined($uname)) {
8710: $uname = $env{'user.name'};
8711: }
8712: if (($udom eq '' || $uname eq '') ||
8713: ($udom eq 'public') && ($uname eq 'public')) {
8714: $quota = 0;
1.536 raeburn 8715: $quotatype = 'default';
8716: $defquota = 0;
1.472 raeburn 8717: } else {
1.536 raeburn 8718: my $inststatus;
1.1134 raeburn 8719: if ($quotaname eq 'course') {
8720: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8721: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8722: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8723: } else {
8724: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8725: $quota = $cenv{'internal.uploadquota'};
8726: }
1.536 raeburn 8727: } else {
1.1134 raeburn 8728: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8729: if ($quotaname eq 'author') {
8730: $quota = $env{'environment.authorquota'};
8731: } else {
8732: $quota = $env{'environment.portfolioquota'};
8733: }
8734: $inststatus = $env{'environment.inststatus'};
8735: } else {
8736: my %userenv =
8737: &Apache::lonnet::get('environment',['portfolioquota',
8738: 'authorquota','inststatus'],$udom,$uname);
8739: my ($tmp) = keys(%userenv);
8740: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8741: if ($quotaname eq 'author') {
8742: $quota = $userenv{'authorquota'};
8743: } else {
8744: $quota = $userenv{'portfolioquota'};
8745: }
8746: $inststatus = $userenv{'inststatus'};
8747: } else {
8748: undef(%userenv);
8749: }
8750: }
8751: }
8752: if ($quota eq '' || wantarray) {
8753: if ($quotaname eq 'course') {
8754: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1136 raeburn 8755: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8756: $defquota = $domdefs{$crstype.'quota'};
8757: }
8758: if ($defquota eq '') {
8759: $defquota = 500;
8760: }
1.1134 raeburn 8761: } else {
8762: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8763: }
8764: if ($quota eq '') {
8765: $quota = $defquota;
8766: $quotatype = 'default';
8767: } else {
8768: $quotatype = 'custom';
8769: }
1.472 raeburn 8770: }
8771: }
1.536 raeburn 8772: if (wantarray) {
8773: return ($quota,$quotatype,$settingstatus,$defquota);
8774: } else {
8775: return $quota;
8776: }
1.472 raeburn 8777: }
8778:
8779: ###############################################
8780:
8781: =pod
8782:
8783: =item * &default_quota()
8784:
1.536 raeburn 8785: Retrieves default quota assigned for storage of user portfolio files,
8786: given an (optional) user's institutional status.
1.472 raeburn 8787:
8788: Incoming parameters:
8789: 1. domain
1.536 raeburn 8790: 2. (Optional) institutional status(es). This is a : separated list of
8791: status types (e.g., faculty, staff, student etc.)
8792: which apply to the user for whom the default is being retrieved.
8793: If the institutional status string in undefined, the domain
1.1134 raeburn 8794: default quota will be returned.
8795: 3. quota name - portfolio, author, or course
8796: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8797:
8798: Returns:
8799: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8800: 2. (Optional) institutional type which determined the value of the
8801: default quota.
1.472 raeburn 8802:
8803: If a value has been stored in the domain's configuration db,
8804: it will return that, otherwise it returns 20 (for backwards
8805: compatibility with domains which have not set up a configuration
8806: db file; the original statically defined portfolio quota was 20 Mb).
8807:
1.536 raeburn 8808: If the user's status includes multiple types (e.g., staff and student),
8809: the largest default quota which applies to the user determines the
8810: default quota returned.
8811:
1.780 raeburn 8812: =back
8813:
1.472 raeburn 8814: =cut
8815:
8816: ###############################################
8817:
8818:
8819: sub default_quota {
1.1134 raeburn 8820: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8821: my ($defquota,$settingstatus);
8822: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8823: ['quotas'],$udom);
1.1134 raeburn 8824: my $key = 'defaultquota';
8825: if ($quotaname eq 'author') {
8826: $key = 'authorquota';
8827: }
1.622 raeburn 8828: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8829: if ($inststatus ne '') {
1.765 raeburn 8830: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8831: foreach my $item (@statuses) {
1.1134 raeburn 8832: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8833: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8834: if ($defquota eq '') {
1.1134 raeburn 8835: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8836: $settingstatus = $item;
1.1134 raeburn 8837: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8838: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8839: $settingstatus = $item;
8840: }
8841: }
1.1134 raeburn 8842: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8843: if ($quotahash{'quotas'}{$item} ne '') {
8844: if ($defquota eq '') {
8845: $defquota = $quotahash{'quotas'}{$item};
8846: $settingstatus = $item;
8847: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8848: $defquota = $quotahash{'quotas'}{$item};
8849: $settingstatus = $item;
8850: }
1.536 raeburn 8851: }
8852: }
8853: }
8854: }
8855: if ($defquota eq '') {
1.1134 raeburn 8856: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8857: $defquota = $quotahash{'quotas'}{$key}{'default'};
8858: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8859: $defquota = $quotahash{'quotas'}{'default'};
8860: }
1.536 raeburn 8861: $settingstatus = 'default';
1.1139 raeburn 8862: if ($defquota eq '') {
8863: if ($quotaname eq 'author') {
8864: $defquota = 500;
8865: }
8866: }
1.536 raeburn 8867: }
8868: } else {
8869: $settingstatus = 'default';
1.1134 raeburn 8870: if ($quotaname eq 'author') {
8871: $defquota = 500;
8872: } else {
8873: $defquota = 20;
8874: }
1.536 raeburn 8875: }
8876: if (wantarray) {
8877: return ($defquota,$settingstatus);
1.472 raeburn 8878: } else {
1.536 raeburn 8879: return $defquota;
1.472 raeburn 8880: }
8881: }
8882:
1.1135 raeburn 8883: ###############################################
8884:
8885: =pod
8886:
1.1136 raeburn 8887: =item * &excess_filesize_warning()
1.1135 raeburn 8888:
8889: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8890: of existing file within authoring space will cause quota for the authoring
8891: space to be exceeded,
8892:
8893: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8894: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8895:
8896: Inputs: 6
1.1136 raeburn 8897: 1. username or coursenum
1.1135 raeburn 8898: 2. domain
1.1136 raeburn 8899: 3. context ('author' or 'course')
1.1135 raeburn 8900: 4. filename of file for which action is being requested
8901: 5. filesize (kB) of file
8902: 6. action being taken: copy or upload.
8903:
8904: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8905: otherwise return null.
8906:
8907: =cut
8908:
1.1136 raeburn 8909: sub excess_filesize_warning {
8910: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8911: my $current_disk_usage = 0;
8912: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8913: if ($context eq 'author') {
8914: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8915: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8916: } else {
8917: foreach my $subdir ('docs','supplemental') {
8918: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8919: }
8920: }
1.1135 raeburn 8921: $disk_quota = int($disk_quota * 1000);
8922: if (($current_disk_usage + $filesize) > $disk_quota) {
8923: return '<p><span class="LC_warning">'.
8924: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8925: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8926: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8927: $disk_quota,$current_disk_usage).
8928: '</p>';
8929: }
8930: return;
8931: }
8932:
8933: ###############################################
8934:
8935:
1.1136 raeburn 8936:
8937:
1.384 raeburn 8938: sub get_secgrprole_info {
8939: my ($cdom,$cnum,$needroles,$type) = @_;
8940: my %sections_count = &get_sections($cdom,$cnum);
8941: my @sections = (sort {$a <=> $b} keys(%sections_count));
8942: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8943: my @groups = sort(keys(%curr_groups));
8944: my $allroles = [];
8945: my $rolehash;
8946: my $accesshash = {
8947: active => 'Currently has access',
8948: future => 'Will have future access',
8949: previous => 'Previously had access',
8950: };
8951: if ($needroles) {
8952: $rolehash = {'all' => 'all'};
1.385 albertel 8953: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8954: if (&Apache::lonnet::error(%user_roles)) {
8955: undef(%user_roles);
8956: }
8957: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8958: my ($role)=split(/\:/,$item,2);
8959: if ($role eq 'cr') { next; }
8960: if ($role =~ /^cr/) {
8961: $$rolehash{$role} = (split('/',$role))[3];
8962: } else {
8963: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8964: }
8965: }
8966: foreach my $key (sort(keys(%{$rolehash}))) {
8967: push(@{$allroles},$key);
8968: }
8969: push (@{$allroles},'st');
8970: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8971: }
8972: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8973: }
8974:
1.555 raeburn 8975: sub user_picker {
1.994 raeburn 8976: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8977: my $currdom = $dom;
8978: my %curr_selected = (
8979: srchin => 'dom',
1.580 raeburn 8980: srchby => 'lastname',
1.555 raeburn 8981: );
8982: my $srchterm;
1.625 raeburn 8983: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8984: if ($srch->{'srchby'} ne '') {
8985: $curr_selected{'srchby'} = $srch->{'srchby'};
8986: }
8987: if ($srch->{'srchin'} ne '') {
8988: $curr_selected{'srchin'} = $srch->{'srchin'};
8989: }
8990: if ($srch->{'srchtype'} ne '') {
8991: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8992: }
8993: if ($srch->{'srchdomain'} ne '') {
8994: $currdom = $srch->{'srchdomain'};
8995: }
8996: $srchterm = $srch->{'srchterm'};
8997: }
8998: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8999: 'usr' => 'Search criteria',
1.563 raeburn 9000: 'doma' => 'Domain/institution to search',
1.558 albertel 9001: 'uname' => 'username',
9002: 'lastname' => 'last name',
1.555 raeburn 9003: 'lastfirst' => 'last name, first name',
1.558 albertel 9004: 'crs' => 'in this course',
1.576 raeburn 9005: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9006: 'alc' => 'all LON-CAPA',
1.573 raeburn 9007: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9008: 'exact' => 'is',
9009: 'contains' => 'contains',
1.569 raeburn 9010: 'begins' => 'begins with',
1.571 raeburn 9011: 'youm' => "You must include some text to search for.",
9012: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9013: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9014: 'yomc' => "You must choose a domain when using an institutional directory search.",
9015: 'ymcd' => "You must choose a domain when using a domain search.",
9016: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9017: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9018: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9019: );
1.563 raeburn 9020: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9021: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9022:
9023: my @srchins = ('crs','dom','alc','instd');
9024:
9025: foreach my $option (@srchins) {
9026: # FIXME 'alc' option unavailable until
9027: # loncreateuser::print_user_query_page()
9028: # has been completed.
9029: next if ($option eq 'alc');
1.880 raeburn 9030: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9031: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9032: if ($curr_selected{'srchin'} eq $option) {
9033: $srchinsel .= '
9034: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9035: } else {
9036: $srchinsel .= '
9037: <option value="'.$option.'">'.$lt{$option}.'</option>';
9038: }
1.555 raeburn 9039: }
1.563 raeburn 9040: $srchinsel .= "\n </select>\n";
1.555 raeburn 9041:
9042: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9043: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9044: if ($curr_selected{'srchby'} eq $option) {
9045: $srchbysel .= '
9046: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9047: } else {
9048: $srchbysel .= '
9049: <option value="'.$option.'">'.$lt{$option}.'</option>';
9050: }
9051: }
9052: $srchbysel .= "\n </select>\n";
9053:
9054: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9055: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9056: if ($curr_selected{'srchtype'} eq $option) {
9057: $srchtypesel .= '
9058: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9059: } else {
9060: $srchtypesel .= '
9061: <option value="'.$option.'">'.$lt{$option}.'</option>';
9062: }
9063: }
9064: $srchtypesel .= "\n </select>\n";
9065:
1.558 albertel 9066: my ($newuserscript,$new_user_create);
1.994 raeburn 9067: my $context_dom = $env{'request.role.domain'};
9068: if ($context eq 'requestcrs') {
9069: if ($env{'form.coursedom'} ne '') {
9070: $context_dom = $env{'form.coursedom'};
9071: }
9072: }
1.556 raeburn 9073: if ($forcenewuser) {
1.576 raeburn 9074: if (ref($srch) eq 'HASH') {
1.994 raeburn 9075: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9076: if ($cancreate) {
9077: $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>';
9078: } else {
1.799 bisitz 9079: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9080: my %usertypetext = (
9081: official => 'institutional',
9082: unofficial => 'non-institutional',
9083: );
1.799 bisitz 9084: $new_user_create = '<p class="LC_warning">'
9085: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9086: .' '
9087: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9088: ,'<a href="'.$helplink.'">','</a>')
9089: .'</p><br />';
1.627 raeburn 9090: }
1.576 raeburn 9091: }
9092: }
9093:
1.556 raeburn 9094: $newuserscript = <<"ENDSCRIPT";
9095:
1.570 raeburn 9096: function setSearch(createnew,callingForm) {
1.556 raeburn 9097: if (createnew == 1) {
1.570 raeburn 9098: for (var i=0; i<callingForm.srchby.length; i++) {
9099: if (callingForm.srchby.options[i].value == 'uname') {
9100: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9101: }
9102: }
1.570 raeburn 9103: for (var i=0; i<callingForm.srchin.length; i++) {
9104: if ( callingForm.srchin.options[i].value == 'dom') {
9105: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9106: }
9107: }
1.570 raeburn 9108: for (var i=0; i<callingForm.srchtype.length; i++) {
9109: if (callingForm.srchtype.options[i].value == 'exact') {
9110: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9111: }
9112: }
1.570 raeburn 9113: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9114: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9115: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9116: }
9117: }
9118: }
9119: }
9120: ENDSCRIPT
1.558 albertel 9121:
1.556 raeburn 9122: }
9123:
1.555 raeburn 9124: my $output = <<"END_BLOCK";
1.556 raeburn 9125: <script type="text/javascript">
1.824 bisitz 9126: // <![CDATA[
1.570 raeburn 9127: function validateEntry(callingForm) {
1.558 albertel 9128:
1.556 raeburn 9129: var checkok = 1;
1.558 albertel 9130: var srchin;
1.570 raeburn 9131: for (var i=0; i<callingForm.srchin.length; i++) {
9132: if ( callingForm.srchin[i].checked ) {
9133: srchin = callingForm.srchin[i].value;
1.558 albertel 9134: }
9135: }
9136:
1.570 raeburn 9137: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9138: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9139: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9140: var srchterm = callingForm.srchterm.value;
9141: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9142: var msg = "";
9143:
9144: if (srchterm == "") {
9145: checkok = 0;
1.571 raeburn 9146: msg += "$lt{'youm'}\\n";
1.556 raeburn 9147: }
9148:
1.569 raeburn 9149: if (srchtype== 'begins') {
9150: if (srchterm.length < 2) {
9151: checkok = 0;
1.571 raeburn 9152: msg += "$lt{'thte'}\\n";
1.569 raeburn 9153: }
9154: }
9155:
1.556 raeburn 9156: if (srchtype== 'contains') {
9157: if (srchterm.length < 3) {
9158: checkok = 0;
1.571 raeburn 9159: msg += "$lt{'thet'}\\n";
1.556 raeburn 9160: }
9161: }
9162: if (srchin == 'instd') {
9163: if (srchdomain == '') {
9164: checkok = 0;
1.571 raeburn 9165: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9166: }
9167: }
9168: if (srchin == 'dom') {
9169: if (srchdomain == '') {
9170: checkok = 0;
1.571 raeburn 9171: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9172: }
9173: }
9174: if (srchby == 'lastfirst') {
9175: if (srchterm.indexOf(",") == -1) {
9176: checkok = 0;
1.571 raeburn 9177: msg += "$lt{'whus'}\\n";
1.556 raeburn 9178: }
9179: if (srchterm.indexOf(",") == srchterm.length -1) {
9180: checkok = 0;
1.571 raeburn 9181: msg += "$lt{'whse'}\\n";
1.556 raeburn 9182: }
9183: }
9184: if (checkok == 0) {
1.571 raeburn 9185: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9186: return;
9187: }
9188: if (checkok == 1) {
1.570 raeburn 9189: callingForm.submit();
1.556 raeburn 9190: }
9191: }
9192:
9193: $newuserscript
9194:
1.824 bisitz 9195: // ]]>
1.556 raeburn 9196: </script>
1.558 albertel 9197:
9198: $new_user_create
9199:
1.555 raeburn 9200: END_BLOCK
1.558 albertel 9201:
1.876 raeburn 9202: $output .= &Apache::lonhtmlcommon::start_pick_box().
9203: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9204: $domform.
9205: &Apache::lonhtmlcommon::row_closure().
9206: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9207: $srchbysel.
9208: $srchtypesel.
9209: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9210: $srchinsel.
9211: &Apache::lonhtmlcommon::row_closure(1).
9212: &Apache::lonhtmlcommon::end_pick_box().
9213: '<br />';
1.555 raeburn 9214: return $output;
9215: }
9216:
1.612 raeburn 9217: sub user_rule_check {
1.615 raeburn 9218: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9219: my $response;
9220: if (ref($usershash) eq 'HASH') {
9221: foreach my $user (keys(%{$usershash})) {
9222: my ($uname,$udom) = split(/:/,$user);
9223: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9224: my ($id,$newuser);
1.612 raeburn 9225: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9226: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9227: $id = $usershash->{$user}->{'id'};
9228: }
9229: my $inst_response;
9230: if (ref($checks) eq 'HASH') {
9231: if (defined($checks->{'username'})) {
1.615 raeburn 9232: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9233: &Apache::lonnet::get_instuser($udom,$uname);
9234: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9235: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9236: &Apache::lonnet::get_instuser($udom,undef,$id);
9237: }
1.615 raeburn 9238: } else {
9239: ($inst_response,%{$inst_results->{$user}}) =
9240: &Apache::lonnet::get_instuser($udom,$uname);
9241: return;
1.612 raeburn 9242: }
1.615 raeburn 9243: if (!$got_rules->{$udom}) {
1.612 raeburn 9244: my %domconfig = &Apache::lonnet::get_dom('configuration',
9245: ['usercreation'],$udom);
9246: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9247: foreach my $item ('username','id') {
1.612 raeburn 9248: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9249: $$curr_rules{$udom}{$item} =
9250: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9251: }
9252: }
9253: }
1.615 raeburn 9254: $got_rules->{$udom} = 1;
1.585 raeburn 9255: }
1.612 raeburn 9256: foreach my $item (keys(%{$checks})) {
9257: if (ref($$curr_rules{$udom}) eq 'HASH') {
9258: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9259: if (@{$$curr_rules{$udom}{$item}} > 0) {
9260: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9261: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9262: if ($rule_check{$rule}) {
9263: $$rulematch{$user}{$item} = $rule;
9264: if ($inst_response eq 'ok') {
1.615 raeburn 9265: if (ref($inst_results) eq 'HASH') {
9266: if (ref($inst_results->{$user}) eq 'HASH') {
9267: if (keys(%{$inst_results->{$user}}) == 0) {
9268: $$alerts{$item}{$udom}{$uname} = 1;
9269: }
1.612 raeburn 9270: }
9271: }
1.615 raeburn 9272: }
9273: last;
1.585 raeburn 9274: }
9275: }
9276: }
9277: }
9278: }
9279: }
9280: }
9281: }
1.612 raeburn 9282: return;
9283: }
9284:
9285: sub user_rule_formats {
9286: my ($domain,$domdesc,$curr_rules,$check) = @_;
9287: my %text = (
9288: 'username' => 'Usernames',
9289: 'id' => 'IDs',
9290: );
9291: my $output;
9292: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9293: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9294: if (@{$ruleorder} > 0) {
1.1102 raeburn 9295: $output = '<br />'.
9296: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9297: '<span class="LC_cusr_emph">','</span>',$domdesc).
9298: ' <ul>';
1.612 raeburn 9299: foreach my $rule (@{$ruleorder}) {
9300: if (ref($curr_rules) eq 'ARRAY') {
9301: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9302: if (ref($rules->{$rule}) eq 'HASH') {
9303: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9304: $rules->{$rule}{'desc'}.'</li>';
9305: }
9306: }
9307: }
9308: }
9309: $output .= '</ul>';
9310: }
9311: }
9312: return $output;
9313: }
9314:
9315: sub instrule_disallow_msg {
1.615 raeburn 9316: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9317: my $response;
9318: my %text = (
9319: item => 'username',
9320: items => 'usernames',
9321: match => 'matches',
9322: do => 'does',
9323: action => 'a username',
9324: one => 'one',
9325: );
9326: if ($count > 1) {
9327: $text{'item'} = 'usernames';
9328: $text{'match'} ='match';
9329: $text{'do'} = 'do';
9330: $text{'action'} = 'usernames',
9331: $text{'one'} = 'ones';
9332: }
9333: if ($checkitem eq 'id') {
9334: $text{'items'} = 'IDs';
9335: $text{'item'} = 'ID';
9336: $text{'action'} = 'an ID';
1.615 raeburn 9337: if ($count > 1) {
9338: $text{'item'} = 'IDs';
9339: $text{'action'} = 'IDs';
9340: }
1.612 raeburn 9341: }
1.674 bisitz 9342: $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 9343: if ($mode eq 'upload') {
9344: if ($checkitem eq 'username') {
9345: $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'}.");
9346: } elsif ($checkitem eq 'id') {
1.674 bisitz 9347: $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 9348: }
1.669 raeburn 9349: } elsif ($mode eq 'selfcreate') {
9350: if ($checkitem eq 'id') {
9351: $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.");
9352: }
1.615 raeburn 9353: } else {
9354: if ($checkitem eq 'username') {
9355: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9356: } elsif ($checkitem eq 'id') {
9357: $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.");
9358: }
1.612 raeburn 9359: }
9360: return $response;
1.585 raeburn 9361: }
9362:
1.624 raeburn 9363: sub personal_data_fieldtitles {
9364: my %fieldtitles = &Apache::lonlocal::texthash (
9365: id => 'Student/Employee ID',
9366: permanentemail => 'E-mail address',
9367: lastname => 'Last Name',
9368: firstname => 'First Name',
9369: middlename => 'Middle Name',
9370: generation => 'Generation',
9371: gen => 'Generation',
1.765 raeburn 9372: inststatus => 'Affiliation',
1.624 raeburn 9373: );
9374: return %fieldtitles;
9375: }
9376:
1.642 raeburn 9377: sub sorted_inst_types {
9378: my ($dom) = @_;
9379: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9380: my $othertitle = &mt('All users');
9381: if ($env{'request.course.id'}) {
1.668 raeburn 9382: $othertitle = &mt('Any users');
1.642 raeburn 9383: }
9384: my @types;
9385: if (ref($order) eq 'ARRAY') {
9386: @types = @{$order};
9387: }
9388: if (@types == 0) {
9389: if (ref($usertypes) eq 'HASH') {
9390: @types = sort(keys(%{$usertypes}));
9391: }
9392: }
9393: if (keys(%{$usertypes}) > 0) {
9394: $othertitle = &mt('Other users');
9395: }
9396: return ($othertitle,$usertypes,\@types);
9397: }
9398:
1.645 raeburn 9399: sub get_institutional_codes {
9400: my ($settings,$allcourses,$LC_code) = @_;
9401: # Get complete list of course sections to update
9402: my @currsections = ();
9403: my @currxlists = ();
9404: my $coursecode = $$settings{'internal.coursecode'};
9405:
9406: if ($$settings{'internal.sectionnums'} ne '') {
9407: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9408: }
9409:
9410: if ($$settings{'internal.crosslistings'} ne '') {
9411: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9412: }
9413:
9414: if (@currxlists > 0) {
9415: foreach (@currxlists) {
9416: if (m/^([^:]+):(\w*)$/) {
9417: unless (grep/^$1$/,@{$allcourses}) {
9418: push @{$allcourses},$1;
9419: $$LC_code{$1} = $2;
9420: }
9421: }
9422: }
9423: }
9424:
9425: if (@currsections > 0) {
9426: foreach (@currsections) {
9427: if (m/^(\w+):(\w*)$/) {
9428: my $sec = $coursecode.$1;
9429: my $lc_sec = $2;
9430: unless (grep/^$sec$/,@{$allcourses}) {
9431: push @{$allcourses},$sec;
9432: $$LC_code{$sec} = $lc_sec;
9433: }
9434: }
9435: }
9436: }
9437: return;
9438: }
9439:
1.971 raeburn 9440: sub get_standard_codeitems {
9441: return ('Year','Semester','Department','Number','Section');
9442: }
9443:
1.112 bowersj2 9444: =pod
9445:
1.780 raeburn 9446: =head1 Slot Helpers
9447:
9448: =over 4
9449:
9450: =item * sorted_slots()
9451:
1.1040 raeburn 9452: Sorts an array of slot names in order of an optional sort key,
9453: default sort is by slot start time (earliest first).
1.780 raeburn 9454:
9455: Inputs:
9456:
9457: =over 4
9458:
9459: slotsarr - Reference to array of unsorted slot names.
9460:
9461: slots - Reference to hash of hash, where outer hash keys are slot names.
9462:
1.1040 raeburn 9463: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9464:
1.549 albertel 9465: =back
9466:
1.780 raeburn 9467: Returns:
9468:
9469: =over 4
9470:
1.1040 raeburn 9471: sorted - An array of slot names sorted by a specified sort key
9472: (default sort key is start time of the slot).
1.780 raeburn 9473:
9474: =back
9475:
9476: =cut
9477:
9478:
9479: sub sorted_slots {
1.1040 raeburn 9480: my ($slotsarr,$slots,$sortkey) = @_;
9481: if ($sortkey eq '') {
9482: $sortkey = 'starttime';
9483: }
1.780 raeburn 9484: my @sorted;
9485: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9486: @sorted =
9487: sort {
9488: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9489: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9490: }
9491: if (ref($slots->{$a})) { return -1;}
9492: if (ref($slots->{$b})) { return 1;}
9493: return 0;
9494: } @{$slotsarr};
9495: }
9496: return @sorted;
9497: }
9498:
1.1040 raeburn 9499: =pod
9500:
9501: =item * get_future_slots()
9502:
9503: Inputs:
9504:
9505: =over 4
9506:
9507: cnum - course number
9508:
9509: cdom - course domain
9510:
9511: now - current UNIX time
9512:
9513: symb - optional symb
9514:
9515: =back
9516:
9517: Returns:
9518:
9519: =over 4
9520:
9521: sorted_reservable - ref to array of student_schedulable slots currently
9522: reservable, ordered by end date of reservation period.
9523:
9524: reservable_now - ref to hash of student_schedulable slots currently
9525: reservable.
9526:
9527: Keys in inner hash are:
9528: (a) symb: either blank or symb to which slot use is restricted.
9529: (b) endreserve: end date of reservation period.
9530:
9531: sorted_future - ref to array of student_schedulable slots reservable in
9532: the future, ordered by start date of reservation period.
9533:
9534: future_reservable - ref to hash of student_schedulable slots reservable
9535: in the future.
9536:
9537: Keys in inner hash are:
9538: (a) symb: either blank or symb to which slot use is restricted.
9539: (b) startreserve: start date of reservation period.
9540:
9541: =back
9542:
9543: =cut
9544:
9545: sub get_future_slots {
9546: my ($cnum,$cdom,$now,$symb) = @_;
9547: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9548: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9549: foreach my $slot (keys(%slots)) {
9550: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9551: if ($symb) {
9552: next if (($slots{$slot}->{'symb'} ne '') &&
9553: ($slots{$slot}->{'symb'} ne $symb));
9554: }
9555: if (($slots{$slot}->{'starttime'} > $now) &&
9556: ($slots{$slot}->{'endtime'} > $now)) {
9557: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9558: my $userallowed = 0;
9559: if ($slots{$slot}->{'allowedsections'}) {
9560: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9561: if (!defined($env{'request.role.sec'})
9562: && grep(/^No section assigned$/,@allowed_sec)) {
9563: $userallowed=1;
9564: } else {
9565: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9566: $userallowed=1;
9567: }
9568: }
9569: unless ($userallowed) {
9570: if (defined($env{'request.course.groups'})) {
9571: my @groups = split(/:/,$env{'request.course.groups'});
9572: foreach my $group (@groups) {
9573: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9574: $userallowed=1;
9575: last;
9576: }
9577: }
9578: }
9579: }
9580: }
9581: if ($slots{$slot}->{'allowedusers'}) {
9582: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9583: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9584: if (grep(/^\Q$user\E$/,@allowed_users)) {
9585: $userallowed = 1;
9586: }
9587: }
9588: next unless($userallowed);
9589: }
9590: my $startreserve = $slots{$slot}->{'startreserve'};
9591: my $endreserve = $slots{$slot}->{'endreserve'};
9592: my $symb = $slots{$slot}->{'symb'};
9593: if (($startreserve < $now) &&
9594: (!$endreserve || $endreserve > $now)) {
9595: my $lastres = $endreserve;
9596: if (!$lastres) {
9597: $lastres = $slots{$slot}->{'starttime'};
9598: }
9599: $reservable_now{$slot} = {
9600: symb => $symb,
9601: endreserve => $lastres
9602: };
9603: } elsif (($startreserve > $now) &&
9604: (!$endreserve || $endreserve > $startreserve)) {
9605: $future_reservable{$slot} = {
9606: symb => $symb,
9607: startreserve => $startreserve
9608: };
9609: }
9610: }
9611: }
9612: my @unsorted_reservable = keys(%reservable_now);
9613: if (@unsorted_reservable > 0) {
9614: @sorted_reservable =
9615: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9616: }
9617: my @unsorted_future = keys(%future_reservable);
9618: if (@unsorted_future > 0) {
9619: @sorted_future =
9620: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9621: }
9622: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9623: }
1.780 raeburn 9624:
9625: =pod
9626:
1.1057 foxr 9627: =back
9628:
1.549 albertel 9629: =head1 HTTP Helpers
9630:
9631: =over 4
9632:
1.648 raeburn 9633: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9634:
1.258 albertel 9635: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9636: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9637: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9638:
9639: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9640: $possible_names is an ref to an array of form element names. As an example:
9641: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9642: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9643:
9644: =cut
1.1 albertel 9645:
1.6 albertel 9646: sub get_unprocessed_cgi {
1.25 albertel 9647: my ($query,$possible_names)= @_;
1.26 matthew 9648: # $Apache::lonxml::debug=1;
1.356 albertel 9649: foreach my $pair (split(/&/,$query)) {
9650: my ($name, $value) = split(/=/,$pair);
1.369 www 9651: $name = &unescape($name);
1.25 albertel 9652: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9653: $value =~ tr/+/ /;
9654: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9655: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9656: }
1.16 harris41 9657: }
1.6 albertel 9658: }
9659:
1.112 bowersj2 9660: =pod
9661:
1.648 raeburn 9662: =item * &cacheheader()
1.112 bowersj2 9663:
9664: returns cache-controlling header code
9665:
9666: =cut
9667:
1.7 albertel 9668: sub cacheheader {
1.258 albertel 9669: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9670: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9671: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9672: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9673: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9674: return $output;
1.7 albertel 9675: }
9676:
1.112 bowersj2 9677: =pod
9678:
1.648 raeburn 9679: =item * &no_cache($r)
1.112 bowersj2 9680:
9681: specifies header code to not have cache
9682:
9683: =cut
9684:
1.9 albertel 9685: sub no_cache {
1.216 albertel 9686: my ($r) = @_;
9687: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9688: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9689: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9690: $r->no_cache(1);
9691: $r->header_out("Expires" => $date);
9692: $r->header_out("Pragma" => "no-cache");
1.123 www 9693: }
9694:
9695: sub content_type {
1.181 albertel 9696: my ($r,$type,$charset) = @_;
1.299 foxr 9697: if ($r) {
9698: # Note that printout.pl calls this with undef for $r.
9699: &no_cache($r);
9700: }
1.258 albertel 9701: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9702: unless ($charset) {
9703: $charset=&Apache::lonlocal::current_encoding;
9704: }
9705: if ($charset) { $type.='; charset='.$charset; }
9706: if ($r) {
9707: $r->content_type($type);
9708: } else {
9709: print("Content-type: $type\n\n");
9710: }
1.9 albertel 9711: }
1.25 albertel 9712:
1.112 bowersj2 9713: =pod
9714:
1.648 raeburn 9715: =item * &add_to_env($name,$value)
1.112 bowersj2 9716:
1.258 albertel 9717: adds $name to the %env hash with value
1.112 bowersj2 9718: $value, if $name already exists, the entry is converted to an array
9719: reference and $value is added to the array.
9720:
9721: =cut
9722:
1.25 albertel 9723: sub add_to_env {
9724: my ($name,$value)=@_;
1.258 albertel 9725: if (defined($env{$name})) {
9726: if (ref($env{$name})) {
1.25 albertel 9727: #already have multiple values
1.258 albertel 9728: push(@{ $env{$name} },$value);
1.25 albertel 9729: } else {
9730: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9731: my $first=$env{$name};
9732: undef($env{$name});
9733: push(@{ $env{$name} },$first,$value);
1.25 albertel 9734: }
9735: } else {
1.258 albertel 9736: $env{$name}=$value;
1.25 albertel 9737: }
1.31 albertel 9738: }
1.149 albertel 9739:
9740: =pod
9741:
1.648 raeburn 9742: =item * &get_env_multiple($name)
1.149 albertel 9743:
1.258 albertel 9744: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9745: values may be defined and end up as an array ref.
9746:
9747: returns an array of values
9748:
9749: =cut
9750:
9751: sub get_env_multiple {
9752: my ($name) = @_;
9753: my @values;
1.258 albertel 9754: if (defined($env{$name})) {
1.149 albertel 9755: # exists is it an array
1.258 albertel 9756: if (ref($env{$name})) {
9757: @values=@{ $env{$name} };
1.149 albertel 9758: } else {
1.258 albertel 9759: $values[0]=$env{$name};
1.149 albertel 9760: }
9761: }
9762: return(@values);
9763: }
9764:
1.660 raeburn 9765: sub ask_for_embedded_content {
9766: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9767: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9768: %currsubfile,%unused,$rem);
1.1071 raeburn 9769: my $counter = 0;
9770: my $numnew = 0;
1.987 raeburn 9771: my $numremref = 0;
9772: my $numinvalid = 0;
9773: my $numpathchg = 0;
9774: my $numexisting = 0;
1.1071 raeburn 9775: my $numunused = 0;
9776: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9777: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9778: my $heading = &mt('Upload embedded files');
9779: my $buttontext = &mt('Upload');
9780:
1.1123 raeburn 9781: my ($navmap,$cdom,$cnum);
1.1085 raeburn 9782: if ($env{'request.course.id'}) {
1.1123 raeburn 9783: if ($actionurl eq '/adm/dependencies') {
9784: $navmap = Apache::lonnavmaps::navmap->new();
9785: }
9786: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9787: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9788: }
1.1123 raeburn 9789: if (($actionurl eq '/adm/portfolio') ||
9790: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9791: my $current_path='/';
9792: if ($env{'form.currentpath'}) {
9793: $current_path = $env{'form.currentpath'};
9794: }
9795: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9796: $udom = $cdom;
9797: $uname = $cnum;
1.984 raeburn 9798: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9799: } else {
9800: $udom = $env{'user.domain'};
9801: $uname = $env{'user.name'};
9802: $url = '/userfiles/portfolio';
9803: }
1.987 raeburn 9804: $toplevel = $url.'/';
1.984 raeburn 9805: $url .= $current_path;
9806: $getpropath = 1;
1.987 raeburn 9807: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9808: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9809: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9810: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9811: $toplevel = $url;
1.984 raeburn 9812: if ($rest ne '') {
1.987 raeburn 9813: $url .= $rest;
9814: }
9815: } elsif ($actionurl eq '/adm/coursedocs') {
9816: if (ref($args) eq 'HASH') {
1.1071 raeburn 9817: $url = $args->{'docs_url'};
9818: $toplevel = $url;
1.1084 raeburn 9819: if ($args->{'context'} eq 'paste') {
9820: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9821: ($path) =
9822: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9823: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9824: $fileloc =~ s{^/}{};
9825: }
1.1071 raeburn 9826: }
1.1084 raeburn 9827: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9828: if ($env{'request.course.id'} ne '') {
9829: if (ref($args) eq 'HASH') {
9830: $url = $args->{'docs_url'};
9831: $title = $args->{'docs_title'};
1.1126 raeburn 9832: $toplevel = $url;
9833: unless ($toplevel =~ m{^/}) {
9834: $toplevel = "/$url";
9835: }
1.1085 raeburn 9836: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9837: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9838: $path = $1;
9839: } else {
9840: ($path) =
9841: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9842: }
1.1071 raeburn 9843: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9844: $fileloc =~ s{^/}{};
9845: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9846: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9847: }
1.987 raeburn 9848: }
1.1123 raeburn 9849: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9850: $udom = $cdom;
9851: $uname = $cnum;
9852: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9853: $toplevel = $url;
9854: $path = $url;
9855: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9856: $fileloc =~ s{^/}{};
1.987 raeburn 9857: }
1.1126 raeburn 9858: foreach my $file (keys(%{$allfiles})) {
9859: my $embed_file;
9860: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9861: $embed_file = $1;
9862: } else {
9863: $embed_file = $file;
9864: }
1.987 raeburn 9865: my $absolutepath;
9866: if ($embed_file =~ m{^\w+://}) {
9867: $newfiles{$embed_file} = 1;
9868: $mapping{$embed_file} = $embed_file;
9869: } else {
9870: if ($embed_file =~ m{^/}) {
9871: $absolutepath = $embed_file;
9872: $embed_file =~ s{^(/+)}{};
9873: }
9874: if ($embed_file =~ m{/}) {
9875: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9876: $path = &check_for_traversal($path,$url,$toplevel);
9877: my $item = $fname;
9878: if ($path ne '') {
9879: $item = $path.'/'.$fname;
9880: $subdependencies{$path}{$fname} = 1;
9881: } else {
9882: $dependencies{$item} = 1;
9883: }
9884: if ($absolutepath) {
9885: $mapping{$item} = $absolutepath;
9886: } else {
9887: $mapping{$item} = $embed_file;
9888: }
9889: } else {
9890: $dependencies{$embed_file} = 1;
9891: if ($absolutepath) {
9892: $mapping{$embed_file} = $absolutepath;
9893: } else {
9894: $mapping{$embed_file} = $embed_file;
9895: }
9896: }
1.984 raeburn 9897: }
9898: }
1.1071 raeburn 9899: my $dirptr = 16384;
1.984 raeburn 9900: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9901: $currsubfile{$path} = {};
1.1123 raeburn 9902: if (($actionurl eq '/adm/portfolio') ||
9903: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9904: my ($sublistref,$listerror) =
9905: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9906: if (ref($sublistref) eq 'ARRAY') {
9907: foreach my $line (@{$sublistref}) {
9908: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9909: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9910: }
1.984 raeburn 9911: }
1.987 raeburn 9912: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9913: if (opendir(my $dir,$url.'/'.$path)) {
9914: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9915: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9916: }
1.1084 raeburn 9917: } elsif (($actionurl eq '/adm/dependencies') ||
9918: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9919: ($args->{'context'} eq 'paste')) ||
9920: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9921: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9922: my $dir;
9923: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9924: $dir = $fileloc;
9925: } else {
9926: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9927: }
1.1071 raeburn 9928: if ($dir ne '') {
9929: my ($sublistref,$listerror) =
9930: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9931: if (ref($sublistref) eq 'ARRAY') {
9932: foreach my $line (@{$sublistref}) {
9933: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9934: undef,$mtime)=split(/\&/,$line,12);
9935: unless (($testdir&$dirptr) ||
9936: ($file_name =~ /^\.\.?$/)) {
9937: $currsubfile{$path}{$file_name} = [$size,$mtime];
9938: }
9939: }
9940: }
9941: }
1.984 raeburn 9942: }
9943: }
9944: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9945: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9946: my $item = $path.'/'.$file;
9947: unless ($mapping{$item} eq $item) {
9948: $pathchanges{$item} = 1;
9949: }
9950: $existing{$item} = 1;
9951: $numexisting ++;
9952: } else {
9953: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9954: }
9955: }
1.1071 raeburn 9956: if ($actionurl eq '/adm/dependencies') {
9957: foreach my $path (keys(%currsubfile)) {
9958: if (ref($currsubfile{$path}) eq 'HASH') {
9959: foreach my $file (keys(%{$currsubfile{$path}})) {
9960: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9961: next if (($rem ne '') &&
9962: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9963: (ref($navmap) &&
9964: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9965: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9966: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9967: $unused{$path.'/'.$file} = 1;
9968: }
9969: }
9970: }
9971: }
9972: }
1.984 raeburn 9973: }
1.987 raeburn 9974: my %currfile;
1.1123 raeburn 9975: if (($actionurl eq '/adm/portfolio') ||
9976: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9977: my ($dirlistref,$listerror) =
9978: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9979: if (ref($dirlistref) eq 'ARRAY') {
9980: foreach my $line (@{$dirlistref}) {
9981: my ($file_name,$rest) = split(/\&/,$line,2);
9982: $currfile{$file_name} = 1;
9983: }
1.984 raeburn 9984: }
1.987 raeburn 9985: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9986: if (opendir(my $dir,$url)) {
1.987 raeburn 9987: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9988: map {$currfile{$_} = 1;} @dir_list;
9989: }
1.1084 raeburn 9990: } elsif (($actionurl eq '/adm/dependencies') ||
9991: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9992: ($args->{'context'} eq 'paste')) ||
9993: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9994: if ($env{'request.course.id'} ne '') {
9995: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9996: if ($dir ne '') {
9997: my ($dirlistref,$listerror) =
9998: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9999: if (ref($dirlistref) eq 'ARRAY') {
10000: foreach my $line (@{$dirlistref}) {
10001: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10002: $size,undef,$mtime)=split(/\&/,$line,12);
10003: unless (($testdir&$dirptr) ||
10004: ($file_name =~ /^\.\.?$/)) {
10005: $currfile{$file_name} = [$size,$mtime];
10006: }
10007: }
10008: }
10009: }
10010: }
1.984 raeburn 10011: }
10012: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10013: if (exists($currfile{$file})) {
1.987 raeburn 10014: unless ($mapping{$file} eq $file) {
10015: $pathchanges{$file} = 1;
10016: }
10017: $existing{$file} = 1;
10018: $numexisting ++;
10019: } else {
1.984 raeburn 10020: $newfiles{$file} = 1;
10021: }
10022: }
1.1071 raeburn 10023: foreach my $file (keys(%currfile)) {
10024: unless (($file eq $filename) ||
10025: ($file eq $filename.'.bak') ||
10026: ($dependencies{$file})) {
1.1085 raeburn 10027: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10028: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10029: next if (($rem ne '') &&
10030: (($env{"httpref.$rem".$file} ne '') ||
10031: (ref($navmap) &&
10032: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10033: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10034: ($navmap->getResourceByUrl($rem.$1)))))));
10035: }
1.1085 raeburn 10036: }
1.1071 raeburn 10037: $unused{$file} = 1;
10038: }
10039: }
1.1084 raeburn 10040: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10041: ($args->{'context'} eq 'paste')) {
10042: $counter = scalar(keys(%existing));
10043: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10044: return ($output,$counter,$numpathchg,\%existing);
10045: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10046: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10047: $counter = scalar(keys(%existing));
10048: $numpathchg = scalar(keys(%pathchanges));
10049: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10050: }
1.984 raeburn 10051: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10052: if ($actionurl eq '/adm/dependencies') {
10053: next if ($embed_file =~ m{^\w+://});
10054: }
1.660 raeburn 10055: $upload_output .= &start_data_table_row().
1.1123 raeburn 10056: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10057: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10058: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10059: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10060: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10061: }
1.1123 raeburn 10062: $upload_output .= '</td>';
1.1071 raeburn 10063: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10064: $upload_output.='<td align="right">'.
10065: '<span class="LC_info LC_fontsize_medium">'.
10066: &mt("URL points to web address").'</span>';
1.987 raeburn 10067: $numremref++;
1.660 raeburn 10068: } elsif ($args->{'error_on_invalid_names'}
10069: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10070: $upload_output.='<td align="right"><span class="LC_warning">'.
10071: &mt('Invalid characters').'</span>';
1.987 raeburn 10072: $numinvalid++;
1.660 raeburn 10073: } else {
1.1123 raeburn 10074: $upload_output .= '<td>'.
10075: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10076: $embed_file,\%mapping,
1.1071 raeburn 10077: $allfiles,$codebase,'upload');
10078: $counter ++;
10079: $numnew ++;
1.987 raeburn 10080: }
10081: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10082: }
10083: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10084: if ($actionurl eq '/adm/dependencies') {
10085: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10086: $modify_output .= &start_data_table_row().
10087: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10088: '<img src="'.&icon($embed_file).'" border="0" />'.
10089: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10090: '<td>'.$size.'</td>'.
10091: '<td>'.$mtime.'</td>'.
10092: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10093: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10094: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10095: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10096: &embedded_file_element('upload_embedded',$counter,
10097: $embed_file,\%mapping,
10098: $allfiles,$codebase,'modify').
10099: '</div></td>'.
10100: &end_data_table_row()."\n";
10101: $counter ++;
10102: } else {
10103: $upload_output .= &start_data_table_row().
1.1123 raeburn 10104: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10105: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10106: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10107: &Apache::loncommon::end_data_table_row()."\n";
10108: }
10109: }
10110: my $delidx = $counter;
10111: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10112: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10113: $delete_output .= &start_data_table_row().
10114: '<td><img src="'.&icon($oldfile).'" />'.
10115: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10116: '<td>'.$size.'</td>'.
10117: '<td>'.$mtime.'</td>'.
10118: '<td><label><input type="checkbox" name="del_upload_dep" '.
10119: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10120: &embedded_file_element('upload_embedded',$delidx,
10121: $oldfile,\%mapping,$allfiles,
10122: $codebase,'delete').'</td>'.
10123: &end_data_table_row()."\n";
10124: $numunused ++;
10125: $delidx ++;
1.987 raeburn 10126: }
10127: if ($upload_output) {
10128: $upload_output = &start_data_table().
10129: $upload_output.
10130: &end_data_table()."\n";
10131: }
1.1071 raeburn 10132: if ($modify_output) {
10133: $modify_output = &start_data_table().
10134: &start_data_table_header_row().
10135: '<th>'.&mt('File').'</th>'.
10136: '<th>'.&mt('Size (KB)').'</th>'.
10137: '<th>'.&mt('Modified').'</th>'.
10138: '<th>'.&mt('Upload replacement?').'</th>'.
10139: &end_data_table_header_row().
10140: $modify_output.
10141: &end_data_table()."\n";
10142: }
10143: if ($delete_output) {
10144: $delete_output = &start_data_table().
10145: &start_data_table_header_row().
10146: '<th>'.&mt('File').'</th>'.
10147: '<th>'.&mt('Size (KB)').'</th>'.
10148: '<th>'.&mt('Modified').'</th>'.
10149: '<th>'.&mt('Delete?').'</th>'.
10150: &end_data_table_header_row().
10151: $delete_output.
10152: &end_data_table()."\n";
10153: }
1.987 raeburn 10154: my $applies = 0;
10155: if ($numremref) {
10156: $applies ++;
10157: }
10158: if ($numinvalid) {
10159: $applies ++;
10160: }
10161: if ($numexisting) {
10162: $applies ++;
10163: }
1.1071 raeburn 10164: if ($counter || $numunused) {
1.987 raeburn 10165: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10166: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10167: $state.'<h3>'.$heading.'</h3>';
10168: if ($actionurl eq '/adm/dependencies') {
10169: if ($numnew) {
10170: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10171: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10172: $upload_output.'<br />'."\n";
10173: }
10174: if ($numexisting) {
10175: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10176: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10177: $modify_output.'<br />'."\n";
10178: $buttontext = &mt('Save changes');
10179: }
10180: if ($numunused) {
10181: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10182: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10183: $delete_output.'<br />'."\n";
10184: $buttontext = &mt('Save changes');
10185: }
10186: } else {
10187: $output .= $upload_output.'<br />'."\n";
10188: }
10189: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10190: $counter.'" />'."\n";
10191: if ($actionurl eq '/adm/dependencies') {
10192: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10193: $numnew.'" />'."\n";
10194: } elsif ($actionurl eq '') {
1.987 raeburn 10195: $output .= '<input type="hidden" name="phase" value="three" />';
10196: }
10197: } elsif ($applies) {
10198: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10199: if ($applies > 1) {
10200: $output .=
1.1123 raeburn 10201: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10202: if ($numremref) {
10203: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10204: }
10205: if ($numinvalid) {
10206: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10207: }
10208: if ($numexisting) {
10209: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10210: }
10211: $output .= '</ul><br />';
10212: } elsif ($numremref) {
10213: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10214: } elsif ($numinvalid) {
10215: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10216: } elsif ($numexisting) {
10217: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10218: }
10219: $output .= $upload_output.'<br />';
10220: }
10221: my ($pathchange_output,$chgcount);
1.1071 raeburn 10222: $chgcount = $counter;
1.987 raeburn 10223: if (keys(%pathchanges) > 0) {
10224: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10225: if ($counter) {
1.987 raeburn 10226: $output .= &embedded_file_element('pathchange',$chgcount,
10227: $embed_file,\%mapping,
1.1071 raeburn 10228: $allfiles,$codebase,'change');
1.987 raeburn 10229: } else {
10230: $pathchange_output .=
10231: &start_data_table_row().
10232: '<td><input type ="checkbox" name="namechange" value="'.
10233: $chgcount.'" checked="checked" /></td>'.
10234: '<td>'.$mapping{$embed_file}.'</td>'.
10235: '<td>'.$embed_file.
10236: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10237: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10238: '</td>'.&end_data_table_row();
1.660 raeburn 10239: }
1.987 raeburn 10240: $numpathchg ++;
10241: $chgcount ++;
1.660 raeburn 10242: }
10243: }
1.1127 raeburn 10244: if (($counter) || ($numunused)) {
1.987 raeburn 10245: if ($numpathchg) {
10246: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10247: $numpathchg.'" />'."\n";
10248: }
10249: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10250: ($actionurl eq '/adm/imsimport')) {
10251: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10252: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10253: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10254: } elsif ($actionurl eq '/adm/dependencies') {
10255: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10256: }
1.1123 raeburn 10257: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10258: } elsif ($numpathchg) {
10259: my %pathchange = ();
10260: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10261: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10262: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10263: }
1.987 raeburn 10264: }
1.1071 raeburn 10265: return ($output,$counter,$numpathchg);
1.987 raeburn 10266: }
10267:
10268: sub embedded_file_element {
1.1071 raeburn 10269: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10270: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10271: (ref($codebase) eq 'HASH'));
10272: my $output;
1.1071 raeburn 10273: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10274: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10275: }
10276: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10277: &escape($embed_file).'" />';
10278: unless (($context eq 'upload_embedded') &&
10279: ($mapping->{$embed_file} eq $embed_file)) {
10280: $output .='
10281: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10282: }
10283: my $attrib;
10284: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10285: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10286: }
10287: $output .=
10288: "\n\t\t".
10289: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10290: $attrib.'" />';
10291: if (exists($codebase->{$mapping->{$embed_file}})) {
10292: $output .=
10293: "\n\t\t".
10294: '<input name="codebase_'.$num.'" type="hidden" value="'.
10295: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10296: }
1.987 raeburn 10297: return $output;
1.660 raeburn 10298: }
10299:
1.1071 raeburn 10300: sub get_dependency_details {
10301: my ($currfile,$currsubfile,$embed_file) = @_;
10302: my ($size,$mtime,$showsize,$showmtime);
10303: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10304: if ($embed_file =~ m{/}) {
10305: my ($path,$fname) = split(/\//,$embed_file);
10306: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10307: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10308: }
10309: } else {
10310: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10311: ($size,$mtime) = @{$currfile->{$embed_file}};
10312: }
10313: }
10314: $showsize = $size/1024.0;
10315: $showsize = sprintf("%.1f",$showsize);
10316: if ($mtime > 0) {
10317: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10318: }
10319: }
10320: return ($showsize,$showmtime);
10321: }
10322:
10323: sub ask_embedded_js {
10324: return <<"END";
10325: <script type="text/javascript"">
10326: // <![CDATA[
10327: function toggleBrowse(counter) {
10328: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10329: var fileid = document.getElementById('embedded_item_'+counter);
10330: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10331: if (chkboxid.checked == true) {
10332: uploaddivid.style.display='block';
10333: } else {
10334: uploaddivid.style.display='none';
10335: fileid.value = '';
10336: }
10337: }
10338: // ]]>
10339: </script>
10340:
10341: END
10342: }
10343:
1.661 raeburn 10344: sub upload_embedded {
10345: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10346: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10347: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10348: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10349: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10350: my $orig_uploaded_filename =
10351: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10352: foreach my $type ('orig','ref','attrib','codebase') {
10353: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10354: $env{'form.embedded_'.$type.'_'.$i} =
10355: &unescape($env{'form.embedded_'.$type.'_'.$i});
10356: }
10357: }
1.661 raeburn 10358: my ($path,$fname) =
10359: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10360: # no path, whole string is fname
10361: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10362: $fname = &Apache::lonnet::clean_filename($fname);
10363: # See if there is anything left
10364: next if ($fname eq '');
10365:
10366: # Check if file already exists as a file or directory.
10367: my ($state,$msg);
10368: if ($context eq 'portfolio') {
10369: my $port_path = $dirpath;
10370: if ($group ne '') {
10371: $port_path = "groups/$group/$port_path";
10372: }
1.987 raeburn 10373: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10374: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10375: $dir_root,$port_path,$disk_quota,
10376: $current_disk_usage,$uname,$udom);
10377: if ($state eq 'will_exceed_quota'
1.984 raeburn 10378: || $state eq 'file_locked') {
1.661 raeburn 10379: $output .= $msg;
10380: next;
10381: }
10382: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10383: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10384: if ($state eq 'exists') {
10385: $output .= $msg;
10386: next;
10387: }
10388: }
10389: # Check if extension is valid
10390: if (($fname =~ /\.(\w+)$/) &&
10391: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10392: $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 10393: next;
10394: } elsif (($fname =~ /\.(\w+)$/) &&
10395: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10396: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10397: next;
10398: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10399: $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 10400: next;
10401: }
10402: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10403: my $subdir = $path;
10404: $subdir =~ s{/+$}{};
1.661 raeburn 10405: if ($context eq 'portfolio') {
1.984 raeburn 10406: my $result;
10407: if ($state eq 'existingfile') {
10408: $result=
10409: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10410: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10411: } else {
1.984 raeburn 10412: $result=
10413: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10414: $dirpath.
1.1123 raeburn 10415: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10416: if ($result !~ m|^/uploaded/|) {
10417: $output .= '<span class="LC_error">'
10418: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10419: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10420: .'</span><br />';
10421: next;
10422: } else {
1.987 raeburn 10423: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10424: $path.$fname.'</span>').'<br />';
1.984 raeburn 10425: }
1.661 raeburn 10426: }
1.1123 raeburn 10427: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10428: my $extendedsubdir = $dirpath.'/'.$subdir;
10429: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10430: my $result =
1.1126 raeburn 10431: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10432: if ($result !~ m|^/uploaded/|) {
10433: $output .= '<span class="LC_error">'
10434: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10435: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10436: .'</span><br />';
10437: next;
10438: } else {
10439: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10440: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10441: if ($context eq 'syllabus') {
10442: &Apache::lonnet::make_public_indefinitely($result);
10443: }
1.987 raeburn 10444: }
1.661 raeburn 10445: } else {
10446: # Save the file
10447: my $target = $env{'form.embedded_item_'.$i};
10448: my $fullpath = $dir_root.$dirpath.'/'.$path;
10449: my $dest = $fullpath.$fname;
10450: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10451: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10452: my $count;
10453: my $filepath = $dir_root;
1.1027 raeburn 10454: foreach my $subdir (@parts) {
10455: $filepath .= "/$subdir";
10456: if (!-e $filepath) {
1.661 raeburn 10457: mkdir($filepath,0770);
10458: }
10459: }
10460: my $fh;
10461: if (!open($fh,'>'.$dest)) {
10462: &Apache::lonnet::logthis('Failed to create '.$dest);
10463: $output .= '<span class="LC_error">'.
1.1071 raeburn 10464: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10465: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10466: '</span><br />';
10467: } else {
10468: if (!print $fh $env{'form.embedded_item_'.$i}) {
10469: &Apache::lonnet::logthis('Failed to write to '.$dest);
10470: $output .= '<span class="LC_error">'.
1.1071 raeburn 10471: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10472: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10473: '</span><br />';
10474: } else {
1.987 raeburn 10475: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10476: $url.'</span>').'<br />';
10477: unless ($context eq 'testbank') {
10478: $footer .= &mt('View embedded file: [_1]',
10479: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10480: }
10481: }
10482: close($fh);
10483: }
10484: }
10485: if ($env{'form.embedded_ref_'.$i}) {
10486: $pathchange{$i} = 1;
10487: }
10488: }
10489: if ($output) {
10490: $output = '<p>'.$output.'</p>';
10491: }
10492: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10493: $returnflag = 'ok';
1.1071 raeburn 10494: my $numpathchgs = scalar(keys(%pathchange));
10495: if ($numpathchgs > 0) {
1.987 raeburn 10496: if ($context eq 'portfolio') {
10497: $output .= '<p>'.&mt('or').'</p>';
10498: } elsif ($context eq 'testbank') {
1.1071 raeburn 10499: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10500: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10501: $returnflag = 'modify_orightml';
10502: }
10503: }
1.1071 raeburn 10504: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10505: }
10506:
10507: sub modify_html_form {
10508: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10509: my $end = 0;
10510: my $modifyform;
10511: if ($context eq 'upload_embedded') {
10512: return unless (ref($pathchange) eq 'HASH');
10513: if ($env{'form.number_embedded_items'}) {
10514: $end += $env{'form.number_embedded_items'};
10515: }
10516: if ($env{'form.number_pathchange_items'}) {
10517: $end += $env{'form.number_pathchange_items'};
10518: }
10519: if ($end) {
10520: for (my $i=0; $i<$end; $i++) {
10521: if ($i < $env{'form.number_embedded_items'}) {
10522: next unless($pathchange->{$i});
10523: }
10524: $modifyform .=
10525: &start_data_table_row().
10526: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10527: 'checked="checked" /></td>'.
10528: '<td>'.$env{'form.embedded_ref_'.$i}.
10529: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10530: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10531: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10532: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10533: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10534: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10535: '<td>'.$env{'form.embedded_orig_'.$i}.
10536: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10537: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10538: &end_data_table_row();
1.1071 raeburn 10539: }
1.987 raeburn 10540: }
10541: } else {
10542: $modifyform = $pathchgtable;
10543: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10544: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10545: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10546: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10547: }
10548: }
10549: if ($modifyform) {
1.1071 raeburn 10550: if ($actionurl eq '/adm/dependencies') {
10551: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10552: }
1.987 raeburn 10553: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10554: '<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".
10555: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10556: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10557: '</ol></p>'."\n".'<p>'.
10558: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10559: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10560: &start_data_table()."\n".
10561: &start_data_table_header_row().
10562: '<th>'.&mt('Change?').'</th>'.
10563: '<th>'.&mt('Current reference').'</th>'.
10564: '<th>'.&mt('Required reference').'</th>'.
10565: &end_data_table_header_row()."\n".
10566: $modifyform.
10567: &end_data_table().'<br />'."\n".$hiddenstate.
10568: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10569: '</form>'."\n";
10570: }
10571: return;
10572: }
10573:
10574: sub modify_html_refs {
1.1123 raeburn 10575: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10576: my $container;
10577: if ($context eq 'portfolio') {
10578: $container = $env{'form.container'};
10579: } elsif ($context eq 'coursedoc') {
10580: $container = $env{'form.primaryurl'};
1.1071 raeburn 10581: } elsif ($context eq 'manage_dependencies') {
10582: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10583: $container = "/$container";
1.1123 raeburn 10584: } elsif ($context eq 'syllabus') {
10585: $container = $url;
1.987 raeburn 10586: } else {
1.1027 raeburn 10587: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10588: }
10589: my (%allfiles,%codebase,$output,$content);
10590: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10591: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10592: if (wantarray) {
10593: return ('',0,0);
10594: } else {
10595: return;
10596: }
10597: }
10598: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10599: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10600: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10601: if (wantarray) {
10602: return ('',0,0);
10603: } else {
10604: return;
10605: }
10606: }
1.987 raeburn 10607: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10608: if ($content eq '-1') {
10609: if (wantarray) {
10610: return ('',0,0);
10611: } else {
10612: return;
10613: }
10614: }
1.987 raeburn 10615: } else {
1.1071 raeburn 10616: unless ($container =~ /^\Q$dir_root\E/) {
10617: if (wantarray) {
10618: return ('',0,0);
10619: } else {
10620: return;
10621: }
10622: }
1.987 raeburn 10623: if (open(my $fh,"<$container")) {
10624: $content = join('', <$fh>);
10625: close($fh);
10626: } else {
1.1071 raeburn 10627: if (wantarray) {
10628: return ('',0,0);
10629: } else {
10630: return;
10631: }
1.987 raeburn 10632: }
10633: }
10634: my ($count,$codebasecount) = (0,0);
10635: my $mm = new File::MMagic;
10636: my $mime_type = $mm->checktype_contents($content);
10637: if ($mime_type eq 'text/html') {
10638: my $parse_result =
10639: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10640: \%codebase,\$content);
10641: if ($parse_result eq 'ok') {
10642: foreach my $i (@changes) {
10643: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10644: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10645: if ($allfiles{$ref}) {
10646: my $newname = $orig;
10647: my ($attrib_regexp,$codebase);
1.1006 raeburn 10648: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10649: if ($attrib_regexp =~ /:/) {
10650: $attrib_regexp =~ s/\:/|/g;
10651: }
10652: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10653: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10654: $count += $numchg;
1.1123 raeburn 10655: $allfiles{$newname} = $allfiles{$ref};
1.987 raeburn 10656: }
10657: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10658: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10659: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10660: $codebasecount ++;
10661: }
10662: }
10663: }
1.1123 raeburn 10664: my $skiprewrites;
1.987 raeburn 10665: if ($count || $codebasecount) {
10666: my $saveresult;
1.1071 raeburn 10667: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10668: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10669: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10670: if ($url eq $container) {
10671: my ($fname) = ($container =~ m{/([^/]+)$});
10672: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10673: $count,'<span class="LC_filename">'.
1.1071 raeburn 10674: $fname.'</span>').'</p>';
1.987 raeburn 10675: } else {
10676: $output = '<p class="LC_error">'.
10677: &mt('Error: update failed for: [_1].',
10678: '<span class="LC_filename">'.
10679: $container.'</span>').'</p>';
10680: }
1.1123 raeburn 10681: if ($context eq 'syllabus') {
10682: unless ($saveresult eq 'ok') {
10683: $skiprewrites = 1;
10684: }
10685: }
1.987 raeburn 10686: } else {
10687: if (open(my $fh,">$container")) {
10688: print $fh $content;
10689: close($fh);
10690: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10691: $count,'<span class="LC_filename">'.
10692: $container.'</span>').'</p>';
1.661 raeburn 10693: } else {
1.987 raeburn 10694: $output = '<p class="LC_error">'.
10695: &mt('Error: could not update [_1].',
10696: '<span class="LC_filename">'.
10697: $container.'</span>').'</p>';
1.661 raeburn 10698: }
10699: }
10700: }
1.1123 raeburn 10701: if (($context eq 'syllabus') && (!$skiprewrites)) {
10702: my ($actionurl,$state);
10703: $actionurl = "/public/$udom/$uname/syllabus";
10704: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10705: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10706: \%codebase,
10707: {'context' => 'rewrites',
10708: 'ignore_remote_references' => 1,});
10709: if (ref($mapping) eq 'HASH') {
10710: my $rewrites = 0;
10711: foreach my $key (keys(%{$mapping})) {
10712: next if ($key =~ m{^https?://});
10713: my $ref = $mapping->{$key};
10714: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10715: my $attrib;
10716: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10717: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10718: }
10719: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10720: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10721: $rewrites += $numchg;
10722: }
10723: }
10724: if ($rewrites) {
10725: my $saveresult;
10726: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10727: if ($url eq $container) {
10728: my ($fname) = ($container =~ m{/([^/]+)$});
10729: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10730: $count,'<span class="LC_filename">'.
10731: $fname.'</span>').'</p>';
10732: } else {
10733: $output .= '<p class="LC_error">'.
10734: &mt('Error: could not update links in [_1].',
10735: '<span class="LC_filename">'.
10736: $container.'</span>').'</p>';
10737:
10738: }
10739: }
10740: }
10741: }
1.987 raeburn 10742: } else {
10743: &logthis('Failed to parse '.$container.
10744: ' to modify references: '.$parse_result);
1.661 raeburn 10745: }
10746: }
1.1071 raeburn 10747: if (wantarray) {
10748: return ($output,$count,$codebasecount);
10749: } else {
10750: return $output;
10751: }
1.661 raeburn 10752: }
10753:
10754: sub check_for_existing {
10755: my ($path,$fname,$element) = @_;
10756: my ($state,$msg);
10757: if (-d $path.'/'.$fname) {
10758: $state = 'exists';
10759: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10760: } elsif (-e $path.'/'.$fname) {
10761: $state = 'exists';
10762: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10763: }
10764: if ($state eq 'exists') {
10765: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10766: }
10767: return ($state,$msg);
10768: }
10769:
10770: sub check_for_upload {
10771: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10772: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10773: my $filesize = length($env{'form.'.$element});
10774: if (!$filesize) {
10775: my $msg = '<span class="LC_error">'.
10776: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10777: '<span class="LC_filename">'.$fname.'</span>',
10778: $filesize).'<br />'.
1.1007 raeburn 10779: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10780: '</span>';
10781: return ('zero_bytes',$msg);
10782: }
10783: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10784: my $getpropath = 1;
1.1021 raeburn 10785: my ($dirlistref,$listerror) =
10786: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10787: my $found_file = 0;
10788: my $locked_file = 0;
1.991 raeburn 10789: my @lockers;
10790: my $navmap;
10791: if ($env{'request.course.id'}) {
10792: $navmap = Apache::lonnavmaps::navmap->new();
10793: }
1.1021 raeburn 10794: if (ref($dirlistref) eq 'ARRAY') {
10795: foreach my $line (@{$dirlistref}) {
10796: my ($file_name,$rest)=split(/\&/,$line,2);
10797: if ($file_name eq $fname){
10798: $file_name = $path.$file_name;
10799: if ($group ne '') {
10800: $file_name = $group.$file_name;
10801: }
10802: $found_file = 1;
10803: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10804: foreach my $lock (@lockers) {
10805: if (ref($lock) eq 'ARRAY') {
10806: my ($symb,$crsid) = @{$lock};
10807: if ($crsid eq $env{'request.course.id'}) {
10808: if (ref($navmap)) {
10809: my $res = $navmap->getBySymb($symb);
10810: foreach my $part (@{$res->parts()}) {
10811: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10812: unless (($slot_status == $res->RESERVED) ||
10813: ($slot_status == $res->RESERVED_LOCATION)) {
10814: $locked_file = 1;
10815: }
1.991 raeburn 10816: }
1.1021 raeburn 10817: } else {
10818: $locked_file = 1;
1.991 raeburn 10819: }
10820: } else {
10821: $locked_file = 1;
10822: }
10823: }
1.1021 raeburn 10824: }
10825: } else {
10826: my @info = split(/\&/,$rest);
10827: my $currsize = $info[6]/1000;
10828: if ($currsize < $filesize) {
10829: my $extra = $filesize - $currsize;
10830: if (($current_disk_usage + $extra) > $disk_quota) {
10831: my $msg = '<span class="LC_error">'.
10832: &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.',
10833: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10834: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10835: $disk_quota,$current_disk_usage);
10836: return ('will_exceed_quota',$msg);
10837: }
1.984 raeburn 10838: }
10839: }
1.661 raeburn 10840: }
10841: }
10842: }
10843: if (($current_disk_usage + $filesize) > $disk_quota){
10844: my $msg = '<span class="LC_error">'.
10845: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10846: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10847: return ('will_exceed_quota',$msg);
10848: } elsif ($found_file) {
10849: if ($locked_file) {
10850: my $msg = '<span class="LC_error">';
10851: $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>');
10852: $msg .= '</span><br />';
10853: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10854: return ('file_locked',$msg);
10855: } else {
10856: my $msg = '<span class="LC_error">';
1.984 raeburn 10857: $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 10858: $msg .= '</span>';
1.984 raeburn 10859: return ('existingfile',$msg);
1.661 raeburn 10860: }
10861: }
10862: }
10863:
1.987 raeburn 10864: sub check_for_traversal {
10865: my ($path,$url,$toplevel) = @_;
10866: my @parts=split(/\//,$path);
10867: my $cleanpath;
10868: my $fullpath = $url;
10869: for (my $i=0;$i<@parts;$i++) {
10870: next if ($parts[$i] eq '.');
10871: if ($parts[$i] eq '..') {
10872: $fullpath =~ s{([^/]+/)$}{};
10873: } else {
10874: $fullpath .= $parts[$i].'/';
10875: }
10876: }
10877: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10878: $cleanpath = $1;
10879: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10880: my $curr_toprel = $1;
10881: my @parts = split(/\//,$curr_toprel);
10882: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10883: my @urlparts = split(/\//,$url_toprel);
10884: my $doubledots;
10885: my $startdiff = -1;
10886: for (my $i=0; $i<@urlparts; $i++) {
10887: if ($startdiff == -1) {
10888: unless ($urlparts[$i] eq $parts[$i]) {
10889: $startdiff = $i;
10890: $doubledots .= '../';
10891: }
10892: } else {
10893: $doubledots .= '../';
10894: }
10895: }
10896: if ($startdiff > -1) {
10897: $cleanpath = $doubledots;
10898: for (my $i=$startdiff; $i<@parts; $i++) {
10899: $cleanpath .= $parts[$i].'/';
10900: }
10901: }
10902: }
10903: $cleanpath =~ s{(/)$}{};
10904: return $cleanpath;
10905: }
1.31 albertel 10906:
1.1053 raeburn 10907: sub is_archive_file {
10908: my ($mimetype) = @_;
10909: if (($mimetype eq 'application/octet-stream') ||
10910: ($mimetype eq 'application/x-stuffit') ||
10911: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10912: return 1;
10913: }
10914: return;
10915: }
10916:
10917: sub decompress_form {
1.1065 raeburn 10918: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10919: my %lt = &Apache::lonlocal::texthash (
10920: this => 'This file is an archive file.',
1.1067 raeburn 10921: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10922: itsc => 'Its contents are as follows:',
1.1053 raeburn 10923: youm => 'You may wish to extract its contents.',
10924: extr => 'Extract contents',
1.1067 raeburn 10925: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10926: proa => 'Process automatically?',
1.1053 raeburn 10927: yes => 'Yes',
10928: no => 'No',
1.1067 raeburn 10929: fold => 'Title for folder containing movie',
10930: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10931: );
1.1065 raeburn 10932: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10933: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10934: my $info = &list_archive_contents($fileloc,\@paths);
10935: if (@paths) {
10936: foreach my $path (@paths) {
10937: $path =~ s{^/}{};
1.1067 raeburn 10938: if ($path =~ m{^([^/]+)/$}) {
10939: $topdir = $1;
10940: }
1.1065 raeburn 10941: if ($path =~ m{^([^/]+)/}) {
10942: $toplevel{$1} = $path;
10943: } else {
10944: $toplevel{$path} = $path;
10945: }
10946: }
10947: }
1.1067 raeburn 10948: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10949: my @camtasia = ("$topdir/","$topdir/index.html",
10950: "$topdir/media/",
10951: "$topdir/media/$topdir.mp4",
10952: "$topdir/media/FirstFrame.png",
10953: "$topdir/media/player.swf",
10954: "$topdir/media/swfobject.js",
10955: "$topdir/media/expressInstall.swf");
10956: my @diffs = &compare_arrays(\@paths,\@camtasia);
10957: if (@diffs == 0) {
10958: $is_camtasia = 1;
10959: }
10960: }
10961: my $output;
10962: if ($is_camtasia) {
10963: $output = <<"ENDCAM";
10964: <script type="text/javascript" language="Javascript">
10965: // <![CDATA[
10966:
10967: function camtasiaToggle() {
10968: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10969: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10970: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10971:
10972: document.getElementById('camtasia_titles').style.display='block';
10973: } else {
10974: document.getElementById('camtasia_titles').style.display='none';
10975: }
10976: }
10977: }
10978: return;
10979: }
10980:
10981: // ]]>
10982: </script>
10983: <p>$lt{'camt'}</p>
10984: ENDCAM
1.1065 raeburn 10985: } else {
1.1067 raeburn 10986: $output = '<p>'.$lt{'this'};
10987: if ($info eq '') {
10988: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10989: } else {
10990: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10991: '<div><pre>'.$info.'</pre></div>';
10992: }
1.1065 raeburn 10993: }
1.1067 raeburn 10994: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10995: my $duplicates;
10996: my $num = 0;
10997: if (ref($dirlist) eq 'ARRAY') {
10998: foreach my $item (@{$dirlist}) {
10999: if (ref($item) eq 'ARRAY') {
11000: if (exists($toplevel{$item->[0]})) {
11001: $duplicates .=
11002: &start_data_table_row().
11003: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11004: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11005: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11006: 'value="1" />'.&mt('Yes').'</label>'.
11007: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11008: '<td>'.$item->[0].'</td>';
11009: if ($item->[2]) {
11010: $duplicates .= '<td>'.&mt('Directory').'</td>';
11011: } else {
11012: $duplicates .= '<td>'.&mt('File').'</td>';
11013: }
11014: $duplicates .= '<td>'.$item->[3].'</td>'.
11015: '<td>'.
11016: &Apache::lonlocal::locallocaltime($item->[4]).
11017: '</td>'.
11018: &end_data_table_row();
11019: $num ++;
11020: }
11021: }
11022: }
11023: }
11024: my $itemcount;
11025: if (@paths > 0) {
11026: $itemcount = scalar(@paths);
11027: } else {
11028: $itemcount = 1;
11029: }
1.1067 raeburn 11030: if ($is_camtasia) {
11031: $output .= $lt{'auto'}.'<br />'.
11032: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
11033: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
11034: $lt{'yes'}.'</label> <label>'.
11035: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11036: $lt{'no'}.'</label></span><br />'.
11037: '<div id="camtasia_titles" style="display:block">'.
11038: &Apache::lonhtmlcommon::start_pick_box().
11039: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11040: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11041: &Apache::lonhtmlcommon::row_closure().
11042: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11043: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11044: &Apache::lonhtmlcommon::row_closure(1).
11045: &Apache::lonhtmlcommon::end_pick_box().
11046: '</div>';
11047: }
1.1065 raeburn 11048: $output .=
11049: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11050: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11051: "\n";
1.1065 raeburn 11052: if ($duplicates ne '') {
11053: $output .= '<p><span class="LC_warning">'.
11054: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11055: &start_data_table().
11056: &start_data_table_header_row().
11057: '<th>'.&mt('Overwrite?').'</th>'.
11058: '<th>'.&mt('Name').'</th>'.
11059: '<th>'.&mt('Type').'</th>'.
11060: '<th>'.&mt('Size').'</th>'.
11061: '<th>'.&mt('Last modified').'</th>'.
11062: &end_data_table_header_row().
11063: $duplicates.
11064: &end_data_table().
11065: '</p>';
11066: }
1.1067 raeburn 11067: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11068: if (ref($hiddenelements) eq 'HASH') {
11069: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11070: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11071: }
11072: }
11073: $output .= <<"END";
1.1067 raeburn 11074: <br />
1.1053 raeburn 11075: <input type="submit" name="decompress" value="$lt{'extr'}" />
11076: </form>
11077: $noextract
11078: END
11079: return $output;
11080: }
11081:
1.1065 raeburn 11082: sub decompression_utility {
11083: my ($program) = @_;
11084: my @utilities = ('tar','gunzip','bunzip2','unzip');
11085: my $location;
11086: if (grep(/^\Q$program\E$/,@utilities)) {
11087: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11088: '/usr/sbin/') {
11089: if (-x $dir.$program) {
11090: $location = $dir.$program;
11091: last;
11092: }
11093: }
11094: }
11095: return $location;
11096: }
11097:
11098: sub list_archive_contents {
11099: my ($file,$pathsref) = @_;
11100: my (@cmd,$output);
11101: my $needsregexp;
11102: if ($file =~ /\.zip$/) {
11103: @cmd = (&decompression_utility('unzip'),"-l");
11104: $needsregexp = 1;
11105: } elsif (($file =~ m/\.tar\.gz$/) ||
11106: ($file =~ /\.tgz$/)) {
11107: @cmd = (&decompression_utility('tar'),"-ztf");
11108: } elsif ($file =~ /\.tar\.bz2$/) {
11109: @cmd = (&decompression_utility('tar'),"-jtf");
11110: } elsif ($file =~ m|\.tar$|) {
11111: @cmd = (&decompression_utility('tar'),"-tf");
11112: }
11113: if (@cmd) {
11114: undef($!);
11115: undef($@);
11116: if (open(my $fh,"-|", @cmd, $file)) {
11117: while (my $line = <$fh>) {
11118: $output .= $line;
11119: chomp($line);
11120: my $item;
11121: if ($needsregexp) {
11122: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11123: } else {
11124: $item = $line;
11125: }
11126: if ($item ne '') {
11127: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11128: push(@{$pathsref},$item);
11129: }
11130: }
11131: }
11132: close($fh);
11133: }
11134: }
11135: return $output;
11136: }
11137:
1.1053 raeburn 11138: sub decompress_uploaded_file {
11139: my ($file,$dir) = @_;
11140: &Apache::lonnet::appenv({'cgi.file' => $file});
11141: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11142: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11143: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11144: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11145: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11146: my $decompressed = $env{'cgi.decompressed'};
11147: &Apache::lonnet::delenv('cgi.file');
11148: &Apache::lonnet::delenv('cgi.dir');
11149: &Apache::lonnet::delenv('cgi.decompressed');
11150: return ($decompressed,$result);
11151: }
11152:
1.1055 raeburn 11153: sub process_decompression {
11154: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11155: my ($dir,$error,$warning,$output);
11156: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1120 bisitz 11157: $error = &mt('Filename not a supported archive file type.').
11158: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11159: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11160: } else {
11161: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11162: if ($docuhome eq 'no_host') {
11163: $error = &mt('Could not determine home server for course.');
11164: } else {
11165: my @ids=&Apache::lonnet::current_machine_ids();
11166: my $currdir = "$dir_root/$destination";
11167: if (grep(/^\Q$docuhome\E$/,@ids)) {
11168: $dir = &LONCAPA::propath($docudom,$docuname).
11169: "$dir_root/$destination";
11170: } else {
11171: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11172: "$dir_root/$docudom/$docuname/$destination";
11173: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11174: $error = &mt('Archive file not found.');
11175: }
11176: }
1.1065 raeburn 11177: my (@to_overwrite,@to_skip);
11178: if ($env{'form.archive_overwrite_total'} > 0) {
11179: my $total = $env{'form.archive_overwrite_total'};
11180: for (my $i=0; $i<$total; $i++) {
11181: if ($env{'form.archive_overwrite_'.$i} == 1) {
11182: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11183: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11184: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11185: }
11186: }
11187: }
11188: my $numskip = scalar(@to_skip);
11189: if (($numskip > 0) &&
11190: ($numskip == $env{'form.archive_itemcount'})) {
11191: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11192: } elsif ($dir eq '') {
1.1055 raeburn 11193: $error = &mt('Directory containing archive file unavailable.');
11194: } elsif (!$error) {
1.1065 raeburn 11195: my ($decompressed,$display);
11196: if ($numskip > 0) {
11197: my $tempdir = time.'_'.$$.int(rand(10000));
11198: mkdir("$dir/$tempdir",0755);
11199: system("mv $dir/$file $dir/$tempdir/$file");
11200: ($decompressed,$display) =
11201: &decompress_uploaded_file($file,"$dir/$tempdir");
11202: foreach my $item (@to_skip) {
11203: if (($item ne '') && ($item !~ /\.\./)) {
11204: if (-f "$dir/$tempdir/$item") {
11205: unlink("$dir/$tempdir/$item");
11206: } elsif (-d "$dir/$tempdir/$item") {
11207: system("rm -rf $dir/$tempdir/$item");
11208: }
11209: }
11210: }
11211: system("mv $dir/$tempdir/* $dir");
11212: rmdir("$dir/$tempdir");
11213: } else {
11214: ($decompressed,$display) =
11215: &decompress_uploaded_file($file,$dir);
11216: }
1.1055 raeburn 11217: if ($decompressed eq 'ok') {
1.1065 raeburn 11218: $output = '<p class="LC_info">'.
11219: &mt('Files extracted successfully from archive.').
11220: '</p>'."\n";
1.1055 raeburn 11221: my ($warning,$result,@contents);
11222: my ($newdirlistref,$newlisterror) =
11223: &Apache::lonnet::dirlist($currdir,$docudom,
11224: $docuname,1);
11225: my (%is_dir,%changes,@newitems);
11226: my $dirptr = 16384;
1.1065 raeburn 11227: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11228: foreach my $dir_line (@{$newdirlistref}) {
11229: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11230: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11231: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11232: push(@newitems,$item);
11233: if ($dirptr&$testdir) {
11234: $is_dir{$item} = 1;
11235: }
11236: $changes{$item} = 1;
11237: }
11238: }
11239: }
11240: if (keys(%changes) > 0) {
11241: foreach my $item (sort(@newitems)) {
11242: if ($changes{$item}) {
11243: push(@contents,$item);
11244: }
11245: }
11246: }
11247: if (@contents > 0) {
1.1067 raeburn 11248: my $wantform;
11249: unless ($env{'form.autoextract_camtasia'}) {
11250: $wantform = 1;
11251: }
1.1056 raeburn 11252: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11253: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11254: $currdir,\%is_dir,
11255: \%children,\%parent,
1.1056 raeburn 11256: \@contents,\%dirorder,
11257: \%titles,$wantform);
1.1055 raeburn 11258: if ($datatable ne '') {
11259: $output .= &archive_options_form('decompressed',$datatable,
11260: $count,$hiddenelem);
1.1065 raeburn 11261: my $startcount = 6;
1.1055 raeburn 11262: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11263: \%titles,\%children);
1.1055 raeburn 11264: }
1.1067 raeburn 11265: if ($env{'form.autoextract_camtasia'}) {
11266: my %displayed;
11267: my $total = 1;
11268: $env{'form.archive_directory'} = [];
11269: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11270: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11271: $path =~ s{/$}{};
11272: my $item;
11273: if ($path ne '') {
11274: $item = "$path/$titles{$i}";
11275: } else {
11276: $item = $titles{$i};
11277: }
11278: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11279: if ($item eq $contents[0]) {
11280: push(@{$env{'form.archive_directory'}},$i);
11281: $env{'form.archive_'.$i} = 'display';
11282: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11283: $displayed{'folder'} = $i;
11284: } elsif ($item eq "$contents[0]/index.html") {
11285: $env{'form.archive_'.$i} = 'display';
11286: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11287: $displayed{'web'} = $i;
11288: } else {
11289: if ($item eq "$contents[0]/media") {
11290: push(@{$env{'form.archive_directory'}},$i);
11291: }
11292: $env{'form.archive_'.$i} = 'dependency';
11293: }
11294: $total ++;
11295: }
11296: for (my $i=1; $i<$total; $i++) {
11297: next if ($i == $displayed{'web'});
11298: next if ($i == $displayed{'folder'});
11299: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11300: }
11301: $env{'form.phase'} = 'decompress_cleanup';
11302: $env{'form.archivedelete'} = 1;
11303: $env{'form.archive_count'} = $total-1;
11304: $output .=
11305: &process_extracted_files('coursedocs',$docudom,
11306: $docuname,$destination,
11307: $dir_root,$hiddenelem);
11308: }
1.1055 raeburn 11309: } else {
11310: $warning = &mt('No new items extracted from archive file.');
11311: }
11312: } else {
11313: $output = $display;
11314: $error = &mt('An error occurred during extraction from the archive file.');
11315: }
11316: }
11317: }
11318: }
11319: if ($error) {
11320: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11321: $error.'</p>'."\n";
11322: }
11323: if ($warning) {
11324: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11325: }
11326: return $output;
11327: }
11328:
11329: sub get_extracted {
1.1056 raeburn 11330: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11331: $titles,$wantform) = @_;
1.1055 raeburn 11332: my $count = 0;
11333: my $depth = 0;
11334: my $datatable;
1.1056 raeburn 11335: my @hierarchy;
1.1055 raeburn 11336: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11337: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11338: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11339: foreach my $item (@{$contents}) {
11340: $count ++;
1.1056 raeburn 11341: @{$dirorder->{$count}} = @hierarchy;
11342: $titles->{$count} = $item;
1.1055 raeburn 11343: &archive_hierarchy($depth,$count,$parent,$children);
11344: if ($wantform) {
11345: $datatable .= &archive_row($is_dir->{$item},$item,
11346: $currdir,$depth,$count);
11347: }
11348: if ($is_dir->{$item}) {
11349: $depth ++;
1.1056 raeburn 11350: push(@hierarchy,$count);
11351: $parent->{$depth} = $count;
1.1055 raeburn 11352: $datatable .=
11353: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11354: \$depth,\$count,\@hierarchy,$dirorder,
11355: $children,$parent,$titles,$wantform);
1.1055 raeburn 11356: $depth --;
1.1056 raeburn 11357: pop(@hierarchy);
1.1055 raeburn 11358: }
11359: }
11360: return ($count,$datatable);
11361: }
11362:
11363: sub recurse_extracted_archive {
1.1056 raeburn 11364: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11365: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11366: my $result='';
1.1056 raeburn 11367: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11368: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11369: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11370: return $result;
11371: }
11372: my $dirptr = 16384;
11373: my ($newdirlistref,$newlisterror) =
11374: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11375: if (ref($newdirlistref) eq 'ARRAY') {
11376: foreach my $dir_line (@{$newdirlistref}) {
11377: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11378: unless ($item =~ /^\.+$/) {
11379: $$count ++;
1.1056 raeburn 11380: @{$dirorder->{$$count}} = @{$hierarchy};
11381: $titles->{$$count} = $item;
1.1055 raeburn 11382: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11383:
1.1055 raeburn 11384: my $is_dir;
11385: if ($dirptr&$testdir) {
11386: $is_dir = 1;
11387: }
11388: if ($wantform) {
11389: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11390: }
11391: if ($is_dir) {
11392: $$depth ++;
1.1056 raeburn 11393: push(@{$hierarchy},$$count);
11394: $parent->{$$depth} = $$count;
1.1055 raeburn 11395: $result .=
11396: &recurse_extracted_archive("$currdir/$item",$docudom,
11397: $docuname,$depth,$count,
1.1056 raeburn 11398: $hierarchy,$dirorder,$children,
11399: $parent,$titles,$wantform);
1.1055 raeburn 11400: $$depth --;
1.1056 raeburn 11401: pop(@{$hierarchy});
1.1055 raeburn 11402: }
11403: }
11404: }
11405: }
11406: return $result;
11407: }
11408:
11409: sub archive_hierarchy {
11410: my ($depth,$count,$parent,$children) =@_;
11411: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11412: if (exists($parent->{$depth})) {
11413: $children->{$parent->{$depth}} .= $count.':';
11414: }
11415: }
11416: return;
11417: }
11418:
11419: sub archive_row {
11420: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11421: my ($name) = ($item =~ m{([^/]+)$});
11422: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11423: 'display' => 'Add as file',
1.1055 raeburn 11424: 'dependency' => 'Include as dependency',
11425: 'discard' => 'Discard',
11426: );
11427: if ($is_dir) {
1.1059 raeburn 11428: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11429: }
1.1056 raeburn 11430: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11431: my $offset = 0;
1.1055 raeburn 11432: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11433: $offset ++;
1.1065 raeburn 11434: if ($action ne 'display') {
11435: $offset ++;
11436: }
1.1055 raeburn 11437: $output .= '<td><span class="LC_nobreak">'.
11438: '<label><input type="radio" name="archive_'.$count.
11439: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11440: my $text = $choices{$action};
11441: if ($is_dir) {
11442: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11443: if ($action eq 'display') {
1.1059 raeburn 11444: $text = &mt('Add as folder');
1.1055 raeburn 11445: }
1.1056 raeburn 11446: } else {
11447: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11448:
11449: }
11450: $output .= ' /> '.$choices{$action}.'</label></span>';
11451: if ($action eq 'dependency') {
11452: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11453: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11454: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11455: '<option value=""></option>'."\n".
11456: '</select>'."\n".
11457: '</div>';
1.1059 raeburn 11458: } elsif ($action eq 'display') {
11459: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11460: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11461: '</div>';
1.1055 raeburn 11462: }
1.1056 raeburn 11463: $output .= '</td>';
1.1055 raeburn 11464: }
11465: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11466: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11467: for (my $i=0; $i<$depth; $i++) {
11468: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11469: }
11470: if ($is_dir) {
11471: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11472: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11473: } else {
11474: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11475: }
11476: $output .= ' '.$name.'</td>'."\n".
11477: &end_data_table_row();
11478: return $output;
11479: }
11480:
11481: sub archive_options_form {
1.1065 raeburn 11482: my ($form,$display,$count,$hiddenelem) = @_;
11483: my %lt = &Apache::lonlocal::texthash(
11484: perm => 'Permanently remove archive file?',
11485: hows => 'How should each extracted item be incorporated in the course?',
11486: cont => 'Content actions for all',
11487: addf => 'Add as folder/file',
11488: incd => 'Include as dependency for a displayed file',
11489: disc => 'Discard',
11490: no => 'No',
11491: yes => 'Yes',
11492: save => 'Save',
11493: );
11494: my $output = <<"END";
11495: <form name="$form" method="post" action="">
11496: <p><span class="LC_nobreak">$lt{'perm'}
11497: <label>
11498: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11499: </label>
11500:
11501: <label>
11502: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11503: </span>
11504: </p>
11505: <input type="hidden" name="phase" value="decompress_cleanup" />
11506: <br />$lt{'hows'}
11507: <div class="LC_columnSection">
11508: <fieldset>
11509: <legend>$lt{'cont'}</legend>
11510: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11511: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11512: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11513: </fieldset>
11514: </div>
11515: END
11516: return $output.
1.1055 raeburn 11517: &start_data_table()."\n".
1.1065 raeburn 11518: $display."\n".
1.1055 raeburn 11519: &end_data_table()."\n".
11520: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11521: $hiddenelem.
1.1065 raeburn 11522: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11523: '</form>';
11524: }
11525:
11526: sub archive_javascript {
1.1056 raeburn 11527: my ($startcount,$numitems,$titles,$children) = @_;
11528: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11529: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11530: my $scripttag = <<START;
11531: <script type="text/javascript">
11532: // <![CDATA[
11533:
11534: function checkAll(form,prefix) {
11535: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11536: for (var i=0; i < form.elements.length; i++) {
11537: var id = form.elements[i].id;
11538: if ((id != '') && (id != undefined)) {
11539: if (idstr.test(id)) {
11540: if (form.elements[i].type == 'radio') {
11541: form.elements[i].checked = true;
1.1056 raeburn 11542: var nostart = i-$startcount;
1.1059 raeburn 11543: var offset = nostart%7;
11544: var count = (nostart-offset)/7;
1.1056 raeburn 11545: dependencyCheck(form,count,offset);
1.1055 raeburn 11546: }
11547: }
11548: }
11549: }
11550: }
11551:
11552: function propagateCheck(form,count) {
11553: if (count > 0) {
1.1059 raeburn 11554: var startelement = $startcount + ((count-1) * 7);
11555: for (var j=1; j<6; j++) {
11556: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11557: var item = startelement + j;
11558: if (form.elements[item].type == 'radio') {
11559: if (form.elements[item].checked) {
11560: containerCheck(form,count,j);
11561: break;
11562: }
1.1055 raeburn 11563: }
11564: }
11565: }
11566: }
11567: }
11568:
11569: numitems = $numitems
1.1056 raeburn 11570: var titles = new Array(numitems);
11571: var parents = new Array(numitems);
1.1055 raeburn 11572: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11573: parents[i] = new Array;
1.1055 raeburn 11574: }
1.1059 raeburn 11575: var maintitle = '$maintitle';
1.1055 raeburn 11576:
11577: START
11578:
1.1056 raeburn 11579: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11580: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11581: for (my $i=0; $i<@contents; $i ++) {
11582: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11583: }
11584: }
11585:
1.1056 raeburn 11586: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11587: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11588: }
11589:
1.1055 raeburn 11590: $scripttag .= <<END;
11591:
11592: function containerCheck(form,count,offset) {
11593: if (count > 0) {
1.1056 raeburn 11594: dependencyCheck(form,count,offset);
1.1059 raeburn 11595: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11596: form.elements[item].checked = true;
11597: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11598: if (parents[count].length > 0) {
11599: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11600: containerCheck(form,parents[count][j],offset);
11601: }
11602: }
11603: }
11604: }
11605: }
11606:
11607: function dependencyCheck(form,count,offset) {
11608: if (count > 0) {
1.1059 raeburn 11609: var chosen = (offset+$startcount)+7*(count-1);
11610: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11611: var currtype = form.elements[depitem].type;
11612: if (form.elements[chosen].value == 'dependency') {
11613: document.getElementById('arc_depon_'+count).style.display='block';
11614: form.elements[depitem].options.length = 0;
11615: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11616: for (var i=1; i<=numitems; i++) {
11617: if (i == count) {
11618: continue;
11619: }
1.1059 raeburn 11620: var startelement = $startcount + (i-1) * 7;
11621: for (var j=1; j<6; j++) {
11622: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11623: var item = startelement + j;
11624: if (form.elements[item].type == 'radio') {
11625: if (form.elements[item].checked) {
11626: if (form.elements[item].value == 'display') {
11627: var n = form.elements[depitem].options.length;
11628: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11629: }
11630: }
11631: }
11632: }
11633: }
11634: }
11635: } else {
11636: document.getElementById('arc_depon_'+count).style.display='none';
11637: form.elements[depitem].options.length = 0;
11638: form.elements[depitem].options[0] = new Option('Select','',true,true);
11639: }
1.1059 raeburn 11640: titleCheck(form,count,offset);
1.1056 raeburn 11641: }
11642: }
11643:
11644: function propagateSelect(form,count,offset) {
11645: if (count > 0) {
1.1065 raeburn 11646: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11647: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11648: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11649: if (parents[count].length > 0) {
11650: for (var j=0; j<parents[count].length; j++) {
11651: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11652: }
11653: }
11654: }
11655: }
11656: }
1.1056 raeburn 11657:
11658: function containerSelect(form,count,offset,picked) {
11659: if (count > 0) {
1.1065 raeburn 11660: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11661: if (form.elements[item].type == 'radio') {
11662: if (form.elements[item].value == 'dependency') {
11663: if (form.elements[item+1].type == 'select-one') {
11664: for (var i=0; i<form.elements[item+1].options.length; i++) {
11665: if (form.elements[item+1].options[i].value == picked) {
11666: form.elements[item+1].selectedIndex = i;
11667: break;
11668: }
11669: }
11670: }
11671: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11672: if (parents[count].length > 0) {
11673: for (var j=0; j<parents[count].length; j++) {
11674: containerSelect(form,parents[count][j],offset,picked);
11675: }
11676: }
11677: }
11678: }
11679: }
11680: }
11681: }
11682:
1.1059 raeburn 11683: function titleCheck(form,count,offset) {
11684: if (count > 0) {
11685: var chosen = (offset+$startcount)+7*(count-1);
11686: var depitem = $startcount + ((count-1) * 7) + 2;
11687: var currtype = form.elements[depitem].type;
11688: if (form.elements[chosen].value == 'display') {
11689: document.getElementById('arc_title_'+count).style.display='block';
11690: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11691: document.getElementById('archive_title_'+count).value=maintitle;
11692: }
11693: } else {
11694: document.getElementById('arc_title_'+count).style.display='none';
11695: if (currtype == 'text') {
11696: document.getElementById('archive_title_'+count).value='';
11697: }
11698: }
11699: }
11700: return;
11701: }
11702:
1.1055 raeburn 11703: // ]]>
11704: </script>
11705: END
11706: return $scripttag;
11707: }
11708:
11709: sub process_extracted_files {
1.1067 raeburn 11710: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11711: my $numitems = $env{'form.archive_count'};
11712: return unless ($numitems);
11713: my @ids=&Apache::lonnet::current_machine_ids();
11714: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11715: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11716: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11717: if (grep(/^\Q$docuhome\E$/,@ids)) {
11718: $prefix = &LONCAPA::propath($docudom,$docuname);
11719: $pathtocheck = "$dir_root/$destination";
11720: $dir = $dir_root;
11721: $ishome = 1;
11722: } else {
11723: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11724: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11725: $dir = "$dir_root/$docudom/$docuname";
11726: }
11727: my $currdir = "$dir_root/$destination";
11728: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11729: if ($env{'form.folderpath'}) {
11730: my @items = split('&',$env{'form.folderpath'});
11731: $folders{'0'} = $items[-2];
1.1099 raeburn 11732: if ($env{'form.folderpath'} =~ /\:1$/) {
11733: $containers{'0'}='page';
11734: } else {
11735: $containers{'0'}='sequence';
11736: }
1.1055 raeburn 11737: }
11738: my @archdirs = &get_env_multiple('form.archive_directory');
11739: if ($numitems) {
11740: for (my $i=1; $i<=$numitems; $i++) {
11741: my $path = $env{'form.archive_content_'.$i};
11742: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11743: my $item = $1;
11744: $toplevelitems{$item} = $i;
11745: if (grep(/^\Q$i\E$/,@archdirs)) {
11746: $is_dir{$item} = 1;
11747: }
11748: }
11749: }
11750: }
1.1067 raeburn 11751: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11752: if (keys(%toplevelitems) > 0) {
11753: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11754: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11755: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11756: }
1.1066 raeburn 11757: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11758: if ($numitems) {
11759: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11760: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11761: my $path = $env{'form.archive_content_'.$i};
11762: if ($path =~ /^\Q$pathtocheck\E/) {
11763: if ($env{'form.archive_'.$i} eq 'discard') {
11764: if ($prefix ne '' && $path ne '') {
11765: if (-e $prefix.$path) {
1.1066 raeburn 11766: if ((@archdirs > 0) &&
11767: (grep(/^\Q$i\E$/,@archdirs))) {
11768: $todeletedir{$prefix.$path} = 1;
11769: } else {
11770: $todelete{$prefix.$path} = 1;
11771: }
1.1055 raeburn 11772: }
11773: }
11774: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11775: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11776: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11777: $docstitle = $env{'form.archive_title_'.$i};
11778: if ($docstitle eq '') {
11779: $docstitle = $title;
11780: }
1.1055 raeburn 11781: $outer = 0;
1.1056 raeburn 11782: if (ref($dirorder{$i}) eq 'ARRAY') {
11783: if (@{$dirorder{$i}} > 0) {
11784: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11785: if ($env{'form.archive_'.$item} eq 'display') {
11786: $outer = $item;
11787: last;
11788: }
11789: }
11790: }
11791: }
11792: my ($errtext,$fatal) =
11793: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11794: '/'.$folders{$outer}.'.'.
11795: $containers{$outer});
11796: next if ($fatal);
11797: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11798: if ($context eq 'coursedocs') {
1.1056 raeburn 11799: $mapinner{$i} = time;
1.1055 raeburn 11800: $folders{$i} = 'default_'.$mapinner{$i};
11801: $containers{$i} = 'sequence';
11802: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11803: $folders{$i}.'.'.$containers{$i};
11804: my $newidx = &LONCAPA::map::getresidx();
11805: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11806: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11807: push(@LONCAPA::map::order,$newidx);
11808: my ($outtext,$errtext) =
11809: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11810: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11811: '.'.$containers{$outer},1,1);
1.1056 raeburn 11812: $newseqid{$i} = $newidx;
1.1067 raeburn 11813: unless ($errtext) {
11814: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11815: }
1.1055 raeburn 11816: }
11817: } else {
11818: if ($context eq 'coursedocs') {
11819: my $newidx=&LONCAPA::map::getresidx();
11820: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11821: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11822: $title;
11823: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11824: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11825: }
11826: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11827: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11828: }
11829: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11830: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11831: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11832: unless ($ishome) {
11833: my $fetch = "$newdest{$i}/$title";
11834: $fetch =~ s/^\Q$prefix$dir\E//;
11835: $prompttofetch{$fetch} = 1;
11836: }
1.1055 raeburn 11837: }
11838: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11839: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11840: push(@LONCAPA::map::order, $newidx);
11841: my ($outtext,$errtext)=
11842: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11843: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11844: '.'.$containers{$outer},1,1);
1.1067 raeburn 11845: unless ($errtext) {
11846: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11847: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11848: }
11849: }
1.1055 raeburn 11850: }
11851: }
1.1086 raeburn 11852: }
11853: } else {
11854: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11855: }
11856: }
11857: for (my $i=1; $i<=$numitems; $i++) {
11858: next unless ($env{'form.archive_'.$i} eq 'dependency');
11859: my $path = $env{'form.archive_content_'.$i};
11860: if ($path =~ /^\Q$pathtocheck\E/) {
11861: my ($title) = ($path =~ m{/([^/]+)$});
11862: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11863: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11864: if (ref($dirorder{$i}) eq 'ARRAY') {
11865: my ($itemidx,$fullpath,$relpath);
11866: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11867: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11868: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11869: if ($dirorder{$i}->[$j] eq $container) {
11870: $itemidx = $j;
1.1056 raeburn 11871: }
11872: }
1.1086 raeburn 11873: }
11874: if ($itemidx eq '') {
11875: $itemidx = 0;
11876: }
11877: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11878: if ($mapinner{$referrer{$i}}) {
11879: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11880: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11881: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11882: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11883: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11884: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11885: if (!-e $fullpath) {
11886: mkdir($fullpath,0755);
1.1056 raeburn 11887: }
11888: }
1.1086 raeburn 11889: } else {
11890: last;
1.1056 raeburn 11891: }
1.1086 raeburn 11892: }
11893: }
11894: } elsif ($newdest{$referrer{$i}}) {
11895: $fullpath = $newdest{$referrer{$i}};
11896: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11897: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11898: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11899: last;
11900: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11901: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11902: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11903: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11904: if (!-e $fullpath) {
11905: mkdir($fullpath,0755);
1.1056 raeburn 11906: }
11907: }
1.1086 raeburn 11908: } else {
11909: last;
1.1056 raeburn 11910: }
1.1055 raeburn 11911: }
11912: }
1.1086 raeburn 11913: if ($fullpath ne '') {
11914: if (-e "$prefix$path") {
11915: system("mv $prefix$path $fullpath/$title");
11916: }
11917: if (-e "$fullpath/$title") {
11918: my $showpath;
11919: if ($relpath ne '') {
11920: $showpath = "$relpath/$title";
11921: } else {
11922: $showpath = "/$title";
11923: }
11924: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11925: }
11926: unless ($ishome) {
11927: my $fetch = "$fullpath/$title";
11928: $fetch =~ s/^\Q$prefix$dir\E//;
11929: $prompttofetch{$fetch} = 1;
11930: }
11931: }
1.1055 raeburn 11932: }
1.1086 raeburn 11933: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11934: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11935: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11936: }
11937: } else {
11938: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11939: }
11940: }
11941: if (keys(%todelete)) {
11942: foreach my $key (keys(%todelete)) {
11943: unlink($key);
1.1066 raeburn 11944: }
11945: }
11946: if (keys(%todeletedir)) {
11947: foreach my $key (keys(%todeletedir)) {
11948: rmdir($key);
11949: }
11950: }
11951: foreach my $dir (sort(keys(%is_dir))) {
11952: if (($pathtocheck ne '') && ($dir ne '')) {
11953: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11954: }
11955: }
1.1067 raeburn 11956: if ($result ne '') {
11957: $output .= '<ul>'."\n".
11958: $result."\n".
11959: '</ul>';
11960: }
11961: unless ($ishome) {
11962: my $replicationfail;
11963: foreach my $item (keys(%prompttofetch)) {
11964: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11965: unless ($fetchresult eq 'ok') {
11966: $replicationfail .= '<li>'.$item.'</li>'."\n";
11967: }
11968: }
11969: if ($replicationfail) {
11970: $output .= '<p class="LC_error">'.
11971: &mt('Course home server failed to retrieve:').'<ul>'.
11972: $replicationfail.
11973: '</ul></p>';
11974: }
11975: }
1.1055 raeburn 11976: } else {
11977: $warning = &mt('No items found in archive.');
11978: }
11979: if ($error) {
11980: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11981: $error.'</p>'."\n";
11982: }
11983: if ($warning) {
11984: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11985: }
11986: return $output;
11987: }
11988:
1.1066 raeburn 11989: sub cleanup_empty_dirs {
11990: my ($path) = @_;
11991: if (($path ne '') && (-d $path)) {
11992: if (opendir(my $dirh,$path)) {
11993: my @dircontents = grep(!/^\./,readdir($dirh));
11994: my $numitems = 0;
11995: foreach my $item (@dircontents) {
11996: if (-d "$path/$item") {
1.1111 raeburn 11997: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11998: if (-e "$path/$item") {
11999: $numitems ++;
12000: }
12001: } else {
12002: $numitems ++;
12003: }
12004: }
12005: if ($numitems == 0) {
12006: rmdir($path);
12007: }
12008: closedir($dirh);
12009: }
12010: }
12011: return;
12012: }
12013:
1.41 ng 12014: =pod
1.45 matthew 12015:
1.1068 raeburn 12016: =item &get_folder_hierarchy()
12017:
12018: Provides hierarchy of names of folders/sub-folders containing the current
12019: item,
12020:
12021: Inputs: 3
12022: - $navmap - navmaps object
12023:
12024: - $map - url for map (either the trigger itself, or map containing
12025: the resource, which is the trigger).
12026:
12027: - $showitem - 1 => show title for map itself; 0 => do not show.
12028:
12029: Outputs: 1 @pathitems - array of folder/subfolder names.
12030:
12031: =cut
12032:
12033: sub get_folder_hierarchy {
12034: my ($navmap,$map,$showitem) = @_;
12035: my @pathitems;
12036: if (ref($navmap)) {
12037: my $mapres = $navmap->getResourceByUrl($map);
12038: if (ref($mapres)) {
12039: my $pcslist = $mapres->map_hierarchy();
12040: if ($pcslist ne '') {
12041: my @pcs = split(/,/,$pcslist);
12042: foreach my $pc (@pcs) {
12043: if ($pc == 1) {
1.1129 raeburn 12044: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12045: } else {
12046: my $res = $navmap->getByMapPc($pc);
12047: if (ref($res)) {
12048: my $title = $res->compTitle();
12049: $title =~ s/\W+/_/g;
12050: if ($title ne '') {
12051: push(@pathitems,$title);
12052: }
12053: }
12054: }
12055: }
12056: }
1.1071 raeburn 12057: if ($showitem) {
12058: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12059: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12060: } else {
12061: my $maptitle = $mapres->compTitle();
12062: $maptitle =~ s/\W+/_/g;
12063: if ($maptitle ne '') {
12064: push(@pathitems,$maptitle);
12065: }
1.1068 raeburn 12066: }
12067: }
12068: }
12069: }
12070: return @pathitems;
12071: }
12072:
12073: =pod
12074:
1.1015 raeburn 12075: =item * &get_turnedin_filepath()
12076:
12077: Determines path in a user's portfolio file for storage of files uploaded
12078: to a specific essayresponse or dropbox item.
12079:
12080: Inputs: 3 required + 1 optional.
12081: $symb is symb for resource, $uname and $udom are for current user (required).
12082: $caller is optional (can be "submission", if routine is called when storing
12083: an upoaded file when "Submit Answer" button was pressed).
12084:
12085: Returns array containing $path and $multiresp.
12086: $path is path in portfolio. $multiresp is 1 if this resource contains more
12087: than one file upload item. Callers of routine should append partid as a
12088: subdirectory to $path in cases where $multiresp is 1.
12089:
12090: Called by: homework/essayresponse.pm and homework/structuretags.pm
12091:
12092: =cut
12093:
12094: sub get_turnedin_filepath {
12095: my ($symb,$uname,$udom,$caller) = @_;
12096: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12097: my $turnindir;
12098: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12099: $turnindir = $userhash{'turnindir'};
12100: my ($path,$multiresp);
12101: if ($turnindir eq '') {
12102: if ($caller eq 'submission') {
12103: $turnindir = &mt('turned in');
12104: $turnindir =~ s/\W+/_/g;
12105: my %newhash = (
12106: 'turnindir' => $turnindir,
12107: );
12108: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12109: }
12110: }
12111: if ($turnindir ne '') {
12112: $path = '/'.$turnindir.'/';
12113: my ($multipart,$turnin,@pathitems);
12114: my $navmap = Apache::lonnavmaps::navmap->new();
12115: if (defined($navmap)) {
12116: my $mapres = $navmap->getResourceByUrl($map);
12117: if (ref($mapres)) {
12118: my $pcslist = $mapres->map_hierarchy();
12119: if ($pcslist ne '') {
12120: foreach my $pc (split(/,/,$pcslist)) {
12121: my $res = $navmap->getByMapPc($pc);
12122: if (ref($res)) {
12123: my $title = $res->compTitle();
12124: $title =~ s/\W+/_/g;
12125: if ($title ne '') {
12126: push(@pathitems,$title);
12127: }
12128: }
12129: }
12130: }
12131: my $maptitle = $mapres->compTitle();
12132: $maptitle =~ s/\W+/_/g;
12133: if ($maptitle ne '') {
12134: push(@pathitems,$maptitle);
12135: }
12136: unless ($env{'request.state'} eq 'construct') {
12137: my $res = $navmap->getBySymb($symb);
12138: if (ref($res)) {
12139: my $partlist = $res->parts();
12140: my $totaluploads = 0;
12141: if (ref($partlist) eq 'ARRAY') {
12142: foreach my $part (@{$partlist}) {
12143: my @types = $res->responseType($part);
12144: my @ids = $res->responseIds($part);
12145: for (my $i=0; $i < scalar(@ids); $i++) {
12146: if ($types[$i] eq 'essay') {
12147: my $partid = $part.'_'.$ids[$i];
12148: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12149: $totaluploads ++;
12150: }
12151: }
12152: }
12153: }
12154: if ($totaluploads > 1) {
12155: $multiresp = 1;
12156: }
12157: }
12158: }
12159: }
12160: } else {
12161: return;
12162: }
12163: } else {
12164: return;
12165: }
12166: my $restitle=&Apache::lonnet::gettitle($symb);
12167: $restitle =~ s/\W+/_/g;
12168: if ($restitle eq '') {
12169: $restitle = ($resurl =~ m{/[^/]+$});
12170: if ($restitle eq '') {
12171: $restitle = time;
12172: }
12173: }
12174: push(@pathitems,$restitle);
12175: $path .= join('/',@pathitems);
12176: }
12177: return ($path,$multiresp);
12178: }
12179:
12180: =pod
12181:
1.464 albertel 12182: =back
1.41 ng 12183:
1.112 bowersj2 12184: =head1 CSV Upload/Handling functions
1.38 albertel 12185:
1.41 ng 12186: =over 4
12187:
1.648 raeburn 12188: =item * &upfile_store($r)
1.41 ng 12189:
12190: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12191: needs $env{'form.upfile'}
1.41 ng 12192: returns $datatoken to be put into hidden field
12193:
12194: =cut
1.31 albertel 12195:
12196: sub upfile_store {
12197: my $r=shift;
1.258 albertel 12198: $env{'form.upfile'}=~s/\r/\n/gs;
12199: $env{'form.upfile'}=~s/\f/\n/gs;
12200: $env{'form.upfile'}=~s/\n+/\n/gs;
12201: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12202:
1.258 albertel 12203: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12204: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12205: {
1.158 raeburn 12206: my $datafile = $r->dir_config('lonDaemons').
12207: '/tmp/'.$datatoken.'.tmp';
12208: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12209: print $fh $env{'form.upfile'};
1.158 raeburn 12210: close($fh);
12211: }
1.31 albertel 12212: }
12213: return $datatoken;
12214: }
12215:
1.56 matthew 12216: =pod
12217:
1.648 raeburn 12218: =item * &load_tmp_file($r)
1.41 ng 12219:
12220: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12221: needs $env{'form.datatoken'},
12222: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12223:
12224: =cut
1.31 albertel 12225:
12226: sub load_tmp_file {
12227: my $r=shift;
12228: my @studentdata=();
12229: {
1.158 raeburn 12230: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12231: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12232: if ( open(my $fh,"<$studentfile") ) {
12233: @studentdata=<$fh>;
12234: close($fh);
12235: }
1.31 albertel 12236: }
1.258 albertel 12237: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12238: }
12239:
1.56 matthew 12240: =pod
12241:
1.648 raeburn 12242: =item * &upfile_record_sep()
1.41 ng 12243:
12244: Separate uploaded file into records
12245: returns array of records,
1.258 albertel 12246: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12247:
12248: =cut
1.31 albertel 12249:
12250: sub upfile_record_sep {
1.258 albertel 12251: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12252: } else {
1.248 albertel 12253: my @records;
1.258 albertel 12254: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12255: if ($line=~/^\s*$/) { next; }
12256: push(@records,$line);
12257: }
12258: return @records;
1.31 albertel 12259: }
12260: }
12261:
1.56 matthew 12262: =pod
12263:
1.648 raeburn 12264: =item * &record_sep($record)
1.41 ng 12265:
1.258 albertel 12266: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12267:
12268: =cut
12269:
1.263 www 12270: sub takeleft {
12271: my $index=shift;
12272: return substr('0000'.$index,-4,4);
12273: }
12274:
1.31 albertel 12275: sub record_sep {
12276: my $record=shift;
12277: my %components=();
1.258 albertel 12278: if ($env{'form.upfiletype'} eq 'xml') {
12279: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12280: my $i=0;
1.356 albertel 12281: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12282: $field=~s/^(\"|\')//;
12283: $field=~s/(\"|\')$//;
1.263 www 12284: $components{&takeleft($i)}=$field;
1.31 albertel 12285: $i++;
12286: }
1.258 albertel 12287: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12288: my $i=0;
1.356 albertel 12289: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12290: $field=~s/^(\"|\')//;
12291: $field=~s/(\"|\')$//;
1.263 www 12292: $components{&takeleft($i)}=$field;
1.31 albertel 12293: $i++;
12294: }
12295: } else {
1.561 www 12296: my $separator=',';
1.480 banghart 12297: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12298: $separator=';';
1.480 banghart 12299: }
1.31 albertel 12300: my $i=0;
1.561 www 12301: # the character we are looking for to indicate the end of a quote or a record
12302: my $looking_for=$separator;
12303: # do not add the characters to the fields
12304: my $ignore=0;
12305: # we just encountered a separator (or the beginning of the record)
12306: my $just_found_separator=1;
12307: # store the field we are working on here
12308: my $field='';
12309: # work our way through all characters in record
12310: foreach my $character ($record=~/(.)/g) {
12311: if ($character eq $looking_for) {
12312: if ($character ne $separator) {
12313: # Found the end of a quote, again looking for separator
12314: $looking_for=$separator;
12315: $ignore=1;
12316: } else {
12317: # Found a separator, store away what we got
12318: $components{&takeleft($i)}=$field;
12319: $i++;
12320: $just_found_separator=1;
12321: $ignore=0;
12322: $field='';
12323: }
12324: next;
12325: }
12326: # single or double quotation marks after a separator indicate beginning of a quote
12327: # we are now looking for the end of the quote and need to ignore separators
12328: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12329: $looking_for=$character;
12330: next;
12331: }
12332: # ignore would be true after we reached the end of a quote
12333: if ($ignore) { next; }
12334: if (($just_found_separator) && ($character=~/\s/)) { next; }
12335: $field.=$character;
12336: $just_found_separator=0;
1.31 albertel 12337: }
1.561 www 12338: # catch the very last entry, since we never encountered the separator
12339: $components{&takeleft($i)}=$field;
1.31 albertel 12340: }
12341: return %components;
12342: }
12343:
1.144 matthew 12344: ######################################################
12345: ######################################################
12346:
1.56 matthew 12347: =pod
12348:
1.648 raeburn 12349: =item * &upfile_select_html()
1.41 ng 12350:
1.144 matthew 12351: Return HTML code to select a file from the users machine and specify
12352: the file type.
1.41 ng 12353:
12354: =cut
12355:
1.144 matthew 12356: ######################################################
12357: ######################################################
1.31 albertel 12358: sub upfile_select_html {
1.144 matthew 12359: my %Types = (
12360: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12361: semisv => &mt('Semicolon separated values'),
1.144 matthew 12362: space => &mt('Space separated'),
12363: tab => &mt('Tabulator separated'),
12364: # xml => &mt('HTML/XML'),
12365: );
12366: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12367: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12368: foreach my $type (sort(keys(%Types))) {
12369: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12370: }
12371: $Str .= "</select>\n";
12372: return $Str;
1.31 albertel 12373: }
12374:
1.301 albertel 12375: sub get_samples {
12376: my ($records,$toget) = @_;
12377: my @samples=({});
12378: my $got=0;
12379: foreach my $rec (@$records) {
12380: my %temp = &record_sep($rec);
12381: if (! grep(/\S/, values(%temp))) { next; }
12382: if (%temp) {
12383: $samples[$got]=\%temp;
12384: $got++;
12385: if ($got == $toget) { last; }
12386: }
12387: }
12388: return \@samples;
12389: }
12390:
1.144 matthew 12391: ######################################################
12392: ######################################################
12393:
1.56 matthew 12394: =pod
12395:
1.648 raeburn 12396: =item * &csv_print_samples($r,$records)
1.41 ng 12397:
12398: Prints a table of sample values from each column uploaded $r is an
12399: Apache Request ref, $records is an arrayref from
12400: &Apache::loncommon::upfile_record_sep
12401:
12402: =cut
12403:
1.144 matthew 12404: ######################################################
12405: ######################################################
1.31 albertel 12406: sub csv_print_samples {
12407: my ($r,$records) = @_;
1.662 bisitz 12408: my $samples = &get_samples($records,5);
1.301 albertel 12409:
1.594 raeburn 12410: $r->print(&mt('Samples').'<br />'.&start_data_table().
12411: &start_data_table_header_row());
1.356 albertel 12412: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12413: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12414: $r->print(&end_data_table_header_row());
1.301 albertel 12415: foreach my $hash (@$samples) {
1.594 raeburn 12416: $r->print(&start_data_table_row());
1.356 albertel 12417: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12418: $r->print('<td>');
1.356 albertel 12419: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12420: $r->print('</td>');
12421: }
1.594 raeburn 12422: $r->print(&end_data_table_row());
1.31 albertel 12423: }
1.594 raeburn 12424: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12425: }
12426:
1.144 matthew 12427: ######################################################
12428: ######################################################
12429:
1.56 matthew 12430: =pod
12431:
1.648 raeburn 12432: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12433:
12434: Prints a table to create associations between values and table columns.
1.144 matthew 12435:
1.41 ng 12436: $r is an Apache Request ref,
12437: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12438: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12439:
12440: =cut
12441:
1.144 matthew 12442: ######################################################
12443: ######################################################
1.31 albertel 12444: sub csv_print_select_table {
12445: my ($r,$records,$d) = @_;
1.301 albertel 12446: my $i=0;
12447: my $samples = &get_samples($records,1);
1.144 matthew 12448: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12449: &start_data_table().&start_data_table_header_row().
1.144 matthew 12450: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12451: '<th>'.&mt('Column').'</th>'.
12452: &end_data_table_header_row()."\n");
1.356 albertel 12453: foreach my $array_ref (@$d) {
12454: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12455: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12456:
1.875 bisitz 12457: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12458: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12459: $r->print('<option value="none"></option>');
1.356 albertel 12460: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12461: $r->print('<option value="'.$sample.'"'.
12462: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12463: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12464: }
1.594 raeburn 12465: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12466: $i++;
12467: }
1.594 raeburn 12468: $r->print(&end_data_table());
1.31 albertel 12469: $i--;
12470: return $i;
12471: }
1.56 matthew 12472:
1.144 matthew 12473: ######################################################
12474: ######################################################
12475:
1.56 matthew 12476: =pod
1.31 albertel 12477:
1.648 raeburn 12478: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12479:
12480: Prints a table of sample values from the upload and can make associate samples to internal names.
12481:
12482: $r is an Apache Request ref,
12483: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12484: $d is an array of 2 element arrays (internal name, displayed name)
12485:
12486: =cut
12487:
1.144 matthew 12488: ######################################################
12489: ######################################################
1.31 albertel 12490: sub csv_samples_select_table {
12491: my ($r,$records,$d) = @_;
12492: my $i=0;
1.144 matthew 12493: #
1.662 bisitz 12494: my $max_samples = 5;
12495: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12496: $r->print(&start_data_table().
12497: &start_data_table_header_row().'<th>'.
12498: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12499: &end_data_table_header_row());
1.301 albertel 12500:
12501: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12502: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12503: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12504: foreach my $option (@$d) {
12505: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12506: $r->print('<option value="'.$value.'"'.
1.253 albertel 12507: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12508: $display.'</option>');
1.31 albertel 12509: }
12510: $r->print('</select></td><td>');
1.662 bisitz 12511: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12512: if (defined($samples->[$line]{$key})) {
12513: $r->print($samples->[$line]{$key}."<br />\n");
12514: }
12515: }
1.594 raeburn 12516: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12517: $i++;
12518: }
1.594 raeburn 12519: $r->print(&end_data_table());
1.31 albertel 12520: $i--;
12521: return($i);
1.115 matthew 12522: }
12523:
1.144 matthew 12524: ######################################################
12525: ######################################################
12526:
1.115 matthew 12527: =pod
12528:
1.648 raeburn 12529: =item * &clean_excel_name($name)
1.115 matthew 12530:
12531: Returns a replacement for $name which does not contain any illegal characters.
12532:
12533: =cut
12534:
1.144 matthew 12535: ######################################################
12536: ######################################################
1.115 matthew 12537: sub clean_excel_name {
12538: my ($name) = @_;
12539: $name =~ s/[:\*\?\/\\]//g;
12540: if (length($name) > 31) {
12541: $name = substr($name,0,31);
12542: }
12543: return $name;
1.25 albertel 12544: }
1.84 albertel 12545:
1.85 albertel 12546: =pod
12547:
1.648 raeburn 12548: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12549:
12550: Returns either 1 or undef
12551:
12552: 1 if the part is to be hidden, undef if it is to be shown
12553:
12554: Arguments are:
12555:
12556: $id the id of the part to be checked
12557: $symb, optional the symb of the resource to check
12558: $udom, optional the domain of the user to check for
12559: $uname, optional the username of the user to check for
12560:
12561: =cut
1.84 albertel 12562:
12563: sub check_if_partid_hidden {
12564: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12565: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12566: $symb,$udom,$uname);
1.141 albertel 12567: my $truth=1;
12568: #if the string starts with !, then the list is the list to show not hide
12569: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12570: my @hiddenlist=split(/,/,$hiddenparts);
12571: foreach my $checkid (@hiddenlist) {
1.141 albertel 12572: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12573: }
1.141 albertel 12574: return !$truth;
1.84 albertel 12575: }
1.127 matthew 12576:
1.138 matthew 12577:
12578: ############################################################
12579: ############################################################
12580:
12581: =pod
12582:
1.157 matthew 12583: =back
12584:
1.138 matthew 12585: =head1 cgi-bin script and graphing routines
12586:
1.157 matthew 12587: =over 4
12588:
1.648 raeburn 12589: =item * &get_cgi_id()
1.138 matthew 12590:
12591: Inputs: none
12592:
12593: Returns an id which can be used to pass environment variables
12594: to various cgi-bin scripts. These environment variables will
12595: be removed from the users environment after a given time by
12596: the routine &Apache::lonnet::transfer_profile_to_env.
12597:
12598: =cut
12599:
12600: ############################################################
12601: ############################################################
1.152 albertel 12602: my $uniq=0;
1.136 matthew 12603: sub get_cgi_id {
1.154 albertel 12604: $uniq=($uniq+1)%100000;
1.280 albertel 12605: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12606: }
12607:
1.127 matthew 12608: ############################################################
12609: ############################################################
12610:
12611: =pod
12612:
1.648 raeburn 12613: =item * &DrawBarGraph()
1.127 matthew 12614:
1.138 matthew 12615: Facilitates the plotting of data in a (stacked) bar graph.
12616: Puts plot definition data into the users environment in order for
12617: graph.png to plot it. Returns an <img> tag for the plot.
12618: The bars on the plot are labeled '1','2',...,'n'.
12619:
12620: Inputs:
12621:
12622: =over 4
12623:
12624: =item $Title: string, the title of the plot
12625:
12626: =item $xlabel: string, text describing the X-axis of the plot
12627:
12628: =item $ylabel: string, text describing the Y-axis of the plot
12629:
12630: =item $Max: scalar, the maximum Y value to use in the plot
12631: If $Max is < any data point, the graph will not be rendered.
12632:
1.140 matthew 12633: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12634: they are plotted. If undefined, default values will be used.
12635:
1.178 matthew 12636: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12637:
1.138 matthew 12638: =item @Values: An array of array references. Each array reference holds data
12639: to be plotted in a stacked bar chart.
12640:
1.239 matthew 12641: =item If the final element of @Values is a hash reference the key/value
12642: pairs will be added to the graph definition.
12643:
1.138 matthew 12644: =back
12645:
12646: Returns:
12647:
12648: An <img> tag which references graph.png and the appropriate identifying
12649: information for the plot.
12650:
1.127 matthew 12651: =cut
12652:
12653: ############################################################
12654: ############################################################
1.134 matthew 12655: sub DrawBarGraph {
1.178 matthew 12656: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12657: #
12658: if (! defined($colors)) {
12659: $colors = ['#33ff00',
12660: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12661: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12662: ];
12663: }
1.228 matthew 12664: my $extra_settings = {};
12665: if (ref($Values[-1]) eq 'HASH') {
12666: $extra_settings = pop(@Values);
12667: }
1.127 matthew 12668: #
1.136 matthew 12669: my $identifier = &get_cgi_id();
12670: my $id = 'cgi.'.$identifier;
1.129 matthew 12671: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12672: return '';
12673: }
1.225 matthew 12674: #
12675: my @Labels;
12676: if (defined($labels)) {
12677: @Labels = @$labels;
12678: } else {
12679: for (my $i=0;$i<@{$Values[0]};$i++) {
12680: push (@Labels,$i+1);
12681: }
12682: }
12683: #
1.129 matthew 12684: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12685: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12686: my %ValuesHash;
12687: my $NumSets=1;
12688: foreach my $array (@Values) {
12689: next if (! ref($array));
1.136 matthew 12690: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12691: join(',',@$array);
1.129 matthew 12692: }
1.127 matthew 12693: #
1.136 matthew 12694: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12695: if ($NumBars < 3) {
12696: $width = 120+$NumBars*32;
1.220 matthew 12697: $xskip = 1;
1.225 matthew 12698: $bar_width = 30;
12699: } elsif ($NumBars < 5) {
12700: $width = 120+$NumBars*20;
12701: $xskip = 1;
12702: $bar_width = 20;
1.220 matthew 12703: } elsif ($NumBars < 10) {
1.136 matthew 12704: $width = 120+$NumBars*15;
12705: $xskip = 1;
12706: $bar_width = 15;
12707: } elsif ($NumBars <= 25) {
12708: $width = 120+$NumBars*11;
12709: $xskip = 5;
12710: $bar_width = 8;
12711: } elsif ($NumBars <= 50) {
12712: $width = 120+$NumBars*8;
12713: $xskip = 5;
12714: $bar_width = 4;
12715: } else {
12716: $width = 120+$NumBars*8;
12717: $xskip = 5;
12718: $bar_width = 4;
12719: }
12720: #
1.137 matthew 12721: $Max = 1 if ($Max < 1);
12722: if ( int($Max) < $Max ) {
12723: $Max++;
12724: $Max = int($Max);
12725: }
1.127 matthew 12726: $Title = '' if (! defined($Title));
12727: $xlabel = '' if (! defined($xlabel));
12728: $ylabel = '' if (! defined($ylabel));
1.369 www 12729: $ValuesHash{$id.'.title'} = &escape($Title);
12730: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12731: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12732: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12733: $ValuesHash{$id.'.NumBars'} = $NumBars;
12734: $ValuesHash{$id.'.NumSets'} = $NumSets;
12735: $ValuesHash{$id.'.PlotType'} = 'bar';
12736: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12737: $ValuesHash{$id.'.height'} = $height;
12738: $ValuesHash{$id.'.width'} = $width;
12739: $ValuesHash{$id.'.xskip'} = $xskip;
12740: $ValuesHash{$id.'.bar_width'} = $bar_width;
12741: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12742: #
1.228 matthew 12743: # Deal with other parameters
12744: while (my ($key,$value) = each(%$extra_settings)) {
12745: $ValuesHash{$id.'.'.$key} = $value;
12746: }
12747: #
1.646 raeburn 12748: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12749: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12750: }
12751:
12752: ############################################################
12753: ############################################################
12754:
12755: =pod
12756:
1.648 raeburn 12757: =item * &DrawXYGraph()
1.137 matthew 12758:
1.138 matthew 12759: Facilitates the plotting of data in an XY graph.
12760: Puts plot definition data into the users environment in order for
12761: graph.png to plot it. Returns an <img> tag for the plot.
12762:
12763: Inputs:
12764:
12765: =over 4
12766:
12767: =item $Title: string, the title of the plot
12768:
12769: =item $xlabel: string, text describing the X-axis of the plot
12770:
12771: =item $ylabel: string, text describing the Y-axis of the plot
12772:
12773: =item $Max: scalar, the maximum Y value to use in the plot
12774: If $Max is < any data point, the graph will not be rendered.
12775:
12776: =item $colors: Array ref containing the hex color codes for the data to be
12777: plotted in. If undefined, default values will be used.
12778:
12779: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12780:
12781: =item $Ydata: Array ref containing Array refs.
1.185 www 12782: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12783:
12784: =item %Values: hash indicating or overriding any default values which are
12785: passed to graph.png.
12786: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12787:
12788: =back
12789:
12790: Returns:
12791:
12792: An <img> tag which references graph.png and the appropriate identifying
12793: information for the plot.
12794:
1.137 matthew 12795: =cut
12796:
12797: ############################################################
12798: ############################################################
12799: sub DrawXYGraph {
12800: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12801: #
12802: # Create the identifier for the graph
12803: my $identifier = &get_cgi_id();
12804: my $id = 'cgi.'.$identifier;
12805: #
12806: $Title = '' if (! defined($Title));
12807: $xlabel = '' if (! defined($xlabel));
12808: $ylabel = '' if (! defined($ylabel));
12809: my %ValuesHash =
12810: (
1.369 www 12811: $id.'.title' => &escape($Title),
12812: $id.'.xlabel' => &escape($xlabel),
12813: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12814: $id.'.y_max_value'=> $Max,
12815: $id.'.labels' => join(',',@$Xlabels),
12816: $id.'.PlotType' => 'XY',
12817: );
12818: #
12819: if (defined($colors) && ref($colors) eq 'ARRAY') {
12820: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12821: }
12822: #
12823: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12824: return '';
12825: }
12826: my $NumSets=1;
1.138 matthew 12827: foreach my $array (@{$Ydata}){
1.137 matthew 12828: next if (! ref($array));
12829: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12830: }
1.138 matthew 12831: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12832: #
12833: # Deal with other parameters
12834: while (my ($key,$value) = each(%Values)) {
12835: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12836: }
12837: #
1.646 raeburn 12838: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12839: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12840: }
12841:
12842: ############################################################
12843: ############################################################
12844:
12845: =pod
12846:
1.648 raeburn 12847: =item * &DrawXYYGraph()
1.138 matthew 12848:
12849: Facilitates the plotting of data in an XY graph with two Y axes.
12850: Puts plot definition data into the users environment in order for
12851: graph.png to plot it. Returns an <img> tag for the plot.
12852:
12853: Inputs:
12854:
12855: =over 4
12856:
12857: =item $Title: string, the title of the plot
12858:
12859: =item $xlabel: string, text describing the X-axis of the plot
12860:
12861: =item $ylabel: string, text describing the Y-axis of the plot
12862:
12863: =item $colors: Array ref containing the hex color codes for the data to be
12864: plotted in. If undefined, default values will be used.
12865:
12866: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12867:
12868: =item $Ydata1: The first data set
12869:
12870: =item $Min1: The minimum value of the left Y-axis
12871:
12872: =item $Max1: The maximum value of the left Y-axis
12873:
12874: =item $Ydata2: The second data set
12875:
12876: =item $Min2: The minimum value of the right Y-axis
12877:
12878: =item $Max2: The maximum value of the left Y-axis
12879:
12880: =item %Values: hash indicating or overriding any default values which are
12881: passed to graph.png.
12882: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12883:
12884: =back
12885:
12886: Returns:
12887:
12888: An <img> tag which references graph.png and the appropriate identifying
12889: information for the plot.
1.136 matthew 12890:
12891: =cut
12892:
12893: ############################################################
12894: ############################################################
1.137 matthew 12895: sub DrawXYYGraph {
12896: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12897: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12898: #
12899: # Create the identifier for the graph
12900: my $identifier = &get_cgi_id();
12901: my $id = 'cgi.'.$identifier;
12902: #
12903: $Title = '' if (! defined($Title));
12904: $xlabel = '' if (! defined($xlabel));
12905: $ylabel = '' if (! defined($ylabel));
12906: my %ValuesHash =
12907: (
1.369 www 12908: $id.'.title' => &escape($Title),
12909: $id.'.xlabel' => &escape($xlabel),
12910: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12911: $id.'.labels' => join(',',@$Xlabels),
12912: $id.'.PlotType' => 'XY',
12913: $id.'.NumSets' => 2,
1.137 matthew 12914: $id.'.two_axes' => 1,
12915: $id.'.y1_max_value' => $Max1,
12916: $id.'.y1_min_value' => $Min1,
12917: $id.'.y2_max_value' => $Max2,
12918: $id.'.y2_min_value' => $Min2,
1.136 matthew 12919: );
12920: #
1.137 matthew 12921: if (defined($colors) && ref($colors) eq 'ARRAY') {
12922: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12923: }
12924: #
12925: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12926: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12927: return '';
12928: }
12929: my $NumSets=1;
1.137 matthew 12930: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12931: next if (! ref($array));
12932: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12933: }
12934: #
12935: # Deal with other parameters
12936: while (my ($key,$value) = each(%Values)) {
12937: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12938: }
12939: #
1.646 raeburn 12940: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12941: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12942: }
12943:
12944: ############################################################
12945: ############################################################
12946:
12947: =pod
12948:
1.157 matthew 12949: =back
12950:
1.139 matthew 12951: =head1 Statistics helper routines?
12952:
12953: Bad place for them but what the hell.
12954:
1.157 matthew 12955: =over 4
12956:
1.648 raeburn 12957: =item * &chartlink()
1.139 matthew 12958:
12959: Returns a link to the chart for a specific student.
12960:
12961: Inputs:
12962:
12963: =over 4
12964:
12965: =item $linktext: The text of the link
12966:
12967: =item $sname: The students username
12968:
12969: =item $sdomain: The students domain
12970:
12971: =back
12972:
1.157 matthew 12973: =back
12974:
1.139 matthew 12975: =cut
12976:
12977: ############################################################
12978: ############################################################
12979: sub chartlink {
12980: my ($linktext, $sname, $sdomain) = @_;
12981: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12982: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12983: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12984: '">'.$linktext.'</a>';
1.153 matthew 12985: }
12986:
12987: #######################################################
12988: #######################################################
12989:
12990: =pod
12991:
12992: =head1 Course Environment Routines
1.157 matthew 12993:
12994: =over 4
1.153 matthew 12995:
1.648 raeburn 12996: =item * &restore_course_settings()
1.153 matthew 12997:
1.648 raeburn 12998: =item * &store_course_settings()
1.153 matthew 12999:
13000: Restores/Store indicated form parameters from the course environment.
13001: Will not overwrite existing values of the form parameters.
13002:
13003: Inputs:
13004: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13005:
13006: a hash ref describing the data to be stored. For example:
13007:
13008: %Save_Parameters = ('Status' => 'scalar',
13009: 'chartoutputmode' => 'scalar',
13010: 'chartoutputdata' => 'scalar',
13011: 'Section' => 'array',
1.373 raeburn 13012: 'Group' => 'array',
1.153 matthew 13013: 'StudentData' => 'array',
13014: 'Maps' => 'array');
13015:
13016: Returns: both routines return nothing
13017:
1.631 raeburn 13018: =back
13019:
1.153 matthew 13020: =cut
13021:
13022: #######################################################
13023: #######################################################
13024: sub store_course_settings {
1.496 albertel 13025: return &store_settings($env{'request.course.id'},@_);
13026: }
13027:
13028: sub store_settings {
1.153 matthew 13029: # save to the environment
13030: # appenv the same items, just to be safe
1.300 albertel 13031: my $udom = $env{'user.domain'};
13032: my $uname = $env{'user.name'};
1.496 albertel 13033: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13034: my %SaveHash;
13035: my %AppHash;
13036: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13037: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13038: my $envname = 'environment.'.$basename;
1.258 albertel 13039: if (exists($env{'form.'.$setting})) {
1.153 matthew 13040: # Save this value away
13041: if ($type eq 'scalar' &&
1.258 albertel 13042: (! exists($env{$envname}) ||
13043: $env{$envname} ne $env{'form.'.$setting})) {
13044: $SaveHash{$basename} = $env{'form.'.$setting};
13045: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13046: } elsif ($type eq 'array') {
13047: my $stored_form;
1.258 albertel 13048: if (ref($env{'form.'.$setting})) {
1.153 matthew 13049: $stored_form = join(',',
13050: map {
1.369 www 13051: &escape($_);
1.258 albertel 13052: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13053: } else {
13054: $stored_form =
1.369 www 13055: &escape($env{'form.'.$setting});
1.153 matthew 13056: }
13057: # Determine if the array contents are the same.
1.258 albertel 13058: if ($stored_form ne $env{$envname}) {
1.153 matthew 13059: $SaveHash{$basename} = $stored_form;
13060: $AppHash{$envname} = $stored_form;
13061: }
13062: }
13063: }
13064: }
13065: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13066: $udom,$uname);
1.153 matthew 13067: if ($put_result !~ /^(ok|delayed)/) {
13068: &Apache::lonnet::logthis('unable to save form parameters, '.
13069: 'got error:'.$put_result);
13070: }
13071: # Make sure these settings stick around in this session, too
1.646 raeburn 13072: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13073: return;
13074: }
13075:
13076: sub restore_course_settings {
1.499 albertel 13077: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13078: }
13079:
13080: sub restore_settings {
13081: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13082: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13083: next if (exists($env{'form.'.$setting}));
1.496 albertel 13084: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13085: '.'.$setting;
1.258 albertel 13086: if (exists($env{$envname})) {
1.153 matthew 13087: if ($type eq 'scalar') {
1.258 albertel 13088: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13089: } elsif ($type eq 'array') {
1.258 albertel 13090: $env{'form.'.$setting} = [
1.153 matthew 13091: map {
1.369 www 13092: &unescape($_);
1.258 albertel 13093: } split(',',$env{$envname})
1.153 matthew 13094: ];
13095: }
13096: }
13097: }
1.127 matthew 13098: }
13099:
1.618 raeburn 13100: #######################################################
13101: #######################################################
13102:
13103: =pod
13104:
13105: =head1 Domain E-mail Routines
13106:
13107: =over 4
13108:
1.648 raeburn 13109: =item * &build_recipient_list()
1.618 raeburn 13110:
1.884 raeburn 13111: Build recipient lists for five types of e-mail:
1.766 raeburn 13112: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 13113: (d) Help requests, (e) Course requests needing approval, generated by
13114: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
13115: loncoursequeueadmin.pm respectively.
1.618 raeburn 13116:
13117: Inputs:
1.619 raeburn 13118: defmail (scalar - email address of default recipient),
1.618 raeburn 13119: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 13120: defdom (domain for which to retrieve configuration settings),
13121: origmail (scalar - email address of recipient from loncapa.conf,
13122: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13123:
1.655 raeburn 13124: Returns: comma separated list of addresses to which to send e-mail.
13125:
13126: =back
1.618 raeburn 13127:
13128: =cut
13129:
13130: ############################################################
13131: ############################################################
13132: sub build_recipient_list {
1.619 raeburn 13133: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13134: my @recipients;
13135: my $otheremails;
13136: my %domconfig =
13137: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13138: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13139: if (exists($domconfig{'contacts'}{$mailing})) {
13140: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13141: my @contacts = ('adminemail','supportemail');
13142: foreach my $item (@contacts) {
13143: if ($domconfig{'contacts'}{$mailing}{$item}) {
13144: my $addr = $domconfig{'contacts'}{$item};
13145: if (!grep(/^\Q$addr\E$/,@recipients)) {
13146: push(@recipients,$addr);
13147: }
1.619 raeburn 13148: }
1.766 raeburn 13149: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13150: }
13151: }
1.766 raeburn 13152: } elsif ($origmail ne '') {
13153: push(@recipients,$origmail);
1.618 raeburn 13154: }
1.619 raeburn 13155: } elsif ($origmail ne '') {
13156: push(@recipients,$origmail);
1.618 raeburn 13157: }
1.688 raeburn 13158: if (defined($defmail)) {
13159: if ($defmail ne '') {
13160: push(@recipients,$defmail);
13161: }
1.618 raeburn 13162: }
13163: if ($otheremails) {
1.619 raeburn 13164: my @others;
13165: if ($otheremails =~ /,/) {
13166: @others = split(/,/,$otheremails);
1.618 raeburn 13167: } else {
1.619 raeburn 13168: push(@others,$otheremails);
13169: }
13170: foreach my $addr (@others) {
13171: if (!grep(/^\Q$addr\E$/,@recipients)) {
13172: push(@recipients,$addr);
13173: }
1.618 raeburn 13174: }
13175: }
1.619 raeburn 13176: my $recipientlist = join(',',@recipients);
1.618 raeburn 13177: return $recipientlist;
13178: }
13179:
1.127 matthew 13180: ############################################################
13181: ############################################################
1.154 albertel 13182:
1.655 raeburn 13183: =pod
13184:
13185: =head1 Course Catalog Routines
13186:
13187: =over 4
13188:
13189: =item * &gather_categories()
13190:
13191: Converts category definitions - keys of categories hash stored in
13192: coursecategories in configuration.db on the primary library server in a
13193: domain - to an array. Also generates javascript and idx hash used to
13194: generate Domain Coordinator interface for editing Course Categories.
13195:
13196: Inputs:
1.663 raeburn 13197:
1.655 raeburn 13198: categories (reference to hash of category definitions).
1.663 raeburn 13199:
1.655 raeburn 13200: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13201: categories and subcategories).
1.663 raeburn 13202:
1.655 raeburn 13203: idx (reference to hash of counters used in Domain Coordinator interface for
13204: editing Course Categories).
1.663 raeburn 13205:
1.655 raeburn 13206: jsarray (reference to array of categories used to create Javascript arrays for
13207: Domain Coordinator interface for editing Course Categories).
13208:
13209: Returns: nothing
13210:
13211: Side effects: populates cats, idx and jsarray.
13212:
13213: =cut
13214:
13215: sub gather_categories {
13216: my ($categories,$cats,$idx,$jsarray) = @_;
13217: my %counters;
13218: my $num = 0;
13219: foreach my $item (keys(%{$categories})) {
13220: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13221: if ($container eq '' && $depth == 0) {
13222: $cats->[$depth][$categories->{$item}] = $cat;
13223: } else {
13224: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13225: }
13226: my ($escitem,$tail) = split(/:/,$item,2);
13227: if ($counters{$tail} eq '') {
13228: $counters{$tail} = $num;
13229: $num ++;
13230: }
13231: if (ref($idx) eq 'HASH') {
13232: $idx->{$item} = $counters{$tail};
13233: }
13234: if (ref($jsarray) eq 'ARRAY') {
13235: push(@{$jsarray->[$counters{$tail}]},$item);
13236: }
13237: }
13238: return;
13239: }
13240:
13241: =pod
13242:
13243: =item * &extract_categories()
13244:
13245: Used to generate breadcrumb trails for course categories.
13246:
13247: Inputs:
1.663 raeburn 13248:
1.655 raeburn 13249: categories (reference to hash of category definitions).
1.663 raeburn 13250:
1.655 raeburn 13251: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13252: categories and subcategories).
1.663 raeburn 13253:
1.655 raeburn 13254: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13255:
1.655 raeburn 13256: allitems (reference to hash - key is category key
13257: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13258:
1.655 raeburn 13259: idx (reference to hash of counters used in Domain Coordinator interface for
13260: editing Course Categories).
1.663 raeburn 13261:
1.655 raeburn 13262: jsarray (reference to array of categories used to create Javascript arrays for
13263: Domain Coordinator interface for editing Course Categories).
13264:
1.665 raeburn 13265: subcats (reference to hash of arrays containing all subcategories within each
13266: category, -recursive)
13267:
1.655 raeburn 13268: Returns: nothing
13269:
13270: Side effects: populates trails and allitems hash references.
13271:
13272: =cut
13273:
13274: sub extract_categories {
1.665 raeburn 13275: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13276: if (ref($categories) eq 'HASH') {
13277: &gather_categories($categories,$cats,$idx,$jsarray);
13278: if (ref($cats->[0]) eq 'ARRAY') {
13279: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13280: my $name = $cats->[0][$i];
13281: my $item = &escape($name).'::0';
13282: my $trailstr;
13283: if ($name eq 'instcode') {
13284: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13285: } elsif ($name eq 'communities') {
13286: $trailstr = &mt('Communities');
1.655 raeburn 13287: } else {
13288: $trailstr = $name;
13289: }
13290: if ($allitems->{$item} eq '') {
13291: push(@{$trails},$trailstr);
13292: $allitems->{$item} = scalar(@{$trails})-1;
13293: }
13294: my @parents = ($name);
13295: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13296: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13297: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13298: if (ref($subcats) eq 'HASH') {
13299: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13300: }
13301: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13302: }
13303: } else {
13304: if (ref($subcats) eq 'HASH') {
13305: $subcats->{$item} = [];
1.655 raeburn 13306: }
13307: }
13308: }
13309: }
13310: }
13311: return;
13312: }
13313:
13314: =pod
13315:
13316: =item *&recurse_categories()
13317:
13318: Recursively used to generate breadcrumb trails for course categories.
13319:
13320: Inputs:
1.663 raeburn 13321:
1.655 raeburn 13322: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13323: categories and subcategories).
1.663 raeburn 13324:
1.655 raeburn 13325: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13326:
13327: category (current course category, for which breadcrumb trail is being generated).
13328:
13329: trails (reference to array of breadcrumb trails for each category).
13330:
1.655 raeburn 13331: allitems (reference to hash - key is category key
13332: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13333:
1.655 raeburn 13334: parents (array containing containers directories for current category,
13335: back to top level).
13336:
13337: Returns: nothing
13338:
13339: Side effects: populates trails and allitems hash references
13340:
13341: =cut
13342:
13343: sub recurse_categories {
1.665 raeburn 13344: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13345: my $shallower = $depth - 1;
13346: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13347: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13348: my $name = $cats->[$depth]{$category}[$k];
13349: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13350: my $trailstr = join(' -> ',(@{$parents},$category));
13351: if ($allitems->{$item} eq '') {
13352: push(@{$trails},$trailstr);
13353: $allitems->{$item} = scalar(@{$trails})-1;
13354: }
13355: my $deeper = $depth+1;
13356: push(@{$parents},$category);
1.665 raeburn 13357: if (ref($subcats) eq 'HASH') {
13358: my $subcat = &escape($name).':'.$category.':'.$depth;
13359: for (my $j=@{$parents}; $j>=0; $j--) {
13360: my $higher;
13361: if ($j > 0) {
13362: $higher = &escape($parents->[$j]).':'.
13363: &escape($parents->[$j-1]).':'.$j;
13364: } else {
13365: $higher = &escape($parents->[$j]).'::'.$j;
13366: }
13367: push(@{$subcats->{$higher}},$subcat);
13368: }
13369: }
13370: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13371: $subcats);
1.655 raeburn 13372: pop(@{$parents});
13373: }
13374: } else {
13375: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13376: my $trailstr = join(' -> ',(@{$parents},$category));
13377: if ($allitems->{$item} eq '') {
13378: push(@{$trails},$trailstr);
13379: $allitems->{$item} = scalar(@{$trails})-1;
13380: }
13381: }
13382: return;
13383: }
13384:
1.663 raeburn 13385: =pod
13386:
13387: =item *&assign_categories_table()
13388:
13389: Create a datatable for display of hierarchical categories in a domain,
13390: with checkboxes to allow a course to be categorized.
13391:
13392: Inputs:
13393:
13394: cathash - reference to hash of categories defined for the domain (from
13395: configuration.db)
13396:
13397: currcat - scalar with an & separated list of categories assigned to a course.
13398:
1.919 raeburn 13399: type - scalar contains course type (Course or Community).
13400:
1.663 raeburn 13401: Returns: $output (markup to be displayed)
13402:
13403: =cut
13404:
13405: sub assign_categories_table {
1.919 raeburn 13406: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13407: my $output;
13408: if (ref($cathash) eq 'HASH') {
13409: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13410: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13411: $maxdepth = scalar(@cats);
13412: if (@cats > 0) {
13413: my $itemcount = 0;
13414: if (ref($cats[0]) eq 'ARRAY') {
13415: my @currcategories;
13416: if ($currcat ne '') {
13417: @currcategories = split('&',$currcat);
13418: }
1.919 raeburn 13419: my $table;
1.663 raeburn 13420: for (my $i=0; $i<@{$cats[0]}; $i++) {
13421: my $parent = $cats[0][$i];
1.919 raeburn 13422: next if ($parent eq 'instcode');
13423: if ($type eq 'Community') {
13424: next unless ($parent eq 'communities');
13425: } else {
13426: next if ($parent eq 'communities');
13427: }
1.663 raeburn 13428: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13429: my $item = &escape($parent).'::0';
13430: my $checked = '';
13431: if (@currcategories > 0) {
13432: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13433: $checked = ' checked="checked"';
1.663 raeburn 13434: }
13435: }
1.919 raeburn 13436: my $parent_title = $parent;
13437: if ($parent eq 'communities') {
13438: $parent_title = &mt('Communities');
13439: }
13440: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13441: '<input type="checkbox" name="usecategory" value="'.
13442: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13443: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13444: my $depth = 1;
13445: push(@path,$parent);
1.919 raeburn 13446: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13447: pop(@path);
1.919 raeburn 13448: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13449: $itemcount ++;
13450: }
1.919 raeburn 13451: if ($itemcount) {
13452: $output = &Apache::loncommon::start_data_table().
13453: $table.
13454: &Apache::loncommon::end_data_table();
13455: }
1.663 raeburn 13456: }
13457: }
13458: }
13459: return $output;
13460: }
13461:
13462: =pod
13463:
13464: =item *&assign_category_rows()
13465:
13466: Create a datatable row for display of nested categories in a domain,
13467: with checkboxes to allow a course to be categorized,called recursively.
13468:
13469: Inputs:
13470:
13471: itemcount - track row number for alternating colors
13472:
13473: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13474: categories and subcategories.
13475:
13476: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13477:
13478: parent - parent of current category item
13479:
13480: path - Array containing all categories back up through the hierarchy from the
13481: current category to the top level.
13482:
13483: currcategories - reference to array of current categories assigned to the course
13484:
13485: Returns: $output (markup to be displayed).
13486:
13487: =cut
13488:
13489: sub assign_category_rows {
13490: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13491: my ($text,$name,$item,$chgstr);
13492: if (ref($cats) eq 'ARRAY') {
13493: my $maxdepth = scalar(@{$cats});
13494: if (ref($cats->[$depth]) eq 'HASH') {
13495: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13496: my $numchildren = @{$cats->[$depth]{$parent}};
13497: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13498: $text .= '<td><table class="LC_datatable">';
13499: for (my $j=0; $j<$numchildren; $j++) {
13500: $name = $cats->[$depth]{$parent}[$j];
13501: $item = &escape($name).':'.&escape($parent).':'.$depth;
13502: my $deeper = $depth+1;
13503: my $checked = '';
13504: if (ref($currcategories) eq 'ARRAY') {
13505: if (@{$currcategories} > 0) {
13506: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13507: $checked = ' checked="checked"';
1.663 raeburn 13508: }
13509: }
13510: }
1.664 raeburn 13511: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13512: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13513: $item.'"'.$checked.' />'.$name.'</label></span>'.
13514: '<input type="hidden" name="catname" value="'.$name.'" />'.
13515: '</td><td>';
1.663 raeburn 13516: if (ref($path) eq 'ARRAY') {
13517: push(@{$path},$name);
13518: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13519: pop(@{$path});
13520: }
13521: $text .= '</td></tr>';
13522: }
13523: $text .= '</table></td>';
13524: }
13525: }
13526: }
13527: return $text;
13528: }
13529:
1.655 raeburn 13530: ############################################################
13531: ############################################################
13532:
13533:
1.443 albertel 13534: sub commit_customrole {
1.664 raeburn 13535: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13536: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13537: ($start?', '.&mt('starting').' '.localtime($start):'').
13538: ($end?', ending '.localtime($end):'').': <b>'.
13539: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13540: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13541: '</b><br />';
13542: return $output;
13543: }
13544:
13545: sub commit_standardrole {
1.1116 raeburn 13546: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13547: my ($output,$logmsg,$linefeed);
13548: if ($context eq 'auto') {
13549: $linefeed = "\n";
13550: } else {
13551: $linefeed = "<br />\n";
13552: }
1.443 albertel 13553: if ($three eq 'st') {
1.541 raeburn 13554: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13555: $one,$two,$sec,$context,$credits);
1.541 raeburn 13556: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13557: ($result eq 'unknown_course') || ($result eq 'refused')) {
13558: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13559: } else {
1.541 raeburn 13560: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13561: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13562: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13563: if ($context eq 'auto') {
13564: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13565: } else {
13566: $output .= '<b>'.$result.'</b>'.$linefeed.
13567: &mt('Add to classlist').': <b>ok</b>';
13568: }
13569: $output .= $linefeed;
1.443 albertel 13570: }
13571: } else {
13572: $output = &mt('Assigning').' '.$three.' in '.$url.
13573: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13574: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13575: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13576: if ($context eq 'auto') {
13577: $output .= $result.$linefeed;
13578: } else {
13579: $output .= '<b>'.$result.'</b>'.$linefeed;
13580: }
1.443 albertel 13581: }
13582: return $output;
13583: }
13584:
13585: sub commit_studentrole {
1.1116 raeburn 13586: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13587: $credits) = @_;
1.626 raeburn 13588: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13589: if ($context eq 'auto') {
13590: $linefeed = "\n";
13591: } else {
13592: $linefeed = '<br />'."\n";
13593: }
1.443 albertel 13594: if (defined($one) && defined($two)) {
13595: my $cid=$one.'_'.$two;
13596: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13597: my $secchange = 0;
13598: my $expire_role_result;
13599: my $modify_section_result;
1.628 raeburn 13600: if ($oldsec ne '-1') {
13601: if ($oldsec ne $sec) {
1.443 albertel 13602: $secchange = 1;
1.628 raeburn 13603: my $now = time;
1.443 albertel 13604: my $uurl='/'.$cid;
13605: $uurl=~s/\_/\//g;
13606: if ($oldsec) {
13607: $uurl.='/'.$oldsec;
13608: }
1.626 raeburn 13609: $oldsecurl = $uurl;
1.628 raeburn 13610: $expire_role_result =
1.652 raeburn 13611: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13612: if ($env{'request.course.sec'} ne '') {
13613: if ($expire_role_result eq 'refused') {
13614: my @roles = ('st');
13615: my @statuses = ('previous');
13616: my @roledoms = ($one);
13617: my $withsec = 1;
13618: my %roleshash =
13619: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13620: \@statuses,\@roles,\@roledoms,$withsec);
13621: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13622: my ($oldstart,$oldend) =
13623: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13624: if ($oldend > 0 && $oldend <= $now) {
13625: $expire_role_result = 'ok';
13626: }
13627: }
13628: }
13629: }
1.443 albertel 13630: $result = $expire_role_result;
13631: }
13632: }
13633: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13634: $modify_section_result =
13635: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13636: undef,undef,undef,$sec,
13637: $end,$start,'','',$cid,
13638: '',$context,$credits);
1.443 albertel 13639: if ($modify_section_result =~ /^ok/) {
13640: if ($secchange == 1) {
1.628 raeburn 13641: if ($sec eq '') {
13642: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13643: } else {
13644: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13645: }
1.443 albertel 13646: } elsif ($oldsec eq '-1') {
1.628 raeburn 13647: if ($sec eq '') {
13648: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13649: } else {
13650: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13651: }
1.443 albertel 13652: } else {
1.628 raeburn 13653: if ($sec eq '') {
13654: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13655: } else {
13656: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13657: }
1.443 albertel 13658: }
13659: } else {
1.1115 raeburn 13660: if ($secchange) {
1.628 raeburn 13661: $$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;
13662: } else {
13663: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13664: }
1.443 albertel 13665: }
13666: $result = $modify_section_result;
13667: } elsif ($secchange == 1) {
1.628 raeburn 13668: if ($oldsec eq '') {
1.1103 raeburn 13669: $$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 13670: } else {
13671: $$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;
13672: }
1.626 raeburn 13673: if ($expire_role_result eq 'refused') {
13674: my $newsecurl = '/'.$cid;
13675: $newsecurl =~ s/\_/\//g;
13676: if ($sec ne '') {
13677: $newsecurl.='/'.$sec;
13678: }
13679: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13680: if ($sec eq '') {
13681: $$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;
13682: } else {
13683: $$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;
13684: }
13685: }
13686: }
1.443 albertel 13687: }
13688: } else {
1.626 raeburn 13689: $$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 13690: $result = "error: incomplete course id\n";
13691: }
13692: return $result;
13693: }
13694:
1.1108 raeburn 13695: sub show_role_extent {
13696: my ($scope,$context,$role) = @_;
13697: $scope =~ s{^/}{};
13698: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13699: push(@courseroles,'co');
13700: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13701: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13702: $scope =~ s{/}{_};
13703: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13704: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13705: my ($audom,$auname) = split(/\//,$scope);
13706: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13707: &Apache::loncommon::plainname($auname,$audom).'</span>');
13708: } else {
13709: $scope =~ s{/$}{};
13710: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13711: &Apache::lonnet::domain($scope,'description').'</span>');
13712: }
13713: }
13714:
1.443 albertel 13715: ############################################################
13716: ############################################################
13717:
1.566 albertel 13718: sub check_clone {
1.578 raeburn 13719: my ($args,$linefeed) = @_;
1.566 albertel 13720: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13721: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13722: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13723: my $clonemsg;
13724: my $can_clone = 0;
1.944 raeburn 13725: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13726: if ($lctype ne 'community') {
13727: $lctype = 'course';
13728: }
1.566 albertel 13729: if ($clonehome eq 'no_host') {
1.944 raeburn 13730: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 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 non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
13732: } else {
13733: $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'});
13734: }
1.566 albertel 13735: } else {
13736: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13737: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13738: if ($clonedesc{'type'} ne 'Community') {
13739: $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'});
13740: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13741: }
13742: }
1.882 raeburn 13743: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13744: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13745: $can_clone = 1;
13746: } else {
13747: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13748: $args->{'clonedomain'},$args->{'clonecourse'});
13749: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13750: if (grep(/^\*$/,@cloners)) {
13751: $can_clone = 1;
13752: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13753: $can_clone = 1;
13754: } else {
1.908 raeburn 13755: my $ccrole = 'cc';
1.944 raeburn 13756: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13757: $ccrole = 'co';
13758: }
1.578 raeburn 13759: my %roleshash =
13760: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13761: $args->{'ccdomain'},
1.908 raeburn 13762: 'userroles',['active'],[$ccrole],
1.578 raeburn 13763: [$args->{'clonedomain'}]);
1.908 raeburn 13764: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13765: $can_clone = 1;
13766: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13767: $can_clone = 1;
13768: } else {
1.944 raeburn 13769: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13770: $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'});
13771: } else {
13772: $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'});
13773: }
1.578 raeburn 13774: }
1.566 albertel 13775: }
1.578 raeburn 13776: }
1.566 albertel 13777: }
13778: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13779: }
13780:
1.444 albertel 13781: sub construct_course {
1.885 raeburn 13782: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13783: my $outcome;
1.541 raeburn 13784: my $linefeed = '<br />'."\n";
13785: if ($context eq 'auto') {
13786: $linefeed = "\n";
13787: }
1.566 albertel 13788:
13789: #
13790: # Are we cloning?
13791: #
13792: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13793: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13794: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13795: if ($context ne 'auto') {
1.578 raeburn 13796: if ($clonemsg ne '') {
13797: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13798: }
1.566 albertel 13799: }
13800: $outcome .= $clonemsg.$linefeed;
13801:
13802: if (!$can_clone) {
13803: return (0,$outcome);
13804: }
13805: }
13806:
1.444 albertel 13807: #
13808: # Open course
13809: #
13810: my $crstype = lc($args->{'crstype'});
13811: my %cenv=();
13812: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13813: $args->{'cdescr'},
13814: $args->{'curl'},
13815: $args->{'course_home'},
13816: $args->{'nonstandard'},
13817: $args->{'crscode'},
13818: $args->{'ccuname'}.':'.
13819: $args->{'ccdomain'},
1.882 raeburn 13820: $args->{'crstype'},
1.885 raeburn 13821: $cnum,$context,$category);
1.444 albertel 13822:
13823: # Note: The testing routines depend on this being output; see
13824: # Utils::Course. This needs to at least be output as a comment
13825: # if anyone ever decides to not show this, and Utils::Course::new
13826: # will need to be suitably modified.
1.541 raeburn 13827: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13828: if ($$courseid =~ /^error:/) {
13829: return (0,$outcome);
13830: }
13831:
1.444 albertel 13832: #
13833: # Check if created correctly
13834: #
1.479 albertel 13835: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13836: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13837: if ($crsuhome eq 'no_host') {
13838: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13839: return (0,$outcome);
13840: }
1.541 raeburn 13841: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13842:
1.444 albertel 13843: #
1.566 albertel 13844: # Do the cloning
13845: #
13846: if ($can_clone && $cloneid) {
13847: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13848: if ($context ne 'auto') {
13849: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13850: }
13851: $outcome .= $clonemsg.$linefeed;
13852: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13853: # Copy all files
1.637 www 13854: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13855: # Restore URL
1.566 albertel 13856: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13857: # Restore title
1.566 albertel 13858: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13859: # Restore creation date, creator and creation context.
13860: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13861: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13862: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13863: # Mark as cloned
1.566 albertel 13864: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13865: # Need to clone grading mode
13866: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13867: $cenv{'grading'}=$newenv{'grading'};
13868: # Do not clone these environment entries
13869: &Apache::lonnet::del('environment',
13870: ['default_enrollment_start_date',
13871: 'default_enrollment_end_date',
13872: 'question.email',
13873: 'policy.email',
13874: 'comment.email',
13875: 'pch.users.denied',
1.725 raeburn 13876: 'plc.users.denied',
13877: 'hidefromcat',
1.1121 raeburn 13878: 'checkforpriv',
1.725 raeburn 13879: 'categories'],
1.638 www 13880: $$crsudom,$$crsunum);
1.444 albertel 13881: }
1.566 albertel 13882:
1.444 albertel 13883: #
13884: # Set environment (will override cloned, if existing)
13885: #
13886: my @sections = ();
13887: my @xlists = ();
13888: if ($args->{'crstype'}) {
13889: $cenv{'type'}=$args->{'crstype'};
13890: }
13891: if ($args->{'crsid'}) {
13892: $cenv{'courseid'}=$args->{'crsid'};
13893: }
13894: if ($args->{'crscode'}) {
13895: $cenv{'internal.coursecode'}=$args->{'crscode'};
13896: }
13897: if ($args->{'crsquota'} ne '') {
13898: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13899: } else {
13900: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13901: }
13902: if ($args->{'ccuname'}) {
13903: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13904: ':'.$args->{'ccdomain'};
13905: } else {
13906: $cenv{'internal.courseowner'} = $args->{'curruser'};
13907: }
1.1116 raeburn 13908: if ($args->{'defaultcredits'}) {
13909: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13910: }
1.444 albertel 13911: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13912: if ($args->{'crssections'}) {
13913: $cenv{'internal.sectionnums'} = '';
13914: if ($args->{'crssections'} =~ m/,/) {
13915: @sections = split/,/,$args->{'crssections'};
13916: } else {
13917: $sections[0] = $args->{'crssections'};
13918: }
13919: if (@sections > 0) {
13920: foreach my $item (@sections) {
13921: my ($sec,$gp) = split/:/,$item;
13922: my $class = $args->{'crscode'}.$sec;
13923: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13924: $cenv{'internal.sectionnums'} .= $item.',';
13925: unless ($addcheck eq 'ok') {
13926: push @badclasses, $class;
13927: }
13928: }
13929: $cenv{'internal.sectionnums'} =~ s/,$//;
13930: }
13931: }
13932: # do not hide course coordinator from staff listing,
13933: # even if privileged
13934: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 13935: # add course coordinator's domain to domains to check for privileged users
13936: # if different to course domain
13937: if ($$crsudom ne $args->{'ccdomain'}) {
13938: $cenv{'checkforpriv'} = $args->{'ccdomain'};
13939: }
1.444 albertel 13940: # add crosslistings
13941: if ($args->{'crsxlist'}) {
13942: $cenv{'internal.crosslistings'}='';
13943: if ($args->{'crsxlist'} =~ m/,/) {
13944: @xlists = split/,/,$args->{'crsxlist'};
13945: } else {
13946: $xlists[0] = $args->{'crsxlist'};
13947: }
13948: if (@xlists > 0) {
13949: foreach my $item (@xlists) {
13950: my ($xl,$gp) = split/:/,$item;
13951: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13952: $cenv{'internal.crosslistings'} .= $item.',';
13953: unless ($addcheck eq 'ok') {
13954: push @badclasses, $xl;
13955: }
13956: }
13957: $cenv{'internal.crosslistings'} =~ s/,$//;
13958: }
13959: }
13960: if ($args->{'autoadds'}) {
13961: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13962: }
13963: if ($args->{'autodrops'}) {
13964: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13965: }
13966: # check for notification of enrollment changes
13967: my @notified = ();
13968: if ($args->{'notify_owner'}) {
13969: if ($args->{'ccuname'} ne '') {
13970: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13971: }
13972: }
13973: if ($args->{'notify_dc'}) {
13974: if ($uname ne '') {
1.630 raeburn 13975: push(@notified,$uname.':'.$udom);
1.444 albertel 13976: }
13977: }
13978: if (@notified > 0) {
13979: my $notifylist;
13980: if (@notified > 1) {
13981: $notifylist = join(',',@notified);
13982: } else {
13983: $notifylist = $notified[0];
13984: }
13985: $cenv{'internal.notifylist'} = $notifylist;
13986: }
13987: if (@badclasses > 0) {
13988: my %lt=&Apache::lonlocal::texthash(
13989: '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',
13990: 'dnhr' => 'does not have rights to access enrollment in these classes',
13991: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13992: );
1.541 raeburn 13993: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13994: ' ('.$lt{'adby'}.')';
13995: if ($context eq 'auto') {
13996: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13997: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13998: foreach my $item (@badclasses) {
13999: if ($context eq 'auto') {
14000: $outcome .= " - $item\n";
14001: } else {
14002: $outcome .= "<li>$item</li>\n";
14003: }
14004: }
14005: if ($context eq 'auto') {
14006: $outcome .= $linefeed;
14007: } else {
1.566 albertel 14008: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14009: }
14010: }
1.444 albertel 14011: }
14012: if ($args->{'no_end_date'}) {
14013: $args->{'endaccess'} = 0;
14014: }
14015: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14016: $cenv{'internal.autoend'}=$args->{'enrollend'};
14017: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14018: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14019: if ($args->{'showphotos'}) {
14020: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14021: }
14022: $cenv{'internal.authtype'} = $args->{'authtype'};
14023: $cenv{'internal.autharg'} = $args->{'autharg'};
14024: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14025: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14026: 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');
14027: if ($context eq 'auto') {
14028: $outcome .= $krb_msg;
14029: } else {
1.566 albertel 14030: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14031: }
14032: $outcome .= $linefeed;
1.444 albertel 14033: }
14034: }
14035: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14036: if ($args->{'setpolicy'}) {
14037: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14038: }
14039: if ($args->{'setcontent'}) {
14040: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14041: }
14042: }
14043: if ($args->{'reshome'}) {
14044: $cenv{'reshome'}=$args->{'reshome'}.'/';
14045: $cenv{'reshome'}=~s/\/+$/\//;
14046: }
14047: #
14048: # course has keyed access
14049: #
14050: if ($args->{'setkeys'}) {
14051: $cenv{'keyaccess'}='yes';
14052: }
14053: # if specified, key authority is not course, but user
14054: # only active if keyaccess is yes
14055: if ($args->{'keyauth'}) {
1.487 albertel 14056: my ($user,$domain) = split(':',$args->{'keyauth'});
14057: $user = &LONCAPA::clean_username($user);
14058: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14059: if ($user ne '' && $domain ne '') {
1.487 albertel 14060: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14061: }
14062: }
14063:
14064: if ($args->{'disresdis'}) {
14065: $cenv{'pch.roles.denied'}='st';
14066: }
14067: if ($args->{'disablechat'}) {
14068: $cenv{'plc.roles.denied'}='st';
14069: }
14070:
14071: # Record we've not yet viewed the Course Initialization Helper for this
14072: # course
14073: $cenv{'course.helper.not.run'} = 1;
14074: #
14075: # Use new Randomseed
14076: #
14077: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14078: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14079: #
14080: # The encryption code and receipt prefix for this course
14081: #
14082: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14083: $cenv{'internal.encpref'}=100+int(9*rand(99));
14084: #
14085: # By default, use standard grading
14086: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14087:
1.541 raeburn 14088: $outcome .= $linefeed.&mt('Setting environment').': '.
14089: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14090: #
14091: # Open all assignments
14092: #
14093: if ($args->{'openall'}) {
14094: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14095: my %storecontent = ($storeunder => time,
14096: $storeunder.'.type' => 'date_start');
14097:
14098: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14099: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14100: }
14101: #
14102: # Set first page
14103: #
14104: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14105: || ($cloneid)) {
1.445 albertel 14106: use LONCAPA::map;
1.444 albertel 14107: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14108:
14109: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14110: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14111:
1.444 albertel 14112: $outcome .= ($fatal?$errtext:'read ok').' - ';
14113: my $title; my $url;
14114: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14115: $title=&mt('Syllabus');
1.444 albertel 14116: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14117: } else {
1.963 raeburn 14118: $title=&mt('Table of Contents');
1.444 albertel 14119: $url='/adm/navmaps';
14120: }
1.445 albertel 14121:
14122: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14123: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14124:
14125: if ($errtext) { $fatal=2; }
1.541 raeburn 14126: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14127: }
1.566 albertel 14128:
14129: return (1,$outcome);
1.444 albertel 14130: }
14131:
14132: ############################################################
14133: ############################################################
14134:
1.953 droeschl 14135: #SD
14136: # only Community and Course, or anything else?
1.378 raeburn 14137: sub course_type {
14138: my ($cid) = @_;
14139: if (!defined($cid)) {
14140: $cid = $env{'request.course.id'};
14141: }
1.404 albertel 14142: if (defined($env{'course.'.$cid.'.type'})) {
14143: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14144: } else {
14145: return 'Course';
1.377 raeburn 14146: }
14147: }
1.156 albertel 14148:
1.406 raeburn 14149: sub group_term {
14150: my $crstype = &course_type();
14151: my %names = (
14152: 'Course' => 'group',
1.865 raeburn 14153: 'Community' => 'group',
1.406 raeburn 14154: );
14155: return $names{$crstype};
14156: }
14157:
1.902 raeburn 14158: sub course_types {
14159: my @types = ('official','unofficial','community');
14160: my %typename = (
14161: official => 'Official course',
14162: unofficial => 'Unofficial course',
14163: community => 'Community',
14164: );
14165: return (\@types,\%typename);
14166: }
14167:
1.156 albertel 14168: sub icon {
14169: my ($file)=@_;
1.505 albertel 14170: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14171: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14172: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14173: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14174: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14175: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14176: $curfext.".gif") {
14177: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14178: $curfext.".gif";
14179: }
14180: }
1.249 albertel 14181: return &lonhttpdurl($iconname);
1.154 albertel 14182: }
1.84 albertel 14183:
1.575 albertel 14184: sub lonhttpdurl {
1.692 www 14185: #
14186: # Had been used for "small fry" static images on separate port 8080.
14187: # Modify here if lightweight http functionality desired again.
14188: # Currently eliminated due to increasing firewall issues.
14189: #
1.575 albertel 14190: my ($url)=@_;
1.692 www 14191: return $url;
1.215 albertel 14192: }
14193:
1.213 albertel 14194: sub connection_aborted {
14195: my ($r)=@_;
14196: $r->print(" ");$r->rflush();
14197: my $c = $r->connection;
14198: return $c->aborted();
14199: }
14200:
1.221 foxr 14201: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14202: # strings as 'strings'.
14203: sub escape_single {
1.221 foxr 14204: my ($input) = @_;
1.223 albertel 14205: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14206: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14207: return $input;
14208: }
1.223 albertel 14209:
1.222 foxr 14210: # Same as escape_single, but escape's "'s This
14211: # can be used for "strings"
14212: sub escape_double {
14213: my ($input) = @_;
14214: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14215: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14216: return $input;
14217: }
1.223 albertel 14218:
1.222 foxr 14219: # Escapes the last element of a full URL.
14220: sub escape_url {
14221: my ($url) = @_;
1.238 raeburn 14222: my @urlslices = split(/\//, $url,-1);
1.369 www 14223: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14224: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14225: }
1.462 albertel 14226:
1.820 raeburn 14227: sub compare_arrays {
14228: my ($arrayref1,$arrayref2) = @_;
14229: my (@difference,%count);
14230: @difference = ();
14231: %count = ();
14232: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14233: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14234: foreach my $element (keys(%count)) {
14235: if ($count{$element} == 1) {
14236: push(@difference,$element);
14237: }
14238: }
14239: }
14240: return @difference;
14241: }
14242:
1.817 bisitz 14243: # -------------------------------------------------------- Initialize user login
1.462 albertel 14244: sub init_user_environment {
1.463 albertel 14245: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14246: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14247:
14248: my $public=($username eq 'public' && $domain eq 'public');
14249:
14250: # See if old ID present, if so, remove
14251:
1.1062 raeburn 14252: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14253: my $now=time;
14254:
14255: if ($public) {
14256: my $max_public=100;
14257: my $oldest;
14258: my $oldest_time=0;
14259: for(my $next=1;$next<=$max_public;$next++) {
14260: if (-e $lonids."/publicuser_$next.id") {
14261: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14262: if ($mtime<$oldest_time || !$oldest_time) {
14263: $oldest_time=$mtime;
14264: $oldest=$next;
14265: }
14266: } else {
14267: $cookie="publicuser_$next";
14268: last;
14269: }
14270: }
14271: if (!$cookie) { $cookie="publicuser_$oldest"; }
14272: } else {
1.463 albertel 14273: # if this isn't a robot, kill any existing non-robot sessions
14274: if (!$args->{'robot'}) {
14275: opendir(DIR,$lonids);
14276: while ($filename=readdir(DIR)) {
14277: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14278: unlink($lonids.'/'.$filename);
14279: }
1.462 albertel 14280: }
1.463 albertel 14281: closedir(DIR);
1.462 albertel 14282: }
14283: # Give them a new cookie
1.463 albertel 14284: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14285: : $now.$$.int(rand(10000)));
1.463 albertel 14286: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14287:
14288: # Initialize roles
14289:
1.1062 raeburn 14290: ($userroles,$firstaccenv,$timerintenv) =
14291: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14292: }
14293: # ------------------------------------ Check browser type and MathML capability
14294:
14295: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 ! raeburn 14296: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14297:
14298: # ------------------------------------------------------------- Get environment
14299:
14300: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14301: my ($tmp) = keys(%userenv);
14302: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14303: } else {
14304: undef(%userenv);
14305: }
14306: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14307: $form->{'interface'}=$userenv{'interface'};
14308: }
14309: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14310:
14311: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14312: foreach my $option ('interface','localpath','localres') {
14313: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14314: }
14315: # --------------------------------------------------------- Write first profile
14316:
14317: {
14318: my %initial_env =
14319: ("user.name" => $username,
14320: "user.domain" => $domain,
14321: "user.home" => $authhost,
14322: "browser.type" => $clientbrowser,
14323: "browser.version" => $clientversion,
14324: "browser.mathml" => $clientmathml,
14325: "browser.unicode" => $clientunicode,
14326: "browser.os" => $clientos,
1.1137 raeburn 14327: "browser.mobile" => $clientmobile,
1.1141 ! raeburn 14328: "browser.info" => $clientinfo,
1.462 albertel 14329: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14330: "request.course.fn" => '',
14331: "request.course.uri" => '',
14332: "request.course.sec" => '',
14333: "request.role" => 'cm',
14334: "request.role.adv" => $env{'user.adv'},
14335: "request.host" => $ENV{'REMOTE_ADDR'},);
14336:
14337: if ($form->{'localpath'}) {
14338: $initial_env{"browser.localpath"} = $form->{'localpath'};
14339: $initial_env{"browser.localres"} = $form->{'localres'};
14340: }
14341:
14342: if ($form->{'interface'}) {
14343: $form->{'interface'}=~s/\W//gs;
14344: $initial_env{"browser.interface"} = $form->{'interface'};
14345: $env{'browser.interface'}=$form->{'interface'};
14346: }
14347:
1.981 raeburn 14348: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14349: my %domdef;
14350: unless ($domain eq 'public') {
14351: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14352: }
1.980 raeburn 14353:
1.1081 raeburn 14354: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14355: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14356: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14357: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14358: }
14359:
1.864 raeburn 14360: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14361: $userenv{'canrequest.'.$crstype} =
14362: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14363: 'reload','requestcourses',
14364: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14365: }
14366:
1.1092 raeburn 14367: $userenv{'canrequest.author'} =
14368: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14369: 'reload','requestauthor',
14370: \%userenv,\%domdef,\%is_adv);
14371: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14372: $domain,$username);
14373: my $reqstatus = $reqauthor{'author_status'};
14374: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14375: if (ref($reqauthor{'author'}) eq 'HASH') {
14376: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14377: $reqauthor{'author'}{'timestamp'};
14378: }
14379: }
14380:
1.462 albertel 14381: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14382:
1.462 albertel 14383: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14384: &GDBM_WRCREAT(),0640)) {
14385: &_add_to_env(\%disk_env,\%initial_env);
14386: &_add_to_env(\%disk_env,\%userenv,'environment.');
14387: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14388: if (ref($firstaccenv) eq 'HASH') {
14389: &_add_to_env(\%disk_env,$firstaccenv);
14390: }
14391: if (ref($timerintenv) eq 'HASH') {
14392: &_add_to_env(\%disk_env,$timerintenv);
14393: }
1.463 albertel 14394: if (ref($args->{'extra_env'})) {
14395: &_add_to_env(\%disk_env,$args->{'extra_env'});
14396: }
1.462 albertel 14397: untie(%disk_env);
14398: } else {
1.705 tempelho 14399: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14400: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14401: return 'error: '.$!;
14402: }
14403: }
14404: $env{'request.role'}='cm';
14405: $env{'request.role.adv'}=$env{'user.adv'};
14406: $env{'browser.type'}=$clientbrowser;
14407:
14408: return $cookie;
14409:
14410: }
14411:
14412: sub _add_to_env {
14413: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14414: if (ref($env_data) eq 'HASH') {
14415: while (my ($key,$value) = each(%$env_data)) {
14416: $idf->{$prefix.$key} = $value;
14417: $env{$prefix.$key} = $value;
14418: }
1.462 albertel 14419: }
14420: }
14421:
1.685 tempelho 14422: # --- Get the symbolic name of a problem and the url
14423: sub get_symb {
14424: my ($request,$silent) = @_;
1.726 raeburn 14425: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14426: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14427: if ($symb eq '') {
14428: if (!$silent) {
1.1071 raeburn 14429: if (ref($request)) {
14430: $request->print("Unable to handle ambiguous references:$url:.");
14431: }
1.685 tempelho 14432: return ();
14433: }
14434: }
14435: &Apache::lonenc::check_decrypt(\$symb);
14436: return ($symb);
14437: }
14438:
14439: # --------------------------------------------------------------Get annotation
14440:
14441: sub get_annotation {
14442: my ($symb,$enc) = @_;
14443:
14444: my $key = $symb;
14445: if (!$enc) {
14446: $key =
14447: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14448: }
14449: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14450: return $annotation{$key};
14451: }
14452:
14453: sub clean_symb {
1.731 raeburn 14454: my ($symb,$delete_enc) = @_;
1.685 tempelho 14455:
14456: &Apache::lonenc::check_decrypt(\$symb);
14457: my $enc = $env{'request.enc'};
1.731 raeburn 14458: if ($delete_enc) {
1.730 raeburn 14459: delete($env{'request.enc'});
14460: }
1.685 tempelho 14461:
14462: return ($symb,$enc);
14463: }
1.462 albertel 14464:
1.990 raeburn 14465: sub build_release_hashes {
14466: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14467: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14468: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14469: (ref($randomizetry) eq 'HASH'));
14470: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14471: my ($item,$name,$value) = split(/:/,$key);
14472: if ($item eq 'parameter') {
14473: if (ref($checkparms->{$name}) eq 'ARRAY') {
14474: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14475: push(@{$checkparms->{$name}},$value);
14476: }
14477: } else {
14478: push(@{$checkparms->{$name}},$value);
14479: }
14480: } elsif ($item eq 'resourcetag') {
14481: if ($name eq 'responsetype') {
14482: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14483: }
14484: } elsif ($item eq 'course') {
14485: if ($name eq 'crstype') {
14486: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14487: }
14488: }
14489: }
14490: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14491: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14492: return;
14493: }
14494:
1.1083 raeburn 14495: sub update_content_constraints {
14496: my ($cdom,$cnum,$chome,$cid) = @_;
14497: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14498: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14499: my %checkresponsetypes;
14500: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14501: my ($item,$name,$value) = split(/:/,$key);
14502: if ($item eq 'resourcetag') {
14503: if ($name eq 'responsetype') {
14504: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14505: }
14506: }
14507: }
14508: my $navmap = Apache::lonnavmaps::navmap->new();
14509: if (defined($navmap)) {
14510: my %allresponses;
14511: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14512: my %responses = $res->responseTypes();
14513: foreach my $key (keys(%responses)) {
14514: next unless(exists($checkresponsetypes{$key}));
14515: $allresponses{$key} += $responses{$key};
14516: }
14517: }
14518: foreach my $key (keys(%allresponses)) {
14519: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14520: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14521: ($reqdmajor,$reqdminor) = ($major,$minor);
14522: }
14523: }
14524: undef($navmap);
14525: }
14526: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14527: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14528: }
14529: return;
14530: }
14531:
1.1110 raeburn 14532: sub allmaps_incourse {
14533: my ($cdom,$cnum,$chome,$cid) = @_;
14534: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14535: $cid = $env{'request.course.id'};
14536: $cdom = $env{'course.'.$cid.'.domain'};
14537: $cnum = $env{'course.'.$cid.'.num'};
14538: $chome = $env{'course.'.$cid.'.home'};
14539: }
14540: my %allmaps = ();
14541: my $lastchange =
14542: &Apache::lonnet::get_coursechange($cdom,$cnum);
14543: if ($lastchange > $env{'request.course.tied'}) {
14544: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14545: unless ($ferr) {
14546: &update_content_constraints($cdom,$cnum,$chome,$cid);
14547: }
14548: }
14549: my $navmap = Apache::lonnavmaps::navmap->new();
14550: if (defined($navmap)) {
14551: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14552: $allmaps{$res->src()} = 1;
14553: }
14554: }
14555: return \%allmaps;
14556: }
14557:
1.1083 raeburn 14558: sub parse_supplemental_title {
14559: my ($title) = @_;
14560:
14561: my ($foldertitle,$renametitle);
14562: if ($title =~ /&&&/) {
14563: $title = &HTML::Entites::decode($title);
14564: }
14565: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14566: $renametitle=$4;
14567: my ($time,$uname,$udom) = ($1,$2,$3);
14568: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14569: my $name = &plainname($uname,$udom);
14570: $name = &HTML::Entities::encode($name,'"<>&\'');
14571: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14572: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14573: $name.': <br />'.$foldertitle;
14574: }
14575: if (wantarray) {
14576: return ($title,$foldertitle,$renametitle);
14577: }
14578: return $title;
14579: }
14580:
1.1101 raeburn 14581: sub symb_to_docspath {
14582: my ($symb) = @_;
14583: return unless ($symb);
14584: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14585: if ($resurl=~/\.(sequence|page)$/) {
14586: $mapurl=$resurl;
14587: } elsif ($resurl eq 'adm/navmaps') {
14588: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14589: }
14590: my $mapresobj;
14591: my $navmap = Apache::lonnavmaps::navmap->new();
14592: if (ref($navmap)) {
14593: $mapresobj = $navmap->getResourceByUrl($mapurl);
14594: }
14595: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14596: my $type=$2;
14597: my $path;
14598: if (ref($mapresobj)) {
14599: my $pcslist = $mapresobj->map_hierarchy();
14600: if ($pcslist ne '') {
14601: foreach my $pc (split(/,/,$pcslist)) {
14602: next if ($pc <= 1);
14603: my $res = $navmap->getByMapPc($pc);
14604: if (ref($res)) {
14605: my $thisurl = $res->src();
14606: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14607: my $thistitle = $res->title();
14608: $path .= '&'.
14609: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14610: &Apache::lonhtmlcommon::entity_encode($thistitle).
14611: ':'.$res->randompick().
14612: ':'.$res->randomout().
14613: ':'.$res->encrypted().
14614: ':'.$res->randomorder().
14615: ':'.$res->is_page();
14616: }
14617: }
14618: }
14619: $path =~ s/^\&//;
14620: my $maptitle = $mapresobj->title();
14621: if ($mapurl eq 'default') {
1.1129 raeburn 14622: $maptitle = 'Main Content';
1.1101 raeburn 14623: }
14624: $path .= (($path ne '')? '&' : '').
14625: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14626: &Apache::lonhtmlcommon::entity_encode($maptitle).
14627: ':'.$mapresobj->randompick().
14628: ':'.$mapresobj->randomout().
14629: ':'.$mapresobj->encrypted().
14630: ':'.$mapresobj->randomorder().
14631: ':'.$mapresobj->is_page();
14632: } else {
14633: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14634: my $ispage = (($type eq 'page')? 1 : '');
14635: if ($mapurl eq 'default') {
1.1129 raeburn 14636: $maptitle = 'Main Content';
1.1101 raeburn 14637: }
14638: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14639: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14640: }
14641: unless ($mapurl eq 'default') {
14642: $path = 'default&'.
1.1129 raeburn 14643: &Apache::lonhtmlcommon::entity_encode('Main Content').
1.1101 raeburn 14644: ':::::&'.$path;
14645: }
14646: return $path;
14647: }
14648:
1.1094 raeburn 14649: sub captcha_display {
14650: my ($context,$lonhost) = @_;
14651: my ($output,$error);
14652: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14653: if ($captcha eq 'original') {
1.1094 raeburn 14654: $output = &create_captcha();
14655: unless ($output) {
14656: $error = 'captcha';
14657: }
14658: } elsif ($captcha eq 'recaptcha') {
14659: $output = &create_recaptcha($pubkey);
14660: unless ($output) {
1.1095 raeburn 14661: $error = 'recaptcha';
1.1094 raeburn 14662: }
14663: }
14664: return ($output,$error);
14665: }
14666:
14667: sub captcha_response {
14668: my ($context,$lonhost) = @_;
14669: my ($captcha_chk,$captcha_error);
14670: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14671: if ($captcha eq 'original') {
1.1094 raeburn 14672: ($captcha_chk,$captcha_error) = &check_captcha();
14673: } elsif ($captcha eq 'recaptcha') {
14674: $captcha_chk = &check_recaptcha($privkey);
14675: } else {
14676: $captcha_chk = 1;
14677: }
14678: return ($captcha_chk,$captcha_error);
14679: }
14680:
14681: sub get_captcha_config {
14682: my ($context,$lonhost) = @_;
1.1095 raeburn 14683: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14684: my $hostname = &Apache::lonnet::hostname($lonhost);
14685: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14686: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14687: if ($context eq 'usercreation') {
14688: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14689: if (ref($domconfig{$context}) eq 'HASH') {
14690: $hashtocheck = $domconfig{$context}{'cancreate'};
14691: if (ref($hashtocheck) eq 'HASH') {
14692: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14693: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14694: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14695: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14696: }
14697: if ($privkey && $pubkey) {
14698: $captcha = 'recaptcha';
14699: } else {
14700: $captcha = 'original';
14701: }
14702: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14703: $captcha = 'original';
14704: }
1.1094 raeburn 14705: }
1.1095 raeburn 14706: } else {
14707: $captcha = 'captcha';
14708: }
14709: } elsif ($context eq 'login') {
14710: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14711: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14712: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14713: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14714: if ($privkey && $pubkey) {
14715: $captcha = 'recaptcha';
1.1095 raeburn 14716: } else {
14717: $captcha = 'original';
1.1094 raeburn 14718: }
1.1095 raeburn 14719: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14720: $captcha = 'original';
1.1094 raeburn 14721: }
14722: }
14723: return ($captcha,$pubkey,$privkey);
14724: }
14725:
14726: sub create_captcha {
14727: my %captcha_params = &captcha_settings();
14728: my ($output,$maxtries,$tries) = ('',10,0);
14729: while ($tries < $maxtries) {
14730: $tries ++;
14731: my $captcha = Authen::Captcha->new (
14732: output_folder => $captcha_params{'output_dir'},
14733: data_folder => $captcha_params{'db_dir'},
14734: );
14735: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14736:
14737: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14738: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14739: &mt('Type in the letters/numbers shown below').' '.
14740: '<input type="text" size="5" name="code" value="" /><br />'.
14741: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14742: last;
14743: }
14744: }
14745: return $output;
14746: }
14747:
14748: sub captcha_settings {
14749: my %captcha_params = (
14750: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14751: www_output_dir => "/captchaspool",
14752: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14753: numchars => '5',
14754: );
14755: return %captcha_params;
14756: }
14757:
14758: sub check_captcha {
14759: my ($captcha_chk,$captcha_error);
14760: my $code = $env{'form.code'};
14761: my $md5sum = $env{'form.crypt'};
14762: my %captcha_params = &captcha_settings();
14763: my $captcha = Authen::Captcha->new(
14764: output_folder => $captcha_params{'output_dir'},
14765: data_folder => $captcha_params{'db_dir'},
14766: );
1.1109 raeburn 14767: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14768: my %captcha_hash = (
14769: 0 => 'Code not checked (file error)',
14770: -1 => 'Failed: code expired',
14771: -2 => 'Failed: invalid code (not in database)',
14772: -3 => 'Failed: invalid code (code does not match crypt)',
14773: );
14774: if ($captcha_chk != 1) {
14775: $captcha_error = $captcha_hash{$captcha_chk}
14776: }
14777: return ($captcha_chk,$captcha_error);
14778: }
14779:
14780: sub create_recaptcha {
14781: my ($pubkey) = @_;
14782: my $captcha = Captcha::reCAPTCHA->new;
14783: return $captcha->get_options_setter({theme => 'white'})."\n".
14784: $captcha->get_html($pubkey).
14785: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 14786: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 14787: '<br /><br />';
14788: }
14789:
14790: sub check_recaptcha {
14791: my ($privkey) = @_;
14792: my $captcha_chk;
14793: my $captcha = Captcha::reCAPTCHA->new;
14794: my $captcha_result =
14795: $captcha->check_answer(
14796: $privkey,
14797: $ENV{'REMOTE_ADDR'},
14798: $env{'form.recaptcha_challenge_field'},
14799: $env{'form.recaptcha_response_field'},
14800: );
14801: if ($captcha_result->{is_valid}) {
14802: $captcha_chk = 1;
14803: }
14804: return $captcha_chk;
14805: }
14806:
1.41 ng 14807: =pod
14808:
14809: =back
14810:
1.112 bowersj2 14811: =cut
1.41 ng 14812:
1.112 bowersj2 14813: 1;
14814: __END__;
1.41 ng 14815:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>