Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.29
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. .29(raeb 4:-24): # $Id: loncommon.pm,v 1.1075.2.161.2.28 2024/09/07 18:47:20 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): }
.1(raebu 6463:21): unless ($args->{'no_primary_menu'}) {
.4(raebu 6464:22): my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
.6(raebu 6465:22): $args->{'links_disabled'},
.21(raeb 6466:-24): $args->{'links_target'},
.23(raeb 6467:-24): $collapsible);
.1(raebu 6468:21): if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6469:21): if ($dc_info) {
6470:21): $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6471:21): }
6472:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6473:21): <em>$realm</em> $dc_info</div>|;
6474:21): return $bodytag;
1.1075.2.1 raeburn 6475: }
1.894 droeschl 6476:
1.1075.2.161. .1(raebu 6477:21): unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6478:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6479:21): }
1.916 droeschl 6480:
1.1075.2.161. .1(raebu 6481:21): $bodytag .= $right;
1.852 droeschl 6482:
1.1075.2.161. .1(raebu 6483:21): if ($dc_info) {
6484:21): $dc_info = &dc_courseid_toggle($dc_info);
6485:21): }
6486:21): $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6487: }
1.916 droeschl 6488:
1.1075.2.61 raeburn 6489: #if directed to not display the secondary menu, don't.
6490: if ($args->{'no_secondary_menu'}) {
6491: return $bodytag;
6492: }
1.903 droeschl 6493: #don't show menus for public users
1.954 raeburn 6494: if (!$public){
1.1075.2.161. .1(raebu 6495:21): unless ($args->{'no_inline_menu'}) {
6496:21): $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6497:21): $args->{'no_primary_menu'},
6498:21): $menucoll,$menuref,
.6(raebu 6499:22): $args->{'links_disabled'},
6500:22): $args->{'links_target'});
.1(raebu 6501:21): }
1.903 droeschl 6502: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6503: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6504: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6505: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.161. .8(raebu 6506:22): $args->{'bread_crumbs'},'','',$hostname,
6507:22): $ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.116 raeburn 6508: } elsif ($forcereg) {
1.1075.2.22 raeburn 6509: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.161. .8(raebu 6510:22): $args->{'group'},$args->{'hide_buttons'},
6511:22): $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.15 raeburn 6512: } else {
1.1075.2.21 raeburn 6513: my $forbodytag;
6514: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6515: $forcereg,$args->{'group'},
6516: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6517: $advtoolsref,'',$hostname,
6518: \$forbodytag);
1.1075.2.21 raeburn 6519: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6520: $bodytag .= $forbodytag;
6521: }
1.920 raeburn 6522: }
1.903 droeschl 6523: }else{
6524: # this is to seperate menu from content when there's no secondary
6525: # menu. Especially needed for public accessible ressources.
6526: $bodytag .= '<hr style="clear:both" />';
6527: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6528: }
1.1075.2.161. .21(raeb 6529:-24): if ($args->{'collapsible_header'} ne '') {
6530:-24): $bodytag .= $args->{'collapsible_header'}.
6531:-24): '<div id="LC_collapsible_separator"></div>'.
6532:-24): '</div></div>';
6533:-24): }
1.235 raeburn 6534: return $bodytag;
1.1075.2.12 raeburn 6535: }
6536:
6537: #
6538: # Top frame rendering, Remote is up
6539: #
6540:
6541: my $imgsrc = $img;
6542: if ($img =~ /^\/adm/) {
6543: $imgsrc = &lonhttpdurl($img);
6544: }
6545: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
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'}) {
6565: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 6566: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 6567: <li>$help</li>
1.1075.2.12 raeburn 6568: <li>$menu</li>
6569: </ol><div id="LC_realm"> $realm $dc_info</div>|;
6570: }
1.1075.2.13 raeburn 6571: if ($env{'request.state'} eq 'construct') {
6572: if (!$public){
6573: if ($env{'request.state'} eq 'construct') {
6574: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6575: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 6576: &Apache::lonhtmlcommon::scripttag('','end').
6577: &Apache::lonmenu::innerregister($forcereg,
6578: $args->{'bread_crumbs'});
6579: }
6580: }
6581: }
1.1075.2.21 raeburn 6582: return $bodytag."\n".$funclist;
1.182 matthew 6583: }
6584:
1.917 raeburn 6585: sub dc_courseid_toggle {
6586: my ($dc_info) = @_;
1.980 raeburn 6587: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6588: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6589: &mt('(More ...)').'</a></span>'.
6590: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6591: }
6592:
1.330 albertel 6593: sub make_attr_string {
6594: my ($register,$attr_ref) = @_;
6595:
6596: if ($attr_ref && !ref($attr_ref)) {
6597: die("addentries Must be a hash ref ".
6598: join(':',caller(1))." ".
6599: join(':',caller(0))." ");
6600: }
6601:
6602: if ($register) {
1.339 albertel 6603: my ($on_load,$on_unload);
6604: foreach my $key (keys(%{$attr_ref})) {
6605: if (lc($key) eq 'onload') {
6606: $on_load.=$attr_ref->{$key}.';';
6607: delete($attr_ref->{$key});
6608:
6609: } elsif (lc($key) eq 'onunload') {
6610: $on_unload.=$attr_ref->{$key}.';';
6611: delete($attr_ref->{$key});
6612: }
6613: }
1.1075.2.12 raeburn 6614: if ($env{'environment.remote'} eq 'on') {
6615: $attr_ref->{'onload'} =
6616: &Apache::lonmenu::loadevents(). $on_load;
6617: $attr_ref->{'onunload'}=
6618: &Apache::lonmenu::unloadevents().$on_unload;
6619: } else {
6620: $attr_ref->{'onload'} = $on_load;
6621: $attr_ref->{'onunload'}= $on_unload;
6622: }
1.330 albertel 6623: }
1.339 albertel 6624:
1.330 albertel 6625: my $attr_string;
1.1075.2.56 raeburn 6626: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6627: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6628: }
6629: return $attr_string;
6630: }
6631:
6632:
1.182 matthew 6633: ###############################################
1.251 albertel 6634: ###############################################
6635:
6636: =pod
6637:
6638: =item * &endbodytag()
6639:
6640: Returns a uniform footer for LON-CAPA web pages.
6641:
1.635 raeburn 6642: Inputs: 1 - optional reference to an args hash
6643: If in the hash, key for noredirectlink has a value which evaluates to true,
6644: a 'Continue' link is not displayed if the page contains an
6645: internal redirect in the <head></head> section,
6646: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6647:
6648: =cut
6649:
6650: sub endbodytag {
1.635 raeburn 6651: my ($args) = @_;
1.1075.2.6 raeburn 6652: my $endbodytag;
6653: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6654: $endbodytag='</body>';
6655: }
1.315 albertel 6656: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6657: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1075.2.161. .9(raebu 6658:22): my ($endbodyjs,$idattr);
6659:22): if ($env{'internal.head.to_opener'}) {
6660:22): my $linkid = 'LC_continue_link';
6661:22): $idattr = ' id="'.$linkid.'"';
6662:22): my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6663:22): $endbodyjs=<<ENDJS;
6664:22): <script type="text/javascript">
6665:22): // <![CDATA[
6666:22): function ebFunction(evt) {
6667:22): evt.preventDefault();
6668:22): var dest = '$redirect_for_js';
6669:22): if (window.opener != null && !window.opener.closed) {
6670:22): window.opener.location.href=dest;
6671:22): window.close();
6672:22): } else {
6673:22): window.location.href=dest;
6674:22): }
6675:22): return false;
6676:22): }
6677:22):
6678:22): \$(document).ready(function () {
6679:22): if (document.getElementById('$linkid')) {
6680:22): var clickelem = document.getElementById('$linkid');
6681:22): clickelem.addEventListener('click',ebFunction,false);
6682:22): }
6683:22): });
6684:22): // ]]>
6685:22): </script>
6686:22): ENDJS
6687:22): }
1.635 raeburn 6688: $endbodytag=
1.1075.2.161. .9(raebu 6689:22): "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6690: &mt('Continue').'</a>'.
6691: $endbodytag;
6692: }
1.315 albertel 6693: }
1.1075.2.161. .19(raeb 6694:-23): if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6695:-23): $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6696:-23): }
1.251 albertel 6697: return $endbodytag;
6698: }
6699:
1.352 albertel 6700: =pod
6701:
6702: =item * &standard_css()
6703:
6704: Returns a style sheet
6705:
6706: Inputs: (all optional)
6707: domain -> force to color decorate a page for a specific
6708: domain
6709: function -> force usage of a specific rolish color scheme
6710: bgcolor -> override the default page bgcolor
6711:
6712: =cut
6713:
1.343 albertel 6714: sub standard_css {
1.345 albertel 6715: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6716: $function = &get_users_function() if (!$function);
6717: my $img = &designparm($function.'.img', $domain);
6718: my $tabbg = &designparm($function.'.tabbg', $domain);
6719: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6720: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6721: #second colour for later usage
1.345 albertel 6722: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6723: my $pgbg_or_bgcolor =
6724: $bgcolor ||
1.352 albertel 6725: &designparm($function.'.pgbg', $domain);
1.382 albertel 6726: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6727: my $alink = &designparm($function.'.alink', $domain);
6728: my $vlink = &designparm($function.'.vlink', $domain);
6729: my $link = &designparm($function.'.link', $domain);
6730:
1.602 albertel 6731: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6732: my $mono = 'monospace';
1.850 bisitz 6733: my $data_table_head = $sidebg;
6734: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6735: my $data_table_dark = '#E0E0E0';
1.470 banghart 6736: my $data_table_darker = '#CCCCCC';
1.349 albertel 6737: my $data_table_highlight = '#FFFF00';
1.352 albertel 6738: my $mail_new = '#FFBB77';
6739: my $mail_new_hover = '#DD9955';
6740: my $mail_read = '#BBBB77';
6741: my $mail_read_hover = '#999944';
6742: my $mail_replied = '#AAAA88';
6743: my $mail_replied_hover = '#888855';
6744: my $mail_other = '#99BBBB';
6745: my $mail_other_hover = '#669999';
1.391 albertel 6746: my $table_header = '#DDDDDD';
1.489 raeburn 6747: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6748: my $lg_border_color = '#C8C8C8';
1.952 onken 6749: my $button_hover = '#BF2317';
1.392 albertel 6750:
1.608 albertel 6751: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6752: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6753: : '0 3px 0 4px';
1.448 albertel 6754:
1.523 albertel 6755:
1.343 albertel 6756: return <<END;
1.947 droeschl 6757:
6758: /* needed for iframe to allow 100% height in FF */
6759: body, html {
6760: margin: 0;
6761: padding: 0 0.5%;
6762: height: 99%; /* to avoid scrollbars */
6763: }
6764:
1.795 www 6765: body {
1.911 bisitz 6766: font-family: $sans;
6767: line-height:130%;
6768: font-size:0.83em;
6769: color:$font;
1.795 www 6770: }
6771:
1.959 onken 6772: a:focus,
6773: a:focus img {
1.795 www 6774: color: red;
6775: }
1.698 harmsja 6776:
1.911 bisitz 6777: form, .inline {
6778: display: inline;
1.795 www 6779: }
1.721 harmsja 6780:
1.1075.2.161. .21(raeb 6781:-24): .LC_menus_content.shown{
.24(raeb 6782:-24): display: block;
.21(raeb 6783:-24): }
6784:-24):
6785:-24): .LC_menus_content.hidden {
6786:-24): display: none;
6787:-24): }
6788:-24):
1.795 www 6789: .LC_right {
1.911 bisitz 6790: text-align:right;
1.795 www 6791: }
6792:
6793: .LC_middle {
1.911 bisitz 6794: vertical-align:middle;
1.795 www 6795: }
1.721 harmsja 6796:
1.1075.2.38 raeburn 6797: .LC_floatleft {
6798: float: left;
6799: }
6800:
6801: .LC_floatright {
6802: float: right;
6803: }
6804:
1.911 bisitz 6805: .LC_400Box {
6806: width:400px;
6807: }
1.721 harmsja 6808:
1.1075.2.161. .21(raeb 6809:-24): #LC_collapsible_separator {
6810:-24): border: 1px solid black;
6811:-24): width: 99.9%;
6812:-24): height: 0px;
6813:-24): }
6814:-24):
1.947 droeschl 6815: .LC_iframecontainer {
6816: width: 98%;
6817: margin: 0;
6818: position: fixed;
6819: top: 8.5em;
6820: bottom: 0;
6821: }
6822:
6823: .LC_iframecontainer iframe{
6824: border: none;
6825: width: 100%;
6826: height: 100%;
6827: }
6828:
1.778 bisitz 6829: .LC_filename {
6830: font-family: $mono;
6831: white-space:pre;
1.921 bisitz 6832: font-size: 120%;
1.778 bisitz 6833: }
6834:
6835: .LC_fileicon {
6836: border: none;
6837: height: 1.3em;
6838: vertical-align: text-bottom;
6839: margin-right: 0.3em;
6840: text-decoration:none;
6841: }
6842:
1.1008 www 6843: .LC_setting {
6844: text-decoration:underline;
6845: }
6846:
1.350 albertel 6847: .LC_error {
6848: color: red;
6849: }
1.795 www 6850:
1.1075.2.15 raeburn 6851: .LC_warning {
6852: color: darkorange;
6853: }
6854:
1.457 albertel 6855: .LC_diff_removed {
1.733 bisitz 6856: color: red;
1.394 albertel 6857: }
1.532 albertel 6858:
6859: .LC_info,
1.457 albertel 6860: .LC_success,
6861: .LC_diff_added {
1.350 albertel 6862: color: green;
6863: }
1.795 www 6864:
1.802 bisitz 6865: div.LC_confirm_box {
6866: background-color: #FAFAFA;
6867: border: 1px solid $lg_border_color;
6868: margin-right: 0;
6869: padding: 5px;
6870: }
6871:
6872: div.LC_confirm_box .LC_error img,
6873: div.LC_confirm_box .LC_success img {
6874: vertical-align: middle;
6875: }
6876:
1.1075.2.108 raeburn 6877: .LC_maxwidth {
6878: max-width: 100%;
6879: height: auto;
6880: }
6881:
6882: .LC_textsize_mobile {
6883: \@media only screen and (max-device-width: 480px) {
6884: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6885: }
6886: }
6887:
1.440 albertel 6888: .LC_icon {
1.771 droeschl 6889: border: none;
1.790 droeschl 6890: vertical-align: middle;
1.771 droeschl 6891: }
6892:
1.543 albertel 6893: .LC_docs_spacer {
6894: width: 25px;
6895: height: 1px;
1.771 droeschl 6896: border: none;
1.543 albertel 6897: }
1.346 albertel 6898:
1.532 albertel 6899: .LC_internal_info {
1.735 bisitz 6900: color: #999999;
1.532 albertel 6901: }
6902:
1.794 www 6903: .LC_discussion {
1.1050 www 6904: background: $data_table_dark;
1.911 bisitz 6905: border: 1px solid black;
6906: margin: 2px;
1.794 www 6907: }
6908:
6909: .LC_disc_action_left {
1.1050 www 6910: background: $sidebg;
1.911 bisitz 6911: text-align: left;
1.1050 www 6912: padding: 4px;
6913: margin: 2px;
1.794 www 6914: }
6915:
6916: .LC_disc_action_right {
1.1050 www 6917: background: $sidebg;
1.911 bisitz 6918: text-align: right;
1.1050 www 6919: padding: 4px;
6920: margin: 2px;
1.794 www 6921: }
6922:
6923: .LC_disc_new_item {
1.911 bisitz 6924: background: white;
6925: border: 2px solid red;
1.1050 www 6926: margin: 4px;
6927: padding: 4px;
1.794 www 6928: }
6929:
6930: .LC_disc_old_item {
1.911 bisitz 6931: background: white;
1.1050 www 6932: margin: 4px;
6933: padding: 4px;
1.794 www 6934: }
6935:
1.458 albertel 6936: table.LC_pastsubmission {
6937: border: 1px solid black;
6938: margin: 2px;
6939: }
6940:
1.924 bisitz 6941: table#LC_menubuttons {
1.345 albertel 6942: width: 100%;
6943: background: $pgbg;
1.392 albertel 6944: border: 2px;
1.402 albertel 6945: border-collapse: separate;
1.803 bisitz 6946: padding: 0;
1.345 albertel 6947: }
1.392 albertel 6948:
1.801 tempelho 6949: table#LC_title_bar a {
6950: color: $fontmenu;
6951: }
1.836 bisitz 6952:
1.807 droeschl 6953: table#LC_title_bar {
1.819 tempelho 6954: clear: both;
1.836 bisitz 6955: display: none;
1.807 droeschl 6956: }
6957:
1.795 www 6958: table#LC_title_bar,
1.933 droeschl 6959: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6960: table#LC_title_bar.LC_with_remote {
1.359 albertel 6961: width: 100%;
1.392 albertel 6962: border-color: $pgbg;
6963: border-style: solid;
6964: border-width: $border;
1.379 albertel 6965: background: $pgbg;
1.801 tempelho 6966: color: $fontmenu;
1.392 albertel 6967: border-collapse: collapse;
1.803 bisitz 6968: padding: 0;
1.819 tempelho 6969: margin: 0;
1.359 albertel 6970: }
1.795 www 6971:
1.933 droeschl 6972: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6973: margin: 0;
6974: padding: 0;
1.933 droeschl 6975: position: relative;
6976: list-style: none;
1.913 droeschl 6977: }
1.933 droeschl 6978: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6979: display: inline;
6980: }
1.933 droeschl 6981:
6982: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6983: padding: 0;
1.933 droeschl 6984: margin: 0;
6985: float: left;
1.913 droeschl 6986: }
1.933 droeschl 6987: .LC_breadcrumb_tools_tools {
6988: padding: 0;
6989: margin: 0;
1.913 droeschl 6990: float: right;
6991: }
6992:
1.359 albertel 6993: table#LC_title_bar td {
6994: background: $tabbg;
6995: }
1.795 www 6996:
1.911 bisitz 6997: table#LC_menubuttons img {
1.803 bisitz 6998: border: none;
1.346 albertel 6999: }
1.795 www 7000:
1.842 droeschl 7001: .LC_breadcrumbs_component {
1.911 bisitz 7002: float: right;
7003: margin: 0 1em;
1.357 albertel 7004: }
1.842 droeschl 7005: .LC_breadcrumbs_component img {
1.911 bisitz 7006: vertical-align: middle;
1.777 tempelho 7007: }
1.795 www 7008:
1.1075.2.108 raeburn 7009: .LC_breadcrumbs_hoverable {
7010: background: $sidebg;
7011: }
7012:
1.383 albertel 7013: td.LC_table_cell_checkbox {
7014: text-align: center;
7015: }
1.795 www 7016:
7017: .LC_fontsize_small {
1.911 bisitz 7018: font-size: 70%;
1.705 tempelho 7019: }
7020:
1.844 bisitz 7021: #LC_breadcrumbs {
1.911 bisitz 7022: clear:both;
7023: background: $sidebg;
7024: border-bottom: 1px solid $lg_border_color;
7025: line-height: 2.5em;
1.933 droeschl 7026: overflow: hidden;
1.911 bisitz 7027: margin: 0;
7028: padding: 0;
1.995 raeburn 7029: text-align: left;
1.819 tempelho 7030: }
1.862 bisitz 7031:
1.1075.2.16 raeburn 7032: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7033: clear:both;
7034: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7035: border: 1px solid $sidebg;
1.1075.2.16 raeburn 7036: margin: 0 0 10px 0;
1.966 bisitz 7037: padding: 3px;
1.995 raeburn 7038: text-align: left;
1.822 bisitz 7039: }
7040:
1.795 www 7041: .LC_fontsize_medium {
1.911 bisitz 7042: font-size: 85%;
1.705 tempelho 7043: }
7044:
1.795 www 7045: .LC_fontsize_large {
1.911 bisitz 7046: font-size: 120%;
1.705 tempelho 7047: }
7048:
1.346 albertel 7049: .LC_menubuttons_inline_text {
7050: color: $font;
1.698 harmsja 7051: font-size: 90%;
1.701 harmsja 7052: padding-left:3px;
1.346 albertel 7053: }
7054:
1.934 droeschl 7055: .LC_menubuttons_inline_text img{
7056: vertical-align: middle;
7057: }
7058:
1.1051 www 7059: li.LC_menubuttons_inline_text img {
1.951 onken 7060: cursor:pointer;
1.1002 droeschl 7061: text-decoration: none;
1.951 onken 7062: }
7063:
1.526 www 7064: .LC_menubuttons_link {
7065: text-decoration: none;
7066: }
1.795 www 7067:
1.522 albertel 7068: .LC_menubuttons_category {
1.521 www 7069: color: $font;
1.526 www 7070: background: $pgbg;
1.521 www 7071: font-size: larger;
7072: font-weight: bold;
7073: }
7074:
1.346 albertel 7075: td.LC_menubuttons_text {
1.911 bisitz 7076: color: $font;
1.346 albertel 7077: }
1.706 harmsja 7078:
1.346 albertel 7079: .LC_current_location {
7080: background: $tabbg;
7081: }
1.795 www 7082:
1.1075.2.134 raeburn 7083: td.LC_zero_height {
7084: line-height: 0;
7085: cellpadding: 0;
7086: }
7087:
1.938 bisitz 7088: table.LC_data_table {
1.347 albertel 7089: border: 1px solid #000000;
1.402 albertel 7090: border-collapse: separate;
1.426 albertel 7091: border-spacing: 1px;
1.610 albertel 7092: background: $pgbg;
1.347 albertel 7093: }
1.795 www 7094:
1.422 albertel 7095: .LC_data_table_dense {
7096: font-size: small;
7097: }
1.795 www 7098:
1.507 raeburn 7099: table.LC_nested_outer {
7100: border: 1px solid #000000;
1.589 raeburn 7101: border-collapse: collapse;
1.803 bisitz 7102: border-spacing: 0;
1.507 raeburn 7103: width: 100%;
7104: }
1.795 www 7105:
1.879 raeburn 7106: table.LC_innerpickbox,
1.507 raeburn 7107: table.LC_nested {
1.803 bisitz 7108: border: none;
1.589 raeburn 7109: border-collapse: collapse;
1.803 bisitz 7110: border-spacing: 0;
1.507 raeburn 7111: width: 100%;
7112: }
1.795 www 7113:
1.911 bisitz 7114: table.LC_data_table tr th,
7115: table.LC_calendar tr th,
1.879 raeburn 7116: table.LC_prior_tries tr th,
7117: table.LC_innerpickbox tr th {
1.349 albertel 7118: font-weight: bold;
7119: background-color: $data_table_head;
1.801 tempelho 7120: color:$fontmenu;
1.701 harmsja 7121: font-size:90%;
1.347 albertel 7122: }
1.795 www 7123:
1.879 raeburn 7124: table.LC_innerpickbox tr th,
7125: table.LC_innerpickbox tr td {
7126: vertical-align: top;
7127: }
7128:
1.711 raeburn 7129: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7130: background-color: #CCCCCC;
1.711 raeburn 7131: font-weight: bold;
7132: text-align: left;
7133: }
1.795 www 7134:
1.912 bisitz 7135: table.LC_data_table tr.LC_odd_row > td {
7136: background-color: $data_table_light;
7137: padding: 2px;
7138: vertical-align: top;
7139: }
7140:
1.809 bisitz 7141: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7142: background-color: $data_table_light;
1.912 bisitz 7143: vertical-align: top;
7144: }
7145:
7146: table.LC_data_table tr.LC_even_row > td {
7147: background-color: $data_table_dark;
1.425 albertel 7148: padding: 2px;
1.900 bisitz 7149: vertical-align: top;
1.347 albertel 7150: }
1.795 www 7151:
1.809 bisitz 7152: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7153: background-color: $data_table_dark;
1.900 bisitz 7154: vertical-align: top;
1.347 albertel 7155: }
1.795 www 7156:
1.425 albertel 7157: table.LC_data_table tr.LC_data_table_highlight td {
7158: background-color: $data_table_darker;
7159: }
1.795 www 7160:
1.639 raeburn 7161: table.LC_data_table tr td.LC_leftcol_header {
7162: background-color: $data_table_head;
7163: font-weight: bold;
7164: }
1.795 www 7165:
1.451 albertel 7166: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7167: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7168: font-weight: bold;
7169: font-style: italic;
7170: text-align: center;
7171: padding: 8px;
1.347 albertel 7172: }
1.795 www 7173:
1.1075.2.30 raeburn 7174: table.LC_data_table tr.LC_empty_row td,
7175: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7176: background-color: $sidebg;
7177: }
7178:
7179: table.LC_nested tr.LC_empty_row td {
7180: background-color: #FFFFFF;
7181: }
7182:
1.890 droeschl 7183: table.LC_caption {
7184: }
7185:
1.507 raeburn 7186: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7187: padding: 4ex
7188: }
1.795 www 7189:
1.507 raeburn 7190: table.LC_nested_outer tr th {
7191: font-weight: bold;
1.801 tempelho 7192: color:$fontmenu;
1.507 raeburn 7193: background-color: $data_table_head;
1.701 harmsja 7194: font-size: small;
1.507 raeburn 7195: border-bottom: 1px solid #000000;
7196: }
1.795 www 7197:
1.507 raeburn 7198: table.LC_nested_outer tr td.LC_subheader {
7199: background-color: $data_table_head;
7200: font-weight: bold;
7201: font-size: small;
7202: border-bottom: 1px solid #000000;
7203: text-align: right;
1.451 albertel 7204: }
1.795 www 7205:
1.507 raeburn 7206: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7207: background-color: #CCCCCC;
1.451 albertel 7208: font-weight: bold;
7209: font-size: small;
1.507 raeburn 7210: text-align: center;
7211: }
1.795 www 7212:
1.589 raeburn 7213: table.LC_nested tr.LC_info_row td.LC_left_item,
7214: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7215: text-align: left;
1.451 albertel 7216: }
1.795 www 7217:
1.507 raeburn 7218: table.LC_nested td {
1.735 bisitz 7219: background-color: #FFFFFF;
1.451 albertel 7220: font-size: small;
1.507 raeburn 7221: }
1.795 www 7222:
1.507 raeburn 7223: table.LC_nested_outer tr th.LC_right_item,
7224: table.LC_nested tr.LC_info_row td.LC_right_item,
7225: table.LC_nested tr.LC_odd_row td.LC_right_item,
7226: table.LC_nested tr td.LC_right_item {
1.451 albertel 7227: text-align: right;
7228: }
7229:
1.507 raeburn 7230: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7231: background-color: #EEEEEE;
1.451 albertel 7232: }
7233:
1.473 raeburn 7234: table.LC_createuser {
7235: }
7236:
7237: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7238: font-size: small;
1.473 raeburn 7239: }
7240:
7241: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7242: background-color: #CCCCCC;
1.473 raeburn 7243: font-weight: bold;
7244: text-align: center;
7245: }
7246:
1.349 albertel 7247: table.LC_calendar {
7248: border: 1px solid #000000;
7249: border-collapse: collapse;
1.917 raeburn 7250: width: 98%;
1.349 albertel 7251: }
1.795 www 7252:
1.349 albertel 7253: table.LC_calendar_pickdate {
7254: font-size: xx-small;
7255: }
1.795 www 7256:
1.349 albertel 7257: table.LC_calendar tr td {
7258: border: 1px solid #000000;
7259: vertical-align: top;
1.917 raeburn 7260: width: 14%;
1.349 albertel 7261: }
1.795 www 7262:
1.349 albertel 7263: table.LC_calendar tr td.LC_calendar_day_empty {
7264: background-color: $data_table_dark;
7265: }
1.795 www 7266:
1.779 bisitz 7267: table.LC_calendar tr td.LC_calendar_day_current {
7268: background-color: $data_table_highlight;
1.777 tempelho 7269: }
1.795 www 7270:
1.938 bisitz 7271: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7272: background-color: $mail_new;
7273: }
1.795 www 7274:
1.938 bisitz 7275: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7276: background-color: $mail_new_hover;
7277: }
1.795 www 7278:
1.938 bisitz 7279: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7280: background-color: $mail_read;
7281: }
1.795 www 7282:
1.938 bisitz 7283: /*
7284: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7285: background-color: $mail_read_hover;
7286: }
1.938 bisitz 7287: */
1.795 www 7288:
1.938 bisitz 7289: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7290: background-color: $mail_replied;
7291: }
1.795 www 7292:
1.938 bisitz 7293: /*
7294: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7295: background-color: $mail_replied_hover;
7296: }
1.938 bisitz 7297: */
1.795 www 7298:
1.938 bisitz 7299: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7300: background-color: $mail_other;
7301: }
1.795 www 7302:
1.938 bisitz 7303: /*
7304: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7305: background-color: $mail_other_hover;
7306: }
1.938 bisitz 7307: */
1.494 raeburn 7308:
1.777 tempelho 7309: table.LC_data_table tr > td.LC_browser_file,
7310: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7311: background: #AAEE77;
1.389 albertel 7312: }
1.795 www 7313:
1.777 tempelho 7314: table.LC_data_table tr > td.LC_browser_file_locked,
7315: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7316: background: #FFAA99;
1.387 albertel 7317: }
1.795 www 7318:
1.777 tempelho 7319: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7320: background: #888888;
1.779 bisitz 7321: }
1.795 www 7322:
1.777 tempelho 7323: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7324: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7325: background: #F8F866;
1.777 tempelho 7326: }
1.795 www 7327:
1.696 bisitz 7328: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7329: background: #E0E8FF;
1.387 albertel 7330: }
1.696 bisitz 7331:
1.707 bisitz 7332: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7333: /* background: #77FF77; */
1.707 bisitz 7334: }
1.795 www 7335:
1.707 bisitz 7336: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7337: border-right: 8px solid #FFFF77;
1.707 bisitz 7338: }
1.795 www 7339:
1.707 bisitz 7340: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7341: border-right: 8px solid #FFAA77;
1.707 bisitz 7342: }
1.795 www 7343:
1.707 bisitz 7344: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7345: border-right: 8px solid #FF7777;
1.707 bisitz 7346: }
1.795 www 7347:
1.707 bisitz 7348: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7349: border-right: 8px solid #AAFF77;
1.707 bisitz 7350: }
1.795 www 7351:
1.707 bisitz 7352: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7353: border-right: 8px solid #11CC55;
1.707 bisitz 7354: }
7355:
1.388 albertel 7356: span.LC_current_location {
1.701 harmsja 7357: font-size:larger;
1.388 albertel 7358: background: $pgbg;
7359: }
1.387 albertel 7360:
1.1029 www 7361: span.LC_current_nav_location {
7362: font-weight:bold;
7363: background: $sidebg;
7364: }
7365:
1.395 albertel 7366: span.LC_parm_menu_item {
7367: font-size: larger;
7368: }
1.795 www 7369:
1.395 albertel 7370: span.LC_parm_scope_all {
7371: color: red;
7372: }
1.795 www 7373:
1.395 albertel 7374: span.LC_parm_scope_folder {
7375: color: green;
7376: }
1.795 www 7377:
1.395 albertel 7378: span.LC_parm_scope_resource {
7379: color: orange;
7380: }
1.795 www 7381:
1.395 albertel 7382: span.LC_parm_part {
7383: color: blue;
7384: }
1.795 www 7385:
1.911 bisitz 7386: span.LC_parm_folder,
7387: span.LC_parm_symb {
1.395 albertel 7388: font-size: x-small;
7389: font-family: $mono;
7390: color: #AAAAAA;
7391: }
7392:
1.977 bisitz 7393: ul.LC_parm_parmlist li {
7394: display: inline-block;
7395: padding: 0.3em 0.8em;
7396: vertical-align: top;
7397: width: 150px;
7398: border-top:1px solid $lg_border_color;
7399: }
7400:
1.795 www 7401: td.LC_parm_overview_level_menu,
7402: td.LC_parm_overview_map_menu,
7403: td.LC_parm_overview_parm_selectors,
7404: td.LC_parm_overview_restrictions {
1.396 albertel 7405: border: 1px solid black;
7406: border-collapse: collapse;
7407: }
1.795 www 7408:
1.396 albertel 7409: table.LC_parm_overview_restrictions td {
7410: border-width: 1px 4px 1px 4px;
7411: border-style: solid;
7412: border-color: $pgbg;
7413: text-align: center;
7414: }
1.795 www 7415:
1.396 albertel 7416: table.LC_parm_overview_restrictions th {
7417: background: $tabbg;
7418: border-width: 1px 4px 1px 4px;
7419: border-style: solid;
7420: border-color: $pgbg;
7421: }
1.795 www 7422:
1.398 albertel 7423: table#LC_helpmenu {
1.803 bisitz 7424: border: none;
1.398 albertel 7425: height: 55px;
1.803 bisitz 7426: border-spacing: 0;
1.398 albertel 7427: }
7428:
7429: table#LC_helpmenu fieldset legend {
7430: font-size: larger;
7431: }
1.795 www 7432:
1.397 albertel 7433: table#LC_helpmenu_links {
7434: width: 100%;
7435: border: 1px solid black;
7436: background: $pgbg;
1.803 bisitz 7437: padding: 0;
1.397 albertel 7438: border-spacing: 1px;
7439: }
1.795 www 7440:
1.397 albertel 7441: table#LC_helpmenu_links tr td {
7442: padding: 1px;
7443: background: $tabbg;
1.399 albertel 7444: text-align: center;
7445: font-weight: bold;
1.397 albertel 7446: }
1.396 albertel 7447:
1.795 www 7448: table#LC_helpmenu_links a:link,
7449: table#LC_helpmenu_links a:visited,
1.397 albertel 7450: table#LC_helpmenu_links a:active {
7451: text-decoration: none;
7452: color: $font;
7453: }
1.795 www 7454:
1.397 albertel 7455: table#LC_helpmenu_links a:hover {
7456: text-decoration: underline;
7457: color: $vlink;
7458: }
1.396 albertel 7459:
1.417 albertel 7460: .LC_chrt_popup_exists {
7461: border: 1px solid #339933;
7462: margin: -1px;
7463: }
1.795 www 7464:
1.417 albertel 7465: .LC_chrt_popup_up {
7466: border: 1px solid yellow;
7467: margin: -1px;
7468: }
1.795 www 7469:
1.417 albertel 7470: .LC_chrt_popup {
7471: border: 1px solid #8888FF;
7472: background: #CCCCFF;
7473: }
1.795 www 7474:
1.421 albertel 7475: table.LC_pick_box {
7476: border-collapse: separate;
7477: background: white;
7478: border: 1px solid black;
7479: border-spacing: 1px;
7480: }
1.795 www 7481:
1.421 albertel 7482: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7483: background: $sidebg;
1.421 albertel 7484: font-weight: bold;
1.900 bisitz 7485: text-align: left;
1.740 bisitz 7486: vertical-align: top;
1.421 albertel 7487: width: 184px;
7488: padding: 8px;
7489: }
1.795 www 7490:
1.579 raeburn 7491: table.LC_pick_box td.LC_pick_box_value {
7492: text-align: left;
7493: padding: 8px;
7494: }
1.795 www 7495:
1.579 raeburn 7496: table.LC_pick_box td.LC_pick_box_select {
7497: text-align: left;
7498: padding: 8px;
7499: }
1.795 www 7500:
1.424 albertel 7501: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7502: padding: 0;
1.421 albertel 7503: height: 1px;
7504: background: black;
7505: }
1.795 www 7506:
1.421 albertel 7507: table.LC_pick_box td.LC_pick_box_submit {
7508: text-align: right;
7509: }
1.795 www 7510:
1.579 raeburn 7511: table.LC_pick_box td.LC_evenrow_value {
7512: text-align: left;
7513: padding: 8px;
7514: background-color: $data_table_light;
7515: }
1.795 www 7516:
1.579 raeburn 7517: table.LC_pick_box td.LC_oddrow_value {
7518: text-align: left;
7519: padding: 8px;
7520: background-color: $data_table_light;
7521: }
1.795 www 7522:
1.579 raeburn 7523: span.LC_helpform_receipt_cat {
7524: font-weight: bold;
7525: }
1.795 www 7526:
1.424 albertel 7527: table.LC_group_priv_box {
7528: background: white;
7529: border: 1px solid black;
7530: border-spacing: 1px;
7531: }
1.795 www 7532:
1.424 albertel 7533: table.LC_group_priv_box td.LC_pick_box_title {
7534: background: $tabbg;
7535: font-weight: bold;
7536: text-align: right;
7537: width: 184px;
7538: }
1.795 www 7539:
1.424 albertel 7540: table.LC_group_priv_box td.LC_groups_fixed {
7541: background: $data_table_light;
7542: text-align: center;
7543: }
1.795 www 7544:
1.424 albertel 7545: table.LC_group_priv_box td.LC_groups_optional {
7546: background: $data_table_dark;
7547: text-align: center;
7548: }
1.795 www 7549:
1.424 albertel 7550: table.LC_group_priv_box td.LC_groups_functionality {
7551: background: $data_table_darker;
7552: text-align: center;
7553: font-weight: bold;
7554: }
1.795 www 7555:
1.424 albertel 7556: table.LC_group_priv td {
7557: text-align: left;
1.803 bisitz 7558: padding: 0;
1.424 albertel 7559: }
7560:
7561: .LC_navbuttons {
7562: margin: 2ex 0ex 2ex 0ex;
7563: }
1.795 www 7564:
1.423 albertel 7565: .LC_topic_bar {
7566: font-weight: bold;
7567: background: $tabbg;
1.918 wenzelju 7568: margin: 1em 0em 1em 2em;
1.805 bisitz 7569: padding: 3px;
1.918 wenzelju 7570: font-size: 1.2em;
1.423 albertel 7571: }
1.795 www 7572:
1.423 albertel 7573: .LC_topic_bar span {
1.918 wenzelju 7574: left: 0.5em;
7575: position: absolute;
1.423 albertel 7576: vertical-align: middle;
1.918 wenzelju 7577: font-size: 1.2em;
1.423 albertel 7578: }
1.795 www 7579:
1.423 albertel 7580: table.LC_course_group_status {
7581: margin: 20px;
7582: }
1.795 www 7583:
1.423 albertel 7584: table.LC_status_selector td {
7585: vertical-align: top;
7586: text-align: center;
1.424 albertel 7587: padding: 4px;
7588: }
1.795 www 7589:
1.599 albertel 7590: div.LC_feedback_link {
1.616 albertel 7591: clear: both;
1.829 kalberla 7592: background: $sidebg;
1.779 bisitz 7593: width: 100%;
1.829 kalberla 7594: padding-bottom: 10px;
7595: border: 1px $tabbg solid;
1.833 kalberla 7596: height: 22px;
7597: line-height: 22px;
7598: padding-top: 5px;
7599: }
7600:
7601: div.LC_feedback_link img {
7602: height: 22px;
1.867 kalberla 7603: vertical-align:middle;
1.829 kalberla 7604: }
7605:
1.911 bisitz 7606: div.LC_feedback_link a {
1.829 kalberla 7607: text-decoration: none;
1.489 raeburn 7608: }
1.795 www 7609:
1.867 kalberla 7610: div.LC_comblock {
1.911 bisitz 7611: display:inline;
1.867 kalberla 7612: color:$font;
7613: font-size:90%;
7614: }
7615:
7616: div.LC_feedback_link div.LC_comblock {
7617: padding-left:5px;
7618: }
7619:
7620: div.LC_feedback_link div.LC_comblock a {
7621: color:$font;
7622: }
7623:
1.489 raeburn 7624: span.LC_feedback_link {
1.858 bisitz 7625: /* background: $feedback_link_bg; */
1.599 albertel 7626: font-size: larger;
7627: }
1.795 www 7628:
1.599 albertel 7629: span.LC_message_link {
1.858 bisitz 7630: /* background: $feedback_link_bg; */
1.599 albertel 7631: font-size: larger;
7632: position: absolute;
7633: right: 1em;
1.489 raeburn 7634: }
1.421 albertel 7635:
1.515 albertel 7636: table.LC_prior_tries {
1.524 albertel 7637: border: 1px solid #000000;
7638: border-collapse: separate;
7639: border-spacing: 1px;
1.515 albertel 7640: }
1.523 albertel 7641:
1.515 albertel 7642: table.LC_prior_tries td {
1.524 albertel 7643: padding: 2px;
1.515 albertel 7644: }
1.523 albertel 7645:
7646: .LC_answer_correct {
1.795 www 7647: background: lightgreen;
7648: color: darkgreen;
7649: padding: 6px;
1.523 albertel 7650: }
1.795 www 7651:
1.523 albertel 7652: .LC_answer_charged_try {
1.797 www 7653: background: #FFAAAA;
1.795 www 7654: color: darkred;
7655: padding: 6px;
1.523 albertel 7656: }
1.795 www 7657:
1.779 bisitz 7658: .LC_answer_not_charged_try,
1.523 albertel 7659: .LC_answer_no_grade,
7660: .LC_answer_late {
1.795 www 7661: background: lightyellow;
1.523 albertel 7662: color: black;
1.795 www 7663: padding: 6px;
1.523 albertel 7664: }
1.795 www 7665:
1.523 albertel 7666: .LC_answer_previous {
1.795 www 7667: background: lightblue;
7668: color: darkblue;
7669: padding: 6px;
1.523 albertel 7670: }
1.795 www 7671:
1.779 bisitz 7672: .LC_answer_no_message {
1.777 tempelho 7673: background: #FFFFFF;
7674: color: black;
1.795 www 7675: padding: 6px;
1.779 bisitz 7676: }
1.795 www 7677:
1.1075.2.140 raeburn 7678: .LC_answer_unknown,
7679: .LC_answer_warning {
1.779 bisitz 7680: background: orange;
7681: color: black;
1.795 www 7682: padding: 6px;
1.777 tempelho 7683: }
1.795 www 7684:
1.529 albertel 7685: span.LC_prior_numerical,
7686: span.LC_prior_string,
7687: span.LC_prior_custom,
7688: span.LC_prior_reaction,
7689: span.LC_prior_math {
1.925 bisitz 7690: font-family: $mono;
1.523 albertel 7691: white-space: pre;
7692: }
7693:
1.525 albertel 7694: span.LC_prior_string {
1.925 bisitz 7695: font-family: $mono;
1.525 albertel 7696: white-space: pre;
7697: }
7698:
1.523 albertel 7699: table.LC_prior_option {
7700: width: 100%;
7701: border-collapse: collapse;
7702: }
1.795 www 7703:
1.911 bisitz 7704: table.LC_prior_rank,
1.795 www 7705: table.LC_prior_match {
1.528 albertel 7706: border-collapse: collapse;
7707: }
1.795 www 7708:
1.528 albertel 7709: table.LC_prior_option tr td,
7710: table.LC_prior_rank tr td,
7711: table.LC_prior_match tr td {
1.524 albertel 7712: border: 1px solid #000000;
1.515 albertel 7713: }
7714:
1.855 bisitz 7715: .LC_nobreak {
1.544 albertel 7716: white-space: nowrap;
1.519 raeburn 7717: }
7718:
1.576 raeburn 7719: span.LC_cusr_emph {
7720: font-style: italic;
7721: }
7722:
1.633 raeburn 7723: span.LC_cusr_subheading {
7724: font-weight: normal;
7725: font-size: 85%;
7726: }
7727:
1.861 bisitz 7728: div.LC_docs_entry_move {
1.859 bisitz 7729: border: 1px solid #BBBBBB;
1.545 albertel 7730: background: #DDDDDD;
1.861 bisitz 7731: width: 22px;
1.859 bisitz 7732: padding: 1px;
7733: margin: 0;
1.545 albertel 7734: }
7735:
1.861 bisitz 7736: table.LC_data_table tr > td.LC_docs_entry_commands,
7737: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7738: font-size: x-small;
7739: }
1.795 www 7740:
1.861 bisitz 7741: .LC_docs_entry_parameter {
7742: white-space: nowrap;
7743: }
7744:
1.544 albertel 7745: .LC_docs_copy {
1.545 albertel 7746: color: #000099;
1.544 albertel 7747: }
1.795 www 7748:
1.544 albertel 7749: .LC_docs_cut {
1.545 albertel 7750: color: #550044;
1.544 albertel 7751: }
1.795 www 7752:
1.544 albertel 7753: .LC_docs_rename {
1.545 albertel 7754: color: #009900;
1.544 albertel 7755: }
1.795 www 7756:
1.544 albertel 7757: .LC_docs_remove {
1.545 albertel 7758: color: #990000;
7759: }
7760:
1.1075.2.134 raeburn 7761: .LC_domprefs_email,
1.547 albertel 7762: .LC_docs_reinit_warn,
7763: .LC_docs_ext_edit {
7764: font-size: x-small;
7765: }
7766:
1.545 albertel 7767: table.LC_docs_adddocs td,
7768: table.LC_docs_adddocs th {
7769: border: 1px solid #BBBBBB;
7770: padding: 4px;
7771: background: #DDDDDD;
1.543 albertel 7772: }
7773:
1.584 albertel 7774: table.LC_sty_begin {
7775: background: #BBFFBB;
7776: }
1.795 www 7777:
1.584 albertel 7778: table.LC_sty_end {
7779: background: #FFBBBB;
7780: }
7781:
1.589 raeburn 7782: table.LC_double_column {
1.803 bisitz 7783: border-width: 0;
1.589 raeburn 7784: border-collapse: collapse;
7785: width: 100%;
7786: padding: 2px;
7787: }
7788:
7789: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7790: top: 2px;
1.589 raeburn 7791: left: 2px;
7792: width: 47%;
7793: vertical-align: top;
7794: }
7795:
7796: table.LC_double_column tr td.LC_right_col {
7797: top: 2px;
1.779 bisitz 7798: right: 2px;
1.589 raeburn 7799: width: 47%;
7800: vertical-align: top;
7801: }
7802:
1.591 raeburn 7803: div.LC_left_float {
7804: float: left;
7805: padding-right: 5%;
1.597 albertel 7806: padding-bottom: 4px;
1.591 raeburn 7807: }
7808:
7809: div.LC_clear_float_header {
1.597 albertel 7810: padding-bottom: 2px;
1.591 raeburn 7811: }
7812:
7813: div.LC_clear_float_footer {
1.597 albertel 7814: padding-top: 10px;
1.591 raeburn 7815: clear: both;
7816: }
7817:
1.597 albertel 7818: div.LC_grade_show_user {
1.941 bisitz 7819: /* border-left: 5px solid $sidebg; */
7820: border-top: 5px solid #000000;
7821: margin: 50px 0 0 0;
1.936 bisitz 7822: padding: 15px 0 5px 10px;
1.597 albertel 7823: }
1.795 www 7824:
1.936 bisitz 7825: div.LC_grade_show_user_odd_row {
1.941 bisitz 7826: /* border-left: 5px solid #000000; */
7827: }
7828:
7829: div.LC_grade_show_user div.LC_Box {
7830: margin-right: 50px;
1.597 albertel 7831: }
7832:
7833: div.LC_grade_submissions,
7834: div.LC_grade_message_center,
1.936 bisitz 7835: div.LC_grade_info_links {
1.597 albertel 7836: margin: 5px;
7837: width: 99%;
7838: background: #FFFFFF;
7839: }
1.795 www 7840:
1.597 albertel 7841: div.LC_grade_submissions_header,
1.936 bisitz 7842: div.LC_grade_message_center_header {
1.705 tempelho 7843: font-weight: bold;
7844: font-size: large;
1.597 albertel 7845: }
1.795 www 7846:
1.597 albertel 7847: div.LC_grade_submissions_body,
1.936 bisitz 7848: div.LC_grade_message_center_body {
1.597 albertel 7849: border: 1px solid black;
7850: width: 99%;
7851: background: #FFFFFF;
7852: }
1.795 www 7853:
1.613 albertel 7854: table.LC_scantron_action {
7855: width: 100%;
7856: }
1.795 www 7857:
1.613 albertel 7858: table.LC_scantron_action tr th {
1.698 harmsja 7859: font-weight:bold;
7860: font-style:normal;
1.613 albertel 7861: }
1.795 www 7862:
1.779 bisitz 7863: .LC_edit_problem_header,
1.614 albertel 7864: div.LC_edit_problem_footer {
1.705 tempelho 7865: font-weight: normal;
7866: font-size: medium;
1.602 albertel 7867: margin: 2px;
1.1060 bisitz 7868: background-color: $sidebg;
1.600 albertel 7869: }
1.795 www 7870:
1.600 albertel 7871: div.LC_edit_problem_header,
1.602 albertel 7872: div.LC_edit_problem_header div,
1.614 albertel 7873: div.LC_edit_problem_footer,
7874: div.LC_edit_problem_footer div,
1.602 albertel 7875: div.LC_edit_problem_editxml_header,
7876: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7877: z-index: 100;
1.600 albertel 7878: }
1.795 www 7879:
1.600 albertel 7880: div.LC_edit_problem_header_title {
1.705 tempelho 7881: font-weight: bold;
7882: font-size: larger;
1.602 albertel 7883: background: $tabbg;
7884: padding: 3px;
1.1060 bisitz 7885: margin: 0 0 5px 0;
1.602 albertel 7886: }
1.795 www 7887:
1.602 albertel 7888: table.LC_edit_problem_header_title {
7889: width: 100%;
1.600 albertel 7890: background: $tabbg;
1.602 albertel 7891: }
7892:
1.1075.2.112 raeburn 7893: div.LC_edit_actionbar {
7894: background-color: $sidebg;
7895: margin: 0;
7896: padding: 0;
7897: line-height: 200%;
1.602 albertel 7898: }
1.795 www 7899:
1.1075.2.112 raeburn 7900: div.LC_edit_actionbar div{
7901: padding: 0;
7902: margin: 0;
7903: display: inline-block;
1.600 albertel 7904: }
1.795 www 7905:
1.1075.2.34 raeburn 7906: .LC_edit_opt {
7907: padding-left: 1em;
7908: white-space: nowrap;
7909: }
7910:
1.1075.2.57 raeburn 7911: .LC_edit_problem_latexhelper{
7912: text-align: right;
7913: }
7914:
7915: #LC_edit_problem_colorful div{
7916: margin-left: 40px;
7917: }
7918:
1.1075.2.112 raeburn 7919: #LC_edit_problem_codemirror div{
7920: margin-left: 0px;
7921: }
7922:
1.911 bisitz 7923: img.stift {
1.803 bisitz 7924: border-width: 0;
7925: vertical-align: middle;
1.677 riegler 7926: }
1.680 riegler 7927:
1.923 bisitz 7928: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7929: vertical-align: top;
1.777 tempelho 7930: }
1.795 www 7931:
1.716 raeburn 7932: div.LC_createcourse {
1.911 bisitz 7933: margin: 10px 10px 10px 10px;
1.716 raeburn 7934: }
7935:
1.917 raeburn 7936: .LC_dccid {
1.1075.2.38 raeburn 7937: float: right;
1.917 raeburn 7938: margin: 0.2em 0 0 0;
7939: padding: 0;
7940: font-size: 90%;
7941: display:none;
7942: }
7943:
1.897 wenzelju 7944: ol.LC_primary_menu a:hover,
1.721 harmsja 7945: ol#LC_MenuBreadcrumbs a:hover,
7946: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7947: ul#LC_secondary_menu a:hover,
1.721 harmsja 7948: .LC_FormSectionClearButton input:hover
1.795 www 7949: ul.LC_TabContent li:hover a {
1.952 onken 7950: color:$button_hover;
1.911 bisitz 7951: text-decoration:none;
1.693 droeschl 7952: }
7953:
1.779 bisitz 7954: h1 {
1.911 bisitz 7955: padding: 0;
7956: line-height:130%;
1.693 droeschl 7957: }
1.698 harmsja 7958:
1.911 bisitz 7959: h2,
7960: h3,
7961: h4,
7962: h5,
7963: h6 {
7964: margin: 5px 0 5px 0;
7965: padding: 0;
7966: line-height:130%;
1.693 droeschl 7967: }
1.795 www 7968:
7969: .LC_hcell {
1.911 bisitz 7970: padding:3px 15px 3px 15px;
7971: margin: 0;
7972: background-color:$tabbg;
7973: color:$fontmenu;
7974: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7975: }
1.795 www 7976:
1.840 bisitz 7977: .LC_Box > .LC_hcell {
1.911 bisitz 7978: margin: 0 -10px 10px -10px;
1.835 bisitz 7979: }
7980:
1.721 harmsja 7981: .LC_noBorder {
1.911 bisitz 7982: border: 0;
1.698 harmsja 7983: }
1.693 droeschl 7984:
1.721 harmsja 7985: .LC_FormSectionClearButton input {
1.911 bisitz 7986: background-color:transparent;
7987: border: none;
7988: cursor:pointer;
7989: text-decoration:underline;
1.693 droeschl 7990: }
1.763 bisitz 7991:
7992: .LC_help_open_topic {
1.911 bisitz 7993: color: #FFFFFF;
7994: background-color: #EEEEFF;
7995: margin: 1px;
7996: padding: 4px;
7997: border: 1px solid #000033;
7998: white-space: nowrap;
7999: /* vertical-align: middle; */
1.759 neumanie 8000: }
1.693 droeschl 8001:
1.911 bisitz 8002: dl,
8003: ul,
8004: div,
8005: fieldset {
8006: margin: 10px 10px 10px 0;
8007: /* overflow: hidden; */
1.693 droeschl 8008: }
1.795 www 8009:
1.1075.2.161. .18(raeb 8010:-23): fieldset#LC_selectuser {
8011:-23): margin: 0;
8012:-23): padding: 0;
8013:-23): }
8014:-23):
1.1075.2.90 raeburn 8015: article.geogebraweb div {
8016: margin: 0;
8017: }
8018:
1.838 bisitz 8019: fieldset > legend {
1.911 bisitz 8020: font-weight: bold;
8021: padding: 0 5px 0 5px;
1.838 bisitz 8022: }
8023:
1.813 bisitz 8024: #LC_nav_bar {
1.911 bisitz 8025: float: left;
1.995 raeburn 8026: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8027: margin: 0 0 2px 0;
1.807 droeschl 8028: }
8029:
1.916 droeschl 8030: #LC_realm {
8031: margin: 0.2em 0 0 0;
8032: padding: 0;
8033: font-weight: bold;
8034: text-align: center;
1.995 raeburn 8035: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8036: }
8037:
1.911 bisitz 8038: #LC_nav_bar em {
8039: font-weight: bold;
8040: font-style: normal;
1.807 droeschl 8041: }
8042:
1.897 wenzelju 8043: ol.LC_primary_menu {
1.934 droeschl 8044: margin: 0;
1.1075.2.2 raeburn 8045: padding: 0;
1.807 droeschl 8046: }
8047:
1.852 droeschl 8048: ol#LC_PathBreadcrumbs {
1.911 bisitz 8049: margin: 0;
1.693 droeschl 8050: }
8051:
1.897 wenzelju 8052: ol.LC_primary_menu li {
1.1075.2.2 raeburn 8053: color: RGB(80, 80, 80);
8054: vertical-align: middle;
8055: text-align: left;
8056: list-style: none;
1.1075.2.112 raeburn 8057: position: relative;
1.1075.2.2 raeburn 8058: float: left;
1.1075.2.112 raeburn 8059: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8060: line-height: 1.5em;
1.1075.2.2 raeburn 8061: }
8062:
1.1075.2.113 raeburn 8063: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 8064: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 8065: display: block;
8066: margin: 0;
8067: padding: 0 5px 0 10px;
8068: text-decoration: none;
8069: }
8070:
1.1075.2.112 raeburn 8071: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8072: display: inline-block;
8073: width: 95%;
8074: text-align: left;
8075: }
8076:
8077: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8078: display: inline-block;
8079: width: 5%;
8080: float: right;
8081: text-align: right;
8082: font-size: 70%;
8083: }
8084:
8085: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 8086: display: none;
1.1075.2.112 raeburn 8087: width: 15em;
1.1075.2.2 raeburn 8088: background-color: $data_table_light;
1.1075.2.112 raeburn 8089: position: absolute;
8090: top: 100%;
8091: }
8092:
8093: ol.LC_primary_menu ul ul {
8094: left: 100%;
8095: top: 0;
1.1075.2.2 raeburn 8096: }
8097:
1.1075.2.112 raeburn 8098: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 8099: display: block;
8100: position: absolute;
8101: margin: 0;
8102: padding: 0;
1.1075.2.5 raeburn 8103: z-index: 2;
1.1075.2.2 raeburn 8104: }
8105:
8106: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 8107: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 8108: font-size: 90%;
1.911 bisitz 8109: vertical-align: top;
1.1075.2.2 raeburn 8110: float: none;
1.1075.2.5 raeburn 8111: border-left: 1px solid black;
8112: border-right: 1px solid black;
1.1075.2.112 raeburn 8113: /* A dark bottom border to visualize different menu options;
8114: overwritten in the create_submenu routine for the last border-bottom of the menu */
8115: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 8116: }
8117:
1.1075.2.112 raeburn 8118: ol.LC_primary_menu li li p:hover {
8119: color:$button_hover;
8120: text-decoration:none;
8121: background-color:$data_table_dark;
1.1075.2.2 raeburn 8122: }
8123:
8124: ol.LC_primary_menu li li a:hover {
8125: color:$button_hover;
8126: background-color:$data_table_dark;
1.693 droeschl 8127: }
8128:
1.1075.2.112 raeburn 8129: /* Font-size equal to the size of the predecessors*/
8130: ol.LC_primary_menu li:hover li li {
8131: font-size: 100%;
8132: }
8133:
1.897 wenzelju 8134: ol.LC_primary_menu li img {
1.911 bisitz 8135: vertical-align: bottom;
1.934 droeschl 8136: height: 1.1em;
1.1075.2.3 raeburn 8137: margin: 0.2em 0 0 0;
1.693 droeschl 8138: }
8139:
1.897 wenzelju 8140: ol.LC_primary_menu a {
1.911 bisitz 8141: color: RGB(80, 80, 80);
8142: text-decoration: none;
1.693 droeschl 8143: }
1.795 www 8144:
1.949 droeschl 8145: ol.LC_primary_menu a.LC_new_message {
8146: font-weight:bold;
8147: color: darkred;
8148: }
8149:
1.975 raeburn 8150: ol.LC_docs_parameters {
8151: margin-left: 0;
8152: padding: 0;
8153: list-style: none;
8154: }
8155:
8156: ol.LC_docs_parameters li {
8157: margin: 0;
8158: padding-right: 20px;
8159: display: inline;
8160: }
8161:
1.976 raeburn 8162: ol.LC_docs_parameters li:before {
8163: content: "\\002022 \\0020";
8164: }
8165:
8166: li.LC_docs_parameters_title {
8167: font-weight: bold;
8168: }
8169:
8170: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8171: content: "";
8172: }
8173:
1.897 wenzelju 8174: ul#LC_secondary_menu {
1.1075.2.23 raeburn 8175: clear: right;
1.911 bisitz 8176: color: $fontmenu;
8177: background: $tabbg;
8178: list-style: none;
8179: padding: 0;
8180: margin: 0;
8181: width: 100%;
1.995 raeburn 8182: text-align: left;
1.1075.2.4 raeburn 8183: float: left;
1.808 droeschl 8184: }
8185:
1.897 wenzelju 8186: ul#LC_secondary_menu li {
1.911 bisitz 8187: font-weight: bold;
8188: line-height: 1.8em;
8189: border-right: 1px solid black;
1.1075.2.4 raeburn 8190: float: left;
8191: }
8192:
8193: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8194: background-color: $data_table_light;
8195: }
8196:
8197: ul#LC_secondary_menu li a {
8198: padding: 0 0.8em;
8199: }
8200:
8201: ul#LC_secondary_menu li ul {
8202: display: none;
8203: }
8204:
8205: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8206: display: block;
8207: position: absolute;
8208: margin: 0;
8209: padding: 0;
8210: list-style:none;
8211: float: none;
8212: background-color: $data_table_light;
1.1075.2.5 raeburn 8213: z-index: 2;
1.1075.2.10 raeburn 8214: margin-left: -1px;
1.1075.2.4 raeburn 8215: }
8216:
8217: ul#LC_secondary_menu li ul li {
8218: font-size: 90%;
8219: vertical-align: top;
8220: border-left: 1px solid black;
8221: border-right: 1px solid black;
1.1075.2.33 raeburn 8222: background-color: $data_table_light;
1.1075.2.4 raeburn 8223: list-style:none;
8224: float: none;
8225: }
8226:
8227: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8228: background-color: $data_table_dark;
1.807 droeschl 8229: }
8230:
1.847 tempelho 8231: ul.LC_TabContent {
1.911 bisitz 8232: display:block;
8233: background: $sidebg;
8234: border-bottom: solid 1px $lg_border_color;
8235: list-style:none;
1.1020 raeburn 8236: margin: -1px -10px 0 -10px;
1.911 bisitz 8237: padding: 0;
1.693 droeschl 8238: }
8239:
1.795 www 8240: ul.LC_TabContent li,
8241: ul.LC_TabContentBigger li {
1.911 bisitz 8242: float:left;
1.741 harmsja 8243: }
1.795 www 8244:
1.897 wenzelju 8245: ul#LC_secondary_menu li a {
1.911 bisitz 8246: color: $fontmenu;
8247: text-decoration: none;
1.693 droeschl 8248: }
1.795 www 8249:
1.721 harmsja 8250: ul.LC_TabContent {
1.952 onken 8251: min-height:20px;
1.721 harmsja 8252: }
1.795 www 8253:
8254: ul.LC_TabContent li {
1.911 bisitz 8255: vertical-align:middle;
1.959 onken 8256: padding: 0 16px 0 10px;
1.911 bisitz 8257: background-color:$tabbg;
8258: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8259: border-left: solid 1px $font;
1.721 harmsja 8260: }
1.795 www 8261:
1.847 tempelho 8262: ul.LC_TabContent .right {
1.911 bisitz 8263: float:right;
1.847 tempelho 8264: }
8265:
1.911 bisitz 8266: ul.LC_TabContent li a,
8267: ul.LC_TabContent li {
8268: color:rgb(47,47,47);
8269: text-decoration:none;
8270: font-size:95%;
8271: font-weight:bold;
1.952 onken 8272: min-height:20px;
8273: }
8274:
1.959 onken 8275: ul.LC_TabContent li a:hover,
8276: ul.LC_TabContent li a:focus {
1.952 onken 8277: color: $button_hover;
1.959 onken 8278: background:none;
8279: outline:none;
1.952 onken 8280: }
8281:
8282: ul.LC_TabContent li:hover {
8283: color: $button_hover;
8284: cursor:pointer;
1.721 harmsja 8285: }
1.795 www 8286:
1.911 bisitz 8287: ul.LC_TabContent li.active {
1.952 onken 8288: color: $font;
1.911 bisitz 8289: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8290: border-bottom:solid 1px #FFFFFF;
8291: cursor: default;
1.744 ehlerst 8292: }
1.795 www 8293:
1.959 onken 8294: ul.LC_TabContent li.active a {
8295: color:$font;
8296: background:#FFFFFF;
8297: outline: none;
8298: }
1.1047 raeburn 8299:
8300: ul.LC_TabContent li.goback {
8301: float: left;
8302: border-left: none;
8303: }
8304:
1.870 tempelho 8305: #maincoursedoc {
1.911 bisitz 8306: clear:both;
1.870 tempelho 8307: }
8308:
8309: ul.LC_TabContentBigger {
1.911 bisitz 8310: display:block;
8311: list-style:none;
8312: padding: 0;
1.870 tempelho 8313: }
8314:
1.795 www 8315: ul.LC_TabContentBigger li {
1.911 bisitz 8316: vertical-align:bottom;
8317: height: 30px;
8318: font-size:110%;
8319: font-weight:bold;
8320: color: #737373;
1.841 tempelho 8321: }
8322:
1.957 onken 8323: ul.LC_TabContentBigger li.active {
8324: position: relative;
8325: top: 1px;
8326: }
8327:
1.870 tempelho 8328: ul.LC_TabContentBigger li a {
1.911 bisitz 8329: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8330: height: 30px;
8331: line-height: 30px;
8332: text-align: center;
8333: display: block;
8334: text-decoration: none;
1.958 onken 8335: outline: none;
1.741 harmsja 8336: }
1.795 www 8337:
1.870 tempelho 8338: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8339: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8340: color:$font;
1.744 ehlerst 8341: }
1.795 www 8342:
1.870 tempelho 8343: ul.LC_TabContentBigger li b {
1.911 bisitz 8344: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8345: display: block;
8346: float: left;
8347: padding: 0 30px;
1.957 onken 8348: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8349: }
8350:
1.956 onken 8351: ul.LC_TabContentBigger li:hover b {
8352: color:$button_hover;
8353: }
8354:
1.870 tempelho 8355: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8356: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8357: color:$font;
1.957 onken 8358: border: 0;
1.741 harmsja 8359: }
1.693 droeschl 8360:
1.870 tempelho 8361:
1.862 bisitz 8362: ul.LC_CourseBreadcrumbs {
8363: background: $sidebg;
1.1020 raeburn 8364: height: 2em;
1.862 bisitz 8365: padding-left: 10px;
1.1020 raeburn 8366: margin: 0;
1.862 bisitz 8367: list-style-position: inside;
8368: }
8369:
1.911 bisitz 8370: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8371: ol#LC_PathBreadcrumbs {
1.911 bisitz 8372: padding-left: 10px;
8373: margin: 0;
1.933 droeschl 8374: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8375: }
8376:
1.911 bisitz 8377: ol#LC_MenuBreadcrumbs li,
8378: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8379: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8380: display: inline;
1.933 droeschl 8381: white-space: normal;
1.693 droeschl 8382: }
8383:
1.823 bisitz 8384: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8385: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8386: text-decoration: none;
8387: font-size:90%;
1.693 droeschl 8388: }
1.795 www 8389:
1.969 droeschl 8390: ol#LC_MenuBreadcrumbs h1 {
8391: display: inline;
8392: font-size: 90%;
8393: line-height: 2.5em;
8394: margin: 0;
8395: padding: 0;
8396: }
8397:
1.795 www 8398: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8399: text-decoration:none;
8400: font-size:100%;
8401: font-weight:bold;
1.693 droeschl 8402: }
1.795 www 8403:
1.840 bisitz 8404: .LC_Box {
1.911 bisitz 8405: border: solid 1px $lg_border_color;
8406: padding: 0 10px 10px 10px;
1.746 neumanie 8407: }
1.795 www 8408:
1.1020 raeburn 8409: .LC_DocsBox {
8410: border: solid 1px $lg_border_color;
8411: padding: 0 0 10px 10px;
8412: }
8413:
1.795 www 8414: .LC_AboutMe_Image {
1.911 bisitz 8415: float:left;
8416: margin-right:10px;
1.747 neumanie 8417: }
1.795 www 8418:
8419: .LC_Clear_AboutMe_Image {
1.911 bisitz 8420: clear:left;
1.747 neumanie 8421: }
1.795 www 8422:
1.721 harmsja 8423: dl.LC_ListStyleClean dt {
1.911 bisitz 8424: padding-right: 5px;
8425: display: table-header-group;
1.693 droeschl 8426: }
8427:
1.721 harmsja 8428: dl.LC_ListStyleClean dd {
1.911 bisitz 8429: display: table-row;
1.693 droeschl 8430: }
8431:
1.721 harmsja 8432: .LC_ListStyleClean,
8433: .LC_ListStyleSimple,
8434: .LC_ListStyleNormal,
1.795 www 8435: .LC_ListStyleSpecial {
1.911 bisitz 8436: /* display:block; */
8437: list-style-position: inside;
8438: list-style-type: none;
8439: overflow: hidden;
8440: padding: 0;
1.693 droeschl 8441: }
8442:
1.721 harmsja 8443: .LC_ListStyleSimple li,
8444: .LC_ListStyleSimple dd,
8445: .LC_ListStyleNormal li,
8446: .LC_ListStyleNormal dd,
8447: .LC_ListStyleSpecial li,
1.795 www 8448: .LC_ListStyleSpecial dd {
1.911 bisitz 8449: margin: 0;
8450: padding: 5px 5px 5px 10px;
8451: clear: both;
1.693 droeschl 8452: }
8453:
1.721 harmsja 8454: .LC_ListStyleClean li,
8455: .LC_ListStyleClean dd {
1.911 bisitz 8456: padding-top: 0;
8457: padding-bottom: 0;
1.693 droeschl 8458: }
8459:
1.721 harmsja 8460: .LC_ListStyleSimple dd,
1.795 www 8461: .LC_ListStyleSimple li {
1.911 bisitz 8462: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8463: }
8464:
1.721 harmsja 8465: .LC_ListStyleSpecial li,
8466: .LC_ListStyleSpecial dd {
1.911 bisitz 8467: list-style-type: none;
8468: background-color: RGB(220, 220, 220);
8469: margin-bottom: 4px;
1.693 droeschl 8470: }
8471:
1.721 harmsja 8472: table.LC_SimpleTable {
1.911 bisitz 8473: margin:5px;
8474: border:solid 1px $lg_border_color;
1.795 www 8475: }
1.693 droeschl 8476:
1.721 harmsja 8477: table.LC_SimpleTable tr {
1.911 bisitz 8478: padding: 0;
8479: border:solid 1px $lg_border_color;
1.693 droeschl 8480: }
1.795 www 8481:
8482: table.LC_SimpleTable thead {
1.911 bisitz 8483: background:rgb(220,220,220);
1.693 droeschl 8484: }
8485:
1.721 harmsja 8486: div.LC_columnSection {
1.911 bisitz 8487: display: block;
8488: clear: both;
8489: overflow: hidden;
8490: margin: 0;
1.693 droeschl 8491: }
8492:
1.721 harmsja 8493: div.LC_columnSection>* {
1.911 bisitz 8494: float: left;
8495: margin: 10px 20px 10px 0;
8496: overflow:hidden;
1.693 droeschl 8497: }
1.721 harmsja 8498:
1.795 www 8499: table em {
1.911 bisitz 8500: font-weight: bold;
8501: font-style: normal;
1.748 schulted 8502: }
1.795 www 8503:
1.779 bisitz 8504: table.LC_tableBrowseRes,
1.795 www 8505: table.LC_tableOfContent {
1.911 bisitz 8506: border:none;
8507: border-spacing: 1px;
8508: padding: 3px;
8509: background-color: #FFFFFF;
8510: font-size: 90%;
1.753 droeschl 8511: }
1.789 droeschl 8512:
1.911 bisitz 8513: table.LC_tableOfContent {
8514: border-collapse: collapse;
1.789 droeschl 8515: }
8516:
1.771 droeschl 8517: table.LC_tableBrowseRes a,
1.768 schulted 8518: table.LC_tableOfContent a {
1.911 bisitz 8519: background-color: transparent;
8520: text-decoration: none;
1.753 droeschl 8521: }
8522:
1.795 www 8523: table.LC_tableOfContent img {
1.911 bisitz 8524: border: none;
8525: height: 1.3em;
8526: vertical-align: text-bottom;
8527: margin-right: 0.3em;
1.753 droeschl 8528: }
1.757 schulted 8529:
1.795 www 8530: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8531: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8532: }
8533:
1.795 www 8534: a#LC_content_toolbar_everything {
1.911 bisitz 8535: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8536: }
8537:
1.795 www 8538: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8539: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8540: }
8541:
1.795 www 8542: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8543: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8544: }
8545:
1.795 www 8546: a#LC_content_toolbar_changefolder {
1.911 bisitz 8547: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8548: }
8549:
1.795 www 8550: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8551: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8552: }
8553:
1.1043 raeburn 8554: a#LC_content_toolbar_edittoplevel {
8555: background-image:url(/res/adm/pages/edittoplevel.gif);
8556: }
8557:
1.1075.2.161. .12(raeb 8558:-23): a#LC_content_toolbar_printout {
8559:-23): background-image:url(/res/adm/pages/printout.gif);
8560:-23): }
8561:-23):
1.795 www 8562: ul#LC_toolbar li a:hover {
1.911 bisitz 8563: background-position: bottom center;
1.757 schulted 8564: }
8565:
1.795 www 8566: ul#LC_toolbar {
1.911 bisitz 8567: padding: 0;
8568: margin: 2px;
8569: list-style:none;
8570: position:relative;
8571: background-color:white;
1.1075.2.9 raeburn 8572: overflow: auto;
1.757 schulted 8573: }
8574:
1.795 www 8575: ul#LC_toolbar li {
1.911 bisitz 8576: border:1px solid white;
8577: padding: 0;
8578: margin: 0;
8579: float: left;
8580: display:inline;
8581: vertical-align:middle;
1.1075.2.9 raeburn 8582: white-space: nowrap;
1.911 bisitz 8583: }
1.757 schulted 8584:
1.783 amueller 8585:
1.795 www 8586: a.LC_toolbarItem {
1.911 bisitz 8587: display:block;
8588: padding: 0;
8589: margin: 0;
8590: height: 32px;
8591: width: 32px;
8592: color:white;
8593: border: none;
8594: background-repeat:no-repeat;
8595: background-color:transparent;
1.757 schulted 8596: }
8597:
1.915 droeschl 8598: ul.LC_funclist {
8599: margin: 0;
8600: padding: 0.5em 1em 0.5em 0;
8601: }
8602:
1.933 droeschl 8603: ul.LC_funclist > li:first-child {
8604: font-weight:bold;
8605: margin-left:0.8em;
8606: }
8607:
1.915 droeschl 8608: ul.LC_funclist + ul.LC_funclist {
8609: /*
8610: left border as a seperator if we have more than
8611: one list
8612: */
8613: border-left: 1px solid $sidebg;
8614: /*
8615: this hides the left border behind the border of the
8616: outer box if element is wrapped to the next 'line'
8617: */
8618: margin-left: -1px;
8619: }
8620:
1.843 bisitz 8621: ul.LC_funclist li {
1.915 droeschl 8622: display: inline;
1.782 bisitz 8623: white-space: nowrap;
1.915 droeschl 8624: margin: 0 0 0 25px;
8625: line-height: 150%;
1.782 bisitz 8626: }
8627:
1.974 wenzelju 8628: .LC_hidden {
8629: display: none;
8630: }
8631:
1.1030 www 8632: .LCmodal-overlay {
8633: position:fixed;
8634: top:0;
8635: right:0;
8636: bottom:0;
8637: left:0;
8638: height:100%;
8639: width:100%;
8640: margin:0;
8641: padding:0;
8642: background:#999;
8643: opacity:.75;
8644: filter: alpha(opacity=75);
8645: -moz-opacity: 0.75;
8646: z-index:101;
8647: }
8648:
8649: * html .LCmodal-overlay {
8650: position: absolute;
8651: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8652: }
8653:
8654: .LCmodal-window {
8655: position:fixed;
8656: top:50%;
8657: left:50%;
8658: margin:0;
8659: padding:0;
8660: z-index:102;
8661: }
8662:
8663: * html .LCmodal-window {
8664: position:absolute;
8665: }
8666:
8667: .LCclose-window {
8668: position:absolute;
8669: width:32px;
8670: height:32px;
8671: right:8px;
8672: top:8px;
8673: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8674: text-indent:-99999px;
8675: overflow:hidden;
8676: cursor:pointer;
8677: }
8678:
1.1075.2.158 raeburn 8679: .LCisDisabled {
8680: cursor: not-allowed;
8681: opacity: 0.5;
8682: }
8683:
8684: a[aria-disabled="true"] {
8685: color: currentColor;
8686: display: inline-block; /* For IE11/ MS Edge bug */
8687: pointer-events: none;
8688: text-decoration: none;
8689: }
8690:
1.1075.2.141 raeburn 8691: pre.LC_wordwrap {
8692: white-space: pre-wrap;
8693: white-space: -moz-pre-wrap;
8694: white-space: -pre-wrap;
8695: white-space: -o-pre-wrap;
8696: word-wrap: break-word;
8697: }
8698:
1.1075.2.17 raeburn 8699: /*
1.1075.2.161. .21(raeb 8700:-24): styles used for response display
8701:-24): */
8702:-24): div.LC_radiofoil, div.LC_rankfoil {
8703:-24): margin: .5em 0em .5em 0em;
8704:-24): }
8705:-24): table.LC_itemgroup {
8706:-24): margin-top: 1em;
8707:-24): }
8708:-24):
8709:-24): /*
1.1075.2.17 raeburn 8710: styles used by TTH when "Default set of options to pass to tth/m
8711: when converting TeX" in course settings has been set
8712:
8713: option passed: -t
8714:
8715: */
8716:
8717: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8718: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8719: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8720: td div.norm {line-height:normal;}
8721:
8722: /*
8723: option passed -y3
8724: */
8725:
8726: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8727: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8728: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8729:
1.1075.2.161. .21(raeb 8730:-24): /*
8731:-24): sections with roles, for content only
8732:-24): */
8733:-24): section[class^="role-"] {
8734:-24): padding-left: 10px;
8735:-24): padding-right: 5px;
8736:-24): margin-top: 8px;
8737:-24): margin-bottom: 8px;
8738:-24): border: 1px solid #2A4;
8739:-24): border-radius: 5px;
8740:-24): box-shadow: 0px 1px 1px #BBB;
8741:-24): }
8742:-24): section[class^="role-"]>h1 {
8743:-24): position: relative;
8744:-24): margin: 0px;
8745:-24): padding-top: 10px;
8746:-24): padding-left: 40px;
8747:-24): }
8748:-24): section[class^="role-"]>h1:before {
8749:-24): position: absolute;
8750:-24): left: -5px;
8751:-24): top: 5px;
8752:-24): }
8753:-24): section.role-activity>h1:before {
8754:-24): content:url('/adm/daxe/images/section_icons/activity.png');
8755:-24): }
8756:-24): section.role-advice>h1:before {
8757:-24): content:url('/adm/daxe/images/section_icons/advice.png');
8758:-24): }
8759:-24): section.role-bibliography>h1:before {
8760:-24): content:url('/adm/daxe/images/section_icons/bibliography.png');
8761:-24): }
8762:-24): section.role-citation>h1:before {
8763:-24): content:url('/adm/daxe/images/section_icons/citation.png');
8764:-24): }
8765:-24): section.role-conclusion>h1:before {
8766:-24): content:url('/adm/daxe/images/section_icons/conclusion.png');
8767:-24): }
8768:-24): section.role-definition>h1:before {
8769:-24): content:url('/adm/daxe/images/section_icons/definition.png');
8770:-24): }
8771:-24): section.role-demonstration>h1:before {
8772:-24): content:url('/adm/daxe/images/section_icons/demonstration.png');
8773:-24): }
8774:-24): section.role-example>h1:before {
8775:-24): content:url('/adm/daxe/images/section_icons/example.png');
8776:-24): }
8777:-24): section.role-explanation>h1:before {
8778:-24): content:url('/adm/daxe/images/section_icons/explanation.png');
8779:-24): }
8780:-24): section.role-introduction>h1:before {
8781:-24): content:url('/adm/daxe/images/section_icons/introduction.png');
8782:-24): }
8783:-24): section.role-method>h1:before {
8784:-24): content:url('/adm/daxe/images/section_icons/method.png');
8785:-24): }
8786:-24): section.role-more_information>h1:before {
8787:-24): content:url('/adm/daxe/images/section_icons/more_information.png');
8788:-24): }
8789:-24): section.role-objectives>h1:before {
8790:-24): content:url('/adm/daxe/images/section_icons/objectives.png');
8791:-24): }
8792:-24): section.role-prerequisites>h1:before {
8793:-24): content:url('/adm/daxe/images/section_icons/prerequisites.png');
8794:-24): }
8795:-24): section.role-remark>h1:before {
8796:-24): content:url('/adm/daxe/images/section_icons/remark.png');
8797:-24): }
8798:-24): section.role-reminder>h1:before {
8799:-24): content:url('/adm/daxe/images/section_icons/reminder.png');
8800:-24): }
8801:-24): section.role-summary>h1:before {
8802:-24): content:url('/adm/daxe/images/section_icons/summary.png');
8803:-24): }
8804:-24): section.role-syntax>h1:before {
8805:-24): content:url('/adm/daxe/images/section_icons/syntax.png');
8806:-24): }
8807:-24): section.role-warning>h1:before {
8808:-24): content:url('/adm/daxe/images/section_icons/warning.png');
8809:-24): }
8810:-24):
1.1075.2.121 raeburn 8811: #LC_minitab_header {
8812: float:left;
8813: width:100%;
8814: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8815: font-size:93%;
8816: line-height:normal;
8817: margin: 0.5em 0 0.5em 0;
8818: }
8819: #LC_minitab_header ul {
8820: margin:0;
8821: padding:10px 10px 0;
8822: list-style:none;
8823: }
8824: #LC_minitab_header li {
8825: float:left;
8826: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8827: margin:0;
8828: padding:0 0 0 9px;
8829: }
8830: #LC_minitab_header a {
8831: display:block;
8832: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8833: padding:5px 15px 4px 6px;
8834: }
8835: #LC_minitab_header #LC_current_minitab {
8836: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8837: }
8838: #LC_minitab_header #LC_current_minitab a {
8839: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8840: padding-bottom:5px;
8841: }
8842:
8843:
1.343 albertel 8844: END
8845: }
8846:
1.306 albertel 8847: =pod
8848:
8849: =item * &headtag()
8850:
8851: Returns a uniform footer for LON-CAPA web pages.
8852:
1.307 albertel 8853: Inputs: $title - optional title for the head
8854: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8855: $args - optional arguments
1.319 albertel 8856: force_register - if is true call registerurl so the remote is
8857: informed
1.415 albertel 8858: redirect -> array ref of
8859: 1- seconds before redirect occurs
8860: 2- url to redirect to
8861: 3- whether the side effect should occur
1.315 albertel 8862: (side effect of setting
8863: $env{'internal.head.redirect'} to the url
1.1075.2.161. .9(raebu 8864:22): redirected to)
8865:22): 4- whether the redirect target should be
8866:22): the opener of the current (pop-up)
8867:22): window (side effect of setting
8868:22): $env{'internal.head.to_opener'} to
8869:22): 1, if true.
.10(raeb 8870:-22): 5- whether encrypt check should be skipped
1.352 albertel 8871: domain -> force to color decorate a page for a specific
8872: domain
8873: function -> force usage of a specific rolish color scheme
8874: bgcolor -> override the default page bgcolor
1.460 albertel 8875: no_auto_mt_title
8876: -> prevent &mt()ing the title arg
1.464 albertel 8877:
1.306 albertel 8878: =cut
8879:
8880: sub headtag {
1.313 albertel 8881: my ($title,$head_extra,$args) = @_;
1.306 albertel 8882:
1.363 albertel 8883: my $function = $args->{'function'} || &get_users_function();
8884: my $domain = $args->{'domain'} || &determinedomain();
8885: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8886: my $httphost = $args->{'use_absolute'};
1.418 albertel 8887: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8888: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8889: #time(),
1.418 albertel 8890: $env{'environment.color.timestamp'},
1.363 albertel 8891: $function,$domain,$bgcolor);
8892:
1.369 www 8893: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8894:
1.308 albertel 8895: my $result =
8896: '<head>'.
1.1075.2.56 raeburn 8897: &font_settings($args);
1.319 albertel 8898:
1.1075.2.72 raeburn 8899: my $inhibitprint;
8900: if ($args->{'print_suppress'}) {
8901: $inhibitprint = &print_suppression();
8902: }
1.1064 raeburn 8903:
1.461 albertel 8904: if (!$args->{'frameset'}) {
8905: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8906: }
1.1075.2.12 raeburn 8907: if ($args->{'force_register'}) {
8908: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8909: }
1.436 albertel 8910: if (!$args->{'no_nav_bar'}
8911: && !$args->{'only_body'}
8912: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8913: $result .= &help_menu_js($httphost);
1.1032 www 8914: $result.=&modal_window();
1.1038 www 8915: $result.=&togglebox_script();
1.1034 www 8916: $result.=&wishlist_window();
1.1041 www 8917: $result.=&LCprogressbarUpdate_script();
1.1034 www 8918: } else {
8919: if ($args->{'add_modal'}) {
8920: $result.=&modal_window();
8921: }
8922: if ($args->{'add_wishlist'}) {
8923: $result.=&wishlist_window();
8924: }
1.1038 www 8925: if ($args->{'add_togglebox'}) {
8926: $result.=&togglebox_script();
8927: }
1.1041 www 8928: if ($args->{'add_progressbar'}) {
8929: $result.=&LCprogressbarUpdate_script();
8930: }
1.436 albertel 8931: }
1.314 albertel 8932: if (ref($args->{'redirect'})) {
1.1075.2.161. .10(raeb 8933:-22): my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
8934:-22): if (!$skip_enc_check) {
8935:-22): $url = &Apache::lonenc::check_encrypt($url);
8936:-22): }
1.414 albertel 8937: if (!$inhibit_continue) {
8938: $env{'internal.head.redirect'} = $url;
8939: }
1.1075.2.161. .9(raebu 8940:22): $result.=<<"ADDMETA";
1.313 albertel 8941: <meta http-equiv="pragma" content="no-cache" />
1.1075.2.161. .9(raebu 8942:22): ADDMETA
8943:22): if ($to_opener) {
8944:22): $env{'internal.head.to_opener'} = 1;
8945:22): my $dest = &js_escape($url);
8946:22): my $timeout = int($time * 1000);
8947:22): $result .=<<"ENDJS";
8948:22): <script type="text/javascript">
8949:22): // <![CDATA[
8950:22): function LC_To_Opener() {
8951:22): var dest = '$dest';
8952:22): if (dest != '') {
8953:22): if (window.opener != null && !window.opener.closed) {
8954:22): window.opener.location.href=dest;
8955:22): window.close();
8956:22): } else {
8957:22): window.location.href=dest;
8958:22): }
8959:22): }
8960:22): }
8961:22): \$(document).ready(function () {
8962:22): setTimeout('LC_To_Opener()',$timeout);
8963:22): });
8964:22): // ]]>
8965:22): </script>
8966:22): ENDJS
8967:22): } else {
8968:22): $result.=<<"ADDMETA";
1.344 albertel 8969: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8970: ADDMETA
1.1075.2.161. .9(raebu 8971:22): }
1.1075.2.89 raeburn 8972: } else {
8973: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8974: my $requrl = $env{'request.uri'};
8975: if ($requrl eq '') {
8976: $requrl = $ENV{'REQUEST_URI'};
8977: $requrl =~ s/\?.+$//;
8978: }
8979: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8980: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8981: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8982: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8983: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8984: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8985: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8986: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8987: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8988: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8989: $offload = 1;
1.1075.2.151 raeburn 8990: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8991: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8992: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8993: $offloadoth = 1;
8994: $dom_in_use = $env{'user.domain'};
8995: }
8996: }
1.1075.2.145 raeburn 8997: }
8998: }
8999: unless ($offload) {
9000: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9001: if ($domdefs{'offloadoth'}{$lonhost}) {
9002: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9003: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9004: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9005: $offload = 1;
1.1075.2.151 raeburn 9006: $offloadoth = 1;
1.1075.2.145 raeburn 9007: $dom_in_use = $env{'user.domain'};
9008: }
1.1075.2.89 raeburn 9009: }
1.1075.2.145 raeburn 9010: }
9011: }
9012: }
9013: if ($offload) {
1.1075.2.158 raeburn 9014: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 9015: if (($newserver eq '') && ($offloadoth)) {
9016: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 9017:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 9018: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9019: }
9020: }
1.1075.2.145 raeburn 9021: if (($newserver) && ($newserver ne $lonhost)) {
9022: my $numsec = 5;
9023: my $timeout = $numsec * 1000;
9024: my ($newurl,$locknum,%locks,$msg);
9025: if ($env{'request.role.adv'}) {
9026: ($locknum,%locks) = &Apache::lonnet::get_locks();
9027: }
9028: my $disable_submit = 0;
9029: if ($requrl =~ /$LONCAPA::assess_re/) {
9030: $disable_submit = 1;
9031: }
9032: if ($locknum) {
9033: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 9034: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 9035: join(", ",sort(values(%locks)))."\n";
9036: if (&show_course()) {
9037: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 9038: } else {
1.1075.2.145 raeburn 9039: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
9040: }
9041: } else {
9042: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9043: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9044: }
9045: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9046: $newurl = '/adm/switchserver?otherserver='.$newserver;
9047: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9048: $newurl .= '&role='.$env{'request.role'};
9049: }
9050: if ($env{'request.symb'}) {
9051: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9052: if ($shownsymb =~ m{^/enc/}) {
9053: my $reqdmajor = 2;
9054: my $reqdminor = 11;
9055: my $reqdsubminor = 3;
9056: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9057: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9058: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9059: if (($major eq '' && $minor eq '') ||
9060: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9061: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9062: ($reqdsubminor > $subminor))))) {
9063: undef($shownsymb);
9064: }
1.1075.2.89 raeburn 9065: }
1.1075.2.145 raeburn 9066: if ($shownsymb) {
9067: &js_escape(\$shownsymb);
9068: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 9069: }
1.1075.2.145 raeburn 9070: } else {
9071: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9072: &js_escape(\$shownurl);
9073: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 9074: }
1.1075.2.145 raeburn 9075: }
9076: &js_escape(\$msg);
9077: $result.=<<OFFLOAD
1.1075.2.89 raeburn 9078: <meta http-equiv="pragma" content="no-cache" />
9079: <script type="text/javascript">
1.1075.2.92 raeburn 9080: // <![CDATA[
1.1075.2.89 raeburn 9081: function LC_Offload_Now() {
9082: var dest = "$newurl";
9083: if (dest != '') {
9084: window.location.href="$newurl";
9085: }
9086: }
1.1075.2.92 raeburn 9087: \$(document).ready(function () {
9088: window.alert('$msg');
9089: if ($disable_submit) {
1.1075.2.89 raeburn 9090: \$(".LC_hwk_submit").prop("disabled", true);
9091: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 9092: }
9093: setTimeout('LC_Offload_Now()', $timeout);
9094: });
9095: // ]]>
1.1075.2.89 raeburn 9096: </script>
9097: OFFLOAD
9098: }
9099: }
9100: }
9101: }
9102: }
1.313 albertel 9103: }
1.306 albertel 9104: if (!defined($title)) {
9105: $title = 'The LearningOnline Network with CAPA';
9106: }
1.460 albertel 9107: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.161. .25(raeb 9108:-24): if ($title =~ /^LON-CAPA\s+/) {
9109:-24): $result .= '<title> '.$title.'</title>';
9110:-24): } else {
9111:-24): $result .= '<title> LON-CAPA '.$title.'</title>';
9112:-24): }
9113:-24): $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1075.2.61 raeburn 9114: if (!$args->{'frameset'}) {
9115: $result .= ' /';
9116: }
9117: $result .= '>'
1.1064 raeburn 9118: .$inhibitprint
1.414 albertel 9119: .$head_extra;
1.1075.2.108 raeburn 9120: my $clientmobile;
9121: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9122: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9123: } else {
9124: $clientmobile = $env{'browser.mobile'};
9125: }
9126: if ($clientmobile) {
1.1075.2.42 raeburn 9127: $result .= '
9128: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9129: <meta name="apple-mobile-web-app-capable" content="yes" />';
9130: }
1.1075.2.126 raeburn 9131: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9132: return $result.'</head>';
1.306 albertel 9133: }
9134:
9135: =pod
9136:
1.340 albertel 9137: =item * &font_settings()
9138:
9139: Returns neccessary <meta> to set the proper encoding
9140:
1.1075.2.56 raeburn 9141: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9142:
9143: =cut
9144:
9145: sub font_settings {
1.1075.2.56 raeburn 9146: my ($args) = @_;
1.340 albertel 9147: my $headerstring='';
1.1075.2.56 raeburn 9148: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9149: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 9150: $headerstring.=
1.1075.2.61 raeburn 9151: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9152: if (!$args->{'frameset'}) {
9153: $headerstring.= ' /';
9154: }
9155: $headerstring .= '>'."\n";
1.340 albertel 9156: }
9157: return $headerstring;
9158: }
9159:
1.341 albertel 9160: =pod
9161:
1.1064 raeburn 9162: =item * &print_suppression()
9163:
9164: In course context returns css which causes the body to be blank when media="print",
9165: if printout generation is unavailable for the current resource.
9166:
9167: This could be because:
9168:
9169: (a) printstartdate is in the future
9170:
9171: (b) printenddate is in the past
9172:
9173: (c) there is an active exam block with "printout"
9174: functionality blocked
9175:
9176: Users with pav, pfo or evb privileges are exempt.
9177:
9178: Inputs: none
9179:
9180: =cut
9181:
9182:
9183: sub print_suppression {
9184: my $noprint;
9185: if ($env{'request.course.id'}) {
9186: my $scope = $env{'request.course.id'};
9187: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9188: (&Apache::lonnet::allowed('pfo',$scope))) {
9189: return;
9190: }
9191: if ($env{'request.course.sec'} ne '') {
9192: $scope .= "/$env{'request.course.sec'}";
9193: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9194: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9195: return;
1.1064 raeburn 9196: }
9197: }
9198: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9199: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 9200: my $clientip = &Apache::lonnet::get_requestor_ip();
9201: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9202: if ($blocked) {
9203: my $checkrole = "cm./$cdom/$cnum";
9204: if ($env{'request.course.sec'} ne '') {
9205: $checkrole .= "/$env{'request.course.sec'}";
9206: }
9207: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9208: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9209: $noprint = 1;
9210: }
9211: }
9212: unless ($noprint) {
9213: my $symb = &Apache::lonnet::symbread();
9214: if ($symb ne '') {
9215: my $navmap = Apache::lonnavmaps::navmap->new();
9216: if (ref($navmap)) {
9217: my $res = $navmap->getBySymb($symb);
9218: if (ref($res)) {
9219: if (!$res->resprintable()) {
9220: $noprint = 1;
9221: }
9222: }
9223: }
9224: }
9225: }
9226: if ($noprint) {
9227: return <<"ENDSTYLE";
9228: <style type="text/css" media="print">
9229: body { display:none }
9230: </style>
9231: ENDSTYLE
9232: }
9233: }
9234: return;
9235: }
9236:
9237: =pod
9238:
1.341 albertel 9239: =item * &xml_begin()
9240:
9241: Returns the needed doctype and <html>
9242:
9243: Inputs: none
9244:
9245: =cut
9246:
9247: sub xml_begin {
1.1075.2.61 raeburn 9248: my ($is_frameset) = @_;
1.341 albertel 9249: my $output='';
9250:
9251: if ($env{'browser.mathml'}) {
9252: $output='<?xml version="1.0"?>'
9253: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9254: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9255:
9256: # .'<!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">] >'
9257: .'<!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">'
9258: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9259: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 9260: } elsif ($is_frameset) {
9261: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9262: '<html>'."\n";
1.341 albertel 9263: } else {
1.1075.2.61 raeburn 9264: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9265: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9266: }
9267: return $output;
9268: }
1.340 albertel 9269:
9270: =pod
9271:
1.306 albertel 9272: =item * &start_page()
9273:
9274: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9275:
1.648 raeburn 9276: Inputs:
9277:
9278: =over 4
9279:
9280: $title - optional title for the page
9281:
9282: $head_extra - optional extra HTML to incude inside the <head>
9283:
9284: $args - additional optional args supported are:
9285:
9286: =over 8
9287:
9288: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9289: arg on
1.814 bisitz 9290: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9291: add_entries -> additional attributes to add to the <body>
9292: domain -> force to color decorate a page for a
1.317 albertel 9293: specific domain
1.648 raeburn 9294: function -> force usage of a specific rolish color
1.317 albertel 9295: scheme
1.648 raeburn 9296: redirect -> see &headtag()
9297: bgcolor -> override the default page bg color
9298: js_ready -> return a string ready for being used in
1.317 albertel 9299: a javascript writeln
1.648 raeburn 9300: html_encode -> return a string ready for being used in
1.320 albertel 9301: a html attribute
1.648 raeburn 9302: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9303: $forcereg arg
1.648 raeburn 9304: frameset -> if true will start with a <frameset>
1.330 albertel 9305: rather than <body>
1.648 raeburn 9306: skip_phases -> hash ref of
1.338 albertel 9307: head -> skip the <html><head> generation
9308: body -> skip all <body> generation
1.1075.2.12 raeburn 9309: no_inline_link -> if true and in remote mode, don't show the
9310: 'Switch To Inline Menu' link
1.648 raeburn 9311: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9312: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9313: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.161. .29(raeb 9314:-24): bread_crumbs_style -> breadcrumbs are contained within <div id="LC_breadcrumbs">,
9315:-24): and &standard_css() contains CSS for #LC_breadcrumbs, if you want
9316:-24): to override those values, or add to them, specify the value to
9317:-24): include in the style attribute to include in the div tag by using
9318:-24): bread_crumbs_style (e.g., overflow: visible)
1.1075.2.123 raeburn 9319: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9320: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 9321: group -> includes the current group, if page is for a
9322: specific group
1.1075.2.133 raeburn 9323: use_absolute -> for request for external resource or syllabus, this
9324: will contain https://<hostname> if server uses
9325: https (as per hosts.tab), but request is for http
9326: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 9327: links_disabled -> Links in primary and secondary menus are disabled
9328: (Can enable them once page has loaded - see lonroles.pm
9329: for an example).
1.1075.2.161. .6(raebu 9330:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9331:
1.648 raeburn 9332: =back
1.460 albertel 9333:
1.648 raeburn 9334: =back
1.562 albertel 9335:
1.306 albertel 9336: =cut
9337:
9338: sub start_page {
1.309 albertel 9339: my ($title,$head_extra,$args) = @_;
1.318 albertel 9340: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9341:
1.315 albertel 9342: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 9343:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9344:
1.338 albertel 9345: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 9346: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9347: }
1.1075.2.161. .1(raebu 9348:21):
9349:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
9350:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9351:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9352:21): $args->{'no_primary_menu'} = 1;
9353:21): }
9354:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9355:21): $args->{'no_inline_menu'} = 1;
9356:21): }
9357:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9358:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9359:21): }
9360:21): } else {
9361:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9362:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9363:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9364:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9365:21): $args->{'no_primary_menu'} = 1;
9366:21): }
9367:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9368:21): $args->{'no_inline_menu'} = 1;
9369:21): }
9370:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9371:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9372:21): }
9373:21): }
9374:21): }
9375:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9376:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
9377:21): $env{'course.'.$env{'request.course.id'}.'.num'});
9378:21): } elsif ($env{'request.course.id'}) {
9379:21): my $expiretime=600;
9380:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9381:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9382:21): }
9383:21): my ($deeplinkmenu,$menuref);
9384:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9385:21): if ($menucoll) {
9386:21): if (ref($menuref) eq 'HASH') {
9387:21): %menu = %{$menuref};
9388:21): }
9389:21): if ($menu{'top'} eq 'n') {
9390:21): $args->{'no_primary_menu'} = 1;
9391:21): }
9392:21): if ($menu{'inline'} eq 'n') {
9393:21): unless (&Apache::lonnet::allowed('opa')) {
9394:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9395:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9396:21): my $crstype = &course_type();
9397:21): my $now = time;
9398:21): my $ccrole;
9399:21): if ($crstype eq 'Community') {
9400:21): $ccrole = 'co';
9401:21): } else {
9402:21): $ccrole = 'cc';
9403:21): }
9404:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9405:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9406:21): if ((($start) && ($start<0)) ||
9407:21): (($end) && ($end<$now)) ||
9408:21): (($start) && ($now<$start))) {
9409:21): $args->{'no_inline_menu'} = 1;
9410:21): }
9411:21): } else {
9412:21): $args->{'no_inline_menu'} = 1;
9413:21): }
9414:21): }
9415:21): }
9416:21): }
9417:21): }
.4(raebu 9418:22):
.8(raebu 9419:22): my $showncrumbs;
1.338 albertel 9420: if (! exists($args->{'skip_phases'}{'body'}) ) {
9421: if ($args->{'frameset'}) {
9422: my $attr_string = &make_attr_string($args->{'force_register'},
9423: $args->{'add_entries'});
9424: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9425: } else {
9426: $result .=
9427: &bodytag($title,
9428: $args->{'function'}, $args->{'add_entries'},
9429: $args->{'only_body'}, $args->{'domain'},
9430: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 9431: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 9432:21): $args, \@advtools,
.8(raebu 9433:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 9434: }
1.330 albertel 9435: }
1.338 albertel 9436:
1.315 albertel 9437: if ($args->{'js_ready'}) {
1.713 kaisler 9438: $result = &js_ready($result);
1.315 albertel 9439: }
1.320 albertel 9440: if ($args->{'html_encode'}) {
1.713 kaisler 9441: $result = &html_encode($result);
9442: }
9443:
1.813 bisitz 9444: # Preparation for new and consistent functionlist at top of screen
9445: # if ($args->{'functionlist'}) {
9446: # $result .= &build_functionlist();
9447: #}
9448:
1.964 droeschl 9449: # Don't add anything more if only_body wanted or in const space
9450: return $result if $args->{'only_body'}
9451: || $env{'request.state'} eq 'construct';
1.813 bisitz 9452:
9453: #Breadcrumbs
1.758 kaisler 9454: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 9455:22): unless ($showncrumbs) {
1.758 kaisler 9456: &Apache::lonhtmlcommon::clear_breadcrumbs();
9457: #if any br links exists, add them to the breadcrumbs
9458: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9459: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9460: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9461: }
9462: }
1.1075.2.19 raeburn 9463: # if @advtools array contains items add then to the breadcrumbs
9464: if (@advtools > 0) {
9465: &Apache::lonmenu::advtools_crumbs(@advtools);
9466: }
1.1075.2.123 raeburn 9467: my $menulink;
9468: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 9469:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
9470:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 9471: $menulink = 0;
9472: } else {
9473: undef($menulink);
9474: }
1.1075.2.161. .8(raebu 9475:22): my $linkprotout;
9476:22): if ($env{'request.deeplink.login'}) {
9477:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
9478:22): if ($linkprotout) {
9479:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9480:22): }
9481:22): }
1.758 kaisler 9482: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9483: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.161. .29(raeb 9484:-24): $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},
9485:-24): '',$menulink,'',
9486:-24): $args->{'bread_crumbs_style'});
.1(raebu 9487:21): } else {
.29(raeb 9488:-24): $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink,'',
9489:-24): $args->{'bread_crumbs_style'});
1.758 kaisler 9490: }
1.1075.2.161. .8(raebu 9491:22): }
1.1075.2.24 raeburn 9492: } elsif (($env{'environment.remote'} eq 'on') &&
9493: ($env{'form.inhibitmenu'} ne 'yes') &&
9494: ($env{'request.noversionuri'} =~ m{^/res/}) &&
9495: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 9496: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 9497: }
1.315 albertel 9498: return $result;
1.306 albertel 9499: }
9500:
9501: sub end_page {
1.315 albertel 9502: my ($args) = @_;
9503: $env{'internal.end_page'}++;
1.330 albertel 9504: my $result;
1.335 albertel 9505: if ($args->{'discussion'}) {
9506: my ($target,$parser);
9507: if (ref($args->{'discussion'})) {
9508: ($target,$parser) =($args->{'discussion'}{'target'},
9509: $args->{'discussion'}{'parser'});
9510: }
9511: $result .= &Apache::lonxml::xmlend($target,$parser);
9512: }
1.330 albertel 9513: if ($args->{'frameset'}) {
9514: $result .= '</frameset>';
9515: } else {
1.635 raeburn 9516: $result .= &endbodytag($args);
1.330 albertel 9517: }
1.1075.2.6 raeburn 9518: unless ($args->{'notbody'}) {
9519: $result .= "\n</html>";
9520: }
1.330 albertel 9521:
1.315 albertel 9522: if ($args->{'js_ready'}) {
1.317 albertel 9523: $result = &js_ready($result);
1.315 albertel 9524: }
1.335 albertel 9525:
1.320 albertel 9526: if ($args->{'html_encode'}) {
9527: $result = &html_encode($result);
9528: }
1.335 albertel 9529:
1.315 albertel 9530: return $result;
9531: }
9532:
1.1075.2.161. .1(raebu 9533:21): sub menucoll_in_effect {
9534:21): my ($menucoll,$deeplinkmenu,%menu);
9535:21): if ($env{'request.course.id'}) {
9536:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9537:21): if ($env{'request.deeplink.login'}) {
9538:21): my ($deeplink_symb,$deeplink,$check_login_symb);
9539:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9540:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9541:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9542:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9543:21): my $navmap = Apache::lonnavmaps::navmap->new();
9544:21): if (ref($navmap)) {
9545:21): $deeplink = $navmap->get_mapparam(undef,
9546:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
9547:21): '0.deeplink');
9548:21): } else {
9549:21): $check_login_symb = 1;
9550:21): }
9551:21): } else {
9552:21): my $symb=&Apache::lonnet::symbread();
9553:21): if ($symb) {
9554:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9555:21): } else {
9556:21): $check_login_symb = 1;
9557:21): }
9558:21): }
9559:21): } else {
9560:21): $check_login_symb = 1;
9561:21): }
9562:21): if ($check_login_symb) {
9563:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9564:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
9565:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9566:21): my $navmap = Apache::lonnavmaps::navmap->new();
9567:21): if (ref($navmap)) {
9568:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9569:21): }
9570:21): } else {
9571:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9572:21): }
9573:21): }
9574:21): if ($deeplink ne '') {
.6(raebu 9575:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 9576:21): if ($display =~ /^\d+$/) {
9577:21): $deeplinkmenu = 1;
9578:21): $menucoll = $display;
9579:21): }
9580:21): }
9581:21): }
9582:21): if ($menucoll) {
9583:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9584:21): }
9585:21): }
9586:21): return ($menucoll,$deeplinkmenu,\%menu);
9587:21): }
9588:21):
9589:21): sub deeplink_login_symb {
9590:21): my ($cnum,$cdom) = @_;
9591:21): my $login_symb;
9592:21): if ($env{'request.deeplink.login'}) {
9593:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9594:21): }
9595:21): return $login_symb;
9596:21): }
9597:21):
9598:21): sub symb_from_tinyurl {
9599:21): my ($url,$cnum,$cdom) = @_;
9600:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9601:21): my $key = $1;
9602:21): my ($tinyurl,$login);
9603:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9604:21): if (defined($cached)) {
9605:21): $tinyurl = $result;
9606:21): } else {
9607:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9608:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9609:21): if ($currtiny{$key} ne '') {
9610:21): $tinyurl = $currtiny{$key};
9611:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9612:21): }
9613:21): }
9614:21): if ($tinyurl ne '') {
9615:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9616:21): if (wantarray) {
9617:21): return ($cnumreq,$symb);
9618:21): } elsif ($cnumreq eq $cnum) {
9619:21): return $symb;
9620:21): }
9621:21): }
9622:21): }
9623:21): if (wantarray) {
9624:21): return ();
9625:21): } else {
9626:21): return;
9627:21): }
9628:21): }
9629:21):
.17(raeb 9630:-23): sub usable_exttools {
9631:-23): my %tooltypes;
9632:-23): if ($env{'request.course.id'}) {
9633:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9634:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9635:-23): %tooltypes = (
9636:-23): crs => 1,
9637:-23): dom => 1,
9638:-23): );
9639:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9640:-23): $tooltypes{'crs'} = 1;
9641:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9642:-23): $tooltypes{'dom'} = 1;
9643:-23): }
9644:-23): } else {
9645:-23): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9646:-23): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9647:-23): my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9648:-23): if ($crstype eq '') {
9649:-23): $crstype = 'course';
9650:-23): }
9651:-23): if ($crstype eq 'course') {
9652:-23): if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9653:-23): $crstype = 'official';
9654:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9655:-23): $crstype = 'textbook';
9656:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9657:-23): $crstype = 'lti';
9658:-23): } else {
9659:-23): $crstype = 'unofficial';
9660:-23): }
9661:-23): }
9662:-23): my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9663:-23): if ($domdefaults{$crstype.'domexttool'}) {
9664:-23): $tooltypes{'dom'} = 1;
9665:-23): }
9666:-23): if ($domdefaults{$crstype.'exttool'}) {
9667:-23): $tooltypes{'crs'} = 1;
9668:-23): }
9669:-23): }
9670:-23): }
9671:-23): return %tooltypes;
9672:-23): }
9673:-23):
1.1034 www 9674: sub wishlist_window {
9675: return(<<'ENDWISHLIST');
1.1046 raeburn 9676: <script type="text/javascript">
1.1034 www 9677: // <![CDATA[
9678: // <!-- BEGIN LON-CAPA Internal
9679: function set_wishlistlink(title, path) {
9680: if (!title) {
9681: title = document.title;
9682: title = title.replace(/^LON-CAPA /,'');
9683: }
1.1075.2.65 raeburn 9684: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9685: title = title.replace("'","\\\'");
1.1034 www 9686: if (!path) {
9687: path = location.pathname;
9688: }
1.1075.2.65 raeburn 9689: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9690: path = path.replace("'","\\\'");
1.1034 www 9691: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9692: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9693: }
9694: // END LON-CAPA Internal -->
9695: // ]]>
9696: </script>
9697: ENDWISHLIST
9698: }
9699:
1.1030 www 9700: sub modal_window {
9701: return(<<'ENDMODAL');
1.1046 raeburn 9702: <script type="text/javascript">
1.1030 www 9703: // <![CDATA[
9704: // <!-- BEGIN LON-CAPA Internal
9705: var modalWindow = {
9706: parent:"body",
9707: windowId:null,
9708: content:null,
9709: width:null,
9710: height:null,
9711: close:function()
9712: {
9713: $(".LCmodal-window").remove();
9714: $(".LCmodal-overlay").remove();
9715: },
9716: open:function()
9717: {
9718: var modal = "";
9719: modal += "<div class=\"LCmodal-overlay\"></div>";
9720: 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;\">";
9721: modal += this.content;
9722: modal += "</div>";
9723:
9724: $(this.parent).append(modal);
9725:
9726: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9727: $(".LCclose-window").click(function(){modalWindow.close();});
9728: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9729: }
9730: };
1.1075.2.42 raeburn 9731: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9732: {
1.1075.2.119 raeburn 9733: source = source.replace(/'/g,"'");
1.1030 www 9734: modalWindow.windowId = "myModal";
9735: modalWindow.width = width;
9736: modalWindow.height = height;
1.1075.2.80 raeburn 9737: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9738: modalWindow.open();
1.1075.2.87 raeburn 9739: };
1.1030 www 9740: // END LON-CAPA Internal -->
9741: // ]]>
9742: </script>
9743: ENDMODAL
9744: }
9745:
9746: sub modal_link {
1.1075.2.42 raeburn 9747: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9748: unless ($width) { $width=480; }
9749: unless ($height) { $height=400; }
1.1031 www 9750: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9751: unless ($transparency) { $transparency='true'; }
9752:
1.1074 raeburn 9753: my $target_attr;
9754: if (defined($target)) {
9755: $target_attr = 'target="'.$target.'"';
9756: }
9757: return <<"ENDLINK";
1.1075.2.143 raeburn 9758: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9759: ENDLINK
1.1030 www 9760: }
9761:
1.1032 www 9762: sub modal_adhoc_script {
1.1075.2.155 raeburn 9763: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9764: my $mathjax;
9765: if ($possmathjax) {
9766: $mathjax = <<'ENDJAX';
9767: if (typeof MathJax == 'object') {
9768: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9769: }
9770: ENDJAX
9771: }
1.1032 www 9772: return (<<ENDADHOC);
1.1046 raeburn 9773: <script type="text/javascript">
1.1032 www 9774: // <![CDATA[
9775: var $funcname = function()
9776: {
9777: modalWindow.windowId = "myModal";
9778: modalWindow.width = $width;
9779: modalWindow.height = $height;
9780: modalWindow.content = '$content';
9781: modalWindow.open();
1.1075.2.155 raeburn 9782: $mathjax
1.1032 www 9783: };
9784: // ]]>
9785: </script>
9786: ENDADHOC
9787: }
9788:
1.1041 www 9789: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9790: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9791: my $innerwidth=$width-20;
9792: $content=&js_ready(
1.1042 www 9793: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9794: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9795: $content.
1.1041 www 9796: &end_scrollbox().
1.1075.2.42 raeburn 9797: &end_page()
1.1041 www 9798: );
1.1075.2.155 raeburn 9799: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9800: }
9801:
9802: sub modal_adhoc_window {
1.1075.2.155 raeburn 9803: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9804: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9805: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9806: }
9807:
9808: sub modal_adhoc_launch {
9809: my ($funcname,$width,$height,$content)=@_;
9810: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9811: <script type="text/javascript">
9812: // <![CDATA[
9813: $funcname();
9814: // ]]>
9815: </script>
9816: ENDLAUNCH
9817: }
9818:
9819: sub modal_adhoc_close {
9820: return (<<ENDCLOSE);
9821: <script type="text/javascript">
9822: // <![CDATA[
9823: modalWindow.close();
9824: // ]]>
9825: </script>
9826: ENDCLOSE
9827: }
9828:
1.1038 www 9829: sub togglebox_script {
9830: return(<<ENDTOGGLE);
9831: <script type="text/javascript">
9832: // <![CDATA[
9833: function LCtoggleDisplay(id,hidetext,showtext) {
9834: link = document.getElementById(id + "link").childNodes[0];
9835: with (document.getElementById(id).style) {
9836: if (display == "none" ) {
9837: display = "inline";
9838: link.nodeValue = hidetext;
9839: } else {
9840: display = "none";
9841: link.nodeValue = showtext;
9842: }
9843: }
9844: }
9845: // ]]>
9846: </script>
9847: ENDTOGGLE
9848: }
9849:
1.1039 www 9850: sub start_togglebox {
9851: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9852: unless ($heading) { $heading=''; } else { $heading.=' '; }
9853: unless ($showtext) { $showtext=&mt('show'); }
9854: unless ($hidetext) { $hidetext=&mt('hide'); }
9855: unless ($headerbg) { $headerbg='#FFFFFF'; }
9856: return &start_data_table().
9857: &start_data_table_header_row().
9858: '<td bgcolor="'.$headerbg.'">'.$heading.
9859: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9860: $showtext.'\')">'.$showtext.'</a>]</td>'.
9861: &end_data_table_header_row().
9862: '<tr id="'.$id.'" style="display:none""><td>';
9863: }
9864:
9865: sub end_togglebox {
9866: return '</td></tr>'.&end_data_table();
9867: }
9868:
1.1041 www 9869: sub LCprogressbar_script {
1.1075.2.130 raeburn 9870: my ($id,$number_to_do)=@_;
9871: if ($number_to_do) {
9872: return(<<ENDPROGRESS);
1.1041 www 9873: <script type="text/javascript">
9874: // <![CDATA[
1.1045 www 9875: \$('#progressbar$id').progressbar({
1.1041 www 9876: value: 0,
9877: change: function(event, ui) {
9878: var newVal = \$(this).progressbar('option', 'value');
9879: \$('.pblabel', this).text(LCprogressTxt);
9880: }
9881: });
9882: // ]]>
9883: </script>
9884: ENDPROGRESS
1.1075.2.130 raeburn 9885: } else {
9886: return(<<ENDPROGRESS);
9887: <script type="text/javascript">
9888: // <![CDATA[
9889: \$('#progressbar$id').progressbar({
9890: value: false,
9891: create: function(event, ui) {
9892: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9893: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9894: }
9895: });
9896: // ]]>
9897: </script>
9898: ENDPROGRESS
9899: }
1.1041 www 9900: }
9901:
9902: sub LCprogressbarUpdate_script {
9903: return(<<ENDPROGRESSUPDATE);
9904: <style type="text/css">
9905: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9906: .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 9907: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9908: </style>
9909: <script type="text/javascript">
9910: // <![CDATA[
1.1045 www 9911: var LCprogressTxt='---';
9912:
1.1075.2.130 raeburn 9913: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9914: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9915: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9916: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9917: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9918: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9919: } else {
9920: \$('#progressbar'+id).progressbar('value',percent);
9921: }
1.1041 www 9922: }
9923: // ]]>
9924: </script>
9925: ENDPROGRESSUPDATE
9926: }
9927:
1.1042 www 9928: my $LClastpercent;
1.1045 www 9929: my $LCidcnt;
9930: my $LCcurrentid;
1.1042 www 9931:
1.1041 www 9932: sub LCprogressbar {
1.1075.2.130 raeburn 9933: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9934: $LClastpercent=0;
1.1045 www 9935: $LCidcnt++;
9936: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9937: my ($starting,$content);
9938: if ($number_to_do) {
9939: $starting=&mt('Starting');
9940: $content=(<<ENDPROGBAR);
9941: $preamble
1.1045 www 9942: <div id="progressbar$LCcurrentid">
1.1041 www 9943: <span class="pblabel">$starting</span>
9944: </div>
9945: ENDPROGBAR
1.1075.2.130 raeburn 9946: } else {
9947: $starting=&mt('Loading...');
9948: $LClastpercent='false';
9949: $content=(<<ENDPROGBAR);
9950: $preamble
9951: <div id="progressbar$LCcurrentid">
9952: <div class="progress-label">$starting</div>
9953: </div>
9954: ENDPROGBAR
9955: }
9956: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9957: }
9958:
9959: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9960: my ($r,$val,$text,$number_to_do)=@_;
9961: if ($number_to_do) {
9962: unless ($val) {
9963: if ($LClastpercent) {
9964: $val=$LClastpercent;
9965: } else {
9966: $val=0;
9967: }
9968: }
9969: if ($val<0) { $val=0; }
9970: if ($val>100) { $val=0; }
9971: $LClastpercent=$val;
9972: unless ($text) { $text=$val.'%'; }
9973: } else {
9974: $val = 'false';
1.1042 www 9975: }
1.1041 www 9976: $text=&js_ready($text);
1.1044 www 9977: &r_print($r,<<ENDUPDATE);
1.1041 www 9978: <script type="text/javascript">
9979: // <![CDATA[
1.1075.2.130 raeburn 9980: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9981: // ]]>
9982: </script>
9983: ENDUPDATE
1.1035 www 9984: }
9985:
1.1042 www 9986: sub LCprogressbarClose {
9987: my ($r)=@_;
9988: $LClastpercent=0;
1.1044 www 9989: &r_print($r,<<ENDCLOSE);
1.1042 www 9990: <script type="text/javascript">
9991: // <![CDATA[
1.1045 www 9992: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9993: // ]]>
9994: </script>
9995: ENDCLOSE
1.1044 www 9996: }
9997:
9998: sub r_print {
9999: my ($r,$to_print)=@_;
10000: if ($r) {
10001: $r->print($to_print);
10002: $r->rflush();
10003: } else {
10004: print($to_print);
10005: }
1.1042 www 10006: }
10007:
1.320 albertel 10008: sub html_encode {
10009: my ($result) = @_;
10010:
1.322 albertel 10011: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10012:
10013: return $result;
10014: }
1.1044 www 10015:
1.317 albertel 10016: sub js_ready {
10017: my ($result) = @_;
10018:
1.323 albertel 10019: $result =~ s/[\n\r]/ /xmsg;
10020: $result =~ s/\\/\\\\/xmsg;
10021: $result =~ s/'/\\'/xmsg;
1.372 albertel 10022: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10023:
10024: return $result;
10025: }
10026:
1.315 albertel 10027: sub validate_page {
10028: if ( exists($env{'internal.start_page'})
1.316 albertel 10029: && $env{'internal.start_page'} > 1) {
10030: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10031: $env{'internal.start_page'}.' '.
1.316 albertel 10032: $ENV{'request.filename'});
1.315 albertel 10033: }
10034: if ( exists($env{'internal.end_page'})
1.316 albertel 10035: && $env{'internal.end_page'} > 1) {
10036: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10037: $env{'internal.end_page'}.' '.
1.316 albertel 10038: $env{'request.filename'});
1.315 albertel 10039: }
10040: if ( exists($env{'internal.start_page'})
10041: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10042: &Apache::lonnet::logthis('start_page called without end_page '.
10043: $env{'request.filename'});
1.315 albertel 10044: }
10045: if ( ! exists($env{'internal.start_page'})
10046: && exists($env{'internal.end_page'})) {
1.316 albertel 10047: &Apache::lonnet::logthis('end_page called without start_page'.
10048: $env{'request.filename'});
1.315 albertel 10049: }
1.306 albertel 10050: }
1.315 albertel 10051:
1.996 www 10052:
10053: sub start_scrollbox {
1.1075.2.56 raeburn 10054: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10055: unless ($outerwidth) { $outerwidth='520px'; }
10056: unless ($width) { $width='500px'; }
10057: unless ($height) { $height='200px'; }
1.1075 raeburn 10058: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10059: if ($id ne '') {
1.1075.2.42 raeburn 10060: $table_id = ' id="table_'.$id.'"';
10061: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10062: }
1.1075 raeburn 10063: if ($bgcolor ne '') {
10064: $tdcol = "background-color: $bgcolor;";
10065: }
1.1075.2.42 raeburn 10066: my $nicescroll_js;
10067: if ($env{'browser.mobile'}) {
10068: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10069: }
1.1075 raeburn 10070: return <<"END";
1.1075.2.42 raeburn 10071: $nicescroll_js
10072:
10073: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 10074: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 10075: END
1.996 www 10076: }
10077:
10078: sub end_scrollbox {
1.1036 www 10079: return '</div></td></tr></table>';
1.996 www 10080: }
10081:
1.1075.2.42 raeburn 10082: sub nicescroll_javascript {
10083: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10084: my %options;
10085: if (ref($cursor) eq 'HASH') {
10086: %options = %{$cursor};
10087: }
10088: unless ($options{'railalign'} =~ /^left|right$/) {
10089: $options{'railalign'} = 'left';
10090: }
10091: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10092: my $function = &get_users_function();
10093: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
10094: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10095: $options{'cursorcolor'} = '#00F';
10096: }
10097: }
10098: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10099: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
10100: $options{'cursoropacity'}='1.0';
10101: }
10102: } else {
10103: $options{'cursoropacity'}='1.0';
10104: }
10105: if ($options{'cursorfixedheight'} eq 'none') {
10106: delete($options{'cursorfixedheight'});
10107: } else {
10108: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10109: }
10110: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10111: delete($options{'railoffset'});
10112: }
10113: my @niceoptions;
10114: while (my($key,$value) = each(%options)) {
10115: if ($value =~ /^\{.+\}$/) {
10116: push(@niceoptions,$key.':'.$value);
10117: } else {
10118: push(@niceoptions,$key.':"'.$value.'"');
10119: }
10120: }
10121: my $nicescroll_js = '
10122: $(document).ready(
10123: function() {
10124: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10125: }
10126: );
10127: ';
10128: if ($framecheck) {
10129: $nicescroll_js .= '
10130: function expand_div(caller) {
10131: if (top === self) {
10132: document.getElementById("'.$id.'").style.width = "auto";
10133: document.getElementById("'.$id.'").style.height = "auto";
10134: } else {
10135: try {
10136: if (parent.frames) {
10137: if (parent.frames.length > 1) {
10138: var framesrc = parent.frames[1].location.href;
10139: var currsrc = framesrc.replace(/\#.*$/,"");
10140: if ((caller == "search") || (currsrc == "'.$location.'")) {
10141: document.getElementById("'.$id.'").style.width = "auto";
10142: document.getElementById("'.$id.'").style.height = "auto";
10143: }
10144: }
10145: }
10146: } catch (e) {
10147: return;
10148: }
10149: }
10150: return;
10151: }
10152: ';
10153: }
10154: if ($needjsready) {
10155: $nicescroll_js = '
10156: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10157: } else {
10158: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10159: }
10160: return $nicescroll_js;
10161: }
10162:
1.318 albertel 10163: sub simple_error_page {
1.1075.2.49 raeburn 10164: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 10165:22): my %displayargs;
1.1075.2.49 raeburn 10166: if (ref($args) eq 'HASH') {
10167: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 10168:22): if ($args->{'only_body'}) {
10169:22): $displayargs{'only_body'} = 1;
10170:22): }
10171:22): if ($args->{'no_nav_bar'}) {
10172:22): $displayargs{'no_nav_bar'} = 1;
10173:22): }
1.1075.2.49 raeburn 10174: } else {
10175: $msg = &mt($msg);
10176: }
10177:
1.318 albertel 10178: my $page =
1.1075.2.161. .4(raebu 10179:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 10180: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10181: &Apache::loncommon::end_page();
10182: if (ref($r)) {
10183: $r->print($page);
1.327 albertel 10184: return;
1.318 albertel 10185: }
10186: return $page;
10187: }
1.347 albertel 10188:
10189: {
1.610 albertel 10190: my @row_count;
1.961 onken 10191:
10192: sub start_data_table_count {
10193: unshift(@row_count, 0);
10194: return;
10195: }
10196:
10197: sub end_data_table_count {
10198: shift(@row_count);
10199: return;
10200: }
10201:
1.347 albertel 10202: sub start_data_table {
1.1018 raeburn 10203: my ($add_class,$id) = @_;
1.422 albertel 10204: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10205: my $table_id;
10206: if (defined($id)) {
10207: $table_id = ' id="'.$id.'"';
10208: }
1.961 onken 10209: &start_data_table_count();
1.1018 raeburn 10210: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10211: }
10212:
10213: sub end_data_table {
1.961 onken 10214: &end_data_table_count();
1.389 albertel 10215: return '</table>'."\n";;
1.347 albertel 10216: }
10217:
10218: sub start_data_table_row {
1.974 wenzelju 10219: my ($add_class, $id) = @_;
1.610 albertel 10220: $row_count[0]++;
10221: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10222: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10223: $id = (' id="'.$id.'"') unless ($id eq '');
10224: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10225: }
1.471 banghart 10226:
10227: sub continue_data_table_row {
1.974 wenzelju 10228: my ($add_class, $id) = @_;
1.610 albertel 10229: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10230: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10231: $id = (' id="'.$id.'"') unless ($id eq '');
10232: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10233: }
1.347 albertel 10234:
10235: sub end_data_table_row {
1.389 albertel 10236: return '</tr>'."\n";;
1.347 albertel 10237: }
1.367 www 10238:
1.421 albertel 10239: sub start_data_table_empty_row {
1.707 bisitz 10240: # $row_count[0]++;
1.421 albertel 10241: return '<tr class="LC_empty_row" >'."\n";;
10242: }
10243:
10244: sub end_data_table_empty_row {
10245: return '</tr>'."\n";;
10246: }
10247:
1.367 www 10248: sub start_data_table_header_row {
1.389 albertel 10249: return '<tr class="LC_header_row">'."\n";;
1.367 www 10250: }
10251:
10252: sub end_data_table_header_row {
1.389 albertel 10253: return '</tr>'."\n";;
1.367 www 10254: }
1.890 droeschl 10255:
10256: sub data_table_caption {
10257: my $caption = shift;
10258: return "<caption class=\"LC_caption\">$caption</caption>";
10259: }
1.347 albertel 10260: }
10261:
1.548 albertel 10262: =pod
10263:
10264: =item * &inhibit_menu_check($arg)
10265:
10266: Checks for a inhibitmenu state and generates output to preserve it
10267:
10268: Inputs: $arg - can be any of
10269: - undef - in which case the return value is a string
10270: to add into arguments list of a uri
10271: - 'input' - in which case the return value is a HTML
10272: <form> <input> field of type hidden to
10273: preserve the value
10274: - a url - in which case the return value is the url with
10275: the neccesary cgi args added to preserve the
10276: inhibitmenu state
10277: - a ref to a url - no return value, but the string is
10278: updated to include the neccessary cgi
10279: args to preserve the inhibitmenu state
10280:
10281: =cut
10282:
10283: sub inhibit_menu_check {
10284: my ($arg) = @_;
10285: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10286: if ($arg eq 'input') {
10287: if ($env{'form.inhibitmenu'}) {
10288: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10289: } else {
10290: return
10291: }
10292: }
10293: if ($env{'form.inhibitmenu'}) {
10294: if (ref($arg)) {
10295: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10296: } elsif ($arg eq '') {
10297: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10298: } else {
10299: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10300: }
10301: }
10302: if (!ref($arg)) {
10303: return $arg;
10304: }
10305: }
10306:
1.251 albertel 10307: ###############################################
1.182 matthew 10308:
10309: =pod
10310:
1.549 albertel 10311: =back
10312:
10313: =head1 User Information Routines
10314:
10315: =over 4
10316:
1.405 albertel 10317: =item * &get_users_function()
1.182 matthew 10318:
10319: Used by &bodytag to determine the current users primary role.
10320: Returns either 'student','coordinator','admin', or 'author'.
10321:
10322: =cut
10323:
10324: ###############################################
10325: sub get_users_function {
1.815 tempelho 10326: my $function = 'norole';
1.818 tempelho 10327: if ($env{'request.role'}=~/^(st)/) {
10328: $function='student';
10329: }
1.907 raeburn 10330: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10331: $function='coordinator';
10332: }
1.258 albertel 10333: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10334: $function='admin';
10335: }
1.826 bisitz 10336: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10337: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10338: $function='author';
10339: }
10340: return $function;
1.54 www 10341: }
1.99 www 10342:
10343: ###############################################
10344:
1.233 raeburn 10345: =pod
10346:
1.821 raeburn 10347: =item * &show_course()
10348:
10349: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10350: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10351:
10352: Inputs:
10353: None
10354:
10355: Outputs:
10356: Scalar: 1 if 'Course' to be used, 0 otherwise.
10357:
10358: =cut
10359:
10360: ###############################################
10361: sub show_course {
10362: my $course = !$env{'user.adv'};
10363: if (!$env{'user.adv'}) {
10364: foreach my $env (keys(%env)) {
10365: next if ($env !~ m/^user\.priv\./);
10366: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10367: $course = 0;
10368: last;
10369: }
10370: }
10371: }
10372: return $course;
10373: }
10374:
10375: ###############################################
10376:
10377: =pod
10378:
1.542 raeburn 10379: =item * &check_user_status()
1.274 raeburn 10380:
10381: Determines current status of supplied role for a
10382: specific user. Roles can be active, previous or future.
10383:
10384: Inputs:
10385: user's domain, user's username, course's domain,
1.375 raeburn 10386: course's number, optional section ID.
1.274 raeburn 10387:
10388: Outputs:
10389: role status: active, previous or future.
10390:
10391: =cut
10392:
10393: sub check_user_status {
1.412 raeburn 10394: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10395: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 10396: my @uroles = keys(%userinfo);
1.274 raeburn 10397: my $srchstr;
10398: my $active_chk = 'none';
1.412 raeburn 10399: my $now = time;
1.274 raeburn 10400: if (@uroles > 0) {
1.908 raeburn 10401: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10402: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10403: } else {
1.412 raeburn 10404: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10405: }
10406: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10407: my $role_end = 0;
10408: my $role_start = 0;
10409: $active_chk = 'active';
1.412 raeburn 10410: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10411: $role_end = $1;
10412: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10413: $role_start = $1;
1.274 raeburn 10414: }
10415: }
10416: if ($role_start > 0) {
1.412 raeburn 10417: if ($now < $role_start) {
1.274 raeburn 10418: $active_chk = 'future';
10419: }
10420: }
10421: if ($role_end > 0) {
1.412 raeburn 10422: if ($now > $role_end) {
1.274 raeburn 10423: $active_chk = 'previous';
10424: }
10425: }
10426: }
10427: }
10428: return $active_chk;
10429: }
10430:
10431: ###############################################
10432:
10433: =pod
10434:
1.405 albertel 10435: =item * &get_sections()
1.233 raeburn 10436:
10437: Determines all the sections for a course including
10438: sections with students and sections containing other roles.
1.419 raeburn 10439: Incoming parameters:
10440:
10441: 1. domain
10442: 2. course number
10443: 3. reference to array containing roles for which sections should
10444: be gathered (optional).
10445: 4. reference to array containing status types for which sections
10446: should be gathered (optional).
10447:
10448: If the third argument is undefined, sections are gathered for any role.
10449: If the fourth argument is undefined, sections are gathered for any status.
10450: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10451:
1.374 raeburn 10452: Returns section hash (keys are section IDs, values are
10453: number of users in each section), subject to the
1.419 raeburn 10454: optional roles filter, optional status filter
1.233 raeburn 10455:
10456: =cut
10457:
10458: ###############################################
10459: sub get_sections {
1.419 raeburn 10460: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10461: if (!defined($cdom) || !defined($cnum)) {
10462: my $cid = $env{'request.course.id'};
10463:
10464: return if (!defined($cid));
10465:
10466: $cdom = $env{'course.'.$cid.'.domain'};
10467: $cnum = $env{'course.'.$cid.'.num'};
10468: }
10469:
10470: my %sectioncount;
1.419 raeburn 10471: my $now = time;
1.240 albertel 10472:
1.1075.2.33 raeburn 10473: my $check_students = 1;
10474: my $only_students = 0;
10475: if (ref($possible_roles) eq 'ARRAY') {
10476: if (grep(/^st$/,@{$possible_roles})) {
10477: if (@{$possible_roles} == 1) {
10478: $only_students = 1;
10479: }
10480: } else {
10481: $check_students = 0;
10482: }
10483: }
10484:
10485: if ($check_students) {
1.276 albertel 10486: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10487: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10488: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10489: my $start_index = &Apache::loncoursedata::CL_START();
10490: my $end_index = &Apache::loncoursedata::CL_END();
10491: my $status;
1.366 albertel 10492: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10493: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10494: $data->[$status_index],
10495: $data->[$start_index],
10496: $data->[$end_index]);
10497: if ($stu_status eq 'Active') {
10498: $status = 'active';
10499: } elsif ($end < $now) {
10500: $status = 'previous';
10501: } elsif ($start > $now) {
10502: $status = 'future';
10503: }
10504: if ($section ne '-1' && $section !~ /^\s*$/) {
10505: if ((!defined($possible_status)) || (($status ne '') &&
10506: (grep/^\Q$status\E$/,@{$possible_status}))) {
10507: $sectioncount{$section}++;
10508: }
1.240 albertel 10509: }
10510: }
10511: }
1.1075.2.33 raeburn 10512: if ($only_students) {
10513: return %sectioncount;
10514: }
1.240 albertel 10515: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10516: foreach my $user (sort(keys(%courseroles))) {
10517: if ($user !~ /^(\w{2})/) { next; }
10518: my ($role) = ($user =~ /^(\w{2})/);
10519: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10520: my ($section,$status);
1.240 albertel 10521: if ($role eq 'cr' &&
10522: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10523: $section=$1;
10524: }
10525: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10526: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10527: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10528: if ($end == -1 && $start == -1) {
10529: next; #deleted role
10530: }
10531: if (!defined($possible_status)) {
10532: $sectioncount{$section}++;
10533: } else {
10534: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10535: $status = 'active';
10536: } elsif ($end < $now) {
10537: $status = 'future';
10538: } elsif ($start > $now) {
10539: $status = 'previous';
10540: }
10541: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10542: $sectioncount{$section}++;
10543: }
10544: }
1.233 raeburn 10545: }
1.366 albertel 10546: return %sectioncount;
1.233 raeburn 10547: }
10548:
1.274 raeburn 10549: ###############################################
1.294 raeburn 10550:
10551: =pod
1.405 albertel 10552:
10553: =item * &get_course_users()
10554:
1.275 raeburn 10555: Retrieves usernames:domains for users in the specified course
10556: with specific role(s), and access status.
10557:
10558: Incoming parameters:
1.277 albertel 10559: 1. course domain
10560: 2. course number
10561: 3. access status: users must have - either active,
1.275 raeburn 10562: previous, future, or all.
1.277 albertel 10563: 4. reference to array of permissible roles
1.288 raeburn 10564: 5. reference to array of section restrictions (optional)
10565: 6. reference to results object (hash of hashes).
10566: 7. reference to optional userdata hash
1.609 raeburn 10567: 8. reference to optional statushash
1.630 raeburn 10568: 9. flag if privileged users (except those set to unhide in
10569: course settings) should be excluded
1.609 raeburn 10570: Keys of top level results hash are roles.
1.275 raeburn 10571: Keys of inner hashes are username:domain, with
10572: values set to access type.
1.288 raeburn 10573: Optional userdata hash returns an array with arguments in the
10574: same order as loncoursedata::get_classlist() for student data.
10575:
1.609 raeburn 10576: Optional statushash returns
10577:
1.288 raeburn 10578: Entries for end, start, section and status are blank because
10579: of the possibility of multiple values for non-student roles.
10580:
1.275 raeburn 10581: =cut
1.405 albertel 10582:
1.275 raeburn 10583: ###############################################
1.405 albertel 10584:
1.275 raeburn 10585: sub get_course_users {
1.630 raeburn 10586: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10587: my %idx = ();
1.419 raeburn 10588: my %seclists;
1.288 raeburn 10589:
10590: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10591: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10592: $idx{end} = &Apache::loncoursedata::CL_END();
10593: $idx{start} = &Apache::loncoursedata::CL_START();
10594: $idx{id} = &Apache::loncoursedata::CL_ID();
10595: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10596: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10597: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10598:
1.290 albertel 10599: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10600: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10601: my $now = time;
1.277 albertel 10602: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10603: my $match = 0;
1.412 raeburn 10604: my $secmatch = 0;
1.419 raeburn 10605: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10606: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10607: if ($section eq '') {
10608: $section = 'none';
10609: }
1.291 albertel 10610: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10611: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10612: $secmatch = 1;
10613: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10614: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10615: $secmatch = 1;
10616: }
10617: } else {
1.419 raeburn 10618: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10619: $secmatch = 1;
10620: }
1.290 albertel 10621: }
1.412 raeburn 10622: if (!$secmatch) {
10623: next;
10624: }
1.419 raeburn 10625: }
1.275 raeburn 10626: if (defined($$types{'active'})) {
1.288 raeburn 10627: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10628: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10629: $match = 1;
1.275 raeburn 10630: }
10631: }
10632: if (defined($$types{'previous'})) {
1.609 raeburn 10633: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10634: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10635: $match = 1;
1.275 raeburn 10636: }
10637: }
10638: if (defined($$types{'future'})) {
1.609 raeburn 10639: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10640: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10641: $match = 1;
1.275 raeburn 10642: }
10643: }
1.609 raeburn 10644: if ($match) {
10645: push(@{$seclists{$student}},$section);
10646: if (ref($userdata) eq 'HASH') {
10647: $$userdata{$student} = $$classlist{$student};
10648: }
10649: if (ref($statushash) eq 'HASH') {
10650: $statushash->{$student}{'st'}{$section} = $status;
10651: }
1.288 raeburn 10652: }
1.275 raeburn 10653: }
10654: }
1.412 raeburn 10655: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10656: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10657: my $now = time;
1.609 raeburn 10658: my %displaystatus = ( previous => 'Expired',
10659: active => 'Active',
10660: future => 'Future',
10661: );
1.1075.2.36 raeburn 10662: my (%nothide,@possdoms);
1.630 raeburn 10663: if ($hidepriv) {
10664: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10665: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10666: if ($user !~ /:/) {
10667: $nothide{join(':',split(/[\@]/,$user))}=1;
10668: } else {
10669: $nothide{$user} = 1;
10670: }
10671: }
1.1075.2.36 raeburn 10672: my @possdoms = ($cdom);
10673: if ($coursehash{'checkforpriv'}) {
10674: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10675: }
1.630 raeburn 10676: }
1.439 raeburn 10677: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10678: my $match = 0;
1.412 raeburn 10679: my $secmatch = 0;
1.439 raeburn 10680: my $status;
1.412 raeburn 10681: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10682: $user =~ s/:$//;
1.439 raeburn 10683: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10684: if ($end == -1 || $start == -1) {
10685: next;
10686: }
10687: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10688: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10689: my ($uname,$udom) = split(/:/,$user);
10690: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10691: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10692: $secmatch = 1;
10693: } elsif ($usec eq '') {
1.420 albertel 10694: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10695: $secmatch = 1;
10696: }
10697: } else {
10698: if (grep(/^\Q$usec\E$/,@{$sections})) {
10699: $secmatch = 1;
10700: }
10701: }
10702: if (!$secmatch) {
10703: next;
10704: }
1.288 raeburn 10705: }
1.419 raeburn 10706: if ($usec eq '') {
10707: $usec = 'none';
10708: }
1.275 raeburn 10709: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10710: if ($hidepriv) {
1.1075.2.36 raeburn 10711: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10712: (!$nothide{$uname.':'.$udom})) {
10713: next;
10714: }
10715: }
1.503 raeburn 10716: if ($end > 0 && $end < $now) {
1.439 raeburn 10717: $status = 'previous';
10718: } elsif ($start > $now) {
10719: $status = 'future';
10720: } else {
10721: $status = 'active';
10722: }
1.277 albertel 10723: foreach my $type (keys(%{$types})) {
1.275 raeburn 10724: if ($status eq $type) {
1.420 albertel 10725: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10726: push(@{$$users{$role}{$user}},$type);
10727: }
1.288 raeburn 10728: $match = 1;
10729: }
10730: }
1.419 raeburn 10731: if (($match) && (ref($userdata) eq 'HASH')) {
10732: if (!exists($$userdata{$uname.':'.$udom})) {
10733: &get_user_info($udom,$uname,\%idx,$userdata);
10734: }
1.420 albertel 10735: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10736: push(@{$seclists{$uname.':'.$udom}},$usec);
10737: }
1.609 raeburn 10738: if (ref($statushash) eq 'HASH') {
10739: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10740: }
1.275 raeburn 10741: }
10742: }
10743: }
10744: }
1.290 albertel 10745: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10746: if ((defined($cdom)) && (defined($cnum))) {
10747: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10748: if ( defined($csettings{'internal.courseowner'}) ) {
10749: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10750: next if ($owner eq '');
10751: my ($ownername,$ownerdom);
10752: if ($owner =~ /^([^:]+):([^:]+)$/) {
10753: $ownername = $1;
10754: $ownerdom = $2;
10755: } else {
10756: $ownername = $owner;
10757: $ownerdom = $cdom;
10758: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10759: }
10760: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10761: if (defined($userdata) &&
1.609 raeburn 10762: !exists($$userdata{$owner})) {
10763: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10764: if (!grep(/^none$/,@{$seclists{$owner}})) {
10765: push(@{$seclists{$owner}},'none');
10766: }
10767: if (ref($statushash) eq 'HASH') {
10768: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10769: }
1.290 albertel 10770: }
1.279 raeburn 10771: }
10772: }
10773: }
1.419 raeburn 10774: foreach my $user (keys(%seclists)) {
10775: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10776: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10777: }
1.275 raeburn 10778: }
10779: return;
10780: }
10781:
1.288 raeburn 10782: sub get_user_info {
10783: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10784: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10785: &plainname($uname,$udom,'lastname');
1.291 albertel 10786: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10787: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10788: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10789: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10790: return;
10791: }
1.275 raeburn 10792:
1.472 raeburn 10793: ###############################################
10794:
10795: =pod
10796:
10797: =item * &get_user_quota()
10798:
1.1075.2.41 raeburn 10799: Retrieves quota assigned for storage of user files.
10800: Default is to report quota for portfolio files.
1.472 raeburn 10801:
10802: Incoming parameters:
10803: 1. user's username
10804: 2. user's domain
1.1075.2.41 raeburn 10805: 3. quota name - portfolio, author, or course
10806: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10807: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10808: course
1.472 raeburn 10809:
10810: Returns:
1.1075.2.58 raeburn 10811: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10812: 2. (Optional) Type of setting: custom or default
10813: (individually assigned or default for user's
10814: institutional status).
10815: 3. (Optional) - User's institutional status (e.g., faculty, staff
10816: or student - types as defined in localenroll::inst_usertypes
10817: for user's domain, which determines default quota for user.
10818: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10819:
10820: If a value has been stored in the user's environment,
1.536 raeburn 10821: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10822: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10823:
10824: =cut
10825:
10826: ###############################################
10827:
10828:
10829: sub get_user_quota {
1.1075.2.42 raeburn 10830: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10831: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10832: if (!defined($udom)) {
10833: $udom = $env{'user.domain'};
10834: }
10835: if (!defined($uname)) {
10836: $uname = $env{'user.name'};
10837: }
10838: if (($udom eq '' || $uname eq '') ||
10839: ($udom eq 'public') && ($uname eq 'public')) {
10840: $quota = 0;
1.536 raeburn 10841: $quotatype = 'default';
10842: $defquota = 0;
1.472 raeburn 10843: } else {
1.536 raeburn 10844: my $inststatus;
1.1075.2.41 raeburn 10845: if ($quotaname eq 'course') {
10846: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10847: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10848: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10849: } else {
10850: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10851: $quota = $cenv{'internal.uploadquota'};
10852: }
1.536 raeburn 10853: } else {
1.1075.2.41 raeburn 10854: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10855: if ($quotaname eq 'author') {
10856: $quota = $env{'environment.authorquota'};
10857: } else {
10858: $quota = $env{'environment.portfolioquota'};
10859: }
10860: $inststatus = $env{'environment.inststatus'};
10861: } else {
10862: my %userenv =
10863: &Apache::lonnet::get('environment',['portfolioquota',
10864: 'authorquota','inststatus'],$udom,$uname);
10865: my ($tmp) = keys(%userenv);
10866: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10867: if ($quotaname eq 'author') {
10868: $quota = $userenv{'authorquota'};
10869: } else {
10870: $quota = $userenv{'portfolioquota'};
10871: }
10872: $inststatus = $userenv{'inststatus'};
10873: } else {
10874: undef(%userenv);
10875: }
10876: }
10877: }
10878: if ($quota eq '' || wantarray) {
10879: if ($quotaname eq 'course') {
10880: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10881: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10882: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10883: $defquota = $domdefs{$crstype.'quota'};
10884: }
10885: if ($defquota eq '') {
10886: $defquota = 500;
10887: }
1.1075.2.41 raeburn 10888: } else {
10889: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10890: }
10891: if ($quota eq '') {
10892: $quota = $defquota;
10893: $quotatype = 'default';
10894: } else {
10895: $quotatype = 'custom';
10896: }
1.472 raeburn 10897: }
10898: }
1.536 raeburn 10899: if (wantarray) {
10900: return ($quota,$quotatype,$settingstatus,$defquota);
10901: } else {
10902: return $quota;
10903: }
1.472 raeburn 10904: }
10905:
10906: ###############################################
10907:
10908: =pod
10909:
10910: =item * &default_quota()
10911:
1.536 raeburn 10912: Retrieves default quota assigned for storage of user portfolio files,
10913: given an (optional) user's institutional status.
1.472 raeburn 10914:
10915: Incoming parameters:
1.1075.2.42 raeburn 10916:
1.472 raeburn 10917: 1. domain
1.536 raeburn 10918: 2. (Optional) institutional status(es). This is a : separated list of
10919: status types (e.g., faculty, staff, student etc.)
10920: which apply to the user for whom the default is being retrieved.
10921: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10922: default quota will be returned.
10923: 3. quota name - portfolio, author, or course
10924: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10925:
10926: Returns:
1.1075.2.42 raeburn 10927:
1.1075.2.58 raeburn 10928: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10929: 2. (Optional) institutional type which determined the value of the
10930: default quota.
1.472 raeburn 10931:
10932: If a value has been stored in the domain's configuration db,
10933: it will return that, otherwise it returns 20 (for backwards
10934: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10935: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10936:
1.536 raeburn 10937: If the user's status includes multiple types (e.g., staff and student),
10938: the largest default quota which applies to the user determines the
10939: default quota returned.
10940:
1.472 raeburn 10941: =cut
10942:
10943: ###############################################
10944:
10945:
10946: sub default_quota {
1.1075.2.41 raeburn 10947: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10948: my ($defquota,$settingstatus);
10949: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10950: ['quotas'],$udom);
1.1075.2.41 raeburn 10951: my $key = 'defaultquota';
10952: if ($quotaname eq 'author') {
10953: $key = 'authorquota';
10954: }
1.622 raeburn 10955: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10956: if ($inststatus ne '') {
1.765 raeburn 10957: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10958: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10959: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10960: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10961: if ($defquota eq '') {
1.1075.2.41 raeburn 10962: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10963: $settingstatus = $item;
1.1075.2.41 raeburn 10964: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10965: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10966: $settingstatus = $item;
10967: }
10968: }
1.1075.2.41 raeburn 10969: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10970: if ($quotahash{'quotas'}{$item} ne '') {
10971: if ($defquota eq '') {
10972: $defquota = $quotahash{'quotas'}{$item};
10973: $settingstatus = $item;
10974: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10975: $defquota = $quotahash{'quotas'}{$item};
10976: $settingstatus = $item;
10977: }
1.536 raeburn 10978: }
10979: }
10980: }
10981: }
10982: if ($defquota eq '') {
1.1075.2.41 raeburn 10983: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10984: $defquota = $quotahash{'quotas'}{$key}{'default'};
10985: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10986: $defquota = $quotahash{'quotas'}{'default'};
10987: }
1.536 raeburn 10988: $settingstatus = 'default';
1.1075.2.42 raeburn 10989: if ($defquota eq '') {
10990: if ($quotaname eq 'author') {
10991: $defquota = 500;
10992: }
10993: }
1.536 raeburn 10994: }
10995: } else {
10996: $settingstatus = 'default';
1.1075.2.41 raeburn 10997: if ($quotaname eq 'author') {
10998: $defquota = 500;
10999: } else {
11000: $defquota = 20;
11001: }
1.536 raeburn 11002: }
11003: if (wantarray) {
11004: return ($defquota,$settingstatus);
1.472 raeburn 11005: } else {
1.536 raeburn 11006: return $defquota;
1.472 raeburn 11007: }
11008: }
11009:
1.1075.2.41 raeburn 11010: ###############################################
11011:
11012: =pod
11013:
1.1075.2.42 raeburn 11014: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 11015:
11016: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 11017: of existing file within authoring space will cause quota for the authoring
11018: space to be exceeded.
11019:
11020: Same, if upload of a file directly to a course/community via Course Editor
11021: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 11022:
1.1075.2.61 raeburn 11023: Inputs: 7
1.1075.2.42 raeburn 11024: 1. username or coursenum
1.1075.2.41 raeburn 11025: 2. domain
1.1075.2.42 raeburn 11026: 3. context ('author' or 'course')
1.1075.2.41 raeburn 11027: 4. filename of file for which action is being requested
11028: 5. filesize (kB) of file
11029: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 11030: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 11031:
11032: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
11033: otherwise return null.
11034:
1.1075.2.42 raeburn 11035: =back
11036:
1.1075.2.41 raeburn 11037: =cut
11038:
1.1075.2.42 raeburn 11039: sub excess_filesize_warning {
1.1075.2.59 raeburn 11040: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 11041: my $current_disk_usage = 0;
1.1075.2.59 raeburn 11042: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 11043: if ($context eq 'author') {
11044: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11045: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11046: } else {
11047: foreach my $subdir ('docs','supplemental') {
11048: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11049: }
11050: }
1.1075.2.41 raeburn 11051: $disk_quota = int($disk_quota * 1000);
11052: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 11053: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 11054: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 11055: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11056: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 11057: $disk_quota,$current_disk_usage).
11058: '</p>';
11059: }
11060: return;
11061: }
11062:
11063: ###############################################
11064:
11065:
1.384 raeburn 11066: sub get_secgrprole_info {
11067: my ($cdom,$cnum,$needroles,$type) = @_;
11068: my %sections_count = &get_sections($cdom,$cnum);
11069: my @sections = (sort {$a <=> $b} keys(%sections_count));
11070: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11071: my @groups = sort(keys(%curr_groups));
11072: my $allroles = [];
11073: my $rolehash;
11074: my $accesshash = {
11075: active => 'Currently has access',
11076: future => 'Will have future access',
11077: previous => 'Previously had access',
11078: };
11079: if ($needroles) {
11080: $rolehash = {'all' => 'all'};
1.385 albertel 11081: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11082: if (&Apache::lonnet::error(%user_roles)) {
11083: undef(%user_roles);
11084: }
11085: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11086: my ($role)=split(/\:/,$item,2);
11087: if ($role eq 'cr') { next; }
11088: if ($role =~ /^cr/) {
11089: $$rolehash{$role} = (split('/',$role))[3];
11090: } else {
11091: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11092: }
11093: }
11094: foreach my $key (sort(keys(%{$rolehash}))) {
11095: push(@{$allroles},$key);
11096: }
11097: push (@{$allroles},'st');
11098: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11099: }
11100: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11101: }
11102:
1.555 raeburn 11103: sub user_picker {
1.1075.2.127 raeburn 11104: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11105: my $currdom = $dom;
1.1075.2.114 raeburn 11106: my @alldoms = &Apache::lonnet::all_domains();
11107: if (@alldoms == 1) {
11108: my %domsrch = &Apache::lonnet::get_dom('configuration',
11109: ['directorysrch'],$alldoms[0]);
11110: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11111: my $showdom = $domdesc;
11112: if ($showdom eq '') {
11113: $showdom = $dom;
11114: }
11115: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11116: if ((!$domsrch{'directorysrch'}{'available'}) &&
11117: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11118: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11119: }
11120: }
11121: }
1.555 raeburn 11122: my %curr_selected = (
11123: srchin => 'dom',
1.580 raeburn 11124: srchby => 'lastname',
1.555 raeburn 11125: );
11126: my $srchterm;
1.625 raeburn 11127: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11128: if ($srch->{'srchby'} ne '') {
11129: $curr_selected{'srchby'} = $srch->{'srchby'};
11130: }
11131: if ($srch->{'srchin'} ne '') {
11132: $curr_selected{'srchin'} = $srch->{'srchin'};
11133: }
11134: if ($srch->{'srchtype'} ne '') {
11135: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11136: }
11137: if ($srch->{'srchdomain'} ne '') {
11138: $currdom = $srch->{'srchdomain'};
11139: }
11140: $srchterm = $srch->{'srchterm'};
11141: }
1.1075.2.98 raeburn 11142: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11143: 'usr' => 'Search criteria',
1.563 raeburn 11144: 'doma' => 'Domain/institution to search',
1.558 albertel 11145: 'uname' => 'username',
11146: 'lastname' => 'last name',
1.555 raeburn 11147: 'lastfirst' => 'last name, first name',
1.558 albertel 11148: 'crs' => 'in this course',
1.576 raeburn 11149: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11150: 'alc' => 'all LON-CAPA',
1.573 raeburn 11151: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11152: 'exact' => 'is',
11153: 'contains' => 'contains',
1.569 raeburn 11154: 'begins' => 'begins with',
1.1075.2.98 raeburn 11155: );
11156: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11157: 'youm' => "You must include some text to search for.",
11158: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11159: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11160: 'yomc' => "You must choose a domain when using an institutional directory search.",
11161: 'ymcd' => "You must choose a domain when using a domain search.",
11162: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11163: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11164: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11165: );
1.1075.2.98 raeburn 11166: &html_escape(\%html_lt);
11167: &js_escape(\%js_lt);
1.1075.2.115 raeburn 11168: my $domform;
1.1075.2.126 raeburn 11169: my $allow_blank = 1;
1.1075.2.115 raeburn 11170: if ($fixeddom) {
1.1075.2.126 raeburn 11171: $allow_blank = 0;
11172: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 11173: } else {
1.1075.2.126 raeburn 11174: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 11175: }
1.563 raeburn 11176: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11177:
11178: my @srchins = ('crs','dom','alc','instd');
11179:
11180: foreach my $option (@srchins) {
11181: # FIXME 'alc' option unavailable until
11182: # loncreateuser::print_user_query_page()
11183: # has been completed.
11184: next if ($option eq 'alc');
1.880 raeburn 11185: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11186: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 11187: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11188: if ($curr_selected{'srchin'} eq $option) {
11189: $srchinsel .= '
1.1075.2.98 raeburn 11190: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11191: } else {
11192: $srchinsel .= '
1.1075.2.98 raeburn 11193: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11194: }
1.555 raeburn 11195: }
1.563 raeburn 11196: $srchinsel .= "\n </select>\n";
1.555 raeburn 11197:
11198: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11199: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11200: if ($curr_selected{'srchby'} eq $option) {
11201: $srchbysel .= '
1.1075.2.98 raeburn 11202: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11203: } else {
11204: $srchbysel .= '
1.1075.2.98 raeburn 11205: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11206: }
11207: }
11208: $srchbysel .= "\n </select>\n";
11209:
11210: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11211: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11212: if ($curr_selected{'srchtype'} eq $option) {
11213: $srchtypesel .= '
1.1075.2.98 raeburn 11214: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11215: } else {
11216: $srchtypesel .= '
1.1075.2.98 raeburn 11217: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11218: }
11219: }
11220: $srchtypesel .= "\n </select>\n";
11221:
1.558 albertel 11222: my ($newuserscript,$new_user_create);
1.994 raeburn 11223: my $context_dom = $env{'request.role.domain'};
11224: if ($context eq 'requestcrs') {
11225: if ($env{'form.coursedom'} ne '') {
11226: $context_dom = $env{'form.coursedom'};
11227: }
11228: }
1.556 raeburn 11229: if ($forcenewuser) {
1.576 raeburn 11230: if (ref($srch) eq 'HASH') {
1.994 raeburn 11231: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11232: if ($cancreate) {
11233: $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>';
11234: } else {
1.799 bisitz 11235: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11236: my %usertypetext = (
11237: official => 'institutional',
11238: unofficial => 'non-institutional',
11239: );
1.799 bisitz 11240: $new_user_create = '<p class="LC_warning">'
11241: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11242: .' '
11243: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11244: ,'<a href="'.$helplink.'">','</a>')
11245: .'</p><br />';
1.627 raeburn 11246: }
1.576 raeburn 11247: }
11248: }
11249:
1.556 raeburn 11250: $newuserscript = <<"ENDSCRIPT";
11251:
1.570 raeburn 11252: function setSearch(createnew,callingForm) {
1.556 raeburn 11253: if (createnew == 1) {
1.570 raeburn 11254: for (var i=0; i<callingForm.srchby.length; i++) {
11255: if (callingForm.srchby.options[i].value == 'uname') {
11256: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11257: }
11258: }
1.570 raeburn 11259: for (var i=0; i<callingForm.srchin.length; i++) {
11260: if ( callingForm.srchin.options[i].value == 'dom') {
11261: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11262: }
11263: }
1.570 raeburn 11264: for (var i=0; i<callingForm.srchtype.length; i++) {
11265: if (callingForm.srchtype.options[i].value == 'exact') {
11266: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11267: }
11268: }
1.570 raeburn 11269: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11270: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11271: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11272: }
11273: }
11274: }
11275: }
11276: ENDSCRIPT
1.558 albertel 11277:
1.556 raeburn 11278: }
11279:
1.555 raeburn 11280: my $output = <<"END_BLOCK";
1.556 raeburn 11281: <script type="text/javascript">
1.824 bisitz 11282: // <![CDATA[
1.570 raeburn 11283: function validateEntry(callingForm) {
1.558 albertel 11284:
1.556 raeburn 11285: var checkok = 1;
1.558 albertel 11286: var srchin;
1.570 raeburn 11287: for (var i=0; i<callingForm.srchin.length; i++) {
11288: if ( callingForm.srchin[i].checked ) {
11289: srchin = callingForm.srchin[i].value;
1.558 albertel 11290: }
11291: }
11292:
1.570 raeburn 11293: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11294: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11295: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11296: var srchterm = callingForm.srchterm.value;
11297: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11298: var msg = "";
11299:
11300: if (srchterm == "") {
11301: checkok = 0;
1.1075.2.98 raeburn 11302: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11303: }
11304:
1.569 raeburn 11305: if (srchtype== 'begins') {
11306: if (srchterm.length < 2) {
11307: checkok = 0;
1.1075.2.98 raeburn 11308: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11309: }
11310: }
11311:
1.556 raeburn 11312: if (srchtype== 'contains') {
11313: if (srchterm.length < 3) {
11314: checkok = 0;
1.1075.2.98 raeburn 11315: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11316: }
11317: }
11318: if (srchin == 'instd') {
11319: if (srchdomain == '') {
11320: checkok = 0;
1.1075.2.98 raeburn 11321: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11322: }
11323: }
11324: if (srchin == 'dom') {
11325: if (srchdomain == '') {
11326: checkok = 0;
1.1075.2.98 raeburn 11327: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11328: }
11329: }
11330: if (srchby == 'lastfirst') {
11331: if (srchterm.indexOf(",") == -1) {
11332: checkok = 0;
1.1075.2.98 raeburn 11333: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11334: }
11335: if (srchterm.indexOf(",") == srchterm.length -1) {
11336: checkok = 0;
1.1075.2.98 raeburn 11337: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11338: }
11339: }
11340: if (checkok == 0) {
1.1075.2.98 raeburn 11341: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11342: return;
11343: }
11344: if (checkok == 1) {
1.570 raeburn 11345: callingForm.submit();
1.556 raeburn 11346: }
11347: }
11348:
11349: $newuserscript
11350:
1.824 bisitz 11351: // ]]>
1.556 raeburn 11352: </script>
1.558 albertel 11353:
11354: $new_user_create
11355:
1.555 raeburn 11356: END_BLOCK
1.558 albertel 11357:
1.876 raeburn 11358: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 11359: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11360: $domform.
11361: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 11362: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11363: $srchbysel.
11364: $srchtypesel.
11365: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11366: $srchinsel.
11367: &Apache::lonhtmlcommon::row_closure(1).
11368: &Apache::lonhtmlcommon::end_pick_box().
11369: '<br />';
1.1075.2.114 raeburn 11370: return ($output,1);
1.555 raeburn 11371: }
11372:
1.612 raeburn 11373: sub user_rule_check {
1.615 raeburn 11374: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 11375: my ($response,%inst_response);
1.612 raeburn 11376: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 11377: if (keys(%{$usershash}) > 1) {
11378: my (%by_username,%by_id,%userdoms);
11379: my $checkid;
1.612 raeburn 11380: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 11381: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11382: $checkid = 1;
11383: }
11384: }
11385: foreach my $user (keys(%{$usershash})) {
11386: my ($uname,$udom) = split(/:/,$user);
11387: if ($checkid) {
11388: if (ref($usershash->{$user}) eq 'HASH') {
11389: if ($usershash->{$user}->{'id'} ne '') {
11390: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
11391: $userdoms{$udom} = 1;
11392: if (ref($inst_results) eq 'HASH') {
11393: $inst_results->{$uname.':'.$udom} = {};
11394: }
11395: }
11396: }
11397: } else {
11398: $by_username{$udom}{$uname} = 1;
11399: $userdoms{$udom} = 1;
11400: if (ref($inst_results) eq 'HASH') {
11401: $inst_results->{$uname.':'.$udom} = {};
11402: }
11403: }
11404: }
11405: foreach my $udom (keys(%userdoms)) {
11406: if (!$got_rules->{$udom}) {
11407: my %domconfig = &Apache::lonnet::get_dom('configuration',
11408: ['usercreation'],$udom);
11409: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11410: foreach my $item ('username','id') {
11411: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11412: $$curr_rules{$udom}{$item} =
11413: $domconfig{'usercreation'}{$item.'_rule'};
11414: }
11415: }
11416: }
11417: $got_rules->{$udom} = 1;
11418: }
11419: }
11420: if ($checkid) {
11421: foreach my $udom (keys(%by_id)) {
11422: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11423: if ($outcome eq 'ok') {
11424: foreach my $id (keys(%{$by_id{$udom}})) {
11425: my $uname = $by_id{$udom}{$id};
11426: $inst_response{$uname.':'.$udom} = $outcome;
11427: }
11428: if (ref($results) eq 'HASH') {
11429: foreach my $uname (keys(%{$results})) {
11430: if (exists($inst_response{$uname.':'.$udom})) {
11431: $inst_response{$uname.':'.$udom} = $outcome;
11432: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11433: }
11434: }
11435: }
11436: }
1.612 raeburn 11437: }
1.615 raeburn 11438: } else {
1.1075.2.99 raeburn 11439: foreach my $udom (keys(%by_username)) {
11440: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11441: if ($outcome eq 'ok') {
11442: foreach my $uname (keys(%{$by_username{$udom}})) {
11443: $inst_response{$uname.':'.$udom} = $outcome;
11444: }
11445: if (ref($results) eq 'HASH') {
11446: foreach my $uname (keys(%{$results})) {
11447: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11448: }
11449: }
11450: }
11451: }
1.612 raeburn 11452: }
1.1075.2.99 raeburn 11453: } elsif (keys(%{$usershash}) == 1) {
11454: my $user = (keys(%{$usershash}))[0];
11455: my ($uname,$udom) = split(/:/,$user);
11456: if (($udom ne '') && ($uname ne '')) {
11457: if (ref($usershash->{$user}) eq 'HASH') {
11458: if (ref($checks) eq 'HASH') {
11459: if (defined($checks->{'username'})) {
11460: ($inst_response{$user},%{$inst_results->{$user}}) =
11461: &Apache::lonnet::get_instuser($udom,$uname);
11462: } elsif (defined($checks->{'id'})) {
11463: if ($usershash->{$user}->{'id'} ne '') {
11464: ($inst_response{$user},%{$inst_results->{$user}}) =
11465: &Apache::lonnet::get_instuser($udom,undef,
11466: $usershash->{$user}->{'id'});
11467: } else {
11468: ($inst_response{$user},%{$inst_results->{$user}}) =
11469: &Apache::lonnet::get_instuser($udom,$uname);
11470: }
11471: }
11472: } else {
11473: ($inst_response{$user},%{$inst_results->{$user}}) =
11474: &Apache::lonnet::get_instuser($udom,$uname);
11475: return;
11476: }
11477: if (!$got_rules->{$udom}) {
11478: my %domconfig = &Apache::lonnet::get_dom('configuration',
11479: ['usercreation'],$udom);
11480: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11481: foreach my $item ('username','id') {
11482: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11483: $$curr_rules{$udom}{$item} =
11484: $domconfig{'usercreation'}{$item.'_rule'};
11485: }
11486: }
1.585 raeburn 11487: }
1.1075.2.99 raeburn 11488: $got_rules->{$udom} = 1;
1.585 raeburn 11489: }
11490: }
1.1075.2.99 raeburn 11491: } else {
11492: return;
11493: }
11494: } else {
11495: return;
11496: }
11497: foreach my $user (keys(%{$usershash})) {
11498: my ($uname,$udom) = split(/:/,$user);
11499: next if (($udom eq '') || ($uname eq ''));
11500: my $id;
11501: if (ref($inst_results) eq 'HASH') {
11502: if (ref($inst_results->{$user}) eq 'HASH') {
11503: $id = $inst_results->{$user}->{'id'};
11504: }
11505: }
11506: if ($id eq '') {
11507: if (ref($usershash->{$user})) {
11508: $id = $usershash->{$user}->{'id'};
11509: }
1.585 raeburn 11510: }
1.612 raeburn 11511: foreach my $item (keys(%{$checks})) {
11512: if (ref($$curr_rules{$udom}) eq 'HASH') {
11513: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11514: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 11515: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11516: $$curr_rules{$udom}{$item});
1.612 raeburn 11517: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11518: if ($rule_check{$rule}) {
11519: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 11520: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11521: if (ref($inst_results) eq 'HASH') {
11522: if (ref($inst_results->{$user}) eq 'HASH') {
11523: if (keys(%{$inst_results->{$user}}) == 0) {
11524: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 11525: } elsif ($item eq 'id') {
11526: if ($inst_results->{$user}->{'id'} eq '') {
11527: $$alerts{$item}{$udom}{$uname} = 1;
11528: }
1.615 raeburn 11529: }
1.612 raeburn 11530: }
11531: }
1.615 raeburn 11532: }
11533: last;
1.585 raeburn 11534: }
11535: }
11536: }
11537: }
11538: }
11539: }
11540: }
11541: }
1.612 raeburn 11542: return;
11543: }
11544:
11545: sub user_rule_formats {
11546: my ($domain,$domdesc,$curr_rules,$check) = @_;
11547: my %text = (
11548: 'username' => 'Usernames',
11549: 'id' => 'IDs',
11550: );
11551: my $output;
11552: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11553: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11554: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 11555: $output = '<br />'.
11556: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11557: '<span class="LC_cusr_emph">','</span>',$domdesc).
11558: ' <ul>';
1.612 raeburn 11559: foreach my $rule (@{$ruleorder}) {
11560: if (ref($curr_rules) eq 'ARRAY') {
11561: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11562: if (ref($rules->{$rule}) eq 'HASH') {
11563: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11564: $rules->{$rule}{'desc'}.'</li>';
11565: }
11566: }
11567: }
11568: }
11569: $output .= '</ul>';
11570: }
11571: }
11572: return $output;
11573: }
11574:
11575: sub instrule_disallow_msg {
1.615 raeburn 11576: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11577: my $response;
11578: my %text = (
11579: item => 'username',
11580: items => 'usernames',
11581: match => 'matches',
11582: do => 'does',
11583: action => 'a username',
11584: one => 'one',
11585: );
11586: if ($count > 1) {
11587: $text{'item'} = 'usernames';
11588: $text{'match'} ='match';
11589: $text{'do'} = 'do';
11590: $text{'action'} = 'usernames',
11591: $text{'one'} = 'ones';
11592: }
11593: if ($checkitem eq 'id') {
11594: $text{'items'} = 'IDs';
11595: $text{'item'} = 'ID';
11596: $text{'action'} = 'an ID';
1.615 raeburn 11597: if ($count > 1) {
11598: $text{'item'} = 'IDs';
11599: $text{'action'} = 'IDs';
11600: }
1.612 raeburn 11601: }
1.674 bisitz 11602: $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 11603: if ($mode eq 'upload') {
11604: if ($checkitem eq 'username') {
11605: $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'}.");
11606: } elsif ($checkitem eq 'id') {
1.674 bisitz 11607: $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 11608: }
1.669 raeburn 11609: } elsif ($mode eq 'selfcreate') {
11610: if ($checkitem eq 'id') {
11611: $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.");
11612: }
1.615 raeburn 11613: } else {
11614: if ($checkitem eq 'username') {
11615: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11616: } elsif ($checkitem eq 'id') {
11617: $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.");
11618: }
1.612 raeburn 11619: }
11620: return $response;
1.585 raeburn 11621: }
11622:
1.624 raeburn 11623: sub personal_data_fieldtitles {
11624: my %fieldtitles = &Apache::lonlocal::texthash (
11625: id => 'Student/Employee ID',
11626: permanentemail => 'E-mail address',
11627: lastname => 'Last Name',
11628: firstname => 'First Name',
11629: middlename => 'Middle Name',
11630: generation => 'Generation',
11631: gen => 'Generation',
1.765 raeburn 11632: inststatus => 'Affiliation',
1.624 raeburn 11633: );
11634: return %fieldtitles;
11635: }
11636:
1.642 raeburn 11637: sub sorted_inst_types {
11638: my ($dom) = @_;
1.1075.2.70 raeburn 11639: my ($usertypes,$order);
11640: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11641: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11642: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11643: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11644: } else {
11645: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11646: }
1.642 raeburn 11647: my $othertitle = &mt('All users');
11648: if ($env{'request.course.id'}) {
1.668 raeburn 11649: $othertitle = &mt('Any users');
1.642 raeburn 11650: }
11651: my @types;
11652: if (ref($order) eq 'ARRAY') {
11653: @types = @{$order};
11654: }
11655: if (@types == 0) {
11656: if (ref($usertypes) eq 'HASH') {
11657: @types = sort(keys(%{$usertypes}));
11658: }
11659: }
11660: if (keys(%{$usertypes}) > 0) {
11661: $othertitle = &mt('Other users');
11662: }
11663: return ($othertitle,$usertypes,\@types);
11664: }
11665:
1.645 raeburn 11666: sub get_institutional_codes {
1.1075.2.157 raeburn 11667: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11668: # Get complete list of course sections to update
11669: my @currsections = ();
11670: my @currxlists = ();
1.1075.2.157 raeburn 11671: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11672: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11673: my $crskey = $crs.':'.$coursecode;
11674: @{$unclutteredsec{$crskey}} = ();
11675: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11676:
11677: if ($$settings{'internal.sectionnums'} ne '') {
11678: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11679: }
11680:
11681: if ($$settings{'internal.crosslistings'} ne '') {
11682: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11683: }
11684:
11685: if (@currxlists > 0) {
1.1075.2.157 raeburn 11686: foreach my $xl (@currxlists) {
11687: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11688: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11689: push(@{$allcourses},$1);
1.645 raeburn 11690: $$LC_code{$1} = $2;
11691: }
11692: }
11693: }
11694: }
1.1075.2.157 raeburn 11695:
1.645 raeburn 11696: if (@currsections > 0) {
1.1075.2.157 raeburn 11697: foreach my $sec (@currsections) {
11698: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11699: my $instsec = $1;
1.645 raeburn 11700: my $lc_sec = $2;
1.1075.2.157 raeburn 11701: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11702: push(@{$unclutteredsec{$crskey}},$instsec);
11703: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11704: }
11705: }
11706: }
11707: }
11708:
11709: if (@{$unclutteredsec{$crskey}} > 0) {
11710: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11711: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11712: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11713: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11714: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11715: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11716: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11717: }
11718: }
11719: }
11720: }
11721: return;
11722: }
11723:
1.971 raeburn 11724: sub get_standard_codeitems {
11725: return ('Year','Semester','Department','Number','Section');
11726: }
11727:
1.112 bowersj2 11728: =pod
11729:
1.780 raeburn 11730: =head1 Slot Helpers
11731:
11732: =over 4
11733:
11734: =item * sorted_slots()
11735:
1.1040 raeburn 11736: Sorts an array of slot names in order of an optional sort key,
11737: default sort is by slot start time (earliest first).
1.780 raeburn 11738:
11739: Inputs:
11740:
11741: =over 4
11742:
11743: slotsarr - Reference to array of unsorted slot names.
11744:
11745: slots - Reference to hash of hash, where outer hash keys are slot names.
11746:
1.1040 raeburn 11747: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11748:
1.549 albertel 11749: =back
11750:
1.780 raeburn 11751: Returns:
11752:
11753: =over 4
11754:
1.1040 raeburn 11755: sorted - An array of slot names sorted by a specified sort key
11756: (default sort key is start time of the slot).
1.780 raeburn 11757:
11758: =back
11759:
11760: =cut
11761:
11762:
11763: sub sorted_slots {
1.1040 raeburn 11764: my ($slotsarr,$slots,$sortkey) = @_;
11765: if ($sortkey eq '') {
11766: $sortkey = 'starttime';
11767: }
1.780 raeburn 11768: my @sorted;
11769: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11770: @sorted =
11771: sort {
11772: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11773: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11774: }
11775: if (ref($slots->{$a})) { return -1;}
11776: if (ref($slots->{$b})) { return 1;}
11777: return 0;
11778: } @{$slotsarr};
11779: }
11780: return @sorted;
11781: }
11782:
1.1040 raeburn 11783: =pod
11784:
11785: =item * get_future_slots()
11786:
11787: Inputs:
11788:
11789: =over 4
11790:
11791: cnum - course number
11792:
11793: cdom - course domain
11794:
11795: now - current UNIX time
11796:
11797: symb - optional symb
11798:
11799: =back
11800:
11801: Returns:
11802:
11803: =over 4
11804:
11805: sorted_reservable - ref to array of student_schedulable slots currently
11806: reservable, ordered by end date of reservation period.
11807:
11808: reservable_now - ref to hash of student_schedulable slots currently
11809: reservable.
11810:
11811: Keys in inner hash are:
11812: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11813: (b) endreserve: end date of reservation period.
11814: (c) uniqueperiod: start,end dates when slot is to be uniquely
11815: selected.
1.1040 raeburn 11816:
11817: sorted_future - ref to array of student_schedulable slots reservable in
11818: the future, ordered by start date of reservation period.
11819:
11820: future_reservable - ref to hash of student_schedulable slots reservable
11821: in the future.
11822:
11823: Keys in inner hash are:
11824: (a) symb: either blank or symb to which slot use is restricted.
11825: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11826: (c) uniqueperiod: start,end dates when slot is to be uniquely
11827: selected.
1.1040 raeburn 11828:
11829: =back
11830:
11831: =cut
11832:
11833: sub get_future_slots {
11834: my ($cnum,$cdom,$now,$symb) = @_;
11835: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11836: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11837: foreach my $slot (keys(%slots)) {
11838: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11839: if ($symb) {
11840: next if (($slots{$slot}->{'symb'} ne '') &&
11841: ($slots{$slot}->{'symb'} ne $symb));
11842: }
11843: if (($slots{$slot}->{'starttime'} > $now) &&
11844: ($slots{$slot}->{'endtime'} > $now)) {
11845: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11846: my $userallowed = 0;
11847: if ($slots{$slot}->{'allowedsections'}) {
11848: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11849: if (!defined($env{'request.role.sec'})
11850: && grep(/^No section assigned$/,@allowed_sec)) {
11851: $userallowed=1;
11852: } else {
11853: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11854: $userallowed=1;
11855: }
11856: }
11857: unless ($userallowed) {
11858: if (defined($env{'request.course.groups'})) {
11859: my @groups = split(/:/,$env{'request.course.groups'});
11860: foreach my $group (@groups) {
11861: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11862: $userallowed=1;
11863: last;
11864: }
11865: }
11866: }
11867: }
11868: }
11869: if ($slots{$slot}->{'allowedusers'}) {
11870: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11871: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11872: if (grep(/^\Q$user\E$/,@allowed_users)) {
11873: $userallowed = 1;
11874: }
11875: }
11876: next unless($userallowed);
11877: }
11878: my $startreserve = $slots{$slot}->{'startreserve'};
11879: my $endreserve = $slots{$slot}->{'endreserve'};
11880: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11881: my $uniqueperiod;
11882: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11883: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11884: }
1.1040 raeburn 11885: if (($startreserve < $now) &&
11886: (!$endreserve || $endreserve > $now)) {
11887: my $lastres = $endreserve;
11888: if (!$lastres) {
11889: $lastres = $slots{$slot}->{'starttime'};
11890: }
11891: $reservable_now{$slot} = {
11892: symb => $symb,
1.1075.2.104 raeburn 11893: endreserve => $lastres,
11894: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11895: };
11896: } elsif (($startreserve > $now) &&
11897: (!$endreserve || $endreserve > $startreserve)) {
11898: $future_reservable{$slot} = {
11899: symb => $symb,
1.1075.2.104 raeburn 11900: startreserve => $startreserve,
11901: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11902: };
11903: }
11904: }
11905: }
11906: my @unsorted_reservable = keys(%reservable_now);
11907: if (@unsorted_reservable > 0) {
11908: @sorted_reservable =
11909: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11910: }
11911: my @unsorted_future = keys(%future_reservable);
11912: if (@unsorted_future > 0) {
11913: @sorted_future =
11914: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11915: }
11916: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11917: }
1.780 raeburn 11918:
11919: =pod
11920:
1.1057 foxr 11921: =back
11922:
1.549 albertel 11923: =head1 HTTP Helpers
11924:
11925: =over 4
11926:
1.648 raeburn 11927: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11928:
1.258 albertel 11929: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11930: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11931: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11932:
11933: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11934: $possible_names is an ref to an array of form element names. As an example:
11935: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11936: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11937:
11938: =cut
1.1 albertel 11939:
1.6 albertel 11940: sub get_unprocessed_cgi {
1.25 albertel 11941: my ($query,$possible_names)= @_;
1.26 matthew 11942: # $Apache::lonxml::debug=1;
1.356 albertel 11943: foreach my $pair (split(/&/,$query)) {
11944: my ($name, $value) = split(/=/,$pair);
1.369 www 11945: $name = &unescape($name);
1.25 albertel 11946: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11947: $value =~ tr/+/ /;
11948: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11949: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11950: }
1.16 harris41 11951: }
1.6 albertel 11952: }
11953:
1.112 bowersj2 11954: =pod
11955:
1.648 raeburn 11956: =item * &cacheheader()
1.112 bowersj2 11957:
11958: returns cache-controlling header code
11959:
11960: =cut
11961:
1.7 albertel 11962: sub cacheheader {
1.258 albertel 11963: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11964: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11965: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11966: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11967: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11968: return $output;
1.7 albertel 11969: }
11970:
1.112 bowersj2 11971: =pod
11972:
1.648 raeburn 11973: =item * &no_cache($r)
1.112 bowersj2 11974:
11975: specifies header code to not have cache
11976:
11977: =cut
11978:
1.9 albertel 11979: sub no_cache {
1.216 albertel 11980: my ($r) = @_;
11981: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11982: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11983: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11984: $r->no_cache(1);
11985: $r->header_out("Expires" => $date);
11986: $r->header_out("Pragma" => "no-cache");
1.123 www 11987: }
11988:
11989: sub content_type {
1.181 albertel 11990: my ($r,$type,$charset) = @_;
1.299 foxr 11991: if ($r) {
11992: # Note that printout.pl calls this with undef for $r.
11993: &no_cache($r);
11994: }
1.258 albertel 11995: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11996: unless ($charset) {
11997: $charset=&Apache::lonlocal::current_encoding;
11998: }
11999: if ($charset) { $type.='; charset='.$charset; }
12000: if ($r) {
12001: $r->content_type($type);
12002: } else {
12003: print("Content-type: $type\n\n");
12004: }
1.9 albertel 12005: }
1.25 albertel 12006:
1.112 bowersj2 12007: =pod
12008:
1.648 raeburn 12009: =item * &add_to_env($name,$value)
1.112 bowersj2 12010:
1.258 albertel 12011: adds $name to the %env hash with value
1.112 bowersj2 12012: $value, if $name already exists, the entry is converted to an array
12013: reference and $value is added to the array.
12014:
12015: =cut
12016:
1.25 albertel 12017: sub add_to_env {
12018: my ($name,$value)=@_;
1.258 albertel 12019: if (defined($env{$name})) {
12020: if (ref($env{$name})) {
1.25 albertel 12021: #already have multiple values
1.258 albertel 12022: push(@{ $env{$name} },$value);
1.25 albertel 12023: } else {
12024: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12025: my $first=$env{$name};
12026: undef($env{$name});
12027: push(@{ $env{$name} },$first,$value);
1.25 albertel 12028: }
12029: } else {
1.258 albertel 12030: $env{$name}=$value;
1.25 albertel 12031: }
1.31 albertel 12032: }
1.149 albertel 12033:
12034: =pod
12035:
1.648 raeburn 12036: =item * &get_env_multiple($name)
1.149 albertel 12037:
1.258 albertel 12038: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12039: values may be defined and end up as an array ref.
12040:
12041: returns an array of values
12042:
12043: =cut
12044:
12045: sub get_env_multiple {
12046: my ($name) = @_;
12047: my @values;
1.258 albertel 12048: if (defined($env{$name})) {
1.149 albertel 12049: # exists is it an array
1.258 albertel 12050: if (ref($env{$name})) {
12051: @values=@{ $env{$name} };
1.149 albertel 12052: } else {
1.258 albertel 12053: $values[0]=$env{$name};
1.149 albertel 12054: }
12055: }
12056: return(@values);
12057: }
12058:
1.660 raeburn 12059: sub ask_for_embedded_content {
12060: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12061: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 12062: %currsubfile,%unused,$rem);
1.1071 raeburn 12063: my $counter = 0;
12064: my $numnew = 0;
1.987 raeburn 12065: my $numremref = 0;
12066: my $numinvalid = 0;
12067: my $numpathchg = 0;
12068: my $numexisting = 0;
1.1071 raeburn 12069: my $numunused = 0;
12070: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 12071: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12072: my $heading = &mt('Upload embedded files');
12073: my $buttontext = &mt('Upload');
12074:
1.1075.2.11 raeburn 12075: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 12076: if ($actionurl eq '/adm/dependencies') {
12077: $navmap = Apache::lonnavmaps::navmap->new();
12078: }
12079: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12080: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 12081: }
1.1075.2.35 raeburn 12082: if (($actionurl eq '/adm/portfolio') ||
12083: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12084: my $current_path='/';
12085: if ($env{'form.currentpath'}) {
12086: $current_path = $env{'form.currentpath'};
12087: }
12088: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 12089: $udom = $cdom;
12090: $uname = $cnum;
1.984 raeburn 12091: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12092: } else {
12093: $udom = $env{'user.domain'};
12094: $uname = $env{'user.name'};
12095: $url = '/userfiles/portfolio';
12096: }
1.987 raeburn 12097: $toplevel = $url.'/';
1.984 raeburn 12098: $url .= $current_path;
12099: $getpropath = 1;
1.987 raeburn 12100: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12101: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12102: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12103: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12104: $toplevel = $url;
1.984 raeburn 12105: if ($rest ne '') {
1.987 raeburn 12106: $url .= $rest;
12107: }
12108: } elsif ($actionurl eq '/adm/coursedocs') {
12109: if (ref($args) eq 'HASH') {
1.1071 raeburn 12110: $url = $args->{'docs_url'};
12111: $toplevel = $url;
1.1075.2.11 raeburn 12112: if ($args->{'context'} eq 'paste') {
12113: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12114: ($path) =
12115: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12116: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12117: $fileloc =~ s{^/}{};
12118: }
1.1071 raeburn 12119: }
12120: } elsif ($actionurl eq '/adm/dependencies') {
12121: if ($env{'request.course.id'} ne '') {
12122: if (ref($args) eq 'HASH') {
12123: $url = $args->{'docs_url'};
12124: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 12125: $toplevel = $url;
12126: unless ($toplevel =~ m{^/}) {
12127: $toplevel = "/$url";
12128: }
1.1075.2.11 raeburn 12129: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 12130: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12131: $path = $1;
12132: } else {
12133: ($path) =
12134: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12135: }
1.1075.2.79 raeburn 12136: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12137: $fileloc = $toplevel;
12138: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12139: my ($udom,$uname,$fname) =
12140: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12141: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12142: } else {
12143: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12144: }
1.1071 raeburn 12145: $fileloc =~ s{^/}{};
12146: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12147: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12148: }
1.987 raeburn 12149: }
1.1075.2.35 raeburn 12150: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12151: $udom = $cdom;
12152: $uname = $cnum;
12153: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12154: $toplevel = $url;
12155: $path = $url;
12156: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12157: $fileloc =~ s{^/}{};
12158: }
12159: foreach my $file (keys(%{$allfiles})) {
12160: my $embed_file;
12161: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12162: $embed_file = $1;
12163: } else {
12164: $embed_file = $file;
12165: }
1.1075.2.55 raeburn 12166: my ($absolutepath,$cleaned_file);
12167: if ($embed_file =~ m{^\w+://}) {
12168: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 12169: $newfiles{$cleaned_file} = 1;
12170: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12171: } else {
1.1075.2.55 raeburn 12172: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12173: if ($embed_file =~ m{^/}) {
12174: $absolutepath = $embed_file;
12175: }
1.1075.2.47 raeburn 12176: if ($cleaned_file =~ m{/}) {
12177: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12178: $path = &check_for_traversal($path,$url,$toplevel);
12179: my $item = $fname;
12180: if ($path ne '') {
12181: $item = $path.'/'.$fname;
12182: $subdependencies{$path}{$fname} = 1;
12183: } else {
12184: $dependencies{$item} = 1;
12185: }
12186: if ($absolutepath) {
12187: $mapping{$item} = $absolutepath;
12188: } else {
12189: $mapping{$item} = $embed_file;
12190: }
12191: } else {
12192: $dependencies{$embed_file} = 1;
12193: if ($absolutepath) {
1.1075.2.47 raeburn 12194: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12195: } else {
1.1075.2.47 raeburn 12196: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12197: }
12198: }
1.984 raeburn 12199: }
12200: }
1.1071 raeburn 12201: my $dirptr = 16384;
1.984 raeburn 12202: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12203: $currsubfile{$path} = {};
1.1075.2.35 raeburn 12204: if (($actionurl eq '/adm/portfolio') ||
12205: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12206: my ($sublistref,$listerror) =
12207: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12208: if (ref($sublistref) eq 'ARRAY') {
12209: foreach my $line (@{$sublistref}) {
12210: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12211: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12212: }
1.984 raeburn 12213: }
1.987 raeburn 12214: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12215: if (opendir(my $dir,$url.'/'.$path)) {
12216: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12217: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12218: }
1.1075.2.11 raeburn 12219: } elsif (($actionurl eq '/adm/dependencies') ||
12220: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12221: ($args->{'context'} eq 'paste')) ||
12222: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12223: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 12224: my $dir;
12225: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12226: $dir = $fileloc;
12227: } else {
12228: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12229: }
1.1071 raeburn 12230: if ($dir ne '') {
12231: my ($sublistref,$listerror) =
12232: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12233: if (ref($sublistref) eq 'ARRAY') {
12234: foreach my $line (@{$sublistref}) {
12235: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12236: undef,$mtime)=split(/\&/,$line,12);
12237: unless (($testdir&$dirptr) ||
12238: ($file_name =~ /^\.\.?$/)) {
12239: $currsubfile{$path}{$file_name} = [$size,$mtime];
12240: }
12241: }
12242: }
12243: }
1.984 raeburn 12244: }
12245: }
12246: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12247: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12248: my $item = $path.'/'.$file;
12249: unless ($mapping{$item} eq $item) {
12250: $pathchanges{$item} = 1;
12251: }
12252: $existing{$item} = 1;
12253: $numexisting ++;
12254: } else {
12255: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12256: }
12257: }
1.1071 raeburn 12258: if ($actionurl eq '/adm/dependencies') {
12259: foreach my $path (keys(%currsubfile)) {
12260: if (ref($currsubfile{$path}) eq 'HASH') {
12261: foreach my $file (keys(%{$currsubfile{$path}})) {
12262: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 12263: next if (($rem ne '') &&
12264: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12265: (ref($navmap) &&
12266: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12267: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12268: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12269: $unused{$path.'/'.$file} = 1;
12270: }
12271: }
12272: }
12273: }
12274: }
1.984 raeburn 12275: }
1.987 raeburn 12276: my %currfile;
1.1075.2.35 raeburn 12277: if (($actionurl eq '/adm/portfolio') ||
12278: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12279: my ($dirlistref,$listerror) =
12280: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12281: if (ref($dirlistref) eq 'ARRAY') {
12282: foreach my $line (@{$dirlistref}) {
12283: my ($file_name,$rest) = split(/\&/,$line,2);
12284: $currfile{$file_name} = 1;
12285: }
1.984 raeburn 12286: }
1.987 raeburn 12287: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12288: if (opendir(my $dir,$url)) {
1.987 raeburn 12289: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12290: map {$currfile{$_} = 1;} @dir_list;
12291: }
1.1075.2.11 raeburn 12292: } elsif (($actionurl eq '/adm/dependencies') ||
12293: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 12294: ($args->{'context'} eq 'paste')) ||
12295: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12296: if ($env{'request.course.id'} ne '') {
12297: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12298: if ($dir ne '') {
12299: my ($dirlistref,$listerror) =
12300: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12301: if (ref($dirlistref) eq 'ARRAY') {
12302: foreach my $line (@{$dirlistref}) {
12303: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12304: $size,undef,$mtime)=split(/\&/,$line,12);
12305: unless (($testdir&$dirptr) ||
12306: ($file_name =~ /^\.\.?$/)) {
12307: $currfile{$file_name} = [$size,$mtime];
12308: }
12309: }
12310: }
12311: }
12312: }
1.984 raeburn 12313: }
12314: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12315: if (exists($currfile{$file})) {
1.987 raeburn 12316: unless ($mapping{$file} eq $file) {
12317: $pathchanges{$file} = 1;
12318: }
12319: $existing{$file} = 1;
12320: $numexisting ++;
12321: } else {
1.984 raeburn 12322: $newfiles{$file} = 1;
12323: }
12324: }
1.1071 raeburn 12325: foreach my $file (keys(%currfile)) {
12326: unless (($file eq $filename) ||
12327: ($file eq $filename.'.bak') ||
12328: ($dependencies{$file})) {
1.1075.2.11 raeburn 12329: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 12330: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12331: next if (($rem ne '') &&
12332: (($env{"httpref.$rem".$file} ne '') ||
12333: (ref($navmap) &&
12334: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12335: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12336: ($navmap->getResourceByUrl($rem.$1)))))));
12337: }
1.1075.2.11 raeburn 12338: }
1.1071 raeburn 12339: $unused{$file} = 1;
12340: }
12341: }
1.1075.2.11 raeburn 12342: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12343: ($args->{'context'} eq 'paste')) {
12344: $counter = scalar(keys(%existing));
12345: $numpathchg = scalar(keys(%pathchanges));
12346: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 12347: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12348: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12349: $counter = scalar(keys(%existing));
12350: $numpathchg = scalar(keys(%pathchanges));
12351: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 12352: }
1.984 raeburn 12353: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12354: if ($actionurl eq '/adm/dependencies') {
12355: next if ($embed_file =~ m{^\w+://});
12356: }
1.660 raeburn 12357: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12358: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12359: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12360: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 12361: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12362: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12363: }
1.1075.2.35 raeburn 12364: $upload_output .= '</td>';
1.1071 raeburn 12365: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 12366: $upload_output.='<td align="right">'.
12367: '<span class="LC_info LC_fontsize_medium">'.
12368: &mt("URL points to web address").'</span>';
1.987 raeburn 12369: $numremref++;
1.660 raeburn 12370: } elsif ($args->{'error_on_invalid_names'}
12371: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 12372: $upload_output.='<td align="right"><span class="LC_warning">'.
12373: &mt('Invalid characters').'</span>';
1.987 raeburn 12374: $numinvalid++;
1.660 raeburn 12375: } else {
1.1075.2.35 raeburn 12376: $upload_output .= '<td>'.
12377: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12378: $embed_file,\%mapping,
1.1071 raeburn 12379: $allfiles,$codebase,'upload');
12380: $counter ++;
12381: $numnew ++;
1.987 raeburn 12382: }
12383: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12384: }
12385: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12386: if ($actionurl eq '/adm/dependencies') {
12387: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12388: $modify_output .= &start_data_table_row().
12389: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12390: '<img src="'.&icon($embed_file).'" border="0" />'.
12391: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12392: '<td>'.$size.'</td>'.
12393: '<td>'.$mtime.'</td>'.
12394: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12395: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12396: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12397: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12398: &embedded_file_element('upload_embedded',$counter,
12399: $embed_file,\%mapping,
12400: $allfiles,$codebase,'modify').
12401: '</div></td>'.
12402: &end_data_table_row()."\n";
12403: $counter ++;
12404: } else {
12405: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 12406: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12407: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12408: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12409: &Apache::loncommon::end_data_table_row()."\n";
12410: }
12411: }
12412: my $delidx = $counter;
12413: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12414: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12415: $delete_output .= &start_data_table_row().
12416: '<td><img src="'.&icon($oldfile).'" />'.
12417: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12418: '<td>'.$size.'</td>'.
12419: '<td>'.$mtime.'</td>'.
12420: '<td><label><input type="checkbox" name="del_upload_dep" '.
12421: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12422: &embedded_file_element('upload_embedded',$delidx,
12423: $oldfile,\%mapping,$allfiles,
12424: $codebase,'delete').'</td>'.
12425: &end_data_table_row()."\n";
12426: $numunused ++;
12427: $delidx ++;
1.987 raeburn 12428: }
12429: if ($upload_output) {
12430: $upload_output = &start_data_table().
12431: $upload_output.
12432: &end_data_table()."\n";
12433: }
1.1071 raeburn 12434: if ($modify_output) {
12435: $modify_output = &start_data_table().
12436: &start_data_table_header_row().
12437: '<th>'.&mt('File').'</th>'.
12438: '<th>'.&mt('Size (KB)').'</th>'.
12439: '<th>'.&mt('Modified').'</th>'.
12440: '<th>'.&mt('Upload replacement?').'</th>'.
12441: &end_data_table_header_row().
12442: $modify_output.
12443: &end_data_table()."\n";
12444: }
12445: if ($delete_output) {
12446: $delete_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('Delete?').'</th>'.
12452: &end_data_table_header_row().
12453: $delete_output.
12454: &end_data_table()."\n";
12455: }
1.987 raeburn 12456: my $applies = 0;
12457: if ($numremref) {
12458: $applies ++;
12459: }
12460: if ($numinvalid) {
12461: $applies ++;
12462: }
12463: if ($numexisting) {
12464: $applies ++;
12465: }
1.1071 raeburn 12466: if ($counter || $numunused) {
1.987 raeburn 12467: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12468: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12469: $state.'<h3>'.$heading.'</h3>';
12470: if ($actionurl eq '/adm/dependencies') {
12471: if ($numnew) {
12472: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12473: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12474: $upload_output.'<br />'."\n";
12475: }
12476: if ($numexisting) {
12477: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12478: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12479: $modify_output.'<br />'."\n";
12480: $buttontext = &mt('Save changes');
12481: }
12482: if ($numunused) {
12483: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12484: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12485: $delete_output.'<br />'."\n";
12486: $buttontext = &mt('Save changes');
12487: }
12488: } else {
12489: $output .= $upload_output.'<br />'."\n";
12490: }
12491: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12492: $counter.'" />'."\n";
12493: if ($actionurl eq '/adm/dependencies') {
12494: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12495: $numnew.'" />'."\n";
12496: } elsif ($actionurl eq '') {
1.987 raeburn 12497: $output .= '<input type="hidden" name="phase" value="three" />';
12498: }
12499: } elsif ($applies) {
12500: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12501: if ($applies > 1) {
12502: $output .=
1.1075.2.35 raeburn 12503: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12504: if ($numremref) {
12505: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12506: }
12507: if ($numinvalid) {
12508: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12509: }
12510: if ($numexisting) {
12511: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12512: }
12513: $output .= '</ul><br />';
12514: } elsif ($numremref) {
12515: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12516: } elsif ($numinvalid) {
12517: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12518: } elsif ($numexisting) {
12519: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12520: }
12521: $output .= $upload_output.'<br />';
12522: }
12523: my ($pathchange_output,$chgcount);
1.1071 raeburn 12524: $chgcount = $counter;
1.987 raeburn 12525: if (keys(%pathchanges) > 0) {
12526: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12527: if ($counter) {
1.987 raeburn 12528: $output .= &embedded_file_element('pathchange',$chgcount,
12529: $embed_file,\%mapping,
1.1071 raeburn 12530: $allfiles,$codebase,'change');
1.987 raeburn 12531: } else {
12532: $pathchange_output .=
12533: &start_data_table_row().
12534: '<td><input type ="checkbox" name="namechange" value="'.
12535: $chgcount.'" checked="checked" /></td>'.
12536: '<td>'.$mapping{$embed_file}.'</td>'.
12537: '<td>'.$embed_file.
12538: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12539: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12540: '</td>'.&end_data_table_row();
1.660 raeburn 12541: }
1.987 raeburn 12542: $numpathchg ++;
12543: $chgcount ++;
1.660 raeburn 12544: }
12545: }
1.1075.2.35 raeburn 12546: if (($counter) || ($numunused)) {
1.987 raeburn 12547: if ($numpathchg) {
12548: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12549: $numpathchg.'" />'."\n";
12550: }
12551: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12552: ($actionurl eq '/adm/imsimport')) {
12553: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12554: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12555: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12556: } elsif ($actionurl eq '/adm/dependencies') {
12557: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12558: }
1.1075.2.35 raeburn 12559: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12560: } elsif ($numpathchg) {
12561: my %pathchange = ();
12562: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12563: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12564: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 12565: }
1.987 raeburn 12566: }
1.1071 raeburn 12567: return ($output,$counter,$numpathchg);
1.987 raeburn 12568: }
12569:
1.1075.2.47 raeburn 12570: =pod
12571:
12572: =item * clean_path($name)
12573:
12574: Performs clean-up of directories, subdirectories and filename in an
12575: embedded object, referenced in an HTML file which is being uploaded
12576: to a course or portfolio, where
12577: "Upload embedded images/multimedia files if HTML file" checkbox was
12578: checked.
12579:
12580: Clean-up is similar to replacements in lonnet::clean_filename()
12581: except each / between sub-directory and next level is preserved.
12582:
12583: =cut
12584:
12585: sub clean_path {
12586: my ($embed_file) = @_;
12587: $embed_file =~s{^/+}{};
12588: my @contents;
12589: if ($embed_file =~ m{/}) {
12590: @contents = split(/\//,$embed_file);
12591: } else {
12592: @contents = ($embed_file);
12593: }
12594: my $lastidx = scalar(@contents)-1;
12595: for (my $i=0; $i<=$lastidx; $i++) {
12596: $contents[$i]=~s{\\}{/}g;
12597: $contents[$i]=~s/\s+/\_/g;
12598: $contents[$i]=~s{[^/\w\.\-]}{}g;
12599: if ($i == $lastidx) {
12600: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12601: }
12602: }
12603: if ($lastidx > 0) {
12604: return join('/',@contents);
12605: } else {
12606: return $contents[0];
12607: }
12608: }
12609:
1.987 raeburn 12610: sub embedded_file_element {
1.1071 raeburn 12611: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12612: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12613: (ref($codebase) eq 'HASH'));
12614: my $output;
1.1071 raeburn 12615: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12616: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12617: }
12618: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12619: &escape($embed_file).'" />';
12620: unless (($context eq 'upload_embedded') &&
12621: ($mapping->{$embed_file} eq $embed_file)) {
12622: $output .='
12623: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12624: }
12625: my $attrib;
12626: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12627: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12628: }
12629: $output .=
12630: "\n\t\t".
12631: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12632: $attrib.'" />';
12633: if (exists($codebase->{$mapping->{$embed_file}})) {
12634: $output .=
12635: "\n\t\t".
12636: '<input name="codebase_'.$num.'" type="hidden" value="'.
12637: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12638: }
1.987 raeburn 12639: return $output;
1.660 raeburn 12640: }
12641:
1.1071 raeburn 12642: sub get_dependency_details {
12643: my ($currfile,$currsubfile,$embed_file) = @_;
12644: my ($size,$mtime,$showsize,$showmtime);
12645: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12646: if ($embed_file =~ m{/}) {
12647: my ($path,$fname) = split(/\//,$embed_file);
12648: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12649: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12650: }
12651: } else {
12652: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12653: ($size,$mtime) = @{$currfile->{$embed_file}};
12654: }
12655: }
12656: $showsize = $size/1024.0;
12657: $showsize = sprintf("%.1f",$showsize);
12658: if ($mtime > 0) {
12659: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12660: }
12661: }
12662: return ($showsize,$showmtime);
12663: }
12664:
12665: sub ask_embedded_js {
12666: return <<"END";
12667: <script type="text/javascript"">
12668: // <![CDATA[
12669: function toggleBrowse(counter) {
12670: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12671: var fileid = document.getElementById('embedded_item_'+counter);
12672: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12673: if (chkboxid.checked == true) {
12674: uploaddivid.style.display='block';
12675: } else {
12676: uploaddivid.style.display='none';
12677: fileid.value = '';
12678: }
12679: }
12680: // ]]>
12681: </script>
12682:
12683: END
12684: }
12685:
1.661 raeburn 12686: sub upload_embedded {
12687: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12688: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12689: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12690: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12691: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12692: my $orig_uploaded_filename =
12693: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12694: foreach my $type ('orig','ref','attrib','codebase') {
12695: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12696: $env{'form.embedded_'.$type.'_'.$i} =
12697: &unescape($env{'form.embedded_'.$type.'_'.$i});
12698: }
12699: }
1.661 raeburn 12700: my ($path,$fname) =
12701: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12702: # no path, whole string is fname
12703: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12704: $fname = &Apache::lonnet::clean_filename($fname);
12705: # See if there is anything left
12706: next if ($fname eq '');
12707:
12708: # Check if file already exists as a file or directory.
12709: my ($state,$msg);
12710: if ($context eq 'portfolio') {
12711: my $port_path = $dirpath;
12712: if ($group ne '') {
12713: $port_path = "groups/$group/$port_path";
12714: }
1.987 raeburn 12715: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12716: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12717: $dir_root,$port_path,$disk_quota,
12718: $current_disk_usage,$uname,$udom);
12719: if ($state eq 'will_exceed_quota'
1.984 raeburn 12720: || $state eq 'file_locked') {
1.661 raeburn 12721: $output .= $msg;
12722: next;
12723: }
12724: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12725: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12726: if ($state eq 'exists') {
12727: $output .= $msg;
12728: next;
12729: }
12730: }
12731: # Check if extension is valid
12732: if (($fname =~ /\.(\w+)$/) &&
12733: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12734: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12735: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12736: next;
12737: } elsif (($fname =~ /\.(\w+)$/) &&
12738: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12739: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12740: next;
12741: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12742: $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 12743: next;
12744: }
12745: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12746: my $subdir = $path;
12747: $subdir =~ s{/+$}{};
1.661 raeburn 12748: if ($context eq 'portfolio') {
1.984 raeburn 12749: my $result;
12750: if ($state eq 'existingfile') {
12751: $result=
12752: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12753: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12754: } else {
1.984 raeburn 12755: $result=
12756: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12757: $dirpath.
1.1075.2.35 raeburn 12758: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12759: if ($result !~ m|^/uploaded/|) {
12760: $output .= '<span class="LC_error">'
12761: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12762: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12763: .'</span><br />';
12764: next;
12765: } else {
1.987 raeburn 12766: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12767: $path.$fname.'</span>').'<br />';
1.984 raeburn 12768: }
1.661 raeburn 12769: }
1.1075.2.35 raeburn 12770: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12771: my $extendedsubdir = $dirpath.'/'.$subdir;
12772: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12773: my $result =
1.1075.2.35 raeburn 12774: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12775: if ($result !~ m|^/uploaded/|) {
12776: $output .= '<span class="LC_error">'
12777: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12778: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12779: .'</span><br />';
12780: next;
12781: } else {
12782: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12783: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12784: if ($context eq 'syllabus') {
12785: &Apache::lonnet::make_public_indefinitely($result);
12786: }
1.987 raeburn 12787: }
1.661 raeburn 12788: } else {
12789: # Save the file
12790: my $target = $env{'form.embedded_item_'.$i};
12791: my $fullpath = $dir_root.$dirpath.'/'.$path;
12792: my $dest = $fullpath.$fname;
12793: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12794: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12795: my $count;
12796: my $filepath = $dir_root;
1.1027 raeburn 12797: foreach my $subdir (@parts) {
12798: $filepath .= "/$subdir";
12799: if (!-e $filepath) {
1.661 raeburn 12800: mkdir($filepath,0770);
12801: }
12802: }
12803: my $fh;
12804: if (!open($fh,'>'.$dest)) {
12805: &Apache::lonnet::logthis('Failed to create '.$dest);
12806: $output .= '<span class="LC_error">'.
1.1071 raeburn 12807: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12808: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12809: '</span><br />';
12810: } else {
12811: if (!print $fh $env{'form.embedded_item_'.$i}) {
12812: &Apache::lonnet::logthis('Failed to write to '.$dest);
12813: $output .= '<span class="LC_error">'.
1.1071 raeburn 12814: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12815: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12816: '</span><br />';
12817: } else {
1.987 raeburn 12818: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12819: $url.'</span>').'<br />';
12820: unless ($context eq 'testbank') {
12821: $footer .= &mt('View embedded file: [_1]',
12822: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12823: }
12824: }
12825: close($fh);
12826: }
12827: }
12828: if ($env{'form.embedded_ref_'.$i}) {
12829: $pathchange{$i} = 1;
12830: }
12831: }
12832: if ($output) {
12833: $output = '<p>'.$output.'</p>';
12834: }
12835: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12836: $returnflag = 'ok';
1.1071 raeburn 12837: my $numpathchgs = scalar(keys(%pathchange));
12838: if ($numpathchgs > 0) {
1.987 raeburn 12839: if ($context eq 'portfolio') {
12840: $output .= '<p>'.&mt('or').'</p>';
12841: } elsif ($context eq 'testbank') {
1.1071 raeburn 12842: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12843: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12844: $returnflag = 'modify_orightml';
12845: }
12846: }
1.1071 raeburn 12847: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12848: }
12849:
12850: sub modify_html_form {
12851: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12852: my $end = 0;
12853: my $modifyform;
12854: if ($context eq 'upload_embedded') {
12855: return unless (ref($pathchange) eq 'HASH');
12856: if ($env{'form.number_embedded_items'}) {
12857: $end += $env{'form.number_embedded_items'};
12858: }
12859: if ($env{'form.number_pathchange_items'}) {
12860: $end += $env{'form.number_pathchange_items'};
12861: }
12862: if ($end) {
12863: for (my $i=0; $i<$end; $i++) {
12864: if ($i < $env{'form.number_embedded_items'}) {
12865: next unless($pathchange->{$i});
12866: }
12867: $modifyform .=
12868: &start_data_table_row().
12869: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12870: 'checked="checked" /></td>'.
12871: '<td>'.$env{'form.embedded_ref_'.$i}.
12872: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12873: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12874: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12875: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12876: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12877: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12878: '<td>'.$env{'form.embedded_orig_'.$i}.
12879: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12880: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12881: &end_data_table_row();
1.1071 raeburn 12882: }
1.987 raeburn 12883: }
12884: } else {
12885: $modifyform = $pathchgtable;
12886: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12887: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12888: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12889: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12890: }
12891: }
12892: if ($modifyform) {
1.1071 raeburn 12893: if ($actionurl eq '/adm/dependencies') {
12894: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12895: }
1.987 raeburn 12896: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12897: '<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".
12898: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12899: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12900: '</ol></p>'."\n".'<p>'.
12901: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12902: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12903: &start_data_table()."\n".
12904: &start_data_table_header_row().
12905: '<th>'.&mt('Change?').'</th>'.
12906: '<th>'.&mt('Current reference').'</th>'.
12907: '<th>'.&mt('Required reference').'</th>'.
12908: &end_data_table_header_row()."\n".
12909: $modifyform.
12910: &end_data_table().'<br />'."\n".$hiddenstate.
12911: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12912: '</form>'."\n";
12913: }
12914: return;
12915: }
12916:
12917: sub modify_html_refs {
1.1075.2.35 raeburn 12918: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12919: my $container;
12920: if ($context eq 'portfolio') {
12921: $container = $env{'form.container'};
12922: } elsif ($context eq 'coursedoc') {
12923: $container = $env{'form.primaryurl'};
1.1071 raeburn 12924: } elsif ($context eq 'manage_dependencies') {
12925: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12926: $container = "/$container";
1.1075.2.35 raeburn 12927: } elsif ($context eq 'syllabus') {
12928: $container = $url;
1.987 raeburn 12929: } else {
1.1027 raeburn 12930: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12931: }
12932: my (%allfiles,%codebase,$output,$content);
12933: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12934: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12935: if (wantarray) {
12936: return ('',0,0);
12937: } else {
12938: return;
12939: }
12940: }
12941: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12942: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12943: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12944: if (wantarray) {
12945: return ('',0,0);
12946: } else {
12947: return;
12948: }
12949: }
1.987 raeburn 12950: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12951: if ($content eq '-1') {
12952: if (wantarray) {
12953: return ('',0,0);
12954: } else {
12955: return;
12956: }
12957: }
1.987 raeburn 12958: } else {
1.1071 raeburn 12959: unless ($container =~ /^\Q$dir_root\E/) {
12960: if (wantarray) {
12961: return ('',0,0);
12962: } else {
12963: return;
12964: }
12965: }
1.1075.2.128 raeburn 12966: if (open(my $fh,'<',$container)) {
1.987 raeburn 12967: $content = join('', <$fh>);
12968: close($fh);
12969: } else {
1.1071 raeburn 12970: if (wantarray) {
12971: return ('',0,0);
12972: } else {
12973: return;
12974: }
1.987 raeburn 12975: }
12976: }
12977: my ($count,$codebasecount) = (0,0);
12978: my $mm = new File::MMagic;
12979: my $mime_type = $mm->checktype_contents($content);
12980: if ($mime_type eq 'text/html') {
12981: my $parse_result =
12982: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12983: \%codebase,\$content);
12984: if ($parse_result eq 'ok') {
12985: foreach my $i (@changes) {
12986: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12987: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12988: if ($allfiles{$ref}) {
12989: my $newname = $orig;
12990: my ($attrib_regexp,$codebase);
1.1006 raeburn 12991: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12992: if ($attrib_regexp =~ /:/) {
12993: $attrib_regexp =~ s/\:/|/g;
12994: }
12995: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12996: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12997: $count += $numchg;
1.1075.2.35 raeburn 12998: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 12999: delete($allfiles{$ref});
1.987 raeburn 13000: }
13001: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13002: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13003: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13004: $codebasecount ++;
13005: }
13006: }
13007: }
1.1075.2.35 raeburn 13008: my $skiprewrites;
1.987 raeburn 13009: if ($count || $codebasecount) {
13010: my $saveresult;
1.1071 raeburn 13011: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 13012: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13013: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13014: if ($url eq $container) {
13015: my ($fname) = ($container =~ m{/([^/]+)$});
13016: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13017: $count,'<span class="LC_filename">'.
1.1071 raeburn 13018: $fname.'</span>').'</p>';
1.987 raeburn 13019: } else {
13020: $output = '<p class="LC_error">'.
13021: &mt('Error: update failed for: [_1].',
13022: '<span class="LC_filename">'.
13023: $container.'</span>').'</p>';
13024: }
1.1075.2.35 raeburn 13025: if ($context eq 'syllabus') {
13026: unless ($saveresult eq 'ok') {
13027: $skiprewrites = 1;
13028: }
13029: }
1.987 raeburn 13030: } else {
1.1075.2.128 raeburn 13031: if (open(my $fh,'>',$container)) {
1.987 raeburn 13032: print $fh $content;
13033: close($fh);
13034: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13035: $count,'<span class="LC_filename">'.
13036: $container.'</span>').'</p>';
1.661 raeburn 13037: } else {
1.987 raeburn 13038: $output = '<p class="LC_error">'.
13039: &mt('Error: could not update [_1].',
13040: '<span class="LC_filename">'.
13041: $container.'</span>').'</p>';
1.661 raeburn 13042: }
13043: }
13044: }
1.1075.2.35 raeburn 13045: if (($context eq 'syllabus') && (!$skiprewrites)) {
13046: my ($actionurl,$state);
13047: $actionurl = "/public/$udom/$uname/syllabus";
13048: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13049: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13050: \%codebase,
13051: {'context' => 'rewrites',
13052: 'ignore_remote_references' => 1,});
13053: if (ref($mapping) eq 'HASH') {
13054: my $rewrites = 0;
13055: foreach my $key (keys(%{$mapping})) {
13056: next if ($key =~ m{^https?://});
13057: my $ref = $mapping->{$key};
13058: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13059: my $attrib;
13060: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13061: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13062: }
13063: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13064: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13065: $rewrites += $numchg;
13066: }
13067: }
13068: if ($rewrites) {
13069: my $saveresult;
13070: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13071: if ($url eq $container) {
13072: my ($fname) = ($container =~ m{/([^/]+)$});
13073: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13074: $count,'<span class="LC_filename">'.
13075: $fname.'</span>').'</p>';
13076: } else {
13077: $output .= '<p class="LC_error">'.
13078: &mt('Error: could not update links in [_1].',
13079: '<span class="LC_filename">'.
13080: $container.'</span>').'</p>';
13081:
13082: }
13083: }
13084: }
13085: }
1.987 raeburn 13086: } else {
13087: &logthis('Failed to parse '.$container.
13088: ' to modify references: '.$parse_result);
1.661 raeburn 13089: }
13090: }
1.1071 raeburn 13091: if (wantarray) {
13092: return ($output,$count,$codebasecount);
13093: } else {
13094: return $output;
13095: }
1.661 raeburn 13096: }
13097:
13098: sub check_for_existing {
13099: my ($path,$fname,$element) = @_;
13100: my ($state,$msg);
13101: if (-d $path.'/'.$fname) {
13102: $state = 'exists';
13103: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13104: } elsif (-e $path.'/'.$fname) {
13105: $state = 'exists';
13106: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13107: }
13108: if ($state eq 'exists') {
13109: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13110: }
13111: return ($state,$msg);
13112: }
13113:
13114: sub check_for_upload {
13115: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13116: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13117: my $filesize = length($env{'form.'.$element});
13118: if (!$filesize) {
13119: my $msg = '<span class="LC_error">'.
13120: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13121: '<span class="LC_filename">'.$fname.'</span>',
13122: $filesize).'<br />'.
1.1007 raeburn 13123: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13124: '</span>';
13125: return ('zero_bytes',$msg);
13126: }
13127: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13128: my $getpropath = 1;
1.1021 raeburn 13129: my ($dirlistref,$listerror) =
13130: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13131: my $found_file = 0;
13132: my $locked_file = 0;
1.991 raeburn 13133: my @lockers;
13134: my $navmap;
13135: if ($env{'request.course.id'}) {
13136: $navmap = Apache::lonnavmaps::navmap->new();
13137: }
1.1021 raeburn 13138: if (ref($dirlistref) eq 'ARRAY') {
13139: foreach my $line (@{$dirlistref}) {
13140: my ($file_name,$rest)=split(/\&/,$line,2);
13141: if ($file_name eq $fname){
13142: $file_name = $path.$file_name;
13143: if ($group ne '') {
13144: $file_name = $group.$file_name;
13145: }
13146: $found_file = 1;
13147: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13148: foreach my $lock (@lockers) {
13149: if (ref($lock) eq 'ARRAY') {
13150: my ($symb,$crsid) = @{$lock};
13151: if ($crsid eq $env{'request.course.id'}) {
13152: if (ref($navmap)) {
13153: my $res = $navmap->getBySymb($symb);
13154: foreach my $part (@{$res->parts()}) {
13155: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13156: unless (($slot_status == $res->RESERVED) ||
13157: ($slot_status == $res->RESERVED_LOCATION)) {
13158: $locked_file = 1;
13159: }
1.991 raeburn 13160: }
1.1021 raeburn 13161: } else {
13162: $locked_file = 1;
1.991 raeburn 13163: }
13164: } else {
13165: $locked_file = 1;
13166: }
13167: }
1.1021 raeburn 13168: }
13169: } else {
13170: my @info = split(/\&/,$rest);
13171: my $currsize = $info[6]/1000;
13172: if ($currsize < $filesize) {
13173: my $extra = $filesize - $currsize;
13174: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 13175: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13176: &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 13177: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13178: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13179: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13180: return ('will_exceed_quota',$msg);
13181: }
1.984 raeburn 13182: }
13183: }
1.661 raeburn 13184: }
13185: }
13186: }
13187: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 13188: my $msg = '<p class="LC_warning">'.
13189: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
13190: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13191: return ('will_exceed_quota',$msg);
13192: } elsif ($found_file) {
13193: if ($locked_file) {
1.1075.2.69 raeburn 13194: my $msg = '<p class="LC_warning">';
1.661 raeburn 13195: $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 13196: $msg .= '</p>';
1.661 raeburn 13197: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13198: return ('file_locked',$msg);
13199: } else {
1.1075.2.69 raeburn 13200: my $msg = '<p class="LC_error">';
1.984 raeburn 13201: $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 13202: $msg .= '</p>';
1.984 raeburn 13203: return ('existingfile',$msg);
1.661 raeburn 13204: }
13205: }
13206: }
13207:
1.987 raeburn 13208: sub check_for_traversal {
13209: my ($path,$url,$toplevel) = @_;
13210: my @parts=split(/\//,$path);
13211: my $cleanpath;
13212: my $fullpath = $url;
13213: for (my $i=0;$i<@parts;$i++) {
13214: next if ($parts[$i] eq '.');
13215: if ($parts[$i] eq '..') {
13216: $fullpath =~ s{([^/]+/)$}{};
13217: } else {
13218: $fullpath .= $parts[$i].'/';
13219: }
13220: }
13221: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13222: $cleanpath = $1;
13223: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13224: my $curr_toprel = $1;
13225: my @parts = split(/\//,$curr_toprel);
13226: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13227: my @urlparts = split(/\//,$url_toprel);
13228: my $doubledots;
13229: my $startdiff = -1;
13230: for (my $i=0; $i<@urlparts; $i++) {
13231: if ($startdiff == -1) {
13232: unless ($urlparts[$i] eq $parts[$i]) {
13233: $startdiff = $i;
13234: $doubledots .= '../';
13235: }
13236: } else {
13237: $doubledots .= '../';
13238: }
13239: }
13240: if ($startdiff > -1) {
13241: $cleanpath = $doubledots;
13242: for (my $i=$startdiff; $i<@parts; $i++) {
13243: $cleanpath .= $parts[$i].'/';
13244: }
13245: }
13246: }
13247: $cleanpath =~ s{(/)$}{};
13248: return $cleanpath;
13249: }
1.31 albertel 13250:
1.1053 raeburn 13251: sub is_archive_file {
13252: my ($mimetype) = @_;
13253: if (($mimetype eq 'application/octet-stream') ||
13254: ($mimetype eq 'application/x-stuffit') ||
13255: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13256: return 1;
13257: }
13258: return;
13259: }
13260:
13261: sub decompress_form {
1.1065 raeburn 13262: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13263: my %lt = &Apache::lonlocal::texthash (
13264: this => 'This file is an archive file.',
1.1067 raeburn 13265: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13266: itsc => 'Its contents are as follows:',
1.1053 raeburn 13267: youm => 'You may wish to extract its contents.',
13268: extr => 'Extract contents',
1.1067 raeburn 13269: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13270: proa => 'Process automatically?',
1.1053 raeburn 13271: yes => 'Yes',
13272: no => 'No',
1.1067 raeburn 13273: fold => 'Title for folder containing movie',
13274: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13275: );
1.1065 raeburn 13276: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13277: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13278: my $info = &list_archive_contents($fileloc,\@paths);
13279: if (@paths) {
13280: foreach my $path (@paths) {
13281: $path =~ s{^/}{};
1.1067 raeburn 13282: if ($path =~ m{^([^/]+)/$}) {
13283: $topdir = $1;
13284: }
1.1065 raeburn 13285: if ($path =~ m{^([^/]+)/}) {
13286: $toplevel{$1} = $path;
13287: } else {
13288: $toplevel{$path} = $path;
13289: }
13290: }
13291: }
1.1067 raeburn 13292: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 13293: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13294: "$topdir/media/",
13295: "$topdir/media/$topdir.mp4",
13296: "$topdir/media/FirstFrame.png",
13297: "$topdir/media/player.swf",
13298: "$topdir/media/swfobject.js",
13299: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 13300: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 13301: "$topdir/$topdir.mp4",
13302: "$topdir/$topdir\_config.xml",
13303: "$topdir/$topdir\_controller.swf",
13304: "$topdir/$topdir\_embed.css",
13305: "$topdir/$topdir\_First_Frame.png",
13306: "$topdir/$topdir\_player.html",
13307: "$topdir/$topdir\_Thumbnails.png",
13308: "$topdir/playerProductInstall.swf",
13309: "$topdir/scripts/",
13310: "$topdir/scripts/config_xml.js",
13311: "$topdir/scripts/handlebars.js",
13312: "$topdir/scripts/jquery-1.7.1.min.js",
13313: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13314: "$topdir/scripts/modernizr.js",
13315: "$topdir/scripts/player-min.js",
13316: "$topdir/scripts/swfobject.js",
13317: "$topdir/skins/",
13318: "$topdir/skins/configuration_express.xml",
13319: "$topdir/skins/express_show/",
13320: "$topdir/skins/express_show/player-min.css",
13321: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 13322: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13323: "$topdir/$topdir.mp4",
13324: "$topdir/$topdir\_config.xml",
13325: "$topdir/$topdir\_controller.swf",
13326: "$topdir/$topdir\_embed.css",
13327: "$topdir/$topdir\_First_Frame.png",
13328: "$topdir/$topdir\_player.html",
13329: "$topdir/$topdir\_Thumbnails.png",
13330: "$topdir/playerProductInstall.swf",
13331: "$topdir/scripts/",
13332: "$topdir/scripts/config_xml.js",
13333: "$topdir/scripts/techsmith-smart-player.min.js",
13334: "$topdir/skins/",
13335: "$topdir/skins/configuration_express.xml",
13336: "$topdir/skins/express_show/",
13337: "$topdir/skins/express_show/spritesheet.min.css",
13338: "$topdir/skins/express_show/spritesheet.png",
13339: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 13340: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13341: if (@diffs == 0) {
1.1075.2.59 raeburn 13342: $is_camtasia = 6;
13343: } else {
1.1075.2.81 raeburn 13344: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 13345: if (@diffs == 0) {
13346: $is_camtasia = 8;
1.1075.2.81 raeburn 13347: } else {
13348: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13349: if (@diffs == 0) {
13350: $is_camtasia = 8;
13351: }
1.1075.2.59 raeburn 13352: }
1.1067 raeburn 13353: }
13354: }
13355: my $output;
13356: if ($is_camtasia) {
13357: $output = <<"ENDCAM";
13358: <script type="text/javascript" language="Javascript">
13359: // <![CDATA[
13360:
13361: function camtasiaToggle() {
13362: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13363: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 13364: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13365: document.getElementById('camtasia_titles').style.display='block';
13366: } else {
13367: document.getElementById('camtasia_titles').style.display='none';
13368: }
13369: }
13370: }
13371: return;
13372: }
13373:
13374: // ]]>
13375: </script>
13376: <p>$lt{'camt'}</p>
13377: ENDCAM
1.1065 raeburn 13378: } else {
1.1067 raeburn 13379: $output = '<p>'.$lt{'this'};
13380: if ($info eq '') {
13381: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13382: } else {
13383: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13384: '<div><pre>'.$info.'</pre></div>';
13385: }
1.1065 raeburn 13386: }
1.1067 raeburn 13387: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13388: my $duplicates;
13389: my $num = 0;
13390: if (ref($dirlist) eq 'ARRAY') {
13391: foreach my $item (@{$dirlist}) {
13392: if (ref($item) eq 'ARRAY') {
13393: if (exists($toplevel{$item->[0]})) {
13394: $duplicates .=
13395: &start_data_table_row().
13396: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13397: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13398: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13399: 'value="1" />'.&mt('Yes').'</label>'.
13400: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13401: '<td>'.$item->[0].'</td>';
13402: if ($item->[2]) {
13403: $duplicates .= '<td>'.&mt('Directory').'</td>';
13404: } else {
13405: $duplicates .= '<td>'.&mt('File').'</td>';
13406: }
13407: $duplicates .= '<td>'.$item->[3].'</td>'.
13408: '<td>'.
13409: &Apache::lonlocal::locallocaltime($item->[4]).
13410: '</td>'.
13411: &end_data_table_row();
13412: $num ++;
13413: }
13414: }
13415: }
13416: }
13417: my $itemcount;
13418: if (@paths > 0) {
13419: $itemcount = scalar(@paths);
13420: } else {
13421: $itemcount = 1;
13422: }
1.1067 raeburn 13423: if ($is_camtasia) {
13424: $output .= $lt{'auto'}.'<br />'.
13425: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 13426: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13427: $lt{'yes'}.'</label> <label>'.
13428: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13429: $lt{'no'}.'</label></span><br />'.
13430: '<div id="camtasia_titles" style="display:block">'.
13431: &Apache::lonhtmlcommon::start_pick_box().
13432: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13433: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13434: &Apache::lonhtmlcommon::row_closure().
13435: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13436: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13437: &Apache::lonhtmlcommon::row_closure(1).
13438: &Apache::lonhtmlcommon::end_pick_box().
13439: '</div>';
13440: }
1.1065 raeburn 13441: $output .=
13442: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13443: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13444: "\n";
1.1065 raeburn 13445: if ($duplicates ne '') {
13446: $output .= '<p><span class="LC_warning">'.
13447: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13448: &start_data_table().
13449: &start_data_table_header_row().
13450: '<th>'.&mt('Overwrite?').'</th>'.
13451: '<th>'.&mt('Name').'</th>'.
13452: '<th>'.&mt('Type').'</th>'.
13453: '<th>'.&mt('Size').'</th>'.
13454: '<th>'.&mt('Last modified').'</th>'.
13455: &end_data_table_header_row().
13456: $duplicates.
13457: &end_data_table().
13458: '</p>';
13459: }
1.1067 raeburn 13460: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13461: if (ref($hiddenelements) eq 'HASH') {
13462: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13463: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13464: }
13465: }
13466: $output .= <<"END";
1.1067 raeburn 13467: <br />
1.1053 raeburn 13468: <input type="submit" name="decompress" value="$lt{'extr'}" />
13469: </form>
13470: $noextract
13471: END
13472: return $output;
13473: }
13474:
1.1065 raeburn 13475: sub decompression_utility {
13476: my ($program) = @_;
13477: my @utilities = ('tar','gunzip','bunzip2','unzip');
13478: my $location;
13479: if (grep(/^\Q$program\E$/,@utilities)) {
13480: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13481: '/usr/sbin/') {
13482: if (-x $dir.$program) {
13483: $location = $dir.$program;
13484: last;
13485: }
13486: }
13487: }
13488: return $location;
13489: }
13490:
13491: sub list_archive_contents {
13492: my ($file,$pathsref) = @_;
13493: my (@cmd,$output);
13494: my $needsregexp;
13495: if ($file =~ /\.zip$/) {
13496: @cmd = (&decompression_utility('unzip'),"-l");
13497: $needsregexp = 1;
13498: } elsif (($file =~ m/\.tar\.gz$/) ||
13499: ($file =~ /\.tgz$/)) {
13500: @cmd = (&decompression_utility('tar'),"-ztf");
13501: } elsif ($file =~ /\.tar\.bz2$/) {
13502: @cmd = (&decompression_utility('tar'),"-jtf");
13503: } elsif ($file =~ m|\.tar$|) {
13504: @cmd = (&decompression_utility('tar'),"-tf");
13505: }
13506: if (@cmd) {
13507: undef($!);
13508: undef($@);
13509: if (open(my $fh,"-|", @cmd, $file)) {
13510: while (my $line = <$fh>) {
13511: $output .= $line;
13512: chomp($line);
13513: my $item;
13514: if ($needsregexp) {
13515: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13516: } else {
13517: $item = $line;
13518: }
13519: if ($item ne '') {
13520: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13521: push(@{$pathsref},$item);
13522: }
13523: }
13524: }
13525: close($fh);
13526: }
13527: }
13528: return $output;
13529: }
13530:
1.1053 raeburn 13531: sub decompress_uploaded_file {
13532: my ($file,$dir) = @_;
13533: &Apache::lonnet::appenv({'cgi.file' => $file});
13534: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13535: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13536: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13537: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13538: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13539: my $decompressed = $env{'cgi.decompressed'};
13540: &Apache::lonnet::delenv('cgi.file');
13541: &Apache::lonnet::delenv('cgi.dir');
13542: &Apache::lonnet::delenv('cgi.decompressed');
13543: return ($decompressed,$result);
13544: }
13545:
1.1055 raeburn 13546: sub process_decompression {
13547: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 13548: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13549: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13550: &mt('Unexpected file path.').'</p>'."\n";
13551: }
13552: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13553: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13554: &mt('Unexpected course context.').'</p>'."\n";
13555: }
13556: unless ($file eq &Apache::lonnet::clean_filename($file)) {
13557: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13558: &mt('Filename contained unexpected characters.').'</p>'."\n";
13559: }
1.1055 raeburn 13560: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 13561: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 13562: $error = &mt('Filename not a supported archive file type.').
13563: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13564: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13565: } else {
13566: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13567: if ($docuhome eq 'no_host') {
13568: $error = &mt('Could not determine home server for course.');
13569: } else {
13570: my @ids=&Apache::lonnet::current_machine_ids();
13571: my $currdir = "$dir_root/$destination";
13572: if (grep(/^\Q$docuhome\E$/,@ids)) {
13573: $dir = &LONCAPA::propath($docudom,$docuname).
13574: "$dir_root/$destination";
13575: } else {
13576: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13577: "$dir_root/$docudom/$docuname/$destination";
13578: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13579: $error = &mt('Archive file not found.');
13580: }
13581: }
1.1065 raeburn 13582: my (@to_overwrite,@to_skip);
13583: if ($env{'form.archive_overwrite_total'} > 0) {
13584: my $total = $env{'form.archive_overwrite_total'};
13585: for (my $i=0; $i<$total; $i++) {
13586: if ($env{'form.archive_overwrite_'.$i} == 1) {
13587: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13588: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13589: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13590: }
13591: }
13592: }
13593: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 13594: my $numoverwrite = scalar(@to_overwrite);
13595: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13596: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13597: } elsif ($dir eq '') {
1.1055 raeburn 13598: $error = &mt('Directory containing archive file unavailable.');
13599: } elsif (!$error) {
1.1065 raeburn 13600: my ($decompressed,$display);
1.1075.2.128 raeburn 13601: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13602: my $tempdir = time.'_'.$$.int(rand(10000));
13603: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 13604: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13605: ($decompressed,$display) =
13606: &decompress_uploaded_file($file,"$dir/$tempdir");
13607: foreach my $item (@to_skip) {
13608: if (($item ne '') && ($item !~ /\.\./)) {
13609: if (-f "$dir/$tempdir/$item") {
13610: unlink("$dir/$tempdir/$item");
13611: } elsif (-d "$dir/$tempdir/$item") {
13612: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
13613: }
13614: }
13615: }
13616: foreach my $item (@to_overwrite) {
13617: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13618: if (($item ne '') && ($item !~ /\.\./)) {
13619: if (-f "$dir/$item") {
13620: unlink("$dir/$item");
13621: } elsif (-d "$dir/$item") {
13622: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
13623: }
13624: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13625: }
1.1065 raeburn 13626: }
13627: }
1.1075.2.128 raeburn 13628: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13629: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13630: }
1.1065 raeburn 13631: }
13632: } else {
13633: ($decompressed,$display) =
13634: &decompress_uploaded_file($file,$dir);
13635: }
1.1055 raeburn 13636: if ($decompressed eq 'ok') {
1.1065 raeburn 13637: $output = '<p class="LC_info">'.
13638: &mt('Files extracted successfully from archive.').
13639: '</p>'."\n";
1.1055 raeburn 13640: my ($warning,$result,@contents);
13641: my ($newdirlistref,$newlisterror) =
13642: &Apache::lonnet::dirlist($currdir,$docudom,
13643: $docuname,1);
13644: my (%is_dir,%changes,@newitems);
13645: my $dirptr = 16384;
1.1065 raeburn 13646: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13647: foreach my $dir_line (@{$newdirlistref}) {
13648: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13649: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13650: push(@newitems,$item);
13651: if ($dirptr&$testdir) {
13652: $is_dir{$item} = 1;
13653: }
13654: $changes{$item} = 1;
13655: }
13656: }
13657: }
13658: if (keys(%changes) > 0) {
13659: foreach my $item (sort(@newitems)) {
13660: if ($changes{$item}) {
13661: push(@contents,$item);
13662: }
13663: }
13664: }
13665: if (@contents > 0) {
1.1067 raeburn 13666: my $wantform;
13667: unless ($env{'form.autoextract_camtasia'}) {
13668: $wantform = 1;
13669: }
1.1056 raeburn 13670: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13671: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13672: $currdir,\%is_dir,
13673: \%children,\%parent,
1.1056 raeburn 13674: \@contents,\%dirorder,
13675: \%titles,$wantform);
1.1055 raeburn 13676: if ($datatable ne '') {
13677: $output .= &archive_options_form('decompressed',$datatable,
13678: $count,$hiddenelem);
1.1065 raeburn 13679: my $startcount = 6;
1.1055 raeburn 13680: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13681: \%titles,\%children);
1.1055 raeburn 13682: }
1.1067 raeburn 13683: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13684: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13685: my %displayed;
13686: my $total = 1;
13687: $env{'form.archive_directory'} = [];
13688: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13689: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13690: $path =~ s{/$}{};
13691: my $item;
13692: if ($path ne '') {
13693: $item = "$path/$titles{$i}";
13694: } else {
13695: $item = $titles{$i};
13696: }
13697: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13698: if ($item eq $contents[0]) {
13699: push(@{$env{'form.archive_directory'}},$i);
13700: $env{'form.archive_'.$i} = 'display';
13701: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13702: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13703: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13704: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13705: $env{'form.archive_'.$i} = 'display';
13706: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13707: $displayed{'web'} = $i;
13708: } else {
1.1075.2.59 raeburn 13709: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13710: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13711: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13712: push(@{$env{'form.archive_directory'}},$i);
13713: }
13714: $env{'form.archive_'.$i} = 'dependency';
13715: }
13716: $total ++;
13717: }
13718: for (my $i=1; $i<$total; $i++) {
13719: next if ($i == $displayed{'web'});
13720: next if ($i == $displayed{'folder'});
13721: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13722: }
13723: $env{'form.phase'} = 'decompress_cleanup';
13724: $env{'form.archivedelete'} = 1;
13725: $env{'form.archive_count'} = $total-1;
13726: $output .=
13727: &process_extracted_files('coursedocs',$docudom,
13728: $docuname,$destination,
13729: $dir_root,$hiddenelem);
13730: }
1.1055 raeburn 13731: } else {
13732: $warning = &mt('No new items extracted from archive file.');
13733: }
13734: } else {
13735: $output = $display;
13736: $error = &mt('An error occurred during extraction from the archive file.');
13737: }
13738: }
13739: }
13740: }
13741: if ($error) {
13742: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13743: $error.'</p>'."\n";
13744: }
13745: if ($warning) {
13746: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13747: }
13748: return $output;
13749: }
13750:
13751: sub get_extracted {
1.1056 raeburn 13752: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13753: $titles,$wantform) = @_;
1.1055 raeburn 13754: my $count = 0;
13755: my $depth = 0;
13756: my $datatable;
1.1056 raeburn 13757: my @hierarchy;
1.1055 raeburn 13758: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13759: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13760: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13761: foreach my $item (@{$contents}) {
13762: $count ++;
1.1056 raeburn 13763: @{$dirorder->{$count}} = @hierarchy;
13764: $titles->{$count} = $item;
1.1055 raeburn 13765: &archive_hierarchy($depth,$count,$parent,$children);
13766: if ($wantform) {
13767: $datatable .= &archive_row($is_dir->{$item},$item,
13768: $currdir,$depth,$count);
13769: }
13770: if ($is_dir->{$item}) {
13771: $depth ++;
1.1056 raeburn 13772: push(@hierarchy,$count);
13773: $parent->{$depth} = $count;
1.1055 raeburn 13774: $datatable .=
13775: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13776: \$depth,\$count,\@hierarchy,$dirorder,
13777: $children,$parent,$titles,$wantform);
1.1055 raeburn 13778: $depth --;
1.1056 raeburn 13779: pop(@hierarchy);
1.1055 raeburn 13780: }
13781: }
13782: return ($count,$datatable);
13783: }
13784:
13785: sub recurse_extracted_archive {
1.1056 raeburn 13786: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13787: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13788: my $result='';
1.1056 raeburn 13789: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13790: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13791: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13792: return $result;
13793: }
13794: my $dirptr = 16384;
13795: my ($newdirlistref,$newlisterror) =
13796: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13797: if (ref($newdirlistref) eq 'ARRAY') {
13798: foreach my $dir_line (@{$newdirlistref}) {
13799: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13800: unless ($item =~ /^\.+$/) {
13801: $$count ++;
1.1056 raeburn 13802: @{$dirorder->{$$count}} = @{$hierarchy};
13803: $titles->{$$count} = $item;
1.1055 raeburn 13804: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13805:
1.1055 raeburn 13806: my $is_dir;
13807: if ($dirptr&$testdir) {
13808: $is_dir = 1;
13809: }
13810: if ($wantform) {
13811: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13812: }
13813: if ($is_dir) {
13814: $$depth ++;
1.1056 raeburn 13815: push(@{$hierarchy},$$count);
13816: $parent->{$$depth} = $$count;
1.1055 raeburn 13817: $result .=
13818: &recurse_extracted_archive("$currdir/$item",$docudom,
13819: $docuname,$depth,$count,
1.1056 raeburn 13820: $hierarchy,$dirorder,$children,
13821: $parent,$titles,$wantform);
1.1055 raeburn 13822: $$depth --;
1.1056 raeburn 13823: pop(@{$hierarchy});
1.1055 raeburn 13824: }
13825: }
13826: }
13827: }
13828: return $result;
13829: }
13830:
13831: sub archive_hierarchy {
13832: my ($depth,$count,$parent,$children) =@_;
13833: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13834: if (exists($parent->{$depth})) {
13835: $children->{$parent->{$depth}} .= $count.':';
13836: }
13837: }
13838: return;
13839: }
13840:
13841: sub archive_row {
13842: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13843: my ($name) = ($item =~ m{([^/]+)$});
13844: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13845: 'display' => 'Add as file',
1.1055 raeburn 13846: 'dependency' => 'Include as dependency',
13847: 'discard' => 'Discard',
13848: );
13849: if ($is_dir) {
1.1059 raeburn 13850: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13851: }
1.1056 raeburn 13852: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13853: my $offset = 0;
1.1055 raeburn 13854: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13855: $offset ++;
1.1065 raeburn 13856: if ($action ne 'display') {
13857: $offset ++;
13858: }
1.1055 raeburn 13859: $output .= '<td><span class="LC_nobreak">'.
13860: '<label><input type="radio" name="archive_'.$count.
13861: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13862: my $text = $choices{$action};
13863: if ($is_dir) {
13864: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13865: if ($action eq 'display') {
1.1059 raeburn 13866: $text = &mt('Add as folder');
1.1055 raeburn 13867: }
1.1056 raeburn 13868: } else {
13869: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13870:
13871: }
13872: $output .= ' /> '.$choices{$action}.'</label></span>';
13873: if ($action eq 'dependency') {
13874: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13875: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13876: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13877: '<option value=""></option>'."\n".
13878: '</select>'."\n".
13879: '</div>';
1.1059 raeburn 13880: } elsif ($action eq 'display') {
13881: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13882: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13883: '</div>';
1.1055 raeburn 13884: }
1.1056 raeburn 13885: $output .= '</td>';
1.1055 raeburn 13886: }
13887: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13888: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13889: for (my $i=0; $i<$depth; $i++) {
13890: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13891: }
13892: if ($is_dir) {
13893: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13894: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13895: } else {
13896: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13897: }
13898: $output .= ' '.$name.'</td>'."\n".
13899: &end_data_table_row();
13900: return $output;
13901: }
13902:
13903: sub archive_options_form {
1.1065 raeburn 13904: my ($form,$display,$count,$hiddenelem) = @_;
13905: my %lt = &Apache::lonlocal::texthash(
13906: perm => 'Permanently remove archive file?',
13907: hows => 'How should each extracted item be incorporated in the course?',
13908: cont => 'Content actions for all',
13909: addf => 'Add as folder/file',
13910: incd => 'Include as dependency for a displayed file',
13911: disc => 'Discard',
13912: no => 'No',
13913: yes => 'Yes',
13914: save => 'Save',
13915: );
13916: my $output = <<"END";
13917: <form name="$form" method="post" action="">
13918: <p><span class="LC_nobreak">$lt{'perm'}
13919: <label>
13920: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13921: </label>
13922:
13923: <label>
13924: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13925: </span>
13926: </p>
13927: <input type="hidden" name="phase" value="decompress_cleanup" />
13928: <br />$lt{'hows'}
13929: <div class="LC_columnSection">
13930: <fieldset>
13931: <legend>$lt{'cont'}</legend>
13932: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13933: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13934: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13935: </fieldset>
13936: </div>
13937: END
13938: return $output.
1.1055 raeburn 13939: &start_data_table()."\n".
1.1065 raeburn 13940: $display."\n".
1.1055 raeburn 13941: &end_data_table()."\n".
13942: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13943: $hiddenelem.
1.1065 raeburn 13944: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13945: '</form>';
13946: }
13947:
13948: sub archive_javascript {
1.1056 raeburn 13949: my ($startcount,$numitems,$titles,$children) = @_;
13950: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13951: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13952: my $scripttag = <<START;
13953: <script type="text/javascript">
13954: // <![CDATA[
13955:
13956: function checkAll(form,prefix) {
13957: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13958: for (var i=0; i < form.elements.length; i++) {
13959: var id = form.elements[i].id;
13960: if ((id != '') && (id != undefined)) {
13961: if (idstr.test(id)) {
13962: if (form.elements[i].type == 'radio') {
13963: form.elements[i].checked = true;
1.1056 raeburn 13964: var nostart = i-$startcount;
1.1059 raeburn 13965: var offset = nostart%7;
13966: var count = (nostart-offset)/7;
1.1056 raeburn 13967: dependencyCheck(form,count,offset);
1.1055 raeburn 13968: }
13969: }
13970: }
13971: }
13972: }
13973:
13974: function propagateCheck(form,count) {
13975: if (count > 0) {
1.1059 raeburn 13976: var startelement = $startcount + ((count-1) * 7);
13977: for (var j=1; j<6; j++) {
13978: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13979: var item = startelement + j;
13980: if (form.elements[item].type == 'radio') {
13981: if (form.elements[item].checked) {
13982: containerCheck(form,count,j);
13983: break;
13984: }
1.1055 raeburn 13985: }
13986: }
13987: }
13988: }
13989: }
13990:
13991: numitems = $numitems
1.1056 raeburn 13992: var titles = new Array(numitems);
13993: var parents = new Array(numitems);
1.1055 raeburn 13994: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13995: parents[i] = new Array;
1.1055 raeburn 13996: }
1.1059 raeburn 13997: var maintitle = '$maintitle';
1.1055 raeburn 13998:
13999: START
14000:
1.1056 raeburn 14001: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14002: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14003: for (my $i=0; $i<@contents; $i ++) {
14004: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14005: }
14006: }
14007:
1.1056 raeburn 14008: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14009: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14010: }
14011:
1.1055 raeburn 14012: $scripttag .= <<END;
14013:
14014: function containerCheck(form,count,offset) {
14015: if (count > 0) {
1.1056 raeburn 14016: dependencyCheck(form,count,offset);
1.1059 raeburn 14017: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14018: form.elements[item].checked = true;
14019: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14020: if (parents[count].length > 0) {
14021: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14022: containerCheck(form,parents[count][j],offset);
14023: }
14024: }
14025: }
14026: }
14027: }
14028:
14029: function dependencyCheck(form,count,offset) {
14030: if (count > 0) {
1.1059 raeburn 14031: var chosen = (offset+$startcount)+7*(count-1);
14032: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14033: var currtype = form.elements[depitem].type;
14034: if (form.elements[chosen].value == 'dependency') {
14035: document.getElementById('arc_depon_'+count).style.display='block';
14036: form.elements[depitem].options.length = 0;
14037: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 14038: for (var i=1; i<=numitems; i++) {
14039: if (i == count) {
14040: continue;
14041: }
1.1059 raeburn 14042: var startelement = $startcount + (i-1) * 7;
14043: for (var j=1; j<6; j++) {
14044: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14045: var item = startelement + j;
14046: if (form.elements[item].type == 'radio') {
14047: if (form.elements[item].checked) {
14048: if (form.elements[item].value == 'display') {
14049: var n = form.elements[depitem].options.length;
14050: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14051: }
14052: }
14053: }
14054: }
14055: }
14056: }
14057: } else {
14058: document.getElementById('arc_depon_'+count).style.display='none';
14059: form.elements[depitem].options.length = 0;
14060: form.elements[depitem].options[0] = new Option('Select','',true,true);
14061: }
1.1059 raeburn 14062: titleCheck(form,count,offset);
1.1056 raeburn 14063: }
14064: }
14065:
14066: function propagateSelect(form,count,offset) {
14067: if (count > 0) {
1.1065 raeburn 14068: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14069: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14070: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14071: if (parents[count].length > 0) {
14072: for (var j=0; j<parents[count].length; j++) {
14073: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14074: }
14075: }
14076: }
14077: }
14078: }
1.1056 raeburn 14079:
14080: function containerSelect(form,count,offset,picked) {
14081: if (count > 0) {
1.1065 raeburn 14082: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14083: if (form.elements[item].type == 'radio') {
14084: if (form.elements[item].value == 'dependency') {
14085: if (form.elements[item+1].type == 'select-one') {
14086: for (var i=0; i<form.elements[item+1].options.length; i++) {
14087: if (form.elements[item+1].options[i].value == picked) {
14088: form.elements[item+1].selectedIndex = i;
14089: break;
14090: }
14091: }
14092: }
14093: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14094: if (parents[count].length > 0) {
14095: for (var j=0; j<parents[count].length; j++) {
14096: containerSelect(form,parents[count][j],offset,picked);
14097: }
14098: }
14099: }
14100: }
14101: }
14102: }
14103: }
14104:
1.1059 raeburn 14105: function titleCheck(form,count,offset) {
14106: if (count > 0) {
14107: var chosen = (offset+$startcount)+7*(count-1);
14108: var depitem = $startcount + ((count-1) * 7) + 2;
14109: var currtype = form.elements[depitem].type;
14110: if (form.elements[chosen].value == 'display') {
14111: document.getElementById('arc_title_'+count).style.display='block';
14112: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14113: document.getElementById('archive_title_'+count).value=maintitle;
14114: }
14115: } else {
14116: document.getElementById('arc_title_'+count).style.display='none';
14117: if (currtype == 'text') {
14118: document.getElementById('archive_title_'+count).value='';
14119: }
14120: }
14121: }
14122: return;
14123: }
14124:
1.1055 raeburn 14125: // ]]>
14126: </script>
14127: END
14128: return $scripttag;
14129: }
14130:
14131: sub process_extracted_files {
1.1067 raeburn 14132: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14133: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 14134: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14135: my @ids=&Apache::lonnet::current_machine_ids();
14136: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14137: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14138: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14139: if (grep(/^\Q$docuhome\E$/,@ids)) {
14140: $prefix = &LONCAPA::propath($docudom,$docuname);
14141: $pathtocheck = "$dir_root/$destination";
14142: $dir = $dir_root;
14143: $ishome = 1;
14144: } else {
14145: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14146: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 14147: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14148: }
14149: my $currdir = "$dir_root/$destination";
14150: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14151: if ($env{'form.folderpath'}) {
14152: my @items = split('&',$env{'form.folderpath'});
14153: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 14154: if ($env{'form.folderpath'} =~ /\:1$/) {
14155: $containers{'0'}='page';
14156: } else {
14157: $containers{'0'}='sequence';
14158: }
1.1055 raeburn 14159: }
14160: my @archdirs = &get_env_multiple('form.archive_directory');
14161: if ($numitems) {
14162: for (my $i=1; $i<=$numitems; $i++) {
14163: my $path = $env{'form.archive_content_'.$i};
14164: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14165: my $item = $1;
14166: $toplevelitems{$item} = $i;
14167: if (grep(/^\Q$i\E$/,@archdirs)) {
14168: $is_dir{$item} = 1;
14169: }
14170: }
14171: }
14172: }
1.1067 raeburn 14173: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14174: if (keys(%toplevelitems) > 0) {
14175: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14176: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14177: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14178: }
1.1066 raeburn 14179: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14180: if ($numitems) {
14181: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 14182: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14183: my $path = $env{'form.archive_content_'.$i};
14184: if ($path =~ /^\Q$pathtocheck\E/) {
14185: if ($env{'form.archive_'.$i} eq 'discard') {
14186: if ($prefix ne '' && $path ne '') {
14187: if (-e $prefix.$path) {
1.1066 raeburn 14188: if ((@archdirs > 0) &&
14189: (grep(/^\Q$i\E$/,@archdirs))) {
14190: $todeletedir{$prefix.$path} = 1;
14191: } else {
14192: $todelete{$prefix.$path} = 1;
14193: }
1.1055 raeburn 14194: }
14195: }
14196: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14197: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14198: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14199: $docstitle = $env{'form.archive_title_'.$i};
14200: if ($docstitle eq '') {
14201: $docstitle = $title;
14202: }
1.1055 raeburn 14203: $outer = 0;
1.1056 raeburn 14204: if (ref($dirorder{$i}) eq 'ARRAY') {
14205: if (@{$dirorder{$i}} > 0) {
14206: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14207: if ($env{'form.archive_'.$item} eq 'display') {
14208: $outer = $item;
14209: last;
14210: }
14211: }
14212: }
14213: }
14214: my ($errtext,$fatal) =
14215: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14216: '/'.$folders{$outer}.'.'.
14217: $containers{$outer});
14218: next if ($fatal);
14219: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14220: if ($context eq 'coursedocs') {
1.1056 raeburn 14221: $mapinner{$i} = time;
1.1055 raeburn 14222: $folders{$i} = 'default_'.$mapinner{$i};
14223: $containers{$i} = 'sequence';
14224: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14225: $folders{$i}.'.'.$containers{$i};
14226: my $newidx = &LONCAPA::map::getresidx();
14227: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14228: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14229: push(@LONCAPA::map::order,$newidx);
14230: my ($outtext,$errtext) =
14231: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14232: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 14233: '.'.$containers{$outer},1,1);
1.1056 raeburn 14234: $newseqid{$i} = $newidx;
1.1067 raeburn 14235: unless ($errtext) {
1.1075.2.128 raeburn 14236: $result .= '<li>'.&mt('Folder: [_1] added to course',
14237: &HTML::Entities::encode($docstitle,'<>&"'))..
14238: '</li>'."\n";
1.1067 raeburn 14239: }
1.1055 raeburn 14240: }
14241: } else {
14242: if ($context eq 'coursedocs') {
14243: my $newidx=&LONCAPA::map::getresidx();
14244: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14245: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14246: $title;
1.1075.2.161. .13(raeb 14247:-23): if (($outer !~ /\D/) &&
14248:-23): (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14249:-23): ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 14250: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14251: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 14252: }
1.1075.2.128 raeburn 14253: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14254: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14255: }
14256: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14257: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14258: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14259: unless ($ishome) {
14260: my $fetch = "$newdest{$i}/$title";
14261: $fetch =~ s/^\Q$prefix$dir\E//;
14262: $prompttofetch{$fetch} = 1;
14263: }
14264: }
14265: }
14266: $LONCAPA::map::resources[$newidx]=
14267: $docstitle.':'.$url.':false:normal:res';
14268: push(@LONCAPA::map::order, $newidx);
14269: my ($outtext,$errtext)=
14270: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14271: $docuname.'/'.$folders{$outer}.
14272: '.'.$containers{$outer},1,1);
14273: unless ($errtext) {
14274: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14275: $result .= '<li>'.&mt('File: [_1] added to course',
14276: &HTML::Entities::encode($docstitle,'<>&"')).
14277: '</li>'."\n";
14278: }
1.1067 raeburn 14279: }
1.1075.2.128 raeburn 14280: } else {
14281: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14282: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 14283: }
1.1055 raeburn 14284: }
14285: }
1.1075.2.11 raeburn 14286: }
14287: } else {
1.1075.2.128 raeburn 14288: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14289: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 14290: }
14291: }
14292: for (my $i=1; $i<=$numitems; $i++) {
14293: next unless ($env{'form.archive_'.$i} eq 'dependency');
14294: my $path = $env{'form.archive_content_'.$i};
14295: if ($path =~ /^\Q$pathtocheck\E/) {
14296: my ($title) = ($path =~ m{/([^/]+)$});
14297: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14298: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14299: if (ref($dirorder{$i}) eq 'ARRAY') {
14300: my ($itemidx,$fullpath,$relpath);
14301: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14302: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14303: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 14304: if ($dirorder{$i}->[$j] eq $container) {
14305: $itemidx = $j;
1.1056 raeburn 14306: }
14307: }
1.1075.2.11 raeburn 14308: }
14309: if ($itemidx eq '') {
14310: $itemidx = 0;
14311: }
14312: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14313: if ($mapinner{$referrer{$i}}) {
14314: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14315: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14316: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14317: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14318: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14319: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14320: if (!-e $fullpath) {
14321: mkdir($fullpath,0755);
1.1056 raeburn 14322: }
14323: }
1.1075.2.11 raeburn 14324: } else {
14325: last;
1.1056 raeburn 14326: }
1.1075.2.11 raeburn 14327: }
14328: }
14329: } elsif ($newdest{$referrer{$i}}) {
14330: $fullpath = $newdest{$referrer{$i}};
14331: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14332: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14333: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14334: last;
14335: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14336: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14337: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14338: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14339: if (!-e $fullpath) {
14340: mkdir($fullpath,0755);
1.1056 raeburn 14341: }
14342: }
1.1075.2.11 raeburn 14343: } else {
14344: last;
1.1056 raeburn 14345: }
1.1075.2.11 raeburn 14346: }
14347: }
14348: if ($fullpath ne '') {
14349: if (-e "$prefix$path") {
1.1075.2.128 raeburn 14350: unless (rename("$prefix$path","$fullpath/$title")) {
14351: $warning .= &mt('Failed to rename dependency').'<br />';
14352: }
1.1075.2.11 raeburn 14353: }
14354: if (-e "$fullpath/$title") {
14355: my $showpath;
14356: if ($relpath ne '') {
14357: $showpath = "$relpath/$title";
14358: } else {
14359: $showpath = "/$title";
1.1056 raeburn 14360: }
1.1075.2.128 raeburn 14361: $result .= '<li>'.&mt('[_1] included as a dependency',
14362: &HTML::Entities::encode($showpath,'<>&"')).
14363: '</li>'."\n";
14364: unless ($ishome) {
14365: my $fetch = "$fullpath/$title";
14366: $fetch =~ s/^\Q$prefix$dir\E//;
14367: $prompttofetch{$fetch} = 1;
14368: }
1.1055 raeburn 14369: }
14370: }
14371: }
1.1075.2.11 raeburn 14372: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14373: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 14374: &HTML::Entities::encode($path,'<>&"'),
14375: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14376: '<br />';
1.1055 raeburn 14377: }
14378: } else {
1.1075.2.128 raeburn 14379: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14380: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14381: }
14382: }
14383: if (keys(%todelete)) {
14384: foreach my $key (keys(%todelete)) {
14385: unlink($key);
1.1066 raeburn 14386: }
14387: }
14388: if (keys(%todeletedir)) {
14389: foreach my $key (keys(%todeletedir)) {
14390: rmdir($key);
14391: }
14392: }
14393: foreach my $dir (sort(keys(%is_dir))) {
14394: if (($pathtocheck ne '') && ($dir ne '')) {
14395: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14396: }
14397: }
1.1067 raeburn 14398: if ($result ne '') {
14399: $output .= '<ul>'."\n".
14400: $result."\n".
14401: '</ul>';
14402: }
14403: unless ($ishome) {
14404: my $replicationfail;
14405: foreach my $item (keys(%prompttofetch)) {
14406: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14407: unless ($fetchresult eq 'ok') {
14408: $replicationfail .= '<li>'.$item.'</li>'."\n";
14409: }
14410: }
14411: if ($replicationfail) {
14412: $output .= '<p class="LC_error">'.
14413: &mt('Course home server failed to retrieve:').'<ul>'.
14414: $replicationfail.
14415: '</ul></p>';
14416: }
14417: }
1.1055 raeburn 14418: } else {
14419: $warning = &mt('No items found in archive.');
14420: }
14421: if ($error) {
14422: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14423: $error.'</p>'."\n";
14424: }
14425: if ($warning) {
14426: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14427: }
14428: return $output;
14429: }
14430:
1.1066 raeburn 14431: sub cleanup_empty_dirs {
14432: my ($path) = @_;
14433: if (($path ne '') && (-d $path)) {
14434: if (opendir(my $dirh,$path)) {
14435: my @dircontents = grep(!/^\./,readdir($dirh));
14436: my $numitems = 0;
14437: foreach my $item (@dircontents) {
14438: if (-d "$path/$item") {
1.1075.2.28 raeburn 14439: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14440: if (-e "$path/$item") {
14441: $numitems ++;
14442: }
14443: } else {
14444: $numitems ++;
14445: }
14446: }
14447: if ($numitems == 0) {
14448: rmdir($path);
14449: }
14450: closedir($dirh);
14451: }
14452: }
14453: return;
14454: }
14455:
1.41 ng 14456: =pod
1.45 matthew 14457:
1.1075.2.56 raeburn 14458: =item * &get_folder_hierarchy()
1.1068 raeburn 14459:
14460: Provides hierarchy of names of folders/sub-folders containing the current
14461: item,
14462:
14463: Inputs: 3
14464: - $navmap - navmaps object
14465:
14466: - $map - url for map (either the trigger itself, or map containing
14467: the resource, which is the trigger).
14468:
14469: - $showitem - 1 => show title for map itself; 0 => do not show.
14470:
14471: Outputs: 1 @pathitems - array of folder/subfolder names.
14472:
14473: =cut
14474:
14475: sub get_folder_hierarchy {
14476: my ($navmap,$map,$showitem) = @_;
14477: my @pathitems;
14478: if (ref($navmap)) {
14479: my $mapres = $navmap->getResourceByUrl($map);
14480: if (ref($mapres)) {
14481: my $pcslist = $mapres->map_hierarchy();
14482: if ($pcslist ne '') {
14483: my @pcs = split(/,/,$pcslist);
14484: foreach my $pc (@pcs) {
14485: if ($pc == 1) {
1.1075.2.38 raeburn 14486: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14487: } else {
14488: my $res = $navmap->getByMapPc($pc);
14489: if (ref($res)) {
14490: my $title = $res->compTitle();
14491: $title =~ s/\W+/_/g;
14492: if ($title ne '') {
14493: push(@pathitems,$title);
14494: }
14495: }
14496: }
14497: }
14498: }
1.1071 raeburn 14499: if ($showitem) {
14500: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 14501: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14502: } else {
14503: my $maptitle = $mapres->compTitle();
14504: $maptitle =~ s/\W+/_/g;
14505: if ($maptitle ne '') {
14506: push(@pathitems,$maptitle);
14507: }
1.1068 raeburn 14508: }
14509: }
14510: }
14511: }
14512: return @pathitems;
14513: }
14514:
14515: =pod
14516:
1.1015 raeburn 14517: =item * &get_turnedin_filepath()
14518:
14519: Determines path in a user's portfolio file for storage of files uploaded
14520: to a specific essayresponse or dropbox item.
14521:
14522: Inputs: 3 required + 1 optional.
14523: $symb is symb for resource, $uname and $udom are for current user (required).
14524: $caller is optional (can be "submission", if routine is called when storing
14525: an upoaded file when "Submit Answer" button was pressed).
14526:
14527: Returns array containing $path and $multiresp.
14528: $path is path in portfolio. $multiresp is 1 if this resource contains more
14529: than one file upload item. Callers of routine should append partid as a
14530: subdirectory to $path in cases where $multiresp is 1.
14531:
14532: Called by: homework/essayresponse.pm and homework/structuretags.pm
14533:
14534: =cut
14535:
14536: sub get_turnedin_filepath {
14537: my ($symb,$uname,$udom,$caller) = @_;
14538: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14539: my $turnindir;
14540: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14541: $turnindir = $userhash{'turnindir'};
14542: my ($path,$multiresp);
14543: if ($turnindir eq '') {
14544: if ($caller eq 'submission') {
14545: $turnindir = &mt('turned in');
14546: $turnindir =~ s/\W+/_/g;
14547: my %newhash = (
14548: 'turnindir' => $turnindir,
14549: );
14550: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14551: }
14552: }
14553: if ($turnindir ne '') {
14554: $path = '/'.$turnindir.'/';
14555: my ($multipart,$turnin,@pathitems);
14556: my $navmap = Apache::lonnavmaps::navmap->new();
14557: if (defined($navmap)) {
14558: my $mapres = $navmap->getResourceByUrl($map);
14559: if (ref($mapres)) {
14560: my $pcslist = $mapres->map_hierarchy();
14561: if ($pcslist ne '') {
14562: foreach my $pc (split(/,/,$pcslist)) {
14563: my $res = $navmap->getByMapPc($pc);
14564: if (ref($res)) {
14565: my $title = $res->compTitle();
14566: $title =~ s/\W+/_/g;
14567: if ($title ne '') {
1.1075.2.48 raeburn 14568: if (($pc > 1) && (length($title) > 12)) {
14569: $title = substr($title,0,12);
14570: }
1.1015 raeburn 14571: push(@pathitems,$title);
14572: }
14573: }
14574: }
14575: }
14576: my $maptitle = $mapres->compTitle();
14577: $maptitle =~ s/\W+/_/g;
14578: if ($maptitle ne '') {
1.1075.2.48 raeburn 14579: if (length($maptitle) > 12) {
14580: $maptitle = substr($maptitle,0,12);
14581: }
1.1015 raeburn 14582: push(@pathitems,$maptitle);
14583: }
14584: unless ($env{'request.state'} eq 'construct') {
14585: my $res = $navmap->getBySymb($symb);
14586: if (ref($res)) {
14587: my $partlist = $res->parts();
14588: my $totaluploads = 0;
14589: if (ref($partlist) eq 'ARRAY') {
14590: foreach my $part (@{$partlist}) {
14591: my @types = $res->responseType($part);
14592: my @ids = $res->responseIds($part);
14593: for (my $i=0; $i < scalar(@ids); $i++) {
14594: if ($types[$i] eq 'essay') {
14595: my $partid = $part.'_'.$ids[$i];
14596: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14597: $totaluploads ++;
14598: }
14599: }
14600: }
14601: }
14602: if ($totaluploads > 1) {
14603: $multiresp = 1;
14604: }
14605: }
14606: }
14607: }
14608: } else {
14609: return;
14610: }
14611: } else {
14612: return;
14613: }
14614: my $restitle=&Apache::lonnet::gettitle($symb);
14615: $restitle =~ s/\W+/_/g;
14616: if ($restitle eq '') {
14617: $restitle = ($resurl =~ m{/[^/]+$});
14618: if ($restitle eq '') {
14619: $restitle = time;
14620: }
14621: }
1.1075.2.48 raeburn 14622: if (length($restitle) > 12) {
14623: $restitle = substr($restitle,0,12);
14624: }
1.1015 raeburn 14625: push(@pathitems,$restitle);
14626: $path .= join('/',@pathitems);
14627: }
14628: return ($path,$multiresp);
14629: }
14630:
14631: =pod
14632:
1.464 albertel 14633: =back
1.41 ng 14634:
1.112 bowersj2 14635: =head1 CSV Upload/Handling functions
1.38 albertel 14636:
1.41 ng 14637: =over 4
14638:
1.648 raeburn 14639: =item * &upfile_store($r)
1.41 ng 14640:
14641: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14642: needs $env{'form.upfile'}
1.41 ng 14643: returns $datatoken to be put into hidden field
14644:
14645: =cut
1.31 albertel 14646:
14647: sub upfile_store {
14648: my $r=shift;
1.258 albertel 14649: $env{'form.upfile'}=~s/\r/\n/gs;
14650: $env{'form.upfile'}=~s/\f/\n/gs;
14651: $env{'form.upfile'}=~s/\n+/\n/gs;
14652: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14653:
1.1075.2.128 raeburn 14654: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14655: '_enroll_'.$env{'request.course.id'}.'_'.
14656: time.'_'.$$);
14657: return if ($datatoken eq '');
14658:
1.31 albertel 14659: {
1.158 raeburn 14660: my $datafile = $r->dir_config('lonDaemons').
14661: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14662: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14663: print $fh $env{'form.upfile'};
1.158 raeburn 14664: close($fh);
14665: }
1.31 albertel 14666: }
14667: return $datatoken;
14668: }
14669:
1.56 matthew 14670: =pod
14671:
1.1075.2.128 raeburn 14672: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14673:
14674: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14675: $datatoken is the name to assign to the temporary file.
1.258 albertel 14676: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14677:
14678: =cut
1.31 albertel 14679:
14680: sub load_tmp_file {
1.1075.2.128 raeburn 14681: my ($r,$datatoken) = @_;
14682: return if ($datatoken eq '');
1.31 albertel 14683: my @studentdata=();
14684: {
1.158 raeburn 14685: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14686: '/tmp/'.$datatoken.'.tmp';
14687: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14688: @studentdata=<$fh>;
14689: close($fh);
14690: }
1.31 albertel 14691: }
1.258 albertel 14692: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14693: }
14694:
1.1075.2.128 raeburn 14695: sub valid_datatoken {
14696: my ($datatoken) = @_;
1.1075.2.131 raeburn 14697: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14698: return $datatoken;
14699: }
14700: return;
14701: }
14702:
1.56 matthew 14703: =pod
14704:
1.648 raeburn 14705: =item * &upfile_record_sep()
1.41 ng 14706:
14707: Separate uploaded file into records
14708: returns array of records,
1.258 albertel 14709: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14710:
14711: =cut
1.31 albertel 14712:
14713: sub upfile_record_sep {
1.258 albertel 14714: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14715: } else {
1.248 albertel 14716: my @records;
1.258 albertel 14717: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14718: if ($line=~/^\s*$/) { next; }
14719: push(@records,$line);
14720: }
14721: return @records;
1.31 albertel 14722: }
14723: }
14724:
1.56 matthew 14725: =pod
14726:
1.648 raeburn 14727: =item * &record_sep($record)
1.41 ng 14728:
1.258 albertel 14729: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14730:
14731: =cut
14732:
1.263 www 14733: sub takeleft {
14734: my $index=shift;
14735: return substr('0000'.$index,-4,4);
14736: }
14737:
1.31 albertel 14738: sub record_sep {
14739: my $record=shift;
14740: my %components=();
1.258 albertel 14741: if ($env{'form.upfiletype'} eq 'xml') {
14742: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14743: my $i=0;
1.356 albertel 14744: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14745: $field=~s/^(\"|\')//;
14746: $field=~s/(\"|\')$//;
1.263 www 14747: $components{&takeleft($i)}=$field;
1.31 albertel 14748: $i++;
14749: }
1.258 albertel 14750: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14751: my $i=0;
1.356 albertel 14752: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14753: $field=~s/^(\"|\')//;
14754: $field=~s/(\"|\')$//;
1.263 www 14755: $components{&takeleft($i)}=$field;
1.31 albertel 14756: $i++;
14757: }
14758: } else {
1.561 www 14759: my $separator=',';
1.480 banghart 14760: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14761: $separator=';';
1.480 banghart 14762: }
1.31 albertel 14763: my $i=0;
1.561 www 14764: # the character we are looking for to indicate the end of a quote or a record
14765: my $looking_for=$separator;
14766: # do not add the characters to the fields
14767: my $ignore=0;
14768: # we just encountered a separator (or the beginning of the record)
14769: my $just_found_separator=1;
14770: # store the field we are working on here
14771: my $field='';
14772: # work our way through all characters in record
14773: foreach my $character ($record=~/(.)/g) {
14774: if ($character eq $looking_for) {
14775: if ($character ne $separator) {
14776: # Found the end of a quote, again looking for separator
14777: $looking_for=$separator;
14778: $ignore=1;
14779: } else {
14780: # Found a separator, store away what we got
14781: $components{&takeleft($i)}=$field;
14782: $i++;
14783: $just_found_separator=1;
14784: $ignore=0;
14785: $field='';
14786: }
14787: next;
14788: }
14789: # single or double quotation marks after a separator indicate beginning of a quote
14790: # we are now looking for the end of the quote and need to ignore separators
14791: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14792: $looking_for=$character;
14793: next;
14794: }
14795: # ignore would be true after we reached the end of a quote
14796: if ($ignore) { next; }
14797: if (($just_found_separator) && ($character=~/\s/)) { next; }
14798: $field.=$character;
14799: $just_found_separator=0;
1.31 albertel 14800: }
1.561 www 14801: # catch the very last entry, since we never encountered the separator
14802: $components{&takeleft($i)}=$field;
1.31 albertel 14803: }
14804: return %components;
14805: }
14806:
1.144 matthew 14807: ######################################################
14808: ######################################################
14809:
1.56 matthew 14810: =pod
14811:
1.648 raeburn 14812: =item * &upfile_select_html()
1.41 ng 14813:
1.144 matthew 14814: Return HTML code to select a file from the users machine and specify
14815: the file type.
1.41 ng 14816:
14817: =cut
14818:
1.144 matthew 14819: ######################################################
14820: ######################################################
1.31 albertel 14821: sub upfile_select_html {
1.144 matthew 14822: my %Types = (
14823: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14824: semisv => &mt('Semicolon separated values'),
1.144 matthew 14825: space => &mt('Space separated'),
14826: tab => &mt('Tabulator separated'),
14827: # xml => &mt('HTML/XML'),
14828: );
14829: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14830: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14831: foreach my $type (sort(keys(%Types))) {
14832: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14833: }
14834: $Str .= "</select>\n";
14835: return $Str;
1.31 albertel 14836: }
14837:
1.301 albertel 14838: sub get_samples {
14839: my ($records,$toget) = @_;
14840: my @samples=({});
14841: my $got=0;
14842: foreach my $rec (@$records) {
14843: my %temp = &record_sep($rec);
14844: if (! grep(/\S/, values(%temp))) { next; }
14845: if (%temp) {
14846: $samples[$got]=\%temp;
14847: $got++;
14848: if ($got == $toget) { last; }
14849: }
14850: }
14851: return \@samples;
14852: }
14853:
1.144 matthew 14854: ######################################################
14855: ######################################################
14856:
1.56 matthew 14857: =pod
14858:
1.648 raeburn 14859: =item * &csv_print_samples($r,$records)
1.41 ng 14860:
14861: Prints a table of sample values from each column uploaded $r is an
14862: Apache Request ref, $records is an arrayref from
14863: &Apache::loncommon::upfile_record_sep
14864:
14865: =cut
14866:
1.144 matthew 14867: ######################################################
14868: ######################################################
1.31 albertel 14869: sub csv_print_samples {
14870: my ($r,$records) = @_;
1.662 bisitz 14871: my $samples = &get_samples($records,5);
1.301 albertel 14872:
1.594 raeburn 14873: $r->print(&mt('Samples').'<br />'.&start_data_table().
14874: &start_data_table_header_row());
1.356 albertel 14875: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14876: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14877: $r->print(&end_data_table_header_row());
1.301 albertel 14878: foreach my $hash (@$samples) {
1.594 raeburn 14879: $r->print(&start_data_table_row());
1.356 albertel 14880: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14881: $r->print('<td>');
1.356 albertel 14882: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14883: $r->print('</td>');
14884: }
1.594 raeburn 14885: $r->print(&end_data_table_row());
1.31 albertel 14886: }
1.594 raeburn 14887: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14888: }
14889:
1.144 matthew 14890: ######################################################
14891: ######################################################
14892:
1.56 matthew 14893: =pod
14894:
1.648 raeburn 14895: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14896:
14897: Prints a table to create associations between values and table columns.
1.144 matthew 14898:
1.41 ng 14899: $r is an Apache Request ref,
14900: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14901: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14902:
14903: =cut
14904:
1.144 matthew 14905: ######################################################
14906: ######################################################
1.31 albertel 14907: sub csv_print_select_table {
14908: my ($r,$records,$d) = @_;
1.301 albertel 14909: my $i=0;
14910: my $samples = &get_samples($records,1);
1.144 matthew 14911: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14912: &start_data_table().&start_data_table_header_row().
1.144 matthew 14913: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14914: '<th>'.&mt('Column').'</th>'.
14915: &end_data_table_header_row()."\n");
1.356 albertel 14916: foreach my $array_ref (@$d) {
14917: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14918: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14919:
1.875 bisitz 14920: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14921: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14922: $r->print('<option value="none"></option>');
1.356 albertel 14923: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14924: $r->print('<option value="'.$sample.'"'.
14925: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14926: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14927: }
1.594 raeburn 14928: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14929: $i++;
14930: }
1.594 raeburn 14931: $r->print(&end_data_table());
1.31 albertel 14932: $i--;
14933: return $i;
14934: }
1.56 matthew 14935:
1.144 matthew 14936: ######################################################
14937: ######################################################
14938:
1.56 matthew 14939: =pod
1.31 albertel 14940:
1.648 raeburn 14941: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14942:
14943: Prints a table of sample values from the upload and can make associate samples to internal names.
14944:
14945: $r is an Apache Request ref,
14946: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14947: $d is an array of 2 element arrays (internal name, displayed name)
14948:
14949: =cut
14950:
1.144 matthew 14951: ######################################################
14952: ######################################################
1.31 albertel 14953: sub csv_samples_select_table {
14954: my ($r,$records,$d) = @_;
14955: my $i=0;
1.144 matthew 14956: #
1.662 bisitz 14957: my $max_samples = 5;
14958: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14959: $r->print(&start_data_table().
14960: &start_data_table_header_row().'<th>'.
14961: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14962: &end_data_table_header_row());
1.301 albertel 14963:
14964: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14965: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14966: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14967: foreach my $option (@$d) {
14968: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14969: $r->print('<option value="'.$value.'"'.
1.253 albertel 14970: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14971: $display.'</option>');
1.31 albertel 14972: }
14973: $r->print('</select></td><td>');
1.662 bisitz 14974: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14975: if (defined($samples->[$line]{$key})) {
14976: $r->print($samples->[$line]{$key}."<br />\n");
14977: }
14978: }
1.594 raeburn 14979: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14980: $i++;
14981: }
1.594 raeburn 14982: $r->print(&end_data_table());
1.31 albertel 14983: $i--;
14984: return($i);
1.115 matthew 14985: }
14986:
1.144 matthew 14987: ######################################################
14988: ######################################################
14989:
1.115 matthew 14990: =pod
14991:
1.648 raeburn 14992: =item * &clean_excel_name($name)
1.115 matthew 14993:
14994: Returns a replacement for $name which does not contain any illegal characters.
14995:
14996: =cut
14997:
1.144 matthew 14998: ######################################################
14999: ######################################################
1.115 matthew 15000: sub clean_excel_name {
15001: my ($name) = @_;
15002: $name =~ s/[:\*\?\/\\]//g;
15003: if (length($name) > 31) {
15004: $name = substr($name,0,31);
15005: }
15006: return $name;
1.25 albertel 15007: }
1.84 albertel 15008:
1.85 albertel 15009: =pod
15010:
1.648 raeburn 15011: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15012:
15013: Returns either 1 or undef
15014:
15015: 1 if the part is to be hidden, undef if it is to be shown
15016:
15017: Arguments are:
15018:
15019: $id the id of the part to be checked
15020: $symb, optional the symb of the resource to check
15021: $udom, optional the domain of the user to check for
15022: $uname, optional the username of the user to check for
15023:
15024: =cut
1.84 albertel 15025:
15026: sub check_if_partid_hidden {
15027: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15028: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15029: $symb,$udom,$uname);
1.141 albertel 15030: my $truth=1;
15031: #if the string starts with !, then the list is the list to show not hide
15032: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15033: my @hiddenlist=split(/,/,$hiddenparts);
15034: foreach my $checkid (@hiddenlist) {
1.141 albertel 15035: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15036: }
1.141 albertel 15037: return !$truth;
1.84 albertel 15038: }
1.127 matthew 15039:
1.138 matthew 15040:
15041: ############################################################
15042: ############################################################
15043:
15044: =pod
15045:
1.157 matthew 15046: =back
15047:
1.138 matthew 15048: =head1 cgi-bin script and graphing routines
15049:
1.157 matthew 15050: =over 4
15051:
1.648 raeburn 15052: =item * &get_cgi_id()
1.138 matthew 15053:
15054: Inputs: none
15055:
15056: Returns an id which can be used to pass environment variables
15057: to various cgi-bin scripts. These environment variables will
15058: be removed from the users environment after a given time by
15059: the routine &Apache::lonnet::transfer_profile_to_env.
15060:
15061: =cut
15062:
15063: ############################################################
15064: ############################################################
1.152 albertel 15065: my $uniq=0;
1.136 matthew 15066: sub get_cgi_id {
1.154 albertel 15067: $uniq=($uniq+1)%100000;
1.280 albertel 15068: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15069: }
15070:
1.127 matthew 15071: ############################################################
15072: ############################################################
15073:
15074: =pod
15075:
1.648 raeburn 15076: =item * &DrawBarGraph()
1.127 matthew 15077:
1.138 matthew 15078: Facilitates the plotting of data in a (stacked) bar graph.
15079: Puts plot definition data into the users environment in order for
15080: graph.png to plot it. Returns an <img> tag for the plot.
15081: The bars on the plot are labeled '1','2',...,'n'.
15082:
15083: Inputs:
15084:
15085: =over 4
15086:
15087: =item $Title: string, the title of the plot
15088:
15089: =item $xlabel: string, text describing the X-axis of the plot
15090:
15091: =item $ylabel: string, text describing the Y-axis of the plot
15092:
15093: =item $Max: scalar, the maximum Y value to use in the plot
15094: If $Max is < any data point, the graph will not be rendered.
15095:
1.140 matthew 15096: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15097: they are plotted. If undefined, default values will be used.
15098:
1.178 matthew 15099: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15100:
1.138 matthew 15101: =item @Values: An array of array references. Each array reference holds data
15102: to be plotted in a stacked bar chart.
15103:
1.239 matthew 15104: =item If the final element of @Values is a hash reference the key/value
15105: pairs will be added to the graph definition.
15106:
1.138 matthew 15107: =back
15108:
15109: Returns:
15110:
15111: An <img> tag which references graph.png and the appropriate identifying
15112: information for the plot.
15113:
1.127 matthew 15114: =cut
15115:
15116: ############################################################
15117: ############################################################
1.134 matthew 15118: sub DrawBarGraph {
1.178 matthew 15119: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15120: #
15121: if (! defined($colors)) {
15122: $colors = ['#33ff00',
15123: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15124: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15125: ];
15126: }
1.228 matthew 15127: my $extra_settings = {};
15128: if (ref($Values[-1]) eq 'HASH') {
15129: $extra_settings = pop(@Values);
15130: }
1.127 matthew 15131: #
1.136 matthew 15132: my $identifier = &get_cgi_id();
15133: my $id = 'cgi.'.$identifier;
1.129 matthew 15134: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15135: return '';
15136: }
1.225 matthew 15137: #
15138: my @Labels;
15139: if (defined($labels)) {
15140: @Labels = @$labels;
15141: } else {
15142: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 15143: push(@Labels,$i+1);
1.225 matthew 15144: }
15145: }
15146: #
1.129 matthew 15147: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15148: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15149: my %ValuesHash;
15150: my $NumSets=1;
15151: foreach my $array (@Values) {
15152: next if (! ref($array));
1.136 matthew 15153: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15154: join(',',@$array);
1.129 matthew 15155: }
1.127 matthew 15156: #
1.136 matthew 15157: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15158: if ($NumBars < 3) {
15159: $width = 120+$NumBars*32;
1.220 matthew 15160: $xskip = 1;
1.225 matthew 15161: $bar_width = 30;
15162: } elsif ($NumBars < 5) {
15163: $width = 120+$NumBars*20;
15164: $xskip = 1;
15165: $bar_width = 20;
1.220 matthew 15166: } elsif ($NumBars < 10) {
1.136 matthew 15167: $width = 120+$NumBars*15;
15168: $xskip = 1;
15169: $bar_width = 15;
15170: } elsif ($NumBars <= 25) {
15171: $width = 120+$NumBars*11;
15172: $xskip = 5;
15173: $bar_width = 8;
15174: } elsif ($NumBars <= 50) {
15175: $width = 120+$NumBars*8;
15176: $xskip = 5;
15177: $bar_width = 4;
15178: } else {
15179: $width = 120+$NumBars*8;
15180: $xskip = 5;
15181: $bar_width = 4;
15182: }
15183: #
1.137 matthew 15184: $Max = 1 if ($Max < 1);
15185: if ( int($Max) < $Max ) {
15186: $Max++;
15187: $Max = int($Max);
15188: }
1.127 matthew 15189: $Title = '' if (! defined($Title));
15190: $xlabel = '' if (! defined($xlabel));
15191: $ylabel = '' if (! defined($ylabel));
1.369 www 15192: $ValuesHash{$id.'.title'} = &escape($Title);
15193: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15194: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15195: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15196: $ValuesHash{$id.'.NumBars'} = $NumBars;
15197: $ValuesHash{$id.'.NumSets'} = $NumSets;
15198: $ValuesHash{$id.'.PlotType'} = 'bar';
15199: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15200: $ValuesHash{$id.'.height'} = $height;
15201: $ValuesHash{$id.'.width'} = $width;
15202: $ValuesHash{$id.'.xskip'} = $xskip;
15203: $ValuesHash{$id.'.bar_width'} = $bar_width;
15204: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15205: #
1.228 matthew 15206: # Deal with other parameters
15207: while (my ($key,$value) = each(%$extra_settings)) {
15208: $ValuesHash{$id.'.'.$key} = $value;
15209: }
15210: #
1.646 raeburn 15211: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15212: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15213: }
15214:
15215: ############################################################
15216: ############################################################
15217:
15218: =pod
15219:
1.648 raeburn 15220: =item * &DrawXYGraph()
1.137 matthew 15221:
1.138 matthew 15222: Facilitates the plotting of data in an XY graph.
15223: Puts plot definition data into the users environment in order for
15224: graph.png to plot it. Returns an <img> tag for the plot.
15225:
15226: Inputs:
15227:
15228: =over 4
15229:
15230: =item $Title: string, the title of the plot
15231:
15232: =item $xlabel: string, text describing the X-axis of the plot
15233:
15234: =item $ylabel: string, text describing the Y-axis of the plot
15235:
15236: =item $Max: scalar, the maximum Y value to use in the plot
15237: If $Max is < any data point, the graph will not be rendered.
15238:
15239: =item $colors: Array ref containing the hex color codes for the data to be
15240: plotted in. If undefined, default values will be used.
15241:
15242: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15243:
15244: =item $Ydata: Array ref containing Array refs.
1.185 www 15245: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15246:
15247: =item %Values: hash indicating or overriding any default values which are
15248: passed to graph.png.
15249: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15250:
15251: =back
15252:
15253: Returns:
15254:
15255: An <img> tag which references graph.png and the appropriate identifying
15256: information for the plot.
15257:
1.137 matthew 15258: =cut
15259:
15260: ############################################################
15261: ############################################################
15262: sub DrawXYGraph {
15263: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15264: #
15265: # Create the identifier for the graph
15266: my $identifier = &get_cgi_id();
15267: my $id = 'cgi.'.$identifier;
15268: #
15269: $Title = '' if (! defined($Title));
15270: $xlabel = '' if (! defined($xlabel));
15271: $ylabel = '' if (! defined($ylabel));
15272: my %ValuesHash =
15273: (
1.369 www 15274: $id.'.title' => &escape($Title),
15275: $id.'.xlabel' => &escape($xlabel),
15276: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15277: $id.'.y_max_value'=> $Max,
15278: $id.'.labels' => join(',',@$Xlabels),
15279: $id.'.PlotType' => 'XY',
15280: );
15281: #
15282: if (defined($colors) && ref($colors) eq 'ARRAY') {
15283: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15284: }
15285: #
15286: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15287: return '';
15288: }
15289: my $NumSets=1;
1.138 matthew 15290: foreach my $array (@{$Ydata}){
1.137 matthew 15291: next if (! ref($array));
15292: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15293: }
1.138 matthew 15294: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15295: #
15296: # Deal with other parameters
15297: while (my ($key,$value) = each(%Values)) {
15298: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15299: }
15300: #
1.646 raeburn 15301: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15302: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15303: }
15304:
15305: ############################################################
15306: ############################################################
15307:
15308: =pod
15309:
1.648 raeburn 15310: =item * &DrawXYYGraph()
1.138 matthew 15311:
15312: Facilitates the plotting of data in an XY graph with two Y axes.
15313: Puts plot definition data into the users environment in order for
15314: graph.png to plot it. Returns an <img> tag for the plot.
15315:
15316: Inputs:
15317:
15318: =over 4
15319:
15320: =item $Title: string, the title of the plot
15321:
15322: =item $xlabel: string, text describing the X-axis of the plot
15323:
15324: =item $ylabel: string, text describing the Y-axis of the plot
15325:
15326: =item $colors: Array ref containing the hex color codes for the data to be
15327: plotted in. If undefined, default values will be used.
15328:
15329: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15330:
15331: =item $Ydata1: The first data set
15332:
15333: =item $Min1: The minimum value of the left Y-axis
15334:
15335: =item $Max1: The maximum value of the left Y-axis
15336:
15337: =item $Ydata2: The second data set
15338:
15339: =item $Min2: The minimum value of the right Y-axis
15340:
15341: =item $Max2: The maximum value of the left Y-axis
15342:
15343: =item %Values: hash indicating or overriding any default values which are
15344: passed to graph.png.
15345: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15346:
15347: =back
15348:
15349: Returns:
15350:
15351: An <img> tag which references graph.png and the appropriate identifying
15352: information for the plot.
1.136 matthew 15353:
15354: =cut
15355:
15356: ############################################################
15357: ############################################################
1.137 matthew 15358: sub DrawXYYGraph {
15359: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15360: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15361: #
15362: # Create the identifier for the graph
15363: my $identifier = &get_cgi_id();
15364: my $id = 'cgi.'.$identifier;
15365: #
15366: $Title = '' if (! defined($Title));
15367: $xlabel = '' if (! defined($xlabel));
15368: $ylabel = '' if (! defined($ylabel));
15369: my %ValuesHash =
15370: (
1.369 www 15371: $id.'.title' => &escape($Title),
15372: $id.'.xlabel' => &escape($xlabel),
15373: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15374: $id.'.labels' => join(',',@$Xlabels),
15375: $id.'.PlotType' => 'XY',
15376: $id.'.NumSets' => 2,
1.137 matthew 15377: $id.'.two_axes' => 1,
15378: $id.'.y1_max_value' => $Max1,
15379: $id.'.y1_min_value' => $Min1,
15380: $id.'.y2_max_value' => $Max2,
15381: $id.'.y2_min_value' => $Min2,
1.136 matthew 15382: );
15383: #
1.137 matthew 15384: if (defined($colors) && ref($colors) eq 'ARRAY') {
15385: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15386: }
15387: #
15388: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15389: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15390: return '';
15391: }
15392: my $NumSets=1;
1.137 matthew 15393: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15394: next if (! ref($array));
15395: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15396: }
15397: #
15398: # Deal with other parameters
15399: while (my ($key,$value) = each(%Values)) {
15400: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15401: }
15402: #
1.646 raeburn 15403: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15404: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15405: }
15406:
15407: ############################################################
15408: ############################################################
15409:
15410: =pod
15411:
1.157 matthew 15412: =back
15413:
1.139 matthew 15414: =head1 Statistics helper routines?
15415:
15416: Bad place for them but what the hell.
15417:
1.157 matthew 15418: =over 4
15419:
1.648 raeburn 15420: =item * &chartlink()
1.139 matthew 15421:
15422: Returns a link to the chart for a specific student.
15423:
15424: Inputs:
15425:
15426: =over 4
15427:
15428: =item $linktext: The text of the link
15429:
15430: =item $sname: The students username
15431:
15432: =item $sdomain: The students domain
15433:
15434: =back
15435:
1.157 matthew 15436: =back
15437:
1.139 matthew 15438: =cut
15439:
15440: ############################################################
15441: ############################################################
15442: sub chartlink {
15443: my ($linktext, $sname, $sdomain) = @_;
15444: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15445: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15446: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15447: '">'.$linktext.'</a>';
1.153 matthew 15448: }
15449:
15450: #######################################################
15451: #######################################################
15452:
15453: =pod
15454:
15455: =head1 Course Environment Routines
1.157 matthew 15456:
15457: =over 4
1.153 matthew 15458:
1.648 raeburn 15459: =item * &restore_course_settings()
1.153 matthew 15460:
1.648 raeburn 15461: =item * &store_course_settings()
1.153 matthew 15462:
15463: Restores/Store indicated form parameters from the course environment.
15464: Will not overwrite existing values of the form parameters.
15465:
15466: Inputs:
15467: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15468:
15469: a hash ref describing the data to be stored. For example:
15470:
15471: %Save_Parameters = ('Status' => 'scalar',
15472: 'chartoutputmode' => 'scalar',
15473: 'chartoutputdata' => 'scalar',
15474: 'Section' => 'array',
1.373 raeburn 15475: 'Group' => 'array',
1.153 matthew 15476: 'StudentData' => 'array',
15477: 'Maps' => 'array');
15478:
15479: Returns: both routines return nothing
15480:
1.631 raeburn 15481: =back
15482:
1.153 matthew 15483: =cut
15484:
15485: #######################################################
15486: #######################################################
15487: sub store_course_settings {
1.496 albertel 15488: return &store_settings($env{'request.course.id'},@_);
15489: }
15490:
15491: sub store_settings {
1.153 matthew 15492: # save to the environment
15493: # appenv the same items, just to be safe
1.300 albertel 15494: my $udom = $env{'user.domain'};
15495: my $uname = $env{'user.name'};
1.496 albertel 15496: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15497: my %SaveHash;
15498: my %AppHash;
15499: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15500: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15501: my $envname = 'environment.'.$basename;
1.258 albertel 15502: if (exists($env{'form.'.$setting})) {
1.153 matthew 15503: # Save this value away
15504: if ($type eq 'scalar' &&
1.258 albertel 15505: (! exists($env{$envname}) ||
15506: $env{$envname} ne $env{'form.'.$setting})) {
15507: $SaveHash{$basename} = $env{'form.'.$setting};
15508: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15509: } elsif ($type eq 'array') {
15510: my $stored_form;
1.258 albertel 15511: if (ref($env{'form.'.$setting})) {
1.153 matthew 15512: $stored_form = join(',',
15513: map {
1.369 www 15514: &escape($_);
1.258 albertel 15515: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15516: } else {
15517: $stored_form =
1.369 www 15518: &escape($env{'form.'.$setting});
1.153 matthew 15519: }
15520: # Determine if the array contents are the same.
1.258 albertel 15521: if ($stored_form ne $env{$envname}) {
1.153 matthew 15522: $SaveHash{$basename} = $stored_form;
15523: $AppHash{$envname} = $stored_form;
15524: }
15525: }
15526: }
15527: }
15528: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15529: $udom,$uname);
1.153 matthew 15530: if ($put_result !~ /^(ok|delayed)/) {
15531: &Apache::lonnet::logthis('unable to save form parameters, '.
15532: 'got error:'.$put_result);
15533: }
15534: # Make sure these settings stick around in this session, too
1.646 raeburn 15535: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15536: return;
15537: }
15538:
15539: sub restore_course_settings {
1.499 albertel 15540: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15541: }
15542:
15543: sub restore_settings {
15544: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15545: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15546: next if (exists($env{'form.'.$setting}));
1.496 albertel 15547: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15548: '.'.$setting;
1.258 albertel 15549: if (exists($env{$envname})) {
1.153 matthew 15550: if ($type eq 'scalar') {
1.258 albertel 15551: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15552: } elsif ($type eq 'array') {
1.258 albertel 15553: $env{'form.'.$setting} = [
1.153 matthew 15554: map {
1.369 www 15555: &unescape($_);
1.258 albertel 15556: } split(',',$env{$envname})
1.153 matthew 15557: ];
15558: }
15559: }
15560: }
1.127 matthew 15561: }
15562:
1.618 raeburn 15563: #######################################################
15564: #######################################################
15565:
15566: =pod
15567:
15568: =head1 Domain E-mail Routines
15569:
15570: =over 4
15571:
1.648 raeburn 15572: =item * &build_recipient_list()
1.618 raeburn 15573:
1.1075.2.44 raeburn 15574: Build recipient lists for following types of e-mail:
1.766 raeburn 15575: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 15576: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15577: module change checking, student/employee ID conflict checks, as
15578: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15579: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15580:
15581: Inputs:
1.1075.2.44 raeburn 15582: defmail (scalar - email address of default recipient),
15583: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15584: requestsmail, updatesmail, or idconflictsmail).
15585:
1.619 raeburn 15586: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 15587:
15588: origmail (scalar - email address of recipient from loncapa.conf,
15589: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 15590:
1.1075.2.139 raeburn 15591: $requname username of requester (if mailing type is helpdeskmail)
15592:
15593: $requdom domain of requester (if mailing type is helpdeskmail)
15594:
15595: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15596:
1.655 raeburn 15597: Returns: comma separated list of addresses to which to send e-mail.
15598:
15599: =back
1.618 raeburn 15600:
15601: =cut
15602:
15603: ############################################################
15604: ############################################################
15605: sub build_recipient_list {
1.1075.2.139 raeburn 15606: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15607: my @recipients;
1.1075.2.122 raeburn 15608: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15609: my %domconfig =
1.1075.2.122 raeburn 15610: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15611: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15612: if (exists($domconfig{'contacts'}{$mailing})) {
15613: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15614: my @contacts = ('adminemail','supportemail');
15615: foreach my $item (@contacts) {
15616: if ($domconfig{'contacts'}{$mailing}{$item}) {
15617: my $addr = $domconfig{'contacts'}{$item};
15618: if (!grep(/^\Q$addr\E$/,@recipients)) {
15619: push(@recipients,$addr);
15620: }
1.619 raeburn 15621: }
1.1075.2.122 raeburn 15622: }
15623: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15624: if ($mailing eq 'helpdeskmail') {
15625: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15626: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15627: my @ok_bccs;
15628: foreach my $bcc (@bccs) {
15629: $bcc =~ s/^\s+//g;
15630: $bcc =~ s/\s+$//g;
15631: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15632: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15633: push(@ok_bccs,$bcc);
15634: }
15635: }
15636: }
15637: if (@ok_bccs > 0) {
15638: $allbcc = join(', ',@ok_bccs);
15639: }
15640: }
15641: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15642: }
15643: }
1.766 raeburn 15644: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15645: $lastresort = $origmail;
1.618 raeburn 15646: }
1.1075.2.139 raeburn 15647: if ($mailing eq 'helpdeskmail') {
15648: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15649: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15650: my ($inststatus,$inststatus_checked);
15651: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15652: ($env{'user.domain'} ne 'public')) {
15653: $inststatus_checked = 1;
15654: $inststatus = $env{'environment.inststatus'};
15655: }
15656: unless ($inststatus_checked) {
15657: if (($requname ne '') && ($requdom ne '')) {
15658: if (($requname =~ /^$match_username$/) &&
15659: ($requdom =~ /^$match_domain$/) &&
15660: (&Apache::lonnet::domain($requdom))) {
15661: my $requhome = &Apache::lonnet::homeserver($requname,
15662: $requdom);
15663: unless ($requhome eq 'no_host') {
15664: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15665: $inststatus = $userenv{'inststatus'};
15666: $inststatus_checked = 1;
15667: }
15668: }
15669: }
15670: }
15671: unless ($inststatus_checked) {
15672: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15673: my %srch = (srchby => 'email',
15674: srchdomain => $defdom,
15675: srchterm => $reqemail,
15676: srchtype => 'exact');
15677: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15678: foreach my $uname (keys(%srch_results)) {
15679: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15680: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15681: $inststatus_checked = 1;
15682: last;
15683: }
15684: }
15685: unless ($inststatus_checked) {
15686: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15687: if ($dirsrchres eq 'ok') {
15688: foreach my $uname (keys(%srch_results)) {
15689: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15690: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15691: $inststatus_checked = 1;
15692: last;
15693: }
15694: }
15695: }
15696: }
15697: }
15698: }
15699: if ($inststatus ne '') {
15700: foreach my $status (split(/\:/,$inststatus)) {
15701: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15702: my @contacts = ('adminemail','supportemail');
15703: foreach my $item (@contacts) {
15704: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15705: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15706: if (!grep(/^\Q$addr\E$/,@recipients)) {
15707: push(@recipients,$addr);
15708: }
15709: }
15710: }
15711: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15712: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15713: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15714: my @ok_bccs;
15715: foreach my $bcc (@bccs) {
15716: $bcc =~ s/^\s+//g;
15717: $bcc =~ s/\s+$//g;
15718: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15719: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15720: push(@ok_bccs,$bcc);
15721: }
15722: }
15723: }
15724: if (@ok_bccs > 0) {
15725: $allbcc = join(', ',@ok_bccs);
15726: }
15727: }
15728: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15729: last;
15730: }
15731: }
15732: }
15733: }
15734: }
1.619 raeburn 15735: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15736: $lastresort = $origmail;
15737: }
1.1075.2.128 raeburn 15738: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15739: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15740: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15741: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15742: my %what = (
15743: perlvar => 1,
15744: );
15745: my $primary = &Apache::lonnet::domain($defdom,'primary');
15746: if ($primary) {
15747: my $gotaddr;
15748: my ($result,$returnhash) =
15749: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15750: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15751: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15752: $lastresort = $returnhash->{'lonSupportEMail'};
15753: $gotaddr = 1;
15754: }
15755: }
15756: unless ($gotaddr) {
15757: my $uintdom = &Apache::lonnet::internet_dom($primary);
15758: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15759: unless ($uintdom eq $intdom) {
15760: my %domconfig =
15761: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15762: if (ref($domconfig{'contacts'}) eq 'HASH') {
15763: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15764: my @contacts = ('adminemail','supportemail');
15765: foreach my $item (@contacts) {
15766: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15767: my $addr = $domconfig{'contacts'}{$item};
15768: if (!grep(/^\Q$addr\E$/,@recipients)) {
15769: push(@recipients,$addr);
15770: }
15771: }
15772: }
15773: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15774: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15775: }
15776: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15777: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15778: my @ok_bccs;
15779: foreach my $bcc (@bccs) {
15780: $bcc =~ s/^\s+//g;
15781: $bcc =~ s/\s+$//g;
15782: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15783: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15784: push(@ok_bccs,$bcc);
15785: }
15786: }
15787: }
15788: if (@ok_bccs > 0) {
15789: $allbcc = join(', ',@ok_bccs);
15790: }
15791: }
15792: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15793: }
15794: }
15795: }
15796: }
15797: }
15798: }
1.618 raeburn 15799: }
1.688 raeburn 15800: if (defined($defmail)) {
15801: if ($defmail ne '') {
15802: push(@recipients,$defmail);
15803: }
1.618 raeburn 15804: }
15805: if ($otheremails) {
1.619 raeburn 15806: my @others;
15807: if ($otheremails =~ /,/) {
15808: @others = split(/,/,$otheremails);
1.618 raeburn 15809: } else {
1.619 raeburn 15810: push(@others,$otheremails);
15811: }
15812: foreach my $addr (@others) {
15813: if (!grep(/^\Q$addr\E$/,@recipients)) {
15814: push(@recipients,$addr);
15815: }
1.618 raeburn 15816: }
15817: }
1.1075.2.128 raeburn 15818: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15819: if ((!@recipients) && ($lastresort ne '')) {
15820: push(@recipients,$lastresort);
15821: }
15822: } elsif ($lastresort ne '') {
15823: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15824: push(@recipients,$lastresort);
15825: }
15826: }
15827: my $recipientlist = join(',',@recipients);
15828: if (wantarray) {
15829: return ($recipientlist,$allbcc,$addtext);
15830: } else {
15831: return $recipientlist;
15832: }
1.618 raeburn 15833: }
15834:
1.127 matthew 15835: ############################################################
15836: ############################################################
1.154 albertel 15837:
1.655 raeburn 15838: =pod
15839:
15840: =head1 Course Catalog Routines
15841:
15842: =over 4
15843:
15844: =item * &gather_categories()
15845:
15846: Converts category definitions - keys of categories hash stored in
15847: coursecategories in configuration.db on the primary library server in a
15848: domain - to an array. Also generates javascript and idx hash used to
15849: generate Domain Coordinator interface for editing Course Categories.
15850:
15851: Inputs:
1.663 raeburn 15852:
1.655 raeburn 15853: categories (reference to hash of category definitions).
1.663 raeburn 15854:
1.655 raeburn 15855: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15856: categories and subcategories).
1.663 raeburn 15857:
1.655 raeburn 15858: idx (reference to hash of counters used in Domain Coordinator interface for
15859: editing Course Categories).
1.663 raeburn 15860:
1.655 raeburn 15861: jsarray (reference to array of categories used to create Javascript arrays for
15862: Domain Coordinator interface for editing Course Categories).
15863:
15864: Returns: nothing
15865:
15866: Side effects: populates cats, idx and jsarray.
15867:
15868: =cut
15869:
15870: sub gather_categories {
15871: my ($categories,$cats,$idx,$jsarray) = @_;
15872: my %counters;
15873: my $num = 0;
15874: foreach my $item (keys(%{$categories})) {
15875: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15876: if ($container eq '' && $depth == 0) {
15877: $cats->[$depth][$categories->{$item}] = $cat;
15878: } else {
15879: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15880: }
15881: my ($escitem,$tail) = split(/:/,$item,2);
15882: if ($counters{$tail} eq '') {
15883: $counters{$tail} = $num;
15884: $num ++;
15885: }
15886: if (ref($idx) eq 'HASH') {
15887: $idx->{$item} = $counters{$tail};
15888: }
15889: if (ref($jsarray) eq 'ARRAY') {
15890: push(@{$jsarray->[$counters{$tail}]},$item);
15891: }
15892: }
15893: return;
15894: }
15895:
15896: =pod
15897:
15898: =item * &extract_categories()
15899:
15900: Used to generate breadcrumb trails for course categories.
15901:
15902: Inputs:
1.663 raeburn 15903:
1.655 raeburn 15904: categories (reference to hash of category definitions).
1.663 raeburn 15905:
1.655 raeburn 15906: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15907: categories and subcategories).
1.663 raeburn 15908:
1.655 raeburn 15909: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15910:
1.655 raeburn 15911: allitems (reference to hash - key is category key
15912: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15913:
1.655 raeburn 15914: idx (reference to hash of counters used in Domain Coordinator interface for
15915: editing Course Categories).
1.663 raeburn 15916:
1.655 raeburn 15917: jsarray (reference to array of categories used to create Javascript arrays for
15918: Domain Coordinator interface for editing Course Categories).
15919:
1.665 raeburn 15920: subcats (reference to hash of arrays containing all subcategories within each
15921: category, -recursive)
15922:
1.1075.2.132 raeburn 15923: maxd (reference to hash used to hold max depth for all top-level categories).
15924:
1.655 raeburn 15925: Returns: nothing
15926:
15927: Side effects: populates trails and allitems hash references.
15928:
15929: =cut
15930:
15931: sub extract_categories {
1.1075.2.132 raeburn 15932: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15933: if (ref($categories) eq 'HASH') {
15934: &gather_categories($categories,$cats,$idx,$jsarray);
15935: if (ref($cats->[0]) eq 'ARRAY') {
15936: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15937: my $name = $cats->[0][$i];
15938: my $item = &escape($name).'::0';
15939: my $trailstr;
15940: if ($name eq 'instcode') {
15941: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15942: } elsif ($name eq 'communities') {
15943: $trailstr = &mt('Communities');
1.655 raeburn 15944: } else {
15945: $trailstr = $name;
15946: }
15947: if ($allitems->{$item} eq '') {
15948: push(@{$trails},$trailstr);
15949: $allitems->{$item} = scalar(@{$trails})-1;
15950: }
15951: my @parents = ($name);
15952: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15953: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15954: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15955: if (ref($subcats) eq 'HASH') {
15956: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15957: }
1.1075.2.132 raeburn 15958: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15959: }
15960: } else {
15961: if (ref($subcats) eq 'HASH') {
15962: $subcats->{$item} = [];
1.655 raeburn 15963: }
1.1075.2.132 raeburn 15964: if (ref($maxd) eq 'HASH') {
15965: $maxd->{$name} = 1;
15966: }
1.655 raeburn 15967: }
15968: }
15969: }
15970: }
15971: return;
15972: }
15973:
15974: =pod
15975:
1.1075.2.56 raeburn 15976: =item * &recurse_categories()
1.655 raeburn 15977:
15978: Recursively used to generate breadcrumb trails for course categories.
15979:
15980: Inputs:
1.663 raeburn 15981:
1.655 raeburn 15982: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15983: categories and subcategories).
1.663 raeburn 15984:
1.655 raeburn 15985: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15986:
15987: category (current course category, for which breadcrumb trail is being generated).
15988:
15989: trails (reference to array of breadcrumb trails for each category).
15990:
1.655 raeburn 15991: allitems (reference to hash - key is category key
15992: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15993:
1.655 raeburn 15994: parents (array containing containers directories for current category,
15995: back to top level).
15996:
15997: Returns: nothing
15998:
15999: Side effects: populates trails and allitems hash references
16000:
16001: =cut
16002:
16003: sub recurse_categories {
1.1075.2.132 raeburn 16004: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16005: my $shallower = $depth - 1;
16006: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16007: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16008: my $name = $cats->[$depth]{$category}[$k];
16009: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 16010:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16011: if ($allitems->{$item} eq '') {
16012: push(@{$trails},$trailstr);
16013: $allitems->{$item} = scalar(@{$trails})-1;
16014: }
16015: my $deeper = $depth+1;
16016: push(@{$parents},$category);
1.665 raeburn 16017: if (ref($subcats) eq 'HASH') {
16018: my $subcat = &escape($name).':'.$category.':'.$depth;
16019: for (my $j=@{$parents}; $j>=0; $j--) {
16020: my $higher;
16021: if ($j > 0) {
16022: $higher = &escape($parents->[$j]).':'.
16023: &escape($parents->[$j-1]).':'.$j;
16024: } else {
16025: $higher = &escape($parents->[$j]).'::'.$j;
16026: }
16027: push(@{$subcats->{$higher}},$subcat);
16028: }
16029: }
16030: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 16031: $subcats,$maxd);
1.655 raeburn 16032: pop(@{$parents});
16033: }
16034: } else {
16035: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 16036: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16037: if ($allitems->{$item} eq '') {
16038: push(@{$trails},$trailstr);
16039: $allitems->{$item} = scalar(@{$trails})-1;
16040: }
1.1075.2.132 raeburn 16041: if (ref($maxd) eq 'HASH') {
16042: if ($depth > $maxd->{$parents->[0]}) {
16043: $maxd->{$parents->[0]} = $depth;
16044: }
16045: }
1.655 raeburn 16046: }
16047: return;
16048: }
16049:
1.663 raeburn 16050: =pod
16051:
1.1075.2.56 raeburn 16052: =item * &assign_categories_table()
1.663 raeburn 16053:
16054: Create a datatable for display of hierarchical categories in a domain,
16055: with checkboxes to allow a course to be categorized.
16056:
16057: Inputs:
16058:
16059: cathash - reference to hash of categories defined for the domain (from
16060: configuration.db)
16061:
16062: currcat - scalar with an & separated list of categories assigned to a course.
16063:
1.919 raeburn 16064: type - scalar contains course type (Course or Community).
16065:
1.1075.2.117 raeburn 16066: disabled - scalar (optional) contains disabled="disabled" if input elements are
16067: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16068:
1.663 raeburn 16069: Returns: $output (markup to be displayed)
16070:
16071: =cut
16072:
16073: sub assign_categories_table {
1.1075.2.117 raeburn 16074: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16075: my $output;
16076: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 16077: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16078: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16079: $maxdepth = scalar(@cats);
16080: if (@cats > 0) {
16081: my $itemcount = 0;
16082: if (ref($cats[0]) eq 'ARRAY') {
16083: my @currcategories;
16084: if ($currcat ne '') {
16085: @currcategories = split('&',$currcat);
16086: }
1.919 raeburn 16087: my $table;
1.663 raeburn 16088: for (my $i=0; $i<@{$cats[0]}; $i++) {
16089: my $parent = $cats[0][$i];
1.919 raeburn 16090: next if ($parent eq 'instcode');
16091: if ($type eq 'Community') {
16092: next unless ($parent eq 'communities');
16093: } else {
16094: next if ($parent eq 'communities');
16095: }
1.663 raeburn 16096: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16097: my $item = &escape($parent).'::0';
16098: my $checked = '';
16099: if (@currcategories > 0) {
16100: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16101: $checked = ' checked="checked"';
1.663 raeburn 16102: }
16103: }
1.919 raeburn 16104: my $parent_title = $parent;
16105: if ($parent eq 'communities') {
16106: $parent_title = &mt('Communities');
16107: }
16108: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16109: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16110: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16111: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16112: my $depth = 1;
16113: push(@path,$parent);
1.1075.2.117 raeburn 16114: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16115: pop(@path);
1.919 raeburn 16116: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16117: $itemcount ++;
16118: }
1.919 raeburn 16119: if ($itemcount) {
16120: $output = &Apache::loncommon::start_data_table().
16121: $table.
16122: &Apache::loncommon::end_data_table();
16123: }
1.663 raeburn 16124: }
16125: }
16126: }
16127: return $output;
16128: }
16129:
16130: =pod
16131:
1.1075.2.56 raeburn 16132: =item * &assign_category_rows()
1.663 raeburn 16133:
16134: Create a datatable row for display of nested categories in a domain,
16135: with checkboxes to allow a course to be categorized,called recursively.
16136:
16137: Inputs:
16138:
16139: itemcount - track row number for alternating colors
16140:
16141: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16142: categories and subcategories.
16143:
16144: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16145:
16146: parent - parent of current category item
16147:
16148: path - Array containing all categories back up through the hierarchy from the
16149: current category to the top level.
16150:
16151: currcategories - reference to array of current categories assigned to the course
16152:
1.1075.2.117 raeburn 16153: disabled - scalar (optional) contains disabled="disabled" if input elements are
16154: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16155:
1.663 raeburn 16156: Returns: $output (markup to be displayed).
16157:
16158: =cut
16159:
16160: sub assign_category_rows {
1.1075.2.117 raeburn 16161: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16162: my ($text,$name,$item,$chgstr);
16163: if (ref($cats) eq 'ARRAY') {
16164: my $maxdepth = scalar(@{$cats});
16165: if (ref($cats->[$depth]) eq 'HASH') {
16166: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16167: my $numchildren = @{$cats->[$depth]{$parent}};
16168: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 16169: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16170: for (my $j=0; $j<$numchildren; $j++) {
16171: $name = $cats->[$depth]{$parent}[$j];
16172: $item = &escape($name).':'.&escape($parent).':'.$depth;
16173: my $deeper = $depth+1;
16174: my $checked = '';
16175: if (ref($currcategories) eq 'ARRAY') {
16176: if (@{$currcategories} > 0) {
16177: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16178: $checked = ' checked="checked"';
1.663 raeburn 16179: }
16180: }
16181: }
1.664 raeburn 16182: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16183: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 16184: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16185: '<input type="hidden" name="catname" value="'.$name.'" />'.
16186: '</td><td>';
1.663 raeburn 16187: if (ref($path) eq 'ARRAY') {
16188: push(@{$path},$name);
1.1075.2.117 raeburn 16189: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16190: pop(@{$path});
16191: }
16192: $text .= '</td></tr>';
16193: }
16194: $text .= '</table></td>';
16195: }
16196: }
16197: }
16198: return $text;
16199: }
16200:
1.1075.2.69 raeburn 16201: =pod
16202:
16203: =back
16204:
16205: =cut
16206:
1.655 raeburn 16207: ############################################################
16208: ############################################################
16209:
16210:
1.443 albertel 16211: sub commit_customrole {
1.664 raeburn 16212: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16213: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16214: ($start?', '.&mt('starting').' '.localtime($start):'').
16215: ($end?', ending '.localtime($end):'').': <b>'.
16216: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16217: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16218: '</b><br />';
16219: return $output;
16220: }
16221:
16222: sub commit_standardrole {
1.1075.2.31 raeburn 16223: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16224: my ($output,$logmsg,$linefeed);
16225: if ($context eq 'auto') {
16226: $linefeed = "\n";
16227: } else {
16228: $linefeed = "<br />\n";
16229: }
1.443 albertel 16230: if ($three eq 'st') {
1.541 raeburn 16231: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 16232: $one,$two,$sec,$context,$credits);
1.541 raeburn 16233: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16234: ($result eq 'unknown_course') || ($result eq 'refused')) {
16235: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16236: } else {
1.541 raeburn 16237: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16238: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16239: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16240: if ($context eq 'auto') {
16241: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16242: } else {
16243: $output .= '<b>'.$result.'</b>'.$linefeed.
16244: &mt('Add to classlist').': <b>ok</b>';
16245: }
16246: $output .= $linefeed;
1.443 albertel 16247: }
16248: } else {
16249: $output = &mt('Assigning').' '.$three.' in '.$url.
16250: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16251: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16252: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16253: if ($context eq 'auto') {
16254: $output .= $result.$linefeed;
16255: } else {
16256: $output .= '<b>'.$result.'</b>'.$linefeed;
16257: }
1.443 albertel 16258: }
16259: return $output;
16260: }
16261:
16262: sub commit_studentrole {
1.1075.2.31 raeburn 16263: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16264: $credits) = @_;
1.626 raeburn 16265: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16266: if ($context eq 'auto') {
16267: $linefeed = "\n";
16268: } else {
16269: $linefeed = '<br />'."\n";
16270: }
1.443 albertel 16271: if (defined($one) && defined($two)) {
16272: my $cid=$one.'_'.$two;
16273: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16274: my $secchange = 0;
16275: my $expire_role_result;
16276: my $modify_section_result;
1.628 raeburn 16277: if ($oldsec ne '-1') {
16278: if ($oldsec ne $sec) {
1.443 albertel 16279: $secchange = 1;
1.628 raeburn 16280: my $now = time;
1.443 albertel 16281: my $uurl='/'.$cid;
16282: $uurl=~s/\_/\//g;
16283: if ($oldsec) {
16284: $uurl.='/'.$oldsec;
16285: }
1.626 raeburn 16286: $oldsecurl = $uurl;
1.628 raeburn 16287: $expire_role_result =
1.1075.2.161. .14(raeb 16288:-23): &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 16289: if ($env{'request.course.sec'} ne '') {
16290: if ($expire_role_result eq 'refused') {
16291: my @roles = ('st');
16292: my @statuses = ('previous');
16293: my @roledoms = ($one);
16294: my $withsec = 1;
16295: my %roleshash =
16296: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16297: \@statuses,\@roles,\@roledoms,$withsec);
16298: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16299: my ($oldstart,$oldend) =
16300: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16301: if ($oldend > 0 && $oldend <= $now) {
16302: $expire_role_result = 'ok';
16303: }
16304: }
16305: }
16306: }
1.443 albertel 16307: $result = $expire_role_result;
16308: }
16309: }
16310: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 16311: $modify_section_result =
16312: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16313: undef,undef,undef,$sec,
16314: $end,$start,'','',$cid,
16315: '',$context,$credits);
1.443 albertel 16316: if ($modify_section_result =~ /^ok/) {
16317: if ($secchange == 1) {
1.628 raeburn 16318: if ($sec eq '') {
16319: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16320: } else {
16321: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16322: }
1.443 albertel 16323: } elsif ($oldsec eq '-1') {
1.628 raeburn 16324: if ($sec eq '') {
16325: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16326: } else {
16327: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16328: }
1.443 albertel 16329: } else {
1.628 raeburn 16330: if ($sec eq '') {
16331: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16332: } else {
16333: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16334: }
1.443 albertel 16335: }
16336: } else {
1.628 raeburn 16337: if ($secchange) {
16338: $$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;
16339: } else {
16340: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16341: }
1.443 albertel 16342: }
16343: $result = $modify_section_result;
16344: } elsif ($secchange == 1) {
1.628 raeburn 16345: if ($oldsec eq '') {
1.1075.2.20 raeburn 16346: $$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 16347: } else {
16348: $$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;
16349: }
1.626 raeburn 16350: if ($expire_role_result eq 'refused') {
16351: my $newsecurl = '/'.$cid;
16352: $newsecurl =~ s/\_/\//g;
16353: if ($sec ne '') {
16354: $newsecurl.='/'.$sec;
16355: }
16356: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16357: if ($sec eq '') {
16358: $$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;
16359: } else {
16360: $$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;
16361: }
16362: }
16363: }
1.443 albertel 16364: }
16365: } else {
1.626 raeburn 16366: $$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 16367: $result = "error: incomplete course id\n";
16368: }
16369: return $result;
16370: }
16371:
1.1075.2.25 raeburn 16372: sub show_role_extent {
16373: my ($scope,$context,$role) = @_;
16374: $scope =~ s{^/}{};
16375: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16376: push(@courseroles,'co');
16377: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16378: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16379: $scope =~ s{/}{_};
16380: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16381: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16382: my ($audom,$auname) = split(/\//,$scope);
16383: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16384: &Apache::loncommon::plainname($auname,$audom).'</span>');
16385: } else {
16386: $scope =~ s{/$}{};
16387: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16388: &Apache::lonnet::domain($scope,'description').'</span>');
16389: }
16390: }
16391:
1.443 albertel 16392: ############################################################
16393: ############################################################
16394:
1.566 albertel 16395: sub check_clone {
1.578 raeburn 16396: my ($args,$linefeed) = @_;
1.566 albertel 16397: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16398: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16399: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 16400:21): my $clonetitle;
16401:21): my @clonemsg;
1.566 albertel 16402: my $can_clone = 0;
1.944 raeburn 16403: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16404: if ($lctype ne 'community') {
16405: $lctype = 'course';
16406: }
1.566 albertel 16407: if ($clonehome eq 'no_host') {
1.944 raeburn 16408: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16409:21): push(@clonemsg,({
16410:21): mt => 'No new community created.',
16411:21): args => [],
16412:21): },
16413:21): {
16414:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16415:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16416:21): }));
1.908 raeburn 16417: } else {
1.1075.2.161. .1(raebu 16418:21): push(@clonemsg,({
16419:21): mt => 'No new course created.',
16420:21): args => [],
16421:21): },
16422:21): {
16423:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16424:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16425:21): }));
16426:21): }
1.566 albertel 16427: } else {
16428: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 16429:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 16430: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16431: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 16432:21): push(@clonemsg,({
16433:21): mt => 'No new community created.',
16434:21): args => [],
16435:21): },
16436:21): {
16437:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16438:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16439:21): }));
16440:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16441: }
16442: }
1.1075.2.119 raeburn 16443: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16444: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16445: $can_clone = 1;
16446: } else {
1.1075.2.95 raeburn 16447: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16448: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 16449: if ($clonehash{'cloners'} eq '') {
16450: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16451: if ($domdefs{'canclone'}) {
16452: unless ($domdefs{'canclone'} eq 'none') {
16453: if ($domdefs{'canclone'} eq 'domain') {
16454: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16455: $can_clone = 1;
16456: }
16457: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16458: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16459: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16460: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16461: $can_clone = 1;
16462: }
16463: }
16464: }
1.908 raeburn 16465: }
1.1075.2.95 raeburn 16466: } else {
16467: my @cloners = split(/,/,$clonehash{'cloners'});
16468: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16469: $can_clone = 1;
1.1075.2.95 raeburn 16470: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16471: $can_clone = 1;
1.1075.2.96 raeburn 16472: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16473: $can_clone = 1;
1.1075.2.95 raeburn 16474: }
16475: unless ($can_clone) {
1.1075.2.96 raeburn 16476: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16477: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 16478: my (%gotdomdefaults,%gotcodedefaults);
16479: foreach my $cloner (@cloners) {
16480: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16481: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16482: my (%codedefaults,@code_order);
16483: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16484: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16485: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16486: }
16487: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16488: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16489: }
16490: } else {
16491: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16492: \%codedefaults,
16493: \@code_order);
16494: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16495: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16496: }
16497: if (@code_order > 0) {
16498: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16499: $cloner,$clonehash{'internal.coursecode'},
16500: $args->{'crscode'})) {
16501: $can_clone = 1;
16502: last;
16503: }
16504: }
16505: }
16506: }
16507: }
1.1075.2.96 raeburn 16508: }
16509: }
16510: unless ($can_clone) {
16511: my $ccrole = 'cc';
16512: if ($args->{'crstype'} eq 'Community') {
16513: $ccrole = 'co';
16514: }
16515: my %roleshash =
16516: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16517: $args->{'ccdomain'},
16518: 'userroles',['active'],[$ccrole],
16519: [$args->{'clonedomain'}]);
16520: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16521: $can_clone = 1;
16522: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16523: $args->{'ccuname'},$args->{'ccdomain'})) {
16524: $can_clone = 1;
1.1075.2.95 raeburn 16525: }
16526: }
16527: unless ($can_clone) {
16528: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16529:21): push(@clonemsg,({
16530:21): mt => 'No new community created.',
16531:21): args => [],
16532:21): },
16533:21): {
16534: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]).',
16535:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16536:21): }));
1.1075.2.95 raeburn 16537: } else {
1.1075.2.161. .1(raebu 16538:21): push(@clonemsg,({
16539:21): mt => 'No new course created.',
16540:21): args => [],
16541:21): },
16542:21): {
16543: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]).',
16544:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16545:21): }));
1.578 raeburn 16546: }
1.566 albertel 16547: }
1.578 raeburn 16548: }
1.566 albertel 16549: }
1.1075.2.161. .1(raebu 16550:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16551: }
16552:
1.444 albertel 16553: sub construct_course {
1.1075.2.119 raeburn 16554: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 16555:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16556:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16557: my $linefeed = '<br />'."\n";
16558: if ($context eq 'auto') {
16559: $linefeed = "\n";
16560: }
1.566 albertel 16561:
16562: #
16563: # Are we cloning?
16564: #
1.1075.2.161. .1(raebu 16565:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16566: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 16567:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16568: if (!$can_clone) {
1.1075.2.161. .1(raebu 16569:21): return (0,$outcome,$clonemsgref);
1.566 albertel 16570: }
16571: }
16572:
1.444 albertel 16573: #
16574: # Open course
16575: #
16576: my $crstype = lc($args->{'crstype'});
16577: my %cenv=();
16578: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16579: $args->{'cdescr'},
16580: $args->{'curl'},
16581: $args->{'course_home'},
16582: $args->{'nonstandard'},
16583: $args->{'crscode'},
16584: $args->{'ccuname'}.':'.
16585: $args->{'ccdomain'},
1.882 raeburn 16586: $args->{'crstype'},
1.1075.2.161. .1(raebu 16587:21): $cnum,$context,$category,
16588:21): $callercontext);
1.444 albertel 16589:
16590: # Note: The testing routines depend on this being output; see
16591: # Utils::Course. This needs to at least be output as a comment
16592: # if anyone ever decides to not show this, and Utils::Course::new
16593: # will need to be suitably modified.
1.1075.2.161. .1(raebu 16594:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16595:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16596:21): } else {
16597:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16598:21): }
1.943 raeburn 16599: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 16600:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16601: }
16602:
1.444 albertel 16603: #
16604: # Check if created correctly
16605: #
1.479 albertel 16606: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16607: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16608: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 16609:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16610:21): $outcome .= &mt_user($user_lh,
16611:21): 'Course creation failed, unrecognized course home server.');
16612:21): } else {
16613:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
16614:21): }
16615:21): $outcome .= $linefeed;
16616:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16617: }
1.541 raeburn 16618: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16619:
1.444 albertel 16620: #
1.566 albertel 16621: # Do the cloning
1.1075.2.161. .1(raebu 16622:21): #
16623:21): my @clonemsg;
1.566 albertel 16624: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 16625:21): push(@clonemsg,
16626:21): {
16627:21): mt => 'Created [_1] by cloning from [_2]',
16628:21): args => [$crstype,$clonetitle],
16629:21): });
1.566 albertel 16630: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16631: # Copy all files
1.1075.2.161. .1(raebu 16632:21): my @info =
16633:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16634:21): $args->{'dateshift'},$args->{'crscode'},
16635:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16636:21): $args->{'tinyurls'});
16637:21): if (@info) {
16638:21): push(@clonemsg,@info);
16639:21): }
1.444 albertel 16640: # Restore URL
1.566 albertel 16641: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16642: # Restore title
1.566 albertel 16643: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16644: # Restore creation date, creator and creation context.
16645: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16646: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16647: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16648: # Mark as cloned
1.566 albertel 16649: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16650: # Need to clone grading mode
16651: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16652: $cenv{'grading'}=$newenv{'grading'};
16653: # Do not clone these environment entries
16654: &Apache::lonnet::del('environment',
16655: ['default_enrollment_start_date',
16656: 'default_enrollment_end_date',
16657: 'question.email',
16658: 'policy.email',
16659: 'comment.email',
16660: 'pch.users.denied',
1.725 raeburn 16661: 'plc.users.denied',
16662: 'hidefromcat',
1.1075.2.36 raeburn 16663: 'checkforpriv',
1.1075.2.158 raeburn 16664: 'categories'],
1.638 www 16665: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16666: if ($args->{'textbook'}) {
16667: $cenv{'internal.textbook'} = $args->{'textbook'};
16668: }
1.444 albertel 16669: }
1.566 albertel 16670:
1.444 albertel 16671: #
16672: # Set environment (will override cloned, if existing)
16673: #
16674: my @sections = ();
16675: my @xlists = ();
16676: if ($args->{'crstype'}) {
16677: $cenv{'type'}=$args->{'crstype'};
16678: }
1.1075.2.161. .17(raeb 16679:-23): if ($args->{'lti'}) {
16680:-23): $cenv{'internal.lti'}=$args->{'lti'};
16681:-23): }
1.444 albertel 16682: if ($args->{'crsid'}) {
16683: $cenv{'courseid'}=$args->{'crsid'};
16684: }
16685: if ($args->{'crscode'}) {
16686: $cenv{'internal.coursecode'}=$args->{'crscode'};
16687: }
16688: if ($args->{'crsquota'} ne '') {
16689: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16690: } else {
16691: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16692: }
16693: if ($args->{'ccuname'}) {
16694: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16695: ':'.$args->{'ccdomain'};
16696: } else {
16697: $cenv{'internal.courseowner'} = $args->{'curruser'};
16698: }
1.1075.2.31 raeburn 16699: if ($args->{'defaultcredits'}) {
16700: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16701: }
1.444 albertel 16702: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.161. .20(raeb 16703:-23): my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 16704: if ($args->{'crssections'}) {
16705: $cenv{'internal.sectionnums'} = '';
16706: if ($args->{'crssections'} =~ m/,/) {
16707: @sections = split/,/,$args->{'crssections'};
16708: } else {
16709: $sections[0] = $args->{'crssections'};
16710: }
16711: if (@sections > 0) {
16712: foreach my $item (@sections) {
16713: my ($sec,$gp) = split/:/,$item;
16714: my $class = $args->{'crscode'}.$sec;
16715: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16716: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.161. .20(raeb 16717:-23): if ($addcheck eq 'ok') {
16718:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16719:-23): push(@oklcsecs,$gp);
16720:-23): }
16721:-23): } else {
1.1075.2.119 raeburn 16722: push(@badclasses,$class);
1.444 albertel 16723: }
16724: }
16725: $cenv{'internal.sectionnums'} =~ s/,$//;
16726: }
16727: }
16728: # do not hide course coordinator from staff listing,
16729: # even if privileged
16730: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16731: # add course coordinator's domain to domains to check for privileged users
16732: # if different to course domain
16733: if ($$crsudom ne $args->{'ccdomain'}) {
16734: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16735: }
1.444 albertel 16736: # add crosslistings
16737: if ($args->{'crsxlist'}) {
16738: $cenv{'internal.crosslistings'}='';
16739: if ($args->{'crsxlist'} =~ m/,/) {
16740: @xlists = split/,/,$args->{'crsxlist'};
16741: } else {
16742: $xlists[0] = $args->{'crsxlist'};
16743: }
16744: if (@xlists > 0) {
16745: foreach my $item (@xlists) {
16746: my ($xl,$gp) = split/:/,$item;
16747: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16748: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.161. .20(raeb 16749:-23): if ($addcheck eq 'ok') {
16750:-23): unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
16751:-23): push(@oklcsecs,$gp);
16752:-23): }
16753:-23): } else {
1.1075.2.119 raeburn 16754: push(@badclasses,$xl);
1.444 albertel 16755: }
16756: }
16757: $cenv{'internal.crosslistings'} =~ s/,$//;
16758: }
16759: }
16760: if ($args->{'autoadds'}) {
16761: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16762: }
16763: if ($args->{'autodrops'}) {
16764: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16765: }
16766: # check for notification of enrollment changes
16767: my @notified = ();
16768: if ($args->{'notify_owner'}) {
16769: if ($args->{'ccuname'} ne '') {
16770: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16771: }
16772: }
16773: if ($args->{'notify_dc'}) {
16774: if ($uname ne '') {
1.630 raeburn 16775: push(@notified,$uname.':'.$udom);
1.444 albertel 16776: }
16777: }
16778: if (@notified > 0) {
16779: my $notifylist;
16780: if (@notified > 1) {
16781: $notifylist = join(',',@notified);
16782: } else {
16783: $notifylist = $notified[0];
16784: }
16785: $cenv{'internal.notifylist'} = $notifylist;
16786: }
16787: if (@badclasses > 0) {
16788: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16789: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16790: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16791: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16792: );
1.1075.2.119 raeburn 16793: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16794: &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 16795: if ($context eq 'auto') {
16796: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16797: } else {
1.566 albertel 16798: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16799: }
16800: foreach my $item (@badclasses) {
1.541 raeburn 16801: if ($context eq 'auto') {
1.1075.2.119 raeburn 16802: $outcome .= " - $item\n";
1.541 raeburn 16803: } else {
1.1075.2.119 raeburn 16804: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16805: }
1.1075.2.119 raeburn 16806: }
16807: if ($context eq 'auto') {
16808: $outcome .= $linefeed;
16809: } else {
16810: $outcome .= "</ul><br /><br /></div>\n";
16811: }
1.444 albertel 16812: }
16813: if ($args->{'no_end_date'}) {
16814: $args->{'endaccess'} = 0;
16815: }
1.1075.2.161. .20(raeb 16816:-23): # If an official course with institutional sections is created by cloning
16817:-23): # an existing course, section-specific hiding of course totals in student's
16818:-23): # view of grades as copied from cloned course, will be checked for valid
16819:-23): # sections.
16820:-23): if (($can_clone && $cloneid) &&
16821:-23): ($cenv{'internal.coursecode'} ne '') &&
16822:-23): ($cenv{'grading'} eq 'standard') &&
16823:-23): ($cenv{'hidetotals'} ne '') &&
16824:-23): ($cenv{'hidetotals'} ne 'all')) {
16825:-23): my @hidesecs;
16826:-23): my $deletehidetotals;
16827:-23): if (@oklcsecs) {
16828:-23): foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
16829:-23): if (grep(/^\Q$sec$/,@oklcsecs)) {
16830:-23): push(@hidesecs,$sec);
16831:-23): }
16832:-23): }
16833:-23): if (@hidesecs) {
16834:-23): $cenv{'hidetotals'} = join(',',@hidesecs);
16835:-23): } else {
16836:-23): $deletehidetotals = 1;
16837:-23): }
16838:-23): } else {
16839:-23): $deletehidetotals = 1;
16840:-23): }
16841:-23): if ($deletehidetotals) {
16842:-23): delete($cenv{'hidetotals'});
16843:-23): &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
16844:-23): }
16845:-23): }
1.444 albertel 16846: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16847: $cenv{'internal.autoend'}=$args->{'enrollend'};
16848: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16849: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16850: if ($args->{'showphotos'}) {
16851: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16852: }
16853: $cenv{'internal.authtype'} = $args->{'authtype'};
16854: $cenv{'internal.autharg'} = $args->{'autharg'};
16855: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16856: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16857: 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');
16858: if ($context eq 'auto') {
16859: $outcome .= $krb_msg;
16860: } else {
1.566 albertel 16861: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16862: }
16863: $outcome .= $linefeed;
1.444 albertel 16864: }
16865: }
16866: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16867: if ($args->{'setpolicy'}) {
16868: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16869: }
16870: if ($args->{'setcontent'}) {
16871: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16872: }
1.1075.2.110 raeburn 16873: if ($args->{'setcomment'}) {
16874: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16875: }
1.444 albertel 16876: }
16877: if ($args->{'reshome'}) {
16878: $cenv{'reshome'}=$args->{'reshome'}.'/';
16879: $cenv{'reshome'}=~s/\/+$/\//;
16880: }
16881: #
16882: # course has keyed access
16883: #
16884: if ($args->{'setkeys'}) {
16885: $cenv{'keyaccess'}='yes';
16886: }
16887: # if specified, key authority is not course, but user
16888: # only active if keyaccess is yes
16889: if ($args->{'keyauth'}) {
1.487 albertel 16890: my ($user,$domain) = split(':',$args->{'keyauth'});
16891: $user = &LONCAPA::clean_username($user);
16892: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16893: if ($user ne '' && $domain ne '') {
1.487 albertel 16894: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16895: }
16896: }
16897:
1.1075.2.59 raeburn 16898: #
16899: # generate and store uniquecode (available to course requester), if course should have one.
16900: #
16901: if ($args->{'uniquecode'}) {
16902: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16903: if ($code) {
16904: $cenv{'internal.uniquecode'} = $code;
16905: my %crsinfo =
16906: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16907: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16908: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16909: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16910: }
16911: if (ref($coderef)) {
16912: $$coderef = $code;
16913: }
16914: }
16915: }
16916:
1.444 albertel 16917: if ($args->{'disresdis'}) {
16918: $cenv{'pch.roles.denied'}='st';
16919: }
16920: if ($args->{'disablechat'}) {
16921: $cenv{'plc.roles.denied'}='st';
16922: }
16923:
16924: # Record we've not yet viewed the Course Initialization Helper for this
16925: # course
16926: $cenv{'course.helper.not.run'} = 1;
16927: #
16928: # Use new Randomseed
16929: #
16930: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16931: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16932: #
16933: # The encryption code and receipt prefix for this course
16934: #
16935: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16936: $cenv{'internal.encpref'}=100+int(9*rand(99));
16937: #
16938: # By default, use standard grading
16939: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16940:
1.541 raeburn 16941: $outcome .= $linefeed.&mt('Setting environment').': '.
16942: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16943: #
16944: # Open all assignments
16945: #
16946: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16947: my $opendate = time;
16948: if ($args->{'openallfrom'} =~ /^\d+$/) {
16949: $opendate = $args->{'openallfrom'};
16950: }
1.444 albertel 16951: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16952: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16953: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16954: $outcome .= &mt('All assignments open starting [_1]',
16955: &Apache::lonlocal::locallocaltime($opendate)).': '.
16956: &Apache::lonnet::cput
16957: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16958: }
16959: #
16960: # Set first page
16961: #
16962: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16963: || ($cloneid)) {
16964: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16965:
16966: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16967: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16968:
1.444 albertel 16969: $outcome .= ($fatal?$errtext:'read ok').' - ';
16970: my $title; my $url;
16971: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16972: $title=&mt('Syllabus');
1.444 albertel 16973: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16974: } else {
1.963 raeburn 16975: $title=&mt('Table of Contents');
1.444 albertel 16976: $url='/adm/navmaps';
16977: }
1.445 albertel 16978:
16979: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16980: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16981:
16982: if ($errtext) { $fatal=2; }
1.541 raeburn 16983: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16984: }
1.566 albertel 16985:
1.1075.2.161. .1(raebu 16986:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16987: }
16988:
1.1075.2.59 raeburn 16989: sub make_unique_code {
16990: my ($cdom,$cnum) = @_;
16991: # get lock on uniquecodes db
16992: my $lockhash = {
16993: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16994: ':'.$env{'user.domain'},
16995: };
16996: my $tries = 0;
16997: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16998: my ($code,$error);
16999:
17000: while (($gotlock ne 'ok') && ($tries<3)) {
17001: $tries ++;
17002: sleep 1;
17003: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17004: }
17005: if ($gotlock eq 'ok') {
17006: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17007: my $gotcode;
17008: my $attempts = 0;
17009: while ((!$gotcode) && ($attempts < 100)) {
17010: $code = &generate_code();
17011: if (!exists($currcodes{$code})) {
17012: $gotcode = 1;
17013: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17014: $error = 'nostore';
17015: }
17016: }
17017: $attempts ++;
17018: }
17019: my @del_lock = ($cnum."\0".'uniquecodes');
17020: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17021: } else {
17022: $error = 'nolock';
17023: }
17024: return ($code,$error);
17025: }
17026:
17027: sub generate_code {
17028: my $code;
17029: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17030: for (my $i=0; $i<6; $i++) {
17031: my $lettnum = int (rand 2);
17032: my $item = '';
17033: if ($lettnum) {
17034: $item = $letts[int( rand(18) )];
17035: } else {
17036: $item = 1+int( rand(8) );
17037: }
17038: $code .= $item;
17039: }
17040: return $code;
17041: }
17042:
1.444 albertel 17043: ############################################################
17044: ############################################################
17045:
1.953 droeschl 17046: #SD
17047: # only Community and Course, or anything else?
1.378 raeburn 17048: sub course_type {
17049: my ($cid) = @_;
17050: if (!defined($cid)) {
17051: $cid = $env{'request.course.id'};
17052: }
1.404 albertel 17053: if (defined($env{'course.'.$cid.'.type'})) {
17054: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17055: } else {
17056: return 'Course';
1.377 raeburn 17057: }
17058: }
1.156 albertel 17059:
1.406 raeburn 17060: sub group_term {
17061: my $crstype = &course_type();
17062: my %names = (
17063: 'Course' => 'group',
1.865 raeburn 17064: 'Community' => 'group',
1.406 raeburn 17065: );
17066: return $names{$crstype};
17067: }
17068:
1.902 raeburn 17069: sub course_types {
1.1075.2.161. .17(raeb 17070:-23): my @types = ('official','unofficial','community','textbook','lti');
1.902 raeburn 17071: my %typename = (
17072: official => 'Official course',
17073: unofficial => 'Unofficial course',
17074: community => 'Community',
1.1075.2.59 raeburn 17075: textbook => 'Textbook course',
1.1075.2.161. .17(raeb 17076:-23): lti => 'LTI provider',
1.902 raeburn 17077: );
17078: return (\@types,\%typename);
17079: }
17080:
1.156 albertel 17081: sub icon {
17082: my ($file)=@_;
1.505 albertel 17083: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17084: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17085: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17086: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17087: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17088: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17089: $curfext.".gif") {
17090: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17091: $curfext.".gif";
17092: }
17093: }
1.249 albertel 17094: return &lonhttpdurl($iconname);
1.154 albertel 17095: }
1.84 albertel 17096:
1.575 albertel 17097: sub lonhttpdurl {
1.692 www 17098: #
17099: # Had been used for "small fry" static images on separate port 8080.
17100: # Modify here if lightweight http functionality desired again.
17101: # Currently eliminated due to increasing firewall issues.
17102: #
1.575 albertel 17103: my ($url)=@_;
1.692 www 17104: return $url;
1.215 albertel 17105: }
17106:
1.213 albertel 17107: sub connection_aborted {
17108: my ($r)=@_;
17109: $r->print(" ");$r->rflush();
17110: my $c = $r->connection;
17111: return $c->aborted();
17112: }
17113:
1.221 foxr 17114: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17115: # strings as 'strings'.
17116: sub escape_single {
1.221 foxr 17117: my ($input) = @_;
1.223 albertel 17118: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17119: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17120: return $input;
17121: }
1.223 albertel 17122:
1.222 foxr 17123: # Same as escape_single, but escape's "'s This
17124: # can be used for "strings"
17125: sub escape_double {
17126: my ($input) = @_;
17127: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17128: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17129: return $input;
17130: }
1.223 albertel 17131:
1.222 foxr 17132: # Escapes the last element of a full URL.
17133: sub escape_url {
17134: my ($url) = @_;
1.238 raeburn 17135: my @urlslices = split(/\//, $url,-1);
1.369 www 17136: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 17137: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17138: }
1.462 albertel 17139:
1.820 raeburn 17140: sub compare_arrays {
17141: my ($arrayref1,$arrayref2) = @_;
17142: my (@difference,%count);
17143: @difference = ();
17144: %count = ();
17145: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17146: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17147: foreach my $element (keys(%count)) {
17148: if ($count{$element} == 1) {
17149: push(@difference,$element);
17150: }
17151: }
17152: }
17153: return @difference;
17154: }
17155:
1.1075.2.152 raeburn 17156: sub lon_status_items {
17157: my %defaults = (
17158: E => 100,
17159: W => 4,
17160: N => 1,
17161: U => 5,
17162: threshold => 200,
17163: sysmail => 2500,
17164: );
17165: my %names = (
17166: E => 'Errors',
17167: W => 'Warnings',
17168: N => 'Notices',
17169: U => 'Unsent',
17170: );
17171: return (\%defaults,\%names);
17172: }
17173:
1.817 bisitz 17174: # -------------------------------------------------------- Initialize user login
1.462 albertel 17175: sub init_user_environment {
1.463 albertel 17176: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17177: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17178:
17179: my $public=($username eq 'public' && $domain eq 'public');
17180:
17181: # See if old ID present, if so, remove
17182:
1.1075.2.161. .22(raeb 17183:-24): my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17184:-24): $coauthorenv);
1.462 albertel 17185: my $now=time;
17186:
17187: if ($public) {
17188: my $max_public=100;
17189: my $oldest;
17190: my $oldest_time=0;
17191: for(my $next=1;$next<=$max_public;$next++) {
17192: if (-e $lonids."/publicuser_$next.id") {
17193: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17194: if ($mtime<$oldest_time || !$oldest_time) {
17195: $oldest_time=$mtime;
17196: $oldest=$next;
17197: }
17198: } else {
17199: $cookie="publicuser_$next";
17200: last;
17201: }
17202: }
17203: if (!$cookie) { $cookie="publicuser_$oldest"; }
17204: } else {
1.463 albertel 17205: # if this isn't a robot, kill any existing non-robot sessions
17206: if (!$args->{'robot'}) {
17207: opendir(DIR,$lonids);
17208: while ($filename=readdir(DIR)) {
17209: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 17210: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17211: &GDBM_READER(),0640)) {
17212: my $linkedfile;
17213: if (exists($oldenv{'user.linkedenv'})) {
17214: $linkedfile = $oldenv{'user.linkedenv'};
17215: }
17216: untie(%oldenv);
17217: if (unlink("$lonids/$filename")) {
17218: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17219: if (-l "$lonids/$linkedfile.id") {
17220: unlink("$lonids/$linkedfile.id");
17221: }
17222: }
17223: }
17224: } else {
17225: unlink($lonids.'/'.$filename);
17226: }
1.463 albertel 17227: }
1.462 albertel 17228: }
1.463 albertel 17229: closedir(DIR);
1.1075.2.84 raeburn 17230: # If there is a undeleted lockfile for the user's paste buffer remove it.
17231: my $namespace = 'nohist_courseeditor';
17232: my $lockingkey = 'paste'."\0".'locked_num';
17233: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17234: $domain,$username);
17235: if (exists($lockhash{$lockingkey})) {
17236: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17237: unless ($delresult eq 'ok') {
17238: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17239: }
17240: }
1.462 albertel 17241: }
17242: # Give them a new cookie
1.463 albertel 17243: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17244: : $now.$$.int(rand(10000)));
1.463 albertel 17245: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17246:
17247: # Initialize roles
17248:
1.1075.2.161. .22(raeb 17249:-24): ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17250: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17251: }
17252: # ------------------------------------ Check browser type and MathML capability
17253:
1.1075.2.77 raeburn 17254: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17255: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17256:
17257: # ------------------------------------------------------------- Get environment
17258:
17259: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17260: my ($tmp) = keys(%userenv);
17261: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
17262: } else {
17263: undef(%userenv);
17264: }
17265: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17266: $form->{'interface'}=$userenv{'interface'};
17267: }
17268: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17269:
17270: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17271: foreach my $option ('interface','localpath','localres') {
17272: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17273: }
17274: # --------------------------------------------------------- Write first profile
17275:
17276: {
1.1075.2.150 raeburn 17277: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 17278: my %initial_env =
17279: ("user.name" => $username,
17280: "user.domain" => $domain,
17281: "user.home" => $authhost,
17282: "browser.type" => $clientbrowser,
17283: "browser.version" => $clientversion,
17284: "browser.mathml" => $clientmathml,
17285: "browser.unicode" => $clientunicode,
17286: "browser.os" => $clientos,
1.1075.2.42 raeburn 17287: "browser.mobile" => $clientmobile,
17288: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 17289: "browser.osversion" => $clientosversion,
1.462 albertel 17290: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17291: "request.course.fn" => '',
17292: "request.course.uri" => '',
17293: "request.course.sec" => '',
17294: "request.role" => 'cm',
17295: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 17296: "request.host" => $ip,);
1.462 albertel 17297:
17298: if ($form->{'localpath'}) {
17299: $initial_env{"browser.localpath"} = $form->{'localpath'};
17300: $initial_env{"browser.localres"} = $form->{'localres'};
17301: }
17302:
17303: if ($form->{'interface'}) {
17304: $form->{'interface'}=~s/\W//gs;
17305: $initial_env{"browser.interface"} = $form->{'interface'};
17306: $env{'browser.interface'}=$form->{'interface'};
17307: }
17308:
1.1075.2.54 raeburn 17309: if ($form->{'iptoken'}) {
17310: my $lonhost = $r->dir_config('lonHostID');
17311: $initial_env{"user.noloadbalance"} = $lonhost;
17312: $env{'user.noloadbalance'} = $lonhost;
17313: }
17314:
1.1075.2.120 raeburn 17315: if ($form->{'noloadbalance'}) {
17316: my @hosts = &Apache::lonnet::current_machine_ids();
17317: my $hosthere = $form->{'noloadbalance'};
17318: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17319: $initial_env{"user.noloadbalance"} = $hosthere;
17320: $env{'user.noloadbalance'} = $hosthere;
17321: }
17322: }
17323:
1.1016 raeburn 17324: unless ($domain eq 'public') {
1.1075.2.125 raeburn 17325: my %is_adv = ( is_adv => $env{'user.adv'} );
17326: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 17327:
1.1075.2.161. .28(raeb 17328:-24): foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
17329:-24): $userenv{'availabletools.'.$tool} =
1.1075.2.125 raeburn 17330: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17331: undef,\%userenv,\%domdef,\%is_adv);
17332: }
1.724 raeburn 17333:
1.1075.2.161. .17(raeb 17334:-23): foreach my $crstype ('official','unofficial','community','textbook','lti') {
1.1075.2.125 raeburn 17335: $userenv{'canrequest.'.$crstype} =
17336: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17337: 'reload','requestcourses',
17338: \%userenv,\%domdef,\%is_adv);
17339: }
1.765 raeburn 17340:
1.1075.2.161. .21(raeb 17341:-24): if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
17342:-24): (exists($userroles->{"user.role.au./$domain/"}))) {
17343:-24): if ($userenv{'authoreditors'}) {
17344:-24): $userenv{'editors'} = $userenv{'authoreditors'};
17345:-24): } elsif ($domdef{'editors'} ne '') {
17346:-24): $userenv{'editors'} = $domdef{'editors'};
17347:-24): } else {
17348:-24): $userenv{'editors'} = 'edit,xml';
17349:-24): }
.25(raeb 17350:-24): if ($userenv{'authorarchive'}) {
17351:-24): $userenv{'canarchive'} = 1;
17352:-24): } elsif (($userenv{'authorarchive'} eq '') &&
17353:-24): ($domdef{'archive'})) {
17354:-24): $userenv{'canarchive'} = 1;
17355:-24): }
.21(raeb 17356:-24): }
17357:-24):
1.1075.2.125 raeburn 17358: $userenv{'canrequest.author'} =
17359: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17360: 'reload','requestauthor',
17361: \%userenv,\%domdef,\%is_adv);
17362: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17363: $domain,$username);
17364: my $reqstatus = $reqauthor{'author_status'};
17365: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17366: if (ref($reqauthor{'author'}) eq 'HASH') {
17367: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17368: $reqauthor{'author'}{'timestamp'};
17369: }
1.1075.2.14 raeburn 17370: }
17371: }
17372:
1.462 albertel 17373: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17374:
1.462 albertel 17375: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17376: &GDBM_WRCREAT(),0640)) {
17377: &_add_to_env(\%disk_env,\%initial_env);
17378: &_add_to_env(\%disk_env,\%userenv,'environment.');
17379: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17380: if (ref($firstaccenv) eq 'HASH') {
17381: &_add_to_env(\%disk_env,$firstaccenv);
17382: }
17383: if (ref($timerintenv) eq 'HASH') {
17384: &_add_to_env(\%disk_env,$timerintenv);
17385: }
1.1075.2.161. .22(raeb 17386:-24): if (ref($coauthorenv) eq 'HASH') {
17387:-24): if (keys(%{$coauthorenv})) {
17388:-24): &_add_to_env(\%disk_env,$coauthorenv);
17389:-24): }
17390:-24): }
1.463 albertel 17391: if (ref($args->{'extra_env'})) {
17392: &_add_to_env(\%disk_env,$args->{'extra_env'});
17393: }
1.462 albertel 17394: untie(%disk_env);
17395: } else {
1.705 tempelho 17396: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17397: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17398: return 'error: '.$!;
17399: }
17400: }
17401: $env{'request.role'}='cm';
17402: $env{'request.role.adv'}=$env{'user.adv'};
17403: $env{'browser.type'}=$clientbrowser;
17404:
17405: return $cookie;
17406:
17407: }
17408:
17409: sub _add_to_env {
17410: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17411: if (ref($env_data) eq 'HASH') {
17412: while (my ($key,$value) = each(%$env_data)) {
17413: $idf->{$prefix.$key} = $value;
17414: $env{$prefix.$key} = $value;
17415: }
1.462 albertel 17416: }
17417: }
17418:
1.685 tempelho 17419: # --- Get the symbolic name of a problem and the url
17420: sub get_symb {
17421: my ($request,$silent) = @_;
1.726 raeburn 17422: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17423: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17424: if ($symb eq '') {
17425: if (!$silent) {
1.1071 raeburn 17426: if (ref($request)) {
17427: $request->print("Unable to handle ambiguous references:$url:.");
17428: }
1.685 tempelho 17429: return ();
17430: }
17431: }
17432: &Apache::lonenc::check_decrypt(\$symb);
17433: return ($symb);
17434: }
17435:
17436: # --------------------------------------------------------------Get annotation
17437:
17438: sub get_annotation {
17439: my ($symb,$enc) = @_;
17440:
17441: my $key = $symb;
17442: if (!$enc) {
17443: $key =
17444: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17445: }
17446: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17447: return $annotation{$key};
17448: }
17449:
17450: sub clean_symb {
1.731 raeburn 17451: my ($symb,$delete_enc) = @_;
1.685 tempelho 17452:
17453: &Apache::lonenc::check_decrypt(\$symb);
17454: my $enc = $env{'request.enc'};
1.731 raeburn 17455: if ($delete_enc) {
1.730 raeburn 17456: delete($env{'request.enc'});
17457: }
1.685 tempelho 17458:
17459: return ($symb,$enc);
17460: }
1.462 albertel 17461:
1.1075.2.69 raeburn 17462: ############################################################
17463: ############################################################
17464:
17465: =pod
17466:
17467: =head1 Routines for building display used to search for courses
17468:
17469:
17470: =over 4
17471:
17472: =item * &build_filters()
17473:
17474: Create markup for a table used to set filters to use when selecting
17475: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17476: and quotacheck.pl
17477:
17478:
17479: Inputs:
17480:
17481: filterlist - anonymous array of fields to include as potential filters
17482:
17483: crstype - course type
17484:
17485: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17486: to pop-open a course selector (will contain "extra element").
17487:
17488: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17489:
17490: filter - anonymous hash of criteria and their values
17491:
17492: action - form action
17493:
17494: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17495:
17496: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
17497:
17498: cloneruname - username of owner of new course who wants to clone
17499:
17500: clonerudom - domain of owner of new course who wants to clone
17501:
17502: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17503:
17504: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17505:
17506: codedom - domain
17507:
17508: formname - value of form element named "form".
17509:
17510: fixeddom - domain, if fixed.
17511:
17512: prevphase - value to assign to form element named "phase" when going back to the previous screen
17513:
17514: cnameelement - name of form element in form on opener page which will receive title of selected course
17515:
17516: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17517:
17518: cdomelement - name of form element in form on opener page which will receive domain of selected course
17519:
17520: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17521:
17522: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17523:
17524: clonewarning - warning message about missing information for intended course owner when DC creates a course
17525:
17526:
17527: Returns: $output - HTML for display of search criteria, and hidden form elements.
17528:
17529:
17530: Side Effects: None
17531:
17532: =cut
17533:
17534: # ---------------------------------------------- search for courses based on last activity etc.
17535:
17536: sub build_filters {
17537: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17538: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17539: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17540: $cnameelement,$cnumelement,$cdomelement,$setroles,
17541: $clonetext,$clonewarning) = @_;
17542: my ($list,$jscript);
17543: my $onchange = 'javascript:updateFilters(this)';
17544: my ($domainselectform,$sincefilterform,$createdfilterform,
17545: $ownerdomselectform,$persondomselectform,$instcodeform,
17546: $typeselectform,$instcodetitle);
17547: if ($formname eq '') {
17548: $formname = $caller;
17549: }
17550: foreach my $item (@{$filterlist}) {
17551: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17552: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17553: if ($item eq 'domainfilter') {
17554: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17555: } elsif ($item eq 'coursefilter') {
17556: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17557: } elsif ($item eq 'ownerfilter') {
17558: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17559: } elsif ($item eq 'ownerdomfilter') {
17560: $filter->{'ownerdomfilter'} =
17561: &LONCAPA::clean_domain($filter->{$item});
17562: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17563: 'ownerdomfilter',1);
17564: } elsif ($item eq 'personfilter') {
17565: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17566: } elsif ($item eq 'persondomfilter') {
17567: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17568: 'persondomfilter',1);
17569: } else {
17570: $filter->{$item} =~ s/\W//g;
17571: }
17572: if (!$filter->{$item}) {
17573: $filter->{$item} = '';
17574: }
17575: }
17576: if ($item eq 'domainfilter') {
17577: my $allow_blank = 1;
17578: if ($formname eq 'portform') {
17579: $allow_blank=0;
17580: } elsif ($formname eq 'studentform') {
17581: $allow_blank=0;
17582: }
17583: if ($fixeddom) {
17584: $domainselectform = '<input type="hidden" name="domainfilter"'.
17585: ' value="'.$codedom.'" />'.
17586: &Apache::lonnet::domain($codedom,'description');
17587: } else {
17588: $domainselectform = &select_dom_form($filter->{$item},
17589: 'domainfilter',
17590: $allow_blank,'',$onchange);
17591: }
17592: } else {
17593: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17594: }
17595: }
17596:
17597: # last course activity filter and selection
17598: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17599:
17600: # course created filter and selection
17601: if (exists($filter->{'createdfilter'})) {
17602: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17603: }
17604:
17605: my %lt = &Apache::lonlocal::texthash(
17606: 'cac' => "$crstype Activity",
17607: 'ccr' => "$crstype Created",
17608: 'cde' => "$crstype Title",
17609: 'cdo' => "$crstype Domain",
17610: 'ins' => 'Institutional Code',
17611: 'inc' => 'Institutional Categorization',
17612: 'cow' => "$crstype Owner/Co-owner",
17613: 'cop' => "$crstype Personnel Includes",
17614: 'cog' => 'Type',
17615: );
17616:
17617: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17618: my $typeval = 'Course';
17619: if ($crstype eq 'Community') {
17620: $typeval = 'Community';
17621: }
17622: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17623: } else {
17624: $typeselectform = '<select name="type" size="1"';
17625: if ($onchange) {
17626: $typeselectform .= ' onchange="'.$onchange.'"';
17627: }
17628: $typeselectform .= '>'."\n";
17629: foreach my $posstype ('Course','Community') {
17630: $typeselectform.='<option value="'.$posstype.'"'.
17631: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
17632: }
17633: $typeselectform.="</select>";
17634: }
17635:
17636: my ($cloneableonlyform,$cloneabletitle);
17637: if (exists($filter->{'cloneableonly'})) {
17638: my $cloneableon = '';
17639: my $cloneableoff = ' checked="checked"';
17640: if ($filter->{'cloneableonly'}) {
17641: $cloneableon = $cloneableoff;
17642: $cloneableoff = '';
17643: }
17644: $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>';
17645: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 17646: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 17647: } else {
17648: $cloneabletitle = &mt('Cloneable by you');
17649: }
17650: }
17651: my $officialjs;
17652: if ($crstype eq 'Course') {
17653: if (exists($filter->{'instcodefilter'})) {
17654: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17655: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17656: if ($codedom) {
17657: $officialjs = 1;
17658: ($instcodeform,$jscript,$$numtitlesref) =
17659: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17660: $officialjs,$codetitlesref);
17661: if ($jscript) {
17662: $jscript = '<script type="text/javascript">'."\n".
17663: '// <![CDATA['."\n".
17664: $jscript."\n".
17665: '// ]]>'."\n".
17666: '</script>'."\n";
17667: }
17668: }
17669: if ($instcodeform eq '') {
17670: $instcodeform =
17671: '<input type="text" name="instcodefilter" size="10" value="'.
17672: $list->{'instcodefilter'}.'" />';
17673: $instcodetitle = $lt{'ins'};
17674: } else {
17675: $instcodetitle = $lt{'inc'};
17676: }
17677: if ($fixeddom) {
17678: $instcodetitle .= '<br />('.$codedom.')';
17679: }
17680: }
17681: }
17682: my $output = qq|
17683: <form method="post" name="filterpicker" action="$action">
17684: <input type="hidden" name="form" value="$formname" />
17685: |;
17686: if ($formname eq 'modifycourse') {
17687: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17688: '<input type="hidden" name="prevphase" value="'.
17689: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 17690: } elsif ($formname eq 'quotacheck') {
17691: $output .= qq|
17692: <input type="hidden" name="sortby" value="" />
17693: <input type="hidden" name="sortorder" value="" />
17694: |;
17695: } else {
1.1075.2.69 raeburn 17696: my $name_input;
17697: if ($cnameelement ne '') {
17698: $name_input = '<input type="hidden" name="cnameelement" value="'.
17699: $cnameelement.'" />';
17700: }
17701: $output .= qq|
17702: <input type="hidden" name="cnumelement" value="$cnumelement" />
17703: <input type="hidden" name="cdomelement" value="$cdomelement" />
17704: $name_input
17705: $roleelement
17706: $multelement
17707: $typeelement
17708: |;
17709: if ($formname eq 'portform') {
17710: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17711: }
17712: }
17713: if ($fixeddom) {
17714: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17715: }
17716: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17717: if ($sincefilterform) {
17718: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17719: .$sincefilterform
17720: .&Apache::lonhtmlcommon::row_closure();
17721: }
17722: if ($createdfilterform) {
17723: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17724: .$createdfilterform
17725: .&Apache::lonhtmlcommon::row_closure();
17726: }
17727: if ($domainselectform) {
17728: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17729: .$domainselectform
17730: .&Apache::lonhtmlcommon::row_closure();
17731: }
17732: if ($typeselectform) {
17733: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17734: $output .= $typeselectform;
17735: } else {
17736: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17737: .$typeselectform
17738: .&Apache::lonhtmlcommon::row_closure();
17739: }
17740: }
17741: if ($instcodeform) {
17742: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17743: .$instcodeform
17744: .&Apache::lonhtmlcommon::row_closure();
17745: }
17746: if (exists($filter->{'ownerfilter'})) {
17747: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17748: '<table><tr><td>'.&mt('Username').'<br />'.
17749: '<input type="text" name="ownerfilter" size="20" value="'.
17750: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17751: $ownerdomselectform.'</td></tr></table>'.
17752: &Apache::lonhtmlcommon::row_closure();
17753: }
17754: if (exists($filter->{'personfilter'})) {
17755: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17756: '<table><tr><td>'.&mt('Username').'<br />'.
17757: '<input type="text" name="personfilter" size="20" value="'.
17758: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17759: $persondomselectform.'</td></tr></table>'.
17760: &Apache::lonhtmlcommon::row_closure();
17761: }
17762: if (exists($filter->{'coursefilter'})) {
17763: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17764: .'<input type="text" name="coursefilter" size="25" value="'
17765: .$list->{'coursefilter'}.'" />'
17766: .&Apache::lonhtmlcommon::row_closure();
17767: }
17768: if ($cloneableonlyform) {
17769: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17770: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17771: }
17772: if (exists($filter->{'descriptfilter'})) {
17773: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17774: .'<input type="text" name="descriptfilter" size="40" value="'
17775: .$list->{'descriptfilter'}.'" />'
17776: .&Apache::lonhtmlcommon::row_closure(1);
17777: }
17778: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17779: '<input type="hidden" name="updater" value="" />'."\n".
17780: '<input type="submit" name="gosearch" value="'.
17781: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17782: return $jscript.$clonewarning.$output;
17783: }
17784:
17785: =pod
17786:
17787: =item * &timebased_select_form()
17788:
17789: Create markup for a dropdown list used to select a time-based
17790: filter e.g., Course Activity, Course Created, when searching for courses
17791: or communities
17792:
17793: Inputs:
17794:
17795: item - name of form element (sincefilter or createdfilter)
17796:
17797: filter - anonymous hash of criteria and their values
17798:
17799: Returns: HTML for a select box contained a blank, then six time selections,
17800: with value set in incoming form variables currently selected.
17801:
17802: Side Effects: None
17803:
17804: =cut
17805:
17806: sub timebased_select_form {
17807: my ($item,$filter) = @_;
17808: if (ref($filter) eq 'HASH') {
17809: $filter->{$item} =~ s/[^\d-]//g;
17810: if (!$filter->{$item}) { $filter->{$item}=-1; }
17811: return &select_form(
17812: $filter->{$item},
17813: $item,
17814: { '-1' => '',
17815: '86400' => &mt('today'),
17816: '604800' => &mt('last week'),
17817: '2592000' => &mt('last month'),
17818: '7776000' => &mt('last three months'),
17819: '15552000' => &mt('last six months'),
17820: '31104000' => &mt('last year'),
17821: 'select_form_order' =>
17822: ['-1','86400','604800','2592000','7776000',
17823: '15552000','31104000']});
17824: }
17825: }
17826:
17827: =pod
17828:
17829: =item * &js_changer()
17830:
17831: Create script tag containing Javascript used to submit course search form
17832: when course type or domain is changed, and also to hide 'Searching ...' on
17833: page load completion for page showing search result.
17834:
17835: Inputs: None
17836:
17837: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17838:
17839: Side Effects: None
17840:
17841: =cut
17842:
17843: sub js_changer {
17844: return <<ENDJS;
17845: <script type="text/javascript">
17846: // <![CDATA[
17847: function updateFilters(caller) {
17848: if (typeof(caller) != "undefined") {
17849: document.filterpicker.updater.value = caller.name;
17850: }
17851: document.filterpicker.submit();
17852: }
17853:
17854: function hideSearching() {
17855: if (document.getElementById('searching')) {
17856: document.getElementById('searching').style.display = 'none';
17857: }
17858: return;
17859: }
17860:
17861: // ]]>
17862: </script>
17863:
17864: ENDJS
17865: }
17866:
17867: =pod
17868:
17869: =item * &search_courses()
17870:
17871: Process selected filters form course search form and pass to lonnet::courseiddump
17872: to retrieve a hash for which keys are courseIDs which match the selected filters.
17873:
17874: Inputs:
17875:
17876: dom - domain being searched
17877:
17878: type - course type ('Course' or 'Community' or '.' if any).
17879:
17880: filter - anonymous hash of criteria and their values
17881:
17882: numtitles - for institutional codes - number of categories
17883:
17884: cloneruname - optional username of new course owner
17885:
17886: clonerudom - optional domain of new course owner
17887:
1.1075.2.95 raeburn 17888: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17889: (used when DC is using course creation form)
17890:
17891: codetitles - reference to array of titles of components in institutional codes (official courses).
17892:
1.1075.2.95 raeburn 17893: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17894: (and so can clone automatically)
17895:
17896: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17897:
17898: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17899: courses to clone
1.1075.2.69 raeburn 17900:
17901: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17902:
17903:
17904: Side Effects: None
17905:
17906: =cut
17907:
17908:
17909: sub search_courses {
1.1075.2.95 raeburn 17910: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17911: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17912: my (%courses,%showcourses,$cloner);
17913: if (($filter->{'ownerfilter'} ne '') ||
17914: ($filter->{'ownerdomfilter'} ne '')) {
17915: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17916: $filter->{'ownerdomfilter'};
17917: }
17918: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17919: if (!$filter->{$item}) {
17920: $filter->{$item}='.';
17921: }
17922: }
17923: my $now = time;
17924: my $timefilter =
17925: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17926: my ($createdbefore,$createdafter);
17927: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17928: $createdbefore = $now;
17929: $createdafter = $now-$filter->{'createdfilter'};
17930: }
17931: my ($instcodefilter,$regexpok);
17932: if ($numtitles) {
17933: if ($env{'form.official'} eq 'on') {
17934: $instcodefilter =
17935: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17936: $regexpok = 1;
17937: } elsif ($env{'form.official'} eq 'off') {
17938: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17939: unless ($instcodefilter eq '') {
17940: $regexpok = -1;
17941: }
17942: }
17943: } else {
17944: $instcodefilter = $filter->{'instcodefilter'};
17945: }
17946: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17947: if ($type eq '') { $type = '.'; }
17948:
17949: if (($clonerudom ne '') && ($cloneruname ne '')) {
17950: $cloner = $cloneruname.':'.$clonerudom;
17951: }
17952: %courses = &Apache::lonnet::courseiddump($dom,
17953: $filter->{'descriptfilter'},
17954: $timefilter,
17955: $instcodefilter,
17956: $filter->{'combownerfilter'},
17957: $filter->{'coursefilter'},
17958: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17959: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17960: $filter->{'cloneableonly'},
17961: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17962: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17963: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17964: my $ccrole;
17965: if ($type eq 'Community') {
17966: $ccrole = 'co';
17967: } else {
17968: $ccrole = 'cc';
17969: }
17970: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17971: $filter->{'persondomfilter'},
17972: 'userroles',undef,
17973: [$ccrole,'in','ad','ep','ta','cr'],
17974: $dom);
17975: foreach my $role (keys(%rolehash)) {
17976: my ($cnum,$cdom,$courserole) = split(':',$role);
17977: my $cid = $cdom.'_'.$cnum;
17978: if (exists($courses{$cid})) {
17979: if (ref($courses{$cid}) eq 'HASH') {
17980: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17981: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17982: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17983: }
17984: } else {
17985: $courses{$cid}{roles} = [$courserole];
17986: }
17987: $showcourses{$cid} = $courses{$cid};
17988: }
17989: }
17990: }
17991: %courses = %showcourses;
17992: }
17993: return %courses;
17994: }
17995:
17996: =pod
17997:
17998: =back
17999:
1.1075.2.88 raeburn 18000: =head1 Routines for version requirements for current course.
18001:
18002: =over 4
18003:
18004: =item * &check_release_required()
18005:
18006: Compares required LON-CAPA version with version on server, and
18007: if required version is newer looks for a server with the required version.
18008:
18009: Looks first at servers in user's owen domain; if none suitable, looks at
18010: servers in course's domain are permitted to host sessions for user's domain.
18011:
18012: Inputs:
18013:
18014: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18015:
18016: $courseid - Course ID of current course
18017:
18018: $rolecode - User's current role in course (for switchserver query string).
18019:
18020: $required - LON-CAPA version needed by course (format: Major.Minor).
18021:
18022:
18023: Returns:
18024:
18025: $switchserver - query string tp append to /adm/switchserver call (if
18026: current server's LON-CAPA version is too old.
18027:
18028: $warning - Message is displayed if no suitable server could be found.
18029:
18030: =cut
18031:
18032: sub check_release_required {
18033: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18034: my ($switchserver,$warning);
18035: if ($required ne '') {
18036: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18037: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18038: if ($reqdmajor ne '' && $reqdminor ne '') {
18039: my $otherserver;
18040: if (($major eq '' && $minor eq '') ||
18041: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18042: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18043: my $switchlcrev =
18044: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18045: $userdomserver);
18046: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18047: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18048: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18049: my $cdom = $env{'course.'.$courseid.'.domain'};
18050: if ($cdom ne $env{'user.domain'}) {
18051: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18052: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18053: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18054: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18055: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18056: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18057: my $canhost =
18058: &Apache::lonnet::can_host_session($env{'user.domain'},
18059: $coursedomserver,
18060: $remoterev,
18061: $udomdefaults{'remotesessions'},
18062: $defdomdefaults{'hostedsessions'});
18063:
18064: if ($canhost) {
18065: $otherserver = $coursedomserver;
18066: } else {
18067: $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.");
18068: }
18069: } else {
18070: $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).");
18071: }
18072: } else {
18073: $otherserver = $userdomserver;
18074: }
18075: }
18076: if ($otherserver ne '') {
18077: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18078: }
18079: }
18080: }
18081: return ($switchserver,$warning);
18082: }
18083:
18084: =pod
18085:
18086: =item * &check_release_result()
18087:
18088: Inputs:
18089:
18090: $switchwarning - Warning message if no suitable server found to host session.
18091:
18092: $switchserver - query string to append to /adm/switchserver containing lonHostID
18093: and current role.
18094:
18095: Returns: HTML to display with information about requirement to switch server.
18096: Either displaying warning with link to Roles/Courses screen or
18097: display link to switchserver.
18098:
1.1075.2.69 raeburn 18099: =cut
18100:
1.1075.2.88 raeburn 18101: sub check_release_result {
18102: my ($switchwarning,$switchserver) = @_;
18103: my $output = &start_page('Selected course unavailable on this server').
18104: '<p class="LC_warning">';
18105: if ($switchwarning) {
18106: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18107: if (&show_course()) {
18108: $output .= &mt('Display courses');
18109: } else {
18110: $output .= &mt('Display roles');
18111: }
18112: $output .= '</a>';
18113: } elsif ($switchserver) {
18114: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18115: '<br />'.
18116: '<a href="/adm/switchserver?'.$switchserver.'">'.
18117: &mt('Switch Server').
18118: '</a>';
18119: }
18120: $output .= '</p>'.&end_page();
18121: return $output;
18122: }
18123:
18124: =pod
18125:
18126: =item * &needs_coursereinit()
18127:
18128: Determine if course contents stored for user's session needs to be
18129: refreshed, because content has changed since "Big Hash" last tied.
18130:
18131: Check for change is made if time last checked is more than 10 minutes ago
18132: (by default).
18133:
18134: Inputs:
18135:
18136: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18137:
18138: $interval (optional) - Time which may elapse (in s) between last check for content
18139: change in current course. (default: 600 s).
18140:
18141: Returns: an array; first element is:
18142:
18143: =over 4
18144:
18145: 'switch' - if content updates mean user's session
18146: needs to be switched to a server running a newer LON-CAPA version
18147:
18148: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18149: on current server hosting user's session
18150:
18151: '' - if no action required.
18152:
18153: =back
18154:
18155: If first item element is 'switch':
18156:
18157: second item is $switchwarning - Warning message if no suitable server found to host session.
18158:
18159: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18160: and current role.
18161:
18162: otherwise: no other elements returned.
18163:
18164: =back
18165:
18166: =cut
18167:
18168: sub needs_coursereinit {
18169: my ($loncaparev,$interval) = @_;
18170: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18171: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18172: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18173: my $now = time;
18174: if ($interval eq '') {
18175: $interval = 600;
18176: }
18177: if (($now-$env{'request.course.timechecked'})>$interval) {
18178: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 18179:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 18180:21): if ($blocked) {
18181:21): return ();
18182:21): }
.13(raeb 18183:-23): my $update;
18184:-23): my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18185:-23): my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18186:-23): if ($lastmainchange > $env{'request.course.tied'}) {
18187:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18188:-23): if ($needswitch) {
18189:-23): return ('switch',$switchwarning,$switchserver);
18190:-23): }
18191:-23): $update = 'main';
18192:-23): }
18193:-23): if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18194:-23): if ($update) {
18195:-23): $update = 'both';
18196:-23): } else {
18197:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18198:-23): if ($needswitch) {
18199:-23): return ('switch',$switchwarning,$switchserver);
18200:-23): } else {
18201:-23): $update = 'supp';
1.1075.2.88 raeburn 18202: }
18203: }
1.1075.2.161. .13(raeb 18204:-23): return ($update);
18205:-23): }
18206:-23): }
18207:-23): return ();
18208:-23): }
18209:-23):
18210:-23): sub switch_for_update {
18211:-23): my ($loncaparev,$cdom,$cnum) = @_;
18212:-23): my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18213:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18214:-23): my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18215:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18216:-23): &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18217:-23): $curr_reqd_hash{'internal.releaserequired'}});
18218:-23): my ($switchserver,$switchwarning) =
18219:-23): &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18220:-23): $curr_reqd_hash{'internal.releaserequired'});
18221:-23): if ($switchwarning ne '' || $switchserver ne '') {
18222:-23): return ('switch',$switchwarning,$switchserver);
18223:-23): }
1.1075.2.88 raeburn 18224: }
18225: }
18226: return ();
18227: }
1.1075.2.69 raeburn 18228:
1.1075.2.11 raeburn 18229: sub update_content_constraints {
18230: my ($cdom,$cnum,$chome,$cid) = @_;
18231: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18232: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
18233: my %checkresponsetypes;
18234: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
18235: my ($item,$name,$value) = split(/:/,$key);
18236: if ($item eq 'resourcetag') {
18237: if ($name eq 'responsetype') {
18238: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18239: }
18240: }
18241: }
18242: my $navmap = Apache::lonnavmaps::navmap->new();
18243: if (defined($navmap)) {
18244: my %allresponses;
18245: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
18246: my %responses = $res->responseTypes();
18247: foreach my $key (keys(%responses)) {
18248: next unless(exists($checkresponsetypes{$key}));
18249: $allresponses{$key} += $responses{$key};
18250: }
18251: }
18252: foreach my $key (keys(%allresponses)) {
18253: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18254: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18255: ($reqdmajor,$reqdminor) = ($major,$minor);
18256: }
18257: }
18258: undef($navmap);
18259: }
18260: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18261: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18262: }
18263: return;
18264: }
18265:
1.1075.2.27 raeburn 18266: sub allmaps_incourse {
18267: my ($cdom,$cnum,$chome,$cid) = @_;
18268: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18269: $cid = $env{'request.course.id'};
18270: $cdom = $env{'course.'.$cid.'.domain'};
18271: $cnum = $env{'course.'.$cid.'.num'};
18272: $chome = $env{'course.'.$cid.'.home'};
18273: }
18274: my %allmaps = ();
18275: my $lastchange =
18276: &Apache::lonnet::get_coursechange($cdom,$cnum);
18277: if ($lastchange > $env{'request.course.tied'}) {
18278: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18279: unless ($ferr) {
18280: &update_content_constraints($cdom,$cnum,$chome,$cid);
18281: }
18282: }
18283: my $navmap = Apache::lonnavmaps::navmap->new();
18284: if (defined($navmap)) {
18285: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18286: $allmaps{$res->src()} = 1;
18287: }
18288: }
18289: return \%allmaps;
18290: }
18291:
1.1075.2.11 raeburn 18292: sub parse_supplemental_title {
18293: my ($title) = @_;
18294:
18295: my ($foldertitle,$renametitle);
18296: if ($title =~ /&&&/) {
18297: $title = &HTML::Entites::decode($title);
18298: }
18299: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18300: $renametitle=$4;
18301: my ($time,$uname,$udom) = ($1,$2,$3);
18302: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18303: my $name = &plainname($uname,$udom);
18304: $name = &HTML::Entities::encode($name,'"<>&\'');
18305: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1075.2.161. .16(raeb 18306:-23): $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
18307:-23): if ($foldertitle ne '') {
18308:-23): $title .= ': <br />'.$foldertitle;
18309:-23): }
1.1075.2.11 raeburn 18310: }
18311: if (wantarray) {
18312: return ($title,$foldertitle,$renametitle);
18313: }
18314: return $title;
18315: }
18316:
1.1075.2.161. .13(raeb 18317:-23): sub get_supplemental {
18318:-23): my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18319:-23): my $hashid=$cnum.':'.$cdom;
18320:-23): my ($supplemental,$cached,$set_httprefs);
18321:-23): unless ($ignorecache) {
18322:-23): ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18323:-23): }
18324:-23): unless (defined($cached)) {
18325:-23): my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18326:-23): unless ($chome eq 'no_host') {
18327:-23): my @order = @LONCAPA::map::order;
18328:-23): my @resources = @LONCAPA::map::resources;
18329:-23): my @resparms = @LONCAPA::map::resparms;
18330:-23): my @zombies = @LONCAPA::map::zombies;
18331:-23): my ($errors,%ids,%hidden);
18332:-23): $errors =
18333:-23): &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18334:-23): $errors,$possdel,\%ids,\%hidden);
18335:-23): @LONCAPA::map::order = @order;
18336:-23): @LONCAPA::map::resources = @resources;
18337:-23): @LONCAPA::map::resparms = @resparms;
18338:-23): @LONCAPA::map::zombies = @zombies;
18339:-23): $set_httprefs = 1;
18340:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18341:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18342:-23): }
18343:-23): $supplemental = {
18344:-23): ids => \%ids,
18345:-23): hidden => \%hidden,
18346:-23): };
18347:-23): &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18348:-23): }
18349:-23): }
18350:-23): return ($supplemental,$set_httprefs);
18351:-23): }
18352:-23):
1.1075.2.43 raeburn 18353: sub recurse_supplemental {
1.1075.2.161. .13(raeb 18354:-23): my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18355:-23): if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18356:-23): my $mapnum;
18357:-23): if ($suppmap eq 'supplemental.sequence') {
18358:-23): $mapnum = 0;
18359:-23): } else {
18360:-23): ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18361:-23): }
1.1075.2.43 raeburn 18362: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18363: if ($fatal) {
18364: $errors ++;
18365: } else {
1.1075.2.161. .13(raeb 18366:-23): my @order = @LONCAPA::map::order;
18367:-23): if (@order > 0) {
18368:-23): my @resources = @LONCAPA::map::resources;
18369:-23): my @resparms = @LONCAPA::map::resparms;
18370:-23): foreach my $idx (@order) {
18371:-23): my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 18372: if (($src ne '') && ($status eq 'res')) {
1.1075.2.161. .13(raeb 18373:-23): my $id = $mapnum.':'.$idx;
18374:-23): push(@{$suppids->{$src}},$id);
18375:-23): if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18376:-23): $hiddensupp->{$id} = 1;
18377:-23): }
1.1075.2.46 raeburn 18378: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1075.2.161. .13(raeb 18379:-23): $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18380:-23): $hiddensupp,$hiddensupp->{$id});
1.1075.2.43 raeburn 18381: } else {
1.1075.2.161. .13(raeb 18382:-23): my $allowed;
18383:-23): if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18384:-23): $allowed = 1;
18385:-23): } elsif ($possdel) {
18386:-23): foreach my $item (@{$suppids->{$src}}) {
18387:-23): next if ($item eq $id);
18388:-23): unless ($hiddensupp->{$item}) {
18389:-23): $allowed = 1;
18390:-23): last;
18391:-23): }
18392:-23): }
18393:-23): if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18394:-23): &Apache::lonnet::delenv('httpref.'.$src);
18395:-23): }
18396:-23): }
18397:-23): if ($allowed && (!exists($env{'httpref.'.$src}))) {
18398:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18399:-23): }
18400:-23): }
18401:-23): }
18402:-23): }
18403:-23): }
18404:-23): }
18405:-23): }
18406:-23): return $errors;
18407:-23): }
18408:-23):
18409:-23): sub set_supp_httprefs {
18410:-23): my ($cnum,$cdom,$supplemental,$possdel) = @_;
18411:-23): if (ref($supplemental) eq 'HASH') {
18412:-23): if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18413:-23): foreach my $src (keys(%{$supplemental->{'ids'}})) {
18414:-23): next if ($src =~ /\.sequence$/);
18415:-23): if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18416:-23): my $allowed;
18417:-23): if ($env{'request.role.adv'}) {
18418:-23): $allowed = 1;
18419:-23): } else {
18420:-23): foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18421:-23): unless ($supplemental->{'hidden'}->{$id}) {
18422:-23): $allowed = 1;
18423:-23): last;
18424:-23): }
18425:-23): }
18426:-23): }
18427:-23): if (exists($env{'httpref.'.$src})) {
18428:-23): if ($possdel) {
18429:-23): unless ($allowed) {
18430:-23): &Apache::lonnet::delenv('httpref.'.$src);
18431:-23): }
1.1075.2.43 raeburn 18432: }
1.1075.2.161. .13(raeb 18433:-23): } elsif ($allowed) {
18434:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1075.2.43 raeburn 18435: }
18436: }
18437: }
1.1075.2.161. .13(raeb 18438:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18439:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18440:-23): }
1.1075.2.43 raeburn 18441: }
18442: }
1.1075.2.161. .13(raeb 18443:-23): }
18444:-23):
18445:-23): sub get_supp_parameter {
18446:-23): my ($resparm,$name)=@_;
18447:-23): return if ($resparm eq '');
18448:-23): my $value=undef;
18449:-23): my $ptype=undef;
18450:-23): foreach (split('&&&',$resparm)) {
18451:-23): my ($thistype,$thisname,$thisvalue)=split('___',$_);
18452:-23): if ($thisname eq $name) {
18453:-23): $value=$thisvalue;
18454:-23): $ptype=$thistype;
18455:-23): }
18456:-23): }
18457:-23): return $value;
1.1075.2.43 raeburn 18458: }
18459:
1.1075.2.18 raeburn 18460: sub symb_to_docspath {
1.1075.2.119 raeburn 18461: my ($symb,$navmapref) = @_;
18462: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 18463: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18464: if ($resurl=~/\.(sequence|page)$/) {
18465: $mapurl=$resurl;
18466: } elsif ($resurl eq 'adm/navmaps') {
18467: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18468: }
18469: my $mapresobj;
1.1075.2.119 raeburn 18470: unless (ref($$navmapref)) {
18471: $$navmapref = Apache::lonnavmaps::navmap->new();
18472: }
18473: if (ref($$navmapref)) {
18474: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 18475: }
18476: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18477: my $type=$2;
18478: my $path;
18479: if (ref($mapresobj)) {
18480: my $pcslist = $mapresobj->map_hierarchy();
18481: if ($pcslist ne '') {
18482: foreach my $pc (split(/,/,$pcslist)) {
18483: next if ($pc <= 1);
1.1075.2.119 raeburn 18484: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 18485: if (ref($res)) {
18486: my $thisurl = $res->src();
18487: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18488: my $thistitle = $res->title();
18489: $path .= '&'.
18490: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 18491: &escape($thistitle).
1.1075.2.18 raeburn 18492: ':'.$res->randompick().
18493: ':'.$res->randomout().
18494: ':'.$res->encrypted().
18495: ':'.$res->randomorder().
18496: ':'.$res->is_page();
18497: }
18498: }
18499: }
18500: $path =~ s/^\&//;
18501: my $maptitle = $mapresobj->title();
18502: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18503: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18504: }
18505: $path .= (($path ne '')? '&' : '').
18506: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18507: &escape($maptitle).
1.1075.2.18 raeburn 18508: ':'.$mapresobj->randompick().
18509: ':'.$mapresobj->randomout().
18510: ':'.$mapresobj->encrypted().
18511: ':'.$mapresobj->randomorder().
18512: ':'.$mapresobj->is_page();
18513: } else {
18514: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18515: my $ispage = (($type eq 'page')? 1 : '');
18516: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18517: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18518: }
18519: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18520: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 18521: }
18522: unless ($mapurl eq 'default') {
18523: $path = 'default&'.
1.1075.2.46 raeburn 18524: &escape('Main Content').
1.1075.2.18 raeburn 18525: ':::::&'.$path;
18526: }
18527: return $path;
18528: }
18529:
1.1075.2.161. .13(raeb 18530:-23): sub validate_folderpath {
18531:-23): my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18532:-23): if ($env{'form.folderpath'} ne '') {
18533:-23): my @items = split(/\&/,$env{'form.folderpath'});
18534:-23): my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
18535:-23): for (my $i=0; $i<@items; $i++) {
18536:-23): my $odd = $i%2;
18537:-23): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18538:-23): $badpath = 1;
18539:-23): } elsif ($odd && $supplementalflag) {
18540:-23): my $idx = $i-1;
18541:-23): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18542:-23): my $esc_name = $1;
18543:-23): if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18544:-23): $supppath .= '&'.$esc_name;
18545:-23): $changed = 1;
18546:-23): } else {
18547:-23): $supppath .= '&'.$items[$i];
18548:-23): }
18549:-23): } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18550:-23): $changed = 1;
18551:-23): my $is_hidden;
18552:-23): unless ($got_supp) {
18553:-23): my ($supplemental) = &get_supplemental($coursenum,$coursedom);
18554:-23): if (ref($supplemental) eq 'HASH') {
18555:-23): if (ref($supplemental->{'hidden'}) eq 'HASH') {
18556:-23): %supphidden = %{$supplemental->{'hidden'}};
18557:-23): }
18558:-23): if (ref($supplemental->{'ids'}) eq 'HASH') {
18559:-23): %suppids = %{$supplemental->{'ids'}};
18560:-23): }
18561:-23): }
18562:-23): $got_supp = 1;
18563:-23): }
18564:-23): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18565:-23): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18566:-23): if ($supphidden{$mapid}) {
18567:-23): $is_hidden = 1;
18568:-23): }
18569:-23): }
18570:-23): $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18571:-23): } else {
18572:-23): $supppath .= '&'.$items[$i];
18573:-23): }
18574:-23): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18575:-23): $badpath = 1;
18576:-23): } elsif ($supplementalflag) {
18577:-23): $supppath .= '&'.$items[$i];
18578:-23): }
18579:-23): last if ($badpath);
18580:-23): }
18581:-23): if ($badpath) {
18582:-23): delete($env{'form.folderpath'});
18583:-23): } elsif ($changed && $supplementalflag) {
18584:-23): $supppath =~ s/^\&//;
18585:-23): $env{'form.folderpath'} = $supppath;
18586:-23): }
18587:-23): }
18588:-23): return;
18589:-23): }
18590:-23):
1.1075.2.14 raeburn 18591: sub captcha_display {
1.1075.2.137 raeburn 18592: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18593: my ($output,$error);
1.1075.2.107 raeburn 18594: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 18595: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18596: if ($captcha eq 'original') {
18597: $output = &create_captcha();
18598: unless ($output) {
18599: $error = 'captcha';
18600: }
18601: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18602: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 18603: unless ($output) {
18604: $error = 'recaptcha';
18605: }
18606: }
1.1075.2.107 raeburn 18607: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 18608: }
18609:
18610: sub captcha_response {
1.1075.2.137 raeburn 18611: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18612: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 18613: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18614: if ($captcha eq 'original') {
18615: ($captcha_chk,$captcha_error) = &check_captcha();
18616: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18617: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 18618: } else {
18619: $captcha_chk = 1;
18620: }
18621: return ($captcha_chk,$captcha_error);
18622: }
18623:
18624: sub get_captcha_config {
1.1075.2.137 raeburn 18625: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 18626: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 18627: my $hostname = &Apache::lonnet::hostname($lonhost);
18628: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18629: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18630: if ($context eq 'usercreation') {
18631: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18632: if (ref($domconfig{$context}) eq 'HASH') {
18633: $hashtocheck = $domconfig{$context}{'cancreate'};
18634: if (ref($hashtocheck) eq 'HASH') {
18635: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18636: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18637: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18638: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18639: }
18640: if ($privkey && $pubkey) {
18641: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18642: $version = $hashtocheck->{'recaptchaversion'};
18643: if ($version ne '2') {
18644: $version = 1;
18645: }
1.1075.2.14 raeburn 18646: } else {
18647: $captcha = 'original';
18648: }
18649: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18650: $captcha = 'original';
18651: }
18652: }
18653: } else {
18654: $captcha = 'captcha';
18655: }
18656: } elsif ($context eq 'login') {
18657: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18658: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18659: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18660: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
18661: if ($privkey && $pubkey) {
18662: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18663: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18664: if ($version ne '2') {
18665: $version = 1;
18666: }
1.1075.2.14 raeburn 18667: } else {
18668: $captcha = 'original';
18669: }
18670: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18671: $captcha = 'original';
18672: }
1.1075.2.137 raeburn 18673: } elsif ($context eq 'passwords') {
18674: if ($dom_in_effect) {
18675: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18676: if ($passwdconf{'captcha'} eq 'recaptcha') {
18677: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18678: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18679: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18680: }
18681: if ($privkey && $pubkey) {
18682: $captcha = 'recaptcha';
18683: $version = $passwdconf{'recaptchaversion'};
18684: if ($version ne '2') {
18685: $version = 1;
18686: }
18687: } else {
18688: $captcha = 'original';
18689: }
18690: } elsif ($passwdconf{'captcha'} ne 'notused') {
18691: $captcha = 'original';
18692: }
18693: }
1.1075.2.14 raeburn 18694: }
1.1075.2.107 raeburn 18695: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 18696: }
18697:
18698: sub create_captcha {
18699: my %captcha_params = &captcha_settings();
18700: my ($output,$maxtries,$tries) = ('',10,0);
18701: while ($tries < $maxtries) {
18702: $tries ++;
18703: my $captcha = Authen::Captcha->new (
18704: output_folder => $captcha_params{'output_dir'},
18705: data_folder => $captcha_params{'db_dir'},
18706: );
18707: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18708:
18709: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18710: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 18711: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 18712: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.161. .15(raeb 18713:-23): '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 18714: '</span><br />'.
1.1075.2.66 raeburn 18715: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 18716: last;
18717: }
18718: }
1.1075.2.158 raeburn 18719: if ($output eq '') {
18720: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18721: }
1.1075.2.14 raeburn 18722: return $output;
18723: }
18724:
18725: sub captcha_settings {
18726: my %captcha_params = (
18727: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18728: www_output_dir => "/captchaspool",
18729: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18730: numchars => '5',
18731: );
18732: return %captcha_params;
18733: }
18734:
18735: sub check_captcha {
18736: my ($captcha_chk,$captcha_error);
18737: my $code = $env{'form.code'};
18738: my $md5sum = $env{'form.crypt'};
18739: my %captcha_params = &captcha_settings();
18740: my $captcha = Authen::Captcha->new(
18741: output_folder => $captcha_params{'output_dir'},
18742: data_folder => $captcha_params{'db_dir'},
18743: );
1.1075.2.26 raeburn 18744: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 18745: my %captcha_hash = (
18746: 0 => 'Code not checked (file error)',
18747: -1 => 'Failed: code expired',
18748: -2 => 'Failed: invalid code (not in database)',
18749: -3 => 'Failed: invalid code (code does not match crypt)',
18750: );
18751: if ($captcha_chk != 1) {
18752: $captcha_error = $captcha_hash{$captcha_chk}
18753: }
18754: return ($captcha_chk,$captcha_error);
18755: }
18756:
18757: sub create_recaptcha {
1.1075.2.107 raeburn 18758: my ($pubkey,$version) = @_;
18759: if ($version >= 2) {
1.1075.2.158 raeburn 18760: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18761: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 18762: } else {
18763: my $use_ssl;
18764: if ($ENV{'SERVER_PORT'} == 443) {
18765: $use_ssl = 1;
18766: }
18767: my $captcha = Captcha::reCAPTCHA->new;
18768: return $captcha->get_options_setter({theme => 'white'})."\n".
18769: $captcha->get_html($pubkey,undef,$use_ssl).
18770: &mt('If the text is hard to read, [_1] will replace them.',
18771: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18772: '<br /><br />';
18773: }
1.1075.2.14 raeburn 18774: }
18775:
18776: sub check_recaptcha {
1.1075.2.107 raeburn 18777: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 18778: my $captcha_chk;
1.1075.2.150 raeburn 18779: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 18780: if ($version >= 2) {
18781: my $ua = LWP::UserAgent->new;
18782: $ua->timeout(10);
18783: my %info = (
18784: secret => $privkey,
18785: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 18786: remoteip => $ip,
1.1075.2.107 raeburn 18787: );
18788: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
18789: if ($response->is_success) {
18790: my $data = JSON::DWIW->from_json($response->decoded_content);
18791: if (ref($data) eq 'HASH') {
18792: if ($data->{'success'}) {
18793: $captcha_chk = 1;
18794: }
18795: }
18796: }
18797: } else {
18798: my $captcha = Captcha::reCAPTCHA->new;
18799: my $captcha_result =
18800: $captcha->check_answer(
18801: $privkey,
1.1075.2.150 raeburn 18802: $ip,
1.1075.2.107 raeburn 18803: $env{'form.recaptcha_challenge_field'},
18804: $env{'form.recaptcha_response_field'},
18805: );
18806: if ($captcha_result->{is_valid}) {
18807: $captcha_chk = 1;
18808: }
1.1075.2.14 raeburn 18809: }
18810: return $captcha_chk;
18811: }
18812:
1.1075.2.64 raeburn 18813: sub emailusername_info {
1.1075.2.103 raeburn 18814: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 18815: my %titles = &Apache::lonlocal::texthash (
18816: lastname => 'Last Name',
18817: firstname => 'First Name',
18818: institution => 'School/college/university',
18819: location => "School's city, state/province, country",
18820: web => "School's web address",
18821: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 18822: id => 'Student/Employee ID',
1.1075.2.64 raeburn 18823: );
18824: return (\@fields,\%titles);
18825: }
18826:
1.1075.2.56 raeburn 18827: sub cleanup_html {
18828: my ($incoming) = @_;
18829: my $outgoing;
18830: if ($incoming ne '') {
18831: $outgoing = $incoming;
18832: $outgoing =~ s/;/;/g;
18833: $outgoing =~ s/\#/#/g;
18834: $outgoing =~ s/\&/&/g;
18835: $outgoing =~ s/</</g;
18836: $outgoing =~ s/>/>/g;
18837: $outgoing =~ s/\(/(/g;
18838: $outgoing =~ s/\)/)/g;
18839: $outgoing =~ s/"/"/g;
18840: $outgoing =~ s/'/'/g;
18841: $outgoing =~ s/\$/$/g;
18842: $outgoing =~ s{/}{/}g;
18843: $outgoing =~ s/=/=/g;
18844: $outgoing =~ s/\\/\/g
18845: }
18846: return $outgoing;
18847: }
18848:
1.1075.2.74 raeburn 18849: # Checks for critical messages and returns a redirect url if one exists.
18850: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 18851:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 18852: sub critical_redirect {
1.1075.2.161. .1(raebu 18853:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 18854: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18855: return ();
18856: }
1.1075.2.74 raeburn 18857: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 18858:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18859:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18860:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 18861:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 18862:21): if ($blocked) {
18863:21): my $checkrole = "cm./$cdom/$cnum";
18864:21): if ($env{'request.course.sec'} ne '') {
18865:21): $checkrole .= "/$env{'request.course.sec'}";
18866:21): }
18867:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18868:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18869:21): return;
18870:21): }
18871:21): }
18872:21): }
1.1075.2.74 raeburn 18873: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18874: $env{'user.name'});
18875: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
18876: my $redirecturl;
18877: if ($what[0]) {
1.1075.2.158 raeburn 18878: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 18879: $redirecturl='/adm/email?critical=display';
18880: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18881: return (1, $url);
18882: }
18883: }
18884: }
18885: return ();
18886: }
18887:
1.1075.2.64 raeburn 18888: # Use:
18889: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18890: #
18891: ##################################################
18892: # password associated functions #
18893: ##################################################
18894: sub des_keys {
18895: # Make a new key for DES encryption.
18896: # Each key has two parts which are returned separately.
18897: # Please note: Each key must be passed through the &hex function
18898: # before it is output to the web browser. The hex versions cannot
18899: # be used to decrypt.
18900: my @hexstr=('0','1','2','3','4','5','6','7',
18901: '8','9','a','b','c','d','e','f');
18902: my $lkey='';
18903: for (0..7) {
18904: $lkey.=$hexstr[rand(15)];
18905: }
18906: my $ukey='';
18907: for (0..7) {
18908: $ukey.=$hexstr[rand(15)];
18909: }
18910: return ($lkey,$ukey);
18911: }
18912:
18913: sub des_decrypt {
18914: my ($key,$cyphertext) = @_;
18915: my $keybin=pack("H16",$key);
18916: my $cypher;
18917: if ($Crypt::DES::VERSION>=2.03) {
18918: $cypher=new Crypt::DES $keybin;
18919: } else {
18920: $cypher=new DES $keybin;
18921: }
1.1075.2.106 raeburn 18922: my $plaintext='';
18923: my $cypherlength = length($cyphertext);
18924: my $numchunks = int($cypherlength/32);
18925: for (my $j=0; $j<$numchunks; $j++) {
18926: my $start = $j*32;
18927: my $cypherblock = substr($cyphertext,$start,32);
18928: my $chunk =
18929: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18930: $chunk .=
18931: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18932: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18933: $plaintext .= $chunk;
18934: }
1.1075.2.64 raeburn 18935: return $plaintext;
18936: }
18937:
1.1075.2.161. .1(raebu 18938:21): sub get_requested_shorturls {
18939:21): my ($cdom,$cnum,$navmap) = @_;
18940:21): return unless (ref($navmap));
18941:21): my ($numnew,$errors);
18942:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18943:21): if (@toshorten) {
18944:21): my (%maps,%resources,%titles);
18945:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18946:21): 'shorturls',$cdom,$cnum);
18947:21): if (keys(%resources)) {
18948:21): my %tocreate;
18949:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18950:21): my $symb = $resources{$item};
18951:21): if ($symb) {
18952:21): $tocreate{$cnum.'&'.$symb} = 1;
18953:21): }
18954:21): }
18955:21): if (keys(%tocreate)) {
18956:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18957:21): \%tocreate);
18958:21): }
18959:21): }
18960:21): }
18961:21): return ($numnew,$errors);
18962:21): }
18963:21):
18964:21): sub make_short_symbs {
18965:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18966:21): my ($numnew,@errors);
18967:21): if (ref($tocreateref) eq 'HASH') {
18968:21): my %tocreate = %{$tocreateref};
18969:21): if (keys(%tocreate)) {
18970:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18971:21): my $su = Short::URL->new(no_vowels => 1);
18972:21): my $init = '';
18973:21): my (%newunique,%addcourse,%courseonly,%failed);
18974:21): # get lock on tiny db
18975:21): my $now = time;
18976:21): if ($lockuser eq '') {
18977:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18978:21): }
18979:21): my $lockhash = {
18980:21): "lock\0$now" => $lockuser,
18981:21): };
18982:21): my $tries = 0;
18983:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18984:21): my ($code,$error);
18985:21): while (($gotlock ne 'ok') && ($tries<3)) {
18986:21): $tries ++;
18987:21): sleep 1;
18988:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18989:21): }
18990:21): if ($gotlock eq 'ok') {
18991:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18992:21): \%addcourse,\%courseonly,\%failed);
18993:21): if (keys(%failed)) {
18994:21): my $numfailed = scalar(keys(%failed));
18995:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18996:21): }
18997:21): if (keys(%newunique)) {
18998:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18999:21): if ($putres eq 'ok') {
19000:21): $numnew = scalar(keys(%newunique));
19001:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19002:21): unless ($newputres eq 'ok') {
19003:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
19004:21): }
19005:21): } else {
19006:21): push(@errors,&mt('error: could not store unique six character URLs'));
19007:21): }
19008:21): }
19009:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19010:21): unless ($dellockres eq 'ok') {
19011:21): push(@errors,&mt('error: could not release lockfile'));
19012:21): }
19013:21): } else {
19014:21): push(@errors,&mt('error: could not obtain lockfile'));
19015:21): }
19016:21): if (keys(%courseonly)) {
19017:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19018:21): if ($result ne 'ok') {
19019:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
19020:21): }
19021:21): }
19022:21): }
19023:21): }
19024:21): return ($numnew,\@errors);
19025:21): }
19026:21):
19027:21): sub shorten_symbs {
19028:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19029:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19030:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19031:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19032:21): my (%possibles,%collisions);
19033:21): foreach my $key (keys(%{$tocreate})) {
19034:21): my $num = String::CRC32::crc32($key);
19035:21): my $tiny = $su->encode($num,$init);
19036:21): if ($tiny) {
19037:21): $possibles{$tiny} = $key;
19038:21): }
19039:21): }
19040:21): if (!$init) {
19041:21): $init = 1;
19042:21): } else {
19043:21): $init ++;
19044:21): }
19045:21): if (keys(%possibles)) {
19046:21): my @posstiny = keys(%possibles);
19047:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19048:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19049:21): if (keys(%currtiny)) {
19050:21): foreach my $key (keys(%currtiny)) {
19051:21): next if ($currtiny{$key} eq '');
19052:21): if ($currtiny{$key} eq $possibles{$key}) {
19053:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19054:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19055:21): $courseonly->{$tsymb} = $key;
19056:21): }
19057:21): } else {
19058:21): $collisions{$possibles{$key}} = 1;
19059:21): }
19060:21): delete($possibles{$key});
19061:21): }
19062:21): }
19063:21): foreach my $key (keys(%possibles)) {
19064:21): $newunique->{$key} = $possibles{$key};
19065:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19066:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19067:21): $addcourse->{$tsymb} = $key;
19068:21): }
19069:21): }
19070:21): }
19071:21): if (keys(%collisions)) {
19072:21): if ($init <5) {
19073:21): if (!$init) {
19074:21): $init = 1;
19075:21): } else {
19076:21): $init ++;
19077:21): }
19078:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19079:21): $newunique,$addcourse,$courseonly,$failed);
19080:21): } else {
19081:21): foreach my $key (keys(%collisions)) {
19082:21): $failed->{$key} = 1;
19083:21): $failed->{$key} = 1;
19084:21): }
19085:21): }
19086:21): }
19087:21): return $init;
19088:21): }
19089:21):
1.1075.2.135 raeburn 19090: sub is_nonframeable {
19091: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19092: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
19093: return if (($remprotocol eq '') || ($remhost eq ''));
19094:
19095: $remprotocol = lc($remprotocol);
19096: $remhost = lc($remhost);
19097: my $remport = 80;
19098: if ($remprotocol eq 'https') {
19099: $remport = 443;
19100: }
19101: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
19102: if ($cached) {
19103: unless ($nocache) {
19104: if ($result) {
19105: return 1;
19106: } else {
19107: return 0;
19108: }
19109: }
19110: }
19111: my $uselink;
19112: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 19113: my $ua = LWP::UserAgent->new;
19114: $ua->timeout(5);
19115: my $response=$ua->request($request);
1.1075.2.135 raeburn 19116: if ($response->is_success()) {
19117: my $secpolicy = lc($response->header('content-security-policy'));
19118: my $xframeop = lc($response->header('x-frame-options'));
19119: $secpolicy =~ s/^\s+|\s+$//g;
19120: $xframeop =~ s/^\s+|\s+$//g;
19121: if (($secpolicy ne '') || ($xframeop ne '')) {
19122: my $remotehost = $remprotocol.'://'.$remhost;
19123: my ($origin,$protocol,$port);
19124: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19125: $port = $ENV{'SERVER_PORT'};
19126: } else {
19127: $port = 80;
19128: }
19129: if ($absolute eq '') {
19130: $protocol = 'http:';
19131: if ($port == 443) {
19132: $protocol = 'https:';
19133: }
19134: $origin = $protocol.'//'.lc($hostname);
19135: } else {
19136: $origin = lc($absolute);
19137: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19138: }
19139: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19140: my $framepolicy = $1;
19141: $framepolicy =~ s/^\s+|\s+$//g;
19142: my @policies = split(/\s+/,$framepolicy);
19143: if (@policies) {
19144: if (grep(/^\Q'none'\E$/,@policies)) {
19145: $uselink = 1;
19146: } else {
19147: $uselink = 1;
19148: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19149: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19150: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19151: undef($uselink);
19152: }
19153: if ($uselink) {
19154: if (grep(/^\Q'self'\E$/,@policies)) {
19155: if (($origin ne '') && ($remotehost eq $origin)) {
19156: undef($uselink);
19157: }
19158: }
19159: }
19160: if ($uselink) {
19161: my @possok;
19162: if ($ip ne '') {
19163: push(@possok,$ip);
19164: }
19165: my $hoststr = '';
19166: foreach my $part (reverse(split(/\./,$hostname))) {
19167: if ($hoststr eq '') {
19168: $hoststr = $part;
19169: } else {
19170: $hoststr = "$part.$hoststr";
19171: }
19172: if ($hoststr eq $hostname) {
19173: push(@possok,$hostname);
19174: } else {
19175: push(@possok,"*.$hoststr");
19176: }
19177: }
19178: if (@possok) {
19179: foreach my $poss (@possok) {
19180: last if (!$uselink);
19181: foreach my $policy (@policies) {
19182: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19183: undef($uselink);
19184: last;
19185: }
19186: }
19187: }
19188: }
19189: }
19190: }
19191: }
19192: } elsif ($xframeop ne '') {
19193: $uselink = 1;
19194: my @policies = split(/\s*,\s*/,$xframeop);
19195: if (@policies) {
19196: unless (grep(/^deny$/,@policies)) {
19197: if ($origin ne '') {
19198: if (grep(/^sameorigin$/,@policies)) {
19199: if ($remotehost eq $origin) {
19200: undef($uselink);
19201: }
19202: }
19203: if ($uselink) {
19204: foreach my $policy (@policies) {
19205: if ($policy =~ /^allow-from\s*(.+)$/) {
19206: my $allowfrom = $1;
19207: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19208: undef($uselink);
19209: last;
19210: }
19211: }
19212: }
19213: }
19214: }
19215: }
19216: }
19217: }
19218: }
19219: }
19220: if ($nocache) {
19221: if ($cached) {
19222: my $devalidate;
19223: if ($uselink && !$result) {
19224: $devalidate = 1;
19225: } elsif (!$uselink && $result) {
19226: $devalidate = 1;
19227: }
19228: if ($devalidate) {
19229: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19230: }
19231: }
19232: } else {
19233: if ($uselink) {
19234: $result = 1;
19235: } else {
19236: $result = 0;
19237: }
19238: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19239: }
19240: return $uselink;
19241: }
19242:
1.1075.2.161. .1(raebu 19243:21): sub page_menu {
19244:21): my ($menucolls,$menunum) = @_;
19245:21): my %menu;
19246:21): foreach my $item (split(/;/,$menucolls)) {
19247:21): my ($num,$value) = split(/\%/,$item);
19248:21): if ($num eq $menunum) {
19249:21): my @entries = split(/\&/,$value);
19250:21): foreach my $entry (@entries) {
19251:21): my ($name,$fields) = split(/=/,$entry);
19252:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
19253:21): $menu{$name} = $fields;
19254:21): } else {
19255:21): my @shown;
19256:21): if ($fields =~ /,/) {
19257:21): @shown = split(/,/,$fields);
19258:21): } else {
19259:21): @shown = ($fields);
19260:21): }
19261:21): if (@shown) {
19262:21): foreach my $field (@shown) {
19263:21): next if ($field eq '');
19264:21): $menu{$field} = 1;
19265:21): }
19266:21): }
19267:21): }
19268:21): }
19269:21): }
19270:21): }
19271:21): return %menu;
19272:21): }
19273:21):
1.112 bowersj2 19274: 1;
19275: __END__;
1.41 ng 19276:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>