Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.14
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.14! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.13 2012/08/07 13:15:28 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.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.1075.2.14! raeburn 73: use Authen::Captcha;
! 74: use Captcha::reCAPTCHA;
1.117 www 75:
1.517 raeburn 76: # ---------------------------------------------- Designs
77: use vars qw(%defaultdesign);
78:
1.22 www 79: my $readit;
80:
1.517 raeburn 81:
1.157 matthew 82: ##
83: ## Global Variables
84: ##
1.46 matthew 85:
1.643 foxr 86:
87: # ----------------------------------------------- SSI with retries:
88: #
89:
90: =pod
91:
1.648 raeburn 92: =head1 Server Side include with retries:
1.643 foxr 93:
94: =over 4
95:
1.648 raeburn 96: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 97:
98: Performs an ssi with some number of retries. Retries continue either
99: until the result is ok or until the retry count supplied by the
100: caller is exhausted.
101:
102: Inputs:
1.648 raeburn 103:
104: =over 4
105:
1.643 foxr 106: resource - Identifies the resource to insert.
1.648 raeburn 107:
1.643 foxr 108: retries - Count of the number of retries allowed.
1.648 raeburn 109:
1.643 foxr 110: form - Hash that identifies the rendering options.
111:
1.648 raeburn 112: =back
113:
114: Returns:
115:
116: =over 4
117:
1.643 foxr 118: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 119:
1.643 foxr 120: response - The response from the last attempt (which may or may not have been successful.
121:
1.648 raeburn 122: =back
123:
124: =back
125:
1.643 foxr 126: =cut
127:
128: sub ssi_with_retries {
129: my ($resource, $retries, %form) = @_;
130:
131:
132: my $ok = 0; # True if we got a good response.
133: my $content;
134: my $response;
135:
136: # Try to get the ssi done. within the retries count:
137:
138: do {
139: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
140: $ok = $response->is_success;
1.650 www 141: if (!$ok) {
142: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
143: }
1.643 foxr 144: $retries--;
145: } while (!$ok && ($retries > 0));
146:
147: if (!$ok) {
148: $content = ''; # On error return an empty content.
149: }
150: return ($content, $response);
151:
152: }
153:
154:
155:
1.20 www 156: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 157: my %language;
1.124 www 158: my %supported_language;
1.1048 foxr 159: my %latex_language; # For choosing hyphenation in <transl..>
160: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 161: my %cprtag;
1.192 taceyjo1 162: my %scprtag;
1.351 www 163: my %fe; my %fd; my %fm;
1.41 ng 164: my %category_extensions;
1.12 harris41 165:
1.46 matthew 166: # ---------------------------------------------- Thesaurus variables
1.144 matthew 167: #
168: # %Keywords:
169: # A hash used by &keyword to determine if a word is considered a keyword.
170: # $thesaurus_db_file
171: # Scalar containing the full path to the thesaurus database.
1.46 matthew 172:
173: my %Keywords;
174: my $thesaurus_db_file;
175:
1.144 matthew 176: #
177: # Initialize values from language.tab, copyright.tab, filetypes.tab,
178: # thesaurus.tab, and filecategories.tab.
179: #
1.18 www 180: BEGIN {
1.46 matthew 181: # Variable initialization
182: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
183: #
1.22 www 184: unless ($readit) {
1.12 harris41 185: # ------------------------------------------------------------------- languages
186: {
1.158 raeburn 187: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
188: '/language.tab';
189: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 190: while (my $line = <$fh>) {
191: next if ($line=~/^\#/);
192: chomp($line);
1.1048 foxr 193: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 194: $language{$key}=$val.' - '.$enc;
195: if ($sup) {
196: $supported_language{$key}=$sup;
197: }
1.1048 foxr 198: if ($latex) {
199: $latex_language_bykey{$key} = $latex;
200: $latex_language{$two} = $latex;
201: }
1.158 raeburn 202: }
203: close($fh);
204: }
1.12 harris41 205: }
206: # ------------------------------------------------------------------ copyrights
207: {
1.158 raeburn 208: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
209: '/copyright.tab';
210: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 211: while (my $line = <$fh>) {
212: next if ($line=~/^\#/);
213: chomp($line);
214: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 215: $cprtag{$key}=$val;
216: }
217: close($fh);
218: }
1.12 harris41 219: }
1.351 www 220: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 221: {
222: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/source_copyright.tab';
224: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line =~ /^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 229: $scprtag{$key}=$val;
230: }
231: close($fh);
232: }
233: }
1.63 www 234:
1.517 raeburn 235: # -------------------------------------------------------------- default domain designs
1.63 www 236: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 237: my $designfile = $designdir.'/default.tab';
238: if ( open (my $fh,"<$designfile") ) {
239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\=/,$line));
243: if ($val) { $defaultdesign{$key}=$val; }
244: }
245: close($fh);
1.63 www 246: }
247:
1.15 harris41 248: # ------------------------------------------------------------- file categories
249: {
1.158 raeburn 250: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
251: '/filecategories.tab';
252: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 257: push @{$category_extensions{lc($category)}},$extension;
258: }
259: close($fh);
260: }
261:
1.15 harris41 262: }
1.12 harris41 263: # ------------------------------------------------------------------ file types
264: {
1.158 raeburn 265: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
266: '/filetypes.tab';
267: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 268: while (my $line = <$fh>) {
269: next if ($line =~ /^\#/);
270: chomp($line);
271: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 272: if ($descr ne '') {
273: $fe{$ending}=lc($emb);
274: $fd{$ending}=$descr;
1.351 www 275: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 276: }
277: }
278: close($fh);
279: }
1.12 harris41 280: }
1.22 www 281: &Apache::lonnet::logthis(
1.705 tempelho 282: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 283: $readit=1;
1.46 matthew 284: } # end of unless($readit)
1.32 matthew 285:
286: }
1.112 bowersj2 287:
1.42 matthew 288: ###############################################################
289: ## HTML and Javascript Helper Functions ##
290: ###############################################################
291:
292: =pod
293:
1.112 bowersj2 294: =head1 HTML and Javascript Functions
1.42 matthew 295:
1.112 bowersj2 296: =over 4
297:
1.648 raeburn 298: =item * &browser_and_searcher_javascript()
1.112 bowersj2 299:
300: X<browsing, javascript>X<searching, javascript>Returns a string
301: containing javascript with two functions, C<openbrowser> and
302: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
303: tags.
1.42 matthew 304:
1.648 raeburn 305: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 306:
307: inputs: formname, elementname, only, omit
308:
309: formname and elementname indicate the name of the html form and name of
310: the element that the results of the browsing selection are to be placed in.
311:
312: Specifying 'only' will restrict the browser to displaying only files
1.185 www 313: with the given extension. Can be a comma separated list.
1.42 matthew 314:
315: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 316: with the given extension. Can be a comma separated list.
1.42 matthew 317:
1.648 raeburn 318: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 319:
320: Inputs: formname, elementname
321:
322: formname and elementname specify the name of the html form and the name
323: of the element the selection from the search results will be placed in.
1.542 raeburn 324:
1.42 matthew 325: =cut
326:
327: sub browser_and_searcher_javascript {
1.199 albertel 328: my ($mode)=@_;
329: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 330: my $resurl=&escape_single(&lastresurl());
1.42 matthew 331: return <<END;
1.219 albertel 332: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 333: var editbrowser = null;
1.135 albertel 334: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 335: var url = '$resurl/?';
1.42 matthew 336: if (editbrowser == null) {
337: url += 'launch=1&';
338: }
339: url += 'catalogmode=interactive&';
1.199 albertel 340: url += 'mode=$mode&';
1.611 albertel 341: url += 'inhibitmenu=yes&';
1.42 matthew 342: url += 'form=' + formname + '&';
343: if (only != null) {
344: url += 'only=' + only + '&';
1.217 albertel 345: } else {
346: url += 'only=&';
347: }
1.42 matthew 348: if (omit != null) {
349: url += 'omit=' + omit + '&';
1.217 albertel 350: } else {
351: url += 'omit=&';
352: }
1.135 albertel 353: if (titleelement != null) {
354: url += 'titleelement=' + titleelement + '&';
1.217 albertel 355: } else {
356: url += 'titleelement=&';
357: }
1.42 matthew 358: url += 'element=' + elementname + '';
359: var title = 'Browser';
1.435 albertel 360: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 361: options += ',width=700,height=600';
362: editbrowser = open(url,title,options,'1');
363: editbrowser.focus();
364: }
365: var editsearcher;
1.135 albertel 366: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 367: var url = '/adm/searchcat?';
368: if (editsearcher == null) {
369: url += 'launch=1&';
370: }
371: url += 'catalogmode=interactive&';
1.199 albertel 372: url += 'mode=$mode&';
1.42 matthew 373: url += 'form=' + formname + '&';
1.135 albertel 374: if (titleelement != null) {
375: url += 'titleelement=' + titleelement + '&';
1.217 albertel 376: } else {
377: url += 'titleelement=&';
378: }
1.42 matthew 379: url += 'element=' + elementname + '';
380: var title = 'Search';
1.435 albertel 381: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 382: options += ',width=700,height=600';
383: editsearcher = open(url,title,options,'1');
384: editsearcher.focus();
385: }
1.219 albertel 386: // END LON-CAPA Internal -->
1.42 matthew 387: END
1.170 www 388: }
389:
390: sub lastresurl {
1.258 albertel 391: if ($env{'environment.lastresurl'}) {
392: return $env{'environment.lastresurl'}
1.170 www 393: } else {
394: return '/res';
395: }
396: }
397:
398: sub storeresurl {
399: my $resurl=&Apache::lonnet::clutter(shift);
400: unless ($resurl=~/^\/res/) { return 0; }
401: $resurl=~s/\/$//;
402: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 403: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 404: return 1;
1.42 matthew 405: }
406:
1.74 www 407: sub studentbrowser_javascript {
1.111 www 408: unless (
1.258 albertel 409: (($env{'request.course.id'}) &&
1.302 albertel 410: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
411: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
412: '/'.$env{'request.course.sec'})
413: ))
1.258 albertel 414: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 415: ) { return ''; }
1.74 www 416: return (<<'ENDSTDBRW');
1.776 bisitz 417: <script type="text/javascript" language="Javascript">
1.824 bisitz 418: // <![CDATA[
1.74 www 419: var stdeditbrowser;
1.999 www 420: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 421: var url = '/adm/pickstudent?';
422: var filter;
1.558 albertel 423: if (!ignorefilter) {
424: eval('filter=document.'+formname+'.'+uname+'.value;');
425: }
1.74 www 426: if (filter != null) {
427: if (filter != '') {
428: url += 'filter='+filter+'&';
429: }
430: }
431: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 432: '&udomelement='+udom+
433: '&clicker='+clicker;
1.111 www 434: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 435: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 436: var title = 'Student_Browser';
1.74 www 437: var options = 'scrollbars=1,resizable=1,menubar=0';
438: options += ',width=700,height=600';
439: stdeditbrowser = open(url,title,options,'1');
440: stdeditbrowser.focus();
441: }
1.824 bisitz 442: // ]]>
1.74 www 443: </script>
444: ENDSTDBRW
445: }
1.42 matthew 446:
1.1003 www 447: sub resourcebrowser_javascript {
448: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 449: return (<<'ENDRESBRW');
1.1003 www 450: <script type="text/javascript" language="Javascript">
451: // <![CDATA[
452: var reseditbrowser;
1.1004 www 453: function openresbrowser(formname,reslink) {
1.1005 www 454: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 455: var title = 'Resource_Browser';
456: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 457: options += ',width=700,height=500';
1.1004 www 458: reseditbrowser = open(url,title,options,'1');
459: reseditbrowser.focus();
1.1003 www 460: }
461: // ]]>
462: </script>
1.1004 www 463: ENDRESBRW
1.1003 www 464: }
465:
1.74 www 466: sub selectstudent_link {
1.999 www 467: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
468: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
469: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
470: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 471: if ($env{'request.course.id'}) {
1.302 albertel 472: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
473: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
474: '/'.$env{'request.course.sec'})) {
1.111 www 475: return '';
476: }
1.999 www 477: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 478: if ($courseadvonly) {
479: $callargs .= ",'',1,1";
480: }
481: return '<span class="LC_nobreak">'.
482: '<a href="javascript:openstdbrowser('.$callargs.');">'.
483: &mt('Select User').'</a></span>';
1.74 www 484: }
1.258 albertel 485: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 486: $callargs .= ",'',1";
1.793 raeburn 487: return '<span class="LC_nobreak">'.
488: '<a href="javascript:openstdbrowser('.$callargs.');">'.
489: &mt('Select User').'</a></span>';
1.111 www 490: }
491: return '';
1.91 www 492: }
493:
1.1004 www 494: sub selectresource_link {
495: my ($form,$reslink,$arg)=@_;
496:
497: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
498: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
499: unless ($env{'request.course.id'}) { return $arg; }
500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openresbrowser('.$callargs.');">'.
502: $arg.'</a></span>';
503: }
504:
505:
506:
1.653 raeburn 507: sub authorbrowser_javascript {
508: return <<"ENDAUTHORBRW";
1.776 bisitz 509: <script type="text/javascript" language="JavaScript">
1.824 bisitz 510: // <![CDATA[
1.653 raeburn 511: var stdeditbrowser;
512:
513: function openauthorbrowser(formname,udom) {
514: var url = '/adm/pickauthor?';
515: url += 'form='+formname+'&roledom='+udom;
516: var title = 'Author_Browser';
517: var options = 'scrollbars=1,resizable=1,menubar=0';
518: options += ',width=700,height=600';
519: stdeditbrowser = open(url,title,options,'1');
520: stdeditbrowser.focus();
521: }
522:
1.824 bisitz 523: // ]]>
1.653 raeburn 524: </script>
525: ENDAUTHORBRW
526: }
527:
1.91 www 528: sub coursebrowser_javascript {
1.909 raeburn 529: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 530: my $wintitle = 'Course_Browser';
1.931 raeburn 531: if ($crstype eq 'Community') {
1.932 raeburn 532: $wintitle = 'Community_Browser';
1.909 raeburn 533: }
1.876 raeburn 534: my $id_functions = &javascript_index_functions();
535: my $output = '
1.776 bisitz 536: <script type="text/javascript" language="JavaScript">
1.824 bisitz 537: // <![CDATA[
1.468 raeburn 538: var stdeditbrowser;'."\n";
1.876 raeburn 539:
540: $output .= <<"ENDSTDBRW";
1.909 raeburn 541: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 542: var url = '/adm/pickcourse?';
1.895 raeburn 543: var formid = getFormIdByName(formname);
1.876 raeburn 544: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 545: if (domainfilter != null) {
546: if (domainfilter != '') {
547: url += 'domainfilter='+domainfilter+'&';
548: }
549: }
1.91 www 550: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 551: '&cdomelement='+udom+
552: '&cnameelement='+desc;
1.468 raeburn 553: if (extra_element !=null && extra_element != '') {
1.594 raeburn 554: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 555: url += '&roleelement='+extra_element;
556: if (domainfilter == null || domainfilter == '') {
557: url += '&domainfilter='+extra_element;
558: }
1.234 raeburn 559: }
1.468 raeburn 560: else {
561: if (formname == 'portform') {
562: url += '&setroles='+extra_element;
1.800 raeburn 563: } else {
564: if (formname == 'rules') {
565: url += '&fixeddom='+extra_element;
566: }
1.468 raeburn 567: }
568: }
1.230 raeburn 569: }
1.909 raeburn 570: if (type != null && type != '') {
571: url += '&type='+type;
572: }
573: if (type_elem != null && type_elem != '') {
574: url += '&typeelement='+type_elem;
575: }
1.872 raeburn 576: if (formname == 'ccrs') {
577: var ownername = document.forms[formid].ccuname.value;
578: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
579: url += '&cloner='+ownername+':'+ownerdom;
580: }
1.293 raeburn 581: if (multflag !=null && multflag != '') {
582: url += '&multiple='+multflag;
583: }
1.909 raeburn 584: var title = '$wintitle';
1.91 www 585: var options = 'scrollbars=1,resizable=1,menubar=0';
586: options += ',width=700,height=600';
587: stdeditbrowser = open(url,title,options,'1');
588: stdeditbrowser.focus();
589: }
1.876 raeburn 590: $id_functions
591: ENDSTDBRW
1.905 raeburn 592: if (($sec_element ne '') || ($role_element ne '')) {
593: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 594: }
595: $output .= '
596: // ]]>
597: </script>';
598: return $output;
599: }
600:
601: sub javascript_index_functions {
602: return <<"ENDJS";
603:
604: function getFormIdByName(formname) {
605: for (var i=0;i<document.forms.length;i++) {
606: if (document.forms[i].name == formname) {
607: return i;
608: }
609: }
610: return -1;
611: }
612:
613: function getIndexByName(formid,item) {
614: for (var i=0;i<document.forms[formid].elements.length;i++) {
615: if (document.forms[formid].elements[i].name == item) {
616: return i;
617: }
618: }
619: return -1;
620: }
1.468 raeburn 621:
1.876 raeburn 622: function getDomainFromSelectbox(formname,udom) {
623: var userdom;
624: var formid = getFormIdByName(formname);
625: if (formid > -1) {
626: var domid = getIndexByName(formid,udom);
627: if (domid > -1) {
628: if (document.forms[formid].elements[domid].type == 'select-one') {
629: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
630: }
631: if (document.forms[formid].elements[domid].type == 'hidden') {
632: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 633: }
634: }
635: }
1.876 raeburn 636: return userdom;
637: }
638:
639: ENDJS
1.468 raeburn 640:
1.876 raeburn 641: }
642:
1.1017 raeburn 643: sub javascript_array_indexof {
1.1018 raeburn 644: return <<ENDJS;
1.1017 raeburn 645: <script type="text/javascript" language="JavaScript">
646: // <![CDATA[
647:
648: if (!Array.prototype.indexOf) {
649: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
650: "use strict";
651: if (this === void 0 || this === null) {
652: throw new TypeError();
653: }
654: var t = Object(this);
655: var len = t.length >>> 0;
656: if (len === 0) {
657: return -1;
658: }
659: var n = 0;
660: if (arguments.length > 0) {
661: n = Number(arguments[1]);
662: if (n !== n) { // shortcut for verifying if it's NaN
663: n = 0;
664: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
665: n = (n > 0 || -1) * Math.floor(Math.abs(n));
666: }
667: }
668: if (n >= len) {
669: return -1;
670: }
671: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
672: for (; k < len; k++) {
673: if (k in t && t[k] === searchElement) {
674: return k;
675: }
676: }
677: return -1;
678: }
679: }
680:
681: // ]]>
682: </script>
683:
684: ENDJS
685:
686: }
687:
1.876 raeburn 688: sub userbrowser_javascript {
689: my $id_functions = &javascript_index_functions();
690: return <<"ENDUSERBRW";
691:
1.888 raeburn 692: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 693: var url = '/adm/pickuser?';
694: var userdom = getDomainFromSelectbox(formname,udom);
695: if (userdom != null) {
696: if (userdom != '') {
697: url += 'srchdom='+userdom+'&';
698: }
699: }
700: url += 'form=' + formname + '&unameelement='+uname+
701: '&udomelement='+udom+
702: '&ulastelement='+ulast+
703: '&ufirstelement='+ufirst+
704: '&uemailelement='+uemail+
1.881 raeburn 705: '&hideudomelement='+hideudom+
706: '&coursedom='+crsdom;
1.888 raeburn 707: if ((caller != null) && (caller != undefined)) {
708: url += '&caller='+caller;
709: }
1.876 raeburn 710: var title = 'User_Browser';
711: var options = 'scrollbars=1,resizable=1,menubar=0';
712: options += ',width=700,height=600';
713: var stdeditbrowser = open(url,title,options,'1');
714: stdeditbrowser.focus();
715: }
716:
1.888 raeburn 717: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 718: var formid = getFormIdByName(formname);
719: if (formid > -1) {
1.888 raeburn 720: var unameid = getIndexByName(formid,uname);
1.876 raeburn 721: var domid = getIndexByName(formid,udom);
722: var hidedomid = getIndexByName(formid,origdom);
723: if (hidedomid > -1) {
724: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 725: var unameval = document.forms[formid].elements[unameid].value;
726: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
727: if (domid > -1) {
728: var slct = document.forms[formid].elements[domid];
729: if (slct.type == 'select-one') {
730: var i;
731: for (i=0;i<slct.length;i++) {
732: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
733: }
734: }
735: if (slct.type == 'hidden') {
736: slct.value = fixeddom;
1.876 raeburn 737: }
738: }
1.468 raeburn 739: }
740: }
741: }
1.876 raeburn 742: return;
743: }
744:
745: $id_functions
746: ENDUSERBRW
1.468 raeburn 747: }
748:
749: sub setsec_javascript {
1.905 raeburn 750: my ($sec_element,$formname,$role_element) = @_;
751: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
752: $communityrolestr);
753: if ($role_element ne '') {
754: my @allroles = ('st','ta','ep','in','ad');
755: foreach my $crstype ('Course','Community') {
756: if ($crstype eq 'Community') {
757: foreach my $role (@allroles) {
758: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
759: }
760: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
761: } else {
762: foreach my $role (@allroles) {
763: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
764: }
765: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
766: }
767: }
768: $rolestr = '"'.join('","',@allroles).'"';
769: $courserolestr = '"'.join('","',@courserolenames).'"';
770: $communityrolestr = '"'.join('","',@communityrolenames).'"';
771: }
1.468 raeburn 772: my $setsections = qq|
773: function setSect(sectionlist) {
1.629 raeburn 774: var sectionsArray = new Array();
775: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
776: sectionsArray = sectionlist.split(",");
777: }
1.468 raeburn 778: var numSections = sectionsArray.length;
779: document.$formname.$sec_element.length = 0;
780: if (numSections == 0) {
781: document.$formname.$sec_element.multiple=false;
782: document.$formname.$sec_element.size=1;
783: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
784: } else {
785: if (numSections == 1) {
786: document.$formname.$sec_element.multiple=false;
787: document.$formname.$sec_element.size=1;
788: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
789: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
790: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
791: } else {
792: for (var i=0; i<numSections; i++) {
793: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
794: }
795: document.$formname.$sec_element.multiple=true
796: if (numSections < 3) {
797: document.$formname.$sec_element.size=numSections;
798: } else {
799: document.$formname.$sec_element.size=3;
800: }
801: document.$formname.$sec_element.options[0].selected = false
802: }
803: }
1.91 www 804: }
1.905 raeburn 805:
806: function setRole(crstype) {
1.468 raeburn 807: |;
1.905 raeburn 808: if ($role_element eq '') {
809: $setsections .= ' return;
810: }
811: ';
812: } else {
813: $setsections .= qq|
814: var elementLength = document.$formname.$role_element.length;
815: var allroles = Array($rolestr);
816: var courserolenames = Array($courserolestr);
817: var communityrolenames = Array($communityrolestr);
818: if (elementLength != undefined) {
819: if (document.$formname.$role_element.options[5].value == 'cc') {
820: if (crstype == 'Course') {
821: return;
822: } else {
823: allroles[5] = 'co';
824: for (var i=0; i<6; i++) {
825: document.$formname.$role_element.options[i].value = allroles[i];
826: document.$formname.$role_element.options[i].text = communityrolenames[i];
827: }
828: }
829: } else {
830: if (crstype == 'Community') {
831: return;
832: } else {
833: allroles[5] = 'cc';
834: for (var i=0; i<6; i++) {
835: document.$formname.$role_element.options[i].value = allroles[i];
836: document.$formname.$role_element.options[i].text = courserolenames[i];
837: }
838: }
839: }
840: }
841: return;
842: }
843: |;
844: }
1.468 raeburn 845: return $setsections;
846: }
847:
1.91 www 848: sub selectcourse_link {
1.909 raeburn 849: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
850: $typeelement) = @_;
851: my $type = $selecttype;
1.871 raeburn 852: my $linktext = &mt('Select Course');
853: if ($selecttype eq 'Community') {
1.909 raeburn 854: $linktext = &mt('Select Community');
1.906 raeburn 855: } elsif ($selecttype eq 'Course/Community') {
856: $linktext = &mt('Select Course/Community');
1.909 raeburn 857: $type = '';
1.1019 raeburn 858: } elsif ($selecttype eq 'Select') {
859: $linktext = &mt('Select');
860: $type = '';
1.871 raeburn 861: }
1.787 bisitz 862: return '<span class="LC_nobreak">'
863: ."<a href='"
864: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
865: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 866: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 867: ."'>".$linktext.'</a>'
1.787 bisitz 868: .'</span>';
1.74 www 869: }
1.42 matthew 870:
1.653 raeburn 871: sub selectauthor_link {
872: my ($form,$udom)=@_;
873: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
874: &mt('Select Author').'</a>';
875: }
876:
1.876 raeburn 877: sub selectuser_link {
1.881 raeburn 878: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 879: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 880: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 881: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 882: ');">'.$linktext.'</a>';
1.876 raeburn 883: }
884:
1.273 raeburn 885: sub check_uncheck_jscript {
886: my $jscript = <<"ENDSCRT";
887: function checkAll(field) {
888: if (field.length > 0) {
889: for (i = 0; i < field.length; i++) {
1.1075.2.14! raeburn 890: if (!field[i].disabled) {
! 891: field[i].checked = true;
! 892: }
1.273 raeburn 893: }
894: } else {
1.1075.2.14! raeburn 895: if (!field.disabled) {
! 896: field.checked = true;
! 897: }
1.273 raeburn 898: }
899: }
900:
901: function uncheckAll(field) {
902: if (field.length > 0) {
903: for (i = 0; i < field.length; i++) {
904: field[i].checked = false ;
1.543 albertel 905: }
906: } else {
1.273 raeburn 907: field.checked = false ;
908: }
909: }
910: ENDSCRT
911: return $jscript;
912: }
913:
1.656 www 914: sub select_timezone {
1.659 raeburn 915: my ($name,$selected,$onchange,$includeempty)=@_;
916: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
917: if ($includeempty) {
918: $output .= '<option value=""';
919: if (($selected eq '') || ($selected eq 'local')) {
920: $output .= ' selected="selected" ';
921: }
922: $output .= '> </option>';
923: }
1.657 raeburn 924: my @timezones = DateTime::TimeZone->all_names;
925: foreach my $tzone (@timezones) {
926: $output.= '<option value="'.$tzone.'"';
927: if ($tzone eq $selected) {
928: $output.=' selected="selected"';
929: }
930: $output.=">$tzone</option>\n";
1.656 www 931: }
932: $output.="</select>";
933: return $output;
934: }
1.273 raeburn 935:
1.687 raeburn 936: sub select_datelocale {
937: my ($name,$selected,$onchange,$includeempty)=@_;
938: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
939: if ($includeempty) {
940: $output .= '<option value=""';
941: if ($selected eq '') {
942: $output .= ' selected="selected" ';
943: }
944: $output .= '> </option>';
945: }
946: my (@possibles,%locale_names);
947: my @locales = DateTime::Locale::Catalog::Locales;
948: foreach my $locale (@locales) {
949: if (ref($locale) eq 'HASH') {
950: my $id = $locale->{'id'};
951: if ($id ne '') {
952: my $en_terr = $locale->{'en_territory'};
953: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 954: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 955: if (grep(/^en$/,@languages) || !@languages) {
956: if ($en_terr ne '') {
957: $locale_names{$id} = '('.$en_terr.')';
958: } elsif ($native_terr ne '') {
959: $locale_names{$id} = $native_terr;
960: }
961: } else {
962: if ($native_terr ne '') {
963: $locale_names{$id} = $native_terr.' ';
964: } elsif ($en_terr ne '') {
965: $locale_names{$id} = '('.$en_terr.')';
966: }
967: }
968: push (@possibles,$id);
969: }
970: }
971: }
972: foreach my $item (sort(@possibles)) {
973: $output.= '<option value="'.$item.'"';
974: if ($item eq $selected) {
975: $output.=' selected="selected"';
976: }
977: $output.=">$item";
978: if ($locale_names{$item} ne '') {
979: $output.=" $locale_names{$item}</option>\n";
980: }
981: $output.="</option>\n";
982: }
983: $output.="</select>";
984: return $output;
985: }
986:
1.792 raeburn 987: sub select_language {
988: my ($name,$selected,$includeempty) = @_;
989: my %langchoices;
990: if ($includeempty) {
991: %langchoices = ('' => 'No language preference');
992: }
993: foreach my $id (&languageids()) {
994: my $code = &supportedlanguagecode($id);
995: if ($code) {
996: $langchoices{$code} = &plainlanguagedescription($id);
997: }
998: }
1.970 raeburn 999: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1000: }
1001:
1.42 matthew 1002: =pod
1.36 matthew 1003:
1.648 raeburn 1004: =item * &linked_select_forms(...)
1.36 matthew 1005:
1006: linked_select_forms returns a string containing a <script></script> block
1007: and html for two <select> menus. The select menus will be linked in that
1008: changing the value of the first menu will result in new values being placed
1009: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1010: order unless a defined order is provided.
1.36 matthew 1011:
1012: linked_select_forms takes the following ordered inputs:
1013:
1014: =over 4
1015:
1.112 bowersj2 1016: =item * $formname, the name of the <form> tag
1.36 matthew 1017:
1.112 bowersj2 1018: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1019:
1.112 bowersj2 1020: =item * $firstdefault, the default value for the first menu
1.36 matthew 1021:
1.112 bowersj2 1022: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1023:
1.112 bowersj2 1024: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1025:
1.112 bowersj2 1026: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1027:
1.609 raeburn 1028: =item * $menuorder, the order of values in the first menu
1029:
1.41 ng 1030: =back
1031:
1.36 matthew 1032: Below is an example of such a hash. Only the 'text', 'default', and
1033: 'select2' keys must appear as stated. keys(%menu) are the possible
1034: values for the first select menu. The text that coincides with the
1.41 ng 1035: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1036: and text for the second menu are given in the hash pointed to by
1037: $menu{$choice1}->{'select2'}.
1038:
1.112 bowersj2 1039: my %menu = ( A1 => { text =>"Choice A1" ,
1040: default => "B3",
1041: select2 => {
1042: B1 => "Choice B1",
1043: B2 => "Choice B2",
1044: B3 => "Choice B3",
1045: B4 => "Choice B4"
1.609 raeburn 1046: },
1047: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1048: },
1049: A2 => { text =>"Choice A2" ,
1050: default => "C2",
1051: select2 => {
1052: C1 => "Choice C1",
1053: C2 => "Choice C2",
1054: C3 => "Choice C3"
1.609 raeburn 1055: },
1056: order => ['C2','C1','C3'],
1.112 bowersj2 1057: },
1058: A3 => { text =>"Choice A3" ,
1059: default => "D6",
1060: select2 => {
1061: D1 => "Choice D1",
1062: D2 => "Choice D2",
1063: D3 => "Choice D3",
1064: D4 => "Choice D4",
1065: D5 => "Choice D5",
1066: D6 => "Choice D6",
1067: D7 => "Choice D7"
1.609 raeburn 1068: },
1069: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1070: }
1071: );
1.36 matthew 1072:
1073: =cut
1074:
1075: sub linked_select_forms {
1076: my ($formname,
1077: $middletext,
1078: $firstdefault,
1079: $firstselectname,
1080: $secondselectname,
1.609 raeburn 1081: $hashref,
1082: $menuorder,
1.36 matthew 1083: ) = @_;
1084: my $second = "document.$formname.$secondselectname";
1085: my $first = "document.$formname.$firstselectname";
1086: # output the javascript to do the changing
1087: my $result = '';
1.776 bisitz 1088: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1089: $result.="// <![CDATA[\n";
1.36 matthew 1090: $result.="var select2data = new Object();\n";
1091: $" = '","';
1092: my $debug = '';
1093: foreach my $s1 (sort(keys(%$hashref))) {
1094: $result.="select2data.d_$s1 = new Object();\n";
1095: $result.="select2data.d_$s1.def = new String('".
1096: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1097: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1098: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1099: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1100: @s2values = @{$hashref->{$s1}->{'order'}};
1101: }
1.36 matthew 1102: $result.="\"@s2values\");\n";
1103: $result.="select2data.d_$s1.texts = new Array(";
1104: my @s2texts;
1105: foreach my $value (@s2values) {
1106: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1107: }
1108: $result.="\"@s2texts\");\n";
1109: }
1110: $"=' ';
1111: $result.= <<"END";
1112:
1113: function select1_changed() {
1114: // Determine new choice
1115: var newvalue = "d_" + $first.value;
1116: // update select2
1117: var values = select2data[newvalue].values;
1118: var texts = select2data[newvalue].texts;
1119: var select2def = select2data[newvalue].def;
1120: var i;
1121: // out with the old
1122: for (i = 0; i < $second.options.length; i++) {
1123: $second.options[i] = null;
1124: }
1125: // in with the nuclear
1126: for (i=0;i<values.length; i++) {
1127: $second.options[i] = new Option(values[i]);
1.143 matthew 1128: $second.options[i].value = values[i];
1.36 matthew 1129: $second.options[i].text = texts[i];
1130: if (values[i] == select2def) {
1131: $second.options[i].selected = true;
1132: }
1133: }
1134: }
1.824 bisitz 1135: // ]]>
1.36 matthew 1136: </script>
1137: END
1138: # output the initial values for the selection lists
1139: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1140: my @order = sort(keys(%{$hashref}));
1141: if (ref($menuorder) eq 'ARRAY') {
1142: @order = @{$menuorder};
1143: }
1144: foreach my $value (@order) {
1.36 matthew 1145: $result.=" <option value=\"$value\" ";
1.253 albertel 1146: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1147: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1148: }
1149: $result .= "</select>\n";
1150: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1151: $result .= $middletext;
1152: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1153: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1154:
1155: my @secondorder = sort(keys(%select2));
1156: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1157: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1158: }
1159: foreach my $value (@secondorder) {
1.36 matthew 1160: $result.=" <option value=\"$value\" ";
1.253 albertel 1161: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1162: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1163: }
1164: $result .= "</select>\n";
1165: # return $debug;
1166: return $result;
1167: } # end of sub linked_select_forms {
1168:
1.45 matthew 1169: =pod
1.44 bowersj2 1170:
1.973 raeburn 1171: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1172:
1.112 bowersj2 1173: Returns a string corresponding to an HTML link to the given help
1174: $topic, where $topic corresponds to the name of a .tex file in
1175: /home/httpd/html/adm/help/tex, with underscores replaced by
1176: spaces.
1177:
1178: $text will optionally be linked to the same topic, allowing you to
1179: link text in addition to the graphic. If you do not want to link
1180: text, but wish to specify one of the later parameters, pass an
1181: empty string.
1182:
1183: $stayOnPage is a value that will be interpreted as a boolean. If true,
1184: the link will not open a new window. If false, the link will open
1185: a new window using Javascript. (Default is false.)
1186:
1187: $width and $height are optional numerical parameters that will
1188: override the width and height of the popped up window, which may
1.973 raeburn 1189: be useful for certain help topics with big pictures included.
1190:
1191: $imgid is the id of the img tag used for the help icon. This may be
1192: used in a javascript call to switch the image src. See
1193: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1194:
1195: =cut
1196:
1197: sub help_open_topic {
1.973 raeburn 1198: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1199: $text = "" if (not defined $text);
1.44 bowersj2 1200: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1201: $width = 500 if (not defined $width);
1.44 bowersj2 1202: $height = 400 if (not defined $height);
1203: my $filename = $topic;
1204: $filename =~ s/ /_/g;
1205:
1.48 bowersj2 1206: my $template = "";
1207: my $link;
1.572 banghart 1208:
1.159 www 1209: $topic=~s/\W/\_/g;
1.44 bowersj2 1210:
1.572 banghart 1211: if (!$stayOnPage) {
1.1033 www 1212: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1213: } elsif ($stayOnPage eq 'popup') {
1214: $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 1215: } else {
1.48 bowersj2 1216: $link = "/adm/help/${filename}.hlp";
1217: }
1218:
1219: # Add the text
1.755 neumanie 1220: if ($text ne "") {
1.763 bisitz 1221: $template.='<span class="LC_help_open_topic">'
1222: .'<a target="_top" href="'.$link.'">'
1223: .$text.'</a>';
1.48 bowersj2 1224: }
1225:
1.763 bisitz 1226: # (Always) Add the graphic
1.179 matthew 1227: my $title = &mt('Online Help');
1.667 raeburn 1228: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1229: if ($imgid ne '') {
1230: $imgid = ' id="'.$imgid.'"';
1231: }
1.763 bisitz 1232: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1233: .'<img src="'.$helpicon.'" border="0"'
1234: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1235: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1236: .' /></a>';
1237: if ($text ne "") {
1238: $template.='</span>';
1239: }
1.44 bowersj2 1240: return $template;
1241:
1.106 bowersj2 1242: }
1243:
1244: # This is a quicky function for Latex cheatsheet editing, since it
1245: # appears in at least four places
1246: sub helpLatexCheatsheet {
1.1037 www 1247: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1248: my $out;
1.106 bowersj2 1249: my $addOther = '';
1.732 raeburn 1250: if ($topic) {
1.1037 www 1251: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1252: }
1253: $out = '<span>' # Start cheatsheet
1254: .$addOther
1255: .'<span>'
1.1037 www 1256: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1257: .'</span> <span>'
1.1037 www 1258: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1259: .'</span>';
1.732 raeburn 1260: unless ($not_author) {
1.763 bisitz 1261: $out .= ' <span>'
1.1037 www 1262: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1263: .'</span>';
1.732 raeburn 1264: }
1.763 bisitz 1265: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1266: return $out;
1.172 www 1267: }
1268:
1.430 albertel 1269: sub general_help {
1270: my $helptopic='Student_Intro';
1271: if ($env{'request.role'}=~/^(ca|au)/) {
1272: $helptopic='Authoring_Intro';
1.907 raeburn 1273: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1274: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1275: } elsif ($env{'request.role'}=~/^dc/) {
1276: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1277: }
1278: return $helptopic;
1279: }
1280:
1281: sub update_help_link {
1282: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1283: my $origurl = $ENV{'REQUEST_URI'};
1284: $origurl=~s|^/~|/priv/|;
1285: my $timestamp = time;
1286: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1287: $$datum = &escape($$datum);
1288: }
1289:
1290: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1291: my $output .= <<"ENDOUTPUT";
1292: <script type="text/javascript">
1.824 bisitz 1293: // <![CDATA[
1.430 albertel 1294: banner_link = '$banner_link';
1.824 bisitz 1295: // ]]>
1.430 albertel 1296: </script>
1297: ENDOUTPUT
1298: return $output;
1299: }
1300:
1301: # now just updates the help link and generates a blue icon
1.193 raeburn 1302: sub help_open_menu {
1.430 albertel 1303: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1304: = @_;
1.949 droeschl 1305: $stayOnPage = 1;
1.430 albertel 1306: my $output;
1307: if ($component_help) {
1308: if (!$text) {
1309: $output=&help_open_topic($component_help,undef,$stayOnPage,
1310: $width,$height);
1311: } else {
1312: my $help_text;
1313: $help_text=&unescape($topic);
1314: $output='<table><tr><td>'.
1315: &help_open_topic($component_help,$help_text,$stayOnPage,
1316: $width,$height).'</td></tr></table>';
1317: }
1318: }
1319: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1320: return $output.$banner_link;
1321: }
1322:
1323: sub top_nav_help {
1324: my ($text) = @_;
1.436 albertel 1325: $text = &mt($text);
1.949 droeschl 1326: my $stay_on_page = 1;
1327:
1.572 banghart 1328: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1329: : "javascript:helpMenu('open')";
1.572 banghart 1330: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1331:
1.201 raeburn 1332: my $title = &mt('Get help');
1.436 albertel 1333:
1334: return <<"END";
1335: $banner_link
1336: <a href="$link" title="$title">$text</a>
1337: END
1338: }
1339:
1340: sub help_menu_js {
1341: my ($text) = @_;
1.949 droeschl 1342: my $stayOnPage = 1;
1.436 albertel 1343: my $width = 620;
1344: my $height = 600;
1.430 albertel 1345: my $helptopic=&general_help();
1346: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1347: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1348: my $start_page =
1349: &Apache::loncommon::start_page('Help Menu', undef,
1350: {'frameset' => 1,
1351: 'js_ready' => 1,
1352: 'add_entries' => {
1353: 'border' => '0',
1.579 raeburn 1354: 'rows' => "110,*",},});
1.331 albertel 1355: my $end_page =
1356: &Apache::loncommon::end_page({'frameset' => 1,
1357: 'js_ready' => 1,});
1358:
1.436 albertel 1359: my $template .= <<"ENDTEMPLATE";
1360: <script type="text/javascript">
1.877 bisitz 1361: // <![CDATA[
1.253 albertel 1362: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1363: var banner_link = '';
1.243 raeburn 1364: function helpMenu(target) {
1365: var caller = this;
1366: if (target == 'open') {
1367: var newWindow = null;
1368: try {
1.262 albertel 1369: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1370: }
1371: catch(error) {
1372: writeHelp(caller);
1373: return;
1374: }
1375: if (newWindow) {
1376: caller = newWindow;
1377: }
1.193 raeburn 1378: }
1.243 raeburn 1379: writeHelp(caller);
1380: return;
1381: }
1382: function writeHelp(caller) {
1.1072 raeburn 1383: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1384: caller.document.close()
1385: caller.focus()
1.193 raeburn 1386: }
1.877 bisitz 1387: // END LON-CAPA Internal -->
1.253 albertel 1388: // ]]>
1.436 albertel 1389: </script>
1.193 raeburn 1390: ENDTEMPLATE
1391: return $template;
1392: }
1393:
1.172 www 1394: sub help_open_bug {
1395: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1396: unless ($env{'user.adv'}) { return ''; }
1.172 www 1397: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1398: $text = "" if (not defined $text);
1399: $stayOnPage=1;
1.184 albertel 1400: $width = 600 if (not defined $width);
1401: $height = 600 if (not defined $height);
1.172 www 1402:
1403: $topic=~s/\W+/\+/g;
1404: my $link='';
1405: my $template='';
1.379 albertel 1406: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1407: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1408: if (!$stayOnPage)
1409: {
1410: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1411: }
1412: else
1413: {
1414: $link = $url;
1415: }
1416: # Add the text
1417: if ($text ne "")
1418: {
1419: $template .=
1420: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1421: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1422: }
1423:
1424: # Add the graphic
1.179 matthew 1425: my $title = &mt('Report a Bug');
1.215 albertel 1426: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1427: $template .= <<"ENDTEMPLATE";
1.436 albertel 1428: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1429: ENDTEMPLATE
1430: if ($text ne '') { $template.='</td></tr></table>' };
1431: return $template;
1432:
1433: }
1434:
1435: sub help_open_faq {
1436: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1437: unless ($env{'user.adv'}) { return ''; }
1.172 www 1438: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1439: $text = "" if (not defined $text);
1440: $stayOnPage=1;
1441: $width = 350 if (not defined $width);
1442: $height = 400 if (not defined $height);
1443:
1444: $topic=~s/\W+/\+/g;
1445: my $link='';
1446: my $template='';
1447: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1448: if (!$stayOnPage)
1449: {
1450: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1451: }
1452: else
1453: {
1454: $link = $url;
1455: }
1456:
1457: # Add the text
1458: if ($text ne "")
1459: {
1460: $template .=
1.173 www 1461: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1462: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1463: }
1464:
1465: # Add the graphic
1.179 matthew 1466: my $title = &mt('View the FAQ');
1.215 albertel 1467: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1468: $template .= <<"ENDTEMPLATE";
1.436 albertel 1469: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1470: ENDTEMPLATE
1471: if ($text ne '') { $template.='</td></tr></table>' };
1472: return $template;
1473:
1.44 bowersj2 1474: }
1.37 matthew 1475:
1.180 matthew 1476: ###############################################################
1477: ###############################################################
1478:
1.45 matthew 1479: =pod
1480:
1.648 raeburn 1481: =item * &change_content_javascript():
1.256 matthew 1482:
1483: This and the next function allow you to create small sections of an
1484: otherwise static HTML page that you can update on the fly with
1485: Javascript, even in Netscape 4.
1486:
1487: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1488: must be written to the HTML page once. It will prove the Javascript
1489: function "change(name, content)". Calling the change function with the
1490: name of the section
1491: you want to update, matching the name passed to C<changable_area>, and
1492: the new content you want to put in there, will put the content into
1493: that area.
1494:
1495: B<Note>: Netscape 4 only reserves enough space for the changable area
1496: to contain room for the original contents. You need to "make space"
1497: for whatever changes you wish to make, and be B<sure> to check your
1498: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1499: it's adequate for updating a one-line status display, but little more.
1500: This script will set the space to 100% width, so you only need to
1501: worry about height in Netscape 4.
1502:
1503: Modern browsers are much less limiting, and if you can commit to the
1504: user not using Netscape 4, this feature may be used freely with
1505: pretty much any HTML.
1506:
1507: =cut
1508:
1509: sub change_content_javascript {
1510: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1511: if ($env{'browser.type'} eq 'netscape' &&
1512: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1513: return (<<NETSCAPE4);
1514: function change(name, content) {
1515: doc = document.layers[name+"___escape"].layers[0].document;
1516: doc.open();
1517: doc.write(content);
1518: doc.close();
1519: }
1520: NETSCAPE4
1521: } else {
1522: # Otherwise, we need to use semi-standards-compliant code
1523: # (technically, "innerHTML" isn't standard but the equivalent
1524: # is really scary, and every useful browser supports it
1525: return (<<DOMBASED);
1526: function change(name, content) {
1527: element = document.getElementById(name);
1528: element.innerHTML = content;
1529: }
1530: DOMBASED
1531: }
1532: }
1533:
1534: =pod
1535:
1.648 raeburn 1536: =item * &changable_area($name,$origContent):
1.256 matthew 1537:
1538: This provides a "changable area" that can be modified on the fly via
1539: the Javascript code provided in C<change_content_javascript>. $name is
1540: the name you will use to reference the area later; do not repeat the
1541: same name on a given HTML page more then once. $origContent is what
1542: the area will originally contain, which can be left blank.
1543:
1544: =cut
1545:
1546: sub changable_area {
1547: my ($name, $origContent) = @_;
1548:
1.258 albertel 1549: if ($env{'browser.type'} eq 'netscape' &&
1550: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1551: # If this is netscape 4, we need to use the Layer tag
1552: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1553: } else {
1554: return "<span id='$name'>$origContent</span>";
1555: }
1556: }
1557:
1558: =pod
1559:
1.648 raeburn 1560: =item * &viewport_geometry_js
1.590 raeburn 1561:
1562: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1563:
1564: =cut
1565:
1566:
1567: sub viewport_geometry_js {
1568: return <<"GEOMETRY";
1569: var Geometry = {};
1570: function init_geometry() {
1571: if (Geometry.init) { return };
1572: Geometry.init=1;
1573: if (window.innerHeight) {
1574: Geometry.getViewportHeight = function() { return window.innerHeight; };
1575: Geometry.getViewportWidth = function() { return window.innerWidth; };
1576: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1577: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1578: }
1579: else if (document.documentElement && document.documentElement.clientHeight) {
1580: Geometry.getViewportHeight =
1581: function() { return document.documentElement.clientHeight; };
1582: Geometry.getViewportWidth =
1583: function() { return document.documentElement.clientWidth; };
1584:
1585: Geometry.getHorizontalScroll =
1586: function() { return document.documentElement.scrollLeft; };
1587: Geometry.getVerticalScroll =
1588: function() { return document.documentElement.scrollTop; };
1589: }
1590: else if (document.body.clientHeight) {
1591: Geometry.getViewportHeight =
1592: function() { return document.body.clientHeight; };
1593: Geometry.getViewportWidth =
1594: function() { return document.body.clientWidth; };
1595: Geometry.getHorizontalScroll =
1596: function() { return document.body.scrollLeft; };
1597: Geometry.getVerticalScroll =
1598: function() { return document.body.scrollTop; };
1599: }
1600: }
1601:
1602: GEOMETRY
1603: }
1604:
1605: =pod
1606:
1.648 raeburn 1607: =item * &viewport_size_js()
1.590 raeburn 1608:
1609: 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.
1610:
1611: =cut
1612:
1613: sub viewport_size_js {
1614: my $geometry = &viewport_geometry_js();
1615: return <<"DIMS";
1616:
1617: $geometry
1618:
1619: function getViewportDims(width,height) {
1620: init_geometry();
1621: width.value = Geometry.getViewportWidth();
1622: height.value = Geometry.getViewportHeight();
1623: return;
1624: }
1625:
1626: DIMS
1627: }
1628:
1629: =pod
1630:
1.648 raeburn 1631: =item * &resize_textarea_js()
1.565 albertel 1632:
1633: emits the needed javascript to resize a textarea to be as big as possible
1634:
1635: creates a function resize_textrea that takes two IDs first should be
1636: the id of the element to resize, second should be the id of a div that
1637: surrounds everything that comes after the textarea, this routine needs
1638: to be attached to the <body> for the onload and onresize events.
1639:
1.648 raeburn 1640: =back
1.565 albertel 1641:
1642: =cut
1643:
1644: sub resize_textarea_js {
1.590 raeburn 1645: my $geometry = &viewport_geometry_js();
1.565 albertel 1646: return <<"RESIZE";
1647: <script type="text/javascript">
1.824 bisitz 1648: // <![CDATA[
1.590 raeburn 1649: $geometry
1.565 albertel 1650:
1.588 albertel 1651: function getX(element) {
1652: var x = 0;
1653: while (element) {
1654: x += element.offsetLeft;
1655: element = element.offsetParent;
1656: }
1657: return x;
1658: }
1659: function getY(element) {
1660: var y = 0;
1661: while (element) {
1662: y += element.offsetTop;
1663: element = element.offsetParent;
1664: }
1665: return y;
1666: }
1667:
1668:
1.565 albertel 1669: function resize_textarea(textarea_id,bottom_id) {
1670: init_geometry();
1671: var textarea = document.getElementById(textarea_id);
1672: //alert(textarea);
1673:
1.588 albertel 1674: var textarea_top = getY(textarea);
1.565 albertel 1675: var textarea_height = textarea.offsetHeight;
1676: var bottom = document.getElementById(bottom_id);
1.588 albertel 1677: var bottom_top = getY(bottom);
1.565 albertel 1678: var bottom_height = bottom.offsetHeight;
1679: var window_height = Geometry.getViewportHeight();
1.588 albertel 1680: var fudge = 23;
1.565 albertel 1681: var new_height = window_height-fudge-textarea_top-bottom_height;
1682: if (new_height < 300) {
1683: new_height = 300;
1684: }
1685: textarea.style.height=new_height+'px';
1686: }
1.824 bisitz 1687: // ]]>
1.565 albertel 1688: </script>
1689: RESIZE
1690:
1691: }
1692:
1693: =pod
1694:
1.256 matthew 1695: =head1 Excel and CSV file utility routines
1696:
1697: =over 4
1698:
1699: =cut
1700:
1701: ###############################################################
1702: ###############################################################
1703:
1704: =pod
1705:
1.648 raeburn 1706: =item * &csv_translate($text)
1.37 matthew 1707:
1.185 www 1708: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1709: format.
1710:
1711: =cut
1712:
1.180 matthew 1713: ###############################################################
1714: ###############################################################
1.37 matthew 1715: sub csv_translate {
1716: my $text = shift;
1717: $text =~ s/\"/\"\"/g;
1.209 albertel 1718: $text =~ s/\n/ /g;
1.37 matthew 1719: return $text;
1720: }
1.180 matthew 1721:
1722: ###############################################################
1723: ###############################################################
1724:
1725: =pod
1726:
1.648 raeburn 1727: =item * &define_excel_formats()
1.180 matthew 1728:
1729: Define some commonly used Excel cell formats.
1730:
1731: Currently supported formats:
1732:
1733: =over 4
1734:
1735: =item header
1736:
1737: =item bold
1738:
1739: =item h1
1740:
1741: =item h2
1742:
1743: =item h3
1744:
1.256 matthew 1745: =item h4
1746:
1747: =item i
1748:
1.180 matthew 1749: =item date
1750:
1751: =back
1752:
1753: Inputs: $workbook
1754:
1755: Returns: $format, a hash reference.
1756:
1.1057 foxr 1757:
1.180 matthew 1758: =cut
1759:
1760: ###############################################################
1761: ###############################################################
1762: sub define_excel_formats {
1763: my ($workbook) = @_;
1764: my $format;
1765: $format->{'header'} = $workbook->add_format(bold => 1,
1766: bottom => 1,
1767: align => 'center');
1768: $format->{'bold'} = $workbook->add_format(bold=>1);
1769: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1770: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1771: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1772: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1773: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1774: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1775: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1776: return $format;
1777: }
1778:
1779: ###############################################################
1780: ###############################################################
1.113 bowersj2 1781:
1782: =pod
1783:
1.648 raeburn 1784: =item * &create_workbook()
1.255 matthew 1785:
1786: Create an Excel worksheet. If it fails, output message on the
1787: request object and return undefs.
1788:
1789: Inputs: Apache request object
1790:
1791: Returns (undef) on failure,
1792: Excel worksheet object, scalar with filename, and formats
1793: from &Apache::loncommon::define_excel_formats on success
1794:
1795: =cut
1796:
1797: ###############################################################
1798: ###############################################################
1799: sub create_workbook {
1800: my ($r) = @_;
1801: #
1802: # Create the excel spreadsheet
1803: my $filename = '/prtspool/'.
1.258 albertel 1804: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1805: time.'_'.rand(1000000000).'.xls';
1806: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1807: if (! defined($workbook)) {
1808: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1809: $r->print(
1810: '<p class="LC_error">'
1811: .&mt('Problems occurred in creating the new Excel file.')
1812: .' '.&mt('This error has been logged.')
1813: .' '.&mt('Please alert your LON-CAPA administrator.')
1814: .'</p>'
1815: );
1.255 matthew 1816: return (undef);
1817: }
1818: #
1.1014 foxr 1819: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1820: #
1821: my $format = &Apache::loncommon::define_excel_formats($workbook);
1822: return ($workbook,$filename,$format);
1823: }
1824:
1825: ###############################################################
1826: ###############################################################
1827:
1828: =pod
1829:
1.648 raeburn 1830: =item * &create_text_file()
1.113 bowersj2 1831:
1.542 raeburn 1832: Create a file to write to and eventually make available to the user.
1.256 matthew 1833: If file creation fails, outputs an error message on the request object and
1834: return undefs.
1.113 bowersj2 1835:
1.256 matthew 1836: Inputs: Apache request object, and file suffix
1.113 bowersj2 1837:
1.256 matthew 1838: Returns (undef) on failure,
1839: Filehandle and filename on success.
1.113 bowersj2 1840:
1841: =cut
1842:
1.256 matthew 1843: ###############################################################
1844: ###############################################################
1845: sub create_text_file {
1846: my ($r,$suffix) = @_;
1847: if (! defined($suffix)) { $suffix = 'txt'; };
1848: my $fh;
1849: my $filename = '/prtspool/'.
1.258 albertel 1850: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1851: time.'_'.rand(1000000000).'.'.$suffix;
1852: $fh = Apache::File->new('>/home/httpd'.$filename);
1853: if (! defined($fh)) {
1854: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1855: $r->print(
1856: '<p class="LC_error">'
1857: .&mt('Problems occurred in creating the output file.')
1858: .' '.&mt('This error has been logged.')
1859: .' '.&mt('Please alert your LON-CAPA administrator.')
1860: .'</p>'
1861: );
1.113 bowersj2 1862: }
1.256 matthew 1863: return ($fh,$filename)
1.113 bowersj2 1864: }
1865:
1866:
1.256 matthew 1867: =pod
1.113 bowersj2 1868:
1869: =back
1870:
1871: =cut
1.37 matthew 1872:
1873: ###############################################################
1.33 matthew 1874: ## Home server <option> list generating code ##
1875: ###############################################################
1.35 matthew 1876:
1.169 www 1877: # ------------------------------------------
1878:
1879: sub domain_select {
1880: my ($name,$value,$multiple)=@_;
1881: my %domains=map {
1.514 albertel 1882: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1883: } &Apache::lonnet::all_domains();
1.169 www 1884: if ($multiple) {
1885: $domains{''}=&mt('Any domain');
1.550 albertel 1886: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1887: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1888: } else {
1.550 albertel 1889: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1890: return &select_form($name,$value,\%domains);
1.169 www 1891: }
1892: }
1893:
1.282 albertel 1894: #-------------------------------------------
1895:
1896: =pod
1897:
1.519 raeburn 1898: =head1 Routines for form select boxes
1899:
1900: =over 4
1901:
1.648 raeburn 1902: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1903:
1904: Returns a string containing a <select> element int multiple mode
1905:
1906:
1907: Args:
1908: $name - name of the <select> element
1.506 raeburn 1909: $value - scalar or array ref of values that should already be selected
1.282 albertel 1910: $size - number of rows long the select element is
1.283 albertel 1911: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1912: (shown text should already have been &mt())
1.506 raeburn 1913: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1914:
1.282 albertel 1915: =cut
1916:
1917: #-------------------------------------------
1.169 www 1918: sub multiple_select_form {
1.284 albertel 1919: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1920: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1921: my $output='';
1.191 matthew 1922: if (! defined($size)) {
1923: $size = 4;
1.283 albertel 1924: if (scalar(keys(%$hash))<4) {
1925: $size = scalar(keys(%$hash));
1.191 matthew 1926: }
1927: }
1.734 bisitz 1928: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1929: my @order;
1.506 raeburn 1930: if (ref($order) eq 'ARRAY') {
1931: @order = @{$order};
1932: } else {
1933: @order = sort(keys(%$hash));
1.501 banghart 1934: }
1935: if (exists($$hash{'select_form_order'})) {
1936: @order = @{$$hash{'select_form_order'}};
1937: }
1938:
1.284 albertel 1939: foreach my $key (@order) {
1.356 albertel 1940: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1941: $output.='selected="selected" ' if ($selected{$key});
1942: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1943: }
1944: $output.="</select>\n";
1945: return $output;
1946: }
1947:
1.88 www 1948: #-------------------------------------------
1949:
1950: =pod
1951:
1.970 raeburn 1952: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1953:
1954: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1955: allow a user to select options from a ref to a hash containing:
1956: option_name => displayed text. An optional $onchange can include
1957: a javascript onchange item, e.g., onchange="this.form.submit();"
1958:
1.88 www 1959: See lonrights.pm for an example invocation and use.
1960:
1961: =cut
1962:
1963: #-------------------------------------------
1964: sub select_form {
1.970 raeburn 1965: my ($def,$name,$hashref,$onchange) = @_;
1966: return unless (ref($hashref) eq 'HASH');
1967: if ($onchange) {
1968: $onchange = ' onchange="'.$onchange.'"';
1969: }
1970: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1971: my @keys;
1.970 raeburn 1972: if (exists($hashref->{'select_form_order'})) {
1973: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1974: } else {
1.970 raeburn 1975: @keys=sort(keys(%{$hashref}));
1.128 albertel 1976: }
1.356 albertel 1977: foreach my $key (@keys) {
1978: $selectform.=
1979: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1980: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 1981: ">".$hashref->{$key}."</option>\n";
1.88 www 1982: }
1983: $selectform.="</select>";
1984: return $selectform;
1985: }
1986:
1.475 www 1987: # For display filters
1988:
1989: sub display_filter {
1.1074 raeburn 1990: my ($context) = @_;
1.475 www 1991: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1992: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 1993: my $phraseinput = 'hidden';
1994: my $includeinput = 'hidden';
1995: my ($checked,$includetypestext);
1996: if ($env{'form.displayfilter'} eq 'containing') {
1997: $phraseinput = 'text';
1998: if ($context eq 'parmslog') {
1999: $includeinput = 'checkbox';
2000: if ($env{'form.includetypes'}) {
2001: $checked = ' checked="checked"';
2002: }
2003: $includetypestext = &mt('Include parameter types');
2004: }
2005: } else {
2006: $includetypestext = ' ';
2007: }
2008: my ($additional,$secondid,$thirdid);
2009: if ($context eq 'parmslog') {
2010: $additional =
2011: '<label><input type="'.$includeinput.'" name="includetypes"'.
2012: $checked.' name="includetypes" value="1" id="includetypes" />'.
2013: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2014: '</label>';
2015: $secondid = 'includetypes';
2016: $thirdid = 'includetypestext';
2017: }
2018: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2019: '$secondid','$thirdid')";
2020: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2021: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2022: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2023: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2024: &mt('Filter: [_1]',
1.477 www 2025: &select_form($env{'form.displayfilter'},
2026: 'displayfilter',
1.970 raeburn 2027: {'currentfolder' => 'Current folder/page',
1.477 www 2028: 'containing' => 'Containing phrase',
1.1074 raeburn 2029: 'none' => 'None'},$onchange)).' '.
2030: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2031: &HTML::Entities::encode($env{'form.containingphrase'}).
2032: '" />'.$additional;
2033: }
2034:
2035: sub display_filter_js {
2036: my $includetext = &mt('Include parameter types');
2037: return <<"ENDJS";
2038:
2039: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2040: var firstType = 'hidden';
2041: if (setter.options[setter.selectedIndex].value == 'containing') {
2042: firstType = 'text';
2043: }
2044: firstObject = document.getElementById(firstid);
2045: if (typeof(firstObject) == 'object') {
2046: if (firstObject.type != firstType) {
2047: changeInputType(firstObject,firstType);
2048: }
2049: }
2050: if (context == 'parmslog') {
2051: var secondType = 'hidden';
2052: if (firstType == 'text') {
2053: secondType = 'checkbox';
2054: }
2055: secondObject = document.getElementById(secondid);
2056: if (typeof(secondObject) == 'object') {
2057: if (secondObject.type != secondType) {
2058: changeInputType(secondObject,secondType);
2059: }
2060: }
2061: var textItem = document.getElementById(thirdid);
2062: var currtext = textItem.innerHTML;
2063: var newtext;
2064: if (firstType == 'text') {
2065: newtext = '$includetext';
2066: } else {
2067: newtext = ' ';
2068: }
2069: if (currtext != newtext) {
2070: textItem.innerHTML = newtext;
2071: }
2072: }
2073: return;
2074: }
2075:
2076: function changeInputType(oldObject,newType) {
2077: var newObject = document.createElement('input');
2078: newObject.type = newType;
2079: if (oldObject.size) {
2080: newObject.size = oldObject.size;
2081: }
2082: if (oldObject.value) {
2083: newObject.value = oldObject.value;
2084: }
2085: if (oldObject.name) {
2086: newObject.name = oldObject.name;
2087: }
2088: if (oldObject.id) {
2089: newObject.id = oldObject.id;
2090: }
2091: oldObject.parentNode.replaceChild(newObject,oldObject);
2092: return;
2093: }
2094:
2095: ENDJS
1.475 www 2096: }
2097:
1.167 www 2098: sub gradeleveldescription {
2099: my $gradelevel=shift;
2100: my %gradelevels=(0 => 'Not specified',
2101: 1 => 'Grade 1',
2102: 2 => 'Grade 2',
2103: 3 => 'Grade 3',
2104: 4 => 'Grade 4',
2105: 5 => 'Grade 5',
2106: 6 => 'Grade 6',
2107: 7 => 'Grade 7',
2108: 8 => 'Grade 8',
2109: 9 => 'Grade 9',
2110: 10 => 'Grade 10',
2111: 11 => 'Grade 11',
2112: 12 => 'Grade 12',
2113: 13 => 'Grade 13',
2114: 14 => '100 Level',
2115: 15 => '200 Level',
2116: 16 => '300 Level',
2117: 17 => '400 Level',
2118: 18 => 'Graduate Level');
2119: return &mt($gradelevels{$gradelevel});
2120: }
2121:
1.163 www 2122: sub select_level_form {
2123: my ($deflevel,$name)=@_;
2124: unless ($deflevel) { $deflevel=0; }
1.167 www 2125: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2126: for (my $i=0; $i<=18; $i++) {
2127: $selectform.="<option value=\"$i\" ".
1.253 albertel 2128: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2129: ">".&gradeleveldescription($i)."</option>\n";
2130: }
2131: $selectform.="</select>";
2132: return $selectform;
1.163 www 2133: }
1.167 www 2134:
1.35 matthew 2135: #-------------------------------------------
2136:
1.45 matthew 2137: =pod
2138:
1.910 raeburn 2139: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2140:
2141: Returns a string containing a <select name='$name' size='1'> form to
2142: allow a user to select the domain to preform an operation in.
2143: See loncreateuser.pm for an example invocation and use.
2144:
1.90 www 2145: If the $includeempty flag is set, it also includes an empty choice ("no domain
2146: selected");
2147:
1.743 raeburn 2148: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2149:
1.910 raeburn 2150: 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.
2151:
2152: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2153:
1.35 matthew 2154: =cut
2155:
2156: #-------------------------------------------
1.34 matthew 2157: sub select_dom_form {
1.910 raeburn 2158: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2159: if ($onchange) {
1.874 raeburn 2160: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2161: }
1.910 raeburn 2162: my @domains;
2163: if (ref($incdoms) eq 'ARRAY') {
2164: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2165: } else {
2166: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2167: }
1.90 www 2168: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2169: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2170: foreach my $dom (@domains) {
2171: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2172: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2173: if ($showdomdesc) {
2174: if ($dom ne '') {
2175: my $domdesc = &Apache::lonnet::domain($dom,'description');
2176: if ($domdesc ne '') {
2177: $selectdomain .= ' ('.$domdesc.')';
2178: }
2179: }
2180: }
2181: $selectdomain .= "</option>\n";
1.34 matthew 2182: }
2183: $selectdomain.="</select>";
2184: return $selectdomain;
2185: }
2186:
1.35 matthew 2187: #-------------------------------------------
2188:
1.45 matthew 2189: =pod
2190:
1.648 raeburn 2191: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2192:
1.586 raeburn 2193: input: 4 arguments (two required, two optional) -
2194: $domain - domain of new user
2195: $name - name of form element
2196: $default - Value of 'default' causes a default item to be first
2197: option, and selected by default.
2198: $hide - Value of 'hide' causes hiding of the name of the server,
2199: if 1 server found, or default, if 0 found.
1.594 raeburn 2200: output: returns 2 items:
1.586 raeburn 2201: (a) form element which contains either:
2202: (i) <select name="$name">
2203: <option value="$hostid1">$hostid $servers{$hostid}</option>
2204: <option value="$hostid2">$hostid $servers{$hostid}</option>
2205: </select>
2206: form item if there are multiple library servers in $domain, or
2207: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2208: if there is only one library server in $domain.
2209:
2210: (b) number of library servers found.
2211:
2212: See loncreateuser.pm for example of use.
1.35 matthew 2213:
2214: =cut
2215:
2216: #-------------------------------------------
1.586 raeburn 2217: sub home_server_form_item {
2218: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2219: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2220: my $result;
2221: my $numlib = keys(%servers);
2222: if ($numlib > 1) {
2223: $result .= '<select name="'.$name.'" />'."\n";
2224: if ($default) {
1.804 bisitz 2225: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2226: '</option>'."\n";
2227: }
2228: foreach my $hostid (sort(keys(%servers))) {
2229: $result.= '<option value="'.$hostid.'">'.
2230: $hostid.' '.$servers{$hostid}."</option>\n";
2231: }
2232: $result .= '</select>'."\n";
2233: } elsif ($numlib == 1) {
2234: my $hostid;
2235: foreach my $item (keys(%servers)) {
2236: $hostid = $item;
2237: }
2238: $result .= '<input type="hidden" name="'.$name.'" value="'.
2239: $hostid.'" />';
2240: if (!$hide) {
2241: $result .= $hostid.' '.$servers{$hostid};
2242: }
2243: $result .= "\n";
2244: } elsif ($default) {
2245: $result .= '<input type="hidden" name="'.$name.
2246: '" value="default" />';
2247: if (!$hide) {
2248: $result .= &mt('default');
2249: }
2250: $result .= "\n";
1.33 matthew 2251: }
1.586 raeburn 2252: return ($result,$numlib);
1.33 matthew 2253: }
1.112 bowersj2 2254:
2255: =pod
2256:
1.534 albertel 2257: =back
2258:
1.112 bowersj2 2259: =cut
1.87 matthew 2260:
2261: ###############################################################
1.112 bowersj2 2262: ## Decoding User Agent ##
1.87 matthew 2263: ###############################################################
2264:
2265: =pod
2266:
1.112 bowersj2 2267: =head1 Decoding the User Agent
2268:
2269: =over 4
2270:
2271: =item * &decode_user_agent()
1.87 matthew 2272:
2273: Inputs: $r
2274:
2275: Outputs:
2276:
2277: =over 4
2278:
1.112 bowersj2 2279: =item * $httpbrowser
1.87 matthew 2280:
1.112 bowersj2 2281: =item * $clientbrowser
1.87 matthew 2282:
1.112 bowersj2 2283: =item * $clientversion
1.87 matthew 2284:
1.112 bowersj2 2285: =item * $clientmathml
1.87 matthew 2286:
1.112 bowersj2 2287: =item * $clientunicode
1.87 matthew 2288:
1.112 bowersj2 2289: =item * $clientos
1.87 matthew 2290:
2291: =back
2292:
1.157 matthew 2293: =back
2294:
1.87 matthew 2295: =cut
2296:
2297: ###############################################################
2298: ###############################################################
2299: sub decode_user_agent {
1.247 albertel 2300: my ($r)=@_;
1.87 matthew 2301: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2302: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2303: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2304: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2305: my $clientbrowser='unknown';
2306: my $clientversion='0';
2307: my $clientmathml='';
2308: my $clientunicode='0';
2309: for (my $i=0;$i<=$#browsertype;$i++) {
2310: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2311: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2312: $clientbrowser=$bname;
2313: $httpbrowser=~/$vreg/i;
2314: $clientversion=$1;
2315: $clientmathml=($clientversion>=$minv);
2316: $clientunicode=($clientversion>=$univ);
2317: }
2318: }
2319: my $clientos='unknown';
2320: if (($httpbrowser=~/linux/i) ||
2321: ($httpbrowser=~/unix/i) ||
2322: ($httpbrowser=~/ux/i) ||
2323: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2324: if (($httpbrowser=~/vax/i) ||
2325: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2326: if ($httpbrowser=~/next/i) { $clientos='next'; }
2327: if (($httpbrowser=~/mac/i) ||
2328: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2329: if ($httpbrowser=~/win/i) { $clientos='win'; }
2330: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2331: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2332: $clientunicode,$clientos,);
2333: }
2334:
1.32 matthew 2335: ###############################################################
2336: ## Authentication changing form generation subroutines ##
2337: ###############################################################
2338: ##
2339: ## All of the authform_xxxxxxx subroutines take their inputs in a
2340: ## hash, and have reasonable default values.
2341: ##
2342: ## formname = the name given in the <form> tag.
1.35 matthew 2343: #-------------------------------------------
2344:
1.45 matthew 2345: =pod
2346:
1.112 bowersj2 2347: =head1 Authentication Routines
2348:
2349: =over 4
2350:
1.648 raeburn 2351: =item * &authform_xxxxxx()
1.35 matthew 2352:
2353: The authform_xxxxxx subroutines provide javascript and html forms which
2354: handle some of the conveniences required for authentication forms.
2355: This is not an optimal method, but it works.
2356:
2357: =over 4
2358:
1.112 bowersj2 2359: =item * authform_header
1.35 matthew 2360:
1.112 bowersj2 2361: =item * authform_authorwarning
1.35 matthew 2362:
1.112 bowersj2 2363: =item * authform_nochange
1.35 matthew 2364:
1.112 bowersj2 2365: =item * authform_kerberos
1.35 matthew 2366:
1.112 bowersj2 2367: =item * authform_internal
1.35 matthew 2368:
1.112 bowersj2 2369: =item * authform_filesystem
1.35 matthew 2370:
2371: =back
2372:
1.648 raeburn 2373: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2374:
1.35 matthew 2375: =cut
2376:
2377: #-------------------------------------------
1.32 matthew 2378: sub authform_header{
2379: my %in = (
2380: formname => 'cu',
1.80 albertel 2381: kerb_def_dom => '',
1.32 matthew 2382: @_,
2383: );
2384: $in{'formname'} = 'document.' . $in{'formname'};
2385: my $result='';
1.80 albertel 2386:
2387: #---------------------------------------------- Code for upper case translation
2388: my $Javascript_toUpperCase;
2389: unless ($in{kerb_def_dom}) {
2390: $Javascript_toUpperCase =<<"END";
2391: switch (choice) {
2392: case 'krb': currentform.elements[choicearg].value =
2393: currentform.elements[choicearg].value.toUpperCase();
2394: break;
2395: default:
2396: }
2397: END
2398: } else {
2399: $Javascript_toUpperCase = "";
2400: }
2401:
1.165 raeburn 2402: my $radioval = "'nochange'";
1.591 raeburn 2403: if (defined($in{'curr_authtype'})) {
2404: if ($in{'curr_authtype'} ne '') {
2405: $radioval = "'".$in{'curr_authtype'}."arg'";
2406: }
1.174 matthew 2407: }
1.165 raeburn 2408: my $argfield = 'null';
1.591 raeburn 2409: if (defined($in{'mode'})) {
1.165 raeburn 2410: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2411: if (defined($in{'curr_autharg'})) {
2412: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2413: $argfield = "'$in{'curr_autharg'}'";
2414: }
2415: }
2416: }
2417: }
2418:
1.32 matthew 2419: $result.=<<"END";
2420: var current = new Object();
1.165 raeburn 2421: current.radiovalue = $radioval;
2422: current.argfield = $argfield;
1.32 matthew 2423:
2424: function changed_radio(choice,currentform) {
2425: var choicearg = choice + 'arg';
2426: // If a radio button in changed, we need to change the argfield
2427: if (current.radiovalue != choice) {
2428: current.radiovalue = choice;
2429: if (current.argfield != null) {
2430: currentform.elements[current.argfield].value = '';
2431: }
2432: if (choice == 'nochange') {
2433: current.argfield = null;
2434: } else {
2435: current.argfield = choicearg;
2436: switch(choice) {
2437: case 'krb':
2438: currentform.elements[current.argfield].value =
2439: "$in{'kerb_def_dom'}";
2440: break;
2441: default:
2442: break;
2443: }
2444: }
2445: }
2446: return;
2447: }
1.22 www 2448:
1.32 matthew 2449: function changed_text(choice,currentform) {
2450: var choicearg = choice + 'arg';
2451: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2452: $Javascript_toUpperCase
1.32 matthew 2453: // clear old field
2454: if ((current.argfield != choicearg) && (current.argfield != null)) {
2455: currentform.elements[current.argfield].value = '';
2456: }
2457: current.argfield = choicearg;
2458: }
2459: set_auth_radio_buttons(choice,currentform);
2460: return;
1.20 www 2461: }
1.32 matthew 2462:
2463: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2464: var numauthchoices = currentform.login.length;
2465: if (typeof numauthchoices == "undefined") {
2466: return;
2467: }
1.32 matthew 2468: var i=0;
1.986 raeburn 2469: while (i < numauthchoices) {
1.32 matthew 2470: if (currentform.login[i].value == newvalue) { break; }
2471: i++;
2472: }
1.986 raeburn 2473: if (i == numauthchoices) {
1.32 matthew 2474: return;
2475: }
2476: current.radiovalue = newvalue;
2477: currentform.login[i].checked = true;
2478: return;
2479: }
2480: END
2481: return $result;
2482: }
2483:
2484: sub authform_authorwarning{
2485: my $result='';
1.144 matthew 2486: $result='<i>'.
2487: &mt('As a general rule, only authors or co-authors should be '.
2488: 'filesystem authenticated '.
2489: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2490: return $result;
2491: }
2492:
2493: sub authform_nochange{
2494: my %in = (
2495: formname => 'document.cu',
2496: kerb_def_dom => 'MSU.EDU',
2497: @_,
2498: );
1.586 raeburn 2499: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2500: my $result;
2501: if (keys(%can_assign) == 0) {
2502: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2503: } else {
2504: $result = '<label>'.&mt('[_1] Do not change login data',
2505: '<input type="radio" name="login" value="nochange" '.
2506: 'checked="checked" onclick="'.
1.281 albertel 2507: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2508: '</label>';
1.586 raeburn 2509: }
1.32 matthew 2510: return $result;
2511: }
2512:
1.591 raeburn 2513: sub authform_kerberos {
1.32 matthew 2514: my %in = (
2515: formname => 'document.cu',
2516: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2517: kerb_def_auth => 'krb4',
1.32 matthew 2518: @_,
2519: );
1.586 raeburn 2520: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2521: $autharg,$jscall);
2522: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2523: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2524: $check5 = ' checked="checked"';
1.80 albertel 2525: } else {
1.772 bisitz 2526: $check4 = ' checked="checked"';
1.80 albertel 2527: }
1.165 raeburn 2528: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2529: if (defined($in{'curr_authtype'})) {
2530: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2531: $krbcheck = ' checked="checked"';
1.623 raeburn 2532: if (defined($in{'mode'})) {
2533: if ($in{'mode'} eq 'modifyuser') {
2534: $krbcheck = '';
2535: }
2536: }
1.591 raeburn 2537: if (defined($in{'curr_kerb_ver'})) {
2538: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2539: $check5 = ' checked="checked"';
1.591 raeburn 2540: $check4 = '';
2541: } else {
1.772 bisitz 2542: $check4 = ' checked="checked"';
1.591 raeburn 2543: $check5 = '';
2544: }
1.586 raeburn 2545: }
1.591 raeburn 2546: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2547: $krbarg = $in{'curr_autharg'};
2548: }
1.586 raeburn 2549: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2550: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2551: $result =
2552: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2553: $in{'curr_autharg'},$krbver);
2554: } else {
2555: $result =
2556: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2557: }
2558: return $result;
2559: }
2560: }
2561: } else {
2562: if ($authnum == 1) {
1.784 bisitz 2563: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2564: }
2565: }
1.586 raeburn 2566: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2567: return;
1.587 raeburn 2568: } elsif ($authtype eq '') {
1.591 raeburn 2569: if (defined($in{'mode'})) {
1.587 raeburn 2570: if ($in{'mode'} eq 'modifycourse') {
2571: if ($authnum == 1) {
1.784 bisitz 2572: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2573: }
2574: }
2575: }
1.586 raeburn 2576: }
2577: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2578: if ($authtype eq '') {
2579: $authtype = '<input type="radio" name="login" value="krb" '.
2580: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2581: $krbcheck.' />';
2582: }
2583: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2584: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2585: $in{'curr_authtype'} eq 'krb5') ||
2586: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2587: $in{'curr_authtype'} eq 'krb4')) {
2588: $result .= &mt
1.144 matthew 2589: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2590: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2591: '<label>'.$authtype,
1.281 albertel 2592: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2593: 'value="'.$krbarg.'" '.
1.144 matthew 2594: 'onchange="'.$jscall.'" />',
1.281 albertel 2595: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2596: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2597: '</label>');
1.586 raeburn 2598: } elsif ($can_assign{'krb4'}) {
2599: $result .= &mt
2600: ('[_1] Kerberos authenticated with domain [_2] '.
2601: '[_3] Version 4 [_4]',
2602: '<label>'.$authtype,
2603: '</label><input type="text" size="10" name="krbarg" '.
2604: 'value="'.$krbarg.'" '.
2605: 'onchange="'.$jscall.'" />',
2606: '<label><input type="hidden" name="krbver" value="4" />',
2607: '</label>');
2608: } elsif ($can_assign{'krb5'}) {
2609: $result .= &mt
2610: ('[_1] Kerberos authenticated with domain [_2] '.
2611: '[_3] Version 5 [_4]',
2612: '<label>'.$authtype,
2613: '</label><input type="text" size="10" name="krbarg" '.
2614: 'value="'.$krbarg.'" '.
2615: 'onchange="'.$jscall.'" />',
2616: '<label><input type="hidden" name="krbver" value="5" />',
2617: '</label>');
2618: }
1.32 matthew 2619: return $result;
2620: }
2621:
2622: sub authform_internal{
1.586 raeburn 2623: my %in = (
1.32 matthew 2624: formname => 'document.cu',
2625: kerb_def_dom => 'MSU.EDU',
2626: @_,
2627: );
1.586 raeburn 2628: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2629: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2630: if (defined($in{'curr_authtype'})) {
2631: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2632: if ($can_assign{'int'}) {
1.772 bisitz 2633: $intcheck = 'checked="checked" ';
1.623 raeburn 2634: if (defined($in{'mode'})) {
2635: if ($in{'mode'} eq 'modifyuser') {
2636: $intcheck = '';
2637: }
2638: }
1.591 raeburn 2639: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2640: $intarg = $in{'curr_autharg'};
2641: }
2642: } else {
2643: $result = &mt('Currently internally authenticated.');
2644: return $result;
1.165 raeburn 2645: }
2646: }
1.586 raeburn 2647: } else {
2648: if ($authnum == 1) {
1.784 bisitz 2649: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2650: }
2651: }
2652: if (!$can_assign{'int'}) {
2653: return;
1.587 raeburn 2654: } elsif ($authtype eq '') {
1.591 raeburn 2655: if (defined($in{'mode'})) {
1.587 raeburn 2656: if ($in{'mode'} eq 'modifycourse') {
2657: if ($authnum == 1) {
1.784 bisitz 2658: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2659: }
2660: }
2661: }
1.165 raeburn 2662: }
1.586 raeburn 2663: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2664: if ($authtype eq '') {
2665: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2666: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2667: }
1.605 bisitz 2668: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2669: $intarg.'" onchange="'.$jscall.'" />';
2670: $result = &mt
1.144 matthew 2671: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2672: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2673: $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 2674: return $result;
2675: }
2676:
2677: sub authform_local{
2678: my %in = (
2679: formname => 'document.cu',
2680: kerb_def_dom => 'MSU.EDU',
2681: @_,
2682: );
1.586 raeburn 2683: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2684: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2685: if (defined($in{'curr_authtype'})) {
2686: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2687: if ($can_assign{'loc'}) {
1.772 bisitz 2688: $loccheck = 'checked="checked" ';
1.623 raeburn 2689: if (defined($in{'mode'})) {
2690: if ($in{'mode'} eq 'modifyuser') {
2691: $loccheck = '';
2692: }
2693: }
1.591 raeburn 2694: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2695: $locarg = $in{'curr_autharg'};
2696: }
2697: } else {
2698: $result = &mt('Currently using local (institutional) authentication.');
2699: return $result;
1.165 raeburn 2700: }
2701: }
1.586 raeburn 2702: } else {
2703: if ($authnum == 1) {
1.784 bisitz 2704: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2705: }
2706: }
2707: if (!$can_assign{'loc'}) {
2708: return;
1.587 raeburn 2709: } elsif ($authtype eq '') {
1.591 raeburn 2710: if (defined($in{'mode'})) {
1.587 raeburn 2711: if ($in{'mode'} eq 'modifycourse') {
2712: if ($authnum == 1) {
1.784 bisitz 2713: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2714: }
2715: }
2716: }
1.165 raeburn 2717: }
1.586 raeburn 2718: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2719: if ($authtype eq '') {
2720: $authtype = '<input type="radio" name="login" value="loc" '.
2721: $loccheck.' onchange="'.$jscall.'" onclick="'.
2722: $jscall.'" />';
2723: }
2724: $autharg = '<input type="text" size="10" name="locarg" value="'.
2725: $locarg.'" onchange="'.$jscall.'" />';
2726: $result = &mt('[_1] Local Authentication with argument [_2]',
2727: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2728: return $result;
2729: }
2730:
2731: sub authform_filesystem{
2732: my %in = (
2733: formname => 'document.cu',
2734: kerb_def_dom => 'MSU.EDU',
2735: @_,
2736: );
1.586 raeburn 2737: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2738: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2739: if (defined($in{'curr_authtype'})) {
2740: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2741: if ($can_assign{'fsys'}) {
1.772 bisitz 2742: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2743: if (defined($in{'mode'})) {
2744: if ($in{'mode'} eq 'modifyuser') {
2745: $fsyscheck = '';
2746: }
2747: }
1.586 raeburn 2748: } else {
2749: $result = &mt('Currently Filesystem Authenticated.');
2750: return $result;
2751: }
2752: }
2753: } else {
2754: if ($authnum == 1) {
1.784 bisitz 2755: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2756: }
2757: }
2758: if (!$can_assign{'fsys'}) {
2759: return;
1.587 raeburn 2760: } elsif ($authtype eq '') {
1.591 raeburn 2761: if (defined($in{'mode'})) {
1.587 raeburn 2762: if ($in{'mode'} eq 'modifycourse') {
2763: if ($authnum == 1) {
1.784 bisitz 2764: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2765: }
2766: }
2767: }
1.586 raeburn 2768: }
2769: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2770: if ($authtype eq '') {
2771: $authtype = '<input type="radio" name="login" value="fsys" '.
2772: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2773: $jscall.'" />';
2774: }
2775: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2776: ' onchange="'.$jscall.'" />';
2777: $result = &mt
1.144 matthew 2778: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2779: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2780: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2781: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2782: 'onchange="'.$jscall.'" />');
1.32 matthew 2783: return $result;
2784: }
2785:
1.586 raeburn 2786: sub get_assignable_auth {
2787: my ($dom) = @_;
2788: if ($dom eq '') {
2789: $dom = $env{'request.role.domain'};
2790: }
2791: my %can_assign = (
2792: krb4 => 1,
2793: krb5 => 1,
2794: int => 1,
2795: loc => 1,
2796: );
2797: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2798: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2799: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2800: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2801: my $context;
2802: if ($env{'request.role'} =~ /^au/) {
2803: $context = 'author';
2804: } elsif ($env{'request.role'} =~ /^dc/) {
2805: $context = 'domain';
2806: } elsif ($env{'request.course.id'}) {
2807: $context = 'course';
2808: }
2809: if ($context) {
2810: if (ref($authhash->{$context}) eq 'HASH') {
2811: %can_assign = %{$authhash->{$context}};
2812: }
2813: }
2814: }
2815: }
2816: my $authnum = 0;
2817: foreach my $key (keys(%can_assign)) {
2818: if ($can_assign{$key}) {
2819: $authnum ++;
2820: }
2821: }
2822: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2823: $authnum --;
2824: }
2825: return ($authnum,%can_assign);
2826: }
2827:
1.80 albertel 2828: ###############################################################
2829: ## Get Kerberos Defaults for Domain ##
2830: ###############################################################
2831: ##
2832: ## Returns default kerberos version and an associated argument
2833: ## as listed in file domain.tab. If not listed, provides
2834: ## appropriate default domain and kerberos version.
2835: ##
2836: #-------------------------------------------
2837:
2838: =pod
2839:
1.648 raeburn 2840: =item * &get_kerberos_defaults()
1.80 albertel 2841:
2842: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2843: version and domain. If not found, it defaults to version 4 and the
2844: domain of the server.
1.80 albertel 2845:
1.648 raeburn 2846: =over 4
2847:
1.80 albertel 2848: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2849:
1.648 raeburn 2850: =back
2851:
2852: =back
2853:
1.80 albertel 2854: =cut
2855:
2856: #-------------------------------------------
2857: sub get_kerberos_defaults {
2858: my $domain=shift;
1.641 raeburn 2859: my ($krbdef,$krbdefdom);
2860: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2861: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2862: $krbdef = $domdefaults{'auth_def'};
2863: $krbdefdom = $domdefaults{'auth_arg_def'};
2864: } else {
1.80 albertel 2865: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2866: my $krbdefdom=$1;
2867: $krbdefdom=~tr/a-z/A-Z/;
2868: $krbdef = "krb4";
2869: }
2870: return ($krbdef,$krbdefdom);
2871: }
1.112 bowersj2 2872:
1.32 matthew 2873:
1.46 matthew 2874: ###############################################################
2875: ## Thesaurus Functions ##
2876: ###############################################################
1.20 www 2877:
1.46 matthew 2878: =pod
1.20 www 2879:
1.112 bowersj2 2880: =head1 Thesaurus Functions
2881:
2882: =over 4
2883:
1.648 raeburn 2884: =item * &initialize_keywords()
1.46 matthew 2885:
2886: Initializes the package variable %Keywords if it is empty. Uses the
2887: package variable $thesaurus_db_file.
2888:
2889: =cut
2890:
2891: ###################################################
2892:
2893: sub initialize_keywords {
2894: return 1 if (scalar keys(%Keywords));
2895: # If we are here, %Keywords is empty, so fill it up
2896: # Make sure the file we need exists...
2897: if (! -e $thesaurus_db_file) {
2898: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2899: " failed because it does not exist");
2900: return 0;
2901: }
2902: # Set up the hash as a database
2903: my %thesaurus_db;
2904: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2905: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2906: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2907: $thesaurus_db_file);
2908: return 0;
2909: }
2910: # Get the average number of appearances of a word.
2911: my $avecount = $thesaurus_db{'average.count'};
2912: # Put keywords (those that appear > average) into %Keywords
2913: while (my ($word,$data)=each (%thesaurus_db)) {
2914: my ($count,undef) = split /:/,$data;
2915: $Keywords{$word}++ if ($count > $avecount);
2916: }
2917: untie %thesaurus_db;
2918: # Remove special values from %Keywords.
1.356 albertel 2919: foreach my $value ('total.count','average.count') {
2920: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2921: }
1.46 matthew 2922: return 1;
2923: }
2924:
2925: ###################################################
2926:
2927: =pod
2928:
1.648 raeburn 2929: =item * &keyword($word)
1.46 matthew 2930:
2931: Returns true if $word is a keyword. A keyword is a word that appears more
2932: than the average number of times in the thesaurus database. Calls
2933: &initialize_keywords
2934:
2935: =cut
2936:
2937: ###################################################
1.20 www 2938:
2939: sub keyword {
1.46 matthew 2940: return if (!&initialize_keywords());
2941: my $word=lc(shift());
2942: $word=~s/\W//g;
2943: return exists($Keywords{$word});
1.20 www 2944: }
1.46 matthew 2945:
2946: ###############################################################
2947:
2948: =pod
1.20 www 2949:
1.648 raeburn 2950: =item * &get_related_words()
1.46 matthew 2951:
1.160 matthew 2952: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2953: an array of words. If the keyword is not in the thesaurus, an empty array
2954: will be returned. The order of the words returned is determined by the
2955: database which holds them.
2956:
2957: Uses global $thesaurus_db_file.
2958:
1.1057 foxr 2959:
1.46 matthew 2960: =cut
2961:
2962: ###############################################################
2963: sub get_related_words {
2964: my $keyword = shift;
2965: my %thesaurus_db;
2966: if (! -e $thesaurus_db_file) {
2967: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2968: "failed because the file does not exist");
2969: return ();
2970: }
2971: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2972: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2973: return ();
2974: }
2975: my @Words=();
1.429 www 2976: my $count=0;
1.46 matthew 2977: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2978: # The first element is the number of times
2979: # the word appears. We do not need it now.
1.429 www 2980: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2981: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2982: my $threshold=$mostfrequentcount/10;
2983: foreach my $possibleword (@RelatedWords) {
2984: my ($word,$wordcount)=split(/\,/,$possibleword);
2985: if ($wordcount>$threshold) {
2986: push(@Words,$word);
2987: $count++;
2988: if ($count>10) { last; }
2989: }
1.20 www 2990: }
2991: }
1.46 matthew 2992: untie %thesaurus_db;
2993: return @Words;
1.14 harris41 2994: }
1.46 matthew 2995:
1.112 bowersj2 2996: =pod
2997:
2998: =back
2999:
3000: =cut
1.61 www 3001:
3002: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3003: =pod
3004:
1.112 bowersj2 3005: =head1 User Name Functions
3006:
3007: =over 4
3008:
1.648 raeburn 3009: =item * &plainname($uname,$udom,$first)
1.81 albertel 3010:
1.112 bowersj2 3011: Takes a users logon name and returns it as a string in
1.226 albertel 3012: "first middle last generation" form
3013: if $first is set to 'lastname' then it returns it as
3014: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3015:
3016: =cut
1.61 www 3017:
1.295 www 3018:
1.81 albertel 3019: ###############################################################
1.61 www 3020: sub plainname {
1.226 albertel 3021: my ($uname,$udom,$first)=@_;
1.537 albertel 3022: return if (!defined($uname) || !defined($udom));
1.295 www 3023: my %names=&getnames($uname,$udom);
1.226 albertel 3024: my $name=&Apache::lonnet::format_name($names{'firstname'},
3025: $names{'middlename'},
3026: $names{'lastname'},
3027: $names{'generation'},$first);
3028: $name=~s/^\s+//;
1.62 www 3029: $name=~s/\s+$//;
3030: $name=~s/\s+/ /g;
1.353 albertel 3031: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3032: return $name;
1.61 www 3033: }
1.66 www 3034:
3035: # -------------------------------------------------------------------- Nickname
1.81 albertel 3036: =pod
3037:
1.648 raeburn 3038: =item * &nickname($uname,$udom)
1.81 albertel 3039:
3040: Gets a users name and returns it as a string as
3041:
3042: ""nickname""
1.66 www 3043:
1.81 albertel 3044: if the user has a nickname or
3045:
3046: "first middle last generation"
3047:
3048: if the user does not
3049:
3050: =cut
1.66 www 3051:
3052: sub nickname {
3053: my ($uname,$udom)=@_;
1.537 albertel 3054: return if (!defined($uname) || !defined($udom));
1.295 www 3055: my %names=&getnames($uname,$udom);
1.68 albertel 3056: my $name=$names{'nickname'};
1.66 www 3057: if ($name) {
3058: $name='"'.$name.'"';
3059: } else {
3060: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3061: $names{'lastname'}.' '.$names{'generation'};
3062: $name=~s/\s+$//;
3063: $name=~s/\s+/ /g;
3064: }
3065: return $name;
3066: }
3067:
1.295 www 3068: sub getnames {
3069: my ($uname,$udom)=@_;
1.537 albertel 3070: return if (!defined($uname) || !defined($udom));
1.433 albertel 3071: if ($udom eq 'public' && $uname eq 'public') {
3072: return ('lastname' => &mt('Public'));
3073: }
1.295 www 3074: my $id=$uname.':'.$udom;
3075: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3076: if ($cached) {
3077: return %{$names};
3078: } else {
3079: my %loadnames=&Apache::lonnet::get('environment',
3080: ['firstname','middlename','lastname','generation','nickname'],
3081: $udom,$uname);
3082: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3083: return %loadnames;
3084: }
3085: }
1.61 www 3086:
1.542 raeburn 3087: # -------------------------------------------------------------------- getemails
1.648 raeburn 3088:
1.542 raeburn 3089: =pod
3090:
1.648 raeburn 3091: =item * &getemails($uname,$udom)
1.542 raeburn 3092:
3093: Gets a user's email information and returns it as a hash with keys:
3094: notification, critnotification, permanentemail
3095:
3096: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3097: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3098:
1.648 raeburn 3099:
1.542 raeburn 3100: =cut
3101:
1.648 raeburn 3102:
1.466 albertel 3103: sub getemails {
3104: my ($uname,$udom)=@_;
3105: if ($udom eq 'public' && $uname eq 'public') {
3106: return;
3107: }
1.467 www 3108: if (!$udom) { $udom=$env{'user.domain'}; }
3109: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3110: my $id=$uname.':'.$udom;
3111: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3112: if ($cached) {
3113: return %{$names};
3114: } else {
3115: my %loadnames=&Apache::lonnet::get('environment',
3116: ['notification','critnotification',
3117: 'permanentemail'],
3118: $udom,$uname);
3119: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3120: return %loadnames;
3121: }
3122: }
3123:
1.551 albertel 3124: sub flush_email_cache {
3125: my ($uname,$udom)=@_;
3126: if (!$udom) { $udom =$env{'user.domain'}; }
3127: if (!$uname) { $uname=$env{'user.name'}; }
3128: return if ($udom eq 'public' && $uname eq 'public');
3129: my $id=$uname.':'.$udom;
3130: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3131: }
3132:
1.728 raeburn 3133: # -------------------------------------------------------------------- getlangs
3134:
3135: =pod
3136:
3137: =item * &getlangs($uname,$udom)
3138:
3139: Gets a user's language preference and returns it as a hash with key:
3140: language.
3141:
3142: =cut
3143:
3144:
3145: sub getlangs {
3146: my ($uname,$udom) = @_;
3147: if (!$udom) { $udom =$env{'user.domain'}; }
3148: if (!$uname) { $uname=$env{'user.name'}; }
3149: my $id=$uname.':'.$udom;
3150: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3151: if ($cached) {
3152: return %{$langs};
3153: } else {
3154: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3155: $udom,$uname);
3156: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3157: return %loadlangs;
3158: }
3159: }
3160:
3161: sub flush_langs_cache {
3162: my ($uname,$udom)=@_;
3163: if (!$udom) { $udom =$env{'user.domain'}; }
3164: if (!$uname) { $uname=$env{'user.name'}; }
3165: return if ($udom eq 'public' && $uname eq 'public');
3166: my $id=$uname.':'.$udom;
3167: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3168: }
3169:
1.61 www 3170: # ------------------------------------------------------------------ Screenname
1.81 albertel 3171:
3172: =pod
3173:
1.648 raeburn 3174: =item * &screenname($uname,$udom)
1.81 albertel 3175:
3176: Gets a users screenname and returns it as a string
3177:
3178: =cut
1.61 www 3179:
3180: sub screenname {
3181: my ($uname,$udom)=@_;
1.258 albertel 3182: if ($uname eq $env{'user.name'} &&
3183: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3184: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3185: return $names{'screenname'};
1.62 www 3186: }
3187:
1.212 albertel 3188:
1.802 bisitz 3189: # ------------------------------------------------------------- Confirm Wrapper
3190: =pod
3191:
3192: =item confirmwrapper
3193:
3194: Wrap messages about completion of operation in box
3195:
3196: =cut
3197:
3198: sub confirmwrapper {
3199: my ($message)=@_;
3200: if ($message) {
3201: return "\n".'<div class="LC_confirm_box">'."\n"
3202: .$message."\n"
3203: .'</div>'."\n";
3204: } else {
3205: return $message;
3206: }
3207: }
3208:
1.62 www 3209: # ------------------------------------------------------------- Message Wrapper
3210:
3211: sub messagewrapper {
1.369 www 3212: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3213: return
1.441 albertel 3214: '<a href="/adm/email?compose=individual&'.
3215: 'recname='.$username.'&recdom='.$domain.
3216: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3217: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3218: }
1.802 bisitz 3219:
1.74 www 3220: # --------------------------------------------------------------- Notes Wrapper
3221:
3222: sub noteswrapper {
3223: my ($link,$un,$do)=@_;
3224: return
1.896 amueller 3225: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3226: }
1.802 bisitz 3227:
1.62 www 3228: # ------------------------------------------------------------- Aboutme Wrapper
3229:
3230: sub aboutmewrapper {
1.1070 raeburn 3231: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3232: if (!defined($username) && !defined($domain)) {
3233: return;
3234: }
1.892 amueller 3235: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.1070 raeburn 3236: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3237: }
3238:
3239: # ------------------------------------------------------------ Syllabus Wrapper
3240:
3241: sub syllabuswrapper {
1.707 bisitz 3242: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3243: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3244: }
1.14 harris41 3245:
1.802 bisitz 3246: # -----------------------------------------------------------------------------
3247:
1.208 matthew 3248: sub track_student_link {
1.887 raeburn 3249: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3250: my $link ="/adm/trackstudent?";
1.208 matthew 3251: my $title = 'View recent activity';
3252: if (defined($sname) && $sname !~ /^\s*$/ &&
3253: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3254: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3255: $title .= ' of this student';
1.268 albertel 3256: }
1.208 matthew 3257: if (defined($target) && $target !~ /^\s*$/) {
3258: $target = qq{target="$target"};
3259: } else {
3260: $target = '';
3261: }
1.268 albertel 3262: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3263: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3264: $title = &mt($title);
3265: $linktext = &mt($linktext);
1.448 albertel 3266: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3267: &help_open_topic('View_recent_activity');
1.208 matthew 3268: }
3269:
1.781 raeburn 3270: sub slot_reservations_link {
3271: my ($linktext,$sname,$sdom,$target) = @_;
3272: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3273: my $title = 'View slot reservation history';
3274: if (defined($sname) && $sname !~ /^\s*$/ &&
3275: defined($sdom) && $sdom !~ /^\s*$/) {
3276: $link .= "&uname=$sname&udom=$sdom";
3277: $title .= ' of this student';
3278: }
3279: if (defined($target) && $target !~ /^\s*$/) {
3280: $target = qq{target="$target"};
3281: } else {
3282: $target = '';
3283: }
3284: $title = &mt($title);
3285: $linktext = &mt($linktext);
3286: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3287: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3288:
3289: }
3290:
1.508 www 3291: # ===================================================== Display a student photo
3292:
3293:
1.509 albertel 3294: sub student_image_tag {
1.508 www 3295: my ($domain,$user)=@_;
3296: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3297: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3298: return '<img src="'.$imgsrc.'" align="right" />';
3299: } else {
3300: return '';
3301: }
3302: }
3303:
1.112 bowersj2 3304: =pod
3305:
3306: =back
3307:
3308: =head1 Access .tab File Data
3309:
3310: =over 4
3311:
1.648 raeburn 3312: =item * &languageids()
1.112 bowersj2 3313:
3314: returns list of all language ids
3315:
3316: =cut
3317:
1.14 harris41 3318: sub languageids {
1.16 harris41 3319: return sort(keys(%language));
1.14 harris41 3320: }
3321:
1.112 bowersj2 3322: =pod
3323:
1.648 raeburn 3324: =item * &languagedescription()
1.112 bowersj2 3325:
3326: returns description of a specified language id
3327:
3328: =cut
3329:
1.14 harris41 3330: sub languagedescription {
1.125 www 3331: my $code=shift;
3332: return ($supported_language{$code}?'* ':'').
3333: $language{$code}.
1.126 www 3334: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3335: }
3336:
1.1048 foxr 3337: =pod
3338:
3339: =item * &plainlanguagedescription
3340:
3341: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3342: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3343:
3344: =cut
3345:
1.145 www 3346: sub plainlanguagedescription {
3347: my $code=shift;
3348: return $language{$code};
3349: }
3350:
1.1048 foxr 3351: =pod
3352:
3353: =item * &supportedlanguagecode
3354:
3355: Returns the supported language code (e.g. sptutf maps to pt) given a language
3356: code.
3357:
3358: =cut
3359:
1.145 www 3360: sub supportedlanguagecode {
3361: my $code=shift;
3362: return $supported_language{$code};
1.97 www 3363: }
3364:
1.112 bowersj2 3365: =pod
3366:
1.1048 foxr 3367: =item * &latexlanguage()
3368:
3369: Given a language key code returns the correspondnig language to use
3370: to select the correct hyphenation on LaTeX printouts. This is undef if there
3371: is no supported hyphenation for the language code.
3372:
3373: =cut
3374:
3375: sub latexlanguage {
3376: my $code = shift;
3377: return $latex_language{$code};
3378: }
3379:
3380: =pod
3381:
3382: =item * &latexhyphenation()
3383:
3384: Same as above but what's supplied is the language as it might be stored
3385: in the metadata.
3386:
3387: =cut
3388:
3389: sub latexhyphenation {
3390: my $key = shift;
3391: return $latex_language_bykey{$key};
3392: }
3393:
3394: =pod
3395:
1.648 raeburn 3396: =item * ©rightids()
1.112 bowersj2 3397:
3398: returns list of all copyrights
3399:
3400: =cut
3401:
3402: sub copyrightids {
3403: return sort(keys(%cprtag));
3404: }
3405:
3406: =pod
3407:
1.648 raeburn 3408: =item * ©rightdescription()
1.112 bowersj2 3409:
3410: returns description of a specified copyright id
3411:
3412: =cut
3413:
3414: sub copyrightdescription {
1.166 www 3415: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3416: }
1.197 matthew 3417:
3418: =pod
3419:
1.648 raeburn 3420: =item * &source_copyrightids()
1.192 taceyjo1 3421:
3422: returns list of all source copyrights
3423:
3424: =cut
3425:
3426: sub source_copyrightids {
3427: return sort(keys(%scprtag));
3428: }
3429:
3430: =pod
3431:
1.648 raeburn 3432: =item * &source_copyrightdescription()
1.192 taceyjo1 3433:
3434: returns description of a specified source copyright id
3435:
3436: =cut
3437:
3438: sub source_copyrightdescription {
3439: return &mt($scprtag{shift(@_)});
3440: }
1.112 bowersj2 3441:
3442: =pod
3443:
1.648 raeburn 3444: =item * &filecategories()
1.112 bowersj2 3445:
3446: returns list of all file categories
3447:
3448: =cut
3449:
3450: sub filecategories {
3451: return sort(keys(%category_extensions));
3452: }
3453:
3454: =pod
3455:
1.648 raeburn 3456: =item * &filecategorytypes()
1.112 bowersj2 3457:
3458: returns list of file types belonging to a given file
3459: category
3460:
3461: =cut
3462:
3463: sub filecategorytypes {
1.356 albertel 3464: my ($cat) = @_;
3465: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3466: }
3467:
3468: =pod
3469:
1.648 raeburn 3470: =item * &fileembstyle()
1.112 bowersj2 3471:
3472: returns embedding style for a specified file type
3473:
3474: =cut
3475:
3476: sub fileembstyle {
3477: return $fe{lc(shift(@_))};
1.169 www 3478: }
3479:
1.351 www 3480: sub filemimetype {
3481: return $fm{lc(shift(@_))};
3482: }
3483:
1.169 www 3484:
3485: sub filecategoryselect {
3486: my ($name,$value)=@_;
1.189 matthew 3487: return &select_form($value,$name,
1.970 raeburn 3488: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3489: }
3490:
3491: =pod
3492:
1.648 raeburn 3493: =item * &filedescription()
1.112 bowersj2 3494:
3495: returns description for a specified file type
3496:
3497: =cut
3498:
3499: sub filedescription {
1.188 matthew 3500: my $file_description = $fd{lc(shift())};
3501: $file_description =~ s:([\[\]]):~$1:g;
3502: return &mt($file_description);
1.112 bowersj2 3503: }
3504:
3505: =pod
3506:
1.648 raeburn 3507: =item * &filedescriptionex()
1.112 bowersj2 3508:
3509: returns description for a specified file type with
3510: extra formatting
3511:
3512: =cut
3513:
3514: sub filedescriptionex {
3515: my $ex=shift;
1.188 matthew 3516: my $file_description = $fd{lc($ex)};
3517: $file_description =~ s:([\[\]]):~$1:g;
3518: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3519: }
3520:
3521: # End of .tab access
3522: =pod
3523:
3524: =back
3525:
3526: =cut
3527:
3528: # ------------------------------------------------------------------ File Types
3529: sub fileextensions {
3530: return sort(keys(%fe));
3531: }
3532:
1.97 www 3533: # ----------------------------------------------------------- Display Languages
3534: # returns a hash with all desired display languages
3535: #
3536:
3537: sub display_languages {
3538: my %languages=();
1.695 raeburn 3539: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3540: $languages{$lang}=1;
1.97 www 3541: }
3542: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3543: if ($env{'form.displaylanguage'}) {
1.356 albertel 3544: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3545: $languages{$lang}=1;
1.97 www 3546: }
3547: }
3548: return %languages;
1.14 harris41 3549: }
3550:
1.582 albertel 3551: sub languages {
3552: my ($possible_langs) = @_;
1.695 raeburn 3553: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3554: if (!ref($possible_langs)) {
3555: if( wantarray ) {
3556: return @preferred_langs;
3557: } else {
3558: return $preferred_langs[0];
3559: }
3560: }
3561: my %possibilities = map { $_ => 1 } (@$possible_langs);
3562: my @preferred_possibilities;
3563: foreach my $preferred_lang (@preferred_langs) {
3564: if (exists($possibilities{$preferred_lang})) {
3565: push(@preferred_possibilities, $preferred_lang);
3566: }
3567: }
3568: if( wantarray ) {
3569: return @preferred_possibilities;
3570: }
3571: return $preferred_possibilities[0];
3572: }
3573:
1.742 raeburn 3574: sub user_lang {
3575: my ($touname,$toudom,$fromcid) = @_;
3576: my @userlangs;
3577: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3578: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3579: $env{'course.'.$fromcid.'.languages'}));
3580: } else {
3581: my %langhash = &getlangs($touname,$toudom);
3582: if ($langhash{'languages'} ne '') {
3583: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3584: } else {
3585: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3586: if ($domdefs{'lang_def'} ne '') {
3587: @userlangs = ($domdefs{'lang_def'});
3588: }
3589: }
3590: }
3591: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3592: my $user_lh = Apache::localize->get_handle(@languages);
3593: return $user_lh;
3594: }
3595:
3596:
1.112 bowersj2 3597: ###############################################################
3598: ## Student Answer Attempts ##
3599: ###############################################################
3600:
3601: =pod
3602:
3603: =head1 Alternate Problem Views
3604:
3605: =over 4
3606:
1.648 raeburn 3607: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3608: $getattempt, $regexp, $gradesub)
3609:
3610: Return string with previous attempt on problem. Arguments:
3611:
3612: =over 4
3613:
3614: =item * $symb: Problem, including path
3615:
3616: =item * $username: username of the desired student
3617:
3618: =item * $domain: domain of the desired student
1.14 harris41 3619:
1.112 bowersj2 3620: =item * $course: Course ID
1.14 harris41 3621:
1.112 bowersj2 3622: =item * $getattempt: Leave blank for all attempts, otherwise put
3623: something
1.14 harris41 3624:
1.112 bowersj2 3625: =item * $regexp: if string matches this regexp, the string will be
3626: sent to $gradesub
1.14 harris41 3627:
1.112 bowersj2 3628: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3629:
1.112 bowersj2 3630: =back
1.14 harris41 3631:
1.112 bowersj2 3632: The output string is a table containing all desired attempts, if any.
1.16 harris41 3633:
1.112 bowersj2 3634: =cut
1.1 albertel 3635:
3636: sub get_previous_attempt {
1.43 ng 3637: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3638: my $prevattempts='';
1.43 ng 3639: no strict 'refs';
1.1 albertel 3640: if ($symb) {
1.3 albertel 3641: my (%returnhash)=
3642: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3643: if ($returnhash{'version'}) {
3644: my %lasthash=();
3645: my $version;
3646: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3647: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3648: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3649: }
1.1 albertel 3650: }
1.596 albertel 3651: $prevattempts=&start_data_table().&start_data_table_header_row();
3652: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3653: my (%typeparts,%lasthidden);
1.945 raeburn 3654: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3655: foreach my $key (sort(keys(%lasthash))) {
3656: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3657: if ($#parts > 0) {
1.31 albertel 3658: my $data=$parts[-1];
1.989 raeburn 3659: next if ($data eq 'foilorder');
1.31 albertel 3660: pop(@parts);
1.1010 www 3661: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3662: if ($data eq 'type') {
3663: unless ($showsurv) {
3664: my $id = join(',',@parts);
3665: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3666: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3667: $lasthidden{$ign.'.'.$id} = 1;
3668: }
1.945 raeburn 3669: }
1.1010 www 3670: }
1.31 albertel 3671: } else {
1.41 ng 3672: if ($#parts == 0) {
3673: $prevattempts.='<th>'.$parts[0].'</th>';
3674: } else {
3675: $prevattempts.='<th>'.$ign.'</th>';
3676: }
1.31 albertel 3677: }
1.16 harris41 3678: }
1.596 albertel 3679: $prevattempts.=&end_data_table_header_row();
1.40 ng 3680: if ($getattempt eq '') {
3681: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3682: my @hidden;
3683: if (%typeparts) {
3684: foreach my $id (keys(%typeparts)) {
3685: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3686: push(@hidden,$id);
3687: }
3688: }
3689: }
3690: $prevattempts.=&start_data_table_row().
3691: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3692: if (@hidden) {
3693: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3694: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3695: my $hide;
3696: foreach my $id (@hidden) {
3697: if ($key =~ /^\Q$id\E/) {
3698: $hide = 1;
3699: last;
3700: }
3701: }
3702: if ($hide) {
3703: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3704: if (($data eq 'award') || ($data eq 'awarddetail')) {
3705: my $value = &format_previous_attempt_value($key,
3706: $returnhash{$version.':'.$key});
3707: $prevattempts.='<td>'.$value.' </td>';
3708: } else {
3709: $prevattempts.='<td> </td>';
3710: }
3711: } else {
3712: if ($key =~ /\./) {
3713: my $value = &format_previous_attempt_value($key,
3714: $returnhash{$version.':'.$key});
3715: $prevattempts.='<td>'.$value.' </td>';
3716: } else {
3717: $prevattempts.='<td> </td>';
3718: }
3719: }
3720: }
3721: } else {
3722: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3723: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3724: my $value = &format_previous_attempt_value($key,
3725: $returnhash{$version.':'.$key});
3726: $prevattempts.='<td>'.$value.' </td>';
3727: }
3728: }
3729: $prevattempts.=&end_data_table_row();
1.40 ng 3730: }
1.1 albertel 3731: }
1.945 raeburn 3732: my @currhidden = keys(%lasthidden);
1.596 albertel 3733: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3734: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3735: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3736: if (%typeparts) {
3737: my $hidden;
3738: foreach my $id (@currhidden) {
3739: if ($key =~ /^\Q$id\E/) {
3740: $hidden = 1;
3741: last;
3742: }
3743: }
3744: if ($hidden) {
3745: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3746: if (($data eq 'award') || ($data eq 'awarddetail')) {
3747: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3748: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3749: $value = &$gradesub($value);
3750: }
3751: $prevattempts.='<td>'.$value.' </td>';
3752: } else {
3753: $prevattempts.='<td> </td>';
3754: }
3755: } else {
3756: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3757: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3758: $value = &$gradesub($value);
3759: }
3760: $prevattempts.='<td>'.$value.' </td>';
3761: }
3762: } else {
3763: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3764: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3765: $value = &$gradesub($value);
3766: }
3767: $prevattempts.='<td>'.$value.' </td>';
3768: }
1.16 harris41 3769: }
1.596 albertel 3770: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3771: } else {
1.596 albertel 3772: $prevattempts=
3773: &start_data_table().&start_data_table_row().
3774: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3775: &end_data_table_row().&end_data_table();
1.1 albertel 3776: }
3777: } else {
1.596 albertel 3778: $prevattempts=
3779: &start_data_table().&start_data_table_row().
3780: '<td>'.&mt('No data.').'</td>'.
3781: &end_data_table_row().&end_data_table();
1.1 albertel 3782: }
1.10 albertel 3783: }
3784:
1.581 albertel 3785: sub format_previous_attempt_value {
3786: my ($key,$value) = @_;
1.1011 www 3787: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3788: $value = &Apache::lonlocal::locallocaltime($value);
3789: } elsif (ref($value) eq 'ARRAY') {
3790: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3791: } elsif ($key =~ /answerstring$/) {
3792: my %answers = &Apache::lonnet::str2hash($value);
3793: my @anskeys = sort(keys(%answers));
3794: if (@anskeys == 1) {
3795: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3796: if ($answer =~ m{\0}) {
3797: $answer =~ s{\0}{,}g;
1.988 raeburn 3798: }
3799: my $tag_internal_answer_name = 'INTERNAL';
3800: if ($anskeys[0] eq $tag_internal_answer_name) {
3801: $value = $answer;
3802: } else {
3803: $value = $anskeys[0].'='.$answer;
3804: }
3805: } else {
3806: foreach my $ans (@anskeys) {
3807: my $answer = $answers{$ans};
1.1001 raeburn 3808: if ($answer =~ m{\0}) {
3809: $answer =~ s{\0}{,}g;
1.988 raeburn 3810: }
3811: $value .= $ans.'='.$answer.'<br />';;
3812: }
3813: }
1.581 albertel 3814: } else {
3815: $value = &unescape($value);
3816: }
3817: return $value;
3818: }
3819:
3820:
1.107 albertel 3821: sub relative_to_absolute {
3822: my ($url,$output)=@_;
3823: my $parser=HTML::TokeParser->new(\$output);
3824: my $token;
3825: my $thisdir=$url;
3826: my @rlinks=();
3827: while ($token=$parser->get_token) {
3828: if ($token->[0] eq 'S') {
3829: if ($token->[1] eq 'a') {
3830: if ($token->[2]->{'href'}) {
3831: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3832: }
3833: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3834: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3835: } elsif ($token->[1] eq 'base') {
3836: $thisdir=$token->[2]->{'href'};
3837: }
3838: }
3839: }
3840: $thisdir=~s-/[^/]*$--;
1.356 albertel 3841: foreach my $link (@rlinks) {
1.726 raeburn 3842: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3843: ($link=~/^\//) ||
3844: ($link=~/^javascript:/i) ||
3845: ($link=~/^mailto:/i) ||
3846: ($link=~/^\#/)) {
3847: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3848: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3849: }
3850: }
3851: # -------------------------------------------------- Deal with Applet codebases
3852: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3853: return $output;
3854: }
3855:
1.112 bowersj2 3856: =pod
3857:
1.648 raeburn 3858: =item * &get_student_view()
1.112 bowersj2 3859:
3860: show a snapshot of what student was looking at
3861:
3862: =cut
3863:
1.10 albertel 3864: sub get_student_view {
1.186 albertel 3865: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3866: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3867: my (%form);
1.10 albertel 3868: my @elements=('symb','courseid','domain','username');
3869: foreach my $element (@elements) {
1.186 albertel 3870: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3871: }
1.186 albertel 3872: if (defined($moreenv)) {
3873: %form=(%form,%{$moreenv});
3874: }
1.236 albertel 3875: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3876: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3877: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3878: $userview=~s/\<body[^\>]*\>//gi;
3879: $userview=~s/\<\/body\>//gi;
3880: $userview=~s/\<html\>//gi;
3881: $userview=~s/\<\/html\>//gi;
3882: $userview=~s/\<head\>//gi;
3883: $userview=~s/\<\/head\>//gi;
3884: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3885: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3886: if (wantarray) {
3887: return ($userview,$response);
3888: } else {
3889: return $userview;
3890: }
3891: }
3892:
3893: sub get_student_view_with_retries {
3894: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3895:
3896: my $ok = 0; # True if we got a good response.
3897: my $content;
3898: my $response;
3899:
3900: # Try to get the student_view done. within the retries count:
3901:
3902: do {
3903: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3904: $ok = $response->is_success;
3905: if (!$ok) {
3906: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3907: }
3908: $retries--;
3909: } while (!$ok && ($retries > 0));
3910:
3911: if (!$ok) {
3912: $content = ''; # On error return an empty content.
3913: }
1.651 www 3914: if (wantarray) {
3915: return ($content, $response);
3916: } else {
3917: return $content;
3918: }
1.11 albertel 3919: }
3920:
1.112 bowersj2 3921: =pod
3922:
1.648 raeburn 3923: =item * &get_student_answers()
1.112 bowersj2 3924:
3925: show a snapshot of how student was answering problem
3926:
3927: =cut
3928:
1.11 albertel 3929: sub get_student_answers {
1.100 sakharuk 3930: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3931: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3932: my (%moreenv);
1.11 albertel 3933: my @elements=('symb','courseid','domain','username');
3934: foreach my $element (@elements) {
1.186 albertel 3935: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3936: }
1.186 albertel 3937: $moreenv{'grade_target'}='answer';
3938: %moreenv=(%form,%moreenv);
1.497 raeburn 3939: $feedurl = &Apache::lonnet::clutter($feedurl);
3940: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3941: return $userview;
1.1 albertel 3942: }
1.116 albertel 3943:
3944: =pod
3945:
3946: =item * &submlink()
3947:
1.242 albertel 3948: Inputs: $text $uname $udom $symb $target
1.116 albertel 3949:
3950: Returns: A link to grades.pm such as to see the SUBM view of a student
3951:
3952: =cut
3953:
3954: ###############################################
3955: sub submlink {
1.242 albertel 3956: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3957: if (!($uname && $udom)) {
3958: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3959: &Apache::lonnet::whichuser($symb);
1.116 albertel 3960: if (!$symb) { $symb=$cursymb; }
3961: }
1.254 matthew 3962: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3963: $symb=&escape($symb);
1.960 bisitz 3964: if ($target) { $target=" target=\"$target\""; }
3965: return
3966: '<a href="/adm/grades?command=submission'.
3967: '&symb='.$symb.
3968: '&student='.$uname.
3969: '&userdom='.$udom.'"'.
3970: $target.'>'.$text.'</a>';
1.242 albertel 3971: }
3972: ##############################################
3973:
3974: =pod
3975:
3976: =item * &pgrdlink()
3977:
3978: Inputs: $text $uname $udom $symb $target
3979:
3980: Returns: A link to grades.pm such as to see the PGRD view of a student
3981:
3982: =cut
3983:
3984: ###############################################
3985: sub pgrdlink {
3986: my $link=&submlink(@_);
3987: $link=~s/(&command=submission)/$1&showgrading=yes/;
3988: return $link;
3989: }
3990: ##############################################
3991:
3992: =pod
3993:
3994: =item * &pprmlink()
3995:
3996: Inputs: $text $uname $udom $symb $target
3997:
3998: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3999: student and a specific resource
1.242 albertel 4000:
4001: =cut
4002:
4003: ###############################################
4004: sub pprmlink {
4005: my ($text,$uname,$udom,$symb,$target)=@_;
4006: if (!($uname && $udom)) {
4007: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4008: &Apache::lonnet::whichuser($symb);
1.242 albertel 4009: if (!$symb) { $symb=$cursymb; }
4010: }
1.254 matthew 4011: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4012: $symb=&escape($symb);
1.242 albertel 4013: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4014: return '<a href="/adm/parmset?command=set&'.
4015: 'symb='.$symb.'&uname='.$uname.
4016: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4017: }
4018: ##############################################
1.37 matthew 4019:
1.112 bowersj2 4020: =pod
4021:
4022: =back
4023:
4024: =cut
4025:
1.37 matthew 4026: ###############################################
1.51 www 4027:
4028:
4029: sub timehash {
1.687 raeburn 4030: my ($thistime) = @_;
4031: my $timezone = &Apache::lonlocal::gettimezone();
4032: my $dt = DateTime->from_epoch(epoch => $thistime)
4033: ->set_time_zone($timezone);
4034: my $wday = $dt->day_of_week();
4035: if ($wday == 7) { $wday = 0; }
4036: return ( 'second' => $dt->second(),
4037: 'minute' => $dt->minute(),
4038: 'hour' => $dt->hour(),
4039: 'day' => $dt->day_of_month(),
4040: 'month' => $dt->month(),
4041: 'year' => $dt->year(),
4042: 'weekday' => $wday,
4043: 'dayyear' => $dt->day_of_year(),
4044: 'dlsav' => $dt->is_dst() );
1.51 www 4045: }
4046:
1.370 www 4047: sub utc_string {
4048: my ($date)=@_;
1.371 www 4049: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4050: }
4051:
1.51 www 4052: sub maketime {
4053: my %th=@_;
1.687 raeburn 4054: my ($epoch_time,$timezone,$dt);
4055: $timezone = &Apache::lonlocal::gettimezone();
4056: eval {
4057: $dt = DateTime->new( year => $th{'year'},
4058: month => $th{'month'},
4059: day => $th{'day'},
4060: hour => $th{'hour'},
4061: minute => $th{'minute'},
4062: second => $th{'second'},
4063: time_zone => $timezone,
4064: );
4065: };
4066: if (!$@) {
4067: $epoch_time = $dt->epoch;
4068: if ($epoch_time) {
4069: return $epoch_time;
4070: }
4071: }
1.51 www 4072: return POSIX::mktime(
4073: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4074: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4075: }
4076:
4077: #########################################
1.51 www 4078:
4079: sub findallcourses {
1.482 raeburn 4080: my ($roles,$uname,$udom) = @_;
1.355 albertel 4081: my %roles;
4082: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4083: my %courses;
1.51 www 4084: my $now=time;
1.482 raeburn 4085: if (!defined($uname)) {
4086: $uname = $env{'user.name'};
4087: }
4088: if (!defined($udom)) {
4089: $udom = $env{'user.domain'};
4090: }
4091: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4092: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4093: if (!%roles) {
4094: %roles = (
4095: cc => 1,
1.907 raeburn 4096: co => 1,
1.482 raeburn 4097: in => 1,
4098: ep => 1,
4099: ta => 1,
4100: cr => 1,
4101: st => 1,
4102: );
4103: }
4104: foreach my $entry (keys(%roleshash)) {
4105: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4106: if ($trole =~ /^cr/) {
4107: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4108: } else {
4109: next if (!exists($roles{$trole}));
4110: }
4111: if ($tend) {
4112: next if ($tend < $now);
4113: }
4114: if ($tstart) {
4115: next if ($tstart > $now);
4116: }
1.1058 raeburn 4117: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4118: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4119: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4120: if ($secpart eq '') {
4121: ($cnum,$role) = split(/_/,$cnumpart);
4122: $sec = 'none';
1.1058 raeburn 4123: $value .= $cnum.'/';
1.482 raeburn 4124: } else {
4125: $cnum = $cnumpart;
4126: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4127: $value .= $cnum.'/'.$sec;
4128: }
4129: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4130: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4131: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4132: }
4133: } else {
4134: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4135: }
1.482 raeburn 4136: }
4137: } else {
4138: foreach my $key (keys(%env)) {
1.483 albertel 4139: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4140: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4141: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4142: next if ($role eq 'ca' || $role eq 'aa');
4143: next if (%roles && !exists($roles{$role}));
4144: my ($starttime,$endtime)=split(/\./,$env{$key});
4145: my $active=1;
4146: if ($starttime) {
4147: if ($now<$starttime) { $active=0; }
4148: }
4149: if ($endtime) {
4150: if ($now>$endtime) { $active=0; }
4151: }
4152: if ($active) {
1.1058 raeburn 4153: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4154: if ($sec eq '') {
4155: $sec = 'none';
1.1058 raeburn 4156: } else {
4157: $value .= $sec;
4158: }
4159: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4160: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4161: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4162: }
4163: } else {
4164: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4165: }
1.474 raeburn 4166: }
4167: }
1.51 www 4168: }
4169: }
1.474 raeburn 4170: return %courses;
1.51 www 4171: }
1.37 matthew 4172:
1.54 www 4173: ###############################################
1.474 raeburn 4174:
4175: sub blockcheck {
1.1062 raeburn 4176: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4177:
4178: if (!defined($udom)) {
4179: $udom = $env{'user.domain'};
4180: }
4181: if (!defined($uname)) {
4182: $uname = $env{'user.name'};
4183: }
4184:
4185: # If uname and udom are for a course, check for blocks in the course.
4186:
4187: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4188: my ($startblock,$endblock,$triggerblock) =
4189: &get_blocks($setters,$activity,$udom,$uname,$url);
4190: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4191: }
1.474 raeburn 4192:
1.502 raeburn 4193: my $startblock = 0;
4194: my $endblock = 0;
1.1062 raeburn 4195: my $triggerblock = '';
1.482 raeburn 4196: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4197:
1.490 raeburn 4198: # If uname is for a user, and activity is course-specific, i.e.,
4199: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4200:
1.490 raeburn 4201: if (($activity eq 'boards' || $activity eq 'chat' ||
4202: $activity eq 'groups') && ($env{'request.course.id'})) {
4203: foreach my $key (keys(%live_courses)) {
4204: if ($key ne $env{'request.course.id'}) {
4205: delete($live_courses{$key});
4206: }
4207: }
4208: }
4209:
4210: my $otheruser = 0;
4211: my %own_courses;
4212: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4213: # Resource belongs to user other than current user.
4214: $otheruser = 1;
4215: # Gather courses for current user
4216: %own_courses =
4217: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4218: }
4219:
4220: # Gather active course roles - course coordinator, instructor,
4221: # exam proctor, ta, student, or custom role.
1.474 raeburn 4222:
4223: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4224: my ($cdom,$cnum);
4225: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4226: $cdom = $env{'course.'.$course.'.domain'};
4227: $cnum = $env{'course.'.$course.'.num'};
4228: } else {
1.490 raeburn 4229: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4230: }
4231: my $no_ownblock = 0;
4232: my $no_userblock = 0;
1.533 raeburn 4233: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4234: # Check if current user has 'evb' priv for this
4235: if (defined($own_courses{$course})) {
4236: foreach my $sec (keys(%{$own_courses{$course}})) {
4237: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4238: if ($sec ne 'none') {
4239: $checkrole .= '/'.$sec;
4240: }
4241: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4242: $no_ownblock = 1;
4243: last;
4244: }
4245: }
4246: }
4247: # if they have 'evb' priv and are currently not playing student
4248: next if (($no_ownblock) &&
4249: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4250: }
1.474 raeburn 4251: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4252: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4253: if ($sec ne 'none') {
1.482 raeburn 4254: $checkrole .= '/'.$sec;
1.474 raeburn 4255: }
1.490 raeburn 4256: if ($otheruser) {
4257: # Resource belongs to user other than current user.
4258: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4259: my (%allroles,%userroles);
4260: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4261: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4262: my ($trole,$tdom,$tnum,$tsec);
4263: if ($entry =~ /^cr/) {
4264: ($trole,$tdom,$tnum,$tsec) =
4265: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4266: } else {
4267: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4268: }
4269: my ($spec,$area,$trest);
4270: $area = '/'.$tdom.'/'.$tnum;
4271: $trest = $tnum;
4272: if ($tsec ne '') {
4273: $area .= '/'.$tsec;
4274: $trest .= '/'.$tsec;
4275: }
4276: $spec = $trole.'.'.$area;
4277: if ($trole =~ /^cr/) {
4278: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4279: $tdom,$spec,$trest,$area);
4280: } else {
4281: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4282: $tdom,$spec,$trest,$area);
4283: }
4284: }
4285: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4286: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4287: if ($1) {
4288: $no_userblock = 1;
4289: last;
4290: }
1.486 raeburn 4291: }
4292: }
1.490 raeburn 4293: } else {
4294: # Resource belongs to current user
4295: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4296: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4297: $no_ownblock = 1;
4298: last;
4299: }
1.474 raeburn 4300: }
4301: }
4302: # if they have the evb priv and are currently not playing student
1.482 raeburn 4303: next if (($no_ownblock) &&
1.491 albertel 4304: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4305: next if ($no_userblock);
1.474 raeburn 4306:
1.866 kalberla 4307: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4308: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4309:
1.1062 raeburn 4310: my ($start,$end,$trigger) =
4311: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4312: if (($start != 0) &&
4313: (($startblock == 0) || ($startblock > $start))) {
4314: $startblock = $start;
1.1062 raeburn 4315: if ($trigger ne '') {
4316: $triggerblock = $trigger;
4317: }
1.502 raeburn 4318: }
4319: if (($end != 0) &&
4320: (($endblock == 0) || ($endblock < $end))) {
4321: $endblock = $end;
1.1062 raeburn 4322: if ($trigger ne '') {
4323: $triggerblock = $trigger;
4324: }
1.502 raeburn 4325: }
1.490 raeburn 4326: }
1.1062 raeburn 4327: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4328: }
4329:
4330: sub get_blocks {
1.1062 raeburn 4331: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4332: my $startblock = 0;
4333: my $endblock = 0;
1.1062 raeburn 4334: my $triggerblock = '';
1.490 raeburn 4335: my $course = $cdom.'_'.$cnum;
4336: $setters->{$course} = {};
4337: $setters->{$course}{'staff'} = [];
4338: $setters->{$course}{'times'} = [];
1.1062 raeburn 4339: $setters->{$course}{'triggers'} = [];
4340: my (@blockers,%triggered);
4341: my $now = time;
4342: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4343: if ($activity eq 'docs') {
4344: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4345: foreach my $block (@blockers) {
4346: if ($block =~ /^firstaccess____(.+)$/) {
4347: my $item = $1;
4348: my $type = 'map';
4349: my $timersymb = $item;
4350: if ($item eq 'course') {
4351: $type = 'course';
4352: } elsif ($item =~ /___\d+___/) {
4353: $type = 'resource';
4354: } else {
4355: $timersymb = &Apache::lonnet::symbread($item);
4356: }
4357: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4358: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4359: $triggered{$block} = {
4360: start => $start,
4361: end => $end,
4362: type => $type,
4363: };
4364: }
4365: }
4366: } else {
4367: foreach my $block (keys(%commblocks)) {
4368: if ($block =~ m/^(\d+)____(\d+)$/) {
4369: my ($start,$end) = ($1,$2);
4370: if ($start <= time && $end >= time) {
4371: if (ref($commblocks{$block}) eq 'HASH') {
4372: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4373: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4374: unless(grep(/^\Q$block\E$/,@blockers)) {
4375: push(@blockers,$block);
4376: }
4377: }
4378: }
4379: }
4380: }
4381: } elsif ($block =~ /^firstaccess____(.+)$/) {
4382: my $item = $1;
4383: my $timersymb = $item;
4384: my $type = 'map';
4385: if ($item eq 'course') {
4386: $type = 'course';
4387: } elsif ($item =~ /___\d+___/) {
4388: $type = 'resource';
4389: } else {
4390: $timersymb = &Apache::lonnet::symbread($item);
4391: }
4392: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4393: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4394: if ($start && $end) {
4395: if (($start <= time) && ($end >= time)) {
4396: unless (grep(/^\Q$block\E$/,@blockers)) {
4397: push(@blockers,$block);
4398: $triggered{$block} = {
4399: start => $start,
4400: end => $end,
4401: type => $type,
4402: };
4403: }
4404: }
1.490 raeburn 4405: }
1.1062 raeburn 4406: }
4407: }
4408: }
4409: foreach my $blocker (@blockers) {
4410: my ($staff_name,$staff_dom,$title,$blocks) =
4411: &parse_block_record($commblocks{$blocker});
4412: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4413: my ($start,$end,$triggertype);
4414: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4415: ($start,$end) = ($1,$2);
4416: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4417: $start = $triggered{$blocker}{'start'};
4418: $end = $triggered{$blocker}{'end'};
4419: $triggertype = $triggered{$blocker}{'type'};
4420: }
4421: if ($start) {
4422: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4423: if ($triggertype) {
4424: push(@{$$setters{$course}{'triggers'}},$triggertype);
4425: } else {
4426: push(@{$$setters{$course}{'triggers'}},0);
4427: }
4428: if ( ($startblock == 0) || ($startblock > $start) ) {
4429: $startblock = $start;
4430: if ($triggertype) {
4431: $triggerblock = $blocker;
1.474 raeburn 4432: }
4433: }
1.1062 raeburn 4434: if ( ($endblock == 0) || ($endblock < $end) ) {
4435: $endblock = $end;
4436: if ($triggertype) {
4437: $triggerblock = $blocker;
4438: }
4439: }
1.474 raeburn 4440: }
4441: }
1.1062 raeburn 4442: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4443: }
4444:
4445: sub parse_block_record {
4446: my ($record) = @_;
4447: my ($setuname,$setudom,$title,$blocks);
4448: if (ref($record) eq 'HASH') {
4449: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4450: $title = &unescape($record->{'event'});
4451: $blocks = $record->{'blocks'};
4452: } else {
4453: my @data = split(/:/,$record,3);
4454: if (scalar(@data) eq 2) {
4455: $title = $data[1];
4456: ($setuname,$setudom) = split(/@/,$data[0]);
4457: } else {
4458: ($setuname,$setudom,$title) = @data;
4459: }
4460: $blocks = { 'com' => 'on' };
4461: }
4462: return ($setuname,$setudom,$title,$blocks);
4463: }
4464:
1.854 kalberla 4465: sub blocking_status {
1.1062 raeburn 4466: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4467: my %setters;
1.890 droeschl 4468:
1.1061 raeburn 4469: # check for active blocking
1.1062 raeburn 4470: my ($startblock,$endblock,$triggerblock) =
4471: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4472: my $blocked = 0;
4473: if ($startblock && $endblock) {
4474: $blocked = 1;
4475: }
1.890 droeschl 4476:
1.1061 raeburn 4477: # caller just wants to know whether a block is active
4478: if (!wantarray) { return $blocked; }
4479:
4480: # build a link to a popup window containing the details
4481: my $querystring = "?activity=$activity";
4482: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4483: if ($activity eq 'port') {
4484: $querystring .= "&udom=$udom" if $udom;
4485: $querystring .= "&uname=$uname" if $uname;
4486: } elsif ($activity eq 'docs') {
4487: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4488: }
1.1061 raeburn 4489:
4490: my $output .= <<'END_MYBLOCK';
4491: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4492: var options = "width=" + w + ",height=" + h + ",";
4493: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4494: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4495: var newWin = window.open(url, wdwName, options);
4496: newWin.focus();
4497: }
1.890 droeschl 4498: END_MYBLOCK
1.854 kalberla 4499:
1.1061 raeburn 4500: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4501:
1.1061 raeburn 4502: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4503: my $text = &mt('Communication Blocked');
4504: if ($activity eq 'docs') {
4505: $text = &mt('Content Access Blocked');
1.1063 raeburn 4506: } elsif ($activity eq 'printout') {
4507: $text = &mt('Printing Blocked');
1.1062 raeburn 4508: }
1.1061 raeburn 4509: $output .= <<"END_BLOCK";
1.867 kalberla 4510: <div class='LC_comblock'>
1.869 kalberla 4511: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4512: title='$text'>
4513: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4514: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4515: title='$text'>$text</a>
1.867 kalberla 4516: </div>
4517:
4518: END_BLOCK
1.474 raeburn 4519:
1.1061 raeburn 4520: return ($blocked, $output);
1.854 kalberla 4521: }
1.490 raeburn 4522:
1.60 matthew 4523: ###############################################
4524:
1.682 raeburn 4525: sub check_ip_acc {
4526: my ($acc)=@_;
4527: &Apache::lonxml::debug("acc is $acc");
4528: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4529: return 1;
4530: }
4531: my $allowed=0;
4532: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4533:
4534: my $name;
4535: foreach my $pattern (split(',',$acc)) {
4536: $pattern =~ s/^\s*//;
4537: $pattern =~ s/\s*$//;
4538: if ($pattern =~ /\*$/) {
4539: #35.8.*
4540: $pattern=~s/\*//;
4541: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4542: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4543: #35.8.3.[34-56]
4544: my $low=$2;
4545: my $high=$3;
4546: $pattern=$1;
4547: if ($ip =~ /^\Q$pattern\E/) {
4548: my $last=(split(/\./,$ip))[3];
4549: if ($last <=$high && $last >=$low) { $allowed=1; }
4550: }
4551: } elsif ($pattern =~ /^\*/) {
4552: #*.msu.edu
4553: $pattern=~s/\*//;
4554: if (!defined($name)) {
4555: use Socket;
4556: my $netaddr=inet_aton($ip);
4557: ($name)=gethostbyaddr($netaddr,AF_INET);
4558: }
4559: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4560: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4561: #127.0.0.1
4562: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4563: } else {
4564: #some.name.com
4565: if (!defined($name)) {
4566: use Socket;
4567: my $netaddr=inet_aton($ip);
4568: ($name)=gethostbyaddr($netaddr,AF_INET);
4569: }
4570: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4571: }
4572: if ($allowed) { last; }
4573: }
4574: return $allowed;
4575: }
4576:
4577: ###############################################
4578:
1.60 matthew 4579: =pod
4580:
1.112 bowersj2 4581: =head1 Domain Template Functions
4582:
4583: =over 4
4584:
4585: =item * &determinedomain()
1.60 matthew 4586:
4587: Inputs: $domain (usually will be undef)
4588:
1.63 www 4589: Returns: Determines which domain should be used for designs
1.60 matthew 4590:
4591: =cut
1.54 www 4592:
1.60 matthew 4593: ###############################################
1.63 www 4594: sub determinedomain {
4595: my $domain=shift;
1.531 albertel 4596: if (! $domain) {
1.60 matthew 4597: # Determine domain if we have not been given one
1.893 raeburn 4598: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4599: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4600: if ($env{'request.role.domain'}) {
4601: $domain=$env{'request.role.domain'};
1.60 matthew 4602: }
4603: }
1.63 www 4604: return $domain;
4605: }
4606: ###############################################
1.517 raeburn 4607:
1.518 albertel 4608: sub devalidate_domconfig_cache {
4609: my ($udom)=@_;
4610: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4611: }
4612:
4613: # ---------------------- Get domain configuration for a domain
4614: sub get_domainconf {
4615: my ($udom) = @_;
4616: my $cachetime=1800;
4617: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4618: if (defined($cached)) { return %{$result}; }
4619:
4620: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4621: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4622: my (%designhash,%legacy);
1.518 albertel 4623: if (keys(%domconfig) > 0) {
4624: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4625: if (keys(%{$domconfig{'login'}})) {
4626: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4627: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4628: if ($key eq 'loginvia') {
4629: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4630: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4631: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4632: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4633: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4634: $designhash{$udom.'.login.loginvia'} = $server;
4635: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4636:
4637: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4638: } else {
1.1013 raeburn 4639: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4640: }
4641: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4642: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4643: }
1.946 raeburn 4644: }
4645: }
4646: }
4647: }
4648: } else {
4649: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4650: $designhash{$udom.'.login.'.$key.'_'.$img} =
4651: $domconfig{'login'}{$key}{$img};
4652: }
1.699 raeburn 4653: }
4654: } else {
4655: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4656: }
1.632 raeburn 4657: }
4658: } else {
4659: $legacy{'login'} = 1;
1.518 albertel 4660: }
1.632 raeburn 4661: } else {
4662: $legacy{'login'} = 1;
1.518 albertel 4663: }
4664: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4665: if (keys(%{$domconfig{'rolecolors'}})) {
4666: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4667: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4668: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4669: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4670: }
1.518 albertel 4671: }
4672: }
1.632 raeburn 4673: } else {
4674: $legacy{'rolecolors'} = 1;
1.518 albertel 4675: }
1.632 raeburn 4676: } else {
4677: $legacy{'rolecolors'} = 1;
1.518 albertel 4678: }
1.948 raeburn 4679: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4680: if ($domconfig{'autoenroll'}{'co-owners'}) {
4681: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4682: }
4683: }
1.632 raeburn 4684: if (keys(%legacy) > 0) {
4685: my %legacyhash = &get_legacy_domconf($udom);
4686: foreach my $item (keys(%legacyhash)) {
4687: if ($item =~ /^\Q$udom\E\.login/) {
4688: if ($legacy{'login'}) {
4689: $designhash{$item} = $legacyhash{$item};
4690: }
4691: } else {
4692: if ($legacy{'rolecolors'}) {
4693: $designhash{$item} = $legacyhash{$item};
4694: }
1.518 albertel 4695: }
4696: }
4697: }
1.632 raeburn 4698: } else {
4699: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4700: }
4701: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4702: $cachetime);
4703: return %designhash;
4704: }
4705:
1.632 raeburn 4706: sub get_legacy_domconf {
4707: my ($udom) = @_;
4708: my %legacyhash;
4709: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4710: my $designfile = $designdir.'/'.$udom.'.tab';
4711: if (-e $designfile) {
4712: if ( open (my $fh,"<$designfile") ) {
4713: while (my $line = <$fh>) {
4714: next if ($line =~ /^\#/);
4715: chomp($line);
4716: my ($key,$val)=(split(/\=/,$line));
4717: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4718: }
4719: close($fh);
4720: }
4721: }
1.1026 raeburn 4722: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4723: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4724: }
4725: return %legacyhash;
4726: }
4727:
1.63 www 4728: =pod
4729:
1.112 bowersj2 4730: =item * &domainlogo()
1.63 www 4731:
4732: Inputs: $domain (usually will be undef)
4733:
4734: Returns: A link to a domain logo, if the domain logo exists.
4735: If the domain logo does not exist, a description of the domain.
4736:
4737: =cut
1.112 bowersj2 4738:
1.63 www 4739: ###############################################
4740: sub domainlogo {
1.517 raeburn 4741: my $domain = &determinedomain(shift);
1.518 albertel 4742: my %designhash = &get_domainconf($domain);
1.517 raeburn 4743: # See if there is a logo
4744: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4745: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4746: if ($imgsrc =~ m{^/(adm|res)/}) {
4747: if ($imgsrc =~ m{^/res/}) {
4748: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4749: &Apache::lonnet::repcopy($local_name);
4750: }
4751: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4752: }
4753: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4754: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4755: return &Apache::lonnet::domain($domain,'description');
1.59 www 4756: } else {
1.60 matthew 4757: return '';
1.59 www 4758: }
4759: }
1.63 www 4760: ##############################################
4761:
4762: =pod
4763:
1.112 bowersj2 4764: =item * &designparm()
1.63 www 4765:
4766: Inputs: $which parameter; $domain (usually will be undef)
4767:
4768: Returns: value of designparamter $which
4769:
4770: =cut
1.112 bowersj2 4771:
1.397 albertel 4772:
1.400 albertel 4773: ##############################################
1.397 albertel 4774: sub designparm {
4775: my ($which,$domain)=@_;
4776: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4777: return $env{'environment.color.'.$which};
1.96 www 4778: }
1.63 www 4779: $domain=&determinedomain($domain);
1.1016 raeburn 4780: my %domdesign;
4781: unless ($domain eq 'public') {
4782: %domdesign = &get_domainconf($domain);
4783: }
1.520 raeburn 4784: my $output;
1.517 raeburn 4785: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4786: $output = $domdesign{$domain.'.'.$which};
1.63 www 4787: } else {
1.520 raeburn 4788: $output = $defaultdesign{$which};
4789: }
4790: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4791: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4792: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4793: if ($output =~ m{^/res/}) {
4794: my $local_name = &Apache::lonnet::filelocation('',$output);
4795: &Apache::lonnet::repcopy($local_name);
4796: }
1.520 raeburn 4797: $output = &lonhttpdurl($output);
4798: }
1.63 www 4799: }
1.520 raeburn 4800: return $output;
1.63 www 4801: }
1.59 www 4802:
1.822 bisitz 4803: ##############################################
4804: =pod
4805:
1.832 bisitz 4806: =item * &authorspace()
4807:
1.1028 raeburn 4808: Inputs: $url (usually will be undef).
1.832 bisitz 4809:
1.1028 raeburn 4810: Returns: Path to Construction Space containing the resource or
4811: directory being viewed (or for which action is being taken).
4812: If $url is provided, and begins /priv/<domain>/<uname>
4813: the path will be that portion of the $context argument.
4814: Otherwise the path will be for the author space of the current
4815: user when the current role is author, or for that of the
4816: co-author/assistant co-author space when the current role
4817: is co-author or assistant co-author.
1.832 bisitz 4818:
4819: =cut
4820:
4821: sub authorspace {
1.1028 raeburn 4822: my ($url) = @_;
4823: if ($url ne '') {
4824: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4825: return $1;
4826: }
4827: }
1.832 bisitz 4828: my $caname = '';
1.1024 www 4829: my $cadom = '';
1.1028 raeburn 4830: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4831: ($cadom,$caname) =
1.832 bisitz 4832: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4833: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4834: $caname = $env{'user.name'};
1.1024 www 4835: $cadom = $env{'user.domain'};
1.832 bisitz 4836: }
1.1028 raeburn 4837: if (($caname ne '') && ($cadom ne '')) {
4838: return "/priv/$cadom/$caname/";
4839: }
4840: return;
1.832 bisitz 4841: }
4842:
4843: ##############################################
4844: =pod
4845:
1.822 bisitz 4846: =item * &head_subbox()
4847:
4848: Inputs: $content (contains HTML code with page functions, etc.)
4849:
4850: Returns: HTML div with $content
4851: To be included in page header
4852:
4853: =cut
4854:
4855: sub head_subbox {
4856: my ($content)=@_;
4857: my $output =
1.993 raeburn 4858: '<div class="LC_head_subbox">'
1.822 bisitz 4859: .$content
4860: .'</div>'
4861: }
4862:
4863: ##############################################
4864: =pod
4865:
4866: =item * &CSTR_pageheader()
4867:
1.1026 raeburn 4868: Input: (optional) filename from which breadcrumb trail is built.
4869: In most cases no input as needed, as $env{'request.filename'}
4870: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4871:
4872: Returns: HTML div with CSTR path and recent box
4873: To be included on Construction Space pages
4874:
4875: =cut
4876:
4877: sub CSTR_pageheader {
1.1026 raeburn 4878: my ($trailfile) = @_;
4879: if ($trailfile eq '') {
4880: $trailfile = $env{'request.filename'};
4881: }
4882:
4883: # this is for resources; directories have customtitle, and crumbs
4884: # and select recent are created in lonpubdir.pm
4885:
4886: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4887: my ($udom,$uname,$thisdisfn)=
1.1026 raeburn 4888: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
4889: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4890: $formaction =~ s{/+}{/}g;
1.822 bisitz 4891:
4892: my $parentpath = '';
4893: my $lastitem = '';
4894: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4895: $parentpath = $1;
4896: $lastitem = $2;
4897: } else {
4898: $lastitem = $thisdisfn;
4899: }
1.921 bisitz 4900:
4901: my $output =
1.822 bisitz 4902: '<div>'
4903: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4904: .'<b>'.&mt('Construction Space:').'</b> '
4905: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4906: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4907: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4908:
4909: if ($lastitem) {
4910: $output .=
4911: '<span class="LC_filename">'
4912: .$lastitem
4913: .'</span>';
4914: }
4915: $output .=
4916: '<br />'
1.822 bisitz 4917: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4918: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4919: .'</form>'
4920: .&Apache::lonmenu::constspaceform()
4921: .'</div>';
1.921 bisitz 4922:
4923: return $output;
1.822 bisitz 4924: }
4925:
1.60 matthew 4926: ###############################################
4927: ###############################################
4928:
4929: =pod
4930:
1.112 bowersj2 4931: =back
4932:
1.549 albertel 4933: =head1 HTML Helpers
1.112 bowersj2 4934:
4935: =over 4
4936:
4937: =item * &bodytag()
1.60 matthew 4938:
4939: Returns a uniform header for LON-CAPA web pages.
4940:
4941: Inputs:
4942:
1.112 bowersj2 4943: =over 4
4944:
4945: =item * $title, A title to be displayed on the page.
4946:
4947: =item * $function, the current role (can be undef).
4948:
4949: =item * $addentries, extra parameters for the <body> tag.
4950:
4951: =item * $bodyonly, if defined, only return the <body> tag.
4952:
4953: =item * $domain, if defined, force a given domain.
4954:
4955: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4956: text interface only)
1.60 matthew 4957:
1.814 bisitz 4958: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4959: navigational links
1.317 albertel 4960:
1.338 albertel 4961: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4962:
1.1075.2.12 raeburn 4963: =item * $no_inline_link, if true and in remote mode, don't show the
4964: 'Switch To Inline Menu' link
4965:
1.460 albertel 4966: =item * $args, optional argument valid values are
4967: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4968: inherit_jsmath -> when creating popup window in a page,
4969: should it have jsmath forced on by the
4970: current page
1.460 albertel 4971:
1.112 bowersj2 4972: =back
4973:
1.60 matthew 4974: Returns: A uniform header for LON-CAPA web pages.
4975: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4976: If $bodyonly is undef or zero, an html string containing a <body> tag and
4977: other decorations will be returned.
4978:
4979: =cut
4980:
1.54 www 4981: sub bodytag {
1.831 bisitz 4982: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.12 raeburn 4983: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4984:
1.954 raeburn 4985: my $public;
4986: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4987: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4988: $public = 1;
4989: }
1.460 albertel 4990: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4991:
1.183 matthew 4992: $function = &get_users_function() if (!$function);
1.339 albertel 4993: my $img = &designparm($function.'.img',$domain);
4994: my $font = &designparm($function.'.font',$domain);
4995: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4996:
1.803 bisitz 4997: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4998: 'bgcolor' => $pgbg,
1.339 albertel 4999: 'text' => $font,
5000: 'alink' => &designparm($function.'.alink',$domain),
5001: 'vlink' => &designparm($function.'.vlink',$domain),
5002: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5003: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5004:
1.63 www 5005: # role and realm
1.378 raeburn 5006: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5007: if ($role eq 'ca') {
1.479 albertel 5008: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5009: $realm = &plainname($rname,$rdom);
1.378 raeburn 5010: }
1.55 www 5011: # realm
1.258 albertel 5012: if ($env{'request.course.id'}) {
1.378 raeburn 5013: if ($env{'request.role'} !~ /^cr/) {
5014: $role = &Apache::lonnet::plaintext($role,&course_type());
5015: }
1.898 raeburn 5016: if ($env{'request.course.sec'}) {
5017: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5018: }
1.359 albertel 5019: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5020: } else {
5021: $role = &Apache::lonnet::plaintext($role);
1.54 www 5022: }
1.433 albertel 5023:
1.359 albertel 5024: if (!$realm) { $realm=' '; }
1.1075.2.12 raeburn 5025: # Set messages
5026: my $messages=&domainlogo($domain);
1.330 albertel 5027:
1.438 albertel 5028: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5029:
1.101 www 5030: # construct main body tag
1.359 albertel 5031: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5032: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5033:
1.530 albertel 5034: if ($bodyonly) {
1.60 matthew 5035: return $bodytag;
1.798 tempelho 5036: }
1.359 albertel 5037:
1.410 albertel 5038: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 5039: if ($public) {
1.433 albertel 5040: undef($role);
1.434 albertel 5041: } else {
1.1070 raeburn 5042: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5043: undef,'LC_menubuttons_link');
1.433 albertel 5044: }
1.359 albertel 5045:
1.762 bisitz 5046: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5047: #
5048: # Extra info if you are the DC
5049: my $dc_info = '';
5050: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5051: $env{'course.'.$env{'request.course.id'}.
5052: '.domain'}.'/'})) {
5053: my $cid = $env{'request.course.id'};
1.917 raeburn 5054: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5055: $dc_info =~ s/\s+$//;
1.359 albertel 5056: }
5057:
1.898 raeburn 5058: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5059: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5060:
1.1075.2.13 raeburn 5061: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
5062: return $bodytag;
5063: }
1.903 droeschl 5064:
1.1075.2.13 raeburn 5065: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5066:
5067: unless ($env{'environment.remote'} eq 'on') {
1.903 droeschl 5068:
5069: # if ($env{'request.state'} eq 'construct') {
5070: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5071: # }
5072:
1.359 albertel 5073:
1.1075.2.2 raeburn 5074:
1.916 droeschl 5075: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.1 raeburn 5076: unless ($env{'request.noversionuri'} =~ m{/res/adm/pages/bookmarkmenu/}) {
5077: if ($dc_info) {
5078: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5079: }
5080: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
5081: <em>$realm</em> $dc_info</div>|;
5082: }
1.903 droeschl 5083: return $bodytag;
5084: }
1.894 droeschl 5085:
1.927 raeburn 5086: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5087: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
5088: }
1.916 droeschl 5089:
1.903 droeschl 5090: $bodytag .= Apache::lonhtmlcommon::scripttag(
5091: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 5092:
1.903 droeschl 5093: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 5094:
1.917 raeburn 5095: if ($dc_info) {
5096: $dc_info = &dc_courseid_toggle($dc_info);
5097: }
5098: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5099:
1.903 droeschl 5100: #don't show menus for public users
1.954 raeburn 5101: if (!$public){
1.903 droeschl 5102: $bodytag .= Apache::lonmenu::secondary_menu();
5103: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5104: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5105: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5106: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5107: $args->{'bread_crumbs'});
5108: } elsif ($forcereg) {
5109: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
5110: }
1.903 droeschl 5111: }else{
5112: # this is to seperate menu from content when there's no secondary
5113: # menu. Especially needed for public accessible ressources.
5114: $bodytag .= '<hr style="clear:both" />';
5115: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5116: }
1.903 droeschl 5117:
1.235 raeburn 5118: return $bodytag;
1.1075.2.12 raeburn 5119: }
5120:
5121: #
5122: # Top frame rendering, Remote is up
5123: #
5124:
5125: my $imgsrc = $img;
5126: if ($img =~ /^\/adm/) {
5127: $imgsrc = &lonhttpdurl($img);
5128: }
5129: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5130:
5131: # Explicit link to get inline menu
5132: my $menu= ($no_inline_link?''
5133: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5134:
5135: if ($dc_info) {
5136: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5137: }
5138:
5139: unless ($env{'form.inhibitmenu'}) {
5140: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
5141: <ol class="LC_primary_menu LC_right">
5142: <li>$menu</li>
5143: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5144: }
1.1075.2.13 raeburn 5145: my $funclist;
5146: if ($env{'request.state'} eq 'construct') {
5147: if (!$public){
5148: if ($env{'request.state'} eq 'construct') {
5149: $funclist = &Apache::lonhtmlcommon::scripttag(
5150: &Apache::lonmenu::utilityfunctions(), 'start').
5151: &Apache::lonhtmlcommon::scripttag('','end').
5152: &Apache::lonmenu::innerregister($forcereg,
5153: $args->{'bread_crumbs'});
5154: }
5155: }
5156: }
1.1075.2.12 raeburn 5157: return(<<ENDBODY);
5158: $bodytag
5159: <table id="LC_title_bar" class="LC_with_remote">
5160: <tr><td>$upperleft</td>
5161: <td>$messages </td>
5162: </tr>
5163: <tr><td>$titleinfo $dc_info $menu</td>
5164: </tr>
5165: </table>
1.1075.2.13 raeburn 5166: $funclist
1.1075.2.12 raeburn 5167: ENDBODY
1.182 matthew 5168: }
5169:
1.917 raeburn 5170: sub dc_courseid_toggle {
5171: my ($dc_info) = @_;
1.980 raeburn 5172: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5173: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5174: &mt('(More ...)').'</a></span>'.
5175: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5176: }
5177:
1.330 albertel 5178: sub make_attr_string {
5179: my ($register,$attr_ref) = @_;
5180:
5181: if ($attr_ref && !ref($attr_ref)) {
5182: die("addentries Must be a hash ref ".
5183: join(':',caller(1))." ".
5184: join(':',caller(0))." ");
5185: }
5186:
5187: if ($register) {
1.339 albertel 5188: my ($on_load,$on_unload);
5189: foreach my $key (keys(%{$attr_ref})) {
5190: if (lc($key) eq 'onload') {
5191: $on_load.=$attr_ref->{$key}.';';
5192: delete($attr_ref->{$key});
5193:
5194: } elsif (lc($key) eq 'onunload') {
5195: $on_unload.=$attr_ref->{$key}.';';
5196: delete($attr_ref->{$key});
5197: }
5198: }
1.1075.2.12 raeburn 5199: if ($env{'environment.remote'} eq 'on') {
5200: $attr_ref->{'onload'} =
5201: &Apache::lonmenu::loadevents(). $on_load;
5202: $attr_ref->{'onunload'}=
5203: &Apache::lonmenu::unloadevents().$on_unload;
5204: } else {
5205: $attr_ref->{'onload'} = $on_load;
5206: $attr_ref->{'onunload'}= $on_unload;
5207: }
1.330 albertel 5208: }
1.339 albertel 5209:
1.330 albertel 5210: my $attr_string;
5211: foreach my $attr (keys(%$attr_ref)) {
5212: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5213: }
5214: return $attr_string;
5215: }
5216:
5217:
1.182 matthew 5218: ###############################################
1.251 albertel 5219: ###############################################
5220:
5221: =pod
5222:
5223: =item * &endbodytag()
5224:
5225: Returns a uniform footer for LON-CAPA web pages.
5226:
1.635 raeburn 5227: Inputs: 1 - optional reference to an args hash
5228: If in the hash, key for noredirectlink has a value which evaluates to true,
5229: a 'Continue' link is not displayed if the page contains an
5230: internal redirect in the <head></head> section,
5231: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5232:
5233: =cut
5234:
5235: sub endbodytag {
1.635 raeburn 5236: my ($args) = @_;
1.1075.2.6 raeburn 5237: my $endbodytag;
5238: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5239: $endbodytag='</body>';
5240: }
1.269 albertel 5241: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5242: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5243: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5244: $endbodytag=
5245: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5246: &mt('Continue').'</a>'.
5247: $endbodytag;
5248: }
1.315 albertel 5249: }
1.251 albertel 5250: return $endbodytag;
5251: }
5252:
1.352 albertel 5253: =pod
5254:
5255: =item * &standard_css()
5256:
5257: Returns a style sheet
5258:
5259: Inputs: (all optional)
5260: domain -> force to color decorate a page for a specific
5261: domain
5262: function -> force usage of a specific rolish color scheme
5263: bgcolor -> override the default page bgcolor
5264:
5265: =cut
5266:
1.343 albertel 5267: sub standard_css {
1.345 albertel 5268: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5269: $function = &get_users_function() if (!$function);
5270: my $img = &designparm($function.'.img', $domain);
5271: my $tabbg = &designparm($function.'.tabbg', $domain);
5272: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5273: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5274: #second colour for later usage
1.345 albertel 5275: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5276: my $pgbg_or_bgcolor =
5277: $bgcolor ||
1.352 albertel 5278: &designparm($function.'.pgbg', $domain);
1.382 albertel 5279: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5280: my $alink = &designparm($function.'.alink', $domain);
5281: my $vlink = &designparm($function.'.vlink', $domain);
5282: my $link = &designparm($function.'.link', $domain);
5283:
1.602 albertel 5284: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5285: my $mono = 'monospace';
1.850 bisitz 5286: my $data_table_head = $sidebg;
5287: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5288: my $data_table_dark = '#E0E0E0';
1.470 banghart 5289: my $data_table_darker = '#CCCCCC';
1.349 albertel 5290: my $data_table_highlight = '#FFFF00';
1.352 albertel 5291: my $mail_new = '#FFBB77';
5292: my $mail_new_hover = '#DD9955';
5293: my $mail_read = '#BBBB77';
5294: my $mail_read_hover = '#999944';
5295: my $mail_replied = '#AAAA88';
5296: my $mail_replied_hover = '#888855';
5297: my $mail_other = '#99BBBB';
5298: my $mail_other_hover = '#669999';
1.391 albertel 5299: my $table_header = '#DDDDDD';
1.489 raeburn 5300: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5301: my $lg_border_color = '#C8C8C8';
1.952 onken 5302: my $button_hover = '#BF2317';
1.392 albertel 5303:
1.608 albertel 5304: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5305: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5306: : '0 3px 0 4px';
1.448 albertel 5307:
1.523 albertel 5308:
1.343 albertel 5309: return <<END;
1.947 droeschl 5310:
5311: /* needed for iframe to allow 100% height in FF */
5312: body, html {
5313: margin: 0;
5314: padding: 0 0.5%;
5315: height: 99%; /* to avoid scrollbars */
5316: }
5317:
1.795 www 5318: body {
1.911 bisitz 5319: font-family: $sans;
5320: line-height:130%;
5321: font-size:0.83em;
5322: color:$font;
1.795 www 5323: }
5324:
1.959 onken 5325: a:focus,
5326: a:focus img {
1.795 www 5327: color: red;
5328: }
1.698 harmsja 5329:
1.911 bisitz 5330: form, .inline {
5331: display: inline;
1.795 www 5332: }
1.721 harmsja 5333:
1.795 www 5334: .LC_right {
1.911 bisitz 5335: text-align:right;
1.795 www 5336: }
5337:
5338: .LC_middle {
1.911 bisitz 5339: vertical-align:middle;
1.795 www 5340: }
1.721 harmsja 5341:
1.911 bisitz 5342: .LC_400Box {
5343: width:400px;
5344: }
1.721 harmsja 5345:
1.947 droeschl 5346: .LC_iframecontainer {
5347: width: 98%;
5348: margin: 0;
5349: position: fixed;
5350: top: 8.5em;
5351: bottom: 0;
5352: }
5353:
5354: .LC_iframecontainer iframe{
5355: border: none;
5356: width: 100%;
5357: height: 100%;
5358: }
5359:
1.778 bisitz 5360: .LC_filename {
5361: font-family: $mono;
5362: white-space:pre;
1.921 bisitz 5363: font-size: 120%;
1.778 bisitz 5364: }
5365:
5366: .LC_fileicon {
5367: border: none;
5368: height: 1.3em;
5369: vertical-align: text-bottom;
5370: margin-right: 0.3em;
5371: text-decoration:none;
5372: }
5373:
1.1008 www 5374: .LC_setting {
5375: text-decoration:underline;
5376: }
5377:
1.350 albertel 5378: .LC_error {
5379: color: red;
5380: font-size: larger;
5381: }
1.795 www 5382:
1.457 albertel 5383: .LC_warning,
5384: .LC_diff_removed {
1.733 bisitz 5385: color: red;
1.394 albertel 5386: }
1.532 albertel 5387:
5388: .LC_info,
1.457 albertel 5389: .LC_success,
5390: .LC_diff_added {
1.350 albertel 5391: color: green;
5392: }
1.795 www 5393:
1.802 bisitz 5394: div.LC_confirm_box {
5395: background-color: #FAFAFA;
5396: border: 1px solid $lg_border_color;
5397: margin-right: 0;
5398: padding: 5px;
5399: }
5400:
5401: div.LC_confirm_box .LC_error img,
5402: div.LC_confirm_box .LC_success img {
5403: vertical-align: middle;
5404: }
5405:
1.440 albertel 5406: .LC_icon {
1.771 droeschl 5407: border: none;
1.790 droeschl 5408: vertical-align: middle;
1.771 droeschl 5409: }
5410:
1.543 albertel 5411: .LC_docs_spacer {
5412: width: 25px;
5413: height: 1px;
1.771 droeschl 5414: border: none;
1.543 albertel 5415: }
1.346 albertel 5416:
1.532 albertel 5417: .LC_internal_info {
1.735 bisitz 5418: color: #999999;
1.532 albertel 5419: }
5420:
1.794 www 5421: .LC_discussion {
1.1050 www 5422: background: $data_table_dark;
1.911 bisitz 5423: border: 1px solid black;
5424: margin: 2px;
1.794 www 5425: }
5426:
5427: .LC_disc_action_left {
1.1050 www 5428: background: $sidebg;
1.911 bisitz 5429: text-align: left;
1.1050 www 5430: padding: 4px;
5431: margin: 2px;
1.794 www 5432: }
5433:
5434: .LC_disc_action_right {
1.1050 www 5435: background: $sidebg;
1.911 bisitz 5436: text-align: right;
1.1050 www 5437: padding: 4px;
5438: margin: 2px;
1.794 www 5439: }
5440:
5441: .LC_disc_new_item {
1.911 bisitz 5442: background: white;
5443: border: 2px solid red;
1.1050 www 5444: margin: 4px;
5445: padding: 4px;
1.794 www 5446: }
5447:
5448: .LC_disc_old_item {
1.911 bisitz 5449: background: white;
1.1050 www 5450: margin: 4px;
5451: padding: 4px;
1.794 www 5452: }
5453:
1.458 albertel 5454: table.LC_pastsubmission {
5455: border: 1px solid black;
5456: margin: 2px;
5457: }
5458:
1.924 bisitz 5459: table#LC_menubuttons {
1.345 albertel 5460: width: 100%;
5461: background: $pgbg;
1.392 albertel 5462: border: 2px;
1.402 albertel 5463: border-collapse: separate;
1.803 bisitz 5464: padding: 0;
1.345 albertel 5465: }
1.392 albertel 5466:
1.801 tempelho 5467: table#LC_title_bar a {
5468: color: $fontmenu;
5469: }
1.836 bisitz 5470:
1.807 droeschl 5471: table#LC_title_bar {
1.819 tempelho 5472: clear: both;
1.836 bisitz 5473: display: none;
1.807 droeschl 5474: }
5475:
1.795 www 5476: table#LC_title_bar,
1.933 droeschl 5477: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5478: table#LC_title_bar.LC_with_remote {
1.359 albertel 5479: width: 100%;
1.392 albertel 5480: border-color: $pgbg;
5481: border-style: solid;
5482: border-width: $border;
1.379 albertel 5483: background: $pgbg;
1.801 tempelho 5484: color: $fontmenu;
1.392 albertel 5485: border-collapse: collapse;
1.803 bisitz 5486: padding: 0;
1.819 tempelho 5487: margin: 0;
1.359 albertel 5488: }
1.795 www 5489:
1.933 droeschl 5490: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5491: margin: 0;
5492: padding: 0;
1.933 droeschl 5493: position: relative;
5494: list-style: none;
1.913 droeschl 5495: }
1.933 droeschl 5496: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5497: display: inline;
5498: }
1.933 droeschl 5499:
5500: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5501: padding: 0;
1.933 droeschl 5502: margin: 0;
5503: float: left;
1.913 droeschl 5504: }
1.933 droeschl 5505: .LC_breadcrumb_tools_tools {
5506: padding: 0;
5507: margin: 0;
1.913 droeschl 5508: float: right;
5509: }
5510:
1.359 albertel 5511: table#LC_title_bar td {
5512: background: $tabbg;
5513: }
1.795 www 5514:
1.911 bisitz 5515: table#LC_menubuttons img {
1.803 bisitz 5516: border: none;
1.346 albertel 5517: }
1.795 www 5518:
1.842 droeschl 5519: .LC_breadcrumbs_component {
1.911 bisitz 5520: float: right;
5521: margin: 0 1em;
1.357 albertel 5522: }
1.842 droeschl 5523: .LC_breadcrumbs_component img {
1.911 bisitz 5524: vertical-align: middle;
1.777 tempelho 5525: }
1.795 www 5526:
1.383 albertel 5527: td.LC_table_cell_checkbox {
5528: text-align: center;
5529: }
1.795 www 5530:
5531: .LC_fontsize_small {
1.911 bisitz 5532: font-size: 70%;
1.705 tempelho 5533: }
5534:
1.844 bisitz 5535: #LC_breadcrumbs {
1.911 bisitz 5536: clear:both;
5537: background: $sidebg;
5538: border-bottom: 1px solid $lg_border_color;
5539: line-height: 2.5em;
1.933 droeschl 5540: overflow: hidden;
1.911 bisitz 5541: margin: 0;
5542: padding: 0;
1.995 raeburn 5543: text-align: left;
1.819 tempelho 5544: }
1.862 bisitz 5545:
1.993 raeburn 5546: .LC_head_subbox {
1.911 bisitz 5547: clear:both;
5548: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5549: border: 1px solid $sidebg;
5550: margin: 0 0 10px 0;
1.966 bisitz 5551: padding: 3px;
1.995 raeburn 5552: text-align: left;
1.822 bisitz 5553: }
5554:
1.795 www 5555: .LC_fontsize_medium {
1.911 bisitz 5556: font-size: 85%;
1.705 tempelho 5557: }
5558:
1.795 www 5559: .LC_fontsize_large {
1.911 bisitz 5560: font-size: 120%;
1.705 tempelho 5561: }
5562:
1.346 albertel 5563: .LC_menubuttons_inline_text {
5564: color: $font;
1.698 harmsja 5565: font-size: 90%;
1.701 harmsja 5566: padding-left:3px;
1.346 albertel 5567: }
5568:
1.934 droeschl 5569: .LC_menubuttons_inline_text img{
5570: vertical-align: middle;
5571: }
5572:
1.1051 www 5573: li.LC_menubuttons_inline_text img {
1.951 onken 5574: cursor:pointer;
1.1002 droeschl 5575: text-decoration: none;
1.951 onken 5576: }
5577:
1.526 www 5578: .LC_menubuttons_link {
5579: text-decoration: none;
5580: }
1.795 www 5581:
1.522 albertel 5582: .LC_menubuttons_category {
1.521 www 5583: color: $font;
1.526 www 5584: background: $pgbg;
1.521 www 5585: font-size: larger;
5586: font-weight: bold;
5587: }
5588:
1.346 albertel 5589: td.LC_menubuttons_text {
1.911 bisitz 5590: color: $font;
1.346 albertel 5591: }
1.706 harmsja 5592:
1.346 albertel 5593: .LC_current_location {
5594: background: $tabbg;
5595: }
1.795 www 5596:
1.938 bisitz 5597: table.LC_data_table {
1.347 albertel 5598: border: 1px solid #000000;
1.402 albertel 5599: border-collapse: separate;
1.426 albertel 5600: border-spacing: 1px;
1.610 albertel 5601: background: $pgbg;
1.347 albertel 5602: }
1.795 www 5603:
1.422 albertel 5604: .LC_data_table_dense {
5605: font-size: small;
5606: }
1.795 www 5607:
1.507 raeburn 5608: table.LC_nested_outer {
5609: border: 1px solid #000000;
1.589 raeburn 5610: border-collapse: collapse;
1.803 bisitz 5611: border-spacing: 0;
1.507 raeburn 5612: width: 100%;
5613: }
1.795 www 5614:
1.879 raeburn 5615: table.LC_innerpickbox,
1.507 raeburn 5616: table.LC_nested {
1.803 bisitz 5617: border: none;
1.589 raeburn 5618: border-collapse: collapse;
1.803 bisitz 5619: border-spacing: 0;
1.507 raeburn 5620: width: 100%;
5621: }
1.795 www 5622:
1.911 bisitz 5623: table.LC_data_table tr th,
5624: table.LC_calendar tr th,
1.879 raeburn 5625: table.LC_prior_tries tr th,
5626: table.LC_innerpickbox tr th {
1.349 albertel 5627: font-weight: bold;
5628: background-color: $data_table_head;
1.801 tempelho 5629: color:$fontmenu;
1.701 harmsja 5630: font-size:90%;
1.347 albertel 5631: }
1.795 www 5632:
1.879 raeburn 5633: table.LC_innerpickbox tr th,
5634: table.LC_innerpickbox tr td {
5635: vertical-align: top;
5636: }
5637:
1.711 raeburn 5638: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5639: background-color: #CCCCCC;
1.711 raeburn 5640: font-weight: bold;
5641: text-align: left;
5642: }
1.795 www 5643:
1.912 bisitz 5644: table.LC_data_table tr.LC_odd_row > td {
5645: background-color: $data_table_light;
5646: padding: 2px;
5647: vertical-align: top;
5648: }
5649:
1.809 bisitz 5650: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5651: background-color: $data_table_light;
1.912 bisitz 5652: vertical-align: top;
5653: }
5654:
5655: table.LC_data_table tr.LC_even_row > td {
5656: background-color: $data_table_dark;
1.425 albertel 5657: padding: 2px;
1.900 bisitz 5658: vertical-align: top;
1.347 albertel 5659: }
1.795 www 5660:
1.809 bisitz 5661: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5662: background-color: $data_table_dark;
1.900 bisitz 5663: vertical-align: top;
1.347 albertel 5664: }
1.795 www 5665:
1.425 albertel 5666: table.LC_data_table tr.LC_data_table_highlight td {
5667: background-color: $data_table_darker;
5668: }
1.795 www 5669:
1.639 raeburn 5670: table.LC_data_table tr td.LC_leftcol_header {
5671: background-color: $data_table_head;
5672: font-weight: bold;
5673: }
1.795 www 5674:
1.451 albertel 5675: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5676: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5677: font-weight: bold;
5678: font-style: italic;
5679: text-align: center;
5680: padding: 8px;
1.347 albertel 5681: }
1.795 www 5682:
1.940 bisitz 5683: table.LC_data_table tr.LC_empty_row td {
5684: background-color: $sidebg;
5685: }
5686:
5687: table.LC_nested tr.LC_empty_row td {
5688: background-color: #FFFFFF;
5689: }
5690:
1.890 droeschl 5691: table.LC_caption {
5692: }
5693:
1.507 raeburn 5694: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5695: padding: 4ex
5696: }
1.795 www 5697:
1.507 raeburn 5698: table.LC_nested_outer tr th {
5699: font-weight: bold;
1.801 tempelho 5700: color:$fontmenu;
1.507 raeburn 5701: background-color: $data_table_head;
1.701 harmsja 5702: font-size: small;
1.507 raeburn 5703: border-bottom: 1px solid #000000;
5704: }
1.795 www 5705:
1.507 raeburn 5706: table.LC_nested_outer tr td.LC_subheader {
5707: background-color: $data_table_head;
5708: font-weight: bold;
5709: font-size: small;
5710: border-bottom: 1px solid #000000;
5711: text-align: right;
1.451 albertel 5712: }
1.795 www 5713:
1.507 raeburn 5714: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5715: background-color: #CCCCCC;
1.451 albertel 5716: font-weight: bold;
5717: font-size: small;
1.507 raeburn 5718: text-align: center;
5719: }
1.795 www 5720:
1.589 raeburn 5721: table.LC_nested tr.LC_info_row td.LC_left_item,
5722: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5723: text-align: left;
1.451 albertel 5724: }
1.795 www 5725:
1.507 raeburn 5726: table.LC_nested td {
1.735 bisitz 5727: background-color: #FFFFFF;
1.451 albertel 5728: font-size: small;
1.507 raeburn 5729: }
1.795 www 5730:
1.507 raeburn 5731: table.LC_nested_outer tr th.LC_right_item,
5732: table.LC_nested tr.LC_info_row td.LC_right_item,
5733: table.LC_nested tr.LC_odd_row td.LC_right_item,
5734: table.LC_nested tr td.LC_right_item {
1.451 albertel 5735: text-align: right;
5736: }
5737:
1.507 raeburn 5738: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5739: background-color: #EEEEEE;
1.451 albertel 5740: }
5741:
1.473 raeburn 5742: table.LC_createuser {
5743: }
5744:
5745: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5746: font-size: small;
1.473 raeburn 5747: }
5748:
5749: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5750: background-color: #CCCCCC;
1.473 raeburn 5751: font-weight: bold;
5752: text-align: center;
5753: }
5754:
1.349 albertel 5755: table.LC_calendar {
5756: border: 1px solid #000000;
5757: border-collapse: collapse;
1.917 raeburn 5758: width: 98%;
1.349 albertel 5759: }
1.795 www 5760:
1.349 albertel 5761: table.LC_calendar_pickdate {
5762: font-size: xx-small;
5763: }
1.795 www 5764:
1.349 albertel 5765: table.LC_calendar tr td {
5766: border: 1px solid #000000;
5767: vertical-align: top;
1.917 raeburn 5768: width: 14%;
1.349 albertel 5769: }
1.795 www 5770:
1.349 albertel 5771: table.LC_calendar tr td.LC_calendar_day_empty {
5772: background-color: $data_table_dark;
5773: }
1.795 www 5774:
1.779 bisitz 5775: table.LC_calendar tr td.LC_calendar_day_current {
5776: background-color: $data_table_highlight;
1.777 tempelho 5777: }
1.795 www 5778:
1.938 bisitz 5779: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5780: background-color: $mail_new;
5781: }
1.795 www 5782:
1.938 bisitz 5783: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5784: background-color: $mail_new_hover;
5785: }
1.795 www 5786:
1.938 bisitz 5787: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5788: background-color: $mail_read;
5789: }
1.795 www 5790:
1.938 bisitz 5791: /*
5792: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5793: background-color: $mail_read_hover;
5794: }
1.938 bisitz 5795: */
1.795 www 5796:
1.938 bisitz 5797: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5798: background-color: $mail_replied;
5799: }
1.795 www 5800:
1.938 bisitz 5801: /*
5802: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5803: background-color: $mail_replied_hover;
5804: }
1.938 bisitz 5805: */
1.795 www 5806:
1.938 bisitz 5807: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5808: background-color: $mail_other;
5809: }
1.795 www 5810:
1.938 bisitz 5811: /*
5812: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5813: background-color: $mail_other_hover;
5814: }
1.938 bisitz 5815: */
1.494 raeburn 5816:
1.777 tempelho 5817: table.LC_data_table tr > td.LC_browser_file,
5818: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5819: background: #AAEE77;
1.389 albertel 5820: }
1.795 www 5821:
1.777 tempelho 5822: table.LC_data_table tr > td.LC_browser_file_locked,
5823: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5824: background: #FFAA99;
1.387 albertel 5825: }
1.795 www 5826:
1.777 tempelho 5827: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5828: background: #888888;
1.779 bisitz 5829: }
1.795 www 5830:
1.777 tempelho 5831: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5832: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5833: background: #F8F866;
1.777 tempelho 5834: }
1.795 www 5835:
1.696 bisitz 5836: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5837: background: #E0E8FF;
1.387 albertel 5838: }
1.696 bisitz 5839:
1.707 bisitz 5840: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5841: /* background: #77FF77; */
1.707 bisitz 5842: }
1.795 www 5843:
1.707 bisitz 5844: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5845: border-right: 8px solid #FFFF77;
1.707 bisitz 5846: }
1.795 www 5847:
1.707 bisitz 5848: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5849: border-right: 8px solid #FFAA77;
1.707 bisitz 5850: }
1.795 www 5851:
1.707 bisitz 5852: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5853: border-right: 8px solid #FF7777;
1.707 bisitz 5854: }
1.795 www 5855:
1.707 bisitz 5856: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5857: border-right: 8px solid #AAFF77;
1.707 bisitz 5858: }
1.795 www 5859:
1.707 bisitz 5860: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5861: border-right: 8px solid #11CC55;
1.707 bisitz 5862: }
5863:
1.388 albertel 5864: span.LC_current_location {
1.701 harmsja 5865: font-size:larger;
1.388 albertel 5866: background: $pgbg;
5867: }
1.387 albertel 5868:
1.1029 www 5869: span.LC_current_nav_location {
5870: font-weight:bold;
5871: background: $sidebg;
5872: }
5873:
1.395 albertel 5874: span.LC_parm_menu_item {
5875: font-size: larger;
5876: }
1.795 www 5877:
1.395 albertel 5878: span.LC_parm_scope_all {
5879: color: red;
5880: }
1.795 www 5881:
1.395 albertel 5882: span.LC_parm_scope_folder {
5883: color: green;
5884: }
1.795 www 5885:
1.395 albertel 5886: span.LC_parm_scope_resource {
5887: color: orange;
5888: }
1.795 www 5889:
1.395 albertel 5890: span.LC_parm_part {
5891: color: blue;
5892: }
1.795 www 5893:
1.911 bisitz 5894: span.LC_parm_folder,
5895: span.LC_parm_symb {
1.395 albertel 5896: font-size: x-small;
5897: font-family: $mono;
5898: color: #AAAAAA;
5899: }
5900:
1.977 bisitz 5901: ul.LC_parm_parmlist li {
5902: display: inline-block;
5903: padding: 0.3em 0.8em;
5904: vertical-align: top;
5905: width: 150px;
5906: border-top:1px solid $lg_border_color;
5907: }
5908:
1.795 www 5909: td.LC_parm_overview_level_menu,
5910: td.LC_parm_overview_map_menu,
5911: td.LC_parm_overview_parm_selectors,
5912: td.LC_parm_overview_restrictions {
1.396 albertel 5913: border: 1px solid black;
5914: border-collapse: collapse;
5915: }
1.795 www 5916:
1.396 albertel 5917: table.LC_parm_overview_restrictions td {
5918: border-width: 1px 4px 1px 4px;
5919: border-style: solid;
5920: border-color: $pgbg;
5921: text-align: center;
5922: }
1.795 www 5923:
1.396 albertel 5924: table.LC_parm_overview_restrictions th {
5925: background: $tabbg;
5926: border-width: 1px 4px 1px 4px;
5927: border-style: solid;
5928: border-color: $pgbg;
5929: }
1.795 www 5930:
1.398 albertel 5931: table#LC_helpmenu {
1.803 bisitz 5932: border: none;
1.398 albertel 5933: height: 55px;
1.803 bisitz 5934: border-spacing: 0;
1.398 albertel 5935: }
5936:
5937: table#LC_helpmenu fieldset legend {
5938: font-size: larger;
5939: }
1.795 www 5940:
1.397 albertel 5941: table#LC_helpmenu_links {
5942: width: 100%;
5943: border: 1px solid black;
5944: background: $pgbg;
1.803 bisitz 5945: padding: 0;
1.397 albertel 5946: border-spacing: 1px;
5947: }
1.795 www 5948:
1.397 albertel 5949: table#LC_helpmenu_links tr td {
5950: padding: 1px;
5951: background: $tabbg;
1.399 albertel 5952: text-align: center;
5953: font-weight: bold;
1.397 albertel 5954: }
1.396 albertel 5955:
1.795 www 5956: table#LC_helpmenu_links a:link,
5957: table#LC_helpmenu_links a:visited,
1.397 albertel 5958: table#LC_helpmenu_links a:active {
5959: text-decoration: none;
5960: color: $font;
5961: }
1.795 www 5962:
1.397 albertel 5963: table#LC_helpmenu_links a:hover {
5964: text-decoration: underline;
5965: color: $vlink;
5966: }
1.396 albertel 5967:
1.417 albertel 5968: .LC_chrt_popup_exists {
5969: border: 1px solid #339933;
5970: margin: -1px;
5971: }
1.795 www 5972:
1.417 albertel 5973: .LC_chrt_popup_up {
5974: border: 1px solid yellow;
5975: margin: -1px;
5976: }
1.795 www 5977:
1.417 albertel 5978: .LC_chrt_popup {
5979: border: 1px solid #8888FF;
5980: background: #CCCCFF;
5981: }
1.795 www 5982:
1.421 albertel 5983: table.LC_pick_box {
5984: border-collapse: separate;
5985: background: white;
5986: border: 1px solid black;
5987: border-spacing: 1px;
5988: }
1.795 www 5989:
1.421 albertel 5990: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5991: background: $sidebg;
1.421 albertel 5992: font-weight: bold;
1.900 bisitz 5993: text-align: left;
1.740 bisitz 5994: vertical-align: top;
1.421 albertel 5995: width: 184px;
5996: padding: 8px;
5997: }
1.795 www 5998:
1.579 raeburn 5999: table.LC_pick_box td.LC_pick_box_value {
6000: text-align: left;
6001: padding: 8px;
6002: }
1.795 www 6003:
1.579 raeburn 6004: table.LC_pick_box td.LC_pick_box_select {
6005: text-align: left;
6006: padding: 8px;
6007: }
1.795 www 6008:
1.424 albertel 6009: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6010: padding: 0;
1.421 albertel 6011: height: 1px;
6012: background: black;
6013: }
1.795 www 6014:
1.421 albertel 6015: table.LC_pick_box td.LC_pick_box_submit {
6016: text-align: right;
6017: }
1.795 www 6018:
1.579 raeburn 6019: table.LC_pick_box td.LC_evenrow_value {
6020: text-align: left;
6021: padding: 8px;
6022: background-color: $data_table_light;
6023: }
1.795 www 6024:
1.579 raeburn 6025: table.LC_pick_box td.LC_oddrow_value {
6026: text-align: left;
6027: padding: 8px;
6028: background-color: $data_table_light;
6029: }
1.795 www 6030:
1.579 raeburn 6031: span.LC_helpform_receipt_cat {
6032: font-weight: bold;
6033: }
1.795 www 6034:
1.424 albertel 6035: table.LC_group_priv_box {
6036: background: white;
6037: border: 1px solid black;
6038: border-spacing: 1px;
6039: }
1.795 www 6040:
1.424 albertel 6041: table.LC_group_priv_box td.LC_pick_box_title {
6042: background: $tabbg;
6043: font-weight: bold;
6044: text-align: right;
6045: width: 184px;
6046: }
1.795 www 6047:
1.424 albertel 6048: table.LC_group_priv_box td.LC_groups_fixed {
6049: background: $data_table_light;
6050: text-align: center;
6051: }
1.795 www 6052:
1.424 albertel 6053: table.LC_group_priv_box td.LC_groups_optional {
6054: background: $data_table_dark;
6055: text-align: center;
6056: }
1.795 www 6057:
1.424 albertel 6058: table.LC_group_priv_box td.LC_groups_functionality {
6059: background: $data_table_darker;
6060: text-align: center;
6061: font-weight: bold;
6062: }
1.795 www 6063:
1.424 albertel 6064: table.LC_group_priv td {
6065: text-align: left;
1.803 bisitz 6066: padding: 0;
1.424 albertel 6067: }
6068:
6069: .LC_navbuttons {
6070: margin: 2ex 0ex 2ex 0ex;
6071: }
1.795 www 6072:
1.423 albertel 6073: .LC_topic_bar {
6074: font-weight: bold;
6075: background: $tabbg;
1.918 wenzelju 6076: margin: 1em 0em 1em 2em;
1.805 bisitz 6077: padding: 3px;
1.918 wenzelju 6078: font-size: 1.2em;
1.423 albertel 6079: }
1.795 www 6080:
1.423 albertel 6081: .LC_topic_bar span {
1.918 wenzelju 6082: left: 0.5em;
6083: position: absolute;
1.423 albertel 6084: vertical-align: middle;
1.918 wenzelju 6085: font-size: 1.2em;
1.423 albertel 6086: }
1.795 www 6087:
1.423 albertel 6088: table.LC_course_group_status {
6089: margin: 20px;
6090: }
1.795 www 6091:
1.423 albertel 6092: table.LC_status_selector td {
6093: vertical-align: top;
6094: text-align: center;
1.424 albertel 6095: padding: 4px;
6096: }
1.795 www 6097:
1.599 albertel 6098: div.LC_feedback_link {
1.616 albertel 6099: clear: both;
1.829 kalberla 6100: background: $sidebg;
1.779 bisitz 6101: width: 100%;
1.829 kalberla 6102: padding-bottom: 10px;
6103: border: 1px $tabbg solid;
1.833 kalberla 6104: height: 22px;
6105: line-height: 22px;
6106: padding-top: 5px;
6107: }
6108:
6109: div.LC_feedback_link img {
6110: height: 22px;
1.867 kalberla 6111: vertical-align:middle;
1.829 kalberla 6112: }
6113:
1.911 bisitz 6114: div.LC_feedback_link a {
1.829 kalberla 6115: text-decoration: none;
1.489 raeburn 6116: }
1.795 www 6117:
1.867 kalberla 6118: div.LC_comblock {
1.911 bisitz 6119: display:inline;
1.867 kalberla 6120: color:$font;
6121: font-size:90%;
6122: }
6123:
6124: div.LC_feedback_link div.LC_comblock {
6125: padding-left:5px;
6126: }
6127:
6128: div.LC_feedback_link div.LC_comblock a {
6129: color:$font;
6130: }
6131:
1.489 raeburn 6132: span.LC_feedback_link {
1.858 bisitz 6133: /* background: $feedback_link_bg; */
1.599 albertel 6134: font-size: larger;
6135: }
1.795 www 6136:
1.599 albertel 6137: span.LC_message_link {
1.858 bisitz 6138: /* background: $feedback_link_bg; */
1.599 albertel 6139: font-size: larger;
6140: position: absolute;
6141: right: 1em;
1.489 raeburn 6142: }
1.421 albertel 6143:
1.515 albertel 6144: table.LC_prior_tries {
1.524 albertel 6145: border: 1px solid #000000;
6146: border-collapse: separate;
6147: border-spacing: 1px;
1.515 albertel 6148: }
1.523 albertel 6149:
1.515 albertel 6150: table.LC_prior_tries td {
1.524 albertel 6151: padding: 2px;
1.515 albertel 6152: }
1.523 albertel 6153:
6154: .LC_answer_correct {
1.795 www 6155: background: lightgreen;
6156: color: darkgreen;
6157: padding: 6px;
1.523 albertel 6158: }
1.795 www 6159:
1.523 albertel 6160: .LC_answer_charged_try {
1.797 www 6161: background: #FFAAAA;
1.795 www 6162: color: darkred;
6163: padding: 6px;
1.523 albertel 6164: }
1.795 www 6165:
1.779 bisitz 6166: .LC_answer_not_charged_try,
1.523 albertel 6167: .LC_answer_no_grade,
6168: .LC_answer_late {
1.795 www 6169: background: lightyellow;
1.523 albertel 6170: color: black;
1.795 www 6171: padding: 6px;
1.523 albertel 6172: }
1.795 www 6173:
1.523 albertel 6174: .LC_answer_previous {
1.795 www 6175: background: lightblue;
6176: color: darkblue;
6177: padding: 6px;
1.523 albertel 6178: }
1.795 www 6179:
1.779 bisitz 6180: .LC_answer_no_message {
1.777 tempelho 6181: background: #FFFFFF;
6182: color: black;
1.795 www 6183: padding: 6px;
1.779 bisitz 6184: }
1.795 www 6185:
1.779 bisitz 6186: .LC_answer_unknown {
6187: background: orange;
6188: color: black;
1.795 www 6189: padding: 6px;
1.777 tempelho 6190: }
1.795 www 6191:
1.529 albertel 6192: span.LC_prior_numerical,
6193: span.LC_prior_string,
6194: span.LC_prior_custom,
6195: span.LC_prior_reaction,
6196: span.LC_prior_math {
1.925 bisitz 6197: font-family: $mono;
1.523 albertel 6198: white-space: pre;
6199: }
6200:
1.525 albertel 6201: span.LC_prior_string {
1.925 bisitz 6202: font-family: $mono;
1.525 albertel 6203: white-space: pre;
6204: }
6205:
1.523 albertel 6206: table.LC_prior_option {
6207: width: 100%;
6208: border-collapse: collapse;
6209: }
1.795 www 6210:
1.911 bisitz 6211: table.LC_prior_rank,
1.795 www 6212: table.LC_prior_match {
1.528 albertel 6213: border-collapse: collapse;
6214: }
1.795 www 6215:
1.528 albertel 6216: table.LC_prior_option tr td,
6217: table.LC_prior_rank tr td,
6218: table.LC_prior_match tr td {
1.524 albertel 6219: border: 1px solid #000000;
1.515 albertel 6220: }
6221:
1.855 bisitz 6222: .LC_nobreak {
1.544 albertel 6223: white-space: nowrap;
1.519 raeburn 6224: }
6225:
1.576 raeburn 6226: span.LC_cusr_emph {
6227: font-style: italic;
6228: }
6229:
1.633 raeburn 6230: span.LC_cusr_subheading {
6231: font-weight: normal;
6232: font-size: 85%;
6233: }
6234:
1.861 bisitz 6235: div.LC_docs_entry_move {
1.859 bisitz 6236: border: 1px solid #BBBBBB;
1.545 albertel 6237: background: #DDDDDD;
1.861 bisitz 6238: width: 22px;
1.859 bisitz 6239: padding: 1px;
6240: margin: 0;
1.545 albertel 6241: }
6242:
1.861 bisitz 6243: table.LC_data_table tr > td.LC_docs_entry_commands,
6244: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6245: background: #DDDDDD;
6246: font-size: x-small;
6247: }
1.795 www 6248:
1.861 bisitz 6249: .LC_docs_entry_parameter {
6250: white-space: nowrap;
6251: }
6252:
1.544 albertel 6253: .LC_docs_copy {
1.545 albertel 6254: color: #000099;
1.544 albertel 6255: }
1.795 www 6256:
1.544 albertel 6257: .LC_docs_cut {
1.545 albertel 6258: color: #550044;
1.544 albertel 6259: }
1.795 www 6260:
1.544 albertel 6261: .LC_docs_rename {
1.545 albertel 6262: color: #009900;
1.544 albertel 6263: }
1.795 www 6264:
1.544 albertel 6265: .LC_docs_remove {
1.545 albertel 6266: color: #990000;
6267: }
6268:
1.547 albertel 6269: .LC_docs_reinit_warn,
6270: .LC_docs_ext_edit {
6271: font-size: x-small;
6272: }
6273:
1.545 albertel 6274: table.LC_docs_adddocs td,
6275: table.LC_docs_adddocs th {
6276: border: 1px solid #BBBBBB;
6277: padding: 4px;
6278: background: #DDDDDD;
1.543 albertel 6279: }
6280:
1.584 albertel 6281: table.LC_sty_begin {
6282: background: #BBFFBB;
6283: }
1.795 www 6284:
1.584 albertel 6285: table.LC_sty_end {
6286: background: #FFBBBB;
6287: }
6288:
1.589 raeburn 6289: table.LC_double_column {
1.803 bisitz 6290: border-width: 0;
1.589 raeburn 6291: border-collapse: collapse;
6292: width: 100%;
6293: padding: 2px;
6294: }
6295:
6296: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6297: top: 2px;
1.589 raeburn 6298: left: 2px;
6299: width: 47%;
6300: vertical-align: top;
6301: }
6302:
6303: table.LC_double_column tr td.LC_right_col {
6304: top: 2px;
1.779 bisitz 6305: right: 2px;
1.589 raeburn 6306: width: 47%;
6307: vertical-align: top;
6308: }
6309:
1.591 raeburn 6310: div.LC_left_float {
6311: float: left;
6312: padding-right: 5%;
1.597 albertel 6313: padding-bottom: 4px;
1.591 raeburn 6314: }
6315:
6316: div.LC_clear_float_header {
1.597 albertel 6317: padding-bottom: 2px;
1.591 raeburn 6318: }
6319:
6320: div.LC_clear_float_footer {
1.597 albertel 6321: padding-top: 10px;
1.591 raeburn 6322: clear: both;
6323: }
6324:
1.597 albertel 6325: div.LC_grade_show_user {
1.941 bisitz 6326: /* border-left: 5px solid $sidebg; */
6327: border-top: 5px solid #000000;
6328: margin: 50px 0 0 0;
1.936 bisitz 6329: padding: 15px 0 5px 10px;
1.597 albertel 6330: }
1.795 www 6331:
1.936 bisitz 6332: div.LC_grade_show_user_odd_row {
1.941 bisitz 6333: /* border-left: 5px solid #000000; */
6334: }
6335:
6336: div.LC_grade_show_user div.LC_Box {
6337: margin-right: 50px;
1.597 albertel 6338: }
6339:
6340: div.LC_grade_submissions,
6341: div.LC_grade_message_center,
1.936 bisitz 6342: div.LC_grade_info_links {
1.597 albertel 6343: margin: 5px;
6344: width: 99%;
6345: background: #FFFFFF;
6346: }
1.795 www 6347:
1.597 albertel 6348: div.LC_grade_submissions_header,
1.936 bisitz 6349: div.LC_grade_message_center_header {
1.705 tempelho 6350: font-weight: bold;
6351: font-size: large;
1.597 albertel 6352: }
1.795 www 6353:
1.597 albertel 6354: div.LC_grade_submissions_body,
1.936 bisitz 6355: div.LC_grade_message_center_body {
1.597 albertel 6356: border: 1px solid black;
6357: width: 99%;
6358: background: #FFFFFF;
6359: }
1.795 www 6360:
1.613 albertel 6361: table.LC_scantron_action {
6362: width: 100%;
6363: }
1.795 www 6364:
1.613 albertel 6365: table.LC_scantron_action tr th {
1.698 harmsja 6366: font-weight:bold;
6367: font-style:normal;
1.613 albertel 6368: }
1.795 www 6369:
1.779 bisitz 6370: .LC_edit_problem_header,
1.614 albertel 6371: div.LC_edit_problem_footer {
1.705 tempelho 6372: font-weight: normal;
6373: font-size: medium;
1.602 albertel 6374: margin: 2px;
1.1060 bisitz 6375: background-color: $sidebg;
1.600 albertel 6376: }
1.795 www 6377:
1.600 albertel 6378: div.LC_edit_problem_header,
1.602 albertel 6379: div.LC_edit_problem_header div,
1.614 albertel 6380: div.LC_edit_problem_footer,
6381: div.LC_edit_problem_footer div,
1.602 albertel 6382: div.LC_edit_problem_editxml_header,
6383: div.LC_edit_problem_editxml_header div {
1.600 albertel 6384: margin-top: 5px;
6385: }
1.795 www 6386:
1.600 albertel 6387: div.LC_edit_problem_header_title {
1.705 tempelho 6388: font-weight: bold;
6389: font-size: larger;
1.602 albertel 6390: background: $tabbg;
6391: padding: 3px;
1.1060 bisitz 6392: margin: 0 0 5px 0;
1.602 albertel 6393: }
1.795 www 6394:
1.602 albertel 6395: table.LC_edit_problem_header_title {
6396: width: 100%;
1.600 albertel 6397: background: $tabbg;
1.602 albertel 6398: }
6399:
6400: div.LC_edit_problem_discards {
6401: float: left;
6402: padding-bottom: 5px;
6403: }
1.795 www 6404:
1.602 albertel 6405: div.LC_edit_problem_saves {
6406: float: right;
6407: padding-bottom: 5px;
1.600 albertel 6408: }
1.795 www 6409:
1.911 bisitz 6410: img.stift {
1.803 bisitz 6411: border-width: 0;
6412: vertical-align: middle;
1.677 riegler 6413: }
1.680 riegler 6414:
1.923 bisitz 6415: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6416: vertical-align: top;
1.777 tempelho 6417: }
1.795 www 6418:
1.716 raeburn 6419: div.LC_createcourse {
1.911 bisitz 6420: margin: 10px 10px 10px 10px;
1.716 raeburn 6421: }
6422:
1.917 raeburn 6423: .LC_dccid {
6424: margin: 0.2em 0 0 0;
6425: padding: 0;
6426: font-size: 90%;
6427: display:none;
6428: }
6429:
1.897 wenzelju 6430: ol.LC_primary_menu a:hover,
1.721 harmsja 6431: ol#LC_MenuBreadcrumbs a:hover,
6432: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6433: ul#LC_secondary_menu a:hover,
1.721 harmsja 6434: .LC_FormSectionClearButton input:hover
1.795 www 6435: ul.LC_TabContent li:hover a {
1.952 onken 6436: color:$button_hover;
1.911 bisitz 6437: text-decoration:none;
1.693 droeschl 6438: }
6439:
1.779 bisitz 6440: h1 {
1.911 bisitz 6441: padding: 0;
6442: line-height:130%;
1.693 droeschl 6443: }
1.698 harmsja 6444:
1.911 bisitz 6445: h2,
6446: h3,
6447: h4,
6448: h5,
6449: h6 {
6450: margin: 5px 0 5px 0;
6451: padding: 0;
6452: line-height:130%;
1.693 droeschl 6453: }
1.795 www 6454:
6455: .LC_hcell {
1.911 bisitz 6456: padding:3px 15px 3px 15px;
6457: margin: 0;
6458: background-color:$tabbg;
6459: color:$fontmenu;
6460: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6461: }
1.795 www 6462:
1.840 bisitz 6463: .LC_Box > .LC_hcell {
1.911 bisitz 6464: margin: 0 -10px 10px -10px;
1.835 bisitz 6465: }
6466:
1.721 harmsja 6467: .LC_noBorder {
1.911 bisitz 6468: border: 0;
1.698 harmsja 6469: }
1.693 droeschl 6470:
1.721 harmsja 6471: .LC_FormSectionClearButton input {
1.911 bisitz 6472: background-color:transparent;
6473: border: none;
6474: cursor:pointer;
6475: text-decoration:underline;
1.693 droeschl 6476: }
1.763 bisitz 6477:
6478: .LC_help_open_topic {
1.911 bisitz 6479: color: #FFFFFF;
6480: background-color: #EEEEFF;
6481: margin: 1px;
6482: padding: 4px;
6483: border: 1px solid #000033;
6484: white-space: nowrap;
6485: /* vertical-align: middle; */
1.759 neumanie 6486: }
1.693 droeschl 6487:
1.911 bisitz 6488: dl,
6489: ul,
6490: div,
6491: fieldset {
6492: margin: 10px 10px 10px 0;
6493: /* overflow: hidden; */
1.693 droeschl 6494: }
1.795 www 6495:
1.838 bisitz 6496: fieldset > legend {
1.911 bisitz 6497: font-weight: bold;
6498: padding: 0 5px 0 5px;
1.838 bisitz 6499: }
6500:
1.813 bisitz 6501: #LC_nav_bar {
1.911 bisitz 6502: float: left;
1.995 raeburn 6503: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6504: margin: 0 0 2px 0;
1.807 droeschl 6505: }
6506:
1.916 droeschl 6507: #LC_realm {
6508: margin: 0.2em 0 0 0;
6509: padding: 0;
6510: font-weight: bold;
6511: text-align: center;
1.995 raeburn 6512: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6513: }
6514:
1.911 bisitz 6515: #LC_nav_bar em {
6516: font-weight: bold;
6517: font-style: normal;
1.807 droeschl 6518: }
6519:
1.897 wenzelju 6520: ol.LC_primary_menu {
1.911 bisitz 6521: float: right;
1.934 droeschl 6522: margin: 0;
1.1075.2.2 raeburn 6523: padding: 0;
1.995 raeburn 6524: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6525: }
6526:
1.852 droeschl 6527: ol#LC_PathBreadcrumbs {
1.911 bisitz 6528: margin: 0;
1.693 droeschl 6529: }
6530:
1.897 wenzelju 6531: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6532: color: RGB(80, 80, 80);
6533: vertical-align: middle;
6534: text-align: left;
6535: list-style: none;
6536: float: left;
6537: }
6538:
6539: ol.LC_primary_menu li a {
6540: display: block;
6541: margin: 0;
6542: padding: 0 5px 0 10px;
6543: text-decoration: none;
6544: }
6545:
6546: ol.LC_primary_menu li ul {
6547: display: none;
6548: width: 10em;
6549: background-color: $data_table_light;
6550: }
6551:
6552: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6553: display: block;
6554: position: absolute;
6555: margin: 0;
6556: padding: 0;
1.1075.2.5 raeburn 6557: z-index: 2;
1.1075.2.2 raeburn 6558: }
6559:
6560: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6561: font-size: 90%;
1.911 bisitz 6562: vertical-align: top;
1.1075.2.2 raeburn 6563: float: none;
1.1075.2.5 raeburn 6564: border-left: 1px solid black;
6565: border-right: 1px solid black;
1.1075.2.2 raeburn 6566: }
6567:
6568: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6569: background-color:$data_table_light;
1.1075.2.2 raeburn 6570: }
6571:
6572: ol.LC_primary_menu li li a:hover {
6573: color:$button_hover;
6574: background-color:$data_table_dark;
1.693 droeschl 6575: }
6576:
1.897 wenzelju 6577: ol.LC_primary_menu li img {
1.911 bisitz 6578: vertical-align: bottom;
1.934 droeschl 6579: height: 1.1em;
1.1075.2.3 raeburn 6580: margin: 0.2em 0 0 0;
1.693 droeschl 6581: }
6582:
1.897 wenzelju 6583: ol.LC_primary_menu a {
1.911 bisitz 6584: color: RGB(80, 80, 80);
6585: text-decoration: none;
1.693 droeschl 6586: }
1.795 www 6587:
1.949 droeschl 6588: ol.LC_primary_menu a.LC_new_message {
6589: font-weight:bold;
6590: color: darkred;
6591: }
6592:
1.975 raeburn 6593: ol.LC_docs_parameters {
6594: margin-left: 0;
6595: padding: 0;
6596: list-style: none;
6597: }
6598:
6599: ol.LC_docs_parameters li {
6600: margin: 0;
6601: padding-right: 20px;
6602: display: inline;
6603: }
6604:
1.976 raeburn 6605: ol.LC_docs_parameters li:before {
6606: content: "\\002022 \\0020";
6607: }
6608:
6609: li.LC_docs_parameters_title {
6610: font-weight: bold;
6611: }
6612:
6613: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6614: content: "";
6615: }
6616:
1.897 wenzelju 6617: ul#LC_secondary_menu {
1.911 bisitz 6618: clear: both;
6619: color: $fontmenu;
6620: background: $tabbg;
6621: list-style: none;
6622: padding: 0;
6623: margin: 0;
6624: width: 100%;
1.995 raeburn 6625: text-align: left;
1.1075.2.4 raeburn 6626: float: left;
1.808 droeschl 6627: }
6628:
1.897 wenzelju 6629: ul#LC_secondary_menu li {
1.911 bisitz 6630: font-weight: bold;
6631: line-height: 1.8em;
6632: border-right: 1px solid black;
6633: vertical-align: middle;
1.1075.2.4 raeburn 6634: float: left;
6635: }
6636:
6637: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6638: background-color: $data_table_light;
6639: }
6640:
6641: ul#LC_secondary_menu li a {
6642: padding: 0 0.8em;
6643: }
6644:
6645: ul#LC_secondary_menu li ul {
6646: display: none;
6647: }
6648:
6649: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6650: display: block;
6651: position: absolute;
6652: margin: 0;
6653: padding: 0;
6654: list-style:none;
6655: float: none;
6656: background-color: $data_table_light;
1.1075.2.5 raeburn 6657: z-index: 2;
1.1075.2.10 raeburn 6658: margin-left: -1px;
1.1075.2.4 raeburn 6659: }
6660:
6661: ul#LC_secondary_menu li ul li {
6662: font-size: 90%;
6663: vertical-align: top;
6664: border-left: 1px solid black;
6665: border-right: 1px solid black;
6666: background-color: $data_table_light
6667: list-style:none;
6668: float: none;
6669: }
6670:
6671: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6672: background-color: $data_table_dark;
1.807 droeschl 6673: }
6674:
1.847 tempelho 6675: ul.LC_TabContent {
1.911 bisitz 6676: display:block;
6677: background: $sidebg;
6678: border-bottom: solid 1px $lg_border_color;
6679: list-style:none;
1.1020 raeburn 6680: margin: -1px -10px 0 -10px;
1.911 bisitz 6681: padding: 0;
1.693 droeschl 6682: }
6683:
1.795 www 6684: ul.LC_TabContent li,
6685: ul.LC_TabContentBigger li {
1.911 bisitz 6686: float:left;
1.741 harmsja 6687: }
1.795 www 6688:
1.897 wenzelju 6689: ul#LC_secondary_menu li a {
1.911 bisitz 6690: color: $fontmenu;
6691: text-decoration: none;
1.693 droeschl 6692: }
1.795 www 6693:
1.721 harmsja 6694: ul.LC_TabContent {
1.952 onken 6695: min-height:20px;
1.721 harmsja 6696: }
1.795 www 6697:
6698: ul.LC_TabContent li {
1.911 bisitz 6699: vertical-align:middle;
1.959 onken 6700: padding: 0 16px 0 10px;
1.911 bisitz 6701: background-color:$tabbg;
6702: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6703: border-left: solid 1px $font;
1.721 harmsja 6704: }
1.795 www 6705:
1.847 tempelho 6706: ul.LC_TabContent .right {
1.911 bisitz 6707: float:right;
1.847 tempelho 6708: }
6709:
1.911 bisitz 6710: ul.LC_TabContent li a,
6711: ul.LC_TabContent li {
6712: color:rgb(47,47,47);
6713: text-decoration:none;
6714: font-size:95%;
6715: font-weight:bold;
1.952 onken 6716: min-height:20px;
6717: }
6718:
1.959 onken 6719: ul.LC_TabContent li a:hover,
6720: ul.LC_TabContent li a:focus {
1.952 onken 6721: color: $button_hover;
1.959 onken 6722: background:none;
6723: outline:none;
1.952 onken 6724: }
6725:
6726: ul.LC_TabContent li:hover {
6727: color: $button_hover;
6728: cursor:pointer;
1.721 harmsja 6729: }
1.795 www 6730:
1.911 bisitz 6731: ul.LC_TabContent li.active {
1.952 onken 6732: color: $font;
1.911 bisitz 6733: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6734: border-bottom:solid 1px #FFFFFF;
6735: cursor: default;
1.744 ehlerst 6736: }
1.795 www 6737:
1.959 onken 6738: ul.LC_TabContent li.active a {
6739: color:$font;
6740: background:#FFFFFF;
6741: outline: none;
6742: }
1.1047 raeburn 6743:
6744: ul.LC_TabContent li.goback {
6745: float: left;
6746: border-left: none;
6747: }
6748:
1.870 tempelho 6749: #maincoursedoc {
1.911 bisitz 6750: clear:both;
1.870 tempelho 6751: }
6752:
6753: ul.LC_TabContentBigger {
1.911 bisitz 6754: display:block;
6755: list-style:none;
6756: padding: 0;
1.870 tempelho 6757: }
6758:
1.795 www 6759: ul.LC_TabContentBigger li {
1.911 bisitz 6760: vertical-align:bottom;
6761: height: 30px;
6762: font-size:110%;
6763: font-weight:bold;
6764: color: #737373;
1.841 tempelho 6765: }
6766:
1.957 onken 6767: ul.LC_TabContentBigger li.active {
6768: position: relative;
6769: top: 1px;
6770: }
6771:
1.870 tempelho 6772: ul.LC_TabContentBigger li a {
1.911 bisitz 6773: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6774: height: 30px;
6775: line-height: 30px;
6776: text-align: center;
6777: display: block;
6778: text-decoration: none;
1.958 onken 6779: outline: none;
1.741 harmsja 6780: }
1.795 www 6781:
1.870 tempelho 6782: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6783: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6784: color:$font;
1.744 ehlerst 6785: }
1.795 www 6786:
1.870 tempelho 6787: ul.LC_TabContentBigger li b {
1.911 bisitz 6788: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6789: display: block;
6790: float: left;
6791: padding: 0 30px;
1.957 onken 6792: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6793: }
6794:
1.956 onken 6795: ul.LC_TabContentBigger li:hover b {
6796: color:$button_hover;
6797: }
6798:
1.870 tempelho 6799: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6800: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6801: color:$font;
1.957 onken 6802: border: 0;
1.741 harmsja 6803: }
1.693 droeschl 6804:
1.870 tempelho 6805:
1.862 bisitz 6806: ul.LC_CourseBreadcrumbs {
6807: background: $sidebg;
1.1020 raeburn 6808: height: 2em;
1.862 bisitz 6809: padding-left: 10px;
1.1020 raeburn 6810: margin: 0;
1.862 bisitz 6811: list-style-position: inside;
6812: }
6813:
1.911 bisitz 6814: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6815: ol#LC_PathBreadcrumbs {
1.911 bisitz 6816: padding-left: 10px;
6817: margin: 0;
1.933 droeschl 6818: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6819: }
6820:
1.911 bisitz 6821: ol#LC_MenuBreadcrumbs li,
6822: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6823: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6824: display: inline;
1.933 droeschl 6825: white-space: normal;
1.693 droeschl 6826: }
6827:
1.823 bisitz 6828: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6829: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6830: text-decoration: none;
6831: font-size:90%;
1.693 droeschl 6832: }
1.795 www 6833:
1.969 droeschl 6834: ol#LC_MenuBreadcrumbs h1 {
6835: display: inline;
6836: font-size: 90%;
6837: line-height: 2.5em;
6838: margin: 0;
6839: padding: 0;
6840: }
6841:
1.795 www 6842: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6843: text-decoration:none;
6844: font-size:100%;
6845: font-weight:bold;
1.693 droeschl 6846: }
1.795 www 6847:
1.840 bisitz 6848: .LC_Box {
1.911 bisitz 6849: border: solid 1px $lg_border_color;
6850: padding: 0 10px 10px 10px;
1.746 neumanie 6851: }
1.795 www 6852:
1.1020 raeburn 6853: .LC_DocsBox {
6854: border: solid 1px $lg_border_color;
6855: padding: 0 0 10px 10px;
6856: }
6857:
1.795 www 6858: .LC_AboutMe_Image {
1.911 bisitz 6859: float:left;
6860: margin-right:10px;
1.747 neumanie 6861: }
1.795 www 6862:
6863: .LC_Clear_AboutMe_Image {
1.911 bisitz 6864: clear:left;
1.747 neumanie 6865: }
1.795 www 6866:
1.721 harmsja 6867: dl.LC_ListStyleClean dt {
1.911 bisitz 6868: padding-right: 5px;
6869: display: table-header-group;
1.693 droeschl 6870: }
6871:
1.721 harmsja 6872: dl.LC_ListStyleClean dd {
1.911 bisitz 6873: display: table-row;
1.693 droeschl 6874: }
6875:
1.721 harmsja 6876: .LC_ListStyleClean,
6877: .LC_ListStyleSimple,
6878: .LC_ListStyleNormal,
1.795 www 6879: .LC_ListStyleSpecial {
1.911 bisitz 6880: /* display:block; */
6881: list-style-position: inside;
6882: list-style-type: none;
6883: overflow: hidden;
6884: padding: 0;
1.693 droeschl 6885: }
6886:
1.721 harmsja 6887: .LC_ListStyleSimple li,
6888: .LC_ListStyleSimple dd,
6889: .LC_ListStyleNormal li,
6890: .LC_ListStyleNormal dd,
6891: .LC_ListStyleSpecial li,
1.795 www 6892: .LC_ListStyleSpecial dd {
1.911 bisitz 6893: margin: 0;
6894: padding: 5px 5px 5px 10px;
6895: clear: both;
1.693 droeschl 6896: }
6897:
1.721 harmsja 6898: .LC_ListStyleClean li,
6899: .LC_ListStyleClean dd {
1.911 bisitz 6900: padding-top: 0;
6901: padding-bottom: 0;
1.693 droeschl 6902: }
6903:
1.721 harmsja 6904: .LC_ListStyleSimple dd,
1.795 www 6905: .LC_ListStyleSimple li {
1.911 bisitz 6906: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6907: }
6908:
1.721 harmsja 6909: .LC_ListStyleSpecial li,
6910: .LC_ListStyleSpecial dd {
1.911 bisitz 6911: list-style-type: none;
6912: background-color: RGB(220, 220, 220);
6913: margin-bottom: 4px;
1.693 droeschl 6914: }
6915:
1.721 harmsja 6916: table.LC_SimpleTable {
1.911 bisitz 6917: margin:5px;
6918: border:solid 1px $lg_border_color;
1.795 www 6919: }
1.693 droeschl 6920:
1.721 harmsja 6921: table.LC_SimpleTable tr {
1.911 bisitz 6922: padding: 0;
6923: border:solid 1px $lg_border_color;
1.693 droeschl 6924: }
1.795 www 6925:
6926: table.LC_SimpleTable thead {
1.911 bisitz 6927: background:rgb(220,220,220);
1.693 droeschl 6928: }
6929:
1.721 harmsja 6930: div.LC_columnSection {
1.911 bisitz 6931: display: block;
6932: clear: both;
6933: overflow: hidden;
6934: margin: 0;
1.693 droeschl 6935: }
6936:
1.721 harmsja 6937: div.LC_columnSection>* {
1.911 bisitz 6938: float: left;
6939: margin: 10px 20px 10px 0;
6940: overflow:hidden;
1.693 droeschl 6941: }
1.721 harmsja 6942:
1.795 www 6943: table em {
1.911 bisitz 6944: font-weight: bold;
6945: font-style: normal;
1.748 schulted 6946: }
1.795 www 6947:
1.779 bisitz 6948: table.LC_tableBrowseRes,
1.795 www 6949: table.LC_tableOfContent {
1.911 bisitz 6950: border:none;
6951: border-spacing: 1px;
6952: padding: 3px;
6953: background-color: #FFFFFF;
6954: font-size: 90%;
1.753 droeschl 6955: }
1.789 droeschl 6956:
1.911 bisitz 6957: table.LC_tableOfContent {
6958: border-collapse: collapse;
1.789 droeschl 6959: }
6960:
1.771 droeschl 6961: table.LC_tableBrowseRes a,
1.768 schulted 6962: table.LC_tableOfContent a {
1.911 bisitz 6963: background-color: transparent;
6964: text-decoration: none;
1.753 droeschl 6965: }
6966:
1.795 www 6967: table.LC_tableOfContent img {
1.911 bisitz 6968: border: none;
6969: height: 1.3em;
6970: vertical-align: text-bottom;
6971: margin-right: 0.3em;
1.753 droeschl 6972: }
1.757 schulted 6973:
1.795 www 6974: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6975: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6976: }
6977:
1.795 www 6978: a#LC_content_toolbar_everything {
1.911 bisitz 6979: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6980: }
6981:
1.795 www 6982: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6983: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6984: }
6985:
1.795 www 6986: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6987: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6988: }
6989:
1.795 www 6990: a#LC_content_toolbar_changefolder {
1.911 bisitz 6991: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6992: }
6993:
1.795 www 6994: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6995: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6996: }
6997:
1.1043 raeburn 6998: a#LC_content_toolbar_edittoplevel {
6999: background-image:url(/res/adm/pages/edittoplevel.gif);
7000: }
7001:
1.795 www 7002: ul#LC_toolbar li a:hover {
1.911 bisitz 7003: background-position: bottom center;
1.757 schulted 7004: }
7005:
1.795 www 7006: ul#LC_toolbar {
1.911 bisitz 7007: padding: 0;
7008: margin: 2px;
7009: list-style:none;
7010: position:relative;
7011: background-color:white;
1.1075.2.9 raeburn 7012: overflow: auto;
1.757 schulted 7013: }
7014:
1.795 www 7015: ul#LC_toolbar li {
1.911 bisitz 7016: border:1px solid white;
7017: padding: 0;
7018: margin: 0;
7019: float: left;
7020: display:inline;
7021: vertical-align:middle;
1.1075.2.9 raeburn 7022: white-space: nowrap;
1.911 bisitz 7023: }
1.757 schulted 7024:
1.783 amueller 7025:
1.795 www 7026: a.LC_toolbarItem {
1.911 bisitz 7027: display:block;
7028: padding: 0;
7029: margin: 0;
7030: height: 32px;
7031: width: 32px;
7032: color:white;
7033: border: none;
7034: background-repeat:no-repeat;
7035: background-color:transparent;
1.757 schulted 7036: }
7037:
1.915 droeschl 7038: ul.LC_funclist {
7039: margin: 0;
7040: padding: 0.5em 1em 0.5em 0;
7041: }
7042:
1.933 droeschl 7043: ul.LC_funclist > li:first-child {
7044: font-weight:bold;
7045: margin-left:0.8em;
7046: }
7047:
1.915 droeschl 7048: ul.LC_funclist + ul.LC_funclist {
7049: /*
7050: left border as a seperator if we have more than
7051: one list
7052: */
7053: border-left: 1px solid $sidebg;
7054: /*
7055: this hides the left border behind the border of the
7056: outer box if element is wrapped to the next 'line'
7057: */
7058: margin-left: -1px;
7059: }
7060:
1.843 bisitz 7061: ul.LC_funclist li {
1.915 droeschl 7062: display: inline;
1.782 bisitz 7063: white-space: nowrap;
1.915 droeschl 7064: margin: 0 0 0 25px;
7065: line-height: 150%;
1.782 bisitz 7066: }
7067:
1.974 wenzelju 7068: .LC_hidden {
7069: display: none;
7070: }
7071:
1.1030 www 7072: .LCmodal-overlay {
7073: position:fixed;
7074: top:0;
7075: right:0;
7076: bottom:0;
7077: left:0;
7078: height:100%;
7079: width:100%;
7080: margin:0;
7081: padding:0;
7082: background:#999;
7083: opacity:.75;
7084: filter: alpha(opacity=75);
7085: -moz-opacity: 0.75;
7086: z-index:101;
7087: }
7088:
7089: * html .LCmodal-overlay {
7090: position: absolute;
7091: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7092: }
7093:
7094: .LCmodal-window {
7095: position:fixed;
7096: top:50%;
7097: left:50%;
7098: margin:0;
7099: padding:0;
7100: z-index:102;
7101: }
7102:
7103: * html .LCmodal-window {
7104: position:absolute;
7105: }
7106:
7107: .LCclose-window {
7108: position:absolute;
7109: width:32px;
7110: height:32px;
7111: right:8px;
7112: top:8px;
7113: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7114: text-indent:-99999px;
7115: overflow:hidden;
7116: cursor:pointer;
7117: }
7118:
1.343 albertel 7119: END
7120: }
7121:
1.306 albertel 7122: =pod
7123:
7124: =item * &headtag()
7125:
7126: Returns a uniform footer for LON-CAPA web pages.
7127:
1.307 albertel 7128: Inputs: $title - optional title for the head
7129: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7130: $args - optional arguments
1.319 albertel 7131: force_register - if is true call registerurl so the remote is
7132: informed
1.415 albertel 7133: redirect -> array ref of
7134: 1- seconds before redirect occurs
7135: 2- url to redirect to
7136: 3- whether the side effect should occur
1.315 albertel 7137: (side effect of setting
7138: $env{'internal.head.redirect'} to the url
7139: redirected too)
1.352 albertel 7140: domain -> force to color decorate a page for a specific
7141: domain
7142: function -> force usage of a specific rolish color scheme
7143: bgcolor -> override the default page bgcolor
1.460 albertel 7144: no_auto_mt_title
7145: -> prevent &mt()ing the title arg
1.464 albertel 7146:
1.306 albertel 7147: =cut
7148:
7149: sub headtag {
1.313 albertel 7150: my ($title,$head_extra,$args) = @_;
1.306 albertel 7151:
1.363 albertel 7152: my $function = $args->{'function'} || &get_users_function();
7153: my $domain = $args->{'domain'} || &determinedomain();
7154: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7155: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7156: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7157: #time(),
1.418 albertel 7158: $env{'environment.color.timestamp'},
1.363 albertel 7159: $function,$domain,$bgcolor);
7160:
1.369 www 7161: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7162:
1.308 albertel 7163: my $result =
7164: '<head>'.
1.461 albertel 7165: &font_settings();
1.319 albertel 7166:
1.1064 raeburn 7167: my $inhibitprint = &print_suppression();
7168:
1.461 albertel 7169: if (!$args->{'frameset'}) {
7170: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7171: }
1.1075.2.12 raeburn 7172: if ($args->{'force_register'}) {
7173: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7174: }
1.436 albertel 7175: if (!$args->{'no_nav_bar'}
7176: && !$args->{'only_body'}
7177: && !$args->{'frameset'}) {
7178: $result .= &help_menu_js();
1.1032 www 7179: $result.=&modal_window();
1.1038 www 7180: $result.=&togglebox_script();
1.1034 www 7181: $result.=&wishlist_window();
1.1041 www 7182: $result.=&LCprogressbarUpdate_script();
1.1034 www 7183: } else {
7184: if ($args->{'add_modal'}) {
7185: $result.=&modal_window();
7186: }
7187: if ($args->{'add_wishlist'}) {
7188: $result.=&wishlist_window();
7189: }
1.1038 www 7190: if ($args->{'add_togglebox'}) {
7191: $result.=&togglebox_script();
7192: }
1.1041 www 7193: if ($args->{'add_progressbar'}) {
7194: $result.=&LCprogressbarUpdate_script();
7195: }
1.436 albertel 7196: }
1.314 albertel 7197: if (ref($args->{'redirect'})) {
1.414 albertel 7198: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7199: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7200: if (!$inhibit_continue) {
7201: $env{'internal.head.redirect'} = $url;
7202: }
1.313 albertel 7203: $result.=<<ADDMETA
7204: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7205: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7206: ADDMETA
7207: }
1.306 albertel 7208: if (!defined($title)) {
7209: $title = 'The LearningOnline Network with CAPA';
7210: }
1.460 albertel 7211: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7212: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7213: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7214: .$inhibitprint
1.414 albertel 7215: .$head_extra;
1.962 droeschl 7216: return $result.'</head>';
1.306 albertel 7217: }
7218:
7219: =pod
7220:
1.340 albertel 7221: =item * &font_settings()
7222:
7223: Returns neccessary <meta> to set the proper encoding
7224:
7225: Inputs: none
7226:
7227: =cut
7228:
7229: sub font_settings {
7230: my $headerstring='';
1.647 www 7231: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7232: $headerstring.=
7233: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7234: }
7235: return $headerstring;
7236: }
7237:
1.341 albertel 7238: =pod
7239:
1.1064 raeburn 7240: =item * &print_suppression()
7241:
7242: In course context returns css which causes the body to be blank when media="print",
7243: if printout generation is unavailable for the current resource.
7244:
7245: This could be because:
7246:
7247: (a) printstartdate is in the future
7248:
7249: (b) printenddate is in the past
7250:
7251: (c) there is an active exam block with "printout"
7252: functionality blocked
7253:
7254: Users with pav, pfo or evb privileges are exempt.
7255:
7256: Inputs: none
7257:
7258: =cut
7259:
7260:
7261: sub print_suppression {
7262: my $noprint;
7263: if ($env{'request.course.id'}) {
7264: my $scope = $env{'request.course.id'};
7265: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7266: (&Apache::lonnet::allowed('pfo',$scope))) {
7267: return;
7268: }
7269: if ($env{'request.course.sec'} ne '') {
7270: $scope .= "/$env{'request.course.sec'}";
7271: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7272: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7273: return;
1.1064 raeburn 7274: }
7275: }
7276: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7277: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7278: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7279: if ($blocked) {
7280: my $checkrole = "cm./$cdom/$cnum";
7281: if ($env{'request.course.sec'} ne '') {
7282: $checkrole .= "/$env{'request.course.sec'}";
7283: }
7284: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7285: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7286: $noprint = 1;
7287: }
7288: }
7289: unless ($noprint) {
7290: my $symb = &Apache::lonnet::symbread();
7291: if ($symb ne '') {
7292: my $navmap = Apache::lonnavmaps::navmap->new();
7293: if (ref($navmap)) {
7294: my $res = $navmap->getBySymb($symb);
7295: if (ref($res)) {
7296: if (!$res->resprintable()) {
7297: $noprint = 1;
7298: }
7299: }
7300: }
7301: }
7302: }
7303: if ($noprint) {
7304: return <<"ENDSTYLE";
7305: <style type="text/css" media="print">
7306: body { display:none }
7307: </style>
7308: ENDSTYLE
7309: }
7310: }
7311: return;
7312: }
7313:
7314: =pod
7315:
1.341 albertel 7316: =item * &xml_begin()
7317:
7318: Returns the needed doctype and <html>
7319:
7320: Inputs: none
7321:
7322: =cut
7323:
7324: sub xml_begin {
7325: my $output='';
7326:
7327: if ($env{'browser.mathml'}) {
7328: $output='<?xml version="1.0"?>'
7329: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7330: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7331:
7332: # .'<!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">] >'
7333: .'<!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">'
7334: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7335: .'xmlns="http://www.w3.org/1999/xhtml">';
7336: } else {
1.849 bisitz 7337: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7338: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7339: }
7340: return $output;
7341: }
1.340 albertel 7342:
7343: =pod
7344:
1.306 albertel 7345: =item * &start_page()
7346:
7347: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7348:
1.648 raeburn 7349: Inputs:
7350:
7351: =over 4
7352:
7353: $title - optional title for the page
7354:
7355: $head_extra - optional extra HTML to incude inside the <head>
7356:
7357: $args - additional optional args supported are:
7358:
7359: =over 8
7360:
7361: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7362: arg on
1.814 bisitz 7363: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7364: add_entries -> additional attributes to add to the <body>
7365: domain -> force to color decorate a page for a
1.317 albertel 7366: specific domain
1.648 raeburn 7367: function -> force usage of a specific rolish color
1.317 albertel 7368: scheme
1.648 raeburn 7369: redirect -> see &headtag()
7370: bgcolor -> override the default page bg color
7371: js_ready -> return a string ready for being used in
1.317 albertel 7372: a javascript writeln
1.648 raeburn 7373: html_encode -> return a string ready for being used in
1.320 albertel 7374: a html attribute
1.648 raeburn 7375: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7376: $forcereg arg
1.648 raeburn 7377: frameset -> if true will start with a <frameset>
1.330 albertel 7378: rather than <body>
1.648 raeburn 7379: skip_phases -> hash ref of
1.338 albertel 7380: head -> skip the <html><head> generation
7381: body -> skip all <body> generation
1.1075.2.12 raeburn 7382: no_inline_link -> if true and in remote mode, don't show the
7383: 'Switch To Inline Menu' link
1.648 raeburn 7384: no_auto_mt_title -> prevent &mt()ing the title arg
7385: inherit_jsmath -> when creating popup window in a page,
7386: should it have jsmath forced on by the
7387: current page
1.867 kalberla 7388: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7389: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 7390:
1.648 raeburn 7391: =back
1.460 albertel 7392:
1.648 raeburn 7393: =back
1.562 albertel 7394:
1.306 albertel 7395: =cut
7396:
7397: sub start_page {
1.309 albertel 7398: my ($title,$head_extra,$args) = @_;
1.318 albertel 7399: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7400:
1.315 albertel 7401: $env{'internal.start_page'}++;
1.338 albertel 7402: my $result;
1.964 droeschl 7403:
1.338 albertel 7404: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7405: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7406: }
7407:
7408: if (! exists($args->{'skip_phases'}{'body'}) ) {
7409: if ($args->{'frameset'}) {
7410: my $attr_string = &make_attr_string($args->{'force_register'},
7411: $args->{'add_entries'});
7412: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7413: } else {
7414: $result .=
7415: &bodytag($title,
7416: $args->{'function'}, $args->{'add_entries'},
7417: $args->{'only_body'}, $args->{'domain'},
7418: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7419: $args->{'bgcolor'}, $args->{'no_inline_link'},
7420: $args);
1.831 bisitz 7421: }
1.330 albertel 7422: }
1.338 albertel 7423:
1.315 albertel 7424: if ($args->{'js_ready'}) {
1.713 kaisler 7425: $result = &js_ready($result);
1.315 albertel 7426: }
1.320 albertel 7427: if ($args->{'html_encode'}) {
1.713 kaisler 7428: $result = &html_encode($result);
7429: }
7430:
1.813 bisitz 7431: # Preparation for new and consistent functionlist at top of screen
7432: # if ($args->{'functionlist'}) {
7433: # $result .= &build_functionlist();
7434: #}
7435:
1.964 droeschl 7436: # Don't add anything more if only_body wanted or in const space
7437: return $result if $args->{'only_body'}
7438: || $env{'request.state'} eq 'construct';
1.813 bisitz 7439:
7440: #Breadcrumbs
1.758 kaisler 7441: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7442: &Apache::lonhtmlcommon::clear_breadcrumbs();
7443: #if any br links exists, add them to the breadcrumbs
7444: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7445: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7446: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7447: }
7448: }
7449:
7450: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7451: if(exists($args->{'bread_crumbs_component'})){
7452: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7453: }else{
7454: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7455: }
1.320 albertel 7456: }
1.315 albertel 7457: return $result;
1.306 albertel 7458: }
7459:
7460: sub end_page {
1.315 albertel 7461: my ($args) = @_;
7462: $env{'internal.end_page'}++;
1.330 albertel 7463: my $result;
1.335 albertel 7464: if ($args->{'discussion'}) {
7465: my ($target,$parser);
7466: if (ref($args->{'discussion'})) {
7467: ($target,$parser) =($args->{'discussion'}{'target'},
7468: $args->{'discussion'}{'parser'});
7469: }
7470: $result .= &Apache::lonxml::xmlend($target,$parser);
7471: }
1.330 albertel 7472: if ($args->{'frameset'}) {
7473: $result .= '</frameset>';
7474: } else {
1.635 raeburn 7475: $result .= &endbodytag($args);
1.330 albertel 7476: }
1.1075.2.6 raeburn 7477: unless ($args->{'notbody'}) {
7478: $result .= "\n</html>";
7479: }
1.330 albertel 7480:
1.315 albertel 7481: if ($args->{'js_ready'}) {
1.317 albertel 7482: $result = &js_ready($result);
1.315 albertel 7483: }
1.335 albertel 7484:
1.320 albertel 7485: if ($args->{'html_encode'}) {
7486: $result = &html_encode($result);
7487: }
1.335 albertel 7488:
1.315 albertel 7489: return $result;
7490: }
7491:
1.1034 www 7492: sub wishlist_window {
7493: return(<<'ENDWISHLIST');
1.1046 raeburn 7494: <script type="text/javascript">
1.1034 www 7495: // <![CDATA[
7496: // <!-- BEGIN LON-CAPA Internal
7497: function set_wishlistlink(title, path) {
7498: if (!title) {
7499: title = document.title;
7500: title = title.replace(/^LON-CAPA /,'');
7501: }
7502: if (!path) {
7503: path = location.pathname;
7504: }
7505: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7506: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7507: }
7508: // END LON-CAPA Internal -->
7509: // ]]>
7510: </script>
7511: ENDWISHLIST
7512: }
7513:
1.1030 www 7514: sub modal_window {
7515: return(<<'ENDMODAL');
1.1046 raeburn 7516: <script type="text/javascript">
1.1030 www 7517: // <![CDATA[
7518: // <!-- BEGIN LON-CAPA Internal
7519: var modalWindow = {
7520: parent:"body",
7521: windowId:null,
7522: content:null,
7523: width:null,
7524: height:null,
7525: close:function()
7526: {
7527: $(".LCmodal-window").remove();
7528: $(".LCmodal-overlay").remove();
7529: },
7530: open:function()
7531: {
7532: var modal = "";
7533: modal += "<div class=\"LCmodal-overlay\"></div>";
7534: 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;\">";
7535: modal += this.content;
7536: modal += "</div>";
7537:
7538: $(this.parent).append(modal);
7539:
7540: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7541: $(".LCclose-window").click(function(){modalWindow.close();});
7542: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7543: }
7544: };
1.1031 www 7545: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7546: {
7547: modalWindow.windowId = "myModal";
7548: modalWindow.width = width;
7549: modalWindow.height = height;
1.1031 www 7550: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7551: modalWindow.open();
7552: };
7553: // END LON-CAPA Internal -->
7554: // ]]>
7555: </script>
7556: ENDMODAL
7557: }
7558:
7559: sub modal_link {
1.1052 www 7560: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7561: unless ($width) { $width=480; }
7562: unless ($height) { $height=400; }
1.1031 www 7563: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7564: my $target_attr;
7565: if (defined($target)) {
7566: $target_attr = 'target="'.$target.'"';
7567: }
7568: return <<"ENDLINK";
7569: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7570: $linktext</a>
7571: ENDLINK
1.1030 www 7572: }
7573:
1.1032 www 7574: sub modal_adhoc_script {
7575: my ($funcname,$width,$height,$content)=@_;
7576: return (<<ENDADHOC);
1.1046 raeburn 7577: <script type="text/javascript">
1.1032 www 7578: // <![CDATA[
7579: var $funcname = function()
7580: {
7581: modalWindow.windowId = "myModal";
7582: modalWindow.width = $width;
7583: modalWindow.height = $height;
7584: modalWindow.content = '$content';
7585: modalWindow.open();
7586: };
7587: // ]]>
7588: </script>
7589: ENDADHOC
7590: }
7591:
1.1041 www 7592: sub modal_adhoc_inner {
7593: my ($funcname,$width,$height,$content)=@_;
7594: my $innerwidth=$width-20;
7595: $content=&js_ready(
1.1042 www 7596: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041 www 7597: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
7598: $content.
7599: &end_scrollbox().
7600: &end_page()
7601: );
7602: return &modal_adhoc_script($funcname,$width,$height,$content);
7603: }
7604:
7605: sub modal_adhoc_window {
7606: my ($funcname,$width,$height,$content,$linktext)=@_;
7607: return &modal_adhoc_inner($funcname,$width,$height,$content).
7608: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7609: }
7610:
7611: sub modal_adhoc_launch {
7612: my ($funcname,$width,$height,$content)=@_;
7613: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7614: <script type="text/javascript">
7615: // <![CDATA[
7616: $funcname();
7617: // ]]>
7618: </script>
7619: ENDLAUNCH
7620: }
7621:
7622: sub modal_adhoc_close {
7623: return (<<ENDCLOSE);
7624: <script type="text/javascript">
7625: // <![CDATA[
7626: modalWindow.close();
7627: // ]]>
7628: </script>
7629: ENDCLOSE
7630: }
7631:
1.1038 www 7632: sub togglebox_script {
7633: return(<<ENDTOGGLE);
7634: <script type="text/javascript">
7635: // <![CDATA[
7636: function LCtoggleDisplay(id,hidetext,showtext) {
7637: link = document.getElementById(id + "link").childNodes[0];
7638: with (document.getElementById(id).style) {
7639: if (display == "none" ) {
7640: display = "inline";
7641: link.nodeValue = hidetext;
7642: } else {
7643: display = "none";
7644: link.nodeValue = showtext;
7645: }
7646: }
7647: }
7648: // ]]>
7649: </script>
7650: ENDTOGGLE
7651: }
7652:
1.1039 www 7653: sub start_togglebox {
7654: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7655: unless ($heading) { $heading=''; } else { $heading.=' '; }
7656: unless ($showtext) { $showtext=&mt('show'); }
7657: unless ($hidetext) { $hidetext=&mt('hide'); }
7658: unless ($headerbg) { $headerbg='#FFFFFF'; }
7659: return &start_data_table().
7660: &start_data_table_header_row().
7661: '<td bgcolor="'.$headerbg.'">'.$heading.
7662: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7663: $showtext.'\')">'.$showtext.'</a>]</td>'.
7664: &end_data_table_header_row().
7665: '<tr id="'.$id.'" style="display:none""><td>';
7666: }
7667:
7668: sub end_togglebox {
7669: return '</td></tr>'.&end_data_table();
7670: }
7671:
1.1041 www 7672: sub LCprogressbar_script {
1.1045 www 7673: my ($id)=@_;
1.1041 www 7674: return(<<ENDPROGRESS);
7675: <script type="text/javascript">
7676: // <![CDATA[
1.1045 www 7677: \$('#progressbar$id').progressbar({
1.1041 www 7678: value: 0,
7679: change: function(event, ui) {
7680: var newVal = \$(this).progressbar('option', 'value');
7681: \$('.pblabel', this).text(LCprogressTxt);
7682: }
7683: });
7684: // ]]>
7685: </script>
7686: ENDPROGRESS
7687: }
7688:
7689: sub LCprogressbarUpdate_script {
7690: return(<<ENDPROGRESSUPDATE);
7691: <style type="text/css">
7692: .ui-progressbar { position:relative; }
7693: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7694: </style>
7695: <script type="text/javascript">
7696: // <![CDATA[
1.1045 www 7697: var LCprogressTxt='---';
7698:
7699: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7700: LCprogressTxt=progresstext;
1.1045 www 7701: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7702: }
7703: // ]]>
7704: </script>
7705: ENDPROGRESSUPDATE
7706: }
7707:
1.1042 www 7708: my $LClastpercent;
1.1045 www 7709: my $LCidcnt;
7710: my $LCcurrentid;
1.1042 www 7711:
1.1041 www 7712: sub LCprogressbar {
1.1042 www 7713: my ($r)=(@_);
7714: $LClastpercent=0;
1.1045 www 7715: $LCidcnt++;
7716: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7717: my $starting=&mt('Starting');
7718: my $content=(<<ENDPROGBAR);
7719: <p>
1.1045 www 7720: <div id="progressbar$LCcurrentid">
1.1041 www 7721: <span class="pblabel">$starting</span>
7722: </div>
7723: </p>
7724: ENDPROGBAR
1.1045 www 7725: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7726: }
7727:
7728: sub LCprogressbarUpdate {
1.1042 www 7729: my ($r,$val,$text)=@_;
7730: unless ($val) {
7731: if ($LClastpercent) {
7732: $val=$LClastpercent;
7733: } else {
7734: $val=0;
7735: }
7736: }
1.1041 www 7737: if ($val<0) { $val=0; }
7738: if ($val>100) { $val=0; }
1.1042 www 7739: $LClastpercent=$val;
1.1041 www 7740: unless ($text) { $text=$val.'%'; }
7741: $text=&js_ready($text);
1.1044 www 7742: &r_print($r,<<ENDUPDATE);
1.1041 www 7743: <script type="text/javascript">
7744: // <![CDATA[
1.1045 www 7745: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7746: // ]]>
7747: </script>
7748: ENDUPDATE
1.1035 www 7749: }
7750:
1.1042 www 7751: sub LCprogressbarClose {
7752: my ($r)=@_;
7753: $LClastpercent=0;
1.1044 www 7754: &r_print($r,<<ENDCLOSE);
1.1042 www 7755: <script type="text/javascript">
7756: // <![CDATA[
1.1045 www 7757: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7758: // ]]>
7759: </script>
7760: ENDCLOSE
1.1044 www 7761: }
7762:
7763: sub r_print {
7764: my ($r,$to_print)=@_;
7765: if ($r) {
7766: $r->print($to_print);
7767: $r->rflush();
7768: } else {
7769: print($to_print);
7770: }
1.1042 www 7771: }
7772:
1.320 albertel 7773: sub html_encode {
7774: my ($result) = @_;
7775:
1.322 albertel 7776: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7777:
7778: return $result;
7779: }
1.1044 www 7780:
1.317 albertel 7781: sub js_ready {
7782: my ($result) = @_;
7783:
1.323 albertel 7784: $result =~ s/[\n\r]/ /xmsg;
7785: $result =~ s/\\/\\\\/xmsg;
7786: $result =~ s/'/\\'/xmsg;
1.372 albertel 7787: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7788:
7789: return $result;
7790: }
7791:
1.315 albertel 7792: sub validate_page {
7793: if ( exists($env{'internal.start_page'})
1.316 albertel 7794: && $env{'internal.start_page'} > 1) {
7795: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7796: $env{'internal.start_page'}.' '.
1.316 albertel 7797: $ENV{'request.filename'});
1.315 albertel 7798: }
7799: if ( exists($env{'internal.end_page'})
1.316 albertel 7800: && $env{'internal.end_page'} > 1) {
7801: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7802: $env{'internal.end_page'}.' '.
1.316 albertel 7803: $env{'request.filename'});
1.315 albertel 7804: }
7805: if ( exists($env{'internal.start_page'})
7806: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7807: &Apache::lonnet::logthis('start_page called without end_page '.
7808: $env{'request.filename'});
1.315 albertel 7809: }
7810: if ( ! exists($env{'internal.start_page'})
7811: && exists($env{'internal.end_page'})) {
1.316 albertel 7812: &Apache::lonnet::logthis('end_page called without start_page'.
7813: $env{'request.filename'});
1.315 albertel 7814: }
1.306 albertel 7815: }
1.315 albertel 7816:
1.996 www 7817:
7818: sub start_scrollbox {
1.1075 raeburn 7819: my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998 raeburn 7820: unless ($outerwidth) { $outerwidth='520px'; }
7821: unless ($width) { $width='500px'; }
7822: unless ($height) { $height='200px'; }
1.1075 raeburn 7823: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7824: if ($id ne '') {
1.1020 raeburn 7825: $table_id = " id='table_$id'";
7826: $div_id = " id='div_$id'";
1.1018 raeburn 7827: }
1.1075 raeburn 7828: if ($bgcolor ne '') {
7829: $tdcol = "background-color: $bgcolor;";
7830: }
7831: return <<"END";
7832: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
7833: END
1.996 www 7834: }
7835:
7836: sub end_scrollbox {
1.1036 www 7837: return '</div></td></tr></table>';
1.996 www 7838: }
7839:
1.318 albertel 7840: sub simple_error_page {
7841: my ($r,$title,$msg) = @_;
7842: my $page =
7843: &Apache::loncommon::start_page($title).
7844: &mt($msg).
7845: &Apache::loncommon::end_page();
7846: if (ref($r)) {
7847: $r->print($page);
1.327 albertel 7848: return;
1.318 albertel 7849: }
7850: return $page;
7851: }
1.347 albertel 7852:
7853: {
1.610 albertel 7854: my @row_count;
1.961 onken 7855:
7856: sub start_data_table_count {
7857: unshift(@row_count, 0);
7858: return;
7859: }
7860:
7861: sub end_data_table_count {
7862: shift(@row_count);
7863: return;
7864: }
7865:
1.347 albertel 7866: sub start_data_table {
1.1018 raeburn 7867: my ($add_class,$id) = @_;
1.422 albertel 7868: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7869: my $table_id;
7870: if (defined($id)) {
7871: $table_id = ' id="'.$id.'"';
7872: }
1.961 onken 7873: &start_data_table_count();
1.1018 raeburn 7874: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7875: }
7876:
7877: sub end_data_table {
1.961 onken 7878: &end_data_table_count();
1.389 albertel 7879: return '</table>'."\n";;
1.347 albertel 7880: }
7881:
7882: sub start_data_table_row {
1.974 wenzelju 7883: my ($add_class, $id) = @_;
1.610 albertel 7884: $row_count[0]++;
7885: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7886: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7887: $id = (' id="'.$id.'"') unless ($id eq '');
7888: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7889: }
1.471 banghart 7890:
7891: sub continue_data_table_row {
1.974 wenzelju 7892: my ($add_class, $id) = @_;
1.610 albertel 7893: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7894: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7895: $id = (' id="'.$id.'"') unless ($id eq '');
7896: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7897: }
1.347 albertel 7898:
7899: sub end_data_table_row {
1.389 albertel 7900: return '</tr>'."\n";;
1.347 albertel 7901: }
1.367 www 7902:
1.421 albertel 7903: sub start_data_table_empty_row {
1.707 bisitz 7904: # $row_count[0]++;
1.421 albertel 7905: return '<tr class="LC_empty_row" >'."\n";;
7906: }
7907:
7908: sub end_data_table_empty_row {
7909: return '</tr>'."\n";;
7910: }
7911:
1.367 www 7912: sub start_data_table_header_row {
1.389 albertel 7913: return '<tr class="LC_header_row">'."\n";;
1.367 www 7914: }
7915:
7916: sub end_data_table_header_row {
1.389 albertel 7917: return '</tr>'."\n";;
1.367 www 7918: }
1.890 droeschl 7919:
7920: sub data_table_caption {
7921: my $caption = shift;
7922: return "<caption class=\"LC_caption\">$caption</caption>";
7923: }
1.347 albertel 7924: }
7925:
1.548 albertel 7926: =pod
7927:
7928: =item * &inhibit_menu_check($arg)
7929:
7930: Checks for a inhibitmenu state and generates output to preserve it
7931:
7932: Inputs: $arg - can be any of
7933: - undef - in which case the return value is a string
7934: to add into arguments list of a uri
7935: - 'input' - in which case the return value is a HTML
7936: <form> <input> field of type hidden to
7937: preserve the value
7938: - a url - in which case the return value is the url with
7939: the neccesary cgi args added to preserve the
7940: inhibitmenu state
7941: - a ref to a url - no return value, but the string is
7942: updated to include the neccessary cgi
7943: args to preserve the inhibitmenu state
7944:
7945: =cut
7946:
7947: sub inhibit_menu_check {
7948: my ($arg) = @_;
7949: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7950: if ($arg eq 'input') {
7951: if ($env{'form.inhibitmenu'}) {
7952: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7953: } else {
7954: return
7955: }
7956: }
7957: if ($env{'form.inhibitmenu'}) {
7958: if (ref($arg)) {
7959: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7960: } elsif ($arg eq '') {
7961: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7962: } else {
7963: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7964: }
7965: }
7966: if (!ref($arg)) {
7967: return $arg;
7968: }
7969: }
7970:
1.251 albertel 7971: ###############################################
1.182 matthew 7972:
7973: =pod
7974:
1.549 albertel 7975: =back
7976:
7977: =head1 User Information Routines
7978:
7979: =over 4
7980:
1.405 albertel 7981: =item * &get_users_function()
1.182 matthew 7982:
7983: Used by &bodytag to determine the current users primary role.
7984: Returns either 'student','coordinator','admin', or 'author'.
7985:
7986: =cut
7987:
7988: ###############################################
7989: sub get_users_function {
1.815 tempelho 7990: my $function = 'norole';
1.818 tempelho 7991: if ($env{'request.role'}=~/^(st)/) {
7992: $function='student';
7993: }
1.907 raeburn 7994: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7995: $function='coordinator';
7996: }
1.258 albertel 7997: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7998: $function='admin';
7999: }
1.826 bisitz 8000: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8001: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8002: $function='author';
8003: }
8004: return $function;
1.54 www 8005: }
1.99 www 8006:
8007: ###############################################
8008:
1.233 raeburn 8009: =pod
8010:
1.821 raeburn 8011: =item * &show_course()
8012:
8013: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8014: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8015:
8016: Inputs:
8017: None
8018:
8019: Outputs:
8020: Scalar: 1 if 'Course' to be used, 0 otherwise.
8021:
8022: =cut
8023:
8024: ###############################################
8025: sub show_course {
8026: my $course = !$env{'user.adv'};
8027: if (!$env{'user.adv'}) {
8028: foreach my $env (keys(%env)) {
8029: next if ($env !~ m/^user\.priv\./);
8030: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8031: $course = 0;
8032: last;
8033: }
8034: }
8035: }
8036: return $course;
8037: }
8038:
8039: ###############################################
8040:
8041: =pod
8042:
1.542 raeburn 8043: =item * &check_user_status()
1.274 raeburn 8044:
8045: Determines current status of supplied role for a
8046: specific user. Roles can be active, previous or future.
8047:
8048: Inputs:
8049: user's domain, user's username, course's domain,
1.375 raeburn 8050: course's number, optional section ID.
1.274 raeburn 8051:
8052: Outputs:
8053: role status: active, previous or future.
8054:
8055: =cut
8056:
8057: sub check_user_status {
1.412 raeburn 8058: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8059: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8060: my @uroles = keys %userinfo;
8061: my $srchstr;
8062: my $active_chk = 'none';
1.412 raeburn 8063: my $now = time;
1.274 raeburn 8064: if (@uroles > 0) {
1.908 raeburn 8065: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8066: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8067: } else {
1.412 raeburn 8068: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8069: }
8070: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8071: my $role_end = 0;
8072: my $role_start = 0;
8073: $active_chk = 'active';
1.412 raeburn 8074: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8075: $role_end = $1;
8076: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8077: $role_start = $1;
1.274 raeburn 8078: }
8079: }
8080: if ($role_start > 0) {
1.412 raeburn 8081: if ($now < $role_start) {
1.274 raeburn 8082: $active_chk = 'future';
8083: }
8084: }
8085: if ($role_end > 0) {
1.412 raeburn 8086: if ($now > $role_end) {
1.274 raeburn 8087: $active_chk = 'previous';
8088: }
8089: }
8090: }
8091: }
8092: return $active_chk;
8093: }
8094:
8095: ###############################################
8096:
8097: =pod
8098:
1.405 albertel 8099: =item * &get_sections()
1.233 raeburn 8100:
8101: Determines all the sections for a course including
8102: sections with students and sections containing other roles.
1.419 raeburn 8103: Incoming parameters:
8104:
8105: 1. domain
8106: 2. course number
8107: 3. reference to array containing roles for which sections should
8108: be gathered (optional).
8109: 4. reference to array containing status types for which sections
8110: should be gathered (optional).
8111:
8112: If the third argument is undefined, sections are gathered for any role.
8113: If the fourth argument is undefined, sections are gathered for any status.
8114: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8115:
1.374 raeburn 8116: Returns section hash (keys are section IDs, values are
8117: number of users in each section), subject to the
1.419 raeburn 8118: optional roles filter, optional status filter
1.233 raeburn 8119:
8120: =cut
8121:
8122: ###############################################
8123: sub get_sections {
1.419 raeburn 8124: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8125: if (!defined($cdom) || !defined($cnum)) {
8126: my $cid = $env{'request.course.id'};
8127:
8128: return if (!defined($cid));
8129:
8130: $cdom = $env{'course.'.$cid.'.domain'};
8131: $cnum = $env{'course.'.$cid.'.num'};
8132: }
8133:
8134: my %sectioncount;
1.419 raeburn 8135: my $now = time;
1.240 albertel 8136:
1.366 albertel 8137: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 8138: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8139: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8140: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8141: my $start_index = &Apache::loncoursedata::CL_START();
8142: my $end_index = &Apache::loncoursedata::CL_END();
8143: my $status;
1.366 albertel 8144: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8145: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8146: $data->[$status_index],
8147: $data->[$start_index],
8148: $data->[$end_index]);
8149: if ($stu_status eq 'Active') {
8150: $status = 'active';
8151: } elsif ($end < $now) {
8152: $status = 'previous';
8153: } elsif ($start > $now) {
8154: $status = 'future';
8155: }
8156: if ($section ne '-1' && $section !~ /^\s*$/) {
8157: if ((!defined($possible_status)) || (($status ne '') &&
8158: (grep/^\Q$status\E$/,@{$possible_status}))) {
8159: $sectioncount{$section}++;
8160: }
1.240 albertel 8161: }
8162: }
8163: }
8164: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8165: foreach my $user (sort(keys(%courseroles))) {
8166: if ($user !~ /^(\w{2})/) { next; }
8167: my ($role) = ($user =~ /^(\w{2})/);
8168: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8169: my ($section,$status);
1.240 albertel 8170: if ($role eq 'cr' &&
8171: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8172: $section=$1;
8173: }
8174: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8175: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8176: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8177: if ($end == -1 && $start == -1) {
8178: next; #deleted role
8179: }
8180: if (!defined($possible_status)) {
8181: $sectioncount{$section}++;
8182: } else {
8183: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8184: $status = 'active';
8185: } elsif ($end < $now) {
8186: $status = 'future';
8187: } elsif ($start > $now) {
8188: $status = 'previous';
8189: }
8190: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8191: $sectioncount{$section}++;
8192: }
8193: }
1.233 raeburn 8194: }
1.366 albertel 8195: return %sectioncount;
1.233 raeburn 8196: }
8197:
1.274 raeburn 8198: ###############################################
1.294 raeburn 8199:
8200: =pod
1.405 albertel 8201:
8202: =item * &get_course_users()
8203:
1.275 raeburn 8204: Retrieves usernames:domains for users in the specified course
8205: with specific role(s), and access status.
8206:
8207: Incoming parameters:
1.277 albertel 8208: 1. course domain
8209: 2. course number
8210: 3. access status: users must have - either active,
1.275 raeburn 8211: previous, future, or all.
1.277 albertel 8212: 4. reference to array of permissible roles
1.288 raeburn 8213: 5. reference to array of section restrictions (optional)
8214: 6. reference to results object (hash of hashes).
8215: 7. reference to optional userdata hash
1.609 raeburn 8216: 8. reference to optional statushash
1.630 raeburn 8217: 9. flag if privileged users (except those set to unhide in
8218: course settings) should be excluded
1.609 raeburn 8219: Keys of top level results hash are roles.
1.275 raeburn 8220: Keys of inner hashes are username:domain, with
8221: values set to access type.
1.288 raeburn 8222: Optional userdata hash returns an array with arguments in the
8223: same order as loncoursedata::get_classlist() for student data.
8224:
1.609 raeburn 8225: Optional statushash returns
8226:
1.288 raeburn 8227: Entries for end, start, section and status are blank because
8228: of the possibility of multiple values for non-student roles.
8229:
1.275 raeburn 8230: =cut
1.405 albertel 8231:
1.275 raeburn 8232: ###############################################
1.405 albertel 8233:
1.275 raeburn 8234: sub get_course_users {
1.630 raeburn 8235: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8236: my %idx = ();
1.419 raeburn 8237: my %seclists;
1.288 raeburn 8238:
8239: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8240: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8241: $idx{end} = &Apache::loncoursedata::CL_END();
8242: $idx{start} = &Apache::loncoursedata::CL_START();
8243: $idx{id} = &Apache::loncoursedata::CL_ID();
8244: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8245: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8246: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8247:
1.290 albertel 8248: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8249: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8250: my $now = time;
1.277 albertel 8251: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8252: my $match = 0;
1.412 raeburn 8253: my $secmatch = 0;
1.419 raeburn 8254: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8255: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8256: if ($section eq '') {
8257: $section = 'none';
8258: }
1.291 albertel 8259: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8260: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8261: $secmatch = 1;
8262: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8263: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8264: $secmatch = 1;
8265: }
8266: } else {
1.419 raeburn 8267: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8268: $secmatch = 1;
8269: }
1.290 albertel 8270: }
1.412 raeburn 8271: if (!$secmatch) {
8272: next;
8273: }
1.419 raeburn 8274: }
1.275 raeburn 8275: if (defined($$types{'active'})) {
1.288 raeburn 8276: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8277: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8278: $match = 1;
1.275 raeburn 8279: }
8280: }
8281: if (defined($$types{'previous'})) {
1.609 raeburn 8282: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8283: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8284: $match = 1;
1.275 raeburn 8285: }
8286: }
8287: if (defined($$types{'future'})) {
1.609 raeburn 8288: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8289: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8290: $match = 1;
1.275 raeburn 8291: }
8292: }
1.609 raeburn 8293: if ($match) {
8294: push(@{$seclists{$student}},$section);
8295: if (ref($userdata) eq 'HASH') {
8296: $$userdata{$student} = $$classlist{$student};
8297: }
8298: if (ref($statushash) eq 'HASH') {
8299: $statushash->{$student}{'st'}{$section} = $status;
8300: }
1.288 raeburn 8301: }
1.275 raeburn 8302: }
8303: }
1.412 raeburn 8304: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8305: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8306: my $now = time;
1.609 raeburn 8307: my %displaystatus = ( previous => 'Expired',
8308: active => 'Active',
8309: future => 'Future',
8310: );
1.630 raeburn 8311: my %nothide;
8312: if ($hidepriv) {
8313: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8314: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8315: if ($user !~ /:/) {
8316: $nothide{join(':',split(/[\@]/,$user))}=1;
8317: } else {
8318: $nothide{$user} = 1;
8319: }
8320: }
8321: }
1.439 raeburn 8322: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8323: my $match = 0;
1.412 raeburn 8324: my $secmatch = 0;
1.439 raeburn 8325: my $status;
1.412 raeburn 8326: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8327: $user =~ s/:$//;
1.439 raeburn 8328: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8329: if ($end == -1 || $start == -1) {
8330: next;
8331: }
8332: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8333: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8334: my ($uname,$udom) = split(/:/,$user);
8335: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8336: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8337: $secmatch = 1;
8338: } elsif ($usec eq '') {
1.420 albertel 8339: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8340: $secmatch = 1;
8341: }
8342: } else {
8343: if (grep(/^\Q$usec\E$/,@{$sections})) {
8344: $secmatch = 1;
8345: }
8346: }
8347: if (!$secmatch) {
8348: next;
8349: }
1.288 raeburn 8350: }
1.419 raeburn 8351: if ($usec eq '') {
8352: $usec = 'none';
8353: }
1.275 raeburn 8354: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8355: if ($hidepriv) {
8356: if ((&Apache::lonnet::privileged($uname,$udom)) &&
8357: (!$nothide{$uname.':'.$udom})) {
8358: next;
8359: }
8360: }
1.503 raeburn 8361: if ($end > 0 && $end < $now) {
1.439 raeburn 8362: $status = 'previous';
8363: } elsif ($start > $now) {
8364: $status = 'future';
8365: } else {
8366: $status = 'active';
8367: }
1.277 albertel 8368: foreach my $type (keys(%{$types})) {
1.275 raeburn 8369: if ($status eq $type) {
1.420 albertel 8370: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8371: push(@{$$users{$role}{$user}},$type);
8372: }
1.288 raeburn 8373: $match = 1;
8374: }
8375: }
1.419 raeburn 8376: if (($match) && (ref($userdata) eq 'HASH')) {
8377: if (!exists($$userdata{$uname.':'.$udom})) {
8378: &get_user_info($udom,$uname,\%idx,$userdata);
8379: }
1.420 albertel 8380: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8381: push(@{$seclists{$uname.':'.$udom}},$usec);
8382: }
1.609 raeburn 8383: if (ref($statushash) eq 'HASH') {
8384: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8385: }
1.275 raeburn 8386: }
8387: }
8388: }
8389: }
1.290 albertel 8390: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8391: if ((defined($cdom)) && (defined($cnum))) {
8392: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8393: if ( defined($csettings{'internal.courseowner'}) ) {
8394: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8395: next if ($owner eq '');
8396: my ($ownername,$ownerdom);
8397: if ($owner =~ /^([^:]+):([^:]+)$/) {
8398: $ownername = $1;
8399: $ownerdom = $2;
8400: } else {
8401: $ownername = $owner;
8402: $ownerdom = $cdom;
8403: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8404: }
8405: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8406: if (defined($userdata) &&
1.609 raeburn 8407: !exists($$userdata{$owner})) {
8408: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8409: if (!grep(/^none$/,@{$seclists{$owner}})) {
8410: push(@{$seclists{$owner}},'none');
8411: }
8412: if (ref($statushash) eq 'HASH') {
8413: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8414: }
1.290 albertel 8415: }
1.279 raeburn 8416: }
8417: }
8418: }
1.419 raeburn 8419: foreach my $user (keys(%seclists)) {
8420: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8421: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8422: }
1.275 raeburn 8423: }
8424: return;
8425: }
8426:
1.288 raeburn 8427: sub get_user_info {
8428: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8429: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8430: &plainname($uname,$udom,'lastname');
1.291 albertel 8431: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8432: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8433: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8434: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8435: return;
8436: }
1.275 raeburn 8437:
1.472 raeburn 8438: ###############################################
8439:
8440: =pod
8441:
8442: =item * &get_user_quota()
8443:
8444: Retrieves quota assigned for storage of portfolio files for a user
8445:
8446: Incoming parameters:
8447: 1. user's username
8448: 2. user's domain
8449:
8450: Returns:
1.536 raeburn 8451: 1. Disk quota (in Mb) assigned to student.
8452: 2. (Optional) Type of setting: custom or default
8453: (individually assigned or default for user's
8454: institutional status).
8455: 3. (Optional) - User's institutional status (e.g., faculty, staff
8456: or student - types as defined in localenroll::inst_usertypes
8457: for user's domain, which determines default quota for user.
8458: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8459:
8460: If a value has been stored in the user's environment,
1.536 raeburn 8461: it will return that, otherwise it returns the maximal default
8462: defined for the user's instituional status(es) in the domain.
1.472 raeburn 8463:
8464: =cut
8465:
8466: ###############################################
8467:
8468:
8469: sub get_user_quota {
8470: my ($uname,$udom) = @_;
1.536 raeburn 8471: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8472: if (!defined($udom)) {
8473: $udom = $env{'user.domain'};
8474: }
8475: if (!defined($uname)) {
8476: $uname = $env{'user.name'};
8477: }
8478: if (($udom eq '' || $uname eq '') ||
8479: ($udom eq 'public') && ($uname eq 'public')) {
8480: $quota = 0;
1.536 raeburn 8481: $quotatype = 'default';
8482: $defquota = 0;
1.472 raeburn 8483: } else {
1.536 raeburn 8484: my $inststatus;
1.472 raeburn 8485: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8486: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 8487: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 8488: } else {
1.536 raeburn 8489: my %userenv =
8490: &Apache::lonnet::get('environment',['portfolioquota',
8491: 'inststatus'],$udom,$uname);
1.472 raeburn 8492: my ($tmp) = keys(%userenv);
8493: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8494: $quota = $userenv{'portfolioquota'};
1.536 raeburn 8495: $inststatus = $userenv{'inststatus'};
1.472 raeburn 8496: } else {
8497: undef(%userenv);
8498: }
8499: }
1.536 raeburn 8500: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 8501: if ($quota eq '') {
1.536 raeburn 8502: $quota = $defquota;
8503: $quotatype = 'default';
8504: } else {
8505: $quotatype = 'custom';
1.472 raeburn 8506: }
8507: }
1.536 raeburn 8508: if (wantarray) {
8509: return ($quota,$quotatype,$settingstatus,$defquota);
8510: } else {
8511: return $quota;
8512: }
1.472 raeburn 8513: }
8514:
8515: ###############################################
8516:
8517: =pod
8518:
8519: =item * &default_quota()
8520:
1.536 raeburn 8521: Retrieves default quota assigned for storage of user portfolio files,
8522: given an (optional) user's institutional status.
1.472 raeburn 8523:
8524: Incoming parameters:
8525: 1. domain
1.536 raeburn 8526: 2. (Optional) institutional status(es). This is a : separated list of
8527: status types (e.g., faculty, staff, student etc.)
8528: which apply to the user for whom the default is being retrieved.
8529: If the institutional status string in undefined, the domain
8530: default quota will be returned.
1.472 raeburn 8531:
8532: Returns:
8533: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8534: 2. (Optional) institutional type which determined the value of the
8535: default quota.
1.472 raeburn 8536:
8537: If a value has been stored in the domain's configuration db,
8538: it will return that, otherwise it returns 20 (for backwards
8539: compatibility with domains which have not set up a configuration
8540: db file; the original statically defined portfolio quota was 20 Mb).
8541:
1.536 raeburn 8542: If the user's status includes multiple types (e.g., staff and student),
8543: the largest default quota which applies to the user determines the
8544: default quota returned.
8545:
1.780 raeburn 8546: =back
8547:
1.472 raeburn 8548: =cut
8549:
8550: ###############################################
8551:
8552:
8553: sub default_quota {
1.536 raeburn 8554: my ($udom,$inststatus) = @_;
8555: my ($defquota,$settingstatus);
8556: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8557: ['quotas'],$udom);
8558: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8559: if ($inststatus ne '') {
1.765 raeburn 8560: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8561: foreach my $item (@statuses) {
1.711 raeburn 8562: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8563: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
8564: if ($defquota eq '') {
8565: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8566: $settingstatus = $item;
8567: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
8568: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8569: $settingstatus = $item;
8570: }
8571: }
8572: } else {
8573: if ($quotahash{'quotas'}{$item} ne '') {
8574: if ($defquota eq '') {
8575: $defquota = $quotahash{'quotas'}{$item};
8576: $settingstatus = $item;
8577: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8578: $defquota = $quotahash{'quotas'}{$item};
8579: $settingstatus = $item;
8580: }
1.536 raeburn 8581: }
8582: }
8583: }
8584: }
8585: if ($defquota eq '') {
1.711 raeburn 8586: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8587: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
8588: } else {
8589: $defquota = $quotahash{'quotas'}{'default'};
8590: }
1.536 raeburn 8591: $settingstatus = 'default';
8592: }
8593: } else {
8594: $settingstatus = 'default';
8595: $defquota = 20;
8596: }
8597: if (wantarray) {
8598: return ($defquota,$settingstatus);
1.472 raeburn 8599: } else {
1.536 raeburn 8600: return $defquota;
1.472 raeburn 8601: }
8602: }
8603:
1.384 raeburn 8604: sub get_secgrprole_info {
8605: my ($cdom,$cnum,$needroles,$type) = @_;
8606: my %sections_count = &get_sections($cdom,$cnum);
8607: my @sections = (sort {$a <=> $b} keys(%sections_count));
8608: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8609: my @groups = sort(keys(%curr_groups));
8610: my $allroles = [];
8611: my $rolehash;
8612: my $accesshash = {
8613: active => 'Currently has access',
8614: future => 'Will have future access',
8615: previous => 'Previously had access',
8616: };
8617: if ($needroles) {
8618: $rolehash = {'all' => 'all'};
1.385 albertel 8619: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8620: if (&Apache::lonnet::error(%user_roles)) {
8621: undef(%user_roles);
8622: }
8623: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8624: my ($role)=split(/\:/,$item,2);
8625: if ($role eq 'cr') { next; }
8626: if ($role =~ /^cr/) {
8627: $$rolehash{$role} = (split('/',$role))[3];
8628: } else {
8629: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8630: }
8631: }
8632: foreach my $key (sort(keys(%{$rolehash}))) {
8633: push(@{$allroles},$key);
8634: }
8635: push (@{$allroles},'st');
8636: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8637: }
8638: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8639: }
8640:
1.555 raeburn 8641: sub user_picker {
1.994 raeburn 8642: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8643: my $currdom = $dom;
8644: my %curr_selected = (
8645: srchin => 'dom',
1.580 raeburn 8646: srchby => 'lastname',
1.555 raeburn 8647: );
8648: my $srchterm;
1.625 raeburn 8649: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8650: if ($srch->{'srchby'} ne '') {
8651: $curr_selected{'srchby'} = $srch->{'srchby'};
8652: }
8653: if ($srch->{'srchin'} ne '') {
8654: $curr_selected{'srchin'} = $srch->{'srchin'};
8655: }
8656: if ($srch->{'srchtype'} ne '') {
8657: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8658: }
8659: if ($srch->{'srchdomain'} ne '') {
8660: $currdom = $srch->{'srchdomain'};
8661: }
8662: $srchterm = $srch->{'srchterm'};
8663: }
8664: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8665: 'usr' => 'Search criteria',
1.563 raeburn 8666: 'doma' => 'Domain/institution to search',
1.558 albertel 8667: 'uname' => 'username',
8668: 'lastname' => 'last name',
1.555 raeburn 8669: 'lastfirst' => 'last name, first name',
1.558 albertel 8670: 'crs' => 'in this course',
1.576 raeburn 8671: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8672: 'alc' => 'all LON-CAPA',
1.573 raeburn 8673: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8674: 'exact' => 'is',
8675: 'contains' => 'contains',
1.569 raeburn 8676: 'begins' => 'begins with',
1.571 raeburn 8677: 'youm' => "You must include some text to search for.",
8678: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8679: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8680: 'yomc' => "You must choose a domain when using an institutional directory search.",
8681: 'ymcd' => "You must choose a domain when using a domain search.",
8682: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8683: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8684: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8685: );
1.563 raeburn 8686: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8687: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8688:
8689: my @srchins = ('crs','dom','alc','instd');
8690:
8691: foreach my $option (@srchins) {
8692: # FIXME 'alc' option unavailable until
8693: # loncreateuser::print_user_query_page()
8694: # has been completed.
8695: next if ($option eq 'alc');
1.880 raeburn 8696: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8697: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8698: if ($curr_selected{'srchin'} eq $option) {
8699: $srchinsel .= '
8700: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8701: } else {
8702: $srchinsel .= '
8703: <option value="'.$option.'">'.$lt{$option}.'</option>';
8704: }
1.555 raeburn 8705: }
1.563 raeburn 8706: $srchinsel .= "\n </select>\n";
1.555 raeburn 8707:
8708: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 8709: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 8710: if ($curr_selected{'srchby'} eq $option) {
8711: $srchbysel .= '
8712: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8713: } else {
8714: $srchbysel .= '
8715: <option value="'.$option.'">'.$lt{$option}.'</option>';
8716: }
8717: }
8718: $srchbysel .= "\n </select>\n";
8719:
8720: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 8721: foreach my $option ('begins','contains','exact') {
1.555 raeburn 8722: if ($curr_selected{'srchtype'} eq $option) {
8723: $srchtypesel .= '
8724: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8725: } else {
8726: $srchtypesel .= '
8727: <option value="'.$option.'">'.$lt{$option}.'</option>';
8728: }
8729: }
8730: $srchtypesel .= "\n </select>\n";
8731:
1.558 albertel 8732: my ($newuserscript,$new_user_create);
1.994 raeburn 8733: my $context_dom = $env{'request.role.domain'};
8734: if ($context eq 'requestcrs') {
8735: if ($env{'form.coursedom'} ne '') {
8736: $context_dom = $env{'form.coursedom'};
8737: }
8738: }
1.556 raeburn 8739: if ($forcenewuser) {
1.576 raeburn 8740: if (ref($srch) eq 'HASH') {
1.994 raeburn 8741: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8742: if ($cancreate) {
8743: $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>';
8744: } else {
1.799 bisitz 8745: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8746: my %usertypetext = (
8747: official => 'institutional',
8748: unofficial => 'non-institutional',
8749: );
1.799 bisitz 8750: $new_user_create = '<p class="LC_warning">'
8751: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
8752: .' '
8753: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8754: ,'<a href="'.$helplink.'">','</a>')
8755: .'</p><br />';
1.627 raeburn 8756: }
1.576 raeburn 8757: }
8758: }
8759:
1.556 raeburn 8760: $newuserscript = <<"ENDSCRIPT";
8761:
1.570 raeburn 8762: function setSearch(createnew,callingForm) {
1.556 raeburn 8763: if (createnew == 1) {
1.570 raeburn 8764: for (var i=0; i<callingForm.srchby.length; i++) {
8765: if (callingForm.srchby.options[i].value == 'uname') {
8766: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8767: }
8768: }
1.570 raeburn 8769: for (var i=0; i<callingForm.srchin.length; i++) {
8770: if ( callingForm.srchin.options[i].value == 'dom') {
8771: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8772: }
8773: }
1.570 raeburn 8774: for (var i=0; i<callingForm.srchtype.length; i++) {
8775: if (callingForm.srchtype.options[i].value == 'exact') {
8776: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8777: }
8778: }
1.570 raeburn 8779: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 8780: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8781: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8782: }
8783: }
8784: }
8785: }
8786: ENDSCRIPT
1.558 albertel 8787:
1.556 raeburn 8788: }
8789:
1.555 raeburn 8790: my $output = <<"END_BLOCK";
1.556 raeburn 8791: <script type="text/javascript">
1.824 bisitz 8792: // <![CDATA[
1.570 raeburn 8793: function validateEntry(callingForm) {
1.558 albertel 8794:
1.556 raeburn 8795: var checkok = 1;
1.558 albertel 8796: var srchin;
1.570 raeburn 8797: for (var i=0; i<callingForm.srchin.length; i++) {
8798: if ( callingForm.srchin[i].checked ) {
8799: srchin = callingForm.srchin[i].value;
1.558 albertel 8800: }
8801: }
8802:
1.570 raeburn 8803: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8804: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8805: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8806: var srchterm = callingForm.srchterm.value;
8807: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8808: var msg = "";
8809:
8810: if (srchterm == "") {
8811: checkok = 0;
1.571 raeburn 8812: msg += "$lt{'youm'}\\n";
1.556 raeburn 8813: }
8814:
1.569 raeburn 8815: if (srchtype== 'begins') {
8816: if (srchterm.length < 2) {
8817: checkok = 0;
1.571 raeburn 8818: msg += "$lt{'thte'}\\n";
1.569 raeburn 8819: }
8820: }
8821:
1.556 raeburn 8822: if (srchtype== 'contains') {
8823: if (srchterm.length < 3) {
8824: checkok = 0;
1.571 raeburn 8825: msg += "$lt{'thet'}\\n";
1.556 raeburn 8826: }
8827: }
8828: if (srchin == 'instd') {
8829: if (srchdomain == '') {
8830: checkok = 0;
1.571 raeburn 8831: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8832: }
8833: }
8834: if (srchin == 'dom') {
8835: if (srchdomain == '') {
8836: checkok = 0;
1.571 raeburn 8837: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8838: }
8839: }
8840: if (srchby == 'lastfirst') {
8841: if (srchterm.indexOf(",") == -1) {
8842: checkok = 0;
1.571 raeburn 8843: msg += "$lt{'whus'}\\n";
1.556 raeburn 8844: }
8845: if (srchterm.indexOf(",") == srchterm.length -1) {
8846: checkok = 0;
1.571 raeburn 8847: msg += "$lt{'whse'}\\n";
1.556 raeburn 8848: }
8849: }
8850: if (checkok == 0) {
1.571 raeburn 8851: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8852: return;
8853: }
8854: if (checkok == 1) {
1.570 raeburn 8855: callingForm.submit();
1.556 raeburn 8856: }
8857: }
8858:
8859: $newuserscript
8860:
1.824 bisitz 8861: // ]]>
1.556 raeburn 8862: </script>
1.558 albertel 8863:
8864: $new_user_create
8865:
1.555 raeburn 8866: END_BLOCK
1.558 albertel 8867:
1.876 raeburn 8868: $output .= &Apache::lonhtmlcommon::start_pick_box().
8869: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8870: $domform.
8871: &Apache::lonhtmlcommon::row_closure().
8872: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8873: $srchbysel.
8874: $srchtypesel.
8875: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8876: $srchinsel.
8877: &Apache::lonhtmlcommon::row_closure(1).
8878: &Apache::lonhtmlcommon::end_pick_box().
8879: '<br />';
1.555 raeburn 8880: return $output;
8881: }
8882:
1.612 raeburn 8883: sub user_rule_check {
1.615 raeburn 8884: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8885: my $response;
8886: if (ref($usershash) eq 'HASH') {
8887: foreach my $user (keys(%{$usershash})) {
8888: my ($uname,$udom) = split(/:/,$user);
8889: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8890: my ($id,$newuser);
1.612 raeburn 8891: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8892: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8893: $id = $usershash->{$user}->{'id'};
8894: }
8895: my $inst_response;
8896: if (ref($checks) eq 'HASH') {
8897: if (defined($checks->{'username'})) {
1.615 raeburn 8898: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8899: &Apache::lonnet::get_instuser($udom,$uname);
8900: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8901: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8902: &Apache::lonnet::get_instuser($udom,undef,$id);
8903: }
1.615 raeburn 8904: } else {
8905: ($inst_response,%{$inst_results->{$user}}) =
8906: &Apache::lonnet::get_instuser($udom,$uname);
8907: return;
1.612 raeburn 8908: }
1.615 raeburn 8909: if (!$got_rules->{$udom}) {
1.612 raeburn 8910: my %domconfig = &Apache::lonnet::get_dom('configuration',
8911: ['usercreation'],$udom);
8912: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8913: foreach my $item ('username','id') {
1.612 raeburn 8914: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8915: $$curr_rules{$udom}{$item} =
8916: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8917: }
8918: }
8919: }
1.615 raeburn 8920: $got_rules->{$udom} = 1;
1.585 raeburn 8921: }
1.612 raeburn 8922: foreach my $item (keys(%{$checks})) {
8923: if (ref($$curr_rules{$udom}) eq 'HASH') {
8924: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8925: if (@{$$curr_rules{$udom}{$item}} > 0) {
8926: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8927: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8928: if ($rule_check{$rule}) {
8929: $$rulematch{$user}{$item} = $rule;
8930: if ($inst_response eq 'ok') {
1.615 raeburn 8931: if (ref($inst_results) eq 'HASH') {
8932: if (ref($inst_results->{$user}) eq 'HASH') {
8933: if (keys(%{$inst_results->{$user}}) == 0) {
8934: $$alerts{$item}{$udom}{$uname} = 1;
8935: }
1.612 raeburn 8936: }
8937: }
1.615 raeburn 8938: }
8939: last;
1.585 raeburn 8940: }
8941: }
8942: }
8943: }
8944: }
8945: }
8946: }
8947: }
1.612 raeburn 8948: return;
8949: }
8950:
8951: sub user_rule_formats {
8952: my ($domain,$domdesc,$curr_rules,$check) = @_;
8953: my %text = (
8954: 'username' => 'Usernames',
8955: 'id' => 'IDs',
8956: );
8957: my $output;
8958: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8959: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8960: if (@{$ruleorder} > 0) {
8961: $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>';
8962: foreach my $rule (@{$ruleorder}) {
8963: if (ref($curr_rules) eq 'ARRAY') {
8964: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8965: if (ref($rules->{$rule}) eq 'HASH') {
8966: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8967: $rules->{$rule}{'desc'}.'</li>';
8968: }
8969: }
8970: }
8971: }
8972: $output .= '</ul>';
8973: }
8974: }
8975: return $output;
8976: }
8977:
8978: sub instrule_disallow_msg {
1.615 raeburn 8979: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8980: my $response;
8981: my %text = (
8982: item => 'username',
8983: items => 'usernames',
8984: match => 'matches',
8985: do => 'does',
8986: action => 'a username',
8987: one => 'one',
8988: );
8989: if ($count > 1) {
8990: $text{'item'} = 'usernames';
8991: $text{'match'} ='match';
8992: $text{'do'} = 'do';
8993: $text{'action'} = 'usernames',
8994: $text{'one'} = 'ones';
8995: }
8996: if ($checkitem eq 'id') {
8997: $text{'items'} = 'IDs';
8998: $text{'item'} = 'ID';
8999: $text{'action'} = 'an ID';
1.615 raeburn 9000: if ($count > 1) {
9001: $text{'item'} = 'IDs';
9002: $text{'action'} = 'IDs';
9003: }
1.612 raeburn 9004: }
1.674 bisitz 9005: $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 9006: if ($mode eq 'upload') {
9007: if ($checkitem eq 'username') {
9008: $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'}.");
9009: } elsif ($checkitem eq 'id') {
1.674 bisitz 9010: $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 9011: }
1.669 raeburn 9012: } elsif ($mode eq 'selfcreate') {
9013: if ($checkitem eq 'id') {
9014: $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.");
9015: }
1.615 raeburn 9016: } else {
9017: if ($checkitem eq 'username') {
9018: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9019: } elsif ($checkitem eq 'id') {
9020: $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.");
9021: }
1.612 raeburn 9022: }
9023: return $response;
1.585 raeburn 9024: }
9025:
1.624 raeburn 9026: sub personal_data_fieldtitles {
9027: my %fieldtitles = &Apache::lonlocal::texthash (
9028: id => 'Student/Employee ID',
9029: permanentemail => 'E-mail address',
9030: lastname => 'Last Name',
9031: firstname => 'First Name',
9032: middlename => 'Middle Name',
9033: generation => 'Generation',
9034: gen => 'Generation',
1.765 raeburn 9035: inststatus => 'Affiliation',
1.624 raeburn 9036: );
9037: return %fieldtitles;
9038: }
9039:
1.642 raeburn 9040: sub sorted_inst_types {
9041: my ($dom) = @_;
9042: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9043: my $othertitle = &mt('All users');
9044: if ($env{'request.course.id'}) {
1.668 raeburn 9045: $othertitle = &mt('Any users');
1.642 raeburn 9046: }
9047: my @types;
9048: if (ref($order) eq 'ARRAY') {
9049: @types = @{$order};
9050: }
9051: if (@types == 0) {
9052: if (ref($usertypes) eq 'HASH') {
9053: @types = sort(keys(%{$usertypes}));
9054: }
9055: }
9056: if (keys(%{$usertypes}) > 0) {
9057: $othertitle = &mt('Other users');
9058: }
9059: return ($othertitle,$usertypes,\@types);
9060: }
9061:
1.645 raeburn 9062: sub get_institutional_codes {
9063: my ($settings,$allcourses,$LC_code) = @_;
9064: # Get complete list of course sections to update
9065: my @currsections = ();
9066: my @currxlists = ();
9067: my $coursecode = $$settings{'internal.coursecode'};
9068:
9069: if ($$settings{'internal.sectionnums'} ne '') {
9070: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9071: }
9072:
9073: if ($$settings{'internal.crosslistings'} ne '') {
9074: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9075: }
9076:
9077: if (@currxlists > 0) {
9078: foreach (@currxlists) {
9079: if (m/^([^:]+):(\w*)$/) {
9080: unless (grep/^$1$/,@{$allcourses}) {
9081: push @{$allcourses},$1;
9082: $$LC_code{$1} = $2;
9083: }
9084: }
9085: }
9086: }
9087:
9088: if (@currsections > 0) {
9089: foreach (@currsections) {
9090: if (m/^(\w+):(\w*)$/) {
9091: my $sec = $coursecode.$1;
9092: my $lc_sec = $2;
9093: unless (grep/^$sec$/,@{$allcourses}) {
9094: push @{$allcourses},$sec;
9095: $$LC_code{$sec} = $lc_sec;
9096: }
9097: }
9098: }
9099: }
9100: return;
9101: }
9102:
1.971 raeburn 9103: sub get_standard_codeitems {
9104: return ('Year','Semester','Department','Number','Section');
9105: }
9106:
1.112 bowersj2 9107: =pod
9108:
1.780 raeburn 9109: =head1 Slot Helpers
9110:
9111: =over 4
9112:
9113: =item * sorted_slots()
9114:
1.1040 raeburn 9115: Sorts an array of slot names in order of an optional sort key,
9116: default sort is by slot start time (earliest first).
1.780 raeburn 9117:
9118: Inputs:
9119:
9120: =over 4
9121:
9122: slotsarr - Reference to array of unsorted slot names.
9123:
9124: slots - Reference to hash of hash, where outer hash keys are slot names.
9125:
1.1040 raeburn 9126: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9127:
1.549 albertel 9128: =back
9129:
1.780 raeburn 9130: Returns:
9131:
9132: =over 4
9133:
1.1040 raeburn 9134: sorted - An array of slot names sorted by a specified sort key
9135: (default sort key is start time of the slot).
1.780 raeburn 9136:
9137: =back
9138:
9139: =cut
9140:
9141:
9142: sub sorted_slots {
1.1040 raeburn 9143: my ($slotsarr,$slots,$sortkey) = @_;
9144: if ($sortkey eq '') {
9145: $sortkey = 'starttime';
9146: }
1.780 raeburn 9147: my @sorted;
9148: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9149: @sorted =
9150: sort {
9151: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9152: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9153: }
9154: if (ref($slots->{$a})) { return -1;}
9155: if (ref($slots->{$b})) { return 1;}
9156: return 0;
9157: } @{$slotsarr};
9158: }
9159: return @sorted;
9160: }
9161:
1.1040 raeburn 9162: =pod
9163:
9164: =item * get_future_slots()
9165:
9166: Inputs:
9167:
9168: =over 4
9169:
9170: cnum - course number
9171:
9172: cdom - course domain
9173:
9174: now - current UNIX time
9175:
9176: symb - optional symb
9177:
9178: =back
9179:
9180: Returns:
9181:
9182: =over 4
9183:
9184: sorted_reservable - ref to array of student_schedulable slots currently
9185: reservable, ordered by end date of reservation period.
9186:
9187: reservable_now - ref to hash of student_schedulable slots currently
9188: reservable.
9189:
9190: Keys in inner hash are:
9191: (a) symb: either blank or symb to which slot use is restricted.
9192: (b) endreserve: end date of reservation period.
9193:
9194: sorted_future - ref to array of student_schedulable slots reservable in
9195: the future, ordered by start date of reservation period.
9196:
9197: future_reservable - ref to hash of student_schedulable slots reservable
9198: in the future.
9199:
9200: Keys in inner hash are:
9201: (a) symb: either blank or symb to which slot use is restricted.
9202: (b) startreserve: start date of reservation period.
9203:
9204: =back
9205:
9206: =cut
9207:
9208: sub get_future_slots {
9209: my ($cnum,$cdom,$now,$symb) = @_;
9210: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9211: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9212: foreach my $slot (keys(%slots)) {
9213: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9214: if ($symb) {
9215: next if (($slots{$slot}->{'symb'} ne '') &&
9216: ($slots{$slot}->{'symb'} ne $symb));
9217: }
9218: if (($slots{$slot}->{'starttime'} > $now) &&
9219: ($slots{$slot}->{'endtime'} > $now)) {
9220: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9221: my $userallowed = 0;
9222: if ($slots{$slot}->{'allowedsections'}) {
9223: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9224: if (!defined($env{'request.role.sec'})
9225: && grep(/^No section assigned$/,@allowed_sec)) {
9226: $userallowed=1;
9227: } else {
9228: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9229: $userallowed=1;
9230: }
9231: }
9232: unless ($userallowed) {
9233: if (defined($env{'request.course.groups'})) {
9234: my @groups = split(/:/,$env{'request.course.groups'});
9235: foreach my $group (@groups) {
9236: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9237: $userallowed=1;
9238: last;
9239: }
9240: }
9241: }
9242: }
9243: }
9244: if ($slots{$slot}->{'allowedusers'}) {
9245: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9246: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9247: if (grep(/^\Q$user\E$/,@allowed_users)) {
9248: $userallowed = 1;
9249: }
9250: }
9251: next unless($userallowed);
9252: }
9253: my $startreserve = $slots{$slot}->{'startreserve'};
9254: my $endreserve = $slots{$slot}->{'endreserve'};
9255: my $symb = $slots{$slot}->{'symb'};
9256: if (($startreserve < $now) &&
9257: (!$endreserve || $endreserve > $now)) {
9258: my $lastres = $endreserve;
9259: if (!$lastres) {
9260: $lastres = $slots{$slot}->{'starttime'};
9261: }
9262: $reservable_now{$slot} = {
9263: symb => $symb,
9264: endreserve => $lastres
9265: };
9266: } elsif (($startreserve > $now) &&
9267: (!$endreserve || $endreserve > $startreserve)) {
9268: $future_reservable{$slot} = {
9269: symb => $symb,
9270: startreserve => $startreserve
9271: };
9272: }
9273: }
9274: }
9275: my @unsorted_reservable = keys(%reservable_now);
9276: if (@unsorted_reservable > 0) {
9277: @sorted_reservable =
9278: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9279: }
9280: my @unsorted_future = keys(%future_reservable);
9281: if (@unsorted_future > 0) {
9282: @sorted_future =
9283: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9284: }
9285: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9286: }
1.780 raeburn 9287:
9288: =pod
9289:
1.1057 foxr 9290: =back
9291:
1.549 albertel 9292: =head1 HTTP Helpers
9293:
9294: =over 4
9295:
1.648 raeburn 9296: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9297:
1.258 albertel 9298: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9299: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9300: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9301:
9302: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9303: $possible_names is an ref to an array of form element names. As an example:
9304: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9305: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9306:
9307: =cut
1.1 albertel 9308:
1.6 albertel 9309: sub get_unprocessed_cgi {
1.25 albertel 9310: my ($query,$possible_names)= @_;
1.26 matthew 9311: # $Apache::lonxml::debug=1;
1.356 albertel 9312: foreach my $pair (split(/&/,$query)) {
9313: my ($name, $value) = split(/=/,$pair);
1.369 www 9314: $name = &unescape($name);
1.25 albertel 9315: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9316: $value =~ tr/+/ /;
9317: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9318: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9319: }
1.16 harris41 9320: }
1.6 albertel 9321: }
9322:
1.112 bowersj2 9323: =pod
9324:
1.648 raeburn 9325: =item * &cacheheader()
1.112 bowersj2 9326:
9327: returns cache-controlling header code
9328:
9329: =cut
9330:
1.7 albertel 9331: sub cacheheader {
1.258 albertel 9332: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9333: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9334: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9335: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9336: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9337: return $output;
1.7 albertel 9338: }
9339:
1.112 bowersj2 9340: =pod
9341:
1.648 raeburn 9342: =item * &no_cache($r)
1.112 bowersj2 9343:
9344: specifies header code to not have cache
9345:
9346: =cut
9347:
1.9 albertel 9348: sub no_cache {
1.216 albertel 9349: my ($r) = @_;
9350: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9351: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9352: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9353: $r->no_cache(1);
9354: $r->header_out("Expires" => $date);
9355: $r->header_out("Pragma" => "no-cache");
1.123 www 9356: }
9357:
9358: sub content_type {
1.181 albertel 9359: my ($r,$type,$charset) = @_;
1.299 foxr 9360: if ($r) {
9361: # Note that printout.pl calls this with undef for $r.
9362: &no_cache($r);
9363: }
1.258 albertel 9364: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9365: unless ($charset) {
9366: $charset=&Apache::lonlocal::current_encoding;
9367: }
9368: if ($charset) { $type.='; charset='.$charset; }
9369: if ($r) {
9370: $r->content_type($type);
9371: } else {
9372: print("Content-type: $type\n\n");
9373: }
1.9 albertel 9374: }
1.25 albertel 9375:
1.112 bowersj2 9376: =pod
9377:
1.648 raeburn 9378: =item * &add_to_env($name,$value)
1.112 bowersj2 9379:
1.258 albertel 9380: adds $name to the %env hash with value
1.112 bowersj2 9381: $value, if $name already exists, the entry is converted to an array
9382: reference and $value is added to the array.
9383:
9384: =cut
9385:
1.25 albertel 9386: sub add_to_env {
9387: my ($name,$value)=@_;
1.258 albertel 9388: if (defined($env{$name})) {
9389: if (ref($env{$name})) {
1.25 albertel 9390: #already have multiple values
1.258 albertel 9391: push(@{ $env{$name} },$value);
1.25 albertel 9392: } else {
9393: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9394: my $first=$env{$name};
9395: undef($env{$name});
9396: push(@{ $env{$name} },$first,$value);
1.25 albertel 9397: }
9398: } else {
1.258 albertel 9399: $env{$name}=$value;
1.25 albertel 9400: }
1.31 albertel 9401: }
1.149 albertel 9402:
9403: =pod
9404:
1.648 raeburn 9405: =item * &get_env_multiple($name)
1.149 albertel 9406:
1.258 albertel 9407: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9408: values may be defined and end up as an array ref.
9409:
9410: returns an array of values
9411:
9412: =cut
9413:
9414: sub get_env_multiple {
9415: my ($name) = @_;
9416: my @values;
1.258 albertel 9417: if (defined($env{$name})) {
1.149 albertel 9418: # exists is it an array
1.258 albertel 9419: if (ref($env{$name})) {
9420: @values=@{ $env{$name} };
1.149 albertel 9421: } else {
1.258 albertel 9422: $values[0]=$env{$name};
1.149 albertel 9423: }
9424: }
9425: return(@values);
9426: }
9427:
1.660 raeburn 9428: sub ask_for_embedded_content {
9429: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9430: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9431: %currsubfile,%unused,$rem);
1.1071 raeburn 9432: my $counter = 0;
9433: my $numnew = 0;
1.987 raeburn 9434: my $numremref = 0;
9435: my $numinvalid = 0;
9436: my $numpathchg = 0;
9437: my $numexisting = 0;
1.1071 raeburn 9438: my $numunused = 0;
9439: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9440: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9441: my $heading = &mt('Upload embedded files');
9442: my $buttontext = &mt('Upload');
9443:
1.1075.2.11 raeburn 9444: my $navmap;
9445: if ($env{'request.course.id'}) {
9446: $navmap = Apache::lonnavmaps::navmap->new();
9447: }
1.984 raeburn 9448: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9449: my $current_path='/';
9450: if ($env{'form.currentpath'}) {
9451: $current_path = $env{'form.currentpath'};
9452: }
9453: if ($actionurl eq '/adm/coursegrp_portfolio') {
9454: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9455: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
9456: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9457: } else {
9458: $udom = $env{'user.domain'};
9459: $uname = $env{'user.name'};
9460: $url = '/userfiles/portfolio';
9461: }
1.987 raeburn 9462: $toplevel = $url.'/';
1.984 raeburn 9463: $url .= $current_path;
9464: $getpropath = 1;
1.987 raeburn 9465: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9466: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9467: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9468: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9469: $toplevel = $url;
1.984 raeburn 9470: if ($rest ne '') {
1.987 raeburn 9471: $url .= $rest;
9472: }
9473: } elsif ($actionurl eq '/adm/coursedocs') {
9474: if (ref($args) eq 'HASH') {
1.1071 raeburn 9475: $url = $args->{'docs_url'};
9476: $toplevel = $url;
1.1075.2.11 raeburn 9477: if ($args->{'context'} eq 'paste') {
9478: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9479: ($path) =
9480: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9481: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9482: $fileloc =~ s{^/}{};
9483: }
1.1071 raeburn 9484: }
9485: } elsif ($actionurl eq '/adm/dependencies') {
9486: if ($env{'request.course.id'} ne '') {
9487: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9488: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9489: if (ref($args) eq 'HASH') {
9490: $url = $args->{'docs_url'};
9491: $title = $args->{'docs_title'};
9492: $toplevel = "/$url";
1.1075.2.11 raeburn 9493: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071 raeburn 9494: ($path) =
9495: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9496: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9497: $fileloc =~ s{^/}{};
9498: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9499: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9500: }
1.987 raeburn 9501: }
9502: }
9503: my $now = time();
9504: foreach my $embed_file (keys(%{$allfiles})) {
9505: my $absolutepath;
9506: if ($embed_file =~ m{^\w+://}) {
9507: $newfiles{$embed_file} = 1;
9508: $mapping{$embed_file} = $embed_file;
9509: } else {
9510: if ($embed_file =~ m{^/}) {
9511: $absolutepath = $embed_file;
9512: $embed_file =~ s{^(/+)}{};
9513: }
9514: if ($embed_file =~ m{/}) {
9515: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9516: $path = &check_for_traversal($path,$url,$toplevel);
9517: my $item = $fname;
9518: if ($path ne '') {
9519: $item = $path.'/'.$fname;
9520: $subdependencies{$path}{$fname} = 1;
9521: } else {
9522: $dependencies{$item} = 1;
9523: }
9524: if ($absolutepath) {
9525: $mapping{$item} = $absolutepath;
9526: } else {
9527: $mapping{$item} = $embed_file;
9528: }
9529: } else {
9530: $dependencies{$embed_file} = 1;
9531: if ($absolutepath) {
9532: $mapping{$embed_file} = $absolutepath;
9533: } else {
9534: $mapping{$embed_file} = $embed_file;
9535: }
9536: }
1.984 raeburn 9537: }
9538: }
1.1071 raeburn 9539: my $dirptr = 16384;
1.984 raeburn 9540: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9541: $currsubfile{$path} = {};
1.984 raeburn 9542: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9543: my ($sublistref,$listerror) =
9544: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9545: if (ref($sublistref) eq 'ARRAY') {
9546: foreach my $line (@{$sublistref}) {
9547: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9548: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9549: }
1.984 raeburn 9550: }
1.987 raeburn 9551: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9552: if (opendir(my $dir,$url.'/'.$path)) {
9553: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9554: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9555: }
1.1075.2.11 raeburn 9556: } elsif (($actionurl eq '/adm/dependencies') ||
9557: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9558: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9559: if ($env{'request.course.id'} ne '') {
9560: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9561: if ($dir ne '') {
9562: my ($sublistref,$listerror) =
9563: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9564: if (ref($sublistref) eq 'ARRAY') {
9565: foreach my $line (@{$sublistref}) {
9566: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9567: undef,$mtime)=split(/\&/,$line,12);
9568: unless (($testdir&$dirptr) ||
9569: ($file_name =~ /^\.\.?$/)) {
9570: $currsubfile{$path}{$file_name} = [$size,$mtime];
9571: }
9572: }
9573: }
9574: }
1.984 raeburn 9575: }
9576: }
9577: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9578: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9579: my $item = $path.'/'.$file;
9580: unless ($mapping{$item} eq $item) {
9581: $pathchanges{$item} = 1;
9582: }
9583: $existing{$item} = 1;
9584: $numexisting ++;
9585: } else {
9586: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9587: }
9588: }
1.1071 raeburn 9589: if ($actionurl eq '/adm/dependencies') {
9590: foreach my $path (keys(%currsubfile)) {
9591: if (ref($currsubfile{$path}) eq 'HASH') {
9592: foreach my $file (keys(%{$currsubfile{$path}})) {
9593: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9594: next if (($rem ne '') &&
9595: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9596: (ref($navmap) &&
9597: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9598: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9599: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9600: $unused{$path.'/'.$file} = 1;
9601: }
9602: }
9603: }
9604: }
9605: }
1.984 raeburn 9606: }
1.987 raeburn 9607: my %currfile;
1.984 raeburn 9608: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9609: my ($dirlistref,$listerror) =
9610: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9611: if (ref($dirlistref) eq 'ARRAY') {
9612: foreach my $line (@{$dirlistref}) {
9613: my ($file_name,$rest) = split(/\&/,$line,2);
9614: $currfile{$file_name} = 1;
9615: }
1.984 raeburn 9616: }
1.987 raeburn 9617: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9618: if (opendir(my $dir,$url)) {
1.987 raeburn 9619: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9620: map {$currfile{$_} = 1;} @dir_list;
9621: }
1.1075.2.11 raeburn 9622: } elsif (($actionurl eq '/adm/dependencies') ||
9623: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9624: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9625: if ($env{'request.course.id'} ne '') {
9626: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9627: if ($dir ne '') {
9628: my ($dirlistref,$listerror) =
9629: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9630: if (ref($dirlistref) eq 'ARRAY') {
9631: foreach my $line (@{$dirlistref}) {
9632: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9633: $size,undef,$mtime)=split(/\&/,$line,12);
9634: unless (($testdir&$dirptr) ||
9635: ($file_name =~ /^\.\.?$/)) {
9636: $currfile{$file_name} = [$size,$mtime];
9637: }
9638: }
9639: }
9640: }
9641: }
1.984 raeburn 9642: }
9643: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9644: if (exists($currfile{$file})) {
1.987 raeburn 9645: unless ($mapping{$file} eq $file) {
9646: $pathchanges{$file} = 1;
9647: }
9648: $existing{$file} = 1;
9649: $numexisting ++;
9650: } else {
1.984 raeburn 9651: $newfiles{$file} = 1;
9652: }
9653: }
1.1071 raeburn 9654: foreach my $file (keys(%currfile)) {
9655: unless (($file eq $filename) ||
9656: ($file eq $filename.'.bak') ||
9657: ($dependencies{$file})) {
1.1075.2.11 raeburn 9658: if ($actionurl eq '/adm/dependencies') {
9659: next if (($rem ne '') &&
9660: (($env{"httpref.$rem".$file} ne '') ||
9661: (ref($navmap) &&
9662: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9663: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9664: ($navmap->getResourceByUrl($rem.$1)))))));
9665: }
1.1071 raeburn 9666: $unused{$file} = 1;
9667: }
9668: }
1.1075.2.11 raeburn 9669: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9670: ($args->{'context'} eq 'paste')) {
9671: $counter = scalar(keys(%existing));
9672: $numpathchg = scalar(keys(%pathchanges));
9673: return ($output,$counter,$numpathchg,\%existing);
9674: }
1.984 raeburn 9675: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 9676: if ($actionurl eq '/adm/dependencies') {
9677: next if ($embed_file =~ m{^\w+://});
9678: }
1.660 raeburn 9679: $upload_output .= &start_data_table_row().
1.1071 raeburn 9680: '<td><img src="'.&icon($embed_file).'" /> '.
9681: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 9682: unless ($mapping{$embed_file} eq $embed_file) {
9683: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
9684: }
9685: $upload_output .= '</td><td>';
1.1071 raeburn 9686: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.660 raeburn 9687: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 9688: $numremref++;
1.660 raeburn 9689: } elsif ($args->{'error_on_invalid_names'}
9690: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987 raeburn 9691: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
9692: $numinvalid++;
1.660 raeburn 9693: } else {
1.1071 raeburn 9694: $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 9695: $embed_file,\%mapping,
1.1071 raeburn 9696: $allfiles,$codebase,'upload');
9697: $counter ++;
9698: $numnew ++;
1.987 raeburn 9699: }
9700: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
9701: }
9702: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 9703: if ($actionurl eq '/adm/dependencies') {
9704: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
9705: $modify_output .= &start_data_table_row().
9706: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
9707: '<img src="'.&icon($embed_file).'" border="0" />'.
9708: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
9709: '<td>'.$size.'</td>'.
9710: '<td>'.$mtime.'</td>'.
9711: '<td><label><input type="checkbox" name="mod_upload_dep" '.
9712: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
9713: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
9714: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
9715: &embedded_file_element('upload_embedded',$counter,
9716: $embed_file,\%mapping,
9717: $allfiles,$codebase,'modify').
9718: '</div></td>'.
9719: &end_data_table_row()."\n";
9720: $counter ++;
9721: } else {
9722: $upload_output .= &start_data_table_row().
9723: '<td><span class="LC_filename">'.$embed_file.'</span></td>';
9724: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
9725: &Apache::loncommon::end_data_table_row()."\n";
9726: }
9727: }
9728: my $delidx = $counter;
9729: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
9730: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
9731: $delete_output .= &start_data_table_row().
9732: '<td><img src="'.&icon($oldfile).'" />'.
9733: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
9734: '<td>'.$size.'</td>'.
9735: '<td>'.$mtime.'</td>'.
9736: '<td><label><input type="checkbox" name="del_upload_dep" '.
9737: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
9738: &embedded_file_element('upload_embedded',$delidx,
9739: $oldfile,\%mapping,$allfiles,
9740: $codebase,'delete').'</td>'.
9741: &end_data_table_row()."\n";
9742: $numunused ++;
9743: $delidx ++;
1.987 raeburn 9744: }
9745: if ($upload_output) {
9746: $upload_output = &start_data_table().
9747: $upload_output.
9748: &end_data_table()."\n";
9749: }
1.1071 raeburn 9750: if ($modify_output) {
9751: $modify_output = &start_data_table().
9752: &start_data_table_header_row().
9753: '<th>'.&mt('File').'</th>'.
9754: '<th>'.&mt('Size (KB)').'</th>'.
9755: '<th>'.&mt('Modified').'</th>'.
9756: '<th>'.&mt('Upload replacement?').'</th>'.
9757: &end_data_table_header_row().
9758: $modify_output.
9759: &end_data_table()."\n";
9760: }
9761: if ($delete_output) {
9762: $delete_output = &start_data_table().
9763: &start_data_table_header_row().
9764: '<th>'.&mt('File').'</th>'.
9765: '<th>'.&mt('Size (KB)').'</th>'.
9766: '<th>'.&mt('Modified').'</th>'.
9767: '<th>'.&mt('Delete?').'</th>'.
9768: &end_data_table_header_row().
9769: $delete_output.
9770: &end_data_table()."\n";
9771: }
1.987 raeburn 9772: my $applies = 0;
9773: if ($numremref) {
9774: $applies ++;
9775: }
9776: if ($numinvalid) {
9777: $applies ++;
9778: }
9779: if ($numexisting) {
9780: $applies ++;
9781: }
1.1071 raeburn 9782: if ($counter || $numunused) {
1.987 raeburn 9783: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
9784: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 9785: $state.'<h3>'.$heading.'</h3>';
9786: if ($actionurl eq '/adm/dependencies') {
9787: if ($numnew) {
9788: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
9789: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
9790: $upload_output.'<br />'."\n";
9791: }
9792: if ($numexisting) {
9793: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
9794: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
9795: $modify_output.'<br />'."\n";
9796: $buttontext = &mt('Save changes');
9797: }
9798: if ($numunused) {
9799: $output .= '<h4>'.&mt('Unused files').'</h4>'.
9800: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
9801: $delete_output.'<br />'."\n";
9802: $buttontext = &mt('Save changes');
9803: }
9804: } else {
9805: $output .= $upload_output.'<br />'."\n";
9806: }
9807: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
9808: $counter.'" />'."\n";
9809: if ($actionurl eq '/adm/dependencies') {
9810: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
9811: $numnew.'" />'."\n";
9812: } elsif ($actionurl eq '') {
1.987 raeburn 9813: $output .= '<input type="hidden" name="phase" value="three" />';
9814: }
9815: } elsif ($applies) {
9816: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
9817: if ($applies > 1) {
9818: $output .=
9819: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
9820: if ($numremref) {
9821: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
9822: }
9823: if ($numinvalid) {
9824: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
9825: }
9826: if ($numexisting) {
9827: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
9828: }
9829: $output .= '</ul><br />';
9830: } elsif ($numremref) {
9831: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
9832: } elsif ($numinvalid) {
9833: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
9834: } elsif ($numexisting) {
9835: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
9836: }
9837: $output .= $upload_output.'<br />';
9838: }
9839: my ($pathchange_output,$chgcount);
1.1071 raeburn 9840: $chgcount = $counter;
1.987 raeburn 9841: if (keys(%pathchanges) > 0) {
9842: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 9843: if ($counter) {
1.987 raeburn 9844: $output .= &embedded_file_element('pathchange',$chgcount,
9845: $embed_file,\%mapping,
1.1071 raeburn 9846: $allfiles,$codebase,'change');
1.987 raeburn 9847: } else {
9848: $pathchange_output .=
9849: &start_data_table_row().
9850: '<td><input type ="checkbox" name="namechange" value="'.
9851: $chgcount.'" checked="checked" /></td>'.
9852: '<td>'.$mapping{$embed_file}.'</td>'.
9853: '<td>'.$embed_file.
9854: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 9855: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 9856: '</td>'.&end_data_table_row();
1.660 raeburn 9857: }
1.987 raeburn 9858: $numpathchg ++;
9859: $chgcount ++;
1.660 raeburn 9860: }
9861: }
1.1071 raeburn 9862: if ($counter) {
1.987 raeburn 9863: if ($numpathchg) {
9864: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
9865: $numpathchg.'" />'."\n";
9866: }
9867: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9868: ($actionurl eq '/adm/imsimport')) {
9869: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
9870: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
9871: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 9872: } elsif ($actionurl eq '/adm/dependencies') {
9873: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 9874: }
1.1071 raeburn 9875: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 9876: } elsif ($numpathchg) {
9877: my %pathchange = ();
9878: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
9879: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9880: $output .= '<p>'.&mt('or').'</p>';
9881: }
9882: }
1.1071 raeburn 9883: return ($output,$counter,$numpathchg);
1.987 raeburn 9884: }
9885:
9886: sub embedded_file_element {
1.1071 raeburn 9887: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 9888: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
9889: (ref($codebase) eq 'HASH'));
9890: my $output;
1.1071 raeburn 9891: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 9892: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
9893: }
9894: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
9895: &escape($embed_file).'" />';
9896: unless (($context eq 'upload_embedded') &&
9897: ($mapping->{$embed_file} eq $embed_file)) {
9898: $output .='
9899: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
9900: }
9901: my $attrib;
9902: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
9903: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
9904: }
9905: $output .=
9906: "\n\t\t".
9907: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
9908: $attrib.'" />';
9909: if (exists($codebase->{$mapping->{$embed_file}})) {
9910: $output .=
9911: "\n\t\t".
9912: '<input name="codebase_'.$num.'" type="hidden" value="'.
9913: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 9914: }
1.987 raeburn 9915: return $output;
1.660 raeburn 9916: }
9917:
1.1071 raeburn 9918: sub get_dependency_details {
9919: my ($currfile,$currsubfile,$embed_file) = @_;
9920: my ($size,$mtime,$showsize,$showmtime);
9921: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
9922: if ($embed_file =~ m{/}) {
9923: my ($path,$fname) = split(/\//,$embed_file);
9924: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
9925: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
9926: }
9927: } else {
9928: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
9929: ($size,$mtime) = @{$currfile->{$embed_file}};
9930: }
9931: }
9932: $showsize = $size/1024.0;
9933: $showsize = sprintf("%.1f",$showsize);
9934: if ($mtime > 0) {
9935: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
9936: }
9937: }
9938: return ($showsize,$showmtime);
9939: }
9940:
9941: sub ask_embedded_js {
9942: return <<"END";
9943: <script type="text/javascript"">
9944: // <![CDATA[
9945: function toggleBrowse(counter) {
9946: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
9947: var fileid = document.getElementById('embedded_item_'+counter);
9948: var uploaddivid = document.getElementById('moduploaddep_'+counter);
9949: if (chkboxid.checked == true) {
9950: uploaddivid.style.display='block';
9951: } else {
9952: uploaddivid.style.display='none';
9953: fileid.value = '';
9954: }
9955: }
9956: // ]]>
9957: </script>
9958:
9959: END
9960: }
9961:
1.661 raeburn 9962: sub upload_embedded {
9963: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 9964: $current_disk_usage,$hiddenstate,$actionurl) = @_;
9965: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 9966: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
9967: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
9968: my $orig_uploaded_filename =
9969: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 9970: foreach my $type ('orig','ref','attrib','codebase') {
9971: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
9972: $env{'form.embedded_'.$type.'_'.$i} =
9973: &unescape($env{'form.embedded_'.$type.'_'.$i});
9974: }
9975: }
1.661 raeburn 9976: my ($path,$fname) =
9977: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
9978: # no path, whole string is fname
9979: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
9980: $fname = &Apache::lonnet::clean_filename($fname);
9981: # See if there is anything left
9982: next if ($fname eq '');
9983:
9984: # Check if file already exists as a file or directory.
9985: my ($state,$msg);
9986: if ($context eq 'portfolio') {
9987: my $port_path = $dirpath;
9988: if ($group ne '') {
9989: $port_path = "groups/$group/$port_path";
9990: }
1.987 raeburn 9991: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
9992: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 9993: $dir_root,$port_path,$disk_quota,
9994: $current_disk_usage,$uname,$udom);
9995: if ($state eq 'will_exceed_quota'
1.984 raeburn 9996: || $state eq 'file_locked') {
1.661 raeburn 9997: $output .= $msg;
9998: next;
9999: }
10000: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10001: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10002: if ($state eq 'exists') {
10003: $output .= $msg;
10004: next;
10005: }
10006: }
10007: # Check if extension is valid
10008: if (($fname =~ /\.(\w+)$/) &&
10009: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10010: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 10011: next;
10012: } elsif (($fname =~ /\.(\w+)$/) &&
10013: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10014: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10015: next;
10016: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 10017: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10018: next;
10019: }
10020: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
10021: if ($context eq 'portfolio') {
1.984 raeburn 10022: my $result;
10023: if ($state eq 'existingfile') {
10024: $result=
10025: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 10026: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 10027: } else {
1.984 raeburn 10028: $result=
10029: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10030: $dirpath.
10031: $env{'form.currentpath'}.$path);
1.984 raeburn 10032: if ($result !~ m|^/uploaded/|) {
10033: $output .= '<span class="LC_error">'
10034: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10035: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10036: .'</span><br />';
10037: next;
10038: } else {
1.987 raeburn 10039: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10040: $path.$fname.'</span>').'<br />';
1.984 raeburn 10041: }
1.661 raeburn 10042: }
1.987 raeburn 10043: } elsif ($context eq 'coursedoc') {
10044: my $result =
10045: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
10046: $dirpath.'/'.$path);
10047: if ($result !~ m|^/uploaded/|) {
10048: $output .= '<span class="LC_error">'
10049: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10050: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10051: .'</span><br />';
10052: next;
10053: } else {
10054: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10055: $path.$fname.'</span>').'<br />';
10056: }
1.661 raeburn 10057: } else {
10058: # Save the file
10059: my $target = $env{'form.embedded_item_'.$i};
10060: my $fullpath = $dir_root.$dirpath.'/'.$path;
10061: my $dest = $fullpath.$fname;
10062: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10063: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10064: my $count;
10065: my $filepath = $dir_root;
1.1027 raeburn 10066: foreach my $subdir (@parts) {
10067: $filepath .= "/$subdir";
10068: if (!-e $filepath) {
1.661 raeburn 10069: mkdir($filepath,0770);
10070: }
10071: }
10072: my $fh;
10073: if (!open($fh,'>'.$dest)) {
10074: &Apache::lonnet::logthis('Failed to create '.$dest);
10075: $output .= '<span class="LC_error">'.
1.1071 raeburn 10076: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10077: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10078: '</span><br />';
10079: } else {
10080: if (!print $fh $env{'form.embedded_item_'.$i}) {
10081: &Apache::lonnet::logthis('Failed to write to '.$dest);
10082: $output .= '<span class="LC_error">'.
1.1071 raeburn 10083: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10084: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10085: '</span><br />';
10086: } else {
1.987 raeburn 10087: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10088: $url.'</span>').'<br />';
10089: unless ($context eq 'testbank') {
10090: $footer .= &mt('View embedded file: [_1]',
10091: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10092: }
10093: }
10094: close($fh);
10095: }
10096: }
10097: if ($env{'form.embedded_ref_'.$i}) {
10098: $pathchange{$i} = 1;
10099: }
10100: }
10101: if ($output) {
10102: $output = '<p>'.$output.'</p>';
10103: }
10104: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10105: $returnflag = 'ok';
1.1071 raeburn 10106: my $numpathchgs = scalar(keys(%pathchange));
10107: if ($numpathchgs > 0) {
1.987 raeburn 10108: if ($context eq 'portfolio') {
10109: $output .= '<p>'.&mt('or').'</p>';
10110: } elsif ($context eq 'testbank') {
1.1071 raeburn 10111: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10112: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10113: $returnflag = 'modify_orightml';
10114: }
10115: }
1.1071 raeburn 10116: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10117: }
10118:
10119: sub modify_html_form {
10120: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10121: my $end = 0;
10122: my $modifyform;
10123: if ($context eq 'upload_embedded') {
10124: return unless (ref($pathchange) eq 'HASH');
10125: if ($env{'form.number_embedded_items'}) {
10126: $end += $env{'form.number_embedded_items'};
10127: }
10128: if ($env{'form.number_pathchange_items'}) {
10129: $end += $env{'form.number_pathchange_items'};
10130: }
10131: if ($end) {
10132: for (my $i=0; $i<$end; $i++) {
10133: if ($i < $env{'form.number_embedded_items'}) {
10134: next unless($pathchange->{$i});
10135: }
10136: $modifyform .=
10137: &start_data_table_row().
10138: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10139: 'checked="checked" /></td>'.
10140: '<td>'.$env{'form.embedded_ref_'.$i}.
10141: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10142: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10143: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10144: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10145: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10146: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10147: '<td>'.$env{'form.embedded_orig_'.$i}.
10148: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10149: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10150: &end_data_table_row();
1.1071 raeburn 10151: }
1.987 raeburn 10152: }
10153: } else {
10154: $modifyform = $pathchgtable;
10155: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10156: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10157: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10158: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10159: }
10160: }
10161: if ($modifyform) {
1.1071 raeburn 10162: if ($actionurl eq '/adm/dependencies') {
10163: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10164: }
1.987 raeburn 10165: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10166: '<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".
10167: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10168: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10169: '</ol></p>'."\n".'<p>'.
10170: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10171: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10172: &start_data_table()."\n".
10173: &start_data_table_header_row().
10174: '<th>'.&mt('Change?').'</th>'.
10175: '<th>'.&mt('Current reference').'</th>'.
10176: '<th>'.&mt('Required reference').'</th>'.
10177: &end_data_table_header_row()."\n".
10178: $modifyform.
10179: &end_data_table().'<br />'."\n".$hiddenstate.
10180: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10181: '</form>'."\n";
10182: }
10183: return;
10184: }
10185:
10186: sub modify_html_refs {
10187: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
10188: my $container;
10189: if ($context eq 'portfolio') {
10190: $container = $env{'form.container'};
10191: } elsif ($context eq 'coursedoc') {
10192: $container = $env{'form.primaryurl'};
1.1071 raeburn 10193: } elsif ($context eq 'manage_dependencies') {
10194: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10195: $container = "/$container";
1.987 raeburn 10196: } else {
1.1027 raeburn 10197: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10198: }
10199: my (%allfiles,%codebase,$output,$content);
10200: my @changes = &get_env_multiple('form.namechange');
1.1071 raeburn 10201: unless (@changes > 0) {
10202: if (wantarray) {
10203: return ('',0,0);
10204: } else {
10205: return;
10206: }
10207: }
10208: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10209: ($context eq 'manage_dependencies')) {
10210: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10211: if (wantarray) {
10212: return ('',0,0);
10213: } else {
10214: return;
10215: }
10216: }
1.987 raeburn 10217: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10218: if ($content eq '-1') {
10219: if (wantarray) {
10220: return ('',0,0);
10221: } else {
10222: return;
10223: }
10224: }
1.987 raeburn 10225: } else {
1.1071 raeburn 10226: unless ($container =~ /^\Q$dir_root\E/) {
10227: if (wantarray) {
10228: return ('',0,0);
10229: } else {
10230: return;
10231: }
10232: }
1.987 raeburn 10233: if (open(my $fh,"<$container")) {
10234: $content = join('', <$fh>);
10235: close($fh);
10236: } else {
1.1071 raeburn 10237: if (wantarray) {
10238: return ('',0,0);
10239: } else {
10240: return;
10241: }
1.987 raeburn 10242: }
10243: }
10244: my ($count,$codebasecount) = (0,0);
10245: my $mm = new File::MMagic;
10246: my $mime_type = $mm->checktype_contents($content);
10247: if ($mime_type eq 'text/html') {
10248: my $parse_result =
10249: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10250: \%codebase,\$content);
10251: if ($parse_result eq 'ok') {
10252: foreach my $i (@changes) {
10253: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10254: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10255: if ($allfiles{$ref}) {
10256: my $newname = $orig;
10257: my ($attrib_regexp,$codebase);
1.1006 raeburn 10258: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10259: if ($attrib_regexp =~ /:/) {
10260: $attrib_regexp =~ s/\:/|/g;
10261: }
10262: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10263: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10264: $count += $numchg;
10265: }
10266: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10267: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10268: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10269: $codebasecount ++;
10270: }
10271: }
10272: }
10273: if ($count || $codebasecount) {
10274: my $saveresult;
1.1071 raeburn 10275: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10276: ($context eq 'manage_dependencies')) {
1.987 raeburn 10277: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10278: if ($url eq $container) {
10279: my ($fname) = ($container =~ m{/([^/]+)$});
10280: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10281: $count,'<span class="LC_filename">'.
1.1071 raeburn 10282: $fname.'</span>').'</p>';
1.987 raeburn 10283: } else {
10284: $output = '<p class="LC_error">'.
10285: &mt('Error: update failed for: [_1].',
10286: '<span class="LC_filename">'.
10287: $container.'</span>').'</p>';
10288: }
10289: } else {
10290: if (open(my $fh,">$container")) {
10291: print $fh $content;
10292: close($fh);
10293: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10294: $count,'<span class="LC_filename">'.
10295: $container.'</span>').'</p>';
1.661 raeburn 10296: } else {
1.987 raeburn 10297: $output = '<p class="LC_error">'.
10298: &mt('Error: could not update [_1].',
10299: '<span class="LC_filename">'.
10300: $container.'</span>').'</p>';
1.661 raeburn 10301: }
10302: }
10303: }
1.987 raeburn 10304: } else {
10305: &logthis('Failed to parse '.$container.
10306: ' to modify references: '.$parse_result);
1.661 raeburn 10307: }
10308: }
1.1071 raeburn 10309: if (wantarray) {
10310: return ($output,$count,$codebasecount);
10311: } else {
10312: return $output;
10313: }
1.661 raeburn 10314: }
10315:
10316: sub check_for_existing {
10317: my ($path,$fname,$element) = @_;
10318: my ($state,$msg);
10319: if (-d $path.'/'.$fname) {
10320: $state = 'exists';
10321: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10322: } elsif (-e $path.'/'.$fname) {
10323: $state = 'exists';
10324: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10325: }
10326: if ($state eq 'exists') {
10327: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10328: }
10329: return ($state,$msg);
10330: }
10331:
10332: sub check_for_upload {
10333: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10334: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10335: my $filesize = length($env{'form.'.$element});
10336: if (!$filesize) {
10337: my $msg = '<span class="LC_error">'.
10338: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10339: '<span class="LC_filename">'.$fname.'</span>',
10340: $filesize).'<br />'.
1.1007 raeburn 10341: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10342: '</span>';
10343: return ('zero_bytes',$msg);
10344: }
10345: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10346: my $getpropath = 1;
1.1021 raeburn 10347: my ($dirlistref,$listerror) =
10348: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10349: my $found_file = 0;
10350: my $locked_file = 0;
1.991 raeburn 10351: my @lockers;
10352: my $navmap;
10353: if ($env{'request.course.id'}) {
10354: $navmap = Apache::lonnavmaps::navmap->new();
10355: }
1.1021 raeburn 10356: if (ref($dirlistref) eq 'ARRAY') {
10357: foreach my $line (@{$dirlistref}) {
10358: my ($file_name,$rest)=split(/\&/,$line,2);
10359: if ($file_name eq $fname){
10360: $file_name = $path.$file_name;
10361: if ($group ne '') {
10362: $file_name = $group.$file_name;
10363: }
10364: $found_file = 1;
10365: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10366: foreach my $lock (@lockers) {
10367: if (ref($lock) eq 'ARRAY') {
10368: my ($symb,$crsid) = @{$lock};
10369: if ($crsid eq $env{'request.course.id'}) {
10370: if (ref($navmap)) {
10371: my $res = $navmap->getBySymb($symb);
10372: foreach my $part (@{$res->parts()}) {
10373: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10374: unless (($slot_status == $res->RESERVED) ||
10375: ($slot_status == $res->RESERVED_LOCATION)) {
10376: $locked_file = 1;
10377: }
1.991 raeburn 10378: }
1.1021 raeburn 10379: } else {
10380: $locked_file = 1;
1.991 raeburn 10381: }
10382: } else {
10383: $locked_file = 1;
10384: }
10385: }
1.1021 raeburn 10386: }
10387: } else {
10388: my @info = split(/\&/,$rest);
10389: my $currsize = $info[6]/1000;
10390: if ($currsize < $filesize) {
10391: my $extra = $filesize - $currsize;
10392: if (($current_disk_usage + $extra) > $disk_quota) {
10393: my $msg = '<span class="LC_error">'.
10394: &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.',
10395: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10396: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10397: $disk_quota,$current_disk_usage);
10398: return ('will_exceed_quota',$msg);
10399: }
1.984 raeburn 10400: }
10401: }
1.661 raeburn 10402: }
10403: }
10404: }
10405: if (($current_disk_usage + $filesize) > $disk_quota){
10406: my $msg = '<span class="LC_error">'.
10407: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10408: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10409: return ('will_exceed_quota',$msg);
10410: } elsif ($found_file) {
10411: if ($locked_file) {
10412: my $msg = '<span class="LC_error">';
10413: $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>');
10414: $msg .= '</span><br />';
10415: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10416: return ('file_locked',$msg);
10417: } else {
10418: my $msg = '<span class="LC_error">';
1.984 raeburn 10419: $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 10420: $msg .= '</span>';
1.984 raeburn 10421: return ('existingfile',$msg);
1.661 raeburn 10422: }
10423: }
10424: }
10425:
1.987 raeburn 10426: sub check_for_traversal {
10427: my ($path,$url,$toplevel) = @_;
10428: my @parts=split(/\//,$path);
10429: my $cleanpath;
10430: my $fullpath = $url;
10431: for (my $i=0;$i<@parts;$i++) {
10432: next if ($parts[$i] eq '.');
10433: if ($parts[$i] eq '..') {
10434: $fullpath =~ s{([^/]+/)$}{};
10435: } else {
10436: $fullpath .= $parts[$i].'/';
10437: }
10438: }
10439: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10440: $cleanpath = $1;
10441: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10442: my $curr_toprel = $1;
10443: my @parts = split(/\//,$curr_toprel);
10444: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10445: my @urlparts = split(/\//,$url_toprel);
10446: my $doubledots;
10447: my $startdiff = -1;
10448: for (my $i=0; $i<@urlparts; $i++) {
10449: if ($startdiff == -1) {
10450: unless ($urlparts[$i] eq $parts[$i]) {
10451: $startdiff = $i;
10452: $doubledots .= '../';
10453: }
10454: } else {
10455: $doubledots .= '../';
10456: }
10457: }
10458: if ($startdiff > -1) {
10459: $cleanpath = $doubledots;
10460: for (my $i=$startdiff; $i<@parts; $i++) {
10461: $cleanpath .= $parts[$i].'/';
10462: }
10463: }
10464: }
10465: $cleanpath =~ s{(/)$}{};
10466: return $cleanpath;
10467: }
1.31 albertel 10468:
1.1053 raeburn 10469: sub is_archive_file {
10470: my ($mimetype) = @_;
10471: if (($mimetype eq 'application/octet-stream') ||
10472: ($mimetype eq 'application/x-stuffit') ||
10473: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10474: return 1;
10475: }
10476: return;
10477: }
10478:
10479: sub decompress_form {
1.1065 raeburn 10480: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10481: my %lt = &Apache::lonlocal::texthash (
10482: this => 'This file is an archive file.',
1.1067 raeburn 10483: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10484: itsc => 'Its contents are as follows:',
1.1053 raeburn 10485: youm => 'You may wish to extract its contents.',
10486: extr => 'Extract contents',
1.1067 raeburn 10487: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10488: proa => 'Process automatically?',
1.1053 raeburn 10489: yes => 'Yes',
10490: no => 'No',
1.1067 raeburn 10491: fold => 'Title for folder containing movie',
10492: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10493: );
1.1065 raeburn 10494: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10495: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10496: my $info = &list_archive_contents($fileloc,\@paths);
10497: if (@paths) {
10498: foreach my $path (@paths) {
10499: $path =~ s{^/}{};
1.1067 raeburn 10500: if ($path =~ m{^([^/]+)/$}) {
10501: $topdir = $1;
10502: }
1.1065 raeburn 10503: if ($path =~ m{^([^/]+)/}) {
10504: $toplevel{$1} = $path;
10505: } else {
10506: $toplevel{$path} = $path;
10507: }
10508: }
10509: }
1.1067 raeburn 10510: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10511: my @camtasia = ("$topdir/","$topdir/index.html",
10512: "$topdir/media/",
10513: "$topdir/media/$topdir.mp4",
10514: "$topdir/media/FirstFrame.png",
10515: "$topdir/media/player.swf",
10516: "$topdir/media/swfobject.js",
10517: "$topdir/media/expressInstall.swf");
10518: my @diffs = &compare_arrays(\@paths,\@camtasia);
10519: if (@diffs == 0) {
10520: $is_camtasia = 1;
10521: }
10522: }
10523: my $output;
10524: if ($is_camtasia) {
10525: $output = <<"ENDCAM";
10526: <script type="text/javascript" language="Javascript">
10527: // <![CDATA[
10528:
10529: function camtasiaToggle() {
10530: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10531: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10532: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10533:
10534: document.getElementById('camtasia_titles').style.display='block';
10535: } else {
10536: document.getElementById('camtasia_titles').style.display='none';
10537: }
10538: }
10539: }
10540: return;
10541: }
10542:
10543: // ]]>
10544: </script>
10545: <p>$lt{'camt'}</p>
10546: ENDCAM
1.1065 raeburn 10547: } else {
1.1067 raeburn 10548: $output = '<p>'.$lt{'this'};
10549: if ($info eq '') {
10550: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10551: } else {
10552: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10553: '<div><pre>'.$info.'</pre></div>';
10554: }
1.1065 raeburn 10555: }
1.1067 raeburn 10556: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10557: my $duplicates;
10558: my $num = 0;
10559: if (ref($dirlist) eq 'ARRAY') {
10560: foreach my $item (@{$dirlist}) {
10561: if (ref($item) eq 'ARRAY') {
10562: if (exists($toplevel{$item->[0]})) {
10563: $duplicates .=
10564: &start_data_table_row().
10565: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10566: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10567: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10568: 'value="1" />'.&mt('Yes').'</label>'.
10569: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10570: '<td>'.$item->[0].'</td>';
10571: if ($item->[2]) {
10572: $duplicates .= '<td>'.&mt('Directory').'</td>';
10573: } else {
10574: $duplicates .= '<td>'.&mt('File').'</td>';
10575: }
10576: $duplicates .= '<td>'.$item->[3].'</td>'.
10577: '<td>'.
10578: &Apache::lonlocal::locallocaltime($item->[4]).
10579: '</td>'.
10580: &end_data_table_row();
10581: $num ++;
10582: }
10583: }
10584: }
10585: }
10586: my $itemcount;
10587: if (@paths > 0) {
10588: $itemcount = scalar(@paths);
10589: } else {
10590: $itemcount = 1;
10591: }
1.1067 raeburn 10592: if ($is_camtasia) {
10593: $output .= $lt{'auto'}.'<br />'.
10594: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10595: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10596: $lt{'yes'}.'</label> <label>'.
10597: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10598: $lt{'no'}.'</label></span><br />'.
10599: '<div id="camtasia_titles" style="display:block">'.
10600: &Apache::lonhtmlcommon::start_pick_box().
10601: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10602: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10603: &Apache::lonhtmlcommon::row_closure().
10604: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
10605: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
10606: &Apache::lonhtmlcommon::row_closure(1).
10607: &Apache::lonhtmlcommon::end_pick_box().
10608: '</div>';
10609: }
1.1065 raeburn 10610: $output .=
10611: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 10612: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
10613: "\n";
1.1065 raeburn 10614: if ($duplicates ne '') {
10615: $output .= '<p><span class="LC_warning">'.
10616: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
10617: &start_data_table().
10618: &start_data_table_header_row().
10619: '<th>'.&mt('Overwrite?').'</th>'.
10620: '<th>'.&mt('Name').'</th>'.
10621: '<th>'.&mt('Type').'</th>'.
10622: '<th>'.&mt('Size').'</th>'.
10623: '<th>'.&mt('Last modified').'</th>'.
10624: &end_data_table_header_row().
10625: $duplicates.
10626: &end_data_table().
10627: '</p>';
10628: }
1.1067 raeburn 10629: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 10630: if (ref($hiddenelements) eq 'HASH') {
10631: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
10632: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
10633: }
10634: }
10635: $output .= <<"END";
1.1067 raeburn 10636: <br />
1.1053 raeburn 10637: <input type="submit" name="decompress" value="$lt{'extr'}" />
10638: </form>
10639: $noextract
10640: END
10641: return $output;
10642: }
10643:
1.1065 raeburn 10644: sub decompression_utility {
10645: my ($program) = @_;
10646: my @utilities = ('tar','gunzip','bunzip2','unzip');
10647: my $location;
10648: if (grep(/^\Q$program\E$/,@utilities)) {
10649: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
10650: '/usr/sbin/') {
10651: if (-x $dir.$program) {
10652: $location = $dir.$program;
10653: last;
10654: }
10655: }
10656: }
10657: return $location;
10658: }
10659:
10660: sub list_archive_contents {
10661: my ($file,$pathsref) = @_;
10662: my (@cmd,$output);
10663: my $needsregexp;
10664: if ($file =~ /\.zip$/) {
10665: @cmd = (&decompression_utility('unzip'),"-l");
10666: $needsregexp = 1;
10667: } elsif (($file =~ m/\.tar\.gz$/) ||
10668: ($file =~ /\.tgz$/)) {
10669: @cmd = (&decompression_utility('tar'),"-ztf");
10670: } elsif ($file =~ /\.tar\.bz2$/) {
10671: @cmd = (&decompression_utility('tar'),"-jtf");
10672: } elsif ($file =~ m|\.tar$|) {
10673: @cmd = (&decompression_utility('tar'),"-tf");
10674: }
10675: if (@cmd) {
10676: undef($!);
10677: undef($@);
10678: if (open(my $fh,"-|", @cmd, $file)) {
10679: while (my $line = <$fh>) {
10680: $output .= $line;
10681: chomp($line);
10682: my $item;
10683: if ($needsregexp) {
10684: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
10685: } else {
10686: $item = $line;
10687: }
10688: if ($item ne '') {
10689: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
10690: push(@{$pathsref},$item);
10691: }
10692: }
10693: }
10694: close($fh);
10695: }
10696: }
10697: return $output;
10698: }
10699:
1.1053 raeburn 10700: sub decompress_uploaded_file {
10701: my ($file,$dir) = @_;
10702: &Apache::lonnet::appenv({'cgi.file' => $file});
10703: &Apache::lonnet::appenv({'cgi.dir' => $dir});
10704: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
10705: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
10706: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
10707: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
10708: my $decompressed = $env{'cgi.decompressed'};
10709: &Apache::lonnet::delenv('cgi.file');
10710: &Apache::lonnet::delenv('cgi.dir');
10711: &Apache::lonnet::delenv('cgi.decompressed');
10712: return ($decompressed,$result);
10713: }
10714:
1.1055 raeburn 10715: sub process_decompression {
10716: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
10717: my ($dir,$error,$warning,$output);
10718: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
10719: $error = &mt('File name not a supported archive file type.').
10720: '<br />'.&mt('File name should end with one of: [_1].',
10721: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
10722: } else {
10723: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
10724: if ($docuhome eq 'no_host') {
10725: $error = &mt('Could not determine home server for course.');
10726: } else {
10727: my @ids=&Apache::lonnet::current_machine_ids();
10728: my $currdir = "$dir_root/$destination";
10729: if (grep(/^\Q$docuhome\E$/,@ids)) {
10730: $dir = &LONCAPA::propath($docudom,$docuname).
10731: "$dir_root/$destination";
10732: } else {
10733: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
10734: "$dir_root/$docudom/$docuname/$destination";
10735: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
10736: $error = &mt('Archive file not found.');
10737: }
10738: }
1.1065 raeburn 10739: my (@to_overwrite,@to_skip);
10740: if ($env{'form.archive_overwrite_total'} > 0) {
10741: my $total = $env{'form.archive_overwrite_total'};
10742: for (my $i=0; $i<$total; $i++) {
10743: if ($env{'form.archive_overwrite_'.$i} == 1) {
10744: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
10745: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
10746: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
10747: }
10748: }
10749: }
10750: my $numskip = scalar(@to_skip);
10751: if (($numskip > 0) &&
10752: ($numskip == $env{'form.archive_itemcount'})) {
10753: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
10754: } elsif ($dir eq '') {
1.1055 raeburn 10755: $error = &mt('Directory containing archive file unavailable.');
10756: } elsif (!$error) {
1.1065 raeburn 10757: my ($decompressed,$display);
10758: if ($numskip > 0) {
10759: my $tempdir = time.'_'.$$.int(rand(10000));
10760: mkdir("$dir/$tempdir",0755);
10761: system("mv $dir/$file $dir/$tempdir/$file");
10762: ($decompressed,$display) =
10763: &decompress_uploaded_file($file,"$dir/$tempdir");
10764: foreach my $item (@to_skip) {
10765: if (($item ne '') && ($item !~ /\.\./)) {
10766: if (-f "$dir/$tempdir/$item") {
10767: unlink("$dir/$tempdir/$item");
10768: } elsif (-d "$dir/$tempdir/$item") {
10769: system("rm -rf $dir/$tempdir/$item");
10770: }
10771: }
10772: }
10773: system("mv $dir/$tempdir/* $dir");
10774: rmdir("$dir/$tempdir");
10775: } else {
10776: ($decompressed,$display) =
10777: &decompress_uploaded_file($file,$dir);
10778: }
1.1055 raeburn 10779: if ($decompressed eq 'ok') {
1.1065 raeburn 10780: $output = '<p class="LC_info">'.
10781: &mt('Files extracted successfully from archive.').
10782: '</p>'."\n";
1.1055 raeburn 10783: my ($warning,$result,@contents);
10784: my ($newdirlistref,$newlisterror) =
10785: &Apache::lonnet::dirlist($currdir,$docudom,
10786: $docuname,1);
10787: my (%is_dir,%changes,@newitems);
10788: my $dirptr = 16384;
1.1065 raeburn 10789: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 10790: foreach my $dir_line (@{$newdirlistref}) {
10791: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 10792: unless (($item =~ /^\.+$/) || ($item eq $file) ||
10793: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 10794: push(@newitems,$item);
10795: if ($dirptr&$testdir) {
10796: $is_dir{$item} = 1;
10797: }
10798: $changes{$item} = 1;
10799: }
10800: }
10801: }
10802: if (keys(%changes) > 0) {
10803: foreach my $item (sort(@newitems)) {
10804: if ($changes{$item}) {
10805: push(@contents,$item);
10806: }
10807: }
10808: }
10809: if (@contents > 0) {
1.1067 raeburn 10810: my $wantform;
10811: unless ($env{'form.autoextract_camtasia'}) {
10812: $wantform = 1;
10813: }
1.1056 raeburn 10814: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 10815: my ($count,$datatable) = &get_extracted($docudom,$docuname,
10816: $currdir,\%is_dir,
10817: \%children,\%parent,
1.1056 raeburn 10818: \@contents,\%dirorder,
10819: \%titles,$wantform);
1.1055 raeburn 10820: if ($datatable ne '') {
10821: $output .= &archive_options_form('decompressed',$datatable,
10822: $count,$hiddenelem);
1.1065 raeburn 10823: my $startcount = 6;
1.1055 raeburn 10824: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 10825: \%titles,\%children);
1.1055 raeburn 10826: }
1.1067 raeburn 10827: if ($env{'form.autoextract_camtasia'}) {
10828: my %displayed;
10829: my $total = 1;
10830: $env{'form.archive_directory'} = [];
10831: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
10832: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
10833: $path =~ s{/$}{};
10834: my $item;
10835: if ($path ne '') {
10836: $item = "$path/$titles{$i}";
10837: } else {
10838: $item = $titles{$i};
10839: }
10840: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
10841: if ($item eq $contents[0]) {
10842: push(@{$env{'form.archive_directory'}},$i);
10843: $env{'form.archive_'.$i} = 'display';
10844: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
10845: $displayed{'folder'} = $i;
10846: } elsif ($item eq "$contents[0]/index.html") {
10847: $env{'form.archive_'.$i} = 'display';
10848: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
10849: $displayed{'web'} = $i;
10850: } else {
10851: if ($item eq "$contents[0]/media") {
10852: push(@{$env{'form.archive_directory'}},$i);
10853: }
10854: $env{'form.archive_'.$i} = 'dependency';
10855: }
10856: $total ++;
10857: }
10858: for (my $i=1; $i<$total; $i++) {
10859: next if ($i == $displayed{'web'});
10860: next if ($i == $displayed{'folder'});
10861: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
10862: }
10863: $env{'form.phase'} = 'decompress_cleanup';
10864: $env{'form.archivedelete'} = 1;
10865: $env{'form.archive_count'} = $total-1;
10866: $output .=
10867: &process_extracted_files('coursedocs',$docudom,
10868: $docuname,$destination,
10869: $dir_root,$hiddenelem);
10870: }
1.1055 raeburn 10871: } else {
10872: $warning = &mt('No new items extracted from archive file.');
10873: }
10874: } else {
10875: $output = $display;
10876: $error = &mt('An error occurred during extraction from the archive file.');
10877: }
10878: }
10879: }
10880: }
10881: if ($error) {
10882: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
10883: $error.'</p>'."\n";
10884: }
10885: if ($warning) {
10886: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
10887: }
10888: return $output;
10889: }
10890:
10891: sub get_extracted {
1.1056 raeburn 10892: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
10893: $titles,$wantform) = @_;
1.1055 raeburn 10894: my $count = 0;
10895: my $depth = 0;
10896: my $datatable;
1.1056 raeburn 10897: my @hierarchy;
1.1055 raeburn 10898: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 10899: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
10900: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 10901: foreach my $item (@{$contents}) {
10902: $count ++;
1.1056 raeburn 10903: @{$dirorder->{$count}} = @hierarchy;
10904: $titles->{$count} = $item;
1.1055 raeburn 10905: &archive_hierarchy($depth,$count,$parent,$children);
10906: if ($wantform) {
10907: $datatable .= &archive_row($is_dir->{$item},$item,
10908: $currdir,$depth,$count);
10909: }
10910: if ($is_dir->{$item}) {
10911: $depth ++;
1.1056 raeburn 10912: push(@hierarchy,$count);
10913: $parent->{$depth} = $count;
1.1055 raeburn 10914: $datatable .=
10915: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 10916: \$depth,\$count,\@hierarchy,$dirorder,
10917: $children,$parent,$titles,$wantform);
1.1055 raeburn 10918: $depth --;
1.1056 raeburn 10919: pop(@hierarchy);
1.1055 raeburn 10920: }
10921: }
10922: return ($count,$datatable);
10923: }
10924:
10925: sub recurse_extracted_archive {
1.1056 raeburn 10926: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
10927: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 10928: my $result='';
1.1056 raeburn 10929: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
10930: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
10931: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 10932: return $result;
10933: }
10934: my $dirptr = 16384;
10935: my ($newdirlistref,$newlisterror) =
10936: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
10937: if (ref($newdirlistref) eq 'ARRAY') {
10938: foreach my $dir_line (@{$newdirlistref}) {
10939: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
10940: unless ($item =~ /^\.+$/) {
10941: $$count ++;
1.1056 raeburn 10942: @{$dirorder->{$$count}} = @{$hierarchy};
10943: $titles->{$$count} = $item;
1.1055 raeburn 10944: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 10945:
1.1055 raeburn 10946: my $is_dir;
10947: if ($dirptr&$testdir) {
10948: $is_dir = 1;
10949: }
10950: if ($wantform) {
10951: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
10952: }
10953: if ($is_dir) {
10954: $$depth ++;
1.1056 raeburn 10955: push(@{$hierarchy},$$count);
10956: $parent->{$$depth} = $$count;
1.1055 raeburn 10957: $result .=
10958: &recurse_extracted_archive("$currdir/$item",$docudom,
10959: $docuname,$depth,$count,
1.1056 raeburn 10960: $hierarchy,$dirorder,$children,
10961: $parent,$titles,$wantform);
1.1055 raeburn 10962: $$depth --;
1.1056 raeburn 10963: pop(@{$hierarchy});
1.1055 raeburn 10964: }
10965: }
10966: }
10967: }
10968: return $result;
10969: }
10970:
10971: sub archive_hierarchy {
10972: my ($depth,$count,$parent,$children) =@_;
10973: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
10974: if (exists($parent->{$depth})) {
10975: $children->{$parent->{$depth}} .= $count.':';
10976: }
10977: }
10978: return;
10979: }
10980:
10981: sub archive_row {
10982: my ($is_dir,$item,$currdir,$depth,$count) = @_;
10983: my ($name) = ($item =~ m{([^/]+)$});
10984: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 10985: 'display' => 'Add as file',
1.1055 raeburn 10986: 'dependency' => 'Include as dependency',
10987: 'discard' => 'Discard',
10988: );
10989: if ($is_dir) {
1.1059 raeburn 10990: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 10991: }
1.1056 raeburn 10992: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
10993: my $offset = 0;
1.1055 raeburn 10994: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 10995: $offset ++;
1.1065 raeburn 10996: if ($action ne 'display') {
10997: $offset ++;
10998: }
1.1055 raeburn 10999: $output .= '<td><span class="LC_nobreak">'.
11000: '<label><input type="radio" name="archive_'.$count.
11001: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11002: my $text = $choices{$action};
11003: if ($is_dir) {
11004: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11005: if ($action eq 'display') {
1.1059 raeburn 11006: $text = &mt('Add as folder');
1.1055 raeburn 11007: }
1.1056 raeburn 11008: } else {
11009: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11010:
11011: }
11012: $output .= ' /> '.$choices{$action}.'</label></span>';
11013: if ($action eq 'dependency') {
11014: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11015: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11016: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11017: '<option value=""></option>'."\n".
11018: '</select>'."\n".
11019: '</div>';
1.1059 raeburn 11020: } elsif ($action eq 'display') {
11021: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11022: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11023: '</div>';
1.1055 raeburn 11024: }
1.1056 raeburn 11025: $output .= '</td>';
1.1055 raeburn 11026: }
11027: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11028: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11029: for (my $i=0; $i<$depth; $i++) {
11030: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11031: }
11032: if ($is_dir) {
11033: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11034: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11035: } else {
11036: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11037: }
11038: $output .= ' '.$name.'</td>'."\n".
11039: &end_data_table_row();
11040: return $output;
11041: }
11042:
11043: sub archive_options_form {
1.1065 raeburn 11044: my ($form,$display,$count,$hiddenelem) = @_;
11045: my %lt = &Apache::lonlocal::texthash(
11046: perm => 'Permanently remove archive file?',
11047: hows => 'How should each extracted item be incorporated in the course?',
11048: cont => 'Content actions for all',
11049: addf => 'Add as folder/file',
11050: incd => 'Include as dependency for a displayed file',
11051: disc => 'Discard',
11052: no => 'No',
11053: yes => 'Yes',
11054: save => 'Save',
11055: );
11056: my $output = <<"END";
11057: <form name="$form" method="post" action="">
11058: <p><span class="LC_nobreak">$lt{'perm'}
11059: <label>
11060: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11061: </label>
11062:
11063: <label>
11064: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11065: </span>
11066: </p>
11067: <input type="hidden" name="phase" value="decompress_cleanup" />
11068: <br />$lt{'hows'}
11069: <div class="LC_columnSection">
11070: <fieldset>
11071: <legend>$lt{'cont'}</legend>
11072: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11073: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11074: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11075: </fieldset>
11076: </div>
11077: END
11078: return $output.
1.1055 raeburn 11079: &start_data_table()."\n".
1.1065 raeburn 11080: $display."\n".
1.1055 raeburn 11081: &end_data_table()."\n".
11082: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11083: $hiddenelem.
1.1065 raeburn 11084: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11085: '</form>';
11086: }
11087:
11088: sub archive_javascript {
1.1056 raeburn 11089: my ($startcount,$numitems,$titles,$children) = @_;
11090: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11091: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11092: my $scripttag = <<START;
11093: <script type="text/javascript">
11094: // <![CDATA[
11095:
11096: function checkAll(form,prefix) {
11097: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11098: for (var i=0; i < form.elements.length; i++) {
11099: var id = form.elements[i].id;
11100: if ((id != '') && (id != undefined)) {
11101: if (idstr.test(id)) {
11102: if (form.elements[i].type == 'radio') {
11103: form.elements[i].checked = true;
1.1056 raeburn 11104: var nostart = i-$startcount;
1.1059 raeburn 11105: var offset = nostart%7;
11106: var count = (nostart-offset)/7;
1.1056 raeburn 11107: dependencyCheck(form,count,offset);
1.1055 raeburn 11108: }
11109: }
11110: }
11111: }
11112: }
11113:
11114: function propagateCheck(form,count) {
11115: if (count > 0) {
1.1059 raeburn 11116: var startelement = $startcount + ((count-1) * 7);
11117: for (var j=1; j<6; j++) {
11118: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11119: var item = startelement + j;
11120: if (form.elements[item].type == 'radio') {
11121: if (form.elements[item].checked) {
11122: containerCheck(form,count,j);
11123: break;
11124: }
1.1055 raeburn 11125: }
11126: }
11127: }
11128: }
11129: }
11130:
11131: numitems = $numitems
1.1056 raeburn 11132: var titles = new Array(numitems);
11133: var parents = new Array(numitems);
1.1055 raeburn 11134: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11135: parents[i] = new Array;
1.1055 raeburn 11136: }
1.1059 raeburn 11137: var maintitle = '$maintitle';
1.1055 raeburn 11138:
11139: START
11140:
1.1056 raeburn 11141: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11142: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11143: for (my $i=0; $i<@contents; $i ++) {
11144: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11145: }
11146: }
11147:
1.1056 raeburn 11148: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11149: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11150: }
11151:
1.1055 raeburn 11152: $scripttag .= <<END;
11153:
11154: function containerCheck(form,count,offset) {
11155: if (count > 0) {
1.1056 raeburn 11156: dependencyCheck(form,count,offset);
1.1059 raeburn 11157: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11158: form.elements[item].checked = true;
11159: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11160: if (parents[count].length > 0) {
11161: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11162: containerCheck(form,parents[count][j],offset);
11163: }
11164: }
11165: }
11166: }
11167: }
11168:
11169: function dependencyCheck(form,count,offset) {
11170: if (count > 0) {
1.1059 raeburn 11171: var chosen = (offset+$startcount)+7*(count-1);
11172: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11173: var currtype = form.elements[depitem].type;
11174: if (form.elements[chosen].value == 'dependency') {
11175: document.getElementById('arc_depon_'+count).style.display='block';
11176: form.elements[depitem].options.length = 0;
11177: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11178: for (var i=1; i<=numitems; i++) {
11179: if (i == count) {
11180: continue;
11181: }
1.1059 raeburn 11182: var startelement = $startcount + (i-1) * 7;
11183: for (var j=1; j<6; j++) {
11184: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11185: var item = startelement + j;
11186: if (form.elements[item].type == 'radio') {
11187: if (form.elements[item].checked) {
11188: if (form.elements[item].value == 'display') {
11189: var n = form.elements[depitem].options.length;
11190: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11191: }
11192: }
11193: }
11194: }
11195: }
11196: }
11197: } else {
11198: document.getElementById('arc_depon_'+count).style.display='none';
11199: form.elements[depitem].options.length = 0;
11200: form.elements[depitem].options[0] = new Option('Select','',true,true);
11201: }
1.1059 raeburn 11202: titleCheck(form,count,offset);
1.1056 raeburn 11203: }
11204: }
11205:
11206: function propagateSelect(form,count,offset) {
11207: if (count > 0) {
1.1065 raeburn 11208: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11209: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11210: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11211: if (parents[count].length > 0) {
11212: for (var j=0; j<parents[count].length; j++) {
11213: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11214: }
11215: }
11216: }
11217: }
11218: }
1.1056 raeburn 11219:
11220: function containerSelect(form,count,offset,picked) {
11221: if (count > 0) {
1.1065 raeburn 11222: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11223: if (form.elements[item].type == 'radio') {
11224: if (form.elements[item].value == 'dependency') {
11225: if (form.elements[item+1].type == 'select-one') {
11226: for (var i=0; i<form.elements[item+1].options.length; i++) {
11227: if (form.elements[item+1].options[i].value == picked) {
11228: form.elements[item+1].selectedIndex = i;
11229: break;
11230: }
11231: }
11232: }
11233: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11234: if (parents[count].length > 0) {
11235: for (var j=0; j<parents[count].length; j++) {
11236: containerSelect(form,parents[count][j],offset,picked);
11237: }
11238: }
11239: }
11240: }
11241: }
11242: }
11243: }
11244:
1.1059 raeburn 11245: function titleCheck(form,count,offset) {
11246: if (count > 0) {
11247: var chosen = (offset+$startcount)+7*(count-1);
11248: var depitem = $startcount + ((count-1) * 7) + 2;
11249: var currtype = form.elements[depitem].type;
11250: if (form.elements[chosen].value == 'display') {
11251: document.getElementById('arc_title_'+count).style.display='block';
11252: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11253: document.getElementById('archive_title_'+count).value=maintitle;
11254: }
11255: } else {
11256: document.getElementById('arc_title_'+count).style.display='none';
11257: if (currtype == 'text') {
11258: document.getElementById('archive_title_'+count).value='';
11259: }
11260: }
11261: }
11262: return;
11263: }
11264:
1.1055 raeburn 11265: // ]]>
11266: </script>
11267: END
11268: return $scripttag;
11269: }
11270:
11271: sub process_extracted_files {
1.1067 raeburn 11272: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11273: my $numitems = $env{'form.archive_count'};
11274: return unless ($numitems);
11275: my @ids=&Apache::lonnet::current_machine_ids();
11276: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11277: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11278: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11279: if (grep(/^\Q$docuhome\E$/,@ids)) {
11280: $prefix = &LONCAPA::propath($docudom,$docuname);
11281: $pathtocheck = "$dir_root/$destination";
11282: $dir = $dir_root;
11283: $ishome = 1;
11284: } else {
11285: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11286: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11287: $dir = "$dir_root/$docudom/$docuname";
11288: }
11289: my $currdir = "$dir_root/$destination";
11290: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11291: if ($env{'form.folderpath'}) {
11292: my @items = split('&',$env{'form.folderpath'});
11293: $folders{'0'} = $items[-2];
11294: $containers{'0'}='sequence';
11295: } elsif ($env{'form.pagepath'}) {
11296: my @items = split('&',$env{'form.pagepath'});
11297: $folders{'0'} = $items[-2];
11298: $containers{'0'}='page';
11299: }
11300: my @archdirs = &get_env_multiple('form.archive_directory');
11301: if ($numitems) {
11302: for (my $i=1; $i<=$numitems; $i++) {
11303: my $path = $env{'form.archive_content_'.$i};
11304: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11305: my $item = $1;
11306: $toplevelitems{$item} = $i;
11307: if (grep(/^\Q$i\E$/,@archdirs)) {
11308: $is_dir{$item} = 1;
11309: }
11310: }
11311: }
11312: }
1.1067 raeburn 11313: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11314: if (keys(%toplevelitems) > 0) {
11315: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11316: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11317: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11318: }
1.1066 raeburn 11319: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11320: if ($numitems) {
11321: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11322: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11323: my $path = $env{'form.archive_content_'.$i};
11324: if ($path =~ /^\Q$pathtocheck\E/) {
11325: if ($env{'form.archive_'.$i} eq 'discard') {
11326: if ($prefix ne '' && $path ne '') {
11327: if (-e $prefix.$path) {
1.1066 raeburn 11328: if ((@archdirs > 0) &&
11329: (grep(/^\Q$i\E$/,@archdirs))) {
11330: $todeletedir{$prefix.$path} = 1;
11331: } else {
11332: $todelete{$prefix.$path} = 1;
11333: }
1.1055 raeburn 11334: }
11335: }
11336: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11337: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11338: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11339: $docstitle = $env{'form.archive_title_'.$i};
11340: if ($docstitle eq '') {
11341: $docstitle = $title;
11342: }
1.1055 raeburn 11343: $outer = 0;
1.1056 raeburn 11344: if (ref($dirorder{$i}) eq 'ARRAY') {
11345: if (@{$dirorder{$i}} > 0) {
11346: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11347: if ($env{'form.archive_'.$item} eq 'display') {
11348: $outer = $item;
11349: last;
11350: }
11351: }
11352: }
11353: }
11354: my ($errtext,$fatal) =
11355: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11356: '/'.$folders{$outer}.'.'.
11357: $containers{$outer});
11358: next if ($fatal);
11359: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11360: if ($context eq 'coursedocs') {
1.1056 raeburn 11361: $mapinner{$i} = time;
1.1055 raeburn 11362: $folders{$i} = 'default_'.$mapinner{$i};
11363: $containers{$i} = 'sequence';
11364: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11365: $folders{$i}.'.'.$containers{$i};
11366: my $newidx = &LONCAPA::map::getresidx();
11367: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11368: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11369: push(@LONCAPA::map::order,$newidx);
11370: my ($outtext,$errtext) =
11371: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11372: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11373: '.'.$containers{$outer},1,1);
1.1056 raeburn 11374: $newseqid{$i} = $newidx;
1.1067 raeburn 11375: unless ($errtext) {
11376: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11377: }
1.1055 raeburn 11378: }
11379: } else {
11380: if ($context eq 'coursedocs') {
11381: my $newidx=&LONCAPA::map::getresidx();
11382: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11383: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11384: $title;
11385: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11386: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11387: }
11388: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11389: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11390: }
11391: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11392: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11393: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11394: unless ($ishome) {
11395: my $fetch = "$newdest{$i}/$title";
11396: $fetch =~ s/^\Q$prefix$dir\E//;
11397: $prompttofetch{$fetch} = 1;
11398: }
1.1055 raeburn 11399: }
11400: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11401: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11402: push(@LONCAPA::map::order, $newidx);
11403: my ($outtext,$errtext)=
11404: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11405: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11406: '.'.$containers{$outer},1,1);
1.1067 raeburn 11407: unless ($errtext) {
11408: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11409: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11410: }
11411: }
1.1055 raeburn 11412: }
11413: }
1.1075.2.11 raeburn 11414: }
11415: } else {
11416: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11417: }
11418: }
11419: for (my $i=1; $i<=$numitems; $i++) {
11420: next unless ($env{'form.archive_'.$i} eq 'dependency');
11421: my $path = $env{'form.archive_content_'.$i};
11422: if ($path =~ /^\Q$pathtocheck\E/) {
11423: my ($title) = ($path =~ m{/([^/]+)$});
11424: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11425: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11426: if (ref($dirorder{$i}) eq 'ARRAY') {
11427: my ($itemidx,$fullpath,$relpath);
11428: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11429: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11430: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11431: if ($dirorder{$i}->[$j] eq $container) {
11432: $itemidx = $j;
1.1056 raeburn 11433: }
11434: }
1.1075.2.11 raeburn 11435: }
11436: if ($itemidx eq '') {
11437: $itemidx = 0;
11438: }
11439: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11440: if ($mapinner{$referrer{$i}}) {
11441: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11442: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11443: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11444: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11445: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11446: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11447: if (!-e $fullpath) {
11448: mkdir($fullpath,0755);
1.1056 raeburn 11449: }
11450: }
1.1075.2.11 raeburn 11451: } else {
11452: last;
1.1056 raeburn 11453: }
1.1075.2.11 raeburn 11454: }
11455: }
11456: } elsif ($newdest{$referrer{$i}}) {
11457: $fullpath = $newdest{$referrer{$i}};
11458: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11459: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11460: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11461: last;
11462: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11463: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11464: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11465: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11466: if (!-e $fullpath) {
11467: mkdir($fullpath,0755);
1.1056 raeburn 11468: }
11469: }
1.1075.2.11 raeburn 11470: } else {
11471: last;
1.1056 raeburn 11472: }
1.1075.2.11 raeburn 11473: }
11474: }
11475: if ($fullpath ne '') {
11476: if (-e "$prefix$path") {
11477: system("mv $prefix$path $fullpath/$title");
11478: }
11479: if (-e "$fullpath/$title") {
11480: my $showpath;
11481: if ($relpath ne '') {
11482: $showpath = "$relpath/$title";
11483: } else {
11484: $showpath = "/$title";
1.1056 raeburn 11485: }
1.1075.2.11 raeburn 11486: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11487: }
11488: unless ($ishome) {
11489: my $fetch = "$fullpath/$title";
11490: $fetch =~ s/^\Q$prefix$dir\E//;
11491: $prompttofetch{$fetch} = 1;
1.1055 raeburn 11492: }
11493: }
11494: }
1.1075.2.11 raeburn 11495: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11496: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11497: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11498: }
11499: } else {
1.1075.2.11 raeburn 11500: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 11501: }
11502: }
11503: if (keys(%todelete)) {
11504: foreach my $key (keys(%todelete)) {
11505: unlink($key);
1.1066 raeburn 11506: }
11507: }
11508: if (keys(%todeletedir)) {
11509: foreach my $key (keys(%todeletedir)) {
11510: rmdir($key);
11511: }
11512: }
11513: foreach my $dir (sort(keys(%is_dir))) {
11514: if (($pathtocheck ne '') && ($dir ne '')) {
11515: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11516: }
11517: }
1.1067 raeburn 11518: if ($result ne '') {
11519: $output .= '<ul>'."\n".
11520: $result."\n".
11521: '</ul>';
11522: }
11523: unless ($ishome) {
11524: my $replicationfail;
11525: foreach my $item (keys(%prompttofetch)) {
11526: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11527: unless ($fetchresult eq 'ok') {
11528: $replicationfail .= '<li>'.$item.'</li>'."\n";
11529: }
11530: }
11531: if ($replicationfail) {
11532: $output .= '<p class="LC_error">'.
11533: &mt('Course home server failed to retrieve:').'<ul>'.
11534: $replicationfail.
11535: '</ul></p>';
11536: }
11537: }
1.1055 raeburn 11538: } else {
11539: $warning = &mt('No items found in archive.');
11540: }
11541: if ($error) {
11542: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11543: $error.'</p>'."\n";
11544: }
11545: if ($warning) {
11546: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11547: }
11548: return $output;
11549: }
11550:
1.1066 raeburn 11551: sub cleanup_empty_dirs {
11552: my ($path) = @_;
11553: if (($path ne '') && (-d $path)) {
11554: if (opendir(my $dirh,$path)) {
11555: my @dircontents = grep(!/^\./,readdir($dirh));
11556: my $numitems = 0;
11557: foreach my $item (@dircontents) {
11558: if (-d "$path/$item") {
11559: &recurse_dirs("$path/$item");
11560: if (-e "$path/$item") {
11561: $numitems ++;
11562: }
11563: } else {
11564: $numitems ++;
11565: }
11566: }
11567: if ($numitems == 0) {
11568: rmdir($path);
11569: }
11570: closedir($dirh);
11571: }
11572: }
11573: return;
11574: }
11575:
1.41 ng 11576: =pod
1.45 matthew 11577:
1.1068 raeburn 11578: =item &get_folder_hierarchy()
11579:
11580: Provides hierarchy of names of folders/sub-folders containing the current
11581: item,
11582:
11583: Inputs: 3
11584: - $navmap - navmaps object
11585:
11586: - $map - url for map (either the trigger itself, or map containing
11587: the resource, which is the trigger).
11588:
11589: - $showitem - 1 => show title for map itself; 0 => do not show.
11590:
11591: Outputs: 1 @pathitems - array of folder/subfolder names.
11592:
11593: =cut
11594:
11595: sub get_folder_hierarchy {
11596: my ($navmap,$map,$showitem) = @_;
11597: my @pathitems;
11598: if (ref($navmap)) {
11599: my $mapres = $navmap->getResourceByUrl($map);
11600: if (ref($mapres)) {
11601: my $pcslist = $mapres->map_hierarchy();
11602: if ($pcslist ne '') {
11603: my @pcs = split(/,/,$pcslist);
11604: foreach my $pc (@pcs) {
11605: if ($pc == 1) {
11606: push(@pathitems,&mt('Main Course Documents'));
11607: } else {
11608: my $res = $navmap->getByMapPc($pc);
11609: if (ref($res)) {
11610: my $title = $res->compTitle();
11611: $title =~ s/\W+/_/g;
11612: if ($title ne '') {
11613: push(@pathitems,$title);
11614: }
11615: }
11616: }
11617: }
11618: }
1.1071 raeburn 11619: if ($showitem) {
11620: if ($mapres->{ID} eq '0.0') {
11621: push(@pathitems,&mt('Main Course Documents'));
11622: } else {
11623: my $maptitle = $mapres->compTitle();
11624: $maptitle =~ s/\W+/_/g;
11625: if ($maptitle ne '') {
11626: push(@pathitems,$maptitle);
11627: }
1.1068 raeburn 11628: }
11629: }
11630: }
11631: }
11632: return @pathitems;
11633: }
11634:
11635: =pod
11636:
1.1015 raeburn 11637: =item * &get_turnedin_filepath()
11638:
11639: Determines path in a user's portfolio file for storage of files uploaded
11640: to a specific essayresponse or dropbox item.
11641:
11642: Inputs: 3 required + 1 optional.
11643: $symb is symb for resource, $uname and $udom are for current user (required).
11644: $caller is optional (can be "submission", if routine is called when storing
11645: an upoaded file when "Submit Answer" button was pressed).
11646:
11647: Returns array containing $path and $multiresp.
11648: $path is path in portfolio. $multiresp is 1 if this resource contains more
11649: than one file upload item. Callers of routine should append partid as a
11650: subdirectory to $path in cases where $multiresp is 1.
11651:
11652: Called by: homework/essayresponse.pm and homework/structuretags.pm
11653:
11654: =cut
11655:
11656: sub get_turnedin_filepath {
11657: my ($symb,$uname,$udom,$caller) = @_;
11658: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
11659: my $turnindir;
11660: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
11661: $turnindir = $userhash{'turnindir'};
11662: my ($path,$multiresp);
11663: if ($turnindir eq '') {
11664: if ($caller eq 'submission') {
11665: $turnindir = &mt('turned in');
11666: $turnindir =~ s/\W+/_/g;
11667: my %newhash = (
11668: 'turnindir' => $turnindir,
11669: );
11670: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
11671: }
11672: }
11673: if ($turnindir ne '') {
11674: $path = '/'.$turnindir.'/';
11675: my ($multipart,$turnin,@pathitems);
11676: my $navmap = Apache::lonnavmaps::navmap->new();
11677: if (defined($navmap)) {
11678: my $mapres = $navmap->getResourceByUrl($map);
11679: if (ref($mapres)) {
11680: my $pcslist = $mapres->map_hierarchy();
11681: if ($pcslist ne '') {
11682: foreach my $pc (split(/,/,$pcslist)) {
11683: my $res = $navmap->getByMapPc($pc);
11684: if (ref($res)) {
11685: my $title = $res->compTitle();
11686: $title =~ s/\W+/_/g;
11687: if ($title ne '') {
11688: push(@pathitems,$title);
11689: }
11690: }
11691: }
11692: }
11693: my $maptitle = $mapres->compTitle();
11694: $maptitle =~ s/\W+/_/g;
11695: if ($maptitle ne '') {
11696: push(@pathitems,$maptitle);
11697: }
11698: unless ($env{'request.state'} eq 'construct') {
11699: my $res = $navmap->getBySymb($symb);
11700: if (ref($res)) {
11701: my $partlist = $res->parts();
11702: my $totaluploads = 0;
11703: if (ref($partlist) eq 'ARRAY') {
11704: foreach my $part (@{$partlist}) {
11705: my @types = $res->responseType($part);
11706: my @ids = $res->responseIds($part);
11707: for (my $i=0; $i < scalar(@ids); $i++) {
11708: if ($types[$i] eq 'essay') {
11709: my $partid = $part.'_'.$ids[$i];
11710: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
11711: $totaluploads ++;
11712: }
11713: }
11714: }
11715: }
11716: if ($totaluploads > 1) {
11717: $multiresp = 1;
11718: }
11719: }
11720: }
11721: }
11722: } else {
11723: return;
11724: }
11725: } else {
11726: return;
11727: }
11728: my $restitle=&Apache::lonnet::gettitle($symb);
11729: $restitle =~ s/\W+/_/g;
11730: if ($restitle eq '') {
11731: $restitle = ($resurl =~ m{/[^/]+$});
11732: if ($restitle eq '') {
11733: $restitle = time;
11734: }
11735: }
11736: push(@pathitems,$restitle);
11737: $path .= join('/',@pathitems);
11738: }
11739: return ($path,$multiresp);
11740: }
11741:
11742: =pod
11743:
1.464 albertel 11744: =back
1.41 ng 11745:
1.112 bowersj2 11746: =head1 CSV Upload/Handling functions
1.38 albertel 11747:
1.41 ng 11748: =over 4
11749:
1.648 raeburn 11750: =item * &upfile_store($r)
1.41 ng 11751:
11752: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 11753: needs $env{'form.upfile'}
1.41 ng 11754: returns $datatoken to be put into hidden field
11755:
11756: =cut
1.31 albertel 11757:
11758: sub upfile_store {
11759: my $r=shift;
1.258 albertel 11760: $env{'form.upfile'}=~s/\r/\n/gs;
11761: $env{'form.upfile'}=~s/\f/\n/gs;
11762: $env{'form.upfile'}=~s/\n+/\n/gs;
11763: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 11764:
1.258 albertel 11765: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
11766: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 11767: {
1.158 raeburn 11768: my $datafile = $r->dir_config('lonDaemons').
11769: '/tmp/'.$datatoken.'.tmp';
11770: if ( open(my $fh,">$datafile") ) {
1.258 albertel 11771: print $fh $env{'form.upfile'};
1.158 raeburn 11772: close($fh);
11773: }
1.31 albertel 11774: }
11775: return $datatoken;
11776: }
11777:
1.56 matthew 11778: =pod
11779:
1.648 raeburn 11780: =item * &load_tmp_file($r)
1.41 ng 11781:
11782: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 11783: needs $env{'form.datatoken'},
11784: sets $env{'form.upfile'} to the contents of the file
1.41 ng 11785:
11786: =cut
1.31 albertel 11787:
11788: sub load_tmp_file {
11789: my $r=shift;
11790: my @studentdata=();
11791: {
1.158 raeburn 11792: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 11793: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 11794: if ( open(my $fh,"<$studentfile") ) {
11795: @studentdata=<$fh>;
11796: close($fh);
11797: }
1.31 albertel 11798: }
1.258 albertel 11799: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 11800: }
11801:
1.56 matthew 11802: =pod
11803:
1.648 raeburn 11804: =item * &upfile_record_sep()
1.41 ng 11805:
11806: Separate uploaded file into records
11807: returns array of records,
1.258 albertel 11808: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 11809:
11810: =cut
1.31 albertel 11811:
11812: sub upfile_record_sep {
1.258 albertel 11813: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 11814: } else {
1.248 albertel 11815: my @records;
1.258 albertel 11816: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 11817: if ($line=~/^\s*$/) { next; }
11818: push(@records,$line);
11819: }
11820: return @records;
1.31 albertel 11821: }
11822: }
11823:
1.56 matthew 11824: =pod
11825:
1.648 raeburn 11826: =item * &record_sep($record)
1.41 ng 11827:
1.258 albertel 11828: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 11829:
11830: =cut
11831:
1.263 www 11832: sub takeleft {
11833: my $index=shift;
11834: return substr('0000'.$index,-4,4);
11835: }
11836:
1.31 albertel 11837: sub record_sep {
11838: my $record=shift;
11839: my %components=();
1.258 albertel 11840: if ($env{'form.upfiletype'} eq 'xml') {
11841: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 11842: my $i=0;
1.356 albertel 11843: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 11844: $field=~s/^(\"|\')//;
11845: $field=~s/(\"|\')$//;
1.263 www 11846: $components{&takeleft($i)}=$field;
1.31 albertel 11847: $i++;
11848: }
1.258 albertel 11849: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 11850: my $i=0;
1.356 albertel 11851: foreach my $field (split(/\t/,$record)) {
1.31 albertel 11852: $field=~s/^(\"|\')//;
11853: $field=~s/(\"|\')$//;
1.263 www 11854: $components{&takeleft($i)}=$field;
1.31 albertel 11855: $i++;
11856: }
11857: } else {
1.561 www 11858: my $separator=',';
1.480 banghart 11859: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 11860: $separator=';';
1.480 banghart 11861: }
1.31 albertel 11862: my $i=0;
1.561 www 11863: # the character we are looking for to indicate the end of a quote or a record
11864: my $looking_for=$separator;
11865: # do not add the characters to the fields
11866: my $ignore=0;
11867: # we just encountered a separator (or the beginning of the record)
11868: my $just_found_separator=1;
11869: # store the field we are working on here
11870: my $field='';
11871: # work our way through all characters in record
11872: foreach my $character ($record=~/(.)/g) {
11873: if ($character eq $looking_for) {
11874: if ($character ne $separator) {
11875: # Found the end of a quote, again looking for separator
11876: $looking_for=$separator;
11877: $ignore=1;
11878: } else {
11879: # Found a separator, store away what we got
11880: $components{&takeleft($i)}=$field;
11881: $i++;
11882: $just_found_separator=1;
11883: $ignore=0;
11884: $field='';
11885: }
11886: next;
11887: }
11888: # single or double quotation marks after a separator indicate beginning of a quote
11889: # we are now looking for the end of the quote and need to ignore separators
11890: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
11891: $looking_for=$character;
11892: next;
11893: }
11894: # ignore would be true after we reached the end of a quote
11895: if ($ignore) { next; }
11896: if (($just_found_separator) && ($character=~/\s/)) { next; }
11897: $field.=$character;
11898: $just_found_separator=0;
1.31 albertel 11899: }
1.561 www 11900: # catch the very last entry, since we never encountered the separator
11901: $components{&takeleft($i)}=$field;
1.31 albertel 11902: }
11903: return %components;
11904: }
11905:
1.144 matthew 11906: ######################################################
11907: ######################################################
11908:
1.56 matthew 11909: =pod
11910:
1.648 raeburn 11911: =item * &upfile_select_html()
1.41 ng 11912:
1.144 matthew 11913: Return HTML code to select a file from the users machine and specify
11914: the file type.
1.41 ng 11915:
11916: =cut
11917:
1.144 matthew 11918: ######################################################
11919: ######################################################
1.31 albertel 11920: sub upfile_select_html {
1.144 matthew 11921: my %Types = (
11922: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 11923: semisv => &mt('Semicolon separated values'),
1.144 matthew 11924: space => &mt('Space separated'),
11925: tab => &mt('Tabulator separated'),
11926: # xml => &mt('HTML/XML'),
11927: );
11928: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 11929: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 11930: foreach my $type (sort(keys(%Types))) {
11931: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
11932: }
11933: $Str .= "</select>\n";
11934: return $Str;
1.31 albertel 11935: }
11936:
1.301 albertel 11937: sub get_samples {
11938: my ($records,$toget) = @_;
11939: my @samples=({});
11940: my $got=0;
11941: foreach my $rec (@$records) {
11942: my %temp = &record_sep($rec);
11943: if (! grep(/\S/, values(%temp))) { next; }
11944: if (%temp) {
11945: $samples[$got]=\%temp;
11946: $got++;
11947: if ($got == $toget) { last; }
11948: }
11949: }
11950: return \@samples;
11951: }
11952:
1.144 matthew 11953: ######################################################
11954: ######################################################
11955:
1.56 matthew 11956: =pod
11957:
1.648 raeburn 11958: =item * &csv_print_samples($r,$records)
1.41 ng 11959:
11960: Prints a table of sample values from each column uploaded $r is an
11961: Apache Request ref, $records is an arrayref from
11962: &Apache::loncommon::upfile_record_sep
11963:
11964: =cut
11965:
1.144 matthew 11966: ######################################################
11967: ######################################################
1.31 albertel 11968: sub csv_print_samples {
11969: my ($r,$records) = @_;
1.662 bisitz 11970: my $samples = &get_samples($records,5);
1.301 albertel 11971:
1.594 raeburn 11972: $r->print(&mt('Samples').'<br />'.&start_data_table().
11973: &start_data_table_header_row());
1.356 albertel 11974: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 11975: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 11976: $r->print(&end_data_table_header_row());
1.301 albertel 11977: foreach my $hash (@$samples) {
1.594 raeburn 11978: $r->print(&start_data_table_row());
1.356 albertel 11979: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 11980: $r->print('<td>');
1.356 albertel 11981: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 11982: $r->print('</td>');
11983: }
1.594 raeburn 11984: $r->print(&end_data_table_row());
1.31 albertel 11985: }
1.594 raeburn 11986: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 11987: }
11988:
1.144 matthew 11989: ######################################################
11990: ######################################################
11991:
1.56 matthew 11992: =pod
11993:
1.648 raeburn 11994: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 11995:
11996: Prints a table to create associations between values and table columns.
1.144 matthew 11997:
1.41 ng 11998: $r is an Apache Request ref,
11999: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12000: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12001:
12002: =cut
12003:
1.144 matthew 12004: ######################################################
12005: ######################################################
1.31 albertel 12006: sub csv_print_select_table {
12007: my ($r,$records,$d) = @_;
1.301 albertel 12008: my $i=0;
12009: my $samples = &get_samples($records,1);
1.144 matthew 12010: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12011: &start_data_table().&start_data_table_header_row().
1.144 matthew 12012: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12013: '<th>'.&mt('Column').'</th>'.
12014: &end_data_table_header_row()."\n");
1.356 albertel 12015: foreach my $array_ref (@$d) {
12016: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12017: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12018:
1.875 bisitz 12019: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12020: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12021: $r->print('<option value="none"></option>');
1.356 albertel 12022: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12023: $r->print('<option value="'.$sample.'"'.
12024: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12025: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12026: }
1.594 raeburn 12027: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12028: $i++;
12029: }
1.594 raeburn 12030: $r->print(&end_data_table());
1.31 albertel 12031: $i--;
12032: return $i;
12033: }
1.56 matthew 12034:
1.144 matthew 12035: ######################################################
12036: ######################################################
12037:
1.56 matthew 12038: =pod
1.31 albertel 12039:
1.648 raeburn 12040: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12041:
12042: Prints a table of sample values from the upload and can make associate samples to internal names.
12043:
12044: $r is an Apache Request ref,
12045: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12046: $d is an array of 2 element arrays (internal name, displayed name)
12047:
12048: =cut
12049:
1.144 matthew 12050: ######################################################
12051: ######################################################
1.31 albertel 12052: sub csv_samples_select_table {
12053: my ($r,$records,$d) = @_;
12054: my $i=0;
1.144 matthew 12055: #
1.662 bisitz 12056: my $max_samples = 5;
12057: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12058: $r->print(&start_data_table().
12059: &start_data_table_header_row().'<th>'.
12060: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12061: &end_data_table_header_row());
1.301 albertel 12062:
12063: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12064: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12065: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12066: foreach my $option (@$d) {
12067: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12068: $r->print('<option value="'.$value.'"'.
1.253 albertel 12069: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12070: $display.'</option>');
1.31 albertel 12071: }
12072: $r->print('</select></td><td>');
1.662 bisitz 12073: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12074: if (defined($samples->[$line]{$key})) {
12075: $r->print($samples->[$line]{$key}."<br />\n");
12076: }
12077: }
1.594 raeburn 12078: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12079: $i++;
12080: }
1.594 raeburn 12081: $r->print(&end_data_table());
1.31 albertel 12082: $i--;
12083: return($i);
1.115 matthew 12084: }
12085:
1.144 matthew 12086: ######################################################
12087: ######################################################
12088:
1.115 matthew 12089: =pod
12090:
1.648 raeburn 12091: =item * &clean_excel_name($name)
1.115 matthew 12092:
12093: Returns a replacement for $name which does not contain any illegal characters.
12094:
12095: =cut
12096:
1.144 matthew 12097: ######################################################
12098: ######################################################
1.115 matthew 12099: sub clean_excel_name {
12100: my ($name) = @_;
12101: $name =~ s/[:\*\?\/\\]//g;
12102: if (length($name) > 31) {
12103: $name = substr($name,0,31);
12104: }
12105: return $name;
1.25 albertel 12106: }
1.84 albertel 12107:
1.85 albertel 12108: =pod
12109:
1.648 raeburn 12110: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12111:
12112: Returns either 1 or undef
12113:
12114: 1 if the part is to be hidden, undef if it is to be shown
12115:
12116: Arguments are:
12117:
12118: $id the id of the part to be checked
12119: $symb, optional the symb of the resource to check
12120: $udom, optional the domain of the user to check for
12121: $uname, optional the username of the user to check for
12122:
12123: =cut
1.84 albertel 12124:
12125: sub check_if_partid_hidden {
12126: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12127: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12128: $symb,$udom,$uname);
1.141 albertel 12129: my $truth=1;
12130: #if the string starts with !, then the list is the list to show not hide
12131: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12132: my @hiddenlist=split(/,/,$hiddenparts);
12133: foreach my $checkid (@hiddenlist) {
1.141 albertel 12134: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12135: }
1.141 albertel 12136: return !$truth;
1.84 albertel 12137: }
1.127 matthew 12138:
1.138 matthew 12139:
12140: ############################################################
12141: ############################################################
12142:
12143: =pod
12144:
1.157 matthew 12145: =back
12146:
1.138 matthew 12147: =head1 cgi-bin script and graphing routines
12148:
1.157 matthew 12149: =over 4
12150:
1.648 raeburn 12151: =item * &get_cgi_id()
1.138 matthew 12152:
12153: Inputs: none
12154:
12155: Returns an id which can be used to pass environment variables
12156: to various cgi-bin scripts. These environment variables will
12157: be removed from the users environment after a given time by
12158: the routine &Apache::lonnet::transfer_profile_to_env.
12159:
12160: =cut
12161:
12162: ############################################################
12163: ############################################################
1.152 albertel 12164: my $uniq=0;
1.136 matthew 12165: sub get_cgi_id {
1.154 albertel 12166: $uniq=($uniq+1)%100000;
1.280 albertel 12167: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12168: }
12169:
1.127 matthew 12170: ############################################################
12171: ############################################################
12172:
12173: =pod
12174:
1.648 raeburn 12175: =item * &DrawBarGraph()
1.127 matthew 12176:
1.138 matthew 12177: Facilitates the plotting of data in a (stacked) bar graph.
12178: Puts plot definition data into the users environment in order for
12179: graph.png to plot it. Returns an <img> tag for the plot.
12180: The bars on the plot are labeled '1','2',...,'n'.
12181:
12182: Inputs:
12183:
12184: =over 4
12185:
12186: =item $Title: string, the title of the plot
12187:
12188: =item $xlabel: string, text describing the X-axis of the plot
12189:
12190: =item $ylabel: string, text describing the Y-axis of the plot
12191:
12192: =item $Max: scalar, the maximum Y value to use in the plot
12193: If $Max is < any data point, the graph will not be rendered.
12194:
1.140 matthew 12195: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12196: they are plotted. If undefined, default values will be used.
12197:
1.178 matthew 12198: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12199:
1.138 matthew 12200: =item @Values: An array of array references. Each array reference holds data
12201: to be plotted in a stacked bar chart.
12202:
1.239 matthew 12203: =item If the final element of @Values is a hash reference the key/value
12204: pairs will be added to the graph definition.
12205:
1.138 matthew 12206: =back
12207:
12208: Returns:
12209:
12210: An <img> tag which references graph.png and the appropriate identifying
12211: information for the plot.
12212:
1.127 matthew 12213: =cut
12214:
12215: ############################################################
12216: ############################################################
1.134 matthew 12217: sub DrawBarGraph {
1.178 matthew 12218: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12219: #
12220: if (! defined($colors)) {
12221: $colors = ['#33ff00',
12222: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12223: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12224: ];
12225: }
1.228 matthew 12226: my $extra_settings = {};
12227: if (ref($Values[-1]) eq 'HASH') {
12228: $extra_settings = pop(@Values);
12229: }
1.127 matthew 12230: #
1.136 matthew 12231: my $identifier = &get_cgi_id();
12232: my $id = 'cgi.'.$identifier;
1.129 matthew 12233: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12234: return '';
12235: }
1.225 matthew 12236: #
12237: my @Labels;
12238: if (defined($labels)) {
12239: @Labels = @$labels;
12240: } else {
12241: for (my $i=0;$i<@{$Values[0]};$i++) {
12242: push (@Labels,$i+1);
12243: }
12244: }
12245: #
1.129 matthew 12246: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12247: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12248: my %ValuesHash;
12249: my $NumSets=1;
12250: foreach my $array (@Values) {
12251: next if (! ref($array));
1.136 matthew 12252: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12253: join(',',@$array);
1.129 matthew 12254: }
1.127 matthew 12255: #
1.136 matthew 12256: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12257: if ($NumBars < 3) {
12258: $width = 120+$NumBars*32;
1.220 matthew 12259: $xskip = 1;
1.225 matthew 12260: $bar_width = 30;
12261: } elsif ($NumBars < 5) {
12262: $width = 120+$NumBars*20;
12263: $xskip = 1;
12264: $bar_width = 20;
1.220 matthew 12265: } elsif ($NumBars < 10) {
1.136 matthew 12266: $width = 120+$NumBars*15;
12267: $xskip = 1;
12268: $bar_width = 15;
12269: } elsif ($NumBars <= 25) {
12270: $width = 120+$NumBars*11;
12271: $xskip = 5;
12272: $bar_width = 8;
12273: } elsif ($NumBars <= 50) {
12274: $width = 120+$NumBars*8;
12275: $xskip = 5;
12276: $bar_width = 4;
12277: } else {
12278: $width = 120+$NumBars*8;
12279: $xskip = 5;
12280: $bar_width = 4;
12281: }
12282: #
1.137 matthew 12283: $Max = 1 if ($Max < 1);
12284: if ( int($Max) < $Max ) {
12285: $Max++;
12286: $Max = int($Max);
12287: }
1.127 matthew 12288: $Title = '' if (! defined($Title));
12289: $xlabel = '' if (! defined($xlabel));
12290: $ylabel = '' if (! defined($ylabel));
1.369 www 12291: $ValuesHash{$id.'.title'} = &escape($Title);
12292: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12293: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12294: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12295: $ValuesHash{$id.'.NumBars'} = $NumBars;
12296: $ValuesHash{$id.'.NumSets'} = $NumSets;
12297: $ValuesHash{$id.'.PlotType'} = 'bar';
12298: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12299: $ValuesHash{$id.'.height'} = $height;
12300: $ValuesHash{$id.'.width'} = $width;
12301: $ValuesHash{$id.'.xskip'} = $xskip;
12302: $ValuesHash{$id.'.bar_width'} = $bar_width;
12303: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12304: #
1.228 matthew 12305: # Deal with other parameters
12306: while (my ($key,$value) = each(%$extra_settings)) {
12307: $ValuesHash{$id.'.'.$key} = $value;
12308: }
12309: #
1.646 raeburn 12310: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12311: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12312: }
12313:
12314: ############################################################
12315: ############################################################
12316:
12317: =pod
12318:
1.648 raeburn 12319: =item * &DrawXYGraph()
1.137 matthew 12320:
1.138 matthew 12321: Facilitates the plotting of data in an XY graph.
12322: Puts plot definition data into the users environment in order for
12323: graph.png to plot it. Returns an <img> tag for the plot.
12324:
12325: Inputs:
12326:
12327: =over 4
12328:
12329: =item $Title: string, the title of the plot
12330:
12331: =item $xlabel: string, text describing the X-axis of the plot
12332:
12333: =item $ylabel: string, text describing the Y-axis of the plot
12334:
12335: =item $Max: scalar, the maximum Y value to use in the plot
12336: If $Max is < any data point, the graph will not be rendered.
12337:
12338: =item $colors: Array ref containing the hex color codes for the data to be
12339: plotted in. If undefined, default values will be used.
12340:
12341: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12342:
12343: =item $Ydata: Array ref containing Array refs.
1.185 www 12344: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12345:
12346: =item %Values: hash indicating or overriding any default values which are
12347: passed to graph.png.
12348: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12349:
12350: =back
12351:
12352: Returns:
12353:
12354: An <img> tag which references graph.png and the appropriate identifying
12355: information for the plot.
12356:
1.137 matthew 12357: =cut
12358:
12359: ############################################################
12360: ############################################################
12361: sub DrawXYGraph {
12362: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12363: #
12364: # Create the identifier for the graph
12365: my $identifier = &get_cgi_id();
12366: my $id = 'cgi.'.$identifier;
12367: #
12368: $Title = '' if (! defined($Title));
12369: $xlabel = '' if (! defined($xlabel));
12370: $ylabel = '' if (! defined($ylabel));
12371: my %ValuesHash =
12372: (
1.369 www 12373: $id.'.title' => &escape($Title),
12374: $id.'.xlabel' => &escape($xlabel),
12375: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12376: $id.'.y_max_value'=> $Max,
12377: $id.'.labels' => join(',',@$Xlabels),
12378: $id.'.PlotType' => 'XY',
12379: );
12380: #
12381: if (defined($colors) && ref($colors) eq 'ARRAY') {
12382: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12383: }
12384: #
12385: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12386: return '';
12387: }
12388: my $NumSets=1;
1.138 matthew 12389: foreach my $array (@{$Ydata}){
1.137 matthew 12390: next if (! ref($array));
12391: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12392: }
1.138 matthew 12393: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12394: #
12395: # Deal with other parameters
12396: while (my ($key,$value) = each(%Values)) {
12397: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12398: }
12399: #
1.646 raeburn 12400: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12401: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12402: }
12403:
12404: ############################################################
12405: ############################################################
12406:
12407: =pod
12408:
1.648 raeburn 12409: =item * &DrawXYYGraph()
1.138 matthew 12410:
12411: Facilitates the plotting of data in an XY graph with two Y axes.
12412: Puts plot definition data into the users environment in order for
12413: graph.png to plot it. Returns an <img> tag for the plot.
12414:
12415: Inputs:
12416:
12417: =over 4
12418:
12419: =item $Title: string, the title of the plot
12420:
12421: =item $xlabel: string, text describing the X-axis of the plot
12422:
12423: =item $ylabel: string, text describing the Y-axis of the plot
12424:
12425: =item $colors: Array ref containing the hex color codes for the data to be
12426: plotted in. If undefined, default values will be used.
12427:
12428: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12429:
12430: =item $Ydata1: The first data set
12431:
12432: =item $Min1: The minimum value of the left Y-axis
12433:
12434: =item $Max1: The maximum value of the left Y-axis
12435:
12436: =item $Ydata2: The second data set
12437:
12438: =item $Min2: The minimum value of the right Y-axis
12439:
12440: =item $Max2: The maximum value of the left Y-axis
12441:
12442: =item %Values: hash indicating or overriding any default values which are
12443: passed to graph.png.
12444: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12445:
12446: =back
12447:
12448: Returns:
12449:
12450: An <img> tag which references graph.png and the appropriate identifying
12451: information for the plot.
1.136 matthew 12452:
12453: =cut
12454:
12455: ############################################################
12456: ############################################################
1.137 matthew 12457: sub DrawXYYGraph {
12458: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12459: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12460: #
12461: # Create the identifier for the graph
12462: my $identifier = &get_cgi_id();
12463: my $id = 'cgi.'.$identifier;
12464: #
12465: $Title = '' if (! defined($Title));
12466: $xlabel = '' if (! defined($xlabel));
12467: $ylabel = '' if (! defined($ylabel));
12468: my %ValuesHash =
12469: (
1.369 www 12470: $id.'.title' => &escape($Title),
12471: $id.'.xlabel' => &escape($xlabel),
12472: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12473: $id.'.labels' => join(',',@$Xlabels),
12474: $id.'.PlotType' => 'XY',
12475: $id.'.NumSets' => 2,
1.137 matthew 12476: $id.'.two_axes' => 1,
12477: $id.'.y1_max_value' => $Max1,
12478: $id.'.y1_min_value' => $Min1,
12479: $id.'.y2_max_value' => $Max2,
12480: $id.'.y2_min_value' => $Min2,
1.136 matthew 12481: );
12482: #
1.137 matthew 12483: if (defined($colors) && ref($colors) eq 'ARRAY') {
12484: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12485: }
12486: #
12487: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12488: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12489: return '';
12490: }
12491: my $NumSets=1;
1.137 matthew 12492: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12493: next if (! ref($array));
12494: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12495: }
12496: #
12497: # Deal with other parameters
12498: while (my ($key,$value) = each(%Values)) {
12499: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12500: }
12501: #
1.646 raeburn 12502: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12503: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12504: }
12505:
12506: ############################################################
12507: ############################################################
12508:
12509: =pod
12510:
1.157 matthew 12511: =back
12512:
1.139 matthew 12513: =head1 Statistics helper routines?
12514:
12515: Bad place for them but what the hell.
12516:
1.157 matthew 12517: =over 4
12518:
1.648 raeburn 12519: =item * &chartlink()
1.139 matthew 12520:
12521: Returns a link to the chart for a specific student.
12522:
12523: Inputs:
12524:
12525: =over 4
12526:
12527: =item $linktext: The text of the link
12528:
12529: =item $sname: The students username
12530:
12531: =item $sdomain: The students domain
12532:
12533: =back
12534:
1.157 matthew 12535: =back
12536:
1.139 matthew 12537: =cut
12538:
12539: ############################################################
12540: ############################################################
12541: sub chartlink {
12542: my ($linktext, $sname, $sdomain) = @_;
12543: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12544: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12545: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12546: '">'.$linktext.'</a>';
1.153 matthew 12547: }
12548:
12549: #######################################################
12550: #######################################################
12551:
12552: =pod
12553:
12554: =head1 Course Environment Routines
1.157 matthew 12555:
12556: =over 4
1.153 matthew 12557:
1.648 raeburn 12558: =item * &restore_course_settings()
1.153 matthew 12559:
1.648 raeburn 12560: =item * &store_course_settings()
1.153 matthew 12561:
12562: Restores/Store indicated form parameters from the course environment.
12563: Will not overwrite existing values of the form parameters.
12564:
12565: Inputs:
12566: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12567:
12568: a hash ref describing the data to be stored. For example:
12569:
12570: %Save_Parameters = ('Status' => 'scalar',
12571: 'chartoutputmode' => 'scalar',
12572: 'chartoutputdata' => 'scalar',
12573: 'Section' => 'array',
1.373 raeburn 12574: 'Group' => 'array',
1.153 matthew 12575: 'StudentData' => 'array',
12576: 'Maps' => 'array');
12577:
12578: Returns: both routines return nothing
12579:
1.631 raeburn 12580: =back
12581:
1.153 matthew 12582: =cut
12583:
12584: #######################################################
12585: #######################################################
12586: sub store_course_settings {
1.496 albertel 12587: return &store_settings($env{'request.course.id'},@_);
12588: }
12589:
12590: sub store_settings {
1.153 matthew 12591: # save to the environment
12592: # appenv the same items, just to be safe
1.300 albertel 12593: my $udom = $env{'user.domain'};
12594: my $uname = $env{'user.name'};
1.496 albertel 12595: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12596: my %SaveHash;
12597: my %AppHash;
12598: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12599: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12600: my $envname = 'environment.'.$basename;
1.258 albertel 12601: if (exists($env{'form.'.$setting})) {
1.153 matthew 12602: # Save this value away
12603: if ($type eq 'scalar' &&
1.258 albertel 12604: (! exists($env{$envname}) ||
12605: $env{$envname} ne $env{'form.'.$setting})) {
12606: $SaveHash{$basename} = $env{'form.'.$setting};
12607: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 12608: } elsif ($type eq 'array') {
12609: my $stored_form;
1.258 albertel 12610: if (ref($env{'form.'.$setting})) {
1.153 matthew 12611: $stored_form = join(',',
12612: map {
1.369 www 12613: &escape($_);
1.258 albertel 12614: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 12615: } else {
12616: $stored_form =
1.369 www 12617: &escape($env{'form.'.$setting});
1.153 matthew 12618: }
12619: # Determine if the array contents are the same.
1.258 albertel 12620: if ($stored_form ne $env{$envname}) {
1.153 matthew 12621: $SaveHash{$basename} = $stored_form;
12622: $AppHash{$envname} = $stored_form;
12623: }
12624: }
12625: }
12626: }
12627: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 12628: $udom,$uname);
1.153 matthew 12629: if ($put_result !~ /^(ok|delayed)/) {
12630: &Apache::lonnet::logthis('unable to save form parameters, '.
12631: 'got error:'.$put_result);
12632: }
12633: # Make sure these settings stick around in this session, too
1.646 raeburn 12634: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 12635: return;
12636: }
12637:
12638: sub restore_course_settings {
1.499 albertel 12639: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 12640: }
12641:
12642: sub restore_settings {
12643: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12644: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 12645: next if (exists($env{'form.'.$setting}));
1.496 albertel 12646: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 12647: '.'.$setting;
1.258 albertel 12648: if (exists($env{$envname})) {
1.153 matthew 12649: if ($type eq 'scalar') {
1.258 albertel 12650: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 12651: } elsif ($type eq 'array') {
1.258 albertel 12652: $env{'form.'.$setting} = [
1.153 matthew 12653: map {
1.369 www 12654: &unescape($_);
1.258 albertel 12655: } split(',',$env{$envname})
1.153 matthew 12656: ];
12657: }
12658: }
12659: }
1.127 matthew 12660: }
12661:
1.618 raeburn 12662: #######################################################
12663: #######################################################
12664:
12665: =pod
12666:
12667: =head1 Domain E-mail Routines
12668:
12669: =over 4
12670:
1.648 raeburn 12671: =item * &build_recipient_list()
1.618 raeburn 12672:
1.884 raeburn 12673: Build recipient lists for five types of e-mail:
1.766 raeburn 12674: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 12675: (d) Help requests, (e) Course requests needing approval, generated by
12676: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
12677: loncoursequeueadmin.pm respectively.
1.618 raeburn 12678:
12679: Inputs:
1.619 raeburn 12680: defmail (scalar - email address of default recipient),
1.618 raeburn 12681: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 12682: defdom (domain for which to retrieve configuration settings),
12683: origmail (scalar - email address of recipient from loncapa.conf,
12684: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 12685:
1.655 raeburn 12686: Returns: comma separated list of addresses to which to send e-mail.
12687:
12688: =back
1.618 raeburn 12689:
12690: =cut
12691:
12692: ############################################################
12693: ############################################################
12694: sub build_recipient_list {
1.619 raeburn 12695: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 12696: my @recipients;
12697: my $otheremails;
12698: my %domconfig =
12699: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
12700: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 12701: if (exists($domconfig{'contacts'}{$mailing})) {
12702: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
12703: my @contacts = ('adminemail','supportemail');
12704: foreach my $item (@contacts) {
12705: if ($domconfig{'contacts'}{$mailing}{$item}) {
12706: my $addr = $domconfig{'contacts'}{$item};
12707: if (!grep(/^\Q$addr\E$/,@recipients)) {
12708: push(@recipients,$addr);
12709: }
1.619 raeburn 12710: }
1.766 raeburn 12711: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 12712: }
12713: }
1.766 raeburn 12714: } elsif ($origmail ne '') {
12715: push(@recipients,$origmail);
1.618 raeburn 12716: }
1.619 raeburn 12717: } elsif ($origmail ne '') {
12718: push(@recipients,$origmail);
1.618 raeburn 12719: }
1.688 raeburn 12720: if (defined($defmail)) {
12721: if ($defmail ne '') {
12722: push(@recipients,$defmail);
12723: }
1.618 raeburn 12724: }
12725: if ($otheremails) {
1.619 raeburn 12726: my @others;
12727: if ($otheremails =~ /,/) {
12728: @others = split(/,/,$otheremails);
1.618 raeburn 12729: } else {
1.619 raeburn 12730: push(@others,$otheremails);
12731: }
12732: foreach my $addr (@others) {
12733: if (!grep(/^\Q$addr\E$/,@recipients)) {
12734: push(@recipients,$addr);
12735: }
1.618 raeburn 12736: }
12737: }
1.619 raeburn 12738: my $recipientlist = join(',',@recipients);
1.618 raeburn 12739: return $recipientlist;
12740: }
12741:
1.127 matthew 12742: ############################################################
12743: ############################################################
1.154 albertel 12744:
1.655 raeburn 12745: =pod
12746:
12747: =head1 Course Catalog Routines
12748:
12749: =over 4
12750:
12751: =item * &gather_categories()
12752:
12753: Converts category definitions - keys of categories hash stored in
12754: coursecategories in configuration.db on the primary library server in a
12755: domain - to an array. Also generates javascript and idx hash used to
12756: generate Domain Coordinator interface for editing Course Categories.
12757:
12758: Inputs:
1.663 raeburn 12759:
1.655 raeburn 12760: categories (reference to hash of category definitions).
1.663 raeburn 12761:
1.655 raeburn 12762: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12763: categories and subcategories).
1.663 raeburn 12764:
1.655 raeburn 12765: idx (reference to hash of counters used in Domain Coordinator interface for
12766: editing Course Categories).
1.663 raeburn 12767:
1.655 raeburn 12768: jsarray (reference to array of categories used to create Javascript arrays for
12769: Domain Coordinator interface for editing Course Categories).
12770:
12771: Returns: nothing
12772:
12773: Side effects: populates cats, idx and jsarray.
12774:
12775: =cut
12776:
12777: sub gather_categories {
12778: my ($categories,$cats,$idx,$jsarray) = @_;
12779: my %counters;
12780: my $num = 0;
12781: foreach my $item (keys(%{$categories})) {
12782: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12783: if ($container eq '' && $depth == 0) {
12784: $cats->[$depth][$categories->{$item}] = $cat;
12785: } else {
12786: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
12787: }
12788: my ($escitem,$tail) = split(/:/,$item,2);
12789: if ($counters{$tail} eq '') {
12790: $counters{$tail} = $num;
12791: $num ++;
12792: }
12793: if (ref($idx) eq 'HASH') {
12794: $idx->{$item} = $counters{$tail};
12795: }
12796: if (ref($jsarray) eq 'ARRAY') {
12797: push(@{$jsarray->[$counters{$tail}]},$item);
12798: }
12799: }
12800: return;
12801: }
12802:
12803: =pod
12804:
12805: =item * &extract_categories()
12806:
12807: Used to generate breadcrumb trails for course categories.
12808:
12809: Inputs:
1.663 raeburn 12810:
1.655 raeburn 12811: categories (reference to hash of category definitions).
1.663 raeburn 12812:
1.655 raeburn 12813: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12814: categories and subcategories).
1.663 raeburn 12815:
1.655 raeburn 12816: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 12817:
1.655 raeburn 12818: allitems (reference to hash - key is category key
12819: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12820:
1.655 raeburn 12821: idx (reference to hash of counters used in Domain Coordinator interface for
12822: editing Course Categories).
1.663 raeburn 12823:
1.655 raeburn 12824: jsarray (reference to array of categories used to create Javascript arrays for
12825: Domain Coordinator interface for editing Course Categories).
12826:
1.665 raeburn 12827: subcats (reference to hash of arrays containing all subcategories within each
12828: category, -recursive)
12829:
1.655 raeburn 12830: Returns: nothing
12831:
12832: Side effects: populates trails and allitems hash references.
12833:
12834: =cut
12835:
12836: sub extract_categories {
1.665 raeburn 12837: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 12838: if (ref($categories) eq 'HASH') {
12839: &gather_categories($categories,$cats,$idx,$jsarray);
12840: if (ref($cats->[0]) eq 'ARRAY') {
12841: for (my $i=0; $i<@{$cats->[0]}; $i++) {
12842: my $name = $cats->[0][$i];
12843: my $item = &escape($name).'::0';
12844: my $trailstr;
12845: if ($name eq 'instcode') {
12846: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 12847: } elsif ($name eq 'communities') {
12848: $trailstr = &mt('Communities');
1.655 raeburn 12849: } else {
12850: $trailstr = $name;
12851: }
12852: if ($allitems->{$item} eq '') {
12853: push(@{$trails},$trailstr);
12854: $allitems->{$item} = scalar(@{$trails})-1;
12855: }
12856: my @parents = ($name);
12857: if (ref($cats->[1]{$name}) eq 'ARRAY') {
12858: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
12859: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 12860: if (ref($subcats) eq 'HASH') {
12861: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
12862: }
12863: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
12864: }
12865: } else {
12866: if (ref($subcats) eq 'HASH') {
12867: $subcats->{$item} = [];
1.655 raeburn 12868: }
12869: }
12870: }
12871: }
12872: }
12873: return;
12874: }
12875:
12876: =pod
12877:
12878: =item *&recurse_categories()
12879:
12880: Recursively used to generate breadcrumb trails for course categories.
12881:
12882: Inputs:
1.663 raeburn 12883:
1.655 raeburn 12884: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12885: categories and subcategories).
1.663 raeburn 12886:
1.655 raeburn 12887: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 12888:
12889: category (current course category, for which breadcrumb trail is being generated).
12890:
12891: trails (reference to array of breadcrumb trails for each category).
12892:
1.655 raeburn 12893: allitems (reference to hash - key is category key
12894: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12895:
1.655 raeburn 12896: parents (array containing containers directories for current category,
12897: back to top level).
12898:
12899: Returns: nothing
12900:
12901: Side effects: populates trails and allitems hash references
12902:
12903: =cut
12904:
12905: sub recurse_categories {
1.665 raeburn 12906: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 12907: my $shallower = $depth - 1;
12908: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
12909: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
12910: my $name = $cats->[$depth]{$category}[$k];
12911: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
12912: my $trailstr = join(' -> ',(@{$parents},$category));
12913: if ($allitems->{$item} eq '') {
12914: push(@{$trails},$trailstr);
12915: $allitems->{$item} = scalar(@{$trails})-1;
12916: }
12917: my $deeper = $depth+1;
12918: push(@{$parents},$category);
1.665 raeburn 12919: if (ref($subcats) eq 'HASH') {
12920: my $subcat = &escape($name).':'.$category.':'.$depth;
12921: for (my $j=@{$parents}; $j>=0; $j--) {
12922: my $higher;
12923: if ($j > 0) {
12924: $higher = &escape($parents->[$j]).':'.
12925: &escape($parents->[$j-1]).':'.$j;
12926: } else {
12927: $higher = &escape($parents->[$j]).'::'.$j;
12928: }
12929: push(@{$subcats->{$higher}},$subcat);
12930: }
12931: }
12932: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
12933: $subcats);
1.655 raeburn 12934: pop(@{$parents});
12935: }
12936: } else {
12937: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
12938: my $trailstr = join(' -> ',(@{$parents},$category));
12939: if ($allitems->{$item} eq '') {
12940: push(@{$trails},$trailstr);
12941: $allitems->{$item} = scalar(@{$trails})-1;
12942: }
12943: }
12944: return;
12945: }
12946:
1.663 raeburn 12947: =pod
12948:
12949: =item *&assign_categories_table()
12950:
12951: Create a datatable for display of hierarchical categories in a domain,
12952: with checkboxes to allow a course to be categorized.
12953:
12954: Inputs:
12955:
12956: cathash - reference to hash of categories defined for the domain (from
12957: configuration.db)
12958:
12959: currcat - scalar with an & separated list of categories assigned to a course.
12960:
1.919 raeburn 12961: type - scalar contains course type (Course or Community).
12962:
1.663 raeburn 12963: Returns: $output (markup to be displayed)
12964:
12965: =cut
12966:
12967: sub assign_categories_table {
1.919 raeburn 12968: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 12969: my $output;
12970: if (ref($cathash) eq 'HASH') {
12971: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
12972: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
12973: $maxdepth = scalar(@cats);
12974: if (@cats > 0) {
12975: my $itemcount = 0;
12976: if (ref($cats[0]) eq 'ARRAY') {
12977: my @currcategories;
12978: if ($currcat ne '') {
12979: @currcategories = split('&',$currcat);
12980: }
1.919 raeburn 12981: my $table;
1.663 raeburn 12982: for (my $i=0; $i<@{$cats[0]}; $i++) {
12983: my $parent = $cats[0][$i];
1.919 raeburn 12984: next if ($parent eq 'instcode');
12985: if ($type eq 'Community') {
12986: next unless ($parent eq 'communities');
12987: } else {
12988: next if ($parent eq 'communities');
12989: }
1.663 raeburn 12990: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
12991: my $item = &escape($parent).'::0';
12992: my $checked = '';
12993: if (@currcategories > 0) {
12994: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 12995: $checked = ' checked="checked"';
1.663 raeburn 12996: }
12997: }
1.919 raeburn 12998: my $parent_title = $parent;
12999: if ($parent eq 'communities') {
13000: $parent_title = &mt('Communities');
13001: }
13002: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13003: '<input type="checkbox" name="usecategory" value="'.
13004: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13005: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13006: my $depth = 1;
13007: push(@path,$parent);
1.919 raeburn 13008: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13009: pop(@path);
1.919 raeburn 13010: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13011: $itemcount ++;
13012: }
1.919 raeburn 13013: if ($itemcount) {
13014: $output = &Apache::loncommon::start_data_table().
13015: $table.
13016: &Apache::loncommon::end_data_table();
13017: }
1.663 raeburn 13018: }
13019: }
13020: }
13021: return $output;
13022: }
13023:
13024: =pod
13025:
13026: =item *&assign_category_rows()
13027:
13028: Create a datatable row for display of nested categories in a domain,
13029: with checkboxes to allow a course to be categorized,called recursively.
13030:
13031: Inputs:
13032:
13033: itemcount - track row number for alternating colors
13034:
13035: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13036: categories and subcategories.
13037:
13038: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13039:
13040: parent - parent of current category item
13041:
13042: path - Array containing all categories back up through the hierarchy from the
13043: current category to the top level.
13044:
13045: currcategories - reference to array of current categories assigned to the course
13046:
13047: Returns: $output (markup to be displayed).
13048:
13049: =cut
13050:
13051: sub assign_category_rows {
13052: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13053: my ($text,$name,$item,$chgstr);
13054: if (ref($cats) eq 'ARRAY') {
13055: my $maxdepth = scalar(@{$cats});
13056: if (ref($cats->[$depth]) eq 'HASH') {
13057: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13058: my $numchildren = @{$cats->[$depth]{$parent}};
13059: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13060: $text .= '<td><table class="LC_datatable">';
13061: for (my $j=0; $j<$numchildren; $j++) {
13062: $name = $cats->[$depth]{$parent}[$j];
13063: $item = &escape($name).':'.&escape($parent).':'.$depth;
13064: my $deeper = $depth+1;
13065: my $checked = '';
13066: if (ref($currcategories) eq 'ARRAY') {
13067: if (@{$currcategories} > 0) {
13068: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13069: $checked = ' checked="checked"';
1.663 raeburn 13070: }
13071: }
13072: }
1.664 raeburn 13073: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13074: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13075: $item.'"'.$checked.' />'.$name.'</label></span>'.
13076: '<input type="hidden" name="catname" value="'.$name.'" />'.
13077: '</td><td>';
1.663 raeburn 13078: if (ref($path) eq 'ARRAY') {
13079: push(@{$path},$name);
13080: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13081: pop(@{$path});
13082: }
13083: $text .= '</td></tr>';
13084: }
13085: $text .= '</table></td>';
13086: }
13087: }
13088: }
13089: return $text;
13090: }
13091:
1.655 raeburn 13092: ############################################################
13093: ############################################################
13094:
13095:
1.443 albertel 13096: sub commit_customrole {
1.664 raeburn 13097: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13098: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13099: ($start?', '.&mt('starting').' '.localtime($start):'').
13100: ($end?', ending '.localtime($end):'').': <b>'.
13101: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13102: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13103: '</b><br />';
13104: return $output;
13105: }
13106:
13107: sub commit_standardrole {
1.541 raeburn 13108: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
13109: my ($output,$logmsg,$linefeed);
13110: if ($context eq 'auto') {
13111: $linefeed = "\n";
13112: } else {
13113: $linefeed = "<br />\n";
13114: }
1.443 albertel 13115: if ($three eq 'st') {
1.541 raeburn 13116: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
13117: $one,$two,$sec,$context);
13118: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13119: ($result eq 'unknown_course') || ($result eq 'refused')) {
13120: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13121: } else {
1.541 raeburn 13122: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13123: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13124: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13125: if ($context eq 'auto') {
13126: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13127: } else {
13128: $output .= '<b>'.$result.'</b>'.$linefeed.
13129: &mt('Add to classlist').': <b>ok</b>';
13130: }
13131: $output .= $linefeed;
1.443 albertel 13132: }
13133: } else {
13134: $output = &mt('Assigning').' '.$three.' in '.$url.
13135: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13136: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13137: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13138: if ($context eq 'auto') {
13139: $output .= $result.$linefeed;
13140: } else {
13141: $output .= '<b>'.$result.'</b>'.$linefeed;
13142: }
1.443 albertel 13143: }
13144: return $output;
13145: }
13146:
13147: sub commit_studentrole {
1.541 raeburn 13148: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 13149: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13150: if ($context eq 'auto') {
13151: $linefeed = "\n";
13152: } else {
13153: $linefeed = '<br />'."\n";
13154: }
1.443 albertel 13155: if (defined($one) && defined($two)) {
13156: my $cid=$one.'_'.$two;
13157: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13158: my $secchange = 0;
13159: my $expire_role_result;
13160: my $modify_section_result;
1.628 raeburn 13161: if ($oldsec ne '-1') {
13162: if ($oldsec ne $sec) {
1.443 albertel 13163: $secchange = 1;
1.628 raeburn 13164: my $now = time;
1.443 albertel 13165: my $uurl='/'.$cid;
13166: $uurl=~s/\_/\//g;
13167: if ($oldsec) {
13168: $uurl.='/'.$oldsec;
13169: }
1.626 raeburn 13170: $oldsecurl = $uurl;
1.628 raeburn 13171: $expire_role_result =
1.652 raeburn 13172: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13173: if ($env{'request.course.sec'} ne '') {
13174: if ($expire_role_result eq 'refused') {
13175: my @roles = ('st');
13176: my @statuses = ('previous');
13177: my @roledoms = ($one);
13178: my $withsec = 1;
13179: my %roleshash =
13180: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13181: \@statuses,\@roles,\@roledoms,$withsec);
13182: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13183: my ($oldstart,$oldend) =
13184: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13185: if ($oldend > 0 && $oldend <= $now) {
13186: $expire_role_result = 'ok';
13187: }
13188: }
13189: }
13190: }
1.443 albertel 13191: $result = $expire_role_result;
13192: }
13193: }
13194: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 13195: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 13196: if ($modify_section_result =~ /^ok/) {
13197: if ($secchange == 1) {
1.628 raeburn 13198: if ($sec eq '') {
13199: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13200: } else {
13201: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13202: }
1.443 albertel 13203: } elsif ($oldsec eq '-1') {
1.628 raeburn 13204: if ($sec eq '') {
13205: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13206: } else {
13207: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13208: }
1.443 albertel 13209: } else {
1.628 raeburn 13210: if ($sec eq '') {
13211: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13212: } else {
13213: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13214: }
1.443 albertel 13215: }
13216: } else {
1.628 raeburn 13217: if ($secchange) {
13218: $$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;
13219: } else {
13220: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13221: }
1.443 albertel 13222: }
13223: $result = $modify_section_result;
13224: } elsif ($secchange == 1) {
1.628 raeburn 13225: if ($oldsec eq '') {
13226: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
13227: } else {
13228: $$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;
13229: }
1.626 raeburn 13230: if ($expire_role_result eq 'refused') {
13231: my $newsecurl = '/'.$cid;
13232: $newsecurl =~ s/\_/\//g;
13233: if ($sec ne '') {
13234: $newsecurl.='/'.$sec;
13235: }
13236: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13237: if ($sec eq '') {
13238: $$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;
13239: } else {
13240: $$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;
13241: }
13242: }
13243: }
1.443 albertel 13244: }
13245: } else {
1.626 raeburn 13246: $$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 13247: $result = "error: incomplete course id\n";
13248: }
13249: return $result;
13250: }
13251:
13252: ############################################################
13253: ############################################################
13254:
1.566 albertel 13255: sub check_clone {
1.578 raeburn 13256: my ($args,$linefeed) = @_;
1.566 albertel 13257: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13258: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13259: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13260: my $clonemsg;
13261: my $can_clone = 0;
1.944 raeburn 13262: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13263: if ($lctype ne 'community') {
13264: $lctype = 'course';
13265: }
1.566 albertel 13266: if ($clonehome eq 'no_host') {
1.944 raeburn 13267: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13268: $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'});
13269: } else {
13270: $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'});
13271: }
1.566 albertel 13272: } else {
13273: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13274: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13275: if ($clonedesc{'type'} ne 'Community') {
13276: $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'});
13277: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13278: }
13279: }
1.882 raeburn 13280: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13281: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13282: $can_clone = 1;
13283: } else {
13284: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13285: $args->{'clonedomain'},$args->{'clonecourse'});
13286: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13287: if (grep(/^\*$/,@cloners)) {
13288: $can_clone = 1;
13289: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13290: $can_clone = 1;
13291: } else {
1.908 raeburn 13292: my $ccrole = 'cc';
1.944 raeburn 13293: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13294: $ccrole = 'co';
13295: }
1.578 raeburn 13296: my %roleshash =
13297: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13298: $args->{'ccdomain'},
1.908 raeburn 13299: 'userroles',['active'],[$ccrole],
1.578 raeburn 13300: [$args->{'clonedomain'}]);
1.908 raeburn 13301: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13302: $can_clone = 1;
13303: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13304: $can_clone = 1;
13305: } else {
1.944 raeburn 13306: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13307: $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'});
13308: } else {
13309: $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'});
13310: }
1.578 raeburn 13311: }
1.566 albertel 13312: }
1.578 raeburn 13313: }
1.566 albertel 13314: }
13315: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13316: }
13317:
1.444 albertel 13318: sub construct_course {
1.885 raeburn 13319: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13320: my $outcome;
1.541 raeburn 13321: my $linefeed = '<br />'."\n";
13322: if ($context eq 'auto') {
13323: $linefeed = "\n";
13324: }
1.566 albertel 13325:
13326: #
13327: # Are we cloning?
13328: #
13329: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13330: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13331: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13332: if ($context ne 'auto') {
1.578 raeburn 13333: if ($clonemsg ne '') {
13334: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13335: }
1.566 albertel 13336: }
13337: $outcome .= $clonemsg.$linefeed;
13338:
13339: if (!$can_clone) {
13340: return (0,$outcome);
13341: }
13342: }
13343:
1.444 albertel 13344: #
13345: # Open course
13346: #
13347: my $crstype = lc($args->{'crstype'});
13348: my %cenv=();
13349: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13350: $args->{'cdescr'},
13351: $args->{'curl'},
13352: $args->{'course_home'},
13353: $args->{'nonstandard'},
13354: $args->{'crscode'},
13355: $args->{'ccuname'}.':'.
13356: $args->{'ccdomain'},
1.882 raeburn 13357: $args->{'crstype'},
1.885 raeburn 13358: $cnum,$context,$category);
1.444 albertel 13359:
13360: # Note: The testing routines depend on this being output; see
13361: # Utils::Course. This needs to at least be output as a comment
13362: # if anyone ever decides to not show this, and Utils::Course::new
13363: # will need to be suitably modified.
1.541 raeburn 13364: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13365: if ($$courseid =~ /^error:/) {
13366: return (0,$outcome);
13367: }
13368:
1.444 albertel 13369: #
13370: # Check if created correctly
13371: #
1.479 albertel 13372: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13373: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13374: if ($crsuhome eq 'no_host') {
13375: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13376: return (0,$outcome);
13377: }
1.541 raeburn 13378: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13379:
1.444 albertel 13380: #
1.566 albertel 13381: # Do the cloning
13382: #
13383: if ($can_clone && $cloneid) {
13384: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13385: if ($context ne 'auto') {
13386: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13387: }
13388: $outcome .= $clonemsg.$linefeed;
13389: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13390: # Copy all files
1.637 www 13391: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13392: # Restore URL
1.566 albertel 13393: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13394: # Restore title
1.566 albertel 13395: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13396: # Restore creation date, creator and creation context.
13397: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13398: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13399: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13400: # Mark as cloned
1.566 albertel 13401: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13402: # Need to clone grading mode
13403: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13404: $cenv{'grading'}=$newenv{'grading'};
13405: # Do not clone these environment entries
13406: &Apache::lonnet::del('environment',
13407: ['default_enrollment_start_date',
13408: 'default_enrollment_end_date',
13409: 'question.email',
13410: 'policy.email',
13411: 'comment.email',
13412: 'pch.users.denied',
1.725 raeburn 13413: 'plc.users.denied',
13414: 'hidefromcat',
13415: 'categories'],
1.638 www 13416: $$crsudom,$$crsunum);
1.444 albertel 13417: }
1.566 albertel 13418:
1.444 albertel 13419: #
13420: # Set environment (will override cloned, if existing)
13421: #
13422: my @sections = ();
13423: my @xlists = ();
13424: if ($args->{'crstype'}) {
13425: $cenv{'type'}=$args->{'crstype'};
13426: }
13427: if ($args->{'crsid'}) {
13428: $cenv{'courseid'}=$args->{'crsid'};
13429: }
13430: if ($args->{'crscode'}) {
13431: $cenv{'internal.coursecode'}=$args->{'crscode'};
13432: }
13433: if ($args->{'crsquota'} ne '') {
13434: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13435: } else {
13436: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13437: }
13438: if ($args->{'ccuname'}) {
13439: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13440: ':'.$args->{'ccdomain'};
13441: } else {
13442: $cenv{'internal.courseowner'} = $args->{'curruser'};
13443: }
13444: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13445: if ($args->{'crssections'}) {
13446: $cenv{'internal.sectionnums'} = '';
13447: if ($args->{'crssections'} =~ m/,/) {
13448: @sections = split/,/,$args->{'crssections'};
13449: } else {
13450: $sections[0] = $args->{'crssections'};
13451: }
13452: if (@sections > 0) {
13453: foreach my $item (@sections) {
13454: my ($sec,$gp) = split/:/,$item;
13455: my $class = $args->{'crscode'}.$sec;
13456: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13457: $cenv{'internal.sectionnums'} .= $item.',';
13458: unless ($addcheck eq 'ok') {
13459: push @badclasses, $class;
13460: }
13461: }
13462: $cenv{'internal.sectionnums'} =~ s/,$//;
13463: }
13464: }
13465: # do not hide course coordinator from staff listing,
13466: # even if privileged
13467: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13468: # add crosslistings
13469: if ($args->{'crsxlist'}) {
13470: $cenv{'internal.crosslistings'}='';
13471: if ($args->{'crsxlist'} =~ m/,/) {
13472: @xlists = split/,/,$args->{'crsxlist'};
13473: } else {
13474: $xlists[0] = $args->{'crsxlist'};
13475: }
13476: if (@xlists > 0) {
13477: foreach my $item (@xlists) {
13478: my ($xl,$gp) = split/:/,$item;
13479: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13480: $cenv{'internal.crosslistings'} .= $item.',';
13481: unless ($addcheck eq 'ok') {
13482: push @badclasses, $xl;
13483: }
13484: }
13485: $cenv{'internal.crosslistings'} =~ s/,$//;
13486: }
13487: }
13488: if ($args->{'autoadds'}) {
13489: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13490: }
13491: if ($args->{'autodrops'}) {
13492: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13493: }
13494: # check for notification of enrollment changes
13495: my @notified = ();
13496: if ($args->{'notify_owner'}) {
13497: if ($args->{'ccuname'} ne '') {
13498: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13499: }
13500: }
13501: if ($args->{'notify_dc'}) {
13502: if ($uname ne '') {
1.630 raeburn 13503: push(@notified,$uname.':'.$udom);
1.444 albertel 13504: }
13505: }
13506: if (@notified > 0) {
13507: my $notifylist;
13508: if (@notified > 1) {
13509: $notifylist = join(',',@notified);
13510: } else {
13511: $notifylist = $notified[0];
13512: }
13513: $cenv{'internal.notifylist'} = $notifylist;
13514: }
13515: if (@badclasses > 0) {
13516: my %lt=&Apache::lonlocal::texthash(
13517: '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',
13518: 'dnhr' => 'does not have rights to access enrollment in these classes',
13519: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13520: );
1.541 raeburn 13521: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13522: ' ('.$lt{'adby'}.')';
13523: if ($context eq 'auto') {
13524: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13525: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13526: foreach my $item (@badclasses) {
13527: if ($context eq 'auto') {
13528: $outcome .= " - $item\n";
13529: } else {
13530: $outcome .= "<li>$item</li>\n";
13531: }
13532: }
13533: if ($context eq 'auto') {
13534: $outcome .= $linefeed;
13535: } else {
1.566 albertel 13536: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13537: }
13538: }
1.444 albertel 13539: }
13540: if ($args->{'no_end_date'}) {
13541: $args->{'endaccess'} = 0;
13542: }
13543: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13544: $cenv{'internal.autoend'}=$args->{'enrollend'};
13545: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13546: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13547: if ($args->{'showphotos'}) {
13548: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13549: }
13550: $cenv{'internal.authtype'} = $args->{'authtype'};
13551: $cenv{'internal.autharg'} = $args->{'autharg'};
13552: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13553: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13554: 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');
13555: if ($context eq 'auto') {
13556: $outcome .= $krb_msg;
13557: } else {
1.566 albertel 13558: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13559: }
13560: $outcome .= $linefeed;
1.444 albertel 13561: }
13562: }
13563: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13564: if ($args->{'setpolicy'}) {
13565: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13566: }
13567: if ($args->{'setcontent'}) {
13568: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13569: }
13570: }
13571: if ($args->{'reshome'}) {
13572: $cenv{'reshome'}=$args->{'reshome'}.'/';
13573: $cenv{'reshome'}=~s/\/+$/\//;
13574: }
13575: #
13576: # course has keyed access
13577: #
13578: if ($args->{'setkeys'}) {
13579: $cenv{'keyaccess'}='yes';
13580: }
13581: # if specified, key authority is not course, but user
13582: # only active if keyaccess is yes
13583: if ($args->{'keyauth'}) {
1.487 albertel 13584: my ($user,$domain) = split(':',$args->{'keyauth'});
13585: $user = &LONCAPA::clean_username($user);
13586: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 13587: if ($user ne '' && $domain ne '') {
1.487 albertel 13588: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 13589: }
13590: }
13591:
13592: if ($args->{'disresdis'}) {
13593: $cenv{'pch.roles.denied'}='st';
13594: }
13595: if ($args->{'disablechat'}) {
13596: $cenv{'plc.roles.denied'}='st';
13597: }
13598:
13599: # Record we've not yet viewed the Course Initialization Helper for this
13600: # course
13601: $cenv{'course.helper.not.run'} = 1;
13602: #
13603: # Use new Randomseed
13604: #
13605: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
13606: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
13607: #
13608: # The encryption code and receipt prefix for this course
13609: #
13610: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
13611: $cenv{'internal.encpref'}=100+int(9*rand(99));
13612: #
13613: # By default, use standard grading
13614: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
13615:
1.541 raeburn 13616: $outcome .= $linefeed.&mt('Setting environment').': '.
13617: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13618: #
13619: # Open all assignments
13620: #
13621: if ($args->{'openall'}) {
13622: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
13623: my %storecontent = ($storeunder => time,
13624: $storeunder.'.type' => 'date_start');
13625:
13626: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 13627: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13628: }
13629: #
13630: # Set first page
13631: #
13632: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
13633: || ($cloneid)) {
1.445 albertel 13634: use LONCAPA::map;
1.444 albertel 13635: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 13636:
13637: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
13638: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
13639:
1.444 albertel 13640: $outcome .= ($fatal?$errtext:'read ok').' - ';
13641: my $title; my $url;
13642: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 13643: $title=&mt('Syllabus');
1.444 albertel 13644: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
13645: } else {
1.963 raeburn 13646: $title=&mt('Table of Contents');
1.444 albertel 13647: $url='/adm/navmaps';
13648: }
1.445 albertel 13649:
13650: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
13651: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
13652:
13653: if ($errtext) { $fatal=2; }
1.541 raeburn 13654: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 13655: }
1.566 albertel 13656:
13657: return (1,$outcome);
1.444 albertel 13658: }
13659:
13660: ############################################################
13661: ############################################################
13662:
1.953 droeschl 13663: #SD
13664: # only Community and Course, or anything else?
1.378 raeburn 13665: sub course_type {
13666: my ($cid) = @_;
13667: if (!defined($cid)) {
13668: $cid = $env{'request.course.id'};
13669: }
1.404 albertel 13670: if (defined($env{'course.'.$cid.'.type'})) {
13671: return $env{'course.'.$cid.'.type'};
1.378 raeburn 13672: } else {
13673: return 'Course';
1.377 raeburn 13674: }
13675: }
1.156 albertel 13676:
1.406 raeburn 13677: sub group_term {
13678: my $crstype = &course_type();
13679: my %names = (
13680: 'Course' => 'group',
1.865 raeburn 13681: 'Community' => 'group',
1.406 raeburn 13682: );
13683: return $names{$crstype};
13684: }
13685:
1.902 raeburn 13686: sub course_types {
13687: my @types = ('official','unofficial','community');
13688: my %typename = (
13689: official => 'Official course',
13690: unofficial => 'Unofficial course',
13691: community => 'Community',
13692: );
13693: return (\@types,\%typename);
13694: }
13695:
1.156 albertel 13696: sub icon {
13697: my ($file)=@_;
1.505 albertel 13698: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 13699: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 13700: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 13701: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
13702: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
13703: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13704: $curfext.".gif") {
13705: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13706: $curfext.".gif";
13707: }
13708: }
1.249 albertel 13709: return &lonhttpdurl($iconname);
1.154 albertel 13710: }
1.84 albertel 13711:
1.575 albertel 13712: sub lonhttpdurl {
1.692 www 13713: #
13714: # Had been used for "small fry" static images on separate port 8080.
13715: # Modify here if lightweight http functionality desired again.
13716: # Currently eliminated due to increasing firewall issues.
13717: #
1.575 albertel 13718: my ($url)=@_;
1.692 www 13719: return $url;
1.215 albertel 13720: }
13721:
1.213 albertel 13722: sub connection_aborted {
13723: my ($r)=@_;
13724: $r->print(" ");$r->rflush();
13725: my $c = $r->connection;
13726: return $c->aborted();
13727: }
13728:
1.221 foxr 13729: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 13730: # strings as 'strings'.
13731: sub escape_single {
1.221 foxr 13732: my ($input) = @_;
1.223 albertel 13733: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 13734: $input =~ s/\'/\\\'/g; # Esacpe the 's....
13735: return $input;
13736: }
1.223 albertel 13737:
1.222 foxr 13738: # Same as escape_single, but escape's "'s This
13739: # can be used for "strings"
13740: sub escape_double {
13741: my ($input) = @_;
13742: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
13743: $input =~ s/\"/\\\"/g; # Esacpe the "s....
13744: return $input;
13745: }
1.223 albertel 13746:
1.222 foxr 13747: # Escapes the last element of a full URL.
13748: sub escape_url {
13749: my ($url) = @_;
1.238 raeburn 13750: my @urlslices = split(/\//, $url,-1);
1.369 www 13751: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 13752: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 13753: }
1.462 albertel 13754:
1.820 raeburn 13755: sub compare_arrays {
13756: my ($arrayref1,$arrayref2) = @_;
13757: my (@difference,%count);
13758: @difference = ();
13759: %count = ();
13760: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
13761: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
13762: foreach my $element (keys(%count)) {
13763: if ($count{$element} == 1) {
13764: push(@difference,$element);
13765: }
13766: }
13767: }
13768: return @difference;
13769: }
13770:
1.817 bisitz 13771: # -------------------------------------------------------- Initialize user login
1.462 albertel 13772: sub init_user_environment {
1.463 albertel 13773: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 13774: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
13775:
13776: my $public=($username eq 'public' && $domain eq 'public');
13777:
13778: # See if old ID present, if so, remove
13779:
1.1062 raeburn 13780: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 13781: my $now=time;
13782:
13783: if ($public) {
13784: my $max_public=100;
13785: my $oldest;
13786: my $oldest_time=0;
13787: for(my $next=1;$next<=$max_public;$next++) {
13788: if (-e $lonids."/publicuser_$next.id") {
13789: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
13790: if ($mtime<$oldest_time || !$oldest_time) {
13791: $oldest_time=$mtime;
13792: $oldest=$next;
13793: }
13794: } else {
13795: $cookie="publicuser_$next";
13796: last;
13797: }
13798: }
13799: if (!$cookie) { $cookie="publicuser_$oldest"; }
13800: } else {
1.463 albertel 13801: # if this isn't a robot, kill any existing non-robot sessions
13802: if (!$args->{'robot'}) {
13803: opendir(DIR,$lonids);
13804: while ($filename=readdir(DIR)) {
13805: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
13806: unlink($lonids.'/'.$filename);
13807: }
1.462 albertel 13808: }
1.463 albertel 13809: closedir(DIR);
1.462 albertel 13810: }
13811: # Give them a new cookie
1.463 albertel 13812: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 13813: : $now.$$.int(rand(10000)));
1.463 albertel 13814: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 13815:
13816: # Initialize roles
13817:
1.1062 raeburn 13818: ($userroles,$firstaccenv,$timerintenv) =
13819: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 13820: }
13821: # ------------------------------------ Check browser type and MathML capability
13822:
13823: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
13824: $clientunicode,$clientos) = &decode_user_agent($r);
13825:
13826: # ------------------------------------------------------------- Get environment
13827:
13828: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
13829: my ($tmp) = keys(%userenv);
13830: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
13831: } else {
13832: undef(%userenv);
13833: }
13834: if (($userenv{'interface'}) && (!$form->{'interface'})) {
13835: $form->{'interface'}=$userenv{'interface'};
13836: }
13837: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
13838:
13839: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 13840: foreach my $option ('interface','localpath','localres') {
13841: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 13842: }
13843: # --------------------------------------------------------- Write first profile
13844:
13845: {
13846: my %initial_env =
13847: ("user.name" => $username,
13848: "user.domain" => $domain,
13849: "user.home" => $authhost,
13850: "browser.type" => $clientbrowser,
13851: "browser.version" => $clientversion,
13852: "browser.mathml" => $clientmathml,
13853: "browser.unicode" => $clientunicode,
13854: "browser.os" => $clientos,
13855: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
13856: "request.course.fn" => '',
13857: "request.course.uri" => '',
13858: "request.course.sec" => '',
13859: "request.role" => 'cm',
13860: "request.role.adv" => $env{'user.adv'},
13861: "request.host" => $ENV{'REMOTE_ADDR'},);
13862:
13863: if ($form->{'localpath'}) {
13864: $initial_env{"browser.localpath"} = $form->{'localpath'};
13865: $initial_env{"browser.localres"} = $form->{'localres'};
13866: }
13867:
13868: if ($form->{'interface'}) {
13869: $form->{'interface'}=~s/\W//gs;
13870: $initial_env{"browser.interface"} = $form->{'interface'};
13871: $env{'browser.interface'}=$form->{'interface'};
13872: }
13873:
1.981 raeburn 13874: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 13875: my %domdef;
13876: unless ($domain eq 'public') {
13877: %domdef = &Apache::lonnet::get_domain_defaults($domain);
13878: }
1.980 raeburn 13879:
1.1075.2.7 raeburn 13880: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 13881: $userenv{'availabletools.'.$tool} =
1.980 raeburn 13882: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
13883: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 13884: }
13885:
1.864 raeburn 13886: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 13887: $userenv{'canrequest.'.$crstype} =
13888: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 13889: 'reload','requestcourses',
13890: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 13891: }
13892:
1.1075.2.14! raeburn 13893: $userenv{'canrequest.author'} =
! 13894: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
! 13895: 'reload','requestauthor',
! 13896: \%userenv,\%domdef,\%is_adv);
! 13897: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
! 13898: $domain,$username);
! 13899: my $reqstatus = $reqauthor{'author_status'};
! 13900: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
! 13901: if (ref($reqauthor{'author'}) eq 'HASH') {
! 13902: $userenv{'requestauthorqueued'} = $reqstatus.':'.
! 13903: $reqauthor{'author'}{'timestamp'};
! 13904: }
! 13905: }
! 13906:
1.462 albertel 13907: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 13908:
1.462 albertel 13909: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
13910: &GDBM_WRCREAT(),0640)) {
13911: &_add_to_env(\%disk_env,\%initial_env);
13912: &_add_to_env(\%disk_env,\%userenv,'environment.');
13913: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 13914: if (ref($firstaccenv) eq 'HASH') {
13915: &_add_to_env(\%disk_env,$firstaccenv);
13916: }
13917: if (ref($timerintenv) eq 'HASH') {
13918: &_add_to_env(\%disk_env,$timerintenv);
13919: }
1.463 albertel 13920: if (ref($args->{'extra_env'})) {
13921: &_add_to_env(\%disk_env,$args->{'extra_env'});
13922: }
1.462 albertel 13923: untie(%disk_env);
13924: } else {
1.705 tempelho 13925: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
13926: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 13927: return 'error: '.$!;
13928: }
13929: }
13930: $env{'request.role'}='cm';
13931: $env{'request.role.adv'}=$env{'user.adv'};
13932: $env{'browser.type'}=$clientbrowser;
13933:
13934: return $cookie;
13935:
13936: }
13937:
13938: sub _add_to_env {
13939: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 13940: if (ref($env_data) eq 'HASH') {
13941: while (my ($key,$value) = each(%$env_data)) {
13942: $idf->{$prefix.$key} = $value;
13943: $env{$prefix.$key} = $value;
13944: }
1.462 albertel 13945: }
13946: }
13947:
1.685 tempelho 13948: # --- Get the symbolic name of a problem and the url
13949: sub get_symb {
13950: my ($request,$silent) = @_;
1.726 raeburn 13951: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 13952: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
13953: if ($symb eq '') {
13954: if (!$silent) {
1.1071 raeburn 13955: if (ref($request)) {
13956: $request->print("Unable to handle ambiguous references:$url:.");
13957: }
1.685 tempelho 13958: return ();
13959: }
13960: }
13961: &Apache::lonenc::check_decrypt(\$symb);
13962: return ($symb);
13963: }
13964:
13965: # --------------------------------------------------------------Get annotation
13966:
13967: sub get_annotation {
13968: my ($symb,$enc) = @_;
13969:
13970: my $key = $symb;
13971: if (!$enc) {
13972: $key =
13973: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
13974: }
13975: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
13976: return $annotation{$key};
13977: }
13978:
13979: sub clean_symb {
1.731 raeburn 13980: my ($symb,$delete_enc) = @_;
1.685 tempelho 13981:
13982: &Apache::lonenc::check_decrypt(\$symb);
13983: my $enc = $env{'request.enc'};
1.731 raeburn 13984: if ($delete_enc) {
1.730 raeburn 13985: delete($env{'request.enc'});
13986: }
1.685 tempelho 13987:
13988: return ($symb,$enc);
13989: }
1.462 albertel 13990:
1.990 raeburn 13991: sub build_release_hashes {
13992: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
13993: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
13994: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
13995: (ref($randomizetry) eq 'HASH'));
13996: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
13997: my ($item,$name,$value) = split(/:/,$key);
13998: if ($item eq 'parameter') {
13999: if (ref($checkparms->{$name}) eq 'ARRAY') {
14000: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14001: push(@{$checkparms->{$name}},$value);
14002: }
14003: } else {
14004: push(@{$checkparms->{$name}},$value);
14005: }
14006: } elsif ($item eq 'resourcetag') {
14007: if ($name eq 'responsetype') {
14008: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14009: }
14010: } elsif ($item eq 'course') {
14011: if ($name eq 'crstype') {
14012: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14013: }
14014: }
14015: }
14016: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14017: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14018: return;
14019: }
14020:
1.1075.2.11 raeburn 14021: sub update_content_constraints {
14022: my ($cdom,$cnum,$chome,$cid) = @_;
14023: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14024: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14025: my %checkresponsetypes;
14026: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14027: my ($item,$name,$value) = split(/:/,$key);
14028: if ($item eq 'resourcetag') {
14029: if ($name eq 'responsetype') {
14030: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14031: }
14032: }
14033: }
14034: my $navmap = Apache::lonnavmaps::navmap->new();
14035: if (defined($navmap)) {
14036: my %allresponses;
14037: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14038: my %responses = $res->responseTypes();
14039: foreach my $key (keys(%responses)) {
14040: next unless(exists($checkresponsetypes{$key}));
14041: $allresponses{$key} += $responses{$key};
14042: }
14043: }
14044: foreach my $key (keys(%allresponses)) {
14045: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14046: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14047: ($reqdmajor,$reqdminor) = ($major,$minor);
14048: }
14049: }
14050: undef($navmap);
14051: }
14052: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14053: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14054: }
14055: return;
14056: }
14057:
14058: sub parse_supplemental_title {
14059: my ($title) = @_;
14060:
14061: my ($foldertitle,$renametitle);
14062: if ($title =~ /&&&/) {
14063: $title = &HTML::Entites::decode($title);
14064: }
14065: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14066: $renametitle=$4;
14067: my ($time,$uname,$udom) = ($1,$2,$3);
14068: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14069: my $name = &plainname($uname,$udom);
14070: $name = &HTML::Entities::encode($name,'"<>&\'');
14071: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14072: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14073: $name.': <br />'.$foldertitle;
14074: }
14075: if (wantarray) {
14076: return ($title,$foldertitle,$renametitle);
14077: }
14078: return $title;
14079: }
14080:
1.1075.2.14! raeburn 14081: sub captcha_display {
! 14082: my ($context,$lonhost) = @_;
! 14083: my ($output,$error);
! 14084: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
! 14085: if ($captcha eq 'original') {
! 14086: $output = &create_captcha();
! 14087: unless ($output) {
! 14088: $error = 'captcha';
! 14089: }
! 14090: } elsif ($captcha eq 'recaptcha') {
! 14091: $output = &create_recaptcha($pubkey);
! 14092: unless ($output) {
! 14093: $error = 'recaptcha';
! 14094: }
! 14095: }
! 14096: return ($output,$error);
! 14097: }
! 14098:
! 14099: sub captcha_response {
! 14100: my ($context,$lonhost) = @_;
! 14101: my ($captcha_chk,$captcha_error);
! 14102: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
! 14103: if ($captcha eq 'original') {
! 14104: ($captcha_chk,$captcha_error) = &check_captcha();
! 14105: } elsif ($captcha eq 'recaptcha') {
! 14106: $captcha_chk = &check_recaptcha($privkey);
! 14107: } else {
! 14108: $captcha_chk = 1;
! 14109: }
! 14110: return ($captcha_chk,$captcha_error);
! 14111: }
! 14112:
! 14113: sub get_captcha_config {
! 14114: my ($context,$lonhost) = @_;
! 14115: my ($captcha,$pubkey,$privkey,$hashtocheck);
! 14116: my $hostname = &Apache::lonnet::hostname($lonhost);
! 14117: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
! 14118: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
! 14119: if ($context eq 'usercreation') {
! 14120: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
! 14121: if (ref($domconfig{$context}) eq 'HASH') {
! 14122: $hashtocheck = $domconfig{$context}{'cancreate'};
! 14123: if (ref($hashtocheck) eq 'HASH') {
! 14124: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
! 14125: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
! 14126: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
! 14127: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
! 14128: }
! 14129: if ($privkey && $pubkey) {
! 14130: $captcha = 'recaptcha';
! 14131: } else {
! 14132: $captcha = 'original';
! 14133: }
! 14134: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
! 14135: $captcha = 'original';
! 14136: }
! 14137: }
! 14138: } else {
! 14139: $captcha = 'captcha';
! 14140: }
! 14141: } elsif ($context eq 'login') {
! 14142: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
! 14143: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
! 14144: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
! 14145: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
! 14146: if ($privkey && $pubkey) {
! 14147: $captcha = 'recaptcha';
! 14148: } else {
! 14149: $captcha = 'original';
! 14150: }
! 14151: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
! 14152: $captcha = 'original';
! 14153: }
! 14154: }
! 14155: return ($captcha,$pubkey,$privkey);
! 14156: }
! 14157:
! 14158: sub create_captcha {
! 14159: my %captcha_params = &captcha_settings();
! 14160: my ($output,$maxtries,$tries) = ('',10,0);
! 14161: while ($tries < $maxtries) {
! 14162: $tries ++;
! 14163: my $captcha = Authen::Captcha->new (
! 14164: output_folder => $captcha_params{'output_dir'},
! 14165: data_folder => $captcha_params{'db_dir'},
! 14166: );
! 14167: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
! 14168:
! 14169: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
! 14170: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
! 14171: &mt('Type in the letters/numbers shown below').' '.
! 14172: '<input type="text" size="5" name="code" value="" /><br />'.
! 14173: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
! 14174: last;
! 14175: }
! 14176: }
! 14177: return $output;
! 14178: }
! 14179:
! 14180: sub captcha_settings {
! 14181: my %captcha_params = (
! 14182: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
! 14183: www_output_dir => "/captchaspool",
! 14184: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
! 14185: numchars => '5',
! 14186: );
! 14187: return %captcha_params;
! 14188: }
! 14189:
! 14190: sub check_captcha {
! 14191: my ($captcha_chk,$captcha_error);
! 14192: my $code = $env{'form.code'};
! 14193: my $md5sum = $env{'form.crypt'};
! 14194: my %captcha_params = &captcha_settings();
! 14195: my $captcha = Authen::Captcha->new(
! 14196: output_folder => $captcha_params{'output_dir'},
! 14197: data_folder => $captcha_params{'db_dir'},
! 14198: );
! 14199: my $captcha_chk = $captcha->check_code($code,$md5sum);
! 14200: my %captcha_hash = (
! 14201: 0 => 'Code not checked (file error)',
! 14202: -1 => 'Failed: code expired',
! 14203: -2 => 'Failed: invalid code (not in database)',
! 14204: -3 => 'Failed: invalid code (code does not match crypt)',
! 14205: );
! 14206: if ($captcha_chk != 1) {
! 14207: $captcha_error = $captcha_hash{$captcha_chk}
! 14208: }
! 14209: return ($captcha_chk,$captcha_error);
! 14210: }
! 14211:
! 14212: sub create_recaptcha {
! 14213: my ($pubkey) = @_;
! 14214: my $captcha = Captcha::reCAPTCHA->new;
! 14215: return $captcha->get_options_setter({theme => 'white'})."\n".
! 14216: $captcha->get_html($pubkey).
! 14217: &mt('If either word is hard to read, [_1] will replace them.',
! 14218: '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
! 14219: '<br /><br />';
! 14220: }
! 14221:
! 14222: sub check_recaptcha {
! 14223: my ($privkey) = @_;
! 14224: my $captcha_chk;
! 14225: my $captcha = Captcha::reCAPTCHA->new;
! 14226: my $captcha_result =
! 14227: $captcha->check_answer(
! 14228: $privkey,
! 14229: $ENV{'REMOTE_ADDR'},
! 14230: $env{'form.recaptcha_challenge_field'},
! 14231: $env{'form.recaptcha_response_field'},
! 14232: );
! 14233: if ($captcha_result->{is_valid}) {
! 14234: $captcha_chk = 1;
! 14235: }
! 14236: return $captcha_chk;
! 14237: }
! 14238:
1.41 ng 14239: =pod
14240:
14241: =back
14242:
1.112 bowersj2 14243: =cut
1.41 ng 14244:
1.112 bowersj2 14245: 1;
14246: __END__;
1.41 ng 14247:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>