Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.30
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. .30(raeb 4:-24): # $Id: loncommon.pm,v 1.1075.2.161.2.29 2024/09/18 14:10:21 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): }
.27(raeb 3455:-24): } elsif ($context eq 'ltitools') {
3456:-24): my %domconfig = &Apache::lonnet::get_dom('configuration',['toolsec'],$domain);
3457:-24): if (ref($domconfig{'toolsec'}) eq 'HASH') {
3458:-24): if (ref($domconfig{'toolsec'}{'rules'}) eq 'HASH') {
3459:-24): %passwdconf = %{$domconfig{'toolsec'}{'rules'}};
3460:-24): }
3461:-24): }
3462:-24): if ($id eq 'add') {
3463:-24): $alertmsg = &mt('Secret for added external tool did not satisfy requirement(s):').'\n\n';
3464:-24): } elsif ($id =~ /^\d+$/) {
3465:-24): my $pos = $id+1;
3466:-24): $alertmsg = &mt('Secret for external tool [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3467:-24): } else {
3468:-24): $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3469:-24): }
.5(raebu 3470:22): } else {
3471:22): %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3472:22): $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3473:22): }
3474:22): my ($min,$max,@chars,$numrules,$intargjs,%alert);
3475:22): $numrules = 0;
3476:22): $min = $Apache::lonnet::passwdmin;
3477:22): if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3478:22): if ($passwdconf{'min'} =~ /^\d+$/) {
3479:22): if ($passwdconf{'min'} > $min) {
3480:22): $min = $passwdconf{'min'};
3481:22): }
3482:22): }
3483:22): if ($passwdconf{'max'} =~ /^\d+$/) {
3484:22): $max = $passwdconf{'max'};
3485:22): $numrules ++;
3486:22): }
3487:22): @chars = @{$passwdconf{'chars'}};
3488:22): if (@chars) {
3489:22): $numrules ++;
3490:22): }
3491:22): }
3492:22): if ($min > 0) {
3493:22): $numrules ++;
3494:22): }
3495:22): if (($min > 0) || ($max ne '') || (@chars > 0)) {
3496:22): if ($min) {
3497:22): $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3498:22): }
3499:22): if ($max) {
3500:22): $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3501:22): }
3502:22): my (@charalerts,@charrules);
3503:22): if (@chars) {
3504:22): if (grep(/^uc$/,@chars)) {
3505:22): push(@charalerts,&mt('contain at least one upper case letter'));
3506:22): push(@charrules,'uc');
3507:22): }
3508:22): if (grep(/^lc$/,@chars)) {
3509:22): push(@charalerts,&mt('contain at least one lower case letter'));
3510:22): push(@charrules,'lc');
3511:22): }
3512:22): if (grep(/^num$/,@chars)) {
3513:22): push(@charalerts,&mt('contain at least one number'));
3514:22): push(@charrules,'num');
3515:22): }
3516:22): if (grep(/^spec$/,@chars)) {
3517:22): push(@charalerts,&mt('contain at least one non-alphanumeric'));
3518:22): push(@charrules,'spec');
3519:22): }
3520:22): }
3521:22): $intargjs = qq| var rulesmsg = '';\n|.
3522:22): qq| var currpwval = $currpasswdval;\n|;
3523:22): if ($min) {
3524:22): $intargjs .= qq|
3525:22): if (currpwval.length < $min) {
3526:22): rulesmsg += ' - $alert{min}';
3527:22): }
3528:22): |;
3529:22): }
3530:22): if ($max) {
3531:22): $intargjs .= qq|
3532:22): if (currpwval.length > $max) {
3533:22): rulesmsg += ' - $alert{max}';
3534:22): }
3535:22): |;
3536:22): }
3537:22): if (@chars > 0) {
3538:22): my $charrulestr = '"'.join('","',@charrules).'"';
3539:22): my $charalertstr = '"'.join('","',@charalerts).'"';
3540:22): $intargjs .= qq| var brokerules = new Array();\n|.
3541:22): qq| var charrules = new Array($charrulestr);\n|.
3542:22): qq| var charalerts = new Array($charalertstr);\n|;
3543:22): my %rules;
3544:22): map { $rules{$_} = 1; } @chars;
3545:22): if ($rules{'uc'}) {
3546:22): $intargjs .= qq|
3547:22): var ucRegExp = /[A-Z]/;
3548:22): if (!ucRegExp.test(currpwval)) {
3549:22): brokerules.push('uc');
3550:22): }
3551:22): |;
3552:22): }
3553:22): if ($rules{'lc'}) {
3554:22): $intargjs .= qq|
3555:22): var lcRegExp = /[a-z]/;
3556:22): if (!lcRegExp.test(currpwval)) {
3557:22): brokerules.push('lc');
3558:22): }
3559:22): |;
3560:22): }
3561:22): if ($rules{'num'}) {
3562:22): $intargjs .= qq|
3563:22): var numRegExp = /[0-9]/;
3564:22): if (!numRegExp.test(currpwval)) {
3565:22): brokerules.push('num');
3566:22): }
3567:22): |;
3568:22): }
3569:22): if ($rules{'spec'}) {
3570:22): $intargjs .= q|
3571:22): var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3572:22): if (!specRegExp.test(currpwval)) {
3573:22): brokerules.push('spec');
3574:22): }
3575:22): |;
3576:22): }
3577:22): $intargjs .= qq|
3578:22): if (brokerules.length > 0) {
3579:22): for (var i=0; i<brokerules.length; i++) {
3580:22): for (var j=0; j<charrules.length; j++) {
3581:22): if (brokerules[i] == charrules[j]) {
3582:22): rulesmsg += ' - '+charalerts[j]+'\\n';
3583:22): break;
3584:22): }
3585:22): }
3586:22): }
3587:22): }
3588:22): |;
3589:22): }
3590:22): $intargjs .= qq|
3591:22): if (rulesmsg != '') {
3592:22): rulesmsg = '$alertmsg'+rulesmsg;
3593:22): alert(rulesmsg);
3594:22): return false;
3595:22): }
3596:22): |;
3597:22): }
3598:22): return ($numrules,$intargjs);
3599:22): }
3600:22):
1.80 albertel 3601: ###############################################################
3602: ## Get Kerberos Defaults for Domain ##
3603: ###############################################################
3604: ##
3605: ## Returns default kerberos version and an associated argument
3606: ## as listed in file domain.tab. If not listed, provides
3607: ## appropriate default domain and kerberos version.
3608: ##
3609: #-------------------------------------------
3610:
3611: =pod
3612:
1.648 raeburn 3613: =item * &get_kerberos_defaults()
1.80 albertel 3614:
3615: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3616: version and domain. If not found, it defaults to version 4 and the
3617: domain of the server.
1.80 albertel 3618:
1.648 raeburn 3619: =over 4
3620:
1.80 albertel 3621: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3622:
1.648 raeburn 3623: =back
3624:
3625: =back
3626:
1.80 albertel 3627: =cut
3628:
3629: #-------------------------------------------
3630: sub get_kerberos_defaults {
3631: my $domain=shift;
1.641 raeburn 3632: my ($krbdef,$krbdefdom);
3633: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3634: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3635: $krbdef = $domdefaults{'auth_def'};
3636: $krbdefdom = $domdefaults{'auth_arg_def'};
3637: } else {
1.80 albertel 3638: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3639: my $krbdefdom=$1;
3640: $krbdefdom=~tr/a-z/A-Z/;
3641: $krbdef = "krb4";
3642: }
3643: return ($krbdef,$krbdefdom);
3644: }
1.112 bowersj2 3645:
1.32 matthew 3646:
1.46 matthew 3647: ###############################################################
3648: ## Thesaurus Functions ##
3649: ###############################################################
1.20 www 3650:
1.46 matthew 3651: =pod
1.20 www 3652:
1.112 bowersj2 3653: =head1 Thesaurus Functions
3654:
3655: =over 4
3656:
1.648 raeburn 3657: =item * &initialize_keywords()
1.46 matthew 3658:
3659: Initializes the package variable %Keywords if it is empty. Uses the
3660: package variable $thesaurus_db_file.
3661:
3662: =cut
3663:
3664: ###################################################
3665:
3666: sub initialize_keywords {
3667: return 1 if (scalar keys(%Keywords));
3668: # If we are here, %Keywords is empty, so fill it up
3669: # Make sure the file we need exists...
3670: if (! -e $thesaurus_db_file) {
3671: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3672: " failed because it does not exist");
3673: return 0;
3674: }
3675: # Set up the hash as a database
3676: my %thesaurus_db;
3677: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3678: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3679: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3680: $thesaurus_db_file);
3681: return 0;
3682: }
3683: # Get the average number of appearances of a word.
3684: my $avecount = $thesaurus_db{'average.count'};
3685: # Put keywords (those that appear > average) into %Keywords
3686: while (my ($word,$data)=each (%thesaurus_db)) {
3687: my ($count,undef) = split /:/,$data;
3688: $Keywords{$word}++ if ($count > $avecount);
3689: }
3690: untie %thesaurus_db;
3691: # Remove special values from %Keywords.
1.356 albertel 3692: foreach my $value ('total.count','average.count') {
3693: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3694: }
1.46 matthew 3695: return 1;
3696: }
3697:
3698: ###################################################
3699:
3700: =pod
3701:
1.648 raeburn 3702: =item * &keyword($word)
1.46 matthew 3703:
3704: Returns true if $word is a keyword. A keyword is a word that appears more
3705: than the average number of times in the thesaurus database. Calls
3706: &initialize_keywords
3707:
3708: =cut
3709:
3710: ###################################################
1.20 www 3711:
3712: sub keyword {
1.46 matthew 3713: return if (!&initialize_keywords());
3714: my $word=lc(shift());
3715: $word=~s/\W//g;
3716: return exists($Keywords{$word});
1.20 www 3717: }
1.46 matthew 3718:
3719: ###############################################################
3720:
3721: =pod
1.20 www 3722:
1.648 raeburn 3723: =item * &get_related_words()
1.46 matthew 3724:
1.160 matthew 3725: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3726: an array of words. If the keyword is not in the thesaurus, an empty array
3727: will be returned. The order of the words returned is determined by the
3728: database which holds them.
3729:
3730: Uses global $thesaurus_db_file.
3731:
1.1057 foxr 3732:
1.46 matthew 3733: =cut
3734:
3735: ###############################################################
3736: sub get_related_words {
3737: my $keyword = shift;
3738: my %thesaurus_db;
3739: if (! -e $thesaurus_db_file) {
3740: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3741: "failed because the file does not exist");
3742: return ();
3743: }
3744: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3745: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3746: return ();
3747: }
3748: my @Words=();
1.429 www 3749: my $count=0;
1.46 matthew 3750: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3751: # The first element is the number of times
3752: # the word appears. We do not need it now.
1.429 www 3753: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3754: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3755: my $threshold=$mostfrequentcount/10;
3756: foreach my $possibleword (@RelatedWords) {
3757: my ($word,$wordcount)=split(/\,/,$possibleword);
3758: if ($wordcount>$threshold) {
3759: push(@Words,$word);
3760: $count++;
3761: if ($count>10) { last; }
3762: }
1.20 www 3763: }
3764: }
1.46 matthew 3765: untie %thesaurus_db;
3766: return @Words;
1.14 harris41 3767: }
1.46 matthew 3768:
1.112 bowersj2 3769: =pod
3770:
3771: =back
3772:
3773: =cut
1.61 www 3774:
3775: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3776: =pod
3777:
1.112 bowersj2 3778: =head1 User Name Functions
3779:
3780: =over 4
3781:
1.648 raeburn 3782: =item * &plainname($uname,$udom,$first)
1.81 albertel 3783:
1.112 bowersj2 3784: Takes a users logon name and returns it as a string in
1.226 albertel 3785: "first middle last generation" form
3786: if $first is set to 'lastname' then it returns it as
3787: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3788:
3789: =cut
1.61 www 3790:
1.295 www 3791:
1.81 albertel 3792: ###############################################################
1.61 www 3793: sub plainname {
1.226 albertel 3794: my ($uname,$udom,$first)=@_;
1.537 albertel 3795: return if (!defined($uname) || !defined($udom));
1.295 www 3796: my %names=&getnames($uname,$udom);
1.226 albertel 3797: my $name=&Apache::lonnet::format_name($names{'firstname'},
3798: $names{'middlename'},
3799: $names{'lastname'},
3800: $names{'generation'},$first);
3801: $name=~s/^\s+//;
1.62 www 3802: $name=~s/\s+$//;
3803: $name=~s/\s+/ /g;
1.353 albertel 3804: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3805: return $name;
1.61 www 3806: }
1.66 www 3807:
3808: # -------------------------------------------------------------------- Nickname
1.81 albertel 3809: =pod
3810:
1.648 raeburn 3811: =item * &nickname($uname,$udom)
1.81 albertel 3812:
3813: Gets a users name and returns it as a string as
3814:
3815: ""nickname""
1.66 www 3816:
1.81 albertel 3817: if the user has a nickname or
3818:
3819: "first middle last generation"
3820:
3821: if the user does not
3822:
3823: =cut
1.66 www 3824:
3825: sub nickname {
3826: my ($uname,$udom)=@_;
1.537 albertel 3827: return if (!defined($uname) || !defined($udom));
1.295 www 3828: my %names=&getnames($uname,$udom);
1.68 albertel 3829: my $name=$names{'nickname'};
1.66 www 3830: if ($name) {
3831: $name='"'.$name.'"';
3832: } else {
3833: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3834: $names{'lastname'}.' '.$names{'generation'};
3835: $name=~s/\s+$//;
3836: $name=~s/\s+/ /g;
3837: }
3838: return $name;
3839: }
3840:
1.295 www 3841: sub getnames {
3842: my ($uname,$udom)=@_;
1.537 albertel 3843: return if (!defined($uname) || !defined($udom));
1.433 albertel 3844: if ($udom eq 'public' && $uname eq 'public') {
3845: return ('lastname' => &mt('Public'));
3846: }
1.295 www 3847: my $id=$uname.':'.$udom;
3848: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3849: if ($cached) {
3850: return %{$names};
3851: } else {
3852: my %loadnames=&Apache::lonnet::get('environment',
3853: ['firstname','middlename','lastname','generation','nickname'],
3854: $udom,$uname);
3855: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3856: return %loadnames;
3857: }
3858: }
1.61 www 3859:
1.542 raeburn 3860: # -------------------------------------------------------------------- getemails
1.648 raeburn 3861:
1.542 raeburn 3862: =pod
3863:
1.648 raeburn 3864: =item * &getemails($uname,$udom)
1.542 raeburn 3865:
3866: Gets a user's email information and returns it as a hash with keys:
3867: notification, critnotification, permanentemail
3868:
3869: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3870: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3871:
1.648 raeburn 3872:
1.542 raeburn 3873: =cut
3874:
1.648 raeburn 3875:
1.466 albertel 3876: sub getemails {
3877: my ($uname,$udom)=@_;
3878: if ($udom eq 'public' && $uname eq 'public') {
3879: return;
3880: }
1.467 www 3881: if (!$udom) { $udom=$env{'user.domain'}; }
3882: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3883: my $id=$uname.':'.$udom;
3884: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3885: if ($cached) {
3886: return %{$names};
3887: } else {
3888: my %loadnames=&Apache::lonnet::get('environment',
3889: ['notification','critnotification',
3890: 'permanentemail'],
3891: $udom,$uname);
3892: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3893: return %loadnames;
3894: }
3895: }
3896:
1.551 albertel 3897: sub flush_email_cache {
3898: my ($uname,$udom)=@_;
3899: if (!$udom) { $udom =$env{'user.domain'}; }
3900: if (!$uname) { $uname=$env{'user.name'}; }
3901: return if ($udom eq 'public' && $uname eq 'public');
3902: my $id=$uname.':'.$udom;
3903: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3904: }
3905:
1.728 raeburn 3906: # -------------------------------------------------------------------- getlangs
3907:
3908: =pod
3909:
3910: =item * &getlangs($uname,$udom)
3911:
3912: Gets a user's language preference and returns it as a hash with key:
3913: language.
3914:
3915: =cut
3916:
3917:
3918: sub getlangs {
3919: my ($uname,$udom) = @_;
3920: if (!$udom) { $udom =$env{'user.domain'}; }
3921: if (!$uname) { $uname=$env{'user.name'}; }
3922: my $id=$uname.':'.$udom;
3923: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3924: if ($cached) {
3925: return %{$langs};
3926: } else {
3927: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3928: $udom,$uname);
3929: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3930: return %loadlangs;
3931: }
3932: }
3933:
3934: sub flush_langs_cache {
3935: my ($uname,$udom)=@_;
3936: if (!$udom) { $udom =$env{'user.domain'}; }
3937: if (!$uname) { $uname=$env{'user.name'}; }
3938: return if ($udom eq 'public' && $uname eq 'public');
3939: my $id=$uname.':'.$udom;
3940: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3941: }
3942:
1.61 www 3943: # ------------------------------------------------------------------ Screenname
1.81 albertel 3944:
3945: =pod
3946:
1.648 raeburn 3947: =item * &screenname($uname,$udom)
1.81 albertel 3948:
3949: Gets a users screenname and returns it as a string
3950:
3951: =cut
1.61 www 3952:
3953: sub screenname {
3954: my ($uname,$udom)=@_;
1.258 albertel 3955: if ($uname eq $env{'user.name'} &&
3956: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3957: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3958: return $names{'screenname'};
1.62 www 3959: }
3960:
1.212 albertel 3961:
1.802 bisitz 3962: # ------------------------------------------------------------- Confirm Wrapper
3963: =pod
3964:
1.1075.2.42 raeburn 3965: =item * &confirmwrapper($message)
1.802 bisitz 3966:
3967: Wrap messages about completion of operation in box
3968:
3969: =cut
3970:
3971: sub confirmwrapper {
3972: my ($message)=@_;
3973: if ($message) {
3974: return "\n".'<div class="LC_confirm_box">'."\n"
3975: .$message."\n"
3976: .'</div>'."\n";
3977: } else {
3978: return $message;
3979: }
3980: }
3981:
1.62 www 3982: # ------------------------------------------------------------- Message Wrapper
3983:
3984: sub messagewrapper {
1.369 www 3985: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3986: return
1.441 albertel 3987: '<a href="/adm/email?compose=individual&'.
3988: 'recname='.$username.'&recdom='.$domain.
3989: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3990: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3991: }
1.802 bisitz 3992:
1.74 www 3993: # --------------------------------------------------------------- Notes Wrapper
3994:
3995: sub noteswrapper {
3996: my ($link,$un,$do)=@_;
3997: return
1.896 amueller 3998: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3999: }
1.802 bisitz 4000:
1.62 www 4001: # ------------------------------------------------------------- Aboutme Wrapper
4002:
4003: sub aboutmewrapper {
1.1070 raeburn 4004: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4005: if (!defined($username) && !defined($domain)) {
4006: return;
4007: }
1.1075.2.15 raeburn 4008: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4009: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4010: }
4011:
4012: # ------------------------------------------------------------ Syllabus Wrapper
4013:
4014: sub syllabuswrapper {
1.707 bisitz 4015: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4016: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4017: }
1.14 harris41 4018:
1.1075.2.161. .11(raeb 4019:-22): sub aboutme_on {
4020:-22): my ($uname,$udom)=@_;
4021:-22): unless ($uname) { $uname=$env{'user.name'}; }
4022:-22): unless ($udom) { $udom=$env{'user.domain'}; }
4023:-22): return if ($udom eq 'public' && $uname eq 'public');
4024:-22): my $hashkey=$uname.':'.$udom;
4025:-22): my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4026:-22): if ($cached) {
4027:-22): return $aboutme;
4028:-22): }
4029:-22): $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4030:-22): &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4031:-22): return $aboutme;
4032:-22): }
4033:-22):
4034:-22): sub devalidate_aboutme_cache {
4035:-22): my ($uname,$udom)=@_;
4036:-22): if (!$udom) { $udom =$env{'user.domain'}; }
4037:-22): if (!$uname) { $uname=$env{'user.name'}; }
4038:-22): return if ($udom eq 'public' && $uname eq 'public');
4039:-22): my $id=$uname.':'.$udom;
4040:-22): &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4041:-22): }
4042:-22):
1.802 bisitz 4043: # -----------------------------------------------------------------------------
4044:
1.208 matthew 4045: sub track_student_link {
1.887 raeburn 4046: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4047: my $link ="/adm/trackstudent?";
1.208 matthew 4048: my $title = 'View recent activity';
4049: if (defined($sname) && $sname !~ /^\s*$/ &&
4050: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4051: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4052: $title .= ' of this student';
1.268 albertel 4053: }
1.208 matthew 4054: if (defined($target) && $target !~ /^\s*$/) {
4055: $target = qq{target="$target"};
4056: } else {
4057: $target = '';
4058: }
1.268 albertel 4059: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4060: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4061: $title = &mt($title);
4062: $linktext = &mt($linktext);
1.448 albertel 4063: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4064: &help_open_topic('View_recent_activity');
1.208 matthew 4065: }
4066:
1.781 raeburn 4067: sub slot_reservations_link {
4068: my ($linktext,$sname,$sdom,$target) = @_;
4069: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4070: my $title = 'View slot reservation history';
4071: if (defined($sname) && $sname !~ /^\s*$/ &&
4072: defined($sdom) && $sdom !~ /^\s*$/) {
4073: $link .= "&uname=$sname&udom=$sdom";
4074: $title .= ' of this student';
4075: }
4076: if (defined($target) && $target !~ /^\s*$/) {
4077: $target = qq{target="$target"};
4078: } else {
4079: $target = '';
4080: }
4081: $title = &mt($title);
4082: $linktext = &mt($linktext);
4083: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4084: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4085:
4086: }
4087:
1.508 www 4088: # ===================================================== Display a student photo
4089:
4090:
1.509 albertel 4091: sub student_image_tag {
1.508 www 4092: my ($domain,$user)=@_;
4093: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4094: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4095: return '<img src="'.$imgsrc.'" align="right" />';
4096: } else {
4097: return '';
4098: }
4099: }
4100:
1.112 bowersj2 4101: =pod
4102:
4103: =back
4104:
4105: =head1 Access .tab File Data
4106:
4107: =over 4
4108:
1.648 raeburn 4109: =item * &languageids()
1.112 bowersj2 4110:
4111: returns list of all language ids
4112:
4113: =cut
4114:
1.14 harris41 4115: sub languageids {
1.16 harris41 4116: return sort(keys(%language));
1.14 harris41 4117: }
4118:
1.112 bowersj2 4119: =pod
4120:
1.648 raeburn 4121: =item * &languagedescription()
1.112 bowersj2 4122:
4123: returns description of a specified language id
4124:
4125: =cut
4126:
1.14 harris41 4127: sub languagedescription {
1.125 www 4128: my $code=shift;
4129: return ($supported_language{$code}?'* ':'').
4130: $language{$code}.
1.126 www 4131: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4132: }
4133:
1.1048 foxr 4134: =pod
4135:
4136: =item * &plainlanguagedescription
4137:
4138: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4139: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4140:
4141: =cut
4142:
1.145 www 4143: sub plainlanguagedescription {
4144: my $code=shift;
4145: return $language{$code};
4146: }
4147:
1.1048 foxr 4148: =pod
4149:
4150: =item * &supportedlanguagecode
4151:
4152: Returns the supported language code (e.g. sptutf maps to pt) given a language
4153: code.
4154:
4155: =cut
4156:
1.145 www 4157: sub supportedlanguagecode {
4158: my $code=shift;
4159: return $supported_language{$code};
1.97 www 4160: }
4161:
1.112 bowersj2 4162: =pod
4163:
1.1048 foxr 4164: =item * &latexlanguage()
4165:
4166: Given a language key code returns the correspondnig language to use
4167: to select the correct hyphenation on LaTeX printouts. This is undef if there
4168: is no supported hyphenation for the language code.
4169:
4170: =cut
4171:
4172: sub latexlanguage {
4173: my $code = shift;
4174: return $latex_language{$code};
4175: }
4176:
4177: =pod
4178:
4179: =item * &latexhyphenation()
4180:
4181: Same as above but what's supplied is the language as it might be stored
4182: in the metadata.
4183:
4184: =cut
4185:
4186: sub latexhyphenation {
4187: my $key = shift;
4188: return $latex_language_bykey{$key};
4189: }
4190:
4191: =pod
4192:
1.648 raeburn 4193: =item * ©rightids()
1.112 bowersj2 4194:
4195: returns list of all copyrights
4196:
4197: =cut
4198:
4199: sub copyrightids {
4200: return sort(keys(%cprtag));
4201: }
4202:
4203: =pod
4204:
1.648 raeburn 4205: =item * ©rightdescription()
1.112 bowersj2 4206:
4207: returns description of a specified copyright id
4208:
4209: =cut
4210:
4211: sub copyrightdescription {
1.166 www 4212: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4213: }
1.197 matthew 4214:
4215: =pod
4216:
1.648 raeburn 4217: =item * &source_copyrightids()
1.192 taceyjo1 4218:
4219: returns list of all source copyrights
4220:
4221: =cut
4222:
4223: sub source_copyrightids {
4224: return sort(keys(%scprtag));
4225: }
4226:
4227: =pod
4228:
1.648 raeburn 4229: =item * &source_copyrightdescription()
1.192 taceyjo1 4230:
4231: returns description of a specified source copyright id
4232:
4233: =cut
4234:
4235: sub source_copyrightdescription {
4236: return &mt($scprtag{shift(@_)});
4237: }
1.112 bowersj2 4238:
4239: =pod
4240:
1.648 raeburn 4241: =item * &filecategories()
1.112 bowersj2 4242:
4243: returns list of all file categories
4244:
4245: =cut
4246:
4247: sub filecategories {
4248: return sort(keys(%category_extensions));
4249: }
4250:
4251: =pod
4252:
1.648 raeburn 4253: =item * &filecategorytypes()
1.112 bowersj2 4254:
4255: returns list of file types belonging to a given file
4256: category
4257:
4258: =cut
4259:
4260: sub filecategorytypes {
1.356 albertel 4261: my ($cat) = @_;
4262: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 4263: }
4264:
4265: =pod
4266:
1.648 raeburn 4267: =item * &fileembstyle()
1.112 bowersj2 4268:
4269: returns embedding style for a specified file type
4270:
4271: =cut
4272:
4273: sub fileembstyle {
4274: return $fe{lc(shift(@_))};
1.169 www 4275: }
4276:
1.351 www 4277: sub filemimetype {
4278: return $fm{lc(shift(@_))};
4279: }
4280:
1.169 www 4281:
4282: sub filecategoryselect {
4283: my ($name,$value)=@_;
1.189 matthew 4284: return &select_form($value,$name,
1.970 raeburn 4285: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4286: }
4287:
4288: =pod
4289:
1.648 raeburn 4290: =item * &filedescription()
1.112 bowersj2 4291:
4292: returns description for a specified file type
4293:
4294: =cut
4295:
4296: sub filedescription {
1.188 matthew 4297: my $file_description = $fd{lc(shift())};
4298: $file_description =~ s:([\[\]]):~$1:g;
4299: return &mt($file_description);
1.112 bowersj2 4300: }
4301:
4302: =pod
4303:
1.648 raeburn 4304: =item * &filedescriptionex()
1.112 bowersj2 4305:
4306: returns description for a specified file type with
4307: extra formatting
4308:
4309: =cut
4310:
4311: sub filedescriptionex {
4312: my $ex=shift;
1.188 matthew 4313: my $file_description = $fd{lc($ex)};
4314: $file_description =~ s:([\[\]]):~$1:g;
4315: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4316: }
4317:
4318: # End of .tab access
4319: =pod
4320:
4321: =back
4322:
4323: =cut
4324:
4325: # ------------------------------------------------------------------ File Types
4326: sub fileextensions {
4327: return sort(keys(%fe));
4328: }
4329:
1.97 www 4330: # ----------------------------------------------------------- Display Languages
4331: # returns a hash with all desired display languages
4332: #
4333:
4334: sub display_languages {
4335: my %languages=();
1.695 raeburn 4336: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4337: $languages{$lang}=1;
1.97 www 4338: }
4339: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4340: if ($env{'form.displaylanguage'}) {
1.356 albertel 4341: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4342: $languages{$lang}=1;
1.97 www 4343: }
4344: }
4345: return %languages;
1.14 harris41 4346: }
4347:
1.582 albertel 4348: sub languages {
4349: my ($possible_langs) = @_;
1.695 raeburn 4350: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4351: if (!ref($possible_langs)) {
4352: if( wantarray ) {
4353: return @preferred_langs;
4354: } else {
4355: return $preferred_langs[0];
4356: }
4357: }
4358: my %possibilities = map { $_ => 1 } (@$possible_langs);
4359: my @preferred_possibilities;
4360: foreach my $preferred_lang (@preferred_langs) {
4361: if (exists($possibilities{$preferred_lang})) {
4362: push(@preferred_possibilities, $preferred_lang);
4363: }
4364: }
4365: if( wantarray ) {
4366: return @preferred_possibilities;
4367: }
4368: return $preferred_possibilities[0];
4369: }
4370:
1.742 raeburn 4371: sub user_lang {
4372: my ($touname,$toudom,$fromcid) = @_;
4373: my @userlangs;
4374: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4375: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4376: $env{'course.'.$fromcid.'.languages'}));
4377: } else {
4378: my %langhash = &getlangs($touname,$toudom);
4379: if ($langhash{'languages'} ne '') {
4380: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4381: } else {
4382: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4383: if ($domdefs{'lang_def'} ne '') {
4384: @userlangs = ($domdefs{'lang_def'});
4385: }
4386: }
4387: }
4388: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4389: my $user_lh = Apache::localize->get_handle(@languages);
4390: return $user_lh;
4391: }
4392:
4393:
1.112 bowersj2 4394: ###############################################################
4395: ## Student Answer Attempts ##
4396: ###############################################################
4397:
4398: =pod
4399:
4400: =head1 Alternate Problem Views
4401:
4402: =over 4
4403:
1.648 raeburn 4404: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4405: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4406:
4407: Return string with previous attempt on problem. Arguments:
4408:
4409: =over 4
4410:
4411: =item * $symb: Problem, including path
4412:
4413: =item * $username: username of the desired student
4414:
4415: =item * $domain: domain of the desired student
1.14 harris41 4416:
1.112 bowersj2 4417: =item * $course: Course ID
1.14 harris41 4418:
1.112 bowersj2 4419: =item * $getattempt: Leave blank for all attempts, otherwise put
4420: something
1.14 harris41 4421:
1.112 bowersj2 4422: =item * $regexp: if string matches this regexp, the string will be
4423: sent to $gradesub
1.14 harris41 4424:
1.112 bowersj2 4425: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4426:
1.1075.2.86 raeburn 4427: =item * $usec: section of the desired student
4428:
4429: =item * $identifier: counter for student (multiple students one problem) or
4430: problem (one student; whole sequence).
4431:
1.112 bowersj2 4432: =back
1.14 harris41 4433:
1.112 bowersj2 4434: The output string is a table containing all desired attempts, if any.
1.16 harris41 4435:
1.112 bowersj2 4436: =cut
1.1 albertel 4437:
4438: sub get_previous_attempt {
1.1075.2.86 raeburn 4439: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4440: my $prevattempts='';
1.43 ng 4441: no strict 'refs';
1.1 albertel 4442: if ($symb) {
1.3 albertel 4443: my (%returnhash)=
4444: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4445: if ($returnhash{'version'}) {
4446: my %lasthash=();
4447: my $version;
4448: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4449: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4450: if ($key =~ /\.rawrndseed$/) {
4451: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4452: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4453: } else {
4454: $lasthash{$key}=$returnhash{$version.':'.$key};
4455: }
1.19 harris41 4456: }
1.1 albertel 4457: }
1.596 albertel 4458: $prevattempts=&start_data_table().&start_data_table_header_row();
4459: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4460: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4461: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4462: foreach my $key (sort(keys(%lasthash))) {
4463: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4464: if ($#parts > 0) {
1.31 albertel 4465: my $data=$parts[-1];
1.989 raeburn 4466: next if ($data eq 'foilorder');
1.31 albertel 4467: pop(@parts);
1.1010 www 4468: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4469: if ($data eq 'type') {
4470: unless ($showsurv) {
4471: my $id = join(',',@parts);
4472: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4473: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4474: $lasthidden{$ign.'.'.$id} = 1;
4475: }
1.945 raeburn 4476: }
1.1075.2.86 raeburn 4477: if ($identifier ne '') {
4478: my $id = join(',',@parts);
4479: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4480: $domain,$username,$usec,undef,$course) =~ /^no/) {
4481: $hidestatus{$ign.'.'.$id} = 1;
4482: }
4483: }
4484: } elsif ($data eq 'regrader') {
4485: if (($identifier ne '') && (@parts)) {
4486: my $id = join(',',@parts);
4487: $regraded{$ign.'.'.$id} = 1;
4488: }
1.1010 www 4489: }
1.31 albertel 4490: } else {
1.41 ng 4491: if ($#parts == 0) {
4492: $prevattempts.='<th>'.$parts[0].'</th>';
4493: } else {
4494: $prevattempts.='<th>'.$ign.'</th>';
4495: }
1.31 albertel 4496: }
1.16 harris41 4497: }
1.596 albertel 4498: $prevattempts.=&end_data_table_header_row();
1.40 ng 4499: if ($getattempt eq '') {
1.1075.2.86 raeburn 4500: my (%solved,%resets,%probstatus);
4501: if (($identifier ne '') && (keys(%regraded) > 0)) {
4502: for ($version=1;$version<=$returnhash{'version'};$version++) {
4503: foreach my $id (keys(%regraded)) {
4504: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4505: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4506: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4507: push(@{$resets{$id}},$version);
4508: }
4509: }
4510: }
4511: }
1.40 ng 4512: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4513: my (@hidden,@unsolved);
1.945 raeburn 4514: if (%typeparts) {
4515: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4516: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4517: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4518: push(@hidden,$id);
1.1075.2.86 raeburn 4519: } elsif ($identifier ne '') {
4520: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4521: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4522: ($hidestatus{$id})) {
4523: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4524: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4525: push(@{$solved{$id}},$version);
4526: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4527: (ref($solved{$id}) eq 'ARRAY')) {
4528: my $skip;
4529: if (ref($resets{$id}) eq 'ARRAY') {
4530: foreach my $reset (@{$resets{$id}}) {
4531: if ($reset > $solved{$id}[-1]) {
4532: $skip=1;
4533: last;
4534: }
4535: }
4536: }
4537: unless ($skip) {
4538: my ($ign,$partslist) = split(/\./,$id,2);
4539: push(@unsolved,$partslist);
4540: }
4541: }
4542: }
1.945 raeburn 4543: }
4544: }
4545: }
4546: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4547: '<td>'.&mt('Transaction [_1]',$version);
4548: if (@unsolved) {
4549: $prevattempts .= '<span class="LC_nobreak"><label>'.
4550: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4551: &mt('Hide').'</label></span>';
4552: }
4553: $prevattempts .= '</td>';
1.945 raeburn 4554: if (@hidden) {
4555: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4556: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4557: my $hide;
4558: foreach my $id (@hidden) {
4559: if ($key =~ /^\Q$id\E/) {
4560: $hide = 1;
4561: last;
4562: }
4563: }
4564: if ($hide) {
4565: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4566: if (($data eq 'award') || ($data eq 'awarddetail')) {
4567: my $value = &format_previous_attempt_value($key,
4568: $returnhash{$version.':'.$key});
4569: $prevattempts.='<td>'.$value.' </td>';
4570: } else {
4571: $prevattempts.='<td> </td>';
4572: }
4573: } else {
4574: if ($key =~ /\./) {
1.1075.2.91 raeburn 4575: my $value = $returnhash{$version.':'.$key};
4576: if ($key =~ /\.rndseed$/) {
4577: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4578: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4579: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4580: }
4581: }
4582: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4583: ' </td>';
1.945 raeburn 4584: } else {
4585: $prevattempts.='<td> </td>';
4586: }
4587: }
4588: }
4589: } else {
4590: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4591: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4592: my $value = $returnhash{$version.':'.$key};
4593: if ($key =~ /\.rndseed$/) {
4594: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4595: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4596: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4597: }
4598: }
4599: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4600: ' </td>';
1.945 raeburn 4601: }
4602: }
4603: $prevattempts.=&end_data_table_row();
1.40 ng 4604: }
1.1 albertel 4605: }
1.945 raeburn 4606: my @currhidden = keys(%lasthidden);
1.596 albertel 4607: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4608: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4609: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4610: if (%typeparts) {
4611: my $hidden;
4612: foreach my $id (@currhidden) {
4613: if ($key =~ /^\Q$id\E/) {
4614: $hidden = 1;
4615: last;
4616: }
4617: }
4618: if ($hidden) {
4619: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4620: if (($data eq 'award') || ($data eq 'awarddetail')) {
4621: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4622: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4623: $value = &$gradesub($value);
4624: }
4625: $prevattempts.='<td>'.$value.' </td>';
4626: } else {
4627: $prevattempts.='<td> </td>';
4628: }
4629: } else {
4630: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4631: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4632: $value = &$gradesub($value);
4633: }
4634: $prevattempts.='<td>'.$value.' </td>';
4635: }
4636: } else {
4637: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4638: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4639: $value = &$gradesub($value);
4640: }
4641: $prevattempts.='<td>'.$value.' </td>';
4642: }
1.16 harris41 4643: }
1.596 albertel 4644: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4645: } else {
1.1075.2.161. .17(raeb 4646:-23): my $msg;
4647:-23): if ($symb =~ /ext\.tool$/) {
4648:-23): $msg = &mt('No grade passed back.');
4649:-23): } else {
4650:-23): $msg = &mt('Nothing submitted - no attempts.');
4651:-23): }
1.596 albertel 4652: $prevattempts=
4653: &start_data_table().&start_data_table_row().
1.1075.2.161. .17(raeb 4654:-23): '<td>'.$msg.'</td>'.
1.596 albertel 4655: &end_data_table_row().&end_data_table();
1.1 albertel 4656: }
4657: } else {
1.596 albertel 4658: $prevattempts=
4659: &start_data_table().&start_data_table_row().
4660: '<td>'.&mt('No data.').'</td>'.
4661: &end_data_table_row().&end_data_table();
1.1 albertel 4662: }
1.10 albertel 4663: }
4664:
1.581 albertel 4665: sub format_previous_attempt_value {
4666: my ($key,$value) = @_;
1.1011 www 4667: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4668: $value = &Apache::lonlocal::locallocaltime($value);
4669: } elsif (ref($value) eq 'ARRAY') {
4670: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4671: } elsif ($key =~ /answerstring$/) {
4672: my %answers = &Apache::lonnet::str2hash($value);
4673: my @anskeys = sort(keys(%answers));
4674: if (@anskeys == 1) {
4675: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4676: if ($answer =~ m{\0}) {
4677: $answer =~ s{\0}{,}g;
1.988 raeburn 4678: }
4679: my $tag_internal_answer_name = 'INTERNAL';
4680: if ($anskeys[0] eq $tag_internal_answer_name) {
4681: $value = $answer;
4682: } else {
4683: $value = $anskeys[0].'='.$answer;
4684: }
4685: } else {
4686: foreach my $ans (@anskeys) {
4687: my $answer = $answers{$ans};
1.1001 raeburn 4688: if ($answer =~ m{\0}) {
4689: $answer =~ s{\0}{,}g;
1.988 raeburn 4690: }
4691: $value .= $ans.'='.$answer.'<br />';;
4692: }
4693: }
1.581 albertel 4694: } else {
4695: $value = &unescape($value);
4696: }
4697: return $value;
4698: }
4699:
4700:
1.107 albertel 4701: sub relative_to_absolute {
4702: my ($url,$output)=@_;
4703: my $parser=HTML::TokeParser->new(\$output);
4704: my $token;
4705: my $thisdir=$url;
4706: my @rlinks=();
4707: while ($token=$parser->get_token) {
4708: if ($token->[0] eq 'S') {
4709: if ($token->[1] eq 'a') {
4710: if ($token->[2]->{'href'}) {
4711: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4712: }
4713: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4714: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4715: } elsif ($token->[1] eq 'base') {
4716: $thisdir=$token->[2]->{'href'};
4717: }
4718: }
4719: }
4720: $thisdir=~s-/[^/]*$--;
1.356 albertel 4721: foreach my $link (@rlinks) {
1.726 raeburn 4722: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4723: ($link=~/^\//) ||
4724: ($link=~/^javascript:/i) ||
4725: ($link=~/^mailto:/i) ||
4726: ($link=~/^\#/)) {
4727: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4728: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4729: }
4730: }
4731: # -------------------------------------------------- Deal with Applet codebases
4732: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4733: return $output;
4734: }
4735:
1.112 bowersj2 4736: =pod
4737:
1.648 raeburn 4738: =item * &get_student_view()
1.112 bowersj2 4739:
4740: show a snapshot of what student was looking at
4741:
4742: =cut
4743:
1.10 albertel 4744: sub get_student_view {
1.186 albertel 4745: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4746: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4747: my (%form);
1.10 albertel 4748: my @elements=('symb','courseid','domain','username');
4749: foreach my $element (@elements) {
1.186 albertel 4750: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4751: }
1.186 albertel 4752: if (defined($moreenv)) {
4753: %form=(%form,%{$moreenv});
4754: }
1.236 albertel 4755: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4756: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4757: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4758: $userview=~s/\<body[^\>]*\>//gi;
4759: $userview=~s/\<\/body\>//gi;
4760: $userview=~s/\<html\>//gi;
4761: $userview=~s/\<\/html\>//gi;
4762: $userview=~s/\<head\>//gi;
4763: $userview=~s/\<\/head\>//gi;
4764: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4765: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4766: if (wantarray) {
4767: return ($userview,$response);
4768: } else {
4769: return $userview;
4770: }
4771: }
4772:
4773: sub get_student_view_with_retries {
4774: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4775:
4776: my $ok = 0; # True if we got a good response.
4777: my $content;
4778: my $response;
4779:
4780: # Try to get the student_view done. within the retries count:
4781:
4782: do {
4783: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4784: $ok = $response->is_success;
4785: if (!$ok) {
4786: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4787: }
4788: $retries--;
4789: } while (!$ok && ($retries > 0));
4790:
4791: if (!$ok) {
4792: $content = ''; # On error return an empty content.
4793: }
1.651 www 4794: if (wantarray) {
4795: return ($content, $response);
4796: } else {
4797: return $content;
4798: }
1.11 albertel 4799: }
4800:
1.1075.2.149 raeburn 4801: sub css_links {
4802: my ($currsymb,$level) = @_;
4803: my ($links,@symbs,%cssrefs,%httpref);
4804: if ($level eq 'map') {
4805: my $navmap = Apache::lonnavmaps::navmap->new();
4806: if (ref($navmap)) {
4807: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4808: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4809: foreach my $res (@resources) {
4810: if (ref($res) && $res->symb()) {
4811: push(@symbs,$res->symb());
4812: }
4813: }
4814: }
4815: } else {
4816: @symbs = ($currsymb);
4817: }
4818: foreach my $symb (@symbs) {
4819: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4820: if ($css_href =~ /\S/) {
4821: unless ($css_href =~ m{https?://}) {
4822: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4823: my $proburl = &Apache::lonnet::clutter($url);
4824: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4825: unless ($css_href =~ m{^/}) {
4826: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4827: }
4828: if ($css_href =~ m{^/(res|uploaded)/}) {
4829: unless (($httpref{'httpref.'.$css_href}) ||
4830: (&Apache::lonnet::is_on_map($css_href))) {
4831: my $thisurl = $proburl;
4832: if ($env{'httpref.'.$proburl}) {
4833: $thisurl = $env{'httpref.'.$proburl};
4834: }
4835: $httpref{'httpref.'.$css_href} = $thisurl;
4836: }
4837: }
4838: }
4839: $cssrefs{$css_href} = 1;
4840: }
4841: }
4842: if (keys(%httpref)) {
4843: &Apache::lonnet::appenv(\%httpref);
4844: }
4845: if (keys(%cssrefs)) {
4846: foreach my $css_href (keys(%cssrefs)) {
4847: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4848: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4849: }
4850: }
4851: return $links;
4852: }
4853:
1.112 bowersj2 4854: =pod
4855:
1.648 raeburn 4856: =item * &get_student_answers()
1.112 bowersj2 4857:
4858: show a snapshot of how student was answering problem
4859:
4860: =cut
4861:
1.11 albertel 4862: sub get_student_answers {
1.100 sakharuk 4863: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4864: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4865: my (%moreenv);
1.11 albertel 4866: my @elements=('symb','courseid','domain','username');
4867: foreach my $element (@elements) {
1.186 albertel 4868: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4869: }
1.186 albertel 4870: $moreenv{'grade_target'}='answer';
4871: %moreenv=(%form,%moreenv);
1.497 raeburn 4872: $feedurl = &Apache::lonnet::clutter($feedurl);
4873: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4874: return $userview;
1.1 albertel 4875: }
1.116 albertel 4876:
4877: =pod
4878:
4879: =item * &submlink()
4880:
1.242 albertel 4881: Inputs: $text $uname $udom $symb $target
1.116 albertel 4882:
4883: Returns: A link to grades.pm such as to see the SUBM view of a student
4884:
4885: =cut
4886:
4887: ###############################################
4888: sub submlink {
1.242 albertel 4889: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4890: if (!($uname && $udom)) {
4891: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4892: &Apache::lonnet::whichuser($symb);
1.116 albertel 4893: if (!$symb) { $symb=$cursymb; }
4894: }
1.254 matthew 4895: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4896: $symb=&escape($symb);
1.960 bisitz 4897: if ($target) { $target=" target=\"$target\""; }
4898: return
4899: '<a href="/adm/grades?command=submission'.
4900: '&symb='.$symb.
4901: '&student='.$uname.
4902: '&userdom='.$udom.'"'.
4903: $target.'>'.$text.'</a>';
1.242 albertel 4904: }
4905: ##############################################
4906:
4907: =pod
4908:
4909: =item * &pgrdlink()
4910:
4911: Inputs: $text $uname $udom $symb $target
4912:
4913: Returns: A link to grades.pm such as to see the PGRD view of a student
4914:
4915: =cut
4916:
4917: ###############################################
4918: sub pgrdlink {
4919: my $link=&submlink(@_);
4920: $link=~s/(&command=submission)/$1&showgrading=yes/;
4921: return $link;
4922: }
4923: ##############################################
4924:
4925: =pod
4926:
4927: =item * &pprmlink()
4928:
4929: Inputs: $text $uname $udom $symb $target
4930:
4931: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4932: student and a specific resource
1.242 albertel 4933:
4934: =cut
4935:
4936: ###############################################
4937: sub pprmlink {
4938: my ($text,$uname,$udom,$symb,$target)=@_;
4939: if (!($uname && $udom)) {
4940: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4941: &Apache::lonnet::whichuser($symb);
1.242 albertel 4942: if (!$symb) { $symb=$cursymb; }
4943: }
1.254 matthew 4944: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4945: $symb=&escape($symb);
1.242 albertel 4946: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4947: return '<a href="/adm/parmset?command=set&'.
4948: 'symb='.$symb.'&uname='.$uname.
4949: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4950: }
4951: ##############################################
1.37 matthew 4952:
1.112 bowersj2 4953: =pod
4954:
4955: =back
4956:
4957: =cut
4958:
1.37 matthew 4959: ###############################################
1.51 www 4960:
4961:
4962: sub timehash {
1.687 raeburn 4963: my ($thistime) = @_;
4964: my $timezone = &Apache::lonlocal::gettimezone();
4965: my $dt = DateTime->from_epoch(epoch => $thistime)
4966: ->set_time_zone($timezone);
4967: my $wday = $dt->day_of_week();
4968: if ($wday == 7) { $wday = 0; }
4969: return ( 'second' => $dt->second(),
4970: 'minute' => $dt->minute(),
4971: 'hour' => $dt->hour(),
4972: 'day' => $dt->day_of_month(),
4973: 'month' => $dt->month(),
4974: 'year' => $dt->year(),
4975: 'weekday' => $wday,
4976: 'dayyear' => $dt->day_of_year(),
4977: 'dlsav' => $dt->is_dst() );
1.51 www 4978: }
4979:
1.370 www 4980: sub utc_string {
4981: my ($date)=@_;
1.371 www 4982: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4983: }
4984:
1.51 www 4985: sub maketime {
4986: my %th=@_;
1.687 raeburn 4987: my ($epoch_time,$timezone,$dt);
4988: $timezone = &Apache::lonlocal::gettimezone();
4989: eval {
4990: $dt = DateTime->new( year => $th{'year'},
4991: month => $th{'month'},
4992: day => $th{'day'},
4993: hour => $th{'hour'},
4994: minute => $th{'minute'},
4995: second => $th{'second'},
4996: time_zone => $timezone,
4997: );
4998: };
4999: if (!$@) {
5000: $epoch_time = $dt->epoch;
5001: if ($epoch_time) {
5002: return $epoch_time;
5003: }
5004: }
1.51 www 5005: return POSIX::mktime(
5006: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5007: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5008: }
5009:
5010: #########################################
1.51 www 5011:
5012: sub findallcourses {
1.482 raeburn 5013: my ($roles,$uname,$udom) = @_;
1.355 albertel 5014: my %roles;
5015: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5016: my %courses;
1.51 www 5017: my $now=time;
1.482 raeburn 5018: if (!defined($uname)) {
5019: $uname = $env{'user.name'};
5020: }
5021: if (!defined($udom)) {
5022: $udom = $env{'user.domain'};
5023: }
5024: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5025: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5026: if (!%roles) {
5027: %roles = (
5028: cc => 1,
1.907 raeburn 5029: co => 1,
1.482 raeburn 5030: in => 1,
5031: ep => 1,
5032: ta => 1,
5033: cr => 1,
5034: st => 1,
5035: );
5036: }
5037: foreach my $entry (keys(%roleshash)) {
5038: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5039: if ($trole =~ /^cr/) {
5040: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5041: } else {
5042: next if (!exists($roles{$trole}));
5043: }
5044: if ($tend) {
5045: next if ($tend < $now);
5046: }
5047: if ($tstart) {
5048: next if ($tstart > $now);
5049: }
1.1058 raeburn 5050: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5051: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5052: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5053: if ($secpart eq '') {
5054: ($cnum,$role) = split(/_/,$cnumpart);
5055: $sec = 'none';
1.1058 raeburn 5056: $value .= $cnum.'/';
1.482 raeburn 5057: } else {
5058: $cnum = $cnumpart;
5059: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5060: $value .= $cnum.'/'.$sec;
5061: }
5062: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5063: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5064: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5065: }
5066: } else {
5067: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5068: }
1.482 raeburn 5069: }
5070: } else {
5071: foreach my $key (keys(%env)) {
1.483 albertel 5072: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5073: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5074: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5075: next if ($role eq 'ca' || $role eq 'aa');
5076: next if (%roles && !exists($roles{$role}));
5077: my ($starttime,$endtime)=split(/\./,$env{$key});
5078: my $active=1;
5079: if ($starttime) {
5080: if ($now<$starttime) { $active=0; }
5081: }
5082: if ($endtime) {
5083: if ($now>$endtime) { $active=0; }
5084: }
5085: if ($active) {
1.1058 raeburn 5086: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5087: if ($sec eq '') {
5088: $sec = 'none';
1.1058 raeburn 5089: } else {
5090: $value .= $sec;
5091: }
5092: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5093: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5094: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5095: }
5096: } else {
5097: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5098: }
1.474 raeburn 5099: }
5100: }
1.51 www 5101: }
5102: }
1.474 raeburn 5103: return %courses;
1.51 www 5104: }
1.37 matthew 5105:
1.54 www 5106: ###############################################
1.474 raeburn 5107:
5108: sub blockcheck {
1.1075.2.158 raeburn 5109: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 5110:
1.1075.2.161. .4(raebu 5111:22): unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
1.1075.2.158 raeburn 5112: my ($has_evb,$check_ipaccess);
5113: my $dom = $env{'user.domain'};
5114: if ($env{'request.course.id'}) {
5115: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5116: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5117: my $checkrole = "cm./$cdom/$cnum";
5118: my $sec = $env{'request.course.sec'};
5119: if ($sec ne '') {
5120: $checkrole .= "/$sec";
5121: }
5122: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5123: ($env{'request.role'} !~ /^st/)) {
5124: $has_evb = 1;
5125: }
5126: unless ($has_evb) {
5127: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5128: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5129: if ($udom eq $cdom) {
5130: $check_ipaccess = 1;
5131: }
5132: }
5133: }
1.1075.2.161. .3(raebu 5134:22): } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5135:22): ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5136:22): my $checkrole;
5137:22): if ($env{'request.role.domain'} eq '') {
5138:22): $checkrole = "cm./$env{'user.domain'}/";
5139:22): } else {
5140:22): $checkrole = "cm./$env{'request.role.domain'}/";
5141:22): }
5142:22): if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5143:22): $has_evb = 1;
5144:22): }
1.1075.2.158 raeburn 5145: }
5146: unless ($has_evb || $check_ipaccess) {
5147: my @machinedoms = &Apache::lonnet::current_machine_domains();
5148: if (($dom eq 'public') && ($activity eq 'port')) {
5149: $dom = $udom;
5150: }
5151: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5152: $check_ipaccess = 1;
5153: } else {
5154: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5155: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5156: my $prim = &Apache::lonnet::domain($dom,'primary');
5157: my $intdom = &Apache::lonnet::internet_dom($prim);
5158: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5159: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5160: $check_ipaccess = 1;
5161: }
5162: }
5163: }
5164: }
5165: if ($check_ipaccess) {
5166: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5167: unless (defined($cached)) {
5168: my %domconfig =
5169: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5170: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5171: }
5172: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5173: foreach my $id (keys(%{$ipaccessref})) {
5174: if (ref($ipaccessref->{$id}) eq 'HASH') {
5175: my $range = $ipaccessref->{$id}->{'ip'};
5176: if ($range) {
5177: if (&Apache::lonnet::ip_match($clientip,$range)) {
5178: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5179: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5180: return ('','','',$id,$dom);
5181: last;
5182: }
5183: }
5184: }
5185: }
5186: }
5187: }
5188: }
5189: }
1.1075.2.161. .4(raebu 5190:22): if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5191:22): return ();
5192:22): }
1.1075.2.158 raeburn 5193: }
1.1075.2.73 raeburn 5194: if (defined($udom) && defined($uname)) {
5195: # If uname and udom are for a course, check for blocks in the course.
5196: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5197: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 5198: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 5199: return ($startblock,$endblock,$triggerblock);
5200: }
5201: } else {
1.490 raeburn 5202: $udom = $env{'user.domain'};
5203: $uname = $env{'user.name'};
5204: }
5205:
1.502 raeburn 5206: my $startblock = 0;
5207: my $endblock = 0;
1.1062 raeburn 5208: my $triggerblock = '';
1.1075.2.160 raeburn 5209: my %live_courses;
5210: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5211: %live_courses = &findallcourses(undef,$uname,$udom);
5212: }
1.474 raeburn 5213:
1.490 raeburn 5214: # If uname is for a user, and activity is course-specific, i.e.,
5215: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5216:
1.490 raeburn 5217: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.161. .1(raebu 5218:21): $activity eq 'groups' || $activity eq 'printout' ||
5219:21): $activity eq 'search' || $activity eq 'reinit' ||
5220:21): $activity eq 'alert') && ($env{'request.course.id'})) {
1.490 raeburn 5221: foreach my $key (keys(%live_courses)) {
5222: if ($key ne $env{'request.course.id'}) {
5223: delete($live_courses{$key});
5224: }
5225: }
5226: }
5227:
5228: my $otheruser = 0;
5229: my %own_courses;
5230: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5231: # Resource belongs to user other than current user.
5232: $otheruser = 1;
5233: # Gather courses for current user
5234: %own_courses =
5235: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5236: }
5237:
5238: # Gather active course roles - course coordinator, instructor,
5239: # exam proctor, ta, student, or custom role.
1.474 raeburn 5240:
5241: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5242: my ($cdom,$cnum);
5243: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5244: $cdom = $env{'course.'.$course.'.domain'};
5245: $cnum = $env{'course.'.$course.'.num'};
5246: } else {
1.490 raeburn 5247: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5248: }
5249: my $no_ownblock = 0;
5250: my $no_userblock = 0;
1.533 raeburn 5251: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5252: # Check if current user has 'evb' priv for this
5253: if (defined($own_courses{$course})) {
5254: foreach my $sec (keys(%{$own_courses{$course}})) {
5255: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5256: if ($sec ne 'none') {
5257: $checkrole .= '/'.$sec;
5258: }
5259: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5260: $no_ownblock = 1;
5261: last;
5262: }
5263: }
5264: }
5265: # if they have 'evb' priv and are currently not playing student
5266: next if (($no_ownblock) &&
5267: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5268: }
1.474 raeburn 5269: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5270: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5271: if ($sec ne 'none') {
1.482 raeburn 5272: $checkrole .= '/'.$sec;
1.474 raeburn 5273: }
1.490 raeburn 5274: if ($otheruser) {
5275: # Resource belongs to user other than current user.
5276: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5277: my (%allroles,%userroles);
5278: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5279: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5280: my ($trole,$tdom,$tnum,$tsec);
5281: if ($entry =~ /^cr/) {
5282: ($trole,$tdom,$tnum,$tsec) =
5283: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5284: } else {
5285: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5286: }
5287: my ($spec,$area,$trest);
5288: $area = '/'.$tdom.'/'.$tnum;
5289: $trest = $tnum;
5290: if ($tsec ne '') {
5291: $area .= '/'.$tsec;
5292: $trest .= '/'.$tsec;
5293: }
5294: $spec = $trole.'.'.$area;
5295: if ($trole =~ /^cr/) {
5296: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5297: $tdom,$spec,$trest,$area);
5298: } else {
5299: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5300: $tdom,$spec,$trest,$area);
5301: }
5302: }
1.1075.2.124 raeburn 5303: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5304: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5305: if ($1) {
5306: $no_userblock = 1;
5307: last;
5308: }
1.486 raeburn 5309: }
5310: }
1.490 raeburn 5311: } else {
5312: # Resource belongs to current user
5313: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5314: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5315: $no_ownblock = 1;
5316: last;
5317: }
1.474 raeburn 5318: }
5319: }
5320: # if they have the evb priv and are currently not playing student
1.482 raeburn 5321: next if (($no_ownblock) &&
1.491 albertel 5322: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5323: next if ($no_userblock);
1.474 raeburn 5324:
1.1075.2.128 raeburn 5325: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5326: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5327:
1.1062 raeburn 5328: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 5329: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5330: if (($start != 0) &&
5331: (($startblock == 0) || ($startblock > $start))) {
5332: $startblock = $start;
1.1062 raeburn 5333: if ($trigger ne '') {
5334: $triggerblock = $trigger;
5335: }
1.502 raeburn 5336: }
5337: if (($end != 0) &&
5338: (($endblock == 0) || ($endblock < $end))) {
5339: $endblock = $end;
1.1062 raeburn 5340: if ($trigger ne '') {
5341: $triggerblock = $trigger;
5342: }
1.502 raeburn 5343: }
1.490 raeburn 5344: }
1.1062 raeburn 5345: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5346: }
5347:
5348: sub get_blocks {
1.1075.2.147 raeburn 5349: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5350: my $startblock = 0;
5351: my $endblock = 0;
1.1062 raeburn 5352: my $triggerblock = '';
1.490 raeburn 5353: my $course = $cdom.'_'.$cnum;
5354: $setters->{$course} = {};
5355: $setters->{$course}{'staff'} = [];
5356: $setters->{$course}{'times'} = [];
1.1062 raeburn 5357: $setters->{$course}{'triggers'} = [];
5358: my (@blockers,%triggered);
5359: my $now = time;
5360: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5361: if ($activity eq 'docs') {
1.1075.2.148 raeburn 5362: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 5363: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5364: $blocked = 1;
5365: $nosymbcache = 1;
1.1075.2.148 raeburn 5366: $noenccheck = 1;
1.1075.2.147 raeburn 5367: }
1.1075.2.148 raeburn 5368: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5369: foreach my $block (@blockers) {
5370: if ($block =~ /^firstaccess____(.+)$/) {
5371: my $item = $1;
5372: my $type = 'map';
5373: my $timersymb = $item;
5374: if ($item eq 'course') {
5375: $type = 'course';
5376: } elsif ($item =~ /___\d+___/) {
5377: $type = 'resource';
5378: } else {
5379: $timersymb = &Apache::lonnet::symbread($item);
5380: }
5381: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5382: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5383: $triggered{$block} = {
5384: start => $start,
5385: end => $end,
5386: type => $type,
5387: };
5388: }
5389: }
5390: } else {
5391: foreach my $block (keys(%commblocks)) {
5392: if ($block =~ m/^(\d+)____(\d+)$/) {
5393: my ($start,$end) = ($1,$2);
5394: if ($start <= time && $end >= time) {
5395: if (ref($commblocks{$block}) eq 'HASH') {
5396: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5397: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5398: unless(grep(/^\Q$block\E$/,@blockers)) {
5399: push(@blockers,$block);
5400: }
5401: }
5402: }
5403: }
5404: }
5405: } elsif ($block =~ /^firstaccess____(.+)$/) {
5406: my $item = $1;
5407: my $timersymb = $item;
5408: my $type = 'map';
5409: if ($item eq 'course') {
5410: $type = 'course';
5411: } elsif ($item =~ /___\d+___/) {
5412: $type = 'resource';
5413: } else {
5414: $timersymb = &Apache::lonnet::symbread($item);
5415: }
5416: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5417: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5418: if ($start && $end) {
5419: if (($start <= time) && ($end >= time)) {
1.1075.2.158 raeburn 5420: if (ref($commblocks{$block}) eq 'HASH') {
5421: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5422: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5423: unless(grep(/^\Q$block\E$/,@blockers)) {
5424: push(@blockers,$block);
5425: $triggered{$block} = {
5426: start => $start,
5427: end => $end,
5428: type => $type,
5429: };
5430: }
5431: }
5432: }
1.1062 raeburn 5433: }
5434: }
1.490 raeburn 5435: }
1.1062 raeburn 5436: }
5437: }
5438: }
5439: foreach my $blocker (@blockers) {
5440: my ($staff_name,$staff_dom,$title,$blocks) =
5441: &parse_block_record($commblocks{$blocker});
5442: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5443: my ($start,$end,$triggertype);
5444: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5445: ($start,$end) = ($1,$2);
5446: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5447: $start = $triggered{$blocker}{'start'};
5448: $end = $triggered{$blocker}{'end'};
5449: $triggertype = $triggered{$blocker}{'type'};
5450: }
5451: if ($start) {
5452: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5453: if ($triggertype) {
5454: push(@{$$setters{$course}{'triggers'}},$triggertype);
5455: } else {
5456: push(@{$$setters{$course}{'triggers'}},0);
5457: }
5458: if ( ($startblock == 0) || ($startblock > $start) ) {
5459: $startblock = $start;
5460: if ($triggertype) {
5461: $triggerblock = $blocker;
1.474 raeburn 5462: }
5463: }
1.1062 raeburn 5464: if ( ($endblock == 0) || ($endblock < $end) ) {
5465: $endblock = $end;
5466: if ($triggertype) {
5467: $triggerblock = $blocker;
5468: }
5469: }
1.474 raeburn 5470: }
5471: }
1.1062 raeburn 5472: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5473: }
5474:
5475: sub parse_block_record {
5476: my ($record) = @_;
5477: my ($setuname,$setudom,$title,$blocks);
5478: if (ref($record) eq 'HASH') {
5479: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5480: $title = &unescape($record->{'event'});
5481: $blocks = $record->{'blocks'};
5482: } else {
5483: my @data = split(/:/,$record,3);
5484: if (scalar(@data) eq 2) {
5485: $title = $data[1];
5486: ($setuname,$setudom) = split(/@/,$data[0]);
5487: } else {
5488: ($setuname,$setudom,$title) = @data;
5489: }
5490: $blocks = { 'com' => 'on' };
5491: }
5492: return ($setuname,$setudom,$title,$blocks);
5493: }
5494:
1.854 kalberla 5495: sub blocking_status {
1.1075.2.158 raeburn 5496: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5497: my %setters;
1.890 droeschl 5498:
1.1061 raeburn 5499: # check for active blocking
1.1075.2.158 raeburn 5500: if ($clientip eq '') {
5501: $clientip = &Apache::lonnet::get_requestor_ip();
5502: }
5503: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5504: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5505: my $blocked = 0;
1.1075.2.158 raeburn 5506: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5507: $blocked = 1;
5508: }
1.890 droeschl 5509:
1.1061 raeburn 5510: # caller just wants to know whether a block is active
5511: if (!wantarray) { return $blocked; }
5512:
5513: # build a link to a popup window containing the details
5514: my $querystring = "?activity=$activity";
1.1075.2.158 raeburn 5515: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5516: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5517: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5518: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5519: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 5520: my $showurl = &Apache::lonenc::check_encrypt($url);
5521: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5522: if ($symb) {
5523: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5524: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5525: }
1.1062 raeburn 5526: }
1.1061 raeburn 5527:
5528: my $output .= <<'END_MYBLOCK';
5529: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5530: var options = "width=" + w + ",height=" + h + ",";
5531: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5532: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5533: var newWin = window.open(url, wdwName, options);
5534: newWin.focus();
5535: }
1.890 droeschl 5536: END_MYBLOCK
1.854 kalberla 5537:
1.1061 raeburn 5538: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5539:
1.1061 raeburn 5540: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5541: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5542: my $class = 'LC_comblock';
1.1062 raeburn 5543: if ($activity eq 'docs') {
5544: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5545: $class = '';
1.1063 raeburn 5546: } elsif ($activity eq 'printout') {
5547: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5548: } elsif ($activity eq 'passwd') {
5549: $text = &mt('Password Changing Blocked');
1.1075.2.158 raeburn 5550: } elsif ($activity eq 'grades') {
5551: $text = &mt('Gradebook Blocked');
5552: } elsif ($activity eq 'search') {
5553: $text = &mt('Search Blocked');
1.1075.2.161. .1(raebu 5554:21): } elsif ($activity eq 'alert') {
5555:21): $text = &mt('Checking Critical Messages Blocked');
5556:21): } elsif ($activity eq 'reinit') {
5557:21): $text = &mt('Checking Course Update Blocked');
1.1075.2.158 raeburn 5558: } elsif ($activity eq 'about') {
5559: $text = &mt('Access to User Information Pages Blocked');
1.1075.2.160 raeburn 5560: } elsif ($activity eq 'wishlist') {
5561: $text = &mt('Access to Stored Links Blocked');
5562: } elsif ($activity eq 'annotate') {
5563: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5564: }
1.1061 raeburn 5565: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5566: <div class='$class'>
1.869 kalberla 5567: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5568: title='$text'>
5569: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5570: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5571: title='$text'>$text</a>
1.867 kalberla 5572: </div>
5573:
5574: END_BLOCK
1.474 raeburn 5575:
1.1061 raeburn 5576: return ($blocked, $output);
1.854 kalberla 5577: }
1.490 raeburn 5578:
1.60 matthew 5579: ###############################################
5580:
1.682 raeburn 5581: sub check_ip_acc {
1.1075.2.105 raeburn 5582: my ($acc,$clientip)=@_;
1.682 raeburn 5583: &Apache::lonxml::debug("acc is $acc");
5584: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5585: return 1;
5586: }
5587: my $allowed=0;
1.1075.2.144 raeburn 5588: my $ip;
5589: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5590: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5591: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5592: } else {
1.1075.2.150 raeburn 5593: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5594: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1075.2.144 raeburn 5595: }
1.682 raeburn 5596:
5597: my $name;
1.1075.2.161. .1(raebu 5598:21): my %access = (
5599:21): allowfrom => 1,
5600:21): denyfrom => 0,
5601:21): );
5602:21): my @allows;
5603:21): my @denies;
5604:21): foreach my $item (split(',',$acc)) {
5605:21): $item =~ s/^\s*//;
5606:21): $item =~ s/\s*$//;
5607:21): if ($item =~ /^\!(.+)$/) {
5608:21): push(@denies,$1);
5609:21): } else {
5610:21): push(@allows,$item);
5611:21): }
5612:21): }
5613:21): my $numdenies = scalar(@denies);
5614:21): my $numallows = scalar(@allows);
5615:21): my $count = 0;
5616:21): foreach my $pattern (@denies,@allows) {
5617:21): $count ++;
5618:21): my $acctype = 'allowfrom';
5619:21): if ($count <= $numdenies) {
5620:21): $acctype = 'denyfrom';
5621:21): }
1.682 raeburn 5622: if ($pattern =~ /\*$/) {
5623: #35.8.*
5624: $pattern=~s/\*//;
1.1075.2.161. .1(raebu 5625:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5626: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5627: #35.8.3.[34-56]
5628: my $low=$2;
5629: my $high=$3;
5630: $pattern=$1;
5631: if ($ip =~ /^\Q$pattern\E/) {
5632: my $last=(split(/\./,$ip))[3];
1.1075.2.161. .1(raebu 5633:21): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5634: }
5635: } elsif ($pattern =~ /^\*/) {
5636: #*.msu.edu
5637: $pattern=~s/\*//;
5638: if (!defined($name)) {
5639: use Socket;
5640: my $netaddr=inet_aton($ip);
5641: ($name)=gethostbyaddr($netaddr,AF_INET);
5642: }
1.1075.2.161. .1(raebu 5643:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5644: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5645: #127.0.0.1
1.1075.2.161. .1(raebu 5646:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5647: } else {
5648: #some.name.com
5649: if (!defined($name)) {
5650: use Socket;
5651: my $netaddr=inet_aton($ip);
5652: ($name)=gethostbyaddr($netaddr,AF_INET);
5653: }
1.1075.2.161. .1(raebu 5654:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5655:21): }
5656:21): if ($allowed =~ /^(0|1)$/) { last; }
5657:21): }
5658:21): if ($allowed eq '') {
5659:21): if ($numdenies && !$numallows) {
5660:21): $allowed = 1;
5661:21): } else {
5662:21): $allowed = 0;
1.682 raeburn 5663: }
5664: }
5665: return $allowed;
5666: }
5667:
5668: ###############################################
5669:
1.60 matthew 5670: =pod
5671:
1.112 bowersj2 5672: =head1 Domain Template Functions
5673:
5674: =over 4
5675:
5676: =item * &determinedomain()
1.60 matthew 5677:
5678: Inputs: $domain (usually will be undef)
5679:
1.63 www 5680: Returns: Determines which domain should be used for designs
1.60 matthew 5681:
5682: =cut
1.54 www 5683:
1.60 matthew 5684: ###############################################
1.63 www 5685: sub determinedomain {
5686: my $domain=shift;
1.531 albertel 5687: if (! $domain) {
1.60 matthew 5688: # Determine domain if we have not been given one
1.893 raeburn 5689: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5690: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5691: if ($env{'request.role.domain'}) {
5692: $domain=$env{'request.role.domain'};
1.60 matthew 5693: }
5694: }
1.63 www 5695: return $domain;
5696: }
5697: ###############################################
1.517 raeburn 5698:
1.518 albertel 5699: sub devalidate_domconfig_cache {
5700: my ($udom)=@_;
5701: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5702: }
5703:
5704: # ---------------------- Get domain configuration for a domain
5705: sub get_domainconf {
5706: my ($udom) = @_;
5707: my $cachetime=1800;
5708: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5709: if (defined($cached)) { return %{$result}; }
5710:
5711: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5712: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5713: my (%designhash,%legacy);
1.518 albertel 5714: if (keys(%domconfig) > 0) {
5715: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5716: if (keys(%{$domconfig{'login'}})) {
5717: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5718: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5719: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5720: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5721: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5722: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5723: if ($key eq 'loginvia') {
5724: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5725: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5726: $designhash{$udom.'.login.loginvia'} = $server;
5727: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5728: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5729: } else {
5730: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5731: }
1.948 raeburn 5732: }
1.1075.2.87 raeburn 5733: } elsif ($key eq 'headtag') {
5734: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5735: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5736: }
1.946 raeburn 5737: }
1.1075.2.87 raeburn 5738: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5739: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5740: }
1.946 raeburn 5741: }
5742: }
5743: }
1.1075.2.158 raeburn 5744: } elsif ($key eq 'saml') {
5745: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5746: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5747: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5748: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1075.2.161. .9(raebu 5749:22): foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1075.2.158 raeburn 5750: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5751: }
5752: }
5753: }
5754: }
1.946 raeburn 5755: } else {
5756: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5757: $designhash{$udom.'.login.'.$key.'_'.$img} =
5758: $domconfig{'login'}{$key}{$img};
5759: }
1.699 raeburn 5760: }
5761: } else {
5762: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5763: }
1.632 raeburn 5764: }
5765: } else {
5766: $legacy{'login'} = 1;
1.518 albertel 5767: }
1.632 raeburn 5768: } else {
5769: $legacy{'login'} = 1;
1.518 albertel 5770: }
5771: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5772: if (keys(%{$domconfig{'rolecolors'}})) {
5773: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5774: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5775: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5776: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5777: }
1.518 albertel 5778: }
5779: }
1.632 raeburn 5780: } else {
5781: $legacy{'rolecolors'} = 1;
1.518 albertel 5782: }
1.632 raeburn 5783: } else {
5784: $legacy{'rolecolors'} = 1;
1.518 albertel 5785: }
1.948 raeburn 5786: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5787: if ($domconfig{'autoenroll'}{'co-owners'}) {
5788: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5789: }
5790: }
1.632 raeburn 5791: if (keys(%legacy) > 0) {
5792: my %legacyhash = &get_legacy_domconf($udom);
5793: foreach my $item (keys(%legacyhash)) {
5794: if ($item =~ /^\Q$udom\E\.login/) {
5795: if ($legacy{'login'}) {
5796: $designhash{$item} = $legacyhash{$item};
5797: }
5798: } else {
5799: if ($legacy{'rolecolors'}) {
5800: $designhash{$item} = $legacyhash{$item};
5801: }
1.518 albertel 5802: }
5803: }
5804: }
1.632 raeburn 5805: } else {
5806: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5807: }
5808: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5809: $cachetime);
5810: return %designhash;
5811: }
5812:
1.632 raeburn 5813: sub get_legacy_domconf {
5814: my ($udom) = @_;
5815: my %legacyhash;
5816: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5817: my $designfile = $designdir.'/'.$udom.'.tab';
5818: if (-e $designfile) {
1.1075.2.128 raeburn 5819: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5820: while (my $line = <$fh>) {
5821: next if ($line =~ /^\#/);
5822: chomp($line);
5823: my ($key,$val)=(split(/\=/,$line));
5824: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5825: }
5826: close($fh);
5827: }
5828: }
1.1026 raeburn 5829: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5830: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5831: }
5832: return %legacyhash;
5833: }
5834:
1.63 www 5835: =pod
5836:
1.112 bowersj2 5837: =item * &domainlogo()
1.63 www 5838:
5839: Inputs: $domain (usually will be undef)
5840:
5841: Returns: A link to a domain logo, if the domain logo exists.
5842: If the domain logo does not exist, a description of the domain.
5843:
5844: =cut
1.112 bowersj2 5845:
1.63 www 5846: ###############################################
5847: sub domainlogo {
1.517 raeburn 5848: my $domain = &determinedomain(shift);
1.518 albertel 5849: my %designhash = &get_domainconf($domain);
1.517 raeburn 5850: # See if there is a logo
5851: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5852: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5853: if ($imgsrc =~ m{^/(adm|res)/}) {
5854: if ($imgsrc =~ m{^/res/}) {
5855: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5856: &Apache::lonnet::repcopy($local_name);
5857: }
5858: $imgsrc = &lonhttpdurl($imgsrc);
1.1075.2.161. .2(raebu 5859:22): }
5860:22): my $alttext = $domain;
5861:22): if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5862:22): $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5863:22): }
5864:22): return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5865: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5866: return &Apache::lonnet::domain($domain,'description');
1.59 www 5867: } else {
1.60 matthew 5868: return '';
1.59 www 5869: }
5870: }
1.63 www 5871: ##############################################
5872:
5873: =pod
5874:
1.112 bowersj2 5875: =item * &designparm()
1.63 www 5876:
5877: Inputs: $which parameter; $domain (usually will be undef)
5878:
5879: Returns: value of designparamter $which
5880:
5881: =cut
1.112 bowersj2 5882:
1.397 albertel 5883:
1.400 albertel 5884: ##############################################
1.397 albertel 5885: sub designparm {
5886: my ($which,$domain)=@_;
5887: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5888: return $env{'environment.color.'.$which};
1.96 www 5889: }
1.63 www 5890: $domain=&determinedomain($domain);
1.1016 raeburn 5891: my %domdesign;
5892: unless ($domain eq 'public') {
5893: %domdesign = &get_domainconf($domain);
5894: }
1.520 raeburn 5895: my $output;
1.517 raeburn 5896: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5897: $output = $domdesign{$domain.'.'.$which};
1.63 www 5898: } else {
1.520 raeburn 5899: $output = $defaultdesign{$which};
5900: }
5901: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5902: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5903: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5904: if ($output =~ m{^/res/}) {
5905: my $local_name = &Apache::lonnet::filelocation('',$output);
5906: &Apache::lonnet::repcopy($local_name);
5907: }
1.520 raeburn 5908: $output = &lonhttpdurl($output);
5909: }
1.63 www 5910: }
1.520 raeburn 5911: return $output;
1.63 www 5912: }
1.59 www 5913:
1.822 bisitz 5914: ##############################################
5915: =pod
5916:
1.832 bisitz 5917: =item * &authorspace()
5918:
1.1028 raeburn 5919: Inputs: $url (usually will be undef).
1.832 bisitz 5920:
1.1075.2.40 raeburn 5921: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5922: directory being viewed (or for which action is being taken).
5923: If $url is provided, and begins /priv/<domain>/<uname>
5924: the path will be that portion of the $context argument.
5925: Otherwise the path will be for the author space of the current
5926: user when the current role is author, or for that of the
5927: co-author/assistant co-author space when the current role
5928: is co-author or assistant co-author.
1.832 bisitz 5929:
5930: =cut
5931:
5932: sub authorspace {
1.1028 raeburn 5933: my ($url) = @_;
5934: if ($url ne '') {
5935: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5936: return $1;
5937: }
5938: }
1.832 bisitz 5939: my $caname = '';
1.1024 www 5940: my $cadom = '';
1.1028 raeburn 5941: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5942: ($cadom,$caname) =
1.832 bisitz 5943: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5944: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5945: $caname = $env{'user.name'};
1.1024 www 5946: $cadom = $env{'user.domain'};
1.832 bisitz 5947: }
1.1028 raeburn 5948: if (($caname ne '') && ($cadom ne '')) {
5949: return "/priv/$cadom/$caname/";
5950: }
5951: return;
1.832 bisitz 5952: }
5953:
5954: ##############################################
5955: =pod
5956:
1.822 bisitz 5957: =item * &head_subbox()
5958:
5959: Inputs: $content (contains HTML code with page functions, etc.)
5960:
5961: Returns: HTML div with $content
5962: To be included in page header
5963:
5964: =cut
5965:
5966: sub head_subbox {
5967: my ($content)=@_;
5968: my $output =
1.993 raeburn 5969: '<div class="LC_head_subbox">'
1.822 bisitz 5970: .$content
5971: .'</div>'
5972: }
5973:
5974: ##############################################
5975: =pod
5976:
5977: =item * &CSTR_pageheader()
5978:
1.1026 raeburn 5979: Input: (optional) filename from which breadcrumb trail is built.
5980: In most cases no input as needed, as $env{'request.filename'}
5981: is appropriate for use in building the breadcrumb trail.
1.1075.2.161. .6(raebu 5982:22): frameset flag
5983:22): If page header is being requested for use in a frameset, then
5984:22): the second (option) argument -- frameset will be true, and
5985:22): the target attribute set for links should be target="_parent".
.26(raeb 5986:-24): If $title is supplied as the third arg, that will be used to
5987:-24): the left of the breadcrumbs tail for the current path.
1.822 bisitz 5988:
5989: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5990: To be included on Authoring Space pages
1.822 bisitz 5991:
5992: =cut
5993:
5994: sub CSTR_pageheader {
1.1075.2.161. .26(raeb 5995:-24): my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 5996: if ($trailfile eq '') {
5997: $trailfile = $env{'request.filename'};
5998: }
5999:
6000: # this is for resources; directories have customtitle, and crumbs
6001: # and select recent are created in lonpubdir.pm
6002:
6003: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6004: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 6005: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6006: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6007: $formaction =~ s{/+}{/}g;
1.822 bisitz 6008:
6009: my $parentpath = '';
6010: my $lastitem = '';
6011: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6012: $parentpath = $1;
6013: $lastitem = $2;
6014: } else {
6015: $lastitem = $thisdisfn;
6016: }
1.921 bisitz 6017:
1.1075.2.161. .26(raeb 6018:-24): if ($title eq '') {
6019:-24): $title = &mt('Authoring Space');
6020:-24): }
6021:-24):
.6(raebu 6022:22): my ($target,$crumbtarget) = (' target="_top"','_top');
6023:22): if ($frameset) {
6024:22): $target = ' target="_parent"';
6025:22): $crumbtarget = '_parent';
.17(raeb 6026:-23): } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
6027:-23): $target = '';
6028:-23): $crumbtarget = '';
.6(raebu 6029:22): } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
6030:22): $target = ' target="'.$env{'request.deeplink.target'}.'"';
6031:22): $crumbtarget = $env{'request.deeplink.target'};
6032:22): }
6033:22):
1.921 bisitz 6034: my $output =
1.822 bisitz 6035: '<div>'
6036: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.161. .26(raeb 6037:-24): .'<b>'.$title.'</b> '
.6(raebu 6038:22): .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6039:22): .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6040:
6041: if ($lastitem) {
6042: $output .=
6043: '<span class="LC_filename">'
6044: .$lastitem
6045: .'</span>';
6046: }
6047: $output .=
6048: '<br />'
1.1075.2.161. .6(raebu 6049:22): #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.822 bisitz 6050: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6051: .'</form>'
1.1075.2.161. .6(raebu 6052:22): .&Apache::lonmenu::constspaceform($frameset)
1.822 bisitz 6053: .'</div>';
1.921 bisitz 6054:
6055: return $output;
1.822 bisitz 6056: }
6057:
1.1075.2.161. .21(raeb 6058:-24): ##############################################
6059:-24): =pod
6060:-24):
6061:-24): =item * &nocodemirror()
6062:-24):
6063:-24): Input: None
6064:-24):
6065:-24): Returns: 1 if CodeMirror is deactivated based on
6066:-24): user's preference, or domain default,
6067:-24): if user indicated use of default.
6068:-24):
6069:-24): =cut
6070:-24):
6071:-24): sub nocodemirror {
6072:-24): my $nocodem = $env{'environment.nocodemirror'};
6073:-24): unless ($nocodem) {
6074:-24): my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6075:-24): if ($domdefs{'nocodemirror'}) {
6076:-24): $nocodem = 'yes';
6077:-24): }
6078:-24): }
6079:-24): if ($nocodem eq 'yes') {
6080:-24): return 1;
6081:-24): }
6082:-24): return;
6083:-24): }
6084:-24):
6085:-24): ##############################################
6086:-24): =pod
6087:-24):
6088:-24): =item * &permitted_editors()
6089:-24):
6090:-24): Input: $uri (optional)
6091:-24):
6092:-24): Returns: %editors hash in which keys are editors
.25(raeb 6093:-24): permitted in current Authoring Space,
6094:-24): or in current course for web pages
6095:-24): created in a course.
6096:-24):
.21(raeb 6097:-24): Value for each key is 1. Possible keys
.25(raeb 6098:-24): are: edit, xml, and daxe.
6099:-24):
6100:-24): For a regular Authoring Space, if no specific
.21(raeb 6101:-24): set of editors has been set for the Author
6102:-24): who owns the Authoring Space, then the
6103:-24): domain default will be used. If no domain
6104:-24): default has been set, then the keys will be
6105:-24): edit and xml.
6106:-24):
.25(raeb 6107:-24): For a course author, or for web pages created
6108:-24): in a course, if no specific set of editors has
6109:-24): been set for the course, then the domain
6110:-24): course default will be used. If no domain
6111:-24): course default has been set, then the keys
6112:-24): will be edit and xml.
6113:-24):
.21(raeb 6114:-24): =cut
6115:-24):
6116:-24): sub permitted_editors {
6117:-24): my ($uri) = @_;
.25(raeb 6118:-24): my ($is_author,$is_coauthor,$is_course,$auname,$audom,%editors);
.21(raeb 6119:-24): if ($env{'request.role'} =~ m{^au\./}) {
6120:-24): $is_author = 1;
6121:-24): } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6122:-24): ($audom,$auname) = ($1,$2);
6123:-24): if (($audom ne '') && ($auname ne '')) {
6124:-24): if (($env{'user.domain'} eq $audom) &&
6125:-24): ($env{'user.name'} eq $auname)) {
6126:-24): $is_author = 1;
6127:-24): } else {
6128:-24): $is_coauthor = 1;
6129:-24): }
6130:-24): }
6131:-24): } elsif ($env{'request.course.id'}) {
.25(raeb 6132:-24): my ($cdom,$cnum);
6133:-24): $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6134:-24): $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6135:-24): if (($env{'request.editurl'} =~ m{^/priv/\Q$cdom/$cnum\E/}) ||
6136:-24): ($env{'request.editurl'} =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}) ||
6137:-24): ($uri =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/})) {
6138:-24): $is_course = 1;
6139:-24): } elsif ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
.21(raeb 6140:-24): ($audom,$auname) = ($1,$2);
6141:-24): } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6142:-24): ($audom,$auname) = ($1,$2);
6143:-24): } elsif (($uri eq '/daxesave') &&
.25(raeb 6144:-24): (($env{'form.path'} =~ m{^/daxeopen/priv/\Q$cdom/$cnum\E/}) ||
6145:-24): ($env{'form.path'} =~ m{^/daxeopen/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}))) {
6146:-24): $is_course = 1;
6147:-24): } elsif (($uri eq '/daxesave') &&
.21(raeb 6148:-24): ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {
6149:-24): ($audom,$auname) = ($1,$2);
6150:-24): }
.25(raeb 6151:-24): unless ($is_course) {
6152:-24): if (($audom ne '') && ($auname ne '')) {
6153:-24): if (($env{'user.domain'} eq $audom) &&
6154:-24): ($env{'user.name'} eq $auname)) {
6155:-24): $is_author = 1;
6156:-24): } else {
6157:-24): $is_coauthor = 1;
6158:-24): }
.21(raeb 6159:-24): }
6160:-24): }
6161:-24): }
6162:-24): if ($is_author) {
6163:-24): if (exists($env{'environment.editors'})) {
6164:-24): map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6165:-24): } else {
6166:-24): %editors = ( edit => 1,
6167:-24): xml => 1,
6168:-24): );
6169:-24): }
6170:-24): } elsif ($is_coauthor) {
6171:-24): if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6172:-24): map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6173:-24): } else {
6174:-24): %editors = ( edit => 1,
6175:-24): xml => 1,
6176:-24): );
6177:-24): }
.25(raeb 6178:-24): } elsif ($is_course) {
6179:-24): if (exists($env{'course.'.$env{'request.course.id'}.'.internal.crseditors'})) {
6180:-24): map { $editors{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.crseditors'});
6181:-24): } else {
6182:-24): my %domdefaults = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
6183:-24): if (exists($domdefaults{'crseditors'})) {
6184:-24): map { $editors{$_} = 1; } split(/,/,$domdefaults{'crseditors'});
6185:-24): } else {
6186:-24): %editors = ( edit => 1,
6187:-24): xml => 1,
6188:-24): );
6189:-24): }
6190:-24): }
.21(raeb 6191:-24): } else {
6192:-24): %editors = ( edit => 1,
6193:-24): xml => 1,
6194:-24): );
6195:-24): }
6196:-24): return %editors;
6197:-24): }
6198:-24):
1.60 matthew 6199: ###############################################
6200: ###############################################
6201:
6202: =pod
6203:
1.112 bowersj2 6204: =back
6205:
1.549 albertel 6206: =head1 HTML Helpers
1.112 bowersj2 6207:
6208: =over 4
6209:
6210: =item * &bodytag()
1.60 matthew 6211:
6212: Returns a uniform header for LON-CAPA web pages.
6213:
6214: Inputs:
6215:
1.112 bowersj2 6216: =over 4
6217:
6218: =item * $title, A title to be displayed on the page.
6219:
6220: =item * $function, the current role (can be undef).
6221:
6222: =item * $addentries, extra parameters for the <body> tag.
6223:
6224: =item * $bodyonly, if defined, only return the <body> tag.
6225:
6226: =item * $domain, if defined, force a given domain.
6227:
6228: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6229: text interface only)
1.60 matthew 6230:
1.814 bisitz 6231: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6232: navigational links
1.317 albertel 6233:
1.338 albertel 6234: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6235:
1.1075.2.12 raeburn 6236: =item * $no_inline_link, if true and in remote mode, don't show the
6237: 'Switch To Inline Menu' link
6238:
1.460 albertel 6239: =item * $args, optional argument valid values are
6240: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 6241: use_absolute -> for external resource or syllabus, this will
6242: contain https://<hostname> if server uses
6243: https (as per hosts.tab), but request is for http
6244: hostname -> hostname, from $r->hostname().
1.460 albertel 6245:
1.1075.2.15 raeburn 6246: =item * $advtoolsref, optional argument, ref to an array containing
6247: inlineremote items to be added in "Functions" menu below
6248: breadcrumbs.
6249:
1.1075.2.161. .1(raebu 6250:21): =item * $ltiscope, optional argument, will be one of: resource, map or
6251:21): course, if LON-CAPA is in LTI Provider context. Value is
6252:21): the scope of use, i.e., launch was for access to a single, a map
6253:21): or the entire course.
6254:21):
6255:21): =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6256:21): context, this will contain the URL for the landing item in
6257:21): the course, after launch from an LTI Consumer
6258:21):
6259:21): =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6260:21): context, this will contain a reference to hash of items
6261:21): to be included in the page header and/or inline menu.
6262:21):
.8(raebu 6263:22): =item * $menucoll, optional argument, if specific menu collection is in
6264:22): effect, either set as the default for the course, or set for
6265:22): the deeplink paramater for $env{'request.deeplink.login'}
6266:22): then $menucoll will be the number of that collection.
6267:22):
6268:22): =item * $menuref, optional argument, reference to a hash, containing the
6269:22): menu options included for the menu in effect, based on the
6270:22): configuration for the numbered menu collection in use.
6271:22):
6272:22): =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6273:22): within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6274:22): if so, $showncrumbsref is set there to 1, and will propagate back
6275:22): via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6276:22): being called a second time.
6277:22):
1.112 bowersj2 6278: =back
6279:
1.60 matthew 6280: Returns: A uniform header for LON-CAPA web pages.
6281: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6282: If $bodyonly is undef or zero, an html string containing a <body> tag and
6283: other decorations will be returned.
6284:
6285: =cut
6286:
1.54 www 6287: sub bodytag {
1.831 bisitz 6288: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.161. .1(raebu 6289:21): $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref,
.8(raebu 6290:22): $ltiscope,$ltiuri,$ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6291:
1.954 raeburn 6292: my $public;
6293: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6294: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6295: $public = 1;
6296: }
1.460 albertel 6297: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 6298: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 6299: my $hostname = $args->{'hostname'};
1.339 albertel 6300:
1.183 matthew 6301: $function = &get_users_function() if (!$function);
1.339 albertel 6302: my $img = &designparm($function.'.img',$domain);
6303: my $font = &designparm($function.'.font',$domain);
6304: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6305:
1.803 bisitz 6306: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6307: 'bgcolor' => $pgbg,
1.339 albertel 6308: 'text' => $font,
6309: 'alink' => &designparm($function.'.alink',$domain),
6310: 'vlink' => &designparm($function.'.vlink',$domain),
6311: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6312: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6313:
1.63 www 6314: # role and realm
1.1075.2.68 raeburn 6315: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6316: if ($realm) {
6317: $realm = '/'.$realm;
6318: }
1.1075.2.159 raeburn 6319: if ($role eq 'ca') {
1.479 albertel 6320: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6321: $realm = &plainname($rname,$rdom);
1.378 raeburn 6322: }
1.55 www 6323: # realm
1.1075.2.158 raeburn 6324: my ($cid,$sec);
1.258 albertel 6325: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 6326: $cid = $env{'request.course.id'};
6327: if ($env{'request.course.sec'}) {
6328: $sec = $env{'request.course.sec'};
6329: }
6330: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6331: if (&Apache::lonnet::is_course($1,$2)) {
6332: $cid = $1.'_'.$2;
6333: $sec = $3;
6334: }
6335: }
6336: if ($cid) {
1.378 raeburn 6337: if ($env{'request.role'} !~ /^cr/) {
6338: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 6339: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 6340: if ($env{'request.role.desc'}) {
6341: $role = $env{'request.role.desc'};
6342: } else {
6343: $role = &mt('Helpdesk[_1]',' '.$2);
6344: }
1.1075.2.115 raeburn 6345: } else {
6346: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6347: }
1.1075.2.158 raeburn 6348: if ($sec) {
6349: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6350: }
1.1075.2.158 raeburn 6351: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6352: } else {
6353: $role = &Apache::lonnet::plaintext($role);
1.54 www 6354: }
1.433 albertel 6355:
1.359 albertel 6356: if (!$realm) { $realm=' '; }
1.330 albertel 6357:
1.438 albertel 6358: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6359:
1.101 www 6360: # construct main body tag
1.359 albertel 6361: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 6362: &Apache::lontexconvert::init_math_support();
1.252 albertel 6363:
1.1075.2.38 raeburn 6364: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6365:
6366: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6367: return $bodytag;
1.1075.2.38 raeburn 6368: }
1.359 albertel 6369:
1.954 raeburn 6370: if ($public) {
1.433 albertel 6371: undef($role);
6372: }
1.1075.2.158 raeburn 6373:
1.1075.2.161. .1(raebu 6374:21): my $showcrstitle = 1;
6375:21): if (($cid) && ($env{'request.lti.login'})) {
6376:21): if (ref($ltimenu) eq 'HASH') {
6377:21): unless ($ltimenu->{'role'}) {
6378:21): undef($role);
6379:21): }
6380:21): unless ($ltimenu->{'coursetitle'}) {
6381:21): $realm=' ';
6382:21): $showcrstitle = 0;
6383:21): }
6384:21): }
6385:21): } elsif (($cid) && ($menucoll)) {
6386:21): if (ref($menuref) eq 'HASH') {
6387:21): unless ($menuref->{'role'}) {
6388:21): undef($role);
6389:21): }
6390:21): unless ($menuref->{'crs'}) {
6391:21): $realm=' ';
6392:21): $showcrstitle = 0;
6393:21): }
6394:21): }
6395:21): }
6396:21):
1.762 bisitz 6397: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6398: #
6399: # Extra info if you are the DC
6400: my $dc_info = '';
1.1075.2.161. .1(raebu 6401:21): if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1075.2.158 raeburn 6402: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6403: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6404: $dc_info =~ s/\s+$//;
1.359 albertel 6405: }
6406:
1.1075.2.161. .1(raebu 6407:21): my $crstype;
6408:21): if ($cid) {
6409:21): $crstype = $env{'course.'.$cid.'.type'};
6410:21): } elsif ($args->{'crstype'}) {
6411:21): $crstype = $args->{'crstype'};
6412:21): }
6413:21):
1.1075.2.108 raeburn 6414: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 6415:
1.1075.2.13 raeburn 6416: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6417:
1.1075.2.38 raeburn 6418:
6419:
1.1075.2.21 raeburn 6420: my $funclist;
6421: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 6422: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 6423: Apache::lonmenu::serverform();
6424: my $forbodytag;
6425: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6426: $forcereg,$args->{'group'},
6427: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6428: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 6429: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6430: $funclist = $forbodytag;
6431: }
6432: } else {
1.903 droeschl 6433:
6434: # if ($env{'request.state'} eq 'construct') {
6435: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6436: # }
6437:
1.1075.2.38 raeburn 6438: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6439: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6440:
1.1075.2.161. .23(raeb 6441:-24): my $collapsible;
.21(raeb 6442:-24): if ($args->{'collapsible_header'} ne '') {
.23(raeb 6443:-24): $collapsible = 1;
6444:-24): my ($menustate,$tiptext,$divclass);
6445:-24): if ($args->{'start_collapsed'}) {
6446:-24): $menustate = 'collapsed';
6447:-24): $tiptext = 'display';
6448:-24): $divclass = 'hidden';
6449:-24): } else {
6450:-24): $menustate = 'expanded';
6451:-24): $tiptext = 'hide';
6452:-24): $divclass = 'shown';
6453:-24): }
6454:-24): my $alttext = &mt('menu state: '.$menustate);
6455:-24): my $tooltip = &mt($tiptext.' standard menus');
.21(raeb 6456:-24): $bodytag .= <<"END";
6457:-24): <div id="LC_expandingContainer" style="display:inline;">
6458:-24): <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
.23(raeb 6459:-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>
6460:-24): <div class="LC_menus_content $divclass">
.21(raeb 6461:-24): END
6462:-24): }
.30(raeb 6463:-24): if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} eq 'construct')) {
6464:-24): unless ($env{'form.inhibitmenu'}) {
6465:-24): $bodytag .= &inline_for_remote($public,$role,$realm,$dc_info,$no_inline_link);
6466:-24): }
6467:-24): } elsif (!$args->{'no_primary_menu'}) {
.4(raebu 6468:22): my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
.6(raebu 6469:22): $args->{'links_disabled'},
.21(raeb 6470:-24): $args->{'links_target'},
.23(raeb 6471:-24): $collapsible);
.1(raebu 6472:21): if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6473:21): if ($dc_info) {
6474:21): $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6475:21): }
6476:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6477:21): <em>$realm</em> $dc_info</div>|;
6478:21): return $bodytag;
1.1075.2.1 raeburn 6479: }
1.894 droeschl 6480:
1.1075.2.161. .1(raebu 6481:21): unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6482:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6483:21): }
1.916 droeschl 6484:
1.1075.2.161. .1(raebu 6485:21): $bodytag .= $right;
1.852 droeschl 6486:
1.1075.2.161. .1(raebu 6487:21): if ($dc_info) {
6488:21): $dc_info = &dc_courseid_toggle($dc_info);
6489:21): }
6490:21): $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6491: }
1.916 droeschl 6492:
1.1075.2.61 raeburn 6493: #if directed to not display the secondary menu, don't.
6494: if ($args->{'no_secondary_menu'}) {
6495: return $bodytag;
6496: }
1.903 droeschl 6497: #don't show menus for public users
1.954 raeburn 6498: if (!$public){
1.1075.2.161. .30(raeb 6499:-24): unless (($args->{'no_inline_menu'}) ||
6500:-24): (($env{'environment.remote'} eq 'on') &&
6501:-24): ($env{'request.state'} eq 'construct'))) {
.1(raebu 6502:21): $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6503:21): $args->{'no_primary_menu'},
6504:21): $menucoll,$menuref,
.6(raebu 6505:22): $args->{'links_disabled'},
6506:22): $args->{'links_target'});
.1(raebu 6507:21): }
1.903 droeschl 6508: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6509: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6510: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6511: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.161. .8(raebu 6512:22): $args->{'bread_crumbs'},'','',$hostname,
6513:22): $ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.116 raeburn 6514: } elsif ($forcereg) {
1.1075.2.22 raeburn 6515: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.161. .8(raebu 6516:22): $args->{'group'},$args->{'hide_buttons'},
6517:22): $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.15 raeburn 6518: } else {
1.1075.2.21 raeburn 6519: my $forbodytag;
6520: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6521: $forcereg,$args->{'group'},
6522: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6523: $advtoolsref,'',$hostname,
6524: \$forbodytag);
1.1075.2.21 raeburn 6525: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6526: $bodytag .= $forbodytag;
6527: }
1.920 raeburn 6528: }
1.903 droeschl 6529: }else{
6530: # this is to seperate menu from content when there's no secondary
6531: # menu. Especially needed for public accessible ressources.
6532: $bodytag .= '<hr style="clear:both" />';
6533: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6534: }
1.1075.2.161. .21(raeb 6535:-24): if ($args->{'collapsible_header'} ne '') {
6536:-24): $bodytag .= $args->{'collapsible_header'}.
6537:-24): '<div id="LC_collapsible_separator"></div>'.
6538:-24): '</div></div>';
6539:-24): }
1.235 raeburn 6540: return $bodytag;
1.1075.2.12 raeburn 6541: }
6542:
6543: #
6544: # Top frame rendering, Remote is up
6545: #
6546:
1.1075.2.60 raeburn 6547: my $help=($no_inline_link?''
6548: :&Apache::loncommon::top_nav_help('Help'));
6549:
1.1075.2.12 raeburn 6550: # Explicit link to get inline menu
6551: my $menu= ($no_inline_link?''
6552: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
6553:
6554: if ($dc_info) {
6555: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
6556: }
6557:
1.1075.2.38 raeburn 6558: my $name = &plainname($env{'user.name'},$env{'user.domain'});
6559: unless ($public) {
6560: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
6561: undef,'LC_menubuttons_link');
6562: }
6563:
1.1075.2.12 raeburn 6564: unless ($env{'form.inhibitmenu'}) {
1.1075.2.161. .30(raeb 6565:-24): $bodytag .= &inline_for_remote($public,$role,$realm,$dc_info,$no_inline_link);
1.1075.2.13 raeburn 6566: }
1.1075.2.21 raeburn 6567: return $bodytag."\n".$funclist;
1.182 matthew 6568: }
6569:
1.1075.2.161. .30(raeb 6570:-24): sub inline_for_remote {
6571:-24): my ($public,$role,$realm,$dc_info,$no_inline_link) = @_;
6572:-24): my $help=($no_inline_link?''
6573:-24): :&Apache::loncommon::top_nav_help('Help'));
6574:-24):
6575:-24): # Explicit link to get inline menu
6576:-24): my $menu= ($no_inline_link?''
6577:-24): :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
6578:-24):
6579:-24): if ($dc_info) {
6580:-24): $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
6581:-24): }
6582:-24):
6583:-24): my $name = &plainname($env{'user.name'},$env{'user.domain'});
6584:-24): unless ($public) {
6585:-24): $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
6586:-24): undef,'LC_menubuttons_link');
6587:-24): }
6588:-24):
6589:-24): return qq|<div id="LC_nav_bar">$name $role</div>
6590:-24): <ol class="LC_primary_menu LC_floatright LC_right">
6591:-24): <li>$help</li>
6592:-24): <li>$menu</li>
6593:-24): </ol><div id="LC_realm"> $realm $dc_info</div>|;
6594:-24): }
6595:-24):
1.917 raeburn 6596: sub dc_courseid_toggle {
6597: my ($dc_info) = @_;
1.980 raeburn 6598: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6599: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6600: &mt('(More ...)').'</a></span>'.
6601: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6602: }
6603:
1.330 albertel 6604: sub make_attr_string {
6605: my ($register,$attr_ref) = @_;
6606:
6607: if ($attr_ref && !ref($attr_ref)) {
6608: die("addentries Must be a hash ref ".
6609: join(':',caller(1))." ".
6610: join(':',caller(0))." ");
6611: }
6612:
6613: if ($register) {
1.339 albertel 6614: my ($on_load,$on_unload);
6615: foreach my $key (keys(%{$attr_ref})) {
6616: if (lc($key) eq 'onload') {
6617: $on_load.=$attr_ref->{$key}.';';
6618: delete($attr_ref->{$key});
6619:
6620: } elsif (lc($key) eq 'onunload') {
6621: $on_unload.=$attr_ref->{$key}.';';
6622: delete($attr_ref->{$key});
6623: }
6624: }
1.1075.2.12 raeburn 6625: if ($env{'environment.remote'} eq 'on') {
6626: $attr_ref->{'onload'} =
6627: &Apache::lonmenu::loadevents(). $on_load;
6628: $attr_ref->{'onunload'}=
6629: &Apache::lonmenu::unloadevents().$on_unload;
6630: } else {
6631: $attr_ref->{'onload'} = $on_load;
6632: $attr_ref->{'onunload'}= $on_unload;
6633: }
1.330 albertel 6634: }
1.339 albertel 6635:
1.330 albertel 6636: my $attr_string;
1.1075.2.56 raeburn 6637: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6638: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6639: }
6640: return $attr_string;
6641: }
6642:
6643:
1.182 matthew 6644: ###############################################
1.251 albertel 6645: ###############################################
6646:
6647: =pod
6648:
6649: =item * &endbodytag()
6650:
6651: Returns a uniform footer for LON-CAPA web pages.
6652:
1.635 raeburn 6653: Inputs: 1 - optional reference to an args hash
6654: If in the hash, key for noredirectlink has a value which evaluates to true,
6655: a 'Continue' link is not displayed if the page contains an
6656: internal redirect in the <head></head> section,
6657: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6658:
6659: =cut
6660:
6661: sub endbodytag {
1.635 raeburn 6662: my ($args) = @_;
1.1075.2.6 raeburn 6663: my $endbodytag;
6664: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6665: $endbodytag='</body>';
6666: }
1.315 albertel 6667: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6668: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1075.2.161. .9(raebu 6669:22): my ($endbodyjs,$idattr);
6670:22): if ($env{'internal.head.to_opener'}) {
6671:22): my $linkid = 'LC_continue_link';
6672:22): $idattr = ' id="'.$linkid.'"';
6673:22): my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6674:22): $endbodyjs=<<ENDJS;
6675:22): <script type="text/javascript">
6676:22): // <![CDATA[
6677:22): function ebFunction(evt) {
6678:22): evt.preventDefault();
6679:22): var dest = '$redirect_for_js';
6680:22): if (window.opener != null && !window.opener.closed) {
6681:22): window.opener.location.href=dest;
6682:22): window.close();
6683:22): } else {
6684:22): window.location.href=dest;
6685:22): }
6686:22): return false;
6687:22): }
6688:22):
6689:22): \$(document).ready(function () {
6690:22): if (document.getElementById('$linkid')) {
6691:22): var clickelem = document.getElementById('$linkid');
6692:22): clickelem.addEventListener('click',ebFunction,false);
6693:22): }
6694:22): });
6695:22): // ]]>
6696:22): </script>
6697:22): ENDJS
6698:22): }
1.635 raeburn 6699: $endbodytag=
1.1075.2.161. .9(raebu 6700:22): "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6701: &mt('Continue').'</a>'.
6702: $endbodytag;
6703: }
1.315 albertel 6704: }
1.1075.2.161. .19(raeb 6705:-23): if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6706:-23): $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6707:-23): }
1.251 albertel 6708: return $endbodytag;
6709: }
6710:
1.352 albertel 6711: =pod
6712:
6713: =item * &standard_css()
6714:
6715: Returns a style sheet
6716:
6717: Inputs: (all optional)
6718: domain -> force to color decorate a page for a specific
6719: domain
6720: function -> force usage of a specific rolish color scheme
6721: bgcolor -> override the default page bgcolor
6722:
6723: =cut
6724:
1.343 albertel 6725: sub standard_css {
1.345 albertel 6726: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6727: $function = &get_users_function() if (!$function);
6728: my $img = &designparm($function.'.img', $domain);
6729: my $tabbg = &designparm($function.'.tabbg', $domain);
6730: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6731: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6732: #second colour for later usage
1.345 albertel 6733: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6734: my $pgbg_or_bgcolor =
6735: $bgcolor ||
1.352 albertel 6736: &designparm($function.'.pgbg', $domain);
1.382 albertel 6737: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6738: my $alink = &designparm($function.'.alink', $domain);
6739: my $vlink = &designparm($function.'.vlink', $domain);
6740: my $link = &designparm($function.'.link', $domain);
6741:
1.602 albertel 6742: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6743: my $mono = 'monospace';
1.850 bisitz 6744: my $data_table_head = $sidebg;
6745: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6746: my $data_table_dark = '#E0E0E0';
1.470 banghart 6747: my $data_table_darker = '#CCCCCC';
1.349 albertel 6748: my $data_table_highlight = '#FFFF00';
1.352 albertel 6749: my $mail_new = '#FFBB77';
6750: my $mail_new_hover = '#DD9955';
6751: my $mail_read = '#BBBB77';
6752: my $mail_read_hover = '#999944';
6753: my $mail_replied = '#AAAA88';
6754: my $mail_replied_hover = '#888855';
6755: my $mail_other = '#99BBBB';
6756: my $mail_other_hover = '#669999';
1.391 albertel 6757: my $table_header = '#DDDDDD';
1.489 raeburn 6758: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6759: my $lg_border_color = '#C8C8C8';
1.952 onken 6760: my $button_hover = '#BF2317';
1.392 albertel 6761:
1.608 albertel 6762: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6763: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6764: : '0 3px 0 4px';
1.448 albertel 6765:
1.523 albertel 6766:
1.343 albertel 6767: return <<END;
1.947 droeschl 6768:
6769: /* needed for iframe to allow 100% height in FF */
6770: body, html {
6771: margin: 0;
6772: padding: 0 0.5%;
6773: height: 99%; /* to avoid scrollbars */
6774: }
6775:
1.795 www 6776: body {
1.911 bisitz 6777: font-family: $sans;
6778: line-height:130%;
6779: font-size:0.83em;
6780: color:$font;
1.795 www 6781: }
6782:
1.959 onken 6783: a:focus,
6784: a:focus img {
1.795 www 6785: color: red;
6786: }
1.698 harmsja 6787:
1.911 bisitz 6788: form, .inline {
6789: display: inline;
1.795 www 6790: }
1.721 harmsja 6791:
1.1075.2.161. .21(raeb 6792:-24): .LC_menus_content.shown{
.24(raeb 6793:-24): display: block;
.21(raeb 6794:-24): }
6795:-24):
6796:-24): .LC_menus_content.hidden {
6797:-24): display: none;
6798:-24): }
6799:-24):
1.795 www 6800: .LC_right {
1.911 bisitz 6801: text-align:right;
1.795 www 6802: }
6803:
6804: .LC_middle {
1.911 bisitz 6805: vertical-align:middle;
1.795 www 6806: }
1.721 harmsja 6807:
1.1075.2.38 raeburn 6808: .LC_floatleft {
6809: float: left;
6810: }
6811:
6812: .LC_floatright {
6813: float: right;
6814: }
6815:
1.911 bisitz 6816: .LC_400Box {
6817: width:400px;
6818: }
1.721 harmsja 6819:
1.1075.2.161. .21(raeb 6820:-24): #LC_collapsible_separator {
6821:-24): border: 1px solid black;
6822:-24): width: 99.9%;
6823:-24): height: 0px;
6824:-24): }
6825:-24):
1.947 droeschl 6826: .LC_iframecontainer {
6827: width: 98%;
6828: margin: 0;
6829: position: fixed;
6830: top: 8.5em;
6831: bottom: 0;
6832: }
6833:
6834: .LC_iframecontainer iframe{
6835: border: none;
6836: width: 100%;
6837: height: 100%;
6838: }
6839:
1.778 bisitz 6840: .LC_filename {
6841: font-family: $mono;
6842: white-space:pre;
1.921 bisitz 6843: font-size: 120%;
1.778 bisitz 6844: }
6845:
6846: .LC_fileicon {
6847: border: none;
6848: height: 1.3em;
6849: vertical-align: text-bottom;
6850: margin-right: 0.3em;
6851: text-decoration:none;
6852: }
6853:
1.1008 www 6854: .LC_setting {
6855: text-decoration:underline;
6856: }
6857:
1.350 albertel 6858: .LC_error {
6859: color: red;
6860: }
1.795 www 6861:
1.1075.2.15 raeburn 6862: .LC_warning {
6863: color: darkorange;
6864: }
6865:
1.457 albertel 6866: .LC_diff_removed {
1.733 bisitz 6867: color: red;
1.394 albertel 6868: }
1.532 albertel 6869:
6870: .LC_info,
1.457 albertel 6871: .LC_success,
6872: .LC_diff_added {
1.350 albertel 6873: color: green;
6874: }
1.795 www 6875:
1.802 bisitz 6876: div.LC_confirm_box {
6877: background-color: #FAFAFA;
6878: border: 1px solid $lg_border_color;
6879: margin-right: 0;
6880: padding: 5px;
6881: }
6882:
6883: div.LC_confirm_box .LC_error img,
6884: div.LC_confirm_box .LC_success img {
6885: vertical-align: middle;
6886: }
6887:
1.1075.2.108 raeburn 6888: .LC_maxwidth {
6889: max-width: 100%;
6890: height: auto;
6891: }
6892:
6893: .LC_textsize_mobile {
6894: \@media only screen and (max-device-width: 480px) {
6895: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6896: }
6897: }
6898:
1.440 albertel 6899: .LC_icon {
1.771 droeschl 6900: border: none;
1.790 droeschl 6901: vertical-align: middle;
1.771 droeschl 6902: }
6903:
1.543 albertel 6904: .LC_docs_spacer {
6905: width: 25px;
6906: height: 1px;
1.771 droeschl 6907: border: none;
1.543 albertel 6908: }
1.346 albertel 6909:
1.532 albertel 6910: .LC_internal_info {
1.735 bisitz 6911: color: #999999;
1.532 albertel 6912: }
6913:
1.794 www 6914: .LC_discussion {
1.1050 www 6915: background: $data_table_dark;
1.911 bisitz 6916: border: 1px solid black;
6917: margin: 2px;
1.794 www 6918: }
6919:
6920: .LC_disc_action_left {
1.1050 www 6921: background: $sidebg;
1.911 bisitz 6922: text-align: left;
1.1050 www 6923: padding: 4px;
6924: margin: 2px;
1.794 www 6925: }
6926:
6927: .LC_disc_action_right {
1.1050 www 6928: background: $sidebg;
1.911 bisitz 6929: text-align: right;
1.1050 www 6930: padding: 4px;
6931: margin: 2px;
1.794 www 6932: }
6933:
6934: .LC_disc_new_item {
1.911 bisitz 6935: background: white;
6936: border: 2px solid red;
1.1050 www 6937: margin: 4px;
6938: padding: 4px;
1.794 www 6939: }
6940:
6941: .LC_disc_old_item {
1.911 bisitz 6942: background: white;
1.1050 www 6943: margin: 4px;
6944: padding: 4px;
1.794 www 6945: }
6946:
1.458 albertel 6947: table.LC_pastsubmission {
6948: border: 1px solid black;
6949: margin: 2px;
6950: }
6951:
1.924 bisitz 6952: table#LC_menubuttons {
1.345 albertel 6953: width: 100%;
6954: background: $pgbg;
1.392 albertel 6955: border: 2px;
1.402 albertel 6956: border-collapse: separate;
1.803 bisitz 6957: padding: 0;
1.345 albertel 6958: }
1.392 albertel 6959:
1.801 tempelho 6960: table#LC_title_bar a {
6961: color: $fontmenu;
6962: }
1.836 bisitz 6963:
1.807 droeschl 6964: table#LC_title_bar {
1.819 tempelho 6965: clear: both;
1.836 bisitz 6966: display: none;
1.807 droeschl 6967: }
6968:
1.795 www 6969: table#LC_title_bar,
1.933 droeschl 6970: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6971: table#LC_title_bar.LC_with_remote {
1.359 albertel 6972: width: 100%;
1.392 albertel 6973: border-color: $pgbg;
6974: border-style: solid;
6975: border-width: $border;
1.379 albertel 6976: background: $pgbg;
1.801 tempelho 6977: color: $fontmenu;
1.392 albertel 6978: border-collapse: collapse;
1.803 bisitz 6979: padding: 0;
1.819 tempelho 6980: margin: 0;
1.359 albertel 6981: }
1.795 www 6982:
1.933 droeschl 6983: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6984: margin: 0;
6985: padding: 0;
1.933 droeschl 6986: position: relative;
6987: list-style: none;
1.913 droeschl 6988: }
1.933 droeschl 6989: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6990: display: inline;
6991: }
1.933 droeschl 6992:
6993: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6994: padding: 0;
1.933 droeschl 6995: margin: 0;
6996: float: left;
1.913 droeschl 6997: }
1.933 droeschl 6998: .LC_breadcrumb_tools_tools {
6999: padding: 0;
7000: margin: 0;
1.913 droeschl 7001: float: right;
7002: }
7003:
1.359 albertel 7004: table#LC_title_bar td {
7005: background: $tabbg;
7006: }
1.795 www 7007:
1.911 bisitz 7008: table#LC_menubuttons img {
1.803 bisitz 7009: border: none;
1.346 albertel 7010: }
1.795 www 7011:
1.842 droeschl 7012: .LC_breadcrumbs_component {
1.911 bisitz 7013: float: right;
7014: margin: 0 1em;
1.357 albertel 7015: }
1.842 droeschl 7016: .LC_breadcrumbs_component img {
1.911 bisitz 7017: vertical-align: middle;
1.777 tempelho 7018: }
1.795 www 7019:
1.1075.2.108 raeburn 7020: .LC_breadcrumbs_hoverable {
7021: background: $sidebg;
7022: }
7023:
1.383 albertel 7024: td.LC_table_cell_checkbox {
7025: text-align: center;
7026: }
1.795 www 7027:
7028: .LC_fontsize_small {
1.911 bisitz 7029: font-size: 70%;
1.705 tempelho 7030: }
7031:
1.844 bisitz 7032: #LC_breadcrumbs {
1.911 bisitz 7033: clear:both;
7034: background: $sidebg;
7035: border-bottom: 1px solid $lg_border_color;
7036: line-height: 2.5em;
1.933 droeschl 7037: overflow: hidden;
1.911 bisitz 7038: margin: 0;
7039: padding: 0;
1.995 raeburn 7040: text-align: left;
1.819 tempelho 7041: }
1.862 bisitz 7042:
1.1075.2.16 raeburn 7043: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7044: clear:both;
7045: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7046: border: 1px solid $sidebg;
1.1075.2.16 raeburn 7047: margin: 0 0 10px 0;
1.966 bisitz 7048: padding: 3px;
1.995 raeburn 7049: text-align: left;
1.822 bisitz 7050: }
7051:
1.795 www 7052: .LC_fontsize_medium {
1.911 bisitz 7053: font-size: 85%;
1.705 tempelho 7054: }
7055:
1.795 www 7056: .LC_fontsize_large {
1.911 bisitz 7057: font-size: 120%;
1.705 tempelho 7058: }
7059:
1.346 albertel 7060: .LC_menubuttons_inline_text {
7061: color: $font;
1.698 harmsja 7062: font-size: 90%;
1.701 harmsja 7063: padding-left:3px;
1.346 albertel 7064: }
7065:
1.934 droeschl 7066: .LC_menubuttons_inline_text img{
7067: vertical-align: middle;
7068: }
7069:
1.1051 www 7070: li.LC_menubuttons_inline_text img {
1.951 onken 7071: cursor:pointer;
1.1002 droeschl 7072: text-decoration: none;
1.951 onken 7073: }
7074:
1.526 www 7075: .LC_menubuttons_link {
7076: text-decoration: none;
7077: }
1.795 www 7078:
1.522 albertel 7079: .LC_menubuttons_category {
1.521 www 7080: color: $font;
1.526 www 7081: background: $pgbg;
1.521 www 7082: font-size: larger;
7083: font-weight: bold;
7084: }
7085:
1.346 albertel 7086: td.LC_menubuttons_text {
1.911 bisitz 7087: color: $font;
1.346 albertel 7088: }
1.706 harmsja 7089:
1.346 albertel 7090: .LC_current_location {
7091: background: $tabbg;
7092: }
1.795 www 7093:
1.1075.2.134 raeburn 7094: td.LC_zero_height {
7095: line-height: 0;
7096: cellpadding: 0;
7097: }
7098:
1.938 bisitz 7099: table.LC_data_table {
1.347 albertel 7100: border: 1px solid #000000;
1.402 albertel 7101: border-collapse: separate;
1.426 albertel 7102: border-spacing: 1px;
1.610 albertel 7103: background: $pgbg;
1.347 albertel 7104: }
1.795 www 7105:
1.422 albertel 7106: .LC_data_table_dense {
7107: font-size: small;
7108: }
1.795 www 7109:
1.507 raeburn 7110: table.LC_nested_outer {
7111: border: 1px solid #000000;
1.589 raeburn 7112: border-collapse: collapse;
1.803 bisitz 7113: border-spacing: 0;
1.507 raeburn 7114: width: 100%;
7115: }
1.795 www 7116:
1.879 raeburn 7117: table.LC_innerpickbox,
1.507 raeburn 7118: table.LC_nested {
1.803 bisitz 7119: border: none;
1.589 raeburn 7120: border-collapse: collapse;
1.803 bisitz 7121: border-spacing: 0;
1.507 raeburn 7122: width: 100%;
7123: }
1.795 www 7124:
1.911 bisitz 7125: table.LC_data_table tr th,
7126: table.LC_calendar tr th,
1.879 raeburn 7127: table.LC_prior_tries tr th,
7128: table.LC_innerpickbox tr th {
1.349 albertel 7129: font-weight: bold;
7130: background-color: $data_table_head;
1.801 tempelho 7131: color:$fontmenu;
1.701 harmsja 7132: font-size:90%;
1.347 albertel 7133: }
1.795 www 7134:
1.879 raeburn 7135: table.LC_innerpickbox tr th,
7136: table.LC_innerpickbox tr td {
7137: vertical-align: top;
7138: }
7139:
1.711 raeburn 7140: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7141: background-color: #CCCCCC;
1.711 raeburn 7142: font-weight: bold;
7143: text-align: left;
7144: }
1.795 www 7145:
1.912 bisitz 7146: table.LC_data_table tr.LC_odd_row > td {
7147: background-color: $data_table_light;
7148: padding: 2px;
7149: vertical-align: top;
7150: }
7151:
1.809 bisitz 7152: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7153: background-color: $data_table_light;
1.912 bisitz 7154: vertical-align: top;
7155: }
7156:
7157: table.LC_data_table tr.LC_even_row > td {
7158: background-color: $data_table_dark;
1.425 albertel 7159: padding: 2px;
1.900 bisitz 7160: vertical-align: top;
1.347 albertel 7161: }
1.795 www 7162:
1.809 bisitz 7163: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7164: background-color: $data_table_dark;
1.900 bisitz 7165: vertical-align: top;
1.347 albertel 7166: }
1.795 www 7167:
1.425 albertel 7168: table.LC_data_table tr.LC_data_table_highlight td {
7169: background-color: $data_table_darker;
7170: }
1.795 www 7171:
1.639 raeburn 7172: table.LC_data_table tr td.LC_leftcol_header {
7173: background-color: $data_table_head;
7174: font-weight: bold;
7175: }
1.795 www 7176:
1.451 albertel 7177: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7178: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7179: font-weight: bold;
7180: font-style: italic;
7181: text-align: center;
7182: padding: 8px;
1.347 albertel 7183: }
1.795 www 7184:
1.1075.2.30 raeburn 7185: table.LC_data_table tr.LC_empty_row td,
7186: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7187: background-color: $sidebg;
7188: }
7189:
7190: table.LC_nested tr.LC_empty_row td {
7191: background-color: #FFFFFF;
7192: }
7193:
1.890 droeschl 7194: table.LC_caption {
7195: }
7196:
1.507 raeburn 7197: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7198: padding: 4ex
7199: }
1.795 www 7200:
1.507 raeburn 7201: table.LC_nested_outer tr th {
7202: font-weight: bold;
1.801 tempelho 7203: color:$fontmenu;
1.507 raeburn 7204: background-color: $data_table_head;
1.701 harmsja 7205: font-size: small;
1.507 raeburn 7206: border-bottom: 1px solid #000000;
7207: }
1.795 www 7208:
1.507 raeburn 7209: table.LC_nested_outer tr td.LC_subheader {
7210: background-color: $data_table_head;
7211: font-weight: bold;
7212: font-size: small;
7213: border-bottom: 1px solid #000000;
7214: text-align: right;
1.451 albertel 7215: }
1.795 www 7216:
1.507 raeburn 7217: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7218: background-color: #CCCCCC;
1.451 albertel 7219: font-weight: bold;
7220: font-size: small;
1.507 raeburn 7221: text-align: center;
7222: }
1.795 www 7223:
1.589 raeburn 7224: table.LC_nested tr.LC_info_row td.LC_left_item,
7225: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7226: text-align: left;
1.451 albertel 7227: }
1.795 www 7228:
1.507 raeburn 7229: table.LC_nested td {
1.735 bisitz 7230: background-color: #FFFFFF;
1.451 albertel 7231: font-size: small;
1.507 raeburn 7232: }
1.795 www 7233:
1.507 raeburn 7234: table.LC_nested_outer tr th.LC_right_item,
7235: table.LC_nested tr.LC_info_row td.LC_right_item,
7236: table.LC_nested tr.LC_odd_row td.LC_right_item,
7237: table.LC_nested tr td.LC_right_item {
1.451 albertel 7238: text-align: right;
7239: }
7240:
1.507 raeburn 7241: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7242: background-color: #EEEEEE;
1.451 albertel 7243: }
7244:
1.473 raeburn 7245: table.LC_createuser {
7246: }
7247:
7248: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7249: font-size: small;
1.473 raeburn 7250: }
7251:
7252: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7253: background-color: #CCCCCC;
1.473 raeburn 7254: font-weight: bold;
7255: text-align: center;
7256: }
7257:
1.349 albertel 7258: table.LC_calendar {
7259: border: 1px solid #000000;
7260: border-collapse: collapse;
1.917 raeburn 7261: width: 98%;
1.349 albertel 7262: }
1.795 www 7263:
1.349 albertel 7264: table.LC_calendar_pickdate {
7265: font-size: xx-small;
7266: }
1.795 www 7267:
1.349 albertel 7268: table.LC_calendar tr td {
7269: border: 1px solid #000000;
7270: vertical-align: top;
1.917 raeburn 7271: width: 14%;
1.349 albertel 7272: }
1.795 www 7273:
1.349 albertel 7274: table.LC_calendar tr td.LC_calendar_day_empty {
7275: background-color: $data_table_dark;
7276: }
1.795 www 7277:
1.779 bisitz 7278: table.LC_calendar tr td.LC_calendar_day_current {
7279: background-color: $data_table_highlight;
1.777 tempelho 7280: }
1.795 www 7281:
1.938 bisitz 7282: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7283: background-color: $mail_new;
7284: }
1.795 www 7285:
1.938 bisitz 7286: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7287: background-color: $mail_new_hover;
7288: }
1.795 www 7289:
1.938 bisitz 7290: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7291: background-color: $mail_read;
7292: }
1.795 www 7293:
1.938 bisitz 7294: /*
7295: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7296: background-color: $mail_read_hover;
7297: }
1.938 bisitz 7298: */
1.795 www 7299:
1.938 bisitz 7300: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7301: background-color: $mail_replied;
7302: }
1.795 www 7303:
1.938 bisitz 7304: /*
7305: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7306: background-color: $mail_replied_hover;
7307: }
1.938 bisitz 7308: */
1.795 www 7309:
1.938 bisitz 7310: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7311: background-color: $mail_other;
7312: }
1.795 www 7313:
1.938 bisitz 7314: /*
7315: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7316: background-color: $mail_other_hover;
7317: }
1.938 bisitz 7318: */
1.494 raeburn 7319:
1.777 tempelho 7320: table.LC_data_table tr > td.LC_browser_file,
7321: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7322: background: #AAEE77;
1.389 albertel 7323: }
1.795 www 7324:
1.777 tempelho 7325: table.LC_data_table tr > td.LC_browser_file_locked,
7326: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7327: background: #FFAA99;
1.387 albertel 7328: }
1.795 www 7329:
1.777 tempelho 7330: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7331: background: #888888;
1.779 bisitz 7332: }
1.795 www 7333:
1.777 tempelho 7334: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7335: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7336: background: #F8F866;
1.777 tempelho 7337: }
1.795 www 7338:
1.696 bisitz 7339: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7340: background: #E0E8FF;
1.387 albertel 7341: }
1.696 bisitz 7342:
1.707 bisitz 7343: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7344: /* background: #77FF77; */
1.707 bisitz 7345: }
1.795 www 7346:
1.707 bisitz 7347: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7348: border-right: 8px solid #FFFF77;
1.707 bisitz 7349: }
1.795 www 7350:
1.707 bisitz 7351: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7352: border-right: 8px solid #FFAA77;
1.707 bisitz 7353: }
1.795 www 7354:
1.707 bisitz 7355: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7356: border-right: 8px solid #FF7777;
1.707 bisitz 7357: }
1.795 www 7358:
1.707 bisitz 7359: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7360: border-right: 8px solid #AAFF77;
1.707 bisitz 7361: }
1.795 www 7362:
1.707 bisitz 7363: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7364: border-right: 8px solid #11CC55;
1.707 bisitz 7365: }
7366:
1.388 albertel 7367: span.LC_current_location {
1.701 harmsja 7368: font-size:larger;
1.388 albertel 7369: background: $pgbg;
7370: }
1.387 albertel 7371:
1.1029 www 7372: span.LC_current_nav_location {
7373: font-weight:bold;
7374: background: $sidebg;
7375: }
7376:
1.395 albertel 7377: span.LC_parm_menu_item {
7378: font-size: larger;
7379: }
1.795 www 7380:
1.395 albertel 7381: span.LC_parm_scope_all {
7382: color: red;
7383: }
1.795 www 7384:
1.395 albertel 7385: span.LC_parm_scope_folder {
7386: color: green;
7387: }
1.795 www 7388:
1.395 albertel 7389: span.LC_parm_scope_resource {
7390: color: orange;
7391: }
1.795 www 7392:
1.395 albertel 7393: span.LC_parm_part {
7394: color: blue;
7395: }
1.795 www 7396:
1.911 bisitz 7397: span.LC_parm_folder,
7398: span.LC_parm_symb {
1.395 albertel 7399: font-size: x-small;
7400: font-family: $mono;
7401: color: #AAAAAA;
7402: }
7403:
1.977 bisitz 7404: ul.LC_parm_parmlist li {
7405: display: inline-block;
7406: padding: 0.3em 0.8em;
7407: vertical-align: top;
7408: width: 150px;
7409: border-top:1px solid $lg_border_color;
7410: }
7411:
1.795 www 7412: td.LC_parm_overview_level_menu,
7413: td.LC_parm_overview_map_menu,
7414: td.LC_parm_overview_parm_selectors,
7415: td.LC_parm_overview_restrictions {
1.396 albertel 7416: border: 1px solid black;
7417: border-collapse: collapse;
7418: }
1.795 www 7419:
1.396 albertel 7420: table.LC_parm_overview_restrictions td {
7421: border-width: 1px 4px 1px 4px;
7422: border-style: solid;
7423: border-color: $pgbg;
7424: text-align: center;
7425: }
1.795 www 7426:
1.396 albertel 7427: table.LC_parm_overview_restrictions th {
7428: background: $tabbg;
7429: border-width: 1px 4px 1px 4px;
7430: border-style: solid;
7431: border-color: $pgbg;
7432: }
1.795 www 7433:
1.398 albertel 7434: table#LC_helpmenu {
1.803 bisitz 7435: border: none;
1.398 albertel 7436: height: 55px;
1.803 bisitz 7437: border-spacing: 0;
1.398 albertel 7438: }
7439:
7440: table#LC_helpmenu fieldset legend {
7441: font-size: larger;
7442: }
1.795 www 7443:
1.397 albertel 7444: table#LC_helpmenu_links {
7445: width: 100%;
7446: border: 1px solid black;
7447: background: $pgbg;
1.803 bisitz 7448: padding: 0;
1.397 albertel 7449: border-spacing: 1px;
7450: }
1.795 www 7451:
1.397 albertel 7452: table#LC_helpmenu_links tr td {
7453: padding: 1px;
7454: background: $tabbg;
1.399 albertel 7455: text-align: center;
7456: font-weight: bold;
1.397 albertel 7457: }
1.396 albertel 7458:
1.795 www 7459: table#LC_helpmenu_links a:link,
7460: table#LC_helpmenu_links a:visited,
1.397 albertel 7461: table#LC_helpmenu_links a:active {
7462: text-decoration: none;
7463: color: $font;
7464: }
1.795 www 7465:
1.397 albertel 7466: table#LC_helpmenu_links a:hover {
7467: text-decoration: underline;
7468: color: $vlink;
7469: }
1.396 albertel 7470:
1.417 albertel 7471: .LC_chrt_popup_exists {
7472: border: 1px solid #339933;
7473: margin: -1px;
7474: }
1.795 www 7475:
1.417 albertel 7476: .LC_chrt_popup_up {
7477: border: 1px solid yellow;
7478: margin: -1px;
7479: }
1.795 www 7480:
1.417 albertel 7481: .LC_chrt_popup {
7482: border: 1px solid #8888FF;
7483: background: #CCCCFF;
7484: }
1.795 www 7485:
1.421 albertel 7486: table.LC_pick_box {
7487: border-collapse: separate;
7488: background: white;
7489: border: 1px solid black;
7490: border-spacing: 1px;
7491: }
1.795 www 7492:
1.421 albertel 7493: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7494: background: $sidebg;
1.421 albertel 7495: font-weight: bold;
1.900 bisitz 7496: text-align: left;
1.740 bisitz 7497: vertical-align: top;
1.421 albertel 7498: width: 184px;
7499: padding: 8px;
7500: }
1.795 www 7501:
1.579 raeburn 7502: table.LC_pick_box td.LC_pick_box_value {
7503: text-align: left;
7504: padding: 8px;
7505: }
1.795 www 7506:
1.579 raeburn 7507: table.LC_pick_box td.LC_pick_box_select {
7508: text-align: left;
7509: padding: 8px;
7510: }
1.795 www 7511:
1.424 albertel 7512: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7513: padding: 0;
1.421 albertel 7514: height: 1px;
7515: background: black;
7516: }
1.795 www 7517:
1.421 albertel 7518: table.LC_pick_box td.LC_pick_box_submit {
7519: text-align: right;
7520: }
1.795 www 7521:
1.579 raeburn 7522: table.LC_pick_box td.LC_evenrow_value {
7523: text-align: left;
7524: padding: 8px;
7525: background-color: $data_table_light;
7526: }
1.795 www 7527:
1.579 raeburn 7528: table.LC_pick_box td.LC_oddrow_value {
7529: text-align: left;
7530: padding: 8px;
7531: background-color: $data_table_light;
7532: }
1.795 www 7533:
1.579 raeburn 7534: span.LC_helpform_receipt_cat {
7535: font-weight: bold;
7536: }
1.795 www 7537:
1.424 albertel 7538: table.LC_group_priv_box {
7539: background: white;
7540: border: 1px solid black;
7541: border-spacing: 1px;
7542: }
1.795 www 7543:
1.424 albertel 7544: table.LC_group_priv_box td.LC_pick_box_title {
7545: background: $tabbg;
7546: font-weight: bold;
7547: text-align: right;
7548: width: 184px;
7549: }
1.795 www 7550:
1.424 albertel 7551: table.LC_group_priv_box td.LC_groups_fixed {
7552: background: $data_table_light;
7553: text-align: center;
7554: }
1.795 www 7555:
1.424 albertel 7556: table.LC_group_priv_box td.LC_groups_optional {
7557: background: $data_table_dark;
7558: text-align: center;
7559: }
1.795 www 7560:
1.424 albertel 7561: table.LC_group_priv_box td.LC_groups_functionality {
7562: background: $data_table_darker;
7563: text-align: center;
7564: font-weight: bold;
7565: }
1.795 www 7566:
1.424 albertel 7567: table.LC_group_priv td {
7568: text-align: left;
1.803 bisitz 7569: padding: 0;
1.424 albertel 7570: }
7571:
7572: .LC_navbuttons {
7573: margin: 2ex 0ex 2ex 0ex;
7574: }
1.795 www 7575:
1.423 albertel 7576: .LC_topic_bar {
7577: font-weight: bold;
7578: background: $tabbg;
1.918 wenzelju 7579: margin: 1em 0em 1em 2em;
1.805 bisitz 7580: padding: 3px;
1.918 wenzelju 7581: font-size: 1.2em;
1.423 albertel 7582: }
1.795 www 7583:
1.423 albertel 7584: .LC_topic_bar span {
1.918 wenzelju 7585: left: 0.5em;
7586: position: absolute;
1.423 albertel 7587: vertical-align: middle;
1.918 wenzelju 7588: font-size: 1.2em;
1.423 albertel 7589: }
1.795 www 7590:
1.423 albertel 7591: table.LC_course_group_status {
7592: margin: 20px;
7593: }
1.795 www 7594:
1.423 albertel 7595: table.LC_status_selector td {
7596: vertical-align: top;
7597: text-align: center;
1.424 albertel 7598: padding: 4px;
7599: }
1.795 www 7600:
1.599 albertel 7601: div.LC_feedback_link {
1.616 albertel 7602: clear: both;
1.829 kalberla 7603: background: $sidebg;
1.779 bisitz 7604: width: 100%;
1.829 kalberla 7605: padding-bottom: 10px;
7606: border: 1px $tabbg solid;
1.833 kalberla 7607: height: 22px;
7608: line-height: 22px;
7609: padding-top: 5px;
7610: }
7611:
7612: div.LC_feedback_link img {
7613: height: 22px;
1.867 kalberla 7614: vertical-align:middle;
1.829 kalberla 7615: }
7616:
1.911 bisitz 7617: div.LC_feedback_link a {
1.829 kalberla 7618: text-decoration: none;
1.489 raeburn 7619: }
1.795 www 7620:
1.867 kalberla 7621: div.LC_comblock {
1.911 bisitz 7622: display:inline;
1.867 kalberla 7623: color:$font;
7624: font-size:90%;
7625: }
7626:
7627: div.LC_feedback_link div.LC_comblock {
7628: padding-left:5px;
7629: }
7630:
7631: div.LC_feedback_link div.LC_comblock a {
7632: color:$font;
7633: }
7634:
1.489 raeburn 7635: span.LC_feedback_link {
1.858 bisitz 7636: /* background: $feedback_link_bg; */
1.599 albertel 7637: font-size: larger;
7638: }
1.795 www 7639:
1.599 albertel 7640: span.LC_message_link {
1.858 bisitz 7641: /* background: $feedback_link_bg; */
1.599 albertel 7642: font-size: larger;
7643: position: absolute;
7644: right: 1em;
1.489 raeburn 7645: }
1.421 albertel 7646:
1.515 albertel 7647: table.LC_prior_tries {
1.524 albertel 7648: border: 1px solid #000000;
7649: border-collapse: separate;
7650: border-spacing: 1px;
1.515 albertel 7651: }
1.523 albertel 7652:
1.515 albertel 7653: table.LC_prior_tries td {
1.524 albertel 7654: padding: 2px;
1.515 albertel 7655: }
1.523 albertel 7656:
7657: .LC_answer_correct {
1.795 www 7658: background: lightgreen;
7659: color: darkgreen;
7660: padding: 6px;
1.523 albertel 7661: }
1.795 www 7662:
1.523 albertel 7663: .LC_answer_charged_try {
1.797 www 7664: background: #FFAAAA;
1.795 www 7665: color: darkred;
7666: padding: 6px;
1.523 albertel 7667: }
1.795 www 7668:
1.779 bisitz 7669: .LC_answer_not_charged_try,
1.523 albertel 7670: .LC_answer_no_grade,
7671: .LC_answer_late {
1.795 www 7672: background: lightyellow;
1.523 albertel 7673: color: black;
1.795 www 7674: padding: 6px;
1.523 albertel 7675: }
1.795 www 7676:
1.523 albertel 7677: .LC_answer_previous {
1.795 www 7678: background: lightblue;
7679: color: darkblue;
7680: padding: 6px;
1.523 albertel 7681: }
1.795 www 7682:
1.779 bisitz 7683: .LC_answer_no_message {
1.777 tempelho 7684: background: #FFFFFF;
7685: color: black;
1.795 www 7686: padding: 6px;
1.779 bisitz 7687: }
1.795 www 7688:
1.1075.2.140 raeburn 7689: .LC_answer_unknown,
7690: .LC_answer_warning {
1.779 bisitz 7691: background: orange;
7692: color: black;
1.795 www 7693: padding: 6px;
1.777 tempelho 7694: }
1.795 www 7695:
1.529 albertel 7696: span.LC_prior_numerical,
7697: span.LC_prior_string,
7698: span.LC_prior_custom,
7699: span.LC_prior_reaction,
7700: span.LC_prior_math {
1.925 bisitz 7701: font-family: $mono;
1.523 albertel 7702: white-space: pre;
7703: }
7704:
1.525 albertel 7705: span.LC_prior_string {
1.925 bisitz 7706: font-family: $mono;
1.525 albertel 7707: white-space: pre;
7708: }
7709:
1.523 albertel 7710: table.LC_prior_option {
7711: width: 100%;
7712: border-collapse: collapse;
7713: }
1.795 www 7714:
1.911 bisitz 7715: table.LC_prior_rank,
1.795 www 7716: table.LC_prior_match {
1.528 albertel 7717: border-collapse: collapse;
7718: }
1.795 www 7719:
1.528 albertel 7720: table.LC_prior_option tr td,
7721: table.LC_prior_rank tr td,
7722: table.LC_prior_match tr td {
1.524 albertel 7723: border: 1px solid #000000;
1.515 albertel 7724: }
7725:
1.855 bisitz 7726: .LC_nobreak {
1.544 albertel 7727: white-space: nowrap;
1.519 raeburn 7728: }
7729:
1.576 raeburn 7730: span.LC_cusr_emph {
7731: font-style: italic;
7732: }
7733:
1.633 raeburn 7734: span.LC_cusr_subheading {
7735: font-weight: normal;
7736: font-size: 85%;
7737: }
7738:
1.861 bisitz 7739: div.LC_docs_entry_move {
1.859 bisitz 7740: border: 1px solid #BBBBBB;
1.545 albertel 7741: background: #DDDDDD;
1.861 bisitz 7742: width: 22px;
1.859 bisitz 7743: padding: 1px;
7744: margin: 0;
1.545 albertel 7745: }
7746:
1.861 bisitz 7747: table.LC_data_table tr > td.LC_docs_entry_commands,
7748: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7749: font-size: x-small;
7750: }
1.795 www 7751:
1.861 bisitz 7752: .LC_docs_entry_parameter {
7753: white-space: nowrap;
7754: }
7755:
1.544 albertel 7756: .LC_docs_copy {
1.545 albertel 7757: color: #000099;
1.544 albertel 7758: }
1.795 www 7759:
1.544 albertel 7760: .LC_docs_cut {
1.545 albertel 7761: color: #550044;
1.544 albertel 7762: }
1.795 www 7763:
1.544 albertel 7764: .LC_docs_rename {
1.545 albertel 7765: color: #009900;
1.544 albertel 7766: }
1.795 www 7767:
1.544 albertel 7768: .LC_docs_remove {
1.545 albertel 7769: color: #990000;
7770: }
7771:
1.1075.2.134 raeburn 7772: .LC_domprefs_email,
1.547 albertel 7773: .LC_docs_reinit_warn,
7774: .LC_docs_ext_edit {
7775: font-size: x-small;
7776: }
7777:
1.545 albertel 7778: table.LC_docs_adddocs td,
7779: table.LC_docs_adddocs th {
7780: border: 1px solid #BBBBBB;
7781: padding: 4px;
7782: background: #DDDDDD;
1.543 albertel 7783: }
7784:
1.584 albertel 7785: table.LC_sty_begin {
7786: background: #BBFFBB;
7787: }
1.795 www 7788:
1.584 albertel 7789: table.LC_sty_end {
7790: background: #FFBBBB;
7791: }
7792:
1.589 raeburn 7793: table.LC_double_column {
1.803 bisitz 7794: border-width: 0;
1.589 raeburn 7795: border-collapse: collapse;
7796: width: 100%;
7797: padding: 2px;
7798: }
7799:
7800: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7801: top: 2px;
1.589 raeburn 7802: left: 2px;
7803: width: 47%;
7804: vertical-align: top;
7805: }
7806:
7807: table.LC_double_column tr td.LC_right_col {
7808: top: 2px;
1.779 bisitz 7809: right: 2px;
1.589 raeburn 7810: width: 47%;
7811: vertical-align: top;
7812: }
7813:
1.591 raeburn 7814: div.LC_left_float {
7815: float: left;
7816: padding-right: 5%;
1.597 albertel 7817: padding-bottom: 4px;
1.591 raeburn 7818: }
7819:
7820: div.LC_clear_float_header {
1.597 albertel 7821: padding-bottom: 2px;
1.591 raeburn 7822: }
7823:
7824: div.LC_clear_float_footer {
1.597 albertel 7825: padding-top: 10px;
1.591 raeburn 7826: clear: both;
7827: }
7828:
1.597 albertel 7829: div.LC_grade_show_user {
1.941 bisitz 7830: /* border-left: 5px solid $sidebg; */
7831: border-top: 5px solid #000000;
7832: margin: 50px 0 0 0;
1.936 bisitz 7833: padding: 15px 0 5px 10px;
1.597 albertel 7834: }
1.795 www 7835:
1.936 bisitz 7836: div.LC_grade_show_user_odd_row {
1.941 bisitz 7837: /* border-left: 5px solid #000000; */
7838: }
7839:
7840: div.LC_grade_show_user div.LC_Box {
7841: margin-right: 50px;
1.597 albertel 7842: }
7843:
7844: div.LC_grade_submissions,
7845: div.LC_grade_message_center,
1.936 bisitz 7846: div.LC_grade_info_links {
1.597 albertel 7847: margin: 5px;
7848: width: 99%;
7849: background: #FFFFFF;
7850: }
1.795 www 7851:
1.597 albertel 7852: div.LC_grade_submissions_header,
1.936 bisitz 7853: div.LC_grade_message_center_header {
1.705 tempelho 7854: font-weight: bold;
7855: font-size: large;
1.597 albertel 7856: }
1.795 www 7857:
1.597 albertel 7858: div.LC_grade_submissions_body,
1.936 bisitz 7859: div.LC_grade_message_center_body {
1.597 albertel 7860: border: 1px solid black;
7861: width: 99%;
7862: background: #FFFFFF;
7863: }
1.795 www 7864:
1.613 albertel 7865: table.LC_scantron_action {
7866: width: 100%;
7867: }
1.795 www 7868:
1.613 albertel 7869: table.LC_scantron_action tr th {
1.698 harmsja 7870: font-weight:bold;
7871: font-style:normal;
1.613 albertel 7872: }
1.795 www 7873:
1.779 bisitz 7874: .LC_edit_problem_header,
1.614 albertel 7875: div.LC_edit_problem_footer {
1.705 tempelho 7876: font-weight: normal;
7877: font-size: medium;
1.602 albertel 7878: margin: 2px;
1.1060 bisitz 7879: background-color: $sidebg;
1.600 albertel 7880: }
1.795 www 7881:
1.600 albertel 7882: div.LC_edit_problem_header,
1.602 albertel 7883: div.LC_edit_problem_header div,
1.614 albertel 7884: div.LC_edit_problem_footer,
7885: div.LC_edit_problem_footer div,
1.602 albertel 7886: div.LC_edit_problem_editxml_header,
7887: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7888: z-index: 100;
1.600 albertel 7889: }
1.795 www 7890:
1.600 albertel 7891: div.LC_edit_problem_header_title {
1.705 tempelho 7892: font-weight: bold;
7893: font-size: larger;
1.602 albertel 7894: background: $tabbg;
7895: padding: 3px;
1.1060 bisitz 7896: margin: 0 0 5px 0;
1.602 albertel 7897: }
1.795 www 7898:
1.602 albertel 7899: table.LC_edit_problem_header_title {
7900: width: 100%;
1.600 albertel 7901: background: $tabbg;
1.602 albertel 7902: }
7903:
1.1075.2.112 raeburn 7904: div.LC_edit_actionbar {
7905: background-color: $sidebg;
7906: margin: 0;
7907: padding: 0;
7908: line-height: 200%;
1.602 albertel 7909: }
1.795 www 7910:
1.1075.2.112 raeburn 7911: div.LC_edit_actionbar div{
7912: padding: 0;
7913: margin: 0;
7914: display: inline-block;
1.600 albertel 7915: }
1.795 www 7916:
1.1075.2.34 raeburn 7917: .LC_edit_opt {
7918: padding-left: 1em;
7919: white-space: nowrap;
7920: }
7921:
1.1075.2.57 raeburn 7922: .LC_edit_problem_latexhelper{
7923: text-align: right;
7924: }
7925:
7926: #LC_edit_problem_colorful div{
7927: margin-left: 40px;
7928: }
7929:
1.1075.2.112 raeburn 7930: #LC_edit_problem_codemirror div{
7931: margin-left: 0px;
7932: }
7933:
1.911 bisitz 7934: img.stift {
1.803 bisitz 7935: border-width: 0;
7936: vertical-align: middle;
1.677 riegler 7937: }
1.680 riegler 7938:
1.923 bisitz 7939: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7940: vertical-align: top;
1.777 tempelho 7941: }
1.795 www 7942:
1.716 raeburn 7943: div.LC_createcourse {
1.911 bisitz 7944: margin: 10px 10px 10px 10px;
1.716 raeburn 7945: }
7946:
1.917 raeburn 7947: .LC_dccid {
1.1075.2.38 raeburn 7948: float: right;
1.917 raeburn 7949: margin: 0.2em 0 0 0;
7950: padding: 0;
7951: font-size: 90%;
7952: display:none;
7953: }
7954:
1.897 wenzelju 7955: ol.LC_primary_menu a:hover,
1.721 harmsja 7956: ol#LC_MenuBreadcrumbs a:hover,
7957: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7958: ul#LC_secondary_menu a:hover,
1.721 harmsja 7959: .LC_FormSectionClearButton input:hover
1.795 www 7960: ul.LC_TabContent li:hover a {
1.952 onken 7961: color:$button_hover;
1.911 bisitz 7962: text-decoration:none;
1.693 droeschl 7963: }
7964:
1.779 bisitz 7965: h1 {
1.911 bisitz 7966: padding: 0;
7967: line-height:130%;
1.693 droeschl 7968: }
1.698 harmsja 7969:
1.911 bisitz 7970: h2,
7971: h3,
7972: h4,
7973: h5,
7974: h6 {
7975: margin: 5px 0 5px 0;
7976: padding: 0;
7977: line-height:130%;
1.693 droeschl 7978: }
1.795 www 7979:
7980: .LC_hcell {
1.911 bisitz 7981: padding:3px 15px 3px 15px;
7982: margin: 0;
7983: background-color:$tabbg;
7984: color:$fontmenu;
7985: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7986: }
1.795 www 7987:
1.840 bisitz 7988: .LC_Box > .LC_hcell {
1.911 bisitz 7989: margin: 0 -10px 10px -10px;
1.835 bisitz 7990: }
7991:
1.721 harmsja 7992: .LC_noBorder {
1.911 bisitz 7993: border: 0;
1.698 harmsja 7994: }
1.693 droeschl 7995:
1.721 harmsja 7996: .LC_FormSectionClearButton input {
1.911 bisitz 7997: background-color:transparent;
7998: border: none;
7999: cursor:pointer;
8000: text-decoration:underline;
1.693 droeschl 8001: }
1.763 bisitz 8002:
8003: .LC_help_open_topic {
1.911 bisitz 8004: color: #FFFFFF;
8005: background-color: #EEEEFF;
8006: margin: 1px;
8007: padding: 4px;
8008: border: 1px solid #000033;
8009: white-space: nowrap;
8010: /* vertical-align: middle; */
1.759 neumanie 8011: }
1.693 droeschl 8012:
1.911 bisitz 8013: dl,
8014: ul,
8015: div,
8016: fieldset {
8017: margin: 10px 10px 10px 0;
8018: /* overflow: hidden; */
1.693 droeschl 8019: }
1.795 www 8020:
1.1075.2.161. .18(raeb 8021:-23): fieldset#LC_selectuser {
8022:-23): margin: 0;
8023:-23): padding: 0;
8024:-23): }
8025:-23):
1.1075.2.90 raeburn 8026: article.geogebraweb div {
8027: margin: 0;
8028: }
8029:
1.838 bisitz 8030: fieldset > legend {
1.911 bisitz 8031: font-weight: bold;
8032: padding: 0 5px 0 5px;
1.838 bisitz 8033: }
8034:
1.813 bisitz 8035: #LC_nav_bar {
1.911 bisitz 8036: float: left;
1.995 raeburn 8037: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8038: margin: 0 0 2px 0;
1.807 droeschl 8039: }
8040:
1.916 droeschl 8041: #LC_realm {
8042: margin: 0.2em 0 0 0;
8043: padding: 0;
8044: font-weight: bold;
8045: text-align: center;
1.995 raeburn 8046: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8047: }
8048:
1.911 bisitz 8049: #LC_nav_bar em {
8050: font-weight: bold;
8051: font-style: normal;
1.807 droeschl 8052: }
8053:
1.897 wenzelju 8054: ol.LC_primary_menu {
1.934 droeschl 8055: margin: 0;
1.1075.2.2 raeburn 8056: padding: 0;
1.807 droeschl 8057: }
8058:
1.852 droeschl 8059: ol#LC_PathBreadcrumbs {
1.911 bisitz 8060: margin: 0;
1.693 droeschl 8061: }
8062:
1.897 wenzelju 8063: ol.LC_primary_menu li {
1.1075.2.2 raeburn 8064: color: RGB(80, 80, 80);
8065: vertical-align: middle;
8066: text-align: left;
8067: list-style: none;
1.1075.2.112 raeburn 8068: position: relative;
1.1075.2.2 raeburn 8069: float: left;
1.1075.2.112 raeburn 8070: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8071: line-height: 1.5em;
1.1075.2.2 raeburn 8072: }
8073:
1.1075.2.113 raeburn 8074: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 8075: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 8076: display: block;
8077: margin: 0;
8078: padding: 0 5px 0 10px;
8079: text-decoration: none;
8080: }
8081:
1.1075.2.112 raeburn 8082: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8083: display: inline-block;
8084: width: 95%;
8085: text-align: left;
8086: }
8087:
8088: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8089: display: inline-block;
8090: width: 5%;
8091: float: right;
8092: text-align: right;
8093: font-size: 70%;
8094: }
8095:
8096: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 8097: display: none;
1.1075.2.112 raeburn 8098: width: 15em;
1.1075.2.2 raeburn 8099: background-color: $data_table_light;
1.1075.2.112 raeburn 8100: position: absolute;
8101: top: 100%;
8102: }
8103:
8104: ol.LC_primary_menu ul ul {
8105: left: 100%;
8106: top: 0;
1.1075.2.2 raeburn 8107: }
8108:
1.1075.2.112 raeburn 8109: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 8110: display: block;
8111: position: absolute;
8112: margin: 0;
8113: padding: 0;
1.1075.2.5 raeburn 8114: z-index: 2;
1.1075.2.2 raeburn 8115: }
8116:
8117: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 8118: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 8119: font-size: 90%;
1.911 bisitz 8120: vertical-align: top;
1.1075.2.2 raeburn 8121: float: none;
1.1075.2.5 raeburn 8122: border-left: 1px solid black;
8123: border-right: 1px solid black;
1.1075.2.112 raeburn 8124: /* A dark bottom border to visualize different menu options;
8125: overwritten in the create_submenu routine for the last border-bottom of the menu */
8126: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 8127: }
8128:
1.1075.2.112 raeburn 8129: ol.LC_primary_menu li li p:hover {
8130: color:$button_hover;
8131: text-decoration:none;
8132: background-color:$data_table_dark;
1.1075.2.2 raeburn 8133: }
8134:
8135: ol.LC_primary_menu li li a:hover {
8136: color:$button_hover;
8137: background-color:$data_table_dark;
1.693 droeschl 8138: }
8139:
1.1075.2.112 raeburn 8140: /* Font-size equal to the size of the predecessors*/
8141: ol.LC_primary_menu li:hover li li {
8142: font-size: 100%;
8143: }
8144:
1.897 wenzelju 8145: ol.LC_primary_menu li img {
1.911 bisitz 8146: vertical-align: bottom;
1.934 droeschl 8147: height: 1.1em;
1.1075.2.3 raeburn 8148: margin: 0.2em 0 0 0;
1.693 droeschl 8149: }
8150:
1.897 wenzelju 8151: ol.LC_primary_menu a {
1.911 bisitz 8152: color: RGB(80, 80, 80);
8153: text-decoration: none;
1.693 droeschl 8154: }
1.795 www 8155:
1.949 droeschl 8156: ol.LC_primary_menu a.LC_new_message {
8157: font-weight:bold;
8158: color: darkred;
8159: }
8160:
1.975 raeburn 8161: ol.LC_docs_parameters {
8162: margin-left: 0;
8163: padding: 0;
8164: list-style: none;
8165: }
8166:
8167: ol.LC_docs_parameters li {
8168: margin: 0;
8169: padding-right: 20px;
8170: display: inline;
8171: }
8172:
1.976 raeburn 8173: ol.LC_docs_parameters li:before {
8174: content: "\\002022 \\0020";
8175: }
8176:
8177: li.LC_docs_parameters_title {
8178: font-weight: bold;
8179: }
8180:
8181: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8182: content: "";
8183: }
8184:
1.897 wenzelju 8185: ul#LC_secondary_menu {
1.1075.2.23 raeburn 8186: clear: right;
1.911 bisitz 8187: color: $fontmenu;
8188: background: $tabbg;
8189: list-style: none;
8190: padding: 0;
8191: margin: 0;
8192: width: 100%;
1.995 raeburn 8193: text-align: left;
1.1075.2.4 raeburn 8194: float: left;
1.808 droeschl 8195: }
8196:
1.897 wenzelju 8197: ul#LC_secondary_menu li {
1.911 bisitz 8198: font-weight: bold;
8199: line-height: 1.8em;
8200: border-right: 1px solid black;
1.1075.2.4 raeburn 8201: float: left;
8202: }
8203:
8204: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8205: background-color: $data_table_light;
8206: }
8207:
8208: ul#LC_secondary_menu li a {
8209: padding: 0 0.8em;
8210: }
8211:
8212: ul#LC_secondary_menu li ul {
8213: display: none;
8214: }
8215:
8216: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8217: display: block;
8218: position: absolute;
8219: margin: 0;
8220: padding: 0;
8221: list-style:none;
8222: float: none;
8223: background-color: $data_table_light;
1.1075.2.5 raeburn 8224: z-index: 2;
1.1075.2.10 raeburn 8225: margin-left: -1px;
1.1075.2.4 raeburn 8226: }
8227:
8228: ul#LC_secondary_menu li ul li {
8229: font-size: 90%;
8230: vertical-align: top;
8231: border-left: 1px solid black;
8232: border-right: 1px solid black;
1.1075.2.33 raeburn 8233: background-color: $data_table_light;
1.1075.2.4 raeburn 8234: list-style:none;
8235: float: none;
8236: }
8237:
8238: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8239: background-color: $data_table_dark;
1.807 droeschl 8240: }
8241:
1.847 tempelho 8242: ul.LC_TabContent {
1.911 bisitz 8243: display:block;
8244: background: $sidebg;
8245: border-bottom: solid 1px $lg_border_color;
8246: list-style:none;
1.1020 raeburn 8247: margin: -1px -10px 0 -10px;
1.911 bisitz 8248: padding: 0;
1.693 droeschl 8249: }
8250:
1.795 www 8251: ul.LC_TabContent li,
8252: ul.LC_TabContentBigger li {
1.911 bisitz 8253: float:left;
1.741 harmsja 8254: }
1.795 www 8255:
1.897 wenzelju 8256: ul#LC_secondary_menu li a {
1.911 bisitz 8257: color: $fontmenu;
8258: text-decoration: none;
1.693 droeschl 8259: }
1.795 www 8260:
1.721 harmsja 8261: ul.LC_TabContent {
1.952 onken 8262: min-height:20px;
1.721 harmsja 8263: }
1.795 www 8264:
8265: ul.LC_TabContent li {
1.911 bisitz 8266: vertical-align:middle;
1.959 onken 8267: padding: 0 16px 0 10px;
1.911 bisitz 8268: background-color:$tabbg;
8269: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8270: border-left: solid 1px $font;
1.721 harmsja 8271: }
1.795 www 8272:
1.847 tempelho 8273: ul.LC_TabContent .right {
1.911 bisitz 8274: float:right;
1.847 tempelho 8275: }
8276:
1.911 bisitz 8277: ul.LC_TabContent li a,
8278: ul.LC_TabContent li {
8279: color:rgb(47,47,47);
8280: text-decoration:none;
8281: font-size:95%;
8282: font-weight:bold;
1.952 onken 8283: min-height:20px;
8284: }
8285:
1.959 onken 8286: ul.LC_TabContent li a:hover,
8287: ul.LC_TabContent li a:focus {
1.952 onken 8288: color: $button_hover;
1.959 onken 8289: background:none;
8290: outline:none;
1.952 onken 8291: }
8292:
8293: ul.LC_TabContent li:hover {
8294: color: $button_hover;
8295: cursor:pointer;
1.721 harmsja 8296: }
1.795 www 8297:
1.911 bisitz 8298: ul.LC_TabContent li.active {
1.952 onken 8299: color: $font;
1.911 bisitz 8300: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8301: border-bottom:solid 1px #FFFFFF;
8302: cursor: default;
1.744 ehlerst 8303: }
1.795 www 8304:
1.959 onken 8305: ul.LC_TabContent li.active a {
8306: color:$font;
8307: background:#FFFFFF;
8308: outline: none;
8309: }
1.1047 raeburn 8310:
8311: ul.LC_TabContent li.goback {
8312: float: left;
8313: border-left: none;
8314: }
8315:
1.870 tempelho 8316: #maincoursedoc {
1.911 bisitz 8317: clear:both;
1.870 tempelho 8318: }
8319:
8320: ul.LC_TabContentBigger {
1.911 bisitz 8321: display:block;
8322: list-style:none;
8323: padding: 0;
1.870 tempelho 8324: }
8325:
1.795 www 8326: ul.LC_TabContentBigger li {
1.911 bisitz 8327: vertical-align:bottom;
8328: height: 30px;
8329: font-size:110%;
8330: font-weight:bold;
8331: color: #737373;
1.841 tempelho 8332: }
8333:
1.957 onken 8334: ul.LC_TabContentBigger li.active {
8335: position: relative;
8336: top: 1px;
8337: }
8338:
1.870 tempelho 8339: ul.LC_TabContentBigger li a {
1.911 bisitz 8340: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8341: height: 30px;
8342: line-height: 30px;
8343: text-align: center;
8344: display: block;
8345: text-decoration: none;
1.958 onken 8346: outline: none;
1.741 harmsja 8347: }
1.795 www 8348:
1.870 tempelho 8349: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8350: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8351: color:$font;
1.744 ehlerst 8352: }
1.795 www 8353:
1.870 tempelho 8354: ul.LC_TabContentBigger li b {
1.911 bisitz 8355: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8356: display: block;
8357: float: left;
8358: padding: 0 30px;
1.957 onken 8359: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8360: }
8361:
1.956 onken 8362: ul.LC_TabContentBigger li:hover b {
8363: color:$button_hover;
8364: }
8365:
1.870 tempelho 8366: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8367: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8368: color:$font;
1.957 onken 8369: border: 0;
1.741 harmsja 8370: }
1.693 droeschl 8371:
1.870 tempelho 8372:
1.862 bisitz 8373: ul.LC_CourseBreadcrumbs {
8374: background: $sidebg;
1.1020 raeburn 8375: height: 2em;
1.862 bisitz 8376: padding-left: 10px;
1.1020 raeburn 8377: margin: 0;
1.862 bisitz 8378: list-style-position: inside;
8379: }
8380:
1.911 bisitz 8381: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8382: ol#LC_PathBreadcrumbs {
1.911 bisitz 8383: padding-left: 10px;
8384: margin: 0;
1.933 droeschl 8385: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8386: }
8387:
1.911 bisitz 8388: ol#LC_MenuBreadcrumbs li,
8389: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8390: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8391: display: inline;
1.933 droeschl 8392: white-space: normal;
1.693 droeschl 8393: }
8394:
1.823 bisitz 8395: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8396: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8397: text-decoration: none;
8398: font-size:90%;
1.693 droeschl 8399: }
1.795 www 8400:
1.969 droeschl 8401: ol#LC_MenuBreadcrumbs h1 {
8402: display: inline;
8403: font-size: 90%;
8404: line-height: 2.5em;
8405: margin: 0;
8406: padding: 0;
8407: }
8408:
1.795 www 8409: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8410: text-decoration:none;
8411: font-size:100%;
8412: font-weight:bold;
1.693 droeschl 8413: }
1.795 www 8414:
1.840 bisitz 8415: .LC_Box {
1.911 bisitz 8416: border: solid 1px $lg_border_color;
8417: padding: 0 10px 10px 10px;
1.746 neumanie 8418: }
1.795 www 8419:
1.1020 raeburn 8420: .LC_DocsBox {
8421: border: solid 1px $lg_border_color;
8422: padding: 0 0 10px 10px;
8423: }
8424:
1.795 www 8425: .LC_AboutMe_Image {
1.911 bisitz 8426: float:left;
8427: margin-right:10px;
1.747 neumanie 8428: }
1.795 www 8429:
8430: .LC_Clear_AboutMe_Image {
1.911 bisitz 8431: clear:left;
1.747 neumanie 8432: }
1.795 www 8433:
1.721 harmsja 8434: dl.LC_ListStyleClean dt {
1.911 bisitz 8435: padding-right: 5px;
8436: display: table-header-group;
1.693 droeschl 8437: }
8438:
1.721 harmsja 8439: dl.LC_ListStyleClean dd {
1.911 bisitz 8440: display: table-row;
1.693 droeschl 8441: }
8442:
1.721 harmsja 8443: .LC_ListStyleClean,
8444: .LC_ListStyleSimple,
8445: .LC_ListStyleNormal,
1.795 www 8446: .LC_ListStyleSpecial {
1.911 bisitz 8447: /* display:block; */
8448: list-style-position: inside;
8449: list-style-type: none;
8450: overflow: hidden;
8451: padding: 0;
1.693 droeschl 8452: }
8453:
1.721 harmsja 8454: .LC_ListStyleSimple li,
8455: .LC_ListStyleSimple dd,
8456: .LC_ListStyleNormal li,
8457: .LC_ListStyleNormal dd,
8458: .LC_ListStyleSpecial li,
1.795 www 8459: .LC_ListStyleSpecial dd {
1.911 bisitz 8460: margin: 0;
8461: padding: 5px 5px 5px 10px;
8462: clear: both;
1.693 droeschl 8463: }
8464:
1.721 harmsja 8465: .LC_ListStyleClean li,
8466: .LC_ListStyleClean dd {
1.911 bisitz 8467: padding-top: 0;
8468: padding-bottom: 0;
1.693 droeschl 8469: }
8470:
1.721 harmsja 8471: .LC_ListStyleSimple dd,
1.795 www 8472: .LC_ListStyleSimple li {
1.911 bisitz 8473: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8474: }
8475:
1.721 harmsja 8476: .LC_ListStyleSpecial li,
8477: .LC_ListStyleSpecial dd {
1.911 bisitz 8478: list-style-type: none;
8479: background-color: RGB(220, 220, 220);
8480: margin-bottom: 4px;
1.693 droeschl 8481: }
8482:
1.721 harmsja 8483: table.LC_SimpleTable {
1.911 bisitz 8484: margin:5px;
8485: border:solid 1px $lg_border_color;
1.795 www 8486: }
1.693 droeschl 8487:
1.721 harmsja 8488: table.LC_SimpleTable tr {
1.911 bisitz 8489: padding: 0;
8490: border:solid 1px $lg_border_color;
1.693 droeschl 8491: }
1.795 www 8492:
8493: table.LC_SimpleTable thead {
1.911 bisitz 8494: background:rgb(220,220,220);
1.693 droeschl 8495: }
8496:
1.721 harmsja 8497: div.LC_columnSection {
1.911 bisitz 8498: display: block;
8499: clear: both;
8500: overflow: hidden;
8501: margin: 0;
1.693 droeschl 8502: }
8503:
1.721 harmsja 8504: div.LC_columnSection>* {
1.911 bisitz 8505: float: left;
8506: margin: 10px 20px 10px 0;
8507: overflow:hidden;
1.693 droeschl 8508: }
1.721 harmsja 8509:
1.795 www 8510: table em {
1.911 bisitz 8511: font-weight: bold;
8512: font-style: normal;
1.748 schulted 8513: }
1.795 www 8514:
1.779 bisitz 8515: table.LC_tableBrowseRes,
1.795 www 8516: table.LC_tableOfContent {
1.911 bisitz 8517: border:none;
8518: border-spacing: 1px;
8519: padding: 3px;
8520: background-color: #FFFFFF;
8521: font-size: 90%;
1.753 droeschl 8522: }
1.789 droeschl 8523:
1.911 bisitz 8524: table.LC_tableOfContent {
8525: border-collapse: collapse;
1.789 droeschl 8526: }
8527:
1.771 droeschl 8528: table.LC_tableBrowseRes a,
1.768 schulted 8529: table.LC_tableOfContent a {
1.911 bisitz 8530: background-color: transparent;
8531: text-decoration: none;
1.753 droeschl 8532: }
8533:
1.795 www 8534: table.LC_tableOfContent img {
1.911 bisitz 8535: border: none;
8536: height: 1.3em;
8537: vertical-align: text-bottom;
8538: margin-right: 0.3em;
1.753 droeschl 8539: }
1.757 schulted 8540:
1.795 www 8541: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8542: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8543: }
8544:
1.795 www 8545: a#LC_content_toolbar_everything {
1.911 bisitz 8546: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8547: }
8548:
1.795 www 8549: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8550: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8551: }
8552:
1.795 www 8553: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8554: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8555: }
8556:
1.795 www 8557: a#LC_content_toolbar_changefolder {
1.911 bisitz 8558: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8559: }
8560:
1.795 www 8561: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8562: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8563: }
8564:
1.1043 raeburn 8565: a#LC_content_toolbar_edittoplevel {
8566: background-image:url(/res/adm/pages/edittoplevel.gif);
8567: }
8568:
1.1075.2.161. .12(raeb 8569:-23): a#LC_content_toolbar_printout {
8570:-23): background-image:url(/res/adm/pages/printout.gif);
8571:-23): }
8572:-23):
1.795 www 8573: ul#LC_toolbar li a:hover {
1.911 bisitz 8574: background-position: bottom center;
1.757 schulted 8575: }
8576:
1.795 www 8577: ul#LC_toolbar {
1.911 bisitz 8578: padding: 0;
8579: margin: 2px;
8580: list-style:none;
8581: position:relative;
8582: background-color:white;
1.1075.2.9 raeburn 8583: overflow: auto;
1.757 schulted 8584: }
8585:
1.795 www 8586: ul#LC_toolbar li {
1.911 bisitz 8587: border:1px solid white;
8588: padding: 0;
8589: margin: 0;
8590: float: left;
8591: display:inline;
8592: vertical-align:middle;
1.1075.2.9 raeburn 8593: white-space: nowrap;
1.911 bisitz 8594: }
1.757 schulted 8595:
1.783 amueller 8596:
1.795 www 8597: a.LC_toolbarItem {
1.911 bisitz 8598: display:block;
8599: padding: 0;
8600: margin: 0;
8601: height: 32px;
8602: width: 32px;
8603: color:white;
8604: border: none;
8605: background-repeat:no-repeat;
8606: background-color:transparent;
1.757 schulted 8607: }
8608:
1.915 droeschl 8609: ul.LC_funclist {
8610: margin: 0;
8611: padding: 0.5em 1em 0.5em 0;
8612: }
8613:
1.933 droeschl 8614: ul.LC_funclist > li:first-child {
8615: font-weight:bold;
8616: margin-left:0.8em;
8617: }
8618:
1.915 droeschl 8619: ul.LC_funclist + ul.LC_funclist {
8620: /*
8621: left border as a seperator if we have more than
8622: one list
8623: */
8624: border-left: 1px solid $sidebg;
8625: /*
8626: this hides the left border behind the border of the
8627: outer box if element is wrapped to the next 'line'
8628: */
8629: margin-left: -1px;
8630: }
8631:
1.843 bisitz 8632: ul.LC_funclist li {
1.915 droeschl 8633: display: inline;
1.782 bisitz 8634: white-space: nowrap;
1.915 droeschl 8635: margin: 0 0 0 25px;
8636: line-height: 150%;
1.782 bisitz 8637: }
8638:
1.974 wenzelju 8639: .LC_hidden {
8640: display: none;
8641: }
8642:
1.1030 www 8643: .LCmodal-overlay {
8644: position:fixed;
8645: top:0;
8646: right:0;
8647: bottom:0;
8648: left:0;
8649: height:100%;
8650: width:100%;
8651: margin:0;
8652: padding:0;
8653: background:#999;
8654: opacity:.75;
8655: filter: alpha(opacity=75);
8656: -moz-opacity: 0.75;
8657: z-index:101;
8658: }
8659:
8660: * html .LCmodal-overlay {
8661: position: absolute;
8662: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8663: }
8664:
8665: .LCmodal-window {
8666: position:fixed;
8667: top:50%;
8668: left:50%;
8669: margin:0;
8670: padding:0;
8671: z-index:102;
8672: }
8673:
8674: * html .LCmodal-window {
8675: position:absolute;
8676: }
8677:
8678: .LCclose-window {
8679: position:absolute;
8680: width:32px;
8681: height:32px;
8682: right:8px;
8683: top:8px;
8684: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8685: text-indent:-99999px;
8686: overflow:hidden;
8687: cursor:pointer;
8688: }
8689:
1.1075.2.158 raeburn 8690: .LCisDisabled {
8691: cursor: not-allowed;
8692: opacity: 0.5;
8693: }
8694:
8695: a[aria-disabled="true"] {
8696: color: currentColor;
8697: display: inline-block; /* For IE11/ MS Edge bug */
8698: pointer-events: none;
8699: text-decoration: none;
8700: }
8701:
1.1075.2.141 raeburn 8702: pre.LC_wordwrap {
8703: white-space: pre-wrap;
8704: white-space: -moz-pre-wrap;
8705: white-space: -pre-wrap;
8706: white-space: -o-pre-wrap;
8707: word-wrap: break-word;
8708: }
8709:
1.1075.2.17 raeburn 8710: /*
1.1075.2.161. .21(raeb 8711:-24): styles used for response display
8712:-24): */
8713:-24): div.LC_radiofoil, div.LC_rankfoil {
8714:-24): margin: .5em 0em .5em 0em;
8715:-24): }
8716:-24): table.LC_itemgroup {
8717:-24): margin-top: 1em;
8718:-24): }
8719:-24):
8720:-24): /*
1.1075.2.17 raeburn 8721: styles used by TTH when "Default set of options to pass to tth/m
8722: when converting TeX" in course settings has been set
8723:
8724: option passed: -t
8725:
8726: */
8727:
8728: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8729: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8730: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8731: td div.norm {line-height:normal;}
8732:
8733: /*
8734: option passed -y3
8735: */
8736:
8737: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8738: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8739: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8740:
1.1075.2.161. .21(raeb 8741:-24): /*
8742:-24): sections with roles, for content only
8743:-24): */
8744:-24): section[class^="role-"] {
8745:-24): padding-left: 10px;
8746:-24): padding-right: 5px;
8747:-24): margin-top: 8px;
8748:-24): margin-bottom: 8px;
8749:-24): border: 1px solid #2A4;
8750:-24): border-radius: 5px;
8751:-24): box-shadow: 0px 1px 1px #BBB;
8752:-24): }
8753:-24): section[class^="role-"]>h1 {
8754:-24): position: relative;
8755:-24): margin: 0px;
8756:-24): padding-top: 10px;
8757:-24): padding-left: 40px;
8758:-24): }
8759:-24): section[class^="role-"]>h1:before {
8760:-24): position: absolute;
8761:-24): left: -5px;
8762:-24): top: 5px;
8763:-24): }
8764:-24): section.role-activity>h1:before {
8765:-24): content:url('/adm/daxe/images/section_icons/activity.png');
8766:-24): }
8767:-24): section.role-advice>h1:before {
8768:-24): content:url('/adm/daxe/images/section_icons/advice.png');
8769:-24): }
8770:-24): section.role-bibliography>h1:before {
8771:-24): content:url('/adm/daxe/images/section_icons/bibliography.png');
8772:-24): }
8773:-24): section.role-citation>h1:before {
8774:-24): content:url('/adm/daxe/images/section_icons/citation.png');
8775:-24): }
8776:-24): section.role-conclusion>h1:before {
8777:-24): content:url('/adm/daxe/images/section_icons/conclusion.png');
8778:-24): }
8779:-24): section.role-definition>h1:before {
8780:-24): content:url('/adm/daxe/images/section_icons/definition.png');
8781:-24): }
8782:-24): section.role-demonstration>h1:before {
8783:-24): content:url('/adm/daxe/images/section_icons/demonstration.png');
8784:-24): }
8785:-24): section.role-example>h1:before {
8786:-24): content:url('/adm/daxe/images/section_icons/example.png');
8787:-24): }
8788:-24): section.role-explanation>h1:before {
8789:-24): content:url('/adm/daxe/images/section_icons/explanation.png');
8790:-24): }
8791:-24): section.role-introduction>h1:before {
8792:-24): content:url('/adm/daxe/images/section_icons/introduction.png');
8793:-24): }
8794:-24): section.role-method>h1:before {
8795:-24): content:url('/adm/daxe/images/section_icons/method.png');
8796:-24): }
8797:-24): section.role-more_information>h1:before {
8798:-24): content:url('/adm/daxe/images/section_icons/more_information.png');
8799:-24): }
8800:-24): section.role-objectives>h1:before {
8801:-24): content:url('/adm/daxe/images/section_icons/objectives.png');
8802:-24): }
8803:-24): section.role-prerequisites>h1:before {
8804:-24): content:url('/adm/daxe/images/section_icons/prerequisites.png');
8805:-24): }
8806:-24): section.role-remark>h1:before {
8807:-24): content:url('/adm/daxe/images/section_icons/remark.png');
8808:-24): }
8809:-24): section.role-reminder>h1:before {
8810:-24): content:url('/adm/daxe/images/section_icons/reminder.png');
8811:-24): }
8812:-24): section.role-summary>h1:before {
8813:-24): content:url('/adm/daxe/images/section_icons/summary.png');
8814:-24): }
8815:-24): section.role-syntax>h1:before {
8816:-24): content:url('/adm/daxe/images/section_icons/syntax.png');
8817:-24): }
8818:-24): section.role-warning>h1:before {
8819:-24): content:url('/adm/daxe/images/section_icons/warning.png');
8820:-24): }
8821:-24):
1.1075.2.121 raeburn 8822: #LC_minitab_header {
8823: float:left;
8824: width:100%;
8825: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8826: font-size:93%;
8827: line-height:normal;
8828: margin: 0.5em 0 0.5em 0;
8829: }
8830: #LC_minitab_header ul {
8831: margin:0;
8832: padding:10px 10px 0;
8833: list-style:none;
8834: }
8835: #LC_minitab_header li {
8836: float:left;
8837: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8838: margin:0;
8839: padding:0 0 0 9px;
8840: }
8841: #LC_minitab_header a {
8842: display:block;
8843: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8844: padding:5px 15px 4px 6px;
8845: }
8846: #LC_minitab_header #LC_current_minitab {
8847: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8848: }
8849: #LC_minitab_header #LC_current_minitab a {
8850: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8851: padding-bottom:5px;
8852: }
8853:
8854:
1.343 albertel 8855: END
8856: }
8857:
1.306 albertel 8858: =pod
8859:
8860: =item * &headtag()
8861:
8862: Returns a uniform footer for LON-CAPA web pages.
8863:
1.307 albertel 8864: Inputs: $title - optional title for the head
8865: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8866: $args - optional arguments
1.319 albertel 8867: force_register - if is true call registerurl so the remote is
8868: informed
1.415 albertel 8869: redirect -> array ref of
8870: 1- seconds before redirect occurs
8871: 2- url to redirect to
8872: 3- whether the side effect should occur
1.315 albertel 8873: (side effect of setting
8874: $env{'internal.head.redirect'} to the url
1.1075.2.161. .9(raebu 8875:22): redirected to)
8876:22): 4- whether the redirect target should be
8877:22): the opener of the current (pop-up)
8878:22): window (side effect of setting
8879:22): $env{'internal.head.to_opener'} to
8880:22): 1, if true.
.10(raeb 8881:-22): 5- whether encrypt check should be skipped
1.352 albertel 8882: domain -> force to color decorate a page for a specific
8883: domain
8884: function -> force usage of a specific rolish color scheme
8885: bgcolor -> override the default page bgcolor
1.460 albertel 8886: no_auto_mt_title
8887: -> prevent &mt()ing the title arg
1.464 albertel 8888:
1.306 albertel 8889: =cut
8890:
8891: sub headtag {
1.313 albertel 8892: my ($title,$head_extra,$args) = @_;
1.306 albertel 8893:
1.363 albertel 8894: my $function = $args->{'function'} || &get_users_function();
8895: my $domain = $args->{'domain'} || &determinedomain();
8896: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8897: my $httphost = $args->{'use_absolute'};
1.418 albertel 8898: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8899: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8900: #time(),
1.418 albertel 8901: $env{'environment.color.timestamp'},
1.363 albertel 8902: $function,$domain,$bgcolor);
8903:
1.369 www 8904: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8905:
1.308 albertel 8906: my $result =
8907: '<head>'.
1.1075.2.56 raeburn 8908: &font_settings($args);
1.319 albertel 8909:
1.1075.2.72 raeburn 8910: my $inhibitprint;
8911: if ($args->{'print_suppress'}) {
8912: $inhibitprint = &print_suppression();
8913: }
1.1064 raeburn 8914:
1.461 albertel 8915: if (!$args->{'frameset'}) {
8916: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8917: }
1.1075.2.12 raeburn 8918: if ($args->{'force_register'}) {
8919: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8920: }
1.436 albertel 8921: if (!$args->{'no_nav_bar'}
8922: && !$args->{'only_body'}
8923: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8924: $result .= &help_menu_js($httphost);
1.1032 www 8925: $result.=&modal_window();
1.1038 www 8926: $result.=&togglebox_script();
1.1034 www 8927: $result.=&wishlist_window();
1.1041 www 8928: $result.=&LCprogressbarUpdate_script();
1.1034 www 8929: } else {
8930: if ($args->{'add_modal'}) {
8931: $result.=&modal_window();
8932: }
8933: if ($args->{'add_wishlist'}) {
8934: $result.=&wishlist_window();
8935: }
1.1038 www 8936: if ($args->{'add_togglebox'}) {
8937: $result.=&togglebox_script();
8938: }
1.1041 www 8939: if ($args->{'add_progressbar'}) {
8940: $result.=&LCprogressbarUpdate_script();
8941: }
1.436 albertel 8942: }
1.314 albertel 8943: if (ref($args->{'redirect'})) {
1.1075.2.161. .10(raeb 8944:-22): my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
8945:-22): if (!$skip_enc_check) {
8946:-22): $url = &Apache::lonenc::check_encrypt($url);
8947:-22): }
1.414 albertel 8948: if (!$inhibit_continue) {
8949: $env{'internal.head.redirect'} = $url;
8950: }
1.1075.2.161. .9(raebu 8951:22): $result.=<<"ADDMETA";
1.313 albertel 8952: <meta http-equiv="pragma" content="no-cache" />
1.1075.2.161. .9(raebu 8953:22): ADDMETA
8954:22): if ($to_opener) {
8955:22): $env{'internal.head.to_opener'} = 1;
8956:22): my $dest = &js_escape($url);
8957:22): my $timeout = int($time * 1000);
8958:22): $result .=<<"ENDJS";
8959:22): <script type="text/javascript">
8960:22): // <![CDATA[
8961:22): function LC_To_Opener() {
8962:22): var dest = '$dest';
8963:22): if (dest != '') {
8964:22): if (window.opener != null && !window.opener.closed) {
8965:22): window.opener.location.href=dest;
8966:22): window.close();
8967:22): } else {
8968:22): window.location.href=dest;
8969:22): }
8970:22): }
8971:22): }
8972:22): \$(document).ready(function () {
8973:22): setTimeout('LC_To_Opener()',$timeout);
8974:22): });
8975:22): // ]]>
8976:22): </script>
8977:22): ENDJS
8978:22): } else {
8979:22): $result.=<<"ADDMETA";
1.344 albertel 8980: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8981: ADDMETA
1.1075.2.161. .9(raebu 8982:22): }
1.1075.2.89 raeburn 8983: } else {
8984: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8985: my $requrl = $env{'request.uri'};
8986: if ($requrl eq '') {
8987: $requrl = $ENV{'REQUEST_URI'};
8988: $requrl =~ s/\?.+$//;
8989: }
8990: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8991: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8992: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8993: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8994: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8995: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8996: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8997: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8998: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8999: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 9000: $offload = 1;
1.1075.2.151 raeburn 9001: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9002: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9003: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9004: $offloadoth = 1;
9005: $dom_in_use = $env{'user.domain'};
9006: }
9007: }
1.1075.2.145 raeburn 9008: }
9009: }
9010: unless ($offload) {
9011: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9012: if ($domdefs{'offloadoth'}{$lonhost}) {
9013: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9014: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9015: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9016: $offload = 1;
1.1075.2.151 raeburn 9017: $offloadoth = 1;
1.1075.2.145 raeburn 9018: $dom_in_use = $env{'user.domain'};
9019: }
1.1075.2.89 raeburn 9020: }
1.1075.2.145 raeburn 9021: }
9022: }
9023: }
9024: if ($offload) {
1.1075.2.158 raeburn 9025: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 9026: if (($newserver eq '') && ($offloadoth)) {
9027: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 9028:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 9029: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9030: }
9031: }
1.1075.2.145 raeburn 9032: if (($newserver) && ($newserver ne $lonhost)) {
9033: my $numsec = 5;
9034: my $timeout = $numsec * 1000;
9035: my ($newurl,$locknum,%locks,$msg);
9036: if ($env{'request.role.adv'}) {
9037: ($locknum,%locks) = &Apache::lonnet::get_locks();
9038: }
9039: my $disable_submit = 0;
9040: if ($requrl =~ /$LONCAPA::assess_re/) {
9041: $disable_submit = 1;
9042: }
9043: if ($locknum) {
9044: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 9045: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 9046: join(", ",sort(values(%locks)))."\n";
9047: if (&show_course()) {
9048: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 9049: } else {
1.1075.2.145 raeburn 9050: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
9051: }
9052: } else {
9053: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9054: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9055: }
9056: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9057: $newurl = '/adm/switchserver?otherserver='.$newserver;
9058: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9059: $newurl .= '&role='.$env{'request.role'};
9060: }
9061: if ($env{'request.symb'}) {
9062: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9063: if ($shownsymb =~ m{^/enc/}) {
9064: my $reqdmajor = 2;
9065: my $reqdminor = 11;
9066: my $reqdsubminor = 3;
9067: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9068: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9069: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9070: if (($major eq '' && $minor eq '') ||
9071: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9072: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9073: ($reqdsubminor > $subminor))))) {
9074: undef($shownsymb);
9075: }
1.1075.2.89 raeburn 9076: }
1.1075.2.145 raeburn 9077: if ($shownsymb) {
9078: &js_escape(\$shownsymb);
9079: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 9080: }
1.1075.2.145 raeburn 9081: } else {
9082: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9083: &js_escape(\$shownurl);
9084: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 9085: }
1.1075.2.145 raeburn 9086: }
9087: &js_escape(\$msg);
9088: $result.=<<OFFLOAD
1.1075.2.89 raeburn 9089: <meta http-equiv="pragma" content="no-cache" />
9090: <script type="text/javascript">
1.1075.2.92 raeburn 9091: // <![CDATA[
1.1075.2.89 raeburn 9092: function LC_Offload_Now() {
9093: var dest = "$newurl";
9094: if (dest != '') {
9095: window.location.href="$newurl";
9096: }
9097: }
1.1075.2.92 raeburn 9098: \$(document).ready(function () {
9099: window.alert('$msg');
9100: if ($disable_submit) {
1.1075.2.89 raeburn 9101: \$(".LC_hwk_submit").prop("disabled", true);
9102: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 9103: }
9104: setTimeout('LC_Offload_Now()', $timeout);
9105: });
9106: // ]]>
1.1075.2.89 raeburn 9107: </script>
9108: OFFLOAD
9109: }
9110: }
9111: }
9112: }
9113: }
1.313 albertel 9114: }
1.306 albertel 9115: if (!defined($title)) {
9116: $title = 'The LearningOnline Network with CAPA';
9117: }
1.460 albertel 9118: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.161. .25(raeb 9119:-24): if ($title =~ /^LON-CAPA\s+/) {
9120:-24): $result .= '<title> '.$title.'</title>';
9121:-24): } else {
9122:-24): $result .= '<title> LON-CAPA '.$title.'</title>';
9123:-24): }
9124:-24): $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1075.2.61 raeburn 9125: if (!$args->{'frameset'}) {
9126: $result .= ' /';
9127: }
9128: $result .= '>'
1.1064 raeburn 9129: .$inhibitprint
1.414 albertel 9130: .$head_extra;
1.1075.2.108 raeburn 9131: my $clientmobile;
9132: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9133: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9134: } else {
9135: $clientmobile = $env{'browser.mobile'};
9136: }
9137: if ($clientmobile) {
1.1075.2.42 raeburn 9138: $result .= '
9139: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9140: <meta name="apple-mobile-web-app-capable" content="yes" />';
9141: }
1.1075.2.126 raeburn 9142: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9143: return $result.'</head>';
1.306 albertel 9144: }
9145:
9146: =pod
9147:
1.340 albertel 9148: =item * &font_settings()
9149:
9150: Returns neccessary <meta> to set the proper encoding
9151:
1.1075.2.56 raeburn 9152: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9153:
9154: =cut
9155:
9156: sub font_settings {
1.1075.2.56 raeburn 9157: my ($args) = @_;
1.340 albertel 9158: my $headerstring='';
1.1075.2.56 raeburn 9159: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9160: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 9161: $headerstring.=
1.1075.2.61 raeburn 9162: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9163: if (!$args->{'frameset'}) {
9164: $headerstring.= ' /';
9165: }
9166: $headerstring .= '>'."\n";
1.340 albertel 9167: }
9168: return $headerstring;
9169: }
9170:
1.341 albertel 9171: =pod
9172:
1.1064 raeburn 9173: =item * &print_suppression()
9174:
9175: In course context returns css which causes the body to be blank when media="print",
9176: if printout generation is unavailable for the current resource.
9177:
9178: This could be because:
9179:
9180: (a) printstartdate is in the future
9181:
9182: (b) printenddate is in the past
9183:
9184: (c) there is an active exam block with "printout"
9185: functionality blocked
9186:
9187: Users with pav, pfo or evb privileges are exempt.
9188:
9189: Inputs: none
9190:
9191: =cut
9192:
9193:
9194: sub print_suppression {
9195: my $noprint;
9196: if ($env{'request.course.id'}) {
9197: my $scope = $env{'request.course.id'};
9198: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9199: (&Apache::lonnet::allowed('pfo',$scope))) {
9200: return;
9201: }
9202: if ($env{'request.course.sec'} ne '') {
9203: $scope .= "/$env{'request.course.sec'}";
9204: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9205: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9206: return;
1.1064 raeburn 9207: }
9208: }
9209: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9210: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 9211: my $clientip = &Apache::lonnet::get_requestor_ip();
9212: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9213: if ($blocked) {
9214: my $checkrole = "cm./$cdom/$cnum";
9215: if ($env{'request.course.sec'} ne '') {
9216: $checkrole .= "/$env{'request.course.sec'}";
9217: }
9218: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9219: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9220: $noprint = 1;
9221: }
9222: }
9223: unless ($noprint) {
9224: my $symb = &Apache::lonnet::symbread();
9225: if ($symb ne '') {
9226: my $navmap = Apache::lonnavmaps::navmap->new();
9227: if (ref($navmap)) {
9228: my $res = $navmap->getBySymb($symb);
9229: if (ref($res)) {
9230: if (!$res->resprintable()) {
9231: $noprint = 1;
9232: }
9233: }
9234: }
9235: }
9236: }
9237: if ($noprint) {
9238: return <<"ENDSTYLE";
9239: <style type="text/css" media="print">
9240: body { display:none }
9241: </style>
9242: ENDSTYLE
9243: }
9244: }
9245: return;
9246: }
9247:
9248: =pod
9249:
1.341 albertel 9250: =item * &xml_begin()
9251:
9252: Returns the needed doctype and <html>
9253:
9254: Inputs: none
9255:
9256: =cut
9257:
9258: sub xml_begin {
1.1075.2.61 raeburn 9259: my ($is_frameset) = @_;
1.341 albertel 9260: my $output='';
9261:
9262: if ($env{'browser.mathml'}) {
9263: $output='<?xml version="1.0"?>'
9264: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9265: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9266:
9267: # .'<!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">] >'
9268: .'<!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">'
9269: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9270: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 9271: } elsif ($is_frameset) {
9272: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9273: '<html>'."\n";
1.341 albertel 9274: } else {
1.1075.2.61 raeburn 9275: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9276: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9277: }
9278: return $output;
9279: }
1.340 albertel 9280:
9281: =pod
9282:
1.306 albertel 9283: =item * &start_page()
9284:
9285: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9286:
1.648 raeburn 9287: Inputs:
9288:
9289: =over 4
9290:
9291: $title - optional title for the page
9292:
9293: $head_extra - optional extra HTML to incude inside the <head>
9294:
9295: $args - additional optional args supported are:
9296:
9297: =over 8
9298:
9299: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9300: arg on
1.814 bisitz 9301: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9302: add_entries -> additional attributes to add to the <body>
9303: domain -> force to color decorate a page for a
1.317 albertel 9304: specific domain
1.648 raeburn 9305: function -> force usage of a specific rolish color
1.317 albertel 9306: scheme
1.648 raeburn 9307: redirect -> see &headtag()
9308: bgcolor -> override the default page bg color
9309: js_ready -> return a string ready for being used in
1.317 albertel 9310: a javascript writeln
1.648 raeburn 9311: html_encode -> return a string ready for being used in
1.320 albertel 9312: a html attribute
1.648 raeburn 9313: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9314: $forcereg arg
1.648 raeburn 9315: frameset -> if true will start with a <frameset>
1.330 albertel 9316: rather than <body>
1.648 raeburn 9317: skip_phases -> hash ref of
1.338 albertel 9318: head -> skip the <html><head> generation
9319: body -> skip all <body> generation
1.1075.2.12 raeburn 9320: no_inline_link -> if true and in remote mode, don't show the
9321: 'Switch To Inline Menu' link
1.648 raeburn 9322: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9323: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9324: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.161. .29(raeb 9325:-24): bread_crumbs_style -> breadcrumbs are contained within <div id="LC_breadcrumbs">,
9326:-24): and &standard_css() contains CSS for #LC_breadcrumbs, if you want
9327:-24): to override those values, or add to them, specify the value to
9328:-24): include in the style attribute to include in the div tag by using
9329:-24): bread_crumbs_style (e.g., overflow: visible)
1.1075.2.123 raeburn 9330: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9331: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 9332: group -> includes the current group, if page is for a
9333: specific group
1.1075.2.133 raeburn 9334: use_absolute -> for request for external resource or syllabus, this
9335: will contain https://<hostname> if server uses
9336: https (as per hosts.tab), but request is for http
9337: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 9338: links_disabled -> Links in primary and secondary menus are disabled
9339: (Can enable them once page has loaded - see lonroles.pm
9340: for an example).
1.1075.2.161. .6(raebu 9341:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9342:
1.648 raeburn 9343: =back
1.460 albertel 9344:
1.648 raeburn 9345: =back
1.562 albertel 9346:
1.306 albertel 9347: =cut
9348:
9349: sub start_page {
1.309 albertel 9350: my ($title,$head_extra,$args) = @_;
1.318 albertel 9351: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9352:
1.315 albertel 9353: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 9354:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9355:
1.338 albertel 9356: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 9357: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9358: }
1.1075.2.161. .1(raebu 9359:21):
9360:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
9361:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9362:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9363:21): $args->{'no_primary_menu'} = 1;
9364:21): }
9365:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9366:21): $args->{'no_inline_menu'} = 1;
9367:21): }
9368:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9369:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9370:21): }
9371:21): } else {
9372:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9373:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9374:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9375:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9376:21): $args->{'no_primary_menu'} = 1;
9377:21): }
9378:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9379:21): $args->{'no_inline_menu'} = 1;
9380:21): }
9381:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9382:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9383:21): }
9384:21): }
9385:21): }
9386:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9387:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
9388:21): $env{'course.'.$env{'request.course.id'}.'.num'});
9389:21): } elsif ($env{'request.course.id'}) {
9390:21): my $expiretime=600;
9391:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9392:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9393:21): }
9394:21): my ($deeplinkmenu,$menuref);
9395:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9396:21): if ($menucoll) {
9397:21): if (ref($menuref) eq 'HASH') {
9398:21): %menu = %{$menuref};
9399:21): }
9400:21): if ($menu{'top'} eq 'n') {
9401:21): $args->{'no_primary_menu'} = 1;
9402:21): }
9403:21): if ($menu{'inline'} eq 'n') {
9404:21): unless (&Apache::lonnet::allowed('opa')) {
9405:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9406:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9407:21): my $crstype = &course_type();
9408:21): my $now = time;
9409:21): my $ccrole;
9410:21): if ($crstype eq 'Community') {
9411:21): $ccrole = 'co';
9412:21): } else {
9413:21): $ccrole = 'cc';
9414:21): }
9415:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9416:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9417:21): if ((($start) && ($start<0)) ||
9418:21): (($end) && ($end<$now)) ||
9419:21): (($start) && ($now<$start))) {
9420:21): $args->{'no_inline_menu'} = 1;
9421:21): }
9422:21): } else {
9423:21): $args->{'no_inline_menu'} = 1;
9424:21): }
9425:21): }
9426:21): }
9427:21): }
9428:21): }
.4(raebu 9429:22):
.8(raebu 9430:22): my $showncrumbs;
1.338 albertel 9431: if (! exists($args->{'skip_phases'}{'body'}) ) {
9432: if ($args->{'frameset'}) {
9433: my $attr_string = &make_attr_string($args->{'force_register'},
9434: $args->{'add_entries'});
9435: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9436: } else {
9437: $result .=
9438: &bodytag($title,
9439: $args->{'function'}, $args->{'add_entries'},
9440: $args->{'only_body'}, $args->{'domain'},
9441: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 9442: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 9443:21): $args, \@advtools,
.8(raebu 9444:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 9445: }
1.330 albertel 9446: }
1.338 albertel 9447:
1.315 albertel 9448: if ($args->{'js_ready'}) {
1.713 kaisler 9449: $result = &js_ready($result);
1.315 albertel 9450: }
1.320 albertel 9451: if ($args->{'html_encode'}) {
1.713 kaisler 9452: $result = &html_encode($result);
9453: }
9454:
1.813 bisitz 9455: # Preparation for new and consistent functionlist at top of screen
9456: # if ($args->{'functionlist'}) {
9457: # $result .= &build_functionlist();
9458: #}
9459:
1.964 droeschl 9460: # Don't add anything more if only_body wanted or in const space
9461: return $result if $args->{'only_body'}
9462: || $env{'request.state'} eq 'construct';
1.813 bisitz 9463:
9464: #Breadcrumbs
1.758 kaisler 9465: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 9466:22): unless ($showncrumbs) {
1.758 kaisler 9467: &Apache::lonhtmlcommon::clear_breadcrumbs();
9468: #if any br links exists, add them to the breadcrumbs
9469: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9470: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9471: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9472: }
9473: }
1.1075.2.19 raeburn 9474: # if @advtools array contains items add then to the breadcrumbs
9475: if (@advtools > 0) {
9476: &Apache::lonmenu::advtools_crumbs(@advtools);
9477: }
1.1075.2.123 raeburn 9478: my $menulink;
9479: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 9480:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
9481:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 9482: $menulink = 0;
9483: } else {
9484: undef($menulink);
9485: }
1.1075.2.161. .8(raebu 9486:22): my $linkprotout;
9487:22): if ($env{'request.deeplink.login'}) {
9488:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
9489:22): if ($linkprotout) {
9490:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9491:22): }
9492:22): }
1.758 kaisler 9493: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9494: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.161. .29(raeb 9495:-24): $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},
9496:-24): '',$menulink,'',
9497:-24): $args->{'bread_crumbs_style'});
.1(raebu 9498:21): } else {
.29(raeb 9499:-24): $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink,'',
9500:-24): $args->{'bread_crumbs_style'});
1.758 kaisler 9501: }
1.1075.2.161. .8(raebu 9502:22): }
1.1075.2.24 raeburn 9503: } elsif (($env{'environment.remote'} eq 'on') &&
9504: ($env{'form.inhibitmenu'} ne 'yes') &&
9505: ($env{'request.noversionuri'} =~ m{^/res/}) &&
9506: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 9507: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 9508: }
1.315 albertel 9509: return $result;
1.306 albertel 9510: }
9511:
9512: sub end_page {
1.315 albertel 9513: my ($args) = @_;
9514: $env{'internal.end_page'}++;
1.330 albertel 9515: my $result;
1.335 albertel 9516: if ($args->{'discussion'}) {
9517: my ($target,$parser);
9518: if (ref($args->{'discussion'})) {
9519: ($target,$parser) =($args->{'discussion'}{'target'},
9520: $args->{'discussion'}{'parser'});
9521: }
9522: $result .= &Apache::lonxml::xmlend($target,$parser);
9523: }
1.330 albertel 9524: if ($args->{'frameset'}) {
9525: $result .= '</frameset>';
9526: } else {
1.635 raeburn 9527: $result .= &endbodytag($args);
1.330 albertel 9528: }
1.1075.2.6 raeburn 9529: unless ($args->{'notbody'}) {
9530: $result .= "\n</html>";
9531: }
1.330 albertel 9532:
1.315 albertel 9533: if ($args->{'js_ready'}) {
1.317 albertel 9534: $result = &js_ready($result);
1.315 albertel 9535: }
1.335 albertel 9536:
1.320 albertel 9537: if ($args->{'html_encode'}) {
9538: $result = &html_encode($result);
9539: }
1.335 albertel 9540:
1.315 albertel 9541: return $result;
9542: }
9543:
1.1075.2.161. .1(raebu 9544:21): sub menucoll_in_effect {
9545:21): my ($menucoll,$deeplinkmenu,%menu);
9546:21): if ($env{'request.course.id'}) {
9547:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9548:21): if ($env{'request.deeplink.login'}) {
9549:21): my ($deeplink_symb,$deeplink,$check_login_symb);
9550:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9551:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9552:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9553:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9554:21): my $navmap = Apache::lonnavmaps::navmap->new();
9555:21): if (ref($navmap)) {
9556:21): $deeplink = $navmap->get_mapparam(undef,
9557:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
9558:21): '0.deeplink');
9559:21): } else {
9560:21): $check_login_symb = 1;
9561:21): }
9562:21): } else {
9563:21): my $symb=&Apache::lonnet::symbread();
9564:21): if ($symb) {
9565:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9566:21): } else {
9567:21): $check_login_symb = 1;
9568:21): }
9569:21): }
9570:21): } else {
9571:21): $check_login_symb = 1;
9572:21): }
9573:21): if ($check_login_symb) {
9574:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9575:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
9576:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9577:21): my $navmap = Apache::lonnavmaps::navmap->new();
9578:21): if (ref($navmap)) {
9579:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9580:21): }
9581:21): } else {
9582:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9583:21): }
9584:21): }
9585:21): if ($deeplink ne '') {
.6(raebu 9586:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 9587:21): if ($display =~ /^\d+$/) {
9588:21): $deeplinkmenu = 1;
9589:21): $menucoll = $display;
9590:21): }
9591:21): }
9592:21): }
9593:21): if ($menucoll) {
9594:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9595:21): }
9596:21): }
9597:21): return ($menucoll,$deeplinkmenu,\%menu);
9598:21): }
9599:21):
9600:21): sub deeplink_login_symb {
9601:21): my ($cnum,$cdom) = @_;
9602:21): my $login_symb;
9603:21): if ($env{'request.deeplink.login'}) {
9604:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9605:21): }
9606:21): return $login_symb;
9607:21): }
9608:21):
9609:21): sub symb_from_tinyurl {
9610:21): my ($url,$cnum,$cdom) = @_;
9611:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9612:21): my $key = $1;
9613:21): my ($tinyurl,$login);
9614:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9615:21): if (defined($cached)) {
9616:21): $tinyurl = $result;
9617:21): } else {
9618:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9619:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9620:21): if ($currtiny{$key} ne '') {
9621:21): $tinyurl = $currtiny{$key};
9622:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9623:21): }
9624:21): }
9625:21): if ($tinyurl ne '') {
9626:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9627:21): if (wantarray) {
9628:21): return ($cnumreq,$symb);
9629:21): } elsif ($cnumreq eq $cnum) {
9630:21): return $symb;
9631:21): }
9632:21): }
9633:21): }
9634:21): if (wantarray) {
9635:21): return ();
9636:21): } else {
9637:21): return;
9638:21): }
9639:21): }
9640:21):
.17(raeb 9641:-23): sub usable_exttools {
9642:-23): my %tooltypes;
9643:-23): if ($env{'request.course.id'}) {
9644:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9645:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9646:-23): %tooltypes = (
9647:-23): crs => 1,
9648:-23): dom => 1,
9649:-23): );
9650:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9651:-23): $tooltypes{'crs'} = 1;
9652:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9653:-23): $tooltypes{'dom'} = 1;
9654:-23): }
9655:-23): } else {
9656:-23): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9657:-23): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9658:-23): my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9659:-23): if ($crstype eq '') {
9660:-23): $crstype = 'course';
9661:-23): }
9662:-23): if ($crstype eq 'course') {
9663:-23): if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9664:-23): $crstype = 'official';
9665:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9666:-23): $crstype = 'textbook';
9667:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9668:-23): $crstype = 'lti';
9669:-23): } else {
9670:-23): $crstype = 'unofficial';
9671:-23): }
9672:-23): }
9673:-23): my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9674:-23): if ($domdefaults{$crstype.'domexttool'}) {
9675:-23): $tooltypes{'dom'} = 1;
9676:-23): }
9677:-23): if ($domdefaults{$crstype.'exttool'}) {
9678:-23): $tooltypes{'crs'} = 1;
9679:-23): }
9680:-23): }
9681:-23): }
9682:-23): return %tooltypes;
9683:-23): }
9684:-23):
1.1034 www 9685: sub wishlist_window {
9686: return(<<'ENDWISHLIST');
1.1046 raeburn 9687: <script type="text/javascript">
1.1034 www 9688: // <![CDATA[
9689: // <!-- BEGIN LON-CAPA Internal
9690: function set_wishlistlink(title, path) {
9691: if (!title) {
9692: title = document.title;
9693: title = title.replace(/^LON-CAPA /,'');
9694: }
1.1075.2.65 raeburn 9695: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9696: title = title.replace("'","\\\'");
1.1034 www 9697: if (!path) {
9698: path = location.pathname;
9699: }
1.1075.2.65 raeburn 9700: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9701: path = path.replace("'","\\\'");
1.1034 www 9702: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9703: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9704: }
9705: // END LON-CAPA Internal -->
9706: // ]]>
9707: </script>
9708: ENDWISHLIST
9709: }
9710:
1.1030 www 9711: sub modal_window {
9712: return(<<'ENDMODAL');
1.1046 raeburn 9713: <script type="text/javascript">
1.1030 www 9714: // <![CDATA[
9715: // <!-- BEGIN LON-CAPA Internal
9716: var modalWindow = {
9717: parent:"body",
9718: windowId:null,
9719: content:null,
9720: width:null,
9721: height:null,
9722: close:function()
9723: {
9724: $(".LCmodal-window").remove();
9725: $(".LCmodal-overlay").remove();
9726: },
9727: open:function()
9728: {
9729: var modal = "";
9730: modal += "<div class=\"LCmodal-overlay\"></div>";
9731: 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;\">";
9732: modal += this.content;
9733: modal += "</div>";
9734:
9735: $(this.parent).append(modal);
9736:
9737: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9738: $(".LCclose-window").click(function(){modalWindow.close();});
9739: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9740: }
9741: };
1.1075.2.42 raeburn 9742: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9743: {
1.1075.2.119 raeburn 9744: source = source.replace(/'/g,"'");
1.1030 www 9745: modalWindow.windowId = "myModal";
9746: modalWindow.width = width;
9747: modalWindow.height = height;
1.1075.2.80 raeburn 9748: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9749: modalWindow.open();
1.1075.2.87 raeburn 9750: };
1.1030 www 9751: // END LON-CAPA Internal -->
9752: // ]]>
9753: </script>
9754: ENDMODAL
9755: }
9756:
9757: sub modal_link {
1.1075.2.42 raeburn 9758: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9759: unless ($width) { $width=480; }
9760: unless ($height) { $height=400; }
1.1031 www 9761: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9762: unless ($transparency) { $transparency='true'; }
9763:
1.1074 raeburn 9764: my $target_attr;
9765: if (defined($target)) {
9766: $target_attr = 'target="'.$target.'"';
9767: }
9768: return <<"ENDLINK";
1.1075.2.143 raeburn 9769: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9770: ENDLINK
1.1030 www 9771: }
9772:
1.1032 www 9773: sub modal_adhoc_script {
1.1075.2.155 raeburn 9774: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9775: my $mathjax;
9776: if ($possmathjax) {
9777: $mathjax = <<'ENDJAX';
9778: if (typeof MathJax == 'object') {
9779: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9780: }
9781: ENDJAX
9782: }
1.1032 www 9783: return (<<ENDADHOC);
1.1046 raeburn 9784: <script type="text/javascript">
1.1032 www 9785: // <![CDATA[
9786: var $funcname = function()
9787: {
9788: modalWindow.windowId = "myModal";
9789: modalWindow.width = $width;
9790: modalWindow.height = $height;
9791: modalWindow.content = '$content';
9792: modalWindow.open();
1.1075.2.155 raeburn 9793: $mathjax
1.1032 www 9794: };
9795: // ]]>
9796: </script>
9797: ENDADHOC
9798: }
9799:
1.1041 www 9800: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9801: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9802: my $innerwidth=$width-20;
9803: $content=&js_ready(
1.1042 www 9804: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9805: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9806: $content.
1.1041 www 9807: &end_scrollbox().
1.1075.2.42 raeburn 9808: &end_page()
1.1041 www 9809: );
1.1075.2.155 raeburn 9810: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9811: }
9812:
9813: sub modal_adhoc_window {
1.1075.2.155 raeburn 9814: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9815: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9816: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9817: }
9818:
9819: sub modal_adhoc_launch {
9820: my ($funcname,$width,$height,$content)=@_;
9821: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9822: <script type="text/javascript">
9823: // <![CDATA[
9824: $funcname();
9825: // ]]>
9826: </script>
9827: ENDLAUNCH
9828: }
9829:
9830: sub modal_adhoc_close {
9831: return (<<ENDCLOSE);
9832: <script type="text/javascript">
9833: // <![CDATA[
9834: modalWindow.close();
9835: // ]]>
9836: </script>
9837: ENDCLOSE
9838: }
9839:
1.1038 www 9840: sub togglebox_script {
9841: return(<<ENDTOGGLE);
9842: <script type="text/javascript">
9843: // <![CDATA[
9844: function LCtoggleDisplay(id,hidetext,showtext) {
9845: link = document.getElementById(id + "link").childNodes[0];
9846: with (document.getElementById(id).style) {
9847: if (display == "none" ) {
9848: display = "inline";
9849: link.nodeValue = hidetext;
9850: } else {
9851: display = "none";
9852: link.nodeValue = showtext;
9853: }
9854: }
9855: }
9856: // ]]>
9857: </script>
9858: ENDTOGGLE
9859: }
9860:
1.1039 www 9861: sub start_togglebox {
9862: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9863: unless ($heading) { $heading=''; } else { $heading.=' '; }
9864: unless ($showtext) { $showtext=&mt('show'); }
9865: unless ($hidetext) { $hidetext=&mt('hide'); }
9866: unless ($headerbg) { $headerbg='#FFFFFF'; }
9867: return &start_data_table().
9868: &start_data_table_header_row().
9869: '<td bgcolor="'.$headerbg.'">'.$heading.
9870: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9871: $showtext.'\')">'.$showtext.'</a>]</td>'.
9872: &end_data_table_header_row().
9873: '<tr id="'.$id.'" style="display:none""><td>';
9874: }
9875:
9876: sub end_togglebox {
9877: return '</td></tr>'.&end_data_table();
9878: }
9879:
1.1041 www 9880: sub LCprogressbar_script {
1.1075.2.130 raeburn 9881: my ($id,$number_to_do)=@_;
9882: if ($number_to_do) {
9883: return(<<ENDPROGRESS);
1.1041 www 9884: <script type="text/javascript">
9885: // <![CDATA[
1.1045 www 9886: \$('#progressbar$id').progressbar({
1.1041 www 9887: value: 0,
9888: change: function(event, ui) {
9889: var newVal = \$(this).progressbar('option', 'value');
9890: \$('.pblabel', this).text(LCprogressTxt);
9891: }
9892: });
9893: // ]]>
9894: </script>
9895: ENDPROGRESS
1.1075.2.130 raeburn 9896: } else {
9897: return(<<ENDPROGRESS);
9898: <script type="text/javascript">
9899: // <![CDATA[
9900: \$('#progressbar$id').progressbar({
9901: value: false,
9902: create: function(event, ui) {
9903: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9904: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9905: }
9906: });
9907: // ]]>
9908: </script>
9909: ENDPROGRESS
9910: }
1.1041 www 9911: }
9912:
9913: sub LCprogressbarUpdate_script {
9914: return(<<ENDPROGRESSUPDATE);
9915: <style type="text/css">
9916: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9917: .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 9918: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9919: </style>
9920: <script type="text/javascript">
9921: // <![CDATA[
1.1045 www 9922: var LCprogressTxt='---';
9923:
1.1075.2.130 raeburn 9924: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9925: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9926: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9927: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9928: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9929: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9930: } else {
9931: \$('#progressbar'+id).progressbar('value',percent);
9932: }
1.1041 www 9933: }
9934: // ]]>
9935: </script>
9936: ENDPROGRESSUPDATE
9937: }
9938:
1.1042 www 9939: my $LClastpercent;
1.1045 www 9940: my $LCidcnt;
9941: my $LCcurrentid;
1.1042 www 9942:
1.1041 www 9943: sub LCprogressbar {
1.1075.2.130 raeburn 9944: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9945: $LClastpercent=0;
1.1045 www 9946: $LCidcnt++;
9947: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9948: my ($starting,$content);
9949: if ($number_to_do) {
9950: $starting=&mt('Starting');
9951: $content=(<<ENDPROGBAR);
9952: $preamble
1.1045 www 9953: <div id="progressbar$LCcurrentid">
1.1041 www 9954: <span class="pblabel">$starting</span>
9955: </div>
9956: ENDPROGBAR
1.1075.2.130 raeburn 9957: } else {
9958: $starting=&mt('Loading...');
9959: $LClastpercent='false';
9960: $content=(<<ENDPROGBAR);
9961: $preamble
9962: <div id="progressbar$LCcurrentid">
9963: <div class="progress-label">$starting</div>
9964: </div>
9965: ENDPROGBAR
9966: }
9967: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9968: }
9969:
9970: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9971: my ($r,$val,$text,$number_to_do)=@_;
9972: if ($number_to_do) {
9973: unless ($val) {
9974: if ($LClastpercent) {
9975: $val=$LClastpercent;
9976: } else {
9977: $val=0;
9978: }
9979: }
9980: if ($val<0) { $val=0; }
9981: if ($val>100) { $val=0; }
9982: $LClastpercent=$val;
9983: unless ($text) { $text=$val.'%'; }
9984: } else {
9985: $val = 'false';
1.1042 www 9986: }
1.1041 www 9987: $text=&js_ready($text);
1.1044 www 9988: &r_print($r,<<ENDUPDATE);
1.1041 www 9989: <script type="text/javascript">
9990: // <![CDATA[
1.1075.2.130 raeburn 9991: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9992: // ]]>
9993: </script>
9994: ENDUPDATE
1.1035 www 9995: }
9996:
1.1042 www 9997: sub LCprogressbarClose {
9998: my ($r)=@_;
9999: $LClastpercent=0;
1.1044 www 10000: &r_print($r,<<ENDCLOSE);
1.1042 www 10001: <script type="text/javascript">
10002: // <![CDATA[
1.1045 www 10003: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10004: // ]]>
10005: </script>
10006: ENDCLOSE
1.1044 www 10007: }
10008:
10009: sub r_print {
10010: my ($r,$to_print)=@_;
10011: if ($r) {
10012: $r->print($to_print);
10013: $r->rflush();
10014: } else {
10015: print($to_print);
10016: }
1.1042 www 10017: }
10018:
1.320 albertel 10019: sub html_encode {
10020: my ($result) = @_;
10021:
1.322 albertel 10022: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10023:
10024: return $result;
10025: }
1.1044 www 10026:
1.317 albertel 10027: sub js_ready {
10028: my ($result) = @_;
10029:
1.323 albertel 10030: $result =~ s/[\n\r]/ /xmsg;
10031: $result =~ s/\\/\\\\/xmsg;
10032: $result =~ s/'/\\'/xmsg;
1.372 albertel 10033: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10034:
10035: return $result;
10036: }
10037:
1.315 albertel 10038: sub validate_page {
10039: if ( exists($env{'internal.start_page'})
1.316 albertel 10040: && $env{'internal.start_page'} > 1) {
10041: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10042: $env{'internal.start_page'}.' '.
1.316 albertel 10043: $ENV{'request.filename'});
1.315 albertel 10044: }
10045: if ( exists($env{'internal.end_page'})
1.316 albertel 10046: && $env{'internal.end_page'} > 1) {
10047: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10048: $env{'internal.end_page'}.' '.
1.316 albertel 10049: $env{'request.filename'});
1.315 albertel 10050: }
10051: if ( exists($env{'internal.start_page'})
10052: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10053: &Apache::lonnet::logthis('start_page called without end_page '.
10054: $env{'request.filename'});
1.315 albertel 10055: }
10056: if ( ! exists($env{'internal.start_page'})
10057: && exists($env{'internal.end_page'})) {
1.316 albertel 10058: &Apache::lonnet::logthis('end_page called without start_page'.
10059: $env{'request.filename'});
1.315 albertel 10060: }
1.306 albertel 10061: }
1.315 albertel 10062:
1.996 www 10063:
10064: sub start_scrollbox {
1.1075.2.56 raeburn 10065: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10066: unless ($outerwidth) { $outerwidth='520px'; }
10067: unless ($width) { $width='500px'; }
10068: unless ($height) { $height='200px'; }
1.1075 raeburn 10069: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10070: if ($id ne '') {
1.1075.2.42 raeburn 10071: $table_id = ' id="table_'.$id.'"';
10072: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10073: }
1.1075 raeburn 10074: if ($bgcolor ne '') {
10075: $tdcol = "background-color: $bgcolor;";
10076: }
1.1075.2.42 raeburn 10077: my $nicescroll_js;
10078: if ($env{'browser.mobile'}) {
10079: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10080: }
1.1075 raeburn 10081: return <<"END";
1.1075.2.42 raeburn 10082: $nicescroll_js
10083:
10084: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 10085: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 10086: END
1.996 www 10087: }
10088:
10089: sub end_scrollbox {
1.1036 www 10090: return '</div></td></tr></table>';
1.996 www 10091: }
10092:
1.1075.2.42 raeburn 10093: sub nicescroll_javascript {
10094: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10095: my %options;
10096: if (ref($cursor) eq 'HASH') {
10097: %options = %{$cursor};
10098: }
10099: unless ($options{'railalign'} =~ /^left|right$/) {
10100: $options{'railalign'} = 'left';
10101: }
10102: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10103: my $function = &get_users_function();
10104: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
10105: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10106: $options{'cursorcolor'} = '#00F';
10107: }
10108: }
10109: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10110: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
10111: $options{'cursoropacity'}='1.0';
10112: }
10113: } else {
10114: $options{'cursoropacity'}='1.0';
10115: }
10116: if ($options{'cursorfixedheight'} eq 'none') {
10117: delete($options{'cursorfixedheight'});
10118: } else {
10119: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10120: }
10121: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10122: delete($options{'railoffset'});
10123: }
10124: my @niceoptions;
10125: while (my($key,$value) = each(%options)) {
10126: if ($value =~ /^\{.+\}$/) {
10127: push(@niceoptions,$key.':'.$value);
10128: } else {
10129: push(@niceoptions,$key.':"'.$value.'"');
10130: }
10131: }
10132: my $nicescroll_js = '
10133: $(document).ready(
10134: function() {
10135: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10136: }
10137: );
10138: ';
10139: if ($framecheck) {
10140: $nicescroll_js .= '
10141: function expand_div(caller) {
10142: if (top === self) {
10143: document.getElementById("'.$id.'").style.width = "auto";
10144: document.getElementById("'.$id.'").style.height = "auto";
10145: } else {
10146: try {
10147: if (parent.frames) {
10148: if (parent.frames.length > 1) {
10149: var framesrc = parent.frames[1].location.href;
10150: var currsrc = framesrc.replace(/\#.*$/,"");
10151: if ((caller == "search") || (currsrc == "'.$location.'")) {
10152: document.getElementById("'.$id.'").style.width = "auto";
10153: document.getElementById("'.$id.'").style.height = "auto";
10154: }
10155: }
10156: }
10157: } catch (e) {
10158: return;
10159: }
10160: }
10161: return;
10162: }
10163: ';
10164: }
10165: if ($needjsready) {
10166: $nicescroll_js = '
10167: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10168: } else {
10169: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10170: }
10171: return $nicescroll_js;
10172: }
10173:
1.318 albertel 10174: sub simple_error_page {
1.1075.2.49 raeburn 10175: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 10176:22): my %displayargs;
1.1075.2.49 raeburn 10177: if (ref($args) eq 'HASH') {
10178: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 10179:22): if ($args->{'only_body'}) {
10180:22): $displayargs{'only_body'} = 1;
10181:22): }
10182:22): if ($args->{'no_nav_bar'}) {
10183:22): $displayargs{'no_nav_bar'} = 1;
10184:22): }
1.1075.2.49 raeburn 10185: } else {
10186: $msg = &mt($msg);
10187: }
10188:
1.318 albertel 10189: my $page =
1.1075.2.161. .4(raebu 10190:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 10191: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10192: &Apache::loncommon::end_page();
10193: if (ref($r)) {
10194: $r->print($page);
1.327 albertel 10195: return;
1.318 albertel 10196: }
10197: return $page;
10198: }
1.347 albertel 10199:
10200: {
1.610 albertel 10201: my @row_count;
1.961 onken 10202:
10203: sub start_data_table_count {
10204: unshift(@row_count, 0);
10205: return;
10206: }
10207:
10208: sub end_data_table_count {
10209: shift(@row_count);
10210: return;
10211: }
10212:
1.347 albertel 10213: sub start_data_table {
1.1018 raeburn 10214: my ($add_class,$id) = @_;
1.422 albertel 10215: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10216: my $table_id;
10217: if (defined($id)) {
10218: $table_id = ' id="'.$id.'"';
10219: }
1.961 onken 10220: &start_data_table_count();
1.1018 raeburn 10221: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10222: }
10223:
10224: sub end_data_table {
1.961 onken 10225: &end_data_table_count();
1.389 albertel 10226: return '</table>'."\n";;
1.347 albertel 10227: }
10228:
10229: sub start_data_table_row {
1.974 wenzelju 10230: my ($add_class, $id) = @_;
1.610 albertel 10231: $row_count[0]++;
10232: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10233: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10234: $id = (' id="'.$id.'"') unless ($id eq '');
10235: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10236: }
1.471 banghart 10237:
10238: sub continue_data_table_row {
1.974 wenzelju 10239: my ($add_class, $id) = @_;
1.610 albertel 10240: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10241: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10242: $id = (' id="'.$id.'"') unless ($id eq '');
10243: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10244: }
1.347 albertel 10245:
10246: sub end_data_table_row {
1.389 albertel 10247: return '</tr>'."\n";;
1.347 albertel 10248: }
1.367 www 10249:
1.421 albertel 10250: sub start_data_table_empty_row {
1.707 bisitz 10251: # $row_count[0]++;
1.421 albertel 10252: return '<tr class="LC_empty_row" >'."\n";;
10253: }
10254:
10255: sub end_data_table_empty_row {
10256: return '</tr>'."\n";;
10257: }
10258:
1.367 www 10259: sub start_data_table_header_row {
1.389 albertel 10260: return '<tr class="LC_header_row">'."\n";;
1.367 www 10261: }
10262:
10263: sub end_data_table_header_row {
1.389 albertel 10264: return '</tr>'."\n";;
1.367 www 10265: }
1.890 droeschl 10266:
10267: sub data_table_caption {
10268: my $caption = shift;
10269: return "<caption class=\"LC_caption\">$caption</caption>";
10270: }
1.347 albertel 10271: }
10272:
1.548 albertel 10273: =pod
10274:
10275: =item * &inhibit_menu_check($arg)
10276:
10277: Checks for a inhibitmenu state and generates output to preserve it
10278:
10279: Inputs: $arg - can be any of
10280: - undef - in which case the return value is a string
10281: to add into arguments list of a uri
10282: - 'input' - in which case the return value is a HTML
10283: <form> <input> field of type hidden to
10284: preserve the value
10285: - a url - in which case the return value is the url with
10286: the neccesary cgi args added to preserve the
10287: inhibitmenu state
10288: - a ref to a url - no return value, but the string is
10289: updated to include the neccessary cgi
10290: args to preserve the inhibitmenu state
10291:
10292: =cut
10293:
10294: sub inhibit_menu_check {
10295: my ($arg) = @_;
10296: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10297: if ($arg eq 'input') {
10298: if ($env{'form.inhibitmenu'}) {
10299: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10300: } else {
10301: return
10302: }
10303: }
10304: if ($env{'form.inhibitmenu'}) {
10305: if (ref($arg)) {
10306: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10307: } elsif ($arg eq '') {
10308: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10309: } else {
10310: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10311: }
10312: }
10313: if (!ref($arg)) {
10314: return $arg;
10315: }
10316: }
10317:
1.251 albertel 10318: ###############################################
1.182 matthew 10319:
10320: =pod
10321:
1.549 albertel 10322: =back
10323:
10324: =head1 User Information Routines
10325:
10326: =over 4
10327:
1.405 albertel 10328: =item * &get_users_function()
1.182 matthew 10329:
10330: Used by &bodytag to determine the current users primary role.
10331: Returns either 'student','coordinator','admin', or 'author'.
10332:
10333: =cut
10334:
10335: ###############################################
10336: sub get_users_function {
1.815 tempelho 10337: my $function = 'norole';
1.818 tempelho 10338: if ($env{'request.role'}=~/^(st)/) {
10339: $function='student';
10340: }
1.907 raeburn 10341: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10342: $function='coordinator';
10343: }
1.258 albertel 10344: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10345: $function='admin';
10346: }
1.826 bisitz 10347: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10348: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10349: $function='author';
10350: }
10351: return $function;
1.54 www 10352: }
1.99 www 10353:
10354: ###############################################
10355:
1.233 raeburn 10356: =pod
10357:
1.821 raeburn 10358: =item * &show_course()
10359:
10360: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10361: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10362:
10363: Inputs:
10364: None
10365:
10366: Outputs:
10367: Scalar: 1 if 'Course' to be used, 0 otherwise.
10368:
10369: =cut
10370:
10371: ###############################################
10372: sub show_course {
10373: my $course = !$env{'user.adv'};
10374: if (!$env{'user.adv'}) {
10375: foreach my $env (keys(%env)) {
10376: next if ($env !~ m/^user\.priv\./);
10377: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10378: $course = 0;
10379: last;
10380: }
10381: }
10382: }
10383: return $course;
10384: }
10385:
10386: ###############################################
10387:
10388: =pod
10389:
1.542 raeburn 10390: =item * &check_user_status()
1.274 raeburn 10391:
10392: Determines current status of supplied role for a
10393: specific user. Roles can be active, previous or future.
10394:
10395: Inputs:
10396: user's domain, user's username, course's domain,
1.375 raeburn 10397: course's number, optional section ID.
1.274 raeburn 10398:
10399: Outputs:
10400: role status: active, previous or future.
10401:
10402: =cut
10403:
10404: sub check_user_status {
1.412 raeburn 10405: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10406: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 10407: my @uroles = keys(%userinfo);
1.274 raeburn 10408: my $srchstr;
10409: my $active_chk = 'none';
1.412 raeburn 10410: my $now = time;
1.274 raeburn 10411: if (@uroles > 0) {
1.908 raeburn 10412: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10413: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10414: } else {
1.412 raeburn 10415: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10416: }
10417: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10418: my $role_end = 0;
10419: my $role_start = 0;
10420: $active_chk = 'active';
1.412 raeburn 10421: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10422: $role_end = $1;
10423: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10424: $role_start = $1;
1.274 raeburn 10425: }
10426: }
10427: if ($role_start > 0) {
1.412 raeburn 10428: if ($now < $role_start) {
1.274 raeburn 10429: $active_chk = 'future';
10430: }
10431: }
10432: if ($role_end > 0) {
1.412 raeburn 10433: if ($now > $role_end) {
1.274 raeburn 10434: $active_chk = 'previous';
10435: }
10436: }
10437: }
10438: }
10439: return $active_chk;
10440: }
10441:
10442: ###############################################
10443:
10444: =pod
10445:
1.405 albertel 10446: =item * &get_sections()
1.233 raeburn 10447:
10448: Determines all the sections for a course including
10449: sections with students and sections containing other roles.
1.419 raeburn 10450: Incoming parameters:
10451:
10452: 1. domain
10453: 2. course number
10454: 3. reference to array containing roles for which sections should
10455: be gathered (optional).
10456: 4. reference to array containing status types for which sections
10457: should be gathered (optional).
10458:
10459: If the third argument is undefined, sections are gathered for any role.
10460: If the fourth argument is undefined, sections are gathered for any status.
10461: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10462:
1.374 raeburn 10463: Returns section hash (keys are section IDs, values are
10464: number of users in each section), subject to the
1.419 raeburn 10465: optional roles filter, optional status filter
1.233 raeburn 10466:
10467: =cut
10468:
10469: ###############################################
10470: sub get_sections {
1.419 raeburn 10471: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10472: if (!defined($cdom) || !defined($cnum)) {
10473: my $cid = $env{'request.course.id'};
10474:
10475: return if (!defined($cid));
10476:
10477: $cdom = $env{'course.'.$cid.'.domain'};
10478: $cnum = $env{'course.'.$cid.'.num'};
10479: }
10480:
10481: my %sectioncount;
1.419 raeburn 10482: my $now = time;
1.240 albertel 10483:
1.1075.2.33 raeburn 10484: my $check_students = 1;
10485: my $only_students = 0;
10486: if (ref($possible_roles) eq 'ARRAY') {
10487: if (grep(/^st$/,@{$possible_roles})) {
10488: if (@{$possible_roles} == 1) {
10489: $only_students = 1;
10490: }
10491: } else {
10492: $check_students = 0;
10493: }
10494: }
10495:
10496: if ($check_students) {
1.276 albertel 10497: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10498: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10499: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10500: my $start_index = &Apache::loncoursedata::CL_START();
10501: my $end_index = &Apache::loncoursedata::CL_END();
10502: my $status;
1.366 albertel 10503: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10504: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10505: $data->[$status_index],
10506: $data->[$start_index],
10507: $data->[$end_index]);
10508: if ($stu_status eq 'Active') {
10509: $status = 'active';
10510: } elsif ($end < $now) {
10511: $status = 'previous';
10512: } elsif ($start > $now) {
10513: $status = 'future';
10514: }
10515: if ($section ne '-1' && $section !~ /^\s*$/) {
10516: if ((!defined($possible_status)) || (($status ne '') &&
10517: (grep/^\Q$status\E$/,@{$possible_status}))) {
10518: $sectioncount{$section}++;
10519: }
1.240 albertel 10520: }
10521: }
10522: }
1.1075.2.33 raeburn 10523: if ($only_students) {
10524: return %sectioncount;
10525: }
1.240 albertel 10526: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10527: foreach my $user (sort(keys(%courseroles))) {
10528: if ($user !~ /^(\w{2})/) { next; }
10529: my ($role) = ($user =~ /^(\w{2})/);
10530: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10531: my ($section,$status);
1.240 albertel 10532: if ($role eq 'cr' &&
10533: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10534: $section=$1;
10535: }
10536: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10537: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10538: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10539: if ($end == -1 && $start == -1) {
10540: next; #deleted role
10541: }
10542: if (!defined($possible_status)) {
10543: $sectioncount{$section}++;
10544: } else {
10545: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10546: $status = 'active';
10547: } elsif ($end < $now) {
10548: $status = 'future';
10549: } elsif ($start > $now) {
10550: $status = 'previous';
10551: }
10552: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10553: $sectioncount{$section}++;
10554: }
10555: }
1.233 raeburn 10556: }
1.366 albertel 10557: return %sectioncount;
1.233 raeburn 10558: }
10559:
1.274 raeburn 10560: ###############################################
1.294 raeburn 10561:
10562: =pod
1.405 albertel 10563:
10564: =item * &get_course_users()
10565:
1.275 raeburn 10566: Retrieves usernames:domains for users in the specified course
10567: with specific role(s), and access status.
10568:
10569: Incoming parameters:
1.277 albertel 10570: 1. course domain
10571: 2. course number
10572: 3. access status: users must have - either active,
1.275 raeburn 10573: previous, future, or all.
1.277 albertel 10574: 4. reference to array of permissible roles
1.288 raeburn 10575: 5. reference to array of section restrictions (optional)
10576: 6. reference to results object (hash of hashes).
10577: 7. reference to optional userdata hash
1.609 raeburn 10578: 8. reference to optional statushash
1.630 raeburn 10579: 9. flag if privileged users (except those set to unhide in
10580: course settings) should be excluded
1.609 raeburn 10581: Keys of top level results hash are roles.
1.275 raeburn 10582: Keys of inner hashes are username:domain, with
10583: values set to access type.
1.288 raeburn 10584: Optional userdata hash returns an array with arguments in the
10585: same order as loncoursedata::get_classlist() for student data.
10586:
1.609 raeburn 10587: Optional statushash returns
10588:
1.288 raeburn 10589: Entries for end, start, section and status are blank because
10590: of the possibility of multiple values for non-student roles.
10591:
1.275 raeburn 10592: =cut
1.405 albertel 10593:
1.275 raeburn 10594: ###############################################
1.405 albertel 10595:
1.275 raeburn 10596: sub get_course_users {
1.630 raeburn 10597: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10598: my %idx = ();
1.419 raeburn 10599: my %seclists;
1.288 raeburn 10600:
10601: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10602: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10603: $idx{end} = &Apache::loncoursedata::CL_END();
10604: $idx{start} = &Apache::loncoursedata::CL_START();
10605: $idx{id} = &Apache::loncoursedata::CL_ID();
10606: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10607: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10608: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10609:
1.290 albertel 10610: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10611: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10612: my $now = time;
1.277 albertel 10613: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10614: my $match = 0;
1.412 raeburn 10615: my $secmatch = 0;
1.419 raeburn 10616: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10617: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10618: if ($section eq '') {
10619: $section = 'none';
10620: }
1.291 albertel 10621: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10622: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10623: $secmatch = 1;
10624: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10625: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10626: $secmatch = 1;
10627: }
10628: } else {
1.419 raeburn 10629: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10630: $secmatch = 1;
10631: }
1.290 albertel 10632: }
1.412 raeburn 10633: if (!$secmatch) {
10634: next;
10635: }
1.419 raeburn 10636: }
1.275 raeburn 10637: if (defined($$types{'active'})) {
1.288 raeburn 10638: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10639: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10640: $match = 1;
1.275 raeburn 10641: }
10642: }
10643: if (defined($$types{'previous'})) {
1.609 raeburn 10644: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10645: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10646: $match = 1;
1.275 raeburn 10647: }
10648: }
10649: if (defined($$types{'future'})) {
1.609 raeburn 10650: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10651: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10652: $match = 1;
1.275 raeburn 10653: }
10654: }
1.609 raeburn 10655: if ($match) {
10656: push(@{$seclists{$student}},$section);
10657: if (ref($userdata) eq 'HASH') {
10658: $$userdata{$student} = $$classlist{$student};
10659: }
10660: if (ref($statushash) eq 'HASH') {
10661: $statushash->{$student}{'st'}{$section} = $status;
10662: }
1.288 raeburn 10663: }
1.275 raeburn 10664: }
10665: }
1.412 raeburn 10666: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10667: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10668: my $now = time;
1.609 raeburn 10669: my %displaystatus = ( previous => 'Expired',
10670: active => 'Active',
10671: future => 'Future',
10672: );
1.1075.2.36 raeburn 10673: my (%nothide,@possdoms);
1.630 raeburn 10674: if ($hidepriv) {
10675: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10676: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10677: if ($user !~ /:/) {
10678: $nothide{join(':',split(/[\@]/,$user))}=1;
10679: } else {
10680: $nothide{$user} = 1;
10681: }
10682: }
1.1075.2.36 raeburn 10683: my @possdoms = ($cdom);
10684: if ($coursehash{'checkforpriv'}) {
10685: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10686: }
1.630 raeburn 10687: }
1.439 raeburn 10688: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10689: my $match = 0;
1.412 raeburn 10690: my $secmatch = 0;
1.439 raeburn 10691: my $status;
1.412 raeburn 10692: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10693: $user =~ s/:$//;
1.439 raeburn 10694: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10695: if ($end == -1 || $start == -1) {
10696: next;
10697: }
10698: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10699: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10700: my ($uname,$udom) = split(/:/,$user);
10701: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10702: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10703: $secmatch = 1;
10704: } elsif ($usec eq '') {
1.420 albertel 10705: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10706: $secmatch = 1;
10707: }
10708: } else {
10709: if (grep(/^\Q$usec\E$/,@{$sections})) {
10710: $secmatch = 1;
10711: }
10712: }
10713: if (!$secmatch) {
10714: next;
10715: }
1.288 raeburn 10716: }
1.419 raeburn 10717: if ($usec eq '') {
10718: $usec = 'none';
10719: }
1.275 raeburn 10720: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10721: if ($hidepriv) {
1.1075.2.36 raeburn 10722: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10723: (!$nothide{$uname.':'.$udom})) {
10724: next;
10725: }
10726: }
1.503 raeburn 10727: if ($end > 0 && $end < $now) {
1.439 raeburn 10728: $status = 'previous';
10729: } elsif ($start > $now) {
10730: $status = 'future';
10731: } else {
10732: $status = 'active';
10733: }
1.277 albertel 10734: foreach my $type (keys(%{$types})) {
1.275 raeburn 10735: if ($status eq $type) {
1.420 albertel 10736: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10737: push(@{$$users{$role}{$user}},$type);
10738: }
1.288 raeburn 10739: $match = 1;
10740: }
10741: }
1.419 raeburn 10742: if (($match) && (ref($userdata) eq 'HASH')) {
10743: if (!exists($$userdata{$uname.':'.$udom})) {
10744: &get_user_info($udom,$uname,\%idx,$userdata);
10745: }
1.420 albertel 10746: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10747: push(@{$seclists{$uname.':'.$udom}},$usec);
10748: }
1.609 raeburn 10749: if (ref($statushash) eq 'HASH') {
10750: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10751: }
1.275 raeburn 10752: }
10753: }
10754: }
10755: }
1.290 albertel 10756: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10757: if ((defined($cdom)) && (defined($cnum))) {
10758: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10759: if ( defined($csettings{'internal.courseowner'}) ) {
10760: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10761: next if ($owner eq '');
10762: my ($ownername,$ownerdom);
10763: if ($owner =~ /^([^:]+):([^:]+)$/) {
10764: $ownername = $1;
10765: $ownerdom = $2;
10766: } else {
10767: $ownername = $owner;
10768: $ownerdom = $cdom;
10769: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10770: }
10771: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10772: if (defined($userdata) &&
1.609 raeburn 10773: !exists($$userdata{$owner})) {
10774: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10775: if (!grep(/^none$/,@{$seclists{$owner}})) {
10776: push(@{$seclists{$owner}},'none');
10777: }
10778: if (ref($statushash) eq 'HASH') {
10779: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10780: }
1.290 albertel 10781: }
1.279 raeburn 10782: }
10783: }
10784: }
1.419 raeburn 10785: foreach my $user (keys(%seclists)) {
10786: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10787: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10788: }
1.275 raeburn 10789: }
10790: return;
10791: }
10792:
1.288 raeburn 10793: sub get_user_info {
10794: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10795: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10796: &plainname($uname,$udom,'lastname');
1.291 albertel 10797: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10798: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10799: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10800: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10801: return;
10802: }
1.275 raeburn 10803:
1.472 raeburn 10804: ###############################################
10805:
10806: =pod
10807:
10808: =item * &get_user_quota()
10809:
1.1075.2.41 raeburn 10810: Retrieves quota assigned for storage of user files.
10811: Default is to report quota for portfolio files.
1.472 raeburn 10812:
10813: Incoming parameters:
10814: 1. user's username
10815: 2. user's domain
1.1075.2.41 raeburn 10816: 3. quota name - portfolio, author, or course
10817: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10818: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10819: course
1.472 raeburn 10820:
10821: Returns:
1.1075.2.58 raeburn 10822: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10823: 2. (Optional) Type of setting: custom or default
10824: (individually assigned or default for user's
10825: institutional status).
10826: 3. (Optional) - User's institutional status (e.g., faculty, staff
10827: or student - types as defined in localenroll::inst_usertypes
10828: for user's domain, which determines default quota for user.
10829: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10830:
10831: If a value has been stored in the user's environment,
1.536 raeburn 10832: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10833: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10834:
10835: =cut
10836:
10837: ###############################################
10838:
10839:
10840: sub get_user_quota {
1.1075.2.42 raeburn 10841: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10842: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10843: if (!defined($udom)) {
10844: $udom = $env{'user.domain'};
10845: }
10846: if (!defined($uname)) {
10847: $uname = $env{'user.name'};
10848: }
10849: if (($udom eq '' || $uname eq '') ||
10850: ($udom eq 'public') && ($uname eq 'public')) {
10851: $quota = 0;
1.536 raeburn 10852: $quotatype = 'default';
10853: $defquota = 0;
1.472 raeburn 10854: } else {
1.536 raeburn 10855: my $inststatus;
1.1075.2.41 raeburn 10856: if ($quotaname eq 'course') {
10857: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10858: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10859: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10860: } else {
10861: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10862: $quota = $cenv{'internal.uploadquota'};
10863: }
1.536 raeburn 10864: } else {
1.1075.2.41 raeburn 10865: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10866: if ($quotaname eq 'author') {
10867: $quota = $env{'environment.authorquota'};
10868: } else {
10869: $quota = $env{'environment.portfolioquota'};
10870: }
10871: $inststatus = $env{'environment.inststatus'};
10872: } else {
10873: my %userenv =
10874: &Apache::lonnet::get('environment',['portfolioquota',
10875: 'authorquota','inststatus'],$udom,$uname);
10876: my ($tmp) = keys(%userenv);
10877: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10878: if ($quotaname eq 'author') {
10879: $quota = $userenv{'authorquota'};
10880: } else {
10881: $quota = $userenv{'portfolioquota'};
10882: }
10883: $inststatus = $userenv{'inststatus'};
10884: } else {
10885: undef(%userenv);
10886: }
10887: }
10888: }
10889: if ($quota eq '' || wantarray) {
10890: if ($quotaname eq 'course') {
10891: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10892: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10893: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10894: $defquota = $domdefs{$crstype.'quota'};
10895: }
10896: if ($defquota eq '') {
10897: $defquota = 500;
10898: }
1.1075.2.41 raeburn 10899: } else {
10900: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10901: }
10902: if ($quota eq '') {
10903: $quota = $defquota;
10904: $quotatype = 'default';
10905: } else {
10906: $quotatype = 'custom';
10907: }
1.472 raeburn 10908: }
10909: }
1.536 raeburn 10910: if (wantarray) {
10911: return ($quota,$quotatype,$settingstatus,$defquota);
10912: } else {
10913: return $quota;
10914: }
1.472 raeburn 10915: }
10916:
10917: ###############################################
10918:
10919: =pod
10920:
10921: =item * &default_quota()
10922:
1.536 raeburn 10923: Retrieves default quota assigned for storage of user portfolio files,
10924: given an (optional) user's institutional status.
1.472 raeburn 10925:
10926: Incoming parameters:
1.1075.2.42 raeburn 10927:
1.472 raeburn 10928: 1. domain
1.536 raeburn 10929: 2. (Optional) institutional status(es). This is a : separated list of
10930: status types (e.g., faculty, staff, student etc.)
10931: which apply to the user for whom the default is being retrieved.
10932: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10933: default quota will be returned.
10934: 3. quota name - portfolio, author, or course
10935: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10936:
10937: Returns:
1.1075.2.42 raeburn 10938:
1.1075.2.58 raeburn 10939: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10940: 2. (Optional) institutional type which determined the value of the
10941: default quota.
1.472 raeburn 10942:
10943: If a value has been stored in the domain's configuration db,
10944: it will return that, otherwise it returns 20 (for backwards
10945: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10946: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10947:
1.536 raeburn 10948: If the user's status includes multiple types (e.g., staff and student),
10949: the largest default quota which applies to the user determines the
10950: default quota returned.
10951:
1.472 raeburn 10952: =cut
10953:
10954: ###############################################
10955:
10956:
10957: sub default_quota {
1.1075.2.41 raeburn 10958: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10959: my ($defquota,$settingstatus);
10960: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10961: ['quotas'],$udom);
1.1075.2.41 raeburn 10962: my $key = 'defaultquota';
10963: if ($quotaname eq 'author') {
10964: $key = 'authorquota';
10965: }
1.622 raeburn 10966: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10967: if ($inststatus ne '') {
1.765 raeburn 10968: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10969: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10970: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10971: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10972: if ($defquota eq '') {
1.1075.2.41 raeburn 10973: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10974: $settingstatus = $item;
1.1075.2.41 raeburn 10975: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10976: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10977: $settingstatus = $item;
10978: }
10979: }
1.1075.2.41 raeburn 10980: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10981: if ($quotahash{'quotas'}{$item} ne '') {
10982: if ($defquota eq '') {
10983: $defquota = $quotahash{'quotas'}{$item};
10984: $settingstatus = $item;
10985: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10986: $defquota = $quotahash{'quotas'}{$item};
10987: $settingstatus = $item;
10988: }
1.536 raeburn 10989: }
10990: }
10991: }
10992: }
10993: if ($defquota eq '') {
1.1075.2.41 raeburn 10994: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10995: $defquota = $quotahash{'quotas'}{$key}{'default'};
10996: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10997: $defquota = $quotahash{'quotas'}{'default'};
10998: }
1.536 raeburn 10999: $settingstatus = 'default';
1.1075.2.42 raeburn 11000: if ($defquota eq '') {
11001: if ($quotaname eq 'author') {
11002: $defquota = 500;
11003: }
11004: }
1.536 raeburn 11005: }
11006: } else {
11007: $settingstatus = 'default';
1.1075.2.41 raeburn 11008: if ($quotaname eq 'author') {
11009: $defquota = 500;
11010: } else {
11011: $defquota = 20;
11012: }
1.536 raeburn 11013: }
11014: if (wantarray) {
11015: return ($defquota,$settingstatus);
1.472 raeburn 11016: } else {
1.536 raeburn 11017: return $defquota;
1.472 raeburn 11018: }
11019: }
11020:
1.1075.2.41 raeburn 11021: ###############################################
11022:
11023: =pod
11024:
1.1075.2.42 raeburn 11025: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 11026:
11027: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 11028: of existing file within authoring space will cause quota for the authoring
11029: space to be exceeded.
11030:
11031: Same, if upload of a file directly to a course/community via Course Editor
11032: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 11033:
1.1075.2.61 raeburn 11034: Inputs: 7
1.1075.2.42 raeburn 11035: 1. username or coursenum
1.1075.2.41 raeburn 11036: 2. domain
1.1075.2.42 raeburn 11037: 3. context ('author' or 'course')
1.1075.2.41 raeburn 11038: 4. filename of file for which action is being requested
11039: 5. filesize (kB) of file
11040: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 11041: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 11042:
11043: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
11044: otherwise return null.
11045:
1.1075.2.42 raeburn 11046: =back
11047:
1.1075.2.41 raeburn 11048: =cut
11049:
1.1075.2.42 raeburn 11050: sub excess_filesize_warning {
1.1075.2.59 raeburn 11051: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 11052: my $current_disk_usage = 0;
1.1075.2.59 raeburn 11053: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 11054: if ($context eq 'author') {
11055: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11056: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11057: } else {
11058: foreach my $subdir ('docs','supplemental') {
11059: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11060: }
11061: }
1.1075.2.41 raeburn 11062: $disk_quota = int($disk_quota * 1000);
11063: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 11064: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 11065: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 11066: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11067: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 11068: $disk_quota,$current_disk_usage).
11069: '</p>';
11070: }
11071: return;
11072: }
11073:
11074: ###############################################
11075:
11076:
1.384 raeburn 11077: sub get_secgrprole_info {
11078: my ($cdom,$cnum,$needroles,$type) = @_;
11079: my %sections_count = &get_sections($cdom,$cnum);
11080: my @sections = (sort {$a <=> $b} keys(%sections_count));
11081: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11082: my @groups = sort(keys(%curr_groups));
11083: my $allroles = [];
11084: my $rolehash;
11085: my $accesshash = {
11086: active => 'Currently has access',
11087: future => 'Will have future access',
11088: previous => 'Previously had access',
11089: };
11090: if ($needroles) {
11091: $rolehash = {'all' => 'all'};
1.385 albertel 11092: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11093: if (&Apache::lonnet::error(%user_roles)) {
11094: undef(%user_roles);
11095: }
11096: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11097: my ($role)=split(/\:/,$item,2);
11098: if ($role eq 'cr') { next; }
11099: if ($role =~ /^cr/) {
11100: $$rolehash{$role} = (split('/',$role))[3];
11101: } else {
11102: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11103: }
11104: }
11105: foreach my $key (sort(keys(%{$rolehash}))) {
11106: push(@{$allroles},$key);
11107: }
11108: push (@{$allroles},'st');
11109: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11110: }
11111: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11112: }
11113:
1.555 raeburn 11114: sub user_picker {
1.1075.2.127 raeburn 11115: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11116: my $currdom = $dom;
1.1075.2.114 raeburn 11117: my @alldoms = &Apache::lonnet::all_domains();
11118: if (@alldoms == 1) {
11119: my %domsrch = &Apache::lonnet::get_dom('configuration',
11120: ['directorysrch'],$alldoms[0]);
11121: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11122: my $showdom = $domdesc;
11123: if ($showdom eq '') {
11124: $showdom = $dom;
11125: }
11126: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11127: if ((!$domsrch{'directorysrch'}{'available'}) &&
11128: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11129: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11130: }
11131: }
11132: }
1.555 raeburn 11133: my %curr_selected = (
11134: srchin => 'dom',
1.580 raeburn 11135: srchby => 'lastname',
1.555 raeburn 11136: );
11137: my $srchterm;
1.625 raeburn 11138: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11139: if ($srch->{'srchby'} ne '') {
11140: $curr_selected{'srchby'} = $srch->{'srchby'};
11141: }
11142: if ($srch->{'srchin'} ne '') {
11143: $curr_selected{'srchin'} = $srch->{'srchin'};
11144: }
11145: if ($srch->{'srchtype'} ne '') {
11146: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11147: }
11148: if ($srch->{'srchdomain'} ne '') {
11149: $currdom = $srch->{'srchdomain'};
11150: }
11151: $srchterm = $srch->{'srchterm'};
11152: }
1.1075.2.98 raeburn 11153: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11154: 'usr' => 'Search criteria',
1.563 raeburn 11155: 'doma' => 'Domain/institution to search',
1.558 albertel 11156: 'uname' => 'username',
11157: 'lastname' => 'last name',
1.555 raeburn 11158: 'lastfirst' => 'last name, first name',
1.558 albertel 11159: 'crs' => 'in this course',
1.576 raeburn 11160: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11161: 'alc' => 'all LON-CAPA',
1.573 raeburn 11162: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11163: 'exact' => 'is',
11164: 'contains' => 'contains',
1.569 raeburn 11165: 'begins' => 'begins with',
1.1075.2.98 raeburn 11166: );
11167: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11168: 'youm' => "You must include some text to search for.",
11169: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11170: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11171: 'yomc' => "You must choose a domain when using an institutional directory search.",
11172: 'ymcd' => "You must choose a domain when using a domain search.",
11173: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11174: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11175: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11176: );
1.1075.2.98 raeburn 11177: &html_escape(\%html_lt);
11178: &js_escape(\%js_lt);
1.1075.2.115 raeburn 11179: my $domform;
1.1075.2.126 raeburn 11180: my $allow_blank = 1;
1.1075.2.115 raeburn 11181: if ($fixeddom) {
1.1075.2.126 raeburn 11182: $allow_blank = 0;
11183: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 11184: } else {
1.1075.2.126 raeburn 11185: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 11186: }
1.563 raeburn 11187: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11188:
11189: my @srchins = ('crs','dom','alc','instd');
11190:
11191: foreach my $option (@srchins) {
11192: # FIXME 'alc' option unavailable until
11193: # loncreateuser::print_user_query_page()
11194: # has been completed.
11195: next if ($option eq 'alc');
1.880 raeburn 11196: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11197: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 11198: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11199: if ($curr_selected{'srchin'} eq $option) {
11200: $srchinsel .= '
1.1075.2.98 raeburn 11201: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11202: } else {
11203: $srchinsel .= '
1.1075.2.98 raeburn 11204: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11205: }
1.555 raeburn 11206: }
1.563 raeburn 11207: $srchinsel .= "\n </select>\n";
1.555 raeburn 11208:
11209: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11210: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11211: if ($curr_selected{'srchby'} eq $option) {
11212: $srchbysel .= '
1.1075.2.98 raeburn 11213: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11214: } else {
11215: $srchbysel .= '
1.1075.2.98 raeburn 11216: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11217: }
11218: }
11219: $srchbysel .= "\n </select>\n";
11220:
11221: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11222: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11223: if ($curr_selected{'srchtype'} eq $option) {
11224: $srchtypesel .= '
1.1075.2.98 raeburn 11225: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11226: } else {
11227: $srchtypesel .= '
1.1075.2.98 raeburn 11228: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11229: }
11230: }
11231: $srchtypesel .= "\n </select>\n";
11232:
1.558 albertel 11233: my ($newuserscript,$new_user_create);
1.994 raeburn 11234: my $context_dom = $env{'request.role.domain'};
11235: if ($context eq 'requestcrs') {
11236: if ($env{'form.coursedom'} ne '') {
11237: $context_dom = $env{'form.coursedom'};
11238: }
11239: }
1.556 raeburn 11240: if ($forcenewuser) {
1.576 raeburn 11241: if (ref($srch) eq 'HASH') {
1.994 raeburn 11242: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11243: if ($cancreate) {
11244: $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>';
11245: } else {
1.799 bisitz 11246: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11247: my %usertypetext = (
11248: official => 'institutional',
11249: unofficial => 'non-institutional',
11250: );
1.799 bisitz 11251: $new_user_create = '<p class="LC_warning">'
11252: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11253: .' '
11254: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11255: ,'<a href="'.$helplink.'">','</a>')
11256: .'</p><br />';
1.627 raeburn 11257: }
1.576 raeburn 11258: }
11259: }
11260:
1.556 raeburn 11261: $newuserscript = <<"ENDSCRIPT";
11262:
1.570 raeburn 11263: function setSearch(createnew,callingForm) {
1.556 raeburn 11264: if (createnew == 1) {
1.570 raeburn 11265: for (var i=0; i<callingForm.srchby.length; i++) {
11266: if (callingForm.srchby.options[i].value == 'uname') {
11267: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11268: }
11269: }
1.570 raeburn 11270: for (var i=0; i<callingForm.srchin.length; i++) {
11271: if ( callingForm.srchin.options[i].value == 'dom') {
11272: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11273: }
11274: }
1.570 raeburn 11275: for (var i=0; i<callingForm.srchtype.length; i++) {
11276: if (callingForm.srchtype.options[i].value == 'exact') {
11277: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11278: }
11279: }
1.570 raeburn 11280: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11281: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11282: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11283: }
11284: }
11285: }
11286: }
11287: ENDSCRIPT
1.558 albertel 11288:
1.556 raeburn 11289: }
11290:
1.555 raeburn 11291: my $output = <<"END_BLOCK";
1.556 raeburn 11292: <script type="text/javascript">
1.824 bisitz 11293: // <![CDATA[
1.570 raeburn 11294: function validateEntry(callingForm) {
1.558 albertel 11295:
1.556 raeburn 11296: var checkok = 1;
1.558 albertel 11297: var srchin;
1.570 raeburn 11298: for (var i=0; i<callingForm.srchin.length; i++) {
11299: if ( callingForm.srchin[i].checked ) {
11300: srchin = callingForm.srchin[i].value;
1.558 albertel 11301: }
11302: }
11303:
1.570 raeburn 11304: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11305: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11306: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11307: var srchterm = callingForm.srchterm.value;
11308: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11309: var msg = "";
11310:
11311: if (srchterm == "") {
11312: checkok = 0;
1.1075.2.98 raeburn 11313: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11314: }
11315:
1.569 raeburn 11316: if (srchtype== 'begins') {
11317: if (srchterm.length < 2) {
11318: checkok = 0;
1.1075.2.98 raeburn 11319: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11320: }
11321: }
11322:
1.556 raeburn 11323: if (srchtype== 'contains') {
11324: if (srchterm.length < 3) {
11325: checkok = 0;
1.1075.2.98 raeburn 11326: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11327: }
11328: }
11329: if (srchin == 'instd') {
11330: if (srchdomain == '') {
11331: checkok = 0;
1.1075.2.98 raeburn 11332: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11333: }
11334: }
11335: if (srchin == 'dom') {
11336: if (srchdomain == '') {
11337: checkok = 0;
1.1075.2.98 raeburn 11338: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11339: }
11340: }
11341: if (srchby == 'lastfirst') {
11342: if (srchterm.indexOf(",") == -1) {
11343: checkok = 0;
1.1075.2.98 raeburn 11344: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11345: }
11346: if (srchterm.indexOf(",") == srchterm.length -1) {
11347: checkok = 0;
1.1075.2.98 raeburn 11348: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11349: }
11350: }
11351: if (checkok == 0) {
1.1075.2.98 raeburn 11352: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11353: return;
11354: }
11355: if (checkok == 1) {
1.570 raeburn 11356: callingForm.submit();
1.556 raeburn 11357: }
11358: }
11359:
11360: $newuserscript
11361:
1.824 bisitz 11362: // ]]>
1.556 raeburn 11363: </script>
1.558 albertel 11364:
11365: $new_user_create
11366:
1.555 raeburn 11367: END_BLOCK
1.558 albertel 11368:
1.876 raeburn 11369: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 11370: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11371: $domform.
11372: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 11373: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11374: $srchbysel.
11375: $srchtypesel.
11376: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11377: $srchinsel.
11378: &Apache::lonhtmlcommon::row_closure(1).
11379: &Apache::lonhtmlcommon::end_pick_box().
11380: '<br />';
1.1075.2.114 raeburn 11381: return ($output,1);
1.555 raeburn 11382: }
11383:
1.612 raeburn 11384: sub user_rule_check {
1.615 raeburn 11385: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 11386: my ($response,%inst_response);
1.612 raeburn 11387: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 11388: if (keys(%{$usershash}) > 1) {
11389: my (%by_username,%by_id,%userdoms);
11390: my $checkid;
1.612 raeburn 11391: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 11392: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11393: $checkid = 1;
11394: }
11395: }
11396: foreach my $user (keys(%{$usershash})) {
11397: my ($uname,$udom) = split(/:/,$user);
11398: if ($checkid) {
11399: if (ref($usershash->{$user}) eq 'HASH') {
11400: if ($usershash->{$user}->{'id'} ne '') {
11401: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
11402: $userdoms{$udom} = 1;
11403: if (ref($inst_results) eq 'HASH') {
11404: $inst_results->{$uname.':'.$udom} = {};
11405: }
11406: }
11407: }
11408: } else {
11409: $by_username{$udom}{$uname} = 1;
11410: $userdoms{$udom} = 1;
11411: if (ref($inst_results) eq 'HASH') {
11412: $inst_results->{$uname.':'.$udom} = {};
11413: }
11414: }
11415: }
11416: foreach my $udom (keys(%userdoms)) {
11417: if (!$got_rules->{$udom}) {
11418: my %domconfig = &Apache::lonnet::get_dom('configuration',
11419: ['usercreation'],$udom);
11420: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11421: foreach my $item ('username','id') {
11422: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11423: $$curr_rules{$udom}{$item} =
11424: $domconfig{'usercreation'}{$item.'_rule'};
11425: }
11426: }
11427: }
11428: $got_rules->{$udom} = 1;
11429: }
11430: }
11431: if ($checkid) {
11432: foreach my $udom (keys(%by_id)) {
11433: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11434: if ($outcome eq 'ok') {
11435: foreach my $id (keys(%{$by_id{$udom}})) {
11436: my $uname = $by_id{$udom}{$id};
11437: $inst_response{$uname.':'.$udom} = $outcome;
11438: }
11439: if (ref($results) eq 'HASH') {
11440: foreach my $uname (keys(%{$results})) {
11441: if (exists($inst_response{$uname.':'.$udom})) {
11442: $inst_response{$uname.':'.$udom} = $outcome;
11443: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11444: }
11445: }
11446: }
11447: }
1.612 raeburn 11448: }
1.615 raeburn 11449: } else {
1.1075.2.99 raeburn 11450: foreach my $udom (keys(%by_username)) {
11451: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11452: if ($outcome eq 'ok') {
11453: foreach my $uname (keys(%{$by_username{$udom}})) {
11454: $inst_response{$uname.':'.$udom} = $outcome;
11455: }
11456: if (ref($results) eq 'HASH') {
11457: foreach my $uname (keys(%{$results})) {
11458: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11459: }
11460: }
11461: }
11462: }
1.612 raeburn 11463: }
1.1075.2.99 raeburn 11464: } elsif (keys(%{$usershash}) == 1) {
11465: my $user = (keys(%{$usershash}))[0];
11466: my ($uname,$udom) = split(/:/,$user);
11467: if (($udom ne '') && ($uname ne '')) {
11468: if (ref($usershash->{$user}) eq 'HASH') {
11469: if (ref($checks) eq 'HASH') {
11470: if (defined($checks->{'username'})) {
11471: ($inst_response{$user},%{$inst_results->{$user}}) =
11472: &Apache::lonnet::get_instuser($udom,$uname);
11473: } elsif (defined($checks->{'id'})) {
11474: if ($usershash->{$user}->{'id'} ne '') {
11475: ($inst_response{$user},%{$inst_results->{$user}}) =
11476: &Apache::lonnet::get_instuser($udom,undef,
11477: $usershash->{$user}->{'id'});
11478: } else {
11479: ($inst_response{$user},%{$inst_results->{$user}}) =
11480: &Apache::lonnet::get_instuser($udom,$uname);
11481: }
11482: }
11483: } else {
11484: ($inst_response{$user},%{$inst_results->{$user}}) =
11485: &Apache::lonnet::get_instuser($udom,$uname);
11486: return;
11487: }
11488: if (!$got_rules->{$udom}) {
11489: my %domconfig = &Apache::lonnet::get_dom('configuration',
11490: ['usercreation'],$udom);
11491: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11492: foreach my $item ('username','id') {
11493: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11494: $$curr_rules{$udom}{$item} =
11495: $domconfig{'usercreation'}{$item.'_rule'};
11496: }
11497: }
1.585 raeburn 11498: }
1.1075.2.99 raeburn 11499: $got_rules->{$udom} = 1;
1.585 raeburn 11500: }
11501: }
1.1075.2.99 raeburn 11502: } else {
11503: return;
11504: }
11505: } else {
11506: return;
11507: }
11508: foreach my $user (keys(%{$usershash})) {
11509: my ($uname,$udom) = split(/:/,$user);
11510: next if (($udom eq '') || ($uname eq ''));
11511: my $id;
11512: if (ref($inst_results) eq 'HASH') {
11513: if (ref($inst_results->{$user}) eq 'HASH') {
11514: $id = $inst_results->{$user}->{'id'};
11515: }
11516: }
11517: if ($id eq '') {
11518: if (ref($usershash->{$user})) {
11519: $id = $usershash->{$user}->{'id'};
11520: }
1.585 raeburn 11521: }
1.612 raeburn 11522: foreach my $item (keys(%{$checks})) {
11523: if (ref($$curr_rules{$udom}) eq 'HASH') {
11524: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11525: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 11526: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11527: $$curr_rules{$udom}{$item});
1.612 raeburn 11528: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11529: if ($rule_check{$rule}) {
11530: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 11531: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11532: if (ref($inst_results) eq 'HASH') {
11533: if (ref($inst_results->{$user}) eq 'HASH') {
11534: if (keys(%{$inst_results->{$user}}) == 0) {
11535: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 11536: } elsif ($item eq 'id') {
11537: if ($inst_results->{$user}->{'id'} eq '') {
11538: $$alerts{$item}{$udom}{$uname} = 1;
11539: }
1.615 raeburn 11540: }
1.612 raeburn 11541: }
11542: }
1.615 raeburn 11543: }
11544: last;
1.585 raeburn 11545: }
11546: }
11547: }
11548: }
11549: }
11550: }
11551: }
11552: }
1.612 raeburn 11553: return;
11554: }
11555:
11556: sub user_rule_formats {
11557: my ($domain,$domdesc,$curr_rules,$check) = @_;
11558: my %text = (
11559: 'username' => 'Usernames',
11560: 'id' => 'IDs',
11561: );
11562: my $output;
11563: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11564: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11565: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 11566: $output = '<br />'.
11567: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11568: '<span class="LC_cusr_emph">','</span>',$domdesc).
11569: ' <ul>';
1.612 raeburn 11570: foreach my $rule (@{$ruleorder}) {
11571: if (ref($curr_rules) eq 'ARRAY') {
11572: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11573: if (ref($rules->{$rule}) eq 'HASH') {
11574: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11575: $rules->{$rule}{'desc'}.'</li>';
11576: }
11577: }
11578: }
11579: }
11580: $output .= '</ul>';
11581: }
11582: }
11583: return $output;
11584: }
11585:
11586: sub instrule_disallow_msg {
1.615 raeburn 11587: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11588: my $response;
11589: my %text = (
11590: item => 'username',
11591: items => 'usernames',
11592: match => 'matches',
11593: do => 'does',
11594: action => 'a username',
11595: one => 'one',
11596: );
11597: if ($count > 1) {
11598: $text{'item'} = 'usernames';
11599: $text{'match'} ='match';
11600: $text{'do'} = 'do';
11601: $text{'action'} = 'usernames',
11602: $text{'one'} = 'ones';
11603: }
11604: if ($checkitem eq 'id') {
11605: $text{'items'} = 'IDs';
11606: $text{'item'} = 'ID';
11607: $text{'action'} = 'an ID';
1.615 raeburn 11608: if ($count > 1) {
11609: $text{'item'} = 'IDs';
11610: $text{'action'} = 'IDs';
11611: }
1.612 raeburn 11612: }
1.674 bisitz 11613: $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 11614: if ($mode eq 'upload') {
11615: if ($checkitem eq 'username') {
11616: $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'}.");
11617: } elsif ($checkitem eq 'id') {
1.674 bisitz 11618: $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 11619: }
1.669 raeburn 11620: } elsif ($mode eq 'selfcreate') {
11621: if ($checkitem eq 'id') {
11622: $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.");
11623: }
1.615 raeburn 11624: } else {
11625: if ($checkitem eq 'username') {
11626: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11627: } elsif ($checkitem eq 'id') {
11628: $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.");
11629: }
1.612 raeburn 11630: }
11631: return $response;
1.585 raeburn 11632: }
11633:
1.624 raeburn 11634: sub personal_data_fieldtitles {
11635: my %fieldtitles = &Apache::lonlocal::texthash (
11636: id => 'Student/Employee ID',
11637: permanentemail => 'E-mail address',
11638: lastname => 'Last Name',
11639: firstname => 'First Name',
11640: middlename => 'Middle Name',
11641: generation => 'Generation',
11642: gen => 'Generation',
1.765 raeburn 11643: inststatus => 'Affiliation',
1.624 raeburn 11644: );
11645: return %fieldtitles;
11646: }
11647:
1.642 raeburn 11648: sub sorted_inst_types {
11649: my ($dom) = @_;
1.1075.2.70 raeburn 11650: my ($usertypes,$order);
11651: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11652: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11653: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11654: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11655: } else {
11656: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11657: }
1.642 raeburn 11658: my $othertitle = &mt('All users');
11659: if ($env{'request.course.id'}) {
1.668 raeburn 11660: $othertitle = &mt('Any users');
1.642 raeburn 11661: }
11662: my @types;
11663: if (ref($order) eq 'ARRAY') {
11664: @types = @{$order};
11665: }
11666: if (@types == 0) {
11667: if (ref($usertypes) eq 'HASH') {
11668: @types = sort(keys(%{$usertypes}));
11669: }
11670: }
11671: if (keys(%{$usertypes}) > 0) {
11672: $othertitle = &mt('Other users');
11673: }
11674: return ($othertitle,$usertypes,\@types);
11675: }
11676:
1.645 raeburn 11677: sub get_institutional_codes {
1.1075.2.157 raeburn 11678: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11679: # Get complete list of course sections to update
11680: my @currsections = ();
11681: my @currxlists = ();
1.1075.2.157 raeburn 11682: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11683: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11684: my $crskey = $crs.':'.$coursecode;
11685: @{$unclutteredsec{$crskey}} = ();
11686: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11687:
11688: if ($$settings{'internal.sectionnums'} ne '') {
11689: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11690: }
11691:
11692: if ($$settings{'internal.crosslistings'} ne '') {
11693: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11694: }
11695:
11696: if (@currxlists > 0) {
1.1075.2.157 raeburn 11697: foreach my $xl (@currxlists) {
11698: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11699: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11700: push(@{$allcourses},$1);
1.645 raeburn 11701: $$LC_code{$1} = $2;
11702: }
11703: }
11704: }
11705: }
1.1075.2.157 raeburn 11706:
1.645 raeburn 11707: if (@currsections > 0) {
1.1075.2.157 raeburn 11708: foreach my $sec (@currsections) {
11709: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11710: my $instsec = $1;
1.645 raeburn 11711: my $lc_sec = $2;
1.1075.2.157 raeburn 11712: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11713: push(@{$unclutteredsec{$crskey}},$instsec);
11714: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11715: }
11716: }
11717: }
11718: }
11719:
11720: if (@{$unclutteredsec{$crskey}} > 0) {
11721: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11722: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11723: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11724: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11725: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11726: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11727: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11728: }
11729: }
11730: }
11731: }
11732: return;
11733: }
11734:
1.971 raeburn 11735: sub get_standard_codeitems {
11736: return ('Year','Semester','Department','Number','Section');
11737: }
11738:
1.112 bowersj2 11739: =pod
11740:
1.780 raeburn 11741: =head1 Slot Helpers
11742:
11743: =over 4
11744:
11745: =item * sorted_slots()
11746:
1.1040 raeburn 11747: Sorts an array of slot names in order of an optional sort key,
11748: default sort is by slot start time (earliest first).
1.780 raeburn 11749:
11750: Inputs:
11751:
11752: =over 4
11753:
11754: slotsarr - Reference to array of unsorted slot names.
11755:
11756: slots - Reference to hash of hash, where outer hash keys are slot names.
11757:
1.1040 raeburn 11758: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11759:
1.549 albertel 11760: =back
11761:
1.780 raeburn 11762: Returns:
11763:
11764: =over 4
11765:
1.1040 raeburn 11766: sorted - An array of slot names sorted by a specified sort key
11767: (default sort key is start time of the slot).
1.780 raeburn 11768:
11769: =back
11770:
11771: =cut
11772:
11773:
11774: sub sorted_slots {
1.1040 raeburn 11775: my ($slotsarr,$slots,$sortkey) = @_;
11776: if ($sortkey eq '') {
11777: $sortkey = 'starttime';
11778: }
1.780 raeburn 11779: my @sorted;
11780: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11781: @sorted =
11782: sort {
11783: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11784: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11785: }
11786: if (ref($slots->{$a})) { return -1;}
11787: if (ref($slots->{$b})) { return 1;}
11788: return 0;
11789: } @{$slotsarr};
11790: }
11791: return @sorted;
11792: }
11793:
1.1040 raeburn 11794: =pod
11795:
11796: =item * get_future_slots()
11797:
11798: Inputs:
11799:
11800: =over 4
11801:
11802: cnum - course number
11803:
11804: cdom - course domain
11805:
11806: now - current UNIX time
11807:
11808: symb - optional symb
11809:
11810: =back
11811:
11812: Returns:
11813:
11814: =over 4
11815:
11816: sorted_reservable - ref to array of student_schedulable slots currently
11817: reservable, ordered by end date of reservation period.
11818:
11819: reservable_now - ref to hash of student_schedulable slots currently
11820: reservable.
11821:
11822: Keys in inner hash are:
11823: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11824: (b) endreserve: end date of reservation period.
11825: (c) uniqueperiod: start,end dates when slot is to be uniquely
11826: selected.
1.1040 raeburn 11827:
11828: sorted_future - ref to array of student_schedulable slots reservable in
11829: the future, ordered by start date of reservation period.
11830:
11831: future_reservable - ref to hash of student_schedulable slots reservable
11832: in the future.
11833:
11834: Keys in inner hash are:
11835: (a) symb: either blank or symb to which slot use is restricted.
11836: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11837: (c) uniqueperiod: start,end dates when slot is to be uniquely
11838: selected.
1.1040 raeburn 11839:
11840: =back
11841:
11842: =cut
11843:
11844: sub get_future_slots {
11845: my ($cnum,$cdom,$now,$symb) = @_;
11846: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11847: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11848: foreach my $slot (keys(%slots)) {
11849: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11850: if ($symb) {
11851: next if (($slots{$slot}->{'symb'} ne '') &&
11852: ($slots{$slot}->{'symb'} ne $symb));
11853: }
11854: if (($slots{$slot}->{'starttime'} > $now) &&
11855: ($slots{$slot}->{'endtime'} > $now)) {
11856: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11857: my $userallowed = 0;
11858: if ($slots{$slot}->{'allowedsections'}) {
11859: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11860: if (!defined($env{'request.role.sec'})
11861: && grep(/^No section assigned$/,@allowed_sec)) {
11862: $userallowed=1;
11863: } else {
11864: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11865: $userallowed=1;
11866: }
11867: }
11868: unless ($userallowed) {
11869: if (defined($env{'request.course.groups'})) {
11870: my @groups = split(/:/,$env{'request.course.groups'});
11871: foreach my $group (@groups) {
11872: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11873: $userallowed=1;
11874: last;
11875: }
11876: }
11877: }
11878: }
11879: }
11880: if ($slots{$slot}->{'allowedusers'}) {
11881: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11882: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11883: if (grep(/^\Q$user\E$/,@allowed_users)) {
11884: $userallowed = 1;
11885: }
11886: }
11887: next unless($userallowed);
11888: }
11889: my $startreserve = $slots{$slot}->{'startreserve'};
11890: my $endreserve = $slots{$slot}->{'endreserve'};
11891: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11892: my $uniqueperiod;
11893: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11894: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11895: }
1.1040 raeburn 11896: if (($startreserve < $now) &&
11897: (!$endreserve || $endreserve > $now)) {
11898: my $lastres = $endreserve;
11899: if (!$lastres) {
11900: $lastres = $slots{$slot}->{'starttime'};
11901: }
11902: $reservable_now{$slot} = {
11903: symb => $symb,
1.1075.2.104 raeburn 11904: endreserve => $lastres,
11905: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11906: };
11907: } elsif (($startreserve > $now) &&
11908: (!$endreserve || $endreserve > $startreserve)) {
11909: $future_reservable{$slot} = {
11910: symb => $symb,
1.1075.2.104 raeburn 11911: startreserve => $startreserve,
11912: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11913: };
11914: }
11915: }
11916: }
11917: my @unsorted_reservable = keys(%reservable_now);
11918: if (@unsorted_reservable > 0) {
11919: @sorted_reservable =
11920: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11921: }
11922: my @unsorted_future = keys(%future_reservable);
11923: if (@unsorted_future > 0) {
11924: @sorted_future =
11925: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11926: }
11927: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11928: }
1.780 raeburn 11929:
11930: =pod
11931:
1.1057 foxr 11932: =back
11933:
1.549 albertel 11934: =head1 HTTP Helpers
11935:
11936: =over 4
11937:
1.648 raeburn 11938: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11939:
1.258 albertel 11940: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11941: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11942: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11943:
11944: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11945: $possible_names is an ref to an array of form element names. As an example:
11946: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11947: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11948:
11949: =cut
1.1 albertel 11950:
1.6 albertel 11951: sub get_unprocessed_cgi {
1.25 albertel 11952: my ($query,$possible_names)= @_;
1.26 matthew 11953: # $Apache::lonxml::debug=1;
1.356 albertel 11954: foreach my $pair (split(/&/,$query)) {
11955: my ($name, $value) = split(/=/,$pair);
1.369 www 11956: $name = &unescape($name);
1.25 albertel 11957: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11958: $value =~ tr/+/ /;
11959: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11960: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11961: }
1.16 harris41 11962: }
1.6 albertel 11963: }
11964:
1.112 bowersj2 11965: =pod
11966:
1.648 raeburn 11967: =item * &cacheheader()
1.112 bowersj2 11968:
11969: returns cache-controlling header code
11970:
11971: =cut
11972:
1.7 albertel 11973: sub cacheheader {
1.258 albertel 11974: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11975: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11976: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11977: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11978: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11979: return $output;
1.7 albertel 11980: }
11981:
1.112 bowersj2 11982: =pod
11983:
1.648 raeburn 11984: =item * &no_cache($r)
1.112 bowersj2 11985:
11986: specifies header code to not have cache
11987:
11988: =cut
11989:
1.9 albertel 11990: sub no_cache {
1.216 albertel 11991: my ($r) = @_;
11992: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11993: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11994: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11995: $r->no_cache(1);
11996: $r->header_out("Expires" => $date);
11997: $r->header_out("Pragma" => "no-cache");
1.123 www 11998: }
11999:
12000: sub content_type {
1.181 albertel 12001: my ($r,$type,$charset) = @_;
1.299 foxr 12002: if ($r) {
12003: # Note that printout.pl calls this with undef for $r.
12004: &no_cache($r);
12005: }
1.258 albertel 12006: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12007: unless ($charset) {
12008: $charset=&Apache::lonlocal::current_encoding;
12009: }
12010: if ($charset) { $type.='; charset='.$charset; }
12011: if ($r) {
12012: $r->content_type($type);
12013: } else {
12014: print("Content-type: $type\n\n");
12015: }
1.9 albertel 12016: }
1.25 albertel 12017:
1.112 bowersj2 12018: =pod
12019:
1.648 raeburn 12020: =item * &add_to_env($name,$value)
1.112 bowersj2 12021:
1.258 albertel 12022: adds $name to the %env hash with value
1.112 bowersj2 12023: $value, if $name already exists, the entry is converted to an array
12024: reference and $value is added to the array.
12025:
12026: =cut
12027:
1.25 albertel 12028: sub add_to_env {
12029: my ($name,$value)=@_;
1.258 albertel 12030: if (defined($env{$name})) {
12031: if (ref($env{$name})) {
1.25 albertel 12032: #already have multiple values
1.258 albertel 12033: push(@{ $env{$name} },$value);
1.25 albertel 12034: } else {
12035: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12036: my $first=$env{$name};
12037: undef($env{$name});
12038: push(@{ $env{$name} },$first,$value);
1.25 albertel 12039: }
12040: } else {
1.258 albertel 12041: $env{$name}=$value;
1.25 albertel 12042: }
1.31 albertel 12043: }
1.149 albertel 12044:
12045: =pod
12046:
1.648 raeburn 12047: =item * &get_env_multiple($name)
1.149 albertel 12048:
1.258 albertel 12049: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12050: values may be defined and end up as an array ref.
12051:
12052: returns an array of values
12053:
12054: =cut
12055:
12056: sub get_env_multiple {
12057: my ($name) = @_;
12058: my @values;
1.258 albertel 12059: if (defined($env{$name})) {
1.149 albertel 12060: # exists is it an array
1.258 albertel 12061: if (ref($env{$name})) {
12062: @values=@{ $env{$name} };
1.149 albertel 12063: } else {
1.258 albertel 12064: $values[0]=$env{$name};
1.149 albertel 12065: }
12066: }
12067: return(@values);
12068: }
12069:
1.660 raeburn 12070: sub ask_for_embedded_content {
12071: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12072: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 12073: %currsubfile,%unused,$rem);
1.1071 raeburn 12074: my $counter = 0;
12075: my $numnew = 0;
1.987 raeburn 12076: my $numremref = 0;
12077: my $numinvalid = 0;
12078: my $numpathchg = 0;
12079: my $numexisting = 0;
1.1071 raeburn 12080: my $numunused = 0;
12081: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 12082: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12083: my $heading = &mt('Upload embedded files');
12084: my $buttontext = &mt('Upload');
12085:
1.1075.2.11 raeburn 12086: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 12087: if ($actionurl eq '/adm/dependencies') {
12088: $navmap = Apache::lonnavmaps::navmap->new();
12089: }
12090: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12091: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 12092: }
1.1075.2.35 raeburn 12093: if (($actionurl eq '/adm/portfolio') ||
12094: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12095: my $current_path='/';
12096: if ($env{'form.currentpath'}) {
12097: $current_path = $env{'form.currentpath'};
12098: }
12099: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 12100: $udom = $cdom;
12101: $uname = $cnum;
1.984 raeburn 12102: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12103: } else {
12104: $udom = $env{'user.domain'};
12105: $uname = $env{'user.name'};
12106: $url = '/userfiles/portfolio';
12107: }
1.987 raeburn 12108: $toplevel = $url.'/';
1.984 raeburn 12109: $url .= $current_path;
12110: $getpropath = 1;
1.987 raeburn 12111: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12112: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12113: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12114: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12115: $toplevel = $url;
1.984 raeburn 12116: if ($rest ne '') {
1.987 raeburn 12117: $url .= $rest;
12118: }
12119: } elsif ($actionurl eq '/adm/coursedocs') {
12120: if (ref($args) eq 'HASH') {
1.1071 raeburn 12121: $url = $args->{'docs_url'};
12122: $toplevel = $url;
1.1075.2.11 raeburn 12123: if ($args->{'context'} eq 'paste') {
12124: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12125: ($path) =
12126: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12127: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12128: $fileloc =~ s{^/}{};
12129: }
1.1071 raeburn 12130: }
12131: } elsif ($actionurl eq '/adm/dependencies') {
12132: if ($env{'request.course.id'} ne '') {
12133: if (ref($args) eq 'HASH') {
12134: $url = $args->{'docs_url'};
12135: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 12136: $toplevel = $url;
12137: unless ($toplevel =~ m{^/}) {
12138: $toplevel = "/$url";
12139: }
1.1075.2.11 raeburn 12140: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 12141: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12142: $path = $1;
12143: } else {
12144: ($path) =
12145: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12146: }
1.1075.2.79 raeburn 12147: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12148: $fileloc = $toplevel;
12149: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12150: my ($udom,$uname,$fname) =
12151: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12152: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12153: } else {
12154: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12155: }
1.1071 raeburn 12156: $fileloc =~ s{^/}{};
12157: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12158: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12159: }
1.987 raeburn 12160: }
1.1075.2.35 raeburn 12161: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12162: $udom = $cdom;
12163: $uname = $cnum;
12164: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12165: $toplevel = $url;
12166: $path = $url;
12167: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12168: $fileloc =~ s{^/}{};
12169: }
12170: foreach my $file (keys(%{$allfiles})) {
12171: my $embed_file;
12172: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12173: $embed_file = $1;
12174: } else {
12175: $embed_file = $file;
12176: }
1.1075.2.55 raeburn 12177: my ($absolutepath,$cleaned_file);
12178: if ($embed_file =~ m{^\w+://}) {
12179: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 12180: $newfiles{$cleaned_file} = 1;
12181: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12182: } else {
1.1075.2.55 raeburn 12183: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12184: if ($embed_file =~ m{^/}) {
12185: $absolutepath = $embed_file;
12186: }
1.1075.2.47 raeburn 12187: if ($cleaned_file =~ m{/}) {
12188: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12189: $path = &check_for_traversal($path,$url,$toplevel);
12190: my $item = $fname;
12191: if ($path ne '') {
12192: $item = $path.'/'.$fname;
12193: $subdependencies{$path}{$fname} = 1;
12194: } else {
12195: $dependencies{$item} = 1;
12196: }
12197: if ($absolutepath) {
12198: $mapping{$item} = $absolutepath;
12199: } else {
12200: $mapping{$item} = $embed_file;
12201: }
12202: } else {
12203: $dependencies{$embed_file} = 1;
12204: if ($absolutepath) {
1.1075.2.47 raeburn 12205: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12206: } else {
1.1075.2.47 raeburn 12207: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12208: }
12209: }
1.984 raeburn 12210: }
12211: }
1.1071 raeburn 12212: my $dirptr = 16384;
1.984 raeburn 12213: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12214: $currsubfile{$path} = {};
1.1075.2.35 raeburn 12215: if (($actionurl eq '/adm/portfolio') ||
12216: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12217: my ($sublistref,$listerror) =
12218: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12219: if (ref($sublistref) eq 'ARRAY') {
12220: foreach my $line (@{$sublistref}) {
12221: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12222: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12223: }
1.984 raeburn 12224: }
1.987 raeburn 12225: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12226: if (opendir(my $dir,$url.'/'.$path)) {
12227: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12228: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12229: }
1.1075.2.11 raeburn 12230: } elsif (($actionurl eq '/adm/dependencies') ||
12231: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12232: ($args->{'context'} eq 'paste')) ||
12233: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12234: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 12235: my $dir;
12236: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12237: $dir = $fileloc;
12238: } else {
12239: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12240: }
1.1071 raeburn 12241: if ($dir ne '') {
12242: my ($sublistref,$listerror) =
12243: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12244: if (ref($sublistref) eq 'ARRAY') {
12245: foreach my $line (@{$sublistref}) {
12246: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12247: undef,$mtime)=split(/\&/,$line,12);
12248: unless (($testdir&$dirptr) ||
12249: ($file_name =~ /^\.\.?$/)) {
12250: $currsubfile{$path}{$file_name} = [$size,$mtime];
12251: }
12252: }
12253: }
12254: }
1.984 raeburn 12255: }
12256: }
12257: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12258: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12259: my $item = $path.'/'.$file;
12260: unless ($mapping{$item} eq $item) {
12261: $pathchanges{$item} = 1;
12262: }
12263: $existing{$item} = 1;
12264: $numexisting ++;
12265: } else {
12266: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12267: }
12268: }
1.1071 raeburn 12269: if ($actionurl eq '/adm/dependencies') {
12270: foreach my $path (keys(%currsubfile)) {
12271: if (ref($currsubfile{$path}) eq 'HASH') {
12272: foreach my $file (keys(%{$currsubfile{$path}})) {
12273: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 12274: next if (($rem ne '') &&
12275: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12276: (ref($navmap) &&
12277: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12278: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12279: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12280: $unused{$path.'/'.$file} = 1;
12281: }
12282: }
12283: }
12284: }
12285: }
1.984 raeburn 12286: }
1.987 raeburn 12287: my %currfile;
1.1075.2.35 raeburn 12288: if (($actionurl eq '/adm/portfolio') ||
12289: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12290: my ($dirlistref,$listerror) =
12291: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12292: if (ref($dirlistref) eq 'ARRAY') {
12293: foreach my $line (@{$dirlistref}) {
12294: my ($file_name,$rest) = split(/\&/,$line,2);
12295: $currfile{$file_name} = 1;
12296: }
1.984 raeburn 12297: }
1.987 raeburn 12298: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12299: if (opendir(my $dir,$url)) {
1.987 raeburn 12300: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12301: map {$currfile{$_} = 1;} @dir_list;
12302: }
1.1075.2.11 raeburn 12303: } elsif (($actionurl eq '/adm/dependencies') ||
12304: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12305: ($args->{'context'} eq 'paste')) ||
12306: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12307: if ($env{'request.course.id'} ne '') {
12308: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12309: if ($dir ne '') {
12310: my ($dirlistref,$listerror) =
12311: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12312: if (ref($dirlistref) eq 'ARRAY') {
12313: foreach my $line (@{$dirlistref}) {
12314: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12315: $size,undef,$mtime)=split(/\&/,$line,12);
12316: unless (($testdir&$dirptr) ||
12317: ($file_name =~ /^\.\.?$/)) {
12318: $currfile{$file_name} = [$size,$mtime];
12319: }
12320: }
12321: }
12322: }
12323: }
1.984 raeburn 12324: }
12325: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12326: if (exists($currfile{$file})) {
1.987 raeburn 12327: unless ($mapping{$file} eq $file) {
12328: $pathchanges{$file} = 1;
12329: }
12330: $existing{$file} = 1;
12331: $numexisting ++;
12332: } else {
1.984 raeburn 12333: $newfiles{$file} = 1;
12334: }
12335: }
1.1071 raeburn 12336: foreach my $file (keys(%currfile)) {
12337: unless (($file eq $filename) ||
12338: ($file eq $filename.'.bak') ||
12339: ($dependencies{$file})) {
1.1075.2.11 raeburn 12340: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 12341: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12342: next if (($rem ne '') &&
12343: (($env{"httpref.$rem".$file} ne '') ||
12344: (ref($navmap) &&
12345: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12346: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12347: ($navmap->getResourceByUrl($rem.$1)))))));
12348: }
1.1075.2.11 raeburn 12349: }
1.1071 raeburn 12350: $unused{$file} = 1;
12351: }
12352: }
1.1075.2.11 raeburn 12353: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12354: ($args->{'context'} eq 'paste')) {
12355: $counter = scalar(keys(%existing));
12356: $numpathchg = scalar(keys(%pathchanges));
12357: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 12358: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12359: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12360: $counter = scalar(keys(%existing));
12361: $numpathchg = scalar(keys(%pathchanges));
12362: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 12363: }
1.984 raeburn 12364: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12365: if ($actionurl eq '/adm/dependencies') {
12366: next if ($embed_file =~ m{^\w+://});
12367: }
1.660 raeburn 12368: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12369: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12370: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12371: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 12372: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12373: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12374: }
1.1075.2.35 raeburn 12375: $upload_output .= '</td>';
1.1071 raeburn 12376: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 12377: $upload_output.='<td align="right">'.
12378: '<span class="LC_info LC_fontsize_medium">'.
12379: &mt("URL points to web address").'</span>';
1.987 raeburn 12380: $numremref++;
1.660 raeburn 12381: } elsif ($args->{'error_on_invalid_names'}
12382: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 12383: $upload_output.='<td align="right"><span class="LC_warning">'.
12384: &mt('Invalid characters').'</span>';
1.987 raeburn 12385: $numinvalid++;
1.660 raeburn 12386: } else {
1.1075.2.35 raeburn 12387: $upload_output .= '<td>'.
12388: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12389: $embed_file,\%mapping,
1.1071 raeburn 12390: $allfiles,$codebase,'upload');
12391: $counter ++;
12392: $numnew ++;
1.987 raeburn 12393: }
12394: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12395: }
12396: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12397: if ($actionurl eq '/adm/dependencies') {
12398: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12399: $modify_output .= &start_data_table_row().
12400: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12401: '<img src="'.&icon($embed_file).'" border="0" />'.
12402: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12403: '<td>'.$size.'</td>'.
12404: '<td>'.$mtime.'</td>'.
12405: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12406: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12407: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12408: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12409: &embedded_file_element('upload_embedded',$counter,
12410: $embed_file,\%mapping,
12411: $allfiles,$codebase,'modify').
12412: '</div></td>'.
12413: &end_data_table_row()."\n";
12414: $counter ++;
12415: } else {
12416: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12417: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12418: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12419: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12420: &Apache::loncommon::end_data_table_row()."\n";
12421: }
12422: }
12423: my $delidx = $counter;
12424: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12425: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12426: $delete_output .= &start_data_table_row().
12427: '<td><img src="'.&icon($oldfile).'" />'.
12428: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12429: '<td>'.$size.'</td>'.
12430: '<td>'.$mtime.'</td>'.
12431: '<td><label><input type="checkbox" name="del_upload_dep" '.
12432: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12433: &embedded_file_element('upload_embedded',$delidx,
12434: $oldfile,\%mapping,$allfiles,
12435: $codebase,'delete').'</td>'.
12436: &end_data_table_row()."\n";
12437: $numunused ++;
12438: $delidx ++;
1.987 raeburn 12439: }
12440: if ($upload_output) {
12441: $upload_output = &start_data_table().
12442: $upload_output.
12443: &end_data_table()."\n";
12444: }
1.1071 raeburn 12445: if ($modify_output) {
12446: $modify_output = &start_data_table().
12447: &start_data_table_header_row().
12448: '<th>'.&mt('File').'</th>'.
12449: '<th>'.&mt('Size (KB)').'</th>'.
12450: '<th>'.&mt('Modified').'</th>'.
12451: '<th>'.&mt('Upload replacement?').'</th>'.
12452: &end_data_table_header_row().
12453: $modify_output.
12454: &end_data_table()."\n";
12455: }
12456: if ($delete_output) {
12457: $delete_output = &start_data_table().
12458: &start_data_table_header_row().
12459: '<th>'.&mt('File').'</th>'.
12460: '<th>'.&mt('Size (KB)').'</th>'.
12461: '<th>'.&mt('Modified').'</th>'.
12462: '<th>'.&mt('Delete?').'</th>'.
12463: &end_data_table_header_row().
12464: $delete_output.
12465: &end_data_table()."\n";
12466: }
1.987 raeburn 12467: my $applies = 0;
12468: if ($numremref) {
12469: $applies ++;
12470: }
12471: if ($numinvalid) {
12472: $applies ++;
12473: }
12474: if ($numexisting) {
12475: $applies ++;
12476: }
1.1071 raeburn 12477: if ($counter || $numunused) {
1.987 raeburn 12478: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12479: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12480: $state.'<h3>'.$heading.'</h3>';
12481: if ($actionurl eq '/adm/dependencies') {
12482: if ($numnew) {
12483: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12484: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12485: $upload_output.'<br />'."\n";
12486: }
12487: if ($numexisting) {
12488: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12489: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12490: $modify_output.'<br />'."\n";
12491: $buttontext = &mt('Save changes');
12492: }
12493: if ($numunused) {
12494: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12495: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12496: $delete_output.'<br />'."\n";
12497: $buttontext = &mt('Save changes');
12498: }
12499: } else {
12500: $output .= $upload_output.'<br />'."\n";
12501: }
12502: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12503: $counter.'" />'."\n";
12504: if ($actionurl eq '/adm/dependencies') {
12505: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12506: $numnew.'" />'."\n";
12507: } elsif ($actionurl eq '') {
1.987 raeburn 12508: $output .= '<input type="hidden" name="phase" value="three" />';
12509: }
12510: } elsif ($applies) {
12511: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12512: if ($applies > 1) {
12513: $output .=
1.1075.2.35 raeburn 12514: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12515: if ($numremref) {
12516: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12517: }
12518: if ($numinvalid) {
12519: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12520: }
12521: if ($numexisting) {
12522: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12523: }
12524: $output .= '</ul><br />';
12525: } elsif ($numremref) {
12526: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12527: } elsif ($numinvalid) {
12528: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12529: } elsif ($numexisting) {
12530: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12531: }
12532: $output .= $upload_output.'<br />';
12533: }
12534: my ($pathchange_output,$chgcount);
1.1071 raeburn 12535: $chgcount = $counter;
1.987 raeburn 12536: if (keys(%pathchanges) > 0) {
12537: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12538: if ($counter) {
1.987 raeburn 12539: $output .= &embedded_file_element('pathchange',$chgcount,
12540: $embed_file,\%mapping,
1.1071 raeburn 12541: $allfiles,$codebase,'change');
1.987 raeburn 12542: } else {
12543: $pathchange_output .=
12544: &start_data_table_row().
12545: '<td><input type ="checkbox" name="namechange" value="'.
12546: $chgcount.'" checked="checked" /></td>'.
12547: '<td>'.$mapping{$embed_file}.'</td>'.
12548: '<td>'.$embed_file.
12549: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12550: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12551: '</td>'.&end_data_table_row();
1.660 raeburn 12552: }
1.987 raeburn 12553: $numpathchg ++;
12554: $chgcount ++;
1.660 raeburn 12555: }
12556: }
1.1075.2.35 raeburn 12557: if (($counter) || ($numunused)) {
1.987 raeburn 12558: if ($numpathchg) {
12559: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12560: $numpathchg.'" />'."\n";
12561: }
12562: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12563: ($actionurl eq '/adm/imsimport')) {
12564: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12565: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12566: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12567: } elsif ($actionurl eq '/adm/dependencies') {
12568: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12569: }
1.1075.2.35 raeburn 12570: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12571: } elsif ($numpathchg) {
12572: my %pathchange = ();
12573: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12574: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12575: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 12576: }
1.987 raeburn 12577: }
1.1071 raeburn 12578: return ($output,$counter,$numpathchg);
1.987 raeburn 12579: }
12580:
1.1075.2.47 raeburn 12581: =pod
12582:
12583: =item * clean_path($name)
12584:
12585: Performs clean-up of directories, subdirectories and filename in an
12586: embedded object, referenced in an HTML file which is being uploaded
12587: to a course or portfolio, where
12588: "Upload embedded images/multimedia files if HTML file" checkbox was
12589: checked.
12590:
12591: Clean-up is similar to replacements in lonnet::clean_filename()
12592: except each / between sub-directory and next level is preserved.
12593:
12594: =cut
12595:
12596: sub clean_path {
12597: my ($embed_file) = @_;
12598: $embed_file =~s{^/+}{};
12599: my @contents;
12600: if ($embed_file =~ m{/}) {
12601: @contents = split(/\//,$embed_file);
12602: } else {
12603: @contents = ($embed_file);
12604: }
12605: my $lastidx = scalar(@contents)-1;
12606: for (my $i=0; $i<=$lastidx; $i++) {
12607: $contents[$i]=~s{\\}{/}g;
12608: $contents[$i]=~s/\s+/\_/g;
12609: $contents[$i]=~s{[^/\w\.\-]}{}g;
12610: if ($i == $lastidx) {
12611: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12612: }
12613: }
12614: if ($lastidx > 0) {
12615: return join('/',@contents);
12616: } else {
12617: return $contents[0];
12618: }
12619: }
12620:
1.987 raeburn 12621: sub embedded_file_element {
1.1071 raeburn 12622: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12623: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12624: (ref($codebase) eq 'HASH'));
12625: my $output;
1.1071 raeburn 12626: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12627: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12628: }
12629: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12630: &escape($embed_file).'" />';
12631: unless (($context eq 'upload_embedded') &&
12632: ($mapping->{$embed_file} eq $embed_file)) {
12633: $output .='
12634: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12635: }
12636: my $attrib;
12637: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12638: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12639: }
12640: $output .=
12641: "\n\t\t".
12642: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12643: $attrib.'" />';
12644: if (exists($codebase->{$mapping->{$embed_file}})) {
12645: $output .=
12646: "\n\t\t".
12647: '<input name="codebase_'.$num.'" type="hidden" value="'.
12648: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12649: }
1.987 raeburn 12650: return $output;
1.660 raeburn 12651: }
12652:
1.1071 raeburn 12653: sub get_dependency_details {
12654: my ($currfile,$currsubfile,$embed_file) = @_;
12655: my ($size,$mtime,$showsize,$showmtime);
12656: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12657: if ($embed_file =~ m{/}) {
12658: my ($path,$fname) = split(/\//,$embed_file);
12659: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12660: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12661: }
12662: } else {
12663: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12664: ($size,$mtime) = @{$currfile->{$embed_file}};
12665: }
12666: }
12667: $showsize = $size/1024.0;
12668: $showsize = sprintf("%.1f",$showsize);
12669: if ($mtime > 0) {
12670: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12671: }
12672: }
12673: return ($showsize,$showmtime);
12674: }
12675:
12676: sub ask_embedded_js {
12677: return <<"END";
12678: <script type="text/javascript"">
12679: // <![CDATA[
12680: function toggleBrowse(counter) {
12681: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12682: var fileid = document.getElementById('embedded_item_'+counter);
12683: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12684: if (chkboxid.checked == true) {
12685: uploaddivid.style.display='block';
12686: } else {
12687: uploaddivid.style.display='none';
12688: fileid.value = '';
12689: }
12690: }
12691: // ]]>
12692: </script>
12693:
12694: END
12695: }
12696:
1.661 raeburn 12697: sub upload_embedded {
12698: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12699: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12700: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12701: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12702: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12703: my $orig_uploaded_filename =
12704: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12705: foreach my $type ('orig','ref','attrib','codebase') {
12706: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12707: $env{'form.embedded_'.$type.'_'.$i} =
12708: &unescape($env{'form.embedded_'.$type.'_'.$i});
12709: }
12710: }
1.661 raeburn 12711: my ($path,$fname) =
12712: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12713: # no path, whole string is fname
12714: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12715: $fname = &Apache::lonnet::clean_filename($fname);
12716: # See if there is anything left
12717: next if ($fname eq '');
12718:
12719: # Check if file already exists as a file or directory.
12720: my ($state,$msg);
12721: if ($context eq 'portfolio') {
12722: my $port_path = $dirpath;
12723: if ($group ne '') {
12724: $port_path = "groups/$group/$port_path";
12725: }
1.987 raeburn 12726: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12727: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12728: $dir_root,$port_path,$disk_quota,
12729: $current_disk_usage,$uname,$udom);
12730: if ($state eq 'will_exceed_quota'
1.984 raeburn 12731: || $state eq 'file_locked') {
1.661 raeburn 12732: $output .= $msg;
12733: next;
12734: }
12735: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12736: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12737: if ($state eq 'exists') {
12738: $output .= $msg;
12739: next;
12740: }
12741: }
12742: # Check if extension is valid
12743: if (($fname =~ /\.(\w+)$/) &&
12744: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12745: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12746: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12747: next;
12748: } elsif (($fname =~ /\.(\w+)$/) &&
12749: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12750: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12751: next;
12752: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12753: $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 12754: next;
12755: }
12756: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12757: my $subdir = $path;
12758: $subdir =~ s{/+$}{};
1.661 raeburn 12759: if ($context eq 'portfolio') {
1.984 raeburn 12760: my $result;
12761: if ($state eq 'existingfile') {
12762: $result=
12763: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12764: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12765: } else {
1.984 raeburn 12766: $result=
12767: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12768: $dirpath.
1.1075.2.35 raeburn 12769: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12770: if ($result !~ m|^/uploaded/|) {
12771: $output .= '<span class="LC_error">'
12772: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12773: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12774: .'</span><br />';
12775: next;
12776: } else {
1.987 raeburn 12777: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12778: $path.$fname.'</span>').'<br />';
1.984 raeburn 12779: }
1.661 raeburn 12780: }
1.1075.2.35 raeburn 12781: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12782: my $extendedsubdir = $dirpath.'/'.$subdir;
12783: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12784: my $result =
1.1075.2.35 raeburn 12785: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12786: if ($result !~ m|^/uploaded/|) {
12787: $output .= '<span class="LC_error">'
12788: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12789: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12790: .'</span><br />';
12791: next;
12792: } else {
12793: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12794: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12795: if ($context eq 'syllabus') {
12796: &Apache::lonnet::make_public_indefinitely($result);
12797: }
1.987 raeburn 12798: }
1.661 raeburn 12799: } else {
12800: # Save the file
12801: my $target = $env{'form.embedded_item_'.$i};
12802: my $fullpath = $dir_root.$dirpath.'/'.$path;
12803: my $dest = $fullpath.$fname;
12804: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12805: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12806: my $count;
12807: my $filepath = $dir_root;
1.1027 raeburn 12808: foreach my $subdir (@parts) {
12809: $filepath .= "/$subdir";
12810: if (!-e $filepath) {
1.661 raeburn 12811: mkdir($filepath,0770);
12812: }
12813: }
12814: my $fh;
12815: if (!open($fh,'>'.$dest)) {
12816: &Apache::lonnet::logthis('Failed to create '.$dest);
12817: $output .= '<span class="LC_error">'.
1.1071 raeburn 12818: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12819: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12820: '</span><br />';
12821: } else {
12822: if (!print $fh $env{'form.embedded_item_'.$i}) {
12823: &Apache::lonnet::logthis('Failed to write to '.$dest);
12824: $output .= '<span class="LC_error">'.
1.1071 raeburn 12825: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12826: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12827: '</span><br />';
12828: } else {
1.987 raeburn 12829: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12830: $url.'</span>').'<br />';
12831: unless ($context eq 'testbank') {
12832: $footer .= &mt('View embedded file: [_1]',
12833: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12834: }
12835: }
12836: close($fh);
12837: }
12838: }
12839: if ($env{'form.embedded_ref_'.$i}) {
12840: $pathchange{$i} = 1;
12841: }
12842: }
12843: if ($output) {
12844: $output = '<p>'.$output.'</p>';
12845: }
12846: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12847: $returnflag = 'ok';
1.1071 raeburn 12848: my $numpathchgs = scalar(keys(%pathchange));
12849: if ($numpathchgs > 0) {
1.987 raeburn 12850: if ($context eq 'portfolio') {
12851: $output .= '<p>'.&mt('or').'</p>';
12852: } elsif ($context eq 'testbank') {
1.1071 raeburn 12853: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12854: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12855: $returnflag = 'modify_orightml';
12856: }
12857: }
1.1071 raeburn 12858: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12859: }
12860:
12861: sub modify_html_form {
12862: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12863: my $end = 0;
12864: my $modifyform;
12865: if ($context eq 'upload_embedded') {
12866: return unless (ref($pathchange) eq 'HASH');
12867: if ($env{'form.number_embedded_items'}) {
12868: $end += $env{'form.number_embedded_items'};
12869: }
12870: if ($env{'form.number_pathchange_items'}) {
12871: $end += $env{'form.number_pathchange_items'};
12872: }
12873: if ($end) {
12874: for (my $i=0; $i<$end; $i++) {
12875: if ($i < $env{'form.number_embedded_items'}) {
12876: next unless($pathchange->{$i});
12877: }
12878: $modifyform .=
12879: &start_data_table_row().
12880: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12881: 'checked="checked" /></td>'.
12882: '<td>'.$env{'form.embedded_ref_'.$i}.
12883: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12884: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12885: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12886: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12887: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12888: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12889: '<td>'.$env{'form.embedded_orig_'.$i}.
12890: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12891: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12892: &end_data_table_row();
1.1071 raeburn 12893: }
1.987 raeburn 12894: }
12895: } else {
12896: $modifyform = $pathchgtable;
12897: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12898: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12899: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12900: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12901: }
12902: }
12903: if ($modifyform) {
1.1071 raeburn 12904: if ($actionurl eq '/adm/dependencies') {
12905: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12906: }
1.987 raeburn 12907: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12908: '<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".
12909: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12910: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12911: '</ol></p>'."\n".'<p>'.
12912: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12913: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12914: &start_data_table()."\n".
12915: &start_data_table_header_row().
12916: '<th>'.&mt('Change?').'</th>'.
12917: '<th>'.&mt('Current reference').'</th>'.
12918: '<th>'.&mt('Required reference').'</th>'.
12919: &end_data_table_header_row()."\n".
12920: $modifyform.
12921: &end_data_table().'<br />'."\n".$hiddenstate.
12922: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12923: '</form>'."\n";
12924: }
12925: return;
12926: }
12927:
12928: sub modify_html_refs {
1.1075.2.35 raeburn 12929: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12930: my $container;
12931: if ($context eq 'portfolio') {
12932: $container = $env{'form.container'};
12933: } elsif ($context eq 'coursedoc') {
12934: $container = $env{'form.primaryurl'};
1.1071 raeburn 12935: } elsif ($context eq 'manage_dependencies') {
12936: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12937: $container = "/$container";
1.1075.2.35 raeburn 12938: } elsif ($context eq 'syllabus') {
12939: $container = $url;
1.987 raeburn 12940: } else {
1.1027 raeburn 12941: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12942: }
12943: my (%allfiles,%codebase,$output,$content);
12944: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12945: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12946: if (wantarray) {
12947: return ('',0,0);
12948: } else {
12949: return;
12950: }
12951: }
12952: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12953: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12954: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12955: if (wantarray) {
12956: return ('',0,0);
12957: } else {
12958: return;
12959: }
12960: }
1.987 raeburn 12961: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12962: if ($content eq '-1') {
12963: if (wantarray) {
12964: return ('',0,0);
12965: } else {
12966: return;
12967: }
12968: }
1.987 raeburn 12969: } else {
1.1071 raeburn 12970: unless ($container =~ /^\Q$dir_root\E/) {
12971: if (wantarray) {
12972: return ('',0,0);
12973: } else {
12974: return;
12975: }
12976: }
1.1075.2.128 raeburn 12977: if (open(my $fh,'<',$container)) {
1.987 raeburn 12978: $content = join('', <$fh>);
12979: close($fh);
12980: } else {
1.1071 raeburn 12981: if (wantarray) {
12982: return ('',0,0);
12983: } else {
12984: return;
12985: }
1.987 raeburn 12986: }
12987: }
12988: my ($count,$codebasecount) = (0,0);
12989: my $mm = new File::MMagic;
12990: my $mime_type = $mm->checktype_contents($content);
12991: if ($mime_type eq 'text/html') {
12992: my $parse_result =
12993: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12994: \%codebase,\$content);
12995: if ($parse_result eq 'ok') {
12996: foreach my $i (@changes) {
12997: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12998: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12999: if ($allfiles{$ref}) {
13000: my $newname = $orig;
13001: my ($attrib_regexp,$codebase);
1.1006 raeburn 13002: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13003: if ($attrib_regexp =~ /:/) {
13004: $attrib_regexp =~ s/\:/|/g;
13005: }
13006: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13007: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13008: $count += $numchg;
1.1075.2.35 raeburn 13009: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 13010: delete($allfiles{$ref});
1.987 raeburn 13011: }
13012: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13013: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13014: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13015: $codebasecount ++;
13016: }
13017: }
13018: }
1.1075.2.35 raeburn 13019: my $skiprewrites;
1.987 raeburn 13020: if ($count || $codebasecount) {
13021: my $saveresult;
1.1071 raeburn 13022: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 13023: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13024: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13025: if ($url eq $container) {
13026: my ($fname) = ($container =~ m{/([^/]+)$});
13027: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13028: $count,'<span class="LC_filename">'.
1.1071 raeburn 13029: $fname.'</span>').'</p>';
1.987 raeburn 13030: } else {
13031: $output = '<p class="LC_error">'.
13032: &mt('Error: update failed for: [_1].',
13033: '<span class="LC_filename">'.
13034: $container.'</span>').'</p>';
13035: }
1.1075.2.35 raeburn 13036: if ($context eq 'syllabus') {
13037: unless ($saveresult eq 'ok') {
13038: $skiprewrites = 1;
13039: }
13040: }
1.987 raeburn 13041: } else {
1.1075.2.128 raeburn 13042: if (open(my $fh,'>',$container)) {
1.987 raeburn 13043: print $fh $content;
13044: close($fh);
13045: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13046: $count,'<span class="LC_filename">'.
13047: $container.'</span>').'</p>';
1.661 raeburn 13048: } else {
1.987 raeburn 13049: $output = '<p class="LC_error">'.
13050: &mt('Error: could not update [_1].',
13051: '<span class="LC_filename">'.
13052: $container.'</span>').'</p>';
1.661 raeburn 13053: }
13054: }
13055: }
1.1075.2.35 raeburn 13056: if (($context eq 'syllabus') && (!$skiprewrites)) {
13057: my ($actionurl,$state);
13058: $actionurl = "/public/$udom/$uname/syllabus";
13059: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13060: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13061: \%codebase,
13062: {'context' => 'rewrites',
13063: 'ignore_remote_references' => 1,});
13064: if (ref($mapping) eq 'HASH') {
13065: my $rewrites = 0;
13066: foreach my $key (keys(%{$mapping})) {
13067: next if ($key =~ m{^https?://});
13068: my $ref = $mapping->{$key};
13069: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13070: my $attrib;
13071: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13072: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13073: }
13074: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13075: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13076: $rewrites += $numchg;
13077: }
13078: }
13079: if ($rewrites) {
13080: my $saveresult;
13081: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13082: if ($url eq $container) {
13083: my ($fname) = ($container =~ m{/([^/]+)$});
13084: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13085: $count,'<span class="LC_filename">'.
13086: $fname.'</span>').'</p>';
13087: } else {
13088: $output .= '<p class="LC_error">'.
13089: &mt('Error: could not update links in [_1].',
13090: '<span class="LC_filename">'.
13091: $container.'</span>').'</p>';
13092:
13093: }
13094: }
13095: }
13096: }
1.987 raeburn 13097: } else {
13098: &logthis('Failed to parse '.$container.
13099: ' to modify references: '.$parse_result);
1.661 raeburn 13100: }
13101: }
1.1071 raeburn 13102: if (wantarray) {
13103: return ($output,$count,$codebasecount);
13104: } else {
13105: return $output;
13106: }
1.661 raeburn 13107: }
13108:
13109: sub check_for_existing {
13110: my ($path,$fname,$element) = @_;
13111: my ($state,$msg);
13112: if (-d $path.'/'.$fname) {
13113: $state = 'exists';
13114: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13115: } elsif (-e $path.'/'.$fname) {
13116: $state = 'exists';
13117: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13118: }
13119: if ($state eq 'exists') {
13120: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13121: }
13122: return ($state,$msg);
13123: }
13124:
13125: sub check_for_upload {
13126: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13127: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13128: my $filesize = length($env{'form.'.$element});
13129: if (!$filesize) {
13130: my $msg = '<span class="LC_error">'.
13131: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13132: '<span class="LC_filename">'.$fname.'</span>',
13133: $filesize).'<br />'.
1.1007 raeburn 13134: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13135: '</span>';
13136: return ('zero_bytes',$msg);
13137: }
13138: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13139: my $getpropath = 1;
1.1021 raeburn 13140: my ($dirlistref,$listerror) =
13141: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13142: my $found_file = 0;
13143: my $locked_file = 0;
1.991 raeburn 13144: my @lockers;
13145: my $navmap;
13146: if ($env{'request.course.id'}) {
13147: $navmap = Apache::lonnavmaps::navmap->new();
13148: }
1.1021 raeburn 13149: if (ref($dirlistref) eq 'ARRAY') {
13150: foreach my $line (@{$dirlistref}) {
13151: my ($file_name,$rest)=split(/\&/,$line,2);
13152: if ($file_name eq $fname){
13153: $file_name = $path.$file_name;
13154: if ($group ne '') {
13155: $file_name = $group.$file_name;
13156: }
13157: $found_file = 1;
13158: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13159: foreach my $lock (@lockers) {
13160: if (ref($lock) eq 'ARRAY') {
13161: my ($symb,$crsid) = @{$lock};
13162: if ($crsid eq $env{'request.course.id'}) {
13163: if (ref($navmap)) {
13164: my $res = $navmap->getBySymb($symb);
13165: foreach my $part (@{$res->parts()}) {
13166: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13167: unless (($slot_status == $res->RESERVED) ||
13168: ($slot_status == $res->RESERVED_LOCATION)) {
13169: $locked_file = 1;
13170: }
1.991 raeburn 13171: }
1.1021 raeburn 13172: } else {
13173: $locked_file = 1;
1.991 raeburn 13174: }
13175: } else {
13176: $locked_file = 1;
13177: }
13178: }
1.1021 raeburn 13179: }
13180: } else {
13181: my @info = split(/\&/,$rest);
13182: my $currsize = $info[6]/1000;
13183: if ($currsize < $filesize) {
13184: my $extra = $filesize - $currsize;
13185: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 13186: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13187: &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 13188: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13189: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13190: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13191: return ('will_exceed_quota',$msg);
13192: }
1.984 raeburn 13193: }
13194: }
1.661 raeburn 13195: }
13196: }
13197: }
13198: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 13199: my $msg = '<p class="LC_warning">'.
13200: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
13201: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13202: return ('will_exceed_quota',$msg);
13203: } elsif ($found_file) {
13204: if ($locked_file) {
1.1075.2.69 raeburn 13205: my $msg = '<p class="LC_warning">';
1.661 raeburn 13206: $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 13207: $msg .= '</p>';
1.661 raeburn 13208: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13209: return ('file_locked',$msg);
13210: } else {
1.1075.2.69 raeburn 13211: my $msg = '<p class="LC_error">';
1.984 raeburn 13212: $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 13213: $msg .= '</p>';
1.984 raeburn 13214: return ('existingfile',$msg);
1.661 raeburn 13215: }
13216: }
13217: }
13218:
1.987 raeburn 13219: sub check_for_traversal {
13220: my ($path,$url,$toplevel) = @_;
13221: my @parts=split(/\//,$path);
13222: my $cleanpath;
13223: my $fullpath = $url;
13224: for (my $i=0;$i<@parts;$i++) {
13225: next if ($parts[$i] eq '.');
13226: if ($parts[$i] eq '..') {
13227: $fullpath =~ s{([^/]+/)$}{};
13228: } else {
13229: $fullpath .= $parts[$i].'/';
13230: }
13231: }
13232: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13233: $cleanpath = $1;
13234: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13235: my $curr_toprel = $1;
13236: my @parts = split(/\//,$curr_toprel);
13237: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13238: my @urlparts = split(/\//,$url_toprel);
13239: my $doubledots;
13240: my $startdiff = -1;
13241: for (my $i=0; $i<@urlparts; $i++) {
13242: if ($startdiff == -1) {
13243: unless ($urlparts[$i] eq $parts[$i]) {
13244: $startdiff = $i;
13245: $doubledots .= '../';
13246: }
13247: } else {
13248: $doubledots .= '../';
13249: }
13250: }
13251: if ($startdiff > -1) {
13252: $cleanpath = $doubledots;
13253: for (my $i=$startdiff; $i<@parts; $i++) {
13254: $cleanpath .= $parts[$i].'/';
13255: }
13256: }
13257: }
13258: $cleanpath =~ s{(/)$}{};
13259: return $cleanpath;
13260: }
1.31 albertel 13261:
1.1053 raeburn 13262: sub is_archive_file {
13263: my ($mimetype) = @_;
13264: if (($mimetype eq 'application/octet-stream') ||
13265: ($mimetype eq 'application/x-stuffit') ||
13266: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13267: return 1;
13268: }
13269: return;
13270: }
13271:
13272: sub decompress_form {
1.1065 raeburn 13273: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13274: my %lt = &Apache::lonlocal::texthash (
13275: this => 'This file is an archive file.',
1.1067 raeburn 13276: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13277: itsc => 'Its contents are as follows:',
1.1053 raeburn 13278: youm => 'You may wish to extract its contents.',
13279: extr => 'Extract contents',
1.1067 raeburn 13280: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13281: proa => 'Process automatically?',
1.1053 raeburn 13282: yes => 'Yes',
13283: no => 'No',
1.1067 raeburn 13284: fold => 'Title for folder containing movie',
13285: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13286: );
1.1065 raeburn 13287: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13288: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13289: my $info = &list_archive_contents($fileloc,\@paths);
13290: if (@paths) {
13291: foreach my $path (@paths) {
13292: $path =~ s{^/}{};
1.1067 raeburn 13293: if ($path =~ m{^([^/]+)/$}) {
13294: $topdir = $1;
13295: }
1.1065 raeburn 13296: if ($path =~ m{^([^/]+)/}) {
13297: $toplevel{$1} = $path;
13298: } else {
13299: $toplevel{$path} = $path;
13300: }
13301: }
13302: }
1.1067 raeburn 13303: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 13304: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13305: "$topdir/media/",
13306: "$topdir/media/$topdir.mp4",
13307: "$topdir/media/FirstFrame.png",
13308: "$topdir/media/player.swf",
13309: "$topdir/media/swfobject.js",
13310: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 13311: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 13312: "$topdir/$topdir.mp4",
13313: "$topdir/$topdir\_config.xml",
13314: "$topdir/$topdir\_controller.swf",
13315: "$topdir/$topdir\_embed.css",
13316: "$topdir/$topdir\_First_Frame.png",
13317: "$topdir/$topdir\_player.html",
13318: "$topdir/$topdir\_Thumbnails.png",
13319: "$topdir/playerProductInstall.swf",
13320: "$topdir/scripts/",
13321: "$topdir/scripts/config_xml.js",
13322: "$topdir/scripts/handlebars.js",
13323: "$topdir/scripts/jquery-1.7.1.min.js",
13324: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13325: "$topdir/scripts/modernizr.js",
13326: "$topdir/scripts/player-min.js",
13327: "$topdir/scripts/swfobject.js",
13328: "$topdir/skins/",
13329: "$topdir/skins/configuration_express.xml",
13330: "$topdir/skins/express_show/",
13331: "$topdir/skins/express_show/player-min.css",
13332: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 13333: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13334: "$topdir/$topdir.mp4",
13335: "$topdir/$topdir\_config.xml",
13336: "$topdir/$topdir\_controller.swf",
13337: "$topdir/$topdir\_embed.css",
13338: "$topdir/$topdir\_First_Frame.png",
13339: "$topdir/$topdir\_player.html",
13340: "$topdir/$topdir\_Thumbnails.png",
13341: "$topdir/playerProductInstall.swf",
13342: "$topdir/scripts/",
13343: "$topdir/scripts/config_xml.js",
13344: "$topdir/scripts/techsmith-smart-player.min.js",
13345: "$topdir/skins/",
13346: "$topdir/skins/configuration_express.xml",
13347: "$topdir/skins/express_show/",
13348: "$topdir/skins/express_show/spritesheet.min.css",
13349: "$topdir/skins/express_show/spritesheet.png",
13350: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 13351: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13352: if (@diffs == 0) {
1.1075.2.59 raeburn 13353: $is_camtasia = 6;
13354: } else {
1.1075.2.81 raeburn 13355: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 13356: if (@diffs == 0) {
13357: $is_camtasia = 8;
1.1075.2.81 raeburn 13358: } else {
13359: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13360: if (@diffs == 0) {
13361: $is_camtasia = 8;
13362: }
1.1075.2.59 raeburn 13363: }
1.1067 raeburn 13364: }
13365: }
13366: my $output;
13367: if ($is_camtasia) {
13368: $output = <<"ENDCAM";
13369: <script type="text/javascript" language="Javascript">
13370: // <![CDATA[
13371:
13372: function camtasiaToggle() {
13373: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13374: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 13375: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13376: document.getElementById('camtasia_titles').style.display='block';
13377: } else {
13378: document.getElementById('camtasia_titles').style.display='none';
13379: }
13380: }
13381: }
13382: return;
13383: }
13384:
13385: // ]]>
13386: </script>
13387: <p>$lt{'camt'}</p>
13388: ENDCAM
1.1065 raeburn 13389: } else {
1.1067 raeburn 13390: $output = '<p>'.$lt{'this'};
13391: if ($info eq '') {
13392: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13393: } else {
13394: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13395: '<div><pre>'.$info.'</pre></div>';
13396: }
1.1065 raeburn 13397: }
1.1067 raeburn 13398: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13399: my $duplicates;
13400: my $num = 0;
13401: if (ref($dirlist) eq 'ARRAY') {
13402: foreach my $item (@{$dirlist}) {
13403: if (ref($item) eq 'ARRAY') {
13404: if (exists($toplevel{$item->[0]})) {
13405: $duplicates .=
13406: &start_data_table_row().
13407: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13408: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13409: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13410: 'value="1" />'.&mt('Yes').'</label>'.
13411: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13412: '<td>'.$item->[0].'</td>';
13413: if ($item->[2]) {
13414: $duplicates .= '<td>'.&mt('Directory').'</td>';
13415: } else {
13416: $duplicates .= '<td>'.&mt('File').'</td>';
13417: }
13418: $duplicates .= '<td>'.$item->[3].'</td>'.
13419: '<td>'.
13420: &Apache::lonlocal::locallocaltime($item->[4]).
13421: '</td>'.
13422: &end_data_table_row();
13423: $num ++;
13424: }
13425: }
13426: }
13427: }
13428: my $itemcount;
13429: if (@paths > 0) {
13430: $itemcount = scalar(@paths);
13431: } else {
13432: $itemcount = 1;
13433: }
1.1067 raeburn 13434: if ($is_camtasia) {
13435: $output .= $lt{'auto'}.'<br />'.
13436: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 13437: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13438: $lt{'yes'}.'</label> <label>'.
13439: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13440: $lt{'no'}.'</label></span><br />'.
13441: '<div id="camtasia_titles" style="display:block">'.
13442: &Apache::lonhtmlcommon::start_pick_box().
13443: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13444: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13445: &Apache::lonhtmlcommon::row_closure().
13446: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13447: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13448: &Apache::lonhtmlcommon::row_closure(1).
13449: &Apache::lonhtmlcommon::end_pick_box().
13450: '</div>';
13451: }
1.1065 raeburn 13452: $output .=
13453: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13454: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13455: "\n";
1.1065 raeburn 13456: if ($duplicates ne '') {
13457: $output .= '<p><span class="LC_warning">'.
13458: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13459: &start_data_table().
13460: &start_data_table_header_row().
13461: '<th>'.&mt('Overwrite?').'</th>'.
13462: '<th>'.&mt('Name').'</th>'.
13463: '<th>'.&mt('Type').'</th>'.
13464: '<th>'.&mt('Size').'</th>'.
13465: '<th>'.&mt('Last modified').'</th>'.
13466: &end_data_table_header_row().
13467: $duplicates.
13468: &end_data_table().
13469: '</p>';
13470: }
1.1067 raeburn 13471: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13472: if (ref($hiddenelements) eq 'HASH') {
13473: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13474: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13475: }
13476: }
13477: $output .= <<"END";
1.1067 raeburn 13478: <br />
1.1053 raeburn 13479: <input type="submit" name="decompress" value="$lt{'extr'}" />
13480: </form>
13481: $noextract
13482: END
13483: return $output;
13484: }
13485:
1.1065 raeburn 13486: sub decompression_utility {
13487: my ($program) = @_;
13488: my @utilities = ('tar','gunzip','bunzip2','unzip');
13489: my $location;
13490: if (grep(/^\Q$program\E$/,@utilities)) {
13491: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13492: '/usr/sbin/') {
13493: if (-x $dir.$program) {
13494: $location = $dir.$program;
13495: last;
13496: }
13497: }
13498: }
13499: return $location;
13500: }
13501:
13502: sub list_archive_contents {
13503: my ($file,$pathsref) = @_;
13504: my (@cmd,$output);
13505: my $needsregexp;
13506: if ($file =~ /\.zip$/) {
13507: @cmd = (&decompression_utility('unzip'),"-l");
13508: $needsregexp = 1;
13509: } elsif (($file =~ m/\.tar\.gz$/) ||
13510: ($file =~ /\.tgz$/)) {
13511: @cmd = (&decompression_utility('tar'),"-ztf");
13512: } elsif ($file =~ /\.tar\.bz2$/) {
13513: @cmd = (&decompression_utility('tar'),"-jtf");
13514: } elsif ($file =~ m|\.tar$|) {
13515: @cmd = (&decompression_utility('tar'),"-tf");
13516: }
13517: if (@cmd) {
13518: undef($!);
13519: undef($@);
13520: if (open(my $fh,"-|", @cmd, $file)) {
13521: while (my $line = <$fh>) {
13522: $output .= $line;
13523: chomp($line);
13524: my $item;
13525: if ($needsregexp) {
13526: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13527: } else {
13528: $item = $line;
13529: }
13530: if ($item ne '') {
13531: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13532: push(@{$pathsref},$item);
13533: }
13534: }
13535: }
13536: close($fh);
13537: }
13538: }
13539: return $output;
13540: }
13541:
1.1053 raeburn 13542: sub decompress_uploaded_file {
13543: my ($file,$dir) = @_;
13544: &Apache::lonnet::appenv({'cgi.file' => $file});
13545: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13546: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13547: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13548: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13549: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13550: my $decompressed = $env{'cgi.decompressed'};
13551: &Apache::lonnet::delenv('cgi.file');
13552: &Apache::lonnet::delenv('cgi.dir');
13553: &Apache::lonnet::delenv('cgi.decompressed');
13554: return ($decompressed,$result);
13555: }
13556:
1.1055 raeburn 13557: sub process_decompression {
13558: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 13559: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13560: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13561: &mt('Unexpected file path.').'</p>'."\n";
13562: }
13563: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13564: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13565: &mt('Unexpected course context.').'</p>'."\n";
13566: }
13567: unless ($file eq &Apache::lonnet::clean_filename($file)) {
13568: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13569: &mt('Filename contained unexpected characters.').'</p>'."\n";
13570: }
1.1055 raeburn 13571: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 13572: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 13573: $error = &mt('Filename not a supported archive file type.').
13574: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13575: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13576: } else {
13577: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13578: if ($docuhome eq 'no_host') {
13579: $error = &mt('Could not determine home server for course.');
13580: } else {
13581: my @ids=&Apache::lonnet::current_machine_ids();
13582: my $currdir = "$dir_root/$destination";
13583: if (grep(/^\Q$docuhome\E$/,@ids)) {
13584: $dir = &LONCAPA::propath($docudom,$docuname).
13585: "$dir_root/$destination";
13586: } else {
13587: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13588: "$dir_root/$docudom/$docuname/$destination";
13589: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13590: $error = &mt('Archive file not found.');
13591: }
13592: }
1.1065 raeburn 13593: my (@to_overwrite,@to_skip);
13594: if ($env{'form.archive_overwrite_total'} > 0) {
13595: my $total = $env{'form.archive_overwrite_total'};
13596: for (my $i=0; $i<$total; $i++) {
13597: if ($env{'form.archive_overwrite_'.$i} == 1) {
13598: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13599: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13600: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13601: }
13602: }
13603: }
13604: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 13605: my $numoverwrite = scalar(@to_overwrite);
13606: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13607: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13608: } elsif ($dir eq '') {
1.1055 raeburn 13609: $error = &mt('Directory containing archive file unavailable.');
13610: } elsif (!$error) {
1.1065 raeburn 13611: my ($decompressed,$display);
1.1075.2.128 raeburn 13612: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13613: my $tempdir = time.'_'.$$.int(rand(10000));
13614: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 13615: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13616: ($decompressed,$display) =
13617: &decompress_uploaded_file($file,"$dir/$tempdir");
13618: foreach my $item (@to_skip) {
13619: if (($item ne '') && ($item !~ /\.\./)) {
13620: if (-f "$dir/$tempdir/$item") {
13621: unlink("$dir/$tempdir/$item");
13622: } elsif (-d "$dir/$tempdir/$item") {
13623: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
13624: }
13625: }
13626: }
13627: foreach my $item (@to_overwrite) {
13628: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13629: if (($item ne '') && ($item !~ /\.\./)) {
13630: if (-f "$dir/$item") {
13631: unlink("$dir/$item");
13632: } elsif (-d "$dir/$item") {
13633: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
13634: }
13635: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13636: }
1.1065 raeburn 13637: }
13638: }
1.1075.2.128 raeburn 13639: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13640: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13641: }
1.1065 raeburn 13642: }
13643: } else {
13644: ($decompressed,$display) =
13645: &decompress_uploaded_file($file,$dir);
13646: }
1.1055 raeburn 13647: if ($decompressed eq 'ok') {
1.1065 raeburn 13648: $output = '<p class="LC_info">'.
13649: &mt('Files extracted successfully from archive.').
13650: '</p>'."\n";
1.1055 raeburn 13651: my ($warning,$result,@contents);
13652: my ($newdirlistref,$newlisterror) =
13653: &Apache::lonnet::dirlist($currdir,$docudom,
13654: $docuname,1);
13655: my (%is_dir,%changes,@newitems);
13656: my $dirptr = 16384;
1.1065 raeburn 13657: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13658: foreach my $dir_line (@{$newdirlistref}) {
13659: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13660: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13661: push(@newitems,$item);
13662: if ($dirptr&$testdir) {
13663: $is_dir{$item} = 1;
13664: }
13665: $changes{$item} = 1;
13666: }
13667: }
13668: }
13669: if (keys(%changes) > 0) {
13670: foreach my $item (sort(@newitems)) {
13671: if ($changes{$item}) {
13672: push(@contents,$item);
13673: }
13674: }
13675: }
13676: if (@contents > 0) {
1.1067 raeburn 13677: my $wantform;
13678: unless ($env{'form.autoextract_camtasia'}) {
13679: $wantform = 1;
13680: }
1.1056 raeburn 13681: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13682: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13683: $currdir,\%is_dir,
13684: \%children,\%parent,
1.1056 raeburn 13685: \@contents,\%dirorder,
13686: \%titles,$wantform);
1.1055 raeburn 13687: if ($datatable ne '') {
13688: $output .= &archive_options_form('decompressed',$datatable,
13689: $count,$hiddenelem);
1.1065 raeburn 13690: my $startcount = 6;
1.1055 raeburn 13691: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13692: \%titles,\%children);
1.1055 raeburn 13693: }
1.1067 raeburn 13694: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13695: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13696: my %displayed;
13697: my $total = 1;
13698: $env{'form.archive_directory'} = [];
13699: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13700: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13701: $path =~ s{/$}{};
13702: my $item;
13703: if ($path ne '') {
13704: $item = "$path/$titles{$i}";
13705: } else {
13706: $item = $titles{$i};
13707: }
13708: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13709: if ($item eq $contents[0]) {
13710: push(@{$env{'form.archive_directory'}},$i);
13711: $env{'form.archive_'.$i} = 'display';
13712: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13713: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13714: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13715: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13716: $env{'form.archive_'.$i} = 'display';
13717: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13718: $displayed{'web'} = $i;
13719: } else {
1.1075.2.59 raeburn 13720: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13721: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13722: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13723: push(@{$env{'form.archive_directory'}},$i);
13724: }
13725: $env{'form.archive_'.$i} = 'dependency';
13726: }
13727: $total ++;
13728: }
13729: for (my $i=1; $i<$total; $i++) {
13730: next if ($i == $displayed{'web'});
13731: next if ($i == $displayed{'folder'});
13732: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13733: }
13734: $env{'form.phase'} = 'decompress_cleanup';
13735: $env{'form.archivedelete'} = 1;
13736: $env{'form.archive_count'} = $total-1;
13737: $output .=
13738: &process_extracted_files('coursedocs',$docudom,
13739: $docuname,$destination,
13740: $dir_root,$hiddenelem);
13741: }
1.1055 raeburn 13742: } else {
13743: $warning = &mt('No new items extracted from archive file.');
13744: }
13745: } else {
13746: $output = $display;
13747: $error = &mt('An error occurred during extraction from the archive file.');
13748: }
13749: }
13750: }
13751: }
13752: if ($error) {
13753: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13754: $error.'</p>'."\n";
13755: }
13756: if ($warning) {
13757: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13758: }
13759: return $output;
13760: }
13761:
13762: sub get_extracted {
1.1056 raeburn 13763: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13764: $titles,$wantform) = @_;
1.1055 raeburn 13765: my $count = 0;
13766: my $depth = 0;
13767: my $datatable;
1.1056 raeburn 13768: my @hierarchy;
1.1055 raeburn 13769: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13770: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13771: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13772: foreach my $item (@{$contents}) {
13773: $count ++;
1.1056 raeburn 13774: @{$dirorder->{$count}} = @hierarchy;
13775: $titles->{$count} = $item;
1.1055 raeburn 13776: &archive_hierarchy($depth,$count,$parent,$children);
13777: if ($wantform) {
13778: $datatable .= &archive_row($is_dir->{$item},$item,
13779: $currdir,$depth,$count);
13780: }
13781: if ($is_dir->{$item}) {
13782: $depth ++;
1.1056 raeburn 13783: push(@hierarchy,$count);
13784: $parent->{$depth} = $count;
1.1055 raeburn 13785: $datatable .=
13786: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13787: \$depth,\$count,\@hierarchy,$dirorder,
13788: $children,$parent,$titles,$wantform);
1.1055 raeburn 13789: $depth --;
1.1056 raeburn 13790: pop(@hierarchy);
1.1055 raeburn 13791: }
13792: }
13793: return ($count,$datatable);
13794: }
13795:
13796: sub recurse_extracted_archive {
1.1056 raeburn 13797: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13798: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13799: my $result='';
1.1056 raeburn 13800: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13801: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13802: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13803: return $result;
13804: }
13805: my $dirptr = 16384;
13806: my ($newdirlistref,$newlisterror) =
13807: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13808: if (ref($newdirlistref) eq 'ARRAY') {
13809: foreach my $dir_line (@{$newdirlistref}) {
13810: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13811: unless ($item =~ /^\.+$/) {
13812: $$count ++;
1.1056 raeburn 13813: @{$dirorder->{$$count}} = @{$hierarchy};
13814: $titles->{$$count} = $item;
1.1055 raeburn 13815: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13816:
1.1055 raeburn 13817: my $is_dir;
13818: if ($dirptr&$testdir) {
13819: $is_dir = 1;
13820: }
13821: if ($wantform) {
13822: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13823: }
13824: if ($is_dir) {
13825: $$depth ++;
1.1056 raeburn 13826: push(@{$hierarchy},$$count);
13827: $parent->{$$depth} = $$count;
1.1055 raeburn 13828: $result .=
13829: &recurse_extracted_archive("$currdir/$item",$docudom,
13830: $docuname,$depth,$count,
1.1056 raeburn 13831: $hierarchy,$dirorder,$children,
13832: $parent,$titles,$wantform);
1.1055 raeburn 13833: $$depth --;
1.1056 raeburn 13834: pop(@{$hierarchy});
1.1055 raeburn 13835: }
13836: }
13837: }
13838: }
13839: return $result;
13840: }
13841:
13842: sub archive_hierarchy {
13843: my ($depth,$count,$parent,$children) =@_;
13844: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13845: if (exists($parent->{$depth})) {
13846: $children->{$parent->{$depth}} .= $count.':';
13847: }
13848: }
13849: return;
13850: }
13851:
13852: sub archive_row {
13853: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13854: my ($name) = ($item =~ m{([^/]+)$});
13855: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13856: 'display' => 'Add as file',
1.1055 raeburn 13857: 'dependency' => 'Include as dependency',
13858: 'discard' => 'Discard',
13859: );
13860: if ($is_dir) {
1.1059 raeburn 13861: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13862: }
1.1056 raeburn 13863: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13864: my $offset = 0;
1.1055 raeburn 13865: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13866: $offset ++;
1.1065 raeburn 13867: if ($action ne 'display') {
13868: $offset ++;
13869: }
1.1055 raeburn 13870: $output .= '<td><span class="LC_nobreak">'.
13871: '<label><input type="radio" name="archive_'.$count.
13872: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13873: my $text = $choices{$action};
13874: if ($is_dir) {
13875: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13876: if ($action eq 'display') {
1.1059 raeburn 13877: $text = &mt('Add as folder');
1.1055 raeburn 13878: }
1.1056 raeburn 13879: } else {
13880: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13881:
13882: }
13883: $output .= ' /> '.$choices{$action}.'</label></span>';
13884: if ($action eq 'dependency') {
13885: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13886: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13887: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13888: '<option value=""></option>'."\n".
13889: '</select>'."\n".
13890: '</div>';
1.1059 raeburn 13891: } elsif ($action eq 'display') {
13892: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13893: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13894: '</div>';
1.1055 raeburn 13895: }
1.1056 raeburn 13896: $output .= '</td>';
1.1055 raeburn 13897: }
13898: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13899: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13900: for (my $i=0; $i<$depth; $i++) {
13901: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13902: }
13903: if ($is_dir) {
13904: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13905: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13906: } else {
13907: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13908: }
13909: $output .= ' '.$name.'</td>'."\n".
13910: &end_data_table_row();
13911: return $output;
13912: }
13913:
13914: sub archive_options_form {
1.1065 raeburn 13915: my ($form,$display,$count,$hiddenelem) = @_;
13916: my %lt = &Apache::lonlocal::texthash(
13917: perm => 'Permanently remove archive file?',
13918: hows => 'How should each extracted item be incorporated in the course?',
13919: cont => 'Content actions for all',
13920: addf => 'Add as folder/file',
13921: incd => 'Include as dependency for a displayed file',
13922: disc => 'Discard',
13923: no => 'No',
13924: yes => 'Yes',
13925: save => 'Save',
13926: );
13927: my $output = <<"END";
13928: <form name="$form" method="post" action="">
13929: <p><span class="LC_nobreak">$lt{'perm'}
13930: <label>
13931: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13932: </label>
13933:
13934: <label>
13935: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13936: </span>
13937: </p>
13938: <input type="hidden" name="phase" value="decompress_cleanup" />
13939: <br />$lt{'hows'}
13940: <div class="LC_columnSection">
13941: <fieldset>
13942: <legend>$lt{'cont'}</legend>
13943: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13944: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13945: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13946: </fieldset>
13947: </div>
13948: END
13949: return $output.
1.1055 raeburn 13950: &start_data_table()."\n".
1.1065 raeburn 13951: $display."\n".
1.1055 raeburn 13952: &end_data_table()."\n".
13953: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13954: $hiddenelem.
1.1065 raeburn 13955: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13956: '</form>';
13957: }
13958:
13959: sub archive_javascript {
1.1056 raeburn 13960: my ($startcount,$numitems,$titles,$children) = @_;
13961: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13962: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13963: my $scripttag = <<START;
13964: <script type="text/javascript">
13965: // <![CDATA[
13966:
13967: function checkAll(form,prefix) {
13968: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13969: for (var i=0; i < form.elements.length; i++) {
13970: var id = form.elements[i].id;
13971: if ((id != '') && (id != undefined)) {
13972: if (idstr.test(id)) {
13973: if (form.elements[i].type == 'radio') {
13974: form.elements[i].checked = true;
1.1056 raeburn 13975: var nostart = i-$startcount;
1.1059 raeburn 13976: var offset = nostart%7;
13977: var count = (nostart-offset)/7;
1.1056 raeburn 13978: dependencyCheck(form,count,offset);
1.1055 raeburn 13979: }
13980: }
13981: }
13982: }
13983: }
13984:
13985: function propagateCheck(form,count) {
13986: if (count > 0) {
1.1059 raeburn 13987: var startelement = $startcount + ((count-1) * 7);
13988: for (var j=1; j<6; j++) {
13989: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13990: var item = startelement + j;
13991: if (form.elements[item].type == 'radio') {
13992: if (form.elements[item].checked) {
13993: containerCheck(form,count,j);
13994: break;
13995: }
1.1055 raeburn 13996: }
13997: }
13998: }
13999: }
14000: }
14001:
14002: numitems = $numitems
1.1056 raeburn 14003: var titles = new Array(numitems);
14004: var parents = new Array(numitems);
1.1055 raeburn 14005: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14006: parents[i] = new Array;
1.1055 raeburn 14007: }
1.1059 raeburn 14008: var maintitle = '$maintitle';
1.1055 raeburn 14009:
14010: START
14011:
1.1056 raeburn 14012: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14013: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14014: for (my $i=0; $i<@contents; $i ++) {
14015: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14016: }
14017: }
14018:
1.1056 raeburn 14019: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14020: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14021: }
14022:
1.1055 raeburn 14023: $scripttag .= <<END;
14024:
14025: function containerCheck(form,count,offset) {
14026: if (count > 0) {
1.1056 raeburn 14027: dependencyCheck(form,count,offset);
1.1059 raeburn 14028: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14029: form.elements[item].checked = true;
14030: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14031: if (parents[count].length > 0) {
14032: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14033: containerCheck(form,parents[count][j],offset);
14034: }
14035: }
14036: }
14037: }
14038: }
14039:
14040: function dependencyCheck(form,count,offset) {
14041: if (count > 0) {
1.1059 raeburn 14042: var chosen = (offset+$startcount)+7*(count-1);
14043: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14044: var currtype = form.elements[depitem].type;
14045: if (form.elements[chosen].value == 'dependency') {
14046: document.getElementById('arc_depon_'+count).style.display='block';
14047: form.elements[depitem].options.length = 0;
14048: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 14049: for (var i=1; i<=numitems; i++) {
14050: if (i == count) {
14051: continue;
14052: }
1.1059 raeburn 14053: var startelement = $startcount + (i-1) * 7;
14054: for (var j=1; j<6; j++) {
14055: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14056: var item = startelement + j;
14057: if (form.elements[item].type == 'radio') {
14058: if (form.elements[item].checked) {
14059: if (form.elements[item].value == 'display') {
14060: var n = form.elements[depitem].options.length;
14061: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14062: }
14063: }
14064: }
14065: }
14066: }
14067: }
14068: } else {
14069: document.getElementById('arc_depon_'+count).style.display='none';
14070: form.elements[depitem].options.length = 0;
14071: form.elements[depitem].options[0] = new Option('Select','',true,true);
14072: }
1.1059 raeburn 14073: titleCheck(form,count,offset);
1.1056 raeburn 14074: }
14075: }
14076:
14077: function propagateSelect(form,count,offset) {
14078: if (count > 0) {
1.1065 raeburn 14079: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14080: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14081: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14082: if (parents[count].length > 0) {
14083: for (var j=0; j<parents[count].length; j++) {
14084: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14085: }
14086: }
14087: }
14088: }
14089: }
1.1056 raeburn 14090:
14091: function containerSelect(form,count,offset,picked) {
14092: if (count > 0) {
1.1065 raeburn 14093: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14094: if (form.elements[item].type == 'radio') {
14095: if (form.elements[item].value == 'dependency') {
14096: if (form.elements[item+1].type == 'select-one') {
14097: for (var i=0; i<form.elements[item+1].options.length; i++) {
14098: if (form.elements[item+1].options[i].value == picked) {
14099: form.elements[item+1].selectedIndex = i;
14100: break;
14101: }
14102: }
14103: }
14104: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14105: if (parents[count].length > 0) {
14106: for (var j=0; j<parents[count].length; j++) {
14107: containerSelect(form,parents[count][j],offset,picked);
14108: }
14109: }
14110: }
14111: }
14112: }
14113: }
14114: }
14115:
1.1059 raeburn 14116: function titleCheck(form,count,offset) {
14117: if (count > 0) {
14118: var chosen = (offset+$startcount)+7*(count-1);
14119: var depitem = $startcount + ((count-1) * 7) + 2;
14120: var currtype = form.elements[depitem].type;
14121: if (form.elements[chosen].value == 'display') {
14122: document.getElementById('arc_title_'+count).style.display='block';
14123: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14124: document.getElementById('archive_title_'+count).value=maintitle;
14125: }
14126: } else {
14127: document.getElementById('arc_title_'+count).style.display='none';
14128: if (currtype == 'text') {
14129: document.getElementById('archive_title_'+count).value='';
14130: }
14131: }
14132: }
14133: return;
14134: }
14135:
1.1055 raeburn 14136: // ]]>
14137: </script>
14138: END
14139: return $scripttag;
14140: }
14141:
14142: sub process_extracted_files {
1.1067 raeburn 14143: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14144: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 14145: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14146: my @ids=&Apache::lonnet::current_machine_ids();
14147: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14148: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14149: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14150: if (grep(/^\Q$docuhome\E$/,@ids)) {
14151: $prefix = &LONCAPA::propath($docudom,$docuname);
14152: $pathtocheck = "$dir_root/$destination";
14153: $dir = $dir_root;
14154: $ishome = 1;
14155: } else {
14156: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14157: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 14158: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14159: }
14160: my $currdir = "$dir_root/$destination";
14161: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14162: if ($env{'form.folderpath'}) {
14163: my @items = split('&',$env{'form.folderpath'});
14164: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 14165: if ($env{'form.folderpath'} =~ /\:1$/) {
14166: $containers{'0'}='page';
14167: } else {
14168: $containers{'0'}='sequence';
14169: }
1.1055 raeburn 14170: }
14171: my @archdirs = &get_env_multiple('form.archive_directory');
14172: if ($numitems) {
14173: for (my $i=1; $i<=$numitems; $i++) {
14174: my $path = $env{'form.archive_content_'.$i};
14175: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14176: my $item = $1;
14177: $toplevelitems{$item} = $i;
14178: if (grep(/^\Q$i\E$/,@archdirs)) {
14179: $is_dir{$item} = 1;
14180: }
14181: }
14182: }
14183: }
1.1067 raeburn 14184: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14185: if (keys(%toplevelitems) > 0) {
14186: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14187: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14188: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14189: }
1.1066 raeburn 14190: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14191: if ($numitems) {
14192: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 14193: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14194: my $path = $env{'form.archive_content_'.$i};
14195: if ($path =~ /^\Q$pathtocheck\E/) {
14196: if ($env{'form.archive_'.$i} eq 'discard') {
14197: if ($prefix ne '' && $path ne '') {
14198: if (-e $prefix.$path) {
1.1066 raeburn 14199: if ((@archdirs > 0) &&
14200: (grep(/^\Q$i\E$/,@archdirs))) {
14201: $todeletedir{$prefix.$path} = 1;
14202: } else {
14203: $todelete{$prefix.$path} = 1;
14204: }
1.1055 raeburn 14205: }
14206: }
14207: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14208: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14209: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14210: $docstitle = $env{'form.archive_title_'.$i};
14211: if ($docstitle eq '') {
14212: $docstitle = $title;
14213: }
1.1055 raeburn 14214: $outer = 0;
1.1056 raeburn 14215: if (ref($dirorder{$i}) eq 'ARRAY') {
14216: if (@{$dirorder{$i}} > 0) {
14217: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14218: if ($env{'form.archive_'.$item} eq 'display') {
14219: $outer = $item;
14220: last;
14221: }
14222: }
14223: }
14224: }
14225: my ($errtext,$fatal) =
14226: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14227: '/'.$folders{$outer}.'.'.
14228: $containers{$outer});
14229: next if ($fatal);
14230: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14231: if ($context eq 'coursedocs') {
1.1056 raeburn 14232: $mapinner{$i} = time;
1.1055 raeburn 14233: $folders{$i} = 'default_'.$mapinner{$i};
14234: $containers{$i} = 'sequence';
14235: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14236: $folders{$i}.'.'.$containers{$i};
14237: my $newidx = &LONCAPA::map::getresidx();
14238: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14239: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14240: push(@LONCAPA::map::order,$newidx);
14241: my ($outtext,$errtext) =
14242: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14243: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 14244: '.'.$containers{$outer},1,1);
1.1056 raeburn 14245: $newseqid{$i} = $newidx;
1.1067 raeburn 14246: unless ($errtext) {
1.1075.2.128 raeburn 14247: $result .= '<li>'.&mt('Folder: [_1] added to course',
14248: &HTML::Entities::encode($docstitle,'<>&"'))..
14249: '</li>'."\n";
1.1067 raeburn 14250: }
1.1055 raeburn 14251: }
14252: } else {
14253: if ($context eq 'coursedocs') {
14254: my $newidx=&LONCAPA::map::getresidx();
14255: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14256: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14257: $title;
1.1075.2.161. .13(raeb 14258:-23): if (($outer !~ /\D/) &&
14259:-23): (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14260:-23): ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 14261: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14262: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 14263: }
1.1075.2.128 raeburn 14264: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14265: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14266: }
14267: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14268: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14269: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14270: unless ($ishome) {
14271: my $fetch = "$newdest{$i}/$title";
14272: $fetch =~ s/^\Q$prefix$dir\E//;
14273: $prompttofetch{$fetch} = 1;
14274: }
14275: }
14276: }
14277: $LONCAPA::map::resources[$newidx]=
14278: $docstitle.':'.$url.':false:normal:res';
14279: push(@LONCAPA::map::order, $newidx);
14280: my ($outtext,$errtext)=
14281: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14282: $docuname.'/'.$folders{$outer}.
14283: '.'.$containers{$outer},1,1);
14284: unless ($errtext) {
14285: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14286: $result .= '<li>'.&mt('File: [_1] added to course',
14287: &HTML::Entities::encode($docstitle,'<>&"')).
14288: '</li>'."\n";
14289: }
1.1067 raeburn 14290: }
1.1075.2.128 raeburn 14291: } else {
14292: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14293: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 14294: }
1.1055 raeburn 14295: }
14296: }
1.1075.2.11 raeburn 14297: }
14298: } else {
1.1075.2.128 raeburn 14299: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14300: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 14301: }
14302: }
14303: for (my $i=1; $i<=$numitems; $i++) {
14304: next unless ($env{'form.archive_'.$i} eq 'dependency');
14305: my $path = $env{'form.archive_content_'.$i};
14306: if ($path =~ /^\Q$pathtocheck\E/) {
14307: my ($title) = ($path =~ m{/([^/]+)$});
14308: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14309: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14310: if (ref($dirorder{$i}) eq 'ARRAY') {
14311: my ($itemidx,$fullpath,$relpath);
14312: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14313: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14314: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 14315: if ($dirorder{$i}->[$j] eq $container) {
14316: $itemidx = $j;
1.1056 raeburn 14317: }
14318: }
1.1075.2.11 raeburn 14319: }
14320: if ($itemidx eq '') {
14321: $itemidx = 0;
14322: }
14323: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14324: if ($mapinner{$referrer{$i}}) {
14325: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14326: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14327: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14328: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14329: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14330: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14331: if (!-e $fullpath) {
14332: mkdir($fullpath,0755);
1.1056 raeburn 14333: }
14334: }
1.1075.2.11 raeburn 14335: } else {
14336: last;
1.1056 raeburn 14337: }
1.1075.2.11 raeburn 14338: }
14339: }
14340: } elsif ($newdest{$referrer{$i}}) {
14341: $fullpath = $newdest{$referrer{$i}};
14342: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14343: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14344: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14345: last;
14346: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14347: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14348: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14349: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14350: if (!-e $fullpath) {
14351: mkdir($fullpath,0755);
1.1056 raeburn 14352: }
14353: }
1.1075.2.11 raeburn 14354: } else {
14355: last;
1.1056 raeburn 14356: }
1.1075.2.11 raeburn 14357: }
14358: }
14359: if ($fullpath ne '') {
14360: if (-e "$prefix$path") {
1.1075.2.128 raeburn 14361: unless (rename("$prefix$path","$fullpath/$title")) {
14362: $warning .= &mt('Failed to rename dependency').'<br />';
14363: }
1.1075.2.11 raeburn 14364: }
14365: if (-e "$fullpath/$title") {
14366: my $showpath;
14367: if ($relpath ne '') {
14368: $showpath = "$relpath/$title";
14369: } else {
14370: $showpath = "/$title";
1.1056 raeburn 14371: }
1.1075.2.128 raeburn 14372: $result .= '<li>'.&mt('[_1] included as a dependency',
14373: &HTML::Entities::encode($showpath,'<>&"')).
14374: '</li>'."\n";
14375: unless ($ishome) {
14376: my $fetch = "$fullpath/$title";
14377: $fetch =~ s/^\Q$prefix$dir\E//;
14378: $prompttofetch{$fetch} = 1;
14379: }
1.1055 raeburn 14380: }
14381: }
14382: }
1.1075.2.11 raeburn 14383: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14384: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 14385: &HTML::Entities::encode($path,'<>&"'),
14386: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14387: '<br />';
1.1055 raeburn 14388: }
14389: } else {
1.1075.2.128 raeburn 14390: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14391: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14392: }
14393: }
14394: if (keys(%todelete)) {
14395: foreach my $key (keys(%todelete)) {
14396: unlink($key);
1.1066 raeburn 14397: }
14398: }
14399: if (keys(%todeletedir)) {
14400: foreach my $key (keys(%todeletedir)) {
14401: rmdir($key);
14402: }
14403: }
14404: foreach my $dir (sort(keys(%is_dir))) {
14405: if (($pathtocheck ne '') && ($dir ne '')) {
14406: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14407: }
14408: }
1.1067 raeburn 14409: if ($result ne '') {
14410: $output .= '<ul>'."\n".
14411: $result."\n".
14412: '</ul>';
14413: }
14414: unless ($ishome) {
14415: my $replicationfail;
14416: foreach my $item (keys(%prompttofetch)) {
14417: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14418: unless ($fetchresult eq 'ok') {
14419: $replicationfail .= '<li>'.$item.'</li>'."\n";
14420: }
14421: }
14422: if ($replicationfail) {
14423: $output .= '<p class="LC_error">'.
14424: &mt('Course home server failed to retrieve:').'<ul>'.
14425: $replicationfail.
14426: '</ul></p>';
14427: }
14428: }
1.1055 raeburn 14429: } else {
14430: $warning = &mt('No items found in archive.');
14431: }
14432: if ($error) {
14433: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14434: $error.'</p>'."\n";
14435: }
14436: if ($warning) {
14437: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14438: }
14439: return $output;
14440: }
14441:
1.1066 raeburn 14442: sub cleanup_empty_dirs {
14443: my ($path) = @_;
14444: if (($path ne '') && (-d $path)) {
14445: if (opendir(my $dirh,$path)) {
14446: my @dircontents = grep(!/^\./,readdir($dirh));
14447: my $numitems = 0;
14448: foreach my $item (@dircontents) {
14449: if (-d "$path/$item") {
1.1075.2.28 raeburn 14450: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14451: if (-e "$path/$item") {
14452: $numitems ++;
14453: }
14454: } else {
14455: $numitems ++;
14456: }
14457: }
14458: if ($numitems == 0) {
14459: rmdir($path);
14460: }
14461: closedir($dirh);
14462: }
14463: }
14464: return;
14465: }
14466:
1.41 ng 14467: =pod
1.45 matthew 14468:
1.1075.2.56 raeburn 14469: =item * &get_folder_hierarchy()
1.1068 raeburn 14470:
14471: Provides hierarchy of names of folders/sub-folders containing the current
14472: item,
14473:
14474: Inputs: 3
14475: - $navmap - navmaps object
14476:
14477: - $map - url for map (either the trigger itself, or map containing
14478: the resource, which is the trigger).
14479:
14480: - $showitem - 1 => show title for map itself; 0 => do not show.
14481:
14482: Outputs: 1 @pathitems - array of folder/subfolder names.
14483:
14484: =cut
14485:
14486: sub get_folder_hierarchy {
14487: my ($navmap,$map,$showitem) = @_;
14488: my @pathitems;
14489: if (ref($navmap)) {
14490: my $mapres = $navmap->getResourceByUrl($map);
14491: if (ref($mapres)) {
14492: my $pcslist = $mapres->map_hierarchy();
14493: if ($pcslist ne '') {
14494: my @pcs = split(/,/,$pcslist);
14495: foreach my $pc (@pcs) {
14496: if ($pc == 1) {
1.1075.2.38 raeburn 14497: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14498: } else {
14499: my $res = $navmap->getByMapPc($pc);
14500: if (ref($res)) {
14501: my $title = $res->compTitle();
14502: $title =~ s/\W+/_/g;
14503: if ($title ne '') {
14504: push(@pathitems,$title);
14505: }
14506: }
14507: }
14508: }
14509: }
1.1071 raeburn 14510: if ($showitem) {
14511: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 14512: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14513: } else {
14514: my $maptitle = $mapres->compTitle();
14515: $maptitle =~ s/\W+/_/g;
14516: if ($maptitle ne '') {
14517: push(@pathitems,$maptitle);
14518: }
1.1068 raeburn 14519: }
14520: }
14521: }
14522: }
14523: return @pathitems;
14524: }
14525:
14526: =pod
14527:
1.1015 raeburn 14528: =item * &get_turnedin_filepath()
14529:
14530: Determines path in a user's portfolio file for storage of files uploaded
14531: to a specific essayresponse or dropbox item.
14532:
14533: Inputs: 3 required + 1 optional.
14534: $symb is symb for resource, $uname and $udom are for current user (required).
14535: $caller is optional (can be "submission", if routine is called when storing
14536: an upoaded file when "Submit Answer" button was pressed).
14537:
14538: Returns array containing $path and $multiresp.
14539: $path is path in portfolio. $multiresp is 1 if this resource contains more
14540: than one file upload item. Callers of routine should append partid as a
14541: subdirectory to $path in cases where $multiresp is 1.
14542:
14543: Called by: homework/essayresponse.pm and homework/structuretags.pm
14544:
14545: =cut
14546:
14547: sub get_turnedin_filepath {
14548: my ($symb,$uname,$udom,$caller) = @_;
14549: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14550: my $turnindir;
14551: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14552: $turnindir = $userhash{'turnindir'};
14553: my ($path,$multiresp);
14554: if ($turnindir eq '') {
14555: if ($caller eq 'submission') {
14556: $turnindir = &mt('turned in');
14557: $turnindir =~ s/\W+/_/g;
14558: my %newhash = (
14559: 'turnindir' => $turnindir,
14560: );
14561: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14562: }
14563: }
14564: if ($turnindir ne '') {
14565: $path = '/'.$turnindir.'/';
14566: my ($multipart,$turnin,@pathitems);
14567: my $navmap = Apache::lonnavmaps::navmap->new();
14568: if (defined($navmap)) {
14569: my $mapres = $navmap->getResourceByUrl($map);
14570: if (ref($mapres)) {
14571: my $pcslist = $mapres->map_hierarchy();
14572: if ($pcslist ne '') {
14573: foreach my $pc (split(/,/,$pcslist)) {
14574: my $res = $navmap->getByMapPc($pc);
14575: if (ref($res)) {
14576: my $title = $res->compTitle();
14577: $title =~ s/\W+/_/g;
14578: if ($title ne '') {
1.1075.2.48 raeburn 14579: if (($pc > 1) && (length($title) > 12)) {
14580: $title = substr($title,0,12);
14581: }
1.1015 raeburn 14582: push(@pathitems,$title);
14583: }
14584: }
14585: }
14586: }
14587: my $maptitle = $mapres->compTitle();
14588: $maptitle =~ s/\W+/_/g;
14589: if ($maptitle ne '') {
1.1075.2.48 raeburn 14590: if (length($maptitle) > 12) {
14591: $maptitle = substr($maptitle,0,12);
14592: }
1.1015 raeburn 14593: push(@pathitems,$maptitle);
14594: }
14595: unless ($env{'request.state'} eq 'construct') {
14596: my $res = $navmap->getBySymb($symb);
14597: if (ref($res)) {
14598: my $partlist = $res->parts();
14599: my $totaluploads = 0;
14600: if (ref($partlist) eq 'ARRAY') {
14601: foreach my $part (@{$partlist}) {
14602: my @types = $res->responseType($part);
14603: my @ids = $res->responseIds($part);
14604: for (my $i=0; $i < scalar(@ids); $i++) {
14605: if ($types[$i] eq 'essay') {
14606: my $partid = $part.'_'.$ids[$i];
14607: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14608: $totaluploads ++;
14609: }
14610: }
14611: }
14612: }
14613: if ($totaluploads > 1) {
14614: $multiresp = 1;
14615: }
14616: }
14617: }
14618: }
14619: } else {
14620: return;
14621: }
14622: } else {
14623: return;
14624: }
14625: my $restitle=&Apache::lonnet::gettitle($symb);
14626: $restitle =~ s/\W+/_/g;
14627: if ($restitle eq '') {
14628: $restitle = ($resurl =~ m{/[^/]+$});
14629: if ($restitle eq '') {
14630: $restitle = time;
14631: }
14632: }
1.1075.2.48 raeburn 14633: if (length($restitle) > 12) {
14634: $restitle = substr($restitle,0,12);
14635: }
1.1015 raeburn 14636: push(@pathitems,$restitle);
14637: $path .= join('/',@pathitems);
14638: }
14639: return ($path,$multiresp);
14640: }
14641:
14642: =pod
14643:
1.464 albertel 14644: =back
1.41 ng 14645:
1.112 bowersj2 14646: =head1 CSV Upload/Handling functions
1.38 albertel 14647:
1.41 ng 14648: =over 4
14649:
1.648 raeburn 14650: =item * &upfile_store($r)
1.41 ng 14651:
14652: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14653: needs $env{'form.upfile'}
1.41 ng 14654: returns $datatoken to be put into hidden field
14655:
14656: =cut
1.31 albertel 14657:
14658: sub upfile_store {
14659: my $r=shift;
1.258 albertel 14660: $env{'form.upfile'}=~s/\r/\n/gs;
14661: $env{'form.upfile'}=~s/\f/\n/gs;
14662: $env{'form.upfile'}=~s/\n+/\n/gs;
14663: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14664:
1.1075.2.128 raeburn 14665: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14666: '_enroll_'.$env{'request.course.id'}.'_'.
14667: time.'_'.$$);
14668: return if ($datatoken eq '');
14669:
1.31 albertel 14670: {
1.158 raeburn 14671: my $datafile = $r->dir_config('lonDaemons').
14672: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14673: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14674: print $fh $env{'form.upfile'};
1.158 raeburn 14675: close($fh);
14676: }
1.31 albertel 14677: }
14678: return $datatoken;
14679: }
14680:
1.56 matthew 14681: =pod
14682:
1.1075.2.128 raeburn 14683: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14684:
14685: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14686: $datatoken is the name to assign to the temporary file.
1.258 albertel 14687: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14688:
14689: =cut
1.31 albertel 14690:
14691: sub load_tmp_file {
1.1075.2.128 raeburn 14692: my ($r,$datatoken) = @_;
14693: return if ($datatoken eq '');
1.31 albertel 14694: my @studentdata=();
14695: {
1.158 raeburn 14696: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14697: '/tmp/'.$datatoken.'.tmp';
14698: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14699: @studentdata=<$fh>;
14700: close($fh);
14701: }
1.31 albertel 14702: }
1.258 albertel 14703: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14704: }
14705:
1.1075.2.128 raeburn 14706: sub valid_datatoken {
14707: my ($datatoken) = @_;
1.1075.2.131 raeburn 14708: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14709: return $datatoken;
14710: }
14711: return;
14712: }
14713:
1.56 matthew 14714: =pod
14715:
1.648 raeburn 14716: =item * &upfile_record_sep()
1.41 ng 14717:
14718: Separate uploaded file into records
14719: returns array of records,
1.258 albertel 14720: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14721:
14722: =cut
1.31 albertel 14723:
14724: sub upfile_record_sep {
1.258 albertel 14725: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14726: } else {
1.248 albertel 14727: my @records;
1.258 albertel 14728: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14729: if ($line=~/^\s*$/) { next; }
14730: push(@records,$line);
14731: }
14732: return @records;
1.31 albertel 14733: }
14734: }
14735:
1.56 matthew 14736: =pod
14737:
1.648 raeburn 14738: =item * &record_sep($record)
1.41 ng 14739:
1.258 albertel 14740: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14741:
14742: =cut
14743:
1.263 www 14744: sub takeleft {
14745: my $index=shift;
14746: return substr('0000'.$index,-4,4);
14747: }
14748:
1.31 albertel 14749: sub record_sep {
14750: my $record=shift;
14751: my %components=();
1.258 albertel 14752: if ($env{'form.upfiletype'} eq 'xml') {
14753: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14754: my $i=0;
1.356 albertel 14755: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14756: $field=~s/^(\"|\')//;
14757: $field=~s/(\"|\')$//;
1.263 www 14758: $components{&takeleft($i)}=$field;
1.31 albertel 14759: $i++;
14760: }
1.258 albertel 14761: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14762: my $i=0;
1.356 albertel 14763: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14764: $field=~s/^(\"|\')//;
14765: $field=~s/(\"|\')$//;
1.263 www 14766: $components{&takeleft($i)}=$field;
1.31 albertel 14767: $i++;
14768: }
14769: } else {
1.561 www 14770: my $separator=',';
1.480 banghart 14771: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14772: $separator=';';
1.480 banghart 14773: }
1.31 albertel 14774: my $i=0;
1.561 www 14775: # the character we are looking for to indicate the end of a quote or a record
14776: my $looking_for=$separator;
14777: # do not add the characters to the fields
14778: my $ignore=0;
14779: # we just encountered a separator (or the beginning of the record)
14780: my $just_found_separator=1;
14781: # store the field we are working on here
14782: my $field='';
14783: # work our way through all characters in record
14784: foreach my $character ($record=~/(.)/g) {
14785: if ($character eq $looking_for) {
14786: if ($character ne $separator) {
14787: # Found the end of a quote, again looking for separator
14788: $looking_for=$separator;
14789: $ignore=1;
14790: } else {
14791: # Found a separator, store away what we got
14792: $components{&takeleft($i)}=$field;
14793: $i++;
14794: $just_found_separator=1;
14795: $ignore=0;
14796: $field='';
14797: }
14798: next;
14799: }
14800: # single or double quotation marks after a separator indicate beginning of a quote
14801: # we are now looking for the end of the quote and need to ignore separators
14802: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14803: $looking_for=$character;
14804: next;
14805: }
14806: # ignore would be true after we reached the end of a quote
14807: if ($ignore) { next; }
14808: if (($just_found_separator) && ($character=~/\s/)) { next; }
14809: $field.=$character;
14810: $just_found_separator=0;
1.31 albertel 14811: }
1.561 www 14812: # catch the very last entry, since we never encountered the separator
14813: $components{&takeleft($i)}=$field;
1.31 albertel 14814: }
14815: return %components;
14816: }
14817:
1.144 matthew 14818: ######################################################
14819: ######################################################
14820:
1.56 matthew 14821: =pod
14822:
1.648 raeburn 14823: =item * &upfile_select_html()
1.41 ng 14824:
1.144 matthew 14825: Return HTML code to select a file from the users machine and specify
14826: the file type.
1.41 ng 14827:
14828: =cut
14829:
1.144 matthew 14830: ######################################################
14831: ######################################################
1.31 albertel 14832: sub upfile_select_html {
1.144 matthew 14833: my %Types = (
14834: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14835: semisv => &mt('Semicolon separated values'),
1.144 matthew 14836: space => &mt('Space separated'),
14837: tab => &mt('Tabulator separated'),
14838: # xml => &mt('HTML/XML'),
14839: );
14840: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14841: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14842: foreach my $type (sort(keys(%Types))) {
14843: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14844: }
14845: $Str .= "</select>\n";
14846: return $Str;
1.31 albertel 14847: }
14848:
1.301 albertel 14849: sub get_samples {
14850: my ($records,$toget) = @_;
14851: my @samples=({});
14852: my $got=0;
14853: foreach my $rec (@$records) {
14854: my %temp = &record_sep($rec);
14855: if (! grep(/\S/, values(%temp))) { next; }
14856: if (%temp) {
14857: $samples[$got]=\%temp;
14858: $got++;
14859: if ($got == $toget) { last; }
14860: }
14861: }
14862: return \@samples;
14863: }
14864:
1.144 matthew 14865: ######################################################
14866: ######################################################
14867:
1.56 matthew 14868: =pod
14869:
1.648 raeburn 14870: =item * &csv_print_samples($r,$records)
1.41 ng 14871:
14872: Prints a table of sample values from each column uploaded $r is an
14873: Apache Request ref, $records is an arrayref from
14874: &Apache::loncommon::upfile_record_sep
14875:
14876: =cut
14877:
1.144 matthew 14878: ######################################################
14879: ######################################################
1.31 albertel 14880: sub csv_print_samples {
14881: my ($r,$records) = @_;
1.662 bisitz 14882: my $samples = &get_samples($records,5);
1.301 albertel 14883:
1.594 raeburn 14884: $r->print(&mt('Samples').'<br />'.&start_data_table().
14885: &start_data_table_header_row());
1.356 albertel 14886: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14887: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14888: $r->print(&end_data_table_header_row());
1.301 albertel 14889: foreach my $hash (@$samples) {
1.594 raeburn 14890: $r->print(&start_data_table_row());
1.356 albertel 14891: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14892: $r->print('<td>');
1.356 albertel 14893: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14894: $r->print('</td>');
14895: }
1.594 raeburn 14896: $r->print(&end_data_table_row());
1.31 albertel 14897: }
1.594 raeburn 14898: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14899: }
14900:
1.144 matthew 14901: ######################################################
14902: ######################################################
14903:
1.56 matthew 14904: =pod
14905:
1.648 raeburn 14906: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14907:
14908: Prints a table to create associations between values and table columns.
1.144 matthew 14909:
1.41 ng 14910: $r is an Apache Request ref,
14911: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14912: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14913:
14914: =cut
14915:
1.144 matthew 14916: ######################################################
14917: ######################################################
1.31 albertel 14918: sub csv_print_select_table {
14919: my ($r,$records,$d) = @_;
1.301 albertel 14920: my $i=0;
14921: my $samples = &get_samples($records,1);
1.144 matthew 14922: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14923: &start_data_table().&start_data_table_header_row().
1.144 matthew 14924: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14925: '<th>'.&mt('Column').'</th>'.
14926: &end_data_table_header_row()."\n");
1.356 albertel 14927: foreach my $array_ref (@$d) {
14928: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14929: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14930:
1.875 bisitz 14931: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14932: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14933: $r->print('<option value="none"></option>');
1.356 albertel 14934: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14935: $r->print('<option value="'.$sample.'"'.
14936: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14937: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14938: }
1.594 raeburn 14939: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14940: $i++;
14941: }
1.594 raeburn 14942: $r->print(&end_data_table());
1.31 albertel 14943: $i--;
14944: return $i;
14945: }
1.56 matthew 14946:
1.144 matthew 14947: ######################################################
14948: ######################################################
14949:
1.56 matthew 14950: =pod
1.31 albertel 14951:
1.648 raeburn 14952: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14953:
14954: Prints a table of sample values from the upload and can make associate samples to internal names.
14955:
14956: $r is an Apache Request ref,
14957: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14958: $d is an array of 2 element arrays (internal name, displayed name)
14959:
14960: =cut
14961:
1.144 matthew 14962: ######################################################
14963: ######################################################
1.31 albertel 14964: sub csv_samples_select_table {
14965: my ($r,$records,$d) = @_;
14966: my $i=0;
1.144 matthew 14967: #
1.662 bisitz 14968: my $max_samples = 5;
14969: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14970: $r->print(&start_data_table().
14971: &start_data_table_header_row().'<th>'.
14972: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14973: &end_data_table_header_row());
1.301 albertel 14974:
14975: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14976: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14977: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14978: foreach my $option (@$d) {
14979: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14980: $r->print('<option value="'.$value.'"'.
1.253 albertel 14981: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14982: $display.'</option>');
1.31 albertel 14983: }
14984: $r->print('</select></td><td>');
1.662 bisitz 14985: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14986: if (defined($samples->[$line]{$key})) {
14987: $r->print($samples->[$line]{$key}."<br />\n");
14988: }
14989: }
1.594 raeburn 14990: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14991: $i++;
14992: }
1.594 raeburn 14993: $r->print(&end_data_table());
1.31 albertel 14994: $i--;
14995: return($i);
1.115 matthew 14996: }
14997:
1.144 matthew 14998: ######################################################
14999: ######################################################
15000:
1.115 matthew 15001: =pod
15002:
1.648 raeburn 15003: =item * &clean_excel_name($name)
1.115 matthew 15004:
15005: Returns a replacement for $name which does not contain any illegal characters.
15006:
15007: =cut
15008:
1.144 matthew 15009: ######################################################
15010: ######################################################
1.115 matthew 15011: sub clean_excel_name {
15012: my ($name) = @_;
15013: $name =~ s/[:\*\?\/\\]//g;
15014: if (length($name) > 31) {
15015: $name = substr($name,0,31);
15016: }
15017: return $name;
1.25 albertel 15018: }
1.84 albertel 15019:
1.85 albertel 15020: =pod
15021:
1.648 raeburn 15022: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15023:
15024: Returns either 1 or undef
15025:
15026: 1 if the part is to be hidden, undef if it is to be shown
15027:
15028: Arguments are:
15029:
15030: $id the id of the part to be checked
15031: $symb, optional the symb of the resource to check
15032: $udom, optional the domain of the user to check for
15033: $uname, optional the username of the user to check for
15034:
15035: =cut
1.84 albertel 15036:
15037: sub check_if_partid_hidden {
15038: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15039: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15040: $symb,$udom,$uname);
1.141 albertel 15041: my $truth=1;
15042: #if the string starts with !, then the list is the list to show not hide
15043: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15044: my @hiddenlist=split(/,/,$hiddenparts);
15045: foreach my $checkid (@hiddenlist) {
1.141 albertel 15046: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15047: }
1.141 albertel 15048: return !$truth;
1.84 albertel 15049: }
1.127 matthew 15050:
1.138 matthew 15051:
15052: ############################################################
15053: ############################################################
15054:
15055: =pod
15056:
1.157 matthew 15057: =back
15058:
1.138 matthew 15059: =head1 cgi-bin script and graphing routines
15060:
1.157 matthew 15061: =over 4
15062:
1.648 raeburn 15063: =item * &get_cgi_id()
1.138 matthew 15064:
15065: Inputs: none
15066:
15067: Returns an id which can be used to pass environment variables
15068: to various cgi-bin scripts. These environment variables will
15069: be removed from the users environment after a given time by
15070: the routine &Apache::lonnet::transfer_profile_to_env.
15071:
15072: =cut
15073:
15074: ############################################################
15075: ############################################################
1.152 albertel 15076: my $uniq=0;
1.136 matthew 15077: sub get_cgi_id {
1.154 albertel 15078: $uniq=($uniq+1)%100000;
1.280 albertel 15079: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15080: }
15081:
1.127 matthew 15082: ############################################################
15083: ############################################################
15084:
15085: =pod
15086:
1.648 raeburn 15087: =item * &DrawBarGraph()
1.127 matthew 15088:
1.138 matthew 15089: Facilitates the plotting of data in a (stacked) bar graph.
15090: Puts plot definition data into the users environment in order for
15091: graph.png to plot it. Returns an <img> tag for the plot.
15092: The bars on the plot are labeled '1','2',...,'n'.
15093:
15094: Inputs:
15095:
15096: =over 4
15097:
15098: =item $Title: string, the title of the plot
15099:
15100: =item $xlabel: string, text describing the X-axis of the plot
15101:
15102: =item $ylabel: string, text describing the Y-axis of the plot
15103:
15104: =item $Max: scalar, the maximum Y value to use in the plot
15105: If $Max is < any data point, the graph will not be rendered.
15106:
1.140 matthew 15107: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15108: they are plotted. If undefined, default values will be used.
15109:
1.178 matthew 15110: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15111:
1.138 matthew 15112: =item @Values: An array of array references. Each array reference holds data
15113: to be plotted in a stacked bar chart.
15114:
1.239 matthew 15115: =item If the final element of @Values is a hash reference the key/value
15116: pairs will be added to the graph definition.
15117:
1.138 matthew 15118: =back
15119:
15120: Returns:
15121:
15122: An <img> tag which references graph.png and the appropriate identifying
15123: information for the plot.
15124:
1.127 matthew 15125: =cut
15126:
15127: ############################################################
15128: ############################################################
1.134 matthew 15129: sub DrawBarGraph {
1.178 matthew 15130: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15131: #
15132: if (! defined($colors)) {
15133: $colors = ['#33ff00',
15134: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15135: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15136: ];
15137: }
1.228 matthew 15138: my $extra_settings = {};
15139: if (ref($Values[-1]) eq 'HASH') {
15140: $extra_settings = pop(@Values);
15141: }
1.127 matthew 15142: #
1.136 matthew 15143: my $identifier = &get_cgi_id();
15144: my $id = 'cgi.'.$identifier;
1.129 matthew 15145: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15146: return '';
15147: }
1.225 matthew 15148: #
15149: my @Labels;
15150: if (defined($labels)) {
15151: @Labels = @$labels;
15152: } else {
15153: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 15154: push(@Labels,$i+1);
1.225 matthew 15155: }
15156: }
15157: #
1.129 matthew 15158: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15159: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15160: my %ValuesHash;
15161: my $NumSets=1;
15162: foreach my $array (@Values) {
15163: next if (! ref($array));
1.136 matthew 15164: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15165: join(',',@$array);
1.129 matthew 15166: }
1.127 matthew 15167: #
1.136 matthew 15168: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15169: if ($NumBars < 3) {
15170: $width = 120+$NumBars*32;
1.220 matthew 15171: $xskip = 1;
1.225 matthew 15172: $bar_width = 30;
15173: } elsif ($NumBars < 5) {
15174: $width = 120+$NumBars*20;
15175: $xskip = 1;
15176: $bar_width = 20;
1.220 matthew 15177: } elsif ($NumBars < 10) {
1.136 matthew 15178: $width = 120+$NumBars*15;
15179: $xskip = 1;
15180: $bar_width = 15;
15181: } elsif ($NumBars <= 25) {
15182: $width = 120+$NumBars*11;
15183: $xskip = 5;
15184: $bar_width = 8;
15185: } elsif ($NumBars <= 50) {
15186: $width = 120+$NumBars*8;
15187: $xskip = 5;
15188: $bar_width = 4;
15189: } else {
15190: $width = 120+$NumBars*8;
15191: $xskip = 5;
15192: $bar_width = 4;
15193: }
15194: #
1.137 matthew 15195: $Max = 1 if ($Max < 1);
15196: if ( int($Max) < $Max ) {
15197: $Max++;
15198: $Max = int($Max);
15199: }
1.127 matthew 15200: $Title = '' if (! defined($Title));
15201: $xlabel = '' if (! defined($xlabel));
15202: $ylabel = '' if (! defined($ylabel));
1.369 www 15203: $ValuesHash{$id.'.title'} = &escape($Title);
15204: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15205: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15206: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15207: $ValuesHash{$id.'.NumBars'} = $NumBars;
15208: $ValuesHash{$id.'.NumSets'} = $NumSets;
15209: $ValuesHash{$id.'.PlotType'} = 'bar';
15210: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15211: $ValuesHash{$id.'.height'} = $height;
15212: $ValuesHash{$id.'.width'} = $width;
15213: $ValuesHash{$id.'.xskip'} = $xskip;
15214: $ValuesHash{$id.'.bar_width'} = $bar_width;
15215: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15216: #
1.228 matthew 15217: # Deal with other parameters
15218: while (my ($key,$value) = each(%$extra_settings)) {
15219: $ValuesHash{$id.'.'.$key} = $value;
15220: }
15221: #
1.646 raeburn 15222: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15223: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15224: }
15225:
15226: ############################################################
15227: ############################################################
15228:
15229: =pod
15230:
1.648 raeburn 15231: =item * &DrawXYGraph()
1.137 matthew 15232:
1.138 matthew 15233: Facilitates the plotting of data in an XY graph.
15234: Puts plot definition data into the users environment in order for
15235: graph.png to plot it. Returns an <img> tag for the plot.
15236:
15237: Inputs:
15238:
15239: =over 4
15240:
15241: =item $Title: string, the title of the plot
15242:
15243: =item $xlabel: string, text describing the X-axis of the plot
15244:
15245: =item $ylabel: string, text describing the Y-axis of the plot
15246:
15247: =item $Max: scalar, the maximum Y value to use in the plot
15248: If $Max is < any data point, the graph will not be rendered.
15249:
15250: =item $colors: Array ref containing the hex color codes for the data to be
15251: plotted in. If undefined, default values will be used.
15252:
15253: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15254:
15255: =item $Ydata: Array ref containing Array refs.
1.185 www 15256: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15257:
15258: =item %Values: hash indicating or overriding any default values which are
15259: passed to graph.png.
15260: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15261:
15262: =back
15263:
15264: Returns:
15265:
15266: An <img> tag which references graph.png and the appropriate identifying
15267: information for the plot.
15268:
1.137 matthew 15269: =cut
15270:
15271: ############################################################
15272: ############################################################
15273: sub DrawXYGraph {
15274: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15275: #
15276: # Create the identifier for the graph
15277: my $identifier = &get_cgi_id();
15278: my $id = 'cgi.'.$identifier;
15279: #
15280: $Title = '' if (! defined($Title));
15281: $xlabel = '' if (! defined($xlabel));
15282: $ylabel = '' if (! defined($ylabel));
15283: my %ValuesHash =
15284: (
1.369 www 15285: $id.'.title' => &escape($Title),
15286: $id.'.xlabel' => &escape($xlabel),
15287: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15288: $id.'.y_max_value'=> $Max,
15289: $id.'.labels' => join(',',@$Xlabels),
15290: $id.'.PlotType' => 'XY',
15291: );
15292: #
15293: if (defined($colors) && ref($colors) eq 'ARRAY') {
15294: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15295: }
15296: #
15297: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15298: return '';
15299: }
15300: my $NumSets=1;
1.138 matthew 15301: foreach my $array (@{$Ydata}){
1.137 matthew 15302: next if (! ref($array));
15303: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15304: }
1.138 matthew 15305: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15306: #
15307: # Deal with other parameters
15308: while (my ($key,$value) = each(%Values)) {
15309: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15310: }
15311: #
1.646 raeburn 15312: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15313: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15314: }
15315:
15316: ############################################################
15317: ############################################################
15318:
15319: =pod
15320:
1.648 raeburn 15321: =item * &DrawXYYGraph()
1.138 matthew 15322:
15323: Facilitates the plotting of data in an XY graph with two Y axes.
15324: Puts plot definition data into the users environment in order for
15325: graph.png to plot it. Returns an <img> tag for the plot.
15326:
15327: Inputs:
15328:
15329: =over 4
15330:
15331: =item $Title: string, the title of the plot
15332:
15333: =item $xlabel: string, text describing the X-axis of the plot
15334:
15335: =item $ylabel: string, text describing the Y-axis of the plot
15336:
15337: =item $colors: Array ref containing the hex color codes for the data to be
15338: plotted in. If undefined, default values will be used.
15339:
15340: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15341:
15342: =item $Ydata1: The first data set
15343:
15344: =item $Min1: The minimum value of the left Y-axis
15345:
15346: =item $Max1: The maximum value of the left Y-axis
15347:
15348: =item $Ydata2: The second data set
15349:
15350: =item $Min2: The minimum value of the right Y-axis
15351:
15352: =item $Max2: The maximum value of the left Y-axis
15353:
15354: =item %Values: hash indicating or overriding any default values which are
15355: passed to graph.png.
15356: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15357:
15358: =back
15359:
15360: Returns:
15361:
15362: An <img> tag which references graph.png and the appropriate identifying
15363: information for the plot.
1.136 matthew 15364:
15365: =cut
15366:
15367: ############################################################
15368: ############################################################
1.137 matthew 15369: sub DrawXYYGraph {
15370: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15371: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15372: #
15373: # Create the identifier for the graph
15374: my $identifier = &get_cgi_id();
15375: my $id = 'cgi.'.$identifier;
15376: #
15377: $Title = '' if (! defined($Title));
15378: $xlabel = '' if (! defined($xlabel));
15379: $ylabel = '' if (! defined($ylabel));
15380: my %ValuesHash =
15381: (
1.369 www 15382: $id.'.title' => &escape($Title),
15383: $id.'.xlabel' => &escape($xlabel),
15384: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15385: $id.'.labels' => join(',',@$Xlabels),
15386: $id.'.PlotType' => 'XY',
15387: $id.'.NumSets' => 2,
1.137 matthew 15388: $id.'.two_axes' => 1,
15389: $id.'.y1_max_value' => $Max1,
15390: $id.'.y1_min_value' => $Min1,
15391: $id.'.y2_max_value' => $Max2,
15392: $id.'.y2_min_value' => $Min2,
1.136 matthew 15393: );
15394: #
1.137 matthew 15395: if (defined($colors) && ref($colors) eq 'ARRAY') {
15396: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15397: }
15398: #
15399: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15400: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15401: return '';
15402: }
15403: my $NumSets=1;
1.137 matthew 15404: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15405: next if (! ref($array));
15406: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15407: }
15408: #
15409: # Deal with other parameters
15410: while (my ($key,$value) = each(%Values)) {
15411: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15412: }
15413: #
1.646 raeburn 15414: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15415: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15416: }
15417:
15418: ############################################################
15419: ############################################################
15420:
15421: =pod
15422:
1.157 matthew 15423: =back
15424:
1.139 matthew 15425: =head1 Statistics helper routines?
15426:
15427: Bad place for them but what the hell.
15428:
1.157 matthew 15429: =over 4
15430:
1.648 raeburn 15431: =item * &chartlink()
1.139 matthew 15432:
15433: Returns a link to the chart for a specific student.
15434:
15435: Inputs:
15436:
15437: =over 4
15438:
15439: =item $linktext: The text of the link
15440:
15441: =item $sname: The students username
15442:
15443: =item $sdomain: The students domain
15444:
15445: =back
15446:
1.157 matthew 15447: =back
15448:
1.139 matthew 15449: =cut
15450:
15451: ############################################################
15452: ############################################################
15453: sub chartlink {
15454: my ($linktext, $sname, $sdomain) = @_;
15455: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15456: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15457: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15458: '">'.$linktext.'</a>';
1.153 matthew 15459: }
15460:
15461: #######################################################
15462: #######################################################
15463:
15464: =pod
15465:
15466: =head1 Course Environment Routines
1.157 matthew 15467:
15468: =over 4
1.153 matthew 15469:
1.648 raeburn 15470: =item * &restore_course_settings()
1.153 matthew 15471:
1.648 raeburn 15472: =item * &store_course_settings()
1.153 matthew 15473:
15474: Restores/Store indicated form parameters from the course environment.
15475: Will not overwrite existing values of the form parameters.
15476:
15477: Inputs:
15478: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15479:
15480: a hash ref describing the data to be stored. For example:
15481:
15482: %Save_Parameters = ('Status' => 'scalar',
15483: 'chartoutputmode' => 'scalar',
15484: 'chartoutputdata' => 'scalar',
15485: 'Section' => 'array',
1.373 raeburn 15486: 'Group' => 'array',
1.153 matthew 15487: 'StudentData' => 'array',
15488: 'Maps' => 'array');
15489:
15490: Returns: both routines return nothing
15491:
1.631 raeburn 15492: =back
15493:
1.153 matthew 15494: =cut
15495:
15496: #######################################################
15497: #######################################################
15498: sub store_course_settings {
1.496 albertel 15499: return &store_settings($env{'request.course.id'},@_);
15500: }
15501:
15502: sub store_settings {
1.153 matthew 15503: # save to the environment
15504: # appenv the same items, just to be safe
1.300 albertel 15505: my $udom = $env{'user.domain'};
15506: my $uname = $env{'user.name'};
1.496 albertel 15507: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15508: my %SaveHash;
15509: my %AppHash;
15510: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15511: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15512: my $envname = 'environment.'.$basename;
1.258 albertel 15513: if (exists($env{'form.'.$setting})) {
1.153 matthew 15514: # Save this value away
15515: if ($type eq 'scalar' &&
1.258 albertel 15516: (! exists($env{$envname}) ||
15517: $env{$envname} ne $env{'form.'.$setting})) {
15518: $SaveHash{$basename} = $env{'form.'.$setting};
15519: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15520: } elsif ($type eq 'array') {
15521: my $stored_form;
1.258 albertel 15522: if (ref($env{'form.'.$setting})) {
1.153 matthew 15523: $stored_form = join(',',
15524: map {
1.369 www 15525: &escape($_);
1.258 albertel 15526: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15527: } else {
15528: $stored_form =
1.369 www 15529: &escape($env{'form.'.$setting});
1.153 matthew 15530: }
15531: # Determine if the array contents are the same.
1.258 albertel 15532: if ($stored_form ne $env{$envname}) {
1.153 matthew 15533: $SaveHash{$basename} = $stored_form;
15534: $AppHash{$envname} = $stored_form;
15535: }
15536: }
15537: }
15538: }
15539: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15540: $udom,$uname);
1.153 matthew 15541: if ($put_result !~ /^(ok|delayed)/) {
15542: &Apache::lonnet::logthis('unable to save form parameters, '.
15543: 'got error:'.$put_result);
15544: }
15545: # Make sure these settings stick around in this session, too
1.646 raeburn 15546: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15547: return;
15548: }
15549:
15550: sub restore_course_settings {
1.499 albertel 15551: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15552: }
15553:
15554: sub restore_settings {
15555: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15556: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15557: next if (exists($env{'form.'.$setting}));
1.496 albertel 15558: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15559: '.'.$setting;
1.258 albertel 15560: if (exists($env{$envname})) {
1.153 matthew 15561: if ($type eq 'scalar') {
1.258 albertel 15562: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15563: } elsif ($type eq 'array') {
1.258 albertel 15564: $env{'form.'.$setting} = [
1.153 matthew 15565: map {
1.369 www 15566: &unescape($_);
1.258 albertel 15567: } split(',',$env{$envname})
1.153 matthew 15568: ];
15569: }
15570: }
15571: }
1.127 matthew 15572: }
15573:
1.618 raeburn 15574: #######################################################
15575: #######################################################
15576:
15577: =pod
15578:
15579: =head1 Domain E-mail Routines
15580:
15581: =over 4
15582:
1.648 raeburn 15583: =item * &build_recipient_list()
1.618 raeburn 15584:
1.1075.2.44 raeburn 15585: Build recipient lists for following types of e-mail:
1.766 raeburn 15586: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 15587: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15588: module change checking, student/employee ID conflict checks, as
15589: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15590: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15591:
15592: Inputs:
1.1075.2.44 raeburn 15593: defmail (scalar - email address of default recipient),
15594: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15595: requestsmail, updatesmail, or idconflictsmail).
15596:
1.619 raeburn 15597: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 15598:
15599: origmail (scalar - email address of recipient from loncapa.conf,
15600: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 15601:
1.1075.2.139 raeburn 15602: $requname username of requester (if mailing type is helpdeskmail)
15603:
15604: $requdom domain of requester (if mailing type is helpdeskmail)
15605:
15606: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15607:
1.655 raeburn 15608: Returns: comma separated list of addresses to which to send e-mail.
15609:
15610: =back
1.618 raeburn 15611:
15612: =cut
15613:
15614: ############################################################
15615: ############################################################
15616: sub build_recipient_list {
1.1075.2.139 raeburn 15617: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15618: my @recipients;
1.1075.2.122 raeburn 15619: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15620: my %domconfig =
1.1075.2.122 raeburn 15621: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15622: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15623: if (exists($domconfig{'contacts'}{$mailing})) {
15624: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15625: my @contacts = ('adminemail','supportemail');
15626: foreach my $item (@contacts) {
15627: if ($domconfig{'contacts'}{$mailing}{$item}) {
15628: my $addr = $domconfig{'contacts'}{$item};
15629: if (!grep(/^\Q$addr\E$/,@recipients)) {
15630: push(@recipients,$addr);
15631: }
1.619 raeburn 15632: }
1.1075.2.122 raeburn 15633: }
15634: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15635: if ($mailing eq 'helpdeskmail') {
15636: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15637: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15638: my @ok_bccs;
15639: foreach my $bcc (@bccs) {
15640: $bcc =~ s/^\s+//g;
15641: $bcc =~ s/\s+$//g;
15642: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15643: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15644: push(@ok_bccs,$bcc);
15645: }
15646: }
15647: }
15648: if (@ok_bccs > 0) {
15649: $allbcc = join(', ',@ok_bccs);
15650: }
15651: }
15652: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15653: }
15654: }
1.766 raeburn 15655: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15656: $lastresort = $origmail;
1.618 raeburn 15657: }
1.1075.2.139 raeburn 15658: if ($mailing eq 'helpdeskmail') {
15659: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15660: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15661: my ($inststatus,$inststatus_checked);
15662: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15663: ($env{'user.domain'} ne 'public')) {
15664: $inststatus_checked = 1;
15665: $inststatus = $env{'environment.inststatus'};
15666: }
15667: unless ($inststatus_checked) {
15668: if (($requname ne '') && ($requdom ne '')) {
15669: if (($requname =~ /^$match_username$/) &&
15670: ($requdom =~ /^$match_domain$/) &&
15671: (&Apache::lonnet::domain($requdom))) {
15672: my $requhome = &Apache::lonnet::homeserver($requname,
15673: $requdom);
15674: unless ($requhome eq 'no_host') {
15675: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15676: $inststatus = $userenv{'inststatus'};
15677: $inststatus_checked = 1;
15678: }
15679: }
15680: }
15681: }
15682: unless ($inststatus_checked) {
15683: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15684: my %srch = (srchby => 'email',
15685: srchdomain => $defdom,
15686: srchterm => $reqemail,
15687: srchtype => 'exact');
15688: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15689: foreach my $uname (keys(%srch_results)) {
15690: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15691: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15692: $inststatus_checked = 1;
15693: last;
15694: }
15695: }
15696: unless ($inststatus_checked) {
15697: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15698: if ($dirsrchres eq 'ok') {
15699: foreach my $uname (keys(%srch_results)) {
15700: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15701: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15702: $inststatus_checked = 1;
15703: last;
15704: }
15705: }
15706: }
15707: }
15708: }
15709: }
15710: if ($inststatus ne '') {
15711: foreach my $status (split(/\:/,$inststatus)) {
15712: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15713: my @contacts = ('adminemail','supportemail');
15714: foreach my $item (@contacts) {
15715: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15716: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15717: if (!grep(/^\Q$addr\E$/,@recipients)) {
15718: push(@recipients,$addr);
15719: }
15720: }
15721: }
15722: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15723: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15724: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15725: my @ok_bccs;
15726: foreach my $bcc (@bccs) {
15727: $bcc =~ s/^\s+//g;
15728: $bcc =~ s/\s+$//g;
15729: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15730: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15731: push(@ok_bccs,$bcc);
15732: }
15733: }
15734: }
15735: if (@ok_bccs > 0) {
15736: $allbcc = join(', ',@ok_bccs);
15737: }
15738: }
15739: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15740: last;
15741: }
15742: }
15743: }
15744: }
15745: }
1.619 raeburn 15746: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15747: $lastresort = $origmail;
15748: }
1.1075.2.128 raeburn 15749: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15750: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15751: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15752: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15753: my %what = (
15754: perlvar => 1,
15755: );
15756: my $primary = &Apache::lonnet::domain($defdom,'primary');
15757: if ($primary) {
15758: my $gotaddr;
15759: my ($result,$returnhash) =
15760: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15761: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15762: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15763: $lastresort = $returnhash->{'lonSupportEMail'};
15764: $gotaddr = 1;
15765: }
15766: }
15767: unless ($gotaddr) {
15768: my $uintdom = &Apache::lonnet::internet_dom($primary);
15769: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15770: unless ($uintdom eq $intdom) {
15771: my %domconfig =
15772: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15773: if (ref($domconfig{'contacts'}) eq 'HASH') {
15774: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15775: my @contacts = ('adminemail','supportemail');
15776: foreach my $item (@contacts) {
15777: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15778: my $addr = $domconfig{'contacts'}{$item};
15779: if (!grep(/^\Q$addr\E$/,@recipients)) {
15780: push(@recipients,$addr);
15781: }
15782: }
15783: }
15784: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15785: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15786: }
15787: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15788: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15789: my @ok_bccs;
15790: foreach my $bcc (@bccs) {
15791: $bcc =~ s/^\s+//g;
15792: $bcc =~ s/\s+$//g;
15793: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15794: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15795: push(@ok_bccs,$bcc);
15796: }
15797: }
15798: }
15799: if (@ok_bccs > 0) {
15800: $allbcc = join(', ',@ok_bccs);
15801: }
15802: }
15803: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15804: }
15805: }
15806: }
15807: }
15808: }
15809: }
1.618 raeburn 15810: }
1.688 raeburn 15811: if (defined($defmail)) {
15812: if ($defmail ne '') {
15813: push(@recipients,$defmail);
15814: }
1.618 raeburn 15815: }
15816: if ($otheremails) {
1.619 raeburn 15817: my @others;
15818: if ($otheremails =~ /,/) {
15819: @others = split(/,/,$otheremails);
1.618 raeburn 15820: } else {
1.619 raeburn 15821: push(@others,$otheremails);
15822: }
15823: foreach my $addr (@others) {
15824: if (!grep(/^\Q$addr\E$/,@recipients)) {
15825: push(@recipients,$addr);
15826: }
1.618 raeburn 15827: }
15828: }
1.1075.2.128 raeburn 15829: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15830: if ((!@recipients) && ($lastresort ne '')) {
15831: push(@recipients,$lastresort);
15832: }
15833: } elsif ($lastresort ne '') {
15834: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15835: push(@recipients,$lastresort);
15836: }
15837: }
15838: my $recipientlist = join(',',@recipients);
15839: if (wantarray) {
15840: return ($recipientlist,$allbcc,$addtext);
15841: } else {
15842: return $recipientlist;
15843: }
1.618 raeburn 15844: }
15845:
1.127 matthew 15846: ############################################################
15847: ############################################################
1.154 albertel 15848:
1.655 raeburn 15849: =pod
15850:
15851: =head1 Course Catalog Routines
15852:
15853: =over 4
15854:
15855: =item * &gather_categories()
15856:
15857: Converts category definitions - keys of categories hash stored in
15858: coursecategories in configuration.db on the primary library server in a
15859: domain - to an array. Also generates javascript and idx hash used to
15860: generate Domain Coordinator interface for editing Course Categories.
15861:
15862: Inputs:
1.663 raeburn 15863:
1.655 raeburn 15864: categories (reference to hash of category definitions).
1.663 raeburn 15865:
1.655 raeburn 15866: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15867: categories and subcategories).
1.663 raeburn 15868:
1.655 raeburn 15869: idx (reference to hash of counters used in Domain Coordinator interface for
15870: editing Course Categories).
1.663 raeburn 15871:
1.655 raeburn 15872: jsarray (reference to array of categories used to create Javascript arrays for
15873: Domain Coordinator interface for editing Course Categories).
15874:
15875: Returns: nothing
15876:
15877: Side effects: populates cats, idx and jsarray.
15878:
15879: =cut
15880:
15881: sub gather_categories {
15882: my ($categories,$cats,$idx,$jsarray) = @_;
15883: my %counters;
15884: my $num = 0;
15885: foreach my $item (keys(%{$categories})) {
15886: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15887: if ($container eq '' && $depth == 0) {
15888: $cats->[$depth][$categories->{$item}] = $cat;
15889: } else {
15890: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15891: }
15892: my ($escitem,$tail) = split(/:/,$item,2);
15893: if ($counters{$tail} eq '') {
15894: $counters{$tail} = $num;
15895: $num ++;
15896: }
15897: if (ref($idx) eq 'HASH') {
15898: $idx->{$item} = $counters{$tail};
15899: }
15900: if (ref($jsarray) eq 'ARRAY') {
15901: push(@{$jsarray->[$counters{$tail}]},$item);
15902: }
15903: }
15904: return;
15905: }
15906:
15907: =pod
15908:
15909: =item * &extract_categories()
15910:
15911: Used to generate breadcrumb trails for course categories.
15912:
15913: Inputs:
1.663 raeburn 15914:
1.655 raeburn 15915: categories (reference to hash of category definitions).
1.663 raeburn 15916:
1.655 raeburn 15917: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15918: categories and subcategories).
1.663 raeburn 15919:
1.655 raeburn 15920: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15921:
1.655 raeburn 15922: allitems (reference to hash - key is category key
15923: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15924:
1.655 raeburn 15925: idx (reference to hash of counters used in Domain Coordinator interface for
15926: editing Course Categories).
1.663 raeburn 15927:
1.655 raeburn 15928: jsarray (reference to array of categories used to create Javascript arrays for
15929: Domain Coordinator interface for editing Course Categories).
15930:
1.665 raeburn 15931: subcats (reference to hash of arrays containing all subcategories within each
15932: category, -recursive)
15933:
1.1075.2.132 raeburn 15934: maxd (reference to hash used to hold max depth for all top-level categories).
15935:
1.655 raeburn 15936: Returns: nothing
15937:
15938: Side effects: populates trails and allitems hash references.
15939:
15940: =cut
15941:
15942: sub extract_categories {
1.1075.2.132 raeburn 15943: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15944: if (ref($categories) eq 'HASH') {
15945: &gather_categories($categories,$cats,$idx,$jsarray);
15946: if (ref($cats->[0]) eq 'ARRAY') {
15947: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15948: my $name = $cats->[0][$i];
15949: my $item = &escape($name).'::0';
15950: my $trailstr;
15951: if ($name eq 'instcode') {
15952: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15953: } elsif ($name eq 'communities') {
15954: $trailstr = &mt('Communities');
1.655 raeburn 15955: } else {
15956: $trailstr = $name;
15957: }
15958: if ($allitems->{$item} eq '') {
15959: push(@{$trails},$trailstr);
15960: $allitems->{$item} = scalar(@{$trails})-1;
15961: }
15962: my @parents = ($name);
15963: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15964: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15965: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15966: if (ref($subcats) eq 'HASH') {
15967: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15968: }
1.1075.2.132 raeburn 15969: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15970: }
15971: } else {
15972: if (ref($subcats) eq 'HASH') {
15973: $subcats->{$item} = [];
1.655 raeburn 15974: }
1.1075.2.132 raeburn 15975: if (ref($maxd) eq 'HASH') {
15976: $maxd->{$name} = 1;
15977: }
1.655 raeburn 15978: }
15979: }
15980: }
15981: }
15982: return;
15983: }
15984:
15985: =pod
15986:
1.1075.2.56 raeburn 15987: =item * &recurse_categories()
1.655 raeburn 15988:
15989: Recursively used to generate breadcrumb trails for course categories.
15990:
15991: Inputs:
1.663 raeburn 15992:
1.655 raeburn 15993: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15994: categories and subcategories).
1.663 raeburn 15995:
1.655 raeburn 15996: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15997:
15998: category (current course category, for which breadcrumb trail is being generated).
15999:
16000: trails (reference to array of breadcrumb trails for each category).
16001:
1.655 raeburn 16002: allitems (reference to hash - key is category key
16003: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16004:
1.655 raeburn 16005: parents (array containing containers directories for current category,
16006: back to top level).
16007:
16008: Returns: nothing
16009:
16010: Side effects: populates trails and allitems hash references
16011:
16012: =cut
16013:
16014: sub recurse_categories {
1.1075.2.132 raeburn 16015: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16016: my $shallower = $depth - 1;
16017: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16018: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16019: my $name = $cats->[$depth]{$category}[$k];
16020: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 16021:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16022: if ($allitems->{$item} eq '') {
16023: push(@{$trails},$trailstr);
16024: $allitems->{$item} = scalar(@{$trails})-1;
16025: }
16026: my $deeper = $depth+1;
16027: push(@{$parents},$category);
1.665 raeburn 16028: if (ref($subcats) eq 'HASH') {
16029: my $subcat = &escape($name).':'.$category.':'.$depth;
16030: for (my $j=@{$parents}; $j>=0; $j--) {
16031: my $higher;
16032: if ($j > 0) {
16033: $higher = &escape($parents->[$j]).':'.
16034: &escape($parents->[$j-1]).':'.$j;
16035: } else {
16036: $higher = &escape($parents->[$j]).'::'.$j;
16037: }
16038: push(@{$subcats->{$higher}},$subcat);
16039: }
16040: }
16041: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 16042: $subcats,$maxd);
1.655 raeburn 16043: pop(@{$parents});
16044: }
16045: } else {
16046: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 16047: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16048: if ($allitems->{$item} eq '') {
16049: push(@{$trails},$trailstr);
16050: $allitems->{$item} = scalar(@{$trails})-1;
16051: }
1.1075.2.132 raeburn 16052: if (ref($maxd) eq 'HASH') {
16053: if ($depth > $maxd->{$parents->[0]}) {
16054: $maxd->{$parents->[0]} = $depth;
16055: }
16056: }
1.655 raeburn 16057: }
16058: return;
16059: }
16060:
1.663 raeburn 16061: =pod
16062:
1.1075.2.56 raeburn 16063: =item * &assign_categories_table()
1.663 raeburn 16064:
16065: Create a datatable for display of hierarchical categories in a domain,
16066: with checkboxes to allow a course to be categorized.
16067:
16068: Inputs:
16069:
16070: cathash - reference to hash of categories defined for the domain (from
16071: configuration.db)
16072:
16073: currcat - scalar with an & separated list of categories assigned to a course.
16074:
1.919 raeburn 16075: type - scalar contains course type (Course or Community).
16076:
1.1075.2.117 raeburn 16077: disabled - scalar (optional) contains disabled="disabled" if input elements are
16078: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16079:
1.663 raeburn 16080: Returns: $output (markup to be displayed)
16081:
16082: =cut
16083:
16084: sub assign_categories_table {
1.1075.2.117 raeburn 16085: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16086: my $output;
16087: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 16088: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16089: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16090: $maxdepth = scalar(@cats);
16091: if (@cats > 0) {
16092: my $itemcount = 0;
16093: if (ref($cats[0]) eq 'ARRAY') {
16094: my @currcategories;
16095: if ($currcat ne '') {
16096: @currcategories = split('&',$currcat);
16097: }
1.919 raeburn 16098: my $table;
1.663 raeburn 16099: for (my $i=0; $i<@{$cats[0]}; $i++) {
16100: my $parent = $cats[0][$i];
1.919 raeburn 16101: next if ($parent eq 'instcode');
16102: if ($type eq 'Community') {
16103: next unless ($parent eq 'communities');
16104: } else {
16105: next if ($parent eq 'communities');
16106: }
1.663 raeburn 16107: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16108: my $item = &escape($parent).'::0';
16109: my $checked = '';
16110: if (@currcategories > 0) {
16111: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16112: $checked = ' checked="checked"';
1.663 raeburn 16113: }
16114: }
1.919 raeburn 16115: my $parent_title = $parent;
16116: if ($parent eq 'communities') {
16117: $parent_title = &mt('Communities');
16118: }
16119: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16120: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16121: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16122: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16123: my $depth = 1;
16124: push(@path,$parent);
1.1075.2.117 raeburn 16125: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16126: pop(@path);
1.919 raeburn 16127: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16128: $itemcount ++;
16129: }
1.919 raeburn 16130: if ($itemcount) {
16131: $output = &Apache::loncommon::start_data_table().
16132: $table.
16133: &Apache::loncommon::end_data_table();
16134: }
1.663 raeburn 16135: }
16136: }
16137: }
16138: return $output;
16139: }
16140:
16141: =pod
16142:
1.1075.2.56 raeburn 16143: =item * &assign_category_rows()
1.663 raeburn 16144:
16145: Create a datatable row for display of nested categories in a domain,
16146: with checkboxes to allow a course to be categorized,called recursively.
16147:
16148: Inputs:
16149:
16150: itemcount - track row number for alternating colors
16151:
16152: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16153: categories and subcategories.
16154:
16155: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16156:
16157: parent - parent of current category item
16158:
16159: path - Array containing all categories back up through the hierarchy from the
16160: current category to the top level.
16161:
16162: currcategories - reference to array of current categories assigned to the course
16163:
1.1075.2.117 raeburn 16164: disabled - scalar (optional) contains disabled="disabled" if input elements are
16165: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16166:
1.663 raeburn 16167: Returns: $output (markup to be displayed).
16168:
16169: =cut
16170:
16171: sub assign_category_rows {
1.1075.2.117 raeburn 16172: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16173: my ($text,$name,$item,$chgstr);
16174: if (ref($cats) eq 'ARRAY') {
16175: my $maxdepth = scalar(@{$cats});
16176: if (ref($cats->[$depth]) eq 'HASH') {
16177: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16178: my $numchildren = @{$cats->[$depth]{$parent}};
16179: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 16180: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16181: for (my $j=0; $j<$numchildren; $j++) {
16182: $name = $cats->[$depth]{$parent}[$j];
16183: $item = &escape($name).':'.&escape($parent).':'.$depth;
16184: my $deeper = $depth+1;
16185: my $checked = '';
16186: if (ref($currcategories) eq 'ARRAY') {
16187: if (@{$currcategories} > 0) {
16188: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16189: $checked = ' checked="checked"';
1.663 raeburn 16190: }
16191: }
16192: }
1.664 raeburn 16193: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16194: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16195: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16196: '<input type="hidden" name="catname" value="'.$name.'" />'.
16197: '</td><td>';
1.663 raeburn 16198: if (ref($path) eq 'ARRAY') {
16199: push(@{$path},$name);
1.1075.2.117 raeburn 16200: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16201: pop(@{$path});
16202: }
16203: $text .= '</td></tr>';
16204: }
16205: $text .= '</table></td>';
16206: }
16207: }
16208: }
16209: return $text;
16210: }
16211:
1.1075.2.69 raeburn 16212: =pod
16213:
16214: =back
16215:
16216: =cut
16217:
1.655 raeburn 16218: ############################################################
16219: ############################################################
16220:
16221:
1.443 albertel 16222: sub commit_customrole {
1.664 raeburn 16223: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16224: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16225: ($start?', '.&mt('starting').' '.localtime($start):'').
16226: ($end?', ending '.localtime($end):'').': <b>'.
16227: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16228: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16229: '</b><br />';
16230: return $output;
16231: }
16232:
16233: sub commit_standardrole {
1.1075.2.31 raeburn 16234: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16235: my ($output,$logmsg,$linefeed);
16236: if ($context eq 'auto') {
16237: $linefeed = "\n";
16238: } else {
16239: $linefeed = "<br />\n";
16240: }
1.443 albertel 16241: if ($three eq 'st') {
1.541 raeburn 16242: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 16243: $one,$two,$sec,$context,$credits);
1.541 raeburn 16244: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16245: ($result eq 'unknown_course') || ($result eq 'refused')) {
16246: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16247: } else {
1.541 raeburn 16248: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16249: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16250: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16251: if ($context eq 'auto') {
16252: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16253: } else {
16254: $output .= '<b>'.$result.'</b>'.$linefeed.
16255: &mt('Add to classlist').': <b>ok</b>';
16256: }
16257: $output .= $linefeed;
1.443 albertel 16258: }
16259: } else {
16260: $output = &mt('Assigning').' '.$three.' in '.$url.
16261: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16262: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16263: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16264: if ($context eq 'auto') {
16265: $output .= $result.$linefeed;
16266: } else {
16267: $output .= '<b>'.$result.'</b>'.$linefeed;
16268: }
1.443 albertel 16269: }
16270: return $output;
16271: }
16272:
16273: sub commit_studentrole {
1.1075.2.31 raeburn 16274: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16275: $credits) = @_;
1.626 raeburn 16276: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16277: if ($context eq 'auto') {
16278: $linefeed = "\n";
16279: } else {
16280: $linefeed = '<br />'."\n";
16281: }
1.443 albertel 16282: if (defined($one) && defined($two)) {
16283: my $cid=$one.'_'.$two;
16284: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16285: my $secchange = 0;
16286: my $expire_role_result;
16287: my $modify_section_result;
1.628 raeburn 16288: if ($oldsec ne '-1') {
16289: if ($oldsec ne $sec) {
1.443 albertel 16290: $secchange = 1;
1.628 raeburn 16291: my $now = time;
1.443 albertel 16292: my $uurl='/'.$cid;
16293: $uurl=~s/\_/\//g;
16294: if ($oldsec) {
16295: $uurl.='/'.$oldsec;
16296: }
1.626 raeburn 16297: $oldsecurl = $uurl;
1.628 raeburn 16298: $expire_role_result =
1.1075.2.161. .14(raeb 16299:-23): &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 16300: if ($env{'request.course.sec'} ne '') {
16301: if ($expire_role_result eq 'refused') {
16302: my @roles = ('st');
16303: my @statuses = ('previous');
16304: my @roledoms = ($one);
16305: my $withsec = 1;
16306: my %roleshash =
16307: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16308: \@statuses,\@roles,\@roledoms,$withsec);
16309: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16310: my ($oldstart,$oldend) =
16311: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16312: if ($oldend > 0 && $oldend <= $now) {
16313: $expire_role_result = 'ok';
16314: }
16315: }
16316: }
16317: }
1.443 albertel 16318: $result = $expire_role_result;
16319: }
16320: }
16321: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 16322: $modify_section_result =
16323: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16324: undef,undef,undef,$sec,
16325: $end,$start,'','',$cid,
16326: '',$context,$credits);
1.443 albertel 16327: if ($modify_section_result =~ /^ok/) {
16328: if ($secchange == 1) {
1.628 raeburn 16329: if ($sec eq '') {
16330: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16331: } else {
16332: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16333: }
1.443 albertel 16334: } elsif ($oldsec eq '-1') {
1.628 raeburn 16335: if ($sec eq '') {
16336: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16337: } else {
16338: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16339: }
1.443 albertel 16340: } else {
1.628 raeburn 16341: if ($sec eq '') {
16342: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16343: } else {
16344: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16345: }
1.443 albertel 16346: }
16347: } else {
1.628 raeburn 16348: if ($secchange) {
16349: $$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;
16350: } else {
16351: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16352: }
1.443 albertel 16353: }
16354: $result = $modify_section_result;
16355: } elsif ($secchange == 1) {
1.628 raeburn 16356: if ($oldsec eq '') {
1.1075.2.20 raeburn 16357: $$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 16358: } else {
16359: $$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;
16360: }
1.626 raeburn 16361: if ($expire_role_result eq 'refused') {
16362: my $newsecurl = '/'.$cid;
16363: $newsecurl =~ s/\_/\//g;
16364: if ($sec ne '') {
16365: $newsecurl.='/'.$sec;
16366: }
16367: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16368: if ($sec eq '') {
16369: $$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;
16370: } else {
16371: $$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;
16372: }
16373: }
16374: }
1.443 albertel 16375: }
16376: } else {
1.626 raeburn 16377: $$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 16378: $result = "error: incomplete course id\n";
16379: }
16380: return $result;
16381: }
16382:
1.1075.2.25 raeburn 16383: sub show_role_extent {
16384: my ($scope,$context,$role) = @_;
16385: $scope =~ s{^/}{};
16386: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16387: push(@courseroles,'co');
16388: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16389: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16390: $scope =~ s{/}{_};
16391: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16392: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16393: my ($audom,$auname) = split(/\//,$scope);
16394: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16395: &Apache::loncommon::plainname($auname,$audom).'</span>');
16396: } else {
16397: $scope =~ s{/$}{};
16398: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16399: &Apache::lonnet::domain($scope,'description').'</span>');
16400: }
16401: }
16402:
1.443 albertel 16403: ############################################################
16404: ############################################################
16405:
1.566 albertel 16406: sub check_clone {
1.578 raeburn 16407: my ($args,$linefeed) = @_;
1.566 albertel 16408: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16409: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16410: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 16411:21): my $clonetitle;
16412:21): my @clonemsg;
1.566 albertel 16413: my $can_clone = 0;
1.944 raeburn 16414: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16415: if ($lctype ne 'community') {
16416: $lctype = 'course';
16417: }
1.566 albertel 16418: if ($clonehome eq 'no_host') {
1.944 raeburn 16419: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16420:21): push(@clonemsg,({
16421:21): mt => 'No new community created.',
16422:21): args => [],
16423:21): },
16424:21): {
16425:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16426:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16427:21): }));
1.908 raeburn 16428: } else {
1.1075.2.161. .1(raebu 16429:21): push(@clonemsg,({
16430:21): mt => 'No new course created.',
16431:21): args => [],
16432:21): },
16433:21): {
16434:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16435:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16436:21): }));
16437:21): }
1.566 albertel 16438: } else {
16439: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 16440:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 16441: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16442: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 16443:21): push(@clonemsg,({
16444:21): mt => 'No new community created.',
16445:21): args => [],
16446:21): },
16447:21): {
16448:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16449:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16450:21): }));
16451:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16452: }
16453: }
1.1075.2.119 raeburn 16454: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16455: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16456: $can_clone = 1;
16457: } else {
1.1075.2.95 raeburn 16458: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16459: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 16460: if ($clonehash{'cloners'} eq '') {
16461: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16462: if ($domdefs{'canclone'}) {
16463: unless ($domdefs{'canclone'} eq 'none') {
16464: if ($domdefs{'canclone'} eq 'domain') {
16465: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16466: $can_clone = 1;
16467: }
16468: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16469: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16470: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16471: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16472: $can_clone = 1;
16473: }
16474: }
16475: }
1.908 raeburn 16476: }
1.1075.2.95 raeburn 16477: } else {
16478: my @cloners = split(/,/,$clonehash{'cloners'});
16479: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16480: $can_clone = 1;
1.1075.2.95 raeburn 16481: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16482: $can_clone = 1;
1.1075.2.96 raeburn 16483: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16484: $can_clone = 1;
1.1075.2.95 raeburn 16485: }
16486: unless ($can_clone) {
1.1075.2.96 raeburn 16487: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16488: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 16489: my (%gotdomdefaults,%gotcodedefaults);
16490: foreach my $cloner (@cloners) {
16491: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16492: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16493: my (%codedefaults,@code_order);
16494: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16495: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16496: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16497: }
16498: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16499: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16500: }
16501: } else {
16502: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16503: \%codedefaults,
16504: \@code_order);
16505: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16506: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16507: }
16508: if (@code_order > 0) {
16509: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16510: $cloner,$clonehash{'internal.coursecode'},
16511: $args->{'crscode'})) {
16512: $can_clone = 1;
16513: last;
16514: }
16515: }
16516: }
16517: }
16518: }
1.1075.2.96 raeburn 16519: }
16520: }
16521: unless ($can_clone) {
16522: my $ccrole = 'cc';
16523: if ($args->{'crstype'} eq 'Community') {
16524: $ccrole = 'co';
16525: }
16526: my %roleshash =
16527: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16528: $args->{'ccdomain'},
16529: 'userroles',['active'],[$ccrole],
16530: [$args->{'clonedomain'}]);
16531: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16532: $can_clone = 1;
16533: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16534: $args->{'ccuname'},$args->{'ccdomain'})) {
16535: $can_clone = 1;
1.1075.2.95 raeburn 16536: }
16537: }
16538: unless ($can_clone) {
16539: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16540:21): push(@clonemsg,({
16541:21): mt => 'No new community created.',
16542:21): args => [],
16543:21): },
16544:21): {
16545: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]).',
16546:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16547:21): }));
1.1075.2.95 raeburn 16548: } else {
1.1075.2.161. .1(raebu 16549:21): push(@clonemsg,({
16550:21): mt => 'No new course created.',
16551:21): args => [],
16552:21): },
16553:21): {
16554: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]).',
16555:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16556:21): }));
1.578 raeburn 16557: }
1.566 albertel 16558: }
1.578 raeburn 16559: }
1.566 albertel 16560: }
1.1075.2.161. .1(raebu 16561:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16562: }
16563:
1.444 albertel 16564: sub construct_course {
1.1075.2.119 raeburn 16565: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 16566:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16567:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16568: my $linefeed = '<br />'."\n";
16569: if ($context eq 'auto') {
16570: $linefeed = "\n";
16571: }
1.566 albertel 16572:
16573: #
16574: # Are we cloning?
16575: #
1.1075.2.161. .1(raebu 16576:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16577: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 16578:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16579: if (!$can_clone) {
1.1075.2.161. .1(raebu 16580:21): return (0,$outcome,$clonemsgref);
1.566 albertel 16581: }
16582: }
16583:
1.444 albertel 16584: #
16585: # Open course
16586: #
16587: my $crstype = lc($args->{'crstype'});
16588: my %cenv=();
16589: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16590: $args->{'cdescr'},
16591: $args->{'curl'},
16592: $args->{'course_home'},
16593: $args->{'nonstandard'},
16594: $args->{'crscode'},
16595: $args->{'ccuname'}.':'.
16596: $args->{'ccdomain'},
1.882 raeburn 16597: $args->{'crstype'},
1.1075.2.161. .1(raebu 16598:21): $cnum,$context,$category,
16599:21): $callercontext);
1.444 albertel 16600:
16601: # Note: The testing routines depend on this being output; see
16602: # Utils::Course. This needs to at least be output as a comment
16603: # if anyone ever decides to not show this, and Utils::Course::new
16604: # will need to be suitably modified.
1.1075.2.161. .1(raebu 16605:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16606:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16607:21): } else {
16608:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16609:21): }
1.943 raeburn 16610: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 16611:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16612: }
16613:
1.444 albertel 16614: #
16615: # Check if created correctly
16616: #
1.479 albertel 16617: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16618: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16619: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 16620:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16621:21): $outcome .= &mt_user($user_lh,
16622:21): 'Course creation failed, unrecognized course home server.');
16623:21): } else {
16624:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
16625:21): }
16626:21): $outcome .= $linefeed;
16627:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16628: }
1.541 raeburn 16629: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16630:
1.444 albertel 16631: #
1.566 albertel 16632: # Do the cloning
1.1075.2.161. .1(raebu 16633:21): #
16634:21): my @clonemsg;
1.566 albertel 16635: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 16636:21): push(@clonemsg,
16637:21): {
16638:21): mt => 'Created [_1] by cloning from [_2]',
16639:21): args => [$crstype,$clonetitle],
16640:21): });
1.566 albertel 16641: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16642: # Copy all files
1.1075.2.161. .1(raebu 16643:21): my @info =
16644:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16645:21): $args->{'dateshift'},$args->{'crscode'},
16646:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16647:21): $args->{'tinyurls'});
16648:21): if (@info) {
16649:21): push(@clonemsg,@info);
16650:21): }
1.444 albertel 16651: # Restore URL
1.566 albertel 16652: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16653: # Restore title
1.566 albertel 16654: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16655: # Restore creation date, creator and creation context.
16656: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16657: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16658: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16659: # Mark as cloned
1.566 albertel 16660: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16661: # Need to clone grading mode
16662: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16663: $cenv{'grading'}=$newenv{'grading'};
16664: # Do not clone these environment entries
16665: &Apache::lonnet::del('environment',
16666: ['default_enrollment_start_date',
16667: 'default_enrollment_end_date',
16668: 'question.email',
16669: 'policy.email',
16670: 'comment.email',
16671: 'pch.users.denied',
1.725 raeburn 16672: 'plc.users.denied',
16673: 'hidefromcat',
1.1075.2.36 raeburn 16674: 'checkforpriv',
1.1075.2.158 raeburn 16675: 'categories'],
1.638 www 16676: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16677: if ($args->{'textbook'}) {
16678: $cenv{'internal.textbook'} = $args->{'textbook'};
16679: }
1.444 albertel 16680: }
1.566 albertel 16681:
1.444 albertel 16682: #
16683: # Set environment (will override cloned, if existing)
16684: #
16685: my @sections = ();
16686: my @xlists = ();
16687: if ($args->{'crstype'}) {
16688: $cenv{'type'}=$args->{'crstype'};
16689: }
1.1075.2.161. .17(raeb 16690:-23): if ($args->{'lti'}) {
16691:-23): $cenv{'internal.lti'}=$args->{'lti'};
16692:-23): }
1.444 albertel 16693: if ($args->{'crsid'}) {
16694: $cenv{'courseid'}=$args->{'crsid'};
16695: }
16696: if ($args->{'crscode'}) {
16697: $cenv{'internal.coursecode'}=$args->{'crscode'};
16698: }
16699: if ($args->{'crsquota'} ne '') {
16700: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16701: } else {
16702: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16703: }
16704: if ($args->{'ccuname'}) {
16705: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16706: ':'.$args->{'ccdomain'};
16707: } else {
16708: $cenv{'internal.courseowner'} = $args->{'curruser'};
16709: }
1.1075.2.31 raeburn 16710: if ($args->{'defaultcredits'}) {
16711: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16712: }
1.444 albertel 16713: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.161. .20(raeb 16714:-23): my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 16715: if ($args->{'crssections'}) {
16716: $cenv{'internal.sectionnums'} = '';
16717: if ($args->{'crssections'} =~ m/,/) {
16718: @sections = split/,/,$args->{'crssections'};
16719: } else {
16720: $sections[0] = $args->{'crssections'};
16721: }
16722: if (@sections > 0) {
16723: foreach my $item (@sections) {
16724: my ($sec,$gp) = split/:/,$item;
16725: my $class = $args->{'crscode'}.$sec;
16726: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16727: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.161. .20(raeb 16728:-23): if ($addcheck eq 'ok') {
16729:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16730:-23): push(@oklcsecs,$gp);
16731:-23): }
16732:-23): } else {
1.1075.2.119 raeburn 16733: push(@badclasses,$class);
1.444 albertel 16734: }
16735: }
16736: $cenv{'internal.sectionnums'} =~ s/,$//;
16737: }
16738: }
16739: # do not hide course coordinator from staff listing,
16740: # even if privileged
16741: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16742: # add course coordinator's domain to domains to check for privileged users
16743: # if different to course domain
16744: if ($$crsudom ne $args->{'ccdomain'}) {
16745: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16746: }
1.444 albertel 16747: # add crosslistings
16748: if ($args->{'crsxlist'}) {
16749: $cenv{'internal.crosslistings'}='';
16750: if ($args->{'crsxlist'} =~ m/,/) {
16751: @xlists = split/,/,$args->{'crsxlist'};
16752: } else {
16753: $xlists[0] = $args->{'crsxlist'};
16754: }
16755: if (@xlists > 0) {
16756: foreach my $item (@xlists) {
16757: my ($xl,$gp) = split/:/,$item;
16758: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16759: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.161. .20(raeb 16760:-23): if ($addcheck eq 'ok') {
16761:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16762:-23): push(@oklcsecs,$gp);
16763:-23): }
16764:-23): } else {
1.1075.2.119 raeburn 16765: push(@badclasses,$xl);
1.444 albertel 16766: }
16767: }
16768: $cenv{'internal.crosslistings'} =~ s/,$//;
16769: }
16770: }
16771: if ($args->{'autoadds'}) {
16772: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16773: }
16774: if ($args->{'autodrops'}) {
16775: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16776: }
16777: # check for notification of enrollment changes
16778: my @notified = ();
16779: if ($args->{'notify_owner'}) {
16780: if ($args->{'ccuname'} ne '') {
16781: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16782: }
16783: }
16784: if ($args->{'notify_dc'}) {
16785: if ($uname ne '') {
1.630 raeburn 16786: push(@notified,$uname.':'.$udom);
1.444 albertel 16787: }
16788: }
16789: if (@notified > 0) {
16790: my $notifylist;
16791: if (@notified > 1) {
16792: $notifylist = join(',',@notified);
16793: } else {
16794: $notifylist = $notified[0];
16795: }
16796: $cenv{'internal.notifylist'} = $notifylist;
16797: }
16798: if (@badclasses > 0) {
16799: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16800: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16801: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16802: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16803: );
1.1075.2.119 raeburn 16804: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16805: &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 16806: if ($context eq 'auto') {
16807: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16808: } else {
1.566 albertel 16809: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16810: }
16811: foreach my $item (@badclasses) {
1.541 raeburn 16812: if ($context eq 'auto') {
1.1075.2.119 raeburn 16813: $outcome .= " - $item\n";
1.541 raeburn 16814: } else {
1.1075.2.119 raeburn 16815: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16816: }
1.1075.2.119 raeburn 16817: }
16818: if ($context eq 'auto') {
16819: $outcome .= $linefeed;
16820: } else {
16821: $outcome .= "</ul><br /><br /></div>\n";
16822: }
1.444 albertel 16823: }
16824: if ($args->{'no_end_date'}) {
16825: $args->{'endaccess'} = 0;
16826: }
1.1075.2.161. .20(raeb 16827:-23): # If an official course with institutional sections is created by cloning
16828:-23): # an existing course, section-specific hiding of course totals in student's
16829:-23): # view of grades as copied from cloned course, will be checked for valid
16830:-23): # sections.
16831:-23): if (($can_clone && $cloneid) &&
16832:-23): ($cenv{'internal.coursecode'} ne '') &&
16833:-23): ($cenv{'grading'} eq 'standard') &&
16834:-23): ($cenv{'hidetotals'} ne '') &&
16835:-23): ($cenv{'hidetotals'} ne 'all')) {
16836:-23): my @hidesecs;
16837:-23): my $deletehidetotals;
16838:-23): if (@oklcsecs) {
16839:-23): foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
16840:-23): if (grep(/^\Q$sec$/,@oklcsecs)) {
16841:-23): push(@hidesecs,$sec);
16842:-23): }
16843:-23): }
16844:-23): if (@hidesecs) {
16845:-23): $cenv{'hidetotals'} = join(',',@hidesecs);
16846:-23): } else {
16847:-23): $deletehidetotals = 1;
16848:-23): }
16849:-23): } else {
16850:-23): $deletehidetotals = 1;
16851:-23): }
16852:-23): if ($deletehidetotals) {
16853:-23): delete($cenv{'hidetotals'});
16854:-23): &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
16855:-23): }
16856:-23): }
1.444 albertel 16857: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16858: $cenv{'internal.autoend'}=$args->{'enrollend'};
16859: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16860: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16861: if ($args->{'showphotos'}) {
16862: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16863: }
16864: $cenv{'internal.authtype'} = $args->{'authtype'};
16865: $cenv{'internal.autharg'} = $args->{'autharg'};
16866: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16867: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16868: 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');
16869: if ($context eq 'auto') {
16870: $outcome .= $krb_msg;
16871: } else {
1.566 albertel 16872: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16873: }
16874: $outcome .= $linefeed;
1.444 albertel 16875: }
16876: }
16877: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16878: if ($args->{'setpolicy'}) {
16879: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16880: }
16881: if ($args->{'setcontent'}) {
16882: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16883: }
1.1075.2.110 raeburn 16884: if ($args->{'setcomment'}) {
16885: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16886: }
1.444 albertel 16887: }
16888: if ($args->{'reshome'}) {
16889: $cenv{'reshome'}=$args->{'reshome'}.'/';
16890: $cenv{'reshome'}=~s/\/+$/\//;
16891: }
16892: #
16893: # course has keyed access
16894: #
16895: if ($args->{'setkeys'}) {
16896: $cenv{'keyaccess'}='yes';
16897: }
16898: # if specified, key authority is not course, but user
16899: # only active if keyaccess is yes
16900: if ($args->{'keyauth'}) {
1.487 albertel 16901: my ($user,$domain) = split(':',$args->{'keyauth'});
16902: $user = &LONCAPA::clean_username($user);
16903: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16904: if ($user ne '' && $domain ne '') {
1.487 albertel 16905: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16906: }
16907: }
16908:
1.1075.2.59 raeburn 16909: #
16910: # generate and store uniquecode (available to course requester), if course should have one.
16911: #
16912: if ($args->{'uniquecode'}) {
16913: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16914: if ($code) {
16915: $cenv{'internal.uniquecode'} = $code;
16916: my %crsinfo =
16917: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16918: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16919: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16920: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16921: }
16922: if (ref($coderef)) {
16923: $$coderef = $code;
16924: }
16925: }
16926: }
16927:
1.444 albertel 16928: if ($args->{'disresdis'}) {
16929: $cenv{'pch.roles.denied'}='st';
16930: }
16931: if ($args->{'disablechat'}) {
16932: $cenv{'plc.roles.denied'}='st';
16933: }
16934:
16935: # Record we've not yet viewed the Course Initialization Helper for this
16936: # course
16937: $cenv{'course.helper.not.run'} = 1;
16938: #
16939: # Use new Randomseed
16940: #
16941: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16942: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16943: #
16944: # The encryption code and receipt prefix for this course
16945: #
16946: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16947: $cenv{'internal.encpref'}=100+int(9*rand(99));
16948: #
16949: # By default, use standard grading
16950: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16951:
1.541 raeburn 16952: $outcome .= $linefeed.&mt('Setting environment').': '.
16953: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16954: #
16955: # Open all assignments
16956: #
16957: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16958: my $opendate = time;
16959: if ($args->{'openallfrom'} =~ /^\d+$/) {
16960: $opendate = $args->{'openallfrom'};
16961: }
1.444 albertel 16962: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16963: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16964: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16965: $outcome .= &mt('All assignments open starting [_1]',
16966: &Apache::lonlocal::locallocaltime($opendate)).': '.
16967: &Apache::lonnet::cput
16968: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16969: }
16970: #
16971: # Set first page
16972: #
16973: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16974: || ($cloneid)) {
16975: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16976:
16977: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16978: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16979:
1.444 albertel 16980: $outcome .= ($fatal?$errtext:'read ok').' - ';
16981: my $title; my $url;
16982: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16983: $title=&mt('Syllabus');
1.444 albertel 16984: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16985: } else {
1.963 raeburn 16986: $title=&mt('Table of Contents');
1.444 albertel 16987: $url='/adm/navmaps';
16988: }
1.445 albertel 16989:
16990: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16991: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16992:
16993: if ($errtext) { $fatal=2; }
1.541 raeburn 16994: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16995: }
1.566 albertel 16996:
1.1075.2.161. .1(raebu 16997:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16998: }
16999:
1.1075.2.59 raeburn 17000: sub make_unique_code {
17001: my ($cdom,$cnum) = @_;
17002: # get lock on uniquecodes db
17003: my $lockhash = {
17004: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17005: ':'.$env{'user.domain'},
17006: };
17007: my $tries = 0;
17008: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17009: my ($code,$error);
17010:
17011: while (($gotlock ne 'ok') && ($tries<3)) {
17012: $tries ++;
17013: sleep 1;
17014: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17015: }
17016: if ($gotlock eq 'ok') {
17017: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17018: my $gotcode;
17019: my $attempts = 0;
17020: while ((!$gotcode) && ($attempts < 100)) {
17021: $code = &generate_code();
17022: if (!exists($currcodes{$code})) {
17023: $gotcode = 1;
17024: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17025: $error = 'nostore';
17026: }
17027: }
17028: $attempts ++;
17029: }
17030: my @del_lock = ($cnum."\0".'uniquecodes');
17031: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17032: } else {
17033: $error = 'nolock';
17034: }
17035: return ($code,$error);
17036: }
17037:
17038: sub generate_code {
17039: my $code;
17040: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17041: for (my $i=0; $i<6; $i++) {
17042: my $lettnum = int (rand 2);
17043: my $item = '';
17044: if ($lettnum) {
17045: $item = $letts[int( rand(18) )];
17046: } else {
17047: $item = 1+int( rand(8) );
17048: }
17049: $code .= $item;
17050: }
17051: return $code;
17052: }
17053:
1.444 albertel 17054: ############################################################
17055: ############################################################
17056:
1.953 droeschl 17057: #SD
17058: # only Community and Course, or anything else?
1.378 raeburn 17059: sub course_type {
17060: my ($cid) = @_;
17061: if (!defined($cid)) {
17062: $cid = $env{'request.course.id'};
17063: }
1.404 albertel 17064: if (defined($env{'course.'.$cid.'.type'})) {
17065: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17066: } else {
17067: return 'Course';
1.377 raeburn 17068: }
17069: }
1.156 albertel 17070:
1.406 raeburn 17071: sub group_term {
17072: my $crstype = &course_type();
17073: my %names = (
17074: 'Course' => 'group',
1.865 raeburn 17075: 'Community' => 'group',
1.406 raeburn 17076: );
17077: return $names{$crstype};
17078: }
17079:
1.902 raeburn 17080: sub course_types {
1.1075.2.161. .17(raeb 17081:-23): my @types = ('official','unofficial','community','textbook','lti');
1.902 raeburn 17082: my %typename = (
17083: official => 'Official course',
17084: unofficial => 'Unofficial course',
17085: community => 'Community',
1.1075.2.59 raeburn 17086: textbook => 'Textbook course',
1.1075.2.161. .17(raeb 17087:-23): lti => 'LTI provider',
1.902 raeburn 17088: );
17089: return (\@types,\%typename);
17090: }
17091:
1.156 albertel 17092: sub icon {
17093: my ($file)=@_;
1.505 albertel 17094: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17095: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17096: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17097: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17098: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17099: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17100: $curfext.".gif") {
17101: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17102: $curfext.".gif";
17103: }
17104: }
1.249 albertel 17105: return &lonhttpdurl($iconname);
1.154 albertel 17106: }
1.84 albertel 17107:
1.575 albertel 17108: sub lonhttpdurl {
1.692 www 17109: #
17110: # Had been used for "small fry" static images on separate port 8080.
17111: # Modify here if lightweight http functionality desired again.
17112: # Currently eliminated due to increasing firewall issues.
17113: #
1.575 albertel 17114: my ($url)=@_;
1.692 www 17115: return $url;
1.215 albertel 17116: }
17117:
1.213 albertel 17118: sub connection_aborted {
17119: my ($r)=@_;
17120: $r->print(" ");$r->rflush();
17121: my $c = $r->connection;
17122: return $c->aborted();
17123: }
17124:
1.221 foxr 17125: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17126: # strings as 'strings'.
17127: sub escape_single {
1.221 foxr 17128: my ($input) = @_;
1.223 albertel 17129: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17130: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17131: return $input;
17132: }
1.223 albertel 17133:
1.222 foxr 17134: # Same as escape_single, but escape's "'s This
17135: # can be used for "strings"
17136: sub escape_double {
17137: my ($input) = @_;
17138: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17139: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17140: return $input;
17141: }
1.223 albertel 17142:
1.222 foxr 17143: # Escapes the last element of a full URL.
17144: sub escape_url {
17145: my ($url) = @_;
1.238 raeburn 17146: my @urlslices = split(/\//, $url,-1);
1.369 www 17147: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 17148: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17149: }
1.462 albertel 17150:
1.820 raeburn 17151: sub compare_arrays {
17152: my ($arrayref1,$arrayref2) = @_;
17153: my (@difference,%count);
17154: @difference = ();
17155: %count = ();
17156: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17157: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17158: foreach my $element (keys(%count)) {
17159: if ($count{$element} == 1) {
17160: push(@difference,$element);
17161: }
17162: }
17163: }
17164: return @difference;
17165: }
17166:
1.1075.2.152 raeburn 17167: sub lon_status_items {
17168: my %defaults = (
17169: E => 100,
17170: W => 4,
17171: N => 1,
17172: U => 5,
17173: threshold => 200,
17174: sysmail => 2500,
17175: );
17176: my %names = (
17177: E => 'Errors',
17178: W => 'Warnings',
17179: N => 'Notices',
17180: U => 'Unsent',
17181: );
17182: return (\%defaults,\%names);
17183: }
17184:
1.817 bisitz 17185: # -------------------------------------------------------- Initialize user login
1.462 albertel 17186: sub init_user_environment {
1.463 albertel 17187: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17188: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17189:
17190: my $public=($username eq 'public' && $domain eq 'public');
17191:
17192: # See if old ID present, if so, remove
17193:
1.1075.2.161. .22(raeb 17194:-24): my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17195:-24): $coauthorenv);
1.462 albertel 17196: my $now=time;
17197:
17198: if ($public) {
17199: my $max_public=100;
17200: my $oldest;
17201: my $oldest_time=0;
17202: for(my $next=1;$next<=$max_public;$next++) {
17203: if (-e $lonids."/publicuser_$next.id") {
17204: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17205: if ($mtime<$oldest_time || !$oldest_time) {
17206: $oldest_time=$mtime;
17207: $oldest=$next;
17208: }
17209: } else {
17210: $cookie="publicuser_$next";
17211: last;
17212: }
17213: }
17214: if (!$cookie) { $cookie="publicuser_$oldest"; }
17215: } else {
1.463 albertel 17216: # if this isn't a robot, kill any existing non-robot sessions
17217: if (!$args->{'robot'}) {
17218: opendir(DIR,$lonids);
17219: while ($filename=readdir(DIR)) {
17220: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 17221: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17222: &GDBM_READER(),0640)) {
17223: my $linkedfile;
17224: if (exists($oldenv{'user.linkedenv'})) {
17225: $linkedfile = $oldenv{'user.linkedenv'};
17226: }
17227: untie(%oldenv);
17228: if (unlink("$lonids/$filename")) {
17229: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17230: if (-l "$lonids/$linkedfile.id") {
17231: unlink("$lonids/$linkedfile.id");
17232: }
17233: }
17234: }
17235: } else {
17236: unlink($lonids.'/'.$filename);
17237: }
1.463 albertel 17238: }
1.462 albertel 17239: }
1.463 albertel 17240: closedir(DIR);
1.1075.2.84 raeburn 17241: # If there is a undeleted lockfile for the user's paste buffer remove it.
17242: my $namespace = 'nohist_courseeditor';
17243: my $lockingkey = 'paste'."\0".'locked_num';
17244: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17245: $domain,$username);
17246: if (exists($lockhash{$lockingkey})) {
17247: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17248: unless ($delresult eq 'ok') {
17249: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17250: }
17251: }
1.462 albertel 17252: }
17253: # Give them a new cookie
1.463 albertel 17254: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17255: : $now.$$.int(rand(10000)));
1.463 albertel 17256: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17257:
17258: # Initialize roles
17259:
1.1075.2.161. .22(raeb 17260:-24): ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17261: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17262: }
17263: # ------------------------------------ Check browser type and MathML capability
17264:
1.1075.2.77 raeburn 17265: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17266: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17267:
17268: # ------------------------------------------------------------- Get environment
17269:
17270: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17271: my ($tmp) = keys(%userenv);
17272: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
17273: } else {
17274: undef(%userenv);
17275: }
17276: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17277: $form->{'interface'}=$userenv{'interface'};
17278: }
17279: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17280:
17281: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17282: foreach my $option ('interface','localpath','localres') {
17283: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17284: }
17285: # --------------------------------------------------------- Write first profile
17286:
17287: {
1.1075.2.150 raeburn 17288: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 17289: my %initial_env =
17290: ("user.name" => $username,
17291: "user.domain" => $domain,
17292: "user.home" => $authhost,
17293: "browser.type" => $clientbrowser,
17294: "browser.version" => $clientversion,
17295: "browser.mathml" => $clientmathml,
17296: "browser.unicode" => $clientunicode,
17297: "browser.os" => $clientos,
1.1075.2.42 raeburn 17298: "browser.mobile" => $clientmobile,
17299: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 17300: "browser.osversion" => $clientosversion,
1.462 albertel 17301: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17302: "request.course.fn" => '',
17303: "request.course.uri" => '',
17304: "request.course.sec" => '',
17305: "request.role" => 'cm',
17306: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 17307: "request.host" => $ip,);
1.462 albertel 17308:
17309: if ($form->{'localpath'}) {
17310: $initial_env{"browser.localpath"} = $form->{'localpath'};
17311: $initial_env{"browser.localres"} = $form->{'localres'};
17312: }
17313:
17314: if ($form->{'interface'}) {
17315: $form->{'interface'}=~s/\W//gs;
17316: $initial_env{"browser.interface"} = $form->{'interface'};
17317: $env{'browser.interface'}=$form->{'interface'};
17318: }
17319:
1.1075.2.54 raeburn 17320: if ($form->{'iptoken'}) {
17321: my $lonhost = $r->dir_config('lonHostID');
17322: $initial_env{"user.noloadbalance"} = $lonhost;
17323: $env{'user.noloadbalance'} = $lonhost;
17324: }
17325:
1.1075.2.120 raeburn 17326: if ($form->{'noloadbalance'}) {
17327: my @hosts = &Apache::lonnet::current_machine_ids();
17328: my $hosthere = $form->{'noloadbalance'};
17329: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17330: $initial_env{"user.noloadbalance"} = $hosthere;
17331: $env{'user.noloadbalance'} = $hosthere;
17332: }
17333: }
17334:
1.1016 raeburn 17335: unless ($domain eq 'public') {
1.1075.2.125 raeburn 17336: my %is_adv = ( is_adv => $env{'user.adv'} );
17337: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 17338:
1.1075.2.161. .28(raeb 17339:-24): foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
17340:-24): $userenv{'availabletools.'.$tool} =
1.1075.2.125 raeburn 17341: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17342: undef,\%userenv,\%domdef,\%is_adv);
17343: }
1.724 raeburn 17344:
1.1075.2.161. .17(raeb 17345:-23): foreach my $crstype ('official','unofficial','community','textbook','lti') {
1.1075.2.125 raeburn 17346: $userenv{'canrequest.'.$crstype} =
17347: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17348: 'reload','requestcourses',
17349: \%userenv,\%domdef,\%is_adv);
17350: }
1.765 raeburn 17351:
1.1075.2.161. .21(raeb 17352:-24): if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
17353:-24): (exists($userroles->{"user.role.au./$domain/"}))) {
17354:-24): if ($userenv{'authoreditors'}) {
17355:-24): $userenv{'editors'} = $userenv{'authoreditors'};
17356:-24): } elsif ($domdef{'editors'} ne '') {
17357:-24): $userenv{'editors'} = $domdef{'editors'};
17358:-24): } else {
17359:-24): $userenv{'editors'} = 'edit,xml';
17360:-24): }
.25(raeb 17361:-24): if ($userenv{'authorarchive'}) {
17362:-24): $userenv{'canarchive'} = 1;
17363:-24): } elsif (($userenv{'authorarchive'} eq '') &&
17364:-24): ($domdef{'archive'})) {
17365:-24): $userenv{'canarchive'} = 1;
17366:-24): }
.21(raeb 17367:-24): }
17368:-24):
1.1075.2.125 raeburn 17369: $userenv{'canrequest.author'} =
17370: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17371: 'reload','requestauthor',
17372: \%userenv,\%domdef,\%is_adv);
17373: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17374: $domain,$username);
17375: my $reqstatus = $reqauthor{'author_status'};
17376: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17377: if (ref($reqauthor{'author'}) eq 'HASH') {
17378: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17379: $reqauthor{'author'}{'timestamp'};
17380: }
1.1075.2.14 raeburn 17381: }
17382: }
17383:
1.462 albertel 17384: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17385:
1.462 albertel 17386: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17387: &GDBM_WRCREAT(),0640)) {
17388: &_add_to_env(\%disk_env,\%initial_env);
17389: &_add_to_env(\%disk_env,\%userenv,'environment.');
17390: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17391: if (ref($firstaccenv) eq 'HASH') {
17392: &_add_to_env(\%disk_env,$firstaccenv);
17393: }
17394: if (ref($timerintenv) eq 'HASH') {
17395: &_add_to_env(\%disk_env,$timerintenv);
17396: }
1.1075.2.161. .22(raeb 17397:-24): if (ref($coauthorenv) eq 'HASH') {
17398:-24): if (keys(%{$coauthorenv})) {
17399:-24): &_add_to_env(\%disk_env,$coauthorenv);
17400:-24): }
17401:-24): }
1.463 albertel 17402: if (ref($args->{'extra_env'})) {
17403: &_add_to_env(\%disk_env,$args->{'extra_env'});
17404: }
1.462 albertel 17405: untie(%disk_env);
17406: } else {
1.705 tempelho 17407: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17408: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17409: return 'error: '.$!;
17410: }
17411: }
17412: $env{'request.role'}='cm';
17413: $env{'request.role.adv'}=$env{'user.adv'};
17414: $env{'browser.type'}=$clientbrowser;
17415:
17416: return $cookie;
17417:
17418: }
17419:
17420: sub _add_to_env {
17421: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17422: if (ref($env_data) eq 'HASH') {
17423: while (my ($key,$value) = each(%$env_data)) {
17424: $idf->{$prefix.$key} = $value;
17425: $env{$prefix.$key} = $value;
17426: }
1.462 albertel 17427: }
17428: }
17429:
1.685 tempelho 17430: # --- Get the symbolic name of a problem and the url
17431: sub get_symb {
17432: my ($request,$silent) = @_;
1.726 raeburn 17433: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17434: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17435: if ($symb eq '') {
17436: if (!$silent) {
1.1071 raeburn 17437: if (ref($request)) {
17438: $request->print("Unable to handle ambiguous references:$url:.");
17439: }
1.685 tempelho 17440: return ();
17441: }
17442: }
17443: &Apache::lonenc::check_decrypt(\$symb);
17444: return ($symb);
17445: }
17446:
17447: # --------------------------------------------------------------Get annotation
17448:
17449: sub get_annotation {
17450: my ($symb,$enc) = @_;
17451:
17452: my $key = $symb;
17453: if (!$enc) {
17454: $key =
17455: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17456: }
17457: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17458: return $annotation{$key};
17459: }
17460:
17461: sub clean_symb {
1.731 raeburn 17462: my ($symb,$delete_enc) = @_;
1.685 tempelho 17463:
17464: &Apache::lonenc::check_decrypt(\$symb);
17465: my $enc = $env{'request.enc'};
1.731 raeburn 17466: if ($delete_enc) {
1.730 raeburn 17467: delete($env{'request.enc'});
17468: }
1.685 tempelho 17469:
17470: return ($symb,$enc);
17471: }
1.462 albertel 17472:
1.1075.2.69 raeburn 17473: ############################################################
17474: ############################################################
17475:
17476: =pod
17477:
17478: =head1 Routines for building display used to search for courses
17479:
17480:
17481: =over 4
17482:
17483: =item * &build_filters()
17484:
17485: Create markup for a table used to set filters to use when selecting
17486: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17487: and quotacheck.pl
17488:
17489:
17490: Inputs:
17491:
17492: filterlist - anonymous array of fields to include as potential filters
17493:
17494: crstype - course type
17495:
17496: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17497: to pop-open a course selector (will contain "extra element").
17498:
17499: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17500:
17501: filter - anonymous hash of criteria and their values
17502:
17503: action - form action
17504:
17505: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17506:
17507: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
17508:
17509: cloneruname - username of owner of new course who wants to clone
17510:
17511: clonerudom - domain of owner of new course who wants to clone
17512:
17513: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17514:
17515: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17516:
17517: codedom - domain
17518:
17519: formname - value of form element named "form".
17520:
17521: fixeddom - domain, if fixed.
17522:
17523: prevphase - value to assign to form element named "phase" when going back to the previous screen
17524:
17525: cnameelement - name of form element in form on opener page which will receive title of selected course
17526:
17527: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17528:
17529: cdomelement - name of form element in form on opener page which will receive domain of selected course
17530:
17531: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17532:
17533: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17534:
17535: clonewarning - warning message about missing information for intended course owner when DC creates a course
17536:
17537:
17538: Returns: $output - HTML for display of search criteria, and hidden form elements.
17539:
17540:
17541: Side Effects: None
17542:
17543: =cut
17544:
17545: # ---------------------------------------------- search for courses based on last activity etc.
17546:
17547: sub build_filters {
17548: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17549: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17550: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17551: $cnameelement,$cnumelement,$cdomelement,$setroles,
17552: $clonetext,$clonewarning) = @_;
17553: my ($list,$jscript);
17554: my $onchange = 'javascript:updateFilters(this)';
17555: my ($domainselectform,$sincefilterform,$createdfilterform,
17556: $ownerdomselectform,$persondomselectform,$instcodeform,
17557: $typeselectform,$instcodetitle);
17558: if ($formname eq '') {
17559: $formname = $caller;
17560: }
17561: foreach my $item (@{$filterlist}) {
17562: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17563: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17564: if ($item eq 'domainfilter') {
17565: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17566: } elsif ($item eq 'coursefilter') {
17567: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17568: } elsif ($item eq 'ownerfilter') {
17569: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17570: } elsif ($item eq 'ownerdomfilter') {
17571: $filter->{'ownerdomfilter'} =
17572: &LONCAPA::clean_domain($filter->{$item});
17573: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17574: 'ownerdomfilter',1);
17575: } elsif ($item eq 'personfilter') {
17576: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17577: } elsif ($item eq 'persondomfilter') {
17578: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17579: 'persondomfilter',1);
17580: } else {
17581: $filter->{$item} =~ s/\W//g;
17582: }
17583: if (!$filter->{$item}) {
17584: $filter->{$item} = '';
17585: }
17586: }
17587: if ($item eq 'domainfilter') {
17588: my $allow_blank = 1;
17589: if ($formname eq 'portform') {
17590: $allow_blank=0;
17591: } elsif ($formname eq 'studentform') {
17592: $allow_blank=0;
17593: }
17594: if ($fixeddom) {
17595: $domainselectform = '<input type="hidden" name="domainfilter"'.
17596: ' value="'.$codedom.'" />'.
17597: &Apache::lonnet::domain($codedom,'description');
17598: } else {
17599: $domainselectform = &select_dom_form($filter->{$item},
17600: 'domainfilter',
17601: $allow_blank,'',$onchange);
17602: }
17603: } else {
17604: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17605: }
17606: }
17607:
17608: # last course activity filter and selection
17609: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17610:
17611: # course created filter and selection
17612: if (exists($filter->{'createdfilter'})) {
17613: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17614: }
17615:
17616: my %lt = &Apache::lonlocal::texthash(
17617: 'cac' => "$crstype Activity",
17618: 'ccr' => "$crstype Created",
17619: 'cde' => "$crstype Title",
17620: 'cdo' => "$crstype Domain",
17621: 'ins' => 'Institutional Code',
17622: 'inc' => 'Institutional Categorization',
17623: 'cow' => "$crstype Owner/Co-owner",
17624: 'cop' => "$crstype Personnel Includes",
17625: 'cog' => 'Type',
17626: );
17627:
17628: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17629: my $typeval = 'Course';
17630: if ($crstype eq 'Community') {
17631: $typeval = 'Community';
17632: }
17633: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17634: } else {
17635: $typeselectform = '<select name="type" size="1"';
17636: if ($onchange) {
17637: $typeselectform .= ' onchange="'.$onchange.'"';
17638: }
17639: $typeselectform .= '>'."\n";
17640: foreach my $posstype ('Course','Community') {
17641: $typeselectform.='<option value="'.$posstype.'"'.
17642: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
17643: }
17644: $typeselectform.="</select>";
17645: }
17646:
17647: my ($cloneableonlyform,$cloneabletitle);
17648: if (exists($filter->{'cloneableonly'})) {
17649: my $cloneableon = '';
17650: my $cloneableoff = ' checked="checked"';
17651: if ($filter->{'cloneableonly'}) {
17652: $cloneableon = $cloneableoff;
17653: $cloneableoff = '';
17654: }
17655: $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>';
17656: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 17657: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 17658: } else {
17659: $cloneabletitle = &mt('Cloneable by you');
17660: }
17661: }
17662: my $officialjs;
17663: if ($crstype eq 'Course') {
17664: if (exists($filter->{'instcodefilter'})) {
17665: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17666: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17667: if ($codedom) {
17668: $officialjs = 1;
17669: ($instcodeform,$jscript,$$numtitlesref) =
17670: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17671: $officialjs,$codetitlesref);
17672: if ($jscript) {
17673: $jscript = '<script type="text/javascript">'."\n".
17674: '// <![CDATA['."\n".
17675: $jscript."\n".
17676: '// ]]>'."\n".
17677: '</script>'."\n";
17678: }
17679: }
17680: if ($instcodeform eq '') {
17681: $instcodeform =
17682: '<input type="text" name="instcodefilter" size="10" value="'.
17683: $list->{'instcodefilter'}.'" />';
17684: $instcodetitle = $lt{'ins'};
17685: } else {
17686: $instcodetitle = $lt{'inc'};
17687: }
17688: if ($fixeddom) {
17689: $instcodetitle .= '<br />('.$codedom.')';
17690: }
17691: }
17692: }
17693: my $output = qq|
17694: <form method="post" name="filterpicker" action="$action">
17695: <input type="hidden" name="form" value="$formname" />
17696: |;
17697: if ($formname eq 'modifycourse') {
17698: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17699: '<input type="hidden" name="prevphase" value="'.
17700: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 17701: } elsif ($formname eq 'quotacheck') {
17702: $output .= qq|
17703: <input type="hidden" name="sortby" value="" />
17704: <input type="hidden" name="sortorder" value="" />
17705: |;
17706: } else {
1.1075.2.69 raeburn 17707: my $name_input;
17708: if ($cnameelement ne '') {
17709: $name_input = '<input type="hidden" name="cnameelement" value="'.
17710: $cnameelement.'" />';
17711: }
17712: $output .= qq|
17713: <input type="hidden" name="cnumelement" value="$cnumelement" />
17714: <input type="hidden" name="cdomelement" value="$cdomelement" />
17715: $name_input
17716: $roleelement
17717: $multelement
17718: $typeelement
17719: |;
17720: if ($formname eq 'portform') {
17721: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17722: }
17723: }
17724: if ($fixeddom) {
17725: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17726: }
17727: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17728: if ($sincefilterform) {
17729: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17730: .$sincefilterform
17731: .&Apache::lonhtmlcommon::row_closure();
17732: }
17733: if ($createdfilterform) {
17734: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17735: .$createdfilterform
17736: .&Apache::lonhtmlcommon::row_closure();
17737: }
17738: if ($domainselectform) {
17739: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17740: .$domainselectform
17741: .&Apache::lonhtmlcommon::row_closure();
17742: }
17743: if ($typeselectform) {
17744: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17745: $output .= $typeselectform;
17746: } else {
17747: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17748: .$typeselectform
17749: .&Apache::lonhtmlcommon::row_closure();
17750: }
17751: }
17752: if ($instcodeform) {
17753: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17754: .$instcodeform
17755: .&Apache::lonhtmlcommon::row_closure();
17756: }
17757: if (exists($filter->{'ownerfilter'})) {
17758: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17759: '<table><tr><td>'.&mt('Username').'<br />'.
17760: '<input type="text" name="ownerfilter" size="20" value="'.
17761: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17762: $ownerdomselectform.'</td></tr></table>'.
17763: &Apache::lonhtmlcommon::row_closure();
17764: }
17765: if (exists($filter->{'personfilter'})) {
17766: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17767: '<table><tr><td>'.&mt('Username').'<br />'.
17768: '<input type="text" name="personfilter" size="20" value="'.
17769: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17770: $persondomselectform.'</td></tr></table>'.
17771: &Apache::lonhtmlcommon::row_closure();
17772: }
17773: if (exists($filter->{'coursefilter'})) {
17774: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17775: .'<input type="text" name="coursefilter" size="25" value="'
17776: .$list->{'coursefilter'}.'" />'
17777: .&Apache::lonhtmlcommon::row_closure();
17778: }
17779: if ($cloneableonlyform) {
17780: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17781: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17782: }
17783: if (exists($filter->{'descriptfilter'})) {
17784: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17785: .'<input type="text" name="descriptfilter" size="40" value="'
17786: .$list->{'descriptfilter'}.'" />'
17787: .&Apache::lonhtmlcommon::row_closure(1);
17788: }
17789: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17790: '<input type="hidden" name="updater" value="" />'."\n".
17791: '<input type="submit" name="gosearch" value="'.
17792: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17793: return $jscript.$clonewarning.$output;
17794: }
17795:
17796: =pod
17797:
17798: =item * &timebased_select_form()
17799:
17800: Create markup for a dropdown list used to select a time-based
17801: filter e.g., Course Activity, Course Created, when searching for courses
17802: or communities
17803:
17804: Inputs:
17805:
17806: item - name of form element (sincefilter or createdfilter)
17807:
17808: filter - anonymous hash of criteria and their values
17809:
17810: Returns: HTML for a select box contained a blank, then six time selections,
17811: with value set in incoming form variables currently selected.
17812:
17813: Side Effects: None
17814:
17815: =cut
17816:
17817: sub timebased_select_form {
17818: my ($item,$filter) = @_;
17819: if (ref($filter) eq 'HASH') {
17820: $filter->{$item} =~ s/[^\d-]//g;
17821: if (!$filter->{$item}) { $filter->{$item}=-1; }
17822: return &select_form(
17823: $filter->{$item},
17824: $item,
17825: { '-1' => '',
17826: '86400' => &mt('today'),
17827: '604800' => &mt('last week'),
17828: '2592000' => &mt('last month'),
17829: '7776000' => &mt('last three months'),
17830: '15552000' => &mt('last six months'),
17831: '31104000' => &mt('last year'),
17832: 'select_form_order' =>
17833: ['-1','86400','604800','2592000','7776000',
17834: '15552000','31104000']});
17835: }
17836: }
17837:
17838: =pod
17839:
17840: =item * &js_changer()
17841:
17842: Create script tag containing Javascript used to submit course search form
17843: when course type or domain is changed, and also to hide 'Searching ...' on
17844: page load completion for page showing search result.
17845:
17846: Inputs: None
17847:
17848: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17849:
17850: Side Effects: None
17851:
17852: =cut
17853:
17854: sub js_changer {
17855: return <<ENDJS;
17856: <script type="text/javascript">
17857: // <![CDATA[
17858: function updateFilters(caller) {
17859: if (typeof(caller) != "undefined") {
17860: document.filterpicker.updater.value = caller.name;
17861: }
17862: document.filterpicker.submit();
17863: }
17864:
17865: function hideSearching() {
17866: if (document.getElementById('searching')) {
17867: document.getElementById('searching').style.display = 'none';
17868: }
17869: return;
17870: }
17871:
17872: // ]]>
17873: </script>
17874:
17875: ENDJS
17876: }
17877:
17878: =pod
17879:
17880: =item * &search_courses()
17881:
17882: Process selected filters form course search form and pass to lonnet::courseiddump
17883: to retrieve a hash for which keys are courseIDs which match the selected filters.
17884:
17885: Inputs:
17886:
17887: dom - domain being searched
17888:
17889: type - course type ('Course' or 'Community' or '.' if any).
17890:
17891: filter - anonymous hash of criteria and their values
17892:
17893: numtitles - for institutional codes - number of categories
17894:
17895: cloneruname - optional username of new course owner
17896:
17897: clonerudom - optional domain of new course owner
17898:
1.1075.2.95 raeburn 17899: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17900: (used when DC is using course creation form)
17901:
17902: codetitles - reference to array of titles of components in institutional codes (official courses).
17903:
1.1075.2.95 raeburn 17904: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17905: (and so can clone automatically)
17906:
17907: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17908:
17909: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17910: courses to clone
1.1075.2.69 raeburn 17911:
17912: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17913:
17914:
17915: Side Effects: None
17916:
17917: =cut
17918:
17919:
17920: sub search_courses {
1.1075.2.95 raeburn 17921: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17922: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17923: my (%courses,%showcourses,$cloner);
17924: if (($filter->{'ownerfilter'} ne '') ||
17925: ($filter->{'ownerdomfilter'} ne '')) {
17926: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17927: $filter->{'ownerdomfilter'};
17928: }
17929: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17930: if (!$filter->{$item}) {
17931: $filter->{$item}='.';
17932: }
17933: }
17934: my $now = time;
17935: my $timefilter =
17936: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17937: my ($createdbefore,$createdafter);
17938: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17939: $createdbefore = $now;
17940: $createdafter = $now-$filter->{'createdfilter'};
17941: }
17942: my ($instcodefilter,$regexpok);
17943: if ($numtitles) {
17944: if ($env{'form.official'} eq 'on') {
17945: $instcodefilter =
17946: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17947: $regexpok = 1;
17948: } elsif ($env{'form.official'} eq 'off') {
17949: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17950: unless ($instcodefilter eq '') {
17951: $regexpok = -1;
17952: }
17953: }
17954: } else {
17955: $instcodefilter = $filter->{'instcodefilter'};
17956: }
17957: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17958: if ($type eq '') { $type = '.'; }
17959:
17960: if (($clonerudom ne '') && ($cloneruname ne '')) {
17961: $cloner = $cloneruname.':'.$clonerudom;
17962: }
17963: %courses = &Apache::lonnet::courseiddump($dom,
17964: $filter->{'descriptfilter'},
17965: $timefilter,
17966: $instcodefilter,
17967: $filter->{'combownerfilter'},
17968: $filter->{'coursefilter'},
17969: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17970: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17971: $filter->{'cloneableonly'},
17972: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17973: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17974: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17975: my $ccrole;
17976: if ($type eq 'Community') {
17977: $ccrole = 'co';
17978: } else {
17979: $ccrole = 'cc';
17980: }
17981: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17982: $filter->{'persondomfilter'},
17983: 'userroles',undef,
17984: [$ccrole,'in','ad','ep','ta','cr'],
17985: $dom);
17986: foreach my $role (keys(%rolehash)) {
17987: my ($cnum,$cdom,$courserole) = split(':',$role);
17988: my $cid = $cdom.'_'.$cnum;
17989: if (exists($courses{$cid})) {
17990: if (ref($courses{$cid}) eq 'HASH') {
17991: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17992: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17993: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17994: }
17995: } else {
17996: $courses{$cid}{roles} = [$courserole];
17997: }
17998: $showcourses{$cid} = $courses{$cid};
17999: }
18000: }
18001: }
18002: %courses = %showcourses;
18003: }
18004: return %courses;
18005: }
18006:
18007: =pod
18008:
18009: =back
18010:
1.1075.2.88 raeburn 18011: =head1 Routines for version requirements for current course.
18012:
18013: =over 4
18014:
18015: =item * &check_release_required()
18016:
18017: Compares required LON-CAPA version with version on server, and
18018: if required version is newer looks for a server with the required version.
18019:
18020: Looks first at servers in user's owen domain; if none suitable, looks at
18021: servers in course's domain are permitted to host sessions for user's domain.
18022:
18023: Inputs:
18024:
18025: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18026:
18027: $courseid - Course ID of current course
18028:
18029: $rolecode - User's current role in course (for switchserver query string).
18030:
18031: $required - LON-CAPA version needed by course (format: Major.Minor).
18032:
18033:
18034: Returns:
18035:
18036: $switchserver - query string tp append to /adm/switchserver call (if
18037: current server's LON-CAPA version is too old.
18038:
18039: $warning - Message is displayed if no suitable server could be found.
18040:
18041: =cut
18042:
18043: sub check_release_required {
18044: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18045: my ($switchserver,$warning);
18046: if ($required ne '') {
18047: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18048: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18049: if ($reqdmajor ne '' && $reqdminor ne '') {
18050: my $otherserver;
18051: if (($major eq '' && $minor eq '') ||
18052: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18053: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18054: my $switchlcrev =
18055: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18056: $userdomserver);
18057: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18058: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18059: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18060: my $cdom = $env{'course.'.$courseid.'.domain'};
18061: if ($cdom ne $env{'user.domain'}) {
18062: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18063: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18064: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18065: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18066: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18067: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18068: my $canhost =
18069: &Apache::lonnet::can_host_session($env{'user.domain'},
18070: $coursedomserver,
18071: $remoterev,
18072: $udomdefaults{'remotesessions'},
18073: $defdomdefaults{'hostedsessions'});
18074:
18075: if ($canhost) {
18076: $otherserver = $coursedomserver;
18077: } else {
18078: $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.");
18079: }
18080: } else {
18081: $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).");
18082: }
18083: } else {
18084: $otherserver = $userdomserver;
18085: }
18086: }
18087: if ($otherserver ne '') {
18088: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18089: }
18090: }
18091: }
18092: return ($switchserver,$warning);
18093: }
18094:
18095: =pod
18096:
18097: =item * &check_release_result()
18098:
18099: Inputs:
18100:
18101: $switchwarning - Warning message if no suitable server found to host session.
18102:
18103: $switchserver - query string to append to /adm/switchserver containing lonHostID
18104: and current role.
18105:
18106: Returns: HTML to display with information about requirement to switch server.
18107: Either displaying warning with link to Roles/Courses screen or
18108: display link to switchserver.
18109:
1.1075.2.69 raeburn 18110: =cut
18111:
1.1075.2.88 raeburn 18112: sub check_release_result {
18113: my ($switchwarning,$switchserver) = @_;
18114: my $output = &start_page('Selected course unavailable on this server').
18115: '<p class="LC_warning">';
18116: if ($switchwarning) {
18117: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18118: if (&show_course()) {
18119: $output .= &mt('Display courses');
18120: } else {
18121: $output .= &mt('Display roles');
18122: }
18123: $output .= '</a>';
18124: } elsif ($switchserver) {
18125: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18126: '<br />'.
18127: '<a href="/adm/switchserver?'.$switchserver.'">'.
18128: &mt('Switch Server').
18129: '</a>';
18130: }
18131: $output .= '</p>'.&end_page();
18132: return $output;
18133: }
18134:
18135: =pod
18136:
18137: =item * &needs_coursereinit()
18138:
18139: Determine if course contents stored for user's session needs to be
18140: refreshed, because content has changed since "Big Hash" last tied.
18141:
18142: Check for change is made if time last checked is more than 10 minutes ago
18143: (by default).
18144:
18145: Inputs:
18146:
18147: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18148:
18149: $interval (optional) - Time which may elapse (in s) between last check for content
18150: change in current course. (default: 600 s).
18151:
18152: Returns: an array; first element is:
18153:
18154: =over 4
18155:
18156: 'switch' - if content updates mean user's session
18157: needs to be switched to a server running a newer LON-CAPA version
18158:
18159: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18160: on current server hosting user's session
18161:
18162: '' - if no action required.
18163:
18164: =back
18165:
18166: If first item element is 'switch':
18167:
18168: second item is $switchwarning - Warning message if no suitable server found to host session.
18169:
18170: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18171: and current role.
18172:
18173: otherwise: no other elements returned.
18174:
18175: =back
18176:
18177: =cut
18178:
18179: sub needs_coursereinit {
18180: my ($loncaparev,$interval) = @_;
18181: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18182: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18183: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18184: my $now = time;
18185: if ($interval eq '') {
18186: $interval = 600;
18187: }
18188: if (($now-$env{'request.course.timechecked'})>$interval) {
18189: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 18190:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 18191:21): if ($blocked) {
18192:21): return ();
18193:21): }
.13(raeb 18194:-23): my $update;
18195:-23): my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18196:-23): my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18197:-23): if ($lastmainchange > $env{'request.course.tied'}) {
18198:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18199:-23): if ($needswitch) {
18200:-23): return ('switch',$switchwarning,$switchserver);
18201:-23): }
18202:-23): $update = 'main';
18203:-23): }
18204:-23): if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18205:-23): if ($update) {
18206:-23): $update = 'both';
18207:-23): } else {
18208:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18209:-23): if ($needswitch) {
18210:-23): return ('switch',$switchwarning,$switchserver);
18211:-23): } else {
18212:-23): $update = 'supp';
1.1075.2.88 raeburn 18213: }
18214: }
1.1075.2.161. .13(raeb 18215:-23): return ($update);
18216:-23): }
18217:-23): }
18218:-23): return ();
18219:-23): }
18220:-23):
18221:-23): sub switch_for_update {
18222:-23): my ($loncaparev,$cdom,$cnum) = @_;
18223:-23): my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18224:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18225:-23): my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18226:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18227:-23): &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18228:-23): $curr_reqd_hash{'internal.releaserequired'}});
18229:-23): my ($switchserver,$switchwarning) =
18230:-23): &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18231:-23): $curr_reqd_hash{'internal.releaserequired'});
18232:-23): if ($switchwarning ne '' || $switchserver ne '') {
18233:-23): return ('switch',$switchwarning,$switchserver);
18234:-23): }
1.1075.2.88 raeburn 18235: }
18236: }
18237: return ();
18238: }
1.1075.2.69 raeburn 18239:
1.1075.2.11 raeburn 18240: sub update_content_constraints {
18241: my ($cdom,$cnum,$chome,$cid) = @_;
18242: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18243: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
18244: my %checkresponsetypes;
18245: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
18246: my ($item,$name,$value) = split(/:/,$key);
18247: if ($item eq 'resourcetag') {
18248: if ($name eq 'responsetype') {
18249: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18250: }
18251: }
18252: }
18253: my $navmap = Apache::lonnavmaps::navmap->new();
18254: if (defined($navmap)) {
18255: my %allresponses;
18256: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
18257: my %responses = $res->responseTypes();
18258: foreach my $key (keys(%responses)) {
18259: next unless(exists($checkresponsetypes{$key}));
18260: $allresponses{$key} += $responses{$key};
18261: }
18262: }
18263: foreach my $key (keys(%allresponses)) {
18264: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18265: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18266: ($reqdmajor,$reqdminor) = ($major,$minor);
18267: }
18268: }
18269: undef($navmap);
18270: }
18271: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18272: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18273: }
18274: return;
18275: }
18276:
1.1075.2.27 raeburn 18277: sub allmaps_incourse {
18278: my ($cdom,$cnum,$chome,$cid) = @_;
18279: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18280: $cid = $env{'request.course.id'};
18281: $cdom = $env{'course.'.$cid.'.domain'};
18282: $cnum = $env{'course.'.$cid.'.num'};
18283: $chome = $env{'course.'.$cid.'.home'};
18284: }
18285: my %allmaps = ();
18286: my $lastchange =
18287: &Apache::lonnet::get_coursechange($cdom,$cnum);
18288: if ($lastchange > $env{'request.course.tied'}) {
18289: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18290: unless ($ferr) {
18291: &update_content_constraints($cdom,$cnum,$chome,$cid);
18292: }
18293: }
18294: my $navmap = Apache::lonnavmaps::navmap->new();
18295: if (defined($navmap)) {
18296: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18297: $allmaps{$res->src()} = 1;
18298: }
18299: }
18300: return \%allmaps;
18301: }
18302:
1.1075.2.11 raeburn 18303: sub parse_supplemental_title {
18304: my ($title) = @_;
18305:
18306: my ($foldertitle,$renametitle);
18307: if ($title =~ /&&&/) {
18308: $title = &HTML::Entites::decode($title);
18309: }
18310: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18311: $renametitle=$4;
18312: my ($time,$uname,$udom) = ($1,$2,$3);
18313: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18314: my $name = &plainname($uname,$udom);
18315: $name = &HTML::Entities::encode($name,'"<>&\'');
18316: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1075.2.161. .16(raeb 18317:-23): $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
18318:-23): if ($foldertitle ne '') {
18319:-23): $title .= ': <br />'.$foldertitle;
18320:-23): }
1.1075.2.11 raeburn 18321: }
18322: if (wantarray) {
18323: return ($title,$foldertitle,$renametitle);
18324: }
18325: return $title;
18326: }
18327:
1.1075.2.161. .13(raeb 18328:-23): sub get_supplemental {
18329:-23): my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18330:-23): my $hashid=$cnum.':'.$cdom;
18331:-23): my ($supplemental,$cached,$set_httprefs);
18332:-23): unless ($ignorecache) {
18333:-23): ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18334:-23): }
18335:-23): unless (defined($cached)) {
18336:-23): my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18337:-23): unless ($chome eq 'no_host') {
18338:-23): my @order = @LONCAPA::map::order;
18339:-23): my @resources = @LONCAPA::map::resources;
18340:-23): my @resparms = @LONCAPA::map::resparms;
18341:-23): my @zombies = @LONCAPA::map::zombies;
18342:-23): my ($errors,%ids,%hidden);
18343:-23): $errors =
18344:-23): &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18345:-23): $errors,$possdel,\%ids,\%hidden);
18346:-23): @LONCAPA::map::order = @order;
18347:-23): @LONCAPA::map::resources = @resources;
18348:-23): @LONCAPA::map::resparms = @resparms;
18349:-23): @LONCAPA::map::zombies = @zombies;
18350:-23): $set_httprefs = 1;
18351:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18352:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18353:-23): }
18354:-23): $supplemental = {
18355:-23): ids => \%ids,
18356:-23): hidden => \%hidden,
18357:-23): };
18358:-23): &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18359:-23): }
18360:-23): }
18361:-23): return ($supplemental,$set_httprefs);
18362:-23): }
18363:-23):
1.1075.2.43 raeburn 18364: sub recurse_supplemental {
1.1075.2.161. .13(raeb 18365:-23): my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18366:-23): if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18367:-23): my $mapnum;
18368:-23): if ($suppmap eq 'supplemental.sequence') {
18369:-23): $mapnum = 0;
18370:-23): } else {
18371:-23): ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18372:-23): }
1.1075.2.43 raeburn 18373: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18374: if ($fatal) {
18375: $errors ++;
18376: } else {
1.1075.2.161. .13(raeb 18377:-23): my @order = @LONCAPA::map::order;
18378:-23): if (@order > 0) {
18379:-23): my @resources = @LONCAPA::map::resources;
18380:-23): my @resparms = @LONCAPA::map::resparms;
18381:-23): foreach my $idx (@order) {
18382:-23): my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 18383: if (($src ne '') && ($status eq 'res')) {
1.1075.2.161. .13(raeb 18384:-23): my $id = $mapnum.':'.$idx;
18385:-23): push(@{$suppids->{$src}},$id);
18386:-23): if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18387:-23): $hiddensupp->{$id} = 1;
18388:-23): }
1.1075.2.46 raeburn 18389: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1075.2.161. .13(raeb 18390:-23): $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18391:-23): $hiddensupp,$hiddensupp->{$id});
1.1075.2.43 raeburn 18392: } else {
1.1075.2.161. .13(raeb 18393:-23): my $allowed;
18394:-23): if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18395:-23): $allowed = 1;
18396:-23): } elsif ($possdel) {
18397:-23): foreach my $item (@{$suppids->{$src}}) {
18398:-23): next if ($item eq $id);
18399:-23): unless ($hiddensupp->{$item}) {
18400:-23): $allowed = 1;
18401:-23): last;
18402:-23): }
18403:-23): }
18404:-23): if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18405:-23): &Apache::lonnet::delenv('httpref.'.$src);
18406:-23): }
18407:-23): }
18408:-23): if ($allowed && (!exists($env{'httpref.'.$src}))) {
18409:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18410:-23): }
18411:-23): }
18412:-23): }
18413:-23): }
18414:-23): }
18415:-23): }
18416:-23): }
18417:-23): return $errors;
18418:-23): }
18419:-23):
18420:-23): sub set_supp_httprefs {
18421:-23): my ($cnum,$cdom,$supplemental,$possdel) = @_;
18422:-23): if (ref($supplemental) eq 'HASH') {
18423:-23): if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18424:-23): foreach my $src (keys(%{$supplemental->{'ids'}})) {
18425:-23): next if ($src =~ /\.sequence$/);
18426:-23): if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18427:-23): my $allowed;
18428:-23): if ($env{'request.role.adv'}) {
18429:-23): $allowed = 1;
18430:-23): } else {
18431:-23): foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18432:-23): unless ($supplemental->{'hidden'}->{$id}) {
18433:-23): $allowed = 1;
18434:-23): last;
18435:-23): }
18436:-23): }
18437:-23): }
18438:-23): if (exists($env{'httpref.'.$src})) {
18439:-23): if ($possdel) {
18440:-23): unless ($allowed) {
18441:-23): &Apache::lonnet::delenv('httpref.'.$src);
18442:-23): }
1.1075.2.43 raeburn 18443: }
1.1075.2.161. .13(raeb 18444:-23): } elsif ($allowed) {
18445:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1075.2.43 raeburn 18446: }
18447: }
18448: }
1.1075.2.161. .13(raeb 18449:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18450:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18451:-23): }
1.1075.2.43 raeburn 18452: }
18453: }
1.1075.2.161. .13(raeb 18454:-23): }
18455:-23):
18456:-23): sub get_supp_parameter {
18457:-23): my ($resparm,$name)=@_;
18458:-23): return if ($resparm eq '');
18459:-23): my $value=undef;
18460:-23): my $ptype=undef;
18461:-23): foreach (split('&&&',$resparm)) {
18462:-23): my ($thistype,$thisname,$thisvalue)=split('___',$_);
18463:-23): if ($thisname eq $name) {
18464:-23): $value=$thisvalue;
18465:-23): $ptype=$thistype;
18466:-23): }
18467:-23): }
18468:-23): return $value;
1.1075.2.43 raeburn 18469: }
18470:
1.1075.2.18 raeburn 18471: sub symb_to_docspath {
1.1075.2.119 raeburn 18472: my ($symb,$navmapref) = @_;
18473: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 18474: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18475: if ($resurl=~/\.(sequence|page)$/) {
18476: $mapurl=$resurl;
18477: } elsif ($resurl eq 'adm/navmaps') {
18478: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18479: }
18480: my $mapresobj;
1.1075.2.119 raeburn 18481: unless (ref($$navmapref)) {
18482: $$navmapref = Apache::lonnavmaps::navmap->new();
18483: }
18484: if (ref($$navmapref)) {
18485: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 18486: }
18487: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18488: my $type=$2;
18489: my $path;
18490: if (ref($mapresobj)) {
18491: my $pcslist = $mapresobj->map_hierarchy();
18492: if ($pcslist ne '') {
18493: foreach my $pc (split(/,/,$pcslist)) {
18494: next if ($pc <= 1);
1.1075.2.119 raeburn 18495: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 18496: if (ref($res)) {
18497: my $thisurl = $res->src();
18498: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18499: my $thistitle = $res->title();
18500: $path .= '&'.
18501: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 18502: &escape($thistitle).
1.1075.2.18 raeburn 18503: ':'.$res->randompick().
18504: ':'.$res->randomout().
18505: ':'.$res->encrypted().
18506: ':'.$res->randomorder().
18507: ':'.$res->is_page();
18508: }
18509: }
18510: }
18511: $path =~ s/^\&//;
18512: my $maptitle = $mapresobj->title();
18513: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18514: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18515: }
18516: $path .= (($path ne '')? '&' : '').
18517: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18518: &escape($maptitle).
1.1075.2.18 raeburn 18519: ':'.$mapresobj->randompick().
18520: ':'.$mapresobj->randomout().
18521: ':'.$mapresobj->encrypted().
18522: ':'.$mapresobj->randomorder().
18523: ':'.$mapresobj->is_page();
18524: } else {
18525: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18526: my $ispage = (($type eq 'page')? 1 : '');
18527: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18528: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18529: }
18530: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18531: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 18532: }
18533: unless ($mapurl eq 'default') {
18534: $path = 'default&'.
1.1075.2.46 raeburn 18535: &escape('Main Content').
1.1075.2.18 raeburn 18536: ':::::&'.$path;
18537: }
18538: return $path;
18539: }
18540:
1.1075.2.161. .13(raeb 18541:-23): sub validate_folderpath {
18542:-23): my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18543:-23): if ($env{'form.folderpath'} ne '') {
18544:-23): my @items = split(/\&/,$env{'form.folderpath'});
18545:-23): my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
18546:-23): for (my $i=0; $i<@items; $i++) {
18547:-23): my $odd = $i%2;
18548:-23): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18549:-23): $badpath = 1;
18550:-23): } elsif ($odd && $supplementalflag) {
18551:-23): my $idx = $i-1;
18552:-23): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18553:-23): my $esc_name = $1;
18554:-23): if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18555:-23): $supppath .= '&'.$esc_name;
18556:-23): $changed = 1;
18557:-23): } else {
18558:-23): $supppath .= '&'.$items[$i];
18559:-23): }
18560:-23): } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18561:-23): $changed = 1;
18562:-23): my $is_hidden;
18563:-23): unless ($got_supp) {
18564:-23): my ($supplemental) = &get_supplemental($coursenum,$coursedom);
18565:-23): if (ref($supplemental) eq 'HASH') {
18566:-23): if (ref($supplemental->{'hidden'}) eq 'HASH') {
18567:-23): %supphidden = %{$supplemental->{'hidden'}};
18568:-23): }
18569:-23): if (ref($supplemental->{'ids'}) eq 'HASH') {
18570:-23): %suppids = %{$supplemental->{'ids'}};
18571:-23): }
18572:-23): }
18573:-23): $got_supp = 1;
18574:-23): }
18575:-23): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18576:-23): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18577:-23): if ($supphidden{$mapid}) {
18578:-23): $is_hidden = 1;
18579:-23): }
18580:-23): }
18581:-23): $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18582:-23): } else {
18583:-23): $supppath .= '&'.$items[$i];
18584:-23): }
18585:-23): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18586:-23): $badpath = 1;
18587:-23): } elsif ($supplementalflag) {
18588:-23): $supppath .= '&'.$items[$i];
18589:-23): }
18590:-23): last if ($badpath);
18591:-23): }
18592:-23): if ($badpath) {
18593:-23): delete($env{'form.folderpath'});
18594:-23): } elsif ($changed && $supplementalflag) {
18595:-23): $supppath =~ s/^\&//;
18596:-23): $env{'form.folderpath'} = $supppath;
18597:-23): }
18598:-23): }
18599:-23): return;
18600:-23): }
18601:-23):
1.1075.2.14 raeburn 18602: sub captcha_display {
1.1075.2.137 raeburn 18603: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18604: my ($output,$error);
1.1075.2.107 raeburn 18605: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 18606: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18607: if ($captcha eq 'original') {
18608: $output = &create_captcha();
18609: unless ($output) {
18610: $error = 'captcha';
18611: }
18612: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18613: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 18614: unless ($output) {
18615: $error = 'recaptcha';
18616: }
18617: }
1.1075.2.107 raeburn 18618: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 18619: }
18620:
18621: sub captcha_response {
1.1075.2.137 raeburn 18622: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18623: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 18624: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18625: if ($captcha eq 'original') {
18626: ($captcha_chk,$captcha_error) = &check_captcha();
18627: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18628: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 18629: } else {
18630: $captcha_chk = 1;
18631: }
18632: return ($captcha_chk,$captcha_error);
18633: }
18634:
18635: sub get_captcha_config {
1.1075.2.137 raeburn 18636: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 18637: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 18638: my $hostname = &Apache::lonnet::hostname($lonhost);
18639: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18640: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18641: if ($context eq 'usercreation') {
18642: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18643: if (ref($domconfig{$context}) eq 'HASH') {
18644: $hashtocheck = $domconfig{$context}{'cancreate'};
18645: if (ref($hashtocheck) eq 'HASH') {
18646: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18647: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18648: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18649: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18650: }
18651: if ($privkey && $pubkey) {
18652: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18653: $version = $hashtocheck->{'recaptchaversion'};
18654: if ($version ne '2') {
18655: $version = 1;
18656: }
1.1075.2.14 raeburn 18657: } else {
18658: $captcha = 'original';
18659: }
18660: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18661: $captcha = 'original';
18662: }
18663: }
18664: } else {
18665: $captcha = 'captcha';
18666: }
18667: } elsif ($context eq 'login') {
18668: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18669: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18670: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18671: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
18672: if ($privkey && $pubkey) {
18673: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18674: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18675: if ($version ne '2') {
18676: $version = 1;
18677: }
1.1075.2.14 raeburn 18678: } else {
18679: $captcha = 'original';
18680: }
18681: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18682: $captcha = 'original';
18683: }
1.1075.2.137 raeburn 18684: } elsif ($context eq 'passwords') {
18685: if ($dom_in_effect) {
18686: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18687: if ($passwdconf{'captcha'} eq 'recaptcha') {
18688: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18689: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18690: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18691: }
18692: if ($privkey && $pubkey) {
18693: $captcha = 'recaptcha';
18694: $version = $passwdconf{'recaptchaversion'};
18695: if ($version ne '2') {
18696: $version = 1;
18697: }
18698: } else {
18699: $captcha = 'original';
18700: }
18701: } elsif ($passwdconf{'captcha'} ne 'notused') {
18702: $captcha = 'original';
18703: }
18704: }
1.1075.2.14 raeburn 18705: }
1.1075.2.107 raeburn 18706: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 18707: }
18708:
18709: sub create_captcha {
18710: my %captcha_params = &captcha_settings();
18711: my ($output,$maxtries,$tries) = ('',10,0);
18712: while ($tries < $maxtries) {
18713: $tries ++;
18714: my $captcha = Authen::Captcha->new (
18715: output_folder => $captcha_params{'output_dir'},
18716: data_folder => $captcha_params{'db_dir'},
18717: );
18718: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18719:
18720: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18721: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 18722: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 18723: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.161. .15(raeb 18724:-23): '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 18725: '</span><br />'.
1.1075.2.66 raeburn 18726: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 18727: last;
18728: }
18729: }
1.1075.2.158 raeburn 18730: if ($output eq '') {
18731: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18732: }
1.1075.2.14 raeburn 18733: return $output;
18734: }
18735:
18736: sub captcha_settings {
18737: my %captcha_params = (
18738: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18739: www_output_dir => "/captchaspool",
18740: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18741: numchars => '5',
18742: );
18743: return %captcha_params;
18744: }
18745:
18746: sub check_captcha {
18747: my ($captcha_chk,$captcha_error);
18748: my $code = $env{'form.code'};
18749: my $md5sum = $env{'form.crypt'};
18750: my %captcha_params = &captcha_settings();
18751: my $captcha = Authen::Captcha->new(
18752: output_folder => $captcha_params{'output_dir'},
18753: data_folder => $captcha_params{'db_dir'},
18754: );
1.1075.2.26 raeburn 18755: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 18756: my %captcha_hash = (
18757: 0 => 'Code not checked (file error)',
18758: -1 => 'Failed: code expired',
18759: -2 => 'Failed: invalid code (not in database)',
18760: -3 => 'Failed: invalid code (code does not match crypt)',
18761: );
18762: if ($captcha_chk != 1) {
18763: $captcha_error = $captcha_hash{$captcha_chk}
18764: }
18765: return ($captcha_chk,$captcha_error);
18766: }
18767:
18768: sub create_recaptcha {
1.1075.2.107 raeburn 18769: my ($pubkey,$version) = @_;
18770: if ($version >= 2) {
1.1075.2.158 raeburn 18771: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18772: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 18773: } else {
18774: my $use_ssl;
18775: if ($ENV{'SERVER_PORT'} == 443) {
18776: $use_ssl = 1;
18777: }
18778: my $captcha = Captcha::reCAPTCHA->new;
18779: return $captcha->get_options_setter({theme => 'white'})."\n".
18780: $captcha->get_html($pubkey,undef,$use_ssl).
18781: &mt('If the text is hard to read, [_1] will replace them.',
18782: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18783: '<br /><br />';
18784: }
1.1075.2.14 raeburn 18785: }
18786:
18787: sub check_recaptcha {
1.1075.2.107 raeburn 18788: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 18789: my $captcha_chk;
1.1075.2.150 raeburn 18790: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 18791: if ($version >= 2) {
18792: my $ua = LWP::UserAgent->new;
18793: $ua->timeout(10);
18794: my %info = (
18795: secret => $privkey,
18796: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 18797: remoteip => $ip,
1.1075.2.107 raeburn 18798: );
18799: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
18800: if ($response->is_success) {
18801: my $data = JSON::DWIW->from_json($response->decoded_content);
18802: if (ref($data) eq 'HASH') {
18803: if ($data->{'success'}) {
18804: $captcha_chk = 1;
18805: }
18806: }
18807: }
18808: } else {
18809: my $captcha = Captcha::reCAPTCHA->new;
18810: my $captcha_result =
18811: $captcha->check_answer(
18812: $privkey,
1.1075.2.150 raeburn 18813: $ip,
1.1075.2.107 raeburn 18814: $env{'form.recaptcha_challenge_field'},
18815: $env{'form.recaptcha_response_field'},
18816: );
18817: if ($captcha_result->{is_valid}) {
18818: $captcha_chk = 1;
18819: }
1.1075.2.14 raeburn 18820: }
18821: return $captcha_chk;
18822: }
18823:
1.1075.2.64 raeburn 18824: sub emailusername_info {
1.1075.2.103 raeburn 18825: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 18826: my %titles = &Apache::lonlocal::texthash (
18827: lastname => 'Last Name',
18828: firstname => 'First Name',
18829: institution => 'School/college/university',
18830: location => "School's city, state/province, country",
18831: web => "School's web address",
18832: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 18833: id => 'Student/Employee ID',
1.1075.2.64 raeburn 18834: );
18835: return (\@fields,\%titles);
18836: }
18837:
1.1075.2.56 raeburn 18838: sub cleanup_html {
18839: my ($incoming) = @_;
18840: my $outgoing;
18841: if ($incoming ne '') {
18842: $outgoing = $incoming;
18843: $outgoing =~ s/;/;/g;
18844: $outgoing =~ s/\#/#/g;
18845: $outgoing =~ s/\&/&/g;
18846: $outgoing =~ s/</</g;
18847: $outgoing =~ s/>/>/g;
18848: $outgoing =~ s/\(/(/g;
18849: $outgoing =~ s/\)/)/g;
18850: $outgoing =~ s/"/"/g;
18851: $outgoing =~ s/'/'/g;
18852: $outgoing =~ s/\$/$/g;
18853: $outgoing =~ s{/}{/}g;
18854: $outgoing =~ s/=/=/g;
18855: $outgoing =~ s/\\/\/g
18856: }
18857: return $outgoing;
18858: }
18859:
1.1075.2.74 raeburn 18860: # Checks for critical messages and returns a redirect url if one exists.
18861: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 18862:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 18863: sub critical_redirect {
1.1075.2.161. .1(raebu 18864:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 18865: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18866: return ();
18867: }
1.1075.2.74 raeburn 18868: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 18869:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18870:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18871:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 18872:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 18873:21): if ($blocked) {
18874:21): my $checkrole = "cm./$cdom/$cnum";
18875:21): if ($env{'request.course.sec'} ne '') {
18876:21): $checkrole .= "/$env{'request.course.sec'}";
18877:21): }
18878:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18879:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18880:21): return;
18881:21): }
18882:21): }
18883:21): }
1.1075.2.74 raeburn 18884: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18885: $env{'user.name'});
18886: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
18887: my $redirecturl;
18888: if ($what[0]) {
1.1075.2.158 raeburn 18889: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 18890: $redirecturl='/adm/email?critical=display';
18891: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18892: return (1, $url);
18893: }
18894: }
18895: }
18896: return ();
18897: }
18898:
1.1075.2.64 raeburn 18899: # Use:
18900: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18901: #
18902: ##################################################
18903: # password associated functions #
18904: ##################################################
18905: sub des_keys {
18906: # Make a new key for DES encryption.
18907: # Each key has two parts which are returned separately.
18908: # Please note: Each key must be passed through the &hex function
18909: # before it is output to the web browser. The hex versions cannot
18910: # be used to decrypt.
18911: my @hexstr=('0','1','2','3','4','5','6','7',
18912: '8','9','a','b','c','d','e','f');
18913: my $lkey='';
18914: for (0..7) {
18915: $lkey.=$hexstr[rand(15)];
18916: }
18917: my $ukey='';
18918: for (0..7) {
18919: $ukey.=$hexstr[rand(15)];
18920: }
18921: return ($lkey,$ukey);
18922: }
18923:
18924: sub des_decrypt {
18925: my ($key,$cyphertext) = @_;
18926: my $keybin=pack("H16",$key);
18927: my $cypher;
18928: if ($Crypt::DES::VERSION>=2.03) {
18929: $cypher=new Crypt::DES $keybin;
18930: } else {
18931: $cypher=new DES $keybin;
18932: }
1.1075.2.106 raeburn 18933: my $plaintext='';
18934: my $cypherlength = length($cyphertext);
18935: my $numchunks = int($cypherlength/32);
18936: for (my $j=0; $j<$numchunks; $j++) {
18937: my $start = $j*32;
18938: my $cypherblock = substr($cyphertext,$start,32);
18939: my $chunk =
18940: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18941: $chunk .=
18942: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18943: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18944: $plaintext .= $chunk;
18945: }
1.1075.2.64 raeburn 18946: return $plaintext;
18947: }
18948:
1.1075.2.161. .1(raebu 18949:21): sub get_requested_shorturls {
18950:21): my ($cdom,$cnum,$navmap) = @_;
18951:21): return unless (ref($navmap));
18952:21): my ($numnew,$errors);
18953:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18954:21): if (@toshorten) {
18955:21): my (%maps,%resources,%titles);
18956:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18957:21): 'shorturls',$cdom,$cnum);
18958:21): if (keys(%resources)) {
18959:21): my %tocreate;
18960:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18961:21): my $symb = $resources{$item};
18962:21): if ($symb) {
18963:21): $tocreate{$cnum.'&'.$symb} = 1;
18964:21): }
18965:21): }
18966:21): if (keys(%tocreate)) {
18967:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18968:21): \%tocreate);
18969:21): }
18970:21): }
18971:21): }
18972:21): return ($numnew,$errors);
18973:21): }
18974:21):
18975:21): sub make_short_symbs {
18976:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18977:21): my ($numnew,@errors);
18978:21): if (ref($tocreateref) eq 'HASH') {
18979:21): my %tocreate = %{$tocreateref};
18980:21): if (keys(%tocreate)) {
18981:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18982:21): my $su = Short::URL->new(no_vowels => 1);
18983:21): my $init = '';
18984:21): my (%newunique,%addcourse,%courseonly,%failed);
18985:21): # get lock on tiny db
18986:21): my $now = time;
18987:21): if ($lockuser eq '') {
18988:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18989:21): }
18990:21): my $lockhash = {
18991:21): "lock\0$now" => $lockuser,
18992:21): };
18993:21): my $tries = 0;
18994:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18995:21): my ($code,$error);
18996:21): while (($gotlock ne 'ok') && ($tries<3)) {
18997:21): $tries ++;
18998:21): sleep 1;
18999:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19000:21): }
19001:21): if ($gotlock eq 'ok') {
19002:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19003:21): \%addcourse,\%courseonly,\%failed);
19004:21): if (keys(%failed)) {
19005:21): my $numfailed = scalar(keys(%failed));
19006:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19007:21): }
19008:21): if (keys(%newunique)) {
19009:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19010:21): if ($putres eq 'ok') {
19011:21): $numnew = scalar(keys(%newunique));
19012:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19013:21): unless ($newputres eq 'ok') {
19014:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
19015:21): }
19016:21): } else {
19017:21): push(@errors,&mt('error: could not store unique six character URLs'));
19018:21): }
19019:21): }
19020:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19021:21): unless ($dellockres eq 'ok') {
19022:21): push(@errors,&mt('error: could not release lockfile'));
19023:21): }
19024:21): } else {
19025:21): push(@errors,&mt('error: could not obtain lockfile'));
19026:21): }
19027:21): if (keys(%courseonly)) {
19028:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19029:21): if ($result ne 'ok') {
19030:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
19031:21): }
19032:21): }
19033:21): }
19034:21): }
19035:21): return ($numnew,\@errors);
19036:21): }
19037:21):
19038:21): sub shorten_symbs {
19039:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19040:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19041:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19042:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19043:21): my (%possibles,%collisions);
19044:21): foreach my $key (keys(%{$tocreate})) {
19045:21): my $num = String::CRC32::crc32($key);
19046:21): my $tiny = $su->encode($num,$init);
19047:21): if ($tiny) {
19048:21): $possibles{$tiny} = $key;
19049:21): }
19050:21): }
19051:21): if (!$init) {
19052:21): $init = 1;
19053:21): } else {
19054:21): $init ++;
19055:21): }
19056:21): if (keys(%possibles)) {
19057:21): my @posstiny = keys(%possibles);
19058:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19059:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19060:21): if (keys(%currtiny)) {
19061:21): foreach my $key (keys(%currtiny)) {
19062:21): next if ($currtiny{$key} eq '');
19063:21): if ($currtiny{$key} eq $possibles{$key}) {
19064:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19065:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19066:21): $courseonly->{$tsymb} = $key;
19067:21): }
19068:21): } else {
19069:21): $collisions{$possibles{$key}} = 1;
19070:21): }
19071:21): delete($possibles{$key});
19072:21): }
19073:21): }
19074:21): foreach my $key (keys(%possibles)) {
19075:21): $newunique->{$key} = $possibles{$key};
19076:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19077:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19078:21): $addcourse->{$tsymb} = $key;
19079:21): }
19080:21): }
19081:21): }
19082:21): if (keys(%collisions)) {
19083:21): if ($init <5) {
19084:21): if (!$init) {
19085:21): $init = 1;
19086:21): } else {
19087:21): $init ++;
19088:21): }
19089:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19090:21): $newunique,$addcourse,$courseonly,$failed);
19091:21): } else {
19092:21): foreach my $key (keys(%collisions)) {
19093:21): $failed->{$key} = 1;
19094:21): $failed->{$key} = 1;
19095:21): }
19096:21): }
19097:21): }
19098:21): return $init;
19099:21): }
19100:21):
1.1075.2.135 raeburn 19101: sub is_nonframeable {
19102: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19103: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
19104: return if (($remprotocol eq '') || ($remhost eq ''));
19105:
19106: $remprotocol = lc($remprotocol);
19107: $remhost = lc($remhost);
19108: my $remport = 80;
19109: if ($remprotocol eq 'https') {
19110: $remport = 443;
19111: }
19112: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
19113: if ($cached) {
19114: unless ($nocache) {
19115: if ($result) {
19116: return 1;
19117: } else {
19118: return 0;
19119: }
19120: }
19121: }
19122: my $uselink;
19123: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 19124: my $ua = LWP::UserAgent->new;
19125: $ua->timeout(5);
19126: my $response=$ua->request($request);
1.1075.2.135 raeburn 19127: if ($response->is_success()) {
19128: my $secpolicy = lc($response->header('content-security-policy'));
19129: my $xframeop = lc($response->header('x-frame-options'));
19130: $secpolicy =~ s/^\s+|\s+$//g;
19131: $xframeop =~ s/^\s+|\s+$//g;
19132: if (($secpolicy ne '') || ($xframeop ne '')) {
19133: my $remotehost = $remprotocol.'://'.$remhost;
19134: my ($origin,$protocol,$port);
19135: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19136: $port = $ENV{'SERVER_PORT'};
19137: } else {
19138: $port = 80;
19139: }
19140: if ($absolute eq '') {
19141: $protocol = 'http:';
19142: if ($port == 443) {
19143: $protocol = 'https:';
19144: }
19145: $origin = $protocol.'//'.lc($hostname);
19146: } else {
19147: $origin = lc($absolute);
19148: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19149: }
19150: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19151: my $framepolicy = $1;
19152: $framepolicy =~ s/^\s+|\s+$//g;
19153: my @policies = split(/\s+/,$framepolicy);
19154: if (@policies) {
19155: if (grep(/^\Q'none'\E$/,@policies)) {
19156: $uselink = 1;
19157: } else {
19158: $uselink = 1;
19159: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19160: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19161: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19162: undef($uselink);
19163: }
19164: if ($uselink) {
19165: if (grep(/^\Q'self'\E$/,@policies)) {
19166: if (($origin ne '') && ($remotehost eq $origin)) {
19167: undef($uselink);
19168: }
19169: }
19170: }
19171: if ($uselink) {
19172: my @possok;
19173: if ($ip ne '') {
19174: push(@possok,$ip);
19175: }
19176: my $hoststr = '';
19177: foreach my $part (reverse(split(/\./,$hostname))) {
19178: if ($hoststr eq '') {
19179: $hoststr = $part;
19180: } else {
19181: $hoststr = "$part.$hoststr";
19182: }
19183: if ($hoststr eq $hostname) {
19184: push(@possok,$hostname);
19185: } else {
19186: push(@possok,"*.$hoststr");
19187: }
19188: }
19189: if (@possok) {
19190: foreach my $poss (@possok) {
19191: last if (!$uselink);
19192: foreach my $policy (@policies) {
19193: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19194: undef($uselink);
19195: last;
19196: }
19197: }
19198: }
19199: }
19200: }
19201: }
19202: }
19203: } elsif ($xframeop ne '') {
19204: $uselink = 1;
19205: my @policies = split(/\s*,\s*/,$xframeop);
19206: if (@policies) {
19207: unless (grep(/^deny$/,@policies)) {
19208: if ($origin ne '') {
19209: if (grep(/^sameorigin$/,@policies)) {
19210: if ($remotehost eq $origin) {
19211: undef($uselink);
19212: }
19213: }
19214: if ($uselink) {
19215: foreach my $policy (@policies) {
19216: if ($policy =~ /^allow-from\s*(.+)$/) {
19217: my $allowfrom = $1;
19218: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19219: undef($uselink);
19220: last;
19221: }
19222: }
19223: }
19224: }
19225: }
19226: }
19227: }
19228: }
19229: }
19230: }
19231: if ($nocache) {
19232: if ($cached) {
19233: my $devalidate;
19234: if ($uselink && !$result) {
19235: $devalidate = 1;
19236: } elsif (!$uselink && $result) {
19237: $devalidate = 1;
19238: }
19239: if ($devalidate) {
19240: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19241: }
19242: }
19243: } else {
19244: if ($uselink) {
19245: $result = 1;
19246: } else {
19247: $result = 0;
19248: }
19249: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19250: }
19251: return $uselink;
19252: }
19253:
1.1075.2.161. .1(raebu 19254:21): sub page_menu {
19255:21): my ($menucolls,$menunum) = @_;
19256:21): my %menu;
19257:21): foreach my $item (split(/;/,$menucolls)) {
19258:21): my ($num,$value) = split(/\%/,$item);
19259:21): if ($num eq $menunum) {
19260:21): my @entries = split(/\&/,$value);
19261:21): foreach my $entry (@entries) {
19262:21): my ($name,$fields) = split(/=/,$entry);
19263:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
19264:21): $menu{$name} = $fields;
19265:21): } else {
19266:21): my @shown;
19267:21): if ($fields =~ /,/) {
19268:21): @shown = split(/,/,$fields);
19269:21): } else {
19270:21): @shown = ($fields);
19271:21): }
19272:21): if (@shown) {
19273:21): foreach my $field (@shown) {
19274:21): next if ($field eq '');
19275:21): $menu{$field} = 1;
19276:21): }
19277:21): }
19278:21): }
19279:21): }
19280:21): }
19281:21): }
19282:21): return %menu;
19283:21): }
19284:21):
1.112 bowersj2 19285: 1;
19286: __END__;
1.41 ng 19287:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>