Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.25
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.161. .25(raeb 4:-24): # $Id: loncommon.pm,v 1.1075.2.161.2.24 2024/03/29 00:45:24 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.1075.2.161. .7(raebu 64:22): use Apache::lonnavmaps();
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.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1075.2.161. .13(raeb 74:-23): use LONCAPA::map();
1.1075.2.135 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1075.2.102 raeburn 77: use DateTime::Locale;
1.1075.2.94 raeburn 78: use Encode();
1.1075.2.14 raeburn 79: use Authen::Captcha;
80: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 81: use JSON::DWIW;
82: use LWP::UserAgent;
1.1075.2.64 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 85: use File::Copy();
86: use File::Path();
1.1075.2.161. .1(raebu 87:21): use String::CRC32();
88:21): use Short::URL();
1.117 www 89:
1.517 raeburn 90: # ---------------------------------------------- Designs
91: use vars qw(%defaultdesign);
92:
1.22 www 93: my $readit;
94:
1.517 raeburn 95:
1.157 matthew 96: ##
97: ## Global Variables
98: ##
1.46 matthew 99:
1.643 foxr 100:
101: # ----------------------------------------------- SSI with retries:
102: #
103:
104: =pod
105:
1.648 raeburn 106: =head1 Server Side include with retries:
1.643 foxr 107:
108: =over 4
109:
1.648 raeburn 110: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 111:
112: Performs an ssi with some number of retries. Retries continue either
113: until the result is ok or until the retry count supplied by the
114: caller is exhausted.
115:
116: Inputs:
1.648 raeburn 117:
118: =over 4
119:
1.643 foxr 120: resource - Identifies the resource to insert.
1.648 raeburn 121:
1.643 foxr 122: retries - Count of the number of retries allowed.
1.648 raeburn 123:
1.643 foxr 124: form - Hash that identifies the rendering options.
125:
1.648 raeburn 126: =back
127:
128: Returns:
129:
130: =over 4
131:
1.643 foxr 132: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 133:
1.643 foxr 134: response - The response from the last attempt (which may or may not have been successful.
135:
1.648 raeburn 136: =back
137:
138: =back
139:
1.643 foxr 140: =cut
141:
142: sub ssi_with_retries {
143: my ($resource, $retries, %form) = @_;
144:
145:
146: my $ok = 0; # True if we got a good response.
147: my $content;
148: my $response;
149:
150: # Try to get the ssi done. within the retries count:
151:
152: do {
153: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
154: $ok = $response->is_success;
1.650 www 155: if (!$ok) {
156: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
157: }
1.643 foxr 158: $retries--;
159: } while (!$ok && ($retries > 0));
160:
161: if (!$ok) {
162: $content = ''; # On error return an empty content.
163: }
164: return ($content, $response);
165:
166: }
167:
168:
169:
1.20 www 170: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 171: my %language;
1.124 www 172: my %supported_language;
1.1048 foxr 173: my %latex_language; # For choosing hyphenation in <transl..>
174: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 175: my %cprtag;
1.192 taceyjo1 176: my %scprtag;
1.351 www 177: my %fe; my %fd; my %fm;
1.41 ng 178: my %category_extensions;
1.12 harris41 179:
1.46 matthew 180: # ---------------------------------------------- Thesaurus variables
1.144 matthew 181: #
182: # %Keywords:
183: # A hash used by &keyword to determine if a word is considered a keyword.
184: # $thesaurus_db_file
185: # Scalar containing the full path to the thesaurus database.
1.46 matthew 186:
187: my %Keywords;
188: my $thesaurus_db_file;
189:
1.144 matthew 190: #
191: # Initialize values from language.tab, copyright.tab, filetypes.tab,
192: # thesaurus.tab, and filecategories.tab.
193: #
1.18 www 194: BEGIN {
1.46 matthew 195: # Variable initialization
196: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
197: #
1.22 www 198: unless ($readit) {
1.12 harris41 199: # ------------------------------------------------------------------- languages
200: {
1.158 raeburn 201: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
202: '/language.tab';
1.1075.2.128 raeburn 203: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 204: while (my $line = <$fh>) {
205: next if ($line=~/^\#/);
206: chomp($line);
1.1048 foxr 207: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 208: $language{$key}=$val.' - '.$enc;
209: if ($sup) {
210: $supported_language{$key}=$sup;
211: }
1.1048 foxr 212: if ($latex) {
213: $latex_language_bykey{$key} = $latex;
214: $latex_language{$two} = $latex;
215: }
1.158 raeburn 216: }
217: close($fh);
218: }
1.12 harris41 219: }
220: # ------------------------------------------------------------------ copyrights
221: {
1.158 raeburn 222: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/copyright.tab';
1.1075.2.128 raeburn 224: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line=~/^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 229: $cprtag{$key}=$val;
230: }
231: close($fh);
232: }
1.12 harris41 233: }
1.351 www 234: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 235: {
236: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
237: '/source_copyright.tab';
1.1075.2.128 raeburn 238: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 243: $scprtag{$key}=$val;
244: }
245: close($fh);
246: }
247: }
1.63 www 248:
1.517 raeburn 249: # -------------------------------------------------------------- default domain designs
1.63 www 250: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 251: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 252: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($key,$val)=(split(/\=/,$line));
257: if ($val) { $defaultdesign{$key}=$val; }
258: }
259: close($fh);
1.63 www 260: }
261:
1.15 harris41 262: # ------------------------------------------------------------- file categories
263: {
1.158 raeburn 264: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
265: '/filecategories.tab';
1.1075.2.128 raeburn 266: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 267: while (my $line = <$fh>) {
268: next if ($line =~ /^\#/);
269: chomp($line);
270: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 271: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 272: }
273: close($fh);
274: }
275:
1.15 harris41 276: }
1.12 harris41 277: # ------------------------------------------------------------------ file types
278: {
1.158 raeburn 279: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
280: '/filetypes.tab';
1.1075.2.128 raeburn 281: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 282: while (my $line = <$fh>) {
283: next if ($line =~ /^\#/);
284: chomp($line);
285: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 286: if ($descr ne '') {
287: $fe{$ending}=lc($emb);
288: $fd{$ending}=$descr;
1.351 www 289: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 290: }
291: }
292: close($fh);
293: }
1.12 harris41 294: }
1.22 www 295: &Apache::lonnet::logthis(
1.705 tempelho 296: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 297: $readit=1;
1.46 matthew 298: } # end of unless($readit)
1.32 matthew 299:
300: }
1.112 bowersj2 301:
1.42 matthew 302: ###############################################################
303: ## HTML and Javascript Helper Functions ##
304: ###############################################################
305:
306: =pod
307:
1.112 bowersj2 308: =head1 HTML and Javascript Functions
1.42 matthew 309:
1.112 bowersj2 310: =over 4
311:
1.648 raeburn 312: =item * &browser_and_searcher_javascript()
1.112 bowersj2 313:
314: X<browsing, javascript>X<searching, javascript>Returns a string
315: containing javascript with two functions, C<openbrowser> and
316: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
317: tags.
1.42 matthew 318:
1.648 raeburn 319: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 320:
321: inputs: formname, elementname, only, omit
322:
323: formname and elementname indicate the name of the html form and name of
324: the element that the results of the browsing selection are to be placed in.
325:
326: Specifying 'only' will restrict the browser to displaying only files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
329: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 330: with the given extension. Can be a comma separated list.
1.42 matthew 331:
1.648 raeburn 332: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 333:
334: Inputs: formname, elementname
335:
336: formname and elementname specify the name of the html form and the name
337: of the element the selection from the search results will be placed in.
1.542 raeburn 338:
1.42 matthew 339: =cut
340:
341: sub browser_and_searcher_javascript {
1.199 albertel 342: my ($mode)=@_;
343: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 344: my $resurl=&escape_single(&lastresurl());
1.42 matthew 345: return <<END;
1.219 albertel 346: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 347: var editbrowser = null;
1.135 albertel 348: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 349: var url = '$resurl/?';
1.42 matthew 350: if (editbrowser == null) {
351: url += 'launch=1&';
352: }
353: url += 'catalogmode=interactive&';
1.199 albertel 354: url += 'mode=$mode&';
1.611 albertel 355: url += 'inhibitmenu=yes&';
1.42 matthew 356: url += 'form=' + formname + '&';
357: if (only != null) {
358: url += 'only=' + only + '&';
1.217 albertel 359: } else {
360: url += 'only=&';
361: }
1.42 matthew 362: if (omit != null) {
363: url += 'omit=' + omit + '&';
1.217 albertel 364: } else {
365: url += 'omit=&';
366: }
1.135 albertel 367: if (titleelement != null) {
368: url += 'titleelement=' + titleelement + '&';
1.217 albertel 369: } else {
370: url += 'titleelement=&';
371: }
1.42 matthew 372: url += 'element=' + elementname + '';
373: var title = 'Browser';
1.435 albertel 374: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 375: options += ',width=700,height=600';
376: editbrowser = open(url,title,options,'1');
377: editbrowser.focus();
378: }
379: var editsearcher;
1.135 albertel 380: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 381: var url = '/adm/searchcat?';
382: if (editsearcher == null) {
383: url += 'launch=1&';
384: }
385: url += 'catalogmode=interactive&';
1.199 albertel 386: url += 'mode=$mode&';
1.42 matthew 387: url += 'form=' + formname + '&';
1.135 albertel 388: if (titleelement != null) {
389: url += 'titleelement=' + titleelement + '&';
1.217 albertel 390: } else {
391: url += 'titleelement=&';
392: }
1.42 matthew 393: url += 'element=' + elementname + '';
394: var title = 'Search';
1.435 albertel 395: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 396: options += ',width=700,height=600';
397: editsearcher = open(url,title,options,'1');
398: editsearcher.focus();
399: }
1.219 albertel 400: // END LON-CAPA Internal -->
1.42 matthew 401: END
1.170 www 402: }
403:
404: sub lastresurl {
1.258 albertel 405: if ($env{'environment.lastresurl'}) {
406: return $env{'environment.lastresurl'}
1.170 www 407: } else {
408: return '/res';
409: }
410: }
411:
412: sub storeresurl {
413: my $resurl=&Apache::lonnet::clutter(shift);
414: unless ($resurl=~/^\/res/) { return 0; }
415: $resurl=~s/\/$//;
416: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 417: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 418: return 1;
1.42 matthew 419: }
420:
1.74 www 421: sub studentbrowser_javascript {
1.111 www 422: unless (
1.258 albertel 423: (($env{'request.course.id'}) &&
1.302 albertel 424: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
425: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
426: '/'.$env{'request.course.sec'})
427: ))
1.258 albertel 428: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 429: ) { return ''; }
1.74 www 430: return (<<'ENDSTDBRW');
1.776 bisitz 431: <script type="text/javascript" language="Javascript">
1.824 bisitz 432: // <![CDATA[
1.74 www 433: var stdeditbrowser;
1.1075.2.161. .20(raeb 434:-23): function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv,uident) {
1.74 www 435: var url = '/adm/pickstudent?';
436: var filter;
1.558 albertel 437: if (!ignorefilter) {
438: eval('filter=document.'+formname+'.'+uname+'.value;');
439: }
1.74 www 440: if (filter != null) {
441: if (filter != '') {
442: url += 'filter='+filter+'&';
443: }
444: }
445: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 446: '&udomelement='+udom+
447: '&clicker='+clicker;
1.111 www 448: if (roleflag) { url+="&roles=1"; }
1.1075.2.143 raeburn 449: if (courseadv == 'condition') {
450: if (document.getElementById('courseadv')) {
451: courseadv = document.getElementById('courseadv').value;
452: }
453: }
454: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.1075.2.161. .20(raeb 455:-23): if (uident !== '') { url+="&identelement="+uident; }
1.102 www 456: var title = 'Student_Browser';
1.74 www 457: var options = 'scrollbars=1,resizable=1,menubar=0';
458: options += ',width=700,height=600';
459: stdeditbrowser = open(url,title,options,'1');
460: stdeditbrowser.focus();
461: }
1.824 bisitz 462: // ]]>
1.74 www 463: </script>
464: ENDSTDBRW
465: }
1.42 matthew 466:
1.1003 www 467: sub resourcebrowser_javascript {
468: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 469: return (<<'ENDRESBRW');
1.1003 www 470: <script type="text/javascript" language="Javascript">
471: // <![CDATA[
472: var reseditbrowser;
1.1004 www 473: function openresbrowser(formname,reslink) {
1.1005 www 474: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 475: var title = 'Resource_Browser';
476: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 477: options += ',width=700,height=500';
1.1004 www 478: reseditbrowser = open(url,title,options,'1');
479: reseditbrowser.focus();
1.1003 www 480: }
481: // ]]>
482: </script>
1.1004 www 483: ENDRESBRW
1.1003 www 484: }
485:
1.74 www 486: sub selectstudent_link {
1.1075.2.161. .20(raeb 487:-23): my ($form,$unameele,$udomele,$courseadv,$clickerid,$identelem)=@_;
1.999 www 488: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
489: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
490: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 491: if ($env{'request.course.id'}) {
1.302 albertel 492: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
493: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
494: '/'.$env{'request.course.sec'})) {
1.111 www 495: return '';
496: }
1.999 www 497: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1075.2.143 raeburn 498: if ($courseadv eq 'only') {
499: $callargs .= ",'',1,'$courseadv'";
500: } elsif ($courseadv eq 'none') {
501: $callargs .= ",'','','$courseadv'";
502: } elsif ($courseadv eq 'condition') {
503: $callargs .= ",'','','$courseadv'";
1.1075.2.161. .20(raeb 504:-23): } elsif ($identelem ne '') {
505:-23): $callargs .= ",'','',''";
506:-23): }
507:-23): if ($identelem ne '') {
508:-23): $callargs .= ",'".&Apache::lonhtmlcommon::entity_encode($identelem)."'";
1.793 raeburn 509: }
510: return '<span class="LC_nobreak">'.
511: '<a href="javascript:openstdbrowser('.$callargs.');">'.
512: &mt('Select User').'</a></span>';
1.74 www 513: }
1.258 albertel 514: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 515: $callargs .= ",'',1";
1.793 raeburn 516: return '<span class="LC_nobreak">'.
517: '<a href="javascript:openstdbrowser('.$callargs.');">'.
518: &mt('Select User').'</a></span>';
1.111 www 519: }
520: return '';
1.91 www 521: }
522:
1.1004 www 523: sub selectresource_link {
524: my ($form,$reslink,$arg)=@_;
525:
526: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
527: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
528: unless ($env{'request.course.id'}) { return $arg; }
529: return '<span class="LC_nobreak">'.
530: '<a href="javascript:openresbrowser('.$callargs.');">'.
531: $arg.'</a></span>';
532: }
533:
534:
535:
1.653 raeburn 536: sub authorbrowser_javascript {
537: return <<"ENDAUTHORBRW";
1.776 bisitz 538: <script type="text/javascript" language="JavaScript">
1.824 bisitz 539: // <![CDATA[
1.653 raeburn 540: var stdeditbrowser;
541:
542: function openauthorbrowser(formname,udom) {
543: var url = '/adm/pickauthor?';
544: url += 'form='+formname+'&roledom='+udom;
545: var title = 'Author_Browser';
546: var options = 'scrollbars=1,resizable=1,menubar=0';
547: options += ',width=700,height=600';
548: stdeditbrowser = open(url,title,options,'1');
549: stdeditbrowser.focus();
550: }
551:
1.824 bisitz 552: // ]]>
1.653 raeburn 553: </script>
554: ENDAUTHORBRW
555: }
556:
1.91 www 557: sub coursebrowser_javascript {
1.1075.2.31 raeburn 558: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 559: $credits_element,$instcode) = @_;
1.932 raeburn 560: my $wintitle = 'Course_Browser';
1.931 raeburn 561: if ($crstype eq 'Community') {
1.932 raeburn 562: $wintitle = 'Community_Browser';
1.909 raeburn 563: }
1.876 raeburn 564: my $id_functions = &javascript_index_functions();
565: my $output = '
1.776 bisitz 566: <script type="text/javascript" language="JavaScript">
1.824 bisitz 567: // <![CDATA[
1.468 raeburn 568: var stdeditbrowser;'."\n";
1.876 raeburn 569:
570: $output .= <<"ENDSTDBRW";
1.909 raeburn 571: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 572: var url = '/adm/pickcourse?';
1.895 raeburn 573: var formid = getFormIdByName(formname);
1.876 raeburn 574: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 575: if (domainfilter != null) {
576: if (domainfilter != '') {
577: url += 'domainfilter='+domainfilter+'&';
578: }
579: }
1.91 www 580: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 581: '&cdomelement='+udom+
582: '&cnameelement='+desc;
1.468 raeburn 583: if (extra_element !=null && extra_element != '') {
1.594 raeburn 584: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 585: url += '&roleelement='+extra_element;
586: if (domainfilter == null || domainfilter == '') {
587: url += '&domainfilter='+extra_element;
588: }
1.234 raeburn 589: }
1.468 raeburn 590: else {
591: if (formname == 'portform') {
592: url += '&setroles='+extra_element;
1.800 raeburn 593: } else {
594: if (formname == 'rules') {
595: url += '&fixeddom='+extra_element;
596: }
1.468 raeburn 597: }
598: }
1.230 raeburn 599: }
1.909 raeburn 600: if (type != null && type != '') {
601: url += '&type='+type;
602: }
603: if (type_elem != null && type_elem != '') {
604: url += '&typeelement='+type_elem;
605: }
1.872 raeburn 606: if (formname == 'ccrs') {
607: var ownername = document.forms[formid].ccuname.value;
608: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 609: url += '&cloner='+ownername+':'+ownerdom;
610: if (type == 'Course') {
611: url += '&crscode='+document.forms[formid].crscode.value;
612: }
1.1075.2.95 raeburn 613: }
614: if (formname == 'requestcrs') {
615: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 616: }
1.293 raeburn 617: if (multflag !=null && multflag != '') {
618: url += '&multiple='+multflag;
619: }
1.909 raeburn 620: var title = '$wintitle';
1.91 www 621: var options = 'scrollbars=1,resizable=1,menubar=0';
622: options += ',width=700,height=600';
623: stdeditbrowser = open(url,title,options,'1');
624: stdeditbrowser.focus();
625: }
1.876 raeburn 626: $id_functions
627: ENDSTDBRW
1.1075.2.31 raeburn 628: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
629: $output .= &setsec_javascript($sec_element,$formname,$role_element,
630: $credits_element);
1.876 raeburn 631: }
632: $output .= '
633: // ]]>
634: </script>';
635: return $output;
636: }
637:
638: sub javascript_index_functions {
639: return <<"ENDJS";
640:
641: function getFormIdByName(formname) {
642: for (var i=0;i<document.forms.length;i++) {
643: if (document.forms[i].name == formname) {
644: return i;
645: }
646: }
647: return -1;
648: }
649:
650: function getIndexByName(formid,item) {
651: for (var i=0;i<document.forms[formid].elements.length;i++) {
652: if (document.forms[formid].elements[i].name == item) {
653: return i;
654: }
655: }
656: return -1;
657: }
1.468 raeburn 658:
1.876 raeburn 659: function getDomainFromSelectbox(formname,udom) {
660: var userdom;
661: var formid = getFormIdByName(formname);
662: if (formid > -1) {
663: var domid = getIndexByName(formid,udom);
664: if (domid > -1) {
665: if (document.forms[formid].elements[domid].type == 'select-one') {
666: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
667: }
668: if (document.forms[formid].elements[domid].type == 'hidden') {
669: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 670: }
671: }
672: }
1.876 raeburn 673: return userdom;
674: }
675:
676: ENDJS
1.468 raeburn 677:
1.876 raeburn 678: }
679:
1.1017 raeburn 680: sub javascript_array_indexof {
1.1018 raeburn 681: return <<ENDJS;
1.1017 raeburn 682: <script type="text/javascript" language="JavaScript">
683: // <![CDATA[
684:
685: if (!Array.prototype.indexOf) {
686: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
687: "use strict";
688: if (this === void 0 || this === null) {
689: throw new TypeError();
690: }
691: var t = Object(this);
692: var len = t.length >>> 0;
693: if (len === 0) {
694: return -1;
695: }
696: var n = 0;
697: if (arguments.length > 0) {
698: n = Number(arguments[1]);
699: if (n !== n) { // shortcut for verifying if it's NaN
700: n = 0;
701: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
702: n = (n > 0 || -1) * Math.floor(Math.abs(n));
703: }
704: }
705: if (n >= len) {
706: return -1;
707: }
708: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
709: for (; k < len; k++) {
710: if (k in t && t[k] === searchElement) {
711: return k;
712: }
713: }
714: return -1;
715: }
716: }
717:
718: // ]]>
719: </script>
720:
721: ENDJS
722:
723: }
724:
1.876 raeburn 725: sub userbrowser_javascript {
726: my $id_functions = &javascript_index_functions();
727: return <<"ENDUSERBRW";
728:
1.888 raeburn 729: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 730: var url = '/adm/pickuser?';
731: var userdom = getDomainFromSelectbox(formname,udom);
732: if (userdom != null) {
733: if (userdom != '') {
734: url += 'srchdom='+userdom+'&';
735: }
736: }
737: url += 'form=' + formname + '&unameelement='+uname+
738: '&udomelement='+udom+
739: '&ulastelement='+ulast+
740: '&ufirstelement='+ufirst+
741: '&uemailelement='+uemail+
1.881 raeburn 742: '&hideudomelement='+hideudom+
743: '&coursedom='+crsdom;
1.888 raeburn 744: if ((caller != null) && (caller != undefined)) {
745: url += '&caller='+caller;
746: }
1.876 raeburn 747: var title = 'User_Browser';
748: var options = 'scrollbars=1,resizable=1,menubar=0';
749: options += ',width=700,height=600';
750: var stdeditbrowser = open(url,title,options,'1');
751: stdeditbrowser.focus();
752: }
753:
1.888 raeburn 754: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 755: var formid = getFormIdByName(formname);
756: if (formid > -1) {
1.888 raeburn 757: var unameid = getIndexByName(formid,uname);
1.876 raeburn 758: var domid = getIndexByName(formid,udom);
759: var hidedomid = getIndexByName(formid,origdom);
760: if (hidedomid > -1) {
761: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 762: var unameval = document.forms[formid].elements[unameid].value;
763: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
764: if (domid > -1) {
765: var slct = document.forms[formid].elements[domid];
766: if (slct.type == 'select-one') {
767: var i;
768: for (i=0;i<slct.length;i++) {
769: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
770: }
771: }
772: if (slct.type == 'hidden') {
773: slct.value = fixeddom;
1.876 raeburn 774: }
775: }
1.468 raeburn 776: }
777: }
778: }
1.876 raeburn 779: return;
780: }
781:
782: $id_functions
783: ENDUSERBRW
1.468 raeburn 784: }
785:
786: sub setsec_javascript {
1.1075.2.31 raeburn 787: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 788: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
789: $communityrolestr);
790: if ($role_element ne '') {
791: my @allroles = ('st','ta','ep','in','ad');
792: foreach my $crstype ('Course','Community') {
793: if ($crstype eq 'Community') {
794: foreach my $role (@allroles) {
795: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
796: }
797: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
798: } else {
799: foreach my $role (@allroles) {
800: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
801: }
802: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
803: }
804: }
805: $rolestr = '"'.join('","',@allroles).'"';
806: $courserolestr = '"'.join('","',@courserolenames).'"';
807: $communityrolestr = '"'.join('","',@communityrolenames).'"';
808: }
1.468 raeburn 809: my $setsections = qq|
810: function setSect(sectionlist) {
1.629 raeburn 811: var sectionsArray = new Array();
812: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
813: sectionsArray = sectionlist.split(",");
814: }
1.468 raeburn 815: var numSections = sectionsArray.length;
816: document.$formname.$sec_element.length = 0;
817: if (numSections == 0) {
818: document.$formname.$sec_element.multiple=false;
819: document.$formname.$sec_element.size=1;
820: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
821: } else {
822: if (numSections == 1) {
823: document.$formname.$sec_element.multiple=false;
824: document.$formname.$sec_element.size=1;
825: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
826: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
827: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
828: } else {
829: for (var i=0; i<numSections; i++) {
830: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
831: }
832: document.$formname.$sec_element.multiple=true
833: if (numSections < 3) {
834: document.$formname.$sec_element.size=numSections;
835: } else {
836: document.$formname.$sec_element.size=3;
837: }
838: document.$formname.$sec_element.options[0].selected = false
839: }
840: }
1.91 www 841: }
1.905 raeburn 842:
843: function setRole(crstype) {
1.468 raeburn 844: |;
1.905 raeburn 845: if ($role_element eq '') {
846: $setsections .= ' return;
847: }
848: ';
849: } else {
850: $setsections .= qq|
851: var elementLength = document.$formname.$role_element.length;
852: var allroles = Array($rolestr);
853: var courserolenames = Array($courserolestr);
854: var communityrolenames = Array($communityrolestr);
855: if (elementLength != undefined) {
856: if (document.$formname.$role_element.options[5].value == 'cc') {
857: if (crstype == 'Course') {
858: return;
859: } else {
860: allroles[5] = 'co';
861: for (var i=0; i<6; i++) {
862: document.$formname.$role_element.options[i].value = allroles[i];
863: document.$formname.$role_element.options[i].text = communityrolenames[i];
864: }
865: }
866: } else {
867: if (crstype == 'Community') {
868: return;
869: } else {
870: allroles[5] = 'cc';
871: for (var i=0; i<6; i++) {
872: document.$formname.$role_element.options[i].value = allroles[i];
873: document.$formname.$role_element.options[i].text = courserolenames[i];
874: }
875: }
876: }
877: }
878: return;
879: }
880: |;
881: }
1.1075.2.31 raeburn 882: if ($credits_element) {
883: $setsections .= qq|
884: function setCredits(defaultcredits) {
885: document.$formname.$credits_element.value = defaultcredits;
886: return;
887: }
888: |;
889: }
1.468 raeburn 890: return $setsections;
891: }
892:
1.91 www 893: sub selectcourse_link {
1.909 raeburn 894: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
895: $typeelement) = @_;
896: my $type = $selecttype;
1.871 raeburn 897: my $linktext = &mt('Select Course');
898: if ($selecttype eq 'Community') {
1.909 raeburn 899: $linktext = &mt('Select Community');
1.906 raeburn 900: } elsif ($selecttype eq 'Course/Community') {
901: $linktext = &mt('Select Course/Community');
1.909 raeburn 902: $type = '';
1.1019 raeburn 903: } elsif ($selecttype eq 'Select') {
904: $linktext = &mt('Select');
905: $type = '';
1.871 raeburn 906: }
1.787 bisitz 907: return '<span class="LC_nobreak">'
908: ."<a href='"
909: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
910: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 911: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 912: ."'>".$linktext.'</a>'
1.787 bisitz 913: .'</span>';
1.74 www 914: }
1.42 matthew 915:
1.653 raeburn 916: sub selectauthor_link {
917: my ($form,$udom)=@_;
918: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
919: &mt('Select Author').'</a>';
920: }
921:
1.876 raeburn 922: sub selectuser_link {
1.881 raeburn 923: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 924: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 925: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 926: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 927: ');">'.$linktext.'</a>';
1.876 raeburn 928: }
929:
1.273 raeburn 930: sub check_uncheck_jscript {
931: my $jscript = <<"ENDSCRT";
932: function checkAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 935: if (!field[i].disabled) {
936: field[i].checked = true;
937: }
1.273 raeburn 938: }
939: } else {
1.1075.2.14 raeburn 940: if (!field.disabled) {
941: field.checked = true;
942: }
1.273 raeburn 943: }
944: }
945:
946: function uncheckAll(field) {
947: if (field.length > 0) {
948: for (i = 0; i < field.length; i++) {
949: field[i].checked = false ;
1.543 albertel 950: }
951: } else {
1.273 raeburn 952: field.checked = false ;
953: }
954: }
955: ENDSCRT
956: return $jscript;
957: }
958:
1.656 www 959: sub select_timezone {
1.1075.2.161. .10(raeb 960:-22): my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
961:-22): my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";
1.659 raeburn 962: if ($includeempty) {
963: $output .= '<option value=""';
964: if (($selected eq '') || ($selected eq 'local')) {
965: $output .= ' selected="selected" ';
966: }
967: $output .= '> </option>';
968: }
1.657 raeburn 969: my @timezones = DateTime::TimeZone->all_names;
970: foreach my $tzone (@timezones) {
971: $output.= '<option value="'.$tzone.'"';
972: if ($tzone eq $selected) {
973: $output.=' selected="selected"';
974: }
975: $output.=">$tzone</option>\n";
1.656 www 976: }
977: $output.="</select>";
978: return $output;
979: }
1.273 raeburn 980:
1.687 raeburn 981: sub select_datelocale {
1.1075.2.115 raeburn 982: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
983: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 984: if ($includeempty) {
985: $output .= '<option value=""';
986: if ($selected eq '') {
987: $output .= ' selected="selected" ';
988: }
989: $output .= '> </option>';
990: }
1.1075.2.102 raeburn 991: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 992: my (@possibles,%locale_names);
1.1075.2.102 raeburn 993: my @locales = DateTime::Locale->ids();
994: foreach my $id (@locales) {
995: if ($id ne '') {
996: my ($en_terr,$native_terr);
997: my $loc = DateTime::Locale->load($id);
998: if (ref($loc)) {
999: $en_terr = $loc->name();
1000: $native_terr = $loc->native_name();
1.687 raeburn 1001: if (grep(/^en$/,@languages) || !@languages) {
1002: if ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: } elsif ($native_terr ne '') {
1005: $locale_names{$id} = $native_terr;
1006: }
1007: } else {
1008: if ($native_terr ne '') {
1009: $locale_names{$id} = $native_terr.' ';
1010: } elsif ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: }
1013: }
1.1075.2.94 raeburn 1014: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1015: push(@possibles,$id);
1.687 raeburn 1016: }
1017: }
1018: }
1019: foreach my $item (sort(@possibles)) {
1020: $output.= '<option value="'.$item.'"';
1021: if ($item eq $selected) {
1022: $output.=' selected="selected"';
1023: }
1024: $output.=">$item";
1025: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1026: $output.=' '.$locale_names{$item};
1.687 raeburn 1027: }
1028: $output.="</option>\n";
1029: }
1030: $output.="</select>";
1031: return $output;
1032: }
1033:
1.792 raeburn 1034: sub select_language {
1.1075.2.115 raeburn 1035: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1036: my %langchoices;
1037: if ($includeempty) {
1.1075.2.32 raeburn 1038: %langchoices = ('' => 'No language preference');
1.792 raeburn 1039: }
1040: foreach my $id (&languageids()) {
1041: my $code = &supportedlanguagecode($id);
1042: if ($code) {
1043: $langchoices{$code} = &plainlanguagedescription($id);
1044: }
1045: }
1.1075.2.32 raeburn 1046: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1047: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1048: }
1049:
1.42 matthew 1050: =pod
1.36 matthew 1051:
1.648 raeburn 1052: =item * &linked_select_forms(...)
1.36 matthew 1053:
1054: linked_select_forms returns a string containing a <script></script> block
1055: and html for two <select> menus. The select menus will be linked in that
1056: changing the value of the first menu will result in new values being placed
1057: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1058: order unless a defined order is provided.
1.36 matthew 1059:
1060: linked_select_forms takes the following ordered inputs:
1061:
1062: =over 4
1063:
1.112 bowersj2 1064: =item * $formname, the name of the <form> tag
1.36 matthew 1065:
1.112 bowersj2 1066: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1067:
1.112 bowersj2 1068: =item * $firstdefault, the default value for the first menu
1.36 matthew 1069:
1.112 bowersj2 1070: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1071:
1.112 bowersj2 1072: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1073:
1.112 bowersj2 1074: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1075:
1.609 raeburn 1076: =item * $menuorder, the order of values in the first menu
1077:
1.1075.2.31 raeburn 1078: =item * $onchangefirst, additional javascript call to execute for an onchange
1079: event for the first <select> tag
1080:
1081: =item * $onchangesecond, additional javascript call to execute for an onchange
1082: event for the second <select> tag
1083:
1.41 ng 1084: =back
1085:
1.36 matthew 1086: Below is an example of such a hash. Only the 'text', 'default', and
1087: 'select2' keys must appear as stated. keys(%menu) are the possible
1088: values for the first select menu. The text that coincides with the
1.41 ng 1089: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1090: and text for the second menu are given in the hash pointed to by
1091: $menu{$choice1}->{'select2'}.
1092:
1.112 bowersj2 1093: my %menu = ( A1 => { text =>"Choice A1" ,
1094: default => "B3",
1095: select2 => {
1096: B1 => "Choice B1",
1097: B2 => "Choice B2",
1098: B3 => "Choice B3",
1099: B4 => "Choice B4"
1.609 raeburn 1100: },
1101: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1102: },
1103: A2 => { text =>"Choice A2" ,
1104: default => "C2",
1105: select2 => {
1106: C1 => "Choice C1",
1107: C2 => "Choice C2",
1108: C3 => "Choice C3"
1.609 raeburn 1109: },
1110: order => ['C2','C1','C3'],
1.112 bowersj2 1111: },
1112: A3 => { text =>"Choice A3" ,
1113: default => "D6",
1114: select2 => {
1115: D1 => "Choice D1",
1116: D2 => "Choice D2",
1117: D3 => "Choice D3",
1118: D4 => "Choice D4",
1119: D5 => "Choice D5",
1120: D6 => "Choice D6",
1121: D7 => "Choice D7"
1.609 raeburn 1122: },
1123: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1124: }
1125: );
1.36 matthew 1126:
1127: =cut
1128:
1129: sub linked_select_forms {
1130: my ($formname,
1131: $middletext,
1132: $firstdefault,
1133: $firstselectname,
1134: $secondselectname,
1.609 raeburn 1135: $hashref,
1136: $menuorder,
1.1075.2.31 raeburn 1137: $onchangefirst,
1138: $onchangesecond
1.36 matthew 1139: ) = @_;
1140: my $second = "document.$formname.$secondselectname";
1141: my $first = "document.$formname.$firstselectname";
1142: # output the javascript to do the changing
1143: my $result = '';
1.776 bisitz 1144: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1145: $result.="// <![CDATA[\n";
1.36 matthew 1146: $result.="var select2data = new Object();\n";
1147: $" = '","';
1148: my $debug = '';
1149: foreach my $s1 (sort(keys(%$hashref))) {
1150: $result.="select2data.d_$s1 = new Object();\n";
1151: $result.="select2data.d_$s1.def = new String('".
1152: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1153: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1154: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1155: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1156: @s2values = @{$hashref->{$s1}->{'order'}};
1157: }
1.36 matthew 1158: $result.="\"@s2values\");\n";
1159: $result.="select2data.d_$s1.texts = new Array(";
1160: my @s2texts;
1161: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1162: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1163: }
1164: $result.="\"@s2texts\");\n";
1165: }
1166: $"=' ';
1167: $result.= <<"END";
1168:
1169: function select1_changed() {
1170: // Determine new choice
1171: var newvalue = "d_" + $first.value;
1172: // update select2
1173: var values = select2data[newvalue].values;
1174: var texts = select2data[newvalue].texts;
1175: var select2def = select2data[newvalue].def;
1176: var i;
1177: // out with the old
1178: for (i = 0; i < $second.options.length; i++) {
1179: $second.options[i] = null;
1180: }
1181: // in with the nuclear
1182: for (i=0;i<values.length; i++) {
1183: $second.options[i] = new Option(values[i]);
1.143 matthew 1184: $second.options[i].value = values[i];
1.36 matthew 1185: $second.options[i].text = texts[i];
1186: if (values[i] == select2def) {
1187: $second.options[i].selected = true;
1188: }
1189: }
1190: }
1.824 bisitz 1191: // ]]>
1.36 matthew 1192: </script>
1193: END
1194: # output the initial values for the selection lists
1.1075.2.31 raeburn 1195: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1196: my @order = sort(keys(%{$hashref}));
1197: if (ref($menuorder) eq 'ARRAY') {
1198: @order = @{$menuorder};
1199: }
1200: foreach my $value (@order) {
1.36 matthew 1201: $result.=" <option value=\"$value\" ";
1.253 albertel 1202: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1203: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1204: }
1205: $result .= "</select>\n";
1206: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1207: $result .= $middletext;
1.1075.2.31 raeburn 1208: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1209: if ($onchangesecond) {
1210: $result .= ' onchange="'.$onchangesecond.'"';
1211: }
1212: $result .= ">\n";
1.36 matthew 1213: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1214:
1215: my @secondorder = sort(keys(%select2));
1216: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1217: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1218: }
1219: foreach my $value (@secondorder) {
1.36 matthew 1220: $result.=" <option value=\"$value\" ";
1.253 albertel 1221: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1222: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1223: }
1224: $result .= "</select>\n";
1225: # return $debug;
1226: return $result;
1227: } # end of sub linked_select_forms {
1228:
1.45 matthew 1229: =pod
1.44 bowersj2 1230:
1.1075.2.161. .6(raebu 1231:22): =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1232:
1.112 bowersj2 1233: Returns a string corresponding to an HTML link to the given help
1234: $topic, where $topic corresponds to the name of a .tex file in
1235: /home/httpd/html/adm/help/tex, with underscores replaced by
1236: spaces.
1237:
1238: $text will optionally be linked to the same topic, allowing you to
1239: link text in addition to the graphic. If you do not want to link
1240: text, but wish to specify one of the later parameters, pass an
1241: empty string.
1242:
1243: $stayOnPage is a value that will be interpreted as a boolean. If true,
1244: the link will not open a new window. If false, the link will open
1245: a new window using Javascript. (Default is false.)
1246:
1247: $width and $height are optional numerical parameters that will
1248: override the width and height of the popped up window, which may
1.973 raeburn 1249: be useful for certain help topics with big pictures included.
1250:
1251: $imgid is the id of the img tag used for the help icon. This may be
1252: used in a javascript call to switch the image src. See
1253: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1254:
1.1075.2.161. .6(raebu 1255:22): $links_target will optionally be set to a target (_top, _parent or _self).
1256:22):
1.44 bowersj2 1257: =cut
1258:
1259: sub help_open_topic {
1.1075.2.161. .6(raebu 1260:22): my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1261: $text = "" if (not defined $text);
1.44 bowersj2 1262: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1263: $width = 500 if (not defined $width);
1.44 bowersj2 1264: $height = 400 if (not defined $height);
1265: my $filename = $topic;
1266: $filename =~ s/ /_/g;
1267:
1.48 bowersj2 1268: my $template = "";
1269: my $link;
1.572 banghart 1270:
1.159 www 1271: $topic=~s/\W/\_/g;
1.44 bowersj2 1272:
1.572 banghart 1273: if (!$stayOnPage) {
1.1075.2.50 raeburn 1274: if ($env{'browser.mobile'}) {
1275: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1276: } else {
1277: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1278: }
1.1037 www 1279: } elsif ($stayOnPage eq 'popup') {
1280: $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 1281: } else {
1.48 bowersj2 1282: $link = "/adm/help/${filename}.hlp";
1283: }
1284:
1285: # Add the text
1.1075.2.161. .6(raebu 1286:22): my $target = ' target="_top"';
1287:22): if ($links_target) {
1288:22): $target = ' target="'.$links_target.'"';
.17(raeb 1289:-23): } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1290:-23): (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
.6(raebu 1291:22): $target = '';
1292:22): }
1.755 neumanie 1293: if ($text ne "") {
1.763 bisitz 1294: $template.='<span class="LC_help_open_topic">'
1.1075.2.161. .6(raebu 1295:22): .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1296: .$text.'</a>';
1.48 bowersj2 1297: }
1298:
1.763 bisitz 1299: # (Always) Add the graphic
1.179 matthew 1300: my $title = &mt('Online Help');
1.667 raeburn 1301: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1302: if ($imgid ne '') {
1303: $imgid = ' id="'.$imgid.'"';
1304: }
1.1075.2.161. .6(raebu 1305:22): $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1306: .'<img src="'.$helpicon.'" border="0"'
1307: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1308: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1309: .' /></a>';
1310: if ($text ne "") {
1311: $template.='</span>';
1312: }
1.44 bowersj2 1313: return $template;
1314:
1.106 bowersj2 1315: }
1316:
1317: # This is a quicky function for Latex cheatsheet editing, since it
1318: # appears in at least four places
1319: sub helpLatexCheatsheet {
1.1037 www 1320: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1321: my $out;
1.106 bowersj2 1322: my $addOther = '';
1.732 raeburn 1323: if ($topic) {
1.1037 www 1324: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1325: }
1326: $out = '<span>' # Start cheatsheet
1327: .$addOther
1328: .'<span>'
1.1037 www 1329: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1330: .'</span> <span>'
1.1037 www 1331: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1332: .'</span>';
1.732 raeburn 1333: unless ($not_author) {
1.763 bisitz 1334: $out .= ' <span>'
1.1037 www 1335: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1336: .'</span> <span>'
1.1075.2.78 raeburn 1337: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1338: .'</span>';
1.732 raeburn 1339: }
1.763 bisitz 1340: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1341: return $out;
1.172 www 1342: }
1343:
1.430 albertel 1344: sub general_help {
1345: my $helptopic='Student_Intro';
1346: if ($env{'request.role'}=~/^(ca|au)/) {
1347: $helptopic='Authoring_Intro';
1.907 raeburn 1348: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1349: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1350: } elsif ($env{'request.role'}=~/^dc/) {
1351: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1352: }
1353: return $helptopic;
1354: }
1355:
1356: sub update_help_link {
1357: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1358: my $origurl = $ENV{'REQUEST_URI'};
1359: $origurl=~s|^/~|/priv/|;
1360: my $timestamp = time;
1361: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1362: $$datum = &escape($$datum);
1363: }
1364:
1365: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1366: my $output .= <<"ENDOUTPUT";
1367: <script type="text/javascript">
1.824 bisitz 1368: // <![CDATA[
1.430 albertel 1369: banner_link = '$banner_link';
1.824 bisitz 1370: // ]]>
1.430 albertel 1371: </script>
1372: ENDOUTPUT
1373: return $output;
1374: }
1375:
1376: # now just updates the help link and generates a blue icon
1.193 raeburn 1377: sub help_open_menu {
1.1075.2.161. .6(raebu 1378:22): my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1379: = @_;
1.949 droeschl 1380: $stayOnPage = 1;
1.430 albertel 1381: my $output;
1382: if ($component_help) {
1383: if (!$text) {
1384: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1075.2.161. .6(raebu 1385:22): $width,$height,'',$links_target);
1.430 albertel 1386: } else {
1387: my $help_text;
1388: $help_text=&unescape($topic);
1389: $output='<table><tr><td>'.
1390: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1075.2.161. .6(raebu 1391:22): $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1392: }
1393: }
1394: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1395: return $output.$banner_link;
1396: }
1397:
1398: sub top_nav_help {
1.1075.2.158 raeburn 1399: my ($text,$linkattr) = @_;
1.436 albertel 1400: $text = &mt($text);
1.1075.2.60 raeburn 1401: my $stay_on_page;
1402: unless ($env{'environment.remote'} eq 'on') {
1403: $stay_on_page = 1;
1404: }
1.1075.2.61 raeburn 1405: my ($link,$banner_link);
1406: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1407: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1408: : "javascript:helpMenu('open')";
1409: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1410: }
1.201 raeburn 1411: my $title = &mt('Get help');
1.1075.2.61 raeburn 1412: if ($link) {
1413: return <<"END";
1.436 albertel 1414: $banner_link
1.1075.2.158 raeburn 1415: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1416: END
1.1075.2.61 raeburn 1417: } else {
1418: return ' '.$text.' ';
1419: }
1.436 albertel 1420: }
1421:
1422: sub help_menu_js {
1.1075.2.52 raeburn 1423: my ($httphost) = @_;
1.949 droeschl 1424: my $stayOnPage = 1;
1.436 albertel 1425: my $width = 620;
1426: my $height = 600;
1.430 albertel 1427: my $helptopic=&general_help();
1.1075.2.52 raeburn 1428: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1429: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1430: my $start_page =
1431: &Apache::loncommon::start_page('Help Menu', undef,
1432: {'frameset' => 1,
1433: 'js_ready' => 1,
1.1075.2.136 raeburn 1434: 'use_absolute' => $httphost,
1.331 albertel 1435: 'add_entries' => {
1436: 'border' => '0',
1.579 raeburn 1437: 'rows' => "110,*",},});
1.331 albertel 1438: my $end_page =
1439: &Apache::loncommon::end_page({'frameset' => 1,
1440: 'js_ready' => 1,});
1441:
1.436 albertel 1442: my $template .= <<"ENDTEMPLATE";
1443: <script type="text/javascript">
1.877 bisitz 1444: // <![CDATA[
1.253 albertel 1445: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1446: var banner_link = '';
1.243 raeburn 1447: function helpMenu(target) {
1448: var caller = this;
1449: if (target == 'open') {
1450: var newWindow = null;
1451: try {
1.262 albertel 1452: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1453: }
1454: catch(error) {
1455: writeHelp(caller);
1456: return;
1457: }
1458: if (newWindow) {
1459: caller = newWindow;
1460: }
1.193 raeburn 1461: }
1.243 raeburn 1462: writeHelp(caller);
1463: return;
1464: }
1465: function writeHelp(caller) {
1.1075.2.61 raeburn 1466: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1467: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1468: caller.document.close();
1469: caller.focus();
1.193 raeburn 1470: }
1.877 bisitz 1471: // END LON-CAPA Internal -->
1.253 albertel 1472: // ]]>
1.436 albertel 1473: </script>
1.193 raeburn 1474: ENDTEMPLATE
1475: return $template;
1476: }
1477:
1.172 www 1478: sub help_open_bug {
1479: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1480: unless ($env{'user.adv'}) { return ''; }
1.172 www 1481: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1482: $text = "" if (not defined $text);
1483: $stayOnPage=1;
1.184 albertel 1484: $width = 600 if (not defined $width);
1485: $height = 600 if (not defined $height);
1.172 www 1486:
1487: $topic=~s/\W+/\+/g;
1488: my $link='';
1489: my $template='';
1.379 albertel 1490: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1491: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1492: if (!$stayOnPage)
1493: {
1494: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1495: }
1496: else
1497: {
1498: $link = $url;
1499: }
1.1075.2.161. .6(raebu 1500:22):
1501:22): my $target = '_top';
1502:22): if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1503:22): (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1504:22): $target = '_blank';
1505:22): }
1506:22):
1.172 www 1507: # Add the text
1508: if ($text ne "")
1509: {
1510: $template .=
1511: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1075.2.161. .6(raebu 1512:22): "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1513: }
1514:
1515: # Add the graphic
1.179 matthew 1516: my $title = &mt('Report a Bug');
1.215 albertel 1517: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1518: $template .= <<"ENDTEMPLATE";
1.1075.2.161. .6(raebu 1519:22): <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1520: ENDTEMPLATE
1521: if ($text ne '') { $template.='</td></tr></table>' };
1522: return $template;
1523:
1524: }
1525:
1526: sub help_open_faq {
1527: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1528: unless ($env{'user.adv'}) { return ''; }
1.172 www 1529: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1530: $text = "" if (not defined $text);
1531: $stayOnPage=1;
1532: $width = 350 if (not defined $width);
1533: $height = 400 if (not defined $height);
1534:
1535: $topic=~s/\W+/\+/g;
1536: my $link='';
1537: my $template='';
1538: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1539: if (!$stayOnPage)
1540: {
1541: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1542: }
1543: else
1544: {
1545: $link = $url;
1546: }
1547:
1548: # Add the text
1549: if ($text ne "")
1550: {
1551: $template .=
1.173 www 1552: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1553: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1554: }
1555:
1556: # Add the graphic
1.179 matthew 1557: my $title = &mt('View the FAQ');
1.215 albertel 1558: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1559: $template .= <<"ENDTEMPLATE";
1.436 albertel 1560: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1561: ENDTEMPLATE
1562: if ($text ne '') { $template.='</td></tr></table>' };
1563: return $template;
1564:
1.44 bowersj2 1565: }
1.37 matthew 1566:
1.180 matthew 1567: ###############################################################
1568: ###############################################################
1569:
1.45 matthew 1570: =pod
1571:
1.648 raeburn 1572: =item * &change_content_javascript():
1.256 matthew 1573:
1574: This and the next function allow you to create small sections of an
1575: otherwise static HTML page that you can update on the fly with
1576: Javascript, even in Netscape 4.
1577:
1578: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1579: must be written to the HTML page once. It will prove the Javascript
1580: function "change(name, content)". Calling the change function with the
1581: name of the section
1582: you want to update, matching the name passed to C<changable_area>, and
1583: the new content you want to put in there, will put the content into
1584: that area.
1585:
1586: B<Note>: Netscape 4 only reserves enough space for the changable area
1587: to contain room for the original contents. You need to "make space"
1588: for whatever changes you wish to make, and be B<sure> to check your
1589: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1590: it's adequate for updating a one-line status display, but little more.
1591: This script will set the space to 100% width, so you only need to
1592: worry about height in Netscape 4.
1593:
1594: Modern browsers are much less limiting, and if you can commit to the
1595: user not using Netscape 4, this feature may be used freely with
1596: pretty much any HTML.
1597:
1598: =cut
1599:
1600: sub change_content_javascript {
1601: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1602: if ($env{'browser.type'} eq 'netscape' &&
1603: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1604: return (<<NETSCAPE4);
1605: function change(name, content) {
1606: doc = document.layers[name+"___escape"].layers[0].document;
1607: doc.open();
1608: doc.write(content);
1609: doc.close();
1610: }
1611: NETSCAPE4
1612: } else {
1613: # Otherwise, we need to use semi-standards-compliant code
1614: # (technically, "innerHTML" isn't standard but the equivalent
1615: # is really scary, and every useful browser supports it
1616: return (<<DOMBASED);
1617: function change(name, content) {
1618: element = document.getElementById(name);
1619: element.innerHTML = content;
1620: }
1621: DOMBASED
1622: }
1623: }
1624:
1625: =pod
1626:
1.648 raeburn 1627: =item * &changable_area($name,$origContent):
1.256 matthew 1628:
1629: This provides a "changable area" that can be modified on the fly via
1630: the Javascript code provided in C<change_content_javascript>. $name is
1631: the name you will use to reference the area later; do not repeat the
1632: same name on a given HTML page more then once. $origContent is what
1633: the area will originally contain, which can be left blank.
1634:
1635: =cut
1636:
1637: sub changable_area {
1638: my ($name, $origContent) = @_;
1639:
1.258 albertel 1640: if ($env{'browser.type'} eq 'netscape' &&
1641: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1642: # If this is netscape 4, we need to use the Layer tag
1643: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1644: } else {
1645: return "<span id='$name'>$origContent</span>";
1646: }
1647: }
1648:
1649: =pod
1650:
1.648 raeburn 1651: =item * &viewport_geometry_js
1.590 raeburn 1652:
1653: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1654:
1655: =cut
1656:
1657:
1658: sub viewport_geometry_js {
1659: return <<"GEOMETRY";
1660: var Geometry = {};
1661: function init_geometry() {
1662: if (Geometry.init) { return };
1663: Geometry.init=1;
1664: if (window.innerHeight) {
1665: Geometry.getViewportHeight = function() { return window.innerHeight; };
1666: Geometry.getViewportWidth = function() { return window.innerWidth; };
1667: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1668: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1669: }
1670: else if (document.documentElement && document.documentElement.clientHeight) {
1671: Geometry.getViewportHeight =
1672: function() { return document.documentElement.clientHeight; };
1673: Geometry.getViewportWidth =
1674: function() { return document.documentElement.clientWidth; };
1675:
1676: Geometry.getHorizontalScroll =
1677: function() { return document.documentElement.scrollLeft; };
1678: Geometry.getVerticalScroll =
1679: function() { return document.documentElement.scrollTop; };
1680: }
1681: else if (document.body.clientHeight) {
1682: Geometry.getViewportHeight =
1683: function() { return document.body.clientHeight; };
1684: Geometry.getViewportWidth =
1685: function() { return document.body.clientWidth; };
1686: Geometry.getHorizontalScroll =
1687: function() { return document.body.scrollLeft; };
1688: Geometry.getVerticalScroll =
1689: function() { return document.body.scrollTop; };
1690: }
1691: }
1692:
1693: GEOMETRY
1694: }
1695:
1696: =pod
1697:
1.648 raeburn 1698: =item * &viewport_size_js()
1.590 raeburn 1699:
1700: 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.
1701:
1702: =cut
1703:
1704: sub viewport_size_js {
1705: my $geometry = &viewport_geometry_js();
1706: return <<"DIMS";
1707:
1708: $geometry
1709:
1710: function getViewportDims(width,height) {
1711: init_geometry();
1712: width.value = Geometry.getViewportWidth();
1713: height.value = Geometry.getViewportHeight();
1714: return;
1715: }
1716:
1717: DIMS
1718: }
1719:
1720: =pod
1721:
1.648 raeburn 1722: =item * &resize_textarea_js()
1.565 albertel 1723:
1724: emits the needed javascript to resize a textarea to be as big as possible
1725:
1726: creates a function resize_textrea that takes two IDs first should be
1727: the id of the element to resize, second should be the id of a div that
1728: surrounds everything that comes after the textarea, this routine needs
1729: to be attached to the <body> for the onload and onresize events.
1730:
1731: =cut
1732:
1733: sub resize_textarea_js {
1.590 raeburn 1734: my $geometry = &viewport_geometry_js();
1.565 albertel 1735: return <<"RESIZE";
1736: <script type="text/javascript">
1.824 bisitz 1737: // <![CDATA[
1.590 raeburn 1738: $geometry
1.565 albertel 1739:
1.588 albertel 1740: function getX(element) {
1741: var x = 0;
1742: while (element) {
1743: x += element.offsetLeft;
1744: element = element.offsetParent;
1745: }
1746: return x;
1747: }
1748: function getY(element) {
1749: var y = 0;
1750: while (element) {
1751: y += element.offsetTop;
1752: element = element.offsetParent;
1753: }
1754: return y;
1755: }
1756:
1757:
1.565 albertel 1758: function resize_textarea(textarea_id,bottom_id) {
1759: init_geometry();
1760: var textarea = document.getElementById(textarea_id);
1761: //alert(textarea);
1762:
1.588 albertel 1763: var textarea_top = getY(textarea);
1.565 albertel 1764: var textarea_height = textarea.offsetHeight;
1765: var bottom = document.getElementById(bottom_id);
1.588 albertel 1766: var bottom_top = getY(bottom);
1.565 albertel 1767: var bottom_height = bottom.offsetHeight;
1768: var window_height = Geometry.getViewportHeight();
1.588 albertel 1769: var fudge = 23;
1.565 albertel 1770: var new_height = window_height-fudge-textarea_top-bottom_height;
1771: if (new_height < 300) {
1772: new_height = 300;
1773: }
1774: textarea.style.height=new_height+'px';
1775: }
1.824 bisitz 1776: // ]]>
1.565 albertel 1777: </script>
1778: RESIZE
1779:
1780: }
1781:
1.1075.2.112 raeburn 1782: sub colorfuleditor_js {
1783: return <<"COLORFULEDIT"
1784: <script type="text/javascript">
1785: // <![CDATA[>
1786: function fold_box(curDepth, lastresource){
1787:
1788: // we need a list because there can be several blocks you need to fold in one tag
1789: var block = document.getElementsByName('foldblock_'+curDepth);
1790: // but there is only one folding button per tag
1791: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1792:
1793: if(block.item(0).style.display == 'none'){
1794:
1795: foldbutton.value = '@{[&mt("Hide")]}';
1796: for (i = 0; i < block.length; i++){
1797: block.item(i).style.display = '';
1798: }
1799: }else{
1800:
1801: foldbutton.value = '@{[&mt("Show")]}';
1802: for (i = 0; i < block.length; i++){
1803: // block.item(i).style.visibility = 'collapse';
1804: block.item(i).style.display = 'none';
1805: }
1806: };
1807: saveState(lastresource);
1808: }
1809:
1810: function saveState (lastresource) {
1811:
1812: var tag_list = getTagList();
1813: if(tag_list != null){
1814: var timestamp = new Date().getTime();
1815: var key = lastresource;
1816:
1817: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1818: // starting with timestamp
1819: var value = timestamp+';';
1820:
1821: // building the list of key-value pairs
1822: for(var i = 0; i < tag_list.length; i++){
1823: value += tag_list[i]+',';
1824: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1825: }
1826:
1827: // only iterate whole storage if nothing to override
1828: if(localStorage.getItem(key) == null){
1829:
1830: // prevent storage from growing large
1831: if(localStorage.length > 50){
1832: var regex_getTimestamp = /^(?:\d)+;/;
1833: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1834: var oldest_key;
1835:
1836: for(var i = 1; i < localStorage.length; i++){
1837: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1838: oldest_key = localStorage.key(i);
1839: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1840: }
1841: }
1842: localStorage.removeItem(oldest_key);
1843: }
1844: }
1845: localStorage.setItem(key,value);
1846: }
1847: }
1848:
1849: // restore folding status of blocks (on page load)
1850: function restoreState (lastresource) {
1851: if(localStorage.getItem(lastresource) != null){
1852: var key = lastresource;
1853: var value = localStorage.getItem(key);
1854: var regex_delTimestamp = /^\d+;/;
1855:
1856: value.replace(regex_delTimestamp, '');
1857:
1858: var valueArr = value.split(';');
1859: var pairs;
1860: var elements;
1861: for (var i = 0; i < valueArr.length; i++){
1862: pairs = valueArr[i].split(',');
1863: elements = document.getElementsByName(pairs[0]);
1864:
1865: for (var j = 0; j < elements.length; j++){
1866: elements[j].style.display = pairs[1];
1867: if (pairs[1] == "none"){
1868: var regex_id = /([_\\d]+)\$/;
1869: regex_id.exec(pairs[0]);
1870: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1871: }
1872: }
1873: }
1874: }
1875: }
1876:
1877: function getTagList () {
1878:
1879: var stringToSearch = document.lonhomework.innerHTML;
1880:
1881: var ret = new Array();
1882: var regex_findBlock = /(foldblock_.*?)"/g;
1883: var tag_list = stringToSearch.match(regex_findBlock);
1884:
1885: if(tag_list != null){
1886: for(var i = 0; i < tag_list.length; i++){
1887: ret.push(tag_list[i].replace(/"/, ''));
1888: }
1889: }
1890: return ret;
1891: }
1892:
1893: function saveScrollPosition (resource) {
1894: var tag_list = getTagList();
1895:
1896: // we dont always want to jump to the first block
1897: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1898: if(\$(window).scrollTop() > 170){
1899: if(tag_list != null){
1900: var result;
1901: for(var i = 0; i < tag_list.length; i++){
1902: if(isElementInViewport(tag_list[i])){
1903: result += tag_list[i]+';';
1904: }
1905: }
1906: sessionStorage.setItem('anchor_'+resource, result);
1907: }
1908: } else {
1909: // we dont need to save zero, just delete the item to leave everything tidy
1910: sessionStorage.removeItem('anchor_'+resource);
1911: }
1912: }
1913:
1914: function restoreScrollPosition(resource){
1915:
1916: var elem = sessionStorage.getItem('anchor_'+resource);
1917: if(elem != null){
1918: var tag_list = elem.split(';');
1919: var elem_list;
1920:
1921: for(var i = 0; i < tag_list.length; i++){
1922: elem_list = document.getElementsByName(tag_list[i]);
1923:
1924: if(elem_list.length > 0){
1925: elem = elem_list[0];
1926: break;
1927: }
1928: }
1929: elem.scrollIntoView();
1930: }
1931: }
1932:
1933: function isElementInViewport(el) {
1934:
1935: // change to last element instead of first
1936: var elem = document.getElementsByName(el);
1937: var rect = elem[0].getBoundingClientRect();
1938:
1939: return (
1940: rect.top >= 0 &&
1941: rect.left >= 0 &&
1942: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1943: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1944: );
1945: }
1946:
1947: function autosize(depth){
1948: var cmInst = window['cm'+depth];
1949: var fitsizeButton = document.getElementById('fitsize'+depth);
1950:
1951: // is fixed size, switching to dynamic
1952: if (sessionStorage.getItem("autosized_"+depth) == null) {
1953: cmInst.setSize("","auto");
1954: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1955: sessionStorage.setItem("autosized_"+depth, "yes");
1956:
1957: // is dynamic size, switching to fixed
1958: } else {
1959: cmInst.setSize("","300px");
1960: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1961: sessionStorage.removeItem("autosized_"+depth);
1962: }
1963: }
1964:
1965:
1966:
1967: // ]]>
1968: </script>
1969: COLORFULEDIT
1970: }
1971:
1972: sub xmleditor_js {
1973: return <<XMLEDIT
1974: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1975: <script type="text/javascript">
1976: // <![CDATA[>
1977:
1978: function saveScrollPosition (resource) {
1979:
1980: var scrollPos = \$(window).scrollTop();
1981: sessionStorage.setItem(resource,scrollPos);
1982: }
1983:
1984: function restoreScrollPosition(resource){
1985:
1986: var scrollPos = sessionStorage.getItem(resource);
1987: \$(window).scrollTop(scrollPos);
1988: }
1989:
1990: // unless internet explorer
1991: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1992:
1993: \$(document).ready(function() {
1994: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1995: });
1996: }
1997:
1998: // inserts text at cursor position into codemirror (xml editor only)
1999: function insertText(text){
2000: cm.focus();
2001: var curPos = cm.getCursor();
2002: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2003: }
2004: // ]]>
2005: </script>
2006: XMLEDIT
2007: }
2008:
2009: sub insert_folding_button {
2010: my $curDepth = $Apache::lonxml::curdepth;
2011: my $lastresource = $env{'request.ambiguous'};
2012:
2013: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2014: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2015: }
2016:
1.1075.2.161. .21(raeb 2017:-24): =pod
2018:-24):
2019:-24): =item * &iframe_wrapper_headjs()
2020:-24):
2021:-24): emits javascript containing two global vars to facilitate handling of resizing
2022:-24): by code in iframe_wrapper_resizejs() used when an iframe is present in a page
2023:-24): with standard LON-CAPA menus.
2024:-24):
2025:-24): =cut
2026:-24):
2027:-24): #
2028:-24): # Where iframe is in use, if window.onload() executes before the custom resize function
2029:-24): # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
2030:-24): # are used to ensure document.ready() triggers a call to resize, so the iframe contents
2031:-24): # do not obscure the Functions menu.
2032:-24): #
2033:-24):
2034:-24): sub iframe_wrapper_headjs {
2035:-24): return <<"ENDJS";
2036:-24): <script type="text/javascript">
2037:-24): // <![CDATA[
2038:-24): var LCnotready = 0;
2039:-24): var LCresizedef = 0;
2040:-24): // ]]>
2041:-24): </script>
2042:-24):
2043:-24): ENDJS
2044:-24):
2045:-24): }
2046:-24):
2047:-24): =pod
2048:-24):
2049:-24): =item * &iframe_wrapper_resizejs()
2050:-24):
2051:-24): emits javascript used to handle resizing for a page containing
2052:-24): an iframe, to ensure that the iframe does not obscure any
2053:-24): standard LON-CAPA menu items.
2054:-24):
2055:-24): =back
2056:-24):
2057:-24): =cut
2058:-24):
2059:-24): #
2060:-24): # jQuery to use when iframe is in use and a page resize occurs.
2061:-24): # This script will ensure that the iframe does not obscure any
2062:-24): # standard LON-CAPA inline menus (primary, secondary, and/or
2063:-24): # breadcrumbs and Functions menus. Expects javascript from
2064:-24): # &iframe_wrapper_headjs() to be in head portion of the web page,
2065:-24): # e.g., by inclusion in second arg passed to &start_page().
2066:-24): #
2067:-24):
2068:-24): sub iframe_wrapper_resizejs {
2069:-24): my $offset = 5;
2070:-24): &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
2071:-24): if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
2072:-24): $offset = 0;
2073:-24): }
2074:-24): return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
2075:-24): \$(document).ready( function() {
2076:-24): \$(window).unbind('resize').resize(function(){
2077:-24): var header = null;
2078:-24): var offset = $offset;
2079:-24): var height = 0;
2080:-24): var hdrtop = 0;
2081:-24): if (\$('div.LC_menus_content:first').length) {
2082:-24): if (\$('div.LC_menus_content:first').hasClass ("shown")) {
2083:-24): header = \$('div.LC_menus_content:first');
2084:-24): offset = 12;
2085:-24): }
2086:-24): } else if (\$('div.LC_head_subbox:first').length) {
2087:-24): header = \$('div.LC_head_subbox:first');
2088:-24): offset = 9;
2089:-24): } else {
2090:-24): if (\$('#LC_breadcrumbs').length) {
2091:-24): header = \$('#LC_breadcrumbs');
2092:-24): }
2093:-24): }
2094:-24): if (header != null && header.length) {
2095:-24): height = header.height();
2096:-24): hdrtop = header.position().top;
2097:-24): }
2098:-24): var pos = height + hdrtop + offset;
2099:-24): \$('.LC_iframecontainer').css('top', pos);
2100:-24): });
2101:-24): LCresizedef = 1;
2102:-24): if (LCnotready == 1) {
2103:-24): LCnotready = 0;
2104:-24): \$(window).trigger('resize');
2105:-24): }
2106:-24): });
2107:-24): window.onload = function(){
2108:-24): if (LCresizedef) {
2109:-24): LCnotready = 0;
2110:-24): \$(window).trigger('resize');
2111:-24): } else {
2112:-24): LCnotready = 1;
2113:-24): }
2114:-24): };
2115:-24): SCRIPT
2116:-24):
2117:-24): }
1.1075.2.112 raeburn 2118:
1.565 albertel 2119: =pod
2120:
1.256 matthew 2121: =head1 Excel and CSV file utility routines
2122:
2123: =cut
2124:
2125: ###############################################################
2126: ###############################################################
2127:
2128: =pod
2129:
1.1075.2.56 raeburn 2130: =over 4
2131:
1.648 raeburn 2132: =item * &csv_translate($text)
1.37 matthew 2133:
1.185 www 2134: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2135: format.
2136:
2137: =cut
2138:
1.180 matthew 2139: ###############################################################
2140: ###############################################################
1.37 matthew 2141: sub csv_translate {
2142: my $text = shift;
2143: $text =~ s/\"/\"\"/g;
1.209 albertel 2144: $text =~ s/\n/ /g;
1.37 matthew 2145: return $text;
2146: }
1.180 matthew 2147:
2148: ###############################################################
2149: ###############################################################
2150:
2151: =pod
2152:
1.648 raeburn 2153: =item * &define_excel_formats()
1.180 matthew 2154:
2155: Define some commonly used Excel cell formats.
2156:
2157: Currently supported formats:
2158:
2159: =over 4
2160:
2161: =item header
2162:
2163: =item bold
2164:
2165: =item h1
2166:
2167: =item h2
2168:
2169: =item h3
2170:
1.256 matthew 2171: =item h4
2172:
2173: =item i
2174:
1.180 matthew 2175: =item date
2176:
2177: =back
2178:
2179: Inputs: $workbook
2180:
2181: Returns: $format, a hash reference.
2182:
1.1057 foxr 2183:
1.180 matthew 2184: =cut
2185:
2186: ###############################################################
2187: ###############################################################
2188: sub define_excel_formats {
2189: my ($workbook) = @_;
2190: my $format;
2191: $format->{'header'} = $workbook->add_format(bold => 1,
2192: bottom => 1,
2193: align => 'center');
2194: $format->{'bold'} = $workbook->add_format(bold=>1);
2195: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2196: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2197: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2198: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2199: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2200: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2201: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2202: return $format;
2203: }
2204:
2205: ###############################################################
2206: ###############################################################
1.113 bowersj2 2207:
2208: =pod
2209:
1.648 raeburn 2210: =item * &create_workbook()
1.255 matthew 2211:
2212: Create an Excel worksheet. If it fails, output message on the
2213: request object and return undefs.
2214:
2215: Inputs: Apache request object
2216:
2217: Returns (undef) on failure,
2218: Excel worksheet object, scalar with filename, and formats
2219: from &Apache::loncommon::define_excel_formats on success
2220:
2221: =cut
2222:
2223: ###############################################################
2224: ###############################################################
2225: sub create_workbook {
2226: my ($r) = @_;
2227: #
2228: # Create the excel spreadsheet
2229: my $filename = '/prtspool/'.
1.258 albertel 2230: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2231: time.'_'.rand(1000000000).'.xls';
2232: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2233: if (! defined($workbook)) {
2234: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2235: $r->print(
2236: '<p class="LC_error">'
2237: .&mt('Problems occurred in creating the new Excel file.')
2238: .' '.&mt('This error has been logged.')
2239: .' '.&mt('Please alert your LON-CAPA administrator.')
2240: .'</p>'
2241: );
1.255 matthew 2242: return (undef);
2243: }
2244: #
1.1014 foxr 2245: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2246: #
2247: my $format = &Apache::loncommon::define_excel_formats($workbook);
2248: return ($workbook,$filename,$format);
2249: }
2250:
2251: ###############################################################
2252: ###############################################################
2253:
2254: =pod
2255:
1.648 raeburn 2256: =item * &create_text_file()
1.113 bowersj2 2257:
1.542 raeburn 2258: Create a file to write to and eventually make available to the user.
1.256 matthew 2259: If file creation fails, outputs an error message on the request object and
2260: return undefs.
1.113 bowersj2 2261:
1.256 matthew 2262: Inputs: Apache request object, and file suffix
1.113 bowersj2 2263:
1.256 matthew 2264: Returns (undef) on failure,
2265: Filehandle and filename on success.
1.113 bowersj2 2266:
2267: =cut
2268:
1.256 matthew 2269: ###############################################################
2270: ###############################################################
2271: sub create_text_file {
2272: my ($r,$suffix) = @_;
2273: if (! defined($suffix)) { $suffix = 'txt'; };
2274: my $fh;
2275: my $filename = '/prtspool/'.
1.258 albertel 2276: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2277: time.'_'.rand(1000000000).'.'.$suffix;
2278: $fh = Apache::File->new('>/home/httpd'.$filename);
2279: if (! defined($fh)) {
2280: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2281: $r->print(
2282: '<p class="LC_error">'
2283: .&mt('Problems occurred in creating the output file.')
2284: .' '.&mt('This error has been logged.')
2285: .' '.&mt('Please alert your LON-CAPA administrator.')
2286: .'</p>'
2287: );
1.113 bowersj2 2288: }
1.256 matthew 2289: return ($fh,$filename)
1.113 bowersj2 2290: }
2291:
2292:
1.256 matthew 2293: =pod
1.113 bowersj2 2294:
2295: =back
2296:
2297: =cut
1.37 matthew 2298:
2299: ###############################################################
1.33 matthew 2300: ## Home server <option> list generating code ##
2301: ###############################################################
1.35 matthew 2302:
1.169 www 2303: # ------------------------------------------
2304:
2305: sub domain_select {
2306: my ($name,$value,$multiple)=@_;
2307: my %domains=map {
1.514 albertel 2308: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2309: } &Apache::lonnet::all_domains();
1.169 www 2310: if ($multiple) {
2311: $domains{''}=&mt('Any domain');
1.550 albertel 2312: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2313: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2314: } else {
1.550 albertel 2315: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2316: return &select_form($name,$value,\%domains);
1.169 www 2317: }
2318: }
2319:
1.282 albertel 2320: #-------------------------------------------
2321:
2322: =pod
2323:
1.519 raeburn 2324: =head1 Routines for form select boxes
2325:
2326: =over 4
2327:
1.648 raeburn 2328: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2329:
2330: Returns a string containing a <select> element int multiple mode
2331:
2332:
2333: Args:
2334: $name - name of the <select> element
1.506 raeburn 2335: $value - scalar or array ref of values that should already be selected
1.282 albertel 2336: $size - number of rows long the select element is
1.283 albertel 2337: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2338: (shown text should already have been &mt())
1.506 raeburn 2339: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2340:
1.282 albertel 2341: =cut
2342:
2343: #-------------------------------------------
1.169 www 2344: sub multiple_select_form {
1.284 albertel 2345: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2346: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2347: my $output='';
1.191 matthew 2348: if (! defined($size)) {
2349: $size = 4;
1.283 albertel 2350: if (scalar(keys(%$hash))<4) {
2351: $size = scalar(keys(%$hash));
1.191 matthew 2352: }
2353: }
1.734 bisitz 2354: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2355: my @order;
1.506 raeburn 2356: if (ref($order) eq 'ARRAY') {
2357: @order = @{$order};
2358: } else {
2359: @order = sort(keys(%$hash));
1.501 banghart 2360: }
2361: if (exists($$hash{'select_form_order'})) {
2362: @order = @{$$hash{'select_form_order'}};
2363: }
2364:
1.284 albertel 2365: foreach my $key (@order) {
1.356 albertel 2366: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2367: $output.='selected="selected" ' if ($selected{$key});
2368: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2369: }
2370: $output.="</select>\n";
2371: return $output;
2372: }
2373:
1.88 www 2374: #-------------------------------------------
2375:
2376: =pod
2377:
1.1075.2.115 raeburn 2378: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2379:
2380: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2381: allow a user to select options from a ref to a hash containing:
2382: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2383: a javascript onchange item, e.g., onchange="this.form.submit();".
2384: An optional arg -- $readonly -- if true will cause the select form
2385: to be disabled, e.g., for the case where an instructor has a section-
2386: specific role, and is viewing/modifying parameters.
1.970 raeburn 2387:
1.88 www 2388: See lonrights.pm for an example invocation and use.
2389:
2390: =cut
2391:
2392: #-------------------------------------------
2393: sub select_form {
1.1075.2.115 raeburn 2394: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2395: return unless (ref($hashref) eq 'HASH');
2396: if ($onchange) {
2397: $onchange = ' onchange="'.$onchange.'"';
2398: }
1.1075.2.129 raeburn 2399: my $disabled;
2400: if ($readonly) {
2401: $disabled = ' disabled="disabled"';
2402: }
2403: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2404: my @keys;
1.970 raeburn 2405: if (exists($hashref->{'select_form_order'})) {
2406: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2407: } else {
1.970 raeburn 2408: @keys=sort(keys(%{$hashref}));
1.128 albertel 2409: }
1.356 albertel 2410: foreach my $key (@keys) {
2411: $selectform.=
2412: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2413: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2414: ">".$hashref->{$key}."</option>\n";
1.88 www 2415: }
2416: $selectform.="</select>";
2417: return $selectform;
2418: }
2419:
1.475 www 2420: # For display filters
2421:
2422: sub display_filter {
1.1074 raeburn 2423: my ($context) = @_;
1.475 www 2424: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2425: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2426: my $phraseinput = 'hidden';
2427: my $includeinput = 'hidden';
2428: my ($checked,$includetypestext);
2429: if ($env{'form.displayfilter'} eq 'containing') {
2430: $phraseinput = 'text';
2431: if ($context eq 'parmslog') {
2432: $includeinput = 'checkbox';
2433: if ($env{'form.includetypes'}) {
2434: $checked = ' checked="checked"';
2435: }
2436: $includetypestext = &mt('Include parameter types');
2437: }
2438: } else {
2439: $includetypestext = ' ';
2440: }
2441: my ($additional,$secondid,$thirdid);
2442: if ($context eq 'parmslog') {
2443: $additional =
2444: '<label><input type="'.$includeinput.'" name="includetypes"'.
2445: $checked.' name="includetypes" value="1" id="includetypes" />'.
2446: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2447: '</label>';
2448: $secondid = 'includetypes';
2449: $thirdid = 'includetypestext';
2450: }
2451: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2452: '$secondid','$thirdid')";
2453: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2454: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2455: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2456: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2457: &mt('Filter: [_1]',
1.477 www 2458: &select_form($env{'form.displayfilter'},
2459: 'displayfilter',
1.970 raeburn 2460: {'currentfolder' => 'Current folder/page',
1.477 www 2461: 'containing' => 'Containing phrase',
1.1074 raeburn 2462: 'none' => 'None'},$onchange)).' '.
2463: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2464: &HTML::Entities::encode($env{'form.containingphrase'}).
2465: '" />'.$additional;
2466: }
2467:
2468: sub display_filter_js {
2469: my $includetext = &mt('Include parameter types');
2470: return <<"ENDJS";
2471:
2472: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2473: var firstType = 'hidden';
2474: if (setter.options[setter.selectedIndex].value == 'containing') {
2475: firstType = 'text';
2476: }
2477: firstObject = document.getElementById(firstid);
2478: if (typeof(firstObject) == 'object') {
2479: if (firstObject.type != firstType) {
2480: changeInputType(firstObject,firstType);
2481: }
2482: }
2483: if (context == 'parmslog') {
2484: var secondType = 'hidden';
2485: if (firstType == 'text') {
2486: secondType = 'checkbox';
2487: }
2488: secondObject = document.getElementById(secondid);
2489: if (typeof(secondObject) == 'object') {
2490: if (secondObject.type != secondType) {
2491: changeInputType(secondObject,secondType);
2492: }
2493: }
2494: var textItem = document.getElementById(thirdid);
2495: var currtext = textItem.innerHTML;
2496: var newtext;
2497: if (firstType == 'text') {
2498: newtext = '$includetext';
2499: } else {
2500: newtext = ' ';
2501: }
2502: if (currtext != newtext) {
2503: textItem.innerHTML = newtext;
2504: }
2505: }
2506: return;
2507: }
2508:
2509: function changeInputType(oldObject,newType) {
2510: var newObject = document.createElement('input');
2511: newObject.type = newType;
2512: if (oldObject.size) {
2513: newObject.size = oldObject.size;
2514: }
2515: if (oldObject.value) {
2516: newObject.value = oldObject.value;
2517: }
2518: if (oldObject.name) {
2519: newObject.name = oldObject.name;
2520: }
2521: if (oldObject.id) {
2522: newObject.id = oldObject.id;
2523: }
2524: oldObject.parentNode.replaceChild(newObject,oldObject);
2525: return;
2526: }
2527:
2528: ENDJS
1.475 www 2529: }
2530:
1.167 www 2531: sub gradeleveldescription {
2532: my $gradelevel=shift;
2533: my %gradelevels=(0 => 'Not specified',
2534: 1 => 'Grade 1',
2535: 2 => 'Grade 2',
2536: 3 => 'Grade 3',
2537: 4 => 'Grade 4',
2538: 5 => 'Grade 5',
2539: 6 => 'Grade 6',
2540: 7 => 'Grade 7',
2541: 8 => 'Grade 8',
2542: 9 => 'Grade 9',
2543: 10 => 'Grade 10',
2544: 11 => 'Grade 11',
2545: 12 => 'Grade 12',
2546: 13 => 'Grade 13',
2547: 14 => '100 Level',
2548: 15 => '200 Level',
2549: 16 => '300 Level',
2550: 17 => '400 Level',
2551: 18 => 'Graduate Level');
2552: return &mt($gradelevels{$gradelevel});
2553: }
2554:
1.163 www 2555: sub select_level_form {
2556: my ($deflevel,$name)=@_;
2557: unless ($deflevel) { $deflevel=0; }
1.167 www 2558: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2559: for (my $i=0; $i<=18; $i++) {
2560: $selectform.="<option value=\"$i\" ".
1.253 albertel 2561: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2562: ">".&gradeleveldescription($i)."</option>\n";
2563: }
2564: $selectform.="</select>";
2565: return $selectform;
1.163 www 2566: }
1.167 www 2567:
1.35 matthew 2568: #-------------------------------------------
2569:
1.45 matthew 2570: =pod
2571:
1.1075.2.115 raeburn 2572: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2573:
2574: Returns a string containing a <select name='$name' size='1'> form to
2575: allow a user to select the domain to preform an operation in.
2576: See loncreateuser.pm for an example invocation and use.
2577:
1.90 www 2578: If the $includeempty flag is set, it also includes an empty choice ("no domain
2579: selected");
2580:
1.743 raeburn 2581: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2582:
1.910 raeburn 2583: 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.
2584:
1.1075.2.36 raeburn 2585: The optional $incdoms is a reference to an array of domains which will be the only available options.
2586:
1.1075.2.115 raeburn 2587: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2588:
2589: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2590:
1.35 matthew 2591: =cut
2592:
2593: #-------------------------------------------
1.34 matthew 2594: sub select_dom_form {
1.1075.2.115 raeburn 2595: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2596: if ($onchange) {
1.874 raeburn 2597: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2598: }
1.1075.2.115 raeburn 2599: if ($disabled) {
2600: $disabled = ' disabled="disabled"';
2601: }
1.1075.2.36 raeburn 2602: my (@domains,%exclude);
1.910 raeburn 2603: if (ref($incdoms) eq 'ARRAY') {
2604: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2605: } else {
2606: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2607: }
1.90 www 2608: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2609: if (ref($excdoms) eq 'ARRAY') {
2610: map { $exclude{$_} = 1; } @{$excdoms};
2611: }
1.1075.2.115 raeburn 2612: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2613: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2614: next if ($exclude{$dom});
1.356 albertel 2615: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2616: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2617: if ($showdomdesc) {
2618: if ($dom ne '') {
2619: my $domdesc = &Apache::lonnet::domain($dom,'description');
2620: if ($domdesc ne '') {
2621: $selectdomain .= ' ('.$domdesc.')';
2622: }
2623: }
2624: }
2625: $selectdomain .= "</option>\n";
1.34 matthew 2626: }
2627: $selectdomain.="</select>";
2628: return $selectdomain;
2629: }
2630:
1.35 matthew 2631: #-------------------------------------------
2632:
1.45 matthew 2633: =pod
2634:
1.648 raeburn 2635: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2636:
1.586 raeburn 2637: input: 4 arguments (two required, two optional) -
2638: $domain - domain of new user
2639: $name - name of form element
2640: $default - Value of 'default' causes a default item to be first
2641: option, and selected by default.
2642: $hide - Value of 'hide' causes hiding of the name of the server,
2643: if 1 server found, or default, if 0 found.
1.594 raeburn 2644: output: returns 2 items:
1.586 raeburn 2645: (a) form element which contains either:
2646: (i) <select name="$name">
2647: <option value="$hostid1">$hostid $servers{$hostid}</option>
2648: <option value="$hostid2">$hostid $servers{$hostid}</option>
2649: </select>
2650: form item if there are multiple library servers in $domain, or
2651: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2652: if there is only one library server in $domain.
2653:
2654: (b) number of library servers found.
2655:
2656: See loncreateuser.pm for example of use.
1.35 matthew 2657:
2658: =cut
2659:
2660: #-------------------------------------------
1.586 raeburn 2661: sub home_server_form_item {
2662: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2663: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2664: my $result;
2665: my $numlib = keys(%servers);
2666: if ($numlib > 1) {
2667: $result .= '<select name="'.$name.'" />'."\n";
2668: if ($default) {
1.804 bisitz 2669: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2670: '</option>'."\n";
2671: }
2672: foreach my $hostid (sort(keys(%servers))) {
2673: $result.= '<option value="'.$hostid.'">'.
2674: $hostid.' '.$servers{$hostid}."</option>\n";
2675: }
2676: $result .= '</select>'."\n";
2677: } elsif ($numlib == 1) {
2678: my $hostid;
2679: foreach my $item (keys(%servers)) {
2680: $hostid = $item;
2681: }
2682: $result .= '<input type="hidden" name="'.$name.'" value="'.
2683: $hostid.'" />';
2684: if (!$hide) {
2685: $result .= $hostid.' '.$servers{$hostid};
2686: }
2687: $result .= "\n";
2688: } elsif ($default) {
2689: $result .= '<input type="hidden" name="'.$name.
2690: '" value="default" />';
2691: if (!$hide) {
2692: $result .= &mt('default');
2693: }
2694: $result .= "\n";
1.33 matthew 2695: }
1.586 raeburn 2696: return ($result,$numlib);
1.33 matthew 2697: }
1.112 bowersj2 2698:
2699: =pod
2700:
1.534 albertel 2701: =back
2702:
1.112 bowersj2 2703: =cut
1.87 matthew 2704:
2705: ###############################################################
1.112 bowersj2 2706: ## Decoding User Agent ##
1.87 matthew 2707: ###############################################################
2708:
2709: =pod
2710:
1.112 bowersj2 2711: =head1 Decoding the User Agent
2712:
2713: =over 4
2714:
2715: =item * &decode_user_agent()
1.87 matthew 2716:
2717: Inputs: $r
2718:
2719: Outputs:
2720:
2721: =over 4
2722:
1.112 bowersj2 2723: =item * $httpbrowser
1.87 matthew 2724:
1.112 bowersj2 2725: =item * $clientbrowser
1.87 matthew 2726:
1.112 bowersj2 2727: =item * $clientversion
1.87 matthew 2728:
1.112 bowersj2 2729: =item * $clientmathml
1.87 matthew 2730:
1.112 bowersj2 2731: =item * $clientunicode
1.87 matthew 2732:
1.112 bowersj2 2733: =item * $clientos
1.87 matthew 2734:
1.1075.2.42 raeburn 2735: =item * $clientmobile
2736:
2737: =item * $clientinfo
2738:
1.1075.2.77 raeburn 2739: =item * $clientosversion
2740:
1.87 matthew 2741: =back
2742:
1.157 matthew 2743: =back
2744:
1.87 matthew 2745: =cut
2746:
2747: ###############################################################
2748: ###############################################################
2749: sub decode_user_agent {
1.247 albertel 2750: my ($r)=@_;
1.87 matthew 2751: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2752: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2753: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2754: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2755: my $clientbrowser='unknown';
2756: my $clientversion='0';
2757: my $clientmathml='';
2758: my $clientunicode='0';
1.1075.2.42 raeburn 2759: my $clientmobile=0;
1.1075.2.77 raeburn 2760: my $clientosversion='';
1.87 matthew 2761: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2762: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2763: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2764: $clientbrowser=$bname;
2765: $httpbrowser=~/$vreg/i;
2766: $clientversion=$1;
2767: $clientmathml=($clientversion>=$minv);
2768: $clientunicode=($clientversion>=$univ);
2769: }
2770: }
2771: my $clientos='unknown';
1.1075.2.42 raeburn 2772: my $clientinfo;
1.87 matthew 2773: if (($httpbrowser=~/linux/i) ||
2774: ($httpbrowser=~/unix/i) ||
2775: ($httpbrowser=~/ux/i) ||
2776: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2777: if (($httpbrowser=~/vax/i) ||
2778: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2779: if ($httpbrowser=~/next/i) { $clientos='next'; }
2780: if (($httpbrowser=~/mac/i) ||
2781: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2782: if ($httpbrowser=~/win/i) {
2783: $clientos='win';
2784: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2785: $clientosversion = $1;
2786: }
2787: }
1.87 matthew 2788: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2789: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2790: $clientmobile=lc($1);
2791: }
2792: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2793: $clientinfo = 'firefox-'.$1;
2794: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2795: $clientinfo = 'chromeframe-'.$1;
2796: }
1.87 matthew 2797: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2798: $clientunicode,$clientos,$clientmobile,$clientinfo,
2799: $clientosversion);
1.87 matthew 2800: }
2801:
1.32 matthew 2802: ###############################################################
2803: ## Authentication changing form generation subroutines ##
2804: ###############################################################
2805: ##
2806: ## All of the authform_xxxxxxx subroutines take their inputs in a
2807: ## hash, and have reasonable default values.
2808: ##
2809: ## formname = the name given in the <form> tag.
1.35 matthew 2810: #-------------------------------------------
2811:
1.45 matthew 2812: =pod
2813:
1.112 bowersj2 2814: =head1 Authentication Routines
2815:
2816: =over 4
2817:
1.648 raeburn 2818: =item * &authform_xxxxxx()
1.35 matthew 2819:
2820: The authform_xxxxxx subroutines provide javascript and html forms which
2821: handle some of the conveniences required for authentication forms.
2822: This is not an optimal method, but it works.
2823:
2824: =over 4
2825:
1.112 bowersj2 2826: =item * authform_header
1.35 matthew 2827:
1.112 bowersj2 2828: =item * authform_authorwarning
1.35 matthew 2829:
1.112 bowersj2 2830: =item * authform_nochange
1.35 matthew 2831:
1.112 bowersj2 2832: =item * authform_kerberos
1.35 matthew 2833:
1.112 bowersj2 2834: =item * authform_internal
1.35 matthew 2835:
1.112 bowersj2 2836: =item * authform_filesystem
1.35 matthew 2837:
1.1075.2.161. .17(raeb 2838:-23): =item * authform_lti
2839:-23):
1.35 matthew 2840: =back
2841:
1.648 raeburn 2842: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2843:
1.35 matthew 2844: =cut
2845:
2846: #-------------------------------------------
1.32 matthew 2847: sub authform_header{
2848: my %in = (
2849: formname => 'cu',
1.80 albertel 2850: kerb_def_dom => '',
1.32 matthew 2851: @_,
2852: );
2853: $in{'formname'} = 'document.' . $in{'formname'};
2854: my $result='';
1.80 albertel 2855:
2856: #---------------------------------------------- Code for upper case translation
2857: my $Javascript_toUpperCase;
2858: unless ($in{kerb_def_dom}) {
2859: $Javascript_toUpperCase =<<"END";
2860: switch (choice) {
2861: case 'krb': currentform.elements[choicearg].value =
2862: currentform.elements[choicearg].value.toUpperCase();
2863: break;
2864: default:
2865: }
2866: END
2867: } else {
2868: $Javascript_toUpperCase = "";
2869: }
2870:
1.165 raeburn 2871: my $radioval = "'nochange'";
1.591 raeburn 2872: if (defined($in{'curr_authtype'})) {
2873: if ($in{'curr_authtype'} ne '') {
2874: $radioval = "'".$in{'curr_authtype'}."arg'";
2875: }
1.174 matthew 2876: }
1.165 raeburn 2877: my $argfield = 'null';
1.591 raeburn 2878: if (defined($in{'mode'})) {
1.165 raeburn 2879: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2880: if (defined($in{'curr_autharg'})) {
2881: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2882: $argfield = "'$in{'curr_autharg'}'";
2883: }
2884: }
2885: }
2886: }
2887:
1.32 matthew 2888: $result.=<<"END";
2889: var current = new Object();
1.165 raeburn 2890: current.radiovalue = $radioval;
2891: current.argfield = $argfield;
1.32 matthew 2892:
2893: function changed_radio(choice,currentform) {
2894: var choicearg = choice + 'arg';
2895: // If a radio button in changed, we need to change the argfield
2896: if (current.radiovalue != choice) {
2897: current.radiovalue = choice;
2898: if (current.argfield != null) {
2899: currentform.elements[current.argfield].value = '';
2900: }
2901: if (choice == 'nochange') {
2902: current.argfield = null;
2903: } else {
2904: current.argfield = choicearg;
2905: switch(choice) {
2906: case 'krb':
2907: currentform.elements[current.argfield].value =
2908: "$in{'kerb_def_dom'}";
2909: break;
2910: default:
2911: break;
2912: }
2913: }
2914: }
2915: return;
2916: }
1.22 www 2917:
1.32 matthew 2918: function changed_text(choice,currentform) {
2919: var choicearg = choice + 'arg';
2920: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2921: $Javascript_toUpperCase
1.32 matthew 2922: // clear old field
2923: if ((current.argfield != choicearg) && (current.argfield != null)) {
2924: currentform.elements[current.argfield].value = '';
2925: }
2926: current.argfield = choicearg;
2927: }
2928: set_auth_radio_buttons(choice,currentform);
2929: return;
1.20 www 2930: }
1.32 matthew 2931:
2932: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2933: var numauthchoices = currentform.login.length;
2934: if (typeof numauthchoices == "undefined") {
2935: return;
2936: }
1.32 matthew 2937: var i=0;
1.986 raeburn 2938: while (i < numauthchoices) {
1.32 matthew 2939: if (currentform.login[i].value == newvalue) { break; }
2940: i++;
2941: }
1.986 raeburn 2942: if (i == numauthchoices) {
1.32 matthew 2943: return;
2944: }
2945: current.radiovalue = newvalue;
2946: currentform.login[i].checked = true;
2947: return;
2948: }
2949: END
2950: return $result;
2951: }
2952:
1.1075.2.20 raeburn 2953: sub authform_authorwarning {
1.32 matthew 2954: my $result='';
1.144 matthew 2955: $result='<i>'.
2956: &mt('As a general rule, only authors or co-authors should be '.
2957: 'filesystem authenticated '.
2958: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2959: return $result;
2960: }
2961:
1.1075.2.20 raeburn 2962: sub authform_nochange {
1.32 matthew 2963: my %in = (
2964: formname => 'document.cu',
2965: kerb_def_dom => 'MSU.EDU',
2966: @_,
2967: );
1.1075.2.20 raeburn 2968: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2969: my $result;
1.1075.2.20 raeburn 2970: if (!$authnum) {
2971: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2972: } else {
2973: $result = '<label>'.&mt('[_1] Do not change login data',
2974: '<input type="radio" name="login" value="nochange" '.
2975: 'checked="checked" onclick="'.
1.281 albertel 2976: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2977: '</label>';
1.586 raeburn 2978: }
1.32 matthew 2979: return $result;
2980: }
2981:
1.591 raeburn 2982: sub authform_kerberos {
1.32 matthew 2983: my %in = (
2984: formname => 'document.cu',
2985: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2986: kerb_def_auth => 'krb4',
1.32 matthew 2987: @_,
2988: );
1.586 raeburn 2989: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2990: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2991: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2992: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2993: $check5 = ' checked="checked"';
1.80 albertel 2994: } else {
1.772 bisitz 2995: $check4 = ' checked="checked"';
1.80 albertel 2996: }
1.1075.2.117 raeburn 2997: if ($in{'readonly'}) {
2998: $disabled = ' disabled="disabled"';
2999: }
1.165 raeburn 3000: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3001: if (defined($in{'curr_authtype'})) {
3002: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3003: $krbcheck = ' checked="checked"';
1.623 raeburn 3004: if (defined($in{'mode'})) {
3005: if ($in{'mode'} eq 'modifyuser') {
3006: $krbcheck = '';
3007: }
3008: }
1.591 raeburn 3009: if (defined($in{'curr_kerb_ver'})) {
3010: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3011: $check5 = ' checked="checked"';
1.591 raeburn 3012: $check4 = '';
3013: } else {
1.772 bisitz 3014: $check4 = ' checked="checked"';
1.591 raeburn 3015: $check5 = '';
3016: }
1.586 raeburn 3017: }
1.591 raeburn 3018: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3019: $krbarg = $in{'curr_autharg'};
3020: }
1.586 raeburn 3021: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3022: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3023: $result =
3024: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3025: $in{'curr_autharg'},$krbver);
3026: } else {
3027: $result =
3028: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3029: }
3030: return $result;
3031: }
3032: }
3033: } else {
3034: if ($authnum == 1) {
1.784 bisitz 3035: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3036: }
3037: }
1.586 raeburn 3038: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3039: return;
1.587 raeburn 3040: } elsif ($authtype eq '') {
1.591 raeburn 3041: if (defined($in{'mode'})) {
1.587 raeburn 3042: if ($in{'mode'} eq 'modifycourse') {
3043: if ($authnum == 1) {
1.1075.2.117 raeburn 3044: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3045: }
3046: }
3047: }
1.586 raeburn 3048: }
3049: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3050: if ($authtype eq '') {
3051: $authtype = '<input type="radio" name="login" value="krb" '.
3052: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 3053: $krbcheck.$disabled.' />';
1.586 raeburn 3054: }
3055: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 3056: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3057: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 3058: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3059: $in{'curr_authtype'} eq 'krb4')) {
3060: $result .= &mt
1.144 matthew 3061: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3062: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3063: '<label>'.$authtype,
1.281 albertel 3064: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3065: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 3066: 'onchange="'.$jscall.'"'.$disabled.' />',
3067: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3068: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3069: '</label>');
1.586 raeburn 3070: } elsif ($can_assign{'krb4'}) {
3071: $result .= &mt
3072: ('[_1] Kerberos authenticated with domain [_2] '.
3073: '[_3] Version 4 [_4]',
3074: '<label>'.$authtype,
3075: '</label><input type="text" size="10" name="krbarg" '.
3076: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 3077: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3078: '<label><input type="hidden" name="krbver" value="4" />',
3079: '</label>');
3080: } elsif ($can_assign{'krb5'}) {
3081: $result .= &mt
3082: ('[_1] Kerberos authenticated with domain [_2] '.
3083: '[_3] Version 5 [_4]',
3084: '<label>'.$authtype,
3085: '</label><input type="text" size="10" name="krbarg" '.
3086: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 3087: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3088: '<label><input type="hidden" name="krbver" value="5" />',
3089: '</label>');
3090: }
1.32 matthew 3091: return $result;
3092: }
3093:
1.1075.2.20 raeburn 3094: sub authform_internal {
1.586 raeburn 3095: my %in = (
1.32 matthew 3096: formname => 'document.cu',
3097: kerb_def_dom => 'MSU.EDU',
3098: @_,
3099: );
1.1075.2.117 raeburn 3100: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3101: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3102: if ($in{'readonly'}) {
3103: $disabled = ' disabled="disabled"';
3104: }
1.591 raeburn 3105: if (defined($in{'curr_authtype'})) {
3106: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3107: if ($can_assign{'int'}) {
1.772 bisitz 3108: $intcheck = 'checked="checked" ';
1.623 raeburn 3109: if (defined($in{'mode'})) {
3110: if ($in{'mode'} eq 'modifyuser') {
3111: $intcheck = '';
3112: }
3113: }
1.591 raeburn 3114: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3115: $intarg = $in{'curr_autharg'};
3116: }
3117: } else {
3118: $result = &mt('Currently internally authenticated.');
3119: return $result;
1.165 raeburn 3120: }
3121: }
1.586 raeburn 3122: } else {
3123: if ($authnum == 1) {
1.784 bisitz 3124: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3125: }
3126: }
3127: if (!$can_assign{'int'}) {
3128: return;
1.587 raeburn 3129: } elsif ($authtype eq '') {
1.591 raeburn 3130: if (defined($in{'mode'})) {
1.587 raeburn 3131: if ($in{'mode'} eq 'modifycourse') {
3132: if ($authnum == 1) {
1.1075.2.117 raeburn 3133: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3134: }
3135: }
3136: }
1.165 raeburn 3137: }
1.586 raeburn 3138: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3139: if ($authtype eq '') {
3140: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3141: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3142: }
1.605 bisitz 3143: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3144: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3145: $result = &mt
1.144 matthew 3146: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3147: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3148: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3149: return $result;
3150: }
3151:
1.1075.2.20 raeburn 3152: sub authform_local {
1.32 matthew 3153: my %in = (
3154: formname => 'document.cu',
3155: kerb_def_dom => 'MSU.EDU',
3156: @_,
3157: );
1.1075.2.117 raeburn 3158: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3159: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3160: if ($in{'readonly'}) {
3161: $disabled = ' disabled="disabled"';
3162: }
1.591 raeburn 3163: if (defined($in{'curr_authtype'})) {
3164: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3165: if ($can_assign{'loc'}) {
1.772 bisitz 3166: $loccheck = 'checked="checked" ';
1.623 raeburn 3167: if (defined($in{'mode'})) {
3168: if ($in{'mode'} eq 'modifyuser') {
3169: $loccheck = '';
3170: }
3171: }
1.591 raeburn 3172: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3173: $locarg = $in{'curr_autharg'};
3174: }
3175: } else {
3176: $result = &mt('Currently using local (institutional) authentication.');
3177: return $result;
1.165 raeburn 3178: }
3179: }
1.586 raeburn 3180: } else {
3181: if ($authnum == 1) {
1.784 bisitz 3182: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3183: }
3184: }
3185: if (!$can_assign{'loc'}) {
3186: return;
1.587 raeburn 3187: } elsif ($authtype eq '') {
1.591 raeburn 3188: if (defined($in{'mode'})) {
1.587 raeburn 3189: if ($in{'mode'} eq 'modifycourse') {
3190: if ($authnum == 1) {
1.1075.2.117 raeburn 3191: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3192: }
3193: }
3194: }
1.165 raeburn 3195: }
1.586 raeburn 3196: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3197: if ($authtype eq '') {
3198: $authtype = '<input type="radio" name="login" value="loc" '.
3199: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3200: $jscall.'"'.$disabled.' />';
1.586 raeburn 3201: }
3202: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3203: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3204: $result = &mt('[_1] Local Authentication with argument [_2]',
3205: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3206: return $result;
3207: }
3208:
1.1075.2.20 raeburn 3209: sub authform_filesystem {
1.32 matthew 3210: my %in = (
3211: formname => 'document.cu',
3212: kerb_def_dom => 'MSU.EDU',
3213: @_,
3214: );
1.1075.2.117 raeburn 3215: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3216: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3217: if ($in{'readonly'}) {
3218: $disabled = ' disabled="disabled"';
3219: }
1.591 raeburn 3220: if (defined($in{'curr_authtype'})) {
3221: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3222: if ($can_assign{'fsys'}) {
1.772 bisitz 3223: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3224: if (defined($in{'mode'})) {
3225: if ($in{'mode'} eq 'modifyuser') {
3226: $fsyscheck = '';
3227: }
3228: }
1.586 raeburn 3229: } else {
3230: $result = &mt('Currently Filesystem Authenticated.');
3231: return $result;
3232: }
3233: }
3234: } else {
3235: if ($authnum == 1) {
1.784 bisitz 3236: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3237: }
3238: }
3239: if (!$can_assign{'fsys'}) {
3240: return;
1.587 raeburn 3241: } elsif ($authtype eq '') {
1.591 raeburn 3242: if (defined($in{'mode'})) {
1.587 raeburn 3243: if ($in{'mode'} eq 'modifycourse') {
3244: if ($authnum == 1) {
1.1075.2.117 raeburn 3245: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3246: }
3247: }
3248: }
1.586 raeburn 3249: }
3250: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3251: if ($authtype eq '') {
3252: $authtype = '<input type="radio" name="login" value="fsys" '.
3253: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3254: $jscall.'"'.$disabled.' />';
1.586 raeburn 3255: }
1.1075.2.158 raeburn 3256: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3257: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3258: $result = &mt
1.144 matthew 3259: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1075.2.158 raeburn 3260: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3261: return $result;
3262: }
3263:
1.1075.2.161. .17(raeb 3264:-23): sub authform_lti {
3265:-23): my %in = (
3266:-23): formname => 'document.cu',
3267:-23): kerb_def_dom => 'MSU.EDU',
3268:-23): @_,
3269:-23): );
3270:-23): my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3271:-23): my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3272:-23): if ($in{'readonly'}) {
3273:-23): $disabled = ' disabled="disabled"';
3274:-23): }
3275:-23): if (defined($in{'curr_authtype'})) {
3276:-23): if ($in{'curr_authtype'} eq 'lti') {
3277:-23): if ($can_assign{'lti'}) {
3278:-23): $lticheck = 'checked="checked" ';
3279:-23): if (defined($in{'mode'})) {
3280:-23): if ($in{'mode'} eq 'modifyuser') {
3281:-23): $lticheck = '';
3282:-23): }
3283:-23): }
3284:-23): } else {
3285:-23): $result = &mt('Currently LTI Authenticated.');
3286:-23): return $result;
3287:-23): }
3288:-23): }
3289:-23): } else {
3290:-23): if ($authnum == 1) {
3291:-23): $authtype = '<input type="hidden" name="login" value="lti" />';
3292:-23): }
3293:-23): }
3294:-23): if (!$can_assign{'lti'}) {
3295:-23): return;
3296:-23): } elsif ($authtype eq '') {
3297:-23): if (defined($in{'mode'})) {
3298:-23): if ($in{'mode'} eq 'modifycourse') {
3299:-23): if ($authnum == 1) {
3300:-23): $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3301:-23): }
3302:-23): }
3303:-23): }
3304:-23): }
3305:-23): $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3306:-23): if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3307:-23): $authtype = '<input type="radio" name="login" value="lti" '.
3308:-23): $lticheck.' onchange="'.$jscall.'" onclick="'.
3309:-23): $jscall.'"'.$disabled.' />';
3310:-23): }
3311:-23): $autharg = '<input type="hidden" name="ltiarg" value="" />';
3312:-23): if ($authtype) {
3313:-23): $result = &mt('[_1] LTI Authenticated',
3314:-23): '<label>'.$authtype.'</label>'.$autharg);
3315:-23): } else {
3316:-23): $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3317:-23): $autharg;
3318:-23): }
3319:-23): return $result;
3320:-23): }
3321:-23):
1.586 raeburn 3322: sub get_assignable_auth {
3323: my ($dom) = @_;
3324: if ($dom eq '') {
3325: $dom = $env{'request.role.domain'};
3326: }
3327: my %can_assign = (
3328: krb4 => 1,
3329: krb5 => 1,
3330: int => 1,
3331: loc => 1,
3332: );
3333: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3334: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3335: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3336: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3337: my $context;
3338: if ($env{'request.role'} =~ /^au/) {
3339: $context = 'author';
1.1075.2.117 raeburn 3340: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3341: $context = 'domain';
3342: } elsif ($env{'request.course.id'}) {
3343: $context = 'course';
3344: }
3345: if ($context) {
3346: if (ref($authhash->{$context}) eq 'HASH') {
3347: %can_assign = %{$authhash->{$context}};
3348: }
3349: }
3350: }
3351: }
3352: my $authnum = 0;
3353: foreach my $key (keys(%can_assign)) {
3354: if ($can_assign{$key}) {
3355: $authnum ++;
3356: }
3357: }
3358: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3359: $authnum --;
3360: }
3361: return ($authnum,%can_assign);
3362: }
3363:
1.1075.2.137 raeburn 3364: sub check_passwd_rules {
3365: my ($domain,$plainpass) = @_;
3366: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3367: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3368: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3369: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3370: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3371: if ($passwdconf{'min'} > $min) {
3372: $min = $passwdconf{'min'};
3373: }
1.1075.2.137 raeburn 3374: }
3375: if ($passwdconf{'max'} =~ /^\d+$/) {
3376: $max = $passwdconf{'max'};
3377: }
3378: @chars = @{$passwdconf{'chars'}};
3379: }
3380: if (($min) && (length($plainpass) < $min)) {
3381: push(@brokerule,'min');
3382: }
3383: if (($max) && (length($plainpass) > $max)) {
3384: push(@brokerule,'max');
3385: }
3386: if (@chars) {
3387: my %rules;
3388: map { $rules{$_} = 1; } @chars;
3389: if ($rules{'uc'}) {
3390: unless ($plainpass =~ /[A-Z]/) {
3391: push(@brokerule,'uc');
3392: }
3393: }
3394: if ($rules{'lc'}) {
3395: unless ($plainpass =~ /[a-z]/) {
3396: push(@brokerule,'lc');
3397: }
3398: }
3399: if ($rules{'num'}) {
3400: unless ($plainpass =~ /\d/) {
3401: push(@brokerule,'num');
3402: }
3403: }
3404: if ($rules{'spec'}) {
3405: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3406: push(@brokerule,'spec');
3407: }
3408: }
3409: }
3410: if (@brokerule) {
3411: my %rulenames = &Apache::lonlocal::texthash(
3412: uc => 'At least one upper case letter',
3413: lc => 'At least one lower case letter',
3414: num => 'At least one number',
3415: spec => 'At least one non-alphanumeric',
3416: );
3417: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3418: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3419: $rulenames{'num'} .= ': 0123456789';
3420: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3421: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3422: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3423: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3424: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3425: if (grep(/^$rule$/,@brokerule)) {
3426: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3427: }
3428: }
3429: $warning .= '</ul>';
3430: }
3431: if (wantarray) {
3432: return @brokerule;
3433: }
3434: return $warning;
3435: }
3436:
1.1075.2.161. .5(raebu 3437:22): sub passwd_validation_js {
3438:22): my ($currpasswdval,$domain,$context,$id) = @_;
3439:22): my (%passwdconf,$alertmsg);
3440:22): if ($context eq 'linkprot') {
3441:22): my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3442:22): if (ref($domconfig{'ltisec'}) eq 'HASH') {
3443:22): if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3444:22): %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3445:22): }
3446:22): }
3447:22): if ($id eq 'add') {
3448:22): $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3449:22): } elsif ($id =~ /^\d+$/) {
3450:22): my $pos = $id+1;
3451:22): $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3452:22): } else {
3453:22): $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3454:22): }
3455:22): } else {
3456:22): %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3457:22): $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3458:22): }
3459:22): my ($min,$max,@chars,$numrules,$intargjs,%alert);
3460:22): $numrules = 0;
3461:22): $min = $Apache::lonnet::passwdmin;
3462:22): if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3463:22): if ($passwdconf{'min'} =~ /^\d+$/) {
3464:22): if ($passwdconf{'min'} > $min) {
3465:22): $min = $passwdconf{'min'};
3466:22): }
3467:22): }
3468:22): if ($passwdconf{'max'} =~ /^\d+$/) {
3469:22): $max = $passwdconf{'max'};
3470:22): $numrules ++;
3471:22): }
3472:22): @chars = @{$passwdconf{'chars'}};
3473:22): if (@chars) {
3474:22): $numrules ++;
3475:22): }
3476:22): }
3477:22): if ($min > 0) {
3478:22): $numrules ++;
3479:22): }
3480:22): if (($min > 0) || ($max ne '') || (@chars > 0)) {
3481:22): if ($min) {
3482:22): $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3483:22): }
3484:22): if ($max) {
3485:22): $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3486:22): }
3487:22): my (@charalerts,@charrules);
3488:22): if (@chars) {
3489:22): if (grep(/^uc$/,@chars)) {
3490:22): push(@charalerts,&mt('contain at least one upper case letter'));
3491:22): push(@charrules,'uc');
3492:22): }
3493:22): if (grep(/^lc$/,@chars)) {
3494:22): push(@charalerts,&mt('contain at least one lower case letter'));
3495:22): push(@charrules,'lc');
3496:22): }
3497:22): if (grep(/^num$/,@chars)) {
3498:22): push(@charalerts,&mt('contain at least one number'));
3499:22): push(@charrules,'num');
3500:22): }
3501:22): if (grep(/^spec$/,@chars)) {
3502:22): push(@charalerts,&mt('contain at least one non-alphanumeric'));
3503:22): push(@charrules,'spec');
3504:22): }
3505:22): }
3506:22): $intargjs = qq| var rulesmsg = '';\n|.
3507:22): qq| var currpwval = $currpasswdval;\n|;
3508:22): if ($min) {
3509:22): $intargjs .= qq|
3510:22): if (currpwval.length < $min) {
3511:22): rulesmsg += ' - $alert{min}';
3512:22): }
3513:22): |;
3514:22): }
3515:22): if ($max) {
3516:22): $intargjs .= qq|
3517:22): if (currpwval.length > $max) {
3518:22): rulesmsg += ' - $alert{max}';
3519:22): }
3520:22): |;
3521:22): }
3522:22): if (@chars > 0) {
3523:22): my $charrulestr = '"'.join('","',@charrules).'"';
3524:22): my $charalertstr = '"'.join('","',@charalerts).'"';
3525:22): $intargjs .= qq| var brokerules = new Array();\n|.
3526:22): qq| var charrules = new Array($charrulestr);\n|.
3527:22): qq| var charalerts = new Array($charalertstr);\n|;
3528:22): my %rules;
3529:22): map { $rules{$_} = 1; } @chars;
3530:22): if ($rules{'uc'}) {
3531:22): $intargjs .= qq|
3532:22): var ucRegExp = /[A-Z]/;
3533:22): if (!ucRegExp.test(currpwval)) {
3534:22): brokerules.push('uc');
3535:22): }
3536:22): |;
3537:22): }
3538:22): if ($rules{'lc'}) {
3539:22): $intargjs .= qq|
3540:22): var lcRegExp = /[a-z]/;
3541:22): if (!lcRegExp.test(currpwval)) {
3542:22): brokerules.push('lc');
3543:22): }
3544:22): |;
3545:22): }
3546:22): if ($rules{'num'}) {
3547:22): $intargjs .= qq|
3548:22): var numRegExp = /[0-9]/;
3549:22): if (!numRegExp.test(currpwval)) {
3550:22): brokerules.push('num');
3551:22): }
3552:22): |;
3553:22): }
3554:22): if ($rules{'spec'}) {
3555:22): $intargjs .= q|
3556:22): var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3557:22): if (!specRegExp.test(currpwval)) {
3558:22): brokerules.push('spec');
3559:22): }
3560:22): |;
3561:22): }
3562:22): $intargjs .= qq|
3563:22): if (brokerules.length > 0) {
3564:22): for (var i=0; i<brokerules.length; i++) {
3565:22): for (var j=0; j<charrules.length; j++) {
3566:22): if (brokerules[i] == charrules[j]) {
3567:22): rulesmsg += ' - '+charalerts[j]+'\\n';
3568:22): break;
3569:22): }
3570:22): }
3571:22): }
3572:22): }
3573:22): |;
3574:22): }
3575:22): $intargjs .= qq|
3576:22): if (rulesmsg != '') {
3577:22): rulesmsg = '$alertmsg'+rulesmsg;
3578:22): alert(rulesmsg);
3579:22): return false;
3580:22): }
3581:22): |;
3582:22): }
3583:22): return ($numrules,$intargjs);
3584:22): }
3585:22):
1.80 albertel 3586: ###############################################################
3587: ## Get Kerberos Defaults for Domain ##
3588: ###############################################################
3589: ##
3590: ## Returns default kerberos version and an associated argument
3591: ## as listed in file domain.tab. If not listed, provides
3592: ## appropriate default domain and kerberos version.
3593: ##
3594: #-------------------------------------------
3595:
3596: =pod
3597:
1.648 raeburn 3598: =item * &get_kerberos_defaults()
1.80 albertel 3599:
3600: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3601: version and domain. If not found, it defaults to version 4 and the
3602: domain of the server.
1.80 albertel 3603:
1.648 raeburn 3604: =over 4
3605:
1.80 albertel 3606: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3607:
1.648 raeburn 3608: =back
3609:
3610: =back
3611:
1.80 albertel 3612: =cut
3613:
3614: #-------------------------------------------
3615: sub get_kerberos_defaults {
3616: my $domain=shift;
1.641 raeburn 3617: my ($krbdef,$krbdefdom);
3618: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3619: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3620: $krbdef = $domdefaults{'auth_def'};
3621: $krbdefdom = $domdefaults{'auth_arg_def'};
3622: } else {
1.80 albertel 3623: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3624: my $krbdefdom=$1;
3625: $krbdefdom=~tr/a-z/A-Z/;
3626: $krbdef = "krb4";
3627: }
3628: return ($krbdef,$krbdefdom);
3629: }
1.112 bowersj2 3630:
1.32 matthew 3631:
1.46 matthew 3632: ###############################################################
3633: ## Thesaurus Functions ##
3634: ###############################################################
1.20 www 3635:
1.46 matthew 3636: =pod
1.20 www 3637:
1.112 bowersj2 3638: =head1 Thesaurus Functions
3639:
3640: =over 4
3641:
1.648 raeburn 3642: =item * &initialize_keywords()
1.46 matthew 3643:
3644: Initializes the package variable %Keywords if it is empty. Uses the
3645: package variable $thesaurus_db_file.
3646:
3647: =cut
3648:
3649: ###################################################
3650:
3651: sub initialize_keywords {
3652: return 1 if (scalar keys(%Keywords));
3653: # If we are here, %Keywords is empty, so fill it up
3654: # Make sure the file we need exists...
3655: if (! -e $thesaurus_db_file) {
3656: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3657: " failed because it does not exist");
3658: return 0;
3659: }
3660: # Set up the hash as a database
3661: my %thesaurus_db;
3662: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3663: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3664: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3665: $thesaurus_db_file);
3666: return 0;
3667: }
3668: # Get the average number of appearances of a word.
3669: my $avecount = $thesaurus_db{'average.count'};
3670: # Put keywords (those that appear > average) into %Keywords
3671: while (my ($word,$data)=each (%thesaurus_db)) {
3672: my ($count,undef) = split /:/,$data;
3673: $Keywords{$word}++ if ($count > $avecount);
3674: }
3675: untie %thesaurus_db;
3676: # Remove special values from %Keywords.
1.356 albertel 3677: foreach my $value ('total.count','average.count') {
3678: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3679: }
1.46 matthew 3680: return 1;
3681: }
3682:
3683: ###################################################
3684:
3685: =pod
3686:
1.648 raeburn 3687: =item * &keyword($word)
1.46 matthew 3688:
3689: Returns true if $word is a keyword. A keyword is a word that appears more
3690: than the average number of times in the thesaurus database. Calls
3691: &initialize_keywords
3692:
3693: =cut
3694:
3695: ###################################################
1.20 www 3696:
3697: sub keyword {
1.46 matthew 3698: return if (!&initialize_keywords());
3699: my $word=lc(shift());
3700: $word=~s/\W//g;
3701: return exists($Keywords{$word});
1.20 www 3702: }
1.46 matthew 3703:
3704: ###############################################################
3705:
3706: =pod
1.20 www 3707:
1.648 raeburn 3708: =item * &get_related_words()
1.46 matthew 3709:
1.160 matthew 3710: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3711: an array of words. If the keyword is not in the thesaurus, an empty array
3712: will be returned. The order of the words returned is determined by the
3713: database which holds them.
3714:
3715: Uses global $thesaurus_db_file.
3716:
1.1057 foxr 3717:
1.46 matthew 3718: =cut
3719:
3720: ###############################################################
3721: sub get_related_words {
3722: my $keyword = shift;
3723: my %thesaurus_db;
3724: if (! -e $thesaurus_db_file) {
3725: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3726: "failed because the file does not exist");
3727: return ();
3728: }
3729: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3730: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3731: return ();
3732: }
3733: my @Words=();
1.429 www 3734: my $count=0;
1.46 matthew 3735: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3736: # The first element is the number of times
3737: # the word appears. We do not need it now.
1.429 www 3738: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3739: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3740: my $threshold=$mostfrequentcount/10;
3741: foreach my $possibleword (@RelatedWords) {
3742: my ($word,$wordcount)=split(/\,/,$possibleword);
3743: if ($wordcount>$threshold) {
3744: push(@Words,$word);
3745: $count++;
3746: if ($count>10) { last; }
3747: }
1.20 www 3748: }
3749: }
1.46 matthew 3750: untie %thesaurus_db;
3751: return @Words;
1.14 harris41 3752: }
1.46 matthew 3753:
1.112 bowersj2 3754: =pod
3755:
3756: =back
3757:
3758: =cut
1.61 www 3759:
3760: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3761: =pod
3762:
1.112 bowersj2 3763: =head1 User Name Functions
3764:
3765: =over 4
3766:
1.648 raeburn 3767: =item * &plainname($uname,$udom,$first)
1.81 albertel 3768:
1.112 bowersj2 3769: Takes a users logon name and returns it as a string in
1.226 albertel 3770: "first middle last generation" form
3771: if $first is set to 'lastname' then it returns it as
3772: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3773:
3774: =cut
1.61 www 3775:
1.295 www 3776:
1.81 albertel 3777: ###############################################################
1.61 www 3778: sub plainname {
1.226 albertel 3779: my ($uname,$udom,$first)=@_;
1.537 albertel 3780: return if (!defined($uname) || !defined($udom));
1.295 www 3781: my %names=&getnames($uname,$udom);
1.226 albertel 3782: my $name=&Apache::lonnet::format_name($names{'firstname'},
3783: $names{'middlename'},
3784: $names{'lastname'},
3785: $names{'generation'},$first);
3786: $name=~s/^\s+//;
1.62 www 3787: $name=~s/\s+$//;
3788: $name=~s/\s+/ /g;
1.353 albertel 3789: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3790: return $name;
1.61 www 3791: }
1.66 www 3792:
3793: # -------------------------------------------------------------------- Nickname
1.81 albertel 3794: =pod
3795:
1.648 raeburn 3796: =item * &nickname($uname,$udom)
1.81 albertel 3797:
3798: Gets a users name and returns it as a string as
3799:
3800: ""nickname""
1.66 www 3801:
1.81 albertel 3802: if the user has a nickname or
3803:
3804: "first middle last generation"
3805:
3806: if the user does not
3807:
3808: =cut
1.66 www 3809:
3810: sub nickname {
3811: my ($uname,$udom)=@_;
1.537 albertel 3812: return if (!defined($uname) || !defined($udom));
1.295 www 3813: my %names=&getnames($uname,$udom);
1.68 albertel 3814: my $name=$names{'nickname'};
1.66 www 3815: if ($name) {
3816: $name='"'.$name.'"';
3817: } else {
3818: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3819: $names{'lastname'}.' '.$names{'generation'};
3820: $name=~s/\s+$//;
3821: $name=~s/\s+/ /g;
3822: }
3823: return $name;
3824: }
3825:
1.295 www 3826: sub getnames {
3827: my ($uname,$udom)=@_;
1.537 albertel 3828: return if (!defined($uname) || !defined($udom));
1.433 albertel 3829: if ($udom eq 'public' && $uname eq 'public') {
3830: return ('lastname' => &mt('Public'));
3831: }
1.295 www 3832: my $id=$uname.':'.$udom;
3833: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3834: if ($cached) {
3835: return %{$names};
3836: } else {
3837: my %loadnames=&Apache::lonnet::get('environment',
3838: ['firstname','middlename','lastname','generation','nickname'],
3839: $udom,$uname);
3840: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3841: return %loadnames;
3842: }
3843: }
1.61 www 3844:
1.542 raeburn 3845: # -------------------------------------------------------------------- getemails
1.648 raeburn 3846:
1.542 raeburn 3847: =pod
3848:
1.648 raeburn 3849: =item * &getemails($uname,$udom)
1.542 raeburn 3850:
3851: Gets a user's email information and returns it as a hash with keys:
3852: notification, critnotification, permanentemail
3853:
3854: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3855: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3856:
1.648 raeburn 3857:
1.542 raeburn 3858: =cut
3859:
1.648 raeburn 3860:
1.466 albertel 3861: sub getemails {
3862: my ($uname,$udom)=@_;
3863: if ($udom eq 'public' && $uname eq 'public') {
3864: return;
3865: }
1.467 www 3866: if (!$udom) { $udom=$env{'user.domain'}; }
3867: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3868: my $id=$uname.':'.$udom;
3869: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3870: if ($cached) {
3871: return %{$names};
3872: } else {
3873: my %loadnames=&Apache::lonnet::get('environment',
3874: ['notification','critnotification',
3875: 'permanentemail'],
3876: $udom,$uname);
3877: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3878: return %loadnames;
3879: }
3880: }
3881:
1.551 albertel 3882: sub flush_email_cache {
3883: my ($uname,$udom)=@_;
3884: if (!$udom) { $udom =$env{'user.domain'}; }
3885: if (!$uname) { $uname=$env{'user.name'}; }
3886: return if ($udom eq 'public' && $uname eq 'public');
3887: my $id=$uname.':'.$udom;
3888: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3889: }
3890:
1.728 raeburn 3891: # -------------------------------------------------------------------- getlangs
3892:
3893: =pod
3894:
3895: =item * &getlangs($uname,$udom)
3896:
3897: Gets a user's language preference and returns it as a hash with key:
3898: language.
3899:
3900: =cut
3901:
3902:
3903: sub getlangs {
3904: my ($uname,$udom) = @_;
3905: if (!$udom) { $udom =$env{'user.domain'}; }
3906: if (!$uname) { $uname=$env{'user.name'}; }
3907: my $id=$uname.':'.$udom;
3908: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3909: if ($cached) {
3910: return %{$langs};
3911: } else {
3912: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3913: $udom,$uname);
3914: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3915: return %loadlangs;
3916: }
3917: }
3918:
3919: sub flush_langs_cache {
3920: my ($uname,$udom)=@_;
3921: if (!$udom) { $udom =$env{'user.domain'}; }
3922: if (!$uname) { $uname=$env{'user.name'}; }
3923: return if ($udom eq 'public' && $uname eq 'public');
3924: my $id=$uname.':'.$udom;
3925: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3926: }
3927:
1.61 www 3928: # ------------------------------------------------------------------ Screenname
1.81 albertel 3929:
3930: =pod
3931:
1.648 raeburn 3932: =item * &screenname($uname,$udom)
1.81 albertel 3933:
3934: Gets a users screenname and returns it as a string
3935:
3936: =cut
1.61 www 3937:
3938: sub screenname {
3939: my ($uname,$udom)=@_;
1.258 albertel 3940: if ($uname eq $env{'user.name'} &&
3941: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3942: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3943: return $names{'screenname'};
1.62 www 3944: }
3945:
1.212 albertel 3946:
1.802 bisitz 3947: # ------------------------------------------------------------- Confirm Wrapper
3948: =pod
3949:
1.1075.2.42 raeburn 3950: =item * &confirmwrapper($message)
1.802 bisitz 3951:
3952: Wrap messages about completion of operation in box
3953:
3954: =cut
3955:
3956: sub confirmwrapper {
3957: my ($message)=@_;
3958: if ($message) {
3959: return "\n".'<div class="LC_confirm_box">'."\n"
3960: .$message."\n"
3961: .'</div>'."\n";
3962: } else {
3963: return $message;
3964: }
3965: }
3966:
1.62 www 3967: # ------------------------------------------------------------- Message Wrapper
3968:
3969: sub messagewrapper {
1.369 www 3970: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3971: return
1.441 albertel 3972: '<a href="/adm/email?compose=individual&'.
3973: 'recname='.$username.'&recdom='.$domain.
3974: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3975: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3976: }
1.802 bisitz 3977:
1.74 www 3978: # --------------------------------------------------------------- Notes Wrapper
3979:
3980: sub noteswrapper {
3981: my ($link,$un,$do)=@_;
3982: return
1.896 amueller 3983: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3984: }
1.802 bisitz 3985:
1.62 www 3986: # ------------------------------------------------------------- Aboutme Wrapper
3987:
3988: sub aboutmewrapper {
1.1070 raeburn 3989: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3990: if (!defined($username) && !defined($domain)) {
3991: return;
3992: }
1.1075.2.15 raeburn 3993: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3994: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3995: }
3996:
3997: # ------------------------------------------------------------ Syllabus Wrapper
3998:
3999: sub syllabuswrapper {
1.707 bisitz 4000: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4001: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4002: }
1.14 harris41 4003:
1.1075.2.161. .11(raeb 4004:-22): sub aboutme_on {
4005:-22): my ($uname,$udom)=@_;
4006:-22): unless ($uname) { $uname=$env{'user.name'}; }
4007:-22): unless ($udom) { $udom=$env{'user.domain'}; }
4008:-22): return if ($udom eq 'public' && $uname eq 'public');
4009:-22): my $hashkey=$uname.':'.$udom;
4010:-22): my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4011:-22): if ($cached) {
4012:-22): return $aboutme;
4013:-22): }
4014:-22): $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4015:-22): &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4016:-22): return $aboutme;
4017:-22): }
4018:-22):
4019:-22): sub devalidate_aboutme_cache {
4020:-22): my ($uname,$udom)=@_;
4021:-22): if (!$udom) { $udom =$env{'user.domain'}; }
4022:-22): if (!$uname) { $uname=$env{'user.name'}; }
4023:-22): return if ($udom eq 'public' && $uname eq 'public');
4024:-22): my $id=$uname.':'.$udom;
4025:-22): &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4026:-22): }
4027:-22):
1.802 bisitz 4028: # -----------------------------------------------------------------------------
4029:
1.208 matthew 4030: sub track_student_link {
1.887 raeburn 4031: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4032: my $link ="/adm/trackstudent?";
1.208 matthew 4033: my $title = 'View recent activity';
4034: if (defined($sname) && $sname !~ /^\s*$/ &&
4035: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4036: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4037: $title .= ' of this student';
1.268 albertel 4038: }
1.208 matthew 4039: if (defined($target) && $target !~ /^\s*$/) {
4040: $target = qq{target="$target"};
4041: } else {
4042: $target = '';
4043: }
1.268 albertel 4044: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4045: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4046: $title = &mt($title);
4047: $linktext = &mt($linktext);
1.448 albertel 4048: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4049: &help_open_topic('View_recent_activity');
1.208 matthew 4050: }
4051:
1.781 raeburn 4052: sub slot_reservations_link {
4053: my ($linktext,$sname,$sdom,$target) = @_;
4054: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4055: my $title = 'View slot reservation history';
4056: if (defined($sname) && $sname !~ /^\s*$/ &&
4057: defined($sdom) && $sdom !~ /^\s*$/) {
4058: $link .= "&uname=$sname&udom=$sdom";
4059: $title .= ' of this student';
4060: }
4061: if (defined($target) && $target !~ /^\s*$/) {
4062: $target = qq{target="$target"};
4063: } else {
4064: $target = '';
4065: }
4066: $title = &mt($title);
4067: $linktext = &mt($linktext);
4068: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4069: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4070:
4071: }
4072:
1.508 www 4073: # ===================================================== Display a student photo
4074:
4075:
1.509 albertel 4076: sub student_image_tag {
1.508 www 4077: my ($domain,$user)=@_;
4078: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4079: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4080: return '<img src="'.$imgsrc.'" align="right" />';
4081: } else {
4082: return '';
4083: }
4084: }
4085:
1.112 bowersj2 4086: =pod
4087:
4088: =back
4089:
4090: =head1 Access .tab File Data
4091:
4092: =over 4
4093:
1.648 raeburn 4094: =item * &languageids()
1.112 bowersj2 4095:
4096: returns list of all language ids
4097:
4098: =cut
4099:
1.14 harris41 4100: sub languageids {
1.16 harris41 4101: return sort(keys(%language));
1.14 harris41 4102: }
4103:
1.112 bowersj2 4104: =pod
4105:
1.648 raeburn 4106: =item * &languagedescription()
1.112 bowersj2 4107:
4108: returns description of a specified language id
4109:
4110: =cut
4111:
1.14 harris41 4112: sub languagedescription {
1.125 www 4113: my $code=shift;
4114: return ($supported_language{$code}?'* ':'').
4115: $language{$code}.
1.126 www 4116: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4117: }
4118:
1.1048 foxr 4119: =pod
4120:
4121: =item * &plainlanguagedescription
4122:
4123: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4124: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4125:
4126: =cut
4127:
1.145 www 4128: sub plainlanguagedescription {
4129: my $code=shift;
4130: return $language{$code};
4131: }
4132:
1.1048 foxr 4133: =pod
4134:
4135: =item * &supportedlanguagecode
4136:
4137: Returns the supported language code (e.g. sptutf maps to pt) given a language
4138: code.
4139:
4140: =cut
4141:
1.145 www 4142: sub supportedlanguagecode {
4143: my $code=shift;
4144: return $supported_language{$code};
1.97 www 4145: }
4146:
1.112 bowersj2 4147: =pod
4148:
1.1048 foxr 4149: =item * &latexlanguage()
4150:
4151: Given a language key code returns the correspondnig language to use
4152: to select the correct hyphenation on LaTeX printouts. This is undef if there
4153: is no supported hyphenation for the language code.
4154:
4155: =cut
4156:
4157: sub latexlanguage {
4158: my $code = shift;
4159: return $latex_language{$code};
4160: }
4161:
4162: =pod
4163:
4164: =item * &latexhyphenation()
4165:
4166: Same as above but what's supplied is the language as it might be stored
4167: in the metadata.
4168:
4169: =cut
4170:
4171: sub latexhyphenation {
4172: my $key = shift;
4173: return $latex_language_bykey{$key};
4174: }
4175:
4176: =pod
4177:
1.648 raeburn 4178: =item * ©rightids()
1.112 bowersj2 4179:
4180: returns list of all copyrights
4181:
4182: =cut
4183:
4184: sub copyrightids {
4185: return sort(keys(%cprtag));
4186: }
4187:
4188: =pod
4189:
1.648 raeburn 4190: =item * ©rightdescription()
1.112 bowersj2 4191:
4192: returns description of a specified copyright id
4193:
4194: =cut
4195:
4196: sub copyrightdescription {
1.166 www 4197: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4198: }
1.197 matthew 4199:
4200: =pod
4201:
1.648 raeburn 4202: =item * &source_copyrightids()
1.192 taceyjo1 4203:
4204: returns list of all source copyrights
4205:
4206: =cut
4207:
4208: sub source_copyrightids {
4209: return sort(keys(%scprtag));
4210: }
4211:
4212: =pod
4213:
1.648 raeburn 4214: =item * &source_copyrightdescription()
1.192 taceyjo1 4215:
4216: returns description of a specified source copyright id
4217:
4218: =cut
4219:
4220: sub source_copyrightdescription {
4221: return &mt($scprtag{shift(@_)});
4222: }
1.112 bowersj2 4223:
4224: =pod
4225:
1.648 raeburn 4226: =item * &filecategories()
1.112 bowersj2 4227:
4228: returns list of all file categories
4229:
4230: =cut
4231:
4232: sub filecategories {
4233: return sort(keys(%category_extensions));
4234: }
4235:
4236: =pod
4237:
1.648 raeburn 4238: =item * &filecategorytypes()
1.112 bowersj2 4239:
4240: returns list of file types belonging to a given file
4241: category
4242:
4243: =cut
4244:
4245: sub filecategorytypes {
1.356 albertel 4246: my ($cat) = @_;
4247: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 4248: }
4249:
4250: =pod
4251:
1.648 raeburn 4252: =item * &fileembstyle()
1.112 bowersj2 4253:
4254: returns embedding style for a specified file type
4255:
4256: =cut
4257:
4258: sub fileembstyle {
4259: return $fe{lc(shift(@_))};
1.169 www 4260: }
4261:
1.351 www 4262: sub filemimetype {
4263: return $fm{lc(shift(@_))};
4264: }
4265:
1.169 www 4266:
4267: sub filecategoryselect {
4268: my ($name,$value)=@_;
1.189 matthew 4269: return &select_form($value,$name,
1.970 raeburn 4270: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4271: }
4272:
4273: =pod
4274:
1.648 raeburn 4275: =item * &filedescription()
1.112 bowersj2 4276:
4277: returns description for a specified file type
4278:
4279: =cut
4280:
4281: sub filedescription {
1.188 matthew 4282: my $file_description = $fd{lc(shift())};
4283: $file_description =~ s:([\[\]]):~$1:g;
4284: return &mt($file_description);
1.112 bowersj2 4285: }
4286:
4287: =pod
4288:
1.648 raeburn 4289: =item * &filedescriptionex()
1.112 bowersj2 4290:
4291: returns description for a specified file type with
4292: extra formatting
4293:
4294: =cut
4295:
4296: sub filedescriptionex {
4297: my $ex=shift;
1.188 matthew 4298: my $file_description = $fd{lc($ex)};
4299: $file_description =~ s:([\[\]]):~$1:g;
4300: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4301: }
4302:
4303: # End of .tab access
4304: =pod
4305:
4306: =back
4307:
4308: =cut
4309:
4310: # ------------------------------------------------------------------ File Types
4311: sub fileextensions {
4312: return sort(keys(%fe));
4313: }
4314:
1.97 www 4315: # ----------------------------------------------------------- Display Languages
4316: # returns a hash with all desired display languages
4317: #
4318:
4319: sub display_languages {
4320: my %languages=();
1.695 raeburn 4321: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4322: $languages{$lang}=1;
1.97 www 4323: }
4324: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4325: if ($env{'form.displaylanguage'}) {
1.356 albertel 4326: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4327: $languages{$lang}=1;
1.97 www 4328: }
4329: }
4330: return %languages;
1.14 harris41 4331: }
4332:
1.582 albertel 4333: sub languages {
4334: my ($possible_langs) = @_;
1.695 raeburn 4335: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4336: if (!ref($possible_langs)) {
4337: if( wantarray ) {
4338: return @preferred_langs;
4339: } else {
4340: return $preferred_langs[0];
4341: }
4342: }
4343: my %possibilities = map { $_ => 1 } (@$possible_langs);
4344: my @preferred_possibilities;
4345: foreach my $preferred_lang (@preferred_langs) {
4346: if (exists($possibilities{$preferred_lang})) {
4347: push(@preferred_possibilities, $preferred_lang);
4348: }
4349: }
4350: if( wantarray ) {
4351: return @preferred_possibilities;
4352: }
4353: return $preferred_possibilities[0];
4354: }
4355:
1.742 raeburn 4356: sub user_lang {
4357: my ($touname,$toudom,$fromcid) = @_;
4358: my @userlangs;
4359: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4360: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4361: $env{'course.'.$fromcid.'.languages'}));
4362: } else {
4363: my %langhash = &getlangs($touname,$toudom);
4364: if ($langhash{'languages'} ne '') {
4365: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4366: } else {
4367: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4368: if ($domdefs{'lang_def'} ne '') {
4369: @userlangs = ($domdefs{'lang_def'});
4370: }
4371: }
4372: }
4373: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4374: my $user_lh = Apache::localize->get_handle(@languages);
4375: return $user_lh;
4376: }
4377:
4378:
1.112 bowersj2 4379: ###############################################################
4380: ## Student Answer Attempts ##
4381: ###############################################################
4382:
4383: =pod
4384:
4385: =head1 Alternate Problem Views
4386:
4387: =over 4
4388:
1.648 raeburn 4389: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4390: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4391:
4392: Return string with previous attempt on problem. Arguments:
4393:
4394: =over 4
4395:
4396: =item * $symb: Problem, including path
4397:
4398: =item * $username: username of the desired student
4399:
4400: =item * $domain: domain of the desired student
1.14 harris41 4401:
1.112 bowersj2 4402: =item * $course: Course ID
1.14 harris41 4403:
1.112 bowersj2 4404: =item * $getattempt: Leave blank for all attempts, otherwise put
4405: something
1.14 harris41 4406:
1.112 bowersj2 4407: =item * $regexp: if string matches this regexp, the string will be
4408: sent to $gradesub
1.14 harris41 4409:
1.112 bowersj2 4410: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4411:
1.1075.2.86 raeburn 4412: =item * $usec: section of the desired student
4413:
4414: =item * $identifier: counter for student (multiple students one problem) or
4415: problem (one student; whole sequence).
4416:
1.112 bowersj2 4417: =back
1.14 harris41 4418:
1.112 bowersj2 4419: The output string is a table containing all desired attempts, if any.
1.16 harris41 4420:
1.112 bowersj2 4421: =cut
1.1 albertel 4422:
4423: sub get_previous_attempt {
1.1075.2.86 raeburn 4424: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4425: my $prevattempts='';
1.43 ng 4426: no strict 'refs';
1.1 albertel 4427: if ($symb) {
1.3 albertel 4428: my (%returnhash)=
4429: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4430: if ($returnhash{'version'}) {
4431: my %lasthash=();
4432: my $version;
4433: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4434: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4435: if ($key =~ /\.rawrndseed$/) {
4436: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4437: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4438: } else {
4439: $lasthash{$key}=$returnhash{$version.':'.$key};
4440: }
1.19 harris41 4441: }
1.1 albertel 4442: }
1.596 albertel 4443: $prevattempts=&start_data_table().&start_data_table_header_row();
4444: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4445: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4446: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4447: foreach my $key (sort(keys(%lasthash))) {
4448: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4449: if ($#parts > 0) {
1.31 albertel 4450: my $data=$parts[-1];
1.989 raeburn 4451: next if ($data eq 'foilorder');
1.31 albertel 4452: pop(@parts);
1.1010 www 4453: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4454: if ($data eq 'type') {
4455: unless ($showsurv) {
4456: my $id = join(',',@parts);
4457: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4458: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4459: $lasthidden{$ign.'.'.$id} = 1;
4460: }
1.945 raeburn 4461: }
1.1075.2.86 raeburn 4462: if ($identifier ne '') {
4463: my $id = join(',',@parts);
4464: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4465: $domain,$username,$usec,undef,$course) =~ /^no/) {
4466: $hidestatus{$ign.'.'.$id} = 1;
4467: }
4468: }
4469: } elsif ($data eq 'regrader') {
4470: if (($identifier ne '') && (@parts)) {
4471: my $id = join(',',@parts);
4472: $regraded{$ign.'.'.$id} = 1;
4473: }
1.1010 www 4474: }
1.31 albertel 4475: } else {
1.41 ng 4476: if ($#parts == 0) {
4477: $prevattempts.='<th>'.$parts[0].'</th>';
4478: } else {
4479: $prevattempts.='<th>'.$ign.'</th>';
4480: }
1.31 albertel 4481: }
1.16 harris41 4482: }
1.596 albertel 4483: $prevattempts.=&end_data_table_header_row();
1.40 ng 4484: if ($getattempt eq '') {
1.1075.2.86 raeburn 4485: my (%solved,%resets,%probstatus);
4486: if (($identifier ne '') && (keys(%regraded) > 0)) {
4487: for ($version=1;$version<=$returnhash{'version'};$version++) {
4488: foreach my $id (keys(%regraded)) {
4489: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4490: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4491: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4492: push(@{$resets{$id}},$version);
4493: }
4494: }
4495: }
4496: }
1.40 ng 4497: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4498: my (@hidden,@unsolved);
1.945 raeburn 4499: if (%typeparts) {
4500: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4501: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4502: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4503: push(@hidden,$id);
1.1075.2.86 raeburn 4504: } elsif ($identifier ne '') {
4505: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4506: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4507: ($hidestatus{$id})) {
4508: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4509: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4510: push(@{$solved{$id}},$version);
4511: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4512: (ref($solved{$id}) eq 'ARRAY')) {
4513: my $skip;
4514: if (ref($resets{$id}) eq 'ARRAY') {
4515: foreach my $reset (@{$resets{$id}}) {
4516: if ($reset > $solved{$id}[-1]) {
4517: $skip=1;
4518: last;
4519: }
4520: }
4521: }
4522: unless ($skip) {
4523: my ($ign,$partslist) = split(/\./,$id,2);
4524: push(@unsolved,$partslist);
4525: }
4526: }
4527: }
1.945 raeburn 4528: }
4529: }
4530: }
4531: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4532: '<td>'.&mt('Transaction [_1]',$version);
4533: if (@unsolved) {
4534: $prevattempts .= '<span class="LC_nobreak"><label>'.
4535: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4536: &mt('Hide').'</label></span>';
4537: }
4538: $prevattempts .= '</td>';
1.945 raeburn 4539: if (@hidden) {
4540: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4541: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4542: my $hide;
4543: foreach my $id (@hidden) {
4544: if ($key =~ /^\Q$id\E/) {
4545: $hide = 1;
4546: last;
4547: }
4548: }
4549: if ($hide) {
4550: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4551: if (($data eq 'award') || ($data eq 'awarddetail')) {
4552: my $value = &format_previous_attempt_value($key,
4553: $returnhash{$version.':'.$key});
4554: $prevattempts.='<td>'.$value.' </td>';
4555: } else {
4556: $prevattempts.='<td> </td>';
4557: }
4558: } else {
4559: if ($key =~ /\./) {
1.1075.2.91 raeburn 4560: my $value = $returnhash{$version.':'.$key};
4561: if ($key =~ /\.rndseed$/) {
4562: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4563: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4564: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4565: }
4566: }
4567: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4568: ' </td>';
1.945 raeburn 4569: } else {
4570: $prevattempts.='<td> </td>';
4571: }
4572: }
4573: }
4574: } else {
4575: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4576: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4577: my $value = $returnhash{$version.':'.$key};
4578: if ($key =~ /\.rndseed$/) {
4579: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4580: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4581: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4582: }
4583: }
4584: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4585: ' </td>';
1.945 raeburn 4586: }
4587: }
4588: $prevattempts.=&end_data_table_row();
1.40 ng 4589: }
1.1 albertel 4590: }
1.945 raeburn 4591: my @currhidden = keys(%lasthidden);
1.596 albertel 4592: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4593: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4594: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4595: if (%typeparts) {
4596: my $hidden;
4597: foreach my $id (@currhidden) {
4598: if ($key =~ /^\Q$id\E/) {
4599: $hidden = 1;
4600: last;
4601: }
4602: }
4603: if ($hidden) {
4604: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4605: if (($data eq 'award') || ($data eq 'awarddetail')) {
4606: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4607: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4608: $value = &$gradesub($value);
4609: }
4610: $prevattempts.='<td>'.$value.' </td>';
4611: } else {
4612: $prevattempts.='<td> </td>';
4613: }
4614: } else {
4615: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4616: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4617: $value = &$gradesub($value);
4618: }
4619: $prevattempts.='<td>'.$value.' </td>';
4620: }
4621: } else {
4622: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4623: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4624: $value = &$gradesub($value);
4625: }
4626: $prevattempts.='<td>'.$value.' </td>';
4627: }
1.16 harris41 4628: }
1.596 albertel 4629: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4630: } else {
1.1075.2.161. .17(raeb 4631:-23): my $msg;
4632:-23): if ($symb =~ /ext\.tool$/) {
4633:-23): $msg = &mt('No grade passed back.');
4634:-23): } else {
4635:-23): $msg = &mt('Nothing submitted - no attempts.');
4636:-23): }
1.596 albertel 4637: $prevattempts=
4638: &start_data_table().&start_data_table_row().
1.1075.2.161. .17(raeb 4639:-23): '<td>'.$msg.'</td>'.
1.596 albertel 4640: &end_data_table_row().&end_data_table();
1.1 albertel 4641: }
4642: } else {
1.596 albertel 4643: $prevattempts=
4644: &start_data_table().&start_data_table_row().
4645: '<td>'.&mt('No data.').'</td>'.
4646: &end_data_table_row().&end_data_table();
1.1 albertel 4647: }
1.10 albertel 4648: }
4649:
1.581 albertel 4650: sub format_previous_attempt_value {
4651: my ($key,$value) = @_;
1.1011 www 4652: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4653: $value = &Apache::lonlocal::locallocaltime($value);
4654: } elsif (ref($value) eq 'ARRAY') {
4655: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4656: } elsif ($key =~ /answerstring$/) {
4657: my %answers = &Apache::lonnet::str2hash($value);
4658: my @anskeys = sort(keys(%answers));
4659: if (@anskeys == 1) {
4660: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4661: if ($answer =~ m{\0}) {
4662: $answer =~ s{\0}{,}g;
1.988 raeburn 4663: }
4664: my $tag_internal_answer_name = 'INTERNAL';
4665: if ($anskeys[0] eq $tag_internal_answer_name) {
4666: $value = $answer;
4667: } else {
4668: $value = $anskeys[0].'='.$answer;
4669: }
4670: } else {
4671: foreach my $ans (@anskeys) {
4672: my $answer = $answers{$ans};
1.1001 raeburn 4673: if ($answer =~ m{\0}) {
4674: $answer =~ s{\0}{,}g;
1.988 raeburn 4675: }
4676: $value .= $ans.'='.$answer.'<br />';;
4677: }
4678: }
1.581 albertel 4679: } else {
4680: $value = &unescape($value);
4681: }
4682: return $value;
4683: }
4684:
4685:
1.107 albertel 4686: sub relative_to_absolute {
4687: my ($url,$output)=@_;
4688: my $parser=HTML::TokeParser->new(\$output);
4689: my $token;
4690: my $thisdir=$url;
4691: my @rlinks=();
4692: while ($token=$parser->get_token) {
4693: if ($token->[0] eq 'S') {
4694: if ($token->[1] eq 'a') {
4695: if ($token->[2]->{'href'}) {
4696: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4697: }
4698: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4699: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4700: } elsif ($token->[1] eq 'base') {
4701: $thisdir=$token->[2]->{'href'};
4702: }
4703: }
4704: }
4705: $thisdir=~s-/[^/]*$--;
1.356 albertel 4706: foreach my $link (@rlinks) {
1.726 raeburn 4707: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4708: ($link=~/^\//) ||
4709: ($link=~/^javascript:/i) ||
4710: ($link=~/^mailto:/i) ||
4711: ($link=~/^\#/)) {
4712: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4713: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4714: }
4715: }
4716: # -------------------------------------------------- Deal with Applet codebases
4717: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4718: return $output;
4719: }
4720:
1.112 bowersj2 4721: =pod
4722:
1.648 raeburn 4723: =item * &get_student_view()
1.112 bowersj2 4724:
4725: show a snapshot of what student was looking at
4726:
4727: =cut
4728:
1.10 albertel 4729: sub get_student_view {
1.186 albertel 4730: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4731: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4732: my (%form);
1.10 albertel 4733: my @elements=('symb','courseid','domain','username');
4734: foreach my $element (@elements) {
1.186 albertel 4735: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4736: }
1.186 albertel 4737: if (defined($moreenv)) {
4738: %form=(%form,%{$moreenv});
4739: }
1.236 albertel 4740: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4741: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4742: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4743: $userview=~s/\<body[^\>]*\>//gi;
4744: $userview=~s/\<\/body\>//gi;
4745: $userview=~s/\<html\>//gi;
4746: $userview=~s/\<\/html\>//gi;
4747: $userview=~s/\<head\>//gi;
4748: $userview=~s/\<\/head\>//gi;
4749: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4750: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4751: if (wantarray) {
4752: return ($userview,$response);
4753: } else {
4754: return $userview;
4755: }
4756: }
4757:
4758: sub get_student_view_with_retries {
4759: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4760:
4761: my $ok = 0; # True if we got a good response.
4762: my $content;
4763: my $response;
4764:
4765: # Try to get the student_view done. within the retries count:
4766:
4767: do {
4768: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4769: $ok = $response->is_success;
4770: if (!$ok) {
4771: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4772: }
4773: $retries--;
4774: } while (!$ok && ($retries > 0));
4775:
4776: if (!$ok) {
4777: $content = ''; # On error return an empty content.
4778: }
1.651 www 4779: if (wantarray) {
4780: return ($content, $response);
4781: } else {
4782: return $content;
4783: }
1.11 albertel 4784: }
4785:
1.1075.2.149 raeburn 4786: sub css_links {
4787: my ($currsymb,$level) = @_;
4788: my ($links,@symbs,%cssrefs,%httpref);
4789: if ($level eq 'map') {
4790: my $navmap = Apache::lonnavmaps::navmap->new();
4791: if (ref($navmap)) {
4792: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4793: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4794: foreach my $res (@resources) {
4795: if (ref($res) && $res->symb()) {
4796: push(@symbs,$res->symb());
4797: }
4798: }
4799: }
4800: } else {
4801: @symbs = ($currsymb);
4802: }
4803: foreach my $symb (@symbs) {
4804: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4805: if ($css_href =~ /\S/) {
4806: unless ($css_href =~ m{https?://}) {
4807: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4808: my $proburl = &Apache::lonnet::clutter($url);
4809: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4810: unless ($css_href =~ m{^/}) {
4811: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4812: }
4813: if ($css_href =~ m{^/(res|uploaded)/}) {
4814: unless (($httpref{'httpref.'.$css_href}) ||
4815: (&Apache::lonnet::is_on_map($css_href))) {
4816: my $thisurl = $proburl;
4817: if ($env{'httpref.'.$proburl}) {
4818: $thisurl = $env{'httpref.'.$proburl};
4819: }
4820: $httpref{'httpref.'.$css_href} = $thisurl;
4821: }
4822: }
4823: }
4824: $cssrefs{$css_href} = 1;
4825: }
4826: }
4827: if (keys(%httpref)) {
4828: &Apache::lonnet::appenv(\%httpref);
4829: }
4830: if (keys(%cssrefs)) {
4831: foreach my $css_href (keys(%cssrefs)) {
4832: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4833: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4834: }
4835: }
4836: return $links;
4837: }
4838:
1.112 bowersj2 4839: =pod
4840:
1.648 raeburn 4841: =item * &get_student_answers()
1.112 bowersj2 4842:
4843: show a snapshot of how student was answering problem
4844:
4845: =cut
4846:
1.11 albertel 4847: sub get_student_answers {
1.100 sakharuk 4848: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4849: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4850: my (%moreenv);
1.11 albertel 4851: my @elements=('symb','courseid','domain','username');
4852: foreach my $element (@elements) {
1.186 albertel 4853: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4854: }
1.186 albertel 4855: $moreenv{'grade_target'}='answer';
4856: %moreenv=(%form,%moreenv);
1.497 raeburn 4857: $feedurl = &Apache::lonnet::clutter($feedurl);
4858: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4859: return $userview;
1.1 albertel 4860: }
1.116 albertel 4861:
4862: =pod
4863:
4864: =item * &submlink()
4865:
1.242 albertel 4866: Inputs: $text $uname $udom $symb $target
1.116 albertel 4867:
4868: Returns: A link to grades.pm such as to see the SUBM view of a student
4869:
4870: =cut
4871:
4872: ###############################################
4873: sub submlink {
1.242 albertel 4874: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4875: if (!($uname && $udom)) {
4876: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4877: &Apache::lonnet::whichuser($symb);
1.116 albertel 4878: if (!$symb) { $symb=$cursymb; }
4879: }
1.254 matthew 4880: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4881: $symb=&escape($symb);
1.960 bisitz 4882: if ($target) { $target=" target=\"$target\""; }
4883: return
4884: '<a href="/adm/grades?command=submission'.
4885: '&symb='.$symb.
4886: '&student='.$uname.
4887: '&userdom='.$udom.'"'.
4888: $target.'>'.$text.'</a>';
1.242 albertel 4889: }
4890: ##############################################
4891:
4892: =pod
4893:
4894: =item * &pgrdlink()
4895:
4896: Inputs: $text $uname $udom $symb $target
4897:
4898: Returns: A link to grades.pm such as to see the PGRD view of a student
4899:
4900: =cut
4901:
4902: ###############################################
4903: sub pgrdlink {
4904: my $link=&submlink(@_);
4905: $link=~s/(&command=submission)/$1&showgrading=yes/;
4906: return $link;
4907: }
4908: ##############################################
4909:
4910: =pod
4911:
4912: =item * &pprmlink()
4913:
4914: Inputs: $text $uname $udom $symb $target
4915:
4916: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4917: student and a specific resource
1.242 albertel 4918:
4919: =cut
4920:
4921: ###############################################
4922: sub pprmlink {
4923: my ($text,$uname,$udom,$symb,$target)=@_;
4924: if (!($uname && $udom)) {
4925: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4926: &Apache::lonnet::whichuser($symb);
1.242 albertel 4927: if (!$symb) { $symb=$cursymb; }
4928: }
1.254 matthew 4929: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4930: $symb=&escape($symb);
1.242 albertel 4931: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4932: return '<a href="/adm/parmset?command=set&'.
4933: 'symb='.$symb.'&uname='.$uname.
4934: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4935: }
4936: ##############################################
1.37 matthew 4937:
1.112 bowersj2 4938: =pod
4939:
4940: =back
4941:
4942: =cut
4943:
1.37 matthew 4944: ###############################################
1.51 www 4945:
4946:
4947: sub timehash {
1.687 raeburn 4948: my ($thistime) = @_;
4949: my $timezone = &Apache::lonlocal::gettimezone();
4950: my $dt = DateTime->from_epoch(epoch => $thistime)
4951: ->set_time_zone($timezone);
4952: my $wday = $dt->day_of_week();
4953: if ($wday == 7) { $wday = 0; }
4954: return ( 'second' => $dt->second(),
4955: 'minute' => $dt->minute(),
4956: 'hour' => $dt->hour(),
4957: 'day' => $dt->day_of_month(),
4958: 'month' => $dt->month(),
4959: 'year' => $dt->year(),
4960: 'weekday' => $wday,
4961: 'dayyear' => $dt->day_of_year(),
4962: 'dlsav' => $dt->is_dst() );
1.51 www 4963: }
4964:
1.370 www 4965: sub utc_string {
4966: my ($date)=@_;
1.371 www 4967: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4968: }
4969:
1.51 www 4970: sub maketime {
4971: my %th=@_;
1.687 raeburn 4972: my ($epoch_time,$timezone,$dt);
4973: $timezone = &Apache::lonlocal::gettimezone();
4974: eval {
4975: $dt = DateTime->new( year => $th{'year'},
4976: month => $th{'month'},
4977: day => $th{'day'},
4978: hour => $th{'hour'},
4979: minute => $th{'minute'},
4980: second => $th{'second'},
4981: time_zone => $timezone,
4982: );
4983: };
4984: if (!$@) {
4985: $epoch_time = $dt->epoch;
4986: if ($epoch_time) {
4987: return $epoch_time;
4988: }
4989: }
1.51 www 4990: return POSIX::mktime(
4991: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4992: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4993: }
4994:
4995: #########################################
1.51 www 4996:
4997: sub findallcourses {
1.482 raeburn 4998: my ($roles,$uname,$udom) = @_;
1.355 albertel 4999: my %roles;
5000: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5001: my %courses;
1.51 www 5002: my $now=time;
1.482 raeburn 5003: if (!defined($uname)) {
5004: $uname = $env{'user.name'};
5005: }
5006: if (!defined($udom)) {
5007: $udom = $env{'user.domain'};
5008: }
5009: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5010: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5011: if (!%roles) {
5012: %roles = (
5013: cc => 1,
1.907 raeburn 5014: co => 1,
1.482 raeburn 5015: in => 1,
5016: ep => 1,
5017: ta => 1,
5018: cr => 1,
5019: st => 1,
5020: );
5021: }
5022: foreach my $entry (keys(%roleshash)) {
5023: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5024: if ($trole =~ /^cr/) {
5025: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5026: } else {
5027: next if (!exists($roles{$trole}));
5028: }
5029: if ($tend) {
5030: next if ($tend < $now);
5031: }
5032: if ($tstart) {
5033: next if ($tstart > $now);
5034: }
1.1058 raeburn 5035: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5036: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5037: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5038: if ($secpart eq '') {
5039: ($cnum,$role) = split(/_/,$cnumpart);
5040: $sec = 'none';
1.1058 raeburn 5041: $value .= $cnum.'/';
1.482 raeburn 5042: } else {
5043: $cnum = $cnumpart;
5044: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5045: $value .= $cnum.'/'.$sec;
5046: }
5047: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5048: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5049: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5050: }
5051: } else {
5052: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5053: }
1.482 raeburn 5054: }
5055: } else {
5056: foreach my $key (keys(%env)) {
1.483 albertel 5057: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5058: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5059: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5060: next if ($role eq 'ca' || $role eq 'aa');
5061: next if (%roles && !exists($roles{$role}));
5062: my ($starttime,$endtime)=split(/\./,$env{$key});
5063: my $active=1;
5064: if ($starttime) {
5065: if ($now<$starttime) { $active=0; }
5066: }
5067: if ($endtime) {
5068: if ($now>$endtime) { $active=0; }
5069: }
5070: if ($active) {
1.1058 raeburn 5071: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5072: if ($sec eq '') {
5073: $sec = 'none';
1.1058 raeburn 5074: } else {
5075: $value .= $sec;
5076: }
5077: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5078: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5079: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5080: }
5081: } else {
5082: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5083: }
1.474 raeburn 5084: }
5085: }
1.51 www 5086: }
5087: }
1.474 raeburn 5088: return %courses;
1.51 www 5089: }
1.37 matthew 5090:
1.54 www 5091: ###############################################
1.474 raeburn 5092:
5093: sub blockcheck {
1.1075.2.158 raeburn 5094: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 5095:
1.1075.2.161. .4(raebu 5096:22): unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
1.1075.2.158 raeburn 5097: my ($has_evb,$check_ipaccess);
5098: my $dom = $env{'user.domain'};
5099: if ($env{'request.course.id'}) {
5100: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5101: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5102: my $checkrole = "cm./$cdom/$cnum";
5103: my $sec = $env{'request.course.sec'};
5104: if ($sec ne '') {
5105: $checkrole .= "/$sec";
5106: }
5107: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5108: ($env{'request.role'} !~ /^st/)) {
5109: $has_evb = 1;
5110: }
5111: unless ($has_evb) {
5112: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5113: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5114: if ($udom eq $cdom) {
5115: $check_ipaccess = 1;
5116: }
5117: }
5118: }
1.1075.2.161. .3(raebu 5119:22): } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5120:22): ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5121:22): my $checkrole;
5122:22): if ($env{'request.role.domain'} eq '') {
5123:22): $checkrole = "cm./$env{'user.domain'}/";
5124:22): } else {
5125:22): $checkrole = "cm./$env{'request.role.domain'}/";
5126:22): }
5127:22): if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5128:22): $has_evb = 1;
5129:22): }
1.1075.2.158 raeburn 5130: }
5131: unless ($has_evb || $check_ipaccess) {
5132: my @machinedoms = &Apache::lonnet::current_machine_domains();
5133: if (($dom eq 'public') && ($activity eq 'port')) {
5134: $dom = $udom;
5135: }
5136: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5137: $check_ipaccess = 1;
5138: } else {
5139: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5140: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5141: my $prim = &Apache::lonnet::domain($dom,'primary');
5142: my $intdom = &Apache::lonnet::internet_dom($prim);
5143: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5144: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5145: $check_ipaccess = 1;
5146: }
5147: }
5148: }
5149: }
5150: if ($check_ipaccess) {
5151: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5152: unless (defined($cached)) {
5153: my %domconfig =
5154: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5155: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5156: }
5157: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5158: foreach my $id (keys(%{$ipaccessref})) {
5159: if (ref($ipaccessref->{$id}) eq 'HASH') {
5160: my $range = $ipaccessref->{$id}->{'ip'};
5161: if ($range) {
5162: if (&Apache::lonnet::ip_match($clientip,$range)) {
5163: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5164: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5165: return ('','','',$id,$dom);
5166: last;
5167: }
5168: }
5169: }
5170: }
5171: }
5172: }
5173: }
5174: }
1.1075.2.161. .4(raebu 5175:22): if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5176:22): return ();
5177:22): }
1.1075.2.158 raeburn 5178: }
1.1075.2.73 raeburn 5179: if (defined($udom) && defined($uname)) {
5180: # If uname and udom are for a course, check for blocks in the course.
5181: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5182: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 5183: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 5184: return ($startblock,$endblock,$triggerblock);
5185: }
5186: } else {
1.490 raeburn 5187: $udom = $env{'user.domain'};
5188: $uname = $env{'user.name'};
5189: }
5190:
1.502 raeburn 5191: my $startblock = 0;
5192: my $endblock = 0;
1.1062 raeburn 5193: my $triggerblock = '';
1.1075.2.160 raeburn 5194: my %live_courses;
5195: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5196: %live_courses = &findallcourses(undef,$uname,$udom);
5197: }
1.474 raeburn 5198:
1.490 raeburn 5199: # If uname is for a user, and activity is course-specific, i.e.,
5200: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5201:
1.490 raeburn 5202: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.161. .1(raebu 5203:21): $activity eq 'groups' || $activity eq 'printout' ||
5204:21): $activity eq 'search' || $activity eq 'reinit' ||
5205:21): $activity eq 'alert') && ($env{'request.course.id'})) {
1.490 raeburn 5206: foreach my $key (keys(%live_courses)) {
5207: if ($key ne $env{'request.course.id'}) {
5208: delete($live_courses{$key});
5209: }
5210: }
5211: }
5212:
5213: my $otheruser = 0;
5214: my %own_courses;
5215: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5216: # Resource belongs to user other than current user.
5217: $otheruser = 1;
5218: # Gather courses for current user
5219: %own_courses =
5220: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5221: }
5222:
5223: # Gather active course roles - course coordinator, instructor,
5224: # exam proctor, ta, student, or custom role.
1.474 raeburn 5225:
5226: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5227: my ($cdom,$cnum);
5228: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5229: $cdom = $env{'course.'.$course.'.domain'};
5230: $cnum = $env{'course.'.$course.'.num'};
5231: } else {
1.490 raeburn 5232: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5233: }
5234: my $no_ownblock = 0;
5235: my $no_userblock = 0;
1.533 raeburn 5236: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5237: # Check if current user has 'evb' priv for this
5238: if (defined($own_courses{$course})) {
5239: foreach my $sec (keys(%{$own_courses{$course}})) {
5240: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5241: if ($sec ne 'none') {
5242: $checkrole .= '/'.$sec;
5243: }
5244: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5245: $no_ownblock = 1;
5246: last;
5247: }
5248: }
5249: }
5250: # if they have 'evb' priv and are currently not playing student
5251: next if (($no_ownblock) &&
5252: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5253: }
1.474 raeburn 5254: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5255: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5256: if ($sec ne 'none') {
1.482 raeburn 5257: $checkrole .= '/'.$sec;
1.474 raeburn 5258: }
1.490 raeburn 5259: if ($otheruser) {
5260: # Resource belongs to user other than current user.
5261: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5262: my (%allroles,%userroles);
5263: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5264: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5265: my ($trole,$tdom,$tnum,$tsec);
5266: if ($entry =~ /^cr/) {
5267: ($trole,$tdom,$tnum,$tsec) =
5268: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5269: } else {
5270: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5271: }
5272: my ($spec,$area,$trest);
5273: $area = '/'.$tdom.'/'.$tnum;
5274: $trest = $tnum;
5275: if ($tsec ne '') {
5276: $area .= '/'.$tsec;
5277: $trest .= '/'.$tsec;
5278: }
5279: $spec = $trole.'.'.$area;
5280: if ($trole =~ /^cr/) {
5281: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5282: $tdom,$spec,$trest,$area);
5283: } else {
5284: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5285: $tdom,$spec,$trest,$area);
5286: }
5287: }
1.1075.2.124 raeburn 5288: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5289: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5290: if ($1) {
5291: $no_userblock = 1;
5292: last;
5293: }
1.486 raeburn 5294: }
5295: }
1.490 raeburn 5296: } else {
5297: # Resource belongs to current user
5298: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5299: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5300: $no_ownblock = 1;
5301: last;
5302: }
1.474 raeburn 5303: }
5304: }
5305: # if they have the evb priv and are currently not playing student
1.482 raeburn 5306: next if (($no_ownblock) &&
1.491 albertel 5307: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5308: next if ($no_userblock);
1.474 raeburn 5309:
1.1075.2.128 raeburn 5310: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5311: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5312:
1.1062 raeburn 5313: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 5314: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5315: if (($start != 0) &&
5316: (($startblock == 0) || ($startblock > $start))) {
5317: $startblock = $start;
1.1062 raeburn 5318: if ($trigger ne '') {
5319: $triggerblock = $trigger;
5320: }
1.502 raeburn 5321: }
5322: if (($end != 0) &&
5323: (($endblock == 0) || ($endblock < $end))) {
5324: $endblock = $end;
1.1062 raeburn 5325: if ($trigger ne '') {
5326: $triggerblock = $trigger;
5327: }
1.502 raeburn 5328: }
1.490 raeburn 5329: }
1.1062 raeburn 5330: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5331: }
5332:
5333: sub get_blocks {
1.1075.2.147 raeburn 5334: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5335: my $startblock = 0;
5336: my $endblock = 0;
1.1062 raeburn 5337: my $triggerblock = '';
1.490 raeburn 5338: my $course = $cdom.'_'.$cnum;
5339: $setters->{$course} = {};
5340: $setters->{$course}{'staff'} = [];
5341: $setters->{$course}{'times'} = [];
1.1062 raeburn 5342: $setters->{$course}{'triggers'} = [];
5343: my (@blockers,%triggered);
5344: my $now = time;
5345: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5346: if ($activity eq 'docs') {
1.1075.2.148 raeburn 5347: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 5348: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5349: $blocked = 1;
5350: $nosymbcache = 1;
1.1075.2.148 raeburn 5351: $noenccheck = 1;
1.1075.2.147 raeburn 5352: }
1.1075.2.148 raeburn 5353: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5354: foreach my $block (@blockers) {
5355: if ($block =~ /^firstaccess____(.+)$/) {
5356: my $item = $1;
5357: my $type = 'map';
5358: my $timersymb = $item;
5359: if ($item eq 'course') {
5360: $type = 'course';
5361: } elsif ($item =~ /___\d+___/) {
5362: $type = 'resource';
5363: } else {
5364: $timersymb = &Apache::lonnet::symbread($item);
5365: }
5366: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5367: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5368: $triggered{$block} = {
5369: start => $start,
5370: end => $end,
5371: type => $type,
5372: };
5373: }
5374: }
5375: } else {
5376: foreach my $block (keys(%commblocks)) {
5377: if ($block =~ m/^(\d+)____(\d+)$/) {
5378: my ($start,$end) = ($1,$2);
5379: if ($start <= time && $end >= time) {
5380: if (ref($commblocks{$block}) eq 'HASH') {
5381: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5382: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5383: unless(grep(/^\Q$block\E$/,@blockers)) {
5384: push(@blockers,$block);
5385: }
5386: }
5387: }
5388: }
5389: }
5390: } elsif ($block =~ /^firstaccess____(.+)$/) {
5391: my $item = $1;
5392: my $timersymb = $item;
5393: my $type = 'map';
5394: if ($item eq 'course') {
5395: $type = 'course';
5396: } elsif ($item =~ /___\d+___/) {
5397: $type = 'resource';
5398: } else {
5399: $timersymb = &Apache::lonnet::symbread($item);
5400: }
5401: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5402: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5403: if ($start && $end) {
5404: if (($start <= time) && ($end >= time)) {
1.1075.2.158 raeburn 5405: if (ref($commblocks{$block}) eq 'HASH') {
5406: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5407: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5408: unless(grep(/^\Q$block\E$/,@blockers)) {
5409: push(@blockers,$block);
5410: $triggered{$block} = {
5411: start => $start,
5412: end => $end,
5413: type => $type,
5414: };
5415: }
5416: }
5417: }
1.1062 raeburn 5418: }
5419: }
1.490 raeburn 5420: }
1.1062 raeburn 5421: }
5422: }
5423: }
5424: foreach my $blocker (@blockers) {
5425: my ($staff_name,$staff_dom,$title,$blocks) =
5426: &parse_block_record($commblocks{$blocker});
5427: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5428: my ($start,$end,$triggertype);
5429: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5430: ($start,$end) = ($1,$2);
5431: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5432: $start = $triggered{$blocker}{'start'};
5433: $end = $triggered{$blocker}{'end'};
5434: $triggertype = $triggered{$blocker}{'type'};
5435: }
5436: if ($start) {
5437: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5438: if ($triggertype) {
5439: push(@{$$setters{$course}{'triggers'}},$triggertype);
5440: } else {
5441: push(@{$$setters{$course}{'triggers'}},0);
5442: }
5443: if ( ($startblock == 0) || ($startblock > $start) ) {
5444: $startblock = $start;
5445: if ($triggertype) {
5446: $triggerblock = $blocker;
1.474 raeburn 5447: }
5448: }
1.1062 raeburn 5449: if ( ($endblock == 0) || ($endblock < $end) ) {
5450: $endblock = $end;
5451: if ($triggertype) {
5452: $triggerblock = $blocker;
5453: }
5454: }
1.474 raeburn 5455: }
5456: }
1.1062 raeburn 5457: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5458: }
5459:
5460: sub parse_block_record {
5461: my ($record) = @_;
5462: my ($setuname,$setudom,$title,$blocks);
5463: if (ref($record) eq 'HASH') {
5464: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5465: $title = &unescape($record->{'event'});
5466: $blocks = $record->{'blocks'};
5467: } else {
5468: my @data = split(/:/,$record,3);
5469: if (scalar(@data) eq 2) {
5470: $title = $data[1];
5471: ($setuname,$setudom) = split(/@/,$data[0]);
5472: } else {
5473: ($setuname,$setudom,$title) = @data;
5474: }
5475: $blocks = { 'com' => 'on' };
5476: }
5477: return ($setuname,$setudom,$title,$blocks);
5478: }
5479:
1.854 kalberla 5480: sub blocking_status {
1.1075.2.158 raeburn 5481: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5482: my %setters;
1.890 droeschl 5483:
1.1061 raeburn 5484: # check for active blocking
1.1075.2.158 raeburn 5485: if ($clientip eq '') {
5486: $clientip = &Apache::lonnet::get_requestor_ip();
5487: }
5488: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5489: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5490: my $blocked = 0;
1.1075.2.158 raeburn 5491: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5492: $blocked = 1;
5493: }
1.890 droeschl 5494:
1.1061 raeburn 5495: # caller just wants to know whether a block is active
5496: if (!wantarray) { return $blocked; }
5497:
5498: # build a link to a popup window containing the details
5499: my $querystring = "?activity=$activity";
1.1075.2.158 raeburn 5500: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5501: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5502: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5503: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5504: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 5505: my $showurl = &Apache::lonenc::check_encrypt($url);
5506: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5507: if ($symb) {
5508: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5509: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5510: }
1.1062 raeburn 5511: }
1.1061 raeburn 5512:
5513: my $output .= <<'END_MYBLOCK';
5514: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5515: var options = "width=" + w + ",height=" + h + ",";
5516: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5517: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5518: var newWin = window.open(url, wdwName, options);
5519: newWin.focus();
5520: }
1.890 droeschl 5521: END_MYBLOCK
1.854 kalberla 5522:
1.1061 raeburn 5523: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5524:
1.1061 raeburn 5525: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5526: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5527: my $class = 'LC_comblock';
1.1062 raeburn 5528: if ($activity eq 'docs') {
5529: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5530: $class = '';
1.1063 raeburn 5531: } elsif ($activity eq 'printout') {
5532: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5533: } elsif ($activity eq 'passwd') {
5534: $text = &mt('Password Changing Blocked');
1.1075.2.158 raeburn 5535: } elsif ($activity eq 'grades') {
5536: $text = &mt('Gradebook Blocked');
5537: } elsif ($activity eq 'search') {
5538: $text = &mt('Search Blocked');
1.1075.2.161. .1(raebu 5539:21): } elsif ($activity eq 'alert') {
5540:21): $text = &mt('Checking Critical Messages Blocked');
5541:21): } elsif ($activity eq 'reinit') {
5542:21): $text = &mt('Checking Course Update Blocked');
1.1075.2.158 raeburn 5543: } elsif ($activity eq 'about') {
5544: $text = &mt('Access to User Information Pages Blocked');
1.1075.2.160 raeburn 5545: } elsif ($activity eq 'wishlist') {
5546: $text = &mt('Access to Stored Links Blocked');
5547: } elsif ($activity eq 'annotate') {
5548: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5549: }
1.1061 raeburn 5550: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5551: <div class='$class'>
1.869 kalberla 5552: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5553: title='$text'>
5554: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5555: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5556: title='$text'>$text</a>
1.867 kalberla 5557: </div>
5558:
5559: END_BLOCK
1.474 raeburn 5560:
1.1061 raeburn 5561: return ($blocked, $output);
1.854 kalberla 5562: }
1.490 raeburn 5563:
1.60 matthew 5564: ###############################################
5565:
1.682 raeburn 5566: sub check_ip_acc {
1.1075.2.105 raeburn 5567: my ($acc,$clientip)=@_;
1.682 raeburn 5568: &Apache::lonxml::debug("acc is $acc");
5569: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5570: return 1;
5571: }
5572: my $allowed=0;
1.1075.2.144 raeburn 5573: my $ip;
5574: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5575: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5576: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5577: } else {
1.1075.2.150 raeburn 5578: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5579: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1075.2.144 raeburn 5580: }
1.682 raeburn 5581:
5582: my $name;
1.1075.2.161. .1(raebu 5583:21): my %access = (
5584:21): allowfrom => 1,
5585:21): denyfrom => 0,
5586:21): );
5587:21): my @allows;
5588:21): my @denies;
5589:21): foreach my $item (split(',',$acc)) {
5590:21): $item =~ s/^\s*//;
5591:21): $item =~ s/\s*$//;
5592:21): if ($item =~ /^\!(.+)$/) {
5593:21): push(@denies,$1);
5594:21): } else {
5595:21): push(@allows,$item);
5596:21): }
5597:21): }
5598:21): my $numdenies = scalar(@denies);
5599:21): my $numallows = scalar(@allows);
5600:21): my $count = 0;
5601:21): foreach my $pattern (@denies,@allows) {
5602:21): $count ++;
5603:21): my $acctype = 'allowfrom';
5604:21): if ($count <= $numdenies) {
5605:21): $acctype = 'denyfrom';
5606:21): }
1.682 raeburn 5607: if ($pattern =~ /\*$/) {
5608: #35.8.*
5609: $pattern=~s/\*//;
1.1075.2.161. .1(raebu 5610:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5611: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5612: #35.8.3.[34-56]
5613: my $low=$2;
5614: my $high=$3;
5615: $pattern=$1;
5616: if ($ip =~ /^\Q$pattern\E/) {
5617: my $last=(split(/\./,$ip))[3];
1.1075.2.161. .1(raebu 5618:21): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5619: }
5620: } elsif ($pattern =~ /^\*/) {
5621: #*.msu.edu
5622: $pattern=~s/\*//;
5623: if (!defined($name)) {
5624: use Socket;
5625: my $netaddr=inet_aton($ip);
5626: ($name)=gethostbyaddr($netaddr,AF_INET);
5627: }
1.1075.2.161. .1(raebu 5628:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5629: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5630: #127.0.0.1
1.1075.2.161. .1(raebu 5631:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5632: } else {
5633: #some.name.com
5634: if (!defined($name)) {
5635: use Socket;
5636: my $netaddr=inet_aton($ip);
5637: ($name)=gethostbyaddr($netaddr,AF_INET);
5638: }
1.1075.2.161. .1(raebu 5639:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5640:21): }
5641:21): if ($allowed =~ /^(0|1)$/) { last; }
5642:21): }
5643:21): if ($allowed eq '') {
5644:21): if ($numdenies && !$numallows) {
5645:21): $allowed = 1;
5646:21): } else {
5647:21): $allowed = 0;
1.682 raeburn 5648: }
5649: }
5650: return $allowed;
5651: }
5652:
5653: ###############################################
5654:
1.60 matthew 5655: =pod
5656:
1.112 bowersj2 5657: =head1 Domain Template Functions
5658:
5659: =over 4
5660:
5661: =item * &determinedomain()
1.60 matthew 5662:
5663: Inputs: $domain (usually will be undef)
5664:
1.63 www 5665: Returns: Determines which domain should be used for designs
1.60 matthew 5666:
5667: =cut
1.54 www 5668:
1.60 matthew 5669: ###############################################
1.63 www 5670: sub determinedomain {
5671: my $domain=shift;
1.531 albertel 5672: if (! $domain) {
1.60 matthew 5673: # Determine domain if we have not been given one
1.893 raeburn 5674: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5675: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5676: if ($env{'request.role.domain'}) {
5677: $domain=$env{'request.role.domain'};
1.60 matthew 5678: }
5679: }
1.63 www 5680: return $domain;
5681: }
5682: ###############################################
1.517 raeburn 5683:
1.518 albertel 5684: sub devalidate_domconfig_cache {
5685: my ($udom)=@_;
5686: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5687: }
5688:
5689: # ---------------------- Get domain configuration for a domain
5690: sub get_domainconf {
5691: my ($udom) = @_;
5692: my $cachetime=1800;
5693: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5694: if (defined($cached)) { return %{$result}; }
5695:
5696: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5697: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5698: my (%designhash,%legacy);
1.518 albertel 5699: if (keys(%domconfig) > 0) {
5700: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5701: if (keys(%{$domconfig{'login'}})) {
5702: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5703: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5704: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5705: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5706: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5707: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5708: if ($key eq 'loginvia') {
5709: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5710: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5711: $designhash{$udom.'.login.loginvia'} = $server;
5712: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5713: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5714: } else {
5715: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5716: }
1.948 raeburn 5717: }
1.1075.2.87 raeburn 5718: } elsif ($key eq 'headtag') {
5719: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5720: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5721: }
1.946 raeburn 5722: }
1.1075.2.87 raeburn 5723: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5724: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5725: }
1.946 raeburn 5726: }
5727: }
5728: }
1.1075.2.158 raeburn 5729: } elsif ($key eq 'saml') {
5730: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5731: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5732: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5733: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1075.2.161. .9(raebu 5734:22): foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1075.2.158 raeburn 5735: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5736: }
5737: }
5738: }
5739: }
1.946 raeburn 5740: } else {
5741: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5742: $designhash{$udom.'.login.'.$key.'_'.$img} =
5743: $domconfig{'login'}{$key}{$img};
5744: }
1.699 raeburn 5745: }
5746: } else {
5747: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5748: }
1.632 raeburn 5749: }
5750: } else {
5751: $legacy{'login'} = 1;
1.518 albertel 5752: }
1.632 raeburn 5753: } else {
5754: $legacy{'login'} = 1;
1.518 albertel 5755: }
5756: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5757: if (keys(%{$domconfig{'rolecolors'}})) {
5758: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5759: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5760: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5761: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5762: }
1.518 albertel 5763: }
5764: }
1.632 raeburn 5765: } else {
5766: $legacy{'rolecolors'} = 1;
1.518 albertel 5767: }
1.632 raeburn 5768: } else {
5769: $legacy{'rolecolors'} = 1;
1.518 albertel 5770: }
1.948 raeburn 5771: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5772: if ($domconfig{'autoenroll'}{'co-owners'}) {
5773: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5774: }
5775: }
1.632 raeburn 5776: if (keys(%legacy) > 0) {
5777: my %legacyhash = &get_legacy_domconf($udom);
5778: foreach my $item (keys(%legacyhash)) {
5779: if ($item =~ /^\Q$udom\E\.login/) {
5780: if ($legacy{'login'}) {
5781: $designhash{$item} = $legacyhash{$item};
5782: }
5783: } else {
5784: if ($legacy{'rolecolors'}) {
5785: $designhash{$item} = $legacyhash{$item};
5786: }
1.518 albertel 5787: }
5788: }
5789: }
1.632 raeburn 5790: } else {
5791: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5792: }
5793: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5794: $cachetime);
5795: return %designhash;
5796: }
5797:
1.632 raeburn 5798: sub get_legacy_domconf {
5799: my ($udom) = @_;
5800: my %legacyhash;
5801: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5802: my $designfile = $designdir.'/'.$udom.'.tab';
5803: if (-e $designfile) {
1.1075.2.128 raeburn 5804: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5805: while (my $line = <$fh>) {
5806: next if ($line =~ /^\#/);
5807: chomp($line);
5808: my ($key,$val)=(split(/\=/,$line));
5809: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5810: }
5811: close($fh);
5812: }
5813: }
1.1026 raeburn 5814: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5815: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5816: }
5817: return %legacyhash;
5818: }
5819:
1.63 www 5820: =pod
5821:
1.112 bowersj2 5822: =item * &domainlogo()
1.63 www 5823:
5824: Inputs: $domain (usually will be undef)
5825:
5826: Returns: A link to a domain logo, if the domain logo exists.
5827: If the domain logo does not exist, a description of the domain.
5828:
5829: =cut
1.112 bowersj2 5830:
1.63 www 5831: ###############################################
5832: sub domainlogo {
1.517 raeburn 5833: my $domain = &determinedomain(shift);
1.518 albertel 5834: my %designhash = &get_domainconf($domain);
1.517 raeburn 5835: # See if there is a logo
5836: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5837: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5838: if ($imgsrc =~ m{^/(adm|res)/}) {
5839: if ($imgsrc =~ m{^/res/}) {
5840: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5841: &Apache::lonnet::repcopy($local_name);
5842: }
5843: $imgsrc = &lonhttpdurl($imgsrc);
1.1075.2.161. .2(raebu 5844:22): }
5845:22): my $alttext = $domain;
5846:22): if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5847:22): $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5848:22): }
5849:22): return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5850: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5851: return &Apache::lonnet::domain($domain,'description');
1.59 www 5852: } else {
1.60 matthew 5853: return '';
1.59 www 5854: }
5855: }
1.63 www 5856: ##############################################
5857:
5858: =pod
5859:
1.112 bowersj2 5860: =item * &designparm()
1.63 www 5861:
5862: Inputs: $which parameter; $domain (usually will be undef)
5863:
5864: Returns: value of designparamter $which
5865:
5866: =cut
1.112 bowersj2 5867:
1.397 albertel 5868:
1.400 albertel 5869: ##############################################
1.397 albertel 5870: sub designparm {
5871: my ($which,$domain)=@_;
5872: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5873: return $env{'environment.color.'.$which};
1.96 www 5874: }
1.63 www 5875: $domain=&determinedomain($domain);
1.1016 raeburn 5876: my %domdesign;
5877: unless ($domain eq 'public') {
5878: %domdesign = &get_domainconf($domain);
5879: }
1.520 raeburn 5880: my $output;
1.517 raeburn 5881: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5882: $output = $domdesign{$domain.'.'.$which};
1.63 www 5883: } else {
1.520 raeburn 5884: $output = $defaultdesign{$which};
5885: }
5886: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5887: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5888: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5889: if ($output =~ m{^/res/}) {
5890: my $local_name = &Apache::lonnet::filelocation('',$output);
5891: &Apache::lonnet::repcopy($local_name);
5892: }
1.520 raeburn 5893: $output = &lonhttpdurl($output);
5894: }
1.63 www 5895: }
1.520 raeburn 5896: return $output;
1.63 www 5897: }
1.59 www 5898:
1.822 bisitz 5899: ##############################################
5900: =pod
5901:
1.832 bisitz 5902: =item * &authorspace()
5903:
1.1028 raeburn 5904: Inputs: $url (usually will be undef).
1.832 bisitz 5905:
1.1075.2.40 raeburn 5906: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5907: directory being viewed (or for which action is being taken).
5908: If $url is provided, and begins /priv/<domain>/<uname>
5909: the path will be that portion of the $context argument.
5910: Otherwise the path will be for the author space of the current
5911: user when the current role is author, or for that of the
5912: co-author/assistant co-author space when the current role
5913: is co-author or assistant co-author.
1.832 bisitz 5914:
5915: =cut
5916:
5917: sub authorspace {
1.1028 raeburn 5918: my ($url) = @_;
5919: if ($url ne '') {
5920: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5921: return $1;
5922: }
5923: }
1.832 bisitz 5924: my $caname = '';
1.1024 www 5925: my $cadom = '';
1.1028 raeburn 5926: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5927: ($cadom,$caname) =
1.832 bisitz 5928: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5929: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5930: $caname = $env{'user.name'};
1.1024 www 5931: $cadom = $env{'user.domain'};
1.832 bisitz 5932: }
1.1028 raeburn 5933: if (($caname ne '') && ($cadom ne '')) {
5934: return "/priv/$cadom/$caname/";
5935: }
5936: return;
1.832 bisitz 5937: }
5938:
5939: ##############################################
5940: =pod
5941:
1.822 bisitz 5942: =item * &head_subbox()
5943:
5944: Inputs: $content (contains HTML code with page functions, etc.)
5945:
5946: Returns: HTML div with $content
5947: To be included in page header
5948:
5949: =cut
5950:
5951: sub head_subbox {
5952: my ($content)=@_;
5953: my $output =
1.993 raeburn 5954: '<div class="LC_head_subbox">'
1.822 bisitz 5955: .$content
5956: .'</div>'
5957: }
5958:
5959: ##############################################
5960: =pod
5961:
5962: =item * &CSTR_pageheader()
5963:
1.1026 raeburn 5964: Input: (optional) filename from which breadcrumb trail is built.
5965: In most cases no input as needed, as $env{'request.filename'}
5966: is appropriate for use in building the breadcrumb trail.
1.1075.2.161. .6(raebu 5967:22): frameset flag
5968:22): If page header is being requested for use in a frameset, then
5969:22): the second (option) argument -- frameset will be true, and
5970:22): the target attribute set for links should be target="_parent".
1.822 bisitz 5971:
5972: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5973: To be included on Authoring Space pages
1.822 bisitz 5974:
5975: =cut
5976:
5977: sub CSTR_pageheader {
1.1075.2.161. .6(raebu 5978:22): my ($trailfile,$frameset) = @_;
1.1026 raeburn 5979: if ($trailfile eq '') {
5980: $trailfile = $env{'request.filename'};
5981: }
5982:
5983: # this is for resources; directories have customtitle, and crumbs
5984: # and select recent are created in lonpubdir.pm
5985:
5986: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5987: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5988: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5989: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5990: $formaction =~ s{/+}{/}g;
1.822 bisitz 5991:
5992: my $parentpath = '';
5993: my $lastitem = '';
5994: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5995: $parentpath = $1;
5996: $lastitem = $2;
5997: } else {
5998: $lastitem = $thisdisfn;
5999: }
1.921 bisitz 6000:
1.1075.2.161. .6(raebu 6001:22): my ($target,$crumbtarget) = (' target="_top"','_top');
6002:22): if ($frameset) {
6003:22): $target = ' target="_parent"';
6004:22): $crumbtarget = '_parent';
.17(raeb 6005:-23): } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
6006:-23): $target = '';
6007:-23): $crumbtarget = '';
.6(raebu 6008:22): } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
6009:22): $target = ' target="'.$env{'request.deeplink.target'}.'"';
6010:22): $crumbtarget = $env{'request.deeplink.target'};
6011:22): }
6012:22):
1.921 bisitz 6013: my $output =
1.822 bisitz 6014: '<div>'
6015: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 6016: .'<b>'.&mt('Authoring Space:').'</b> '
1.1075.2.161. .6(raebu 6017:22): .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6018:22): .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6019:
6020: if ($lastitem) {
6021: $output .=
6022: '<span class="LC_filename">'
6023: .$lastitem
6024: .'</span>';
6025: }
6026: $output .=
6027: '<br />'
1.1075.2.161. .6(raebu 6028:22): #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.822 bisitz 6029: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6030: .'</form>'
1.1075.2.161. .6(raebu 6031:22): .&Apache::lonmenu::constspaceform($frameset)
1.822 bisitz 6032: .'</div>';
1.921 bisitz 6033:
6034: return $output;
1.822 bisitz 6035: }
6036:
1.1075.2.161. .21(raeb 6037:-24): ##############################################
6038:-24): =pod
6039:-24):
6040:-24): =item * &nocodemirror()
6041:-24):
6042:-24): Input: None
6043:-24):
6044:-24): Returns: 1 if CodeMirror is deactivated based on
6045:-24): user's preference, or domain default,
6046:-24): if user indicated use of default.
6047:-24):
6048:-24): =cut
6049:-24):
6050:-24): sub nocodemirror {
6051:-24): my $nocodem = $env{'environment.nocodemirror'};
6052:-24): unless ($nocodem) {
6053:-24): my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6054:-24): if ($domdefs{'nocodemirror'}) {
6055:-24): $nocodem = 'yes';
6056:-24): }
6057:-24): }
6058:-24): if ($nocodem eq 'yes') {
6059:-24): return 1;
6060:-24): }
6061:-24): return;
6062:-24): }
6063:-24):
6064:-24): ##############################################
6065:-24): =pod
6066:-24):
6067:-24): =item * &permitted_editors()
6068:-24):
6069:-24): Input: $uri (optional)
6070:-24):
6071:-24): Returns: %editors hash in which keys are editors
.25(raeb 6072:-24): permitted in current Authoring Space,
6073:-24): or in current course for web pages
6074:-24): created in a course.
6075:-24):
.21(raeb 6076:-24): Value for each key is 1. Possible keys
.25(raeb 6077:-24): are: edit, xml, and daxe.
6078:-24):
6079:-24): For a regular Authoring Space, if no specific
.21(raeb 6080:-24): set of editors has been set for the Author
6081:-24): who owns the Authoring Space, then the
6082:-24): domain default will be used. If no domain
6083:-24): default has been set, then the keys will be
6084:-24): edit and xml.
6085:-24):
.25(raeb 6086:-24): For a course author, or for web pages created
6087:-24): in a course, if no specific set of editors has
6088:-24): been set for the course, then the domain
6089:-24): course default will be used. If no domain
6090:-24): course default has been set, then the keys
6091:-24): will be edit and xml.
6092:-24):
.21(raeb 6093:-24): =cut
6094:-24):
6095:-24): sub permitted_editors {
6096:-24): my ($uri) = @_;
.25(raeb 6097:-24): my ($is_author,$is_coauthor,$is_course,$auname,$audom,%editors);
.21(raeb 6098:-24): if ($env{'request.role'} =~ m{^au\./}) {
6099:-24): $is_author = 1;
6100:-24): } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6101:-24): ($audom,$auname) = ($1,$2);
6102:-24): if (($audom ne '') && ($auname ne '')) {
6103:-24): if (($env{'user.domain'} eq $audom) &&
6104:-24): ($env{'user.name'} eq $auname)) {
6105:-24): $is_author = 1;
6106:-24): } else {
6107:-24): $is_coauthor = 1;
6108:-24): }
6109:-24): }
6110:-24): } elsif ($env{'request.course.id'}) {
.25(raeb 6111:-24): my ($cdom,$cnum);
6112:-24): $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6113:-24): $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6114:-24): if (($env{'request.editurl'} =~ m{^/priv/\Q$cdom/$cnum\E/}) ||
6115:-24): ($env{'request.editurl'} =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}) ||
6116:-24): ($uri =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/})) {
6117:-24): $is_course = 1;
6118:-24): } elsif ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
.21(raeb 6119:-24): ($audom,$auname) = ($1,$2);
6120:-24): } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6121:-24): ($audom,$auname) = ($1,$2);
6122:-24): } elsif (($uri eq '/daxesave') &&
.25(raeb 6123:-24): (($env{'form.path'} =~ m{^/daxeopen/priv/\Q$cdom/$cnum\E/}) ||
6124:-24): ($env{'form.path'} =~ m{^/daxeopen/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}))) {
6125:-24): $is_course = 1;
6126:-24): } elsif (($uri eq '/daxesave') &&
.21(raeb 6127:-24): ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {
6128:-24): ($audom,$auname) = ($1,$2);
6129:-24): }
.25(raeb 6130:-24): unless ($is_course) {
6131:-24): if (($audom ne '') && ($auname ne '')) {
6132:-24): if (($env{'user.domain'} eq $audom) &&
6133:-24): ($env{'user.name'} eq $auname)) {
6134:-24): $is_author = 1;
6135:-24): } else {
6136:-24): $is_coauthor = 1;
6137:-24): }
.21(raeb 6138:-24): }
6139:-24): }
6140:-24): }
6141:-24): if ($is_author) {
6142:-24): if (exists($env{'environment.editors'})) {
6143:-24): map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6144:-24): } else {
6145:-24): %editors = ( edit => 1,
6146:-24): xml => 1,
6147:-24): );
6148:-24): }
6149:-24): } elsif ($is_coauthor) {
6150:-24): if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6151:-24): map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6152:-24): } else {
6153:-24): %editors = ( edit => 1,
6154:-24): xml => 1,
6155:-24): );
6156:-24): }
.25(raeb 6157:-24): } elsif ($is_course) {
6158:-24): if (exists($env{'course.'.$env{'request.course.id'}.'.internal.crseditors'})) {
6159:-24): map { $editors{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.crseditors'});
6160:-24): } else {
6161:-24): my %domdefaults = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
6162:-24): if (exists($domdefaults{'crseditors'})) {
6163:-24): map { $editors{$_} = 1; } split(/,/,$domdefaults{'crseditors'});
6164:-24): } else {
6165:-24): %editors = ( edit => 1,
6166:-24): xml => 1,
6167:-24): );
6168:-24): }
6169:-24): }
.21(raeb 6170:-24): } else {
6171:-24): %editors = ( edit => 1,
6172:-24): xml => 1,
6173:-24): );
6174:-24): }
6175:-24): return %editors;
6176:-24): }
6177:-24):
1.60 matthew 6178: ###############################################
6179: ###############################################
6180:
6181: =pod
6182:
1.112 bowersj2 6183: =back
6184:
1.549 albertel 6185: =head1 HTML Helpers
1.112 bowersj2 6186:
6187: =over 4
6188:
6189: =item * &bodytag()
1.60 matthew 6190:
6191: Returns a uniform header for LON-CAPA web pages.
6192:
6193: Inputs:
6194:
1.112 bowersj2 6195: =over 4
6196:
6197: =item * $title, A title to be displayed on the page.
6198:
6199: =item * $function, the current role (can be undef).
6200:
6201: =item * $addentries, extra parameters for the <body> tag.
6202:
6203: =item * $bodyonly, if defined, only return the <body> tag.
6204:
6205: =item * $domain, if defined, force a given domain.
6206:
6207: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6208: text interface only)
1.60 matthew 6209:
1.814 bisitz 6210: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6211: navigational links
1.317 albertel 6212:
1.338 albertel 6213: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6214:
1.1075.2.12 raeburn 6215: =item * $no_inline_link, if true and in remote mode, don't show the
6216: 'Switch To Inline Menu' link
6217:
1.460 albertel 6218: =item * $args, optional argument valid values are
6219: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 6220: use_absolute -> for external resource or syllabus, this will
6221: contain https://<hostname> if server uses
6222: https (as per hosts.tab), but request is for http
6223: hostname -> hostname, from $r->hostname().
1.460 albertel 6224:
1.1075.2.15 raeburn 6225: =item * $advtoolsref, optional argument, ref to an array containing
6226: inlineremote items to be added in "Functions" menu below
6227: breadcrumbs.
6228:
1.1075.2.161. .1(raebu 6229:21): =item * $ltiscope, optional argument, will be one of: resource, map or
6230:21): course, if LON-CAPA is in LTI Provider context. Value is
6231:21): the scope of use, i.e., launch was for access to a single, a map
6232:21): or the entire course.
6233:21):
6234:21): =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6235:21): context, this will contain the URL for the landing item in
6236:21): the course, after launch from an LTI Consumer
6237:21):
6238:21): =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6239:21): context, this will contain a reference to hash of items
6240:21): to be included in the page header and/or inline menu.
6241:21):
.8(raebu 6242:22): =item * $menucoll, optional argument, if specific menu collection is in
6243:22): effect, either set as the default for the course, or set for
6244:22): the deeplink paramater for $env{'request.deeplink.login'}
6245:22): then $menucoll will be the number of that collection.
6246:22):
6247:22): =item * $menuref, optional argument, reference to a hash, containing the
6248:22): menu options included for the menu in effect, based on the
6249:22): configuration for the numbered menu collection in use.
6250:22):
6251:22): =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6252:22): within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6253:22): if so, $showncrumbsref is set there to 1, and will propagate back
6254:22): via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6255:22): being called a second time.
6256:22):
1.112 bowersj2 6257: =back
6258:
1.60 matthew 6259: Returns: A uniform header for LON-CAPA web pages.
6260: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6261: If $bodyonly is undef or zero, an html string containing a <body> tag and
6262: other decorations will be returned.
6263:
6264: =cut
6265:
1.54 www 6266: sub bodytag {
1.831 bisitz 6267: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.161. .1(raebu 6268:21): $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref,
.8(raebu 6269:22): $ltiscope,$ltiuri,$ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6270:
1.954 raeburn 6271: my $public;
6272: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6273: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6274: $public = 1;
6275: }
1.460 albertel 6276: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 6277: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 6278: my $hostname = $args->{'hostname'};
1.339 albertel 6279:
1.183 matthew 6280: $function = &get_users_function() if (!$function);
1.339 albertel 6281: my $img = &designparm($function.'.img',$domain);
6282: my $font = &designparm($function.'.font',$domain);
6283: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6284:
1.803 bisitz 6285: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6286: 'bgcolor' => $pgbg,
1.339 albertel 6287: 'text' => $font,
6288: 'alink' => &designparm($function.'.alink',$domain),
6289: 'vlink' => &designparm($function.'.vlink',$domain),
6290: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6291: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6292:
1.63 www 6293: # role and realm
1.1075.2.68 raeburn 6294: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6295: if ($realm) {
6296: $realm = '/'.$realm;
6297: }
1.1075.2.159 raeburn 6298: if ($role eq 'ca') {
1.479 albertel 6299: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6300: $realm = &plainname($rname,$rdom);
1.378 raeburn 6301: }
1.55 www 6302: # realm
1.1075.2.158 raeburn 6303: my ($cid,$sec);
1.258 albertel 6304: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 6305: $cid = $env{'request.course.id'};
6306: if ($env{'request.course.sec'}) {
6307: $sec = $env{'request.course.sec'};
6308: }
6309: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6310: if (&Apache::lonnet::is_course($1,$2)) {
6311: $cid = $1.'_'.$2;
6312: $sec = $3;
6313: }
6314: }
6315: if ($cid) {
1.378 raeburn 6316: if ($env{'request.role'} !~ /^cr/) {
6317: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 6318: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 6319: if ($env{'request.role.desc'}) {
6320: $role = $env{'request.role.desc'};
6321: } else {
6322: $role = &mt('Helpdesk[_1]',' '.$2);
6323: }
1.1075.2.115 raeburn 6324: } else {
6325: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6326: }
1.1075.2.158 raeburn 6327: if ($sec) {
6328: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6329: }
1.1075.2.158 raeburn 6330: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6331: } else {
6332: $role = &Apache::lonnet::plaintext($role);
1.54 www 6333: }
1.433 albertel 6334:
1.359 albertel 6335: if (!$realm) { $realm=' '; }
1.330 albertel 6336:
1.438 albertel 6337: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6338:
1.101 www 6339: # construct main body tag
1.359 albertel 6340: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 6341: &Apache::lontexconvert::init_math_support();
1.252 albertel 6342:
1.1075.2.38 raeburn 6343: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6344:
6345: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6346: return $bodytag;
1.1075.2.38 raeburn 6347: }
1.359 albertel 6348:
1.954 raeburn 6349: if ($public) {
1.433 albertel 6350: undef($role);
6351: }
1.1075.2.158 raeburn 6352:
1.1075.2.161. .1(raebu 6353:21): my $showcrstitle = 1;
6354:21): if (($cid) && ($env{'request.lti.login'})) {
6355:21): if (ref($ltimenu) eq 'HASH') {
6356:21): unless ($ltimenu->{'role'}) {
6357:21): undef($role);
6358:21): }
6359:21): unless ($ltimenu->{'coursetitle'}) {
6360:21): $realm=' ';
6361:21): $showcrstitle = 0;
6362:21): }
6363:21): }
6364:21): } elsif (($cid) && ($menucoll)) {
6365:21): if (ref($menuref) eq 'HASH') {
6366:21): unless ($menuref->{'role'}) {
6367:21): undef($role);
6368:21): }
6369:21): unless ($menuref->{'crs'}) {
6370:21): $realm=' ';
6371:21): $showcrstitle = 0;
6372:21): }
6373:21): }
6374:21): }
6375:21):
1.762 bisitz 6376: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6377: #
6378: # Extra info if you are the DC
6379: my $dc_info = '';
1.1075.2.161. .1(raebu 6380:21): if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1075.2.158 raeburn 6381: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6382: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6383: $dc_info =~ s/\s+$//;
1.359 albertel 6384: }
6385:
1.1075.2.161. .1(raebu 6386:21): my $crstype;
6387:21): if ($cid) {
6388:21): $crstype = $env{'course.'.$cid.'.type'};
6389:21): } elsif ($args->{'crstype'}) {
6390:21): $crstype = $args->{'crstype'};
6391:21): }
6392:21):
1.1075.2.108 raeburn 6393: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 6394:
1.1075.2.13 raeburn 6395: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6396:
1.1075.2.38 raeburn 6397:
6398:
1.1075.2.21 raeburn 6399: my $funclist;
6400: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 6401: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 6402: Apache::lonmenu::serverform();
6403: my $forbodytag;
6404: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6405: $forcereg,$args->{'group'},
6406: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6407: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 6408: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6409: $funclist = $forbodytag;
6410: }
6411: } else {
1.903 droeschl 6412:
6413: # if ($env{'request.state'} eq 'construct') {
6414: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6415: # }
6416:
1.1075.2.38 raeburn 6417: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6418: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6419:
1.1075.2.161. .23(raeb 6420:-24): my $collapsible;
.21(raeb 6421:-24): if ($args->{'collapsible_header'} ne '') {
.23(raeb 6422:-24): $collapsible = 1;
6423:-24): my ($menustate,$tiptext,$divclass);
6424:-24): if ($args->{'start_collapsed'}) {
6425:-24): $menustate = 'collapsed';
6426:-24): $tiptext = 'display';
6427:-24): $divclass = 'hidden';
6428:-24): } else {
6429:-24): $menustate = 'expanded';
6430:-24): $tiptext = 'hide';
6431:-24): $divclass = 'shown';
6432:-24): }
6433:-24): my $alttext = &mt('menu state: '.$menustate);
6434:-24): my $tooltip = &mt($tiptext.' standard menus');
.21(raeb 6435:-24): $bodytag .= <<"END";
6436:-24): <div id="LC_expandingContainer" style="display:inline;">
6437:-24): <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
.23(raeb 6438:-24): <a href="#" style="text-decoration:none;"><img class="LC_collapsible_indicator" alt="$alttext" title="$tooltip" src="/res/adm/pages/$menustate.png" style="border:0;margin:0;padding:0;max-width:100%;height:auto" /></a></div>
6439:-24): <div class="LC_menus_content $divclass">
.21(raeb 6440:-24): END
6441:-24): }
.1(raebu 6442:21): unless ($args->{'no_primary_menu'}) {
.4(raebu 6443:22): my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
.6(raebu 6444:22): $args->{'links_disabled'},
.21(raeb 6445:-24): $args->{'links_target'},
.23(raeb 6446:-24): $collapsible);
.1(raebu 6447:21): if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6448:21): if ($dc_info) {
6449:21): $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6450:21): }
6451:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6452:21): <em>$realm</em> $dc_info</div>|;
6453:21): return $bodytag;
1.1075.2.1 raeburn 6454: }
1.894 droeschl 6455:
1.1075.2.161. .1(raebu 6456:21): unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6457:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6458:21): }
1.916 droeschl 6459:
1.1075.2.161. .1(raebu 6460:21): $bodytag .= $right;
1.852 droeschl 6461:
1.1075.2.161. .1(raebu 6462:21): if ($dc_info) {
6463:21): $dc_info = &dc_courseid_toggle($dc_info);
6464:21): }
6465:21): $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6466: }
1.916 droeschl 6467:
1.1075.2.61 raeburn 6468: #if directed to not display the secondary menu, don't.
6469: if ($args->{'no_secondary_menu'}) {
6470: return $bodytag;
6471: }
1.903 droeschl 6472: #don't show menus for public users
1.954 raeburn 6473: if (!$public){
1.1075.2.161. .1(raebu 6474:21): unless ($args->{'no_inline_menu'}) {
6475:21): $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6476:21): $args->{'no_primary_menu'},
6477:21): $menucoll,$menuref,
.6(raebu 6478:22): $args->{'links_disabled'},
6479:22): $args->{'links_target'});
.1(raebu 6480:21): }
1.903 droeschl 6481: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6482: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6483: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6484: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.161. .8(raebu 6485:22): $args->{'bread_crumbs'},'','',$hostname,
6486:22): $ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.116 raeburn 6487: } elsif ($forcereg) {
1.1075.2.22 raeburn 6488: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.161. .8(raebu 6489:22): $args->{'group'},$args->{'hide_buttons'},
6490:22): $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.15 raeburn 6491: } else {
1.1075.2.21 raeburn 6492: my $forbodytag;
6493: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6494: $forcereg,$args->{'group'},
6495: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6496: $advtoolsref,'',$hostname,
6497: \$forbodytag);
1.1075.2.21 raeburn 6498: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6499: $bodytag .= $forbodytag;
6500: }
1.920 raeburn 6501: }
1.903 droeschl 6502: }else{
6503: # this is to seperate menu from content when there's no secondary
6504: # menu. Especially needed for public accessible ressources.
6505: $bodytag .= '<hr style="clear:both" />';
6506: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6507: }
1.1075.2.161. .21(raeb 6508:-24): if ($args->{'collapsible_header'} ne '') {
6509:-24): $bodytag .= $args->{'collapsible_header'}.
6510:-24): '<div id="LC_collapsible_separator"></div>'.
6511:-24): '</div></div>';
6512:-24): }
1.235 raeburn 6513: return $bodytag;
1.1075.2.12 raeburn 6514: }
6515:
6516: #
6517: # Top frame rendering, Remote is up
6518: #
6519:
6520: my $imgsrc = $img;
6521: if ($img =~ /^\/adm/) {
6522: $imgsrc = &lonhttpdurl($img);
6523: }
6524: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
6525:
1.1075.2.60 raeburn 6526: my $help=($no_inline_link?''
6527: :&Apache::loncommon::top_nav_help('Help'));
6528:
1.1075.2.12 raeburn 6529: # Explicit link to get inline menu
6530: my $menu= ($no_inline_link?''
6531: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
6532:
6533: if ($dc_info) {
6534: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
6535: }
6536:
1.1075.2.38 raeburn 6537: my $name = &plainname($env{'user.name'},$env{'user.domain'});
6538: unless ($public) {
6539: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
6540: undef,'LC_menubuttons_link');
6541: }
6542:
1.1075.2.12 raeburn 6543: unless ($env{'form.inhibitmenu'}) {
6544: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 6545: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 6546: <li>$help</li>
1.1075.2.12 raeburn 6547: <li>$menu</li>
6548: </ol><div id="LC_realm"> $realm $dc_info</div>|;
6549: }
1.1075.2.13 raeburn 6550: if ($env{'request.state'} eq 'construct') {
6551: if (!$public){
6552: if ($env{'request.state'} eq 'construct') {
6553: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6554: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 6555: &Apache::lonhtmlcommon::scripttag('','end').
6556: &Apache::lonmenu::innerregister($forcereg,
6557: $args->{'bread_crumbs'});
6558: }
6559: }
6560: }
1.1075.2.21 raeburn 6561: return $bodytag."\n".$funclist;
1.182 matthew 6562: }
6563:
1.917 raeburn 6564: sub dc_courseid_toggle {
6565: my ($dc_info) = @_;
1.980 raeburn 6566: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6567: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6568: &mt('(More ...)').'</a></span>'.
6569: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6570: }
6571:
1.330 albertel 6572: sub make_attr_string {
6573: my ($register,$attr_ref) = @_;
6574:
6575: if ($attr_ref && !ref($attr_ref)) {
6576: die("addentries Must be a hash ref ".
6577: join(':',caller(1))." ".
6578: join(':',caller(0))." ");
6579: }
6580:
6581: if ($register) {
1.339 albertel 6582: my ($on_load,$on_unload);
6583: foreach my $key (keys(%{$attr_ref})) {
6584: if (lc($key) eq 'onload') {
6585: $on_load.=$attr_ref->{$key}.';';
6586: delete($attr_ref->{$key});
6587:
6588: } elsif (lc($key) eq 'onunload') {
6589: $on_unload.=$attr_ref->{$key}.';';
6590: delete($attr_ref->{$key});
6591: }
6592: }
1.1075.2.12 raeburn 6593: if ($env{'environment.remote'} eq 'on') {
6594: $attr_ref->{'onload'} =
6595: &Apache::lonmenu::loadevents(). $on_load;
6596: $attr_ref->{'onunload'}=
6597: &Apache::lonmenu::unloadevents().$on_unload;
6598: } else {
6599: $attr_ref->{'onload'} = $on_load;
6600: $attr_ref->{'onunload'}= $on_unload;
6601: }
1.330 albertel 6602: }
1.339 albertel 6603:
1.330 albertel 6604: my $attr_string;
1.1075.2.56 raeburn 6605: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6606: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6607: }
6608: return $attr_string;
6609: }
6610:
6611:
1.182 matthew 6612: ###############################################
1.251 albertel 6613: ###############################################
6614:
6615: =pod
6616:
6617: =item * &endbodytag()
6618:
6619: Returns a uniform footer for LON-CAPA web pages.
6620:
1.635 raeburn 6621: Inputs: 1 - optional reference to an args hash
6622: If in the hash, key for noredirectlink has a value which evaluates to true,
6623: a 'Continue' link is not displayed if the page contains an
6624: internal redirect in the <head></head> section,
6625: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6626:
6627: =cut
6628:
6629: sub endbodytag {
1.635 raeburn 6630: my ($args) = @_;
1.1075.2.6 raeburn 6631: my $endbodytag;
6632: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6633: $endbodytag='</body>';
6634: }
1.315 albertel 6635: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6636: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1075.2.161. .9(raebu 6637:22): my ($endbodyjs,$idattr);
6638:22): if ($env{'internal.head.to_opener'}) {
6639:22): my $linkid = 'LC_continue_link';
6640:22): $idattr = ' id="'.$linkid.'"';
6641:22): my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6642:22): $endbodyjs=<<ENDJS;
6643:22): <script type="text/javascript">
6644:22): // <![CDATA[
6645:22): function ebFunction(evt) {
6646:22): evt.preventDefault();
6647:22): var dest = '$redirect_for_js';
6648:22): if (window.opener != null && !window.opener.closed) {
6649:22): window.opener.location.href=dest;
6650:22): window.close();
6651:22): } else {
6652:22): window.location.href=dest;
6653:22): }
6654:22): return false;
6655:22): }
6656:22):
6657:22): \$(document).ready(function () {
6658:22): if (document.getElementById('$linkid')) {
6659:22): var clickelem = document.getElementById('$linkid');
6660:22): clickelem.addEventListener('click',ebFunction,false);
6661:22): }
6662:22): });
6663:22): // ]]>
6664:22): </script>
6665:22): ENDJS
6666:22): }
1.635 raeburn 6667: $endbodytag=
1.1075.2.161. .9(raebu 6668:22): "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6669: &mt('Continue').'</a>'.
6670: $endbodytag;
6671: }
1.315 albertel 6672: }
1.1075.2.161. .19(raeb 6673:-23): if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6674:-23): $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6675:-23): }
1.251 albertel 6676: return $endbodytag;
6677: }
6678:
1.352 albertel 6679: =pod
6680:
6681: =item * &standard_css()
6682:
6683: Returns a style sheet
6684:
6685: Inputs: (all optional)
6686: domain -> force to color decorate a page for a specific
6687: domain
6688: function -> force usage of a specific rolish color scheme
6689: bgcolor -> override the default page bgcolor
6690:
6691: =cut
6692:
1.343 albertel 6693: sub standard_css {
1.345 albertel 6694: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6695: $function = &get_users_function() if (!$function);
6696: my $img = &designparm($function.'.img', $domain);
6697: my $tabbg = &designparm($function.'.tabbg', $domain);
6698: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6699: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6700: #second colour for later usage
1.345 albertel 6701: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6702: my $pgbg_or_bgcolor =
6703: $bgcolor ||
1.352 albertel 6704: &designparm($function.'.pgbg', $domain);
1.382 albertel 6705: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6706: my $alink = &designparm($function.'.alink', $domain);
6707: my $vlink = &designparm($function.'.vlink', $domain);
6708: my $link = &designparm($function.'.link', $domain);
6709:
1.602 albertel 6710: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6711: my $mono = 'monospace';
1.850 bisitz 6712: my $data_table_head = $sidebg;
6713: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6714: my $data_table_dark = '#E0E0E0';
1.470 banghart 6715: my $data_table_darker = '#CCCCCC';
1.349 albertel 6716: my $data_table_highlight = '#FFFF00';
1.352 albertel 6717: my $mail_new = '#FFBB77';
6718: my $mail_new_hover = '#DD9955';
6719: my $mail_read = '#BBBB77';
6720: my $mail_read_hover = '#999944';
6721: my $mail_replied = '#AAAA88';
6722: my $mail_replied_hover = '#888855';
6723: my $mail_other = '#99BBBB';
6724: my $mail_other_hover = '#669999';
1.391 albertel 6725: my $table_header = '#DDDDDD';
1.489 raeburn 6726: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6727: my $lg_border_color = '#C8C8C8';
1.952 onken 6728: my $button_hover = '#BF2317';
1.392 albertel 6729:
1.608 albertel 6730: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6731: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6732: : '0 3px 0 4px';
1.448 albertel 6733:
1.523 albertel 6734:
1.343 albertel 6735: return <<END;
1.947 droeschl 6736:
6737: /* needed for iframe to allow 100% height in FF */
6738: body, html {
6739: margin: 0;
6740: padding: 0 0.5%;
6741: height: 99%; /* to avoid scrollbars */
6742: }
6743:
1.795 www 6744: body {
1.911 bisitz 6745: font-family: $sans;
6746: line-height:130%;
6747: font-size:0.83em;
6748: color:$font;
1.795 www 6749: }
6750:
1.959 onken 6751: a:focus,
6752: a:focus img {
1.795 www 6753: color: red;
6754: }
1.698 harmsja 6755:
1.911 bisitz 6756: form, .inline {
6757: display: inline;
1.795 www 6758: }
1.721 harmsja 6759:
1.1075.2.161. .21(raeb 6760:-24): .LC_menus_content.shown{
.24(raeb 6761:-24): display: block;
.21(raeb 6762:-24): }
6763:-24):
6764:-24): .LC_menus_content.hidden {
6765:-24): display: none;
6766:-24): }
6767:-24):
1.795 www 6768: .LC_right {
1.911 bisitz 6769: text-align:right;
1.795 www 6770: }
6771:
6772: .LC_middle {
1.911 bisitz 6773: vertical-align:middle;
1.795 www 6774: }
1.721 harmsja 6775:
1.1075.2.38 raeburn 6776: .LC_floatleft {
6777: float: left;
6778: }
6779:
6780: .LC_floatright {
6781: float: right;
6782: }
6783:
1.911 bisitz 6784: .LC_400Box {
6785: width:400px;
6786: }
1.721 harmsja 6787:
1.1075.2.161. .21(raeb 6788:-24): #LC_collapsible_separator {
6789:-24): border: 1px solid black;
6790:-24): width: 99.9%;
6791:-24): height: 0px;
6792:-24): }
6793:-24):
1.947 droeschl 6794: .LC_iframecontainer {
6795: width: 98%;
6796: margin: 0;
6797: position: fixed;
6798: top: 8.5em;
6799: bottom: 0;
6800: }
6801:
6802: .LC_iframecontainer iframe{
6803: border: none;
6804: width: 100%;
6805: height: 100%;
6806: }
6807:
1.778 bisitz 6808: .LC_filename {
6809: font-family: $mono;
6810: white-space:pre;
1.921 bisitz 6811: font-size: 120%;
1.778 bisitz 6812: }
6813:
6814: .LC_fileicon {
6815: border: none;
6816: height: 1.3em;
6817: vertical-align: text-bottom;
6818: margin-right: 0.3em;
6819: text-decoration:none;
6820: }
6821:
1.1008 www 6822: .LC_setting {
6823: text-decoration:underline;
6824: }
6825:
1.350 albertel 6826: .LC_error {
6827: color: red;
6828: }
1.795 www 6829:
1.1075.2.15 raeburn 6830: .LC_warning {
6831: color: darkorange;
6832: }
6833:
1.457 albertel 6834: .LC_diff_removed {
1.733 bisitz 6835: color: red;
1.394 albertel 6836: }
1.532 albertel 6837:
6838: .LC_info,
1.457 albertel 6839: .LC_success,
6840: .LC_diff_added {
1.350 albertel 6841: color: green;
6842: }
1.795 www 6843:
1.802 bisitz 6844: div.LC_confirm_box {
6845: background-color: #FAFAFA;
6846: border: 1px solid $lg_border_color;
6847: margin-right: 0;
6848: padding: 5px;
6849: }
6850:
6851: div.LC_confirm_box .LC_error img,
6852: div.LC_confirm_box .LC_success img {
6853: vertical-align: middle;
6854: }
6855:
1.1075.2.108 raeburn 6856: .LC_maxwidth {
6857: max-width: 100%;
6858: height: auto;
6859: }
6860:
6861: .LC_textsize_mobile {
6862: \@media only screen and (max-device-width: 480px) {
6863: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6864: }
6865: }
6866:
1.440 albertel 6867: .LC_icon {
1.771 droeschl 6868: border: none;
1.790 droeschl 6869: vertical-align: middle;
1.771 droeschl 6870: }
6871:
1.543 albertel 6872: .LC_docs_spacer {
6873: width: 25px;
6874: height: 1px;
1.771 droeschl 6875: border: none;
1.543 albertel 6876: }
1.346 albertel 6877:
1.532 albertel 6878: .LC_internal_info {
1.735 bisitz 6879: color: #999999;
1.532 albertel 6880: }
6881:
1.794 www 6882: .LC_discussion {
1.1050 www 6883: background: $data_table_dark;
1.911 bisitz 6884: border: 1px solid black;
6885: margin: 2px;
1.794 www 6886: }
6887:
6888: .LC_disc_action_left {
1.1050 www 6889: background: $sidebg;
1.911 bisitz 6890: text-align: left;
1.1050 www 6891: padding: 4px;
6892: margin: 2px;
1.794 www 6893: }
6894:
6895: .LC_disc_action_right {
1.1050 www 6896: background: $sidebg;
1.911 bisitz 6897: text-align: right;
1.1050 www 6898: padding: 4px;
6899: margin: 2px;
1.794 www 6900: }
6901:
6902: .LC_disc_new_item {
1.911 bisitz 6903: background: white;
6904: border: 2px solid red;
1.1050 www 6905: margin: 4px;
6906: padding: 4px;
1.794 www 6907: }
6908:
6909: .LC_disc_old_item {
1.911 bisitz 6910: background: white;
1.1050 www 6911: margin: 4px;
6912: padding: 4px;
1.794 www 6913: }
6914:
1.458 albertel 6915: table.LC_pastsubmission {
6916: border: 1px solid black;
6917: margin: 2px;
6918: }
6919:
1.924 bisitz 6920: table#LC_menubuttons {
1.345 albertel 6921: width: 100%;
6922: background: $pgbg;
1.392 albertel 6923: border: 2px;
1.402 albertel 6924: border-collapse: separate;
1.803 bisitz 6925: padding: 0;
1.345 albertel 6926: }
1.392 albertel 6927:
1.801 tempelho 6928: table#LC_title_bar a {
6929: color: $fontmenu;
6930: }
1.836 bisitz 6931:
1.807 droeschl 6932: table#LC_title_bar {
1.819 tempelho 6933: clear: both;
1.836 bisitz 6934: display: none;
1.807 droeschl 6935: }
6936:
1.795 www 6937: table#LC_title_bar,
1.933 droeschl 6938: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6939: table#LC_title_bar.LC_with_remote {
1.359 albertel 6940: width: 100%;
1.392 albertel 6941: border-color: $pgbg;
6942: border-style: solid;
6943: border-width: $border;
1.379 albertel 6944: background: $pgbg;
1.801 tempelho 6945: color: $fontmenu;
1.392 albertel 6946: border-collapse: collapse;
1.803 bisitz 6947: padding: 0;
1.819 tempelho 6948: margin: 0;
1.359 albertel 6949: }
1.795 www 6950:
1.933 droeschl 6951: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6952: margin: 0;
6953: padding: 0;
1.933 droeschl 6954: position: relative;
6955: list-style: none;
1.913 droeschl 6956: }
1.933 droeschl 6957: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6958: display: inline;
6959: }
1.933 droeschl 6960:
6961: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6962: padding: 0;
1.933 droeschl 6963: margin: 0;
6964: float: left;
1.913 droeschl 6965: }
1.933 droeschl 6966: .LC_breadcrumb_tools_tools {
6967: padding: 0;
6968: margin: 0;
1.913 droeschl 6969: float: right;
6970: }
6971:
1.359 albertel 6972: table#LC_title_bar td {
6973: background: $tabbg;
6974: }
1.795 www 6975:
1.911 bisitz 6976: table#LC_menubuttons img {
1.803 bisitz 6977: border: none;
1.346 albertel 6978: }
1.795 www 6979:
1.842 droeschl 6980: .LC_breadcrumbs_component {
1.911 bisitz 6981: float: right;
6982: margin: 0 1em;
1.357 albertel 6983: }
1.842 droeschl 6984: .LC_breadcrumbs_component img {
1.911 bisitz 6985: vertical-align: middle;
1.777 tempelho 6986: }
1.795 www 6987:
1.1075.2.108 raeburn 6988: .LC_breadcrumbs_hoverable {
6989: background: $sidebg;
6990: }
6991:
1.383 albertel 6992: td.LC_table_cell_checkbox {
6993: text-align: center;
6994: }
1.795 www 6995:
6996: .LC_fontsize_small {
1.911 bisitz 6997: font-size: 70%;
1.705 tempelho 6998: }
6999:
1.844 bisitz 7000: #LC_breadcrumbs {
1.911 bisitz 7001: clear:both;
7002: background: $sidebg;
7003: border-bottom: 1px solid $lg_border_color;
7004: line-height: 2.5em;
1.933 droeschl 7005: overflow: hidden;
1.911 bisitz 7006: margin: 0;
7007: padding: 0;
1.995 raeburn 7008: text-align: left;
1.819 tempelho 7009: }
1.862 bisitz 7010:
1.1075.2.16 raeburn 7011: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7012: clear:both;
7013: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7014: border: 1px solid $sidebg;
1.1075.2.16 raeburn 7015: margin: 0 0 10px 0;
1.966 bisitz 7016: padding: 3px;
1.995 raeburn 7017: text-align: left;
1.822 bisitz 7018: }
7019:
1.795 www 7020: .LC_fontsize_medium {
1.911 bisitz 7021: font-size: 85%;
1.705 tempelho 7022: }
7023:
1.795 www 7024: .LC_fontsize_large {
1.911 bisitz 7025: font-size: 120%;
1.705 tempelho 7026: }
7027:
1.346 albertel 7028: .LC_menubuttons_inline_text {
7029: color: $font;
1.698 harmsja 7030: font-size: 90%;
1.701 harmsja 7031: padding-left:3px;
1.346 albertel 7032: }
7033:
1.934 droeschl 7034: .LC_menubuttons_inline_text img{
7035: vertical-align: middle;
7036: }
7037:
1.1051 www 7038: li.LC_menubuttons_inline_text img {
1.951 onken 7039: cursor:pointer;
1.1002 droeschl 7040: text-decoration: none;
1.951 onken 7041: }
7042:
1.526 www 7043: .LC_menubuttons_link {
7044: text-decoration: none;
7045: }
1.795 www 7046:
1.522 albertel 7047: .LC_menubuttons_category {
1.521 www 7048: color: $font;
1.526 www 7049: background: $pgbg;
1.521 www 7050: font-size: larger;
7051: font-weight: bold;
7052: }
7053:
1.346 albertel 7054: td.LC_menubuttons_text {
1.911 bisitz 7055: color: $font;
1.346 albertel 7056: }
1.706 harmsja 7057:
1.346 albertel 7058: .LC_current_location {
7059: background: $tabbg;
7060: }
1.795 www 7061:
1.1075.2.134 raeburn 7062: td.LC_zero_height {
7063: line-height: 0;
7064: cellpadding: 0;
7065: }
7066:
1.938 bisitz 7067: table.LC_data_table {
1.347 albertel 7068: border: 1px solid #000000;
1.402 albertel 7069: border-collapse: separate;
1.426 albertel 7070: border-spacing: 1px;
1.610 albertel 7071: background: $pgbg;
1.347 albertel 7072: }
1.795 www 7073:
1.422 albertel 7074: .LC_data_table_dense {
7075: font-size: small;
7076: }
1.795 www 7077:
1.507 raeburn 7078: table.LC_nested_outer {
7079: border: 1px solid #000000;
1.589 raeburn 7080: border-collapse: collapse;
1.803 bisitz 7081: border-spacing: 0;
1.507 raeburn 7082: width: 100%;
7083: }
1.795 www 7084:
1.879 raeburn 7085: table.LC_innerpickbox,
1.507 raeburn 7086: table.LC_nested {
1.803 bisitz 7087: border: none;
1.589 raeburn 7088: border-collapse: collapse;
1.803 bisitz 7089: border-spacing: 0;
1.507 raeburn 7090: width: 100%;
7091: }
1.795 www 7092:
1.911 bisitz 7093: table.LC_data_table tr th,
7094: table.LC_calendar tr th,
1.879 raeburn 7095: table.LC_prior_tries tr th,
7096: table.LC_innerpickbox tr th {
1.349 albertel 7097: font-weight: bold;
7098: background-color: $data_table_head;
1.801 tempelho 7099: color:$fontmenu;
1.701 harmsja 7100: font-size:90%;
1.347 albertel 7101: }
1.795 www 7102:
1.879 raeburn 7103: table.LC_innerpickbox tr th,
7104: table.LC_innerpickbox tr td {
7105: vertical-align: top;
7106: }
7107:
1.711 raeburn 7108: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7109: background-color: #CCCCCC;
1.711 raeburn 7110: font-weight: bold;
7111: text-align: left;
7112: }
1.795 www 7113:
1.912 bisitz 7114: table.LC_data_table tr.LC_odd_row > td {
7115: background-color: $data_table_light;
7116: padding: 2px;
7117: vertical-align: top;
7118: }
7119:
1.809 bisitz 7120: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7121: background-color: $data_table_light;
1.912 bisitz 7122: vertical-align: top;
7123: }
7124:
7125: table.LC_data_table tr.LC_even_row > td {
7126: background-color: $data_table_dark;
1.425 albertel 7127: padding: 2px;
1.900 bisitz 7128: vertical-align: top;
1.347 albertel 7129: }
1.795 www 7130:
1.809 bisitz 7131: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7132: background-color: $data_table_dark;
1.900 bisitz 7133: vertical-align: top;
1.347 albertel 7134: }
1.795 www 7135:
1.425 albertel 7136: table.LC_data_table tr.LC_data_table_highlight td {
7137: background-color: $data_table_darker;
7138: }
1.795 www 7139:
1.639 raeburn 7140: table.LC_data_table tr td.LC_leftcol_header {
7141: background-color: $data_table_head;
7142: font-weight: bold;
7143: }
1.795 www 7144:
1.451 albertel 7145: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7146: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7147: font-weight: bold;
7148: font-style: italic;
7149: text-align: center;
7150: padding: 8px;
1.347 albertel 7151: }
1.795 www 7152:
1.1075.2.30 raeburn 7153: table.LC_data_table tr.LC_empty_row td,
7154: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7155: background-color: $sidebg;
7156: }
7157:
7158: table.LC_nested tr.LC_empty_row td {
7159: background-color: #FFFFFF;
7160: }
7161:
1.890 droeschl 7162: table.LC_caption {
7163: }
7164:
1.507 raeburn 7165: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7166: padding: 4ex
7167: }
1.795 www 7168:
1.507 raeburn 7169: table.LC_nested_outer tr th {
7170: font-weight: bold;
1.801 tempelho 7171: color:$fontmenu;
1.507 raeburn 7172: background-color: $data_table_head;
1.701 harmsja 7173: font-size: small;
1.507 raeburn 7174: border-bottom: 1px solid #000000;
7175: }
1.795 www 7176:
1.507 raeburn 7177: table.LC_nested_outer tr td.LC_subheader {
7178: background-color: $data_table_head;
7179: font-weight: bold;
7180: font-size: small;
7181: border-bottom: 1px solid #000000;
7182: text-align: right;
1.451 albertel 7183: }
1.795 www 7184:
1.507 raeburn 7185: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7186: background-color: #CCCCCC;
1.451 albertel 7187: font-weight: bold;
7188: font-size: small;
1.507 raeburn 7189: text-align: center;
7190: }
1.795 www 7191:
1.589 raeburn 7192: table.LC_nested tr.LC_info_row td.LC_left_item,
7193: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7194: text-align: left;
1.451 albertel 7195: }
1.795 www 7196:
1.507 raeburn 7197: table.LC_nested td {
1.735 bisitz 7198: background-color: #FFFFFF;
1.451 albertel 7199: font-size: small;
1.507 raeburn 7200: }
1.795 www 7201:
1.507 raeburn 7202: table.LC_nested_outer tr th.LC_right_item,
7203: table.LC_nested tr.LC_info_row td.LC_right_item,
7204: table.LC_nested tr.LC_odd_row td.LC_right_item,
7205: table.LC_nested tr td.LC_right_item {
1.451 albertel 7206: text-align: right;
7207: }
7208:
1.507 raeburn 7209: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7210: background-color: #EEEEEE;
1.451 albertel 7211: }
7212:
1.473 raeburn 7213: table.LC_createuser {
7214: }
7215:
7216: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7217: font-size: small;
1.473 raeburn 7218: }
7219:
7220: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7221: background-color: #CCCCCC;
1.473 raeburn 7222: font-weight: bold;
7223: text-align: center;
7224: }
7225:
1.349 albertel 7226: table.LC_calendar {
7227: border: 1px solid #000000;
7228: border-collapse: collapse;
1.917 raeburn 7229: width: 98%;
1.349 albertel 7230: }
1.795 www 7231:
1.349 albertel 7232: table.LC_calendar_pickdate {
7233: font-size: xx-small;
7234: }
1.795 www 7235:
1.349 albertel 7236: table.LC_calendar tr td {
7237: border: 1px solid #000000;
7238: vertical-align: top;
1.917 raeburn 7239: width: 14%;
1.349 albertel 7240: }
1.795 www 7241:
1.349 albertel 7242: table.LC_calendar tr td.LC_calendar_day_empty {
7243: background-color: $data_table_dark;
7244: }
1.795 www 7245:
1.779 bisitz 7246: table.LC_calendar tr td.LC_calendar_day_current {
7247: background-color: $data_table_highlight;
1.777 tempelho 7248: }
1.795 www 7249:
1.938 bisitz 7250: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7251: background-color: $mail_new;
7252: }
1.795 www 7253:
1.938 bisitz 7254: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7255: background-color: $mail_new_hover;
7256: }
1.795 www 7257:
1.938 bisitz 7258: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7259: background-color: $mail_read;
7260: }
1.795 www 7261:
1.938 bisitz 7262: /*
7263: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7264: background-color: $mail_read_hover;
7265: }
1.938 bisitz 7266: */
1.795 www 7267:
1.938 bisitz 7268: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7269: background-color: $mail_replied;
7270: }
1.795 www 7271:
1.938 bisitz 7272: /*
7273: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7274: background-color: $mail_replied_hover;
7275: }
1.938 bisitz 7276: */
1.795 www 7277:
1.938 bisitz 7278: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7279: background-color: $mail_other;
7280: }
1.795 www 7281:
1.938 bisitz 7282: /*
7283: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7284: background-color: $mail_other_hover;
7285: }
1.938 bisitz 7286: */
1.494 raeburn 7287:
1.777 tempelho 7288: table.LC_data_table tr > td.LC_browser_file,
7289: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7290: background: #AAEE77;
1.389 albertel 7291: }
1.795 www 7292:
1.777 tempelho 7293: table.LC_data_table tr > td.LC_browser_file_locked,
7294: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7295: background: #FFAA99;
1.387 albertel 7296: }
1.795 www 7297:
1.777 tempelho 7298: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7299: background: #888888;
1.779 bisitz 7300: }
1.795 www 7301:
1.777 tempelho 7302: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7303: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7304: background: #F8F866;
1.777 tempelho 7305: }
1.795 www 7306:
1.696 bisitz 7307: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7308: background: #E0E8FF;
1.387 albertel 7309: }
1.696 bisitz 7310:
1.707 bisitz 7311: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7312: /* background: #77FF77; */
1.707 bisitz 7313: }
1.795 www 7314:
1.707 bisitz 7315: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7316: border-right: 8px solid #FFFF77;
1.707 bisitz 7317: }
1.795 www 7318:
1.707 bisitz 7319: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7320: border-right: 8px solid #FFAA77;
1.707 bisitz 7321: }
1.795 www 7322:
1.707 bisitz 7323: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7324: border-right: 8px solid #FF7777;
1.707 bisitz 7325: }
1.795 www 7326:
1.707 bisitz 7327: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7328: border-right: 8px solid #AAFF77;
1.707 bisitz 7329: }
1.795 www 7330:
1.707 bisitz 7331: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7332: border-right: 8px solid #11CC55;
1.707 bisitz 7333: }
7334:
1.388 albertel 7335: span.LC_current_location {
1.701 harmsja 7336: font-size:larger;
1.388 albertel 7337: background: $pgbg;
7338: }
1.387 albertel 7339:
1.1029 www 7340: span.LC_current_nav_location {
7341: font-weight:bold;
7342: background: $sidebg;
7343: }
7344:
1.395 albertel 7345: span.LC_parm_menu_item {
7346: font-size: larger;
7347: }
1.795 www 7348:
1.395 albertel 7349: span.LC_parm_scope_all {
7350: color: red;
7351: }
1.795 www 7352:
1.395 albertel 7353: span.LC_parm_scope_folder {
7354: color: green;
7355: }
1.795 www 7356:
1.395 albertel 7357: span.LC_parm_scope_resource {
7358: color: orange;
7359: }
1.795 www 7360:
1.395 albertel 7361: span.LC_parm_part {
7362: color: blue;
7363: }
1.795 www 7364:
1.911 bisitz 7365: span.LC_parm_folder,
7366: span.LC_parm_symb {
1.395 albertel 7367: font-size: x-small;
7368: font-family: $mono;
7369: color: #AAAAAA;
7370: }
7371:
1.977 bisitz 7372: ul.LC_parm_parmlist li {
7373: display: inline-block;
7374: padding: 0.3em 0.8em;
7375: vertical-align: top;
7376: width: 150px;
7377: border-top:1px solid $lg_border_color;
7378: }
7379:
1.795 www 7380: td.LC_parm_overview_level_menu,
7381: td.LC_parm_overview_map_menu,
7382: td.LC_parm_overview_parm_selectors,
7383: td.LC_parm_overview_restrictions {
1.396 albertel 7384: border: 1px solid black;
7385: border-collapse: collapse;
7386: }
1.795 www 7387:
1.396 albertel 7388: table.LC_parm_overview_restrictions td {
7389: border-width: 1px 4px 1px 4px;
7390: border-style: solid;
7391: border-color: $pgbg;
7392: text-align: center;
7393: }
1.795 www 7394:
1.396 albertel 7395: table.LC_parm_overview_restrictions th {
7396: background: $tabbg;
7397: border-width: 1px 4px 1px 4px;
7398: border-style: solid;
7399: border-color: $pgbg;
7400: }
1.795 www 7401:
1.398 albertel 7402: table#LC_helpmenu {
1.803 bisitz 7403: border: none;
1.398 albertel 7404: height: 55px;
1.803 bisitz 7405: border-spacing: 0;
1.398 albertel 7406: }
7407:
7408: table#LC_helpmenu fieldset legend {
7409: font-size: larger;
7410: }
1.795 www 7411:
1.397 albertel 7412: table#LC_helpmenu_links {
7413: width: 100%;
7414: border: 1px solid black;
7415: background: $pgbg;
1.803 bisitz 7416: padding: 0;
1.397 albertel 7417: border-spacing: 1px;
7418: }
1.795 www 7419:
1.397 albertel 7420: table#LC_helpmenu_links tr td {
7421: padding: 1px;
7422: background: $tabbg;
1.399 albertel 7423: text-align: center;
7424: font-weight: bold;
1.397 albertel 7425: }
1.396 albertel 7426:
1.795 www 7427: table#LC_helpmenu_links a:link,
7428: table#LC_helpmenu_links a:visited,
1.397 albertel 7429: table#LC_helpmenu_links a:active {
7430: text-decoration: none;
7431: color: $font;
7432: }
1.795 www 7433:
1.397 albertel 7434: table#LC_helpmenu_links a:hover {
7435: text-decoration: underline;
7436: color: $vlink;
7437: }
1.396 albertel 7438:
1.417 albertel 7439: .LC_chrt_popup_exists {
7440: border: 1px solid #339933;
7441: margin: -1px;
7442: }
1.795 www 7443:
1.417 albertel 7444: .LC_chrt_popup_up {
7445: border: 1px solid yellow;
7446: margin: -1px;
7447: }
1.795 www 7448:
1.417 albertel 7449: .LC_chrt_popup {
7450: border: 1px solid #8888FF;
7451: background: #CCCCFF;
7452: }
1.795 www 7453:
1.421 albertel 7454: table.LC_pick_box {
7455: border-collapse: separate;
7456: background: white;
7457: border: 1px solid black;
7458: border-spacing: 1px;
7459: }
1.795 www 7460:
1.421 albertel 7461: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7462: background: $sidebg;
1.421 albertel 7463: font-weight: bold;
1.900 bisitz 7464: text-align: left;
1.740 bisitz 7465: vertical-align: top;
1.421 albertel 7466: width: 184px;
7467: padding: 8px;
7468: }
1.795 www 7469:
1.579 raeburn 7470: table.LC_pick_box td.LC_pick_box_value {
7471: text-align: left;
7472: padding: 8px;
7473: }
1.795 www 7474:
1.579 raeburn 7475: table.LC_pick_box td.LC_pick_box_select {
7476: text-align: left;
7477: padding: 8px;
7478: }
1.795 www 7479:
1.424 albertel 7480: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7481: padding: 0;
1.421 albertel 7482: height: 1px;
7483: background: black;
7484: }
1.795 www 7485:
1.421 albertel 7486: table.LC_pick_box td.LC_pick_box_submit {
7487: text-align: right;
7488: }
1.795 www 7489:
1.579 raeburn 7490: table.LC_pick_box td.LC_evenrow_value {
7491: text-align: left;
7492: padding: 8px;
7493: background-color: $data_table_light;
7494: }
1.795 www 7495:
1.579 raeburn 7496: table.LC_pick_box td.LC_oddrow_value {
7497: text-align: left;
7498: padding: 8px;
7499: background-color: $data_table_light;
7500: }
1.795 www 7501:
1.579 raeburn 7502: span.LC_helpform_receipt_cat {
7503: font-weight: bold;
7504: }
1.795 www 7505:
1.424 albertel 7506: table.LC_group_priv_box {
7507: background: white;
7508: border: 1px solid black;
7509: border-spacing: 1px;
7510: }
1.795 www 7511:
1.424 albertel 7512: table.LC_group_priv_box td.LC_pick_box_title {
7513: background: $tabbg;
7514: font-weight: bold;
7515: text-align: right;
7516: width: 184px;
7517: }
1.795 www 7518:
1.424 albertel 7519: table.LC_group_priv_box td.LC_groups_fixed {
7520: background: $data_table_light;
7521: text-align: center;
7522: }
1.795 www 7523:
1.424 albertel 7524: table.LC_group_priv_box td.LC_groups_optional {
7525: background: $data_table_dark;
7526: text-align: center;
7527: }
1.795 www 7528:
1.424 albertel 7529: table.LC_group_priv_box td.LC_groups_functionality {
7530: background: $data_table_darker;
7531: text-align: center;
7532: font-weight: bold;
7533: }
1.795 www 7534:
1.424 albertel 7535: table.LC_group_priv td {
7536: text-align: left;
1.803 bisitz 7537: padding: 0;
1.424 albertel 7538: }
7539:
7540: .LC_navbuttons {
7541: margin: 2ex 0ex 2ex 0ex;
7542: }
1.795 www 7543:
1.423 albertel 7544: .LC_topic_bar {
7545: font-weight: bold;
7546: background: $tabbg;
1.918 wenzelju 7547: margin: 1em 0em 1em 2em;
1.805 bisitz 7548: padding: 3px;
1.918 wenzelju 7549: font-size: 1.2em;
1.423 albertel 7550: }
1.795 www 7551:
1.423 albertel 7552: .LC_topic_bar span {
1.918 wenzelju 7553: left: 0.5em;
7554: position: absolute;
1.423 albertel 7555: vertical-align: middle;
1.918 wenzelju 7556: font-size: 1.2em;
1.423 albertel 7557: }
1.795 www 7558:
1.423 albertel 7559: table.LC_course_group_status {
7560: margin: 20px;
7561: }
1.795 www 7562:
1.423 albertel 7563: table.LC_status_selector td {
7564: vertical-align: top;
7565: text-align: center;
1.424 albertel 7566: padding: 4px;
7567: }
1.795 www 7568:
1.599 albertel 7569: div.LC_feedback_link {
1.616 albertel 7570: clear: both;
1.829 kalberla 7571: background: $sidebg;
1.779 bisitz 7572: width: 100%;
1.829 kalberla 7573: padding-bottom: 10px;
7574: border: 1px $tabbg solid;
1.833 kalberla 7575: height: 22px;
7576: line-height: 22px;
7577: padding-top: 5px;
7578: }
7579:
7580: div.LC_feedback_link img {
7581: height: 22px;
1.867 kalberla 7582: vertical-align:middle;
1.829 kalberla 7583: }
7584:
1.911 bisitz 7585: div.LC_feedback_link a {
1.829 kalberla 7586: text-decoration: none;
1.489 raeburn 7587: }
1.795 www 7588:
1.867 kalberla 7589: div.LC_comblock {
1.911 bisitz 7590: display:inline;
1.867 kalberla 7591: color:$font;
7592: font-size:90%;
7593: }
7594:
7595: div.LC_feedback_link div.LC_comblock {
7596: padding-left:5px;
7597: }
7598:
7599: div.LC_feedback_link div.LC_comblock a {
7600: color:$font;
7601: }
7602:
1.489 raeburn 7603: span.LC_feedback_link {
1.858 bisitz 7604: /* background: $feedback_link_bg; */
1.599 albertel 7605: font-size: larger;
7606: }
1.795 www 7607:
1.599 albertel 7608: span.LC_message_link {
1.858 bisitz 7609: /* background: $feedback_link_bg; */
1.599 albertel 7610: font-size: larger;
7611: position: absolute;
7612: right: 1em;
1.489 raeburn 7613: }
1.421 albertel 7614:
1.515 albertel 7615: table.LC_prior_tries {
1.524 albertel 7616: border: 1px solid #000000;
7617: border-collapse: separate;
7618: border-spacing: 1px;
1.515 albertel 7619: }
1.523 albertel 7620:
1.515 albertel 7621: table.LC_prior_tries td {
1.524 albertel 7622: padding: 2px;
1.515 albertel 7623: }
1.523 albertel 7624:
7625: .LC_answer_correct {
1.795 www 7626: background: lightgreen;
7627: color: darkgreen;
7628: padding: 6px;
1.523 albertel 7629: }
1.795 www 7630:
1.523 albertel 7631: .LC_answer_charged_try {
1.797 www 7632: background: #FFAAAA;
1.795 www 7633: color: darkred;
7634: padding: 6px;
1.523 albertel 7635: }
1.795 www 7636:
1.779 bisitz 7637: .LC_answer_not_charged_try,
1.523 albertel 7638: .LC_answer_no_grade,
7639: .LC_answer_late {
1.795 www 7640: background: lightyellow;
1.523 albertel 7641: color: black;
1.795 www 7642: padding: 6px;
1.523 albertel 7643: }
1.795 www 7644:
1.523 albertel 7645: .LC_answer_previous {
1.795 www 7646: background: lightblue;
7647: color: darkblue;
7648: padding: 6px;
1.523 albertel 7649: }
1.795 www 7650:
1.779 bisitz 7651: .LC_answer_no_message {
1.777 tempelho 7652: background: #FFFFFF;
7653: color: black;
1.795 www 7654: padding: 6px;
1.779 bisitz 7655: }
1.795 www 7656:
1.1075.2.140 raeburn 7657: .LC_answer_unknown,
7658: .LC_answer_warning {
1.779 bisitz 7659: background: orange;
7660: color: black;
1.795 www 7661: padding: 6px;
1.777 tempelho 7662: }
1.795 www 7663:
1.529 albertel 7664: span.LC_prior_numerical,
7665: span.LC_prior_string,
7666: span.LC_prior_custom,
7667: span.LC_prior_reaction,
7668: span.LC_prior_math {
1.925 bisitz 7669: font-family: $mono;
1.523 albertel 7670: white-space: pre;
7671: }
7672:
1.525 albertel 7673: span.LC_prior_string {
1.925 bisitz 7674: font-family: $mono;
1.525 albertel 7675: white-space: pre;
7676: }
7677:
1.523 albertel 7678: table.LC_prior_option {
7679: width: 100%;
7680: border-collapse: collapse;
7681: }
1.795 www 7682:
1.911 bisitz 7683: table.LC_prior_rank,
1.795 www 7684: table.LC_prior_match {
1.528 albertel 7685: border-collapse: collapse;
7686: }
1.795 www 7687:
1.528 albertel 7688: table.LC_prior_option tr td,
7689: table.LC_prior_rank tr td,
7690: table.LC_prior_match tr td {
1.524 albertel 7691: border: 1px solid #000000;
1.515 albertel 7692: }
7693:
1.855 bisitz 7694: .LC_nobreak {
1.544 albertel 7695: white-space: nowrap;
1.519 raeburn 7696: }
7697:
1.576 raeburn 7698: span.LC_cusr_emph {
7699: font-style: italic;
7700: }
7701:
1.633 raeburn 7702: span.LC_cusr_subheading {
7703: font-weight: normal;
7704: font-size: 85%;
7705: }
7706:
1.861 bisitz 7707: div.LC_docs_entry_move {
1.859 bisitz 7708: border: 1px solid #BBBBBB;
1.545 albertel 7709: background: #DDDDDD;
1.861 bisitz 7710: width: 22px;
1.859 bisitz 7711: padding: 1px;
7712: margin: 0;
1.545 albertel 7713: }
7714:
1.861 bisitz 7715: table.LC_data_table tr > td.LC_docs_entry_commands,
7716: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7717: font-size: x-small;
7718: }
1.795 www 7719:
1.861 bisitz 7720: .LC_docs_entry_parameter {
7721: white-space: nowrap;
7722: }
7723:
1.544 albertel 7724: .LC_docs_copy {
1.545 albertel 7725: color: #000099;
1.544 albertel 7726: }
1.795 www 7727:
1.544 albertel 7728: .LC_docs_cut {
1.545 albertel 7729: color: #550044;
1.544 albertel 7730: }
1.795 www 7731:
1.544 albertel 7732: .LC_docs_rename {
1.545 albertel 7733: color: #009900;
1.544 albertel 7734: }
1.795 www 7735:
1.544 albertel 7736: .LC_docs_remove {
1.545 albertel 7737: color: #990000;
7738: }
7739:
1.1075.2.134 raeburn 7740: .LC_domprefs_email,
1.547 albertel 7741: .LC_docs_reinit_warn,
7742: .LC_docs_ext_edit {
7743: font-size: x-small;
7744: }
7745:
1.545 albertel 7746: table.LC_docs_adddocs td,
7747: table.LC_docs_adddocs th {
7748: border: 1px solid #BBBBBB;
7749: padding: 4px;
7750: background: #DDDDDD;
1.543 albertel 7751: }
7752:
1.584 albertel 7753: table.LC_sty_begin {
7754: background: #BBFFBB;
7755: }
1.795 www 7756:
1.584 albertel 7757: table.LC_sty_end {
7758: background: #FFBBBB;
7759: }
7760:
1.589 raeburn 7761: table.LC_double_column {
1.803 bisitz 7762: border-width: 0;
1.589 raeburn 7763: border-collapse: collapse;
7764: width: 100%;
7765: padding: 2px;
7766: }
7767:
7768: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7769: top: 2px;
1.589 raeburn 7770: left: 2px;
7771: width: 47%;
7772: vertical-align: top;
7773: }
7774:
7775: table.LC_double_column tr td.LC_right_col {
7776: top: 2px;
1.779 bisitz 7777: right: 2px;
1.589 raeburn 7778: width: 47%;
7779: vertical-align: top;
7780: }
7781:
1.591 raeburn 7782: div.LC_left_float {
7783: float: left;
7784: padding-right: 5%;
1.597 albertel 7785: padding-bottom: 4px;
1.591 raeburn 7786: }
7787:
7788: div.LC_clear_float_header {
1.597 albertel 7789: padding-bottom: 2px;
1.591 raeburn 7790: }
7791:
7792: div.LC_clear_float_footer {
1.597 albertel 7793: padding-top: 10px;
1.591 raeburn 7794: clear: both;
7795: }
7796:
1.597 albertel 7797: div.LC_grade_show_user {
1.941 bisitz 7798: /* border-left: 5px solid $sidebg; */
7799: border-top: 5px solid #000000;
7800: margin: 50px 0 0 0;
1.936 bisitz 7801: padding: 15px 0 5px 10px;
1.597 albertel 7802: }
1.795 www 7803:
1.936 bisitz 7804: div.LC_grade_show_user_odd_row {
1.941 bisitz 7805: /* border-left: 5px solid #000000; */
7806: }
7807:
7808: div.LC_grade_show_user div.LC_Box {
7809: margin-right: 50px;
1.597 albertel 7810: }
7811:
7812: div.LC_grade_submissions,
7813: div.LC_grade_message_center,
1.936 bisitz 7814: div.LC_grade_info_links {
1.597 albertel 7815: margin: 5px;
7816: width: 99%;
7817: background: #FFFFFF;
7818: }
1.795 www 7819:
1.597 albertel 7820: div.LC_grade_submissions_header,
1.936 bisitz 7821: div.LC_grade_message_center_header {
1.705 tempelho 7822: font-weight: bold;
7823: font-size: large;
1.597 albertel 7824: }
1.795 www 7825:
1.597 albertel 7826: div.LC_grade_submissions_body,
1.936 bisitz 7827: div.LC_grade_message_center_body {
1.597 albertel 7828: border: 1px solid black;
7829: width: 99%;
7830: background: #FFFFFF;
7831: }
1.795 www 7832:
1.613 albertel 7833: table.LC_scantron_action {
7834: width: 100%;
7835: }
1.795 www 7836:
1.613 albertel 7837: table.LC_scantron_action tr th {
1.698 harmsja 7838: font-weight:bold;
7839: font-style:normal;
1.613 albertel 7840: }
1.795 www 7841:
1.779 bisitz 7842: .LC_edit_problem_header,
1.614 albertel 7843: div.LC_edit_problem_footer {
1.705 tempelho 7844: font-weight: normal;
7845: font-size: medium;
1.602 albertel 7846: margin: 2px;
1.1060 bisitz 7847: background-color: $sidebg;
1.600 albertel 7848: }
1.795 www 7849:
1.600 albertel 7850: div.LC_edit_problem_header,
1.602 albertel 7851: div.LC_edit_problem_header div,
1.614 albertel 7852: div.LC_edit_problem_footer,
7853: div.LC_edit_problem_footer div,
1.602 albertel 7854: div.LC_edit_problem_editxml_header,
7855: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7856: z-index: 100;
1.600 albertel 7857: }
1.795 www 7858:
1.600 albertel 7859: div.LC_edit_problem_header_title {
1.705 tempelho 7860: font-weight: bold;
7861: font-size: larger;
1.602 albertel 7862: background: $tabbg;
7863: padding: 3px;
1.1060 bisitz 7864: margin: 0 0 5px 0;
1.602 albertel 7865: }
1.795 www 7866:
1.602 albertel 7867: table.LC_edit_problem_header_title {
7868: width: 100%;
1.600 albertel 7869: background: $tabbg;
1.602 albertel 7870: }
7871:
1.1075.2.112 raeburn 7872: div.LC_edit_actionbar {
7873: background-color: $sidebg;
7874: margin: 0;
7875: padding: 0;
7876: line-height: 200%;
1.602 albertel 7877: }
1.795 www 7878:
1.1075.2.112 raeburn 7879: div.LC_edit_actionbar div{
7880: padding: 0;
7881: margin: 0;
7882: display: inline-block;
1.600 albertel 7883: }
1.795 www 7884:
1.1075.2.34 raeburn 7885: .LC_edit_opt {
7886: padding-left: 1em;
7887: white-space: nowrap;
7888: }
7889:
1.1075.2.57 raeburn 7890: .LC_edit_problem_latexhelper{
7891: text-align: right;
7892: }
7893:
7894: #LC_edit_problem_colorful div{
7895: margin-left: 40px;
7896: }
7897:
1.1075.2.112 raeburn 7898: #LC_edit_problem_codemirror div{
7899: margin-left: 0px;
7900: }
7901:
1.911 bisitz 7902: img.stift {
1.803 bisitz 7903: border-width: 0;
7904: vertical-align: middle;
1.677 riegler 7905: }
1.680 riegler 7906:
1.923 bisitz 7907: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7908: vertical-align: top;
1.777 tempelho 7909: }
1.795 www 7910:
1.716 raeburn 7911: div.LC_createcourse {
1.911 bisitz 7912: margin: 10px 10px 10px 10px;
1.716 raeburn 7913: }
7914:
1.917 raeburn 7915: .LC_dccid {
1.1075.2.38 raeburn 7916: float: right;
1.917 raeburn 7917: margin: 0.2em 0 0 0;
7918: padding: 0;
7919: font-size: 90%;
7920: display:none;
7921: }
7922:
1.897 wenzelju 7923: ol.LC_primary_menu a:hover,
1.721 harmsja 7924: ol#LC_MenuBreadcrumbs a:hover,
7925: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7926: ul#LC_secondary_menu a:hover,
1.721 harmsja 7927: .LC_FormSectionClearButton input:hover
1.795 www 7928: ul.LC_TabContent li:hover a {
1.952 onken 7929: color:$button_hover;
1.911 bisitz 7930: text-decoration:none;
1.693 droeschl 7931: }
7932:
1.779 bisitz 7933: h1 {
1.911 bisitz 7934: padding: 0;
7935: line-height:130%;
1.693 droeschl 7936: }
1.698 harmsja 7937:
1.911 bisitz 7938: h2,
7939: h3,
7940: h4,
7941: h5,
7942: h6 {
7943: margin: 5px 0 5px 0;
7944: padding: 0;
7945: line-height:130%;
1.693 droeschl 7946: }
1.795 www 7947:
7948: .LC_hcell {
1.911 bisitz 7949: padding:3px 15px 3px 15px;
7950: margin: 0;
7951: background-color:$tabbg;
7952: color:$fontmenu;
7953: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7954: }
1.795 www 7955:
1.840 bisitz 7956: .LC_Box > .LC_hcell {
1.911 bisitz 7957: margin: 0 -10px 10px -10px;
1.835 bisitz 7958: }
7959:
1.721 harmsja 7960: .LC_noBorder {
1.911 bisitz 7961: border: 0;
1.698 harmsja 7962: }
1.693 droeschl 7963:
1.721 harmsja 7964: .LC_FormSectionClearButton input {
1.911 bisitz 7965: background-color:transparent;
7966: border: none;
7967: cursor:pointer;
7968: text-decoration:underline;
1.693 droeschl 7969: }
1.763 bisitz 7970:
7971: .LC_help_open_topic {
1.911 bisitz 7972: color: #FFFFFF;
7973: background-color: #EEEEFF;
7974: margin: 1px;
7975: padding: 4px;
7976: border: 1px solid #000033;
7977: white-space: nowrap;
7978: /* vertical-align: middle; */
1.759 neumanie 7979: }
1.693 droeschl 7980:
1.911 bisitz 7981: dl,
7982: ul,
7983: div,
7984: fieldset {
7985: margin: 10px 10px 10px 0;
7986: /* overflow: hidden; */
1.693 droeschl 7987: }
1.795 www 7988:
1.1075.2.161. .18(raeb 7989:-23): fieldset#LC_selectuser {
7990:-23): margin: 0;
7991:-23): padding: 0;
7992:-23): }
7993:-23):
1.1075.2.90 raeburn 7994: article.geogebraweb div {
7995: margin: 0;
7996: }
7997:
1.838 bisitz 7998: fieldset > legend {
1.911 bisitz 7999: font-weight: bold;
8000: padding: 0 5px 0 5px;
1.838 bisitz 8001: }
8002:
1.813 bisitz 8003: #LC_nav_bar {
1.911 bisitz 8004: float: left;
1.995 raeburn 8005: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8006: margin: 0 0 2px 0;
1.807 droeschl 8007: }
8008:
1.916 droeschl 8009: #LC_realm {
8010: margin: 0.2em 0 0 0;
8011: padding: 0;
8012: font-weight: bold;
8013: text-align: center;
1.995 raeburn 8014: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8015: }
8016:
1.911 bisitz 8017: #LC_nav_bar em {
8018: font-weight: bold;
8019: font-style: normal;
1.807 droeschl 8020: }
8021:
1.897 wenzelju 8022: ol.LC_primary_menu {
1.934 droeschl 8023: margin: 0;
1.1075.2.2 raeburn 8024: padding: 0;
1.807 droeschl 8025: }
8026:
1.852 droeschl 8027: ol#LC_PathBreadcrumbs {
1.911 bisitz 8028: margin: 0;
1.693 droeschl 8029: }
8030:
1.897 wenzelju 8031: ol.LC_primary_menu li {
1.1075.2.2 raeburn 8032: color: RGB(80, 80, 80);
8033: vertical-align: middle;
8034: text-align: left;
8035: list-style: none;
1.1075.2.112 raeburn 8036: position: relative;
1.1075.2.2 raeburn 8037: float: left;
1.1075.2.112 raeburn 8038: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8039: line-height: 1.5em;
1.1075.2.2 raeburn 8040: }
8041:
1.1075.2.113 raeburn 8042: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 8043: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 8044: display: block;
8045: margin: 0;
8046: padding: 0 5px 0 10px;
8047: text-decoration: none;
8048: }
8049:
1.1075.2.112 raeburn 8050: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8051: display: inline-block;
8052: width: 95%;
8053: text-align: left;
8054: }
8055:
8056: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8057: display: inline-block;
8058: width: 5%;
8059: float: right;
8060: text-align: right;
8061: font-size: 70%;
8062: }
8063:
8064: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 8065: display: none;
1.1075.2.112 raeburn 8066: width: 15em;
1.1075.2.2 raeburn 8067: background-color: $data_table_light;
1.1075.2.112 raeburn 8068: position: absolute;
8069: top: 100%;
8070: }
8071:
8072: ol.LC_primary_menu ul ul {
8073: left: 100%;
8074: top: 0;
1.1075.2.2 raeburn 8075: }
8076:
1.1075.2.112 raeburn 8077: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 8078: display: block;
8079: position: absolute;
8080: margin: 0;
8081: padding: 0;
1.1075.2.5 raeburn 8082: z-index: 2;
1.1075.2.2 raeburn 8083: }
8084:
8085: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 8086: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 8087: font-size: 90%;
1.911 bisitz 8088: vertical-align: top;
1.1075.2.2 raeburn 8089: float: none;
1.1075.2.5 raeburn 8090: border-left: 1px solid black;
8091: border-right: 1px solid black;
1.1075.2.112 raeburn 8092: /* A dark bottom border to visualize different menu options;
8093: overwritten in the create_submenu routine for the last border-bottom of the menu */
8094: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 8095: }
8096:
1.1075.2.112 raeburn 8097: ol.LC_primary_menu li li p:hover {
8098: color:$button_hover;
8099: text-decoration:none;
8100: background-color:$data_table_dark;
1.1075.2.2 raeburn 8101: }
8102:
8103: ol.LC_primary_menu li li a:hover {
8104: color:$button_hover;
8105: background-color:$data_table_dark;
1.693 droeschl 8106: }
8107:
1.1075.2.112 raeburn 8108: /* Font-size equal to the size of the predecessors*/
8109: ol.LC_primary_menu li:hover li li {
8110: font-size: 100%;
8111: }
8112:
1.897 wenzelju 8113: ol.LC_primary_menu li img {
1.911 bisitz 8114: vertical-align: bottom;
1.934 droeschl 8115: height: 1.1em;
1.1075.2.3 raeburn 8116: margin: 0.2em 0 0 0;
1.693 droeschl 8117: }
8118:
1.897 wenzelju 8119: ol.LC_primary_menu a {
1.911 bisitz 8120: color: RGB(80, 80, 80);
8121: text-decoration: none;
1.693 droeschl 8122: }
1.795 www 8123:
1.949 droeschl 8124: ol.LC_primary_menu a.LC_new_message {
8125: font-weight:bold;
8126: color: darkred;
8127: }
8128:
1.975 raeburn 8129: ol.LC_docs_parameters {
8130: margin-left: 0;
8131: padding: 0;
8132: list-style: none;
8133: }
8134:
8135: ol.LC_docs_parameters li {
8136: margin: 0;
8137: padding-right: 20px;
8138: display: inline;
8139: }
8140:
1.976 raeburn 8141: ol.LC_docs_parameters li:before {
8142: content: "\\002022 \\0020";
8143: }
8144:
8145: li.LC_docs_parameters_title {
8146: font-weight: bold;
8147: }
8148:
8149: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8150: content: "";
8151: }
8152:
1.897 wenzelju 8153: ul#LC_secondary_menu {
1.1075.2.23 raeburn 8154: clear: right;
1.911 bisitz 8155: color: $fontmenu;
8156: background: $tabbg;
8157: list-style: none;
8158: padding: 0;
8159: margin: 0;
8160: width: 100%;
1.995 raeburn 8161: text-align: left;
1.1075.2.4 raeburn 8162: float: left;
1.808 droeschl 8163: }
8164:
1.897 wenzelju 8165: ul#LC_secondary_menu li {
1.911 bisitz 8166: font-weight: bold;
8167: line-height: 1.8em;
8168: border-right: 1px solid black;
1.1075.2.4 raeburn 8169: float: left;
8170: }
8171:
8172: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8173: background-color: $data_table_light;
8174: }
8175:
8176: ul#LC_secondary_menu li a {
8177: padding: 0 0.8em;
8178: }
8179:
8180: ul#LC_secondary_menu li ul {
8181: display: none;
8182: }
8183:
8184: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8185: display: block;
8186: position: absolute;
8187: margin: 0;
8188: padding: 0;
8189: list-style:none;
8190: float: none;
8191: background-color: $data_table_light;
1.1075.2.5 raeburn 8192: z-index: 2;
1.1075.2.10 raeburn 8193: margin-left: -1px;
1.1075.2.4 raeburn 8194: }
8195:
8196: ul#LC_secondary_menu li ul li {
8197: font-size: 90%;
8198: vertical-align: top;
8199: border-left: 1px solid black;
8200: border-right: 1px solid black;
1.1075.2.33 raeburn 8201: background-color: $data_table_light;
1.1075.2.4 raeburn 8202: list-style:none;
8203: float: none;
8204: }
8205:
8206: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8207: background-color: $data_table_dark;
1.807 droeschl 8208: }
8209:
1.847 tempelho 8210: ul.LC_TabContent {
1.911 bisitz 8211: display:block;
8212: background: $sidebg;
8213: border-bottom: solid 1px $lg_border_color;
8214: list-style:none;
1.1020 raeburn 8215: margin: -1px -10px 0 -10px;
1.911 bisitz 8216: padding: 0;
1.693 droeschl 8217: }
8218:
1.795 www 8219: ul.LC_TabContent li,
8220: ul.LC_TabContentBigger li {
1.911 bisitz 8221: float:left;
1.741 harmsja 8222: }
1.795 www 8223:
1.897 wenzelju 8224: ul#LC_secondary_menu li a {
1.911 bisitz 8225: color: $fontmenu;
8226: text-decoration: none;
1.693 droeschl 8227: }
1.795 www 8228:
1.721 harmsja 8229: ul.LC_TabContent {
1.952 onken 8230: min-height:20px;
1.721 harmsja 8231: }
1.795 www 8232:
8233: ul.LC_TabContent li {
1.911 bisitz 8234: vertical-align:middle;
1.959 onken 8235: padding: 0 16px 0 10px;
1.911 bisitz 8236: background-color:$tabbg;
8237: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8238: border-left: solid 1px $font;
1.721 harmsja 8239: }
1.795 www 8240:
1.847 tempelho 8241: ul.LC_TabContent .right {
1.911 bisitz 8242: float:right;
1.847 tempelho 8243: }
8244:
1.911 bisitz 8245: ul.LC_TabContent li a,
8246: ul.LC_TabContent li {
8247: color:rgb(47,47,47);
8248: text-decoration:none;
8249: font-size:95%;
8250: font-weight:bold;
1.952 onken 8251: min-height:20px;
8252: }
8253:
1.959 onken 8254: ul.LC_TabContent li a:hover,
8255: ul.LC_TabContent li a:focus {
1.952 onken 8256: color: $button_hover;
1.959 onken 8257: background:none;
8258: outline:none;
1.952 onken 8259: }
8260:
8261: ul.LC_TabContent li:hover {
8262: color: $button_hover;
8263: cursor:pointer;
1.721 harmsja 8264: }
1.795 www 8265:
1.911 bisitz 8266: ul.LC_TabContent li.active {
1.952 onken 8267: color: $font;
1.911 bisitz 8268: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8269: border-bottom:solid 1px #FFFFFF;
8270: cursor: default;
1.744 ehlerst 8271: }
1.795 www 8272:
1.959 onken 8273: ul.LC_TabContent li.active a {
8274: color:$font;
8275: background:#FFFFFF;
8276: outline: none;
8277: }
1.1047 raeburn 8278:
8279: ul.LC_TabContent li.goback {
8280: float: left;
8281: border-left: none;
8282: }
8283:
1.870 tempelho 8284: #maincoursedoc {
1.911 bisitz 8285: clear:both;
1.870 tempelho 8286: }
8287:
8288: ul.LC_TabContentBigger {
1.911 bisitz 8289: display:block;
8290: list-style:none;
8291: padding: 0;
1.870 tempelho 8292: }
8293:
1.795 www 8294: ul.LC_TabContentBigger li {
1.911 bisitz 8295: vertical-align:bottom;
8296: height: 30px;
8297: font-size:110%;
8298: font-weight:bold;
8299: color: #737373;
1.841 tempelho 8300: }
8301:
1.957 onken 8302: ul.LC_TabContentBigger li.active {
8303: position: relative;
8304: top: 1px;
8305: }
8306:
1.870 tempelho 8307: ul.LC_TabContentBigger li a {
1.911 bisitz 8308: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8309: height: 30px;
8310: line-height: 30px;
8311: text-align: center;
8312: display: block;
8313: text-decoration: none;
1.958 onken 8314: outline: none;
1.741 harmsja 8315: }
1.795 www 8316:
1.870 tempelho 8317: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8318: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8319: color:$font;
1.744 ehlerst 8320: }
1.795 www 8321:
1.870 tempelho 8322: ul.LC_TabContentBigger li b {
1.911 bisitz 8323: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8324: display: block;
8325: float: left;
8326: padding: 0 30px;
1.957 onken 8327: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8328: }
8329:
1.956 onken 8330: ul.LC_TabContentBigger li:hover b {
8331: color:$button_hover;
8332: }
8333:
1.870 tempelho 8334: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8335: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8336: color:$font;
1.957 onken 8337: border: 0;
1.741 harmsja 8338: }
1.693 droeschl 8339:
1.870 tempelho 8340:
1.862 bisitz 8341: ul.LC_CourseBreadcrumbs {
8342: background: $sidebg;
1.1020 raeburn 8343: height: 2em;
1.862 bisitz 8344: padding-left: 10px;
1.1020 raeburn 8345: margin: 0;
1.862 bisitz 8346: list-style-position: inside;
8347: }
8348:
1.911 bisitz 8349: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8350: ol#LC_PathBreadcrumbs {
1.911 bisitz 8351: padding-left: 10px;
8352: margin: 0;
1.933 droeschl 8353: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8354: }
8355:
1.911 bisitz 8356: ol#LC_MenuBreadcrumbs li,
8357: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8358: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8359: display: inline;
1.933 droeschl 8360: white-space: normal;
1.693 droeschl 8361: }
8362:
1.823 bisitz 8363: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8364: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8365: text-decoration: none;
8366: font-size:90%;
1.693 droeschl 8367: }
1.795 www 8368:
1.969 droeschl 8369: ol#LC_MenuBreadcrumbs h1 {
8370: display: inline;
8371: font-size: 90%;
8372: line-height: 2.5em;
8373: margin: 0;
8374: padding: 0;
8375: }
8376:
1.795 www 8377: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8378: text-decoration:none;
8379: font-size:100%;
8380: font-weight:bold;
1.693 droeschl 8381: }
1.795 www 8382:
1.840 bisitz 8383: .LC_Box {
1.911 bisitz 8384: border: solid 1px $lg_border_color;
8385: padding: 0 10px 10px 10px;
1.746 neumanie 8386: }
1.795 www 8387:
1.1020 raeburn 8388: .LC_DocsBox {
8389: border: solid 1px $lg_border_color;
8390: padding: 0 0 10px 10px;
8391: }
8392:
1.795 www 8393: .LC_AboutMe_Image {
1.911 bisitz 8394: float:left;
8395: margin-right:10px;
1.747 neumanie 8396: }
1.795 www 8397:
8398: .LC_Clear_AboutMe_Image {
1.911 bisitz 8399: clear:left;
1.747 neumanie 8400: }
1.795 www 8401:
1.721 harmsja 8402: dl.LC_ListStyleClean dt {
1.911 bisitz 8403: padding-right: 5px;
8404: display: table-header-group;
1.693 droeschl 8405: }
8406:
1.721 harmsja 8407: dl.LC_ListStyleClean dd {
1.911 bisitz 8408: display: table-row;
1.693 droeschl 8409: }
8410:
1.721 harmsja 8411: .LC_ListStyleClean,
8412: .LC_ListStyleSimple,
8413: .LC_ListStyleNormal,
1.795 www 8414: .LC_ListStyleSpecial {
1.911 bisitz 8415: /* display:block; */
8416: list-style-position: inside;
8417: list-style-type: none;
8418: overflow: hidden;
8419: padding: 0;
1.693 droeschl 8420: }
8421:
1.721 harmsja 8422: .LC_ListStyleSimple li,
8423: .LC_ListStyleSimple dd,
8424: .LC_ListStyleNormal li,
8425: .LC_ListStyleNormal dd,
8426: .LC_ListStyleSpecial li,
1.795 www 8427: .LC_ListStyleSpecial dd {
1.911 bisitz 8428: margin: 0;
8429: padding: 5px 5px 5px 10px;
8430: clear: both;
1.693 droeschl 8431: }
8432:
1.721 harmsja 8433: .LC_ListStyleClean li,
8434: .LC_ListStyleClean dd {
1.911 bisitz 8435: padding-top: 0;
8436: padding-bottom: 0;
1.693 droeschl 8437: }
8438:
1.721 harmsja 8439: .LC_ListStyleSimple dd,
1.795 www 8440: .LC_ListStyleSimple li {
1.911 bisitz 8441: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8442: }
8443:
1.721 harmsja 8444: .LC_ListStyleSpecial li,
8445: .LC_ListStyleSpecial dd {
1.911 bisitz 8446: list-style-type: none;
8447: background-color: RGB(220, 220, 220);
8448: margin-bottom: 4px;
1.693 droeschl 8449: }
8450:
1.721 harmsja 8451: table.LC_SimpleTable {
1.911 bisitz 8452: margin:5px;
8453: border:solid 1px $lg_border_color;
1.795 www 8454: }
1.693 droeschl 8455:
1.721 harmsja 8456: table.LC_SimpleTable tr {
1.911 bisitz 8457: padding: 0;
8458: border:solid 1px $lg_border_color;
1.693 droeschl 8459: }
1.795 www 8460:
8461: table.LC_SimpleTable thead {
1.911 bisitz 8462: background:rgb(220,220,220);
1.693 droeschl 8463: }
8464:
1.721 harmsja 8465: div.LC_columnSection {
1.911 bisitz 8466: display: block;
8467: clear: both;
8468: overflow: hidden;
8469: margin: 0;
1.693 droeschl 8470: }
8471:
1.721 harmsja 8472: div.LC_columnSection>* {
1.911 bisitz 8473: float: left;
8474: margin: 10px 20px 10px 0;
8475: overflow:hidden;
1.693 droeschl 8476: }
1.721 harmsja 8477:
1.795 www 8478: table em {
1.911 bisitz 8479: font-weight: bold;
8480: font-style: normal;
1.748 schulted 8481: }
1.795 www 8482:
1.779 bisitz 8483: table.LC_tableBrowseRes,
1.795 www 8484: table.LC_tableOfContent {
1.911 bisitz 8485: border:none;
8486: border-spacing: 1px;
8487: padding: 3px;
8488: background-color: #FFFFFF;
8489: font-size: 90%;
1.753 droeschl 8490: }
1.789 droeschl 8491:
1.911 bisitz 8492: table.LC_tableOfContent {
8493: border-collapse: collapse;
1.789 droeschl 8494: }
8495:
1.771 droeschl 8496: table.LC_tableBrowseRes a,
1.768 schulted 8497: table.LC_tableOfContent a {
1.911 bisitz 8498: background-color: transparent;
8499: text-decoration: none;
1.753 droeschl 8500: }
8501:
1.795 www 8502: table.LC_tableOfContent img {
1.911 bisitz 8503: border: none;
8504: height: 1.3em;
8505: vertical-align: text-bottom;
8506: margin-right: 0.3em;
1.753 droeschl 8507: }
1.757 schulted 8508:
1.795 www 8509: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8510: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8511: }
8512:
1.795 www 8513: a#LC_content_toolbar_everything {
1.911 bisitz 8514: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8515: }
8516:
1.795 www 8517: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8518: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8519: }
8520:
1.795 www 8521: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8522: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8523: }
8524:
1.795 www 8525: a#LC_content_toolbar_changefolder {
1.911 bisitz 8526: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8527: }
8528:
1.795 www 8529: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8530: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8531: }
8532:
1.1043 raeburn 8533: a#LC_content_toolbar_edittoplevel {
8534: background-image:url(/res/adm/pages/edittoplevel.gif);
8535: }
8536:
1.1075.2.161. .12(raeb 8537:-23): a#LC_content_toolbar_printout {
8538:-23): background-image:url(/res/adm/pages/printout.gif);
8539:-23): }
8540:-23):
1.795 www 8541: ul#LC_toolbar li a:hover {
1.911 bisitz 8542: background-position: bottom center;
1.757 schulted 8543: }
8544:
1.795 www 8545: ul#LC_toolbar {
1.911 bisitz 8546: padding: 0;
8547: margin: 2px;
8548: list-style:none;
8549: position:relative;
8550: background-color:white;
1.1075.2.9 raeburn 8551: overflow: auto;
1.757 schulted 8552: }
8553:
1.795 www 8554: ul#LC_toolbar li {
1.911 bisitz 8555: border:1px solid white;
8556: padding: 0;
8557: margin: 0;
8558: float: left;
8559: display:inline;
8560: vertical-align:middle;
1.1075.2.9 raeburn 8561: white-space: nowrap;
1.911 bisitz 8562: }
1.757 schulted 8563:
1.783 amueller 8564:
1.795 www 8565: a.LC_toolbarItem {
1.911 bisitz 8566: display:block;
8567: padding: 0;
8568: margin: 0;
8569: height: 32px;
8570: width: 32px;
8571: color:white;
8572: border: none;
8573: background-repeat:no-repeat;
8574: background-color:transparent;
1.757 schulted 8575: }
8576:
1.915 droeschl 8577: ul.LC_funclist {
8578: margin: 0;
8579: padding: 0.5em 1em 0.5em 0;
8580: }
8581:
1.933 droeschl 8582: ul.LC_funclist > li:first-child {
8583: font-weight:bold;
8584: margin-left:0.8em;
8585: }
8586:
1.915 droeschl 8587: ul.LC_funclist + ul.LC_funclist {
8588: /*
8589: left border as a seperator if we have more than
8590: one list
8591: */
8592: border-left: 1px solid $sidebg;
8593: /*
8594: this hides the left border behind the border of the
8595: outer box if element is wrapped to the next 'line'
8596: */
8597: margin-left: -1px;
8598: }
8599:
1.843 bisitz 8600: ul.LC_funclist li {
1.915 droeschl 8601: display: inline;
1.782 bisitz 8602: white-space: nowrap;
1.915 droeschl 8603: margin: 0 0 0 25px;
8604: line-height: 150%;
1.782 bisitz 8605: }
8606:
1.974 wenzelju 8607: .LC_hidden {
8608: display: none;
8609: }
8610:
1.1030 www 8611: .LCmodal-overlay {
8612: position:fixed;
8613: top:0;
8614: right:0;
8615: bottom:0;
8616: left:0;
8617: height:100%;
8618: width:100%;
8619: margin:0;
8620: padding:0;
8621: background:#999;
8622: opacity:.75;
8623: filter: alpha(opacity=75);
8624: -moz-opacity: 0.75;
8625: z-index:101;
8626: }
8627:
8628: * html .LCmodal-overlay {
8629: position: absolute;
8630: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8631: }
8632:
8633: .LCmodal-window {
8634: position:fixed;
8635: top:50%;
8636: left:50%;
8637: margin:0;
8638: padding:0;
8639: z-index:102;
8640: }
8641:
8642: * html .LCmodal-window {
8643: position:absolute;
8644: }
8645:
8646: .LCclose-window {
8647: position:absolute;
8648: width:32px;
8649: height:32px;
8650: right:8px;
8651: top:8px;
8652: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8653: text-indent:-99999px;
8654: overflow:hidden;
8655: cursor:pointer;
8656: }
8657:
1.1075.2.158 raeburn 8658: .LCisDisabled {
8659: cursor: not-allowed;
8660: opacity: 0.5;
8661: }
8662:
8663: a[aria-disabled="true"] {
8664: color: currentColor;
8665: display: inline-block; /* For IE11/ MS Edge bug */
8666: pointer-events: none;
8667: text-decoration: none;
8668: }
8669:
1.1075.2.141 raeburn 8670: pre.LC_wordwrap {
8671: white-space: pre-wrap;
8672: white-space: -moz-pre-wrap;
8673: white-space: -pre-wrap;
8674: white-space: -o-pre-wrap;
8675: word-wrap: break-word;
8676: }
8677:
1.1075.2.17 raeburn 8678: /*
1.1075.2.161. .21(raeb 8679:-24): styles used for response display
8680:-24): */
8681:-24): div.LC_radiofoil, div.LC_rankfoil {
8682:-24): margin: .5em 0em .5em 0em;
8683:-24): }
8684:-24): table.LC_itemgroup {
8685:-24): margin-top: 1em;
8686:-24): }
8687:-24):
8688:-24): /*
1.1075.2.17 raeburn 8689: styles used by TTH when "Default set of options to pass to tth/m
8690: when converting TeX" in course settings has been set
8691:
8692: option passed: -t
8693:
8694: */
8695:
8696: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8697: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8698: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8699: td div.norm {line-height:normal;}
8700:
8701: /*
8702: option passed -y3
8703: */
8704:
8705: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8706: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8707: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8708:
1.1075.2.161. .21(raeb 8709:-24): /*
8710:-24): sections with roles, for content only
8711:-24): */
8712:-24): section[class^="role-"] {
8713:-24): padding-left: 10px;
8714:-24): padding-right: 5px;
8715:-24): margin-top: 8px;
8716:-24): margin-bottom: 8px;
8717:-24): border: 1px solid #2A4;
8718:-24): border-radius: 5px;
8719:-24): box-shadow: 0px 1px 1px #BBB;
8720:-24): }
8721:-24): section[class^="role-"]>h1 {
8722:-24): position: relative;
8723:-24): margin: 0px;
8724:-24): padding-top: 10px;
8725:-24): padding-left: 40px;
8726:-24): }
8727:-24): section[class^="role-"]>h1:before {
8728:-24): position: absolute;
8729:-24): left: -5px;
8730:-24): top: 5px;
8731:-24): }
8732:-24): section.role-activity>h1:before {
8733:-24): content:url('/adm/daxe/images/section_icons/activity.png');
8734:-24): }
8735:-24): section.role-advice>h1:before {
8736:-24): content:url('/adm/daxe/images/section_icons/advice.png');
8737:-24): }
8738:-24): section.role-bibliography>h1:before {
8739:-24): content:url('/adm/daxe/images/section_icons/bibliography.png');
8740:-24): }
8741:-24): section.role-citation>h1:before {
8742:-24): content:url('/adm/daxe/images/section_icons/citation.png');
8743:-24): }
8744:-24): section.role-conclusion>h1:before {
8745:-24): content:url('/adm/daxe/images/section_icons/conclusion.png');
8746:-24): }
8747:-24): section.role-definition>h1:before {
8748:-24): content:url('/adm/daxe/images/section_icons/definition.png');
8749:-24): }
8750:-24): section.role-demonstration>h1:before {
8751:-24): content:url('/adm/daxe/images/section_icons/demonstration.png');
8752:-24): }
8753:-24): section.role-example>h1:before {
8754:-24): content:url('/adm/daxe/images/section_icons/example.png');
8755:-24): }
8756:-24): section.role-explanation>h1:before {
8757:-24): content:url('/adm/daxe/images/section_icons/explanation.png');
8758:-24): }
8759:-24): section.role-introduction>h1:before {
8760:-24): content:url('/adm/daxe/images/section_icons/introduction.png');
8761:-24): }
8762:-24): section.role-method>h1:before {
8763:-24): content:url('/adm/daxe/images/section_icons/method.png');
8764:-24): }
8765:-24): section.role-more_information>h1:before {
8766:-24): content:url('/adm/daxe/images/section_icons/more_information.png');
8767:-24): }
8768:-24): section.role-objectives>h1:before {
8769:-24): content:url('/adm/daxe/images/section_icons/objectives.png');
8770:-24): }
8771:-24): section.role-prerequisites>h1:before {
8772:-24): content:url('/adm/daxe/images/section_icons/prerequisites.png');
8773:-24): }
8774:-24): section.role-remark>h1:before {
8775:-24): content:url('/adm/daxe/images/section_icons/remark.png');
8776:-24): }
8777:-24): section.role-reminder>h1:before {
8778:-24): content:url('/adm/daxe/images/section_icons/reminder.png');
8779:-24): }
8780:-24): section.role-summary>h1:before {
8781:-24): content:url('/adm/daxe/images/section_icons/summary.png');
8782:-24): }
8783:-24): section.role-syntax>h1:before {
8784:-24): content:url('/adm/daxe/images/section_icons/syntax.png');
8785:-24): }
8786:-24): section.role-warning>h1:before {
8787:-24): content:url('/adm/daxe/images/section_icons/warning.png');
8788:-24): }
8789:-24):
1.1075.2.121 raeburn 8790: #LC_minitab_header {
8791: float:left;
8792: width:100%;
8793: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8794: font-size:93%;
8795: line-height:normal;
8796: margin: 0.5em 0 0.5em 0;
8797: }
8798: #LC_minitab_header ul {
8799: margin:0;
8800: padding:10px 10px 0;
8801: list-style:none;
8802: }
8803: #LC_minitab_header li {
8804: float:left;
8805: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8806: margin:0;
8807: padding:0 0 0 9px;
8808: }
8809: #LC_minitab_header a {
8810: display:block;
8811: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8812: padding:5px 15px 4px 6px;
8813: }
8814: #LC_minitab_header #LC_current_minitab {
8815: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8816: }
8817: #LC_minitab_header #LC_current_minitab a {
8818: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8819: padding-bottom:5px;
8820: }
8821:
8822:
1.343 albertel 8823: END
8824: }
8825:
1.306 albertel 8826: =pod
8827:
8828: =item * &headtag()
8829:
8830: Returns a uniform footer for LON-CAPA web pages.
8831:
1.307 albertel 8832: Inputs: $title - optional title for the head
8833: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8834: $args - optional arguments
1.319 albertel 8835: force_register - if is true call registerurl so the remote is
8836: informed
1.415 albertel 8837: redirect -> array ref of
8838: 1- seconds before redirect occurs
8839: 2- url to redirect to
8840: 3- whether the side effect should occur
1.315 albertel 8841: (side effect of setting
8842: $env{'internal.head.redirect'} to the url
1.1075.2.161. .9(raebu 8843:22): redirected to)
8844:22): 4- whether the redirect target should be
8845:22): the opener of the current (pop-up)
8846:22): window (side effect of setting
8847:22): $env{'internal.head.to_opener'} to
8848:22): 1, if true.
.10(raeb 8849:-22): 5- whether encrypt check should be skipped
1.352 albertel 8850: domain -> force to color decorate a page for a specific
8851: domain
8852: function -> force usage of a specific rolish color scheme
8853: bgcolor -> override the default page bgcolor
1.460 albertel 8854: no_auto_mt_title
8855: -> prevent &mt()ing the title arg
1.464 albertel 8856:
1.306 albertel 8857: =cut
8858:
8859: sub headtag {
1.313 albertel 8860: my ($title,$head_extra,$args) = @_;
1.306 albertel 8861:
1.363 albertel 8862: my $function = $args->{'function'} || &get_users_function();
8863: my $domain = $args->{'domain'} || &determinedomain();
8864: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8865: my $httphost = $args->{'use_absolute'};
1.418 albertel 8866: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8867: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8868: #time(),
1.418 albertel 8869: $env{'environment.color.timestamp'},
1.363 albertel 8870: $function,$domain,$bgcolor);
8871:
1.369 www 8872: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8873:
1.308 albertel 8874: my $result =
8875: '<head>'.
1.1075.2.56 raeburn 8876: &font_settings($args);
1.319 albertel 8877:
1.1075.2.72 raeburn 8878: my $inhibitprint;
8879: if ($args->{'print_suppress'}) {
8880: $inhibitprint = &print_suppression();
8881: }
1.1064 raeburn 8882:
1.461 albertel 8883: if (!$args->{'frameset'}) {
8884: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8885: }
1.1075.2.12 raeburn 8886: if ($args->{'force_register'}) {
8887: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8888: }
1.436 albertel 8889: if (!$args->{'no_nav_bar'}
8890: && !$args->{'only_body'}
8891: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8892: $result .= &help_menu_js($httphost);
1.1032 www 8893: $result.=&modal_window();
1.1038 www 8894: $result.=&togglebox_script();
1.1034 www 8895: $result.=&wishlist_window();
1.1041 www 8896: $result.=&LCprogressbarUpdate_script();
1.1034 www 8897: } else {
8898: if ($args->{'add_modal'}) {
8899: $result.=&modal_window();
8900: }
8901: if ($args->{'add_wishlist'}) {
8902: $result.=&wishlist_window();
8903: }
1.1038 www 8904: if ($args->{'add_togglebox'}) {
8905: $result.=&togglebox_script();
8906: }
1.1041 www 8907: if ($args->{'add_progressbar'}) {
8908: $result.=&LCprogressbarUpdate_script();
8909: }
1.436 albertel 8910: }
1.314 albertel 8911: if (ref($args->{'redirect'})) {
1.1075.2.161. .10(raeb 8912:-22): my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
8913:-22): if (!$skip_enc_check) {
8914:-22): $url = &Apache::lonenc::check_encrypt($url);
8915:-22): }
1.414 albertel 8916: if (!$inhibit_continue) {
8917: $env{'internal.head.redirect'} = $url;
8918: }
1.1075.2.161. .9(raebu 8919:22): $result.=<<"ADDMETA";
1.313 albertel 8920: <meta http-equiv="pragma" content="no-cache" />
1.1075.2.161. .9(raebu 8921:22): ADDMETA
8922:22): if ($to_opener) {
8923:22): $env{'internal.head.to_opener'} = 1;
8924:22): my $dest = &js_escape($url);
8925:22): my $timeout = int($time * 1000);
8926:22): $result .=<<"ENDJS";
8927:22): <script type="text/javascript">
8928:22): // <![CDATA[
8929:22): function LC_To_Opener() {
8930:22): var dest = '$dest';
8931:22): if (dest != '') {
8932:22): if (window.opener != null && !window.opener.closed) {
8933:22): window.opener.location.href=dest;
8934:22): window.close();
8935:22): } else {
8936:22): window.location.href=dest;
8937:22): }
8938:22): }
8939:22): }
8940:22): \$(document).ready(function () {
8941:22): setTimeout('LC_To_Opener()',$timeout);
8942:22): });
8943:22): // ]]>
8944:22): </script>
8945:22): ENDJS
8946:22): } else {
8947:22): $result.=<<"ADDMETA";
1.344 albertel 8948: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8949: ADDMETA
1.1075.2.161. .9(raebu 8950:22): }
1.1075.2.89 raeburn 8951: } else {
8952: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8953: my $requrl = $env{'request.uri'};
8954: if ($requrl eq '') {
8955: $requrl = $ENV{'REQUEST_URI'};
8956: $requrl =~ s/\?.+$//;
8957: }
8958: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8959: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8960: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8961: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8962: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8963: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8964: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8965: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8966: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8967: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8968: $offload = 1;
1.1075.2.151 raeburn 8969: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8970: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8971: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8972: $offloadoth = 1;
8973: $dom_in_use = $env{'user.domain'};
8974: }
8975: }
1.1075.2.145 raeburn 8976: }
8977: }
8978: unless ($offload) {
8979: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8980: if ($domdefs{'offloadoth'}{$lonhost}) {
8981: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8982: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8983: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8984: $offload = 1;
1.1075.2.151 raeburn 8985: $offloadoth = 1;
1.1075.2.145 raeburn 8986: $dom_in_use = $env{'user.domain'};
8987: }
1.1075.2.89 raeburn 8988: }
1.1075.2.145 raeburn 8989: }
8990: }
8991: }
8992: if ($offload) {
1.1075.2.158 raeburn 8993: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8994: if (($newserver eq '') && ($offloadoth)) {
8995: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 8996:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 8997: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8998: }
8999: }
1.1075.2.145 raeburn 9000: if (($newserver) && ($newserver ne $lonhost)) {
9001: my $numsec = 5;
9002: my $timeout = $numsec * 1000;
9003: my ($newurl,$locknum,%locks,$msg);
9004: if ($env{'request.role.adv'}) {
9005: ($locknum,%locks) = &Apache::lonnet::get_locks();
9006: }
9007: my $disable_submit = 0;
9008: if ($requrl =~ /$LONCAPA::assess_re/) {
9009: $disable_submit = 1;
9010: }
9011: if ($locknum) {
9012: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 9013: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 9014: join(", ",sort(values(%locks)))."\n";
9015: if (&show_course()) {
9016: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 9017: } else {
1.1075.2.145 raeburn 9018: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
9019: }
9020: } else {
9021: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9022: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9023: }
9024: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9025: $newurl = '/adm/switchserver?otherserver='.$newserver;
9026: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9027: $newurl .= '&role='.$env{'request.role'};
9028: }
9029: if ($env{'request.symb'}) {
9030: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9031: if ($shownsymb =~ m{^/enc/}) {
9032: my $reqdmajor = 2;
9033: my $reqdminor = 11;
9034: my $reqdsubminor = 3;
9035: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9036: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9037: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9038: if (($major eq '' && $minor eq '') ||
9039: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9040: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9041: ($reqdsubminor > $subminor))))) {
9042: undef($shownsymb);
9043: }
1.1075.2.89 raeburn 9044: }
1.1075.2.145 raeburn 9045: if ($shownsymb) {
9046: &js_escape(\$shownsymb);
9047: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 9048: }
1.1075.2.145 raeburn 9049: } else {
9050: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9051: &js_escape(\$shownurl);
9052: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 9053: }
1.1075.2.145 raeburn 9054: }
9055: &js_escape(\$msg);
9056: $result.=<<OFFLOAD
1.1075.2.89 raeburn 9057: <meta http-equiv="pragma" content="no-cache" />
9058: <script type="text/javascript">
1.1075.2.92 raeburn 9059: // <![CDATA[
1.1075.2.89 raeburn 9060: function LC_Offload_Now() {
9061: var dest = "$newurl";
9062: if (dest != '') {
9063: window.location.href="$newurl";
9064: }
9065: }
1.1075.2.92 raeburn 9066: \$(document).ready(function () {
9067: window.alert('$msg');
9068: if ($disable_submit) {
1.1075.2.89 raeburn 9069: \$(".LC_hwk_submit").prop("disabled", true);
9070: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 9071: }
9072: setTimeout('LC_Offload_Now()', $timeout);
9073: });
9074: // ]]>
1.1075.2.89 raeburn 9075: </script>
9076: OFFLOAD
9077: }
9078: }
9079: }
9080: }
9081: }
1.313 albertel 9082: }
1.306 albertel 9083: if (!defined($title)) {
9084: $title = 'The LearningOnline Network with CAPA';
9085: }
1.460 albertel 9086: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.161. .25(raeb 9087:-24): if ($title =~ /^LON-CAPA\s+/) {
9088:-24): $result .= '<title> '.$title.'</title>';
9089:-24): } else {
9090:-24): $result .= '<title> LON-CAPA '.$title.'</title>';
9091:-24): }
9092:-24): $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1075.2.61 raeburn 9093: if (!$args->{'frameset'}) {
9094: $result .= ' /';
9095: }
9096: $result .= '>'
1.1064 raeburn 9097: .$inhibitprint
1.414 albertel 9098: .$head_extra;
1.1075.2.108 raeburn 9099: my $clientmobile;
9100: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9101: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9102: } else {
9103: $clientmobile = $env{'browser.mobile'};
9104: }
9105: if ($clientmobile) {
1.1075.2.42 raeburn 9106: $result .= '
9107: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9108: <meta name="apple-mobile-web-app-capable" content="yes" />';
9109: }
1.1075.2.126 raeburn 9110: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9111: return $result.'</head>';
1.306 albertel 9112: }
9113:
9114: =pod
9115:
1.340 albertel 9116: =item * &font_settings()
9117:
9118: Returns neccessary <meta> to set the proper encoding
9119:
1.1075.2.56 raeburn 9120: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9121:
9122: =cut
9123:
9124: sub font_settings {
1.1075.2.56 raeburn 9125: my ($args) = @_;
1.340 albertel 9126: my $headerstring='';
1.1075.2.56 raeburn 9127: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9128: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 9129: $headerstring.=
1.1075.2.61 raeburn 9130: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9131: if (!$args->{'frameset'}) {
9132: $headerstring.= ' /';
9133: }
9134: $headerstring .= '>'."\n";
1.340 albertel 9135: }
9136: return $headerstring;
9137: }
9138:
1.341 albertel 9139: =pod
9140:
1.1064 raeburn 9141: =item * &print_suppression()
9142:
9143: In course context returns css which causes the body to be blank when media="print",
9144: if printout generation is unavailable for the current resource.
9145:
9146: This could be because:
9147:
9148: (a) printstartdate is in the future
9149:
9150: (b) printenddate is in the past
9151:
9152: (c) there is an active exam block with "printout"
9153: functionality blocked
9154:
9155: Users with pav, pfo or evb privileges are exempt.
9156:
9157: Inputs: none
9158:
9159: =cut
9160:
9161:
9162: sub print_suppression {
9163: my $noprint;
9164: if ($env{'request.course.id'}) {
9165: my $scope = $env{'request.course.id'};
9166: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9167: (&Apache::lonnet::allowed('pfo',$scope))) {
9168: return;
9169: }
9170: if ($env{'request.course.sec'} ne '') {
9171: $scope .= "/$env{'request.course.sec'}";
9172: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9173: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9174: return;
1.1064 raeburn 9175: }
9176: }
9177: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9178: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 9179: my $clientip = &Apache::lonnet::get_requestor_ip();
9180: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9181: if ($blocked) {
9182: my $checkrole = "cm./$cdom/$cnum";
9183: if ($env{'request.course.sec'} ne '') {
9184: $checkrole .= "/$env{'request.course.sec'}";
9185: }
9186: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9187: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9188: $noprint = 1;
9189: }
9190: }
9191: unless ($noprint) {
9192: my $symb = &Apache::lonnet::symbread();
9193: if ($symb ne '') {
9194: my $navmap = Apache::lonnavmaps::navmap->new();
9195: if (ref($navmap)) {
9196: my $res = $navmap->getBySymb($symb);
9197: if (ref($res)) {
9198: if (!$res->resprintable()) {
9199: $noprint = 1;
9200: }
9201: }
9202: }
9203: }
9204: }
9205: if ($noprint) {
9206: return <<"ENDSTYLE";
9207: <style type="text/css" media="print">
9208: body { display:none }
9209: </style>
9210: ENDSTYLE
9211: }
9212: }
9213: return;
9214: }
9215:
9216: =pod
9217:
1.341 albertel 9218: =item * &xml_begin()
9219:
9220: Returns the needed doctype and <html>
9221:
9222: Inputs: none
9223:
9224: =cut
9225:
9226: sub xml_begin {
1.1075.2.61 raeburn 9227: my ($is_frameset) = @_;
1.341 albertel 9228: my $output='';
9229:
9230: if ($env{'browser.mathml'}) {
9231: $output='<?xml version="1.0"?>'
9232: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9233: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9234:
9235: # .'<!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">] >'
9236: .'<!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">'
9237: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9238: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 9239: } elsif ($is_frameset) {
9240: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9241: '<html>'."\n";
1.341 albertel 9242: } else {
1.1075.2.61 raeburn 9243: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9244: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9245: }
9246: return $output;
9247: }
1.340 albertel 9248:
9249: =pod
9250:
1.306 albertel 9251: =item * &start_page()
9252:
9253: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9254:
1.648 raeburn 9255: Inputs:
9256:
9257: =over 4
9258:
9259: $title - optional title for the page
9260:
9261: $head_extra - optional extra HTML to incude inside the <head>
9262:
9263: $args - additional optional args supported are:
9264:
9265: =over 8
9266:
9267: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9268: arg on
1.814 bisitz 9269: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9270: add_entries -> additional attributes to add to the <body>
9271: domain -> force to color decorate a page for a
1.317 albertel 9272: specific domain
1.648 raeburn 9273: function -> force usage of a specific rolish color
1.317 albertel 9274: scheme
1.648 raeburn 9275: redirect -> see &headtag()
9276: bgcolor -> override the default page bg color
9277: js_ready -> return a string ready for being used in
1.317 albertel 9278: a javascript writeln
1.648 raeburn 9279: html_encode -> return a string ready for being used in
1.320 albertel 9280: a html attribute
1.648 raeburn 9281: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9282: $forcereg arg
1.648 raeburn 9283: frameset -> if true will start with a <frameset>
1.330 albertel 9284: rather than <body>
1.648 raeburn 9285: skip_phases -> hash ref of
1.338 albertel 9286: head -> skip the <html><head> generation
9287: body -> skip all <body> generation
1.1075.2.12 raeburn 9288: no_inline_link -> if true and in remote mode, don't show the
9289: 'Switch To Inline Menu' link
1.648 raeburn 9290: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9291: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9292: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 9293: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9294: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 9295: group -> includes the current group, if page is for a
9296: specific group
1.1075.2.133 raeburn 9297: use_absolute -> for request for external resource or syllabus, this
9298: will contain https://<hostname> if server uses
9299: https (as per hosts.tab), but request is for http
9300: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 9301: links_disabled -> Links in primary and secondary menus are disabled
9302: (Can enable them once page has loaded - see lonroles.pm
9303: for an example).
1.1075.2.161. .6(raebu 9304:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9305:
1.648 raeburn 9306: =back
1.460 albertel 9307:
1.648 raeburn 9308: =back
1.562 albertel 9309:
1.306 albertel 9310: =cut
9311:
9312: sub start_page {
1.309 albertel 9313: my ($title,$head_extra,$args) = @_;
1.318 albertel 9314: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9315:
1.315 albertel 9316: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 9317:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9318:
1.338 albertel 9319: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 9320: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9321: }
1.1075.2.161. .1(raebu 9322:21):
9323:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
9324:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9325:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9326:21): $args->{'no_primary_menu'} = 1;
9327:21): }
9328:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9329:21): $args->{'no_inline_menu'} = 1;
9330:21): }
9331:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9332:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9333:21): }
9334:21): } else {
9335:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9336:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9337:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9338:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9339:21): $args->{'no_primary_menu'} = 1;
9340:21): }
9341:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9342:21): $args->{'no_inline_menu'} = 1;
9343:21): }
9344:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9345:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9346:21): }
9347:21): }
9348:21): }
9349:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9350:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
9351:21): $env{'course.'.$env{'request.course.id'}.'.num'});
9352:21): } elsif ($env{'request.course.id'}) {
9353:21): my $expiretime=600;
9354:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9355:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9356:21): }
9357:21): my ($deeplinkmenu,$menuref);
9358:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9359:21): if ($menucoll) {
9360:21): if (ref($menuref) eq 'HASH') {
9361:21): %menu = %{$menuref};
9362:21): }
9363:21): if ($menu{'top'} eq 'n') {
9364:21): $args->{'no_primary_menu'} = 1;
9365:21): }
9366:21): if ($menu{'inline'} eq 'n') {
9367:21): unless (&Apache::lonnet::allowed('opa')) {
9368:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9369:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9370:21): my $crstype = &course_type();
9371:21): my $now = time;
9372:21): my $ccrole;
9373:21): if ($crstype eq 'Community') {
9374:21): $ccrole = 'co';
9375:21): } else {
9376:21): $ccrole = 'cc';
9377:21): }
9378:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9379:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9380:21): if ((($start) && ($start<0)) ||
9381:21): (($end) && ($end<$now)) ||
9382:21): (($start) && ($now<$start))) {
9383:21): $args->{'no_inline_menu'} = 1;
9384:21): }
9385:21): } else {
9386:21): $args->{'no_inline_menu'} = 1;
9387:21): }
9388:21): }
9389:21): }
9390:21): }
9391:21): }
.4(raebu 9392:22):
.8(raebu 9393:22): my $showncrumbs;
1.338 albertel 9394: if (! exists($args->{'skip_phases'}{'body'}) ) {
9395: if ($args->{'frameset'}) {
9396: my $attr_string = &make_attr_string($args->{'force_register'},
9397: $args->{'add_entries'});
9398: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9399: } else {
9400: $result .=
9401: &bodytag($title,
9402: $args->{'function'}, $args->{'add_entries'},
9403: $args->{'only_body'}, $args->{'domain'},
9404: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 9405: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 9406:21): $args, \@advtools,
.8(raebu 9407:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 9408: }
1.330 albertel 9409: }
1.338 albertel 9410:
1.315 albertel 9411: if ($args->{'js_ready'}) {
1.713 kaisler 9412: $result = &js_ready($result);
1.315 albertel 9413: }
1.320 albertel 9414: if ($args->{'html_encode'}) {
1.713 kaisler 9415: $result = &html_encode($result);
9416: }
9417:
1.813 bisitz 9418: # Preparation for new and consistent functionlist at top of screen
9419: # if ($args->{'functionlist'}) {
9420: # $result .= &build_functionlist();
9421: #}
9422:
1.964 droeschl 9423: # Don't add anything more if only_body wanted or in const space
9424: return $result if $args->{'only_body'}
9425: || $env{'request.state'} eq 'construct';
1.813 bisitz 9426:
9427: #Breadcrumbs
1.758 kaisler 9428: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 9429:22): unless ($showncrumbs) {
1.758 kaisler 9430: &Apache::lonhtmlcommon::clear_breadcrumbs();
9431: #if any br links exists, add them to the breadcrumbs
9432: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9433: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9434: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9435: }
9436: }
1.1075.2.19 raeburn 9437: # if @advtools array contains items add then to the breadcrumbs
9438: if (@advtools > 0) {
9439: &Apache::lonmenu::advtools_crumbs(@advtools);
9440: }
1.1075.2.123 raeburn 9441: my $menulink;
9442: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 9443:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
9444:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 9445: $menulink = 0;
9446: } else {
9447: undef($menulink);
9448: }
1.1075.2.161. .8(raebu 9449:22): my $linkprotout;
9450:22): if ($env{'request.deeplink.login'}) {
9451:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
9452:22): if ($linkprotout) {
9453:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9454:22): }
9455:22): }
1.758 kaisler 9456: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9457: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 9458: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1075.2.161. .1(raebu 9459:21): } else {
1.1075.2.123 raeburn 9460: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9461: }
1.1075.2.161. .8(raebu 9462:22): }
1.1075.2.24 raeburn 9463: } elsif (($env{'environment.remote'} eq 'on') &&
9464: ($env{'form.inhibitmenu'} ne 'yes') &&
9465: ($env{'request.noversionuri'} =~ m{^/res/}) &&
9466: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 9467: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 9468: }
1.315 albertel 9469: return $result;
1.306 albertel 9470: }
9471:
9472: sub end_page {
1.315 albertel 9473: my ($args) = @_;
9474: $env{'internal.end_page'}++;
1.330 albertel 9475: my $result;
1.335 albertel 9476: if ($args->{'discussion'}) {
9477: my ($target,$parser);
9478: if (ref($args->{'discussion'})) {
9479: ($target,$parser) =($args->{'discussion'}{'target'},
9480: $args->{'discussion'}{'parser'});
9481: }
9482: $result .= &Apache::lonxml::xmlend($target,$parser);
9483: }
1.330 albertel 9484: if ($args->{'frameset'}) {
9485: $result .= '</frameset>';
9486: } else {
1.635 raeburn 9487: $result .= &endbodytag($args);
1.330 albertel 9488: }
1.1075.2.6 raeburn 9489: unless ($args->{'notbody'}) {
9490: $result .= "\n</html>";
9491: }
1.330 albertel 9492:
1.315 albertel 9493: if ($args->{'js_ready'}) {
1.317 albertel 9494: $result = &js_ready($result);
1.315 albertel 9495: }
1.335 albertel 9496:
1.320 albertel 9497: if ($args->{'html_encode'}) {
9498: $result = &html_encode($result);
9499: }
1.335 albertel 9500:
1.315 albertel 9501: return $result;
9502: }
9503:
1.1075.2.161. .1(raebu 9504:21): sub menucoll_in_effect {
9505:21): my ($menucoll,$deeplinkmenu,%menu);
9506:21): if ($env{'request.course.id'}) {
9507:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9508:21): if ($env{'request.deeplink.login'}) {
9509:21): my ($deeplink_symb,$deeplink,$check_login_symb);
9510:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9511:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9512:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9513:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9514:21): my $navmap = Apache::lonnavmaps::navmap->new();
9515:21): if (ref($navmap)) {
9516:21): $deeplink = $navmap->get_mapparam(undef,
9517:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
9518:21): '0.deeplink');
9519:21): } else {
9520:21): $check_login_symb = 1;
9521:21): }
9522:21): } else {
9523:21): my $symb=&Apache::lonnet::symbread();
9524:21): if ($symb) {
9525:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9526:21): } else {
9527:21): $check_login_symb = 1;
9528:21): }
9529:21): }
9530:21): } else {
9531:21): $check_login_symb = 1;
9532:21): }
9533:21): if ($check_login_symb) {
9534:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9535:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
9536:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9537:21): my $navmap = Apache::lonnavmaps::navmap->new();
9538:21): if (ref($navmap)) {
9539:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9540:21): }
9541:21): } else {
9542:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9543:21): }
9544:21): }
9545:21): if ($deeplink ne '') {
.6(raebu 9546:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 9547:21): if ($display =~ /^\d+$/) {
9548:21): $deeplinkmenu = 1;
9549:21): $menucoll = $display;
9550:21): }
9551:21): }
9552:21): }
9553:21): if ($menucoll) {
9554:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9555:21): }
9556:21): }
9557:21): return ($menucoll,$deeplinkmenu,\%menu);
9558:21): }
9559:21):
9560:21): sub deeplink_login_symb {
9561:21): my ($cnum,$cdom) = @_;
9562:21): my $login_symb;
9563:21): if ($env{'request.deeplink.login'}) {
9564:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9565:21): }
9566:21): return $login_symb;
9567:21): }
9568:21):
9569:21): sub symb_from_tinyurl {
9570:21): my ($url,$cnum,$cdom) = @_;
9571:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9572:21): my $key = $1;
9573:21): my ($tinyurl,$login);
9574:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9575:21): if (defined($cached)) {
9576:21): $tinyurl = $result;
9577:21): } else {
9578:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9579:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9580:21): if ($currtiny{$key} ne '') {
9581:21): $tinyurl = $currtiny{$key};
9582:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9583:21): }
9584:21): }
9585:21): if ($tinyurl ne '') {
9586:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9587:21): if (wantarray) {
9588:21): return ($cnumreq,$symb);
9589:21): } elsif ($cnumreq eq $cnum) {
9590:21): return $symb;
9591:21): }
9592:21): }
9593:21): }
9594:21): if (wantarray) {
9595:21): return ();
9596:21): } else {
9597:21): return;
9598:21): }
9599:21): }
9600:21):
.17(raeb 9601:-23): sub usable_exttools {
9602:-23): my %tooltypes;
9603:-23): if ($env{'request.course.id'}) {
9604:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9605:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9606:-23): %tooltypes = (
9607:-23): crs => 1,
9608:-23): dom => 1,
9609:-23): );
9610:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9611:-23): $tooltypes{'crs'} = 1;
9612:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9613:-23): $tooltypes{'dom'} = 1;
9614:-23): }
9615:-23): } else {
9616:-23): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9617:-23): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9618:-23): my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9619:-23): if ($crstype eq '') {
9620:-23): $crstype = 'course';
9621:-23): }
9622:-23): if ($crstype eq 'course') {
9623:-23): if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9624:-23): $crstype = 'official';
9625:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9626:-23): $crstype = 'textbook';
9627:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9628:-23): $crstype = 'lti';
9629:-23): } else {
9630:-23): $crstype = 'unofficial';
9631:-23): }
9632:-23): }
9633:-23): my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9634:-23): if ($domdefaults{$crstype.'domexttool'}) {
9635:-23): $tooltypes{'dom'} = 1;
9636:-23): }
9637:-23): if ($domdefaults{$crstype.'exttool'}) {
9638:-23): $tooltypes{'crs'} = 1;
9639:-23): }
9640:-23): }
9641:-23): }
9642:-23): return %tooltypes;
9643:-23): }
9644:-23):
1.1034 www 9645: sub wishlist_window {
9646: return(<<'ENDWISHLIST');
1.1046 raeburn 9647: <script type="text/javascript">
1.1034 www 9648: // <![CDATA[
9649: // <!-- BEGIN LON-CAPA Internal
9650: function set_wishlistlink(title, path) {
9651: if (!title) {
9652: title = document.title;
9653: title = title.replace(/^LON-CAPA /,'');
9654: }
1.1075.2.65 raeburn 9655: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9656: title = title.replace("'","\\\'");
1.1034 www 9657: if (!path) {
9658: path = location.pathname;
9659: }
1.1075.2.65 raeburn 9660: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9661: path = path.replace("'","\\\'");
1.1034 www 9662: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9663: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9664: }
9665: // END LON-CAPA Internal -->
9666: // ]]>
9667: </script>
9668: ENDWISHLIST
9669: }
9670:
1.1030 www 9671: sub modal_window {
9672: return(<<'ENDMODAL');
1.1046 raeburn 9673: <script type="text/javascript">
1.1030 www 9674: // <![CDATA[
9675: // <!-- BEGIN LON-CAPA Internal
9676: var modalWindow = {
9677: parent:"body",
9678: windowId:null,
9679: content:null,
9680: width:null,
9681: height:null,
9682: close:function()
9683: {
9684: $(".LCmodal-window").remove();
9685: $(".LCmodal-overlay").remove();
9686: },
9687: open:function()
9688: {
9689: var modal = "";
9690: modal += "<div class=\"LCmodal-overlay\"></div>";
9691: 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;\">";
9692: modal += this.content;
9693: modal += "</div>";
9694:
9695: $(this.parent).append(modal);
9696:
9697: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9698: $(".LCclose-window").click(function(){modalWindow.close();});
9699: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9700: }
9701: };
1.1075.2.42 raeburn 9702: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9703: {
1.1075.2.119 raeburn 9704: source = source.replace(/'/g,"'");
1.1030 www 9705: modalWindow.windowId = "myModal";
9706: modalWindow.width = width;
9707: modalWindow.height = height;
1.1075.2.80 raeburn 9708: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9709: modalWindow.open();
1.1075.2.87 raeburn 9710: };
1.1030 www 9711: // END LON-CAPA Internal -->
9712: // ]]>
9713: </script>
9714: ENDMODAL
9715: }
9716:
9717: sub modal_link {
1.1075.2.42 raeburn 9718: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9719: unless ($width) { $width=480; }
9720: unless ($height) { $height=400; }
1.1031 www 9721: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9722: unless ($transparency) { $transparency='true'; }
9723:
1.1074 raeburn 9724: my $target_attr;
9725: if (defined($target)) {
9726: $target_attr = 'target="'.$target.'"';
9727: }
9728: return <<"ENDLINK";
1.1075.2.143 raeburn 9729: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9730: ENDLINK
1.1030 www 9731: }
9732:
1.1032 www 9733: sub modal_adhoc_script {
1.1075.2.155 raeburn 9734: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9735: my $mathjax;
9736: if ($possmathjax) {
9737: $mathjax = <<'ENDJAX';
9738: if (typeof MathJax == 'object') {
9739: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9740: }
9741: ENDJAX
9742: }
1.1032 www 9743: return (<<ENDADHOC);
1.1046 raeburn 9744: <script type="text/javascript">
1.1032 www 9745: // <![CDATA[
9746: var $funcname = function()
9747: {
9748: modalWindow.windowId = "myModal";
9749: modalWindow.width = $width;
9750: modalWindow.height = $height;
9751: modalWindow.content = '$content';
9752: modalWindow.open();
1.1075.2.155 raeburn 9753: $mathjax
1.1032 www 9754: };
9755: // ]]>
9756: </script>
9757: ENDADHOC
9758: }
9759:
1.1041 www 9760: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9761: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9762: my $innerwidth=$width-20;
9763: $content=&js_ready(
1.1042 www 9764: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9765: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9766: $content.
1.1041 www 9767: &end_scrollbox().
1.1075.2.42 raeburn 9768: &end_page()
1.1041 www 9769: );
1.1075.2.155 raeburn 9770: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9771: }
9772:
9773: sub modal_adhoc_window {
1.1075.2.155 raeburn 9774: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9775: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9776: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9777: }
9778:
9779: sub modal_adhoc_launch {
9780: my ($funcname,$width,$height,$content)=@_;
9781: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9782: <script type="text/javascript">
9783: // <![CDATA[
9784: $funcname();
9785: // ]]>
9786: </script>
9787: ENDLAUNCH
9788: }
9789:
9790: sub modal_adhoc_close {
9791: return (<<ENDCLOSE);
9792: <script type="text/javascript">
9793: // <![CDATA[
9794: modalWindow.close();
9795: // ]]>
9796: </script>
9797: ENDCLOSE
9798: }
9799:
1.1038 www 9800: sub togglebox_script {
9801: return(<<ENDTOGGLE);
9802: <script type="text/javascript">
9803: // <![CDATA[
9804: function LCtoggleDisplay(id,hidetext,showtext) {
9805: link = document.getElementById(id + "link").childNodes[0];
9806: with (document.getElementById(id).style) {
9807: if (display == "none" ) {
9808: display = "inline";
9809: link.nodeValue = hidetext;
9810: } else {
9811: display = "none";
9812: link.nodeValue = showtext;
9813: }
9814: }
9815: }
9816: // ]]>
9817: </script>
9818: ENDTOGGLE
9819: }
9820:
1.1039 www 9821: sub start_togglebox {
9822: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9823: unless ($heading) { $heading=''; } else { $heading.=' '; }
9824: unless ($showtext) { $showtext=&mt('show'); }
9825: unless ($hidetext) { $hidetext=&mt('hide'); }
9826: unless ($headerbg) { $headerbg='#FFFFFF'; }
9827: return &start_data_table().
9828: &start_data_table_header_row().
9829: '<td bgcolor="'.$headerbg.'">'.$heading.
9830: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9831: $showtext.'\')">'.$showtext.'</a>]</td>'.
9832: &end_data_table_header_row().
9833: '<tr id="'.$id.'" style="display:none""><td>';
9834: }
9835:
9836: sub end_togglebox {
9837: return '</td></tr>'.&end_data_table();
9838: }
9839:
1.1041 www 9840: sub LCprogressbar_script {
1.1075.2.130 raeburn 9841: my ($id,$number_to_do)=@_;
9842: if ($number_to_do) {
9843: return(<<ENDPROGRESS);
1.1041 www 9844: <script type="text/javascript">
9845: // <![CDATA[
1.1045 www 9846: \$('#progressbar$id').progressbar({
1.1041 www 9847: value: 0,
9848: change: function(event, ui) {
9849: var newVal = \$(this).progressbar('option', 'value');
9850: \$('.pblabel', this).text(LCprogressTxt);
9851: }
9852: });
9853: // ]]>
9854: </script>
9855: ENDPROGRESS
1.1075.2.130 raeburn 9856: } else {
9857: return(<<ENDPROGRESS);
9858: <script type="text/javascript">
9859: // <![CDATA[
9860: \$('#progressbar$id').progressbar({
9861: value: false,
9862: create: function(event, ui) {
9863: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9864: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9865: }
9866: });
9867: // ]]>
9868: </script>
9869: ENDPROGRESS
9870: }
1.1041 www 9871: }
9872:
9873: sub LCprogressbarUpdate_script {
9874: return(<<ENDPROGRESSUPDATE);
9875: <style type="text/css">
9876: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9877: .progress-label {position: absolute; width: 100%; text-align: center; top: 1px; font-weight: bold; text-shadow: 1px 1px 0 #fff;margin: 0; line-height: 200%; }
1.1041 www 9878: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9879: </style>
9880: <script type="text/javascript">
9881: // <![CDATA[
1.1045 www 9882: var LCprogressTxt='---';
9883:
1.1075.2.130 raeburn 9884: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9885: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9886: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9887: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9888: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9889: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9890: } else {
9891: \$('#progressbar'+id).progressbar('value',percent);
9892: }
1.1041 www 9893: }
9894: // ]]>
9895: </script>
9896: ENDPROGRESSUPDATE
9897: }
9898:
1.1042 www 9899: my $LClastpercent;
1.1045 www 9900: my $LCidcnt;
9901: my $LCcurrentid;
1.1042 www 9902:
1.1041 www 9903: sub LCprogressbar {
1.1075.2.130 raeburn 9904: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9905: $LClastpercent=0;
1.1045 www 9906: $LCidcnt++;
9907: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9908: my ($starting,$content);
9909: if ($number_to_do) {
9910: $starting=&mt('Starting');
9911: $content=(<<ENDPROGBAR);
9912: $preamble
1.1045 www 9913: <div id="progressbar$LCcurrentid">
1.1041 www 9914: <span class="pblabel">$starting</span>
9915: </div>
9916: ENDPROGBAR
1.1075.2.130 raeburn 9917: } else {
9918: $starting=&mt('Loading...');
9919: $LClastpercent='false';
9920: $content=(<<ENDPROGBAR);
9921: $preamble
9922: <div id="progressbar$LCcurrentid">
9923: <div class="progress-label">$starting</div>
9924: </div>
9925: ENDPROGBAR
9926: }
9927: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9928: }
9929:
9930: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9931: my ($r,$val,$text,$number_to_do)=@_;
9932: if ($number_to_do) {
9933: unless ($val) {
9934: if ($LClastpercent) {
9935: $val=$LClastpercent;
9936: } else {
9937: $val=0;
9938: }
9939: }
9940: if ($val<0) { $val=0; }
9941: if ($val>100) { $val=0; }
9942: $LClastpercent=$val;
9943: unless ($text) { $text=$val.'%'; }
9944: } else {
9945: $val = 'false';
1.1042 www 9946: }
1.1041 www 9947: $text=&js_ready($text);
1.1044 www 9948: &r_print($r,<<ENDUPDATE);
1.1041 www 9949: <script type="text/javascript">
9950: // <![CDATA[
1.1075.2.130 raeburn 9951: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9952: // ]]>
9953: </script>
9954: ENDUPDATE
1.1035 www 9955: }
9956:
1.1042 www 9957: sub LCprogressbarClose {
9958: my ($r)=@_;
9959: $LClastpercent=0;
1.1044 www 9960: &r_print($r,<<ENDCLOSE);
1.1042 www 9961: <script type="text/javascript">
9962: // <![CDATA[
1.1045 www 9963: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9964: // ]]>
9965: </script>
9966: ENDCLOSE
1.1044 www 9967: }
9968:
9969: sub r_print {
9970: my ($r,$to_print)=@_;
9971: if ($r) {
9972: $r->print($to_print);
9973: $r->rflush();
9974: } else {
9975: print($to_print);
9976: }
1.1042 www 9977: }
9978:
1.320 albertel 9979: sub html_encode {
9980: my ($result) = @_;
9981:
1.322 albertel 9982: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9983:
9984: return $result;
9985: }
1.1044 www 9986:
1.317 albertel 9987: sub js_ready {
9988: my ($result) = @_;
9989:
1.323 albertel 9990: $result =~ s/[\n\r]/ /xmsg;
9991: $result =~ s/\\/\\\\/xmsg;
9992: $result =~ s/'/\\'/xmsg;
1.372 albertel 9993: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9994:
9995: return $result;
9996: }
9997:
1.315 albertel 9998: sub validate_page {
9999: if ( exists($env{'internal.start_page'})
1.316 albertel 10000: && $env{'internal.start_page'} > 1) {
10001: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10002: $env{'internal.start_page'}.' '.
1.316 albertel 10003: $ENV{'request.filename'});
1.315 albertel 10004: }
10005: if ( exists($env{'internal.end_page'})
1.316 albertel 10006: && $env{'internal.end_page'} > 1) {
10007: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10008: $env{'internal.end_page'}.' '.
1.316 albertel 10009: $env{'request.filename'});
1.315 albertel 10010: }
10011: if ( exists($env{'internal.start_page'})
10012: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10013: &Apache::lonnet::logthis('start_page called without end_page '.
10014: $env{'request.filename'});
1.315 albertel 10015: }
10016: if ( ! exists($env{'internal.start_page'})
10017: && exists($env{'internal.end_page'})) {
1.316 albertel 10018: &Apache::lonnet::logthis('end_page called without start_page'.
10019: $env{'request.filename'});
1.315 albertel 10020: }
1.306 albertel 10021: }
1.315 albertel 10022:
1.996 www 10023:
10024: sub start_scrollbox {
1.1075.2.56 raeburn 10025: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10026: unless ($outerwidth) { $outerwidth='520px'; }
10027: unless ($width) { $width='500px'; }
10028: unless ($height) { $height='200px'; }
1.1075 raeburn 10029: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10030: if ($id ne '') {
1.1075.2.42 raeburn 10031: $table_id = ' id="table_'.$id.'"';
10032: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10033: }
1.1075 raeburn 10034: if ($bgcolor ne '') {
10035: $tdcol = "background-color: $bgcolor;";
10036: }
1.1075.2.42 raeburn 10037: my $nicescroll_js;
10038: if ($env{'browser.mobile'}) {
10039: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10040: }
1.1075 raeburn 10041: return <<"END";
1.1075.2.42 raeburn 10042: $nicescroll_js
10043:
10044: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 10045: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 10046: END
1.996 www 10047: }
10048:
10049: sub end_scrollbox {
1.1036 www 10050: return '</div></td></tr></table>';
1.996 www 10051: }
10052:
1.1075.2.42 raeburn 10053: sub nicescroll_javascript {
10054: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10055: my %options;
10056: if (ref($cursor) eq 'HASH') {
10057: %options = %{$cursor};
10058: }
10059: unless ($options{'railalign'} =~ /^left|right$/) {
10060: $options{'railalign'} = 'left';
10061: }
10062: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10063: my $function = &get_users_function();
10064: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
10065: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10066: $options{'cursorcolor'} = '#00F';
10067: }
10068: }
10069: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10070: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
10071: $options{'cursoropacity'}='1.0';
10072: }
10073: } else {
10074: $options{'cursoropacity'}='1.0';
10075: }
10076: if ($options{'cursorfixedheight'} eq 'none') {
10077: delete($options{'cursorfixedheight'});
10078: } else {
10079: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10080: }
10081: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10082: delete($options{'railoffset'});
10083: }
10084: my @niceoptions;
10085: while (my($key,$value) = each(%options)) {
10086: if ($value =~ /^\{.+\}$/) {
10087: push(@niceoptions,$key.':'.$value);
10088: } else {
10089: push(@niceoptions,$key.':"'.$value.'"');
10090: }
10091: }
10092: my $nicescroll_js = '
10093: $(document).ready(
10094: function() {
10095: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10096: }
10097: );
10098: ';
10099: if ($framecheck) {
10100: $nicescroll_js .= '
10101: function expand_div(caller) {
10102: if (top === self) {
10103: document.getElementById("'.$id.'").style.width = "auto";
10104: document.getElementById("'.$id.'").style.height = "auto";
10105: } else {
10106: try {
10107: if (parent.frames) {
10108: if (parent.frames.length > 1) {
10109: var framesrc = parent.frames[1].location.href;
10110: var currsrc = framesrc.replace(/\#.*$/,"");
10111: if ((caller == "search") || (currsrc == "'.$location.'")) {
10112: document.getElementById("'.$id.'").style.width = "auto";
10113: document.getElementById("'.$id.'").style.height = "auto";
10114: }
10115: }
10116: }
10117: } catch (e) {
10118: return;
10119: }
10120: }
10121: return;
10122: }
10123: ';
10124: }
10125: if ($needjsready) {
10126: $nicescroll_js = '
10127: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10128: } else {
10129: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10130: }
10131: return $nicescroll_js;
10132: }
10133:
1.318 albertel 10134: sub simple_error_page {
1.1075.2.49 raeburn 10135: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 10136:22): my %displayargs;
1.1075.2.49 raeburn 10137: if (ref($args) eq 'HASH') {
10138: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 10139:22): if ($args->{'only_body'}) {
10140:22): $displayargs{'only_body'} = 1;
10141:22): }
10142:22): if ($args->{'no_nav_bar'}) {
10143:22): $displayargs{'no_nav_bar'} = 1;
10144:22): }
1.1075.2.49 raeburn 10145: } else {
10146: $msg = &mt($msg);
10147: }
10148:
1.318 albertel 10149: my $page =
1.1075.2.161. .4(raebu 10150:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 10151: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10152: &Apache::loncommon::end_page();
10153: if (ref($r)) {
10154: $r->print($page);
1.327 albertel 10155: return;
1.318 albertel 10156: }
10157: return $page;
10158: }
1.347 albertel 10159:
10160: {
1.610 albertel 10161: my @row_count;
1.961 onken 10162:
10163: sub start_data_table_count {
10164: unshift(@row_count, 0);
10165: return;
10166: }
10167:
10168: sub end_data_table_count {
10169: shift(@row_count);
10170: return;
10171: }
10172:
1.347 albertel 10173: sub start_data_table {
1.1018 raeburn 10174: my ($add_class,$id) = @_;
1.422 albertel 10175: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10176: my $table_id;
10177: if (defined($id)) {
10178: $table_id = ' id="'.$id.'"';
10179: }
1.961 onken 10180: &start_data_table_count();
1.1018 raeburn 10181: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10182: }
10183:
10184: sub end_data_table {
1.961 onken 10185: &end_data_table_count();
1.389 albertel 10186: return '</table>'."\n";;
1.347 albertel 10187: }
10188:
10189: sub start_data_table_row {
1.974 wenzelju 10190: my ($add_class, $id) = @_;
1.610 albertel 10191: $row_count[0]++;
10192: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10193: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10194: $id = (' id="'.$id.'"') unless ($id eq '');
10195: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10196: }
1.471 banghart 10197:
10198: sub continue_data_table_row {
1.974 wenzelju 10199: my ($add_class, $id) = @_;
1.610 albertel 10200: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10201: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10202: $id = (' id="'.$id.'"') unless ($id eq '');
10203: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10204: }
1.347 albertel 10205:
10206: sub end_data_table_row {
1.389 albertel 10207: return '</tr>'."\n";;
1.347 albertel 10208: }
1.367 www 10209:
1.421 albertel 10210: sub start_data_table_empty_row {
1.707 bisitz 10211: # $row_count[0]++;
1.421 albertel 10212: return '<tr class="LC_empty_row" >'."\n";;
10213: }
10214:
10215: sub end_data_table_empty_row {
10216: return '</tr>'."\n";;
10217: }
10218:
1.367 www 10219: sub start_data_table_header_row {
1.389 albertel 10220: return '<tr class="LC_header_row">'."\n";;
1.367 www 10221: }
10222:
10223: sub end_data_table_header_row {
1.389 albertel 10224: return '</tr>'."\n";;
1.367 www 10225: }
1.890 droeschl 10226:
10227: sub data_table_caption {
10228: my $caption = shift;
10229: return "<caption class=\"LC_caption\">$caption</caption>";
10230: }
1.347 albertel 10231: }
10232:
1.548 albertel 10233: =pod
10234:
10235: =item * &inhibit_menu_check($arg)
10236:
10237: Checks for a inhibitmenu state and generates output to preserve it
10238:
10239: Inputs: $arg - can be any of
10240: - undef - in which case the return value is a string
10241: to add into arguments list of a uri
10242: - 'input' - in which case the return value is a HTML
10243: <form> <input> field of type hidden to
10244: preserve the value
10245: - a url - in which case the return value is the url with
10246: the neccesary cgi args added to preserve the
10247: inhibitmenu state
10248: - a ref to a url - no return value, but the string is
10249: updated to include the neccessary cgi
10250: args to preserve the inhibitmenu state
10251:
10252: =cut
10253:
10254: sub inhibit_menu_check {
10255: my ($arg) = @_;
10256: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10257: if ($arg eq 'input') {
10258: if ($env{'form.inhibitmenu'}) {
10259: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10260: } else {
10261: return
10262: }
10263: }
10264: if ($env{'form.inhibitmenu'}) {
10265: if (ref($arg)) {
10266: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10267: } elsif ($arg eq '') {
10268: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10269: } else {
10270: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10271: }
10272: }
10273: if (!ref($arg)) {
10274: return $arg;
10275: }
10276: }
10277:
1.251 albertel 10278: ###############################################
1.182 matthew 10279:
10280: =pod
10281:
1.549 albertel 10282: =back
10283:
10284: =head1 User Information Routines
10285:
10286: =over 4
10287:
1.405 albertel 10288: =item * &get_users_function()
1.182 matthew 10289:
10290: Used by &bodytag to determine the current users primary role.
10291: Returns either 'student','coordinator','admin', or 'author'.
10292:
10293: =cut
10294:
10295: ###############################################
10296: sub get_users_function {
1.815 tempelho 10297: my $function = 'norole';
1.818 tempelho 10298: if ($env{'request.role'}=~/^(st)/) {
10299: $function='student';
10300: }
1.907 raeburn 10301: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10302: $function='coordinator';
10303: }
1.258 albertel 10304: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10305: $function='admin';
10306: }
1.826 bisitz 10307: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10308: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10309: $function='author';
10310: }
10311: return $function;
1.54 www 10312: }
1.99 www 10313:
10314: ###############################################
10315:
1.233 raeburn 10316: =pod
10317:
1.821 raeburn 10318: =item * &show_course()
10319:
10320: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10321: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10322:
10323: Inputs:
10324: None
10325:
10326: Outputs:
10327: Scalar: 1 if 'Course' to be used, 0 otherwise.
10328:
10329: =cut
10330:
10331: ###############################################
10332: sub show_course {
10333: my $course = !$env{'user.adv'};
10334: if (!$env{'user.adv'}) {
10335: foreach my $env (keys(%env)) {
10336: next if ($env !~ m/^user\.priv\./);
10337: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10338: $course = 0;
10339: last;
10340: }
10341: }
10342: }
10343: return $course;
10344: }
10345:
10346: ###############################################
10347:
10348: =pod
10349:
1.542 raeburn 10350: =item * &check_user_status()
1.274 raeburn 10351:
10352: Determines current status of supplied role for a
10353: specific user. Roles can be active, previous or future.
10354:
10355: Inputs:
10356: user's domain, user's username, course's domain,
1.375 raeburn 10357: course's number, optional section ID.
1.274 raeburn 10358:
10359: Outputs:
10360: role status: active, previous or future.
10361:
10362: =cut
10363:
10364: sub check_user_status {
1.412 raeburn 10365: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10366: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 10367: my @uroles = keys(%userinfo);
1.274 raeburn 10368: my $srchstr;
10369: my $active_chk = 'none';
1.412 raeburn 10370: my $now = time;
1.274 raeburn 10371: if (@uroles > 0) {
1.908 raeburn 10372: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10373: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10374: } else {
1.412 raeburn 10375: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10376: }
10377: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10378: my $role_end = 0;
10379: my $role_start = 0;
10380: $active_chk = 'active';
1.412 raeburn 10381: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10382: $role_end = $1;
10383: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10384: $role_start = $1;
1.274 raeburn 10385: }
10386: }
10387: if ($role_start > 0) {
1.412 raeburn 10388: if ($now < $role_start) {
1.274 raeburn 10389: $active_chk = 'future';
10390: }
10391: }
10392: if ($role_end > 0) {
1.412 raeburn 10393: if ($now > $role_end) {
1.274 raeburn 10394: $active_chk = 'previous';
10395: }
10396: }
10397: }
10398: }
10399: return $active_chk;
10400: }
10401:
10402: ###############################################
10403:
10404: =pod
10405:
1.405 albertel 10406: =item * &get_sections()
1.233 raeburn 10407:
10408: Determines all the sections for a course including
10409: sections with students and sections containing other roles.
1.419 raeburn 10410: Incoming parameters:
10411:
10412: 1. domain
10413: 2. course number
10414: 3. reference to array containing roles for which sections should
10415: be gathered (optional).
10416: 4. reference to array containing status types for which sections
10417: should be gathered (optional).
10418:
10419: If the third argument is undefined, sections are gathered for any role.
10420: If the fourth argument is undefined, sections are gathered for any status.
10421: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10422:
1.374 raeburn 10423: Returns section hash (keys are section IDs, values are
10424: number of users in each section), subject to the
1.419 raeburn 10425: optional roles filter, optional status filter
1.233 raeburn 10426:
10427: =cut
10428:
10429: ###############################################
10430: sub get_sections {
1.419 raeburn 10431: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10432: if (!defined($cdom) || !defined($cnum)) {
10433: my $cid = $env{'request.course.id'};
10434:
10435: return if (!defined($cid));
10436:
10437: $cdom = $env{'course.'.$cid.'.domain'};
10438: $cnum = $env{'course.'.$cid.'.num'};
10439: }
10440:
10441: my %sectioncount;
1.419 raeburn 10442: my $now = time;
1.240 albertel 10443:
1.1075.2.33 raeburn 10444: my $check_students = 1;
10445: my $only_students = 0;
10446: if (ref($possible_roles) eq 'ARRAY') {
10447: if (grep(/^st$/,@{$possible_roles})) {
10448: if (@{$possible_roles} == 1) {
10449: $only_students = 1;
10450: }
10451: } else {
10452: $check_students = 0;
10453: }
10454: }
10455:
10456: if ($check_students) {
1.276 albertel 10457: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10458: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10459: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10460: my $start_index = &Apache::loncoursedata::CL_START();
10461: my $end_index = &Apache::loncoursedata::CL_END();
10462: my $status;
1.366 albertel 10463: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10464: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10465: $data->[$status_index],
10466: $data->[$start_index],
10467: $data->[$end_index]);
10468: if ($stu_status eq 'Active') {
10469: $status = 'active';
10470: } elsif ($end < $now) {
10471: $status = 'previous';
10472: } elsif ($start > $now) {
10473: $status = 'future';
10474: }
10475: if ($section ne '-1' && $section !~ /^\s*$/) {
10476: if ((!defined($possible_status)) || (($status ne '') &&
10477: (grep/^\Q$status\E$/,@{$possible_status}))) {
10478: $sectioncount{$section}++;
10479: }
1.240 albertel 10480: }
10481: }
10482: }
1.1075.2.33 raeburn 10483: if ($only_students) {
10484: return %sectioncount;
10485: }
1.240 albertel 10486: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10487: foreach my $user (sort(keys(%courseroles))) {
10488: if ($user !~ /^(\w{2})/) { next; }
10489: my ($role) = ($user =~ /^(\w{2})/);
10490: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10491: my ($section,$status);
1.240 albertel 10492: if ($role eq 'cr' &&
10493: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10494: $section=$1;
10495: }
10496: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10497: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10498: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10499: if ($end == -1 && $start == -1) {
10500: next; #deleted role
10501: }
10502: if (!defined($possible_status)) {
10503: $sectioncount{$section}++;
10504: } else {
10505: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10506: $status = 'active';
10507: } elsif ($end < $now) {
10508: $status = 'future';
10509: } elsif ($start > $now) {
10510: $status = 'previous';
10511: }
10512: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10513: $sectioncount{$section}++;
10514: }
10515: }
1.233 raeburn 10516: }
1.366 albertel 10517: return %sectioncount;
1.233 raeburn 10518: }
10519:
1.274 raeburn 10520: ###############################################
1.294 raeburn 10521:
10522: =pod
1.405 albertel 10523:
10524: =item * &get_course_users()
10525:
1.275 raeburn 10526: Retrieves usernames:domains for users in the specified course
10527: with specific role(s), and access status.
10528:
10529: Incoming parameters:
1.277 albertel 10530: 1. course domain
10531: 2. course number
10532: 3. access status: users must have - either active,
1.275 raeburn 10533: previous, future, or all.
1.277 albertel 10534: 4. reference to array of permissible roles
1.288 raeburn 10535: 5. reference to array of section restrictions (optional)
10536: 6. reference to results object (hash of hashes).
10537: 7. reference to optional userdata hash
1.609 raeburn 10538: 8. reference to optional statushash
1.630 raeburn 10539: 9. flag if privileged users (except those set to unhide in
10540: course settings) should be excluded
1.609 raeburn 10541: Keys of top level results hash are roles.
1.275 raeburn 10542: Keys of inner hashes are username:domain, with
10543: values set to access type.
1.288 raeburn 10544: Optional userdata hash returns an array with arguments in the
10545: same order as loncoursedata::get_classlist() for student data.
10546:
1.609 raeburn 10547: Optional statushash returns
10548:
1.288 raeburn 10549: Entries for end, start, section and status are blank because
10550: of the possibility of multiple values for non-student roles.
10551:
1.275 raeburn 10552: =cut
1.405 albertel 10553:
1.275 raeburn 10554: ###############################################
1.405 albertel 10555:
1.275 raeburn 10556: sub get_course_users {
1.630 raeburn 10557: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10558: my %idx = ();
1.419 raeburn 10559: my %seclists;
1.288 raeburn 10560:
10561: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10562: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10563: $idx{end} = &Apache::loncoursedata::CL_END();
10564: $idx{start} = &Apache::loncoursedata::CL_START();
10565: $idx{id} = &Apache::loncoursedata::CL_ID();
10566: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10567: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10568: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10569:
1.290 albertel 10570: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10571: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10572: my $now = time;
1.277 albertel 10573: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10574: my $match = 0;
1.412 raeburn 10575: my $secmatch = 0;
1.419 raeburn 10576: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10577: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10578: if ($section eq '') {
10579: $section = 'none';
10580: }
1.291 albertel 10581: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10582: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10583: $secmatch = 1;
10584: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10585: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10586: $secmatch = 1;
10587: }
10588: } else {
1.419 raeburn 10589: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10590: $secmatch = 1;
10591: }
1.290 albertel 10592: }
1.412 raeburn 10593: if (!$secmatch) {
10594: next;
10595: }
1.419 raeburn 10596: }
1.275 raeburn 10597: if (defined($$types{'active'})) {
1.288 raeburn 10598: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10599: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10600: $match = 1;
1.275 raeburn 10601: }
10602: }
10603: if (defined($$types{'previous'})) {
1.609 raeburn 10604: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10605: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10606: $match = 1;
1.275 raeburn 10607: }
10608: }
10609: if (defined($$types{'future'})) {
1.609 raeburn 10610: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10611: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10612: $match = 1;
1.275 raeburn 10613: }
10614: }
1.609 raeburn 10615: if ($match) {
10616: push(@{$seclists{$student}},$section);
10617: if (ref($userdata) eq 'HASH') {
10618: $$userdata{$student} = $$classlist{$student};
10619: }
10620: if (ref($statushash) eq 'HASH') {
10621: $statushash->{$student}{'st'}{$section} = $status;
10622: }
1.288 raeburn 10623: }
1.275 raeburn 10624: }
10625: }
1.412 raeburn 10626: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10627: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10628: my $now = time;
1.609 raeburn 10629: my %displaystatus = ( previous => 'Expired',
10630: active => 'Active',
10631: future => 'Future',
10632: );
1.1075.2.36 raeburn 10633: my (%nothide,@possdoms);
1.630 raeburn 10634: if ($hidepriv) {
10635: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10636: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10637: if ($user !~ /:/) {
10638: $nothide{join(':',split(/[\@]/,$user))}=1;
10639: } else {
10640: $nothide{$user} = 1;
10641: }
10642: }
1.1075.2.36 raeburn 10643: my @possdoms = ($cdom);
10644: if ($coursehash{'checkforpriv'}) {
10645: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10646: }
1.630 raeburn 10647: }
1.439 raeburn 10648: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10649: my $match = 0;
1.412 raeburn 10650: my $secmatch = 0;
1.439 raeburn 10651: my $status;
1.412 raeburn 10652: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10653: $user =~ s/:$//;
1.439 raeburn 10654: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10655: if ($end == -1 || $start == -1) {
10656: next;
10657: }
10658: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10659: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10660: my ($uname,$udom) = split(/:/,$user);
10661: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10662: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10663: $secmatch = 1;
10664: } elsif ($usec eq '') {
1.420 albertel 10665: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10666: $secmatch = 1;
10667: }
10668: } else {
10669: if (grep(/^\Q$usec\E$/,@{$sections})) {
10670: $secmatch = 1;
10671: }
10672: }
10673: if (!$secmatch) {
10674: next;
10675: }
1.288 raeburn 10676: }
1.419 raeburn 10677: if ($usec eq '') {
10678: $usec = 'none';
10679: }
1.275 raeburn 10680: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10681: if ($hidepriv) {
1.1075.2.36 raeburn 10682: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10683: (!$nothide{$uname.':'.$udom})) {
10684: next;
10685: }
10686: }
1.503 raeburn 10687: if ($end > 0 && $end < $now) {
1.439 raeburn 10688: $status = 'previous';
10689: } elsif ($start > $now) {
10690: $status = 'future';
10691: } else {
10692: $status = 'active';
10693: }
1.277 albertel 10694: foreach my $type (keys(%{$types})) {
1.275 raeburn 10695: if ($status eq $type) {
1.420 albertel 10696: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10697: push(@{$$users{$role}{$user}},$type);
10698: }
1.288 raeburn 10699: $match = 1;
10700: }
10701: }
1.419 raeburn 10702: if (($match) && (ref($userdata) eq 'HASH')) {
10703: if (!exists($$userdata{$uname.':'.$udom})) {
10704: &get_user_info($udom,$uname,\%idx,$userdata);
10705: }
1.420 albertel 10706: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10707: push(@{$seclists{$uname.':'.$udom}},$usec);
10708: }
1.609 raeburn 10709: if (ref($statushash) eq 'HASH') {
10710: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10711: }
1.275 raeburn 10712: }
10713: }
10714: }
10715: }
1.290 albertel 10716: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10717: if ((defined($cdom)) && (defined($cnum))) {
10718: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10719: if ( defined($csettings{'internal.courseowner'}) ) {
10720: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10721: next if ($owner eq '');
10722: my ($ownername,$ownerdom);
10723: if ($owner =~ /^([^:]+):([^:]+)$/) {
10724: $ownername = $1;
10725: $ownerdom = $2;
10726: } else {
10727: $ownername = $owner;
10728: $ownerdom = $cdom;
10729: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10730: }
10731: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10732: if (defined($userdata) &&
1.609 raeburn 10733: !exists($$userdata{$owner})) {
10734: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10735: if (!grep(/^none$/,@{$seclists{$owner}})) {
10736: push(@{$seclists{$owner}},'none');
10737: }
10738: if (ref($statushash) eq 'HASH') {
10739: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10740: }
1.290 albertel 10741: }
1.279 raeburn 10742: }
10743: }
10744: }
1.419 raeburn 10745: foreach my $user (keys(%seclists)) {
10746: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10747: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10748: }
1.275 raeburn 10749: }
10750: return;
10751: }
10752:
1.288 raeburn 10753: sub get_user_info {
10754: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10755: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10756: &plainname($uname,$udom,'lastname');
1.291 albertel 10757: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10758: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10759: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10760: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10761: return;
10762: }
1.275 raeburn 10763:
1.472 raeburn 10764: ###############################################
10765:
10766: =pod
10767:
10768: =item * &get_user_quota()
10769:
1.1075.2.41 raeburn 10770: Retrieves quota assigned for storage of user files.
10771: Default is to report quota for portfolio files.
1.472 raeburn 10772:
10773: Incoming parameters:
10774: 1. user's username
10775: 2. user's domain
1.1075.2.41 raeburn 10776: 3. quota name - portfolio, author, or course
10777: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10778: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10779: course
1.472 raeburn 10780:
10781: Returns:
1.1075.2.58 raeburn 10782: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10783: 2. (Optional) Type of setting: custom or default
10784: (individually assigned or default for user's
10785: institutional status).
10786: 3. (Optional) - User's institutional status (e.g., faculty, staff
10787: or student - types as defined in localenroll::inst_usertypes
10788: for user's domain, which determines default quota for user.
10789: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10790:
10791: If a value has been stored in the user's environment,
1.536 raeburn 10792: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10793: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10794:
10795: =cut
10796:
10797: ###############################################
10798:
10799:
10800: sub get_user_quota {
1.1075.2.42 raeburn 10801: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10802: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10803: if (!defined($udom)) {
10804: $udom = $env{'user.domain'};
10805: }
10806: if (!defined($uname)) {
10807: $uname = $env{'user.name'};
10808: }
10809: if (($udom eq '' || $uname eq '') ||
10810: ($udom eq 'public') && ($uname eq 'public')) {
10811: $quota = 0;
1.536 raeburn 10812: $quotatype = 'default';
10813: $defquota = 0;
1.472 raeburn 10814: } else {
1.536 raeburn 10815: my $inststatus;
1.1075.2.41 raeburn 10816: if ($quotaname eq 'course') {
10817: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10818: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10819: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10820: } else {
10821: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10822: $quota = $cenv{'internal.uploadquota'};
10823: }
1.536 raeburn 10824: } else {
1.1075.2.41 raeburn 10825: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10826: if ($quotaname eq 'author') {
10827: $quota = $env{'environment.authorquota'};
10828: } else {
10829: $quota = $env{'environment.portfolioquota'};
10830: }
10831: $inststatus = $env{'environment.inststatus'};
10832: } else {
10833: my %userenv =
10834: &Apache::lonnet::get('environment',['portfolioquota',
10835: 'authorquota','inststatus'],$udom,$uname);
10836: my ($tmp) = keys(%userenv);
10837: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10838: if ($quotaname eq 'author') {
10839: $quota = $userenv{'authorquota'};
10840: } else {
10841: $quota = $userenv{'portfolioquota'};
10842: }
10843: $inststatus = $userenv{'inststatus'};
10844: } else {
10845: undef(%userenv);
10846: }
10847: }
10848: }
10849: if ($quota eq '' || wantarray) {
10850: if ($quotaname eq 'course') {
10851: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10852: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10853: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10854: $defquota = $domdefs{$crstype.'quota'};
10855: }
10856: if ($defquota eq '') {
10857: $defquota = 500;
10858: }
1.1075.2.41 raeburn 10859: } else {
10860: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10861: }
10862: if ($quota eq '') {
10863: $quota = $defquota;
10864: $quotatype = 'default';
10865: } else {
10866: $quotatype = 'custom';
10867: }
1.472 raeburn 10868: }
10869: }
1.536 raeburn 10870: if (wantarray) {
10871: return ($quota,$quotatype,$settingstatus,$defquota);
10872: } else {
10873: return $quota;
10874: }
1.472 raeburn 10875: }
10876:
10877: ###############################################
10878:
10879: =pod
10880:
10881: =item * &default_quota()
10882:
1.536 raeburn 10883: Retrieves default quota assigned for storage of user portfolio files,
10884: given an (optional) user's institutional status.
1.472 raeburn 10885:
10886: Incoming parameters:
1.1075.2.42 raeburn 10887:
1.472 raeburn 10888: 1. domain
1.536 raeburn 10889: 2. (Optional) institutional status(es). This is a : separated list of
10890: status types (e.g., faculty, staff, student etc.)
10891: which apply to the user for whom the default is being retrieved.
10892: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10893: default quota will be returned.
10894: 3. quota name - portfolio, author, or course
10895: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10896:
10897: Returns:
1.1075.2.42 raeburn 10898:
1.1075.2.58 raeburn 10899: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10900: 2. (Optional) institutional type which determined the value of the
10901: default quota.
1.472 raeburn 10902:
10903: If a value has been stored in the domain's configuration db,
10904: it will return that, otherwise it returns 20 (for backwards
10905: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10906: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10907:
1.536 raeburn 10908: If the user's status includes multiple types (e.g., staff and student),
10909: the largest default quota which applies to the user determines the
10910: default quota returned.
10911:
1.472 raeburn 10912: =cut
10913:
10914: ###############################################
10915:
10916:
10917: sub default_quota {
1.1075.2.41 raeburn 10918: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10919: my ($defquota,$settingstatus);
10920: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10921: ['quotas'],$udom);
1.1075.2.41 raeburn 10922: my $key = 'defaultquota';
10923: if ($quotaname eq 'author') {
10924: $key = 'authorquota';
10925: }
1.622 raeburn 10926: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10927: if ($inststatus ne '') {
1.765 raeburn 10928: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10929: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10930: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10931: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10932: if ($defquota eq '') {
1.1075.2.41 raeburn 10933: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10934: $settingstatus = $item;
1.1075.2.41 raeburn 10935: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10936: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10937: $settingstatus = $item;
10938: }
10939: }
1.1075.2.41 raeburn 10940: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10941: if ($quotahash{'quotas'}{$item} ne '') {
10942: if ($defquota eq '') {
10943: $defquota = $quotahash{'quotas'}{$item};
10944: $settingstatus = $item;
10945: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10946: $defquota = $quotahash{'quotas'}{$item};
10947: $settingstatus = $item;
10948: }
1.536 raeburn 10949: }
10950: }
10951: }
10952: }
10953: if ($defquota eq '') {
1.1075.2.41 raeburn 10954: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10955: $defquota = $quotahash{'quotas'}{$key}{'default'};
10956: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10957: $defquota = $quotahash{'quotas'}{'default'};
10958: }
1.536 raeburn 10959: $settingstatus = 'default';
1.1075.2.42 raeburn 10960: if ($defquota eq '') {
10961: if ($quotaname eq 'author') {
10962: $defquota = 500;
10963: }
10964: }
1.536 raeburn 10965: }
10966: } else {
10967: $settingstatus = 'default';
1.1075.2.41 raeburn 10968: if ($quotaname eq 'author') {
10969: $defquota = 500;
10970: } else {
10971: $defquota = 20;
10972: }
1.536 raeburn 10973: }
10974: if (wantarray) {
10975: return ($defquota,$settingstatus);
1.472 raeburn 10976: } else {
1.536 raeburn 10977: return $defquota;
1.472 raeburn 10978: }
10979: }
10980:
1.1075.2.41 raeburn 10981: ###############################################
10982:
10983: =pod
10984:
1.1075.2.42 raeburn 10985: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 10986:
10987: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 10988: of existing file within authoring space will cause quota for the authoring
10989: space to be exceeded.
10990:
10991: Same, if upload of a file directly to a course/community via Course Editor
10992: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 10993:
1.1075.2.61 raeburn 10994: Inputs: 7
1.1075.2.42 raeburn 10995: 1. username or coursenum
1.1075.2.41 raeburn 10996: 2. domain
1.1075.2.42 raeburn 10997: 3. context ('author' or 'course')
1.1075.2.41 raeburn 10998: 4. filename of file for which action is being requested
10999: 5. filesize (kB) of file
11000: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 11001: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 11002:
11003: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
11004: otherwise return null.
11005:
1.1075.2.42 raeburn 11006: =back
11007:
1.1075.2.41 raeburn 11008: =cut
11009:
1.1075.2.42 raeburn 11010: sub excess_filesize_warning {
1.1075.2.59 raeburn 11011: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 11012: my $current_disk_usage = 0;
1.1075.2.59 raeburn 11013: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 11014: if ($context eq 'author') {
11015: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11016: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11017: } else {
11018: foreach my $subdir ('docs','supplemental') {
11019: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11020: }
11021: }
1.1075.2.41 raeburn 11022: $disk_quota = int($disk_quota * 1000);
11023: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 11024: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 11025: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 11026: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11027: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 11028: $disk_quota,$current_disk_usage).
11029: '</p>';
11030: }
11031: return;
11032: }
11033:
11034: ###############################################
11035:
11036:
1.384 raeburn 11037: sub get_secgrprole_info {
11038: my ($cdom,$cnum,$needroles,$type) = @_;
11039: my %sections_count = &get_sections($cdom,$cnum);
11040: my @sections = (sort {$a <=> $b} keys(%sections_count));
11041: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11042: my @groups = sort(keys(%curr_groups));
11043: my $allroles = [];
11044: my $rolehash;
11045: my $accesshash = {
11046: active => 'Currently has access',
11047: future => 'Will have future access',
11048: previous => 'Previously had access',
11049: };
11050: if ($needroles) {
11051: $rolehash = {'all' => 'all'};
1.385 albertel 11052: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11053: if (&Apache::lonnet::error(%user_roles)) {
11054: undef(%user_roles);
11055: }
11056: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11057: my ($role)=split(/\:/,$item,2);
11058: if ($role eq 'cr') { next; }
11059: if ($role =~ /^cr/) {
11060: $$rolehash{$role} = (split('/',$role))[3];
11061: } else {
11062: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11063: }
11064: }
11065: foreach my $key (sort(keys(%{$rolehash}))) {
11066: push(@{$allroles},$key);
11067: }
11068: push (@{$allroles},'st');
11069: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11070: }
11071: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11072: }
11073:
1.555 raeburn 11074: sub user_picker {
1.1075.2.127 raeburn 11075: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11076: my $currdom = $dom;
1.1075.2.114 raeburn 11077: my @alldoms = &Apache::lonnet::all_domains();
11078: if (@alldoms == 1) {
11079: my %domsrch = &Apache::lonnet::get_dom('configuration',
11080: ['directorysrch'],$alldoms[0]);
11081: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11082: my $showdom = $domdesc;
11083: if ($showdom eq '') {
11084: $showdom = $dom;
11085: }
11086: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11087: if ((!$domsrch{'directorysrch'}{'available'}) &&
11088: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11089: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11090: }
11091: }
11092: }
1.555 raeburn 11093: my %curr_selected = (
11094: srchin => 'dom',
1.580 raeburn 11095: srchby => 'lastname',
1.555 raeburn 11096: );
11097: my $srchterm;
1.625 raeburn 11098: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11099: if ($srch->{'srchby'} ne '') {
11100: $curr_selected{'srchby'} = $srch->{'srchby'};
11101: }
11102: if ($srch->{'srchin'} ne '') {
11103: $curr_selected{'srchin'} = $srch->{'srchin'};
11104: }
11105: if ($srch->{'srchtype'} ne '') {
11106: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11107: }
11108: if ($srch->{'srchdomain'} ne '') {
11109: $currdom = $srch->{'srchdomain'};
11110: }
11111: $srchterm = $srch->{'srchterm'};
11112: }
1.1075.2.98 raeburn 11113: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11114: 'usr' => 'Search criteria',
1.563 raeburn 11115: 'doma' => 'Domain/institution to search',
1.558 albertel 11116: 'uname' => 'username',
11117: 'lastname' => 'last name',
1.555 raeburn 11118: 'lastfirst' => 'last name, first name',
1.558 albertel 11119: 'crs' => 'in this course',
1.576 raeburn 11120: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11121: 'alc' => 'all LON-CAPA',
1.573 raeburn 11122: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11123: 'exact' => 'is',
11124: 'contains' => 'contains',
1.569 raeburn 11125: 'begins' => 'begins with',
1.1075.2.98 raeburn 11126: );
11127: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11128: 'youm' => "You must include some text to search for.",
11129: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11130: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11131: 'yomc' => "You must choose a domain when using an institutional directory search.",
11132: 'ymcd' => "You must choose a domain when using a domain search.",
11133: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11134: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11135: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11136: );
1.1075.2.98 raeburn 11137: &html_escape(\%html_lt);
11138: &js_escape(\%js_lt);
1.1075.2.115 raeburn 11139: my $domform;
1.1075.2.126 raeburn 11140: my $allow_blank = 1;
1.1075.2.115 raeburn 11141: if ($fixeddom) {
1.1075.2.126 raeburn 11142: $allow_blank = 0;
11143: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 11144: } else {
1.1075.2.126 raeburn 11145: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 11146: }
1.563 raeburn 11147: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11148:
11149: my @srchins = ('crs','dom','alc','instd');
11150:
11151: foreach my $option (@srchins) {
11152: # FIXME 'alc' option unavailable until
11153: # loncreateuser::print_user_query_page()
11154: # has been completed.
11155: next if ($option eq 'alc');
1.880 raeburn 11156: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11157: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 11158: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11159: if ($curr_selected{'srchin'} eq $option) {
11160: $srchinsel .= '
1.1075.2.98 raeburn 11161: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11162: } else {
11163: $srchinsel .= '
1.1075.2.98 raeburn 11164: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11165: }
1.555 raeburn 11166: }
1.563 raeburn 11167: $srchinsel .= "\n </select>\n";
1.555 raeburn 11168:
11169: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11170: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11171: if ($curr_selected{'srchby'} eq $option) {
11172: $srchbysel .= '
1.1075.2.98 raeburn 11173: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11174: } else {
11175: $srchbysel .= '
1.1075.2.98 raeburn 11176: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11177: }
11178: }
11179: $srchbysel .= "\n </select>\n";
11180:
11181: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11182: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11183: if ($curr_selected{'srchtype'} eq $option) {
11184: $srchtypesel .= '
1.1075.2.98 raeburn 11185: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11186: } else {
11187: $srchtypesel .= '
1.1075.2.98 raeburn 11188: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11189: }
11190: }
11191: $srchtypesel .= "\n </select>\n";
11192:
1.558 albertel 11193: my ($newuserscript,$new_user_create);
1.994 raeburn 11194: my $context_dom = $env{'request.role.domain'};
11195: if ($context eq 'requestcrs') {
11196: if ($env{'form.coursedom'} ne '') {
11197: $context_dom = $env{'form.coursedom'};
11198: }
11199: }
1.556 raeburn 11200: if ($forcenewuser) {
1.576 raeburn 11201: if (ref($srch) eq 'HASH') {
1.994 raeburn 11202: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11203: if ($cancreate) {
11204: $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>';
11205: } else {
1.799 bisitz 11206: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11207: my %usertypetext = (
11208: official => 'institutional',
11209: unofficial => 'non-institutional',
11210: );
1.799 bisitz 11211: $new_user_create = '<p class="LC_warning">'
11212: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11213: .' '
11214: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11215: ,'<a href="'.$helplink.'">','</a>')
11216: .'</p><br />';
1.627 raeburn 11217: }
1.576 raeburn 11218: }
11219: }
11220:
1.556 raeburn 11221: $newuserscript = <<"ENDSCRIPT";
11222:
1.570 raeburn 11223: function setSearch(createnew,callingForm) {
1.556 raeburn 11224: if (createnew == 1) {
1.570 raeburn 11225: for (var i=0; i<callingForm.srchby.length; i++) {
11226: if (callingForm.srchby.options[i].value == 'uname') {
11227: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11228: }
11229: }
1.570 raeburn 11230: for (var i=0; i<callingForm.srchin.length; i++) {
11231: if ( callingForm.srchin.options[i].value == 'dom') {
11232: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11233: }
11234: }
1.570 raeburn 11235: for (var i=0; i<callingForm.srchtype.length; i++) {
11236: if (callingForm.srchtype.options[i].value == 'exact') {
11237: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11238: }
11239: }
1.570 raeburn 11240: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11241: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11242: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11243: }
11244: }
11245: }
11246: }
11247: ENDSCRIPT
1.558 albertel 11248:
1.556 raeburn 11249: }
11250:
1.555 raeburn 11251: my $output = <<"END_BLOCK";
1.556 raeburn 11252: <script type="text/javascript">
1.824 bisitz 11253: // <![CDATA[
1.570 raeburn 11254: function validateEntry(callingForm) {
1.558 albertel 11255:
1.556 raeburn 11256: var checkok = 1;
1.558 albertel 11257: var srchin;
1.570 raeburn 11258: for (var i=0; i<callingForm.srchin.length; i++) {
11259: if ( callingForm.srchin[i].checked ) {
11260: srchin = callingForm.srchin[i].value;
1.558 albertel 11261: }
11262: }
11263:
1.570 raeburn 11264: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11265: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11266: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11267: var srchterm = callingForm.srchterm.value;
11268: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11269: var msg = "";
11270:
11271: if (srchterm == "") {
11272: checkok = 0;
1.1075.2.98 raeburn 11273: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11274: }
11275:
1.569 raeburn 11276: if (srchtype== 'begins') {
11277: if (srchterm.length < 2) {
11278: checkok = 0;
1.1075.2.98 raeburn 11279: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11280: }
11281: }
11282:
1.556 raeburn 11283: if (srchtype== 'contains') {
11284: if (srchterm.length < 3) {
11285: checkok = 0;
1.1075.2.98 raeburn 11286: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11287: }
11288: }
11289: if (srchin == 'instd') {
11290: if (srchdomain == '') {
11291: checkok = 0;
1.1075.2.98 raeburn 11292: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11293: }
11294: }
11295: if (srchin == 'dom') {
11296: if (srchdomain == '') {
11297: checkok = 0;
1.1075.2.98 raeburn 11298: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11299: }
11300: }
11301: if (srchby == 'lastfirst') {
11302: if (srchterm.indexOf(",") == -1) {
11303: checkok = 0;
1.1075.2.98 raeburn 11304: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11305: }
11306: if (srchterm.indexOf(",") == srchterm.length -1) {
11307: checkok = 0;
1.1075.2.98 raeburn 11308: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11309: }
11310: }
11311: if (checkok == 0) {
1.1075.2.98 raeburn 11312: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11313: return;
11314: }
11315: if (checkok == 1) {
1.570 raeburn 11316: callingForm.submit();
1.556 raeburn 11317: }
11318: }
11319:
11320: $newuserscript
11321:
1.824 bisitz 11322: // ]]>
1.556 raeburn 11323: </script>
1.558 albertel 11324:
11325: $new_user_create
11326:
1.555 raeburn 11327: END_BLOCK
1.558 albertel 11328:
1.876 raeburn 11329: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 11330: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11331: $domform.
11332: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 11333: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11334: $srchbysel.
11335: $srchtypesel.
11336: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11337: $srchinsel.
11338: &Apache::lonhtmlcommon::row_closure(1).
11339: &Apache::lonhtmlcommon::end_pick_box().
11340: '<br />';
1.1075.2.114 raeburn 11341: return ($output,1);
1.555 raeburn 11342: }
11343:
1.612 raeburn 11344: sub user_rule_check {
1.615 raeburn 11345: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 11346: my ($response,%inst_response);
1.612 raeburn 11347: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 11348: if (keys(%{$usershash}) > 1) {
11349: my (%by_username,%by_id,%userdoms);
11350: my $checkid;
1.612 raeburn 11351: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 11352: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11353: $checkid = 1;
11354: }
11355: }
11356: foreach my $user (keys(%{$usershash})) {
11357: my ($uname,$udom) = split(/:/,$user);
11358: if ($checkid) {
11359: if (ref($usershash->{$user}) eq 'HASH') {
11360: if ($usershash->{$user}->{'id'} ne '') {
11361: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
11362: $userdoms{$udom} = 1;
11363: if (ref($inst_results) eq 'HASH') {
11364: $inst_results->{$uname.':'.$udom} = {};
11365: }
11366: }
11367: }
11368: } else {
11369: $by_username{$udom}{$uname} = 1;
11370: $userdoms{$udom} = 1;
11371: if (ref($inst_results) eq 'HASH') {
11372: $inst_results->{$uname.':'.$udom} = {};
11373: }
11374: }
11375: }
11376: foreach my $udom (keys(%userdoms)) {
11377: if (!$got_rules->{$udom}) {
11378: my %domconfig = &Apache::lonnet::get_dom('configuration',
11379: ['usercreation'],$udom);
11380: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11381: foreach my $item ('username','id') {
11382: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11383: $$curr_rules{$udom}{$item} =
11384: $domconfig{'usercreation'}{$item.'_rule'};
11385: }
11386: }
11387: }
11388: $got_rules->{$udom} = 1;
11389: }
11390: }
11391: if ($checkid) {
11392: foreach my $udom (keys(%by_id)) {
11393: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11394: if ($outcome eq 'ok') {
11395: foreach my $id (keys(%{$by_id{$udom}})) {
11396: my $uname = $by_id{$udom}{$id};
11397: $inst_response{$uname.':'.$udom} = $outcome;
11398: }
11399: if (ref($results) eq 'HASH') {
11400: foreach my $uname (keys(%{$results})) {
11401: if (exists($inst_response{$uname.':'.$udom})) {
11402: $inst_response{$uname.':'.$udom} = $outcome;
11403: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11404: }
11405: }
11406: }
11407: }
1.612 raeburn 11408: }
1.615 raeburn 11409: } else {
1.1075.2.99 raeburn 11410: foreach my $udom (keys(%by_username)) {
11411: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11412: if ($outcome eq 'ok') {
11413: foreach my $uname (keys(%{$by_username{$udom}})) {
11414: $inst_response{$uname.':'.$udom} = $outcome;
11415: }
11416: if (ref($results) eq 'HASH') {
11417: foreach my $uname (keys(%{$results})) {
11418: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11419: }
11420: }
11421: }
11422: }
1.612 raeburn 11423: }
1.1075.2.99 raeburn 11424: } elsif (keys(%{$usershash}) == 1) {
11425: my $user = (keys(%{$usershash}))[0];
11426: my ($uname,$udom) = split(/:/,$user);
11427: if (($udom ne '') && ($uname ne '')) {
11428: if (ref($usershash->{$user}) eq 'HASH') {
11429: if (ref($checks) eq 'HASH') {
11430: if (defined($checks->{'username'})) {
11431: ($inst_response{$user},%{$inst_results->{$user}}) =
11432: &Apache::lonnet::get_instuser($udom,$uname);
11433: } elsif (defined($checks->{'id'})) {
11434: if ($usershash->{$user}->{'id'} ne '') {
11435: ($inst_response{$user},%{$inst_results->{$user}}) =
11436: &Apache::lonnet::get_instuser($udom,undef,
11437: $usershash->{$user}->{'id'});
11438: } else {
11439: ($inst_response{$user},%{$inst_results->{$user}}) =
11440: &Apache::lonnet::get_instuser($udom,$uname);
11441: }
11442: }
11443: } else {
11444: ($inst_response{$user},%{$inst_results->{$user}}) =
11445: &Apache::lonnet::get_instuser($udom,$uname);
11446: return;
11447: }
11448: if (!$got_rules->{$udom}) {
11449: my %domconfig = &Apache::lonnet::get_dom('configuration',
11450: ['usercreation'],$udom);
11451: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11452: foreach my $item ('username','id') {
11453: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11454: $$curr_rules{$udom}{$item} =
11455: $domconfig{'usercreation'}{$item.'_rule'};
11456: }
11457: }
1.585 raeburn 11458: }
1.1075.2.99 raeburn 11459: $got_rules->{$udom} = 1;
1.585 raeburn 11460: }
11461: }
1.1075.2.99 raeburn 11462: } else {
11463: return;
11464: }
11465: } else {
11466: return;
11467: }
11468: foreach my $user (keys(%{$usershash})) {
11469: my ($uname,$udom) = split(/:/,$user);
11470: next if (($udom eq '') || ($uname eq ''));
11471: my $id;
11472: if (ref($inst_results) eq 'HASH') {
11473: if (ref($inst_results->{$user}) eq 'HASH') {
11474: $id = $inst_results->{$user}->{'id'};
11475: }
11476: }
11477: if ($id eq '') {
11478: if (ref($usershash->{$user})) {
11479: $id = $usershash->{$user}->{'id'};
11480: }
1.585 raeburn 11481: }
1.612 raeburn 11482: foreach my $item (keys(%{$checks})) {
11483: if (ref($$curr_rules{$udom}) eq 'HASH') {
11484: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11485: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 11486: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11487: $$curr_rules{$udom}{$item});
1.612 raeburn 11488: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11489: if ($rule_check{$rule}) {
11490: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 11491: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11492: if (ref($inst_results) eq 'HASH') {
11493: if (ref($inst_results->{$user}) eq 'HASH') {
11494: if (keys(%{$inst_results->{$user}}) == 0) {
11495: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 11496: } elsif ($item eq 'id') {
11497: if ($inst_results->{$user}->{'id'} eq '') {
11498: $$alerts{$item}{$udom}{$uname} = 1;
11499: }
1.615 raeburn 11500: }
1.612 raeburn 11501: }
11502: }
1.615 raeburn 11503: }
11504: last;
1.585 raeburn 11505: }
11506: }
11507: }
11508: }
11509: }
11510: }
11511: }
11512: }
1.612 raeburn 11513: return;
11514: }
11515:
11516: sub user_rule_formats {
11517: my ($domain,$domdesc,$curr_rules,$check) = @_;
11518: my %text = (
11519: 'username' => 'Usernames',
11520: 'id' => 'IDs',
11521: );
11522: my $output;
11523: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11524: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11525: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 11526: $output = '<br />'.
11527: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11528: '<span class="LC_cusr_emph">','</span>',$domdesc).
11529: ' <ul>';
1.612 raeburn 11530: foreach my $rule (@{$ruleorder}) {
11531: if (ref($curr_rules) eq 'ARRAY') {
11532: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11533: if (ref($rules->{$rule}) eq 'HASH') {
11534: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11535: $rules->{$rule}{'desc'}.'</li>';
11536: }
11537: }
11538: }
11539: }
11540: $output .= '</ul>';
11541: }
11542: }
11543: return $output;
11544: }
11545:
11546: sub instrule_disallow_msg {
1.615 raeburn 11547: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11548: my $response;
11549: my %text = (
11550: item => 'username',
11551: items => 'usernames',
11552: match => 'matches',
11553: do => 'does',
11554: action => 'a username',
11555: one => 'one',
11556: );
11557: if ($count > 1) {
11558: $text{'item'} = 'usernames';
11559: $text{'match'} ='match';
11560: $text{'do'} = 'do';
11561: $text{'action'} = 'usernames',
11562: $text{'one'} = 'ones';
11563: }
11564: if ($checkitem eq 'id') {
11565: $text{'items'} = 'IDs';
11566: $text{'item'} = 'ID';
11567: $text{'action'} = 'an ID';
1.615 raeburn 11568: if ($count > 1) {
11569: $text{'item'} = 'IDs';
11570: $text{'action'} = 'IDs';
11571: }
1.612 raeburn 11572: }
1.674 bisitz 11573: $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 11574: if ($mode eq 'upload') {
11575: if ($checkitem eq 'username') {
11576: $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'}.");
11577: } elsif ($checkitem eq 'id') {
1.674 bisitz 11578: $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 11579: }
1.669 raeburn 11580: } elsif ($mode eq 'selfcreate') {
11581: if ($checkitem eq 'id') {
11582: $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.");
11583: }
1.615 raeburn 11584: } else {
11585: if ($checkitem eq 'username') {
11586: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11587: } elsif ($checkitem eq 'id') {
11588: $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.");
11589: }
1.612 raeburn 11590: }
11591: return $response;
1.585 raeburn 11592: }
11593:
1.624 raeburn 11594: sub personal_data_fieldtitles {
11595: my %fieldtitles = &Apache::lonlocal::texthash (
11596: id => 'Student/Employee ID',
11597: permanentemail => 'E-mail address',
11598: lastname => 'Last Name',
11599: firstname => 'First Name',
11600: middlename => 'Middle Name',
11601: generation => 'Generation',
11602: gen => 'Generation',
1.765 raeburn 11603: inststatus => 'Affiliation',
1.624 raeburn 11604: );
11605: return %fieldtitles;
11606: }
11607:
1.642 raeburn 11608: sub sorted_inst_types {
11609: my ($dom) = @_;
1.1075.2.70 raeburn 11610: my ($usertypes,$order);
11611: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11612: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11613: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11614: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11615: } else {
11616: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11617: }
1.642 raeburn 11618: my $othertitle = &mt('All users');
11619: if ($env{'request.course.id'}) {
1.668 raeburn 11620: $othertitle = &mt('Any users');
1.642 raeburn 11621: }
11622: my @types;
11623: if (ref($order) eq 'ARRAY') {
11624: @types = @{$order};
11625: }
11626: if (@types == 0) {
11627: if (ref($usertypes) eq 'HASH') {
11628: @types = sort(keys(%{$usertypes}));
11629: }
11630: }
11631: if (keys(%{$usertypes}) > 0) {
11632: $othertitle = &mt('Other users');
11633: }
11634: return ($othertitle,$usertypes,\@types);
11635: }
11636:
1.645 raeburn 11637: sub get_institutional_codes {
1.1075.2.157 raeburn 11638: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11639: # Get complete list of course sections to update
11640: my @currsections = ();
11641: my @currxlists = ();
1.1075.2.157 raeburn 11642: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11643: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11644: my $crskey = $crs.':'.$coursecode;
11645: @{$unclutteredsec{$crskey}} = ();
11646: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11647:
11648: if ($$settings{'internal.sectionnums'} ne '') {
11649: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11650: }
11651:
11652: if ($$settings{'internal.crosslistings'} ne '') {
11653: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11654: }
11655:
11656: if (@currxlists > 0) {
1.1075.2.157 raeburn 11657: foreach my $xl (@currxlists) {
11658: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11659: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11660: push(@{$allcourses},$1);
1.645 raeburn 11661: $$LC_code{$1} = $2;
11662: }
11663: }
11664: }
11665: }
1.1075.2.157 raeburn 11666:
1.645 raeburn 11667: if (@currsections > 0) {
1.1075.2.157 raeburn 11668: foreach my $sec (@currsections) {
11669: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11670: my $instsec = $1;
1.645 raeburn 11671: my $lc_sec = $2;
1.1075.2.157 raeburn 11672: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11673: push(@{$unclutteredsec{$crskey}},$instsec);
11674: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11675: }
11676: }
11677: }
11678: }
11679:
11680: if (@{$unclutteredsec{$crskey}} > 0) {
11681: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11682: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11683: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11684: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11685: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11686: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11687: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11688: }
11689: }
11690: }
11691: }
11692: return;
11693: }
11694:
1.971 raeburn 11695: sub get_standard_codeitems {
11696: return ('Year','Semester','Department','Number','Section');
11697: }
11698:
1.112 bowersj2 11699: =pod
11700:
1.780 raeburn 11701: =head1 Slot Helpers
11702:
11703: =over 4
11704:
11705: =item * sorted_slots()
11706:
1.1040 raeburn 11707: Sorts an array of slot names in order of an optional sort key,
11708: default sort is by slot start time (earliest first).
1.780 raeburn 11709:
11710: Inputs:
11711:
11712: =over 4
11713:
11714: slotsarr - Reference to array of unsorted slot names.
11715:
11716: slots - Reference to hash of hash, where outer hash keys are slot names.
11717:
1.1040 raeburn 11718: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11719:
1.549 albertel 11720: =back
11721:
1.780 raeburn 11722: Returns:
11723:
11724: =over 4
11725:
1.1040 raeburn 11726: sorted - An array of slot names sorted by a specified sort key
11727: (default sort key is start time of the slot).
1.780 raeburn 11728:
11729: =back
11730:
11731: =cut
11732:
11733:
11734: sub sorted_slots {
1.1040 raeburn 11735: my ($slotsarr,$slots,$sortkey) = @_;
11736: if ($sortkey eq '') {
11737: $sortkey = 'starttime';
11738: }
1.780 raeburn 11739: my @sorted;
11740: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11741: @sorted =
11742: sort {
11743: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11744: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11745: }
11746: if (ref($slots->{$a})) { return -1;}
11747: if (ref($slots->{$b})) { return 1;}
11748: return 0;
11749: } @{$slotsarr};
11750: }
11751: return @sorted;
11752: }
11753:
1.1040 raeburn 11754: =pod
11755:
11756: =item * get_future_slots()
11757:
11758: Inputs:
11759:
11760: =over 4
11761:
11762: cnum - course number
11763:
11764: cdom - course domain
11765:
11766: now - current UNIX time
11767:
11768: symb - optional symb
11769:
11770: =back
11771:
11772: Returns:
11773:
11774: =over 4
11775:
11776: sorted_reservable - ref to array of student_schedulable slots currently
11777: reservable, ordered by end date of reservation period.
11778:
11779: reservable_now - ref to hash of student_schedulable slots currently
11780: reservable.
11781:
11782: Keys in inner hash are:
11783: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11784: (b) endreserve: end date of reservation period.
11785: (c) uniqueperiod: start,end dates when slot is to be uniquely
11786: selected.
1.1040 raeburn 11787:
11788: sorted_future - ref to array of student_schedulable slots reservable in
11789: the future, ordered by start date of reservation period.
11790:
11791: future_reservable - ref to hash of student_schedulable slots reservable
11792: in the future.
11793:
11794: Keys in inner hash are:
11795: (a) symb: either blank or symb to which slot use is restricted.
11796: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11797: (c) uniqueperiod: start,end dates when slot is to be uniquely
11798: selected.
1.1040 raeburn 11799:
11800: =back
11801:
11802: =cut
11803:
11804: sub get_future_slots {
11805: my ($cnum,$cdom,$now,$symb) = @_;
11806: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11807: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11808: foreach my $slot (keys(%slots)) {
11809: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11810: if ($symb) {
11811: next if (($slots{$slot}->{'symb'} ne '') &&
11812: ($slots{$slot}->{'symb'} ne $symb));
11813: }
11814: if (($slots{$slot}->{'starttime'} > $now) &&
11815: ($slots{$slot}->{'endtime'} > $now)) {
11816: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11817: my $userallowed = 0;
11818: if ($slots{$slot}->{'allowedsections'}) {
11819: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11820: if (!defined($env{'request.role.sec'})
11821: && grep(/^No section assigned$/,@allowed_sec)) {
11822: $userallowed=1;
11823: } else {
11824: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11825: $userallowed=1;
11826: }
11827: }
11828: unless ($userallowed) {
11829: if (defined($env{'request.course.groups'})) {
11830: my @groups = split(/:/,$env{'request.course.groups'});
11831: foreach my $group (@groups) {
11832: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11833: $userallowed=1;
11834: last;
11835: }
11836: }
11837: }
11838: }
11839: }
11840: if ($slots{$slot}->{'allowedusers'}) {
11841: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11842: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11843: if (grep(/^\Q$user\E$/,@allowed_users)) {
11844: $userallowed = 1;
11845: }
11846: }
11847: next unless($userallowed);
11848: }
11849: my $startreserve = $slots{$slot}->{'startreserve'};
11850: my $endreserve = $slots{$slot}->{'endreserve'};
11851: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11852: my $uniqueperiod;
11853: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11854: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11855: }
1.1040 raeburn 11856: if (($startreserve < $now) &&
11857: (!$endreserve || $endreserve > $now)) {
11858: my $lastres = $endreserve;
11859: if (!$lastres) {
11860: $lastres = $slots{$slot}->{'starttime'};
11861: }
11862: $reservable_now{$slot} = {
11863: symb => $symb,
1.1075.2.104 raeburn 11864: endreserve => $lastres,
11865: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11866: };
11867: } elsif (($startreserve > $now) &&
11868: (!$endreserve || $endreserve > $startreserve)) {
11869: $future_reservable{$slot} = {
11870: symb => $symb,
1.1075.2.104 raeburn 11871: startreserve => $startreserve,
11872: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11873: };
11874: }
11875: }
11876: }
11877: my @unsorted_reservable = keys(%reservable_now);
11878: if (@unsorted_reservable > 0) {
11879: @sorted_reservable =
11880: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11881: }
11882: my @unsorted_future = keys(%future_reservable);
11883: if (@unsorted_future > 0) {
11884: @sorted_future =
11885: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11886: }
11887: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11888: }
1.780 raeburn 11889:
11890: =pod
11891:
1.1057 foxr 11892: =back
11893:
1.549 albertel 11894: =head1 HTTP Helpers
11895:
11896: =over 4
11897:
1.648 raeburn 11898: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11899:
1.258 albertel 11900: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11901: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11902: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11903:
11904: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11905: $possible_names is an ref to an array of form element names. As an example:
11906: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11907: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11908:
11909: =cut
1.1 albertel 11910:
1.6 albertel 11911: sub get_unprocessed_cgi {
1.25 albertel 11912: my ($query,$possible_names)= @_;
1.26 matthew 11913: # $Apache::lonxml::debug=1;
1.356 albertel 11914: foreach my $pair (split(/&/,$query)) {
11915: my ($name, $value) = split(/=/,$pair);
1.369 www 11916: $name = &unescape($name);
1.25 albertel 11917: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11918: $value =~ tr/+/ /;
11919: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11920: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11921: }
1.16 harris41 11922: }
1.6 albertel 11923: }
11924:
1.112 bowersj2 11925: =pod
11926:
1.648 raeburn 11927: =item * &cacheheader()
1.112 bowersj2 11928:
11929: returns cache-controlling header code
11930:
11931: =cut
11932:
1.7 albertel 11933: sub cacheheader {
1.258 albertel 11934: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11935: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11936: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11937: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11938: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11939: return $output;
1.7 albertel 11940: }
11941:
1.112 bowersj2 11942: =pod
11943:
1.648 raeburn 11944: =item * &no_cache($r)
1.112 bowersj2 11945:
11946: specifies header code to not have cache
11947:
11948: =cut
11949:
1.9 albertel 11950: sub no_cache {
1.216 albertel 11951: my ($r) = @_;
11952: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11953: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11954: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11955: $r->no_cache(1);
11956: $r->header_out("Expires" => $date);
11957: $r->header_out("Pragma" => "no-cache");
1.123 www 11958: }
11959:
11960: sub content_type {
1.181 albertel 11961: my ($r,$type,$charset) = @_;
1.299 foxr 11962: if ($r) {
11963: # Note that printout.pl calls this with undef for $r.
11964: &no_cache($r);
11965: }
1.258 albertel 11966: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11967: unless ($charset) {
11968: $charset=&Apache::lonlocal::current_encoding;
11969: }
11970: if ($charset) { $type.='; charset='.$charset; }
11971: if ($r) {
11972: $r->content_type($type);
11973: } else {
11974: print("Content-type: $type\n\n");
11975: }
1.9 albertel 11976: }
1.25 albertel 11977:
1.112 bowersj2 11978: =pod
11979:
1.648 raeburn 11980: =item * &add_to_env($name,$value)
1.112 bowersj2 11981:
1.258 albertel 11982: adds $name to the %env hash with value
1.112 bowersj2 11983: $value, if $name already exists, the entry is converted to an array
11984: reference and $value is added to the array.
11985:
11986: =cut
11987:
1.25 albertel 11988: sub add_to_env {
11989: my ($name,$value)=@_;
1.258 albertel 11990: if (defined($env{$name})) {
11991: if (ref($env{$name})) {
1.25 albertel 11992: #already have multiple values
1.258 albertel 11993: push(@{ $env{$name} },$value);
1.25 albertel 11994: } else {
11995: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11996: my $first=$env{$name};
11997: undef($env{$name});
11998: push(@{ $env{$name} },$first,$value);
1.25 albertel 11999: }
12000: } else {
1.258 albertel 12001: $env{$name}=$value;
1.25 albertel 12002: }
1.31 albertel 12003: }
1.149 albertel 12004:
12005: =pod
12006:
1.648 raeburn 12007: =item * &get_env_multiple($name)
1.149 albertel 12008:
1.258 albertel 12009: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12010: values may be defined and end up as an array ref.
12011:
12012: returns an array of values
12013:
12014: =cut
12015:
12016: sub get_env_multiple {
12017: my ($name) = @_;
12018: my @values;
1.258 albertel 12019: if (defined($env{$name})) {
1.149 albertel 12020: # exists is it an array
1.258 albertel 12021: if (ref($env{$name})) {
12022: @values=@{ $env{$name} };
1.149 albertel 12023: } else {
1.258 albertel 12024: $values[0]=$env{$name};
1.149 albertel 12025: }
12026: }
12027: return(@values);
12028: }
12029:
1.660 raeburn 12030: sub ask_for_embedded_content {
12031: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12032: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 12033: %currsubfile,%unused,$rem);
1.1071 raeburn 12034: my $counter = 0;
12035: my $numnew = 0;
1.987 raeburn 12036: my $numremref = 0;
12037: my $numinvalid = 0;
12038: my $numpathchg = 0;
12039: my $numexisting = 0;
1.1071 raeburn 12040: my $numunused = 0;
12041: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 12042: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12043: my $heading = &mt('Upload embedded files');
12044: my $buttontext = &mt('Upload');
12045:
1.1075.2.11 raeburn 12046: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 12047: if ($actionurl eq '/adm/dependencies') {
12048: $navmap = Apache::lonnavmaps::navmap->new();
12049: }
12050: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12051: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 12052: }
1.1075.2.35 raeburn 12053: if (($actionurl eq '/adm/portfolio') ||
12054: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12055: my $current_path='/';
12056: if ($env{'form.currentpath'}) {
12057: $current_path = $env{'form.currentpath'};
12058: }
12059: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 12060: $udom = $cdom;
12061: $uname = $cnum;
1.984 raeburn 12062: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12063: } else {
12064: $udom = $env{'user.domain'};
12065: $uname = $env{'user.name'};
12066: $url = '/userfiles/portfolio';
12067: }
1.987 raeburn 12068: $toplevel = $url.'/';
1.984 raeburn 12069: $url .= $current_path;
12070: $getpropath = 1;
1.987 raeburn 12071: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12072: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12073: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12074: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12075: $toplevel = $url;
1.984 raeburn 12076: if ($rest ne '') {
1.987 raeburn 12077: $url .= $rest;
12078: }
12079: } elsif ($actionurl eq '/adm/coursedocs') {
12080: if (ref($args) eq 'HASH') {
1.1071 raeburn 12081: $url = $args->{'docs_url'};
12082: $toplevel = $url;
1.1075.2.11 raeburn 12083: if ($args->{'context'} eq 'paste') {
12084: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12085: ($path) =
12086: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12087: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12088: $fileloc =~ s{^/}{};
12089: }
1.1071 raeburn 12090: }
12091: } elsif ($actionurl eq '/adm/dependencies') {
12092: if ($env{'request.course.id'} ne '') {
12093: if (ref($args) eq 'HASH') {
12094: $url = $args->{'docs_url'};
12095: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 12096: $toplevel = $url;
12097: unless ($toplevel =~ m{^/}) {
12098: $toplevel = "/$url";
12099: }
1.1075.2.11 raeburn 12100: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 12101: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12102: $path = $1;
12103: } else {
12104: ($path) =
12105: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12106: }
1.1075.2.79 raeburn 12107: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12108: $fileloc = $toplevel;
12109: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12110: my ($udom,$uname,$fname) =
12111: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12112: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12113: } else {
12114: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12115: }
1.1071 raeburn 12116: $fileloc =~ s{^/}{};
12117: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12118: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12119: }
1.987 raeburn 12120: }
1.1075.2.35 raeburn 12121: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12122: $udom = $cdom;
12123: $uname = $cnum;
12124: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12125: $toplevel = $url;
12126: $path = $url;
12127: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12128: $fileloc =~ s{^/}{};
12129: }
12130: foreach my $file (keys(%{$allfiles})) {
12131: my $embed_file;
12132: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12133: $embed_file = $1;
12134: } else {
12135: $embed_file = $file;
12136: }
1.1075.2.55 raeburn 12137: my ($absolutepath,$cleaned_file);
12138: if ($embed_file =~ m{^\w+://}) {
12139: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 12140: $newfiles{$cleaned_file} = 1;
12141: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12142: } else {
1.1075.2.55 raeburn 12143: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12144: if ($embed_file =~ m{^/}) {
12145: $absolutepath = $embed_file;
12146: }
1.1075.2.47 raeburn 12147: if ($cleaned_file =~ m{/}) {
12148: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12149: $path = &check_for_traversal($path,$url,$toplevel);
12150: my $item = $fname;
12151: if ($path ne '') {
12152: $item = $path.'/'.$fname;
12153: $subdependencies{$path}{$fname} = 1;
12154: } else {
12155: $dependencies{$item} = 1;
12156: }
12157: if ($absolutepath) {
12158: $mapping{$item} = $absolutepath;
12159: } else {
12160: $mapping{$item} = $embed_file;
12161: }
12162: } else {
12163: $dependencies{$embed_file} = 1;
12164: if ($absolutepath) {
1.1075.2.47 raeburn 12165: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12166: } else {
1.1075.2.47 raeburn 12167: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12168: }
12169: }
1.984 raeburn 12170: }
12171: }
1.1071 raeburn 12172: my $dirptr = 16384;
1.984 raeburn 12173: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12174: $currsubfile{$path} = {};
1.1075.2.35 raeburn 12175: if (($actionurl eq '/adm/portfolio') ||
12176: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12177: my ($sublistref,$listerror) =
12178: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12179: if (ref($sublistref) eq 'ARRAY') {
12180: foreach my $line (@{$sublistref}) {
12181: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12182: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12183: }
1.984 raeburn 12184: }
1.987 raeburn 12185: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12186: if (opendir(my $dir,$url.'/'.$path)) {
12187: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12188: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12189: }
1.1075.2.11 raeburn 12190: } elsif (($actionurl eq '/adm/dependencies') ||
12191: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12192: ($args->{'context'} eq 'paste')) ||
12193: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12194: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 12195: my $dir;
12196: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12197: $dir = $fileloc;
12198: } else {
12199: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12200: }
1.1071 raeburn 12201: if ($dir ne '') {
12202: my ($sublistref,$listerror) =
12203: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12204: if (ref($sublistref) eq 'ARRAY') {
12205: foreach my $line (@{$sublistref}) {
12206: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12207: undef,$mtime)=split(/\&/,$line,12);
12208: unless (($testdir&$dirptr) ||
12209: ($file_name =~ /^\.\.?$/)) {
12210: $currsubfile{$path}{$file_name} = [$size,$mtime];
12211: }
12212: }
12213: }
12214: }
1.984 raeburn 12215: }
12216: }
12217: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12218: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12219: my $item = $path.'/'.$file;
12220: unless ($mapping{$item} eq $item) {
12221: $pathchanges{$item} = 1;
12222: }
12223: $existing{$item} = 1;
12224: $numexisting ++;
12225: } else {
12226: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12227: }
12228: }
1.1071 raeburn 12229: if ($actionurl eq '/adm/dependencies') {
12230: foreach my $path (keys(%currsubfile)) {
12231: if (ref($currsubfile{$path}) eq 'HASH') {
12232: foreach my $file (keys(%{$currsubfile{$path}})) {
12233: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 12234: next if (($rem ne '') &&
12235: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12236: (ref($navmap) &&
12237: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12238: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12239: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12240: $unused{$path.'/'.$file} = 1;
12241: }
12242: }
12243: }
12244: }
12245: }
1.984 raeburn 12246: }
1.987 raeburn 12247: my %currfile;
1.1075.2.35 raeburn 12248: if (($actionurl eq '/adm/portfolio') ||
12249: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12250: my ($dirlistref,$listerror) =
12251: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12252: if (ref($dirlistref) eq 'ARRAY') {
12253: foreach my $line (@{$dirlistref}) {
12254: my ($file_name,$rest) = split(/\&/,$line,2);
12255: $currfile{$file_name} = 1;
12256: }
1.984 raeburn 12257: }
1.987 raeburn 12258: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12259: if (opendir(my $dir,$url)) {
1.987 raeburn 12260: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12261: map {$currfile{$_} = 1;} @dir_list;
12262: }
1.1075.2.11 raeburn 12263: } elsif (($actionurl eq '/adm/dependencies') ||
12264: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12265: ($args->{'context'} eq 'paste')) ||
12266: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12267: if ($env{'request.course.id'} ne '') {
12268: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12269: if ($dir ne '') {
12270: my ($dirlistref,$listerror) =
12271: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12272: if (ref($dirlistref) eq 'ARRAY') {
12273: foreach my $line (@{$dirlistref}) {
12274: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12275: $size,undef,$mtime)=split(/\&/,$line,12);
12276: unless (($testdir&$dirptr) ||
12277: ($file_name =~ /^\.\.?$/)) {
12278: $currfile{$file_name} = [$size,$mtime];
12279: }
12280: }
12281: }
12282: }
12283: }
1.984 raeburn 12284: }
12285: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12286: if (exists($currfile{$file})) {
1.987 raeburn 12287: unless ($mapping{$file} eq $file) {
12288: $pathchanges{$file} = 1;
12289: }
12290: $existing{$file} = 1;
12291: $numexisting ++;
12292: } else {
1.984 raeburn 12293: $newfiles{$file} = 1;
12294: }
12295: }
1.1071 raeburn 12296: foreach my $file (keys(%currfile)) {
12297: unless (($file eq $filename) ||
12298: ($file eq $filename.'.bak') ||
12299: ($dependencies{$file})) {
1.1075.2.11 raeburn 12300: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 12301: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12302: next if (($rem ne '') &&
12303: (($env{"httpref.$rem".$file} ne '') ||
12304: (ref($navmap) &&
12305: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12306: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12307: ($navmap->getResourceByUrl($rem.$1)))))));
12308: }
1.1075.2.11 raeburn 12309: }
1.1071 raeburn 12310: $unused{$file} = 1;
12311: }
12312: }
1.1075.2.11 raeburn 12313: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12314: ($args->{'context'} eq 'paste')) {
12315: $counter = scalar(keys(%existing));
12316: $numpathchg = scalar(keys(%pathchanges));
12317: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 12318: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12319: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12320: $counter = scalar(keys(%existing));
12321: $numpathchg = scalar(keys(%pathchanges));
12322: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 12323: }
1.984 raeburn 12324: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12325: if ($actionurl eq '/adm/dependencies') {
12326: next if ($embed_file =~ m{^\w+://});
12327: }
1.660 raeburn 12328: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12329: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12330: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12331: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 12332: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12333: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12334: }
1.1075.2.35 raeburn 12335: $upload_output .= '</td>';
1.1071 raeburn 12336: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 12337: $upload_output.='<td align="right">'.
12338: '<span class="LC_info LC_fontsize_medium">'.
12339: &mt("URL points to web address").'</span>';
1.987 raeburn 12340: $numremref++;
1.660 raeburn 12341: } elsif ($args->{'error_on_invalid_names'}
12342: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 12343: $upload_output.='<td align="right"><span class="LC_warning">'.
12344: &mt('Invalid characters').'</span>';
1.987 raeburn 12345: $numinvalid++;
1.660 raeburn 12346: } else {
1.1075.2.35 raeburn 12347: $upload_output .= '<td>'.
12348: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12349: $embed_file,\%mapping,
1.1071 raeburn 12350: $allfiles,$codebase,'upload');
12351: $counter ++;
12352: $numnew ++;
1.987 raeburn 12353: }
12354: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12355: }
12356: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12357: if ($actionurl eq '/adm/dependencies') {
12358: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12359: $modify_output .= &start_data_table_row().
12360: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12361: '<img src="'.&icon($embed_file).'" border="0" />'.
12362: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12363: '<td>'.$size.'</td>'.
12364: '<td>'.$mtime.'</td>'.
12365: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12366: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12367: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12368: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12369: &embedded_file_element('upload_embedded',$counter,
12370: $embed_file,\%mapping,
12371: $allfiles,$codebase,'modify').
12372: '</div></td>'.
12373: &end_data_table_row()."\n";
12374: $counter ++;
12375: } else {
12376: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12377: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12378: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12379: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12380: &Apache::loncommon::end_data_table_row()."\n";
12381: }
12382: }
12383: my $delidx = $counter;
12384: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12385: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12386: $delete_output .= &start_data_table_row().
12387: '<td><img src="'.&icon($oldfile).'" />'.
12388: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12389: '<td>'.$size.'</td>'.
12390: '<td>'.$mtime.'</td>'.
12391: '<td><label><input type="checkbox" name="del_upload_dep" '.
12392: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12393: &embedded_file_element('upload_embedded',$delidx,
12394: $oldfile,\%mapping,$allfiles,
12395: $codebase,'delete').'</td>'.
12396: &end_data_table_row()."\n";
12397: $numunused ++;
12398: $delidx ++;
1.987 raeburn 12399: }
12400: if ($upload_output) {
12401: $upload_output = &start_data_table().
12402: $upload_output.
12403: &end_data_table()."\n";
12404: }
1.1071 raeburn 12405: if ($modify_output) {
12406: $modify_output = &start_data_table().
12407: &start_data_table_header_row().
12408: '<th>'.&mt('File').'</th>'.
12409: '<th>'.&mt('Size (KB)').'</th>'.
12410: '<th>'.&mt('Modified').'</th>'.
12411: '<th>'.&mt('Upload replacement?').'</th>'.
12412: &end_data_table_header_row().
12413: $modify_output.
12414: &end_data_table()."\n";
12415: }
12416: if ($delete_output) {
12417: $delete_output = &start_data_table().
12418: &start_data_table_header_row().
12419: '<th>'.&mt('File').'</th>'.
12420: '<th>'.&mt('Size (KB)').'</th>'.
12421: '<th>'.&mt('Modified').'</th>'.
12422: '<th>'.&mt('Delete?').'</th>'.
12423: &end_data_table_header_row().
12424: $delete_output.
12425: &end_data_table()."\n";
12426: }
1.987 raeburn 12427: my $applies = 0;
12428: if ($numremref) {
12429: $applies ++;
12430: }
12431: if ($numinvalid) {
12432: $applies ++;
12433: }
12434: if ($numexisting) {
12435: $applies ++;
12436: }
1.1071 raeburn 12437: if ($counter || $numunused) {
1.987 raeburn 12438: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12439: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12440: $state.'<h3>'.$heading.'</h3>';
12441: if ($actionurl eq '/adm/dependencies') {
12442: if ($numnew) {
12443: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12444: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12445: $upload_output.'<br />'."\n";
12446: }
12447: if ($numexisting) {
12448: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12449: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12450: $modify_output.'<br />'."\n";
12451: $buttontext = &mt('Save changes');
12452: }
12453: if ($numunused) {
12454: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12455: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12456: $delete_output.'<br />'."\n";
12457: $buttontext = &mt('Save changes');
12458: }
12459: } else {
12460: $output .= $upload_output.'<br />'."\n";
12461: }
12462: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12463: $counter.'" />'."\n";
12464: if ($actionurl eq '/adm/dependencies') {
12465: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12466: $numnew.'" />'."\n";
12467: } elsif ($actionurl eq '') {
1.987 raeburn 12468: $output .= '<input type="hidden" name="phase" value="three" />';
12469: }
12470: } elsif ($applies) {
12471: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12472: if ($applies > 1) {
12473: $output .=
1.1075.2.35 raeburn 12474: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12475: if ($numremref) {
12476: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12477: }
12478: if ($numinvalid) {
12479: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12480: }
12481: if ($numexisting) {
12482: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12483: }
12484: $output .= '</ul><br />';
12485: } elsif ($numremref) {
12486: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12487: } elsif ($numinvalid) {
12488: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12489: } elsif ($numexisting) {
12490: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12491: }
12492: $output .= $upload_output.'<br />';
12493: }
12494: my ($pathchange_output,$chgcount);
1.1071 raeburn 12495: $chgcount = $counter;
1.987 raeburn 12496: if (keys(%pathchanges) > 0) {
12497: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12498: if ($counter) {
1.987 raeburn 12499: $output .= &embedded_file_element('pathchange',$chgcount,
12500: $embed_file,\%mapping,
1.1071 raeburn 12501: $allfiles,$codebase,'change');
1.987 raeburn 12502: } else {
12503: $pathchange_output .=
12504: &start_data_table_row().
12505: '<td><input type ="checkbox" name="namechange" value="'.
12506: $chgcount.'" checked="checked" /></td>'.
12507: '<td>'.$mapping{$embed_file}.'</td>'.
12508: '<td>'.$embed_file.
12509: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12510: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12511: '</td>'.&end_data_table_row();
1.660 raeburn 12512: }
1.987 raeburn 12513: $numpathchg ++;
12514: $chgcount ++;
1.660 raeburn 12515: }
12516: }
1.1075.2.35 raeburn 12517: if (($counter) || ($numunused)) {
1.987 raeburn 12518: if ($numpathchg) {
12519: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12520: $numpathchg.'" />'."\n";
12521: }
12522: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12523: ($actionurl eq '/adm/imsimport')) {
12524: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12525: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12526: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12527: } elsif ($actionurl eq '/adm/dependencies') {
12528: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12529: }
1.1075.2.35 raeburn 12530: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12531: } elsif ($numpathchg) {
12532: my %pathchange = ();
12533: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12534: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12535: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 12536: }
1.987 raeburn 12537: }
1.1071 raeburn 12538: return ($output,$counter,$numpathchg);
1.987 raeburn 12539: }
12540:
1.1075.2.47 raeburn 12541: =pod
12542:
12543: =item * clean_path($name)
12544:
12545: Performs clean-up of directories, subdirectories and filename in an
12546: embedded object, referenced in an HTML file which is being uploaded
12547: to a course or portfolio, where
12548: "Upload embedded images/multimedia files if HTML file" checkbox was
12549: checked.
12550:
12551: Clean-up is similar to replacements in lonnet::clean_filename()
12552: except each / between sub-directory and next level is preserved.
12553:
12554: =cut
12555:
12556: sub clean_path {
12557: my ($embed_file) = @_;
12558: $embed_file =~s{^/+}{};
12559: my @contents;
12560: if ($embed_file =~ m{/}) {
12561: @contents = split(/\//,$embed_file);
12562: } else {
12563: @contents = ($embed_file);
12564: }
12565: my $lastidx = scalar(@contents)-1;
12566: for (my $i=0; $i<=$lastidx; $i++) {
12567: $contents[$i]=~s{\\}{/}g;
12568: $contents[$i]=~s/\s+/\_/g;
12569: $contents[$i]=~s{[^/\w\.\-]}{}g;
12570: if ($i == $lastidx) {
12571: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12572: }
12573: }
12574: if ($lastidx > 0) {
12575: return join('/',@contents);
12576: } else {
12577: return $contents[0];
12578: }
12579: }
12580:
1.987 raeburn 12581: sub embedded_file_element {
1.1071 raeburn 12582: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12583: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12584: (ref($codebase) eq 'HASH'));
12585: my $output;
1.1071 raeburn 12586: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12587: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12588: }
12589: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12590: &escape($embed_file).'" />';
12591: unless (($context eq 'upload_embedded') &&
12592: ($mapping->{$embed_file} eq $embed_file)) {
12593: $output .='
12594: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12595: }
12596: my $attrib;
12597: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12598: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12599: }
12600: $output .=
12601: "\n\t\t".
12602: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12603: $attrib.'" />';
12604: if (exists($codebase->{$mapping->{$embed_file}})) {
12605: $output .=
12606: "\n\t\t".
12607: '<input name="codebase_'.$num.'" type="hidden" value="'.
12608: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12609: }
1.987 raeburn 12610: return $output;
1.660 raeburn 12611: }
12612:
1.1071 raeburn 12613: sub get_dependency_details {
12614: my ($currfile,$currsubfile,$embed_file) = @_;
12615: my ($size,$mtime,$showsize,$showmtime);
12616: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12617: if ($embed_file =~ m{/}) {
12618: my ($path,$fname) = split(/\//,$embed_file);
12619: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12620: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12621: }
12622: } else {
12623: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12624: ($size,$mtime) = @{$currfile->{$embed_file}};
12625: }
12626: }
12627: $showsize = $size/1024.0;
12628: $showsize = sprintf("%.1f",$showsize);
12629: if ($mtime > 0) {
12630: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12631: }
12632: }
12633: return ($showsize,$showmtime);
12634: }
12635:
12636: sub ask_embedded_js {
12637: return <<"END";
12638: <script type="text/javascript"">
12639: // <![CDATA[
12640: function toggleBrowse(counter) {
12641: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12642: var fileid = document.getElementById('embedded_item_'+counter);
12643: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12644: if (chkboxid.checked == true) {
12645: uploaddivid.style.display='block';
12646: } else {
12647: uploaddivid.style.display='none';
12648: fileid.value = '';
12649: }
12650: }
12651: // ]]>
12652: </script>
12653:
12654: END
12655: }
12656:
1.661 raeburn 12657: sub upload_embedded {
12658: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12659: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12660: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12661: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12662: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12663: my $orig_uploaded_filename =
12664: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12665: foreach my $type ('orig','ref','attrib','codebase') {
12666: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12667: $env{'form.embedded_'.$type.'_'.$i} =
12668: &unescape($env{'form.embedded_'.$type.'_'.$i});
12669: }
12670: }
1.661 raeburn 12671: my ($path,$fname) =
12672: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12673: # no path, whole string is fname
12674: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12675: $fname = &Apache::lonnet::clean_filename($fname);
12676: # See if there is anything left
12677: next if ($fname eq '');
12678:
12679: # Check if file already exists as a file or directory.
12680: my ($state,$msg);
12681: if ($context eq 'portfolio') {
12682: my $port_path = $dirpath;
12683: if ($group ne '') {
12684: $port_path = "groups/$group/$port_path";
12685: }
1.987 raeburn 12686: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12687: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12688: $dir_root,$port_path,$disk_quota,
12689: $current_disk_usage,$uname,$udom);
12690: if ($state eq 'will_exceed_quota'
1.984 raeburn 12691: || $state eq 'file_locked') {
1.661 raeburn 12692: $output .= $msg;
12693: next;
12694: }
12695: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12696: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12697: if ($state eq 'exists') {
12698: $output .= $msg;
12699: next;
12700: }
12701: }
12702: # Check if extension is valid
12703: if (($fname =~ /\.(\w+)$/) &&
12704: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12705: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12706: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12707: next;
12708: } elsif (($fname =~ /\.(\w+)$/) &&
12709: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12710: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12711: next;
12712: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12713: $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 12714: next;
12715: }
12716: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12717: my $subdir = $path;
12718: $subdir =~ s{/+$}{};
1.661 raeburn 12719: if ($context eq 'portfolio') {
1.984 raeburn 12720: my $result;
12721: if ($state eq 'existingfile') {
12722: $result=
12723: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12724: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12725: } else {
1.984 raeburn 12726: $result=
12727: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12728: $dirpath.
1.1075.2.35 raeburn 12729: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12730: if ($result !~ m|^/uploaded/|) {
12731: $output .= '<span class="LC_error">'
12732: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12733: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12734: .'</span><br />';
12735: next;
12736: } else {
1.987 raeburn 12737: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12738: $path.$fname.'</span>').'<br />';
1.984 raeburn 12739: }
1.661 raeburn 12740: }
1.1075.2.35 raeburn 12741: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12742: my $extendedsubdir = $dirpath.'/'.$subdir;
12743: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12744: my $result =
1.1075.2.35 raeburn 12745: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12746: if ($result !~ m|^/uploaded/|) {
12747: $output .= '<span class="LC_error">'
12748: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12749: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12750: .'</span><br />';
12751: next;
12752: } else {
12753: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12754: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12755: if ($context eq 'syllabus') {
12756: &Apache::lonnet::make_public_indefinitely($result);
12757: }
1.987 raeburn 12758: }
1.661 raeburn 12759: } else {
12760: # Save the file
12761: my $target = $env{'form.embedded_item_'.$i};
12762: my $fullpath = $dir_root.$dirpath.'/'.$path;
12763: my $dest = $fullpath.$fname;
12764: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12765: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12766: my $count;
12767: my $filepath = $dir_root;
1.1027 raeburn 12768: foreach my $subdir (@parts) {
12769: $filepath .= "/$subdir";
12770: if (!-e $filepath) {
1.661 raeburn 12771: mkdir($filepath,0770);
12772: }
12773: }
12774: my $fh;
12775: if (!open($fh,'>'.$dest)) {
12776: &Apache::lonnet::logthis('Failed to create '.$dest);
12777: $output .= '<span class="LC_error">'.
1.1071 raeburn 12778: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12779: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12780: '</span><br />';
12781: } else {
12782: if (!print $fh $env{'form.embedded_item_'.$i}) {
12783: &Apache::lonnet::logthis('Failed to write to '.$dest);
12784: $output .= '<span class="LC_error">'.
1.1071 raeburn 12785: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12786: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12787: '</span><br />';
12788: } else {
1.987 raeburn 12789: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12790: $url.'</span>').'<br />';
12791: unless ($context eq 'testbank') {
12792: $footer .= &mt('View embedded file: [_1]',
12793: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12794: }
12795: }
12796: close($fh);
12797: }
12798: }
12799: if ($env{'form.embedded_ref_'.$i}) {
12800: $pathchange{$i} = 1;
12801: }
12802: }
12803: if ($output) {
12804: $output = '<p>'.$output.'</p>';
12805: }
12806: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12807: $returnflag = 'ok';
1.1071 raeburn 12808: my $numpathchgs = scalar(keys(%pathchange));
12809: if ($numpathchgs > 0) {
1.987 raeburn 12810: if ($context eq 'portfolio') {
12811: $output .= '<p>'.&mt('or').'</p>';
12812: } elsif ($context eq 'testbank') {
1.1071 raeburn 12813: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12814: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12815: $returnflag = 'modify_orightml';
12816: }
12817: }
1.1071 raeburn 12818: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12819: }
12820:
12821: sub modify_html_form {
12822: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12823: my $end = 0;
12824: my $modifyform;
12825: if ($context eq 'upload_embedded') {
12826: return unless (ref($pathchange) eq 'HASH');
12827: if ($env{'form.number_embedded_items'}) {
12828: $end += $env{'form.number_embedded_items'};
12829: }
12830: if ($env{'form.number_pathchange_items'}) {
12831: $end += $env{'form.number_pathchange_items'};
12832: }
12833: if ($end) {
12834: for (my $i=0; $i<$end; $i++) {
12835: if ($i < $env{'form.number_embedded_items'}) {
12836: next unless($pathchange->{$i});
12837: }
12838: $modifyform .=
12839: &start_data_table_row().
12840: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12841: 'checked="checked" /></td>'.
12842: '<td>'.$env{'form.embedded_ref_'.$i}.
12843: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12844: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12845: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12846: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12847: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12848: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12849: '<td>'.$env{'form.embedded_orig_'.$i}.
12850: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12851: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12852: &end_data_table_row();
1.1071 raeburn 12853: }
1.987 raeburn 12854: }
12855: } else {
12856: $modifyform = $pathchgtable;
12857: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12858: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12859: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12860: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12861: }
12862: }
12863: if ($modifyform) {
1.1071 raeburn 12864: if ($actionurl eq '/adm/dependencies') {
12865: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12866: }
1.987 raeburn 12867: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12868: '<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".
12869: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12870: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12871: '</ol></p>'."\n".'<p>'.
12872: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12873: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12874: &start_data_table()."\n".
12875: &start_data_table_header_row().
12876: '<th>'.&mt('Change?').'</th>'.
12877: '<th>'.&mt('Current reference').'</th>'.
12878: '<th>'.&mt('Required reference').'</th>'.
12879: &end_data_table_header_row()."\n".
12880: $modifyform.
12881: &end_data_table().'<br />'."\n".$hiddenstate.
12882: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12883: '</form>'."\n";
12884: }
12885: return;
12886: }
12887:
12888: sub modify_html_refs {
1.1075.2.35 raeburn 12889: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12890: my $container;
12891: if ($context eq 'portfolio') {
12892: $container = $env{'form.container'};
12893: } elsif ($context eq 'coursedoc') {
12894: $container = $env{'form.primaryurl'};
1.1071 raeburn 12895: } elsif ($context eq 'manage_dependencies') {
12896: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12897: $container = "/$container";
1.1075.2.35 raeburn 12898: } elsif ($context eq 'syllabus') {
12899: $container = $url;
1.987 raeburn 12900: } else {
1.1027 raeburn 12901: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12902: }
12903: my (%allfiles,%codebase,$output,$content);
12904: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12905: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12906: if (wantarray) {
12907: return ('',0,0);
12908: } else {
12909: return;
12910: }
12911: }
12912: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12913: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12914: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12915: if (wantarray) {
12916: return ('',0,0);
12917: } else {
12918: return;
12919: }
12920: }
1.987 raeburn 12921: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12922: if ($content eq '-1') {
12923: if (wantarray) {
12924: return ('',0,0);
12925: } else {
12926: return;
12927: }
12928: }
1.987 raeburn 12929: } else {
1.1071 raeburn 12930: unless ($container =~ /^\Q$dir_root\E/) {
12931: if (wantarray) {
12932: return ('',0,0);
12933: } else {
12934: return;
12935: }
12936: }
1.1075.2.128 raeburn 12937: if (open(my $fh,'<',$container)) {
1.987 raeburn 12938: $content = join('', <$fh>);
12939: close($fh);
12940: } else {
1.1071 raeburn 12941: if (wantarray) {
12942: return ('',0,0);
12943: } else {
12944: return;
12945: }
1.987 raeburn 12946: }
12947: }
12948: my ($count,$codebasecount) = (0,0);
12949: my $mm = new File::MMagic;
12950: my $mime_type = $mm->checktype_contents($content);
12951: if ($mime_type eq 'text/html') {
12952: my $parse_result =
12953: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12954: \%codebase,\$content);
12955: if ($parse_result eq 'ok') {
12956: foreach my $i (@changes) {
12957: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12958: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12959: if ($allfiles{$ref}) {
12960: my $newname = $orig;
12961: my ($attrib_regexp,$codebase);
1.1006 raeburn 12962: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12963: if ($attrib_regexp =~ /:/) {
12964: $attrib_regexp =~ s/\:/|/g;
12965: }
12966: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12967: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12968: $count += $numchg;
1.1075.2.35 raeburn 12969: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 12970: delete($allfiles{$ref});
1.987 raeburn 12971: }
12972: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12973: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12974: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12975: $codebasecount ++;
12976: }
12977: }
12978: }
1.1075.2.35 raeburn 12979: my $skiprewrites;
1.987 raeburn 12980: if ($count || $codebasecount) {
12981: my $saveresult;
1.1071 raeburn 12982: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12983: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12984: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12985: if ($url eq $container) {
12986: my ($fname) = ($container =~ m{/([^/]+)$});
12987: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12988: $count,'<span class="LC_filename">'.
1.1071 raeburn 12989: $fname.'</span>').'</p>';
1.987 raeburn 12990: } else {
12991: $output = '<p class="LC_error">'.
12992: &mt('Error: update failed for: [_1].',
12993: '<span class="LC_filename">'.
12994: $container.'</span>').'</p>';
12995: }
1.1075.2.35 raeburn 12996: if ($context eq 'syllabus') {
12997: unless ($saveresult eq 'ok') {
12998: $skiprewrites = 1;
12999: }
13000: }
1.987 raeburn 13001: } else {
1.1075.2.128 raeburn 13002: if (open(my $fh,'>',$container)) {
1.987 raeburn 13003: print $fh $content;
13004: close($fh);
13005: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13006: $count,'<span class="LC_filename">'.
13007: $container.'</span>').'</p>';
1.661 raeburn 13008: } else {
1.987 raeburn 13009: $output = '<p class="LC_error">'.
13010: &mt('Error: could not update [_1].',
13011: '<span class="LC_filename">'.
13012: $container.'</span>').'</p>';
1.661 raeburn 13013: }
13014: }
13015: }
1.1075.2.35 raeburn 13016: if (($context eq 'syllabus') && (!$skiprewrites)) {
13017: my ($actionurl,$state);
13018: $actionurl = "/public/$udom/$uname/syllabus";
13019: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13020: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13021: \%codebase,
13022: {'context' => 'rewrites',
13023: 'ignore_remote_references' => 1,});
13024: if (ref($mapping) eq 'HASH') {
13025: my $rewrites = 0;
13026: foreach my $key (keys(%{$mapping})) {
13027: next if ($key =~ m{^https?://});
13028: my $ref = $mapping->{$key};
13029: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13030: my $attrib;
13031: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13032: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13033: }
13034: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13035: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13036: $rewrites += $numchg;
13037: }
13038: }
13039: if ($rewrites) {
13040: my $saveresult;
13041: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13042: if ($url eq $container) {
13043: my ($fname) = ($container =~ m{/([^/]+)$});
13044: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13045: $count,'<span class="LC_filename">'.
13046: $fname.'</span>').'</p>';
13047: } else {
13048: $output .= '<p class="LC_error">'.
13049: &mt('Error: could not update links in [_1].',
13050: '<span class="LC_filename">'.
13051: $container.'</span>').'</p>';
13052:
13053: }
13054: }
13055: }
13056: }
1.987 raeburn 13057: } else {
13058: &logthis('Failed to parse '.$container.
13059: ' to modify references: '.$parse_result);
1.661 raeburn 13060: }
13061: }
1.1071 raeburn 13062: if (wantarray) {
13063: return ($output,$count,$codebasecount);
13064: } else {
13065: return $output;
13066: }
1.661 raeburn 13067: }
13068:
13069: sub check_for_existing {
13070: my ($path,$fname,$element) = @_;
13071: my ($state,$msg);
13072: if (-d $path.'/'.$fname) {
13073: $state = 'exists';
13074: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13075: } elsif (-e $path.'/'.$fname) {
13076: $state = 'exists';
13077: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13078: }
13079: if ($state eq 'exists') {
13080: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13081: }
13082: return ($state,$msg);
13083: }
13084:
13085: sub check_for_upload {
13086: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13087: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13088: my $filesize = length($env{'form.'.$element});
13089: if (!$filesize) {
13090: my $msg = '<span class="LC_error">'.
13091: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13092: '<span class="LC_filename">'.$fname.'</span>',
13093: $filesize).'<br />'.
1.1007 raeburn 13094: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13095: '</span>';
13096: return ('zero_bytes',$msg);
13097: }
13098: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13099: my $getpropath = 1;
1.1021 raeburn 13100: my ($dirlistref,$listerror) =
13101: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13102: my $found_file = 0;
13103: my $locked_file = 0;
1.991 raeburn 13104: my @lockers;
13105: my $navmap;
13106: if ($env{'request.course.id'}) {
13107: $navmap = Apache::lonnavmaps::navmap->new();
13108: }
1.1021 raeburn 13109: if (ref($dirlistref) eq 'ARRAY') {
13110: foreach my $line (@{$dirlistref}) {
13111: my ($file_name,$rest)=split(/\&/,$line,2);
13112: if ($file_name eq $fname){
13113: $file_name = $path.$file_name;
13114: if ($group ne '') {
13115: $file_name = $group.$file_name;
13116: }
13117: $found_file = 1;
13118: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13119: foreach my $lock (@lockers) {
13120: if (ref($lock) eq 'ARRAY') {
13121: my ($symb,$crsid) = @{$lock};
13122: if ($crsid eq $env{'request.course.id'}) {
13123: if (ref($navmap)) {
13124: my $res = $navmap->getBySymb($symb);
13125: foreach my $part (@{$res->parts()}) {
13126: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13127: unless (($slot_status == $res->RESERVED) ||
13128: ($slot_status == $res->RESERVED_LOCATION)) {
13129: $locked_file = 1;
13130: }
1.991 raeburn 13131: }
1.1021 raeburn 13132: } else {
13133: $locked_file = 1;
1.991 raeburn 13134: }
13135: } else {
13136: $locked_file = 1;
13137: }
13138: }
1.1021 raeburn 13139: }
13140: } else {
13141: my @info = split(/\&/,$rest);
13142: my $currsize = $info[6]/1000;
13143: if ($currsize < $filesize) {
13144: my $extra = $filesize - $currsize;
13145: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 13146: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13147: &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.',
1.1075.2.69 raeburn 13148: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13149: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13150: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13151: return ('will_exceed_quota',$msg);
13152: }
1.984 raeburn 13153: }
13154: }
1.661 raeburn 13155: }
13156: }
13157: }
13158: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 13159: my $msg = '<p class="LC_warning">'.
13160: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
13161: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13162: return ('will_exceed_quota',$msg);
13163: } elsif ($found_file) {
13164: if ($locked_file) {
1.1075.2.69 raeburn 13165: my $msg = '<p class="LC_warning">';
1.661 raeburn 13166: $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>');
1.1075.2.69 raeburn 13167: $msg .= '</p>';
1.661 raeburn 13168: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13169: return ('file_locked',$msg);
13170: } else {
1.1075.2.69 raeburn 13171: my $msg = '<p class="LC_error">';
1.984 raeburn 13172: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 13173: $msg .= '</p>';
1.984 raeburn 13174: return ('existingfile',$msg);
1.661 raeburn 13175: }
13176: }
13177: }
13178:
1.987 raeburn 13179: sub check_for_traversal {
13180: my ($path,$url,$toplevel) = @_;
13181: my @parts=split(/\//,$path);
13182: my $cleanpath;
13183: my $fullpath = $url;
13184: for (my $i=0;$i<@parts;$i++) {
13185: next if ($parts[$i] eq '.');
13186: if ($parts[$i] eq '..') {
13187: $fullpath =~ s{([^/]+/)$}{};
13188: } else {
13189: $fullpath .= $parts[$i].'/';
13190: }
13191: }
13192: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13193: $cleanpath = $1;
13194: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13195: my $curr_toprel = $1;
13196: my @parts = split(/\//,$curr_toprel);
13197: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13198: my @urlparts = split(/\//,$url_toprel);
13199: my $doubledots;
13200: my $startdiff = -1;
13201: for (my $i=0; $i<@urlparts; $i++) {
13202: if ($startdiff == -1) {
13203: unless ($urlparts[$i] eq $parts[$i]) {
13204: $startdiff = $i;
13205: $doubledots .= '../';
13206: }
13207: } else {
13208: $doubledots .= '../';
13209: }
13210: }
13211: if ($startdiff > -1) {
13212: $cleanpath = $doubledots;
13213: for (my $i=$startdiff; $i<@parts; $i++) {
13214: $cleanpath .= $parts[$i].'/';
13215: }
13216: }
13217: }
13218: $cleanpath =~ s{(/)$}{};
13219: return $cleanpath;
13220: }
1.31 albertel 13221:
1.1053 raeburn 13222: sub is_archive_file {
13223: my ($mimetype) = @_;
13224: if (($mimetype eq 'application/octet-stream') ||
13225: ($mimetype eq 'application/x-stuffit') ||
13226: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13227: return 1;
13228: }
13229: return;
13230: }
13231:
13232: sub decompress_form {
1.1065 raeburn 13233: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13234: my %lt = &Apache::lonlocal::texthash (
13235: this => 'This file is an archive file.',
1.1067 raeburn 13236: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13237: itsc => 'Its contents are as follows:',
1.1053 raeburn 13238: youm => 'You may wish to extract its contents.',
13239: extr => 'Extract contents',
1.1067 raeburn 13240: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13241: proa => 'Process automatically?',
1.1053 raeburn 13242: yes => 'Yes',
13243: no => 'No',
1.1067 raeburn 13244: fold => 'Title for folder containing movie',
13245: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13246: );
1.1065 raeburn 13247: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13248: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13249: my $info = &list_archive_contents($fileloc,\@paths);
13250: if (@paths) {
13251: foreach my $path (@paths) {
13252: $path =~ s{^/}{};
1.1067 raeburn 13253: if ($path =~ m{^([^/]+)/$}) {
13254: $topdir = $1;
13255: }
1.1065 raeburn 13256: if ($path =~ m{^([^/]+)/}) {
13257: $toplevel{$1} = $path;
13258: } else {
13259: $toplevel{$path} = $path;
13260: }
13261: }
13262: }
1.1067 raeburn 13263: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 13264: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13265: "$topdir/media/",
13266: "$topdir/media/$topdir.mp4",
13267: "$topdir/media/FirstFrame.png",
13268: "$topdir/media/player.swf",
13269: "$topdir/media/swfobject.js",
13270: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 13271: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 13272: "$topdir/$topdir.mp4",
13273: "$topdir/$topdir\_config.xml",
13274: "$topdir/$topdir\_controller.swf",
13275: "$topdir/$topdir\_embed.css",
13276: "$topdir/$topdir\_First_Frame.png",
13277: "$topdir/$topdir\_player.html",
13278: "$topdir/$topdir\_Thumbnails.png",
13279: "$topdir/playerProductInstall.swf",
13280: "$topdir/scripts/",
13281: "$topdir/scripts/config_xml.js",
13282: "$topdir/scripts/handlebars.js",
13283: "$topdir/scripts/jquery-1.7.1.min.js",
13284: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13285: "$topdir/scripts/modernizr.js",
13286: "$topdir/scripts/player-min.js",
13287: "$topdir/scripts/swfobject.js",
13288: "$topdir/skins/",
13289: "$topdir/skins/configuration_express.xml",
13290: "$topdir/skins/express_show/",
13291: "$topdir/skins/express_show/player-min.css",
13292: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 13293: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13294: "$topdir/$topdir.mp4",
13295: "$topdir/$topdir\_config.xml",
13296: "$topdir/$topdir\_controller.swf",
13297: "$topdir/$topdir\_embed.css",
13298: "$topdir/$topdir\_First_Frame.png",
13299: "$topdir/$topdir\_player.html",
13300: "$topdir/$topdir\_Thumbnails.png",
13301: "$topdir/playerProductInstall.swf",
13302: "$topdir/scripts/",
13303: "$topdir/scripts/config_xml.js",
13304: "$topdir/scripts/techsmith-smart-player.min.js",
13305: "$topdir/skins/",
13306: "$topdir/skins/configuration_express.xml",
13307: "$topdir/skins/express_show/",
13308: "$topdir/skins/express_show/spritesheet.min.css",
13309: "$topdir/skins/express_show/spritesheet.png",
13310: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 13311: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13312: if (@diffs == 0) {
1.1075.2.59 raeburn 13313: $is_camtasia = 6;
13314: } else {
1.1075.2.81 raeburn 13315: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 13316: if (@diffs == 0) {
13317: $is_camtasia = 8;
1.1075.2.81 raeburn 13318: } else {
13319: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13320: if (@diffs == 0) {
13321: $is_camtasia = 8;
13322: }
1.1075.2.59 raeburn 13323: }
1.1067 raeburn 13324: }
13325: }
13326: my $output;
13327: if ($is_camtasia) {
13328: $output = <<"ENDCAM";
13329: <script type="text/javascript" language="Javascript">
13330: // <![CDATA[
13331:
13332: function camtasiaToggle() {
13333: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13334: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 13335: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13336: document.getElementById('camtasia_titles').style.display='block';
13337: } else {
13338: document.getElementById('camtasia_titles').style.display='none';
13339: }
13340: }
13341: }
13342: return;
13343: }
13344:
13345: // ]]>
13346: </script>
13347: <p>$lt{'camt'}</p>
13348: ENDCAM
1.1065 raeburn 13349: } else {
1.1067 raeburn 13350: $output = '<p>'.$lt{'this'};
13351: if ($info eq '') {
13352: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13353: } else {
13354: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13355: '<div><pre>'.$info.'</pre></div>';
13356: }
1.1065 raeburn 13357: }
1.1067 raeburn 13358: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13359: my $duplicates;
13360: my $num = 0;
13361: if (ref($dirlist) eq 'ARRAY') {
13362: foreach my $item (@{$dirlist}) {
13363: if (ref($item) eq 'ARRAY') {
13364: if (exists($toplevel{$item->[0]})) {
13365: $duplicates .=
13366: &start_data_table_row().
13367: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13368: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13369: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13370: 'value="1" />'.&mt('Yes').'</label>'.
13371: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13372: '<td>'.$item->[0].'</td>';
13373: if ($item->[2]) {
13374: $duplicates .= '<td>'.&mt('Directory').'</td>';
13375: } else {
13376: $duplicates .= '<td>'.&mt('File').'</td>';
13377: }
13378: $duplicates .= '<td>'.$item->[3].'</td>'.
13379: '<td>'.
13380: &Apache::lonlocal::locallocaltime($item->[4]).
13381: '</td>'.
13382: &end_data_table_row();
13383: $num ++;
13384: }
13385: }
13386: }
13387: }
13388: my $itemcount;
13389: if (@paths > 0) {
13390: $itemcount = scalar(@paths);
13391: } else {
13392: $itemcount = 1;
13393: }
1.1067 raeburn 13394: if ($is_camtasia) {
13395: $output .= $lt{'auto'}.'<br />'.
13396: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 13397: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13398: $lt{'yes'}.'</label> <label>'.
13399: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13400: $lt{'no'}.'</label></span><br />'.
13401: '<div id="camtasia_titles" style="display:block">'.
13402: &Apache::lonhtmlcommon::start_pick_box().
13403: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13404: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13405: &Apache::lonhtmlcommon::row_closure().
13406: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13407: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13408: &Apache::lonhtmlcommon::row_closure(1).
13409: &Apache::lonhtmlcommon::end_pick_box().
13410: '</div>';
13411: }
1.1065 raeburn 13412: $output .=
13413: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13414: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13415: "\n";
1.1065 raeburn 13416: if ($duplicates ne '') {
13417: $output .= '<p><span class="LC_warning">'.
13418: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13419: &start_data_table().
13420: &start_data_table_header_row().
13421: '<th>'.&mt('Overwrite?').'</th>'.
13422: '<th>'.&mt('Name').'</th>'.
13423: '<th>'.&mt('Type').'</th>'.
13424: '<th>'.&mt('Size').'</th>'.
13425: '<th>'.&mt('Last modified').'</th>'.
13426: &end_data_table_header_row().
13427: $duplicates.
13428: &end_data_table().
13429: '</p>';
13430: }
1.1067 raeburn 13431: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13432: if (ref($hiddenelements) eq 'HASH') {
13433: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13434: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13435: }
13436: }
13437: $output .= <<"END";
1.1067 raeburn 13438: <br />
1.1053 raeburn 13439: <input type="submit" name="decompress" value="$lt{'extr'}" />
13440: </form>
13441: $noextract
13442: END
13443: return $output;
13444: }
13445:
1.1065 raeburn 13446: sub decompression_utility {
13447: my ($program) = @_;
13448: my @utilities = ('tar','gunzip','bunzip2','unzip');
13449: my $location;
13450: if (grep(/^\Q$program\E$/,@utilities)) {
13451: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13452: '/usr/sbin/') {
13453: if (-x $dir.$program) {
13454: $location = $dir.$program;
13455: last;
13456: }
13457: }
13458: }
13459: return $location;
13460: }
13461:
13462: sub list_archive_contents {
13463: my ($file,$pathsref) = @_;
13464: my (@cmd,$output);
13465: my $needsregexp;
13466: if ($file =~ /\.zip$/) {
13467: @cmd = (&decompression_utility('unzip'),"-l");
13468: $needsregexp = 1;
13469: } elsif (($file =~ m/\.tar\.gz$/) ||
13470: ($file =~ /\.tgz$/)) {
13471: @cmd = (&decompression_utility('tar'),"-ztf");
13472: } elsif ($file =~ /\.tar\.bz2$/) {
13473: @cmd = (&decompression_utility('tar'),"-jtf");
13474: } elsif ($file =~ m|\.tar$|) {
13475: @cmd = (&decompression_utility('tar'),"-tf");
13476: }
13477: if (@cmd) {
13478: undef($!);
13479: undef($@);
13480: if (open(my $fh,"-|", @cmd, $file)) {
13481: while (my $line = <$fh>) {
13482: $output .= $line;
13483: chomp($line);
13484: my $item;
13485: if ($needsregexp) {
13486: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13487: } else {
13488: $item = $line;
13489: }
13490: if ($item ne '') {
13491: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13492: push(@{$pathsref},$item);
13493: }
13494: }
13495: }
13496: close($fh);
13497: }
13498: }
13499: return $output;
13500: }
13501:
1.1053 raeburn 13502: sub decompress_uploaded_file {
13503: my ($file,$dir) = @_;
13504: &Apache::lonnet::appenv({'cgi.file' => $file});
13505: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13506: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13507: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13508: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13509: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13510: my $decompressed = $env{'cgi.decompressed'};
13511: &Apache::lonnet::delenv('cgi.file');
13512: &Apache::lonnet::delenv('cgi.dir');
13513: &Apache::lonnet::delenv('cgi.decompressed');
13514: return ($decompressed,$result);
13515: }
13516:
1.1055 raeburn 13517: sub process_decompression {
13518: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 13519: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13520: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13521: &mt('Unexpected file path.').'</p>'."\n";
13522: }
13523: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13524: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13525: &mt('Unexpected course context.').'</p>'."\n";
13526: }
13527: unless ($file eq &Apache::lonnet::clean_filename($file)) {
13528: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13529: &mt('Filename contained unexpected characters.').'</p>'."\n";
13530: }
1.1055 raeburn 13531: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 13532: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 13533: $error = &mt('Filename not a supported archive file type.').
13534: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13535: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13536: } else {
13537: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13538: if ($docuhome eq 'no_host') {
13539: $error = &mt('Could not determine home server for course.');
13540: } else {
13541: my @ids=&Apache::lonnet::current_machine_ids();
13542: my $currdir = "$dir_root/$destination";
13543: if (grep(/^\Q$docuhome\E$/,@ids)) {
13544: $dir = &LONCAPA::propath($docudom,$docuname).
13545: "$dir_root/$destination";
13546: } else {
13547: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13548: "$dir_root/$docudom/$docuname/$destination";
13549: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13550: $error = &mt('Archive file not found.');
13551: }
13552: }
1.1065 raeburn 13553: my (@to_overwrite,@to_skip);
13554: if ($env{'form.archive_overwrite_total'} > 0) {
13555: my $total = $env{'form.archive_overwrite_total'};
13556: for (my $i=0; $i<$total; $i++) {
13557: if ($env{'form.archive_overwrite_'.$i} == 1) {
13558: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13559: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13560: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13561: }
13562: }
13563: }
13564: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 13565: my $numoverwrite = scalar(@to_overwrite);
13566: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13567: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13568: } elsif ($dir eq '') {
1.1055 raeburn 13569: $error = &mt('Directory containing archive file unavailable.');
13570: } elsif (!$error) {
1.1065 raeburn 13571: my ($decompressed,$display);
1.1075.2.128 raeburn 13572: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13573: my $tempdir = time.'_'.$$.int(rand(10000));
13574: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 13575: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13576: ($decompressed,$display) =
13577: &decompress_uploaded_file($file,"$dir/$tempdir");
13578: foreach my $item (@to_skip) {
13579: if (($item ne '') && ($item !~ /\.\./)) {
13580: if (-f "$dir/$tempdir/$item") {
13581: unlink("$dir/$tempdir/$item");
13582: } elsif (-d "$dir/$tempdir/$item") {
13583: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
13584: }
13585: }
13586: }
13587: foreach my $item (@to_overwrite) {
13588: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13589: if (($item ne '') && ($item !~ /\.\./)) {
13590: if (-f "$dir/$item") {
13591: unlink("$dir/$item");
13592: } elsif (-d "$dir/$item") {
13593: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
13594: }
13595: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13596: }
1.1065 raeburn 13597: }
13598: }
1.1075.2.128 raeburn 13599: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13600: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13601: }
1.1065 raeburn 13602: }
13603: } else {
13604: ($decompressed,$display) =
13605: &decompress_uploaded_file($file,$dir);
13606: }
1.1055 raeburn 13607: if ($decompressed eq 'ok') {
1.1065 raeburn 13608: $output = '<p class="LC_info">'.
13609: &mt('Files extracted successfully from archive.').
13610: '</p>'."\n";
1.1055 raeburn 13611: my ($warning,$result,@contents);
13612: my ($newdirlistref,$newlisterror) =
13613: &Apache::lonnet::dirlist($currdir,$docudom,
13614: $docuname,1);
13615: my (%is_dir,%changes,@newitems);
13616: my $dirptr = 16384;
1.1065 raeburn 13617: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13618: foreach my $dir_line (@{$newdirlistref}) {
13619: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13620: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13621: push(@newitems,$item);
13622: if ($dirptr&$testdir) {
13623: $is_dir{$item} = 1;
13624: }
13625: $changes{$item} = 1;
13626: }
13627: }
13628: }
13629: if (keys(%changes) > 0) {
13630: foreach my $item (sort(@newitems)) {
13631: if ($changes{$item}) {
13632: push(@contents,$item);
13633: }
13634: }
13635: }
13636: if (@contents > 0) {
1.1067 raeburn 13637: my $wantform;
13638: unless ($env{'form.autoextract_camtasia'}) {
13639: $wantform = 1;
13640: }
1.1056 raeburn 13641: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13642: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13643: $currdir,\%is_dir,
13644: \%children,\%parent,
1.1056 raeburn 13645: \@contents,\%dirorder,
13646: \%titles,$wantform);
1.1055 raeburn 13647: if ($datatable ne '') {
13648: $output .= &archive_options_form('decompressed',$datatable,
13649: $count,$hiddenelem);
1.1065 raeburn 13650: my $startcount = 6;
1.1055 raeburn 13651: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13652: \%titles,\%children);
1.1055 raeburn 13653: }
1.1067 raeburn 13654: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13655: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13656: my %displayed;
13657: my $total = 1;
13658: $env{'form.archive_directory'} = [];
13659: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13660: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13661: $path =~ s{/$}{};
13662: my $item;
13663: if ($path ne '') {
13664: $item = "$path/$titles{$i}";
13665: } else {
13666: $item = $titles{$i};
13667: }
13668: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13669: if ($item eq $contents[0]) {
13670: push(@{$env{'form.archive_directory'}},$i);
13671: $env{'form.archive_'.$i} = 'display';
13672: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13673: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13674: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13675: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13676: $env{'form.archive_'.$i} = 'display';
13677: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13678: $displayed{'web'} = $i;
13679: } else {
1.1075.2.59 raeburn 13680: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13681: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13682: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13683: push(@{$env{'form.archive_directory'}},$i);
13684: }
13685: $env{'form.archive_'.$i} = 'dependency';
13686: }
13687: $total ++;
13688: }
13689: for (my $i=1; $i<$total; $i++) {
13690: next if ($i == $displayed{'web'});
13691: next if ($i == $displayed{'folder'});
13692: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13693: }
13694: $env{'form.phase'} = 'decompress_cleanup';
13695: $env{'form.archivedelete'} = 1;
13696: $env{'form.archive_count'} = $total-1;
13697: $output .=
13698: &process_extracted_files('coursedocs',$docudom,
13699: $docuname,$destination,
13700: $dir_root,$hiddenelem);
13701: }
1.1055 raeburn 13702: } else {
13703: $warning = &mt('No new items extracted from archive file.');
13704: }
13705: } else {
13706: $output = $display;
13707: $error = &mt('An error occurred during extraction from the archive file.');
13708: }
13709: }
13710: }
13711: }
13712: if ($error) {
13713: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13714: $error.'</p>'."\n";
13715: }
13716: if ($warning) {
13717: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13718: }
13719: return $output;
13720: }
13721:
13722: sub get_extracted {
1.1056 raeburn 13723: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13724: $titles,$wantform) = @_;
1.1055 raeburn 13725: my $count = 0;
13726: my $depth = 0;
13727: my $datatable;
1.1056 raeburn 13728: my @hierarchy;
1.1055 raeburn 13729: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13730: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13731: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13732: foreach my $item (@{$contents}) {
13733: $count ++;
1.1056 raeburn 13734: @{$dirorder->{$count}} = @hierarchy;
13735: $titles->{$count} = $item;
1.1055 raeburn 13736: &archive_hierarchy($depth,$count,$parent,$children);
13737: if ($wantform) {
13738: $datatable .= &archive_row($is_dir->{$item},$item,
13739: $currdir,$depth,$count);
13740: }
13741: if ($is_dir->{$item}) {
13742: $depth ++;
1.1056 raeburn 13743: push(@hierarchy,$count);
13744: $parent->{$depth} = $count;
1.1055 raeburn 13745: $datatable .=
13746: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13747: \$depth,\$count,\@hierarchy,$dirorder,
13748: $children,$parent,$titles,$wantform);
1.1055 raeburn 13749: $depth --;
1.1056 raeburn 13750: pop(@hierarchy);
1.1055 raeburn 13751: }
13752: }
13753: return ($count,$datatable);
13754: }
13755:
13756: sub recurse_extracted_archive {
1.1056 raeburn 13757: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13758: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13759: my $result='';
1.1056 raeburn 13760: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13761: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13762: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13763: return $result;
13764: }
13765: my $dirptr = 16384;
13766: my ($newdirlistref,$newlisterror) =
13767: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13768: if (ref($newdirlistref) eq 'ARRAY') {
13769: foreach my $dir_line (@{$newdirlistref}) {
13770: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13771: unless ($item =~ /^\.+$/) {
13772: $$count ++;
1.1056 raeburn 13773: @{$dirorder->{$$count}} = @{$hierarchy};
13774: $titles->{$$count} = $item;
1.1055 raeburn 13775: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13776:
1.1055 raeburn 13777: my $is_dir;
13778: if ($dirptr&$testdir) {
13779: $is_dir = 1;
13780: }
13781: if ($wantform) {
13782: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13783: }
13784: if ($is_dir) {
13785: $$depth ++;
1.1056 raeburn 13786: push(@{$hierarchy},$$count);
13787: $parent->{$$depth} = $$count;
1.1055 raeburn 13788: $result .=
13789: &recurse_extracted_archive("$currdir/$item",$docudom,
13790: $docuname,$depth,$count,
1.1056 raeburn 13791: $hierarchy,$dirorder,$children,
13792: $parent,$titles,$wantform);
1.1055 raeburn 13793: $$depth --;
1.1056 raeburn 13794: pop(@{$hierarchy});
1.1055 raeburn 13795: }
13796: }
13797: }
13798: }
13799: return $result;
13800: }
13801:
13802: sub archive_hierarchy {
13803: my ($depth,$count,$parent,$children) =@_;
13804: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13805: if (exists($parent->{$depth})) {
13806: $children->{$parent->{$depth}} .= $count.':';
13807: }
13808: }
13809: return;
13810: }
13811:
13812: sub archive_row {
13813: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13814: my ($name) = ($item =~ m{([^/]+)$});
13815: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13816: 'display' => 'Add as file',
1.1055 raeburn 13817: 'dependency' => 'Include as dependency',
13818: 'discard' => 'Discard',
13819: );
13820: if ($is_dir) {
1.1059 raeburn 13821: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13822: }
1.1056 raeburn 13823: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13824: my $offset = 0;
1.1055 raeburn 13825: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13826: $offset ++;
1.1065 raeburn 13827: if ($action ne 'display') {
13828: $offset ++;
13829: }
1.1055 raeburn 13830: $output .= '<td><span class="LC_nobreak">'.
13831: '<label><input type="radio" name="archive_'.$count.
13832: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13833: my $text = $choices{$action};
13834: if ($is_dir) {
13835: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13836: if ($action eq 'display') {
1.1059 raeburn 13837: $text = &mt('Add as folder');
1.1055 raeburn 13838: }
1.1056 raeburn 13839: } else {
13840: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13841:
13842: }
13843: $output .= ' /> '.$choices{$action}.'</label></span>';
13844: if ($action eq 'dependency') {
13845: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13846: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13847: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13848: '<option value=""></option>'."\n".
13849: '</select>'."\n".
13850: '</div>';
1.1059 raeburn 13851: } elsif ($action eq 'display') {
13852: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13853: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13854: '</div>';
1.1055 raeburn 13855: }
1.1056 raeburn 13856: $output .= '</td>';
1.1055 raeburn 13857: }
13858: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13859: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13860: for (my $i=0; $i<$depth; $i++) {
13861: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13862: }
13863: if ($is_dir) {
13864: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13865: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13866: } else {
13867: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13868: }
13869: $output .= ' '.$name.'</td>'."\n".
13870: &end_data_table_row();
13871: return $output;
13872: }
13873:
13874: sub archive_options_form {
1.1065 raeburn 13875: my ($form,$display,$count,$hiddenelem) = @_;
13876: my %lt = &Apache::lonlocal::texthash(
13877: perm => 'Permanently remove archive file?',
13878: hows => 'How should each extracted item be incorporated in the course?',
13879: cont => 'Content actions for all',
13880: addf => 'Add as folder/file',
13881: incd => 'Include as dependency for a displayed file',
13882: disc => 'Discard',
13883: no => 'No',
13884: yes => 'Yes',
13885: save => 'Save',
13886: );
13887: my $output = <<"END";
13888: <form name="$form" method="post" action="">
13889: <p><span class="LC_nobreak">$lt{'perm'}
13890: <label>
13891: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13892: </label>
13893:
13894: <label>
13895: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13896: </span>
13897: </p>
13898: <input type="hidden" name="phase" value="decompress_cleanup" />
13899: <br />$lt{'hows'}
13900: <div class="LC_columnSection">
13901: <fieldset>
13902: <legend>$lt{'cont'}</legend>
13903: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13904: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13905: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13906: </fieldset>
13907: </div>
13908: END
13909: return $output.
1.1055 raeburn 13910: &start_data_table()."\n".
1.1065 raeburn 13911: $display."\n".
1.1055 raeburn 13912: &end_data_table()."\n".
13913: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13914: $hiddenelem.
1.1065 raeburn 13915: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13916: '</form>';
13917: }
13918:
13919: sub archive_javascript {
1.1056 raeburn 13920: my ($startcount,$numitems,$titles,$children) = @_;
13921: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13922: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13923: my $scripttag = <<START;
13924: <script type="text/javascript">
13925: // <![CDATA[
13926:
13927: function checkAll(form,prefix) {
13928: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13929: for (var i=0; i < form.elements.length; i++) {
13930: var id = form.elements[i].id;
13931: if ((id != '') && (id != undefined)) {
13932: if (idstr.test(id)) {
13933: if (form.elements[i].type == 'radio') {
13934: form.elements[i].checked = true;
1.1056 raeburn 13935: var nostart = i-$startcount;
1.1059 raeburn 13936: var offset = nostart%7;
13937: var count = (nostart-offset)/7;
1.1056 raeburn 13938: dependencyCheck(form,count,offset);
1.1055 raeburn 13939: }
13940: }
13941: }
13942: }
13943: }
13944:
13945: function propagateCheck(form,count) {
13946: if (count > 0) {
1.1059 raeburn 13947: var startelement = $startcount + ((count-1) * 7);
13948: for (var j=1; j<6; j++) {
13949: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13950: var item = startelement + j;
13951: if (form.elements[item].type == 'radio') {
13952: if (form.elements[item].checked) {
13953: containerCheck(form,count,j);
13954: break;
13955: }
1.1055 raeburn 13956: }
13957: }
13958: }
13959: }
13960: }
13961:
13962: numitems = $numitems
1.1056 raeburn 13963: var titles = new Array(numitems);
13964: var parents = new Array(numitems);
1.1055 raeburn 13965: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13966: parents[i] = new Array;
1.1055 raeburn 13967: }
1.1059 raeburn 13968: var maintitle = '$maintitle';
1.1055 raeburn 13969:
13970: START
13971:
1.1056 raeburn 13972: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13973: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13974: for (my $i=0; $i<@contents; $i ++) {
13975: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13976: }
13977: }
13978:
1.1056 raeburn 13979: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13980: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13981: }
13982:
1.1055 raeburn 13983: $scripttag .= <<END;
13984:
13985: function containerCheck(form,count,offset) {
13986: if (count > 0) {
1.1056 raeburn 13987: dependencyCheck(form,count,offset);
1.1059 raeburn 13988: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13989: form.elements[item].checked = true;
13990: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13991: if (parents[count].length > 0) {
13992: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13993: containerCheck(form,parents[count][j],offset);
13994: }
13995: }
13996: }
13997: }
13998: }
13999:
14000: function dependencyCheck(form,count,offset) {
14001: if (count > 0) {
1.1059 raeburn 14002: var chosen = (offset+$startcount)+7*(count-1);
14003: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14004: var currtype = form.elements[depitem].type;
14005: if (form.elements[chosen].value == 'dependency') {
14006: document.getElementById('arc_depon_'+count).style.display='block';
14007: form.elements[depitem].options.length = 0;
14008: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 14009: for (var i=1; i<=numitems; i++) {
14010: if (i == count) {
14011: continue;
14012: }
1.1059 raeburn 14013: var startelement = $startcount + (i-1) * 7;
14014: for (var j=1; j<6; j++) {
14015: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14016: var item = startelement + j;
14017: if (form.elements[item].type == 'radio') {
14018: if (form.elements[item].checked) {
14019: if (form.elements[item].value == 'display') {
14020: var n = form.elements[depitem].options.length;
14021: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14022: }
14023: }
14024: }
14025: }
14026: }
14027: }
14028: } else {
14029: document.getElementById('arc_depon_'+count).style.display='none';
14030: form.elements[depitem].options.length = 0;
14031: form.elements[depitem].options[0] = new Option('Select','',true,true);
14032: }
1.1059 raeburn 14033: titleCheck(form,count,offset);
1.1056 raeburn 14034: }
14035: }
14036:
14037: function propagateSelect(form,count,offset) {
14038: if (count > 0) {
1.1065 raeburn 14039: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14040: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14041: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14042: if (parents[count].length > 0) {
14043: for (var j=0; j<parents[count].length; j++) {
14044: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14045: }
14046: }
14047: }
14048: }
14049: }
1.1056 raeburn 14050:
14051: function containerSelect(form,count,offset,picked) {
14052: if (count > 0) {
1.1065 raeburn 14053: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14054: if (form.elements[item].type == 'radio') {
14055: if (form.elements[item].value == 'dependency') {
14056: if (form.elements[item+1].type == 'select-one') {
14057: for (var i=0; i<form.elements[item+1].options.length; i++) {
14058: if (form.elements[item+1].options[i].value == picked) {
14059: form.elements[item+1].selectedIndex = i;
14060: break;
14061: }
14062: }
14063: }
14064: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14065: if (parents[count].length > 0) {
14066: for (var j=0; j<parents[count].length; j++) {
14067: containerSelect(form,parents[count][j],offset,picked);
14068: }
14069: }
14070: }
14071: }
14072: }
14073: }
14074: }
14075:
1.1059 raeburn 14076: function titleCheck(form,count,offset) {
14077: if (count > 0) {
14078: var chosen = (offset+$startcount)+7*(count-1);
14079: var depitem = $startcount + ((count-1) * 7) + 2;
14080: var currtype = form.elements[depitem].type;
14081: if (form.elements[chosen].value == 'display') {
14082: document.getElementById('arc_title_'+count).style.display='block';
14083: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14084: document.getElementById('archive_title_'+count).value=maintitle;
14085: }
14086: } else {
14087: document.getElementById('arc_title_'+count).style.display='none';
14088: if (currtype == 'text') {
14089: document.getElementById('archive_title_'+count).value='';
14090: }
14091: }
14092: }
14093: return;
14094: }
14095:
1.1055 raeburn 14096: // ]]>
14097: </script>
14098: END
14099: return $scripttag;
14100: }
14101:
14102: sub process_extracted_files {
1.1067 raeburn 14103: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14104: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 14105: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14106: my @ids=&Apache::lonnet::current_machine_ids();
14107: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14108: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14109: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14110: if (grep(/^\Q$docuhome\E$/,@ids)) {
14111: $prefix = &LONCAPA::propath($docudom,$docuname);
14112: $pathtocheck = "$dir_root/$destination";
14113: $dir = $dir_root;
14114: $ishome = 1;
14115: } else {
14116: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14117: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 14118: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14119: }
14120: my $currdir = "$dir_root/$destination";
14121: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14122: if ($env{'form.folderpath'}) {
14123: my @items = split('&',$env{'form.folderpath'});
14124: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 14125: if ($env{'form.folderpath'} =~ /\:1$/) {
14126: $containers{'0'}='page';
14127: } else {
14128: $containers{'0'}='sequence';
14129: }
1.1055 raeburn 14130: }
14131: my @archdirs = &get_env_multiple('form.archive_directory');
14132: if ($numitems) {
14133: for (my $i=1; $i<=$numitems; $i++) {
14134: my $path = $env{'form.archive_content_'.$i};
14135: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14136: my $item = $1;
14137: $toplevelitems{$item} = $i;
14138: if (grep(/^\Q$i\E$/,@archdirs)) {
14139: $is_dir{$item} = 1;
14140: }
14141: }
14142: }
14143: }
1.1067 raeburn 14144: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14145: if (keys(%toplevelitems) > 0) {
14146: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14147: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14148: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14149: }
1.1066 raeburn 14150: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14151: if ($numitems) {
14152: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 14153: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14154: my $path = $env{'form.archive_content_'.$i};
14155: if ($path =~ /^\Q$pathtocheck\E/) {
14156: if ($env{'form.archive_'.$i} eq 'discard') {
14157: if ($prefix ne '' && $path ne '') {
14158: if (-e $prefix.$path) {
1.1066 raeburn 14159: if ((@archdirs > 0) &&
14160: (grep(/^\Q$i\E$/,@archdirs))) {
14161: $todeletedir{$prefix.$path} = 1;
14162: } else {
14163: $todelete{$prefix.$path} = 1;
14164: }
1.1055 raeburn 14165: }
14166: }
14167: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14168: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14169: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14170: $docstitle = $env{'form.archive_title_'.$i};
14171: if ($docstitle eq '') {
14172: $docstitle = $title;
14173: }
1.1055 raeburn 14174: $outer = 0;
1.1056 raeburn 14175: if (ref($dirorder{$i}) eq 'ARRAY') {
14176: if (@{$dirorder{$i}} > 0) {
14177: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14178: if ($env{'form.archive_'.$item} eq 'display') {
14179: $outer = $item;
14180: last;
14181: }
14182: }
14183: }
14184: }
14185: my ($errtext,$fatal) =
14186: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14187: '/'.$folders{$outer}.'.'.
14188: $containers{$outer});
14189: next if ($fatal);
14190: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14191: if ($context eq 'coursedocs') {
1.1056 raeburn 14192: $mapinner{$i} = time;
1.1055 raeburn 14193: $folders{$i} = 'default_'.$mapinner{$i};
14194: $containers{$i} = 'sequence';
14195: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14196: $folders{$i}.'.'.$containers{$i};
14197: my $newidx = &LONCAPA::map::getresidx();
14198: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14199: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14200: push(@LONCAPA::map::order,$newidx);
14201: my ($outtext,$errtext) =
14202: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14203: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 14204: '.'.$containers{$outer},1,1);
1.1056 raeburn 14205: $newseqid{$i} = $newidx;
1.1067 raeburn 14206: unless ($errtext) {
1.1075.2.128 raeburn 14207: $result .= '<li>'.&mt('Folder: [_1] added to course',
14208: &HTML::Entities::encode($docstitle,'<>&"'))..
14209: '</li>'."\n";
1.1067 raeburn 14210: }
1.1055 raeburn 14211: }
14212: } else {
14213: if ($context eq 'coursedocs') {
14214: my $newidx=&LONCAPA::map::getresidx();
14215: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14216: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14217: $title;
1.1075.2.161. .13(raeb 14218:-23): if (($outer !~ /\D/) &&
14219:-23): (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14220:-23): ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 14221: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14222: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 14223: }
1.1075.2.128 raeburn 14224: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14225: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14226: }
14227: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14228: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14229: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14230: unless ($ishome) {
14231: my $fetch = "$newdest{$i}/$title";
14232: $fetch =~ s/^\Q$prefix$dir\E//;
14233: $prompttofetch{$fetch} = 1;
14234: }
14235: }
14236: }
14237: $LONCAPA::map::resources[$newidx]=
14238: $docstitle.':'.$url.':false:normal:res';
14239: push(@LONCAPA::map::order, $newidx);
14240: my ($outtext,$errtext)=
14241: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14242: $docuname.'/'.$folders{$outer}.
14243: '.'.$containers{$outer},1,1);
14244: unless ($errtext) {
14245: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14246: $result .= '<li>'.&mt('File: [_1] added to course',
14247: &HTML::Entities::encode($docstitle,'<>&"')).
14248: '</li>'."\n";
14249: }
1.1067 raeburn 14250: }
1.1075.2.128 raeburn 14251: } else {
14252: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14253: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 14254: }
1.1055 raeburn 14255: }
14256: }
1.1075.2.11 raeburn 14257: }
14258: } else {
1.1075.2.128 raeburn 14259: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14260: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 14261: }
14262: }
14263: for (my $i=1; $i<=$numitems; $i++) {
14264: next unless ($env{'form.archive_'.$i} eq 'dependency');
14265: my $path = $env{'form.archive_content_'.$i};
14266: if ($path =~ /^\Q$pathtocheck\E/) {
14267: my ($title) = ($path =~ m{/([^/]+)$});
14268: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14269: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14270: if (ref($dirorder{$i}) eq 'ARRAY') {
14271: my ($itemidx,$fullpath,$relpath);
14272: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14273: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14274: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 14275: if ($dirorder{$i}->[$j] eq $container) {
14276: $itemidx = $j;
1.1056 raeburn 14277: }
14278: }
1.1075.2.11 raeburn 14279: }
14280: if ($itemidx eq '') {
14281: $itemidx = 0;
14282: }
14283: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14284: if ($mapinner{$referrer{$i}}) {
14285: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14286: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14287: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14288: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14289: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14290: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14291: if (!-e $fullpath) {
14292: mkdir($fullpath,0755);
1.1056 raeburn 14293: }
14294: }
1.1075.2.11 raeburn 14295: } else {
14296: last;
1.1056 raeburn 14297: }
1.1075.2.11 raeburn 14298: }
14299: }
14300: } elsif ($newdest{$referrer{$i}}) {
14301: $fullpath = $newdest{$referrer{$i}};
14302: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14303: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14304: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14305: last;
14306: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14307: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14308: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14309: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14310: if (!-e $fullpath) {
14311: mkdir($fullpath,0755);
1.1056 raeburn 14312: }
14313: }
1.1075.2.11 raeburn 14314: } else {
14315: last;
1.1056 raeburn 14316: }
1.1075.2.11 raeburn 14317: }
14318: }
14319: if ($fullpath ne '') {
14320: if (-e "$prefix$path") {
1.1075.2.128 raeburn 14321: unless (rename("$prefix$path","$fullpath/$title")) {
14322: $warning .= &mt('Failed to rename dependency').'<br />';
14323: }
1.1075.2.11 raeburn 14324: }
14325: if (-e "$fullpath/$title") {
14326: my $showpath;
14327: if ($relpath ne '') {
14328: $showpath = "$relpath/$title";
14329: } else {
14330: $showpath = "/$title";
1.1056 raeburn 14331: }
1.1075.2.128 raeburn 14332: $result .= '<li>'.&mt('[_1] included as a dependency',
14333: &HTML::Entities::encode($showpath,'<>&"')).
14334: '</li>'."\n";
14335: unless ($ishome) {
14336: my $fetch = "$fullpath/$title";
14337: $fetch =~ s/^\Q$prefix$dir\E//;
14338: $prompttofetch{$fetch} = 1;
14339: }
1.1055 raeburn 14340: }
14341: }
14342: }
1.1075.2.11 raeburn 14343: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14344: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 14345: &HTML::Entities::encode($path,'<>&"'),
14346: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14347: '<br />';
1.1055 raeburn 14348: }
14349: } else {
1.1075.2.128 raeburn 14350: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14351: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14352: }
14353: }
14354: if (keys(%todelete)) {
14355: foreach my $key (keys(%todelete)) {
14356: unlink($key);
1.1066 raeburn 14357: }
14358: }
14359: if (keys(%todeletedir)) {
14360: foreach my $key (keys(%todeletedir)) {
14361: rmdir($key);
14362: }
14363: }
14364: foreach my $dir (sort(keys(%is_dir))) {
14365: if (($pathtocheck ne '') && ($dir ne '')) {
14366: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14367: }
14368: }
1.1067 raeburn 14369: if ($result ne '') {
14370: $output .= '<ul>'."\n".
14371: $result."\n".
14372: '</ul>';
14373: }
14374: unless ($ishome) {
14375: my $replicationfail;
14376: foreach my $item (keys(%prompttofetch)) {
14377: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14378: unless ($fetchresult eq 'ok') {
14379: $replicationfail .= '<li>'.$item.'</li>'."\n";
14380: }
14381: }
14382: if ($replicationfail) {
14383: $output .= '<p class="LC_error">'.
14384: &mt('Course home server failed to retrieve:').'<ul>'.
14385: $replicationfail.
14386: '</ul></p>';
14387: }
14388: }
1.1055 raeburn 14389: } else {
14390: $warning = &mt('No items found in archive.');
14391: }
14392: if ($error) {
14393: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14394: $error.'</p>'."\n";
14395: }
14396: if ($warning) {
14397: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14398: }
14399: return $output;
14400: }
14401:
1.1066 raeburn 14402: sub cleanup_empty_dirs {
14403: my ($path) = @_;
14404: if (($path ne '') && (-d $path)) {
14405: if (opendir(my $dirh,$path)) {
14406: my @dircontents = grep(!/^\./,readdir($dirh));
14407: my $numitems = 0;
14408: foreach my $item (@dircontents) {
14409: if (-d "$path/$item") {
1.1075.2.28 raeburn 14410: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14411: if (-e "$path/$item") {
14412: $numitems ++;
14413: }
14414: } else {
14415: $numitems ++;
14416: }
14417: }
14418: if ($numitems == 0) {
14419: rmdir($path);
14420: }
14421: closedir($dirh);
14422: }
14423: }
14424: return;
14425: }
14426:
1.41 ng 14427: =pod
1.45 matthew 14428:
1.1075.2.56 raeburn 14429: =item * &get_folder_hierarchy()
1.1068 raeburn 14430:
14431: Provides hierarchy of names of folders/sub-folders containing the current
14432: item,
14433:
14434: Inputs: 3
14435: - $navmap - navmaps object
14436:
14437: - $map - url for map (either the trigger itself, or map containing
14438: the resource, which is the trigger).
14439:
14440: - $showitem - 1 => show title for map itself; 0 => do not show.
14441:
14442: Outputs: 1 @pathitems - array of folder/subfolder names.
14443:
14444: =cut
14445:
14446: sub get_folder_hierarchy {
14447: my ($navmap,$map,$showitem) = @_;
14448: my @pathitems;
14449: if (ref($navmap)) {
14450: my $mapres = $navmap->getResourceByUrl($map);
14451: if (ref($mapres)) {
14452: my $pcslist = $mapres->map_hierarchy();
14453: if ($pcslist ne '') {
14454: my @pcs = split(/,/,$pcslist);
14455: foreach my $pc (@pcs) {
14456: if ($pc == 1) {
1.1075.2.38 raeburn 14457: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14458: } else {
14459: my $res = $navmap->getByMapPc($pc);
14460: if (ref($res)) {
14461: my $title = $res->compTitle();
14462: $title =~ s/\W+/_/g;
14463: if ($title ne '') {
14464: push(@pathitems,$title);
14465: }
14466: }
14467: }
14468: }
14469: }
1.1071 raeburn 14470: if ($showitem) {
14471: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 14472: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14473: } else {
14474: my $maptitle = $mapres->compTitle();
14475: $maptitle =~ s/\W+/_/g;
14476: if ($maptitle ne '') {
14477: push(@pathitems,$maptitle);
14478: }
1.1068 raeburn 14479: }
14480: }
14481: }
14482: }
14483: return @pathitems;
14484: }
14485:
14486: =pod
14487:
1.1015 raeburn 14488: =item * &get_turnedin_filepath()
14489:
14490: Determines path in a user's portfolio file for storage of files uploaded
14491: to a specific essayresponse or dropbox item.
14492:
14493: Inputs: 3 required + 1 optional.
14494: $symb is symb for resource, $uname and $udom are for current user (required).
14495: $caller is optional (can be "submission", if routine is called when storing
14496: an upoaded file when "Submit Answer" button was pressed).
14497:
14498: Returns array containing $path and $multiresp.
14499: $path is path in portfolio. $multiresp is 1 if this resource contains more
14500: than one file upload item. Callers of routine should append partid as a
14501: subdirectory to $path in cases where $multiresp is 1.
14502:
14503: Called by: homework/essayresponse.pm and homework/structuretags.pm
14504:
14505: =cut
14506:
14507: sub get_turnedin_filepath {
14508: my ($symb,$uname,$udom,$caller) = @_;
14509: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14510: my $turnindir;
14511: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14512: $turnindir = $userhash{'turnindir'};
14513: my ($path,$multiresp);
14514: if ($turnindir eq '') {
14515: if ($caller eq 'submission') {
14516: $turnindir = &mt('turned in');
14517: $turnindir =~ s/\W+/_/g;
14518: my %newhash = (
14519: 'turnindir' => $turnindir,
14520: );
14521: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14522: }
14523: }
14524: if ($turnindir ne '') {
14525: $path = '/'.$turnindir.'/';
14526: my ($multipart,$turnin,@pathitems);
14527: my $navmap = Apache::lonnavmaps::navmap->new();
14528: if (defined($navmap)) {
14529: my $mapres = $navmap->getResourceByUrl($map);
14530: if (ref($mapres)) {
14531: my $pcslist = $mapres->map_hierarchy();
14532: if ($pcslist ne '') {
14533: foreach my $pc (split(/,/,$pcslist)) {
14534: my $res = $navmap->getByMapPc($pc);
14535: if (ref($res)) {
14536: my $title = $res->compTitle();
14537: $title =~ s/\W+/_/g;
14538: if ($title ne '') {
1.1075.2.48 raeburn 14539: if (($pc > 1) && (length($title) > 12)) {
14540: $title = substr($title,0,12);
14541: }
1.1015 raeburn 14542: push(@pathitems,$title);
14543: }
14544: }
14545: }
14546: }
14547: my $maptitle = $mapres->compTitle();
14548: $maptitle =~ s/\W+/_/g;
14549: if ($maptitle ne '') {
1.1075.2.48 raeburn 14550: if (length($maptitle) > 12) {
14551: $maptitle = substr($maptitle,0,12);
14552: }
1.1015 raeburn 14553: push(@pathitems,$maptitle);
14554: }
14555: unless ($env{'request.state'} eq 'construct') {
14556: my $res = $navmap->getBySymb($symb);
14557: if (ref($res)) {
14558: my $partlist = $res->parts();
14559: my $totaluploads = 0;
14560: if (ref($partlist) eq 'ARRAY') {
14561: foreach my $part (@{$partlist}) {
14562: my @types = $res->responseType($part);
14563: my @ids = $res->responseIds($part);
14564: for (my $i=0; $i < scalar(@ids); $i++) {
14565: if ($types[$i] eq 'essay') {
14566: my $partid = $part.'_'.$ids[$i];
14567: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14568: $totaluploads ++;
14569: }
14570: }
14571: }
14572: }
14573: if ($totaluploads > 1) {
14574: $multiresp = 1;
14575: }
14576: }
14577: }
14578: }
14579: } else {
14580: return;
14581: }
14582: } else {
14583: return;
14584: }
14585: my $restitle=&Apache::lonnet::gettitle($symb);
14586: $restitle =~ s/\W+/_/g;
14587: if ($restitle eq '') {
14588: $restitle = ($resurl =~ m{/[^/]+$});
14589: if ($restitle eq '') {
14590: $restitle = time;
14591: }
14592: }
1.1075.2.48 raeburn 14593: if (length($restitle) > 12) {
14594: $restitle = substr($restitle,0,12);
14595: }
1.1015 raeburn 14596: push(@pathitems,$restitle);
14597: $path .= join('/',@pathitems);
14598: }
14599: return ($path,$multiresp);
14600: }
14601:
14602: =pod
14603:
1.464 albertel 14604: =back
1.41 ng 14605:
1.112 bowersj2 14606: =head1 CSV Upload/Handling functions
1.38 albertel 14607:
1.41 ng 14608: =over 4
14609:
1.648 raeburn 14610: =item * &upfile_store($r)
1.41 ng 14611:
14612: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14613: needs $env{'form.upfile'}
1.41 ng 14614: returns $datatoken to be put into hidden field
14615:
14616: =cut
1.31 albertel 14617:
14618: sub upfile_store {
14619: my $r=shift;
1.258 albertel 14620: $env{'form.upfile'}=~s/\r/\n/gs;
14621: $env{'form.upfile'}=~s/\f/\n/gs;
14622: $env{'form.upfile'}=~s/\n+/\n/gs;
14623: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14624:
1.1075.2.128 raeburn 14625: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14626: '_enroll_'.$env{'request.course.id'}.'_'.
14627: time.'_'.$$);
14628: return if ($datatoken eq '');
14629:
1.31 albertel 14630: {
1.158 raeburn 14631: my $datafile = $r->dir_config('lonDaemons').
14632: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14633: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14634: print $fh $env{'form.upfile'};
1.158 raeburn 14635: close($fh);
14636: }
1.31 albertel 14637: }
14638: return $datatoken;
14639: }
14640:
1.56 matthew 14641: =pod
14642:
1.1075.2.128 raeburn 14643: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14644:
14645: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14646: $datatoken is the name to assign to the temporary file.
1.258 albertel 14647: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14648:
14649: =cut
1.31 albertel 14650:
14651: sub load_tmp_file {
1.1075.2.128 raeburn 14652: my ($r,$datatoken) = @_;
14653: return if ($datatoken eq '');
1.31 albertel 14654: my @studentdata=();
14655: {
1.158 raeburn 14656: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14657: '/tmp/'.$datatoken.'.tmp';
14658: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14659: @studentdata=<$fh>;
14660: close($fh);
14661: }
1.31 albertel 14662: }
1.258 albertel 14663: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14664: }
14665:
1.1075.2.128 raeburn 14666: sub valid_datatoken {
14667: my ($datatoken) = @_;
1.1075.2.131 raeburn 14668: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14669: return $datatoken;
14670: }
14671: return;
14672: }
14673:
1.56 matthew 14674: =pod
14675:
1.648 raeburn 14676: =item * &upfile_record_sep()
1.41 ng 14677:
14678: Separate uploaded file into records
14679: returns array of records,
1.258 albertel 14680: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14681:
14682: =cut
1.31 albertel 14683:
14684: sub upfile_record_sep {
1.258 albertel 14685: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14686: } else {
1.248 albertel 14687: my @records;
1.258 albertel 14688: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14689: if ($line=~/^\s*$/) { next; }
14690: push(@records,$line);
14691: }
14692: return @records;
1.31 albertel 14693: }
14694: }
14695:
1.56 matthew 14696: =pod
14697:
1.648 raeburn 14698: =item * &record_sep($record)
1.41 ng 14699:
1.258 albertel 14700: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14701:
14702: =cut
14703:
1.263 www 14704: sub takeleft {
14705: my $index=shift;
14706: return substr('0000'.$index,-4,4);
14707: }
14708:
1.31 albertel 14709: sub record_sep {
14710: my $record=shift;
14711: my %components=();
1.258 albertel 14712: if ($env{'form.upfiletype'} eq 'xml') {
14713: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14714: my $i=0;
1.356 albertel 14715: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14716: $field=~s/^(\"|\')//;
14717: $field=~s/(\"|\')$//;
1.263 www 14718: $components{&takeleft($i)}=$field;
1.31 albertel 14719: $i++;
14720: }
1.258 albertel 14721: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14722: my $i=0;
1.356 albertel 14723: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14724: $field=~s/^(\"|\')//;
14725: $field=~s/(\"|\')$//;
1.263 www 14726: $components{&takeleft($i)}=$field;
1.31 albertel 14727: $i++;
14728: }
14729: } else {
1.561 www 14730: my $separator=',';
1.480 banghart 14731: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14732: $separator=';';
1.480 banghart 14733: }
1.31 albertel 14734: my $i=0;
1.561 www 14735: # the character we are looking for to indicate the end of a quote or a record
14736: my $looking_for=$separator;
14737: # do not add the characters to the fields
14738: my $ignore=0;
14739: # we just encountered a separator (or the beginning of the record)
14740: my $just_found_separator=1;
14741: # store the field we are working on here
14742: my $field='';
14743: # work our way through all characters in record
14744: foreach my $character ($record=~/(.)/g) {
14745: if ($character eq $looking_for) {
14746: if ($character ne $separator) {
14747: # Found the end of a quote, again looking for separator
14748: $looking_for=$separator;
14749: $ignore=1;
14750: } else {
14751: # Found a separator, store away what we got
14752: $components{&takeleft($i)}=$field;
14753: $i++;
14754: $just_found_separator=1;
14755: $ignore=0;
14756: $field='';
14757: }
14758: next;
14759: }
14760: # single or double quotation marks after a separator indicate beginning of a quote
14761: # we are now looking for the end of the quote and need to ignore separators
14762: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14763: $looking_for=$character;
14764: next;
14765: }
14766: # ignore would be true after we reached the end of a quote
14767: if ($ignore) { next; }
14768: if (($just_found_separator) && ($character=~/\s/)) { next; }
14769: $field.=$character;
14770: $just_found_separator=0;
1.31 albertel 14771: }
1.561 www 14772: # catch the very last entry, since we never encountered the separator
14773: $components{&takeleft($i)}=$field;
1.31 albertel 14774: }
14775: return %components;
14776: }
14777:
1.144 matthew 14778: ######################################################
14779: ######################################################
14780:
1.56 matthew 14781: =pod
14782:
1.648 raeburn 14783: =item * &upfile_select_html()
1.41 ng 14784:
1.144 matthew 14785: Return HTML code to select a file from the users machine and specify
14786: the file type.
1.41 ng 14787:
14788: =cut
14789:
1.144 matthew 14790: ######################################################
14791: ######################################################
1.31 albertel 14792: sub upfile_select_html {
1.144 matthew 14793: my %Types = (
14794: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14795: semisv => &mt('Semicolon separated values'),
1.144 matthew 14796: space => &mt('Space separated'),
14797: tab => &mt('Tabulator separated'),
14798: # xml => &mt('HTML/XML'),
14799: );
14800: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14801: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14802: foreach my $type (sort(keys(%Types))) {
14803: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14804: }
14805: $Str .= "</select>\n";
14806: return $Str;
1.31 albertel 14807: }
14808:
1.301 albertel 14809: sub get_samples {
14810: my ($records,$toget) = @_;
14811: my @samples=({});
14812: my $got=0;
14813: foreach my $rec (@$records) {
14814: my %temp = &record_sep($rec);
14815: if (! grep(/\S/, values(%temp))) { next; }
14816: if (%temp) {
14817: $samples[$got]=\%temp;
14818: $got++;
14819: if ($got == $toget) { last; }
14820: }
14821: }
14822: return \@samples;
14823: }
14824:
1.144 matthew 14825: ######################################################
14826: ######################################################
14827:
1.56 matthew 14828: =pod
14829:
1.648 raeburn 14830: =item * &csv_print_samples($r,$records)
1.41 ng 14831:
14832: Prints a table of sample values from each column uploaded $r is an
14833: Apache Request ref, $records is an arrayref from
14834: &Apache::loncommon::upfile_record_sep
14835:
14836: =cut
14837:
1.144 matthew 14838: ######################################################
14839: ######################################################
1.31 albertel 14840: sub csv_print_samples {
14841: my ($r,$records) = @_;
1.662 bisitz 14842: my $samples = &get_samples($records,5);
1.301 albertel 14843:
1.594 raeburn 14844: $r->print(&mt('Samples').'<br />'.&start_data_table().
14845: &start_data_table_header_row());
1.356 albertel 14846: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14847: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14848: $r->print(&end_data_table_header_row());
1.301 albertel 14849: foreach my $hash (@$samples) {
1.594 raeburn 14850: $r->print(&start_data_table_row());
1.356 albertel 14851: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14852: $r->print('<td>');
1.356 albertel 14853: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14854: $r->print('</td>');
14855: }
1.594 raeburn 14856: $r->print(&end_data_table_row());
1.31 albertel 14857: }
1.594 raeburn 14858: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14859: }
14860:
1.144 matthew 14861: ######################################################
14862: ######################################################
14863:
1.56 matthew 14864: =pod
14865:
1.648 raeburn 14866: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14867:
14868: Prints a table to create associations between values and table columns.
1.144 matthew 14869:
1.41 ng 14870: $r is an Apache Request ref,
14871: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14872: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14873:
14874: =cut
14875:
1.144 matthew 14876: ######################################################
14877: ######################################################
1.31 albertel 14878: sub csv_print_select_table {
14879: my ($r,$records,$d) = @_;
1.301 albertel 14880: my $i=0;
14881: my $samples = &get_samples($records,1);
1.144 matthew 14882: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14883: &start_data_table().&start_data_table_header_row().
1.144 matthew 14884: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14885: '<th>'.&mt('Column').'</th>'.
14886: &end_data_table_header_row()."\n");
1.356 albertel 14887: foreach my $array_ref (@$d) {
14888: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14889: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14890:
1.875 bisitz 14891: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14892: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14893: $r->print('<option value="none"></option>');
1.356 albertel 14894: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14895: $r->print('<option value="'.$sample.'"'.
14896: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14897: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14898: }
1.594 raeburn 14899: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14900: $i++;
14901: }
1.594 raeburn 14902: $r->print(&end_data_table());
1.31 albertel 14903: $i--;
14904: return $i;
14905: }
1.56 matthew 14906:
1.144 matthew 14907: ######################################################
14908: ######################################################
14909:
1.56 matthew 14910: =pod
1.31 albertel 14911:
1.648 raeburn 14912: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14913:
14914: Prints a table of sample values from the upload and can make associate samples to internal names.
14915:
14916: $r is an Apache Request ref,
14917: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14918: $d is an array of 2 element arrays (internal name, displayed name)
14919:
14920: =cut
14921:
1.144 matthew 14922: ######################################################
14923: ######################################################
1.31 albertel 14924: sub csv_samples_select_table {
14925: my ($r,$records,$d) = @_;
14926: my $i=0;
1.144 matthew 14927: #
1.662 bisitz 14928: my $max_samples = 5;
14929: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14930: $r->print(&start_data_table().
14931: &start_data_table_header_row().'<th>'.
14932: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14933: &end_data_table_header_row());
1.301 albertel 14934:
14935: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14936: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14937: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14938: foreach my $option (@$d) {
14939: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14940: $r->print('<option value="'.$value.'"'.
1.253 albertel 14941: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14942: $display.'</option>');
1.31 albertel 14943: }
14944: $r->print('</select></td><td>');
1.662 bisitz 14945: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14946: if (defined($samples->[$line]{$key})) {
14947: $r->print($samples->[$line]{$key}."<br />\n");
14948: }
14949: }
1.594 raeburn 14950: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14951: $i++;
14952: }
1.594 raeburn 14953: $r->print(&end_data_table());
1.31 albertel 14954: $i--;
14955: return($i);
1.115 matthew 14956: }
14957:
1.144 matthew 14958: ######################################################
14959: ######################################################
14960:
1.115 matthew 14961: =pod
14962:
1.648 raeburn 14963: =item * &clean_excel_name($name)
1.115 matthew 14964:
14965: Returns a replacement for $name which does not contain any illegal characters.
14966:
14967: =cut
14968:
1.144 matthew 14969: ######################################################
14970: ######################################################
1.115 matthew 14971: sub clean_excel_name {
14972: my ($name) = @_;
14973: $name =~ s/[:\*\?\/\\]//g;
14974: if (length($name) > 31) {
14975: $name = substr($name,0,31);
14976: }
14977: return $name;
1.25 albertel 14978: }
1.84 albertel 14979:
1.85 albertel 14980: =pod
14981:
1.648 raeburn 14982: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14983:
14984: Returns either 1 or undef
14985:
14986: 1 if the part is to be hidden, undef if it is to be shown
14987:
14988: Arguments are:
14989:
14990: $id the id of the part to be checked
14991: $symb, optional the symb of the resource to check
14992: $udom, optional the domain of the user to check for
14993: $uname, optional the username of the user to check for
14994:
14995: =cut
1.84 albertel 14996:
14997: sub check_if_partid_hidden {
14998: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14999: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15000: $symb,$udom,$uname);
1.141 albertel 15001: my $truth=1;
15002: #if the string starts with !, then the list is the list to show not hide
15003: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15004: my @hiddenlist=split(/,/,$hiddenparts);
15005: foreach my $checkid (@hiddenlist) {
1.141 albertel 15006: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15007: }
1.141 albertel 15008: return !$truth;
1.84 albertel 15009: }
1.127 matthew 15010:
1.138 matthew 15011:
15012: ############################################################
15013: ############################################################
15014:
15015: =pod
15016:
1.157 matthew 15017: =back
15018:
1.138 matthew 15019: =head1 cgi-bin script and graphing routines
15020:
1.157 matthew 15021: =over 4
15022:
1.648 raeburn 15023: =item * &get_cgi_id()
1.138 matthew 15024:
15025: Inputs: none
15026:
15027: Returns an id which can be used to pass environment variables
15028: to various cgi-bin scripts. These environment variables will
15029: be removed from the users environment after a given time by
15030: the routine &Apache::lonnet::transfer_profile_to_env.
15031:
15032: =cut
15033:
15034: ############################################################
15035: ############################################################
1.152 albertel 15036: my $uniq=0;
1.136 matthew 15037: sub get_cgi_id {
1.154 albertel 15038: $uniq=($uniq+1)%100000;
1.280 albertel 15039: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15040: }
15041:
1.127 matthew 15042: ############################################################
15043: ############################################################
15044:
15045: =pod
15046:
1.648 raeburn 15047: =item * &DrawBarGraph()
1.127 matthew 15048:
1.138 matthew 15049: Facilitates the plotting of data in a (stacked) bar graph.
15050: Puts plot definition data into the users environment in order for
15051: graph.png to plot it. Returns an <img> tag for the plot.
15052: The bars on the plot are labeled '1','2',...,'n'.
15053:
15054: Inputs:
15055:
15056: =over 4
15057:
15058: =item $Title: string, the title of the plot
15059:
15060: =item $xlabel: string, text describing the X-axis of the plot
15061:
15062: =item $ylabel: string, text describing the Y-axis of the plot
15063:
15064: =item $Max: scalar, the maximum Y value to use in the plot
15065: If $Max is < any data point, the graph will not be rendered.
15066:
1.140 matthew 15067: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15068: they are plotted. If undefined, default values will be used.
15069:
1.178 matthew 15070: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15071:
1.138 matthew 15072: =item @Values: An array of array references. Each array reference holds data
15073: to be plotted in a stacked bar chart.
15074:
1.239 matthew 15075: =item If the final element of @Values is a hash reference the key/value
15076: pairs will be added to the graph definition.
15077:
1.138 matthew 15078: =back
15079:
15080: Returns:
15081:
15082: An <img> tag which references graph.png and the appropriate identifying
15083: information for the plot.
15084:
1.127 matthew 15085: =cut
15086:
15087: ############################################################
15088: ############################################################
1.134 matthew 15089: sub DrawBarGraph {
1.178 matthew 15090: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15091: #
15092: if (! defined($colors)) {
15093: $colors = ['#33ff00',
15094: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15095: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15096: ];
15097: }
1.228 matthew 15098: my $extra_settings = {};
15099: if (ref($Values[-1]) eq 'HASH') {
15100: $extra_settings = pop(@Values);
15101: }
1.127 matthew 15102: #
1.136 matthew 15103: my $identifier = &get_cgi_id();
15104: my $id = 'cgi.'.$identifier;
1.129 matthew 15105: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15106: return '';
15107: }
1.225 matthew 15108: #
15109: my @Labels;
15110: if (defined($labels)) {
15111: @Labels = @$labels;
15112: } else {
15113: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 15114: push(@Labels,$i+1);
1.225 matthew 15115: }
15116: }
15117: #
1.129 matthew 15118: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15119: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15120: my %ValuesHash;
15121: my $NumSets=1;
15122: foreach my $array (@Values) {
15123: next if (! ref($array));
1.136 matthew 15124: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15125: join(',',@$array);
1.129 matthew 15126: }
1.127 matthew 15127: #
1.136 matthew 15128: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15129: if ($NumBars < 3) {
15130: $width = 120+$NumBars*32;
1.220 matthew 15131: $xskip = 1;
1.225 matthew 15132: $bar_width = 30;
15133: } elsif ($NumBars < 5) {
15134: $width = 120+$NumBars*20;
15135: $xskip = 1;
15136: $bar_width = 20;
1.220 matthew 15137: } elsif ($NumBars < 10) {
1.136 matthew 15138: $width = 120+$NumBars*15;
15139: $xskip = 1;
15140: $bar_width = 15;
15141: } elsif ($NumBars <= 25) {
15142: $width = 120+$NumBars*11;
15143: $xskip = 5;
15144: $bar_width = 8;
15145: } elsif ($NumBars <= 50) {
15146: $width = 120+$NumBars*8;
15147: $xskip = 5;
15148: $bar_width = 4;
15149: } else {
15150: $width = 120+$NumBars*8;
15151: $xskip = 5;
15152: $bar_width = 4;
15153: }
15154: #
1.137 matthew 15155: $Max = 1 if ($Max < 1);
15156: if ( int($Max) < $Max ) {
15157: $Max++;
15158: $Max = int($Max);
15159: }
1.127 matthew 15160: $Title = '' if (! defined($Title));
15161: $xlabel = '' if (! defined($xlabel));
15162: $ylabel = '' if (! defined($ylabel));
1.369 www 15163: $ValuesHash{$id.'.title'} = &escape($Title);
15164: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15165: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15166: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15167: $ValuesHash{$id.'.NumBars'} = $NumBars;
15168: $ValuesHash{$id.'.NumSets'} = $NumSets;
15169: $ValuesHash{$id.'.PlotType'} = 'bar';
15170: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15171: $ValuesHash{$id.'.height'} = $height;
15172: $ValuesHash{$id.'.width'} = $width;
15173: $ValuesHash{$id.'.xskip'} = $xskip;
15174: $ValuesHash{$id.'.bar_width'} = $bar_width;
15175: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15176: #
1.228 matthew 15177: # Deal with other parameters
15178: while (my ($key,$value) = each(%$extra_settings)) {
15179: $ValuesHash{$id.'.'.$key} = $value;
15180: }
15181: #
1.646 raeburn 15182: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15183: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15184: }
15185:
15186: ############################################################
15187: ############################################################
15188:
15189: =pod
15190:
1.648 raeburn 15191: =item * &DrawXYGraph()
1.137 matthew 15192:
1.138 matthew 15193: Facilitates the plotting of data in an XY graph.
15194: Puts plot definition data into the users environment in order for
15195: graph.png to plot it. Returns an <img> tag for the plot.
15196:
15197: Inputs:
15198:
15199: =over 4
15200:
15201: =item $Title: string, the title of the plot
15202:
15203: =item $xlabel: string, text describing the X-axis of the plot
15204:
15205: =item $ylabel: string, text describing the Y-axis of the plot
15206:
15207: =item $Max: scalar, the maximum Y value to use in the plot
15208: If $Max is < any data point, the graph will not be rendered.
15209:
15210: =item $colors: Array ref containing the hex color codes for the data to be
15211: plotted in. If undefined, default values will be used.
15212:
15213: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15214:
15215: =item $Ydata: Array ref containing Array refs.
1.185 www 15216: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15217:
15218: =item %Values: hash indicating or overriding any default values which are
15219: passed to graph.png.
15220: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15221:
15222: =back
15223:
15224: Returns:
15225:
15226: An <img> tag which references graph.png and the appropriate identifying
15227: information for the plot.
15228:
1.137 matthew 15229: =cut
15230:
15231: ############################################################
15232: ############################################################
15233: sub DrawXYGraph {
15234: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15235: #
15236: # Create the identifier for the graph
15237: my $identifier = &get_cgi_id();
15238: my $id = 'cgi.'.$identifier;
15239: #
15240: $Title = '' if (! defined($Title));
15241: $xlabel = '' if (! defined($xlabel));
15242: $ylabel = '' if (! defined($ylabel));
15243: my %ValuesHash =
15244: (
1.369 www 15245: $id.'.title' => &escape($Title),
15246: $id.'.xlabel' => &escape($xlabel),
15247: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15248: $id.'.y_max_value'=> $Max,
15249: $id.'.labels' => join(',',@$Xlabels),
15250: $id.'.PlotType' => 'XY',
15251: );
15252: #
15253: if (defined($colors) && ref($colors) eq 'ARRAY') {
15254: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15255: }
15256: #
15257: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15258: return '';
15259: }
15260: my $NumSets=1;
1.138 matthew 15261: foreach my $array (@{$Ydata}){
1.137 matthew 15262: next if (! ref($array));
15263: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15264: }
1.138 matthew 15265: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15266: #
15267: # Deal with other parameters
15268: while (my ($key,$value) = each(%Values)) {
15269: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15270: }
15271: #
1.646 raeburn 15272: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15273: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15274: }
15275:
15276: ############################################################
15277: ############################################################
15278:
15279: =pod
15280:
1.648 raeburn 15281: =item * &DrawXYYGraph()
1.138 matthew 15282:
15283: Facilitates the plotting of data in an XY graph with two Y axes.
15284: Puts plot definition data into the users environment in order for
15285: graph.png to plot it. Returns an <img> tag for the plot.
15286:
15287: Inputs:
15288:
15289: =over 4
15290:
15291: =item $Title: string, the title of the plot
15292:
15293: =item $xlabel: string, text describing the X-axis of the plot
15294:
15295: =item $ylabel: string, text describing the Y-axis of the plot
15296:
15297: =item $colors: Array ref containing the hex color codes for the data to be
15298: plotted in. If undefined, default values will be used.
15299:
15300: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15301:
15302: =item $Ydata1: The first data set
15303:
15304: =item $Min1: The minimum value of the left Y-axis
15305:
15306: =item $Max1: The maximum value of the left Y-axis
15307:
15308: =item $Ydata2: The second data set
15309:
15310: =item $Min2: The minimum value of the right Y-axis
15311:
15312: =item $Max2: The maximum value of the left Y-axis
15313:
15314: =item %Values: hash indicating or overriding any default values which are
15315: passed to graph.png.
15316: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15317:
15318: =back
15319:
15320: Returns:
15321:
15322: An <img> tag which references graph.png and the appropriate identifying
15323: information for the plot.
1.136 matthew 15324:
15325: =cut
15326:
15327: ############################################################
15328: ############################################################
1.137 matthew 15329: sub DrawXYYGraph {
15330: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15331: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15332: #
15333: # Create the identifier for the graph
15334: my $identifier = &get_cgi_id();
15335: my $id = 'cgi.'.$identifier;
15336: #
15337: $Title = '' if (! defined($Title));
15338: $xlabel = '' if (! defined($xlabel));
15339: $ylabel = '' if (! defined($ylabel));
15340: my %ValuesHash =
15341: (
1.369 www 15342: $id.'.title' => &escape($Title),
15343: $id.'.xlabel' => &escape($xlabel),
15344: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15345: $id.'.labels' => join(',',@$Xlabels),
15346: $id.'.PlotType' => 'XY',
15347: $id.'.NumSets' => 2,
1.137 matthew 15348: $id.'.two_axes' => 1,
15349: $id.'.y1_max_value' => $Max1,
15350: $id.'.y1_min_value' => $Min1,
15351: $id.'.y2_max_value' => $Max2,
15352: $id.'.y2_min_value' => $Min2,
1.136 matthew 15353: );
15354: #
1.137 matthew 15355: if (defined($colors) && ref($colors) eq 'ARRAY') {
15356: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15357: }
15358: #
15359: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15360: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15361: return '';
15362: }
15363: my $NumSets=1;
1.137 matthew 15364: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15365: next if (! ref($array));
15366: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15367: }
15368: #
15369: # Deal with other parameters
15370: while (my ($key,$value) = each(%Values)) {
15371: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15372: }
15373: #
1.646 raeburn 15374: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15375: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15376: }
15377:
15378: ############################################################
15379: ############################################################
15380:
15381: =pod
15382:
1.157 matthew 15383: =back
15384:
1.139 matthew 15385: =head1 Statistics helper routines?
15386:
15387: Bad place for them but what the hell.
15388:
1.157 matthew 15389: =over 4
15390:
1.648 raeburn 15391: =item * &chartlink()
1.139 matthew 15392:
15393: Returns a link to the chart for a specific student.
15394:
15395: Inputs:
15396:
15397: =over 4
15398:
15399: =item $linktext: The text of the link
15400:
15401: =item $sname: The students username
15402:
15403: =item $sdomain: The students domain
15404:
15405: =back
15406:
1.157 matthew 15407: =back
15408:
1.139 matthew 15409: =cut
15410:
15411: ############################################################
15412: ############################################################
15413: sub chartlink {
15414: my ($linktext, $sname, $sdomain) = @_;
15415: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15416: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15417: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15418: '">'.$linktext.'</a>';
1.153 matthew 15419: }
15420:
15421: #######################################################
15422: #######################################################
15423:
15424: =pod
15425:
15426: =head1 Course Environment Routines
1.157 matthew 15427:
15428: =over 4
1.153 matthew 15429:
1.648 raeburn 15430: =item * &restore_course_settings()
1.153 matthew 15431:
1.648 raeburn 15432: =item * &store_course_settings()
1.153 matthew 15433:
15434: Restores/Store indicated form parameters from the course environment.
15435: Will not overwrite existing values of the form parameters.
15436:
15437: Inputs:
15438: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15439:
15440: a hash ref describing the data to be stored. For example:
15441:
15442: %Save_Parameters = ('Status' => 'scalar',
15443: 'chartoutputmode' => 'scalar',
15444: 'chartoutputdata' => 'scalar',
15445: 'Section' => 'array',
1.373 raeburn 15446: 'Group' => 'array',
1.153 matthew 15447: 'StudentData' => 'array',
15448: 'Maps' => 'array');
15449:
15450: Returns: both routines return nothing
15451:
1.631 raeburn 15452: =back
15453:
1.153 matthew 15454: =cut
15455:
15456: #######################################################
15457: #######################################################
15458: sub store_course_settings {
1.496 albertel 15459: return &store_settings($env{'request.course.id'},@_);
15460: }
15461:
15462: sub store_settings {
1.153 matthew 15463: # save to the environment
15464: # appenv the same items, just to be safe
1.300 albertel 15465: my $udom = $env{'user.domain'};
15466: my $uname = $env{'user.name'};
1.496 albertel 15467: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15468: my %SaveHash;
15469: my %AppHash;
15470: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15471: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15472: my $envname = 'environment.'.$basename;
1.258 albertel 15473: if (exists($env{'form.'.$setting})) {
1.153 matthew 15474: # Save this value away
15475: if ($type eq 'scalar' &&
1.258 albertel 15476: (! exists($env{$envname}) ||
15477: $env{$envname} ne $env{'form.'.$setting})) {
15478: $SaveHash{$basename} = $env{'form.'.$setting};
15479: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15480: } elsif ($type eq 'array') {
15481: my $stored_form;
1.258 albertel 15482: if (ref($env{'form.'.$setting})) {
1.153 matthew 15483: $stored_form = join(',',
15484: map {
1.369 www 15485: &escape($_);
1.258 albertel 15486: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15487: } else {
15488: $stored_form =
1.369 www 15489: &escape($env{'form.'.$setting});
1.153 matthew 15490: }
15491: # Determine if the array contents are the same.
1.258 albertel 15492: if ($stored_form ne $env{$envname}) {
1.153 matthew 15493: $SaveHash{$basename} = $stored_form;
15494: $AppHash{$envname} = $stored_form;
15495: }
15496: }
15497: }
15498: }
15499: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15500: $udom,$uname);
1.153 matthew 15501: if ($put_result !~ /^(ok|delayed)/) {
15502: &Apache::lonnet::logthis('unable to save form parameters, '.
15503: 'got error:'.$put_result);
15504: }
15505: # Make sure these settings stick around in this session, too
1.646 raeburn 15506: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15507: return;
15508: }
15509:
15510: sub restore_course_settings {
1.499 albertel 15511: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15512: }
15513:
15514: sub restore_settings {
15515: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15516: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15517: next if (exists($env{'form.'.$setting}));
1.496 albertel 15518: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15519: '.'.$setting;
1.258 albertel 15520: if (exists($env{$envname})) {
1.153 matthew 15521: if ($type eq 'scalar') {
1.258 albertel 15522: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15523: } elsif ($type eq 'array') {
1.258 albertel 15524: $env{'form.'.$setting} = [
1.153 matthew 15525: map {
1.369 www 15526: &unescape($_);
1.258 albertel 15527: } split(',',$env{$envname})
1.153 matthew 15528: ];
15529: }
15530: }
15531: }
1.127 matthew 15532: }
15533:
1.618 raeburn 15534: #######################################################
15535: #######################################################
15536:
15537: =pod
15538:
15539: =head1 Domain E-mail Routines
15540:
15541: =over 4
15542:
1.648 raeburn 15543: =item * &build_recipient_list()
1.618 raeburn 15544:
1.1075.2.44 raeburn 15545: Build recipient lists for following types of e-mail:
1.766 raeburn 15546: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 15547: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15548: module change checking, student/employee ID conflict checks, as
15549: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15550: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15551:
15552: Inputs:
1.1075.2.44 raeburn 15553: defmail (scalar - email address of default recipient),
15554: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15555: requestsmail, updatesmail, or idconflictsmail).
15556:
1.619 raeburn 15557: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 15558:
15559: origmail (scalar - email address of recipient from loncapa.conf,
15560: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 15561:
1.1075.2.139 raeburn 15562: $requname username of requester (if mailing type is helpdeskmail)
15563:
15564: $requdom domain of requester (if mailing type is helpdeskmail)
15565:
15566: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15567:
1.655 raeburn 15568: Returns: comma separated list of addresses to which to send e-mail.
15569:
15570: =back
1.618 raeburn 15571:
15572: =cut
15573:
15574: ############################################################
15575: ############################################################
15576: sub build_recipient_list {
1.1075.2.139 raeburn 15577: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15578: my @recipients;
1.1075.2.122 raeburn 15579: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15580: my %domconfig =
1.1075.2.122 raeburn 15581: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15582: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15583: if (exists($domconfig{'contacts'}{$mailing})) {
15584: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15585: my @contacts = ('adminemail','supportemail');
15586: foreach my $item (@contacts) {
15587: if ($domconfig{'contacts'}{$mailing}{$item}) {
15588: my $addr = $domconfig{'contacts'}{$item};
15589: if (!grep(/^\Q$addr\E$/,@recipients)) {
15590: push(@recipients,$addr);
15591: }
1.619 raeburn 15592: }
1.1075.2.122 raeburn 15593: }
15594: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15595: if ($mailing eq 'helpdeskmail') {
15596: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15597: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15598: my @ok_bccs;
15599: foreach my $bcc (@bccs) {
15600: $bcc =~ s/^\s+//g;
15601: $bcc =~ s/\s+$//g;
15602: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15603: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15604: push(@ok_bccs,$bcc);
15605: }
15606: }
15607: }
15608: if (@ok_bccs > 0) {
15609: $allbcc = join(', ',@ok_bccs);
15610: }
15611: }
15612: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15613: }
15614: }
1.766 raeburn 15615: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15616: $lastresort = $origmail;
1.618 raeburn 15617: }
1.1075.2.139 raeburn 15618: if ($mailing eq 'helpdeskmail') {
15619: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15620: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15621: my ($inststatus,$inststatus_checked);
15622: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15623: ($env{'user.domain'} ne 'public')) {
15624: $inststatus_checked = 1;
15625: $inststatus = $env{'environment.inststatus'};
15626: }
15627: unless ($inststatus_checked) {
15628: if (($requname ne '') && ($requdom ne '')) {
15629: if (($requname =~ /^$match_username$/) &&
15630: ($requdom =~ /^$match_domain$/) &&
15631: (&Apache::lonnet::domain($requdom))) {
15632: my $requhome = &Apache::lonnet::homeserver($requname,
15633: $requdom);
15634: unless ($requhome eq 'no_host') {
15635: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15636: $inststatus = $userenv{'inststatus'};
15637: $inststatus_checked = 1;
15638: }
15639: }
15640: }
15641: }
15642: unless ($inststatus_checked) {
15643: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15644: my %srch = (srchby => 'email',
15645: srchdomain => $defdom,
15646: srchterm => $reqemail,
15647: srchtype => 'exact');
15648: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15649: foreach my $uname (keys(%srch_results)) {
15650: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15651: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15652: $inststatus_checked = 1;
15653: last;
15654: }
15655: }
15656: unless ($inststatus_checked) {
15657: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15658: if ($dirsrchres eq 'ok') {
15659: foreach my $uname (keys(%srch_results)) {
15660: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15661: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15662: $inststatus_checked = 1;
15663: last;
15664: }
15665: }
15666: }
15667: }
15668: }
15669: }
15670: if ($inststatus ne '') {
15671: foreach my $status (split(/\:/,$inststatus)) {
15672: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15673: my @contacts = ('adminemail','supportemail');
15674: foreach my $item (@contacts) {
15675: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15676: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15677: if (!grep(/^\Q$addr\E$/,@recipients)) {
15678: push(@recipients,$addr);
15679: }
15680: }
15681: }
15682: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15683: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15684: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15685: my @ok_bccs;
15686: foreach my $bcc (@bccs) {
15687: $bcc =~ s/^\s+//g;
15688: $bcc =~ s/\s+$//g;
15689: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15690: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15691: push(@ok_bccs,$bcc);
15692: }
15693: }
15694: }
15695: if (@ok_bccs > 0) {
15696: $allbcc = join(', ',@ok_bccs);
15697: }
15698: }
15699: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15700: last;
15701: }
15702: }
15703: }
15704: }
15705: }
1.619 raeburn 15706: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15707: $lastresort = $origmail;
15708: }
1.1075.2.128 raeburn 15709: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15710: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15711: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15712: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15713: my %what = (
15714: perlvar => 1,
15715: );
15716: my $primary = &Apache::lonnet::domain($defdom,'primary');
15717: if ($primary) {
15718: my $gotaddr;
15719: my ($result,$returnhash) =
15720: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15721: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15722: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15723: $lastresort = $returnhash->{'lonSupportEMail'};
15724: $gotaddr = 1;
15725: }
15726: }
15727: unless ($gotaddr) {
15728: my $uintdom = &Apache::lonnet::internet_dom($primary);
15729: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15730: unless ($uintdom eq $intdom) {
15731: my %domconfig =
15732: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15733: if (ref($domconfig{'contacts'}) eq 'HASH') {
15734: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15735: my @contacts = ('adminemail','supportemail');
15736: foreach my $item (@contacts) {
15737: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15738: my $addr = $domconfig{'contacts'}{$item};
15739: if (!grep(/^\Q$addr\E$/,@recipients)) {
15740: push(@recipients,$addr);
15741: }
15742: }
15743: }
15744: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15745: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15746: }
15747: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15748: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15749: my @ok_bccs;
15750: foreach my $bcc (@bccs) {
15751: $bcc =~ s/^\s+//g;
15752: $bcc =~ s/\s+$//g;
15753: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15754: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15755: push(@ok_bccs,$bcc);
15756: }
15757: }
15758: }
15759: if (@ok_bccs > 0) {
15760: $allbcc = join(', ',@ok_bccs);
15761: }
15762: }
15763: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15764: }
15765: }
15766: }
15767: }
15768: }
15769: }
1.618 raeburn 15770: }
1.688 raeburn 15771: if (defined($defmail)) {
15772: if ($defmail ne '') {
15773: push(@recipients,$defmail);
15774: }
1.618 raeburn 15775: }
15776: if ($otheremails) {
1.619 raeburn 15777: my @others;
15778: if ($otheremails =~ /,/) {
15779: @others = split(/,/,$otheremails);
1.618 raeburn 15780: } else {
1.619 raeburn 15781: push(@others,$otheremails);
15782: }
15783: foreach my $addr (@others) {
15784: if (!grep(/^\Q$addr\E$/,@recipients)) {
15785: push(@recipients,$addr);
15786: }
1.618 raeburn 15787: }
15788: }
1.1075.2.128 raeburn 15789: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15790: if ((!@recipients) && ($lastresort ne '')) {
15791: push(@recipients,$lastresort);
15792: }
15793: } elsif ($lastresort ne '') {
15794: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15795: push(@recipients,$lastresort);
15796: }
15797: }
15798: my $recipientlist = join(',',@recipients);
15799: if (wantarray) {
15800: return ($recipientlist,$allbcc,$addtext);
15801: } else {
15802: return $recipientlist;
15803: }
1.618 raeburn 15804: }
15805:
1.127 matthew 15806: ############################################################
15807: ############################################################
1.154 albertel 15808:
1.655 raeburn 15809: =pod
15810:
15811: =head1 Course Catalog Routines
15812:
15813: =over 4
15814:
15815: =item * &gather_categories()
15816:
15817: Converts category definitions - keys of categories hash stored in
15818: coursecategories in configuration.db on the primary library server in a
15819: domain - to an array. Also generates javascript and idx hash used to
15820: generate Domain Coordinator interface for editing Course Categories.
15821:
15822: Inputs:
1.663 raeburn 15823:
1.655 raeburn 15824: categories (reference to hash of category definitions).
1.663 raeburn 15825:
1.655 raeburn 15826: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15827: categories and subcategories).
1.663 raeburn 15828:
1.655 raeburn 15829: idx (reference to hash of counters used in Domain Coordinator interface for
15830: editing Course Categories).
1.663 raeburn 15831:
1.655 raeburn 15832: jsarray (reference to array of categories used to create Javascript arrays for
15833: Domain Coordinator interface for editing Course Categories).
15834:
15835: Returns: nothing
15836:
15837: Side effects: populates cats, idx and jsarray.
15838:
15839: =cut
15840:
15841: sub gather_categories {
15842: my ($categories,$cats,$idx,$jsarray) = @_;
15843: my %counters;
15844: my $num = 0;
15845: foreach my $item (keys(%{$categories})) {
15846: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15847: if ($container eq '' && $depth == 0) {
15848: $cats->[$depth][$categories->{$item}] = $cat;
15849: } else {
15850: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15851: }
15852: my ($escitem,$tail) = split(/:/,$item,2);
15853: if ($counters{$tail} eq '') {
15854: $counters{$tail} = $num;
15855: $num ++;
15856: }
15857: if (ref($idx) eq 'HASH') {
15858: $idx->{$item} = $counters{$tail};
15859: }
15860: if (ref($jsarray) eq 'ARRAY') {
15861: push(@{$jsarray->[$counters{$tail}]},$item);
15862: }
15863: }
15864: return;
15865: }
15866:
15867: =pod
15868:
15869: =item * &extract_categories()
15870:
15871: Used to generate breadcrumb trails for course categories.
15872:
15873: Inputs:
1.663 raeburn 15874:
1.655 raeburn 15875: categories (reference to hash of category definitions).
1.663 raeburn 15876:
1.655 raeburn 15877: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15878: categories and subcategories).
1.663 raeburn 15879:
1.655 raeburn 15880: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15881:
1.655 raeburn 15882: allitems (reference to hash - key is category key
15883: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15884:
1.655 raeburn 15885: idx (reference to hash of counters used in Domain Coordinator interface for
15886: editing Course Categories).
1.663 raeburn 15887:
1.655 raeburn 15888: jsarray (reference to array of categories used to create Javascript arrays for
15889: Domain Coordinator interface for editing Course Categories).
15890:
1.665 raeburn 15891: subcats (reference to hash of arrays containing all subcategories within each
15892: category, -recursive)
15893:
1.1075.2.132 raeburn 15894: maxd (reference to hash used to hold max depth for all top-level categories).
15895:
1.655 raeburn 15896: Returns: nothing
15897:
15898: Side effects: populates trails and allitems hash references.
15899:
15900: =cut
15901:
15902: sub extract_categories {
1.1075.2.132 raeburn 15903: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15904: if (ref($categories) eq 'HASH') {
15905: &gather_categories($categories,$cats,$idx,$jsarray);
15906: if (ref($cats->[0]) eq 'ARRAY') {
15907: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15908: my $name = $cats->[0][$i];
15909: my $item = &escape($name).'::0';
15910: my $trailstr;
15911: if ($name eq 'instcode') {
15912: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15913: } elsif ($name eq 'communities') {
15914: $trailstr = &mt('Communities');
1.655 raeburn 15915: } else {
15916: $trailstr = $name;
15917: }
15918: if ($allitems->{$item} eq '') {
15919: push(@{$trails},$trailstr);
15920: $allitems->{$item} = scalar(@{$trails})-1;
15921: }
15922: my @parents = ($name);
15923: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15924: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15925: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15926: if (ref($subcats) eq 'HASH') {
15927: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15928: }
1.1075.2.132 raeburn 15929: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15930: }
15931: } else {
15932: if (ref($subcats) eq 'HASH') {
15933: $subcats->{$item} = [];
1.655 raeburn 15934: }
1.1075.2.132 raeburn 15935: if (ref($maxd) eq 'HASH') {
15936: $maxd->{$name} = 1;
15937: }
1.655 raeburn 15938: }
15939: }
15940: }
15941: }
15942: return;
15943: }
15944:
15945: =pod
15946:
1.1075.2.56 raeburn 15947: =item * &recurse_categories()
1.655 raeburn 15948:
15949: Recursively used to generate breadcrumb trails for course categories.
15950:
15951: Inputs:
1.663 raeburn 15952:
1.655 raeburn 15953: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15954: categories and subcategories).
1.663 raeburn 15955:
1.655 raeburn 15956: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15957:
15958: category (current course category, for which breadcrumb trail is being generated).
15959:
15960: trails (reference to array of breadcrumb trails for each category).
15961:
1.655 raeburn 15962: allitems (reference to hash - key is category key
15963: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15964:
1.655 raeburn 15965: parents (array containing containers directories for current category,
15966: back to top level).
15967:
15968: Returns: nothing
15969:
15970: Side effects: populates trails and allitems hash references
15971:
15972: =cut
15973:
15974: sub recurse_categories {
1.1075.2.132 raeburn 15975: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15976: my $shallower = $depth - 1;
15977: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15978: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15979: my $name = $cats->[$depth]{$category}[$k];
15980: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 15981:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15982: if ($allitems->{$item} eq '') {
15983: push(@{$trails},$trailstr);
15984: $allitems->{$item} = scalar(@{$trails})-1;
15985: }
15986: my $deeper = $depth+1;
15987: push(@{$parents},$category);
1.665 raeburn 15988: if (ref($subcats) eq 'HASH') {
15989: my $subcat = &escape($name).':'.$category.':'.$depth;
15990: for (my $j=@{$parents}; $j>=0; $j--) {
15991: my $higher;
15992: if ($j > 0) {
15993: $higher = &escape($parents->[$j]).':'.
15994: &escape($parents->[$j-1]).':'.$j;
15995: } else {
15996: $higher = &escape($parents->[$j]).'::'.$j;
15997: }
15998: push(@{$subcats->{$higher}},$subcat);
15999: }
16000: }
16001: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 16002: $subcats,$maxd);
1.655 raeburn 16003: pop(@{$parents});
16004: }
16005: } else {
16006: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 16007: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16008: if ($allitems->{$item} eq '') {
16009: push(@{$trails},$trailstr);
16010: $allitems->{$item} = scalar(@{$trails})-1;
16011: }
1.1075.2.132 raeburn 16012: if (ref($maxd) eq 'HASH') {
16013: if ($depth > $maxd->{$parents->[0]}) {
16014: $maxd->{$parents->[0]} = $depth;
16015: }
16016: }
1.655 raeburn 16017: }
16018: return;
16019: }
16020:
1.663 raeburn 16021: =pod
16022:
1.1075.2.56 raeburn 16023: =item * &assign_categories_table()
1.663 raeburn 16024:
16025: Create a datatable for display of hierarchical categories in a domain,
16026: with checkboxes to allow a course to be categorized.
16027:
16028: Inputs:
16029:
16030: cathash - reference to hash of categories defined for the domain (from
16031: configuration.db)
16032:
16033: currcat - scalar with an & separated list of categories assigned to a course.
16034:
1.919 raeburn 16035: type - scalar contains course type (Course or Community).
16036:
1.1075.2.117 raeburn 16037: disabled - scalar (optional) contains disabled="disabled" if input elements are
16038: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16039:
1.663 raeburn 16040: Returns: $output (markup to be displayed)
16041:
16042: =cut
16043:
16044: sub assign_categories_table {
1.1075.2.117 raeburn 16045: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16046: my $output;
16047: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 16048: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16049: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16050: $maxdepth = scalar(@cats);
16051: if (@cats > 0) {
16052: my $itemcount = 0;
16053: if (ref($cats[0]) eq 'ARRAY') {
16054: my @currcategories;
16055: if ($currcat ne '') {
16056: @currcategories = split('&',$currcat);
16057: }
1.919 raeburn 16058: my $table;
1.663 raeburn 16059: for (my $i=0; $i<@{$cats[0]}; $i++) {
16060: my $parent = $cats[0][$i];
1.919 raeburn 16061: next if ($parent eq 'instcode');
16062: if ($type eq 'Community') {
16063: next unless ($parent eq 'communities');
16064: } else {
16065: next if ($parent eq 'communities');
16066: }
1.663 raeburn 16067: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16068: my $item = &escape($parent).'::0';
16069: my $checked = '';
16070: if (@currcategories > 0) {
16071: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16072: $checked = ' checked="checked"';
1.663 raeburn 16073: }
16074: }
1.919 raeburn 16075: my $parent_title = $parent;
16076: if ($parent eq 'communities') {
16077: $parent_title = &mt('Communities');
16078: }
16079: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16080: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16081: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16082: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16083: my $depth = 1;
16084: push(@path,$parent);
1.1075.2.117 raeburn 16085: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16086: pop(@path);
1.919 raeburn 16087: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16088: $itemcount ++;
16089: }
1.919 raeburn 16090: if ($itemcount) {
16091: $output = &Apache::loncommon::start_data_table().
16092: $table.
16093: &Apache::loncommon::end_data_table();
16094: }
1.663 raeburn 16095: }
16096: }
16097: }
16098: return $output;
16099: }
16100:
16101: =pod
16102:
1.1075.2.56 raeburn 16103: =item * &assign_category_rows()
1.663 raeburn 16104:
16105: Create a datatable row for display of nested categories in a domain,
16106: with checkboxes to allow a course to be categorized,called recursively.
16107:
16108: Inputs:
16109:
16110: itemcount - track row number for alternating colors
16111:
16112: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16113: categories and subcategories.
16114:
16115: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16116:
16117: parent - parent of current category item
16118:
16119: path - Array containing all categories back up through the hierarchy from the
16120: current category to the top level.
16121:
16122: currcategories - reference to array of current categories assigned to the course
16123:
1.1075.2.117 raeburn 16124: disabled - scalar (optional) contains disabled="disabled" if input elements are
16125: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16126:
1.663 raeburn 16127: Returns: $output (markup to be displayed).
16128:
16129: =cut
16130:
16131: sub assign_category_rows {
1.1075.2.117 raeburn 16132: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16133: my ($text,$name,$item,$chgstr);
16134: if (ref($cats) eq 'ARRAY') {
16135: my $maxdepth = scalar(@{$cats});
16136: if (ref($cats->[$depth]) eq 'HASH') {
16137: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16138: my $numchildren = @{$cats->[$depth]{$parent}};
16139: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 16140: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16141: for (my $j=0; $j<$numchildren; $j++) {
16142: $name = $cats->[$depth]{$parent}[$j];
16143: $item = &escape($name).':'.&escape($parent).':'.$depth;
16144: my $deeper = $depth+1;
16145: my $checked = '';
16146: if (ref($currcategories) eq 'ARRAY') {
16147: if (@{$currcategories} > 0) {
16148: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16149: $checked = ' checked="checked"';
1.663 raeburn 16150: }
16151: }
16152: }
1.664 raeburn 16153: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16154: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16155: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16156: '<input type="hidden" name="catname" value="'.$name.'" />'.
16157: '</td><td>';
1.663 raeburn 16158: if (ref($path) eq 'ARRAY') {
16159: push(@{$path},$name);
1.1075.2.117 raeburn 16160: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16161: pop(@{$path});
16162: }
16163: $text .= '</td></tr>';
16164: }
16165: $text .= '</table></td>';
16166: }
16167: }
16168: }
16169: return $text;
16170: }
16171:
1.1075.2.69 raeburn 16172: =pod
16173:
16174: =back
16175:
16176: =cut
16177:
1.655 raeburn 16178: ############################################################
16179: ############################################################
16180:
16181:
1.443 albertel 16182: sub commit_customrole {
1.664 raeburn 16183: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16184: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16185: ($start?', '.&mt('starting').' '.localtime($start):'').
16186: ($end?', ending '.localtime($end):'').': <b>'.
16187: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16188: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16189: '</b><br />';
16190: return $output;
16191: }
16192:
16193: sub commit_standardrole {
1.1075.2.31 raeburn 16194: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16195: my ($output,$logmsg,$linefeed);
16196: if ($context eq 'auto') {
16197: $linefeed = "\n";
16198: } else {
16199: $linefeed = "<br />\n";
16200: }
1.443 albertel 16201: if ($three eq 'st') {
1.541 raeburn 16202: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 16203: $one,$two,$sec,$context,$credits);
1.541 raeburn 16204: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16205: ($result eq 'unknown_course') || ($result eq 'refused')) {
16206: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16207: } else {
1.541 raeburn 16208: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16209: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16210: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16211: if ($context eq 'auto') {
16212: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16213: } else {
16214: $output .= '<b>'.$result.'</b>'.$linefeed.
16215: &mt('Add to classlist').': <b>ok</b>';
16216: }
16217: $output .= $linefeed;
1.443 albertel 16218: }
16219: } else {
16220: $output = &mt('Assigning').' '.$three.' in '.$url.
16221: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16222: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16223: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16224: if ($context eq 'auto') {
16225: $output .= $result.$linefeed;
16226: } else {
16227: $output .= '<b>'.$result.'</b>'.$linefeed;
16228: }
1.443 albertel 16229: }
16230: return $output;
16231: }
16232:
16233: sub commit_studentrole {
1.1075.2.31 raeburn 16234: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16235: $credits) = @_;
1.626 raeburn 16236: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16237: if ($context eq 'auto') {
16238: $linefeed = "\n";
16239: } else {
16240: $linefeed = '<br />'."\n";
16241: }
1.443 albertel 16242: if (defined($one) && defined($two)) {
16243: my $cid=$one.'_'.$two;
16244: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16245: my $secchange = 0;
16246: my $expire_role_result;
16247: my $modify_section_result;
1.628 raeburn 16248: if ($oldsec ne '-1') {
16249: if ($oldsec ne $sec) {
1.443 albertel 16250: $secchange = 1;
1.628 raeburn 16251: my $now = time;
1.443 albertel 16252: my $uurl='/'.$cid;
16253: $uurl=~s/\_/\//g;
16254: if ($oldsec) {
16255: $uurl.='/'.$oldsec;
16256: }
1.626 raeburn 16257: $oldsecurl = $uurl;
1.628 raeburn 16258: $expire_role_result =
1.1075.2.161. .14(raeb 16259:-23): &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 16260: if ($env{'request.course.sec'} ne '') {
16261: if ($expire_role_result eq 'refused') {
16262: my @roles = ('st');
16263: my @statuses = ('previous');
16264: my @roledoms = ($one);
16265: my $withsec = 1;
16266: my %roleshash =
16267: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16268: \@statuses,\@roles,\@roledoms,$withsec);
16269: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16270: my ($oldstart,$oldend) =
16271: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16272: if ($oldend > 0 && $oldend <= $now) {
16273: $expire_role_result = 'ok';
16274: }
16275: }
16276: }
16277: }
1.443 albertel 16278: $result = $expire_role_result;
16279: }
16280: }
16281: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 16282: $modify_section_result =
16283: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16284: undef,undef,undef,$sec,
16285: $end,$start,'','',$cid,
16286: '',$context,$credits);
1.443 albertel 16287: if ($modify_section_result =~ /^ok/) {
16288: if ($secchange == 1) {
1.628 raeburn 16289: if ($sec eq '') {
16290: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16291: } else {
16292: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16293: }
1.443 albertel 16294: } elsif ($oldsec eq '-1') {
1.628 raeburn 16295: if ($sec eq '') {
16296: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16297: } else {
16298: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16299: }
1.443 albertel 16300: } else {
1.628 raeburn 16301: if ($sec eq '') {
16302: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16303: } else {
16304: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16305: }
1.443 albertel 16306: }
16307: } else {
1.628 raeburn 16308: if ($secchange) {
16309: $$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;
16310: } else {
16311: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16312: }
1.443 albertel 16313: }
16314: $result = $modify_section_result;
16315: } elsif ($secchange == 1) {
1.628 raeburn 16316: if ($oldsec eq '') {
1.1075.2.20 raeburn 16317: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_2] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
1.628 raeburn 16318: } else {
16319: $$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;
16320: }
1.626 raeburn 16321: if ($expire_role_result eq 'refused') {
16322: my $newsecurl = '/'.$cid;
16323: $newsecurl =~ s/\_/\//g;
16324: if ($sec ne '') {
16325: $newsecurl.='/'.$sec;
16326: }
16327: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16328: if ($sec eq '') {
16329: $$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;
16330: } else {
16331: $$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;
16332: }
16333: }
16334: }
1.443 albertel 16335: }
16336: } else {
1.626 raeburn 16337: $$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 16338: $result = "error: incomplete course id\n";
16339: }
16340: return $result;
16341: }
16342:
1.1075.2.25 raeburn 16343: sub show_role_extent {
16344: my ($scope,$context,$role) = @_;
16345: $scope =~ s{^/}{};
16346: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16347: push(@courseroles,'co');
16348: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16349: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16350: $scope =~ s{/}{_};
16351: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16352: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16353: my ($audom,$auname) = split(/\//,$scope);
16354: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16355: &Apache::loncommon::plainname($auname,$audom).'</span>');
16356: } else {
16357: $scope =~ s{/$}{};
16358: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16359: &Apache::lonnet::domain($scope,'description').'</span>');
16360: }
16361: }
16362:
1.443 albertel 16363: ############################################################
16364: ############################################################
16365:
1.566 albertel 16366: sub check_clone {
1.578 raeburn 16367: my ($args,$linefeed) = @_;
1.566 albertel 16368: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16369: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16370: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 16371:21): my $clonetitle;
16372:21): my @clonemsg;
1.566 albertel 16373: my $can_clone = 0;
1.944 raeburn 16374: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16375: if ($lctype ne 'community') {
16376: $lctype = 'course';
16377: }
1.566 albertel 16378: if ($clonehome eq 'no_host') {
1.944 raeburn 16379: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16380:21): push(@clonemsg,({
16381:21): mt => 'No new community created.',
16382:21): args => [],
16383:21): },
16384:21): {
16385:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16386:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16387:21): }));
1.908 raeburn 16388: } else {
1.1075.2.161. .1(raebu 16389:21): push(@clonemsg,({
16390:21): mt => 'No new course created.',
16391:21): args => [],
16392:21): },
16393:21): {
16394:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16395:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16396:21): }));
16397:21): }
1.566 albertel 16398: } else {
16399: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 16400:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 16401: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16402: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 16403:21): push(@clonemsg,({
16404:21): mt => 'No new community created.',
16405:21): args => [],
16406:21): },
16407:21): {
16408:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16409:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16410:21): }));
16411:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16412: }
16413: }
1.1075.2.119 raeburn 16414: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16415: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16416: $can_clone = 1;
16417: } else {
1.1075.2.95 raeburn 16418: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16419: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 16420: if ($clonehash{'cloners'} eq '') {
16421: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16422: if ($domdefs{'canclone'}) {
16423: unless ($domdefs{'canclone'} eq 'none') {
16424: if ($domdefs{'canclone'} eq 'domain') {
16425: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16426: $can_clone = 1;
16427: }
16428: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16429: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16430: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16431: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16432: $can_clone = 1;
16433: }
16434: }
16435: }
1.908 raeburn 16436: }
1.1075.2.95 raeburn 16437: } else {
16438: my @cloners = split(/,/,$clonehash{'cloners'});
16439: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16440: $can_clone = 1;
1.1075.2.95 raeburn 16441: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16442: $can_clone = 1;
1.1075.2.96 raeburn 16443: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16444: $can_clone = 1;
1.1075.2.95 raeburn 16445: }
16446: unless ($can_clone) {
1.1075.2.96 raeburn 16447: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16448: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 16449: my (%gotdomdefaults,%gotcodedefaults);
16450: foreach my $cloner (@cloners) {
16451: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16452: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16453: my (%codedefaults,@code_order);
16454: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16455: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16456: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16457: }
16458: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16459: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16460: }
16461: } else {
16462: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16463: \%codedefaults,
16464: \@code_order);
16465: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16466: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16467: }
16468: if (@code_order > 0) {
16469: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16470: $cloner,$clonehash{'internal.coursecode'},
16471: $args->{'crscode'})) {
16472: $can_clone = 1;
16473: last;
16474: }
16475: }
16476: }
16477: }
16478: }
1.1075.2.96 raeburn 16479: }
16480: }
16481: unless ($can_clone) {
16482: my $ccrole = 'cc';
16483: if ($args->{'crstype'} eq 'Community') {
16484: $ccrole = 'co';
16485: }
16486: my %roleshash =
16487: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16488: $args->{'ccdomain'},
16489: 'userroles',['active'],[$ccrole],
16490: [$args->{'clonedomain'}]);
16491: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16492: $can_clone = 1;
16493: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16494: $args->{'ccuname'},$args->{'ccdomain'})) {
16495: $can_clone = 1;
1.1075.2.95 raeburn 16496: }
16497: }
16498: unless ($can_clone) {
16499: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16500:21): push(@clonemsg,({
16501:21): mt => 'No new community created.',
16502:21): args => [],
16503:21): },
16504:21): {
16505:21): 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]).',
16506:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16507:21): }));
1.1075.2.95 raeburn 16508: } else {
1.1075.2.161. .1(raebu 16509:21): push(@clonemsg,({
16510:21): mt => 'No new course created.',
16511:21): args => [],
16512:21): },
16513:21): {
16514:21): 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]).',
16515:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16516:21): }));
1.578 raeburn 16517: }
1.566 albertel 16518: }
1.578 raeburn 16519: }
1.566 albertel 16520: }
1.1075.2.161. .1(raebu 16521:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16522: }
16523:
1.444 albertel 16524: sub construct_course {
1.1075.2.119 raeburn 16525: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 16526:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16527:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16528: my $linefeed = '<br />'."\n";
16529: if ($context eq 'auto') {
16530: $linefeed = "\n";
16531: }
1.566 albertel 16532:
16533: #
16534: # Are we cloning?
16535: #
1.1075.2.161. .1(raebu 16536:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16537: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 16538:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16539: if (!$can_clone) {
1.1075.2.161. .1(raebu 16540:21): return (0,$outcome,$clonemsgref);
1.566 albertel 16541: }
16542: }
16543:
1.444 albertel 16544: #
16545: # Open course
16546: #
16547: my $crstype = lc($args->{'crstype'});
16548: my %cenv=();
16549: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16550: $args->{'cdescr'},
16551: $args->{'curl'},
16552: $args->{'course_home'},
16553: $args->{'nonstandard'},
16554: $args->{'crscode'},
16555: $args->{'ccuname'}.':'.
16556: $args->{'ccdomain'},
1.882 raeburn 16557: $args->{'crstype'},
1.1075.2.161. .1(raebu 16558:21): $cnum,$context,$category,
16559:21): $callercontext);
1.444 albertel 16560:
16561: # Note: The testing routines depend on this being output; see
16562: # Utils::Course. This needs to at least be output as a comment
16563: # if anyone ever decides to not show this, and Utils::Course::new
16564: # will need to be suitably modified.
1.1075.2.161. .1(raebu 16565:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16566:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16567:21): } else {
16568:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16569:21): }
1.943 raeburn 16570: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 16571:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16572: }
16573:
1.444 albertel 16574: #
16575: # Check if created correctly
16576: #
1.479 albertel 16577: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16578: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16579: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 16580:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16581:21): $outcome .= &mt_user($user_lh,
16582:21): 'Course creation failed, unrecognized course home server.');
16583:21): } else {
16584:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
16585:21): }
16586:21): $outcome .= $linefeed;
16587:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16588: }
1.541 raeburn 16589: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16590:
1.444 albertel 16591: #
1.566 albertel 16592: # Do the cloning
1.1075.2.161. .1(raebu 16593:21): #
16594:21): my @clonemsg;
1.566 albertel 16595: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 16596:21): push(@clonemsg,
16597:21): {
16598:21): mt => 'Created [_1] by cloning from [_2]',
16599:21): args => [$crstype,$clonetitle],
16600:21): });
1.566 albertel 16601: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16602: # Copy all files
1.1075.2.161. .1(raebu 16603:21): my @info =
16604:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16605:21): $args->{'dateshift'},$args->{'crscode'},
16606:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16607:21): $args->{'tinyurls'});
16608:21): if (@info) {
16609:21): push(@clonemsg,@info);
16610:21): }
1.444 albertel 16611: # Restore URL
1.566 albertel 16612: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16613: # Restore title
1.566 albertel 16614: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16615: # Restore creation date, creator and creation context.
16616: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16617: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16618: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16619: # Mark as cloned
1.566 albertel 16620: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16621: # Need to clone grading mode
16622: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16623: $cenv{'grading'}=$newenv{'grading'};
16624: # Do not clone these environment entries
16625: &Apache::lonnet::del('environment',
16626: ['default_enrollment_start_date',
16627: 'default_enrollment_end_date',
16628: 'question.email',
16629: 'policy.email',
16630: 'comment.email',
16631: 'pch.users.denied',
1.725 raeburn 16632: 'plc.users.denied',
16633: 'hidefromcat',
1.1075.2.36 raeburn 16634: 'checkforpriv',
1.1075.2.158 raeburn 16635: 'categories'],
1.638 www 16636: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16637: if ($args->{'textbook'}) {
16638: $cenv{'internal.textbook'} = $args->{'textbook'};
16639: }
1.444 albertel 16640: }
1.566 albertel 16641:
1.444 albertel 16642: #
16643: # Set environment (will override cloned, if existing)
16644: #
16645: my @sections = ();
16646: my @xlists = ();
16647: if ($args->{'crstype'}) {
16648: $cenv{'type'}=$args->{'crstype'};
16649: }
1.1075.2.161. .17(raeb 16650:-23): if ($args->{'lti'}) {
16651:-23): $cenv{'internal.lti'}=$args->{'lti'};
16652:-23): }
1.444 albertel 16653: if ($args->{'crsid'}) {
16654: $cenv{'courseid'}=$args->{'crsid'};
16655: }
16656: if ($args->{'crscode'}) {
16657: $cenv{'internal.coursecode'}=$args->{'crscode'};
16658: }
16659: if ($args->{'crsquota'} ne '') {
16660: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16661: } else {
16662: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16663: }
16664: if ($args->{'ccuname'}) {
16665: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16666: ':'.$args->{'ccdomain'};
16667: } else {
16668: $cenv{'internal.courseowner'} = $args->{'curruser'};
16669: }
1.1075.2.31 raeburn 16670: if ($args->{'defaultcredits'}) {
16671: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16672: }
1.444 albertel 16673: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.161. .20(raeb 16674:-23): my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 16675: if ($args->{'crssections'}) {
16676: $cenv{'internal.sectionnums'} = '';
16677: if ($args->{'crssections'} =~ m/,/) {
16678: @sections = split/,/,$args->{'crssections'};
16679: } else {
16680: $sections[0] = $args->{'crssections'};
16681: }
16682: if (@sections > 0) {
16683: foreach my $item (@sections) {
16684: my ($sec,$gp) = split/:/,$item;
16685: my $class = $args->{'crscode'}.$sec;
16686: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16687: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.161. .20(raeb 16688:-23): if ($addcheck eq 'ok') {
16689:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16690:-23): push(@oklcsecs,$gp);
16691:-23): }
16692:-23): } else {
1.1075.2.119 raeburn 16693: push(@badclasses,$class);
1.444 albertel 16694: }
16695: }
16696: $cenv{'internal.sectionnums'} =~ s/,$//;
16697: }
16698: }
16699: # do not hide course coordinator from staff listing,
16700: # even if privileged
16701: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16702: # add course coordinator's domain to domains to check for privileged users
16703: # if different to course domain
16704: if ($$crsudom ne $args->{'ccdomain'}) {
16705: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16706: }
1.444 albertel 16707: # add crosslistings
16708: if ($args->{'crsxlist'}) {
16709: $cenv{'internal.crosslistings'}='';
16710: if ($args->{'crsxlist'} =~ m/,/) {
16711: @xlists = split/,/,$args->{'crsxlist'};
16712: } else {
16713: $xlists[0] = $args->{'crsxlist'};
16714: }
16715: if (@xlists > 0) {
16716: foreach my $item (@xlists) {
16717: my ($xl,$gp) = split/:/,$item;
16718: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16719: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.161. .20(raeb 16720:-23): if ($addcheck eq 'ok') {
16721:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16722:-23): push(@oklcsecs,$gp);
16723:-23): }
16724:-23): } else {
1.1075.2.119 raeburn 16725: push(@badclasses,$xl);
1.444 albertel 16726: }
16727: }
16728: $cenv{'internal.crosslistings'} =~ s/,$//;
16729: }
16730: }
16731: if ($args->{'autoadds'}) {
16732: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16733: }
16734: if ($args->{'autodrops'}) {
16735: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16736: }
16737: # check for notification of enrollment changes
16738: my @notified = ();
16739: if ($args->{'notify_owner'}) {
16740: if ($args->{'ccuname'} ne '') {
16741: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16742: }
16743: }
16744: if ($args->{'notify_dc'}) {
16745: if ($uname ne '') {
1.630 raeburn 16746: push(@notified,$uname.':'.$udom);
1.444 albertel 16747: }
16748: }
16749: if (@notified > 0) {
16750: my $notifylist;
16751: if (@notified > 1) {
16752: $notifylist = join(',',@notified);
16753: } else {
16754: $notifylist = $notified[0];
16755: }
16756: $cenv{'internal.notifylist'} = $notifylist;
16757: }
16758: if (@badclasses > 0) {
16759: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16760: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16761: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16762: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16763: );
1.1075.2.119 raeburn 16764: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16765: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 16766: if ($context eq 'auto') {
16767: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16768: } else {
1.566 albertel 16769: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16770: }
16771: foreach my $item (@badclasses) {
1.541 raeburn 16772: if ($context eq 'auto') {
1.1075.2.119 raeburn 16773: $outcome .= " - $item\n";
1.541 raeburn 16774: } else {
1.1075.2.119 raeburn 16775: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16776: }
1.1075.2.119 raeburn 16777: }
16778: if ($context eq 'auto') {
16779: $outcome .= $linefeed;
16780: } else {
16781: $outcome .= "</ul><br /><br /></div>\n";
16782: }
1.444 albertel 16783: }
16784: if ($args->{'no_end_date'}) {
16785: $args->{'endaccess'} = 0;
16786: }
1.1075.2.161. .20(raeb 16787:-23): # If an official course with institutional sections is created by cloning
16788:-23): # an existing course, section-specific hiding of course totals in student's
16789:-23): # view of grades as copied from cloned course, will be checked for valid
16790:-23): # sections.
16791:-23): if (($can_clone && $cloneid) &&
16792:-23): ($cenv{'internal.coursecode'} ne '') &&
16793:-23): ($cenv{'grading'} eq 'standard') &&
16794:-23): ($cenv{'hidetotals'} ne '') &&
16795:-23): ($cenv{'hidetotals'} ne 'all')) {
16796:-23): my @hidesecs;
16797:-23): my $deletehidetotals;
16798:-23): if (@oklcsecs) {
16799:-23): foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
16800:-23): if (grep(/^\Q$sec$/,@oklcsecs)) {
16801:-23): push(@hidesecs,$sec);
16802:-23): }
16803:-23): }
16804:-23): if (@hidesecs) {
16805:-23): $cenv{'hidetotals'} = join(',',@hidesecs);
16806:-23): } else {
16807:-23): $deletehidetotals = 1;
16808:-23): }
16809:-23): } else {
16810:-23): $deletehidetotals = 1;
16811:-23): }
16812:-23): if ($deletehidetotals) {
16813:-23): delete($cenv{'hidetotals'});
16814:-23): &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
16815:-23): }
16816:-23): }
1.444 albertel 16817: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16818: $cenv{'internal.autoend'}=$args->{'enrollend'};
16819: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16820: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16821: if ($args->{'showphotos'}) {
16822: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16823: }
16824: $cenv{'internal.authtype'} = $args->{'authtype'};
16825: $cenv{'internal.autharg'} = $args->{'autharg'};
16826: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16827: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16828: 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');
16829: if ($context eq 'auto') {
16830: $outcome .= $krb_msg;
16831: } else {
1.566 albertel 16832: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16833: }
16834: $outcome .= $linefeed;
1.444 albertel 16835: }
16836: }
16837: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16838: if ($args->{'setpolicy'}) {
16839: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16840: }
16841: if ($args->{'setcontent'}) {
16842: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16843: }
1.1075.2.110 raeburn 16844: if ($args->{'setcomment'}) {
16845: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16846: }
1.444 albertel 16847: }
16848: if ($args->{'reshome'}) {
16849: $cenv{'reshome'}=$args->{'reshome'}.'/';
16850: $cenv{'reshome'}=~s/\/+$/\//;
16851: }
16852: #
16853: # course has keyed access
16854: #
16855: if ($args->{'setkeys'}) {
16856: $cenv{'keyaccess'}='yes';
16857: }
16858: # if specified, key authority is not course, but user
16859: # only active if keyaccess is yes
16860: if ($args->{'keyauth'}) {
1.487 albertel 16861: my ($user,$domain) = split(':',$args->{'keyauth'});
16862: $user = &LONCAPA::clean_username($user);
16863: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16864: if ($user ne '' && $domain ne '') {
1.487 albertel 16865: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16866: }
16867: }
16868:
1.1075.2.59 raeburn 16869: #
16870: # generate and store uniquecode (available to course requester), if course should have one.
16871: #
16872: if ($args->{'uniquecode'}) {
16873: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16874: if ($code) {
16875: $cenv{'internal.uniquecode'} = $code;
16876: my %crsinfo =
16877: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16878: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16879: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16880: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16881: }
16882: if (ref($coderef)) {
16883: $$coderef = $code;
16884: }
16885: }
16886: }
16887:
1.444 albertel 16888: if ($args->{'disresdis'}) {
16889: $cenv{'pch.roles.denied'}='st';
16890: }
16891: if ($args->{'disablechat'}) {
16892: $cenv{'plc.roles.denied'}='st';
16893: }
16894:
16895: # Record we've not yet viewed the Course Initialization Helper for this
16896: # course
16897: $cenv{'course.helper.not.run'} = 1;
16898: #
16899: # Use new Randomseed
16900: #
16901: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16902: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16903: #
16904: # The encryption code and receipt prefix for this course
16905: #
16906: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16907: $cenv{'internal.encpref'}=100+int(9*rand(99));
16908: #
16909: # By default, use standard grading
16910: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16911:
1.541 raeburn 16912: $outcome .= $linefeed.&mt('Setting environment').': '.
16913: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16914: #
16915: # Open all assignments
16916: #
16917: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16918: my $opendate = time;
16919: if ($args->{'openallfrom'} =~ /^\d+$/) {
16920: $opendate = $args->{'openallfrom'};
16921: }
1.444 albertel 16922: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16923: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16924: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16925: $outcome .= &mt('All assignments open starting [_1]',
16926: &Apache::lonlocal::locallocaltime($opendate)).': '.
16927: &Apache::lonnet::cput
16928: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16929: }
16930: #
16931: # Set first page
16932: #
16933: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16934: || ($cloneid)) {
16935: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16936:
16937: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16938: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16939:
1.444 albertel 16940: $outcome .= ($fatal?$errtext:'read ok').' - ';
16941: my $title; my $url;
16942: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16943: $title=&mt('Syllabus');
1.444 albertel 16944: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16945: } else {
1.963 raeburn 16946: $title=&mt('Table of Contents');
1.444 albertel 16947: $url='/adm/navmaps';
16948: }
1.445 albertel 16949:
16950: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16951: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16952:
16953: if ($errtext) { $fatal=2; }
1.541 raeburn 16954: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16955: }
1.566 albertel 16956:
1.1075.2.161. .1(raebu 16957:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16958: }
16959:
1.1075.2.59 raeburn 16960: sub make_unique_code {
16961: my ($cdom,$cnum) = @_;
16962: # get lock on uniquecodes db
16963: my $lockhash = {
16964: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16965: ':'.$env{'user.domain'},
16966: };
16967: my $tries = 0;
16968: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16969: my ($code,$error);
16970:
16971: while (($gotlock ne 'ok') && ($tries<3)) {
16972: $tries ++;
16973: sleep 1;
16974: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16975: }
16976: if ($gotlock eq 'ok') {
16977: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16978: my $gotcode;
16979: my $attempts = 0;
16980: while ((!$gotcode) && ($attempts < 100)) {
16981: $code = &generate_code();
16982: if (!exists($currcodes{$code})) {
16983: $gotcode = 1;
16984: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16985: $error = 'nostore';
16986: }
16987: }
16988: $attempts ++;
16989: }
16990: my @del_lock = ($cnum."\0".'uniquecodes');
16991: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16992: } else {
16993: $error = 'nolock';
16994: }
16995: return ($code,$error);
16996: }
16997:
16998: sub generate_code {
16999: my $code;
17000: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17001: for (my $i=0; $i<6; $i++) {
17002: my $lettnum = int (rand 2);
17003: my $item = '';
17004: if ($lettnum) {
17005: $item = $letts[int( rand(18) )];
17006: } else {
17007: $item = 1+int( rand(8) );
17008: }
17009: $code .= $item;
17010: }
17011: return $code;
17012: }
17013:
1.444 albertel 17014: ############################################################
17015: ############################################################
17016:
1.953 droeschl 17017: #SD
17018: # only Community and Course, or anything else?
1.378 raeburn 17019: sub course_type {
17020: my ($cid) = @_;
17021: if (!defined($cid)) {
17022: $cid = $env{'request.course.id'};
17023: }
1.404 albertel 17024: if (defined($env{'course.'.$cid.'.type'})) {
17025: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17026: } else {
17027: return 'Course';
1.377 raeburn 17028: }
17029: }
1.156 albertel 17030:
1.406 raeburn 17031: sub group_term {
17032: my $crstype = &course_type();
17033: my %names = (
17034: 'Course' => 'group',
1.865 raeburn 17035: 'Community' => 'group',
1.406 raeburn 17036: );
17037: return $names{$crstype};
17038: }
17039:
1.902 raeburn 17040: sub course_types {
1.1075.2.161. .17(raeb 17041:-23): my @types = ('official','unofficial','community','textbook','lti');
1.902 raeburn 17042: my %typename = (
17043: official => 'Official course',
17044: unofficial => 'Unofficial course',
17045: community => 'Community',
1.1075.2.59 raeburn 17046: textbook => 'Textbook course',
1.1075.2.161. .17(raeb 17047:-23): lti => 'LTI provider',
1.902 raeburn 17048: );
17049: return (\@types,\%typename);
17050: }
17051:
1.156 albertel 17052: sub icon {
17053: my ($file)=@_;
1.505 albertel 17054: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17055: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17056: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17057: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17058: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17059: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17060: $curfext.".gif") {
17061: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17062: $curfext.".gif";
17063: }
17064: }
1.249 albertel 17065: return &lonhttpdurl($iconname);
1.154 albertel 17066: }
1.84 albertel 17067:
1.575 albertel 17068: sub lonhttpdurl {
1.692 www 17069: #
17070: # Had been used for "small fry" static images on separate port 8080.
17071: # Modify here if lightweight http functionality desired again.
17072: # Currently eliminated due to increasing firewall issues.
17073: #
1.575 albertel 17074: my ($url)=@_;
1.692 www 17075: return $url;
1.215 albertel 17076: }
17077:
1.213 albertel 17078: sub connection_aborted {
17079: my ($r)=@_;
17080: $r->print(" ");$r->rflush();
17081: my $c = $r->connection;
17082: return $c->aborted();
17083: }
17084:
1.221 foxr 17085: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17086: # strings as 'strings'.
17087: sub escape_single {
1.221 foxr 17088: my ($input) = @_;
1.223 albertel 17089: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17090: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17091: return $input;
17092: }
1.223 albertel 17093:
1.222 foxr 17094: # Same as escape_single, but escape's "'s This
17095: # can be used for "strings"
17096: sub escape_double {
17097: my ($input) = @_;
17098: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17099: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17100: return $input;
17101: }
1.223 albertel 17102:
1.222 foxr 17103: # Escapes the last element of a full URL.
17104: sub escape_url {
17105: my ($url) = @_;
1.238 raeburn 17106: my @urlslices = split(/\//, $url,-1);
1.369 www 17107: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 17108: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17109: }
1.462 albertel 17110:
1.820 raeburn 17111: sub compare_arrays {
17112: my ($arrayref1,$arrayref2) = @_;
17113: my (@difference,%count);
17114: @difference = ();
17115: %count = ();
17116: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17117: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17118: foreach my $element (keys(%count)) {
17119: if ($count{$element} == 1) {
17120: push(@difference,$element);
17121: }
17122: }
17123: }
17124: return @difference;
17125: }
17126:
1.1075.2.152 raeburn 17127: sub lon_status_items {
17128: my %defaults = (
17129: E => 100,
17130: W => 4,
17131: N => 1,
17132: U => 5,
17133: threshold => 200,
17134: sysmail => 2500,
17135: );
17136: my %names = (
17137: E => 'Errors',
17138: W => 'Warnings',
17139: N => 'Notices',
17140: U => 'Unsent',
17141: );
17142: return (\%defaults,\%names);
17143: }
17144:
1.817 bisitz 17145: # -------------------------------------------------------- Initialize user login
1.462 albertel 17146: sub init_user_environment {
1.463 albertel 17147: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17148: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17149:
17150: my $public=($username eq 'public' && $domain eq 'public');
17151:
17152: # See if old ID present, if so, remove
17153:
1.1075.2.161. .22(raeb 17154:-24): my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17155:-24): $coauthorenv);
1.462 albertel 17156: my $now=time;
17157:
17158: if ($public) {
17159: my $max_public=100;
17160: my $oldest;
17161: my $oldest_time=0;
17162: for(my $next=1;$next<=$max_public;$next++) {
17163: if (-e $lonids."/publicuser_$next.id") {
17164: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17165: if ($mtime<$oldest_time || !$oldest_time) {
17166: $oldest_time=$mtime;
17167: $oldest=$next;
17168: }
17169: } else {
17170: $cookie="publicuser_$next";
17171: last;
17172: }
17173: }
17174: if (!$cookie) { $cookie="publicuser_$oldest"; }
17175: } else {
1.463 albertel 17176: # if this isn't a robot, kill any existing non-robot sessions
17177: if (!$args->{'robot'}) {
17178: opendir(DIR,$lonids);
17179: while ($filename=readdir(DIR)) {
17180: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 17181: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17182: &GDBM_READER(),0640)) {
17183: my $linkedfile;
17184: if (exists($oldenv{'user.linkedenv'})) {
17185: $linkedfile = $oldenv{'user.linkedenv'};
17186: }
17187: untie(%oldenv);
17188: if (unlink("$lonids/$filename")) {
17189: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17190: if (-l "$lonids/$linkedfile.id") {
17191: unlink("$lonids/$linkedfile.id");
17192: }
17193: }
17194: }
17195: } else {
17196: unlink($lonids.'/'.$filename);
17197: }
1.463 albertel 17198: }
1.462 albertel 17199: }
1.463 albertel 17200: closedir(DIR);
1.1075.2.84 raeburn 17201: # If there is a undeleted lockfile for the user's paste buffer remove it.
17202: my $namespace = 'nohist_courseeditor';
17203: my $lockingkey = 'paste'."\0".'locked_num';
17204: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17205: $domain,$username);
17206: if (exists($lockhash{$lockingkey})) {
17207: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17208: unless ($delresult eq 'ok') {
17209: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17210: }
17211: }
1.462 albertel 17212: }
17213: # Give them a new cookie
1.463 albertel 17214: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17215: : $now.$$.int(rand(10000)));
1.463 albertel 17216: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17217:
17218: # Initialize roles
17219:
1.1075.2.161. .22(raeb 17220:-24): ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17221: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17222: }
17223: # ------------------------------------ Check browser type and MathML capability
17224:
1.1075.2.77 raeburn 17225: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17226: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17227:
17228: # ------------------------------------------------------------- Get environment
17229:
17230: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17231: my ($tmp) = keys(%userenv);
17232: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
17233: } else {
17234: undef(%userenv);
17235: }
17236: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17237: $form->{'interface'}=$userenv{'interface'};
17238: }
17239: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17240:
17241: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17242: foreach my $option ('interface','localpath','localres') {
17243: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17244: }
17245: # --------------------------------------------------------- Write first profile
17246:
17247: {
1.1075.2.150 raeburn 17248: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 17249: my %initial_env =
17250: ("user.name" => $username,
17251: "user.domain" => $domain,
17252: "user.home" => $authhost,
17253: "browser.type" => $clientbrowser,
17254: "browser.version" => $clientversion,
17255: "browser.mathml" => $clientmathml,
17256: "browser.unicode" => $clientunicode,
17257: "browser.os" => $clientos,
1.1075.2.42 raeburn 17258: "browser.mobile" => $clientmobile,
17259: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 17260: "browser.osversion" => $clientosversion,
1.462 albertel 17261: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17262: "request.course.fn" => '',
17263: "request.course.uri" => '',
17264: "request.course.sec" => '',
17265: "request.role" => 'cm',
17266: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 17267: "request.host" => $ip,);
1.462 albertel 17268:
17269: if ($form->{'localpath'}) {
17270: $initial_env{"browser.localpath"} = $form->{'localpath'};
17271: $initial_env{"browser.localres"} = $form->{'localres'};
17272: }
17273:
17274: if ($form->{'interface'}) {
17275: $form->{'interface'}=~s/\W//gs;
17276: $initial_env{"browser.interface"} = $form->{'interface'};
17277: $env{'browser.interface'}=$form->{'interface'};
17278: }
17279:
1.1075.2.54 raeburn 17280: if ($form->{'iptoken'}) {
17281: my $lonhost = $r->dir_config('lonHostID');
17282: $initial_env{"user.noloadbalance"} = $lonhost;
17283: $env{'user.noloadbalance'} = $lonhost;
17284: }
17285:
1.1075.2.120 raeburn 17286: if ($form->{'noloadbalance'}) {
17287: my @hosts = &Apache::lonnet::current_machine_ids();
17288: my $hosthere = $form->{'noloadbalance'};
17289: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17290: $initial_env{"user.noloadbalance"} = $hosthere;
17291: $env{'user.noloadbalance'} = $hosthere;
17292: }
17293: }
17294:
1.1016 raeburn 17295: unless ($domain eq 'public') {
1.1075.2.125 raeburn 17296: my %is_adv = ( is_adv => $env{'user.adv'} );
17297: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 17298:
1.1075.2.161. .10(raeb 17299:-22): foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {
1.1075.2.125 raeburn 17300: $userenv{'availabletools.'.$tool} =
17301: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17302: undef,\%userenv,\%domdef,\%is_adv);
17303: }
1.724 raeburn 17304:
1.1075.2.161. .17(raeb 17305:-23): foreach my $crstype ('official','unofficial','community','textbook','lti') {
1.1075.2.125 raeburn 17306: $userenv{'canrequest.'.$crstype} =
17307: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17308: 'reload','requestcourses',
17309: \%userenv,\%domdef,\%is_adv);
17310: }
1.765 raeburn 17311:
1.1075.2.161. .21(raeb 17312:-24): if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
17313:-24): (exists($userroles->{"user.role.au./$domain/"}))) {
17314:-24): if ($userenv{'authoreditors'}) {
17315:-24): $userenv{'editors'} = $userenv{'authoreditors'};
17316:-24): } elsif ($domdef{'editors'} ne '') {
17317:-24): $userenv{'editors'} = $domdef{'editors'};
17318:-24): } else {
17319:-24): $userenv{'editors'} = 'edit,xml';
17320:-24): }
.25(raeb 17321:-24): if ($userenv{'authorarchive'}) {
17322:-24): $userenv{'canarchive'} = 1;
17323:-24): } elsif (($userenv{'authorarchive'} eq '') &&
17324:-24): ($domdef{'archive'})) {
17325:-24): $userenv{'canarchive'} = 1;
17326:-24): }
.21(raeb 17327:-24): }
17328:-24):
1.1075.2.125 raeburn 17329: $userenv{'canrequest.author'} =
17330: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17331: 'reload','requestauthor',
17332: \%userenv,\%domdef,\%is_adv);
17333: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17334: $domain,$username);
17335: my $reqstatus = $reqauthor{'author_status'};
17336: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17337: if (ref($reqauthor{'author'}) eq 'HASH') {
17338: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17339: $reqauthor{'author'}{'timestamp'};
17340: }
1.1075.2.14 raeburn 17341: }
17342: }
17343:
1.462 albertel 17344: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17345:
1.462 albertel 17346: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17347: &GDBM_WRCREAT(),0640)) {
17348: &_add_to_env(\%disk_env,\%initial_env);
17349: &_add_to_env(\%disk_env,\%userenv,'environment.');
17350: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17351: if (ref($firstaccenv) eq 'HASH') {
17352: &_add_to_env(\%disk_env,$firstaccenv);
17353: }
17354: if (ref($timerintenv) eq 'HASH') {
17355: &_add_to_env(\%disk_env,$timerintenv);
17356: }
1.1075.2.161. .22(raeb 17357:-24): if (ref($coauthorenv) eq 'HASH') {
17358:-24): if (keys(%{$coauthorenv})) {
17359:-24): &_add_to_env(\%disk_env,$coauthorenv);
17360:-24): }
17361:-24): }
1.463 albertel 17362: if (ref($args->{'extra_env'})) {
17363: &_add_to_env(\%disk_env,$args->{'extra_env'});
17364: }
1.462 albertel 17365: untie(%disk_env);
17366: } else {
1.705 tempelho 17367: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17368: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17369: return 'error: '.$!;
17370: }
17371: }
17372: $env{'request.role'}='cm';
17373: $env{'request.role.adv'}=$env{'user.adv'};
17374: $env{'browser.type'}=$clientbrowser;
17375:
17376: return $cookie;
17377:
17378: }
17379:
17380: sub _add_to_env {
17381: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17382: if (ref($env_data) eq 'HASH') {
17383: while (my ($key,$value) = each(%$env_data)) {
17384: $idf->{$prefix.$key} = $value;
17385: $env{$prefix.$key} = $value;
17386: }
1.462 albertel 17387: }
17388: }
17389:
1.685 tempelho 17390: # --- Get the symbolic name of a problem and the url
17391: sub get_symb {
17392: my ($request,$silent) = @_;
1.726 raeburn 17393: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17394: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17395: if ($symb eq '') {
17396: if (!$silent) {
1.1071 raeburn 17397: if (ref($request)) {
17398: $request->print("Unable to handle ambiguous references:$url:.");
17399: }
1.685 tempelho 17400: return ();
17401: }
17402: }
17403: &Apache::lonenc::check_decrypt(\$symb);
17404: return ($symb);
17405: }
17406:
17407: # --------------------------------------------------------------Get annotation
17408:
17409: sub get_annotation {
17410: my ($symb,$enc) = @_;
17411:
17412: my $key = $symb;
17413: if (!$enc) {
17414: $key =
17415: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17416: }
17417: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17418: return $annotation{$key};
17419: }
17420:
17421: sub clean_symb {
1.731 raeburn 17422: my ($symb,$delete_enc) = @_;
1.685 tempelho 17423:
17424: &Apache::lonenc::check_decrypt(\$symb);
17425: my $enc = $env{'request.enc'};
1.731 raeburn 17426: if ($delete_enc) {
1.730 raeburn 17427: delete($env{'request.enc'});
17428: }
1.685 tempelho 17429:
17430: return ($symb,$enc);
17431: }
1.462 albertel 17432:
1.1075.2.69 raeburn 17433: ############################################################
17434: ############################################################
17435:
17436: =pod
17437:
17438: =head1 Routines for building display used to search for courses
17439:
17440:
17441: =over 4
17442:
17443: =item * &build_filters()
17444:
17445: Create markup for a table used to set filters to use when selecting
17446: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17447: and quotacheck.pl
17448:
17449:
17450: Inputs:
17451:
17452: filterlist - anonymous array of fields to include as potential filters
17453:
17454: crstype - course type
17455:
17456: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17457: to pop-open a course selector (will contain "extra element").
17458:
17459: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17460:
17461: filter - anonymous hash of criteria and their values
17462:
17463: action - form action
17464:
17465: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17466:
17467: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
17468:
17469: cloneruname - username of owner of new course who wants to clone
17470:
17471: clonerudom - domain of owner of new course who wants to clone
17472:
17473: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17474:
17475: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17476:
17477: codedom - domain
17478:
17479: formname - value of form element named "form".
17480:
17481: fixeddom - domain, if fixed.
17482:
17483: prevphase - value to assign to form element named "phase" when going back to the previous screen
17484:
17485: cnameelement - name of form element in form on opener page which will receive title of selected course
17486:
17487: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17488:
17489: cdomelement - name of form element in form on opener page which will receive domain of selected course
17490:
17491: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17492:
17493: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17494:
17495: clonewarning - warning message about missing information for intended course owner when DC creates a course
17496:
17497:
17498: Returns: $output - HTML for display of search criteria, and hidden form elements.
17499:
17500:
17501: Side Effects: None
17502:
17503: =cut
17504:
17505: # ---------------------------------------------- search for courses based on last activity etc.
17506:
17507: sub build_filters {
17508: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17509: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17510: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17511: $cnameelement,$cnumelement,$cdomelement,$setroles,
17512: $clonetext,$clonewarning) = @_;
17513: my ($list,$jscript);
17514: my $onchange = 'javascript:updateFilters(this)';
17515: my ($domainselectform,$sincefilterform,$createdfilterform,
17516: $ownerdomselectform,$persondomselectform,$instcodeform,
17517: $typeselectform,$instcodetitle);
17518: if ($formname eq '') {
17519: $formname = $caller;
17520: }
17521: foreach my $item (@{$filterlist}) {
17522: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17523: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17524: if ($item eq 'domainfilter') {
17525: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17526: } elsif ($item eq 'coursefilter') {
17527: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17528: } elsif ($item eq 'ownerfilter') {
17529: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17530: } elsif ($item eq 'ownerdomfilter') {
17531: $filter->{'ownerdomfilter'} =
17532: &LONCAPA::clean_domain($filter->{$item});
17533: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17534: 'ownerdomfilter',1);
17535: } elsif ($item eq 'personfilter') {
17536: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17537: } elsif ($item eq 'persondomfilter') {
17538: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17539: 'persondomfilter',1);
17540: } else {
17541: $filter->{$item} =~ s/\W//g;
17542: }
17543: if (!$filter->{$item}) {
17544: $filter->{$item} = '';
17545: }
17546: }
17547: if ($item eq 'domainfilter') {
17548: my $allow_blank = 1;
17549: if ($formname eq 'portform') {
17550: $allow_blank=0;
17551: } elsif ($formname eq 'studentform') {
17552: $allow_blank=0;
17553: }
17554: if ($fixeddom) {
17555: $domainselectform = '<input type="hidden" name="domainfilter"'.
17556: ' value="'.$codedom.'" />'.
17557: &Apache::lonnet::domain($codedom,'description');
17558: } else {
17559: $domainselectform = &select_dom_form($filter->{$item},
17560: 'domainfilter',
17561: $allow_blank,'',$onchange);
17562: }
17563: } else {
17564: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17565: }
17566: }
17567:
17568: # last course activity filter and selection
17569: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17570:
17571: # course created filter and selection
17572: if (exists($filter->{'createdfilter'})) {
17573: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17574: }
17575:
17576: my %lt = &Apache::lonlocal::texthash(
17577: 'cac' => "$crstype Activity",
17578: 'ccr' => "$crstype Created",
17579: 'cde' => "$crstype Title",
17580: 'cdo' => "$crstype Domain",
17581: 'ins' => 'Institutional Code',
17582: 'inc' => 'Institutional Categorization',
17583: 'cow' => "$crstype Owner/Co-owner",
17584: 'cop' => "$crstype Personnel Includes",
17585: 'cog' => 'Type',
17586: );
17587:
17588: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17589: my $typeval = 'Course';
17590: if ($crstype eq 'Community') {
17591: $typeval = 'Community';
17592: }
17593: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17594: } else {
17595: $typeselectform = '<select name="type" size="1"';
17596: if ($onchange) {
17597: $typeselectform .= ' onchange="'.$onchange.'"';
17598: }
17599: $typeselectform .= '>'."\n";
17600: foreach my $posstype ('Course','Community') {
17601: $typeselectform.='<option value="'.$posstype.'"'.
17602: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
17603: }
17604: $typeselectform.="</select>";
17605: }
17606:
17607: my ($cloneableonlyform,$cloneabletitle);
17608: if (exists($filter->{'cloneableonly'})) {
17609: my $cloneableon = '';
17610: my $cloneableoff = ' checked="checked"';
17611: if ($filter->{'cloneableonly'}) {
17612: $cloneableon = $cloneableoff;
17613: $cloneableoff = '';
17614: }
17615: $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
17616: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 17617: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 17618: } else {
17619: $cloneabletitle = &mt('Cloneable by you');
17620: }
17621: }
17622: my $officialjs;
17623: if ($crstype eq 'Course') {
17624: if (exists($filter->{'instcodefilter'})) {
17625: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17626: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17627: if ($codedom) {
17628: $officialjs = 1;
17629: ($instcodeform,$jscript,$$numtitlesref) =
17630: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17631: $officialjs,$codetitlesref);
17632: if ($jscript) {
17633: $jscript = '<script type="text/javascript">'."\n".
17634: '// <![CDATA['."\n".
17635: $jscript."\n".
17636: '// ]]>'."\n".
17637: '</script>'."\n";
17638: }
17639: }
17640: if ($instcodeform eq '') {
17641: $instcodeform =
17642: '<input type="text" name="instcodefilter" size="10" value="'.
17643: $list->{'instcodefilter'}.'" />';
17644: $instcodetitle = $lt{'ins'};
17645: } else {
17646: $instcodetitle = $lt{'inc'};
17647: }
17648: if ($fixeddom) {
17649: $instcodetitle .= '<br />('.$codedom.')';
17650: }
17651: }
17652: }
17653: my $output = qq|
17654: <form method="post" name="filterpicker" action="$action">
17655: <input type="hidden" name="form" value="$formname" />
17656: |;
17657: if ($formname eq 'modifycourse') {
17658: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17659: '<input type="hidden" name="prevphase" value="'.
17660: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 17661: } elsif ($formname eq 'quotacheck') {
17662: $output .= qq|
17663: <input type="hidden" name="sortby" value="" />
17664: <input type="hidden" name="sortorder" value="" />
17665: |;
17666: } else {
1.1075.2.69 raeburn 17667: my $name_input;
17668: if ($cnameelement ne '') {
17669: $name_input = '<input type="hidden" name="cnameelement" value="'.
17670: $cnameelement.'" />';
17671: }
17672: $output .= qq|
17673: <input type="hidden" name="cnumelement" value="$cnumelement" />
17674: <input type="hidden" name="cdomelement" value="$cdomelement" />
17675: $name_input
17676: $roleelement
17677: $multelement
17678: $typeelement
17679: |;
17680: if ($formname eq 'portform') {
17681: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17682: }
17683: }
17684: if ($fixeddom) {
17685: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17686: }
17687: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17688: if ($sincefilterform) {
17689: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17690: .$sincefilterform
17691: .&Apache::lonhtmlcommon::row_closure();
17692: }
17693: if ($createdfilterform) {
17694: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17695: .$createdfilterform
17696: .&Apache::lonhtmlcommon::row_closure();
17697: }
17698: if ($domainselectform) {
17699: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17700: .$domainselectform
17701: .&Apache::lonhtmlcommon::row_closure();
17702: }
17703: if ($typeselectform) {
17704: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17705: $output .= $typeselectform;
17706: } else {
17707: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17708: .$typeselectform
17709: .&Apache::lonhtmlcommon::row_closure();
17710: }
17711: }
17712: if ($instcodeform) {
17713: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17714: .$instcodeform
17715: .&Apache::lonhtmlcommon::row_closure();
17716: }
17717: if (exists($filter->{'ownerfilter'})) {
17718: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17719: '<table><tr><td>'.&mt('Username').'<br />'.
17720: '<input type="text" name="ownerfilter" size="20" value="'.
17721: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17722: $ownerdomselectform.'</td></tr></table>'.
17723: &Apache::lonhtmlcommon::row_closure();
17724: }
17725: if (exists($filter->{'personfilter'})) {
17726: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17727: '<table><tr><td>'.&mt('Username').'<br />'.
17728: '<input type="text" name="personfilter" size="20" value="'.
17729: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17730: $persondomselectform.'</td></tr></table>'.
17731: &Apache::lonhtmlcommon::row_closure();
17732: }
17733: if (exists($filter->{'coursefilter'})) {
17734: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17735: .'<input type="text" name="coursefilter" size="25" value="'
17736: .$list->{'coursefilter'}.'" />'
17737: .&Apache::lonhtmlcommon::row_closure();
17738: }
17739: if ($cloneableonlyform) {
17740: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17741: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17742: }
17743: if (exists($filter->{'descriptfilter'})) {
17744: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17745: .'<input type="text" name="descriptfilter" size="40" value="'
17746: .$list->{'descriptfilter'}.'" />'
17747: .&Apache::lonhtmlcommon::row_closure(1);
17748: }
17749: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17750: '<input type="hidden" name="updater" value="" />'."\n".
17751: '<input type="submit" name="gosearch" value="'.
17752: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17753: return $jscript.$clonewarning.$output;
17754: }
17755:
17756: =pod
17757:
17758: =item * &timebased_select_form()
17759:
17760: Create markup for a dropdown list used to select a time-based
17761: filter e.g., Course Activity, Course Created, when searching for courses
17762: or communities
17763:
17764: Inputs:
17765:
17766: item - name of form element (sincefilter or createdfilter)
17767:
17768: filter - anonymous hash of criteria and their values
17769:
17770: Returns: HTML for a select box contained a blank, then six time selections,
17771: with value set in incoming form variables currently selected.
17772:
17773: Side Effects: None
17774:
17775: =cut
17776:
17777: sub timebased_select_form {
17778: my ($item,$filter) = @_;
17779: if (ref($filter) eq 'HASH') {
17780: $filter->{$item} =~ s/[^\d-]//g;
17781: if (!$filter->{$item}) { $filter->{$item}=-1; }
17782: return &select_form(
17783: $filter->{$item},
17784: $item,
17785: { '-1' => '',
17786: '86400' => &mt('today'),
17787: '604800' => &mt('last week'),
17788: '2592000' => &mt('last month'),
17789: '7776000' => &mt('last three months'),
17790: '15552000' => &mt('last six months'),
17791: '31104000' => &mt('last year'),
17792: 'select_form_order' =>
17793: ['-1','86400','604800','2592000','7776000',
17794: '15552000','31104000']});
17795: }
17796: }
17797:
17798: =pod
17799:
17800: =item * &js_changer()
17801:
17802: Create script tag containing Javascript used to submit course search form
17803: when course type or domain is changed, and also to hide 'Searching ...' on
17804: page load completion for page showing search result.
17805:
17806: Inputs: None
17807:
17808: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17809:
17810: Side Effects: None
17811:
17812: =cut
17813:
17814: sub js_changer {
17815: return <<ENDJS;
17816: <script type="text/javascript">
17817: // <![CDATA[
17818: function updateFilters(caller) {
17819: if (typeof(caller) != "undefined") {
17820: document.filterpicker.updater.value = caller.name;
17821: }
17822: document.filterpicker.submit();
17823: }
17824:
17825: function hideSearching() {
17826: if (document.getElementById('searching')) {
17827: document.getElementById('searching').style.display = 'none';
17828: }
17829: return;
17830: }
17831:
17832: // ]]>
17833: </script>
17834:
17835: ENDJS
17836: }
17837:
17838: =pod
17839:
17840: =item * &search_courses()
17841:
17842: Process selected filters form course search form and pass to lonnet::courseiddump
17843: to retrieve a hash for which keys are courseIDs which match the selected filters.
17844:
17845: Inputs:
17846:
17847: dom - domain being searched
17848:
17849: type - course type ('Course' or 'Community' or '.' if any).
17850:
17851: filter - anonymous hash of criteria and their values
17852:
17853: numtitles - for institutional codes - number of categories
17854:
17855: cloneruname - optional username of new course owner
17856:
17857: clonerudom - optional domain of new course owner
17858:
1.1075.2.95 raeburn 17859: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17860: (used when DC is using course creation form)
17861:
17862: codetitles - reference to array of titles of components in institutional codes (official courses).
17863:
1.1075.2.95 raeburn 17864: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17865: (and so can clone automatically)
17866:
17867: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17868:
17869: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17870: courses to clone
1.1075.2.69 raeburn 17871:
17872: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17873:
17874:
17875: Side Effects: None
17876:
17877: =cut
17878:
17879:
17880: sub search_courses {
1.1075.2.95 raeburn 17881: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17882: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17883: my (%courses,%showcourses,$cloner);
17884: if (($filter->{'ownerfilter'} ne '') ||
17885: ($filter->{'ownerdomfilter'} ne '')) {
17886: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17887: $filter->{'ownerdomfilter'};
17888: }
17889: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17890: if (!$filter->{$item}) {
17891: $filter->{$item}='.';
17892: }
17893: }
17894: my $now = time;
17895: my $timefilter =
17896: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17897: my ($createdbefore,$createdafter);
17898: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17899: $createdbefore = $now;
17900: $createdafter = $now-$filter->{'createdfilter'};
17901: }
17902: my ($instcodefilter,$regexpok);
17903: if ($numtitles) {
17904: if ($env{'form.official'} eq 'on') {
17905: $instcodefilter =
17906: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17907: $regexpok = 1;
17908: } elsif ($env{'form.official'} eq 'off') {
17909: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17910: unless ($instcodefilter eq '') {
17911: $regexpok = -1;
17912: }
17913: }
17914: } else {
17915: $instcodefilter = $filter->{'instcodefilter'};
17916: }
17917: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17918: if ($type eq '') { $type = '.'; }
17919:
17920: if (($clonerudom ne '') && ($cloneruname ne '')) {
17921: $cloner = $cloneruname.':'.$clonerudom;
17922: }
17923: %courses = &Apache::lonnet::courseiddump($dom,
17924: $filter->{'descriptfilter'},
17925: $timefilter,
17926: $instcodefilter,
17927: $filter->{'combownerfilter'},
17928: $filter->{'coursefilter'},
17929: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17930: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17931: $filter->{'cloneableonly'},
17932: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17933: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17934: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17935: my $ccrole;
17936: if ($type eq 'Community') {
17937: $ccrole = 'co';
17938: } else {
17939: $ccrole = 'cc';
17940: }
17941: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17942: $filter->{'persondomfilter'},
17943: 'userroles',undef,
17944: [$ccrole,'in','ad','ep','ta','cr'],
17945: $dom);
17946: foreach my $role (keys(%rolehash)) {
17947: my ($cnum,$cdom,$courserole) = split(':',$role);
17948: my $cid = $cdom.'_'.$cnum;
17949: if (exists($courses{$cid})) {
17950: if (ref($courses{$cid}) eq 'HASH') {
17951: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17952: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17953: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17954: }
17955: } else {
17956: $courses{$cid}{roles} = [$courserole];
17957: }
17958: $showcourses{$cid} = $courses{$cid};
17959: }
17960: }
17961: }
17962: %courses = %showcourses;
17963: }
17964: return %courses;
17965: }
17966:
17967: =pod
17968:
17969: =back
17970:
1.1075.2.88 raeburn 17971: =head1 Routines for version requirements for current course.
17972:
17973: =over 4
17974:
17975: =item * &check_release_required()
17976:
17977: Compares required LON-CAPA version with version on server, and
17978: if required version is newer looks for a server with the required version.
17979:
17980: Looks first at servers in user's owen domain; if none suitable, looks at
17981: servers in course's domain are permitted to host sessions for user's domain.
17982:
17983: Inputs:
17984:
17985: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17986:
17987: $courseid - Course ID of current course
17988:
17989: $rolecode - User's current role in course (for switchserver query string).
17990:
17991: $required - LON-CAPA version needed by course (format: Major.Minor).
17992:
17993:
17994: Returns:
17995:
17996: $switchserver - query string tp append to /adm/switchserver call (if
17997: current server's LON-CAPA version is too old.
17998:
17999: $warning - Message is displayed if no suitable server could be found.
18000:
18001: =cut
18002:
18003: sub check_release_required {
18004: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18005: my ($switchserver,$warning);
18006: if ($required ne '') {
18007: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18008: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18009: if ($reqdmajor ne '' && $reqdminor ne '') {
18010: my $otherserver;
18011: if (($major eq '' && $minor eq '') ||
18012: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18013: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18014: my $switchlcrev =
18015: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18016: $userdomserver);
18017: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18018: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18019: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18020: my $cdom = $env{'course.'.$courseid.'.domain'};
18021: if ($cdom ne $env{'user.domain'}) {
18022: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18023: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18024: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18025: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18026: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18027: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18028: my $canhost =
18029: &Apache::lonnet::can_host_session($env{'user.domain'},
18030: $coursedomserver,
18031: $remoterev,
18032: $udomdefaults{'remotesessions'},
18033: $defdomdefaults{'hostedsessions'});
18034:
18035: if ($canhost) {
18036: $otherserver = $coursedomserver;
18037: } else {
18038: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
18039: }
18040: } else {
18041: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
18042: }
18043: } else {
18044: $otherserver = $userdomserver;
18045: }
18046: }
18047: if ($otherserver ne '') {
18048: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18049: }
18050: }
18051: }
18052: return ($switchserver,$warning);
18053: }
18054:
18055: =pod
18056:
18057: =item * &check_release_result()
18058:
18059: Inputs:
18060:
18061: $switchwarning - Warning message if no suitable server found to host session.
18062:
18063: $switchserver - query string to append to /adm/switchserver containing lonHostID
18064: and current role.
18065:
18066: Returns: HTML to display with information about requirement to switch server.
18067: Either displaying warning with link to Roles/Courses screen or
18068: display link to switchserver.
18069:
1.1075.2.69 raeburn 18070: =cut
18071:
1.1075.2.88 raeburn 18072: sub check_release_result {
18073: my ($switchwarning,$switchserver) = @_;
18074: my $output = &start_page('Selected course unavailable on this server').
18075: '<p class="LC_warning">';
18076: if ($switchwarning) {
18077: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18078: if (&show_course()) {
18079: $output .= &mt('Display courses');
18080: } else {
18081: $output .= &mt('Display roles');
18082: }
18083: $output .= '</a>';
18084: } elsif ($switchserver) {
18085: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18086: '<br />'.
18087: '<a href="/adm/switchserver?'.$switchserver.'">'.
18088: &mt('Switch Server').
18089: '</a>';
18090: }
18091: $output .= '</p>'.&end_page();
18092: return $output;
18093: }
18094:
18095: =pod
18096:
18097: =item * &needs_coursereinit()
18098:
18099: Determine if course contents stored for user's session needs to be
18100: refreshed, because content has changed since "Big Hash" last tied.
18101:
18102: Check for change is made if time last checked is more than 10 minutes ago
18103: (by default).
18104:
18105: Inputs:
18106:
18107: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18108:
18109: $interval (optional) - Time which may elapse (in s) between last check for content
18110: change in current course. (default: 600 s).
18111:
18112: Returns: an array; first element is:
18113:
18114: =over 4
18115:
18116: 'switch' - if content updates mean user's session
18117: needs to be switched to a server running a newer LON-CAPA version
18118:
18119: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18120: on current server hosting user's session
18121:
18122: '' - if no action required.
18123:
18124: =back
18125:
18126: If first item element is 'switch':
18127:
18128: second item is $switchwarning - Warning message if no suitable server found to host session.
18129:
18130: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18131: and current role.
18132:
18133: otherwise: no other elements returned.
18134:
18135: =back
18136:
18137: =cut
18138:
18139: sub needs_coursereinit {
18140: my ($loncaparev,$interval) = @_;
18141: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18142: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18143: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18144: my $now = time;
18145: if ($interval eq '') {
18146: $interval = 600;
18147: }
18148: if (($now-$env{'request.course.timechecked'})>$interval) {
18149: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 18150:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 18151:21): if ($blocked) {
18152:21): return ();
18153:21): }
.13(raeb 18154:-23): my $update;
18155:-23): my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18156:-23): my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18157:-23): if ($lastmainchange > $env{'request.course.tied'}) {
18158:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18159:-23): if ($needswitch) {
18160:-23): return ('switch',$switchwarning,$switchserver);
18161:-23): }
18162:-23): $update = 'main';
18163:-23): }
18164:-23): if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18165:-23): if ($update) {
18166:-23): $update = 'both';
18167:-23): } else {
18168:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18169:-23): if ($needswitch) {
18170:-23): return ('switch',$switchwarning,$switchserver);
18171:-23): } else {
18172:-23): $update = 'supp';
1.1075.2.88 raeburn 18173: }
18174: }
1.1075.2.161. .13(raeb 18175:-23): return ($update);
18176:-23): }
18177:-23): }
18178:-23): return ();
18179:-23): }
18180:-23):
18181:-23): sub switch_for_update {
18182:-23): my ($loncaparev,$cdom,$cnum) = @_;
18183:-23): my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18184:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18185:-23): my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18186:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18187:-23): &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18188:-23): $curr_reqd_hash{'internal.releaserequired'}});
18189:-23): my ($switchserver,$switchwarning) =
18190:-23): &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18191:-23): $curr_reqd_hash{'internal.releaserequired'});
18192:-23): if ($switchwarning ne '' || $switchserver ne '') {
18193:-23): return ('switch',$switchwarning,$switchserver);
18194:-23): }
1.1075.2.88 raeburn 18195: }
18196: }
18197: return ();
18198: }
1.1075.2.69 raeburn 18199:
1.1075.2.11 raeburn 18200: sub update_content_constraints {
18201: my ($cdom,$cnum,$chome,$cid) = @_;
18202: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18203: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
18204: my %checkresponsetypes;
18205: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
18206: my ($item,$name,$value) = split(/:/,$key);
18207: if ($item eq 'resourcetag') {
18208: if ($name eq 'responsetype') {
18209: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18210: }
18211: }
18212: }
18213: my $navmap = Apache::lonnavmaps::navmap->new();
18214: if (defined($navmap)) {
18215: my %allresponses;
18216: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
18217: my %responses = $res->responseTypes();
18218: foreach my $key (keys(%responses)) {
18219: next unless(exists($checkresponsetypes{$key}));
18220: $allresponses{$key} += $responses{$key};
18221: }
18222: }
18223: foreach my $key (keys(%allresponses)) {
18224: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18225: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18226: ($reqdmajor,$reqdminor) = ($major,$minor);
18227: }
18228: }
18229: undef($navmap);
18230: }
18231: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18232: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18233: }
18234: return;
18235: }
18236:
1.1075.2.27 raeburn 18237: sub allmaps_incourse {
18238: my ($cdom,$cnum,$chome,$cid) = @_;
18239: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18240: $cid = $env{'request.course.id'};
18241: $cdom = $env{'course.'.$cid.'.domain'};
18242: $cnum = $env{'course.'.$cid.'.num'};
18243: $chome = $env{'course.'.$cid.'.home'};
18244: }
18245: my %allmaps = ();
18246: my $lastchange =
18247: &Apache::lonnet::get_coursechange($cdom,$cnum);
18248: if ($lastchange > $env{'request.course.tied'}) {
18249: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18250: unless ($ferr) {
18251: &update_content_constraints($cdom,$cnum,$chome,$cid);
18252: }
18253: }
18254: my $navmap = Apache::lonnavmaps::navmap->new();
18255: if (defined($navmap)) {
18256: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18257: $allmaps{$res->src()} = 1;
18258: }
18259: }
18260: return \%allmaps;
18261: }
18262:
1.1075.2.11 raeburn 18263: sub parse_supplemental_title {
18264: my ($title) = @_;
18265:
18266: my ($foldertitle,$renametitle);
18267: if ($title =~ /&&&/) {
18268: $title = &HTML::Entites::decode($title);
18269: }
18270: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18271: $renametitle=$4;
18272: my ($time,$uname,$udom) = ($1,$2,$3);
18273: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18274: my $name = &plainname($uname,$udom);
18275: $name = &HTML::Entities::encode($name,'"<>&\'');
18276: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1075.2.161. .16(raeb 18277:-23): $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
18278:-23): if ($foldertitle ne '') {
18279:-23): $title .= ': <br />'.$foldertitle;
18280:-23): }
1.1075.2.11 raeburn 18281: }
18282: if (wantarray) {
18283: return ($title,$foldertitle,$renametitle);
18284: }
18285: return $title;
18286: }
18287:
1.1075.2.161. .13(raeb 18288:-23): sub get_supplemental {
18289:-23): my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18290:-23): my $hashid=$cnum.':'.$cdom;
18291:-23): my ($supplemental,$cached,$set_httprefs);
18292:-23): unless ($ignorecache) {
18293:-23): ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18294:-23): }
18295:-23): unless (defined($cached)) {
18296:-23): my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18297:-23): unless ($chome eq 'no_host') {
18298:-23): my @order = @LONCAPA::map::order;
18299:-23): my @resources = @LONCAPA::map::resources;
18300:-23): my @resparms = @LONCAPA::map::resparms;
18301:-23): my @zombies = @LONCAPA::map::zombies;
18302:-23): my ($errors,%ids,%hidden);
18303:-23): $errors =
18304:-23): &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18305:-23): $errors,$possdel,\%ids,\%hidden);
18306:-23): @LONCAPA::map::order = @order;
18307:-23): @LONCAPA::map::resources = @resources;
18308:-23): @LONCAPA::map::resparms = @resparms;
18309:-23): @LONCAPA::map::zombies = @zombies;
18310:-23): $set_httprefs = 1;
18311:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18312:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18313:-23): }
18314:-23): $supplemental = {
18315:-23): ids => \%ids,
18316:-23): hidden => \%hidden,
18317:-23): };
18318:-23): &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18319:-23): }
18320:-23): }
18321:-23): return ($supplemental,$set_httprefs);
18322:-23): }
18323:-23):
1.1075.2.43 raeburn 18324: sub recurse_supplemental {
1.1075.2.161. .13(raeb 18325:-23): my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18326:-23): if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18327:-23): my $mapnum;
18328:-23): if ($suppmap eq 'supplemental.sequence') {
18329:-23): $mapnum = 0;
18330:-23): } else {
18331:-23): ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18332:-23): }
1.1075.2.43 raeburn 18333: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18334: if ($fatal) {
18335: $errors ++;
18336: } else {
1.1075.2.161. .13(raeb 18337:-23): my @order = @LONCAPA::map::order;
18338:-23): if (@order > 0) {
18339:-23): my @resources = @LONCAPA::map::resources;
18340:-23): my @resparms = @LONCAPA::map::resparms;
18341:-23): foreach my $idx (@order) {
18342:-23): my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 18343: if (($src ne '') && ($status eq 'res')) {
1.1075.2.161. .13(raeb 18344:-23): my $id = $mapnum.':'.$idx;
18345:-23): push(@{$suppids->{$src}},$id);
18346:-23): if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18347:-23): $hiddensupp->{$id} = 1;
18348:-23): }
1.1075.2.46 raeburn 18349: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1075.2.161. .13(raeb 18350:-23): $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18351:-23): $hiddensupp,$hiddensupp->{$id});
1.1075.2.43 raeburn 18352: } else {
1.1075.2.161. .13(raeb 18353:-23): my $allowed;
18354:-23): if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18355:-23): $allowed = 1;
18356:-23): } elsif ($possdel) {
18357:-23): foreach my $item (@{$suppids->{$src}}) {
18358:-23): next if ($item eq $id);
18359:-23): unless ($hiddensupp->{$item}) {
18360:-23): $allowed = 1;
18361:-23): last;
18362:-23): }
18363:-23): }
18364:-23): if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18365:-23): &Apache::lonnet::delenv('httpref.'.$src);
18366:-23): }
18367:-23): }
18368:-23): if ($allowed && (!exists($env{'httpref.'.$src}))) {
18369:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18370:-23): }
18371:-23): }
18372:-23): }
18373:-23): }
18374:-23): }
18375:-23): }
18376:-23): }
18377:-23): return $errors;
18378:-23): }
18379:-23):
18380:-23): sub set_supp_httprefs {
18381:-23): my ($cnum,$cdom,$supplemental,$possdel) = @_;
18382:-23): if (ref($supplemental) eq 'HASH') {
18383:-23): if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18384:-23): foreach my $src (keys(%{$supplemental->{'ids'}})) {
18385:-23): next if ($src =~ /\.sequence$/);
18386:-23): if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18387:-23): my $allowed;
18388:-23): if ($env{'request.role.adv'}) {
18389:-23): $allowed = 1;
18390:-23): } else {
18391:-23): foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18392:-23): unless ($supplemental->{'hidden'}->{$id}) {
18393:-23): $allowed = 1;
18394:-23): last;
18395:-23): }
18396:-23): }
18397:-23): }
18398:-23): if (exists($env{'httpref.'.$src})) {
18399:-23): if ($possdel) {
18400:-23): unless ($allowed) {
18401:-23): &Apache::lonnet::delenv('httpref.'.$src);
18402:-23): }
1.1075.2.43 raeburn 18403: }
1.1075.2.161. .13(raeb 18404:-23): } elsif ($allowed) {
18405:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1075.2.43 raeburn 18406: }
18407: }
18408: }
1.1075.2.161. .13(raeb 18409:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18410:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18411:-23): }
1.1075.2.43 raeburn 18412: }
18413: }
1.1075.2.161. .13(raeb 18414:-23): }
18415:-23):
18416:-23): sub get_supp_parameter {
18417:-23): my ($resparm,$name)=@_;
18418:-23): return if ($resparm eq '');
18419:-23): my $value=undef;
18420:-23): my $ptype=undef;
18421:-23): foreach (split('&&&',$resparm)) {
18422:-23): my ($thistype,$thisname,$thisvalue)=split('___',$_);
18423:-23): if ($thisname eq $name) {
18424:-23): $value=$thisvalue;
18425:-23): $ptype=$thistype;
18426:-23): }
18427:-23): }
18428:-23): return $value;
1.1075.2.43 raeburn 18429: }
18430:
1.1075.2.18 raeburn 18431: sub symb_to_docspath {
1.1075.2.119 raeburn 18432: my ($symb,$navmapref) = @_;
18433: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 18434: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18435: if ($resurl=~/\.(sequence|page)$/) {
18436: $mapurl=$resurl;
18437: } elsif ($resurl eq 'adm/navmaps') {
18438: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18439: }
18440: my $mapresobj;
1.1075.2.119 raeburn 18441: unless (ref($$navmapref)) {
18442: $$navmapref = Apache::lonnavmaps::navmap->new();
18443: }
18444: if (ref($$navmapref)) {
18445: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 18446: }
18447: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18448: my $type=$2;
18449: my $path;
18450: if (ref($mapresobj)) {
18451: my $pcslist = $mapresobj->map_hierarchy();
18452: if ($pcslist ne '') {
18453: foreach my $pc (split(/,/,$pcslist)) {
18454: next if ($pc <= 1);
1.1075.2.119 raeburn 18455: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 18456: if (ref($res)) {
18457: my $thisurl = $res->src();
18458: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18459: my $thistitle = $res->title();
18460: $path .= '&'.
18461: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 18462: &escape($thistitle).
1.1075.2.18 raeburn 18463: ':'.$res->randompick().
18464: ':'.$res->randomout().
18465: ':'.$res->encrypted().
18466: ':'.$res->randomorder().
18467: ':'.$res->is_page();
18468: }
18469: }
18470: }
18471: $path =~ s/^\&//;
18472: my $maptitle = $mapresobj->title();
18473: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18474: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18475: }
18476: $path .= (($path ne '')? '&' : '').
18477: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18478: &escape($maptitle).
1.1075.2.18 raeburn 18479: ':'.$mapresobj->randompick().
18480: ':'.$mapresobj->randomout().
18481: ':'.$mapresobj->encrypted().
18482: ':'.$mapresobj->randomorder().
18483: ':'.$mapresobj->is_page();
18484: } else {
18485: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18486: my $ispage = (($type eq 'page')? 1 : '');
18487: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18488: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18489: }
18490: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18491: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 18492: }
18493: unless ($mapurl eq 'default') {
18494: $path = 'default&'.
1.1075.2.46 raeburn 18495: &escape('Main Content').
1.1075.2.18 raeburn 18496: ':::::&'.$path;
18497: }
18498: return $path;
18499: }
18500:
1.1075.2.161. .13(raeb 18501:-23): sub validate_folderpath {
18502:-23): my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18503:-23): if ($env{'form.folderpath'} ne '') {
18504:-23): my @items = split(/\&/,$env{'form.folderpath'});
18505:-23): my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
18506:-23): for (my $i=0; $i<@items; $i++) {
18507:-23): my $odd = $i%2;
18508:-23): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18509:-23): $badpath = 1;
18510:-23): } elsif ($odd && $supplementalflag) {
18511:-23): my $idx = $i-1;
18512:-23): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18513:-23): my $esc_name = $1;
18514:-23): if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18515:-23): $supppath .= '&'.$esc_name;
18516:-23): $changed = 1;
18517:-23): } else {
18518:-23): $supppath .= '&'.$items[$i];
18519:-23): }
18520:-23): } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18521:-23): $changed = 1;
18522:-23): my $is_hidden;
18523:-23): unless ($got_supp) {
18524:-23): my ($supplemental) = &get_supplemental($coursenum,$coursedom);
18525:-23): if (ref($supplemental) eq 'HASH') {
18526:-23): if (ref($supplemental->{'hidden'}) eq 'HASH') {
18527:-23): %supphidden = %{$supplemental->{'hidden'}};
18528:-23): }
18529:-23): if (ref($supplemental->{'ids'}) eq 'HASH') {
18530:-23): %suppids = %{$supplemental->{'ids'}};
18531:-23): }
18532:-23): }
18533:-23): $got_supp = 1;
18534:-23): }
18535:-23): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18536:-23): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18537:-23): if ($supphidden{$mapid}) {
18538:-23): $is_hidden = 1;
18539:-23): }
18540:-23): }
18541:-23): $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18542:-23): } else {
18543:-23): $supppath .= '&'.$items[$i];
18544:-23): }
18545:-23): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18546:-23): $badpath = 1;
18547:-23): } elsif ($supplementalflag) {
18548:-23): $supppath .= '&'.$items[$i];
18549:-23): }
18550:-23): last if ($badpath);
18551:-23): }
18552:-23): if ($badpath) {
18553:-23): delete($env{'form.folderpath'});
18554:-23): } elsif ($changed && $supplementalflag) {
18555:-23): $supppath =~ s/^\&//;
18556:-23): $env{'form.folderpath'} = $supppath;
18557:-23): }
18558:-23): }
18559:-23): return;
18560:-23): }
18561:-23):
1.1075.2.14 raeburn 18562: sub captcha_display {
1.1075.2.137 raeburn 18563: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18564: my ($output,$error);
1.1075.2.107 raeburn 18565: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 18566: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18567: if ($captcha eq 'original') {
18568: $output = &create_captcha();
18569: unless ($output) {
18570: $error = 'captcha';
18571: }
18572: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18573: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 18574: unless ($output) {
18575: $error = 'recaptcha';
18576: }
18577: }
1.1075.2.107 raeburn 18578: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 18579: }
18580:
18581: sub captcha_response {
1.1075.2.137 raeburn 18582: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18583: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 18584: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18585: if ($captcha eq 'original') {
18586: ($captcha_chk,$captcha_error) = &check_captcha();
18587: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18588: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 18589: } else {
18590: $captcha_chk = 1;
18591: }
18592: return ($captcha_chk,$captcha_error);
18593: }
18594:
18595: sub get_captcha_config {
1.1075.2.137 raeburn 18596: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 18597: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 18598: my $hostname = &Apache::lonnet::hostname($lonhost);
18599: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18600: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18601: if ($context eq 'usercreation') {
18602: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18603: if (ref($domconfig{$context}) eq 'HASH') {
18604: $hashtocheck = $domconfig{$context}{'cancreate'};
18605: if (ref($hashtocheck) eq 'HASH') {
18606: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18607: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18608: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18609: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18610: }
18611: if ($privkey && $pubkey) {
18612: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18613: $version = $hashtocheck->{'recaptchaversion'};
18614: if ($version ne '2') {
18615: $version = 1;
18616: }
1.1075.2.14 raeburn 18617: } else {
18618: $captcha = 'original';
18619: }
18620: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18621: $captcha = 'original';
18622: }
18623: }
18624: } else {
18625: $captcha = 'captcha';
18626: }
18627: } elsif ($context eq 'login') {
18628: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18629: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18630: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18631: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
18632: if ($privkey && $pubkey) {
18633: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18634: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18635: if ($version ne '2') {
18636: $version = 1;
18637: }
1.1075.2.14 raeburn 18638: } else {
18639: $captcha = 'original';
18640: }
18641: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18642: $captcha = 'original';
18643: }
1.1075.2.137 raeburn 18644: } elsif ($context eq 'passwords') {
18645: if ($dom_in_effect) {
18646: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18647: if ($passwdconf{'captcha'} eq 'recaptcha') {
18648: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18649: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18650: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18651: }
18652: if ($privkey && $pubkey) {
18653: $captcha = 'recaptcha';
18654: $version = $passwdconf{'recaptchaversion'};
18655: if ($version ne '2') {
18656: $version = 1;
18657: }
18658: } else {
18659: $captcha = 'original';
18660: }
18661: } elsif ($passwdconf{'captcha'} ne 'notused') {
18662: $captcha = 'original';
18663: }
18664: }
1.1075.2.14 raeburn 18665: }
1.1075.2.107 raeburn 18666: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 18667: }
18668:
18669: sub create_captcha {
18670: my %captcha_params = &captcha_settings();
18671: my ($output,$maxtries,$tries) = ('',10,0);
18672: while ($tries < $maxtries) {
18673: $tries ++;
18674: my $captcha = Authen::Captcha->new (
18675: output_folder => $captcha_params{'output_dir'},
18676: data_folder => $captcha_params{'db_dir'},
18677: );
18678: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18679:
18680: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18681: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 18682: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 18683: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.161. .15(raeb 18684:-23): '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 18685: '</span><br />'.
1.1075.2.66 raeburn 18686: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 18687: last;
18688: }
18689: }
1.1075.2.158 raeburn 18690: if ($output eq '') {
18691: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18692: }
1.1075.2.14 raeburn 18693: return $output;
18694: }
18695:
18696: sub captcha_settings {
18697: my %captcha_params = (
18698: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18699: www_output_dir => "/captchaspool",
18700: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18701: numchars => '5',
18702: );
18703: return %captcha_params;
18704: }
18705:
18706: sub check_captcha {
18707: my ($captcha_chk,$captcha_error);
18708: my $code = $env{'form.code'};
18709: my $md5sum = $env{'form.crypt'};
18710: my %captcha_params = &captcha_settings();
18711: my $captcha = Authen::Captcha->new(
18712: output_folder => $captcha_params{'output_dir'},
18713: data_folder => $captcha_params{'db_dir'},
18714: );
1.1075.2.26 raeburn 18715: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 18716: my %captcha_hash = (
18717: 0 => 'Code not checked (file error)',
18718: -1 => 'Failed: code expired',
18719: -2 => 'Failed: invalid code (not in database)',
18720: -3 => 'Failed: invalid code (code does not match crypt)',
18721: );
18722: if ($captcha_chk != 1) {
18723: $captcha_error = $captcha_hash{$captcha_chk}
18724: }
18725: return ($captcha_chk,$captcha_error);
18726: }
18727:
18728: sub create_recaptcha {
1.1075.2.107 raeburn 18729: my ($pubkey,$version) = @_;
18730: if ($version >= 2) {
1.1075.2.158 raeburn 18731: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18732: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 18733: } else {
18734: my $use_ssl;
18735: if ($ENV{'SERVER_PORT'} == 443) {
18736: $use_ssl = 1;
18737: }
18738: my $captcha = Captcha::reCAPTCHA->new;
18739: return $captcha->get_options_setter({theme => 'white'})."\n".
18740: $captcha->get_html($pubkey,undef,$use_ssl).
18741: &mt('If the text is hard to read, [_1] will replace them.',
18742: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18743: '<br /><br />';
18744: }
1.1075.2.14 raeburn 18745: }
18746:
18747: sub check_recaptcha {
1.1075.2.107 raeburn 18748: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 18749: my $captcha_chk;
1.1075.2.150 raeburn 18750: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 18751: if ($version >= 2) {
18752: my $ua = LWP::UserAgent->new;
18753: $ua->timeout(10);
18754: my %info = (
18755: secret => $privkey,
18756: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 18757: remoteip => $ip,
1.1075.2.107 raeburn 18758: );
18759: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
18760: if ($response->is_success) {
18761: my $data = JSON::DWIW->from_json($response->decoded_content);
18762: if (ref($data) eq 'HASH') {
18763: if ($data->{'success'}) {
18764: $captcha_chk = 1;
18765: }
18766: }
18767: }
18768: } else {
18769: my $captcha = Captcha::reCAPTCHA->new;
18770: my $captcha_result =
18771: $captcha->check_answer(
18772: $privkey,
1.1075.2.150 raeburn 18773: $ip,
1.1075.2.107 raeburn 18774: $env{'form.recaptcha_challenge_field'},
18775: $env{'form.recaptcha_response_field'},
18776: );
18777: if ($captcha_result->{is_valid}) {
18778: $captcha_chk = 1;
18779: }
1.1075.2.14 raeburn 18780: }
18781: return $captcha_chk;
18782: }
18783:
1.1075.2.64 raeburn 18784: sub emailusername_info {
1.1075.2.103 raeburn 18785: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 18786: my %titles = &Apache::lonlocal::texthash (
18787: lastname => 'Last Name',
18788: firstname => 'First Name',
18789: institution => 'School/college/university',
18790: location => "School's city, state/province, country",
18791: web => "School's web address",
18792: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 18793: id => 'Student/Employee ID',
1.1075.2.64 raeburn 18794: );
18795: return (\@fields,\%titles);
18796: }
18797:
1.1075.2.56 raeburn 18798: sub cleanup_html {
18799: my ($incoming) = @_;
18800: my $outgoing;
18801: if ($incoming ne '') {
18802: $outgoing = $incoming;
18803: $outgoing =~ s/;/;/g;
18804: $outgoing =~ s/\#/#/g;
18805: $outgoing =~ s/\&/&/g;
18806: $outgoing =~ s/</</g;
18807: $outgoing =~ s/>/>/g;
18808: $outgoing =~ s/\(/(/g;
18809: $outgoing =~ s/\)/)/g;
18810: $outgoing =~ s/"/"/g;
18811: $outgoing =~ s/'/'/g;
18812: $outgoing =~ s/\$/$/g;
18813: $outgoing =~ s{/}{/}g;
18814: $outgoing =~ s/=/=/g;
18815: $outgoing =~ s/\\/\/g
18816: }
18817: return $outgoing;
18818: }
18819:
1.1075.2.74 raeburn 18820: # Checks for critical messages and returns a redirect url if one exists.
18821: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 18822:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 18823: sub critical_redirect {
1.1075.2.161. .1(raebu 18824:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 18825: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18826: return ();
18827: }
1.1075.2.74 raeburn 18828: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 18829:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18830:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18831:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 18832:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 18833:21): if ($blocked) {
18834:21): my $checkrole = "cm./$cdom/$cnum";
18835:21): if ($env{'request.course.sec'} ne '') {
18836:21): $checkrole .= "/$env{'request.course.sec'}";
18837:21): }
18838:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18839:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18840:21): return;
18841:21): }
18842:21): }
18843:21): }
1.1075.2.74 raeburn 18844: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18845: $env{'user.name'});
18846: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
18847: my $redirecturl;
18848: if ($what[0]) {
1.1075.2.158 raeburn 18849: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 18850: $redirecturl='/adm/email?critical=display';
18851: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18852: return (1, $url);
18853: }
18854: }
18855: }
18856: return ();
18857: }
18858:
1.1075.2.64 raeburn 18859: # Use:
18860: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18861: #
18862: ##################################################
18863: # password associated functions #
18864: ##################################################
18865: sub des_keys {
18866: # Make a new key for DES encryption.
18867: # Each key has two parts which are returned separately.
18868: # Please note: Each key must be passed through the &hex function
18869: # before it is output to the web browser. The hex versions cannot
18870: # be used to decrypt.
18871: my @hexstr=('0','1','2','3','4','5','6','7',
18872: '8','9','a','b','c','d','e','f');
18873: my $lkey='';
18874: for (0..7) {
18875: $lkey.=$hexstr[rand(15)];
18876: }
18877: my $ukey='';
18878: for (0..7) {
18879: $ukey.=$hexstr[rand(15)];
18880: }
18881: return ($lkey,$ukey);
18882: }
18883:
18884: sub des_decrypt {
18885: my ($key,$cyphertext) = @_;
18886: my $keybin=pack("H16",$key);
18887: my $cypher;
18888: if ($Crypt::DES::VERSION>=2.03) {
18889: $cypher=new Crypt::DES $keybin;
18890: } else {
18891: $cypher=new DES $keybin;
18892: }
1.1075.2.106 raeburn 18893: my $plaintext='';
18894: my $cypherlength = length($cyphertext);
18895: my $numchunks = int($cypherlength/32);
18896: for (my $j=0; $j<$numchunks; $j++) {
18897: my $start = $j*32;
18898: my $cypherblock = substr($cyphertext,$start,32);
18899: my $chunk =
18900: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18901: $chunk .=
18902: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18903: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18904: $plaintext .= $chunk;
18905: }
1.1075.2.64 raeburn 18906: return $plaintext;
18907: }
18908:
1.1075.2.161. .1(raebu 18909:21): sub get_requested_shorturls {
18910:21): my ($cdom,$cnum,$navmap) = @_;
18911:21): return unless (ref($navmap));
18912:21): my ($numnew,$errors);
18913:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18914:21): if (@toshorten) {
18915:21): my (%maps,%resources,%titles);
18916:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18917:21): 'shorturls',$cdom,$cnum);
18918:21): if (keys(%resources)) {
18919:21): my %tocreate;
18920:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18921:21): my $symb = $resources{$item};
18922:21): if ($symb) {
18923:21): $tocreate{$cnum.'&'.$symb} = 1;
18924:21): }
18925:21): }
18926:21): if (keys(%tocreate)) {
18927:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18928:21): \%tocreate);
18929:21): }
18930:21): }
18931:21): }
18932:21): return ($numnew,$errors);
18933:21): }
18934:21):
18935:21): sub make_short_symbs {
18936:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18937:21): my ($numnew,@errors);
18938:21): if (ref($tocreateref) eq 'HASH') {
18939:21): my %tocreate = %{$tocreateref};
18940:21): if (keys(%tocreate)) {
18941:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18942:21): my $su = Short::URL->new(no_vowels => 1);
18943:21): my $init = '';
18944:21): my (%newunique,%addcourse,%courseonly,%failed);
18945:21): # get lock on tiny db
18946:21): my $now = time;
18947:21): if ($lockuser eq '') {
18948:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18949:21): }
18950:21): my $lockhash = {
18951:21): "lock\0$now" => $lockuser,
18952:21): };
18953:21): my $tries = 0;
18954:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18955:21): my ($code,$error);
18956:21): while (($gotlock ne 'ok') && ($tries<3)) {
18957:21): $tries ++;
18958:21): sleep 1;
18959:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18960:21): }
18961:21): if ($gotlock eq 'ok') {
18962:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18963:21): \%addcourse,\%courseonly,\%failed);
18964:21): if (keys(%failed)) {
18965:21): my $numfailed = scalar(keys(%failed));
18966:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18967:21): }
18968:21): if (keys(%newunique)) {
18969:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18970:21): if ($putres eq 'ok') {
18971:21): $numnew = scalar(keys(%newunique));
18972:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18973:21): unless ($newputres eq 'ok') {
18974:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
18975:21): }
18976:21): } else {
18977:21): push(@errors,&mt('error: could not store unique six character URLs'));
18978:21): }
18979:21): }
18980:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18981:21): unless ($dellockres eq 'ok') {
18982:21): push(@errors,&mt('error: could not release lockfile'));
18983:21): }
18984:21): } else {
18985:21): push(@errors,&mt('error: could not obtain lockfile'));
18986:21): }
18987:21): if (keys(%courseonly)) {
18988:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18989:21): if ($result ne 'ok') {
18990:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
18991:21): }
18992:21): }
18993:21): }
18994:21): }
18995:21): return ($numnew,\@errors);
18996:21): }
18997:21):
18998:21): sub shorten_symbs {
18999:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19000:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19001:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19002:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19003:21): my (%possibles,%collisions);
19004:21): foreach my $key (keys(%{$tocreate})) {
19005:21): my $num = String::CRC32::crc32($key);
19006:21): my $tiny = $su->encode($num,$init);
19007:21): if ($tiny) {
19008:21): $possibles{$tiny} = $key;
19009:21): }
19010:21): }
19011:21): if (!$init) {
19012:21): $init = 1;
19013:21): } else {
19014:21): $init ++;
19015:21): }
19016:21): if (keys(%possibles)) {
19017:21): my @posstiny = keys(%possibles);
19018:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19019:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19020:21): if (keys(%currtiny)) {
19021:21): foreach my $key (keys(%currtiny)) {
19022:21): next if ($currtiny{$key} eq '');
19023:21): if ($currtiny{$key} eq $possibles{$key}) {
19024:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19025:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19026:21): $courseonly->{$tsymb} = $key;
19027:21): }
19028:21): } else {
19029:21): $collisions{$possibles{$key}} = 1;
19030:21): }
19031:21): delete($possibles{$key});
19032:21): }
19033:21): }
19034:21): foreach my $key (keys(%possibles)) {
19035:21): $newunique->{$key} = $possibles{$key};
19036:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19037:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19038:21): $addcourse->{$tsymb} = $key;
19039:21): }
19040:21): }
19041:21): }
19042:21): if (keys(%collisions)) {
19043:21): if ($init <5) {
19044:21): if (!$init) {
19045:21): $init = 1;
19046:21): } else {
19047:21): $init ++;
19048:21): }
19049:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19050:21): $newunique,$addcourse,$courseonly,$failed);
19051:21): } else {
19052:21): foreach my $key (keys(%collisions)) {
19053:21): $failed->{$key} = 1;
19054:21): $failed->{$key} = 1;
19055:21): }
19056:21): }
19057:21): }
19058:21): return $init;
19059:21): }
19060:21):
1.1075.2.135 raeburn 19061: sub is_nonframeable {
19062: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19063: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
19064: return if (($remprotocol eq '') || ($remhost eq ''));
19065:
19066: $remprotocol = lc($remprotocol);
19067: $remhost = lc($remhost);
19068: my $remport = 80;
19069: if ($remprotocol eq 'https') {
19070: $remport = 443;
19071: }
19072: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
19073: if ($cached) {
19074: unless ($nocache) {
19075: if ($result) {
19076: return 1;
19077: } else {
19078: return 0;
19079: }
19080: }
19081: }
19082: my $uselink;
19083: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 19084: my $ua = LWP::UserAgent->new;
19085: $ua->timeout(5);
19086: my $response=$ua->request($request);
1.1075.2.135 raeburn 19087: if ($response->is_success()) {
19088: my $secpolicy = lc($response->header('content-security-policy'));
19089: my $xframeop = lc($response->header('x-frame-options'));
19090: $secpolicy =~ s/^\s+|\s+$//g;
19091: $xframeop =~ s/^\s+|\s+$//g;
19092: if (($secpolicy ne '') || ($xframeop ne '')) {
19093: my $remotehost = $remprotocol.'://'.$remhost;
19094: my ($origin,$protocol,$port);
19095: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19096: $port = $ENV{'SERVER_PORT'};
19097: } else {
19098: $port = 80;
19099: }
19100: if ($absolute eq '') {
19101: $protocol = 'http:';
19102: if ($port == 443) {
19103: $protocol = 'https:';
19104: }
19105: $origin = $protocol.'//'.lc($hostname);
19106: } else {
19107: $origin = lc($absolute);
19108: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19109: }
19110: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19111: my $framepolicy = $1;
19112: $framepolicy =~ s/^\s+|\s+$//g;
19113: my @policies = split(/\s+/,$framepolicy);
19114: if (@policies) {
19115: if (grep(/^\Q'none'\E$/,@policies)) {
19116: $uselink = 1;
19117: } else {
19118: $uselink = 1;
19119: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19120: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19121: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19122: undef($uselink);
19123: }
19124: if ($uselink) {
19125: if (grep(/^\Q'self'\E$/,@policies)) {
19126: if (($origin ne '') && ($remotehost eq $origin)) {
19127: undef($uselink);
19128: }
19129: }
19130: }
19131: if ($uselink) {
19132: my @possok;
19133: if ($ip ne '') {
19134: push(@possok,$ip);
19135: }
19136: my $hoststr = '';
19137: foreach my $part (reverse(split(/\./,$hostname))) {
19138: if ($hoststr eq '') {
19139: $hoststr = $part;
19140: } else {
19141: $hoststr = "$part.$hoststr";
19142: }
19143: if ($hoststr eq $hostname) {
19144: push(@possok,$hostname);
19145: } else {
19146: push(@possok,"*.$hoststr");
19147: }
19148: }
19149: if (@possok) {
19150: foreach my $poss (@possok) {
19151: last if (!$uselink);
19152: foreach my $policy (@policies) {
19153: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19154: undef($uselink);
19155: last;
19156: }
19157: }
19158: }
19159: }
19160: }
19161: }
19162: }
19163: } elsif ($xframeop ne '') {
19164: $uselink = 1;
19165: my @policies = split(/\s*,\s*/,$xframeop);
19166: if (@policies) {
19167: unless (grep(/^deny$/,@policies)) {
19168: if ($origin ne '') {
19169: if (grep(/^sameorigin$/,@policies)) {
19170: if ($remotehost eq $origin) {
19171: undef($uselink);
19172: }
19173: }
19174: if ($uselink) {
19175: foreach my $policy (@policies) {
19176: if ($policy =~ /^allow-from\s*(.+)$/) {
19177: my $allowfrom = $1;
19178: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19179: undef($uselink);
19180: last;
19181: }
19182: }
19183: }
19184: }
19185: }
19186: }
19187: }
19188: }
19189: }
19190: }
19191: if ($nocache) {
19192: if ($cached) {
19193: my $devalidate;
19194: if ($uselink && !$result) {
19195: $devalidate = 1;
19196: } elsif (!$uselink && $result) {
19197: $devalidate = 1;
19198: }
19199: if ($devalidate) {
19200: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19201: }
19202: }
19203: } else {
19204: if ($uselink) {
19205: $result = 1;
19206: } else {
19207: $result = 0;
19208: }
19209: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19210: }
19211: return $uselink;
19212: }
19213:
1.1075.2.161. .1(raebu 19214:21): sub page_menu {
19215:21): my ($menucolls,$menunum) = @_;
19216:21): my %menu;
19217:21): foreach my $item (split(/;/,$menucolls)) {
19218:21): my ($num,$value) = split(/\%/,$item);
19219:21): if ($num eq $menunum) {
19220:21): my @entries = split(/\&/,$value);
19221:21): foreach my $entry (@entries) {
19222:21): my ($name,$fields) = split(/=/,$entry);
19223:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
19224:21): $menu{$name} = $fields;
19225:21): } else {
19226:21): my @shown;
19227:21): if ($fields =~ /,/) {
19228:21): @shown = split(/,/,$fields);
19229:21): } else {
19230:21): @shown = ($fields);
19231:21): }
19232:21): if (@shown) {
19233:21): foreach my $field (@shown) {
19234:21): next if ($field eq '');
19235:21): $menu{$field} = 1;
19236:21): }
19237:21): }
19238:21): }
19239:21): }
19240:21): }
19241:21): }
19242:21): return %menu;
19243:21): }
19244:21):
1.112 bowersj2 19245: 1;
19246: __END__;
1.41 ng 19247:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>