Annotation of loncom/interface/loncommon.pm, revision 1.1166
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1166 ! raeburn 4: # $Id: loncommon.pm,v 1.1165 2013/12/24 19:15:10 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
1.1159 raeburn 1391: <a href="$link" title="$title">$text</a>
1.436 albertel 1392: END
1393: }
1394:
1395: sub help_menu_js {
1.1154 raeburn 1396: my ($httphost) = @_;
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();
1.1154 raeburn 1401: my $details_link = $httphost.'/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,
1.1154 raeburn 1407: 'use_absolute' => $httphost,
1.331 albertel 1408: 'add_entries' => {
1409: 'border' => '0',
1.579 raeburn 1410: 'rows' => "110,*",},});
1.331 albertel 1411: my $end_page =
1412: &Apache::loncommon::end_page({'frameset' => 1,
1413: 'js_ready' => 1,});
1414:
1.436 albertel 1415: my $template .= <<"ENDTEMPLATE";
1416: <script type="text/javascript">
1.877 bisitz 1417: // <![CDATA[
1.253 albertel 1418: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1419: var banner_link = '';
1.243 raeburn 1420: function helpMenu(target) {
1421: var caller = this;
1422: if (target == 'open') {
1423: var newWindow = null;
1424: try {
1.262 albertel 1425: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1426: }
1427: catch(error) {
1428: writeHelp(caller);
1429: return;
1430: }
1431: if (newWindow) {
1432: caller = newWindow;
1433: }
1.193 raeburn 1434: }
1.243 raeburn 1435: writeHelp(caller);
1436: return;
1437: }
1438: function writeHelp(caller) {
1.1072 raeburn 1439: 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 1440: caller.document.close()
1441: caller.focus()
1.193 raeburn 1442: }
1.877 bisitz 1443: // END LON-CAPA Internal -->
1.253 albertel 1444: // ]]>
1.436 albertel 1445: </script>
1.193 raeburn 1446: ENDTEMPLATE
1447: return $template;
1448: }
1449:
1.172 www 1450: sub help_open_bug {
1451: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1452: unless ($env{'user.adv'}) { return ''; }
1.172 www 1453: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1454: $text = "" if (not defined $text);
1455: $stayOnPage=1;
1.184 albertel 1456: $width = 600 if (not defined $width);
1457: $height = 600 if (not defined $height);
1.172 www 1458:
1459: $topic=~s/\W+/\+/g;
1460: my $link='';
1461: my $template='';
1.379 albertel 1462: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1463: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1464: if (!$stayOnPage)
1465: {
1466: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1467: }
1468: else
1469: {
1470: $link = $url;
1471: }
1472: # Add the text
1473: if ($text ne "")
1474: {
1475: $template .=
1476: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1477: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1478: }
1479:
1480: # Add the graphic
1.179 matthew 1481: my $title = &mt('Report a Bug');
1.215 albertel 1482: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1483: $template .= <<"ENDTEMPLATE";
1.436 albertel 1484: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1485: ENDTEMPLATE
1486: if ($text ne '') { $template.='</td></tr></table>' };
1487: return $template;
1488:
1489: }
1490:
1491: sub help_open_faq {
1492: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1493: unless ($env{'user.adv'}) { return ''; }
1.172 www 1494: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1495: $text = "" if (not defined $text);
1496: $stayOnPage=1;
1497: $width = 350 if (not defined $width);
1498: $height = 400 if (not defined $height);
1499:
1500: $topic=~s/\W+/\+/g;
1501: my $link='';
1502: my $template='';
1503: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1504: if (!$stayOnPage)
1505: {
1506: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1507: }
1508: else
1509: {
1510: $link = $url;
1511: }
1512:
1513: # Add the text
1514: if ($text ne "")
1515: {
1516: $template .=
1.173 www 1517: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1518: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1519: }
1520:
1521: # Add the graphic
1.179 matthew 1522: my $title = &mt('View the FAQ');
1.215 albertel 1523: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1524: $template .= <<"ENDTEMPLATE";
1.436 albertel 1525: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1526: ENDTEMPLATE
1527: if ($text ne '') { $template.='</td></tr></table>' };
1528: return $template;
1529:
1.44 bowersj2 1530: }
1.37 matthew 1531:
1.180 matthew 1532: ###############################################################
1533: ###############################################################
1534:
1.45 matthew 1535: =pod
1536:
1.648 raeburn 1537: =item * &change_content_javascript():
1.256 matthew 1538:
1539: This and the next function allow you to create small sections of an
1540: otherwise static HTML page that you can update on the fly with
1541: Javascript, even in Netscape 4.
1542:
1543: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1544: must be written to the HTML page once. It will prove the Javascript
1545: function "change(name, content)". Calling the change function with the
1546: name of the section
1547: you want to update, matching the name passed to C<changable_area>, and
1548: the new content you want to put in there, will put the content into
1549: that area.
1550:
1551: B<Note>: Netscape 4 only reserves enough space for the changable area
1552: to contain room for the original contents. You need to "make space"
1553: for whatever changes you wish to make, and be B<sure> to check your
1554: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1555: it's adequate for updating a one-line status display, but little more.
1556: This script will set the space to 100% width, so you only need to
1557: worry about height in Netscape 4.
1558:
1559: Modern browsers are much less limiting, and if you can commit to the
1560: user not using Netscape 4, this feature may be used freely with
1561: pretty much any HTML.
1562:
1563: =cut
1564:
1565: sub change_content_javascript {
1566: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1567: if ($env{'browser.type'} eq 'netscape' &&
1568: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1569: return (<<NETSCAPE4);
1570: function change(name, content) {
1571: doc = document.layers[name+"___escape"].layers[0].document;
1572: doc.open();
1573: doc.write(content);
1574: doc.close();
1575: }
1576: NETSCAPE4
1577: } else {
1578: # Otherwise, we need to use semi-standards-compliant code
1579: # (technically, "innerHTML" isn't standard but the equivalent
1580: # is really scary, and every useful browser supports it
1581: return (<<DOMBASED);
1582: function change(name, content) {
1583: element = document.getElementById(name);
1584: element.innerHTML = content;
1585: }
1586: DOMBASED
1587: }
1588: }
1589:
1590: =pod
1591:
1.648 raeburn 1592: =item * &changable_area($name,$origContent):
1.256 matthew 1593:
1594: This provides a "changable area" that can be modified on the fly via
1595: the Javascript code provided in C<change_content_javascript>. $name is
1596: the name you will use to reference the area later; do not repeat the
1597: same name on a given HTML page more then once. $origContent is what
1598: the area will originally contain, which can be left blank.
1599:
1600: =cut
1601:
1602: sub changable_area {
1603: my ($name, $origContent) = @_;
1604:
1.258 albertel 1605: if ($env{'browser.type'} eq 'netscape' &&
1606: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1607: # If this is netscape 4, we need to use the Layer tag
1608: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1609: } else {
1610: return "<span id='$name'>$origContent</span>";
1611: }
1612: }
1613:
1614: =pod
1615:
1.648 raeburn 1616: =item * &viewport_geometry_js
1.590 raeburn 1617:
1618: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1619:
1620: =cut
1621:
1622:
1623: sub viewport_geometry_js {
1624: return <<"GEOMETRY";
1625: var Geometry = {};
1626: function init_geometry() {
1627: if (Geometry.init) { return };
1628: Geometry.init=1;
1629: if (window.innerHeight) {
1630: Geometry.getViewportHeight = function() { return window.innerHeight; };
1631: Geometry.getViewportWidth = function() { return window.innerWidth; };
1632: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1633: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1634: }
1635: else if (document.documentElement && document.documentElement.clientHeight) {
1636: Geometry.getViewportHeight =
1637: function() { return document.documentElement.clientHeight; };
1638: Geometry.getViewportWidth =
1639: function() { return document.documentElement.clientWidth; };
1640:
1641: Geometry.getHorizontalScroll =
1642: function() { return document.documentElement.scrollLeft; };
1643: Geometry.getVerticalScroll =
1644: function() { return document.documentElement.scrollTop; };
1645: }
1646: else if (document.body.clientHeight) {
1647: Geometry.getViewportHeight =
1648: function() { return document.body.clientHeight; };
1649: Geometry.getViewportWidth =
1650: function() { return document.body.clientWidth; };
1651: Geometry.getHorizontalScroll =
1652: function() { return document.body.scrollLeft; };
1653: Geometry.getVerticalScroll =
1654: function() { return document.body.scrollTop; };
1655: }
1656: }
1657:
1658: GEOMETRY
1659: }
1660:
1661: =pod
1662:
1.648 raeburn 1663: =item * &viewport_size_js()
1.590 raeburn 1664:
1665: 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.
1666:
1667: =cut
1668:
1669: sub viewport_size_js {
1670: my $geometry = &viewport_geometry_js();
1671: return <<"DIMS";
1672:
1673: $geometry
1674:
1675: function getViewportDims(width,height) {
1676: init_geometry();
1677: width.value = Geometry.getViewportWidth();
1678: height.value = Geometry.getViewportHeight();
1679: return;
1680: }
1681:
1682: DIMS
1683: }
1684:
1685: =pod
1686:
1.648 raeburn 1687: =item * &resize_textarea_js()
1.565 albertel 1688:
1689: emits the needed javascript to resize a textarea to be as big as possible
1690:
1691: creates a function resize_textrea that takes two IDs first should be
1692: the id of the element to resize, second should be the id of a div that
1693: surrounds everything that comes after the textarea, this routine needs
1694: to be attached to the <body> for the onload and onresize events.
1695:
1.648 raeburn 1696: =back
1.565 albertel 1697:
1698: =cut
1699:
1700: sub resize_textarea_js {
1.590 raeburn 1701: my $geometry = &viewport_geometry_js();
1.565 albertel 1702: return <<"RESIZE";
1703: <script type="text/javascript">
1.824 bisitz 1704: // <![CDATA[
1.590 raeburn 1705: $geometry
1.565 albertel 1706:
1.588 albertel 1707: function getX(element) {
1708: var x = 0;
1709: while (element) {
1710: x += element.offsetLeft;
1711: element = element.offsetParent;
1712: }
1713: return x;
1714: }
1715: function getY(element) {
1716: var y = 0;
1717: while (element) {
1718: y += element.offsetTop;
1719: element = element.offsetParent;
1720: }
1721: return y;
1722: }
1723:
1724:
1.565 albertel 1725: function resize_textarea(textarea_id,bottom_id) {
1726: init_geometry();
1727: var textarea = document.getElementById(textarea_id);
1728: //alert(textarea);
1729:
1.588 albertel 1730: var textarea_top = getY(textarea);
1.565 albertel 1731: var textarea_height = textarea.offsetHeight;
1732: var bottom = document.getElementById(bottom_id);
1.588 albertel 1733: var bottom_top = getY(bottom);
1.565 albertel 1734: var bottom_height = bottom.offsetHeight;
1735: var window_height = Geometry.getViewportHeight();
1.588 albertel 1736: var fudge = 23;
1.565 albertel 1737: var new_height = window_height-fudge-textarea_top-bottom_height;
1738: if (new_height < 300) {
1739: new_height = 300;
1740: }
1741: textarea.style.height=new_height+'px';
1742: }
1.824 bisitz 1743: // ]]>
1.565 albertel 1744: </script>
1745: RESIZE
1746:
1747: }
1748:
1749: =pod
1750:
1.256 matthew 1751: =head1 Excel and CSV file utility routines
1752:
1753: =cut
1754:
1755: ###############################################################
1756: ###############################################################
1757:
1758: =pod
1759:
1.1162 raeburn 1760: =over 4
1761:
1.648 raeburn 1762: =item * &csv_translate($text)
1.37 matthew 1763:
1.185 www 1764: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1765: format.
1766:
1767: =cut
1768:
1.180 matthew 1769: ###############################################################
1770: ###############################################################
1.37 matthew 1771: sub csv_translate {
1772: my $text = shift;
1773: $text =~ s/\"/\"\"/g;
1.209 albertel 1774: $text =~ s/\n/ /g;
1.37 matthew 1775: return $text;
1776: }
1.180 matthew 1777:
1778: ###############################################################
1779: ###############################################################
1780:
1781: =pod
1782:
1.648 raeburn 1783: =item * &define_excel_formats()
1.180 matthew 1784:
1785: Define some commonly used Excel cell formats.
1786:
1787: Currently supported formats:
1788:
1789: =over 4
1790:
1791: =item header
1792:
1793: =item bold
1794:
1795: =item h1
1796:
1797: =item h2
1798:
1799: =item h3
1800:
1.256 matthew 1801: =item h4
1802:
1803: =item i
1804:
1.180 matthew 1805: =item date
1806:
1807: =back
1808:
1809: Inputs: $workbook
1810:
1811: Returns: $format, a hash reference.
1812:
1.1057 foxr 1813:
1.180 matthew 1814: =cut
1815:
1816: ###############################################################
1817: ###############################################################
1818: sub define_excel_formats {
1819: my ($workbook) = @_;
1820: my $format;
1821: $format->{'header'} = $workbook->add_format(bold => 1,
1822: bottom => 1,
1823: align => 'center');
1824: $format->{'bold'} = $workbook->add_format(bold=>1);
1825: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1826: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1827: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1828: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1829: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1830: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1831: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1832: return $format;
1833: }
1834:
1835: ###############################################################
1836: ###############################################################
1.113 bowersj2 1837:
1838: =pod
1839:
1.648 raeburn 1840: =item * &create_workbook()
1.255 matthew 1841:
1842: Create an Excel worksheet. If it fails, output message on the
1843: request object and return undefs.
1844:
1845: Inputs: Apache request object
1846:
1847: Returns (undef) on failure,
1848: Excel worksheet object, scalar with filename, and formats
1849: from &Apache::loncommon::define_excel_formats on success
1850:
1851: =cut
1852:
1853: ###############################################################
1854: ###############################################################
1855: sub create_workbook {
1856: my ($r) = @_;
1857: #
1858: # Create the excel spreadsheet
1859: my $filename = '/prtspool/'.
1.258 albertel 1860: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1861: time.'_'.rand(1000000000).'.xls';
1862: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1863: if (! defined($workbook)) {
1864: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1865: $r->print(
1866: '<p class="LC_error">'
1867: .&mt('Problems occurred in creating the new Excel file.')
1868: .' '.&mt('This error has been logged.')
1869: .' '.&mt('Please alert your LON-CAPA administrator.')
1870: .'</p>'
1871: );
1.255 matthew 1872: return (undef);
1873: }
1874: #
1.1014 foxr 1875: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1876: #
1877: my $format = &Apache::loncommon::define_excel_formats($workbook);
1878: return ($workbook,$filename,$format);
1879: }
1880:
1881: ###############################################################
1882: ###############################################################
1883:
1884: =pod
1885:
1.648 raeburn 1886: =item * &create_text_file()
1.113 bowersj2 1887:
1.542 raeburn 1888: Create a file to write to and eventually make available to the user.
1.256 matthew 1889: If file creation fails, outputs an error message on the request object and
1890: return undefs.
1.113 bowersj2 1891:
1.256 matthew 1892: Inputs: Apache request object, and file suffix
1.113 bowersj2 1893:
1.256 matthew 1894: Returns (undef) on failure,
1895: Filehandle and filename on success.
1.113 bowersj2 1896:
1897: =cut
1898:
1.256 matthew 1899: ###############################################################
1900: ###############################################################
1901: sub create_text_file {
1902: my ($r,$suffix) = @_;
1903: if (! defined($suffix)) { $suffix = 'txt'; };
1904: my $fh;
1905: my $filename = '/prtspool/'.
1.258 albertel 1906: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1907: time.'_'.rand(1000000000).'.'.$suffix;
1908: $fh = Apache::File->new('>/home/httpd'.$filename);
1909: if (! defined($fh)) {
1910: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1911: $r->print(
1912: '<p class="LC_error">'
1913: .&mt('Problems occurred in creating the output file.')
1914: .' '.&mt('This error has been logged.')
1915: .' '.&mt('Please alert your LON-CAPA administrator.')
1916: .'</p>'
1917: );
1.113 bowersj2 1918: }
1.256 matthew 1919: return ($fh,$filename)
1.113 bowersj2 1920: }
1921:
1922:
1.256 matthew 1923: =pod
1.113 bowersj2 1924:
1925: =back
1926:
1927: =cut
1.37 matthew 1928:
1929: ###############################################################
1.33 matthew 1930: ## Home server <option> list generating code ##
1931: ###############################################################
1.35 matthew 1932:
1.169 www 1933: # ------------------------------------------
1934:
1935: sub domain_select {
1936: my ($name,$value,$multiple)=@_;
1937: my %domains=map {
1.514 albertel 1938: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1939: } &Apache::lonnet::all_domains();
1.169 www 1940: if ($multiple) {
1941: $domains{''}=&mt('Any domain');
1.550 albertel 1942: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1943: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1944: } else {
1.550 albertel 1945: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1946: return &select_form($name,$value,\%domains);
1.169 www 1947: }
1948: }
1949:
1.282 albertel 1950: #-------------------------------------------
1951:
1952: =pod
1953:
1.519 raeburn 1954: =head1 Routines for form select boxes
1955:
1956: =over 4
1957:
1.648 raeburn 1958: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1959:
1960: Returns a string containing a <select> element int multiple mode
1961:
1962:
1963: Args:
1964: $name - name of the <select> element
1.506 raeburn 1965: $value - scalar or array ref of values that should already be selected
1.282 albertel 1966: $size - number of rows long the select element is
1.283 albertel 1967: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1968: (shown text should already have been &mt())
1.506 raeburn 1969: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1970:
1.282 albertel 1971: =cut
1972:
1973: #-------------------------------------------
1.169 www 1974: sub multiple_select_form {
1.284 albertel 1975: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1976: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1977: my $output='';
1.191 matthew 1978: if (! defined($size)) {
1979: $size = 4;
1.283 albertel 1980: if (scalar(keys(%$hash))<4) {
1981: $size = scalar(keys(%$hash));
1.191 matthew 1982: }
1983: }
1.734 bisitz 1984: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1985: my @order;
1.506 raeburn 1986: if (ref($order) eq 'ARRAY') {
1987: @order = @{$order};
1988: } else {
1989: @order = sort(keys(%$hash));
1.501 banghart 1990: }
1991: if (exists($$hash{'select_form_order'})) {
1992: @order = @{$$hash{'select_form_order'}};
1993: }
1994:
1.284 albertel 1995: foreach my $key (@order) {
1.356 albertel 1996: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1997: $output.='selected="selected" ' if ($selected{$key});
1998: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1999: }
2000: $output.="</select>\n";
2001: return $output;
2002: }
2003:
1.88 www 2004: #-------------------------------------------
2005:
2006: =pod
2007:
1.970 raeburn 2008: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2009:
2010: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2011: allow a user to select options from a ref to a hash containing:
2012: option_name => displayed text. An optional $onchange can include
2013: a javascript onchange item, e.g., onchange="this.form.submit();"
2014:
1.88 www 2015: See lonrights.pm for an example invocation and use.
2016:
2017: =cut
2018:
2019: #-------------------------------------------
2020: sub select_form {
1.970 raeburn 2021: my ($def,$name,$hashref,$onchange) = @_;
2022: return unless (ref($hashref) eq 'HASH');
2023: if ($onchange) {
2024: $onchange = ' onchange="'.$onchange.'"';
2025: }
2026: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2027: my @keys;
1.970 raeburn 2028: if (exists($hashref->{'select_form_order'})) {
2029: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2030: } else {
1.970 raeburn 2031: @keys=sort(keys(%{$hashref}));
1.128 albertel 2032: }
1.356 albertel 2033: foreach my $key (@keys) {
2034: $selectform.=
2035: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2036: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2037: ">".$hashref->{$key}."</option>\n";
1.88 www 2038: }
2039: $selectform.="</select>";
2040: return $selectform;
2041: }
2042:
1.475 www 2043: # For display filters
2044:
2045: sub display_filter {
1.1074 raeburn 2046: my ($context) = @_;
1.475 www 2047: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2048: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2049: my $phraseinput = 'hidden';
2050: my $includeinput = 'hidden';
2051: my ($checked,$includetypestext);
2052: if ($env{'form.displayfilter'} eq 'containing') {
2053: $phraseinput = 'text';
2054: if ($context eq 'parmslog') {
2055: $includeinput = 'checkbox';
2056: if ($env{'form.includetypes'}) {
2057: $checked = ' checked="checked"';
2058: }
2059: $includetypestext = &mt('Include parameter types');
2060: }
2061: } else {
2062: $includetypestext = ' ';
2063: }
2064: my ($additional,$secondid,$thirdid);
2065: if ($context eq 'parmslog') {
2066: $additional =
2067: '<label><input type="'.$includeinput.'" name="includetypes"'.
2068: $checked.' name="includetypes" value="1" id="includetypes" />'.
2069: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2070: '</label>';
2071: $secondid = 'includetypes';
2072: $thirdid = 'includetypestext';
2073: }
2074: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2075: '$secondid','$thirdid')";
2076: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2077: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2078: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2079: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2080: &mt('Filter: [_1]',
1.477 www 2081: &select_form($env{'form.displayfilter'},
2082: 'displayfilter',
1.970 raeburn 2083: {'currentfolder' => 'Current folder/page',
1.477 www 2084: 'containing' => 'Containing phrase',
1.1074 raeburn 2085: 'none' => 'None'},$onchange)).' '.
2086: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2087: &HTML::Entities::encode($env{'form.containingphrase'}).
2088: '" />'.$additional;
2089: }
2090:
2091: sub display_filter_js {
2092: my $includetext = &mt('Include parameter types');
2093: return <<"ENDJS";
2094:
2095: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2096: var firstType = 'hidden';
2097: if (setter.options[setter.selectedIndex].value == 'containing') {
2098: firstType = 'text';
2099: }
2100: firstObject = document.getElementById(firstid);
2101: if (typeof(firstObject) == 'object') {
2102: if (firstObject.type != firstType) {
2103: changeInputType(firstObject,firstType);
2104: }
2105: }
2106: if (context == 'parmslog') {
2107: var secondType = 'hidden';
2108: if (firstType == 'text') {
2109: secondType = 'checkbox';
2110: }
2111: secondObject = document.getElementById(secondid);
2112: if (typeof(secondObject) == 'object') {
2113: if (secondObject.type != secondType) {
2114: changeInputType(secondObject,secondType);
2115: }
2116: }
2117: var textItem = document.getElementById(thirdid);
2118: var currtext = textItem.innerHTML;
2119: var newtext;
2120: if (firstType == 'text') {
2121: newtext = '$includetext';
2122: } else {
2123: newtext = ' ';
2124: }
2125: if (currtext != newtext) {
2126: textItem.innerHTML = newtext;
2127: }
2128: }
2129: return;
2130: }
2131:
2132: function changeInputType(oldObject,newType) {
2133: var newObject = document.createElement('input');
2134: newObject.type = newType;
2135: if (oldObject.size) {
2136: newObject.size = oldObject.size;
2137: }
2138: if (oldObject.value) {
2139: newObject.value = oldObject.value;
2140: }
2141: if (oldObject.name) {
2142: newObject.name = oldObject.name;
2143: }
2144: if (oldObject.id) {
2145: newObject.id = oldObject.id;
2146: }
2147: oldObject.parentNode.replaceChild(newObject,oldObject);
2148: return;
2149: }
2150:
2151: ENDJS
1.475 www 2152: }
2153:
1.167 www 2154: sub gradeleveldescription {
2155: my $gradelevel=shift;
2156: my %gradelevels=(0 => 'Not specified',
2157: 1 => 'Grade 1',
2158: 2 => 'Grade 2',
2159: 3 => 'Grade 3',
2160: 4 => 'Grade 4',
2161: 5 => 'Grade 5',
2162: 6 => 'Grade 6',
2163: 7 => 'Grade 7',
2164: 8 => 'Grade 8',
2165: 9 => 'Grade 9',
2166: 10 => 'Grade 10',
2167: 11 => 'Grade 11',
2168: 12 => 'Grade 12',
2169: 13 => 'Grade 13',
2170: 14 => '100 Level',
2171: 15 => '200 Level',
2172: 16 => '300 Level',
2173: 17 => '400 Level',
2174: 18 => 'Graduate Level');
2175: return &mt($gradelevels{$gradelevel});
2176: }
2177:
1.163 www 2178: sub select_level_form {
2179: my ($deflevel,$name)=@_;
2180: unless ($deflevel) { $deflevel=0; }
1.167 www 2181: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2182: for (my $i=0; $i<=18; $i++) {
2183: $selectform.="<option value=\"$i\" ".
1.253 albertel 2184: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2185: ">".&gradeleveldescription($i)."</option>\n";
2186: }
2187: $selectform.="</select>";
2188: return $selectform;
1.163 www 2189: }
1.167 www 2190:
1.35 matthew 2191: #-------------------------------------------
2192:
1.45 matthew 2193: =pod
2194:
1.1121 raeburn 2195: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2196:
2197: Returns a string containing a <select name='$name' size='1'> form to
2198: allow a user to select the domain to preform an operation in.
2199: See loncreateuser.pm for an example invocation and use.
2200:
1.90 www 2201: If the $includeempty flag is set, it also includes an empty choice ("no domain
2202: selected");
2203:
1.743 raeburn 2204: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2205:
1.910 raeburn 2206: 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.
2207:
1.1121 raeburn 2208: The optional $incdoms is a reference to an array of domains which will be the only available options.
2209:
2210: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2211:
1.35 matthew 2212: =cut
2213:
2214: #-------------------------------------------
1.34 matthew 2215: sub select_dom_form {
1.1121 raeburn 2216: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2217: if ($onchange) {
1.874 raeburn 2218: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2219: }
1.1121 raeburn 2220: my (@domains,%exclude);
1.910 raeburn 2221: if (ref($incdoms) eq 'ARRAY') {
2222: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2223: } else {
2224: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2225: }
1.90 www 2226: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2227: if (ref($excdoms) eq 'ARRAY') {
2228: map { $exclude{$_} = 1; } @{$excdoms};
2229: }
1.743 raeburn 2230: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2231: foreach my $dom (@domains) {
1.1121 raeburn 2232: next if ($exclude{$dom});
1.356 albertel 2233: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2234: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2235: if ($showdomdesc) {
2236: if ($dom ne '') {
2237: my $domdesc = &Apache::lonnet::domain($dom,'description');
2238: if ($domdesc ne '') {
2239: $selectdomain .= ' ('.$domdesc.')';
2240: }
2241: }
2242: }
2243: $selectdomain .= "</option>\n";
1.34 matthew 2244: }
2245: $selectdomain.="</select>";
2246: return $selectdomain;
2247: }
2248:
1.35 matthew 2249: #-------------------------------------------
2250:
1.45 matthew 2251: =pod
2252:
1.648 raeburn 2253: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2254:
1.586 raeburn 2255: input: 4 arguments (two required, two optional) -
2256: $domain - domain of new user
2257: $name - name of form element
2258: $default - Value of 'default' causes a default item to be first
2259: option, and selected by default.
2260: $hide - Value of 'hide' causes hiding of the name of the server,
2261: if 1 server found, or default, if 0 found.
1.594 raeburn 2262: output: returns 2 items:
1.586 raeburn 2263: (a) form element which contains either:
2264: (i) <select name="$name">
2265: <option value="$hostid1">$hostid $servers{$hostid}</option>
2266: <option value="$hostid2">$hostid $servers{$hostid}</option>
2267: </select>
2268: form item if there are multiple library servers in $domain, or
2269: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2270: if there is only one library server in $domain.
2271:
2272: (b) number of library servers found.
2273:
2274: See loncreateuser.pm for example of use.
1.35 matthew 2275:
2276: =cut
2277:
2278: #-------------------------------------------
1.586 raeburn 2279: sub home_server_form_item {
2280: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2281: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2282: my $result;
2283: my $numlib = keys(%servers);
2284: if ($numlib > 1) {
2285: $result .= '<select name="'.$name.'" />'."\n";
2286: if ($default) {
1.804 bisitz 2287: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2288: '</option>'."\n";
2289: }
2290: foreach my $hostid (sort(keys(%servers))) {
2291: $result.= '<option value="'.$hostid.'">'.
2292: $hostid.' '.$servers{$hostid}."</option>\n";
2293: }
2294: $result .= '</select>'."\n";
2295: } elsif ($numlib == 1) {
2296: my $hostid;
2297: foreach my $item (keys(%servers)) {
2298: $hostid = $item;
2299: }
2300: $result .= '<input type="hidden" name="'.$name.'" value="'.
2301: $hostid.'" />';
2302: if (!$hide) {
2303: $result .= $hostid.' '.$servers{$hostid};
2304: }
2305: $result .= "\n";
2306: } elsif ($default) {
2307: $result .= '<input type="hidden" name="'.$name.
2308: '" value="default" />';
2309: if (!$hide) {
2310: $result .= &mt('default');
2311: }
2312: $result .= "\n";
1.33 matthew 2313: }
1.586 raeburn 2314: return ($result,$numlib);
1.33 matthew 2315: }
1.112 bowersj2 2316:
2317: =pod
2318:
1.534 albertel 2319: =back
2320:
1.112 bowersj2 2321: =cut
1.87 matthew 2322:
2323: ###############################################################
1.112 bowersj2 2324: ## Decoding User Agent ##
1.87 matthew 2325: ###############################################################
2326:
2327: =pod
2328:
1.112 bowersj2 2329: =head1 Decoding the User Agent
2330:
2331: =over 4
2332:
2333: =item * &decode_user_agent()
1.87 matthew 2334:
2335: Inputs: $r
2336:
2337: Outputs:
2338:
2339: =over 4
2340:
1.112 bowersj2 2341: =item * $httpbrowser
1.87 matthew 2342:
1.112 bowersj2 2343: =item * $clientbrowser
1.87 matthew 2344:
1.112 bowersj2 2345: =item * $clientversion
1.87 matthew 2346:
1.112 bowersj2 2347: =item * $clientmathml
1.87 matthew 2348:
1.112 bowersj2 2349: =item * $clientunicode
1.87 matthew 2350:
1.112 bowersj2 2351: =item * $clientos
1.87 matthew 2352:
1.1137 raeburn 2353: =item * $clientmobile
2354:
1.1141 raeburn 2355: =item * $clientinfo
2356:
1.87 matthew 2357: =back
2358:
1.157 matthew 2359: =back
2360:
1.87 matthew 2361: =cut
2362:
2363: ###############################################################
2364: ###############################################################
2365: sub decode_user_agent {
1.247 albertel 2366: my ($r)=@_;
1.87 matthew 2367: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2368: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2369: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2370: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2371: my $clientbrowser='unknown';
2372: my $clientversion='0';
2373: my $clientmathml='';
2374: my $clientunicode='0';
1.1137 raeburn 2375: my $clientmobile=0;
1.87 matthew 2376: for (my $i=0;$i<=$#browsertype;$i++) {
2377: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2378: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2379: $clientbrowser=$bname;
2380: $httpbrowser=~/$vreg/i;
2381: $clientversion=$1;
2382: $clientmathml=($clientversion>=$minv);
2383: $clientunicode=($clientversion>=$univ);
2384: }
2385: }
2386: my $clientos='unknown';
1.1141 raeburn 2387: my $clientinfo;
1.87 matthew 2388: if (($httpbrowser=~/linux/i) ||
2389: ($httpbrowser=~/unix/i) ||
2390: ($httpbrowser=~/ux/i) ||
2391: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2392: if (($httpbrowser=~/vax/i) ||
2393: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2394: if ($httpbrowser=~/next/i) { $clientos='next'; }
2395: if (($httpbrowser=~/mac/i) ||
2396: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2397: if ($httpbrowser=~/win/i) { $clientos='win'; }
2398: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2399: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2400: $clientmobile=lc($1);
2401: }
1.1141 raeburn 2402: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2403: $clientinfo = 'firefox-'.$1;
2404: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2405: $clientinfo = 'chromeframe-'.$1;
2406: }
1.87 matthew 2407: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 2408: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2409: }
2410:
1.32 matthew 2411: ###############################################################
2412: ## Authentication changing form generation subroutines ##
2413: ###############################################################
2414: ##
2415: ## All of the authform_xxxxxxx subroutines take their inputs in a
2416: ## hash, and have reasonable default values.
2417: ##
2418: ## formname = the name given in the <form> tag.
1.35 matthew 2419: #-------------------------------------------
2420:
1.45 matthew 2421: =pod
2422:
1.112 bowersj2 2423: =head1 Authentication Routines
2424:
2425: =over 4
2426:
1.648 raeburn 2427: =item * &authform_xxxxxx()
1.35 matthew 2428:
2429: The authform_xxxxxx subroutines provide javascript and html forms which
2430: handle some of the conveniences required for authentication forms.
2431: This is not an optimal method, but it works.
2432:
2433: =over 4
2434:
1.112 bowersj2 2435: =item * authform_header
1.35 matthew 2436:
1.112 bowersj2 2437: =item * authform_authorwarning
1.35 matthew 2438:
1.112 bowersj2 2439: =item * authform_nochange
1.35 matthew 2440:
1.112 bowersj2 2441: =item * authform_kerberos
1.35 matthew 2442:
1.112 bowersj2 2443: =item * authform_internal
1.35 matthew 2444:
1.112 bowersj2 2445: =item * authform_filesystem
1.35 matthew 2446:
2447: =back
2448:
1.648 raeburn 2449: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2450:
1.35 matthew 2451: =cut
2452:
2453: #-------------------------------------------
1.32 matthew 2454: sub authform_header{
2455: my %in = (
2456: formname => 'cu',
1.80 albertel 2457: kerb_def_dom => '',
1.32 matthew 2458: @_,
2459: );
2460: $in{'formname'} = 'document.' . $in{'formname'};
2461: my $result='';
1.80 albertel 2462:
2463: #---------------------------------------------- Code for upper case translation
2464: my $Javascript_toUpperCase;
2465: unless ($in{kerb_def_dom}) {
2466: $Javascript_toUpperCase =<<"END";
2467: switch (choice) {
2468: case 'krb': currentform.elements[choicearg].value =
2469: currentform.elements[choicearg].value.toUpperCase();
2470: break;
2471: default:
2472: }
2473: END
2474: } else {
2475: $Javascript_toUpperCase = "";
2476: }
2477:
1.165 raeburn 2478: my $radioval = "'nochange'";
1.591 raeburn 2479: if (defined($in{'curr_authtype'})) {
2480: if ($in{'curr_authtype'} ne '') {
2481: $radioval = "'".$in{'curr_authtype'}."arg'";
2482: }
1.174 matthew 2483: }
1.165 raeburn 2484: my $argfield = 'null';
1.591 raeburn 2485: if (defined($in{'mode'})) {
1.165 raeburn 2486: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2487: if (defined($in{'curr_autharg'})) {
2488: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2489: $argfield = "'$in{'curr_autharg'}'";
2490: }
2491: }
2492: }
2493: }
2494:
1.32 matthew 2495: $result.=<<"END";
2496: var current = new Object();
1.165 raeburn 2497: current.radiovalue = $radioval;
2498: current.argfield = $argfield;
1.32 matthew 2499:
2500: function changed_radio(choice,currentform) {
2501: var choicearg = choice + 'arg';
2502: // If a radio button in changed, we need to change the argfield
2503: if (current.radiovalue != choice) {
2504: current.radiovalue = choice;
2505: if (current.argfield != null) {
2506: currentform.elements[current.argfield].value = '';
2507: }
2508: if (choice == 'nochange') {
2509: current.argfield = null;
2510: } else {
2511: current.argfield = choicearg;
2512: switch(choice) {
2513: case 'krb':
2514: currentform.elements[current.argfield].value =
2515: "$in{'kerb_def_dom'}";
2516: break;
2517: default:
2518: break;
2519: }
2520: }
2521: }
2522: return;
2523: }
1.22 www 2524:
1.32 matthew 2525: function changed_text(choice,currentform) {
2526: var choicearg = choice + 'arg';
2527: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2528: $Javascript_toUpperCase
1.32 matthew 2529: // clear old field
2530: if ((current.argfield != choicearg) && (current.argfield != null)) {
2531: currentform.elements[current.argfield].value = '';
2532: }
2533: current.argfield = choicearg;
2534: }
2535: set_auth_radio_buttons(choice,currentform);
2536: return;
1.20 www 2537: }
1.32 matthew 2538:
2539: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2540: var numauthchoices = currentform.login.length;
2541: if (typeof numauthchoices == "undefined") {
2542: return;
2543: }
1.32 matthew 2544: var i=0;
1.986 raeburn 2545: while (i < numauthchoices) {
1.32 matthew 2546: if (currentform.login[i].value == newvalue) { break; }
2547: i++;
2548: }
1.986 raeburn 2549: if (i == numauthchoices) {
1.32 matthew 2550: return;
2551: }
2552: current.radiovalue = newvalue;
2553: currentform.login[i].checked = true;
2554: return;
2555: }
2556: END
2557: return $result;
2558: }
2559:
1.1106 raeburn 2560: sub authform_authorwarning {
1.32 matthew 2561: my $result='';
1.144 matthew 2562: $result='<i>'.
2563: &mt('As a general rule, only authors or co-authors should be '.
2564: 'filesystem authenticated '.
2565: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2566: return $result;
2567: }
2568:
1.1106 raeburn 2569: sub authform_nochange {
1.32 matthew 2570: my %in = (
2571: formname => 'document.cu',
2572: kerb_def_dom => 'MSU.EDU',
2573: @_,
2574: );
1.1106 raeburn 2575: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2576: my $result;
1.1104 raeburn 2577: if (!$authnum) {
1.1105 raeburn 2578: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2579: } else {
2580: $result = '<label>'.&mt('[_1] Do not change login data',
2581: '<input type="radio" name="login" value="nochange" '.
2582: 'checked="checked" onclick="'.
1.281 albertel 2583: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2584: '</label>';
1.586 raeburn 2585: }
1.32 matthew 2586: return $result;
2587: }
2588:
1.591 raeburn 2589: sub authform_kerberos {
1.32 matthew 2590: my %in = (
2591: formname => 'document.cu',
2592: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2593: kerb_def_auth => 'krb4',
1.32 matthew 2594: @_,
2595: );
1.586 raeburn 2596: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2597: $autharg,$jscall);
1.1106 raeburn 2598: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2599: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2600: $check5 = ' checked="checked"';
1.80 albertel 2601: } else {
1.772 bisitz 2602: $check4 = ' checked="checked"';
1.80 albertel 2603: }
1.165 raeburn 2604: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2605: if (defined($in{'curr_authtype'})) {
2606: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2607: $krbcheck = ' checked="checked"';
1.623 raeburn 2608: if (defined($in{'mode'})) {
2609: if ($in{'mode'} eq 'modifyuser') {
2610: $krbcheck = '';
2611: }
2612: }
1.591 raeburn 2613: if (defined($in{'curr_kerb_ver'})) {
2614: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2615: $check5 = ' checked="checked"';
1.591 raeburn 2616: $check4 = '';
2617: } else {
1.772 bisitz 2618: $check4 = ' checked="checked"';
1.591 raeburn 2619: $check5 = '';
2620: }
1.586 raeburn 2621: }
1.591 raeburn 2622: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2623: $krbarg = $in{'curr_autharg'};
2624: }
1.586 raeburn 2625: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2626: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2627: $result =
2628: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2629: $in{'curr_autharg'},$krbver);
2630: } else {
2631: $result =
2632: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2633: }
2634: return $result;
2635: }
2636: }
2637: } else {
2638: if ($authnum == 1) {
1.784 bisitz 2639: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2640: }
2641: }
1.586 raeburn 2642: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2643: return;
1.587 raeburn 2644: } elsif ($authtype eq '') {
1.591 raeburn 2645: if (defined($in{'mode'})) {
1.587 raeburn 2646: if ($in{'mode'} eq 'modifycourse') {
2647: if ($authnum == 1) {
1.1104 raeburn 2648: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2649: }
2650: }
2651: }
1.586 raeburn 2652: }
2653: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2654: if ($authtype eq '') {
2655: $authtype = '<input type="radio" name="login" value="krb" '.
2656: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2657: $krbcheck.' />';
2658: }
2659: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2660: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2661: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2662: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2663: $in{'curr_authtype'} eq 'krb4')) {
2664: $result .= &mt
1.144 matthew 2665: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2666: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2667: '<label>'.$authtype,
1.281 albertel 2668: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2669: 'value="'.$krbarg.'" '.
1.144 matthew 2670: 'onchange="'.$jscall.'" />',
1.281 albertel 2671: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2672: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2673: '</label>');
1.586 raeburn 2674: } elsif ($can_assign{'krb4'}) {
2675: $result .= &mt
2676: ('[_1] Kerberos authenticated with domain [_2] '.
2677: '[_3] Version 4 [_4]',
2678: '<label>'.$authtype,
2679: '</label><input type="text" size="10" name="krbarg" '.
2680: 'value="'.$krbarg.'" '.
2681: 'onchange="'.$jscall.'" />',
2682: '<label><input type="hidden" name="krbver" value="4" />',
2683: '</label>');
2684: } elsif ($can_assign{'krb5'}) {
2685: $result .= &mt
2686: ('[_1] Kerberos authenticated with domain [_2] '.
2687: '[_3] Version 5 [_4]',
2688: '<label>'.$authtype,
2689: '</label><input type="text" size="10" name="krbarg" '.
2690: 'value="'.$krbarg.'" '.
2691: 'onchange="'.$jscall.'" />',
2692: '<label><input type="hidden" name="krbver" value="5" />',
2693: '</label>');
2694: }
1.32 matthew 2695: return $result;
2696: }
2697:
1.1106 raeburn 2698: sub authform_internal {
1.586 raeburn 2699: my %in = (
1.32 matthew 2700: formname => 'document.cu',
2701: kerb_def_dom => 'MSU.EDU',
2702: @_,
2703: );
1.586 raeburn 2704: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2705: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2706: if (defined($in{'curr_authtype'})) {
2707: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2708: if ($can_assign{'int'}) {
1.772 bisitz 2709: $intcheck = 'checked="checked" ';
1.623 raeburn 2710: if (defined($in{'mode'})) {
2711: if ($in{'mode'} eq 'modifyuser') {
2712: $intcheck = '';
2713: }
2714: }
1.591 raeburn 2715: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2716: $intarg = $in{'curr_autharg'};
2717: }
2718: } else {
2719: $result = &mt('Currently internally authenticated.');
2720: return $result;
1.165 raeburn 2721: }
2722: }
1.586 raeburn 2723: } else {
2724: if ($authnum == 1) {
1.784 bisitz 2725: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2726: }
2727: }
2728: if (!$can_assign{'int'}) {
2729: return;
1.587 raeburn 2730: } elsif ($authtype eq '') {
1.591 raeburn 2731: if (defined($in{'mode'})) {
1.587 raeburn 2732: if ($in{'mode'} eq 'modifycourse') {
2733: if ($authnum == 1) {
1.1104 raeburn 2734: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2735: }
2736: }
2737: }
1.165 raeburn 2738: }
1.586 raeburn 2739: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2740: if ($authtype eq '') {
2741: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2742: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2743: }
1.605 bisitz 2744: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2745: $intarg.'" onchange="'.$jscall.'" />';
2746: $result = &mt
1.144 matthew 2747: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2748: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2749: $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 2750: return $result;
2751: }
2752:
1.1104 raeburn 2753: sub authform_local {
1.32 matthew 2754: my %in = (
2755: formname => 'document.cu',
2756: kerb_def_dom => 'MSU.EDU',
2757: @_,
2758: );
1.586 raeburn 2759: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2760: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2761: if (defined($in{'curr_authtype'})) {
2762: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2763: if ($can_assign{'loc'}) {
1.772 bisitz 2764: $loccheck = 'checked="checked" ';
1.623 raeburn 2765: if (defined($in{'mode'})) {
2766: if ($in{'mode'} eq 'modifyuser') {
2767: $loccheck = '';
2768: }
2769: }
1.591 raeburn 2770: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2771: $locarg = $in{'curr_autharg'};
2772: }
2773: } else {
2774: $result = &mt('Currently using local (institutional) authentication.');
2775: return $result;
1.165 raeburn 2776: }
2777: }
1.586 raeburn 2778: } else {
2779: if ($authnum == 1) {
1.784 bisitz 2780: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2781: }
2782: }
2783: if (!$can_assign{'loc'}) {
2784: return;
1.587 raeburn 2785: } elsif ($authtype eq '') {
1.591 raeburn 2786: if (defined($in{'mode'})) {
1.587 raeburn 2787: if ($in{'mode'} eq 'modifycourse') {
2788: if ($authnum == 1) {
1.1104 raeburn 2789: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2790: }
2791: }
2792: }
1.165 raeburn 2793: }
1.586 raeburn 2794: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2795: if ($authtype eq '') {
2796: $authtype = '<input type="radio" name="login" value="loc" '.
2797: $loccheck.' onchange="'.$jscall.'" onclick="'.
2798: $jscall.'" />';
2799: }
2800: $autharg = '<input type="text" size="10" name="locarg" value="'.
2801: $locarg.'" onchange="'.$jscall.'" />';
2802: $result = &mt('[_1] Local Authentication with argument [_2]',
2803: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2804: return $result;
2805: }
2806:
1.1106 raeburn 2807: sub authform_filesystem {
1.32 matthew 2808: my %in = (
2809: formname => 'document.cu',
2810: kerb_def_dom => 'MSU.EDU',
2811: @_,
2812: );
1.586 raeburn 2813: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2814: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2815: if (defined($in{'curr_authtype'})) {
2816: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2817: if ($can_assign{'fsys'}) {
1.772 bisitz 2818: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2819: if (defined($in{'mode'})) {
2820: if ($in{'mode'} eq 'modifyuser') {
2821: $fsyscheck = '';
2822: }
2823: }
1.586 raeburn 2824: } else {
2825: $result = &mt('Currently Filesystem Authenticated.');
2826: return $result;
2827: }
2828: }
2829: } else {
2830: if ($authnum == 1) {
1.784 bisitz 2831: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2832: }
2833: }
2834: if (!$can_assign{'fsys'}) {
2835: return;
1.587 raeburn 2836: } elsif ($authtype eq '') {
1.591 raeburn 2837: if (defined($in{'mode'})) {
1.587 raeburn 2838: if ($in{'mode'} eq 'modifycourse') {
2839: if ($authnum == 1) {
1.1104 raeburn 2840: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2841: }
2842: }
2843: }
1.586 raeburn 2844: }
2845: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2846: if ($authtype eq '') {
2847: $authtype = '<input type="radio" name="login" value="fsys" '.
2848: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2849: $jscall.'" />';
2850: }
2851: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2852: ' onchange="'.$jscall.'" />';
2853: $result = &mt
1.144 matthew 2854: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2855: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2856: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2857: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2858: 'onchange="'.$jscall.'" />');
1.32 matthew 2859: return $result;
2860: }
2861:
1.586 raeburn 2862: sub get_assignable_auth {
2863: my ($dom) = @_;
2864: if ($dom eq '') {
2865: $dom = $env{'request.role.domain'};
2866: }
2867: my %can_assign = (
2868: krb4 => 1,
2869: krb5 => 1,
2870: int => 1,
2871: loc => 1,
2872: );
2873: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2874: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2875: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2876: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2877: my $context;
2878: if ($env{'request.role'} =~ /^au/) {
2879: $context = 'author';
2880: } elsif ($env{'request.role'} =~ /^dc/) {
2881: $context = 'domain';
2882: } elsif ($env{'request.course.id'}) {
2883: $context = 'course';
2884: }
2885: if ($context) {
2886: if (ref($authhash->{$context}) eq 'HASH') {
2887: %can_assign = %{$authhash->{$context}};
2888: }
2889: }
2890: }
2891: }
2892: my $authnum = 0;
2893: foreach my $key (keys(%can_assign)) {
2894: if ($can_assign{$key}) {
2895: $authnum ++;
2896: }
2897: }
2898: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2899: $authnum --;
2900: }
2901: return ($authnum,%can_assign);
2902: }
2903:
1.80 albertel 2904: ###############################################################
2905: ## Get Kerberos Defaults for Domain ##
2906: ###############################################################
2907: ##
2908: ## Returns default kerberos version and an associated argument
2909: ## as listed in file domain.tab. If not listed, provides
2910: ## appropriate default domain and kerberos version.
2911: ##
2912: #-------------------------------------------
2913:
2914: =pod
2915:
1.648 raeburn 2916: =item * &get_kerberos_defaults()
1.80 albertel 2917:
2918: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2919: version and domain. If not found, it defaults to version 4 and the
2920: domain of the server.
1.80 albertel 2921:
1.648 raeburn 2922: =over 4
2923:
1.80 albertel 2924: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2925:
1.648 raeburn 2926: =back
2927:
2928: =back
2929:
1.80 albertel 2930: =cut
2931:
2932: #-------------------------------------------
2933: sub get_kerberos_defaults {
2934: my $domain=shift;
1.641 raeburn 2935: my ($krbdef,$krbdefdom);
2936: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2937: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2938: $krbdef = $domdefaults{'auth_def'};
2939: $krbdefdom = $domdefaults{'auth_arg_def'};
2940: } else {
1.80 albertel 2941: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2942: my $krbdefdom=$1;
2943: $krbdefdom=~tr/a-z/A-Z/;
2944: $krbdef = "krb4";
2945: }
2946: return ($krbdef,$krbdefdom);
2947: }
1.112 bowersj2 2948:
1.32 matthew 2949:
1.46 matthew 2950: ###############################################################
2951: ## Thesaurus Functions ##
2952: ###############################################################
1.20 www 2953:
1.46 matthew 2954: =pod
1.20 www 2955:
1.112 bowersj2 2956: =head1 Thesaurus Functions
2957:
2958: =over 4
2959:
1.648 raeburn 2960: =item * &initialize_keywords()
1.46 matthew 2961:
2962: Initializes the package variable %Keywords if it is empty. Uses the
2963: package variable $thesaurus_db_file.
2964:
2965: =cut
2966:
2967: ###################################################
2968:
2969: sub initialize_keywords {
2970: return 1 if (scalar keys(%Keywords));
2971: # If we are here, %Keywords is empty, so fill it up
2972: # Make sure the file we need exists...
2973: if (! -e $thesaurus_db_file) {
2974: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2975: " failed because it does not exist");
2976: return 0;
2977: }
2978: # Set up the hash as a database
2979: my %thesaurus_db;
2980: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2981: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2982: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2983: $thesaurus_db_file);
2984: return 0;
2985: }
2986: # Get the average number of appearances of a word.
2987: my $avecount = $thesaurus_db{'average.count'};
2988: # Put keywords (those that appear > average) into %Keywords
2989: while (my ($word,$data)=each (%thesaurus_db)) {
2990: my ($count,undef) = split /:/,$data;
2991: $Keywords{$word}++ if ($count > $avecount);
2992: }
2993: untie %thesaurus_db;
2994: # Remove special values from %Keywords.
1.356 albertel 2995: foreach my $value ('total.count','average.count') {
2996: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2997: }
1.46 matthew 2998: return 1;
2999: }
3000:
3001: ###################################################
3002:
3003: =pod
3004:
1.648 raeburn 3005: =item * &keyword($word)
1.46 matthew 3006:
3007: Returns true if $word is a keyword. A keyword is a word that appears more
3008: than the average number of times in the thesaurus database. Calls
3009: &initialize_keywords
3010:
3011: =cut
3012:
3013: ###################################################
1.20 www 3014:
3015: sub keyword {
1.46 matthew 3016: return if (!&initialize_keywords());
3017: my $word=lc(shift());
3018: $word=~s/\W//g;
3019: return exists($Keywords{$word});
1.20 www 3020: }
1.46 matthew 3021:
3022: ###############################################################
3023:
3024: =pod
1.20 www 3025:
1.648 raeburn 3026: =item * &get_related_words()
1.46 matthew 3027:
1.160 matthew 3028: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3029: an array of words. If the keyword is not in the thesaurus, an empty array
3030: will be returned. The order of the words returned is determined by the
3031: database which holds them.
3032:
3033: Uses global $thesaurus_db_file.
3034:
1.1057 foxr 3035:
1.46 matthew 3036: =cut
3037:
3038: ###############################################################
3039: sub get_related_words {
3040: my $keyword = shift;
3041: my %thesaurus_db;
3042: if (! -e $thesaurus_db_file) {
3043: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3044: "failed because the file does not exist");
3045: return ();
3046: }
3047: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3048: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3049: return ();
3050: }
3051: my @Words=();
1.429 www 3052: my $count=0;
1.46 matthew 3053: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3054: # The first element is the number of times
3055: # the word appears. We do not need it now.
1.429 www 3056: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3057: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3058: my $threshold=$mostfrequentcount/10;
3059: foreach my $possibleword (@RelatedWords) {
3060: my ($word,$wordcount)=split(/\,/,$possibleword);
3061: if ($wordcount>$threshold) {
3062: push(@Words,$word);
3063: $count++;
3064: if ($count>10) { last; }
3065: }
1.20 www 3066: }
3067: }
1.46 matthew 3068: untie %thesaurus_db;
3069: return @Words;
1.14 harris41 3070: }
1.1090 foxr 3071: ###############################################################
3072: #
3073: # Spell checking
3074: #
3075:
3076: =pod
3077:
1.1142 raeburn 3078: =back
3079:
1.1090 foxr 3080: =head1 Spell checking
3081:
3082: =over 4
3083:
3084: =item * &check_spelling($wordlist $language)
3085:
3086: Takes a string containing words and feeds it to an external
3087: spellcheck program via a pipeline. Returns a string containing
3088: them mis-spelled words.
3089:
3090: Parameters:
3091:
3092: =over 4
3093:
3094: =item - $wordlist
3095:
3096: String that will be fed into the spellcheck program.
3097:
3098: =item - $language
3099:
3100: Language string that specifies the language for which the spell
3101: check will be performed.
3102:
3103: =back
3104:
3105: =back
3106:
3107: Note: This sub assumes that aspell is installed.
3108:
3109:
3110: =cut
3111:
1.46 matthew 3112:
1.1090 foxr 3113: sub check_spelling {
3114: my ($wordlist, $language) = @_;
1.1091 foxr 3115: my @misspellings;
3116:
3117: # Generate the speller and set the langauge.
3118: # if explicitly selected:
1.1090 foxr 3119:
1.1091 foxr 3120: my $speller = Text::Aspell->new;
1.1090 foxr 3121: if ($language) {
1.1091 foxr 3122: $speller->set_option('lang', $language);
1.1090 foxr 3123: }
3124:
1.1091 foxr 3125: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3126:
1.1091 foxr 3127: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3128:
1.1091 foxr 3129: foreach my $word (@words) {
3130: if(! $speller->check($word)) {
3131: push(@misspellings, $word);
1.1090 foxr 3132: }
3133: }
1.1091 foxr 3134: return join(' ', @misspellings);
3135:
1.1090 foxr 3136: }
3137:
1.61 www 3138: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3139: =pod
3140:
1.112 bowersj2 3141: =head1 User Name Functions
3142:
3143: =over 4
3144:
1.648 raeburn 3145: =item * &plainname($uname,$udom,$first)
1.81 albertel 3146:
1.112 bowersj2 3147: Takes a users logon name and returns it as a string in
1.226 albertel 3148: "first middle last generation" form
3149: if $first is set to 'lastname' then it returns it as
3150: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3151:
3152: =cut
1.61 www 3153:
1.295 www 3154:
1.81 albertel 3155: ###############################################################
1.61 www 3156: sub plainname {
1.226 albertel 3157: my ($uname,$udom,$first)=@_;
1.537 albertel 3158: return if (!defined($uname) || !defined($udom));
1.295 www 3159: my %names=&getnames($uname,$udom);
1.226 albertel 3160: my $name=&Apache::lonnet::format_name($names{'firstname'},
3161: $names{'middlename'},
3162: $names{'lastname'},
3163: $names{'generation'},$first);
3164: $name=~s/^\s+//;
1.62 www 3165: $name=~s/\s+$//;
3166: $name=~s/\s+/ /g;
1.353 albertel 3167: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3168: return $name;
1.61 www 3169: }
1.66 www 3170:
3171: # -------------------------------------------------------------------- Nickname
1.81 albertel 3172: =pod
3173:
1.648 raeburn 3174: =item * &nickname($uname,$udom)
1.81 albertel 3175:
3176: Gets a users name and returns it as a string as
3177:
3178: ""nickname""
1.66 www 3179:
1.81 albertel 3180: if the user has a nickname or
3181:
3182: "first middle last generation"
3183:
3184: if the user does not
3185:
3186: =cut
1.66 www 3187:
3188: sub nickname {
3189: my ($uname,$udom)=@_;
1.537 albertel 3190: return if (!defined($uname) || !defined($udom));
1.295 www 3191: my %names=&getnames($uname,$udom);
1.68 albertel 3192: my $name=$names{'nickname'};
1.66 www 3193: if ($name) {
3194: $name='"'.$name.'"';
3195: } else {
3196: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3197: $names{'lastname'}.' '.$names{'generation'};
3198: $name=~s/\s+$//;
3199: $name=~s/\s+/ /g;
3200: }
3201: return $name;
3202: }
3203:
1.295 www 3204: sub getnames {
3205: my ($uname,$udom)=@_;
1.537 albertel 3206: return if (!defined($uname) || !defined($udom));
1.433 albertel 3207: if ($udom eq 'public' && $uname eq 'public') {
3208: return ('lastname' => &mt('Public'));
3209: }
1.295 www 3210: my $id=$uname.':'.$udom;
3211: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3212: if ($cached) {
3213: return %{$names};
3214: } else {
3215: my %loadnames=&Apache::lonnet::get('environment',
3216: ['firstname','middlename','lastname','generation','nickname'],
3217: $udom,$uname);
3218: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3219: return %loadnames;
3220: }
3221: }
1.61 www 3222:
1.542 raeburn 3223: # -------------------------------------------------------------------- getemails
1.648 raeburn 3224:
1.542 raeburn 3225: =pod
3226:
1.648 raeburn 3227: =item * &getemails($uname,$udom)
1.542 raeburn 3228:
3229: Gets a user's email information and returns it as a hash with keys:
3230: notification, critnotification, permanentemail
3231:
3232: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3233: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3234:
1.648 raeburn 3235:
1.542 raeburn 3236: =cut
3237:
1.648 raeburn 3238:
1.466 albertel 3239: sub getemails {
3240: my ($uname,$udom)=@_;
3241: if ($udom eq 'public' && $uname eq 'public') {
3242: return;
3243: }
1.467 www 3244: if (!$udom) { $udom=$env{'user.domain'}; }
3245: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3246: my $id=$uname.':'.$udom;
3247: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3248: if ($cached) {
3249: return %{$names};
3250: } else {
3251: my %loadnames=&Apache::lonnet::get('environment',
3252: ['notification','critnotification',
3253: 'permanentemail'],
3254: $udom,$uname);
3255: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3256: return %loadnames;
3257: }
3258: }
3259:
1.551 albertel 3260: sub flush_email_cache {
3261: my ($uname,$udom)=@_;
3262: if (!$udom) { $udom =$env{'user.domain'}; }
3263: if (!$uname) { $uname=$env{'user.name'}; }
3264: return if ($udom eq 'public' && $uname eq 'public');
3265: my $id=$uname.':'.$udom;
3266: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3267: }
3268:
1.728 raeburn 3269: # -------------------------------------------------------------------- getlangs
3270:
3271: =pod
3272:
3273: =item * &getlangs($uname,$udom)
3274:
3275: Gets a user's language preference and returns it as a hash with key:
3276: language.
3277:
3278: =cut
3279:
3280:
3281: sub getlangs {
3282: my ($uname,$udom) = @_;
3283: if (!$udom) { $udom =$env{'user.domain'}; }
3284: if (!$uname) { $uname=$env{'user.name'}; }
3285: my $id=$uname.':'.$udom;
3286: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3287: if ($cached) {
3288: return %{$langs};
3289: } else {
3290: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3291: $udom,$uname);
3292: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3293: return %loadlangs;
3294: }
3295: }
3296:
3297: sub flush_langs_cache {
3298: my ($uname,$udom)=@_;
3299: if (!$udom) { $udom =$env{'user.domain'}; }
3300: if (!$uname) { $uname=$env{'user.name'}; }
3301: return if ($udom eq 'public' && $uname eq 'public');
3302: my $id=$uname.':'.$udom;
3303: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3304: }
3305:
1.61 www 3306: # ------------------------------------------------------------------ Screenname
1.81 albertel 3307:
3308: =pod
3309:
1.648 raeburn 3310: =item * &screenname($uname,$udom)
1.81 albertel 3311:
3312: Gets a users screenname and returns it as a string
3313:
3314: =cut
1.61 www 3315:
3316: sub screenname {
3317: my ($uname,$udom)=@_;
1.258 albertel 3318: if ($uname eq $env{'user.name'} &&
3319: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3320: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3321: return $names{'screenname'};
1.62 www 3322: }
3323:
1.212 albertel 3324:
1.802 bisitz 3325: # ------------------------------------------------------------- Confirm Wrapper
3326: =pod
3327:
1.1142 raeburn 3328: =item * &confirmwrapper($message)
1.802 bisitz 3329:
3330: Wrap messages about completion of operation in box
3331:
3332: =cut
3333:
3334: sub confirmwrapper {
3335: my ($message)=@_;
3336: if ($message) {
3337: return "\n".'<div class="LC_confirm_box">'."\n"
3338: .$message."\n"
3339: .'</div>'."\n";
3340: } else {
3341: return $message;
3342: }
3343: }
3344:
1.62 www 3345: # ------------------------------------------------------------- Message Wrapper
3346:
3347: sub messagewrapper {
1.369 www 3348: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3349: return
1.441 albertel 3350: '<a href="/adm/email?compose=individual&'.
3351: 'recname='.$username.'&recdom='.$domain.
3352: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3353: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3354: }
1.802 bisitz 3355:
1.74 www 3356: # --------------------------------------------------------------- Notes Wrapper
3357:
3358: sub noteswrapper {
3359: my ($link,$un,$do)=@_;
3360: return
1.896 amueller 3361: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3362: }
1.802 bisitz 3363:
1.62 www 3364: # ------------------------------------------------------------- Aboutme Wrapper
3365:
3366: sub aboutmewrapper {
1.1070 raeburn 3367: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3368: if (!defined($username) && !defined($domain)) {
3369: return;
3370: }
1.1096 raeburn 3371: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3372: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3373: }
3374:
3375: # ------------------------------------------------------------ Syllabus Wrapper
3376:
3377: sub syllabuswrapper {
1.707 bisitz 3378: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3379: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3380: }
1.14 harris41 3381:
1.802 bisitz 3382: # -----------------------------------------------------------------------------
3383:
1.208 matthew 3384: sub track_student_link {
1.887 raeburn 3385: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3386: my $link ="/adm/trackstudent?";
1.208 matthew 3387: my $title = 'View recent activity';
3388: if (defined($sname) && $sname !~ /^\s*$/ &&
3389: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3390: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3391: $title .= ' of this student';
1.268 albertel 3392: }
1.208 matthew 3393: if (defined($target) && $target !~ /^\s*$/) {
3394: $target = qq{target="$target"};
3395: } else {
3396: $target = '';
3397: }
1.268 albertel 3398: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3399: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3400: $title = &mt($title);
3401: $linktext = &mt($linktext);
1.448 albertel 3402: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3403: &help_open_topic('View_recent_activity');
1.208 matthew 3404: }
3405:
1.781 raeburn 3406: sub slot_reservations_link {
3407: my ($linktext,$sname,$sdom,$target) = @_;
3408: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3409: my $title = 'View slot reservation history';
3410: if (defined($sname) && $sname !~ /^\s*$/ &&
3411: defined($sdom) && $sdom !~ /^\s*$/) {
3412: $link .= "&uname=$sname&udom=$sdom";
3413: $title .= ' of this student';
3414: }
3415: if (defined($target) && $target !~ /^\s*$/) {
3416: $target = qq{target="$target"};
3417: } else {
3418: $target = '';
3419: }
3420: $title = &mt($title);
3421: $linktext = &mt($linktext);
3422: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3423: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3424:
3425: }
3426:
1.508 www 3427: # ===================================================== Display a student photo
3428:
3429:
1.509 albertel 3430: sub student_image_tag {
1.508 www 3431: my ($domain,$user)=@_;
3432: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3433: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3434: return '<img src="'.$imgsrc.'" align="right" />';
3435: } else {
3436: return '';
3437: }
3438: }
3439:
1.112 bowersj2 3440: =pod
3441:
3442: =back
3443:
3444: =head1 Access .tab File Data
3445:
3446: =over 4
3447:
1.648 raeburn 3448: =item * &languageids()
1.112 bowersj2 3449:
3450: returns list of all language ids
3451:
3452: =cut
3453:
1.14 harris41 3454: sub languageids {
1.16 harris41 3455: return sort(keys(%language));
1.14 harris41 3456: }
3457:
1.112 bowersj2 3458: =pod
3459:
1.648 raeburn 3460: =item * &languagedescription()
1.112 bowersj2 3461:
3462: returns description of a specified language id
3463:
3464: =cut
3465:
1.14 harris41 3466: sub languagedescription {
1.125 www 3467: my $code=shift;
3468: return ($supported_language{$code}?'* ':'').
3469: $language{$code}.
1.126 www 3470: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3471: }
3472:
1.1048 foxr 3473: =pod
3474:
3475: =item * &plainlanguagedescription
3476:
3477: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3478: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3479:
3480: =cut
3481:
1.145 www 3482: sub plainlanguagedescription {
3483: my $code=shift;
3484: return $language{$code};
3485: }
3486:
1.1048 foxr 3487: =pod
3488:
3489: =item * &supportedlanguagecode
3490:
3491: Returns the supported language code (e.g. sptutf maps to pt) given a language
3492: code.
3493:
3494: =cut
3495:
1.145 www 3496: sub supportedlanguagecode {
3497: my $code=shift;
3498: return $supported_language{$code};
1.97 www 3499: }
3500:
1.112 bowersj2 3501: =pod
3502:
1.1048 foxr 3503: =item * &latexlanguage()
3504:
3505: Given a language key code returns the correspondnig language to use
3506: to select the correct hyphenation on LaTeX printouts. This is undef if there
3507: is no supported hyphenation for the language code.
3508:
3509: =cut
3510:
3511: sub latexlanguage {
3512: my $code = shift;
3513: return $latex_language{$code};
3514: }
3515:
3516: =pod
3517:
3518: =item * &latexhyphenation()
3519:
3520: Same as above but what's supplied is the language as it might be stored
3521: in the metadata.
3522:
3523: =cut
3524:
3525: sub latexhyphenation {
3526: my $key = shift;
3527: return $latex_language_bykey{$key};
3528: }
3529:
3530: =pod
3531:
1.648 raeburn 3532: =item * ©rightids()
1.112 bowersj2 3533:
3534: returns list of all copyrights
3535:
3536: =cut
3537:
3538: sub copyrightids {
3539: return sort(keys(%cprtag));
3540: }
3541:
3542: =pod
3543:
1.648 raeburn 3544: =item * ©rightdescription()
1.112 bowersj2 3545:
3546: returns description of a specified copyright id
3547:
3548: =cut
3549:
3550: sub copyrightdescription {
1.166 www 3551: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3552: }
1.197 matthew 3553:
3554: =pod
3555:
1.648 raeburn 3556: =item * &source_copyrightids()
1.192 taceyjo1 3557:
3558: returns list of all source copyrights
3559:
3560: =cut
3561:
3562: sub source_copyrightids {
3563: return sort(keys(%scprtag));
3564: }
3565:
3566: =pod
3567:
1.648 raeburn 3568: =item * &source_copyrightdescription()
1.192 taceyjo1 3569:
3570: returns description of a specified source copyright id
3571:
3572: =cut
3573:
3574: sub source_copyrightdescription {
3575: return &mt($scprtag{shift(@_)});
3576: }
1.112 bowersj2 3577:
3578: =pod
3579:
1.648 raeburn 3580: =item * &filecategories()
1.112 bowersj2 3581:
3582: returns list of all file categories
3583:
3584: =cut
3585:
3586: sub filecategories {
3587: return sort(keys(%category_extensions));
3588: }
3589:
3590: =pod
3591:
1.648 raeburn 3592: =item * &filecategorytypes()
1.112 bowersj2 3593:
3594: returns list of file types belonging to a given file
3595: category
3596:
3597: =cut
3598:
3599: sub filecategorytypes {
1.356 albertel 3600: my ($cat) = @_;
3601: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3602: }
3603:
3604: =pod
3605:
1.648 raeburn 3606: =item * &fileembstyle()
1.112 bowersj2 3607:
3608: returns embedding style for a specified file type
3609:
3610: =cut
3611:
3612: sub fileembstyle {
3613: return $fe{lc(shift(@_))};
1.169 www 3614: }
3615:
1.351 www 3616: sub filemimetype {
3617: return $fm{lc(shift(@_))};
3618: }
3619:
1.169 www 3620:
3621: sub filecategoryselect {
3622: my ($name,$value)=@_;
1.189 matthew 3623: return &select_form($value,$name,
1.970 raeburn 3624: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3625: }
3626:
3627: =pod
3628:
1.648 raeburn 3629: =item * &filedescription()
1.112 bowersj2 3630:
3631: returns description for a specified file type
3632:
3633: =cut
3634:
3635: sub filedescription {
1.188 matthew 3636: my $file_description = $fd{lc(shift())};
3637: $file_description =~ s:([\[\]]):~$1:g;
3638: return &mt($file_description);
1.112 bowersj2 3639: }
3640:
3641: =pod
3642:
1.648 raeburn 3643: =item * &filedescriptionex()
1.112 bowersj2 3644:
3645: returns description for a specified file type with
3646: extra formatting
3647:
3648: =cut
3649:
3650: sub filedescriptionex {
3651: my $ex=shift;
1.188 matthew 3652: my $file_description = $fd{lc($ex)};
3653: $file_description =~ s:([\[\]]):~$1:g;
3654: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3655: }
3656:
3657: # End of .tab access
3658: =pod
3659:
3660: =back
3661:
3662: =cut
3663:
3664: # ------------------------------------------------------------------ File Types
3665: sub fileextensions {
3666: return sort(keys(%fe));
3667: }
3668:
1.97 www 3669: # ----------------------------------------------------------- Display Languages
3670: # returns a hash with all desired display languages
3671: #
3672:
3673: sub display_languages {
3674: my %languages=();
1.695 raeburn 3675: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3676: $languages{$lang}=1;
1.97 www 3677: }
3678: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3679: if ($env{'form.displaylanguage'}) {
1.356 albertel 3680: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3681: $languages{$lang}=1;
1.97 www 3682: }
3683: }
3684: return %languages;
1.14 harris41 3685: }
3686:
1.582 albertel 3687: sub languages {
3688: my ($possible_langs) = @_;
1.695 raeburn 3689: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3690: if (!ref($possible_langs)) {
3691: if( wantarray ) {
3692: return @preferred_langs;
3693: } else {
3694: return $preferred_langs[0];
3695: }
3696: }
3697: my %possibilities = map { $_ => 1 } (@$possible_langs);
3698: my @preferred_possibilities;
3699: foreach my $preferred_lang (@preferred_langs) {
3700: if (exists($possibilities{$preferred_lang})) {
3701: push(@preferred_possibilities, $preferred_lang);
3702: }
3703: }
3704: if( wantarray ) {
3705: return @preferred_possibilities;
3706: }
3707: return $preferred_possibilities[0];
3708: }
3709:
1.742 raeburn 3710: sub user_lang {
3711: my ($touname,$toudom,$fromcid) = @_;
3712: my @userlangs;
3713: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3714: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3715: $env{'course.'.$fromcid.'.languages'}));
3716: } else {
3717: my %langhash = &getlangs($touname,$toudom);
3718: if ($langhash{'languages'} ne '') {
3719: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3720: } else {
3721: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3722: if ($domdefs{'lang_def'} ne '') {
3723: @userlangs = ($domdefs{'lang_def'});
3724: }
3725: }
3726: }
3727: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3728: my $user_lh = Apache::localize->get_handle(@languages);
3729: return $user_lh;
3730: }
3731:
3732:
1.112 bowersj2 3733: ###############################################################
3734: ## Student Answer Attempts ##
3735: ###############################################################
3736:
3737: =pod
3738:
3739: =head1 Alternate Problem Views
3740:
3741: =over 4
3742:
1.648 raeburn 3743: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3744: $getattempt, $regexp, $gradesub)
3745:
3746: Return string with previous attempt on problem. Arguments:
3747:
3748: =over 4
3749:
3750: =item * $symb: Problem, including path
3751:
3752: =item * $username: username of the desired student
3753:
3754: =item * $domain: domain of the desired student
1.14 harris41 3755:
1.112 bowersj2 3756: =item * $course: Course ID
1.14 harris41 3757:
1.112 bowersj2 3758: =item * $getattempt: Leave blank for all attempts, otherwise put
3759: something
1.14 harris41 3760:
1.112 bowersj2 3761: =item * $regexp: if string matches this regexp, the string will be
3762: sent to $gradesub
1.14 harris41 3763:
1.112 bowersj2 3764: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3765:
1.112 bowersj2 3766: =back
1.14 harris41 3767:
1.112 bowersj2 3768: The output string is a table containing all desired attempts, if any.
1.16 harris41 3769:
1.112 bowersj2 3770: =cut
1.1 albertel 3771:
3772: sub get_previous_attempt {
1.43 ng 3773: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3774: my $prevattempts='';
1.43 ng 3775: no strict 'refs';
1.1 albertel 3776: if ($symb) {
1.3 albertel 3777: my (%returnhash)=
3778: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3779: if ($returnhash{'version'}) {
3780: my %lasthash=();
3781: my $version;
3782: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3783: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3784: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3785: }
1.1 albertel 3786: }
1.596 albertel 3787: $prevattempts=&start_data_table().&start_data_table_header_row();
3788: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3789: my (%typeparts,%lasthidden);
1.945 raeburn 3790: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3791: foreach my $key (sort(keys(%lasthash))) {
3792: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3793: if ($#parts > 0) {
1.31 albertel 3794: my $data=$parts[-1];
1.989 raeburn 3795: next if ($data eq 'foilorder');
1.31 albertel 3796: pop(@parts);
1.1010 www 3797: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3798: if ($data eq 'type') {
3799: unless ($showsurv) {
3800: my $id = join(',',@parts);
3801: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3802: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3803: $lasthidden{$ign.'.'.$id} = 1;
3804: }
1.945 raeburn 3805: }
1.1010 www 3806: }
1.31 albertel 3807: } else {
1.41 ng 3808: if ($#parts == 0) {
3809: $prevattempts.='<th>'.$parts[0].'</th>';
3810: } else {
3811: $prevattempts.='<th>'.$ign.'</th>';
3812: }
1.31 albertel 3813: }
1.16 harris41 3814: }
1.596 albertel 3815: $prevattempts.=&end_data_table_header_row();
1.40 ng 3816: if ($getattempt eq '') {
3817: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3818: my @hidden;
3819: if (%typeparts) {
3820: foreach my $id (keys(%typeparts)) {
3821: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3822: push(@hidden,$id);
3823: }
3824: }
3825: }
3826: $prevattempts.=&start_data_table_row().
3827: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3828: if (@hidden) {
3829: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3830: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3831: my $hide;
3832: foreach my $id (@hidden) {
3833: if ($key =~ /^\Q$id\E/) {
3834: $hide = 1;
3835: last;
3836: }
3837: }
3838: if ($hide) {
3839: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3840: if (($data eq 'award') || ($data eq 'awarddetail')) {
3841: my $value = &format_previous_attempt_value($key,
3842: $returnhash{$version.':'.$key});
3843: $prevattempts.='<td>'.$value.' </td>';
3844: } else {
3845: $prevattempts.='<td> </td>';
3846: }
3847: } else {
3848: if ($key =~ /\./) {
3849: my $value = &format_previous_attempt_value($key,
3850: $returnhash{$version.':'.$key});
3851: $prevattempts.='<td>'.$value.' </td>';
3852: } else {
3853: $prevattempts.='<td> </td>';
3854: }
3855: }
3856: }
3857: } else {
3858: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3859: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3860: my $value = &format_previous_attempt_value($key,
3861: $returnhash{$version.':'.$key});
3862: $prevattempts.='<td>'.$value.' </td>';
3863: }
3864: }
3865: $prevattempts.=&end_data_table_row();
1.40 ng 3866: }
1.1 albertel 3867: }
1.945 raeburn 3868: my @currhidden = keys(%lasthidden);
1.596 albertel 3869: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3870: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3871: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3872: if (%typeparts) {
3873: my $hidden;
3874: foreach my $id (@currhidden) {
3875: if ($key =~ /^\Q$id\E/) {
3876: $hidden = 1;
3877: last;
3878: }
3879: }
3880: if ($hidden) {
3881: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3882: if (($data eq 'award') || ($data eq 'awarddetail')) {
3883: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3884: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3885: $value = &$gradesub($value);
3886: }
3887: $prevattempts.='<td>'.$value.' </td>';
3888: } else {
3889: $prevattempts.='<td> </td>';
3890: }
3891: } else {
3892: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3893: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3894: $value = &$gradesub($value);
3895: }
3896: $prevattempts.='<td>'.$value.' </td>';
3897: }
3898: } else {
3899: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3900: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3901: $value = &$gradesub($value);
3902: }
3903: $prevattempts.='<td>'.$value.' </td>';
3904: }
1.16 harris41 3905: }
1.596 albertel 3906: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3907: } else {
1.596 albertel 3908: $prevattempts=
3909: &start_data_table().&start_data_table_row().
3910: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3911: &end_data_table_row().&end_data_table();
1.1 albertel 3912: }
3913: } else {
1.596 albertel 3914: $prevattempts=
3915: &start_data_table().&start_data_table_row().
3916: '<td>'.&mt('No data.').'</td>'.
3917: &end_data_table_row().&end_data_table();
1.1 albertel 3918: }
1.10 albertel 3919: }
3920:
1.581 albertel 3921: sub format_previous_attempt_value {
3922: my ($key,$value) = @_;
1.1011 www 3923: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3924: $value = &Apache::lonlocal::locallocaltime($value);
3925: } elsif (ref($value) eq 'ARRAY') {
3926: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3927: } elsif ($key =~ /answerstring$/) {
3928: my %answers = &Apache::lonnet::str2hash($value);
3929: my @anskeys = sort(keys(%answers));
3930: if (@anskeys == 1) {
3931: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3932: if ($answer =~ m{\0}) {
3933: $answer =~ s{\0}{,}g;
1.988 raeburn 3934: }
3935: my $tag_internal_answer_name = 'INTERNAL';
3936: if ($anskeys[0] eq $tag_internal_answer_name) {
3937: $value = $answer;
3938: } else {
3939: $value = $anskeys[0].'='.$answer;
3940: }
3941: } else {
3942: foreach my $ans (@anskeys) {
3943: my $answer = $answers{$ans};
1.1001 raeburn 3944: if ($answer =~ m{\0}) {
3945: $answer =~ s{\0}{,}g;
1.988 raeburn 3946: }
3947: $value .= $ans.'='.$answer.'<br />';;
3948: }
3949: }
1.581 albertel 3950: } else {
3951: $value = &unescape($value);
3952: }
3953: return $value;
3954: }
3955:
3956:
1.107 albertel 3957: sub relative_to_absolute {
3958: my ($url,$output)=@_;
3959: my $parser=HTML::TokeParser->new(\$output);
3960: my $token;
3961: my $thisdir=$url;
3962: my @rlinks=();
3963: while ($token=$parser->get_token) {
3964: if ($token->[0] eq 'S') {
3965: if ($token->[1] eq 'a') {
3966: if ($token->[2]->{'href'}) {
3967: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3968: }
3969: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3970: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3971: } elsif ($token->[1] eq 'base') {
3972: $thisdir=$token->[2]->{'href'};
3973: }
3974: }
3975: }
3976: $thisdir=~s-/[^/]*$--;
1.356 albertel 3977: foreach my $link (@rlinks) {
1.726 raeburn 3978: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3979: ($link=~/^\//) ||
3980: ($link=~/^javascript:/i) ||
3981: ($link=~/^mailto:/i) ||
3982: ($link=~/^\#/)) {
3983: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3984: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3985: }
3986: }
3987: # -------------------------------------------------- Deal with Applet codebases
3988: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3989: return $output;
3990: }
3991:
1.112 bowersj2 3992: =pod
3993:
1.648 raeburn 3994: =item * &get_student_view()
1.112 bowersj2 3995:
3996: show a snapshot of what student was looking at
3997:
3998: =cut
3999:
1.10 albertel 4000: sub get_student_view {
1.186 albertel 4001: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4002: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4003: my (%form);
1.10 albertel 4004: my @elements=('symb','courseid','domain','username');
4005: foreach my $element (@elements) {
1.186 albertel 4006: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4007: }
1.186 albertel 4008: if (defined($moreenv)) {
4009: %form=(%form,%{$moreenv});
4010: }
1.236 albertel 4011: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4012: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4013: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4014: $userview=~s/\<body[^\>]*\>//gi;
4015: $userview=~s/\<\/body\>//gi;
4016: $userview=~s/\<html\>//gi;
4017: $userview=~s/\<\/html\>//gi;
4018: $userview=~s/\<head\>//gi;
4019: $userview=~s/\<\/head\>//gi;
4020: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4021: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4022: if (wantarray) {
4023: return ($userview,$response);
4024: } else {
4025: return $userview;
4026: }
4027: }
4028:
4029: sub get_student_view_with_retries {
4030: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4031:
4032: my $ok = 0; # True if we got a good response.
4033: my $content;
4034: my $response;
4035:
4036: # Try to get the student_view done. within the retries count:
4037:
4038: do {
4039: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4040: $ok = $response->is_success;
4041: if (!$ok) {
4042: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4043: }
4044: $retries--;
4045: } while (!$ok && ($retries > 0));
4046:
4047: if (!$ok) {
4048: $content = ''; # On error return an empty content.
4049: }
1.651 www 4050: if (wantarray) {
4051: return ($content, $response);
4052: } else {
4053: return $content;
4054: }
1.11 albertel 4055: }
4056:
1.112 bowersj2 4057: =pod
4058:
1.648 raeburn 4059: =item * &get_student_answers()
1.112 bowersj2 4060:
4061: show a snapshot of how student was answering problem
4062:
4063: =cut
4064:
1.11 albertel 4065: sub get_student_answers {
1.100 sakharuk 4066: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4067: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4068: my (%moreenv);
1.11 albertel 4069: my @elements=('symb','courseid','domain','username');
4070: foreach my $element (@elements) {
1.186 albertel 4071: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4072: }
1.186 albertel 4073: $moreenv{'grade_target'}='answer';
4074: %moreenv=(%form,%moreenv);
1.497 raeburn 4075: $feedurl = &Apache::lonnet::clutter($feedurl);
4076: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4077: return $userview;
1.1 albertel 4078: }
1.116 albertel 4079:
4080: =pod
4081:
4082: =item * &submlink()
4083:
1.242 albertel 4084: Inputs: $text $uname $udom $symb $target
1.116 albertel 4085:
4086: Returns: A link to grades.pm such as to see the SUBM view of a student
4087:
4088: =cut
4089:
4090: ###############################################
4091: sub submlink {
1.242 albertel 4092: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4093: if (!($uname && $udom)) {
4094: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4095: &Apache::lonnet::whichuser($symb);
1.116 albertel 4096: if (!$symb) { $symb=$cursymb; }
4097: }
1.254 matthew 4098: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4099: $symb=&escape($symb);
1.960 bisitz 4100: if ($target) { $target=" target=\"$target\""; }
4101: return
4102: '<a href="/adm/grades?command=submission'.
4103: '&symb='.$symb.
4104: '&student='.$uname.
4105: '&userdom='.$udom.'"'.
4106: $target.'>'.$text.'</a>';
1.242 albertel 4107: }
4108: ##############################################
4109:
4110: =pod
4111:
4112: =item * &pgrdlink()
4113:
4114: Inputs: $text $uname $udom $symb $target
4115:
4116: Returns: A link to grades.pm such as to see the PGRD view of a student
4117:
4118: =cut
4119:
4120: ###############################################
4121: sub pgrdlink {
4122: my $link=&submlink(@_);
4123: $link=~s/(&command=submission)/$1&showgrading=yes/;
4124: return $link;
4125: }
4126: ##############################################
4127:
4128: =pod
4129:
4130: =item * &pprmlink()
4131:
4132: Inputs: $text $uname $udom $symb $target
4133:
4134: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4135: student and a specific resource
1.242 albertel 4136:
4137: =cut
4138:
4139: ###############################################
4140: sub pprmlink {
4141: my ($text,$uname,$udom,$symb,$target)=@_;
4142: if (!($uname && $udom)) {
4143: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4144: &Apache::lonnet::whichuser($symb);
1.242 albertel 4145: if (!$symb) { $symb=$cursymb; }
4146: }
1.254 matthew 4147: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4148: $symb=&escape($symb);
1.242 albertel 4149: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4150: return '<a href="/adm/parmset?command=set&'.
4151: 'symb='.$symb.'&uname='.$uname.
4152: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4153: }
4154: ##############################################
1.37 matthew 4155:
1.112 bowersj2 4156: =pod
4157:
4158: =back
4159:
4160: =cut
4161:
1.37 matthew 4162: ###############################################
1.51 www 4163:
4164:
4165: sub timehash {
1.687 raeburn 4166: my ($thistime) = @_;
4167: my $timezone = &Apache::lonlocal::gettimezone();
4168: my $dt = DateTime->from_epoch(epoch => $thistime)
4169: ->set_time_zone($timezone);
4170: my $wday = $dt->day_of_week();
4171: if ($wday == 7) { $wday = 0; }
4172: return ( 'second' => $dt->second(),
4173: 'minute' => $dt->minute(),
4174: 'hour' => $dt->hour(),
4175: 'day' => $dt->day_of_month(),
4176: 'month' => $dt->month(),
4177: 'year' => $dt->year(),
4178: 'weekday' => $wday,
4179: 'dayyear' => $dt->day_of_year(),
4180: 'dlsav' => $dt->is_dst() );
1.51 www 4181: }
4182:
1.370 www 4183: sub utc_string {
4184: my ($date)=@_;
1.371 www 4185: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4186: }
4187:
1.51 www 4188: sub maketime {
4189: my %th=@_;
1.687 raeburn 4190: my ($epoch_time,$timezone,$dt);
4191: $timezone = &Apache::lonlocal::gettimezone();
4192: eval {
4193: $dt = DateTime->new( year => $th{'year'},
4194: month => $th{'month'},
4195: day => $th{'day'},
4196: hour => $th{'hour'},
4197: minute => $th{'minute'},
4198: second => $th{'second'},
4199: time_zone => $timezone,
4200: );
4201: };
4202: if (!$@) {
4203: $epoch_time = $dt->epoch;
4204: if ($epoch_time) {
4205: return $epoch_time;
4206: }
4207: }
1.51 www 4208: return POSIX::mktime(
4209: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4210: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4211: }
4212:
4213: #########################################
1.51 www 4214:
4215: sub findallcourses {
1.482 raeburn 4216: my ($roles,$uname,$udom) = @_;
1.355 albertel 4217: my %roles;
4218: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4219: my %courses;
1.51 www 4220: my $now=time;
1.482 raeburn 4221: if (!defined($uname)) {
4222: $uname = $env{'user.name'};
4223: }
4224: if (!defined($udom)) {
4225: $udom = $env{'user.domain'};
4226: }
4227: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4228: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4229: if (!%roles) {
4230: %roles = (
4231: cc => 1,
1.907 raeburn 4232: co => 1,
1.482 raeburn 4233: in => 1,
4234: ep => 1,
4235: ta => 1,
4236: cr => 1,
4237: st => 1,
4238: );
4239: }
4240: foreach my $entry (keys(%roleshash)) {
4241: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4242: if ($trole =~ /^cr/) {
4243: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4244: } else {
4245: next if (!exists($roles{$trole}));
4246: }
4247: if ($tend) {
4248: next if ($tend < $now);
4249: }
4250: if ($tstart) {
4251: next if ($tstart > $now);
4252: }
1.1058 raeburn 4253: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4254: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4255: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4256: if ($secpart eq '') {
4257: ($cnum,$role) = split(/_/,$cnumpart);
4258: $sec = 'none';
1.1058 raeburn 4259: $value .= $cnum.'/';
1.482 raeburn 4260: } else {
4261: $cnum = $cnumpart;
4262: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4263: $value .= $cnum.'/'.$sec;
4264: }
4265: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4266: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4267: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4268: }
4269: } else {
4270: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4271: }
1.482 raeburn 4272: }
4273: } else {
4274: foreach my $key (keys(%env)) {
1.483 albertel 4275: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4276: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4277: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4278: next if ($role eq 'ca' || $role eq 'aa');
4279: next if (%roles && !exists($roles{$role}));
4280: my ($starttime,$endtime)=split(/\./,$env{$key});
4281: my $active=1;
4282: if ($starttime) {
4283: if ($now<$starttime) { $active=0; }
4284: }
4285: if ($endtime) {
4286: if ($now>$endtime) { $active=0; }
4287: }
4288: if ($active) {
1.1058 raeburn 4289: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4290: if ($sec eq '') {
4291: $sec = 'none';
1.1058 raeburn 4292: } else {
4293: $value .= $sec;
4294: }
4295: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4296: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4297: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4298: }
4299: } else {
4300: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4301: }
1.474 raeburn 4302: }
4303: }
1.51 www 4304: }
4305: }
1.474 raeburn 4306: return %courses;
1.51 www 4307: }
1.37 matthew 4308:
1.54 www 4309: ###############################################
1.474 raeburn 4310:
4311: sub blockcheck {
1.1062 raeburn 4312: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4313:
4314: if (!defined($udom)) {
4315: $udom = $env{'user.domain'};
4316: }
4317: if (!defined($uname)) {
4318: $uname = $env{'user.name'};
4319: }
4320:
4321: # If uname and udom are for a course, check for blocks in the course.
4322:
4323: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4324: my ($startblock,$endblock,$triggerblock) =
4325: &get_blocks($setters,$activity,$udom,$uname,$url);
4326: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4327: }
1.474 raeburn 4328:
1.502 raeburn 4329: my $startblock = 0;
4330: my $endblock = 0;
1.1062 raeburn 4331: my $triggerblock = '';
1.482 raeburn 4332: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4333:
1.490 raeburn 4334: # If uname is for a user, and activity is course-specific, i.e.,
4335: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4336:
1.490 raeburn 4337: if (($activity eq 'boards' || $activity eq 'chat' ||
4338: $activity eq 'groups') && ($env{'request.course.id'})) {
4339: foreach my $key (keys(%live_courses)) {
4340: if ($key ne $env{'request.course.id'}) {
4341: delete($live_courses{$key});
4342: }
4343: }
4344: }
4345:
4346: my $otheruser = 0;
4347: my %own_courses;
4348: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4349: # Resource belongs to user other than current user.
4350: $otheruser = 1;
4351: # Gather courses for current user
4352: %own_courses =
4353: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4354: }
4355:
4356: # Gather active course roles - course coordinator, instructor,
4357: # exam proctor, ta, student, or custom role.
1.474 raeburn 4358:
4359: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4360: my ($cdom,$cnum);
4361: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4362: $cdom = $env{'course.'.$course.'.domain'};
4363: $cnum = $env{'course.'.$course.'.num'};
4364: } else {
1.490 raeburn 4365: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4366: }
4367: my $no_ownblock = 0;
4368: my $no_userblock = 0;
1.533 raeburn 4369: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4370: # Check if current user has 'evb' priv for this
4371: if (defined($own_courses{$course})) {
4372: foreach my $sec (keys(%{$own_courses{$course}})) {
4373: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4374: if ($sec ne 'none') {
4375: $checkrole .= '/'.$sec;
4376: }
4377: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4378: $no_ownblock = 1;
4379: last;
4380: }
4381: }
4382: }
4383: # if they have 'evb' priv and are currently not playing student
4384: next if (($no_ownblock) &&
4385: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4386: }
1.474 raeburn 4387: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4388: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4389: if ($sec ne 'none') {
1.482 raeburn 4390: $checkrole .= '/'.$sec;
1.474 raeburn 4391: }
1.490 raeburn 4392: if ($otheruser) {
4393: # Resource belongs to user other than current user.
4394: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4395: my (%allroles,%userroles);
4396: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4397: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4398: my ($trole,$tdom,$tnum,$tsec);
4399: if ($entry =~ /^cr/) {
4400: ($trole,$tdom,$tnum,$tsec) =
4401: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4402: } else {
4403: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4404: }
4405: my ($spec,$area,$trest);
4406: $area = '/'.$tdom.'/'.$tnum;
4407: $trest = $tnum;
4408: if ($tsec ne '') {
4409: $area .= '/'.$tsec;
4410: $trest .= '/'.$tsec;
4411: }
4412: $spec = $trole.'.'.$area;
4413: if ($trole =~ /^cr/) {
4414: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4415: $tdom,$spec,$trest,$area);
4416: } else {
4417: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4418: $tdom,$spec,$trest,$area);
4419: }
4420: }
4421: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4422: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4423: if ($1) {
4424: $no_userblock = 1;
4425: last;
4426: }
1.486 raeburn 4427: }
4428: }
1.490 raeburn 4429: } else {
4430: # Resource belongs to current user
4431: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4432: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4433: $no_ownblock = 1;
4434: last;
4435: }
1.474 raeburn 4436: }
4437: }
4438: # if they have the evb priv and are currently not playing student
1.482 raeburn 4439: next if (($no_ownblock) &&
1.491 albertel 4440: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4441: next if ($no_userblock);
1.474 raeburn 4442:
1.866 kalberla 4443: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4444: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4445:
1.1062 raeburn 4446: my ($start,$end,$trigger) =
4447: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4448: if (($start != 0) &&
4449: (($startblock == 0) || ($startblock > $start))) {
4450: $startblock = $start;
1.1062 raeburn 4451: if ($trigger ne '') {
4452: $triggerblock = $trigger;
4453: }
1.502 raeburn 4454: }
4455: if (($end != 0) &&
4456: (($endblock == 0) || ($endblock < $end))) {
4457: $endblock = $end;
1.1062 raeburn 4458: if ($trigger ne '') {
4459: $triggerblock = $trigger;
4460: }
1.502 raeburn 4461: }
1.490 raeburn 4462: }
1.1062 raeburn 4463: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4464: }
4465:
4466: sub get_blocks {
1.1062 raeburn 4467: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4468: my $startblock = 0;
4469: my $endblock = 0;
1.1062 raeburn 4470: my $triggerblock = '';
1.490 raeburn 4471: my $course = $cdom.'_'.$cnum;
4472: $setters->{$course} = {};
4473: $setters->{$course}{'staff'} = [];
4474: $setters->{$course}{'times'} = [];
1.1062 raeburn 4475: $setters->{$course}{'triggers'} = [];
4476: my (@blockers,%triggered);
4477: my $now = time;
4478: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4479: if ($activity eq 'docs') {
4480: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4481: foreach my $block (@blockers) {
4482: if ($block =~ /^firstaccess____(.+)$/) {
4483: my $item = $1;
4484: my $type = 'map';
4485: my $timersymb = $item;
4486: if ($item eq 'course') {
4487: $type = 'course';
4488: } elsif ($item =~ /___\d+___/) {
4489: $type = 'resource';
4490: } else {
4491: $timersymb = &Apache::lonnet::symbread($item);
4492: }
4493: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4494: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4495: $triggered{$block} = {
4496: start => $start,
4497: end => $end,
4498: type => $type,
4499: };
4500: }
4501: }
4502: } else {
4503: foreach my $block (keys(%commblocks)) {
4504: if ($block =~ m/^(\d+)____(\d+)$/) {
4505: my ($start,$end) = ($1,$2);
4506: if ($start <= time && $end >= time) {
4507: if (ref($commblocks{$block}) eq 'HASH') {
4508: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4509: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4510: unless(grep(/^\Q$block\E$/,@blockers)) {
4511: push(@blockers,$block);
4512: }
4513: }
4514: }
4515: }
4516: }
4517: } elsif ($block =~ /^firstaccess____(.+)$/) {
4518: my $item = $1;
4519: my $timersymb = $item;
4520: my $type = 'map';
4521: if ($item eq 'course') {
4522: $type = 'course';
4523: } elsif ($item =~ /___\d+___/) {
4524: $type = 'resource';
4525: } else {
4526: $timersymb = &Apache::lonnet::symbread($item);
4527: }
4528: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4529: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4530: if ($start && $end) {
4531: if (($start <= time) && ($end >= time)) {
4532: unless (grep(/^\Q$block\E$/,@blockers)) {
4533: push(@blockers,$block);
4534: $triggered{$block} = {
4535: start => $start,
4536: end => $end,
4537: type => $type,
4538: };
4539: }
4540: }
1.490 raeburn 4541: }
1.1062 raeburn 4542: }
4543: }
4544: }
4545: foreach my $blocker (@blockers) {
4546: my ($staff_name,$staff_dom,$title,$blocks) =
4547: &parse_block_record($commblocks{$blocker});
4548: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4549: my ($start,$end,$triggertype);
4550: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4551: ($start,$end) = ($1,$2);
4552: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4553: $start = $triggered{$blocker}{'start'};
4554: $end = $triggered{$blocker}{'end'};
4555: $triggertype = $triggered{$blocker}{'type'};
4556: }
4557: if ($start) {
4558: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4559: if ($triggertype) {
4560: push(@{$$setters{$course}{'triggers'}},$triggertype);
4561: } else {
4562: push(@{$$setters{$course}{'triggers'}},0);
4563: }
4564: if ( ($startblock == 0) || ($startblock > $start) ) {
4565: $startblock = $start;
4566: if ($triggertype) {
4567: $triggerblock = $blocker;
1.474 raeburn 4568: }
4569: }
1.1062 raeburn 4570: if ( ($endblock == 0) || ($endblock < $end) ) {
4571: $endblock = $end;
4572: if ($triggertype) {
4573: $triggerblock = $blocker;
4574: }
4575: }
1.474 raeburn 4576: }
4577: }
1.1062 raeburn 4578: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4579: }
4580:
4581: sub parse_block_record {
4582: my ($record) = @_;
4583: my ($setuname,$setudom,$title,$blocks);
4584: if (ref($record) eq 'HASH') {
4585: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4586: $title = &unescape($record->{'event'});
4587: $blocks = $record->{'blocks'};
4588: } else {
4589: my @data = split(/:/,$record,3);
4590: if (scalar(@data) eq 2) {
4591: $title = $data[1];
4592: ($setuname,$setudom) = split(/@/,$data[0]);
4593: } else {
4594: ($setuname,$setudom,$title) = @data;
4595: }
4596: $blocks = { 'com' => 'on' };
4597: }
4598: return ($setuname,$setudom,$title,$blocks);
4599: }
4600:
1.854 kalberla 4601: sub blocking_status {
1.1062 raeburn 4602: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4603: my %setters;
1.890 droeschl 4604:
1.1061 raeburn 4605: # check for active blocking
1.1062 raeburn 4606: my ($startblock,$endblock,$triggerblock) =
4607: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4608: my $blocked = 0;
4609: if ($startblock && $endblock) {
4610: $blocked = 1;
4611: }
1.890 droeschl 4612:
1.1061 raeburn 4613: # caller just wants to know whether a block is active
4614: if (!wantarray) { return $blocked; }
4615:
4616: # build a link to a popup window containing the details
4617: my $querystring = "?activity=$activity";
4618: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4619: if ($activity eq 'port') {
4620: $querystring .= "&udom=$udom" if $udom;
4621: $querystring .= "&uname=$uname" if $uname;
4622: } elsif ($activity eq 'docs') {
4623: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4624: }
1.1061 raeburn 4625:
4626: my $output .= <<'END_MYBLOCK';
4627: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4628: var options = "width=" + w + ",height=" + h + ",";
4629: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4630: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4631: var newWin = window.open(url, wdwName, options);
4632: newWin.focus();
4633: }
1.890 droeschl 4634: END_MYBLOCK
1.854 kalberla 4635:
1.1061 raeburn 4636: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4637:
1.1061 raeburn 4638: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4639: my $text = &mt('Communication Blocked');
4640: if ($activity eq 'docs') {
4641: $text = &mt('Content Access Blocked');
1.1063 raeburn 4642: } elsif ($activity eq 'printout') {
4643: $text = &mt('Printing Blocked');
1.1062 raeburn 4644: }
1.1061 raeburn 4645: $output .= <<"END_BLOCK";
1.867 kalberla 4646: <div class='LC_comblock'>
1.869 kalberla 4647: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4648: title='$text'>
4649: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
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'>$text</a>
1.867 kalberla 4652: </div>
4653:
4654: END_BLOCK
1.474 raeburn 4655:
1.1061 raeburn 4656: return ($blocked, $output);
1.854 kalberla 4657: }
1.490 raeburn 4658:
1.60 matthew 4659: ###############################################
4660:
1.682 raeburn 4661: sub check_ip_acc {
4662: my ($acc)=@_;
4663: &Apache::lonxml::debug("acc is $acc");
4664: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4665: return 1;
4666: }
4667: my $allowed=0;
4668: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4669:
4670: my $name;
4671: foreach my $pattern (split(',',$acc)) {
4672: $pattern =~ s/^\s*//;
4673: $pattern =~ s/\s*$//;
4674: if ($pattern =~ /\*$/) {
4675: #35.8.*
4676: $pattern=~s/\*//;
4677: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4678: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4679: #35.8.3.[34-56]
4680: my $low=$2;
4681: my $high=$3;
4682: $pattern=$1;
4683: if ($ip =~ /^\Q$pattern\E/) {
4684: my $last=(split(/\./,$ip))[3];
4685: if ($last <=$high && $last >=$low) { $allowed=1; }
4686: }
4687: } elsif ($pattern =~ /^\*/) {
4688: #*.msu.edu
4689: $pattern=~s/\*//;
4690: if (!defined($name)) {
4691: use Socket;
4692: my $netaddr=inet_aton($ip);
4693: ($name)=gethostbyaddr($netaddr,AF_INET);
4694: }
4695: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4696: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4697: #127.0.0.1
4698: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4699: } else {
4700: #some.name.com
4701: if (!defined($name)) {
4702: use Socket;
4703: my $netaddr=inet_aton($ip);
4704: ($name)=gethostbyaddr($netaddr,AF_INET);
4705: }
4706: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4707: }
4708: if ($allowed) { last; }
4709: }
4710: return $allowed;
4711: }
4712:
4713: ###############################################
4714:
1.60 matthew 4715: =pod
4716:
1.112 bowersj2 4717: =head1 Domain Template Functions
4718:
4719: =over 4
4720:
4721: =item * &determinedomain()
1.60 matthew 4722:
4723: Inputs: $domain (usually will be undef)
4724:
1.63 www 4725: Returns: Determines which domain should be used for designs
1.60 matthew 4726:
4727: =cut
1.54 www 4728:
1.60 matthew 4729: ###############################################
1.63 www 4730: sub determinedomain {
4731: my $domain=shift;
1.531 albertel 4732: if (! $domain) {
1.60 matthew 4733: # Determine domain if we have not been given one
1.893 raeburn 4734: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4735: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4736: if ($env{'request.role.domain'}) {
4737: $domain=$env{'request.role.domain'};
1.60 matthew 4738: }
4739: }
1.63 www 4740: return $domain;
4741: }
4742: ###############################################
1.517 raeburn 4743:
1.518 albertel 4744: sub devalidate_domconfig_cache {
4745: my ($udom)=@_;
4746: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4747: }
4748:
4749: # ---------------------- Get domain configuration for a domain
4750: sub get_domainconf {
4751: my ($udom) = @_;
4752: my $cachetime=1800;
4753: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4754: if (defined($cached)) { return %{$result}; }
4755:
4756: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4757: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4758: my (%designhash,%legacy);
1.518 albertel 4759: if (keys(%domconfig) > 0) {
4760: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4761: if (keys(%{$domconfig{'login'}})) {
4762: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4763: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4764: if ($key eq 'loginvia') {
4765: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4766: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4767: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4768: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4769: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4770: $designhash{$udom.'.login.loginvia'} = $server;
4771: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4772:
4773: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4774: } else {
1.1013 raeburn 4775: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4776: }
4777: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4778: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4779: }
1.946 raeburn 4780: }
4781: }
4782: }
4783: }
4784: } else {
4785: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4786: $designhash{$udom.'.login.'.$key.'_'.$img} =
4787: $domconfig{'login'}{$key}{$img};
4788: }
1.699 raeburn 4789: }
4790: } else {
4791: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4792: }
1.632 raeburn 4793: }
4794: } else {
4795: $legacy{'login'} = 1;
1.518 albertel 4796: }
1.632 raeburn 4797: } else {
4798: $legacy{'login'} = 1;
1.518 albertel 4799: }
4800: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4801: if (keys(%{$domconfig{'rolecolors'}})) {
4802: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4803: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4804: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4805: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4806: }
1.518 albertel 4807: }
4808: }
1.632 raeburn 4809: } else {
4810: $legacy{'rolecolors'} = 1;
1.518 albertel 4811: }
1.632 raeburn 4812: } else {
4813: $legacy{'rolecolors'} = 1;
1.518 albertel 4814: }
1.948 raeburn 4815: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4816: if ($domconfig{'autoenroll'}{'co-owners'}) {
4817: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4818: }
4819: }
1.632 raeburn 4820: if (keys(%legacy) > 0) {
4821: my %legacyhash = &get_legacy_domconf($udom);
4822: foreach my $item (keys(%legacyhash)) {
4823: if ($item =~ /^\Q$udom\E\.login/) {
4824: if ($legacy{'login'}) {
4825: $designhash{$item} = $legacyhash{$item};
4826: }
4827: } else {
4828: if ($legacy{'rolecolors'}) {
4829: $designhash{$item} = $legacyhash{$item};
4830: }
1.518 albertel 4831: }
4832: }
4833: }
1.632 raeburn 4834: } else {
4835: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4836: }
4837: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4838: $cachetime);
4839: return %designhash;
4840: }
4841:
1.632 raeburn 4842: sub get_legacy_domconf {
4843: my ($udom) = @_;
4844: my %legacyhash;
4845: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4846: my $designfile = $designdir.'/'.$udom.'.tab';
4847: if (-e $designfile) {
4848: if ( open (my $fh,"<$designfile") ) {
4849: while (my $line = <$fh>) {
4850: next if ($line =~ /^\#/);
4851: chomp($line);
4852: my ($key,$val)=(split(/\=/,$line));
4853: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4854: }
4855: close($fh);
4856: }
4857: }
1.1026 raeburn 4858: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4859: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4860: }
4861: return %legacyhash;
4862: }
4863:
1.63 www 4864: =pod
4865:
1.112 bowersj2 4866: =item * &domainlogo()
1.63 www 4867:
4868: Inputs: $domain (usually will be undef)
4869:
4870: Returns: A link to a domain logo, if the domain logo exists.
4871: If the domain logo does not exist, a description of the domain.
4872:
4873: =cut
1.112 bowersj2 4874:
1.63 www 4875: ###############################################
4876: sub domainlogo {
1.517 raeburn 4877: my $domain = &determinedomain(shift);
1.518 albertel 4878: my %designhash = &get_domainconf($domain);
1.517 raeburn 4879: # See if there is a logo
4880: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4881: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4882: if ($imgsrc =~ m{^/(adm|res)/}) {
4883: if ($imgsrc =~ m{^/res/}) {
4884: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4885: &Apache::lonnet::repcopy($local_name);
4886: }
4887: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4888: }
4889: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4890: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4891: return &Apache::lonnet::domain($domain,'description');
1.59 www 4892: } else {
1.60 matthew 4893: return '';
1.59 www 4894: }
4895: }
1.63 www 4896: ##############################################
4897:
4898: =pod
4899:
1.112 bowersj2 4900: =item * &designparm()
1.63 www 4901:
4902: Inputs: $which parameter; $domain (usually will be undef)
4903:
4904: Returns: value of designparamter $which
4905:
4906: =cut
1.112 bowersj2 4907:
1.397 albertel 4908:
1.400 albertel 4909: ##############################################
1.397 albertel 4910: sub designparm {
4911: my ($which,$domain)=@_;
4912: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4913: return $env{'environment.color.'.$which};
1.96 www 4914: }
1.63 www 4915: $domain=&determinedomain($domain);
1.1016 raeburn 4916: my %domdesign;
4917: unless ($domain eq 'public') {
4918: %domdesign = &get_domainconf($domain);
4919: }
1.520 raeburn 4920: my $output;
1.517 raeburn 4921: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4922: $output = $domdesign{$domain.'.'.$which};
1.63 www 4923: } else {
1.520 raeburn 4924: $output = $defaultdesign{$which};
4925: }
4926: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4927: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4928: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4929: if ($output =~ m{^/res/}) {
4930: my $local_name = &Apache::lonnet::filelocation('',$output);
4931: &Apache::lonnet::repcopy($local_name);
4932: }
1.520 raeburn 4933: $output = &lonhttpdurl($output);
4934: }
1.63 www 4935: }
1.520 raeburn 4936: return $output;
1.63 www 4937: }
1.59 www 4938:
1.822 bisitz 4939: ##############################################
4940: =pod
4941:
1.832 bisitz 4942: =item * &authorspace()
4943:
1.1028 raeburn 4944: Inputs: $url (usually will be undef).
1.832 bisitz 4945:
1.1132 raeburn 4946: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4947: directory being viewed (or for which action is being taken).
4948: If $url is provided, and begins /priv/<domain>/<uname>
4949: the path will be that portion of the $context argument.
4950: Otherwise the path will be for the author space of the current
4951: user when the current role is author, or for that of the
4952: co-author/assistant co-author space when the current role
4953: is co-author or assistant co-author.
1.832 bisitz 4954:
4955: =cut
4956:
4957: sub authorspace {
1.1028 raeburn 4958: my ($url) = @_;
4959: if ($url ne '') {
4960: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4961: return $1;
4962: }
4963: }
1.832 bisitz 4964: my $caname = '';
1.1024 www 4965: my $cadom = '';
1.1028 raeburn 4966: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4967: ($cadom,$caname) =
1.832 bisitz 4968: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4969: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4970: $caname = $env{'user.name'};
1.1024 www 4971: $cadom = $env{'user.domain'};
1.832 bisitz 4972: }
1.1028 raeburn 4973: if (($caname ne '') && ($cadom ne '')) {
4974: return "/priv/$cadom/$caname/";
4975: }
4976: return;
1.832 bisitz 4977: }
4978:
4979: ##############################################
4980: =pod
4981:
1.822 bisitz 4982: =item * &head_subbox()
4983:
4984: Inputs: $content (contains HTML code with page functions, etc.)
4985:
4986: Returns: HTML div with $content
4987: To be included in page header
4988:
4989: =cut
4990:
4991: sub head_subbox {
4992: my ($content)=@_;
4993: my $output =
1.993 raeburn 4994: '<div class="LC_head_subbox">'
1.822 bisitz 4995: .$content
4996: .'</div>'
4997: }
4998:
4999: ##############################################
5000: =pod
5001:
5002: =item * &CSTR_pageheader()
5003:
1.1026 raeburn 5004: Input: (optional) filename from which breadcrumb trail is built.
5005: In most cases no input as needed, as $env{'request.filename'}
5006: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5007:
5008: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5009: To be included on Authoring Space pages
1.822 bisitz 5010:
5011: =cut
5012:
5013: sub CSTR_pageheader {
1.1026 raeburn 5014: my ($trailfile) = @_;
5015: if ($trailfile eq '') {
5016: $trailfile = $env{'request.filename'};
5017: }
5018:
5019: # this is for resources; directories have customtitle, and crumbs
5020: # and select recent are created in lonpubdir.pm
5021:
5022: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5023: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5024: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5025: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5026: $formaction =~ s{/+}{/}g;
1.822 bisitz 5027:
5028: my $parentpath = '';
5029: my $lastitem = '';
5030: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5031: $parentpath = $1;
5032: $lastitem = $2;
5033: } else {
5034: $lastitem = $thisdisfn;
5035: }
1.921 bisitz 5036:
5037: my $output =
1.822 bisitz 5038: '<div>'
5039: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5040: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5041: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5042: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5043: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5044:
5045: if ($lastitem) {
5046: $output .=
5047: '<span class="LC_filename">'
5048: .$lastitem
5049: .'</span>';
5050: }
5051: $output .=
5052: '<br />'
1.822 bisitz 5053: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5054: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5055: .'</form>'
5056: .&Apache::lonmenu::constspaceform()
5057: .'</div>';
1.921 bisitz 5058:
5059: return $output;
1.822 bisitz 5060: }
5061:
1.60 matthew 5062: ###############################################
5063: ###############################################
5064:
5065: =pod
5066:
1.112 bowersj2 5067: =back
5068:
1.549 albertel 5069: =head1 HTML Helpers
1.112 bowersj2 5070:
5071: =over 4
5072:
5073: =item * &bodytag()
1.60 matthew 5074:
5075: Returns a uniform header for LON-CAPA web pages.
5076:
5077: Inputs:
5078:
1.112 bowersj2 5079: =over 4
5080:
5081: =item * $title, A title to be displayed on the page.
5082:
5083: =item * $function, the current role (can be undef).
5084:
5085: =item * $addentries, extra parameters for the <body> tag.
5086:
5087: =item * $bodyonly, if defined, only return the <body> tag.
5088:
5089: =item * $domain, if defined, force a given domain.
5090:
5091: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5092: text interface only)
1.60 matthew 5093:
1.814 bisitz 5094: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5095: navigational links
1.317 albertel 5096:
1.338 albertel 5097: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5098:
1.460 albertel 5099: =item * $args, optional argument valid values are
5100: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5101: inherit_jsmath -> when creating popup window in a page,
5102: should it have jsmath forced on by the
5103: current page
1.460 albertel 5104:
1.1096 raeburn 5105: =item * $advtoolsref, optional argument, ref to an array containing
5106: inlineremote items to be added in "Functions" menu below
5107: breadcrumbs.
5108:
1.112 bowersj2 5109: =back
5110:
1.60 matthew 5111: Returns: A uniform header for LON-CAPA web pages.
5112: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5113: If $bodyonly is undef or zero, an html string containing a <body> tag and
5114: other decorations will be returned.
5115:
5116: =cut
5117:
1.54 www 5118: sub bodytag {
1.831 bisitz 5119: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5120: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5121:
1.954 raeburn 5122: my $public;
5123: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5124: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5125: $public = 1;
5126: }
1.460 albertel 5127: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5128: my $httphost = $args->{'use_absolute'};
1.339 albertel 5129:
1.183 matthew 5130: $function = &get_users_function() if (!$function);
1.339 albertel 5131: my $img = &designparm($function.'.img',$domain);
5132: my $font = &designparm($function.'.font',$domain);
5133: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5134:
1.803 bisitz 5135: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5136: 'bgcolor' => $pgbg,
1.339 albertel 5137: 'text' => $font,
5138: 'alink' => &designparm($function.'.alink',$domain),
5139: 'vlink' => &designparm($function.'.vlink',$domain),
5140: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5141: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5142:
1.63 www 5143: # role and realm
1.378 raeburn 5144: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5145: if ($role eq 'ca') {
1.479 albertel 5146: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5147: $realm = &plainname($rname,$rdom);
1.378 raeburn 5148: }
1.55 www 5149: # realm
1.258 albertel 5150: if ($env{'request.course.id'}) {
1.378 raeburn 5151: if ($env{'request.role'} !~ /^cr/) {
5152: $role = &Apache::lonnet::plaintext($role,&course_type());
5153: }
1.898 raeburn 5154: if ($env{'request.course.sec'}) {
5155: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5156: }
1.359 albertel 5157: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5158: } else {
5159: $role = &Apache::lonnet::plaintext($role);
1.54 www 5160: }
1.433 albertel 5161:
1.359 albertel 5162: if (!$realm) { $realm=' '; }
1.330 albertel 5163:
1.438 albertel 5164: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5165:
1.101 www 5166: # construct main body tag
1.359 albertel 5167: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5168: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5169:
1.1131 raeburn 5170: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5171:
1.1130 raeburn 5172: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5173: return $bodytag;
1.1130 raeburn 5174: }
1.359 albertel 5175:
1.954 raeburn 5176: if ($public) {
1.433 albertel 5177: undef($role);
5178: }
1.359 albertel 5179:
1.762 bisitz 5180: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5181: #
5182: # Extra info if you are the DC
5183: my $dc_info = '';
5184: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5185: $env{'course.'.$env{'request.course.id'}.
5186: '.domain'}.'/'})) {
5187: my $cid = $env{'request.course.id'};
1.917 raeburn 5188: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5189: $dc_info =~ s/\s+$//;
1.359 albertel 5190: }
5191:
1.898 raeburn 5192: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5193:
1.903 droeschl 5194: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5195:
5196: # if ($env{'request.state'} eq 'construct') {
5197: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5198: # }
5199:
1.1130 raeburn 5200: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5201: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5202:
1.1130 raeburn 5203: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5204:
1.916 droeschl 5205: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5206: if ($dc_info) {
5207: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5208: }
1.1130 raeburn 5209: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5210: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5211: return $bodytag;
5212: }
1.894 droeschl 5213:
1.927 raeburn 5214: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5215: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5216: }
1.916 droeschl 5217:
1.1130 raeburn 5218: $bodytag .= $right;
1.852 droeschl 5219:
1.917 raeburn 5220: if ($dc_info) {
5221: $dc_info = &dc_courseid_toggle($dc_info);
5222: }
5223: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5224:
1.903 droeschl 5225: #don't show menus for public users
1.954 raeburn 5226: if (!$public){
1.1154 raeburn 5227: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5228: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5229: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5230: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5231: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5232: $args->{'bread_crumbs'});
1.1096 raeburn 5233: } elsif ($forcereg) {
5234: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5235: $args->{'group'});
5236: } else {
5237: $bodytag .=
5238: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5239: $forcereg,$args->{'group'},
5240: $args->{'bread_crumbs'},
5241: $advtoolsref);
1.920 raeburn 5242: }
1.903 droeschl 5243: }else{
5244: # this is to seperate menu from content when there's no secondary
5245: # menu. Especially needed for public accessible ressources.
5246: $bodytag .= '<hr style="clear:both" />';
5247: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5248: }
1.903 droeschl 5249:
1.235 raeburn 5250: return $bodytag;
1.182 matthew 5251: }
5252:
1.917 raeburn 5253: sub dc_courseid_toggle {
5254: my ($dc_info) = @_;
1.980 raeburn 5255: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5256: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5257: &mt('(More ...)').'</a></span>'.
5258: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5259: }
5260:
1.330 albertel 5261: sub make_attr_string {
5262: my ($register,$attr_ref) = @_;
5263:
5264: if ($attr_ref && !ref($attr_ref)) {
5265: die("addentries Must be a hash ref ".
5266: join(':',caller(1))." ".
5267: join(':',caller(0))." ");
5268: }
5269:
5270: if ($register) {
1.339 albertel 5271: my ($on_load,$on_unload);
5272: foreach my $key (keys(%{$attr_ref})) {
5273: if (lc($key) eq 'onload') {
5274: $on_load.=$attr_ref->{$key}.';';
5275: delete($attr_ref->{$key});
5276:
5277: } elsif (lc($key) eq 'onunload') {
5278: $on_unload.=$attr_ref->{$key}.';';
5279: delete($attr_ref->{$key});
5280: }
5281: }
1.953 droeschl 5282: $attr_ref->{'onload'} = $on_load;
5283: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5284: }
1.339 albertel 5285:
1.330 albertel 5286: my $attr_string;
1.1159 raeburn 5287: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5288: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5289: }
5290: return $attr_string;
5291: }
5292:
5293:
1.182 matthew 5294: ###############################################
1.251 albertel 5295: ###############################################
5296:
5297: =pod
5298:
5299: =item * &endbodytag()
5300:
5301: Returns a uniform footer for LON-CAPA web pages.
5302:
1.635 raeburn 5303: Inputs: 1 - optional reference to an args hash
5304: If in the hash, key for noredirectlink has a value which evaluates to true,
5305: a 'Continue' link is not displayed if the page contains an
5306: internal redirect in the <head></head> section,
5307: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5308:
5309: =cut
5310:
5311: sub endbodytag {
1.635 raeburn 5312: my ($args) = @_;
1.1080 raeburn 5313: my $endbodytag;
5314: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5315: $endbodytag='</body>';
5316: }
1.269 albertel 5317: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5318: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5319: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5320: $endbodytag=
5321: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5322: &mt('Continue').'</a>'.
5323: $endbodytag;
5324: }
1.315 albertel 5325: }
1.251 albertel 5326: return $endbodytag;
5327: }
5328:
1.352 albertel 5329: =pod
5330:
5331: =item * &standard_css()
5332:
5333: Returns a style sheet
5334:
5335: Inputs: (all optional)
5336: domain -> force to color decorate a page for a specific
5337: domain
5338: function -> force usage of a specific rolish color scheme
5339: bgcolor -> override the default page bgcolor
5340:
5341: =cut
5342:
1.343 albertel 5343: sub standard_css {
1.345 albertel 5344: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5345: $function = &get_users_function() if (!$function);
5346: my $img = &designparm($function.'.img', $domain);
5347: my $tabbg = &designparm($function.'.tabbg', $domain);
5348: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5349: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5350: #second colour for later usage
1.345 albertel 5351: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5352: my $pgbg_or_bgcolor =
5353: $bgcolor ||
1.352 albertel 5354: &designparm($function.'.pgbg', $domain);
1.382 albertel 5355: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5356: my $alink = &designparm($function.'.alink', $domain);
5357: my $vlink = &designparm($function.'.vlink', $domain);
5358: my $link = &designparm($function.'.link', $domain);
5359:
1.602 albertel 5360: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5361: my $mono = 'monospace';
1.850 bisitz 5362: my $data_table_head = $sidebg;
5363: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5364: my $data_table_dark = '#E0E0E0';
1.470 banghart 5365: my $data_table_darker = '#CCCCCC';
1.349 albertel 5366: my $data_table_highlight = '#FFFF00';
1.352 albertel 5367: my $mail_new = '#FFBB77';
5368: my $mail_new_hover = '#DD9955';
5369: my $mail_read = '#BBBB77';
5370: my $mail_read_hover = '#999944';
5371: my $mail_replied = '#AAAA88';
5372: my $mail_replied_hover = '#888855';
5373: my $mail_other = '#99BBBB';
5374: my $mail_other_hover = '#669999';
1.391 albertel 5375: my $table_header = '#DDDDDD';
1.489 raeburn 5376: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5377: my $lg_border_color = '#C8C8C8';
1.952 onken 5378: my $button_hover = '#BF2317';
1.392 albertel 5379:
1.608 albertel 5380: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5381: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5382: : '0 3px 0 4px';
1.448 albertel 5383:
1.523 albertel 5384:
1.343 albertel 5385: return <<END;
1.947 droeschl 5386:
5387: /* needed for iframe to allow 100% height in FF */
5388: body, html {
5389: margin: 0;
5390: padding: 0 0.5%;
5391: height: 99%; /* to avoid scrollbars */
5392: }
5393:
1.795 www 5394: body {
1.911 bisitz 5395: font-family: $sans;
5396: line-height:130%;
5397: font-size:0.83em;
5398: color:$font;
1.795 www 5399: }
5400:
1.959 onken 5401: a:focus,
5402: a:focus img {
1.795 www 5403: color: red;
5404: }
1.698 harmsja 5405:
1.911 bisitz 5406: form, .inline {
5407: display: inline;
1.795 www 5408: }
1.721 harmsja 5409:
1.795 www 5410: .LC_right {
1.911 bisitz 5411: text-align:right;
1.795 www 5412: }
5413:
5414: .LC_middle {
1.911 bisitz 5415: vertical-align:middle;
1.795 www 5416: }
1.721 harmsja 5417:
1.1130 raeburn 5418: .LC_floatleft {
5419: float: left;
5420: }
5421:
5422: .LC_floatright {
5423: float: right;
5424: }
5425:
1.911 bisitz 5426: .LC_400Box {
5427: width:400px;
5428: }
1.721 harmsja 5429:
1.947 droeschl 5430: .LC_iframecontainer {
5431: width: 98%;
5432: margin: 0;
5433: position: fixed;
5434: top: 8.5em;
5435: bottom: 0;
5436: }
5437:
5438: .LC_iframecontainer iframe{
5439: border: none;
5440: width: 100%;
5441: height: 100%;
5442: }
5443:
1.778 bisitz 5444: .LC_filename {
5445: font-family: $mono;
5446: white-space:pre;
1.921 bisitz 5447: font-size: 120%;
1.778 bisitz 5448: }
5449:
5450: .LC_fileicon {
5451: border: none;
5452: height: 1.3em;
5453: vertical-align: text-bottom;
5454: margin-right: 0.3em;
5455: text-decoration:none;
5456: }
5457:
1.1008 www 5458: .LC_setting {
5459: text-decoration:underline;
5460: }
5461:
1.350 albertel 5462: .LC_error {
5463: color: red;
5464: }
1.795 www 5465:
1.1097 bisitz 5466: .LC_warning {
5467: color: darkorange;
5468: }
5469:
1.457 albertel 5470: .LC_diff_removed {
1.733 bisitz 5471: color: red;
1.394 albertel 5472: }
1.532 albertel 5473:
5474: .LC_info,
1.457 albertel 5475: .LC_success,
5476: .LC_diff_added {
1.350 albertel 5477: color: green;
5478: }
1.795 www 5479:
1.802 bisitz 5480: div.LC_confirm_box {
5481: background-color: #FAFAFA;
5482: border: 1px solid $lg_border_color;
5483: margin-right: 0;
5484: padding: 5px;
5485: }
5486:
5487: div.LC_confirm_box .LC_error img,
5488: div.LC_confirm_box .LC_success img {
5489: vertical-align: middle;
5490: }
5491:
1.440 albertel 5492: .LC_icon {
1.771 droeschl 5493: border: none;
1.790 droeschl 5494: vertical-align: middle;
1.771 droeschl 5495: }
5496:
1.543 albertel 5497: .LC_docs_spacer {
5498: width: 25px;
5499: height: 1px;
1.771 droeschl 5500: border: none;
1.543 albertel 5501: }
1.346 albertel 5502:
1.532 albertel 5503: .LC_internal_info {
1.735 bisitz 5504: color: #999999;
1.532 albertel 5505: }
5506:
1.794 www 5507: .LC_discussion {
1.1050 www 5508: background: $data_table_dark;
1.911 bisitz 5509: border: 1px solid black;
5510: margin: 2px;
1.794 www 5511: }
5512:
5513: .LC_disc_action_left {
1.1050 www 5514: background: $sidebg;
1.911 bisitz 5515: text-align: left;
1.1050 www 5516: padding: 4px;
5517: margin: 2px;
1.794 www 5518: }
5519:
5520: .LC_disc_action_right {
1.1050 www 5521: background: $sidebg;
1.911 bisitz 5522: text-align: right;
1.1050 www 5523: padding: 4px;
5524: margin: 2px;
1.794 www 5525: }
5526:
5527: .LC_disc_new_item {
1.911 bisitz 5528: background: white;
5529: border: 2px solid red;
1.1050 www 5530: margin: 4px;
5531: padding: 4px;
1.794 www 5532: }
5533:
5534: .LC_disc_old_item {
1.911 bisitz 5535: background: white;
1.1050 www 5536: margin: 4px;
5537: padding: 4px;
1.794 www 5538: }
5539:
1.458 albertel 5540: table.LC_pastsubmission {
5541: border: 1px solid black;
5542: margin: 2px;
5543: }
5544:
1.924 bisitz 5545: table#LC_menubuttons {
1.345 albertel 5546: width: 100%;
5547: background: $pgbg;
1.392 albertel 5548: border: 2px;
1.402 albertel 5549: border-collapse: separate;
1.803 bisitz 5550: padding: 0;
1.345 albertel 5551: }
1.392 albertel 5552:
1.801 tempelho 5553: table#LC_title_bar a {
5554: color: $fontmenu;
5555: }
1.836 bisitz 5556:
1.807 droeschl 5557: table#LC_title_bar {
1.819 tempelho 5558: clear: both;
1.836 bisitz 5559: display: none;
1.807 droeschl 5560: }
5561:
1.795 www 5562: table#LC_title_bar,
1.933 droeschl 5563: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5564: table#LC_title_bar.LC_with_remote {
1.359 albertel 5565: width: 100%;
1.392 albertel 5566: border-color: $pgbg;
5567: border-style: solid;
5568: border-width: $border;
1.379 albertel 5569: background: $pgbg;
1.801 tempelho 5570: color: $fontmenu;
1.392 albertel 5571: border-collapse: collapse;
1.803 bisitz 5572: padding: 0;
1.819 tempelho 5573: margin: 0;
1.359 albertel 5574: }
1.795 www 5575:
1.933 droeschl 5576: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5577: margin: 0;
5578: padding: 0;
1.933 droeschl 5579: position: relative;
5580: list-style: none;
1.913 droeschl 5581: }
1.933 droeschl 5582: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5583: display: inline;
5584: }
1.933 droeschl 5585:
5586: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5587: padding: 0;
1.933 droeschl 5588: margin: 0;
5589: float: left;
1.913 droeschl 5590: }
1.933 droeschl 5591: .LC_breadcrumb_tools_tools {
5592: padding: 0;
5593: margin: 0;
1.913 droeschl 5594: float: right;
5595: }
5596:
1.359 albertel 5597: table#LC_title_bar td {
5598: background: $tabbg;
5599: }
1.795 www 5600:
1.911 bisitz 5601: table#LC_menubuttons img {
1.803 bisitz 5602: border: none;
1.346 albertel 5603: }
1.795 www 5604:
1.842 droeschl 5605: .LC_breadcrumbs_component {
1.911 bisitz 5606: float: right;
5607: margin: 0 1em;
1.357 albertel 5608: }
1.842 droeschl 5609: .LC_breadcrumbs_component img {
1.911 bisitz 5610: vertical-align: middle;
1.777 tempelho 5611: }
1.795 www 5612:
1.383 albertel 5613: td.LC_table_cell_checkbox {
5614: text-align: center;
5615: }
1.795 www 5616:
5617: .LC_fontsize_small {
1.911 bisitz 5618: font-size: 70%;
1.705 tempelho 5619: }
5620:
1.844 bisitz 5621: #LC_breadcrumbs {
1.911 bisitz 5622: clear:both;
5623: background: $sidebg;
5624: border-bottom: 1px solid $lg_border_color;
5625: line-height: 2.5em;
1.933 droeschl 5626: overflow: hidden;
1.911 bisitz 5627: margin: 0;
5628: padding: 0;
1.995 raeburn 5629: text-align: left;
1.819 tempelho 5630: }
1.862 bisitz 5631:
1.1098 bisitz 5632: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5633: clear:both;
5634: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5635: border: 1px solid $sidebg;
1.1098 bisitz 5636: margin: 0 0 10px 0;
1.966 bisitz 5637: padding: 3px;
1.995 raeburn 5638: text-align: left;
1.822 bisitz 5639: }
5640:
1.795 www 5641: .LC_fontsize_medium {
1.911 bisitz 5642: font-size: 85%;
1.705 tempelho 5643: }
5644:
1.795 www 5645: .LC_fontsize_large {
1.911 bisitz 5646: font-size: 120%;
1.705 tempelho 5647: }
5648:
1.346 albertel 5649: .LC_menubuttons_inline_text {
5650: color: $font;
1.698 harmsja 5651: font-size: 90%;
1.701 harmsja 5652: padding-left:3px;
1.346 albertel 5653: }
5654:
1.934 droeschl 5655: .LC_menubuttons_inline_text img{
5656: vertical-align: middle;
5657: }
5658:
1.1051 www 5659: li.LC_menubuttons_inline_text img {
1.951 onken 5660: cursor:pointer;
1.1002 droeschl 5661: text-decoration: none;
1.951 onken 5662: }
5663:
1.526 www 5664: .LC_menubuttons_link {
5665: text-decoration: none;
5666: }
1.795 www 5667:
1.522 albertel 5668: .LC_menubuttons_category {
1.521 www 5669: color: $font;
1.526 www 5670: background: $pgbg;
1.521 www 5671: font-size: larger;
5672: font-weight: bold;
5673: }
5674:
1.346 albertel 5675: td.LC_menubuttons_text {
1.911 bisitz 5676: color: $font;
1.346 albertel 5677: }
1.706 harmsja 5678:
1.346 albertel 5679: .LC_current_location {
5680: background: $tabbg;
5681: }
1.795 www 5682:
1.938 bisitz 5683: table.LC_data_table {
1.347 albertel 5684: border: 1px solid #000000;
1.402 albertel 5685: border-collapse: separate;
1.426 albertel 5686: border-spacing: 1px;
1.610 albertel 5687: background: $pgbg;
1.347 albertel 5688: }
1.795 www 5689:
1.422 albertel 5690: .LC_data_table_dense {
5691: font-size: small;
5692: }
1.795 www 5693:
1.507 raeburn 5694: table.LC_nested_outer {
5695: border: 1px solid #000000;
1.589 raeburn 5696: border-collapse: collapse;
1.803 bisitz 5697: border-spacing: 0;
1.507 raeburn 5698: width: 100%;
5699: }
1.795 www 5700:
1.879 raeburn 5701: table.LC_innerpickbox,
1.507 raeburn 5702: table.LC_nested {
1.803 bisitz 5703: border: none;
1.589 raeburn 5704: border-collapse: collapse;
1.803 bisitz 5705: border-spacing: 0;
1.507 raeburn 5706: width: 100%;
5707: }
1.795 www 5708:
1.911 bisitz 5709: table.LC_data_table tr th,
5710: table.LC_calendar tr th,
1.879 raeburn 5711: table.LC_prior_tries tr th,
5712: table.LC_innerpickbox tr th {
1.349 albertel 5713: font-weight: bold;
5714: background-color: $data_table_head;
1.801 tempelho 5715: color:$fontmenu;
1.701 harmsja 5716: font-size:90%;
1.347 albertel 5717: }
1.795 www 5718:
1.879 raeburn 5719: table.LC_innerpickbox tr th,
5720: table.LC_innerpickbox tr td {
5721: vertical-align: top;
5722: }
5723:
1.711 raeburn 5724: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5725: background-color: #CCCCCC;
1.711 raeburn 5726: font-weight: bold;
5727: text-align: left;
5728: }
1.795 www 5729:
1.912 bisitz 5730: table.LC_data_table tr.LC_odd_row > td {
5731: background-color: $data_table_light;
5732: padding: 2px;
5733: vertical-align: top;
5734: }
5735:
1.809 bisitz 5736: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5737: background-color: $data_table_light;
1.912 bisitz 5738: vertical-align: top;
5739: }
5740:
5741: table.LC_data_table tr.LC_even_row > td {
5742: background-color: $data_table_dark;
1.425 albertel 5743: padding: 2px;
1.900 bisitz 5744: vertical-align: top;
1.347 albertel 5745: }
1.795 www 5746:
1.809 bisitz 5747: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5748: background-color: $data_table_dark;
1.900 bisitz 5749: vertical-align: top;
1.347 albertel 5750: }
1.795 www 5751:
1.425 albertel 5752: table.LC_data_table tr.LC_data_table_highlight td {
5753: background-color: $data_table_darker;
5754: }
1.795 www 5755:
1.639 raeburn 5756: table.LC_data_table tr td.LC_leftcol_header {
5757: background-color: $data_table_head;
5758: font-weight: bold;
5759: }
1.795 www 5760:
1.451 albertel 5761: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5762: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5763: font-weight: bold;
5764: font-style: italic;
5765: text-align: center;
5766: padding: 8px;
1.347 albertel 5767: }
1.795 www 5768:
1.1114 raeburn 5769: table.LC_data_table tr.LC_empty_row td,
5770: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5771: background-color: $sidebg;
5772: }
5773:
5774: table.LC_nested tr.LC_empty_row td {
5775: background-color: #FFFFFF;
5776: }
5777:
1.890 droeschl 5778: table.LC_caption {
5779: }
5780:
1.507 raeburn 5781: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5782: padding: 4ex
5783: }
1.795 www 5784:
1.507 raeburn 5785: table.LC_nested_outer tr th {
5786: font-weight: bold;
1.801 tempelho 5787: color:$fontmenu;
1.507 raeburn 5788: background-color: $data_table_head;
1.701 harmsja 5789: font-size: small;
1.507 raeburn 5790: border-bottom: 1px solid #000000;
5791: }
1.795 www 5792:
1.507 raeburn 5793: table.LC_nested_outer tr td.LC_subheader {
5794: background-color: $data_table_head;
5795: font-weight: bold;
5796: font-size: small;
5797: border-bottom: 1px solid #000000;
5798: text-align: right;
1.451 albertel 5799: }
1.795 www 5800:
1.507 raeburn 5801: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5802: background-color: #CCCCCC;
1.451 albertel 5803: font-weight: bold;
5804: font-size: small;
1.507 raeburn 5805: text-align: center;
5806: }
1.795 www 5807:
1.589 raeburn 5808: table.LC_nested tr.LC_info_row td.LC_left_item,
5809: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5810: text-align: left;
1.451 albertel 5811: }
1.795 www 5812:
1.507 raeburn 5813: table.LC_nested td {
1.735 bisitz 5814: background-color: #FFFFFF;
1.451 albertel 5815: font-size: small;
1.507 raeburn 5816: }
1.795 www 5817:
1.507 raeburn 5818: table.LC_nested_outer tr th.LC_right_item,
5819: table.LC_nested tr.LC_info_row td.LC_right_item,
5820: table.LC_nested tr.LC_odd_row td.LC_right_item,
5821: table.LC_nested tr td.LC_right_item {
1.451 albertel 5822: text-align: right;
5823: }
5824:
1.507 raeburn 5825: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5826: background-color: #EEEEEE;
1.451 albertel 5827: }
5828:
1.473 raeburn 5829: table.LC_createuser {
5830: }
5831:
5832: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5833: font-size: small;
1.473 raeburn 5834: }
5835:
5836: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5837: background-color: #CCCCCC;
1.473 raeburn 5838: font-weight: bold;
5839: text-align: center;
5840: }
5841:
1.349 albertel 5842: table.LC_calendar {
5843: border: 1px solid #000000;
5844: border-collapse: collapse;
1.917 raeburn 5845: width: 98%;
1.349 albertel 5846: }
1.795 www 5847:
1.349 albertel 5848: table.LC_calendar_pickdate {
5849: font-size: xx-small;
5850: }
1.795 www 5851:
1.349 albertel 5852: table.LC_calendar tr td {
5853: border: 1px solid #000000;
5854: vertical-align: top;
1.917 raeburn 5855: width: 14%;
1.349 albertel 5856: }
1.795 www 5857:
1.349 albertel 5858: table.LC_calendar tr td.LC_calendar_day_empty {
5859: background-color: $data_table_dark;
5860: }
1.795 www 5861:
1.779 bisitz 5862: table.LC_calendar tr td.LC_calendar_day_current {
5863: background-color: $data_table_highlight;
1.777 tempelho 5864: }
1.795 www 5865:
1.938 bisitz 5866: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5867: background-color: $mail_new;
5868: }
1.795 www 5869:
1.938 bisitz 5870: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5871: background-color: $mail_new_hover;
5872: }
1.795 www 5873:
1.938 bisitz 5874: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5875: background-color: $mail_read;
5876: }
1.795 www 5877:
1.938 bisitz 5878: /*
5879: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5880: background-color: $mail_read_hover;
5881: }
1.938 bisitz 5882: */
1.795 www 5883:
1.938 bisitz 5884: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5885: background-color: $mail_replied;
5886: }
1.795 www 5887:
1.938 bisitz 5888: /*
5889: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5890: background-color: $mail_replied_hover;
5891: }
1.938 bisitz 5892: */
1.795 www 5893:
1.938 bisitz 5894: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5895: background-color: $mail_other;
5896: }
1.795 www 5897:
1.938 bisitz 5898: /*
5899: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5900: background-color: $mail_other_hover;
5901: }
1.938 bisitz 5902: */
1.494 raeburn 5903:
1.777 tempelho 5904: table.LC_data_table tr > td.LC_browser_file,
5905: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5906: background: #AAEE77;
1.389 albertel 5907: }
1.795 www 5908:
1.777 tempelho 5909: table.LC_data_table tr > td.LC_browser_file_locked,
5910: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5911: background: #FFAA99;
1.387 albertel 5912: }
1.795 www 5913:
1.777 tempelho 5914: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5915: background: #888888;
1.779 bisitz 5916: }
1.795 www 5917:
1.777 tempelho 5918: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5919: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5920: background: #F8F866;
1.777 tempelho 5921: }
1.795 www 5922:
1.696 bisitz 5923: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5924: background: #E0E8FF;
1.387 albertel 5925: }
1.696 bisitz 5926:
1.707 bisitz 5927: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5928: /* background: #77FF77; */
1.707 bisitz 5929: }
1.795 www 5930:
1.707 bisitz 5931: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5932: border-right: 8px solid #FFFF77;
1.707 bisitz 5933: }
1.795 www 5934:
1.707 bisitz 5935: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5936: border-right: 8px solid #FFAA77;
1.707 bisitz 5937: }
1.795 www 5938:
1.707 bisitz 5939: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5940: border-right: 8px solid #FF7777;
1.707 bisitz 5941: }
1.795 www 5942:
1.707 bisitz 5943: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5944: border-right: 8px solid #AAFF77;
1.707 bisitz 5945: }
1.795 www 5946:
1.707 bisitz 5947: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5948: border-right: 8px solid #11CC55;
1.707 bisitz 5949: }
5950:
1.388 albertel 5951: span.LC_current_location {
1.701 harmsja 5952: font-size:larger;
1.388 albertel 5953: background: $pgbg;
5954: }
1.387 albertel 5955:
1.1029 www 5956: span.LC_current_nav_location {
5957: font-weight:bold;
5958: background: $sidebg;
5959: }
5960:
1.395 albertel 5961: span.LC_parm_menu_item {
5962: font-size: larger;
5963: }
1.795 www 5964:
1.395 albertel 5965: span.LC_parm_scope_all {
5966: color: red;
5967: }
1.795 www 5968:
1.395 albertel 5969: span.LC_parm_scope_folder {
5970: color: green;
5971: }
1.795 www 5972:
1.395 albertel 5973: span.LC_parm_scope_resource {
5974: color: orange;
5975: }
1.795 www 5976:
1.395 albertel 5977: span.LC_parm_part {
5978: color: blue;
5979: }
1.795 www 5980:
1.911 bisitz 5981: span.LC_parm_folder,
5982: span.LC_parm_symb {
1.395 albertel 5983: font-size: x-small;
5984: font-family: $mono;
5985: color: #AAAAAA;
5986: }
5987:
1.977 bisitz 5988: ul.LC_parm_parmlist li {
5989: display: inline-block;
5990: padding: 0.3em 0.8em;
5991: vertical-align: top;
5992: width: 150px;
5993: border-top:1px solid $lg_border_color;
5994: }
5995:
1.795 www 5996: td.LC_parm_overview_level_menu,
5997: td.LC_parm_overview_map_menu,
5998: td.LC_parm_overview_parm_selectors,
5999: td.LC_parm_overview_restrictions {
1.396 albertel 6000: border: 1px solid black;
6001: border-collapse: collapse;
6002: }
1.795 www 6003:
1.396 albertel 6004: table.LC_parm_overview_restrictions td {
6005: border-width: 1px 4px 1px 4px;
6006: border-style: solid;
6007: border-color: $pgbg;
6008: text-align: center;
6009: }
1.795 www 6010:
1.396 albertel 6011: table.LC_parm_overview_restrictions th {
6012: background: $tabbg;
6013: border-width: 1px 4px 1px 4px;
6014: border-style: solid;
6015: border-color: $pgbg;
6016: }
1.795 www 6017:
1.398 albertel 6018: table#LC_helpmenu {
1.803 bisitz 6019: border: none;
1.398 albertel 6020: height: 55px;
1.803 bisitz 6021: border-spacing: 0;
1.398 albertel 6022: }
6023:
6024: table#LC_helpmenu fieldset legend {
6025: font-size: larger;
6026: }
1.795 www 6027:
1.397 albertel 6028: table#LC_helpmenu_links {
6029: width: 100%;
6030: border: 1px solid black;
6031: background: $pgbg;
1.803 bisitz 6032: padding: 0;
1.397 albertel 6033: border-spacing: 1px;
6034: }
1.795 www 6035:
1.397 albertel 6036: table#LC_helpmenu_links tr td {
6037: padding: 1px;
6038: background: $tabbg;
1.399 albertel 6039: text-align: center;
6040: font-weight: bold;
1.397 albertel 6041: }
1.396 albertel 6042:
1.795 www 6043: table#LC_helpmenu_links a:link,
6044: table#LC_helpmenu_links a:visited,
1.397 albertel 6045: table#LC_helpmenu_links a:active {
6046: text-decoration: none;
6047: color: $font;
6048: }
1.795 www 6049:
1.397 albertel 6050: table#LC_helpmenu_links a:hover {
6051: text-decoration: underline;
6052: color: $vlink;
6053: }
1.396 albertel 6054:
1.417 albertel 6055: .LC_chrt_popup_exists {
6056: border: 1px solid #339933;
6057: margin: -1px;
6058: }
1.795 www 6059:
1.417 albertel 6060: .LC_chrt_popup_up {
6061: border: 1px solid yellow;
6062: margin: -1px;
6063: }
1.795 www 6064:
1.417 albertel 6065: .LC_chrt_popup {
6066: border: 1px solid #8888FF;
6067: background: #CCCCFF;
6068: }
1.795 www 6069:
1.421 albertel 6070: table.LC_pick_box {
6071: border-collapse: separate;
6072: background: white;
6073: border: 1px solid black;
6074: border-spacing: 1px;
6075: }
1.795 www 6076:
1.421 albertel 6077: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6078: background: $sidebg;
1.421 albertel 6079: font-weight: bold;
1.900 bisitz 6080: text-align: left;
1.740 bisitz 6081: vertical-align: top;
1.421 albertel 6082: width: 184px;
6083: padding: 8px;
6084: }
1.795 www 6085:
1.579 raeburn 6086: table.LC_pick_box td.LC_pick_box_value {
6087: text-align: left;
6088: padding: 8px;
6089: }
1.795 www 6090:
1.579 raeburn 6091: table.LC_pick_box td.LC_pick_box_select {
6092: text-align: left;
6093: padding: 8px;
6094: }
1.795 www 6095:
1.424 albertel 6096: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6097: padding: 0;
1.421 albertel 6098: height: 1px;
6099: background: black;
6100: }
1.795 www 6101:
1.421 albertel 6102: table.LC_pick_box td.LC_pick_box_submit {
6103: text-align: right;
6104: }
1.795 www 6105:
1.579 raeburn 6106: table.LC_pick_box td.LC_evenrow_value {
6107: text-align: left;
6108: padding: 8px;
6109: background-color: $data_table_light;
6110: }
1.795 www 6111:
1.579 raeburn 6112: table.LC_pick_box td.LC_oddrow_value {
6113: text-align: left;
6114: padding: 8px;
6115: background-color: $data_table_light;
6116: }
1.795 www 6117:
1.579 raeburn 6118: span.LC_helpform_receipt_cat {
6119: font-weight: bold;
6120: }
1.795 www 6121:
1.424 albertel 6122: table.LC_group_priv_box {
6123: background: white;
6124: border: 1px solid black;
6125: border-spacing: 1px;
6126: }
1.795 www 6127:
1.424 albertel 6128: table.LC_group_priv_box td.LC_pick_box_title {
6129: background: $tabbg;
6130: font-weight: bold;
6131: text-align: right;
6132: width: 184px;
6133: }
1.795 www 6134:
1.424 albertel 6135: table.LC_group_priv_box td.LC_groups_fixed {
6136: background: $data_table_light;
6137: text-align: center;
6138: }
1.795 www 6139:
1.424 albertel 6140: table.LC_group_priv_box td.LC_groups_optional {
6141: background: $data_table_dark;
6142: text-align: center;
6143: }
1.795 www 6144:
1.424 albertel 6145: table.LC_group_priv_box td.LC_groups_functionality {
6146: background: $data_table_darker;
6147: text-align: center;
6148: font-weight: bold;
6149: }
1.795 www 6150:
1.424 albertel 6151: table.LC_group_priv td {
6152: text-align: left;
1.803 bisitz 6153: padding: 0;
1.424 albertel 6154: }
6155:
6156: .LC_navbuttons {
6157: margin: 2ex 0ex 2ex 0ex;
6158: }
1.795 www 6159:
1.423 albertel 6160: .LC_topic_bar {
6161: font-weight: bold;
6162: background: $tabbg;
1.918 wenzelju 6163: margin: 1em 0em 1em 2em;
1.805 bisitz 6164: padding: 3px;
1.918 wenzelju 6165: font-size: 1.2em;
1.423 albertel 6166: }
1.795 www 6167:
1.423 albertel 6168: .LC_topic_bar span {
1.918 wenzelju 6169: left: 0.5em;
6170: position: absolute;
1.423 albertel 6171: vertical-align: middle;
1.918 wenzelju 6172: font-size: 1.2em;
1.423 albertel 6173: }
1.795 www 6174:
1.423 albertel 6175: table.LC_course_group_status {
6176: margin: 20px;
6177: }
1.795 www 6178:
1.423 albertel 6179: table.LC_status_selector td {
6180: vertical-align: top;
6181: text-align: center;
1.424 albertel 6182: padding: 4px;
6183: }
1.795 www 6184:
1.599 albertel 6185: div.LC_feedback_link {
1.616 albertel 6186: clear: both;
1.829 kalberla 6187: background: $sidebg;
1.779 bisitz 6188: width: 100%;
1.829 kalberla 6189: padding-bottom: 10px;
6190: border: 1px $tabbg solid;
1.833 kalberla 6191: height: 22px;
6192: line-height: 22px;
6193: padding-top: 5px;
6194: }
6195:
6196: div.LC_feedback_link img {
6197: height: 22px;
1.867 kalberla 6198: vertical-align:middle;
1.829 kalberla 6199: }
6200:
1.911 bisitz 6201: div.LC_feedback_link a {
1.829 kalberla 6202: text-decoration: none;
1.489 raeburn 6203: }
1.795 www 6204:
1.867 kalberla 6205: div.LC_comblock {
1.911 bisitz 6206: display:inline;
1.867 kalberla 6207: color:$font;
6208: font-size:90%;
6209: }
6210:
6211: div.LC_feedback_link div.LC_comblock {
6212: padding-left:5px;
6213: }
6214:
6215: div.LC_feedback_link div.LC_comblock a {
6216: color:$font;
6217: }
6218:
1.489 raeburn 6219: span.LC_feedback_link {
1.858 bisitz 6220: /* background: $feedback_link_bg; */
1.599 albertel 6221: font-size: larger;
6222: }
1.795 www 6223:
1.599 albertel 6224: span.LC_message_link {
1.858 bisitz 6225: /* background: $feedback_link_bg; */
1.599 albertel 6226: font-size: larger;
6227: position: absolute;
6228: right: 1em;
1.489 raeburn 6229: }
1.421 albertel 6230:
1.515 albertel 6231: table.LC_prior_tries {
1.524 albertel 6232: border: 1px solid #000000;
6233: border-collapse: separate;
6234: border-spacing: 1px;
1.515 albertel 6235: }
1.523 albertel 6236:
1.515 albertel 6237: table.LC_prior_tries td {
1.524 albertel 6238: padding: 2px;
1.515 albertel 6239: }
1.523 albertel 6240:
6241: .LC_answer_correct {
1.795 www 6242: background: lightgreen;
6243: color: darkgreen;
6244: padding: 6px;
1.523 albertel 6245: }
1.795 www 6246:
1.523 albertel 6247: .LC_answer_charged_try {
1.797 www 6248: background: #FFAAAA;
1.795 www 6249: color: darkred;
6250: padding: 6px;
1.523 albertel 6251: }
1.795 www 6252:
1.779 bisitz 6253: .LC_answer_not_charged_try,
1.523 albertel 6254: .LC_answer_no_grade,
6255: .LC_answer_late {
1.795 www 6256: background: lightyellow;
1.523 albertel 6257: color: black;
1.795 www 6258: padding: 6px;
1.523 albertel 6259: }
1.795 www 6260:
1.523 albertel 6261: .LC_answer_previous {
1.795 www 6262: background: lightblue;
6263: color: darkblue;
6264: padding: 6px;
1.523 albertel 6265: }
1.795 www 6266:
1.779 bisitz 6267: .LC_answer_no_message {
1.777 tempelho 6268: background: #FFFFFF;
6269: color: black;
1.795 www 6270: padding: 6px;
1.779 bisitz 6271: }
1.795 www 6272:
1.779 bisitz 6273: .LC_answer_unknown {
6274: background: orange;
6275: color: black;
1.795 www 6276: padding: 6px;
1.777 tempelho 6277: }
1.795 www 6278:
1.529 albertel 6279: span.LC_prior_numerical,
6280: span.LC_prior_string,
6281: span.LC_prior_custom,
6282: span.LC_prior_reaction,
6283: span.LC_prior_math {
1.925 bisitz 6284: font-family: $mono;
1.523 albertel 6285: white-space: pre;
6286: }
6287:
1.525 albertel 6288: span.LC_prior_string {
1.925 bisitz 6289: font-family: $mono;
1.525 albertel 6290: white-space: pre;
6291: }
6292:
1.523 albertel 6293: table.LC_prior_option {
6294: width: 100%;
6295: border-collapse: collapse;
6296: }
1.795 www 6297:
1.911 bisitz 6298: table.LC_prior_rank,
1.795 www 6299: table.LC_prior_match {
1.528 albertel 6300: border-collapse: collapse;
6301: }
1.795 www 6302:
1.528 albertel 6303: table.LC_prior_option tr td,
6304: table.LC_prior_rank tr td,
6305: table.LC_prior_match tr td {
1.524 albertel 6306: border: 1px solid #000000;
1.515 albertel 6307: }
6308:
1.855 bisitz 6309: .LC_nobreak {
1.544 albertel 6310: white-space: nowrap;
1.519 raeburn 6311: }
6312:
1.576 raeburn 6313: span.LC_cusr_emph {
6314: font-style: italic;
6315: }
6316:
1.633 raeburn 6317: span.LC_cusr_subheading {
6318: font-weight: normal;
6319: font-size: 85%;
6320: }
6321:
1.861 bisitz 6322: div.LC_docs_entry_move {
1.859 bisitz 6323: border: 1px solid #BBBBBB;
1.545 albertel 6324: background: #DDDDDD;
1.861 bisitz 6325: width: 22px;
1.859 bisitz 6326: padding: 1px;
6327: margin: 0;
1.545 albertel 6328: }
6329:
1.861 bisitz 6330: table.LC_data_table tr > td.LC_docs_entry_commands,
6331: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6332: font-size: x-small;
6333: }
1.795 www 6334:
1.861 bisitz 6335: .LC_docs_entry_parameter {
6336: white-space: nowrap;
6337: }
6338:
1.544 albertel 6339: .LC_docs_copy {
1.545 albertel 6340: color: #000099;
1.544 albertel 6341: }
1.795 www 6342:
1.544 albertel 6343: .LC_docs_cut {
1.545 albertel 6344: color: #550044;
1.544 albertel 6345: }
1.795 www 6346:
1.544 albertel 6347: .LC_docs_rename {
1.545 albertel 6348: color: #009900;
1.544 albertel 6349: }
1.795 www 6350:
1.544 albertel 6351: .LC_docs_remove {
1.545 albertel 6352: color: #990000;
6353: }
6354:
1.547 albertel 6355: .LC_docs_reinit_warn,
6356: .LC_docs_ext_edit {
6357: font-size: x-small;
6358: }
6359:
1.545 albertel 6360: table.LC_docs_adddocs td,
6361: table.LC_docs_adddocs th {
6362: border: 1px solid #BBBBBB;
6363: padding: 4px;
6364: background: #DDDDDD;
1.543 albertel 6365: }
6366:
1.584 albertel 6367: table.LC_sty_begin {
6368: background: #BBFFBB;
6369: }
1.795 www 6370:
1.584 albertel 6371: table.LC_sty_end {
6372: background: #FFBBBB;
6373: }
6374:
1.589 raeburn 6375: table.LC_double_column {
1.803 bisitz 6376: border-width: 0;
1.589 raeburn 6377: border-collapse: collapse;
6378: width: 100%;
6379: padding: 2px;
6380: }
6381:
6382: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6383: top: 2px;
1.589 raeburn 6384: left: 2px;
6385: width: 47%;
6386: vertical-align: top;
6387: }
6388:
6389: table.LC_double_column tr td.LC_right_col {
6390: top: 2px;
1.779 bisitz 6391: right: 2px;
1.589 raeburn 6392: width: 47%;
6393: vertical-align: top;
6394: }
6395:
1.591 raeburn 6396: div.LC_left_float {
6397: float: left;
6398: padding-right: 5%;
1.597 albertel 6399: padding-bottom: 4px;
1.591 raeburn 6400: }
6401:
6402: div.LC_clear_float_header {
1.597 albertel 6403: padding-bottom: 2px;
1.591 raeburn 6404: }
6405:
6406: div.LC_clear_float_footer {
1.597 albertel 6407: padding-top: 10px;
1.591 raeburn 6408: clear: both;
6409: }
6410:
1.597 albertel 6411: div.LC_grade_show_user {
1.941 bisitz 6412: /* border-left: 5px solid $sidebg; */
6413: border-top: 5px solid #000000;
6414: margin: 50px 0 0 0;
1.936 bisitz 6415: padding: 15px 0 5px 10px;
1.597 albertel 6416: }
1.795 www 6417:
1.936 bisitz 6418: div.LC_grade_show_user_odd_row {
1.941 bisitz 6419: /* border-left: 5px solid #000000; */
6420: }
6421:
6422: div.LC_grade_show_user div.LC_Box {
6423: margin-right: 50px;
1.597 albertel 6424: }
6425:
6426: div.LC_grade_submissions,
6427: div.LC_grade_message_center,
1.936 bisitz 6428: div.LC_grade_info_links {
1.597 albertel 6429: margin: 5px;
6430: width: 99%;
6431: background: #FFFFFF;
6432: }
1.795 www 6433:
1.597 albertel 6434: div.LC_grade_submissions_header,
1.936 bisitz 6435: div.LC_grade_message_center_header {
1.705 tempelho 6436: font-weight: bold;
6437: font-size: large;
1.597 albertel 6438: }
1.795 www 6439:
1.597 albertel 6440: div.LC_grade_submissions_body,
1.936 bisitz 6441: div.LC_grade_message_center_body {
1.597 albertel 6442: border: 1px solid black;
6443: width: 99%;
6444: background: #FFFFFF;
6445: }
1.795 www 6446:
1.613 albertel 6447: table.LC_scantron_action {
6448: width: 100%;
6449: }
1.795 www 6450:
1.613 albertel 6451: table.LC_scantron_action tr th {
1.698 harmsja 6452: font-weight:bold;
6453: font-style:normal;
1.613 albertel 6454: }
1.795 www 6455:
1.779 bisitz 6456: .LC_edit_problem_header,
1.614 albertel 6457: div.LC_edit_problem_footer {
1.705 tempelho 6458: font-weight: normal;
6459: font-size: medium;
1.602 albertel 6460: margin: 2px;
1.1060 bisitz 6461: background-color: $sidebg;
1.600 albertel 6462: }
1.795 www 6463:
1.600 albertel 6464: div.LC_edit_problem_header,
1.602 albertel 6465: div.LC_edit_problem_header div,
1.614 albertel 6466: div.LC_edit_problem_footer,
6467: div.LC_edit_problem_footer div,
1.602 albertel 6468: div.LC_edit_problem_editxml_header,
6469: div.LC_edit_problem_editxml_header div {
1.600 albertel 6470: margin-top: 5px;
6471: }
1.795 www 6472:
1.600 albertel 6473: div.LC_edit_problem_header_title {
1.705 tempelho 6474: font-weight: bold;
6475: font-size: larger;
1.602 albertel 6476: background: $tabbg;
6477: padding: 3px;
1.1060 bisitz 6478: margin: 0 0 5px 0;
1.602 albertel 6479: }
1.795 www 6480:
1.602 albertel 6481: table.LC_edit_problem_header_title {
6482: width: 100%;
1.600 albertel 6483: background: $tabbg;
1.602 albertel 6484: }
6485:
6486: div.LC_edit_problem_discards {
6487: float: left;
6488: padding-bottom: 5px;
6489: }
1.795 www 6490:
1.602 albertel 6491: div.LC_edit_problem_saves {
6492: float: right;
6493: padding-bottom: 5px;
1.600 albertel 6494: }
1.795 www 6495:
1.1124 bisitz 6496: .LC_edit_opt {
6497: padding-left: 1em;
6498: white-space: nowrap;
6499: }
6500:
1.1152 golterma 6501: .LC_edit_problem_latexhelper{
6502: text-align: right;
6503: }
6504:
6505: #LC_edit_problem_colorful div{
6506: margin-left: 40px;
6507: }
6508:
1.911 bisitz 6509: img.stift {
1.803 bisitz 6510: border-width: 0;
6511: vertical-align: middle;
1.677 riegler 6512: }
1.680 riegler 6513:
1.923 bisitz 6514: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6515: vertical-align: top;
1.777 tempelho 6516: }
1.795 www 6517:
1.716 raeburn 6518: div.LC_createcourse {
1.911 bisitz 6519: margin: 10px 10px 10px 10px;
1.716 raeburn 6520: }
6521:
1.917 raeburn 6522: .LC_dccid {
1.1130 raeburn 6523: float: right;
1.917 raeburn 6524: margin: 0.2em 0 0 0;
6525: padding: 0;
6526: font-size: 90%;
6527: display:none;
6528: }
6529:
1.897 wenzelju 6530: ol.LC_primary_menu a:hover,
1.721 harmsja 6531: ol#LC_MenuBreadcrumbs a:hover,
6532: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6533: ul#LC_secondary_menu a:hover,
1.721 harmsja 6534: .LC_FormSectionClearButton input:hover
1.795 www 6535: ul.LC_TabContent li:hover a {
1.952 onken 6536: color:$button_hover;
1.911 bisitz 6537: text-decoration:none;
1.693 droeschl 6538: }
6539:
1.779 bisitz 6540: h1 {
1.911 bisitz 6541: padding: 0;
6542: line-height:130%;
1.693 droeschl 6543: }
1.698 harmsja 6544:
1.911 bisitz 6545: h2,
6546: h3,
6547: h4,
6548: h5,
6549: h6 {
6550: margin: 5px 0 5px 0;
6551: padding: 0;
6552: line-height:130%;
1.693 droeschl 6553: }
1.795 www 6554:
6555: .LC_hcell {
1.911 bisitz 6556: padding:3px 15px 3px 15px;
6557: margin: 0;
6558: background-color:$tabbg;
6559: color:$fontmenu;
6560: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6561: }
1.795 www 6562:
1.840 bisitz 6563: .LC_Box > .LC_hcell {
1.911 bisitz 6564: margin: 0 -10px 10px -10px;
1.835 bisitz 6565: }
6566:
1.721 harmsja 6567: .LC_noBorder {
1.911 bisitz 6568: border: 0;
1.698 harmsja 6569: }
1.693 droeschl 6570:
1.721 harmsja 6571: .LC_FormSectionClearButton input {
1.911 bisitz 6572: background-color:transparent;
6573: border: none;
6574: cursor:pointer;
6575: text-decoration:underline;
1.693 droeschl 6576: }
1.763 bisitz 6577:
6578: .LC_help_open_topic {
1.911 bisitz 6579: color: #FFFFFF;
6580: background-color: #EEEEFF;
6581: margin: 1px;
6582: padding: 4px;
6583: border: 1px solid #000033;
6584: white-space: nowrap;
6585: /* vertical-align: middle; */
1.759 neumanie 6586: }
1.693 droeschl 6587:
1.911 bisitz 6588: dl,
6589: ul,
6590: div,
6591: fieldset {
6592: margin: 10px 10px 10px 0;
6593: /* overflow: hidden; */
1.693 droeschl 6594: }
1.795 www 6595:
1.838 bisitz 6596: fieldset > legend {
1.911 bisitz 6597: font-weight: bold;
6598: padding: 0 5px 0 5px;
1.838 bisitz 6599: }
6600:
1.813 bisitz 6601: #LC_nav_bar {
1.911 bisitz 6602: float: left;
1.995 raeburn 6603: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6604: margin: 0 0 2px 0;
1.807 droeschl 6605: }
6606:
1.916 droeschl 6607: #LC_realm {
6608: margin: 0.2em 0 0 0;
6609: padding: 0;
6610: font-weight: bold;
6611: text-align: center;
1.995 raeburn 6612: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6613: }
6614:
1.911 bisitz 6615: #LC_nav_bar em {
6616: font-weight: bold;
6617: font-style: normal;
1.807 droeschl 6618: }
6619:
1.897 wenzelju 6620: ol.LC_primary_menu {
1.934 droeschl 6621: margin: 0;
1.1076 raeburn 6622: padding: 0;
1.995 raeburn 6623: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6624: }
6625:
1.852 droeschl 6626: ol#LC_PathBreadcrumbs {
1.911 bisitz 6627: margin: 0;
1.693 droeschl 6628: }
6629:
1.897 wenzelju 6630: ol.LC_primary_menu li {
1.1076 raeburn 6631: color: RGB(80, 80, 80);
6632: vertical-align: middle;
6633: text-align: left;
6634: list-style: none;
6635: float: left;
6636: }
6637:
6638: ol.LC_primary_menu li a {
6639: display: block;
6640: margin: 0;
6641: padding: 0 5px 0 10px;
6642: text-decoration: none;
6643: }
6644:
6645: ol.LC_primary_menu li ul {
6646: display: none;
6647: width: 10em;
6648: background-color: $data_table_light;
6649: }
6650:
6651: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6652: display: block;
6653: position: absolute;
6654: margin: 0;
6655: padding: 0;
1.1078 raeburn 6656: z-index: 2;
1.1076 raeburn 6657: }
6658:
6659: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6660: font-size: 90%;
1.911 bisitz 6661: vertical-align: top;
1.1076 raeburn 6662: float: none;
1.1079 raeburn 6663: border-left: 1px solid black;
6664: border-right: 1px solid black;
1.1076 raeburn 6665: }
6666:
6667: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6668: background-color:$data_table_light;
1.1076 raeburn 6669: }
6670:
6671: ol.LC_primary_menu li li a:hover {
6672: color:$button_hover;
6673: background-color:$data_table_dark;
1.693 droeschl 6674: }
6675:
1.897 wenzelju 6676: ol.LC_primary_menu li img {
1.911 bisitz 6677: vertical-align: bottom;
1.934 droeschl 6678: height: 1.1em;
1.1077 raeburn 6679: margin: 0.2em 0 0 0;
1.693 droeschl 6680: }
6681:
1.897 wenzelju 6682: ol.LC_primary_menu a {
1.911 bisitz 6683: color: RGB(80, 80, 80);
6684: text-decoration: none;
1.693 droeschl 6685: }
1.795 www 6686:
1.949 droeschl 6687: ol.LC_primary_menu a.LC_new_message {
6688: font-weight:bold;
6689: color: darkred;
6690: }
6691:
1.975 raeburn 6692: ol.LC_docs_parameters {
6693: margin-left: 0;
6694: padding: 0;
6695: list-style: none;
6696: }
6697:
6698: ol.LC_docs_parameters li {
6699: margin: 0;
6700: padding-right: 20px;
6701: display: inline;
6702: }
6703:
1.976 raeburn 6704: ol.LC_docs_parameters li:before {
6705: content: "\\002022 \\0020";
6706: }
6707:
6708: li.LC_docs_parameters_title {
6709: font-weight: bold;
6710: }
6711:
6712: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6713: content: "";
6714: }
6715:
1.897 wenzelju 6716: ul#LC_secondary_menu {
1.1107 raeburn 6717: clear: right;
1.911 bisitz 6718: color: $fontmenu;
6719: background: $tabbg;
6720: list-style: none;
6721: padding: 0;
6722: margin: 0;
6723: width: 100%;
1.995 raeburn 6724: text-align: left;
1.1107 raeburn 6725: float: left;
1.808 droeschl 6726: }
6727:
1.897 wenzelju 6728: ul#LC_secondary_menu li {
1.911 bisitz 6729: font-weight: bold;
6730: line-height: 1.8em;
1.1107 raeburn 6731: border-right: 1px solid black;
6732: float: left;
6733: }
6734:
6735: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6736: background-color: $data_table_light;
6737: }
6738:
6739: ul#LC_secondary_menu li a {
1.911 bisitz 6740: padding: 0 0.8em;
1.1107 raeburn 6741: }
6742:
6743: ul#LC_secondary_menu li ul {
6744: display: none;
6745: }
6746:
6747: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6748: display: block;
6749: position: absolute;
6750: margin: 0;
6751: padding: 0;
6752: list-style:none;
6753: float: none;
6754: background-color: $data_table_light;
6755: z-index: 2;
6756: margin-left: -1px;
6757: }
6758:
6759: ul#LC_secondary_menu li ul li {
6760: font-size: 90%;
6761: vertical-align: top;
6762: border-left: 1px solid black;
1.911 bisitz 6763: border-right: 1px solid black;
1.1119 raeburn 6764: background-color: $data_table_light;
1.1107 raeburn 6765: list-style:none;
6766: float: none;
6767: }
6768:
6769: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6770: background-color: $data_table_dark;
1.807 droeschl 6771: }
6772:
1.847 tempelho 6773: ul.LC_TabContent {
1.911 bisitz 6774: display:block;
6775: background: $sidebg;
6776: border-bottom: solid 1px $lg_border_color;
6777: list-style:none;
1.1020 raeburn 6778: margin: -1px -10px 0 -10px;
1.911 bisitz 6779: padding: 0;
1.693 droeschl 6780: }
6781:
1.795 www 6782: ul.LC_TabContent li,
6783: ul.LC_TabContentBigger li {
1.911 bisitz 6784: float:left;
1.741 harmsja 6785: }
1.795 www 6786:
1.897 wenzelju 6787: ul#LC_secondary_menu li a {
1.911 bisitz 6788: color: $fontmenu;
6789: text-decoration: none;
1.693 droeschl 6790: }
1.795 www 6791:
1.721 harmsja 6792: ul.LC_TabContent {
1.952 onken 6793: min-height:20px;
1.721 harmsja 6794: }
1.795 www 6795:
6796: ul.LC_TabContent li {
1.911 bisitz 6797: vertical-align:middle;
1.959 onken 6798: padding: 0 16px 0 10px;
1.911 bisitz 6799: background-color:$tabbg;
6800: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6801: border-left: solid 1px $font;
1.721 harmsja 6802: }
1.795 www 6803:
1.847 tempelho 6804: ul.LC_TabContent .right {
1.911 bisitz 6805: float:right;
1.847 tempelho 6806: }
6807:
1.911 bisitz 6808: ul.LC_TabContent li a,
6809: ul.LC_TabContent li {
6810: color:rgb(47,47,47);
6811: text-decoration:none;
6812: font-size:95%;
6813: font-weight:bold;
1.952 onken 6814: min-height:20px;
6815: }
6816:
1.959 onken 6817: ul.LC_TabContent li a:hover,
6818: ul.LC_TabContent li a:focus {
1.952 onken 6819: color: $button_hover;
1.959 onken 6820: background:none;
6821: outline:none;
1.952 onken 6822: }
6823:
6824: ul.LC_TabContent li:hover {
6825: color: $button_hover;
6826: cursor:pointer;
1.721 harmsja 6827: }
1.795 www 6828:
1.911 bisitz 6829: ul.LC_TabContent li.active {
1.952 onken 6830: color: $font;
1.911 bisitz 6831: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6832: border-bottom:solid 1px #FFFFFF;
6833: cursor: default;
1.744 ehlerst 6834: }
1.795 www 6835:
1.959 onken 6836: ul.LC_TabContent li.active a {
6837: color:$font;
6838: background:#FFFFFF;
6839: outline: none;
6840: }
1.1047 raeburn 6841:
6842: ul.LC_TabContent li.goback {
6843: float: left;
6844: border-left: none;
6845: }
6846:
1.870 tempelho 6847: #maincoursedoc {
1.911 bisitz 6848: clear:both;
1.870 tempelho 6849: }
6850:
6851: ul.LC_TabContentBigger {
1.911 bisitz 6852: display:block;
6853: list-style:none;
6854: padding: 0;
1.870 tempelho 6855: }
6856:
1.795 www 6857: ul.LC_TabContentBigger li {
1.911 bisitz 6858: vertical-align:bottom;
6859: height: 30px;
6860: font-size:110%;
6861: font-weight:bold;
6862: color: #737373;
1.841 tempelho 6863: }
6864:
1.957 onken 6865: ul.LC_TabContentBigger li.active {
6866: position: relative;
6867: top: 1px;
6868: }
6869:
1.870 tempelho 6870: ul.LC_TabContentBigger li a {
1.911 bisitz 6871: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6872: height: 30px;
6873: line-height: 30px;
6874: text-align: center;
6875: display: block;
6876: text-decoration: none;
1.958 onken 6877: outline: none;
1.741 harmsja 6878: }
1.795 www 6879:
1.870 tempelho 6880: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6881: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6882: color:$font;
1.744 ehlerst 6883: }
1.795 www 6884:
1.870 tempelho 6885: ul.LC_TabContentBigger li b {
1.911 bisitz 6886: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6887: display: block;
6888: float: left;
6889: padding: 0 30px;
1.957 onken 6890: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6891: }
6892:
1.956 onken 6893: ul.LC_TabContentBigger li:hover b {
6894: color:$button_hover;
6895: }
6896:
1.870 tempelho 6897: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6898: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6899: color:$font;
1.957 onken 6900: border: 0;
1.741 harmsja 6901: }
1.693 droeschl 6902:
1.870 tempelho 6903:
1.862 bisitz 6904: ul.LC_CourseBreadcrumbs {
6905: background: $sidebg;
1.1020 raeburn 6906: height: 2em;
1.862 bisitz 6907: padding-left: 10px;
1.1020 raeburn 6908: margin: 0;
1.862 bisitz 6909: list-style-position: inside;
6910: }
6911:
1.911 bisitz 6912: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6913: ol#LC_PathBreadcrumbs {
1.911 bisitz 6914: padding-left: 10px;
6915: margin: 0;
1.933 droeschl 6916: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6917: }
6918:
1.911 bisitz 6919: ol#LC_MenuBreadcrumbs li,
6920: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6921: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6922: display: inline;
1.933 droeschl 6923: white-space: normal;
1.693 droeschl 6924: }
6925:
1.823 bisitz 6926: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6927: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6928: text-decoration: none;
6929: font-size:90%;
1.693 droeschl 6930: }
1.795 www 6931:
1.969 droeschl 6932: ol#LC_MenuBreadcrumbs h1 {
6933: display: inline;
6934: font-size: 90%;
6935: line-height: 2.5em;
6936: margin: 0;
6937: padding: 0;
6938: }
6939:
1.795 www 6940: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6941: text-decoration:none;
6942: font-size:100%;
6943: font-weight:bold;
1.693 droeschl 6944: }
1.795 www 6945:
1.840 bisitz 6946: .LC_Box {
1.911 bisitz 6947: border: solid 1px $lg_border_color;
6948: padding: 0 10px 10px 10px;
1.746 neumanie 6949: }
1.795 www 6950:
1.1020 raeburn 6951: .LC_DocsBox {
6952: border: solid 1px $lg_border_color;
6953: padding: 0 0 10px 10px;
6954: }
6955:
1.795 www 6956: .LC_AboutMe_Image {
1.911 bisitz 6957: float:left;
6958: margin-right:10px;
1.747 neumanie 6959: }
1.795 www 6960:
6961: .LC_Clear_AboutMe_Image {
1.911 bisitz 6962: clear:left;
1.747 neumanie 6963: }
1.795 www 6964:
1.721 harmsja 6965: dl.LC_ListStyleClean dt {
1.911 bisitz 6966: padding-right: 5px;
6967: display: table-header-group;
1.693 droeschl 6968: }
6969:
1.721 harmsja 6970: dl.LC_ListStyleClean dd {
1.911 bisitz 6971: display: table-row;
1.693 droeschl 6972: }
6973:
1.721 harmsja 6974: .LC_ListStyleClean,
6975: .LC_ListStyleSimple,
6976: .LC_ListStyleNormal,
1.795 www 6977: .LC_ListStyleSpecial {
1.911 bisitz 6978: /* display:block; */
6979: list-style-position: inside;
6980: list-style-type: none;
6981: overflow: hidden;
6982: padding: 0;
1.693 droeschl 6983: }
6984:
1.721 harmsja 6985: .LC_ListStyleSimple li,
6986: .LC_ListStyleSimple dd,
6987: .LC_ListStyleNormal li,
6988: .LC_ListStyleNormal dd,
6989: .LC_ListStyleSpecial li,
1.795 www 6990: .LC_ListStyleSpecial dd {
1.911 bisitz 6991: margin: 0;
6992: padding: 5px 5px 5px 10px;
6993: clear: both;
1.693 droeschl 6994: }
6995:
1.721 harmsja 6996: .LC_ListStyleClean li,
6997: .LC_ListStyleClean dd {
1.911 bisitz 6998: padding-top: 0;
6999: padding-bottom: 0;
1.693 droeschl 7000: }
7001:
1.721 harmsja 7002: .LC_ListStyleSimple dd,
1.795 www 7003: .LC_ListStyleSimple li {
1.911 bisitz 7004: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7005: }
7006:
1.721 harmsja 7007: .LC_ListStyleSpecial li,
7008: .LC_ListStyleSpecial dd {
1.911 bisitz 7009: list-style-type: none;
7010: background-color: RGB(220, 220, 220);
7011: margin-bottom: 4px;
1.693 droeschl 7012: }
7013:
1.721 harmsja 7014: table.LC_SimpleTable {
1.911 bisitz 7015: margin:5px;
7016: border:solid 1px $lg_border_color;
1.795 www 7017: }
1.693 droeschl 7018:
1.721 harmsja 7019: table.LC_SimpleTable tr {
1.911 bisitz 7020: padding: 0;
7021: border:solid 1px $lg_border_color;
1.693 droeschl 7022: }
1.795 www 7023:
7024: table.LC_SimpleTable thead {
1.911 bisitz 7025: background:rgb(220,220,220);
1.693 droeschl 7026: }
7027:
1.721 harmsja 7028: div.LC_columnSection {
1.911 bisitz 7029: display: block;
7030: clear: both;
7031: overflow: hidden;
7032: margin: 0;
1.693 droeschl 7033: }
7034:
1.721 harmsja 7035: div.LC_columnSection>* {
1.911 bisitz 7036: float: left;
7037: margin: 10px 20px 10px 0;
7038: overflow:hidden;
1.693 droeschl 7039: }
1.721 harmsja 7040:
1.795 www 7041: table em {
1.911 bisitz 7042: font-weight: bold;
7043: font-style: normal;
1.748 schulted 7044: }
1.795 www 7045:
1.779 bisitz 7046: table.LC_tableBrowseRes,
1.795 www 7047: table.LC_tableOfContent {
1.911 bisitz 7048: border:none;
7049: border-spacing: 1px;
7050: padding: 3px;
7051: background-color: #FFFFFF;
7052: font-size: 90%;
1.753 droeschl 7053: }
1.789 droeschl 7054:
1.911 bisitz 7055: table.LC_tableOfContent {
7056: border-collapse: collapse;
1.789 droeschl 7057: }
7058:
1.771 droeschl 7059: table.LC_tableBrowseRes a,
1.768 schulted 7060: table.LC_tableOfContent a {
1.911 bisitz 7061: background-color: transparent;
7062: text-decoration: none;
1.753 droeschl 7063: }
7064:
1.795 www 7065: table.LC_tableOfContent img {
1.911 bisitz 7066: border: none;
7067: height: 1.3em;
7068: vertical-align: text-bottom;
7069: margin-right: 0.3em;
1.753 droeschl 7070: }
1.757 schulted 7071:
1.795 www 7072: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7073: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7074: }
7075:
1.795 www 7076: a#LC_content_toolbar_everything {
1.911 bisitz 7077: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7078: }
7079:
1.795 www 7080: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7081: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7082: }
7083:
1.795 www 7084: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7085: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7086: }
7087:
1.795 www 7088: a#LC_content_toolbar_changefolder {
1.911 bisitz 7089: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7090: }
7091:
1.795 www 7092: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7093: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7094: }
7095:
1.1043 raeburn 7096: a#LC_content_toolbar_edittoplevel {
7097: background-image:url(/res/adm/pages/edittoplevel.gif);
7098: }
7099:
1.795 www 7100: ul#LC_toolbar li a:hover {
1.911 bisitz 7101: background-position: bottom center;
1.757 schulted 7102: }
7103:
1.795 www 7104: ul#LC_toolbar {
1.911 bisitz 7105: padding: 0;
7106: margin: 2px;
7107: list-style:none;
7108: position:relative;
7109: background-color:white;
1.1082 raeburn 7110: overflow: auto;
1.757 schulted 7111: }
7112:
1.795 www 7113: ul#LC_toolbar li {
1.911 bisitz 7114: border:1px solid white;
7115: padding: 0;
7116: margin: 0;
7117: float: left;
7118: display:inline;
7119: vertical-align:middle;
1.1082 raeburn 7120: white-space: nowrap;
1.911 bisitz 7121: }
1.757 schulted 7122:
1.783 amueller 7123:
1.795 www 7124: a.LC_toolbarItem {
1.911 bisitz 7125: display:block;
7126: padding: 0;
7127: margin: 0;
7128: height: 32px;
7129: width: 32px;
7130: color:white;
7131: border: none;
7132: background-repeat:no-repeat;
7133: background-color:transparent;
1.757 schulted 7134: }
7135:
1.915 droeschl 7136: ul.LC_funclist {
7137: margin: 0;
7138: padding: 0.5em 1em 0.5em 0;
7139: }
7140:
1.933 droeschl 7141: ul.LC_funclist > li:first-child {
7142: font-weight:bold;
7143: margin-left:0.8em;
7144: }
7145:
1.915 droeschl 7146: ul.LC_funclist + ul.LC_funclist {
7147: /*
7148: left border as a seperator if we have more than
7149: one list
7150: */
7151: border-left: 1px solid $sidebg;
7152: /*
7153: this hides the left border behind the border of the
7154: outer box if element is wrapped to the next 'line'
7155: */
7156: margin-left: -1px;
7157: }
7158:
1.843 bisitz 7159: ul.LC_funclist li {
1.915 droeschl 7160: display: inline;
1.782 bisitz 7161: white-space: nowrap;
1.915 droeschl 7162: margin: 0 0 0 25px;
7163: line-height: 150%;
1.782 bisitz 7164: }
7165:
1.974 wenzelju 7166: .LC_hidden {
7167: display: none;
7168: }
7169:
1.1030 www 7170: .LCmodal-overlay {
7171: position:fixed;
7172: top:0;
7173: right:0;
7174: bottom:0;
7175: left:0;
7176: height:100%;
7177: width:100%;
7178: margin:0;
7179: padding:0;
7180: background:#999;
7181: opacity:.75;
7182: filter: alpha(opacity=75);
7183: -moz-opacity: 0.75;
7184: z-index:101;
7185: }
7186:
7187: * html .LCmodal-overlay {
7188: position: absolute;
7189: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7190: }
7191:
7192: .LCmodal-window {
7193: position:fixed;
7194: top:50%;
7195: left:50%;
7196: margin:0;
7197: padding:0;
7198: z-index:102;
7199: }
7200:
7201: * html .LCmodal-window {
7202: position:absolute;
7203: }
7204:
7205: .LCclose-window {
7206: position:absolute;
7207: width:32px;
7208: height:32px;
7209: right:8px;
7210: top:8px;
7211: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7212: text-indent:-99999px;
7213: overflow:hidden;
7214: cursor:pointer;
7215: }
7216:
1.1100 raeburn 7217: /*
7218: styles used by TTH when "Default set of options to pass to tth/m
7219: when converting TeX" in course settings has been set
7220:
7221: option passed: -t
7222:
7223: */
7224:
7225: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7226: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7227: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7228: td div.norm {line-height:normal;}
7229:
7230: /*
7231: option passed -y3
7232: */
7233:
7234: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7235: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7236: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7237:
1.343 albertel 7238: END
7239: }
7240:
1.306 albertel 7241: =pod
7242:
7243: =item * &headtag()
7244:
7245: Returns a uniform footer for LON-CAPA web pages.
7246:
1.307 albertel 7247: Inputs: $title - optional title for the head
7248: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7249: $args - optional arguments
1.319 albertel 7250: force_register - if is true call registerurl so the remote is
7251: informed
1.415 albertel 7252: redirect -> array ref of
7253: 1- seconds before redirect occurs
7254: 2- url to redirect to
7255: 3- whether the side effect should occur
1.315 albertel 7256: (side effect of setting
7257: $env{'internal.head.redirect'} to the url
7258: redirected too)
1.352 albertel 7259: domain -> force to color decorate a page for a specific
7260: domain
7261: function -> force usage of a specific rolish color scheme
7262: bgcolor -> override the default page bgcolor
1.460 albertel 7263: no_auto_mt_title
7264: -> prevent &mt()ing the title arg
1.464 albertel 7265:
1.306 albertel 7266: =cut
7267:
7268: sub headtag {
1.313 albertel 7269: my ($title,$head_extra,$args) = @_;
1.306 albertel 7270:
1.363 albertel 7271: my $function = $args->{'function'} || &get_users_function();
7272: my $domain = $args->{'domain'} || &determinedomain();
7273: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7274: my $httphost = $args->{'use_absolute'};
1.418 albertel 7275: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7276: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7277: #time(),
1.418 albertel 7278: $env{'environment.color.timestamp'},
1.363 albertel 7279: $function,$domain,$bgcolor);
7280:
1.369 www 7281: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7282:
1.308 albertel 7283: my $result =
7284: '<head>'.
1.1160 raeburn 7285: &font_settings($args);
1.319 albertel 7286:
1.1064 raeburn 7287: my $inhibitprint = &print_suppression();
7288:
1.461 albertel 7289: if (!$args->{'frameset'}) {
7290: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7291: }
1.962 droeschl 7292: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7293: $result .= Apache::lonxml::display_title();
1.319 albertel 7294: }
1.436 albertel 7295: if (!$args->{'no_nav_bar'}
7296: && !$args->{'only_body'}
7297: && !$args->{'frameset'}) {
1.1154 raeburn 7298: $result .= &help_menu_js($httphost);
1.1032 www 7299: $result.=&modal_window();
1.1038 www 7300: $result.=&togglebox_script();
1.1034 www 7301: $result.=&wishlist_window();
1.1041 www 7302: $result.=&LCprogressbarUpdate_script();
1.1034 www 7303: } else {
7304: if ($args->{'add_modal'}) {
7305: $result.=&modal_window();
7306: }
7307: if ($args->{'add_wishlist'}) {
7308: $result.=&wishlist_window();
7309: }
1.1038 www 7310: if ($args->{'add_togglebox'}) {
7311: $result.=&togglebox_script();
7312: }
1.1041 www 7313: if ($args->{'add_progressbar'}) {
7314: $result.=&LCprogressbarUpdate_script();
7315: }
1.436 albertel 7316: }
1.314 albertel 7317: if (ref($args->{'redirect'})) {
1.414 albertel 7318: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7319: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7320: if (!$inhibit_continue) {
7321: $env{'internal.head.redirect'} = $url;
7322: }
1.313 albertel 7323: $result.=<<ADDMETA
7324: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7325: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7326: ADDMETA
7327: }
1.306 albertel 7328: if (!defined($title)) {
7329: $title = 'The LearningOnline Network with CAPA';
7330: }
1.460 albertel 7331: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7332: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7333: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7334: .$inhibitprint
1.414 albertel 7335: .$head_extra;
1.1137 raeburn 7336: if ($env{'browser.mobile'}) {
7337: $result .= '
7338: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7339: <meta name="apple-mobile-web-app-capable" content="yes" />';
7340: }
1.962 droeschl 7341: return $result.'</head>';
1.306 albertel 7342: }
7343:
7344: =pod
7345:
1.340 albertel 7346: =item * &font_settings()
7347:
7348: Returns neccessary <meta> to set the proper encoding
7349:
1.1160 raeburn 7350: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7351:
7352: =cut
7353:
7354: sub font_settings {
1.1160 raeburn 7355: my ($args) = @_;
1.340 albertel 7356: my $headerstring='';
1.1160 raeburn 7357: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7358: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7359: $headerstring.=
1.1159 raeburn 7360: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
1.340 albertel 7361: }
7362: return $headerstring;
7363: }
7364:
1.341 albertel 7365: =pod
7366:
1.1064 raeburn 7367: =item * &print_suppression()
7368:
7369: In course context returns css which causes the body to be blank when media="print",
7370: if printout generation is unavailable for the current resource.
7371:
7372: This could be because:
7373:
7374: (a) printstartdate is in the future
7375:
7376: (b) printenddate is in the past
7377:
7378: (c) there is an active exam block with "printout"
7379: functionality blocked
7380:
7381: Users with pav, pfo or evb privileges are exempt.
7382:
7383: Inputs: none
7384:
7385: =cut
7386:
7387:
7388: sub print_suppression {
7389: my $noprint;
7390: if ($env{'request.course.id'}) {
7391: my $scope = $env{'request.course.id'};
7392: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7393: (&Apache::lonnet::allowed('pfo',$scope))) {
7394: return;
7395: }
7396: if ($env{'request.course.sec'} ne '') {
7397: $scope .= "/$env{'request.course.sec'}";
7398: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7399: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7400: return;
1.1064 raeburn 7401: }
7402: }
7403: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7404: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7405: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7406: if ($blocked) {
7407: my $checkrole = "cm./$cdom/$cnum";
7408: if ($env{'request.course.sec'} ne '') {
7409: $checkrole .= "/$env{'request.course.sec'}";
7410: }
7411: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7412: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7413: $noprint = 1;
7414: }
7415: }
7416: unless ($noprint) {
7417: my $symb = &Apache::lonnet::symbread();
7418: if ($symb ne '') {
7419: my $navmap = Apache::lonnavmaps::navmap->new();
7420: if (ref($navmap)) {
7421: my $res = $navmap->getBySymb($symb);
7422: if (ref($res)) {
7423: if (!$res->resprintable()) {
7424: $noprint = 1;
7425: }
7426: }
7427: }
7428: }
7429: }
7430: if ($noprint) {
7431: return <<"ENDSTYLE";
7432: <style type="text/css" media="print">
7433: body { display:none }
7434: </style>
7435: ENDSTYLE
7436: }
7437: }
7438: return;
7439: }
7440:
7441: =pod
7442:
1.341 albertel 7443: =item * &xml_begin()
7444:
7445: Returns the needed doctype and <html>
7446:
7447: Inputs: none
7448:
7449: =cut
7450:
7451: sub xml_begin {
7452: my $output='';
7453:
7454: if ($env{'browser.mathml'}) {
7455: $output='<?xml version="1.0"?>'
7456: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7457: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7458:
7459: # .'<!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">] >'
7460: .'<!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">'
7461: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7462: .'xmlns="http://www.w3.org/1999/xhtml">';
7463: } else {
1.1159 raeburn 7464: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n"
7465: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7466: }
7467: return $output;
7468: }
1.340 albertel 7469:
7470: =pod
7471:
1.306 albertel 7472: =item * &start_page()
7473:
7474: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7475:
1.648 raeburn 7476: Inputs:
7477:
7478: =over 4
7479:
7480: $title - optional title for the page
7481:
7482: $head_extra - optional extra HTML to incude inside the <head>
7483:
7484: $args - additional optional args supported are:
7485:
7486: =over 8
7487:
7488: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7489: arg on
1.814 bisitz 7490: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7491: add_entries -> additional attributes to add to the <body>
7492: domain -> force to color decorate a page for a
1.317 albertel 7493: specific domain
1.648 raeburn 7494: function -> force usage of a specific rolish color
1.317 albertel 7495: scheme
1.648 raeburn 7496: redirect -> see &headtag()
7497: bgcolor -> override the default page bg color
7498: js_ready -> return a string ready for being used in
1.317 albertel 7499: a javascript writeln
1.648 raeburn 7500: html_encode -> return a string ready for being used in
1.320 albertel 7501: a html attribute
1.648 raeburn 7502: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7503: $forcereg arg
1.648 raeburn 7504: frameset -> if true will start with a <frameset>
1.330 albertel 7505: rather than <body>
1.648 raeburn 7506: skip_phases -> hash ref of
1.338 albertel 7507: head -> skip the <html><head> generation
7508: body -> skip all <body> generation
1.648 raeburn 7509: no_auto_mt_title -> prevent &mt()ing the title arg
7510: inherit_jsmath -> when creating popup window in a page,
7511: should it have jsmath forced on by the
7512: current page
1.867 kalberla 7513: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7514: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7515: group -> includes the current group, if page is for a
7516: specific group
1.361 albertel 7517:
1.648 raeburn 7518: =back
1.460 albertel 7519:
1.648 raeburn 7520: =back
1.562 albertel 7521:
1.306 albertel 7522: =cut
7523:
7524: sub start_page {
1.309 albertel 7525: my ($title,$head_extra,$args) = @_;
1.318 albertel 7526: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7527:
1.315 albertel 7528: $env{'internal.start_page'}++;
1.1096 raeburn 7529: my ($result,@advtools);
1.964 droeschl 7530:
1.338 albertel 7531: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7532: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7533: }
7534:
7535: if (! exists($args->{'skip_phases'}{'body'}) ) {
7536: if ($args->{'frameset'}) {
7537: my $attr_string = &make_attr_string($args->{'force_register'},
7538: $args->{'add_entries'});
7539: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7540: } else {
7541: $result .=
7542: &bodytag($title,
7543: $args->{'function'}, $args->{'add_entries'},
7544: $args->{'only_body'}, $args->{'domain'},
7545: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7546: $args->{'bgcolor'}, $args,
7547: \@advtools);
1.831 bisitz 7548: }
1.330 albertel 7549: }
1.338 albertel 7550:
1.315 albertel 7551: if ($args->{'js_ready'}) {
1.713 kaisler 7552: $result = &js_ready($result);
1.315 albertel 7553: }
1.320 albertel 7554: if ($args->{'html_encode'}) {
1.713 kaisler 7555: $result = &html_encode($result);
7556: }
7557:
1.813 bisitz 7558: # Preparation for new and consistent functionlist at top of screen
7559: # if ($args->{'functionlist'}) {
7560: # $result .= &build_functionlist();
7561: #}
7562:
1.964 droeschl 7563: # Don't add anything more if only_body wanted or in const space
7564: return $result if $args->{'only_body'}
7565: || $env{'request.state'} eq 'construct';
1.813 bisitz 7566:
7567: #Breadcrumbs
1.758 kaisler 7568: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7569: &Apache::lonhtmlcommon::clear_breadcrumbs();
7570: #if any br links exists, add them to the breadcrumbs
7571: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7572: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7573: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7574: }
7575: }
1.1096 raeburn 7576: # if @advtools array contains items add then to the breadcrumbs
7577: if (@advtools > 0) {
7578: &Apache::lonmenu::advtools_crumbs(@advtools);
7579: }
1.758 kaisler 7580:
7581: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7582: if(exists($args->{'bread_crumbs_component'})){
7583: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7584: }else{
7585: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7586: }
1.320 albertel 7587: }
1.315 albertel 7588: return $result;
1.306 albertel 7589: }
7590:
7591: sub end_page {
1.315 albertel 7592: my ($args) = @_;
7593: $env{'internal.end_page'}++;
1.330 albertel 7594: my $result;
1.335 albertel 7595: if ($args->{'discussion'}) {
7596: my ($target,$parser);
7597: if (ref($args->{'discussion'})) {
7598: ($target,$parser) =($args->{'discussion'}{'target'},
7599: $args->{'discussion'}{'parser'});
7600: }
7601: $result .= &Apache::lonxml::xmlend($target,$parser);
7602: }
1.330 albertel 7603: if ($args->{'frameset'}) {
7604: $result .= '</frameset>';
7605: } else {
1.635 raeburn 7606: $result .= &endbodytag($args);
1.330 albertel 7607: }
1.1080 raeburn 7608: unless ($args->{'notbody'}) {
7609: $result .= "\n</html>";
7610: }
1.330 albertel 7611:
1.315 albertel 7612: if ($args->{'js_ready'}) {
1.317 albertel 7613: $result = &js_ready($result);
1.315 albertel 7614: }
1.335 albertel 7615:
1.320 albertel 7616: if ($args->{'html_encode'}) {
7617: $result = &html_encode($result);
7618: }
1.335 albertel 7619:
1.315 albertel 7620: return $result;
7621: }
7622:
1.1034 www 7623: sub wishlist_window {
7624: return(<<'ENDWISHLIST');
1.1046 raeburn 7625: <script type="text/javascript">
1.1034 www 7626: // <![CDATA[
7627: // <!-- BEGIN LON-CAPA Internal
7628: function set_wishlistlink(title, path) {
7629: if (!title) {
7630: title = document.title;
7631: title = title.replace(/^LON-CAPA /,'');
7632: }
7633: if (!path) {
7634: path = location.pathname;
7635: }
7636: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7637: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7638: }
7639: // END LON-CAPA Internal -->
7640: // ]]>
7641: </script>
7642: ENDWISHLIST
7643: }
7644:
1.1030 www 7645: sub modal_window {
7646: return(<<'ENDMODAL');
1.1046 raeburn 7647: <script type="text/javascript">
1.1030 www 7648: // <![CDATA[
7649: // <!-- BEGIN LON-CAPA Internal
7650: var modalWindow = {
7651: parent:"body",
7652: windowId:null,
7653: content:null,
7654: width:null,
7655: height:null,
7656: close:function()
7657: {
7658: $(".LCmodal-window").remove();
7659: $(".LCmodal-overlay").remove();
7660: },
7661: open:function()
7662: {
7663: var modal = "";
7664: modal += "<div class=\"LCmodal-overlay\"></div>";
7665: 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;\">";
7666: modal += this.content;
7667: modal += "</div>";
7668:
7669: $(this.parent).append(modal);
7670:
7671: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7672: $(".LCclose-window").click(function(){modalWindow.close();});
7673: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7674: }
7675: };
1.1140 raeburn 7676: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7677: {
7678: modalWindow.windowId = "myModal";
7679: modalWindow.width = width;
7680: modalWindow.height = height;
1.1140 raeburn 7681: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7682: modalWindow.open();
7683: };
7684: // END LON-CAPA Internal -->
7685: // ]]>
7686: </script>
7687: ENDMODAL
7688: }
7689:
7690: sub modal_link {
1.1140 raeburn 7691: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7692: unless ($width) { $width=480; }
7693: unless ($height) { $height=400; }
1.1031 www 7694: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 7695: unless ($transparency) { $transparency='true'; }
7696:
1.1074 raeburn 7697: my $target_attr;
7698: if (defined($target)) {
7699: $target_attr = 'target="'.$target.'"';
7700: }
7701: return <<"ENDLINK";
1.1140 raeburn 7702: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7703: $linktext</a>
7704: ENDLINK
1.1030 www 7705: }
7706:
1.1032 www 7707: sub modal_adhoc_script {
7708: my ($funcname,$width,$height,$content)=@_;
7709: return (<<ENDADHOC);
1.1046 raeburn 7710: <script type="text/javascript">
1.1032 www 7711: // <![CDATA[
7712: var $funcname = function()
7713: {
7714: modalWindow.windowId = "myModal";
7715: modalWindow.width = $width;
7716: modalWindow.height = $height;
7717: modalWindow.content = '$content';
7718: modalWindow.open();
7719: };
7720: // ]]>
7721: </script>
7722: ENDADHOC
7723: }
7724:
1.1041 www 7725: sub modal_adhoc_inner {
7726: my ($funcname,$width,$height,$content)=@_;
7727: my $innerwidth=$width-20;
7728: $content=&js_ready(
1.1140 raeburn 7729: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
7730: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7731: $content.
1.1041 www 7732: &end_scrollbox().
1.1140 raeburn 7733: &end_page()
1.1041 www 7734: );
7735: return &modal_adhoc_script($funcname,$width,$height,$content);
7736: }
7737:
7738: sub modal_adhoc_window {
7739: my ($funcname,$width,$height,$content,$linktext)=@_;
7740: return &modal_adhoc_inner($funcname,$width,$height,$content).
7741: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7742: }
7743:
7744: sub modal_adhoc_launch {
7745: my ($funcname,$width,$height,$content)=@_;
7746: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7747: <script type="text/javascript">
7748: // <![CDATA[
7749: $funcname();
7750: // ]]>
7751: </script>
7752: ENDLAUNCH
7753: }
7754:
7755: sub modal_adhoc_close {
7756: return (<<ENDCLOSE);
7757: <script type="text/javascript">
7758: // <![CDATA[
7759: modalWindow.close();
7760: // ]]>
7761: </script>
7762: ENDCLOSE
7763: }
7764:
1.1038 www 7765: sub togglebox_script {
7766: return(<<ENDTOGGLE);
7767: <script type="text/javascript">
7768: // <![CDATA[
7769: function LCtoggleDisplay(id,hidetext,showtext) {
7770: link = document.getElementById(id + "link").childNodes[0];
7771: with (document.getElementById(id).style) {
7772: if (display == "none" ) {
7773: display = "inline";
7774: link.nodeValue = hidetext;
7775: } else {
7776: display = "none";
7777: link.nodeValue = showtext;
7778: }
7779: }
7780: }
7781: // ]]>
7782: </script>
7783: ENDTOGGLE
7784: }
7785:
1.1039 www 7786: sub start_togglebox {
7787: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7788: unless ($heading) { $heading=''; } else { $heading.=' '; }
7789: unless ($showtext) { $showtext=&mt('show'); }
7790: unless ($hidetext) { $hidetext=&mt('hide'); }
7791: unless ($headerbg) { $headerbg='#FFFFFF'; }
7792: return &start_data_table().
7793: &start_data_table_header_row().
7794: '<td bgcolor="'.$headerbg.'">'.$heading.
7795: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7796: $showtext.'\')">'.$showtext.'</a>]</td>'.
7797: &end_data_table_header_row().
7798: '<tr id="'.$id.'" style="display:none""><td>';
7799: }
7800:
7801: sub end_togglebox {
7802: return '</td></tr>'.&end_data_table();
7803: }
7804:
1.1041 www 7805: sub LCprogressbar_script {
1.1045 www 7806: my ($id)=@_;
1.1041 www 7807: return(<<ENDPROGRESS);
7808: <script type="text/javascript">
7809: // <![CDATA[
1.1045 www 7810: \$('#progressbar$id').progressbar({
1.1041 www 7811: value: 0,
7812: change: function(event, ui) {
7813: var newVal = \$(this).progressbar('option', 'value');
7814: \$('.pblabel', this).text(LCprogressTxt);
7815: }
7816: });
7817: // ]]>
7818: </script>
7819: ENDPROGRESS
7820: }
7821:
7822: sub LCprogressbarUpdate_script {
7823: return(<<ENDPROGRESSUPDATE);
7824: <style type="text/css">
7825: .ui-progressbar { position:relative; }
7826: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7827: </style>
7828: <script type="text/javascript">
7829: // <![CDATA[
1.1045 www 7830: var LCprogressTxt='---';
7831:
7832: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7833: LCprogressTxt=progresstext;
1.1045 www 7834: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7835: }
7836: // ]]>
7837: </script>
7838: ENDPROGRESSUPDATE
7839: }
7840:
1.1042 www 7841: my $LClastpercent;
1.1045 www 7842: my $LCidcnt;
7843: my $LCcurrentid;
1.1042 www 7844:
1.1041 www 7845: sub LCprogressbar {
1.1042 www 7846: my ($r)=(@_);
7847: $LClastpercent=0;
1.1045 www 7848: $LCidcnt++;
7849: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7850: my $starting=&mt('Starting');
7851: my $content=(<<ENDPROGBAR);
1.1045 www 7852: <div id="progressbar$LCcurrentid">
1.1041 www 7853: <span class="pblabel">$starting</span>
7854: </div>
7855: ENDPROGBAR
1.1045 www 7856: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7857: }
7858:
7859: sub LCprogressbarUpdate {
1.1042 www 7860: my ($r,$val,$text)=@_;
7861: unless ($val) {
7862: if ($LClastpercent) {
7863: $val=$LClastpercent;
7864: } else {
7865: $val=0;
7866: }
7867: }
1.1041 www 7868: if ($val<0) { $val=0; }
7869: if ($val>100) { $val=0; }
1.1042 www 7870: $LClastpercent=$val;
1.1041 www 7871: unless ($text) { $text=$val.'%'; }
7872: $text=&js_ready($text);
1.1044 www 7873: &r_print($r,<<ENDUPDATE);
1.1041 www 7874: <script type="text/javascript">
7875: // <![CDATA[
1.1045 www 7876: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7877: // ]]>
7878: </script>
7879: ENDUPDATE
1.1035 www 7880: }
7881:
1.1042 www 7882: sub LCprogressbarClose {
7883: my ($r)=@_;
7884: $LClastpercent=0;
1.1044 www 7885: &r_print($r,<<ENDCLOSE);
1.1042 www 7886: <script type="text/javascript">
7887: // <![CDATA[
1.1045 www 7888: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7889: // ]]>
7890: </script>
7891: ENDCLOSE
1.1044 www 7892: }
7893:
7894: sub r_print {
7895: my ($r,$to_print)=@_;
7896: if ($r) {
7897: $r->print($to_print);
7898: $r->rflush();
7899: } else {
7900: print($to_print);
7901: }
1.1042 www 7902: }
7903:
1.320 albertel 7904: sub html_encode {
7905: my ($result) = @_;
7906:
1.322 albertel 7907: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7908:
7909: return $result;
7910: }
1.1044 www 7911:
1.317 albertel 7912: sub js_ready {
7913: my ($result) = @_;
7914:
1.323 albertel 7915: $result =~ s/[\n\r]/ /xmsg;
7916: $result =~ s/\\/\\\\/xmsg;
7917: $result =~ s/'/\\'/xmsg;
1.372 albertel 7918: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7919:
7920: return $result;
7921: }
7922:
1.315 albertel 7923: sub validate_page {
7924: if ( exists($env{'internal.start_page'})
1.316 albertel 7925: && $env{'internal.start_page'} > 1) {
7926: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7927: $env{'internal.start_page'}.' '.
1.316 albertel 7928: $ENV{'request.filename'});
1.315 albertel 7929: }
7930: if ( exists($env{'internal.end_page'})
1.316 albertel 7931: && $env{'internal.end_page'} > 1) {
7932: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7933: $env{'internal.end_page'}.' '.
1.316 albertel 7934: $env{'request.filename'});
1.315 albertel 7935: }
7936: if ( exists($env{'internal.start_page'})
7937: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7938: &Apache::lonnet::logthis('start_page called without end_page '.
7939: $env{'request.filename'});
1.315 albertel 7940: }
7941: if ( ! exists($env{'internal.start_page'})
7942: && exists($env{'internal.end_page'})) {
1.316 albertel 7943: &Apache::lonnet::logthis('end_page called without start_page'.
7944: $env{'request.filename'});
1.315 albertel 7945: }
1.306 albertel 7946: }
1.315 albertel 7947:
1.996 www 7948:
7949: sub start_scrollbox {
1.1140 raeburn 7950: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7951: unless ($outerwidth) { $outerwidth='520px'; }
7952: unless ($width) { $width='500px'; }
7953: unless ($height) { $height='200px'; }
1.1075 raeburn 7954: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7955: if ($id ne '') {
1.1140 raeburn 7956: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 7957: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7958: }
1.1075 raeburn 7959: if ($bgcolor ne '') {
7960: $tdcol = "background-color: $bgcolor;";
7961: }
1.1137 raeburn 7962: my $nicescroll_js;
7963: if ($env{'browser.mobile'}) {
1.1140 raeburn 7964: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7965: }
7966: return <<"END";
7967: $nicescroll_js
7968:
7969: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
7970: <div style="overflow:auto; width:$width; height:$height;"$div_id>
7971: END
7972: }
7973:
7974: sub end_scrollbox {
7975: return '</div></td></tr></table>';
7976: }
7977:
7978: sub nicescroll_javascript {
7979: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7980: my %options;
7981: if (ref($cursor) eq 'HASH') {
7982: %options = %{$cursor};
7983: }
7984: unless ($options{'railalign'} =~ /^left|right$/) {
7985: $options{'railalign'} = 'left';
7986: }
7987: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7988: my $function = &get_users_function();
7989: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 7990: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 7991: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 7992: }
1.1140 raeburn 7993: }
7994: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7995: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 7996: $options{'cursoropacity'}='1.0';
7997: }
1.1140 raeburn 7998: } else {
7999: $options{'cursoropacity'}='1.0';
8000: }
8001: if ($options{'cursorfixedheight'} eq 'none') {
8002: delete($options{'cursorfixedheight'});
8003: } else {
8004: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8005: }
8006: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8007: delete($options{'railoffset'});
8008: }
8009: my @niceoptions;
8010: while (my($key,$value) = each(%options)) {
8011: if ($value =~ /^\{.+\}$/) {
8012: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8013: } else {
1.1140 raeburn 8014: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8015: }
1.1140 raeburn 8016: }
8017: my $nicescroll_js = '
1.1137 raeburn 8018: $(document).ready(
1.1140 raeburn 8019: function() {
8020: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8021: }
1.1137 raeburn 8022: );
8023: ';
1.1140 raeburn 8024: if ($framecheck) {
8025: $nicescroll_js .= '
8026: function expand_div(caller) {
8027: if (top === self) {
8028: document.getElementById("'.$id.'").style.width = "auto";
8029: document.getElementById("'.$id.'").style.height = "auto";
8030: } else {
8031: try {
8032: if (parent.frames) {
8033: if (parent.frames.length > 1) {
8034: var framesrc = parent.frames[1].location.href;
8035: var currsrc = framesrc.replace(/\#.*$/,"");
8036: if ((caller == "search") || (currsrc == "'.$location.'")) {
8037: document.getElementById("'.$id.'").style.width = "auto";
8038: document.getElementById("'.$id.'").style.height = "auto";
8039: }
8040: }
8041: }
8042: } catch (e) {
8043: return;
8044: }
1.1137 raeburn 8045: }
1.1140 raeburn 8046: return;
1.996 www 8047: }
1.1140 raeburn 8048: ';
8049: }
8050: if ($needjsready) {
8051: $nicescroll_js = '
8052: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8053: } else {
8054: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8055: }
8056: return $nicescroll_js;
1.996 www 8057: }
8058:
1.318 albertel 8059: sub simple_error_page {
1.1150 bisitz 8060: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8061: if (ref($args) eq 'HASH') {
8062: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8063: } else {
8064: $msg = &mt($msg);
8065: }
1.1150 bisitz 8066:
1.318 albertel 8067: my $page =
8068: &Apache::loncommon::start_page($title).
1.1150 bisitz 8069: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8070: &Apache::loncommon::end_page();
8071: if (ref($r)) {
8072: $r->print($page);
1.327 albertel 8073: return;
1.318 albertel 8074: }
8075: return $page;
8076: }
1.347 albertel 8077:
8078: {
1.610 albertel 8079: my @row_count;
1.961 onken 8080:
8081: sub start_data_table_count {
8082: unshift(@row_count, 0);
8083: return;
8084: }
8085:
8086: sub end_data_table_count {
8087: shift(@row_count);
8088: return;
8089: }
8090:
1.347 albertel 8091: sub start_data_table {
1.1018 raeburn 8092: my ($add_class,$id) = @_;
1.422 albertel 8093: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8094: my $table_id;
8095: if (defined($id)) {
8096: $table_id = ' id="'.$id.'"';
8097: }
1.961 onken 8098: &start_data_table_count();
1.1018 raeburn 8099: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8100: }
8101:
8102: sub end_data_table {
1.961 onken 8103: &end_data_table_count();
1.389 albertel 8104: return '</table>'."\n";;
1.347 albertel 8105: }
8106:
8107: sub start_data_table_row {
1.974 wenzelju 8108: my ($add_class, $id) = @_;
1.610 albertel 8109: $row_count[0]++;
8110: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8111: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8112: $id = (' id="'.$id.'"') unless ($id eq '');
8113: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8114: }
1.471 banghart 8115:
8116: sub continue_data_table_row {
1.974 wenzelju 8117: my ($add_class, $id) = @_;
1.610 albertel 8118: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8119: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8120: $id = (' id="'.$id.'"') unless ($id eq '');
8121: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8122: }
1.347 albertel 8123:
8124: sub end_data_table_row {
1.389 albertel 8125: return '</tr>'."\n";;
1.347 albertel 8126: }
1.367 www 8127:
1.421 albertel 8128: sub start_data_table_empty_row {
1.707 bisitz 8129: # $row_count[0]++;
1.421 albertel 8130: return '<tr class="LC_empty_row" >'."\n";;
8131: }
8132:
8133: sub end_data_table_empty_row {
8134: return '</tr>'."\n";;
8135: }
8136:
1.367 www 8137: sub start_data_table_header_row {
1.389 albertel 8138: return '<tr class="LC_header_row">'."\n";;
1.367 www 8139: }
8140:
8141: sub end_data_table_header_row {
1.389 albertel 8142: return '</tr>'."\n";;
1.367 www 8143: }
1.890 droeschl 8144:
8145: sub data_table_caption {
8146: my $caption = shift;
8147: return "<caption class=\"LC_caption\">$caption</caption>";
8148: }
1.347 albertel 8149: }
8150:
1.548 albertel 8151: =pod
8152:
8153: =item * &inhibit_menu_check($arg)
8154:
8155: Checks for a inhibitmenu state and generates output to preserve it
8156:
8157: Inputs: $arg - can be any of
8158: - undef - in which case the return value is a string
8159: to add into arguments list of a uri
8160: - 'input' - in which case the return value is a HTML
8161: <form> <input> field of type hidden to
8162: preserve the value
8163: - a url - in which case the return value is the url with
8164: the neccesary cgi args added to preserve the
8165: inhibitmenu state
8166: - a ref to a url - no return value, but the string is
8167: updated to include the neccessary cgi
8168: args to preserve the inhibitmenu state
8169:
8170: =cut
8171:
8172: sub inhibit_menu_check {
8173: my ($arg) = @_;
8174: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8175: if ($arg eq 'input') {
8176: if ($env{'form.inhibitmenu'}) {
8177: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8178: } else {
8179: return
8180: }
8181: }
8182: if ($env{'form.inhibitmenu'}) {
8183: if (ref($arg)) {
8184: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8185: } elsif ($arg eq '') {
8186: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8187: } else {
8188: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8189: }
8190: }
8191: if (!ref($arg)) {
8192: return $arg;
8193: }
8194: }
8195:
1.251 albertel 8196: ###############################################
1.182 matthew 8197:
8198: =pod
8199:
1.549 albertel 8200: =back
8201:
8202: =head1 User Information Routines
8203:
8204: =over 4
8205:
1.405 albertel 8206: =item * &get_users_function()
1.182 matthew 8207:
8208: Used by &bodytag to determine the current users primary role.
8209: Returns either 'student','coordinator','admin', or 'author'.
8210:
8211: =cut
8212:
8213: ###############################################
8214: sub get_users_function {
1.815 tempelho 8215: my $function = 'norole';
1.818 tempelho 8216: if ($env{'request.role'}=~/^(st)/) {
8217: $function='student';
8218: }
1.907 raeburn 8219: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8220: $function='coordinator';
8221: }
1.258 albertel 8222: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8223: $function='admin';
8224: }
1.826 bisitz 8225: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8226: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8227: $function='author';
8228: }
8229: return $function;
1.54 www 8230: }
1.99 www 8231:
8232: ###############################################
8233:
1.233 raeburn 8234: =pod
8235:
1.821 raeburn 8236: =item * &show_course()
8237:
8238: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8239: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8240:
8241: Inputs:
8242: None
8243:
8244: Outputs:
8245: Scalar: 1 if 'Course' to be used, 0 otherwise.
8246:
8247: =cut
8248:
8249: ###############################################
8250: sub show_course {
8251: my $course = !$env{'user.adv'};
8252: if (!$env{'user.adv'}) {
8253: foreach my $env (keys(%env)) {
8254: next if ($env !~ m/^user\.priv\./);
8255: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8256: $course = 0;
8257: last;
8258: }
8259: }
8260: }
8261: return $course;
8262: }
8263:
8264: ###############################################
8265:
8266: =pod
8267:
1.542 raeburn 8268: =item * &check_user_status()
1.274 raeburn 8269:
8270: Determines current status of supplied role for a
8271: specific user. Roles can be active, previous or future.
8272:
8273: Inputs:
8274: user's domain, user's username, course's domain,
1.375 raeburn 8275: course's number, optional section ID.
1.274 raeburn 8276:
8277: Outputs:
8278: role status: active, previous or future.
8279:
8280: =cut
8281:
8282: sub check_user_status {
1.412 raeburn 8283: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8284: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8285: my @uroles = keys %userinfo;
8286: my $srchstr;
8287: my $active_chk = 'none';
1.412 raeburn 8288: my $now = time;
1.274 raeburn 8289: if (@uroles > 0) {
1.908 raeburn 8290: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8291: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8292: } else {
1.412 raeburn 8293: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8294: }
8295: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8296: my $role_end = 0;
8297: my $role_start = 0;
8298: $active_chk = 'active';
1.412 raeburn 8299: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8300: $role_end = $1;
8301: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8302: $role_start = $1;
1.274 raeburn 8303: }
8304: }
8305: if ($role_start > 0) {
1.412 raeburn 8306: if ($now < $role_start) {
1.274 raeburn 8307: $active_chk = 'future';
8308: }
8309: }
8310: if ($role_end > 0) {
1.412 raeburn 8311: if ($now > $role_end) {
1.274 raeburn 8312: $active_chk = 'previous';
8313: }
8314: }
8315: }
8316: }
8317: return $active_chk;
8318: }
8319:
8320: ###############################################
8321:
8322: =pod
8323:
1.405 albertel 8324: =item * &get_sections()
1.233 raeburn 8325:
8326: Determines all the sections for a course including
8327: sections with students and sections containing other roles.
1.419 raeburn 8328: Incoming parameters:
8329:
8330: 1. domain
8331: 2. course number
8332: 3. reference to array containing roles for which sections should
8333: be gathered (optional).
8334: 4. reference to array containing status types for which sections
8335: should be gathered (optional).
8336:
8337: If the third argument is undefined, sections are gathered for any role.
8338: If the fourth argument is undefined, sections are gathered for any status.
8339: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8340:
1.374 raeburn 8341: Returns section hash (keys are section IDs, values are
8342: number of users in each section), subject to the
1.419 raeburn 8343: optional roles filter, optional status filter
1.233 raeburn 8344:
8345: =cut
8346:
8347: ###############################################
8348: sub get_sections {
1.419 raeburn 8349: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8350: if (!defined($cdom) || !defined($cnum)) {
8351: my $cid = $env{'request.course.id'};
8352:
8353: return if (!defined($cid));
8354:
8355: $cdom = $env{'course.'.$cid.'.domain'};
8356: $cnum = $env{'course.'.$cid.'.num'};
8357: }
8358:
8359: my %sectioncount;
1.419 raeburn 8360: my $now = time;
1.240 albertel 8361:
1.1118 raeburn 8362: my $check_students = 1;
8363: my $only_students = 0;
8364: if (ref($possible_roles) eq 'ARRAY') {
8365: if (grep(/^st$/,@{$possible_roles})) {
8366: if (@{$possible_roles} == 1) {
8367: $only_students = 1;
8368: }
8369: } else {
8370: $check_students = 0;
8371: }
8372: }
8373:
8374: if ($check_students) {
1.276 albertel 8375: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8376: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8377: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8378: my $start_index = &Apache::loncoursedata::CL_START();
8379: my $end_index = &Apache::loncoursedata::CL_END();
8380: my $status;
1.366 albertel 8381: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8382: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8383: $data->[$status_index],
8384: $data->[$start_index],
8385: $data->[$end_index]);
8386: if ($stu_status eq 'Active') {
8387: $status = 'active';
8388: } elsif ($end < $now) {
8389: $status = 'previous';
8390: } elsif ($start > $now) {
8391: $status = 'future';
8392: }
8393: if ($section ne '-1' && $section !~ /^\s*$/) {
8394: if ((!defined($possible_status)) || (($status ne '') &&
8395: (grep/^\Q$status\E$/,@{$possible_status}))) {
8396: $sectioncount{$section}++;
8397: }
1.240 albertel 8398: }
8399: }
8400: }
1.1118 raeburn 8401: if ($only_students) {
8402: return %sectioncount;
8403: }
1.240 albertel 8404: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8405: foreach my $user (sort(keys(%courseroles))) {
8406: if ($user !~ /^(\w{2})/) { next; }
8407: my ($role) = ($user =~ /^(\w{2})/);
8408: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8409: my ($section,$status);
1.240 albertel 8410: if ($role eq 'cr' &&
8411: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8412: $section=$1;
8413: }
8414: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8415: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8416: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8417: if ($end == -1 && $start == -1) {
8418: next; #deleted role
8419: }
8420: if (!defined($possible_status)) {
8421: $sectioncount{$section}++;
8422: } else {
8423: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8424: $status = 'active';
8425: } elsif ($end < $now) {
8426: $status = 'future';
8427: } elsif ($start > $now) {
8428: $status = 'previous';
8429: }
8430: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8431: $sectioncount{$section}++;
8432: }
8433: }
1.233 raeburn 8434: }
1.366 albertel 8435: return %sectioncount;
1.233 raeburn 8436: }
8437:
1.274 raeburn 8438: ###############################################
1.294 raeburn 8439:
8440: =pod
1.405 albertel 8441:
8442: =item * &get_course_users()
8443:
1.275 raeburn 8444: Retrieves usernames:domains for users in the specified course
8445: with specific role(s), and access status.
8446:
8447: Incoming parameters:
1.277 albertel 8448: 1. course domain
8449: 2. course number
8450: 3. access status: users must have - either active,
1.275 raeburn 8451: previous, future, or all.
1.277 albertel 8452: 4. reference to array of permissible roles
1.288 raeburn 8453: 5. reference to array of section restrictions (optional)
8454: 6. reference to results object (hash of hashes).
8455: 7. reference to optional userdata hash
1.609 raeburn 8456: 8. reference to optional statushash
1.630 raeburn 8457: 9. flag if privileged users (except those set to unhide in
8458: course settings) should be excluded
1.609 raeburn 8459: Keys of top level results hash are roles.
1.275 raeburn 8460: Keys of inner hashes are username:domain, with
8461: values set to access type.
1.288 raeburn 8462: Optional userdata hash returns an array with arguments in the
8463: same order as loncoursedata::get_classlist() for student data.
8464:
1.609 raeburn 8465: Optional statushash returns
8466:
1.288 raeburn 8467: Entries for end, start, section and status are blank because
8468: of the possibility of multiple values for non-student roles.
8469:
1.275 raeburn 8470: =cut
1.405 albertel 8471:
1.275 raeburn 8472: ###############################################
1.405 albertel 8473:
1.275 raeburn 8474: sub get_course_users {
1.630 raeburn 8475: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8476: my %idx = ();
1.419 raeburn 8477: my %seclists;
1.288 raeburn 8478:
8479: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8480: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8481: $idx{end} = &Apache::loncoursedata::CL_END();
8482: $idx{start} = &Apache::loncoursedata::CL_START();
8483: $idx{id} = &Apache::loncoursedata::CL_ID();
8484: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8485: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8486: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8487:
1.290 albertel 8488: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8489: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8490: my $now = time;
1.277 albertel 8491: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8492: my $match = 0;
1.412 raeburn 8493: my $secmatch = 0;
1.419 raeburn 8494: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8495: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8496: if ($section eq '') {
8497: $section = 'none';
8498: }
1.291 albertel 8499: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8500: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8501: $secmatch = 1;
8502: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8503: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8504: $secmatch = 1;
8505: }
8506: } else {
1.419 raeburn 8507: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8508: $secmatch = 1;
8509: }
1.290 albertel 8510: }
1.412 raeburn 8511: if (!$secmatch) {
8512: next;
8513: }
1.419 raeburn 8514: }
1.275 raeburn 8515: if (defined($$types{'active'})) {
1.288 raeburn 8516: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8517: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8518: $match = 1;
1.275 raeburn 8519: }
8520: }
8521: if (defined($$types{'previous'})) {
1.609 raeburn 8522: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8523: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8524: $match = 1;
1.275 raeburn 8525: }
8526: }
8527: if (defined($$types{'future'})) {
1.609 raeburn 8528: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8529: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8530: $match = 1;
1.275 raeburn 8531: }
8532: }
1.609 raeburn 8533: if ($match) {
8534: push(@{$seclists{$student}},$section);
8535: if (ref($userdata) eq 'HASH') {
8536: $$userdata{$student} = $$classlist{$student};
8537: }
8538: if (ref($statushash) eq 'HASH') {
8539: $statushash->{$student}{'st'}{$section} = $status;
8540: }
1.288 raeburn 8541: }
1.275 raeburn 8542: }
8543: }
1.412 raeburn 8544: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8545: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8546: my $now = time;
1.609 raeburn 8547: my %displaystatus = ( previous => 'Expired',
8548: active => 'Active',
8549: future => 'Future',
8550: );
1.1121 raeburn 8551: my (%nothide,@possdoms);
1.630 raeburn 8552: if ($hidepriv) {
8553: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8554: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8555: if ($user !~ /:/) {
8556: $nothide{join(':',split(/[\@]/,$user))}=1;
8557: } else {
8558: $nothide{$user} = 1;
8559: }
8560: }
1.1121 raeburn 8561: my @possdoms = ($cdom);
8562: if ($coursehash{'checkforpriv'}) {
8563: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8564: }
1.630 raeburn 8565: }
1.439 raeburn 8566: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8567: my $match = 0;
1.412 raeburn 8568: my $secmatch = 0;
1.439 raeburn 8569: my $status;
1.412 raeburn 8570: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8571: $user =~ s/:$//;
1.439 raeburn 8572: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8573: if ($end == -1 || $start == -1) {
8574: next;
8575: }
8576: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8577: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8578: my ($uname,$udom) = split(/:/,$user);
8579: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8580: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8581: $secmatch = 1;
8582: } elsif ($usec eq '') {
1.420 albertel 8583: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8584: $secmatch = 1;
8585: }
8586: } else {
8587: if (grep(/^\Q$usec\E$/,@{$sections})) {
8588: $secmatch = 1;
8589: }
8590: }
8591: if (!$secmatch) {
8592: next;
8593: }
1.288 raeburn 8594: }
1.419 raeburn 8595: if ($usec eq '') {
8596: $usec = 'none';
8597: }
1.275 raeburn 8598: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8599: if ($hidepriv) {
1.1121 raeburn 8600: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8601: (!$nothide{$uname.':'.$udom})) {
8602: next;
8603: }
8604: }
1.503 raeburn 8605: if ($end > 0 && $end < $now) {
1.439 raeburn 8606: $status = 'previous';
8607: } elsif ($start > $now) {
8608: $status = 'future';
8609: } else {
8610: $status = 'active';
8611: }
1.277 albertel 8612: foreach my $type (keys(%{$types})) {
1.275 raeburn 8613: if ($status eq $type) {
1.420 albertel 8614: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8615: push(@{$$users{$role}{$user}},$type);
8616: }
1.288 raeburn 8617: $match = 1;
8618: }
8619: }
1.419 raeburn 8620: if (($match) && (ref($userdata) eq 'HASH')) {
8621: if (!exists($$userdata{$uname.':'.$udom})) {
8622: &get_user_info($udom,$uname,\%idx,$userdata);
8623: }
1.420 albertel 8624: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8625: push(@{$seclists{$uname.':'.$udom}},$usec);
8626: }
1.609 raeburn 8627: if (ref($statushash) eq 'HASH') {
8628: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8629: }
1.275 raeburn 8630: }
8631: }
8632: }
8633: }
1.290 albertel 8634: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8635: if ((defined($cdom)) && (defined($cnum))) {
8636: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8637: if ( defined($csettings{'internal.courseowner'}) ) {
8638: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8639: next if ($owner eq '');
8640: my ($ownername,$ownerdom);
8641: if ($owner =~ /^([^:]+):([^:]+)$/) {
8642: $ownername = $1;
8643: $ownerdom = $2;
8644: } else {
8645: $ownername = $owner;
8646: $ownerdom = $cdom;
8647: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8648: }
8649: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8650: if (defined($userdata) &&
1.609 raeburn 8651: !exists($$userdata{$owner})) {
8652: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8653: if (!grep(/^none$/,@{$seclists{$owner}})) {
8654: push(@{$seclists{$owner}},'none');
8655: }
8656: if (ref($statushash) eq 'HASH') {
8657: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8658: }
1.290 albertel 8659: }
1.279 raeburn 8660: }
8661: }
8662: }
1.419 raeburn 8663: foreach my $user (keys(%seclists)) {
8664: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8665: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8666: }
1.275 raeburn 8667: }
8668: return;
8669: }
8670:
1.288 raeburn 8671: sub get_user_info {
8672: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8673: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8674: &plainname($uname,$udom,'lastname');
1.291 albertel 8675: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8676: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8677: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8678: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8679: return;
8680: }
1.275 raeburn 8681:
1.472 raeburn 8682: ###############################################
8683:
8684: =pod
8685:
8686: =item * &get_user_quota()
8687:
1.1134 raeburn 8688: Retrieves quota assigned for storage of user files.
8689: Default is to report quota for portfolio files.
1.472 raeburn 8690:
8691: Incoming parameters:
8692: 1. user's username
8693: 2. user's domain
1.1134 raeburn 8694: 3. quota name - portfolio, author, or course
1.1136 raeburn 8695: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 8696: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 8697: course
1.472 raeburn 8698:
8699: Returns:
1.1163 raeburn 8700: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8701: 2. (Optional) Type of setting: custom or default
8702: (individually assigned or default for user's
8703: institutional status).
8704: 3. (Optional) - User's institutional status (e.g., faculty, staff
8705: or student - types as defined in localenroll::inst_usertypes
8706: for user's domain, which determines default quota for user.
8707: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8708:
8709: If a value has been stored in the user's environment,
1.536 raeburn 8710: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8711: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8712:
8713: =cut
8714:
8715: ###############################################
8716:
8717:
8718: sub get_user_quota {
1.1136 raeburn 8719: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8720: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8721: if (!defined($udom)) {
8722: $udom = $env{'user.domain'};
8723: }
8724: if (!defined($uname)) {
8725: $uname = $env{'user.name'};
8726: }
8727: if (($udom eq '' || $uname eq '') ||
8728: ($udom eq 'public') && ($uname eq 'public')) {
8729: $quota = 0;
1.536 raeburn 8730: $quotatype = 'default';
8731: $defquota = 0;
1.472 raeburn 8732: } else {
1.536 raeburn 8733: my $inststatus;
1.1134 raeburn 8734: if ($quotaname eq 'course') {
8735: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8736: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8737: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8738: } else {
8739: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8740: $quota = $cenv{'internal.uploadquota'};
8741: }
1.536 raeburn 8742: } else {
1.1134 raeburn 8743: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8744: if ($quotaname eq 'author') {
8745: $quota = $env{'environment.authorquota'};
8746: } else {
8747: $quota = $env{'environment.portfolioquota'};
8748: }
8749: $inststatus = $env{'environment.inststatus'};
8750: } else {
8751: my %userenv =
8752: &Apache::lonnet::get('environment',['portfolioquota',
8753: 'authorquota','inststatus'],$udom,$uname);
8754: my ($tmp) = keys(%userenv);
8755: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8756: if ($quotaname eq 'author') {
8757: $quota = $userenv{'authorquota'};
8758: } else {
8759: $quota = $userenv{'portfolioquota'};
8760: }
8761: $inststatus = $userenv{'inststatus'};
8762: } else {
8763: undef(%userenv);
8764: }
8765: }
8766: }
8767: if ($quota eq '' || wantarray) {
8768: if ($quotaname eq 'course') {
8769: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 8770: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8771: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 8772: $defquota = $domdefs{$crstype.'quota'};
8773: }
8774: if ($defquota eq '') {
8775: $defquota = 500;
8776: }
1.1134 raeburn 8777: } else {
8778: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8779: }
8780: if ($quota eq '') {
8781: $quota = $defquota;
8782: $quotatype = 'default';
8783: } else {
8784: $quotatype = 'custom';
8785: }
1.472 raeburn 8786: }
8787: }
1.536 raeburn 8788: if (wantarray) {
8789: return ($quota,$quotatype,$settingstatus,$defquota);
8790: } else {
8791: return $quota;
8792: }
1.472 raeburn 8793: }
8794:
8795: ###############################################
8796:
8797: =pod
8798:
8799: =item * &default_quota()
8800:
1.536 raeburn 8801: Retrieves default quota assigned for storage of user portfolio files,
8802: given an (optional) user's institutional status.
1.472 raeburn 8803:
8804: Incoming parameters:
1.1142 raeburn 8805:
1.472 raeburn 8806: 1. domain
1.536 raeburn 8807: 2. (Optional) institutional status(es). This is a : separated list of
8808: status types (e.g., faculty, staff, student etc.)
8809: which apply to the user for whom the default is being retrieved.
8810: If the institutional status string in undefined, the domain
1.1134 raeburn 8811: default quota will be returned.
8812: 3. quota name - portfolio, author, or course
8813: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8814:
8815: Returns:
1.1142 raeburn 8816:
1.1163 raeburn 8817: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8818: 2. (Optional) institutional type which determined the value of the
8819: default quota.
1.472 raeburn 8820:
8821: If a value has been stored in the domain's configuration db,
8822: it will return that, otherwise it returns 20 (for backwards
8823: compatibility with domains which have not set up a configuration
1.1163 raeburn 8824: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8825:
1.536 raeburn 8826: If the user's status includes multiple types (e.g., staff and student),
8827: the largest default quota which applies to the user determines the
8828: default quota returned.
8829:
1.472 raeburn 8830: =cut
8831:
8832: ###############################################
8833:
8834:
8835: sub default_quota {
1.1134 raeburn 8836: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8837: my ($defquota,$settingstatus);
8838: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8839: ['quotas'],$udom);
1.1134 raeburn 8840: my $key = 'defaultquota';
8841: if ($quotaname eq 'author') {
8842: $key = 'authorquota';
8843: }
1.622 raeburn 8844: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8845: if ($inststatus ne '') {
1.765 raeburn 8846: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8847: foreach my $item (@statuses) {
1.1134 raeburn 8848: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8849: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8850: if ($defquota eq '') {
1.1134 raeburn 8851: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8852: $settingstatus = $item;
1.1134 raeburn 8853: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8854: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8855: $settingstatus = $item;
8856: }
8857: }
1.1134 raeburn 8858: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8859: if ($quotahash{'quotas'}{$item} ne '') {
8860: if ($defquota eq '') {
8861: $defquota = $quotahash{'quotas'}{$item};
8862: $settingstatus = $item;
8863: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8864: $defquota = $quotahash{'quotas'}{$item};
8865: $settingstatus = $item;
8866: }
1.536 raeburn 8867: }
8868: }
8869: }
8870: }
8871: if ($defquota eq '') {
1.1134 raeburn 8872: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8873: $defquota = $quotahash{'quotas'}{$key}{'default'};
8874: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8875: $defquota = $quotahash{'quotas'}{'default'};
8876: }
1.536 raeburn 8877: $settingstatus = 'default';
1.1139 raeburn 8878: if ($defquota eq '') {
8879: if ($quotaname eq 'author') {
8880: $defquota = 500;
8881: }
8882: }
1.536 raeburn 8883: }
8884: } else {
8885: $settingstatus = 'default';
1.1134 raeburn 8886: if ($quotaname eq 'author') {
8887: $defquota = 500;
8888: } else {
8889: $defquota = 20;
8890: }
1.536 raeburn 8891: }
8892: if (wantarray) {
8893: return ($defquota,$settingstatus);
1.472 raeburn 8894: } else {
1.536 raeburn 8895: return $defquota;
1.472 raeburn 8896: }
8897: }
8898:
1.1135 raeburn 8899: ###############################################
8900:
8901: =pod
8902:
1.1136 raeburn 8903: =item * &excess_filesize_warning()
1.1135 raeburn 8904:
8905: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8906: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 8907: space to be exceeded.
1.1136 raeburn 8908:
8909: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8910: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8911:
1.1165 raeburn 8912: Inputs: 7
1.1136 raeburn 8913: 1. username or coursenum
1.1135 raeburn 8914: 2. domain
1.1136 raeburn 8915: 3. context ('author' or 'course')
1.1135 raeburn 8916: 4. filename of file for which action is being requested
8917: 5. filesize (kB) of file
8918: 6. action being taken: copy or upload.
1.1165 raeburn 8919: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 8920:
8921: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 8922: otherwise return null.
8923:
8924: =back
1.1135 raeburn 8925:
8926: =cut
8927:
1.1136 raeburn 8928: sub excess_filesize_warning {
1.1165 raeburn 8929: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 8930: my $current_disk_usage = 0;
1.1165 raeburn 8931: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 8932: if ($context eq 'author') {
8933: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8934: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8935: } else {
8936: foreach my $subdir ('docs','supplemental') {
8937: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8938: }
8939: }
1.1135 raeburn 8940: $disk_quota = int($disk_quota * 1000);
8941: if (($current_disk_usage + $filesize) > $disk_quota) {
8942: return '<p><span class="LC_warning">'.
8943: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8944: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8945: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8946: $disk_quota,$current_disk_usage).
8947: '</p>';
8948: }
8949: return;
8950: }
8951:
8952: ###############################################
8953:
8954:
1.1136 raeburn 8955:
8956:
1.384 raeburn 8957: sub get_secgrprole_info {
8958: my ($cdom,$cnum,$needroles,$type) = @_;
8959: my %sections_count = &get_sections($cdom,$cnum);
8960: my @sections = (sort {$a <=> $b} keys(%sections_count));
8961: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8962: my @groups = sort(keys(%curr_groups));
8963: my $allroles = [];
8964: my $rolehash;
8965: my $accesshash = {
8966: active => 'Currently has access',
8967: future => 'Will have future access',
8968: previous => 'Previously had access',
8969: };
8970: if ($needroles) {
8971: $rolehash = {'all' => 'all'};
1.385 albertel 8972: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8973: if (&Apache::lonnet::error(%user_roles)) {
8974: undef(%user_roles);
8975: }
8976: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8977: my ($role)=split(/\:/,$item,2);
8978: if ($role eq 'cr') { next; }
8979: if ($role =~ /^cr/) {
8980: $$rolehash{$role} = (split('/',$role))[3];
8981: } else {
8982: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8983: }
8984: }
8985: foreach my $key (sort(keys(%{$rolehash}))) {
8986: push(@{$allroles},$key);
8987: }
8988: push (@{$allroles},'st');
8989: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8990: }
8991: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8992: }
8993:
1.555 raeburn 8994: sub user_picker {
1.994 raeburn 8995: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8996: my $currdom = $dom;
8997: my %curr_selected = (
8998: srchin => 'dom',
1.580 raeburn 8999: srchby => 'lastname',
1.555 raeburn 9000: );
9001: my $srchterm;
1.625 raeburn 9002: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9003: if ($srch->{'srchby'} ne '') {
9004: $curr_selected{'srchby'} = $srch->{'srchby'};
9005: }
9006: if ($srch->{'srchin'} ne '') {
9007: $curr_selected{'srchin'} = $srch->{'srchin'};
9008: }
9009: if ($srch->{'srchtype'} ne '') {
9010: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9011: }
9012: if ($srch->{'srchdomain'} ne '') {
9013: $currdom = $srch->{'srchdomain'};
9014: }
9015: $srchterm = $srch->{'srchterm'};
9016: }
9017: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9018: 'usr' => 'Search criteria',
1.563 raeburn 9019: 'doma' => 'Domain/institution to search',
1.558 albertel 9020: 'uname' => 'username',
9021: 'lastname' => 'last name',
1.555 raeburn 9022: 'lastfirst' => 'last name, first name',
1.558 albertel 9023: 'crs' => 'in this course',
1.576 raeburn 9024: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9025: 'alc' => 'all LON-CAPA',
1.573 raeburn 9026: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9027: 'exact' => 'is',
9028: 'contains' => 'contains',
1.569 raeburn 9029: 'begins' => 'begins with',
1.571 raeburn 9030: 'youm' => "You must include some text to search for.",
9031: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9032: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9033: 'yomc' => "You must choose a domain when using an institutional directory search.",
9034: 'ymcd' => "You must choose a domain when using a domain search.",
9035: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9036: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9037: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9038: );
1.563 raeburn 9039: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9040: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9041:
9042: my @srchins = ('crs','dom','alc','instd');
9043:
9044: foreach my $option (@srchins) {
9045: # FIXME 'alc' option unavailable until
9046: # loncreateuser::print_user_query_page()
9047: # has been completed.
9048: next if ($option eq 'alc');
1.880 raeburn 9049: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9050: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9051: if ($curr_selected{'srchin'} eq $option) {
9052: $srchinsel .= '
9053: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9054: } else {
9055: $srchinsel .= '
9056: <option value="'.$option.'">'.$lt{$option}.'</option>';
9057: }
1.555 raeburn 9058: }
1.563 raeburn 9059: $srchinsel .= "\n </select>\n";
1.555 raeburn 9060:
9061: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9062: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9063: if ($curr_selected{'srchby'} eq $option) {
9064: $srchbysel .= '
9065: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9066: } else {
9067: $srchbysel .= '
9068: <option value="'.$option.'">'.$lt{$option}.'</option>';
9069: }
9070: }
9071: $srchbysel .= "\n </select>\n";
9072:
9073: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9074: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9075: if ($curr_selected{'srchtype'} eq $option) {
9076: $srchtypesel .= '
9077: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9078: } else {
9079: $srchtypesel .= '
9080: <option value="'.$option.'">'.$lt{$option}.'</option>';
9081: }
9082: }
9083: $srchtypesel .= "\n </select>\n";
9084:
1.558 albertel 9085: my ($newuserscript,$new_user_create);
1.994 raeburn 9086: my $context_dom = $env{'request.role.domain'};
9087: if ($context eq 'requestcrs') {
9088: if ($env{'form.coursedom'} ne '') {
9089: $context_dom = $env{'form.coursedom'};
9090: }
9091: }
1.556 raeburn 9092: if ($forcenewuser) {
1.576 raeburn 9093: if (ref($srch) eq 'HASH') {
1.994 raeburn 9094: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9095: if ($cancreate) {
9096: $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>';
9097: } else {
1.799 bisitz 9098: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9099: my %usertypetext = (
9100: official => 'institutional',
9101: unofficial => 'non-institutional',
9102: );
1.799 bisitz 9103: $new_user_create = '<p class="LC_warning">'
9104: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9105: .' '
9106: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9107: ,'<a href="'.$helplink.'">','</a>')
9108: .'</p><br />';
1.627 raeburn 9109: }
1.576 raeburn 9110: }
9111: }
9112:
1.556 raeburn 9113: $newuserscript = <<"ENDSCRIPT";
9114:
1.570 raeburn 9115: function setSearch(createnew,callingForm) {
1.556 raeburn 9116: if (createnew == 1) {
1.570 raeburn 9117: for (var i=0; i<callingForm.srchby.length; i++) {
9118: if (callingForm.srchby.options[i].value == 'uname') {
9119: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9120: }
9121: }
1.570 raeburn 9122: for (var i=0; i<callingForm.srchin.length; i++) {
9123: if ( callingForm.srchin.options[i].value == 'dom') {
9124: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9125: }
9126: }
1.570 raeburn 9127: for (var i=0; i<callingForm.srchtype.length; i++) {
9128: if (callingForm.srchtype.options[i].value == 'exact') {
9129: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9130: }
9131: }
1.570 raeburn 9132: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9133: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9134: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9135: }
9136: }
9137: }
9138: }
9139: ENDSCRIPT
1.558 albertel 9140:
1.556 raeburn 9141: }
9142:
1.555 raeburn 9143: my $output = <<"END_BLOCK";
1.556 raeburn 9144: <script type="text/javascript">
1.824 bisitz 9145: // <![CDATA[
1.570 raeburn 9146: function validateEntry(callingForm) {
1.558 albertel 9147:
1.556 raeburn 9148: var checkok = 1;
1.558 albertel 9149: var srchin;
1.570 raeburn 9150: for (var i=0; i<callingForm.srchin.length; i++) {
9151: if ( callingForm.srchin[i].checked ) {
9152: srchin = callingForm.srchin[i].value;
1.558 albertel 9153: }
9154: }
9155:
1.570 raeburn 9156: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9157: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9158: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9159: var srchterm = callingForm.srchterm.value;
9160: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9161: var msg = "";
9162:
9163: if (srchterm == "") {
9164: checkok = 0;
1.571 raeburn 9165: msg += "$lt{'youm'}\\n";
1.556 raeburn 9166: }
9167:
1.569 raeburn 9168: if (srchtype== 'begins') {
9169: if (srchterm.length < 2) {
9170: checkok = 0;
1.571 raeburn 9171: msg += "$lt{'thte'}\\n";
1.569 raeburn 9172: }
9173: }
9174:
1.556 raeburn 9175: if (srchtype== 'contains') {
9176: if (srchterm.length < 3) {
9177: checkok = 0;
1.571 raeburn 9178: msg += "$lt{'thet'}\\n";
1.556 raeburn 9179: }
9180: }
9181: if (srchin == 'instd') {
9182: if (srchdomain == '') {
9183: checkok = 0;
1.571 raeburn 9184: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9185: }
9186: }
9187: if (srchin == 'dom') {
9188: if (srchdomain == '') {
9189: checkok = 0;
1.571 raeburn 9190: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9191: }
9192: }
9193: if (srchby == 'lastfirst') {
9194: if (srchterm.indexOf(",") == -1) {
9195: checkok = 0;
1.571 raeburn 9196: msg += "$lt{'whus'}\\n";
1.556 raeburn 9197: }
9198: if (srchterm.indexOf(",") == srchterm.length -1) {
9199: checkok = 0;
1.571 raeburn 9200: msg += "$lt{'whse'}\\n";
1.556 raeburn 9201: }
9202: }
9203: if (checkok == 0) {
1.571 raeburn 9204: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9205: return;
9206: }
9207: if (checkok == 1) {
1.570 raeburn 9208: callingForm.submit();
1.556 raeburn 9209: }
9210: }
9211:
9212: $newuserscript
9213:
1.824 bisitz 9214: // ]]>
1.556 raeburn 9215: </script>
1.558 albertel 9216:
9217: $new_user_create
9218:
1.555 raeburn 9219: END_BLOCK
1.558 albertel 9220:
1.876 raeburn 9221: $output .= &Apache::lonhtmlcommon::start_pick_box().
9222: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9223: $domform.
9224: &Apache::lonhtmlcommon::row_closure().
9225: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9226: $srchbysel.
9227: $srchtypesel.
9228: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9229: $srchinsel.
9230: &Apache::lonhtmlcommon::row_closure(1).
9231: &Apache::lonhtmlcommon::end_pick_box().
9232: '<br />';
1.555 raeburn 9233: return $output;
9234: }
9235:
1.612 raeburn 9236: sub user_rule_check {
1.615 raeburn 9237: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9238: my $response;
9239: if (ref($usershash) eq 'HASH') {
9240: foreach my $user (keys(%{$usershash})) {
9241: my ($uname,$udom) = split(/:/,$user);
9242: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9243: my ($id,$newuser);
1.612 raeburn 9244: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9245: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9246: $id = $usershash->{$user}->{'id'};
9247: }
9248: my $inst_response;
9249: if (ref($checks) eq 'HASH') {
9250: if (defined($checks->{'username'})) {
1.615 raeburn 9251: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9252: &Apache::lonnet::get_instuser($udom,$uname);
9253: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9254: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9255: &Apache::lonnet::get_instuser($udom,undef,$id);
9256: }
1.615 raeburn 9257: } else {
9258: ($inst_response,%{$inst_results->{$user}}) =
9259: &Apache::lonnet::get_instuser($udom,$uname);
9260: return;
1.612 raeburn 9261: }
1.615 raeburn 9262: if (!$got_rules->{$udom}) {
1.612 raeburn 9263: my %domconfig = &Apache::lonnet::get_dom('configuration',
9264: ['usercreation'],$udom);
9265: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9266: foreach my $item ('username','id') {
1.612 raeburn 9267: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9268: $$curr_rules{$udom}{$item} =
9269: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9270: }
9271: }
9272: }
1.615 raeburn 9273: $got_rules->{$udom} = 1;
1.585 raeburn 9274: }
1.612 raeburn 9275: foreach my $item (keys(%{$checks})) {
9276: if (ref($$curr_rules{$udom}) eq 'HASH') {
9277: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9278: if (@{$$curr_rules{$udom}{$item}} > 0) {
9279: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9280: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9281: if ($rule_check{$rule}) {
9282: $$rulematch{$user}{$item} = $rule;
9283: if ($inst_response eq 'ok') {
1.615 raeburn 9284: if (ref($inst_results) eq 'HASH') {
9285: if (ref($inst_results->{$user}) eq 'HASH') {
9286: if (keys(%{$inst_results->{$user}}) == 0) {
9287: $$alerts{$item}{$udom}{$uname} = 1;
9288: }
1.612 raeburn 9289: }
9290: }
1.615 raeburn 9291: }
9292: last;
1.585 raeburn 9293: }
9294: }
9295: }
9296: }
9297: }
9298: }
9299: }
9300: }
1.612 raeburn 9301: return;
9302: }
9303:
9304: sub user_rule_formats {
9305: my ($domain,$domdesc,$curr_rules,$check) = @_;
9306: my %text = (
9307: 'username' => 'Usernames',
9308: 'id' => 'IDs',
9309: );
9310: my $output;
9311: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9312: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9313: if (@{$ruleorder} > 0) {
1.1102 raeburn 9314: $output = '<br />'.
9315: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9316: '<span class="LC_cusr_emph">','</span>',$domdesc).
9317: ' <ul>';
1.612 raeburn 9318: foreach my $rule (@{$ruleorder}) {
9319: if (ref($curr_rules) eq 'ARRAY') {
9320: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9321: if (ref($rules->{$rule}) eq 'HASH') {
9322: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9323: $rules->{$rule}{'desc'}.'</li>';
9324: }
9325: }
9326: }
9327: }
9328: $output .= '</ul>';
9329: }
9330: }
9331: return $output;
9332: }
9333:
9334: sub instrule_disallow_msg {
1.615 raeburn 9335: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9336: my $response;
9337: my %text = (
9338: item => 'username',
9339: items => 'usernames',
9340: match => 'matches',
9341: do => 'does',
9342: action => 'a username',
9343: one => 'one',
9344: );
9345: if ($count > 1) {
9346: $text{'item'} = 'usernames';
9347: $text{'match'} ='match';
9348: $text{'do'} = 'do';
9349: $text{'action'} = 'usernames',
9350: $text{'one'} = 'ones';
9351: }
9352: if ($checkitem eq 'id') {
9353: $text{'items'} = 'IDs';
9354: $text{'item'} = 'ID';
9355: $text{'action'} = 'an ID';
1.615 raeburn 9356: if ($count > 1) {
9357: $text{'item'} = 'IDs';
9358: $text{'action'} = 'IDs';
9359: }
1.612 raeburn 9360: }
1.674 bisitz 9361: $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 9362: if ($mode eq 'upload') {
9363: if ($checkitem eq 'username') {
9364: $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'}.");
9365: } elsif ($checkitem eq 'id') {
1.674 bisitz 9366: $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 9367: }
1.669 raeburn 9368: } elsif ($mode eq 'selfcreate') {
9369: if ($checkitem eq 'id') {
9370: $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.");
9371: }
1.615 raeburn 9372: } else {
9373: if ($checkitem eq 'username') {
9374: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9375: } elsif ($checkitem eq 'id') {
9376: $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.");
9377: }
1.612 raeburn 9378: }
9379: return $response;
1.585 raeburn 9380: }
9381:
1.624 raeburn 9382: sub personal_data_fieldtitles {
9383: my %fieldtitles = &Apache::lonlocal::texthash (
9384: id => 'Student/Employee ID',
9385: permanentemail => 'E-mail address',
9386: lastname => 'Last Name',
9387: firstname => 'First Name',
9388: middlename => 'Middle Name',
9389: generation => 'Generation',
9390: gen => 'Generation',
1.765 raeburn 9391: inststatus => 'Affiliation',
1.624 raeburn 9392: );
9393: return %fieldtitles;
9394: }
9395:
1.642 raeburn 9396: sub sorted_inst_types {
9397: my ($dom) = @_;
9398: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9399: my $othertitle = &mt('All users');
9400: if ($env{'request.course.id'}) {
1.668 raeburn 9401: $othertitle = &mt('Any users');
1.642 raeburn 9402: }
9403: my @types;
9404: if (ref($order) eq 'ARRAY') {
9405: @types = @{$order};
9406: }
9407: if (@types == 0) {
9408: if (ref($usertypes) eq 'HASH') {
9409: @types = sort(keys(%{$usertypes}));
9410: }
9411: }
9412: if (keys(%{$usertypes}) > 0) {
9413: $othertitle = &mt('Other users');
9414: }
9415: return ($othertitle,$usertypes,\@types);
9416: }
9417:
1.645 raeburn 9418: sub get_institutional_codes {
9419: my ($settings,$allcourses,$LC_code) = @_;
9420: # Get complete list of course sections to update
9421: my @currsections = ();
9422: my @currxlists = ();
9423: my $coursecode = $$settings{'internal.coursecode'};
9424:
9425: if ($$settings{'internal.sectionnums'} ne '') {
9426: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9427: }
9428:
9429: if ($$settings{'internal.crosslistings'} ne '') {
9430: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9431: }
9432:
9433: if (@currxlists > 0) {
9434: foreach (@currxlists) {
9435: if (m/^([^:]+):(\w*)$/) {
9436: unless (grep/^$1$/,@{$allcourses}) {
9437: push @{$allcourses},$1;
9438: $$LC_code{$1} = $2;
9439: }
9440: }
9441: }
9442: }
9443:
9444: if (@currsections > 0) {
9445: foreach (@currsections) {
9446: if (m/^(\w+):(\w*)$/) {
9447: my $sec = $coursecode.$1;
9448: my $lc_sec = $2;
9449: unless (grep/^$sec$/,@{$allcourses}) {
9450: push @{$allcourses},$sec;
9451: $$LC_code{$sec} = $lc_sec;
9452: }
9453: }
9454: }
9455: }
9456: return;
9457: }
9458:
1.971 raeburn 9459: sub get_standard_codeitems {
9460: return ('Year','Semester','Department','Number','Section');
9461: }
9462:
1.112 bowersj2 9463: =pod
9464:
1.780 raeburn 9465: =head1 Slot Helpers
9466:
9467: =over 4
9468:
9469: =item * sorted_slots()
9470:
1.1040 raeburn 9471: Sorts an array of slot names in order of an optional sort key,
9472: default sort is by slot start time (earliest first).
1.780 raeburn 9473:
9474: Inputs:
9475:
9476: =over 4
9477:
9478: slotsarr - Reference to array of unsorted slot names.
9479:
9480: slots - Reference to hash of hash, where outer hash keys are slot names.
9481:
1.1040 raeburn 9482: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9483:
1.549 albertel 9484: =back
9485:
1.780 raeburn 9486: Returns:
9487:
9488: =over 4
9489:
1.1040 raeburn 9490: sorted - An array of slot names sorted by a specified sort key
9491: (default sort key is start time of the slot).
1.780 raeburn 9492:
9493: =back
9494:
9495: =cut
9496:
9497:
9498: sub sorted_slots {
1.1040 raeburn 9499: my ($slotsarr,$slots,$sortkey) = @_;
9500: if ($sortkey eq '') {
9501: $sortkey = 'starttime';
9502: }
1.780 raeburn 9503: my @sorted;
9504: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9505: @sorted =
9506: sort {
9507: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9508: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9509: }
9510: if (ref($slots->{$a})) { return -1;}
9511: if (ref($slots->{$b})) { return 1;}
9512: return 0;
9513: } @{$slotsarr};
9514: }
9515: return @sorted;
9516: }
9517:
1.1040 raeburn 9518: =pod
9519:
9520: =item * get_future_slots()
9521:
9522: Inputs:
9523:
9524: =over 4
9525:
9526: cnum - course number
9527:
9528: cdom - course domain
9529:
9530: now - current UNIX time
9531:
9532: symb - optional symb
9533:
9534: =back
9535:
9536: Returns:
9537:
9538: =over 4
9539:
9540: sorted_reservable - ref to array of student_schedulable slots currently
9541: reservable, ordered by end date of reservation period.
9542:
9543: reservable_now - ref to hash of student_schedulable slots currently
9544: reservable.
9545:
9546: Keys in inner hash are:
9547: (a) symb: either blank or symb to which slot use is restricted.
9548: (b) endreserve: end date of reservation period.
9549:
9550: sorted_future - ref to array of student_schedulable slots reservable in
9551: the future, ordered by start date of reservation period.
9552:
9553: future_reservable - ref to hash of student_schedulable slots reservable
9554: in the future.
9555:
9556: Keys in inner hash are:
9557: (a) symb: either blank or symb to which slot use is restricted.
9558: (b) startreserve: start date of reservation period.
9559:
9560: =back
9561:
9562: =cut
9563:
9564: sub get_future_slots {
9565: my ($cnum,$cdom,$now,$symb) = @_;
9566: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9567: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9568: foreach my $slot (keys(%slots)) {
9569: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9570: if ($symb) {
9571: next if (($slots{$slot}->{'symb'} ne '') &&
9572: ($slots{$slot}->{'symb'} ne $symb));
9573: }
9574: if (($slots{$slot}->{'starttime'} > $now) &&
9575: ($slots{$slot}->{'endtime'} > $now)) {
9576: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9577: my $userallowed = 0;
9578: if ($slots{$slot}->{'allowedsections'}) {
9579: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9580: if (!defined($env{'request.role.sec'})
9581: && grep(/^No section assigned$/,@allowed_sec)) {
9582: $userallowed=1;
9583: } else {
9584: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9585: $userallowed=1;
9586: }
9587: }
9588: unless ($userallowed) {
9589: if (defined($env{'request.course.groups'})) {
9590: my @groups = split(/:/,$env{'request.course.groups'});
9591: foreach my $group (@groups) {
9592: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9593: $userallowed=1;
9594: last;
9595: }
9596: }
9597: }
9598: }
9599: }
9600: if ($slots{$slot}->{'allowedusers'}) {
9601: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9602: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9603: if (grep(/^\Q$user\E$/,@allowed_users)) {
9604: $userallowed = 1;
9605: }
9606: }
9607: next unless($userallowed);
9608: }
9609: my $startreserve = $slots{$slot}->{'startreserve'};
9610: my $endreserve = $slots{$slot}->{'endreserve'};
9611: my $symb = $slots{$slot}->{'symb'};
9612: if (($startreserve < $now) &&
9613: (!$endreserve || $endreserve > $now)) {
9614: my $lastres = $endreserve;
9615: if (!$lastres) {
9616: $lastres = $slots{$slot}->{'starttime'};
9617: }
9618: $reservable_now{$slot} = {
9619: symb => $symb,
9620: endreserve => $lastres
9621: };
9622: } elsif (($startreserve > $now) &&
9623: (!$endreserve || $endreserve > $startreserve)) {
9624: $future_reservable{$slot} = {
9625: symb => $symb,
9626: startreserve => $startreserve
9627: };
9628: }
9629: }
9630: }
9631: my @unsorted_reservable = keys(%reservable_now);
9632: if (@unsorted_reservable > 0) {
9633: @sorted_reservable =
9634: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9635: }
9636: my @unsorted_future = keys(%future_reservable);
9637: if (@unsorted_future > 0) {
9638: @sorted_future =
9639: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9640: }
9641: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9642: }
1.780 raeburn 9643:
9644: =pod
9645:
1.1057 foxr 9646: =back
9647:
1.549 albertel 9648: =head1 HTTP Helpers
9649:
9650: =over 4
9651:
1.648 raeburn 9652: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9653:
1.258 albertel 9654: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9655: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9656: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9657:
9658: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9659: $possible_names is an ref to an array of form element names. As an example:
9660: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9661: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9662:
9663: =cut
1.1 albertel 9664:
1.6 albertel 9665: sub get_unprocessed_cgi {
1.25 albertel 9666: my ($query,$possible_names)= @_;
1.26 matthew 9667: # $Apache::lonxml::debug=1;
1.356 albertel 9668: foreach my $pair (split(/&/,$query)) {
9669: my ($name, $value) = split(/=/,$pair);
1.369 www 9670: $name = &unescape($name);
1.25 albertel 9671: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9672: $value =~ tr/+/ /;
9673: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9674: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9675: }
1.16 harris41 9676: }
1.6 albertel 9677: }
9678:
1.112 bowersj2 9679: =pod
9680:
1.648 raeburn 9681: =item * &cacheheader()
1.112 bowersj2 9682:
9683: returns cache-controlling header code
9684:
9685: =cut
9686:
1.7 albertel 9687: sub cacheheader {
1.258 albertel 9688: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9689: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9690: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9691: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9692: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9693: return $output;
1.7 albertel 9694: }
9695:
1.112 bowersj2 9696: =pod
9697:
1.648 raeburn 9698: =item * &no_cache($r)
1.112 bowersj2 9699:
9700: specifies header code to not have cache
9701:
9702: =cut
9703:
1.9 albertel 9704: sub no_cache {
1.216 albertel 9705: my ($r) = @_;
9706: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9707: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9708: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9709: $r->no_cache(1);
9710: $r->header_out("Expires" => $date);
9711: $r->header_out("Pragma" => "no-cache");
1.123 www 9712: }
9713:
9714: sub content_type {
1.181 albertel 9715: my ($r,$type,$charset) = @_;
1.299 foxr 9716: if ($r) {
9717: # Note that printout.pl calls this with undef for $r.
9718: &no_cache($r);
9719: }
1.258 albertel 9720: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9721: unless ($charset) {
9722: $charset=&Apache::lonlocal::current_encoding;
9723: }
9724: if ($charset) { $type.='; charset='.$charset; }
9725: if ($r) {
9726: $r->content_type($type);
9727: } else {
9728: print("Content-type: $type\n\n");
9729: }
1.9 albertel 9730: }
1.25 albertel 9731:
1.112 bowersj2 9732: =pod
9733:
1.648 raeburn 9734: =item * &add_to_env($name,$value)
1.112 bowersj2 9735:
1.258 albertel 9736: adds $name to the %env hash with value
1.112 bowersj2 9737: $value, if $name already exists, the entry is converted to an array
9738: reference and $value is added to the array.
9739:
9740: =cut
9741:
1.25 albertel 9742: sub add_to_env {
9743: my ($name,$value)=@_;
1.258 albertel 9744: if (defined($env{$name})) {
9745: if (ref($env{$name})) {
1.25 albertel 9746: #already have multiple values
1.258 albertel 9747: push(@{ $env{$name} },$value);
1.25 albertel 9748: } else {
9749: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9750: my $first=$env{$name};
9751: undef($env{$name});
9752: push(@{ $env{$name} },$first,$value);
1.25 albertel 9753: }
9754: } else {
1.258 albertel 9755: $env{$name}=$value;
1.25 albertel 9756: }
1.31 albertel 9757: }
1.149 albertel 9758:
9759: =pod
9760:
1.648 raeburn 9761: =item * &get_env_multiple($name)
1.149 albertel 9762:
1.258 albertel 9763: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9764: values may be defined and end up as an array ref.
9765:
9766: returns an array of values
9767:
9768: =cut
9769:
9770: sub get_env_multiple {
9771: my ($name) = @_;
9772: my @values;
1.258 albertel 9773: if (defined($env{$name})) {
1.149 albertel 9774: # exists is it an array
1.258 albertel 9775: if (ref($env{$name})) {
9776: @values=@{ $env{$name} };
1.149 albertel 9777: } else {
1.258 albertel 9778: $values[0]=$env{$name};
1.149 albertel 9779: }
9780: }
9781: return(@values);
9782: }
9783:
1.660 raeburn 9784: sub ask_for_embedded_content {
9785: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9786: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9787: %currsubfile,%unused,$rem);
1.1071 raeburn 9788: my $counter = 0;
9789: my $numnew = 0;
1.987 raeburn 9790: my $numremref = 0;
9791: my $numinvalid = 0;
9792: my $numpathchg = 0;
9793: my $numexisting = 0;
1.1071 raeburn 9794: my $numunused = 0;
9795: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 9796: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9797: my $heading = &mt('Upload embedded files');
9798: my $buttontext = &mt('Upload');
9799:
1.1085 raeburn 9800: if ($env{'request.course.id'}) {
1.1123 raeburn 9801: if ($actionurl eq '/adm/dependencies') {
9802: $navmap = Apache::lonnavmaps::navmap->new();
9803: }
9804: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9805: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9806: }
1.1123 raeburn 9807: if (($actionurl eq '/adm/portfolio') ||
9808: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9809: my $current_path='/';
9810: if ($env{'form.currentpath'}) {
9811: $current_path = $env{'form.currentpath'};
9812: }
9813: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9814: $udom = $cdom;
9815: $uname = $cnum;
1.984 raeburn 9816: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9817: } else {
9818: $udom = $env{'user.domain'};
9819: $uname = $env{'user.name'};
9820: $url = '/userfiles/portfolio';
9821: }
1.987 raeburn 9822: $toplevel = $url.'/';
1.984 raeburn 9823: $url .= $current_path;
9824: $getpropath = 1;
1.987 raeburn 9825: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9826: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9827: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9828: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9829: $toplevel = $url;
1.984 raeburn 9830: if ($rest ne '') {
1.987 raeburn 9831: $url .= $rest;
9832: }
9833: } elsif ($actionurl eq '/adm/coursedocs') {
9834: if (ref($args) eq 'HASH') {
1.1071 raeburn 9835: $url = $args->{'docs_url'};
9836: $toplevel = $url;
1.1084 raeburn 9837: if ($args->{'context'} eq 'paste') {
9838: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9839: ($path) =
9840: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9841: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9842: $fileloc =~ s{^/}{};
9843: }
1.1071 raeburn 9844: }
1.1084 raeburn 9845: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9846: if ($env{'request.course.id'} ne '') {
9847: if (ref($args) eq 'HASH') {
9848: $url = $args->{'docs_url'};
9849: $title = $args->{'docs_title'};
1.1126 raeburn 9850: $toplevel = $url;
9851: unless ($toplevel =~ m{^/}) {
9852: $toplevel = "/$url";
9853: }
1.1085 raeburn 9854: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9855: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9856: $path = $1;
9857: } else {
9858: ($path) =
9859: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9860: }
1.1071 raeburn 9861: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9862: $fileloc =~ s{^/}{};
9863: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9864: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9865: }
1.987 raeburn 9866: }
1.1123 raeburn 9867: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9868: $udom = $cdom;
9869: $uname = $cnum;
9870: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9871: $toplevel = $url;
9872: $path = $url;
9873: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9874: $fileloc =~ s{^/}{};
1.987 raeburn 9875: }
1.1126 raeburn 9876: foreach my $file (keys(%{$allfiles})) {
9877: my $embed_file;
9878: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9879: $embed_file = $1;
9880: } else {
9881: $embed_file = $file;
9882: }
1.1158 raeburn 9883: my ($absolutepath,$cleaned_file);
9884: if ($embed_file =~ m{^\w+://}) {
9885: $cleaned_file = $embed_file;
1.1147 raeburn 9886: $newfiles{$cleaned_file} = 1;
9887: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9888: } else {
1.1158 raeburn 9889: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9890: if ($embed_file =~ m{^/}) {
9891: $absolutepath = $embed_file;
9892: }
1.1147 raeburn 9893: if ($cleaned_file =~ m{/}) {
9894: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9895: $path = &check_for_traversal($path,$url,$toplevel);
9896: my $item = $fname;
9897: if ($path ne '') {
9898: $item = $path.'/'.$fname;
9899: $subdependencies{$path}{$fname} = 1;
9900: } else {
9901: $dependencies{$item} = 1;
9902: }
9903: if ($absolutepath) {
9904: $mapping{$item} = $absolutepath;
9905: } else {
9906: $mapping{$item} = $embed_file;
9907: }
9908: } else {
9909: $dependencies{$embed_file} = 1;
9910: if ($absolutepath) {
1.1147 raeburn 9911: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9912: } else {
1.1147 raeburn 9913: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9914: }
9915: }
1.984 raeburn 9916: }
9917: }
1.1071 raeburn 9918: my $dirptr = 16384;
1.984 raeburn 9919: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9920: $currsubfile{$path} = {};
1.1123 raeburn 9921: if (($actionurl eq '/adm/portfolio') ||
9922: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9923: my ($sublistref,$listerror) =
9924: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9925: if (ref($sublistref) eq 'ARRAY') {
9926: foreach my $line (@{$sublistref}) {
9927: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9928: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9929: }
1.984 raeburn 9930: }
1.987 raeburn 9931: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9932: if (opendir(my $dir,$url.'/'.$path)) {
9933: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9934: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9935: }
1.1084 raeburn 9936: } elsif (($actionurl eq '/adm/dependencies') ||
9937: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9938: ($args->{'context'} eq 'paste')) ||
9939: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9940: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9941: my $dir;
9942: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9943: $dir = $fileloc;
9944: } else {
9945: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9946: }
1.1071 raeburn 9947: if ($dir ne '') {
9948: my ($sublistref,$listerror) =
9949: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9950: if (ref($sublistref) eq 'ARRAY') {
9951: foreach my $line (@{$sublistref}) {
9952: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9953: undef,$mtime)=split(/\&/,$line,12);
9954: unless (($testdir&$dirptr) ||
9955: ($file_name =~ /^\.\.?$/)) {
9956: $currsubfile{$path}{$file_name} = [$size,$mtime];
9957: }
9958: }
9959: }
9960: }
1.984 raeburn 9961: }
9962: }
9963: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9964: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9965: my $item = $path.'/'.$file;
9966: unless ($mapping{$item} eq $item) {
9967: $pathchanges{$item} = 1;
9968: }
9969: $existing{$item} = 1;
9970: $numexisting ++;
9971: } else {
9972: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9973: }
9974: }
1.1071 raeburn 9975: if ($actionurl eq '/adm/dependencies') {
9976: foreach my $path (keys(%currsubfile)) {
9977: if (ref($currsubfile{$path}) eq 'HASH') {
9978: foreach my $file (keys(%{$currsubfile{$path}})) {
9979: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9980: next if (($rem ne '') &&
9981: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9982: (ref($navmap) &&
9983: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9984: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9985: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9986: $unused{$path.'/'.$file} = 1;
9987: }
9988: }
9989: }
9990: }
9991: }
1.984 raeburn 9992: }
1.987 raeburn 9993: my %currfile;
1.1123 raeburn 9994: if (($actionurl eq '/adm/portfolio') ||
9995: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9996: my ($dirlistref,$listerror) =
9997: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9998: if (ref($dirlistref) eq 'ARRAY') {
9999: foreach my $line (@{$dirlistref}) {
10000: my ($file_name,$rest) = split(/\&/,$line,2);
10001: $currfile{$file_name} = 1;
10002: }
1.984 raeburn 10003: }
1.987 raeburn 10004: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10005: if (opendir(my $dir,$url)) {
1.987 raeburn 10006: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10007: map {$currfile{$_} = 1;} @dir_list;
10008: }
1.1084 raeburn 10009: } elsif (($actionurl eq '/adm/dependencies') ||
10010: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10011: ($args->{'context'} eq 'paste')) ||
10012: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10013: if ($env{'request.course.id'} ne '') {
10014: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10015: if ($dir ne '') {
10016: my ($dirlistref,$listerror) =
10017: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10018: if (ref($dirlistref) eq 'ARRAY') {
10019: foreach my $line (@{$dirlistref}) {
10020: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10021: $size,undef,$mtime)=split(/\&/,$line,12);
10022: unless (($testdir&$dirptr) ||
10023: ($file_name =~ /^\.\.?$/)) {
10024: $currfile{$file_name} = [$size,$mtime];
10025: }
10026: }
10027: }
10028: }
10029: }
1.984 raeburn 10030: }
10031: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10032: if (exists($currfile{$file})) {
1.987 raeburn 10033: unless ($mapping{$file} eq $file) {
10034: $pathchanges{$file} = 1;
10035: }
10036: $existing{$file} = 1;
10037: $numexisting ++;
10038: } else {
1.984 raeburn 10039: $newfiles{$file} = 1;
10040: }
10041: }
1.1071 raeburn 10042: foreach my $file (keys(%currfile)) {
10043: unless (($file eq $filename) ||
10044: ($file eq $filename.'.bak') ||
10045: ($dependencies{$file})) {
1.1085 raeburn 10046: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10047: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10048: next if (($rem ne '') &&
10049: (($env{"httpref.$rem".$file} ne '') ||
10050: (ref($navmap) &&
10051: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10052: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10053: ($navmap->getResourceByUrl($rem.$1)))))));
10054: }
1.1085 raeburn 10055: }
1.1071 raeburn 10056: $unused{$file} = 1;
10057: }
10058: }
1.1084 raeburn 10059: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10060: ($args->{'context'} eq 'paste')) {
10061: $counter = scalar(keys(%existing));
10062: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10063: return ($output,$counter,$numpathchg,\%existing);
10064: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10065: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10066: $counter = scalar(keys(%existing));
10067: $numpathchg = scalar(keys(%pathchanges));
10068: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10069: }
1.984 raeburn 10070: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10071: if ($actionurl eq '/adm/dependencies') {
10072: next if ($embed_file =~ m{^\w+://});
10073: }
1.660 raeburn 10074: $upload_output .= &start_data_table_row().
1.1123 raeburn 10075: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10076: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10077: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10078: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10079: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10080: }
1.1123 raeburn 10081: $upload_output .= '</td>';
1.1071 raeburn 10082: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10083: $upload_output.='<td align="right">'.
10084: '<span class="LC_info LC_fontsize_medium">'.
10085: &mt("URL points to web address").'</span>';
1.987 raeburn 10086: $numremref++;
1.660 raeburn 10087: } elsif ($args->{'error_on_invalid_names'}
10088: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10089: $upload_output.='<td align="right"><span class="LC_warning">'.
10090: &mt('Invalid characters').'</span>';
1.987 raeburn 10091: $numinvalid++;
1.660 raeburn 10092: } else {
1.1123 raeburn 10093: $upload_output .= '<td>'.
10094: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10095: $embed_file,\%mapping,
1.1071 raeburn 10096: $allfiles,$codebase,'upload');
10097: $counter ++;
10098: $numnew ++;
1.987 raeburn 10099: }
10100: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10101: }
10102: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10103: if ($actionurl eq '/adm/dependencies') {
10104: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10105: $modify_output .= &start_data_table_row().
10106: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10107: '<img src="'.&icon($embed_file).'" border="0" />'.
10108: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10109: '<td>'.$size.'</td>'.
10110: '<td>'.$mtime.'</td>'.
10111: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10112: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10113: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10114: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10115: &embedded_file_element('upload_embedded',$counter,
10116: $embed_file,\%mapping,
10117: $allfiles,$codebase,'modify').
10118: '</div></td>'.
10119: &end_data_table_row()."\n";
10120: $counter ++;
10121: } else {
10122: $upload_output .= &start_data_table_row().
1.1123 raeburn 10123: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10124: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10125: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10126: &Apache::loncommon::end_data_table_row()."\n";
10127: }
10128: }
10129: my $delidx = $counter;
10130: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10131: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10132: $delete_output .= &start_data_table_row().
10133: '<td><img src="'.&icon($oldfile).'" />'.
10134: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10135: '<td>'.$size.'</td>'.
10136: '<td>'.$mtime.'</td>'.
10137: '<td><label><input type="checkbox" name="del_upload_dep" '.
10138: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10139: &embedded_file_element('upload_embedded',$delidx,
10140: $oldfile,\%mapping,$allfiles,
10141: $codebase,'delete').'</td>'.
10142: &end_data_table_row()."\n";
10143: $numunused ++;
10144: $delidx ++;
1.987 raeburn 10145: }
10146: if ($upload_output) {
10147: $upload_output = &start_data_table().
10148: $upload_output.
10149: &end_data_table()."\n";
10150: }
1.1071 raeburn 10151: if ($modify_output) {
10152: $modify_output = &start_data_table().
10153: &start_data_table_header_row().
10154: '<th>'.&mt('File').'</th>'.
10155: '<th>'.&mt('Size (KB)').'</th>'.
10156: '<th>'.&mt('Modified').'</th>'.
10157: '<th>'.&mt('Upload replacement?').'</th>'.
10158: &end_data_table_header_row().
10159: $modify_output.
10160: &end_data_table()."\n";
10161: }
10162: if ($delete_output) {
10163: $delete_output = &start_data_table().
10164: &start_data_table_header_row().
10165: '<th>'.&mt('File').'</th>'.
10166: '<th>'.&mt('Size (KB)').'</th>'.
10167: '<th>'.&mt('Modified').'</th>'.
10168: '<th>'.&mt('Delete?').'</th>'.
10169: &end_data_table_header_row().
10170: $delete_output.
10171: &end_data_table()."\n";
10172: }
1.987 raeburn 10173: my $applies = 0;
10174: if ($numremref) {
10175: $applies ++;
10176: }
10177: if ($numinvalid) {
10178: $applies ++;
10179: }
10180: if ($numexisting) {
10181: $applies ++;
10182: }
1.1071 raeburn 10183: if ($counter || $numunused) {
1.987 raeburn 10184: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10185: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10186: $state.'<h3>'.$heading.'</h3>';
10187: if ($actionurl eq '/adm/dependencies') {
10188: if ($numnew) {
10189: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10190: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10191: $upload_output.'<br />'."\n";
10192: }
10193: if ($numexisting) {
10194: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10195: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10196: $modify_output.'<br />'."\n";
10197: $buttontext = &mt('Save changes');
10198: }
10199: if ($numunused) {
10200: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10201: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10202: $delete_output.'<br />'."\n";
10203: $buttontext = &mt('Save changes');
10204: }
10205: } else {
10206: $output .= $upload_output.'<br />'."\n";
10207: }
10208: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10209: $counter.'" />'."\n";
10210: if ($actionurl eq '/adm/dependencies') {
10211: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10212: $numnew.'" />'."\n";
10213: } elsif ($actionurl eq '') {
1.987 raeburn 10214: $output .= '<input type="hidden" name="phase" value="three" />';
10215: }
10216: } elsif ($applies) {
10217: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10218: if ($applies > 1) {
10219: $output .=
1.1123 raeburn 10220: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10221: if ($numremref) {
10222: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10223: }
10224: if ($numinvalid) {
10225: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10226: }
10227: if ($numexisting) {
10228: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10229: }
10230: $output .= '</ul><br />';
10231: } elsif ($numremref) {
10232: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10233: } elsif ($numinvalid) {
10234: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10235: } elsif ($numexisting) {
10236: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10237: }
10238: $output .= $upload_output.'<br />';
10239: }
10240: my ($pathchange_output,$chgcount);
1.1071 raeburn 10241: $chgcount = $counter;
1.987 raeburn 10242: if (keys(%pathchanges) > 0) {
10243: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10244: if ($counter) {
1.987 raeburn 10245: $output .= &embedded_file_element('pathchange',$chgcount,
10246: $embed_file,\%mapping,
1.1071 raeburn 10247: $allfiles,$codebase,'change');
1.987 raeburn 10248: } else {
10249: $pathchange_output .=
10250: &start_data_table_row().
10251: '<td><input type ="checkbox" name="namechange" value="'.
10252: $chgcount.'" checked="checked" /></td>'.
10253: '<td>'.$mapping{$embed_file}.'</td>'.
10254: '<td>'.$embed_file.
10255: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10256: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10257: '</td>'.&end_data_table_row();
1.660 raeburn 10258: }
1.987 raeburn 10259: $numpathchg ++;
10260: $chgcount ++;
1.660 raeburn 10261: }
10262: }
1.1127 raeburn 10263: if (($counter) || ($numunused)) {
1.987 raeburn 10264: if ($numpathchg) {
10265: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10266: $numpathchg.'" />'."\n";
10267: }
10268: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10269: ($actionurl eq '/adm/imsimport')) {
10270: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10271: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10272: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10273: } elsif ($actionurl eq '/adm/dependencies') {
10274: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10275: }
1.1123 raeburn 10276: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10277: } elsif ($numpathchg) {
10278: my %pathchange = ();
10279: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10280: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10281: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10282: }
1.987 raeburn 10283: }
1.1071 raeburn 10284: return ($output,$counter,$numpathchg);
1.987 raeburn 10285: }
10286:
1.1147 raeburn 10287: =pod
10288:
10289: =item * clean_path($name)
10290:
10291: Performs clean-up of directories, subdirectories and filename in an
10292: embedded object, referenced in an HTML file which is being uploaded
10293: to a course or portfolio, where
10294: "Upload embedded images/multimedia files if HTML file" checkbox was
10295: checked.
10296:
10297: Clean-up is similar to replacements in lonnet::clean_filename()
10298: except each / between sub-directory and next level is preserved.
10299:
10300: =cut
10301:
10302: sub clean_path {
10303: my ($embed_file) = @_;
10304: $embed_file =~s{^/+}{};
10305: my @contents;
10306: if ($embed_file =~ m{/}) {
10307: @contents = split(/\//,$embed_file);
10308: } else {
10309: @contents = ($embed_file);
10310: }
10311: my $lastidx = scalar(@contents)-1;
10312: for (my $i=0; $i<=$lastidx; $i++) {
10313: $contents[$i]=~s{\\}{/}g;
10314: $contents[$i]=~s/\s+/\_/g;
10315: $contents[$i]=~s{[^/\w\.\-]}{}g;
10316: if ($i == $lastidx) {
10317: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10318: }
10319: }
10320: if ($lastidx > 0) {
10321: return join('/',@contents);
10322: } else {
10323: return $contents[0];
10324: }
10325: }
10326:
1.987 raeburn 10327: sub embedded_file_element {
1.1071 raeburn 10328: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10329: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10330: (ref($codebase) eq 'HASH'));
10331: my $output;
1.1071 raeburn 10332: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10333: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10334: }
10335: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10336: &escape($embed_file).'" />';
10337: unless (($context eq 'upload_embedded') &&
10338: ($mapping->{$embed_file} eq $embed_file)) {
10339: $output .='
10340: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10341: }
10342: my $attrib;
10343: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10344: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10345: }
10346: $output .=
10347: "\n\t\t".
10348: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10349: $attrib.'" />';
10350: if (exists($codebase->{$mapping->{$embed_file}})) {
10351: $output .=
10352: "\n\t\t".
10353: '<input name="codebase_'.$num.'" type="hidden" value="'.
10354: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10355: }
1.987 raeburn 10356: return $output;
1.660 raeburn 10357: }
10358:
1.1071 raeburn 10359: sub get_dependency_details {
10360: my ($currfile,$currsubfile,$embed_file) = @_;
10361: my ($size,$mtime,$showsize,$showmtime);
10362: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10363: if ($embed_file =~ m{/}) {
10364: my ($path,$fname) = split(/\//,$embed_file);
10365: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10366: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10367: }
10368: } else {
10369: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10370: ($size,$mtime) = @{$currfile->{$embed_file}};
10371: }
10372: }
10373: $showsize = $size/1024.0;
10374: $showsize = sprintf("%.1f",$showsize);
10375: if ($mtime > 0) {
10376: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10377: }
10378: }
10379: return ($showsize,$showmtime);
10380: }
10381:
10382: sub ask_embedded_js {
10383: return <<"END";
10384: <script type="text/javascript"">
10385: // <![CDATA[
10386: function toggleBrowse(counter) {
10387: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10388: var fileid = document.getElementById('embedded_item_'+counter);
10389: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10390: if (chkboxid.checked == true) {
10391: uploaddivid.style.display='block';
10392: } else {
10393: uploaddivid.style.display='none';
10394: fileid.value = '';
10395: }
10396: }
10397: // ]]>
10398: </script>
10399:
10400: END
10401: }
10402:
1.661 raeburn 10403: sub upload_embedded {
10404: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10405: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10406: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10407: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10408: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10409: my $orig_uploaded_filename =
10410: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10411: foreach my $type ('orig','ref','attrib','codebase') {
10412: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10413: $env{'form.embedded_'.$type.'_'.$i} =
10414: &unescape($env{'form.embedded_'.$type.'_'.$i});
10415: }
10416: }
1.661 raeburn 10417: my ($path,$fname) =
10418: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10419: # no path, whole string is fname
10420: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10421: $fname = &Apache::lonnet::clean_filename($fname);
10422: # See if there is anything left
10423: next if ($fname eq '');
10424:
10425: # Check if file already exists as a file or directory.
10426: my ($state,$msg);
10427: if ($context eq 'portfolio') {
10428: my $port_path = $dirpath;
10429: if ($group ne '') {
10430: $port_path = "groups/$group/$port_path";
10431: }
1.987 raeburn 10432: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10433: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10434: $dir_root,$port_path,$disk_quota,
10435: $current_disk_usage,$uname,$udom);
10436: if ($state eq 'will_exceed_quota'
1.984 raeburn 10437: || $state eq 'file_locked') {
1.661 raeburn 10438: $output .= $msg;
10439: next;
10440: }
10441: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10442: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10443: if ($state eq 'exists') {
10444: $output .= $msg;
10445: next;
10446: }
10447: }
10448: # Check if extension is valid
10449: if (($fname =~ /\.(\w+)$/) &&
10450: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 10451: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10452: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10453: next;
10454: } elsif (($fname =~ /\.(\w+)$/) &&
10455: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10456: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10457: next;
10458: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10459: $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 10460: next;
10461: }
10462: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10463: my $subdir = $path;
10464: $subdir =~ s{/+$}{};
1.661 raeburn 10465: if ($context eq 'portfolio') {
1.984 raeburn 10466: my $result;
10467: if ($state eq 'existingfile') {
10468: $result=
10469: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10470: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10471: } else {
1.984 raeburn 10472: $result=
10473: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10474: $dirpath.
1.1123 raeburn 10475: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10476: if ($result !~ m|^/uploaded/|) {
10477: $output .= '<span class="LC_error">'
10478: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10479: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10480: .'</span><br />';
10481: next;
10482: } else {
1.987 raeburn 10483: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10484: $path.$fname.'</span>').'<br />';
1.984 raeburn 10485: }
1.661 raeburn 10486: }
1.1123 raeburn 10487: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10488: my $extendedsubdir = $dirpath.'/'.$subdir;
10489: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10490: my $result =
1.1126 raeburn 10491: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10492: if ($result !~ m|^/uploaded/|) {
10493: $output .= '<span class="LC_error">'
10494: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10495: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10496: .'</span><br />';
10497: next;
10498: } else {
10499: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10500: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10501: if ($context eq 'syllabus') {
10502: &Apache::lonnet::make_public_indefinitely($result);
10503: }
1.987 raeburn 10504: }
1.661 raeburn 10505: } else {
10506: # Save the file
10507: my $target = $env{'form.embedded_item_'.$i};
10508: my $fullpath = $dir_root.$dirpath.'/'.$path;
10509: my $dest = $fullpath.$fname;
10510: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10511: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10512: my $count;
10513: my $filepath = $dir_root;
1.1027 raeburn 10514: foreach my $subdir (@parts) {
10515: $filepath .= "/$subdir";
10516: if (!-e $filepath) {
1.661 raeburn 10517: mkdir($filepath,0770);
10518: }
10519: }
10520: my $fh;
10521: if (!open($fh,'>'.$dest)) {
10522: &Apache::lonnet::logthis('Failed to create '.$dest);
10523: $output .= '<span class="LC_error">'.
1.1071 raeburn 10524: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10525: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10526: '</span><br />';
10527: } else {
10528: if (!print $fh $env{'form.embedded_item_'.$i}) {
10529: &Apache::lonnet::logthis('Failed to write to '.$dest);
10530: $output .= '<span class="LC_error">'.
1.1071 raeburn 10531: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10532: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10533: '</span><br />';
10534: } else {
1.987 raeburn 10535: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10536: $url.'</span>').'<br />';
10537: unless ($context eq 'testbank') {
10538: $footer .= &mt('View embedded file: [_1]',
10539: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10540: }
10541: }
10542: close($fh);
10543: }
10544: }
10545: if ($env{'form.embedded_ref_'.$i}) {
10546: $pathchange{$i} = 1;
10547: }
10548: }
10549: if ($output) {
10550: $output = '<p>'.$output.'</p>';
10551: }
10552: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10553: $returnflag = 'ok';
1.1071 raeburn 10554: my $numpathchgs = scalar(keys(%pathchange));
10555: if ($numpathchgs > 0) {
1.987 raeburn 10556: if ($context eq 'portfolio') {
10557: $output .= '<p>'.&mt('or').'</p>';
10558: } elsif ($context eq 'testbank') {
1.1071 raeburn 10559: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10560: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10561: $returnflag = 'modify_orightml';
10562: }
10563: }
1.1071 raeburn 10564: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10565: }
10566:
10567: sub modify_html_form {
10568: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10569: my $end = 0;
10570: my $modifyform;
10571: if ($context eq 'upload_embedded') {
10572: return unless (ref($pathchange) eq 'HASH');
10573: if ($env{'form.number_embedded_items'}) {
10574: $end += $env{'form.number_embedded_items'};
10575: }
10576: if ($env{'form.number_pathchange_items'}) {
10577: $end += $env{'form.number_pathchange_items'};
10578: }
10579: if ($end) {
10580: for (my $i=0; $i<$end; $i++) {
10581: if ($i < $env{'form.number_embedded_items'}) {
10582: next unless($pathchange->{$i});
10583: }
10584: $modifyform .=
10585: &start_data_table_row().
10586: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10587: 'checked="checked" /></td>'.
10588: '<td>'.$env{'form.embedded_ref_'.$i}.
10589: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10590: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10591: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10592: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10593: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10594: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10595: '<td>'.$env{'form.embedded_orig_'.$i}.
10596: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10597: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10598: &end_data_table_row();
1.1071 raeburn 10599: }
1.987 raeburn 10600: }
10601: } else {
10602: $modifyform = $pathchgtable;
10603: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10604: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10605: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10606: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10607: }
10608: }
10609: if ($modifyform) {
1.1071 raeburn 10610: if ($actionurl eq '/adm/dependencies') {
10611: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10612: }
1.987 raeburn 10613: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10614: '<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".
10615: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10616: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10617: '</ol></p>'."\n".'<p>'.
10618: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10619: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10620: &start_data_table()."\n".
10621: &start_data_table_header_row().
10622: '<th>'.&mt('Change?').'</th>'.
10623: '<th>'.&mt('Current reference').'</th>'.
10624: '<th>'.&mt('Required reference').'</th>'.
10625: &end_data_table_header_row()."\n".
10626: $modifyform.
10627: &end_data_table().'<br />'."\n".$hiddenstate.
10628: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10629: '</form>'."\n";
10630: }
10631: return;
10632: }
10633:
10634: sub modify_html_refs {
1.1123 raeburn 10635: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10636: my $container;
10637: if ($context eq 'portfolio') {
10638: $container = $env{'form.container'};
10639: } elsif ($context eq 'coursedoc') {
10640: $container = $env{'form.primaryurl'};
1.1071 raeburn 10641: } elsif ($context eq 'manage_dependencies') {
10642: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10643: $container = "/$container";
1.1123 raeburn 10644: } elsif ($context eq 'syllabus') {
10645: $container = $url;
1.987 raeburn 10646: } else {
1.1027 raeburn 10647: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10648: }
10649: my (%allfiles,%codebase,$output,$content);
10650: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10651: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10652: if (wantarray) {
10653: return ('',0,0);
10654: } else {
10655: return;
10656: }
10657: }
10658: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10659: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10660: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10661: if (wantarray) {
10662: return ('',0,0);
10663: } else {
10664: return;
10665: }
10666: }
1.987 raeburn 10667: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10668: if ($content eq '-1') {
10669: if (wantarray) {
10670: return ('',0,0);
10671: } else {
10672: return;
10673: }
10674: }
1.987 raeburn 10675: } else {
1.1071 raeburn 10676: unless ($container =~ /^\Q$dir_root\E/) {
10677: if (wantarray) {
10678: return ('',0,0);
10679: } else {
10680: return;
10681: }
10682: }
1.987 raeburn 10683: if (open(my $fh,"<$container")) {
10684: $content = join('', <$fh>);
10685: close($fh);
10686: } else {
1.1071 raeburn 10687: if (wantarray) {
10688: return ('',0,0);
10689: } else {
10690: return;
10691: }
1.987 raeburn 10692: }
10693: }
10694: my ($count,$codebasecount) = (0,0);
10695: my $mm = new File::MMagic;
10696: my $mime_type = $mm->checktype_contents($content);
10697: if ($mime_type eq 'text/html') {
10698: my $parse_result =
10699: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10700: \%codebase,\$content);
10701: if ($parse_result eq 'ok') {
10702: foreach my $i (@changes) {
10703: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10704: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10705: if ($allfiles{$ref}) {
10706: my $newname = $orig;
10707: my ($attrib_regexp,$codebase);
1.1006 raeburn 10708: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10709: if ($attrib_regexp =~ /:/) {
10710: $attrib_regexp =~ s/\:/|/g;
10711: }
10712: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10713: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10714: $count += $numchg;
1.1123 raeburn 10715: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 10716: delete($allfiles{$ref});
1.987 raeburn 10717: }
10718: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10719: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10720: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10721: $codebasecount ++;
10722: }
10723: }
10724: }
1.1123 raeburn 10725: my $skiprewrites;
1.987 raeburn 10726: if ($count || $codebasecount) {
10727: my $saveresult;
1.1071 raeburn 10728: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10729: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10730: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10731: if ($url eq $container) {
10732: my ($fname) = ($container =~ m{/([^/]+)$});
10733: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10734: $count,'<span class="LC_filename">'.
1.1071 raeburn 10735: $fname.'</span>').'</p>';
1.987 raeburn 10736: } else {
10737: $output = '<p class="LC_error">'.
10738: &mt('Error: update failed for: [_1].',
10739: '<span class="LC_filename">'.
10740: $container.'</span>').'</p>';
10741: }
1.1123 raeburn 10742: if ($context eq 'syllabus') {
10743: unless ($saveresult eq 'ok') {
10744: $skiprewrites = 1;
10745: }
10746: }
1.987 raeburn 10747: } else {
10748: if (open(my $fh,">$container")) {
10749: print $fh $content;
10750: close($fh);
10751: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10752: $count,'<span class="LC_filename">'.
10753: $container.'</span>').'</p>';
1.661 raeburn 10754: } else {
1.987 raeburn 10755: $output = '<p class="LC_error">'.
10756: &mt('Error: could not update [_1].',
10757: '<span class="LC_filename">'.
10758: $container.'</span>').'</p>';
1.661 raeburn 10759: }
10760: }
10761: }
1.1123 raeburn 10762: if (($context eq 'syllabus') && (!$skiprewrites)) {
10763: my ($actionurl,$state);
10764: $actionurl = "/public/$udom/$uname/syllabus";
10765: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10766: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10767: \%codebase,
10768: {'context' => 'rewrites',
10769: 'ignore_remote_references' => 1,});
10770: if (ref($mapping) eq 'HASH') {
10771: my $rewrites = 0;
10772: foreach my $key (keys(%{$mapping})) {
10773: next if ($key =~ m{^https?://});
10774: my $ref = $mapping->{$key};
10775: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10776: my $attrib;
10777: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10778: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10779: }
10780: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10781: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10782: $rewrites += $numchg;
10783: }
10784: }
10785: if ($rewrites) {
10786: my $saveresult;
10787: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10788: if ($url eq $container) {
10789: my ($fname) = ($container =~ m{/([^/]+)$});
10790: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10791: $count,'<span class="LC_filename">'.
10792: $fname.'</span>').'</p>';
10793: } else {
10794: $output .= '<p class="LC_error">'.
10795: &mt('Error: could not update links in [_1].',
10796: '<span class="LC_filename">'.
10797: $container.'</span>').'</p>';
10798:
10799: }
10800: }
10801: }
10802: }
1.987 raeburn 10803: } else {
10804: &logthis('Failed to parse '.$container.
10805: ' to modify references: '.$parse_result);
1.661 raeburn 10806: }
10807: }
1.1071 raeburn 10808: if (wantarray) {
10809: return ($output,$count,$codebasecount);
10810: } else {
10811: return $output;
10812: }
1.661 raeburn 10813: }
10814:
10815: sub check_for_existing {
10816: my ($path,$fname,$element) = @_;
10817: my ($state,$msg);
10818: if (-d $path.'/'.$fname) {
10819: $state = 'exists';
10820: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10821: } elsif (-e $path.'/'.$fname) {
10822: $state = 'exists';
10823: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10824: }
10825: if ($state eq 'exists') {
10826: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10827: }
10828: return ($state,$msg);
10829: }
10830:
10831: sub check_for_upload {
10832: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10833: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10834: my $filesize = length($env{'form.'.$element});
10835: if (!$filesize) {
10836: my $msg = '<span class="LC_error">'.
10837: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10838: '<span class="LC_filename">'.$fname.'</span>',
10839: $filesize).'<br />'.
1.1007 raeburn 10840: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10841: '</span>';
10842: return ('zero_bytes',$msg);
10843: }
10844: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10845: my $getpropath = 1;
1.1021 raeburn 10846: my ($dirlistref,$listerror) =
10847: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10848: my $found_file = 0;
10849: my $locked_file = 0;
1.991 raeburn 10850: my @lockers;
10851: my $navmap;
10852: if ($env{'request.course.id'}) {
10853: $navmap = Apache::lonnavmaps::navmap->new();
10854: }
1.1021 raeburn 10855: if (ref($dirlistref) eq 'ARRAY') {
10856: foreach my $line (@{$dirlistref}) {
10857: my ($file_name,$rest)=split(/\&/,$line,2);
10858: if ($file_name eq $fname){
10859: $file_name = $path.$file_name;
10860: if ($group ne '') {
10861: $file_name = $group.$file_name;
10862: }
10863: $found_file = 1;
10864: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10865: foreach my $lock (@lockers) {
10866: if (ref($lock) eq 'ARRAY') {
10867: my ($symb,$crsid) = @{$lock};
10868: if ($crsid eq $env{'request.course.id'}) {
10869: if (ref($navmap)) {
10870: my $res = $navmap->getBySymb($symb);
10871: foreach my $part (@{$res->parts()}) {
10872: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10873: unless (($slot_status == $res->RESERVED) ||
10874: ($slot_status == $res->RESERVED_LOCATION)) {
10875: $locked_file = 1;
10876: }
1.991 raeburn 10877: }
1.1021 raeburn 10878: } else {
10879: $locked_file = 1;
1.991 raeburn 10880: }
10881: } else {
10882: $locked_file = 1;
10883: }
10884: }
1.1021 raeburn 10885: }
10886: } else {
10887: my @info = split(/\&/,$rest);
10888: my $currsize = $info[6]/1000;
10889: if ($currsize < $filesize) {
10890: my $extra = $filesize - $currsize;
10891: if (($current_disk_usage + $extra) > $disk_quota) {
10892: my $msg = '<span class="LC_error">'.
10893: &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.',
10894: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10895: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10896: $disk_quota,$current_disk_usage);
10897: return ('will_exceed_quota',$msg);
10898: }
1.984 raeburn 10899: }
10900: }
1.661 raeburn 10901: }
10902: }
10903: }
10904: if (($current_disk_usage + $filesize) > $disk_quota){
10905: my $msg = '<span class="LC_error">'.
10906: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10907: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10908: return ('will_exceed_quota',$msg);
10909: } elsif ($found_file) {
10910: if ($locked_file) {
10911: my $msg = '<span class="LC_error">';
10912: $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>');
10913: $msg .= '</span><br />';
10914: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10915: return ('file_locked',$msg);
10916: } else {
10917: my $msg = '<span class="LC_error">';
1.984 raeburn 10918: $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 10919: $msg .= '</span>';
1.984 raeburn 10920: return ('existingfile',$msg);
1.661 raeburn 10921: }
10922: }
10923: }
10924:
1.987 raeburn 10925: sub check_for_traversal {
10926: my ($path,$url,$toplevel) = @_;
10927: my @parts=split(/\//,$path);
10928: my $cleanpath;
10929: my $fullpath = $url;
10930: for (my $i=0;$i<@parts;$i++) {
10931: next if ($parts[$i] eq '.');
10932: if ($parts[$i] eq '..') {
10933: $fullpath =~ s{([^/]+/)$}{};
10934: } else {
10935: $fullpath .= $parts[$i].'/';
10936: }
10937: }
10938: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10939: $cleanpath = $1;
10940: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10941: my $curr_toprel = $1;
10942: my @parts = split(/\//,$curr_toprel);
10943: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10944: my @urlparts = split(/\//,$url_toprel);
10945: my $doubledots;
10946: my $startdiff = -1;
10947: for (my $i=0; $i<@urlparts; $i++) {
10948: if ($startdiff == -1) {
10949: unless ($urlparts[$i] eq $parts[$i]) {
10950: $startdiff = $i;
10951: $doubledots .= '../';
10952: }
10953: } else {
10954: $doubledots .= '../';
10955: }
10956: }
10957: if ($startdiff > -1) {
10958: $cleanpath = $doubledots;
10959: for (my $i=$startdiff; $i<@parts; $i++) {
10960: $cleanpath .= $parts[$i].'/';
10961: }
10962: }
10963: }
10964: $cleanpath =~ s{(/)$}{};
10965: return $cleanpath;
10966: }
1.31 albertel 10967:
1.1053 raeburn 10968: sub is_archive_file {
10969: my ($mimetype) = @_;
10970: if (($mimetype eq 'application/octet-stream') ||
10971: ($mimetype eq 'application/x-stuffit') ||
10972: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10973: return 1;
10974: }
10975: return;
10976: }
10977:
10978: sub decompress_form {
1.1065 raeburn 10979: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10980: my %lt = &Apache::lonlocal::texthash (
10981: this => 'This file is an archive file.',
1.1067 raeburn 10982: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10983: itsc => 'Its contents are as follows:',
1.1053 raeburn 10984: youm => 'You may wish to extract its contents.',
10985: extr => 'Extract contents',
1.1067 raeburn 10986: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10987: proa => 'Process automatically?',
1.1053 raeburn 10988: yes => 'Yes',
10989: no => 'No',
1.1067 raeburn 10990: fold => 'Title for folder containing movie',
10991: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10992: );
1.1065 raeburn 10993: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10994: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10995: my $info = &list_archive_contents($fileloc,\@paths);
10996: if (@paths) {
10997: foreach my $path (@paths) {
10998: $path =~ s{^/}{};
1.1067 raeburn 10999: if ($path =~ m{^([^/]+)/$}) {
11000: $topdir = $1;
11001: }
1.1065 raeburn 11002: if ($path =~ m{^([^/]+)/}) {
11003: $toplevel{$1} = $path;
11004: } else {
11005: $toplevel{$path} = $path;
11006: }
11007: }
11008: }
1.1067 raeburn 11009: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11010: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11011: "$topdir/media/",
11012: "$topdir/media/$topdir.mp4",
11013: "$topdir/media/FirstFrame.png",
11014: "$topdir/media/player.swf",
11015: "$topdir/media/swfobject.js",
11016: "$topdir/media/expressInstall.swf");
1.1164 raeburn 11017: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11018: "$topdir/$topdir.mp4",
11019: "$topdir/$topdir\_config.xml",
11020: "$topdir/$topdir\_controller.swf",
11021: "$topdir/$topdir\_embed.css",
11022: "$topdir/$topdir\_First_Frame.png",
11023: "$topdir/$topdir\_player.html",
11024: "$topdir/$topdir\_Thumbnails.png",
11025: "$topdir/playerProductInstall.swf",
11026: "$topdir/scripts/",
11027: "$topdir/scripts/config_xml.js",
11028: "$topdir/scripts/handlebars.js",
11029: "$topdir/scripts/jquery-1.7.1.min.js",
11030: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11031: "$topdir/scripts/modernizr.js",
11032: "$topdir/scripts/player-min.js",
11033: "$topdir/scripts/swfobject.js",
11034: "$topdir/skins/",
11035: "$topdir/skins/configuration_express.xml",
11036: "$topdir/skins/express_show/",
11037: "$topdir/skins/express_show/player-min.css",
11038: "$topdir/skins/express_show/spritesheet.png");
11039: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11040: if (@diffs == 0) {
1.1164 raeburn 11041: $is_camtasia = 6;
11042: } else {
11043: @diffs = &compare_arrays(\@paths,\@camtasia8);
11044: if (@diffs == 0) {
11045: $is_camtasia = 8;
11046: }
1.1067 raeburn 11047: }
11048: }
11049: my $output;
11050: if ($is_camtasia) {
11051: $output = <<"ENDCAM";
11052: <script type="text/javascript" language="Javascript">
11053: // <![CDATA[
11054:
11055: function camtasiaToggle() {
11056: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11057: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11058: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11059:
11060: document.getElementById('camtasia_titles').style.display='block';
11061: } else {
11062: document.getElementById('camtasia_titles').style.display='none';
11063: }
11064: }
11065: }
11066: return;
11067: }
11068:
11069: // ]]>
11070: </script>
11071: <p>$lt{'camt'}</p>
11072: ENDCAM
1.1065 raeburn 11073: } else {
1.1067 raeburn 11074: $output = '<p>'.$lt{'this'};
11075: if ($info eq '') {
11076: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11077: } else {
11078: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11079: '<div><pre>'.$info.'</pre></div>';
11080: }
1.1065 raeburn 11081: }
1.1067 raeburn 11082: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11083: my $duplicates;
11084: my $num = 0;
11085: if (ref($dirlist) eq 'ARRAY') {
11086: foreach my $item (@{$dirlist}) {
11087: if (ref($item) eq 'ARRAY') {
11088: if (exists($toplevel{$item->[0]})) {
11089: $duplicates .=
11090: &start_data_table_row().
11091: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11092: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11093: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11094: 'value="1" />'.&mt('Yes').'</label>'.
11095: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11096: '<td>'.$item->[0].'</td>';
11097: if ($item->[2]) {
11098: $duplicates .= '<td>'.&mt('Directory').'</td>';
11099: } else {
11100: $duplicates .= '<td>'.&mt('File').'</td>';
11101: }
11102: $duplicates .= '<td>'.$item->[3].'</td>'.
11103: '<td>'.
11104: &Apache::lonlocal::locallocaltime($item->[4]).
11105: '</td>'.
11106: &end_data_table_row();
11107: $num ++;
11108: }
11109: }
11110: }
11111: }
11112: my $itemcount;
11113: if (@paths > 0) {
11114: $itemcount = scalar(@paths);
11115: } else {
11116: $itemcount = 1;
11117: }
1.1067 raeburn 11118: if ($is_camtasia) {
11119: $output .= $lt{'auto'}.'<br />'.
11120: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11121: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11122: $lt{'yes'}.'</label> <label>'.
11123: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11124: $lt{'no'}.'</label></span><br />'.
11125: '<div id="camtasia_titles" style="display:block">'.
11126: &Apache::lonhtmlcommon::start_pick_box().
11127: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11128: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11129: &Apache::lonhtmlcommon::row_closure().
11130: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11131: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11132: &Apache::lonhtmlcommon::row_closure(1).
11133: &Apache::lonhtmlcommon::end_pick_box().
11134: '</div>';
11135: }
1.1065 raeburn 11136: $output .=
11137: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11138: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11139: "\n";
1.1065 raeburn 11140: if ($duplicates ne '') {
11141: $output .= '<p><span class="LC_warning">'.
11142: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11143: &start_data_table().
11144: &start_data_table_header_row().
11145: '<th>'.&mt('Overwrite?').'</th>'.
11146: '<th>'.&mt('Name').'</th>'.
11147: '<th>'.&mt('Type').'</th>'.
11148: '<th>'.&mt('Size').'</th>'.
11149: '<th>'.&mt('Last modified').'</th>'.
11150: &end_data_table_header_row().
11151: $duplicates.
11152: &end_data_table().
11153: '</p>';
11154: }
1.1067 raeburn 11155: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11156: if (ref($hiddenelements) eq 'HASH') {
11157: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11158: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11159: }
11160: }
11161: $output .= <<"END";
1.1067 raeburn 11162: <br />
1.1053 raeburn 11163: <input type="submit" name="decompress" value="$lt{'extr'}" />
11164: </form>
11165: $noextract
11166: END
11167: return $output;
11168: }
11169:
1.1065 raeburn 11170: sub decompression_utility {
11171: my ($program) = @_;
11172: my @utilities = ('tar','gunzip','bunzip2','unzip');
11173: my $location;
11174: if (grep(/^\Q$program\E$/,@utilities)) {
11175: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11176: '/usr/sbin/') {
11177: if (-x $dir.$program) {
11178: $location = $dir.$program;
11179: last;
11180: }
11181: }
11182: }
11183: return $location;
11184: }
11185:
11186: sub list_archive_contents {
11187: my ($file,$pathsref) = @_;
11188: my (@cmd,$output);
11189: my $needsregexp;
11190: if ($file =~ /\.zip$/) {
11191: @cmd = (&decompression_utility('unzip'),"-l");
11192: $needsregexp = 1;
11193: } elsif (($file =~ m/\.tar\.gz$/) ||
11194: ($file =~ /\.tgz$/)) {
11195: @cmd = (&decompression_utility('tar'),"-ztf");
11196: } elsif ($file =~ /\.tar\.bz2$/) {
11197: @cmd = (&decompression_utility('tar'),"-jtf");
11198: } elsif ($file =~ m|\.tar$|) {
11199: @cmd = (&decompression_utility('tar'),"-tf");
11200: }
11201: if (@cmd) {
11202: undef($!);
11203: undef($@);
11204: if (open(my $fh,"-|", @cmd, $file)) {
11205: while (my $line = <$fh>) {
11206: $output .= $line;
11207: chomp($line);
11208: my $item;
11209: if ($needsregexp) {
11210: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11211: } else {
11212: $item = $line;
11213: }
11214: if ($item ne '') {
11215: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11216: push(@{$pathsref},$item);
11217: }
11218: }
11219: }
11220: close($fh);
11221: }
11222: }
11223: return $output;
11224: }
11225:
1.1053 raeburn 11226: sub decompress_uploaded_file {
11227: my ($file,$dir) = @_;
11228: &Apache::lonnet::appenv({'cgi.file' => $file});
11229: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11230: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11231: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11232: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11233: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11234: my $decompressed = $env{'cgi.decompressed'};
11235: &Apache::lonnet::delenv('cgi.file');
11236: &Apache::lonnet::delenv('cgi.dir');
11237: &Apache::lonnet::delenv('cgi.decompressed');
11238: return ($decompressed,$result);
11239: }
11240:
1.1055 raeburn 11241: sub process_decompression {
11242: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11243: my ($dir,$error,$warning,$output);
11244: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1120 bisitz 11245: $error = &mt('Filename not a supported archive file type.').
11246: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11247: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11248: } else {
11249: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11250: if ($docuhome eq 'no_host') {
11251: $error = &mt('Could not determine home server for course.');
11252: } else {
11253: my @ids=&Apache::lonnet::current_machine_ids();
11254: my $currdir = "$dir_root/$destination";
11255: if (grep(/^\Q$docuhome\E$/,@ids)) {
11256: $dir = &LONCAPA::propath($docudom,$docuname).
11257: "$dir_root/$destination";
11258: } else {
11259: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11260: "$dir_root/$docudom/$docuname/$destination";
11261: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11262: $error = &mt('Archive file not found.');
11263: }
11264: }
1.1065 raeburn 11265: my (@to_overwrite,@to_skip);
11266: if ($env{'form.archive_overwrite_total'} > 0) {
11267: my $total = $env{'form.archive_overwrite_total'};
11268: for (my $i=0; $i<$total; $i++) {
11269: if ($env{'form.archive_overwrite_'.$i} == 1) {
11270: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11271: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11272: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11273: }
11274: }
11275: }
11276: my $numskip = scalar(@to_skip);
11277: if (($numskip > 0) &&
11278: ($numskip == $env{'form.archive_itemcount'})) {
11279: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11280: } elsif ($dir eq '') {
1.1055 raeburn 11281: $error = &mt('Directory containing archive file unavailable.');
11282: } elsif (!$error) {
1.1065 raeburn 11283: my ($decompressed,$display);
11284: if ($numskip > 0) {
11285: my $tempdir = time.'_'.$$.int(rand(10000));
11286: mkdir("$dir/$tempdir",0755);
11287: system("mv $dir/$file $dir/$tempdir/$file");
11288: ($decompressed,$display) =
11289: &decompress_uploaded_file($file,"$dir/$tempdir");
11290: foreach my $item (@to_skip) {
11291: if (($item ne '') && ($item !~ /\.\./)) {
11292: if (-f "$dir/$tempdir/$item") {
11293: unlink("$dir/$tempdir/$item");
11294: } elsif (-d "$dir/$tempdir/$item") {
11295: system("rm -rf $dir/$tempdir/$item");
11296: }
11297: }
11298: }
11299: system("mv $dir/$tempdir/* $dir");
11300: rmdir("$dir/$tempdir");
11301: } else {
11302: ($decompressed,$display) =
11303: &decompress_uploaded_file($file,$dir);
11304: }
1.1055 raeburn 11305: if ($decompressed eq 'ok') {
1.1065 raeburn 11306: $output = '<p class="LC_info">'.
11307: &mt('Files extracted successfully from archive.').
11308: '</p>'."\n";
1.1055 raeburn 11309: my ($warning,$result,@contents);
11310: my ($newdirlistref,$newlisterror) =
11311: &Apache::lonnet::dirlist($currdir,$docudom,
11312: $docuname,1);
11313: my (%is_dir,%changes,@newitems);
11314: my $dirptr = 16384;
1.1065 raeburn 11315: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11316: foreach my $dir_line (@{$newdirlistref}) {
11317: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11318: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11319: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11320: push(@newitems,$item);
11321: if ($dirptr&$testdir) {
11322: $is_dir{$item} = 1;
11323: }
11324: $changes{$item} = 1;
11325: }
11326: }
11327: }
11328: if (keys(%changes) > 0) {
11329: foreach my $item (sort(@newitems)) {
11330: if ($changes{$item}) {
11331: push(@contents,$item);
11332: }
11333: }
11334: }
11335: if (@contents > 0) {
1.1067 raeburn 11336: my $wantform;
11337: unless ($env{'form.autoextract_camtasia'}) {
11338: $wantform = 1;
11339: }
1.1056 raeburn 11340: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11341: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11342: $currdir,\%is_dir,
11343: \%children,\%parent,
1.1056 raeburn 11344: \@contents,\%dirorder,
11345: \%titles,$wantform);
1.1055 raeburn 11346: if ($datatable ne '') {
11347: $output .= &archive_options_form('decompressed',$datatable,
11348: $count,$hiddenelem);
1.1065 raeburn 11349: my $startcount = 6;
1.1055 raeburn 11350: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11351: \%titles,\%children);
1.1055 raeburn 11352: }
1.1067 raeburn 11353: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11354: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11355: my %displayed;
11356: my $total = 1;
11357: $env{'form.archive_directory'} = [];
11358: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11359: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11360: $path =~ s{/$}{};
11361: my $item;
11362: if ($path ne '') {
11363: $item = "$path/$titles{$i}";
11364: } else {
11365: $item = $titles{$i};
11366: }
11367: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11368: if ($item eq $contents[0]) {
11369: push(@{$env{'form.archive_directory'}},$i);
11370: $env{'form.archive_'.$i} = 'display';
11371: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11372: $displayed{'folder'} = $i;
1.1164 raeburn 11373: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11374: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11375: $env{'form.archive_'.$i} = 'display';
11376: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11377: $displayed{'web'} = $i;
11378: } else {
1.1164 raeburn 11379: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11380: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11381: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11382: push(@{$env{'form.archive_directory'}},$i);
11383: }
11384: $env{'form.archive_'.$i} = 'dependency';
11385: }
11386: $total ++;
11387: }
11388: for (my $i=1; $i<$total; $i++) {
11389: next if ($i == $displayed{'web'});
11390: next if ($i == $displayed{'folder'});
11391: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11392: }
11393: $env{'form.phase'} = 'decompress_cleanup';
11394: $env{'form.archivedelete'} = 1;
11395: $env{'form.archive_count'} = $total-1;
11396: $output .=
11397: &process_extracted_files('coursedocs',$docudom,
11398: $docuname,$destination,
11399: $dir_root,$hiddenelem);
11400: }
1.1055 raeburn 11401: } else {
11402: $warning = &mt('No new items extracted from archive file.');
11403: }
11404: } else {
11405: $output = $display;
11406: $error = &mt('An error occurred during extraction from the archive file.');
11407: }
11408: }
11409: }
11410: }
11411: if ($error) {
11412: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11413: $error.'</p>'."\n";
11414: }
11415: if ($warning) {
11416: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11417: }
11418: return $output;
11419: }
11420:
11421: sub get_extracted {
1.1056 raeburn 11422: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11423: $titles,$wantform) = @_;
1.1055 raeburn 11424: my $count = 0;
11425: my $depth = 0;
11426: my $datatable;
1.1056 raeburn 11427: my @hierarchy;
1.1055 raeburn 11428: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11429: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11430: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11431: foreach my $item (@{$contents}) {
11432: $count ++;
1.1056 raeburn 11433: @{$dirorder->{$count}} = @hierarchy;
11434: $titles->{$count} = $item;
1.1055 raeburn 11435: &archive_hierarchy($depth,$count,$parent,$children);
11436: if ($wantform) {
11437: $datatable .= &archive_row($is_dir->{$item},$item,
11438: $currdir,$depth,$count);
11439: }
11440: if ($is_dir->{$item}) {
11441: $depth ++;
1.1056 raeburn 11442: push(@hierarchy,$count);
11443: $parent->{$depth} = $count;
1.1055 raeburn 11444: $datatable .=
11445: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11446: \$depth,\$count,\@hierarchy,$dirorder,
11447: $children,$parent,$titles,$wantform);
1.1055 raeburn 11448: $depth --;
1.1056 raeburn 11449: pop(@hierarchy);
1.1055 raeburn 11450: }
11451: }
11452: return ($count,$datatable);
11453: }
11454:
11455: sub recurse_extracted_archive {
1.1056 raeburn 11456: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11457: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11458: my $result='';
1.1056 raeburn 11459: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11460: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11461: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11462: return $result;
11463: }
11464: my $dirptr = 16384;
11465: my ($newdirlistref,$newlisterror) =
11466: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11467: if (ref($newdirlistref) eq 'ARRAY') {
11468: foreach my $dir_line (@{$newdirlistref}) {
11469: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11470: unless ($item =~ /^\.+$/) {
11471: $$count ++;
1.1056 raeburn 11472: @{$dirorder->{$$count}} = @{$hierarchy};
11473: $titles->{$$count} = $item;
1.1055 raeburn 11474: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11475:
1.1055 raeburn 11476: my $is_dir;
11477: if ($dirptr&$testdir) {
11478: $is_dir = 1;
11479: }
11480: if ($wantform) {
11481: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11482: }
11483: if ($is_dir) {
11484: $$depth ++;
1.1056 raeburn 11485: push(@{$hierarchy},$$count);
11486: $parent->{$$depth} = $$count;
1.1055 raeburn 11487: $result .=
11488: &recurse_extracted_archive("$currdir/$item",$docudom,
11489: $docuname,$depth,$count,
1.1056 raeburn 11490: $hierarchy,$dirorder,$children,
11491: $parent,$titles,$wantform);
1.1055 raeburn 11492: $$depth --;
1.1056 raeburn 11493: pop(@{$hierarchy});
1.1055 raeburn 11494: }
11495: }
11496: }
11497: }
11498: return $result;
11499: }
11500:
11501: sub archive_hierarchy {
11502: my ($depth,$count,$parent,$children) =@_;
11503: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11504: if (exists($parent->{$depth})) {
11505: $children->{$parent->{$depth}} .= $count.':';
11506: }
11507: }
11508: return;
11509: }
11510:
11511: sub archive_row {
11512: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11513: my ($name) = ($item =~ m{([^/]+)$});
11514: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11515: 'display' => 'Add as file',
1.1055 raeburn 11516: 'dependency' => 'Include as dependency',
11517: 'discard' => 'Discard',
11518: );
11519: if ($is_dir) {
1.1059 raeburn 11520: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11521: }
1.1056 raeburn 11522: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11523: my $offset = 0;
1.1055 raeburn 11524: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11525: $offset ++;
1.1065 raeburn 11526: if ($action ne 'display') {
11527: $offset ++;
11528: }
1.1055 raeburn 11529: $output .= '<td><span class="LC_nobreak">'.
11530: '<label><input type="radio" name="archive_'.$count.
11531: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11532: my $text = $choices{$action};
11533: if ($is_dir) {
11534: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11535: if ($action eq 'display') {
1.1059 raeburn 11536: $text = &mt('Add as folder');
1.1055 raeburn 11537: }
1.1056 raeburn 11538: } else {
11539: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11540:
11541: }
11542: $output .= ' /> '.$choices{$action}.'</label></span>';
11543: if ($action eq 'dependency') {
11544: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11545: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11546: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11547: '<option value=""></option>'."\n".
11548: '</select>'."\n".
11549: '</div>';
1.1059 raeburn 11550: } elsif ($action eq 'display') {
11551: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11552: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11553: '</div>';
1.1055 raeburn 11554: }
1.1056 raeburn 11555: $output .= '</td>';
1.1055 raeburn 11556: }
11557: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11558: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11559: for (my $i=0; $i<$depth; $i++) {
11560: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11561: }
11562: if ($is_dir) {
11563: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11564: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11565: } else {
11566: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11567: }
11568: $output .= ' '.$name.'</td>'."\n".
11569: &end_data_table_row();
11570: return $output;
11571: }
11572:
11573: sub archive_options_form {
1.1065 raeburn 11574: my ($form,$display,$count,$hiddenelem) = @_;
11575: my %lt = &Apache::lonlocal::texthash(
11576: perm => 'Permanently remove archive file?',
11577: hows => 'How should each extracted item be incorporated in the course?',
11578: cont => 'Content actions for all',
11579: addf => 'Add as folder/file',
11580: incd => 'Include as dependency for a displayed file',
11581: disc => 'Discard',
11582: no => 'No',
11583: yes => 'Yes',
11584: save => 'Save',
11585: );
11586: my $output = <<"END";
11587: <form name="$form" method="post" action="">
11588: <p><span class="LC_nobreak">$lt{'perm'}
11589: <label>
11590: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11591: </label>
11592:
11593: <label>
11594: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11595: </span>
11596: </p>
11597: <input type="hidden" name="phase" value="decompress_cleanup" />
11598: <br />$lt{'hows'}
11599: <div class="LC_columnSection">
11600: <fieldset>
11601: <legend>$lt{'cont'}</legend>
11602: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11603: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11604: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11605: </fieldset>
11606: </div>
11607: END
11608: return $output.
1.1055 raeburn 11609: &start_data_table()."\n".
1.1065 raeburn 11610: $display."\n".
1.1055 raeburn 11611: &end_data_table()."\n".
11612: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11613: $hiddenelem.
1.1065 raeburn 11614: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11615: '</form>';
11616: }
11617:
11618: sub archive_javascript {
1.1056 raeburn 11619: my ($startcount,$numitems,$titles,$children) = @_;
11620: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11621: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11622: my $scripttag = <<START;
11623: <script type="text/javascript">
11624: // <![CDATA[
11625:
11626: function checkAll(form,prefix) {
11627: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11628: for (var i=0; i < form.elements.length; i++) {
11629: var id = form.elements[i].id;
11630: if ((id != '') && (id != undefined)) {
11631: if (idstr.test(id)) {
11632: if (form.elements[i].type == 'radio') {
11633: form.elements[i].checked = true;
1.1056 raeburn 11634: var nostart = i-$startcount;
1.1059 raeburn 11635: var offset = nostart%7;
11636: var count = (nostart-offset)/7;
1.1056 raeburn 11637: dependencyCheck(form,count,offset);
1.1055 raeburn 11638: }
11639: }
11640: }
11641: }
11642: }
11643:
11644: function propagateCheck(form,count) {
11645: if (count > 0) {
1.1059 raeburn 11646: var startelement = $startcount + ((count-1) * 7);
11647: for (var j=1; j<6; j++) {
11648: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11649: var item = startelement + j;
11650: if (form.elements[item].type == 'radio') {
11651: if (form.elements[item].checked) {
11652: containerCheck(form,count,j);
11653: break;
11654: }
1.1055 raeburn 11655: }
11656: }
11657: }
11658: }
11659: }
11660:
11661: numitems = $numitems
1.1056 raeburn 11662: var titles = new Array(numitems);
11663: var parents = new Array(numitems);
1.1055 raeburn 11664: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11665: parents[i] = new Array;
1.1055 raeburn 11666: }
1.1059 raeburn 11667: var maintitle = '$maintitle';
1.1055 raeburn 11668:
11669: START
11670:
1.1056 raeburn 11671: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11672: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11673: for (my $i=0; $i<@contents; $i ++) {
11674: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11675: }
11676: }
11677:
1.1056 raeburn 11678: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11679: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11680: }
11681:
1.1055 raeburn 11682: $scripttag .= <<END;
11683:
11684: function containerCheck(form,count,offset) {
11685: if (count > 0) {
1.1056 raeburn 11686: dependencyCheck(form,count,offset);
1.1059 raeburn 11687: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11688: form.elements[item].checked = true;
11689: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11690: if (parents[count].length > 0) {
11691: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11692: containerCheck(form,parents[count][j],offset);
11693: }
11694: }
11695: }
11696: }
11697: }
11698:
11699: function dependencyCheck(form,count,offset) {
11700: if (count > 0) {
1.1059 raeburn 11701: var chosen = (offset+$startcount)+7*(count-1);
11702: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11703: var currtype = form.elements[depitem].type;
11704: if (form.elements[chosen].value == 'dependency') {
11705: document.getElementById('arc_depon_'+count).style.display='block';
11706: form.elements[depitem].options.length = 0;
11707: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11708: for (var i=1; i<=numitems; i++) {
11709: if (i == count) {
11710: continue;
11711: }
1.1059 raeburn 11712: var startelement = $startcount + (i-1) * 7;
11713: for (var j=1; j<6; j++) {
11714: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11715: var item = startelement + j;
11716: if (form.elements[item].type == 'radio') {
11717: if (form.elements[item].checked) {
11718: if (form.elements[item].value == 'display') {
11719: var n = form.elements[depitem].options.length;
11720: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11721: }
11722: }
11723: }
11724: }
11725: }
11726: }
11727: } else {
11728: document.getElementById('arc_depon_'+count).style.display='none';
11729: form.elements[depitem].options.length = 0;
11730: form.elements[depitem].options[0] = new Option('Select','',true,true);
11731: }
1.1059 raeburn 11732: titleCheck(form,count,offset);
1.1056 raeburn 11733: }
11734: }
11735:
11736: function propagateSelect(form,count,offset) {
11737: if (count > 0) {
1.1065 raeburn 11738: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11739: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11740: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11741: if (parents[count].length > 0) {
11742: for (var j=0; j<parents[count].length; j++) {
11743: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11744: }
11745: }
11746: }
11747: }
11748: }
1.1056 raeburn 11749:
11750: function containerSelect(form,count,offset,picked) {
11751: if (count > 0) {
1.1065 raeburn 11752: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11753: if (form.elements[item].type == 'radio') {
11754: if (form.elements[item].value == 'dependency') {
11755: if (form.elements[item+1].type == 'select-one') {
11756: for (var i=0; i<form.elements[item+1].options.length; i++) {
11757: if (form.elements[item+1].options[i].value == picked) {
11758: form.elements[item+1].selectedIndex = i;
11759: break;
11760: }
11761: }
11762: }
11763: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11764: if (parents[count].length > 0) {
11765: for (var j=0; j<parents[count].length; j++) {
11766: containerSelect(form,parents[count][j],offset,picked);
11767: }
11768: }
11769: }
11770: }
11771: }
11772: }
11773: }
11774:
1.1059 raeburn 11775: function titleCheck(form,count,offset) {
11776: if (count > 0) {
11777: var chosen = (offset+$startcount)+7*(count-1);
11778: var depitem = $startcount + ((count-1) * 7) + 2;
11779: var currtype = form.elements[depitem].type;
11780: if (form.elements[chosen].value == 'display') {
11781: document.getElementById('arc_title_'+count).style.display='block';
11782: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11783: document.getElementById('archive_title_'+count).value=maintitle;
11784: }
11785: } else {
11786: document.getElementById('arc_title_'+count).style.display='none';
11787: if (currtype == 'text') {
11788: document.getElementById('archive_title_'+count).value='';
11789: }
11790: }
11791: }
11792: return;
11793: }
11794:
1.1055 raeburn 11795: // ]]>
11796: </script>
11797: END
11798: return $scripttag;
11799: }
11800:
11801: sub process_extracted_files {
1.1067 raeburn 11802: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11803: my $numitems = $env{'form.archive_count'};
11804: return unless ($numitems);
11805: my @ids=&Apache::lonnet::current_machine_ids();
11806: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11807: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11808: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11809: if (grep(/^\Q$docuhome\E$/,@ids)) {
11810: $prefix = &LONCAPA::propath($docudom,$docuname);
11811: $pathtocheck = "$dir_root/$destination";
11812: $dir = $dir_root;
11813: $ishome = 1;
11814: } else {
11815: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11816: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11817: $dir = "$dir_root/$docudom/$docuname";
11818: }
11819: my $currdir = "$dir_root/$destination";
11820: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11821: if ($env{'form.folderpath'}) {
11822: my @items = split('&',$env{'form.folderpath'});
11823: $folders{'0'} = $items[-2];
1.1099 raeburn 11824: if ($env{'form.folderpath'} =~ /\:1$/) {
11825: $containers{'0'}='page';
11826: } else {
11827: $containers{'0'}='sequence';
11828: }
1.1055 raeburn 11829: }
11830: my @archdirs = &get_env_multiple('form.archive_directory');
11831: if ($numitems) {
11832: for (my $i=1; $i<=$numitems; $i++) {
11833: my $path = $env{'form.archive_content_'.$i};
11834: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11835: my $item = $1;
11836: $toplevelitems{$item} = $i;
11837: if (grep(/^\Q$i\E$/,@archdirs)) {
11838: $is_dir{$item} = 1;
11839: }
11840: }
11841: }
11842: }
1.1067 raeburn 11843: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11844: if (keys(%toplevelitems) > 0) {
11845: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11846: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11847: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11848: }
1.1066 raeburn 11849: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11850: if ($numitems) {
11851: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11852: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11853: my $path = $env{'form.archive_content_'.$i};
11854: if ($path =~ /^\Q$pathtocheck\E/) {
11855: if ($env{'form.archive_'.$i} eq 'discard') {
11856: if ($prefix ne '' && $path ne '') {
11857: if (-e $prefix.$path) {
1.1066 raeburn 11858: if ((@archdirs > 0) &&
11859: (grep(/^\Q$i\E$/,@archdirs))) {
11860: $todeletedir{$prefix.$path} = 1;
11861: } else {
11862: $todelete{$prefix.$path} = 1;
11863: }
1.1055 raeburn 11864: }
11865: }
11866: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11867: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11868: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11869: $docstitle = $env{'form.archive_title_'.$i};
11870: if ($docstitle eq '') {
11871: $docstitle = $title;
11872: }
1.1055 raeburn 11873: $outer = 0;
1.1056 raeburn 11874: if (ref($dirorder{$i}) eq 'ARRAY') {
11875: if (@{$dirorder{$i}} > 0) {
11876: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11877: if ($env{'form.archive_'.$item} eq 'display') {
11878: $outer = $item;
11879: last;
11880: }
11881: }
11882: }
11883: }
11884: my ($errtext,$fatal) =
11885: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11886: '/'.$folders{$outer}.'.'.
11887: $containers{$outer});
11888: next if ($fatal);
11889: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11890: if ($context eq 'coursedocs') {
1.1056 raeburn 11891: $mapinner{$i} = time;
1.1055 raeburn 11892: $folders{$i} = 'default_'.$mapinner{$i};
11893: $containers{$i} = 'sequence';
11894: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11895: $folders{$i}.'.'.$containers{$i};
11896: my $newidx = &LONCAPA::map::getresidx();
11897: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11898: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11899: push(@LONCAPA::map::order,$newidx);
11900: my ($outtext,$errtext) =
11901: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11902: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11903: '.'.$containers{$outer},1,1);
1.1056 raeburn 11904: $newseqid{$i} = $newidx;
1.1067 raeburn 11905: unless ($errtext) {
11906: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11907: }
1.1055 raeburn 11908: }
11909: } else {
11910: if ($context eq 'coursedocs') {
11911: my $newidx=&LONCAPA::map::getresidx();
11912: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11913: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11914: $title;
11915: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11916: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11917: }
11918: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11919: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11920: }
11921: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11922: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11923: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11924: unless ($ishome) {
11925: my $fetch = "$newdest{$i}/$title";
11926: $fetch =~ s/^\Q$prefix$dir\E//;
11927: $prompttofetch{$fetch} = 1;
11928: }
1.1055 raeburn 11929: }
11930: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11931: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11932: push(@LONCAPA::map::order, $newidx);
11933: my ($outtext,$errtext)=
11934: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11935: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11936: '.'.$containers{$outer},1,1);
1.1067 raeburn 11937: unless ($errtext) {
11938: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11939: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11940: }
11941: }
1.1055 raeburn 11942: }
11943: }
1.1086 raeburn 11944: }
11945: } else {
11946: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11947: }
11948: }
11949: for (my $i=1; $i<=$numitems; $i++) {
11950: next unless ($env{'form.archive_'.$i} eq 'dependency');
11951: my $path = $env{'form.archive_content_'.$i};
11952: if ($path =~ /^\Q$pathtocheck\E/) {
11953: my ($title) = ($path =~ m{/([^/]+)$});
11954: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11955: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11956: if (ref($dirorder{$i}) eq 'ARRAY') {
11957: my ($itemidx,$fullpath,$relpath);
11958: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11959: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11960: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11961: if ($dirorder{$i}->[$j] eq $container) {
11962: $itemidx = $j;
1.1056 raeburn 11963: }
11964: }
1.1086 raeburn 11965: }
11966: if ($itemidx eq '') {
11967: $itemidx = 0;
11968: }
11969: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11970: if ($mapinner{$referrer{$i}}) {
11971: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11972: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11973: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11974: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11975: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11976: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11977: if (!-e $fullpath) {
11978: mkdir($fullpath,0755);
1.1056 raeburn 11979: }
11980: }
1.1086 raeburn 11981: } else {
11982: last;
1.1056 raeburn 11983: }
1.1086 raeburn 11984: }
11985: }
11986: } elsif ($newdest{$referrer{$i}}) {
11987: $fullpath = $newdest{$referrer{$i}};
11988: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11989: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11990: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11991: last;
11992: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11993: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11994: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11995: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11996: if (!-e $fullpath) {
11997: mkdir($fullpath,0755);
1.1056 raeburn 11998: }
11999: }
1.1086 raeburn 12000: } else {
12001: last;
1.1056 raeburn 12002: }
1.1055 raeburn 12003: }
12004: }
1.1086 raeburn 12005: if ($fullpath ne '') {
12006: if (-e "$prefix$path") {
12007: system("mv $prefix$path $fullpath/$title");
12008: }
12009: if (-e "$fullpath/$title") {
12010: my $showpath;
12011: if ($relpath ne '') {
12012: $showpath = "$relpath/$title";
12013: } else {
12014: $showpath = "/$title";
12015: }
12016: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12017: }
12018: unless ($ishome) {
12019: my $fetch = "$fullpath/$title";
12020: $fetch =~ s/^\Q$prefix$dir\E//;
12021: $prompttofetch{$fetch} = 1;
12022: }
12023: }
1.1055 raeburn 12024: }
1.1086 raeburn 12025: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12026: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12027: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12028: }
12029: } else {
12030: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12031: }
12032: }
12033: if (keys(%todelete)) {
12034: foreach my $key (keys(%todelete)) {
12035: unlink($key);
1.1066 raeburn 12036: }
12037: }
12038: if (keys(%todeletedir)) {
12039: foreach my $key (keys(%todeletedir)) {
12040: rmdir($key);
12041: }
12042: }
12043: foreach my $dir (sort(keys(%is_dir))) {
12044: if (($pathtocheck ne '') && ($dir ne '')) {
12045: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12046: }
12047: }
1.1067 raeburn 12048: if ($result ne '') {
12049: $output .= '<ul>'."\n".
12050: $result."\n".
12051: '</ul>';
12052: }
12053: unless ($ishome) {
12054: my $replicationfail;
12055: foreach my $item (keys(%prompttofetch)) {
12056: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12057: unless ($fetchresult eq 'ok') {
12058: $replicationfail .= '<li>'.$item.'</li>'."\n";
12059: }
12060: }
12061: if ($replicationfail) {
12062: $output .= '<p class="LC_error">'.
12063: &mt('Course home server failed to retrieve:').'<ul>'.
12064: $replicationfail.
12065: '</ul></p>';
12066: }
12067: }
1.1055 raeburn 12068: } else {
12069: $warning = &mt('No items found in archive.');
12070: }
12071: if ($error) {
12072: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12073: $error.'</p>'."\n";
12074: }
12075: if ($warning) {
12076: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12077: }
12078: return $output;
12079: }
12080:
1.1066 raeburn 12081: sub cleanup_empty_dirs {
12082: my ($path) = @_;
12083: if (($path ne '') && (-d $path)) {
12084: if (opendir(my $dirh,$path)) {
12085: my @dircontents = grep(!/^\./,readdir($dirh));
12086: my $numitems = 0;
12087: foreach my $item (@dircontents) {
12088: if (-d "$path/$item") {
1.1111 raeburn 12089: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12090: if (-e "$path/$item") {
12091: $numitems ++;
12092: }
12093: } else {
12094: $numitems ++;
12095: }
12096: }
12097: if ($numitems == 0) {
12098: rmdir($path);
12099: }
12100: closedir($dirh);
12101: }
12102: }
12103: return;
12104: }
12105:
1.41 ng 12106: =pod
1.45 matthew 12107:
1.1162 raeburn 12108: =item * &get_folder_hierarchy()
1.1068 raeburn 12109:
12110: Provides hierarchy of names of folders/sub-folders containing the current
12111: item,
12112:
12113: Inputs: 3
12114: - $navmap - navmaps object
12115:
12116: - $map - url for map (either the trigger itself, or map containing
12117: the resource, which is the trigger).
12118:
12119: - $showitem - 1 => show title for map itself; 0 => do not show.
12120:
12121: Outputs: 1 @pathitems - array of folder/subfolder names.
12122:
12123: =cut
12124:
12125: sub get_folder_hierarchy {
12126: my ($navmap,$map,$showitem) = @_;
12127: my @pathitems;
12128: if (ref($navmap)) {
12129: my $mapres = $navmap->getResourceByUrl($map);
12130: if (ref($mapres)) {
12131: my $pcslist = $mapres->map_hierarchy();
12132: if ($pcslist ne '') {
12133: my @pcs = split(/,/,$pcslist);
12134: foreach my $pc (@pcs) {
12135: if ($pc == 1) {
1.1129 raeburn 12136: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12137: } else {
12138: my $res = $navmap->getByMapPc($pc);
12139: if (ref($res)) {
12140: my $title = $res->compTitle();
12141: $title =~ s/\W+/_/g;
12142: if ($title ne '') {
12143: push(@pathitems,$title);
12144: }
12145: }
12146: }
12147: }
12148: }
1.1071 raeburn 12149: if ($showitem) {
12150: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12151: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12152: } else {
12153: my $maptitle = $mapres->compTitle();
12154: $maptitle =~ s/\W+/_/g;
12155: if ($maptitle ne '') {
12156: push(@pathitems,$maptitle);
12157: }
1.1068 raeburn 12158: }
12159: }
12160: }
12161: }
12162: return @pathitems;
12163: }
12164:
12165: =pod
12166:
1.1015 raeburn 12167: =item * &get_turnedin_filepath()
12168:
12169: Determines path in a user's portfolio file for storage of files uploaded
12170: to a specific essayresponse or dropbox item.
12171:
12172: Inputs: 3 required + 1 optional.
12173: $symb is symb for resource, $uname and $udom are for current user (required).
12174: $caller is optional (can be "submission", if routine is called when storing
12175: an upoaded file when "Submit Answer" button was pressed).
12176:
12177: Returns array containing $path and $multiresp.
12178: $path is path in portfolio. $multiresp is 1 if this resource contains more
12179: than one file upload item. Callers of routine should append partid as a
12180: subdirectory to $path in cases where $multiresp is 1.
12181:
12182: Called by: homework/essayresponse.pm and homework/structuretags.pm
12183:
12184: =cut
12185:
12186: sub get_turnedin_filepath {
12187: my ($symb,$uname,$udom,$caller) = @_;
12188: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12189: my $turnindir;
12190: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12191: $turnindir = $userhash{'turnindir'};
12192: my ($path,$multiresp);
12193: if ($turnindir eq '') {
12194: if ($caller eq 'submission') {
12195: $turnindir = &mt('turned in');
12196: $turnindir =~ s/\W+/_/g;
12197: my %newhash = (
12198: 'turnindir' => $turnindir,
12199: );
12200: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12201: }
12202: }
12203: if ($turnindir ne '') {
12204: $path = '/'.$turnindir.'/';
12205: my ($multipart,$turnin,@pathitems);
12206: my $navmap = Apache::lonnavmaps::navmap->new();
12207: if (defined($navmap)) {
12208: my $mapres = $navmap->getResourceByUrl($map);
12209: if (ref($mapres)) {
12210: my $pcslist = $mapres->map_hierarchy();
12211: if ($pcslist ne '') {
12212: foreach my $pc (split(/,/,$pcslist)) {
12213: my $res = $navmap->getByMapPc($pc);
12214: if (ref($res)) {
12215: my $title = $res->compTitle();
12216: $title =~ s/\W+/_/g;
12217: if ($title ne '') {
1.1149 raeburn 12218: if (($pc > 1) && (length($title) > 12)) {
12219: $title = substr($title,0,12);
12220: }
1.1015 raeburn 12221: push(@pathitems,$title);
12222: }
12223: }
12224: }
12225: }
12226: my $maptitle = $mapres->compTitle();
12227: $maptitle =~ s/\W+/_/g;
12228: if ($maptitle ne '') {
1.1149 raeburn 12229: if (length($maptitle) > 12) {
12230: $maptitle = substr($maptitle,0,12);
12231: }
1.1015 raeburn 12232: push(@pathitems,$maptitle);
12233: }
12234: unless ($env{'request.state'} eq 'construct') {
12235: my $res = $navmap->getBySymb($symb);
12236: if (ref($res)) {
12237: my $partlist = $res->parts();
12238: my $totaluploads = 0;
12239: if (ref($partlist) eq 'ARRAY') {
12240: foreach my $part (@{$partlist}) {
12241: my @types = $res->responseType($part);
12242: my @ids = $res->responseIds($part);
12243: for (my $i=0; $i < scalar(@ids); $i++) {
12244: if ($types[$i] eq 'essay') {
12245: my $partid = $part.'_'.$ids[$i];
12246: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12247: $totaluploads ++;
12248: }
12249: }
12250: }
12251: }
12252: if ($totaluploads > 1) {
12253: $multiresp = 1;
12254: }
12255: }
12256: }
12257: }
12258: } else {
12259: return;
12260: }
12261: } else {
12262: return;
12263: }
12264: my $restitle=&Apache::lonnet::gettitle($symb);
12265: $restitle =~ s/\W+/_/g;
12266: if ($restitle eq '') {
12267: $restitle = ($resurl =~ m{/[^/]+$});
12268: if ($restitle eq '') {
12269: $restitle = time;
12270: }
12271: }
1.1149 raeburn 12272: if (length($restitle) > 12) {
12273: $restitle = substr($restitle,0,12);
12274: }
1.1015 raeburn 12275: push(@pathitems,$restitle);
12276: $path .= join('/',@pathitems);
12277: }
12278: return ($path,$multiresp);
12279: }
12280:
12281: =pod
12282:
1.464 albertel 12283: =back
1.41 ng 12284:
1.112 bowersj2 12285: =head1 CSV Upload/Handling functions
1.38 albertel 12286:
1.41 ng 12287: =over 4
12288:
1.648 raeburn 12289: =item * &upfile_store($r)
1.41 ng 12290:
12291: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12292: needs $env{'form.upfile'}
1.41 ng 12293: returns $datatoken to be put into hidden field
12294:
12295: =cut
1.31 albertel 12296:
12297: sub upfile_store {
12298: my $r=shift;
1.258 albertel 12299: $env{'form.upfile'}=~s/\r/\n/gs;
12300: $env{'form.upfile'}=~s/\f/\n/gs;
12301: $env{'form.upfile'}=~s/\n+/\n/gs;
12302: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12303:
1.258 albertel 12304: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12305: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12306: {
1.158 raeburn 12307: my $datafile = $r->dir_config('lonDaemons').
12308: '/tmp/'.$datatoken.'.tmp';
12309: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12310: print $fh $env{'form.upfile'};
1.158 raeburn 12311: close($fh);
12312: }
1.31 albertel 12313: }
12314: return $datatoken;
12315: }
12316:
1.56 matthew 12317: =pod
12318:
1.648 raeburn 12319: =item * &load_tmp_file($r)
1.41 ng 12320:
12321: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12322: needs $env{'form.datatoken'},
12323: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12324:
12325: =cut
1.31 albertel 12326:
12327: sub load_tmp_file {
12328: my $r=shift;
12329: my @studentdata=();
12330: {
1.158 raeburn 12331: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12332: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12333: if ( open(my $fh,"<$studentfile") ) {
12334: @studentdata=<$fh>;
12335: close($fh);
12336: }
1.31 albertel 12337: }
1.258 albertel 12338: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12339: }
12340:
1.56 matthew 12341: =pod
12342:
1.648 raeburn 12343: =item * &upfile_record_sep()
1.41 ng 12344:
12345: Separate uploaded file into records
12346: returns array of records,
1.258 albertel 12347: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12348:
12349: =cut
1.31 albertel 12350:
12351: sub upfile_record_sep {
1.258 albertel 12352: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12353: } else {
1.248 albertel 12354: my @records;
1.258 albertel 12355: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12356: if ($line=~/^\s*$/) { next; }
12357: push(@records,$line);
12358: }
12359: return @records;
1.31 albertel 12360: }
12361: }
12362:
1.56 matthew 12363: =pod
12364:
1.648 raeburn 12365: =item * &record_sep($record)
1.41 ng 12366:
1.258 albertel 12367: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12368:
12369: =cut
12370:
1.263 www 12371: sub takeleft {
12372: my $index=shift;
12373: return substr('0000'.$index,-4,4);
12374: }
12375:
1.31 albertel 12376: sub record_sep {
12377: my $record=shift;
12378: my %components=();
1.258 albertel 12379: if ($env{'form.upfiletype'} eq 'xml') {
12380: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12381: my $i=0;
1.356 albertel 12382: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12383: $field=~s/^(\"|\')//;
12384: $field=~s/(\"|\')$//;
1.263 www 12385: $components{&takeleft($i)}=$field;
1.31 albertel 12386: $i++;
12387: }
1.258 albertel 12388: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12389: my $i=0;
1.356 albertel 12390: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12391: $field=~s/^(\"|\')//;
12392: $field=~s/(\"|\')$//;
1.263 www 12393: $components{&takeleft($i)}=$field;
1.31 albertel 12394: $i++;
12395: }
12396: } else {
1.561 www 12397: my $separator=',';
1.480 banghart 12398: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12399: $separator=';';
1.480 banghart 12400: }
1.31 albertel 12401: my $i=0;
1.561 www 12402: # the character we are looking for to indicate the end of a quote or a record
12403: my $looking_for=$separator;
12404: # do not add the characters to the fields
12405: my $ignore=0;
12406: # we just encountered a separator (or the beginning of the record)
12407: my $just_found_separator=1;
12408: # store the field we are working on here
12409: my $field='';
12410: # work our way through all characters in record
12411: foreach my $character ($record=~/(.)/g) {
12412: if ($character eq $looking_for) {
12413: if ($character ne $separator) {
12414: # Found the end of a quote, again looking for separator
12415: $looking_for=$separator;
12416: $ignore=1;
12417: } else {
12418: # Found a separator, store away what we got
12419: $components{&takeleft($i)}=$field;
12420: $i++;
12421: $just_found_separator=1;
12422: $ignore=0;
12423: $field='';
12424: }
12425: next;
12426: }
12427: # single or double quotation marks after a separator indicate beginning of a quote
12428: # we are now looking for the end of the quote and need to ignore separators
12429: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12430: $looking_for=$character;
12431: next;
12432: }
12433: # ignore would be true after we reached the end of a quote
12434: if ($ignore) { next; }
12435: if (($just_found_separator) && ($character=~/\s/)) { next; }
12436: $field.=$character;
12437: $just_found_separator=0;
1.31 albertel 12438: }
1.561 www 12439: # catch the very last entry, since we never encountered the separator
12440: $components{&takeleft($i)}=$field;
1.31 albertel 12441: }
12442: return %components;
12443: }
12444:
1.144 matthew 12445: ######################################################
12446: ######################################################
12447:
1.56 matthew 12448: =pod
12449:
1.648 raeburn 12450: =item * &upfile_select_html()
1.41 ng 12451:
1.144 matthew 12452: Return HTML code to select a file from the users machine and specify
12453: the file type.
1.41 ng 12454:
12455: =cut
12456:
1.144 matthew 12457: ######################################################
12458: ######################################################
1.31 albertel 12459: sub upfile_select_html {
1.144 matthew 12460: my %Types = (
12461: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12462: semisv => &mt('Semicolon separated values'),
1.144 matthew 12463: space => &mt('Space separated'),
12464: tab => &mt('Tabulator separated'),
12465: # xml => &mt('HTML/XML'),
12466: );
12467: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12468: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12469: foreach my $type (sort(keys(%Types))) {
12470: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12471: }
12472: $Str .= "</select>\n";
12473: return $Str;
1.31 albertel 12474: }
12475:
1.301 albertel 12476: sub get_samples {
12477: my ($records,$toget) = @_;
12478: my @samples=({});
12479: my $got=0;
12480: foreach my $rec (@$records) {
12481: my %temp = &record_sep($rec);
12482: if (! grep(/\S/, values(%temp))) { next; }
12483: if (%temp) {
12484: $samples[$got]=\%temp;
12485: $got++;
12486: if ($got == $toget) { last; }
12487: }
12488: }
12489: return \@samples;
12490: }
12491:
1.144 matthew 12492: ######################################################
12493: ######################################################
12494:
1.56 matthew 12495: =pod
12496:
1.648 raeburn 12497: =item * &csv_print_samples($r,$records)
1.41 ng 12498:
12499: Prints a table of sample values from each column uploaded $r is an
12500: Apache Request ref, $records is an arrayref from
12501: &Apache::loncommon::upfile_record_sep
12502:
12503: =cut
12504:
1.144 matthew 12505: ######################################################
12506: ######################################################
1.31 albertel 12507: sub csv_print_samples {
12508: my ($r,$records) = @_;
1.662 bisitz 12509: my $samples = &get_samples($records,5);
1.301 albertel 12510:
1.594 raeburn 12511: $r->print(&mt('Samples').'<br />'.&start_data_table().
12512: &start_data_table_header_row());
1.356 albertel 12513: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12514: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12515: $r->print(&end_data_table_header_row());
1.301 albertel 12516: foreach my $hash (@$samples) {
1.594 raeburn 12517: $r->print(&start_data_table_row());
1.356 albertel 12518: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12519: $r->print('<td>');
1.356 albertel 12520: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12521: $r->print('</td>');
12522: }
1.594 raeburn 12523: $r->print(&end_data_table_row());
1.31 albertel 12524: }
1.594 raeburn 12525: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12526: }
12527:
1.144 matthew 12528: ######################################################
12529: ######################################################
12530:
1.56 matthew 12531: =pod
12532:
1.648 raeburn 12533: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12534:
12535: Prints a table to create associations between values and table columns.
1.144 matthew 12536:
1.41 ng 12537: $r is an Apache Request ref,
12538: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12539: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12540:
12541: =cut
12542:
1.144 matthew 12543: ######################################################
12544: ######################################################
1.31 albertel 12545: sub csv_print_select_table {
12546: my ($r,$records,$d) = @_;
1.301 albertel 12547: my $i=0;
12548: my $samples = &get_samples($records,1);
1.144 matthew 12549: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12550: &start_data_table().&start_data_table_header_row().
1.144 matthew 12551: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12552: '<th>'.&mt('Column').'</th>'.
12553: &end_data_table_header_row()."\n");
1.356 albertel 12554: foreach my $array_ref (@$d) {
12555: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12556: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12557:
1.875 bisitz 12558: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12559: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12560: $r->print('<option value="none"></option>');
1.356 albertel 12561: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12562: $r->print('<option value="'.$sample.'"'.
12563: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12564: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12565: }
1.594 raeburn 12566: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12567: $i++;
12568: }
1.594 raeburn 12569: $r->print(&end_data_table());
1.31 albertel 12570: $i--;
12571: return $i;
12572: }
1.56 matthew 12573:
1.144 matthew 12574: ######################################################
12575: ######################################################
12576:
1.56 matthew 12577: =pod
1.31 albertel 12578:
1.648 raeburn 12579: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12580:
12581: Prints a table of sample values from the upload and can make associate samples to internal names.
12582:
12583: $r is an Apache Request ref,
12584: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12585: $d is an array of 2 element arrays (internal name, displayed name)
12586:
12587: =cut
12588:
1.144 matthew 12589: ######################################################
12590: ######################################################
1.31 albertel 12591: sub csv_samples_select_table {
12592: my ($r,$records,$d) = @_;
12593: my $i=0;
1.144 matthew 12594: #
1.662 bisitz 12595: my $max_samples = 5;
12596: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12597: $r->print(&start_data_table().
12598: &start_data_table_header_row().'<th>'.
12599: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12600: &end_data_table_header_row());
1.301 albertel 12601:
12602: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12603: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12604: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12605: foreach my $option (@$d) {
12606: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12607: $r->print('<option value="'.$value.'"'.
1.253 albertel 12608: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12609: $display.'</option>');
1.31 albertel 12610: }
12611: $r->print('</select></td><td>');
1.662 bisitz 12612: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12613: if (defined($samples->[$line]{$key})) {
12614: $r->print($samples->[$line]{$key}."<br />\n");
12615: }
12616: }
1.594 raeburn 12617: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12618: $i++;
12619: }
1.594 raeburn 12620: $r->print(&end_data_table());
1.31 albertel 12621: $i--;
12622: return($i);
1.115 matthew 12623: }
12624:
1.144 matthew 12625: ######################################################
12626: ######################################################
12627:
1.115 matthew 12628: =pod
12629:
1.648 raeburn 12630: =item * &clean_excel_name($name)
1.115 matthew 12631:
12632: Returns a replacement for $name which does not contain any illegal characters.
12633:
12634: =cut
12635:
1.144 matthew 12636: ######################################################
12637: ######################################################
1.115 matthew 12638: sub clean_excel_name {
12639: my ($name) = @_;
12640: $name =~ s/[:\*\?\/\\]//g;
12641: if (length($name) > 31) {
12642: $name = substr($name,0,31);
12643: }
12644: return $name;
1.25 albertel 12645: }
1.84 albertel 12646:
1.85 albertel 12647: =pod
12648:
1.648 raeburn 12649: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12650:
12651: Returns either 1 or undef
12652:
12653: 1 if the part is to be hidden, undef if it is to be shown
12654:
12655: Arguments are:
12656:
12657: $id the id of the part to be checked
12658: $symb, optional the symb of the resource to check
12659: $udom, optional the domain of the user to check for
12660: $uname, optional the username of the user to check for
12661:
12662: =cut
1.84 albertel 12663:
12664: sub check_if_partid_hidden {
12665: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12666: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12667: $symb,$udom,$uname);
1.141 albertel 12668: my $truth=1;
12669: #if the string starts with !, then the list is the list to show not hide
12670: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12671: my @hiddenlist=split(/,/,$hiddenparts);
12672: foreach my $checkid (@hiddenlist) {
1.141 albertel 12673: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12674: }
1.141 albertel 12675: return !$truth;
1.84 albertel 12676: }
1.127 matthew 12677:
1.138 matthew 12678:
12679: ############################################################
12680: ############################################################
12681:
12682: =pod
12683:
1.157 matthew 12684: =back
12685:
1.138 matthew 12686: =head1 cgi-bin script and graphing routines
12687:
1.157 matthew 12688: =over 4
12689:
1.648 raeburn 12690: =item * &get_cgi_id()
1.138 matthew 12691:
12692: Inputs: none
12693:
12694: Returns an id which can be used to pass environment variables
12695: to various cgi-bin scripts. These environment variables will
12696: be removed from the users environment after a given time by
12697: the routine &Apache::lonnet::transfer_profile_to_env.
12698:
12699: =cut
12700:
12701: ############################################################
12702: ############################################################
1.152 albertel 12703: my $uniq=0;
1.136 matthew 12704: sub get_cgi_id {
1.154 albertel 12705: $uniq=($uniq+1)%100000;
1.280 albertel 12706: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12707: }
12708:
1.127 matthew 12709: ############################################################
12710: ############################################################
12711:
12712: =pod
12713:
1.648 raeburn 12714: =item * &DrawBarGraph()
1.127 matthew 12715:
1.138 matthew 12716: Facilitates the plotting of data in a (stacked) bar graph.
12717: Puts plot definition data into the users environment in order for
12718: graph.png to plot it. Returns an <img> tag for the plot.
12719: The bars on the plot are labeled '1','2',...,'n'.
12720:
12721: Inputs:
12722:
12723: =over 4
12724:
12725: =item $Title: string, the title of the plot
12726:
12727: =item $xlabel: string, text describing the X-axis of the plot
12728:
12729: =item $ylabel: string, text describing the Y-axis of the plot
12730:
12731: =item $Max: scalar, the maximum Y value to use in the plot
12732: If $Max is < any data point, the graph will not be rendered.
12733:
1.140 matthew 12734: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12735: they are plotted. If undefined, default values will be used.
12736:
1.178 matthew 12737: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12738:
1.138 matthew 12739: =item @Values: An array of array references. Each array reference holds data
12740: to be plotted in a stacked bar chart.
12741:
1.239 matthew 12742: =item If the final element of @Values is a hash reference the key/value
12743: pairs will be added to the graph definition.
12744:
1.138 matthew 12745: =back
12746:
12747: Returns:
12748:
12749: An <img> tag which references graph.png and the appropriate identifying
12750: information for the plot.
12751:
1.127 matthew 12752: =cut
12753:
12754: ############################################################
12755: ############################################################
1.134 matthew 12756: sub DrawBarGraph {
1.178 matthew 12757: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12758: #
12759: if (! defined($colors)) {
12760: $colors = ['#33ff00',
12761: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12762: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12763: ];
12764: }
1.228 matthew 12765: my $extra_settings = {};
12766: if (ref($Values[-1]) eq 'HASH') {
12767: $extra_settings = pop(@Values);
12768: }
1.127 matthew 12769: #
1.136 matthew 12770: my $identifier = &get_cgi_id();
12771: my $id = 'cgi.'.$identifier;
1.129 matthew 12772: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12773: return '';
12774: }
1.225 matthew 12775: #
12776: my @Labels;
12777: if (defined($labels)) {
12778: @Labels = @$labels;
12779: } else {
12780: for (my $i=0;$i<@{$Values[0]};$i++) {
12781: push (@Labels,$i+1);
12782: }
12783: }
12784: #
1.129 matthew 12785: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12786: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12787: my %ValuesHash;
12788: my $NumSets=1;
12789: foreach my $array (@Values) {
12790: next if (! ref($array));
1.136 matthew 12791: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12792: join(',',@$array);
1.129 matthew 12793: }
1.127 matthew 12794: #
1.136 matthew 12795: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12796: if ($NumBars < 3) {
12797: $width = 120+$NumBars*32;
1.220 matthew 12798: $xskip = 1;
1.225 matthew 12799: $bar_width = 30;
12800: } elsif ($NumBars < 5) {
12801: $width = 120+$NumBars*20;
12802: $xskip = 1;
12803: $bar_width = 20;
1.220 matthew 12804: } elsif ($NumBars < 10) {
1.136 matthew 12805: $width = 120+$NumBars*15;
12806: $xskip = 1;
12807: $bar_width = 15;
12808: } elsif ($NumBars <= 25) {
12809: $width = 120+$NumBars*11;
12810: $xskip = 5;
12811: $bar_width = 8;
12812: } elsif ($NumBars <= 50) {
12813: $width = 120+$NumBars*8;
12814: $xskip = 5;
12815: $bar_width = 4;
12816: } else {
12817: $width = 120+$NumBars*8;
12818: $xskip = 5;
12819: $bar_width = 4;
12820: }
12821: #
1.137 matthew 12822: $Max = 1 if ($Max < 1);
12823: if ( int($Max) < $Max ) {
12824: $Max++;
12825: $Max = int($Max);
12826: }
1.127 matthew 12827: $Title = '' if (! defined($Title));
12828: $xlabel = '' if (! defined($xlabel));
12829: $ylabel = '' if (! defined($ylabel));
1.369 www 12830: $ValuesHash{$id.'.title'} = &escape($Title);
12831: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12832: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12833: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12834: $ValuesHash{$id.'.NumBars'} = $NumBars;
12835: $ValuesHash{$id.'.NumSets'} = $NumSets;
12836: $ValuesHash{$id.'.PlotType'} = 'bar';
12837: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12838: $ValuesHash{$id.'.height'} = $height;
12839: $ValuesHash{$id.'.width'} = $width;
12840: $ValuesHash{$id.'.xskip'} = $xskip;
12841: $ValuesHash{$id.'.bar_width'} = $bar_width;
12842: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12843: #
1.228 matthew 12844: # Deal with other parameters
12845: while (my ($key,$value) = each(%$extra_settings)) {
12846: $ValuesHash{$id.'.'.$key} = $value;
12847: }
12848: #
1.646 raeburn 12849: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12850: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12851: }
12852:
12853: ############################################################
12854: ############################################################
12855:
12856: =pod
12857:
1.648 raeburn 12858: =item * &DrawXYGraph()
1.137 matthew 12859:
1.138 matthew 12860: Facilitates the plotting of data in an XY graph.
12861: Puts plot definition data into the users environment in order for
12862: graph.png to plot it. Returns an <img> tag for the plot.
12863:
12864: Inputs:
12865:
12866: =over 4
12867:
12868: =item $Title: string, the title of the plot
12869:
12870: =item $xlabel: string, text describing the X-axis of the plot
12871:
12872: =item $ylabel: string, text describing the Y-axis of the plot
12873:
12874: =item $Max: scalar, the maximum Y value to use in the plot
12875: If $Max is < any data point, the graph will not be rendered.
12876:
12877: =item $colors: Array ref containing the hex color codes for the data to be
12878: plotted in. If undefined, default values will be used.
12879:
12880: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12881:
12882: =item $Ydata: Array ref containing Array refs.
1.185 www 12883: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12884:
12885: =item %Values: hash indicating or overriding any default values which are
12886: passed to graph.png.
12887: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12888:
12889: =back
12890:
12891: Returns:
12892:
12893: An <img> tag which references graph.png and the appropriate identifying
12894: information for the plot.
12895:
1.137 matthew 12896: =cut
12897:
12898: ############################################################
12899: ############################################################
12900: sub DrawXYGraph {
12901: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12902: #
12903: # Create the identifier for the graph
12904: my $identifier = &get_cgi_id();
12905: my $id = 'cgi.'.$identifier;
12906: #
12907: $Title = '' if (! defined($Title));
12908: $xlabel = '' if (! defined($xlabel));
12909: $ylabel = '' if (! defined($ylabel));
12910: my %ValuesHash =
12911: (
1.369 www 12912: $id.'.title' => &escape($Title),
12913: $id.'.xlabel' => &escape($xlabel),
12914: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12915: $id.'.y_max_value'=> $Max,
12916: $id.'.labels' => join(',',@$Xlabels),
12917: $id.'.PlotType' => 'XY',
12918: );
12919: #
12920: if (defined($colors) && ref($colors) eq 'ARRAY') {
12921: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12922: }
12923: #
12924: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12925: return '';
12926: }
12927: my $NumSets=1;
1.138 matthew 12928: foreach my $array (@{$Ydata}){
1.137 matthew 12929: next if (! ref($array));
12930: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12931: }
1.138 matthew 12932: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12933: #
12934: # Deal with other parameters
12935: while (my ($key,$value) = each(%Values)) {
12936: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12937: }
12938: #
1.646 raeburn 12939: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12940: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12941: }
12942:
12943: ############################################################
12944: ############################################################
12945:
12946: =pod
12947:
1.648 raeburn 12948: =item * &DrawXYYGraph()
1.138 matthew 12949:
12950: Facilitates the plotting of data in an XY graph with two Y axes.
12951: Puts plot definition data into the users environment in order for
12952: graph.png to plot it. Returns an <img> tag for the plot.
12953:
12954: Inputs:
12955:
12956: =over 4
12957:
12958: =item $Title: string, the title of the plot
12959:
12960: =item $xlabel: string, text describing the X-axis of the plot
12961:
12962: =item $ylabel: string, text describing the Y-axis of the plot
12963:
12964: =item $colors: Array ref containing the hex color codes for the data to be
12965: plotted in. If undefined, default values will be used.
12966:
12967: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12968:
12969: =item $Ydata1: The first data set
12970:
12971: =item $Min1: The minimum value of the left Y-axis
12972:
12973: =item $Max1: The maximum value of the left Y-axis
12974:
12975: =item $Ydata2: The second data set
12976:
12977: =item $Min2: The minimum value of the right Y-axis
12978:
12979: =item $Max2: The maximum value of the left Y-axis
12980:
12981: =item %Values: hash indicating or overriding any default values which are
12982: passed to graph.png.
12983: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12984:
12985: =back
12986:
12987: Returns:
12988:
12989: An <img> tag which references graph.png and the appropriate identifying
12990: information for the plot.
1.136 matthew 12991:
12992: =cut
12993:
12994: ############################################################
12995: ############################################################
1.137 matthew 12996: sub DrawXYYGraph {
12997: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12998: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12999: #
13000: # Create the identifier for the graph
13001: my $identifier = &get_cgi_id();
13002: my $id = 'cgi.'.$identifier;
13003: #
13004: $Title = '' if (! defined($Title));
13005: $xlabel = '' if (! defined($xlabel));
13006: $ylabel = '' if (! defined($ylabel));
13007: my %ValuesHash =
13008: (
1.369 www 13009: $id.'.title' => &escape($Title),
13010: $id.'.xlabel' => &escape($xlabel),
13011: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13012: $id.'.labels' => join(',',@$Xlabels),
13013: $id.'.PlotType' => 'XY',
13014: $id.'.NumSets' => 2,
1.137 matthew 13015: $id.'.two_axes' => 1,
13016: $id.'.y1_max_value' => $Max1,
13017: $id.'.y1_min_value' => $Min1,
13018: $id.'.y2_max_value' => $Max2,
13019: $id.'.y2_min_value' => $Min2,
1.136 matthew 13020: );
13021: #
1.137 matthew 13022: if (defined($colors) && ref($colors) eq 'ARRAY') {
13023: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13024: }
13025: #
13026: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13027: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13028: return '';
13029: }
13030: my $NumSets=1;
1.137 matthew 13031: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13032: next if (! ref($array));
13033: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13034: }
13035: #
13036: # Deal with other parameters
13037: while (my ($key,$value) = each(%Values)) {
13038: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13039: }
13040: #
1.646 raeburn 13041: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13042: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13043: }
13044:
13045: ############################################################
13046: ############################################################
13047:
13048: =pod
13049:
1.157 matthew 13050: =back
13051:
1.139 matthew 13052: =head1 Statistics helper routines?
13053:
13054: Bad place for them but what the hell.
13055:
1.157 matthew 13056: =over 4
13057:
1.648 raeburn 13058: =item * &chartlink()
1.139 matthew 13059:
13060: Returns a link to the chart for a specific student.
13061:
13062: Inputs:
13063:
13064: =over 4
13065:
13066: =item $linktext: The text of the link
13067:
13068: =item $sname: The students username
13069:
13070: =item $sdomain: The students domain
13071:
13072: =back
13073:
1.157 matthew 13074: =back
13075:
1.139 matthew 13076: =cut
13077:
13078: ############################################################
13079: ############################################################
13080: sub chartlink {
13081: my ($linktext, $sname, $sdomain) = @_;
13082: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13083: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13084: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13085: '">'.$linktext.'</a>';
1.153 matthew 13086: }
13087:
13088: #######################################################
13089: #######################################################
13090:
13091: =pod
13092:
13093: =head1 Course Environment Routines
1.157 matthew 13094:
13095: =over 4
1.153 matthew 13096:
1.648 raeburn 13097: =item * &restore_course_settings()
1.153 matthew 13098:
1.648 raeburn 13099: =item * &store_course_settings()
1.153 matthew 13100:
13101: Restores/Store indicated form parameters from the course environment.
13102: Will not overwrite existing values of the form parameters.
13103:
13104: Inputs:
13105: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13106:
13107: a hash ref describing the data to be stored. For example:
13108:
13109: %Save_Parameters = ('Status' => 'scalar',
13110: 'chartoutputmode' => 'scalar',
13111: 'chartoutputdata' => 'scalar',
13112: 'Section' => 'array',
1.373 raeburn 13113: 'Group' => 'array',
1.153 matthew 13114: 'StudentData' => 'array',
13115: 'Maps' => 'array');
13116:
13117: Returns: both routines return nothing
13118:
1.631 raeburn 13119: =back
13120:
1.153 matthew 13121: =cut
13122:
13123: #######################################################
13124: #######################################################
13125: sub store_course_settings {
1.496 albertel 13126: return &store_settings($env{'request.course.id'},@_);
13127: }
13128:
13129: sub store_settings {
1.153 matthew 13130: # save to the environment
13131: # appenv the same items, just to be safe
1.300 albertel 13132: my $udom = $env{'user.domain'};
13133: my $uname = $env{'user.name'};
1.496 albertel 13134: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13135: my %SaveHash;
13136: my %AppHash;
13137: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13138: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13139: my $envname = 'environment.'.$basename;
1.258 albertel 13140: if (exists($env{'form.'.$setting})) {
1.153 matthew 13141: # Save this value away
13142: if ($type eq 'scalar' &&
1.258 albertel 13143: (! exists($env{$envname}) ||
13144: $env{$envname} ne $env{'form.'.$setting})) {
13145: $SaveHash{$basename} = $env{'form.'.$setting};
13146: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13147: } elsif ($type eq 'array') {
13148: my $stored_form;
1.258 albertel 13149: if (ref($env{'form.'.$setting})) {
1.153 matthew 13150: $stored_form = join(',',
13151: map {
1.369 www 13152: &escape($_);
1.258 albertel 13153: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13154: } else {
13155: $stored_form =
1.369 www 13156: &escape($env{'form.'.$setting});
1.153 matthew 13157: }
13158: # Determine if the array contents are the same.
1.258 albertel 13159: if ($stored_form ne $env{$envname}) {
1.153 matthew 13160: $SaveHash{$basename} = $stored_form;
13161: $AppHash{$envname} = $stored_form;
13162: }
13163: }
13164: }
13165: }
13166: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13167: $udom,$uname);
1.153 matthew 13168: if ($put_result !~ /^(ok|delayed)/) {
13169: &Apache::lonnet::logthis('unable to save form parameters, '.
13170: 'got error:'.$put_result);
13171: }
13172: # Make sure these settings stick around in this session, too
1.646 raeburn 13173: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13174: return;
13175: }
13176:
13177: sub restore_course_settings {
1.499 albertel 13178: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13179: }
13180:
13181: sub restore_settings {
13182: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13183: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13184: next if (exists($env{'form.'.$setting}));
1.496 albertel 13185: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13186: '.'.$setting;
1.258 albertel 13187: if (exists($env{$envname})) {
1.153 matthew 13188: if ($type eq 'scalar') {
1.258 albertel 13189: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13190: } elsif ($type eq 'array') {
1.258 albertel 13191: $env{'form.'.$setting} = [
1.153 matthew 13192: map {
1.369 www 13193: &unescape($_);
1.258 albertel 13194: } split(',',$env{$envname})
1.153 matthew 13195: ];
13196: }
13197: }
13198: }
1.127 matthew 13199: }
13200:
1.618 raeburn 13201: #######################################################
13202: #######################################################
13203:
13204: =pod
13205:
13206: =head1 Domain E-mail Routines
13207:
13208: =over 4
13209:
1.648 raeburn 13210: =item * &build_recipient_list()
1.618 raeburn 13211:
1.1144 raeburn 13212: Build recipient lists for following types of e-mail:
1.766 raeburn 13213: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13214: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13215: module change checking, student/employee ID conflict checks, as
13216: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13217: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13218:
13219: Inputs:
1.619 raeburn 13220: defmail (scalar - email address of default recipient),
1.1144 raeburn 13221: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13222: requestsmail, updatesmail, or idconflictsmail).
13223:
1.619 raeburn 13224: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13225:
1.619 raeburn 13226: origmail (scalar - email address of recipient from loncapa.conf,
13227: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13228:
1.655 raeburn 13229: Returns: comma separated list of addresses to which to send e-mail.
13230:
13231: =back
1.618 raeburn 13232:
13233: =cut
13234:
13235: ############################################################
13236: ############################################################
13237: sub build_recipient_list {
1.619 raeburn 13238: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13239: my @recipients;
13240: my $otheremails;
13241: my %domconfig =
13242: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13243: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13244: if (exists($domconfig{'contacts'}{$mailing})) {
13245: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13246: my @contacts = ('adminemail','supportemail');
13247: foreach my $item (@contacts) {
13248: if ($domconfig{'contacts'}{$mailing}{$item}) {
13249: my $addr = $domconfig{'contacts'}{$item};
13250: if (!grep(/^\Q$addr\E$/,@recipients)) {
13251: push(@recipients,$addr);
13252: }
1.619 raeburn 13253: }
1.766 raeburn 13254: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13255: }
13256: }
1.766 raeburn 13257: } elsif ($origmail ne '') {
13258: push(@recipients,$origmail);
1.618 raeburn 13259: }
1.619 raeburn 13260: } elsif ($origmail ne '') {
13261: push(@recipients,$origmail);
1.618 raeburn 13262: }
1.688 raeburn 13263: if (defined($defmail)) {
13264: if ($defmail ne '') {
13265: push(@recipients,$defmail);
13266: }
1.618 raeburn 13267: }
13268: if ($otheremails) {
1.619 raeburn 13269: my @others;
13270: if ($otheremails =~ /,/) {
13271: @others = split(/,/,$otheremails);
1.618 raeburn 13272: } else {
1.619 raeburn 13273: push(@others,$otheremails);
13274: }
13275: foreach my $addr (@others) {
13276: if (!grep(/^\Q$addr\E$/,@recipients)) {
13277: push(@recipients,$addr);
13278: }
1.618 raeburn 13279: }
13280: }
1.619 raeburn 13281: my $recipientlist = join(',',@recipients);
1.618 raeburn 13282: return $recipientlist;
13283: }
13284:
1.127 matthew 13285: ############################################################
13286: ############################################################
1.154 albertel 13287:
1.655 raeburn 13288: =pod
13289:
13290: =head1 Course Catalog Routines
13291:
13292: =over 4
13293:
13294: =item * &gather_categories()
13295:
13296: Converts category definitions - keys of categories hash stored in
13297: coursecategories in configuration.db on the primary library server in a
13298: domain - to an array. Also generates javascript and idx hash used to
13299: generate Domain Coordinator interface for editing Course Categories.
13300:
13301: Inputs:
1.663 raeburn 13302:
1.655 raeburn 13303: categories (reference to hash of category definitions).
1.663 raeburn 13304:
1.655 raeburn 13305: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13306: categories and subcategories).
1.663 raeburn 13307:
1.655 raeburn 13308: idx (reference to hash of counters used in Domain Coordinator interface for
13309: editing Course Categories).
1.663 raeburn 13310:
1.655 raeburn 13311: jsarray (reference to array of categories used to create Javascript arrays for
13312: Domain Coordinator interface for editing Course Categories).
13313:
13314: Returns: nothing
13315:
13316: Side effects: populates cats, idx and jsarray.
13317:
13318: =cut
13319:
13320: sub gather_categories {
13321: my ($categories,$cats,$idx,$jsarray) = @_;
13322: my %counters;
13323: my $num = 0;
13324: foreach my $item (keys(%{$categories})) {
13325: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13326: if ($container eq '' && $depth == 0) {
13327: $cats->[$depth][$categories->{$item}] = $cat;
13328: } else {
13329: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13330: }
13331: my ($escitem,$tail) = split(/:/,$item,2);
13332: if ($counters{$tail} eq '') {
13333: $counters{$tail} = $num;
13334: $num ++;
13335: }
13336: if (ref($idx) eq 'HASH') {
13337: $idx->{$item} = $counters{$tail};
13338: }
13339: if (ref($jsarray) eq 'ARRAY') {
13340: push(@{$jsarray->[$counters{$tail}]},$item);
13341: }
13342: }
13343: return;
13344: }
13345:
13346: =pod
13347:
13348: =item * &extract_categories()
13349:
13350: Used to generate breadcrumb trails for course categories.
13351:
13352: Inputs:
1.663 raeburn 13353:
1.655 raeburn 13354: categories (reference to hash of category definitions).
1.663 raeburn 13355:
1.655 raeburn 13356: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13357: categories and subcategories).
1.663 raeburn 13358:
1.655 raeburn 13359: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13360:
1.655 raeburn 13361: allitems (reference to hash - key is category key
13362: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13363:
1.655 raeburn 13364: idx (reference to hash of counters used in Domain Coordinator interface for
13365: editing Course Categories).
1.663 raeburn 13366:
1.655 raeburn 13367: jsarray (reference to array of categories used to create Javascript arrays for
13368: Domain Coordinator interface for editing Course Categories).
13369:
1.665 raeburn 13370: subcats (reference to hash of arrays containing all subcategories within each
13371: category, -recursive)
13372:
1.655 raeburn 13373: Returns: nothing
13374:
13375: Side effects: populates trails and allitems hash references.
13376:
13377: =cut
13378:
13379: sub extract_categories {
1.665 raeburn 13380: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13381: if (ref($categories) eq 'HASH') {
13382: &gather_categories($categories,$cats,$idx,$jsarray);
13383: if (ref($cats->[0]) eq 'ARRAY') {
13384: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13385: my $name = $cats->[0][$i];
13386: my $item = &escape($name).'::0';
13387: my $trailstr;
13388: if ($name eq 'instcode') {
13389: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13390: } elsif ($name eq 'communities') {
13391: $trailstr = &mt('Communities');
1.655 raeburn 13392: } else {
13393: $trailstr = $name;
13394: }
13395: if ($allitems->{$item} eq '') {
13396: push(@{$trails},$trailstr);
13397: $allitems->{$item} = scalar(@{$trails})-1;
13398: }
13399: my @parents = ($name);
13400: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13401: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13402: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13403: if (ref($subcats) eq 'HASH') {
13404: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13405: }
13406: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13407: }
13408: } else {
13409: if (ref($subcats) eq 'HASH') {
13410: $subcats->{$item} = [];
1.655 raeburn 13411: }
13412: }
13413: }
13414: }
13415: }
13416: return;
13417: }
13418:
13419: =pod
13420:
1.1162 raeburn 13421: =item * &recurse_categories()
1.655 raeburn 13422:
13423: Recursively used to generate breadcrumb trails for course categories.
13424:
13425: Inputs:
1.663 raeburn 13426:
1.655 raeburn 13427: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13428: categories and subcategories).
1.663 raeburn 13429:
1.655 raeburn 13430: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13431:
13432: category (current course category, for which breadcrumb trail is being generated).
13433:
13434: trails (reference to array of breadcrumb trails for each category).
13435:
1.655 raeburn 13436: allitems (reference to hash - key is category key
13437: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13438:
1.655 raeburn 13439: parents (array containing containers directories for current category,
13440: back to top level).
13441:
13442: Returns: nothing
13443:
13444: Side effects: populates trails and allitems hash references
13445:
13446: =cut
13447:
13448: sub recurse_categories {
1.665 raeburn 13449: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13450: my $shallower = $depth - 1;
13451: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13452: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13453: my $name = $cats->[$depth]{$category}[$k];
13454: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13455: my $trailstr = join(' -> ',(@{$parents},$category));
13456: if ($allitems->{$item} eq '') {
13457: push(@{$trails},$trailstr);
13458: $allitems->{$item} = scalar(@{$trails})-1;
13459: }
13460: my $deeper = $depth+1;
13461: push(@{$parents},$category);
1.665 raeburn 13462: if (ref($subcats) eq 'HASH') {
13463: my $subcat = &escape($name).':'.$category.':'.$depth;
13464: for (my $j=@{$parents}; $j>=0; $j--) {
13465: my $higher;
13466: if ($j > 0) {
13467: $higher = &escape($parents->[$j]).':'.
13468: &escape($parents->[$j-1]).':'.$j;
13469: } else {
13470: $higher = &escape($parents->[$j]).'::'.$j;
13471: }
13472: push(@{$subcats->{$higher}},$subcat);
13473: }
13474: }
13475: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13476: $subcats);
1.655 raeburn 13477: pop(@{$parents});
13478: }
13479: } else {
13480: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13481: my $trailstr = join(' -> ',(@{$parents},$category));
13482: if ($allitems->{$item} eq '') {
13483: push(@{$trails},$trailstr);
13484: $allitems->{$item} = scalar(@{$trails})-1;
13485: }
13486: }
13487: return;
13488: }
13489:
1.663 raeburn 13490: =pod
13491:
1.1162 raeburn 13492: =item * &assign_categories_table()
1.663 raeburn 13493:
13494: Create a datatable for display of hierarchical categories in a domain,
13495: with checkboxes to allow a course to be categorized.
13496:
13497: Inputs:
13498:
13499: cathash - reference to hash of categories defined for the domain (from
13500: configuration.db)
13501:
13502: currcat - scalar with an & separated list of categories assigned to a course.
13503:
1.919 raeburn 13504: type - scalar contains course type (Course or Community).
13505:
1.663 raeburn 13506: Returns: $output (markup to be displayed)
13507:
13508: =cut
13509:
13510: sub assign_categories_table {
1.919 raeburn 13511: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13512: my $output;
13513: if (ref($cathash) eq 'HASH') {
13514: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13515: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13516: $maxdepth = scalar(@cats);
13517: if (@cats > 0) {
13518: my $itemcount = 0;
13519: if (ref($cats[0]) eq 'ARRAY') {
13520: my @currcategories;
13521: if ($currcat ne '') {
13522: @currcategories = split('&',$currcat);
13523: }
1.919 raeburn 13524: my $table;
1.663 raeburn 13525: for (my $i=0; $i<@{$cats[0]}; $i++) {
13526: my $parent = $cats[0][$i];
1.919 raeburn 13527: next if ($parent eq 'instcode');
13528: if ($type eq 'Community') {
13529: next unless ($parent eq 'communities');
13530: } else {
13531: next if ($parent eq 'communities');
13532: }
1.663 raeburn 13533: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13534: my $item = &escape($parent).'::0';
13535: my $checked = '';
13536: if (@currcategories > 0) {
13537: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13538: $checked = ' checked="checked"';
1.663 raeburn 13539: }
13540: }
1.919 raeburn 13541: my $parent_title = $parent;
13542: if ($parent eq 'communities') {
13543: $parent_title = &mt('Communities');
13544: }
13545: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13546: '<input type="checkbox" name="usecategory" value="'.
13547: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13548: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13549: my $depth = 1;
13550: push(@path,$parent);
1.919 raeburn 13551: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13552: pop(@path);
1.919 raeburn 13553: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13554: $itemcount ++;
13555: }
1.919 raeburn 13556: if ($itemcount) {
13557: $output = &Apache::loncommon::start_data_table().
13558: $table.
13559: &Apache::loncommon::end_data_table();
13560: }
1.663 raeburn 13561: }
13562: }
13563: }
13564: return $output;
13565: }
13566:
13567: =pod
13568:
1.1162 raeburn 13569: =item * &assign_category_rows()
1.663 raeburn 13570:
13571: Create a datatable row for display of nested categories in a domain,
13572: with checkboxes to allow a course to be categorized,called recursively.
13573:
13574: Inputs:
13575:
13576: itemcount - track row number for alternating colors
13577:
13578: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13579: categories and subcategories.
13580:
13581: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13582:
13583: parent - parent of current category item
13584:
13585: path - Array containing all categories back up through the hierarchy from the
13586: current category to the top level.
13587:
13588: currcategories - reference to array of current categories assigned to the course
13589:
13590: Returns: $output (markup to be displayed).
13591:
13592: =cut
13593:
13594: sub assign_category_rows {
13595: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13596: my ($text,$name,$item,$chgstr);
13597: if (ref($cats) eq 'ARRAY') {
13598: my $maxdepth = scalar(@{$cats});
13599: if (ref($cats->[$depth]) eq 'HASH') {
13600: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13601: my $numchildren = @{$cats->[$depth]{$parent}};
13602: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 13603: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13604: for (my $j=0; $j<$numchildren; $j++) {
13605: $name = $cats->[$depth]{$parent}[$j];
13606: $item = &escape($name).':'.&escape($parent).':'.$depth;
13607: my $deeper = $depth+1;
13608: my $checked = '';
13609: if (ref($currcategories) eq 'ARRAY') {
13610: if (@{$currcategories} > 0) {
13611: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13612: $checked = ' checked="checked"';
1.663 raeburn 13613: }
13614: }
13615: }
1.664 raeburn 13616: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13617: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13618: $item.'"'.$checked.' />'.$name.'</label></span>'.
13619: '<input type="hidden" name="catname" value="'.$name.'" />'.
13620: '</td><td>';
1.663 raeburn 13621: if (ref($path) eq 'ARRAY') {
13622: push(@{$path},$name);
13623: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13624: pop(@{$path});
13625: }
13626: $text .= '</td></tr>';
13627: }
13628: $text .= '</table></td>';
13629: }
13630: }
13631: }
13632: return $text;
13633: }
13634:
1.655 raeburn 13635: ############################################################
13636: ############################################################
13637:
13638:
1.443 albertel 13639: sub commit_customrole {
1.664 raeburn 13640: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13641: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13642: ($start?', '.&mt('starting').' '.localtime($start):'').
13643: ($end?', ending '.localtime($end):'').': <b>'.
13644: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13645: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13646: '</b><br />';
13647: return $output;
13648: }
13649:
13650: sub commit_standardrole {
1.1116 raeburn 13651: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13652: my ($output,$logmsg,$linefeed);
13653: if ($context eq 'auto') {
13654: $linefeed = "\n";
13655: } else {
13656: $linefeed = "<br />\n";
13657: }
1.443 albertel 13658: if ($three eq 'st') {
1.541 raeburn 13659: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13660: $one,$two,$sec,$context,$credits);
1.541 raeburn 13661: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13662: ($result eq 'unknown_course') || ($result eq 'refused')) {
13663: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13664: } else {
1.541 raeburn 13665: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13666: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13667: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13668: if ($context eq 'auto') {
13669: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13670: } else {
13671: $output .= '<b>'.$result.'</b>'.$linefeed.
13672: &mt('Add to classlist').': <b>ok</b>';
13673: }
13674: $output .= $linefeed;
1.443 albertel 13675: }
13676: } else {
13677: $output = &mt('Assigning').' '.$three.' in '.$url.
13678: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13679: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13680: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13681: if ($context eq 'auto') {
13682: $output .= $result.$linefeed;
13683: } else {
13684: $output .= '<b>'.$result.'</b>'.$linefeed;
13685: }
1.443 albertel 13686: }
13687: return $output;
13688: }
13689:
13690: sub commit_studentrole {
1.1116 raeburn 13691: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13692: $credits) = @_;
1.626 raeburn 13693: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13694: if ($context eq 'auto') {
13695: $linefeed = "\n";
13696: } else {
13697: $linefeed = '<br />'."\n";
13698: }
1.443 albertel 13699: if (defined($one) && defined($two)) {
13700: my $cid=$one.'_'.$two;
13701: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13702: my $secchange = 0;
13703: my $expire_role_result;
13704: my $modify_section_result;
1.628 raeburn 13705: if ($oldsec ne '-1') {
13706: if ($oldsec ne $sec) {
1.443 albertel 13707: $secchange = 1;
1.628 raeburn 13708: my $now = time;
1.443 albertel 13709: my $uurl='/'.$cid;
13710: $uurl=~s/\_/\//g;
13711: if ($oldsec) {
13712: $uurl.='/'.$oldsec;
13713: }
1.626 raeburn 13714: $oldsecurl = $uurl;
1.628 raeburn 13715: $expire_role_result =
1.652 raeburn 13716: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13717: if ($env{'request.course.sec'} ne '') {
13718: if ($expire_role_result eq 'refused') {
13719: my @roles = ('st');
13720: my @statuses = ('previous');
13721: my @roledoms = ($one);
13722: my $withsec = 1;
13723: my %roleshash =
13724: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13725: \@statuses,\@roles,\@roledoms,$withsec);
13726: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13727: my ($oldstart,$oldend) =
13728: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13729: if ($oldend > 0 && $oldend <= $now) {
13730: $expire_role_result = 'ok';
13731: }
13732: }
13733: }
13734: }
1.443 albertel 13735: $result = $expire_role_result;
13736: }
13737: }
13738: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13739: $modify_section_result =
13740: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13741: undef,undef,undef,$sec,
13742: $end,$start,'','',$cid,
13743: '',$context,$credits);
1.443 albertel 13744: if ($modify_section_result =~ /^ok/) {
13745: if ($secchange == 1) {
1.628 raeburn 13746: if ($sec eq '') {
13747: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13748: } else {
13749: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13750: }
1.443 albertel 13751: } elsif ($oldsec eq '-1') {
1.628 raeburn 13752: if ($sec eq '') {
13753: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13754: } else {
13755: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13756: }
1.443 albertel 13757: } else {
1.628 raeburn 13758: if ($sec eq '') {
13759: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13760: } else {
13761: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13762: }
1.443 albertel 13763: }
13764: } else {
1.1115 raeburn 13765: if ($secchange) {
1.628 raeburn 13766: $$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;
13767: } else {
13768: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13769: }
1.443 albertel 13770: }
13771: $result = $modify_section_result;
13772: } elsif ($secchange == 1) {
1.628 raeburn 13773: if ($oldsec eq '') {
1.1103 raeburn 13774: $$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 13775: } else {
13776: $$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;
13777: }
1.626 raeburn 13778: if ($expire_role_result eq 'refused') {
13779: my $newsecurl = '/'.$cid;
13780: $newsecurl =~ s/\_/\//g;
13781: if ($sec ne '') {
13782: $newsecurl.='/'.$sec;
13783: }
13784: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13785: if ($sec eq '') {
13786: $$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;
13787: } else {
13788: $$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;
13789: }
13790: }
13791: }
1.443 albertel 13792: }
13793: } else {
1.626 raeburn 13794: $$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 13795: $result = "error: incomplete course id\n";
13796: }
13797: return $result;
13798: }
13799:
1.1108 raeburn 13800: sub show_role_extent {
13801: my ($scope,$context,$role) = @_;
13802: $scope =~ s{^/}{};
13803: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13804: push(@courseroles,'co');
13805: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13806: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13807: $scope =~ s{/}{_};
13808: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13809: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13810: my ($audom,$auname) = split(/\//,$scope);
13811: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13812: &Apache::loncommon::plainname($auname,$audom).'</span>');
13813: } else {
13814: $scope =~ s{/$}{};
13815: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13816: &Apache::lonnet::domain($scope,'description').'</span>');
13817: }
13818: }
13819:
1.443 albertel 13820: ############################################################
13821: ############################################################
13822:
1.566 albertel 13823: sub check_clone {
1.578 raeburn 13824: my ($args,$linefeed) = @_;
1.566 albertel 13825: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13826: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13827: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13828: my $clonemsg;
13829: my $can_clone = 0;
1.944 raeburn 13830: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13831: if ($lctype ne 'community') {
13832: $lctype = 'course';
13833: }
1.566 albertel 13834: if ($clonehome eq 'no_host') {
1.944 raeburn 13835: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13836: $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'});
13837: } else {
13838: $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'});
13839: }
1.566 albertel 13840: } else {
13841: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13842: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13843: if ($clonedesc{'type'} ne 'Community') {
13844: $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'});
13845: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13846: }
13847: }
1.882 raeburn 13848: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13849: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13850: $can_clone = 1;
13851: } else {
13852: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13853: $args->{'clonedomain'},$args->{'clonecourse'});
13854: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13855: if (grep(/^\*$/,@cloners)) {
13856: $can_clone = 1;
13857: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13858: $can_clone = 1;
13859: } else {
1.908 raeburn 13860: my $ccrole = 'cc';
1.944 raeburn 13861: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13862: $ccrole = 'co';
13863: }
1.578 raeburn 13864: my %roleshash =
13865: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13866: $args->{'ccdomain'},
1.908 raeburn 13867: 'userroles',['active'],[$ccrole],
1.578 raeburn 13868: [$args->{'clonedomain'}]);
1.908 raeburn 13869: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13870: $can_clone = 1;
13871: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13872: $can_clone = 1;
13873: } else {
1.944 raeburn 13874: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13875: $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'});
13876: } else {
13877: $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'});
13878: }
1.578 raeburn 13879: }
1.566 albertel 13880: }
1.578 raeburn 13881: }
1.566 albertel 13882: }
13883: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13884: }
13885:
1.444 albertel 13886: sub construct_course {
1.1166 ! raeburn 13887: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13888: my $outcome;
1.541 raeburn 13889: my $linefeed = '<br />'."\n";
13890: if ($context eq 'auto') {
13891: $linefeed = "\n";
13892: }
1.566 albertel 13893:
13894: #
13895: # Are we cloning?
13896: #
13897: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13898: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13899: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13900: if ($context ne 'auto') {
1.578 raeburn 13901: if ($clonemsg ne '') {
13902: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13903: }
1.566 albertel 13904: }
13905: $outcome .= $clonemsg.$linefeed;
13906:
13907: if (!$can_clone) {
13908: return (0,$outcome);
13909: }
13910: }
13911:
1.444 albertel 13912: #
13913: # Open course
13914: #
13915: my $crstype = lc($args->{'crstype'});
13916: my %cenv=();
13917: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13918: $args->{'cdescr'},
13919: $args->{'curl'},
13920: $args->{'course_home'},
13921: $args->{'nonstandard'},
13922: $args->{'crscode'},
13923: $args->{'ccuname'}.':'.
13924: $args->{'ccdomain'},
1.882 raeburn 13925: $args->{'crstype'},
1.885 raeburn 13926: $cnum,$context,$category);
1.444 albertel 13927:
13928: # Note: The testing routines depend on this being output; see
13929: # Utils::Course. This needs to at least be output as a comment
13930: # if anyone ever decides to not show this, and Utils::Course::new
13931: # will need to be suitably modified.
1.541 raeburn 13932: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13933: if ($$courseid =~ /^error:/) {
13934: return (0,$outcome);
13935: }
13936:
1.444 albertel 13937: #
13938: # Check if created correctly
13939: #
1.479 albertel 13940: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13941: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13942: if ($crsuhome eq 'no_host') {
13943: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13944: return (0,$outcome);
13945: }
1.541 raeburn 13946: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13947:
1.444 albertel 13948: #
1.566 albertel 13949: # Do the cloning
13950: #
13951: if ($can_clone && $cloneid) {
13952: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13953: if ($context ne 'auto') {
13954: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13955: }
13956: $outcome .= $clonemsg.$linefeed;
13957: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13958: # Copy all files
1.637 www 13959: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13960: # Restore URL
1.566 albertel 13961: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13962: # Restore title
1.566 albertel 13963: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13964: # Restore creation date, creator and creation context.
13965: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13966: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13967: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13968: # Mark as cloned
1.566 albertel 13969: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13970: # Need to clone grading mode
13971: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13972: $cenv{'grading'}=$newenv{'grading'};
13973: # Do not clone these environment entries
13974: &Apache::lonnet::del('environment',
13975: ['default_enrollment_start_date',
13976: 'default_enrollment_end_date',
13977: 'question.email',
13978: 'policy.email',
13979: 'comment.email',
13980: 'pch.users.denied',
1.725 raeburn 13981: 'plc.users.denied',
13982: 'hidefromcat',
1.1121 raeburn 13983: 'checkforpriv',
1.1166 ! raeburn 13984: 'categories',
! 13985: 'internal.uniquecode'],
1.638 www 13986: $$crsudom,$$crsunum);
1.444 albertel 13987: }
1.566 albertel 13988:
1.444 albertel 13989: #
13990: # Set environment (will override cloned, if existing)
13991: #
13992: my @sections = ();
13993: my @xlists = ();
13994: if ($args->{'crstype'}) {
13995: $cenv{'type'}=$args->{'crstype'};
13996: }
13997: if ($args->{'crsid'}) {
13998: $cenv{'courseid'}=$args->{'crsid'};
13999: }
14000: if ($args->{'crscode'}) {
14001: $cenv{'internal.coursecode'}=$args->{'crscode'};
14002: }
14003: if ($args->{'crsquota'} ne '') {
14004: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14005: } else {
14006: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14007: }
14008: if ($args->{'ccuname'}) {
14009: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14010: ':'.$args->{'ccdomain'};
14011: } else {
14012: $cenv{'internal.courseowner'} = $args->{'curruser'};
14013: }
1.1116 raeburn 14014: if ($args->{'defaultcredits'}) {
14015: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14016: }
1.444 albertel 14017: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14018: if ($args->{'crssections'}) {
14019: $cenv{'internal.sectionnums'} = '';
14020: if ($args->{'crssections'} =~ m/,/) {
14021: @sections = split/,/,$args->{'crssections'};
14022: } else {
14023: $sections[0] = $args->{'crssections'};
14024: }
14025: if (@sections > 0) {
14026: foreach my $item (@sections) {
14027: my ($sec,$gp) = split/:/,$item;
14028: my $class = $args->{'crscode'}.$sec;
14029: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14030: $cenv{'internal.sectionnums'} .= $item.',';
14031: unless ($addcheck eq 'ok') {
14032: push @badclasses, $class;
14033: }
14034: }
14035: $cenv{'internal.sectionnums'} =~ s/,$//;
14036: }
14037: }
14038: # do not hide course coordinator from staff listing,
14039: # even if privileged
14040: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14041: # add course coordinator's domain to domains to check for privileged users
14042: # if different to course domain
14043: if ($$crsudom ne $args->{'ccdomain'}) {
14044: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14045: }
1.444 albertel 14046: # add crosslistings
14047: if ($args->{'crsxlist'}) {
14048: $cenv{'internal.crosslistings'}='';
14049: if ($args->{'crsxlist'} =~ m/,/) {
14050: @xlists = split/,/,$args->{'crsxlist'};
14051: } else {
14052: $xlists[0] = $args->{'crsxlist'};
14053: }
14054: if (@xlists > 0) {
14055: foreach my $item (@xlists) {
14056: my ($xl,$gp) = split/:/,$item;
14057: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14058: $cenv{'internal.crosslistings'} .= $item.',';
14059: unless ($addcheck eq 'ok') {
14060: push @badclasses, $xl;
14061: }
14062: }
14063: $cenv{'internal.crosslistings'} =~ s/,$//;
14064: }
14065: }
14066: if ($args->{'autoadds'}) {
14067: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14068: }
14069: if ($args->{'autodrops'}) {
14070: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14071: }
14072: # check for notification of enrollment changes
14073: my @notified = ();
14074: if ($args->{'notify_owner'}) {
14075: if ($args->{'ccuname'} ne '') {
14076: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14077: }
14078: }
14079: if ($args->{'notify_dc'}) {
14080: if ($uname ne '') {
1.630 raeburn 14081: push(@notified,$uname.':'.$udom);
1.444 albertel 14082: }
14083: }
14084: if (@notified > 0) {
14085: my $notifylist;
14086: if (@notified > 1) {
14087: $notifylist = join(',',@notified);
14088: } else {
14089: $notifylist = $notified[0];
14090: }
14091: $cenv{'internal.notifylist'} = $notifylist;
14092: }
14093: if (@badclasses > 0) {
14094: my %lt=&Apache::lonlocal::texthash(
14095: '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',
14096: 'dnhr' => 'does not have rights to access enrollment in these classes',
14097: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14098: );
1.541 raeburn 14099: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14100: ' ('.$lt{'adby'}.')';
14101: if ($context eq 'auto') {
14102: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14103: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14104: foreach my $item (@badclasses) {
14105: if ($context eq 'auto') {
14106: $outcome .= " - $item\n";
14107: } else {
14108: $outcome .= "<li>$item</li>\n";
14109: }
14110: }
14111: if ($context eq 'auto') {
14112: $outcome .= $linefeed;
14113: } else {
1.566 albertel 14114: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14115: }
14116: }
1.444 albertel 14117: }
14118: if ($args->{'no_end_date'}) {
14119: $args->{'endaccess'} = 0;
14120: }
14121: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14122: $cenv{'internal.autoend'}=$args->{'enrollend'};
14123: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14124: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14125: if ($args->{'showphotos'}) {
14126: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14127: }
14128: $cenv{'internal.authtype'} = $args->{'authtype'};
14129: $cenv{'internal.autharg'} = $args->{'autharg'};
14130: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14131: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14132: 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');
14133: if ($context eq 'auto') {
14134: $outcome .= $krb_msg;
14135: } else {
1.566 albertel 14136: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14137: }
14138: $outcome .= $linefeed;
1.444 albertel 14139: }
14140: }
14141: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14142: if ($args->{'setpolicy'}) {
14143: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14144: }
14145: if ($args->{'setcontent'}) {
14146: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14147: }
14148: }
14149: if ($args->{'reshome'}) {
14150: $cenv{'reshome'}=$args->{'reshome'}.'/';
14151: $cenv{'reshome'}=~s/\/+$/\//;
14152: }
14153: #
14154: # course has keyed access
14155: #
14156: if ($args->{'setkeys'}) {
14157: $cenv{'keyaccess'}='yes';
14158: }
14159: # if specified, key authority is not course, but user
14160: # only active if keyaccess is yes
14161: if ($args->{'keyauth'}) {
1.487 albertel 14162: my ($user,$domain) = split(':',$args->{'keyauth'});
14163: $user = &LONCAPA::clean_username($user);
14164: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14165: if ($user ne '' && $domain ne '') {
1.487 albertel 14166: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14167: }
14168: }
14169:
1.1166 ! raeburn 14170: #
! 14171: # course should have uniquecode (available to course requester).
! 14172: #
! 14173: if ($args->{'uniquecode'}) {
! 14174: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
! 14175: if ($code) {
! 14176: $cenv{'internal.uniquecode'} = $code;
! 14177: if (ref($coderef)) {
! 14178: $$coderef = $code;
! 14179: }
! 14180: }
! 14181: }
! 14182:
1.444 albertel 14183: if ($args->{'disresdis'}) {
14184: $cenv{'pch.roles.denied'}='st';
14185: }
14186: if ($args->{'disablechat'}) {
14187: $cenv{'plc.roles.denied'}='st';
14188: }
14189:
14190: # Record we've not yet viewed the Course Initialization Helper for this
14191: # course
14192: $cenv{'course.helper.not.run'} = 1;
14193: #
14194: # Use new Randomseed
14195: #
14196: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14197: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14198: #
14199: # The encryption code and receipt prefix for this course
14200: #
14201: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14202: $cenv{'internal.encpref'}=100+int(9*rand(99));
14203: #
14204: # By default, use standard grading
14205: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14206:
1.541 raeburn 14207: $outcome .= $linefeed.&mt('Setting environment').': '.
14208: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14209: #
14210: # Open all assignments
14211: #
14212: if ($args->{'openall'}) {
14213: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14214: my %storecontent = ($storeunder => time,
14215: $storeunder.'.type' => 'date_start');
14216:
14217: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14218: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14219: }
14220: #
14221: # Set first page
14222: #
14223: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14224: || ($cloneid)) {
1.445 albertel 14225: use LONCAPA::map;
1.444 albertel 14226: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14227:
14228: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14229: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14230:
1.444 albertel 14231: $outcome .= ($fatal?$errtext:'read ok').' - ';
14232: my $title; my $url;
14233: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14234: $title=&mt('Syllabus');
1.444 albertel 14235: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14236: } else {
1.963 raeburn 14237: $title=&mt('Table of Contents');
1.444 albertel 14238: $url='/adm/navmaps';
14239: }
1.445 albertel 14240:
14241: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14242: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14243:
14244: if ($errtext) { $fatal=2; }
1.541 raeburn 14245: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14246: }
1.566 albertel 14247:
14248: return (1,$outcome);
1.444 albertel 14249: }
14250:
1.1166 ! raeburn 14251: sub make_unique_code {
! 14252: my ($cdom,$cnum) = @_;
! 14253: # get lock on uniquecodes db
! 14254: my $lockhash = {
! 14255: $cnum."\0".'uniquecodes' => $env{'user.name'}.
! 14256: ':'.$env{'user.domain'},
! 14257: };
! 14258: my $tries = 0;
! 14259: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
! 14260: my ($code,$error);
! 14261:
! 14262: while (($gotlock ne 'ok') && ($tries<3)) {
! 14263: $tries ++;
! 14264: sleep 1;
! 14265: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
! 14266: }
! 14267: if ($gotlock eq 'ok') {
! 14268: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
! 14269: my $gotcode;
! 14270: my $attempts = 0;
! 14271: while ((!$gotcode) && ($attempts < 100)) {
! 14272: $code = &generate_code();
! 14273: if (!exists($currcodes{$code})) {
! 14274: $gotcode = 1;
! 14275: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
! 14276: $error = 'nostore';
! 14277: }
! 14278: }
! 14279: $attempts ++;
! 14280: }
! 14281: my @del_lock = ($cnum."\0".'uniquecodes');
! 14282: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
! 14283: } else {
! 14284: $error = 'nolock';
! 14285: }
! 14286: return ($code,$error);
! 14287: }
! 14288:
! 14289: sub generate_code {
! 14290: my $code;
! 14291: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
! 14292: for (my $i=0; $i<6; $i++) {
! 14293: my $lettnum = int (rand 2);
! 14294: my $item = '';
! 14295: if ($lettnum) {
! 14296: $item = $letts[int( rand(18) )];
! 14297: } else {
! 14298: $item = 1+int( rand(8) );
! 14299: }
! 14300: $code .= $item;
! 14301: }
! 14302: return $code;
! 14303: }
! 14304:
1.444 albertel 14305: ############################################################
14306: ############################################################
14307:
1.953 droeschl 14308: #SD
14309: # only Community and Course, or anything else?
1.378 raeburn 14310: sub course_type {
14311: my ($cid) = @_;
14312: if (!defined($cid)) {
14313: $cid = $env{'request.course.id'};
14314: }
1.404 albertel 14315: if (defined($env{'course.'.$cid.'.type'})) {
14316: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14317: } else {
14318: return 'Course';
1.377 raeburn 14319: }
14320: }
1.156 albertel 14321:
1.406 raeburn 14322: sub group_term {
14323: my $crstype = &course_type();
14324: my %names = (
14325: 'Course' => 'group',
1.865 raeburn 14326: 'Community' => 'group',
1.406 raeburn 14327: );
14328: return $names{$crstype};
14329: }
14330:
1.902 raeburn 14331: sub course_types {
1.1165 raeburn 14332: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14333: my %typename = (
14334: official => 'Official course',
14335: unofficial => 'Unofficial course',
14336: community => 'Community',
1.1165 raeburn 14337: textbook => 'Textbook course',
1.902 raeburn 14338: );
14339: return (\@types,\%typename);
14340: }
14341:
1.156 albertel 14342: sub icon {
14343: my ($file)=@_;
1.505 albertel 14344: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14345: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14346: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14347: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14348: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14349: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14350: $curfext.".gif") {
14351: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14352: $curfext.".gif";
14353: }
14354: }
1.249 albertel 14355: return &lonhttpdurl($iconname);
1.154 albertel 14356: }
1.84 albertel 14357:
1.575 albertel 14358: sub lonhttpdurl {
1.692 www 14359: #
14360: # Had been used for "small fry" static images on separate port 8080.
14361: # Modify here if lightweight http functionality desired again.
14362: # Currently eliminated due to increasing firewall issues.
14363: #
1.575 albertel 14364: my ($url)=@_;
1.692 www 14365: return $url;
1.215 albertel 14366: }
14367:
1.213 albertel 14368: sub connection_aborted {
14369: my ($r)=@_;
14370: $r->print(" ");$r->rflush();
14371: my $c = $r->connection;
14372: return $c->aborted();
14373: }
14374:
1.221 foxr 14375: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14376: # strings as 'strings'.
14377: sub escape_single {
1.221 foxr 14378: my ($input) = @_;
1.223 albertel 14379: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14380: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14381: return $input;
14382: }
1.223 albertel 14383:
1.222 foxr 14384: # Same as escape_single, but escape's "'s This
14385: # can be used for "strings"
14386: sub escape_double {
14387: my ($input) = @_;
14388: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14389: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14390: return $input;
14391: }
1.223 albertel 14392:
1.222 foxr 14393: # Escapes the last element of a full URL.
14394: sub escape_url {
14395: my ($url) = @_;
1.238 raeburn 14396: my @urlslices = split(/\//, $url,-1);
1.369 www 14397: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14398: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14399: }
1.462 albertel 14400:
1.820 raeburn 14401: sub compare_arrays {
14402: my ($arrayref1,$arrayref2) = @_;
14403: my (@difference,%count);
14404: @difference = ();
14405: %count = ();
14406: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14407: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14408: foreach my $element (keys(%count)) {
14409: if ($count{$element} == 1) {
14410: push(@difference,$element);
14411: }
14412: }
14413: }
14414: return @difference;
14415: }
14416:
1.817 bisitz 14417: # -------------------------------------------------------- Initialize user login
1.462 albertel 14418: sub init_user_environment {
1.463 albertel 14419: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14420: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14421:
14422: my $public=($username eq 'public' && $domain eq 'public');
14423:
14424: # See if old ID present, if so, remove
14425:
1.1062 raeburn 14426: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14427: my $now=time;
14428:
14429: if ($public) {
14430: my $max_public=100;
14431: my $oldest;
14432: my $oldest_time=0;
14433: for(my $next=1;$next<=$max_public;$next++) {
14434: if (-e $lonids."/publicuser_$next.id") {
14435: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14436: if ($mtime<$oldest_time || !$oldest_time) {
14437: $oldest_time=$mtime;
14438: $oldest=$next;
14439: }
14440: } else {
14441: $cookie="publicuser_$next";
14442: last;
14443: }
14444: }
14445: if (!$cookie) { $cookie="publicuser_$oldest"; }
14446: } else {
1.463 albertel 14447: # if this isn't a robot, kill any existing non-robot sessions
14448: if (!$args->{'robot'}) {
14449: opendir(DIR,$lonids);
14450: while ($filename=readdir(DIR)) {
14451: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14452: unlink($lonids.'/'.$filename);
14453: }
1.462 albertel 14454: }
1.463 albertel 14455: closedir(DIR);
1.462 albertel 14456: }
14457: # Give them a new cookie
1.463 albertel 14458: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14459: : $now.$$.int(rand(10000)));
1.463 albertel 14460: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14461:
14462: # Initialize roles
14463:
1.1062 raeburn 14464: ($userroles,$firstaccenv,$timerintenv) =
14465: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14466: }
14467: # ------------------------------------ Check browser type and MathML capability
14468:
14469: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 14470: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14471:
14472: # ------------------------------------------------------------- Get environment
14473:
14474: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14475: my ($tmp) = keys(%userenv);
14476: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14477: } else {
14478: undef(%userenv);
14479: }
14480: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14481: $form->{'interface'}=$userenv{'interface'};
14482: }
14483: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14484:
14485: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14486: foreach my $option ('interface','localpath','localres') {
14487: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14488: }
14489: # --------------------------------------------------------- Write first profile
14490:
14491: {
14492: my %initial_env =
14493: ("user.name" => $username,
14494: "user.domain" => $domain,
14495: "user.home" => $authhost,
14496: "browser.type" => $clientbrowser,
14497: "browser.version" => $clientversion,
14498: "browser.mathml" => $clientmathml,
14499: "browser.unicode" => $clientunicode,
14500: "browser.os" => $clientos,
1.1137 raeburn 14501: "browser.mobile" => $clientmobile,
1.1141 raeburn 14502: "browser.info" => $clientinfo,
1.462 albertel 14503: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14504: "request.course.fn" => '',
14505: "request.course.uri" => '',
14506: "request.course.sec" => '',
14507: "request.role" => 'cm',
14508: "request.role.adv" => $env{'user.adv'},
14509: "request.host" => $ENV{'REMOTE_ADDR'},);
14510:
14511: if ($form->{'localpath'}) {
14512: $initial_env{"browser.localpath"} = $form->{'localpath'};
14513: $initial_env{"browser.localres"} = $form->{'localres'};
14514: }
14515:
14516: if ($form->{'interface'}) {
14517: $form->{'interface'}=~s/\W//gs;
14518: $initial_env{"browser.interface"} = $form->{'interface'};
14519: $env{'browser.interface'}=$form->{'interface'};
14520: }
14521:
1.1157 raeburn 14522: if ($form->{'iptoken'}) {
14523: my $lonhost = $r->dir_config('lonHostID');
14524: $initial_env{"user.noloadbalance"} = $lonhost;
14525: $env{'user.noloadbalance'} = $lonhost;
14526: }
14527:
1.981 raeburn 14528: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14529: my %domdef;
14530: unless ($domain eq 'public') {
14531: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14532: }
1.980 raeburn 14533:
1.1081 raeburn 14534: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14535: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14536: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14537: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14538: }
14539:
1.1165 raeburn 14540: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14541: $userenv{'canrequest.'.$crstype} =
14542: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14543: 'reload','requestcourses',
14544: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14545: }
14546:
1.1092 raeburn 14547: $userenv{'canrequest.author'} =
14548: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14549: 'reload','requestauthor',
14550: \%userenv,\%domdef,\%is_adv);
14551: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14552: $domain,$username);
14553: my $reqstatus = $reqauthor{'author_status'};
14554: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14555: if (ref($reqauthor{'author'}) eq 'HASH') {
14556: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14557: $reqauthor{'author'}{'timestamp'};
14558: }
14559: }
14560:
1.462 albertel 14561: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14562:
1.462 albertel 14563: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14564: &GDBM_WRCREAT(),0640)) {
14565: &_add_to_env(\%disk_env,\%initial_env);
14566: &_add_to_env(\%disk_env,\%userenv,'environment.');
14567: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14568: if (ref($firstaccenv) eq 'HASH') {
14569: &_add_to_env(\%disk_env,$firstaccenv);
14570: }
14571: if (ref($timerintenv) eq 'HASH') {
14572: &_add_to_env(\%disk_env,$timerintenv);
14573: }
1.463 albertel 14574: if (ref($args->{'extra_env'})) {
14575: &_add_to_env(\%disk_env,$args->{'extra_env'});
14576: }
1.462 albertel 14577: untie(%disk_env);
14578: } else {
1.705 tempelho 14579: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14580: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14581: return 'error: '.$!;
14582: }
14583: }
14584: $env{'request.role'}='cm';
14585: $env{'request.role.adv'}=$env{'user.adv'};
14586: $env{'browser.type'}=$clientbrowser;
14587:
14588: return $cookie;
14589:
14590: }
14591:
14592: sub _add_to_env {
14593: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14594: if (ref($env_data) eq 'HASH') {
14595: while (my ($key,$value) = each(%$env_data)) {
14596: $idf->{$prefix.$key} = $value;
14597: $env{$prefix.$key} = $value;
14598: }
1.462 albertel 14599: }
14600: }
14601:
1.685 tempelho 14602: # --- Get the symbolic name of a problem and the url
14603: sub get_symb {
14604: my ($request,$silent) = @_;
1.726 raeburn 14605: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14606: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14607: if ($symb eq '') {
14608: if (!$silent) {
1.1071 raeburn 14609: if (ref($request)) {
14610: $request->print("Unable to handle ambiguous references:$url:.");
14611: }
1.685 tempelho 14612: return ();
14613: }
14614: }
14615: &Apache::lonenc::check_decrypt(\$symb);
14616: return ($symb);
14617: }
14618:
14619: # --------------------------------------------------------------Get annotation
14620:
14621: sub get_annotation {
14622: my ($symb,$enc) = @_;
14623:
14624: my $key = $symb;
14625: if (!$enc) {
14626: $key =
14627: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14628: }
14629: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14630: return $annotation{$key};
14631: }
14632:
14633: sub clean_symb {
1.731 raeburn 14634: my ($symb,$delete_enc) = @_;
1.685 tempelho 14635:
14636: &Apache::lonenc::check_decrypt(\$symb);
14637: my $enc = $env{'request.enc'};
1.731 raeburn 14638: if ($delete_enc) {
1.730 raeburn 14639: delete($env{'request.enc'});
14640: }
1.685 tempelho 14641:
14642: return ($symb,$enc);
14643: }
1.462 albertel 14644:
1.990 raeburn 14645: sub build_release_hashes {
14646: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14647: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14648: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14649: (ref($randomizetry) eq 'HASH'));
14650: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14651: my ($item,$name,$value) = split(/:/,$key);
14652: if ($item eq 'parameter') {
14653: if (ref($checkparms->{$name}) eq 'ARRAY') {
14654: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14655: push(@{$checkparms->{$name}},$value);
14656: }
14657: } else {
14658: push(@{$checkparms->{$name}},$value);
14659: }
14660: } elsif ($item eq 'resourcetag') {
14661: if ($name eq 'responsetype') {
14662: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14663: }
14664: } elsif ($item eq 'course') {
14665: if ($name eq 'crstype') {
14666: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14667: }
14668: }
14669: }
14670: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14671: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14672: return;
14673: }
14674:
1.1083 raeburn 14675: sub update_content_constraints {
14676: my ($cdom,$cnum,$chome,$cid) = @_;
14677: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14678: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14679: my %checkresponsetypes;
14680: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14681: my ($item,$name,$value) = split(/:/,$key);
14682: if ($item eq 'resourcetag') {
14683: if ($name eq 'responsetype') {
14684: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14685: }
14686: }
14687: }
14688: my $navmap = Apache::lonnavmaps::navmap->new();
14689: if (defined($navmap)) {
14690: my %allresponses;
14691: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14692: my %responses = $res->responseTypes();
14693: foreach my $key (keys(%responses)) {
14694: next unless(exists($checkresponsetypes{$key}));
14695: $allresponses{$key} += $responses{$key};
14696: }
14697: }
14698: foreach my $key (keys(%allresponses)) {
14699: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14700: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14701: ($reqdmajor,$reqdminor) = ($major,$minor);
14702: }
14703: }
14704: undef($navmap);
14705: }
14706: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14707: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14708: }
14709: return;
14710: }
14711:
1.1110 raeburn 14712: sub allmaps_incourse {
14713: my ($cdom,$cnum,$chome,$cid) = @_;
14714: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14715: $cid = $env{'request.course.id'};
14716: $cdom = $env{'course.'.$cid.'.domain'};
14717: $cnum = $env{'course.'.$cid.'.num'};
14718: $chome = $env{'course.'.$cid.'.home'};
14719: }
14720: my %allmaps = ();
14721: my $lastchange =
14722: &Apache::lonnet::get_coursechange($cdom,$cnum);
14723: if ($lastchange > $env{'request.course.tied'}) {
14724: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14725: unless ($ferr) {
14726: &update_content_constraints($cdom,$cnum,$chome,$cid);
14727: }
14728: }
14729: my $navmap = Apache::lonnavmaps::navmap->new();
14730: if (defined($navmap)) {
14731: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14732: $allmaps{$res->src()} = 1;
14733: }
14734: }
14735: return \%allmaps;
14736: }
14737:
1.1083 raeburn 14738: sub parse_supplemental_title {
14739: my ($title) = @_;
14740:
14741: my ($foldertitle,$renametitle);
14742: if ($title =~ /&&&/) {
14743: $title = &HTML::Entites::decode($title);
14744: }
14745: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14746: $renametitle=$4;
14747: my ($time,$uname,$udom) = ($1,$2,$3);
14748: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14749: my $name = &plainname($uname,$udom);
14750: $name = &HTML::Entities::encode($name,'"<>&\'');
14751: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14752: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14753: $name.': <br />'.$foldertitle;
14754: }
14755: if (wantarray) {
14756: return ($title,$foldertitle,$renametitle);
14757: }
14758: return $title;
14759: }
14760:
1.1143 raeburn 14761: sub recurse_supplemental {
14762: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14763: if ($suppmap) {
14764: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14765: if ($fatal) {
14766: $errors ++;
14767: } else {
14768: if ($#LONCAPA::map::resources > 0) {
14769: foreach my $res (@LONCAPA::map::resources) {
14770: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14771: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 14772: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14773: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 14774: } else {
14775: $numfiles ++;
14776: }
14777: }
14778: }
14779: }
14780: }
14781: }
14782: return ($numfiles,$errors);
14783: }
14784:
1.1101 raeburn 14785: sub symb_to_docspath {
14786: my ($symb) = @_;
14787: return unless ($symb);
14788: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14789: if ($resurl=~/\.(sequence|page)$/) {
14790: $mapurl=$resurl;
14791: } elsif ($resurl eq 'adm/navmaps') {
14792: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14793: }
14794: my $mapresobj;
14795: my $navmap = Apache::lonnavmaps::navmap->new();
14796: if (ref($navmap)) {
14797: $mapresobj = $navmap->getResourceByUrl($mapurl);
14798: }
14799: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14800: my $type=$2;
14801: my $path;
14802: if (ref($mapresobj)) {
14803: my $pcslist = $mapresobj->map_hierarchy();
14804: if ($pcslist ne '') {
14805: foreach my $pc (split(/,/,$pcslist)) {
14806: next if ($pc <= 1);
14807: my $res = $navmap->getByMapPc($pc);
14808: if (ref($res)) {
14809: my $thisurl = $res->src();
14810: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14811: my $thistitle = $res->title();
14812: $path .= '&'.
14813: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 14814: &escape($thistitle).
1.1101 raeburn 14815: ':'.$res->randompick().
14816: ':'.$res->randomout().
14817: ':'.$res->encrypted().
14818: ':'.$res->randomorder().
14819: ':'.$res->is_page();
14820: }
14821: }
14822: }
14823: $path =~ s/^\&//;
14824: my $maptitle = $mapresobj->title();
14825: if ($mapurl eq 'default') {
1.1129 raeburn 14826: $maptitle = 'Main Content';
1.1101 raeburn 14827: }
14828: $path .= (($path ne '')? '&' : '').
14829: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 14830: &escape($maptitle).
1.1101 raeburn 14831: ':'.$mapresobj->randompick().
14832: ':'.$mapresobj->randomout().
14833: ':'.$mapresobj->encrypted().
14834: ':'.$mapresobj->randomorder().
14835: ':'.$mapresobj->is_page();
14836: } else {
14837: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14838: my $ispage = (($type eq 'page')? 1 : '');
14839: if ($mapurl eq 'default') {
1.1129 raeburn 14840: $maptitle = 'Main Content';
1.1101 raeburn 14841: }
14842: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 14843: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 14844: }
14845: unless ($mapurl eq 'default') {
14846: $path = 'default&'.
1.1146 raeburn 14847: &escape('Main Content').
1.1101 raeburn 14848: ':::::&'.$path;
14849: }
14850: return $path;
14851: }
14852:
1.1094 raeburn 14853: sub captcha_display {
14854: my ($context,$lonhost) = @_;
14855: my ($output,$error);
14856: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14857: if ($captcha eq 'original') {
1.1094 raeburn 14858: $output = &create_captcha();
14859: unless ($output) {
14860: $error = 'captcha';
14861: }
14862: } elsif ($captcha eq 'recaptcha') {
14863: $output = &create_recaptcha($pubkey);
14864: unless ($output) {
1.1095 raeburn 14865: $error = 'recaptcha';
1.1094 raeburn 14866: }
14867: }
14868: return ($output,$error);
14869: }
14870:
14871: sub captcha_response {
14872: my ($context,$lonhost) = @_;
14873: my ($captcha_chk,$captcha_error);
14874: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14875: if ($captcha eq 'original') {
1.1094 raeburn 14876: ($captcha_chk,$captcha_error) = &check_captcha();
14877: } elsif ($captcha eq 'recaptcha') {
14878: $captcha_chk = &check_recaptcha($privkey);
14879: } else {
14880: $captcha_chk = 1;
14881: }
14882: return ($captcha_chk,$captcha_error);
14883: }
14884:
14885: sub get_captcha_config {
14886: my ($context,$lonhost) = @_;
1.1095 raeburn 14887: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14888: my $hostname = &Apache::lonnet::hostname($lonhost);
14889: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14890: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14891: if ($context eq 'usercreation') {
14892: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14893: if (ref($domconfig{$context}) eq 'HASH') {
14894: $hashtocheck = $domconfig{$context}{'cancreate'};
14895: if (ref($hashtocheck) eq 'HASH') {
14896: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14897: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14898: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14899: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14900: }
14901: if ($privkey && $pubkey) {
14902: $captcha = 'recaptcha';
14903: } else {
14904: $captcha = 'original';
14905: }
14906: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14907: $captcha = 'original';
14908: }
1.1094 raeburn 14909: }
1.1095 raeburn 14910: } else {
14911: $captcha = 'captcha';
14912: }
14913: } elsif ($context eq 'login') {
14914: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14915: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14916: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14917: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14918: if ($privkey && $pubkey) {
14919: $captcha = 'recaptcha';
1.1095 raeburn 14920: } else {
14921: $captcha = 'original';
1.1094 raeburn 14922: }
1.1095 raeburn 14923: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14924: $captcha = 'original';
1.1094 raeburn 14925: }
14926: }
14927: return ($captcha,$pubkey,$privkey);
14928: }
14929:
14930: sub create_captcha {
14931: my %captcha_params = &captcha_settings();
14932: my ($output,$maxtries,$tries) = ('',10,0);
14933: while ($tries < $maxtries) {
14934: $tries ++;
14935: my $captcha = Authen::Captcha->new (
14936: output_folder => $captcha_params{'output_dir'},
14937: data_folder => $captcha_params{'db_dir'},
14938: );
14939: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14940:
14941: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14942: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14943: &mt('Type in the letters/numbers shown below').' '.
14944: '<input type="text" size="5" name="code" value="" /><br />'.
14945: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14946: last;
14947: }
14948: }
14949: return $output;
14950: }
14951:
14952: sub captcha_settings {
14953: my %captcha_params = (
14954: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14955: www_output_dir => "/captchaspool",
14956: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14957: numchars => '5',
14958: );
14959: return %captcha_params;
14960: }
14961:
14962: sub check_captcha {
14963: my ($captcha_chk,$captcha_error);
14964: my $code = $env{'form.code'};
14965: my $md5sum = $env{'form.crypt'};
14966: my %captcha_params = &captcha_settings();
14967: my $captcha = Authen::Captcha->new(
14968: output_folder => $captcha_params{'output_dir'},
14969: data_folder => $captcha_params{'db_dir'},
14970: );
1.1109 raeburn 14971: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14972: my %captcha_hash = (
14973: 0 => 'Code not checked (file error)',
14974: -1 => 'Failed: code expired',
14975: -2 => 'Failed: invalid code (not in database)',
14976: -3 => 'Failed: invalid code (code does not match crypt)',
14977: );
14978: if ($captcha_chk != 1) {
14979: $captcha_error = $captcha_hash{$captcha_chk}
14980: }
14981: return ($captcha_chk,$captcha_error);
14982: }
14983:
14984: sub create_recaptcha {
14985: my ($pubkey) = @_;
1.1153 raeburn 14986: my $use_ssl;
14987: if ($ENV{'SERVER_PORT'} == 443) {
14988: $use_ssl = 1;
14989: }
1.1094 raeburn 14990: my $captcha = Captcha::reCAPTCHA->new;
14991: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 14992: $captcha->get_html($pubkey,undef,$use_ssl).
1.1094 raeburn 14993: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 14994: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 14995: '<br /><br />';
14996: }
14997:
14998: sub check_recaptcha {
14999: my ($privkey) = @_;
15000: my $captcha_chk;
15001: my $captcha = Captcha::reCAPTCHA->new;
15002: my $captcha_result =
15003: $captcha->check_answer(
15004: $privkey,
15005: $ENV{'REMOTE_ADDR'},
15006: $env{'form.recaptcha_challenge_field'},
15007: $env{'form.recaptcha_response_field'},
15008: );
15009: if ($captcha_result->{is_valid}) {
15010: $captcha_chk = 1;
15011: }
15012: return $captcha_chk;
15013: }
15014:
1.1161 raeburn 15015: sub cleanup_html {
15016: my ($incoming) = @_;
15017: my $outgoing;
15018: if ($incoming ne '') {
15019: $outgoing = $incoming;
15020: $outgoing =~ s/;/;/g;
15021: $outgoing =~ s/\#/#/g;
15022: $outgoing =~ s/\&/&/g;
15023: $outgoing =~ s/</</g;
15024: $outgoing =~ s/>/>/g;
15025: $outgoing =~ s/\(/(/g;
15026: $outgoing =~ s/\)/)/g;
15027: $outgoing =~ s/"/"/g;
15028: $outgoing =~ s/'/'/g;
15029: $outgoing =~ s/\$/$/g;
15030: $outgoing =~ s{/}{/}g;
15031: $outgoing =~ s/=/=/g;
15032: $outgoing =~ s/\\/\/g
15033: }
15034: return $outgoing;
15035: }
15036:
1.41 ng 15037: =pod
15038:
15039: =back
15040:
1.112 bowersj2 15041: =cut
1.41 ng 15042:
1.112 bowersj2 15043: 1;
15044: __END__;
1.41 ng 15045:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>