Annotation of loncom/interface/loncommon.pm, revision 1.1173
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1173 ! kruse 4: # $Id: loncommon.pm,v 1.1172 2014/01/27 02:21:30 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.1168 raeburn 1383: my ($link,$banner_link);
1384: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1385: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1386: : "javascript:helpMenu('open')";
1387: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1388: }
1.201 raeburn 1389: my $title = &mt('Get help');
1.1168 raeburn 1390: if ($link) {
1391: return <<"END";
1.436 albertel 1392: $banner_link
1.1159 raeburn 1393: <a href="$link" title="$title">$text</a>
1.436 albertel 1394: END
1.1168 raeburn 1395: } else {
1396: return ' '.$text.' ';
1397: }
1.436 albertel 1398: }
1399:
1400: sub help_menu_js {
1.1154 raeburn 1401: my ($httphost) = @_;
1.949 droeschl 1402: my $stayOnPage = 1;
1.436 albertel 1403: my $width = 620;
1404: my $height = 600;
1.430 albertel 1405: my $helptopic=&general_help();
1.1154 raeburn 1406: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1407: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1408: my $start_page =
1409: &Apache::loncommon::start_page('Help Menu', undef,
1410: {'frameset' => 1,
1411: 'js_ready' => 1,
1.1154 raeburn 1412: 'use_absolute' => $httphost,
1.331 albertel 1413: 'add_entries' => {
1.1168 raeburn 1414: 'border' => '0',
1.579 raeburn 1415: 'rows' => "110,*",},});
1.331 albertel 1416: my $end_page =
1417: &Apache::loncommon::end_page({'frameset' => 1,
1418: 'js_ready' => 1,});
1419:
1.436 albertel 1420: my $template .= <<"ENDTEMPLATE";
1421: <script type="text/javascript">
1.877 bisitz 1422: // <![CDATA[
1.253 albertel 1423: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1424: var banner_link = '';
1.243 raeburn 1425: function helpMenu(target) {
1426: var caller = this;
1427: if (target == 'open') {
1428: var newWindow = null;
1429: try {
1.262 albertel 1430: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1431: }
1432: catch(error) {
1433: writeHelp(caller);
1434: return;
1435: }
1436: if (newWindow) {
1437: caller = newWindow;
1438: }
1.193 raeburn 1439: }
1.243 raeburn 1440: writeHelp(caller);
1441: return;
1442: }
1443: function writeHelp(caller) {
1.1168 raeburn 1444: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1445: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1446: caller.document.close();
1447: caller.focus();
1.193 raeburn 1448: }
1.877 bisitz 1449: // END LON-CAPA Internal -->
1.253 albertel 1450: // ]]>
1.436 albertel 1451: </script>
1.193 raeburn 1452: ENDTEMPLATE
1453: return $template;
1454: }
1455:
1.172 www 1456: sub help_open_bug {
1457: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1458: unless ($env{'user.adv'}) { return ''; }
1.172 www 1459: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1460: $text = "" if (not defined $text);
1461: $stayOnPage=1;
1.184 albertel 1462: $width = 600 if (not defined $width);
1463: $height = 600 if (not defined $height);
1.172 www 1464:
1465: $topic=~s/\W+/\+/g;
1466: my $link='';
1467: my $template='';
1.379 albertel 1468: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1469: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1470: if (!$stayOnPage)
1471: {
1472: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1473: }
1474: else
1475: {
1476: $link = $url;
1477: }
1478: # Add the text
1479: if ($text ne "")
1480: {
1481: $template .=
1482: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1483: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1484: }
1485:
1486: # Add the graphic
1.179 matthew 1487: my $title = &mt('Report a Bug');
1.215 albertel 1488: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1489: $template .= <<"ENDTEMPLATE";
1.436 albertel 1490: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1491: ENDTEMPLATE
1492: if ($text ne '') { $template.='</td></tr></table>' };
1493: return $template;
1494:
1495: }
1496:
1497: sub help_open_faq {
1498: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1499: unless ($env{'user.adv'}) { return ''; }
1.172 www 1500: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1501: $text = "" if (not defined $text);
1502: $stayOnPage=1;
1503: $width = 350 if (not defined $width);
1504: $height = 400 if (not defined $height);
1505:
1506: $topic=~s/\W+/\+/g;
1507: my $link='';
1508: my $template='';
1509: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1510: if (!$stayOnPage)
1511: {
1512: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1513: }
1514: else
1515: {
1516: $link = $url;
1517: }
1518:
1519: # Add the text
1520: if ($text ne "")
1521: {
1522: $template .=
1.173 www 1523: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1524: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1525: }
1526:
1527: # Add the graphic
1.179 matthew 1528: my $title = &mt('View the FAQ');
1.215 albertel 1529: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1530: $template .= <<"ENDTEMPLATE";
1.436 albertel 1531: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1532: ENDTEMPLATE
1533: if ($text ne '') { $template.='</td></tr></table>' };
1534: return $template;
1535:
1.44 bowersj2 1536: }
1.37 matthew 1537:
1.180 matthew 1538: ###############################################################
1539: ###############################################################
1540:
1.45 matthew 1541: =pod
1542:
1.648 raeburn 1543: =item * &change_content_javascript():
1.256 matthew 1544:
1545: This and the next function allow you to create small sections of an
1546: otherwise static HTML page that you can update on the fly with
1547: Javascript, even in Netscape 4.
1548:
1549: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1550: must be written to the HTML page once. It will prove the Javascript
1551: function "change(name, content)". Calling the change function with the
1552: name of the section
1553: you want to update, matching the name passed to C<changable_area>, and
1554: the new content you want to put in there, will put the content into
1555: that area.
1556:
1557: B<Note>: Netscape 4 only reserves enough space for the changable area
1558: to contain room for the original contents. You need to "make space"
1559: for whatever changes you wish to make, and be B<sure> to check your
1560: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1561: it's adequate for updating a one-line status display, but little more.
1562: This script will set the space to 100% width, so you only need to
1563: worry about height in Netscape 4.
1564:
1565: Modern browsers are much less limiting, and if you can commit to the
1566: user not using Netscape 4, this feature may be used freely with
1567: pretty much any HTML.
1568:
1569: =cut
1570:
1571: sub change_content_javascript {
1572: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1573: if ($env{'browser.type'} eq 'netscape' &&
1574: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1575: return (<<NETSCAPE4);
1576: function change(name, content) {
1577: doc = document.layers[name+"___escape"].layers[0].document;
1578: doc.open();
1579: doc.write(content);
1580: doc.close();
1581: }
1582: NETSCAPE4
1583: } else {
1584: # Otherwise, we need to use semi-standards-compliant code
1585: # (technically, "innerHTML" isn't standard but the equivalent
1586: # is really scary, and every useful browser supports it
1587: return (<<DOMBASED);
1588: function change(name, content) {
1589: element = document.getElementById(name);
1590: element.innerHTML = content;
1591: }
1592: DOMBASED
1593: }
1594: }
1595:
1596: =pod
1597:
1.648 raeburn 1598: =item * &changable_area($name,$origContent):
1.256 matthew 1599:
1600: This provides a "changable area" that can be modified on the fly via
1601: the Javascript code provided in C<change_content_javascript>. $name is
1602: the name you will use to reference the area later; do not repeat the
1603: same name on a given HTML page more then once. $origContent is what
1604: the area will originally contain, which can be left blank.
1605:
1606: =cut
1607:
1608: sub changable_area {
1609: my ($name, $origContent) = @_;
1610:
1.258 albertel 1611: if ($env{'browser.type'} eq 'netscape' &&
1612: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1613: # If this is netscape 4, we need to use the Layer tag
1614: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1615: } else {
1616: return "<span id='$name'>$origContent</span>";
1617: }
1618: }
1619:
1620: =pod
1621:
1.648 raeburn 1622: =item * &viewport_geometry_js
1.590 raeburn 1623:
1624: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1625:
1626: =cut
1627:
1628:
1629: sub viewport_geometry_js {
1630: return <<"GEOMETRY";
1631: var Geometry = {};
1632: function init_geometry() {
1633: if (Geometry.init) { return };
1634: Geometry.init=1;
1635: if (window.innerHeight) {
1636: Geometry.getViewportHeight = function() { return window.innerHeight; };
1637: Geometry.getViewportWidth = function() { return window.innerWidth; };
1638: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1639: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1640: }
1641: else if (document.documentElement && document.documentElement.clientHeight) {
1642: Geometry.getViewportHeight =
1643: function() { return document.documentElement.clientHeight; };
1644: Geometry.getViewportWidth =
1645: function() { return document.documentElement.clientWidth; };
1646:
1647: Geometry.getHorizontalScroll =
1648: function() { return document.documentElement.scrollLeft; };
1649: Geometry.getVerticalScroll =
1650: function() { return document.documentElement.scrollTop; };
1651: }
1652: else if (document.body.clientHeight) {
1653: Geometry.getViewportHeight =
1654: function() { return document.body.clientHeight; };
1655: Geometry.getViewportWidth =
1656: function() { return document.body.clientWidth; };
1657: Geometry.getHorizontalScroll =
1658: function() { return document.body.scrollLeft; };
1659: Geometry.getVerticalScroll =
1660: function() { return document.body.scrollTop; };
1661: }
1662: }
1663:
1664: GEOMETRY
1665: }
1666:
1667: =pod
1668:
1.648 raeburn 1669: =item * &viewport_size_js()
1.590 raeburn 1670:
1671: 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.
1672:
1673: =cut
1674:
1675: sub viewport_size_js {
1676: my $geometry = &viewport_geometry_js();
1677: return <<"DIMS";
1678:
1679: $geometry
1680:
1681: function getViewportDims(width,height) {
1682: init_geometry();
1683: width.value = Geometry.getViewportWidth();
1684: height.value = Geometry.getViewportHeight();
1685: return;
1686: }
1687:
1688: DIMS
1689: }
1690:
1691: =pod
1692:
1.648 raeburn 1693: =item * &resize_textarea_js()
1.565 albertel 1694:
1695: emits the needed javascript to resize a textarea to be as big as possible
1696:
1697: creates a function resize_textrea that takes two IDs first should be
1698: the id of the element to resize, second should be the id of a div that
1699: surrounds everything that comes after the textarea, this routine needs
1700: to be attached to the <body> for the onload and onresize events.
1701:
1.648 raeburn 1702: =back
1.565 albertel 1703:
1704: =cut
1705:
1706: sub resize_textarea_js {
1.590 raeburn 1707: my $geometry = &viewport_geometry_js();
1.565 albertel 1708: return <<"RESIZE";
1709: <script type="text/javascript">
1.824 bisitz 1710: // <![CDATA[
1.590 raeburn 1711: $geometry
1.565 albertel 1712:
1.588 albertel 1713: function getX(element) {
1714: var x = 0;
1715: while (element) {
1716: x += element.offsetLeft;
1717: element = element.offsetParent;
1718: }
1719: return x;
1720: }
1721: function getY(element) {
1722: var y = 0;
1723: while (element) {
1724: y += element.offsetTop;
1725: element = element.offsetParent;
1726: }
1727: return y;
1728: }
1729:
1730:
1.565 albertel 1731: function resize_textarea(textarea_id,bottom_id) {
1732: init_geometry();
1733: var textarea = document.getElementById(textarea_id);
1734: //alert(textarea);
1735:
1.588 albertel 1736: var textarea_top = getY(textarea);
1.565 albertel 1737: var textarea_height = textarea.offsetHeight;
1738: var bottom = document.getElementById(bottom_id);
1.588 albertel 1739: var bottom_top = getY(bottom);
1.565 albertel 1740: var bottom_height = bottom.offsetHeight;
1741: var window_height = Geometry.getViewportHeight();
1.588 albertel 1742: var fudge = 23;
1.565 albertel 1743: var new_height = window_height-fudge-textarea_top-bottom_height;
1744: if (new_height < 300) {
1745: new_height = 300;
1746: }
1747: textarea.style.height=new_height+'px';
1748: }
1.824 bisitz 1749: // ]]>
1.565 albertel 1750: </script>
1751: RESIZE
1752:
1753: }
1754:
1755: =pod
1756:
1.256 matthew 1757: =head1 Excel and CSV file utility routines
1758:
1759: =cut
1760:
1761: ###############################################################
1762: ###############################################################
1763:
1764: =pod
1765:
1.1162 raeburn 1766: =over 4
1767:
1.648 raeburn 1768: =item * &csv_translate($text)
1.37 matthew 1769:
1.185 www 1770: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1771: format.
1772:
1773: =cut
1774:
1.180 matthew 1775: ###############################################################
1776: ###############################################################
1.37 matthew 1777: sub csv_translate {
1778: my $text = shift;
1779: $text =~ s/\"/\"\"/g;
1.209 albertel 1780: $text =~ s/\n/ /g;
1.37 matthew 1781: return $text;
1782: }
1.180 matthew 1783:
1784: ###############################################################
1785: ###############################################################
1786:
1787: =pod
1788:
1.648 raeburn 1789: =item * &define_excel_formats()
1.180 matthew 1790:
1791: Define some commonly used Excel cell formats.
1792:
1793: Currently supported formats:
1794:
1795: =over 4
1796:
1797: =item header
1798:
1799: =item bold
1800:
1801: =item h1
1802:
1803: =item h2
1804:
1805: =item h3
1806:
1.256 matthew 1807: =item h4
1808:
1809: =item i
1810:
1.180 matthew 1811: =item date
1812:
1813: =back
1814:
1815: Inputs: $workbook
1816:
1817: Returns: $format, a hash reference.
1818:
1.1057 foxr 1819:
1.180 matthew 1820: =cut
1821:
1822: ###############################################################
1823: ###############################################################
1824: sub define_excel_formats {
1825: my ($workbook) = @_;
1826: my $format;
1827: $format->{'header'} = $workbook->add_format(bold => 1,
1828: bottom => 1,
1829: align => 'center');
1830: $format->{'bold'} = $workbook->add_format(bold=>1);
1831: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1832: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1833: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1834: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1835: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1836: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1837: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1838: return $format;
1839: }
1840:
1841: ###############################################################
1842: ###############################################################
1.113 bowersj2 1843:
1844: =pod
1845:
1.648 raeburn 1846: =item * &create_workbook()
1.255 matthew 1847:
1848: Create an Excel worksheet. If it fails, output message on the
1849: request object and return undefs.
1850:
1851: Inputs: Apache request object
1852:
1853: Returns (undef) on failure,
1854: Excel worksheet object, scalar with filename, and formats
1855: from &Apache::loncommon::define_excel_formats on success
1856:
1857: =cut
1858:
1859: ###############################################################
1860: ###############################################################
1861: sub create_workbook {
1862: my ($r) = @_;
1863: #
1864: # Create the excel spreadsheet
1865: my $filename = '/prtspool/'.
1.258 albertel 1866: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1867: time.'_'.rand(1000000000).'.xls';
1868: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1869: if (! defined($workbook)) {
1870: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1871: $r->print(
1872: '<p class="LC_error">'
1873: .&mt('Problems occurred in creating the new Excel file.')
1874: .' '.&mt('This error has been logged.')
1875: .' '.&mt('Please alert your LON-CAPA administrator.')
1876: .'</p>'
1877: );
1.255 matthew 1878: return (undef);
1879: }
1880: #
1.1014 foxr 1881: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1882: #
1883: my $format = &Apache::loncommon::define_excel_formats($workbook);
1884: return ($workbook,$filename,$format);
1885: }
1886:
1887: ###############################################################
1888: ###############################################################
1889:
1890: =pod
1891:
1.648 raeburn 1892: =item * &create_text_file()
1.113 bowersj2 1893:
1.542 raeburn 1894: Create a file to write to and eventually make available to the user.
1.256 matthew 1895: If file creation fails, outputs an error message on the request object and
1896: return undefs.
1.113 bowersj2 1897:
1.256 matthew 1898: Inputs: Apache request object, and file suffix
1.113 bowersj2 1899:
1.256 matthew 1900: Returns (undef) on failure,
1901: Filehandle and filename on success.
1.113 bowersj2 1902:
1903: =cut
1904:
1.256 matthew 1905: ###############################################################
1906: ###############################################################
1907: sub create_text_file {
1908: my ($r,$suffix) = @_;
1909: if (! defined($suffix)) { $suffix = 'txt'; };
1910: my $fh;
1911: my $filename = '/prtspool/'.
1.258 albertel 1912: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1913: time.'_'.rand(1000000000).'.'.$suffix;
1914: $fh = Apache::File->new('>/home/httpd'.$filename);
1915: if (! defined($fh)) {
1916: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1917: $r->print(
1918: '<p class="LC_error">'
1919: .&mt('Problems occurred in creating the output file.')
1920: .' '.&mt('This error has been logged.')
1921: .' '.&mt('Please alert your LON-CAPA administrator.')
1922: .'</p>'
1923: );
1.113 bowersj2 1924: }
1.256 matthew 1925: return ($fh,$filename)
1.113 bowersj2 1926: }
1927:
1928:
1.256 matthew 1929: =pod
1.113 bowersj2 1930:
1931: =back
1932:
1933: =cut
1.37 matthew 1934:
1935: ###############################################################
1.33 matthew 1936: ## Home server <option> list generating code ##
1937: ###############################################################
1.35 matthew 1938:
1.169 www 1939: # ------------------------------------------
1940:
1941: sub domain_select {
1942: my ($name,$value,$multiple)=@_;
1943: my %domains=map {
1.514 albertel 1944: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1945: } &Apache::lonnet::all_domains();
1.169 www 1946: if ($multiple) {
1947: $domains{''}=&mt('Any domain');
1.550 albertel 1948: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1949: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1950: } else {
1.550 albertel 1951: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1952: return &select_form($name,$value,\%domains);
1.169 www 1953: }
1954: }
1955:
1.282 albertel 1956: #-------------------------------------------
1957:
1958: =pod
1959:
1.519 raeburn 1960: =head1 Routines for form select boxes
1961:
1962: =over 4
1963:
1.648 raeburn 1964: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1965:
1966: Returns a string containing a <select> element int multiple mode
1967:
1968:
1969: Args:
1970: $name - name of the <select> element
1.506 raeburn 1971: $value - scalar or array ref of values that should already be selected
1.282 albertel 1972: $size - number of rows long the select element is
1.283 albertel 1973: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1974: (shown text should already have been &mt())
1.506 raeburn 1975: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1976:
1.282 albertel 1977: =cut
1978:
1979: #-------------------------------------------
1.169 www 1980: sub multiple_select_form {
1.284 albertel 1981: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1982: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1983: my $output='';
1.191 matthew 1984: if (! defined($size)) {
1985: $size = 4;
1.283 albertel 1986: if (scalar(keys(%$hash))<4) {
1987: $size = scalar(keys(%$hash));
1.191 matthew 1988: }
1989: }
1.734 bisitz 1990: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1991: my @order;
1.506 raeburn 1992: if (ref($order) eq 'ARRAY') {
1993: @order = @{$order};
1994: } else {
1995: @order = sort(keys(%$hash));
1.501 banghart 1996: }
1997: if (exists($$hash{'select_form_order'})) {
1998: @order = @{$$hash{'select_form_order'}};
1999: }
2000:
1.284 albertel 2001: foreach my $key (@order) {
1.356 albertel 2002: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2003: $output.='selected="selected" ' if ($selected{$key});
2004: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2005: }
2006: $output.="</select>\n";
2007: return $output;
2008: }
2009:
1.88 www 2010: #-------------------------------------------
2011:
2012: =pod
2013:
1.970 raeburn 2014: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2015:
2016: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2017: allow a user to select options from a ref to a hash containing:
2018: option_name => displayed text. An optional $onchange can include
2019: a javascript onchange item, e.g., onchange="this.form.submit();"
2020:
1.88 www 2021: See lonrights.pm for an example invocation and use.
2022:
2023: =cut
2024:
2025: #-------------------------------------------
2026: sub select_form {
1.970 raeburn 2027: my ($def,$name,$hashref,$onchange) = @_;
2028: return unless (ref($hashref) eq 'HASH');
2029: if ($onchange) {
2030: $onchange = ' onchange="'.$onchange.'"';
2031: }
2032: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2033: my @keys;
1.970 raeburn 2034: if (exists($hashref->{'select_form_order'})) {
2035: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2036: } else {
1.970 raeburn 2037: @keys=sort(keys(%{$hashref}));
1.128 albertel 2038: }
1.356 albertel 2039: foreach my $key (@keys) {
2040: $selectform.=
2041: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2042: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2043: ">".$hashref->{$key}."</option>\n";
1.88 www 2044: }
2045: $selectform.="</select>";
2046: return $selectform;
2047: }
2048:
1.475 www 2049: # For display filters
2050:
2051: sub display_filter {
1.1074 raeburn 2052: my ($context) = @_;
1.475 www 2053: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2054: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2055: my $phraseinput = 'hidden';
2056: my $includeinput = 'hidden';
2057: my ($checked,$includetypestext);
2058: if ($env{'form.displayfilter'} eq 'containing') {
2059: $phraseinput = 'text';
2060: if ($context eq 'parmslog') {
2061: $includeinput = 'checkbox';
2062: if ($env{'form.includetypes'}) {
2063: $checked = ' checked="checked"';
2064: }
2065: $includetypestext = &mt('Include parameter types');
2066: }
2067: } else {
2068: $includetypestext = ' ';
2069: }
2070: my ($additional,$secondid,$thirdid);
2071: if ($context eq 'parmslog') {
2072: $additional =
2073: '<label><input type="'.$includeinput.'" name="includetypes"'.
2074: $checked.' name="includetypes" value="1" id="includetypes" />'.
2075: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2076: '</label>';
2077: $secondid = 'includetypes';
2078: $thirdid = 'includetypestext';
2079: }
2080: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2081: '$secondid','$thirdid')";
2082: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2083: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2084: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2085: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2086: &mt('Filter: [_1]',
1.477 www 2087: &select_form($env{'form.displayfilter'},
2088: 'displayfilter',
1.970 raeburn 2089: {'currentfolder' => 'Current folder/page',
1.477 www 2090: 'containing' => 'Containing phrase',
1.1074 raeburn 2091: 'none' => 'None'},$onchange)).' '.
2092: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2093: &HTML::Entities::encode($env{'form.containingphrase'}).
2094: '" />'.$additional;
2095: }
2096:
2097: sub display_filter_js {
2098: my $includetext = &mt('Include parameter types');
2099: return <<"ENDJS";
2100:
2101: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2102: var firstType = 'hidden';
2103: if (setter.options[setter.selectedIndex].value == 'containing') {
2104: firstType = 'text';
2105: }
2106: firstObject = document.getElementById(firstid);
2107: if (typeof(firstObject) == 'object') {
2108: if (firstObject.type != firstType) {
2109: changeInputType(firstObject,firstType);
2110: }
2111: }
2112: if (context == 'parmslog') {
2113: var secondType = 'hidden';
2114: if (firstType == 'text') {
2115: secondType = 'checkbox';
2116: }
2117: secondObject = document.getElementById(secondid);
2118: if (typeof(secondObject) == 'object') {
2119: if (secondObject.type != secondType) {
2120: changeInputType(secondObject,secondType);
2121: }
2122: }
2123: var textItem = document.getElementById(thirdid);
2124: var currtext = textItem.innerHTML;
2125: var newtext;
2126: if (firstType == 'text') {
2127: newtext = '$includetext';
2128: } else {
2129: newtext = ' ';
2130: }
2131: if (currtext != newtext) {
2132: textItem.innerHTML = newtext;
2133: }
2134: }
2135: return;
2136: }
2137:
2138: function changeInputType(oldObject,newType) {
2139: var newObject = document.createElement('input');
2140: newObject.type = newType;
2141: if (oldObject.size) {
2142: newObject.size = oldObject.size;
2143: }
2144: if (oldObject.value) {
2145: newObject.value = oldObject.value;
2146: }
2147: if (oldObject.name) {
2148: newObject.name = oldObject.name;
2149: }
2150: if (oldObject.id) {
2151: newObject.id = oldObject.id;
2152: }
2153: oldObject.parentNode.replaceChild(newObject,oldObject);
2154: return;
2155: }
2156:
2157: ENDJS
1.475 www 2158: }
2159:
1.167 www 2160: sub gradeleveldescription {
2161: my $gradelevel=shift;
2162: my %gradelevels=(0 => 'Not specified',
2163: 1 => 'Grade 1',
2164: 2 => 'Grade 2',
2165: 3 => 'Grade 3',
2166: 4 => 'Grade 4',
2167: 5 => 'Grade 5',
2168: 6 => 'Grade 6',
2169: 7 => 'Grade 7',
2170: 8 => 'Grade 8',
2171: 9 => 'Grade 9',
2172: 10 => 'Grade 10',
2173: 11 => 'Grade 11',
2174: 12 => 'Grade 12',
2175: 13 => 'Grade 13',
2176: 14 => '100 Level',
2177: 15 => '200 Level',
2178: 16 => '300 Level',
2179: 17 => '400 Level',
2180: 18 => 'Graduate Level');
2181: return &mt($gradelevels{$gradelevel});
2182: }
2183:
1.163 www 2184: sub select_level_form {
2185: my ($deflevel,$name)=@_;
2186: unless ($deflevel) { $deflevel=0; }
1.167 www 2187: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2188: for (my $i=0; $i<=18; $i++) {
2189: $selectform.="<option value=\"$i\" ".
1.253 albertel 2190: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2191: ">".&gradeleveldescription($i)."</option>\n";
2192: }
2193: $selectform.="</select>";
2194: return $selectform;
1.163 www 2195: }
1.167 www 2196:
1.35 matthew 2197: #-------------------------------------------
2198:
1.45 matthew 2199: =pod
2200:
1.1121 raeburn 2201: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2202:
2203: Returns a string containing a <select name='$name' size='1'> form to
2204: allow a user to select the domain to preform an operation in.
2205: See loncreateuser.pm for an example invocation and use.
2206:
1.90 www 2207: If the $includeempty flag is set, it also includes an empty choice ("no domain
2208: selected");
2209:
1.743 raeburn 2210: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2211:
1.910 raeburn 2212: 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.
2213:
1.1121 raeburn 2214: The optional $incdoms is a reference to an array of domains which will be the only available options.
2215:
2216: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2217:
1.35 matthew 2218: =cut
2219:
2220: #-------------------------------------------
1.34 matthew 2221: sub select_dom_form {
1.1121 raeburn 2222: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2223: if ($onchange) {
1.874 raeburn 2224: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2225: }
1.1121 raeburn 2226: my (@domains,%exclude);
1.910 raeburn 2227: if (ref($incdoms) eq 'ARRAY') {
2228: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2229: } else {
2230: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2231: }
1.90 www 2232: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2233: if (ref($excdoms) eq 'ARRAY') {
2234: map { $exclude{$_} = 1; } @{$excdoms};
2235: }
1.743 raeburn 2236: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2237: foreach my $dom (@domains) {
1.1121 raeburn 2238: next if ($exclude{$dom});
1.356 albertel 2239: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2240: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2241: if ($showdomdesc) {
2242: if ($dom ne '') {
2243: my $domdesc = &Apache::lonnet::domain($dom,'description');
2244: if ($domdesc ne '') {
2245: $selectdomain .= ' ('.$domdesc.')';
2246: }
2247: }
2248: }
2249: $selectdomain .= "</option>\n";
1.34 matthew 2250: }
2251: $selectdomain.="</select>";
2252: return $selectdomain;
2253: }
2254:
1.35 matthew 2255: #-------------------------------------------
2256:
1.45 matthew 2257: =pod
2258:
1.648 raeburn 2259: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2260:
1.586 raeburn 2261: input: 4 arguments (two required, two optional) -
2262: $domain - domain of new user
2263: $name - name of form element
2264: $default - Value of 'default' causes a default item to be first
2265: option, and selected by default.
2266: $hide - Value of 'hide' causes hiding of the name of the server,
2267: if 1 server found, or default, if 0 found.
1.594 raeburn 2268: output: returns 2 items:
1.586 raeburn 2269: (a) form element which contains either:
2270: (i) <select name="$name">
2271: <option value="$hostid1">$hostid $servers{$hostid}</option>
2272: <option value="$hostid2">$hostid $servers{$hostid}</option>
2273: </select>
2274: form item if there are multiple library servers in $domain, or
2275: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2276: if there is only one library server in $domain.
2277:
2278: (b) number of library servers found.
2279:
2280: See loncreateuser.pm for example of use.
1.35 matthew 2281:
2282: =cut
2283:
2284: #-------------------------------------------
1.586 raeburn 2285: sub home_server_form_item {
2286: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2287: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2288: my $result;
2289: my $numlib = keys(%servers);
2290: if ($numlib > 1) {
2291: $result .= '<select name="'.$name.'" />'."\n";
2292: if ($default) {
1.804 bisitz 2293: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2294: '</option>'."\n";
2295: }
2296: foreach my $hostid (sort(keys(%servers))) {
2297: $result.= '<option value="'.$hostid.'">'.
2298: $hostid.' '.$servers{$hostid}."</option>\n";
2299: }
2300: $result .= '</select>'."\n";
2301: } elsif ($numlib == 1) {
2302: my $hostid;
2303: foreach my $item (keys(%servers)) {
2304: $hostid = $item;
2305: }
2306: $result .= '<input type="hidden" name="'.$name.'" value="'.
2307: $hostid.'" />';
2308: if (!$hide) {
2309: $result .= $hostid.' '.$servers{$hostid};
2310: }
2311: $result .= "\n";
2312: } elsif ($default) {
2313: $result .= '<input type="hidden" name="'.$name.
2314: '" value="default" />';
2315: if (!$hide) {
2316: $result .= &mt('default');
2317: }
2318: $result .= "\n";
1.33 matthew 2319: }
1.586 raeburn 2320: return ($result,$numlib);
1.33 matthew 2321: }
1.112 bowersj2 2322:
2323: =pod
2324:
1.534 albertel 2325: =back
2326:
1.112 bowersj2 2327: =cut
1.87 matthew 2328:
2329: ###############################################################
1.112 bowersj2 2330: ## Decoding User Agent ##
1.87 matthew 2331: ###############################################################
2332:
2333: =pod
2334:
1.112 bowersj2 2335: =head1 Decoding the User Agent
2336:
2337: =over 4
2338:
2339: =item * &decode_user_agent()
1.87 matthew 2340:
2341: Inputs: $r
2342:
2343: Outputs:
2344:
2345: =over 4
2346:
1.112 bowersj2 2347: =item * $httpbrowser
1.87 matthew 2348:
1.112 bowersj2 2349: =item * $clientbrowser
1.87 matthew 2350:
1.112 bowersj2 2351: =item * $clientversion
1.87 matthew 2352:
1.112 bowersj2 2353: =item * $clientmathml
1.87 matthew 2354:
1.112 bowersj2 2355: =item * $clientunicode
1.87 matthew 2356:
1.112 bowersj2 2357: =item * $clientos
1.87 matthew 2358:
1.1137 raeburn 2359: =item * $clientmobile
2360:
1.1141 raeburn 2361: =item * $clientinfo
2362:
1.87 matthew 2363: =back
2364:
1.157 matthew 2365: =back
2366:
1.87 matthew 2367: =cut
2368:
2369: ###############################################################
2370: ###############################################################
2371: sub decode_user_agent {
1.247 albertel 2372: my ($r)=@_;
1.87 matthew 2373: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2374: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2375: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2376: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2377: my $clientbrowser='unknown';
2378: my $clientversion='0';
2379: my $clientmathml='';
2380: my $clientunicode='0';
1.1137 raeburn 2381: my $clientmobile=0;
1.87 matthew 2382: for (my $i=0;$i<=$#browsertype;$i++) {
2383: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2384: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2385: $clientbrowser=$bname;
2386: $httpbrowser=~/$vreg/i;
2387: $clientversion=$1;
2388: $clientmathml=($clientversion>=$minv);
2389: $clientunicode=($clientversion>=$univ);
2390: }
2391: }
2392: my $clientos='unknown';
1.1141 raeburn 2393: my $clientinfo;
1.87 matthew 2394: if (($httpbrowser=~/linux/i) ||
2395: ($httpbrowser=~/unix/i) ||
2396: ($httpbrowser=~/ux/i) ||
2397: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2398: if (($httpbrowser=~/vax/i) ||
2399: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2400: if ($httpbrowser=~/next/i) { $clientos='next'; }
2401: if (($httpbrowser=~/mac/i) ||
2402: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2403: if ($httpbrowser=~/win/i) { $clientos='win'; }
2404: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2405: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2406: $clientmobile=lc($1);
2407: }
1.1141 raeburn 2408: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2409: $clientinfo = 'firefox-'.$1;
2410: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2411: $clientinfo = 'chromeframe-'.$1;
2412: }
1.87 matthew 2413: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 2414: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2415: }
2416:
1.32 matthew 2417: ###############################################################
2418: ## Authentication changing form generation subroutines ##
2419: ###############################################################
2420: ##
2421: ## All of the authform_xxxxxxx subroutines take their inputs in a
2422: ## hash, and have reasonable default values.
2423: ##
2424: ## formname = the name given in the <form> tag.
1.35 matthew 2425: #-------------------------------------------
2426:
1.45 matthew 2427: =pod
2428:
1.112 bowersj2 2429: =head1 Authentication Routines
2430:
2431: =over 4
2432:
1.648 raeburn 2433: =item * &authform_xxxxxx()
1.35 matthew 2434:
2435: The authform_xxxxxx subroutines provide javascript and html forms which
2436: handle some of the conveniences required for authentication forms.
2437: This is not an optimal method, but it works.
2438:
2439: =over 4
2440:
1.112 bowersj2 2441: =item * authform_header
1.35 matthew 2442:
1.112 bowersj2 2443: =item * authform_authorwarning
1.35 matthew 2444:
1.112 bowersj2 2445: =item * authform_nochange
1.35 matthew 2446:
1.112 bowersj2 2447: =item * authform_kerberos
1.35 matthew 2448:
1.112 bowersj2 2449: =item * authform_internal
1.35 matthew 2450:
1.112 bowersj2 2451: =item * authform_filesystem
1.35 matthew 2452:
2453: =back
2454:
1.648 raeburn 2455: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2456:
1.35 matthew 2457: =cut
2458:
2459: #-------------------------------------------
1.32 matthew 2460: sub authform_header{
2461: my %in = (
2462: formname => 'cu',
1.80 albertel 2463: kerb_def_dom => '',
1.32 matthew 2464: @_,
2465: );
2466: $in{'formname'} = 'document.' . $in{'formname'};
2467: my $result='';
1.80 albertel 2468:
2469: #---------------------------------------------- Code for upper case translation
2470: my $Javascript_toUpperCase;
2471: unless ($in{kerb_def_dom}) {
2472: $Javascript_toUpperCase =<<"END";
2473: switch (choice) {
2474: case 'krb': currentform.elements[choicearg].value =
2475: currentform.elements[choicearg].value.toUpperCase();
2476: break;
2477: default:
2478: }
2479: END
2480: } else {
2481: $Javascript_toUpperCase = "";
2482: }
2483:
1.165 raeburn 2484: my $radioval = "'nochange'";
1.591 raeburn 2485: if (defined($in{'curr_authtype'})) {
2486: if ($in{'curr_authtype'} ne '') {
2487: $radioval = "'".$in{'curr_authtype'}."arg'";
2488: }
1.174 matthew 2489: }
1.165 raeburn 2490: my $argfield = 'null';
1.591 raeburn 2491: if (defined($in{'mode'})) {
1.165 raeburn 2492: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2493: if (defined($in{'curr_autharg'})) {
2494: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2495: $argfield = "'$in{'curr_autharg'}'";
2496: }
2497: }
2498: }
2499: }
2500:
1.32 matthew 2501: $result.=<<"END";
2502: var current = new Object();
1.165 raeburn 2503: current.radiovalue = $radioval;
2504: current.argfield = $argfield;
1.32 matthew 2505:
2506: function changed_radio(choice,currentform) {
2507: var choicearg = choice + 'arg';
2508: // If a radio button in changed, we need to change the argfield
2509: if (current.radiovalue != choice) {
2510: current.radiovalue = choice;
2511: if (current.argfield != null) {
2512: currentform.elements[current.argfield].value = '';
2513: }
2514: if (choice == 'nochange') {
2515: current.argfield = null;
2516: } else {
2517: current.argfield = choicearg;
2518: switch(choice) {
2519: case 'krb':
2520: currentform.elements[current.argfield].value =
2521: "$in{'kerb_def_dom'}";
2522: break;
2523: default:
2524: break;
2525: }
2526: }
2527: }
2528: return;
2529: }
1.22 www 2530:
1.32 matthew 2531: function changed_text(choice,currentform) {
2532: var choicearg = choice + 'arg';
2533: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2534: $Javascript_toUpperCase
1.32 matthew 2535: // clear old field
2536: if ((current.argfield != choicearg) && (current.argfield != null)) {
2537: currentform.elements[current.argfield].value = '';
2538: }
2539: current.argfield = choicearg;
2540: }
2541: set_auth_radio_buttons(choice,currentform);
2542: return;
1.20 www 2543: }
1.32 matthew 2544:
2545: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2546: var numauthchoices = currentform.login.length;
2547: if (typeof numauthchoices == "undefined") {
2548: return;
2549: }
1.32 matthew 2550: var i=0;
1.986 raeburn 2551: while (i < numauthchoices) {
1.32 matthew 2552: if (currentform.login[i].value == newvalue) { break; }
2553: i++;
2554: }
1.986 raeburn 2555: if (i == numauthchoices) {
1.32 matthew 2556: return;
2557: }
2558: current.radiovalue = newvalue;
2559: currentform.login[i].checked = true;
2560: return;
2561: }
2562: END
2563: return $result;
2564: }
2565:
1.1106 raeburn 2566: sub authform_authorwarning {
1.32 matthew 2567: my $result='';
1.144 matthew 2568: $result='<i>'.
2569: &mt('As a general rule, only authors or co-authors should be '.
2570: 'filesystem authenticated '.
2571: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2572: return $result;
2573: }
2574:
1.1106 raeburn 2575: sub authform_nochange {
1.32 matthew 2576: my %in = (
2577: formname => 'document.cu',
2578: kerb_def_dom => 'MSU.EDU',
2579: @_,
2580: );
1.1106 raeburn 2581: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2582: my $result;
1.1104 raeburn 2583: if (!$authnum) {
1.1105 raeburn 2584: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2585: } else {
2586: $result = '<label>'.&mt('[_1] Do not change login data',
2587: '<input type="radio" name="login" value="nochange" '.
2588: 'checked="checked" onclick="'.
1.281 albertel 2589: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2590: '</label>';
1.586 raeburn 2591: }
1.32 matthew 2592: return $result;
2593: }
2594:
1.591 raeburn 2595: sub authform_kerberos {
1.32 matthew 2596: my %in = (
2597: formname => 'document.cu',
2598: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2599: kerb_def_auth => 'krb4',
1.32 matthew 2600: @_,
2601: );
1.586 raeburn 2602: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2603: $autharg,$jscall);
1.1106 raeburn 2604: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2605: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2606: $check5 = ' checked="checked"';
1.80 albertel 2607: } else {
1.772 bisitz 2608: $check4 = ' checked="checked"';
1.80 albertel 2609: }
1.165 raeburn 2610: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2611: if (defined($in{'curr_authtype'})) {
2612: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2613: $krbcheck = ' checked="checked"';
1.623 raeburn 2614: if (defined($in{'mode'})) {
2615: if ($in{'mode'} eq 'modifyuser') {
2616: $krbcheck = '';
2617: }
2618: }
1.591 raeburn 2619: if (defined($in{'curr_kerb_ver'})) {
2620: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2621: $check5 = ' checked="checked"';
1.591 raeburn 2622: $check4 = '';
2623: } else {
1.772 bisitz 2624: $check4 = ' checked="checked"';
1.591 raeburn 2625: $check5 = '';
2626: }
1.586 raeburn 2627: }
1.591 raeburn 2628: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2629: $krbarg = $in{'curr_autharg'};
2630: }
1.586 raeburn 2631: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2632: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2633: $result =
2634: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2635: $in{'curr_autharg'},$krbver);
2636: } else {
2637: $result =
2638: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2639: }
2640: return $result;
2641: }
2642: }
2643: } else {
2644: if ($authnum == 1) {
1.784 bisitz 2645: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2646: }
2647: }
1.586 raeburn 2648: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2649: return;
1.587 raeburn 2650: } elsif ($authtype eq '') {
1.591 raeburn 2651: if (defined($in{'mode'})) {
1.587 raeburn 2652: if ($in{'mode'} eq 'modifycourse') {
2653: if ($authnum == 1) {
1.1104 raeburn 2654: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2655: }
2656: }
2657: }
1.586 raeburn 2658: }
2659: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2660: if ($authtype eq '') {
2661: $authtype = '<input type="radio" name="login" value="krb" '.
2662: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2663: $krbcheck.' />';
2664: }
2665: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2666: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2667: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2668: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2669: $in{'curr_authtype'} eq 'krb4')) {
2670: $result .= &mt
1.144 matthew 2671: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2672: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2673: '<label>'.$authtype,
1.281 albertel 2674: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2675: 'value="'.$krbarg.'" '.
1.144 matthew 2676: 'onchange="'.$jscall.'" />',
1.281 albertel 2677: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2678: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2679: '</label>');
1.586 raeburn 2680: } elsif ($can_assign{'krb4'}) {
2681: $result .= &mt
2682: ('[_1] Kerberos authenticated with domain [_2] '.
2683: '[_3] Version 4 [_4]',
2684: '<label>'.$authtype,
2685: '</label><input type="text" size="10" name="krbarg" '.
2686: 'value="'.$krbarg.'" '.
2687: 'onchange="'.$jscall.'" />',
2688: '<label><input type="hidden" name="krbver" value="4" />',
2689: '</label>');
2690: } elsif ($can_assign{'krb5'}) {
2691: $result .= &mt
2692: ('[_1] Kerberos authenticated with domain [_2] '.
2693: '[_3] Version 5 [_4]',
2694: '<label>'.$authtype,
2695: '</label><input type="text" size="10" name="krbarg" '.
2696: 'value="'.$krbarg.'" '.
2697: 'onchange="'.$jscall.'" />',
2698: '<label><input type="hidden" name="krbver" value="5" />',
2699: '</label>');
2700: }
1.32 matthew 2701: return $result;
2702: }
2703:
1.1106 raeburn 2704: sub authform_internal {
1.586 raeburn 2705: my %in = (
1.32 matthew 2706: formname => 'document.cu',
2707: kerb_def_dom => 'MSU.EDU',
2708: @_,
2709: );
1.586 raeburn 2710: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2711: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2712: if (defined($in{'curr_authtype'})) {
2713: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2714: if ($can_assign{'int'}) {
1.772 bisitz 2715: $intcheck = 'checked="checked" ';
1.623 raeburn 2716: if (defined($in{'mode'})) {
2717: if ($in{'mode'} eq 'modifyuser') {
2718: $intcheck = '';
2719: }
2720: }
1.591 raeburn 2721: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2722: $intarg = $in{'curr_autharg'};
2723: }
2724: } else {
2725: $result = &mt('Currently internally authenticated.');
2726: return $result;
1.165 raeburn 2727: }
2728: }
1.586 raeburn 2729: } else {
2730: if ($authnum == 1) {
1.784 bisitz 2731: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2732: }
2733: }
2734: if (!$can_assign{'int'}) {
2735: return;
1.587 raeburn 2736: } elsif ($authtype eq '') {
1.591 raeburn 2737: if (defined($in{'mode'})) {
1.587 raeburn 2738: if ($in{'mode'} eq 'modifycourse') {
2739: if ($authnum == 1) {
1.1104 raeburn 2740: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2741: }
2742: }
2743: }
1.165 raeburn 2744: }
1.586 raeburn 2745: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2746: if ($authtype eq '') {
2747: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2748: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2749: }
1.605 bisitz 2750: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2751: $intarg.'" onchange="'.$jscall.'" />';
2752: $result = &mt
1.144 matthew 2753: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2754: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2755: $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 2756: return $result;
2757: }
2758:
1.1104 raeburn 2759: sub authform_local {
1.32 matthew 2760: my %in = (
2761: formname => 'document.cu',
2762: kerb_def_dom => 'MSU.EDU',
2763: @_,
2764: );
1.586 raeburn 2765: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2766: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2767: if (defined($in{'curr_authtype'})) {
2768: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2769: if ($can_assign{'loc'}) {
1.772 bisitz 2770: $loccheck = 'checked="checked" ';
1.623 raeburn 2771: if (defined($in{'mode'})) {
2772: if ($in{'mode'} eq 'modifyuser') {
2773: $loccheck = '';
2774: }
2775: }
1.591 raeburn 2776: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2777: $locarg = $in{'curr_autharg'};
2778: }
2779: } else {
2780: $result = &mt('Currently using local (institutional) authentication.');
2781: return $result;
1.165 raeburn 2782: }
2783: }
1.586 raeburn 2784: } else {
2785: if ($authnum == 1) {
1.784 bisitz 2786: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2787: }
2788: }
2789: if (!$can_assign{'loc'}) {
2790: return;
1.587 raeburn 2791: } elsif ($authtype eq '') {
1.591 raeburn 2792: if (defined($in{'mode'})) {
1.587 raeburn 2793: if ($in{'mode'} eq 'modifycourse') {
2794: if ($authnum == 1) {
1.1104 raeburn 2795: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2796: }
2797: }
2798: }
1.165 raeburn 2799: }
1.586 raeburn 2800: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2801: if ($authtype eq '') {
2802: $authtype = '<input type="radio" name="login" value="loc" '.
2803: $loccheck.' onchange="'.$jscall.'" onclick="'.
2804: $jscall.'" />';
2805: }
2806: $autharg = '<input type="text" size="10" name="locarg" value="'.
2807: $locarg.'" onchange="'.$jscall.'" />';
2808: $result = &mt('[_1] Local Authentication with argument [_2]',
2809: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2810: return $result;
2811: }
2812:
1.1106 raeburn 2813: sub authform_filesystem {
1.32 matthew 2814: my %in = (
2815: formname => 'document.cu',
2816: kerb_def_dom => 'MSU.EDU',
2817: @_,
2818: );
1.586 raeburn 2819: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2820: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2821: if (defined($in{'curr_authtype'})) {
2822: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2823: if ($can_assign{'fsys'}) {
1.772 bisitz 2824: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2825: if (defined($in{'mode'})) {
2826: if ($in{'mode'} eq 'modifyuser') {
2827: $fsyscheck = '';
2828: }
2829: }
1.586 raeburn 2830: } else {
2831: $result = &mt('Currently Filesystem Authenticated.');
2832: return $result;
2833: }
2834: }
2835: } else {
2836: if ($authnum == 1) {
1.784 bisitz 2837: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2838: }
2839: }
2840: if (!$can_assign{'fsys'}) {
2841: return;
1.587 raeburn 2842: } elsif ($authtype eq '') {
1.591 raeburn 2843: if (defined($in{'mode'})) {
1.587 raeburn 2844: if ($in{'mode'} eq 'modifycourse') {
2845: if ($authnum == 1) {
1.1104 raeburn 2846: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2847: }
2848: }
2849: }
1.586 raeburn 2850: }
2851: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2852: if ($authtype eq '') {
2853: $authtype = '<input type="radio" name="login" value="fsys" '.
2854: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2855: $jscall.'" />';
2856: }
2857: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2858: ' onchange="'.$jscall.'" />';
2859: $result = &mt
1.144 matthew 2860: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2861: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2862: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2863: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2864: 'onchange="'.$jscall.'" />');
1.32 matthew 2865: return $result;
2866: }
2867:
1.586 raeburn 2868: sub get_assignable_auth {
2869: my ($dom) = @_;
2870: if ($dom eq '') {
2871: $dom = $env{'request.role.domain'};
2872: }
2873: my %can_assign = (
2874: krb4 => 1,
2875: krb5 => 1,
2876: int => 1,
2877: loc => 1,
2878: );
2879: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2880: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2881: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2882: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2883: my $context;
2884: if ($env{'request.role'} =~ /^au/) {
2885: $context = 'author';
2886: } elsif ($env{'request.role'} =~ /^dc/) {
2887: $context = 'domain';
2888: } elsif ($env{'request.course.id'}) {
2889: $context = 'course';
2890: }
2891: if ($context) {
2892: if (ref($authhash->{$context}) eq 'HASH') {
2893: %can_assign = %{$authhash->{$context}};
2894: }
2895: }
2896: }
2897: }
2898: my $authnum = 0;
2899: foreach my $key (keys(%can_assign)) {
2900: if ($can_assign{$key}) {
2901: $authnum ++;
2902: }
2903: }
2904: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2905: $authnum --;
2906: }
2907: return ($authnum,%can_assign);
2908: }
2909:
1.80 albertel 2910: ###############################################################
2911: ## Get Kerberos Defaults for Domain ##
2912: ###############################################################
2913: ##
2914: ## Returns default kerberos version and an associated argument
2915: ## as listed in file domain.tab. If not listed, provides
2916: ## appropriate default domain and kerberos version.
2917: ##
2918: #-------------------------------------------
2919:
2920: =pod
2921:
1.648 raeburn 2922: =item * &get_kerberos_defaults()
1.80 albertel 2923:
2924: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2925: version and domain. If not found, it defaults to version 4 and the
2926: domain of the server.
1.80 albertel 2927:
1.648 raeburn 2928: =over 4
2929:
1.80 albertel 2930: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2931:
1.648 raeburn 2932: =back
2933:
2934: =back
2935:
1.80 albertel 2936: =cut
2937:
2938: #-------------------------------------------
2939: sub get_kerberos_defaults {
2940: my $domain=shift;
1.641 raeburn 2941: my ($krbdef,$krbdefdom);
2942: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2943: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2944: $krbdef = $domdefaults{'auth_def'};
2945: $krbdefdom = $domdefaults{'auth_arg_def'};
2946: } else {
1.80 albertel 2947: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2948: my $krbdefdom=$1;
2949: $krbdefdom=~tr/a-z/A-Z/;
2950: $krbdef = "krb4";
2951: }
2952: return ($krbdef,$krbdefdom);
2953: }
1.112 bowersj2 2954:
1.32 matthew 2955:
1.46 matthew 2956: ###############################################################
2957: ## Thesaurus Functions ##
2958: ###############################################################
1.20 www 2959:
1.46 matthew 2960: =pod
1.20 www 2961:
1.112 bowersj2 2962: =head1 Thesaurus Functions
2963:
2964: =over 4
2965:
1.648 raeburn 2966: =item * &initialize_keywords()
1.46 matthew 2967:
2968: Initializes the package variable %Keywords if it is empty. Uses the
2969: package variable $thesaurus_db_file.
2970:
2971: =cut
2972:
2973: ###################################################
2974:
2975: sub initialize_keywords {
2976: return 1 if (scalar keys(%Keywords));
2977: # If we are here, %Keywords is empty, so fill it up
2978: # Make sure the file we need exists...
2979: if (! -e $thesaurus_db_file) {
2980: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2981: " failed because it does not exist");
2982: return 0;
2983: }
2984: # Set up the hash as a database
2985: my %thesaurus_db;
2986: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2987: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2988: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2989: $thesaurus_db_file);
2990: return 0;
2991: }
2992: # Get the average number of appearances of a word.
2993: my $avecount = $thesaurus_db{'average.count'};
2994: # Put keywords (those that appear > average) into %Keywords
2995: while (my ($word,$data)=each (%thesaurus_db)) {
2996: my ($count,undef) = split /:/,$data;
2997: $Keywords{$word}++ if ($count > $avecount);
2998: }
2999: untie %thesaurus_db;
3000: # Remove special values from %Keywords.
1.356 albertel 3001: foreach my $value ('total.count','average.count') {
3002: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3003: }
1.46 matthew 3004: return 1;
3005: }
3006:
3007: ###################################################
3008:
3009: =pod
3010:
1.648 raeburn 3011: =item * &keyword($word)
1.46 matthew 3012:
3013: Returns true if $word is a keyword. A keyword is a word that appears more
3014: than the average number of times in the thesaurus database. Calls
3015: &initialize_keywords
3016:
3017: =cut
3018:
3019: ###################################################
1.20 www 3020:
3021: sub keyword {
1.46 matthew 3022: return if (!&initialize_keywords());
3023: my $word=lc(shift());
3024: $word=~s/\W//g;
3025: return exists($Keywords{$word});
1.20 www 3026: }
1.46 matthew 3027:
3028: ###############################################################
3029:
3030: =pod
1.20 www 3031:
1.648 raeburn 3032: =item * &get_related_words()
1.46 matthew 3033:
1.160 matthew 3034: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3035: an array of words. If the keyword is not in the thesaurus, an empty array
3036: will be returned. The order of the words returned is determined by the
3037: database which holds them.
3038:
3039: Uses global $thesaurus_db_file.
3040:
1.1057 foxr 3041:
1.46 matthew 3042: =cut
3043:
3044: ###############################################################
3045: sub get_related_words {
3046: my $keyword = shift;
3047: my %thesaurus_db;
3048: if (! -e $thesaurus_db_file) {
3049: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3050: "failed because the file does not exist");
3051: return ();
3052: }
3053: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3054: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3055: return ();
3056: }
3057: my @Words=();
1.429 www 3058: my $count=0;
1.46 matthew 3059: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3060: # The first element is the number of times
3061: # the word appears. We do not need it now.
1.429 www 3062: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3063: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3064: my $threshold=$mostfrequentcount/10;
3065: foreach my $possibleword (@RelatedWords) {
3066: my ($word,$wordcount)=split(/\,/,$possibleword);
3067: if ($wordcount>$threshold) {
3068: push(@Words,$word);
3069: $count++;
3070: if ($count>10) { last; }
3071: }
1.20 www 3072: }
3073: }
1.46 matthew 3074: untie %thesaurus_db;
3075: return @Words;
1.14 harris41 3076: }
1.1090 foxr 3077: ###############################################################
3078: #
3079: # Spell checking
3080: #
3081:
3082: =pod
3083:
1.1142 raeburn 3084: =back
3085:
1.1090 foxr 3086: =head1 Spell checking
3087:
3088: =over 4
3089:
3090: =item * &check_spelling($wordlist $language)
3091:
3092: Takes a string containing words and feeds it to an external
3093: spellcheck program via a pipeline. Returns a string containing
3094: them mis-spelled words.
3095:
3096: Parameters:
3097:
3098: =over 4
3099:
3100: =item - $wordlist
3101:
3102: String that will be fed into the spellcheck program.
3103:
3104: =item - $language
3105:
3106: Language string that specifies the language for which the spell
3107: check will be performed.
3108:
3109: =back
3110:
3111: =back
3112:
3113: Note: This sub assumes that aspell is installed.
3114:
3115:
3116: =cut
3117:
1.46 matthew 3118:
1.1090 foxr 3119: sub check_spelling {
3120: my ($wordlist, $language) = @_;
1.1091 foxr 3121: my @misspellings;
3122:
3123: # Generate the speller and set the langauge.
3124: # if explicitly selected:
1.1090 foxr 3125:
1.1091 foxr 3126: my $speller = Text::Aspell->new;
1.1090 foxr 3127: if ($language) {
1.1091 foxr 3128: $speller->set_option('lang', $language);
1.1090 foxr 3129: }
3130:
1.1091 foxr 3131: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3132:
1.1091 foxr 3133: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3134:
1.1091 foxr 3135: foreach my $word (@words) {
3136: if(! $speller->check($word)) {
3137: push(@misspellings, $word);
1.1090 foxr 3138: }
3139: }
1.1091 foxr 3140: return join(' ', @misspellings);
3141:
1.1090 foxr 3142: }
3143:
1.61 www 3144: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3145: =pod
3146:
1.112 bowersj2 3147: =head1 User Name Functions
3148:
3149: =over 4
3150:
1.648 raeburn 3151: =item * &plainname($uname,$udom,$first)
1.81 albertel 3152:
1.112 bowersj2 3153: Takes a users logon name and returns it as a string in
1.226 albertel 3154: "first middle last generation" form
3155: if $first is set to 'lastname' then it returns it as
3156: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3157:
3158: =cut
1.61 www 3159:
1.295 www 3160:
1.81 albertel 3161: ###############################################################
1.61 www 3162: sub plainname {
1.226 albertel 3163: my ($uname,$udom,$first)=@_;
1.537 albertel 3164: return if (!defined($uname) || !defined($udom));
1.295 www 3165: my %names=&getnames($uname,$udom);
1.226 albertel 3166: my $name=&Apache::lonnet::format_name($names{'firstname'},
3167: $names{'middlename'},
3168: $names{'lastname'},
3169: $names{'generation'},$first);
3170: $name=~s/^\s+//;
1.62 www 3171: $name=~s/\s+$//;
3172: $name=~s/\s+/ /g;
1.353 albertel 3173: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3174: return $name;
1.61 www 3175: }
1.66 www 3176:
3177: # -------------------------------------------------------------------- Nickname
1.81 albertel 3178: =pod
3179:
1.648 raeburn 3180: =item * &nickname($uname,$udom)
1.81 albertel 3181:
3182: Gets a users name and returns it as a string as
3183:
3184: ""nickname""
1.66 www 3185:
1.81 albertel 3186: if the user has a nickname or
3187:
3188: "first middle last generation"
3189:
3190: if the user does not
3191:
3192: =cut
1.66 www 3193:
3194: sub nickname {
3195: my ($uname,$udom)=@_;
1.537 albertel 3196: return if (!defined($uname) || !defined($udom));
1.295 www 3197: my %names=&getnames($uname,$udom);
1.68 albertel 3198: my $name=$names{'nickname'};
1.66 www 3199: if ($name) {
3200: $name='"'.$name.'"';
3201: } else {
3202: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3203: $names{'lastname'}.' '.$names{'generation'};
3204: $name=~s/\s+$//;
3205: $name=~s/\s+/ /g;
3206: }
3207: return $name;
3208: }
3209:
1.295 www 3210: sub getnames {
3211: my ($uname,$udom)=@_;
1.537 albertel 3212: return if (!defined($uname) || !defined($udom));
1.433 albertel 3213: if ($udom eq 'public' && $uname eq 'public') {
3214: return ('lastname' => &mt('Public'));
3215: }
1.295 www 3216: my $id=$uname.':'.$udom;
3217: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3218: if ($cached) {
3219: return %{$names};
3220: } else {
3221: my %loadnames=&Apache::lonnet::get('environment',
3222: ['firstname','middlename','lastname','generation','nickname'],
3223: $udom,$uname);
3224: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3225: return %loadnames;
3226: }
3227: }
1.61 www 3228:
1.542 raeburn 3229: # -------------------------------------------------------------------- getemails
1.648 raeburn 3230:
1.542 raeburn 3231: =pod
3232:
1.648 raeburn 3233: =item * &getemails($uname,$udom)
1.542 raeburn 3234:
3235: Gets a user's email information and returns it as a hash with keys:
3236: notification, critnotification, permanentemail
3237:
3238: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3239: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3240:
1.648 raeburn 3241:
1.542 raeburn 3242: =cut
3243:
1.648 raeburn 3244:
1.466 albertel 3245: sub getemails {
3246: my ($uname,$udom)=@_;
3247: if ($udom eq 'public' && $uname eq 'public') {
3248: return;
3249: }
1.467 www 3250: if (!$udom) { $udom=$env{'user.domain'}; }
3251: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3252: my $id=$uname.':'.$udom;
3253: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3254: if ($cached) {
3255: return %{$names};
3256: } else {
3257: my %loadnames=&Apache::lonnet::get('environment',
3258: ['notification','critnotification',
3259: 'permanentemail'],
3260: $udom,$uname);
3261: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3262: return %loadnames;
3263: }
3264: }
3265:
1.551 albertel 3266: sub flush_email_cache {
3267: my ($uname,$udom)=@_;
3268: if (!$udom) { $udom =$env{'user.domain'}; }
3269: if (!$uname) { $uname=$env{'user.name'}; }
3270: return if ($udom eq 'public' && $uname eq 'public');
3271: my $id=$uname.':'.$udom;
3272: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3273: }
3274:
1.728 raeburn 3275: # -------------------------------------------------------------------- getlangs
3276:
3277: =pod
3278:
3279: =item * &getlangs($uname,$udom)
3280:
3281: Gets a user's language preference and returns it as a hash with key:
3282: language.
3283:
3284: =cut
3285:
3286:
3287: sub getlangs {
3288: my ($uname,$udom) = @_;
3289: if (!$udom) { $udom =$env{'user.domain'}; }
3290: if (!$uname) { $uname=$env{'user.name'}; }
3291: my $id=$uname.':'.$udom;
3292: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3293: if ($cached) {
3294: return %{$langs};
3295: } else {
3296: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3297: $udom,$uname);
3298: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3299: return %loadlangs;
3300: }
3301: }
3302:
3303: sub flush_langs_cache {
3304: my ($uname,$udom)=@_;
3305: if (!$udom) { $udom =$env{'user.domain'}; }
3306: if (!$uname) { $uname=$env{'user.name'}; }
3307: return if ($udom eq 'public' && $uname eq 'public');
3308: my $id=$uname.':'.$udom;
3309: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3310: }
3311:
1.61 www 3312: # ------------------------------------------------------------------ Screenname
1.81 albertel 3313:
3314: =pod
3315:
1.648 raeburn 3316: =item * &screenname($uname,$udom)
1.81 albertel 3317:
3318: Gets a users screenname and returns it as a string
3319:
3320: =cut
1.61 www 3321:
3322: sub screenname {
3323: my ($uname,$udom)=@_;
1.258 albertel 3324: if ($uname eq $env{'user.name'} &&
3325: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3326: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3327: return $names{'screenname'};
1.62 www 3328: }
3329:
1.212 albertel 3330:
1.802 bisitz 3331: # ------------------------------------------------------------- Confirm Wrapper
3332: =pod
3333:
1.1142 raeburn 3334: =item * &confirmwrapper($message)
1.802 bisitz 3335:
3336: Wrap messages about completion of operation in box
3337:
3338: =cut
3339:
3340: sub confirmwrapper {
3341: my ($message)=@_;
3342: if ($message) {
3343: return "\n".'<div class="LC_confirm_box">'."\n"
3344: .$message."\n"
3345: .'</div>'."\n";
3346: } else {
3347: return $message;
3348: }
3349: }
3350:
1.62 www 3351: # ------------------------------------------------------------- Message Wrapper
3352:
3353: sub messagewrapper {
1.369 www 3354: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3355: return
1.441 albertel 3356: '<a href="/adm/email?compose=individual&'.
3357: 'recname='.$username.'&recdom='.$domain.
3358: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3359: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3360: }
1.802 bisitz 3361:
1.74 www 3362: # --------------------------------------------------------------- Notes Wrapper
3363:
3364: sub noteswrapper {
3365: my ($link,$un,$do)=@_;
3366: return
1.896 amueller 3367: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3368: }
1.802 bisitz 3369:
1.62 www 3370: # ------------------------------------------------------------- Aboutme Wrapper
3371:
3372: sub aboutmewrapper {
1.1070 raeburn 3373: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3374: if (!defined($username) && !defined($domain)) {
3375: return;
3376: }
1.1096 raeburn 3377: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3378: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3379: }
3380:
3381: # ------------------------------------------------------------ Syllabus Wrapper
3382:
3383: sub syllabuswrapper {
1.707 bisitz 3384: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3385: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3386: }
1.14 harris41 3387:
1.802 bisitz 3388: # -----------------------------------------------------------------------------
3389:
1.208 matthew 3390: sub track_student_link {
1.887 raeburn 3391: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3392: my $link ="/adm/trackstudent?";
1.208 matthew 3393: my $title = 'View recent activity';
3394: if (defined($sname) && $sname !~ /^\s*$/ &&
3395: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3396: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3397: $title .= ' of this student';
1.268 albertel 3398: }
1.208 matthew 3399: if (defined($target) && $target !~ /^\s*$/) {
3400: $target = qq{target="$target"};
3401: } else {
3402: $target = '';
3403: }
1.268 albertel 3404: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3405: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3406: $title = &mt($title);
3407: $linktext = &mt($linktext);
1.448 albertel 3408: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3409: &help_open_topic('View_recent_activity');
1.208 matthew 3410: }
3411:
1.781 raeburn 3412: sub slot_reservations_link {
3413: my ($linktext,$sname,$sdom,$target) = @_;
3414: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3415: my $title = 'View slot reservation history';
3416: if (defined($sname) && $sname !~ /^\s*$/ &&
3417: defined($sdom) && $sdom !~ /^\s*$/) {
3418: $link .= "&uname=$sname&udom=$sdom";
3419: $title .= ' of this student';
3420: }
3421: if (defined($target) && $target !~ /^\s*$/) {
3422: $target = qq{target="$target"};
3423: } else {
3424: $target = '';
3425: }
3426: $title = &mt($title);
3427: $linktext = &mt($linktext);
3428: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3429: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3430:
3431: }
3432:
1.508 www 3433: # ===================================================== Display a student photo
3434:
3435:
1.509 albertel 3436: sub student_image_tag {
1.508 www 3437: my ($domain,$user)=@_;
3438: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3439: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3440: return '<img src="'.$imgsrc.'" align="right" />';
3441: } else {
3442: return '';
3443: }
3444: }
3445:
1.112 bowersj2 3446: =pod
3447:
3448: =back
3449:
3450: =head1 Access .tab File Data
3451:
3452: =over 4
3453:
1.648 raeburn 3454: =item * &languageids()
1.112 bowersj2 3455:
3456: returns list of all language ids
3457:
3458: =cut
3459:
1.14 harris41 3460: sub languageids {
1.16 harris41 3461: return sort(keys(%language));
1.14 harris41 3462: }
3463:
1.112 bowersj2 3464: =pod
3465:
1.648 raeburn 3466: =item * &languagedescription()
1.112 bowersj2 3467:
3468: returns description of a specified language id
3469:
3470: =cut
3471:
1.14 harris41 3472: sub languagedescription {
1.125 www 3473: my $code=shift;
3474: return ($supported_language{$code}?'* ':'').
3475: $language{$code}.
1.126 www 3476: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3477: }
3478:
1.1048 foxr 3479: =pod
3480:
3481: =item * &plainlanguagedescription
3482:
3483: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3484: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3485:
3486: =cut
3487:
1.145 www 3488: sub plainlanguagedescription {
3489: my $code=shift;
3490: return $language{$code};
3491: }
3492:
1.1048 foxr 3493: =pod
3494:
3495: =item * &supportedlanguagecode
3496:
3497: Returns the supported language code (e.g. sptutf maps to pt) given a language
3498: code.
3499:
3500: =cut
3501:
1.145 www 3502: sub supportedlanguagecode {
3503: my $code=shift;
3504: return $supported_language{$code};
1.97 www 3505: }
3506:
1.112 bowersj2 3507: =pod
3508:
1.1048 foxr 3509: =item * &latexlanguage()
3510:
3511: Given a language key code returns the correspondnig language to use
3512: to select the correct hyphenation on LaTeX printouts. This is undef if there
3513: is no supported hyphenation for the language code.
3514:
3515: =cut
3516:
3517: sub latexlanguage {
3518: my $code = shift;
3519: return $latex_language{$code};
3520: }
3521:
3522: =pod
3523:
3524: =item * &latexhyphenation()
3525:
3526: Same as above but what's supplied is the language as it might be stored
3527: in the metadata.
3528:
3529: =cut
3530:
3531: sub latexhyphenation {
3532: my $key = shift;
3533: return $latex_language_bykey{$key};
3534: }
3535:
3536: =pod
3537:
1.648 raeburn 3538: =item * ©rightids()
1.112 bowersj2 3539:
3540: returns list of all copyrights
3541:
3542: =cut
3543:
3544: sub copyrightids {
3545: return sort(keys(%cprtag));
3546: }
3547:
3548: =pod
3549:
1.648 raeburn 3550: =item * ©rightdescription()
1.112 bowersj2 3551:
3552: returns description of a specified copyright id
3553:
3554: =cut
3555:
3556: sub copyrightdescription {
1.166 www 3557: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3558: }
1.197 matthew 3559:
3560: =pod
3561:
1.648 raeburn 3562: =item * &source_copyrightids()
1.192 taceyjo1 3563:
3564: returns list of all source copyrights
3565:
3566: =cut
3567:
3568: sub source_copyrightids {
3569: return sort(keys(%scprtag));
3570: }
3571:
3572: =pod
3573:
1.648 raeburn 3574: =item * &source_copyrightdescription()
1.192 taceyjo1 3575:
3576: returns description of a specified source copyright id
3577:
3578: =cut
3579:
3580: sub source_copyrightdescription {
3581: return &mt($scprtag{shift(@_)});
3582: }
1.112 bowersj2 3583:
3584: =pod
3585:
1.648 raeburn 3586: =item * &filecategories()
1.112 bowersj2 3587:
3588: returns list of all file categories
3589:
3590: =cut
3591:
3592: sub filecategories {
3593: return sort(keys(%category_extensions));
3594: }
3595:
3596: =pod
3597:
1.648 raeburn 3598: =item * &filecategorytypes()
1.112 bowersj2 3599:
3600: returns list of file types belonging to a given file
3601: category
3602:
3603: =cut
3604:
3605: sub filecategorytypes {
1.356 albertel 3606: my ($cat) = @_;
3607: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3608: }
3609:
3610: =pod
3611:
1.648 raeburn 3612: =item * &fileembstyle()
1.112 bowersj2 3613:
3614: returns embedding style for a specified file type
3615:
3616: =cut
3617:
3618: sub fileembstyle {
3619: return $fe{lc(shift(@_))};
1.169 www 3620: }
3621:
1.351 www 3622: sub filemimetype {
3623: return $fm{lc(shift(@_))};
3624: }
3625:
1.169 www 3626:
3627: sub filecategoryselect {
3628: my ($name,$value)=@_;
1.189 matthew 3629: return &select_form($value,$name,
1.970 raeburn 3630: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3631: }
3632:
3633: =pod
3634:
1.648 raeburn 3635: =item * &filedescription()
1.112 bowersj2 3636:
3637: returns description for a specified file type
3638:
3639: =cut
3640:
3641: sub filedescription {
1.188 matthew 3642: my $file_description = $fd{lc(shift())};
3643: $file_description =~ s:([\[\]]):~$1:g;
3644: return &mt($file_description);
1.112 bowersj2 3645: }
3646:
3647: =pod
3648:
1.648 raeburn 3649: =item * &filedescriptionex()
1.112 bowersj2 3650:
3651: returns description for a specified file type with
3652: extra formatting
3653:
3654: =cut
3655:
3656: sub filedescriptionex {
3657: my $ex=shift;
1.188 matthew 3658: my $file_description = $fd{lc($ex)};
3659: $file_description =~ s:([\[\]]):~$1:g;
3660: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3661: }
3662:
3663: # End of .tab access
3664: =pod
3665:
3666: =back
3667:
3668: =cut
3669:
3670: # ------------------------------------------------------------------ File Types
3671: sub fileextensions {
3672: return sort(keys(%fe));
3673: }
3674:
1.97 www 3675: # ----------------------------------------------------------- Display Languages
3676: # returns a hash with all desired display languages
3677: #
3678:
3679: sub display_languages {
3680: my %languages=();
1.695 raeburn 3681: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3682: $languages{$lang}=1;
1.97 www 3683: }
3684: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3685: if ($env{'form.displaylanguage'}) {
1.356 albertel 3686: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3687: $languages{$lang}=1;
1.97 www 3688: }
3689: }
3690: return %languages;
1.14 harris41 3691: }
3692:
1.582 albertel 3693: sub languages {
3694: my ($possible_langs) = @_;
1.695 raeburn 3695: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3696: if (!ref($possible_langs)) {
3697: if( wantarray ) {
3698: return @preferred_langs;
3699: } else {
3700: return $preferred_langs[0];
3701: }
3702: }
3703: my %possibilities = map { $_ => 1 } (@$possible_langs);
3704: my @preferred_possibilities;
3705: foreach my $preferred_lang (@preferred_langs) {
3706: if (exists($possibilities{$preferred_lang})) {
3707: push(@preferred_possibilities, $preferred_lang);
3708: }
3709: }
3710: if( wantarray ) {
3711: return @preferred_possibilities;
3712: }
3713: return $preferred_possibilities[0];
3714: }
3715:
1.742 raeburn 3716: sub user_lang {
3717: my ($touname,$toudom,$fromcid) = @_;
3718: my @userlangs;
3719: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3720: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3721: $env{'course.'.$fromcid.'.languages'}));
3722: } else {
3723: my %langhash = &getlangs($touname,$toudom);
3724: if ($langhash{'languages'} ne '') {
3725: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3726: } else {
3727: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3728: if ($domdefs{'lang_def'} ne '') {
3729: @userlangs = ($domdefs{'lang_def'});
3730: }
3731: }
3732: }
3733: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3734: my $user_lh = Apache::localize->get_handle(@languages);
3735: return $user_lh;
3736: }
3737:
3738:
1.112 bowersj2 3739: ###############################################################
3740: ## Student Answer Attempts ##
3741: ###############################################################
3742:
3743: =pod
3744:
3745: =head1 Alternate Problem Views
3746:
3747: =over 4
3748:
1.648 raeburn 3749: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3750: $getattempt, $regexp, $gradesub)
3751:
3752: Return string with previous attempt on problem. Arguments:
3753:
3754: =over 4
3755:
3756: =item * $symb: Problem, including path
3757:
3758: =item * $username: username of the desired student
3759:
3760: =item * $domain: domain of the desired student
1.14 harris41 3761:
1.112 bowersj2 3762: =item * $course: Course ID
1.14 harris41 3763:
1.112 bowersj2 3764: =item * $getattempt: Leave blank for all attempts, otherwise put
3765: something
1.14 harris41 3766:
1.112 bowersj2 3767: =item * $regexp: if string matches this regexp, the string will be
3768: sent to $gradesub
1.14 harris41 3769:
1.112 bowersj2 3770: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3771:
1.112 bowersj2 3772: =back
1.14 harris41 3773:
1.112 bowersj2 3774: The output string is a table containing all desired attempts, if any.
1.16 harris41 3775:
1.112 bowersj2 3776: =cut
1.1 albertel 3777:
3778: sub get_previous_attempt {
1.43 ng 3779: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3780: my $prevattempts='';
1.43 ng 3781: no strict 'refs';
1.1 albertel 3782: if ($symb) {
1.3 albertel 3783: my (%returnhash)=
3784: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3785: if ($returnhash{'version'}) {
3786: my %lasthash=();
3787: my $version;
3788: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3789: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3790: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3791: }
1.1 albertel 3792: }
1.596 albertel 3793: $prevattempts=&start_data_table().&start_data_table_header_row();
3794: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3795: my (%typeparts,%lasthidden);
1.945 raeburn 3796: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3797: foreach my $key (sort(keys(%lasthash))) {
3798: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3799: if ($#parts > 0) {
1.31 albertel 3800: my $data=$parts[-1];
1.989 raeburn 3801: next if ($data eq 'foilorder');
1.31 albertel 3802: pop(@parts);
1.1010 www 3803: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3804: if ($data eq 'type') {
3805: unless ($showsurv) {
3806: my $id = join(',',@parts);
3807: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3808: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3809: $lasthidden{$ign.'.'.$id} = 1;
3810: }
1.945 raeburn 3811: }
1.1010 www 3812: }
1.31 albertel 3813: } else {
1.41 ng 3814: if ($#parts == 0) {
3815: $prevattempts.='<th>'.$parts[0].'</th>';
3816: } else {
3817: $prevattempts.='<th>'.$ign.'</th>';
3818: }
1.31 albertel 3819: }
1.16 harris41 3820: }
1.596 albertel 3821: $prevattempts.=&end_data_table_header_row();
1.40 ng 3822: if ($getattempt eq '') {
3823: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3824: my @hidden;
3825: if (%typeparts) {
3826: foreach my $id (keys(%typeparts)) {
3827: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3828: push(@hidden,$id);
3829: }
3830: }
3831: }
3832: $prevattempts.=&start_data_table_row().
3833: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3834: if (@hidden) {
3835: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3836: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3837: my $hide;
3838: foreach my $id (@hidden) {
3839: if ($key =~ /^\Q$id\E/) {
3840: $hide = 1;
3841: last;
3842: }
3843: }
3844: if ($hide) {
3845: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3846: if (($data eq 'award') || ($data eq 'awarddetail')) {
3847: my $value = &format_previous_attempt_value($key,
3848: $returnhash{$version.':'.$key});
1.1173 ! kruse 3849: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3850: } else {
3851: $prevattempts.='<td> </td>';
3852: }
3853: } else {
3854: if ($key =~ /\./) {
3855: my $value = &format_previous_attempt_value($key,
3856: $returnhash{$version.':'.$key});
1.1173 ! kruse 3857: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3858: } else {
3859: $prevattempts.='<td> </td>';
3860: }
3861: }
3862: }
3863: } else {
3864: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3865: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3866: my $value = &format_previous_attempt_value($key,
3867: $returnhash{$version.':'.$key});
1.1173 ! kruse 3868: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3869: }
3870: }
3871: $prevattempts.=&end_data_table_row();
1.40 ng 3872: }
1.1 albertel 3873: }
1.945 raeburn 3874: my @currhidden = keys(%lasthidden);
1.596 albertel 3875: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3876: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3877: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3878: if (%typeparts) {
3879: my $hidden;
3880: foreach my $id (@currhidden) {
3881: if ($key =~ /^\Q$id\E/) {
3882: $hidden = 1;
3883: last;
3884: }
3885: }
3886: if ($hidden) {
3887: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3888: if (($data eq 'award') || ($data eq 'awarddetail')) {
3889: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3890: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3891: $value = &$gradesub($value);
3892: }
1.1173 ! kruse 3893: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 3894: } else {
3895: $prevattempts.='<td> </td>';
3896: }
3897: } else {
3898: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3899: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3900: $value = &$gradesub($value);
3901: }
1.1173 ! kruse 3902: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3903: }
3904: } else {
3905: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3906: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3907: $value = &$gradesub($value);
3908: }
1.1173 ! kruse 3909: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3910: }
1.16 harris41 3911: }
1.596 albertel 3912: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3913: } else {
1.596 albertel 3914: $prevattempts=
3915: &start_data_table().&start_data_table_row().
3916: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3917: &end_data_table_row().&end_data_table();
1.1 albertel 3918: }
3919: } else {
1.596 albertel 3920: $prevattempts=
3921: &start_data_table().&start_data_table_row().
3922: '<td>'.&mt('No data.').'</td>'.
3923: &end_data_table_row().&end_data_table();
1.1 albertel 3924: }
1.10 albertel 3925: }
3926:
1.581 albertel 3927: sub format_previous_attempt_value {
3928: my ($key,$value) = @_;
1.1011 www 3929: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 ! kruse 3930: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 3931: } elsif (ref($value) eq 'ARRAY') {
1.1173 ! kruse 3932: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 3933: } elsif ($key =~ /answerstring$/) {
3934: my %answers = &Apache::lonnet::str2hash($value);
1.1173 ! kruse 3935: my @answer = %answers;
! 3936: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 3937: my @anskeys = sort(keys(%answers));
3938: if (@anskeys == 1) {
3939: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3940: if ($answer =~ m{\0}) {
3941: $answer =~ s{\0}{,}g;
1.988 raeburn 3942: }
3943: my $tag_internal_answer_name = 'INTERNAL';
3944: if ($anskeys[0] eq $tag_internal_answer_name) {
3945: $value = $answer;
3946: } else {
3947: $value = $anskeys[0].'='.$answer;
3948: }
3949: } else {
3950: foreach my $ans (@anskeys) {
3951: my $answer = $answers{$ans};
1.1001 raeburn 3952: if ($answer =~ m{\0}) {
3953: $answer =~ s{\0}{,}g;
1.988 raeburn 3954: }
3955: $value .= $ans.'='.$answer.'<br />';;
3956: }
3957: }
1.581 albertel 3958: } else {
1.1173 ! kruse 3959: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 3960: }
3961: return $value;
3962: }
3963:
3964:
1.107 albertel 3965: sub relative_to_absolute {
3966: my ($url,$output)=@_;
3967: my $parser=HTML::TokeParser->new(\$output);
3968: my $token;
3969: my $thisdir=$url;
3970: my @rlinks=();
3971: while ($token=$parser->get_token) {
3972: if ($token->[0] eq 'S') {
3973: if ($token->[1] eq 'a') {
3974: if ($token->[2]->{'href'}) {
3975: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3976: }
3977: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3978: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3979: } elsif ($token->[1] eq 'base') {
3980: $thisdir=$token->[2]->{'href'};
3981: }
3982: }
3983: }
3984: $thisdir=~s-/[^/]*$--;
1.356 albertel 3985: foreach my $link (@rlinks) {
1.726 raeburn 3986: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3987: ($link=~/^\//) ||
3988: ($link=~/^javascript:/i) ||
3989: ($link=~/^mailto:/i) ||
3990: ($link=~/^\#/)) {
3991: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3992: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3993: }
3994: }
3995: # -------------------------------------------------- Deal with Applet codebases
3996: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3997: return $output;
3998: }
3999:
1.112 bowersj2 4000: =pod
4001:
1.648 raeburn 4002: =item * &get_student_view()
1.112 bowersj2 4003:
4004: show a snapshot of what student was looking at
4005:
4006: =cut
4007:
1.10 albertel 4008: sub get_student_view {
1.186 albertel 4009: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4010: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4011: my (%form);
1.10 albertel 4012: my @elements=('symb','courseid','domain','username');
4013: foreach my $element (@elements) {
1.186 albertel 4014: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4015: }
1.186 albertel 4016: if (defined($moreenv)) {
4017: %form=(%form,%{$moreenv});
4018: }
1.236 albertel 4019: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4020: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4021: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4022: $userview=~s/\<body[^\>]*\>//gi;
4023: $userview=~s/\<\/body\>//gi;
4024: $userview=~s/\<html\>//gi;
4025: $userview=~s/\<\/html\>//gi;
4026: $userview=~s/\<head\>//gi;
4027: $userview=~s/\<\/head\>//gi;
4028: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4029: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4030: if (wantarray) {
4031: return ($userview,$response);
4032: } else {
4033: return $userview;
4034: }
4035: }
4036:
4037: sub get_student_view_with_retries {
4038: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4039:
4040: my $ok = 0; # True if we got a good response.
4041: my $content;
4042: my $response;
4043:
4044: # Try to get the student_view done. within the retries count:
4045:
4046: do {
4047: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4048: $ok = $response->is_success;
4049: if (!$ok) {
4050: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4051: }
4052: $retries--;
4053: } while (!$ok && ($retries > 0));
4054:
4055: if (!$ok) {
4056: $content = ''; # On error return an empty content.
4057: }
1.651 www 4058: if (wantarray) {
4059: return ($content, $response);
4060: } else {
4061: return $content;
4062: }
1.11 albertel 4063: }
4064:
1.112 bowersj2 4065: =pod
4066:
1.648 raeburn 4067: =item * &get_student_answers()
1.112 bowersj2 4068:
4069: show a snapshot of how student was answering problem
4070:
4071: =cut
4072:
1.11 albertel 4073: sub get_student_answers {
1.100 sakharuk 4074: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4075: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4076: my (%moreenv);
1.11 albertel 4077: my @elements=('symb','courseid','domain','username');
4078: foreach my $element (@elements) {
1.186 albertel 4079: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4080: }
1.186 albertel 4081: $moreenv{'grade_target'}='answer';
4082: %moreenv=(%form,%moreenv);
1.497 raeburn 4083: $feedurl = &Apache::lonnet::clutter($feedurl);
4084: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4085: return $userview;
1.1 albertel 4086: }
1.116 albertel 4087:
4088: =pod
4089:
4090: =item * &submlink()
4091:
1.242 albertel 4092: Inputs: $text $uname $udom $symb $target
1.116 albertel 4093:
4094: Returns: A link to grades.pm such as to see the SUBM view of a student
4095:
4096: =cut
4097:
4098: ###############################################
4099: sub submlink {
1.242 albertel 4100: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4101: if (!($uname && $udom)) {
4102: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4103: &Apache::lonnet::whichuser($symb);
1.116 albertel 4104: if (!$symb) { $symb=$cursymb; }
4105: }
1.254 matthew 4106: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4107: $symb=&escape($symb);
1.960 bisitz 4108: if ($target) { $target=" target=\"$target\""; }
4109: return
4110: '<a href="/adm/grades?command=submission'.
4111: '&symb='.$symb.
4112: '&student='.$uname.
4113: '&userdom='.$udom.'"'.
4114: $target.'>'.$text.'</a>';
1.242 albertel 4115: }
4116: ##############################################
4117:
4118: =pod
4119:
4120: =item * &pgrdlink()
4121:
4122: Inputs: $text $uname $udom $symb $target
4123:
4124: Returns: A link to grades.pm such as to see the PGRD view of a student
4125:
4126: =cut
4127:
4128: ###############################################
4129: sub pgrdlink {
4130: my $link=&submlink(@_);
4131: $link=~s/(&command=submission)/$1&showgrading=yes/;
4132: return $link;
4133: }
4134: ##############################################
4135:
4136: =pod
4137:
4138: =item * &pprmlink()
4139:
4140: Inputs: $text $uname $udom $symb $target
4141:
4142: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4143: student and a specific resource
1.242 albertel 4144:
4145: =cut
4146:
4147: ###############################################
4148: sub pprmlink {
4149: my ($text,$uname,$udom,$symb,$target)=@_;
4150: if (!($uname && $udom)) {
4151: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4152: &Apache::lonnet::whichuser($symb);
1.242 albertel 4153: if (!$symb) { $symb=$cursymb; }
4154: }
1.254 matthew 4155: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4156: $symb=&escape($symb);
1.242 albertel 4157: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4158: return '<a href="/adm/parmset?command=set&'.
4159: 'symb='.$symb.'&uname='.$uname.
4160: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4161: }
4162: ##############################################
1.37 matthew 4163:
1.112 bowersj2 4164: =pod
4165:
4166: =back
4167:
4168: =cut
4169:
1.37 matthew 4170: ###############################################
1.51 www 4171:
4172:
4173: sub timehash {
1.687 raeburn 4174: my ($thistime) = @_;
4175: my $timezone = &Apache::lonlocal::gettimezone();
4176: my $dt = DateTime->from_epoch(epoch => $thistime)
4177: ->set_time_zone($timezone);
4178: my $wday = $dt->day_of_week();
4179: if ($wday == 7) { $wday = 0; }
4180: return ( 'second' => $dt->second(),
4181: 'minute' => $dt->minute(),
4182: 'hour' => $dt->hour(),
4183: 'day' => $dt->day_of_month(),
4184: 'month' => $dt->month(),
4185: 'year' => $dt->year(),
4186: 'weekday' => $wday,
4187: 'dayyear' => $dt->day_of_year(),
4188: 'dlsav' => $dt->is_dst() );
1.51 www 4189: }
4190:
1.370 www 4191: sub utc_string {
4192: my ($date)=@_;
1.371 www 4193: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4194: }
4195:
1.51 www 4196: sub maketime {
4197: my %th=@_;
1.687 raeburn 4198: my ($epoch_time,$timezone,$dt);
4199: $timezone = &Apache::lonlocal::gettimezone();
4200: eval {
4201: $dt = DateTime->new( year => $th{'year'},
4202: month => $th{'month'},
4203: day => $th{'day'},
4204: hour => $th{'hour'},
4205: minute => $th{'minute'},
4206: second => $th{'second'},
4207: time_zone => $timezone,
4208: );
4209: };
4210: if (!$@) {
4211: $epoch_time = $dt->epoch;
4212: if ($epoch_time) {
4213: return $epoch_time;
4214: }
4215: }
1.51 www 4216: return POSIX::mktime(
4217: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4218: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4219: }
4220:
4221: #########################################
1.51 www 4222:
4223: sub findallcourses {
1.482 raeburn 4224: my ($roles,$uname,$udom) = @_;
1.355 albertel 4225: my %roles;
4226: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4227: my %courses;
1.51 www 4228: my $now=time;
1.482 raeburn 4229: if (!defined($uname)) {
4230: $uname = $env{'user.name'};
4231: }
4232: if (!defined($udom)) {
4233: $udom = $env{'user.domain'};
4234: }
4235: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4236: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4237: if (!%roles) {
4238: %roles = (
4239: cc => 1,
1.907 raeburn 4240: co => 1,
1.482 raeburn 4241: in => 1,
4242: ep => 1,
4243: ta => 1,
4244: cr => 1,
4245: st => 1,
4246: );
4247: }
4248: foreach my $entry (keys(%roleshash)) {
4249: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4250: if ($trole =~ /^cr/) {
4251: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4252: } else {
4253: next if (!exists($roles{$trole}));
4254: }
4255: if ($tend) {
4256: next if ($tend < $now);
4257: }
4258: if ($tstart) {
4259: next if ($tstart > $now);
4260: }
1.1058 raeburn 4261: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4262: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4263: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4264: if ($secpart eq '') {
4265: ($cnum,$role) = split(/_/,$cnumpart);
4266: $sec = 'none';
1.1058 raeburn 4267: $value .= $cnum.'/';
1.482 raeburn 4268: } else {
4269: $cnum = $cnumpart;
4270: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4271: $value .= $cnum.'/'.$sec;
4272: }
4273: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4274: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4275: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4276: }
4277: } else {
4278: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4279: }
1.482 raeburn 4280: }
4281: } else {
4282: foreach my $key (keys(%env)) {
1.483 albertel 4283: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4284: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4285: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4286: next if ($role eq 'ca' || $role eq 'aa');
4287: next if (%roles && !exists($roles{$role}));
4288: my ($starttime,$endtime)=split(/\./,$env{$key});
4289: my $active=1;
4290: if ($starttime) {
4291: if ($now<$starttime) { $active=0; }
4292: }
4293: if ($endtime) {
4294: if ($now>$endtime) { $active=0; }
4295: }
4296: if ($active) {
1.1058 raeburn 4297: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4298: if ($sec eq '') {
4299: $sec = 'none';
1.1058 raeburn 4300: } else {
4301: $value .= $sec;
4302: }
4303: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4304: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4305: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4306: }
4307: } else {
4308: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4309: }
1.474 raeburn 4310: }
4311: }
1.51 www 4312: }
4313: }
1.474 raeburn 4314: return %courses;
1.51 www 4315: }
1.37 matthew 4316:
1.54 www 4317: ###############################################
1.474 raeburn 4318:
4319: sub blockcheck {
1.1062 raeburn 4320: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4321:
4322: if (!defined($udom)) {
4323: $udom = $env{'user.domain'};
4324: }
4325: if (!defined($uname)) {
4326: $uname = $env{'user.name'};
4327: }
4328:
4329: # If uname and udom are for a course, check for blocks in the course.
4330:
4331: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4332: my ($startblock,$endblock,$triggerblock) =
4333: &get_blocks($setters,$activity,$udom,$uname,$url);
4334: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4335: }
1.474 raeburn 4336:
1.502 raeburn 4337: my $startblock = 0;
4338: my $endblock = 0;
1.1062 raeburn 4339: my $triggerblock = '';
1.482 raeburn 4340: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4341:
1.490 raeburn 4342: # If uname is for a user, and activity is course-specific, i.e.,
4343: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4344:
1.490 raeburn 4345: if (($activity eq 'boards' || $activity eq 'chat' ||
4346: $activity eq 'groups') && ($env{'request.course.id'})) {
4347: foreach my $key (keys(%live_courses)) {
4348: if ($key ne $env{'request.course.id'}) {
4349: delete($live_courses{$key});
4350: }
4351: }
4352: }
4353:
4354: my $otheruser = 0;
4355: my %own_courses;
4356: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4357: # Resource belongs to user other than current user.
4358: $otheruser = 1;
4359: # Gather courses for current user
4360: %own_courses =
4361: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4362: }
4363:
4364: # Gather active course roles - course coordinator, instructor,
4365: # exam proctor, ta, student, or custom role.
1.474 raeburn 4366:
4367: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4368: my ($cdom,$cnum);
4369: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4370: $cdom = $env{'course.'.$course.'.domain'};
4371: $cnum = $env{'course.'.$course.'.num'};
4372: } else {
1.490 raeburn 4373: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4374: }
4375: my $no_ownblock = 0;
4376: my $no_userblock = 0;
1.533 raeburn 4377: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4378: # Check if current user has 'evb' priv for this
4379: if (defined($own_courses{$course})) {
4380: foreach my $sec (keys(%{$own_courses{$course}})) {
4381: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4382: if ($sec ne 'none') {
4383: $checkrole .= '/'.$sec;
4384: }
4385: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4386: $no_ownblock = 1;
4387: last;
4388: }
4389: }
4390: }
4391: # if they have 'evb' priv and are currently not playing student
4392: next if (($no_ownblock) &&
4393: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4394: }
1.474 raeburn 4395: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4396: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4397: if ($sec ne 'none') {
1.482 raeburn 4398: $checkrole .= '/'.$sec;
1.474 raeburn 4399: }
1.490 raeburn 4400: if ($otheruser) {
4401: # Resource belongs to user other than current user.
4402: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4403: my (%allroles,%userroles);
4404: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4405: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4406: my ($trole,$tdom,$tnum,$tsec);
4407: if ($entry =~ /^cr/) {
4408: ($trole,$tdom,$tnum,$tsec) =
4409: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4410: } else {
4411: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4412: }
4413: my ($spec,$area,$trest);
4414: $area = '/'.$tdom.'/'.$tnum;
4415: $trest = $tnum;
4416: if ($tsec ne '') {
4417: $area .= '/'.$tsec;
4418: $trest .= '/'.$tsec;
4419: }
4420: $spec = $trole.'.'.$area;
4421: if ($trole =~ /^cr/) {
4422: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4423: $tdom,$spec,$trest,$area);
4424: } else {
4425: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4426: $tdom,$spec,$trest,$area);
4427: }
4428: }
4429: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4430: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4431: if ($1) {
4432: $no_userblock = 1;
4433: last;
4434: }
1.486 raeburn 4435: }
4436: }
1.490 raeburn 4437: } else {
4438: # Resource belongs to current user
4439: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4440: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4441: $no_ownblock = 1;
4442: last;
4443: }
1.474 raeburn 4444: }
4445: }
4446: # if they have the evb priv and are currently not playing student
1.482 raeburn 4447: next if (($no_ownblock) &&
1.491 albertel 4448: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4449: next if ($no_userblock);
1.474 raeburn 4450:
1.866 kalberla 4451: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4452: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4453:
1.1062 raeburn 4454: my ($start,$end,$trigger) =
4455: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4456: if (($start != 0) &&
4457: (($startblock == 0) || ($startblock > $start))) {
4458: $startblock = $start;
1.1062 raeburn 4459: if ($trigger ne '') {
4460: $triggerblock = $trigger;
4461: }
1.502 raeburn 4462: }
4463: if (($end != 0) &&
4464: (($endblock == 0) || ($endblock < $end))) {
4465: $endblock = $end;
1.1062 raeburn 4466: if ($trigger ne '') {
4467: $triggerblock = $trigger;
4468: }
1.502 raeburn 4469: }
1.490 raeburn 4470: }
1.1062 raeburn 4471: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4472: }
4473:
4474: sub get_blocks {
1.1062 raeburn 4475: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4476: my $startblock = 0;
4477: my $endblock = 0;
1.1062 raeburn 4478: my $triggerblock = '';
1.490 raeburn 4479: my $course = $cdom.'_'.$cnum;
4480: $setters->{$course} = {};
4481: $setters->{$course}{'staff'} = [];
4482: $setters->{$course}{'times'} = [];
1.1062 raeburn 4483: $setters->{$course}{'triggers'} = [];
4484: my (@blockers,%triggered);
4485: my $now = time;
4486: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4487: if ($activity eq 'docs') {
4488: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4489: foreach my $block (@blockers) {
4490: if ($block =~ /^firstaccess____(.+)$/) {
4491: my $item = $1;
4492: my $type = 'map';
4493: my $timersymb = $item;
4494: if ($item eq 'course') {
4495: $type = 'course';
4496: } elsif ($item =~ /___\d+___/) {
4497: $type = 'resource';
4498: } else {
4499: $timersymb = &Apache::lonnet::symbread($item);
4500: }
4501: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4502: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4503: $triggered{$block} = {
4504: start => $start,
4505: end => $end,
4506: type => $type,
4507: };
4508: }
4509: }
4510: } else {
4511: foreach my $block (keys(%commblocks)) {
4512: if ($block =~ m/^(\d+)____(\d+)$/) {
4513: my ($start,$end) = ($1,$2);
4514: if ($start <= time && $end >= time) {
4515: if (ref($commblocks{$block}) eq 'HASH') {
4516: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4517: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4518: unless(grep(/^\Q$block\E$/,@blockers)) {
4519: push(@blockers,$block);
4520: }
4521: }
4522: }
4523: }
4524: }
4525: } elsif ($block =~ /^firstaccess____(.+)$/) {
4526: my $item = $1;
4527: my $timersymb = $item;
4528: my $type = 'map';
4529: if ($item eq 'course') {
4530: $type = 'course';
4531: } elsif ($item =~ /___\d+___/) {
4532: $type = 'resource';
4533: } else {
4534: $timersymb = &Apache::lonnet::symbread($item);
4535: }
4536: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4537: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4538: if ($start && $end) {
4539: if (($start <= time) && ($end >= time)) {
4540: unless (grep(/^\Q$block\E$/,@blockers)) {
4541: push(@blockers,$block);
4542: $triggered{$block} = {
4543: start => $start,
4544: end => $end,
4545: type => $type,
4546: };
4547: }
4548: }
1.490 raeburn 4549: }
1.1062 raeburn 4550: }
4551: }
4552: }
4553: foreach my $blocker (@blockers) {
4554: my ($staff_name,$staff_dom,$title,$blocks) =
4555: &parse_block_record($commblocks{$blocker});
4556: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4557: my ($start,$end,$triggertype);
4558: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4559: ($start,$end) = ($1,$2);
4560: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4561: $start = $triggered{$blocker}{'start'};
4562: $end = $triggered{$blocker}{'end'};
4563: $triggertype = $triggered{$blocker}{'type'};
4564: }
4565: if ($start) {
4566: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4567: if ($triggertype) {
4568: push(@{$$setters{$course}{'triggers'}},$triggertype);
4569: } else {
4570: push(@{$$setters{$course}{'triggers'}},0);
4571: }
4572: if ( ($startblock == 0) || ($startblock > $start) ) {
4573: $startblock = $start;
4574: if ($triggertype) {
4575: $triggerblock = $blocker;
1.474 raeburn 4576: }
4577: }
1.1062 raeburn 4578: if ( ($endblock == 0) || ($endblock < $end) ) {
4579: $endblock = $end;
4580: if ($triggertype) {
4581: $triggerblock = $blocker;
4582: }
4583: }
1.474 raeburn 4584: }
4585: }
1.1062 raeburn 4586: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4587: }
4588:
4589: sub parse_block_record {
4590: my ($record) = @_;
4591: my ($setuname,$setudom,$title,$blocks);
4592: if (ref($record) eq 'HASH') {
4593: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4594: $title = &unescape($record->{'event'});
4595: $blocks = $record->{'blocks'};
4596: } else {
4597: my @data = split(/:/,$record,3);
4598: if (scalar(@data) eq 2) {
4599: $title = $data[1];
4600: ($setuname,$setudom) = split(/@/,$data[0]);
4601: } else {
4602: ($setuname,$setudom,$title) = @data;
4603: }
4604: $blocks = { 'com' => 'on' };
4605: }
4606: return ($setuname,$setudom,$title,$blocks);
4607: }
4608:
1.854 kalberla 4609: sub blocking_status {
1.1062 raeburn 4610: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4611: my %setters;
1.890 droeschl 4612:
1.1061 raeburn 4613: # check for active blocking
1.1062 raeburn 4614: my ($startblock,$endblock,$triggerblock) =
4615: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4616: my $blocked = 0;
4617: if ($startblock && $endblock) {
4618: $blocked = 1;
4619: }
1.890 droeschl 4620:
1.1061 raeburn 4621: # caller just wants to know whether a block is active
4622: if (!wantarray) { return $blocked; }
4623:
4624: # build a link to a popup window containing the details
4625: my $querystring = "?activity=$activity";
4626: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4627: if ($activity eq 'port') {
4628: $querystring .= "&udom=$udom" if $udom;
4629: $querystring .= "&uname=$uname" if $uname;
4630: } elsif ($activity eq 'docs') {
4631: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4632: }
1.1061 raeburn 4633:
4634: my $output .= <<'END_MYBLOCK';
4635: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4636: var options = "width=" + w + ",height=" + h + ",";
4637: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4638: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4639: var newWin = window.open(url, wdwName, options);
4640: newWin.focus();
4641: }
1.890 droeschl 4642: END_MYBLOCK
1.854 kalberla 4643:
1.1061 raeburn 4644: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4645:
1.1061 raeburn 4646: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4647: my $text = &mt('Communication Blocked');
4648: if ($activity eq 'docs') {
4649: $text = &mt('Content Access Blocked');
1.1063 raeburn 4650: } elsif ($activity eq 'printout') {
4651: $text = &mt('Printing Blocked');
1.1062 raeburn 4652: }
1.1061 raeburn 4653: $output .= <<"END_BLOCK";
1.867 kalberla 4654: <div class='LC_comblock'>
1.869 kalberla 4655: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4656: title='$text'>
4657: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4658: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4659: title='$text'>$text</a>
1.867 kalberla 4660: </div>
4661:
4662: END_BLOCK
1.474 raeburn 4663:
1.1061 raeburn 4664: return ($blocked, $output);
1.854 kalberla 4665: }
1.490 raeburn 4666:
1.60 matthew 4667: ###############################################
4668:
1.682 raeburn 4669: sub check_ip_acc {
4670: my ($acc)=@_;
4671: &Apache::lonxml::debug("acc is $acc");
4672: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4673: return 1;
4674: }
4675: my $allowed=0;
4676: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4677:
4678: my $name;
4679: foreach my $pattern (split(',',$acc)) {
4680: $pattern =~ s/^\s*//;
4681: $pattern =~ s/\s*$//;
4682: if ($pattern =~ /\*$/) {
4683: #35.8.*
4684: $pattern=~s/\*//;
4685: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4686: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4687: #35.8.3.[34-56]
4688: my $low=$2;
4689: my $high=$3;
4690: $pattern=$1;
4691: if ($ip =~ /^\Q$pattern\E/) {
4692: my $last=(split(/\./,$ip))[3];
4693: if ($last <=$high && $last >=$low) { $allowed=1; }
4694: }
4695: } elsif ($pattern =~ /^\*/) {
4696: #*.msu.edu
4697: $pattern=~s/\*//;
4698: if (!defined($name)) {
4699: use Socket;
4700: my $netaddr=inet_aton($ip);
4701: ($name)=gethostbyaddr($netaddr,AF_INET);
4702: }
4703: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4704: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4705: #127.0.0.1
4706: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4707: } else {
4708: #some.name.com
4709: if (!defined($name)) {
4710: use Socket;
4711: my $netaddr=inet_aton($ip);
4712: ($name)=gethostbyaddr($netaddr,AF_INET);
4713: }
4714: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4715: }
4716: if ($allowed) { last; }
4717: }
4718: return $allowed;
4719: }
4720:
4721: ###############################################
4722:
1.60 matthew 4723: =pod
4724:
1.112 bowersj2 4725: =head1 Domain Template Functions
4726:
4727: =over 4
4728:
4729: =item * &determinedomain()
1.60 matthew 4730:
4731: Inputs: $domain (usually will be undef)
4732:
1.63 www 4733: Returns: Determines which domain should be used for designs
1.60 matthew 4734:
4735: =cut
1.54 www 4736:
1.60 matthew 4737: ###############################################
1.63 www 4738: sub determinedomain {
4739: my $domain=shift;
1.531 albertel 4740: if (! $domain) {
1.60 matthew 4741: # Determine domain if we have not been given one
1.893 raeburn 4742: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4743: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4744: if ($env{'request.role.domain'}) {
4745: $domain=$env{'request.role.domain'};
1.60 matthew 4746: }
4747: }
1.63 www 4748: return $domain;
4749: }
4750: ###############################################
1.517 raeburn 4751:
1.518 albertel 4752: sub devalidate_domconfig_cache {
4753: my ($udom)=@_;
4754: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4755: }
4756:
4757: # ---------------------- Get domain configuration for a domain
4758: sub get_domainconf {
4759: my ($udom) = @_;
4760: my $cachetime=1800;
4761: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4762: if (defined($cached)) { return %{$result}; }
4763:
4764: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4765: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4766: my (%designhash,%legacy);
1.518 albertel 4767: if (keys(%domconfig) > 0) {
4768: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4769: if (keys(%{$domconfig{'login'}})) {
4770: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4771: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4772: if ($key eq 'loginvia') {
4773: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4774: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4775: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4776: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4777: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4778: $designhash{$udom.'.login.loginvia'} = $server;
4779: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4780:
4781: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4782: } else {
1.1013 raeburn 4783: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4784: }
4785: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4786: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4787: }
1.946 raeburn 4788: }
4789: }
4790: }
4791: }
4792: } else {
4793: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4794: $designhash{$udom.'.login.'.$key.'_'.$img} =
4795: $domconfig{'login'}{$key}{$img};
4796: }
1.699 raeburn 4797: }
4798: } else {
4799: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4800: }
1.632 raeburn 4801: }
4802: } else {
4803: $legacy{'login'} = 1;
1.518 albertel 4804: }
1.632 raeburn 4805: } else {
4806: $legacy{'login'} = 1;
1.518 albertel 4807: }
4808: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4809: if (keys(%{$domconfig{'rolecolors'}})) {
4810: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4811: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4812: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4813: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4814: }
1.518 albertel 4815: }
4816: }
1.632 raeburn 4817: } else {
4818: $legacy{'rolecolors'} = 1;
1.518 albertel 4819: }
1.632 raeburn 4820: } else {
4821: $legacy{'rolecolors'} = 1;
1.518 albertel 4822: }
1.948 raeburn 4823: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4824: if ($domconfig{'autoenroll'}{'co-owners'}) {
4825: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4826: }
4827: }
1.632 raeburn 4828: if (keys(%legacy) > 0) {
4829: my %legacyhash = &get_legacy_domconf($udom);
4830: foreach my $item (keys(%legacyhash)) {
4831: if ($item =~ /^\Q$udom\E\.login/) {
4832: if ($legacy{'login'}) {
4833: $designhash{$item} = $legacyhash{$item};
4834: }
4835: } else {
4836: if ($legacy{'rolecolors'}) {
4837: $designhash{$item} = $legacyhash{$item};
4838: }
1.518 albertel 4839: }
4840: }
4841: }
1.632 raeburn 4842: } else {
4843: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4844: }
4845: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4846: $cachetime);
4847: return %designhash;
4848: }
4849:
1.632 raeburn 4850: sub get_legacy_domconf {
4851: my ($udom) = @_;
4852: my %legacyhash;
4853: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4854: my $designfile = $designdir.'/'.$udom.'.tab';
4855: if (-e $designfile) {
4856: if ( open (my $fh,"<$designfile") ) {
4857: while (my $line = <$fh>) {
4858: next if ($line =~ /^\#/);
4859: chomp($line);
4860: my ($key,$val)=(split(/\=/,$line));
4861: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4862: }
4863: close($fh);
4864: }
4865: }
1.1026 raeburn 4866: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4867: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4868: }
4869: return %legacyhash;
4870: }
4871:
1.63 www 4872: =pod
4873:
1.112 bowersj2 4874: =item * &domainlogo()
1.63 www 4875:
4876: Inputs: $domain (usually will be undef)
4877:
4878: Returns: A link to a domain logo, if the domain logo exists.
4879: If the domain logo does not exist, a description of the domain.
4880:
4881: =cut
1.112 bowersj2 4882:
1.63 www 4883: ###############################################
4884: sub domainlogo {
1.517 raeburn 4885: my $domain = &determinedomain(shift);
1.518 albertel 4886: my %designhash = &get_domainconf($domain);
1.517 raeburn 4887: # See if there is a logo
4888: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4889: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4890: if ($imgsrc =~ m{^/(adm|res)/}) {
4891: if ($imgsrc =~ m{^/res/}) {
4892: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4893: &Apache::lonnet::repcopy($local_name);
4894: }
4895: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4896: }
4897: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4898: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4899: return &Apache::lonnet::domain($domain,'description');
1.59 www 4900: } else {
1.60 matthew 4901: return '';
1.59 www 4902: }
4903: }
1.63 www 4904: ##############################################
4905:
4906: =pod
4907:
1.112 bowersj2 4908: =item * &designparm()
1.63 www 4909:
4910: Inputs: $which parameter; $domain (usually will be undef)
4911:
4912: Returns: value of designparamter $which
4913:
4914: =cut
1.112 bowersj2 4915:
1.397 albertel 4916:
1.400 albertel 4917: ##############################################
1.397 albertel 4918: sub designparm {
4919: my ($which,$domain)=@_;
4920: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4921: return $env{'environment.color.'.$which};
1.96 www 4922: }
1.63 www 4923: $domain=&determinedomain($domain);
1.1016 raeburn 4924: my %domdesign;
4925: unless ($domain eq 'public') {
4926: %domdesign = &get_domainconf($domain);
4927: }
1.520 raeburn 4928: my $output;
1.517 raeburn 4929: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4930: $output = $domdesign{$domain.'.'.$which};
1.63 www 4931: } else {
1.520 raeburn 4932: $output = $defaultdesign{$which};
4933: }
4934: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4935: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4936: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4937: if ($output =~ m{^/res/}) {
4938: my $local_name = &Apache::lonnet::filelocation('',$output);
4939: &Apache::lonnet::repcopy($local_name);
4940: }
1.520 raeburn 4941: $output = &lonhttpdurl($output);
4942: }
1.63 www 4943: }
1.520 raeburn 4944: return $output;
1.63 www 4945: }
1.59 www 4946:
1.822 bisitz 4947: ##############################################
4948: =pod
4949:
1.832 bisitz 4950: =item * &authorspace()
4951:
1.1028 raeburn 4952: Inputs: $url (usually will be undef).
1.832 bisitz 4953:
1.1132 raeburn 4954: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4955: directory being viewed (or for which action is being taken).
4956: If $url is provided, and begins /priv/<domain>/<uname>
4957: the path will be that portion of the $context argument.
4958: Otherwise the path will be for the author space of the current
4959: user when the current role is author, or for that of the
4960: co-author/assistant co-author space when the current role
4961: is co-author or assistant co-author.
1.832 bisitz 4962:
4963: =cut
4964:
4965: sub authorspace {
1.1028 raeburn 4966: my ($url) = @_;
4967: if ($url ne '') {
4968: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4969: return $1;
4970: }
4971: }
1.832 bisitz 4972: my $caname = '';
1.1024 www 4973: my $cadom = '';
1.1028 raeburn 4974: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4975: ($cadom,$caname) =
1.832 bisitz 4976: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4977: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4978: $caname = $env{'user.name'};
1.1024 www 4979: $cadom = $env{'user.domain'};
1.832 bisitz 4980: }
1.1028 raeburn 4981: if (($caname ne '') && ($cadom ne '')) {
4982: return "/priv/$cadom/$caname/";
4983: }
4984: return;
1.832 bisitz 4985: }
4986:
4987: ##############################################
4988: =pod
4989:
1.822 bisitz 4990: =item * &head_subbox()
4991:
4992: Inputs: $content (contains HTML code with page functions, etc.)
4993:
4994: Returns: HTML div with $content
4995: To be included in page header
4996:
4997: =cut
4998:
4999: sub head_subbox {
5000: my ($content)=@_;
5001: my $output =
1.993 raeburn 5002: '<div class="LC_head_subbox">'
1.822 bisitz 5003: .$content
5004: .'</div>'
5005: }
5006:
5007: ##############################################
5008: =pod
5009:
5010: =item * &CSTR_pageheader()
5011:
1.1026 raeburn 5012: Input: (optional) filename from which breadcrumb trail is built.
5013: In most cases no input as needed, as $env{'request.filename'}
5014: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5015:
5016: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5017: To be included on Authoring Space pages
1.822 bisitz 5018:
5019: =cut
5020:
5021: sub CSTR_pageheader {
1.1026 raeburn 5022: my ($trailfile) = @_;
5023: if ($trailfile eq '') {
5024: $trailfile = $env{'request.filename'};
5025: }
5026:
5027: # this is for resources; directories have customtitle, and crumbs
5028: # and select recent are created in lonpubdir.pm
5029:
5030: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5031: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5032: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5033: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5034: $formaction =~ s{/+}{/}g;
1.822 bisitz 5035:
5036: my $parentpath = '';
5037: my $lastitem = '';
5038: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5039: $parentpath = $1;
5040: $lastitem = $2;
5041: } else {
5042: $lastitem = $thisdisfn;
5043: }
1.921 bisitz 5044:
5045: my $output =
1.822 bisitz 5046: '<div>'
5047: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5048: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5049: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5050: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5051: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5052:
5053: if ($lastitem) {
5054: $output .=
5055: '<span class="LC_filename">'
5056: .$lastitem
5057: .'</span>';
5058: }
5059: $output .=
5060: '<br />'
1.822 bisitz 5061: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5062: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5063: .'</form>'
5064: .&Apache::lonmenu::constspaceform()
5065: .'</div>';
1.921 bisitz 5066:
5067: return $output;
1.822 bisitz 5068: }
5069:
1.60 matthew 5070: ###############################################
5071: ###############################################
5072:
5073: =pod
5074:
1.112 bowersj2 5075: =back
5076:
1.549 albertel 5077: =head1 HTML Helpers
1.112 bowersj2 5078:
5079: =over 4
5080:
5081: =item * &bodytag()
1.60 matthew 5082:
5083: Returns a uniform header for LON-CAPA web pages.
5084:
5085: Inputs:
5086:
1.112 bowersj2 5087: =over 4
5088:
5089: =item * $title, A title to be displayed on the page.
5090:
5091: =item * $function, the current role (can be undef).
5092:
5093: =item * $addentries, extra parameters for the <body> tag.
5094:
5095: =item * $bodyonly, if defined, only return the <body> tag.
5096:
5097: =item * $domain, if defined, force a given domain.
5098:
5099: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5100: text interface only)
1.60 matthew 5101:
1.814 bisitz 5102: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5103: navigational links
1.317 albertel 5104:
1.338 albertel 5105: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5106:
1.460 albertel 5107: =item * $args, optional argument valid values are
5108: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5109: inherit_jsmath -> when creating popup window in a page,
5110: should it have jsmath forced on by the
5111: current page
1.460 albertel 5112:
1.1096 raeburn 5113: =item * $advtoolsref, optional argument, ref to an array containing
5114: inlineremote items to be added in "Functions" menu below
5115: breadcrumbs.
5116:
1.112 bowersj2 5117: =back
5118:
1.60 matthew 5119: Returns: A uniform header for LON-CAPA web pages.
5120: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5121: If $bodyonly is undef or zero, an html string containing a <body> tag and
5122: other decorations will be returned.
5123:
5124: =cut
5125:
1.54 www 5126: sub bodytag {
1.831 bisitz 5127: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5128: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5129:
1.954 raeburn 5130: my $public;
5131: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5132: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5133: $public = 1;
5134: }
1.460 albertel 5135: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5136: my $httphost = $args->{'use_absolute'};
1.339 albertel 5137:
1.183 matthew 5138: $function = &get_users_function() if (!$function);
1.339 albertel 5139: my $img = &designparm($function.'.img',$domain);
5140: my $font = &designparm($function.'.font',$domain);
5141: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5142:
1.803 bisitz 5143: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5144: 'bgcolor' => $pgbg,
1.339 albertel 5145: 'text' => $font,
5146: 'alink' => &designparm($function.'.alink',$domain),
5147: 'vlink' => &designparm($function.'.vlink',$domain),
5148: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5149: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5150:
1.63 www 5151: # role and realm
1.378 raeburn 5152: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5153: if ($role eq 'ca') {
1.479 albertel 5154: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5155: $realm = &plainname($rname,$rdom);
1.378 raeburn 5156: }
1.55 www 5157: # realm
1.258 albertel 5158: if ($env{'request.course.id'}) {
1.378 raeburn 5159: if ($env{'request.role'} !~ /^cr/) {
5160: $role = &Apache::lonnet::plaintext($role,&course_type());
5161: }
1.898 raeburn 5162: if ($env{'request.course.sec'}) {
5163: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5164: }
1.359 albertel 5165: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5166: } else {
5167: $role = &Apache::lonnet::plaintext($role);
1.54 www 5168: }
1.433 albertel 5169:
1.359 albertel 5170: if (!$realm) { $realm=' '; }
1.330 albertel 5171:
1.438 albertel 5172: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5173:
1.101 www 5174: # construct main body tag
1.359 albertel 5175: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5176: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5177:
1.1131 raeburn 5178: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5179:
1.1130 raeburn 5180: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5181: return $bodytag;
1.1130 raeburn 5182: }
1.359 albertel 5183:
1.954 raeburn 5184: if ($public) {
1.433 albertel 5185: undef($role);
5186: }
1.359 albertel 5187:
1.762 bisitz 5188: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5189: #
5190: # Extra info if you are the DC
5191: my $dc_info = '';
5192: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5193: $env{'course.'.$env{'request.course.id'}.
5194: '.domain'}.'/'})) {
5195: my $cid = $env{'request.course.id'};
1.917 raeburn 5196: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5197: $dc_info =~ s/\s+$//;
1.359 albertel 5198: }
5199:
1.898 raeburn 5200: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5201:
1.903 droeschl 5202: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5203:
5204: # if ($env{'request.state'} eq 'construct') {
5205: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5206: # }
5207:
1.1130 raeburn 5208: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5209: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5210:
1.1130 raeburn 5211: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5212:
1.916 droeschl 5213: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5214: if ($dc_info) {
5215: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5216: }
1.1130 raeburn 5217: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5218: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5219: return $bodytag;
5220: }
1.894 droeschl 5221:
1.927 raeburn 5222: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5223: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5224: }
1.916 droeschl 5225:
1.1130 raeburn 5226: $bodytag .= $right;
1.852 droeschl 5227:
1.917 raeburn 5228: if ($dc_info) {
5229: $dc_info = &dc_courseid_toggle($dc_info);
5230: }
5231: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5232:
1.1169 raeburn 5233: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5234: if ($args->{'no_secondary_menu'}) {
5235: return $bodytag;
5236: }
1.1169 raeburn 5237: #don't show menus for public users
1.954 raeburn 5238: if (!$public){
1.1154 raeburn 5239: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5240: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5241: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5242: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5243: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5244: $args->{'bread_crumbs'});
1.1096 raeburn 5245: } elsif ($forcereg) {
5246: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5247: $args->{'group'});
5248: } else {
5249: $bodytag .=
5250: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5251: $forcereg,$args->{'group'},
5252: $args->{'bread_crumbs'},
5253: $advtoolsref);
1.920 raeburn 5254: }
1.903 droeschl 5255: }else{
5256: # this is to seperate menu from content when there's no secondary
5257: # menu. Especially needed for public accessible ressources.
5258: $bodytag .= '<hr style="clear:both" />';
5259: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5260: }
1.903 droeschl 5261:
1.235 raeburn 5262: return $bodytag;
1.182 matthew 5263: }
5264:
1.917 raeburn 5265: sub dc_courseid_toggle {
5266: my ($dc_info) = @_;
1.980 raeburn 5267: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5268: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5269: &mt('(More ...)').'</a></span>'.
5270: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5271: }
5272:
1.330 albertel 5273: sub make_attr_string {
5274: my ($register,$attr_ref) = @_;
5275:
5276: if ($attr_ref && !ref($attr_ref)) {
5277: die("addentries Must be a hash ref ".
5278: join(':',caller(1))." ".
5279: join(':',caller(0))." ");
5280: }
5281:
5282: if ($register) {
1.339 albertel 5283: my ($on_load,$on_unload);
5284: foreach my $key (keys(%{$attr_ref})) {
5285: if (lc($key) eq 'onload') {
5286: $on_load.=$attr_ref->{$key}.';';
5287: delete($attr_ref->{$key});
5288:
5289: } elsif (lc($key) eq 'onunload') {
5290: $on_unload.=$attr_ref->{$key}.';';
5291: delete($attr_ref->{$key});
5292: }
5293: }
1.953 droeschl 5294: $attr_ref->{'onload'} = $on_load;
5295: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5296: }
1.339 albertel 5297:
1.330 albertel 5298: my $attr_string;
1.1159 raeburn 5299: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5300: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5301: }
5302: return $attr_string;
5303: }
5304:
5305:
1.182 matthew 5306: ###############################################
1.251 albertel 5307: ###############################################
5308:
5309: =pod
5310:
5311: =item * &endbodytag()
5312:
5313: Returns a uniform footer for LON-CAPA web pages.
5314:
1.635 raeburn 5315: Inputs: 1 - optional reference to an args hash
5316: If in the hash, key for noredirectlink has a value which evaluates to true,
5317: a 'Continue' link is not displayed if the page contains an
5318: internal redirect in the <head></head> section,
5319: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5320:
5321: =cut
5322:
5323: sub endbodytag {
1.635 raeburn 5324: my ($args) = @_;
1.1080 raeburn 5325: my $endbodytag;
5326: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5327: $endbodytag='</body>';
5328: }
1.269 albertel 5329: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5330: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5331: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5332: $endbodytag=
5333: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5334: &mt('Continue').'</a>'.
5335: $endbodytag;
5336: }
1.315 albertel 5337: }
1.251 albertel 5338: return $endbodytag;
5339: }
5340:
1.352 albertel 5341: =pod
5342:
5343: =item * &standard_css()
5344:
5345: Returns a style sheet
5346:
5347: Inputs: (all optional)
5348: domain -> force to color decorate a page for a specific
5349: domain
5350: function -> force usage of a specific rolish color scheme
5351: bgcolor -> override the default page bgcolor
5352:
5353: =cut
5354:
1.343 albertel 5355: sub standard_css {
1.345 albertel 5356: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5357: $function = &get_users_function() if (!$function);
5358: my $img = &designparm($function.'.img', $domain);
5359: my $tabbg = &designparm($function.'.tabbg', $domain);
5360: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5361: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5362: #second colour for later usage
1.345 albertel 5363: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5364: my $pgbg_or_bgcolor =
5365: $bgcolor ||
1.352 albertel 5366: &designparm($function.'.pgbg', $domain);
1.382 albertel 5367: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5368: my $alink = &designparm($function.'.alink', $domain);
5369: my $vlink = &designparm($function.'.vlink', $domain);
5370: my $link = &designparm($function.'.link', $domain);
5371:
1.602 albertel 5372: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5373: my $mono = 'monospace';
1.850 bisitz 5374: my $data_table_head = $sidebg;
5375: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5376: my $data_table_dark = '#E0E0E0';
1.470 banghart 5377: my $data_table_darker = '#CCCCCC';
1.349 albertel 5378: my $data_table_highlight = '#FFFF00';
1.352 albertel 5379: my $mail_new = '#FFBB77';
5380: my $mail_new_hover = '#DD9955';
5381: my $mail_read = '#BBBB77';
5382: my $mail_read_hover = '#999944';
5383: my $mail_replied = '#AAAA88';
5384: my $mail_replied_hover = '#888855';
5385: my $mail_other = '#99BBBB';
5386: my $mail_other_hover = '#669999';
1.391 albertel 5387: my $table_header = '#DDDDDD';
1.489 raeburn 5388: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5389: my $lg_border_color = '#C8C8C8';
1.952 onken 5390: my $button_hover = '#BF2317';
1.392 albertel 5391:
1.608 albertel 5392: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5393: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5394: : '0 3px 0 4px';
1.448 albertel 5395:
1.523 albertel 5396:
1.343 albertel 5397: return <<END;
1.947 droeschl 5398:
5399: /* needed for iframe to allow 100% height in FF */
5400: body, html {
5401: margin: 0;
5402: padding: 0 0.5%;
5403: height: 99%; /* to avoid scrollbars */
5404: }
5405:
1.795 www 5406: body {
1.911 bisitz 5407: font-family: $sans;
5408: line-height:130%;
5409: font-size:0.83em;
5410: color:$font;
1.795 www 5411: }
5412:
1.959 onken 5413: a:focus,
5414: a:focus img {
1.795 www 5415: color: red;
5416: }
1.698 harmsja 5417:
1.911 bisitz 5418: form, .inline {
5419: display: inline;
1.795 www 5420: }
1.721 harmsja 5421:
1.795 www 5422: .LC_right {
1.911 bisitz 5423: text-align:right;
1.795 www 5424: }
5425:
5426: .LC_middle {
1.911 bisitz 5427: vertical-align:middle;
1.795 www 5428: }
1.721 harmsja 5429:
1.1130 raeburn 5430: .LC_floatleft {
5431: float: left;
5432: }
5433:
5434: .LC_floatright {
5435: float: right;
5436: }
5437:
1.911 bisitz 5438: .LC_400Box {
5439: width:400px;
5440: }
1.721 harmsja 5441:
1.947 droeschl 5442: .LC_iframecontainer {
5443: width: 98%;
5444: margin: 0;
5445: position: fixed;
5446: top: 8.5em;
5447: bottom: 0;
5448: }
5449:
5450: .LC_iframecontainer iframe{
5451: border: none;
5452: width: 100%;
5453: height: 100%;
5454: }
5455:
1.778 bisitz 5456: .LC_filename {
5457: font-family: $mono;
5458: white-space:pre;
1.921 bisitz 5459: font-size: 120%;
1.778 bisitz 5460: }
5461:
5462: .LC_fileicon {
5463: border: none;
5464: height: 1.3em;
5465: vertical-align: text-bottom;
5466: margin-right: 0.3em;
5467: text-decoration:none;
5468: }
5469:
1.1008 www 5470: .LC_setting {
5471: text-decoration:underline;
5472: }
5473:
1.350 albertel 5474: .LC_error {
5475: color: red;
5476: }
1.795 www 5477:
1.1097 bisitz 5478: .LC_warning {
5479: color: darkorange;
5480: }
5481:
1.457 albertel 5482: .LC_diff_removed {
1.733 bisitz 5483: color: red;
1.394 albertel 5484: }
1.532 albertel 5485:
5486: .LC_info,
1.457 albertel 5487: .LC_success,
5488: .LC_diff_added {
1.350 albertel 5489: color: green;
5490: }
1.795 www 5491:
1.802 bisitz 5492: div.LC_confirm_box {
5493: background-color: #FAFAFA;
5494: border: 1px solid $lg_border_color;
5495: margin-right: 0;
5496: padding: 5px;
5497: }
5498:
5499: div.LC_confirm_box .LC_error img,
5500: div.LC_confirm_box .LC_success img {
5501: vertical-align: middle;
5502: }
5503:
1.440 albertel 5504: .LC_icon {
1.771 droeschl 5505: border: none;
1.790 droeschl 5506: vertical-align: middle;
1.771 droeschl 5507: }
5508:
1.543 albertel 5509: .LC_docs_spacer {
5510: width: 25px;
5511: height: 1px;
1.771 droeschl 5512: border: none;
1.543 albertel 5513: }
1.346 albertel 5514:
1.532 albertel 5515: .LC_internal_info {
1.735 bisitz 5516: color: #999999;
1.532 albertel 5517: }
5518:
1.794 www 5519: .LC_discussion {
1.1050 www 5520: background: $data_table_dark;
1.911 bisitz 5521: border: 1px solid black;
5522: margin: 2px;
1.794 www 5523: }
5524:
5525: .LC_disc_action_left {
1.1050 www 5526: background: $sidebg;
1.911 bisitz 5527: text-align: left;
1.1050 www 5528: padding: 4px;
5529: margin: 2px;
1.794 www 5530: }
5531:
5532: .LC_disc_action_right {
1.1050 www 5533: background: $sidebg;
1.911 bisitz 5534: text-align: right;
1.1050 www 5535: padding: 4px;
5536: margin: 2px;
1.794 www 5537: }
5538:
5539: .LC_disc_new_item {
1.911 bisitz 5540: background: white;
5541: border: 2px solid red;
1.1050 www 5542: margin: 4px;
5543: padding: 4px;
1.794 www 5544: }
5545:
5546: .LC_disc_old_item {
1.911 bisitz 5547: background: white;
1.1050 www 5548: margin: 4px;
5549: padding: 4px;
1.794 www 5550: }
5551:
1.458 albertel 5552: table.LC_pastsubmission {
5553: border: 1px solid black;
5554: margin: 2px;
5555: }
5556:
1.924 bisitz 5557: table#LC_menubuttons {
1.345 albertel 5558: width: 100%;
5559: background: $pgbg;
1.392 albertel 5560: border: 2px;
1.402 albertel 5561: border-collapse: separate;
1.803 bisitz 5562: padding: 0;
1.345 albertel 5563: }
1.392 albertel 5564:
1.801 tempelho 5565: table#LC_title_bar a {
5566: color: $fontmenu;
5567: }
1.836 bisitz 5568:
1.807 droeschl 5569: table#LC_title_bar {
1.819 tempelho 5570: clear: both;
1.836 bisitz 5571: display: none;
1.807 droeschl 5572: }
5573:
1.795 www 5574: table#LC_title_bar,
1.933 droeschl 5575: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5576: table#LC_title_bar.LC_with_remote {
1.359 albertel 5577: width: 100%;
1.392 albertel 5578: border-color: $pgbg;
5579: border-style: solid;
5580: border-width: $border;
1.379 albertel 5581: background: $pgbg;
1.801 tempelho 5582: color: $fontmenu;
1.392 albertel 5583: border-collapse: collapse;
1.803 bisitz 5584: padding: 0;
1.819 tempelho 5585: margin: 0;
1.359 albertel 5586: }
1.795 www 5587:
1.933 droeschl 5588: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5589: margin: 0;
5590: padding: 0;
1.933 droeschl 5591: position: relative;
5592: list-style: none;
1.913 droeschl 5593: }
1.933 droeschl 5594: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5595: display: inline;
5596: }
1.933 droeschl 5597:
5598: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5599: padding: 0;
1.933 droeschl 5600: margin: 0;
5601: float: left;
1.913 droeschl 5602: }
1.933 droeschl 5603: .LC_breadcrumb_tools_tools {
5604: padding: 0;
5605: margin: 0;
1.913 droeschl 5606: float: right;
5607: }
5608:
1.359 albertel 5609: table#LC_title_bar td {
5610: background: $tabbg;
5611: }
1.795 www 5612:
1.911 bisitz 5613: table#LC_menubuttons img {
1.803 bisitz 5614: border: none;
1.346 albertel 5615: }
1.795 www 5616:
1.842 droeschl 5617: .LC_breadcrumbs_component {
1.911 bisitz 5618: float: right;
5619: margin: 0 1em;
1.357 albertel 5620: }
1.842 droeschl 5621: .LC_breadcrumbs_component img {
1.911 bisitz 5622: vertical-align: middle;
1.777 tempelho 5623: }
1.795 www 5624:
1.383 albertel 5625: td.LC_table_cell_checkbox {
5626: text-align: center;
5627: }
1.795 www 5628:
5629: .LC_fontsize_small {
1.911 bisitz 5630: font-size: 70%;
1.705 tempelho 5631: }
5632:
1.844 bisitz 5633: #LC_breadcrumbs {
1.911 bisitz 5634: clear:both;
5635: background: $sidebg;
5636: border-bottom: 1px solid $lg_border_color;
5637: line-height: 2.5em;
1.933 droeschl 5638: overflow: hidden;
1.911 bisitz 5639: margin: 0;
5640: padding: 0;
1.995 raeburn 5641: text-align: left;
1.819 tempelho 5642: }
1.862 bisitz 5643:
1.1098 bisitz 5644: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5645: clear:both;
5646: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5647: border: 1px solid $sidebg;
1.1098 bisitz 5648: margin: 0 0 10px 0;
1.966 bisitz 5649: padding: 3px;
1.995 raeburn 5650: text-align: left;
1.822 bisitz 5651: }
5652:
1.795 www 5653: .LC_fontsize_medium {
1.911 bisitz 5654: font-size: 85%;
1.705 tempelho 5655: }
5656:
1.795 www 5657: .LC_fontsize_large {
1.911 bisitz 5658: font-size: 120%;
1.705 tempelho 5659: }
5660:
1.346 albertel 5661: .LC_menubuttons_inline_text {
5662: color: $font;
1.698 harmsja 5663: font-size: 90%;
1.701 harmsja 5664: padding-left:3px;
1.346 albertel 5665: }
5666:
1.934 droeschl 5667: .LC_menubuttons_inline_text img{
5668: vertical-align: middle;
5669: }
5670:
1.1051 www 5671: li.LC_menubuttons_inline_text img {
1.951 onken 5672: cursor:pointer;
1.1002 droeschl 5673: text-decoration: none;
1.951 onken 5674: }
5675:
1.526 www 5676: .LC_menubuttons_link {
5677: text-decoration: none;
5678: }
1.795 www 5679:
1.522 albertel 5680: .LC_menubuttons_category {
1.521 www 5681: color: $font;
1.526 www 5682: background: $pgbg;
1.521 www 5683: font-size: larger;
5684: font-weight: bold;
5685: }
5686:
1.346 albertel 5687: td.LC_menubuttons_text {
1.911 bisitz 5688: color: $font;
1.346 albertel 5689: }
1.706 harmsja 5690:
1.346 albertel 5691: .LC_current_location {
5692: background: $tabbg;
5693: }
1.795 www 5694:
1.938 bisitz 5695: table.LC_data_table {
1.347 albertel 5696: border: 1px solid #000000;
1.402 albertel 5697: border-collapse: separate;
1.426 albertel 5698: border-spacing: 1px;
1.610 albertel 5699: background: $pgbg;
1.347 albertel 5700: }
1.795 www 5701:
1.422 albertel 5702: .LC_data_table_dense {
5703: font-size: small;
5704: }
1.795 www 5705:
1.507 raeburn 5706: table.LC_nested_outer {
5707: border: 1px solid #000000;
1.589 raeburn 5708: border-collapse: collapse;
1.803 bisitz 5709: border-spacing: 0;
1.507 raeburn 5710: width: 100%;
5711: }
1.795 www 5712:
1.879 raeburn 5713: table.LC_innerpickbox,
1.507 raeburn 5714: table.LC_nested {
1.803 bisitz 5715: border: none;
1.589 raeburn 5716: border-collapse: collapse;
1.803 bisitz 5717: border-spacing: 0;
1.507 raeburn 5718: width: 100%;
5719: }
1.795 www 5720:
1.911 bisitz 5721: table.LC_data_table tr th,
5722: table.LC_calendar tr th,
1.879 raeburn 5723: table.LC_prior_tries tr th,
5724: table.LC_innerpickbox tr th {
1.349 albertel 5725: font-weight: bold;
5726: background-color: $data_table_head;
1.801 tempelho 5727: color:$fontmenu;
1.701 harmsja 5728: font-size:90%;
1.347 albertel 5729: }
1.795 www 5730:
1.879 raeburn 5731: table.LC_innerpickbox tr th,
5732: table.LC_innerpickbox tr td {
5733: vertical-align: top;
5734: }
5735:
1.711 raeburn 5736: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5737: background-color: #CCCCCC;
1.711 raeburn 5738: font-weight: bold;
5739: text-align: left;
5740: }
1.795 www 5741:
1.912 bisitz 5742: table.LC_data_table tr.LC_odd_row > td {
5743: background-color: $data_table_light;
5744: padding: 2px;
5745: vertical-align: top;
5746: }
5747:
1.809 bisitz 5748: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5749: background-color: $data_table_light;
1.912 bisitz 5750: vertical-align: top;
5751: }
5752:
5753: table.LC_data_table tr.LC_even_row > td {
5754: background-color: $data_table_dark;
1.425 albertel 5755: padding: 2px;
1.900 bisitz 5756: vertical-align: top;
1.347 albertel 5757: }
1.795 www 5758:
1.809 bisitz 5759: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5760: background-color: $data_table_dark;
1.900 bisitz 5761: vertical-align: top;
1.347 albertel 5762: }
1.795 www 5763:
1.425 albertel 5764: table.LC_data_table tr.LC_data_table_highlight td {
5765: background-color: $data_table_darker;
5766: }
1.795 www 5767:
1.639 raeburn 5768: table.LC_data_table tr td.LC_leftcol_header {
5769: background-color: $data_table_head;
5770: font-weight: bold;
5771: }
1.795 www 5772:
1.451 albertel 5773: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5774: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5775: font-weight: bold;
5776: font-style: italic;
5777: text-align: center;
5778: padding: 8px;
1.347 albertel 5779: }
1.795 www 5780:
1.1114 raeburn 5781: table.LC_data_table tr.LC_empty_row td,
5782: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5783: background-color: $sidebg;
5784: }
5785:
5786: table.LC_nested tr.LC_empty_row td {
5787: background-color: #FFFFFF;
5788: }
5789:
1.890 droeschl 5790: table.LC_caption {
5791: }
5792:
1.507 raeburn 5793: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5794: padding: 4ex
5795: }
1.795 www 5796:
1.507 raeburn 5797: table.LC_nested_outer tr th {
5798: font-weight: bold;
1.801 tempelho 5799: color:$fontmenu;
1.507 raeburn 5800: background-color: $data_table_head;
1.701 harmsja 5801: font-size: small;
1.507 raeburn 5802: border-bottom: 1px solid #000000;
5803: }
1.795 www 5804:
1.507 raeburn 5805: table.LC_nested_outer tr td.LC_subheader {
5806: background-color: $data_table_head;
5807: font-weight: bold;
5808: font-size: small;
5809: border-bottom: 1px solid #000000;
5810: text-align: right;
1.451 albertel 5811: }
1.795 www 5812:
1.507 raeburn 5813: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5814: background-color: #CCCCCC;
1.451 albertel 5815: font-weight: bold;
5816: font-size: small;
1.507 raeburn 5817: text-align: center;
5818: }
1.795 www 5819:
1.589 raeburn 5820: table.LC_nested tr.LC_info_row td.LC_left_item,
5821: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5822: text-align: left;
1.451 albertel 5823: }
1.795 www 5824:
1.507 raeburn 5825: table.LC_nested td {
1.735 bisitz 5826: background-color: #FFFFFF;
1.451 albertel 5827: font-size: small;
1.507 raeburn 5828: }
1.795 www 5829:
1.507 raeburn 5830: table.LC_nested_outer tr th.LC_right_item,
5831: table.LC_nested tr.LC_info_row td.LC_right_item,
5832: table.LC_nested tr.LC_odd_row td.LC_right_item,
5833: table.LC_nested tr td.LC_right_item {
1.451 albertel 5834: text-align: right;
5835: }
5836:
1.507 raeburn 5837: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5838: background-color: #EEEEEE;
1.451 albertel 5839: }
5840:
1.473 raeburn 5841: table.LC_createuser {
5842: }
5843:
5844: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5845: font-size: small;
1.473 raeburn 5846: }
5847:
5848: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5849: background-color: #CCCCCC;
1.473 raeburn 5850: font-weight: bold;
5851: text-align: center;
5852: }
5853:
1.349 albertel 5854: table.LC_calendar {
5855: border: 1px solid #000000;
5856: border-collapse: collapse;
1.917 raeburn 5857: width: 98%;
1.349 albertel 5858: }
1.795 www 5859:
1.349 albertel 5860: table.LC_calendar_pickdate {
5861: font-size: xx-small;
5862: }
1.795 www 5863:
1.349 albertel 5864: table.LC_calendar tr td {
5865: border: 1px solid #000000;
5866: vertical-align: top;
1.917 raeburn 5867: width: 14%;
1.349 albertel 5868: }
1.795 www 5869:
1.349 albertel 5870: table.LC_calendar tr td.LC_calendar_day_empty {
5871: background-color: $data_table_dark;
5872: }
1.795 www 5873:
1.779 bisitz 5874: table.LC_calendar tr td.LC_calendar_day_current {
5875: background-color: $data_table_highlight;
1.777 tempelho 5876: }
1.795 www 5877:
1.938 bisitz 5878: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5879: background-color: $mail_new;
5880: }
1.795 www 5881:
1.938 bisitz 5882: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5883: background-color: $mail_new_hover;
5884: }
1.795 www 5885:
1.938 bisitz 5886: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5887: background-color: $mail_read;
5888: }
1.795 www 5889:
1.938 bisitz 5890: /*
5891: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5892: background-color: $mail_read_hover;
5893: }
1.938 bisitz 5894: */
1.795 www 5895:
1.938 bisitz 5896: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5897: background-color: $mail_replied;
5898: }
1.795 www 5899:
1.938 bisitz 5900: /*
5901: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5902: background-color: $mail_replied_hover;
5903: }
1.938 bisitz 5904: */
1.795 www 5905:
1.938 bisitz 5906: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5907: background-color: $mail_other;
5908: }
1.795 www 5909:
1.938 bisitz 5910: /*
5911: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5912: background-color: $mail_other_hover;
5913: }
1.938 bisitz 5914: */
1.494 raeburn 5915:
1.777 tempelho 5916: table.LC_data_table tr > td.LC_browser_file,
5917: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5918: background: #AAEE77;
1.389 albertel 5919: }
1.795 www 5920:
1.777 tempelho 5921: table.LC_data_table tr > td.LC_browser_file_locked,
5922: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5923: background: #FFAA99;
1.387 albertel 5924: }
1.795 www 5925:
1.777 tempelho 5926: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5927: background: #888888;
1.779 bisitz 5928: }
1.795 www 5929:
1.777 tempelho 5930: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5931: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5932: background: #F8F866;
1.777 tempelho 5933: }
1.795 www 5934:
1.696 bisitz 5935: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5936: background: #E0E8FF;
1.387 albertel 5937: }
1.696 bisitz 5938:
1.707 bisitz 5939: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5940: /* background: #77FF77; */
1.707 bisitz 5941: }
1.795 www 5942:
1.707 bisitz 5943: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5944: border-right: 8px solid #FFFF77;
1.707 bisitz 5945: }
1.795 www 5946:
1.707 bisitz 5947: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5948: border-right: 8px solid #FFAA77;
1.707 bisitz 5949: }
1.795 www 5950:
1.707 bisitz 5951: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5952: border-right: 8px solid #FF7777;
1.707 bisitz 5953: }
1.795 www 5954:
1.707 bisitz 5955: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5956: border-right: 8px solid #AAFF77;
1.707 bisitz 5957: }
1.795 www 5958:
1.707 bisitz 5959: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5960: border-right: 8px solid #11CC55;
1.707 bisitz 5961: }
5962:
1.388 albertel 5963: span.LC_current_location {
1.701 harmsja 5964: font-size:larger;
1.388 albertel 5965: background: $pgbg;
5966: }
1.387 albertel 5967:
1.1029 www 5968: span.LC_current_nav_location {
5969: font-weight:bold;
5970: background: $sidebg;
5971: }
5972:
1.395 albertel 5973: span.LC_parm_menu_item {
5974: font-size: larger;
5975: }
1.795 www 5976:
1.395 albertel 5977: span.LC_parm_scope_all {
5978: color: red;
5979: }
1.795 www 5980:
1.395 albertel 5981: span.LC_parm_scope_folder {
5982: color: green;
5983: }
1.795 www 5984:
1.395 albertel 5985: span.LC_parm_scope_resource {
5986: color: orange;
5987: }
1.795 www 5988:
1.395 albertel 5989: span.LC_parm_part {
5990: color: blue;
5991: }
1.795 www 5992:
1.911 bisitz 5993: span.LC_parm_folder,
5994: span.LC_parm_symb {
1.395 albertel 5995: font-size: x-small;
5996: font-family: $mono;
5997: color: #AAAAAA;
5998: }
5999:
1.977 bisitz 6000: ul.LC_parm_parmlist li {
6001: display: inline-block;
6002: padding: 0.3em 0.8em;
6003: vertical-align: top;
6004: width: 150px;
6005: border-top:1px solid $lg_border_color;
6006: }
6007:
1.795 www 6008: td.LC_parm_overview_level_menu,
6009: td.LC_parm_overview_map_menu,
6010: td.LC_parm_overview_parm_selectors,
6011: td.LC_parm_overview_restrictions {
1.396 albertel 6012: border: 1px solid black;
6013: border-collapse: collapse;
6014: }
1.795 www 6015:
1.396 albertel 6016: table.LC_parm_overview_restrictions td {
6017: border-width: 1px 4px 1px 4px;
6018: border-style: solid;
6019: border-color: $pgbg;
6020: text-align: center;
6021: }
1.795 www 6022:
1.396 albertel 6023: table.LC_parm_overview_restrictions th {
6024: background: $tabbg;
6025: border-width: 1px 4px 1px 4px;
6026: border-style: solid;
6027: border-color: $pgbg;
6028: }
1.795 www 6029:
1.398 albertel 6030: table#LC_helpmenu {
1.803 bisitz 6031: border: none;
1.398 albertel 6032: height: 55px;
1.803 bisitz 6033: border-spacing: 0;
1.398 albertel 6034: }
6035:
6036: table#LC_helpmenu fieldset legend {
6037: font-size: larger;
6038: }
1.795 www 6039:
1.397 albertel 6040: table#LC_helpmenu_links {
6041: width: 100%;
6042: border: 1px solid black;
6043: background: $pgbg;
1.803 bisitz 6044: padding: 0;
1.397 albertel 6045: border-spacing: 1px;
6046: }
1.795 www 6047:
1.397 albertel 6048: table#LC_helpmenu_links tr td {
6049: padding: 1px;
6050: background: $tabbg;
1.399 albertel 6051: text-align: center;
6052: font-weight: bold;
1.397 albertel 6053: }
1.396 albertel 6054:
1.795 www 6055: table#LC_helpmenu_links a:link,
6056: table#LC_helpmenu_links a:visited,
1.397 albertel 6057: table#LC_helpmenu_links a:active {
6058: text-decoration: none;
6059: color: $font;
6060: }
1.795 www 6061:
1.397 albertel 6062: table#LC_helpmenu_links a:hover {
6063: text-decoration: underline;
6064: color: $vlink;
6065: }
1.396 albertel 6066:
1.417 albertel 6067: .LC_chrt_popup_exists {
6068: border: 1px solid #339933;
6069: margin: -1px;
6070: }
1.795 www 6071:
1.417 albertel 6072: .LC_chrt_popup_up {
6073: border: 1px solid yellow;
6074: margin: -1px;
6075: }
1.795 www 6076:
1.417 albertel 6077: .LC_chrt_popup {
6078: border: 1px solid #8888FF;
6079: background: #CCCCFF;
6080: }
1.795 www 6081:
1.421 albertel 6082: table.LC_pick_box {
6083: border-collapse: separate;
6084: background: white;
6085: border: 1px solid black;
6086: border-spacing: 1px;
6087: }
1.795 www 6088:
1.421 albertel 6089: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6090: background: $sidebg;
1.421 albertel 6091: font-weight: bold;
1.900 bisitz 6092: text-align: left;
1.740 bisitz 6093: vertical-align: top;
1.421 albertel 6094: width: 184px;
6095: padding: 8px;
6096: }
1.795 www 6097:
1.579 raeburn 6098: table.LC_pick_box td.LC_pick_box_value {
6099: text-align: left;
6100: padding: 8px;
6101: }
1.795 www 6102:
1.579 raeburn 6103: table.LC_pick_box td.LC_pick_box_select {
6104: text-align: left;
6105: padding: 8px;
6106: }
1.795 www 6107:
1.424 albertel 6108: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6109: padding: 0;
1.421 albertel 6110: height: 1px;
6111: background: black;
6112: }
1.795 www 6113:
1.421 albertel 6114: table.LC_pick_box td.LC_pick_box_submit {
6115: text-align: right;
6116: }
1.795 www 6117:
1.579 raeburn 6118: table.LC_pick_box td.LC_evenrow_value {
6119: text-align: left;
6120: padding: 8px;
6121: background-color: $data_table_light;
6122: }
1.795 www 6123:
1.579 raeburn 6124: table.LC_pick_box td.LC_oddrow_value {
6125: text-align: left;
6126: padding: 8px;
6127: background-color: $data_table_light;
6128: }
1.795 www 6129:
1.579 raeburn 6130: span.LC_helpform_receipt_cat {
6131: font-weight: bold;
6132: }
1.795 www 6133:
1.424 albertel 6134: table.LC_group_priv_box {
6135: background: white;
6136: border: 1px solid black;
6137: border-spacing: 1px;
6138: }
1.795 www 6139:
1.424 albertel 6140: table.LC_group_priv_box td.LC_pick_box_title {
6141: background: $tabbg;
6142: font-weight: bold;
6143: text-align: right;
6144: width: 184px;
6145: }
1.795 www 6146:
1.424 albertel 6147: table.LC_group_priv_box td.LC_groups_fixed {
6148: background: $data_table_light;
6149: text-align: center;
6150: }
1.795 www 6151:
1.424 albertel 6152: table.LC_group_priv_box td.LC_groups_optional {
6153: background: $data_table_dark;
6154: text-align: center;
6155: }
1.795 www 6156:
1.424 albertel 6157: table.LC_group_priv_box td.LC_groups_functionality {
6158: background: $data_table_darker;
6159: text-align: center;
6160: font-weight: bold;
6161: }
1.795 www 6162:
1.424 albertel 6163: table.LC_group_priv td {
6164: text-align: left;
1.803 bisitz 6165: padding: 0;
1.424 albertel 6166: }
6167:
6168: .LC_navbuttons {
6169: margin: 2ex 0ex 2ex 0ex;
6170: }
1.795 www 6171:
1.423 albertel 6172: .LC_topic_bar {
6173: font-weight: bold;
6174: background: $tabbg;
1.918 wenzelju 6175: margin: 1em 0em 1em 2em;
1.805 bisitz 6176: padding: 3px;
1.918 wenzelju 6177: font-size: 1.2em;
1.423 albertel 6178: }
1.795 www 6179:
1.423 albertel 6180: .LC_topic_bar span {
1.918 wenzelju 6181: left: 0.5em;
6182: position: absolute;
1.423 albertel 6183: vertical-align: middle;
1.918 wenzelju 6184: font-size: 1.2em;
1.423 albertel 6185: }
1.795 www 6186:
1.423 albertel 6187: table.LC_course_group_status {
6188: margin: 20px;
6189: }
1.795 www 6190:
1.423 albertel 6191: table.LC_status_selector td {
6192: vertical-align: top;
6193: text-align: center;
1.424 albertel 6194: padding: 4px;
6195: }
1.795 www 6196:
1.599 albertel 6197: div.LC_feedback_link {
1.616 albertel 6198: clear: both;
1.829 kalberla 6199: background: $sidebg;
1.779 bisitz 6200: width: 100%;
1.829 kalberla 6201: padding-bottom: 10px;
6202: border: 1px $tabbg solid;
1.833 kalberla 6203: height: 22px;
6204: line-height: 22px;
6205: padding-top: 5px;
6206: }
6207:
6208: div.LC_feedback_link img {
6209: height: 22px;
1.867 kalberla 6210: vertical-align:middle;
1.829 kalberla 6211: }
6212:
1.911 bisitz 6213: div.LC_feedback_link a {
1.829 kalberla 6214: text-decoration: none;
1.489 raeburn 6215: }
1.795 www 6216:
1.867 kalberla 6217: div.LC_comblock {
1.911 bisitz 6218: display:inline;
1.867 kalberla 6219: color:$font;
6220: font-size:90%;
6221: }
6222:
6223: div.LC_feedback_link div.LC_comblock {
6224: padding-left:5px;
6225: }
6226:
6227: div.LC_feedback_link div.LC_comblock a {
6228: color:$font;
6229: }
6230:
1.489 raeburn 6231: span.LC_feedback_link {
1.858 bisitz 6232: /* background: $feedback_link_bg; */
1.599 albertel 6233: font-size: larger;
6234: }
1.795 www 6235:
1.599 albertel 6236: span.LC_message_link {
1.858 bisitz 6237: /* background: $feedback_link_bg; */
1.599 albertel 6238: font-size: larger;
6239: position: absolute;
6240: right: 1em;
1.489 raeburn 6241: }
1.421 albertel 6242:
1.515 albertel 6243: table.LC_prior_tries {
1.524 albertel 6244: border: 1px solid #000000;
6245: border-collapse: separate;
6246: border-spacing: 1px;
1.515 albertel 6247: }
1.523 albertel 6248:
1.515 albertel 6249: table.LC_prior_tries td {
1.524 albertel 6250: padding: 2px;
1.515 albertel 6251: }
1.523 albertel 6252:
6253: .LC_answer_correct {
1.795 www 6254: background: lightgreen;
6255: color: darkgreen;
6256: padding: 6px;
1.523 albertel 6257: }
1.795 www 6258:
1.523 albertel 6259: .LC_answer_charged_try {
1.797 www 6260: background: #FFAAAA;
1.795 www 6261: color: darkred;
6262: padding: 6px;
1.523 albertel 6263: }
1.795 www 6264:
1.779 bisitz 6265: .LC_answer_not_charged_try,
1.523 albertel 6266: .LC_answer_no_grade,
6267: .LC_answer_late {
1.795 www 6268: background: lightyellow;
1.523 albertel 6269: color: black;
1.795 www 6270: padding: 6px;
1.523 albertel 6271: }
1.795 www 6272:
1.523 albertel 6273: .LC_answer_previous {
1.795 www 6274: background: lightblue;
6275: color: darkblue;
6276: padding: 6px;
1.523 albertel 6277: }
1.795 www 6278:
1.779 bisitz 6279: .LC_answer_no_message {
1.777 tempelho 6280: background: #FFFFFF;
6281: color: black;
1.795 www 6282: padding: 6px;
1.779 bisitz 6283: }
1.795 www 6284:
1.779 bisitz 6285: .LC_answer_unknown {
6286: background: orange;
6287: color: black;
1.795 www 6288: padding: 6px;
1.777 tempelho 6289: }
1.795 www 6290:
1.529 albertel 6291: span.LC_prior_numerical,
6292: span.LC_prior_string,
6293: span.LC_prior_custom,
6294: span.LC_prior_reaction,
6295: span.LC_prior_math {
1.925 bisitz 6296: font-family: $mono;
1.523 albertel 6297: white-space: pre;
6298: }
6299:
1.525 albertel 6300: span.LC_prior_string {
1.925 bisitz 6301: font-family: $mono;
1.525 albertel 6302: white-space: pre;
6303: }
6304:
1.523 albertel 6305: table.LC_prior_option {
6306: width: 100%;
6307: border-collapse: collapse;
6308: }
1.795 www 6309:
1.911 bisitz 6310: table.LC_prior_rank,
1.795 www 6311: table.LC_prior_match {
1.528 albertel 6312: border-collapse: collapse;
6313: }
1.795 www 6314:
1.528 albertel 6315: table.LC_prior_option tr td,
6316: table.LC_prior_rank tr td,
6317: table.LC_prior_match tr td {
1.524 albertel 6318: border: 1px solid #000000;
1.515 albertel 6319: }
6320:
1.855 bisitz 6321: .LC_nobreak {
1.544 albertel 6322: white-space: nowrap;
1.519 raeburn 6323: }
6324:
1.576 raeburn 6325: span.LC_cusr_emph {
6326: font-style: italic;
6327: }
6328:
1.633 raeburn 6329: span.LC_cusr_subheading {
6330: font-weight: normal;
6331: font-size: 85%;
6332: }
6333:
1.861 bisitz 6334: div.LC_docs_entry_move {
1.859 bisitz 6335: border: 1px solid #BBBBBB;
1.545 albertel 6336: background: #DDDDDD;
1.861 bisitz 6337: width: 22px;
1.859 bisitz 6338: padding: 1px;
6339: margin: 0;
1.545 albertel 6340: }
6341:
1.861 bisitz 6342: table.LC_data_table tr > td.LC_docs_entry_commands,
6343: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6344: font-size: x-small;
6345: }
1.795 www 6346:
1.861 bisitz 6347: .LC_docs_entry_parameter {
6348: white-space: nowrap;
6349: }
6350:
1.544 albertel 6351: .LC_docs_copy {
1.545 albertel 6352: color: #000099;
1.544 albertel 6353: }
1.795 www 6354:
1.544 albertel 6355: .LC_docs_cut {
1.545 albertel 6356: color: #550044;
1.544 albertel 6357: }
1.795 www 6358:
1.544 albertel 6359: .LC_docs_rename {
1.545 albertel 6360: color: #009900;
1.544 albertel 6361: }
1.795 www 6362:
1.544 albertel 6363: .LC_docs_remove {
1.545 albertel 6364: color: #990000;
6365: }
6366:
1.547 albertel 6367: .LC_docs_reinit_warn,
6368: .LC_docs_ext_edit {
6369: font-size: x-small;
6370: }
6371:
1.545 albertel 6372: table.LC_docs_adddocs td,
6373: table.LC_docs_adddocs th {
6374: border: 1px solid #BBBBBB;
6375: padding: 4px;
6376: background: #DDDDDD;
1.543 albertel 6377: }
6378:
1.584 albertel 6379: table.LC_sty_begin {
6380: background: #BBFFBB;
6381: }
1.795 www 6382:
1.584 albertel 6383: table.LC_sty_end {
6384: background: #FFBBBB;
6385: }
6386:
1.589 raeburn 6387: table.LC_double_column {
1.803 bisitz 6388: border-width: 0;
1.589 raeburn 6389: border-collapse: collapse;
6390: width: 100%;
6391: padding: 2px;
6392: }
6393:
6394: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6395: top: 2px;
1.589 raeburn 6396: left: 2px;
6397: width: 47%;
6398: vertical-align: top;
6399: }
6400:
6401: table.LC_double_column tr td.LC_right_col {
6402: top: 2px;
1.779 bisitz 6403: right: 2px;
1.589 raeburn 6404: width: 47%;
6405: vertical-align: top;
6406: }
6407:
1.591 raeburn 6408: div.LC_left_float {
6409: float: left;
6410: padding-right: 5%;
1.597 albertel 6411: padding-bottom: 4px;
1.591 raeburn 6412: }
6413:
6414: div.LC_clear_float_header {
1.597 albertel 6415: padding-bottom: 2px;
1.591 raeburn 6416: }
6417:
6418: div.LC_clear_float_footer {
1.597 albertel 6419: padding-top: 10px;
1.591 raeburn 6420: clear: both;
6421: }
6422:
1.597 albertel 6423: div.LC_grade_show_user {
1.941 bisitz 6424: /* border-left: 5px solid $sidebg; */
6425: border-top: 5px solid #000000;
6426: margin: 50px 0 0 0;
1.936 bisitz 6427: padding: 15px 0 5px 10px;
1.597 albertel 6428: }
1.795 www 6429:
1.936 bisitz 6430: div.LC_grade_show_user_odd_row {
1.941 bisitz 6431: /* border-left: 5px solid #000000; */
6432: }
6433:
6434: div.LC_grade_show_user div.LC_Box {
6435: margin-right: 50px;
1.597 albertel 6436: }
6437:
6438: div.LC_grade_submissions,
6439: div.LC_grade_message_center,
1.936 bisitz 6440: div.LC_grade_info_links {
1.597 albertel 6441: margin: 5px;
6442: width: 99%;
6443: background: #FFFFFF;
6444: }
1.795 www 6445:
1.597 albertel 6446: div.LC_grade_submissions_header,
1.936 bisitz 6447: div.LC_grade_message_center_header {
1.705 tempelho 6448: font-weight: bold;
6449: font-size: large;
1.597 albertel 6450: }
1.795 www 6451:
1.597 albertel 6452: div.LC_grade_submissions_body,
1.936 bisitz 6453: div.LC_grade_message_center_body {
1.597 albertel 6454: border: 1px solid black;
6455: width: 99%;
6456: background: #FFFFFF;
6457: }
1.795 www 6458:
1.613 albertel 6459: table.LC_scantron_action {
6460: width: 100%;
6461: }
1.795 www 6462:
1.613 albertel 6463: table.LC_scantron_action tr th {
1.698 harmsja 6464: font-weight:bold;
6465: font-style:normal;
1.613 albertel 6466: }
1.795 www 6467:
1.779 bisitz 6468: .LC_edit_problem_header,
1.614 albertel 6469: div.LC_edit_problem_footer {
1.705 tempelho 6470: font-weight: normal;
6471: font-size: medium;
1.602 albertel 6472: margin: 2px;
1.1060 bisitz 6473: background-color: $sidebg;
1.600 albertel 6474: }
1.795 www 6475:
1.600 albertel 6476: div.LC_edit_problem_header,
1.602 albertel 6477: div.LC_edit_problem_header div,
1.614 albertel 6478: div.LC_edit_problem_footer,
6479: div.LC_edit_problem_footer div,
1.602 albertel 6480: div.LC_edit_problem_editxml_header,
6481: div.LC_edit_problem_editxml_header div {
1.600 albertel 6482: margin-top: 5px;
6483: }
1.795 www 6484:
1.600 albertel 6485: div.LC_edit_problem_header_title {
1.705 tempelho 6486: font-weight: bold;
6487: font-size: larger;
1.602 albertel 6488: background: $tabbg;
6489: padding: 3px;
1.1060 bisitz 6490: margin: 0 0 5px 0;
1.602 albertel 6491: }
1.795 www 6492:
1.602 albertel 6493: table.LC_edit_problem_header_title {
6494: width: 100%;
1.600 albertel 6495: background: $tabbg;
1.602 albertel 6496: }
6497:
6498: div.LC_edit_problem_discards {
6499: float: left;
6500: padding-bottom: 5px;
6501: }
1.795 www 6502:
1.602 albertel 6503: div.LC_edit_problem_saves {
6504: float: right;
6505: padding-bottom: 5px;
1.600 albertel 6506: }
1.795 www 6507:
1.1124 bisitz 6508: .LC_edit_opt {
6509: padding-left: 1em;
6510: white-space: nowrap;
6511: }
6512:
1.1152 golterma 6513: .LC_edit_problem_latexhelper{
6514: text-align: right;
6515: }
6516:
6517: #LC_edit_problem_colorful div{
6518: margin-left: 40px;
6519: }
6520:
1.911 bisitz 6521: img.stift {
1.803 bisitz 6522: border-width: 0;
6523: vertical-align: middle;
1.677 riegler 6524: }
1.680 riegler 6525:
1.923 bisitz 6526: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6527: vertical-align: top;
1.777 tempelho 6528: }
1.795 www 6529:
1.716 raeburn 6530: div.LC_createcourse {
1.911 bisitz 6531: margin: 10px 10px 10px 10px;
1.716 raeburn 6532: }
6533:
1.917 raeburn 6534: .LC_dccid {
1.1130 raeburn 6535: float: right;
1.917 raeburn 6536: margin: 0.2em 0 0 0;
6537: padding: 0;
6538: font-size: 90%;
6539: display:none;
6540: }
6541:
1.897 wenzelju 6542: ol.LC_primary_menu a:hover,
1.721 harmsja 6543: ol#LC_MenuBreadcrumbs a:hover,
6544: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6545: ul#LC_secondary_menu a:hover,
1.721 harmsja 6546: .LC_FormSectionClearButton input:hover
1.795 www 6547: ul.LC_TabContent li:hover a {
1.952 onken 6548: color:$button_hover;
1.911 bisitz 6549: text-decoration:none;
1.693 droeschl 6550: }
6551:
1.779 bisitz 6552: h1 {
1.911 bisitz 6553: padding: 0;
6554: line-height:130%;
1.693 droeschl 6555: }
1.698 harmsja 6556:
1.911 bisitz 6557: h2,
6558: h3,
6559: h4,
6560: h5,
6561: h6 {
6562: margin: 5px 0 5px 0;
6563: padding: 0;
6564: line-height:130%;
1.693 droeschl 6565: }
1.795 www 6566:
6567: .LC_hcell {
1.911 bisitz 6568: padding:3px 15px 3px 15px;
6569: margin: 0;
6570: background-color:$tabbg;
6571: color:$fontmenu;
6572: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6573: }
1.795 www 6574:
1.840 bisitz 6575: .LC_Box > .LC_hcell {
1.911 bisitz 6576: margin: 0 -10px 10px -10px;
1.835 bisitz 6577: }
6578:
1.721 harmsja 6579: .LC_noBorder {
1.911 bisitz 6580: border: 0;
1.698 harmsja 6581: }
1.693 droeschl 6582:
1.721 harmsja 6583: .LC_FormSectionClearButton input {
1.911 bisitz 6584: background-color:transparent;
6585: border: none;
6586: cursor:pointer;
6587: text-decoration:underline;
1.693 droeschl 6588: }
1.763 bisitz 6589:
6590: .LC_help_open_topic {
1.911 bisitz 6591: color: #FFFFFF;
6592: background-color: #EEEEFF;
6593: margin: 1px;
6594: padding: 4px;
6595: border: 1px solid #000033;
6596: white-space: nowrap;
6597: /* vertical-align: middle; */
1.759 neumanie 6598: }
1.693 droeschl 6599:
1.911 bisitz 6600: dl,
6601: ul,
6602: div,
6603: fieldset {
6604: margin: 10px 10px 10px 0;
6605: /* overflow: hidden; */
1.693 droeschl 6606: }
1.795 www 6607:
1.838 bisitz 6608: fieldset > legend {
1.911 bisitz 6609: font-weight: bold;
6610: padding: 0 5px 0 5px;
1.838 bisitz 6611: }
6612:
1.813 bisitz 6613: #LC_nav_bar {
1.911 bisitz 6614: float: left;
1.995 raeburn 6615: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6616: margin: 0 0 2px 0;
1.807 droeschl 6617: }
6618:
1.916 droeschl 6619: #LC_realm {
6620: margin: 0.2em 0 0 0;
6621: padding: 0;
6622: font-weight: bold;
6623: text-align: center;
1.995 raeburn 6624: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6625: }
6626:
1.911 bisitz 6627: #LC_nav_bar em {
6628: font-weight: bold;
6629: font-style: normal;
1.807 droeschl 6630: }
6631:
1.897 wenzelju 6632: ol.LC_primary_menu {
1.934 droeschl 6633: margin: 0;
1.1076 raeburn 6634: padding: 0;
1.995 raeburn 6635: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6636: }
6637:
1.852 droeschl 6638: ol#LC_PathBreadcrumbs {
1.911 bisitz 6639: margin: 0;
1.693 droeschl 6640: }
6641:
1.897 wenzelju 6642: ol.LC_primary_menu li {
1.1076 raeburn 6643: color: RGB(80, 80, 80);
6644: vertical-align: middle;
6645: text-align: left;
6646: list-style: none;
6647: float: left;
6648: }
6649:
6650: ol.LC_primary_menu li a {
6651: display: block;
6652: margin: 0;
6653: padding: 0 5px 0 10px;
6654: text-decoration: none;
6655: }
6656:
6657: ol.LC_primary_menu li ul {
6658: display: none;
6659: width: 10em;
6660: background-color: $data_table_light;
6661: }
6662:
6663: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6664: display: block;
6665: position: absolute;
6666: margin: 0;
6667: padding: 0;
1.1078 raeburn 6668: z-index: 2;
1.1076 raeburn 6669: }
6670:
6671: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6672: font-size: 90%;
1.911 bisitz 6673: vertical-align: top;
1.1076 raeburn 6674: float: none;
1.1079 raeburn 6675: border-left: 1px solid black;
6676: border-right: 1px solid black;
1.1076 raeburn 6677: }
6678:
6679: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6680: background-color:$data_table_light;
1.1076 raeburn 6681: }
6682:
6683: ol.LC_primary_menu li li a:hover {
6684: color:$button_hover;
6685: background-color:$data_table_dark;
1.693 droeschl 6686: }
6687:
1.897 wenzelju 6688: ol.LC_primary_menu li img {
1.911 bisitz 6689: vertical-align: bottom;
1.934 droeschl 6690: height: 1.1em;
1.1077 raeburn 6691: margin: 0.2em 0 0 0;
1.693 droeschl 6692: }
6693:
1.897 wenzelju 6694: ol.LC_primary_menu a {
1.911 bisitz 6695: color: RGB(80, 80, 80);
6696: text-decoration: none;
1.693 droeschl 6697: }
1.795 www 6698:
1.949 droeschl 6699: ol.LC_primary_menu a.LC_new_message {
6700: font-weight:bold;
6701: color: darkred;
6702: }
6703:
1.975 raeburn 6704: ol.LC_docs_parameters {
6705: margin-left: 0;
6706: padding: 0;
6707: list-style: none;
6708: }
6709:
6710: ol.LC_docs_parameters li {
6711: margin: 0;
6712: padding-right: 20px;
6713: display: inline;
6714: }
6715:
1.976 raeburn 6716: ol.LC_docs_parameters li:before {
6717: content: "\\002022 \\0020";
6718: }
6719:
6720: li.LC_docs_parameters_title {
6721: font-weight: bold;
6722: }
6723:
6724: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6725: content: "";
6726: }
6727:
1.897 wenzelju 6728: ul#LC_secondary_menu {
1.1107 raeburn 6729: clear: right;
1.911 bisitz 6730: color: $fontmenu;
6731: background: $tabbg;
6732: list-style: none;
6733: padding: 0;
6734: margin: 0;
6735: width: 100%;
1.995 raeburn 6736: text-align: left;
1.1107 raeburn 6737: float: left;
1.808 droeschl 6738: }
6739:
1.897 wenzelju 6740: ul#LC_secondary_menu li {
1.911 bisitz 6741: font-weight: bold;
6742: line-height: 1.8em;
1.1107 raeburn 6743: border-right: 1px solid black;
6744: float: left;
6745: }
6746:
6747: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6748: background-color: $data_table_light;
6749: }
6750:
6751: ul#LC_secondary_menu li a {
1.911 bisitz 6752: padding: 0 0.8em;
1.1107 raeburn 6753: }
6754:
6755: ul#LC_secondary_menu li ul {
6756: display: none;
6757: }
6758:
6759: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6760: display: block;
6761: position: absolute;
6762: margin: 0;
6763: padding: 0;
6764: list-style:none;
6765: float: none;
6766: background-color: $data_table_light;
6767: z-index: 2;
6768: margin-left: -1px;
6769: }
6770:
6771: ul#LC_secondary_menu li ul li {
6772: font-size: 90%;
6773: vertical-align: top;
6774: border-left: 1px solid black;
1.911 bisitz 6775: border-right: 1px solid black;
1.1119 raeburn 6776: background-color: $data_table_light;
1.1107 raeburn 6777: list-style:none;
6778: float: none;
6779: }
6780:
6781: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6782: background-color: $data_table_dark;
1.807 droeschl 6783: }
6784:
1.847 tempelho 6785: ul.LC_TabContent {
1.911 bisitz 6786: display:block;
6787: background: $sidebg;
6788: border-bottom: solid 1px $lg_border_color;
6789: list-style:none;
1.1020 raeburn 6790: margin: -1px -10px 0 -10px;
1.911 bisitz 6791: padding: 0;
1.693 droeschl 6792: }
6793:
1.795 www 6794: ul.LC_TabContent li,
6795: ul.LC_TabContentBigger li {
1.911 bisitz 6796: float:left;
1.741 harmsja 6797: }
1.795 www 6798:
1.897 wenzelju 6799: ul#LC_secondary_menu li a {
1.911 bisitz 6800: color: $fontmenu;
6801: text-decoration: none;
1.693 droeschl 6802: }
1.795 www 6803:
1.721 harmsja 6804: ul.LC_TabContent {
1.952 onken 6805: min-height:20px;
1.721 harmsja 6806: }
1.795 www 6807:
6808: ul.LC_TabContent li {
1.911 bisitz 6809: vertical-align:middle;
1.959 onken 6810: padding: 0 16px 0 10px;
1.911 bisitz 6811: background-color:$tabbg;
6812: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6813: border-left: solid 1px $font;
1.721 harmsja 6814: }
1.795 www 6815:
1.847 tempelho 6816: ul.LC_TabContent .right {
1.911 bisitz 6817: float:right;
1.847 tempelho 6818: }
6819:
1.911 bisitz 6820: ul.LC_TabContent li a,
6821: ul.LC_TabContent li {
6822: color:rgb(47,47,47);
6823: text-decoration:none;
6824: font-size:95%;
6825: font-weight:bold;
1.952 onken 6826: min-height:20px;
6827: }
6828:
1.959 onken 6829: ul.LC_TabContent li a:hover,
6830: ul.LC_TabContent li a:focus {
1.952 onken 6831: color: $button_hover;
1.959 onken 6832: background:none;
6833: outline:none;
1.952 onken 6834: }
6835:
6836: ul.LC_TabContent li:hover {
6837: color: $button_hover;
6838: cursor:pointer;
1.721 harmsja 6839: }
1.795 www 6840:
1.911 bisitz 6841: ul.LC_TabContent li.active {
1.952 onken 6842: color: $font;
1.911 bisitz 6843: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6844: border-bottom:solid 1px #FFFFFF;
6845: cursor: default;
1.744 ehlerst 6846: }
1.795 www 6847:
1.959 onken 6848: ul.LC_TabContent li.active a {
6849: color:$font;
6850: background:#FFFFFF;
6851: outline: none;
6852: }
1.1047 raeburn 6853:
6854: ul.LC_TabContent li.goback {
6855: float: left;
6856: border-left: none;
6857: }
6858:
1.870 tempelho 6859: #maincoursedoc {
1.911 bisitz 6860: clear:both;
1.870 tempelho 6861: }
6862:
6863: ul.LC_TabContentBigger {
1.911 bisitz 6864: display:block;
6865: list-style:none;
6866: padding: 0;
1.870 tempelho 6867: }
6868:
1.795 www 6869: ul.LC_TabContentBigger li {
1.911 bisitz 6870: vertical-align:bottom;
6871: height: 30px;
6872: font-size:110%;
6873: font-weight:bold;
6874: color: #737373;
1.841 tempelho 6875: }
6876:
1.957 onken 6877: ul.LC_TabContentBigger li.active {
6878: position: relative;
6879: top: 1px;
6880: }
6881:
1.870 tempelho 6882: ul.LC_TabContentBigger li a {
1.911 bisitz 6883: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6884: height: 30px;
6885: line-height: 30px;
6886: text-align: center;
6887: display: block;
6888: text-decoration: none;
1.958 onken 6889: outline: none;
1.741 harmsja 6890: }
1.795 www 6891:
1.870 tempelho 6892: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6893: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6894: color:$font;
1.744 ehlerst 6895: }
1.795 www 6896:
1.870 tempelho 6897: ul.LC_TabContentBigger li b {
1.911 bisitz 6898: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6899: display: block;
6900: float: left;
6901: padding: 0 30px;
1.957 onken 6902: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6903: }
6904:
1.956 onken 6905: ul.LC_TabContentBigger li:hover b {
6906: color:$button_hover;
6907: }
6908:
1.870 tempelho 6909: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6910: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6911: color:$font;
1.957 onken 6912: border: 0;
1.741 harmsja 6913: }
1.693 droeschl 6914:
1.870 tempelho 6915:
1.862 bisitz 6916: ul.LC_CourseBreadcrumbs {
6917: background: $sidebg;
1.1020 raeburn 6918: height: 2em;
1.862 bisitz 6919: padding-left: 10px;
1.1020 raeburn 6920: margin: 0;
1.862 bisitz 6921: list-style-position: inside;
6922: }
6923:
1.911 bisitz 6924: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6925: ol#LC_PathBreadcrumbs {
1.911 bisitz 6926: padding-left: 10px;
6927: margin: 0;
1.933 droeschl 6928: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6929: }
6930:
1.911 bisitz 6931: ol#LC_MenuBreadcrumbs li,
6932: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6933: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6934: display: inline;
1.933 droeschl 6935: white-space: normal;
1.693 droeschl 6936: }
6937:
1.823 bisitz 6938: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6939: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6940: text-decoration: none;
6941: font-size:90%;
1.693 droeschl 6942: }
1.795 www 6943:
1.969 droeschl 6944: ol#LC_MenuBreadcrumbs h1 {
6945: display: inline;
6946: font-size: 90%;
6947: line-height: 2.5em;
6948: margin: 0;
6949: padding: 0;
6950: }
6951:
1.795 www 6952: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6953: text-decoration:none;
6954: font-size:100%;
6955: font-weight:bold;
1.693 droeschl 6956: }
1.795 www 6957:
1.840 bisitz 6958: .LC_Box {
1.911 bisitz 6959: border: solid 1px $lg_border_color;
6960: padding: 0 10px 10px 10px;
1.746 neumanie 6961: }
1.795 www 6962:
1.1020 raeburn 6963: .LC_DocsBox {
6964: border: solid 1px $lg_border_color;
6965: padding: 0 0 10px 10px;
6966: }
6967:
1.795 www 6968: .LC_AboutMe_Image {
1.911 bisitz 6969: float:left;
6970: margin-right:10px;
1.747 neumanie 6971: }
1.795 www 6972:
6973: .LC_Clear_AboutMe_Image {
1.911 bisitz 6974: clear:left;
1.747 neumanie 6975: }
1.795 www 6976:
1.721 harmsja 6977: dl.LC_ListStyleClean dt {
1.911 bisitz 6978: padding-right: 5px;
6979: display: table-header-group;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: dl.LC_ListStyleClean dd {
1.911 bisitz 6983: display: table-row;
1.693 droeschl 6984: }
6985:
1.721 harmsja 6986: .LC_ListStyleClean,
6987: .LC_ListStyleSimple,
6988: .LC_ListStyleNormal,
1.795 www 6989: .LC_ListStyleSpecial {
1.911 bisitz 6990: /* display:block; */
6991: list-style-position: inside;
6992: list-style-type: none;
6993: overflow: hidden;
6994: padding: 0;
1.693 droeschl 6995: }
6996:
1.721 harmsja 6997: .LC_ListStyleSimple li,
6998: .LC_ListStyleSimple dd,
6999: .LC_ListStyleNormal li,
7000: .LC_ListStyleNormal dd,
7001: .LC_ListStyleSpecial li,
1.795 www 7002: .LC_ListStyleSpecial dd {
1.911 bisitz 7003: margin: 0;
7004: padding: 5px 5px 5px 10px;
7005: clear: both;
1.693 droeschl 7006: }
7007:
1.721 harmsja 7008: .LC_ListStyleClean li,
7009: .LC_ListStyleClean dd {
1.911 bisitz 7010: padding-top: 0;
7011: padding-bottom: 0;
1.693 droeschl 7012: }
7013:
1.721 harmsja 7014: .LC_ListStyleSimple dd,
1.795 www 7015: .LC_ListStyleSimple li {
1.911 bisitz 7016: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7017: }
7018:
1.721 harmsja 7019: .LC_ListStyleSpecial li,
7020: .LC_ListStyleSpecial dd {
1.911 bisitz 7021: list-style-type: none;
7022: background-color: RGB(220, 220, 220);
7023: margin-bottom: 4px;
1.693 droeschl 7024: }
7025:
1.721 harmsja 7026: table.LC_SimpleTable {
1.911 bisitz 7027: margin:5px;
7028: border:solid 1px $lg_border_color;
1.795 www 7029: }
1.693 droeschl 7030:
1.721 harmsja 7031: table.LC_SimpleTable tr {
1.911 bisitz 7032: padding: 0;
7033: border:solid 1px $lg_border_color;
1.693 droeschl 7034: }
1.795 www 7035:
7036: table.LC_SimpleTable thead {
1.911 bisitz 7037: background:rgb(220,220,220);
1.693 droeschl 7038: }
7039:
1.721 harmsja 7040: div.LC_columnSection {
1.911 bisitz 7041: display: block;
7042: clear: both;
7043: overflow: hidden;
7044: margin: 0;
1.693 droeschl 7045: }
7046:
1.721 harmsja 7047: div.LC_columnSection>* {
1.911 bisitz 7048: float: left;
7049: margin: 10px 20px 10px 0;
7050: overflow:hidden;
1.693 droeschl 7051: }
1.721 harmsja 7052:
1.795 www 7053: table em {
1.911 bisitz 7054: font-weight: bold;
7055: font-style: normal;
1.748 schulted 7056: }
1.795 www 7057:
1.779 bisitz 7058: table.LC_tableBrowseRes,
1.795 www 7059: table.LC_tableOfContent {
1.911 bisitz 7060: border:none;
7061: border-spacing: 1px;
7062: padding: 3px;
7063: background-color: #FFFFFF;
7064: font-size: 90%;
1.753 droeschl 7065: }
1.789 droeschl 7066:
1.911 bisitz 7067: table.LC_tableOfContent {
7068: border-collapse: collapse;
1.789 droeschl 7069: }
7070:
1.771 droeschl 7071: table.LC_tableBrowseRes a,
1.768 schulted 7072: table.LC_tableOfContent a {
1.911 bisitz 7073: background-color: transparent;
7074: text-decoration: none;
1.753 droeschl 7075: }
7076:
1.795 www 7077: table.LC_tableOfContent img {
1.911 bisitz 7078: border: none;
7079: height: 1.3em;
7080: vertical-align: text-bottom;
7081: margin-right: 0.3em;
1.753 droeschl 7082: }
1.757 schulted 7083:
1.795 www 7084: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7085: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7086: }
7087:
1.795 www 7088: a#LC_content_toolbar_everything {
1.911 bisitz 7089: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7090: }
7091:
1.795 www 7092: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7093: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7094: }
7095:
1.795 www 7096: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7097: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7098: }
7099:
1.795 www 7100: a#LC_content_toolbar_changefolder {
1.911 bisitz 7101: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7102: }
7103:
1.795 www 7104: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7105: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7106: }
7107:
1.1043 raeburn 7108: a#LC_content_toolbar_edittoplevel {
7109: background-image:url(/res/adm/pages/edittoplevel.gif);
7110: }
7111:
1.795 www 7112: ul#LC_toolbar li a:hover {
1.911 bisitz 7113: background-position: bottom center;
1.757 schulted 7114: }
7115:
1.795 www 7116: ul#LC_toolbar {
1.911 bisitz 7117: padding: 0;
7118: margin: 2px;
7119: list-style:none;
7120: position:relative;
7121: background-color:white;
1.1082 raeburn 7122: overflow: auto;
1.757 schulted 7123: }
7124:
1.795 www 7125: ul#LC_toolbar li {
1.911 bisitz 7126: border:1px solid white;
7127: padding: 0;
7128: margin: 0;
7129: float: left;
7130: display:inline;
7131: vertical-align:middle;
1.1082 raeburn 7132: white-space: nowrap;
1.911 bisitz 7133: }
1.757 schulted 7134:
1.783 amueller 7135:
1.795 www 7136: a.LC_toolbarItem {
1.911 bisitz 7137: display:block;
7138: padding: 0;
7139: margin: 0;
7140: height: 32px;
7141: width: 32px;
7142: color:white;
7143: border: none;
7144: background-repeat:no-repeat;
7145: background-color:transparent;
1.757 schulted 7146: }
7147:
1.915 droeschl 7148: ul.LC_funclist {
7149: margin: 0;
7150: padding: 0.5em 1em 0.5em 0;
7151: }
7152:
1.933 droeschl 7153: ul.LC_funclist > li:first-child {
7154: font-weight:bold;
7155: margin-left:0.8em;
7156: }
7157:
1.915 droeschl 7158: ul.LC_funclist + ul.LC_funclist {
7159: /*
7160: left border as a seperator if we have more than
7161: one list
7162: */
7163: border-left: 1px solid $sidebg;
7164: /*
7165: this hides the left border behind the border of the
7166: outer box if element is wrapped to the next 'line'
7167: */
7168: margin-left: -1px;
7169: }
7170:
1.843 bisitz 7171: ul.LC_funclist li {
1.915 droeschl 7172: display: inline;
1.782 bisitz 7173: white-space: nowrap;
1.915 droeschl 7174: margin: 0 0 0 25px;
7175: line-height: 150%;
1.782 bisitz 7176: }
7177:
1.974 wenzelju 7178: .LC_hidden {
7179: display: none;
7180: }
7181:
1.1030 www 7182: .LCmodal-overlay {
7183: position:fixed;
7184: top:0;
7185: right:0;
7186: bottom:0;
7187: left:0;
7188: height:100%;
7189: width:100%;
7190: margin:0;
7191: padding:0;
7192: background:#999;
7193: opacity:.75;
7194: filter: alpha(opacity=75);
7195: -moz-opacity: 0.75;
7196: z-index:101;
7197: }
7198:
7199: * html .LCmodal-overlay {
7200: position: absolute;
7201: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7202: }
7203:
7204: .LCmodal-window {
7205: position:fixed;
7206: top:50%;
7207: left:50%;
7208: margin:0;
7209: padding:0;
7210: z-index:102;
7211: }
7212:
7213: * html .LCmodal-window {
7214: position:absolute;
7215: }
7216:
7217: .LCclose-window {
7218: position:absolute;
7219: width:32px;
7220: height:32px;
7221: right:8px;
7222: top:8px;
7223: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7224: text-indent:-99999px;
7225: overflow:hidden;
7226: cursor:pointer;
7227: }
7228:
1.1100 raeburn 7229: /*
7230: styles used by TTH when "Default set of options to pass to tth/m
7231: when converting TeX" in course settings has been set
7232:
7233: option passed: -t
7234:
7235: */
7236:
7237: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7238: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7239: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7240: td div.norm {line-height:normal;}
7241:
7242: /*
7243: option passed -y3
7244: */
7245:
7246: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7247: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7248: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7249:
1.343 albertel 7250: END
7251: }
7252:
1.306 albertel 7253: =pod
7254:
7255: =item * &headtag()
7256:
7257: Returns a uniform footer for LON-CAPA web pages.
7258:
1.307 albertel 7259: Inputs: $title - optional title for the head
7260: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7261: $args - optional arguments
1.319 albertel 7262: force_register - if is true call registerurl so the remote is
7263: informed
1.415 albertel 7264: redirect -> array ref of
7265: 1- seconds before redirect occurs
7266: 2- url to redirect to
7267: 3- whether the side effect should occur
1.315 albertel 7268: (side effect of setting
7269: $env{'internal.head.redirect'} to the url
7270: redirected too)
1.352 albertel 7271: domain -> force to color decorate a page for a specific
7272: domain
7273: function -> force usage of a specific rolish color scheme
7274: bgcolor -> override the default page bgcolor
1.460 albertel 7275: no_auto_mt_title
7276: -> prevent &mt()ing the title arg
1.464 albertel 7277:
1.306 albertel 7278: =cut
7279:
7280: sub headtag {
1.313 albertel 7281: my ($title,$head_extra,$args) = @_;
1.306 albertel 7282:
1.363 albertel 7283: my $function = $args->{'function'} || &get_users_function();
7284: my $domain = $args->{'domain'} || &determinedomain();
7285: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7286: my $httphost = $args->{'use_absolute'};
1.418 albertel 7287: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7288: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7289: #time(),
1.418 albertel 7290: $env{'environment.color.timestamp'},
1.363 albertel 7291: $function,$domain,$bgcolor);
7292:
1.369 www 7293: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7294:
1.308 albertel 7295: my $result =
7296: '<head>'.
1.1160 raeburn 7297: &font_settings($args);
1.319 albertel 7298:
1.1064 raeburn 7299: my $inhibitprint = &print_suppression();
7300:
1.461 albertel 7301: if (!$args->{'frameset'}) {
7302: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7303: }
1.962 droeschl 7304: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7305: $result .= Apache::lonxml::display_title();
1.319 albertel 7306: }
1.436 albertel 7307: if (!$args->{'no_nav_bar'}
7308: && !$args->{'only_body'}
7309: && !$args->{'frameset'}) {
1.1154 raeburn 7310: $result .= &help_menu_js($httphost);
1.1032 www 7311: $result.=&modal_window();
1.1038 www 7312: $result.=&togglebox_script();
1.1034 www 7313: $result.=&wishlist_window();
1.1041 www 7314: $result.=&LCprogressbarUpdate_script();
1.1034 www 7315: } else {
7316: if ($args->{'add_modal'}) {
7317: $result.=&modal_window();
7318: }
7319: if ($args->{'add_wishlist'}) {
7320: $result.=&wishlist_window();
7321: }
1.1038 www 7322: if ($args->{'add_togglebox'}) {
7323: $result.=&togglebox_script();
7324: }
1.1041 www 7325: if ($args->{'add_progressbar'}) {
7326: $result.=&LCprogressbarUpdate_script();
7327: }
1.436 albertel 7328: }
1.314 albertel 7329: if (ref($args->{'redirect'})) {
1.414 albertel 7330: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7331: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7332: if (!$inhibit_continue) {
7333: $env{'internal.head.redirect'} = $url;
7334: }
1.313 albertel 7335: $result.=<<ADDMETA
7336: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7337: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7338: ADDMETA
7339: }
1.306 albertel 7340: if (!defined($title)) {
7341: $title = 'The LearningOnline Network with CAPA';
7342: }
1.460 albertel 7343: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7344: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7345: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7346: if (!$args->{'frameset'}) {
7347: $result .= ' /';
7348: }
7349: $result .= '>'
1.1064 raeburn 7350: .$inhibitprint
1.414 albertel 7351: .$head_extra;
1.1137 raeburn 7352: if ($env{'browser.mobile'}) {
7353: $result .= '
7354: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7355: <meta name="apple-mobile-web-app-capable" content="yes" />';
7356: }
1.962 droeschl 7357: return $result.'</head>';
1.306 albertel 7358: }
7359:
7360: =pod
7361:
1.340 albertel 7362: =item * &font_settings()
7363:
7364: Returns neccessary <meta> to set the proper encoding
7365:
1.1160 raeburn 7366: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7367:
7368: =cut
7369:
7370: sub font_settings {
1.1160 raeburn 7371: my ($args) = @_;
1.340 albertel 7372: my $headerstring='';
1.1160 raeburn 7373: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7374: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7375: $headerstring.=
7376: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7377: if (!$args->{'frameset'}) {
7378: $headerstring.= ' /';
7379: }
7380: $headerstring .= '>'."\n";
1.340 albertel 7381: }
7382: return $headerstring;
7383: }
7384:
1.341 albertel 7385: =pod
7386:
1.1064 raeburn 7387: =item * &print_suppression()
7388:
7389: In course context returns css which causes the body to be blank when media="print",
7390: if printout generation is unavailable for the current resource.
7391:
7392: This could be because:
7393:
7394: (a) printstartdate is in the future
7395:
7396: (b) printenddate is in the past
7397:
7398: (c) there is an active exam block with "printout"
7399: functionality blocked
7400:
7401: Users with pav, pfo or evb privileges are exempt.
7402:
7403: Inputs: none
7404:
7405: =cut
7406:
7407:
7408: sub print_suppression {
7409: my $noprint;
7410: if ($env{'request.course.id'}) {
7411: my $scope = $env{'request.course.id'};
7412: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7413: (&Apache::lonnet::allowed('pfo',$scope))) {
7414: return;
7415: }
7416: if ($env{'request.course.sec'} ne '') {
7417: $scope .= "/$env{'request.course.sec'}";
7418: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7419: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7420: return;
1.1064 raeburn 7421: }
7422: }
7423: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7424: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7425: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7426: if ($blocked) {
7427: my $checkrole = "cm./$cdom/$cnum";
7428: if ($env{'request.course.sec'} ne '') {
7429: $checkrole .= "/$env{'request.course.sec'}";
7430: }
7431: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7432: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7433: $noprint = 1;
7434: }
7435: }
7436: unless ($noprint) {
7437: my $symb = &Apache::lonnet::symbread();
7438: if ($symb ne '') {
7439: my $navmap = Apache::lonnavmaps::navmap->new();
7440: if (ref($navmap)) {
7441: my $res = $navmap->getBySymb($symb);
7442: if (ref($res)) {
7443: if (!$res->resprintable()) {
7444: $noprint = 1;
7445: }
7446: }
7447: }
7448: }
7449: }
7450: if ($noprint) {
7451: return <<"ENDSTYLE";
7452: <style type="text/css" media="print">
7453: body { display:none }
7454: </style>
7455: ENDSTYLE
7456: }
7457: }
7458: return;
7459: }
7460:
7461: =pod
7462:
1.341 albertel 7463: =item * &xml_begin()
7464:
7465: Returns the needed doctype and <html>
7466:
7467: Inputs: none
7468:
7469: =cut
7470:
7471: sub xml_begin {
1.1168 raeburn 7472: my ($is_frameset) = @_;
1.341 albertel 7473: my $output='';
7474:
7475: if ($env{'browser.mathml'}) {
7476: $output='<?xml version="1.0"?>'
7477: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7478: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7479:
7480: # .'<!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">] >'
7481: .'<!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">'
7482: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7483: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7484: } elsif ($is_frameset) {
7485: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7486: '<html>'."\n";
1.341 albertel 7487: } else {
1.1168 raeburn 7488: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7489: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7490: }
7491: return $output;
7492: }
1.340 albertel 7493:
7494: =pod
7495:
1.306 albertel 7496: =item * &start_page()
7497:
7498: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7499:
1.648 raeburn 7500: Inputs:
7501:
7502: =over 4
7503:
7504: $title - optional title for the page
7505:
7506: $head_extra - optional extra HTML to incude inside the <head>
7507:
7508: $args - additional optional args supported are:
7509:
7510: =over 8
7511:
7512: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7513: arg on
1.814 bisitz 7514: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7515: add_entries -> additional attributes to add to the <body>
7516: domain -> force to color decorate a page for a
1.317 albertel 7517: specific domain
1.648 raeburn 7518: function -> force usage of a specific rolish color
1.317 albertel 7519: scheme
1.648 raeburn 7520: redirect -> see &headtag()
7521: bgcolor -> override the default page bg color
7522: js_ready -> return a string ready for being used in
1.317 albertel 7523: a javascript writeln
1.648 raeburn 7524: html_encode -> return a string ready for being used in
1.320 albertel 7525: a html attribute
1.648 raeburn 7526: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7527: $forcereg arg
1.648 raeburn 7528: frameset -> if true will start with a <frameset>
1.330 albertel 7529: rather than <body>
1.648 raeburn 7530: skip_phases -> hash ref of
1.338 albertel 7531: head -> skip the <html><head> generation
7532: body -> skip all <body> generation
1.648 raeburn 7533: no_auto_mt_title -> prevent &mt()ing the title arg
7534: inherit_jsmath -> when creating popup window in a page,
7535: should it have jsmath forced on by the
7536: current page
1.867 kalberla 7537: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7538: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7539: group -> includes the current group, if page is for a
7540: specific group
1.361 albertel 7541:
1.648 raeburn 7542: =back
1.460 albertel 7543:
1.648 raeburn 7544: =back
1.562 albertel 7545:
1.306 albertel 7546: =cut
7547:
7548: sub start_page {
1.309 albertel 7549: my ($title,$head_extra,$args) = @_;
1.318 albertel 7550: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7551:
1.315 albertel 7552: $env{'internal.start_page'}++;
1.1096 raeburn 7553: my ($result,@advtools);
1.964 droeschl 7554:
1.338 albertel 7555: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 7556: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7557: }
7558:
7559: if (! exists($args->{'skip_phases'}{'body'}) ) {
7560: if ($args->{'frameset'}) {
7561: my $attr_string = &make_attr_string($args->{'force_register'},
7562: $args->{'add_entries'});
7563: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7564: } else {
7565: $result .=
7566: &bodytag($title,
7567: $args->{'function'}, $args->{'add_entries'},
7568: $args->{'only_body'}, $args->{'domain'},
7569: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7570: $args->{'bgcolor'}, $args,
7571: \@advtools);
1.831 bisitz 7572: }
1.330 albertel 7573: }
1.338 albertel 7574:
1.315 albertel 7575: if ($args->{'js_ready'}) {
1.713 kaisler 7576: $result = &js_ready($result);
1.315 albertel 7577: }
1.320 albertel 7578: if ($args->{'html_encode'}) {
1.713 kaisler 7579: $result = &html_encode($result);
7580: }
7581:
1.813 bisitz 7582: # Preparation for new and consistent functionlist at top of screen
7583: # if ($args->{'functionlist'}) {
7584: # $result .= &build_functionlist();
7585: #}
7586:
1.964 droeschl 7587: # Don't add anything more if only_body wanted or in const space
7588: return $result if $args->{'only_body'}
7589: || $env{'request.state'} eq 'construct';
1.813 bisitz 7590:
7591: #Breadcrumbs
1.758 kaisler 7592: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7593: &Apache::lonhtmlcommon::clear_breadcrumbs();
7594: #if any br links exists, add them to the breadcrumbs
7595: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7596: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7597: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7598: }
7599: }
1.1096 raeburn 7600: # if @advtools array contains items add then to the breadcrumbs
7601: if (@advtools > 0) {
7602: &Apache::lonmenu::advtools_crumbs(@advtools);
7603: }
1.758 kaisler 7604:
7605: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7606: if(exists($args->{'bread_crumbs_component'})){
7607: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7608: }else{
7609: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7610: }
1.320 albertel 7611: }
1.315 albertel 7612: return $result;
1.306 albertel 7613: }
7614:
7615: sub end_page {
1.315 albertel 7616: my ($args) = @_;
7617: $env{'internal.end_page'}++;
1.330 albertel 7618: my $result;
1.335 albertel 7619: if ($args->{'discussion'}) {
7620: my ($target,$parser);
7621: if (ref($args->{'discussion'})) {
7622: ($target,$parser) =($args->{'discussion'}{'target'},
7623: $args->{'discussion'}{'parser'});
7624: }
7625: $result .= &Apache::lonxml::xmlend($target,$parser);
7626: }
1.330 albertel 7627: if ($args->{'frameset'}) {
7628: $result .= '</frameset>';
7629: } else {
1.635 raeburn 7630: $result .= &endbodytag($args);
1.330 albertel 7631: }
1.1080 raeburn 7632: unless ($args->{'notbody'}) {
7633: $result .= "\n</html>";
7634: }
1.330 albertel 7635:
1.315 albertel 7636: if ($args->{'js_ready'}) {
1.317 albertel 7637: $result = &js_ready($result);
1.315 albertel 7638: }
1.335 albertel 7639:
1.320 albertel 7640: if ($args->{'html_encode'}) {
7641: $result = &html_encode($result);
7642: }
1.335 albertel 7643:
1.315 albertel 7644: return $result;
7645: }
7646:
1.1034 www 7647: sub wishlist_window {
7648: return(<<'ENDWISHLIST');
1.1046 raeburn 7649: <script type="text/javascript">
1.1034 www 7650: // <![CDATA[
7651: // <!-- BEGIN LON-CAPA Internal
7652: function set_wishlistlink(title, path) {
7653: if (!title) {
7654: title = document.title;
7655: title = title.replace(/^LON-CAPA /,'');
7656: }
7657: if (!path) {
7658: path = location.pathname;
7659: }
7660: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7661: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7662: }
7663: // END LON-CAPA Internal -->
7664: // ]]>
7665: </script>
7666: ENDWISHLIST
7667: }
7668:
1.1030 www 7669: sub modal_window {
7670: return(<<'ENDMODAL');
1.1046 raeburn 7671: <script type="text/javascript">
1.1030 www 7672: // <![CDATA[
7673: // <!-- BEGIN LON-CAPA Internal
7674: var modalWindow = {
7675: parent:"body",
7676: windowId:null,
7677: content:null,
7678: width:null,
7679: height:null,
7680: close:function()
7681: {
7682: $(".LCmodal-window").remove();
7683: $(".LCmodal-overlay").remove();
7684: },
7685: open:function()
7686: {
7687: var modal = "";
7688: modal += "<div class=\"LCmodal-overlay\"></div>";
7689: 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;\">";
7690: modal += this.content;
7691: modal += "</div>";
7692:
7693: $(this.parent).append(modal);
7694:
7695: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7696: $(".LCclose-window").click(function(){modalWindow.close();});
7697: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7698: }
7699: };
1.1140 raeburn 7700: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7701: {
7702: modalWindow.windowId = "myModal";
7703: modalWindow.width = width;
7704: modalWindow.height = height;
1.1140 raeburn 7705: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7706: modalWindow.open();
7707: };
7708: // END LON-CAPA Internal -->
7709: // ]]>
7710: </script>
7711: ENDMODAL
7712: }
7713:
7714: sub modal_link {
1.1140 raeburn 7715: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7716: unless ($width) { $width=480; }
7717: unless ($height) { $height=400; }
1.1031 www 7718: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 7719: unless ($transparency) { $transparency='true'; }
7720:
1.1074 raeburn 7721: my $target_attr;
7722: if (defined($target)) {
7723: $target_attr = 'target="'.$target.'"';
7724: }
7725: return <<"ENDLINK";
1.1140 raeburn 7726: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7727: $linktext</a>
7728: ENDLINK
1.1030 www 7729: }
7730:
1.1032 www 7731: sub modal_adhoc_script {
7732: my ($funcname,$width,$height,$content)=@_;
7733: return (<<ENDADHOC);
1.1046 raeburn 7734: <script type="text/javascript">
1.1032 www 7735: // <![CDATA[
7736: var $funcname = function()
7737: {
7738: modalWindow.windowId = "myModal";
7739: modalWindow.width = $width;
7740: modalWindow.height = $height;
7741: modalWindow.content = '$content';
7742: modalWindow.open();
7743: };
7744: // ]]>
7745: </script>
7746: ENDADHOC
7747: }
7748:
1.1041 www 7749: sub modal_adhoc_inner {
7750: my ($funcname,$width,$height,$content)=@_;
7751: my $innerwidth=$width-20;
7752: $content=&js_ready(
1.1140 raeburn 7753: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
7754: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7755: $content.
1.1041 www 7756: &end_scrollbox().
1.1140 raeburn 7757: &end_page()
1.1041 www 7758: );
7759: return &modal_adhoc_script($funcname,$width,$height,$content);
7760: }
7761:
7762: sub modal_adhoc_window {
7763: my ($funcname,$width,$height,$content,$linktext)=@_;
7764: return &modal_adhoc_inner($funcname,$width,$height,$content).
7765: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7766: }
7767:
7768: sub modal_adhoc_launch {
7769: my ($funcname,$width,$height,$content)=@_;
7770: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7771: <script type="text/javascript">
7772: // <![CDATA[
7773: $funcname();
7774: // ]]>
7775: </script>
7776: ENDLAUNCH
7777: }
7778:
7779: sub modal_adhoc_close {
7780: return (<<ENDCLOSE);
7781: <script type="text/javascript">
7782: // <![CDATA[
7783: modalWindow.close();
7784: // ]]>
7785: </script>
7786: ENDCLOSE
7787: }
7788:
1.1038 www 7789: sub togglebox_script {
7790: return(<<ENDTOGGLE);
7791: <script type="text/javascript">
7792: // <![CDATA[
7793: function LCtoggleDisplay(id,hidetext,showtext) {
7794: link = document.getElementById(id + "link").childNodes[0];
7795: with (document.getElementById(id).style) {
7796: if (display == "none" ) {
7797: display = "inline";
7798: link.nodeValue = hidetext;
7799: } else {
7800: display = "none";
7801: link.nodeValue = showtext;
7802: }
7803: }
7804: }
7805: // ]]>
7806: </script>
7807: ENDTOGGLE
7808: }
7809:
1.1039 www 7810: sub start_togglebox {
7811: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7812: unless ($heading) { $heading=''; } else { $heading.=' '; }
7813: unless ($showtext) { $showtext=&mt('show'); }
7814: unless ($hidetext) { $hidetext=&mt('hide'); }
7815: unless ($headerbg) { $headerbg='#FFFFFF'; }
7816: return &start_data_table().
7817: &start_data_table_header_row().
7818: '<td bgcolor="'.$headerbg.'">'.$heading.
7819: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7820: $showtext.'\')">'.$showtext.'</a>]</td>'.
7821: &end_data_table_header_row().
7822: '<tr id="'.$id.'" style="display:none""><td>';
7823: }
7824:
7825: sub end_togglebox {
7826: return '</td></tr>'.&end_data_table();
7827: }
7828:
1.1041 www 7829: sub LCprogressbar_script {
1.1045 www 7830: my ($id)=@_;
1.1041 www 7831: return(<<ENDPROGRESS);
7832: <script type="text/javascript">
7833: // <![CDATA[
1.1045 www 7834: \$('#progressbar$id').progressbar({
1.1041 www 7835: value: 0,
7836: change: function(event, ui) {
7837: var newVal = \$(this).progressbar('option', 'value');
7838: \$('.pblabel', this).text(LCprogressTxt);
7839: }
7840: });
7841: // ]]>
7842: </script>
7843: ENDPROGRESS
7844: }
7845:
7846: sub LCprogressbarUpdate_script {
7847: return(<<ENDPROGRESSUPDATE);
7848: <style type="text/css">
7849: .ui-progressbar { position:relative; }
7850: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7851: </style>
7852: <script type="text/javascript">
7853: // <![CDATA[
1.1045 www 7854: var LCprogressTxt='---';
7855:
7856: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7857: LCprogressTxt=progresstext;
1.1045 www 7858: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7859: }
7860: // ]]>
7861: </script>
7862: ENDPROGRESSUPDATE
7863: }
7864:
1.1042 www 7865: my $LClastpercent;
1.1045 www 7866: my $LCidcnt;
7867: my $LCcurrentid;
1.1042 www 7868:
1.1041 www 7869: sub LCprogressbar {
1.1042 www 7870: my ($r)=(@_);
7871: $LClastpercent=0;
1.1045 www 7872: $LCidcnt++;
7873: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7874: my $starting=&mt('Starting');
7875: my $content=(<<ENDPROGBAR);
1.1045 www 7876: <div id="progressbar$LCcurrentid">
1.1041 www 7877: <span class="pblabel">$starting</span>
7878: </div>
7879: ENDPROGBAR
1.1045 www 7880: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7881: }
7882:
7883: sub LCprogressbarUpdate {
1.1042 www 7884: my ($r,$val,$text)=@_;
7885: unless ($val) {
7886: if ($LClastpercent) {
7887: $val=$LClastpercent;
7888: } else {
7889: $val=0;
7890: }
7891: }
1.1041 www 7892: if ($val<0) { $val=0; }
7893: if ($val>100) { $val=0; }
1.1042 www 7894: $LClastpercent=$val;
1.1041 www 7895: unless ($text) { $text=$val.'%'; }
7896: $text=&js_ready($text);
1.1044 www 7897: &r_print($r,<<ENDUPDATE);
1.1041 www 7898: <script type="text/javascript">
7899: // <![CDATA[
1.1045 www 7900: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7901: // ]]>
7902: </script>
7903: ENDUPDATE
1.1035 www 7904: }
7905:
1.1042 www 7906: sub LCprogressbarClose {
7907: my ($r)=@_;
7908: $LClastpercent=0;
1.1044 www 7909: &r_print($r,<<ENDCLOSE);
1.1042 www 7910: <script type="text/javascript">
7911: // <![CDATA[
1.1045 www 7912: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7913: // ]]>
7914: </script>
7915: ENDCLOSE
1.1044 www 7916: }
7917:
7918: sub r_print {
7919: my ($r,$to_print)=@_;
7920: if ($r) {
7921: $r->print($to_print);
7922: $r->rflush();
7923: } else {
7924: print($to_print);
7925: }
1.1042 www 7926: }
7927:
1.320 albertel 7928: sub html_encode {
7929: my ($result) = @_;
7930:
1.322 albertel 7931: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7932:
7933: return $result;
7934: }
1.1044 www 7935:
1.317 albertel 7936: sub js_ready {
7937: my ($result) = @_;
7938:
1.323 albertel 7939: $result =~ s/[\n\r]/ /xmsg;
7940: $result =~ s/\\/\\\\/xmsg;
7941: $result =~ s/'/\\'/xmsg;
1.372 albertel 7942: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7943:
7944: return $result;
7945: }
7946:
1.315 albertel 7947: sub validate_page {
7948: if ( exists($env{'internal.start_page'})
1.316 albertel 7949: && $env{'internal.start_page'} > 1) {
7950: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7951: $env{'internal.start_page'}.' '.
1.316 albertel 7952: $ENV{'request.filename'});
1.315 albertel 7953: }
7954: if ( exists($env{'internal.end_page'})
1.316 albertel 7955: && $env{'internal.end_page'} > 1) {
7956: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7957: $env{'internal.end_page'}.' '.
1.316 albertel 7958: $env{'request.filename'});
1.315 albertel 7959: }
7960: if ( exists($env{'internal.start_page'})
7961: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7962: &Apache::lonnet::logthis('start_page called without end_page '.
7963: $env{'request.filename'});
1.315 albertel 7964: }
7965: if ( ! exists($env{'internal.start_page'})
7966: && exists($env{'internal.end_page'})) {
1.316 albertel 7967: &Apache::lonnet::logthis('end_page called without start_page'.
7968: $env{'request.filename'});
1.315 albertel 7969: }
1.306 albertel 7970: }
1.315 albertel 7971:
1.996 www 7972:
7973: sub start_scrollbox {
1.1140 raeburn 7974: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7975: unless ($outerwidth) { $outerwidth='520px'; }
7976: unless ($width) { $width='500px'; }
7977: unless ($height) { $height='200px'; }
1.1075 raeburn 7978: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7979: if ($id ne '') {
1.1140 raeburn 7980: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 7981: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7982: }
1.1075 raeburn 7983: if ($bgcolor ne '') {
7984: $tdcol = "background-color: $bgcolor;";
7985: }
1.1137 raeburn 7986: my $nicescroll_js;
7987: if ($env{'browser.mobile'}) {
1.1140 raeburn 7988: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7989: }
7990: return <<"END";
7991: $nicescroll_js
7992:
7993: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
7994: <div style="overflow:auto; width:$width; height:$height;"$div_id>
7995: END
7996: }
7997:
7998: sub end_scrollbox {
7999: return '</div></td></tr></table>';
8000: }
8001:
8002: sub nicescroll_javascript {
8003: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8004: my %options;
8005: if (ref($cursor) eq 'HASH') {
8006: %options = %{$cursor};
8007: }
8008: unless ($options{'railalign'} =~ /^left|right$/) {
8009: $options{'railalign'} = 'left';
8010: }
8011: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8012: my $function = &get_users_function();
8013: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8014: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8015: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8016: }
1.1140 raeburn 8017: }
8018: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8019: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8020: $options{'cursoropacity'}='1.0';
8021: }
1.1140 raeburn 8022: } else {
8023: $options{'cursoropacity'}='1.0';
8024: }
8025: if ($options{'cursorfixedheight'} eq 'none') {
8026: delete($options{'cursorfixedheight'});
8027: } else {
8028: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8029: }
8030: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8031: delete($options{'railoffset'});
8032: }
8033: my @niceoptions;
8034: while (my($key,$value) = each(%options)) {
8035: if ($value =~ /^\{.+\}$/) {
8036: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8037: } else {
1.1140 raeburn 8038: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8039: }
1.1140 raeburn 8040: }
8041: my $nicescroll_js = '
1.1137 raeburn 8042: $(document).ready(
1.1140 raeburn 8043: function() {
8044: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8045: }
1.1137 raeburn 8046: );
8047: ';
1.1140 raeburn 8048: if ($framecheck) {
8049: $nicescroll_js .= '
8050: function expand_div(caller) {
8051: if (top === self) {
8052: document.getElementById("'.$id.'").style.width = "auto";
8053: document.getElementById("'.$id.'").style.height = "auto";
8054: } else {
8055: try {
8056: if (parent.frames) {
8057: if (parent.frames.length > 1) {
8058: var framesrc = parent.frames[1].location.href;
8059: var currsrc = framesrc.replace(/\#.*$/,"");
8060: if ((caller == "search") || (currsrc == "'.$location.'")) {
8061: document.getElementById("'.$id.'").style.width = "auto";
8062: document.getElementById("'.$id.'").style.height = "auto";
8063: }
8064: }
8065: }
8066: } catch (e) {
8067: return;
8068: }
1.1137 raeburn 8069: }
1.1140 raeburn 8070: return;
1.996 www 8071: }
1.1140 raeburn 8072: ';
8073: }
8074: if ($needjsready) {
8075: $nicescroll_js = '
8076: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8077: } else {
8078: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8079: }
8080: return $nicescroll_js;
1.996 www 8081: }
8082:
1.318 albertel 8083: sub simple_error_page {
1.1150 bisitz 8084: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8085: if (ref($args) eq 'HASH') {
8086: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8087: } else {
8088: $msg = &mt($msg);
8089: }
1.1150 bisitz 8090:
1.318 albertel 8091: my $page =
8092: &Apache::loncommon::start_page($title).
1.1150 bisitz 8093: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8094: &Apache::loncommon::end_page();
8095: if (ref($r)) {
8096: $r->print($page);
1.327 albertel 8097: return;
1.318 albertel 8098: }
8099: return $page;
8100: }
1.347 albertel 8101:
8102: {
1.610 albertel 8103: my @row_count;
1.961 onken 8104:
8105: sub start_data_table_count {
8106: unshift(@row_count, 0);
8107: return;
8108: }
8109:
8110: sub end_data_table_count {
8111: shift(@row_count);
8112: return;
8113: }
8114:
1.347 albertel 8115: sub start_data_table {
1.1018 raeburn 8116: my ($add_class,$id) = @_;
1.422 albertel 8117: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8118: my $table_id;
8119: if (defined($id)) {
8120: $table_id = ' id="'.$id.'"';
8121: }
1.961 onken 8122: &start_data_table_count();
1.1018 raeburn 8123: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8124: }
8125:
8126: sub end_data_table {
1.961 onken 8127: &end_data_table_count();
1.389 albertel 8128: return '</table>'."\n";;
1.347 albertel 8129: }
8130:
8131: sub start_data_table_row {
1.974 wenzelju 8132: my ($add_class, $id) = @_;
1.610 albertel 8133: $row_count[0]++;
8134: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8135: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8136: $id = (' id="'.$id.'"') unless ($id eq '');
8137: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8138: }
1.471 banghart 8139:
8140: sub continue_data_table_row {
1.974 wenzelju 8141: my ($add_class, $id) = @_;
1.610 albertel 8142: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8143: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8144: $id = (' id="'.$id.'"') unless ($id eq '');
8145: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8146: }
1.347 albertel 8147:
8148: sub end_data_table_row {
1.389 albertel 8149: return '</tr>'."\n";;
1.347 albertel 8150: }
1.367 www 8151:
1.421 albertel 8152: sub start_data_table_empty_row {
1.707 bisitz 8153: # $row_count[0]++;
1.421 albertel 8154: return '<tr class="LC_empty_row" >'."\n";;
8155: }
8156:
8157: sub end_data_table_empty_row {
8158: return '</tr>'."\n";;
8159: }
8160:
1.367 www 8161: sub start_data_table_header_row {
1.389 albertel 8162: return '<tr class="LC_header_row">'."\n";;
1.367 www 8163: }
8164:
8165: sub end_data_table_header_row {
1.389 albertel 8166: return '</tr>'."\n";;
1.367 www 8167: }
1.890 droeschl 8168:
8169: sub data_table_caption {
8170: my $caption = shift;
8171: return "<caption class=\"LC_caption\">$caption</caption>";
8172: }
1.347 albertel 8173: }
8174:
1.548 albertel 8175: =pod
8176:
8177: =item * &inhibit_menu_check($arg)
8178:
8179: Checks for a inhibitmenu state and generates output to preserve it
8180:
8181: Inputs: $arg - can be any of
8182: - undef - in which case the return value is a string
8183: to add into arguments list of a uri
8184: - 'input' - in which case the return value is a HTML
8185: <form> <input> field of type hidden to
8186: preserve the value
8187: - a url - in which case the return value is the url with
8188: the neccesary cgi args added to preserve the
8189: inhibitmenu state
8190: - a ref to a url - no return value, but the string is
8191: updated to include the neccessary cgi
8192: args to preserve the inhibitmenu state
8193:
8194: =cut
8195:
8196: sub inhibit_menu_check {
8197: my ($arg) = @_;
8198: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8199: if ($arg eq 'input') {
8200: if ($env{'form.inhibitmenu'}) {
8201: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8202: } else {
8203: return
8204: }
8205: }
8206: if ($env{'form.inhibitmenu'}) {
8207: if (ref($arg)) {
8208: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8209: } elsif ($arg eq '') {
8210: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8211: } else {
8212: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8213: }
8214: }
8215: if (!ref($arg)) {
8216: return $arg;
8217: }
8218: }
8219:
1.251 albertel 8220: ###############################################
1.182 matthew 8221:
8222: =pod
8223:
1.549 albertel 8224: =back
8225:
8226: =head1 User Information Routines
8227:
8228: =over 4
8229:
1.405 albertel 8230: =item * &get_users_function()
1.182 matthew 8231:
8232: Used by &bodytag to determine the current users primary role.
8233: Returns either 'student','coordinator','admin', or 'author'.
8234:
8235: =cut
8236:
8237: ###############################################
8238: sub get_users_function {
1.815 tempelho 8239: my $function = 'norole';
1.818 tempelho 8240: if ($env{'request.role'}=~/^(st)/) {
8241: $function='student';
8242: }
1.907 raeburn 8243: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8244: $function='coordinator';
8245: }
1.258 albertel 8246: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8247: $function='admin';
8248: }
1.826 bisitz 8249: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8250: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8251: $function='author';
8252: }
8253: return $function;
1.54 www 8254: }
1.99 www 8255:
8256: ###############################################
8257:
1.233 raeburn 8258: =pod
8259:
1.821 raeburn 8260: =item * &show_course()
8261:
8262: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8263: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8264:
8265: Inputs:
8266: None
8267:
8268: Outputs:
8269: Scalar: 1 if 'Course' to be used, 0 otherwise.
8270:
8271: =cut
8272:
8273: ###############################################
8274: sub show_course {
8275: my $course = !$env{'user.adv'};
8276: if (!$env{'user.adv'}) {
8277: foreach my $env (keys(%env)) {
8278: next if ($env !~ m/^user\.priv\./);
8279: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8280: $course = 0;
8281: last;
8282: }
8283: }
8284: }
8285: return $course;
8286: }
8287:
8288: ###############################################
8289:
8290: =pod
8291:
1.542 raeburn 8292: =item * &check_user_status()
1.274 raeburn 8293:
8294: Determines current status of supplied role for a
8295: specific user. Roles can be active, previous or future.
8296:
8297: Inputs:
8298: user's domain, user's username, course's domain,
1.375 raeburn 8299: course's number, optional section ID.
1.274 raeburn 8300:
8301: Outputs:
8302: role status: active, previous or future.
8303:
8304: =cut
8305:
8306: sub check_user_status {
1.412 raeburn 8307: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8308: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8309: my @uroles = keys %userinfo;
8310: my $srchstr;
8311: my $active_chk = 'none';
1.412 raeburn 8312: my $now = time;
1.274 raeburn 8313: if (@uroles > 0) {
1.908 raeburn 8314: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8315: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8316: } else {
1.412 raeburn 8317: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8318: }
8319: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8320: my $role_end = 0;
8321: my $role_start = 0;
8322: $active_chk = 'active';
1.412 raeburn 8323: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8324: $role_end = $1;
8325: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8326: $role_start = $1;
1.274 raeburn 8327: }
8328: }
8329: if ($role_start > 0) {
1.412 raeburn 8330: if ($now < $role_start) {
1.274 raeburn 8331: $active_chk = 'future';
8332: }
8333: }
8334: if ($role_end > 0) {
1.412 raeburn 8335: if ($now > $role_end) {
1.274 raeburn 8336: $active_chk = 'previous';
8337: }
8338: }
8339: }
8340: }
8341: return $active_chk;
8342: }
8343:
8344: ###############################################
8345:
8346: =pod
8347:
1.405 albertel 8348: =item * &get_sections()
1.233 raeburn 8349:
8350: Determines all the sections for a course including
8351: sections with students and sections containing other roles.
1.419 raeburn 8352: Incoming parameters:
8353:
8354: 1. domain
8355: 2. course number
8356: 3. reference to array containing roles for which sections should
8357: be gathered (optional).
8358: 4. reference to array containing status types for which sections
8359: should be gathered (optional).
8360:
8361: If the third argument is undefined, sections are gathered for any role.
8362: If the fourth argument is undefined, sections are gathered for any status.
8363: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8364:
1.374 raeburn 8365: Returns section hash (keys are section IDs, values are
8366: number of users in each section), subject to the
1.419 raeburn 8367: optional roles filter, optional status filter
1.233 raeburn 8368:
8369: =cut
8370:
8371: ###############################################
8372: sub get_sections {
1.419 raeburn 8373: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8374: if (!defined($cdom) || !defined($cnum)) {
8375: my $cid = $env{'request.course.id'};
8376:
8377: return if (!defined($cid));
8378:
8379: $cdom = $env{'course.'.$cid.'.domain'};
8380: $cnum = $env{'course.'.$cid.'.num'};
8381: }
8382:
8383: my %sectioncount;
1.419 raeburn 8384: my $now = time;
1.240 albertel 8385:
1.1118 raeburn 8386: my $check_students = 1;
8387: my $only_students = 0;
8388: if (ref($possible_roles) eq 'ARRAY') {
8389: if (grep(/^st$/,@{$possible_roles})) {
8390: if (@{$possible_roles} == 1) {
8391: $only_students = 1;
8392: }
8393: } else {
8394: $check_students = 0;
8395: }
8396: }
8397:
8398: if ($check_students) {
1.276 albertel 8399: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8400: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8401: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8402: my $start_index = &Apache::loncoursedata::CL_START();
8403: my $end_index = &Apache::loncoursedata::CL_END();
8404: my $status;
1.366 albertel 8405: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8406: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8407: $data->[$status_index],
8408: $data->[$start_index],
8409: $data->[$end_index]);
8410: if ($stu_status eq 'Active') {
8411: $status = 'active';
8412: } elsif ($end < $now) {
8413: $status = 'previous';
8414: } elsif ($start > $now) {
8415: $status = 'future';
8416: }
8417: if ($section ne '-1' && $section !~ /^\s*$/) {
8418: if ((!defined($possible_status)) || (($status ne '') &&
8419: (grep/^\Q$status\E$/,@{$possible_status}))) {
8420: $sectioncount{$section}++;
8421: }
1.240 albertel 8422: }
8423: }
8424: }
1.1118 raeburn 8425: if ($only_students) {
8426: return %sectioncount;
8427: }
1.240 albertel 8428: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8429: foreach my $user (sort(keys(%courseroles))) {
8430: if ($user !~ /^(\w{2})/) { next; }
8431: my ($role) = ($user =~ /^(\w{2})/);
8432: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8433: my ($section,$status);
1.240 albertel 8434: if ($role eq 'cr' &&
8435: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8436: $section=$1;
8437: }
8438: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8439: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8440: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8441: if ($end == -1 && $start == -1) {
8442: next; #deleted role
8443: }
8444: if (!defined($possible_status)) {
8445: $sectioncount{$section}++;
8446: } else {
8447: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8448: $status = 'active';
8449: } elsif ($end < $now) {
8450: $status = 'future';
8451: } elsif ($start > $now) {
8452: $status = 'previous';
8453: }
8454: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8455: $sectioncount{$section}++;
8456: }
8457: }
1.233 raeburn 8458: }
1.366 albertel 8459: return %sectioncount;
1.233 raeburn 8460: }
8461:
1.274 raeburn 8462: ###############################################
1.294 raeburn 8463:
8464: =pod
1.405 albertel 8465:
8466: =item * &get_course_users()
8467:
1.275 raeburn 8468: Retrieves usernames:domains for users in the specified course
8469: with specific role(s), and access status.
8470:
8471: Incoming parameters:
1.277 albertel 8472: 1. course domain
8473: 2. course number
8474: 3. access status: users must have - either active,
1.275 raeburn 8475: previous, future, or all.
1.277 albertel 8476: 4. reference to array of permissible roles
1.288 raeburn 8477: 5. reference to array of section restrictions (optional)
8478: 6. reference to results object (hash of hashes).
8479: 7. reference to optional userdata hash
1.609 raeburn 8480: 8. reference to optional statushash
1.630 raeburn 8481: 9. flag if privileged users (except those set to unhide in
8482: course settings) should be excluded
1.609 raeburn 8483: Keys of top level results hash are roles.
1.275 raeburn 8484: Keys of inner hashes are username:domain, with
8485: values set to access type.
1.288 raeburn 8486: Optional userdata hash returns an array with arguments in the
8487: same order as loncoursedata::get_classlist() for student data.
8488:
1.609 raeburn 8489: Optional statushash returns
8490:
1.288 raeburn 8491: Entries for end, start, section and status are blank because
8492: of the possibility of multiple values for non-student roles.
8493:
1.275 raeburn 8494: =cut
1.405 albertel 8495:
1.275 raeburn 8496: ###############################################
1.405 albertel 8497:
1.275 raeburn 8498: sub get_course_users {
1.630 raeburn 8499: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8500: my %idx = ();
1.419 raeburn 8501: my %seclists;
1.288 raeburn 8502:
8503: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8504: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8505: $idx{end} = &Apache::loncoursedata::CL_END();
8506: $idx{start} = &Apache::loncoursedata::CL_START();
8507: $idx{id} = &Apache::loncoursedata::CL_ID();
8508: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8509: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8510: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8511:
1.290 albertel 8512: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8513: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8514: my $now = time;
1.277 albertel 8515: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8516: my $match = 0;
1.412 raeburn 8517: my $secmatch = 0;
1.419 raeburn 8518: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8519: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8520: if ($section eq '') {
8521: $section = 'none';
8522: }
1.291 albertel 8523: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8524: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8525: $secmatch = 1;
8526: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8527: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8528: $secmatch = 1;
8529: }
8530: } else {
1.419 raeburn 8531: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8532: $secmatch = 1;
8533: }
1.290 albertel 8534: }
1.412 raeburn 8535: if (!$secmatch) {
8536: next;
8537: }
1.419 raeburn 8538: }
1.275 raeburn 8539: if (defined($$types{'active'})) {
1.288 raeburn 8540: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8541: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8542: $match = 1;
1.275 raeburn 8543: }
8544: }
8545: if (defined($$types{'previous'})) {
1.609 raeburn 8546: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8547: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8548: $match = 1;
1.275 raeburn 8549: }
8550: }
8551: if (defined($$types{'future'})) {
1.609 raeburn 8552: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8553: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8554: $match = 1;
1.275 raeburn 8555: }
8556: }
1.609 raeburn 8557: if ($match) {
8558: push(@{$seclists{$student}},$section);
8559: if (ref($userdata) eq 'HASH') {
8560: $$userdata{$student} = $$classlist{$student};
8561: }
8562: if (ref($statushash) eq 'HASH') {
8563: $statushash->{$student}{'st'}{$section} = $status;
8564: }
1.288 raeburn 8565: }
1.275 raeburn 8566: }
8567: }
1.412 raeburn 8568: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8569: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8570: my $now = time;
1.609 raeburn 8571: my %displaystatus = ( previous => 'Expired',
8572: active => 'Active',
8573: future => 'Future',
8574: );
1.1121 raeburn 8575: my (%nothide,@possdoms);
1.630 raeburn 8576: if ($hidepriv) {
8577: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8578: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8579: if ($user !~ /:/) {
8580: $nothide{join(':',split(/[\@]/,$user))}=1;
8581: } else {
8582: $nothide{$user} = 1;
8583: }
8584: }
1.1121 raeburn 8585: my @possdoms = ($cdom);
8586: if ($coursehash{'checkforpriv'}) {
8587: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8588: }
1.630 raeburn 8589: }
1.439 raeburn 8590: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8591: my $match = 0;
1.412 raeburn 8592: my $secmatch = 0;
1.439 raeburn 8593: my $status;
1.412 raeburn 8594: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8595: $user =~ s/:$//;
1.439 raeburn 8596: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8597: if ($end == -1 || $start == -1) {
8598: next;
8599: }
8600: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8601: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8602: my ($uname,$udom) = split(/:/,$user);
8603: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8604: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8605: $secmatch = 1;
8606: } elsif ($usec eq '') {
1.420 albertel 8607: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8608: $secmatch = 1;
8609: }
8610: } else {
8611: if (grep(/^\Q$usec\E$/,@{$sections})) {
8612: $secmatch = 1;
8613: }
8614: }
8615: if (!$secmatch) {
8616: next;
8617: }
1.288 raeburn 8618: }
1.419 raeburn 8619: if ($usec eq '') {
8620: $usec = 'none';
8621: }
1.275 raeburn 8622: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8623: if ($hidepriv) {
1.1121 raeburn 8624: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8625: (!$nothide{$uname.':'.$udom})) {
8626: next;
8627: }
8628: }
1.503 raeburn 8629: if ($end > 0 && $end < $now) {
1.439 raeburn 8630: $status = 'previous';
8631: } elsif ($start > $now) {
8632: $status = 'future';
8633: } else {
8634: $status = 'active';
8635: }
1.277 albertel 8636: foreach my $type (keys(%{$types})) {
1.275 raeburn 8637: if ($status eq $type) {
1.420 albertel 8638: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8639: push(@{$$users{$role}{$user}},$type);
8640: }
1.288 raeburn 8641: $match = 1;
8642: }
8643: }
1.419 raeburn 8644: if (($match) && (ref($userdata) eq 'HASH')) {
8645: if (!exists($$userdata{$uname.':'.$udom})) {
8646: &get_user_info($udom,$uname,\%idx,$userdata);
8647: }
1.420 albertel 8648: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8649: push(@{$seclists{$uname.':'.$udom}},$usec);
8650: }
1.609 raeburn 8651: if (ref($statushash) eq 'HASH') {
8652: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8653: }
1.275 raeburn 8654: }
8655: }
8656: }
8657: }
1.290 albertel 8658: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8659: if ((defined($cdom)) && (defined($cnum))) {
8660: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8661: if ( defined($csettings{'internal.courseowner'}) ) {
8662: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8663: next if ($owner eq '');
8664: my ($ownername,$ownerdom);
8665: if ($owner =~ /^([^:]+):([^:]+)$/) {
8666: $ownername = $1;
8667: $ownerdom = $2;
8668: } else {
8669: $ownername = $owner;
8670: $ownerdom = $cdom;
8671: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8672: }
8673: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8674: if (defined($userdata) &&
1.609 raeburn 8675: !exists($$userdata{$owner})) {
8676: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8677: if (!grep(/^none$/,@{$seclists{$owner}})) {
8678: push(@{$seclists{$owner}},'none');
8679: }
8680: if (ref($statushash) eq 'HASH') {
8681: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8682: }
1.290 albertel 8683: }
1.279 raeburn 8684: }
8685: }
8686: }
1.419 raeburn 8687: foreach my $user (keys(%seclists)) {
8688: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8689: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8690: }
1.275 raeburn 8691: }
8692: return;
8693: }
8694:
1.288 raeburn 8695: sub get_user_info {
8696: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8697: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8698: &plainname($uname,$udom,'lastname');
1.291 albertel 8699: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8700: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8701: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8702: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8703: return;
8704: }
1.275 raeburn 8705:
1.472 raeburn 8706: ###############################################
8707:
8708: =pod
8709:
8710: =item * &get_user_quota()
8711:
1.1134 raeburn 8712: Retrieves quota assigned for storage of user files.
8713: Default is to report quota for portfolio files.
1.472 raeburn 8714:
8715: Incoming parameters:
8716: 1. user's username
8717: 2. user's domain
1.1134 raeburn 8718: 3. quota name - portfolio, author, or course
1.1136 raeburn 8719: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 8720: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 8721: course
1.472 raeburn 8722:
8723: Returns:
1.1163 raeburn 8724: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8725: 2. (Optional) Type of setting: custom or default
8726: (individually assigned or default for user's
8727: institutional status).
8728: 3. (Optional) - User's institutional status (e.g., faculty, staff
8729: or student - types as defined in localenroll::inst_usertypes
8730: for user's domain, which determines default quota for user.
8731: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8732:
8733: If a value has been stored in the user's environment,
1.536 raeburn 8734: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8735: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8736:
8737: =cut
8738:
8739: ###############################################
8740:
8741:
8742: sub get_user_quota {
1.1136 raeburn 8743: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8744: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8745: if (!defined($udom)) {
8746: $udom = $env{'user.domain'};
8747: }
8748: if (!defined($uname)) {
8749: $uname = $env{'user.name'};
8750: }
8751: if (($udom eq '' || $uname eq '') ||
8752: ($udom eq 'public') && ($uname eq 'public')) {
8753: $quota = 0;
1.536 raeburn 8754: $quotatype = 'default';
8755: $defquota = 0;
1.472 raeburn 8756: } else {
1.536 raeburn 8757: my $inststatus;
1.1134 raeburn 8758: if ($quotaname eq 'course') {
8759: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8760: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8761: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8762: } else {
8763: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8764: $quota = $cenv{'internal.uploadquota'};
8765: }
1.536 raeburn 8766: } else {
1.1134 raeburn 8767: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8768: if ($quotaname eq 'author') {
8769: $quota = $env{'environment.authorquota'};
8770: } else {
8771: $quota = $env{'environment.portfolioquota'};
8772: }
8773: $inststatus = $env{'environment.inststatus'};
8774: } else {
8775: my %userenv =
8776: &Apache::lonnet::get('environment',['portfolioquota',
8777: 'authorquota','inststatus'],$udom,$uname);
8778: my ($tmp) = keys(%userenv);
8779: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8780: if ($quotaname eq 'author') {
8781: $quota = $userenv{'authorquota'};
8782: } else {
8783: $quota = $userenv{'portfolioquota'};
8784: }
8785: $inststatus = $userenv{'inststatus'};
8786: } else {
8787: undef(%userenv);
8788: }
8789: }
8790: }
8791: if ($quota eq '' || wantarray) {
8792: if ($quotaname eq 'course') {
8793: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 8794: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8795: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 8796: $defquota = $domdefs{$crstype.'quota'};
8797: }
8798: if ($defquota eq '') {
8799: $defquota = 500;
8800: }
1.1134 raeburn 8801: } else {
8802: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8803: }
8804: if ($quota eq '') {
8805: $quota = $defquota;
8806: $quotatype = 'default';
8807: } else {
8808: $quotatype = 'custom';
8809: }
1.472 raeburn 8810: }
8811: }
1.536 raeburn 8812: if (wantarray) {
8813: return ($quota,$quotatype,$settingstatus,$defquota);
8814: } else {
8815: return $quota;
8816: }
1.472 raeburn 8817: }
8818:
8819: ###############################################
8820:
8821: =pod
8822:
8823: =item * &default_quota()
8824:
1.536 raeburn 8825: Retrieves default quota assigned for storage of user portfolio files,
8826: given an (optional) user's institutional status.
1.472 raeburn 8827:
8828: Incoming parameters:
1.1142 raeburn 8829:
1.472 raeburn 8830: 1. domain
1.536 raeburn 8831: 2. (Optional) institutional status(es). This is a : separated list of
8832: status types (e.g., faculty, staff, student etc.)
8833: which apply to the user for whom the default is being retrieved.
8834: If the institutional status string in undefined, the domain
1.1134 raeburn 8835: default quota will be returned.
8836: 3. quota name - portfolio, author, or course
8837: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8838:
8839: Returns:
1.1142 raeburn 8840:
1.1163 raeburn 8841: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8842: 2. (Optional) institutional type which determined the value of the
8843: default quota.
1.472 raeburn 8844:
8845: If a value has been stored in the domain's configuration db,
8846: it will return that, otherwise it returns 20 (for backwards
8847: compatibility with domains which have not set up a configuration
1.1163 raeburn 8848: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8849:
1.536 raeburn 8850: If the user's status includes multiple types (e.g., staff and student),
8851: the largest default quota which applies to the user determines the
8852: default quota returned.
8853:
1.472 raeburn 8854: =cut
8855:
8856: ###############################################
8857:
8858:
8859: sub default_quota {
1.1134 raeburn 8860: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8861: my ($defquota,$settingstatus);
8862: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8863: ['quotas'],$udom);
1.1134 raeburn 8864: my $key = 'defaultquota';
8865: if ($quotaname eq 'author') {
8866: $key = 'authorquota';
8867: }
1.622 raeburn 8868: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8869: if ($inststatus ne '') {
1.765 raeburn 8870: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8871: foreach my $item (@statuses) {
1.1134 raeburn 8872: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8873: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8874: if ($defquota eq '') {
1.1134 raeburn 8875: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8876: $settingstatus = $item;
1.1134 raeburn 8877: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8878: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8879: $settingstatus = $item;
8880: }
8881: }
1.1134 raeburn 8882: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8883: if ($quotahash{'quotas'}{$item} ne '') {
8884: if ($defquota eq '') {
8885: $defquota = $quotahash{'quotas'}{$item};
8886: $settingstatus = $item;
8887: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8888: $defquota = $quotahash{'quotas'}{$item};
8889: $settingstatus = $item;
8890: }
1.536 raeburn 8891: }
8892: }
8893: }
8894: }
8895: if ($defquota eq '') {
1.1134 raeburn 8896: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8897: $defquota = $quotahash{'quotas'}{$key}{'default'};
8898: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8899: $defquota = $quotahash{'quotas'}{'default'};
8900: }
1.536 raeburn 8901: $settingstatus = 'default';
1.1139 raeburn 8902: if ($defquota eq '') {
8903: if ($quotaname eq 'author') {
8904: $defquota = 500;
8905: }
8906: }
1.536 raeburn 8907: }
8908: } else {
8909: $settingstatus = 'default';
1.1134 raeburn 8910: if ($quotaname eq 'author') {
8911: $defquota = 500;
8912: } else {
8913: $defquota = 20;
8914: }
1.536 raeburn 8915: }
8916: if (wantarray) {
8917: return ($defquota,$settingstatus);
1.472 raeburn 8918: } else {
1.536 raeburn 8919: return $defquota;
1.472 raeburn 8920: }
8921: }
8922:
1.1135 raeburn 8923: ###############################################
8924:
8925: =pod
8926:
1.1136 raeburn 8927: =item * &excess_filesize_warning()
1.1135 raeburn 8928:
8929: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8930: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 8931: space to be exceeded.
1.1136 raeburn 8932:
8933: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8934: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8935:
1.1165 raeburn 8936: Inputs: 7
1.1136 raeburn 8937: 1. username or coursenum
1.1135 raeburn 8938: 2. domain
1.1136 raeburn 8939: 3. context ('author' or 'course')
1.1135 raeburn 8940: 4. filename of file for which action is being requested
8941: 5. filesize (kB) of file
8942: 6. action being taken: copy or upload.
1.1165 raeburn 8943: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 8944:
8945: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 8946: otherwise return null.
8947:
8948: =back
1.1135 raeburn 8949:
8950: =cut
8951:
1.1136 raeburn 8952: sub excess_filesize_warning {
1.1165 raeburn 8953: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 8954: my $current_disk_usage = 0;
1.1165 raeburn 8955: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 8956: if ($context eq 'author') {
8957: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8958: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8959: } else {
8960: foreach my $subdir ('docs','supplemental') {
8961: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8962: }
8963: }
1.1135 raeburn 8964: $disk_quota = int($disk_quota * 1000);
8965: if (($current_disk_usage + $filesize) > $disk_quota) {
8966: return '<p><span class="LC_warning">'.
8967: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8968: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8969: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8970: $disk_quota,$current_disk_usage).
8971: '</p>';
8972: }
8973: return;
8974: }
8975:
8976: ###############################################
8977:
8978:
1.1136 raeburn 8979:
8980:
1.384 raeburn 8981: sub get_secgrprole_info {
8982: my ($cdom,$cnum,$needroles,$type) = @_;
8983: my %sections_count = &get_sections($cdom,$cnum);
8984: my @sections = (sort {$a <=> $b} keys(%sections_count));
8985: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8986: my @groups = sort(keys(%curr_groups));
8987: my $allroles = [];
8988: my $rolehash;
8989: my $accesshash = {
8990: active => 'Currently has access',
8991: future => 'Will have future access',
8992: previous => 'Previously had access',
8993: };
8994: if ($needroles) {
8995: $rolehash = {'all' => 'all'};
1.385 albertel 8996: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8997: if (&Apache::lonnet::error(%user_roles)) {
8998: undef(%user_roles);
8999: }
9000: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9001: my ($role)=split(/\:/,$item,2);
9002: if ($role eq 'cr') { next; }
9003: if ($role =~ /^cr/) {
9004: $$rolehash{$role} = (split('/',$role))[3];
9005: } else {
9006: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9007: }
9008: }
9009: foreach my $key (sort(keys(%{$rolehash}))) {
9010: push(@{$allroles},$key);
9011: }
9012: push (@{$allroles},'st');
9013: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9014: }
9015: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9016: }
9017:
1.555 raeburn 9018: sub user_picker {
1.994 raeburn 9019: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9020: my $currdom = $dom;
9021: my %curr_selected = (
9022: srchin => 'dom',
1.580 raeburn 9023: srchby => 'lastname',
1.555 raeburn 9024: );
9025: my $srchterm;
1.625 raeburn 9026: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9027: if ($srch->{'srchby'} ne '') {
9028: $curr_selected{'srchby'} = $srch->{'srchby'};
9029: }
9030: if ($srch->{'srchin'} ne '') {
9031: $curr_selected{'srchin'} = $srch->{'srchin'};
9032: }
9033: if ($srch->{'srchtype'} ne '') {
9034: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9035: }
9036: if ($srch->{'srchdomain'} ne '') {
9037: $currdom = $srch->{'srchdomain'};
9038: }
9039: $srchterm = $srch->{'srchterm'};
9040: }
9041: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9042: 'usr' => 'Search criteria',
1.563 raeburn 9043: 'doma' => 'Domain/institution to search',
1.558 albertel 9044: 'uname' => 'username',
9045: 'lastname' => 'last name',
1.555 raeburn 9046: 'lastfirst' => 'last name, first name',
1.558 albertel 9047: 'crs' => 'in this course',
1.576 raeburn 9048: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9049: 'alc' => 'all LON-CAPA',
1.573 raeburn 9050: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9051: 'exact' => 'is',
9052: 'contains' => 'contains',
1.569 raeburn 9053: 'begins' => 'begins with',
1.571 raeburn 9054: 'youm' => "You must include some text to search for.",
9055: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9056: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9057: 'yomc' => "You must choose a domain when using an institutional directory search.",
9058: 'ymcd' => "You must choose a domain when using a domain search.",
9059: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9060: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9061: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9062: );
1.563 raeburn 9063: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9064: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9065:
9066: my @srchins = ('crs','dom','alc','instd');
9067:
9068: foreach my $option (@srchins) {
9069: # FIXME 'alc' option unavailable until
9070: # loncreateuser::print_user_query_page()
9071: # has been completed.
9072: next if ($option eq 'alc');
1.880 raeburn 9073: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9074: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9075: if ($curr_selected{'srchin'} eq $option) {
9076: $srchinsel .= '
9077: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9078: } else {
9079: $srchinsel .= '
9080: <option value="'.$option.'">'.$lt{$option}.'</option>';
9081: }
1.555 raeburn 9082: }
1.563 raeburn 9083: $srchinsel .= "\n </select>\n";
1.555 raeburn 9084:
9085: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9086: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9087: if ($curr_selected{'srchby'} eq $option) {
9088: $srchbysel .= '
9089: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9090: } else {
9091: $srchbysel .= '
9092: <option value="'.$option.'">'.$lt{$option}.'</option>';
9093: }
9094: }
9095: $srchbysel .= "\n </select>\n";
9096:
9097: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9098: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9099: if ($curr_selected{'srchtype'} eq $option) {
9100: $srchtypesel .= '
9101: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9102: } else {
9103: $srchtypesel .= '
9104: <option value="'.$option.'">'.$lt{$option}.'</option>';
9105: }
9106: }
9107: $srchtypesel .= "\n </select>\n";
9108:
1.558 albertel 9109: my ($newuserscript,$new_user_create);
1.994 raeburn 9110: my $context_dom = $env{'request.role.domain'};
9111: if ($context eq 'requestcrs') {
9112: if ($env{'form.coursedom'} ne '') {
9113: $context_dom = $env{'form.coursedom'};
9114: }
9115: }
1.556 raeburn 9116: if ($forcenewuser) {
1.576 raeburn 9117: if (ref($srch) eq 'HASH') {
1.994 raeburn 9118: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9119: if ($cancreate) {
9120: $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>';
9121: } else {
1.799 bisitz 9122: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9123: my %usertypetext = (
9124: official => 'institutional',
9125: unofficial => 'non-institutional',
9126: );
1.799 bisitz 9127: $new_user_create = '<p class="LC_warning">'
9128: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9129: .' '
9130: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9131: ,'<a href="'.$helplink.'">','</a>')
9132: .'</p><br />';
1.627 raeburn 9133: }
1.576 raeburn 9134: }
9135: }
9136:
1.556 raeburn 9137: $newuserscript = <<"ENDSCRIPT";
9138:
1.570 raeburn 9139: function setSearch(createnew,callingForm) {
1.556 raeburn 9140: if (createnew == 1) {
1.570 raeburn 9141: for (var i=0; i<callingForm.srchby.length; i++) {
9142: if (callingForm.srchby.options[i].value == 'uname') {
9143: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9144: }
9145: }
1.570 raeburn 9146: for (var i=0; i<callingForm.srchin.length; i++) {
9147: if ( callingForm.srchin.options[i].value == 'dom') {
9148: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9149: }
9150: }
1.570 raeburn 9151: for (var i=0; i<callingForm.srchtype.length; i++) {
9152: if (callingForm.srchtype.options[i].value == 'exact') {
9153: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9154: }
9155: }
1.570 raeburn 9156: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9157: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9158: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9159: }
9160: }
9161: }
9162: }
9163: ENDSCRIPT
1.558 albertel 9164:
1.556 raeburn 9165: }
9166:
1.555 raeburn 9167: my $output = <<"END_BLOCK";
1.556 raeburn 9168: <script type="text/javascript">
1.824 bisitz 9169: // <![CDATA[
1.570 raeburn 9170: function validateEntry(callingForm) {
1.558 albertel 9171:
1.556 raeburn 9172: var checkok = 1;
1.558 albertel 9173: var srchin;
1.570 raeburn 9174: for (var i=0; i<callingForm.srchin.length; i++) {
9175: if ( callingForm.srchin[i].checked ) {
9176: srchin = callingForm.srchin[i].value;
1.558 albertel 9177: }
9178: }
9179:
1.570 raeburn 9180: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9181: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9182: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9183: var srchterm = callingForm.srchterm.value;
9184: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9185: var msg = "";
9186:
9187: if (srchterm == "") {
9188: checkok = 0;
1.571 raeburn 9189: msg += "$lt{'youm'}\\n";
1.556 raeburn 9190: }
9191:
1.569 raeburn 9192: if (srchtype== 'begins') {
9193: if (srchterm.length < 2) {
9194: checkok = 0;
1.571 raeburn 9195: msg += "$lt{'thte'}\\n";
1.569 raeburn 9196: }
9197: }
9198:
1.556 raeburn 9199: if (srchtype== 'contains') {
9200: if (srchterm.length < 3) {
9201: checkok = 0;
1.571 raeburn 9202: msg += "$lt{'thet'}\\n";
1.556 raeburn 9203: }
9204: }
9205: if (srchin == 'instd') {
9206: if (srchdomain == '') {
9207: checkok = 0;
1.571 raeburn 9208: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9209: }
9210: }
9211: if (srchin == 'dom') {
9212: if (srchdomain == '') {
9213: checkok = 0;
1.571 raeburn 9214: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9215: }
9216: }
9217: if (srchby == 'lastfirst') {
9218: if (srchterm.indexOf(",") == -1) {
9219: checkok = 0;
1.571 raeburn 9220: msg += "$lt{'whus'}\\n";
1.556 raeburn 9221: }
9222: if (srchterm.indexOf(",") == srchterm.length -1) {
9223: checkok = 0;
1.571 raeburn 9224: msg += "$lt{'whse'}\\n";
1.556 raeburn 9225: }
9226: }
9227: if (checkok == 0) {
1.571 raeburn 9228: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9229: return;
9230: }
9231: if (checkok == 1) {
1.570 raeburn 9232: callingForm.submit();
1.556 raeburn 9233: }
9234: }
9235:
9236: $newuserscript
9237:
1.824 bisitz 9238: // ]]>
1.556 raeburn 9239: </script>
1.558 albertel 9240:
9241: $new_user_create
9242:
1.555 raeburn 9243: END_BLOCK
1.558 albertel 9244:
1.876 raeburn 9245: $output .= &Apache::lonhtmlcommon::start_pick_box().
9246: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9247: $domform.
9248: &Apache::lonhtmlcommon::row_closure().
9249: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9250: $srchbysel.
9251: $srchtypesel.
9252: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9253: $srchinsel.
9254: &Apache::lonhtmlcommon::row_closure(1).
9255: &Apache::lonhtmlcommon::end_pick_box().
9256: '<br />';
1.555 raeburn 9257: return $output;
9258: }
9259:
1.612 raeburn 9260: sub user_rule_check {
1.615 raeburn 9261: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9262: my $response;
9263: if (ref($usershash) eq 'HASH') {
9264: foreach my $user (keys(%{$usershash})) {
9265: my ($uname,$udom) = split(/:/,$user);
9266: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9267: my ($id,$newuser);
1.612 raeburn 9268: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9269: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9270: $id = $usershash->{$user}->{'id'};
9271: }
9272: my $inst_response;
9273: if (ref($checks) eq 'HASH') {
9274: if (defined($checks->{'username'})) {
1.615 raeburn 9275: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9276: &Apache::lonnet::get_instuser($udom,$uname);
9277: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9278: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9279: &Apache::lonnet::get_instuser($udom,undef,$id);
9280: }
1.615 raeburn 9281: } else {
9282: ($inst_response,%{$inst_results->{$user}}) =
9283: &Apache::lonnet::get_instuser($udom,$uname);
9284: return;
1.612 raeburn 9285: }
1.615 raeburn 9286: if (!$got_rules->{$udom}) {
1.612 raeburn 9287: my %domconfig = &Apache::lonnet::get_dom('configuration',
9288: ['usercreation'],$udom);
9289: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9290: foreach my $item ('username','id') {
1.612 raeburn 9291: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9292: $$curr_rules{$udom}{$item} =
9293: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9294: }
9295: }
9296: }
1.615 raeburn 9297: $got_rules->{$udom} = 1;
1.585 raeburn 9298: }
1.612 raeburn 9299: foreach my $item (keys(%{$checks})) {
9300: if (ref($$curr_rules{$udom}) eq 'HASH') {
9301: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9302: if (@{$$curr_rules{$udom}{$item}} > 0) {
9303: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9304: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9305: if ($rule_check{$rule}) {
9306: $$rulematch{$user}{$item} = $rule;
9307: if ($inst_response eq 'ok') {
1.615 raeburn 9308: if (ref($inst_results) eq 'HASH') {
9309: if (ref($inst_results->{$user}) eq 'HASH') {
9310: if (keys(%{$inst_results->{$user}}) == 0) {
9311: $$alerts{$item}{$udom}{$uname} = 1;
9312: }
1.612 raeburn 9313: }
9314: }
1.615 raeburn 9315: }
9316: last;
1.585 raeburn 9317: }
9318: }
9319: }
9320: }
9321: }
9322: }
9323: }
9324: }
1.612 raeburn 9325: return;
9326: }
9327:
9328: sub user_rule_formats {
9329: my ($domain,$domdesc,$curr_rules,$check) = @_;
9330: my %text = (
9331: 'username' => 'Usernames',
9332: 'id' => 'IDs',
9333: );
9334: my $output;
9335: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9336: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9337: if (@{$ruleorder} > 0) {
1.1102 raeburn 9338: $output = '<br />'.
9339: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9340: '<span class="LC_cusr_emph">','</span>',$domdesc).
9341: ' <ul>';
1.612 raeburn 9342: foreach my $rule (@{$ruleorder}) {
9343: if (ref($curr_rules) eq 'ARRAY') {
9344: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9345: if (ref($rules->{$rule}) eq 'HASH') {
9346: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9347: $rules->{$rule}{'desc'}.'</li>';
9348: }
9349: }
9350: }
9351: }
9352: $output .= '</ul>';
9353: }
9354: }
9355: return $output;
9356: }
9357:
9358: sub instrule_disallow_msg {
1.615 raeburn 9359: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9360: my $response;
9361: my %text = (
9362: item => 'username',
9363: items => 'usernames',
9364: match => 'matches',
9365: do => 'does',
9366: action => 'a username',
9367: one => 'one',
9368: );
9369: if ($count > 1) {
9370: $text{'item'} = 'usernames';
9371: $text{'match'} ='match';
9372: $text{'do'} = 'do';
9373: $text{'action'} = 'usernames',
9374: $text{'one'} = 'ones';
9375: }
9376: if ($checkitem eq 'id') {
9377: $text{'items'} = 'IDs';
9378: $text{'item'} = 'ID';
9379: $text{'action'} = 'an ID';
1.615 raeburn 9380: if ($count > 1) {
9381: $text{'item'} = 'IDs';
9382: $text{'action'} = 'IDs';
9383: }
1.612 raeburn 9384: }
1.674 bisitz 9385: $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 9386: if ($mode eq 'upload') {
9387: if ($checkitem eq 'username') {
9388: $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'}.");
9389: } elsif ($checkitem eq 'id') {
1.674 bisitz 9390: $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 9391: }
1.669 raeburn 9392: } elsif ($mode eq 'selfcreate') {
9393: if ($checkitem eq 'id') {
9394: $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.");
9395: }
1.615 raeburn 9396: } else {
9397: if ($checkitem eq 'username') {
9398: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9399: } elsif ($checkitem eq 'id') {
9400: $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.");
9401: }
1.612 raeburn 9402: }
9403: return $response;
1.585 raeburn 9404: }
9405:
1.624 raeburn 9406: sub personal_data_fieldtitles {
9407: my %fieldtitles = &Apache::lonlocal::texthash (
9408: id => 'Student/Employee ID',
9409: permanentemail => 'E-mail address',
9410: lastname => 'Last Name',
9411: firstname => 'First Name',
9412: middlename => 'Middle Name',
9413: generation => 'Generation',
9414: gen => 'Generation',
1.765 raeburn 9415: inststatus => 'Affiliation',
1.624 raeburn 9416: );
9417: return %fieldtitles;
9418: }
9419:
1.642 raeburn 9420: sub sorted_inst_types {
9421: my ($dom) = @_;
9422: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9423: my $othertitle = &mt('All users');
9424: if ($env{'request.course.id'}) {
1.668 raeburn 9425: $othertitle = &mt('Any users');
1.642 raeburn 9426: }
9427: my @types;
9428: if (ref($order) eq 'ARRAY') {
9429: @types = @{$order};
9430: }
9431: if (@types == 0) {
9432: if (ref($usertypes) eq 'HASH') {
9433: @types = sort(keys(%{$usertypes}));
9434: }
9435: }
9436: if (keys(%{$usertypes}) > 0) {
9437: $othertitle = &mt('Other users');
9438: }
9439: return ($othertitle,$usertypes,\@types);
9440: }
9441:
1.645 raeburn 9442: sub get_institutional_codes {
9443: my ($settings,$allcourses,$LC_code) = @_;
9444: # Get complete list of course sections to update
9445: my @currsections = ();
9446: my @currxlists = ();
9447: my $coursecode = $$settings{'internal.coursecode'};
9448:
9449: if ($$settings{'internal.sectionnums'} ne '') {
9450: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9451: }
9452:
9453: if ($$settings{'internal.crosslistings'} ne '') {
9454: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9455: }
9456:
9457: if (@currxlists > 0) {
9458: foreach (@currxlists) {
9459: if (m/^([^:]+):(\w*)$/) {
9460: unless (grep/^$1$/,@{$allcourses}) {
9461: push @{$allcourses},$1;
9462: $$LC_code{$1} = $2;
9463: }
9464: }
9465: }
9466: }
9467:
9468: if (@currsections > 0) {
9469: foreach (@currsections) {
9470: if (m/^(\w+):(\w*)$/) {
9471: my $sec = $coursecode.$1;
9472: my $lc_sec = $2;
9473: unless (grep/^$sec$/,@{$allcourses}) {
9474: push @{$allcourses},$sec;
9475: $$LC_code{$sec} = $lc_sec;
9476: }
9477: }
9478: }
9479: }
9480: return;
9481: }
9482:
1.971 raeburn 9483: sub get_standard_codeitems {
9484: return ('Year','Semester','Department','Number','Section');
9485: }
9486:
1.112 bowersj2 9487: =pod
9488:
1.780 raeburn 9489: =head1 Slot Helpers
9490:
9491: =over 4
9492:
9493: =item * sorted_slots()
9494:
1.1040 raeburn 9495: Sorts an array of slot names in order of an optional sort key,
9496: default sort is by slot start time (earliest first).
1.780 raeburn 9497:
9498: Inputs:
9499:
9500: =over 4
9501:
9502: slotsarr - Reference to array of unsorted slot names.
9503:
9504: slots - Reference to hash of hash, where outer hash keys are slot names.
9505:
1.1040 raeburn 9506: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9507:
1.549 albertel 9508: =back
9509:
1.780 raeburn 9510: Returns:
9511:
9512: =over 4
9513:
1.1040 raeburn 9514: sorted - An array of slot names sorted by a specified sort key
9515: (default sort key is start time of the slot).
1.780 raeburn 9516:
9517: =back
9518:
9519: =cut
9520:
9521:
9522: sub sorted_slots {
1.1040 raeburn 9523: my ($slotsarr,$slots,$sortkey) = @_;
9524: if ($sortkey eq '') {
9525: $sortkey = 'starttime';
9526: }
1.780 raeburn 9527: my @sorted;
9528: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9529: @sorted =
9530: sort {
9531: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9532: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9533: }
9534: if (ref($slots->{$a})) { return -1;}
9535: if (ref($slots->{$b})) { return 1;}
9536: return 0;
9537: } @{$slotsarr};
9538: }
9539: return @sorted;
9540: }
9541:
1.1040 raeburn 9542: =pod
9543:
9544: =item * get_future_slots()
9545:
9546: Inputs:
9547:
9548: =over 4
9549:
9550: cnum - course number
9551:
9552: cdom - course domain
9553:
9554: now - current UNIX time
9555:
9556: symb - optional symb
9557:
9558: =back
9559:
9560: Returns:
9561:
9562: =over 4
9563:
9564: sorted_reservable - ref to array of student_schedulable slots currently
9565: reservable, ordered by end date of reservation period.
9566:
9567: reservable_now - ref to hash of student_schedulable slots currently
9568: reservable.
9569:
9570: Keys in inner hash are:
9571: (a) symb: either blank or symb to which slot use is restricted.
9572: (b) endreserve: end date of reservation period.
9573:
9574: sorted_future - ref to array of student_schedulable slots reservable in
9575: the future, ordered by start date of reservation period.
9576:
9577: future_reservable - ref to hash of student_schedulable slots reservable
9578: in the future.
9579:
9580: Keys in inner hash are:
9581: (a) symb: either blank or symb to which slot use is restricted.
9582: (b) startreserve: start date of reservation period.
9583:
9584: =back
9585:
9586: =cut
9587:
9588: sub get_future_slots {
9589: my ($cnum,$cdom,$now,$symb) = @_;
9590: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9591: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9592: foreach my $slot (keys(%slots)) {
9593: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9594: if ($symb) {
9595: next if (($slots{$slot}->{'symb'} ne '') &&
9596: ($slots{$slot}->{'symb'} ne $symb));
9597: }
9598: if (($slots{$slot}->{'starttime'} > $now) &&
9599: ($slots{$slot}->{'endtime'} > $now)) {
9600: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9601: my $userallowed = 0;
9602: if ($slots{$slot}->{'allowedsections'}) {
9603: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9604: if (!defined($env{'request.role.sec'})
9605: && grep(/^No section assigned$/,@allowed_sec)) {
9606: $userallowed=1;
9607: } else {
9608: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9609: $userallowed=1;
9610: }
9611: }
9612: unless ($userallowed) {
9613: if (defined($env{'request.course.groups'})) {
9614: my @groups = split(/:/,$env{'request.course.groups'});
9615: foreach my $group (@groups) {
9616: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9617: $userallowed=1;
9618: last;
9619: }
9620: }
9621: }
9622: }
9623: }
9624: if ($slots{$slot}->{'allowedusers'}) {
9625: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9626: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9627: if (grep(/^\Q$user\E$/,@allowed_users)) {
9628: $userallowed = 1;
9629: }
9630: }
9631: next unless($userallowed);
9632: }
9633: my $startreserve = $slots{$slot}->{'startreserve'};
9634: my $endreserve = $slots{$slot}->{'endreserve'};
9635: my $symb = $slots{$slot}->{'symb'};
9636: if (($startreserve < $now) &&
9637: (!$endreserve || $endreserve > $now)) {
9638: my $lastres = $endreserve;
9639: if (!$lastres) {
9640: $lastres = $slots{$slot}->{'starttime'};
9641: }
9642: $reservable_now{$slot} = {
9643: symb => $symb,
9644: endreserve => $lastres
9645: };
9646: } elsif (($startreserve > $now) &&
9647: (!$endreserve || $endreserve > $startreserve)) {
9648: $future_reservable{$slot} = {
9649: symb => $symb,
9650: startreserve => $startreserve
9651: };
9652: }
9653: }
9654: }
9655: my @unsorted_reservable = keys(%reservable_now);
9656: if (@unsorted_reservable > 0) {
9657: @sorted_reservable =
9658: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9659: }
9660: my @unsorted_future = keys(%future_reservable);
9661: if (@unsorted_future > 0) {
9662: @sorted_future =
9663: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9664: }
9665: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9666: }
1.780 raeburn 9667:
9668: =pod
9669:
1.1057 foxr 9670: =back
9671:
1.549 albertel 9672: =head1 HTTP Helpers
9673:
9674: =over 4
9675:
1.648 raeburn 9676: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9677:
1.258 albertel 9678: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9679: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9680: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9681:
9682: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9683: $possible_names is an ref to an array of form element names. As an example:
9684: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9685: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9686:
9687: =cut
1.1 albertel 9688:
1.6 albertel 9689: sub get_unprocessed_cgi {
1.25 albertel 9690: my ($query,$possible_names)= @_;
1.26 matthew 9691: # $Apache::lonxml::debug=1;
1.356 albertel 9692: foreach my $pair (split(/&/,$query)) {
9693: my ($name, $value) = split(/=/,$pair);
1.369 www 9694: $name = &unescape($name);
1.25 albertel 9695: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9696: $value =~ tr/+/ /;
9697: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9698: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9699: }
1.16 harris41 9700: }
1.6 albertel 9701: }
9702:
1.112 bowersj2 9703: =pod
9704:
1.648 raeburn 9705: =item * &cacheheader()
1.112 bowersj2 9706:
9707: returns cache-controlling header code
9708:
9709: =cut
9710:
1.7 albertel 9711: sub cacheheader {
1.258 albertel 9712: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9713: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9714: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9715: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9716: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9717: return $output;
1.7 albertel 9718: }
9719:
1.112 bowersj2 9720: =pod
9721:
1.648 raeburn 9722: =item * &no_cache($r)
1.112 bowersj2 9723:
9724: specifies header code to not have cache
9725:
9726: =cut
9727:
1.9 albertel 9728: sub no_cache {
1.216 albertel 9729: my ($r) = @_;
9730: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9731: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9732: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9733: $r->no_cache(1);
9734: $r->header_out("Expires" => $date);
9735: $r->header_out("Pragma" => "no-cache");
1.123 www 9736: }
9737:
9738: sub content_type {
1.181 albertel 9739: my ($r,$type,$charset) = @_;
1.299 foxr 9740: if ($r) {
9741: # Note that printout.pl calls this with undef for $r.
9742: &no_cache($r);
9743: }
1.258 albertel 9744: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9745: unless ($charset) {
9746: $charset=&Apache::lonlocal::current_encoding;
9747: }
9748: if ($charset) { $type.='; charset='.$charset; }
9749: if ($r) {
9750: $r->content_type($type);
9751: } else {
9752: print("Content-type: $type\n\n");
9753: }
1.9 albertel 9754: }
1.25 albertel 9755:
1.112 bowersj2 9756: =pod
9757:
1.648 raeburn 9758: =item * &add_to_env($name,$value)
1.112 bowersj2 9759:
1.258 albertel 9760: adds $name to the %env hash with value
1.112 bowersj2 9761: $value, if $name already exists, the entry is converted to an array
9762: reference and $value is added to the array.
9763:
9764: =cut
9765:
1.25 albertel 9766: sub add_to_env {
9767: my ($name,$value)=@_;
1.258 albertel 9768: if (defined($env{$name})) {
9769: if (ref($env{$name})) {
1.25 albertel 9770: #already have multiple values
1.258 albertel 9771: push(@{ $env{$name} },$value);
1.25 albertel 9772: } else {
9773: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9774: my $first=$env{$name};
9775: undef($env{$name});
9776: push(@{ $env{$name} },$first,$value);
1.25 albertel 9777: }
9778: } else {
1.258 albertel 9779: $env{$name}=$value;
1.25 albertel 9780: }
1.31 albertel 9781: }
1.149 albertel 9782:
9783: =pod
9784:
1.648 raeburn 9785: =item * &get_env_multiple($name)
1.149 albertel 9786:
1.258 albertel 9787: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9788: values may be defined and end up as an array ref.
9789:
9790: returns an array of values
9791:
9792: =cut
9793:
9794: sub get_env_multiple {
9795: my ($name) = @_;
9796: my @values;
1.258 albertel 9797: if (defined($env{$name})) {
1.149 albertel 9798: # exists is it an array
1.258 albertel 9799: if (ref($env{$name})) {
9800: @values=@{ $env{$name} };
1.149 albertel 9801: } else {
1.258 albertel 9802: $values[0]=$env{$name};
1.149 albertel 9803: }
9804: }
9805: return(@values);
9806: }
9807:
1.660 raeburn 9808: sub ask_for_embedded_content {
9809: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9810: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9811: %currsubfile,%unused,$rem);
1.1071 raeburn 9812: my $counter = 0;
9813: my $numnew = 0;
1.987 raeburn 9814: my $numremref = 0;
9815: my $numinvalid = 0;
9816: my $numpathchg = 0;
9817: my $numexisting = 0;
1.1071 raeburn 9818: my $numunused = 0;
9819: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 9820: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9821: my $heading = &mt('Upload embedded files');
9822: my $buttontext = &mt('Upload');
9823:
1.1085 raeburn 9824: if ($env{'request.course.id'}) {
1.1123 raeburn 9825: if ($actionurl eq '/adm/dependencies') {
9826: $navmap = Apache::lonnavmaps::navmap->new();
9827: }
9828: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9829: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9830: }
1.1123 raeburn 9831: if (($actionurl eq '/adm/portfolio') ||
9832: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9833: my $current_path='/';
9834: if ($env{'form.currentpath'}) {
9835: $current_path = $env{'form.currentpath'};
9836: }
9837: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9838: $udom = $cdom;
9839: $uname = $cnum;
1.984 raeburn 9840: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9841: } else {
9842: $udom = $env{'user.domain'};
9843: $uname = $env{'user.name'};
9844: $url = '/userfiles/portfolio';
9845: }
1.987 raeburn 9846: $toplevel = $url.'/';
1.984 raeburn 9847: $url .= $current_path;
9848: $getpropath = 1;
1.987 raeburn 9849: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9850: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9851: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9852: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9853: $toplevel = $url;
1.984 raeburn 9854: if ($rest ne '') {
1.987 raeburn 9855: $url .= $rest;
9856: }
9857: } elsif ($actionurl eq '/adm/coursedocs') {
9858: if (ref($args) eq 'HASH') {
1.1071 raeburn 9859: $url = $args->{'docs_url'};
9860: $toplevel = $url;
1.1084 raeburn 9861: if ($args->{'context'} eq 'paste') {
9862: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9863: ($path) =
9864: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9865: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9866: $fileloc =~ s{^/}{};
9867: }
1.1071 raeburn 9868: }
1.1084 raeburn 9869: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9870: if ($env{'request.course.id'} ne '') {
9871: if (ref($args) eq 'HASH') {
9872: $url = $args->{'docs_url'};
9873: $title = $args->{'docs_title'};
1.1126 raeburn 9874: $toplevel = $url;
9875: unless ($toplevel =~ m{^/}) {
9876: $toplevel = "/$url";
9877: }
1.1085 raeburn 9878: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9879: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9880: $path = $1;
9881: } else {
9882: ($path) =
9883: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9884: }
1.1071 raeburn 9885: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9886: $fileloc =~ s{^/}{};
9887: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9888: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9889: }
1.987 raeburn 9890: }
1.1123 raeburn 9891: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9892: $udom = $cdom;
9893: $uname = $cnum;
9894: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9895: $toplevel = $url;
9896: $path = $url;
9897: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9898: $fileloc =~ s{^/}{};
1.987 raeburn 9899: }
1.1126 raeburn 9900: foreach my $file (keys(%{$allfiles})) {
9901: my $embed_file;
9902: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9903: $embed_file = $1;
9904: } else {
9905: $embed_file = $file;
9906: }
1.1158 raeburn 9907: my ($absolutepath,$cleaned_file);
9908: if ($embed_file =~ m{^\w+://}) {
9909: $cleaned_file = $embed_file;
1.1147 raeburn 9910: $newfiles{$cleaned_file} = 1;
9911: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9912: } else {
1.1158 raeburn 9913: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9914: if ($embed_file =~ m{^/}) {
9915: $absolutepath = $embed_file;
9916: }
1.1147 raeburn 9917: if ($cleaned_file =~ m{/}) {
9918: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9919: $path = &check_for_traversal($path,$url,$toplevel);
9920: my $item = $fname;
9921: if ($path ne '') {
9922: $item = $path.'/'.$fname;
9923: $subdependencies{$path}{$fname} = 1;
9924: } else {
9925: $dependencies{$item} = 1;
9926: }
9927: if ($absolutepath) {
9928: $mapping{$item} = $absolutepath;
9929: } else {
9930: $mapping{$item} = $embed_file;
9931: }
9932: } else {
9933: $dependencies{$embed_file} = 1;
9934: if ($absolutepath) {
1.1147 raeburn 9935: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9936: } else {
1.1147 raeburn 9937: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9938: }
9939: }
1.984 raeburn 9940: }
9941: }
1.1071 raeburn 9942: my $dirptr = 16384;
1.984 raeburn 9943: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9944: $currsubfile{$path} = {};
1.1123 raeburn 9945: if (($actionurl eq '/adm/portfolio') ||
9946: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9947: my ($sublistref,$listerror) =
9948: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9949: if (ref($sublistref) eq 'ARRAY') {
9950: foreach my $line (@{$sublistref}) {
9951: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9952: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9953: }
1.984 raeburn 9954: }
1.987 raeburn 9955: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9956: if (opendir(my $dir,$url.'/'.$path)) {
9957: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9958: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9959: }
1.1084 raeburn 9960: } elsif (($actionurl eq '/adm/dependencies') ||
9961: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9962: ($args->{'context'} eq 'paste')) ||
9963: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9964: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9965: my $dir;
9966: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9967: $dir = $fileloc;
9968: } else {
9969: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9970: }
1.1071 raeburn 9971: if ($dir ne '') {
9972: my ($sublistref,$listerror) =
9973: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9974: if (ref($sublistref) eq 'ARRAY') {
9975: foreach my $line (@{$sublistref}) {
9976: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9977: undef,$mtime)=split(/\&/,$line,12);
9978: unless (($testdir&$dirptr) ||
9979: ($file_name =~ /^\.\.?$/)) {
9980: $currsubfile{$path}{$file_name} = [$size,$mtime];
9981: }
9982: }
9983: }
9984: }
1.984 raeburn 9985: }
9986: }
9987: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9988: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9989: my $item = $path.'/'.$file;
9990: unless ($mapping{$item} eq $item) {
9991: $pathchanges{$item} = 1;
9992: }
9993: $existing{$item} = 1;
9994: $numexisting ++;
9995: } else {
9996: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9997: }
9998: }
1.1071 raeburn 9999: if ($actionurl eq '/adm/dependencies') {
10000: foreach my $path (keys(%currsubfile)) {
10001: if (ref($currsubfile{$path}) eq 'HASH') {
10002: foreach my $file (keys(%{$currsubfile{$path}})) {
10003: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10004: next if (($rem ne '') &&
10005: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10006: (ref($navmap) &&
10007: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10008: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10009: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10010: $unused{$path.'/'.$file} = 1;
10011: }
10012: }
10013: }
10014: }
10015: }
1.984 raeburn 10016: }
1.987 raeburn 10017: my %currfile;
1.1123 raeburn 10018: if (($actionurl eq '/adm/portfolio') ||
10019: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10020: my ($dirlistref,$listerror) =
10021: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10022: if (ref($dirlistref) eq 'ARRAY') {
10023: foreach my $line (@{$dirlistref}) {
10024: my ($file_name,$rest) = split(/\&/,$line,2);
10025: $currfile{$file_name} = 1;
10026: }
1.984 raeburn 10027: }
1.987 raeburn 10028: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10029: if (opendir(my $dir,$url)) {
1.987 raeburn 10030: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10031: map {$currfile{$_} = 1;} @dir_list;
10032: }
1.1084 raeburn 10033: } elsif (($actionurl eq '/adm/dependencies') ||
10034: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10035: ($args->{'context'} eq 'paste')) ||
10036: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10037: if ($env{'request.course.id'} ne '') {
10038: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10039: if ($dir ne '') {
10040: my ($dirlistref,$listerror) =
10041: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10042: if (ref($dirlistref) eq 'ARRAY') {
10043: foreach my $line (@{$dirlistref}) {
10044: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10045: $size,undef,$mtime)=split(/\&/,$line,12);
10046: unless (($testdir&$dirptr) ||
10047: ($file_name =~ /^\.\.?$/)) {
10048: $currfile{$file_name} = [$size,$mtime];
10049: }
10050: }
10051: }
10052: }
10053: }
1.984 raeburn 10054: }
10055: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10056: if (exists($currfile{$file})) {
1.987 raeburn 10057: unless ($mapping{$file} eq $file) {
10058: $pathchanges{$file} = 1;
10059: }
10060: $existing{$file} = 1;
10061: $numexisting ++;
10062: } else {
1.984 raeburn 10063: $newfiles{$file} = 1;
10064: }
10065: }
1.1071 raeburn 10066: foreach my $file (keys(%currfile)) {
10067: unless (($file eq $filename) ||
10068: ($file eq $filename.'.bak') ||
10069: ($dependencies{$file})) {
1.1085 raeburn 10070: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10071: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10072: next if (($rem ne '') &&
10073: (($env{"httpref.$rem".$file} ne '') ||
10074: (ref($navmap) &&
10075: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10076: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10077: ($navmap->getResourceByUrl($rem.$1)))))));
10078: }
1.1085 raeburn 10079: }
1.1071 raeburn 10080: $unused{$file} = 1;
10081: }
10082: }
1.1084 raeburn 10083: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10084: ($args->{'context'} eq 'paste')) {
10085: $counter = scalar(keys(%existing));
10086: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10087: return ($output,$counter,$numpathchg,\%existing);
10088: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10089: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10090: $counter = scalar(keys(%existing));
10091: $numpathchg = scalar(keys(%pathchanges));
10092: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10093: }
1.984 raeburn 10094: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10095: if ($actionurl eq '/adm/dependencies') {
10096: next if ($embed_file =~ m{^\w+://});
10097: }
1.660 raeburn 10098: $upload_output .= &start_data_table_row().
1.1123 raeburn 10099: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10100: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10101: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10102: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10103: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10104: }
1.1123 raeburn 10105: $upload_output .= '</td>';
1.1071 raeburn 10106: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10107: $upload_output.='<td align="right">'.
10108: '<span class="LC_info LC_fontsize_medium">'.
10109: &mt("URL points to web address").'</span>';
1.987 raeburn 10110: $numremref++;
1.660 raeburn 10111: } elsif ($args->{'error_on_invalid_names'}
10112: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10113: $upload_output.='<td align="right"><span class="LC_warning">'.
10114: &mt('Invalid characters').'</span>';
1.987 raeburn 10115: $numinvalid++;
1.660 raeburn 10116: } else {
1.1123 raeburn 10117: $upload_output .= '<td>'.
10118: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10119: $embed_file,\%mapping,
1.1071 raeburn 10120: $allfiles,$codebase,'upload');
10121: $counter ++;
10122: $numnew ++;
1.987 raeburn 10123: }
10124: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10125: }
10126: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10127: if ($actionurl eq '/adm/dependencies') {
10128: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10129: $modify_output .= &start_data_table_row().
10130: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10131: '<img src="'.&icon($embed_file).'" border="0" />'.
10132: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10133: '<td>'.$size.'</td>'.
10134: '<td>'.$mtime.'</td>'.
10135: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10136: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10137: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10138: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10139: &embedded_file_element('upload_embedded',$counter,
10140: $embed_file,\%mapping,
10141: $allfiles,$codebase,'modify').
10142: '</div></td>'.
10143: &end_data_table_row()."\n";
10144: $counter ++;
10145: } else {
10146: $upload_output .= &start_data_table_row().
1.1123 raeburn 10147: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10148: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10149: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10150: &Apache::loncommon::end_data_table_row()."\n";
10151: }
10152: }
10153: my $delidx = $counter;
10154: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10155: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10156: $delete_output .= &start_data_table_row().
10157: '<td><img src="'.&icon($oldfile).'" />'.
10158: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10159: '<td>'.$size.'</td>'.
10160: '<td>'.$mtime.'</td>'.
10161: '<td><label><input type="checkbox" name="del_upload_dep" '.
10162: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10163: &embedded_file_element('upload_embedded',$delidx,
10164: $oldfile,\%mapping,$allfiles,
10165: $codebase,'delete').'</td>'.
10166: &end_data_table_row()."\n";
10167: $numunused ++;
10168: $delidx ++;
1.987 raeburn 10169: }
10170: if ($upload_output) {
10171: $upload_output = &start_data_table().
10172: $upload_output.
10173: &end_data_table()."\n";
10174: }
1.1071 raeburn 10175: if ($modify_output) {
10176: $modify_output = &start_data_table().
10177: &start_data_table_header_row().
10178: '<th>'.&mt('File').'</th>'.
10179: '<th>'.&mt('Size (KB)').'</th>'.
10180: '<th>'.&mt('Modified').'</th>'.
10181: '<th>'.&mt('Upload replacement?').'</th>'.
10182: &end_data_table_header_row().
10183: $modify_output.
10184: &end_data_table()."\n";
10185: }
10186: if ($delete_output) {
10187: $delete_output = &start_data_table().
10188: &start_data_table_header_row().
10189: '<th>'.&mt('File').'</th>'.
10190: '<th>'.&mt('Size (KB)').'</th>'.
10191: '<th>'.&mt('Modified').'</th>'.
10192: '<th>'.&mt('Delete?').'</th>'.
10193: &end_data_table_header_row().
10194: $delete_output.
10195: &end_data_table()."\n";
10196: }
1.987 raeburn 10197: my $applies = 0;
10198: if ($numremref) {
10199: $applies ++;
10200: }
10201: if ($numinvalid) {
10202: $applies ++;
10203: }
10204: if ($numexisting) {
10205: $applies ++;
10206: }
1.1071 raeburn 10207: if ($counter || $numunused) {
1.987 raeburn 10208: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10209: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10210: $state.'<h3>'.$heading.'</h3>';
10211: if ($actionurl eq '/adm/dependencies') {
10212: if ($numnew) {
10213: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10214: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10215: $upload_output.'<br />'."\n";
10216: }
10217: if ($numexisting) {
10218: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10219: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10220: $modify_output.'<br />'."\n";
10221: $buttontext = &mt('Save changes');
10222: }
10223: if ($numunused) {
10224: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10225: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10226: $delete_output.'<br />'."\n";
10227: $buttontext = &mt('Save changes');
10228: }
10229: } else {
10230: $output .= $upload_output.'<br />'."\n";
10231: }
10232: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10233: $counter.'" />'."\n";
10234: if ($actionurl eq '/adm/dependencies') {
10235: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10236: $numnew.'" />'."\n";
10237: } elsif ($actionurl eq '') {
1.987 raeburn 10238: $output .= '<input type="hidden" name="phase" value="three" />';
10239: }
10240: } elsif ($applies) {
10241: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10242: if ($applies > 1) {
10243: $output .=
1.1123 raeburn 10244: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10245: if ($numremref) {
10246: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10247: }
10248: if ($numinvalid) {
10249: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10250: }
10251: if ($numexisting) {
10252: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10253: }
10254: $output .= '</ul><br />';
10255: } elsif ($numremref) {
10256: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10257: } elsif ($numinvalid) {
10258: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10259: } elsif ($numexisting) {
10260: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10261: }
10262: $output .= $upload_output.'<br />';
10263: }
10264: my ($pathchange_output,$chgcount);
1.1071 raeburn 10265: $chgcount = $counter;
1.987 raeburn 10266: if (keys(%pathchanges) > 0) {
10267: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10268: if ($counter) {
1.987 raeburn 10269: $output .= &embedded_file_element('pathchange',$chgcount,
10270: $embed_file,\%mapping,
1.1071 raeburn 10271: $allfiles,$codebase,'change');
1.987 raeburn 10272: } else {
10273: $pathchange_output .=
10274: &start_data_table_row().
10275: '<td><input type ="checkbox" name="namechange" value="'.
10276: $chgcount.'" checked="checked" /></td>'.
10277: '<td>'.$mapping{$embed_file}.'</td>'.
10278: '<td>'.$embed_file.
10279: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10280: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10281: '</td>'.&end_data_table_row();
1.660 raeburn 10282: }
1.987 raeburn 10283: $numpathchg ++;
10284: $chgcount ++;
1.660 raeburn 10285: }
10286: }
1.1127 raeburn 10287: if (($counter) || ($numunused)) {
1.987 raeburn 10288: if ($numpathchg) {
10289: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10290: $numpathchg.'" />'."\n";
10291: }
10292: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10293: ($actionurl eq '/adm/imsimport')) {
10294: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10295: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10296: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10297: } elsif ($actionurl eq '/adm/dependencies') {
10298: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10299: }
1.1123 raeburn 10300: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10301: } elsif ($numpathchg) {
10302: my %pathchange = ();
10303: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10304: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10305: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10306: }
1.987 raeburn 10307: }
1.1071 raeburn 10308: return ($output,$counter,$numpathchg);
1.987 raeburn 10309: }
10310:
1.1147 raeburn 10311: =pod
10312:
10313: =item * clean_path($name)
10314:
10315: Performs clean-up of directories, subdirectories and filename in an
10316: embedded object, referenced in an HTML file which is being uploaded
10317: to a course or portfolio, where
10318: "Upload embedded images/multimedia files if HTML file" checkbox was
10319: checked.
10320:
10321: Clean-up is similar to replacements in lonnet::clean_filename()
10322: except each / between sub-directory and next level is preserved.
10323:
10324: =cut
10325:
10326: sub clean_path {
10327: my ($embed_file) = @_;
10328: $embed_file =~s{^/+}{};
10329: my @contents;
10330: if ($embed_file =~ m{/}) {
10331: @contents = split(/\//,$embed_file);
10332: } else {
10333: @contents = ($embed_file);
10334: }
10335: my $lastidx = scalar(@contents)-1;
10336: for (my $i=0; $i<=$lastidx; $i++) {
10337: $contents[$i]=~s{\\}{/}g;
10338: $contents[$i]=~s/\s+/\_/g;
10339: $contents[$i]=~s{[^/\w\.\-]}{}g;
10340: if ($i == $lastidx) {
10341: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10342: }
10343: }
10344: if ($lastidx > 0) {
10345: return join('/',@contents);
10346: } else {
10347: return $contents[0];
10348: }
10349: }
10350:
1.987 raeburn 10351: sub embedded_file_element {
1.1071 raeburn 10352: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10353: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10354: (ref($codebase) eq 'HASH'));
10355: my $output;
1.1071 raeburn 10356: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10357: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10358: }
10359: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10360: &escape($embed_file).'" />';
10361: unless (($context eq 'upload_embedded') &&
10362: ($mapping->{$embed_file} eq $embed_file)) {
10363: $output .='
10364: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10365: }
10366: my $attrib;
10367: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10368: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10369: }
10370: $output .=
10371: "\n\t\t".
10372: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10373: $attrib.'" />';
10374: if (exists($codebase->{$mapping->{$embed_file}})) {
10375: $output .=
10376: "\n\t\t".
10377: '<input name="codebase_'.$num.'" type="hidden" value="'.
10378: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10379: }
1.987 raeburn 10380: return $output;
1.660 raeburn 10381: }
10382:
1.1071 raeburn 10383: sub get_dependency_details {
10384: my ($currfile,$currsubfile,$embed_file) = @_;
10385: my ($size,$mtime,$showsize,$showmtime);
10386: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10387: if ($embed_file =~ m{/}) {
10388: my ($path,$fname) = split(/\//,$embed_file);
10389: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10390: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10391: }
10392: } else {
10393: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10394: ($size,$mtime) = @{$currfile->{$embed_file}};
10395: }
10396: }
10397: $showsize = $size/1024.0;
10398: $showsize = sprintf("%.1f",$showsize);
10399: if ($mtime > 0) {
10400: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10401: }
10402: }
10403: return ($showsize,$showmtime);
10404: }
10405:
10406: sub ask_embedded_js {
10407: return <<"END";
10408: <script type="text/javascript"">
10409: // <![CDATA[
10410: function toggleBrowse(counter) {
10411: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10412: var fileid = document.getElementById('embedded_item_'+counter);
10413: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10414: if (chkboxid.checked == true) {
10415: uploaddivid.style.display='block';
10416: } else {
10417: uploaddivid.style.display='none';
10418: fileid.value = '';
10419: }
10420: }
10421: // ]]>
10422: </script>
10423:
10424: END
10425: }
10426:
1.661 raeburn 10427: sub upload_embedded {
10428: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10429: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10430: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10431: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10432: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10433: my $orig_uploaded_filename =
10434: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10435: foreach my $type ('orig','ref','attrib','codebase') {
10436: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10437: $env{'form.embedded_'.$type.'_'.$i} =
10438: &unescape($env{'form.embedded_'.$type.'_'.$i});
10439: }
10440: }
1.661 raeburn 10441: my ($path,$fname) =
10442: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10443: # no path, whole string is fname
10444: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10445: $fname = &Apache::lonnet::clean_filename($fname);
10446: # See if there is anything left
10447: next if ($fname eq '');
10448:
10449: # Check if file already exists as a file or directory.
10450: my ($state,$msg);
10451: if ($context eq 'portfolio') {
10452: my $port_path = $dirpath;
10453: if ($group ne '') {
10454: $port_path = "groups/$group/$port_path";
10455: }
1.987 raeburn 10456: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10457: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10458: $dir_root,$port_path,$disk_quota,
10459: $current_disk_usage,$uname,$udom);
10460: if ($state eq 'will_exceed_quota'
1.984 raeburn 10461: || $state eq 'file_locked') {
1.661 raeburn 10462: $output .= $msg;
10463: next;
10464: }
10465: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10466: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10467: if ($state eq 'exists') {
10468: $output .= $msg;
10469: next;
10470: }
10471: }
10472: # Check if extension is valid
10473: if (($fname =~ /\.(\w+)$/) &&
10474: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 10475: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10476: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10477: next;
10478: } elsif (($fname =~ /\.(\w+)$/) &&
10479: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10480: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10481: next;
10482: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10483: $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 10484: next;
10485: }
10486: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10487: my $subdir = $path;
10488: $subdir =~ s{/+$}{};
1.661 raeburn 10489: if ($context eq 'portfolio') {
1.984 raeburn 10490: my $result;
10491: if ($state eq 'existingfile') {
10492: $result=
10493: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10494: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10495: } else {
1.984 raeburn 10496: $result=
10497: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10498: $dirpath.
1.1123 raeburn 10499: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10500: if ($result !~ m|^/uploaded/|) {
10501: $output .= '<span class="LC_error">'
10502: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10503: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10504: .'</span><br />';
10505: next;
10506: } else {
1.987 raeburn 10507: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10508: $path.$fname.'</span>').'<br />';
1.984 raeburn 10509: }
1.661 raeburn 10510: }
1.1123 raeburn 10511: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10512: my $extendedsubdir = $dirpath.'/'.$subdir;
10513: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10514: my $result =
1.1126 raeburn 10515: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10516: if ($result !~ m|^/uploaded/|) {
10517: $output .= '<span class="LC_error">'
10518: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10519: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10520: .'</span><br />';
10521: next;
10522: } else {
10523: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10524: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10525: if ($context eq 'syllabus') {
10526: &Apache::lonnet::make_public_indefinitely($result);
10527: }
1.987 raeburn 10528: }
1.661 raeburn 10529: } else {
10530: # Save the file
10531: my $target = $env{'form.embedded_item_'.$i};
10532: my $fullpath = $dir_root.$dirpath.'/'.$path;
10533: my $dest = $fullpath.$fname;
10534: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10535: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10536: my $count;
10537: my $filepath = $dir_root;
1.1027 raeburn 10538: foreach my $subdir (@parts) {
10539: $filepath .= "/$subdir";
10540: if (!-e $filepath) {
1.661 raeburn 10541: mkdir($filepath,0770);
10542: }
10543: }
10544: my $fh;
10545: if (!open($fh,'>'.$dest)) {
10546: &Apache::lonnet::logthis('Failed to create '.$dest);
10547: $output .= '<span class="LC_error">'.
1.1071 raeburn 10548: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10549: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10550: '</span><br />';
10551: } else {
10552: if (!print $fh $env{'form.embedded_item_'.$i}) {
10553: &Apache::lonnet::logthis('Failed to write to '.$dest);
10554: $output .= '<span class="LC_error">'.
1.1071 raeburn 10555: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10556: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10557: '</span><br />';
10558: } else {
1.987 raeburn 10559: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10560: $url.'</span>').'<br />';
10561: unless ($context eq 'testbank') {
10562: $footer .= &mt('View embedded file: [_1]',
10563: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10564: }
10565: }
10566: close($fh);
10567: }
10568: }
10569: if ($env{'form.embedded_ref_'.$i}) {
10570: $pathchange{$i} = 1;
10571: }
10572: }
10573: if ($output) {
10574: $output = '<p>'.$output.'</p>';
10575: }
10576: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10577: $returnflag = 'ok';
1.1071 raeburn 10578: my $numpathchgs = scalar(keys(%pathchange));
10579: if ($numpathchgs > 0) {
1.987 raeburn 10580: if ($context eq 'portfolio') {
10581: $output .= '<p>'.&mt('or').'</p>';
10582: } elsif ($context eq 'testbank') {
1.1071 raeburn 10583: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10584: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10585: $returnflag = 'modify_orightml';
10586: }
10587: }
1.1071 raeburn 10588: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10589: }
10590:
10591: sub modify_html_form {
10592: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10593: my $end = 0;
10594: my $modifyform;
10595: if ($context eq 'upload_embedded') {
10596: return unless (ref($pathchange) eq 'HASH');
10597: if ($env{'form.number_embedded_items'}) {
10598: $end += $env{'form.number_embedded_items'};
10599: }
10600: if ($env{'form.number_pathchange_items'}) {
10601: $end += $env{'form.number_pathchange_items'};
10602: }
10603: if ($end) {
10604: for (my $i=0; $i<$end; $i++) {
10605: if ($i < $env{'form.number_embedded_items'}) {
10606: next unless($pathchange->{$i});
10607: }
10608: $modifyform .=
10609: &start_data_table_row().
10610: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10611: 'checked="checked" /></td>'.
10612: '<td>'.$env{'form.embedded_ref_'.$i}.
10613: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10614: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10615: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10616: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10617: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10618: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10619: '<td>'.$env{'form.embedded_orig_'.$i}.
10620: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10621: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10622: &end_data_table_row();
1.1071 raeburn 10623: }
1.987 raeburn 10624: }
10625: } else {
10626: $modifyform = $pathchgtable;
10627: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10628: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10629: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10630: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10631: }
10632: }
10633: if ($modifyform) {
1.1071 raeburn 10634: if ($actionurl eq '/adm/dependencies') {
10635: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10636: }
1.987 raeburn 10637: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10638: '<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".
10639: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10640: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10641: '</ol></p>'."\n".'<p>'.
10642: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10643: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10644: &start_data_table()."\n".
10645: &start_data_table_header_row().
10646: '<th>'.&mt('Change?').'</th>'.
10647: '<th>'.&mt('Current reference').'</th>'.
10648: '<th>'.&mt('Required reference').'</th>'.
10649: &end_data_table_header_row()."\n".
10650: $modifyform.
10651: &end_data_table().'<br />'."\n".$hiddenstate.
10652: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10653: '</form>'."\n";
10654: }
10655: return;
10656: }
10657:
10658: sub modify_html_refs {
1.1123 raeburn 10659: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10660: my $container;
10661: if ($context eq 'portfolio') {
10662: $container = $env{'form.container'};
10663: } elsif ($context eq 'coursedoc') {
10664: $container = $env{'form.primaryurl'};
1.1071 raeburn 10665: } elsif ($context eq 'manage_dependencies') {
10666: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10667: $container = "/$container";
1.1123 raeburn 10668: } elsif ($context eq 'syllabus') {
10669: $container = $url;
1.987 raeburn 10670: } else {
1.1027 raeburn 10671: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10672: }
10673: my (%allfiles,%codebase,$output,$content);
10674: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10675: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10676: if (wantarray) {
10677: return ('',0,0);
10678: } else {
10679: return;
10680: }
10681: }
10682: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10683: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10684: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10685: if (wantarray) {
10686: return ('',0,0);
10687: } else {
10688: return;
10689: }
10690: }
1.987 raeburn 10691: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10692: if ($content eq '-1') {
10693: if (wantarray) {
10694: return ('',0,0);
10695: } else {
10696: return;
10697: }
10698: }
1.987 raeburn 10699: } else {
1.1071 raeburn 10700: unless ($container =~ /^\Q$dir_root\E/) {
10701: if (wantarray) {
10702: return ('',0,0);
10703: } else {
10704: return;
10705: }
10706: }
1.987 raeburn 10707: if (open(my $fh,"<$container")) {
10708: $content = join('', <$fh>);
10709: close($fh);
10710: } else {
1.1071 raeburn 10711: if (wantarray) {
10712: return ('',0,0);
10713: } else {
10714: return;
10715: }
1.987 raeburn 10716: }
10717: }
10718: my ($count,$codebasecount) = (0,0);
10719: my $mm = new File::MMagic;
10720: my $mime_type = $mm->checktype_contents($content);
10721: if ($mime_type eq 'text/html') {
10722: my $parse_result =
10723: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10724: \%codebase,\$content);
10725: if ($parse_result eq 'ok') {
10726: foreach my $i (@changes) {
10727: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10728: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10729: if ($allfiles{$ref}) {
10730: my $newname = $orig;
10731: my ($attrib_regexp,$codebase);
1.1006 raeburn 10732: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10733: if ($attrib_regexp =~ /:/) {
10734: $attrib_regexp =~ s/\:/|/g;
10735: }
10736: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10737: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10738: $count += $numchg;
1.1123 raeburn 10739: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 10740: delete($allfiles{$ref});
1.987 raeburn 10741: }
10742: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10743: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10744: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10745: $codebasecount ++;
10746: }
10747: }
10748: }
1.1123 raeburn 10749: my $skiprewrites;
1.987 raeburn 10750: if ($count || $codebasecount) {
10751: my $saveresult;
1.1071 raeburn 10752: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10753: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10754: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10755: if ($url eq $container) {
10756: my ($fname) = ($container =~ m{/([^/]+)$});
10757: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10758: $count,'<span class="LC_filename">'.
1.1071 raeburn 10759: $fname.'</span>').'</p>';
1.987 raeburn 10760: } else {
10761: $output = '<p class="LC_error">'.
10762: &mt('Error: update failed for: [_1].',
10763: '<span class="LC_filename">'.
10764: $container.'</span>').'</p>';
10765: }
1.1123 raeburn 10766: if ($context eq 'syllabus') {
10767: unless ($saveresult eq 'ok') {
10768: $skiprewrites = 1;
10769: }
10770: }
1.987 raeburn 10771: } else {
10772: if (open(my $fh,">$container")) {
10773: print $fh $content;
10774: close($fh);
10775: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10776: $count,'<span class="LC_filename">'.
10777: $container.'</span>').'</p>';
1.661 raeburn 10778: } else {
1.987 raeburn 10779: $output = '<p class="LC_error">'.
10780: &mt('Error: could not update [_1].',
10781: '<span class="LC_filename">'.
10782: $container.'</span>').'</p>';
1.661 raeburn 10783: }
10784: }
10785: }
1.1123 raeburn 10786: if (($context eq 'syllabus') && (!$skiprewrites)) {
10787: my ($actionurl,$state);
10788: $actionurl = "/public/$udom/$uname/syllabus";
10789: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10790: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10791: \%codebase,
10792: {'context' => 'rewrites',
10793: 'ignore_remote_references' => 1,});
10794: if (ref($mapping) eq 'HASH') {
10795: my $rewrites = 0;
10796: foreach my $key (keys(%{$mapping})) {
10797: next if ($key =~ m{^https?://});
10798: my $ref = $mapping->{$key};
10799: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10800: my $attrib;
10801: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10802: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10803: }
10804: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10805: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10806: $rewrites += $numchg;
10807: }
10808: }
10809: if ($rewrites) {
10810: my $saveresult;
10811: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10812: if ($url eq $container) {
10813: my ($fname) = ($container =~ m{/([^/]+)$});
10814: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10815: $count,'<span class="LC_filename">'.
10816: $fname.'</span>').'</p>';
10817: } else {
10818: $output .= '<p class="LC_error">'.
10819: &mt('Error: could not update links in [_1].',
10820: '<span class="LC_filename">'.
10821: $container.'</span>').'</p>';
10822:
10823: }
10824: }
10825: }
10826: }
1.987 raeburn 10827: } else {
10828: &logthis('Failed to parse '.$container.
10829: ' to modify references: '.$parse_result);
1.661 raeburn 10830: }
10831: }
1.1071 raeburn 10832: if (wantarray) {
10833: return ($output,$count,$codebasecount);
10834: } else {
10835: return $output;
10836: }
1.661 raeburn 10837: }
10838:
10839: sub check_for_existing {
10840: my ($path,$fname,$element) = @_;
10841: my ($state,$msg);
10842: if (-d $path.'/'.$fname) {
10843: $state = 'exists';
10844: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10845: } elsif (-e $path.'/'.$fname) {
10846: $state = 'exists';
10847: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10848: }
10849: if ($state eq 'exists') {
10850: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10851: }
10852: return ($state,$msg);
10853: }
10854:
10855: sub check_for_upload {
10856: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10857: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10858: my $filesize = length($env{'form.'.$element});
10859: if (!$filesize) {
10860: my $msg = '<span class="LC_error">'.
10861: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10862: '<span class="LC_filename">'.$fname.'</span>',
10863: $filesize).'<br />'.
1.1007 raeburn 10864: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10865: '</span>';
10866: return ('zero_bytes',$msg);
10867: }
10868: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10869: my $getpropath = 1;
1.1021 raeburn 10870: my ($dirlistref,$listerror) =
10871: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10872: my $found_file = 0;
10873: my $locked_file = 0;
1.991 raeburn 10874: my @lockers;
10875: my $navmap;
10876: if ($env{'request.course.id'}) {
10877: $navmap = Apache::lonnavmaps::navmap->new();
10878: }
1.1021 raeburn 10879: if (ref($dirlistref) eq 'ARRAY') {
10880: foreach my $line (@{$dirlistref}) {
10881: my ($file_name,$rest)=split(/\&/,$line,2);
10882: if ($file_name eq $fname){
10883: $file_name = $path.$file_name;
10884: if ($group ne '') {
10885: $file_name = $group.$file_name;
10886: }
10887: $found_file = 1;
10888: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10889: foreach my $lock (@lockers) {
10890: if (ref($lock) eq 'ARRAY') {
10891: my ($symb,$crsid) = @{$lock};
10892: if ($crsid eq $env{'request.course.id'}) {
10893: if (ref($navmap)) {
10894: my $res = $navmap->getBySymb($symb);
10895: foreach my $part (@{$res->parts()}) {
10896: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10897: unless (($slot_status == $res->RESERVED) ||
10898: ($slot_status == $res->RESERVED_LOCATION)) {
10899: $locked_file = 1;
10900: }
1.991 raeburn 10901: }
1.1021 raeburn 10902: } else {
10903: $locked_file = 1;
1.991 raeburn 10904: }
10905: } else {
10906: $locked_file = 1;
10907: }
10908: }
1.1021 raeburn 10909: }
10910: } else {
10911: my @info = split(/\&/,$rest);
10912: my $currsize = $info[6]/1000;
10913: if ($currsize < $filesize) {
10914: my $extra = $filesize - $currsize;
10915: if (($current_disk_usage + $extra) > $disk_quota) {
10916: my $msg = '<span class="LC_error">'.
10917: &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.',
10918: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10919: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10920: $disk_quota,$current_disk_usage);
10921: return ('will_exceed_quota',$msg);
10922: }
1.984 raeburn 10923: }
10924: }
1.661 raeburn 10925: }
10926: }
10927: }
10928: if (($current_disk_usage + $filesize) > $disk_quota){
10929: my $msg = '<span class="LC_error">'.
10930: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10931: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10932: return ('will_exceed_quota',$msg);
10933: } elsif ($found_file) {
10934: if ($locked_file) {
10935: my $msg = '<span class="LC_error">';
10936: $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>');
10937: $msg .= '</span><br />';
10938: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10939: return ('file_locked',$msg);
10940: } else {
10941: my $msg = '<span class="LC_error">';
1.984 raeburn 10942: $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 10943: $msg .= '</span>';
1.984 raeburn 10944: return ('existingfile',$msg);
1.661 raeburn 10945: }
10946: }
10947: }
10948:
1.987 raeburn 10949: sub check_for_traversal {
10950: my ($path,$url,$toplevel) = @_;
10951: my @parts=split(/\//,$path);
10952: my $cleanpath;
10953: my $fullpath = $url;
10954: for (my $i=0;$i<@parts;$i++) {
10955: next if ($parts[$i] eq '.');
10956: if ($parts[$i] eq '..') {
10957: $fullpath =~ s{([^/]+/)$}{};
10958: } else {
10959: $fullpath .= $parts[$i].'/';
10960: }
10961: }
10962: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10963: $cleanpath = $1;
10964: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10965: my $curr_toprel = $1;
10966: my @parts = split(/\//,$curr_toprel);
10967: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10968: my @urlparts = split(/\//,$url_toprel);
10969: my $doubledots;
10970: my $startdiff = -1;
10971: for (my $i=0; $i<@urlparts; $i++) {
10972: if ($startdiff == -1) {
10973: unless ($urlparts[$i] eq $parts[$i]) {
10974: $startdiff = $i;
10975: $doubledots .= '../';
10976: }
10977: } else {
10978: $doubledots .= '../';
10979: }
10980: }
10981: if ($startdiff > -1) {
10982: $cleanpath = $doubledots;
10983: for (my $i=$startdiff; $i<@parts; $i++) {
10984: $cleanpath .= $parts[$i].'/';
10985: }
10986: }
10987: }
10988: $cleanpath =~ s{(/)$}{};
10989: return $cleanpath;
10990: }
1.31 albertel 10991:
1.1053 raeburn 10992: sub is_archive_file {
10993: my ($mimetype) = @_;
10994: if (($mimetype eq 'application/octet-stream') ||
10995: ($mimetype eq 'application/x-stuffit') ||
10996: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10997: return 1;
10998: }
10999: return;
11000: }
11001:
11002: sub decompress_form {
1.1065 raeburn 11003: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11004: my %lt = &Apache::lonlocal::texthash (
11005: this => 'This file is an archive file.',
1.1067 raeburn 11006: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11007: itsc => 'Its contents are as follows:',
1.1053 raeburn 11008: youm => 'You may wish to extract its contents.',
11009: extr => 'Extract contents',
1.1067 raeburn 11010: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11011: proa => 'Process automatically?',
1.1053 raeburn 11012: yes => 'Yes',
11013: no => 'No',
1.1067 raeburn 11014: fold => 'Title for folder containing movie',
11015: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11016: );
1.1065 raeburn 11017: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11018: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11019: my $info = &list_archive_contents($fileloc,\@paths);
11020: if (@paths) {
11021: foreach my $path (@paths) {
11022: $path =~ s{^/}{};
1.1067 raeburn 11023: if ($path =~ m{^([^/]+)/$}) {
11024: $topdir = $1;
11025: }
1.1065 raeburn 11026: if ($path =~ m{^([^/]+)/}) {
11027: $toplevel{$1} = $path;
11028: } else {
11029: $toplevel{$path} = $path;
11030: }
11031: }
11032: }
1.1067 raeburn 11033: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11034: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11035: "$topdir/media/",
11036: "$topdir/media/$topdir.mp4",
11037: "$topdir/media/FirstFrame.png",
11038: "$topdir/media/player.swf",
11039: "$topdir/media/swfobject.js",
11040: "$topdir/media/expressInstall.swf");
1.1164 raeburn 11041: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11042: "$topdir/$topdir.mp4",
11043: "$topdir/$topdir\_config.xml",
11044: "$topdir/$topdir\_controller.swf",
11045: "$topdir/$topdir\_embed.css",
11046: "$topdir/$topdir\_First_Frame.png",
11047: "$topdir/$topdir\_player.html",
11048: "$topdir/$topdir\_Thumbnails.png",
11049: "$topdir/playerProductInstall.swf",
11050: "$topdir/scripts/",
11051: "$topdir/scripts/config_xml.js",
11052: "$topdir/scripts/handlebars.js",
11053: "$topdir/scripts/jquery-1.7.1.min.js",
11054: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11055: "$topdir/scripts/modernizr.js",
11056: "$topdir/scripts/player-min.js",
11057: "$topdir/scripts/swfobject.js",
11058: "$topdir/skins/",
11059: "$topdir/skins/configuration_express.xml",
11060: "$topdir/skins/express_show/",
11061: "$topdir/skins/express_show/player-min.css",
11062: "$topdir/skins/express_show/spritesheet.png");
11063: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11064: if (@diffs == 0) {
1.1164 raeburn 11065: $is_camtasia = 6;
11066: } else {
11067: @diffs = &compare_arrays(\@paths,\@camtasia8);
11068: if (@diffs == 0) {
11069: $is_camtasia = 8;
11070: }
1.1067 raeburn 11071: }
11072: }
11073: my $output;
11074: if ($is_camtasia) {
11075: $output = <<"ENDCAM";
11076: <script type="text/javascript" language="Javascript">
11077: // <![CDATA[
11078:
11079: function camtasiaToggle() {
11080: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11081: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11082: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11083:
11084: document.getElementById('camtasia_titles').style.display='block';
11085: } else {
11086: document.getElementById('camtasia_titles').style.display='none';
11087: }
11088: }
11089: }
11090: return;
11091: }
11092:
11093: // ]]>
11094: </script>
11095: <p>$lt{'camt'}</p>
11096: ENDCAM
1.1065 raeburn 11097: } else {
1.1067 raeburn 11098: $output = '<p>'.$lt{'this'};
11099: if ($info eq '') {
11100: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11101: } else {
11102: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11103: '<div><pre>'.$info.'</pre></div>';
11104: }
1.1065 raeburn 11105: }
1.1067 raeburn 11106: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11107: my $duplicates;
11108: my $num = 0;
11109: if (ref($dirlist) eq 'ARRAY') {
11110: foreach my $item (@{$dirlist}) {
11111: if (ref($item) eq 'ARRAY') {
11112: if (exists($toplevel{$item->[0]})) {
11113: $duplicates .=
11114: &start_data_table_row().
11115: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11116: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11117: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11118: 'value="1" />'.&mt('Yes').'</label>'.
11119: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11120: '<td>'.$item->[0].'</td>';
11121: if ($item->[2]) {
11122: $duplicates .= '<td>'.&mt('Directory').'</td>';
11123: } else {
11124: $duplicates .= '<td>'.&mt('File').'</td>';
11125: }
11126: $duplicates .= '<td>'.$item->[3].'</td>'.
11127: '<td>'.
11128: &Apache::lonlocal::locallocaltime($item->[4]).
11129: '</td>'.
11130: &end_data_table_row();
11131: $num ++;
11132: }
11133: }
11134: }
11135: }
11136: my $itemcount;
11137: if (@paths > 0) {
11138: $itemcount = scalar(@paths);
11139: } else {
11140: $itemcount = 1;
11141: }
1.1067 raeburn 11142: if ($is_camtasia) {
11143: $output .= $lt{'auto'}.'<br />'.
11144: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11145: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11146: $lt{'yes'}.'</label> <label>'.
11147: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11148: $lt{'no'}.'</label></span><br />'.
11149: '<div id="camtasia_titles" style="display:block">'.
11150: &Apache::lonhtmlcommon::start_pick_box().
11151: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11152: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11153: &Apache::lonhtmlcommon::row_closure().
11154: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11155: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11156: &Apache::lonhtmlcommon::row_closure(1).
11157: &Apache::lonhtmlcommon::end_pick_box().
11158: '</div>';
11159: }
1.1065 raeburn 11160: $output .=
11161: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11162: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11163: "\n";
1.1065 raeburn 11164: if ($duplicates ne '') {
11165: $output .= '<p><span class="LC_warning">'.
11166: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11167: &start_data_table().
11168: &start_data_table_header_row().
11169: '<th>'.&mt('Overwrite?').'</th>'.
11170: '<th>'.&mt('Name').'</th>'.
11171: '<th>'.&mt('Type').'</th>'.
11172: '<th>'.&mt('Size').'</th>'.
11173: '<th>'.&mt('Last modified').'</th>'.
11174: &end_data_table_header_row().
11175: $duplicates.
11176: &end_data_table().
11177: '</p>';
11178: }
1.1067 raeburn 11179: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11180: if (ref($hiddenelements) eq 'HASH') {
11181: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11182: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11183: }
11184: }
11185: $output .= <<"END";
1.1067 raeburn 11186: <br />
1.1053 raeburn 11187: <input type="submit" name="decompress" value="$lt{'extr'}" />
11188: </form>
11189: $noextract
11190: END
11191: return $output;
11192: }
11193:
1.1065 raeburn 11194: sub decompression_utility {
11195: my ($program) = @_;
11196: my @utilities = ('tar','gunzip','bunzip2','unzip');
11197: my $location;
11198: if (grep(/^\Q$program\E$/,@utilities)) {
11199: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11200: '/usr/sbin/') {
11201: if (-x $dir.$program) {
11202: $location = $dir.$program;
11203: last;
11204: }
11205: }
11206: }
11207: return $location;
11208: }
11209:
11210: sub list_archive_contents {
11211: my ($file,$pathsref) = @_;
11212: my (@cmd,$output);
11213: my $needsregexp;
11214: if ($file =~ /\.zip$/) {
11215: @cmd = (&decompression_utility('unzip'),"-l");
11216: $needsregexp = 1;
11217: } elsif (($file =~ m/\.tar\.gz$/) ||
11218: ($file =~ /\.tgz$/)) {
11219: @cmd = (&decompression_utility('tar'),"-ztf");
11220: } elsif ($file =~ /\.tar\.bz2$/) {
11221: @cmd = (&decompression_utility('tar'),"-jtf");
11222: } elsif ($file =~ m|\.tar$|) {
11223: @cmd = (&decompression_utility('tar'),"-tf");
11224: }
11225: if (@cmd) {
11226: undef($!);
11227: undef($@);
11228: if (open(my $fh,"-|", @cmd, $file)) {
11229: while (my $line = <$fh>) {
11230: $output .= $line;
11231: chomp($line);
11232: my $item;
11233: if ($needsregexp) {
11234: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11235: } else {
11236: $item = $line;
11237: }
11238: if ($item ne '') {
11239: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11240: push(@{$pathsref},$item);
11241: }
11242: }
11243: }
11244: close($fh);
11245: }
11246: }
11247: return $output;
11248: }
11249:
1.1053 raeburn 11250: sub decompress_uploaded_file {
11251: my ($file,$dir) = @_;
11252: &Apache::lonnet::appenv({'cgi.file' => $file});
11253: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11254: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11255: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11256: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11257: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11258: my $decompressed = $env{'cgi.decompressed'};
11259: &Apache::lonnet::delenv('cgi.file');
11260: &Apache::lonnet::delenv('cgi.dir');
11261: &Apache::lonnet::delenv('cgi.decompressed');
11262: return ($decompressed,$result);
11263: }
11264:
1.1055 raeburn 11265: sub process_decompression {
11266: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11267: my ($dir,$error,$warning,$output);
11268: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1120 bisitz 11269: $error = &mt('Filename not a supported archive file type.').
11270: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11271: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11272: } else {
11273: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11274: if ($docuhome eq 'no_host') {
11275: $error = &mt('Could not determine home server for course.');
11276: } else {
11277: my @ids=&Apache::lonnet::current_machine_ids();
11278: my $currdir = "$dir_root/$destination";
11279: if (grep(/^\Q$docuhome\E$/,@ids)) {
11280: $dir = &LONCAPA::propath($docudom,$docuname).
11281: "$dir_root/$destination";
11282: } else {
11283: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11284: "$dir_root/$docudom/$docuname/$destination";
11285: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11286: $error = &mt('Archive file not found.');
11287: }
11288: }
1.1065 raeburn 11289: my (@to_overwrite,@to_skip);
11290: if ($env{'form.archive_overwrite_total'} > 0) {
11291: my $total = $env{'form.archive_overwrite_total'};
11292: for (my $i=0; $i<$total; $i++) {
11293: if ($env{'form.archive_overwrite_'.$i} == 1) {
11294: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11295: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11296: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11297: }
11298: }
11299: }
11300: my $numskip = scalar(@to_skip);
11301: if (($numskip > 0) &&
11302: ($numskip == $env{'form.archive_itemcount'})) {
11303: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11304: } elsif ($dir eq '') {
1.1055 raeburn 11305: $error = &mt('Directory containing archive file unavailable.');
11306: } elsif (!$error) {
1.1065 raeburn 11307: my ($decompressed,$display);
11308: if ($numskip > 0) {
11309: my $tempdir = time.'_'.$$.int(rand(10000));
11310: mkdir("$dir/$tempdir",0755);
11311: system("mv $dir/$file $dir/$tempdir/$file");
11312: ($decompressed,$display) =
11313: &decompress_uploaded_file($file,"$dir/$tempdir");
11314: foreach my $item (@to_skip) {
11315: if (($item ne '') && ($item !~ /\.\./)) {
11316: if (-f "$dir/$tempdir/$item") {
11317: unlink("$dir/$tempdir/$item");
11318: } elsif (-d "$dir/$tempdir/$item") {
11319: system("rm -rf $dir/$tempdir/$item");
11320: }
11321: }
11322: }
11323: system("mv $dir/$tempdir/* $dir");
11324: rmdir("$dir/$tempdir");
11325: } else {
11326: ($decompressed,$display) =
11327: &decompress_uploaded_file($file,$dir);
11328: }
1.1055 raeburn 11329: if ($decompressed eq 'ok') {
1.1065 raeburn 11330: $output = '<p class="LC_info">'.
11331: &mt('Files extracted successfully from archive.').
11332: '</p>'."\n";
1.1055 raeburn 11333: my ($warning,$result,@contents);
11334: my ($newdirlistref,$newlisterror) =
11335: &Apache::lonnet::dirlist($currdir,$docudom,
11336: $docuname,1);
11337: my (%is_dir,%changes,@newitems);
11338: my $dirptr = 16384;
1.1065 raeburn 11339: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11340: foreach my $dir_line (@{$newdirlistref}) {
11341: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11342: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11343: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11344: push(@newitems,$item);
11345: if ($dirptr&$testdir) {
11346: $is_dir{$item} = 1;
11347: }
11348: $changes{$item} = 1;
11349: }
11350: }
11351: }
11352: if (keys(%changes) > 0) {
11353: foreach my $item (sort(@newitems)) {
11354: if ($changes{$item}) {
11355: push(@contents,$item);
11356: }
11357: }
11358: }
11359: if (@contents > 0) {
1.1067 raeburn 11360: my $wantform;
11361: unless ($env{'form.autoextract_camtasia'}) {
11362: $wantform = 1;
11363: }
1.1056 raeburn 11364: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11365: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11366: $currdir,\%is_dir,
11367: \%children,\%parent,
1.1056 raeburn 11368: \@contents,\%dirorder,
11369: \%titles,$wantform);
1.1055 raeburn 11370: if ($datatable ne '') {
11371: $output .= &archive_options_form('decompressed',$datatable,
11372: $count,$hiddenelem);
1.1065 raeburn 11373: my $startcount = 6;
1.1055 raeburn 11374: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11375: \%titles,\%children);
1.1055 raeburn 11376: }
1.1067 raeburn 11377: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11378: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11379: my %displayed;
11380: my $total = 1;
11381: $env{'form.archive_directory'} = [];
11382: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11383: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11384: $path =~ s{/$}{};
11385: my $item;
11386: if ($path ne '') {
11387: $item = "$path/$titles{$i}";
11388: } else {
11389: $item = $titles{$i};
11390: }
11391: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11392: if ($item eq $contents[0]) {
11393: push(@{$env{'form.archive_directory'}},$i);
11394: $env{'form.archive_'.$i} = 'display';
11395: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11396: $displayed{'folder'} = $i;
1.1164 raeburn 11397: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11398: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11399: $env{'form.archive_'.$i} = 'display';
11400: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11401: $displayed{'web'} = $i;
11402: } else {
1.1164 raeburn 11403: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11404: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11405: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11406: push(@{$env{'form.archive_directory'}},$i);
11407: }
11408: $env{'form.archive_'.$i} = 'dependency';
11409: }
11410: $total ++;
11411: }
11412: for (my $i=1; $i<$total; $i++) {
11413: next if ($i == $displayed{'web'});
11414: next if ($i == $displayed{'folder'});
11415: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11416: }
11417: $env{'form.phase'} = 'decompress_cleanup';
11418: $env{'form.archivedelete'} = 1;
11419: $env{'form.archive_count'} = $total-1;
11420: $output .=
11421: &process_extracted_files('coursedocs',$docudom,
11422: $docuname,$destination,
11423: $dir_root,$hiddenelem);
11424: }
1.1055 raeburn 11425: } else {
11426: $warning = &mt('No new items extracted from archive file.');
11427: }
11428: } else {
11429: $output = $display;
11430: $error = &mt('An error occurred during extraction from the archive file.');
11431: }
11432: }
11433: }
11434: }
11435: if ($error) {
11436: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11437: $error.'</p>'."\n";
11438: }
11439: if ($warning) {
11440: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11441: }
11442: return $output;
11443: }
11444:
11445: sub get_extracted {
1.1056 raeburn 11446: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11447: $titles,$wantform) = @_;
1.1055 raeburn 11448: my $count = 0;
11449: my $depth = 0;
11450: my $datatable;
1.1056 raeburn 11451: my @hierarchy;
1.1055 raeburn 11452: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11453: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11454: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11455: foreach my $item (@{$contents}) {
11456: $count ++;
1.1056 raeburn 11457: @{$dirorder->{$count}} = @hierarchy;
11458: $titles->{$count} = $item;
1.1055 raeburn 11459: &archive_hierarchy($depth,$count,$parent,$children);
11460: if ($wantform) {
11461: $datatable .= &archive_row($is_dir->{$item},$item,
11462: $currdir,$depth,$count);
11463: }
11464: if ($is_dir->{$item}) {
11465: $depth ++;
1.1056 raeburn 11466: push(@hierarchy,$count);
11467: $parent->{$depth} = $count;
1.1055 raeburn 11468: $datatable .=
11469: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11470: \$depth,\$count,\@hierarchy,$dirorder,
11471: $children,$parent,$titles,$wantform);
1.1055 raeburn 11472: $depth --;
1.1056 raeburn 11473: pop(@hierarchy);
1.1055 raeburn 11474: }
11475: }
11476: return ($count,$datatable);
11477: }
11478:
11479: sub recurse_extracted_archive {
1.1056 raeburn 11480: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11481: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11482: my $result='';
1.1056 raeburn 11483: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11484: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11485: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11486: return $result;
11487: }
11488: my $dirptr = 16384;
11489: my ($newdirlistref,$newlisterror) =
11490: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11491: if (ref($newdirlistref) eq 'ARRAY') {
11492: foreach my $dir_line (@{$newdirlistref}) {
11493: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11494: unless ($item =~ /^\.+$/) {
11495: $$count ++;
1.1056 raeburn 11496: @{$dirorder->{$$count}} = @{$hierarchy};
11497: $titles->{$$count} = $item;
1.1055 raeburn 11498: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11499:
1.1055 raeburn 11500: my $is_dir;
11501: if ($dirptr&$testdir) {
11502: $is_dir = 1;
11503: }
11504: if ($wantform) {
11505: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11506: }
11507: if ($is_dir) {
11508: $$depth ++;
1.1056 raeburn 11509: push(@{$hierarchy},$$count);
11510: $parent->{$$depth} = $$count;
1.1055 raeburn 11511: $result .=
11512: &recurse_extracted_archive("$currdir/$item",$docudom,
11513: $docuname,$depth,$count,
1.1056 raeburn 11514: $hierarchy,$dirorder,$children,
11515: $parent,$titles,$wantform);
1.1055 raeburn 11516: $$depth --;
1.1056 raeburn 11517: pop(@{$hierarchy});
1.1055 raeburn 11518: }
11519: }
11520: }
11521: }
11522: return $result;
11523: }
11524:
11525: sub archive_hierarchy {
11526: my ($depth,$count,$parent,$children) =@_;
11527: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11528: if (exists($parent->{$depth})) {
11529: $children->{$parent->{$depth}} .= $count.':';
11530: }
11531: }
11532: return;
11533: }
11534:
11535: sub archive_row {
11536: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11537: my ($name) = ($item =~ m{([^/]+)$});
11538: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11539: 'display' => 'Add as file',
1.1055 raeburn 11540: 'dependency' => 'Include as dependency',
11541: 'discard' => 'Discard',
11542: );
11543: if ($is_dir) {
1.1059 raeburn 11544: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11545: }
1.1056 raeburn 11546: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11547: my $offset = 0;
1.1055 raeburn 11548: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11549: $offset ++;
1.1065 raeburn 11550: if ($action ne 'display') {
11551: $offset ++;
11552: }
1.1055 raeburn 11553: $output .= '<td><span class="LC_nobreak">'.
11554: '<label><input type="radio" name="archive_'.$count.
11555: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11556: my $text = $choices{$action};
11557: if ($is_dir) {
11558: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11559: if ($action eq 'display') {
1.1059 raeburn 11560: $text = &mt('Add as folder');
1.1055 raeburn 11561: }
1.1056 raeburn 11562: } else {
11563: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11564:
11565: }
11566: $output .= ' /> '.$choices{$action}.'</label></span>';
11567: if ($action eq 'dependency') {
11568: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11569: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11570: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11571: '<option value=""></option>'."\n".
11572: '</select>'."\n".
11573: '</div>';
1.1059 raeburn 11574: } elsif ($action eq 'display') {
11575: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11576: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11577: '</div>';
1.1055 raeburn 11578: }
1.1056 raeburn 11579: $output .= '</td>';
1.1055 raeburn 11580: }
11581: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11582: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11583: for (my $i=0; $i<$depth; $i++) {
11584: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11585: }
11586: if ($is_dir) {
11587: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11588: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11589: } else {
11590: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11591: }
11592: $output .= ' '.$name.'</td>'."\n".
11593: &end_data_table_row();
11594: return $output;
11595: }
11596:
11597: sub archive_options_form {
1.1065 raeburn 11598: my ($form,$display,$count,$hiddenelem) = @_;
11599: my %lt = &Apache::lonlocal::texthash(
11600: perm => 'Permanently remove archive file?',
11601: hows => 'How should each extracted item be incorporated in the course?',
11602: cont => 'Content actions for all',
11603: addf => 'Add as folder/file',
11604: incd => 'Include as dependency for a displayed file',
11605: disc => 'Discard',
11606: no => 'No',
11607: yes => 'Yes',
11608: save => 'Save',
11609: );
11610: my $output = <<"END";
11611: <form name="$form" method="post" action="">
11612: <p><span class="LC_nobreak">$lt{'perm'}
11613: <label>
11614: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11615: </label>
11616:
11617: <label>
11618: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11619: </span>
11620: </p>
11621: <input type="hidden" name="phase" value="decompress_cleanup" />
11622: <br />$lt{'hows'}
11623: <div class="LC_columnSection">
11624: <fieldset>
11625: <legend>$lt{'cont'}</legend>
11626: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11627: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11628: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11629: </fieldset>
11630: </div>
11631: END
11632: return $output.
1.1055 raeburn 11633: &start_data_table()."\n".
1.1065 raeburn 11634: $display."\n".
1.1055 raeburn 11635: &end_data_table()."\n".
11636: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11637: $hiddenelem.
1.1065 raeburn 11638: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11639: '</form>';
11640: }
11641:
11642: sub archive_javascript {
1.1056 raeburn 11643: my ($startcount,$numitems,$titles,$children) = @_;
11644: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11645: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11646: my $scripttag = <<START;
11647: <script type="text/javascript">
11648: // <![CDATA[
11649:
11650: function checkAll(form,prefix) {
11651: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11652: for (var i=0; i < form.elements.length; i++) {
11653: var id = form.elements[i].id;
11654: if ((id != '') && (id != undefined)) {
11655: if (idstr.test(id)) {
11656: if (form.elements[i].type == 'radio') {
11657: form.elements[i].checked = true;
1.1056 raeburn 11658: var nostart = i-$startcount;
1.1059 raeburn 11659: var offset = nostart%7;
11660: var count = (nostart-offset)/7;
1.1056 raeburn 11661: dependencyCheck(form,count,offset);
1.1055 raeburn 11662: }
11663: }
11664: }
11665: }
11666: }
11667:
11668: function propagateCheck(form,count) {
11669: if (count > 0) {
1.1059 raeburn 11670: var startelement = $startcount + ((count-1) * 7);
11671: for (var j=1; j<6; j++) {
11672: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11673: var item = startelement + j;
11674: if (form.elements[item].type == 'radio') {
11675: if (form.elements[item].checked) {
11676: containerCheck(form,count,j);
11677: break;
11678: }
1.1055 raeburn 11679: }
11680: }
11681: }
11682: }
11683: }
11684:
11685: numitems = $numitems
1.1056 raeburn 11686: var titles = new Array(numitems);
11687: var parents = new Array(numitems);
1.1055 raeburn 11688: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11689: parents[i] = new Array;
1.1055 raeburn 11690: }
1.1059 raeburn 11691: var maintitle = '$maintitle';
1.1055 raeburn 11692:
11693: START
11694:
1.1056 raeburn 11695: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11696: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11697: for (my $i=0; $i<@contents; $i ++) {
11698: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11699: }
11700: }
11701:
1.1056 raeburn 11702: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11703: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11704: }
11705:
1.1055 raeburn 11706: $scripttag .= <<END;
11707:
11708: function containerCheck(form,count,offset) {
11709: if (count > 0) {
1.1056 raeburn 11710: dependencyCheck(form,count,offset);
1.1059 raeburn 11711: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11712: form.elements[item].checked = true;
11713: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11714: if (parents[count].length > 0) {
11715: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11716: containerCheck(form,parents[count][j],offset);
11717: }
11718: }
11719: }
11720: }
11721: }
11722:
11723: function dependencyCheck(form,count,offset) {
11724: if (count > 0) {
1.1059 raeburn 11725: var chosen = (offset+$startcount)+7*(count-1);
11726: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11727: var currtype = form.elements[depitem].type;
11728: if (form.elements[chosen].value == 'dependency') {
11729: document.getElementById('arc_depon_'+count).style.display='block';
11730: form.elements[depitem].options.length = 0;
11731: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11732: for (var i=1; i<=numitems; i++) {
11733: if (i == count) {
11734: continue;
11735: }
1.1059 raeburn 11736: var startelement = $startcount + (i-1) * 7;
11737: for (var j=1; j<6; j++) {
11738: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11739: var item = startelement + j;
11740: if (form.elements[item].type == 'radio') {
11741: if (form.elements[item].checked) {
11742: if (form.elements[item].value == 'display') {
11743: var n = form.elements[depitem].options.length;
11744: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11745: }
11746: }
11747: }
11748: }
11749: }
11750: }
11751: } else {
11752: document.getElementById('arc_depon_'+count).style.display='none';
11753: form.elements[depitem].options.length = 0;
11754: form.elements[depitem].options[0] = new Option('Select','',true,true);
11755: }
1.1059 raeburn 11756: titleCheck(form,count,offset);
1.1056 raeburn 11757: }
11758: }
11759:
11760: function propagateSelect(form,count,offset) {
11761: if (count > 0) {
1.1065 raeburn 11762: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11763: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11764: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11765: if (parents[count].length > 0) {
11766: for (var j=0; j<parents[count].length; j++) {
11767: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11768: }
11769: }
11770: }
11771: }
11772: }
1.1056 raeburn 11773:
11774: function containerSelect(form,count,offset,picked) {
11775: if (count > 0) {
1.1065 raeburn 11776: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11777: if (form.elements[item].type == 'radio') {
11778: if (form.elements[item].value == 'dependency') {
11779: if (form.elements[item+1].type == 'select-one') {
11780: for (var i=0; i<form.elements[item+1].options.length; i++) {
11781: if (form.elements[item+1].options[i].value == picked) {
11782: form.elements[item+1].selectedIndex = i;
11783: break;
11784: }
11785: }
11786: }
11787: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11788: if (parents[count].length > 0) {
11789: for (var j=0; j<parents[count].length; j++) {
11790: containerSelect(form,parents[count][j],offset,picked);
11791: }
11792: }
11793: }
11794: }
11795: }
11796: }
11797: }
11798:
1.1059 raeburn 11799: function titleCheck(form,count,offset) {
11800: if (count > 0) {
11801: var chosen = (offset+$startcount)+7*(count-1);
11802: var depitem = $startcount + ((count-1) * 7) + 2;
11803: var currtype = form.elements[depitem].type;
11804: if (form.elements[chosen].value == 'display') {
11805: document.getElementById('arc_title_'+count).style.display='block';
11806: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11807: document.getElementById('archive_title_'+count).value=maintitle;
11808: }
11809: } else {
11810: document.getElementById('arc_title_'+count).style.display='none';
11811: if (currtype == 'text') {
11812: document.getElementById('archive_title_'+count).value='';
11813: }
11814: }
11815: }
11816: return;
11817: }
11818:
1.1055 raeburn 11819: // ]]>
11820: </script>
11821: END
11822: return $scripttag;
11823: }
11824:
11825: sub process_extracted_files {
1.1067 raeburn 11826: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11827: my $numitems = $env{'form.archive_count'};
11828: return unless ($numitems);
11829: my @ids=&Apache::lonnet::current_machine_ids();
11830: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11831: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11832: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11833: if (grep(/^\Q$docuhome\E$/,@ids)) {
11834: $prefix = &LONCAPA::propath($docudom,$docuname);
11835: $pathtocheck = "$dir_root/$destination";
11836: $dir = $dir_root;
11837: $ishome = 1;
11838: } else {
11839: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11840: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11841: $dir = "$dir_root/$docudom/$docuname";
11842: }
11843: my $currdir = "$dir_root/$destination";
11844: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11845: if ($env{'form.folderpath'}) {
11846: my @items = split('&',$env{'form.folderpath'});
11847: $folders{'0'} = $items[-2];
1.1099 raeburn 11848: if ($env{'form.folderpath'} =~ /\:1$/) {
11849: $containers{'0'}='page';
11850: } else {
11851: $containers{'0'}='sequence';
11852: }
1.1055 raeburn 11853: }
11854: my @archdirs = &get_env_multiple('form.archive_directory');
11855: if ($numitems) {
11856: for (my $i=1; $i<=$numitems; $i++) {
11857: my $path = $env{'form.archive_content_'.$i};
11858: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11859: my $item = $1;
11860: $toplevelitems{$item} = $i;
11861: if (grep(/^\Q$i\E$/,@archdirs)) {
11862: $is_dir{$item} = 1;
11863: }
11864: }
11865: }
11866: }
1.1067 raeburn 11867: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11868: if (keys(%toplevelitems) > 0) {
11869: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11870: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11871: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11872: }
1.1066 raeburn 11873: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11874: if ($numitems) {
11875: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11876: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11877: my $path = $env{'form.archive_content_'.$i};
11878: if ($path =~ /^\Q$pathtocheck\E/) {
11879: if ($env{'form.archive_'.$i} eq 'discard') {
11880: if ($prefix ne '' && $path ne '') {
11881: if (-e $prefix.$path) {
1.1066 raeburn 11882: if ((@archdirs > 0) &&
11883: (grep(/^\Q$i\E$/,@archdirs))) {
11884: $todeletedir{$prefix.$path} = 1;
11885: } else {
11886: $todelete{$prefix.$path} = 1;
11887: }
1.1055 raeburn 11888: }
11889: }
11890: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11891: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11892: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11893: $docstitle = $env{'form.archive_title_'.$i};
11894: if ($docstitle eq '') {
11895: $docstitle = $title;
11896: }
1.1055 raeburn 11897: $outer = 0;
1.1056 raeburn 11898: if (ref($dirorder{$i}) eq 'ARRAY') {
11899: if (@{$dirorder{$i}} > 0) {
11900: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11901: if ($env{'form.archive_'.$item} eq 'display') {
11902: $outer = $item;
11903: last;
11904: }
11905: }
11906: }
11907: }
11908: my ($errtext,$fatal) =
11909: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11910: '/'.$folders{$outer}.'.'.
11911: $containers{$outer});
11912: next if ($fatal);
11913: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11914: if ($context eq 'coursedocs') {
1.1056 raeburn 11915: $mapinner{$i} = time;
1.1055 raeburn 11916: $folders{$i} = 'default_'.$mapinner{$i};
11917: $containers{$i} = 'sequence';
11918: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11919: $folders{$i}.'.'.$containers{$i};
11920: my $newidx = &LONCAPA::map::getresidx();
11921: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11922: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11923: push(@LONCAPA::map::order,$newidx);
11924: my ($outtext,$errtext) =
11925: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11926: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11927: '.'.$containers{$outer},1,1);
1.1056 raeburn 11928: $newseqid{$i} = $newidx;
1.1067 raeburn 11929: unless ($errtext) {
11930: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11931: }
1.1055 raeburn 11932: }
11933: } else {
11934: if ($context eq 'coursedocs') {
11935: my $newidx=&LONCAPA::map::getresidx();
11936: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11937: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11938: $title;
11939: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11940: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11941: }
11942: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11943: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11944: }
11945: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11946: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11947: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11948: unless ($ishome) {
11949: my $fetch = "$newdest{$i}/$title";
11950: $fetch =~ s/^\Q$prefix$dir\E//;
11951: $prompttofetch{$fetch} = 1;
11952: }
1.1055 raeburn 11953: }
11954: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11955: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11956: push(@LONCAPA::map::order, $newidx);
11957: my ($outtext,$errtext)=
11958: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11959: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11960: '.'.$containers{$outer},1,1);
1.1067 raeburn 11961: unless ($errtext) {
11962: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11963: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11964: }
11965: }
1.1055 raeburn 11966: }
11967: }
1.1086 raeburn 11968: }
11969: } else {
11970: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11971: }
11972: }
11973: for (my $i=1; $i<=$numitems; $i++) {
11974: next unless ($env{'form.archive_'.$i} eq 'dependency');
11975: my $path = $env{'form.archive_content_'.$i};
11976: if ($path =~ /^\Q$pathtocheck\E/) {
11977: my ($title) = ($path =~ m{/([^/]+)$});
11978: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11979: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11980: if (ref($dirorder{$i}) eq 'ARRAY') {
11981: my ($itemidx,$fullpath,$relpath);
11982: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11983: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11984: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11985: if ($dirorder{$i}->[$j] eq $container) {
11986: $itemidx = $j;
1.1056 raeburn 11987: }
11988: }
1.1086 raeburn 11989: }
11990: if ($itemidx eq '') {
11991: $itemidx = 0;
11992: }
11993: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11994: if ($mapinner{$referrer{$i}}) {
11995: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11996: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11997: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11998: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11999: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12000: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12001: if (!-e $fullpath) {
12002: mkdir($fullpath,0755);
1.1056 raeburn 12003: }
12004: }
1.1086 raeburn 12005: } else {
12006: last;
1.1056 raeburn 12007: }
1.1086 raeburn 12008: }
12009: }
12010: } elsif ($newdest{$referrer{$i}}) {
12011: $fullpath = $newdest{$referrer{$i}};
12012: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12013: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12014: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12015: last;
12016: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12017: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12018: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12019: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12020: if (!-e $fullpath) {
12021: mkdir($fullpath,0755);
1.1056 raeburn 12022: }
12023: }
1.1086 raeburn 12024: } else {
12025: last;
1.1056 raeburn 12026: }
1.1055 raeburn 12027: }
12028: }
1.1086 raeburn 12029: if ($fullpath ne '') {
12030: if (-e "$prefix$path") {
12031: system("mv $prefix$path $fullpath/$title");
12032: }
12033: if (-e "$fullpath/$title") {
12034: my $showpath;
12035: if ($relpath ne '') {
12036: $showpath = "$relpath/$title";
12037: } else {
12038: $showpath = "/$title";
12039: }
12040: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12041: }
12042: unless ($ishome) {
12043: my $fetch = "$fullpath/$title";
12044: $fetch =~ s/^\Q$prefix$dir\E//;
12045: $prompttofetch{$fetch} = 1;
12046: }
12047: }
1.1055 raeburn 12048: }
1.1086 raeburn 12049: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12050: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12051: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12052: }
12053: } else {
12054: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12055: }
12056: }
12057: if (keys(%todelete)) {
12058: foreach my $key (keys(%todelete)) {
12059: unlink($key);
1.1066 raeburn 12060: }
12061: }
12062: if (keys(%todeletedir)) {
12063: foreach my $key (keys(%todeletedir)) {
12064: rmdir($key);
12065: }
12066: }
12067: foreach my $dir (sort(keys(%is_dir))) {
12068: if (($pathtocheck ne '') && ($dir ne '')) {
12069: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12070: }
12071: }
1.1067 raeburn 12072: if ($result ne '') {
12073: $output .= '<ul>'."\n".
12074: $result."\n".
12075: '</ul>';
12076: }
12077: unless ($ishome) {
12078: my $replicationfail;
12079: foreach my $item (keys(%prompttofetch)) {
12080: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12081: unless ($fetchresult eq 'ok') {
12082: $replicationfail .= '<li>'.$item.'</li>'."\n";
12083: }
12084: }
12085: if ($replicationfail) {
12086: $output .= '<p class="LC_error">'.
12087: &mt('Course home server failed to retrieve:').'<ul>'.
12088: $replicationfail.
12089: '</ul></p>';
12090: }
12091: }
1.1055 raeburn 12092: } else {
12093: $warning = &mt('No items found in archive.');
12094: }
12095: if ($error) {
12096: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12097: $error.'</p>'."\n";
12098: }
12099: if ($warning) {
12100: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12101: }
12102: return $output;
12103: }
12104:
1.1066 raeburn 12105: sub cleanup_empty_dirs {
12106: my ($path) = @_;
12107: if (($path ne '') && (-d $path)) {
12108: if (opendir(my $dirh,$path)) {
12109: my @dircontents = grep(!/^\./,readdir($dirh));
12110: my $numitems = 0;
12111: foreach my $item (@dircontents) {
12112: if (-d "$path/$item") {
1.1111 raeburn 12113: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12114: if (-e "$path/$item") {
12115: $numitems ++;
12116: }
12117: } else {
12118: $numitems ++;
12119: }
12120: }
12121: if ($numitems == 0) {
12122: rmdir($path);
12123: }
12124: closedir($dirh);
12125: }
12126: }
12127: return;
12128: }
12129:
1.41 ng 12130: =pod
1.45 matthew 12131:
1.1162 raeburn 12132: =item * &get_folder_hierarchy()
1.1068 raeburn 12133:
12134: Provides hierarchy of names of folders/sub-folders containing the current
12135: item,
12136:
12137: Inputs: 3
12138: - $navmap - navmaps object
12139:
12140: - $map - url for map (either the trigger itself, or map containing
12141: the resource, which is the trigger).
12142:
12143: - $showitem - 1 => show title for map itself; 0 => do not show.
12144:
12145: Outputs: 1 @pathitems - array of folder/subfolder names.
12146:
12147: =cut
12148:
12149: sub get_folder_hierarchy {
12150: my ($navmap,$map,$showitem) = @_;
12151: my @pathitems;
12152: if (ref($navmap)) {
12153: my $mapres = $navmap->getResourceByUrl($map);
12154: if (ref($mapres)) {
12155: my $pcslist = $mapres->map_hierarchy();
12156: if ($pcslist ne '') {
12157: my @pcs = split(/,/,$pcslist);
12158: foreach my $pc (@pcs) {
12159: if ($pc == 1) {
1.1129 raeburn 12160: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12161: } else {
12162: my $res = $navmap->getByMapPc($pc);
12163: if (ref($res)) {
12164: my $title = $res->compTitle();
12165: $title =~ s/\W+/_/g;
12166: if ($title ne '') {
12167: push(@pathitems,$title);
12168: }
12169: }
12170: }
12171: }
12172: }
1.1071 raeburn 12173: if ($showitem) {
12174: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12175: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12176: } else {
12177: my $maptitle = $mapres->compTitle();
12178: $maptitle =~ s/\W+/_/g;
12179: if ($maptitle ne '') {
12180: push(@pathitems,$maptitle);
12181: }
1.1068 raeburn 12182: }
12183: }
12184: }
12185: }
12186: return @pathitems;
12187: }
12188:
12189: =pod
12190:
1.1015 raeburn 12191: =item * &get_turnedin_filepath()
12192:
12193: Determines path in a user's portfolio file for storage of files uploaded
12194: to a specific essayresponse or dropbox item.
12195:
12196: Inputs: 3 required + 1 optional.
12197: $symb is symb for resource, $uname and $udom are for current user (required).
12198: $caller is optional (can be "submission", if routine is called when storing
12199: an upoaded file when "Submit Answer" button was pressed).
12200:
12201: Returns array containing $path and $multiresp.
12202: $path is path in portfolio. $multiresp is 1 if this resource contains more
12203: than one file upload item. Callers of routine should append partid as a
12204: subdirectory to $path in cases where $multiresp is 1.
12205:
12206: Called by: homework/essayresponse.pm and homework/structuretags.pm
12207:
12208: =cut
12209:
12210: sub get_turnedin_filepath {
12211: my ($symb,$uname,$udom,$caller) = @_;
12212: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12213: my $turnindir;
12214: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12215: $turnindir = $userhash{'turnindir'};
12216: my ($path,$multiresp);
12217: if ($turnindir eq '') {
12218: if ($caller eq 'submission') {
12219: $turnindir = &mt('turned in');
12220: $turnindir =~ s/\W+/_/g;
12221: my %newhash = (
12222: 'turnindir' => $turnindir,
12223: );
12224: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12225: }
12226: }
12227: if ($turnindir ne '') {
12228: $path = '/'.$turnindir.'/';
12229: my ($multipart,$turnin,@pathitems);
12230: my $navmap = Apache::lonnavmaps::navmap->new();
12231: if (defined($navmap)) {
12232: my $mapres = $navmap->getResourceByUrl($map);
12233: if (ref($mapres)) {
12234: my $pcslist = $mapres->map_hierarchy();
12235: if ($pcslist ne '') {
12236: foreach my $pc (split(/,/,$pcslist)) {
12237: my $res = $navmap->getByMapPc($pc);
12238: if (ref($res)) {
12239: my $title = $res->compTitle();
12240: $title =~ s/\W+/_/g;
12241: if ($title ne '') {
1.1149 raeburn 12242: if (($pc > 1) && (length($title) > 12)) {
12243: $title = substr($title,0,12);
12244: }
1.1015 raeburn 12245: push(@pathitems,$title);
12246: }
12247: }
12248: }
12249: }
12250: my $maptitle = $mapres->compTitle();
12251: $maptitle =~ s/\W+/_/g;
12252: if ($maptitle ne '') {
1.1149 raeburn 12253: if (length($maptitle) > 12) {
12254: $maptitle = substr($maptitle,0,12);
12255: }
1.1015 raeburn 12256: push(@pathitems,$maptitle);
12257: }
12258: unless ($env{'request.state'} eq 'construct') {
12259: my $res = $navmap->getBySymb($symb);
12260: if (ref($res)) {
12261: my $partlist = $res->parts();
12262: my $totaluploads = 0;
12263: if (ref($partlist) eq 'ARRAY') {
12264: foreach my $part (@{$partlist}) {
12265: my @types = $res->responseType($part);
12266: my @ids = $res->responseIds($part);
12267: for (my $i=0; $i < scalar(@ids); $i++) {
12268: if ($types[$i] eq 'essay') {
12269: my $partid = $part.'_'.$ids[$i];
12270: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12271: $totaluploads ++;
12272: }
12273: }
12274: }
12275: }
12276: if ($totaluploads > 1) {
12277: $multiresp = 1;
12278: }
12279: }
12280: }
12281: }
12282: } else {
12283: return;
12284: }
12285: } else {
12286: return;
12287: }
12288: my $restitle=&Apache::lonnet::gettitle($symb);
12289: $restitle =~ s/\W+/_/g;
12290: if ($restitle eq '') {
12291: $restitle = ($resurl =~ m{/[^/]+$});
12292: if ($restitle eq '') {
12293: $restitle = time;
12294: }
12295: }
1.1149 raeburn 12296: if (length($restitle) > 12) {
12297: $restitle = substr($restitle,0,12);
12298: }
1.1015 raeburn 12299: push(@pathitems,$restitle);
12300: $path .= join('/',@pathitems);
12301: }
12302: return ($path,$multiresp);
12303: }
12304:
12305: =pod
12306:
1.464 albertel 12307: =back
1.41 ng 12308:
1.112 bowersj2 12309: =head1 CSV Upload/Handling functions
1.38 albertel 12310:
1.41 ng 12311: =over 4
12312:
1.648 raeburn 12313: =item * &upfile_store($r)
1.41 ng 12314:
12315: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12316: needs $env{'form.upfile'}
1.41 ng 12317: returns $datatoken to be put into hidden field
12318:
12319: =cut
1.31 albertel 12320:
12321: sub upfile_store {
12322: my $r=shift;
1.258 albertel 12323: $env{'form.upfile'}=~s/\r/\n/gs;
12324: $env{'form.upfile'}=~s/\f/\n/gs;
12325: $env{'form.upfile'}=~s/\n+/\n/gs;
12326: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12327:
1.258 albertel 12328: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12329: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12330: {
1.158 raeburn 12331: my $datafile = $r->dir_config('lonDaemons').
12332: '/tmp/'.$datatoken.'.tmp';
12333: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12334: print $fh $env{'form.upfile'};
1.158 raeburn 12335: close($fh);
12336: }
1.31 albertel 12337: }
12338: return $datatoken;
12339: }
12340:
1.56 matthew 12341: =pod
12342:
1.648 raeburn 12343: =item * &load_tmp_file($r)
1.41 ng 12344:
12345: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12346: needs $env{'form.datatoken'},
12347: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12348:
12349: =cut
1.31 albertel 12350:
12351: sub load_tmp_file {
12352: my $r=shift;
12353: my @studentdata=();
12354: {
1.158 raeburn 12355: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12356: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12357: if ( open(my $fh,"<$studentfile") ) {
12358: @studentdata=<$fh>;
12359: close($fh);
12360: }
1.31 albertel 12361: }
1.258 albertel 12362: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12363: }
12364:
1.56 matthew 12365: =pod
12366:
1.648 raeburn 12367: =item * &upfile_record_sep()
1.41 ng 12368:
12369: Separate uploaded file into records
12370: returns array of records,
1.258 albertel 12371: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12372:
12373: =cut
1.31 albertel 12374:
12375: sub upfile_record_sep {
1.258 albertel 12376: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12377: } else {
1.248 albertel 12378: my @records;
1.258 albertel 12379: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12380: if ($line=~/^\s*$/) { next; }
12381: push(@records,$line);
12382: }
12383: return @records;
1.31 albertel 12384: }
12385: }
12386:
1.56 matthew 12387: =pod
12388:
1.648 raeburn 12389: =item * &record_sep($record)
1.41 ng 12390:
1.258 albertel 12391: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12392:
12393: =cut
12394:
1.263 www 12395: sub takeleft {
12396: my $index=shift;
12397: return substr('0000'.$index,-4,4);
12398: }
12399:
1.31 albertel 12400: sub record_sep {
12401: my $record=shift;
12402: my %components=();
1.258 albertel 12403: if ($env{'form.upfiletype'} eq 'xml') {
12404: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12405: my $i=0;
1.356 albertel 12406: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12407: $field=~s/^(\"|\')//;
12408: $field=~s/(\"|\')$//;
1.263 www 12409: $components{&takeleft($i)}=$field;
1.31 albertel 12410: $i++;
12411: }
1.258 albertel 12412: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12413: my $i=0;
1.356 albertel 12414: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12415: $field=~s/^(\"|\')//;
12416: $field=~s/(\"|\')$//;
1.263 www 12417: $components{&takeleft($i)}=$field;
1.31 albertel 12418: $i++;
12419: }
12420: } else {
1.561 www 12421: my $separator=',';
1.480 banghart 12422: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12423: $separator=';';
1.480 banghart 12424: }
1.31 albertel 12425: my $i=0;
1.561 www 12426: # the character we are looking for to indicate the end of a quote or a record
12427: my $looking_for=$separator;
12428: # do not add the characters to the fields
12429: my $ignore=0;
12430: # we just encountered a separator (or the beginning of the record)
12431: my $just_found_separator=1;
12432: # store the field we are working on here
12433: my $field='';
12434: # work our way through all characters in record
12435: foreach my $character ($record=~/(.)/g) {
12436: if ($character eq $looking_for) {
12437: if ($character ne $separator) {
12438: # Found the end of a quote, again looking for separator
12439: $looking_for=$separator;
12440: $ignore=1;
12441: } else {
12442: # Found a separator, store away what we got
12443: $components{&takeleft($i)}=$field;
12444: $i++;
12445: $just_found_separator=1;
12446: $ignore=0;
12447: $field='';
12448: }
12449: next;
12450: }
12451: # single or double quotation marks after a separator indicate beginning of a quote
12452: # we are now looking for the end of the quote and need to ignore separators
12453: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12454: $looking_for=$character;
12455: next;
12456: }
12457: # ignore would be true after we reached the end of a quote
12458: if ($ignore) { next; }
12459: if (($just_found_separator) && ($character=~/\s/)) { next; }
12460: $field.=$character;
12461: $just_found_separator=0;
1.31 albertel 12462: }
1.561 www 12463: # catch the very last entry, since we never encountered the separator
12464: $components{&takeleft($i)}=$field;
1.31 albertel 12465: }
12466: return %components;
12467: }
12468:
1.144 matthew 12469: ######################################################
12470: ######################################################
12471:
1.56 matthew 12472: =pod
12473:
1.648 raeburn 12474: =item * &upfile_select_html()
1.41 ng 12475:
1.144 matthew 12476: Return HTML code to select a file from the users machine and specify
12477: the file type.
1.41 ng 12478:
12479: =cut
12480:
1.144 matthew 12481: ######################################################
12482: ######################################################
1.31 albertel 12483: sub upfile_select_html {
1.144 matthew 12484: my %Types = (
12485: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12486: semisv => &mt('Semicolon separated values'),
1.144 matthew 12487: space => &mt('Space separated'),
12488: tab => &mt('Tabulator separated'),
12489: # xml => &mt('HTML/XML'),
12490: );
12491: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12492: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12493: foreach my $type (sort(keys(%Types))) {
12494: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12495: }
12496: $Str .= "</select>\n";
12497: return $Str;
1.31 albertel 12498: }
12499:
1.301 albertel 12500: sub get_samples {
12501: my ($records,$toget) = @_;
12502: my @samples=({});
12503: my $got=0;
12504: foreach my $rec (@$records) {
12505: my %temp = &record_sep($rec);
12506: if (! grep(/\S/, values(%temp))) { next; }
12507: if (%temp) {
12508: $samples[$got]=\%temp;
12509: $got++;
12510: if ($got == $toget) { last; }
12511: }
12512: }
12513: return \@samples;
12514: }
12515:
1.144 matthew 12516: ######################################################
12517: ######################################################
12518:
1.56 matthew 12519: =pod
12520:
1.648 raeburn 12521: =item * &csv_print_samples($r,$records)
1.41 ng 12522:
12523: Prints a table of sample values from each column uploaded $r is an
12524: Apache Request ref, $records is an arrayref from
12525: &Apache::loncommon::upfile_record_sep
12526:
12527: =cut
12528:
1.144 matthew 12529: ######################################################
12530: ######################################################
1.31 albertel 12531: sub csv_print_samples {
12532: my ($r,$records) = @_;
1.662 bisitz 12533: my $samples = &get_samples($records,5);
1.301 albertel 12534:
1.594 raeburn 12535: $r->print(&mt('Samples').'<br />'.&start_data_table().
12536: &start_data_table_header_row());
1.356 albertel 12537: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12538: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12539: $r->print(&end_data_table_header_row());
1.301 albertel 12540: foreach my $hash (@$samples) {
1.594 raeburn 12541: $r->print(&start_data_table_row());
1.356 albertel 12542: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12543: $r->print('<td>');
1.356 albertel 12544: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12545: $r->print('</td>');
12546: }
1.594 raeburn 12547: $r->print(&end_data_table_row());
1.31 albertel 12548: }
1.594 raeburn 12549: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12550: }
12551:
1.144 matthew 12552: ######################################################
12553: ######################################################
12554:
1.56 matthew 12555: =pod
12556:
1.648 raeburn 12557: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12558:
12559: Prints a table to create associations between values and table columns.
1.144 matthew 12560:
1.41 ng 12561: $r is an Apache Request ref,
12562: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12563: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12564:
12565: =cut
12566:
1.144 matthew 12567: ######################################################
12568: ######################################################
1.31 albertel 12569: sub csv_print_select_table {
12570: my ($r,$records,$d) = @_;
1.301 albertel 12571: my $i=0;
12572: my $samples = &get_samples($records,1);
1.144 matthew 12573: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12574: &start_data_table().&start_data_table_header_row().
1.144 matthew 12575: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12576: '<th>'.&mt('Column').'</th>'.
12577: &end_data_table_header_row()."\n");
1.356 albertel 12578: foreach my $array_ref (@$d) {
12579: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12580: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12581:
1.875 bisitz 12582: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12583: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12584: $r->print('<option value="none"></option>');
1.356 albertel 12585: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12586: $r->print('<option value="'.$sample.'"'.
12587: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12588: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12589: }
1.594 raeburn 12590: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12591: $i++;
12592: }
1.594 raeburn 12593: $r->print(&end_data_table());
1.31 albertel 12594: $i--;
12595: return $i;
12596: }
1.56 matthew 12597:
1.144 matthew 12598: ######################################################
12599: ######################################################
12600:
1.56 matthew 12601: =pod
1.31 albertel 12602:
1.648 raeburn 12603: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12604:
12605: Prints a table of sample values from the upload and can make associate samples to internal names.
12606:
12607: $r is an Apache Request ref,
12608: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12609: $d is an array of 2 element arrays (internal name, displayed name)
12610:
12611: =cut
12612:
1.144 matthew 12613: ######################################################
12614: ######################################################
1.31 albertel 12615: sub csv_samples_select_table {
12616: my ($r,$records,$d) = @_;
12617: my $i=0;
1.144 matthew 12618: #
1.662 bisitz 12619: my $max_samples = 5;
12620: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12621: $r->print(&start_data_table().
12622: &start_data_table_header_row().'<th>'.
12623: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12624: &end_data_table_header_row());
1.301 albertel 12625:
12626: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12627: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12628: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12629: foreach my $option (@$d) {
12630: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12631: $r->print('<option value="'.$value.'"'.
1.253 albertel 12632: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12633: $display.'</option>');
1.31 albertel 12634: }
12635: $r->print('</select></td><td>');
1.662 bisitz 12636: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12637: if (defined($samples->[$line]{$key})) {
12638: $r->print($samples->[$line]{$key}."<br />\n");
12639: }
12640: }
1.594 raeburn 12641: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12642: $i++;
12643: }
1.594 raeburn 12644: $r->print(&end_data_table());
1.31 albertel 12645: $i--;
12646: return($i);
1.115 matthew 12647: }
12648:
1.144 matthew 12649: ######################################################
12650: ######################################################
12651:
1.115 matthew 12652: =pod
12653:
1.648 raeburn 12654: =item * &clean_excel_name($name)
1.115 matthew 12655:
12656: Returns a replacement for $name which does not contain any illegal characters.
12657:
12658: =cut
12659:
1.144 matthew 12660: ######################################################
12661: ######################################################
1.115 matthew 12662: sub clean_excel_name {
12663: my ($name) = @_;
12664: $name =~ s/[:\*\?\/\\]//g;
12665: if (length($name) > 31) {
12666: $name = substr($name,0,31);
12667: }
12668: return $name;
1.25 albertel 12669: }
1.84 albertel 12670:
1.85 albertel 12671: =pod
12672:
1.648 raeburn 12673: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12674:
12675: Returns either 1 or undef
12676:
12677: 1 if the part is to be hidden, undef if it is to be shown
12678:
12679: Arguments are:
12680:
12681: $id the id of the part to be checked
12682: $symb, optional the symb of the resource to check
12683: $udom, optional the domain of the user to check for
12684: $uname, optional the username of the user to check for
12685:
12686: =cut
1.84 albertel 12687:
12688: sub check_if_partid_hidden {
12689: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12690: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12691: $symb,$udom,$uname);
1.141 albertel 12692: my $truth=1;
12693: #if the string starts with !, then the list is the list to show not hide
12694: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12695: my @hiddenlist=split(/,/,$hiddenparts);
12696: foreach my $checkid (@hiddenlist) {
1.141 albertel 12697: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12698: }
1.141 albertel 12699: return !$truth;
1.84 albertel 12700: }
1.127 matthew 12701:
1.138 matthew 12702:
12703: ############################################################
12704: ############################################################
12705:
12706: =pod
12707:
1.157 matthew 12708: =back
12709:
1.138 matthew 12710: =head1 cgi-bin script and graphing routines
12711:
1.157 matthew 12712: =over 4
12713:
1.648 raeburn 12714: =item * &get_cgi_id()
1.138 matthew 12715:
12716: Inputs: none
12717:
12718: Returns an id which can be used to pass environment variables
12719: to various cgi-bin scripts. These environment variables will
12720: be removed from the users environment after a given time by
12721: the routine &Apache::lonnet::transfer_profile_to_env.
12722:
12723: =cut
12724:
12725: ############################################################
12726: ############################################################
1.152 albertel 12727: my $uniq=0;
1.136 matthew 12728: sub get_cgi_id {
1.154 albertel 12729: $uniq=($uniq+1)%100000;
1.280 albertel 12730: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12731: }
12732:
1.127 matthew 12733: ############################################################
12734: ############################################################
12735:
12736: =pod
12737:
1.648 raeburn 12738: =item * &DrawBarGraph()
1.127 matthew 12739:
1.138 matthew 12740: Facilitates the plotting of data in a (stacked) bar graph.
12741: Puts plot definition data into the users environment in order for
12742: graph.png to plot it. Returns an <img> tag for the plot.
12743: The bars on the plot are labeled '1','2',...,'n'.
12744:
12745: Inputs:
12746:
12747: =over 4
12748:
12749: =item $Title: string, the title of the plot
12750:
12751: =item $xlabel: string, text describing the X-axis of the plot
12752:
12753: =item $ylabel: string, text describing the Y-axis of the plot
12754:
12755: =item $Max: scalar, the maximum Y value to use in the plot
12756: If $Max is < any data point, the graph will not be rendered.
12757:
1.140 matthew 12758: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12759: they are plotted. If undefined, default values will be used.
12760:
1.178 matthew 12761: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12762:
1.138 matthew 12763: =item @Values: An array of array references. Each array reference holds data
12764: to be plotted in a stacked bar chart.
12765:
1.239 matthew 12766: =item If the final element of @Values is a hash reference the key/value
12767: pairs will be added to the graph definition.
12768:
1.138 matthew 12769: =back
12770:
12771: Returns:
12772:
12773: An <img> tag which references graph.png and the appropriate identifying
12774: information for the plot.
12775:
1.127 matthew 12776: =cut
12777:
12778: ############################################################
12779: ############################################################
1.134 matthew 12780: sub DrawBarGraph {
1.178 matthew 12781: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12782: #
12783: if (! defined($colors)) {
12784: $colors = ['#33ff00',
12785: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12786: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12787: ];
12788: }
1.228 matthew 12789: my $extra_settings = {};
12790: if (ref($Values[-1]) eq 'HASH') {
12791: $extra_settings = pop(@Values);
12792: }
1.127 matthew 12793: #
1.136 matthew 12794: my $identifier = &get_cgi_id();
12795: my $id = 'cgi.'.$identifier;
1.129 matthew 12796: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12797: return '';
12798: }
1.225 matthew 12799: #
12800: my @Labels;
12801: if (defined($labels)) {
12802: @Labels = @$labels;
12803: } else {
12804: for (my $i=0;$i<@{$Values[0]};$i++) {
12805: push (@Labels,$i+1);
12806: }
12807: }
12808: #
1.129 matthew 12809: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12810: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12811: my %ValuesHash;
12812: my $NumSets=1;
12813: foreach my $array (@Values) {
12814: next if (! ref($array));
1.136 matthew 12815: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12816: join(',',@$array);
1.129 matthew 12817: }
1.127 matthew 12818: #
1.136 matthew 12819: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12820: if ($NumBars < 3) {
12821: $width = 120+$NumBars*32;
1.220 matthew 12822: $xskip = 1;
1.225 matthew 12823: $bar_width = 30;
12824: } elsif ($NumBars < 5) {
12825: $width = 120+$NumBars*20;
12826: $xskip = 1;
12827: $bar_width = 20;
1.220 matthew 12828: } elsif ($NumBars < 10) {
1.136 matthew 12829: $width = 120+$NumBars*15;
12830: $xskip = 1;
12831: $bar_width = 15;
12832: } elsif ($NumBars <= 25) {
12833: $width = 120+$NumBars*11;
12834: $xskip = 5;
12835: $bar_width = 8;
12836: } elsif ($NumBars <= 50) {
12837: $width = 120+$NumBars*8;
12838: $xskip = 5;
12839: $bar_width = 4;
12840: } else {
12841: $width = 120+$NumBars*8;
12842: $xskip = 5;
12843: $bar_width = 4;
12844: }
12845: #
1.137 matthew 12846: $Max = 1 if ($Max < 1);
12847: if ( int($Max) < $Max ) {
12848: $Max++;
12849: $Max = int($Max);
12850: }
1.127 matthew 12851: $Title = '' if (! defined($Title));
12852: $xlabel = '' if (! defined($xlabel));
12853: $ylabel = '' if (! defined($ylabel));
1.369 www 12854: $ValuesHash{$id.'.title'} = &escape($Title);
12855: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12856: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12857: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12858: $ValuesHash{$id.'.NumBars'} = $NumBars;
12859: $ValuesHash{$id.'.NumSets'} = $NumSets;
12860: $ValuesHash{$id.'.PlotType'} = 'bar';
12861: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12862: $ValuesHash{$id.'.height'} = $height;
12863: $ValuesHash{$id.'.width'} = $width;
12864: $ValuesHash{$id.'.xskip'} = $xskip;
12865: $ValuesHash{$id.'.bar_width'} = $bar_width;
12866: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12867: #
1.228 matthew 12868: # Deal with other parameters
12869: while (my ($key,$value) = each(%$extra_settings)) {
12870: $ValuesHash{$id.'.'.$key} = $value;
12871: }
12872: #
1.646 raeburn 12873: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12874: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12875: }
12876:
12877: ############################################################
12878: ############################################################
12879:
12880: =pod
12881:
1.648 raeburn 12882: =item * &DrawXYGraph()
1.137 matthew 12883:
1.138 matthew 12884: Facilitates the plotting of data in an XY graph.
12885: Puts plot definition data into the users environment in order for
12886: graph.png to plot it. Returns an <img> tag for the plot.
12887:
12888: Inputs:
12889:
12890: =over 4
12891:
12892: =item $Title: string, the title of the plot
12893:
12894: =item $xlabel: string, text describing the X-axis of the plot
12895:
12896: =item $ylabel: string, text describing the Y-axis of the plot
12897:
12898: =item $Max: scalar, the maximum Y value to use in the plot
12899: If $Max is < any data point, the graph will not be rendered.
12900:
12901: =item $colors: Array ref containing the hex color codes for the data to be
12902: plotted in. If undefined, default values will be used.
12903:
12904: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12905:
12906: =item $Ydata: Array ref containing Array refs.
1.185 www 12907: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12908:
12909: =item %Values: hash indicating or overriding any default values which are
12910: passed to graph.png.
12911: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12912:
12913: =back
12914:
12915: Returns:
12916:
12917: An <img> tag which references graph.png and the appropriate identifying
12918: information for the plot.
12919:
1.137 matthew 12920: =cut
12921:
12922: ############################################################
12923: ############################################################
12924: sub DrawXYGraph {
12925: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12926: #
12927: # Create the identifier for the graph
12928: my $identifier = &get_cgi_id();
12929: my $id = 'cgi.'.$identifier;
12930: #
12931: $Title = '' if (! defined($Title));
12932: $xlabel = '' if (! defined($xlabel));
12933: $ylabel = '' if (! defined($ylabel));
12934: my %ValuesHash =
12935: (
1.369 www 12936: $id.'.title' => &escape($Title),
12937: $id.'.xlabel' => &escape($xlabel),
12938: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12939: $id.'.y_max_value'=> $Max,
12940: $id.'.labels' => join(',',@$Xlabels),
12941: $id.'.PlotType' => 'XY',
12942: );
12943: #
12944: if (defined($colors) && ref($colors) eq 'ARRAY') {
12945: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12946: }
12947: #
12948: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12949: return '';
12950: }
12951: my $NumSets=1;
1.138 matthew 12952: foreach my $array (@{$Ydata}){
1.137 matthew 12953: next if (! ref($array));
12954: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12955: }
1.138 matthew 12956: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12957: #
12958: # Deal with other parameters
12959: while (my ($key,$value) = each(%Values)) {
12960: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12961: }
12962: #
1.646 raeburn 12963: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12964: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12965: }
12966:
12967: ############################################################
12968: ############################################################
12969:
12970: =pod
12971:
1.648 raeburn 12972: =item * &DrawXYYGraph()
1.138 matthew 12973:
12974: Facilitates the plotting of data in an XY graph with two Y axes.
12975: Puts plot definition data into the users environment in order for
12976: graph.png to plot it. Returns an <img> tag for the plot.
12977:
12978: Inputs:
12979:
12980: =over 4
12981:
12982: =item $Title: string, the title of the plot
12983:
12984: =item $xlabel: string, text describing the X-axis of the plot
12985:
12986: =item $ylabel: string, text describing the Y-axis of the plot
12987:
12988: =item $colors: Array ref containing the hex color codes for the data to be
12989: plotted in. If undefined, default values will be used.
12990:
12991: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12992:
12993: =item $Ydata1: The first data set
12994:
12995: =item $Min1: The minimum value of the left Y-axis
12996:
12997: =item $Max1: The maximum value of the left Y-axis
12998:
12999: =item $Ydata2: The second data set
13000:
13001: =item $Min2: The minimum value of the right Y-axis
13002:
13003: =item $Max2: The maximum value of the left Y-axis
13004:
13005: =item %Values: hash indicating or overriding any default values which are
13006: passed to graph.png.
13007: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13008:
13009: =back
13010:
13011: Returns:
13012:
13013: An <img> tag which references graph.png and the appropriate identifying
13014: information for the plot.
1.136 matthew 13015:
13016: =cut
13017:
13018: ############################################################
13019: ############################################################
1.137 matthew 13020: sub DrawXYYGraph {
13021: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13022: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13023: #
13024: # Create the identifier for the graph
13025: my $identifier = &get_cgi_id();
13026: my $id = 'cgi.'.$identifier;
13027: #
13028: $Title = '' if (! defined($Title));
13029: $xlabel = '' if (! defined($xlabel));
13030: $ylabel = '' if (! defined($ylabel));
13031: my %ValuesHash =
13032: (
1.369 www 13033: $id.'.title' => &escape($Title),
13034: $id.'.xlabel' => &escape($xlabel),
13035: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13036: $id.'.labels' => join(',',@$Xlabels),
13037: $id.'.PlotType' => 'XY',
13038: $id.'.NumSets' => 2,
1.137 matthew 13039: $id.'.two_axes' => 1,
13040: $id.'.y1_max_value' => $Max1,
13041: $id.'.y1_min_value' => $Min1,
13042: $id.'.y2_max_value' => $Max2,
13043: $id.'.y2_min_value' => $Min2,
1.136 matthew 13044: );
13045: #
1.137 matthew 13046: if (defined($colors) && ref($colors) eq 'ARRAY') {
13047: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13048: }
13049: #
13050: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13051: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13052: return '';
13053: }
13054: my $NumSets=1;
1.137 matthew 13055: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13056: next if (! ref($array));
13057: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13058: }
13059: #
13060: # Deal with other parameters
13061: while (my ($key,$value) = each(%Values)) {
13062: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13063: }
13064: #
1.646 raeburn 13065: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13066: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13067: }
13068:
13069: ############################################################
13070: ############################################################
13071:
13072: =pod
13073:
1.157 matthew 13074: =back
13075:
1.139 matthew 13076: =head1 Statistics helper routines?
13077:
13078: Bad place for them but what the hell.
13079:
1.157 matthew 13080: =over 4
13081:
1.648 raeburn 13082: =item * &chartlink()
1.139 matthew 13083:
13084: Returns a link to the chart for a specific student.
13085:
13086: Inputs:
13087:
13088: =over 4
13089:
13090: =item $linktext: The text of the link
13091:
13092: =item $sname: The students username
13093:
13094: =item $sdomain: The students domain
13095:
13096: =back
13097:
1.157 matthew 13098: =back
13099:
1.139 matthew 13100: =cut
13101:
13102: ############################################################
13103: ############################################################
13104: sub chartlink {
13105: my ($linktext, $sname, $sdomain) = @_;
13106: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13107: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13108: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13109: '">'.$linktext.'</a>';
1.153 matthew 13110: }
13111:
13112: #######################################################
13113: #######################################################
13114:
13115: =pod
13116:
13117: =head1 Course Environment Routines
1.157 matthew 13118:
13119: =over 4
1.153 matthew 13120:
1.648 raeburn 13121: =item * &restore_course_settings()
1.153 matthew 13122:
1.648 raeburn 13123: =item * &store_course_settings()
1.153 matthew 13124:
13125: Restores/Store indicated form parameters from the course environment.
13126: Will not overwrite existing values of the form parameters.
13127:
13128: Inputs:
13129: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13130:
13131: a hash ref describing the data to be stored. For example:
13132:
13133: %Save_Parameters = ('Status' => 'scalar',
13134: 'chartoutputmode' => 'scalar',
13135: 'chartoutputdata' => 'scalar',
13136: 'Section' => 'array',
1.373 raeburn 13137: 'Group' => 'array',
1.153 matthew 13138: 'StudentData' => 'array',
13139: 'Maps' => 'array');
13140:
13141: Returns: both routines return nothing
13142:
1.631 raeburn 13143: =back
13144:
1.153 matthew 13145: =cut
13146:
13147: #######################################################
13148: #######################################################
13149: sub store_course_settings {
1.496 albertel 13150: return &store_settings($env{'request.course.id'},@_);
13151: }
13152:
13153: sub store_settings {
1.153 matthew 13154: # save to the environment
13155: # appenv the same items, just to be safe
1.300 albertel 13156: my $udom = $env{'user.domain'};
13157: my $uname = $env{'user.name'};
1.496 albertel 13158: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13159: my %SaveHash;
13160: my %AppHash;
13161: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13162: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13163: my $envname = 'environment.'.$basename;
1.258 albertel 13164: if (exists($env{'form.'.$setting})) {
1.153 matthew 13165: # Save this value away
13166: if ($type eq 'scalar' &&
1.258 albertel 13167: (! exists($env{$envname}) ||
13168: $env{$envname} ne $env{'form.'.$setting})) {
13169: $SaveHash{$basename} = $env{'form.'.$setting};
13170: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13171: } elsif ($type eq 'array') {
13172: my $stored_form;
1.258 albertel 13173: if (ref($env{'form.'.$setting})) {
1.153 matthew 13174: $stored_form = join(',',
13175: map {
1.369 www 13176: &escape($_);
1.258 albertel 13177: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13178: } else {
13179: $stored_form =
1.369 www 13180: &escape($env{'form.'.$setting});
1.153 matthew 13181: }
13182: # Determine if the array contents are the same.
1.258 albertel 13183: if ($stored_form ne $env{$envname}) {
1.153 matthew 13184: $SaveHash{$basename} = $stored_form;
13185: $AppHash{$envname} = $stored_form;
13186: }
13187: }
13188: }
13189: }
13190: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13191: $udom,$uname);
1.153 matthew 13192: if ($put_result !~ /^(ok|delayed)/) {
13193: &Apache::lonnet::logthis('unable to save form parameters, '.
13194: 'got error:'.$put_result);
13195: }
13196: # Make sure these settings stick around in this session, too
1.646 raeburn 13197: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13198: return;
13199: }
13200:
13201: sub restore_course_settings {
1.499 albertel 13202: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13203: }
13204:
13205: sub restore_settings {
13206: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13207: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13208: next if (exists($env{'form.'.$setting}));
1.496 albertel 13209: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13210: '.'.$setting;
1.258 albertel 13211: if (exists($env{$envname})) {
1.153 matthew 13212: if ($type eq 'scalar') {
1.258 albertel 13213: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13214: } elsif ($type eq 'array') {
1.258 albertel 13215: $env{'form.'.$setting} = [
1.153 matthew 13216: map {
1.369 www 13217: &unescape($_);
1.258 albertel 13218: } split(',',$env{$envname})
1.153 matthew 13219: ];
13220: }
13221: }
13222: }
1.127 matthew 13223: }
13224:
1.618 raeburn 13225: #######################################################
13226: #######################################################
13227:
13228: =pod
13229:
13230: =head1 Domain E-mail Routines
13231:
13232: =over 4
13233:
1.648 raeburn 13234: =item * &build_recipient_list()
1.618 raeburn 13235:
1.1144 raeburn 13236: Build recipient lists for following types of e-mail:
1.766 raeburn 13237: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13238: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13239: module change checking, student/employee ID conflict checks, as
13240: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13241: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13242:
13243: Inputs:
1.619 raeburn 13244: defmail (scalar - email address of default recipient),
1.1144 raeburn 13245: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13246: requestsmail, updatesmail, or idconflictsmail).
13247:
1.619 raeburn 13248: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13249:
1.619 raeburn 13250: origmail (scalar - email address of recipient from loncapa.conf,
13251: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13252:
1.655 raeburn 13253: Returns: comma separated list of addresses to which to send e-mail.
13254:
13255: =back
1.618 raeburn 13256:
13257: =cut
13258:
13259: ############################################################
13260: ############################################################
13261: sub build_recipient_list {
1.619 raeburn 13262: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13263: my @recipients;
13264: my $otheremails;
13265: my %domconfig =
13266: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13267: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13268: if (exists($domconfig{'contacts'}{$mailing})) {
13269: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13270: my @contacts = ('adminemail','supportemail');
13271: foreach my $item (@contacts) {
13272: if ($domconfig{'contacts'}{$mailing}{$item}) {
13273: my $addr = $domconfig{'contacts'}{$item};
13274: if (!grep(/^\Q$addr\E$/,@recipients)) {
13275: push(@recipients,$addr);
13276: }
1.619 raeburn 13277: }
1.766 raeburn 13278: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13279: }
13280: }
1.766 raeburn 13281: } elsif ($origmail ne '') {
13282: push(@recipients,$origmail);
1.618 raeburn 13283: }
1.619 raeburn 13284: } elsif ($origmail ne '') {
13285: push(@recipients,$origmail);
1.618 raeburn 13286: }
1.688 raeburn 13287: if (defined($defmail)) {
13288: if ($defmail ne '') {
13289: push(@recipients,$defmail);
13290: }
1.618 raeburn 13291: }
13292: if ($otheremails) {
1.619 raeburn 13293: my @others;
13294: if ($otheremails =~ /,/) {
13295: @others = split(/,/,$otheremails);
1.618 raeburn 13296: } else {
1.619 raeburn 13297: push(@others,$otheremails);
13298: }
13299: foreach my $addr (@others) {
13300: if (!grep(/^\Q$addr\E$/,@recipients)) {
13301: push(@recipients,$addr);
13302: }
1.618 raeburn 13303: }
13304: }
1.619 raeburn 13305: my $recipientlist = join(',',@recipients);
1.618 raeburn 13306: return $recipientlist;
13307: }
13308:
1.127 matthew 13309: ############################################################
13310: ############################################################
1.154 albertel 13311:
1.655 raeburn 13312: =pod
13313:
13314: =head1 Course Catalog Routines
13315:
13316: =over 4
13317:
13318: =item * &gather_categories()
13319:
13320: Converts category definitions - keys of categories hash stored in
13321: coursecategories in configuration.db on the primary library server in a
13322: domain - to an array. Also generates javascript and idx hash used to
13323: generate Domain Coordinator interface for editing Course Categories.
13324:
13325: Inputs:
1.663 raeburn 13326:
1.655 raeburn 13327: categories (reference to hash of category definitions).
1.663 raeburn 13328:
1.655 raeburn 13329: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13330: categories and subcategories).
1.663 raeburn 13331:
1.655 raeburn 13332: idx (reference to hash of counters used in Domain Coordinator interface for
13333: editing Course Categories).
1.663 raeburn 13334:
1.655 raeburn 13335: jsarray (reference to array of categories used to create Javascript arrays for
13336: Domain Coordinator interface for editing Course Categories).
13337:
13338: Returns: nothing
13339:
13340: Side effects: populates cats, idx and jsarray.
13341:
13342: =cut
13343:
13344: sub gather_categories {
13345: my ($categories,$cats,$idx,$jsarray) = @_;
13346: my %counters;
13347: my $num = 0;
13348: foreach my $item (keys(%{$categories})) {
13349: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13350: if ($container eq '' && $depth == 0) {
13351: $cats->[$depth][$categories->{$item}] = $cat;
13352: } else {
13353: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13354: }
13355: my ($escitem,$tail) = split(/:/,$item,2);
13356: if ($counters{$tail} eq '') {
13357: $counters{$tail} = $num;
13358: $num ++;
13359: }
13360: if (ref($idx) eq 'HASH') {
13361: $idx->{$item} = $counters{$tail};
13362: }
13363: if (ref($jsarray) eq 'ARRAY') {
13364: push(@{$jsarray->[$counters{$tail}]},$item);
13365: }
13366: }
13367: return;
13368: }
13369:
13370: =pod
13371:
13372: =item * &extract_categories()
13373:
13374: Used to generate breadcrumb trails for course categories.
13375:
13376: Inputs:
1.663 raeburn 13377:
1.655 raeburn 13378: categories (reference to hash of category definitions).
1.663 raeburn 13379:
1.655 raeburn 13380: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13381: categories and subcategories).
1.663 raeburn 13382:
1.655 raeburn 13383: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13384:
1.655 raeburn 13385: allitems (reference to hash - key is category key
13386: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13387:
1.655 raeburn 13388: idx (reference to hash of counters used in Domain Coordinator interface for
13389: editing Course Categories).
1.663 raeburn 13390:
1.655 raeburn 13391: jsarray (reference to array of categories used to create Javascript arrays for
13392: Domain Coordinator interface for editing Course Categories).
13393:
1.665 raeburn 13394: subcats (reference to hash of arrays containing all subcategories within each
13395: category, -recursive)
13396:
1.655 raeburn 13397: Returns: nothing
13398:
13399: Side effects: populates trails and allitems hash references.
13400:
13401: =cut
13402:
13403: sub extract_categories {
1.665 raeburn 13404: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13405: if (ref($categories) eq 'HASH') {
13406: &gather_categories($categories,$cats,$idx,$jsarray);
13407: if (ref($cats->[0]) eq 'ARRAY') {
13408: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13409: my $name = $cats->[0][$i];
13410: my $item = &escape($name).'::0';
13411: my $trailstr;
13412: if ($name eq 'instcode') {
13413: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13414: } elsif ($name eq 'communities') {
13415: $trailstr = &mt('Communities');
1.655 raeburn 13416: } else {
13417: $trailstr = $name;
13418: }
13419: if ($allitems->{$item} eq '') {
13420: push(@{$trails},$trailstr);
13421: $allitems->{$item} = scalar(@{$trails})-1;
13422: }
13423: my @parents = ($name);
13424: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13425: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13426: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13427: if (ref($subcats) eq 'HASH') {
13428: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13429: }
13430: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13431: }
13432: } else {
13433: if (ref($subcats) eq 'HASH') {
13434: $subcats->{$item} = [];
1.655 raeburn 13435: }
13436: }
13437: }
13438: }
13439: }
13440: return;
13441: }
13442:
13443: =pod
13444:
1.1162 raeburn 13445: =item * &recurse_categories()
1.655 raeburn 13446:
13447: Recursively used to generate breadcrumb trails for course categories.
13448:
13449: Inputs:
1.663 raeburn 13450:
1.655 raeburn 13451: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13452: categories and subcategories).
1.663 raeburn 13453:
1.655 raeburn 13454: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13455:
13456: category (current course category, for which breadcrumb trail is being generated).
13457:
13458: trails (reference to array of breadcrumb trails for each category).
13459:
1.655 raeburn 13460: allitems (reference to hash - key is category key
13461: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13462:
1.655 raeburn 13463: parents (array containing containers directories for current category,
13464: back to top level).
13465:
13466: Returns: nothing
13467:
13468: Side effects: populates trails and allitems hash references
13469:
13470: =cut
13471:
13472: sub recurse_categories {
1.665 raeburn 13473: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13474: my $shallower = $depth - 1;
13475: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13476: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13477: my $name = $cats->[$depth]{$category}[$k];
13478: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13479: my $trailstr = join(' -> ',(@{$parents},$category));
13480: if ($allitems->{$item} eq '') {
13481: push(@{$trails},$trailstr);
13482: $allitems->{$item} = scalar(@{$trails})-1;
13483: }
13484: my $deeper = $depth+1;
13485: push(@{$parents},$category);
1.665 raeburn 13486: if (ref($subcats) eq 'HASH') {
13487: my $subcat = &escape($name).':'.$category.':'.$depth;
13488: for (my $j=@{$parents}; $j>=0; $j--) {
13489: my $higher;
13490: if ($j > 0) {
13491: $higher = &escape($parents->[$j]).':'.
13492: &escape($parents->[$j-1]).':'.$j;
13493: } else {
13494: $higher = &escape($parents->[$j]).'::'.$j;
13495: }
13496: push(@{$subcats->{$higher}},$subcat);
13497: }
13498: }
13499: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13500: $subcats);
1.655 raeburn 13501: pop(@{$parents});
13502: }
13503: } else {
13504: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13505: my $trailstr = join(' -> ',(@{$parents},$category));
13506: if ($allitems->{$item} eq '') {
13507: push(@{$trails},$trailstr);
13508: $allitems->{$item} = scalar(@{$trails})-1;
13509: }
13510: }
13511: return;
13512: }
13513:
1.663 raeburn 13514: =pod
13515:
1.1162 raeburn 13516: =item * &assign_categories_table()
1.663 raeburn 13517:
13518: Create a datatable for display of hierarchical categories in a domain,
13519: with checkboxes to allow a course to be categorized.
13520:
13521: Inputs:
13522:
13523: cathash - reference to hash of categories defined for the domain (from
13524: configuration.db)
13525:
13526: currcat - scalar with an & separated list of categories assigned to a course.
13527:
1.919 raeburn 13528: type - scalar contains course type (Course or Community).
13529:
1.663 raeburn 13530: Returns: $output (markup to be displayed)
13531:
13532: =cut
13533:
13534: sub assign_categories_table {
1.919 raeburn 13535: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13536: my $output;
13537: if (ref($cathash) eq 'HASH') {
13538: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13539: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13540: $maxdepth = scalar(@cats);
13541: if (@cats > 0) {
13542: my $itemcount = 0;
13543: if (ref($cats[0]) eq 'ARRAY') {
13544: my @currcategories;
13545: if ($currcat ne '') {
13546: @currcategories = split('&',$currcat);
13547: }
1.919 raeburn 13548: my $table;
1.663 raeburn 13549: for (my $i=0; $i<@{$cats[0]}; $i++) {
13550: my $parent = $cats[0][$i];
1.919 raeburn 13551: next if ($parent eq 'instcode');
13552: if ($type eq 'Community') {
13553: next unless ($parent eq 'communities');
13554: } else {
13555: next if ($parent eq 'communities');
13556: }
1.663 raeburn 13557: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13558: my $item = &escape($parent).'::0';
13559: my $checked = '';
13560: if (@currcategories > 0) {
13561: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13562: $checked = ' checked="checked"';
1.663 raeburn 13563: }
13564: }
1.919 raeburn 13565: my $parent_title = $parent;
13566: if ($parent eq 'communities') {
13567: $parent_title = &mt('Communities');
13568: }
13569: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13570: '<input type="checkbox" name="usecategory" value="'.
13571: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13572: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13573: my $depth = 1;
13574: push(@path,$parent);
1.919 raeburn 13575: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13576: pop(@path);
1.919 raeburn 13577: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13578: $itemcount ++;
13579: }
1.919 raeburn 13580: if ($itemcount) {
13581: $output = &Apache::loncommon::start_data_table().
13582: $table.
13583: &Apache::loncommon::end_data_table();
13584: }
1.663 raeburn 13585: }
13586: }
13587: }
13588: return $output;
13589: }
13590:
13591: =pod
13592:
1.1162 raeburn 13593: =item * &assign_category_rows()
1.663 raeburn 13594:
13595: Create a datatable row for display of nested categories in a domain,
13596: with checkboxes to allow a course to be categorized,called recursively.
13597:
13598: Inputs:
13599:
13600: itemcount - track row number for alternating colors
13601:
13602: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13603: categories and subcategories.
13604:
13605: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13606:
13607: parent - parent of current category item
13608:
13609: path - Array containing all categories back up through the hierarchy from the
13610: current category to the top level.
13611:
13612: currcategories - reference to array of current categories assigned to the course
13613:
13614: Returns: $output (markup to be displayed).
13615:
13616: =cut
13617:
13618: sub assign_category_rows {
13619: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13620: my ($text,$name,$item,$chgstr);
13621: if (ref($cats) eq 'ARRAY') {
13622: my $maxdepth = scalar(@{$cats});
13623: if (ref($cats->[$depth]) eq 'HASH') {
13624: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13625: my $numchildren = @{$cats->[$depth]{$parent}};
13626: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 13627: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13628: for (my $j=0; $j<$numchildren; $j++) {
13629: $name = $cats->[$depth]{$parent}[$j];
13630: $item = &escape($name).':'.&escape($parent).':'.$depth;
13631: my $deeper = $depth+1;
13632: my $checked = '';
13633: if (ref($currcategories) eq 'ARRAY') {
13634: if (@{$currcategories} > 0) {
13635: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13636: $checked = ' checked="checked"';
1.663 raeburn 13637: }
13638: }
13639: }
1.664 raeburn 13640: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13641: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13642: $item.'"'.$checked.' />'.$name.'</label></span>'.
13643: '<input type="hidden" name="catname" value="'.$name.'" />'.
13644: '</td><td>';
1.663 raeburn 13645: if (ref($path) eq 'ARRAY') {
13646: push(@{$path},$name);
13647: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13648: pop(@{$path});
13649: }
13650: $text .= '</td></tr>';
13651: }
13652: $text .= '</table></td>';
13653: }
13654: }
13655: }
13656: return $text;
13657: }
13658:
1.655 raeburn 13659: ############################################################
13660: ############################################################
13661:
13662:
1.443 albertel 13663: sub commit_customrole {
1.664 raeburn 13664: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13665: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13666: ($start?', '.&mt('starting').' '.localtime($start):'').
13667: ($end?', ending '.localtime($end):'').': <b>'.
13668: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13669: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13670: '</b><br />';
13671: return $output;
13672: }
13673:
13674: sub commit_standardrole {
1.1116 raeburn 13675: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13676: my ($output,$logmsg,$linefeed);
13677: if ($context eq 'auto') {
13678: $linefeed = "\n";
13679: } else {
13680: $linefeed = "<br />\n";
13681: }
1.443 albertel 13682: if ($three eq 'st') {
1.541 raeburn 13683: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13684: $one,$two,$sec,$context,$credits);
1.541 raeburn 13685: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13686: ($result eq 'unknown_course') || ($result eq 'refused')) {
13687: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13688: } else {
1.541 raeburn 13689: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13690: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13691: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13692: if ($context eq 'auto') {
13693: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13694: } else {
13695: $output .= '<b>'.$result.'</b>'.$linefeed.
13696: &mt('Add to classlist').': <b>ok</b>';
13697: }
13698: $output .= $linefeed;
1.443 albertel 13699: }
13700: } else {
13701: $output = &mt('Assigning').' '.$three.' in '.$url.
13702: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13703: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13704: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13705: if ($context eq 'auto') {
13706: $output .= $result.$linefeed;
13707: } else {
13708: $output .= '<b>'.$result.'</b>'.$linefeed;
13709: }
1.443 albertel 13710: }
13711: return $output;
13712: }
13713:
13714: sub commit_studentrole {
1.1116 raeburn 13715: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13716: $credits) = @_;
1.626 raeburn 13717: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13718: if ($context eq 'auto') {
13719: $linefeed = "\n";
13720: } else {
13721: $linefeed = '<br />'."\n";
13722: }
1.443 albertel 13723: if (defined($one) && defined($two)) {
13724: my $cid=$one.'_'.$two;
13725: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13726: my $secchange = 0;
13727: my $expire_role_result;
13728: my $modify_section_result;
1.628 raeburn 13729: if ($oldsec ne '-1') {
13730: if ($oldsec ne $sec) {
1.443 albertel 13731: $secchange = 1;
1.628 raeburn 13732: my $now = time;
1.443 albertel 13733: my $uurl='/'.$cid;
13734: $uurl=~s/\_/\//g;
13735: if ($oldsec) {
13736: $uurl.='/'.$oldsec;
13737: }
1.626 raeburn 13738: $oldsecurl = $uurl;
1.628 raeburn 13739: $expire_role_result =
1.652 raeburn 13740: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13741: if ($env{'request.course.sec'} ne '') {
13742: if ($expire_role_result eq 'refused') {
13743: my @roles = ('st');
13744: my @statuses = ('previous');
13745: my @roledoms = ($one);
13746: my $withsec = 1;
13747: my %roleshash =
13748: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13749: \@statuses,\@roles,\@roledoms,$withsec);
13750: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13751: my ($oldstart,$oldend) =
13752: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13753: if ($oldend > 0 && $oldend <= $now) {
13754: $expire_role_result = 'ok';
13755: }
13756: }
13757: }
13758: }
1.443 albertel 13759: $result = $expire_role_result;
13760: }
13761: }
13762: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13763: $modify_section_result =
13764: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13765: undef,undef,undef,$sec,
13766: $end,$start,'','',$cid,
13767: '',$context,$credits);
1.443 albertel 13768: if ($modify_section_result =~ /^ok/) {
13769: if ($secchange == 1) {
1.628 raeburn 13770: if ($sec eq '') {
13771: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13772: } else {
13773: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13774: }
1.443 albertel 13775: } elsif ($oldsec eq '-1') {
1.628 raeburn 13776: if ($sec eq '') {
13777: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13778: } else {
13779: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13780: }
1.443 albertel 13781: } else {
1.628 raeburn 13782: if ($sec eq '') {
13783: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13784: } else {
13785: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13786: }
1.443 albertel 13787: }
13788: } else {
1.1115 raeburn 13789: if ($secchange) {
1.628 raeburn 13790: $$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;
13791: } else {
13792: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13793: }
1.443 albertel 13794: }
13795: $result = $modify_section_result;
13796: } elsif ($secchange == 1) {
1.628 raeburn 13797: if ($oldsec eq '') {
1.1103 raeburn 13798: $$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 13799: } else {
13800: $$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;
13801: }
1.626 raeburn 13802: if ($expire_role_result eq 'refused') {
13803: my $newsecurl = '/'.$cid;
13804: $newsecurl =~ s/\_/\//g;
13805: if ($sec ne '') {
13806: $newsecurl.='/'.$sec;
13807: }
13808: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13809: if ($sec eq '') {
13810: $$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;
13811: } else {
13812: $$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;
13813: }
13814: }
13815: }
1.443 albertel 13816: }
13817: } else {
1.626 raeburn 13818: $$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 13819: $result = "error: incomplete course id\n";
13820: }
13821: return $result;
13822: }
13823:
1.1108 raeburn 13824: sub show_role_extent {
13825: my ($scope,$context,$role) = @_;
13826: $scope =~ s{^/}{};
13827: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13828: push(@courseroles,'co');
13829: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13830: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13831: $scope =~ s{/}{_};
13832: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13833: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13834: my ($audom,$auname) = split(/\//,$scope);
13835: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13836: &Apache::loncommon::plainname($auname,$audom).'</span>');
13837: } else {
13838: $scope =~ s{/$}{};
13839: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13840: &Apache::lonnet::domain($scope,'description').'</span>');
13841: }
13842: }
13843:
1.443 albertel 13844: ############################################################
13845: ############################################################
13846:
1.566 albertel 13847: sub check_clone {
1.578 raeburn 13848: my ($args,$linefeed) = @_;
1.566 albertel 13849: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13850: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13851: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13852: my $clonemsg;
13853: my $can_clone = 0;
1.944 raeburn 13854: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13855: if ($lctype ne 'community') {
13856: $lctype = 'course';
13857: }
1.566 albertel 13858: if ($clonehome eq 'no_host') {
1.944 raeburn 13859: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13860: $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'});
13861: } else {
13862: $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'});
13863: }
1.566 albertel 13864: } else {
13865: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13866: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13867: if ($clonedesc{'type'} ne 'Community') {
13868: $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'});
13869: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13870: }
13871: }
1.882 raeburn 13872: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13873: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13874: $can_clone = 1;
13875: } else {
13876: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13877: $args->{'clonedomain'},$args->{'clonecourse'});
13878: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13879: if (grep(/^\*$/,@cloners)) {
13880: $can_clone = 1;
13881: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13882: $can_clone = 1;
13883: } else {
1.908 raeburn 13884: my $ccrole = 'cc';
1.944 raeburn 13885: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13886: $ccrole = 'co';
13887: }
1.578 raeburn 13888: my %roleshash =
13889: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13890: $args->{'ccdomain'},
1.908 raeburn 13891: 'userroles',['active'],[$ccrole],
1.578 raeburn 13892: [$args->{'clonedomain'}]);
1.908 raeburn 13893: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13894: $can_clone = 1;
13895: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13896: $can_clone = 1;
13897: } else {
1.944 raeburn 13898: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13899: $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'});
13900: } else {
13901: $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'});
13902: }
1.578 raeburn 13903: }
1.566 albertel 13904: }
1.578 raeburn 13905: }
1.566 albertel 13906: }
13907: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13908: }
13909:
1.444 albertel 13910: sub construct_course {
1.1166 raeburn 13911: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13912: my $outcome;
1.541 raeburn 13913: my $linefeed = '<br />'."\n";
13914: if ($context eq 'auto') {
13915: $linefeed = "\n";
13916: }
1.566 albertel 13917:
13918: #
13919: # Are we cloning?
13920: #
13921: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13922: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13923: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13924: if ($context ne 'auto') {
1.578 raeburn 13925: if ($clonemsg ne '') {
13926: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13927: }
1.566 albertel 13928: }
13929: $outcome .= $clonemsg.$linefeed;
13930:
13931: if (!$can_clone) {
13932: return (0,$outcome);
13933: }
13934: }
13935:
1.444 albertel 13936: #
13937: # Open course
13938: #
13939: my $crstype = lc($args->{'crstype'});
13940: my %cenv=();
13941: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13942: $args->{'cdescr'},
13943: $args->{'curl'},
13944: $args->{'course_home'},
13945: $args->{'nonstandard'},
13946: $args->{'crscode'},
13947: $args->{'ccuname'}.':'.
13948: $args->{'ccdomain'},
1.882 raeburn 13949: $args->{'crstype'},
1.885 raeburn 13950: $cnum,$context,$category);
1.444 albertel 13951:
13952: # Note: The testing routines depend on this being output; see
13953: # Utils::Course. This needs to at least be output as a comment
13954: # if anyone ever decides to not show this, and Utils::Course::new
13955: # will need to be suitably modified.
1.541 raeburn 13956: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13957: if ($$courseid =~ /^error:/) {
13958: return (0,$outcome);
13959: }
13960:
1.444 albertel 13961: #
13962: # Check if created correctly
13963: #
1.479 albertel 13964: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13965: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13966: if ($crsuhome eq 'no_host') {
13967: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13968: return (0,$outcome);
13969: }
1.541 raeburn 13970: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13971:
1.444 albertel 13972: #
1.566 albertel 13973: # Do the cloning
13974: #
13975: if ($can_clone && $cloneid) {
13976: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13977: if ($context ne 'auto') {
13978: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13979: }
13980: $outcome .= $clonemsg.$linefeed;
13981: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13982: # Copy all files
1.637 www 13983: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13984: # Restore URL
1.566 albertel 13985: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13986: # Restore title
1.566 albertel 13987: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13988: # Restore creation date, creator and creation context.
13989: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13990: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13991: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13992: # Mark as cloned
1.566 albertel 13993: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13994: # Need to clone grading mode
13995: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13996: $cenv{'grading'}=$newenv{'grading'};
13997: # Do not clone these environment entries
13998: &Apache::lonnet::del('environment',
13999: ['default_enrollment_start_date',
14000: 'default_enrollment_end_date',
14001: 'question.email',
14002: 'policy.email',
14003: 'comment.email',
14004: 'pch.users.denied',
1.725 raeburn 14005: 'plc.users.denied',
14006: 'hidefromcat',
1.1121 raeburn 14007: 'checkforpriv',
1.1166 raeburn 14008: 'categories',
14009: 'internal.uniquecode'],
1.638 www 14010: $$crsudom,$$crsunum);
1.1170 raeburn 14011: if ($args->{'textbook'}) {
14012: $cenv{'internal.textbook'} = $args->{'textbook'};
14013: }
1.444 albertel 14014: }
1.566 albertel 14015:
1.444 albertel 14016: #
14017: # Set environment (will override cloned, if existing)
14018: #
14019: my @sections = ();
14020: my @xlists = ();
14021: if ($args->{'crstype'}) {
14022: $cenv{'type'}=$args->{'crstype'};
14023: }
14024: if ($args->{'crsid'}) {
14025: $cenv{'courseid'}=$args->{'crsid'};
14026: }
14027: if ($args->{'crscode'}) {
14028: $cenv{'internal.coursecode'}=$args->{'crscode'};
14029: }
14030: if ($args->{'crsquota'} ne '') {
14031: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14032: } else {
14033: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14034: }
14035: if ($args->{'ccuname'}) {
14036: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14037: ':'.$args->{'ccdomain'};
14038: } else {
14039: $cenv{'internal.courseowner'} = $args->{'curruser'};
14040: }
1.1116 raeburn 14041: if ($args->{'defaultcredits'}) {
14042: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14043: }
1.444 albertel 14044: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14045: if ($args->{'crssections'}) {
14046: $cenv{'internal.sectionnums'} = '';
14047: if ($args->{'crssections'} =~ m/,/) {
14048: @sections = split/,/,$args->{'crssections'};
14049: } else {
14050: $sections[0] = $args->{'crssections'};
14051: }
14052: if (@sections > 0) {
14053: foreach my $item (@sections) {
14054: my ($sec,$gp) = split/:/,$item;
14055: my $class = $args->{'crscode'}.$sec;
14056: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14057: $cenv{'internal.sectionnums'} .= $item.',';
14058: unless ($addcheck eq 'ok') {
14059: push @badclasses, $class;
14060: }
14061: }
14062: $cenv{'internal.sectionnums'} =~ s/,$//;
14063: }
14064: }
14065: # do not hide course coordinator from staff listing,
14066: # even if privileged
14067: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14068: # add course coordinator's domain to domains to check for privileged users
14069: # if different to course domain
14070: if ($$crsudom ne $args->{'ccdomain'}) {
14071: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14072: }
1.444 albertel 14073: # add crosslistings
14074: if ($args->{'crsxlist'}) {
14075: $cenv{'internal.crosslistings'}='';
14076: if ($args->{'crsxlist'} =~ m/,/) {
14077: @xlists = split/,/,$args->{'crsxlist'};
14078: } else {
14079: $xlists[0] = $args->{'crsxlist'};
14080: }
14081: if (@xlists > 0) {
14082: foreach my $item (@xlists) {
14083: my ($xl,$gp) = split/:/,$item;
14084: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14085: $cenv{'internal.crosslistings'} .= $item.',';
14086: unless ($addcheck eq 'ok') {
14087: push @badclasses, $xl;
14088: }
14089: }
14090: $cenv{'internal.crosslistings'} =~ s/,$//;
14091: }
14092: }
14093: if ($args->{'autoadds'}) {
14094: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14095: }
14096: if ($args->{'autodrops'}) {
14097: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14098: }
14099: # check for notification of enrollment changes
14100: my @notified = ();
14101: if ($args->{'notify_owner'}) {
14102: if ($args->{'ccuname'} ne '') {
14103: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14104: }
14105: }
14106: if ($args->{'notify_dc'}) {
14107: if ($uname ne '') {
1.630 raeburn 14108: push(@notified,$uname.':'.$udom);
1.444 albertel 14109: }
14110: }
14111: if (@notified > 0) {
14112: my $notifylist;
14113: if (@notified > 1) {
14114: $notifylist = join(',',@notified);
14115: } else {
14116: $notifylist = $notified[0];
14117: }
14118: $cenv{'internal.notifylist'} = $notifylist;
14119: }
14120: if (@badclasses > 0) {
14121: my %lt=&Apache::lonlocal::texthash(
14122: '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',
14123: 'dnhr' => 'does not have rights to access enrollment in these classes',
14124: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14125: );
1.541 raeburn 14126: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14127: ' ('.$lt{'adby'}.')';
14128: if ($context eq 'auto') {
14129: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14130: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14131: foreach my $item (@badclasses) {
14132: if ($context eq 'auto') {
14133: $outcome .= " - $item\n";
14134: } else {
14135: $outcome .= "<li>$item</li>\n";
14136: }
14137: }
14138: if ($context eq 'auto') {
14139: $outcome .= $linefeed;
14140: } else {
1.566 albertel 14141: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14142: }
14143: }
1.444 albertel 14144: }
14145: if ($args->{'no_end_date'}) {
14146: $args->{'endaccess'} = 0;
14147: }
14148: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14149: $cenv{'internal.autoend'}=$args->{'enrollend'};
14150: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14151: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14152: if ($args->{'showphotos'}) {
14153: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14154: }
14155: $cenv{'internal.authtype'} = $args->{'authtype'};
14156: $cenv{'internal.autharg'} = $args->{'autharg'};
14157: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14158: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14159: 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');
14160: if ($context eq 'auto') {
14161: $outcome .= $krb_msg;
14162: } else {
1.566 albertel 14163: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14164: }
14165: $outcome .= $linefeed;
1.444 albertel 14166: }
14167: }
14168: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14169: if ($args->{'setpolicy'}) {
14170: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14171: }
14172: if ($args->{'setcontent'}) {
14173: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14174: }
14175: }
14176: if ($args->{'reshome'}) {
14177: $cenv{'reshome'}=$args->{'reshome'}.'/';
14178: $cenv{'reshome'}=~s/\/+$/\//;
14179: }
14180: #
14181: # course has keyed access
14182: #
14183: if ($args->{'setkeys'}) {
14184: $cenv{'keyaccess'}='yes';
14185: }
14186: # if specified, key authority is not course, but user
14187: # only active if keyaccess is yes
14188: if ($args->{'keyauth'}) {
1.487 albertel 14189: my ($user,$domain) = split(':',$args->{'keyauth'});
14190: $user = &LONCAPA::clean_username($user);
14191: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14192: if ($user ne '' && $domain ne '') {
1.487 albertel 14193: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14194: }
14195: }
14196:
1.1166 raeburn 14197: #
1.1167 raeburn 14198: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14199: #
14200: if ($args->{'uniquecode'}) {
14201: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14202: if ($code) {
14203: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14204: my %crsinfo =
14205: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14206: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14207: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14208: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14209: }
1.1166 raeburn 14210: if (ref($coderef)) {
14211: $$coderef = $code;
14212: }
14213: }
14214: }
14215:
1.444 albertel 14216: if ($args->{'disresdis'}) {
14217: $cenv{'pch.roles.denied'}='st';
14218: }
14219: if ($args->{'disablechat'}) {
14220: $cenv{'plc.roles.denied'}='st';
14221: }
14222:
14223: # Record we've not yet viewed the Course Initialization Helper for this
14224: # course
14225: $cenv{'course.helper.not.run'} = 1;
14226: #
14227: # Use new Randomseed
14228: #
14229: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14230: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14231: #
14232: # The encryption code and receipt prefix for this course
14233: #
14234: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14235: $cenv{'internal.encpref'}=100+int(9*rand(99));
14236: #
14237: # By default, use standard grading
14238: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14239:
1.541 raeburn 14240: $outcome .= $linefeed.&mt('Setting environment').': '.
14241: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14242: #
14243: # Open all assignments
14244: #
14245: if ($args->{'openall'}) {
14246: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14247: my %storecontent = ($storeunder => time,
14248: $storeunder.'.type' => 'date_start');
14249:
14250: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14251: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14252: }
14253: #
14254: # Set first page
14255: #
14256: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14257: || ($cloneid)) {
1.445 albertel 14258: use LONCAPA::map;
1.444 albertel 14259: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14260:
14261: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14262: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14263:
1.444 albertel 14264: $outcome .= ($fatal?$errtext:'read ok').' - ';
14265: my $title; my $url;
14266: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14267: $title=&mt('Syllabus');
1.444 albertel 14268: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14269: } else {
1.963 raeburn 14270: $title=&mt('Table of Contents');
1.444 albertel 14271: $url='/adm/navmaps';
14272: }
1.445 albertel 14273:
14274: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14275: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14276:
14277: if ($errtext) { $fatal=2; }
1.541 raeburn 14278: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14279: }
1.566 albertel 14280:
14281: return (1,$outcome);
1.444 albertel 14282: }
14283:
1.1166 raeburn 14284: sub make_unique_code {
14285: my ($cdom,$cnum) = @_;
14286: # get lock on uniquecodes db
14287: my $lockhash = {
14288: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14289: ':'.$env{'user.domain'},
14290: };
14291: my $tries = 0;
14292: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14293: my ($code,$error);
14294:
14295: while (($gotlock ne 'ok') && ($tries<3)) {
14296: $tries ++;
14297: sleep 1;
14298: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14299: }
14300: if ($gotlock eq 'ok') {
14301: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14302: my $gotcode;
14303: my $attempts = 0;
14304: while ((!$gotcode) && ($attempts < 100)) {
14305: $code = &generate_code();
14306: if (!exists($currcodes{$code})) {
14307: $gotcode = 1;
14308: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14309: $error = 'nostore';
14310: }
14311: }
14312: $attempts ++;
14313: }
14314: my @del_lock = ($cnum."\0".'uniquecodes');
14315: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14316: } else {
14317: $error = 'nolock';
14318: }
14319: return ($code,$error);
14320: }
14321:
14322: sub generate_code {
14323: my $code;
14324: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14325: for (my $i=0; $i<6; $i++) {
14326: my $lettnum = int (rand 2);
14327: my $item = '';
14328: if ($lettnum) {
14329: $item = $letts[int( rand(18) )];
14330: } else {
14331: $item = 1+int( rand(8) );
14332: }
14333: $code .= $item;
14334: }
14335: return $code;
14336: }
14337:
1.444 albertel 14338: ############################################################
14339: ############################################################
14340:
1.953 droeschl 14341: #SD
14342: # only Community and Course, or anything else?
1.378 raeburn 14343: sub course_type {
14344: my ($cid) = @_;
14345: if (!defined($cid)) {
14346: $cid = $env{'request.course.id'};
14347: }
1.404 albertel 14348: if (defined($env{'course.'.$cid.'.type'})) {
14349: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14350: } else {
14351: return 'Course';
1.377 raeburn 14352: }
14353: }
1.156 albertel 14354:
1.406 raeburn 14355: sub group_term {
14356: my $crstype = &course_type();
14357: my %names = (
14358: 'Course' => 'group',
1.865 raeburn 14359: 'Community' => 'group',
1.406 raeburn 14360: );
14361: return $names{$crstype};
14362: }
14363:
1.902 raeburn 14364: sub course_types {
1.1165 raeburn 14365: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14366: my %typename = (
14367: official => 'Official course',
14368: unofficial => 'Unofficial course',
14369: community => 'Community',
1.1165 raeburn 14370: textbook => 'Textbook course',
1.902 raeburn 14371: );
14372: return (\@types,\%typename);
14373: }
14374:
1.156 albertel 14375: sub icon {
14376: my ($file)=@_;
1.505 albertel 14377: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14378: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14379: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14380: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14381: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14382: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14383: $curfext.".gif") {
14384: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14385: $curfext.".gif";
14386: }
14387: }
1.249 albertel 14388: return &lonhttpdurl($iconname);
1.154 albertel 14389: }
1.84 albertel 14390:
1.575 albertel 14391: sub lonhttpdurl {
1.692 www 14392: #
14393: # Had been used for "small fry" static images on separate port 8080.
14394: # Modify here if lightweight http functionality desired again.
14395: # Currently eliminated due to increasing firewall issues.
14396: #
1.575 albertel 14397: my ($url)=@_;
1.692 www 14398: return $url;
1.215 albertel 14399: }
14400:
1.213 albertel 14401: sub connection_aborted {
14402: my ($r)=@_;
14403: $r->print(" ");$r->rflush();
14404: my $c = $r->connection;
14405: return $c->aborted();
14406: }
14407:
1.221 foxr 14408: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14409: # strings as 'strings'.
14410: sub escape_single {
1.221 foxr 14411: my ($input) = @_;
1.223 albertel 14412: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14413: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14414: return $input;
14415: }
1.223 albertel 14416:
1.222 foxr 14417: # Same as escape_single, but escape's "'s This
14418: # can be used for "strings"
14419: sub escape_double {
14420: my ($input) = @_;
14421: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14422: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14423: return $input;
14424: }
1.223 albertel 14425:
1.222 foxr 14426: # Escapes the last element of a full URL.
14427: sub escape_url {
14428: my ($url) = @_;
1.238 raeburn 14429: my @urlslices = split(/\//, $url,-1);
1.369 www 14430: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14431: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14432: }
1.462 albertel 14433:
1.820 raeburn 14434: sub compare_arrays {
14435: my ($arrayref1,$arrayref2) = @_;
14436: my (@difference,%count);
14437: @difference = ();
14438: %count = ();
14439: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14440: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14441: foreach my $element (keys(%count)) {
14442: if ($count{$element} == 1) {
14443: push(@difference,$element);
14444: }
14445: }
14446: }
14447: return @difference;
14448: }
14449:
1.817 bisitz 14450: # -------------------------------------------------------- Initialize user login
1.462 albertel 14451: sub init_user_environment {
1.463 albertel 14452: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14453: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14454:
14455: my $public=($username eq 'public' && $domain eq 'public');
14456:
14457: # See if old ID present, if so, remove
14458:
1.1062 raeburn 14459: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14460: my $now=time;
14461:
14462: if ($public) {
14463: my $max_public=100;
14464: my $oldest;
14465: my $oldest_time=0;
14466: for(my $next=1;$next<=$max_public;$next++) {
14467: if (-e $lonids."/publicuser_$next.id") {
14468: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14469: if ($mtime<$oldest_time || !$oldest_time) {
14470: $oldest_time=$mtime;
14471: $oldest=$next;
14472: }
14473: } else {
14474: $cookie="publicuser_$next";
14475: last;
14476: }
14477: }
14478: if (!$cookie) { $cookie="publicuser_$oldest"; }
14479: } else {
1.463 albertel 14480: # if this isn't a robot, kill any existing non-robot sessions
14481: if (!$args->{'robot'}) {
14482: opendir(DIR,$lonids);
14483: while ($filename=readdir(DIR)) {
14484: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14485: unlink($lonids.'/'.$filename);
14486: }
1.462 albertel 14487: }
1.463 albertel 14488: closedir(DIR);
1.462 albertel 14489: }
14490: # Give them a new cookie
1.463 albertel 14491: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14492: : $now.$$.int(rand(10000)));
1.463 albertel 14493: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14494:
14495: # Initialize roles
14496:
1.1062 raeburn 14497: ($userroles,$firstaccenv,$timerintenv) =
14498: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14499: }
14500: # ------------------------------------ Check browser type and MathML capability
14501:
14502: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 14503: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14504:
14505: # ------------------------------------------------------------- Get environment
14506:
14507: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14508: my ($tmp) = keys(%userenv);
14509: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14510: } else {
14511: undef(%userenv);
14512: }
14513: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14514: $form->{'interface'}=$userenv{'interface'};
14515: }
14516: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14517:
14518: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14519: foreach my $option ('interface','localpath','localres') {
14520: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14521: }
14522: # --------------------------------------------------------- Write first profile
14523:
14524: {
14525: my %initial_env =
14526: ("user.name" => $username,
14527: "user.domain" => $domain,
14528: "user.home" => $authhost,
14529: "browser.type" => $clientbrowser,
14530: "browser.version" => $clientversion,
14531: "browser.mathml" => $clientmathml,
14532: "browser.unicode" => $clientunicode,
14533: "browser.os" => $clientos,
1.1137 raeburn 14534: "browser.mobile" => $clientmobile,
1.1141 raeburn 14535: "browser.info" => $clientinfo,
1.462 albertel 14536: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14537: "request.course.fn" => '',
14538: "request.course.uri" => '',
14539: "request.course.sec" => '',
14540: "request.role" => 'cm',
14541: "request.role.adv" => $env{'user.adv'},
14542: "request.host" => $ENV{'REMOTE_ADDR'},);
14543:
14544: if ($form->{'localpath'}) {
14545: $initial_env{"browser.localpath"} = $form->{'localpath'};
14546: $initial_env{"browser.localres"} = $form->{'localres'};
14547: }
14548:
14549: if ($form->{'interface'}) {
14550: $form->{'interface'}=~s/\W//gs;
14551: $initial_env{"browser.interface"} = $form->{'interface'};
14552: $env{'browser.interface'}=$form->{'interface'};
14553: }
14554:
1.1157 raeburn 14555: if ($form->{'iptoken'}) {
14556: my $lonhost = $r->dir_config('lonHostID');
14557: $initial_env{"user.noloadbalance"} = $lonhost;
14558: $env{'user.noloadbalance'} = $lonhost;
14559: }
14560:
1.981 raeburn 14561: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14562: my %domdef;
14563: unless ($domain eq 'public') {
14564: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14565: }
1.980 raeburn 14566:
1.1081 raeburn 14567: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14568: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14569: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14570: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14571: }
14572:
1.1165 raeburn 14573: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14574: $userenv{'canrequest.'.$crstype} =
14575: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14576: 'reload','requestcourses',
14577: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14578: }
14579:
1.1092 raeburn 14580: $userenv{'canrequest.author'} =
14581: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14582: 'reload','requestauthor',
14583: \%userenv,\%domdef,\%is_adv);
14584: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14585: $domain,$username);
14586: my $reqstatus = $reqauthor{'author_status'};
14587: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14588: if (ref($reqauthor{'author'}) eq 'HASH') {
14589: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14590: $reqauthor{'author'}{'timestamp'};
14591: }
14592: }
14593:
1.462 albertel 14594: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14595:
1.462 albertel 14596: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14597: &GDBM_WRCREAT(),0640)) {
14598: &_add_to_env(\%disk_env,\%initial_env);
14599: &_add_to_env(\%disk_env,\%userenv,'environment.');
14600: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14601: if (ref($firstaccenv) eq 'HASH') {
14602: &_add_to_env(\%disk_env,$firstaccenv);
14603: }
14604: if (ref($timerintenv) eq 'HASH') {
14605: &_add_to_env(\%disk_env,$timerintenv);
14606: }
1.463 albertel 14607: if (ref($args->{'extra_env'})) {
14608: &_add_to_env(\%disk_env,$args->{'extra_env'});
14609: }
1.462 albertel 14610: untie(%disk_env);
14611: } else {
1.705 tempelho 14612: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14613: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14614: return 'error: '.$!;
14615: }
14616: }
14617: $env{'request.role'}='cm';
14618: $env{'request.role.adv'}=$env{'user.adv'};
14619: $env{'browser.type'}=$clientbrowser;
14620:
14621: return $cookie;
14622:
14623: }
14624:
14625: sub _add_to_env {
14626: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14627: if (ref($env_data) eq 'HASH') {
14628: while (my ($key,$value) = each(%$env_data)) {
14629: $idf->{$prefix.$key} = $value;
14630: $env{$prefix.$key} = $value;
14631: }
1.462 albertel 14632: }
14633: }
14634:
1.685 tempelho 14635: # --- Get the symbolic name of a problem and the url
14636: sub get_symb {
14637: my ($request,$silent) = @_;
1.726 raeburn 14638: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14639: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14640: if ($symb eq '') {
14641: if (!$silent) {
1.1071 raeburn 14642: if (ref($request)) {
14643: $request->print("Unable to handle ambiguous references:$url:.");
14644: }
1.685 tempelho 14645: return ();
14646: }
14647: }
14648: &Apache::lonenc::check_decrypt(\$symb);
14649: return ($symb);
14650: }
14651:
14652: # --------------------------------------------------------------Get annotation
14653:
14654: sub get_annotation {
14655: my ($symb,$enc) = @_;
14656:
14657: my $key = $symb;
14658: if (!$enc) {
14659: $key =
14660: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14661: }
14662: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14663: return $annotation{$key};
14664: }
14665:
14666: sub clean_symb {
1.731 raeburn 14667: my ($symb,$delete_enc) = @_;
1.685 tempelho 14668:
14669: &Apache::lonenc::check_decrypt(\$symb);
14670: my $enc = $env{'request.enc'};
1.731 raeburn 14671: if ($delete_enc) {
1.730 raeburn 14672: delete($env{'request.enc'});
14673: }
1.685 tempelho 14674:
14675: return ($symb,$enc);
14676: }
1.462 albertel 14677:
1.990 raeburn 14678: sub build_release_hashes {
14679: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14680: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14681: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14682: (ref($randomizetry) eq 'HASH'));
14683: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14684: my ($item,$name,$value) = split(/:/,$key);
14685: if ($item eq 'parameter') {
14686: if (ref($checkparms->{$name}) eq 'ARRAY') {
14687: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14688: push(@{$checkparms->{$name}},$value);
14689: }
14690: } else {
14691: push(@{$checkparms->{$name}},$value);
14692: }
14693: } elsif ($item eq 'resourcetag') {
14694: if ($name eq 'responsetype') {
14695: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14696: }
14697: } elsif ($item eq 'course') {
14698: if ($name eq 'crstype') {
14699: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14700: }
14701: }
14702: }
14703: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14704: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14705: return;
14706: }
14707:
1.1083 raeburn 14708: sub update_content_constraints {
14709: my ($cdom,$cnum,$chome,$cid) = @_;
14710: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14711: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14712: my %checkresponsetypes;
14713: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14714: my ($item,$name,$value) = split(/:/,$key);
14715: if ($item eq 'resourcetag') {
14716: if ($name eq 'responsetype') {
14717: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14718: }
14719: }
14720: }
14721: my $navmap = Apache::lonnavmaps::navmap->new();
14722: if (defined($navmap)) {
14723: my %allresponses;
14724: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14725: my %responses = $res->responseTypes();
14726: foreach my $key (keys(%responses)) {
14727: next unless(exists($checkresponsetypes{$key}));
14728: $allresponses{$key} += $responses{$key};
14729: }
14730: }
14731: foreach my $key (keys(%allresponses)) {
14732: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14733: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14734: ($reqdmajor,$reqdminor) = ($major,$minor);
14735: }
14736: }
14737: undef($navmap);
14738: }
14739: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14740: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14741: }
14742: return;
14743: }
14744:
1.1110 raeburn 14745: sub allmaps_incourse {
14746: my ($cdom,$cnum,$chome,$cid) = @_;
14747: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14748: $cid = $env{'request.course.id'};
14749: $cdom = $env{'course.'.$cid.'.domain'};
14750: $cnum = $env{'course.'.$cid.'.num'};
14751: $chome = $env{'course.'.$cid.'.home'};
14752: }
14753: my %allmaps = ();
14754: my $lastchange =
14755: &Apache::lonnet::get_coursechange($cdom,$cnum);
14756: if ($lastchange > $env{'request.course.tied'}) {
14757: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14758: unless ($ferr) {
14759: &update_content_constraints($cdom,$cnum,$chome,$cid);
14760: }
14761: }
14762: my $navmap = Apache::lonnavmaps::navmap->new();
14763: if (defined($navmap)) {
14764: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14765: $allmaps{$res->src()} = 1;
14766: }
14767: }
14768: return \%allmaps;
14769: }
14770:
1.1083 raeburn 14771: sub parse_supplemental_title {
14772: my ($title) = @_;
14773:
14774: my ($foldertitle,$renametitle);
14775: if ($title =~ /&&&/) {
14776: $title = &HTML::Entites::decode($title);
14777: }
14778: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14779: $renametitle=$4;
14780: my ($time,$uname,$udom) = ($1,$2,$3);
14781: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14782: my $name = &plainname($uname,$udom);
14783: $name = &HTML::Entities::encode($name,'"<>&\'');
14784: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14785: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14786: $name.': <br />'.$foldertitle;
14787: }
14788: if (wantarray) {
14789: return ($title,$foldertitle,$renametitle);
14790: }
14791: return $title;
14792: }
14793:
1.1143 raeburn 14794: sub recurse_supplemental {
14795: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14796: if ($suppmap) {
14797: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14798: if ($fatal) {
14799: $errors ++;
14800: } else {
14801: if ($#LONCAPA::map::resources > 0) {
14802: foreach my $res (@LONCAPA::map::resources) {
14803: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14804: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 14805: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14806: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 14807: } else {
14808: $numfiles ++;
14809: }
14810: }
14811: }
14812: }
14813: }
14814: }
14815: return ($numfiles,$errors);
14816: }
14817:
1.1101 raeburn 14818: sub symb_to_docspath {
14819: my ($symb) = @_;
14820: return unless ($symb);
14821: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14822: if ($resurl=~/\.(sequence|page)$/) {
14823: $mapurl=$resurl;
14824: } elsif ($resurl eq 'adm/navmaps') {
14825: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14826: }
14827: my $mapresobj;
14828: my $navmap = Apache::lonnavmaps::navmap->new();
14829: if (ref($navmap)) {
14830: $mapresobj = $navmap->getResourceByUrl($mapurl);
14831: }
14832: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14833: my $type=$2;
14834: my $path;
14835: if (ref($mapresobj)) {
14836: my $pcslist = $mapresobj->map_hierarchy();
14837: if ($pcslist ne '') {
14838: foreach my $pc (split(/,/,$pcslist)) {
14839: next if ($pc <= 1);
14840: my $res = $navmap->getByMapPc($pc);
14841: if (ref($res)) {
14842: my $thisurl = $res->src();
14843: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14844: my $thistitle = $res->title();
14845: $path .= '&'.
14846: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 14847: &escape($thistitle).
1.1101 raeburn 14848: ':'.$res->randompick().
14849: ':'.$res->randomout().
14850: ':'.$res->encrypted().
14851: ':'.$res->randomorder().
14852: ':'.$res->is_page();
14853: }
14854: }
14855: }
14856: $path =~ s/^\&//;
14857: my $maptitle = $mapresobj->title();
14858: if ($mapurl eq 'default') {
1.1129 raeburn 14859: $maptitle = 'Main Content';
1.1101 raeburn 14860: }
14861: $path .= (($path ne '')? '&' : '').
14862: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 14863: &escape($maptitle).
1.1101 raeburn 14864: ':'.$mapresobj->randompick().
14865: ':'.$mapresobj->randomout().
14866: ':'.$mapresobj->encrypted().
14867: ':'.$mapresobj->randomorder().
14868: ':'.$mapresobj->is_page();
14869: } else {
14870: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14871: my $ispage = (($type eq 'page')? 1 : '');
14872: if ($mapurl eq 'default') {
1.1129 raeburn 14873: $maptitle = 'Main Content';
1.1101 raeburn 14874: }
14875: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 14876: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 14877: }
14878: unless ($mapurl eq 'default') {
14879: $path = 'default&'.
1.1146 raeburn 14880: &escape('Main Content').
1.1101 raeburn 14881: ':::::&'.$path;
14882: }
14883: return $path;
14884: }
14885:
1.1094 raeburn 14886: sub captcha_display {
14887: my ($context,$lonhost) = @_;
14888: my ($output,$error);
14889: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14890: if ($captcha eq 'original') {
1.1094 raeburn 14891: $output = &create_captcha();
14892: unless ($output) {
1.1172 raeburn 14893: $error = 'captcha';
1.1094 raeburn 14894: }
14895: } elsif ($captcha eq 'recaptcha') {
14896: $output = &create_recaptcha($pubkey);
14897: unless ($output) {
1.1172 raeburn 14898: $error = 'recaptcha';
1.1094 raeburn 14899: }
14900: }
14901: return ($output,$error);
14902: }
14903:
14904: sub captcha_response {
14905: my ($context,$lonhost) = @_;
14906: my ($captcha_chk,$captcha_error);
14907: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14908: if ($captcha eq 'original') {
1.1094 raeburn 14909: ($captcha_chk,$captcha_error) = &check_captcha();
14910: } elsif ($captcha eq 'recaptcha') {
14911: $captcha_chk = &check_recaptcha($privkey);
14912: } else {
14913: $captcha_chk = 1;
14914: }
14915: return ($captcha_chk,$captcha_error);
14916: }
14917:
14918: sub get_captcha_config {
14919: my ($context,$lonhost) = @_;
1.1095 raeburn 14920: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14921: my $hostname = &Apache::lonnet::hostname($lonhost);
14922: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14923: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14924: if ($context eq 'usercreation') {
14925: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14926: if (ref($domconfig{$context}) eq 'HASH') {
14927: $hashtocheck = $domconfig{$context}{'cancreate'};
14928: if (ref($hashtocheck) eq 'HASH') {
14929: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14930: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14931: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14932: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14933: }
14934: if ($privkey && $pubkey) {
14935: $captcha = 'recaptcha';
14936: } else {
14937: $captcha = 'original';
14938: }
14939: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14940: $captcha = 'original';
14941: }
1.1094 raeburn 14942: }
1.1095 raeburn 14943: } else {
14944: $captcha = 'captcha';
14945: }
14946: } elsif ($context eq 'login') {
14947: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14948: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14949: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14950: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14951: if ($privkey && $pubkey) {
14952: $captcha = 'recaptcha';
1.1095 raeburn 14953: } else {
14954: $captcha = 'original';
1.1094 raeburn 14955: }
1.1095 raeburn 14956: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14957: $captcha = 'original';
1.1094 raeburn 14958: }
14959: }
14960: return ($captcha,$pubkey,$privkey);
14961: }
14962:
14963: sub create_captcha {
14964: my %captcha_params = &captcha_settings();
14965: my ($output,$maxtries,$tries) = ('',10,0);
14966: while ($tries < $maxtries) {
14967: $tries ++;
14968: my $captcha = Authen::Captcha->new (
14969: output_folder => $captcha_params{'output_dir'},
14970: data_folder => $captcha_params{'db_dir'},
14971: );
14972: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14973:
14974: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14975: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14976: &mt('Type in the letters/numbers shown below').' '.
14977: '<input type="text" size="5" name="code" value="" /><br />'.
1.1172 raeburn 14978: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 14979: last;
14980: }
14981: }
14982: return $output;
14983: }
14984:
14985: sub captcha_settings {
14986: my %captcha_params = (
14987: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14988: www_output_dir => "/captchaspool",
14989: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14990: numchars => '5',
14991: );
14992: return %captcha_params;
14993: }
14994:
14995: sub check_captcha {
14996: my ($captcha_chk,$captcha_error);
14997: my $code = $env{'form.code'};
14998: my $md5sum = $env{'form.crypt'};
14999: my %captcha_params = &captcha_settings();
15000: my $captcha = Authen::Captcha->new(
15001: output_folder => $captcha_params{'output_dir'},
15002: data_folder => $captcha_params{'db_dir'},
15003: );
1.1109 raeburn 15004: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 15005: my %captcha_hash = (
15006: 0 => 'Code not checked (file error)',
15007: -1 => 'Failed: code expired',
15008: -2 => 'Failed: invalid code (not in database)',
15009: -3 => 'Failed: invalid code (code does not match crypt)',
15010: );
15011: if ($captcha_chk != 1) {
15012: $captcha_error = $captcha_hash{$captcha_chk}
15013: }
15014: return ($captcha_chk,$captcha_error);
15015: }
15016:
15017: sub create_recaptcha {
15018: my ($pubkey) = @_;
1.1153 raeburn 15019: my $use_ssl;
15020: if ($ENV{'SERVER_PORT'} == 443) {
15021: $use_ssl = 1;
15022: }
1.1094 raeburn 15023: my $captcha = Captcha::reCAPTCHA->new;
15024: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 15025: $captcha->get_html($pubkey,undef,$use_ssl).
1.1094 raeburn 15026: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 15027: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 15028: '<br /><br />';
15029: }
15030:
15031: sub check_recaptcha {
15032: my ($privkey) = @_;
15033: my $captcha_chk;
15034: my $captcha = Captcha::reCAPTCHA->new;
15035: my $captcha_result =
15036: $captcha->check_answer(
15037: $privkey,
15038: $ENV{'REMOTE_ADDR'},
15039: $env{'form.recaptcha_challenge_field'},
15040: $env{'form.recaptcha_response_field'},
15041: );
15042: if ($captcha_result->{is_valid}) {
15043: $captcha_chk = 1;
15044: }
15045: return $captcha_chk;
15046: }
15047:
1.1161 raeburn 15048: sub cleanup_html {
15049: my ($incoming) = @_;
15050: my $outgoing;
15051: if ($incoming ne '') {
15052: $outgoing = $incoming;
15053: $outgoing =~ s/;/;/g;
15054: $outgoing =~ s/\#/#/g;
15055: $outgoing =~ s/\&/&/g;
15056: $outgoing =~ s/</</g;
15057: $outgoing =~ s/>/>/g;
15058: $outgoing =~ s/\(/(/g;
15059: $outgoing =~ s/\)/)/g;
15060: $outgoing =~ s/"/"/g;
15061: $outgoing =~ s/'/'/g;
15062: $outgoing =~ s/\$/$/g;
15063: $outgoing =~ s{/}{/}g;
15064: $outgoing =~ s/=/=/g;
15065: $outgoing =~ s/\\/\/g
15066: }
15067: return $outgoing;
15068: }
15069:
1.41 ng 15070: =pod
15071:
15072: =back
15073:
1.112 bowersj2 15074: =cut
1.41 ng 15075:
1.112 bowersj2 15076: 1;
15077: __END__;
1.41 ng 15078:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>