Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.23
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. .23(raeb 4:-24): # $Id: loncommon.pm,v 1.1075.2.161.2.22 2024/02/28 03:23:49 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
6072:-24): permitted in current Authoring Space.
6073:-24): Value for each key is 1. Possible keys
6074:-24): are: edit, xml, and daxe. If no specific
6075:-24): set of editors has been set for the Author
6076:-24): who owns the Authoring Space, then the
6077:-24): domain default will be used. If no domain
6078:-24): default has been set, then the keys will be
6079:-24): edit and xml.
6080:-24):
6081:-24): =cut
6082:-24):
6083:-24): sub permitted_editors {
6084:-24): my ($uri) = @_;
6085:-24): my ($is_author,$is_coauthor,$auname,$audom,%editors);
6086:-24): if ($env{'request.role'} =~ m{^au\./}) {
6087:-24): $is_author = 1;
6088:-24): } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6089:-24): ($audom,$auname) = ($1,$2);
6090:-24): if (($audom ne '') && ($auname ne '')) {
6091:-24): if (($env{'user.domain'} eq $audom) &&
6092:-24): ($env{'user.name'} eq $auname)) {
6093:-24): $is_author = 1;
6094:-24): } else {
6095:-24): $is_coauthor = 1;
6096:-24): }
6097:-24): }
6098:-24): } elsif ($env{'request.course.id'}) {
6099:-24): if ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6100:-24): ($audom,$auname) = ($1,$2);
6101:-24): } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6102:-24): ($audom,$auname) = ($1,$2);
6103:-24): } elsif (($uri eq '/daxesave') &&
6104:-24): ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {
6105:-24): ($audom,$auname) = ($1,$2);
6106:-24): }
6107:-24): if (($audom ne '') && ($auname ne '')) {
6108:-24): if (($env{'user.domain'} eq $audom) &&
6109:-24): ($env{'user.name'} eq $auname)) {
6110:-24): $is_author = 1;
6111:-24): } else {
6112:-24): $is_coauthor = 1;
6113:-24): }
6114:-24): }
6115:-24): }
6116:-24): if ($is_author) {
6117:-24): if (exists($env{'environment.editors'})) {
6118:-24): map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6119:-24): } else {
6120:-24): %editors = ( edit => 1,
6121:-24): xml => 1,
6122:-24): );
6123:-24): }
6124:-24): } elsif ($is_coauthor) {
6125:-24): if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6126:-24): map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6127:-24): } else {
6128:-24): %editors = ( edit => 1,
6129:-24): xml => 1,
6130:-24): );
6131:-24): }
6132:-24): } else {
6133:-24): %editors = ( edit => 1,
6134:-24): xml => 1,
6135:-24): );
6136:-24): }
6137:-24): return %editors;
6138:-24): }
6139:-24):
1.60 matthew 6140: ###############################################
6141: ###############################################
6142:
6143: =pod
6144:
1.112 bowersj2 6145: =back
6146:
1.549 albertel 6147: =head1 HTML Helpers
1.112 bowersj2 6148:
6149: =over 4
6150:
6151: =item * &bodytag()
1.60 matthew 6152:
6153: Returns a uniform header for LON-CAPA web pages.
6154:
6155: Inputs:
6156:
1.112 bowersj2 6157: =over 4
6158:
6159: =item * $title, A title to be displayed on the page.
6160:
6161: =item * $function, the current role (can be undef).
6162:
6163: =item * $addentries, extra parameters for the <body> tag.
6164:
6165: =item * $bodyonly, if defined, only return the <body> tag.
6166:
6167: =item * $domain, if defined, force a given domain.
6168:
6169: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6170: text interface only)
1.60 matthew 6171:
1.814 bisitz 6172: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6173: navigational links
1.317 albertel 6174:
1.338 albertel 6175: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6176:
1.1075.2.12 raeburn 6177: =item * $no_inline_link, if true and in remote mode, don't show the
6178: 'Switch To Inline Menu' link
6179:
1.460 albertel 6180: =item * $args, optional argument valid values are
6181: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 6182: use_absolute -> for external resource or syllabus, this will
6183: contain https://<hostname> if server uses
6184: https (as per hosts.tab), but request is for http
6185: hostname -> hostname, from $r->hostname().
1.460 albertel 6186:
1.1075.2.15 raeburn 6187: =item * $advtoolsref, optional argument, ref to an array containing
6188: inlineremote items to be added in "Functions" menu below
6189: breadcrumbs.
6190:
1.1075.2.161. .1(raebu 6191:21): =item * $ltiscope, optional argument, will be one of: resource, map or
6192:21): course, if LON-CAPA is in LTI Provider context. Value is
6193:21): the scope of use, i.e., launch was for access to a single, a map
6194:21): or the entire course.
6195:21):
6196:21): =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6197:21): context, this will contain the URL for the landing item in
6198:21): the course, after launch from an LTI Consumer
6199:21):
6200:21): =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6201:21): context, this will contain a reference to hash of items
6202:21): to be included in the page header and/or inline menu.
6203:21):
.8(raebu 6204:22): =item * $menucoll, optional argument, if specific menu collection is in
6205:22): effect, either set as the default for the course, or set for
6206:22): the deeplink paramater for $env{'request.deeplink.login'}
6207:22): then $menucoll will be the number of that collection.
6208:22):
6209:22): =item * $menuref, optional argument, reference to a hash, containing the
6210:22): menu options included for the menu in effect, based on the
6211:22): configuration for the numbered menu collection in use.
6212:22):
6213:22): =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6214:22): within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6215:22): if so, $showncrumbsref is set there to 1, and will propagate back
6216:22): via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6217:22): being called a second time.
6218:22):
1.112 bowersj2 6219: =back
6220:
1.60 matthew 6221: Returns: A uniform header for LON-CAPA web pages.
6222: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6223: If $bodyonly is undef or zero, an html string containing a <body> tag and
6224: other decorations will be returned.
6225:
6226: =cut
6227:
1.54 www 6228: sub bodytag {
1.831 bisitz 6229: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.161. .1(raebu 6230:21): $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref,
.8(raebu 6231:22): $ltiscope,$ltiuri,$ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6232:
1.954 raeburn 6233: my $public;
6234: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6235: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6236: $public = 1;
6237: }
1.460 albertel 6238: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 6239: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 6240: my $hostname = $args->{'hostname'};
1.339 albertel 6241:
1.183 matthew 6242: $function = &get_users_function() if (!$function);
1.339 albertel 6243: my $img = &designparm($function.'.img',$domain);
6244: my $font = &designparm($function.'.font',$domain);
6245: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6246:
1.803 bisitz 6247: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6248: 'bgcolor' => $pgbg,
1.339 albertel 6249: 'text' => $font,
6250: 'alink' => &designparm($function.'.alink',$domain),
6251: 'vlink' => &designparm($function.'.vlink',$domain),
6252: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6253: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6254:
1.63 www 6255: # role and realm
1.1075.2.68 raeburn 6256: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6257: if ($realm) {
6258: $realm = '/'.$realm;
6259: }
1.1075.2.159 raeburn 6260: if ($role eq 'ca') {
1.479 albertel 6261: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6262: $realm = &plainname($rname,$rdom);
1.378 raeburn 6263: }
1.55 www 6264: # realm
1.1075.2.158 raeburn 6265: my ($cid,$sec);
1.258 albertel 6266: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 6267: $cid = $env{'request.course.id'};
6268: if ($env{'request.course.sec'}) {
6269: $sec = $env{'request.course.sec'};
6270: }
6271: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6272: if (&Apache::lonnet::is_course($1,$2)) {
6273: $cid = $1.'_'.$2;
6274: $sec = $3;
6275: }
6276: }
6277: if ($cid) {
1.378 raeburn 6278: if ($env{'request.role'} !~ /^cr/) {
6279: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 6280: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 6281: if ($env{'request.role.desc'}) {
6282: $role = $env{'request.role.desc'};
6283: } else {
6284: $role = &mt('Helpdesk[_1]',' '.$2);
6285: }
1.1075.2.115 raeburn 6286: } else {
6287: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6288: }
1.1075.2.158 raeburn 6289: if ($sec) {
6290: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6291: }
1.1075.2.158 raeburn 6292: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6293: } else {
6294: $role = &Apache::lonnet::plaintext($role);
1.54 www 6295: }
1.433 albertel 6296:
1.359 albertel 6297: if (!$realm) { $realm=' '; }
1.330 albertel 6298:
1.438 albertel 6299: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6300:
1.101 www 6301: # construct main body tag
1.359 albertel 6302: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 6303: &Apache::lontexconvert::init_math_support();
1.252 albertel 6304:
1.1075.2.38 raeburn 6305: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6306:
6307: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6308: return $bodytag;
1.1075.2.38 raeburn 6309: }
1.359 albertel 6310:
1.954 raeburn 6311: if ($public) {
1.433 albertel 6312: undef($role);
6313: }
1.1075.2.158 raeburn 6314:
1.1075.2.161. .1(raebu 6315:21): my $showcrstitle = 1;
6316:21): if (($cid) && ($env{'request.lti.login'})) {
6317:21): if (ref($ltimenu) eq 'HASH') {
6318:21): unless ($ltimenu->{'role'}) {
6319:21): undef($role);
6320:21): }
6321:21): unless ($ltimenu->{'coursetitle'}) {
6322:21): $realm=' ';
6323:21): $showcrstitle = 0;
6324:21): }
6325:21): }
6326:21): } elsif (($cid) && ($menucoll)) {
6327:21): if (ref($menuref) eq 'HASH') {
6328:21): unless ($menuref->{'role'}) {
6329:21): undef($role);
6330:21): }
6331:21): unless ($menuref->{'crs'}) {
6332:21): $realm=' ';
6333:21): $showcrstitle = 0;
6334:21): }
6335:21): }
6336:21): }
6337:21):
1.762 bisitz 6338: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6339: #
6340: # Extra info if you are the DC
6341: my $dc_info = '';
1.1075.2.161. .1(raebu 6342:21): if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1075.2.158 raeburn 6343: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6344: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6345: $dc_info =~ s/\s+$//;
1.359 albertel 6346: }
6347:
1.1075.2.161. .1(raebu 6348:21): my $crstype;
6349:21): if ($cid) {
6350:21): $crstype = $env{'course.'.$cid.'.type'};
6351:21): } elsif ($args->{'crstype'}) {
6352:21): $crstype = $args->{'crstype'};
6353:21): }
6354:21):
1.1075.2.108 raeburn 6355: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 6356:
1.1075.2.13 raeburn 6357: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6358:
1.1075.2.38 raeburn 6359:
6360:
1.1075.2.21 raeburn 6361: my $funclist;
6362: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 6363: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 6364: Apache::lonmenu::serverform();
6365: my $forbodytag;
6366: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6367: $forcereg,$args->{'group'},
6368: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6369: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 6370: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6371: $funclist = $forbodytag;
6372: }
6373: } else {
1.903 droeschl 6374:
6375: # if ($env{'request.state'} eq 'construct') {
6376: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6377: # }
6378:
1.1075.2.38 raeburn 6379: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6380: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6381:
1.1075.2.161. .23(raeb 6382:-24): my $collapsible;
.21(raeb 6383:-24): if ($args->{'collapsible_header'} ne '') {
.23(raeb 6384:-24): $collapsible = 1;
6385:-24): my ($menustate,$tiptext,$divclass);
6386:-24): if ($args->{'start_collapsed'}) {
6387:-24): $menustate = 'collapsed';
6388:-24): $tiptext = 'display';
6389:-24): $divclass = 'hidden';
6390:-24): } else {
6391:-24): $menustate = 'expanded';
6392:-24): $tiptext = 'hide';
6393:-24): $divclass = 'shown';
6394:-24): }
6395:-24): my $alttext = &mt('menu state: '.$menustate);
6396:-24): my $tooltip = &mt($tiptext.' standard menus');
.21(raeb 6397:-24): $bodytag .= <<"END";
6398:-24): <div id="LC_expandingContainer" style="display:inline;">
6399:-24): <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
.23(raeb 6400:-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>
6401:-24): <div class="LC_menus_content $divclass">
.21(raeb 6402:-24): END
6403:-24): }
.1(raebu 6404:21): unless ($args->{'no_primary_menu'}) {
.4(raebu 6405:22): my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
.6(raebu 6406:22): $args->{'links_disabled'},
.21(raeb 6407:-24): $args->{'links_target'},
.23(raeb 6408:-24): $collapsible);
.1(raebu 6409:21): if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6410:21): if ($dc_info) {
6411:21): $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6412:21): }
6413:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6414:21): <em>$realm</em> $dc_info</div>|;
6415:21): return $bodytag;
1.1075.2.1 raeburn 6416: }
1.894 droeschl 6417:
1.1075.2.161. .1(raebu 6418:21): unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6419:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6420:21): }
1.916 droeschl 6421:
1.1075.2.161. .1(raebu 6422:21): $bodytag .= $right;
1.852 droeschl 6423:
1.1075.2.161. .1(raebu 6424:21): if ($dc_info) {
6425:21): $dc_info = &dc_courseid_toggle($dc_info);
6426:21): }
6427:21): $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6428: }
1.916 droeschl 6429:
1.1075.2.61 raeburn 6430: #if directed to not display the secondary menu, don't.
6431: if ($args->{'no_secondary_menu'}) {
6432: return $bodytag;
6433: }
1.903 droeschl 6434: #don't show menus for public users
1.954 raeburn 6435: if (!$public){
1.1075.2.161. .1(raebu 6436:21): unless ($args->{'no_inline_menu'}) {
6437:21): $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6438:21): $args->{'no_primary_menu'},
6439:21): $menucoll,$menuref,
.6(raebu 6440:22): $args->{'links_disabled'},
6441:22): $args->{'links_target'});
.1(raebu 6442:21): }
1.903 droeschl 6443: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6444: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6445: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6446: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.161. .8(raebu 6447:22): $args->{'bread_crumbs'},'','',$hostname,
6448:22): $ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.116 raeburn 6449: } elsif ($forcereg) {
1.1075.2.22 raeburn 6450: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.161. .8(raebu 6451:22): $args->{'group'},$args->{'hide_buttons'},
6452:22): $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.15 raeburn 6453: } else {
1.1075.2.21 raeburn 6454: my $forbodytag;
6455: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6456: $forcereg,$args->{'group'},
6457: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6458: $advtoolsref,'',$hostname,
6459: \$forbodytag);
1.1075.2.21 raeburn 6460: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6461: $bodytag .= $forbodytag;
6462: }
1.920 raeburn 6463: }
1.903 droeschl 6464: }else{
6465: # this is to seperate menu from content when there's no secondary
6466: # menu. Especially needed for public accessible ressources.
6467: $bodytag .= '<hr style="clear:both" />';
6468: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6469: }
1.1075.2.161. .21(raeb 6470:-24): if ($args->{'collapsible_header'} ne '') {
6471:-24): $bodytag .= $args->{'collapsible_header'}.
6472:-24): '<div id="LC_collapsible_separator"></div>'.
6473:-24): '</div></div>';
6474:-24): }
1.235 raeburn 6475: return $bodytag;
1.1075.2.12 raeburn 6476: }
6477:
6478: #
6479: # Top frame rendering, Remote is up
6480: #
6481:
6482: my $imgsrc = $img;
6483: if ($img =~ /^\/adm/) {
6484: $imgsrc = &lonhttpdurl($img);
6485: }
6486: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
6487:
1.1075.2.60 raeburn 6488: my $help=($no_inline_link?''
6489: :&Apache::loncommon::top_nav_help('Help'));
6490:
1.1075.2.12 raeburn 6491: # Explicit link to get inline menu
6492: my $menu= ($no_inline_link?''
6493: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
6494:
6495: if ($dc_info) {
6496: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
6497: }
6498:
1.1075.2.38 raeburn 6499: my $name = &plainname($env{'user.name'},$env{'user.domain'});
6500: unless ($public) {
6501: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
6502: undef,'LC_menubuttons_link');
6503: }
6504:
1.1075.2.12 raeburn 6505: unless ($env{'form.inhibitmenu'}) {
6506: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 6507: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 6508: <li>$help</li>
1.1075.2.12 raeburn 6509: <li>$menu</li>
6510: </ol><div id="LC_realm"> $realm $dc_info</div>|;
6511: }
1.1075.2.13 raeburn 6512: if ($env{'request.state'} eq 'construct') {
6513: if (!$public){
6514: if ($env{'request.state'} eq 'construct') {
6515: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6516: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 6517: &Apache::lonhtmlcommon::scripttag('','end').
6518: &Apache::lonmenu::innerregister($forcereg,
6519: $args->{'bread_crumbs'});
6520: }
6521: }
6522: }
1.1075.2.21 raeburn 6523: return $bodytag."\n".$funclist;
1.182 matthew 6524: }
6525:
1.917 raeburn 6526: sub dc_courseid_toggle {
6527: my ($dc_info) = @_;
1.980 raeburn 6528: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6529: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6530: &mt('(More ...)').'</a></span>'.
6531: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6532: }
6533:
1.330 albertel 6534: sub make_attr_string {
6535: my ($register,$attr_ref) = @_;
6536:
6537: if ($attr_ref && !ref($attr_ref)) {
6538: die("addentries Must be a hash ref ".
6539: join(':',caller(1))." ".
6540: join(':',caller(0))." ");
6541: }
6542:
6543: if ($register) {
1.339 albertel 6544: my ($on_load,$on_unload);
6545: foreach my $key (keys(%{$attr_ref})) {
6546: if (lc($key) eq 'onload') {
6547: $on_load.=$attr_ref->{$key}.';';
6548: delete($attr_ref->{$key});
6549:
6550: } elsif (lc($key) eq 'onunload') {
6551: $on_unload.=$attr_ref->{$key}.';';
6552: delete($attr_ref->{$key});
6553: }
6554: }
1.1075.2.12 raeburn 6555: if ($env{'environment.remote'} eq 'on') {
6556: $attr_ref->{'onload'} =
6557: &Apache::lonmenu::loadevents(). $on_load;
6558: $attr_ref->{'onunload'}=
6559: &Apache::lonmenu::unloadevents().$on_unload;
6560: } else {
6561: $attr_ref->{'onload'} = $on_load;
6562: $attr_ref->{'onunload'}= $on_unload;
6563: }
1.330 albertel 6564: }
1.339 albertel 6565:
1.330 albertel 6566: my $attr_string;
1.1075.2.56 raeburn 6567: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6568: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6569: }
6570: return $attr_string;
6571: }
6572:
6573:
1.182 matthew 6574: ###############################################
1.251 albertel 6575: ###############################################
6576:
6577: =pod
6578:
6579: =item * &endbodytag()
6580:
6581: Returns a uniform footer for LON-CAPA web pages.
6582:
1.635 raeburn 6583: Inputs: 1 - optional reference to an args hash
6584: If in the hash, key for noredirectlink has a value which evaluates to true,
6585: a 'Continue' link is not displayed if the page contains an
6586: internal redirect in the <head></head> section,
6587: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6588:
6589: =cut
6590:
6591: sub endbodytag {
1.635 raeburn 6592: my ($args) = @_;
1.1075.2.6 raeburn 6593: my $endbodytag;
6594: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6595: $endbodytag='</body>';
6596: }
1.315 albertel 6597: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6598: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1075.2.161. .9(raebu 6599:22): my ($endbodyjs,$idattr);
6600:22): if ($env{'internal.head.to_opener'}) {
6601:22): my $linkid = 'LC_continue_link';
6602:22): $idattr = ' id="'.$linkid.'"';
6603:22): my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6604:22): $endbodyjs=<<ENDJS;
6605:22): <script type="text/javascript">
6606:22): // <![CDATA[
6607:22): function ebFunction(evt) {
6608:22): evt.preventDefault();
6609:22): var dest = '$redirect_for_js';
6610:22): if (window.opener != null && !window.opener.closed) {
6611:22): window.opener.location.href=dest;
6612:22): window.close();
6613:22): } else {
6614:22): window.location.href=dest;
6615:22): }
6616:22): return false;
6617:22): }
6618:22):
6619:22): \$(document).ready(function () {
6620:22): if (document.getElementById('$linkid')) {
6621:22): var clickelem = document.getElementById('$linkid');
6622:22): clickelem.addEventListener('click',ebFunction,false);
6623:22): }
6624:22): });
6625:22): // ]]>
6626:22): </script>
6627:22): ENDJS
6628:22): }
1.635 raeburn 6629: $endbodytag=
1.1075.2.161. .9(raebu 6630:22): "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6631: &mt('Continue').'</a>'.
6632: $endbodytag;
6633: }
1.315 albertel 6634: }
1.1075.2.161. .19(raeb 6635:-23): if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6636:-23): $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6637:-23): }
1.251 albertel 6638: return $endbodytag;
6639: }
6640:
1.352 albertel 6641: =pod
6642:
6643: =item * &standard_css()
6644:
6645: Returns a style sheet
6646:
6647: Inputs: (all optional)
6648: domain -> force to color decorate a page for a specific
6649: domain
6650: function -> force usage of a specific rolish color scheme
6651: bgcolor -> override the default page bgcolor
6652:
6653: =cut
6654:
1.343 albertel 6655: sub standard_css {
1.345 albertel 6656: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6657: $function = &get_users_function() if (!$function);
6658: my $img = &designparm($function.'.img', $domain);
6659: my $tabbg = &designparm($function.'.tabbg', $domain);
6660: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6661: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6662: #second colour for later usage
1.345 albertel 6663: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6664: my $pgbg_or_bgcolor =
6665: $bgcolor ||
1.352 albertel 6666: &designparm($function.'.pgbg', $domain);
1.382 albertel 6667: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6668: my $alink = &designparm($function.'.alink', $domain);
6669: my $vlink = &designparm($function.'.vlink', $domain);
6670: my $link = &designparm($function.'.link', $domain);
6671:
1.602 albertel 6672: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6673: my $mono = 'monospace';
1.850 bisitz 6674: my $data_table_head = $sidebg;
6675: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6676: my $data_table_dark = '#E0E0E0';
1.470 banghart 6677: my $data_table_darker = '#CCCCCC';
1.349 albertel 6678: my $data_table_highlight = '#FFFF00';
1.352 albertel 6679: my $mail_new = '#FFBB77';
6680: my $mail_new_hover = '#DD9955';
6681: my $mail_read = '#BBBB77';
6682: my $mail_read_hover = '#999944';
6683: my $mail_replied = '#AAAA88';
6684: my $mail_replied_hover = '#888855';
6685: my $mail_other = '#99BBBB';
6686: my $mail_other_hover = '#669999';
1.391 albertel 6687: my $table_header = '#DDDDDD';
1.489 raeburn 6688: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6689: my $lg_border_color = '#C8C8C8';
1.952 onken 6690: my $button_hover = '#BF2317';
1.392 albertel 6691:
1.608 albertel 6692: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6693: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6694: : '0 3px 0 4px';
1.448 albertel 6695:
1.523 albertel 6696:
1.343 albertel 6697: return <<END;
1.947 droeschl 6698:
6699: /* needed for iframe to allow 100% height in FF */
6700: body, html {
6701: margin: 0;
6702: padding: 0 0.5%;
6703: height: 99%; /* to avoid scrollbars */
6704: }
6705:
1.795 www 6706: body {
1.911 bisitz 6707: font-family: $sans;
6708: line-height:130%;
6709: font-size:0.83em;
6710: color:$font;
1.795 www 6711: }
6712:
1.959 onken 6713: a:focus,
6714: a:focus img {
1.795 www 6715: color: red;
6716: }
1.698 harmsja 6717:
1.911 bisitz 6718: form, .inline {
6719: display: inline;
1.795 www 6720: }
1.721 harmsja 6721:
1.1075.2.161. .21(raeb 6722:-24): .LC_menus_content.shown{
6723:-24): display: inline;
6724:-24): }
6725:-24):
6726:-24): .LC_menus_content.hidden {
6727:-24): display: none;
6728:-24): }
6729:-24):
1.795 www 6730: .LC_right {
1.911 bisitz 6731: text-align:right;
1.795 www 6732: }
6733:
6734: .LC_middle {
1.911 bisitz 6735: vertical-align:middle;
1.795 www 6736: }
1.721 harmsja 6737:
1.1075.2.38 raeburn 6738: .LC_floatleft {
6739: float: left;
6740: }
6741:
6742: .LC_floatright {
6743: float: right;
6744: }
6745:
1.911 bisitz 6746: .LC_400Box {
6747: width:400px;
6748: }
1.721 harmsja 6749:
1.1075.2.161. .21(raeb 6750:-24): #LC_collapsible_separator {
6751:-24): border: 1px solid black;
6752:-24): width: 99.9%;
6753:-24): height: 0px;
6754:-24): }
6755:-24):
1.947 droeschl 6756: .LC_iframecontainer {
6757: width: 98%;
6758: margin: 0;
6759: position: fixed;
6760: top: 8.5em;
6761: bottom: 0;
6762: }
6763:
6764: .LC_iframecontainer iframe{
6765: border: none;
6766: width: 100%;
6767: height: 100%;
6768: }
6769:
1.778 bisitz 6770: .LC_filename {
6771: font-family: $mono;
6772: white-space:pre;
1.921 bisitz 6773: font-size: 120%;
1.778 bisitz 6774: }
6775:
6776: .LC_fileicon {
6777: border: none;
6778: height: 1.3em;
6779: vertical-align: text-bottom;
6780: margin-right: 0.3em;
6781: text-decoration:none;
6782: }
6783:
1.1008 www 6784: .LC_setting {
6785: text-decoration:underline;
6786: }
6787:
1.350 albertel 6788: .LC_error {
6789: color: red;
6790: }
1.795 www 6791:
1.1075.2.15 raeburn 6792: .LC_warning {
6793: color: darkorange;
6794: }
6795:
1.457 albertel 6796: .LC_diff_removed {
1.733 bisitz 6797: color: red;
1.394 albertel 6798: }
1.532 albertel 6799:
6800: .LC_info,
1.457 albertel 6801: .LC_success,
6802: .LC_diff_added {
1.350 albertel 6803: color: green;
6804: }
1.795 www 6805:
1.802 bisitz 6806: div.LC_confirm_box {
6807: background-color: #FAFAFA;
6808: border: 1px solid $lg_border_color;
6809: margin-right: 0;
6810: padding: 5px;
6811: }
6812:
6813: div.LC_confirm_box .LC_error img,
6814: div.LC_confirm_box .LC_success img {
6815: vertical-align: middle;
6816: }
6817:
1.1075.2.108 raeburn 6818: .LC_maxwidth {
6819: max-width: 100%;
6820: height: auto;
6821: }
6822:
6823: .LC_textsize_mobile {
6824: \@media only screen and (max-device-width: 480px) {
6825: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6826: }
6827: }
6828:
1.440 albertel 6829: .LC_icon {
1.771 droeschl 6830: border: none;
1.790 droeschl 6831: vertical-align: middle;
1.771 droeschl 6832: }
6833:
1.543 albertel 6834: .LC_docs_spacer {
6835: width: 25px;
6836: height: 1px;
1.771 droeschl 6837: border: none;
1.543 albertel 6838: }
1.346 albertel 6839:
1.532 albertel 6840: .LC_internal_info {
1.735 bisitz 6841: color: #999999;
1.532 albertel 6842: }
6843:
1.794 www 6844: .LC_discussion {
1.1050 www 6845: background: $data_table_dark;
1.911 bisitz 6846: border: 1px solid black;
6847: margin: 2px;
1.794 www 6848: }
6849:
6850: .LC_disc_action_left {
1.1050 www 6851: background: $sidebg;
1.911 bisitz 6852: text-align: left;
1.1050 www 6853: padding: 4px;
6854: margin: 2px;
1.794 www 6855: }
6856:
6857: .LC_disc_action_right {
1.1050 www 6858: background: $sidebg;
1.911 bisitz 6859: text-align: right;
1.1050 www 6860: padding: 4px;
6861: margin: 2px;
1.794 www 6862: }
6863:
6864: .LC_disc_new_item {
1.911 bisitz 6865: background: white;
6866: border: 2px solid red;
1.1050 www 6867: margin: 4px;
6868: padding: 4px;
1.794 www 6869: }
6870:
6871: .LC_disc_old_item {
1.911 bisitz 6872: background: white;
1.1050 www 6873: margin: 4px;
6874: padding: 4px;
1.794 www 6875: }
6876:
1.458 albertel 6877: table.LC_pastsubmission {
6878: border: 1px solid black;
6879: margin: 2px;
6880: }
6881:
1.924 bisitz 6882: table#LC_menubuttons {
1.345 albertel 6883: width: 100%;
6884: background: $pgbg;
1.392 albertel 6885: border: 2px;
1.402 albertel 6886: border-collapse: separate;
1.803 bisitz 6887: padding: 0;
1.345 albertel 6888: }
1.392 albertel 6889:
1.801 tempelho 6890: table#LC_title_bar a {
6891: color: $fontmenu;
6892: }
1.836 bisitz 6893:
1.807 droeschl 6894: table#LC_title_bar {
1.819 tempelho 6895: clear: both;
1.836 bisitz 6896: display: none;
1.807 droeschl 6897: }
6898:
1.795 www 6899: table#LC_title_bar,
1.933 droeschl 6900: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6901: table#LC_title_bar.LC_with_remote {
1.359 albertel 6902: width: 100%;
1.392 albertel 6903: border-color: $pgbg;
6904: border-style: solid;
6905: border-width: $border;
1.379 albertel 6906: background: $pgbg;
1.801 tempelho 6907: color: $fontmenu;
1.392 albertel 6908: border-collapse: collapse;
1.803 bisitz 6909: padding: 0;
1.819 tempelho 6910: margin: 0;
1.359 albertel 6911: }
1.795 www 6912:
1.933 droeschl 6913: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6914: margin: 0;
6915: padding: 0;
1.933 droeschl 6916: position: relative;
6917: list-style: none;
1.913 droeschl 6918: }
1.933 droeschl 6919: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6920: display: inline;
6921: }
1.933 droeschl 6922:
6923: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6924: padding: 0;
1.933 droeschl 6925: margin: 0;
6926: float: left;
1.913 droeschl 6927: }
1.933 droeschl 6928: .LC_breadcrumb_tools_tools {
6929: padding: 0;
6930: margin: 0;
1.913 droeschl 6931: float: right;
6932: }
6933:
1.359 albertel 6934: table#LC_title_bar td {
6935: background: $tabbg;
6936: }
1.795 www 6937:
1.911 bisitz 6938: table#LC_menubuttons img {
1.803 bisitz 6939: border: none;
1.346 albertel 6940: }
1.795 www 6941:
1.842 droeschl 6942: .LC_breadcrumbs_component {
1.911 bisitz 6943: float: right;
6944: margin: 0 1em;
1.357 albertel 6945: }
1.842 droeschl 6946: .LC_breadcrumbs_component img {
1.911 bisitz 6947: vertical-align: middle;
1.777 tempelho 6948: }
1.795 www 6949:
1.1075.2.108 raeburn 6950: .LC_breadcrumbs_hoverable {
6951: background: $sidebg;
6952: }
6953:
1.383 albertel 6954: td.LC_table_cell_checkbox {
6955: text-align: center;
6956: }
1.795 www 6957:
6958: .LC_fontsize_small {
1.911 bisitz 6959: font-size: 70%;
1.705 tempelho 6960: }
6961:
1.844 bisitz 6962: #LC_breadcrumbs {
1.911 bisitz 6963: clear:both;
6964: background: $sidebg;
6965: border-bottom: 1px solid $lg_border_color;
6966: line-height: 2.5em;
1.933 droeschl 6967: overflow: hidden;
1.911 bisitz 6968: margin: 0;
6969: padding: 0;
1.995 raeburn 6970: text-align: left;
1.819 tempelho 6971: }
1.862 bisitz 6972:
1.1075.2.16 raeburn 6973: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6974: clear:both;
6975: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6976: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6977: margin: 0 0 10px 0;
1.966 bisitz 6978: padding: 3px;
1.995 raeburn 6979: text-align: left;
1.822 bisitz 6980: }
6981:
1.795 www 6982: .LC_fontsize_medium {
1.911 bisitz 6983: font-size: 85%;
1.705 tempelho 6984: }
6985:
1.795 www 6986: .LC_fontsize_large {
1.911 bisitz 6987: font-size: 120%;
1.705 tempelho 6988: }
6989:
1.346 albertel 6990: .LC_menubuttons_inline_text {
6991: color: $font;
1.698 harmsja 6992: font-size: 90%;
1.701 harmsja 6993: padding-left:3px;
1.346 albertel 6994: }
6995:
1.934 droeschl 6996: .LC_menubuttons_inline_text img{
6997: vertical-align: middle;
6998: }
6999:
1.1051 www 7000: li.LC_menubuttons_inline_text img {
1.951 onken 7001: cursor:pointer;
1.1002 droeschl 7002: text-decoration: none;
1.951 onken 7003: }
7004:
1.526 www 7005: .LC_menubuttons_link {
7006: text-decoration: none;
7007: }
1.795 www 7008:
1.522 albertel 7009: .LC_menubuttons_category {
1.521 www 7010: color: $font;
1.526 www 7011: background: $pgbg;
1.521 www 7012: font-size: larger;
7013: font-weight: bold;
7014: }
7015:
1.346 albertel 7016: td.LC_menubuttons_text {
1.911 bisitz 7017: color: $font;
1.346 albertel 7018: }
1.706 harmsja 7019:
1.346 albertel 7020: .LC_current_location {
7021: background: $tabbg;
7022: }
1.795 www 7023:
1.1075.2.134 raeburn 7024: td.LC_zero_height {
7025: line-height: 0;
7026: cellpadding: 0;
7027: }
7028:
1.938 bisitz 7029: table.LC_data_table {
1.347 albertel 7030: border: 1px solid #000000;
1.402 albertel 7031: border-collapse: separate;
1.426 albertel 7032: border-spacing: 1px;
1.610 albertel 7033: background: $pgbg;
1.347 albertel 7034: }
1.795 www 7035:
1.422 albertel 7036: .LC_data_table_dense {
7037: font-size: small;
7038: }
1.795 www 7039:
1.507 raeburn 7040: table.LC_nested_outer {
7041: border: 1px solid #000000;
1.589 raeburn 7042: border-collapse: collapse;
1.803 bisitz 7043: border-spacing: 0;
1.507 raeburn 7044: width: 100%;
7045: }
1.795 www 7046:
1.879 raeburn 7047: table.LC_innerpickbox,
1.507 raeburn 7048: table.LC_nested {
1.803 bisitz 7049: border: none;
1.589 raeburn 7050: border-collapse: collapse;
1.803 bisitz 7051: border-spacing: 0;
1.507 raeburn 7052: width: 100%;
7053: }
1.795 www 7054:
1.911 bisitz 7055: table.LC_data_table tr th,
7056: table.LC_calendar tr th,
1.879 raeburn 7057: table.LC_prior_tries tr th,
7058: table.LC_innerpickbox tr th {
1.349 albertel 7059: font-weight: bold;
7060: background-color: $data_table_head;
1.801 tempelho 7061: color:$fontmenu;
1.701 harmsja 7062: font-size:90%;
1.347 albertel 7063: }
1.795 www 7064:
1.879 raeburn 7065: table.LC_innerpickbox tr th,
7066: table.LC_innerpickbox tr td {
7067: vertical-align: top;
7068: }
7069:
1.711 raeburn 7070: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7071: background-color: #CCCCCC;
1.711 raeburn 7072: font-weight: bold;
7073: text-align: left;
7074: }
1.795 www 7075:
1.912 bisitz 7076: table.LC_data_table tr.LC_odd_row > td {
7077: background-color: $data_table_light;
7078: padding: 2px;
7079: vertical-align: top;
7080: }
7081:
1.809 bisitz 7082: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7083: background-color: $data_table_light;
1.912 bisitz 7084: vertical-align: top;
7085: }
7086:
7087: table.LC_data_table tr.LC_even_row > td {
7088: background-color: $data_table_dark;
1.425 albertel 7089: padding: 2px;
1.900 bisitz 7090: vertical-align: top;
1.347 albertel 7091: }
1.795 www 7092:
1.809 bisitz 7093: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7094: background-color: $data_table_dark;
1.900 bisitz 7095: vertical-align: top;
1.347 albertel 7096: }
1.795 www 7097:
1.425 albertel 7098: table.LC_data_table tr.LC_data_table_highlight td {
7099: background-color: $data_table_darker;
7100: }
1.795 www 7101:
1.639 raeburn 7102: table.LC_data_table tr td.LC_leftcol_header {
7103: background-color: $data_table_head;
7104: font-weight: bold;
7105: }
1.795 www 7106:
1.451 albertel 7107: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7108: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7109: font-weight: bold;
7110: font-style: italic;
7111: text-align: center;
7112: padding: 8px;
1.347 albertel 7113: }
1.795 www 7114:
1.1075.2.30 raeburn 7115: table.LC_data_table tr.LC_empty_row td,
7116: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7117: background-color: $sidebg;
7118: }
7119:
7120: table.LC_nested tr.LC_empty_row td {
7121: background-color: #FFFFFF;
7122: }
7123:
1.890 droeschl 7124: table.LC_caption {
7125: }
7126:
1.507 raeburn 7127: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7128: padding: 4ex
7129: }
1.795 www 7130:
1.507 raeburn 7131: table.LC_nested_outer tr th {
7132: font-weight: bold;
1.801 tempelho 7133: color:$fontmenu;
1.507 raeburn 7134: background-color: $data_table_head;
1.701 harmsja 7135: font-size: small;
1.507 raeburn 7136: border-bottom: 1px solid #000000;
7137: }
1.795 www 7138:
1.507 raeburn 7139: table.LC_nested_outer tr td.LC_subheader {
7140: background-color: $data_table_head;
7141: font-weight: bold;
7142: font-size: small;
7143: border-bottom: 1px solid #000000;
7144: text-align: right;
1.451 albertel 7145: }
1.795 www 7146:
1.507 raeburn 7147: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7148: background-color: #CCCCCC;
1.451 albertel 7149: font-weight: bold;
7150: font-size: small;
1.507 raeburn 7151: text-align: center;
7152: }
1.795 www 7153:
1.589 raeburn 7154: table.LC_nested tr.LC_info_row td.LC_left_item,
7155: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7156: text-align: left;
1.451 albertel 7157: }
1.795 www 7158:
1.507 raeburn 7159: table.LC_nested td {
1.735 bisitz 7160: background-color: #FFFFFF;
1.451 albertel 7161: font-size: small;
1.507 raeburn 7162: }
1.795 www 7163:
1.507 raeburn 7164: table.LC_nested_outer tr th.LC_right_item,
7165: table.LC_nested tr.LC_info_row td.LC_right_item,
7166: table.LC_nested tr.LC_odd_row td.LC_right_item,
7167: table.LC_nested tr td.LC_right_item {
1.451 albertel 7168: text-align: right;
7169: }
7170:
1.507 raeburn 7171: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7172: background-color: #EEEEEE;
1.451 albertel 7173: }
7174:
1.473 raeburn 7175: table.LC_createuser {
7176: }
7177:
7178: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7179: font-size: small;
1.473 raeburn 7180: }
7181:
7182: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7183: background-color: #CCCCCC;
1.473 raeburn 7184: font-weight: bold;
7185: text-align: center;
7186: }
7187:
1.349 albertel 7188: table.LC_calendar {
7189: border: 1px solid #000000;
7190: border-collapse: collapse;
1.917 raeburn 7191: width: 98%;
1.349 albertel 7192: }
1.795 www 7193:
1.349 albertel 7194: table.LC_calendar_pickdate {
7195: font-size: xx-small;
7196: }
1.795 www 7197:
1.349 albertel 7198: table.LC_calendar tr td {
7199: border: 1px solid #000000;
7200: vertical-align: top;
1.917 raeburn 7201: width: 14%;
1.349 albertel 7202: }
1.795 www 7203:
1.349 albertel 7204: table.LC_calendar tr td.LC_calendar_day_empty {
7205: background-color: $data_table_dark;
7206: }
1.795 www 7207:
1.779 bisitz 7208: table.LC_calendar tr td.LC_calendar_day_current {
7209: background-color: $data_table_highlight;
1.777 tempelho 7210: }
1.795 www 7211:
1.938 bisitz 7212: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7213: background-color: $mail_new;
7214: }
1.795 www 7215:
1.938 bisitz 7216: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7217: background-color: $mail_new_hover;
7218: }
1.795 www 7219:
1.938 bisitz 7220: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7221: background-color: $mail_read;
7222: }
1.795 www 7223:
1.938 bisitz 7224: /*
7225: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7226: background-color: $mail_read_hover;
7227: }
1.938 bisitz 7228: */
1.795 www 7229:
1.938 bisitz 7230: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7231: background-color: $mail_replied;
7232: }
1.795 www 7233:
1.938 bisitz 7234: /*
7235: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7236: background-color: $mail_replied_hover;
7237: }
1.938 bisitz 7238: */
1.795 www 7239:
1.938 bisitz 7240: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7241: background-color: $mail_other;
7242: }
1.795 www 7243:
1.938 bisitz 7244: /*
7245: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7246: background-color: $mail_other_hover;
7247: }
1.938 bisitz 7248: */
1.494 raeburn 7249:
1.777 tempelho 7250: table.LC_data_table tr > td.LC_browser_file,
7251: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7252: background: #AAEE77;
1.389 albertel 7253: }
1.795 www 7254:
1.777 tempelho 7255: table.LC_data_table tr > td.LC_browser_file_locked,
7256: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7257: background: #FFAA99;
1.387 albertel 7258: }
1.795 www 7259:
1.777 tempelho 7260: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7261: background: #888888;
1.779 bisitz 7262: }
1.795 www 7263:
1.777 tempelho 7264: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7265: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7266: background: #F8F866;
1.777 tempelho 7267: }
1.795 www 7268:
1.696 bisitz 7269: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7270: background: #E0E8FF;
1.387 albertel 7271: }
1.696 bisitz 7272:
1.707 bisitz 7273: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7274: /* background: #77FF77; */
1.707 bisitz 7275: }
1.795 www 7276:
1.707 bisitz 7277: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7278: border-right: 8px solid #FFFF77;
1.707 bisitz 7279: }
1.795 www 7280:
1.707 bisitz 7281: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7282: border-right: 8px solid #FFAA77;
1.707 bisitz 7283: }
1.795 www 7284:
1.707 bisitz 7285: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7286: border-right: 8px solid #FF7777;
1.707 bisitz 7287: }
1.795 www 7288:
1.707 bisitz 7289: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7290: border-right: 8px solid #AAFF77;
1.707 bisitz 7291: }
1.795 www 7292:
1.707 bisitz 7293: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7294: border-right: 8px solid #11CC55;
1.707 bisitz 7295: }
7296:
1.388 albertel 7297: span.LC_current_location {
1.701 harmsja 7298: font-size:larger;
1.388 albertel 7299: background: $pgbg;
7300: }
1.387 albertel 7301:
1.1029 www 7302: span.LC_current_nav_location {
7303: font-weight:bold;
7304: background: $sidebg;
7305: }
7306:
1.395 albertel 7307: span.LC_parm_menu_item {
7308: font-size: larger;
7309: }
1.795 www 7310:
1.395 albertel 7311: span.LC_parm_scope_all {
7312: color: red;
7313: }
1.795 www 7314:
1.395 albertel 7315: span.LC_parm_scope_folder {
7316: color: green;
7317: }
1.795 www 7318:
1.395 albertel 7319: span.LC_parm_scope_resource {
7320: color: orange;
7321: }
1.795 www 7322:
1.395 albertel 7323: span.LC_parm_part {
7324: color: blue;
7325: }
1.795 www 7326:
1.911 bisitz 7327: span.LC_parm_folder,
7328: span.LC_parm_symb {
1.395 albertel 7329: font-size: x-small;
7330: font-family: $mono;
7331: color: #AAAAAA;
7332: }
7333:
1.977 bisitz 7334: ul.LC_parm_parmlist li {
7335: display: inline-block;
7336: padding: 0.3em 0.8em;
7337: vertical-align: top;
7338: width: 150px;
7339: border-top:1px solid $lg_border_color;
7340: }
7341:
1.795 www 7342: td.LC_parm_overview_level_menu,
7343: td.LC_parm_overview_map_menu,
7344: td.LC_parm_overview_parm_selectors,
7345: td.LC_parm_overview_restrictions {
1.396 albertel 7346: border: 1px solid black;
7347: border-collapse: collapse;
7348: }
1.795 www 7349:
1.396 albertel 7350: table.LC_parm_overview_restrictions td {
7351: border-width: 1px 4px 1px 4px;
7352: border-style: solid;
7353: border-color: $pgbg;
7354: text-align: center;
7355: }
1.795 www 7356:
1.396 albertel 7357: table.LC_parm_overview_restrictions th {
7358: background: $tabbg;
7359: border-width: 1px 4px 1px 4px;
7360: border-style: solid;
7361: border-color: $pgbg;
7362: }
1.795 www 7363:
1.398 albertel 7364: table#LC_helpmenu {
1.803 bisitz 7365: border: none;
1.398 albertel 7366: height: 55px;
1.803 bisitz 7367: border-spacing: 0;
1.398 albertel 7368: }
7369:
7370: table#LC_helpmenu fieldset legend {
7371: font-size: larger;
7372: }
1.795 www 7373:
1.397 albertel 7374: table#LC_helpmenu_links {
7375: width: 100%;
7376: border: 1px solid black;
7377: background: $pgbg;
1.803 bisitz 7378: padding: 0;
1.397 albertel 7379: border-spacing: 1px;
7380: }
1.795 www 7381:
1.397 albertel 7382: table#LC_helpmenu_links tr td {
7383: padding: 1px;
7384: background: $tabbg;
1.399 albertel 7385: text-align: center;
7386: font-weight: bold;
1.397 albertel 7387: }
1.396 albertel 7388:
1.795 www 7389: table#LC_helpmenu_links a:link,
7390: table#LC_helpmenu_links a:visited,
1.397 albertel 7391: table#LC_helpmenu_links a:active {
7392: text-decoration: none;
7393: color: $font;
7394: }
1.795 www 7395:
1.397 albertel 7396: table#LC_helpmenu_links a:hover {
7397: text-decoration: underline;
7398: color: $vlink;
7399: }
1.396 albertel 7400:
1.417 albertel 7401: .LC_chrt_popup_exists {
7402: border: 1px solid #339933;
7403: margin: -1px;
7404: }
1.795 www 7405:
1.417 albertel 7406: .LC_chrt_popup_up {
7407: border: 1px solid yellow;
7408: margin: -1px;
7409: }
1.795 www 7410:
1.417 albertel 7411: .LC_chrt_popup {
7412: border: 1px solid #8888FF;
7413: background: #CCCCFF;
7414: }
1.795 www 7415:
1.421 albertel 7416: table.LC_pick_box {
7417: border-collapse: separate;
7418: background: white;
7419: border: 1px solid black;
7420: border-spacing: 1px;
7421: }
1.795 www 7422:
1.421 albertel 7423: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7424: background: $sidebg;
1.421 albertel 7425: font-weight: bold;
1.900 bisitz 7426: text-align: left;
1.740 bisitz 7427: vertical-align: top;
1.421 albertel 7428: width: 184px;
7429: padding: 8px;
7430: }
1.795 www 7431:
1.579 raeburn 7432: table.LC_pick_box td.LC_pick_box_value {
7433: text-align: left;
7434: padding: 8px;
7435: }
1.795 www 7436:
1.579 raeburn 7437: table.LC_pick_box td.LC_pick_box_select {
7438: text-align: left;
7439: padding: 8px;
7440: }
1.795 www 7441:
1.424 albertel 7442: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7443: padding: 0;
1.421 albertel 7444: height: 1px;
7445: background: black;
7446: }
1.795 www 7447:
1.421 albertel 7448: table.LC_pick_box td.LC_pick_box_submit {
7449: text-align: right;
7450: }
1.795 www 7451:
1.579 raeburn 7452: table.LC_pick_box td.LC_evenrow_value {
7453: text-align: left;
7454: padding: 8px;
7455: background-color: $data_table_light;
7456: }
1.795 www 7457:
1.579 raeburn 7458: table.LC_pick_box td.LC_oddrow_value {
7459: text-align: left;
7460: padding: 8px;
7461: background-color: $data_table_light;
7462: }
1.795 www 7463:
1.579 raeburn 7464: span.LC_helpform_receipt_cat {
7465: font-weight: bold;
7466: }
1.795 www 7467:
1.424 albertel 7468: table.LC_group_priv_box {
7469: background: white;
7470: border: 1px solid black;
7471: border-spacing: 1px;
7472: }
1.795 www 7473:
1.424 albertel 7474: table.LC_group_priv_box td.LC_pick_box_title {
7475: background: $tabbg;
7476: font-weight: bold;
7477: text-align: right;
7478: width: 184px;
7479: }
1.795 www 7480:
1.424 albertel 7481: table.LC_group_priv_box td.LC_groups_fixed {
7482: background: $data_table_light;
7483: text-align: center;
7484: }
1.795 www 7485:
1.424 albertel 7486: table.LC_group_priv_box td.LC_groups_optional {
7487: background: $data_table_dark;
7488: text-align: center;
7489: }
1.795 www 7490:
1.424 albertel 7491: table.LC_group_priv_box td.LC_groups_functionality {
7492: background: $data_table_darker;
7493: text-align: center;
7494: font-weight: bold;
7495: }
1.795 www 7496:
1.424 albertel 7497: table.LC_group_priv td {
7498: text-align: left;
1.803 bisitz 7499: padding: 0;
1.424 albertel 7500: }
7501:
7502: .LC_navbuttons {
7503: margin: 2ex 0ex 2ex 0ex;
7504: }
1.795 www 7505:
1.423 albertel 7506: .LC_topic_bar {
7507: font-weight: bold;
7508: background: $tabbg;
1.918 wenzelju 7509: margin: 1em 0em 1em 2em;
1.805 bisitz 7510: padding: 3px;
1.918 wenzelju 7511: font-size: 1.2em;
1.423 albertel 7512: }
1.795 www 7513:
1.423 albertel 7514: .LC_topic_bar span {
1.918 wenzelju 7515: left: 0.5em;
7516: position: absolute;
1.423 albertel 7517: vertical-align: middle;
1.918 wenzelju 7518: font-size: 1.2em;
1.423 albertel 7519: }
1.795 www 7520:
1.423 albertel 7521: table.LC_course_group_status {
7522: margin: 20px;
7523: }
1.795 www 7524:
1.423 albertel 7525: table.LC_status_selector td {
7526: vertical-align: top;
7527: text-align: center;
1.424 albertel 7528: padding: 4px;
7529: }
1.795 www 7530:
1.599 albertel 7531: div.LC_feedback_link {
1.616 albertel 7532: clear: both;
1.829 kalberla 7533: background: $sidebg;
1.779 bisitz 7534: width: 100%;
1.829 kalberla 7535: padding-bottom: 10px;
7536: border: 1px $tabbg solid;
1.833 kalberla 7537: height: 22px;
7538: line-height: 22px;
7539: padding-top: 5px;
7540: }
7541:
7542: div.LC_feedback_link img {
7543: height: 22px;
1.867 kalberla 7544: vertical-align:middle;
1.829 kalberla 7545: }
7546:
1.911 bisitz 7547: div.LC_feedback_link a {
1.829 kalberla 7548: text-decoration: none;
1.489 raeburn 7549: }
1.795 www 7550:
1.867 kalberla 7551: div.LC_comblock {
1.911 bisitz 7552: display:inline;
1.867 kalberla 7553: color:$font;
7554: font-size:90%;
7555: }
7556:
7557: div.LC_feedback_link div.LC_comblock {
7558: padding-left:5px;
7559: }
7560:
7561: div.LC_feedback_link div.LC_comblock a {
7562: color:$font;
7563: }
7564:
1.489 raeburn 7565: span.LC_feedback_link {
1.858 bisitz 7566: /* background: $feedback_link_bg; */
1.599 albertel 7567: font-size: larger;
7568: }
1.795 www 7569:
1.599 albertel 7570: span.LC_message_link {
1.858 bisitz 7571: /* background: $feedback_link_bg; */
1.599 albertel 7572: font-size: larger;
7573: position: absolute;
7574: right: 1em;
1.489 raeburn 7575: }
1.421 albertel 7576:
1.515 albertel 7577: table.LC_prior_tries {
1.524 albertel 7578: border: 1px solid #000000;
7579: border-collapse: separate;
7580: border-spacing: 1px;
1.515 albertel 7581: }
1.523 albertel 7582:
1.515 albertel 7583: table.LC_prior_tries td {
1.524 albertel 7584: padding: 2px;
1.515 albertel 7585: }
1.523 albertel 7586:
7587: .LC_answer_correct {
1.795 www 7588: background: lightgreen;
7589: color: darkgreen;
7590: padding: 6px;
1.523 albertel 7591: }
1.795 www 7592:
1.523 albertel 7593: .LC_answer_charged_try {
1.797 www 7594: background: #FFAAAA;
1.795 www 7595: color: darkred;
7596: padding: 6px;
1.523 albertel 7597: }
1.795 www 7598:
1.779 bisitz 7599: .LC_answer_not_charged_try,
1.523 albertel 7600: .LC_answer_no_grade,
7601: .LC_answer_late {
1.795 www 7602: background: lightyellow;
1.523 albertel 7603: color: black;
1.795 www 7604: padding: 6px;
1.523 albertel 7605: }
1.795 www 7606:
1.523 albertel 7607: .LC_answer_previous {
1.795 www 7608: background: lightblue;
7609: color: darkblue;
7610: padding: 6px;
1.523 albertel 7611: }
1.795 www 7612:
1.779 bisitz 7613: .LC_answer_no_message {
1.777 tempelho 7614: background: #FFFFFF;
7615: color: black;
1.795 www 7616: padding: 6px;
1.779 bisitz 7617: }
1.795 www 7618:
1.1075.2.140 raeburn 7619: .LC_answer_unknown,
7620: .LC_answer_warning {
1.779 bisitz 7621: background: orange;
7622: color: black;
1.795 www 7623: padding: 6px;
1.777 tempelho 7624: }
1.795 www 7625:
1.529 albertel 7626: span.LC_prior_numerical,
7627: span.LC_prior_string,
7628: span.LC_prior_custom,
7629: span.LC_prior_reaction,
7630: span.LC_prior_math {
1.925 bisitz 7631: font-family: $mono;
1.523 albertel 7632: white-space: pre;
7633: }
7634:
1.525 albertel 7635: span.LC_prior_string {
1.925 bisitz 7636: font-family: $mono;
1.525 albertel 7637: white-space: pre;
7638: }
7639:
1.523 albertel 7640: table.LC_prior_option {
7641: width: 100%;
7642: border-collapse: collapse;
7643: }
1.795 www 7644:
1.911 bisitz 7645: table.LC_prior_rank,
1.795 www 7646: table.LC_prior_match {
1.528 albertel 7647: border-collapse: collapse;
7648: }
1.795 www 7649:
1.528 albertel 7650: table.LC_prior_option tr td,
7651: table.LC_prior_rank tr td,
7652: table.LC_prior_match tr td {
1.524 albertel 7653: border: 1px solid #000000;
1.515 albertel 7654: }
7655:
1.855 bisitz 7656: .LC_nobreak {
1.544 albertel 7657: white-space: nowrap;
1.519 raeburn 7658: }
7659:
1.576 raeburn 7660: span.LC_cusr_emph {
7661: font-style: italic;
7662: }
7663:
1.633 raeburn 7664: span.LC_cusr_subheading {
7665: font-weight: normal;
7666: font-size: 85%;
7667: }
7668:
1.861 bisitz 7669: div.LC_docs_entry_move {
1.859 bisitz 7670: border: 1px solid #BBBBBB;
1.545 albertel 7671: background: #DDDDDD;
1.861 bisitz 7672: width: 22px;
1.859 bisitz 7673: padding: 1px;
7674: margin: 0;
1.545 albertel 7675: }
7676:
1.861 bisitz 7677: table.LC_data_table tr > td.LC_docs_entry_commands,
7678: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7679: font-size: x-small;
7680: }
1.795 www 7681:
1.861 bisitz 7682: .LC_docs_entry_parameter {
7683: white-space: nowrap;
7684: }
7685:
1.544 albertel 7686: .LC_docs_copy {
1.545 albertel 7687: color: #000099;
1.544 albertel 7688: }
1.795 www 7689:
1.544 albertel 7690: .LC_docs_cut {
1.545 albertel 7691: color: #550044;
1.544 albertel 7692: }
1.795 www 7693:
1.544 albertel 7694: .LC_docs_rename {
1.545 albertel 7695: color: #009900;
1.544 albertel 7696: }
1.795 www 7697:
1.544 albertel 7698: .LC_docs_remove {
1.545 albertel 7699: color: #990000;
7700: }
7701:
1.1075.2.134 raeburn 7702: .LC_domprefs_email,
1.547 albertel 7703: .LC_docs_reinit_warn,
7704: .LC_docs_ext_edit {
7705: font-size: x-small;
7706: }
7707:
1.545 albertel 7708: table.LC_docs_adddocs td,
7709: table.LC_docs_adddocs th {
7710: border: 1px solid #BBBBBB;
7711: padding: 4px;
7712: background: #DDDDDD;
1.543 albertel 7713: }
7714:
1.584 albertel 7715: table.LC_sty_begin {
7716: background: #BBFFBB;
7717: }
1.795 www 7718:
1.584 albertel 7719: table.LC_sty_end {
7720: background: #FFBBBB;
7721: }
7722:
1.589 raeburn 7723: table.LC_double_column {
1.803 bisitz 7724: border-width: 0;
1.589 raeburn 7725: border-collapse: collapse;
7726: width: 100%;
7727: padding: 2px;
7728: }
7729:
7730: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7731: top: 2px;
1.589 raeburn 7732: left: 2px;
7733: width: 47%;
7734: vertical-align: top;
7735: }
7736:
7737: table.LC_double_column tr td.LC_right_col {
7738: top: 2px;
1.779 bisitz 7739: right: 2px;
1.589 raeburn 7740: width: 47%;
7741: vertical-align: top;
7742: }
7743:
1.591 raeburn 7744: div.LC_left_float {
7745: float: left;
7746: padding-right: 5%;
1.597 albertel 7747: padding-bottom: 4px;
1.591 raeburn 7748: }
7749:
7750: div.LC_clear_float_header {
1.597 albertel 7751: padding-bottom: 2px;
1.591 raeburn 7752: }
7753:
7754: div.LC_clear_float_footer {
1.597 albertel 7755: padding-top: 10px;
1.591 raeburn 7756: clear: both;
7757: }
7758:
1.597 albertel 7759: div.LC_grade_show_user {
1.941 bisitz 7760: /* border-left: 5px solid $sidebg; */
7761: border-top: 5px solid #000000;
7762: margin: 50px 0 0 0;
1.936 bisitz 7763: padding: 15px 0 5px 10px;
1.597 albertel 7764: }
1.795 www 7765:
1.936 bisitz 7766: div.LC_grade_show_user_odd_row {
1.941 bisitz 7767: /* border-left: 5px solid #000000; */
7768: }
7769:
7770: div.LC_grade_show_user div.LC_Box {
7771: margin-right: 50px;
1.597 albertel 7772: }
7773:
7774: div.LC_grade_submissions,
7775: div.LC_grade_message_center,
1.936 bisitz 7776: div.LC_grade_info_links {
1.597 albertel 7777: margin: 5px;
7778: width: 99%;
7779: background: #FFFFFF;
7780: }
1.795 www 7781:
1.597 albertel 7782: div.LC_grade_submissions_header,
1.936 bisitz 7783: div.LC_grade_message_center_header {
1.705 tempelho 7784: font-weight: bold;
7785: font-size: large;
1.597 albertel 7786: }
1.795 www 7787:
1.597 albertel 7788: div.LC_grade_submissions_body,
1.936 bisitz 7789: div.LC_grade_message_center_body {
1.597 albertel 7790: border: 1px solid black;
7791: width: 99%;
7792: background: #FFFFFF;
7793: }
1.795 www 7794:
1.613 albertel 7795: table.LC_scantron_action {
7796: width: 100%;
7797: }
1.795 www 7798:
1.613 albertel 7799: table.LC_scantron_action tr th {
1.698 harmsja 7800: font-weight:bold;
7801: font-style:normal;
1.613 albertel 7802: }
1.795 www 7803:
1.779 bisitz 7804: .LC_edit_problem_header,
1.614 albertel 7805: div.LC_edit_problem_footer {
1.705 tempelho 7806: font-weight: normal;
7807: font-size: medium;
1.602 albertel 7808: margin: 2px;
1.1060 bisitz 7809: background-color: $sidebg;
1.600 albertel 7810: }
1.795 www 7811:
1.600 albertel 7812: div.LC_edit_problem_header,
1.602 albertel 7813: div.LC_edit_problem_header div,
1.614 albertel 7814: div.LC_edit_problem_footer,
7815: div.LC_edit_problem_footer div,
1.602 albertel 7816: div.LC_edit_problem_editxml_header,
7817: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7818: z-index: 100;
1.600 albertel 7819: }
1.795 www 7820:
1.600 albertel 7821: div.LC_edit_problem_header_title {
1.705 tempelho 7822: font-weight: bold;
7823: font-size: larger;
1.602 albertel 7824: background: $tabbg;
7825: padding: 3px;
1.1060 bisitz 7826: margin: 0 0 5px 0;
1.602 albertel 7827: }
1.795 www 7828:
1.602 albertel 7829: table.LC_edit_problem_header_title {
7830: width: 100%;
1.600 albertel 7831: background: $tabbg;
1.602 albertel 7832: }
7833:
1.1075.2.112 raeburn 7834: div.LC_edit_actionbar {
7835: background-color: $sidebg;
7836: margin: 0;
7837: padding: 0;
7838: line-height: 200%;
1.602 albertel 7839: }
1.795 www 7840:
1.1075.2.112 raeburn 7841: div.LC_edit_actionbar div{
7842: padding: 0;
7843: margin: 0;
7844: display: inline-block;
1.600 albertel 7845: }
1.795 www 7846:
1.1075.2.34 raeburn 7847: .LC_edit_opt {
7848: padding-left: 1em;
7849: white-space: nowrap;
7850: }
7851:
1.1075.2.57 raeburn 7852: .LC_edit_problem_latexhelper{
7853: text-align: right;
7854: }
7855:
7856: #LC_edit_problem_colorful div{
7857: margin-left: 40px;
7858: }
7859:
1.1075.2.112 raeburn 7860: #LC_edit_problem_codemirror div{
7861: margin-left: 0px;
7862: }
7863:
1.911 bisitz 7864: img.stift {
1.803 bisitz 7865: border-width: 0;
7866: vertical-align: middle;
1.677 riegler 7867: }
1.680 riegler 7868:
1.923 bisitz 7869: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7870: vertical-align: top;
1.777 tempelho 7871: }
1.795 www 7872:
1.716 raeburn 7873: div.LC_createcourse {
1.911 bisitz 7874: margin: 10px 10px 10px 10px;
1.716 raeburn 7875: }
7876:
1.917 raeburn 7877: .LC_dccid {
1.1075.2.38 raeburn 7878: float: right;
1.917 raeburn 7879: margin: 0.2em 0 0 0;
7880: padding: 0;
7881: font-size: 90%;
7882: display:none;
7883: }
7884:
1.897 wenzelju 7885: ol.LC_primary_menu a:hover,
1.721 harmsja 7886: ol#LC_MenuBreadcrumbs a:hover,
7887: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7888: ul#LC_secondary_menu a:hover,
1.721 harmsja 7889: .LC_FormSectionClearButton input:hover
1.795 www 7890: ul.LC_TabContent li:hover a {
1.952 onken 7891: color:$button_hover;
1.911 bisitz 7892: text-decoration:none;
1.693 droeschl 7893: }
7894:
1.779 bisitz 7895: h1 {
1.911 bisitz 7896: padding: 0;
7897: line-height:130%;
1.693 droeschl 7898: }
1.698 harmsja 7899:
1.911 bisitz 7900: h2,
7901: h3,
7902: h4,
7903: h5,
7904: h6 {
7905: margin: 5px 0 5px 0;
7906: padding: 0;
7907: line-height:130%;
1.693 droeschl 7908: }
1.795 www 7909:
7910: .LC_hcell {
1.911 bisitz 7911: padding:3px 15px 3px 15px;
7912: margin: 0;
7913: background-color:$tabbg;
7914: color:$fontmenu;
7915: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7916: }
1.795 www 7917:
1.840 bisitz 7918: .LC_Box > .LC_hcell {
1.911 bisitz 7919: margin: 0 -10px 10px -10px;
1.835 bisitz 7920: }
7921:
1.721 harmsja 7922: .LC_noBorder {
1.911 bisitz 7923: border: 0;
1.698 harmsja 7924: }
1.693 droeschl 7925:
1.721 harmsja 7926: .LC_FormSectionClearButton input {
1.911 bisitz 7927: background-color:transparent;
7928: border: none;
7929: cursor:pointer;
7930: text-decoration:underline;
1.693 droeschl 7931: }
1.763 bisitz 7932:
7933: .LC_help_open_topic {
1.911 bisitz 7934: color: #FFFFFF;
7935: background-color: #EEEEFF;
7936: margin: 1px;
7937: padding: 4px;
7938: border: 1px solid #000033;
7939: white-space: nowrap;
7940: /* vertical-align: middle; */
1.759 neumanie 7941: }
1.693 droeschl 7942:
1.911 bisitz 7943: dl,
7944: ul,
7945: div,
7946: fieldset {
7947: margin: 10px 10px 10px 0;
7948: /* overflow: hidden; */
1.693 droeschl 7949: }
1.795 www 7950:
1.1075.2.161. .18(raeb 7951:-23): fieldset#LC_selectuser {
7952:-23): margin: 0;
7953:-23): padding: 0;
7954:-23): }
7955:-23):
1.1075.2.90 raeburn 7956: article.geogebraweb div {
7957: margin: 0;
7958: }
7959:
1.838 bisitz 7960: fieldset > legend {
1.911 bisitz 7961: font-weight: bold;
7962: padding: 0 5px 0 5px;
1.838 bisitz 7963: }
7964:
1.813 bisitz 7965: #LC_nav_bar {
1.911 bisitz 7966: float: left;
1.995 raeburn 7967: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7968: margin: 0 0 2px 0;
1.807 droeschl 7969: }
7970:
1.916 droeschl 7971: #LC_realm {
7972: margin: 0.2em 0 0 0;
7973: padding: 0;
7974: font-weight: bold;
7975: text-align: center;
1.995 raeburn 7976: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7977: }
7978:
1.911 bisitz 7979: #LC_nav_bar em {
7980: font-weight: bold;
7981: font-style: normal;
1.807 droeschl 7982: }
7983:
1.897 wenzelju 7984: ol.LC_primary_menu {
1.934 droeschl 7985: margin: 0;
1.1075.2.2 raeburn 7986: padding: 0;
1.807 droeschl 7987: }
7988:
1.852 droeschl 7989: ol#LC_PathBreadcrumbs {
1.911 bisitz 7990: margin: 0;
1.693 droeschl 7991: }
7992:
1.897 wenzelju 7993: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7994: color: RGB(80, 80, 80);
7995: vertical-align: middle;
7996: text-align: left;
7997: list-style: none;
1.1075.2.112 raeburn 7998: position: relative;
1.1075.2.2 raeburn 7999: float: left;
1.1075.2.112 raeburn 8000: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8001: line-height: 1.5em;
1.1075.2.2 raeburn 8002: }
8003:
1.1075.2.113 raeburn 8004: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 8005: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 8006: display: block;
8007: margin: 0;
8008: padding: 0 5px 0 10px;
8009: text-decoration: none;
8010: }
8011:
1.1075.2.112 raeburn 8012: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8013: display: inline-block;
8014: width: 95%;
8015: text-align: left;
8016: }
8017:
8018: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8019: display: inline-block;
8020: width: 5%;
8021: float: right;
8022: text-align: right;
8023: font-size: 70%;
8024: }
8025:
8026: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 8027: display: none;
1.1075.2.112 raeburn 8028: width: 15em;
1.1075.2.2 raeburn 8029: background-color: $data_table_light;
1.1075.2.112 raeburn 8030: position: absolute;
8031: top: 100%;
8032: }
8033:
8034: ol.LC_primary_menu ul ul {
8035: left: 100%;
8036: top: 0;
1.1075.2.2 raeburn 8037: }
8038:
1.1075.2.112 raeburn 8039: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 8040: display: block;
8041: position: absolute;
8042: margin: 0;
8043: padding: 0;
1.1075.2.5 raeburn 8044: z-index: 2;
1.1075.2.2 raeburn 8045: }
8046:
8047: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 8048: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 8049: font-size: 90%;
1.911 bisitz 8050: vertical-align: top;
1.1075.2.2 raeburn 8051: float: none;
1.1075.2.5 raeburn 8052: border-left: 1px solid black;
8053: border-right: 1px solid black;
1.1075.2.112 raeburn 8054: /* A dark bottom border to visualize different menu options;
8055: overwritten in the create_submenu routine for the last border-bottom of the menu */
8056: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 8057: }
8058:
1.1075.2.112 raeburn 8059: ol.LC_primary_menu li li p:hover {
8060: color:$button_hover;
8061: text-decoration:none;
8062: background-color:$data_table_dark;
1.1075.2.2 raeburn 8063: }
8064:
8065: ol.LC_primary_menu li li a:hover {
8066: color:$button_hover;
8067: background-color:$data_table_dark;
1.693 droeschl 8068: }
8069:
1.1075.2.112 raeburn 8070: /* Font-size equal to the size of the predecessors*/
8071: ol.LC_primary_menu li:hover li li {
8072: font-size: 100%;
8073: }
8074:
1.897 wenzelju 8075: ol.LC_primary_menu li img {
1.911 bisitz 8076: vertical-align: bottom;
1.934 droeschl 8077: height: 1.1em;
1.1075.2.3 raeburn 8078: margin: 0.2em 0 0 0;
1.693 droeschl 8079: }
8080:
1.897 wenzelju 8081: ol.LC_primary_menu a {
1.911 bisitz 8082: color: RGB(80, 80, 80);
8083: text-decoration: none;
1.693 droeschl 8084: }
1.795 www 8085:
1.949 droeschl 8086: ol.LC_primary_menu a.LC_new_message {
8087: font-weight:bold;
8088: color: darkred;
8089: }
8090:
1.975 raeburn 8091: ol.LC_docs_parameters {
8092: margin-left: 0;
8093: padding: 0;
8094: list-style: none;
8095: }
8096:
8097: ol.LC_docs_parameters li {
8098: margin: 0;
8099: padding-right: 20px;
8100: display: inline;
8101: }
8102:
1.976 raeburn 8103: ol.LC_docs_parameters li:before {
8104: content: "\\002022 \\0020";
8105: }
8106:
8107: li.LC_docs_parameters_title {
8108: font-weight: bold;
8109: }
8110:
8111: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8112: content: "";
8113: }
8114:
1.897 wenzelju 8115: ul#LC_secondary_menu {
1.1075.2.23 raeburn 8116: clear: right;
1.911 bisitz 8117: color: $fontmenu;
8118: background: $tabbg;
8119: list-style: none;
8120: padding: 0;
8121: margin: 0;
8122: width: 100%;
1.995 raeburn 8123: text-align: left;
1.1075.2.4 raeburn 8124: float: left;
1.808 droeschl 8125: }
8126:
1.897 wenzelju 8127: ul#LC_secondary_menu li {
1.911 bisitz 8128: font-weight: bold;
8129: line-height: 1.8em;
8130: border-right: 1px solid black;
1.1075.2.4 raeburn 8131: float: left;
8132: }
8133:
8134: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8135: background-color: $data_table_light;
8136: }
8137:
8138: ul#LC_secondary_menu li a {
8139: padding: 0 0.8em;
8140: }
8141:
8142: ul#LC_secondary_menu li ul {
8143: display: none;
8144: }
8145:
8146: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8147: display: block;
8148: position: absolute;
8149: margin: 0;
8150: padding: 0;
8151: list-style:none;
8152: float: none;
8153: background-color: $data_table_light;
1.1075.2.5 raeburn 8154: z-index: 2;
1.1075.2.10 raeburn 8155: margin-left: -1px;
1.1075.2.4 raeburn 8156: }
8157:
8158: ul#LC_secondary_menu li ul li {
8159: font-size: 90%;
8160: vertical-align: top;
8161: border-left: 1px solid black;
8162: border-right: 1px solid black;
1.1075.2.33 raeburn 8163: background-color: $data_table_light;
1.1075.2.4 raeburn 8164: list-style:none;
8165: float: none;
8166: }
8167:
8168: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8169: background-color: $data_table_dark;
1.807 droeschl 8170: }
8171:
1.847 tempelho 8172: ul.LC_TabContent {
1.911 bisitz 8173: display:block;
8174: background: $sidebg;
8175: border-bottom: solid 1px $lg_border_color;
8176: list-style:none;
1.1020 raeburn 8177: margin: -1px -10px 0 -10px;
1.911 bisitz 8178: padding: 0;
1.693 droeschl 8179: }
8180:
1.795 www 8181: ul.LC_TabContent li,
8182: ul.LC_TabContentBigger li {
1.911 bisitz 8183: float:left;
1.741 harmsja 8184: }
1.795 www 8185:
1.897 wenzelju 8186: ul#LC_secondary_menu li a {
1.911 bisitz 8187: color: $fontmenu;
8188: text-decoration: none;
1.693 droeschl 8189: }
1.795 www 8190:
1.721 harmsja 8191: ul.LC_TabContent {
1.952 onken 8192: min-height:20px;
1.721 harmsja 8193: }
1.795 www 8194:
8195: ul.LC_TabContent li {
1.911 bisitz 8196: vertical-align:middle;
1.959 onken 8197: padding: 0 16px 0 10px;
1.911 bisitz 8198: background-color:$tabbg;
8199: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8200: border-left: solid 1px $font;
1.721 harmsja 8201: }
1.795 www 8202:
1.847 tempelho 8203: ul.LC_TabContent .right {
1.911 bisitz 8204: float:right;
1.847 tempelho 8205: }
8206:
1.911 bisitz 8207: ul.LC_TabContent li a,
8208: ul.LC_TabContent li {
8209: color:rgb(47,47,47);
8210: text-decoration:none;
8211: font-size:95%;
8212: font-weight:bold;
1.952 onken 8213: min-height:20px;
8214: }
8215:
1.959 onken 8216: ul.LC_TabContent li a:hover,
8217: ul.LC_TabContent li a:focus {
1.952 onken 8218: color: $button_hover;
1.959 onken 8219: background:none;
8220: outline:none;
1.952 onken 8221: }
8222:
8223: ul.LC_TabContent li:hover {
8224: color: $button_hover;
8225: cursor:pointer;
1.721 harmsja 8226: }
1.795 www 8227:
1.911 bisitz 8228: ul.LC_TabContent li.active {
1.952 onken 8229: color: $font;
1.911 bisitz 8230: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8231: border-bottom:solid 1px #FFFFFF;
8232: cursor: default;
1.744 ehlerst 8233: }
1.795 www 8234:
1.959 onken 8235: ul.LC_TabContent li.active a {
8236: color:$font;
8237: background:#FFFFFF;
8238: outline: none;
8239: }
1.1047 raeburn 8240:
8241: ul.LC_TabContent li.goback {
8242: float: left;
8243: border-left: none;
8244: }
8245:
1.870 tempelho 8246: #maincoursedoc {
1.911 bisitz 8247: clear:both;
1.870 tempelho 8248: }
8249:
8250: ul.LC_TabContentBigger {
1.911 bisitz 8251: display:block;
8252: list-style:none;
8253: padding: 0;
1.870 tempelho 8254: }
8255:
1.795 www 8256: ul.LC_TabContentBigger li {
1.911 bisitz 8257: vertical-align:bottom;
8258: height: 30px;
8259: font-size:110%;
8260: font-weight:bold;
8261: color: #737373;
1.841 tempelho 8262: }
8263:
1.957 onken 8264: ul.LC_TabContentBigger li.active {
8265: position: relative;
8266: top: 1px;
8267: }
8268:
1.870 tempelho 8269: ul.LC_TabContentBigger li a {
1.911 bisitz 8270: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8271: height: 30px;
8272: line-height: 30px;
8273: text-align: center;
8274: display: block;
8275: text-decoration: none;
1.958 onken 8276: outline: none;
1.741 harmsja 8277: }
1.795 www 8278:
1.870 tempelho 8279: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8280: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8281: color:$font;
1.744 ehlerst 8282: }
1.795 www 8283:
1.870 tempelho 8284: ul.LC_TabContentBigger li b {
1.911 bisitz 8285: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8286: display: block;
8287: float: left;
8288: padding: 0 30px;
1.957 onken 8289: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8290: }
8291:
1.956 onken 8292: ul.LC_TabContentBigger li:hover b {
8293: color:$button_hover;
8294: }
8295:
1.870 tempelho 8296: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8297: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8298: color:$font;
1.957 onken 8299: border: 0;
1.741 harmsja 8300: }
1.693 droeschl 8301:
1.870 tempelho 8302:
1.862 bisitz 8303: ul.LC_CourseBreadcrumbs {
8304: background: $sidebg;
1.1020 raeburn 8305: height: 2em;
1.862 bisitz 8306: padding-left: 10px;
1.1020 raeburn 8307: margin: 0;
1.862 bisitz 8308: list-style-position: inside;
8309: }
8310:
1.911 bisitz 8311: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8312: ol#LC_PathBreadcrumbs {
1.911 bisitz 8313: padding-left: 10px;
8314: margin: 0;
1.933 droeschl 8315: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8316: }
8317:
1.911 bisitz 8318: ol#LC_MenuBreadcrumbs li,
8319: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8320: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8321: display: inline;
1.933 droeschl 8322: white-space: normal;
1.693 droeschl 8323: }
8324:
1.823 bisitz 8325: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8326: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8327: text-decoration: none;
8328: font-size:90%;
1.693 droeschl 8329: }
1.795 www 8330:
1.969 droeschl 8331: ol#LC_MenuBreadcrumbs h1 {
8332: display: inline;
8333: font-size: 90%;
8334: line-height: 2.5em;
8335: margin: 0;
8336: padding: 0;
8337: }
8338:
1.795 www 8339: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8340: text-decoration:none;
8341: font-size:100%;
8342: font-weight:bold;
1.693 droeschl 8343: }
1.795 www 8344:
1.840 bisitz 8345: .LC_Box {
1.911 bisitz 8346: border: solid 1px $lg_border_color;
8347: padding: 0 10px 10px 10px;
1.746 neumanie 8348: }
1.795 www 8349:
1.1020 raeburn 8350: .LC_DocsBox {
8351: border: solid 1px $lg_border_color;
8352: padding: 0 0 10px 10px;
8353: }
8354:
1.795 www 8355: .LC_AboutMe_Image {
1.911 bisitz 8356: float:left;
8357: margin-right:10px;
1.747 neumanie 8358: }
1.795 www 8359:
8360: .LC_Clear_AboutMe_Image {
1.911 bisitz 8361: clear:left;
1.747 neumanie 8362: }
1.795 www 8363:
1.721 harmsja 8364: dl.LC_ListStyleClean dt {
1.911 bisitz 8365: padding-right: 5px;
8366: display: table-header-group;
1.693 droeschl 8367: }
8368:
1.721 harmsja 8369: dl.LC_ListStyleClean dd {
1.911 bisitz 8370: display: table-row;
1.693 droeschl 8371: }
8372:
1.721 harmsja 8373: .LC_ListStyleClean,
8374: .LC_ListStyleSimple,
8375: .LC_ListStyleNormal,
1.795 www 8376: .LC_ListStyleSpecial {
1.911 bisitz 8377: /* display:block; */
8378: list-style-position: inside;
8379: list-style-type: none;
8380: overflow: hidden;
8381: padding: 0;
1.693 droeschl 8382: }
8383:
1.721 harmsja 8384: .LC_ListStyleSimple li,
8385: .LC_ListStyleSimple dd,
8386: .LC_ListStyleNormal li,
8387: .LC_ListStyleNormal dd,
8388: .LC_ListStyleSpecial li,
1.795 www 8389: .LC_ListStyleSpecial dd {
1.911 bisitz 8390: margin: 0;
8391: padding: 5px 5px 5px 10px;
8392: clear: both;
1.693 droeschl 8393: }
8394:
1.721 harmsja 8395: .LC_ListStyleClean li,
8396: .LC_ListStyleClean dd {
1.911 bisitz 8397: padding-top: 0;
8398: padding-bottom: 0;
1.693 droeschl 8399: }
8400:
1.721 harmsja 8401: .LC_ListStyleSimple dd,
1.795 www 8402: .LC_ListStyleSimple li {
1.911 bisitz 8403: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8404: }
8405:
1.721 harmsja 8406: .LC_ListStyleSpecial li,
8407: .LC_ListStyleSpecial dd {
1.911 bisitz 8408: list-style-type: none;
8409: background-color: RGB(220, 220, 220);
8410: margin-bottom: 4px;
1.693 droeschl 8411: }
8412:
1.721 harmsja 8413: table.LC_SimpleTable {
1.911 bisitz 8414: margin:5px;
8415: border:solid 1px $lg_border_color;
1.795 www 8416: }
1.693 droeschl 8417:
1.721 harmsja 8418: table.LC_SimpleTable tr {
1.911 bisitz 8419: padding: 0;
8420: border:solid 1px $lg_border_color;
1.693 droeschl 8421: }
1.795 www 8422:
8423: table.LC_SimpleTable thead {
1.911 bisitz 8424: background:rgb(220,220,220);
1.693 droeschl 8425: }
8426:
1.721 harmsja 8427: div.LC_columnSection {
1.911 bisitz 8428: display: block;
8429: clear: both;
8430: overflow: hidden;
8431: margin: 0;
1.693 droeschl 8432: }
8433:
1.721 harmsja 8434: div.LC_columnSection>* {
1.911 bisitz 8435: float: left;
8436: margin: 10px 20px 10px 0;
8437: overflow:hidden;
1.693 droeschl 8438: }
1.721 harmsja 8439:
1.795 www 8440: table em {
1.911 bisitz 8441: font-weight: bold;
8442: font-style: normal;
1.748 schulted 8443: }
1.795 www 8444:
1.779 bisitz 8445: table.LC_tableBrowseRes,
1.795 www 8446: table.LC_tableOfContent {
1.911 bisitz 8447: border:none;
8448: border-spacing: 1px;
8449: padding: 3px;
8450: background-color: #FFFFFF;
8451: font-size: 90%;
1.753 droeschl 8452: }
1.789 droeschl 8453:
1.911 bisitz 8454: table.LC_tableOfContent {
8455: border-collapse: collapse;
1.789 droeschl 8456: }
8457:
1.771 droeschl 8458: table.LC_tableBrowseRes a,
1.768 schulted 8459: table.LC_tableOfContent a {
1.911 bisitz 8460: background-color: transparent;
8461: text-decoration: none;
1.753 droeschl 8462: }
8463:
1.795 www 8464: table.LC_tableOfContent img {
1.911 bisitz 8465: border: none;
8466: height: 1.3em;
8467: vertical-align: text-bottom;
8468: margin-right: 0.3em;
1.753 droeschl 8469: }
1.757 schulted 8470:
1.795 www 8471: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8472: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8473: }
8474:
1.795 www 8475: a#LC_content_toolbar_everything {
1.911 bisitz 8476: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8477: }
8478:
1.795 www 8479: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8480: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8481: }
8482:
1.795 www 8483: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8484: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8485: }
8486:
1.795 www 8487: a#LC_content_toolbar_changefolder {
1.911 bisitz 8488: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8489: }
8490:
1.795 www 8491: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8492: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8493: }
8494:
1.1043 raeburn 8495: a#LC_content_toolbar_edittoplevel {
8496: background-image:url(/res/adm/pages/edittoplevel.gif);
8497: }
8498:
1.1075.2.161. .12(raeb 8499:-23): a#LC_content_toolbar_printout {
8500:-23): background-image:url(/res/adm/pages/printout.gif);
8501:-23): }
8502:-23):
1.795 www 8503: ul#LC_toolbar li a:hover {
1.911 bisitz 8504: background-position: bottom center;
1.757 schulted 8505: }
8506:
1.795 www 8507: ul#LC_toolbar {
1.911 bisitz 8508: padding: 0;
8509: margin: 2px;
8510: list-style:none;
8511: position:relative;
8512: background-color:white;
1.1075.2.9 raeburn 8513: overflow: auto;
1.757 schulted 8514: }
8515:
1.795 www 8516: ul#LC_toolbar li {
1.911 bisitz 8517: border:1px solid white;
8518: padding: 0;
8519: margin: 0;
8520: float: left;
8521: display:inline;
8522: vertical-align:middle;
1.1075.2.9 raeburn 8523: white-space: nowrap;
1.911 bisitz 8524: }
1.757 schulted 8525:
1.783 amueller 8526:
1.795 www 8527: a.LC_toolbarItem {
1.911 bisitz 8528: display:block;
8529: padding: 0;
8530: margin: 0;
8531: height: 32px;
8532: width: 32px;
8533: color:white;
8534: border: none;
8535: background-repeat:no-repeat;
8536: background-color:transparent;
1.757 schulted 8537: }
8538:
1.915 droeschl 8539: ul.LC_funclist {
8540: margin: 0;
8541: padding: 0.5em 1em 0.5em 0;
8542: }
8543:
1.933 droeschl 8544: ul.LC_funclist > li:first-child {
8545: font-weight:bold;
8546: margin-left:0.8em;
8547: }
8548:
1.915 droeschl 8549: ul.LC_funclist + ul.LC_funclist {
8550: /*
8551: left border as a seperator if we have more than
8552: one list
8553: */
8554: border-left: 1px solid $sidebg;
8555: /*
8556: this hides the left border behind the border of the
8557: outer box if element is wrapped to the next 'line'
8558: */
8559: margin-left: -1px;
8560: }
8561:
1.843 bisitz 8562: ul.LC_funclist li {
1.915 droeschl 8563: display: inline;
1.782 bisitz 8564: white-space: nowrap;
1.915 droeschl 8565: margin: 0 0 0 25px;
8566: line-height: 150%;
1.782 bisitz 8567: }
8568:
1.974 wenzelju 8569: .LC_hidden {
8570: display: none;
8571: }
8572:
1.1030 www 8573: .LCmodal-overlay {
8574: position:fixed;
8575: top:0;
8576: right:0;
8577: bottom:0;
8578: left:0;
8579: height:100%;
8580: width:100%;
8581: margin:0;
8582: padding:0;
8583: background:#999;
8584: opacity:.75;
8585: filter: alpha(opacity=75);
8586: -moz-opacity: 0.75;
8587: z-index:101;
8588: }
8589:
8590: * html .LCmodal-overlay {
8591: position: absolute;
8592: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8593: }
8594:
8595: .LCmodal-window {
8596: position:fixed;
8597: top:50%;
8598: left:50%;
8599: margin:0;
8600: padding:0;
8601: z-index:102;
8602: }
8603:
8604: * html .LCmodal-window {
8605: position:absolute;
8606: }
8607:
8608: .LCclose-window {
8609: position:absolute;
8610: width:32px;
8611: height:32px;
8612: right:8px;
8613: top:8px;
8614: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8615: text-indent:-99999px;
8616: overflow:hidden;
8617: cursor:pointer;
8618: }
8619:
1.1075.2.158 raeburn 8620: .LCisDisabled {
8621: cursor: not-allowed;
8622: opacity: 0.5;
8623: }
8624:
8625: a[aria-disabled="true"] {
8626: color: currentColor;
8627: display: inline-block; /* For IE11/ MS Edge bug */
8628: pointer-events: none;
8629: text-decoration: none;
8630: }
8631:
1.1075.2.141 raeburn 8632: pre.LC_wordwrap {
8633: white-space: pre-wrap;
8634: white-space: -moz-pre-wrap;
8635: white-space: -pre-wrap;
8636: white-space: -o-pre-wrap;
8637: word-wrap: break-word;
8638: }
8639:
1.1075.2.17 raeburn 8640: /*
1.1075.2.161. .21(raeb 8641:-24): styles used for response display
8642:-24): */
8643:-24): div.LC_radiofoil, div.LC_rankfoil {
8644:-24): margin: .5em 0em .5em 0em;
8645:-24): }
8646:-24): table.LC_itemgroup {
8647:-24): margin-top: 1em;
8648:-24): }
8649:-24):
8650:-24): /*
1.1075.2.17 raeburn 8651: styles used by TTH when "Default set of options to pass to tth/m
8652: when converting TeX" in course settings has been set
8653:
8654: option passed: -t
8655:
8656: */
8657:
8658: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8659: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8660: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8661: td div.norm {line-height:normal;}
8662:
8663: /*
8664: option passed -y3
8665: */
8666:
8667: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8668: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8669: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8670:
1.1075.2.161. .21(raeb 8671:-24): /*
8672:-24): sections with roles, for content only
8673:-24): */
8674:-24): section[class^="role-"] {
8675:-24): padding-left: 10px;
8676:-24): padding-right: 5px;
8677:-24): margin-top: 8px;
8678:-24): margin-bottom: 8px;
8679:-24): border: 1px solid #2A4;
8680:-24): border-radius: 5px;
8681:-24): box-shadow: 0px 1px 1px #BBB;
8682:-24): }
8683:-24): section[class^="role-"]>h1 {
8684:-24): position: relative;
8685:-24): margin: 0px;
8686:-24): padding-top: 10px;
8687:-24): padding-left: 40px;
8688:-24): }
8689:-24): section[class^="role-"]>h1:before {
8690:-24): position: absolute;
8691:-24): left: -5px;
8692:-24): top: 5px;
8693:-24): }
8694:-24): section.role-activity>h1:before {
8695:-24): content:url('/adm/daxe/images/section_icons/activity.png');
8696:-24): }
8697:-24): section.role-advice>h1:before {
8698:-24): content:url('/adm/daxe/images/section_icons/advice.png');
8699:-24): }
8700:-24): section.role-bibliography>h1:before {
8701:-24): content:url('/adm/daxe/images/section_icons/bibliography.png');
8702:-24): }
8703:-24): section.role-citation>h1:before {
8704:-24): content:url('/adm/daxe/images/section_icons/citation.png');
8705:-24): }
8706:-24): section.role-conclusion>h1:before {
8707:-24): content:url('/adm/daxe/images/section_icons/conclusion.png');
8708:-24): }
8709:-24): section.role-definition>h1:before {
8710:-24): content:url('/adm/daxe/images/section_icons/definition.png');
8711:-24): }
8712:-24): section.role-demonstration>h1:before {
8713:-24): content:url('/adm/daxe/images/section_icons/demonstration.png');
8714:-24): }
8715:-24): section.role-example>h1:before {
8716:-24): content:url('/adm/daxe/images/section_icons/example.png');
8717:-24): }
8718:-24): section.role-explanation>h1:before {
8719:-24): content:url('/adm/daxe/images/section_icons/explanation.png');
8720:-24): }
8721:-24): section.role-introduction>h1:before {
8722:-24): content:url('/adm/daxe/images/section_icons/introduction.png');
8723:-24): }
8724:-24): section.role-method>h1:before {
8725:-24): content:url('/adm/daxe/images/section_icons/method.png');
8726:-24): }
8727:-24): section.role-more_information>h1:before {
8728:-24): content:url('/adm/daxe/images/section_icons/more_information.png');
8729:-24): }
8730:-24): section.role-objectives>h1:before {
8731:-24): content:url('/adm/daxe/images/section_icons/objectives.png');
8732:-24): }
8733:-24): section.role-prerequisites>h1:before {
8734:-24): content:url('/adm/daxe/images/section_icons/prerequisites.png');
8735:-24): }
8736:-24): section.role-remark>h1:before {
8737:-24): content:url('/adm/daxe/images/section_icons/remark.png');
8738:-24): }
8739:-24): section.role-reminder>h1:before {
8740:-24): content:url('/adm/daxe/images/section_icons/reminder.png');
8741:-24): }
8742:-24): section.role-summary>h1:before {
8743:-24): content:url('/adm/daxe/images/section_icons/summary.png');
8744:-24): }
8745:-24): section.role-syntax>h1:before {
8746:-24): content:url('/adm/daxe/images/section_icons/syntax.png');
8747:-24): }
8748:-24): section.role-warning>h1:before {
8749:-24): content:url('/adm/daxe/images/section_icons/warning.png');
8750:-24): }
8751:-24):
1.1075.2.121 raeburn 8752: #LC_minitab_header {
8753: float:left;
8754: width:100%;
8755: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8756: font-size:93%;
8757: line-height:normal;
8758: margin: 0.5em 0 0.5em 0;
8759: }
8760: #LC_minitab_header ul {
8761: margin:0;
8762: padding:10px 10px 0;
8763: list-style:none;
8764: }
8765: #LC_minitab_header li {
8766: float:left;
8767: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8768: margin:0;
8769: padding:0 0 0 9px;
8770: }
8771: #LC_minitab_header a {
8772: display:block;
8773: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8774: padding:5px 15px 4px 6px;
8775: }
8776: #LC_minitab_header #LC_current_minitab {
8777: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8778: }
8779: #LC_minitab_header #LC_current_minitab a {
8780: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8781: padding-bottom:5px;
8782: }
8783:
8784:
1.343 albertel 8785: END
8786: }
8787:
1.306 albertel 8788: =pod
8789:
8790: =item * &headtag()
8791:
8792: Returns a uniform footer for LON-CAPA web pages.
8793:
1.307 albertel 8794: Inputs: $title - optional title for the head
8795: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8796: $args - optional arguments
1.319 albertel 8797: force_register - if is true call registerurl so the remote is
8798: informed
1.415 albertel 8799: redirect -> array ref of
8800: 1- seconds before redirect occurs
8801: 2- url to redirect to
8802: 3- whether the side effect should occur
1.315 albertel 8803: (side effect of setting
8804: $env{'internal.head.redirect'} to the url
1.1075.2.161. .9(raebu 8805:22): redirected to)
8806:22): 4- whether the redirect target should be
8807:22): the opener of the current (pop-up)
8808:22): window (side effect of setting
8809:22): $env{'internal.head.to_opener'} to
8810:22): 1, if true.
.10(raeb 8811:-22): 5- whether encrypt check should be skipped
1.352 albertel 8812: domain -> force to color decorate a page for a specific
8813: domain
8814: function -> force usage of a specific rolish color scheme
8815: bgcolor -> override the default page bgcolor
1.460 albertel 8816: no_auto_mt_title
8817: -> prevent &mt()ing the title arg
1.464 albertel 8818:
1.306 albertel 8819: =cut
8820:
8821: sub headtag {
1.313 albertel 8822: my ($title,$head_extra,$args) = @_;
1.306 albertel 8823:
1.363 albertel 8824: my $function = $args->{'function'} || &get_users_function();
8825: my $domain = $args->{'domain'} || &determinedomain();
8826: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8827: my $httphost = $args->{'use_absolute'};
1.418 albertel 8828: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8829: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8830: #time(),
1.418 albertel 8831: $env{'environment.color.timestamp'},
1.363 albertel 8832: $function,$domain,$bgcolor);
8833:
1.369 www 8834: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8835:
1.308 albertel 8836: my $result =
8837: '<head>'.
1.1075.2.56 raeburn 8838: &font_settings($args);
1.319 albertel 8839:
1.1075.2.72 raeburn 8840: my $inhibitprint;
8841: if ($args->{'print_suppress'}) {
8842: $inhibitprint = &print_suppression();
8843: }
1.1064 raeburn 8844:
1.461 albertel 8845: if (!$args->{'frameset'}) {
8846: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8847: }
1.1075.2.12 raeburn 8848: if ($args->{'force_register'}) {
8849: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8850: }
1.436 albertel 8851: if (!$args->{'no_nav_bar'}
8852: && !$args->{'only_body'}
8853: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8854: $result .= &help_menu_js($httphost);
1.1032 www 8855: $result.=&modal_window();
1.1038 www 8856: $result.=&togglebox_script();
1.1034 www 8857: $result.=&wishlist_window();
1.1041 www 8858: $result.=&LCprogressbarUpdate_script();
1.1034 www 8859: } else {
8860: if ($args->{'add_modal'}) {
8861: $result.=&modal_window();
8862: }
8863: if ($args->{'add_wishlist'}) {
8864: $result.=&wishlist_window();
8865: }
1.1038 www 8866: if ($args->{'add_togglebox'}) {
8867: $result.=&togglebox_script();
8868: }
1.1041 www 8869: if ($args->{'add_progressbar'}) {
8870: $result.=&LCprogressbarUpdate_script();
8871: }
1.436 albertel 8872: }
1.314 albertel 8873: if (ref($args->{'redirect'})) {
1.1075.2.161. .10(raeb 8874:-22): my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
8875:-22): if (!$skip_enc_check) {
8876:-22): $url = &Apache::lonenc::check_encrypt($url);
8877:-22): }
1.414 albertel 8878: if (!$inhibit_continue) {
8879: $env{'internal.head.redirect'} = $url;
8880: }
1.1075.2.161. .9(raebu 8881:22): $result.=<<"ADDMETA";
1.313 albertel 8882: <meta http-equiv="pragma" content="no-cache" />
1.1075.2.161. .9(raebu 8883:22): ADDMETA
8884:22): if ($to_opener) {
8885:22): $env{'internal.head.to_opener'} = 1;
8886:22): my $dest = &js_escape($url);
8887:22): my $timeout = int($time * 1000);
8888:22): $result .=<<"ENDJS";
8889:22): <script type="text/javascript">
8890:22): // <![CDATA[
8891:22): function LC_To_Opener() {
8892:22): var dest = '$dest';
8893:22): if (dest != '') {
8894:22): if (window.opener != null && !window.opener.closed) {
8895:22): window.opener.location.href=dest;
8896:22): window.close();
8897:22): } else {
8898:22): window.location.href=dest;
8899:22): }
8900:22): }
8901:22): }
8902:22): \$(document).ready(function () {
8903:22): setTimeout('LC_To_Opener()',$timeout);
8904:22): });
8905:22): // ]]>
8906:22): </script>
8907:22): ENDJS
8908:22): } else {
8909:22): $result.=<<"ADDMETA";
1.344 albertel 8910: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8911: ADDMETA
1.1075.2.161. .9(raebu 8912:22): }
1.1075.2.89 raeburn 8913: } else {
8914: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8915: my $requrl = $env{'request.uri'};
8916: if ($requrl eq '') {
8917: $requrl = $ENV{'REQUEST_URI'};
8918: $requrl =~ s/\?.+$//;
8919: }
8920: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8921: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8922: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8923: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8924: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8925: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8926: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8927: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8928: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8929: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8930: $offload = 1;
1.1075.2.151 raeburn 8931: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8932: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8933: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8934: $offloadoth = 1;
8935: $dom_in_use = $env{'user.domain'};
8936: }
8937: }
1.1075.2.145 raeburn 8938: }
8939: }
8940: unless ($offload) {
8941: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8942: if ($domdefs{'offloadoth'}{$lonhost}) {
8943: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8944: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8945: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8946: $offload = 1;
1.1075.2.151 raeburn 8947: $offloadoth = 1;
1.1075.2.145 raeburn 8948: $dom_in_use = $env{'user.domain'};
8949: }
1.1075.2.89 raeburn 8950: }
1.1075.2.145 raeburn 8951: }
8952: }
8953: }
8954: if ($offload) {
1.1075.2.158 raeburn 8955: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8956: if (($newserver eq '') && ($offloadoth)) {
8957: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 8958:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 8959: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8960: }
8961: }
1.1075.2.145 raeburn 8962: if (($newserver) && ($newserver ne $lonhost)) {
8963: my $numsec = 5;
8964: my $timeout = $numsec * 1000;
8965: my ($newurl,$locknum,%locks,$msg);
8966: if ($env{'request.role.adv'}) {
8967: ($locknum,%locks) = &Apache::lonnet::get_locks();
8968: }
8969: my $disable_submit = 0;
8970: if ($requrl =~ /$LONCAPA::assess_re/) {
8971: $disable_submit = 1;
8972: }
8973: if ($locknum) {
8974: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8975: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8976: join(", ",sort(values(%locks)))."\n";
8977: if (&show_course()) {
8978: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8979: } else {
1.1075.2.145 raeburn 8980: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8981: }
8982: } else {
8983: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8984: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8985: }
8986: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8987: $newurl = '/adm/switchserver?otherserver='.$newserver;
8988: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8989: $newurl .= '&role='.$env{'request.role'};
8990: }
8991: if ($env{'request.symb'}) {
8992: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8993: if ($shownsymb =~ m{^/enc/}) {
8994: my $reqdmajor = 2;
8995: my $reqdminor = 11;
8996: my $reqdsubminor = 3;
8997: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8998: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8999: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9000: if (($major eq '' && $minor eq '') ||
9001: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9002: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9003: ($reqdsubminor > $subminor))))) {
9004: undef($shownsymb);
9005: }
1.1075.2.89 raeburn 9006: }
1.1075.2.145 raeburn 9007: if ($shownsymb) {
9008: &js_escape(\$shownsymb);
9009: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 9010: }
1.1075.2.145 raeburn 9011: } else {
9012: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9013: &js_escape(\$shownurl);
9014: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 9015: }
1.1075.2.145 raeburn 9016: }
9017: &js_escape(\$msg);
9018: $result.=<<OFFLOAD
1.1075.2.89 raeburn 9019: <meta http-equiv="pragma" content="no-cache" />
9020: <script type="text/javascript">
1.1075.2.92 raeburn 9021: // <![CDATA[
1.1075.2.89 raeburn 9022: function LC_Offload_Now() {
9023: var dest = "$newurl";
9024: if (dest != '') {
9025: window.location.href="$newurl";
9026: }
9027: }
1.1075.2.92 raeburn 9028: \$(document).ready(function () {
9029: window.alert('$msg');
9030: if ($disable_submit) {
1.1075.2.89 raeburn 9031: \$(".LC_hwk_submit").prop("disabled", true);
9032: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 9033: }
9034: setTimeout('LC_Offload_Now()', $timeout);
9035: });
9036: // ]]>
1.1075.2.89 raeburn 9037: </script>
9038: OFFLOAD
9039: }
9040: }
9041: }
9042: }
9043: }
1.313 albertel 9044: }
1.306 albertel 9045: if (!defined($title)) {
9046: $title = 'The LearningOnline Network with CAPA';
9047: }
1.460 albertel 9048: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9049: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 9050: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9051: if (!$args->{'frameset'}) {
9052: $result .= ' /';
9053: }
9054: $result .= '>'
1.1064 raeburn 9055: .$inhibitprint
1.414 albertel 9056: .$head_extra;
1.1075.2.108 raeburn 9057: my $clientmobile;
9058: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9059: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9060: } else {
9061: $clientmobile = $env{'browser.mobile'};
9062: }
9063: if ($clientmobile) {
1.1075.2.42 raeburn 9064: $result .= '
9065: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9066: <meta name="apple-mobile-web-app-capable" content="yes" />';
9067: }
1.1075.2.126 raeburn 9068: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9069: return $result.'</head>';
1.306 albertel 9070: }
9071:
9072: =pod
9073:
1.340 albertel 9074: =item * &font_settings()
9075:
9076: Returns neccessary <meta> to set the proper encoding
9077:
1.1075.2.56 raeburn 9078: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9079:
9080: =cut
9081:
9082: sub font_settings {
1.1075.2.56 raeburn 9083: my ($args) = @_;
1.340 albertel 9084: my $headerstring='';
1.1075.2.56 raeburn 9085: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9086: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 9087: $headerstring.=
1.1075.2.61 raeburn 9088: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9089: if (!$args->{'frameset'}) {
9090: $headerstring.= ' /';
9091: }
9092: $headerstring .= '>'."\n";
1.340 albertel 9093: }
9094: return $headerstring;
9095: }
9096:
1.341 albertel 9097: =pod
9098:
1.1064 raeburn 9099: =item * &print_suppression()
9100:
9101: In course context returns css which causes the body to be blank when media="print",
9102: if printout generation is unavailable for the current resource.
9103:
9104: This could be because:
9105:
9106: (a) printstartdate is in the future
9107:
9108: (b) printenddate is in the past
9109:
9110: (c) there is an active exam block with "printout"
9111: functionality blocked
9112:
9113: Users with pav, pfo or evb privileges are exempt.
9114:
9115: Inputs: none
9116:
9117: =cut
9118:
9119:
9120: sub print_suppression {
9121: my $noprint;
9122: if ($env{'request.course.id'}) {
9123: my $scope = $env{'request.course.id'};
9124: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9125: (&Apache::lonnet::allowed('pfo',$scope))) {
9126: return;
9127: }
9128: if ($env{'request.course.sec'} ne '') {
9129: $scope .= "/$env{'request.course.sec'}";
9130: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9131: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9132: return;
1.1064 raeburn 9133: }
9134: }
9135: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9136: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 9137: my $clientip = &Apache::lonnet::get_requestor_ip();
9138: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9139: if ($blocked) {
9140: my $checkrole = "cm./$cdom/$cnum";
9141: if ($env{'request.course.sec'} ne '') {
9142: $checkrole .= "/$env{'request.course.sec'}";
9143: }
9144: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9145: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9146: $noprint = 1;
9147: }
9148: }
9149: unless ($noprint) {
9150: my $symb = &Apache::lonnet::symbread();
9151: if ($symb ne '') {
9152: my $navmap = Apache::lonnavmaps::navmap->new();
9153: if (ref($navmap)) {
9154: my $res = $navmap->getBySymb($symb);
9155: if (ref($res)) {
9156: if (!$res->resprintable()) {
9157: $noprint = 1;
9158: }
9159: }
9160: }
9161: }
9162: }
9163: if ($noprint) {
9164: return <<"ENDSTYLE";
9165: <style type="text/css" media="print">
9166: body { display:none }
9167: </style>
9168: ENDSTYLE
9169: }
9170: }
9171: return;
9172: }
9173:
9174: =pod
9175:
1.341 albertel 9176: =item * &xml_begin()
9177:
9178: Returns the needed doctype and <html>
9179:
9180: Inputs: none
9181:
9182: =cut
9183:
9184: sub xml_begin {
1.1075.2.61 raeburn 9185: my ($is_frameset) = @_;
1.341 albertel 9186: my $output='';
9187:
9188: if ($env{'browser.mathml'}) {
9189: $output='<?xml version="1.0"?>'
9190: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9191: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9192:
9193: # .'<!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">] >'
9194: .'<!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">'
9195: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9196: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 9197: } elsif ($is_frameset) {
9198: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9199: '<html>'."\n";
1.341 albertel 9200: } else {
1.1075.2.61 raeburn 9201: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9202: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9203: }
9204: return $output;
9205: }
1.340 albertel 9206:
9207: =pod
9208:
1.306 albertel 9209: =item * &start_page()
9210:
9211: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9212:
1.648 raeburn 9213: Inputs:
9214:
9215: =over 4
9216:
9217: $title - optional title for the page
9218:
9219: $head_extra - optional extra HTML to incude inside the <head>
9220:
9221: $args - additional optional args supported are:
9222:
9223: =over 8
9224:
9225: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9226: arg on
1.814 bisitz 9227: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9228: add_entries -> additional attributes to add to the <body>
9229: domain -> force to color decorate a page for a
1.317 albertel 9230: specific domain
1.648 raeburn 9231: function -> force usage of a specific rolish color
1.317 albertel 9232: scheme
1.648 raeburn 9233: redirect -> see &headtag()
9234: bgcolor -> override the default page bg color
9235: js_ready -> return a string ready for being used in
1.317 albertel 9236: a javascript writeln
1.648 raeburn 9237: html_encode -> return a string ready for being used in
1.320 albertel 9238: a html attribute
1.648 raeburn 9239: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9240: $forcereg arg
1.648 raeburn 9241: frameset -> if true will start with a <frameset>
1.330 albertel 9242: rather than <body>
1.648 raeburn 9243: skip_phases -> hash ref of
1.338 albertel 9244: head -> skip the <html><head> generation
9245: body -> skip all <body> generation
1.1075.2.12 raeburn 9246: no_inline_link -> if true and in remote mode, don't show the
9247: 'Switch To Inline Menu' link
1.648 raeburn 9248: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9249: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9250: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 9251: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9252: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 9253: group -> includes the current group, if page is for a
9254: specific group
1.1075.2.133 raeburn 9255: use_absolute -> for request for external resource or syllabus, this
9256: will contain https://<hostname> if server uses
9257: https (as per hosts.tab), but request is for http
9258: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 9259: links_disabled -> Links in primary and secondary menus are disabled
9260: (Can enable them once page has loaded - see lonroles.pm
9261: for an example).
1.1075.2.161. .6(raebu 9262:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9263:
1.648 raeburn 9264: =back
1.460 albertel 9265:
1.648 raeburn 9266: =back
1.562 albertel 9267:
1.306 albertel 9268: =cut
9269:
9270: sub start_page {
1.309 albertel 9271: my ($title,$head_extra,$args) = @_;
1.318 albertel 9272: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9273:
1.315 albertel 9274: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 9275:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9276:
1.338 albertel 9277: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 9278: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9279: }
1.1075.2.161. .1(raebu 9280:21):
9281:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
9282:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9283:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9284:21): $args->{'no_primary_menu'} = 1;
9285:21): }
9286:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9287:21): $args->{'no_inline_menu'} = 1;
9288:21): }
9289:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9290:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9291:21): }
9292:21): } else {
9293:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9294:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9295:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9296:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9297:21): $args->{'no_primary_menu'} = 1;
9298:21): }
9299:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9300:21): $args->{'no_inline_menu'} = 1;
9301:21): }
9302:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9303:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9304:21): }
9305:21): }
9306:21): }
9307:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9308:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
9309:21): $env{'course.'.$env{'request.course.id'}.'.num'});
9310:21): } elsif ($env{'request.course.id'}) {
9311:21): my $expiretime=600;
9312:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9313:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9314:21): }
9315:21): my ($deeplinkmenu,$menuref);
9316:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9317:21): if ($menucoll) {
9318:21): if (ref($menuref) eq 'HASH') {
9319:21): %menu = %{$menuref};
9320:21): }
9321:21): if ($menu{'top'} eq 'n') {
9322:21): $args->{'no_primary_menu'} = 1;
9323:21): }
9324:21): if ($menu{'inline'} eq 'n') {
9325:21): unless (&Apache::lonnet::allowed('opa')) {
9326:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9327:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9328:21): my $crstype = &course_type();
9329:21): my $now = time;
9330:21): my $ccrole;
9331:21): if ($crstype eq 'Community') {
9332:21): $ccrole = 'co';
9333:21): } else {
9334:21): $ccrole = 'cc';
9335:21): }
9336:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9337:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9338:21): if ((($start) && ($start<0)) ||
9339:21): (($end) && ($end<$now)) ||
9340:21): (($start) && ($now<$start))) {
9341:21): $args->{'no_inline_menu'} = 1;
9342:21): }
9343:21): } else {
9344:21): $args->{'no_inline_menu'} = 1;
9345:21): }
9346:21): }
9347:21): }
9348:21): }
9349:21): }
.4(raebu 9350:22):
.8(raebu 9351:22): my $showncrumbs;
1.338 albertel 9352: if (! exists($args->{'skip_phases'}{'body'}) ) {
9353: if ($args->{'frameset'}) {
9354: my $attr_string = &make_attr_string($args->{'force_register'},
9355: $args->{'add_entries'});
9356: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9357: } else {
9358: $result .=
9359: &bodytag($title,
9360: $args->{'function'}, $args->{'add_entries'},
9361: $args->{'only_body'}, $args->{'domain'},
9362: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 9363: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 9364:21): $args, \@advtools,
.8(raebu 9365:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 9366: }
1.330 albertel 9367: }
1.338 albertel 9368:
1.315 albertel 9369: if ($args->{'js_ready'}) {
1.713 kaisler 9370: $result = &js_ready($result);
1.315 albertel 9371: }
1.320 albertel 9372: if ($args->{'html_encode'}) {
1.713 kaisler 9373: $result = &html_encode($result);
9374: }
9375:
1.813 bisitz 9376: # Preparation for new and consistent functionlist at top of screen
9377: # if ($args->{'functionlist'}) {
9378: # $result .= &build_functionlist();
9379: #}
9380:
1.964 droeschl 9381: # Don't add anything more if only_body wanted or in const space
9382: return $result if $args->{'only_body'}
9383: || $env{'request.state'} eq 'construct';
1.813 bisitz 9384:
9385: #Breadcrumbs
1.758 kaisler 9386: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 9387:22): unless ($showncrumbs) {
1.758 kaisler 9388: &Apache::lonhtmlcommon::clear_breadcrumbs();
9389: #if any br links exists, add them to the breadcrumbs
9390: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9391: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9392: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9393: }
9394: }
1.1075.2.19 raeburn 9395: # if @advtools array contains items add then to the breadcrumbs
9396: if (@advtools > 0) {
9397: &Apache::lonmenu::advtools_crumbs(@advtools);
9398: }
1.1075.2.123 raeburn 9399: my $menulink;
9400: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 9401:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
9402:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 9403: $menulink = 0;
9404: } else {
9405: undef($menulink);
9406: }
1.1075.2.161. .8(raebu 9407:22): my $linkprotout;
9408:22): if ($env{'request.deeplink.login'}) {
9409:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
9410:22): if ($linkprotout) {
9411:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9412:22): }
9413:22): }
1.758 kaisler 9414: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9415: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 9416: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1075.2.161. .1(raebu 9417:21): } else {
1.1075.2.123 raeburn 9418: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9419: }
1.1075.2.161. .8(raebu 9420:22): }
1.1075.2.24 raeburn 9421: } elsif (($env{'environment.remote'} eq 'on') &&
9422: ($env{'form.inhibitmenu'} ne 'yes') &&
9423: ($env{'request.noversionuri'} =~ m{^/res/}) &&
9424: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 9425: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 9426: }
1.315 albertel 9427: return $result;
1.306 albertel 9428: }
9429:
9430: sub end_page {
1.315 albertel 9431: my ($args) = @_;
9432: $env{'internal.end_page'}++;
1.330 albertel 9433: my $result;
1.335 albertel 9434: if ($args->{'discussion'}) {
9435: my ($target,$parser);
9436: if (ref($args->{'discussion'})) {
9437: ($target,$parser) =($args->{'discussion'}{'target'},
9438: $args->{'discussion'}{'parser'});
9439: }
9440: $result .= &Apache::lonxml::xmlend($target,$parser);
9441: }
1.330 albertel 9442: if ($args->{'frameset'}) {
9443: $result .= '</frameset>';
9444: } else {
1.635 raeburn 9445: $result .= &endbodytag($args);
1.330 albertel 9446: }
1.1075.2.6 raeburn 9447: unless ($args->{'notbody'}) {
9448: $result .= "\n</html>";
9449: }
1.330 albertel 9450:
1.315 albertel 9451: if ($args->{'js_ready'}) {
1.317 albertel 9452: $result = &js_ready($result);
1.315 albertel 9453: }
1.335 albertel 9454:
1.320 albertel 9455: if ($args->{'html_encode'}) {
9456: $result = &html_encode($result);
9457: }
1.335 albertel 9458:
1.315 albertel 9459: return $result;
9460: }
9461:
1.1075.2.161. .1(raebu 9462:21): sub menucoll_in_effect {
9463:21): my ($menucoll,$deeplinkmenu,%menu);
9464:21): if ($env{'request.course.id'}) {
9465:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9466:21): if ($env{'request.deeplink.login'}) {
9467:21): my ($deeplink_symb,$deeplink,$check_login_symb);
9468:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9469:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9470:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9471:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9472:21): my $navmap = Apache::lonnavmaps::navmap->new();
9473:21): if (ref($navmap)) {
9474:21): $deeplink = $navmap->get_mapparam(undef,
9475:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
9476:21): '0.deeplink');
9477:21): } else {
9478:21): $check_login_symb = 1;
9479:21): }
9480:21): } else {
9481:21): my $symb=&Apache::lonnet::symbread();
9482:21): if ($symb) {
9483:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9484:21): } else {
9485:21): $check_login_symb = 1;
9486:21): }
9487:21): }
9488:21): } else {
9489:21): $check_login_symb = 1;
9490:21): }
9491:21): if ($check_login_symb) {
9492:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9493:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
9494:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9495:21): my $navmap = Apache::lonnavmaps::navmap->new();
9496:21): if (ref($navmap)) {
9497:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9498:21): }
9499:21): } else {
9500:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9501:21): }
9502:21): }
9503:21): if ($deeplink ne '') {
.6(raebu 9504:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 9505:21): if ($display =~ /^\d+$/) {
9506:21): $deeplinkmenu = 1;
9507:21): $menucoll = $display;
9508:21): }
9509:21): }
9510:21): }
9511:21): if ($menucoll) {
9512:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9513:21): }
9514:21): }
9515:21): return ($menucoll,$deeplinkmenu,\%menu);
9516:21): }
9517:21):
9518:21): sub deeplink_login_symb {
9519:21): my ($cnum,$cdom) = @_;
9520:21): my $login_symb;
9521:21): if ($env{'request.deeplink.login'}) {
9522:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9523:21): }
9524:21): return $login_symb;
9525:21): }
9526:21):
9527:21): sub symb_from_tinyurl {
9528:21): my ($url,$cnum,$cdom) = @_;
9529:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9530:21): my $key = $1;
9531:21): my ($tinyurl,$login);
9532:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9533:21): if (defined($cached)) {
9534:21): $tinyurl = $result;
9535:21): } else {
9536:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9537:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9538:21): if ($currtiny{$key} ne '') {
9539:21): $tinyurl = $currtiny{$key};
9540:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9541:21): }
9542:21): }
9543:21): if ($tinyurl ne '') {
9544:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9545:21): if (wantarray) {
9546:21): return ($cnumreq,$symb);
9547:21): } elsif ($cnumreq eq $cnum) {
9548:21): return $symb;
9549:21): }
9550:21): }
9551:21): }
9552:21): if (wantarray) {
9553:21): return ();
9554:21): } else {
9555:21): return;
9556:21): }
9557:21): }
9558:21):
.17(raeb 9559:-23): sub usable_exttools {
9560:-23): my %tooltypes;
9561:-23): if ($env{'request.course.id'}) {
9562:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9563:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9564:-23): %tooltypes = (
9565:-23): crs => 1,
9566:-23): dom => 1,
9567:-23): );
9568:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9569:-23): $tooltypes{'crs'} = 1;
9570:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9571:-23): $tooltypes{'dom'} = 1;
9572:-23): }
9573:-23): } else {
9574:-23): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9575:-23): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9576:-23): my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9577:-23): if ($crstype eq '') {
9578:-23): $crstype = 'course';
9579:-23): }
9580:-23): if ($crstype eq 'course') {
9581:-23): if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9582:-23): $crstype = 'official';
9583:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9584:-23): $crstype = 'textbook';
9585:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9586:-23): $crstype = 'lti';
9587:-23): } else {
9588:-23): $crstype = 'unofficial';
9589:-23): }
9590:-23): }
9591:-23): my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9592:-23): if ($domdefaults{$crstype.'domexttool'}) {
9593:-23): $tooltypes{'dom'} = 1;
9594:-23): }
9595:-23): if ($domdefaults{$crstype.'exttool'}) {
9596:-23): $tooltypes{'crs'} = 1;
9597:-23): }
9598:-23): }
9599:-23): }
9600:-23): return %tooltypes;
9601:-23): }
9602:-23):
1.1034 www 9603: sub wishlist_window {
9604: return(<<'ENDWISHLIST');
1.1046 raeburn 9605: <script type="text/javascript">
1.1034 www 9606: // <![CDATA[
9607: // <!-- BEGIN LON-CAPA Internal
9608: function set_wishlistlink(title, path) {
9609: if (!title) {
9610: title = document.title;
9611: title = title.replace(/^LON-CAPA /,'');
9612: }
1.1075.2.65 raeburn 9613: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9614: title = title.replace("'","\\\'");
1.1034 www 9615: if (!path) {
9616: path = location.pathname;
9617: }
1.1075.2.65 raeburn 9618: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9619: path = path.replace("'","\\\'");
1.1034 www 9620: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9621: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9622: }
9623: // END LON-CAPA Internal -->
9624: // ]]>
9625: </script>
9626: ENDWISHLIST
9627: }
9628:
1.1030 www 9629: sub modal_window {
9630: return(<<'ENDMODAL');
1.1046 raeburn 9631: <script type="text/javascript">
1.1030 www 9632: // <![CDATA[
9633: // <!-- BEGIN LON-CAPA Internal
9634: var modalWindow = {
9635: parent:"body",
9636: windowId:null,
9637: content:null,
9638: width:null,
9639: height:null,
9640: close:function()
9641: {
9642: $(".LCmodal-window").remove();
9643: $(".LCmodal-overlay").remove();
9644: },
9645: open:function()
9646: {
9647: var modal = "";
9648: modal += "<div class=\"LCmodal-overlay\"></div>";
9649: 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;\">";
9650: modal += this.content;
9651: modal += "</div>";
9652:
9653: $(this.parent).append(modal);
9654:
9655: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9656: $(".LCclose-window").click(function(){modalWindow.close();});
9657: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9658: }
9659: };
1.1075.2.42 raeburn 9660: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9661: {
1.1075.2.119 raeburn 9662: source = source.replace(/'/g,"'");
1.1030 www 9663: modalWindow.windowId = "myModal";
9664: modalWindow.width = width;
9665: modalWindow.height = height;
1.1075.2.80 raeburn 9666: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9667: modalWindow.open();
1.1075.2.87 raeburn 9668: };
1.1030 www 9669: // END LON-CAPA Internal -->
9670: // ]]>
9671: </script>
9672: ENDMODAL
9673: }
9674:
9675: sub modal_link {
1.1075.2.42 raeburn 9676: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9677: unless ($width) { $width=480; }
9678: unless ($height) { $height=400; }
1.1031 www 9679: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9680: unless ($transparency) { $transparency='true'; }
9681:
1.1074 raeburn 9682: my $target_attr;
9683: if (defined($target)) {
9684: $target_attr = 'target="'.$target.'"';
9685: }
9686: return <<"ENDLINK";
1.1075.2.143 raeburn 9687: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9688: ENDLINK
1.1030 www 9689: }
9690:
1.1032 www 9691: sub modal_adhoc_script {
1.1075.2.155 raeburn 9692: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9693: my $mathjax;
9694: if ($possmathjax) {
9695: $mathjax = <<'ENDJAX';
9696: if (typeof MathJax == 'object') {
9697: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9698: }
9699: ENDJAX
9700: }
1.1032 www 9701: return (<<ENDADHOC);
1.1046 raeburn 9702: <script type="text/javascript">
1.1032 www 9703: // <![CDATA[
9704: var $funcname = function()
9705: {
9706: modalWindow.windowId = "myModal";
9707: modalWindow.width = $width;
9708: modalWindow.height = $height;
9709: modalWindow.content = '$content';
9710: modalWindow.open();
1.1075.2.155 raeburn 9711: $mathjax
1.1032 www 9712: };
9713: // ]]>
9714: </script>
9715: ENDADHOC
9716: }
9717:
1.1041 www 9718: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9719: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9720: my $innerwidth=$width-20;
9721: $content=&js_ready(
1.1042 www 9722: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9723: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9724: $content.
1.1041 www 9725: &end_scrollbox().
1.1075.2.42 raeburn 9726: &end_page()
1.1041 www 9727: );
1.1075.2.155 raeburn 9728: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9729: }
9730:
9731: sub modal_adhoc_window {
1.1075.2.155 raeburn 9732: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9733: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9734: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9735: }
9736:
9737: sub modal_adhoc_launch {
9738: my ($funcname,$width,$height,$content)=@_;
9739: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9740: <script type="text/javascript">
9741: // <![CDATA[
9742: $funcname();
9743: // ]]>
9744: </script>
9745: ENDLAUNCH
9746: }
9747:
9748: sub modal_adhoc_close {
9749: return (<<ENDCLOSE);
9750: <script type="text/javascript">
9751: // <![CDATA[
9752: modalWindow.close();
9753: // ]]>
9754: </script>
9755: ENDCLOSE
9756: }
9757:
1.1038 www 9758: sub togglebox_script {
9759: return(<<ENDTOGGLE);
9760: <script type="text/javascript">
9761: // <![CDATA[
9762: function LCtoggleDisplay(id,hidetext,showtext) {
9763: link = document.getElementById(id + "link").childNodes[0];
9764: with (document.getElementById(id).style) {
9765: if (display == "none" ) {
9766: display = "inline";
9767: link.nodeValue = hidetext;
9768: } else {
9769: display = "none";
9770: link.nodeValue = showtext;
9771: }
9772: }
9773: }
9774: // ]]>
9775: </script>
9776: ENDTOGGLE
9777: }
9778:
1.1039 www 9779: sub start_togglebox {
9780: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9781: unless ($heading) { $heading=''; } else { $heading.=' '; }
9782: unless ($showtext) { $showtext=&mt('show'); }
9783: unless ($hidetext) { $hidetext=&mt('hide'); }
9784: unless ($headerbg) { $headerbg='#FFFFFF'; }
9785: return &start_data_table().
9786: &start_data_table_header_row().
9787: '<td bgcolor="'.$headerbg.'">'.$heading.
9788: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9789: $showtext.'\')">'.$showtext.'</a>]</td>'.
9790: &end_data_table_header_row().
9791: '<tr id="'.$id.'" style="display:none""><td>';
9792: }
9793:
9794: sub end_togglebox {
9795: return '</td></tr>'.&end_data_table();
9796: }
9797:
1.1041 www 9798: sub LCprogressbar_script {
1.1075.2.130 raeburn 9799: my ($id,$number_to_do)=@_;
9800: if ($number_to_do) {
9801: return(<<ENDPROGRESS);
1.1041 www 9802: <script type="text/javascript">
9803: // <![CDATA[
1.1045 www 9804: \$('#progressbar$id').progressbar({
1.1041 www 9805: value: 0,
9806: change: function(event, ui) {
9807: var newVal = \$(this).progressbar('option', 'value');
9808: \$('.pblabel', this).text(LCprogressTxt);
9809: }
9810: });
9811: // ]]>
9812: </script>
9813: ENDPROGRESS
1.1075.2.130 raeburn 9814: } else {
9815: return(<<ENDPROGRESS);
9816: <script type="text/javascript">
9817: // <![CDATA[
9818: \$('#progressbar$id').progressbar({
9819: value: false,
9820: create: function(event, ui) {
9821: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9822: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9823: }
9824: });
9825: // ]]>
9826: </script>
9827: ENDPROGRESS
9828: }
1.1041 www 9829: }
9830:
9831: sub LCprogressbarUpdate_script {
9832: return(<<ENDPROGRESSUPDATE);
9833: <style type="text/css">
9834: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9835: .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 9836: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9837: </style>
9838: <script type="text/javascript">
9839: // <![CDATA[
1.1045 www 9840: var LCprogressTxt='---';
9841:
1.1075.2.130 raeburn 9842: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9843: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9844: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9845: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9846: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9847: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9848: } else {
9849: \$('#progressbar'+id).progressbar('value',percent);
9850: }
1.1041 www 9851: }
9852: // ]]>
9853: </script>
9854: ENDPROGRESSUPDATE
9855: }
9856:
1.1042 www 9857: my $LClastpercent;
1.1045 www 9858: my $LCidcnt;
9859: my $LCcurrentid;
1.1042 www 9860:
1.1041 www 9861: sub LCprogressbar {
1.1075.2.130 raeburn 9862: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9863: $LClastpercent=0;
1.1045 www 9864: $LCidcnt++;
9865: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9866: my ($starting,$content);
9867: if ($number_to_do) {
9868: $starting=&mt('Starting');
9869: $content=(<<ENDPROGBAR);
9870: $preamble
1.1045 www 9871: <div id="progressbar$LCcurrentid">
1.1041 www 9872: <span class="pblabel">$starting</span>
9873: </div>
9874: ENDPROGBAR
1.1075.2.130 raeburn 9875: } else {
9876: $starting=&mt('Loading...');
9877: $LClastpercent='false';
9878: $content=(<<ENDPROGBAR);
9879: $preamble
9880: <div id="progressbar$LCcurrentid">
9881: <div class="progress-label">$starting</div>
9882: </div>
9883: ENDPROGBAR
9884: }
9885: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9886: }
9887:
9888: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9889: my ($r,$val,$text,$number_to_do)=@_;
9890: if ($number_to_do) {
9891: unless ($val) {
9892: if ($LClastpercent) {
9893: $val=$LClastpercent;
9894: } else {
9895: $val=0;
9896: }
9897: }
9898: if ($val<0) { $val=0; }
9899: if ($val>100) { $val=0; }
9900: $LClastpercent=$val;
9901: unless ($text) { $text=$val.'%'; }
9902: } else {
9903: $val = 'false';
1.1042 www 9904: }
1.1041 www 9905: $text=&js_ready($text);
1.1044 www 9906: &r_print($r,<<ENDUPDATE);
1.1041 www 9907: <script type="text/javascript">
9908: // <![CDATA[
1.1075.2.130 raeburn 9909: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9910: // ]]>
9911: </script>
9912: ENDUPDATE
1.1035 www 9913: }
9914:
1.1042 www 9915: sub LCprogressbarClose {
9916: my ($r)=@_;
9917: $LClastpercent=0;
1.1044 www 9918: &r_print($r,<<ENDCLOSE);
1.1042 www 9919: <script type="text/javascript">
9920: // <![CDATA[
1.1045 www 9921: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9922: // ]]>
9923: </script>
9924: ENDCLOSE
1.1044 www 9925: }
9926:
9927: sub r_print {
9928: my ($r,$to_print)=@_;
9929: if ($r) {
9930: $r->print($to_print);
9931: $r->rflush();
9932: } else {
9933: print($to_print);
9934: }
1.1042 www 9935: }
9936:
1.320 albertel 9937: sub html_encode {
9938: my ($result) = @_;
9939:
1.322 albertel 9940: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9941:
9942: return $result;
9943: }
1.1044 www 9944:
1.317 albertel 9945: sub js_ready {
9946: my ($result) = @_;
9947:
1.323 albertel 9948: $result =~ s/[\n\r]/ /xmsg;
9949: $result =~ s/\\/\\\\/xmsg;
9950: $result =~ s/'/\\'/xmsg;
1.372 albertel 9951: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9952:
9953: return $result;
9954: }
9955:
1.315 albertel 9956: sub validate_page {
9957: if ( exists($env{'internal.start_page'})
1.316 albertel 9958: && $env{'internal.start_page'} > 1) {
9959: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9960: $env{'internal.start_page'}.' '.
1.316 albertel 9961: $ENV{'request.filename'});
1.315 albertel 9962: }
9963: if ( exists($env{'internal.end_page'})
1.316 albertel 9964: && $env{'internal.end_page'} > 1) {
9965: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9966: $env{'internal.end_page'}.' '.
1.316 albertel 9967: $env{'request.filename'});
1.315 albertel 9968: }
9969: if ( exists($env{'internal.start_page'})
9970: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9971: &Apache::lonnet::logthis('start_page called without end_page '.
9972: $env{'request.filename'});
1.315 albertel 9973: }
9974: if ( ! exists($env{'internal.start_page'})
9975: && exists($env{'internal.end_page'})) {
1.316 albertel 9976: &Apache::lonnet::logthis('end_page called without start_page'.
9977: $env{'request.filename'});
1.315 albertel 9978: }
1.306 albertel 9979: }
1.315 albertel 9980:
1.996 www 9981:
9982: sub start_scrollbox {
1.1075.2.56 raeburn 9983: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9984: unless ($outerwidth) { $outerwidth='520px'; }
9985: unless ($width) { $width='500px'; }
9986: unless ($height) { $height='200px'; }
1.1075 raeburn 9987: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9988: if ($id ne '') {
1.1075.2.42 raeburn 9989: $table_id = ' id="table_'.$id.'"';
9990: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9991: }
1.1075 raeburn 9992: if ($bgcolor ne '') {
9993: $tdcol = "background-color: $bgcolor;";
9994: }
1.1075.2.42 raeburn 9995: my $nicescroll_js;
9996: if ($env{'browser.mobile'}) {
9997: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9998: }
1.1075 raeburn 9999: return <<"END";
1.1075.2.42 raeburn 10000: $nicescroll_js
10001:
10002: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 10003: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 10004: END
1.996 www 10005: }
10006:
10007: sub end_scrollbox {
1.1036 www 10008: return '</div></td></tr></table>';
1.996 www 10009: }
10010:
1.1075.2.42 raeburn 10011: sub nicescroll_javascript {
10012: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10013: my %options;
10014: if (ref($cursor) eq 'HASH') {
10015: %options = %{$cursor};
10016: }
10017: unless ($options{'railalign'} =~ /^left|right$/) {
10018: $options{'railalign'} = 'left';
10019: }
10020: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10021: my $function = &get_users_function();
10022: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
10023: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10024: $options{'cursorcolor'} = '#00F';
10025: }
10026: }
10027: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10028: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
10029: $options{'cursoropacity'}='1.0';
10030: }
10031: } else {
10032: $options{'cursoropacity'}='1.0';
10033: }
10034: if ($options{'cursorfixedheight'} eq 'none') {
10035: delete($options{'cursorfixedheight'});
10036: } else {
10037: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10038: }
10039: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10040: delete($options{'railoffset'});
10041: }
10042: my @niceoptions;
10043: while (my($key,$value) = each(%options)) {
10044: if ($value =~ /^\{.+\}$/) {
10045: push(@niceoptions,$key.':'.$value);
10046: } else {
10047: push(@niceoptions,$key.':"'.$value.'"');
10048: }
10049: }
10050: my $nicescroll_js = '
10051: $(document).ready(
10052: function() {
10053: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10054: }
10055: );
10056: ';
10057: if ($framecheck) {
10058: $nicescroll_js .= '
10059: function expand_div(caller) {
10060: if (top === self) {
10061: document.getElementById("'.$id.'").style.width = "auto";
10062: document.getElementById("'.$id.'").style.height = "auto";
10063: } else {
10064: try {
10065: if (parent.frames) {
10066: if (parent.frames.length > 1) {
10067: var framesrc = parent.frames[1].location.href;
10068: var currsrc = framesrc.replace(/\#.*$/,"");
10069: if ((caller == "search") || (currsrc == "'.$location.'")) {
10070: document.getElementById("'.$id.'").style.width = "auto";
10071: document.getElementById("'.$id.'").style.height = "auto";
10072: }
10073: }
10074: }
10075: } catch (e) {
10076: return;
10077: }
10078: }
10079: return;
10080: }
10081: ';
10082: }
10083: if ($needjsready) {
10084: $nicescroll_js = '
10085: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10086: } else {
10087: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10088: }
10089: return $nicescroll_js;
10090: }
10091:
1.318 albertel 10092: sub simple_error_page {
1.1075.2.49 raeburn 10093: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 10094:22): my %displayargs;
1.1075.2.49 raeburn 10095: if (ref($args) eq 'HASH') {
10096: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 10097:22): if ($args->{'only_body'}) {
10098:22): $displayargs{'only_body'} = 1;
10099:22): }
10100:22): if ($args->{'no_nav_bar'}) {
10101:22): $displayargs{'no_nav_bar'} = 1;
10102:22): }
1.1075.2.49 raeburn 10103: } else {
10104: $msg = &mt($msg);
10105: }
10106:
1.318 albertel 10107: my $page =
1.1075.2.161. .4(raebu 10108:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 10109: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10110: &Apache::loncommon::end_page();
10111: if (ref($r)) {
10112: $r->print($page);
1.327 albertel 10113: return;
1.318 albertel 10114: }
10115: return $page;
10116: }
1.347 albertel 10117:
10118: {
1.610 albertel 10119: my @row_count;
1.961 onken 10120:
10121: sub start_data_table_count {
10122: unshift(@row_count, 0);
10123: return;
10124: }
10125:
10126: sub end_data_table_count {
10127: shift(@row_count);
10128: return;
10129: }
10130:
1.347 albertel 10131: sub start_data_table {
1.1018 raeburn 10132: my ($add_class,$id) = @_;
1.422 albertel 10133: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10134: my $table_id;
10135: if (defined($id)) {
10136: $table_id = ' id="'.$id.'"';
10137: }
1.961 onken 10138: &start_data_table_count();
1.1018 raeburn 10139: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10140: }
10141:
10142: sub end_data_table {
1.961 onken 10143: &end_data_table_count();
1.389 albertel 10144: return '</table>'."\n";;
1.347 albertel 10145: }
10146:
10147: sub start_data_table_row {
1.974 wenzelju 10148: my ($add_class, $id) = @_;
1.610 albertel 10149: $row_count[0]++;
10150: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10151: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10152: $id = (' id="'.$id.'"') unless ($id eq '');
10153: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10154: }
1.471 banghart 10155:
10156: sub continue_data_table_row {
1.974 wenzelju 10157: my ($add_class, $id) = @_;
1.610 albertel 10158: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10159: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10160: $id = (' id="'.$id.'"') unless ($id eq '');
10161: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10162: }
1.347 albertel 10163:
10164: sub end_data_table_row {
1.389 albertel 10165: return '</tr>'."\n";;
1.347 albertel 10166: }
1.367 www 10167:
1.421 albertel 10168: sub start_data_table_empty_row {
1.707 bisitz 10169: # $row_count[0]++;
1.421 albertel 10170: return '<tr class="LC_empty_row" >'."\n";;
10171: }
10172:
10173: sub end_data_table_empty_row {
10174: return '</tr>'."\n";;
10175: }
10176:
1.367 www 10177: sub start_data_table_header_row {
1.389 albertel 10178: return '<tr class="LC_header_row">'."\n";;
1.367 www 10179: }
10180:
10181: sub end_data_table_header_row {
1.389 albertel 10182: return '</tr>'."\n";;
1.367 www 10183: }
1.890 droeschl 10184:
10185: sub data_table_caption {
10186: my $caption = shift;
10187: return "<caption class=\"LC_caption\">$caption</caption>";
10188: }
1.347 albertel 10189: }
10190:
1.548 albertel 10191: =pod
10192:
10193: =item * &inhibit_menu_check($arg)
10194:
10195: Checks for a inhibitmenu state and generates output to preserve it
10196:
10197: Inputs: $arg - can be any of
10198: - undef - in which case the return value is a string
10199: to add into arguments list of a uri
10200: - 'input' - in which case the return value is a HTML
10201: <form> <input> field of type hidden to
10202: preserve the value
10203: - a url - in which case the return value is the url with
10204: the neccesary cgi args added to preserve the
10205: inhibitmenu state
10206: - a ref to a url - no return value, but the string is
10207: updated to include the neccessary cgi
10208: args to preserve the inhibitmenu state
10209:
10210: =cut
10211:
10212: sub inhibit_menu_check {
10213: my ($arg) = @_;
10214: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10215: if ($arg eq 'input') {
10216: if ($env{'form.inhibitmenu'}) {
10217: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10218: } else {
10219: return
10220: }
10221: }
10222: if ($env{'form.inhibitmenu'}) {
10223: if (ref($arg)) {
10224: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10225: } elsif ($arg eq '') {
10226: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10227: } else {
10228: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10229: }
10230: }
10231: if (!ref($arg)) {
10232: return $arg;
10233: }
10234: }
10235:
1.251 albertel 10236: ###############################################
1.182 matthew 10237:
10238: =pod
10239:
1.549 albertel 10240: =back
10241:
10242: =head1 User Information Routines
10243:
10244: =over 4
10245:
1.405 albertel 10246: =item * &get_users_function()
1.182 matthew 10247:
10248: Used by &bodytag to determine the current users primary role.
10249: Returns either 'student','coordinator','admin', or 'author'.
10250:
10251: =cut
10252:
10253: ###############################################
10254: sub get_users_function {
1.815 tempelho 10255: my $function = 'norole';
1.818 tempelho 10256: if ($env{'request.role'}=~/^(st)/) {
10257: $function='student';
10258: }
1.907 raeburn 10259: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10260: $function='coordinator';
10261: }
1.258 albertel 10262: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10263: $function='admin';
10264: }
1.826 bisitz 10265: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10266: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10267: $function='author';
10268: }
10269: return $function;
1.54 www 10270: }
1.99 www 10271:
10272: ###############################################
10273:
1.233 raeburn 10274: =pod
10275:
1.821 raeburn 10276: =item * &show_course()
10277:
10278: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10279: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10280:
10281: Inputs:
10282: None
10283:
10284: Outputs:
10285: Scalar: 1 if 'Course' to be used, 0 otherwise.
10286:
10287: =cut
10288:
10289: ###############################################
10290: sub show_course {
10291: my $course = !$env{'user.adv'};
10292: if (!$env{'user.adv'}) {
10293: foreach my $env (keys(%env)) {
10294: next if ($env !~ m/^user\.priv\./);
10295: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10296: $course = 0;
10297: last;
10298: }
10299: }
10300: }
10301: return $course;
10302: }
10303:
10304: ###############################################
10305:
10306: =pod
10307:
1.542 raeburn 10308: =item * &check_user_status()
1.274 raeburn 10309:
10310: Determines current status of supplied role for a
10311: specific user. Roles can be active, previous or future.
10312:
10313: Inputs:
10314: user's domain, user's username, course's domain,
1.375 raeburn 10315: course's number, optional section ID.
1.274 raeburn 10316:
10317: Outputs:
10318: role status: active, previous or future.
10319:
10320: =cut
10321:
10322: sub check_user_status {
1.412 raeburn 10323: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10324: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 10325: my @uroles = keys(%userinfo);
1.274 raeburn 10326: my $srchstr;
10327: my $active_chk = 'none';
1.412 raeburn 10328: my $now = time;
1.274 raeburn 10329: if (@uroles > 0) {
1.908 raeburn 10330: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10331: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10332: } else {
1.412 raeburn 10333: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10334: }
10335: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10336: my $role_end = 0;
10337: my $role_start = 0;
10338: $active_chk = 'active';
1.412 raeburn 10339: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10340: $role_end = $1;
10341: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10342: $role_start = $1;
1.274 raeburn 10343: }
10344: }
10345: if ($role_start > 0) {
1.412 raeburn 10346: if ($now < $role_start) {
1.274 raeburn 10347: $active_chk = 'future';
10348: }
10349: }
10350: if ($role_end > 0) {
1.412 raeburn 10351: if ($now > $role_end) {
1.274 raeburn 10352: $active_chk = 'previous';
10353: }
10354: }
10355: }
10356: }
10357: return $active_chk;
10358: }
10359:
10360: ###############################################
10361:
10362: =pod
10363:
1.405 albertel 10364: =item * &get_sections()
1.233 raeburn 10365:
10366: Determines all the sections for a course including
10367: sections with students and sections containing other roles.
1.419 raeburn 10368: Incoming parameters:
10369:
10370: 1. domain
10371: 2. course number
10372: 3. reference to array containing roles for which sections should
10373: be gathered (optional).
10374: 4. reference to array containing status types for which sections
10375: should be gathered (optional).
10376:
10377: If the third argument is undefined, sections are gathered for any role.
10378: If the fourth argument is undefined, sections are gathered for any status.
10379: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10380:
1.374 raeburn 10381: Returns section hash (keys are section IDs, values are
10382: number of users in each section), subject to the
1.419 raeburn 10383: optional roles filter, optional status filter
1.233 raeburn 10384:
10385: =cut
10386:
10387: ###############################################
10388: sub get_sections {
1.419 raeburn 10389: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10390: if (!defined($cdom) || !defined($cnum)) {
10391: my $cid = $env{'request.course.id'};
10392:
10393: return if (!defined($cid));
10394:
10395: $cdom = $env{'course.'.$cid.'.domain'};
10396: $cnum = $env{'course.'.$cid.'.num'};
10397: }
10398:
10399: my %sectioncount;
1.419 raeburn 10400: my $now = time;
1.240 albertel 10401:
1.1075.2.33 raeburn 10402: my $check_students = 1;
10403: my $only_students = 0;
10404: if (ref($possible_roles) eq 'ARRAY') {
10405: if (grep(/^st$/,@{$possible_roles})) {
10406: if (@{$possible_roles} == 1) {
10407: $only_students = 1;
10408: }
10409: } else {
10410: $check_students = 0;
10411: }
10412: }
10413:
10414: if ($check_students) {
1.276 albertel 10415: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10416: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10417: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10418: my $start_index = &Apache::loncoursedata::CL_START();
10419: my $end_index = &Apache::loncoursedata::CL_END();
10420: my $status;
1.366 albertel 10421: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10422: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10423: $data->[$status_index],
10424: $data->[$start_index],
10425: $data->[$end_index]);
10426: if ($stu_status eq 'Active') {
10427: $status = 'active';
10428: } elsif ($end < $now) {
10429: $status = 'previous';
10430: } elsif ($start > $now) {
10431: $status = 'future';
10432: }
10433: if ($section ne '-1' && $section !~ /^\s*$/) {
10434: if ((!defined($possible_status)) || (($status ne '') &&
10435: (grep/^\Q$status\E$/,@{$possible_status}))) {
10436: $sectioncount{$section}++;
10437: }
1.240 albertel 10438: }
10439: }
10440: }
1.1075.2.33 raeburn 10441: if ($only_students) {
10442: return %sectioncount;
10443: }
1.240 albertel 10444: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10445: foreach my $user (sort(keys(%courseroles))) {
10446: if ($user !~ /^(\w{2})/) { next; }
10447: my ($role) = ($user =~ /^(\w{2})/);
10448: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10449: my ($section,$status);
1.240 albertel 10450: if ($role eq 'cr' &&
10451: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10452: $section=$1;
10453: }
10454: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10455: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10456: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10457: if ($end == -1 && $start == -1) {
10458: next; #deleted role
10459: }
10460: if (!defined($possible_status)) {
10461: $sectioncount{$section}++;
10462: } else {
10463: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10464: $status = 'active';
10465: } elsif ($end < $now) {
10466: $status = 'future';
10467: } elsif ($start > $now) {
10468: $status = 'previous';
10469: }
10470: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10471: $sectioncount{$section}++;
10472: }
10473: }
1.233 raeburn 10474: }
1.366 albertel 10475: return %sectioncount;
1.233 raeburn 10476: }
10477:
1.274 raeburn 10478: ###############################################
1.294 raeburn 10479:
10480: =pod
1.405 albertel 10481:
10482: =item * &get_course_users()
10483:
1.275 raeburn 10484: Retrieves usernames:domains for users in the specified course
10485: with specific role(s), and access status.
10486:
10487: Incoming parameters:
1.277 albertel 10488: 1. course domain
10489: 2. course number
10490: 3. access status: users must have - either active,
1.275 raeburn 10491: previous, future, or all.
1.277 albertel 10492: 4. reference to array of permissible roles
1.288 raeburn 10493: 5. reference to array of section restrictions (optional)
10494: 6. reference to results object (hash of hashes).
10495: 7. reference to optional userdata hash
1.609 raeburn 10496: 8. reference to optional statushash
1.630 raeburn 10497: 9. flag if privileged users (except those set to unhide in
10498: course settings) should be excluded
1.609 raeburn 10499: Keys of top level results hash are roles.
1.275 raeburn 10500: Keys of inner hashes are username:domain, with
10501: values set to access type.
1.288 raeburn 10502: Optional userdata hash returns an array with arguments in the
10503: same order as loncoursedata::get_classlist() for student data.
10504:
1.609 raeburn 10505: Optional statushash returns
10506:
1.288 raeburn 10507: Entries for end, start, section and status are blank because
10508: of the possibility of multiple values for non-student roles.
10509:
1.275 raeburn 10510: =cut
1.405 albertel 10511:
1.275 raeburn 10512: ###############################################
1.405 albertel 10513:
1.275 raeburn 10514: sub get_course_users {
1.630 raeburn 10515: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10516: my %idx = ();
1.419 raeburn 10517: my %seclists;
1.288 raeburn 10518:
10519: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10520: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10521: $idx{end} = &Apache::loncoursedata::CL_END();
10522: $idx{start} = &Apache::loncoursedata::CL_START();
10523: $idx{id} = &Apache::loncoursedata::CL_ID();
10524: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10525: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10526: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10527:
1.290 albertel 10528: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10529: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10530: my $now = time;
1.277 albertel 10531: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10532: my $match = 0;
1.412 raeburn 10533: my $secmatch = 0;
1.419 raeburn 10534: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10535: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10536: if ($section eq '') {
10537: $section = 'none';
10538: }
1.291 albertel 10539: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10540: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10541: $secmatch = 1;
10542: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10543: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10544: $secmatch = 1;
10545: }
10546: } else {
1.419 raeburn 10547: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10548: $secmatch = 1;
10549: }
1.290 albertel 10550: }
1.412 raeburn 10551: if (!$secmatch) {
10552: next;
10553: }
1.419 raeburn 10554: }
1.275 raeburn 10555: if (defined($$types{'active'})) {
1.288 raeburn 10556: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10557: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10558: $match = 1;
1.275 raeburn 10559: }
10560: }
10561: if (defined($$types{'previous'})) {
1.609 raeburn 10562: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10563: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10564: $match = 1;
1.275 raeburn 10565: }
10566: }
10567: if (defined($$types{'future'})) {
1.609 raeburn 10568: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10569: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10570: $match = 1;
1.275 raeburn 10571: }
10572: }
1.609 raeburn 10573: if ($match) {
10574: push(@{$seclists{$student}},$section);
10575: if (ref($userdata) eq 'HASH') {
10576: $$userdata{$student} = $$classlist{$student};
10577: }
10578: if (ref($statushash) eq 'HASH') {
10579: $statushash->{$student}{'st'}{$section} = $status;
10580: }
1.288 raeburn 10581: }
1.275 raeburn 10582: }
10583: }
1.412 raeburn 10584: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10585: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10586: my $now = time;
1.609 raeburn 10587: my %displaystatus = ( previous => 'Expired',
10588: active => 'Active',
10589: future => 'Future',
10590: );
1.1075.2.36 raeburn 10591: my (%nothide,@possdoms);
1.630 raeburn 10592: if ($hidepriv) {
10593: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10594: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10595: if ($user !~ /:/) {
10596: $nothide{join(':',split(/[\@]/,$user))}=1;
10597: } else {
10598: $nothide{$user} = 1;
10599: }
10600: }
1.1075.2.36 raeburn 10601: my @possdoms = ($cdom);
10602: if ($coursehash{'checkforpriv'}) {
10603: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10604: }
1.630 raeburn 10605: }
1.439 raeburn 10606: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10607: my $match = 0;
1.412 raeburn 10608: my $secmatch = 0;
1.439 raeburn 10609: my $status;
1.412 raeburn 10610: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10611: $user =~ s/:$//;
1.439 raeburn 10612: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10613: if ($end == -1 || $start == -1) {
10614: next;
10615: }
10616: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10617: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10618: my ($uname,$udom) = split(/:/,$user);
10619: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10620: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10621: $secmatch = 1;
10622: } elsif ($usec eq '') {
1.420 albertel 10623: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10624: $secmatch = 1;
10625: }
10626: } else {
10627: if (grep(/^\Q$usec\E$/,@{$sections})) {
10628: $secmatch = 1;
10629: }
10630: }
10631: if (!$secmatch) {
10632: next;
10633: }
1.288 raeburn 10634: }
1.419 raeburn 10635: if ($usec eq '') {
10636: $usec = 'none';
10637: }
1.275 raeburn 10638: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10639: if ($hidepriv) {
1.1075.2.36 raeburn 10640: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10641: (!$nothide{$uname.':'.$udom})) {
10642: next;
10643: }
10644: }
1.503 raeburn 10645: if ($end > 0 && $end < $now) {
1.439 raeburn 10646: $status = 'previous';
10647: } elsif ($start > $now) {
10648: $status = 'future';
10649: } else {
10650: $status = 'active';
10651: }
1.277 albertel 10652: foreach my $type (keys(%{$types})) {
1.275 raeburn 10653: if ($status eq $type) {
1.420 albertel 10654: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10655: push(@{$$users{$role}{$user}},$type);
10656: }
1.288 raeburn 10657: $match = 1;
10658: }
10659: }
1.419 raeburn 10660: if (($match) && (ref($userdata) eq 'HASH')) {
10661: if (!exists($$userdata{$uname.':'.$udom})) {
10662: &get_user_info($udom,$uname,\%idx,$userdata);
10663: }
1.420 albertel 10664: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10665: push(@{$seclists{$uname.':'.$udom}},$usec);
10666: }
1.609 raeburn 10667: if (ref($statushash) eq 'HASH') {
10668: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10669: }
1.275 raeburn 10670: }
10671: }
10672: }
10673: }
1.290 albertel 10674: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10675: if ((defined($cdom)) && (defined($cnum))) {
10676: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10677: if ( defined($csettings{'internal.courseowner'}) ) {
10678: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10679: next if ($owner eq '');
10680: my ($ownername,$ownerdom);
10681: if ($owner =~ /^([^:]+):([^:]+)$/) {
10682: $ownername = $1;
10683: $ownerdom = $2;
10684: } else {
10685: $ownername = $owner;
10686: $ownerdom = $cdom;
10687: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10688: }
10689: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10690: if (defined($userdata) &&
1.609 raeburn 10691: !exists($$userdata{$owner})) {
10692: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10693: if (!grep(/^none$/,@{$seclists{$owner}})) {
10694: push(@{$seclists{$owner}},'none');
10695: }
10696: if (ref($statushash) eq 'HASH') {
10697: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10698: }
1.290 albertel 10699: }
1.279 raeburn 10700: }
10701: }
10702: }
1.419 raeburn 10703: foreach my $user (keys(%seclists)) {
10704: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10705: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10706: }
1.275 raeburn 10707: }
10708: return;
10709: }
10710:
1.288 raeburn 10711: sub get_user_info {
10712: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10713: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10714: &plainname($uname,$udom,'lastname');
1.291 albertel 10715: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10716: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10717: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10718: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10719: return;
10720: }
1.275 raeburn 10721:
1.472 raeburn 10722: ###############################################
10723:
10724: =pod
10725:
10726: =item * &get_user_quota()
10727:
1.1075.2.41 raeburn 10728: Retrieves quota assigned for storage of user files.
10729: Default is to report quota for portfolio files.
1.472 raeburn 10730:
10731: Incoming parameters:
10732: 1. user's username
10733: 2. user's domain
1.1075.2.41 raeburn 10734: 3. quota name - portfolio, author, or course
10735: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10736: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10737: course
1.472 raeburn 10738:
10739: Returns:
1.1075.2.58 raeburn 10740: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10741: 2. (Optional) Type of setting: custom or default
10742: (individually assigned or default for user's
10743: institutional status).
10744: 3. (Optional) - User's institutional status (e.g., faculty, staff
10745: or student - types as defined in localenroll::inst_usertypes
10746: for user's domain, which determines default quota for user.
10747: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10748:
10749: If a value has been stored in the user's environment,
1.536 raeburn 10750: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10751: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10752:
10753: =cut
10754:
10755: ###############################################
10756:
10757:
10758: sub get_user_quota {
1.1075.2.42 raeburn 10759: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10760: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10761: if (!defined($udom)) {
10762: $udom = $env{'user.domain'};
10763: }
10764: if (!defined($uname)) {
10765: $uname = $env{'user.name'};
10766: }
10767: if (($udom eq '' || $uname eq '') ||
10768: ($udom eq 'public') && ($uname eq 'public')) {
10769: $quota = 0;
1.536 raeburn 10770: $quotatype = 'default';
10771: $defquota = 0;
1.472 raeburn 10772: } else {
1.536 raeburn 10773: my $inststatus;
1.1075.2.41 raeburn 10774: if ($quotaname eq 'course') {
10775: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10776: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10777: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10778: } else {
10779: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10780: $quota = $cenv{'internal.uploadquota'};
10781: }
1.536 raeburn 10782: } else {
1.1075.2.41 raeburn 10783: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10784: if ($quotaname eq 'author') {
10785: $quota = $env{'environment.authorquota'};
10786: } else {
10787: $quota = $env{'environment.portfolioquota'};
10788: }
10789: $inststatus = $env{'environment.inststatus'};
10790: } else {
10791: my %userenv =
10792: &Apache::lonnet::get('environment',['portfolioquota',
10793: 'authorquota','inststatus'],$udom,$uname);
10794: my ($tmp) = keys(%userenv);
10795: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10796: if ($quotaname eq 'author') {
10797: $quota = $userenv{'authorquota'};
10798: } else {
10799: $quota = $userenv{'portfolioquota'};
10800: }
10801: $inststatus = $userenv{'inststatus'};
10802: } else {
10803: undef(%userenv);
10804: }
10805: }
10806: }
10807: if ($quota eq '' || wantarray) {
10808: if ($quotaname eq 'course') {
10809: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10810: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10811: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10812: $defquota = $domdefs{$crstype.'quota'};
10813: }
10814: if ($defquota eq '') {
10815: $defquota = 500;
10816: }
1.1075.2.41 raeburn 10817: } else {
10818: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10819: }
10820: if ($quota eq '') {
10821: $quota = $defquota;
10822: $quotatype = 'default';
10823: } else {
10824: $quotatype = 'custom';
10825: }
1.472 raeburn 10826: }
10827: }
1.536 raeburn 10828: if (wantarray) {
10829: return ($quota,$quotatype,$settingstatus,$defquota);
10830: } else {
10831: return $quota;
10832: }
1.472 raeburn 10833: }
10834:
10835: ###############################################
10836:
10837: =pod
10838:
10839: =item * &default_quota()
10840:
1.536 raeburn 10841: Retrieves default quota assigned for storage of user portfolio files,
10842: given an (optional) user's institutional status.
1.472 raeburn 10843:
10844: Incoming parameters:
1.1075.2.42 raeburn 10845:
1.472 raeburn 10846: 1. domain
1.536 raeburn 10847: 2. (Optional) institutional status(es). This is a : separated list of
10848: status types (e.g., faculty, staff, student etc.)
10849: which apply to the user for whom the default is being retrieved.
10850: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10851: default quota will be returned.
10852: 3. quota name - portfolio, author, or course
10853: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10854:
10855: Returns:
1.1075.2.42 raeburn 10856:
1.1075.2.58 raeburn 10857: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10858: 2. (Optional) institutional type which determined the value of the
10859: default quota.
1.472 raeburn 10860:
10861: If a value has been stored in the domain's configuration db,
10862: it will return that, otherwise it returns 20 (for backwards
10863: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10864: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10865:
1.536 raeburn 10866: If the user's status includes multiple types (e.g., staff and student),
10867: the largest default quota which applies to the user determines the
10868: default quota returned.
10869:
1.472 raeburn 10870: =cut
10871:
10872: ###############################################
10873:
10874:
10875: sub default_quota {
1.1075.2.41 raeburn 10876: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10877: my ($defquota,$settingstatus);
10878: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10879: ['quotas'],$udom);
1.1075.2.41 raeburn 10880: my $key = 'defaultquota';
10881: if ($quotaname eq 'author') {
10882: $key = 'authorquota';
10883: }
1.622 raeburn 10884: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10885: if ($inststatus ne '') {
1.765 raeburn 10886: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10887: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10888: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10889: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10890: if ($defquota eq '') {
1.1075.2.41 raeburn 10891: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10892: $settingstatus = $item;
1.1075.2.41 raeburn 10893: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10894: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10895: $settingstatus = $item;
10896: }
10897: }
1.1075.2.41 raeburn 10898: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10899: if ($quotahash{'quotas'}{$item} ne '') {
10900: if ($defquota eq '') {
10901: $defquota = $quotahash{'quotas'}{$item};
10902: $settingstatus = $item;
10903: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10904: $defquota = $quotahash{'quotas'}{$item};
10905: $settingstatus = $item;
10906: }
1.536 raeburn 10907: }
10908: }
10909: }
10910: }
10911: if ($defquota eq '') {
1.1075.2.41 raeburn 10912: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10913: $defquota = $quotahash{'quotas'}{$key}{'default'};
10914: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10915: $defquota = $quotahash{'quotas'}{'default'};
10916: }
1.536 raeburn 10917: $settingstatus = 'default';
1.1075.2.42 raeburn 10918: if ($defquota eq '') {
10919: if ($quotaname eq 'author') {
10920: $defquota = 500;
10921: }
10922: }
1.536 raeburn 10923: }
10924: } else {
10925: $settingstatus = 'default';
1.1075.2.41 raeburn 10926: if ($quotaname eq 'author') {
10927: $defquota = 500;
10928: } else {
10929: $defquota = 20;
10930: }
1.536 raeburn 10931: }
10932: if (wantarray) {
10933: return ($defquota,$settingstatus);
1.472 raeburn 10934: } else {
1.536 raeburn 10935: return $defquota;
1.472 raeburn 10936: }
10937: }
10938:
1.1075.2.41 raeburn 10939: ###############################################
10940:
10941: =pod
10942:
1.1075.2.42 raeburn 10943: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 10944:
10945: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 10946: of existing file within authoring space will cause quota for the authoring
10947: space to be exceeded.
10948:
10949: Same, if upload of a file directly to a course/community via Course Editor
10950: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 10951:
1.1075.2.61 raeburn 10952: Inputs: 7
1.1075.2.42 raeburn 10953: 1. username or coursenum
1.1075.2.41 raeburn 10954: 2. domain
1.1075.2.42 raeburn 10955: 3. context ('author' or 'course')
1.1075.2.41 raeburn 10956: 4. filename of file for which action is being requested
10957: 5. filesize (kB) of file
10958: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 10959: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 10960:
10961: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
10962: otherwise return null.
10963:
1.1075.2.42 raeburn 10964: =back
10965:
1.1075.2.41 raeburn 10966: =cut
10967:
1.1075.2.42 raeburn 10968: sub excess_filesize_warning {
1.1075.2.59 raeburn 10969: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 10970: my $current_disk_usage = 0;
1.1075.2.59 raeburn 10971: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 10972: if ($context eq 'author') {
10973: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10974: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10975: } else {
10976: foreach my $subdir ('docs','supplemental') {
10977: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10978: }
10979: }
1.1075.2.41 raeburn 10980: $disk_quota = int($disk_quota * 1000);
10981: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 10982: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 10983: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 10984: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10985: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 10986: $disk_quota,$current_disk_usage).
10987: '</p>';
10988: }
10989: return;
10990: }
10991:
10992: ###############################################
10993:
10994:
1.384 raeburn 10995: sub get_secgrprole_info {
10996: my ($cdom,$cnum,$needroles,$type) = @_;
10997: my %sections_count = &get_sections($cdom,$cnum);
10998: my @sections = (sort {$a <=> $b} keys(%sections_count));
10999: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11000: my @groups = sort(keys(%curr_groups));
11001: my $allroles = [];
11002: my $rolehash;
11003: my $accesshash = {
11004: active => 'Currently has access',
11005: future => 'Will have future access',
11006: previous => 'Previously had access',
11007: };
11008: if ($needroles) {
11009: $rolehash = {'all' => 'all'};
1.385 albertel 11010: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11011: if (&Apache::lonnet::error(%user_roles)) {
11012: undef(%user_roles);
11013: }
11014: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11015: my ($role)=split(/\:/,$item,2);
11016: if ($role eq 'cr') { next; }
11017: if ($role =~ /^cr/) {
11018: $$rolehash{$role} = (split('/',$role))[3];
11019: } else {
11020: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11021: }
11022: }
11023: foreach my $key (sort(keys(%{$rolehash}))) {
11024: push(@{$allroles},$key);
11025: }
11026: push (@{$allroles},'st');
11027: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11028: }
11029: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11030: }
11031:
1.555 raeburn 11032: sub user_picker {
1.1075.2.127 raeburn 11033: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11034: my $currdom = $dom;
1.1075.2.114 raeburn 11035: my @alldoms = &Apache::lonnet::all_domains();
11036: if (@alldoms == 1) {
11037: my %domsrch = &Apache::lonnet::get_dom('configuration',
11038: ['directorysrch'],$alldoms[0]);
11039: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11040: my $showdom = $domdesc;
11041: if ($showdom eq '') {
11042: $showdom = $dom;
11043: }
11044: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11045: if ((!$domsrch{'directorysrch'}{'available'}) &&
11046: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11047: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11048: }
11049: }
11050: }
1.555 raeburn 11051: my %curr_selected = (
11052: srchin => 'dom',
1.580 raeburn 11053: srchby => 'lastname',
1.555 raeburn 11054: );
11055: my $srchterm;
1.625 raeburn 11056: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11057: if ($srch->{'srchby'} ne '') {
11058: $curr_selected{'srchby'} = $srch->{'srchby'};
11059: }
11060: if ($srch->{'srchin'} ne '') {
11061: $curr_selected{'srchin'} = $srch->{'srchin'};
11062: }
11063: if ($srch->{'srchtype'} ne '') {
11064: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11065: }
11066: if ($srch->{'srchdomain'} ne '') {
11067: $currdom = $srch->{'srchdomain'};
11068: }
11069: $srchterm = $srch->{'srchterm'};
11070: }
1.1075.2.98 raeburn 11071: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11072: 'usr' => 'Search criteria',
1.563 raeburn 11073: 'doma' => 'Domain/institution to search',
1.558 albertel 11074: 'uname' => 'username',
11075: 'lastname' => 'last name',
1.555 raeburn 11076: 'lastfirst' => 'last name, first name',
1.558 albertel 11077: 'crs' => 'in this course',
1.576 raeburn 11078: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11079: 'alc' => 'all LON-CAPA',
1.573 raeburn 11080: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11081: 'exact' => 'is',
11082: 'contains' => 'contains',
1.569 raeburn 11083: 'begins' => 'begins with',
1.1075.2.98 raeburn 11084: );
11085: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11086: 'youm' => "You must include some text to search for.",
11087: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11088: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11089: 'yomc' => "You must choose a domain when using an institutional directory search.",
11090: 'ymcd' => "You must choose a domain when using a domain search.",
11091: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11092: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11093: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11094: );
1.1075.2.98 raeburn 11095: &html_escape(\%html_lt);
11096: &js_escape(\%js_lt);
1.1075.2.115 raeburn 11097: my $domform;
1.1075.2.126 raeburn 11098: my $allow_blank = 1;
1.1075.2.115 raeburn 11099: if ($fixeddom) {
1.1075.2.126 raeburn 11100: $allow_blank = 0;
11101: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 11102: } else {
1.1075.2.126 raeburn 11103: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 11104: }
1.563 raeburn 11105: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11106:
11107: my @srchins = ('crs','dom','alc','instd');
11108:
11109: foreach my $option (@srchins) {
11110: # FIXME 'alc' option unavailable until
11111: # loncreateuser::print_user_query_page()
11112: # has been completed.
11113: next if ($option eq 'alc');
1.880 raeburn 11114: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11115: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 11116: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11117: if ($curr_selected{'srchin'} eq $option) {
11118: $srchinsel .= '
1.1075.2.98 raeburn 11119: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11120: } else {
11121: $srchinsel .= '
1.1075.2.98 raeburn 11122: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11123: }
1.555 raeburn 11124: }
1.563 raeburn 11125: $srchinsel .= "\n </select>\n";
1.555 raeburn 11126:
11127: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11128: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11129: if ($curr_selected{'srchby'} eq $option) {
11130: $srchbysel .= '
1.1075.2.98 raeburn 11131: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11132: } else {
11133: $srchbysel .= '
1.1075.2.98 raeburn 11134: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11135: }
11136: }
11137: $srchbysel .= "\n </select>\n";
11138:
11139: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11140: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11141: if ($curr_selected{'srchtype'} eq $option) {
11142: $srchtypesel .= '
1.1075.2.98 raeburn 11143: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11144: } else {
11145: $srchtypesel .= '
1.1075.2.98 raeburn 11146: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11147: }
11148: }
11149: $srchtypesel .= "\n </select>\n";
11150:
1.558 albertel 11151: my ($newuserscript,$new_user_create);
1.994 raeburn 11152: my $context_dom = $env{'request.role.domain'};
11153: if ($context eq 'requestcrs') {
11154: if ($env{'form.coursedom'} ne '') {
11155: $context_dom = $env{'form.coursedom'};
11156: }
11157: }
1.556 raeburn 11158: if ($forcenewuser) {
1.576 raeburn 11159: if (ref($srch) eq 'HASH') {
1.994 raeburn 11160: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11161: if ($cancreate) {
11162: $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>';
11163: } else {
1.799 bisitz 11164: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11165: my %usertypetext = (
11166: official => 'institutional',
11167: unofficial => 'non-institutional',
11168: );
1.799 bisitz 11169: $new_user_create = '<p class="LC_warning">'
11170: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11171: .' '
11172: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11173: ,'<a href="'.$helplink.'">','</a>')
11174: .'</p><br />';
1.627 raeburn 11175: }
1.576 raeburn 11176: }
11177: }
11178:
1.556 raeburn 11179: $newuserscript = <<"ENDSCRIPT";
11180:
1.570 raeburn 11181: function setSearch(createnew,callingForm) {
1.556 raeburn 11182: if (createnew == 1) {
1.570 raeburn 11183: for (var i=0; i<callingForm.srchby.length; i++) {
11184: if (callingForm.srchby.options[i].value == 'uname') {
11185: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11186: }
11187: }
1.570 raeburn 11188: for (var i=0; i<callingForm.srchin.length; i++) {
11189: if ( callingForm.srchin.options[i].value == 'dom') {
11190: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11191: }
11192: }
1.570 raeburn 11193: for (var i=0; i<callingForm.srchtype.length; i++) {
11194: if (callingForm.srchtype.options[i].value == 'exact') {
11195: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11196: }
11197: }
1.570 raeburn 11198: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11199: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11200: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11201: }
11202: }
11203: }
11204: }
11205: ENDSCRIPT
1.558 albertel 11206:
1.556 raeburn 11207: }
11208:
1.555 raeburn 11209: my $output = <<"END_BLOCK";
1.556 raeburn 11210: <script type="text/javascript">
1.824 bisitz 11211: // <![CDATA[
1.570 raeburn 11212: function validateEntry(callingForm) {
1.558 albertel 11213:
1.556 raeburn 11214: var checkok = 1;
1.558 albertel 11215: var srchin;
1.570 raeburn 11216: for (var i=0; i<callingForm.srchin.length; i++) {
11217: if ( callingForm.srchin[i].checked ) {
11218: srchin = callingForm.srchin[i].value;
1.558 albertel 11219: }
11220: }
11221:
1.570 raeburn 11222: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11223: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11224: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11225: var srchterm = callingForm.srchterm.value;
11226: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11227: var msg = "";
11228:
11229: if (srchterm == "") {
11230: checkok = 0;
1.1075.2.98 raeburn 11231: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11232: }
11233:
1.569 raeburn 11234: if (srchtype== 'begins') {
11235: if (srchterm.length < 2) {
11236: checkok = 0;
1.1075.2.98 raeburn 11237: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11238: }
11239: }
11240:
1.556 raeburn 11241: if (srchtype== 'contains') {
11242: if (srchterm.length < 3) {
11243: checkok = 0;
1.1075.2.98 raeburn 11244: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11245: }
11246: }
11247: if (srchin == 'instd') {
11248: if (srchdomain == '') {
11249: checkok = 0;
1.1075.2.98 raeburn 11250: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11251: }
11252: }
11253: if (srchin == 'dom') {
11254: if (srchdomain == '') {
11255: checkok = 0;
1.1075.2.98 raeburn 11256: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11257: }
11258: }
11259: if (srchby == 'lastfirst') {
11260: if (srchterm.indexOf(",") == -1) {
11261: checkok = 0;
1.1075.2.98 raeburn 11262: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11263: }
11264: if (srchterm.indexOf(",") == srchterm.length -1) {
11265: checkok = 0;
1.1075.2.98 raeburn 11266: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11267: }
11268: }
11269: if (checkok == 0) {
1.1075.2.98 raeburn 11270: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11271: return;
11272: }
11273: if (checkok == 1) {
1.570 raeburn 11274: callingForm.submit();
1.556 raeburn 11275: }
11276: }
11277:
11278: $newuserscript
11279:
1.824 bisitz 11280: // ]]>
1.556 raeburn 11281: </script>
1.558 albertel 11282:
11283: $new_user_create
11284:
1.555 raeburn 11285: END_BLOCK
1.558 albertel 11286:
1.876 raeburn 11287: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 11288: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11289: $domform.
11290: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 11291: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11292: $srchbysel.
11293: $srchtypesel.
11294: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11295: $srchinsel.
11296: &Apache::lonhtmlcommon::row_closure(1).
11297: &Apache::lonhtmlcommon::end_pick_box().
11298: '<br />';
1.1075.2.114 raeburn 11299: return ($output,1);
1.555 raeburn 11300: }
11301:
1.612 raeburn 11302: sub user_rule_check {
1.615 raeburn 11303: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 11304: my ($response,%inst_response);
1.612 raeburn 11305: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 11306: if (keys(%{$usershash}) > 1) {
11307: my (%by_username,%by_id,%userdoms);
11308: my $checkid;
1.612 raeburn 11309: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 11310: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11311: $checkid = 1;
11312: }
11313: }
11314: foreach my $user (keys(%{$usershash})) {
11315: my ($uname,$udom) = split(/:/,$user);
11316: if ($checkid) {
11317: if (ref($usershash->{$user}) eq 'HASH') {
11318: if ($usershash->{$user}->{'id'} ne '') {
11319: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
11320: $userdoms{$udom} = 1;
11321: if (ref($inst_results) eq 'HASH') {
11322: $inst_results->{$uname.':'.$udom} = {};
11323: }
11324: }
11325: }
11326: } else {
11327: $by_username{$udom}{$uname} = 1;
11328: $userdoms{$udom} = 1;
11329: if (ref($inst_results) eq 'HASH') {
11330: $inst_results->{$uname.':'.$udom} = {};
11331: }
11332: }
11333: }
11334: foreach my $udom (keys(%userdoms)) {
11335: if (!$got_rules->{$udom}) {
11336: my %domconfig = &Apache::lonnet::get_dom('configuration',
11337: ['usercreation'],$udom);
11338: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11339: foreach my $item ('username','id') {
11340: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11341: $$curr_rules{$udom}{$item} =
11342: $domconfig{'usercreation'}{$item.'_rule'};
11343: }
11344: }
11345: }
11346: $got_rules->{$udom} = 1;
11347: }
11348: }
11349: if ($checkid) {
11350: foreach my $udom (keys(%by_id)) {
11351: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11352: if ($outcome eq 'ok') {
11353: foreach my $id (keys(%{$by_id{$udom}})) {
11354: my $uname = $by_id{$udom}{$id};
11355: $inst_response{$uname.':'.$udom} = $outcome;
11356: }
11357: if (ref($results) eq 'HASH') {
11358: foreach my $uname (keys(%{$results})) {
11359: if (exists($inst_response{$uname.':'.$udom})) {
11360: $inst_response{$uname.':'.$udom} = $outcome;
11361: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11362: }
11363: }
11364: }
11365: }
1.612 raeburn 11366: }
1.615 raeburn 11367: } else {
1.1075.2.99 raeburn 11368: foreach my $udom (keys(%by_username)) {
11369: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11370: if ($outcome eq 'ok') {
11371: foreach my $uname (keys(%{$by_username{$udom}})) {
11372: $inst_response{$uname.':'.$udom} = $outcome;
11373: }
11374: if (ref($results) eq 'HASH') {
11375: foreach my $uname (keys(%{$results})) {
11376: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11377: }
11378: }
11379: }
11380: }
1.612 raeburn 11381: }
1.1075.2.99 raeburn 11382: } elsif (keys(%{$usershash}) == 1) {
11383: my $user = (keys(%{$usershash}))[0];
11384: my ($uname,$udom) = split(/:/,$user);
11385: if (($udom ne '') && ($uname ne '')) {
11386: if (ref($usershash->{$user}) eq 'HASH') {
11387: if (ref($checks) eq 'HASH') {
11388: if (defined($checks->{'username'})) {
11389: ($inst_response{$user},%{$inst_results->{$user}}) =
11390: &Apache::lonnet::get_instuser($udom,$uname);
11391: } elsif (defined($checks->{'id'})) {
11392: if ($usershash->{$user}->{'id'} ne '') {
11393: ($inst_response{$user},%{$inst_results->{$user}}) =
11394: &Apache::lonnet::get_instuser($udom,undef,
11395: $usershash->{$user}->{'id'});
11396: } else {
11397: ($inst_response{$user},%{$inst_results->{$user}}) =
11398: &Apache::lonnet::get_instuser($udom,$uname);
11399: }
11400: }
11401: } else {
11402: ($inst_response{$user},%{$inst_results->{$user}}) =
11403: &Apache::lonnet::get_instuser($udom,$uname);
11404: return;
11405: }
11406: if (!$got_rules->{$udom}) {
11407: my %domconfig = &Apache::lonnet::get_dom('configuration',
11408: ['usercreation'],$udom);
11409: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11410: foreach my $item ('username','id') {
11411: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11412: $$curr_rules{$udom}{$item} =
11413: $domconfig{'usercreation'}{$item.'_rule'};
11414: }
11415: }
1.585 raeburn 11416: }
1.1075.2.99 raeburn 11417: $got_rules->{$udom} = 1;
1.585 raeburn 11418: }
11419: }
1.1075.2.99 raeburn 11420: } else {
11421: return;
11422: }
11423: } else {
11424: return;
11425: }
11426: foreach my $user (keys(%{$usershash})) {
11427: my ($uname,$udom) = split(/:/,$user);
11428: next if (($udom eq '') || ($uname eq ''));
11429: my $id;
11430: if (ref($inst_results) eq 'HASH') {
11431: if (ref($inst_results->{$user}) eq 'HASH') {
11432: $id = $inst_results->{$user}->{'id'};
11433: }
11434: }
11435: if ($id eq '') {
11436: if (ref($usershash->{$user})) {
11437: $id = $usershash->{$user}->{'id'};
11438: }
1.585 raeburn 11439: }
1.612 raeburn 11440: foreach my $item (keys(%{$checks})) {
11441: if (ref($$curr_rules{$udom}) eq 'HASH') {
11442: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11443: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 11444: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11445: $$curr_rules{$udom}{$item});
1.612 raeburn 11446: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11447: if ($rule_check{$rule}) {
11448: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 11449: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11450: if (ref($inst_results) eq 'HASH') {
11451: if (ref($inst_results->{$user}) eq 'HASH') {
11452: if (keys(%{$inst_results->{$user}}) == 0) {
11453: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 11454: } elsif ($item eq 'id') {
11455: if ($inst_results->{$user}->{'id'} eq '') {
11456: $$alerts{$item}{$udom}{$uname} = 1;
11457: }
1.615 raeburn 11458: }
1.612 raeburn 11459: }
11460: }
1.615 raeburn 11461: }
11462: last;
1.585 raeburn 11463: }
11464: }
11465: }
11466: }
11467: }
11468: }
11469: }
11470: }
1.612 raeburn 11471: return;
11472: }
11473:
11474: sub user_rule_formats {
11475: my ($domain,$domdesc,$curr_rules,$check) = @_;
11476: my %text = (
11477: 'username' => 'Usernames',
11478: 'id' => 'IDs',
11479: );
11480: my $output;
11481: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11482: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11483: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 11484: $output = '<br />'.
11485: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11486: '<span class="LC_cusr_emph">','</span>',$domdesc).
11487: ' <ul>';
1.612 raeburn 11488: foreach my $rule (@{$ruleorder}) {
11489: if (ref($curr_rules) eq 'ARRAY') {
11490: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11491: if (ref($rules->{$rule}) eq 'HASH') {
11492: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11493: $rules->{$rule}{'desc'}.'</li>';
11494: }
11495: }
11496: }
11497: }
11498: $output .= '</ul>';
11499: }
11500: }
11501: return $output;
11502: }
11503:
11504: sub instrule_disallow_msg {
1.615 raeburn 11505: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11506: my $response;
11507: my %text = (
11508: item => 'username',
11509: items => 'usernames',
11510: match => 'matches',
11511: do => 'does',
11512: action => 'a username',
11513: one => 'one',
11514: );
11515: if ($count > 1) {
11516: $text{'item'} = 'usernames';
11517: $text{'match'} ='match';
11518: $text{'do'} = 'do';
11519: $text{'action'} = 'usernames',
11520: $text{'one'} = 'ones';
11521: }
11522: if ($checkitem eq 'id') {
11523: $text{'items'} = 'IDs';
11524: $text{'item'} = 'ID';
11525: $text{'action'} = 'an ID';
1.615 raeburn 11526: if ($count > 1) {
11527: $text{'item'} = 'IDs';
11528: $text{'action'} = 'IDs';
11529: }
1.612 raeburn 11530: }
1.674 bisitz 11531: $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 11532: if ($mode eq 'upload') {
11533: if ($checkitem eq 'username') {
11534: $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'}.");
11535: } elsif ($checkitem eq 'id') {
1.674 bisitz 11536: $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 11537: }
1.669 raeburn 11538: } elsif ($mode eq 'selfcreate') {
11539: if ($checkitem eq 'id') {
11540: $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.");
11541: }
1.615 raeburn 11542: } else {
11543: if ($checkitem eq 'username') {
11544: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11545: } elsif ($checkitem eq 'id') {
11546: $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.");
11547: }
1.612 raeburn 11548: }
11549: return $response;
1.585 raeburn 11550: }
11551:
1.624 raeburn 11552: sub personal_data_fieldtitles {
11553: my %fieldtitles = &Apache::lonlocal::texthash (
11554: id => 'Student/Employee ID',
11555: permanentemail => 'E-mail address',
11556: lastname => 'Last Name',
11557: firstname => 'First Name',
11558: middlename => 'Middle Name',
11559: generation => 'Generation',
11560: gen => 'Generation',
1.765 raeburn 11561: inststatus => 'Affiliation',
1.624 raeburn 11562: );
11563: return %fieldtitles;
11564: }
11565:
1.642 raeburn 11566: sub sorted_inst_types {
11567: my ($dom) = @_;
1.1075.2.70 raeburn 11568: my ($usertypes,$order);
11569: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11570: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11571: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11572: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11573: } else {
11574: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11575: }
1.642 raeburn 11576: my $othertitle = &mt('All users');
11577: if ($env{'request.course.id'}) {
1.668 raeburn 11578: $othertitle = &mt('Any users');
1.642 raeburn 11579: }
11580: my @types;
11581: if (ref($order) eq 'ARRAY') {
11582: @types = @{$order};
11583: }
11584: if (@types == 0) {
11585: if (ref($usertypes) eq 'HASH') {
11586: @types = sort(keys(%{$usertypes}));
11587: }
11588: }
11589: if (keys(%{$usertypes}) > 0) {
11590: $othertitle = &mt('Other users');
11591: }
11592: return ($othertitle,$usertypes,\@types);
11593: }
11594:
1.645 raeburn 11595: sub get_institutional_codes {
1.1075.2.157 raeburn 11596: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11597: # Get complete list of course sections to update
11598: my @currsections = ();
11599: my @currxlists = ();
1.1075.2.157 raeburn 11600: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11601: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11602: my $crskey = $crs.':'.$coursecode;
11603: @{$unclutteredsec{$crskey}} = ();
11604: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11605:
11606: if ($$settings{'internal.sectionnums'} ne '') {
11607: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11608: }
11609:
11610: if ($$settings{'internal.crosslistings'} ne '') {
11611: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11612: }
11613:
11614: if (@currxlists > 0) {
1.1075.2.157 raeburn 11615: foreach my $xl (@currxlists) {
11616: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11617: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11618: push(@{$allcourses},$1);
1.645 raeburn 11619: $$LC_code{$1} = $2;
11620: }
11621: }
11622: }
11623: }
1.1075.2.157 raeburn 11624:
1.645 raeburn 11625: if (@currsections > 0) {
1.1075.2.157 raeburn 11626: foreach my $sec (@currsections) {
11627: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11628: my $instsec = $1;
1.645 raeburn 11629: my $lc_sec = $2;
1.1075.2.157 raeburn 11630: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11631: push(@{$unclutteredsec{$crskey}},$instsec);
11632: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11633: }
11634: }
11635: }
11636: }
11637:
11638: if (@{$unclutteredsec{$crskey}} > 0) {
11639: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11640: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11641: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11642: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11643: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11644: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11645: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11646: }
11647: }
11648: }
11649: }
11650: return;
11651: }
11652:
1.971 raeburn 11653: sub get_standard_codeitems {
11654: return ('Year','Semester','Department','Number','Section');
11655: }
11656:
1.112 bowersj2 11657: =pod
11658:
1.780 raeburn 11659: =head1 Slot Helpers
11660:
11661: =over 4
11662:
11663: =item * sorted_slots()
11664:
1.1040 raeburn 11665: Sorts an array of slot names in order of an optional sort key,
11666: default sort is by slot start time (earliest first).
1.780 raeburn 11667:
11668: Inputs:
11669:
11670: =over 4
11671:
11672: slotsarr - Reference to array of unsorted slot names.
11673:
11674: slots - Reference to hash of hash, where outer hash keys are slot names.
11675:
1.1040 raeburn 11676: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11677:
1.549 albertel 11678: =back
11679:
1.780 raeburn 11680: Returns:
11681:
11682: =over 4
11683:
1.1040 raeburn 11684: sorted - An array of slot names sorted by a specified sort key
11685: (default sort key is start time of the slot).
1.780 raeburn 11686:
11687: =back
11688:
11689: =cut
11690:
11691:
11692: sub sorted_slots {
1.1040 raeburn 11693: my ($slotsarr,$slots,$sortkey) = @_;
11694: if ($sortkey eq '') {
11695: $sortkey = 'starttime';
11696: }
1.780 raeburn 11697: my @sorted;
11698: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11699: @sorted =
11700: sort {
11701: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11702: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11703: }
11704: if (ref($slots->{$a})) { return -1;}
11705: if (ref($slots->{$b})) { return 1;}
11706: return 0;
11707: } @{$slotsarr};
11708: }
11709: return @sorted;
11710: }
11711:
1.1040 raeburn 11712: =pod
11713:
11714: =item * get_future_slots()
11715:
11716: Inputs:
11717:
11718: =over 4
11719:
11720: cnum - course number
11721:
11722: cdom - course domain
11723:
11724: now - current UNIX time
11725:
11726: symb - optional symb
11727:
11728: =back
11729:
11730: Returns:
11731:
11732: =over 4
11733:
11734: sorted_reservable - ref to array of student_schedulable slots currently
11735: reservable, ordered by end date of reservation period.
11736:
11737: reservable_now - ref to hash of student_schedulable slots currently
11738: reservable.
11739:
11740: Keys in inner hash are:
11741: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11742: (b) endreserve: end date of reservation period.
11743: (c) uniqueperiod: start,end dates when slot is to be uniquely
11744: selected.
1.1040 raeburn 11745:
11746: sorted_future - ref to array of student_schedulable slots reservable in
11747: the future, ordered by start date of reservation period.
11748:
11749: future_reservable - ref to hash of student_schedulable slots reservable
11750: in the future.
11751:
11752: Keys in inner hash are:
11753: (a) symb: either blank or symb to which slot use is restricted.
11754: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11755: (c) uniqueperiod: start,end dates when slot is to be uniquely
11756: selected.
1.1040 raeburn 11757:
11758: =back
11759:
11760: =cut
11761:
11762: sub get_future_slots {
11763: my ($cnum,$cdom,$now,$symb) = @_;
11764: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11765: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11766: foreach my $slot (keys(%slots)) {
11767: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11768: if ($symb) {
11769: next if (($slots{$slot}->{'symb'} ne '') &&
11770: ($slots{$slot}->{'symb'} ne $symb));
11771: }
11772: if (($slots{$slot}->{'starttime'} > $now) &&
11773: ($slots{$slot}->{'endtime'} > $now)) {
11774: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11775: my $userallowed = 0;
11776: if ($slots{$slot}->{'allowedsections'}) {
11777: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11778: if (!defined($env{'request.role.sec'})
11779: && grep(/^No section assigned$/,@allowed_sec)) {
11780: $userallowed=1;
11781: } else {
11782: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11783: $userallowed=1;
11784: }
11785: }
11786: unless ($userallowed) {
11787: if (defined($env{'request.course.groups'})) {
11788: my @groups = split(/:/,$env{'request.course.groups'});
11789: foreach my $group (@groups) {
11790: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11791: $userallowed=1;
11792: last;
11793: }
11794: }
11795: }
11796: }
11797: }
11798: if ($slots{$slot}->{'allowedusers'}) {
11799: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11800: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11801: if (grep(/^\Q$user\E$/,@allowed_users)) {
11802: $userallowed = 1;
11803: }
11804: }
11805: next unless($userallowed);
11806: }
11807: my $startreserve = $slots{$slot}->{'startreserve'};
11808: my $endreserve = $slots{$slot}->{'endreserve'};
11809: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11810: my $uniqueperiod;
11811: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11812: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11813: }
1.1040 raeburn 11814: if (($startreserve < $now) &&
11815: (!$endreserve || $endreserve > $now)) {
11816: my $lastres = $endreserve;
11817: if (!$lastres) {
11818: $lastres = $slots{$slot}->{'starttime'};
11819: }
11820: $reservable_now{$slot} = {
11821: symb => $symb,
1.1075.2.104 raeburn 11822: endreserve => $lastres,
11823: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11824: };
11825: } elsif (($startreserve > $now) &&
11826: (!$endreserve || $endreserve > $startreserve)) {
11827: $future_reservable{$slot} = {
11828: symb => $symb,
1.1075.2.104 raeburn 11829: startreserve => $startreserve,
11830: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11831: };
11832: }
11833: }
11834: }
11835: my @unsorted_reservable = keys(%reservable_now);
11836: if (@unsorted_reservable > 0) {
11837: @sorted_reservable =
11838: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11839: }
11840: my @unsorted_future = keys(%future_reservable);
11841: if (@unsorted_future > 0) {
11842: @sorted_future =
11843: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11844: }
11845: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11846: }
1.780 raeburn 11847:
11848: =pod
11849:
1.1057 foxr 11850: =back
11851:
1.549 albertel 11852: =head1 HTTP Helpers
11853:
11854: =over 4
11855:
1.648 raeburn 11856: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11857:
1.258 albertel 11858: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11859: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11860: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11861:
11862: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11863: $possible_names is an ref to an array of form element names. As an example:
11864: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11865: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11866:
11867: =cut
1.1 albertel 11868:
1.6 albertel 11869: sub get_unprocessed_cgi {
1.25 albertel 11870: my ($query,$possible_names)= @_;
1.26 matthew 11871: # $Apache::lonxml::debug=1;
1.356 albertel 11872: foreach my $pair (split(/&/,$query)) {
11873: my ($name, $value) = split(/=/,$pair);
1.369 www 11874: $name = &unescape($name);
1.25 albertel 11875: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11876: $value =~ tr/+/ /;
11877: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11878: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11879: }
1.16 harris41 11880: }
1.6 albertel 11881: }
11882:
1.112 bowersj2 11883: =pod
11884:
1.648 raeburn 11885: =item * &cacheheader()
1.112 bowersj2 11886:
11887: returns cache-controlling header code
11888:
11889: =cut
11890:
1.7 albertel 11891: sub cacheheader {
1.258 albertel 11892: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11893: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11894: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11895: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11896: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11897: return $output;
1.7 albertel 11898: }
11899:
1.112 bowersj2 11900: =pod
11901:
1.648 raeburn 11902: =item * &no_cache($r)
1.112 bowersj2 11903:
11904: specifies header code to not have cache
11905:
11906: =cut
11907:
1.9 albertel 11908: sub no_cache {
1.216 albertel 11909: my ($r) = @_;
11910: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11911: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11912: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11913: $r->no_cache(1);
11914: $r->header_out("Expires" => $date);
11915: $r->header_out("Pragma" => "no-cache");
1.123 www 11916: }
11917:
11918: sub content_type {
1.181 albertel 11919: my ($r,$type,$charset) = @_;
1.299 foxr 11920: if ($r) {
11921: # Note that printout.pl calls this with undef for $r.
11922: &no_cache($r);
11923: }
1.258 albertel 11924: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11925: unless ($charset) {
11926: $charset=&Apache::lonlocal::current_encoding;
11927: }
11928: if ($charset) { $type.='; charset='.$charset; }
11929: if ($r) {
11930: $r->content_type($type);
11931: } else {
11932: print("Content-type: $type\n\n");
11933: }
1.9 albertel 11934: }
1.25 albertel 11935:
1.112 bowersj2 11936: =pod
11937:
1.648 raeburn 11938: =item * &add_to_env($name,$value)
1.112 bowersj2 11939:
1.258 albertel 11940: adds $name to the %env hash with value
1.112 bowersj2 11941: $value, if $name already exists, the entry is converted to an array
11942: reference and $value is added to the array.
11943:
11944: =cut
11945:
1.25 albertel 11946: sub add_to_env {
11947: my ($name,$value)=@_;
1.258 albertel 11948: if (defined($env{$name})) {
11949: if (ref($env{$name})) {
1.25 albertel 11950: #already have multiple values
1.258 albertel 11951: push(@{ $env{$name} },$value);
1.25 albertel 11952: } else {
11953: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11954: my $first=$env{$name};
11955: undef($env{$name});
11956: push(@{ $env{$name} },$first,$value);
1.25 albertel 11957: }
11958: } else {
1.258 albertel 11959: $env{$name}=$value;
1.25 albertel 11960: }
1.31 albertel 11961: }
1.149 albertel 11962:
11963: =pod
11964:
1.648 raeburn 11965: =item * &get_env_multiple($name)
1.149 albertel 11966:
1.258 albertel 11967: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11968: values may be defined and end up as an array ref.
11969:
11970: returns an array of values
11971:
11972: =cut
11973:
11974: sub get_env_multiple {
11975: my ($name) = @_;
11976: my @values;
1.258 albertel 11977: if (defined($env{$name})) {
1.149 albertel 11978: # exists is it an array
1.258 albertel 11979: if (ref($env{$name})) {
11980: @values=@{ $env{$name} };
1.149 albertel 11981: } else {
1.258 albertel 11982: $values[0]=$env{$name};
1.149 albertel 11983: }
11984: }
11985: return(@values);
11986: }
11987:
1.660 raeburn 11988: sub ask_for_embedded_content {
11989: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11990: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11991: %currsubfile,%unused,$rem);
1.1071 raeburn 11992: my $counter = 0;
11993: my $numnew = 0;
1.987 raeburn 11994: my $numremref = 0;
11995: my $numinvalid = 0;
11996: my $numpathchg = 0;
11997: my $numexisting = 0;
1.1071 raeburn 11998: my $numunused = 0;
11999: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 12000: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12001: my $heading = &mt('Upload embedded files');
12002: my $buttontext = &mt('Upload');
12003:
1.1075.2.11 raeburn 12004: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 12005: if ($actionurl eq '/adm/dependencies') {
12006: $navmap = Apache::lonnavmaps::navmap->new();
12007: }
12008: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12009: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 12010: }
1.1075.2.35 raeburn 12011: if (($actionurl eq '/adm/portfolio') ||
12012: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12013: my $current_path='/';
12014: if ($env{'form.currentpath'}) {
12015: $current_path = $env{'form.currentpath'};
12016: }
12017: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 12018: $udom = $cdom;
12019: $uname = $cnum;
1.984 raeburn 12020: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12021: } else {
12022: $udom = $env{'user.domain'};
12023: $uname = $env{'user.name'};
12024: $url = '/userfiles/portfolio';
12025: }
1.987 raeburn 12026: $toplevel = $url.'/';
1.984 raeburn 12027: $url .= $current_path;
12028: $getpropath = 1;
1.987 raeburn 12029: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12030: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12031: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12032: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12033: $toplevel = $url;
1.984 raeburn 12034: if ($rest ne '') {
1.987 raeburn 12035: $url .= $rest;
12036: }
12037: } elsif ($actionurl eq '/adm/coursedocs') {
12038: if (ref($args) eq 'HASH') {
1.1071 raeburn 12039: $url = $args->{'docs_url'};
12040: $toplevel = $url;
1.1075.2.11 raeburn 12041: if ($args->{'context'} eq 'paste') {
12042: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12043: ($path) =
12044: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12045: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12046: $fileloc =~ s{^/}{};
12047: }
1.1071 raeburn 12048: }
12049: } elsif ($actionurl eq '/adm/dependencies') {
12050: if ($env{'request.course.id'} ne '') {
12051: if (ref($args) eq 'HASH') {
12052: $url = $args->{'docs_url'};
12053: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 12054: $toplevel = $url;
12055: unless ($toplevel =~ m{^/}) {
12056: $toplevel = "/$url";
12057: }
1.1075.2.11 raeburn 12058: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 12059: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12060: $path = $1;
12061: } else {
12062: ($path) =
12063: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12064: }
1.1075.2.79 raeburn 12065: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12066: $fileloc = $toplevel;
12067: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12068: my ($udom,$uname,$fname) =
12069: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12070: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12071: } else {
12072: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12073: }
1.1071 raeburn 12074: $fileloc =~ s{^/}{};
12075: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12076: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12077: }
1.987 raeburn 12078: }
1.1075.2.35 raeburn 12079: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12080: $udom = $cdom;
12081: $uname = $cnum;
12082: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12083: $toplevel = $url;
12084: $path = $url;
12085: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12086: $fileloc =~ s{^/}{};
12087: }
12088: foreach my $file (keys(%{$allfiles})) {
12089: my $embed_file;
12090: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12091: $embed_file = $1;
12092: } else {
12093: $embed_file = $file;
12094: }
1.1075.2.55 raeburn 12095: my ($absolutepath,$cleaned_file);
12096: if ($embed_file =~ m{^\w+://}) {
12097: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 12098: $newfiles{$cleaned_file} = 1;
12099: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12100: } else {
1.1075.2.55 raeburn 12101: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12102: if ($embed_file =~ m{^/}) {
12103: $absolutepath = $embed_file;
12104: }
1.1075.2.47 raeburn 12105: if ($cleaned_file =~ m{/}) {
12106: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12107: $path = &check_for_traversal($path,$url,$toplevel);
12108: my $item = $fname;
12109: if ($path ne '') {
12110: $item = $path.'/'.$fname;
12111: $subdependencies{$path}{$fname} = 1;
12112: } else {
12113: $dependencies{$item} = 1;
12114: }
12115: if ($absolutepath) {
12116: $mapping{$item} = $absolutepath;
12117: } else {
12118: $mapping{$item} = $embed_file;
12119: }
12120: } else {
12121: $dependencies{$embed_file} = 1;
12122: if ($absolutepath) {
1.1075.2.47 raeburn 12123: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12124: } else {
1.1075.2.47 raeburn 12125: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12126: }
12127: }
1.984 raeburn 12128: }
12129: }
1.1071 raeburn 12130: my $dirptr = 16384;
1.984 raeburn 12131: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12132: $currsubfile{$path} = {};
1.1075.2.35 raeburn 12133: if (($actionurl eq '/adm/portfolio') ||
12134: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12135: my ($sublistref,$listerror) =
12136: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12137: if (ref($sublistref) eq 'ARRAY') {
12138: foreach my $line (@{$sublistref}) {
12139: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12140: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12141: }
1.984 raeburn 12142: }
1.987 raeburn 12143: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12144: if (opendir(my $dir,$url.'/'.$path)) {
12145: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12146: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12147: }
1.1075.2.11 raeburn 12148: } elsif (($actionurl eq '/adm/dependencies') ||
12149: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12150: ($args->{'context'} eq 'paste')) ||
12151: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12152: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 12153: my $dir;
12154: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12155: $dir = $fileloc;
12156: } else {
12157: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12158: }
1.1071 raeburn 12159: if ($dir ne '') {
12160: my ($sublistref,$listerror) =
12161: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12162: if (ref($sublistref) eq 'ARRAY') {
12163: foreach my $line (@{$sublistref}) {
12164: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12165: undef,$mtime)=split(/\&/,$line,12);
12166: unless (($testdir&$dirptr) ||
12167: ($file_name =~ /^\.\.?$/)) {
12168: $currsubfile{$path}{$file_name} = [$size,$mtime];
12169: }
12170: }
12171: }
12172: }
1.984 raeburn 12173: }
12174: }
12175: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12176: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12177: my $item = $path.'/'.$file;
12178: unless ($mapping{$item} eq $item) {
12179: $pathchanges{$item} = 1;
12180: }
12181: $existing{$item} = 1;
12182: $numexisting ++;
12183: } else {
12184: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12185: }
12186: }
1.1071 raeburn 12187: if ($actionurl eq '/adm/dependencies') {
12188: foreach my $path (keys(%currsubfile)) {
12189: if (ref($currsubfile{$path}) eq 'HASH') {
12190: foreach my $file (keys(%{$currsubfile{$path}})) {
12191: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 12192: next if (($rem ne '') &&
12193: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12194: (ref($navmap) &&
12195: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12196: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12197: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12198: $unused{$path.'/'.$file} = 1;
12199: }
12200: }
12201: }
12202: }
12203: }
1.984 raeburn 12204: }
1.987 raeburn 12205: my %currfile;
1.1075.2.35 raeburn 12206: if (($actionurl eq '/adm/portfolio') ||
12207: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12208: my ($dirlistref,$listerror) =
12209: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12210: if (ref($dirlistref) eq 'ARRAY') {
12211: foreach my $line (@{$dirlistref}) {
12212: my ($file_name,$rest) = split(/\&/,$line,2);
12213: $currfile{$file_name} = 1;
12214: }
1.984 raeburn 12215: }
1.987 raeburn 12216: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12217: if (opendir(my $dir,$url)) {
1.987 raeburn 12218: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12219: map {$currfile{$_} = 1;} @dir_list;
12220: }
1.1075.2.11 raeburn 12221: } elsif (($actionurl eq '/adm/dependencies') ||
12222: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12223: ($args->{'context'} eq 'paste')) ||
12224: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12225: if ($env{'request.course.id'} ne '') {
12226: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12227: if ($dir ne '') {
12228: my ($dirlistref,$listerror) =
12229: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12230: if (ref($dirlistref) eq 'ARRAY') {
12231: foreach my $line (@{$dirlistref}) {
12232: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12233: $size,undef,$mtime)=split(/\&/,$line,12);
12234: unless (($testdir&$dirptr) ||
12235: ($file_name =~ /^\.\.?$/)) {
12236: $currfile{$file_name} = [$size,$mtime];
12237: }
12238: }
12239: }
12240: }
12241: }
1.984 raeburn 12242: }
12243: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12244: if (exists($currfile{$file})) {
1.987 raeburn 12245: unless ($mapping{$file} eq $file) {
12246: $pathchanges{$file} = 1;
12247: }
12248: $existing{$file} = 1;
12249: $numexisting ++;
12250: } else {
1.984 raeburn 12251: $newfiles{$file} = 1;
12252: }
12253: }
1.1071 raeburn 12254: foreach my $file (keys(%currfile)) {
12255: unless (($file eq $filename) ||
12256: ($file eq $filename.'.bak') ||
12257: ($dependencies{$file})) {
1.1075.2.11 raeburn 12258: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 12259: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12260: next if (($rem ne '') &&
12261: (($env{"httpref.$rem".$file} ne '') ||
12262: (ref($navmap) &&
12263: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12264: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12265: ($navmap->getResourceByUrl($rem.$1)))))));
12266: }
1.1075.2.11 raeburn 12267: }
1.1071 raeburn 12268: $unused{$file} = 1;
12269: }
12270: }
1.1075.2.11 raeburn 12271: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12272: ($args->{'context'} eq 'paste')) {
12273: $counter = scalar(keys(%existing));
12274: $numpathchg = scalar(keys(%pathchanges));
12275: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 12276: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12277: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12278: $counter = scalar(keys(%existing));
12279: $numpathchg = scalar(keys(%pathchanges));
12280: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 12281: }
1.984 raeburn 12282: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12283: if ($actionurl eq '/adm/dependencies') {
12284: next if ($embed_file =~ m{^\w+://});
12285: }
1.660 raeburn 12286: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12287: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12288: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12289: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 12290: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12291: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12292: }
1.1075.2.35 raeburn 12293: $upload_output .= '</td>';
1.1071 raeburn 12294: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 12295: $upload_output.='<td align="right">'.
12296: '<span class="LC_info LC_fontsize_medium">'.
12297: &mt("URL points to web address").'</span>';
1.987 raeburn 12298: $numremref++;
1.660 raeburn 12299: } elsif ($args->{'error_on_invalid_names'}
12300: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 12301: $upload_output.='<td align="right"><span class="LC_warning">'.
12302: &mt('Invalid characters').'</span>';
1.987 raeburn 12303: $numinvalid++;
1.660 raeburn 12304: } else {
1.1075.2.35 raeburn 12305: $upload_output .= '<td>'.
12306: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12307: $embed_file,\%mapping,
1.1071 raeburn 12308: $allfiles,$codebase,'upload');
12309: $counter ++;
12310: $numnew ++;
1.987 raeburn 12311: }
12312: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12313: }
12314: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12315: if ($actionurl eq '/adm/dependencies') {
12316: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12317: $modify_output .= &start_data_table_row().
12318: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12319: '<img src="'.&icon($embed_file).'" border="0" />'.
12320: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12321: '<td>'.$size.'</td>'.
12322: '<td>'.$mtime.'</td>'.
12323: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12324: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12325: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12326: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12327: &embedded_file_element('upload_embedded',$counter,
12328: $embed_file,\%mapping,
12329: $allfiles,$codebase,'modify').
12330: '</div></td>'.
12331: &end_data_table_row()."\n";
12332: $counter ++;
12333: } else {
12334: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12335: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12336: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12337: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12338: &Apache::loncommon::end_data_table_row()."\n";
12339: }
12340: }
12341: my $delidx = $counter;
12342: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12343: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12344: $delete_output .= &start_data_table_row().
12345: '<td><img src="'.&icon($oldfile).'" />'.
12346: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12347: '<td>'.$size.'</td>'.
12348: '<td>'.$mtime.'</td>'.
12349: '<td><label><input type="checkbox" name="del_upload_dep" '.
12350: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12351: &embedded_file_element('upload_embedded',$delidx,
12352: $oldfile,\%mapping,$allfiles,
12353: $codebase,'delete').'</td>'.
12354: &end_data_table_row()."\n";
12355: $numunused ++;
12356: $delidx ++;
1.987 raeburn 12357: }
12358: if ($upload_output) {
12359: $upload_output = &start_data_table().
12360: $upload_output.
12361: &end_data_table()."\n";
12362: }
1.1071 raeburn 12363: if ($modify_output) {
12364: $modify_output = &start_data_table().
12365: &start_data_table_header_row().
12366: '<th>'.&mt('File').'</th>'.
12367: '<th>'.&mt('Size (KB)').'</th>'.
12368: '<th>'.&mt('Modified').'</th>'.
12369: '<th>'.&mt('Upload replacement?').'</th>'.
12370: &end_data_table_header_row().
12371: $modify_output.
12372: &end_data_table()."\n";
12373: }
12374: if ($delete_output) {
12375: $delete_output = &start_data_table().
12376: &start_data_table_header_row().
12377: '<th>'.&mt('File').'</th>'.
12378: '<th>'.&mt('Size (KB)').'</th>'.
12379: '<th>'.&mt('Modified').'</th>'.
12380: '<th>'.&mt('Delete?').'</th>'.
12381: &end_data_table_header_row().
12382: $delete_output.
12383: &end_data_table()."\n";
12384: }
1.987 raeburn 12385: my $applies = 0;
12386: if ($numremref) {
12387: $applies ++;
12388: }
12389: if ($numinvalid) {
12390: $applies ++;
12391: }
12392: if ($numexisting) {
12393: $applies ++;
12394: }
1.1071 raeburn 12395: if ($counter || $numunused) {
1.987 raeburn 12396: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12397: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12398: $state.'<h3>'.$heading.'</h3>';
12399: if ($actionurl eq '/adm/dependencies') {
12400: if ($numnew) {
12401: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12402: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12403: $upload_output.'<br />'."\n";
12404: }
12405: if ($numexisting) {
12406: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12407: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12408: $modify_output.'<br />'."\n";
12409: $buttontext = &mt('Save changes');
12410: }
12411: if ($numunused) {
12412: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12413: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12414: $delete_output.'<br />'."\n";
12415: $buttontext = &mt('Save changes');
12416: }
12417: } else {
12418: $output .= $upload_output.'<br />'."\n";
12419: }
12420: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12421: $counter.'" />'."\n";
12422: if ($actionurl eq '/adm/dependencies') {
12423: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12424: $numnew.'" />'."\n";
12425: } elsif ($actionurl eq '') {
1.987 raeburn 12426: $output .= '<input type="hidden" name="phase" value="three" />';
12427: }
12428: } elsif ($applies) {
12429: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12430: if ($applies > 1) {
12431: $output .=
1.1075.2.35 raeburn 12432: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12433: if ($numremref) {
12434: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12435: }
12436: if ($numinvalid) {
12437: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12438: }
12439: if ($numexisting) {
12440: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12441: }
12442: $output .= '</ul><br />';
12443: } elsif ($numremref) {
12444: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12445: } elsif ($numinvalid) {
12446: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12447: } elsif ($numexisting) {
12448: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12449: }
12450: $output .= $upload_output.'<br />';
12451: }
12452: my ($pathchange_output,$chgcount);
1.1071 raeburn 12453: $chgcount = $counter;
1.987 raeburn 12454: if (keys(%pathchanges) > 0) {
12455: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12456: if ($counter) {
1.987 raeburn 12457: $output .= &embedded_file_element('pathchange',$chgcount,
12458: $embed_file,\%mapping,
1.1071 raeburn 12459: $allfiles,$codebase,'change');
1.987 raeburn 12460: } else {
12461: $pathchange_output .=
12462: &start_data_table_row().
12463: '<td><input type ="checkbox" name="namechange" value="'.
12464: $chgcount.'" checked="checked" /></td>'.
12465: '<td>'.$mapping{$embed_file}.'</td>'.
12466: '<td>'.$embed_file.
12467: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12468: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12469: '</td>'.&end_data_table_row();
1.660 raeburn 12470: }
1.987 raeburn 12471: $numpathchg ++;
12472: $chgcount ++;
1.660 raeburn 12473: }
12474: }
1.1075.2.35 raeburn 12475: if (($counter) || ($numunused)) {
1.987 raeburn 12476: if ($numpathchg) {
12477: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12478: $numpathchg.'" />'."\n";
12479: }
12480: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12481: ($actionurl eq '/adm/imsimport')) {
12482: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12483: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12484: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12485: } elsif ($actionurl eq '/adm/dependencies') {
12486: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12487: }
1.1075.2.35 raeburn 12488: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12489: } elsif ($numpathchg) {
12490: my %pathchange = ();
12491: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12492: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12493: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 12494: }
1.987 raeburn 12495: }
1.1071 raeburn 12496: return ($output,$counter,$numpathchg);
1.987 raeburn 12497: }
12498:
1.1075.2.47 raeburn 12499: =pod
12500:
12501: =item * clean_path($name)
12502:
12503: Performs clean-up of directories, subdirectories and filename in an
12504: embedded object, referenced in an HTML file which is being uploaded
12505: to a course or portfolio, where
12506: "Upload embedded images/multimedia files if HTML file" checkbox was
12507: checked.
12508:
12509: Clean-up is similar to replacements in lonnet::clean_filename()
12510: except each / between sub-directory and next level is preserved.
12511:
12512: =cut
12513:
12514: sub clean_path {
12515: my ($embed_file) = @_;
12516: $embed_file =~s{^/+}{};
12517: my @contents;
12518: if ($embed_file =~ m{/}) {
12519: @contents = split(/\//,$embed_file);
12520: } else {
12521: @contents = ($embed_file);
12522: }
12523: my $lastidx = scalar(@contents)-1;
12524: for (my $i=0; $i<=$lastidx; $i++) {
12525: $contents[$i]=~s{\\}{/}g;
12526: $contents[$i]=~s/\s+/\_/g;
12527: $contents[$i]=~s{[^/\w\.\-]}{}g;
12528: if ($i == $lastidx) {
12529: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12530: }
12531: }
12532: if ($lastidx > 0) {
12533: return join('/',@contents);
12534: } else {
12535: return $contents[0];
12536: }
12537: }
12538:
1.987 raeburn 12539: sub embedded_file_element {
1.1071 raeburn 12540: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12541: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12542: (ref($codebase) eq 'HASH'));
12543: my $output;
1.1071 raeburn 12544: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12545: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12546: }
12547: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12548: &escape($embed_file).'" />';
12549: unless (($context eq 'upload_embedded') &&
12550: ($mapping->{$embed_file} eq $embed_file)) {
12551: $output .='
12552: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12553: }
12554: my $attrib;
12555: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12556: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12557: }
12558: $output .=
12559: "\n\t\t".
12560: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12561: $attrib.'" />';
12562: if (exists($codebase->{$mapping->{$embed_file}})) {
12563: $output .=
12564: "\n\t\t".
12565: '<input name="codebase_'.$num.'" type="hidden" value="'.
12566: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12567: }
1.987 raeburn 12568: return $output;
1.660 raeburn 12569: }
12570:
1.1071 raeburn 12571: sub get_dependency_details {
12572: my ($currfile,$currsubfile,$embed_file) = @_;
12573: my ($size,$mtime,$showsize,$showmtime);
12574: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12575: if ($embed_file =~ m{/}) {
12576: my ($path,$fname) = split(/\//,$embed_file);
12577: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12578: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12579: }
12580: } else {
12581: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12582: ($size,$mtime) = @{$currfile->{$embed_file}};
12583: }
12584: }
12585: $showsize = $size/1024.0;
12586: $showsize = sprintf("%.1f",$showsize);
12587: if ($mtime > 0) {
12588: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12589: }
12590: }
12591: return ($showsize,$showmtime);
12592: }
12593:
12594: sub ask_embedded_js {
12595: return <<"END";
12596: <script type="text/javascript"">
12597: // <![CDATA[
12598: function toggleBrowse(counter) {
12599: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12600: var fileid = document.getElementById('embedded_item_'+counter);
12601: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12602: if (chkboxid.checked == true) {
12603: uploaddivid.style.display='block';
12604: } else {
12605: uploaddivid.style.display='none';
12606: fileid.value = '';
12607: }
12608: }
12609: // ]]>
12610: </script>
12611:
12612: END
12613: }
12614:
1.661 raeburn 12615: sub upload_embedded {
12616: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12617: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12618: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12619: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12620: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12621: my $orig_uploaded_filename =
12622: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12623: foreach my $type ('orig','ref','attrib','codebase') {
12624: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12625: $env{'form.embedded_'.$type.'_'.$i} =
12626: &unescape($env{'form.embedded_'.$type.'_'.$i});
12627: }
12628: }
1.661 raeburn 12629: my ($path,$fname) =
12630: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12631: # no path, whole string is fname
12632: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12633: $fname = &Apache::lonnet::clean_filename($fname);
12634: # See if there is anything left
12635: next if ($fname eq '');
12636:
12637: # Check if file already exists as a file or directory.
12638: my ($state,$msg);
12639: if ($context eq 'portfolio') {
12640: my $port_path = $dirpath;
12641: if ($group ne '') {
12642: $port_path = "groups/$group/$port_path";
12643: }
1.987 raeburn 12644: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12645: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12646: $dir_root,$port_path,$disk_quota,
12647: $current_disk_usage,$uname,$udom);
12648: if ($state eq 'will_exceed_quota'
1.984 raeburn 12649: || $state eq 'file_locked') {
1.661 raeburn 12650: $output .= $msg;
12651: next;
12652: }
12653: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12654: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12655: if ($state eq 'exists') {
12656: $output .= $msg;
12657: next;
12658: }
12659: }
12660: # Check if extension is valid
12661: if (($fname =~ /\.(\w+)$/) &&
12662: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12663: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12664: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12665: next;
12666: } elsif (($fname =~ /\.(\w+)$/) &&
12667: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12668: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12669: next;
12670: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12671: $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 12672: next;
12673: }
12674: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12675: my $subdir = $path;
12676: $subdir =~ s{/+$}{};
1.661 raeburn 12677: if ($context eq 'portfolio') {
1.984 raeburn 12678: my $result;
12679: if ($state eq 'existingfile') {
12680: $result=
12681: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12682: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12683: } else {
1.984 raeburn 12684: $result=
12685: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12686: $dirpath.
1.1075.2.35 raeburn 12687: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12688: if ($result !~ m|^/uploaded/|) {
12689: $output .= '<span class="LC_error">'
12690: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12691: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12692: .'</span><br />';
12693: next;
12694: } else {
1.987 raeburn 12695: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12696: $path.$fname.'</span>').'<br />';
1.984 raeburn 12697: }
1.661 raeburn 12698: }
1.1075.2.35 raeburn 12699: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12700: my $extendedsubdir = $dirpath.'/'.$subdir;
12701: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12702: my $result =
1.1075.2.35 raeburn 12703: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12704: if ($result !~ m|^/uploaded/|) {
12705: $output .= '<span class="LC_error">'
12706: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12707: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12708: .'</span><br />';
12709: next;
12710: } else {
12711: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12712: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12713: if ($context eq 'syllabus') {
12714: &Apache::lonnet::make_public_indefinitely($result);
12715: }
1.987 raeburn 12716: }
1.661 raeburn 12717: } else {
12718: # Save the file
12719: my $target = $env{'form.embedded_item_'.$i};
12720: my $fullpath = $dir_root.$dirpath.'/'.$path;
12721: my $dest = $fullpath.$fname;
12722: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12723: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12724: my $count;
12725: my $filepath = $dir_root;
1.1027 raeburn 12726: foreach my $subdir (@parts) {
12727: $filepath .= "/$subdir";
12728: if (!-e $filepath) {
1.661 raeburn 12729: mkdir($filepath,0770);
12730: }
12731: }
12732: my $fh;
12733: if (!open($fh,'>'.$dest)) {
12734: &Apache::lonnet::logthis('Failed to create '.$dest);
12735: $output .= '<span class="LC_error">'.
1.1071 raeburn 12736: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12737: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12738: '</span><br />';
12739: } else {
12740: if (!print $fh $env{'form.embedded_item_'.$i}) {
12741: &Apache::lonnet::logthis('Failed to write to '.$dest);
12742: $output .= '<span class="LC_error">'.
1.1071 raeburn 12743: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12744: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12745: '</span><br />';
12746: } else {
1.987 raeburn 12747: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12748: $url.'</span>').'<br />';
12749: unless ($context eq 'testbank') {
12750: $footer .= &mt('View embedded file: [_1]',
12751: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12752: }
12753: }
12754: close($fh);
12755: }
12756: }
12757: if ($env{'form.embedded_ref_'.$i}) {
12758: $pathchange{$i} = 1;
12759: }
12760: }
12761: if ($output) {
12762: $output = '<p>'.$output.'</p>';
12763: }
12764: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12765: $returnflag = 'ok';
1.1071 raeburn 12766: my $numpathchgs = scalar(keys(%pathchange));
12767: if ($numpathchgs > 0) {
1.987 raeburn 12768: if ($context eq 'portfolio') {
12769: $output .= '<p>'.&mt('or').'</p>';
12770: } elsif ($context eq 'testbank') {
1.1071 raeburn 12771: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12772: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12773: $returnflag = 'modify_orightml';
12774: }
12775: }
1.1071 raeburn 12776: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12777: }
12778:
12779: sub modify_html_form {
12780: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12781: my $end = 0;
12782: my $modifyform;
12783: if ($context eq 'upload_embedded') {
12784: return unless (ref($pathchange) eq 'HASH');
12785: if ($env{'form.number_embedded_items'}) {
12786: $end += $env{'form.number_embedded_items'};
12787: }
12788: if ($env{'form.number_pathchange_items'}) {
12789: $end += $env{'form.number_pathchange_items'};
12790: }
12791: if ($end) {
12792: for (my $i=0; $i<$end; $i++) {
12793: if ($i < $env{'form.number_embedded_items'}) {
12794: next unless($pathchange->{$i});
12795: }
12796: $modifyform .=
12797: &start_data_table_row().
12798: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12799: 'checked="checked" /></td>'.
12800: '<td>'.$env{'form.embedded_ref_'.$i}.
12801: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12802: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12803: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12804: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12805: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12806: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12807: '<td>'.$env{'form.embedded_orig_'.$i}.
12808: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12809: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12810: &end_data_table_row();
1.1071 raeburn 12811: }
1.987 raeburn 12812: }
12813: } else {
12814: $modifyform = $pathchgtable;
12815: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12816: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12817: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12818: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12819: }
12820: }
12821: if ($modifyform) {
1.1071 raeburn 12822: if ($actionurl eq '/adm/dependencies') {
12823: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12824: }
1.987 raeburn 12825: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12826: '<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".
12827: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12828: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12829: '</ol></p>'."\n".'<p>'.
12830: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12831: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12832: &start_data_table()."\n".
12833: &start_data_table_header_row().
12834: '<th>'.&mt('Change?').'</th>'.
12835: '<th>'.&mt('Current reference').'</th>'.
12836: '<th>'.&mt('Required reference').'</th>'.
12837: &end_data_table_header_row()."\n".
12838: $modifyform.
12839: &end_data_table().'<br />'."\n".$hiddenstate.
12840: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12841: '</form>'."\n";
12842: }
12843: return;
12844: }
12845:
12846: sub modify_html_refs {
1.1075.2.35 raeburn 12847: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12848: my $container;
12849: if ($context eq 'portfolio') {
12850: $container = $env{'form.container'};
12851: } elsif ($context eq 'coursedoc') {
12852: $container = $env{'form.primaryurl'};
1.1071 raeburn 12853: } elsif ($context eq 'manage_dependencies') {
12854: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12855: $container = "/$container";
1.1075.2.35 raeburn 12856: } elsif ($context eq 'syllabus') {
12857: $container = $url;
1.987 raeburn 12858: } else {
1.1027 raeburn 12859: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12860: }
12861: my (%allfiles,%codebase,$output,$content);
12862: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12863: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12864: if (wantarray) {
12865: return ('',0,0);
12866: } else {
12867: return;
12868: }
12869: }
12870: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12871: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12872: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12873: if (wantarray) {
12874: return ('',0,0);
12875: } else {
12876: return;
12877: }
12878: }
1.987 raeburn 12879: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12880: if ($content eq '-1') {
12881: if (wantarray) {
12882: return ('',0,0);
12883: } else {
12884: return;
12885: }
12886: }
1.987 raeburn 12887: } else {
1.1071 raeburn 12888: unless ($container =~ /^\Q$dir_root\E/) {
12889: if (wantarray) {
12890: return ('',0,0);
12891: } else {
12892: return;
12893: }
12894: }
1.1075.2.128 raeburn 12895: if (open(my $fh,'<',$container)) {
1.987 raeburn 12896: $content = join('', <$fh>);
12897: close($fh);
12898: } else {
1.1071 raeburn 12899: if (wantarray) {
12900: return ('',0,0);
12901: } else {
12902: return;
12903: }
1.987 raeburn 12904: }
12905: }
12906: my ($count,$codebasecount) = (0,0);
12907: my $mm = new File::MMagic;
12908: my $mime_type = $mm->checktype_contents($content);
12909: if ($mime_type eq 'text/html') {
12910: my $parse_result =
12911: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12912: \%codebase,\$content);
12913: if ($parse_result eq 'ok') {
12914: foreach my $i (@changes) {
12915: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12916: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12917: if ($allfiles{$ref}) {
12918: my $newname = $orig;
12919: my ($attrib_regexp,$codebase);
1.1006 raeburn 12920: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12921: if ($attrib_regexp =~ /:/) {
12922: $attrib_regexp =~ s/\:/|/g;
12923: }
12924: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12925: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12926: $count += $numchg;
1.1075.2.35 raeburn 12927: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 12928: delete($allfiles{$ref});
1.987 raeburn 12929: }
12930: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12931: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12932: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12933: $codebasecount ++;
12934: }
12935: }
12936: }
1.1075.2.35 raeburn 12937: my $skiprewrites;
1.987 raeburn 12938: if ($count || $codebasecount) {
12939: my $saveresult;
1.1071 raeburn 12940: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12941: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12942: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12943: if ($url eq $container) {
12944: my ($fname) = ($container =~ m{/([^/]+)$});
12945: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12946: $count,'<span class="LC_filename">'.
1.1071 raeburn 12947: $fname.'</span>').'</p>';
1.987 raeburn 12948: } else {
12949: $output = '<p class="LC_error">'.
12950: &mt('Error: update failed for: [_1].',
12951: '<span class="LC_filename">'.
12952: $container.'</span>').'</p>';
12953: }
1.1075.2.35 raeburn 12954: if ($context eq 'syllabus') {
12955: unless ($saveresult eq 'ok') {
12956: $skiprewrites = 1;
12957: }
12958: }
1.987 raeburn 12959: } else {
1.1075.2.128 raeburn 12960: if (open(my $fh,'>',$container)) {
1.987 raeburn 12961: print $fh $content;
12962: close($fh);
12963: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12964: $count,'<span class="LC_filename">'.
12965: $container.'</span>').'</p>';
1.661 raeburn 12966: } else {
1.987 raeburn 12967: $output = '<p class="LC_error">'.
12968: &mt('Error: could not update [_1].',
12969: '<span class="LC_filename">'.
12970: $container.'</span>').'</p>';
1.661 raeburn 12971: }
12972: }
12973: }
1.1075.2.35 raeburn 12974: if (($context eq 'syllabus') && (!$skiprewrites)) {
12975: my ($actionurl,$state);
12976: $actionurl = "/public/$udom/$uname/syllabus";
12977: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12978: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12979: \%codebase,
12980: {'context' => 'rewrites',
12981: 'ignore_remote_references' => 1,});
12982: if (ref($mapping) eq 'HASH') {
12983: my $rewrites = 0;
12984: foreach my $key (keys(%{$mapping})) {
12985: next if ($key =~ m{^https?://});
12986: my $ref = $mapping->{$key};
12987: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12988: my $attrib;
12989: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12990: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12991: }
12992: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12993: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12994: $rewrites += $numchg;
12995: }
12996: }
12997: if ($rewrites) {
12998: my $saveresult;
12999: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13000: if ($url eq $container) {
13001: my ($fname) = ($container =~ m{/([^/]+)$});
13002: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13003: $count,'<span class="LC_filename">'.
13004: $fname.'</span>').'</p>';
13005: } else {
13006: $output .= '<p class="LC_error">'.
13007: &mt('Error: could not update links in [_1].',
13008: '<span class="LC_filename">'.
13009: $container.'</span>').'</p>';
13010:
13011: }
13012: }
13013: }
13014: }
1.987 raeburn 13015: } else {
13016: &logthis('Failed to parse '.$container.
13017: ' to modify references: '.$parse_result);
1.661 raeburn 13018: }
13019: }
1.1071 raeburn 13020: if (wantarray) {
13021: return ($output,$count,$codebasecount);
13022: } else {
13023: return $output;
13024: }
1.661 raeburn 13025: }
13026:
13027: sub check_for_existing {
13028: my ($path,$fname,$element) = @_;
13029: my ($state,$msg);
13030: if (-d $path.'/'.$fname) {
13031: $state = 'exists';
13032: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13033: } elsif (-e $path.'/'.$fname) {
13034: $state = 'exists';
13035: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13036: }
13037: if ($state eq 'exists') {
13038: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13039: }
13040: return ($state,$msg);
13041: }
13042:
13043: sub check_for_upload {
13044: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13045: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13046: my $filesize = length($env{'form.'.$element});
13047: if (!$filesize) {
13048: my $msg = '<span class="LC_error">'.
13049: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13050: '<span class="LC_filename">'.$fname.'</span>',
13051: $filesize).'<br />'.
1.1007 raeburn 13052: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13053: '</span>';
13054: return ('zero_bytes',$msg);
13055: }
13056: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13057: my $getpropath = 1;
1.1021 raeburn 13058: my ($dirlistref,$listerror) =
13059: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13060: my $found_file = 0;
13061: my $locked_file = 0;
1.991 raeburn 13062: my @lockers;
13063: my $navmap;
13064: if ($env{'request.course.id'}) {
13065: $navmap = Apache::lonnavmaps::navmap->new();
13066: }
1.1021 raeburn 13067: if (ref($dirlistref) eq 'ARRAY') {
13068: foreach my $line (@{$dirlistref}) {
13069: my ($file_name,$rest)=split(/\&/,$line,2);
13070: if ($file_name eq $fname){
13071: $file_name = $path.$file_name;
13072: if ($group ne '') {
13073: $file_name = $group.$file_name;
13074: }
13075: $found_file = 1;
13076: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13077: foreach my $lock (@lockers) {
13078: if (ref($lock) eq 'ARRAY') {
13079: my ($symb,$crsid) = @{$lock};
13080: if ($crsid eq $env{'request.course.id'}) {
13081: if (ref($navmap)) {
13082: my $res = $navmap->getBySymb($symb);
13083: foreach my $part (@{$res->parts()}) {
13084: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13085: unless (($slot_status == $res->RESERVED) ||
13086: ($slot_status == $res->RESERVED_LOCATION)) {
13087: $locked_file = 1;
13088: }
1.991 raeburn 13089: }
1.1021 raeburn 13090: } else {
13091: $locked_file = 1;
1.991 raeburn 13092: }
13093: } else {
13094: $locked_file = 1;
13095: }
13096: }
1.1021 raeburn 13097: }
13098: } else {
13099: my @info = split(/\&/,$rest);
13100: my $currsize = $info[6]/1000;
13101: if ($currsize < $filesize) {
13102: my $extra = $filesize - $currsize;
13103: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 13104: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13105: &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 13106: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13107: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13108: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13109: return ('will_exceed_quota',$msg);
13110: }
1.984 raeburn 13111: }
13112: }
1.661 raeburn 13113: }
13114: }
13115: }
13116: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 13117: my $msg = '<p class="LC_warning">'.
13118: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
13119: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13120: return ('will_exceed_quota',$msg);
13121: } elsif ($found_file) {
13122: if ($locked_file) {
1.1075.2.69 raeburn 13123: my $msg = '<p class="LC_warning">';
1.661 raeburn 13124: $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 13125: $msg .= '</p>';
1.661 raeburn 13126: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13127: return ('file_locked',$msg);
13128: } else {
1.1075.2.69 raeburn 13129: my $msg = '<p class="LC_error">';
1.984 raeburn 13130: $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 13131: $msg .= '</p>';
1.984 raeburn 13132: return ('existingfile',$msg);
1.661 raeburn 13133: }
13134: }
13135: }
13136:
1.987 raeburn 13137: sub check_for_traversal {
13138: my ($path,$url,$toplevel) = @_;
13139: my @parts=split(/\//,$path);
13140: my $cleanpath;
13141: my $fullpath = $url;
13142: for (my $i=0;$i<@parts;$i++) {
13143: next if ($parts[$i] eq '.');
13144: if ($parts[$i] eq '..') {
13145: $fullpath =~ s{([^/]+/)$}{};
13146: } else {
13147: $fullpath .= $parts[$i].'/';
13148: }
13149: }
13150: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13151: $cleanpath = $1;
13152: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13153: my $curr_toprel = $1;
13154: my @parts = split(/\//,$curr_toprel);
13155: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13156: my @urlparts = split(/\//,$url_toprel);
13157: my $doubledots;
13158: my $startdiff = -1;
13159: for (my $i=0; $i<@urlparts; $i++) {
13160: if ($startdiff == -1) {
13161: unless ($urlparts[$i] eq $parts[$i]) {
13162: $startdiff = $i;
13163: $doubledots .= '../';
13164: }
13165: } else {
13166: $doubledots .= '../';
13167: }
13168: }
13169: if ($startdiff > -1) {
13170: $cleanpath = $doubledots;
13171: for (my $i=$startdiff; $i<@parts; $i++) {
13172: $cleanpath .= $parts[$i].'/';
13173: }
13174: }
13175: }
13176: $cleanpath =~ s{(/)$}{};
13177: return $cleanpath;
13178: }
1.31 albertel 13179:
1.1053 raeburn 13180: sub is_archive_file {
13181: my ($mimetype) = @_;
13182: if (($mimetype eq 'application/octet-stream') ||
13183: ($mimetype eq 'application/x-stuffit') ||
13184: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13185: return 1;
13186: }
13187: return;
13188: }
13189:
13190: sub decompress_form {
1.1065 raeburn 13191: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13192: my %lt = &Apache::lonlocal::texthash (
13193: this => 'This file is an archive file.',
1.1067 raeburn 13194: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13195: itsc => 'Its contents are as follows:',
1.1053 raeburn 13196: youm => 'You may wish to extract its contents.',
13197: extr => 'Extract contents',
1.1067 raeburn 13198: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13199: proa => 'Process automatically?',
1.1053 raeburn 13200: yes => 'Yes',
13201: no => 'No',
1.1067 raeburn 13202: fold => 'Title for folder containing movie',
13203: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13204: );
1.1065 raeburn 13205: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13206: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13207: my $info = &list_archive_contents($fileloc,\@paths);
13208: if (@paths) {
13209: foreach my $path (@paths) {
13210: $path =~ s{^/}{};
1.1067 raeburn 13211: if ($path =~ m{^([^/]+)/$}) {
13212: $topdir = $1;
13213: }
1.1065 raeburn 13214: if ($path =~ m{^([^/]+)/}) {
13215: $toplevel{$1} = $path;
13216: } else {
13217: $toplevel{$path} = $path;
13218: }
13219: }
13220: }
1.1067 raeburn 13221: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 13222: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13223: "$topdir/media/",
13224: "$topdir/media/$topdir.mp4",
13225: "$topdir/media/FirstFrame.png",
13226: "$topdir/media/player.swf",
13227: "$topdir/media/swfobject.js",
13228: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 13229: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 13230: "$topdir/$topdir.mp4",
13231: "$topdir/$topdir\_config.xml",
13232: "$topdir/$topdir\_controller.swf",
13233: "$topdir/$topdir\_embed.css",
13234: "$topdir/$topdir\_First_Frame.png",
13235: "$topdir/$topdir\_player.html",
13236: "$topdir/$topdir\_Thumbnails.png",
13237: "$topdir/playerProductInstall.swf",
13238: "$topdir/scripts/",
13239: "$topdir/scripts/config_xml.js",
13240: "$topdir/scripts/handlebars.js",
13241: "$topdir/scripts/jquery-1.7.1.min.js",
13242: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13243: "$topdir/scripts/modernizr.js",
13244: "$topdir/scripts/player-min.js",
13245: "$topdir/scripts/swfobject.js",
13246: "$topdir/skins/",
13247: "$topdir/skins/configuration_express.xml",
13248: "$topdir/skins/express_show/",
13249: "$topdir/skins/express_show/player-min.css",
13250: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 13251: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13252: "$topdir/$topdir.mp4",
13253: "$topdir/$topdir\_config.xml",
13254: "$topdir/$topdir\_controller.swf",
13255: "$topdir/$topdir\_embed.css",
13256: "$topdir/$topdir\_First_Frame.png",
13257: "$topdir/$topdir\_player.html",
13258: "$topdir/$topdir\_Thumbnails.png",
13259: "$topdir/playerProductInstall.swf",
13260: "$topdir/scripts/",
13261: "$topdir/scripts/config_xml.js",
13262: "$topdir/scripts/techsmith-smart-player.min.js",
13263: "$topdir/skins/",
13264: "$topdir/skins/configuration_express.xml",
13265: "$topdir/skins/express_show/",
13266: "$topdir/skins/express_show/spritesheet.min.css",
13267: "$topdir/skins/express_show/spritesheet.png",
13268: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 13269: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13270: if (@diffs == 0) {
1.1075.2.59 raeburn 13271: $is_camtasia = 6;
13272: } else {
1.1075.2.81 raeburn 13273: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 13274: if (@diffs == 0) {
13275: $is_camtasia = 8;
1.1075.2.81 raeburn 13276: } else {
13277: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13278: if (@diffs == 0) {
13279: $is_camtasia = 8;
13280: }
1.1075.2.59 raeburn 13281: }
1.1067 raeburn 13282: }
13283: }
13284: my $output;
13285: if ($is_camtasia) {
13286: $output = <<"ENDCAM";
13287: <script type="text/javascript" language="Javascript">
13288: // <![CDATA[
13289:
13290: function camtasiaToggle() {
13291: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13292: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 13293: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13294: document.getElementById('camtasia_titles').style.display='block';
13295: } else {
13296: document.getElementById('camtasia_titles').style.display='none';
13297: }
13298: }
13299: }
13300: return;
13301: }
13302:
13303: // ]]>
13304: </script>
13305: <p>$lt{'camt'}</p>
13306: ENDCAM
1.1065 raeburn 13307: } else {
1.1067 raeburn 13308: $output = '<p>'.$lt{'this'};
13309: if ($info eq '') {
13310: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13311: } else {
13312: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13313: '<div><pre>'.$info.'</pre></div>';
13314: }
1.1065 raeburn 13315: }
1.1067 raeburn 13316: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13317: my $duplicates;
13318: my $num = 0;
13319: if (ref($dirlist) eq 'ARRAY') {
13320: foreach my $item (@{$dirlist}) {
13321: if (ref($item) eq 'ARRAY') {
13322: if (exists($toplevel{$item->[0]})) {
13323: $duplicates .=
13324: &start_data_table_row().
13325: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13326: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13327: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13328: 'value="1" />'.&mt('Yes').'</label>'.
13329: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13330: '<td>'.$item->[0].'</td>';
13331: if ($item->[2]) {
13332: $duplicates .= '<td>'.&mt('Directory').'</td>';
13333: } else {
13334: $duplicates .= '<td>'.&mt('File').'</td>';
13335: }
13336: $duplicates .= '<td>'.$item->[3].'</td>'.
13337: '<td>'.
13338: &Apache::lonlocal::locallocaltime($item->[4]).
13339: '</td>'.
13340: &end_data_table_row();
13341: $num ++;
13342: }
13343: }
13344: }
13345: }
13346: my $itemcount;
13347: if (@paths > 0) {
13348: $itemcount = scalar(@paths);
13349: } else {
13350: $itemcount = 1;
13351: }
1.1067 raeburn 13352: if ($is_camtasia) {
13353: $output .= $lt{'auto'}.'<br />'.
13354: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 13355: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13356: $lt{'yes'}.'</label> <label>'.
13357: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13358: $lt{'no'}.'</label></span><br />'.
13359: '<div id="camtasia_titles" style="display:block">'.
13360: &Apache::lonhtmlcommon::start_pick_box().
13361: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13362: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13363: &Apache::lonhtmlcommon::row_closure().
13364: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13365: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13366: &Apache::lonhtmlcommon::row_closure(1).
13367: &Apache::lonhtmlcommon::end_pick_box().
13368: '</div>';
13369: }
1.1065 raeburn 13370: $output .=
13371: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13372: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13373: "\n";
1.1065 raeburn 13374: if ($duplicates ne '') {
13375: $output .= '<p><span class="LC_warning">'.
13376: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13377: &start_data_table().
13378: &start_data_table_header_row().
13379: '<th>'.&mt('Overwrite?').'</th>'.
13380: '<th>'.&mt('Name').'</th>'.
13381: '<th>'.&mt('Type').'</th>'.
13382: '<th>'.&mt('Size').'</th>'.
13383: '<th>'.&mt('Last modified').'</th>'.
13384: &end_data_table_header_row().
13385: $duplicates.
13386: &end_data_table().
13387: '</p>';
13388: }
1.1067 raeburn 13389: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13390: if (ref($hiddenelements) eq 'HASH') {
13391: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13392: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13393: }
13394: }
13395: $output .= <<"END";
1.1067 raeburn 13396: <br />
1.1053 raeburn 13397: <input type="submit" name="decompress" value="$lt{'extr'}" />
13398: </form>
13399: $noextract
13400: END
13401: return $output;
13402: }
13403:
1.1065 raeburn 13404: sub decompression_utility {
13405: my ($program) = @_;
13406: my @utilities = ('tar','gunzip','bunzip2','unzip');
13407: my $location;
13408: if (grep(/^\Q$program\E$/,@utilities)) {
13409: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13410: '/usr/sbin/') {
13411: if (-x $dir.$program) {
13412: $location = $dir.$program;
13413: last;
13414: }
13415: }
13416: }
13417: return $location;
13418: }
13419:
13420: sub list_archive_contents {
13421: my ($file,$pathsref) = @_;
13422: my (@cmd,$output);
13423: my $needsregexp;
13424: if ($file =~ /\.zip$/) {
13425: @cmd = (&decompression_utility('unzip'),"-l");
13426: $needsregexp = 1;
13427: } elsif (($file =~ m/\.tar\.gz$/) ||
13428: ($file =~ /\.tgz$/)) {
13429: @cmd = (&decompression_utility('tar'),"-ztf");
13430: } elsif ($file =~ /\.tar\.bz2$/) {
13431: @cmd = (&decompression_utility('tar'),"-jtf");
13432: } elsif ($file =~ m|\.tar$|) {
13433: @cmd = (&decompression_utility('tar'),"-tf");
13434: }
13435: if (@cmd) {
13436: undef($!);
13437: undef($@);
13438: if (open(my $fh,"-|", @cmd, $file)) {
13439: while (my $line = <$fh>) {
13440: $output .= $line;
13441: chomp($line);
13442: my $item;
13443: if ($needsregexp) {
13444: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13445: } else {
13446: $item = $line;
13447: }
13448: if ($item ne '') {
13449: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13450: push(@{$pathsref},$item);
13451: }
13452: }
13453: }
13454: close($fh);
13455: }
13456: }
13457: return $output;
13458: }
13459:
1.1053 raeburn 13460: sub decompress_uploaded_file {
13461: my ($file,$dir) = @_;
13462: &Apache::lonnet::appenv({'cgi.file' => $file});
13463: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13464: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13465: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13466: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13467: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13468: my $decompressed = $env{'cgi.decompressed'};
13469: &Apache::lonnet::delenv('cgi.file');
13470: &Apache::lonnet::delenv('cgi.dir');
13471: &Apache::lonnet::delenv('cgi.decompressed');
13472: return ($decompressed,$result);
13473: }
13474:
1.1055 raeburn 13475: sub process_decompression {
13476: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 13477: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13478: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13479: &mt('Unexpected file path.').'</p>'."\n";
13480: }
13481: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13482: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13483: &mt('Unexpected course context.').'</p>'."\n";
13484: }
13485: unless ($file eq &Apache::lonnet::clean_filename($file)) {
13486: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13487: &mt('Filename contained unexpected characters.').'</p>'."\n";
13488: }
1.1055 raeburn 13489: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 13490: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 13491: $error = &mt('Filename not a supported archive file type.').
13492: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13493: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13494: } else {
13495: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13496: if ($docuhome eq 'no_host') {
13497: $error = &mt('Could not determine home server for course.');
13498: } else {
13499: my @ids=&Apache::lonnet::current_machine_ids();
13500: my $currdir = "$dir_root/$destination";
13501: if (grep(/^\Q$docuhome\E$/,@ids)) {
13502: $dir = &LONCAPA::propath($docudom,$docuname).
13503: "$dir_root/$destination";
13504: } else {
13505: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13506: "$dir_root/$docudom/$docuname/$destination";
13507: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13508: $error = &mt('Archive file not found.');
13509: }
13510: }
1.1065 raeburn 13511: my (@to_overwrite,@to_skip);
13512: if ($env{'form.archive_overwrite_total'} > 0) {
13513: my $total = $env{'form.archive_overwrite_total'};
13514: for (my $i=0; $i<$total; $i++) {
13515: if ($env{'form.archive_overwrite_'.$i} == 1) {
13516: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13517: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13518: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13519: }
13520: }
13521: }
13522: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 13523: my $numoverwrite = scalar(@to_overwrite);
13524: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13525: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13526: } elsif ($dir eq '') {
1.1055 raeburn 13527: $error = &mt('Directory containing archive file unavailable.');
13528: } elsif (!$error) {
1.1065 raeburn 13529: my ($decompressed,$display);
1.1075.2.128 raeburn 13530: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13531: my $tempdir = time.'_'.$$.int(rand(10000));
13532: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 13533: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13534: ($decompressed,$display) =
13535: &decompress_uploaded_file($file,"$dir/$tempdir");
13536: foreach my $item (@to_skip) {
13537: if (($item ne '') && ($item !~ /\.\./)) {
13538: if (-f "$dir/$tempdir/$item") {
13539: unlink("$dir/$tempdir/$item");
13540: } elsif (-d "$dir/$tempdir/$item") {
13541: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
13542: }
13543: }
13544: }
13545: foreach my $item (@to_overwrite) {
13546: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13547: if (($item ne '') && ($item !~ /\.\./)) {
13548: if (-f "$dir/$item") {
13549: unlink("$dir/$item");
13550: } elsif (-d "$dir/$item") {
13551: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
13552: }
13553: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13554: }
1.1065 raeburn 13555: }
13556: }
1.1075.2.128 raeburn 13557: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13558: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13559: }
1.1065 raeburn 13560: }
13561: } else {
13562: ($decompressed,$display) =
13563: &decompress_uploaded_file($file,$dir);
13564: }
1.1055 raeburn 13565: if ($decompressed eq 'ok') {
1.1065 raeburn 13566: $output = '<p class="LC_info">'.
13567: &mt('Files extracted successfully from archive.').
13568: '</p>'."\n";
1.1055 raeburn 13569: my ($warning,$result,@contents);
13570: my ($newdirlistref,$newlisterror) =
13571: &Apache::lonnet::dirlist($currdir,$docudom,
13572: $docuname,1);
13573: my (%is_dir,%changes,@newitems);
13574: my $dirptr = 16384;
1.1065 raeburn 13575: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13576: foreach my $dir_line (@{$newdirlistref}) {
13577: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13578: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13579: push(@newitems,$item);
13580: if ($dirptr&$testdir) {
13581: $is_dir{$item} = 1;
13582: }
13583: $changes{$item} = 1;
13584: }
13585: }
13586: }
13587: if (keys(%changes) > 0) {
13588: foreach my $item (sort(@newitems)) {
13589: if ($changes{$item}) {
13590: push(@contents,$item);
13591: }
13592: }
13593: }
13594: if (@contents > 0) {
1.1067 raeburn 13595: my $wantform;
13596: unless ($env{'form.autoextract_camtasia'}) {
13597: $wantform = 1;
13598: }
1.1056 raeburn 13599: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13600: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13601: $currdir,\%is_dir,
13602: \%children,\%parent,
1.1056 raeburn 13603: \@contents,\%dirorder,
13604: \%titles,$wantform);
1.1055 raeburn 13605: if ($datatable ne '') {
13606: $output .= &archive_options_form('decompressed',$datatable,
13607: $count,$hiddenelem);
1.1065 raeburn 13608: my $startcount = 6;
1.1055 raeburn 13609: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13610: \%titles,\%children);
1.1055 raeburn 13611: }
1.1067 raeburn 13612: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13613: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13614: my %displayed;
13615: my $total = 1;
13616: $env{'form.archive_directory'} = [];
13617: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13618: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13619: $path =~ s{/$}{};
13620: my $item;
13621: if ($path ne '') {
13622: $item = "$path/$titles{$i}";
13623: } else {
13624: $item = $titles{$i};
13625: }
13626: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13627: if ($item eq $contents[0]) {
13628: push(@{$env{'form.archive_directory'}},$i);
13629: $env{'form.archive_'.$i} = 'display';
13630: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13631: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13632: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13633: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13634: $env{'form.archive_'.$i} = 'display';
13635: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13636: $displayed{'web'} = $i;
13637: } else {
1.1075.2.59 raeburn 13638: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13639: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13640: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13641: push(@{$env{'form.archive_directory'}},$i);
13642: }
13643: $env{'form.archive_'.$i} = 'dependency';
13644: }
13645: $total ++;
13646: }
13647: for (my $i=1; $i<$total; $i++) {
13648: next if ($i == $displayed{'web'});
13649: next if ($i == $displayed{'folder'});
13650: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13651: }
13652: $env{'form.phase'} = 'decompress_cleanup';
13653: $env{'form.archivedelete'} = 1;
13654: $env{'form.archive_count'} = $total-1;
13655: $output .=
13656: &process_extracted_files('coursedocs',$docudom,
13657: $docuname,$destination,
13658: $dir_root,$hiddenelem);
13659: }
1.1055 raeburn 13660: } else {
13661: $warning = &mt('No new items extracted from archive file.');
13662: }
13663: } else {
13664: $output = $display;
13665: $error = &mt('An error occurred during extraction from the archive file.');
13666: }
13667: }
13668: }
13669: }
13670: if ($error) {
13671: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13672: $error.'</p>'."\n";
13673: }
13674: if ($warning) {
13675: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13676: }
13677: return $output;
13678: }
13679:
13680: sub get_extracted {
1.1056 raeburn 13681: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13682: $titles,$wantform) = @_;
1.1055 raeburn 13683: my $count = 0;
13684: my $depth = 0;
13685: my $datatable;
1.1056 raeburn 13686: my @hierarchy;
1.1055 raeburn 13687: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13688: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13689: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13690: foreach my $item (@{$contents}) {
13691: $count ++;
1.1056 raeburn 13692: @{$dirorder->{$count}} = @hierarchy;
13693: $titles->{$count} = $item;
1.1055 raeburn 13694: &archive_hierarchy($depth,$count,$parent,$children);
13695: if ($wantform) {
13696: $datatable .= &archive_row($is_dir->{$item},$item,
13697: $currdir,$depth,$count);
13698: }
13699: if ($is_dir->{$item}) {
13700: $depth ++;
1.1056 raeburn 13701: push(@hierarchy,$count);
13702: $parent->{$depth} = $count;
1.1055 raeburn 13703: $datatable .=
13704: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13705: \$depth,\$count,\@hierarchy,$dirorder,
13706: $children,$parent,$titles,$wantform);
1.1055 raeburn 13707: $depth --;
1.1056 raeburn 13708: pop(@hierarchy);
1.1055 raeburn 13709: }
13710: }
13711: return ($count,$datatable);
13712: }
13713:
13714: sub recurse_extracted_archive {
1.1056 raeburn 13715: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13716: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13717: my $result='';
1.1056 raeburn 13718: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13719: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13720: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13721: return $result;
13722: }
13723: my $dirptr = 16384;
13724: my ($newdirlistref,$newlisterror) =
13725: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13726: if (ref($newdirlistref) eq 'ARRAY') {
13727: foreach my $dir_line (@{$newdirlistref}) {
13728: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13729: unless ($item =~ /^\.+$/) {
13730: $$count ++;
1.1056 raeburn 13731: @{$dirorder->{$$count}} = @{$hierarchy};
13732: $titles->{$$count} = $item;
1.1055 raeburn 13733: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13734:
1.1055 raeburn 13735: my $is_dir;
13736: if ($dirptr&$testdir) {
13737: $is_dir = 1;
13738: }
13739: if ($wantform) {
13740: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13741: }
13742: if ($is_dir) {
13743: $$depth ++;
1.1056 raeburn 13744: push(@{$hierarchy},$$count);
13745: $parent->{$$depth} = $$count;
1.1055 raeburn 13746: $result .=
13747: &recurse_extracted_archive("$currdir/$item",$docudom,
13748: $docuname,$depth,$count,
1.1056 raeburn 13749: $hierarchy,$dirorder,$children,
13750: $parent,$titles,$wantform);
1.1055 raeburn 13751: $$depth --;
1.1056 raeburn 13752: pop(@{$hierarchy});
1.1055 raeburn 13753: }
13754: }
13755: }
13756: }
13757: return $result;
13758: }
13759:
13760: sub archive_hierarchy {
13761: my ($depth,$count,$parent,$children) =@_;
13762: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13763: if (exists($parent->{$depth})) {
13764: $children->{$parent->{$depth}} .= $count.':';
13765: }
13766: }
13767: return;
13768: }
13769:
13770: sub archive_row {
13771: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13772: my ($name) = ($item =~ m{([^/]+)$});
13773: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13774: 'display' => 'Add as file',
1.1055 raeburn 13775: 'dependency' => 'Include as dependency',
13776: 'discard' => 'Discard',
13777: );
13778: if ($is_dir) {
1.1059 raeburn 13779: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13780: }
1.1056 raeburn 13781: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13782: my $offset = 0;
1.1055 raeburn 13783: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13784: $offset ++;
1.1065 raeburn 13785: if ($action ne 'display') {
13786: $offset ++;
13787: }
1.1055 raeburn 13788: $output .= '<td><span class="LC_nobreak">'.
13789: '<label><input type="radio" name="archive_'.$count.
13790: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13791: my $text = $choices{$action};
13792: if ($is_dir) {
13793: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13794: if ($action eq 'display') {
1.1059 raeburn 13795: $text = &mt('Add as folder');
1.1055 raeburn 13796: }
1.1056 raeburn 13797: } else {
13798: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13799:
13800: }
13801: $output .= ' /> '.$choices{$action}.'</label></span>';
13802: if ($action eq 'dependency') {
13803: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13804: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13805: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13806: '<option value=""></option>'."\n".
13807: '</select>'."\n".
13808: '</div>';
1.1059 raeburn 13809: } elsif ($action eq 'display') {
13810: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13811: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13812: '</div>';
1.1055 raeburn 13813: }
1.1056 raeburn 13814: $output .= '</td>';
1.1055 raeburn 13815: }
13816: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13817: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13818: for (my $i=0; $i<$depth; $i++) {
13819: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13820: }
13821: if ($is_dir) {
13822: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13823: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13824: } else {
13825: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13826: }
13827: $output .= ' '.$name.'</td>'."\n".
13828: &end_data_table_row();
13829: return $output;
13830: }
13831:
13832: sub archive_options_form {
1.1065 raeburn 13833: my ($form,$display,$count,$hiddenelem) = @_;
13834: my %lt = &Apache::lonlocal::texthash(
13835: perm => 'Permanently remove archive file?',
13836: hows => 'How should each extracted item be incorporated in the course?',
13837: cont => 'Content actions for all',
13838: addf => 'Add as folder/file',
13839: incd => 'Include as dependency for a displayed file',
13840: disc => 'Discard',
13841: no => 'No',
13842: yes => 'Yes',
13843: save => 'Save',
13844: );
13845: my $output = <<"END";
13846: <form name="$form" method="post" action="">
13847: <p><span class="LC_nobreak">$lt{'perm'}
13848: <label>
13849: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13850: </label>
13851:
13852: <label>
13853: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13854: </span>
13855: </p>
13856: <input type="hidden" name="phase" value="decompress_cleanup" />
13857: <br />$lt{'hows'}
13858: <div class="LC_columnSection">
13859: <fieldset>
13860: <legend>$lt{'cont'}</legend>
13861: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13862: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13863: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13864: </fieldset>
13865: </div>
13866: END
13867: return $output.
1.1055 raeburn 13868: &start_data_table()."\n".
1.1065 raeburn 13869: $display."\n".
1.1055 raeburn 13870: &end_data_table()."\n".
13871: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13872: $hiddenelem.
1.1065 raeburn 13873: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13874: '</form>';
13875: }
13876:
13877: sub archive_javascript {
1.1056 raeburn 13878: my ($startcount,$numitems,$titles,$children) = @_;
13879: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13880: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13881: my $scripttag = <<START;
13882: <script type="text/javascript">
13883: // <![CDATA[
13884:
13885: function checkAll(form,prefix) {
13886: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13887: for (var i=0; i < form.elements.length; i++) {
13888: var id = form.elements[i].id;
13889: if ((id != '') && (id != undefined)) {
13890: if (idstr.test(id)) {
13891: if (form.elements[i].type == 'radio') {
13892: form.elements[i].checked = true;
1.1056 raeburn 13893: var nostart = i-$startcount;
1.1059 raeburn 13894: var offset = nostart%7;
13895: var count = (nostart-offset)/7;
1.1056 raeburn 13896: dependencyCheck(form,count,offset);
1.1055 raeburn 13897: }
13898: }
13899: }
13900: }
13901: }
13902:
13903: function propagateCheck(form,count) {
13904: if (count > 0) {
1.1059 raeburn 13905: var startelement = $startcount + ((count-1) * 7);
13906: for (var j=1; j<6; j++) {
13907: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13908: var item = startelement + j;
13909: if (form.elements[item].type == 'radio') {
13910: if (form.elements[item].checked) {
13911: containerCheck(form,count,j);
13912: break;
13913: }
1.1055 raeburn 13914: }
13915: }
13916: }
13917: }
13918: }
13919:
13920: numitems = $numitems
1.1056 raeburn 13921: var titles = new Array(numitems);
13922: var parents = new Array(numitems);
1.1055 raeburn 13923: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13924: parents[i] = new Array;
1.1055 raeburn 13925: }
1.1059 raeburn 13926: var maintitle = '$maintitle';
1.1055 raeburn 13927:
13928: START
13929:
1.1056 raeburn 13930: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13931: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13932: for (my $i=0; $i<@contents; $i ++) {
13933: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13934: }
13935: }
13936:
1.1056 raeburn 13937: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13938: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13939: }
13940:
1.1055 raeburn 13941: $scripttag .= <<END;
13942:
13943: function containerCheck(form,count,offset) {
13944: if (count > 0) {
1.1056 raeburn 13945: dependencyCheck(form,count,offset);
1.1059 raeburn 13946: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13947: form.elements[item].checked = true;
13948: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13949: if (parents[count].length > 0) {
13950: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13951: containerCheck(form,parents[count][j],offset);
13952: }
13953: }
13954: }
13955: }
13956: }
13957:
13958: function dependencyCheck(form,count,offset) {
13959: if (count > 0) {
1.1059 raeburn 13960: var chosen = (offset+$startcount)+7*(count-1);
13961: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13962: var currtype = form.elements[depitem].type;
13963: if (form.elements[chosen].value == 'dependency') {
13964: document.getElementById('arc_depon_'+count).style.display='block';
13965: form.elements[depitem].options.length = 0;
13966: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 13967: for (var i=1; i<=numitems; i++) {
13968: if (i == count) {
13969: continue;
13970: }
1.1059 raeburn 13971: var startelement = $startcount + (i-1) * 7;
13972: for (var j=1; j<6; j++) {
13973: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13974: var item = startelement + j;
13975: if (form.elements[item].type == 'radio') {
13976: if (form.elements[item].checked) {
13977: if (form.elements[item].value == 'display') {
13978: var n = form.elements[depitem].options.length;
13979: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13980: }
13981: }
13982: }
13983: }
13984: }
13985: }
13986: } else {
13987: document.getElementById('arc_depon_'+count).style.display='none';
13988: form.elements[depitem].options.length = 0;
13989: form.elements[depitem].options[0] = new Option('Select','',true,true);
13990: }
1.1059 raeburn 13991: titleCheck(form,count,offset);
1.1056 raeburn 13992: }
13993: }
13994:
13995: function propagateSelect(form,count,offset) {
13996: if (count > 0) {
1.1065 raeburn 13997: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13998: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13999: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14000: if (parents[count].length > 0) {
14001: for (var j=0; j<parents[count].length; j++) {
14002: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14003: }
14004: }
14005: }
14006: }
14007: }
1.1056 raeburn 14008:
14009: function containerSelect(form,count,offset,picked) {
14010: if (count > 0) {
1.1065 raeburn 14011: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14012: if (form.elements[item].type == 'radio') {
14013: if (form.elements[item].value == 'dependency') {
14014: if (form.elements[item+1].type == 'select-one') {
14015: for (var i=0; i<form.elements[item+1].options.length; i++) {
14016: if (form.elements[item+1].options[i].value == picked) {
14017: form.elements[item+1].selectedIndex = i;
14018: break;
14019: }
14020: }
14021: }
14022: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14023: if (parents[count].length > 0) {
14024: for (var j=0; j<parents[count].length; j++) {
14025: containerSelect(form,parents[count][j],offset,picked);
14026: }
14027: }
14028: }
14029: }
14030: }
14031: }
14032: }
14033:
1.1059 raeburn 14034: function titleCheck(form,count,offset) {
14035: if (count > 0) {
14036: var chosen = (offset+$startcount)+7*(count-1);
14037: var depitem = $startcount + ((count-1) * 7) + 2;
14038: var currtype = form.elements[depitem].type;
14039: if (form.elements[chosen].value == 'display') {
14040: document.getElementById('arc_title_'+count).style.display='block';
14041: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14042: document.getElementById('archive_title_'+count).value=maintitle;
14043: }
14044: } else {
14045: document.getElementById('arc_title_'+count).style.display='none';
14046: if (currtype == 'text') {
14047: document.getElementById('archive_title_'+count).value='';
14048: }
14049: }
14050: }
14051: return;
14052: }
14053:
1.1055 raeburn 14054: // ]]>
14055: </script>
14056: END
14057: return $scripttag;
14058: }
14059:
14060: sub process_extracted_files {
1.1067 raeburn 14061: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14062: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 14063: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14064: my @ids=&Apache::lonnet::current_machine_ids();
14065: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14066: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14067: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14068: if (grep(/^\Q$docuhome\E$/,@ids)) {
14069: $prefix = &LONCAPA::propath($docudom,$docuname);
14070: $pathtocheck = "$dir_root/$destination";
14071: $dir = $dir_root;
14072: $ishome = 1;
14073: } else {
14074: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14075: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 14076: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14077: }
14078: my $currdir = "$dir_root/$destination";
14079: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14080: if ($env{'form.folderpath'}) {
14081: my @items = split('&',$env{'form.folderpath'});
14082: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 14083: if ($env{'form.folderpath'} =~ /\:1$/) {
14084: $containers{'0'}='page';
14085: } else {
14086: $containers{'0'}='sequence';
14087: }
1.1055 raeburn 14088: }
14089: my @archdirs = &get_env_multiple('form.archive_directory');
14090: if ($numitems) {
14091: for (my $i=1; $i<=$numitems; $i++) {
14092: my $path = $env{'form.archive_content_'.$i};
14093: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14094: my $item = $1;
14095: $toplevelitems{$item} = $i;
14096: if (grep(/^\Q$i\E$/,@archdirs)) {
14097: $is_dir{$item} = 1;
14098: }
14099: }
14100: }
14101: }
1.1067 raeburn 14102: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14103: if (keys(%toplevelitems) > 0) {
14104: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14105: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14106: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14107: }
1.1066 raeburn 14108: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14109: if ($numitems) {
14110: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 14111: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14112: my $path = $env{'form.archive_content_'.$i};
14113: if ($path =~ /^\Q$pathtocheck\E/) {
14114: if ($env{'form.archive_'.$i} eq 'discard') {
14115: if ($prefix ne '' && $path ne '') {
14116: if (-e $prefix.$path) {
1.1066 raeburn 14117: if ((@archdirs > 0) &&
14118: (grep(/^\Q$i\E$/,@archdirs))) {
14119: $todeletedir{$prefix.$path} = 1;
14120: } else {
14121: $todelete{$prefix.$path} = 1;
14122: }
1.1055 raeburn 14123: }
14124: }
14125: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14126: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14127: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14128: $docstitle = $env{'form.archive_title_'.$i};
14129: if ($docstitle eq '') {
14130: $docstitle = $title;
14131: }
1.1055 raeburn 14132: $outer = 0;
1.1056 raeburn 14133: if (ref($dirorder{$i}) eq 'ARRAY') {
14134: if (@{$dirorder{$i}} > 0) {
14135: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14136: if ($env{'form.archive_'.$item} eq 'display') {
14137: $outer = $item;
14138: last;
14139: }
14140: }
14141: }
14142: }
14143: my ($errtext,$fatal) =
14144: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14145: '/'.$folders{$outer}.'.'.
14146: $containers{$outer});
14147: next if ($fatal);
14148: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14149: if ($context eq 'coursedocs') {
1.1056 raeburn 14150: $mapinner{$i} = time;
1.1055 raeburn 14151: $folders{$i} = 'default_'.$mapinner{$i};
14152: $containers{$i} = 'sequence';
14153: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14154: $folders{$i}.'.'.$containers{$i};
14155: my $newidx = &LONCAPA::map::getresidx();
14156: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14157: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14158: push(@LONCAPA::map::order,$newidx);
14159: my ($outtext,$errtext) =
14160: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14161: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 14162: '.'.$containers{$outer},1,1);
1.1056 raeburn 14163: $newseqid{$i} = $newidx;
1.1067 raeburn 14164: unless ($errtext) {
1.1075.2.128 raeburn 14165: $result .= '<li>'.&mt('Folder: [_1] added to course',
14166: &HTML::Entities::encode($docstitle,'<>&"'))..
14167: '</li>'."\n";
1.1067 raeburn 14168: }
1.1055 raeburn 14169: }
14170: } else {
14171: if ($context eq 'coursedocs') {
14172: my $newidx=&LONCAPA::map::getresidx();
14173: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14174: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14175: $title;
1.1075.2.161. .13(raeb 14176:-23): if (($outer !~ /\D/) &&
14177:-23): (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14178:-23): ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 14179: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14180: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 14181: }
1.1075.2.128 raeburn 14182: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14183: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14184: }
14185: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14186: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14187: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14188: unless ($ishome) {
14189: my $fetch = "$newdest{$i}/$title";
14190: $fetch =~ s/^\Q$prefix$dir\E//;
14191: $prompttofetch{$fetch} = 1;
14192: }
14193: }
14194: }
14195: $LONCAPA::map::resources[$newidx]=
14196: $docstitle.':'.$url.':false:normal:res';
14197: push(@LONCAPA::map::order, $newidx);
14198: my ($outtext,$errtext)=
14199: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14200: $docuname.'/'.$folders{$outer}.
14201: '.'.$containers{$outer},1,1);
14202: unless ($errtext) {
14203: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14204: $result .= '<li>'.&mt('File: [_1] added to course',
14205: &HTML::Entities::encode($docstitle,'<>&"')).
14206: '</li>'."\n";
14207: }
1.1067 raeburn 14208: }
1.1075.2.128 raeburn 14209: } else {
14210: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14211: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 14212: }
1.1055 raeburn 14213: }
14214: }
1.1075.2.11 raeburn 14215: }
14216: } else {
1.1075.2.128 raeburn 14217: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14218: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 14219: }
14220: }
14221: for (my $i=1; $i<=$numitems; $i++) {
14222: next unless ($env{'form.archive_'.$i} eq 'dependency');
14223: my $path = $env{'form.archive_content_'.$i};
14224: if ($path =~ /^\Q$pathtocheck\E/) {
14225: my ($title) = ($path =~ m{/([^/]+)$});
14226: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14227: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14228: if (ref($dirorder{$i}) eq 'ARRAY') {
14229: my ($itemidx,$fullpath,$relpath);
14230: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14231: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14232: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 14233: if ($dirorder{$i}->[$j] eq $container) {
14234: $itemidx = $j;
1.1056 raeburn 14235: }
14236: }
1.1075.2.11 raeburn 14237: }
14238: if ($itemidx eq '') {
14239: $itemidx = 0;
14240: }
14241: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14242: if ($mapinner{$referrer{$i}}) {
14243: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14244: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14245: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14246: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14247: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14248: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14249: if (!-e $fullpath) {
14250: mkdir($fullpath,0755);
1.1056 raeburn 14251: }
14252: }
1.1075.2.11 raeburn 14253: } else {
14254: last;
1.1056 raeburn 14255: }
1.1075.2.11 raeburn 14256: }
14257: }
14258: } elsif ($newdest{$referrer{$i}}) {
14259: $fullpath = $newdest{$referrer{$i}};
14260: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14261: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14262: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14263: last;
14264: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14265: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14266: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14267: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14268: if (!-e $fullpath) {
14269: mkdir($fullpath,0755);
1.1056 raeburn 14270: }
14271: }
1.1075.2.11 raeburn 14272: } else {
14273: last;
1.1056 raeburn 14274: }
1.1075.2.11 raeburn 14275: }
14276: }
14277: if ($fullpath ne '') {
14278: if (-e "$prefix$path") {
1.1075.2.128 raeburn 14279: unless (rename("$prefix$path","$fullpath/$title")) {
14280: $warning .= &mt('Failed to rename dependency').'<br />';
14281: }
1.1075.2.11 raeburn 14282: }
14283: if (-e "$fullpath/$title") {
14284: my $showpath;
14285: if ($relpath ne '') {
14286: $showpath = "$relpath/$title";
14287: } else {
14288: $showpath = "/$title";
1.1056 raeburn 14289: }
1.1075.2.128 raeburn 14290: $result .= '<li>'.&mt('[_1] included as a dependency',
14291: &HTML::Entities::encode($showpath,'<>&"')).
14292: '</li>'."\n";
14293: unless ($ishome) {
14294: my $fetch = "$fullpath/$title";
14295: $fetch =~ s/^\Q$prefix$dir\E//;
14296: $prompttofetch{$fetch} = 1;
14297: }
1.1055 raeburn 14298: }
14299: }
14300: }
1.1075.2.11 raeburn 14301: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14302: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 14303: &HTML::Entities::encode($path,'<>&"'),
14304: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14305: '<br />';
1.1055 raeburn 14306: }
14307: } else {
1.1075.2.128 raeburn 14308: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14309: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14310: }
14311: }
14312: if (keys(%todelete)) {
14313: foreach my $key (keys(%todelete)) {
14314: unlink($key);
1.1066 raeburn 14315: }
14316: }
14317: if (keys(%todeletedir)) {
14318: foreach my $key (keys(%todeletedir)) {
14319: rmdir($key);
14320: }
14321: }
14322: foreach my $dir (sort(keys(%is_dir))) {
14323: if (($pathtocheck ne '') && ($dir ne '')) {
14324: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14325: }
14326: }
1.1067 raeburn 14327: if ($result ne '') {
14328: $output .= '<ul>'."\n".
14329: $result."\n".
14330: '</ul>';
14331: }
14332: unless ($ishome) {
14333: my $replicationfail;
14334: foreach my $item (keys(%prompttofetch)) {
14335: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14336: unless ($fetchresult eq 'ok') {
14337: $replicationfail .= '<li>'.$item.'</li>'."\n";
14338: }
14339: }
14340: if ($replicationfail) {
14341: $output .= '<p class="LC_error">'.
14342: &mt('Course home server failed to retrieve:').'<ul>'.
14343: $replicationfail.
14344: '</ul></p>';
14345: }
14346: }
1.1055 raeburn 14347: } else {
14348: $warning = &mt('No items found in archive.');
14349: }
14350: if ($error) {
14351: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14352: $error.'</p>'."\n";
14353: }
14354: if ($warning) {
14355: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14356: }
14357: return $output;
14358: }
14359:
1.1066 raeburn 14360: sub cleanup_empty_dirs {
14361: my ($path) = @_;
14362: if (($path ne '') && (-d $path)) {
14363: if (opendir(my $dirh,$path)) {
14364: my @dircontents = grep(!/^\./,readdir($dirh));
14365: my $numitems = 0;
14366: foreach my $item (@dircontents) {
14367: if (-d "$path/$item") {
1.1075.2.28 raeburn 14368: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14369: if (-e "$path/$item") {
14370: $numitems ++;
14371: }
14372: } else {
14373: $numitems ++;
14374: }
14375: }
14376: if ($numitems == 0) {
14377: rmdir($path);
14378: }
14379: closedir($dirh);
14380: }
14381: }
14382: return;
14383: }
14384:
1.41 ng 14385: =pod
1.45 matthew 14386:
1.1075.2.56 raeburn 14387: =item * &get_folder_hierarchy()
1.1068 raeburn 14388:
14389: Provides hierarchy of names of folders/sub-folders containing the current
14390: item,
14391:
14392: Inputs: 3
14393: - $navmap - navmaps object
14394:
14395: - $map - url for map (either the trigger itself, or map containing
14396: the resource, which is the trigger).
14397:
14398: - $showitem - 1 => show title for map itself; 0 => do not show.
14399:
14400: Outputs: 1 @pathitems - array of folder/subfolder names.
14401:
14402: =cut
14403:
14404: sub get_folder_hierarchy {
14405: my ($navmap,$map,$showitem) = @_;
14406: my @pathitems;
14407: if (ref($navmap)) {
14408: my $mapres = $navmap->getResourceByUrl($map);
14409: if (ref($mapres)) {
14410: my $pcslist = $mapres->map_hierarchy();
14411: if ($pcslist ne '') {
14412: my @pcs = split(/,/,$pcslist);
14413: foreach my $pc (@pcs) {
14414: if ($pc == 1) {
1.1075.2.38 raeburn 14415: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14416: } else {
14417: my $res = $navmap->getByMapPc($pc);
14418: if (ref($res)) {
14419: my $title = $res->compTitle();
14420: $title =~ s/\W+/_/g;
14421: if ($title ne '') {
14422: push(@pathitems,$title);
14423: }
14424: }
14425: }
14426: }
14427: }
1.1071 raeburn 14428: if ($showitem) {
14429: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 14430: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14431: } else {
14432: my $maptitle = $mapres->compTitle();
14433: $maptitle =~ s/\W+/_/g;
14434: if ($maptitle ne '') {
14435: push(@pathitems,$maptitle);
14436: }
1.1068 raeburn 14437: }
14438: }
14439: }
14440: }
14441: return @pathitems;
14442: }
14443:
14444: =pod
14445:
1.1015 raeburn 14446: =item * &get_turnedin_filepath()
14447:
14448: Determines path in a user's portfolio file for storage of files uploaded
14449: to a specific essayresponse or dropbox item.
14450:
14451: Inputs: 3 required + 1 optional.
14452: $symb is symb for resource, $uname and $udom are for current user (required).
14453: $caller is optional (can be "submission", if routine is called when storing
14454: an upoaded file when "Submit Answer" button was pressed).
14455:
14456: Returns array containing $path and $multiresp.
14457: $path is path in portfolio. $multiresp is 1 if this resource contains more
14458: than one file upload item. Callers of routine should append partid as a
14459: subdirectory to $path in cases where $multiresp is 1.
14460:
14461: Called by: homework/essayresponse.pm and homework/structuretags.pm
14462:
14463: =cut
14464:
14465: sub get_turnedin_filepath {
14466: my ($symb,$uname,$udom,$caller) = @_;
14467: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14468: my $turnindir;
14469: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14470: $turnindir = $userhash{'turnindir'};
14471: my ($path,$multiresp);
14472: if ($turnindir eq '') {
14473: if ($caller eq 'submission') {
14474: $turnindir = &mt('turned in');
14475: $turnindir =~ s/\W+/_/g;
14476: my %newhash = (
14477: 'turnindir' => $turnindir,
14478: );
14479: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14480: }
14481: }
14482: if ($turnindir ne '') {
14483: $path = '/'.$turnindir.'/';
14484: my ($multipart,$turnin,@pathitems);
14485: my $navmap = Apache::lonnavmaps::navmap->new();
14486: if (defined($navmap)) {
14487: my $mapres = $navmap->getResourceByUrl($map);
14488: if (ref($mapres)) {
14489: my $pcslist = $mapres->map_hierarchy();
14490: if ($pcslist ne '') {
14491: foreach my $pc (split(/,/,$pcslist)) {
14492: my $res = $navmap->getByMapPc($pc);
14493: if (ref($res)) {
14494: my $title = $res->compTitle();
14495: $title =~ s/\W+/_/g;
14496: if ($title ne '') {
1.1075.2.48 raeburn 14497: if (($pc > 1) && (length($title) > 12)) {
14498: $title = substr($title,0,12);
14499: }
1.1015 raeburn 14500: push(@pathitems,$title);
14501: }
14502: }
14503: }
14504: }
14505: my $maptitle = $mapres->compTitle();
14506: $maptitle =~ s/\W+/_/g;
14507: if ($maptitle ne '') {
1.1075.2.48 raeburn 14508: if (length($maptitle) > 12) {
14509: $maptitle = substr($maptitle,0,12);
14510: }
1.1015 raeburn 14511: push(@pathitems,$maptitle);
14512: }
14513: unless ($env{'request.state'} eq 'construct') {
14514: my $res = $navmap->getBySymb($symb);
14515: if (ref($res)) {
14516: my $partlist = $res->parts();
14517: my $totaluploads = 0;
14518: if (ref($partlist) eq 'ARRAY') {
14519: foreach my $part (@{$partlist}) {
14520: my @types = $res->responseType($part);
14521: my @ids = $res->responseIds($part);
14522: for (my $i=0; $i < scalar(@ids); $i++) {
14523: if ($types[$i] eq 'essay') {
14524: my $partid = $part.'_'.$ids[$i];
14525: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14526: $totaluploads ++;
14527: }
14528: }
14529: }
14530: }
14531: if ($totaluploads > 1) {
14532: $multiresp = 1;
14533: }
14534: }
14535: }
14536: }
14537: } else {
14538: return;
14539: }
14540: } else {
14541: return;
14542: }
14543: my $restitle=&Apache::lonnet::gettitle($symb);
14544: $restitle =~ s/\W+/_/g;
14545: if ($restitle eq '') {
14546: $restitle = ($resurl =~ m{/[^/]+$});
14547: if ($restitle eq '') {
14548: $restitle = time;
14549: }
14550: }
1.1075.2.48 raeburn 14551: if (length($restitle) > 12) {
14552: $restitle = substr($restitle,0,12);
14553: }
1.1015 raeburn 14554: push(@pathitems,$restitle);
14555: $path .= join('/',@pathitems);
14556: }
14557: return ($path,$multiresp);
14558: }
14559:
14560: =pod
14561:
1.464 albertel 14562: =back
1.41 ng 14563:
1.112 bowersj2 14564: =head1 CSV Upload/Handling functions
1.38 albertel 14565:
1.41 ng 14566: =over 4
14567:
1.648 raeburn 14568: =item * &upfile_store($r)
1.41 ng 14569:
14570: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14571: needs $env{'form.upfile'}
1.41 ng 14572: returns $datatoken to be put into hidden field
14573:
14574: =cut
1.31 albertel 14575:
14576: sub upfile_store {
14577: my $r=shift;
1.258 albertel 14578: $env{'form.upfile'}=~s/\r/\n/gs;
14579: $env{'form.upfile'}=~s/\f/\n/gs;
14580: $env{'form.upfile'}=~s/\n+/\n/gs;
14581: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14582:
1.1075.2.128 raeburn 14583: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14584: '_enroll_'.$env{'request.course.id'}.'_'.
14585: time.'_'.$$);
14586: return if ($datatoken eq '');
14587:
1.31 albertel 14588: {
1.158 raeburn 14589: my $datafile = $r->dir_config('lonDaemons').
14590: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14591: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14592: print $fh $env{'form.upfile'};
1.158 raeburn 14593: close($fh);
14594: }
1.31 albertel 14595: }
14596: return $datatoken;
14597: }
14598:
1.56 matthew 14599: =pod
14600:
1.1075.2.128 raeburn 14601: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14602:
14603: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14604: $datatoken is the name to assign to the temporary file.
1.258 albertel 14605: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14606:
14607: =cut
1.31 albertel 14608:
14609: sub load_tmp_file {
1.1075.2.128 raeburn 14610: my ($r,$datatoken) = @_;
14611: return if ($datatoken eq '');
1.31 albertel 14612: my @studentdata=();
14613: {
1.158 raeburn 14614: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14615: '/tmp/'.$datatoken.'.tmp';
14616: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14617: @studentdata=<$fh>;
14618: close($fh);
14619: }
1.31 albertel 14620: }
1.258 albertel 14621: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14622: }
14623:
1.1075.2.128 raeburn 14624: sub valid_datatoken {
14625: my ($datatoken) = @_;
1.1075.2.131 raeburn 14626: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14627: return $datatoken;
14628: }
14629: return;
14630: }
14631:
1.56 matthew 14632: =pod
14633:
1.648 raeburn 14634: =item * &upfile_record_sep()
1.41 ng 14635:
14636: Separate uploaded file into records
14637: returns array of records,
1.258 albertel 14638: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14639:
14640: =cut
1.31 albertel 14641:
14642: sub upfile_record_sep {
1.258 albertel 14643: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14644: } else {
1.248 albertel 14645: my @records;
1.258 albertel 14646: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14647: if ($line=~/^\s*$/) { next; }
14648: push(@records,$line);
14649: }
14650: return @records;
1.31 albertel 14651: }
14652: }
14653:
1.56 matthew 14654: =pod
14655:
1.648 raeburn 14656: =item * &record_sep($record)
1.41 ng 14657:
1.258 albertel 14658: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14659:
14660: =cut
14661:
1.263 www 14662: sub takeleft {
14663: my $index=shift;
14664: return substr('0000'.$index,-4,4);
14665: }
14666:
1.31 albertel 14667: sub record_sep {
14668: my $record=shift;
14669: my %components=();
1.258 albertel 14670: if ($env{'form.upfiletype'} eq 'xml') {
14671: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14672: my $i=0;
1.356 albertel 14673: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14674: $field=~s/^(\"|\')//;
14675: $field=~s/(\"|\')$//;
1.263 www 14676: $components{&takeleft($i)}=$field;
1.31 albertel 14677: $i++;
14678: }
1.258 albertel 14679: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14680: my $i=0;
1.356 albertel 14681: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14682: $field=~s/^(\"|\')//;
14683: $field=~s/(\"|\')$//;
1.263 www 14684: $components{&takeleft($i)}=$field;
1.31 albertel 14685: $i++;
14686: }
14687: } else {
1.561 www 14688: my $separator=',';
1.480 banghart 14689: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14690: $separator=';';
1.480 banghart 14691: }
1.31 albertel 14692: my $i=0;
1.561 www 14693: # the character we are looking for to indicate the end of a quote or a record
14694: my $looking_for=$separator;
14695: # do not add the characters to the fields
14696: my $ignore=0;
14697: # we just encountered a separator (or the beginning of the record)
14698: my $just_found_separator=1;
14699: # store the field we are working on here
14700: my $field='';
14701: # work our way through all characters in record
14702: foreach my $character ($record=~/(.)/g) {
14703: if ($character eq $looking_for) {
14704: if ($character ne $separator) {
14705: # Found the end of a quote, again looking for separator
14706: $looking_for=$separator;
14707: $ignore=1;
14708: } else {
14709: # Found a separator, store away what we got
14710: $components{&takeleft($i)}=$field;
14711: $i++;
14712: $just_found_separator=1;
14713: $ignore=0;
14714: $field='';
14715: }
14716: next;
14717: }
14718: # single or double quotation marks after a separator indicate beginning of a quote
14719: # we are now looking for the end of the quote and need to ignore separators
14720: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14721: $looking_for=$character;
14722: next;
14723: }
14724: # ignore would be true after we reached the end of a quote
14725: if ($ignore) { next; }
14726: if (($just_found_separator) && ($character=~/\s/)) { next; }
14727: $field.=$character;
14728: $just_found_separator=0;
1.31 albertel 14729: }
1.561 www 14730: # catch the very last entry, since we never encountered the separator
14731: $components{&takeleft($i)}=$field;
1.31 albertel 14732: }
14733: return %components;
14734: }
14735:
1.144 matthew 14736: ######################################################
14737: ######################################################
14738:
1.56 matthew 14739: =pod
14740:
1.648 raeburn 14741: =item * &upfile_select_html()
1.41 ng 14742:
1.144 matthew 14743: Return HTML code to select a file from the users machine and specify
14744: the file type.
1.41 ng 14745:
14746: =cut
14747:
1.144 matthew 14748: ######################################################
14749: ######################################################
1.31 albertel 14750: sub upfile_select_html {
1.144 matthew 14751: my %Types = (
14752: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14753: semisv => &mt('Semicolon separated values'),
1.144 matthew 14754: space => &mt('Space separated'),
14755: tab => &mt('Tabulator separated'),
14756: # xml => &mt('HTML/XML'),
14757: );
14758: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14759: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14760: foreach my $type (sort(keys(%Types))) {
14761: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14762: }
14763: $Str .= "</select>\n";
14764: return $Str;
1.31 albertel 14765: }
14766:
1.301 albertel 14767: sub get_samples {
14768: my ($records,$toget) = @_;
14769: my @samples=({});
14770: my $got=0;
14771: foreach my $rec (@$records) {
14772: my %temp = &record_sep($rec);
14773: if (! grep(/\S/, values(%temp))) { next; }
14774: if (%temp) {
14775: $samples[$got]=\%temp;
14776: $got++;
14777: if ($got == $toget) { last; }
14778: }
14779: }
14780: return \@samples;
14781: }
14782:
1.144 matthew 14783: ######################################################
14784: ######################################################
14785:
1.56 matthew 14786: =pod
14787:
1.648 raeburn 14788: =item * &csv_print_samples($r,$records)
1.41 ng 14789:
14790: Prints a table of sample values from each column uploaded $r is an
14791: Apache Request ref, $records is an arrayref from
14792: &Apache::loncommon::upfile_record_sep
14793:
14794: =cut
14795:
1.144 matthew 14796: ######################################################
14797: ######################################################
1.31 albertel 14798: sub csv_print_samples {
14799: my ($r,$records) = @_;
1.662 bisitz 14800: my $samples = &get_samples($records,5);
1.301 albertel 14801:
1.594 raeburn 14802: $r->print(&mt('Samples').'<br />'.&start_data_table().
14803: &start_data_table_header_row());
1.356 albertel 14804: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14805: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14806: $r->print(&end_data_table_header_row());
1.301 albertel 14807: foreach my $hash (@$samples) {
1.594 raeburn 14808: $r->print(&start_data_table_row());
1.356 albertel 14809: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14810: $r->print('<td>');
1.356 albertel 14811: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14812: $r->print('</td>');
14813: }
1.594 raeburn 14814: $r->print(&end_data_table_row());
1.31 albertel 14815: }
1.594 raeburn 14816: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14817: }
14818:
1.144 matthew 14819: ######################################################
14820: ######################################################
14821:
1.56 matthew 14822: =pod
14823:
1.648 raeburn 14824: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14825:
14826: Prints a table to create associations between values and table columns.
1.144 matthew 14827:
1.41 ng 14828: $r is an Apache Request ref,
14829: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14830: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14831:
14832: =cut
14833:
1.144 matthew 14834: ######################################################
14835: ######################################################
1.31 albertel 14836: sub csv_print_select_table {
14837: my ($r,$records,$d) = @_;
1.301 albertel 14838: my $i=0;
14839: my $samples = &get_samples($records,1);
1.144 matthew 14840: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14841: &start_data_table().&start_data_table_header_row().
1.144 matthew 14842: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14843: '<th>'.&mt('Column').'</th>'.
14844: &end_data_table_header_row()."\n");
1.356 albertel 14845: foreach my $array_ref (@$d) {
14846: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14847: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14848:
1.875 bisitz 14849: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14850: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14851: $r->print('<option value="none"></option>');
1.356 albertel 14852: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14853: $r->print('<option value="'.$sample.'"'.
14854: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14855: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14856: }
1.594 raeburn 14857: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14858: $i++;
14859: }
1.594 raeburn 14860: $r->print(&end_data_table());
1.31 albertel 14861: $i--;
14862: return $i;
14863: }
1.56 matthew 14864:
1.144 matthew 14865: ######################################################
14866: ######################################################
14867:
1.56 matthew 14868: =pod
1.31 albertel 14869:
1.648 raeburn 14870: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14871:
14872: Prints a table of sample values from the upload and can make associate samples to internal names.
14873:
14874: $r is an Apache Request ref,
14875: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14876: $d is an array of 2 element arrays (internal name, displayed name)
14877:
14878: =cut
14879:
1.144 matthew 14880: ######################################################
14881: ######################################################
1.31 albertel 14882: sub csv_samples_select_table {
14883: my ($r,$records,$d) = @_;
14884: my $i=0;
1.144 matthew 14885: #
1.662 bisitz 14886: my $max_samples = 5;
14887: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14888: $r->print(&start_data_table().
14889: &start_data_table_header_row().'<th>'.
14890: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14891: &end_data_table_header_row());
1.301 albertel 14892:
14893: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14894: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14895: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14896: foreach my $option (@$d) {
14897: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14898: $r->print('<option value="'.$value.'"'.
1.253 albertel 14899: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14900: $display.'</option>');
1.31 albertel 14901: }
14902: $r->print('</select></td><td>');
1.662 bisitz 14903: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14904: if (defined($samples->[$line]{$key})) {
14905: $r->print($samples->[$line]{$key}."<br />\n");
14906: }
14907: }
1.594 raeburn 14908: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14909: $i++;
14910: }
1.594 raeburn 14911: $r->print(&end_data_table());
1.31 albertel 14912: $i--;
14913: return($i);
1.115 matthew 14914: }
14915:
1.144 matthew 14916: ######################################################
14917: ######################################################
14918:
1.115 matthew 14919: =pod
14920:
1.648 raeburn 14921: =item * &clean_excel_name($name)
1.115 matthew 14922:
14923: Returns a replacement for $name which does not contain any illegal characters.
14924:
14925: =cut
14926:
1.144 matthew 14927: ######################################################
14928: ######################################################
1.115 matthew 14929: sub clean_excel_name {
14930: my ($name) = @_;
14931: $name =~ s/[:\*\?\/\\]//g;
14932: if (length($name) > 31) {
14933: $name = substr($name,0,31);
14934: }
14935: return $name;
1.25 albertel 14936: }
1.84 albertel 14937:
1.85 albertel 14938: =pod
14939:
1.648 raeburn 14940: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14941:
14942: Returns either 1 or undef
14943:
14944: 1 if the part is to be hidden, undef if it is to be shown
14945:
14946: Arguments are:
14947:
14948: $id the id of the part to be checked
14949: $symb, optional the symb of the resource to check
14950: $udom, optional the domain of the user to check for
14951: $uname, optional the username of the user to check for
14952:
14953: =cut
1.84 albertel 14954:
14955: sub check_if_partid_hidden {
14956: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14957: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14958: $symb,$udom,$uname);
1.141 albertel 14959: my $truth=1;
14960: #if the string starts with !, then the list is the list to show not hide
14961: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14962: my @hiddenlist=split(/,/,$hiddenparts);
14963: foreach my $checkid (@hiddenlist) {
1.141 albertel 14964: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14965: }
1.141 albertel 14966: return !$truth;
1.84 albertel 14967: }
1.127 matthew 14968:
1.138 matthew 14969:
14970: ############################################################
14971: ############################################################
14972:
14973: =pod
14974:
1.157 matthew 14975: =back
14976:
1.138 matthew 14977: =head1 cgi-bin script and graphing routines
14978:
1.157 matthew 14979: =over 4
14980:
1.648 raeburn 14981: =item * &get_cgi_id()
1.138 matthew 14982:
14983: Inputs: none
14984:
14985: Returns an id which can be used to pass environment variables
14986: to various cgi-bin scripts. These environment variables will
14987: be removed from the users environment after a given time by
14988: the routine &Apache::lonnet::transfer_profile_to_env.
14989:
14990: =cut
14991:
14992: ############################################################
14993: ############################################################
1.152 albertel 14994: my $uniq=0;
1.136 matthew 14995: sub get_cgi_id {
1.154 albertel 14996: $uniq=($uniq+1)%100000;
1.280 albertel 14997: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14998: }
14999:
1.127 matthew 15000: ############################################################
15001: ############################################################
15002:
15003: =pod
15004:
1.648 raeburn 15005: =item * &DrawBarGraph()
1.127 matthew 15006:
1.138 matthew 15007: Facilitates the plotting of data in a (stacked) bar graph.
15008: Puts plot definition data into the users environment in order for
15009: graph.png to plot it. Returns an <img> tag for the plot.
15010: The bars on the plot are labeled '1','2',...,'n'.
15011:
15012: Inputs:
15013:
15014: =over 4
15015:
15016: =item $Title: string, the title of the plot
15017:
15018: =item $xlabel: string, text describing the X-axis of the plot
15019:
15020: =item $ylabel: string, text describing the Y-axis of the plot
15021:
15022: =item $Max: scalar, the maximum Y value to use in the plot
15023: If $Max is < any data point, the graph will not be rendered.
15024:
1.140 matthew 15025: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15026: they are plotted. If undefined, default values will be used.
15027:
1.178 matthew 15028: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15029:
1.138 matthew 15030: =item @Values: An array of array references. Each array reference holds data
15031: to be plotted in a stacked bar chart.
15032:
1.239 matthew 15033: =item If the final element of @Values is a hash reference the key/value
15034: pairs will be added to the graph definition.
15035:
1.138 matthew 15036: =back
15037:
15038: Returns:
15039:
15040: An <img> tag which references graph.png and the appropriate identifying
15041: information for the plot.
15042:
1.127 matthew 15043: =cut
15044:
15045: ############################################################
15046: ############################################################
1.134 matthew 15047: sub DrawBarGraph {
1.178 matthew 15048: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15049: #
15050: if (! defined($colors)) {
15051: $colors = ['#33ff00',
15052: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15053: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15054: ];
15055: }
1.228 matthew 15056: my $extra_settings = {};
15057: if (ref($Values[-1]) eq 'HASH') {
15058: $extra_settings = pop(@Values);
15059: }
1.127 matthew 15060: #
1.136 matthew 15061: my $identifier = &get_cgi_id();
15062: my $id = 'cgi.'.$identifier;
1.129 matthew 15063: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15064: return '';
15065: }
1.225 matthew 15066: #
15067: my @Labels;
15068: if (defined($labels)) {
15069: @Labels = @$labels;
15070: } else {
15071: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 15072: push(@Labels,$i+1);
1.225 matthew 15073: }
15074: }
15075: #
1.129 matthew 15076: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15077: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15078: my %ValuesHash;
15079: my $NumSets=1;
15080: foreach my $array (@Values) {
15081: next if (! ref($array));
1.136 matthew 15082: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15083: join(',',@$array);
1.129 matthew 15084: }
1.127 matthew 15085: #
1.136 matthew 15086: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15087: if ($NumBars < 3) {
15088: $width = 120+$NumBars*32;
1.220 matthew 15089: $xskip = 1;
1.225 matthew 15090: $bar_width = 30;
15091: } elsif ($NumBars < 5) {
15092: $width = 120+$NumBars*20;
15093: $xskip = 1;
15094: $bar_width = 20;
1.220 matthew 15095: } elsif ($NumBars < 10) {
1.136 matthew 15096: $width = 120+$NumBars*15;
15097: $xskip = 1;
15098: $bar_width = 15;
15099: } elsif ($NumBars <= 25) {
15100: $width = 120+$NumBars*11;
15101: $xskip = 5;
15102: $bar_width = 8;
15103: } elsif ($NumBars <= 50) {
15104: $width = 120+$NumBars*8;
15105: $xskip = 5;
15106: $bar_width = 4;
15107: } else {
15108: $width = 120+$NumBars*8;
15109: $xskip = 5;
15110: $bar_width = 4;
15111: }
15112: #
1.137 matthew 15113: $Max = 1 if ($Max < 1);
15114: if ( int($Max) < $Max ) {
15115: $Max++;
15116: $Max = int($Max);
15117: }
1.127 matthew 15118: $Title = '' if (! defined($Title));
15119: $xlabel = '' if (! defined($xlabel));
15120: $ylabel = '' if (! defined($ylabel));
1.369 www 15121: $ValuesHash{$id.'.title'} = &escape($Title);
15122: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15123: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15124: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15125: $ValuesHash{$id.'.NumBars'} = $NumBars;
15126: $ValuesHash{$id.'.NumSets'} = $NumSets;
15127: $ValuesHash{$id.'.PlotType'} = 'bar';
15128: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15129: $ValuesHash{$id.'.height'} = $height;
15130: $ValuesHash{$id.'.width'} = $width;
15131: $ValuesHash{$id.'.xskip'} = $xskip;
15132: $ValuesHash{$id.'.bar_width'} = $bar_width;
15133: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15134: #
1.228 matthew 15135: # Deal with other parameters
15136: while (my ($key,$value) = each(%$extra_settings)) {
15137: $ValuesHash{$id.'.'.$key} = $value;
15138: }
15139: #
1.646 raeburn 15140: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15141: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15142: }
15143:
15144: ############################################################
15145: ############################################################
15146:
15147: =pod
15148:
1.648 raeburn 15149: =item * &DrawXYGraph()
1.137 matthew 15150:
1.138 matthew 15151: Facilitates the plotting of data in an XY graph.
15152: Puts plot definition data into the users environment in order for
15153: graph.png to plot it. Returns an <img> tag for the plot.
15154:
15155: Inputs:
15156:
15157: =over 4
15158:
15159: =item $Title: string, the title of the plot
15160:
15161: =item $xlabel: string, text describing the X-axis of the plot
15162:
15163: =item $ylabel: string, text describing the Y-axis of the plot
15164:
15165: =item $Max: scalar, the maximum Y value to use in the plot
15166: If $Max is < any data point, the graph will not be rendered.
15167:
15168: =item $colors: Array ref containing the hex color codes for the data to be
15169: plotted in. If undefined, default values will be used.
15170:
15171: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15172:
15173: =item $Ydata: Array ref containing Array refs.
1.185 www 15174: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15175:
15176: =item %Values: hash indicating or overriding any default values which are
15177: passed to graph.png.
15178: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15179:
15180: =back
15181:
15182: Returns:
15183:
15184: An <img> tag which references graph.png and the appropriate identifying
15185: information for the plot.
15186:
1.137 matthew 15187: =cut
15188:
15189: ############################################################
15190: ############################################################
15191: sub DrawXYGraph {
15192: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15193: #
15194: # Create the identifier for the graph
15195: my $identifier = &get_cgi_id();
15196: my $id = 'cgi.'.$identifier;
15197: #
15198: $Title = '' if (! defined($Title));
15199: $xlabel = '' if (! defined($xlabel));
15200: $ylabel = '' if (! defined($ylabel));
15201: my %ValuesHash =
15202: (
1.369 www 15203: $id.'.title' => &escape($Title),
15204: $id.'.xlabel' => &escape($xlabel),
15205: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15206: $id.'.y_max_value'=> $Max,
15207: $id.'.labels' => join(',',@$Xlabels),
15208: $id.'.PlotType' => 'XY',
15209: );
15210: #
15211: if (defined($colors) && ref($colors) eq 'ARRAY') {
15212: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15213: }
15214: #
15215: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15216: return '';
15217: }
15218: my $NumSets=1;
1.138 matthew 15219: foreach my $array (@{$Ydata}){
1.137 matthew 15220: next if (! ref($array));
15221: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15222: }
1.138 matthew 15223: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15224: #
15225: # Deal with other parameters
15226: while (my ($key,$value) = each(%Values)) {
15227: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15228: }
15229: #
1.646 raeburn 15230: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15231: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15232: }
15233:
15234: ############################################################
15235: ############################################################
15236:
15237: =pod
15238:
1.648 raeburn 15239: =item * &DrawXYYGraph()
1.138 matthew 15240:
15241: Facilitates the plotting of data in an XY graph with two Y axes.
15242: Puts plot definition data into the users environment in order for
15243: graph.png to plot it. Returns an <img> tag for the plot.
15244:
15245: Inputs:
15246:
15247: =over 4
15248:
15249: =item $Title: string, the title of the plot
15250:
15251: =item $xlabel: string, text describing the X-axis of the plot
15252:
15253: =item $ylabel: string, text describing the Y-axis of the plot
15254:
15255: =item $colors: Array ref containing the hex color codes for the data to be
15256: plotted in. If undefined, default values will be used.
15257:
15258: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15259:
15260: =item $Ydata1: The first data set
15261:
15262: =item $Min1: The minimum value of the left Y-axis
15263:
15264: =item $Max1: The maximum value of the left Y-axis
15265:
15266: =item $Ydata2: The second data set
15267:
15268: =item $Min2: The minimum value of the right Y-axis
15269:
15270: =item $Max2: The maximum value of the left Y-axis
15271:
15272: =item %Values: hash indicating or overriding any default values which are
15273: passed to graph.png.
15274: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15275:
15276: =back
15277:
15278: Returns:
15279:
15280: An <img> tag which references graph.png and the appropriate identifying
15281: information for the plot.
1.136 matthew 15282:
15283: =cut
15284:
15285: ############################################################
15286: ############################################################
1.137 matthew 15287: sub DrawXYYGraph {
15288: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15289: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15290: #
15291: # Create the identifier for the graph
15292: my $identifier = &get_cgi_id();
15293: my $id = 'cgi.'.$identifier;
15294: #
15295: $Title = '' if (! defined($Title));
15296: $xlabel = '' if (! defined($xlabel));
15297: $ylabel = '' if (! defined($ylabel));
15298: my %ValuesHash =
15299: (
1.369 www 15300: $id.'.title' => &escape($Title),
15301: $id.'.xlabel' => &escape($xlabel),
15302: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15303: $id.'.labels' => join(',',@$Xlabels),
15304: $id.'.PlotType' => 'XY',
15305: $id.'.NumSets' => 2,
1.137 matthew 15306: $id.'.two_axes' => 1,
15307: $id.'.y1_max_value' => $Max1,
15308: $id.'.y1_min_value' => $Min1,
15309: $id.'.y2_max_value' => $Max2,
15310: $id.'.y2_min_value' => $Min2,
1.136 matthew 15311: );
15312: #
1.137 matthew 15313: if (defined($colors) && ref($colors) eq 'ARRAY') {
15314: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15315: }
15316: #
15317: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15318: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15319: return '';
15320: }
15321: my $NumSets=1;
1.137 matthew 15322: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15323: next if (! ref($array));
15324: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15325: }
15326: #
15327: # Deal with other parameters
15328: while (my ($key,$value) = each(%Values)) {
15329: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15330: }
15331: #
1.646 raeburn 15332: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15333: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15334: }
15335:
15336: ############################################################
15337: ############################################################
15338:
15339: =pod
15340:
1.157 matthew 15341: =back
15342:
1.139 matthew 15343: =head1 Statistics helper routines?
15344:
15345: Bad place for them but what the hell.
15346:
1.157 matthew 15347: =over 4
15348:
1.648 raeburn 15349: =item * &chartlink()
1.139 matthew 15350:
15351: Returns a link to the chart for a specific student.
15352:
15353: Inputs:
15354:
15355: =over 4
15356:
15357: =item $linktext: The text of the link
15358:
15359: =item $sname: The students username
15360:
15361: =item $sdomain: The students domain
15362:
15363: =back
15364:
1.157 matthew 15365: =back
15366:
1.139 matthew 15367: =cut
15368:
15369: ############################################################
15370: ############################################################
15371: sub chartlink {
15372: my ($linktext, $sname, $sdomain) = @_;
15373: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15374: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15375: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15376: '">'.$linktext.'</a>';
1.153 matthew 15377: }
15378:
15379: #######################################################
15380: #######################################################
15381:
15382: =pod
15383:
15384: =head1 Course Environment Routines
1.157 matthew 15385:
15386: =over 4
1.153 matthew 15387:
1.648 raeburn 15388: =item * &restore_course_settings()
1.153 matthew 15389:
1.648 raeburn 15390: =item * &store_course_settings()
1.153 matthew 15391:
15392: Restores/Store indicated form parameters from the course environment.
15393: Will not overwrite existing values of the form parameters.
15394:
15395: Inputs:
15396: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15397:
15398: a hash ref describing the data to be stored. For example:
15399:
15400: %Save_Parameters = ('Status' => 'scalar',
15401: 'chartoutputmode' => 'scalar',
15402: 'chartoutputdata' => 'scalar',
15403: 'Section' => 'array',
1.373 raeburn 15404: 'Group' => 'array',
1.153 matthew 15405: 'StudentData' => 'array',
15406: 'Maps' => 'array');
15407:
15408: Returns: both routines return nothing
15409:
1.631 raeburn 15410: =back
15411:
1.153 matthew 15412: =cut
15413:
15414: #######################################################
15415: #######################################################
15416: sub store_course_settings {
1.496 albertel 15417: return &store_settings($env{'request.course.id'},@_);
15418: }
15419:
15420: sub store_settings {
1.153 matthew 15421: # save to the environment
15422: # appenv the same items, just to be safe
1.300 albertel 15423: my $udom = $env{'user.domain'};
15424: my $uname = $env{'user.name'};
1.496 albertel 15425: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15426: my %SaveHash;
15427: my %AppHash;
15428: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15429: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15430: my $envname = 'environment.'.$basename;
1.258 albertel 15431: if (exists($env{'form.'.$setting})) {
1.153 matthew 15432: # Save this value away
15433: if ($type eq 'scalar' &&
1.258 albertel 15434: (! exists($env{$envname}) ||
15435: $env{$envname} ne $env{'form.'.$setting})) {
15436: $SaveHash{$basename} = $env{'form.'.$setting};
15437: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15438: } elsif ($type eq 'array') {
15439: my $stored_form;
1.258 albertel 15440: if (ref($env{'form.'.$setting})) {
1.153 matthew 15441: $stored_form = join(',',
15442: map {
1.369 www 15443: &escape($_);
1.258 albertel 15444: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15445: } else {
15446: $stored_form =
1.369 www 15447: &escape($env{'form.'.$setting});
1.153 matthew 15448: }
15449: # Determine if the array contents are the same.
1.258 albertel 15450: if ($stored_form ne $env{$envname}) {
1.153 matthew 15451: $SaveHash{$basename} = $stored_form;
15452: $AppHash{$envname} = $stored_form;
15453: }
15454: }
15455: }
15456: }
15457: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15458: $udom,$uname);
1.153 matthew 15459: if ($put_result !~ /^(ok|delayed)/) {
15460: &Apache::lonnet::logthis('unable to save form parameters, '.
15461: 'got error:'.$put_result);
15462: }
15463: # Make sure these settings stick around in this session, too
1.646 raeburn 15464: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15465: return;
15466: }
15467:
15468: sub restore_course_settings {
1.499 albertel 15469: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15470: }
15471:
15472: sub restore_settings {
15473: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15474: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15475: next if (exists($env{'form.'.$setting}));
1.496 albertel 15476: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15477: '.'.$setting;
1.258 albertel 15478: if (exists($env{$envname})) {
1.153 matthew 15479: if ($type eq 'scalar') {
1.258 albertel 15480: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15481: } elsif ($type eq 'array') {
1.258 albertel 15482: $env{'form.'.$setting} = [
1.153 matthew 15483: map {
1.369 www 15484: &unescape($_);
1.258 albertel 15485: } split(',',$env{$envname})
1.153 matthew 15486: ];
15487: }
15488: }
15489: }
1.127 matthew 15490: }
15491:
1.618 raeburn 15492: #######################################################
15493: #######################################################
15494:
15495: =pod
15496:
15497: =head1 Domain E-mail Routines
15498:
15499: =over 4
15500:
1.648 raeburn 15501: =item * &build_recipient_list()
1.618 raeburn 15502:
1.1075.2.44 raeburn 15503: Build recipient lists for following types of e-mail:
1.766 raeburn 15504: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 15505: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15506: module change checking, student/employee ID conflict checks, as
15507: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15508: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15509:
15510: Inputs:
1.1075.2.44 raeburn 15511: defmail (scalar - email address of default recipient),
15512: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15513: requestsmail, updatesmail, or idconflictsmail).
15514:
1.619 raeburn 15515: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 15516:
15517: origmail (scalar - email address of recipient from loncapa.conf,
15518: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 15519:
1.1075.2.139 raeburn 15520: $requname username of requester (if mailing type is helpdeskmail)
15521:
15522: $requdom domain of requester (if mailing type is helpdeskmail)
15523:
15524: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15525:
1.655 raeburn 15526: Returns: comma separated list of addresses to which to send e-mail.
15527:
15528: =back
1.618 raeburn 15529:
15530: =cut
15531:
15532: ############################################################
15533: ############################################################
15534: sub build_recipient_list {
1.1075.2.139 raeburn 15535: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15536: my @recipients;
1.1075.2.122 raeburn 15537: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15538: my %domconfig =
1.1075.2.122 raeburn 15539: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15540: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15541: if (exists($domconfig{'contacts'}{$mailing})) {
15542: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15543: my @contacts = ('adminemail','supportemail');
15544: foreach my $item (@contacts) {
15545: if ($domconfig{'contacts'}{$mailing}{$item}) {
15546: my $addr = $domconfig{'contacts'}{$item};
15547: if (!grep(/^\Q$addr\E$/,@recipients)) {
15548: push(@recipients,$addr);
15549: }
1.619 raeburn 15550: }
1.1075.2.122 raeburn 15551: }
15552: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15553: if ($mailing eq 'helpdeskmail') {
15554: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15555: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15556: my @ok_bccs;
15557: foreach my $bcc (@bccs) {
15558: $bcc =~ s/^\s+//g;
15559: $bcc =~ s/\s+$//g;
15560: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15561: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15562: push(@ok_bccs,$bcc);
15563: }
15564: }
15565: }
15566: if (@ok_bccs > 0) {
15567: $allbcc = join(', ',@ok_bccs);
15568: }
15569: }
15570: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15571: }
15572: }
1.766 raeburn 15573: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15574: $lastresort = $origmail;
1.618 raeburn 15575: }
1.1075.2.139 raeburn 15576: if ($mailing eq 'helpdeskmail') {
15577: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15578: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15579: my ($inststatus,$inststatus_checked);
15580: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15581: ($env{'user.domain'} ne 'public')) {
15582: $inststatus_checked = 1;
15583: $inststatus = $env{'environment.inststatus'};
15584: }
15585: unless ($inststatus_checked) {
15586: if (($requname ne '') && ($requdom ne '')) {
15587: if (($requname =~ /^$match_username$/) &&
15588: ($requdom =~ /^$match_domain$/) &&
15589: (&Apache::lonnet::domain($requdom))) {
15590: my $requhome = &Apache::lonnet::homeserver($requname,
15591: $requdom);
15592: unless ($requhome eq 'no_host') {
15593: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15594: $inststatus = $userenv{'inststatus'};
15595: $inststatus_checked = 1;
15596: }
15597: }
15598: }
15599: }
15600: unless ($inststatus_checked) {
15601: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15602: my %srch = (srchby => 'email',
15603: srchdomain => $defdom,
15604: srchterm => $reqemail,
15605: srchtype => 'exact');
15606: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15607: foreach my $uname (keys(%srch_results)) {
15608: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15609: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15610: $inststatus_checked = 1;
15611: last;
15612: }
15613: }
15614: unless ($inststatus_checked) {
15615: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15616: if ($dirsrchres eq 'ok') {
15617: foreach my $uname (keys(%srch_results)) {
15618: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15619: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15620: $inststatus_checked = 1;
15621: last;
15622: }
15623: }
15624: }
15625: }
15626: }
15627: }
15628: if ($inststatus ne '') {
15629: foreach my $status (split(/\:/,$inststatus)) {
15630: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15631: my @contacts = ('adminemail','supportemail');
15632: foreach my $item (@contacts) {
15633: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15634: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15635: if (!grep(/^\Q$addr\E$/,@recipients)) {
15636: push(@recipients,$addr);
15637: }
15638: }
15639: }
15640: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15641: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15642: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15643: my @ok_bccs;
15644: foreach my $bcc (@bccs) {
15645: $bcc =~ s/^\s+//g;
15646: $bcc =~ s/\s+$//g;
15647: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15648: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15649: push(@ok_bccs,$bcc);
15650: }
15651: }
15652: }
15653: if (@ok_bccs > 0) {
15654: $allbcc = join(', ',@ok_bccs);
15655: }
15656: }
15657: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15658: last;
15659: }
15660: }
15661: }
15662: }
15663: }
1.619 raeburn 15664: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15665: $lastresort = $origmail;
15666: }
1.1075.2.128 raeburn 15667: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15668: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15669: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15670: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15671: my %what = (
15672: perlvar => 1,
15673: );
15674: my $primary = &Apache::lonnet::domain($defdom,'primary');
15675: if ($primary) {
15676: my $gotaddr;
15677: my ($result,$returnhash) =
15678: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15679: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15680: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15681: $lastresort = $returnhash->{'lonSupportEMail'};
15682: $gotaddr = 1;
15683: }
15684: }
15685: unless ($gotaddr) {
15686: my $uintdom = &Apache::lonnet::internet_dom($primary);
15687: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15688: unless ($uintdom eq $intdom) {
15689: my %domconfig =
15690: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15691: if (ref($domconfig{'contacts'}) eq 'HASH') {
15692: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15693: my @contacts = ('adminemail','supportemail');
15694: foreach my $item (@contacts) {
15695: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15696: my $addr = $domconfig{'contacts'}{$item};
15697: if (!grep(/^\Q$addr\E$/,@recipients)) {
15698: push(@recipients,$addr);
15699: }
15700: }
15701: }
15702: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15703: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15704: }
15705: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15706: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15707: my @ok_bccs;
15708: foreach my $bcc (@bccs) {
15709: $bcc =~ s/^\s+//g;
15710: $bcc =~ s/\s+$//g;
15711: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15712: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15713: push(@ok_bccs,$bcc);
15714: }
15715: }
15716: }
15717: if (@ok_bccs > 0) {
15718: $allbcc = join(', ',@ok_bccs);
15719: }
15720: }
15721: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15722: }
15723: }
15724: }
15725: }
15726: }
15727: }
1.618 raeburn 15728: }
1.688 raeburn 15729: if (defined($defmail)) {
15730: if ($defmail ne '') {
15731: push(@recipients,$defmail);
15732: }
1.618 raeburn 15733: }
15734: if ($otheremails) {
1.619 raeburn 15735: my @others;
15736: if ($otheremails =~ /,/) {
15737: @others = split(/,/,$otheremails);
1.618 raeburn 15738: } else {
1.619 raeburn 15739: push(@others,$otheremails);
15740: }
15741: foreach my $addr (@others) {
15742: if (!grep(/^\Q$addr\E$/,@recipients)) {
15743: push(@recipients,$addr);
15744: }
1.618 raeburn 15745: }
15746: }
1.1075.2.128 raeburn 15747: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15748: if ((!@recipients) && ($lastresort ne '')) {
15749: push(@recipients,$lastresort);
15750: }
15751: } elsif ($lastresort ne '') {
15752: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15753: push(@recipients,$lastresort);
15754: }
15755: }
15756: my $recipientlist = join(',',@recipients);
15757: if (wantarray) {
15758: return ($recipientlist,$allbcc,$addtext);
15759: } else {
15760: return $recipientlist;
15761: }
1.618 raeburn 15762: }
15763:
1.127 matthew 15764: ############################################################
15765: ############################################################
1.154 albertel 15766:
1.655 raeburn 15767: =pod
15768:
15769: =head1 Course Catalog Routines
15770:
15771: =over 4
15772:
15773: =item * &gather_categories()
15774:
15775: Converts category definitions - keys of categories hash stored in
15776: coursecategories in configuration.db on the primary library server in a
15777: domain - to an array. Also generates javascript and idx hash used to
15778: generate Domain Coordinator interface for editing Course Categories.
15779:
15780: Inputs:
1.663 raeburn 15781:
1.655 raeburn 15782: categories (reference to hash of category definitions).
1.663 raeburn 15783:
1.655 raeburn 15784: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15785: categories and subcategories).
1.663 raeburn 15786:
1.655 raeburn 15787: idx (reference to hash of counters used in Domain Coordinator interface for
15788: editing Course Categories).
1.663 raeburn 15789:
1.655 raeburn 15790: jsarray (reference to array of categories used to create Javascript arrays for
15791: Domain Coordinator interface for editing Course Categories).
15792:
15793: Returns: nothing
15794:
15795: Side effects: populates cats, idx and jsarray.
15796:
15797: =cut
15798:
15799: sub gather_categories {
15800: my ($categories,$cats,$idx,$jsarray) = @_;
15801: my %counters;
15802: my $num = 0;
15803: foreach my $item (keys(%{$categories})) {
15804: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15805: if ($container eq '' && $depth == 0) {
15806: $cats->[$depth][$categories->{$item}] = $cat;
15807: } else {
15808: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15809: }
15810: my ($escitem,$tail) = split(/:/,$item,2);
15811: if ($counters{$tail} eq '') {
15812: $counters{$tail} = $num;
15813: $num ++;
15814: }
15815: if (ref($idx) eq 'HASH') {
15816: $idx->{$item} = $counters{$tail};
15817: }
15818: if (ref($jsarray) eq 'ARRAY') {
15819: push(@{$jsarray->[$counters{$tail}]},$item);
15820: }
15821: }
15822: return;
15823: }
15824:
15825: =pod
15826:
15827: =item * &extract_categories()
15828:
15829: Used to generate breadcrumb trails for course categories.
15830:
15831: Inputs:
1.663 raeburn 15832:
1.655 raeburn 15833: categories (reference to hash of category definitions).
1.663 raeburn 15834:
1.655 raeburn 15835: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15836: categories and subcategories).
1.663 raeburn 15837:
1.655 raeburn 15838: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15839:
1.655 raeburn 15840: allitems (reference to hash - key is category key
15841: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15842:
1.655 raeburn 15843: idx (reference to hash of counters used in Domain Coordinator interface for
15844: editing Course Categories).
1.663 raeburn 15845:
1.655 raeburn 15846: jsarray (reference to array of categories used to create Javascript arrays for
15847: Domain Coordinator interface for editing Course Categories).
15848:
1.665 raeburn 15849: subcats (reference to hash of arrays containing all subcategories within each
15850: category, -recursive)
15851:
1.1075.2.132 raeburn 15852: maxd (reference to hash used to hold max depth for all top-level categories).
15853:
1.655 raeburn 15854: Returns: nothing
15855:
15856: Side effects: populates trails and allitems hash references.
15857:
15858: =cut
15859:
15860: sub extract_categories {
1.1075.2.132 raeburn 15861: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15862: if (ref($categories) eq 'HASH') {
15863: &gather_categories($categories,$cats,$idx,$jsarray);
15864: if (ref($cats->[0]) eq 'ARRAY') {
15865: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15866: my $name = $cats->[0][$i];
15867: my $item = &escape($name).'::0';
15868: my $trailstr;
15869: if ($name eq 'instcode') {
15870: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15871: } elsif ($name eq 'communities') {
15872: $trailstr = &mt('Communities');
1.655 raeburn 15873: } else {
15874: $trailstr = $name;
15875: }
15876: if ($allitems->{$item} eq '') {
15877: push(@{$trails},$trailstr);
15878: $allitems->{$item} = scalar(@{$trails})-1;
15879: }
15880: my @parents = ($name);
15881: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15882: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15883: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15884: if (ref($subcats) eq 'HASH') {
15885: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15886: }
1.1075.2.132 raeburn 15887: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15888: }
15889: } else {
15890: if (ref($subcats) eq 'HASH') {
15891: $subcats->{$item} = [];
1.655 raeburn 15892: }
1.1075.2.132 raeburn 15893: if (ref($maxd) eq 'HASH') {
15894: $maxd->{$name} = 1;
15895: }
1.655 raeburn 15896: }
15897: }
15898: }
15899: }
15900: return;
15901: }
15902:
15903: =pod
15904:
1.1075.2.56 raeburn 15905: =item * &recurse_categories()
1.655 raeburn 15906:
15907: Recursively used to generate breadcrumb trails for course categories.
15908:
15909: Inputs:
1.663 raeburn 15910:
1.655 raeburn 15911: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15912: categories and subcategories).
1.663 raeburn 15913:
1.655 raeburn 15914: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15915:
15916: category (current course category, for which breadcrumb trail is being generated).
15917:
15918: trails (reference to array of breadcrumb trails for each category).
15919:
1.655 raeburn 15920: allitems (reference to hash - key is category key
15921: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15922:
1.655 raeburn 15923: parents (array containing containers directories for current category,
15924: back to top level).
15925:
15926: Returns: nothing
15927:
15928: Side effects: populates trails and allitems hash references
15929:
15930: =cut
15931:
15932: sub recurse_categories {
1.1075.2.132 raeburn 15933: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15934: my $shallower = $depth - 1;
15935: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15936: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15937: my $name = $cats->[$depth]{$category}[$k];
15938: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 15939:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15940: if ($allitems->{$item} eq '') {
15941: push(@{$trails},$trailstr);
15942: $allitems->{$item} = scalar(@{$trails})-1;
15943: }
15944: my $deeper = $depth+1;
15945: push(@{$parents},$category);
1.665 raeburn 15946: if (ref($subcats) eq 'HASH') {
15947: my $subcat = &escape($name).':'.$category.':'.$depth;
15948: for (my $j=@{$parents}; $j>=0; $j--) {
15949: my $higher;
15950: if ($j > 0) {
15951: $higher = &escape($parents->[$j]).':'.
15952: &escape($parents->[$j-1]).':'.$j;
15953: } else {
15954: $higher = &escape($parents->[$j]).'::'.$j;
15955: }
15956: push(@{$subcats->{$higher}},$subcat);
15957: }
15958: }
15959: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 15960: $subcats,$maxd);
1.655 raeburn 15961: pop(@{$parents});
15962: }
15963: } else {
15964: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 15965: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15966: if ($allitems->{$item} eq '') {
15967: push(@{$trails},$trailstr);
15968: $allitems->{$item} = scalar(@{$trails})-1;
15969: }
1.1075.2.132 raeburn 15970: if (ref($maxd) eq 'HASH') {
15971: if ($depth > $maxd->{$parents->[0]}) {
15972: $maxd->{$parents->[0]} = $depth;
15973: }
15974: }
1.655 raeburn 15975: }
15976: return;
15977: }
15978:
1.663 raeburn 15979: =pod
15980:
1.1075.2.56 raeburn 15981: =item * &assign_categories_table()
1.663 raeburn 15982:
15983: Create a datatable for display of hierarchical categories in a domain,
15984: with checkboxes to allow a course to be categorized.
15985:
15986: Inputs:
15987:
15988: cathash - reference to hash of categories defined for the domain (from
15989: configuration.db)
15990:
15991: currcat - scalar with an & separated list of categories assigned to a course.
15992:
1.919 raeburn 15993: type - scalar contains course type (Course or Community).
15994:
1.1075.2.117 raeburn 15995: disabled - scalar (optional) contains disabled="disabled" if input elements are
15996: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15997:
1.663 raeburn 15998: Returns: $output (markup to be displayed)
15999:
16000: =cut
16001:
16002: sub assign_categories_table {
1.1075.2.117 raeburn 16003: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16004: my $output;
16005: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 16006: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16007: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16008: $maxdepth = scalar(@cats);
16009: if (@cats > 0) {
16010: my $itemcount = 0;
16011: if (ref($cats[0]) eq 'ARRAY') {
16012: my @currcategories;
16013: if ($currcat ne '') {
16014: @currcategories = split('&',$currcat);
16015: }
1.919 raeburn 16016: my $table;
1.663 raeburn 16017: for (my $i=0; $i<@{$cats[0]}; $i++) {
16018: my $parent = $cats[0][$i];
1.919 raeburn 16019: next if ($parent eq 'instcode');
16020: if ($type eq 'Community') {
16021: next unless ($parent eq 'communities');
16022: } else {
16023: next if ($parent eq 'communities');
16024: }
1.663 raeburn 16025: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16026: my $item = &escape($parent).'::0';
16027: my $checked = '';
16028: if (@currcategories > 0) {
16029: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16030: $checked = ' checked="checked"';
1.663 raeburn 16031: }
16032: }
1.919 raeburn 16033: my $parent_title = $parent;
16034: if ($parent eq 'communities') {
16035: $parent_title = &mt('Communities');
16036: }
16037: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16038: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16039: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16040: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16041: my $depth = 1;
16042: push(@path,$parent);
1.1075.2.117 raeburn 16043: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16044: pop(@path);
1.919 raeburn 16045: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16046: $itemcount ++;
16047: }
1.919 raeburn 16048: if ($itemcount) {
16049: $output = &Apache::loncommon::start_data_table().
16050: $table.
16051: &Apache::loncommon::end_data_table();
16052: }
1.663 raeburn 16053: }
16054: }
16055: }
16056: return $output;
16057: }
16058:
16059: =pod
16060:
1.1075.2.56 raeburn 16061: =item * &assign_category_rows()
1.663 raeburn 16062:
16063: Create a datatable row for display of nested categories in a domain,
16064: with checkboxes to allow a course to be categorized,called recursively.
16065:
16066: Inputs:
16067:
16068: itemcount - track row number for alternating colors
16069:
16070: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16071: categories and subcategories.
16072:
16073: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16074:
16075: parent - parent of current category item
16076:
16077: path - Array containing all categories back up through the hierarchy from the
16078: current category to the top level.
16079:
16080: currcategories - reference to array of current categories assigned to the course
16081:
1.1075.2.117 raeburn 16082: disabled - scalar (optional) contains disabled="disabled" if input elements are
16083: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16084:
1.663 raeburn 16085: Returns: $output (markup to be displayed).
16086:
16087: =cut
16088:
16089: sub assign_category_rows {
1.1075.2.117 raeburn 16090: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16091: my ($text,$name,$item,$chgstr);
16092: if (ref($cats) eq 'ARRAY') {
16093: my $maxdepth = scalar(@{$cats});
16094: if (ref($cats->[$depth]) eq 'HASH') {
16095: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16096: my $numchildren = @{$cats->[$depth]{$parent}};
16097: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 16098: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16099: for (my $j=0; $j<$numchildren; $j++) {
16100: $name = $cats->[$depth]{$parent}[$j];
16101: $item = &escape($name).':'.&escape($parent).':'.$depth;
16102: my $deeper = $depth+1;
16103: my $checked = '';
16104: if (ref($currcategories) eq 'ARRAY') {
16105: if (@{$currcategories} > 0) {
16106: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16107: $checked = ' checked="checked"';
1.663 raeburn 16108: }
16109: }
16110: }
1.664 raeburn 16111: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16112: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16113: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16114: '<input type="hidden" name="catname" value="'.$name.'" />'.
16115: '</td><td>';
1.663 raeburn 16116: if (ref($path) eq 'ARRAY') {
16117: push(@{$path},$name);
1.1075.2.117 raeburn 16118: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16119: pop(@{$path});
16120: }
16121: $text .= '</td></tr>';
16122: }
16123: $text .= '</table></td>';
16124: }
16125: }
16126: }
16127: return $text;
16128: }
16129:
1.1075.2.69 raeburn 16130: =pod
16131:
16132: =back
16133:
16134: =cut
16135:
1.655 raeburn 16136: ############################################################
16137: ############################################################
16138:
16139:
1.443 albertel 16140: sub commit_customrole {
1.664 raeburn 16141: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16142: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16143: ($start?', '.&mt('starting').' '.localtime($start):'').
16144: ($end?', ending '.localtime($end):'').': <b>'.
16145: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16146: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16147: '</b><br />';
16148: return $output;
16149: }
16150:
16151: sub commit_standardrole {
1.1075.2.31 raeburn 16152: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16153: my ($output,$logmsg,$linefeed);
16154: if ($context eq 'auto') {
16155: $linefeed = "\n";
16156: } else {
16157: $linefeed = "<br />\n";
16158: }
1.443 albertel 16159: if ($three eq 'st') {
1.541 raeburn 16160: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 16161: $one,$two,$sec,$context,$credits);
1.541 raeburn 16162: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16163: ($result eq 'unknown_course') || ($result eq 'refused')) {
16164: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16165: } else {
1.541 raeburn 16166: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16167: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16168: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16169: if ($context eq 'auto') {
16170: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16171: } else {
16172: $output .= '<b>'.$result.'</b>'.$linefeed.
16173: &mt('Add to classlist').': <b>ok</b>';
16174: }
16175: $output .= $linefeed;
1.443 albertel 16176: }
16177: } else {
16178: $output = &mt('Assigning').' '.$three.' in '.$url.
16179: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16180: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16181: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16182: if ($context eq 'auto') {
16183: $output .= $result.$linefeed;
16184: } else {
16185: $output .= '<b>'.$result.'</b>'.$linefeed;
16186: }
1.443 albertel 16187: }
16188: return $output;
16189: }
16190:
16191: sub commit_studentrole {
1.1075.2.31 raeburn 16192: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16193: $credits) = @_;
1.626 raeburn 16194: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16195: if ($context eq 'auto') {
16196: $linefeed = "\n";
16197: } else {
16198: $linefeed = '<br />'."\n";
16199: }
1.443 albertel 16200: if (defined($one) && defined($two)) {
16201: my $cid=$one.'_'.$two;
16202: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16203: my $secchange = 0;
16204: my $expire_role_result;
16205: my $modify_section_result;
1.628 raeburn 16206: if ($oldsec ne '-1') {
16207: if ($oldsec ne $sec) {
1.443 albertel 16208: $secchange = 1;
1.628 raeburn 16209: my $now = time;
1.443 albertel 16210: my $uurl='/'.$cid;
16211: $uurl=~s/\_/\//g;
16212: if ($oldsec) {
16213: $uurl.='/'.$oldsec;
16214: }
1.626 raeburn 16215: $oldsecurl = $uurl;
1.628 raeburn 16216: $expire_role_result =
1.1075.2.161. .14(raeb 16217:-23): &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 16218: if ($env{'request.course.sec'} ne '') {
16219: if ($expire_role_result eq 'refused') {
16220: my @roles = ('st');
16221: my @statuses = ('previous');
16222: my @roledoms = ($one);
16223: my $withsec = 1;
16224: my %roleshash =
16225: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16226: \@statuses,\@roles,\@roledoms,$withsec);
16227: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16228: my ($oldstart,$oldend) =
16229: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16230: if ($oldend > 0 && $oldend <= $now) {
16231: $expire_role_result = 'ok';
16232: }
16233: }
16234: }
16235: }
1.443 albertel 16236: $result = $expire_role_result;
16237: }
16238: }
16239: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 16240: $modify_section_result =
16241: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16242: undef,undef,undef,$sec,
16243: $end,$start,'','',$cid,
16244: '',$context,$credits);
1.443 albertel 16245: if ($modify_section_result =~ /^ok/) {
16246: if ($secchange == 1) {
1.628 raeburn 16247: if ($sec eq '') {
16248: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16249: } else {
16250: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16251: }
1.443 albertel 16252: } elsif ($oldsec eq '-1') {
1.628 raeburn 16253: if ($sec eq '') {
16254: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16255: } else {
16256: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16257: }
1.443 albertel 16258: } else {
1.628 raeburn 16259: if ($sec eq '') {
16260: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16261: } else {
16262: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16263: }
1.443 albertel 16264: }
16265: } else {
1.628 raeburn 16266: if ($secchange) {
16267: $$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;
16268: } else {
16269: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16270: }
1.443 albertel 16271: }
16272: $result = $modify_section_result;
16273: } elsif ($secchange == 1) {
1.628 raeburn 16274: if ($oldsec eq '') {
1.1075.2.20 raeburn 16275: $$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 16276: } else {
16277: $$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;
16278: }
1.626 raeburn 16279: if ($expire_role_result eq 'refused') {
16280: my $newsecurl = '/'.$cid;
16281: $newsecurl =~ s/\_/\//g;
16282: if ($sec ne '') {
16283: $newsecurl.='/'.$sec;
16284: }
16285: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16286: if ($sec eq '') {
16287: $$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;
16288: } else {
16289: $$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;
16290: }
16291: }
16292: }
1.443 albertel 16293: }
16294: } else {
1.626 raeburn 16295: $$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 16296: $result = "error: incomplete course id\n";
16297: }
16298: return $result;
16299: }
16300:
1.1075.2.25 raeburn 16301: sub show_role_extent {
16302: my ($scope,$context,$role) = @_;
16303: $scope =~ s{^/}{};
16304: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16305: push(@courseroles,'co');
16306: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16307: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16308: $scope =~ s{/}{_};
16309: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16310: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16311: my ($audom,$auname) = split(/\//,$scope);
16312: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16313: &Apache::loncommon::plainname($auname,$audom).'</span>');
16314: } else {
16315: $scope =~ s{/$}{};
16316: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16317: &Apache::lonnet::domain($scope,'description').'</span>');
16318: }
16319: }
16320:
1.443 albertel 16321: ############################################################
16322: ############################################################
16323:
1.566 albertel 16324: sub check_clone {
1.578 raeburn 16325: my ($args,$linefeed) = @_;
1.566 albertel 16326: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16327: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16328: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 16329:21): my $clonetitle;
16330:21): my @clonemsg;
1.566 albertel 16331: my $can_clone = 0;
1.944 raeburn 16332: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16333: if ($lctype ne 'community') {
16334: $lctype = 'course';
16335: }
1.566 albertel 16336: if ($clonehome eq 'no_host') {
1.944 raeburn 16337: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16338:21): push(@clonemsg,({
16339:21): mt => 'No new community created.',
16340:21): args => [],
16341:21): },
16342:21): {
16343:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16344:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16345:21): }));
1.908 raeburn 16346: } else {
1.1075.2.161. .1(raebu 16347:21): push(@clonemsg,({
16348:21): mt => 'No new course created.',
16349:21): args => [],
16350:21): },
16351:21): {
16352:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16353:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16354:21): }));
16355:21): }
1.566 albertel 16356: } else {
16357: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 16358:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 16359: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16360: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 16361:21): push(@clonemsg,({
16362:21): mt => 'No new community created.',
16363:21): args => [],
16364:21): },
16365:21): {
16366:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16367:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16368:21): }));
16369:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16370: }
16371: }
1.1075.2.119 raeburn 16372: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16373: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16374: $can_clone = 1;
16375: } else {
1.1075.2.95 raeburn 16376: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16377: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 16378: if ($clonehash{'cloners'} eq '') {
16379: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16380: if ($domdefs{'canclone'}) {
16381: unless ($domdefs{'canclone'} eq 'none') {
16382: if ($domdefs{'canclone'} eq 'domain') {
16383: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16384: $can_clone = 1;
16385: }
16386: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16387: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16388: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16389: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16390: $can_clone = 1;
16391: }
16392: }
16393: }
1.908 raeburn 16394: }
1.1075.2.95 raeburn 16395: } else {
16396: my @cloners = split(/,/,$clonehash{'cloners'});
16397: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16398: $can_clone = 1;
1.1075.2.95 raeburn 16399: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16400: $can_clone = 1;
1.1075.2.96 raeburn 16401: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16402: $can_clone = 1;
1.1075.2.95 raeburn 16403: }
16404: unless ($can_clone) {
1.1075.2.96 raeburn 16405: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16406: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 16407: my (%gotdomdefaults,%gotcodedefaults);
16408: foreach my $cloner (@cloners) {
16409: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16410: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16411: my (%codedefaults,@code_order);
16412: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16413: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16414: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16415: }
16416: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16417: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16418: }
16419: } else {
16420: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16421: \%codedefaults,
16422: \@code_order);
16423: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16424: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16425: }
16426: if (@code_order > 0) {
16427: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16428: $cloner,$clonehash{'internal.coursecode'},
16429: $args->{'crscode'})) {
16430: $can_clone = 1;
16431: last;
16432: }
16433: }
16434: }
16435: }
16436: }
1.1075.2.96 raeburn 16437: }
16438: }
16439: unless ($can_clone) {
16440: my $ccrole = 'cc';
16441: if ($args->{'crstype'} eq 'Community') {
16442: $ccrole = 'co';
16443: }
16444: my %roleshash =
16445: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16446: $args->{'ccdomain'},
16447: 'userroles',['active'],[$ccrole],
16448: [$args->{'clonedomain'}]);
16449: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16450: $can_clone = 1;
16451: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16452: $args->{'ccuname'},$args->{'ccdomain'})) {
16453: $can_clone = 1;
1.1075.2.95 raeburn 16454: }
16455: }
16456: unless ($can_clone) {
16457: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16458:21): push(@clonemsg,({
16459:21): mt => 'No new community created.',
16460:21): args => [],
16461:21): },
16462:21): {
16463: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]).',
16464:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16465:21): }));
1.1075.2.95 raeburn 16466: } else {
1.1075.2.161. .1(raebu 16467:21): push(@clonemsg,({
16468:21): mt => 'No new course created.',
16469:21): args => [],
16470:21): },
16471:21): {
16472: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]).',
16473:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16474:21): }));
1.578 raeburn 16475: }
1.566 albertel 16476: }
1.578 raeburn 16477: }
1.566 albertel 16478: }
1.1075.2.161. .1(raebu 16479:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16480: }
16481:
1.444 albertel 16482: sub construct_course {
1.1075.2.119 raeburn 16483: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 16484:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16485:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16486: my $linefeed = '<br />'."\n";
16487: if ($context eq 'auto') {
16488: $linefeed = "\n";
16489: }
1.566 albertel 16490:
16491: #
16492: # Are we cloning?
16493: #
1.1075.2.161. .1(raebu 16494:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16495: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 16496:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16497: if (!$can_clone) {
1.1075.2.161. .1(raebu 16498:21): return (0,$outcome,$clonemsgref);
1.566 albertel 16499: }
16500: }
16501:
1.444 albertel 16502: #
16503: # Open course
16504: #
16505: my $crstype = lc($args->{'crstype'});
16506: my %cenv=();
16507: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16508: $args->{'cdescr'},
16509: $args->{'curl'},
16510: $args->{'course_home'},
16511: $args->{'nonstandard'},
16512: $args->{'crscode'},
16513: $args->{'ccuname'}.':'.
16514: $args->{'ccdomain'},
1.882 raeburn 16515: $args->{'crstype'},
1.1075.2.161. .1(raebu 16516:21): $cnum,$context,$category,
16517:21): $callercontext);
1.444 albertel 16518:
16519: # Note: The testing routines depend on this being output; see
16520: # Utils::Course. This needs to at least be output as a comment
16521: # if anyone ever decides to not show this, and Utils::Course::new
16522: # will need to be suitably modified.
1.1075.2.161. .1(raebu 16523:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16524:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16525:21): } else {
16526:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16527:21): }
1.943 raeburn 16528: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 16529:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16530: }
16531:
1.444 albertel 16532: #
16533: # Check if created correctly
16534: #
1.479 albertel 16535: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16536: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16537: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 16538:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16539:21): $outcome .= &mt_user($user_lh,
16540:21): 'Course creation failed, unrecognized course home server.');
16541:21): } else {
16542:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
16543:21): }
16544:21): $outcome .= $linefeed;
16545:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16546: }
1.541 raeburn 16547: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16548:
1.444 albertel 16549: #
1.566 albertel 16550: # Do the cloning
1.1075.2.161. .1(raebu 16551:21): #
16552:21): my @clonemsg;
1.566 albertel 16553: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 16554:21): push(@clonemsg,
16555:21): {
16556:21): mt => 'Created [_1] by cloning from [_2]',
16557:21): args => [$crstype,$clonetitle],
16558:21): });
1.566 albertel 16559: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16560: # Copy all files
1.1075.2.161. .1(raebu 16561:21): my @info =
16562:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16563:21): $args->{'dateshift'},$args->{'crscode'},
16564:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16565:21): $args->{'tinyurls'});
16566:21): if (@info) {
16567:21): push(@clonemsg,@info);
16568:21): }
1.444 albertel 16569: # Restore URL
1.566 albertel 16570: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16571: # Restore title
1.566 albertel 16572: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16573: # Restore creation date, creator and creation context.
16574: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16575: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16576: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16577: # Mark as cloned
1.566 albertel 16578: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16579: # Need to clone grading mode
16580: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16581: $cenv{'grading'}=$newenv{'grading'};
16582: # Do not clone these environment entries
16583: &Apache::lonnet::del('environment',
16584: ['default_enrollment_start_date',
16585: 'default_enrollment_end_date',
16586: 'question.email',
16587: 'policy.email',
16588: 'comment.email',
16589: 'pch.users.denied',
1.725 raeburn 16590: 'plc.users.denied',
16591: 'hidefromcat',
1.1075.2.36 raeburn 16592: 'checkforpriv',
1.1075.2.158 raeburn 16593: 'categories'],
1.638 www 16594: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16595: if ($args->{'textbook'}) {
16596: $cenv{'internal.textbook'} = $args->{'textbook'};
16597: }
1.444 albertel 16598: }
1.566 albertel 16599:
1.444 albertel 16600: #
16601: # Set environment (will override cloned, if existing)
16602: #
16603: my @sections = ();
16604: my @xlists = ();
16605: if ($args->{'crstype'}) {
16606: $cenv{'type'}=$args->{'crstype'};
16607: }
1.1075.2.161. .17(raeb 16608:-23): if ($args->{'lti'}) {
16609:-23): $cenv{'internal.lti'}=$args->{'lti'};
16610:-23): }
1.444 albertel 16611: if ($args->{'crsid'}) {
16612: $cenv{'courseid'}=$args->{'crsid'};
16613: }
16614: if ($args->{'crscode'}) {
16615: $cenv{'internal.coursecode'}=$args->{'crscode'};
16616: }
16617: if ($args->{'crsquota'} ne '') {
16618: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16619: } else {
16620: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16621: }
16622: if ($args->{'ccuname'}) {
16623: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16624: ':'.$args->{'ccdomain'};
16625: } else {
16626: $cenv{'internal.courseowner'} = $args->{'curruser'};
16627: }
1.1075.2.31 raeburn 16628: if ($args->{'defaultcredits'}) {
16629: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16630: }
1.444 albertel 16631: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.161. .20(raeb 16632:-23): my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 16633: if ($args->{'crssections'}) {
16634: $cenv{'internal.sectionnums'} = '';
16635: if ($args->{'crssections'} =~ m/,/) {
16636: @sections = split/,/,$args->{'crssections'};
16637: } else {
16638: $sections[0] = $args->{'crssections'};
16639: }
16640: if (@sections > 0) {
16641: foreach my $item (@sections) {
16642: my ($sec,$gp) = split/:/,$item;
16643: my $class = $args->{'crscode'}.$sec;
16644: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16645: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.161. .20(raeb 16646:-23): if ($addcheck eq 'ok') {
16647:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16648:-23): push(@oklcsecs,$gp);
16649:-23): }
16650:-23): } else {
1.1075.2.119 raeburn 16651: push(@badclasses,$class);
1.444 albertel 16652: }
16653: }
16654: $cenv{'internal.sectionnums'} =~ s/,$//;
16655: }
16656: }
16657: # do not hide course coordinator from staff listing,
16658: # even if privileged
16659: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16660: # add course coordinator's domain to domains to check for privileged users
16661: # if different to course domain
16662: if ($$crsudom ne $args->{'ccdomain'}) {
16663: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16664: }
1.444 albertel 16665: # add crosslistings
16666: if ($args->{'crsxlist'}) {
16667: $cenv{'internal.crosslistings'}='';
16668: if ($args->{'crsxlist'} =~ m/,/) {
16669: @xlists = split/,/,$args->{'crsxlist'};
16670: } else {
16671: $xlists[0] = $args->{'crsxlist'};
16672: }
16673: if (@xlists > 0) {
16674: foreach my $item (@xlists) {
16675: my ($xl,$gp) = split/:/,$item;
16676: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16677: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.161. .20(raeb 16678:-23): if ($addcheck eq 'ok') {
16679:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16680:-23): push(@oklcsecs,$gp);
16681:-23): }
16682:-23): } else {
1.1075.2.119 raeburn 16683: push(@badclasses,$xl);
1.444 albertel 16684: }
16685: }
16686: $cenv{'internal.crosslistings'} =~ s/,$//;
16687: }
16688: }
16689: if ($args->{'autoadds'}) {
16690: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16691: }
16692: if ($args->{'autodrops'}) {
16693: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16694: }
16695: # check for notification of enrollment changes
16696: my @notified = ();
16697: if ($args->{'notify_owner'}) {
16698: if ($args->{'ccuname'} ne '') {
16699: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16700: }
16701: }
16702: if ($args->{'notify_dc'}) {
16703: if ($uname ne '') {
1.630 raeburn 16704: push(@notified,$uname.':'.$udom);
1.444 albertel 16705: }
16706: }
16707: if (@notified > 0) {
16708: my $notifylist;
16709: if (@notified > 1) {
16710: $notifylist = join(',',@notified);
16711: } else {
16712: $notifylist = $notified[0];
16713: }
16714: $cenv{'internal.notifylist'} = $notifylist;
16715: }
16716: if (@badclasses > 0) {
16717: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16718: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16719: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16720: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16721: );
1.1075.2.119 raeburn 16722: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16723: &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 16724: if ($context eq 'auto') {
16725: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16726: } else {
1.566 albertel 16727: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16728: }
16729: foreach my $item (@badclasses) {
1.541 raeburn 16730: if ($context eq 'auto') {
1.1075.2.119 raeburn 16731: $outcome .= " - $item\n";
1.541 raeburn 16732: } else {
1.1075.2.119 raeburn 16733: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16734: }
1.1075.2.119 raeburn 16735: }
16736: if ($context eq 'auto') {
16737: $outcome .= $linefeed;
16738: } else {
16739: $outcome .= "</ul><br /><br /></div>\n";
16740: }
1.444 albertel 16741: }
16742: if ($args->{'no_end_date'}) {
16743: $args->{'endaccess'} = 0;
16744: }
1.1075.2.161. .20(raeb 16745:-23): # If an official course with institutional sections is created by cloning
16746:-23): # an existing course, section-specific hiding of course totals in student's
16747:-23): # view of grades as copied from cloned course, will be checked for valid
16748:-23): # sections.
16749:-23): if (($can_clone && $cloneid) &&
16750:-23): ($cenv{'internal.coursecode'} ne '') &&
16751:-23): ($cenv{'grading'} eq 'standard') &&
16752:-23): ($cenv{'hidetotals'} ne '') &&
16753:-23): ($cenv{'hidetotals'} ne 'all')) {
16754:-23): my @hidesecs;
16755:-23): my $deletehidetotals;
16756:-23): if (@oklcsecs) {
16757:-23): foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
16758:-23): if (grep(/^\Q$sec$/,@oklcsecs)) {
16759:-23): push(@hidesecs,$sec);
16760:-23): }
16761:-23): }
16762:-23): if (@hidesecs) {
16763:-23): $cenv{'hidetotals'} = join(',',@hidesecs);
16764:-23): } else {
16765:-23): $deletehidetotals = 1;
16766:-23): }
16767:-23): } else {
16768:-23): $deletehidetotals = 1;
16769:-23): }
16770:-23): if ($deletehidetotals) {
16771:-23): delete($cenv{'hidetotals'});
16772:-23): &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
16773:-23): }
16774:-23): }
1.444 albertel 16775: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16776: $cenv{'internal.autoend'}=$args->{'enrollend'};
16777: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16778: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16779: if ($args->{'showphotos'}) {
16780: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16781: }
16782: $cenv{'internal.authtype'} = $args->{'authtype'};
16783: $cenv{'internal.autharg'} = $args->{'autharg'};
16784: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16785: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16786: 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');
16787: if ($context eq 'auto') {
16788: $outcome .= $krb_msg;
16789: } else {
1.566 albertel 16790: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16791: }
16792: $outcome .= $linefeed;
1.444 albertel 16793: }
16794: }
16795: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16796: if ($args->{'setpolicy'}) {
16797: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16798: }
16799: if ($args->{'setcontent'}) {
16800: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16801: }
1.1075.2.110 raeburn 16802: if ($args->{'setcomment'}) {
16803: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16804: }
1.444 albertel 16805: }
16806: if ($args->{'reshome'}) {
16807: $cenv{'reshome'}=$args->{'reshome'}.'/';
16808: $cenv{'reshome'}=~s/\/+$/\//;
16809: }
16810: #
16811: # course has keyed access
16812: #
16813: if ($args->{'setkeys'}) {
16814: $cenv{'keyaccess'}='yes';
16815: }
16816: # if specified, key authority is not course, but user
16817: # only active if keyaccess is yes
16818: if ($args->{'keyauth'}) {
1.487 albertel 16819: my ($user,$domain) = split(':',$args->{'keyauth'});
16820: $user = &LONCAPA::clean_username($user);
16821: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16822: if ($user ne '' && $domain ne '') {
1.487 albertel 16823: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16824: }
16825: }
16826:
1.1075.2.59 raeburn 16827: #
16828: # generate and store uniquecode (available to course requester), if course should have one.
16829: #
16830: if ($args->{'uniquecode'}) {
16831: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16832: if ($code) {
16833: $cenv{'internal.uniquecode'} = $code;
16834: my %crsinfo =
16835: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16836: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16837: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16838: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16839: }
16840: if (ref($coderef)) {
16841: $$coderef = $code;
16842: }
16843: }
16844: }
16845:
1.444 albertel 16846: if ($args->{'disresdis'}) {
16847: $cenv{'pch.roles.denied'}='st';
16848: }
16849: if ($args->{'disablechat'}) {
16850: $cenv{'plc.roles.denied'}='st';
16851: }
16852:
16853: # Record we've not yet viewed the Course Initialization Helper for this
16854: # course
16855: $cenv{'course.helper.not.run'} = 1;
16856: #
16857: # Use new Randomseed
16858: #
16859: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16860: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16861: #
16862: # The encryption code and receipt prefix for this course
16863: #
16864: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16865: $cenv{'internal.encpref'}=100+int(9*rand(99));
16866: #
16867: # By default, use standard grading
16868: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16869:
1.541 raeburn 16870: $outcome .= $linefeed.&mt('Setting environment').': '.
16871: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16872: #
16873: # Open all assignments
16874: #
16875: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16876: my $opendate = time;
16877: if ($args->{'openallfrom'} =~ /^\d+$/) {
16878: $opendate = $args->{'openallfrom'};
16879: }
1.444 albertel 16880: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16881: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16882: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16883: $outcome .= &mt('All assignments open starting [_1]',
16884: &Apache::lonlocal::locallocaltime($opendate)).': '.
16885: &Apache::lonnet::cput
16886: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16887: }
16888: #
16889: # Set first page
16890: #
16891: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16892: || ($cloneid)) {
16893: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16894:
16895: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16896: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16897:
1.444 albertel 16898: $outcome .= ($fatal?$errtext:'read ok').' - ';
16899: my $title; my $url;
16900: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16901: $title=&mt('Syllabus');
1.444 albertel 16902: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16903: } else {
1.963 raeburn 16904: $title=&mt('Table of Contents');
1.444 albertel 16905: $url='/adm/navmaps';
16906: }
1.445 albertel 16907:
16908: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16909: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16910:
16911: if ($errtext) { $fatal=2; }
1.541 raeburn 16912: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16913: }
1.566 albertel 16914:
1.1075.2.161. .1(raebu 16915:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16916: }
16917:
1.1075.2.59 raeburn 16918: sub make_unique_code {
16919: my ($cdom,$cnum) = @_;
16920: # get lock on uniquecodes db
16921: my $lockhash = {
16922: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16923: ':'.$env{'user.domain'},
16924: };
16925: my $tries = 0;
16926: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16927: my ($code,$error);
16928:
16929: while (($gotlock ne 'ok') && ($tries<3)) {
16930: $tries ++;
16931: sleep 1;
16932: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16933: }
16934: if ($gotlock eq 'ok') {
16935: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16936: my $gotcode;
16937: my $attempts = 0;
16938: while ((!$gotcode) && ($attempts < 100)) {
16939: $code = &generate_code();
16940: if (!exists($currcodes{$code})) {
16941: $gotcode = 1;
16942: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16943: $error = 'nostore';
16944: }
16945: }
16946: $attempts ++;
16947: }
16948: my @del_lock = ($cnum."\0".'uniquecodes');
16949: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16950: } else {
16951: $error = 'nolock';
16952: }
16953: return ($code,$error);
16954: }
16955:
16956: sub generate_code {
16957: my $code;
16958: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16959: for (my $i=0; $i<6; $i++) {
16960: my $lettnum = int (rand 2);
16961: my $item = '';
16962: if ($lettnum) {
16963: $item = $letts[int( rand(18) )];
16964: } else {
16965: $item = 1+int( rand(8) );
16966: }
16967: $code .= $item;
16968: }
16969: return $code;
16970: }
16971:
1.444 albertel 16972: ############################################################
16973: ############################################################
16974:
1.953 droeschl 16975: #SD
16976: # only Community and Course, or anything else?
1.378 raeburn 16977: sub course_type {
16978: my ($cid) = @_;
16979: if (!defined($cid)) {
16980: $cid = $env{'request.course.id'};
16981: }
1.404 albertel 16982: if (defined($env{'course.'.$cid.'.type'})) {
16983: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16984: } else {
16985: return 'Course';
1.377 raeburn 16986: }
16987: }
1.156 albertel 16988:
1.406 raeburn 16989: sub group_term {
16990: my $crstype = &course_type();
16991: my %names = (
16992: 'Course' => 'group',
1.865 raeburn 16993: 'Community' => 'group',
1.406 raeburn 16994: );
16995: return $names{$crstype};
16996: }
16997:
1.902 raeburn 16998: sub course_types {
1.1075.2.161. .17(raeb 16999:-23): my @types = ('official','unofficial','community','textbook','lti');
1.902 raeburn 17000: my %typename = (
17001: official => 'Official course',
17002: unofficial => 'Unofficial course',
17003: community => 'Community',
1.1075.2.59 raeburn 17004: textbook => 'Textbook course',
1.1075.2.161. .17(raeb 17005:-23): lti => 'LTI provider',
1.902 raeburn 17006: );
17007: return (\@types,\%typename);
17008: }
17009:
1.156 albertel 17010: sub icon {
17011: my ($file)=@_;
1.505 albertel 17012: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17013: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17014: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17015: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17016: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17017: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17018: $curfext.".gif") {
17019: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17020: $curfext.".gif";
17021: }
17022: }
1.249 albertel 17023: return &lonhttpdurl($iconname);
1.154 albertel 17024: }
1.84 albertel 17025:
1.575 albertel 17026: sub lonhttpdurl {
1.692 www 17027: #
17028: # Had been used for "small fry" static images on separate port 8080.
17029: # Modify here if lightweight http functionality desired again.
17030: # Currently eliminated due to increasing firewall issues.
17031: #
1.575 albertel 17032: my ($url)=@_;
1.692 www 17033: return $url;
1.215 albertel 17034: }
17035:
1.213 albertel 17036: sub connection_aborted {
17037: my ($r)=@_;
17038: $r->print(" ");$r->rflush();
17039: my $c = $r->connection;
17040: return $c->aborted();
17041: }
17042:
1.221 foxr 17043: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17044: # strings as 'strings'.
17045: sub escape_single {
1.221 foxr 17046: my ($input) = @_;
1.223 albertel 17047: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17048: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17049: return $input;
17050: }
1.223 albertel 17051:
1.222 foxr 17052: # Same as escape_single, but escape's "'s This
17053: # can be used for "strings"
17054: sub escape_double {
17055: my ($input) = @_;
17056: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17057: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17058: return $input;
17059: }
1.223 albertel 17060:
1.222 foxr 17061: # Escapes the last element of a full URL.
17062: sub escape_url {
17063: my ($url) = @_;
1.238 raeburn 17064: my @urlslices = split(/\//, $url,-1);
1.369 www 17065: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 17066: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17067: }
1.462 albertel 17068:
1.820 raeburn 17069: sub compare_arrays {
17070: my ($arrayref1,$arrayref2) = @_;
17071: my (@difference,%count);
17072: @difference = ();
17073: %count = ();
17074: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17075: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17076: foreach my $element (keys(%count)) {
17077: if ($count{$element} == 1) {
17078: push(@difference,$element);
17079: }
17080: }
17081: }
17082: return @difference;
17083: }
17084:
1.1075.2.152 raeburn 17085: sub lon_status_items {
17086: my %defaults = (
17087: E => 100,
17088: W => 4,
17089: N => 1,
17090: U => 5,
17091: threshold => 200,
17092: sysmail => 2500,
17093: );
17094: my %names = (
17095: E => 'Errors',
17096: W => 'Warnings',
17097: N => 'Notices',
17098: U => 'Unsent',
17099: );
17100: return (\%defaults,\%names);
17101: }
17102:
1.817 bisitz 17103: # -------------------------------------------------------- Initialize user login
1.462 albertel 17104: sub init_user_environment {
1.463 albertel 17105: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17106: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17107:
17108: my $public=($username eq 'public' && $domain eq 'public');
17109:
17110: # See if old ID present, if so, remove
17111:
1.1075.2.161. .22(raeb 17112:-24): my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17113:-24): $coauthorenv);
1.462 albertel 17114: my $now=time;
17115:
17116: if ($public) {
17117: my $max_public=100;
17118: my $oldest;
17119: my $oldest_time=0;
17120: for(my $next=1;$next<=$max_public;$next++) {
17121: if (-e $lonids."/publicuser_$next.id") {
17122: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17123: if ($mtime<$oldest_time || !$oldest_time) {
17124: $oldest_time=$mtime;
17125: $oldest=$next;
17126: }
17127: } else {
17128: $cookie="publicuser_$next";
17129: last;
17130: }
17131: }
17132: if (!$cookie) { $cookie="publicuser_$oldest"; }
17133: } else {
1.463 albertel 17134: # if this isn't a robot, kill any existing non-robot sessions
17135: if (!$args->{'robot'}) {
17136: opendir(DIR,$lonids);
17137: while ($filename=readdir(DIR)) {
17138: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 17139: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17140: &GDBM_READER(),0640)) {
17141: my $linkedfile;
17142: if (exists($oldenv{'user.linkedenv'})) {
17143: $linkedfile = $oldenv{'user.linkedenv'};
17144: }
17145: untie(%oldenv);
17146: if (unlink("$lonids/$filename")) {
17147: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17148: if (-l "$lonids/$linkedfile.id") {
17149: unlink("$lonids/$linkedfile.id");
17150: }
17151: }
17152: }
17153: } else {
17154: unlink($lonids.'/'.$filename);
17155: }
1.463 albertel 17156: }
1.462 albertel 17157: }
1.463 albertel 17158: closedir(DIR);
1.1075.2.84 raeburn 17159: # If there is a undeleted lockfile for the user's paste buffer remove it.
17160: my $namespace = 'nohist_courseeditor';
17161: my $lockingkey = 'paste'."\0".'locked_num';
17162: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17163: $domain,$username);
17164: if (exists($lockhash{$lockingkey})) {
17165: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17166: unless ($delresult eq 'ok') {
17167: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17168: }
17169: }
1.462 albertel 17170: }
17171: # Give them a new cookie
1.463 albertel 17172: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17173: : $now.$$.int(rand(10000)));
1.463 albertel 17174: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17175:
17176: # Initialize roles
17177:
1.1075.2.161. .22(raeb 17178:-24): ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17179: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17180: }
17181: # ------------------------------------ Check browser type and MathML capability
17182:
1.1075.2.77 raeburn 17183: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17184: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17185:
17186: # ------------------------------------------------------------- Get environment
17187:
17188: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17189: my ($tmp) = keys(%userenv);
17190: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
17191: } else {
17192: undef(%userenv);
17193: }
17194: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17195: $form->{'interface'}=$userenv{'interface'};
17196: }
17197: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17198:
17199: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17200: foreach my $option ('interface','localpath','localres') {
17201: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17202: }
17203: # --------------------------------------------------------- Write first profile
17204:
17205: {
1.1075.2.150 raeburn 17206: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 17207: my %initial_env =
17208: ("user.name" => $username,
17209: "user.domain" => $domain,
17210: "user.home" => $authhost,
17211: "browser.type" => $clientbrowser,
17212: "browser.version" => $clientversion,
17213: "browser.mathml" => $clientmathml,
17214: "browser.unicode" => $clientunicode,
17215: "browser.os" => $clientos,
1.1075.2.42 raeburn 17216: "browser.mobile" => $clientmobile,
17217: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 17218: "browser.osversion" => $clientosversion,
1.462 albertel 17219: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17220: "request.course.fn" => '',
17221: "request.course.uri" => '',
17222: "request.course.sec" => '',
17223: "request.role" => 'cm',
17224: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 17225: "request.host" => $ip,);
1.462 albertel 17226:
17227: if ($form->{'localpath'}) {
17228: $initial_env{"browser.localpath"} = $form->{'localpath'};
17229: $initial_env{"browser.localres"} = $form->{'localres'};
17230: }
17231:
17232: if ($form->{'interface'}) {
17233: $form->{'interface'}=~s/\W//gs;
17234: $initial_env{"browser.interface"} = $form->{'interface'};
17235: $env{'browser.interface'}=$form->{'interface'};
17236: }
17237:
1.1075.2.54 raeburn 17238: if ($form->{'iptoken'}) {
17239: my $lonhost = $r->dir_config('lonHostID');
17240: $initial_env{"user.noloadbalance"} = $lonhost;
17241: $env{'user.noloadbalance'} = $lonhost;
17242: }
17243:
1.1075.2.120 raeburn 17244: if ($form->{'noloadbalance'}) {
17245: my @hosts = &Apache::lonnet::current_machine_ids();
17246: my $hosthere = $form->{'noloadbalance'};
17247: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17248: $initial_env{"user.noloadbalance"} = $hosthere;
17249: $env{'user.noloadbalance'} = $hosthere;
17250: }
17251: }
17252:
1.1016 raeburn 17253: unless ($domain eq 'public') {
1.1075.2.125 raeburn 17254: my %is_adv = ( is_adv => $env{'user.adv'} );
17255: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 17256:
1.1075.2.161. .10(raeb 17257:-22): foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {
1.1075.2.125 raeburn 17258: $userenv{'availabletools.'.$tool} =
17259: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17260: undef,\%userenv,\%domdef,\%is_adv);
17261: }
1.724 raeburn 17262:
1.1075.2.161. .17(raeb 17263:-23): foreach my $crstype ('official','unofficial','community','textbook','lti') {
1.1075.2.125 raeburn 17264: $userenv{'canrequest.'.$crstype} =
17265: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17266: 'reload','requestcourses',
17267: \%userenv,\%domdef,\%is_adv);
17268: }
1.765 raeburn 17269:
1.1075.2.161. .21(raeb 17270:-24): if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
17271:-24): (exists($userroles->{"user.role.au./$domain/"}))) {
17272:-24): if ($userenv{'authoreditors'}) {
17273:-24): $userenv{'editors'} = $userenv{'authoreditors'};
17274:-24): } elsif ($domdef{'editors'} ne '') {
17275:-24): $userenv{'editors'} = $domdef{'editors'};
17276:-24): } else {
17277:-24): $userenv{'editors'} = 'edit,xml';
17278:-24): }
17279:-24): }
17280:-24):
1.1075.2.125 raeburn 17281: $userenv{'canrequest.author'} =
17282: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17283: 'reload','requestauthor',
17284: \%userenv,\%domdef,\%is_adv);
17285: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17286: $domain,$username);
17287: my $reqstatus = $reqauthor{'author_status'};
17288: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17289: if (ref($reqauthor{'author'}) eq 'HASH') {
17290: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17291: $reqauthor{'author'}{'timestamp'};
17292: }
1.1075.2.14 raeburn 17293: }
17294: }
17295:
1.462 albertel 17296: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17297:
1.462 albertel 17298: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17299: &GDBM_WRCREAT(),0640)) {
17300: &_add_to_env(\%disk_env,\%initial_env);
17301: &_add_to_env(\%disk_env,\%userenv,'environment.');
17302: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17303: if (ref($firstaccenv) eq 'HASH') {
17304: &_add_to_env(\%disk_env,$firstaccenv);
17305: }
17306: if (ref($timerintenv) eq 'HASH') {
17307: &_add_to_env(\%disk_env,$timerintenv);
17308: }
1.1075.2.161. .22(raeb 17309:-24): if (ref($coauthorenv) eq 'HASH') {
17310:-24): if (keys(%{$coauthorenv})) {
17311:-24): &_add_to_env(\%disk_env,$coauthorenv);
17312:-24): }
17313:-24): }
1.463 albertel 17314: if (ref($args->{'extra_env'})) {
17315: &_add_to_env(\%disk_env,$args->{'extra_env'});
17316: }
1.462 albertel 17317: untie(%disk_env);
17318: } else {
1.705 tempelho 17319: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17320: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17321: return 'error: '.$!;
17322: }
17323: }
17324: $env{'request.role'}='cm';
17325: $env{'request.role.adv'}=$env{'user.adv'};
17326: $env{'browser.type'}=$clientbrowser;
17327:
17328: return $cookie;
17329:
17330: }
17331:
17332: sub _add_to_env {
17333: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17334: if (ref($env_data) eq 'HASH') {
17335: while (my ($key,$value) = each(%$env_data)) {
17336: $idf->{$prefix.$key} = $value;
17337: $env{$prefix.$key} = $value;
17338: }
1.462 albertel 17339: }
17340: }
17341:
1.685 tempelho 17342: # --- Get the symbolic name of a problem and the url
17343: sub get_symb {
17344: my ($request,$silent) = @_;
1.726 raeburn 17345: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17346: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17347: if ($symb eq '') {
17348: if (!$silent) {
1.1071 raeburn 17349: if (ref($request)) {
17350: $request->print("Unable to handle ambiguous references:$url:.");
17351: }
1.685 tempelho 17352: return ();
17353: }
17354: }
17355: &Apache::lonenc::check_decrypt(\$symb);
17356: return ($symb);
17357: }
17358:
17359: # --------------------------------------------------------------Get annotation
17360:
17361: sub get_annotation {
17362: my ($symb,$enc) = @_;
17363:
17364: my $key = $symb;
17365: if (!$enc) {
17366: $key =
17367: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17368: }
17369: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17370: return $annotation{$key};
17371: }
17372:
17373: sub clean_symb {
1.731 raeburn 17374: my ($symb,$delete_enc) = @_;
1.685 tempelho 17375:
17376: &Apache::lonenc::check_decrypt(\$symb);
17377: my $enc = $env{'request.enc'};
1.731 raeburn 17378: if ($delete_enc) {
1.730 raeburn 17379: delete($env{'request.enc'});
17380: }
1.685 tempelho 17381:
17382: return ($symb,$enc);
17383: }
1.462 albertel 17384:
1.1075.2.69 raeburn 17385: ############################################################
17386: ############################################################
17387:
17388: =pod
17389:
17390: =head1 Routines for building display used to search for courses
17391:
17392:
17393: =over 4
17394:
17395: =item * &build_filters()
17396:
17397: Create markup for a table used to set filters to use when selecting
17398: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17399: and quotacheck.pl
17400:
17401:
17402: Inputs:
17403:
17404: filterlist - anonymous array of fields to include as potential filters
17405:
17406: crstype - course type
17407:
17408: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17409: to pop-open a course selector (will contain "extra element").
17410:
17411: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17412:
17413: filter - anonymous hash of criteria and their values
17414:
17415: action - form action
17416:
17417: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17418:
17419: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
17420:
17421: cloneruname - username of owner of new course who wants to clone
17422:
17423: clonerudom - domain of owner of new course who wants to clone
17424:
17425: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17426:
17427: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17428:
17429: codedom - domain
17430:
17431: formname - value of form element named "form".
17432:
17433: fixeddom - domain, if fixed.
17434:
17435: prevphase - value to assign to form element named "phase" when going back to the previous screen
17436:
17437: cnameelement - name of form element in form on opener page which will receive title of selected course
17438:
17439: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17440:
17441: cdomelement - name of form element in form on opener page which will receive domain of selected course
17442:
17443: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17444:
17445: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17446:
17447: clonewarning - warning message about missing information for intended course owner when DC creates a course
17448:
17449:
17450: Returns: $output - HTML for display of search criteria, and hidden form elements.
17451:
17452:
17453: Side Effects: None
17454:
17455: =cut
17456:
17457: # ---------------------------------------------- search for courses based on last activity etc.
17458:
17459: sub build_filters {
17460: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17461: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17462: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17463: $cnameelement,$cnumelement,$cdomelement,$setroles,
17464: $clonetext,$clonewarning) = @_;
17465: my ($list,$jscript);
17466: my $onchange = 'javascript:updateFilters(this)';
17467: my ($domainselectform,$sincefilterform,$createdfilterform,
17468: $ownerdomselectform,$persondomselectform,$instcodeform,
17469: $typeselectform,$instcodetitle);
17470: if ($formname eq '') {
17471: $formname = $caller;
17472: }
17473: foreach my $item (@{$filterlist}) {
17474: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17475: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17476: if ($item eq 'domainfilter') {
17477: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17478: } elsif ($item eq 'coursefilter') {
17479: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17480: } elsif ($item eq 'ownerfilter') {
17481: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17482: } elsif ($item eq 'ownerdomfilter') {
17483: $filter->{'ownerdomfilter'} =
17484: &LONCAPA::clean_domain($filter->{$item});
17485: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17486: 'ownerdomfilter',1);
17487: } elsif ($item eq 'personfilter') {
17488: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17489: } elsif ($item eq 'persondomfilter') {
17490: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17491: 'persondomfilter',1);
17492: } else {
17493: $filter->{$item} =~ s/\W//g;
17494: }
17495: if (!$filter->{$item}) {
17496: $filter->{$item} = '';
17497: }
17498: }
17499: if ($item eq 'domainfilter') {
17500: my $allow_blank = 1;
17501: if ($formname eq 'portform') {
17502: $allow_blank=0;
17503: } elsif ($formname eq 'studentform') {
17504: $allow_blank=0;
17505: }
17506: if ($fixeddom) {
17507: $domainselectform = '<input type="hidden" name="domainfilter"'.
17508: ' value="'.$codedom.'" />'.
17509: &Apache::lonnet::domain($codedom,'description');
17510: } else {
17511: $domainselectform = &select_dom_form($filter->{$item},
17512: 'domainfilter',
17513: $allow_blank,'',$onchange);
17514: }
17515: } else {
17516: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17517: }
17518: }
17519:
17520: # last course activity filter and selection
17521: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17522:
17523: # course created filter and selection
17524: if (exists($filter->{'createdfilter'})) {
17525: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17526: }
17527:
17528: my %lt = &Apache::lonlocal::texthash(
17529: 'cac' => "$crstype Activity",
17530: 'ccr' => "$crstype Created",
17531: 'cde' => "$crstype Title",
17532: 'cdo' => "$crstype Domain",
17533: 'ins' => 'Institutional Code',
17534: 'inc' => 'Institutional Categorization',
17535: 'cow' => "$crstype Owner/Co-owner",
17536: 'cop' => "$crstype Personnel Includes",
17537: 'cog' => 'Type',
17538: );
17539:
17540: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17541: my $typeval = 'Course';
17542: if ($crstype eq 'Community') {
17543: $typeval = 'Community';
17544: }
17545: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17546: } else {
17547: $typeselectform = '<select name="type" size="1"';
17548: if ($onchange) {
17549: $typeselectform .= ' onchange="'.$onchange.'"';
17550: }
17551: $typeselectform .= '>'."\n";
17552: foreach my $posstype ('Course','Community') {
17553: $typeselectform.='<option value="'.$posstype.'"'.
17554: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
17555: }
17556: $typeselectform.="</select>";
17557: }
17558:
17559: my ($cloneableonlyform,$cloneabletitle);
17560: if (exists($filter->{'cloneableonly'})) {
17561: my $cloneableon = '';
17562: my $cloneableoff = ' checked="checked"';
17563: if ($filter->{'cloneableonly'}) {
17564: $cloneableon = $cloneableoff;
17565: $cloneableoff = '';
17566: }
17567: $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>';
17568: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 17569: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 17570: } else {
17571: $cloneabletitle = &mt('Cloneable by you');
17572: }
17573: }
17574: my $officialjs;
17575: if ($crstype eq 'Course') {
17576: if (exists($filter->{'instcodefilter'})) {
17577: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17578: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17579: if ($codedom) {
17580: $officialjs = 1;
17581: ($instcodeform,$jscript,$$numtitlesref) =
17582: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17583: $officialjs,$codetitlesref);
17584: if ($jscript) {
17585: $jscript = '<script type="text/javascript">'."\n".
17586: '// <![CDATA['."\n".
17587: $jscript."\n".
17588: '// ]]>'."\n".
17589: '</script>'."\n";
17590: }
17591: }
17592: if ($instcodeform eq '') {
17593: $instcodeform =
17594: '<input type="text" name="instcodefilter" size="10" value="'.
17595: $list->{'instcodefilter'}.'" />';
17596: $instcodetitle = $lt{'ins'};
17597: } else {
17598: $instcodetitle = $lt{'inc'};
17599: }
17600: if ($fixeddom) {
17601: $instcodetitle .= '<br />('.$codedom.')';
17602: }
17603: }
17604: }
17605: my $output = qq|
17606: <form method="post" name="filterpicker" action="$action">
17607: <input type="hidden" name="form" value="$formname" />
17608: |;
17609: if ($formname eq 'modifycourse') {
17610: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17611: '<input type="hidden" name="prevphase" value="'.
17612: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 17613: } elsif ($formname eq 'quotacheck') {
17614: $output .= qq|
17615: <input type="hidden" name="sortby" value="" />
17616: <input type="hidden" name="sortorder" value="" />
17617: |;
17618: } else {
1.1075.2.69 raeburn 17619: my $name_input;
17620: if ($cnameelement ne '') {
17621: $name_input = '<input type="hidden" name="cnameelement" value="'.
17622: $cnameelement.'" />';
17623: }
17624: $output .= qq|
17625: <input type="hidden" name="cnumelement" value="$cnumelement" />
17626: <input type="hidden" name="cdomelement" value="$cdomelement" />
17627: $name_input
17628: $roleelement
17629: $multelement
17630: $typeelement
17631: |;
17632: if ($formname eq 'portform') {
17633: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17634: }
17635: }
17636: if ($fixeddom) {
17637: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17638: }
17639: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17640: if ($sincefilterform) {
17641: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17642: .$sincefilterform
17643: .&Apache::lonhtmlcommon::row_closure();
17644: }
17645: if ($createdfilterform) {
17646: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17647: .$createdfilterform
17648: .&Apache::lonhtmlcommon::row_closure();
17649: }
17650: if ($domainselectform) {
17651: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17652: .$domainselectform
17653: .&Apache::lonhtmlcommon::row_closure();
17654: }
17655: if ($typeselectform) {
17656: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17657: $output .= $typeselectform;
17658: } else {
17659: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17660: .$typeselectform
17661: .&Apache::lonhtmlcommon::row_closure();
17662: }
17663: }
17664: if ($instcodeform) {
17665: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17666: .$instcodeform
17667: .&Apache::lonhtmlcommon::row_closure();
17668: }
17669: if (exists($filter->{'ownerfilter'})) {
17670: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17671: '<table><tr><td>'.&mt('Username').'<br />'.
17672: '<input type="text" name="ownerfilter" size="20" value="'.
17673: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17674: $ownerdomselectform.'</td></tr></table>'.
17675: &Apache::lonhtmlcommon::row_closure();
17676: }
17677: if (exists($filter->{'personfilter'})) {
17678: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17679: '<table><tr><td>'.&mt('Username').'<br />'.
17680: '<input type="text" name="personfilter" size="20" value="'.
17681: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17682: $persondomselectform.'</td></tr></table>'.
17683: &Apache::lonhtmlcommon::row_closure();
17684: }
17685: if (exists($filter->{'coursefilter'})) {
17686: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17687: .'<input type="text" name="coursefilter" size="25" value="'
17688: .$list->{'coursefilter'}.'" />'
17689: .&Apache::lonhtmlcommon::row_closure();
17690: }
17691: if ($cloneableonlyform) {
17692: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17693: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17694: }
17695: if (exists($filter->{'descriptfilter'})) {
17696: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17697: .'<input type="text" name="descriptfilter" size="40" value="'
17698: .$list->{'descriptfilter'}.'" />'
17699: .&Apache::lonhtmlcommon::row_closure(1);
17700: }
17701: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17702: '<input type="hidden" name="updater" value="" />'."\n".
17703: '<input type="submit" name="gosearch" value="'.
17704: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17705: return $jscript.$clonewarning.$output;
17706: }
17707:
17708: =pod
17709:
17710: =item * &timebased_select_form()
17711:
17712: Create markup for a dropdown list used to select a time-based
17713: filter e.g., Course Activity, Course Created, when searching for courses
17714: or communities
17715:
17716: Inputs:
17717:
17718: item - name of form element (sincefilter or createdfilter)
17719:
17720: filter - anonymous hash of criteria and their values
17721:
17722: Returns: HTML for a select box contained a blank, then six time selections,
17723: with value set in incoming form variables currently selected.
17724:
17725: Side Effects: None
17726:
17727: =cut
17728:
17729: sub timebased_select_form {
17730: my ($item,$filter) = @_;
17731: if (ref($filter) eq 'HASH') {
17732: $filter->{$item} =~ s/[^\d-]//g;
17733: if (!$filter->{$item}) { $filter->{$item}=-1; }
17734: return &select_form(
17735: $filter->{$item},
17736: $item,
17737: { '-1' => '',
17738: '86400' => &mt('today'),
17739: '604800' => &mt('last week'),
17740: '2592000' => &mt('last month'),
17741: '7776000' => &mt('last three months'),
17742: '15552000' => &mt('last six months'),
17743: '31104000' => &mt('last year'),
17744: 'select_form_order' =>
17745: ['-1','86400','604800','2592000','7776000',
17746: '15552000','31104000']});
17747: }
17748: }
17749:
17750: =pod
17751:
17752: =item * &js_changer()
17753:
17754: Create script tag containing Javascript used to submit course search form
17755: when course type or domain is changed, and also to hide 'Searching ...' on
17756: page load completion for page showing search result.
17757:
17758: Inputs: None
17759:
17760: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17761:
17762: Side Effects: None
17763:
17764: =cut
17765:
17766: sub js_changer {
17767: return <<ENDJS;
17768: <script type="text/javascript">
17769: // <![CDATA[
17770: function updateFilters(caller) {
17771: if (typeof(caller) != "undefined") {
17772: document.filterpicker.updater.value = caller.name;
17773: }
17774: document.filterpicker.submit();
17775: }
17776:
17777: function hideSearching() {
17778: if (document.getElementById('searching')) {
17779: document.getElementById('searching').style.display = 'none';
17780: }
17781: return;
17782: }
17783:
17784: // ]]>
17785: </script>
17786:
17787: ENDJS
17788: }
17789:
17790: =pod
17791:
17792: =item * &search_courses()
17793:
17794: Process selected filters form course search form and pass to lonnet::courseiddump
17795: to retrieve a hash for which keys are courseIDs which match the selected filters.
17796:
17797: Inputs:
17798:
17799: dom - domain being searched
17800:
17801: type - course type ('Course' or 'Community' or '.' if any).
17802:
17803: filter - anonymous hash of criteria and their values
17804:
17805: numtitles - for institutional codes - number of categories
17806:
17807: cloneruname - optional username of new course owner
17808:
17809: clonerudom - optional domain of new course owner
17810:
1.1075.2.95 raeburn 17811: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17812: (used when DC is using course creation form)
17813:
17814: codetitles - reference to array of titles of components in institutional codes (official courses).
17815:
1.1075.2.95 raeburn 17816: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17817: (and so can clone automatically)
17818:
17819: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17820:
17821: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17822: courses to clone
1.1075.2.69 raeburn 17823:
17824: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17825:
17826:
17827: Side Effects: None
17828:
17829: =cut
17830:
17831:
17832: sub search_courses {
1.1075.2.95 raeburn 17833: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17834: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17835: my (%courses,%showcourses,$cloner);
17836: if (($filter->{'ownerfilter'} ne '') ||
17837: ($filter->{'ownerdomfilter'} ne '')) {
17838: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17839: $filter->{'ownerdomfilter'};
17840: }
17841: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17842: if (!$filter->{$item}) {
17843: $filter->{$item}='.';
17844: }
17845: }
17846: my $now = time;
17847: my $timefilter =
17848: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17849: my ($createdbefore,$createdafter);
17850: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17851: $createdbefore = $now;
17852: $createdafter = $now-$filter->{'createdfilter'};
17853: }
17854: my ($instcodefilter,$regexpok);
17855: if ($numtitles) {
17856: if ($env{'form.official'} eq 'on') {
17857: $instcodefilter =
17858: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17859: $regexpok = 1;
17860: } elsif ($env{'form.official'} eq 'off') {
17861: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17862: unless ($instcodefilter eq '') {
17863: $regexpok = -1;
17864: }
17865: }
17866: } else {
17867: $instcodefilter = $filter->{'instcodefilter'};
17868: }
17869: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17870: if ($type eq '') { $type = '.'; }
17871:
17872: if (($clonerudom ne '') && ($cloneruname ne '')) {
17873: $cloner = $cloneruname.':'.$clonerudom;
17874: }
17875: %courses = &Apache::lonnet::courseiddump($dom,
17876: $filter->{'descriptfilter'},
17877: $timefilter,
17878: $instcodefilter,
17879: $filter->{'combownerfilter'},
17880: $filter->{'coursefilter'},
17881: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17882: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17883: $filter->{'cloneableonly'},
17884: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17885: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17886: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17887: my $ccrole;
17888: if ($type eq 'Community') {
17889: $ccrole = 'co';
17890: } else {
17891: $ccrole = 'cc';
17892: }
17893: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17894: $filter->{'persondomfilter'},
17895: 'userroles',undef,
17896: [$ccrole,'in','ad','ep','ta','cr'],
17897: $dom);
17898: foreach my $role (keys(%rolehash)) {
17899: my ($cnum,$cdom,$courserole) = split(':',$role);
17900: my $cid = $cdom.'_'.$cnum;
17901: if (exists($courses{$cid})) {
17902: if (ref($courses{$cid}) eq 'HASH') {
17903: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17904: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17905: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17906: }
17907: } else {
17908: $courses{$cid}{roles} = [$courserole];
17909: }
17910: $showcourses{$cid} = $courses{$cid};
17911: }
17912: }
17913: }
17914: %courses = %showcourses;
17915: }
17916: return %courses;
17917: }
17918:
17919: =pod
17920:
17921: =back
17922:
1.1075.2.88 raeburn 17923: =head1 Routines for version requirements for current course.
17924:
17925: =over 4
17926:
17927: =item * &check_release_required()
17928:
17929: Compares required LON-CAPA version with version on server, and
17930: if required version is newer looks for a server with the required version.
17931:
17932: Looks first at servers in user's owen domain; if none suitable, looks at
17933: servers in course's domain are permitted to host sessions for user's domain.
17934:
17935: Inputs:
17936:
17937: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17938:
17939: $courseid - Course ID of current course
17940:
17941: $rolecode - User's current role in course (for switchserver query string).
17942:
17943: $required - LON-CAPA version needed by course (format: Major.Minor).
17944:
17945:
17946: Returns:
17947:
17948: $switchserver - query string tp append to /adm/switchserver call (if
17949: current server's LON-CAPA version is too old.
17950:
17951: $warning - Message is displayed if no suitable server could be found.
17952:
17953: =cut
17954:
17955: sub check_release_required {
17956: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17957: my ($switchserver,$warning);
17958: if ($required ne '') {
17959: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17960: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17961: if ($reqdmajor ne '' && $reqdminor ne '') {
17962: my $otherserver;
17963: if (($major eq '' && $minor eq '') ||
17964: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17965: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17966: my $switchlcrev =
17967: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17968: $userdomserver);
17969: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17970: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17971: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17972: my $cdom = $env{'course.'.$courseid.'.domain'};
17973: if ($cdom ne $env{'user.domain'}) {
17974: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17975: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17976: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17977: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17978: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17979: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17980: my $canhost =
17981: &Apache::lonnet::can_host_session($env{'user.domain'},
17982: $coursedomserver,
17983: $remoterev,
17984: $udomdefaults{'remotesessions'},
17985: $defdomdefaults{'hostedsessions'});
17986:
17987: if ($canhost) {
17988: $otherserver = $coursedomserver;
17989: } else {
17990: $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.");
17991: }
17992: } else {
17993: $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).");
17994: }
17995: } else {
17996: $otherserver = $userdomserver;
17997: }
17998: }
17999: if ($otherserver ne '') {
18000: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18001: }
18002: }
18003: }
18004: return ($switchserver,$warning);
18005: }
18006:
18007: =pod
18008:
18009: =item * &check_release_result()
18010:
18011: Inputs:
18012:
18013: $switchwarning - Warning message if no suitable server found to host session.
18014:
18015: $switchserver - query string to append to /adm/switchserver containing lonHostID
18016: and current role.
18017:
18018: Returns: HTML to display with information about requirement to switch server.
18019: Either displaying warning with link to Roles/Courses screen or
18020: display link to switchserver.
18021:
1.1075.2.69 raeburn 18022: =cut
18023:
1.1075.2.88 raeburn 18024: sub check_release_result {
18025: my ($switchwarning,$switchserver) = @_;
18026: my $output = &start_page('Selected course unavailable on this server').
18027: '<p class="LC_warning">';
18028: if ($switchwarning) {
18029: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18030: if (&show_course()) {
18031: $output .= &mt('Display courses');
18032: } else {
18033: $output .= &mt('Display roles');
18034: }
18035: $output .= '</a>';
18036: } elsif ($switchserver) {
18037: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18038: '<br />'.
18039: '<a href="/adm/switchserver?'.$switchserver.'">'.
18040: &mt('Switch Server').
18041: '</a>';
18042: }
18043: $output .= '</p>'.&end_page();
18044: return $output;
18045: }
18046:
18047: =pod
18048:
18049: =item * &needs_coursereinit()
18050:
18051: Determine if course contents stored for user's session needs to be
18052: refreshed, because content has changed since "Big Hash" last tied.
18053:
18054: Check for change is made if time last checked is more than 10 minutes ago
18055: (by default).
18056:
18057: Inputs:
18058:
18059: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18060:
18061: $interval (optional) - Time which may elapse (in s) between last check for content
18062: change in current course. (default: 600 s).
18063:
18064: Returns: an array; first element is:
18065:
18066: =over 4
18067:
18068: 'switch' - if content updates mean user's session
18069: needs to be switched to a server running a newer LON-CAPA version
18070:
18071: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18072: on current server hosting user's session
18073:
18074: '' - if no action required.
18075:
18076: =back
18077:
18078: If first item element is 'switch':
18079:
18080: second item is $switchwarning - Warning message if no suitable server found to host session.
18081:
18082: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18083: and current role.
18084:
18085: otherwise: no other elements returned.
18086:
18087: =back
18088:
18089: =cut
18090:
18091: sub needs_coursereinit {
18092: my ($loncaparev,$interval) = @_;
18093: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18094: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18095: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18096: my $now = time;
18097: if ($interval eq '') {
18098: $interval = 600;
18099: }
18100: if (($now-$env{'request.course.timechecked'})>$interval) {
18101: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 18102:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 18103:21): if ($blocked) {
18104:21): return ();
18105:21): }
.13(raeb 18106:-23): my $update;
18107:-23): my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18108:-23): my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18109:-23): if ($lastmainchange > $env{'request.course.tied'}) {
18110:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18111:-23): if ($needswitch) {
18112:-23): return ('switch',$switchwarning,$switchserver);
18113:-23): }
18114:-23): $update = 'main';
18115:-23): }
18116:-23): if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18117:-23): if ($update) {
18118:-23): $update = 'both';
18119:-23): } else {
18120:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18121:-23): if ($needswitch) {
18122:-23): return ('switch',$switchwarning,$switchserver);
18123:-23): } else {
18124:-23): $update = 'supp';
1.1075.2.88 raeburn 18125: }
18126: }
1.1075.2.161. .13(raeb 18127:-23): return ($update);
18128:-23): }
18129:-23): }
18130:-23): return ();
18131:-23): }
18132:-23):
18133:-23): sub switch_for_update {
18134:-23): my ($loncaparev,$cdom,$cnum) = @_;
18135:-23): my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18136:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18137:-23): my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18138:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18139:-23): &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18140:-23): $curr_reqd_hash{'internal.releaserequired'}});
18141:-23): my ($switchserver,$switchwarning) =
18142:-23): &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18143:-23): $curr_reqd_hash{'internal.releaserequired'});
18144:-23): if ($switchwarning ne '' || $switchserver ne '') {
18145:-23): return ('switch',$switchwarning,$switchserver);
18146:-23): }
1.1075.2.88 raeburn 18147: }
18148: }
18149: return ();
18150: }
1.1075.2.69 raeburn 18151:
1.1075.2.11 raeburn 18152: sub update_content_constraints {
18153: my ($cdom,$cnum,$chome,$cid) = @_;
18154: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18155: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
18156: my %checkresponsetypes;
18157: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
18158: my ($item,$name,$value) = split(/:/,$key);
18159: if ($item eq 'resourcetag') {
18160: if ($name eq 'responsetype') {
18161: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18162: }
18163: }
18164: }
18165: my $navmap = Apache::lonnavmaps::navmap->new();
18166: if (defined($navmap)) {
18167: my %allresponses;
18168: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
18169: my %responses = $res->responseTypes();
18170: foreach my $key (keys(%responses)) {
18171: next unless(exists($checkresponsetypes{$key}));
18172: $allresponses{$key} += $responses{$key};
18173: }
18174: }
18175: foreach my $key (keys(%allresponses)) {
18176: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18177: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18178: ($reqdmajor,$reqdminor) = ($major,$minor);
18179: }
18180: }
18181: undef($navmap);
18182: }
18183: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18184: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18185: }
18186: return;
18187: }
18188:
1.1075.2.27 raeburn 18189: sub allmaps_incourse {
18190: my ($cdom,$cnum,$chome,$cid) = @_;
18191: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18192: $cid = $env{'request.course.id'};
18193: $cdom = $env{'course.'.$cid.'.domain'};
18194: $cnum = $env{'course.'.$cid.'.num'};
18195: $chome = $env{'course.'.$cid.'.home'};
18196: }
18197: my %allmaps = ();
18198: my $lastchange =
18199: &Apache::lonnet::get_coursechange($cdom,$cnum);
18200: if ($lastchange > $env{'request.course.tied'}) {
18201: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18202: unless ($ferr) {
18203: &update_content_constraints($cdom,$cnum,$chome,$cid);
18204: }
18205: }
18206: my $navmap = Apache::lonnavmaps::navmap->new();
18207: if (defined($navmap)) {
18208: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18209: $allmaps{$res->src()} = 1;
18210: }
18211: }
18212: return \%allmaps;
18213: }
18214:
1.1075.2.11 raeburn 18215: sub parse_supplemental_title {
18216: my ($title) = @_;
18217:
18218: my ($foldertitle,$renametitle);
18219: if ($title =~ /&&&/) {
18220: $title = &HTML::Entites::decode($title);
18221: }
18222: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18223: $renametitle=$4;
18224: my ($time,$uname,$udom) = ($1,$2,$3);
18225: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18226: my $name = &plainname($uname,$udom);
18227: $name = &HTML::Entities::encode($name,'"<>&\'');
18228: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1075.2.161. .16(raeb 18229:-23): $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
18230:-23): if ($foldertitle ne '') {
18231:-23): $title .= ': <br />'.$foldertitle;
18232:-23): }
1.1075.2.11 raeburn 18233: }
18234: if (wantarray) {
18235: return ($title,$foldertitle,$renametitle);
18236: }
18237: return $title;
18238: }
18239:
1.1075.2.161. .13(raeb 18240:-23): sub get_supplemental {
18241:-23): my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18242:-23): my $hashid=$cnum.':'.$cdom;
18243:-23): my ($supplemental,$cached,$set_httprefs);
18244:-23): unless ($ignorecache) {
18245:-23): ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18246:-23): }
18247:-23): unless (defined($cached)) {
18248:-23): my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18249:-23): unless ($chome eq 'no_host') {
18250:-23): my @order = @LONCAPA::map::order;
18251:-23): my @resources = @LONCAPA::map::resources;
18252:-23): my @resparms = @LONCAPA::map::resparms;
18253:-23): my @zombies = @LONCAPA::map::zombies;
18254:-23): my ($errors,%ids,%hidden);
18255:-23): $errors =
18256:-23): &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18257:-23): $errors,$possdel,\%ids,\%hidden);
18258:-23): @LONCAPA::map::order = @order;
18259:-23): @LONCAPA::map::resources = @resources;
18260:-23): @LONCAPA::map::resparms = @resparms;
18261:-23): @LONCAPA::map::zombies = @zombies;
18262:-23): $set_httprefs = 1;
18263:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18264:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18265:-23): }
18266:-23): $supplemental = {
18267:-23): ids => \%ids,
18268:-23): hidden => \%hidden,
18269:-23): };
18270:-23): &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18271:-23): }
18272:-23): }
18273:-23): return ($supplemental,$set_httprefs);
18274:-23): }
18275:-23):
1.1075.2.43 raeburn 18276: sub recurse_supplemental {
1.1075.2.161. .13(raeb 18277:-23): my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18278:-23): if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18279:-23): my $mapnum;
18280:-23): if ($suppmap eq 'supplemental.sequence') {
18281:-23): $mapnum = 0;
18282:-23): } else {
18283:-23): ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18284:-23): }
1.1075.2.43 raeburn 18285: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18286: if ($fatal) {
18287: $errors ++;
18288: } else {
1.1075.2.161. .13(raeb 18289:-23): my @order = @LONCAPA::map::order;
18290:-23): if (@order > 0) {
18291:-23): my @resources = @LONCAPA::map::resources;
18292:-23): my @resparms = @LONCAPA::map::resparms;
18293:-23): foreach my $idx (@order) {
18294:-23): my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 18295: if (($src ne '') && ($status eq 'res')) {
1.1075.2.161. .13(raeb 18296:-23): my $id = $mapnum.':'.$idx;
18297:-23): push(@{$suppids->{$src}},$id);
18298:-23): if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18299:-23): $hiddensupp->{$id} = 1;
18300:-23): }
1.1075.2.46 raeburn 18301: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1075.2.161. .13(raeb 18302:-23): $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18303:-23): $hiddensupp,$hiddensupp->{$id});
1.1075.2.43 raeburn 18304: } else {
1.1075.2.161. .13(raeb 18305:-23): my $allowed;
18306:-23): if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18307:-23): $allowed = 1;
18308:-23): } elsif ($possdel) {
18309:-23): foreach my $item (@{$suppids->{$src}}) {
18310:-23): next if ($item eq $id);
18311:-23): unless ($hiddensupp->{$item}) {
18312:-23): $allowed = 1;
18313:-23): last;
18314:-23): }
18315:-23): }
18316:-23): if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18317:-23): &Apache::lonnet::delenv('httpref.'.$src);
18318:-23): }
18319:-23): }
18320:-23): if ($allowed && (!exists($env{'httpref.'.$src}))) {
18321:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18322:-23): }
18323:-23): }
18324:-23): }
18325:-23): }
18326:-23): }
18327:-23): }
18328:-23): }
18329:-23): return $errors;
18330:-23): }
18331:-23):
18332:-23): sub set_supp_httprefs {
18333:-23): my ($cnum,$cdom,$supplemental,$possdel) = @_;
18334:-23): if (ref($supplemental) eq 'HASH') {
18335:-23): if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18336:-23): foreach my $src (keys(%{$supplemental->{'ids'}})) {
18337:-23): next if ($src =~ /\.sequence$/);
18338:-23): if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18339:-23): my $allowed;
18340:-23): if ($env{'request.role.adv'}) {
18341:-23): $allowed = 1;
18342:-23): } else {
18343:-23): foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18344:-23): unless ($supplemental->{'hidden'}->{$id}) {
18345:-23): $allowed = 1;
18346:-23): last;
18347:-23): }
18348:-23): }
18349:-23): }
18350:-23): if (exists($env{'httpref.'.$src})) {
18351:-23): if ($possdel) {
18352:-23): unless ($allowed) {
18353:-23): &Apache::lonnet::delenv('httpref.'.$src);
18354:-23): }
1.1075.2.43 raeburn 18355: }
1.1075.2.161. .13(raeb 18356:-23): } elsif ($allowed) {
18357:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1075.2.43 raeburn 18358: }
18359: }
18360: }
1.1075.2.161. .13(raeb 18361:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18362:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18363:-23): }
1.1075.2.43 raeburn 18364: }
18365: }
1.1075.2.161. .13(raeb 18366:-23): }
18367:-23):
18368:-23): sub get_supp_parameter {
18369:-23): my ($resparm,$name)=@_;
18370:-23): return if ($resparm eq '');
18371:-23): my $value=undef;
18372:-23): my $ptype=undef;
18373:-23): foreach (split('&&&',$resparm)) {
18374:-23): my ($thistype,$thisname,$thisvalue)=split('___',$_);
18375:-23): if ($thisname eq $name) {
18376:-23): $value=$thisvalue;
18377:-23): $ptype=$thistype;
18378:-23): }
18379:-23): }
18380:-23): return $value;
1.1075.2.43 raeburn 18381: }
18382:
1.1075.2.18 raeburn 18383: sub symb_to_docspath {
1.1075.2.119 raeburn 18384: my ($symb,$navmapref) = @_;
18385: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 18386: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18387: if ($resurl=~/\.(sequence|page)$/) {
18388: $mapurl=$resurl;
18389: } elsif ($resurl eq 'adm/navmaps') {
18390: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18391: }
18392: my $mapresobj;
1.1075.2.119 raeburn 18393: unless (ref($$navmapref)) {
18394: $$navmapref = Apache::lonnavmaps::navmap->new();
18395: }
18396: if (ref($$navmapref)) {
18397: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 18398: }
18399: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18400: my $type=$2;
18401: my $path;
18402: if (ref($mapresobj)) {
18403: my $pcslist = $mapresobj->map_hierarchy();
18404: if ($pcslist ne '') {
18405: foreach my $pc (split(/,/,$pcslist)) {
18406: next if ($pc <= 1);
1.1075.2.119 raeburn 18407: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 18408: if (ref($res)) {
18409: my $thisurl = $res->src();
18410: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18411: my $thistitle = $res->title();
18412: $path .= '&'.
18413: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 18414: &escape($thistitle).
1.1075.2.18 raeburn 18415: ':'.$res->randompick().
18416: ':'.$res->randomout().
18417: ':'.$res->encrypted().
18418: ':'.$res->randomorder().
18419: ':'.$res->is_page();
18420: }
18421: }
18422: }
18423: $path =~ s/^\&//;
18424: my $maptitle = $mapresobj->title();
18425: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18426: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18427: }
18428: $path .= (($path ne '')? '&' : '').
18429: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18430: &escape($maptitle).
1.1075.2.18 raeburn 18431: ':'.$mapresobj->randompick().
18432: ':'.$mapresobj->randomout().
18433: ':'.$mapresobj->encrypted().
18434: ':'.$mapresobj->randomorder().
18435: ':'.$mapresobj->is_page();
18436: } else {
18437: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18438: my $ispage = (($type eq 'page')? 1 : '');
18439: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18440: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18441: }
18442: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18443: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 18444: }
18445: unless ($mapurl eq 'default') {
18446: $path = 'default&'.
1.1075.2.46 raeburn 18447: &escape('Main Content').
1.1075.2.18 raeburn 18448: ':::::&'.$path;
18449: }
18450: return $path;
18451: }
18452:
1.1075.2.161. .13(raeb 18453:-23): sub validate_folderpath {
18454:-23): my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18455:-23): if ($env{'form.folderpath'} ne '') {
18456:-23): my @items = split(/\&/,$env{'form.folderpath'});
18457:-23): my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
18458:-23): for (my $i=0; $i<@items; $i++) {
18459:-23): my $odd = $i%2;
18460:-23): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18461:-23): $badpath = 1;
18462:-23): } elsif ($odd && $supplementalflag) {
18463:-23): my $idx = $i-1;
18464:-23): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18465:-23): my $esc_name = $1;
18466:-23): if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18467:-23): $supppath .= '&'.$esc_name;
18468:-23): $changed = 1;
18469:-23): } else {
18470:-23): $supppath .= '&'.$items[$i];
18471:-23): }
18472:-23): } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18473:-23): $changed = 1;
18474:-23): my $is_hidden;
18475:-23): unless ($got_supp) {
18476:-23): my ($supplemental) = &get_supplemental($coursenum,$coursedom);
18477:-23): if (ref($supplemental) eq 'HASH') {
18478:-23): if (ref($supplemental->{'hidden'}) eq 'HASH') {
18479:-23): %supphidden = %{$supplemental->{'hidden'}};
18480:-23): }
18481:-23): if (ref($supplemental->{'ids'}) eq 'HASH') {
18482:-23): %suppids = %{$supplemental->{'ids'}};
18483:-23): }
18484:-23): }
18485:-23): $got_supp = 1;
18486:-23): }
18487:-23): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18488:-23): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18489:-23): if ($supphidden{$mapid}) {
18490:-23): $is_hidden = 1;
18491:-23): }
18492:-23): }
18493:-23): $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18494:-23): } else {
18495:-23): $supppath .= '&'.$items[$i];
18496:-23): }
18497:-23): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18498:-23): $badpath = 1;
18499:-23): } elsif ($supplementalflag) {
18500:-23): $supppath .= '&'.$items[$i];
18501:-23): }
18502:-23): last if ($badpath);
18503:-23): }
18504:-23): if ($badpath) {
18505:-23): delete($env{'form.folderpath'});
18506:-23): } elsif ($changed && $supplementalflag) {
18507:-23): $supppath =~ s/^\&//;
18508:-23): $env{'form.folderpath'} = $supppath;
18509:-23): }
18510:-23): }
18511:-23): return;
18512:-23): }
18513:-23):
1.1075.2.14 raeburn 18514: sub captcha_display {
1.1075.2.137 raeburn 18515: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18516: my ($output,$error);
1.1075.2.107 raeburn 18517: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 18518: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18519: if ($captcha eq 'original') {
18520: $output = &create_captcha();
18521: unless ($output) {
18522: $error = 'captcha';
18523: }
18524: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18525: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 18526: unless ($output) {
18527: $error = 'recaptcha';
18528: }
18529: }
1.1075.2.107 raeburn 18530: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 18531: }
18532:
18533: sub captcha_response {
1.1075.2.137 raeburn 18534: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18535: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 18536: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18537: if ($captcha eq 'original') {
18538: ($captcha_chk,$captcha_error) = &check_captcha();
18539: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18540: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 18541: } else {
18542: $captcha_chk = 1;
18543: }
18544: return ($captcha_chk,$captcha_error);
18545: }
18546:
18547: sub get_captcha_config {
1.1075.2.137 raeburn 18548: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 18549: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 18550: my $hostname = &Apache::lonnet::hostname($lonhost);
18551: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18552: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18553: if ($context eq 'usercreation') {
18554: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18555: if (ref($domconfig{$context}) eq 'HASH') {
18556: $hashtocheck = $domconfig{$context}{'cancreate'};
18557: if (ref($hashtocheck) eq 'HASH') {
18558: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18559: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18560: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18561: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18562: }
18563: if ($privkey && $pubkey) {
18564: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18565: $version = $hashtocheck->{'recaptchaversion'};
18566: if ($version ne '2') {
18567: $version = 1;
18568: }
1.1075.2.14 raeburn 18569: } else {
18570: $captcha = 'original';
18571: }
18572: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18573: $captcha = 'original';
18574: }
18575: }
18576: } else {
18577: $captcha = 'captcha';
18578: }
18579: } elsif ($context eq 'login') {
18580: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18581: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18582: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18583: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
18584: if ($privkey && $pubkey) {
18585: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18586: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18587: if ($version ne '2') {
18588: $version = 1;
18589: }
1.1075.2.14 raeburn 18590: } else {
18591: $captcha = 'original';
18592: }
18593: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18594: $captcha = 'original';
18595: }
1.1075.2.137 raeburn 18596: } elsif ($context eq 'passwords') {
18597: if ($dom_in_effect) {
18598: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18599: if ($passwdconf{'captcha'} eq 'recaptcha') {
18600: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18601: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18602: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18603: }
18604: if ($privkey && $pubkey) {
18605: $captcha = 'recaptcha';
18606: $version = $passwdconf{'recaptchaversion'};
18607: if ($version ne '2') {
18608: $version = 1;
18609: }
18610: } else {
18611: $captcha = 'original';
18612: }
18613: } elsif ($passwdconf{'captcha'} ne 'notused') {
18614: $captcha = 'original';
18615: }
18616: }
1.1075.2.14 raeburn 18617: }
1.1075.2.107 raeburn 18618: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 18619: }
18620:
18621: sub create_captcha {
18622: my %captcha_params = &captcha_settings();
18623: my ($output,$maxtries,$tries) = ('',10,0);
18624: while ($tries < $maxtries) {
18625: $tries ++;
18626: my $captcha = Authen::Captcha->new (
18627: output_folder => $captcha_params{'output_dir'},
18628: data_folder => $captcha_params{'db_dir'},
18629: );
18630: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18631:
18632: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18633: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 18634: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 18635: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.161. .15(raeb 18636:-23): '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 18637: '</span><br />'.
1.1075.2.66 raeburn 18638: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 18639: last;
18640: }
18641: }
1.1075.2.158 raeburn 18642: if ($output eq '') {
18643: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18644: }
1.1075.2.14 raeburn 18645: return $output;
18646: }
18647:
18648: sub captcha_settings {
18649: my %captcha_params = (
18650: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18651: www_output_dir => "/captchaspool",
18652: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18653: numchars => '5',
18654: );
18655: return %captcha_params;
18656: }
18657:
18658: sub check_captcha {
18659: my ($captcha_chk,$captcha_error);
18660: my $code = $env{'form.code'};
18661: my $md5sum = $env{'form.crypt'};
18662: my %captcha_params = &captcha_settings();
18663: my $captcha = Authen::Captcha->new(
18664: output_folder => $captcha_params{'output_dir'},
18665: data_folder => $captcha_params{'db_dir'},
18666: );
1.1075.2.26 raeburn 18667: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 18668: my %captcha_hash = (
18669: 0 => 'Code not checked (file error)',
18670: -1 => 'Failed: code expired',
18671: -2 => 'Failed: invalid code (not in database)',
18672: -3 => 'Failed: invalid code (code does not match crypt)',
18673: );
18674: if ($captcha_chk != 1) {
18675: $captcha_error = $captcha_hash{$captcha_chk}
18676: }
18677: return ($captcha_chk,$captcha_error);
18678: }
18679:
18680: sub create_recaptcha {
1.1075.2.107 raeburn 18681: my ($pubkey,$version) = @_;
18682: if ($version >= 2) {
1.1075.2.158 raeburn 18683: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18684: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 18685: } else {
18686: my $use_ssl;
18687: if ($ENV{'SERVER_PORT'} == 443) {
18688: $use_ssl = 1;
18689: }
18690: my $captcha = Captcha::reCAPTCHA->new;
18691: return $captcha->get_options_setter({theme => 'white'})."\n".
18692: $captcha->get_html($pubkey,undef,$use_ssl).
18693: &mt('If the text is hard to read, [_1] will replace them.',
18694: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18695: '<br /><br />';
18696: }
1.1075.2.14 raeburn 18697: }
18698:
18699: sub check_recaptcha {
1.1075.2.107 raeburn 18700: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 18701: my $captcha_chk;
1.1075.2.150 raeburn 18702: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 18703: if ($version >= 2) {
18704: my $ua = LWP::UserAgent->new;
18705: $ua->timeout(10);
18706: my %info = (
18707: secret => $privkey,
18708: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 18709: remoteip => $ip,
1.1075.2.107 raeburn 18710: );
18711: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
18712: if ($response->is_success) {
18713: my $data = JSON::DWIW->from_json($response->decoded_content);
18714: if (ref($data) eq 'HASH') {
18715: if ($data->{'success'}) {
18716: $captcha_chk = 1;
18717: }
18718: }
18719: }
18720: } else {
18721: my $captcha = Captcha::reCAPTCHA->new;
18722: my $captcha_result =
18723: $captcha->check_answer(
18724: $privkey,
1.1075.2.150 raeburn 18725: $ip,
1.1075.2.107 raeburn 18726: $env{'form.recaptcha_challenge_field'},
18727: $env{'form.recaptcha_response_field'},
18728: );
18729: if ($captcha_result->{is_valid}) {
18730: $captcha_chk = 1;
18731: }
1.1075.2.14 raeburn 18732: }
18733: return $captcha_chk;
18734: }
18735:
1.1075.2.64 raeburn 18736: sub emailusername_info {
1.1075.2.103 raeburn 18737: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 18738: my %titles = &Apache::lonlocal::texthash (
18739: lastname => 'Last Name',
18740: firstname => 'First Name',
18741: institution => 'School/college/university',
18742: location => "School's city, state/province, country",
18743: web => "School's web address",
18744: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 18745: id => 'Student/Employee ID',
1.1075.2.64 raeburn 18746: );
18747: return (\@fields,\%titles);
18748: }
18749:
1.1075.2.56 raeburn 18750: sub cleanup_html {
18751: my ($incoming) = @_;
18752: my $outgoing;
18753: if ($incoming ne '') {
18754: $outgoing = $incoming;
18755: $outgoing =~ s/;/;/g;
18756: $outgoing =~ s/\#/#/g;
18757: $outgoing =~ s/\&/&/g;
18758: $outgoing =~ s/</</g;
18759: $outgoing =~ s/>/>/g;
18760: $outgoing =~ s/\(/(/g;
18761: $outgoing =~ s/\)/)/g;
18762: $outgoing =~ s/"/"/g;
18763: $outgoing =~ s/'/'/g;
18764: $outgoing =~ s/\$/$/g;
18765: $outgoing =~ s{/}{/}g;
18766: $outgoing =~ s/=/=/g;
18767: $outgoing =~ s/\\/\/g
18768: }
18769: return $outgoing;
18770: }
18771:
1.1075.2.74 raeburn 18772: # Checks for critical messages and returns a redirect url if one exists.
18773: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 18774:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 18775: sub critical_redirect {
1.1075.2.161. .1(raebu 18776:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 18777: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18778: return ();
18779: }
1.1075.2.74 raeburn 18780: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 18781:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18782:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18783:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 18784:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 18785:21): if ($blocked) {
18786:21): my $checkrole = "cm./$cdom/$cnum";
18787:21): if ($env{'request.course.sec'} ne '') {
18788:21): $checkrole .= "/$env{'request.course.sec'}";
18789:21): }
18790:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18791:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18792:21): return;
18793:21): }
18794:21): }
18795:21): }
1.1075.2.74 raeburn 18796: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18797: $env{'user.name'});
18798: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
18799: my $redirecturl;
18800: if ($what[0]) {
1.1075.2.158 raeburn 18801: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 18802: $redirecturl='/adm/email?critical=display';
18803: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18804: return (1, $url);
18805: }
18806: }
18807: }
18808: return ();
18809: }
18810:
1.1075.2.64 raeburn 18811: # Use:
18812: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18813: #
18814: ##################################################
18815: # password associated functions #
18816: ##################################################
18817: sub des_keys {
18818: # Make a new key for DES encryption.
18819: # Each key has two parts which are returned separately.
18820: # Please note: Each key must be passed through the &hex function
18821: # before it is output to the web browser. The hex versions cannot
18822: # be used to decrypt.
18823: my @hexstr=('0','1','2','3','4','5','6','7',
18824: '8','9','a','b','c','d','e','f');
18825: my $lkey='';
18826: for (0..7) {
18827: $lkey.=$hexstr[rand(15)];
18828: }
18829: my $ukey='';
18830: for (0..7) {
18831: $ukey.=$hexstr[rand(15)];
18832: }
18833: return ($lkey,$ukey);
18834: }
18835:
18836: sub des_decrypt {
18837: my ($key,$cyphertext) = @_;
18838: my $keybin=pack("H16",$key);
18839: my $cypher;
18840: if ($Crypt::DES::VERSION>=2.03) {
18841: $cypher=new Crypt::DES $keybin;
18842: } else {
18843: $cypher=new DES $keybin;
18844: }
1.1075.2.106 raeburn 18845: my $plaintext='';
18846: my $cypherlength = length($cyphertext);
18847: my $numchunks = int($cypherlength/32);
18848: for (my $j=0; $j<$numchunks; $j++) {
18849: my $start = $j*32;
18850: my $cypherblock = substr($cyphertext,$start,32);
18851: my $chunk =
18852: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18853: $chunk .=
18854: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18855: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18856: $plaintext .= $chunk;
18857: }
1.1075.2.64 raeburn 18858: return $plaintext;
18859: }
18860:
1.1075.2.161. .1(raebu 18861:21): sub get_requested_shorturls {
18862:21): my ($cdom,$cnum,$navmap) = @_;
18863:21): return unless (ref($navmap));
18864:21): my ($numnew,$errors);
18865:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18866:21): if (@toshorten) {
18867:21): my (%maps,%resources,%titles);
18868:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18869:21): 'shorturls',$cdom,$cnum);
18870:21): if (keys(%resources)) {
18871:21): my %tocreate;
18872:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18873:21): my $symb = $resources{$item};
18874:21): if ($symb) {
18875:21): $tocreate{$cnum.'&'.$symb} = 1;
18876:21): }
18877:21): }
18878:21): if (keys(%tocreate)) {
18879:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18880:21): \%tocreate);
18881:21): }
18882:21): }
18883:21): }
18884:21): return ($numnew,$errors);
18885:21): }
18886:21):
18887:21): sub make_short_symbs {
18888:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18889:21): my ($numnew,@errors);
18890:21): if (ref($tocreateref) eq 'HASH') {
18891:21): my %tocreate = %{$tocreateref};
18892:21): if (keys(%tocreate)) {
18893:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18894:21): my $su = Short::URL->new(no_vowels => 1);
18895:21): my $init = '';
18896:21): my (%newunique,%addcourse,%courseonly,%failed);
18897:21): # get lock on tiny db
18898:21): my $now = time;
18899:21): if ($lockuser eq '') {
18900:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18901:21): }
18902:21): my $lockhash = {
18903:21): "lock\0$now" => $lockuser,
18904:21): };
18905:21): my $tries = 0;
18906:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18907:21): my ($code,$error);
18908:21): while (($gotlock ne 'ok') && ($tries<3)) {
18909:21): $tries ++;
18910:21): sleep 1;
18911:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18912:21): }
18913:21): if ($gotlock eq 'ok') {
18914:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18915:21): \%addcourse,\%courseonly,\%failed);
18916:21): if (keys(%failed)) {
18917:21): my $numfailed = scalar(keys(%failed));
18918:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18919:21): }
18920:21): if (keys(%newunique)) {
18921:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18922:21): if ($putres eq 'ok') {
18923:21): $numnew = scalar(keys(%newunique));
18924:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18925:21): unless ($newputres eq 'ok') {
18926:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
18927:21): }
18928:21): } else {
18929:21): push(@errors,&mt('error: could not store unique six character URLs'));
18930:21): }
18931:21): }
18932:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18933:21): unless ($dellockres eq 'ok') {
18934:21): push(@errors,&mt('error: could not release lockfile'));
18935:21): }
18936:21): } else {
18937:21): push(@errors,&mt('error: could not obtain lockfile'));
18938:21): }
18939:21): if (keys(%courseonly)) {
18940:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18941:21): if ($result ne 'ok') {
18942:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
18943:21): }
18944:21): }
18945:21): }
18946:21): }
18947:21): return ($numnew,\@errors);
18948:21): }
18949:21):
18950:21): sub shorten_symbs {
18951:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18952:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18953:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18954:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18955:21): my (%possibles,%collisions);
18956:21): foreach my $key (keys(%{$tocreate})) {
18957:21): my $num = String::CRC32::crc32($key);
18958:21): my $tiny = $su->encode($num,$init);
18959:21): if ($tiny) {
18960:21): $possibles{$tiny} = $key;
18961:21): }
18962:21): }
18963:21): if (!$init) {
18964:21): $init = 1;
18965:21): } else {
18966:21): $init ++;
18967:21): }
18968:21): if (keys(%possibles)) {
18969:21): my @posstiny = keys(%possibles);
18970:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18971:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18972:21): if (keys(%currtiny)) {
18973:21): foreach my $key (keys(%currtiny)) {
18974:21): next if ($currtiny{$key} eq '');
18975:21): if ($currtiny{$key} eq $possibles{$key}) {
18976:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18977:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18978:21): $courseonly->{$tsymb} = $key;
18979:21): }
18980:21): } else {
18981:21): $collisions{$possibles{$key}} = 1;
18982:21): }
18983:21): delete($possibles{$key});
18984:21): }
18985:21): }
18986:21): foreach my $key (keys(%possibles)) {
18987:21): $newunique->{$key} = $possibles{$key};
18988:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18989:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18990:21): $addcourse->{$tsymb} = $key;
18991:21): }
18992:21): }
18993:21): }
18994:21): if (keys(%collisions)) {
18995:21): if ($init <5) {
18996:21): if (!$init) {
18997:21): $init = 1;
18998:21): } else {
18999:21): $init ++;
19000:21): }
19001:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19002:21): $newunique,$addcourse,$courseonly,$failed);
19003:21): } else {
19004:21): foreach my $key (keys(%collisions)) {
19005:21): $failed->{$key} = 1;
19006:21): $failed->{$key} = 1;
19007:21): }
19008:21): }
19009:21): }
19010:21): return $init;
19011:21): }
19012:21):
1.1075.2.135 raeburn 19013: sub is_nonframeable {
19014: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19015: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
19016: return if (($remprotocol eq '') || ($remhost eq ''));
19017:
19018: $remprotocol = lc($remprotocol);
19019: $remhost = lc($remhost);
19020: my $remport = 80;
19021: if ($remprotocol eq 'https') {
19022: $remport = 443;
19023: }
19024: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
19025: if ($cached) {
19026: unless ($nocache) {
19027: if ($result) {
19028: return 1;
19029: } else {
19030: return 0;
19031: }
19032: }
19033: }
19034: my $uselink;
19035: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 19036: my $ua = LWP::UserAgent->new;
19037: $ua->timeout(5);
19038: my $response=$ua->request($request);
1.1075.2.135 raeburn 19039: if ($response->is_success()) {
19040: my $secpolicy = lc($response->header('content-security-policy'));
19041: my $xframeop = lc($response->header('x-frame-options'));
19042: $secpolicy =~ s/^\s+|\s+$//g;
19043: $xframeop =~ s/^\s+|\s+$//g;
19044: if (($secpolicy ne '') || ($xframeop ne '')) {
19045: my $remotehost = $remprotocol.'://'.$remhost;
19046: my ($origin,$protocol,$port);
19047: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19048: $port = $ENV{'SERVER_PORT'};
19049: } else {
19050: $port = 80;
19051: }
19052: if ($absolute eq '') {
19053: $protocol = 'http:';
19054: if ($port == 443) {
19055: $protocol = 'https:';
19056: }
19057: $origin = $protocol.'//'.lc($hostname);
19058: } else {
19059: $origin = lc($absolute);
19060: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19061: }
19062: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19063: my $framepolicy = $1;
19064: $framepolicy =~ s/^\s+|\s+$//g;
19065: my @policies = split(/\s+/,$framepolicy);
19066: if (@policies) {
19067: if (grep(/^\Q'none'\E$/,@policies)) {
19068: $uselink = 1;
19069: } else {
19070: $uselink = 1;
19071: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19072: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19073: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19074: undef($uselink);
19075: }
19076: if ($uselink) {
19077: if (grep(/^\Q'self'\E$/,@policies)) {
19078: if (($origin ne '') && ($remotehost eq $origin)) {
19079: undef($uselink);
19080: }
19081: }
19082: }
19083: if ($uselink) {
19084: my @possok;
19085: if ($ip ne '') {
19086: push(@possok,$ip);
19087: }
19088: my $hoststr = '';
19089: foreach my $part (reverse(split(/\./,$hostname))) {
19090: if ($hoststr eq '') {
19091: $hoststr = $part;
19092: } else {
19093: $hoststr = "$part.$hoststr";
19094: }
19095: if ($hoststr eq $hostname) {
19096: push(@possok,$hostname);
19097: } else {
19098: push(@possok,"*.$hoststr");
19099: }
19100: }
19101: if (@possok) {
19102: foreach my $poss (@possok) {
19103: last if (!$uselink);
19104: foreach my $policy (@policies) {
19105: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19106: undef($uselink);
19107: last;
19108: }
19109: }
19110: }
19111: }
19112: }
19113: }
19114: }
19115: } elsif ($xframeop ne '') {
19116: $uselink = 1;
19117: my @policies = split(/\s*,\s*/,$xframeop);
19118: if (@policies) {
19119: unless (grep(/^deny$/,@policies)) {
19120: if ($origin ne '') {
19121: if (grep(/^sameorigin$/,@policies)) {
19122: if ($remotehost eq $origin) {
19123: undef($uselink);
19124: }
19125: }
19126: if ($uselink) {
19127: foreach my $policy (@policies) {
19128: if ($policy =~ /^allow-from\s*(.+)$/) {
19129: my $allowfrom = $1;
19130: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19131: undef($uselink);
19132: last;
19133: }
19134: }
19135: }
19136: }
19137: }
19138: }
19139: }
19140: }
19141: }
19142: }
19143: if ($nocache) {
19144: if ($cached) {
19145: my $devalidate;
19146: if ($uselink && !$result) {
19147: $devalidate = 1;
19148: } elsif (!$uselink && $result) {
19149: $devalidate = 1;
19150: }
19151: if ($devalidate) {
19152: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19153: }
19154: }
19155: } else {
19156: if ($uselink) {
19157: $result = 1;
19158: } else {
19159: $result = 0;
19160: }
19161: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19162: }
19163: return $uselink;
19164: }
19165:
1.1075.2.161. .1(raebu 19166:21): sub page_menu {
19167:21): my ($menucolls,$menunum) = @_;
19168:21): my %menu;
19169:21): foreach my $item (split(/;/,$menucolls)) {
19170:21): my ($num,$value) = split(/\%/,$item);
19171:21): if ($num eq $menunum) {
19172:21): my @entries = split(/\&/,$value);
19173:21): foreach my $entry (@entries) {
19174:21): my ($name,$fields) = split(/=/,$entry);
19175:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
19176:21): $menu{$name} = $fields;
19177:21): } else {
19178:21): my @shown;
19179:21): if ($fields =~ /,/) {
19180:21): @shown = split(/,/,$fields);
19181:21): } else {
19182:21): @shown = ($fields);
19183:21): }
19184:21): if (@shown) {
19185:21): foreach my $field (@shown) {
19186:21): next if ($field eq '');
19187:21): $menu{$field} = 1;
19188:21): }
19189:21): }
19190:21): }
19191:21): }
19192:21): }
19193:21): }
19194:21): return %menu;
19195:21): }
19196:21):
1.112 bowersj2 19197: 1;
19198: __END__;
1.41 ng 19199:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>