Annotation of loncom/interface/loncommon.pm, revision 1.1470
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1470 ! raeburn 4: # $Id: loncommon.pm,v 1.1469 2025/03/07 02:13:40 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.1383 raeburn 64: 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.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1409 raeburn 74: use LONCAPA::ltiutils;
1.1280 raeburn 75: use LONCAPA::LWPReq;
1.1395 raeburn 76: use LONCAPA::map();
1.1328 raeburn 77: use HTTP::Request;
1.657 raeburn 78: use DateTime::TimeZone;
1.1241 raeburn 79: use DateTime::Locale;
1.1220 raeburn 80: use Encode();
1.1091 foxr 81: use Text::Aspell;
1.1094 raeburn 82: use Authen::Captcha;
83: use Captcha::reCAPTCHA;
1.1234 raeburn 84: use JSON::DWIW;
1.1174 raeburn 85: use Crypt::DES;
86: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 87: use MIME::Lite;
88: use MIME::Types;
1.1292 raeburn 89: use File::Copy();
1.1300 raeburn 90: use File::Path();
1.1309 raeburn 91: use String::CRC32();
92: use Short::URL();
1.117 www 93:
1.517 raeburn 94: # ---------------------------------------------- Designs
95: use vars qw(%defaultdesign);
96:
1.22 www 97: my $readit;
98:
1.517 raeburn 99:
1.157 matthew 100: ##
101: ## Global Variables
102: ##
1.46 matthew 103:
1.643 foxr 104:
105: # ----------------------------------------------- SSI with retries:
106: #
107:
108: =pod
109:
1.648 raeburn 110: =head1 Server Side include with retries:
1.643 foxr 111:
112: =over 4
113:
1.648 raeburn 114: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 115:
116: Performs an ssi with some number of retries. Retries continue either
117: until the result is ok or until the retry count supplied by the
118: caller is exhausted.
119:
120: Inputs:
1.648 raeburn 121:
122: =over 4
123:
1.643 foxr 124: resource - Identifies the resource to insert.
1.648 raeburn 125:
1.643 foxr 126: retries - Count of the number of retries allowed.
1.648 raeburn 127:
1.643 foxr 128: form - Hash that identifies the rendering options.
129:
1.648 raeburn 130: =back
131:
132: Returns:
133:
134: =over 4
135:
1.643 foxr 136: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 137:
1.643 foxr 138: response - The response from the last attempt (which may or may not have been successful.
139:
1.648 raeburn 140: =back
141:
142: =back
143:
1.643 foxr 144: =cut
145:
146: sub ssi_with_retries {
147: my ($resource, $retries, %form) = @_;
148:
149:
150: my $ok = 0; # True if we got a good response.
151: my $content;
152: my $response;
153:
154: # Try to get the ssi done. within the retries count:
155:
156: do {
157: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
158: $ok = $response->is_success;
1.650 www 159: if (!$ok) {
160: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
161: }
1.643 foxr 162: $retries--;
163: } while (!$ok && ($retries > 0));
164:
165: if (!$ok) {
166: $content = ''; # On error return an empty content.
167: }
168: return ($content, $response);
169:
170: }
171:
172:
173:
1.20 www 174: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 175: my %language;
1.124 www 176: my %supported_language;
1.1088 foxr 177: my %supported_codes;
1.1048 foxr 178: my %latex_language; # For choosing hyphenation in <transl..>
179: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 180: my %cprtag;
1.192 taceyjo1 181: my %scprtag;
1.351 www 182: my %fe; my %fd; my %fm;
1.41 ng 183: my %category_extensions;
1.12 harris41 184:
1.46 matthew 185: # ---------------------------------------------- Thesaurus variables
1.144 matthew 186: #
187: # %Keywords:
188: # A hash used by &keyword to determine if a word is considered a keyword.
189: # $thesaurus_db_file
190: # Scalar containing the full path to the thesaurus database.
1.46 matthew 191:
192: my %Keywords;
193: my $thesaurus_db_file;
194:
1.144 matthew 195: #
196: # Initialize values from language.tab, copyright.tab, filetypes.tab,
197: # thesaurus.tab, and filecategories.tab.
198: #
1.18 www 199: BEGIN {
1.46 matthew 200: # Variable initialization
201: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
202: #
1.22 www 203: unless ($readit) {
1.12 harris41 204: # ------------------------------------------------------------------- languages
205: {
1.158 raeburn 206: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
207: '/language.tab';
1.1317 raeburn 208: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 209: while (my $line = <$fh>) {
210: next if ($line=~/^\#/);
211: chomp($line);
1.1088 foxr 212: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 213: $language{$key}=$val.' - '.$enc;
214: if ($sup) {
215: $supported_language{$key}=$sup;
1.1088 foxr 216: $supported_codes{$key} = $code;
1.158 raeburn 217: }
1.1048 foxr 218: if ($latex) {
219: $latex_language_bykey{$key} = $latex;
1.1088 foxr 220: $latex_language{$code} = $latex;
1.1048 foxr 221: }
1.158 raeburn 222: }
223: close($fh);
224: }
1.12 harris41 225: }
226: # ------------------------------------------------------------------ copyrights
227: {
1.158 raeburn 228: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
229: '/copyright.tab';
1.1317 raeburn 230: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 231: while (my $line = <$fh>) {
232: next if ($line=~/^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 235: $cprtag{$key}=$val;
236: }
237: close($fh);
238: }
1.12 harris41 239: }
1.351 www 240: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 241: {
242: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
243: '/source_copyright.tab';
1.1317 raeburn 244: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 249: $scprtag{$key}=$val;
250: }
251: close($fh);
252: }
253: }
1.63 www 254:
1.517 raeburn 255: # -------------------------------------------------------------- default domain designs
1.63 www 256: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 257: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 258: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 259: while (my $line = <$fh>) {
260: next if ($line =~ /^\#/);
261: chomp($line);
262: my ($key,$val)=(split(/\=/,$line));
263: if ($val) { $defaultdesign{$key}=$val; }
264: }
265: close($fh);
1.63 www 266: }
267:
1.15 harris41 268: # ------------------------------------------------------------- file categories
269: {
1.158 raeburn 270: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filecategories.tab';
1.1317 raeburn 272: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 277: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 278: }
279: close($fh);
280: }
281:
1.15 harris41 282: }
1.12 harris41 283: # ------------------------------------------------------------------ file types
284: {
1.158 raeburn 285: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
286: '/filetypes.tab';
1.1317 raeburn 287: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 288: while (my $line = <$fh>) {
289: next if ($line =~ /^\#/);
290: chomp($line);
291: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 292: if ($descr ne '') {
293: $fe{$ending}=lc($emb);
294: $fd{$ending}=$descr;
1.351 www 295: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 296: }
297: }
298: close($fh);
299: }
1.12 harris41 300: }
1.22 www 301: &Apache::lonnet::logthis(
1.705 tempelho 302: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 303: $readit=1;
1.46 matthew 304: } # end of unless($readit)
1.32 matthew 305:
306: }
1.112 bowersj2 307:
1.42 matthew 308: ###############################################################
309: ## HTML and Javascript Helper Functions ##
310: ###############################################################
311:
312: =pod
313:
1.112 bowersj2 314: =head1 HTML and Javascript Functions
1.42 matthew 315:
1.112 bowersj2 316: =over 4
317:
1.648 raeburn 318: =item * &browser_and_searcher_javascript()
1.112 bowersj2 319:
320: X<browsing, javascript>X<searching, javascript>Returns a string
321: containing javascript with two functions, C<openbrowser> and
322: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
323: tags.
1.42 matthew 324:
1.648 raeburn 325: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 326:
327: inputs: formname, elementname, only, omit
328:
329: formname and elementname indicate the name of the html form and name of
330: the element that the results of the browsing selection are to be placed in.
331:
332: Specifying 'only' will restrict the browser to displaying only files
1.185 www 333: with the given extension. Can be a comma separated list.
1.42 matthew 334:
335: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 336: with the given extension. Can be a comma separated list.
1.42 matthew 337:
1.648 raeburn 338: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 339:
340: Inputs: formname, elementname
341:
342: formname and elementname specify the name of the html form and the name
343: of the element the selection from the search results will be placed in.
1.542 raeburn 344:
1.42 matthew 345: =cut
346:
347: sub browser_and_searcher_javascript {
1.199 albertel 348: my ($mode)=@_;
349: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 350: my $resurl=&escape_single(&lastresurl());
1.42 matthew 351: return <<END;
1.219 albertel 352: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 353: var editbrowser = null;
1.135 albertel 354: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 355: var url = '$resurl/?';
1.42 matthew 356: if (editbrowser == null) {
357: url += 'launch=1&';
358: }
359: url += 'catalogmode=interactive&';
1.199 albertel 360: url += 'mode=$mode&';
1.611 albertel 361: url += 'inhibitmenu=yes&';
1.42 matthew 362: url += 'form=' + formname + '&';
363: if (only != null) {
364: url += 'only=' + only + '&';
1.217 albertel 365: } else {
366: url += 'only=&';
367: }
1.42 matthew 368: if (omit != null) {
369: url += 'omit=' + omit + '&';
1.217 albertel 370: } else {
371: url += 'omit=&';
372: }
1.135 albertel 373: if (titleelement != null) {
374: url += 'titleelement=' + titleelement + '&';
1.217 albertel 375: } else {
376: url += 'titleelement=&';
377: }
1.42 matthew 378: url += 'element=' + elementname + '';
379: var title = 'Browser';
1.435 albertel 380: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 381: options += ',width=700,height=600';
382: editbrowser = open(url,title,options,'1');
383: editbrowser.focus();
384: }
385: var editsearcher;
1.135 albertel 386: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 387: var url = '/adm/searchcat?';
388: if (editsearcher == null) {
389: url += 'launch=1&';
390: }
391: url += 'catalogmode=interactive&';
1.199 albertel 392: url += 'mode=$mode&';
1.42 matthew 393: url += 'form=' + formname + '&';
1.135 albertel 394: if (titleelement != null) {
395: url += 'titleelement=' + titleelement + '&';
1.217 albertel 396: } else {
397: url += 'titleelement=&';
398: }
1.42 matthew 399: url += 'element=' + elementname + '';
400: var title = 'Search';
1.435 albertel 401: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 402: options += ',width=700,height=600';
403: editsearcher = open(url,title,options,'1');
404: editsearcher.focus();
405: }
1.219 albertel 406: // END LON-CAPA Internal -->
1.42 matthew 407: END
1.170 www 408: }
409:
410: sub lastresurl {
1.258 albertel 411: if ($env{'environment.lastresurl'}) {
412: return $env{'environment.lastresurl'}
1.170 www 413: } else {
414: return '/res';
415: }
416: }
417:
418: sub storeresurl {
419: my $resurl=&Apache::lonnet::clutter(shift);
420: unless ($resurl=~/^\/res/) { return 0; }
421: $resurl=~s/\/$//;
422: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 423: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 424: return 1;
1.42 matthew 425: }
426:
1.74 www 427: sub studentbrowser_javascript {
1.111 www 428: unless (
1.258 albertel 429: (($env{'request.course.id'}) &&
1.302 albertel 430: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
431: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
432: '/'.$env{'request.course.sec'})
433: ))
1.258 albertel 434: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 435: ) { return ''; }
1.74 www 436: return (<<'ENDSTDBRW');
1.776 bisitz 437: <script type="text/javascript" language="Javascript">
1.824 bisitz 438: // <![CDATA[
1.74 www 439: var stdeditbrowser;
1.1413 raeburn 440: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv,uident) {
1.74 www 441: var url = '/adm/pickstudent?';
442: var filter;
1.558 albertel 443: if (!ignorefilter) {
444: eval('filter=document.'+formname+'.'+uname+'.value;');
445: }
1.74 www 446: if (filter != null) {
447: if (filter != '') {
448: url += 'filter='+filter+'&';
449: }
450: }
451: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 452: '&udomelement='+udom+
453: '&clicker='+clicker;
1.111 www 454: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 455: if (courseadv == 'condition') {
456: if (document.getElementById('courseadv')) {
457: courseadv = document.getElementById('courseadv').value;
458: }
459: }
460: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.1413 raeburn 461: if (uident !== '') { url+="&identelement="+uident; }
1.102 www 462: var title = 'Student_Browser';
1.74 www 463: var options = 'scrollbars=1,resizable=1,menubar=0';
464: options += ',width=700,height=600';
465: stdeditbrowser = open(url,title,options,'1');
466: stdeditbrowser.focus();
467: }
1.824 bisitz 468: // ]]>
1.74 www 469: </script>
470: ENDSTDBRW
471: }
1.42 matthew 472:
1.1003 www 473: sub resourcebrowser_javascript {
474: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 475: return (<<'ENDRESBRW');
1.1003 www 476: <script type="text/javascript" language="Javascript">
477: // <![CDATA[
478: var reseditbrowser;
1.1004 www 479: function openresbrowser(formname,reslink) {
1.1005 www 480: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 481: var title = 'Resource_Browser';
482: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 483: options += ',width=700,height=500';
1.1004 www 484: reseditbrowser = open(url,title,options,'1');
485: reseditbrowser.focus();
1.1003 www 486: }
487: // ]]>
488: </script>
1.1004 www 489: ENDRESBRW
1.1003 www 490: }
491:
1.74 www 492: sub selectstudent_link {
1.1413 raeburn 493: my ($form,$unameele,$udomele,$courseadv,$clickerid,$identelem)=@_;
1.999 www 494: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
495: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
496: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 497: if ($env{'request.course.id'}) {
1.302 albertel 498: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
499: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
500: '/'.$env{'request.course.sec'})) {
1.111 www 501: return '';
502: }
1.999 www 503: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 504: if ($courseadv eq 'only') {
505: $callargs .= ",'',1,'$courseadv'";
506: } elsif ($courseadv eq 'none') {
507: $callargs .= ",'','','$courseadv'";
508: } elsif ($courseadv eq 'condition') {
509: $callargs .= ",'','','$courseadv'";
1.1413 raeburn 510: } elsif ($identelem ne '') {
511: $callargs .= ",'','',''";
512: }
513: if ($identelem ne '') {
514: $callargs .= ",'".&Apache::lonhtmlcommon::entity_encode($identelem)."'";
1.793 raeburn 515: }
516: return '<span class="LC_nobreak">'.
517: '<a href="javascript:openstdbrowser('.$callargs.');">'.
518: &mt('Select User').'</a></span>';
1.74 www 519: }
1.258 albertel 520: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 521: $callargs .= ",'',1";
1.793 raeburn 522: return '<span class="LC_nobreak">'.
523: '<a href="javascript:openstdbrowser('.$callargs.');">'.
524: &mt('Select User').'</a></span>';
1.111 www 525: }
526: return '';
1.91 www 527: }
528:
1.1004 www 529: sub selectresource_link {
530: my ($form,$reslink,$arg)=@_;
531:
532: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
533: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
534: unless ($env{'request.course.id'}) { return $arg; }
535: return '<span class="LC_nobreak">'.
536: '<a href="javascript:openresbrowser('.$callargs.');">'.
537: $arg.'</a></span>';
538: }
539:
540:
541:
1.653 raeburn 542: sub authorbrowser_javascript {
543: return <<"ENDAUTHORBRW";
1.776 bisitz 544: <script type="text/javascript" language="JavaScript">
1.824 bisitz 545: // <![CDATA[
1.653 raeburn 546: var stdeditbrowser;
547:
548: function openauthorbrowser(formname,udom) {
549: var url = '/adm/pickauthor?';
550: url += 'form='+formname+'&roledom='+udom;
551: var title = 'Author_Browser';
552: var options = 'scrollbars=1,resizable=1,menubar=0';
553: options += ',width=700,height=600';
554: stdeditbrowser = open(url,title,options,'1');
555: stdeditbrowser.focus();
556: }
557:
1.824 bisitz 558: // ]]>
1.653 raeburn 559: </script>
560: ENDAUTHORBRW
561: }
562:
1.91 www 563: sub coursebrowser_javascript {
1.1116 raeburn 564: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 565: $credits_element,$instcode) = @_;
1.932 raeburn 566: my $wintitle = 'Course_Browser';
1.931 raeburn 567: if ($crstype eq 'Community') {
1.932 raeburn 568: $wintitle = 'Community_Browser';
1.909 raeburn 569: }
1.876 raeburn 570: my $id_functions = &javascript_index_functions();
571: my $output = '
1.776 bisitz 572: <script type="text/javascript" language="JavaScript">
1.824 bisitz 573: // <![CDATA[
1.468 raeburn 574: var stdeditbrowser;'."\n";
1.876 raeburn 575:
576: $output .= <<"ENDSTDBRW";
1.909 raeburn 577: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 578: var url = '/adm/pickcourse?';
1.895 raeburn 579: var formid = getFormIdByName(formname);
1.876 raeburn 580: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 581: if (domainfilter != null) {
582: if (domainfilter != '') {
583: url += 'domainfilter='+domainfilter+'&';
584: }
585: }
1.91 www 586: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 587: '&cdomelement='+udom+
588: '&cnameelement='+desc;
1.468 raeburn 589: if (extra_element !=null && extra_element != '') {
1.594 raeburn 590: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 591: url += '&roleelement='+extra_element;
592: if (domainfilter == null || domainfilter == '') {
593: url += '&domainfilter='+extra_element;
594: }
1.234 raeburn 595: }
1.468 raeburn 596: else {
597: if (formname == 'portform') {
598: url += '&setroles='+extra_element;
1.800 raeburn 599: } else {
600: if (formname == 'rules') {
601: url += '&fixeddom='+extra_element;
602: }
1.468 raeburn 603: }
604: }
1.230 raeburn 605: }
1.909 raeburn 606: if (type != null && type != '') {
607: url += '&type='+type;
608: }
609: if (type_elem != null && type_elem != '') {
610: url += '&typeelement='+type_elem;
611: }
1.872 raeburn 612: if (formname == 'ccrs') {
613: var ownername = document.forms[formid].ccuname.value;
614: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 615: url += '&cloner='+ownername+':'+ownerdom;
616: if (type == 'Course') {
617: url += '&crscode='+document.forms[formid].crscode.value;
618: }
1.1221 raeburn 619: }
620: if (formname == 'requestcrs') {
621: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 622: }
1.293 raeburn 623: if (multflag !=null && multflag != '') {
624: url += '&multiple='+multflag;
625: }
1.909 raeburn 626: var title = '$wintitle';
1.91 www 627: var options = 'scrollbars=1,resizable=1,menubar=0';
628: options += ',width=700,height=600';
629: stdeditbrowser = open(url,title,options,'1');
630: stdeditbrowser.focus();
631: }
1.876 raeburn 632: $id_functions
633: ENDSTDBRW
1.1116 raeburn 634: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
635: $output .= &setsec_javascript($sec_element,$formname,$role_element,
636: $credits_element);
1.876 raeburn 637: }
638: $output .= '
639: // ]]>
640: </script>';
641: return $output;
642: }
643:
644: sub javascript_index_functions {
645: return <<"ENDJS";
646:
647: function getFormIdByName(formname) {
648: for (var i=0;i<document.forms.length;i++) {
649: if (document.forms[i].name == formname) {
650: return i;
651: }
652: }
653: return -1;
654: }
655:
656: function getIndexByName(formid,item) {
657: for (var i=0;i<document.forms[formid].elements.length;i++) {
658: if (document.forms[formid].elements[i].name == item) {
659: return i;
660: }
661: }
662: return -1;
663: }
1.468 raeburn 664:
1.876 raeburn 665: function getDomainFromSelectbox(formname,udom) {
666: var userdom;
667: var formid = getFormIdByName(formname);
668: if (formid > -1) {
669: var domid = getIndexByName(formid,udom);
670: if (domid > -1) {
671: if (document.forms[formid].elements[domid].type == 'select-one') {
672: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
673: }
674: if (document.forms[formid].elements[domid].type == 'hidden') {
675: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 676: }
677: }
678: }
1.876 raeburn 679: return userdom;
680: }
681:
682: ENDJS
1.468 raeburn 683:
1.876 raeburn 684: }
685:
1.1017 raeburn 686: sub javascript_array_indexof {
1.1018 raeburn 687: return <<ENDJS;
1.1017 raeburn 688: <script type="text/javascript" language="JavaScript">
689: // <![CDATA[
690:
691: if (!Array.prototype.indexOf) {
692: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
693: "use strict";
694: if (this === void 0 || this === null) {
695: throw new TypeError();
696: }
697: var t = Object(this);
698: var len = t.length >>> 0;
699: if (len === 0) {
700: return -1;
701: }
702: var n = 0;
703: if (arguments.length > 0) {
704: n = Number(arguments[1]);
1.1088 foxr 705: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 706: n = 0;
707: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
708: n = (n > 0 || -1) * Math.floor(Math.abs(n));
709: }
710: }
711: if (n >= len) {
712: return -1;
713: }
714: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
715: for (; k < len; k++) {
716: if (k in t && t[k] === searchElement) {
717: return k;
718: }
719: }
720: return -1;
721: }
722: }
723:
724: // ]]>
725: </script>
726:
727: ENDJS
728:
729: }
730:
1.876 raeburn 731: sub userbrowser_javascript {
732: my $id_functions = &javascript_index_functions();
733: return <<"ENDUSERBRW";
734:
1.888 raeburn 735: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 736: var url = '/adm/pickuser?';
737: var userdom = getDomainFromSelectbox(formname,udom);
738: if (userdom != null) {
739: if (userdom != '') {
740: url += 'srchdom='+userdom+'&';
741: }
742: }
743: url += 'form=' + formname + '&unameelement='+uname+
744: '&udomelement='+udom+
745: '&ulastelement='+ulast+
746: '&ufirstelement='+ufirst+
747: '&uemailelement='+uemail+
1.881 raeburn 748: '&hideudomelement='+hideudom+
749: '&coursedom='+crsdom;
1.888 raeburn 750: if ((caller != null) && (caller != undefined)) {
751: url += '&caller='+caller;
752: }
1.876 raeburn 753: var title = 'User_Browser';
754: var options = 'scrollbars=1,resizable=1,menubar=0';
755: options += ',width=700,height=600';
756: var stdeditbrowser = open(url,title,options,'1');
757: stdeditbrowser.focus();
758: }
759:
1.888 raeburn 760: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 761: var formid = getFormIdByName(formname);
762: if (formid > -1) {
1.888 raeburn 763: var unameid = getIndexByName(formid,uname);
1.876 raeburn 764: var domid = getIndexByName(formid,udom);
765: var hidedomid = getIndexByName(formid,origdom);
766: if (hidedomid > -1) {
767: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 768: var unameval = document.forms[formid].elements[unameid].value;
769: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
770: if (domid > -1) {
771: var slct = document.forms[formid].elements[domid];
772: if (slct.type == 'select-one') {
773: var i;
774: for (i=0;i<slct.length;i++) {
775: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
776: }
777: }
778: if (slct.type == 'hidden') {
779: slct.value = fixeddom;
1.876 raeburn 780: }
781: }
1.468 raeburn 782: }
783: }
784: }
1.876 raeburn 785: return;
786: }
787:
788: $id_functions
789: ENDUSERBRW
1.468 raeburn 790: }
791:
792: sub setsec_javascript {
1.1116 raeburn 793: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 794: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
795: $communityrolestr);
796: if ($role_element ne '') {
797: my @allroles = ('st','ta','ep','in','ad');
798: foreach my $crstype ('Course','Community') {
799: if ($crstype eq 'Community') {
800: foreach my $role (@allroles) {
801: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
802: }
803: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
804: } else {
805: foreach my $role (@allroles) {
806: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
807: }
808: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
809: }
810: }
811: $rolestr = '"'.join('","',@allroles).'"';
812: $courserolestr = '"'.join('","',@courserolenames).'"';
813: $communityrolestr = '"'.join('","',@communityrolenames).'"';
814: }
1.468 raeburn 815: my $setsections = qq|
816: function setSect(sectionlist) {
1.629 raeburn 817: var sectionsArray = new Array();
818: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
819: sectionsArray = sectionlist.split(",");
820: }
1.468 raeburn 821: var numSections = sectionsArray.length;
822: document.$formname.$sec_element.length = 0;
823: if (numSections == 0) {
824: document.$formname.$sec_element.multiple=false;
825: document.$formname.$sec_element.size=1;
826: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
827: } else {
828: if (numSections == 1) {
829: document.$formname.$sec_element.multiple=false;
830: document.$formname.$sec_element.size=1;
831: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
832: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
833: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
834: } else {
835: for (var i=0; i<numSections; i++) {
836: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
837: }
838: document.$formname.$sec_element.multiple=true
839: if (numSections < 3) {
840: document.$formname.$sec_element.size=numSections;
841: } else {
842: document.$formname.$sec_element.size=3;
843: }
844: document.$formname.$sec_element.options[0].selected = false
845: }
846: }
1.91 www 847: }
1.905 raeburn 848:
849: function setRole(crstype) {
1.468 raeburn 850: |;
1.905 raeburn 851: if ($role_element eq '') {
852: $setsections .= ' return;
853: }
854: ';
855: } else {
856: $setsections .= qq|
857: var elementLength = document.$formname.$role_element.length;
858: var allroles = Array($rolestr);
859: var courserolenames = Array($courserolestr);
860: var communityrolenames = Array($communityrolestr);
861: if (elementLength != undefined) {
862: if (document.$formname.$role_element.options[5].value == 'cc') {
863: if (crstype == 'Course') {
864: return;
865: } else {
866: allroles[5] = 'co';
867: for (var i=0; i<6; i++) {
868: document.$formname.$role_element.options[i].value = allroles[i];
869: document.$formname.$role_element.options[i].text = communityrolenames[i];
870: }
871: }
872: } else {
873: if (crstype == 'Community') {
874: return;
875: } else {
876: allroles[5] = 'cc';
877: for (var i=0; i<6; i++) {
878: document.$formname.$role_element.options[i].value = allroles[i];
879: document.$formname.$role_element.options[i].text = courserolenames[i];
880: }
881: }
882: }
883: }
884: return;
885: }
886: |;
887: }
1.1116 raeburn 888: if ($credits_element) {
889: $setsections .= qq|
890: function setCredits(defaultcredits) {
891: document.$formname.$credits_element.value = defaultcredits;
892: return;
893: }
894: |;
895: }
1.468 raeburn 896: return $setsections;
897: }
898:
1.91 www 899: sub selectcourse_link {
1.909 raeburn 900: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
901: $typeelement) = @_;
902: my $type = $selecttype;
1.871 raeburn 903: my $linktext = &mt('Select Course');
904: if ($selecttype eq 'Community') {
1.909 raeburn 905: $linktext = &mt('Select Community');
1.1239 raeburn 906: } elsif ($selecttype eq 'Placement') {
907: $linktext = &mt('Select Placement Test');
1.906 raeburn 908: } elsif ($selecttype eq 'Course/Community') {
909: $linktext = &mt('Select Course/Community');
1.909 raeburn 910: $type = '';
1.1019 raeburn 911: } elsif ($selecttype eq 'Select') {
912: $linktext = &mt('Select');
913: $type = '';
1.871 raeburn 914: }
1.787 bisitz 915: return '<span class="LC_nobreak">'
916: ."<a href='"
917: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
918: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 919: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 920: ."'>".$linktext.'</a>'
1.787 bisitz 921: .'</span>';
1.74 www 922: }
1.42 matthew 923:
1.653 raeburn 924: sub selectauthor_link {
925: my ($form,$udom)=@_;
926: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
927: &mt('Select Author').'</a>';
928: }
929:
1.876 raeburn 930: sub selectuser_link {
1.881 raeburn 931: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 932: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 933: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 934: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 935: ');">'.$linktext.'</a>';
1.876 raeburn 936: }
937:
1.273 raeburn 938: sub check_uncheck_jscript {
939: my $jscript = <<"ENDSCRT";
940: function checkAll(field) {
941: if (field.length > 0) {
942: for (i = 0; i < field.length; i++) {
1.1093 raeburn 943: if (!field[i].disabled) {
944: field[i].checked = true;
945: }
1.273 raeburn 946: }
947: } else {
1.1093 raeburn 948: if (!field.disabled) {
949: field.checked = true;
950: }
1.273 raeburn 951: }
952: }
953:
954: function uncheckAll(field) {
955: if (field.length > 0) {
956: for (i = 0; i < field.length; i++) {
957: field[i].checked = false ;
1.543 albertel 958: }
959: } else {
1.273 raeburn 960: field.checked = false ;
961: }
962: }
963: ENDSCRT
964: return $jscript;
965: }
966:
1.656 www 967: sub select_timezone {
1.1387 raeburn 968: my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
1.1469 raeburn 969: my $labeltext = &HTML::Entities::encode(&mt('Select Time Zone'));
970: my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.
971: ' aria-label="'.$labeltext.'">'."\n";
1.659 raeburn 972: if ($includeempty) {
973: $output .= '<option value=""';
974: if (($selected eq '') || ($selected eq 'local')) {
975: $output .= ' selected="selected" ';
976: }
977: $output .= '> </option>';
978: }
1.657 raeburn 979: my @timezones = DateTime::TimeZone->all_names;
980: foreach my $tzone (@timezones) {
981: $output.= '<option value="'.$tzone.'"';
982: if ($tzone eq $selected) {
983: $output.=' selected="selected"';
984: }
985: $output.=">$tzone</option>\n";
1.656 www 986: }
987: $output.="</select>";
988: return $output;
989: }
1.273 raeburn 990:
1.687 raeburn 991: sub select_datelocale {
1.1256 raeburn 992: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
993: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 994: if ($includeempty) {
995: $output .= '<option value=""';
996: if ($selected eq '') {
997: $output .= ' selected="selected" ';
998: }
999: $output .= '> </option>';
1000: }
1.1241 raeburn 1001: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 1002: my (@possibles,%locale_names);
1.1241 raeburn 1003: my @locales = DateTime::Locale->ids();
1004: foreach my $id (@locales) {
1005: if ($id ne '') {
1006: my ($en_terr,$native_terr);
1007: my $loc = DateTime::Locale->load($id);
1008: if (ref($loc)) {
1009: $en_terr = $loc->name();
1010: $native_terr = $loc->native_name();
1.687 raeburn 1011: if (grep(/^en$/,@languages) || !@languages) {
1012: if ($en_terr ne '') {
1013: $locale_names{$id} = '('.$en_terr.')';
1014: } elsif ($native_terr ne '') {
1015: $locale_names{$id} = $native_terr;
1016: }
1017: } else {
1018: if ($native_terr ne '') {
1019: $locale_names{$id} = $native_terr.' ';
1020: } elsif ($en_terr ne '') {
1021: $locale_names{$id} = '('.$en_terr.')';
1022: }
1023: }
1.1220 raeburn 1024: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1025: push(@possibles,$id);
1026: }
1.687 raeburn 1027: }
1028: }
1029: foreach my $item (sort(@possibles)) {
1030: $output.= '<option value="'.$item.'"';
1031: if ($item eq $selected) {
1032: $output.=' selected="selected"';
1033: }
1034: $output.=">$item";
1035: if ($locale_names{$item} ne '') {
1.1220 raeburn 1036: $output.=' '.$locale_names{$item};
1.687 raeburn 1037: }
1038: $output.="</option>\n";
1039: }
1040: $output.="</select>";
1041: return $output;
1042: }
1043:
1.792 raeburn 1044: sub select_language {
1.1256 raeburn 1045: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1046: my %langchoices;
1047: if ($includeempty) {
1.1117 raeburn 1048: %langchoices = ('' => 'No language preference');
1.792 raeburn 1049: }
1050: foreach my $id (&languageids()) {
1051: my $code = &supportedlanguagecode($id);
1052: if ($code) {
1053: $langchoices{$code} = &plainlanguagedescription($id);
1054: }
1055: }
1.1117 raeburn 1056: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1057: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1058: }
1059:
1.42 matthew 1060: =pod
1.36 matthew 1061:
1.1088 foxr 1062:
1063: =item * &list_languages()
1064:
1065: Returns an array reference that is suitable for use in language prompters.
1066: Each array element is itself a two element array. The first element
1067: is the language code. The second element a descsriptiuon of the
1068: language itself. This is suitable for use in e.g.
1069: &Apache::edit::select_arg (once dereferenced that is).
1070:
1071: =cut
1072:
1073: sub list_languages {
1074: my @lang_choices;
1075:
1076: foreach my $id (&languageids()) {
1077: my $code = &supportedlanguagecode($id);
1078: if ($code) {
1079: my $selector = $supported_codes{$id};
1080: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1081: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1082: }
1083: }
1084: return \@lang_choices;
1085: }
1086:
1087: =pod
1088:
1.648 raeburn 1089: =item * &linked_select_forms(...)
1.36 matthew 1090:
1091: linked_select_forms returns a string containing a <script></script> block
1092: and html for two <select> menus. The select menus will be linked in that
1093: changing the value of the first menu will result in new values being placed
1094: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1095: order unless a defined order is provided.
1.36 matthew 1096:
1097: linked_select_forms takes the following ordered inputs:
1098:
1099: =over 4
1100:
1.112 bowersj2 1101: =item * $formname, the name of the <form> tag
1.36 matthew 1102:
1.112 bowersj2 1103: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1104:
1.112 bowersj2 1105: =item * $firstdefault, the default value for the first menu
1.36 matthew 1106:
1.112 bowersj2 1107: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1108:
1.112 bowersj2 1109: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1110:
1.112 bowersj2 1111: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1112:
1.609 raeburn 1113: =item * $menuorder, the order of values in the first menu
1114:
1.1115 raeburn 1115: =item * $onchangefirst, additional javascript call to execute for an onchange
1116: event for the first <select> tag
1117:
1118: =item * $onchangesecond, additional javascript call to execute for an onchange
1119: event for the second <select> tag
1120:
1.1245 raeburn 1121: =item * $suffix, to differentiate separate uses of select2data javascript
1122: objects in a page.
1123:
1.41 ng 1124: =back
1125:
1.36 matthew 1126: Below is an example of such a hash. Only the 'text', 'default', and
1127: 'select2' keys must appear as stated. keys(%menu) are the possible
1128: values for the first select menu. The text that coincides with the
1.41 ng 1129: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1130: and text for the second menu are given in the hash pointed to by
1131: $menu{$choice1}->{'select2'}.
1132:
1.112 bowersj2 1133: my %menu = ( A1 => { text =>"Choice A1" ,
1134: default => "B3",
1135: select2 => {
1136: B1 => "Choice B1",
1137: B2 => "Choice B2",
1138: B3 => "Choice B3",
1139: B4 => "Choice B4"
1.609 raeburn 1140: },
1141: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1142: },
1143: A2 => { text =>"Choice A2" ,
1144: default => "C2",
1145: select2 => {
1146: C1 => "Choice C1",
1147: C2 => "Choice C2",
1148: C3 => "Choice C3"
1.609 raeburn 1149: },
1150: order => ['C2','C1','C3'],
1.112 bowersj2 1151: },
1152: A3 => { text =>"Choice A3" ,
1153: default => "D6",
1154: select2 => {
1155: D1 => "Choice D1",
1156: D2 => "Choice D2",
1157: D3 => "Choice D3",
1158: D4 => "Choice D4",
1159: D5 => "Choice D5",
1160: D6 => "Choice D6",
1161: D7 => "Choice D7"
1.609 raeburn 1162: },
1163: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1164: }
1165: );
1.36 matthew 1166:
1167: =cut
1168:
1169: sub linked_select_forms {
1170: my ($formname,
1171: $middletext,
1172: $firstdefault,
1173: $firstselectname,
1174: $secondselectname,
1.609 raeburn 1175: $hashref,
1176: $menuorder,
1.1115 raeburn 1177: $onchangefirst,
1.1245 raeburn 1178: $onchangesecond,
1.1450 raeburn 1179: $suffix,
1180: $haslabel
1.36 matthew 1181: ) = @_;
1182: my $second = "document.$formname.$secondselectname";
1183: my $first = "document.$formname.$firstselectname";
1184: # output the javascript to do the changing
1185: my $result = '';
1.776 bisitz 1186: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1187: $result.="// <![CDATA[\n";
1.1245 raeburn 1188: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1189: $" = '","';
1190: my $debug = '';
1191: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1192: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1193: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1194: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1195: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1196: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1197: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1198: @s2values = @{$hashref->{$s1}->{'order'}};
1199: }
1.36 matthew 1200: $result.="\"@s2values\");\n";
1.1245 raeburn 1201: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1202: my @s2texts;
1203: foreach my $value (@s2values) {
1.1263 raeburn 1204: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1205: }
1206: $result.="\"@s2texts\");\n";
1207: }
1208: $"=' ';
1209: $result.= <<"END";
1210:
1.1245 raeburn 1211: function select1${suffix}_changed() {
1.36 matthew 1212: // Determine new choice
1.1245 raeburn 1213: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1214: // update select2
1.1245 raeburn 1215: var values = select2data${suffix}[newvalue].values;
1216: var texts = select2data${suffix}[newvalue].texts;
1217: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1218: var i;
1219: // out with the old
1.1245 raeburn 1220: $second.options.length = 0;
1221: // in with the new
1.36 matthew 1222: for (i=0;i<values.length; i++) {
1223: $second.options[i] = new Option(values[i]);
1.143 matthew 1224: $second.options[i].value = values[i];
1.36 matthew 1225: $second.options[i].text = texts[i];
1226: if (values[i] == select2def) {
1227: $second.options[i].selected = true;
1228: }
1229: }
1230: }
1.824 bisitz 1231: // ]]>
1.36 matthew 1232: </script>
1233: END
1234: # output the initial values for the selection lists
1.1245 raeburn 1235: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1236: my @order = sort(keys(%{$hashref}));
1237: if (ref($menuorder) eq 'ARRAY') {
1238: @order = @{$menuorder};
1239: }
1240: foreach my $value (@order) {
1.36 matthew 1241: $result.=" <option value=\"$value\" ";
1.253 albertel 1242: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1243: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1244: }
1245: $result .= "</select>\n";
1.1450 raeburn 1246: if ($haslabel) {
1247: $result .= '</label>';
1248: }
1.1400 raeburn 1249: my %select2;
1250: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1251: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1252: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1253: }
1254: }
1.1450 raeburn 1255: if ($middletext ne '') {
1.1452 raeburn 1256: $result .= '<label>'.$middletext;
1.1450 raeburn 1257: }
1.1115 raeburn 1258: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1259: if ($onchangesecond) {
1260: $result .= ' onchange="'.$onchangesecond.'"';
1261: }
1262: $result .= ">\n";
1.36 matthew 1263: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1264:
1265: my @secondorder = sort(keys(%select2));
1266: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1267: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1268: }
1269: foreach my $value (@secondorder) {
1.36 matthew 1270: $result.=" <option value=\"$value\" ";
1.253 albertel 1271: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1272: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1273: }
1274: $result .= "</select>\n";
1.1450 raeburn 1275: if ($middletext ne '') {
1276: $result .= '</label>';
1277: }
1.36 matthew 1278: # return $debug;
1279: return $result;
1280: } # end of sub linked_select_forms {
1281:
1.45 matthew 1282: =pod
1.44 bowersj2 1283:
1.1381 raeburn 1284: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1285:
1.112 bowersj2 1286: Returns a string corresponding to an HTML link to the given help
1287: $topic, where $topic corresponds to the name of a .tex file in
1288: /home/httpd/html/adm/help/tex, with underscores replaced by
1289: spaces.
1290:
1291: $text will optionally be linked to the same topic, allowing you to
1292: link text in addition to the graphic. If you do not want to link
1293: text, but wish to specify one of the later parameters, pass an
1294: empty string.
1295:
1296: $stayOnPage is a value that will be interpreted as a boolean. If true,
1297: the link will not open a new window. If false, the link will open
1298: a new window using Javascript. (Default is false.)
1299:
1300: $width and $height are optional numerical parameters that will
1301: override the width and height of the popped up window, which may
1.973 raeburn 1302: be useful for certain help topics with big pictures included.
1303:
1304: $imgid is the id of the img tag used for the help icon. This may be
1305: used in a javascript call to switch the image src. See
1306: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1307:
1.1381 raeburn 1308: $links_target will optionally be set to a target (_top, _parent or _self).
1309:
1.44 bowersj2 1310: =cut
1311:
1312: sub help_open_topic {
1.1381 raeburn 1313: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1314: $text = "" if (not defined $text);
1.44 bowersj2 1315: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1316: $width = 500 if (not defined $width);
1.44 bowersj2 1317: $height = 400 if (not defined $height);
1318: my $filename = $topic;
1319: $filename =~ s/ /_/g;
1320:
1.48 bowersj2 1321: my $template = "";
1322: my $link;
1.572 banghart 1323:
1.159 www 1324: $topic=~s/\W/\_/g;
1.44 bowersj2 1325:
1.572 banghart 1326: if (!$stayOnPage) {
1.1033 www 1327: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1328: } elsif ($stayOnPage eq 'popup') {
1329: $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 1330: } else {
1.48 bowersj2 1331: $link = "/adm/help/${filename}.hlp";
1332: }
1333:
1334: # Add the text
1.1314 raeburn 1335: my $target = ' target="_top"';
1.1381 raeburn 1336: if ($links_target) {
1337: $target = ' target="'.$links_target.'"';
1338: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1339: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1340: $target = '';
1.1378 raeburn 1341: }
1.1380 raeburn 1342: if ($text ne "") {
1.763 bisitz 1343: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1344: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1345: .$text.'</a>';
1.48 bowersj2 1346: }
1347:
1.763 bisitz 1348: # (Always) Add the graphic
1.179 matthew 1349: my $title = &mt('Online Help');
1.667 raeburn 1350: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1351: if ($imgid ne '') {
1352: $imgid = ' id="'.$imgid.'"';
1353: }
1.1314 raeburn 1354: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1355: .'<img src="'.$helpicon.'" border="0"'
1.1469 raeburn 1356: .' alt="'.&mt('Help icon').'"'
1.973 raeburn 1357: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1358: .' /></a>';
1359: if ($text ne "") {
1360: $template.='</span>';
1361: }
1.44 bowersj2 1362: return $template;
1363:
1.106 bowersj2 1364: }
1365:
1366: # This is a quicky function for Latex cheatsheet editing, since it
1367: # appears in at least four places
1368: sub helpLatexCheatsheet {
1.1037 www 1369: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1370: my $out;
1.106 bowersj2 1371: my $addOther = '';
1.732 raeburn 1372: if ($topic) {
1.1037 www 1373: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1374: }
1375: $out = '<span>' # Start cheatsheet
1376: .$addOther
1377: .'<span>'
1.1037 www 1378: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1379: .'</span> <span>'
1.1037 www 1380: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1381: .'</span>';
1.732 raeburn 1382: unless ($not_author) {
1.1186 kruse 1383: $out .= '<span>'
1384: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1385: .'</span> <span>'
1.1424 raeburn 1386: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.763 bisitz 1387: .'</span>';
1.732 raeburn 1388: }
1.763 bisitz 1389: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1390: return $out;
1.172 www 1391: }
1392:
1.430 albertel 1393: sub general_help {
1394: my $helptopic='Student_Intro';
1395: if ($env{'request.role'}=~/^(ca|au)/) {
1396: $helptopic='Authoring_Intro';
1.907 raeburn 1397: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1398: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1399: } elsif ($env{'request.role'}=~/^dc/) {
1400: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1401: }
1402: return $helptopic;
1403: }
1404:
1405: sub update_help_link {
1406: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1407: my $origurl = $ENV{'REQUEST_URI'};
1408: $origurl=~s|^/~|/priv/|;
1409: my $timestamp = time;
1410: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1411: $$datum = &escape($$datum);
1412: }
1413:
1414: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1415: my $output .= <<"ENDOUTPUT";
1416: <script type="text/javascript">
1.824 bisitz 1417: // <![CDATA[
1.430 albertel 1418: banner_link = '$banner_link';
1.824 bisitz 1419: // ]]>
1.430 albertel 1420: </script>
1421: ENDOUTPUT
1422: return $output;
1423: }
1424:
1425: # now just updates the help link and generates a blue icon
1.193 raeburn 1426: sub help_open_menu {
1.1381 raeburn 1427: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1428: = @_;
1.949 droeschl 1429: $stayOnPage = 1;
1.430 albertel 1430: my $output;
1431: if ($component_help) {
1432: if (!$text) {
1433: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1434: $width,$height,'',$links_target);
1.430 albertel 1435: } else {
1436: my $help_text;
1437: $help_text=&unescape($topic);
1438: $output='<table><tr><td>'.
1439: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1440: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1441: }
1442: }
1443: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1444: return $output.$banner_link;
1445: }
1446:
1447: sub top_nav_help {
1.1369 raeburn 1448: my ($text,$linkattr) = @_;
1.436 albertel 1449: $text = &mt($text);
1.949 droeschl 1450: my $stay_on_page = 1;
1451:
1.1168 raeburn 1452: my ($link,$banner_link);
1453: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1454: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1455: : "javascript:helpMenu('open')";
1456: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1457: }
1.201 raeburn 1458: my $title = &mt('Get help');
1.1168 raeburn 1459: if ($link) {
1460: return <<"END";
1.436 albertel 1461: $banner_link
1.1369 raeburn 1462: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1463: END
1.1168 raeburn 1464: } else {
1.1459 raeburn 1465: return ' <h1 class="LC_helpmenu">'.$text.'</h1> ';
1.1168 raeburn 1466: }
1.436 albertel 1467: }
1468:
1469: sub help_menu_js {
1.1154 raeburn 1470: my ($httphost) = @_;
1.949 droeschl 1471: my $stayOnPage = 1;
1.436 albertel 1472: my $width = 620;
1473: my $height = 600;
1.430 albertel 1474: my $helptopic=&general_help();
1.1154 raeburn 1475: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1476: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.1459 raeburn 1477: my $bannertitle = &mt('Help Menu');
1478: &js_escape(\$bannertitle);
1479: my $bodytitle = &mt('Documentation');
1480: &js_escape(\$bodytitle);
1.331 albertel 1481: my $start_page =
1482: &Apache::loncommon::start_page('Help Menu', undef,
1483: {'frameset' => 1,
1484: 'js_ready' => 1,
1.1154 raeburn 1485: 'use_absolute' => $httphost,
1.331 albertel 1486: 'add_entries' => {
1.1168 raeburn 1487: 'border' => '0',
1.579 raeburn 1488: 'rows' => "110,*",},});
1.331 albertel 1489: my $end_page =
1490: &Apache::loncommon::end_page({'frameset' => 1,
1491: 'js_ready' => 1,});
1.436 albertel 1492: my $template .= <<"ENDTEMPLATE";
1493: <script type="text/javascript">
1.877 bisitz 1494: // <![CDATA[
1.253 albertel 1495: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1496: var banner_link = '';
1.243 raeburn 1497: function helpMenu(target) {
1498: var caller = this;
1499: if (target == 'open') {
1500: var newWindow = null;
1501: try {
1.262 albertel 1502: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1503: }
1504: catch(error) {
1505: writeHelp(caller);
1506: return;
1507: }
1508: if (newWindow) {
1509: caller = newWindow;
1510: }
1.193 raeburn 1511: }
1.243 raeburn 1512: writeHelp(caller);
1513: return;
1514: }
1515: function writeHelp(caller) {
1.1459 raeburn 1516: caller.document.writeln('$start_page\\n<frame name="bannerframe" title="$bannertitle" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1517: caller.document.writeln('<frame name="bodyframe" title="$bodytitle" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1.1168 raeburn 1518: caller.document.close();
1519: caller.focus();
1.193 raeburn 1520: }
1.877 bisitz 1521: // END LON-CAPA Internal -->
1.253 albertel 1522: // ]]>
1.436 albertel 1523: </script>
1.193 raeburn 1524: ENDTEMPLATE
1525: return $template;
1526: }
1527:
1.172 www 1528: sub help_open_bug {
1529: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1530: unless ($env{'user.adv'}) { return ''; }
1.172 www 1531: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1532: $text = "" if (not defined $text);
1533: $stayOnPage=1;
1.184 albertel 1534: $width = 600 if (not defined $width);
1535: $height = 600 if (not defined $height);
1.172 www 1536:
1537: $topic=~s/\W+/\+/g;
1538: my $link='';
1539: my $template='';
1.379 albertel 1540: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1541: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1542: if (!$stayOnPage)
1543: {
1544: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1545: }
1546: else
1547: {
1548: $link = $url;
1549: }
1.1314 raeburn 1550:
1.1382 raeburn 1551: my $target = '_top';
1552: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1553: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1554: $target = '_blank';
1.1378 raeburn 1555: }
1.1382 raeburn 1556:
1.172 www 1557: # Add the text
1558: if ($text ne "")
1559: {
1560: $template .=
1561: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1562: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1563: }
1564:
1565: # Add the graphic
1.179 matthew 1566: my $title = &mt('Report a Bug');
1.215 albertel 1567: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1568: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1569: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1570: ENDTEMPLATE
1571: if ($text ne '') { $template.='</td></tr></table>' };
1572: return $template;
1573:
1574: }
1575:
1576: sub help_open_faq {
1577: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1578: unless ($env{'user.adv'}) { return ''; }
1.172 www 1579: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1580: $text = "" if (not defined $text);
1581: $stayOnPage=1;
1582: $width = 350 if (not defined $width);
1583: $height = 400 if (not defined $height);
1584:
1585: $topic=~s/\W+/\+/g;
1586: my $link='';
1587: my $template='';
1588: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1589: if (!$stayOnPage)
1590: {
1591: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1592: }
1593: else
1594: {
1595: $link = $url;
1596: }
1597:
1598: # Add the text
1599: if ($text ne "")
1600: {
1601: $template .=
1.173 www 1602: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1603: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1604: }
1605:
1606: # Add the graphic
1.179 matthew 1607: my $title = &mt('View the FAQ');
1.215 albertel 1608: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1609: $template .= <<"ENDTEMPLATE";
1.436 albertel 1610: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1611: ENDTEMPLATE
1612: if ($text ne '') { $template.='</td></tr></table>' };
1613: return $template;
1614:
1.44 bowersj2 1615: }
1.37 matthew 1616:
1.180 matthew 1617: ###############################################################
1618: ###############################################################
1619:
1.45 matthew 1620: =pod
1621:
1.648 raeburn 1622: =item * &change_content_javascript():
1.256 matthew 1623:
1624: This and the next function allow you to create small sections of an
1625: otherwise static HTML page that you can update on the fly with
1626: Javascript, even in Netscape 4.
1627:
1628: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1629: must be written to the HTML page once. It will prove the Javascript
1630: function "change(name, content)". Calling the change function with the
1631: name of the section
1632: you want to update, matching the name passed to C<changable_area>, and
1633: the new content you want to put in there, will put the content into
1634: that area.
1635:
1636: B<Note>: Netscape 4 only reserves enough space for the changable area
1637: to contain room for the original contents. You need to "make space"
1638: for whatever changes you wish to make, and be B<sure> to check your
1639: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1640: it's adequate for updating a one-line status display, but little more.
1641: This script will set the space to 100% width, so you only need to
1642: worry about height in Netscape 4.
1643:
1644: Modern browsers are much less limiting, and if you can commit to the
1645: user not using Netscape 4, this feature may be used freely with
1646: pretty much any HTML.
1647:
1648: =cut
1649:
1650: sub change_content_javascript {
1651: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1652: if ($env{'browser.type'} eq 'netscape' &&
1653: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1654: return (<<NETSCAPE4);
1655: function change(name, content) {
1656: doc = document.layers[name+"___escape"].layers[0].document;
1657: doc.open();
1658: doc.write(content);
1659: doc.close();
1660: }
1661: NETSCAPE4
1662: } else {
1663: # Otherwise, we need to use semi-standards-compliant code
1664: # (technically, "innerHTML" isn't standard but the equivalent
1665: # is really scary, and every useful browser supports it
1666: return (<<DOMBASED);
1667: function change(name, content) {
1668: element = document.getElementById(name);
1669: element.innerHTML = content;
1670: }
1671: DOMBASED
1672: }
1673: }
1674:
1675: =pod
1676:
1.648 raeburn 1677: =item * &changable_area($name,$origContent):
1.256 matthew 1678:
1679: This provides a "changable area" that can be modified on the fly via
1680: the Javascript code provided in C<change_content_javascript>. $name is
1681: the name you will use to reference the area later; do not repeat the
1682: same name on a given HTML page more then once. $origContent is what
1683: the area will originally contain, which can be left blank.
1684:
1685: =cut
1686:
1687: sub changable_area {
1688: my ($name, $origContent) = @_;
1689:
1.258 albertel 1690: if ($env{'browser.type'} eq 'netscape' &&
1691: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1692: # If this is netscape 4, we need to use the Layer tag
1693: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1694: } else {
1695: return "<span id='$name'>$origContent</span>";
1696: }
1697: }
1698:
1699: =pod
1700:
1.648 raeburn 1701: =item * &viewport_geometry_js
1.590 raeburn 1702:
1703: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1704:
1705: =cut
1706:
1707:
1708: sub viewport_geometry_js {
1709: return <<"GEOMETRY";
1710: var Geometry = {};
1711: function init_geometry() {
1712: if (Geometry.init) { return };
1713: Geometry.init=1;
1714: if (window.innerHeight) {
1715: Geometry.getViewportHeight = function() { return window.innerHeight; };
1716: Geometry.getViewportWidth = function() { return window.innerWidth; };
1717: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1718: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1719: }
1720: else if (document.documentElement && document.documentElement.clientHeight) {
1721: Geometry.getViewportHeight =
1722: function() { return document.documentElement.clientHeight; };
1723: Geometry.getViewportWidth =
1724: function() { return document.documentElement.clientWidth; };
1725:
1726: Geometry.getHorizontalScroll =
1727: function() { return document.documentElement.scrollLeft; };
1728: Geometry.getVerticalScroll =
1729: function() { return document.documentElement.scrollTop; };
1730: }
1731: else if (document.body.clientHeight) {
1732: Geometry.getViewportHeight =
1733: function() { return document.body.clientHeight; };
1734: Geometry.getViewportWidth =
1735: function() { return document.body.clientWidth; };
1736: Geometry.getHorizontalScroll =
1737: function() { return document.body.scrollLeft; };
1738: Geometry.getVerticalScroll =
1739: function() { return document.body.scrollTop; };
1740: }
1741: }
1742:
1743: GEOMETRY
1744: }
1745:
1746: =pod
1747:
1.648 raeburn 1748: =item * &viewport_size_js()
1.590 raeburn 1749:
1750: 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.
1751:
1752: =cut
1753:
1754: sub viewport_size_js {
1755: my $geometry = &viewport_geometry_js();
1756: return <<"DIMS";
1757:
1758: $geometry
1759:
1760: function getViewportDims(width,height) {
1761: init_geometry();
1762: width.value = Geometry.getViewportWidth();
1763: height.value = Geometry.getViewportHeight();
1764: return;
1765: }
1766:
1767: DIMS
1768: }
1769:
1770: =pod
1771:
1.648 raeburn 1772: =item * &resize_textarea_js()
1.565 albertel 1773:
1774: emits the needed javascript to resize a textarea to be as big as possible
1775:
1776: creates a function resize_textrea that takes two IDs first should be
1777: the id of the element to resize, second should be the id of a div that
1778: surrounds everything that comes after the textarea, this routine needs
1779: to be attached to the <body> for the onload and onresize events.
1780:
1781: =cut
1782:
1783: sub resize_textarea_js {
1.590 raeburn 1784: my $geometry = &viewport_geometry_js();
1.565 albertel 1785: return <<"RESIZE";
1786: <script type="text/javascript">
1.824 bisitz 1787: // <![CDATA[
1.590 raeburn 1788: $geometry
1.565 albertel 1789:
1.588 albertel 1790: function getX(element) {
1791: var x = 0;
1792: while (element) {
1793: x += element.offsetLeft;
1794: element = element.offsetParent;
1795: }
1796: return x;
1797: }
1798: function getY(element) {
1799: var y = 0;
1800: while (element) {
1801: y += element.offsetTop;
1802: element = element.offsetParent;
1803: }
1804: return y;
1805: }
1806:
1807:
1.565 albertel 1808: function resize_textarea(textarea_id,bottom_id) {
1809: init_geometry();
1810: var textarea = document.getElementById(textarea_id);
1811: //alert(textarea);
1812:
1.588 albertel 1813: var textarea_top = getY(textarea);
1.565 albertel 1814: var textarea_height = textarea.offsetHeight;
1815: var bottom = document.getElementById(bottom_id);
1.588 albertel 1816: var bottom_top = getY(bottom);
1.565 albertel 1817: var bottom_height = bottom.offsetHeight;
1818: var window_height = Geometry.getViewportHeight();
1.588 albertel 1819: var fudge = 23;
1.565 albertel 1820: var new_height = window_height-fudge-textarea_top-bottom_height;
1821: if (new_height < 300) {
1822: new_height = 300;
1823: }
1824: textarea.style.height=new_height+'px';
1825: }
1.824 bisitz 1826: // ]]>
1.565 albertel 1827: </script>
1828: RESIZE
1829:
1830: }
1831:
1.1205 golterma 1832: sub colorfuleditor_js {
1.1248 raeburn 1833: my $browse_or_search;
1834: my $respath;
1835: my ($cnum,$cdom) = &crsauthor_url();
1836: if ($cnum) {
1837: $respath = "/res/$cdom/$cnum/";
1838: my %js_lt = &Apache::lonlocal::texthash(
1839: sunm => 'Sub-directory name',
1840: save => 'Save page to make this permanent',
1841: );
1842: &js_escape(\%js_lt);
1.1400 raeburn 1843: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1844: $browse_or_search = <<"END";
1845:
1.1400 raeburn 1846: $showfile_js
1847:
1.1248 raeburn 1848: function toggleChooser(form,element,titleid,only,search) {
1849: var disp = 'none';
1850: if (document.getElementById('chooser_'+element)) {
1851: var curr = document.getElementById('chooser_'+element).style.display;
1852: if (curr == 'none') {
1853: disp='inline';
1854: if (form.elements['chooser_'+element].length) {
1855: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1856: form.elements['chooser_'+element][i].checked = false;
1857: }
1858: }
1859: toggleResImport(form,element);
1860: }
1861: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1862: var dirsel = '';
1863: var filesel = '';
1864: if (document.getElementById('chooser_'+element+'_crsres')) {
1865: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1866: if (currcrsres == 'none') {
1867: dirsel = 'coursepath_'+element;
1868: var filesel = 'coursefile_'+element;
1869: var include;
1870: if (document.getElementById('crsres_include_'+element)) {
1871: include = document.getElementById('crsres_include_'+element).value;
1872: }
1.1402 raeburn 1873: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 1874: }
1875: }
1876: if (document.getElementById('chooser_'+element+'_upload')) {
1877: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1878: if (currcrsupload == 'none') {
1879: dirsel = 'crsauthorpath_'+element;
1880: filesel = '';
1.1402 raeburn 1881: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 1882: }
1883: }
1.1248 raeburn 1884: }
1885: }
1886:
1.1400 raeburn 1887: function toggleCrsFile(form,element) {
1.1248 raeburn 1888: if (document.getElementById('chooser_'+element+'_crsres')) {
1889: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1890: if (curr == 'none') {
1.1400 raeburn 1891: if (document.getElementById('coursepath_'+element)) {
1892: var numdirs;
1893: if (document.getElementById('coursepath_'+element).length) {
1894: numdirs = document.getElementById('coursepath_'+element).length;
1895: }
1.1402 raeburn 1896: if ((document.getElementById('hascrsres_'+element)) &&
1897: (document.getElementById('nocrsres_'+element))) {
1898: if (numdirs) {
1899: document.getElementById('hascrsres_'+element).style.display='inline-block';
1900: document.getElementById('nocrsres_'+element).style.display='none';
1901: } else {
1902: document.getElementById('hascrsres_'+element).style.display='none';
1903: document.getElementById('nocrsres_'+element).style.display='inline-block';
1904: }
1905: }
1.1248 raeburn 1906: form.elements['coursepath_'+element].selectedIndex = 0;
1907: if (numdirs > 1) {
1.1400 raeburn 1908: var selelem = form.elements['coursefile_'+element];
1909: var i, len = selelem.options.length -1;
1910: if (len >=0) {
1911: for (i = len; i >= 0; i--) {
1912: selelem.remove(i);
1913: }
1914: selelem.options[0] = new Option('','');
1915: }
1.1248 raeburn 1916: }
1917: }
1.1400 raeburn 1918: }
1.1248 raeburn 1919: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1920: }
1921: if (document.getElementById('chooser_'+element+'_upload')) {
1922: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1923: if (document.getElementById('uploadcrsres_'+element)) {
1924: document.getElementById('uploadcrsres_'+element).value = '';
1925: }
1926: }
1927: return;
1928: }
1929:
1.1400 raeburn 1930: function toggleCrsUpload(form,element) {
1.1248 raeburn 1931: if (document.getElementById('chooser_'+element+'_crsres')) {
1932: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1933: }
1934: if (document.getElementById('chooser_'+element+'_upload')) {
1935: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1936: if (curr == 'none') {
1.1400 raeburn 1937: form.elements['newsubdir_'+element][0].checked = true;
1938: toggleNewsubdir(form,element);
1939: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1940: if (document.getElementById('uploadcrsres_'+element)) {
1941: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1942: }
1943: }
1944: }
1945: return;
1946: }
1947:
1948: function toggleResImport(form,element) {
1949: var choices = new Array('crsres','upload');
1950: for (var i=0; i<choices.length; i++) {
1951: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1952: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1953: }
1954: }
1955: }
1956:
1957: function toggleNewsubdir(form,element) {
1958: var newsub = form.elements['newsubdir_'+element];
1959: if (newsub) {
1960: if (newsub.length) {
1961: for (var j=0; j<newsub.length; j++) {
1962: if (newsub[j].checked) {
1963: if (document.getElementById('newsubdirname_'+element)) {
1964: if (newsub[j].value == '1') {
1965: document.getElementById('newsubdirname_'+element).type = "text";
1966: if (document.getElementById('newsubdir_'+element)) {
1967: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1968: }
1969: } else {
1970: document.getElementById('newsubdirname_'+element).type = "hidden";
1971: document.getElementById('newsubdirname_'+element).value = "";
1972: document.getElementById('newsubdir_'+element).innerHTML = "";
1973: }
1974: }
1975: break;
1976: }
1977: }
1978: }
1979: }
1980: }
1981:
1982: function updateCrsFile(form,element) {
1983: var directory = form.elements['coursepath_'+element];
1984: var filename = form.elements['coursefile_'+element];
1985: var path = directory.options[directory.selectedIndex].value;
1986: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1987: if (file != '') {
1988: form.elements[element].value = '$respath';
1989: if (path == '/') {
1990: form.elements[element].value += file;
1991: } else {
1992: form.elements[element].value += path+'/'+file;
1993: }
1994: unClean();
1995: if (document.getElementById('previewimg_'+element)) {
1996: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1997: var newsrc = document.getElementById('previewimg_'+element).src;
1998: }
1999: if (document.getElementById('showimg_'+element)) {
2000: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
2001: }
1.1248 raeburn 2002: }
2003: toggleChooser(form,element);
2004: return;
2005: }
2006:
2007: function uploadDone(suffix,name) {
2008: if (name) {
2009: document.forms["lonhomework"].elements[suffix].value = name;
2010: unClean();
2011: toggleChooser(document.forms["lonhomework"],suffix);
2012: }
2013: }
2014:
2015: \$(document).ready(function(){
2016:
2017: \$(document).delegate('form :submit', 'click', function( event ) {
2018: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2019: var buttonId = this.id;
2020: var suffix = buttonId.toString();
2021: suffix = suffix.replace(/^crsupload_/,'');
2022: event.preventDefault();
2023: document.lonhomework.target = 'crsupload_target_'+suffix;
2024: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2025: \$(this.form).submit();
2026: document.lonhomework.target = '';
2027: if (document.getElementById('crsuploadto_'+suffix)) {
2028: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2029: }
2030: return false;
2031: }
2032: });
2033: });
2034: END
2035: }
1.1205 golterma 2036: return <<"COLORFULEDIT"
2037: <script type="text/javascript">
2038: // <![CDATA[>
2039: function fold_box(curDepth, lastresource){
2040:
2041: // we need a list because there can be several blocks you need to fold in one tag
2042: var block = document.getElementsByName('foldblock_'+curDepth);
2043: // but there is only one folding button per tag
2044: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2045:
2046: if(block.item(0).style.display == 'none'){
2047:
2048: foldbutton.value = '@{[&mt("Hide")]}';
2049: for (i = 0; i < block.length; i++){
2050: block.item(i).style.display = '';
2051: }
2052: }else{
2053:
2054: foldbutton.value = '@{[&mt("Show")]}';
2055: for (i = 0; i < block.length; i++){
2056: // block.item(i).style.visibility = 'collapse';
2057: block.item(i).style.display = 'none';
2058: }
2059: };
2060: saveState(lastresource);
2061: }
2062:
2063: function saveState (lastresource) {
2064:
2065: var tag_list = getTagList();
2066: if(tag_list != null){
2067: var timestamp = new Date().getTime();
2068: var key = lastresource;
2069:
2070: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2071: // starting with timestamp
2072: var value = timestamp+';';
2073:
2074: // building the list of key-value pairs
2075: for(var i = 0; i < tag_list.length; i++){
2076: value += tag_list[i]+',';
2077: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2078: }
2079:
2080: // only iterate whole storage if nothing to override
2081: if(localStorage.getItem(key) == null){
2082:
2083: // prevent storage from growing large
2084: if(localStorage.length > 50){
2085: var regex_getTimestamp = /^(?:\d)+;/;
2086: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2087: var oldest_key;
2088:
2089: for(var i = 1; i < localStorage.length; i++){
2090: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2091: oldest_key = localStorage.key(i);
2092: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2093: }
2094: }
2095: localStorage.removeItem(oldest_key);
2096: }
2097: }
2098: localStorage.setItem(key,value);
2099: }
2100: }
2101:
2102: // restore folding status of blocks (on page load)
2103: function restoreState (lastresource) {
2104: if(localStorage.getItem(lastresource) != null){
2105: var key = lastresource;
2106: var value = localStorage.getItem(key);
2107: var regex_delTimestamp = /^\d+;/;
2108:
2109: value.replace(regex_delTimestamp, '');
2110:
2111: var valueArr = value.split(';');
2112: var pairs;
2113: var elements;
2114: for (var i = 0; i < valueArr.length; i++){
2115: pairs = valueArr[i].split(',');
2116: elements = document.getElementsByName(pairs[0]);
2117:
2118: for (var j = 0; j < elements.length; j++){
2119: elements[j].style.display = pairs[1];
2120: if (pairs[1] == "none"){
2121: var regex_id = /([_\\d]+)\$/;
2122: regex_id.exec(pairs[0]);
2123: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2124: }
2125: }
2126: }
2127: }
2128: }
2129:
2130: function getTagList () {
2131:
2132: var stringToSearch = document.lonhomework.innerHTML;
2133:
2134: var ret = new Array();
2135: var regex_findBlock = /(foldblock_.*?)"/g;
2136: var tag_list = stringToSearch.match(regex_findBlock);
2137:
2138: if(tag_list != null){
2139: for(var i = 0; i < tag_list.length; i++){
2140: ret.push(tag_list[i].replace(/"/, ''));
2141: }
2142: }
2143: return ret;
2144: }
2145:
2146: function saveScrollPosition (resource) {
2147: var tag_list = getTagList();
2148:
2149: // we dont always want to jump to the first block
2150: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2151: if(\$(window).scrollTop() > 170){
2152: if(tag_list != null){
2153: var result;
2154: for(var i = 0; i < tag_list.length; i++){
2155: if(isElementInViewport(tag_list[i])){
2156: result += tag_list[i]+';';
2157: }
2158: }
2159: sessionStorage.setItem('anchor_'+resource, result);
2160: }
2161: } else {
2162: // we dont need to save zero, just delete the item to leave everything tidy
2163: sessionStorage.removeItem('anchor_'+resource);
2164: }
2165: }
2166:
2167: function restoreScrollPosition(resource){
2168:
2169: var elem = sessionStorage.getItem('anchor_'+resource);
2170: if(elem != null){
2171: var tag_list = elem.split(';');
2172: var elem_list;
2173:
2174: for(var i = 0; i < tag_list.length; i++){
2175: elem_list = document.getElementsByName(tag_list[i]);
2176:
2177: if(elem_list.length > 0){
2178: elem = elem_list[0];
2179: break;
2180: }
2181: }
2182: elem.scrollIntoView();
2183: }
2184: }
2185:
2186: function isElementInViewport(el) {
2187:
2188: // change to last element instead of first
2189: var elem = document.getElementsByName(el);
2190: var rect = elem[0].getBoundingClientRect();
2191:
2192: return (
2193: rect.top >= 0 &&
2194: rect.left >= 0 &&
2195: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2196: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2197: );
2198: }
2199:
2200: function autosize(depth){
2201: var cmInst = window['cm'+depth];
2202: var fitsizeButton = document.getElementById('fitsize'+depth);
2203:
2204: // is fixed size, switching to dynamic
2205: if (sessionStorage.getItem("autosized_"+depth) == null) {
2206: cmInst.setSize("","auto");
2207: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2208: sessionStorage.setItem("autosized_"+depth, "yes");
2209:
2210: // is dynamic size, switching to fixed
2211: } else {
2212: cmInst.setSize("","300px");
2213: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2214: sessionStorage.removeItem("autosized_"+depth);
2215: }
2216: }
2217:
1.1248 raeburn 2218: $browse_or_search
1.1205 golterma 2219:
2220: // ]]>
2221: </script>
2222: COLORFULEDIT
2223: }
2224:
2225: sub xmleditor_js {
2226: return <<XMLEDIT
2227: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2228: <script type="text/javascript">
2229: // <![CDATA[>
2230:
2231: function saveScrollPosition (resource) {
2232:
2233: var scrollPos = \$(window).scrollTop();
2234: sessionStorage.setItem(resource,scrollPos);
2235: }
2236:
2237: function restoreScrollPosition(resource){
2238:
2239: var scrollPos = sessionStorage.getItem(resource);
2240: \$(window).scrollTop(scrollPos);
2241: }
2242:
2243: // unless internet explorer
2244: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2245:
2246: \$(document).ready(function() {
2247: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2248: });
2249: }
2250:
2251: // inserts text at cursor position into codemirror (xml editor only)
2252: function insertText(text){
2253: cm.focus();
2254: var curPos = cm.getCursor();
2255: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2256: }
2257: // ]]>
2258: </script>
2259: XMLEDIT
2260: }
2261:
2262: sub insert_folding_button {
2263: my $curDepth = $Apache::lonxml::curdepth;
2264: my $lastresource = $env{'request.ambiguous'};
2265:
2266: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2267: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2268: }
2269:
1.1248 raeburn 2270: sub crsauthor_url {
2271: my ($url) = @_;
2272: if ($url eq '') {
2273: $url = $ENV{'REQUEST_URI'};
2274: }
2275: my ($cnum,$cdom);
2276: if ($env{'request.course.id'}) {
2277: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2278: if ($audom ne '' && $auname ne '') {
2279: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2280: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2281: $cnum = $auname;
2282: $cdom = $audom;
2283: }
2284: }
2285: }
2286: return ($cnum,$cdom);
2287: }
2288:
2289: sub import_crsauthor_form {
1.1400 raeburn 2290: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2291: return (0) unless ($env{'request.course.id'});
2292: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2293: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2294: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2295: return (0) unless (($cnum ne '') && ($cdom ne ''));
2296: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2297: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2298:
1.1248 raeburn 2299: if (grep(/^\Q$crshome\E$/,@ids)) {
2300: $is_home = 1;
2301: }
1.1400 raeburn 2302: $toppath = "/priv/$cdom/$cnum";
2303: my $nonemptydir = 1;
2304: my $js_only;
2305: if ($only) {
2306: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2307: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2308: }
2309: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2310: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2311: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2312: my %lt = &Apache::lonlocal::texthash (
2313: fnam => 'Filename',
2314: dire => 'Directory',
1.1400 raeburn 2315: se => 'Select',
1.1248 raeburn 2316: );
1.1450 raeburn 2317: $output = '<label>'.$lt{'dire'}.': '.
1.1400 raeburn 2318: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2319: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2320: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2321: if ($files{'/'}) {
2322: $output .= '<option value="/">/</option>'."\n";
2323: }
1.1400 raeburn 2324: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2325: next if ($key eq '/');
1.1400 raeburn 2326: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2327: }
1.1450 raeburn 2328: $output .= '</select></label><br /><label>'."\n".
1.1402 raeburn 2329: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2330: '<option value="" selected="selected"></option>'."\n".
1.1450 raeburn 2331: '</select></label>'."\n".
1.1402 raeburn 2332: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2333: return ($numdirs,$output);
2334: }
2335:
2336: sub show_crsfiles_js {
2337: my $excluderef = &Apache::lonnet::priv_exclude();
2338: my $se = &js_escape(&mt('Select'));
2339: my $exclude;
2340: if (ref($excluderef) eq 'HASH') {
2341: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2342: }
2343: my $js = <<"END";
2344:
2345:
1.1402 raeburn 2346: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2347: var relpath = '';
2348: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2349: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2350: if (currdir == '') {
2351: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2352: selelem = form.elements[filesel];
2353: var j, numfiles = selelem.options.length -1;
2354: if (numfiles >=0) {
2355: for (j = numfiles; j >= 0; j--) {
2356: selelem.remove(j);
2357: }
2358: }
2359: if (selelem.options.length == 0) {
2360: selelem.options[selelem.options.length] = new Option('','');
2361: selelem.selectedIndex = 0;
1.1248 raeburn 2362: }
2363: }
1.1400 raeburn 2364: return;
2365: } else {
2366: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2367: }
2368: }
1.1400 raeburn 2369: var http = new XMLHttpRequest();
2370: var url = "/adm/courseauthor";
2371: var crsrole = "$env{'request.role'}";
2372: var exclude = '';
2373: if (exc) {
2374: exclude = '$exclude';
2375: }
1.1402 raeburn 2376: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2377: http.open("POST", url, true);
2378: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2379: http.onreadystatechange = function() {
2380: if (http.readyState == 4 && http.status == 200) {
2381: var data = JSON.parse(http.responseText);
2382: var selelem;
2383: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2384: if (Array.isArray(data.dirs)) {
2385: selelem = form.elements[dirsel];
2386: var i, numdirs = selelem.options.length -1;
2387: if (numdirs >=0) {
2388: for (i = numdirs; i >= 0; i--) {
2389: selelem.remove(i);
2390: }
2391: }
2392: var len = data.dirs.length;
2393: if (len) {
1.1402 raeburn 2394: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2395: var j;
2396: for (j = 0; j < len; j++) {
2397: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2398: }
2399: selelem.selectedIndex = 0;
2400: }
2401: if (!setfile) {
2402: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2403: selelem = form.elements[filesel];
2404: var j, numfiles = selelem.options.length -1;
2405: if (numfiles >=0) {
2406: for (j = numfiles; j >= 0; j--) {
2407: selelem.remove(j);
2408: }
2409: }
2410: if (selelem.options.length == 0) {
2411: selelem.options[selelem.options.length] = new Option('','');
2412: selelem.selectedIndex = 0;
2413: }
2414: }
2415: }
2416: }
2417: }
2418: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2419: selelem = form.elements[filesel];
2420: var i, numfiles = selelem.options.length -1;
2421: if (numfiles >=0) {
2422: for (i = numfiles; i >= 0; i--) {
2423: selelem.remove(i);
2424: }
2425: }
2426: var x;
2427: for (x in data.files) {
2428: if (Array.isArray(data.files[x])) {
2429: if (data.files[x].length > 1) {
2430: selelem.options[selelem.options.length] = new Option('$se','');
2431: }
2432: var len = data.files[x].length;
2433: if (len) {
2434: var k;
2435: for (k = 0; k < len; k++) {
2436: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2437: }
2438: selelem.selectedIndex = 0;
2439: }
2440: }
2441: }
2442: if (selelem.options.length == 0) {
2443: selelem.options[selelem.options.length] = new Option('','');
2444: selelem.selectedIndex = 0;
2445: }
1.1248 raeburn 2446: }
2447: }
2448: }
1.1400 raeburn 2449: http.send(params);
1.1248 raeburn 2450: }
1.1400 raeburn 2451: END
1.1248 raeburn 2452: }
2453:
1.1426 raeburn 2454: sub crsauthor_rights {
2455: my ($rightsfile,$path,$docroot,$cnum,$cdom) = @_;
2456: my $sourcerights = "$path/$rightsfile";
2457: my $now = time;
2458: if (!-e $sourcerights) {
2459: my $cid = $cdom.'_'.$cnum;
2460: if (!-e "$docroot/priv/$cdom") {
2461: mkdir("$docroot/priv/$cdom",0755);
2462: }
2463: if (!-e "$docroot/priv/$cdom/$cnum") {
2464: mkdir("$docroot/priv/$cdom/$cnum",0755);
2465: }
2466: if (open(my $fh,">$sourcerights")) {
2467: print $fh <<END;
2468: <accessrule effect="deny" realm="" type="course" role="" />
2469: <accessrule effect="allow" realm="$cid" type="course" role="" />
2470: END
2471: close($fh);
2472: }
2473: }
2474: if (!-e "$sourcerights.meta") {
2475: if (open(my $fh,">$sourcerights.meta")) {
2476: my $author=$env{'environment.firstname'}.' '.
2477: $env{'environment.middlename'}.' '.
2478: $env{'environment.lastname'}.' '.
2479: $env{'environment.generation'};
2480: $author =~ s/\s+$//;
2481: print $fh <<"END";
2482:
2483: <abstract></abstract>
2484: <author>$author</author>
2485: <authorspace>$cnum:$cdom</authorspace>
2486: <copyright>private</copyright>
2487: <creationdate>$now</creationdate>
2488: <customdistributionfile></customdistributionfile>
2489: <dependencies></dependencies>
2490: <domain>$cdom</domain>
2491: <highestgradelevel>0</highestgradelevel>
2492: <keywords></keywords>
1.1445 raeburn 2493: <language>notset</language>
1.1426 raeburn 2494: <lastrevisiondate>$now</lastrevisiondate>
2495: <lowestgradelevel>0</lowestgradelevel>
2496: <mime>rights</mime>
2497: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
2498: <notes></notes>
2499: <obsolete></obsolete>
2500: <obsoletereplacement></obsoletereplacement>
2501: <owner>$cnum:$cdom</owner>
2502: <rule>deny:::course,allow:$cid::course</rule>
2503: <sourceavail></sourceavail>
2504: <standards></standards>
2505: <subject></subject>
2506: <title>Course Authoring Rights</title>
2507: END
2508: close($fh);
2509: }
2510: }
2511: return;
2512: }
2513:
1.565 albertel 2514: =pod
2515:
1.1420 raeburn 2516: =item * &iframe_wrapper_headjs()
2517:
1.1425 raeburn 2518: emits javascript containing two global vars to facilitate handling of resizing
2519: by code in iframe_wrapper_resizejs() used when an iframe is present in a page
2520: with standard LON-CAPA menus.
2521:
2522: =cut
2523:
1.1420 raeburn 2524: #
2525: # Where iframe is in use, if window.onload() executes before the custom resize function
2526: # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
2527: # are used to ensure document.ready() triggers a call to resize, so the iframe contents
2528: # do not obscure the Functions menu.
2529: #
2530:
2531: sub iframe_wrapper_headjs {
2532: return <<"ENDJS";
2533: <script type="text/javascript">
2534: // <![CDATA[
2535: var LCnotready = 0;
2536: var LCresizedef = 0;
2537: // ]]>
2538: </script>
2539:
2540: ENDJS
2541:
2542: }
2543:
2544: =pod
2545:
2546: =item * &iframe_wrapper_resizejs()
2547:
1.1425 raeburn 2548: emits javascript used to handle resizing for a page containing
2549: an iframe, to ensure that the iframe does not obscure any
2550: standard LON-CAPA menu items.
2551:
2552: =back
2553:
2554: =cut
2555:
1.1420 raeburn 2556: #
2557: # jQuery to use when iframe is in use and a page resize occurs.
2558: # This script will ensure that the iframe does not obscure any
2559: # standard LON-CAPA inline menus (primary, secondary, and/or
2560: # breadcrumbs and Functions menus. Expects javascript from
2561: # &iframe_wrapper_headjs() to be in head portion of the web page,
2562: # e.g., by inclusion in second arg passed to &start_page().
2563: #
2564:
2565: sub iframe_wrapper_resizejs {
2566: my $offset = 5;
2567: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
2568: if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
2569: $offset = 0;
2570: }
2571: return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
2572: \$(document).ready( function() {
2573: \$(window).unbind('resize').resize(function(){
2574: var header = null;
2575: var offset = $offset;
2576: var height = 0;
2577: var hdrtop = 0;
1.1421 raeburn 2578: if (\$('div.LC_menus_content:first').length) {
2579: if (\$('div.LC_menus_content:first').hasClass ("shown")) {
2580: header = \$('div.LC_menus_content:first');
1.1423 raeburn 2581: offset = 12;
1.1421 raeburn 2582: }
2583: } else if (\$('div.LC_head_subbox:first').length) {
1.1420 raeburn 2584: header = \$('div.LC_head_subbox:first');
2585: offset = 9;
2586: } else {
2587: if (\$('#LC_breadcrumbs').length) {
2588: header = \$('#LC_breadcrumbs');
2589: }
2590: }
2591: if (header != null && header.length) {
2592: height = header.height();
2593: hdrtop = header.position().top;
2594: }
2595: var pos = height + hdrtop + offset;
2596: \$('.LC_iframecontainer').css('top', pos);
2597: });
2598: LCresizedef = 1;
2599: if (LCnotready == 1) {
2600: LCnotready = 0;
2601: \$(window).trigger('resize');
2602: }
2603: });
2604: window.onload = function(){
2605: if (LCresizedef) {
2606: LCnotready = 0;
2607: \$(window).trigger('resize');
2608: } else {
2609: LCnotready = 1;
2610: }
2611: };
2612: SCRIPT
2613:
2614: }
2615:
2616: =pod
2617:
1.256 matthew 2618: =head1 Excel and CSV file utility routines
2619:
2620: =cut
2621:
2622: ###############################################################
2623: ###############################################################
2624:
2625: =pod
2626:
1.1162 raeburn 2627: =over 4
2628:
1.648 raeburn 2629: =item * &csv_translate($text)
1.37 matthew 2630:
1.185 www 2631: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2632: format.
2633:
2634: =cut
2635:
1.180 matthew 2636: ###############################################################
2637: ###############################################################
1.37 matthew 2638: sub csv_translate {
2639: my $text = shift;
2640: $text =~ s/\"/\"\"/g;
1.209 albertel 2641: $text =~ s/\n/ /g;
1.37 matthew 2642: return $text;
2643: }
1.180 matthew 2644:
2645: ###############################################################
2646: ###############################################################
2647:
2648: =pod
2649:
1.648 raeburn 2650: =item * &define_excel_formats()
1.180 matthew 2651:
2652: Define some commonly used Excel cell formats.
2653:
2654: Currently supported formats:
2655:
2656: =over 4
2657:
2658: =item header
2659:
2660: =item bold
2661:
2662: =item h1
2663:
2664: =item h2
2665:
2666: =item h3
2667:
1.256 matthew 2668: =item h4
2669:
2670: =item i
2671:
1.180 matthew 2672: =item date
2673:
2674: =back
2675:
2676: Inputs: $workbook
2677:
2678: Returns: $format, a hash reference.
2679:
1.1057 foxr 2680:
1.180 matthew 2681: =cut
2682:
2683: ###############################################################
2684: ###############################################################
2685: sub define_excel_formats {
2686: my ($workbook) = @_;
2687: my $format;
2688: $format->{'header'} = $workbook->add_format(bold => 1,
2689: bottom => 1,
2690: align => 'center');
2691: $format->{'bold'} = $workbook->add_format(bold=>1);
2692: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2693: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2694: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2695: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2696: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2697: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2698: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2699: return $format;
2700: }
2701:
2702: ###############################################################
2703: ###############################################################
1.113 bowersj2 2704:
2705: =pod
2706:
1.648 raeburn 2707: =item * &create_workbook()
1.255 matthew 2708:
2709: Create an Excel worksheet. If it fails, output message on the
2710: request object and return undefs.
2711:
2712: Inputs: Apache request object
2713:
2714: Returns (undef) on failure,
2715: Excel worksheet object, scalar with filename, and formats
2716: from &Apache::loncommon::define_excel_formats on success
2717:
2718: =cut
2719:
2720: ###############################################################
2721: ###############################################################
2722: sub create_workbook {
2723: my ($r) = @_;
2724: #
2725: # Create the excel spreadsheet
2726: my $filename = '/prtspool/'.
1.258 albertel 2727: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2728: time.'_'.rand(1000000000).'.xls';
2729: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2730: if (! defined($workbook)) {
2731: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2732: $r->print(
2733: '<p class="LC_error">'
2734: .&mt('Problems occurred in creating the new Excel file.')
2735: .' '.&mt('This error has been logged.')
2736: .' '.&mt('Please alert your LON-CAPA administrator.')
2737: .'</p>'
2738: );
1.255 matthew 2739: return (undef);
2740: }
2741: #
1.1014 foxr 2742: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2743: #
2744: my $format = &Apache::loncommon::define_excel_formats($workbook);
2745: return ($workbook,$filename,$format);
2746: }
2747:
2748: ###############################################################
2749: ###############################################################
2750:
2751: =pod
2752:
1.648 raeburn 2753: =item * &create_text_file()
1.113 bowersj2 2754:
1.542 raeburn 2755: Create a file to write to and eventually make available to the user.
1.256 matthew 2756: If file creation fails, outputs an error message on the request object and
2757: return undefs.
1.113 bowersj2 2758:
1.256 matthew 2759: Inputs: Apache request object, and file suffix
1.113 bowersj2 2760:
1.256 matthew 2761: Returns (undef) on failure,
2762: Filehandle and filename on success.
1.113 bowersj2 2763:
2764: =cut
2765:
1.256 matthew 2766: ###############################################################
2767: ###############################################################
2768: sub create_text_file {
2769: my ($r,$suffix) = @_;
2770: if (! defined($suffix)) { $suffix = 'txt'; };
2771: my $fh;
2772: my $filename = '/prtspool/'.
1.258 albertel 2773: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2774: time.'_'.rand(1000000000).'.'.$suffix;
2775: $fh = Apache::File->new('>/home/httpd'.$filename);
2776: if (! defined($fh)) {
2777: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2778: $r->print(
2779: '<p class="LC_error">'
2780: .&mt('Problems occurred in creating the output file.')
2781: .' '.&mt('This error has been logged.')
2782: .' '.&mt('Please alert your LON-CAPA administrator.')
2783: .'</p>'
2784: );
1.113 bowersj2 2785: }
1.256 matthew 2786: return ($fh,$filename)
1.113 bowersj2 2787: }
2788:
2789:
1.256 matthew 2790: =pod
1.113 bowersj2 2791:
2792: =back
2793:
2794: =cut
1.37 matthew 2795:
2796: ###############################################################
1.33 matthew 2797: ## Home server <option> list generating code ##
2798: ###############################################################
1.35 matthew 2799:
1.169 www 2800: # ------------------------------------------
2801:
2802: sub domain_select {
1.1289 raeburn 2803: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2804: my @possdoms;
2805: if (ref($incdoms) eq 'ARRAY') {
2806: @possdoms = @{$incdoms};
2807: } else {
2808: @possdoms = &Apache::lonnet::all_domains();
2809: }
2810:
1.169 www 2811: my %domains=map {
1.514 albertel 2812: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2813: } @possdoms;
2814:
2815: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2816: foreach my $dom (@{$excdoms}) {
2817: delete($domains{$dom});
2818: }
2819: }
2820:
1.169 www 2821: if ($multiple) {
2822: $domains{''}=&mt('Any domain');
1.550 albertel 2823: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2824: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2825: } else {
1.550 albertel 2826: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2827: return &select_form($name,$value,\%domains);
1.169 www 2828: }
2829: }
2830:
1.282 albertel 2831: #-------------------------------------------
2832:
2833: =pod
2834:
1.519 raeburn 2835: =head1 Routines for form select boxes
2836:
2837: =over 4
2838:
1.648 raeburn 2839: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2840:
2841: Returns a string containing a <select> element int multiple mode
2842:
2843:
2844: Args:
2845: $name - name of the <select> element
1.506 raeburn 2846: $value - scalar or array ref of values that should already be selected
1.282 albertel 2847: $size - number of rows long the select element is
1.283 albertel 2848: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2849: (shown text should already have been &mt())
1.506 raeburn 2850: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2851:
1.282 albertel 2852: =cut
2853:
2854: #-------------------------------------------
1.169 www 2855: sub multiple_select_form {
1.284 albertel 2856: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2857: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2858: my $output='';
1.191 matthew 2859: if (! defined($size)) {
2860: $size = 4;
1.283 albertel 2861: if (scalar(keys(%$hash))<4) {
2862: $size = scalar(keys(%$hash));
1.191 matthew 2863: }
2864: }
1.734 bisitz 2865: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2866: my @order;
1.506 raeburn 2867: if (ref($order) eq 'ARRAY') {
2868: @order = @{$order};
2869: } else {
2870: @order = sort(keys(%$hash));
1.501 banghart 2871: }
2872: if (exists($$hash{'select_form_order'})) {
2873: @order = @{$$hash{'select_form_order'}};
2874: }
2875:
1.284 albertel 2876: foreach my $key (@order) {
1.356 albertel 2877: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2878: $output.='selected="selected" ' if ($selected{$key});
2879: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2880: }
2881: $output.="</select>\n";
2882: return $output;
2883: }
2884:
1.88 www 2885: #-------------------------------------------
2886:
2887: =pod
2888:
1.1254 raeburn 2889: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2890:
2891: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2892: allow a user to select options from a ref to a hash containing:
2893: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2894: a javascript onchange item, e.g., onchange="this.form.submit();".
2895: An optional arg -- $readonly -- if true will cause the select form
2896: to be disabled, e.g., for the case where an instructor has a section-
2897: specific role, and is viewing/modifying parameters.
1.970 raeburn 2898:
1.88 www 2899: See lonrights.pm for an example invocation and use.
2900:
2901: =cut
2902:
2903: #-------------------------------------------
2904: sub select_form {
1.1228 raeburn 2905: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2906: return unless (ref($hashref) eq 'HASH');
2907: if ($onchange) {
2908: $onchange = ' onchange="'.$onchange.'"';
2909: }
1.1228 raeburn 2910: my $disabled;
2911: if ($readonly) {
2912: $disabled = ' disabled="disabled"';
2913: }
2914: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2915: my @keys;
1.970 raeburn 2916: if (exists($hashref->{'select_form_order'})) {
2917: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2918: } else {
1.970 raeburn 2919: @keys=sort(keys(%{$hashref}));
1.128 albertel 2920: }
1.356 albertel 2921: foreach my $key (@keys) {
2922: $selectform.=
2923: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2924: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2925: ">".$hashref->{$key}."</option>\n";
1.88 www 2926: }
2927: $selectform.="</select>";
2928: return $selectform;
2929: }
2930:
1.475 www 2931: # For display filters
2932:
2933: sub display_filter {
1.1074 raeburn 2934: my ($context) = @_;
1.475 www 2935: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2936: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2937: my $phraseinput = 'hidden';
2938: my $includeinput = 'hidden';
2939: my ($checked,$includetypestext);
2940: if ($env{'form.displayfilter'} eq 'containing') {
2941: $phraseinput = 'text';
2942: if ($context eq 'parmslog') {
2943: $includeinput = 'checkbox';
2944: if ($env{'form.includetypes'}) {
2945: $checked = ' checked="checked"';
2946: }
2947: $includetypestext = &mt('Include parameter types');
2948: }
2949: } else {
2950: $includetypestext = ' ';
2951: }
2952: my ($additional,$secondid,$thirdid);
2953: if ($context eq 'parmslog') {
2954: $additional =
2955: '<label><input type="'.$includeinput.'" name="includetypes"'.
2956: $checked.' name="includetypes" value="1" id="includetypes" />'.
2957: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2958: '</label>';
2959: $secondid = 'includetypes';
2960: $thirdid = 'includetypestext';
2961: }
2962: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2963: '$secondid','$thirdid')";
2964: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2965: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2966: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2967: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2968: &mt('Filter: [_1]',
1.477 www 2969: &select_form($env{'form.displayfilter'},
2970: 'displayfilter',
1.970 raeburn 2971: {'currentfolder' => 'Current folder/page',
1.477 www 2972: 'containing' => 'Containing phrase',
1.1074 raeburn 2973: 'none' => 'None'},$onchange)).' '.
2974: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2975: &HTML::Entities::encode($env{'form.containingphrase'}).
2976: '" />'.$additional;
2977: }
2978:
2979: sub display_filter_js {
2980: my $includetext = &mt('Include parameter types');
2981: return <<"ENDJS";
2982:
2983: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2984: var firstType = 'hidden';
2985: if (setter.options[setter.selectedIndex].value == 'containing') {
2986: firstType = 'text';
2987: }
2988: firstObject = document.getElementById(firstid);
2989: if (typeof(firstObject) == 'object') {
2990: if (firstObject.type != firstType) {
2991: changeInputType(firstObject,firstType);
2992: }
2993: }
2994: if (context == 'parmslog') {
2995: var secondType = 'hidden';
2996: if (firstType == 'text') {
2997: secondType = 'checkbox';
2998: }
2999: secondObject = document.getElementById(secondid);
3000: if (typeof(secondObject) == 'object') {
3001: if (secondObject.type != secondType) {
3002: changeInputType(secondObject,secondType);
3003: }
3004: }
3005: var textItem = document.getElementById(thirdid);
3006: var currtext = textItem.innerHTML;
3007: var newtext;
3008: if (firstType == 'text') {
3009: newtext = '$includetext';
3010: } else {
3011: newtext = ' ';
3012: }
3013: if (currtext != newtext) {
3014: textItem.innerHTML = newtext;
3015: }
3016: }
3017: return;
3018: }
3019:
3020: function changeInputType(oldObject,newType) {
3021: var newObject = document.createElement('input');
3022: newObject.type = newType;
3023: if (oldObject.size) {
3024: newObject.size = oldObject.size;
3025: }
3026: if (oldObject.value) {
3027: newObject.value = oldObject.value;
3028: }
3029: if (oldObject.name) {
3030: newObject.name = oldObject.name;
3031: }
3032: if (oldObject.id) {
3033: newObject.id = oldObject.id;
3034: }
3035: oldObject.parentNode.replaceChild(newObject,oldObject);
3036: return;
3037: }
3038:
3039: ENDJS
1.475 www 3040: }
3041:
1.167 www 3042: sub gradeleveldescription {
3043: my $gradelevel=shift;
3044: my %gradelevels=(0 => 'Not specified',
3045: 1 => 'Grade 1',
3046: 2 => 'Grade 2',
3047: 3 => 'Grade 3',
3048: 4 => 'Grade 4',
3049: 5 => 'Grade 5',
3050: 6 => 'Grade 6',
3051: 7 => 'Grade 7',
3052: 8 => 'Grade 8',
3053: 9 => 'Grade 9',
3054: 10 => 'Grade 10',
3055: 11 => 'Grade 11',
3056: 12 => 'Grade 12',
3057: 13 => 'Grade 13',
3058: 14 => '100 Level',
3059: 15 => '200 Level',
3060: 16 => '300 Level',
3061: 17 => '400 Level',
3062: 18 => 'Graduate Level');
3063: return &mt($gradelevels{$gradelevel});
3064: }
3065:
1.163 www 3066: sub select_level_form {
3067: my ($deflevel,$name)=@_;
3068: unless ($deflevel) { $deflevel=0; }
1.167 www 3069: my $selectform = "<select name=\"$name\" size=\"1\">\n";
3070: for (my $i=0; $i<=18; $i++) {
3071: $selectform.="<option value=\"$i\" ".
1.253 albertel 3072: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 3073: ">".&gradeleveldescription($i)."</option>\n";
3074: }
3075: $selectform.="</select>";
3076: return $selectform;
1.163 www 3077: }
1.167 www 3078:
1.35 matthew 3079: #-------------------------------------------
3080:
1.45 matthew 3081: =pod
3082:
1.1453 raeburn 3083: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled,$id)
1.35 matthew 3084:
3085: Returns a string containing a <select name='$name' size='1'> form to
3086: allow a user to select the domain to preform an operation in.
3087: See loncreateuser.pm for an example invocation and use.
3088:
1.90 www 3089: If the $includeempty flag is set, it also includes an empty choice ("no domain
3090: selected");
3091:
1.743 raeburn 3092: If the $showdomdesc flag is set, the domain name is followed by the domain description.
3093:
1.910 raeburn 3094: 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.
3095:
1.1121 raeburn 3096: The optional $incdoms is a reference to an array of domains which will be the only available options.
3097:
3098: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 3099:
1.1256 raeburn 3100: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
3101:
1.1453 raeburn 3102: The option $id argument is the value (if any) to set as the (unique) id attribute for the select tag.
3103:
1.35 matthew 3104: =cut
3105:
3106: #-------------------------------------------
1.34 matthew 3107: sub select_dom_form {
1.1453 raeburn 3108: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled,$id) = @_;
1.872 raeburn 3109: if ($onchange) {
1.874 raeburn 3110: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 3111: }
1.1256 raeburn 3112: if ($disabled) {
3113: $disabled = ' disabled="disabled"';
3114: }
1.1453 raeburn 3115: if ($id ne '') {
3116: $id = ' id="'.$id.'"';
3117: }
1.1121 raeburn 3118: my (@domains,%exclude);
1.910 raeburn 3119: if (ref($incdoms) eq 'ARRAY') {
3120: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
3121: } else {
3122: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
3123: }
1.90 www 3124: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 3125: if (ref($excdoms) eq 'ARRAY') {
3126: map { $exclude{$_} = 1; } @{$excdoms};
3127: }
1.1453 raeburn 3128: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled$id>\n";
1.356 albertel 3129: foreach my $dom (@domains) {
1.1121 raeburn 3130: next if ($exclude{$dom});
1.356 albertel 3131: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 3132: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
3133: if ($showdomdesc) {
3134: if ($dom ne '') {
3135: my $domdesc = &Apache::lonnet::domain($dom,'description');
3136: if ($domdesc ne '') {
3137: $selectdomain .= ' ('.$domdesc.')';
3138: }
3139: }
3140: }
3141: $selectdomain .= "</option>\n";
1.34 matthew 3142: }
3143: $selectdomain.="</select>";
3144: return $selectdomain;
3145: }
3146:
1.35 matthew 3147: #-------------------------------------------
3148:
1.45 matthew 3149: =pod
3150:
1.648 raeburn 3151: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 3152:
1.586 raeburn 3153: input: 4 arguments (two required, two optional) -
3154: $domain - domain of new user
3155: $name - name of form element
3156: $default - Value of 'default' causes a default item to be first
3157: option, and selected by default.
3158: $hide - Value of 'hide' causes hiding of the name of the server,
3159: if 1 server found, or default, if 0 found.
1.594 raeburn 3160: output: returns 2 items:
1.586 raeburn 3161: (a) form element which contains either:
3162: (i) <select name="$name">
3163: <option value="$hostid1">$hostid $servers{$hostid}</option>
3164: <option value="$hostid2">$hostid $servers{$hostid}</option>
3165: </select>
3166: form item if there are multiple library servers in $domain, or
3167: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
3168: if there is only one library server in $domain.
3169:
3170: (b) number of library servers found.
3171:
3172: See loncreateuser.pm for example of use.
1.35 matthew 3173:
3174: =cut
3175:
3176: #-------------------------------------------
1.586 raeburn 3177: sub home_server_form_item {
3178: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 3179: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 3180: my $result;
3181: my $numlib = keys(%servers);
3182: if ($numlib > 1) {
3183: $result .= '<select name="'.$name.'" />'."\n";
3184: if ($default) {
1.804 bisitz 3185: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3186: '</option>'."\n";
3187: }
3188: foreach my $hostid (sort(keys(%servers))) {
3189: $result.= '<option value="'.$hostid.'">'.
3190: $hostid.' '.$servers{$hostid}."</option>\n";
3191: }
3192: $result .= '</select>'."\n";
3193: } elsif ($numlib == 1) {
3194: my $hostid;
3195: foreach my $item (keys(%servers)) {
3196: $hostid = $item;
3197: }
3198: $result .= '<input type="hidden" name="'.$name.'" value="'.
3199: $hostid.'" />';
3200: if (!$hide) {
3201: $result .= $hostid.' '.$servers{$hostid};
3202: }
3203: $result .= "\n";
3204: } elsif ($default) {
3205: $result .= '<input type="hidden" name="'.$name.
3206: '" value="default" />';
3207: if (!$hide) {
3208: $result .= &mt('default');
3209: }
3210: $result .= "\n";
1.33 matthew 3211: }
1.586 raeburn 3212: return ($result,$numlib);
1.33 matthew 3213: }
1.112 bowersj2 3214:
3215: =pod
3216:
1.534 albertel 3217: =back
3218:
1.112 bowersj2 3219: =cut
1.87 matthew 3220:
3221: ###############################################################
1.112 bowersj2 3222: ## Decoding User Agent ##
1.87 matthew 3223: ###############################################################
3224:
3225: =pod
3226:
1.112 bowersj2 3227: =head1 Decoding the User Agent
3228:
3229: =over 4
3230:
3231: =item * &decode_user_agent()
1.87 matthew 3232:
3233: Inputs: $r
3234:
3235: Outputs:
3236:
3237: =over 4
3238:
1.112 bowersj2 3239: =item * $httpbrowser
1.87 matthew 3240:
1.112 bowersj2 3241: =item * $clientbrowser
1.87 matthew 3242:
1.112 bowersj2 3243: =item * $clientversion
1.87 matthew 3244:
1.112 bowersj2 3245: =item * $clientmathml
1.87 matthew 3246:
1.112 bowersj2 3247: =item * $clientunicode
1.87 matthew 3248:
1.112 bowersj2 3249: =item * $clientos
1.87 matthew 3250:
1.1137 raeburn 3251: =item * $clientmobile
3252:
1.1141 raeburn 3253: =item * $clientinfo
3254:
1.1194 raeburn 3255: =item * $clientosversion
3256:
1.87 matthew 3257: =back
3258:
1.157 matthew 3259: =back
3260:
1.87 matthew 3261: =cut
3262:
3263: ###############################################################
3264: ###############################################################
3265: sub decode_user_agent {
1.247 albertel 3266: my ($r)=@_;
1.87 matthew 3267: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3268: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3269: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3270: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3271: my $clientbrowser='unknown';
3272: my $clientversion='0';
3273: my $clientmathml='';
3274: my $clientunicode='0';
1.1137 raeburn 3275: my $clientmobile=0;
1.1194 raeburn 3276: my $clientosversion='';
1.87 matthew 3277: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3278: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3279: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3280: $clientbrowser=$bname;
3281: $httpbrowser=~/$vreg/i;
3282: $clientversion=$1;
3283: $clientmathml=($clientversion>=$minv);
3284: $clientunicode=($clientversion>=$univ);
3285: }
3286: }
3287: my $clientos='unknown';
1.1141 raeburn 3288: my $clientinfo;
1.87 matthew 3289: if (($httpbrowser=~/linux/i) ||
3290: ($httpbrowser=~/unix/i) ||
3291: ($httpbrowser=~/ux/i) ||
3292: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3293: if (($httpbrowser=~/vax/i) ||
3294: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3295: if ($httpbrowser=~/next/i) { $clientos='next'; }
3296: if (($httpbrowser=~/mac/i) ||
3297: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3298: if ($httpbrowser=~/win/i) {
3299: $clientos='win';
3300: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3301: $clientosversion = $1;
3302: }
3303: }
1.87 matthew 3304: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3305: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3306: $clientmobile=lc($1);
3307: }
1.1141 raeburn 3308: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3309: $clientinfo = 'firefox-'.$1;
3310: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3311: $clientinfo = 'chromeframe-'.$1;
3312: }
1.87 matthew 3313: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3314: $clientunicode,$clientos,$clientmobile,$clientinfo,
3315: $clientosversion);
1.87 matthew 3316: }
3317:
1.32 matthew 3318: ###############################################################
3319: ## Authentication changing form generation subroutines ##
3320: ###############################################################
3321: ##
3322: ## All of the authform_xxxxxxx subroutines take their inputs in a
3323: ## hash, and have reasonable default values.
3324: ##
3325: ## formname = the name given in the <form> tag.
1.35 matthew 3326: #-------------------------------------------
3327:
1.45 matthew 3328: =pod
3329:
1.112 bowersj2 3330: =head1 Authentication Routines
3331:
3332: =over 4
3333:
1.648 raeburn 3334: =item * &authform_xxxxxx()
1.35 matthew 3335:
3336: The authform_xxxxxx subroutines provide javascript and html forms which
3337: handle some of the conveniences required for authentication forms.
3338: This is not an optimal method, but it works.
3339:
3340: =over 4
3341:
1.112 bowersj2 3342: =item * authform_header
1.35 matthew 3343:
1.112 bowersj2 3344: =item * authform_authorwarning
1.35 matthew 3345:
1.112 bowersj2 3346: =item * authform_nochange
1.35 matthew 3347:
1.112 bowersj2 3348: =item * authform_kerberos
1.35 matthew 3349:
1.112 bowersj2 3350: =item * authform_internal
1.35 matthew 3351:
1.112 bowersj2 3352: =item * authform_filesystem
1.35 matthew 3353:
1.1310 raeburn 3354: =item * authform_lti
3355:
1.35 matthew 3356: =back
3357:
1.648 raeburn 3358: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3359:
1.35 matthew 3360: =cut
3361:
3362: #-------------------------------------------
1.32 matthew 3363: sub authform_header{
3364: my %in = (
3365: formname => 'cu',
1.80 albertel 3366: kerb_def_dom => '',
1.32 matthew 3367: @_,
3368: );
3369: $in{'formname'} = 'document.' . $in{'formname'};
3370: my $result='';
1.80 albertel 3371:
3372: #---------------------------------------------- Code for upper case translation
3373: my $Javascript_toUpperCase;
3374: unless ($in{kerb_def_dom}) {
3375: $Javascript_toUpperCase =<<"END";
3376: switch (choice) {
3377: case 'krb': currentform.elements[choicearg].value =
3378: currentform.elements[choicearg].value.toUpperCase();
3379: break;
3380: default:
3381: }
3382: END
3383: } else {
3384: $Javascript_toUpperCase = "";
3385: }
3386:
1.165 raeburn 3387: my $radioval = "'nochange'";
1.591 raeburn 3388: if (defined($in{'curr_authtype'})) {
3389: if ($in{'curr_authtype'} ne '') {
3390: $radioval = "'".$in{'curr_authtype'}."arg'";
3391: }
1.174 matthew 3392: }
1.165 raeburn 3393: my $argfield = 'null';
1.591 raeburn 3394: if (defined($in{'mode'})) {
1.165 raeburn 3395: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3396: if (defined($in{'curr_autharg'})) {
3397: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3398: $argfield = "'$in{'curr_autharg'}'";
3399: }
3400: }
3401: }
3402: }
3403:
1.32 matthew 3404: $result.=<<"END";
3405: var current = new Object();
1.165 raeburn 3406: current.radiovalue = $radioval;
3407: current.argfield = $argfield;
1.32 matthew 3408:
3409: function changed_radio(choice,currentform) {
3410: var choicearg = choice + 'arg';
3411: // If a radio button in changed, we need to change the argfield
3412: if (current.radiovalue != choice) {
3413: current.radiovalue = choice;
3414: if (current.argfield != null) {
3415: currentform.elements[current.argfield].value = '';
3416: }
3417: if (choice == 'nochange') {
3418: current.argfield = null;
3419: } else {
3420: current.argfield = choicearg;
3421: switch(choice) {
3422: case 'krb':
3423: currentform.elements[current.argfield].value =
3424: "$in{'kerb_def_dom'}";
3425: break;
3426: default:
3427: break;
3428: }
3429: }
3430: }
3431: return;
3432: }
1.22 www 3433:
1.32 matthew 3434: function changed_text(choice,currentform) {
3435: var choicearg = choice + 'arg';
3436: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3437: $Javascript_toUpperCase
1.32 matthew 3438: // clear old field
3439: if ((current.argfield != choicearg) && (current.argfield != null)) {
3440: currentform.elements[current.argfield].value = '';
3441: }
3442: current.argfield = choicearg;
3443: }
3444: set_auth_radio_buttons(choice,currentform);
3445: return;
1.20 www 3446: }
1.32 matthew 3447:
3448: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3449: var numauthchoices = currentform.login.length;
3450: if (typeof numauthchoices == "undefined") {
3451: return;
3452: }
1.32 matthew 3453: var i=0;
1.986 raeburn 3454: while (i < numauthchoices) {
1.32 matthew 3455: if (currentform.login[i].value == newvalue) { break; }
3456: i++;
3457: }
1.986 raeburn 3458: if (i == numauthchoices) {
1.32 matthew 3459: return;
3460: }
3461: current.radiovalue = newvalue;
3462: currentform.login[i].checked = true;
3463: return;
3464: }
3465: END
3466: return $result;
3467: }
3468:
1.1106 raeburn 3469: sub authform_authorwarning {
1.32 matthew 3470: my $result='';
1.144 matthew 3471: $result='<i>'.
3472: &mt('As a general rule, only authors or co-authors should be '.
3473: 'filesystem authenticated '.
3474: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3475: return $result;
3476: }
3477:
1.1106 raeburn 3478: sub authform_nochange {
1.32 matthew 3479: my %in = (
3480: formname => 'document.cu',
3481: kerb_def_dom => 'MSU.EDU',
3482: @_,
3483: );
1.1106 raeburn 3484: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3485: my $result;
1.1104 raeburn 3486: if (!$authnum) {
1.1105 raeburn 3487: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3488: } else {
3489: $result = '<label>'.&mt('[_1] Do not change login data',
3490: '<input type="radio" name="login" value="nochange" '.
3491: 'checked="checked" onclick="'.
1.281 albertel 3492: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3493: '</label>';
1.586 raeburn 3494: }
1.32 matthew 3495: return $result;
3496: }
3497:
1.591 raeburn 3498: sub authform_kerberos {
1.32 matthew 3499: my %in = (
3500: formname => 'document.cu',
3501: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3502: kerb_def_auth => 'krb4',
1.32 matthew 3503: @_,
3504: );
1.586 raeburn 3505: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3506: $autharg,$jscall,$disabled);
1.1106 raeburn 3507: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3508: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3509: $check5 = ' checked="checked"';
1.80 albertel 3510: } else {
1.772 bisitz 3511: $check4 = ' checked="checked"';
1.80 albertel 3512: }
1.1259 raeburn 3513: if ($in{'readonly'}) {
3514: $disabled = ' disabled="disabled"';
3515: }
1.165 raeburn 3516: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3517: if (defined($in{'curr_authtype'})) {
3518: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3519: $krbcheck = ' checked="checked"';
1.623 raeburn 3520: if (defined($in{'mode'})) {
3521: if ($in{'mode'} eq 'modifyuser') {
3522: $krbcheck = '';
3523: }
3524: }
1.591 raeburn 3525: if (defined($in{'curr_kerb_ver'})) {
3526: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3527: $check5 = ' checked="checked"';
1.591 raeburn 3528: $check4 = '';
3529: } else {
1.772 bisitz 3530: $check4 = ' checked="checked"';
1.591 raeburn 3531: $check5 = '';
3532: }
1.586 raeburn 3533: }
1.591 raeburn 3534: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3535: $krbarg = $in{'curr_autharg'};
3536: }
1.586 raeburn 3537: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3538: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3539: $result =
3540: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3541: $in{'curr_autharg'},$krbver);
3542: } else {
3543: $result =
3544: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3545: }
3546: return $result;
3547: }
3548: }
3549: } else {
3550: if ($authnum == 1) {
1.784 bisitz 3551: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3552: }
3553: }
1.586 raeburn 3554: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3555: return;
1.587 raeburn 3556: } elsif ($authtype eq '') {
1.591 raeburn 3557: if (defined($in{'mode'})) {
1.587 raeburn 3558: if ($in{'mode'} eq 'modifycourse') {
3559: if ($authnum == 1) {
1.1259 raeburn 3560: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3561: }
3562: }
3563: }
1.586 raeburn 3564: }
3565: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3566: if ($authtype eq '') {
3567: $authtype = '<input type="radio" name="login" value="krb" '.
3568: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3569: $krbcheck.$disabled.' />';
1.586 raeburn 3570: }
3571: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3572: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3573: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3574: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3575: $in{'curr_authtype'} eq 'krb4')) {
3576: $result .= &mt
1.144 matthew 3577: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3578: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3579: '<label>'.$authtype,
1.281 albertel 3580: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3581: 'value="'.$krbarg.'" '.
1.1259 raeburn 3582: 'onchange="'.$jscall.'"'.$disabled.' />',
3583: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3584: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3585: '</label>');
1.586 raeburn 3586: } elsif ($can_assign{'krb4'}) {
3587: $result .= &mt
3588: ('[_1] Kerberos authenticated with domain [_2] '.
3589: '[_3] Version 4 [_4]',
3590: '<label>'.$authtype,
3591: '</label><input type="text" size="10" name="krbarg" '.
3592: 'value="'.$krbarg.'" '.
1.1259 raeburn 3593: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3594: '<label><input type="hidden" name="krbver" value="4" />',
3595: '</label>');
3596: } elsif ($can_assign{'krb5'}) {
3597: $result .= &mt
3598: ('[_1] Kerberos authenticated with domain [_2] '.
3599: '[_3] Version 5 [_4]',
3600: '<label>'.$authtype,
3601: '</label><input type="text" size="10" name="krbarg" '.
3602: 'value="'.$krbarg.'" '.
1.1259 raeburn 3603: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3604: '<label><input type="hidden" name="krbver" value="5" />',
3605: '</label>');
3606: }
1.32 matthew 3607: return $result;
3608: }
3609:
1.1106 raeburn 3610: sub authform_internal {
1.586 raeburn 3611: my %in = (
1.32 matthew 3612: formname => 'document.cu',
3613: kerb_def_dom => 'MSU.EDU',
3614: @_,
3615: );
1.1259 raeburn 3616: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3617: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3618: if ($in{'readonly'}) {
3619: $disabled = ' disabled="disabled"';
3620: }
1.591 raeburn 3621: if (defined($in{'curr_authtype'})) {
3622: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3623: if ($can_assign{'int'}) {
1.772 bisitz 3624: $intcheck = 'checked="checked" ';
1.623 raeburn 3625: if (defined($in{'mode'})) {
3626: if ($in{'mode'} eq 'modifyuser') {
3627: $intcheck = '';
3628: }
3629: }
1.591 raeburn 3630: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3631: $intarg = $in{'curr_autharg'};
3632: }
3633: } else {
3634: $result = &mt('Currently internally authenticated.');
3635: return $result;
1.165 raeburn 3636: }
3637: }
1.586 raeburn 3638: } else {
3639: if ($authnum == 1) {
1.784 bisitz 3640: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3641: }
3642: }
3643: if (!$can_assign{'int'}) {
3644: return;
1.587 raeburn 3645: } elsif ($authtype eq '') {
1.591 raeburn 3646: if (defined($in{'mode'})) {
1.587 raeburn 3647: if ($in{'mode'} eq 'modifycourse') {
3648: if ($authnum == 1) {
1.1259 raeburn 3649: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3650: }
3651: }
3652: }
1.165 raeburn 3653: }
1.586 raeburn 3654: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3655: if ($authtype eq '') {
3656: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3657: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3658: }
1.605 bisitz 3659: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3660: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3661: $result = &mt
1.144 matthew 3662: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3663: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3664: $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 3665: return $result;
3666: }
3667:
1.1104 raeburn 3668: sub authform_local {
1.32 matthew 3669: my %in = (
3670: formname => 'document.cu',
3671: kerb_def_dom => 'MSU.EDU',
3672: @_,
3673: );
1.1259 raeburn 3674: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3675: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3676: if ($in{'readonly'}) {
3677: $disabled = ' disabled="disabled"';
3678: }
1.591 raeburn 3679: if (defined($in{'curr_authtype'})) {
3680: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3681: if ($can_assign{'loc'}) {
1.772 bisitz 3682: $loccheck = 'checked="checked" ';
1.623 raeburn 3683: if (defined($in{'mode'})) {
3684: if ($in{'mode'} eq 'modifyuser') {
3685: $loccheck = '';
3686: }
3687: }
1.591 raeburn 3688: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3689: $locarg = $in{'curr_autharg'};
3690: }
3691: } else {
3692: $result = &mt('Currently using local (institutional) authentication.');
3693: return $result;
1.165 raeburn 3694: }
3695: }
1.586 raeburn 3696: } else {
3697: if ($authnum == 1) {
1.784 bisitz 3698: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3699: }
3700: }
3701: if (!$can_assign{'loc'}) {
3702: return;
1.587 raeburn 3703: } elsif ($authtype eq '') {
1.591 raeburn 3704: if (defined($in{'mode'})) {
1.587 raeburn 3705: if ($in{'mode'} eq 'modifycourse') {
3706: if ($authnum == 1) {
1.1259 raeburn 3707: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3708: }
3709: }
3710: }
1.165 raeburn 3711: }
1.586 raeburn 3712: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3713: if ($authtype eq '') {
3714: $authtype = '<input type="radio" name="login" value="loc" '.
3715: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3716: $jscall.'"'.$disabled.' />';
1.586 raeburn 3717: }
3718: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3719: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3720: $result = &mt('[_1] Local Authentication with argument [_2]',
3721: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3722: return $result;
3723: }
3724:
1.1106 raeburn 3725: sub authform_filesystem {
1.32 matthew 3726: my %in = (
3727: formname => 'document.cu',
3728: kerb_def_dom => 'MSU.EDU',
3729: @_,
3730: );
1.1259 raeburn 3731: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3732: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3733: if ($in{'readonly'}) {
3734: $disabled = ' disabled="disabled"';
3735: }
1.591 raeburn 3736: if (defined($in{'curr_authtype'})) {
3737: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3738: if ($can_assign{'fsys'}) {
1.772 bisitz 3739: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3740: if (defined($in{'mode'})) {
3741: if ($in{'mode'} eq 'modifyuser') {
3742: $fsyscheck = '';
3743: }
3744: }
1.586 raeburn 3745: } else {
3746: $result = &mt('Currently Filesystem Authenticated.');
3747: return $result;
1.1259 raeburn 3748: }
1.586 raeburn 3749: }
3750: } else {
3751: if ($authnum == 1) {
1.784 bisitz 3752: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3753: }
3754: }
3755: if (!$can_assign{'fsys'}) {
3756: return;
1.587 raeburn 3757: } elsif ($authtype eq '') {
1.591 raeburn 3758: if (defined($in{'mode'})) {
1.587 raeburn 3759: if ($in{'mode'} eq 'modifycourse') {
3760: if ($authnum == 1) {
1.1259 raeburn 3761: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3762: }
3763: }
3764: }
1.586 raeburn 3765: }
3766: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3767: if ($authtype eq '') {
3768: $authtype = '<input type="radio" name="login" value="fsys" '.
3769: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3770: $jscall.'"'.$disabled.' />';
1.586 raeburn 3771: }
1.1310 raeburn 3772: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3773: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3774: $result = &mt
1.144 matthew 3775: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3776: '<label>'.$authtype,'</label>'.$autharg);
3777: return $result;
3778: }
3779:
3780: sub authform_lti {
3781: my %in = (
3782: formname => 'document.cu',
3783: kerb_def_dom => 'MSU.EDU',
3784: @_,
3785: );
3786: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3787: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3788: if ($in{'readonly'}) {
3789: $disabled = ' disabled="disabled"';
3790: }
3791: if (defined($in{'curr_authtype'})) {
3792: if ($in{'curr_authtype'} eq 'lti') {
3793: if ($can_assign{'lti'}) {
3794: $lticheck = 'checked="checked" ';
3795: if (defined($in{'mode'})) {
3796: if ($in{'mode'} eq 'modifyuser') {
3797: $lticheck = '';
3798: }
3799: }
3800: } else {
3801: $result = &mt('Currently LTI Authenticated.');
3802: return $result;
3803: }
3804: }
3805: } else {
3806: if ($authnum == 1) {
3807: $authtype = '<input type="hidden" name="login" value="lti" />';
3808: }
3809: }
3810: if (!$can_assign{'lti'}) {
3811: return;
3812: } elsif ($authtype eq '') {
3813: if (defined($in{'mode'})) {
3814: if ($in{'mode'} eq 'modifycourse') {
3815: if ($authnum == 1) {
3816: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3817: }
3818: }
3819: }
3820: }
3821: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3822: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3823: $authtype = '<input type="radio" name="login" value="lti" '.
3824: $lticheck.' onchange="'.$jscall.'" onclick="'.
3825: $jscall.'"'.$disabled.' />';
3826: }
3827: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3828: if ($authtype) {
3829: $result = &mt('[_1] LTI Authenticated',
3830: '<label>'.$authtype.'</label>'.$autharg);
3831: } else {
3832: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3833: $autharg;
3834: }
1.32 matthew 3835: return $result;
3836: }
3837:
1.586 raeburn 3838: sub get_assignable_auth {
3839: my ($dom) = @_;
3840: if ($dom eq '') {
3841: $dom = $env{'request.role.domain'};
3842: }
3843: my %can_assign = (
3844: krb4 => 1,
3845: krb5 => 1,
3846: int => 1,
3847: loc => 1,
1.1310 raeburn 3848: lti => 1,
1.586 raeburn 3849: );
3850: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3851: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3852: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3853: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3854: my $context;
3855: if ($env{'request.role'} =~ /^au/) {
3856: $context = 'author';
1.1259 raeburn 3857: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3858: $context = 'domain';
3859: } elsif ($env{'request.course.id'}) {
3860: $context = 'course';
3861: }
3862: if ($context) {
3863: if (ref($authhash->{$context}) eq 'HASH') {
3864: %can_assign = %{$authhash->{$context}};
3865: }
3866: }
3867: }
3868: }
3869: my $authnum = 0;
3870: foreach my $key (keys(%can_assign)) {
3871: if ($can_assign{$key}) {
3872: $authnum ++;
3873: }
3874: }
3875: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3876: $authnum --;
3877: }
3878: return ($authnum,%can_assign);
3879: }
3880:
1.1331 raeburn 3881: sub check_passwd_rules {
3882: my ($domain,$plainpass) = @_;
3883: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3884: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3885: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3886: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3887: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3888: if ($passwdconf{'min'} > $min) {
3889: $min = $passwdconf{'min'};
3890: }
1.1331 raeburn 3891: }
3892: if ($passwdconf{'max'} =~ /^\d+$/) {
3893: $max = $passwdconf{'max'};
3894: }
3895: @chars = @{$passwdconf{'chars'}};
3896: }
3897: if (($min) && (length($plainpass) < $min)) {
3898: push(@brokerule,'min');
3899: }
3900: if (($max) && (length($plainpass) > $max)) {
3901: push(@brokerule,'max');
3902: }
3903: if (@chars) {
3904: my %rules;
3905: map { $rules{$_} = 1; } @chars;
3906: if ($rules{'uc'}) {
3907: unless ($plainpass =~ /[A-Z]/) {
3908: push(@brokerule,'uc');
3909: }
3910: }
3911: if ($rules{'lc'}) {
1.1332 raeburn 3912: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3913: push(@brokerule,'lc');
3914: }
3915: }
3916: if ($rules{'num'}) {
3917: unless ($plainpass =~ /\d/) {
3918: push(@brokerule,'num');
3919: }
3920: }
3921: if ($rules{'spec'}) {
3922: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3923: push(@brokerule,'spec');
3924: }
3925: }
3926: }
3927: if (@brokerule) {
3928: my %rulenames = &Apache::lonlocal::texthash(
3929: uc => 'At least one upper case letter',
3930: lc => 'At least one lower case letter',
3931: num => 'At least one number',
3932: spec => 'At least one non-alphanumeric',
3933: );
3934: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3935: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3936: $rulenames{'num'} .= ': 0123456789';
3937: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3938: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3939: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3940: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3941: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3942: if (grep(/^$rule$/,@brokerule)) {
3943: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3944: }
3945: }
3946: $warning .= '</ul>';
3947: }
1.1332 raeburn 3948: if (wantarray) {
3949: return @brokerule;
3950: }
1.1331 raeburn 3951: return $warning;
3952: }
3953:
1.1376 raeburn 3954: sub passwd_validation_js {
1.1377 raeburn 3955: my ($currpasswdval,$domain,$context,$id) = @_;
3956: my (%passwdconf,$alertmsg);
3957: if ($context eq 'linkprot') {
3958: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3959: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3960: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3961: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3962: }
3963: }
3964: if ($id eq 'add') {
3965: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3966: } elsif ($id =~ /^\d+$/) {
3967: my $pos = $id+1;
3968: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3969: } else {
3970: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3971: }
1.1434 raeburn 3972: } elsif ($context eq 'ltitools') {
3973: my %domconfig = &Apache::lonnet::get_dom('configuration',['toolsec'],$domain);
3974: if (ref($domconfig{'toolsec'}) eq 'HASH') {
3975: if (ref($domconfig{'toolsec'}{'rules'}) eq 'HASH') {
3976: %passwdconf = %{$domconfig{'toolsec'}{'rules'}};
3977: }
3978: }
3979: if ($id eq 'add') {
3980: $alertmsg = &mt('Secret for added external tool did not satisfy requirement(s):').'\n\n';
3981: } elsif ($id =~ /^\d+$/) {
3982: my $pos = $id+1;
3983: $alertmsg = &mt('Secret for external tool [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3984: } else {
3985: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3986: }
1.1377 raeburn 3987: } else {
3988: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3989: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3990: }
1.1376 raeburn 3991: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3992: $numrules = 0;
3993: $min = $Apache::lonnet::passwdmin;
3994: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3995: if ($passwdconf{'min'} =~ /^\d+$/) {
3996: if ($passwdconf{'min'} > $min) {
3997: $min = $passwdconf{'min'};
3998: }
3999: }
4000: if ($passwdconf{'max'} =~ /^\d+$/) {
4001: $max = $passwdconf{'max'};
4002: $numrules ++;
4003: }
4004: @chars = @{$passwdconf{'chars'}};
4005: if (@chars) {
4006: $numrules ++;
4007: }
4008: }
4009: if ($min > 0) {
4010: $numrules ++;
4011: }
4012: if (($min > 0) || ($max ne '') || (@chars > 0)) {
4013: if ($min) {
4014: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
4015: }
4016: if ($max) {
4017: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
4018: }
4019: my (@charalerts,@charrules);
4020: if (@chars) {
4021: if (grep(/^uc$/,@chars)) {
4022: push(@charalerts,&mt('contain at least one upper case letter'));
4023: push(@charrules,'uc');
4024: }
4025: if (grep(/^lc$/,@chars)) {
4026: push(@charalerts,&mt('contain at least one lower case letter'));
4027: push(@charrules,'lc');
4028: }
4029: if (grep(/^num$/,@chars)) {
4030: push(@charalerts,&mt('contain at least one number'));
4031: push(@charrules,'num');
4032: }
4033: if (grep(/^spec$/,@chars)) {
4034: push(@charalerts,&mt('contain at least one non-alphanumeric'));
4035: push(@charrules,'spec');
4036: }
4037: }
4038: $intargjs = qq| var rulesmsg = '';\n|.
4039: qq| var currpwval = $currpasswdval;\n|;
4040: if ($min) {
4041: $intargjs .= qq|
4042: if (currpwval.length < $min) {
4043: rulesmsg += ' - $alert{min}';
4044: }
4045: |;
4046: }
4047: if ($max) {
4048: $intargjs .= qq|
4049: if (currpwval.length > $max) {
4050: rulesmsg += ' - $alert{max}';
4051: }
4052: |;
4053: }
4054: if (@chars > 0) {
4055: my $charrulestr = '"'.join('","',@charrules).'"';
4056: my $charalertstr = '"'.join('","',@charalerts).'"';
4057: $intargjs .= qq| var brokerules = new Array();\n|.
4058: qq| var charrules = new Array($charrulestr);\n|.
4059: qq| var charalerts = new Array($charalertstr);\n|;
4060: my %rules;
4061: map { $rules{$_} = 1; } @chars;
4062: if ($rules{'uc'}) {
4063: $intargjs .= qq|
4064: var ucRegExp = /[A-Z]/;
4065: if (!ucRegExp.test(currpwval)) {
4066: brokerules.push('uc');
4067: }
4068: |;
4069: }
4070: if ($rules{'lc'}) {
4071: $intargjs .= qq|
4072: var lcRegExp = /[a-z]/;
4073: if (!lcRegExp.test(currpwval)) {
4074: brokerules.push('lc');
4075: }
4076: |;
4077: }
4078: if ($rules{'num'}) {
4079: $intargjs .= qq|
4080: var numRegExp = /[0-9]/;
4081: if (!numRegExp.test(currpwval)) {
4082: brokerules.push('num');
4083: }
4084: |;
4085: }
4086: if ($rules{'spec'}) {
4087: $intargjs .= q|
4088: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
4089: if (!specRegExp.test(currpwval)) {
4090: brokerules.push('spec');
4091: }
4092: |;
4093: }
4094: $intargjs .= qq|
4095: if (brokerules.length > 0) {
4096: for (var i=0; i<brokerules.length; i++) {
4097: for (var j=0; j<charrules.length; j++) {
4098: if (brokerules[i] == charrules[j]) {
4099: rulesmsg += ' - '+charalerts[j]+'\\n';
4100: break;
4101: }
4102: }
4103: }
4104: }
4105: |;
4106: }
4107: $intargjs .= qq|
4108: if (rulesmsg != '') {
4109: rulesmsg = '$alertmsg'+rulesmsg;
4110: alert(rulesmsg);
4111: return false;
4112: }
4113: |;
4114: }
4115: return ($numrules,$intargjs);
4116: }
4117:
1.80 albertel 4118: ###############################################################
4119: ## Get Kerberos Defaults for Domain ##
4120: ###############################################################
4121: ##
4122: ## Returns default kerberos version and an associated argument
4123: ## as listed in file domain.tab. If not listed, provides
4124: ## appropriate default domain and kerberos version.
4125: ##
4126: #-------------------------------------------
4127:
4128: =pod
4129:
1.648 raeburn 4130: =item * &get_kerberos_defaults()
1.80 albertel 4131:
4132: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 4133: version and domain. If not found, it defaults to version 4 and the
4134: domain of the server.
1.80 albertel 4135:
1.648 raeburn 4136: =over 4
4137:
1.80 albertel 4138: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
4139:
1.648 raeburn 4140: =back
4141:
4142: =back
4143:
1.80 albertel 4144: =cut
4145:
4146: #-------------------------------------------
4147: sub get_kerberos_defaults {
4148: my $domain=shift;
1.641 raeburn 4149: my ($krbdef,$krbdefdom);
4150: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
4151: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
4152: $krbdef = $domdefaults{'auth_def'};
4153: $krbdefdom = $domdefaults{'auth_arg_def'};
4154: } else {
1.80 albertel 4155: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
4156: my $krbdefdom=$1;
4157: $krbdefdom=~tr/a-z/A-Z/;
4158: $krbdef = "krb4";
4159: }
4160: return ($krbdef,$krbdefdom);
4161: }
1.112 bowersj2 4162:
1.32 matthew 4163:
1.46 matthew 4164: ###############################################################
4165: ## Thesaurus Functions ##
4166: ###############################################################
1.20 www 4167:
1.46 matthew 4168: =pod
1.20 www 4169:
1.112 bowersj2 4170: =head1 Thesaurus Functions
4171:
4172: =over 4
4173:
1.648 raeburn 4174: =item * &initialize_keywords()
1.46 matthew 4175:
4176: Initializes the package variable %Keywords if it is empty. Uses the
4177: package variable $thesaurus_db_file.
4178:
4179: =cut
4180:
4181: ###################################################
4182:
4183: sub initialize_keywords {
4184: return 1 if (scalar keys(%Keywords));
4185: # If we are here, %Keywords is empty, so fill it up
4186: # Make sure the file we need exists...
4187: if (! -e $thesaurus_db_file) {
4188: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
4189: " failed because it does not exist");
4190: return 0;
4191: }
4192: # Set up the hash as a database
4193: my %thesaurus_db;
4194: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4195: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4196: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
4197: $thesaurus_db_file);
4198: return 0;
4199: }
4200: # Get the average number of appearances of a word.
4201: my $avecount = $thesaurus_db{'average.count'};
4202: # Put keywords (those that appear > average) into %Keywords
4203: while (my ($word,$data)=each (%thesaurus_db)) {
4204: my ($count,undef) = split /:/,$data;
4205: $Keywords{$word}++ if ($count > $avecount);
4206: }
4207: untie %thesaurus_db;
4208: # Remove special values from %Keywords.
1.356 albertel 4209: foreach my $value ('total.count','average.count') {
4210: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4211: }
1.46 matthew 4212: return 1;
4213: }
4214:
4215: ###################################################
4216:
4217: =pod
4218:
1.648 raeburn 4219: =item * &keyword($word)
1.46 matthew 4220:
4221: Returns true if $word is a keyword. A keyword is a word that appears more
4222: than the average number of times in the thesaurus database. Calls
4223: &initialize_keywords
4224:
4225: =cut
4226:
4227: ###################################################
1.20 www 4228:
4229: sub keyword {
1.46 matthew 4230: return if (!&initialize_keywords());
4231: my $word=lc(shift());
4232: $word=~s/\W//g;
4233: return exists($Keywords{$word});
1.20 www 4234: }
1.46 matthew 4235:
4236: ###############################################################
4237:
4238: =pod
1.20 www 4239:
1.648 raeburn 4240: =item * &get_related_words()
1.46 matthew 4241:
1.160 matthew 4242: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4243: an array of words. If the keyword is not in the thesaurus, an empty array
4244: will be returned. The order of the words returned is determined by the
4245: database which holds them.
4246:
4247: Uses global $thesaurus_db_file.
4248:
1.1057 foxr 4249:
1.46 matthew 4250: =cut
4251:
4252: ###############################################################
4253: sub get_related_words {
4254: my $keyword = shift;
4255: my %thesaurus_db;
4256: if (! -e $thesaurus_db_file) {
4257: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4258: "failed because the file does not exist");
4259: return ();
4260: }
4261: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4262: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4263: return ();
4264: }
4265: my @Words=();
1.429 www 4266: my $count=0;
1.46 matthew 4267: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4268: # The first element is the number of times
4269: # the word appears. We do not need it now.
1.429 www 4270: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4271: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4272: my $threshold=$mostfrequentcount/10;
4273: foreach my $possibleword (@RelatedWords) {
4274: my ($word,$wordcount)=split(/\,/,$possibleword);
4275: if ($wordcount>$threshold) {
4276: push(@Words,$word);
4277: $count++;
4278: if ($count>10) { last; }
4279: }
1.20 www 4280: }
4281: }
1.46 matthew 4282: untie %thesaurus_db;
4283: return @Words;
1.14 harris41 4284: }
1.1090 foxr 4285: ###############################################################
4286: #
4287: # Spell checking
4288: #
4289:
4290: =pod
4291:
1.1142 raeburn 4292: =back
4293:
1.1090 foxr 4294: =head1 Spell checking
4295:
4296: =over 4
4297:
4298: =item * &check_spelling($wordlist $language)
4299:
4300: Takes a string containing words and feeds it to an external
4301: spellcheck program via a pipeline. Returns a string containing
4302: them mis-spelled words.
4303:
4304: Parameters:
4305:
4306: =over 4
4307:
4308: =item - $wordlist
4309:
4310: String that will be fed into the spellcheck program.
4311:
4312: =item - $language
4313:
4314: Language string that specifies the language for which the spell
4315: check will be performed.
4316:
4317: =back
4318:
4319: =back
4320:
4321: Note: This sub assumes that aspell is installed.
4322:
4323:
4324: =cut
4325:
1.46 matthew 4326:
1.1090 foxr 4327: sub check_spelling {
4328: my ($wordlist, $language) = @_;
1.1091 foxr 4329: my @misspellings;
4330:
4331: # Generate the speller and set the langauge.
4332: # if explicitly selected:
1.1090 foxr 4333:
1.1091 foxr 4334: my $speller = Text::Aspell->new;
1.1090 foxr 4335: if ($language) {
1.1091 foxr 4336: $speller->set_option('lang', $language);
1.1090 foxr 4337: }
4338:
1.1091 foxr 4339: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4340:
1.1091 foxr 4341: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4342:
1.1091 foxr 4343: foreach my $word (@words) {
4344: if(! $speller->check($word)) {
4345: push(@misspellings, $word);
1.1090 foxr 4346: }
4347: }
1.1091 foxr 4348: return join(' ', @misspellings);
4349:
1.1090 foxr 4350: }
4351:
1.61 www 4352: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4353: =pod
4354:
1.112 bowersj2 4355: =head1 User Name Functions
4356:
4357: =over 4
4358:
1.648 raeburn 4359: =item * &plainname($uname,$udom,$first)
1.81 albertel 4360:
1.112 bowersj2 4361: Takes a users logon name and returns it as a string in
1.226 albertel 4362: "first middle last generation" form
4363: if $first is set to 'lastname' then it returns it as
4364: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4365:
4366: =cut
1.61 www 4367:
1.295 www 4368:
1.81 albertel 4369: ###############################################################
1.61 www 4370: sub plainname {
1.226 albertel 4371: my ($uname,$udom,$first)=@_;
1.537 albertel 4372: return if (!defined($uname) || !defined($udom));
1.295 www 4373: my %names=&getnames($uname,$udom);
1.226 albertel 4374: my $name=&Apache::lonnet::format_name($names{'firstname'},
4375: $names{'middlename'},
4376: $names{'lastname'},
4377: $names{'generation'},$first);
4378: $name=~s/^\s+//;
1.62 www 4379: $name=~s/\s+$//;
4380: $name=~s/\s+/ /g;
1.353 albertel 4381: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4382: return $name;
1.61 www 4383: }
1.66 www 4384:
4385: # -------------------------------------------------------------------- Nickname
1.81 albertel 4386: =pod
4387:
1.648 raeburn 4388: =item * &nickname($uname,$udom)
1.81 albertel 4389:
4390: Gets a users name and returns it as a string as
4391:
4392: ""nickname""
1.66 www 4393:
1.81 albertel 4394: if the user has a nickname or
4395:
4396: "first middle last generation"
4397:
4398: if the user does not
4399:
4400: =cut
1.66 www 4401:
4402: sub nickname {
4403: my ($uname,$udom)=@_;
1.537 albertel 4404: return if (!defined($uname) || !defined($udom));
1.295 www 4405: my %names=&getnames($uname,$udom);
1.68 albertel 4406: my $name=$names{'nickname'};
1.66 www 4407: if ($name) {
4408: $name='"'.$name.'"';
4409: } else {
4410: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4411: $names{'lastname'}.' '.$names{'generation'};
4412: $name=~s/\s+$//;
4413: $name=~s/\s+/ /g;
4414: }
4415: return $name;
4416: }
4417:
1.295 www 4418: sub getnames {
4419: my ($uname,$udom)=@_;
1.537 albertel 4420: return if (!defined($uname) || !defined($udom));
1.433 albertel 4421: if ($udom eq 'public' && $uname eq 'public') {
4422: return ('lastname' => &mt('Public'));
4423: }
1.295 www 4424: my $id=$uname.':'.$udom;
4425: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4426: if ($cached) {
4427: return %{$names};
4428: } else {
4429: my %loadnames=&Apache::lonnet::get('environment',
4430: ['firstname','middlename','lastname','generation','nickname'],
4431: $udom,$uname);
4432: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4433: return %loadnames;
4434: }
4435: }
1.61 www 4436:
1.542 raeburn 4437: # -------------------------------------------------------------------- getemails
1.648 raeburn 4438:
1.542 raeburn 4439: =pod
4440:
1.648 raeburn 4441: =item * &getemails($uname,$udom)
1.542 raeburn 4442:
4443: Gets a user's email information and returns it as a hash with keys:
4444: notification, critnotification, permanentemail
4445:
4446: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4447: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4448:
1.648 raeburn 4449:
1.542 raeburn 4450: =cut
4451:
1.648 raeburn 4452:
1.466 albertel 4453: sub getemails {
4454: my ($uname,$udom)=@_;
4455: if ($udom eq 'public' && $uname eq 'public') {
4456: return;
4457: }
1.467 www 4458: if (!$udom) { $udom=$env{'user.domain'}; }
4459: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4460: my $id=$uname.':'.$udom;
4461: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4462: if ($cached) {
4463: return %{$names};
4464: } else {
4465: my %loadnames=&Apache::lonnet::get('environment',
4466: ['notification','critnotification',
4467: 'permanentemail'],
4468: $udom,$uname);
4469: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4470: return %loadnames;
4471: }
4472: }
4473:
1.551 albertel 4474: sub flush_email_cache {
4475: my ($uname,$udom)=@_;
4476: if (!$udom) { $udom =$env{'user.domain'}; }
4477: if (!$uname) { $uname=$env{'user.name'}; }
4478: return if ($udom eq 'public' && $uname eq 'public');
4479: my $id=$uname.':'.$udom;
4480: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4481: }
4482:
1.728 raeburn 4483: # -------------------------------------------------------------------- getlangs
4484:
4485: =pod
4486:
4487: =item * &getlangs($uname,$udom)
4488:
4489: Gets a user's language preference and returns it as a hash with key:
4490: language.
4491:
4492: =cut
4493:
4494:
4495: sub getlangs {
4496: my ($uname,$udom) = @_;
4497: if (!$udom) { $udom =$env{'user.domain'}; }
4498: if (!$uname) { $uname=$env{'user.name'}; }
4499: my $id=$uname.':'.$udom;
4500: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4501: if ($cached) {
4502: return %{$langs};
4503: } else {
4504: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4505: $udom,$uname);
4506: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4507: return %loadlangs;
4508: }
4509: }
4510:
4511: sub flush_langs_cache {
4512: my ($uname,$udom)=@_;
4513: if (!$udom) { $udom =$env{'user.domain'}; }
4514: if (!$uname) { $uname=$env{'user.name'}; }
4515: return if ($udom eq 'public' && $uname eq 'public');
4516: my $id=$uname.':'.$udom;
4517: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4518: }
4519:
1.61 www 4520: # ------------------------------------------------------------------ Screenname
1.81 albertel 4521:
4522: =pod
4523:
1.648 raeburn 4524: =item * &screenname($uname,$udom)
1.81 albertel 4525:
4526: Gets a users screenname and returns it as a string
4527:
4528: =cut
1.61 www 4529:
4530: sub screenname {
4531: my ($uname,$udom)=@_;
1.258 albertel 4532: if ($uname eq $env{'user.name'} &&
4533: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4534: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4535: return $names{'screenname'};
1.62 www 4536: }
4537:
1.212 albertel 4538:
1.802 bisitz 4539: # ------------------------------------------------------------- Confirm Wrapper
4540: =pod
4541:
1.1142 raeburn 4542: =item * &confirmwrapper($message)
1.802 bisitz 4543:
4544: Wrap messages about completion of operation in box
4545:
4546: =cut
4547:
4548: sub confirmwrapper {
4549: my ($message)=@_;
4550: if ($message) {
4551: return "\n".'<div class="LC_confirm_box">'."\n"
4552: .$message."\n"
4553: .'</div>'."\n";
4554: } else {
4555: return $message;
4556: }
4557: }
4558:
1.62 www 4559: # ------------------------------------------------------------- Message Wrapper
4560:
4561: sub messagewrapper {
1.369 www 4562: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4563: return
1.441 albertel 4564: '<a href="/adm/email?compose=individual&'.
4565: 'recname='.$username.'&recdom='.$domain.
4566: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4567: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4568: }
1.802 bisitz 4569:
1.74 www 4570: # --------------------------------------------------------------- Notes Wrapper
4571:
4572: sub noteswrapper {
4573: my ($link,$un,$do)=@_;
4574: return
1.896 amueller 4575: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4576: }
1.802 bisitz 4577:
1.62 www 4578: # ------------------------------------------------------------- Aboutme Wrapper
4579:
4580: sub aboutmewrapper {
1.1070 raeburn 4581: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4582: if (!defined($username) && !defined($domain)) {
4583: return;
4584: }
1.1096 raeburn 4585: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4586: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4587: }
4588:
4589: # ------------------------------------------------------------ Syllabus Wrapper
4590:
4591: sub syllabuswrapper {
1.707 bisitz 4592: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4593: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4594: }
1.14 harris41 4595:
1.1397 raeburn 4596: # -----------------------------------------------------------------------------
4597:
1.1396 raeburn 4598: sub aboutme_on {
4599: my ($uname,$udom)=@_;
4600: unless ($uname) { $uname=$env{'user.name'}; }
4601: unless ($udom) { $udom=$env{'user.domain'}; }
4602: return if ($udom eq 'public' && $uname eq 'public');
4603: my $hashkey=$uname.':'.$udom;
4604: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4605: if ($cached) {
4606: return $aboutme;
4607: }
4608: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4609: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4610: return $aboutme;
4611: }
4612:
4613: sub devalidate_aboutme_cache {
4614: my ($uname,$udom)=@_;
4615: if (!$udom) { $udom =$env{'user.domain'}; }
4616: if (!$uname) { $uname=$env{'user.name'}; }
4617: return if ($udom eq 'public' && $uname eq 'public');
4618: my $id=$uname.':'.$udom;
4619: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4620: }
4621:
1.208 matthew 4622: sub track_student_link {
1.887 raeburn 4623: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4624: my $link ="/adm/trackstudent?";
1.208 matthew 4625: my $title = 'View recent activity';
4626: if (defined($sname) && $sname !~ /^\s*$/ &&
4627: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4628: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4629: $title .= ' of this student';
1.268 albertel 4630: }
1.208 matthew 4631: if (defined($target) && $target !~ /^\s*$/) {
4632: $target = qq{target="$target"};
4633: } else {
4634: $target = '';
4635: }
1.268 albertel 4636: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4637: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4638: $title = &mt($title);
4639: $linktext = &mt($linktext);
1.448 albertel 4640: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4641: &help_open_topic('View_recent_activity');
1.208 matthew 4642: }
4643:
1.781 raeburn 4644: sub slot_reservations_link {
4645: my ($linktext,$sname,$sdom,$target) = @_;
4646: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4647: my $title = 'View slot reservation history';
4648: if (defined($sname) && $sname !~ /^\s*$/ &&
4649: defined($sdom) && $sdom !~ /^\s*$/) {
4650: $link .= "&uname=$sname&udom=$sdom";
4651: $title .= ' of this student';
4652: }
4653: if (defined($target) && $target !~ /^\s*$/) {
4654: $target = qq{target="$target"};
4655: } else {
4656: $target = '';
4657: }
4658: $title = &mt($title);
4659: $linktext = &mt($linktext);
4660: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4661: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4662:
4663: }
4664:
1.508 www 4665: # ===================================================== Display a student photo
4666:
4667:
1.509 albertel 4668: sub student_image_tag {
1.508 www 4669: my ($domain,$user)=@_;
4670: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4671: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4672: return '<img src="'.$imgsrc.'" align="right" />';
4673: } else {
4674: return '';
4675: }
4676: }
4677:
1.112 bowersj2 4678: =pod
4679:
4680: =back
4681:
4682: =head1 Access .tab File Data
4683:
4684: =over 4
4685:
1.648 raeburn 4686: =item * &languageids()
1.112 bowersj2 4687:
4688: returns list of all language ids
4689:
4690: =cut
4691:
1.14 harris41 4692: sub languageids {
1.16 harris41 4693: return sort(keys(%language));
1.14 harris41 4694: }
4695:
1.112 bowersj2 4696: =pod
4697:
1.648 raeburn 4698: =item * &languagedescription()
1.112 bowersj2 4699:
4700: returns description of a specified language id
4701:
4702: =cut
4703:
1.14 harris41 4704: sub languagedescription {
1.125 www 4705: my $code=shift;
4706: return ($supported_language{$code}?'* ':'').
4707: $language{$code}.
1.126 www 4708: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4709: }
4710:
1.1048 foxr 4711: =pod
4712:
4713: =item * &plainlanguagedescription
4714:
4715: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4716: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4717:
4718: =cut
4719:
1.145 www 4720: sub plainlanguagedescription {
4721: my $code=shift;
4722: return $language{$code};
4723: }
4724:
1.1048 foxr 4725: =pod
4726:
4727: =item * &supportedlanguagecode
4728:
4729: Returns the supported language code (e.g. sptutf maps to pt) given a language
4730: code.
4731:
4732: =cut
4733:
1.145 www 4734: sub supportedlanguagecode {
4735: my $code=shift;
4736: return $supported_language{$code};
1.97 www 4737: }
4738:
1.112 bowersj2 4739: =pod
4740:
1.1048 foxr 4741: =item * &latexlanguage()
4742:
4743: Given a language key code returns the correspondnig language to use
4744: to select the correct hyphenation on LaTeX printouts. This is undef if there
4745: is no supported hyphenation for the language code.
4746:
4747: =cut
4748:
4749: sub latexlanguage {
4750: my $code = shift;
4751: return $latex_language{$code};
4752: }
4753:
4754: =pod
4755:
4756: =item * &latexhyphenation()
4757:
4758: Same as above but what's supplied is the language as it might be stored
4759: in the metadata.
4760:
4761: =cut
4762:
4763: sub latexhyphenation {
4764: my $key = shift;
4765: return $latex_language_bykey{$key};
4766: }
4767:
4768: =pod
4769:
1.648 raeburn 4770: =item * ©rightids()
1.112 bowersj2 4771:
4772: returns list of all copyrights
4773:
4774: =cut
4775:
4776: sub copyrightids {
4777: return sort(keys(%cprtag));
4778: }
4779:
4780: =pod
4781:
1.648 raeburn 4782: =item * ©rightdescription()
1.112 bowersj2 4783:
4784: returns description of a specified copyright id
4785:
4786: =cut
4787:
4788: sub copyrightdescription {
1.166 www 4789: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4790: }
1.197 matthew 4791:
4792: =pod
4793:
1.648 raeburn 4794: =item * &source_copyrightids()
1.192 taceyjo1 4795:
4796: returns list of all source copyrights
4797:
4798: =cut
4799:
4800: sub source_copyrightids {
4801: return sort(keys(%scprtag));
4802: }
4803:
4804: =pod
4805:
1.648 raeburn 4806: =item * &source_copyrightdescription()
1.192 taceyjo1 4807:
4808: returns description of a specified source copyright id
4809:
4810: =cut
4811:
4812: sub source_copyrightdescription {
4813: return &mt($scprtag{shift(@_)});
4814: }
1.112 bowersj2 4815:
4816: =pod
4817:
1.648 raeburn 4818: =item * &filecategories()
1.112 bowersj2 4819:
4820: returns list of all file categories
4821:
4822: =cut
4823:
4824: sub filecategories {
4825: return sort(keys(%category_extensions));
4826: }
4827:
4828: =pod
4829:
1.648 raeburn 4830: =item * &filecategorytypes()
1.112 bowersj2 4831:
4832: returns list of file types belonging to a given file
4833: category
4834:
4835: =cut
4836:
4837: sub filecategorytypes {
1.356 albertel 4838: my ($cat) = @_;
1.1248 raeburn 4839: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4840: return @{$category_extensions{lc($cat)}};
4841: } else {
4842: return ();
4843: }
1.112 bowersj2 4844: }
4845:
4846: =pod
4847:
1.648 raeburn 4848: =item * &fileembstyle()
1.112 bowersj2 4849:
4850: returns embedding style for a specified file type
4851:
4852: =cut
4853:
4854: sub fileembstyle {
4855: return $fe{lc(shift(@_))};
1.169 www 4856: }
4857:
1.351 www 4858: sub filemimetype {
4859: return $fm{lc(shift(@_))};
4860: }
4861:
1.169 www 4862:
4863: sub filecategoryselect {
4864: my ($name,$value)=@_;
1.189 matthew 4865: return &select_form($value,$name,
1.970 raeburn 4866: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4867: }
4868:
4869: =pod
4870:
1.648 raeburn 4871: =item * &filedescription()
1.112 bowersj2 4872:
4873: returns description for a specified file type
4874:
4875: =cut
4876:
4877: sub filedescription {
1.188 matthew 4878: my $file_description = $fd{lc(shift())};
4879: $file_description =~ s:([\[\]]):~$1:g;
4880: return &mt($file_description);
1.112 bowersj2 4881: }
4882:
4883: =pod
4884:
1.648 raeburn 4885: =item * &filedescriptionex()
1.112 bowersj2 4886:
4887: returns description for a specified file type with
4888: extra formatting
4889:
4890: =cut
4891:
4892: sub filedescriptionex {
4893: my $ex=shift;
1.188 matthew 4894: my $file_description = $fd{lc($ex)};
4895: $file_description =~ s:([\[\]]):~$1:g;
4896: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4897: }
4898:
4899: # End of .tab access
4900: =pod
4901:
4902: =back
4903:
4904: =cut
4905:
4906: # ------------------------------------------------------------------ File Types
4907: sub fileextensions {
4908: return sort(keys(%fe));
4909: }
4910:
1.97 www 4911: # ----------------------------------------------------------- Display Languages
4912: # returns a hash with all desired display languages
4913: #
4914:
4915: sub display_languages {
4916: my %languages=();
1.695 raeburn 4917: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4918: $languages{$lang}=1;
1.97 www 4919: }
4920: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4921: if ($env{'form.displaylanguage'}) {
1.356 albertel 4922: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4923: $languages{$lang}=1;
1.97 www 4924: }
4925: }
4926: return %languages;
1.14 harris41 4927: }
4928:
1.582 albertel 4929: sub languages {
4930: my ($possible_langs) = @_;
1.695 raeburn 4931: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4932: if (!ref($possible_langs)) {
4933: if( wantarray ) {
4934: return @preferred_langs;
4935: } else {
4936: return $preferred_langs[0];
4937: }
4938: }
4939: my %possibilities = map { $_ => 1 } (@$possible_langs);
4940: my @preferred_possibilities;
4941: foreach my $preferred_lang (@preferred_langs) {
4942: if (exists($possibilities{$preferred_lang})) {
4943: push(@preferred_possibilities, $preferred_lang);
4944: }
4945: }
4946: if( wantarray ) {
4947: return @preferred_possibilities;
4948: }
4949: return $preferred_possibilities[0];
4950: }
4951:
1.742 raeburn 4952: sub user_lang {
4953: my ($touname,$toudom,$fromcid) = @_;
4954: my @userlangs;
4955: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4956: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4957: $env{'course.'.$fromcid.'.languages'}));
4958: } else {
4959: my %langhash = &getlangs($touname,$toudom);
4960: if ($langhash{'languages'} ne '') {
4961: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4962: } else {
4963: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4964: if ($domdefs{'lang_def'} ne '') {
4965: @userlangs = ($domdefs{'lang_def'});
4966: }
4967: }
4968: }
4969: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4970: my $user_lh = Apache::localize->get_handle(@languages);
4971: return $user_lh;
4972: }
4973:
4974:
1.112 bowersj2 4975: ###############################################################
4976: ## Student Answer Attempts ##
4977: ###############################################################
4978:
4979: =pod
4980:
4981: =head1 Alternate Problem Views
4982:
4983: =over 4
4984:
1.648 raeburn 4985: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4986: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4987:
4988: Return string with previous attempt on problem. Arguments:
4989:
4990: =over 4
4991:
4992: =item * $symb: Problem, including path
4993:
4994: =item * $username: username of the desired student
4995:
4996: =item * $domain: domain of the desired student
1.14 harris41 4997:
1.112 bowersj2 4998: =item * $course: Course ID
1.14 harris41 4999:
1.112 bowersj2 5000: =item * $getattempt: Leave blank for all attempts, otherwise put
5001: something
1.14 harris41 5002:
1.112 bowersj2 5003: =item * $regexp: if string matches this regexp, the string will be
5004: sent to $gradesub
1.14 harris41 5005:
1.112 bowersj2 5006: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 5007:
1.1199 raeburn 5008: =item * $usec: section of the desired student
5009:
5010: =item * $identifier: counter for student (multiple students one problem) or
5011: problem (one student; whole sequence).
5012:
1.112 bowersj2 5013: =back
1.14 harris41 5014:
1.112 bowersj2 5015: The output string is a table containing all desired attempts, if any.
1.16 harris41 5016:
1.112 bowersj2 5017: =cut
1.1 albertel 5018:
5019: sub get_previous_attempt {
1.1199 raeburn 5020: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 5021: my $prevattempts='';
1.43 ng 5022: no strict 'refs';
1.1 albertel 5023: if ($symb) {
1.3 albertel 5024: my (%returnhash)=
5025: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 5026: if ($returnhash{'version'}) {
5027: my %lasthash=();
5028: my $version;
5029: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 5030: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
5031: if ($key =~ /\.rawrndseed$/) {
5032: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
5033: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
5034: } else {
5035: $lasthash{$key}=$returnhash{$version.':'.$key};
5036: }
1.19 harris41 5037: }
1.1 albertel 5038: }
1.596 albertel 5039: $prevattempts=&start_data_table().&start_data_table_header_row();
5040: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 5041: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 5042: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 5043: foreach my $key (sort(keys(%lasthash))) {
5044: my ($ign,@parts) = split(/\./,$key);
1.41 ng 5045: if ($#parts > 0) {
1.31 albertel 5046: my $data=$parts[-1];
1.989 raeburn 5047: next if ($data eq 'foilorder');
1.31 albertel 5048: pop(@parts);
1.1010 www 5049: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 5050: if ($data eq 'type') {
5051: unless ($showsurv) {
5052: my $id = join(',',@parts);
5053: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 5054: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
5055: $lasthidden{$ign.'.'.$id} = 1;
5056: }
1.945 raeburn 5057: }
1.1199 raeburn 5058: if ($identifier ne '') {
5059: my $id = join(',',@parts);
5060: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
5061: $domain,$username,$usec,undef,$course) =~ /^no/) {
5062: $hidestatus{$ign.'.'.$id} = 1;
5063: }
5064: }
5065: } elsif ($data eq 'regrader') {
5066: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 5067: my $id = join(',',@parts);
5068: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 5069: }
1.1010 www 5070: }
1.31 albertel 5071: } else {
1.41 ng 5072: if ($#parts == 0) {
5073: $prevattempts.='<th>'.$parts[0].'</th>';
5074: } else {
5075: $prevattempts.='<th>'.$ign.'</th>';
5076: }
1.31 albertel 5077: }
1.16 harris41 5078: }
1.596 albertel 5079: $prevattempts.=&end_data_table_header_row();
1.40 ng 5080: if ($getattempt eq '') {
1.1199 raeburn 5081: my (%solved,%resets,%probstatus);
1.1200 raeburn 5082: if (($identifier ne '') && (keys(%regraded) > 0)) {
5083: for ($version=1;$version<=$returnhash{'version'};$version++) {
5084: foreach my $id (keys(%regraded)) {
5085: if (($returnhash{$version.':'.$id.'.regrader'}) &&
5086: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
5087: ($returnhash{$version.':'.$id.'.award'} eq '')) {
5088: push(@{$resets{$id}},$version);
1.1199 raeburn 5089: }
5090: }
5091: }
1.1200 raeburn 5092: }
5093: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 5094: my (@hidden,@unsolved);
1.945 raeburn 5095: if (%typeparts) {
5096: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 5097: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
5098: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 5099: push(@hidden,$id);
1.1199 raeburn 5100: } elsif ($identifier ne '') {
5101: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
5102: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
5103: ($hidestatus{$id})) {
1.1200 raeburn 5104: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 5105: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
5106: push(@{$solved{$id}},$version);
5107: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
5108: (ref($solved{$id}) eq 'ARRAY')) {
5109: my $skip;
5110: if (ref($resets{$id}) eq 'ARRAY') {
5111: foreach my $reset (@{$resets{$id}}) {
5112: if ($reset > $solved{$id}[-1]) {
5113: $skip=1;
5114: last;
5115: }
5116: }
5117: }
5118: unless ($skip) {
5119: my ($ign,$partslist) = split(/\./,$id,2);
5120: push(@unsolved,$partslist);
5121: }
5122: }
5123: }
1.945 raeburn 5124: }
5125: }
5126: }
5127: $prevattempts.=&start_data_table_row().
1.1199 raeburn 5128: '<td>'.&mt('Transaction [_1]',$version);
5129: if (@unsolved) {
5130: $prevattempts .= '<span class="LC_nobreak"><label>'.
5131: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
5132: &mt('Hide').'</label></span>';
5133: }
5134: $prevattempts .= '</td>';
1.945 raeburn 5135: if (@hidden) {
5136: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5137: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5138: my $hide;
5139: foreach my $id (@hidden) {
5140: if ($key =~ /^\Q$id\E/) {
5141: $hide = 1;
5142: last;
5143: }
5144: }
5145: if ($hide) {
5146: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5147: if (($data eq 'award') || ($data eq 'awarddetail')) {
5148: my $value = &format_previous_attempt_value($key,
5149: $returnhash{$version.':'.$key});
1.1173 kruse 5150: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5151: } else {
5152: $prevattempts.='<td> </td>';
5153: }
5154: } else {
5155: if ($key =~ /\./) {
1.1212 raeburn 5156: my $value = $returnhash{$version.':'.$key};
5157: if ($key =~ /\.rndseed$/) {
5158: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5159: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5160: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5161: }
5162: }
5163: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5164: ' </td>';
1.945 raeburn 5165: } else {
5166: $prevattempts.='<td> </td>';
5167: }
5168: }
5169: }
5170: } else {
5171: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5172: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 5173: my $value = $returnhash{$version.':'.$key};
5174: if ($key =~ /\.rndseed$/) {
5175: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5176: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5177: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5178: }
5179: }
5180: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5181: ' </td>';
1.945 raeburn 5182: }
5183: }
5184: $prevattempts.=&end_data_table_row();
1.40 ng 5185: }
1.1 albertel 5186: }
1.945 raeburn 5187: my @currhidden = keys(%lasthidden);
1.596 albertel 5188: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 5189: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5190: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5191: if (%typeparts) {
5192: my $hidden;
5193: foreach my $id (@currhidden) {
5194: if ($key =~ /^\Q$id\E/) {
5195: $hidden = 1;
5196: last;
5197: }
5198: }
5199: if ($hidden) {
5200: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5201: if (($data eq 'award') || ($data eq 'awarddetail')) {
5202: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5203: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5204: $value = &$gradesub($value);
5205: }
1.1173 kruse 5206: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5207: } else {
5208: $prevattempts.='<td> </td>';
5209: }
5210: } else {
5211: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5212: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5213: $value = &$gradesub($value);
5214: }
1.1173 kruse 5215: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5216: }
5217: } else {
5218: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5219: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5220: $value = &$gradesub($value);
5221: }
1.1173 kruse 5222: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5223: }
1.16 harris41 5224: }
1.596 albertel 5225: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5226: } else {
1.1305 raeburn 5227: my $msg;
5228: if ($symb =~ /ext\.tool$/) {
5229: $msg = &mt('No grade passed back.');
5230: } else {
5231: $msg = &mt('Nothing submitted - no attempts.');
5232: }
1.596 albertel 5233: $prevattempts=
5234: &start_data_table().&start_data_table_row().
1.1305 raeburn 5235: '<td>'.$msg.'</td>'.
1.596 albertel 5236: &end_data_table_row().&end_data_table();
1.1 albertel 5237: }
5238: } else {
1.596 albertel 5239: $prevattempts=
5240: &start_data_table().&start_data_table_row().
5241: '<td>'.&mt('No data.').'</td>'.
5242: &end_data_table_row().&end_data_table();
1.1 albertel 5243: }
1.10 albertel 5244: }
5245:
1.581 albertel 5246: sub format_previous_attempt_value {
5247: my ($key,$value) = @_;
1.1011 www 5248: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5249: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5250: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5251: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5252: } elsif ($key =~ /answerstring$/) {
5253: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5254: my @answer = %answers;
5255: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5256: my @anskeys = sort(keys(%answers));
5257: if (@anskeys == 1) {
5258: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5259: if ($answer =~ m{\0}) {
5260: $answer =~ s{\0}{,}g;
1.988 raeburn 5261: }
5262: my $tag_internal_answer_name = 'INTERNAL';
5263: if ($anskeys[0] eq $tag_internal_answer_name) {
5264: $value = $answer;
5265: } else {
5266: $value = $anskeys[0].'='.$answer;
5267: }
5268: } else {
5269: foreach my $ans (@anskeys) {
5270: my $answer = $answers{$ans};
1.1001 raeburn 5271: if ($answer =~ m{\0}) {
5272: $answer =~ s{\0}{,}g;
1.988 raeburn 5273: }
5274: $value .= $ans.'='.$answer.'<br />';;
5275: }
5276: }
1.581 albertel 5277: } else {
1.1173 kruse 5278: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5279: }
5280: return $value;
5281: }
5282:
5283:
1.107 albertel 5284: sub relative_to_absolute {
5285: my ($url,$output)=@_;
5286: my $parser=HTML::TokeParser->new(\$output);
5287: my $token;
5288: my $thisdir=$url;
5289: my @rlinks=();
5290: while ($token=$parser->get_token) {
5291: if ($token->[0] eq 'S') {
5292: if ($token->[1] eq 'a') {
5293: if ($token->[2]->{'href'}) {
5294: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5295: }
5296: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5297: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5298: } elsif ($token->[1] eq 'base') {
5299: $thisdir=$token->[2]->{'href'};
5300: }
5301: }
5302: }
5303: $thisdir=~s-/[^/]*$--;
1.356 albertel 5304: foreach my $link (@rlinks) {
1.726 raeburn 5305: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5306: ($link=~/^\//) ||
5307: ($link=~/^javascript:/i) ||
5308: ($link=~/^mailto:/i) ||
5309: ($link=~/^\#/)) {
5310: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5311: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5312: }
5313: }
5314: # -------------------------------------------------- Deal with Applet codebases
5315: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5316: return $output;
5317: }
5318:
1.112 bowersj2 5319: =pod
5320:
1.648 raeburn 5321: =item * &get_student_view()
1.112 bowersj2 5322:
5323: show a snapshot of what student was looking at
5324:
5325: =cut
5326:
1.10 albertel 5327: sub get_student_view {
1.186 albertel 5328: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5329: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5330: my (%form);
1.10 albertel 5331: my @elements=('symb','courseid','domain','username');
5332: foreach my $element (@elements) {
1.186 albertel 5333: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5334: }
1.186 albertel 5335: if (defined($moreenv)) {
5336: %form=(%form,%{$moreenv});
5337: }
1.236 albertel 5338: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5339: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5340: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5341: $feedurl =~ s{^/adm/wrapper}{};
5342: }
1.650 www 5343: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5344: $userview=~s/\<body[^\>]*\>//gi;
5345: $userview=~s/\<\/body\>//gi;
5346: $userview=~s/\<html\>//gi;
5347: $userview=~s/\<\/html\>//gi;
5348: $userview=~s/\<head\>//gi;
5349: $userview=~s/\<\/head\>//gi;
1.1460 raeburn 5350: $userview=~s/\Q<div class="LC_landmark" role="main"\E/<div class="LC_landmark"/;
1.11 albertel 5351: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5352: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5353: if (wantarray) {
5354: return ($userview,$response);
5355: } else {
5356: return $userview;
5357: }
5358: }
5359:
5360: sub get_student_view_with_retries {
5361: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5362:
5363: my $ok = 0; # True if we got a good response.
5364: my $content;
5365: my $response;
5366:
5367: # Try to get the student_view done. within the retries count:
5368:
5369: do {
5370: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5371: $ok = $response->is_success;
5372: if (!$ok) {
5373: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5374: }
5375: $retries--;
5376: } while (!$ok && ($retries > 0));
5377:
5378: if (!$ok) {
5379: $content = ''; # On error return an empty content.
5380: }
1.651 www 5381: if (wantarray) {
5382: return ($content, $response);
5383: } else {
5384: return $content;
5385: }
1.11 albertel 5386: }
5387:
1.1349 raeburn 5388: sub css_links {
5389: my ($currsymb,$level) = @_;
5390: my ($links,@symbs,%cssrefs,%httpref);
5391: if ($level eq 'map') {
5392: my $navmap = Apache::lonnavmaps::navmap->new();
5393: if (ref($navmap)) {
5394: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5395: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5396: foreach my $res (@resources) {
5397: if (ref($res) && $res->symb()) {
5398: push(@symbs,$res->symb());
5399: }
5400: }
5401: }
5402: } else {
5403: @symbs = ($currsymb);
5404: }
5405: foreach my $symb (@symbs) {
5406: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5407: if ($css_href =~ /\S/) {
5408: unless ($css_href =~ m{https?://}) {
5409: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5410: my $proburl = &Apache::lonnet::clutter($url);
5411: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5412: unless ($css_href =~ m{^/}) {
5413: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5414: }
5415: if ($css_href =~ m{^/(res|uploaded)/}) {
5416: unless (($httpref{'httpref.'.$css_href}) ||
5417: (&Apache::lonnet::is_on_map($css_href))) {
5418: my $thisurl = $proburl;
5419: if ($env{'httpref.'.$proburl}) {
5420: $thisurl = $env{'httpref.'.$proburl};
5421: }
5422: $httpref{'httpref.'.$css_href} = $thisurl;
5423: }
5424: }
5425: }
5426: $cssrefs{$css_href} = 1;
5427: }
5428: }
5429: if (keys(%httpref)) {
5430: &Apache::lonnet::appenv(\%httpref);
5431: }
5432: if (keys(%cssrefs)) {
5433: foreach my $css_href (keys(%cssrefs)) {
5434: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5435: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5436: }
5437: }
5438: return $links;
5439: }
5440:
1.112 bowersj2 5441: =pod
5442:
1.648 raeburn 5443: =item * &get_student_answers()
1.112 bowersj2 5444:
5445: show a snapshot of how student was answering problem
5446:
5447: =cut
5448:
1.11 albertel 5449: sub get_student_answers {
1.100 sakharuk 5450: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5451: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5452: my (%moreenv);
1.11 albertel 5453: my @elements=('symb','courseid','domain','username');
5454: foreach my $element (@elements) {
1.186 albertel 5455: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5456: }
1.186 albertel 5457: $moreenv{'grade_target'}='answer';
5458: %moreenv=(%form,%moreenv);
1.497 raeburn 5459: $feedurl = &Apache::lonnet::clutter($feedurl);
5460: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5461: return $userview;
1.1 albertel 5462: }
1.116 albertel 5463:
5464: =pod
5465:
5466: =item * &submlink()
5467:
1.242 albertel 5468: Inputs: $text $uname $udom $symb $target
1.116 albertel 5469:
5470: Returns: A link to grades.pm such as to see the SUBM view of a student
5471:
5472: =cut
5473:
5474: ###############################################
5475: sub submlink {
1.242 albertel 5476: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5477: if (!($uname && $udom)) {
5478: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5479: &Apache::lonnet::whichuser($symb);
1.116 albertel 5480: if (!$symb) { $symb=$cursymb; }
5481: }
1.254 matthew 5482: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5483: $symb=&escape($symb);
1.960 bisitz 5484: if ($target) { $target=" target=\"$target\""; }
5485: return
5486: '<a href="/adm/grades?command=submission'.
5487: '&symb='.$symb.
5488: '&student='.$uname.
5489: '&userdom='.$udom.'"'.
5490: $target.'>'.$text.'</a>';
1.242 albertel 5491: }
5492: ##############################################
5493:
5494: =pod
5495:
5496: =item * &pgrdlink()
5497:
5498: Inputs: $text $uname $udom $symb $target
5499:
5500: Returns: A link to grades.pm such as to see the PGRD view of a student
5501:
5502: =cut
5503:
5504: ###############################################
5505: sub pgrdlink {
5506: my $link=&submlink(@_);
5507: $link=~s/(&command=submission)/$1&showgrading=yes/;
5508: return $link;
5509: }
5510: ##############################################
5511:
5512: =pod
5513:
5514: =item * &pprmlink()
5515:
5516: Inputs: $text $uname $udom $symb $target
5517:
5518: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5519: student and a specific resource
1.242 albertel 5520:
5521: =cut
5522:
5523: ###############################################
5524: sub pprmlink {
5525: my ($text,$uname,$udom,$symb,$target)=@_;
5526: if (!($uname && $udom)) {
5527: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5528: &Apache::lonnet::whichuser($symb);
1.242 albertel 5529: if (!$symb) { $symb=$cursymb; }
5530: }
1.254 matthew 5531: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5532: $symb=&escape($symb);
1.242 albertel 5533: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5534: return '<a href="/adm/parmset?command=set&'.
5535: 'symb='.$symb.'&uname='.$uname.
5536: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5537: }
5538: ##############################################
1.37 matthew 5539:
1.112 bowersj2 5540: =pod
5541:
5542: =back
5543:
5544: =cut
5545:
1.37 matthew 5546: ###############################################
1.51 www 5547:
5548:
5549: sub timehash {
1.687 raeburn 5550: my ($thistime) = @_;
5551: my $timezone = &Apache::lonlocal::gettimezone();
5552: my $dt = DateTime->from_epoch(epoch => $thistime)
5553: ->set_time_zone($timezone);
5554: my $wday = $dt->day_of_week();
5555: if ($wday == 7) { $wday = 0; }
5556: return ( 'second' => $dt->second(),
5557: 'minute' => $dt->minute(),
5558: 'hour' => $dt->hour(),
5559: 'day' => $dt->day_of_month(),
5560: 'month' => $dt->month(),
5561: 'year' => $dt->year(),
5562: 'weekday' => $wday,
5563: 'dayyear' => $dt->day_of_year(),
5564: 'dlsav' => $dt->is_dst() );
1.51 www 5565: }
5566:
1.370 www 5567: sub utc_string {
5568: my ($date)=@_;
1.371 www 5569: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5570: }
5571:
1.51 www 5572: sub maketime {
5573: my %th=@_;
1.687 raeburn 5574: my ($epoch_time,$timezone,$dt);
5575: $timezone = &Apache::lonlocal::gettimezone();
5576: eval {
5577: $dt = DateTime->new( year => $th{'year'},
5578: month => $th{'month'},
5579: day => $th{'day'},
5580: hour => $th{'hour'},
5581: minute => $th{'minute'},
5582: second => $th{'second'},
5583: time_zone => $timezone,
5584: );
5585: };
5586: if (!$@) {
5587: $epoch_time = $dt->epoch;
5588: if ($epoch_time) {
5589: return $epoch_time;
5590: }
5591: }
1.51 www 5592: return POSIX::mktime(
5593: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5594: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5595: }
5596:
5597: #########################################
1.51 www 5598:
5599: sub findallcourses {
1.482 raeburn 5600: my ($roles,$uname,$udom) = @_;
1.355 albertel 5601: my %roles;
5602: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5603: my %courses;
1.51 www 5604: my $now=time;
1.482 raeburn 5605: if (!defined($uname)) {
5606: $uname = $env{'user.name'};
5607: }
5608: if (!defined($udom)) {
5609: $udom = $env{'user.domain'};
5610: }
5611: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5612: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5613: if (!%roles) {
5614: %roles = (
5615: cc => 1,
1.907 raeburn 5616: co => 1,
1.482 raeburn 5617: in => 1,
5618: ep => 1,
5619: ta => 1,
5620: cr => 1,
5621: st => 1,
5622: );
5623: }
5624: foreach my $entry (keys(%roleshash)) {
5625: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5626: if ($trole =~ /^cr/) {
5627: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5628: } else {
5629: next if (!exists($roles{$trole}));
5630: }
5631: if ($tend) {
5632: next if ($tend < $now);
5633: }
5634: if ($tstart) {
5635: next if ($tstart > $now);
5636: }
1.1058 raeburn 5637: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5638: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5639: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5640: if ($secpart eq '') {
5641: ($cnum,$role) = split(/_/,$cnumpart);
5642: $sec = 'none';
1.1058 raeburn 5643: $value .= $cnum.'/';
1.482 raeburn 5644: } else {
5645: $cnum = $cnumpart;
5646: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5647: $value .= $cnum.'/'.$sec;
5648: }
5649: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5650: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5651: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5652: }
5653: } else {
5654: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5655: }
1.482 raeburn 5656: }
5657: } else {
5658: foreach my $key (keys(%env)) {
1.483 albertel 5659: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5660: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5661: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5662: next if ($role eq 'ca' || $role eq 'aa');
5663: next if (%roles && !exists($roles{$role}));
5664: my ($starttime,$endtime)=split(/\./,$env{$key});
5665: my $active=1;
5666: if ($starttime) {
5667: if ($now<$starttime) { $active=0; }
5668: }
5669: if ($endtime) {
5670: if ($now>$endtime) { $active=0; }
5671: }
5672: if ($active) {
1.1058 raeburn 5673: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5674: if ($sec eq '') {
5675: $sec = 'none';
1.1058 raeburn 5676: } else {
5677: $value .= $sec;
5678: }
5679: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5680: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5681: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5682: }
5683: } else {
5684: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5685: }
1.474 raeburn 5686: }
5687: }
1.51 www 5688: }
5689: }
1.474 raeburn 5690: return %courses;
1.51 www 5691: }
1.37 matthew 5692:
1.54 www 5693: ###############################################
1.474 raeburn 5694:
5695: sub blockcheck {
1.1372 raeburn 5696: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5697: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5698: my ($has_evb,$check_ipaccess);
5699: my $dom = $env{'user.domain'};
5700: if ($env{'request.course.id'}) {
5701: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5702: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5703: my $checkrole = "cm./$cdom/$cnum";
5704: my $sec = $env{'request.course.sec'};
5705: if ($sec ne '') {
5706: $checkrole .= "/$sec";
5707: }
5708: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5709: ($env{'request.role'} !~ /^st/)) {
5710: $has_evb = 1;
5711: }
5712: unless ($has_evb) {
5713: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
1.1444 raeburn 5714: ($activity eq 'index') || ($activity eq 'boards') || ($activity eq 'groups') ||
5715: ($activity eq 'chat')) {
1.1372 raeburn 5716: if ($udom eq $cdom) {
5717: $check_ipaccess = 1;
5718: }
5719: }
5720: }
1.1375 raeburn 5721: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5722: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5723: my $checkrole;
5724: if ($env{'request.role.domain'} eq '') {
5725: $checkrole = "cm./$env{'user.domain'}/";
5726: } else {
5727: $checkrole = "cm./$env{'request.role.domain'}/";
5728: }
5729: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5730: $has_evb = 1;
5731: }
1.1372 raeburn 5732: }
5733: unless ($has_evb || $check_ipaccess) {
5734: my @machinedoms = &Apache::lonnet::current_machine_domains();
5735: if (($dom eq 'public') && ($activity eq 'port')) {
5736: $dom = $udom;
5737: }
5738: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5739: $check_ipaccess = 1;
5740: } else {
5741: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5742: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5743: my $prim = &Apache::lonnet::domain($dom,'primary');
5744: my $intdom = &Apache::lonnet::internet_dom($prim);
5745: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5746: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5747: $check_ipaccess = 1;
5748: }
5749: }
5750: }
5751: }
5752: if ($check_ipaccess) {
5753: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5754: unless (defined($cached)) {
5755: my %domconfig =
5756: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5757: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5758: }
5759: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5760: foreach my $id (keys(%{$ipaccessref})) {
5761: if (ref($ipaccessref->{$id}) eq 'HASH') {
5762: my $range = $ipaccessref->{$id}->{'ip'};
5763: if ($range) {
5764: if (&Apache::lonnet::ip_match($clientip,$range)) {
5765: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5766: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5767: return ('','','',$id,$dom);
5768: last;
5769: }
5770: }
5771: }
5772: }
5773: }
5774: }
5775: }
5776: }
1.1373 raeburn 5777: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5778: return ();
5779: }
1.1372 raeburn 5780: }
1.1189 raeburn 5781: if (defined($udom) && defined($uname)) {
5782: # If uname and udom are for a course, check for blocks in the course.
5783: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5784: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5785: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5786: return ($startblock,$endblock,$triggerblock);
5787: }
5788: } else {
1.490 raeburn 5789: $udom = $env{'user.domain'};
5790: $uname = $env{'user.name'};
5791: }
5792:
1.502 raeburn 5793: my $startblock = 0;
5794: my $endblock = 0;
1.1062 raeburn 5795: my $triggerblock = '';
1.1373 raeburn 5796: my %live_courses;
5797: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5798: %live_courses = &findallcourses(undef,$uname,$udom);
5799: }
1.474 raeburn 5800:
1.490 raeburn 5801: # If uname is for a user, and activity is course-specific, i.e.,
5802: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5803:
1.490 raeburn 5804: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5805: $activity eq 'groups' || $activity eq 'printout' ||
1.1444 raeburn 5806: $activity eq 'search' || $activity eq 'index' ||
5807: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5808: ($env{'request.course.id'})) {
1.490 raeburn 5809: foreach my $key (keys(%live_courses)) {
5810: if ($key ne $env{'request.course.id'}) {
5811: delete($live_courses{$key});
5812: }
5813: }
5814: }
5815:
5816: my $otheruser = 0;
5817: my %own_courses;
5818: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5819: # Resource belongs to user other than current user.
5820: $otheruser = 1;
5821: # Gather courses for current user
5822: %own_courses =
5823: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5824: }
5825:
5826: # Gather active course roles - course coordinator, instructor,
5827: # exam proctor, ta, student, or custom role.
1.474 raeburn 5828:
5829: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5830: my ($cdom,$cnum);
5831: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5832: $cdom = $env{'course.'.$course.'.domain'};
5833: $cnum = $env{'course.'.$course.'.num'};
5834: } else {
1.490 raeburn 5835: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5836: }
5837: my $no_ownblock = 0;
5838: my $no_userblock = 0;
1.533 raeburn 5839: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5840: # Check if current user has 'evb' priv for this
5841: if (defined($own_courses{$course})) {
5842: foreach my $sec (keys(%{$own_courses{$course}})) {
5843: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5844: if ($sec ne 'none') {
5845: $checkrole .= '/'.$sec;
5846: }
5847: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5848: $no_ownblock = 1;
5849: last;
5850: }
5851: }
5852: }
5853: # if they have 'evb' priv and are currently not playing student
5854: next if (($no_ownblock) &&
5855: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5856: }
1.474 raeburn 5857: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5858: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5859: if ($sec ne 'none') {
1.482 raeburn 5860: $checkrole .= '/'.$sec;
1.474 raeburn 5861: }
1.490 raeburn 5862: if ($otheruser) {
5863: # Resource belongs to user other than current user.
5864: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5865: my (%allroles,%userroles);
5866: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5867: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5868: my ($trole,$tdom,$tnum,$tsec);
5869: if ($entry =~ /^cr/) {
5870: ($trole,$tdom,$tnum,$tsec) =
5871: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5872: } else {
5873: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5874: }
5875: my ($spec,$area,$trest);
5876: $area = '/'.$tdom.'/'.$tnum;
5877: $trest = $tnum;
5878: if ($tsec ne '') {
5879: $area .= '/'.$tsec;
5880: $trest .= '/'.$tsec;
5881: }
5882: $spec = $trole.'.'.$area;
5883: if ($trole =~ /^cr/) {
5884: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5885: $tdom,$spec,$trest,$area);
5886: } else {
5887: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5888: $tdom,$spec,$trest,$area);
5889: }
5890: }
1.1276 raeburn 5891: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5892: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5893: if ($1) {
5894: $no_userblock = 1;
5895: last;
5896: }
1.486 raeburn 5897: }
5898: }
1.490 raeburn 5899: } else {
5900: # Resource belongs to current user
5901: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5902: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5903: $no_ownblock = 1;
5904: last;
5905: }
1.474 raeburn 5906: }
5907: }
5908: # if they have the evb priv and are currently not playing student
1.482 raeburn 5909: next if (($no_ownblock) &&
1.491 albertel 5910: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5911: next if ($no_userblock);
1.474 raeburn 5912:
1.1303 raeburn 5913: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5914: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5915:
1.1062 raeburn 5916: my ($start,$end,$trigger) =
1.1347 raeburn 5917: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5918: if (($start != 0) &&
5919: (($startblock == 0) || ($startblock > $start))) {
5920: $startblock = $start;
1.1062 raeburn 5921: if ($trigger ne '') {
5922: $triggerblock = $trigger;
5923: }
1.502 raeburn 5924: }
5925: if (($end != 0) &&
5926: (($endblock == 0) || ($endblock < $end))) {
5927: $endblock = $end;
1.1062 raeburn 5928: if ($trigger ne '') {
5929: $triggerblock = $trigger;
5930: }
1.502 raeburn 5931: }
1.490 raeburn 5932: }
1.1062 raeburn 5933: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5934: }
5935:
5936: sub get_blocks {
1.1347 raeburn 5937: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5938: my $startblock = 0;
5939: my $endblock = 0;
1.1062 raeburn 5940: my $triggerblock = '';
1.490 raeburn 5941: my $course = $cdom.'_'.$cnum;
5942: $setters->{$course} = {};
5943: $setters->{$course}{'staff'} = [];
5944: $setters->{$course}{'times'} = [];
1.1062 raeburn 5945: $setters->{$course}{'triggers'} = [];
5946: my (@blockers,%triggered);
5947: my $now = time;
5948: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5949: if ($activity eq 'docs') {
1.1348 raeburn 5950: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5951: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5952: $blocked = 1;
5953: $nosymbcache = 1;
1.1348 raeburn 5954: $noenccheck = 1;
1.1347 raeburn 5955: }
1.1348 raeburn 5956: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5957: foreach my $block (@blockers) {
5958: if ($block =~ /^firstaccess____(.+)$/) {
5959: my $item = $1;
5960: my $type = 'map';
5961: my $timersymb = $item;
5962: if ($item eq 'course') {
5963: $type = 'course';
5964: } elsif ($item =~ /___\d+___/) {
5965: $type = 'resource';
5966: } else {
5967: $timersymb = &Apache::lonnet::symbread($item);
5968: }
5969: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5970: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5971: $triggered{$block} = {
5972: start => $start,
5973: end => $end,
5974: type => $type,
5975: };
5976: }
5977: }
5978: } else {
5979: foreach my $block (keys(%commblocks)) {
5980: if ($block =~ m/^(\d+)____(\d+)$/) {
5981: my ($start,$end) = ($1,$2);
5982: if ($start <= time && $end >= time) {
5983: if (ref($commblocks{$block}) eq 'HASH') {
5984: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5985: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5986: unless(grep(/^\Q$block\E$/,@blockers)) {
5987: push(@blockers,$block);
5988: }
5989: }
5990: }
5991: }
5992: }
5993: } elsif ($block =~ /^firstaccess____(.+)$/) {
5994: my $item = $1;
5995: my $timersymb = $item;
5996: my $type = 'map';
5997: if ($item eq 'course') {
5998: $type = 'course';
5999: } elsif ($item =~ /___\d+___/) {
6000: $type = 'resource';
6001: } else {
6002: $timersymb = &Apache::lonnet::symbread($item);
6003: }
6004: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
6005: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
6006: if ($start && $end) {
6007: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 6008: if (ref($commblocks{$block}) eq 'HASH') {
6009: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
6010: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
6011: unless(grep(/^\Q$block\E$/,@blockers)) {
6012: push(@blockers,$block);
6013: $triggered{$block} = {
6014: start => $start,
6015: end => $end,
6016: type => $type,
6017: };
6018: }
6019: }
6020: }
1.1062 raeburn 6021: }
6022: }
1.490 raeburn 6023: }
1.1062 raeburn 6024: }
6025: }
6026: }
6027: foreach my $blocker (@blockers) {
6028: my ($staff_name,$staff_dom,$title,$blocks) =
6029: &parse_block_record($commblocks{$blocker});
6030: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
6031: my ($start,$end,$triggertype);
6032: if ($blocker =~ m/^(\d+)____(\d+)$/) {
6033: ($start,$end) = ($1,$2);
6034: } elsif (ref($triggered{$blocker}) eq 'HASH') {
6035: $start = $triggered{$blocker}{'start'};
6036: $end = $triggered{$blocker}{'end'};
6037: $triggertype = $triggered{$blocker}{'type'};
6038: }
6039: if ($start) {
6040: push(@{$$setters{$course}{'times'}}, [$start,$end]);
6041: if ($triggertype) {
6042: push(@{$$setters{$course}{'triggers'}},$triggertype);
6043: } else {
6044: push(@{$$setters{$course}{'triggers'}},0);
6045: }
6046: if ( ($startblock == 0) || ($startblock > $start) ) {
6047: $startblock = $start;
6048: if ($triggertype) {
6049: $triggerblock = $blocker;
1.474 raeburn 6050: }
6051: }
1.1062 raeburn 6052: if ( ($endblock == 0) || ($endblock < $end) ) {
6053: $endblock = $end;
6054: if ($triggertype) {
6055: $triggerblock = $blocker;
6056: }
6057: }
1.474 raeburn 6058: }
6059: }
1.1062 raeburn 6060: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 6061: }
6062:
6063: sub parse_block_record {
6064: my ($record) = @_;
6065: my ($setuname,$setudom,$title,$blocks);
6066: if (ref($record) eq 'HASH') {
6067: ($setuname,$setudom) = split(/:/,$record->{'setter'});
6068: $title = &unescape($record->{'event'});
6069: $blocks = $record->{'blocks'};
6070: } else {
6071: my @data = split(/:/,$record,3);
6072: if (scalar(@data) eq 2) {
6073: $title = $data[1];
6074: ($setuname,$setudom) = split(/@/,$data[0]);
6075: } else {
6076: ($setuname,$setudom,$title) = @data;
6077: }
6078: $blocks = { 'com' => 'on' };
6079: }
6080: return ($setuname,$setudom,$title,$blocks);
6081: }
6082:
1.854 kalberla 6083: sub blocking_status {
1.1372 raeburn 6084: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 6085: my %setters;
1.890 droeschl 6086:
1.1061 raeburn 6087: # check for active blocking
1.1372 raeburn 6088: if ($clientip eq '') {
6089: $clientip = &Apache::lonnet::get_requestor_ip();
6090: }
6091: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
6092: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 6093: my $blocked = 0;
1.1372 raeburn 6094: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 6095: $blocked = 1;
6096: }
1.890 droeschl 6097:
1.1061 raeburn 6098: # caller just wants to know whether a block is active
6099: if (!wantarray) { return $blocked; }
6100:
6101: # build a link to a popup window containing the details
6102: my $querystring = "?activity=$activity";
1.1351 raeburn 6103: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
6104: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 6105: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
6106: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 6107: } elsif ($activity eq 'docs') {
1.1347 raeburn 6108: my $showurl = &Apache::lonenc::check_encrypt($url);
6109: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
6110: if ($symb) {
6111: my $showsymb = &Apache::lonenc::check_encrypt($symb);
6112: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
6113: }
1.1062 raeburn 6114: }
1.1061 raeburn 6115:
6116: my $output .= <<'END_MYBLOCK';
6117: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
6118: var options = "width=" + w + ",height=" + h + ",";
6119: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
6120: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
6121: var newWin = window.open(url, wdwName, options);
6122: newWin.focus();
6123: }
1.890 droeschl 6124: END_MYBLOCK
1.854 kalberla 6125:
1.1061 raeburn 6126: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 6127:
1.1061 raeburn 6128: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 6129: my $text = &mt('Communication Blocked');
1.1217 raeburn 6130: my $class = 'LC_comblock';
1.1062 raeburn 6131: if ($activity eq 'docs') {
6132: $text = &mt('Content Access Blocked');
1.1217 raeburn 6133: $class = '';
1.1063 raeburn 6134: } elsif ($activity eq 'printout') {
6135: $text = &mt('Printing Blocked');
1.1232 raeburn 6136: } elsif ($activity eq 'passwd') {
6137: $text = &mt('Password Changing Blocked');
1.1345 raeburn 6138: } elsif ($activity eq 'grades') {
6139: $text = &mt('Gradebook Blocked');
1.1346 raeburn 6140: } elsif ($activity eq 'search') {
6141: $text = &mt('Search Blocked');
1.1444 raeburn 6142: } elsif ($activity eq 'index') {
6143: $text = &mt('Content Index Blocked');
1.1282 raeburn 6144: } elsif ($activity eq 'alert') {
6145: $text = &mt('Checking Critical Messages Blocked');
6146: } elsif ($activity eq 'reinit') {
6147: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 6148: } elsif ($activity eq 'about') {
6149: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 6150: } elsif ($activity eq 'wishlist') {
6151: $text = &mt('Access to Stored Links Blocked');
6152: } elsif ($activity eq 'annotate') {
6153: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 6154: }
1.1061 raeburn 6155: $output .= <<"END_BLOCK";
1.1217 raeburn 6156: <div class='$class'>
1.869 kalberla 6157: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6158: title='$text'>
6159: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 6160: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6161: title='$text'>$text</a>
1.867 kalberla 6162: </div>
6163:
6164: END_BLOCK
1.474 raeburn 6165:
1.1061 raeburn 6166: return ($blocked, $output);
1.854 kalberla 6167: }
1.490 raeburn 6168:
1.60 matthew 6169: ###############################################
6170:
1.682 raeburn 6171: sub check_ip_acc {
1.1201 raeburn 6172: my ($acc,$clientip)=@_;
1.682 raeburn 6173: &Apache::lonxml::debug("acc is $acc");
6174: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
6175: return 1;
6176: }
1.1339 raeburn 6177: my ($ip,$allowed);
6178: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
6179: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
6180: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
6181: } else {
1.1350 raeburn 6182: my $remote_ip = &Apache::lonnet::get_requestor_ip();
6183: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 6184: }
1.682 raeburn 6185:
6186: my $name;
1.1219 raeburn 6187: my %access = (
6188: allowfrom => 1,
6189: denyfrom => 0,
6190: );
6191: my @allows;
6192: my @denies;
6193: foreach my $item (split(',',$acc)) {
6194: $item =~ s/^\s*//;
6195: $item =~ s/\s*$//;
6196: my $pattern;
6197: if ($item =~ /^\!(.+)$/) {
6198: push(@denies,$1);
6199: } else {
6200: push(@allows,$item);
6201: }
6202: }
6203: my $numdenies = scalar(@denies);
6204: my $numallows = scalar(@allows);
6205: my $count = 0;
6206: foreach my $pattern (@denies,@allows) {
6207: $count ++;
6208: my $acctype = 'allowfrom';
6209: if ($count <= $numdenies) {
6210: $acctype = 'denyfrom';
6211: }
1.682 raeburn 6212: if ($pattern =~ /\*$/) {
6213: #35.8.*
6214: $pattern=~s/\*//;
1.1219 raeburn 6215: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6216: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6217: #35.8.3.[34-56]
6218: my $low=$2;
6219: my $high=$3;
6220: $pattern=$1;
6221: if ($ip =~ /^\Q$pattern\E/) {
6222: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6223: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6224: }
6225: } elsif ($pattern =~ /^\*/) {
6226: #*.msu.edu
6227: $pattern=~s/\*//;
6228: if (!defined($name)) {
6229: use Socket;
6230: my $netaddr=inet_aton($ip);
6231: ($name)=gethostbyaddr($netaddr,AF_INET);
6232: }
1.1219 raeburn 6233: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6234: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6235: #127.0.0.1
1.1219 raeburn 6236: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6237: } else {
6238: #some.name.com
6239: if (!defined($name)) {
6240: use Socket;
6241: my $netaddr=inet_aton($ip);
6242: ($name)=gethostbyaddr($netaddr,AF_INET);
6243: }
1.1219 raeburn 6244: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6245: }
6246: if ($allowed =~ /^(0|1)$/) { last; }
6247: }
6248: if ($allowed eq '') {
6249: if ($numdenies && !$numallows) {
6250: $allowed = 1;
6251: } else {
6252: $allowed = 0;
1.682 raeburn 6253: }
6254: }
6255: return $allowed;
6256: }
6257:
6258: ###############################################
6259:
1.60 matthew 6260: =pod
6261:
1.112 bowersj2 6262: =head1 Domain Template Functions
6263:
6264: =over 4
6265:
6266: =item * &determinedomain()
1.60 matthew 6267:
6268: Inputs: $domain (usually will be undef)
6269:
1.63 www 6270: Returns: Determines which domain should be used for designs
1.60 matthew 6271:
6272: =cut
1.54 www 6273:
1.60 matthew 6274: ###############################################
1.63 www 6275: sub determinedomain {
6276: my $domain=shift;
1.531 albertel 6277: if (! $domain) {
1.60 matthew 6278: # Determine domain if we have not been given one
1.893 raeburn 6279: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6280: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6281: if ($env{'request.role.domain'}) {
6282: $domain=$env{'request.role.domain'};
1.60 matthew 6283: }
6284: }
1.63 www 6285: return $domain;
6286: }
6287: ###############################################
1.517 raeburn 6288:
1.518 albertel 6289: sub devalidate_domconfig_cache {
6290: my ($udom)=@_;
6291: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6292: }
6293:
6294: # ---------------------- Get domain configuration for a domain
6295: sub get_domainconf {
6296: my ($udom) = @_;
6297: my $cachetime=1800;
6298: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6299: if (defined($cached)) { return %{$result}; }
6300:
6301: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6302: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6303: my (%designhash,%legacy);
1.518 albertel 6304: if (keys(%domconfig) > 0) {
6305: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6306: if (keys(%{$domconfig{'login'}})) {
6307: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6308: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6309: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6310: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6311: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6312: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6313: if ($key eq 'loginvia') {
6314: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6315: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6316: $designhash{$udom.'.login.loginvia'} = $server;
6317: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6318:
6319: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6320: } else {
6321: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6322: }
1.948 raeburn 6323: }
1.1208 raeburn 6324: } elsif ($key eq 'headtag') {
6325: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6326: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6327: }
1.946 raeburn 6328: }
1.1208 raeburn 6329: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6330: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6331: }
1.946 raeburn 6332: }
6333: }
6334: }
1.1366 raeburn 6335: } elsif ($key eq 'saml') {
6336: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6337: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6338: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6339: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6340: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6341: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6342: }
6343: }
6344: }
6345: }
1.946 raeburn 6346: } else {
6347: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6348: $designhash{$udom.'.login.'.$key.'_'.$img} =
6349: $domconfig{'login'}{$key}{$img};
6350: }
1.699 raeburn 6351: }
6352: } else {
6353: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6354: }
1.632 raeburn 6355: }
6356: } else {
6357: $legacy{'login'} = 1;
1.518 albertel 6358: }
1.632 raeburn 6359: } else {
6360: $legacy{'login'} = 1;
1.518 albertel 6361: }
6362: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6363: if (keys(%{$domconfig{'rolecolors'}})) {
6364: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6365: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6366: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6367: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6368: }
1.518 albertel 6369: }
6370: }
1.632 raeburn 6371: } else {
6372: $legacy{'rolecolors'} = 1;
1.518 albertel 6373: }
1.632 raeburn 6374: } else {
6375: $legacy{'rolecolors'} = 1;
1.518 albertel 6376: }
1.948 raeburn 6377: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6378: if ($domconfig{'autoenroll'}{'co-owners'}) {
6379: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6380: }
6381: }
1.632 raeburn 6382: if (keys(%legacy) > 0) {
6383: my %legacyhash = &get_legacy_domconf($udom);
6384: foreach my $item (keys(%legacyhash)) {
6385: if ($item =~ /^\Q$udom\E\.login/) {
6386: if ($legacy{'login'}) {
6387: $designhash{$item} = $legacyhash{$item};
6388: }
6389: } else {
6390: if ($legacy{'rolecolors'}) {
6391: $designhash{$item} = $legacyhash{$item};
6392: }
1.518 albertel 6393: }
6394: }
6395: }
1.632 raeburn 6396: } else {
6397: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6398: }
6399: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6400: $cachetime);
6401: return %designhash;
6402: }
6403:
1.632 raeburn 6404: sub get_legacy_domconf {
6405: my ($udom) = @_;
6406: my %legacyhash;
6407: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6408: my $designfile = $designdir.'/'.$udom.'.tab';
6409: if (-e $designfile) {
1.1317 raeburn 6410: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6411: while (my $line = <$fh>) {
6412: next if ($line =~ /^\#/);
6413: chomp($line);
6414: my ($key,$val)=(split(/\=/,$line));
6415: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6416: }
6417: close($fh);
6418: }
6419: }
1.1026 raeburn 6420: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6421: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6422: }
6423: return %legacyhash;
6424: }
6425:
1.63 www 6426: =pod
6427:
1.112 bowersj2 6428: =item * &domainlogo()
1.63 www 6429:
6430: Inputs: $domain (usually will be undef)
6431:
6432: Returns: A link to a domain logo, if the domain logo exists.
6433: If the domain logo does not exist, a description of the domain.
6434:
6435: =cut
1.112 bowersj2 6436:
1.63 www 6437: ###############################################
6438: sub domainlogo {
1.517 raeburn 6439: my $domain = &determinedomain(shift);
1.518 albertel 6440: my %designhash = &get_domainconf($domain);
1.517 raeburn 6441: # See if there is a logo
6442: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6443: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6444: if ($imgsrc =~ m{^/(adm|res)/}) {
6445: if ($imgsrc =~ m{^/res/}) {
6446: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6447: &Apache::lonnet::repcopy($local_name);
6448: }
6449: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6450: }
6451: my $alttext = $domain;
6452: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6453: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6454: }
6455: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6456: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6457: return &Apache::lonnet::domain($domain,'description');
1.59 www 6458: } else {
1.60 matthew 6459: return '';
1.59 www 6460: }
6461: }
1.63 www 6462: ##############################################
6463:
6464: =pod
6465:
1.112 bowersj2 6466: =item * &designparm()
1.63 www 6467:
6468: Inputs: $which parameter; $domain (usually will be undef)
6469:
6470: Returns: value of designparamter $which
6471:
6472: =cut
1.112 bowersj2 6473:
1.397 albertel 6474:
1.400 albertel 6475: ##############################################
1.397 albertel 6476: sub designparm {
6477: my ($which,$domain)=@_;
6478: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6479: return $env{'environment.color.'.$which};
1.96 www 6480: }
1.63 www 6481: $domain=&determinedomain($domain);
1.1016 raeburn 6482: my %domdesign;
6483: unless ($domain eq 'public') {
6484: %domdesign = &get_domainconf($domain);
6485: }
1.520 raeburn 6486: my $output;
1.517 raeburn 6487: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6488: $output = $domdesign{$domain.'.'.$which};
1.63 www 6489: } else {
1.520 raeburn 6490: $output = $defaultdesign{$which};
6491: }
6492: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6493: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6494: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6495: if ($output =~ m{^/res/}) {
6496: my $local_name = &Apache::lonnet::filelocation('',$output);
6497: &Apache::lonnet::repcopy($local_name);
6498: }
1.520 raeburn 6499: $output = &lonhttpdurl($output);
6500: }
1.63 www 6501: }
1.520 raeburn 6502: return $output;
1.63 www 6503: }
1.59 www 6504:
1.822 bisitz 6505: ##############################################
6506: =pod
6507:
1.832 bisitz 6508: =item * &authorspace()
6509:
1.1028 raeburn 6510: Inputs: $url (usually will be undef).
1.832 bisitz 6511:
1.1132 raeburn 6512: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6513: directory being viewed (or for which action is being taken).
6514: If $url is provided, and begins /priv/<domain>/<uname>
6515: the path will be that portion of the $context argument.
6516: Otherwise the path will be for the author space of the current
6517: user when the current role is author, or for that of the
6518: co-author/assistant co-author space when the current role
6519: is co-author or assistant co-author.
1.832 bisitz 6520:
6521: =cut
6522:
6523: sub authorspace {
1.1028 raeburn 6524: my ($url) = @_;
6525: if ($url ne '') {
6526: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6527: return $1;
6528: }
6529: }
1.832 bisitz 6530: my $caname = '';
1.1024 www 6531: my $cadom = '';
1.1028 raeburn 6532: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6533: ($cadom,$caname) =
1.832 bisitz 6534: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6535: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6536: $caname = $env{'user.name'};
1.1024 www 6537: $cadom = $env{'user.domain'};
1.832 bisitz 6538: }
1.1028 raeburn 6539: if (($caname ne '') && ($cadom ne '')) {
6540: return "/priv/$cadom/$caname/";
6541: }
6542: return;
1.832 bisitz 6543: }
6544:
6545: ##############################################
6546: =pod
6547:
1.822 bisitz 6548: =item * &head_subbox()
6549:
6550: Inputs: $content (contains HTML code with page functions, etc.)
6551:
6552: Returns: HTML div with $content
6553: To be included in page header
6554:
6555: =cut
6556:
6557: sub head_subbox {
6558: my ($content)=@_;
6559: my $output =
1.993 raeburn 6560: '<div class="LC_head_subbox">'
1.822 bisitz 6561: .$content
6562: .'</div>'
6563: }
6564:
6565: ##############################################
6566: =pod
6567:
6568: =item * &CSTR_pageheader()
6569:
1.1026 raeburn 6570: Input: (optional) filename from which breadcrumb trail is built.
6571: In most cases no input as needed, as $env{'request.filename'}
6572: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6573: frameset flag
6574: If page header is being requested for use in a frameset, then
6575: the second (option) argument -- frameset will be true, and
6576: the target attribute set for links should be target="_parent".
1.1433 raeburn 6577: If $title is supplied as the third arg, that will be used to
1.1407 raeburn 6578: the left of the breadcrumbs tail for the current path.
1.822 bisitz 6579:
6580: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6581: To be included on Authoring Space pages
1.822 bisitz 6582:
6583: =cut
6584:
6585: sub CSTR_pageheader {
1.1407 raeburn 6586: my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 6587: if ($trailfile eq '') {
6588: $trailfile = $env{'request.filename'};
6589: }
6590:
6591: # this is for resources; directories have customtitle, and crumbs
6592: # and select recent are created in lonpubdir.pm
6593:
6594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6595: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6596: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6597: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6598: $formaction =~ s{/+}{/}g;
1.822 bisitz 6599:
6600: my $parentpath = '';
6601: my $lastitem = '';
6602: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6603: $parentpath = $1;
6604: $lastitem = $2;
6605: } else {
6606: $lastitem = $thisdisfn;
6607: }
1.921 bisitz 6608:
1.1406 raeburn 6609: my $crsauthor;
1.1246 raeburn 6610: if (($env{'request.course.id'}) &&
6611: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6612: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6613: $crsauthor = 1;
1.1406 raeburn 6614: if ($title eq '') {
6615: $title = &mt('Course Authoring Space');
6616: }
6617: } elsif ($title eq '') {
1.1246 raeburn 6618: $title = &mt('Authoring Space');
6619: }
6620:
1.1379 raeburn 6621: my ($target,$crumbtarget) = (' target="_top"','_top');
6622: if ($frameset) {
6623: $target = ' target="_parent"';
6624: $crumbtarget = '_parent';
6625: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6626: $target = '';
6627: $crumbtarget = '';
1.1379 raeburn 6628: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6629: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6630: $crumbtarget = $env{'request.deeplink.target'};
6631: }
1.1313 raeburn 6632:
1.921 bisitz 6633: my $output =
1.1407 raeburn 6634: '<div>'
1.822 bisitz 6635: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6636: .'<b>'.$title.'</b> '
1.1314 raeburn 6637: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6638: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6639:
6640: if ($lastitem) {
6641: $output .=
6642: '<span class="LC_filename">'
6643: .$lastitem
6644: .'</span>';
6645: }
1.1245 raeburn 6646:
1.1246 raeburn 6647: if ($crsauthor) {
1.1379 raeburn 6648: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6649: } else {
6650: $output .=
6651: '<br />'
1.1314 raeburn 6652: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6653: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6654: .'</form>'
1.1379 raeburn 6655: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6656: }
1.1407 raeburn 6657: $output .= '</div>';
1.921 bisitz 6658:
6659: return $output;
1.822 bisitz 6660: }
6661:
1.1419 raeburn 6662: ##############################################
6663: =pod
6664:
6665: =item * &nocodemirror()
6666:
6667: Input: None
6668:
6669: Returns: 1 if CodeMirror is deactivated based on
6670: user's preference, or domain default,
6671: if user indicated use of default.
6672:
6673: =cut
6674:
1.1416 raeburn 6675: sub nocodemirror {
6676: my $nocodem = $env{'environment.nocodemirror'};
6677: unless ($nocodem) {
6678: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6679: if ($domdefs{'nocodemirror'}) {
6680: $nocodem = 'yes';
6681: }
6682: }
1.1417 raeburn 6683: if ($nocodem eq 'yes') {
6684: return 1;
6685: }
6686: return;
1.1416 raeburn 6687: }
6688:
1.1419 raeburn 6689: ##############################################
6690: =pod
6691:
6692: =item * &permitted_editors()
6693:
1.1422 raeburn 6694: Input: $uri (optional)
1.1419 raeburn 6695:
6696: Returns: %editors hash in which keys are editors
1.1429 raeburn 6697: permitted in current Authoring Space,
6698: or in current course for web pages
6699: created in a course.
6700:
1.1419 raeburn 6701: Value for each key is 1. Possible keys
1.1429 raeburn 6702: are: edit, xml, and daxe.
6703:
6704: For a regular Authoring Space, if no specific
1.1419 raeburn 6705: set of editors has been set for the Author
6706: who owns the Authoring Space, then the
6707: domain default will be used. If no domain
6708: default has been set, then the keys will be
6709: edit and xml.
6710:
1.1429 raeburn 6711: For a course author, or for web pages created
6712: in a course, if no specific set of editors has
6713: been set for the course, then the domain
6714: course default will be used. If no domain
6715: course default has been set, then the keys
6716: will be edit and xml.
6717:
1.1419 raeburn 6718: =cut
6719:
1.1418 raeburn 6720: sub permitted_editors {
1.1422 raeburn 6721: my ($uri) = @_;
1.1429 raeburn 6722: my ($is_author,$is_coauthor,$is_course,$auname,$audom,%editors);
1.1418 raeburn 6723: if ($env{'request.role'} =~ m{^au\./}) {
6724: $is_author = 1;
6725: } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6726: ($audom,$auname) = ($1,$2);
6727: if (($audom ne '') && ($auname ne '')) {
6728: if (($env{'user.domain'} eq $audom) &&
6729: ($env{'user.name'} eq $auname)) {
6730: $is_author = 1;
6731: } else {
6732: $is_coauthor = 1;
6733: }
6734: }
6735: } elsif ($env{'request.course.id'}) {
1.1429 raeburn 6736: my ($cdom,$cnum);
6737: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6738: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6739: if (($env{'request.editurl'} =~ m{^/priv/\Q$cdom/$cnum\E/}) ||
1.1430 raeburn 6740: ($env{'request.editurl'} =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}) ||
6741: ($uri =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/})) {
1.1429 raeburn 6742: $is_course = 1;
6743: } elsif ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
1.1418 raeburn 6744: ($audom,$auname) = ($1,$2);
6745: } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6746: ($audom,$auname) = ($1,$2);
1.1422 raeburn 6747: } elsif (($uri eq '/daxesave') &&
1.1429 raeburn 6748: (($env{'form.path'} =~ m{^/daxeopen/priv/\Q$cdom/$cnum\E/}) ||
6749: ($env{'form.path'} =~ m{^/daxeopen/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}))) {
6750: $is_course = 1;
6751: } elsif (($uri eq '/daxesave') &&
1.1422 raeburn 6752: ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {
6753: ($audom,$auname) = ($1,$2);
1.1418 raeburn 6754: }
1.1429 raeburn 6755: unless ($is_course) {
6756: if (($audom ne '') && ($auname ne '')) {
6757: if (($env{'user.domain'} eq $audom) &&
6758: ($env{'user.name'} eq $auname)) {
6759: $is_author = 1;
6760: } else {
6761: $is_coauthor = 1;
6762: }
1.1418 raeburn 6763: }
6764: }
6765: }
6766: if ($is_author) {
6767: if (exists($env{'environment.editors'})) {
6768: map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6769: } else {
6770: %editors = ( edit => 1,
6771: xml => 1,
6772: );
6773: }
6774: } elsif ($is_coauthor) {
6775: if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6776: map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6777: } else {
6778: %editors = ( edit => 1,
6779: xml => 1,
6780: );
6781: }
1.1429 raeburn 6782: } elsif ($is_course) {
6783: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.crseditors'})) {
6784: map { $editors{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.crseditors'});
6785: } else {
6786: my %domdefaults = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
6787: if (exists($domdefaults{'crseditors'})) {
6788: map { $editors{$_} = 1; } split(/,/,$domdefaults{'crseditors'});
6789: } else {
6790: %editors = ( edit => 1,
6791: xml => 1,
6792: );
6793: }
6794: }
1.1418 raeburn 6795: } else {
6796: %editors = ( edit => 1,
6797: xml => 1,
6798: );
6799: }
6800: return %editors;
6801: }
6802:
1.60 matthew 6803: ###############################################
6804: ###############################################
6805:
6806: =pod
6807:
1.112 bowersj2 6808: =back
6809:
1.549 albertel 6810: =head1 HTML Helpers
1.112 bowersj2 6811:
6812: =over 4
6813:
6814: =item * &bodytag()
1.60 matthew 6815:
6816: Returns a uniform header for LON-CAPA web pages.
6817:
6818: Inputs:
6819:
1.112 bowersj2 6820: =over 4
6821:
6822: =item * $title, A title to be displayed on the page.
6823:
6824: =item * $function, the current role (can be undef).
6825:
6826: =item * $addentries, extra parameters for the <body> tag.
6827:
6828: =item * $bodyonly, if defined, only return the <body> tag.
6829:
6830: =item * $domain, if defined, force a given domain.
6831:
6832: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6833: text interface only)
1.60 matthew 6834:
1.814 bisitz 6835: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6836: navigational links
1.317 albertel 6837:
1.338 albertel 6838: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6839:
1.460 albertel 6840: =item * $args, optional argument valid values are
6841: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6842: use_absolute -> for external resource or syllabus, this will
6843: contain https://<hostname> if server uses
6844: https (as per hosts.tab), but request is for http
6845: hostname -> hostname, from $r->hostname().
1.460 albertel 6846:
1.1096 raeburn 6847: =item * $advtoolsref, optional argument, ref to an array containing
6848: inlineremote items to be added in "Functions" menu below
6849: breadcrumbs.
6850:
1.1316 raeburn 6851: =item * $ltiscope, optional argument, will be one of: resource, map or
6852: course, if LON-CAPA is in LTI Provider context. Value is
6853: the scope of use, i.e., launch was for access to a single, a map
6854: or the entire course.
6855:
6856: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6857: context, this will contain the URL for the landing item in
6858: the course, after launch from an LTI Consumer
6859:
1.1318 raeburn 6860: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6861: context, this will contain a reference to hash of items
6862: to be included in the page header and/or inline menu.
6863:
1.1385 raeburn 6864: =item * $menucoll, optional argument, if specific menu collection is in
6865: effect, either set as the default for the course, or set for
6866: the deeplink paramater for $env{'request.deeplink.login'}
6867: then $menucoll will be the number of that collection.
6868:
6869: =item * $menuref, optional argument, reference to a hash, containing the
6870: menu options included for the menu in effect, based on the
6871: configuration for the numbered menu collection in use.
6872:
6873: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6874: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6875: if so, $showncrumbsref is set there to 1, and will propagate back
6876: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6877: being called a second time.
6878:
1.112 bowersj2 6879: =back
6880:
1.60 matthew 6881: Returns: A uniform header for LON-CAPA web pages.
6882: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6883: If $bodyonly is undef or zero, an html string containing a <body> tag and
6884: other decorations will be returned.
6885:
6886: =cut
6887:
1.54 www 6888: sub bodytag {
1.831 bisitz 6889: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6890: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6891: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6892:
1.954 raeburn 6893: my $public;
6894: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6895: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6896: $public = 1;
6897: }
1.460 albertel 6898: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6899: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6900: my $hostname = $args->{'hostname'};
1.339 albertel 6901:
1.183 matthew 6902: $function = &get_users_function() if (!$function);
1.339 albertel 6903: my $font = &designparm($function.'.font',$domain);
6904: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6905:
1.803 bisitz 6906: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6907: 'bgcolor' => $pgbg,
1.339 albertel 6908: 'text' => $font,
6909: 'alink' => &designparm($function.'.alink',$domain),
6910: 'vlink' => &designparm($function.'.vlink',$domain),
6911: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6912: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6913:
1.63 www 6914: # role and realm
1.1178 raeburn 6915: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6916: if ($realm) {
6917: $realm = '/'.$realm;
6918: }
1.1357 raeburn 6919: if ($role eq 'ca') {
1.479 albertel 6920: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6921: $realm = &plainname($rname,$rdom);
1.378 raeburn 6922: }
1.55 www 6923: # realm
1.1357 raeburn 6924: my ($cid,$sec);
1.258 albertel 6925: if ($env{'request.course.id'}) {
1.1357 raeburn 6926: $cid = $env{'request.course.id'};
6927: if ($env{'request.course.sec'}) {
6928: $sec = $env{'request.course.sec'};
6929: }
6930: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6931: if (&Apache::lonnet::is_course($1,$2)) {
6932: $cid = $1.'_'.$2;
6933: $sec = $3;
6934: }
6935: }
6936: if ($cid) {
1.378 raeburn 6937: if ($env{'request.role'} !~ /^cr/) {
6938: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6939: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6940: if ($env{'request.role.desc'}) {
6941: $role = $env{'request.role.desc'};
6942: } else {
6943: $role = &mt('Helpdesk[_1]',' '.$2);
6944: }
1.1257 raeburn 6945: } else {
6946: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6947: }
1.1357 raeburn 6948: if ($sec) {
6949: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6950: }
1.1357 raeburn 6951: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6952: } else {
6953: $role = &Apache::lonnet::plaintext($role);
1.54 www 6954: }
1.433 albertel 6955:
1.438 albertel 6956: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6957:
1.101 www 6958: # construct main body tag
1.359 albertel 6959: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6960: &Apache::lontexconvert::init_math_support();
1.252 albertel 6961:
1.1131 raeburn 6962: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6963:
1.1130 raeburn 6964: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6965: return $bodytag;
1.1130 raeburn 6966: }
1.359 albertel 6967:
1.954 raeburn 6968: if ($public) {
1.433 albertel 6969: undef($role);
6970: }
1.1318 raeburn 6971:
1.1359 raeburn 6972: my $showcrstitle = 1;
1.1357 raeburn 6973: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6974: if (ref($ltimenu) eq 'HASH') {
6975: unless ($ltimenu->{'role'}) {
6976: undef($role);
6977: }
6978: unless ($ltimenu->{'coursetitle'}) {
1.1359 raeburn 6979: $showcrstitle = 0;
6980: }
6981: }
6982: } elsif (($cid) && ($menucoll)) {
6983: if (ref($menuref) eq 'HASH') {
6984: unless ($menuref->{'role'}) {
6985: undef($role);
6986: }
6987: unless ($menuref->{'crs'}) {
6988: $showcrstitle = 0;
1.1318 raeburn 6989: }
6990: }
6991: }
6992:
1.762 bisitz 6993: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6994: #
6995: # Extra info if you are the DC
6996: my $dc_info = '';
1.1359 raeburn 6997: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6998: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6999: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 7000: $dc_info =~ s/\s+$//;
1.359 albertel 7001: }
7002:
1.1237 raeburn 7003: my $crstype;
1.1357 raeburn 7004: if ($cid) {
7005: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 7006: } elsif ($args->{'crstype'}) {
7007: $crstype = $args->{'crstype'};
7008: }
7009: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
7010: undef($role);
7011: } else {
1.1242 raeburn 7012: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 7013: }
1.853 droeschl 7014:
1.903 droeschl 7015: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
7016:
7017: # if ($env{'request.state'} eq 'construct') {
7018: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
7019: # }
7020:
1.1440 raeburn 7021: my $need_endlcint;
7022: unless ($args->{'switchserver'}) {
7023: $bodytag .= Apache::lonhtmlcommon::scripttag(
7024: Apache::lonmenu::utilityfunctions($httphost), 'start');
7025: $need_endlcint = 1;
7026: }
1.359 albertel 7027:
1.1427 raeburn 7028: my $collapsible;
1.1423 raeburn 7029: if ($args->{'collapsible_header'} ne '') {
1.1427 raeburn 7030: $collapsible = 1;
7031: my ($menustate,$tiptext,$divclass);
7032: if ($args->{'start_collapsed'}) {
7033: $menustate = 'collapsed';
7034: $tiptext = 'display';
7035: $divclass = 'hidden';
7036: } else {
7037: $menustate = 'expanded';
7038: $tiptext = 'hide';
7039: $divclass = 'shown';
7040: }
7041: my $alttext = &mt('menu state: '.$menustate);
7042: my $tooltip = &mt($tiptext.' standard menus');
1.1421 raeburn 7043: $bodytag .= <<"END";
1.1461 raeburn 7044: <div id="LC_expandingContainer" style="display:inline;" role="navigation">
1.1421 raeburn 7045: <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
1.1427 raeburn 7046: <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>
7047: <div class="LC_menus_content $divclass">
1.1421 raeburn 7048: END
7049: }
1.1318 raeburn 7050: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 7051: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 7052: $args->{'links_disabled'},
1.1421 raeburn 7053: $args->{'links_target'},
1.1427 raeburn 7054: $collapsible);
1.1454 raeburn 7055: my $labeltext = &HTML::Entities::encode(&mt('Primary links'));
1.1318 raeburn 7056: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
7057: if ($dc_info) {
7058: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
7059: }
1.1456 raeburn 7060: $bodytag .= qq|<div id="LC_nav_bar" role="navigation" aria-label="$labeltext">$left $role</div>|;
1.1454 raeburn 7061: unless (($realm eq '') && ($dc_info eq '')) {
7062: $bodytag .= qq|<div id="LC_realm" role="complementary"><em>$realm</em> $dc_info</div>|;
7063: }
1.1440 raeburn 7064: if ($need_endlcint) {
7065: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7066: }
1.1318 raeburn 7067: return $bodytag;
7068: }
1.894 droeschl 7069:
1.1457 raeburn 7070: $bodytag .= '<div class="LC_landmark" style="margin: 3px 0 0 0;" role="navigation" aria-label="'.$labeltext.'">';
1.1318 raeburn 7071: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
7072: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
7073: }
1.916 droeschl 7074:
1.1454 raeburn 7075: $bodytag .= $right.'</div>';
1.852 droeschl 7076:
1.1318 raeburn 7077: if ($dc_info) {
7078: $dc_info = &dc_courseid_toggle($dc_info);
7079: }
1.1454 raeburn 7080: unless (($realm eq '') && ($dc_info eq '')) {
1.1457 raeburn 7081: $bodytag .= qq|<div id="LC_realm" role="complementary">$realm $dc_info</div>|;
1.1454 raeburn 7082: }
1.1457 raeburn 7083: $bodytag .= qq|<div style="clear: both; margin: 5px 0 0 0;"></div>|;
1.917 raeburn 7084: }
1.916 droeschl 7085:
1.1169 raeburn 7086: #if directed to not display the secondary menu, don't.
1.1168 raeburn 7087: if ($args->{'no_secondary_menu'}) {
1.1440 raeburn 7088: if ($need_endlcint) {
7089: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7090: }
1.1168 raeburn 7091: return $bodytag;
7092: }
1.1169 raeburn 7093: #don't show menus for public users
1.954 raeburn 7094: if (!$public){
1.1318 raeburn 7095: unless ($args->{'no_inline_menu'}) {
1.1459 raeburn 7096: $bodytag .= '<div class="LC_landmark" role="navigation" aria-label="Secondary Links">'.
7097: Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 7098: $args->{'no_primary_menu'},
1.1369 raeburn 7099: $menucoll,$menuref,
1.1380 raeburn 7100: $args->{'links_disabled'},
1.1459 raeburn 7101: $args->{'links_target'}).
1.1460 raeburn 7102: '</div>';
1.1318 raeburn 7103: }
1.903 droeschl 7104: $bodytag .= Apache::lonmenu::serverform();
1.1440 raeburn 7105: if ($need_endlcint) {
7106: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7107: }
1.920 raeburn 7108: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 7109: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 7110: $args->{'bread_crumbs'},'','',$hostname,
7111: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 7112: } elsif ($forcereg) {
7113: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 7114: $args->{'group'},$args->{'hide_buttons'},
7115: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 7116: } else {
1.1459 raeburn 7117: $bodytag .=
1.1096 raeburn 7118: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
7119: $forcereg,$args->{'group'},
7120: $args->{'bread_crumbs'},
1.1274 raeburn 7121: $advtoolsref,'',$hostname);
1.920 raeburn 7122: }
1.1440 raeburn 7123: } else {
7124: # this is to separate menu from content when there's no secondary
1.1441 raeburn 7125: # menu. Especially needed for publicly accessible resources.
1.1459 raeburn 7126: $bodytag .= '<hr style="clear:both" role="complementary" />';
1.1440 raeburn 7127: if ($need_endlcint) {
7128: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7129: }
1.235 raeburn 7130: }
1.1423 raeburn 7131: if ($args->{'collapsible_header'} ne '') {
7132: $bodytag .= $args->{'collapsible_header'}.
7133: '<div id="LC_collapsible_separator"></div>'.
1.1421 raeburn 7134: '</div></div>';
7135: }
1.235 raeburn 7136: return $bodytag;
1.182 matthew 7137: }
7138:
1.917 raeburn 7139: sub dc_courseid_toggle {
7140: my ($dc_info) = @_;
1.980 raeburn 7141: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 7142: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 7143: &mt('(More ...)').'</a></span>'.
7144: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
7145: }
7146:
1.330 albertel 7147: sub make_attr_string {
7148: my ($register,$attr_ref) = @_;
7149:
7150: if ($attr_ref && !ref($attr_ref)) {
7151: die("addentries Must be a hash ref ".
7152: join(':',caller(1))." ".
7153: join(':',caller(0))." ");
7154: }
7155:
7156: if ($register) {
1.339 albertel 7157: my ($on_load,$on_unload);
7158: foreach my $key (keys(%{$attr_ref})) {
7159: if (lc($key) eq 'onload') {
7160: $on_load.=$attr_ref->{$key}.';';
7161: delete($attr_ref->{$key});
7162:
7163: } elsif (lc($key) eq 'onunload') {
7164: $on_unload.=$attr_ref->{$key}.';';
7165: delete($attr_ref->{$key});
7166: }
7167: }
1.953 droeschl 7168: $attr_ref->{'onload'} = $on_load;
7169: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 7170: }
1.339 albertel 7171:
1.330 albertel 7172: my $attr_string;
1.1159 raeburn 7173: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 7174: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
7175: }
7176: return $attr_string;
7177: }
7178:
7179:
1.182 matthew 7180: ###############################################
1.251 albertel 7181: ###############################################
7182:
7183: =pod
7184:
7185: =item * &endbodytag()
7186:
7187: Returns a uniform footer for LON-CAPA web pages.
7188:
1.635 raeburn 7189: Inputs: 1 - optional reference to an args hash
7190: If in the hash, key for noredirectlink has a value which evaluates to true,
7191: a 'Continue' link is not displayed if the page contains an
7192: internal redirect in the <head></head> section,
7193: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 7194:
7195: =cut
7196:
7197: sub endbodytag {
1.635 raeburn 7198: my ($args) = @_;
1.1080 raeburn 7199: my $endbodytag;
7200: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
7201: $endbodytag='</body>';
7202: }
1.315 albertel 7203: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 7204: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 7205: my ($endbodyjs,$idattr);
7206: if ($env{'internal.head.to_opener'}) {
7207: my $linkid = 'LC_continue_link';
7208: $idattr = ' id="'.$linkid.'"';
7209: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
7210: $endbodyjs=<<ENDJS;
7211: <script type="text/javascript">
7212: // <![CDATA[
7213: function ebFunction(evt) {
7214: evt.preventDefault();
7215: var dest = '$redirect_for_js';
7216: if (window.opener != null && !window.opener.closed) {
7217: window.opener.location.href=dest;
7218: window.close();
7219: } else {
7220: window.location.href=dest;
7221: }
7222: return false;
7223: }
7224:
7225: \$(document).ready(function () {
7226: if (document.getElementById('$linkid')) {
7227: var clickelem = document.getElementById('$linkid');
7228: clickelem.addEventListener('click',ebFunction,false);
7229: }
7230: });
7231: // ]]>
7232: </script>
7233: ENDJS
7234: }
1.635 raeburn 7235: $endbodytag=
1.1386 raeburn 7236: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 7237: &mt('Continue').'</a>'.
7238: $endbodytag;
7239: }
1.315 albertel 7240: }
1.1411 raeburn 7241: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
7242: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
7243: }
1.251 albertel 7244: return $endbodytag;
7245: }
7246:
1.352 albertel 7247: =pod
7248:
7249: =item * &standard_css()
7250:
7251: Returns a style sheet
7252:
7253: Inputs: (all optional)
7254: domain -> force to color decorate a page for a specific
7255: domain
7256: function -> force usage of a specific rolish color scheme
7257: bgcolor -> override the default page bgcolor
7258:
7259: =cut
7260:
1.343 albertel 7261: sub standard_css {
1.345 albertel 7262: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 7263: $function = &get_users_function() if (!$function);
7264: my $tabbg = &designparm($function.'.tabbg', $domain);
7265: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 7266: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 7267: #second colour for later usage
1.345 albertel 7268: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 7269: my $pgbg_or_bgcolor =
7270: $bgcolor ||
1.352 albertel 7271: &designparm($function.'.pgbg', $domain);
1.382 albertel 7272: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 7273: my $alink = &designparm($function.'.alink', $domain);
7274: my $vlink = &designparm($function.'.vlink', $domain);
7275: my $link = &designparm($function.'.link', $domain);
7276:
1.602 albertel 7277: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 7278: my $mono = 'monospace';
1.850 bisitz 7279: my $data_table_head = $sidebg;
7280: my $data_table_light = '#FAFAFA';
1.1060 bisitz 7281: my $data_table_dark = '#E0E0E0';
1.470 banghart 7282: my $data_table_darker = '#CCCCCC';
1.349 albertel 7283: my $data_table_highlight = '#FFFF00';
1.352 albertel 7284: my $mail_new = '#FFBB77';
7285: my $mail_new_hover = '#DD9955';
7286: my $mail_read = '#BBBB77';
7287: my $mail_read_hover = '#999944';
7288: my $mail_replied = '#AAAA88';
7289: my $mail_replied_hover = '#888855';
7290: my $mail_other = '#99BBBB';
7291: my $mail_other_hover = '#669999';
1.391 albertel 7292: my $table_header = '#DDDDDD';
1.489 raeburn 7293: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 7294: my $lg_border_color = '#C8C8C8';
1.952 onken 7295: my $button_hover = '#BF2317';
1.392 albertel 7296:
1.608 albertel 7297: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 7298: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
7299: : '0 3px 0 4px';
1.448 albertel 7300:
1.523 albertel 7301:
1.343 albertel 7302: return <<END;
1.947 droeschl 7303:
7304: /* needed for iframe to allow 100% height in FF */
7305: body, html {
7306: margin: 0;
7307: padding: 0 0.5%;
7308: height: 99%; /* to avoid scrollbars */
7309: }
7310:
1.795 www 7311: body {
1.911 bisitz 7312: font-family: $sans;
7313: line-height:130%;
7314: font-size:0.83em;
7315: color:$font;
1.1436 raeburn 7316: background-color: $pgbg_or_bgcolor;
1.795 www 7317: }
7318:
1.959 onken 7319: a:focus,
7320: a:focus img {
1.795 www 7321: color: red;
7322: }
1.698 harmsja 7323:
1.911 bisitz 7324: form, .inline {
7325: display: inline;
1.795 www 7326: }
1.721 harmsja 7327:
1.1453 raeburn 7328: .LC_landmark {
7329: margin: 0;
7330: padding: 0;
7331: border: none;
7332: }
7333:
1.1443 raeburn 7334: .LC_visually_hidden:not(:focus):not(:active) {
7335: clip-path: inset(50%);
7336: height: 1px;
7337: overflow: hidden;
7338: position: absolute;
7339: white-space: nowrap;
7340: width: 1px;
7341: display: inline;
7342: }
7343:
1.1453 raeburn 7344: .LC_heading_2 {
7345: font-size: 1.17em;
7346: }
7347:
1.1458 raeburn 7348: .LC_heading_3 {
7349: font-size: 1.0em;
7350: }
7351:
1.1421 raeburn 7352: .LC_menus_content.shown{
1.1428 raeburn 7353: display: block;
1.1421 raeburn 7354: }
7355:
7356: .LC_menus_content.hidden {
7357: display: none;
7358: }
7359:
1.795 www 7360: .LC_right {
1.911 bisitz 7361: text-align:right;
1.795 www 7362: }
7363:
1.1470 ! raeburn 7364: .LC_left {
! 7365: text-align:left;
! 7366: }
! 7367:
1.1449 raeburn 7368: .LC_center {
7369: text-align:center;
7370: }
7371:
1.795 www 7372: .LC_middle {
1.911 bisitz 7373: vertical-align:middle;
1.795 www 7374: }
1.721 harmsja 7375:
1.1130 raeburn 7376: .LC_floatleft {
7377: float: left;
7378: }
7379:
7380: .LC_floatright {
7381: float: right;
7382: }
7383:
1.911 bisitz 7384: .LC_400Box {
7385: width:400px;
7386: }
1.721 harmsja 7387:
1.1421 raeburn 7388: #LC_collapsible_separator {
7389: border: 1px solid black;
7390: width: 99.9%;
7391: height: 0px;
7392: }
7393:
1.947 droeschl 7394: .LC_iframecontainer {
7395: width: 98%;
7396: margin: 0;
7397: position: fixed;
7398: top: 8.5em;
7399: bottom: 0;
7400: }
7401:
7402: .LC_iframecontainer iframe{
7403: border: none;
7404: width: 100%;
7405: height: 100%;
7406: }
7407:
1.778 bisitz 7408: .LC_filename {
7409: font-family: $mono;
7410: white-space:pre;
1.921 bisitz 7411: font-size: 120%;
1.778 bisitz 7412: }
7413:
7414: .LC_fileicon {
7415: border: none;
7416: height: 1.3em;
7417: vertical-align: text-bottom;
7418: margin-right: 0.3em;
7419: text-decoration:none;
7420: }
7421:
1.1008 www 7422: .LC_setting {
7423: text-decoration:underline;
7424: }
7425:
1.350 albertel 7426: .LC_error {
7427: color: red;
7428: }
1.795 www 7429:
1.1097 bisitz 7430: .LC_warning {
7431: color: darkorange;
7432: }
7433:
1.457 albertel 7434: .LC_diff_removed {
1.733 bisitz 7435: color: red;
1.394 albertel 7436: }
1.532 albertel 7437:
7438: .LC_info,
1.457 albertel 7439: .LC_success,
7440: .LC_diff_added {
1.350 albertel 7441: color: green;
7442: }
1.795 www 7443:
1.802 bisitz 7444: div.LC_confirm_box {
7445: background-color: #FAFAFA;
7446: border: 1px solid $lg_border_color;
7447: margin-right: 0;
7448: padding: 5px;
7449: }
7450:
7451: div.LC_confirm_box .LC_error img,
7452: div.LC_confirm_box .LC_success img {
7453: vertical-align: middle;
7454: }
7455:
1.1242 raeburn 7456: .LC_maxwidth {
7457: max-width: 100%;
7458: height: auto;
7459: }
7460:
1.1243 raeburn 7461: .LC_textsize_mobile {
7462: \@media only screen and (max-device-width: 480px) {
7463: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7464: }
7465: }
7466:
1.440 albertel 7467: .LC_icon {
1.771 droeschl 7468: border: none;
1.790 droeschl 7469: vertical-align: middle;
1.771 droeschl 7470: }
7471:
1.543 albertel 7472: .LC_docs_spacer {
7473: width: 25px;
7474: height: 1px;
1.771 droeschl 7475: border: none;
1.543 albertel 7476: }
1.346 albertel 7477:
1.532 albertel 7478: .LC_internal_info {
1.735 bisitz 7479: color: #999999;
1.532 albertel 7480: }
7481:
1.794 www 7482: .LC_discussion {
1.1050 www 7483: background: $data_table_dark;
1.911 bisitz 7484: border: 1px solid black;
7485: margin: 2px;
1.794 www 7486: }
7487:
7488: .LC_disc_action_left {
1.1050 www 7489: background: $sidebg;
1.911 bisitz 7490: text-align: left;
1.1050 www 7491: padding: 4px;
7492: margin: 2px;
1.794 www 7493: }
7494:
7495: .LC_disc_action_right {
1.1050 www 7496: background: $sidebg;
1.911 bisitz 7497: text-align: right;
1.1050 www 7498: padding: 4px;
7499: margin: 2px;
1.794 www 7500: }
7501:
7502: .LC_disc_new_item {
1.911 bisitz 7503: background: white;
7504: border: 2px solid red;
1.1050 www 7505: margin: 4px;
7506: padding: 4px;
1.794 www 7507: }
7508:
7509: .LC_disc_old_item {
1.911 bisitz 7510: background: white;
1.1050 www 7511: margin: 4px;
7512: padding: 4px;
1.794 www 7513: }
7514:
1.1468 raeburn 7515: .LC_pastsubmission {
1.458 albertel 7516: border: 1px solid black;
7517: margin: 2px;
1.1468 raeburn 7518: padding: 2px;
1.458 albertel 7519: }
7520:
1.924 bisitz 7521: table#LC_menubuttons {
1.345 albertel 7522: width: 100%;
7523: background: $pgbg;
1.392 albertel 7524: border: 2px;
1.402 albertel 7525: border-collapse: separate;
1.803 bisitz 7526: padding: 0;
1.345 albertel 7527: }
1.392 albertel 7528:
1.801 tempelho 7529: table#LC_title_bar a {
7530: color: $fontmenu;
7531: }
1.836 bisitz 7532:
1.807 droeschl 7533: table#LC_title_bar {
1.819 tempelho 7534: clear: both;
1.836 bisitz 7535: display: none;
1.807 droeschl 7536: }
7537:
1.795 www 7538: table#LC_title_bar,
1.933 droeschl 7539: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7540: table#LC_title_bar.LC_with_remote {
1.359 albertel 7541: width: 100%;
1.392 albertel 7542: border-color: $pgbg;
7543: border-style: solid;
7544: border-width: $border;
1.379 albertel 7545: background: $pgbg;
1.801 tempelho 7546: color: $fontmenu;
1.392 albertel 7547: border-collapse: collapse;
1.803 bisitz 7548: padding: 0;
1.819 tempelho 7549: margin: 0;
1.359 albertel 7550: }
1.795 www 7551:
1.933 droeschl 7552: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7553: margin: 0;
7554: padding: 0;
1.933 droeschl 7555: position: relative;
7556: list-style: none;
1.913 droeschl 7557: }
1.933 droeschl 7558: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7559: display: inline;
7560: }
1.933 droeschl 7561:
7562: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7563: padding: 0;
1.933 droeschl 7564: margin: 0;
7565: float: left;
1.913 droeschl 7566: }
1.933 droeschl 7567: .LC_breadcrumb_tools_tools {
7568: padding: 0;
7569: margin: 0;
1.913 droeschl 7570: float: right;
7571: }
7572:
1.1240 raeburn 7573: .LC_placement_prog {
7574: padding-right: 20px;
7575: font-weight: bold;
7576: font-size: 90%;
7577: }
7578:
1.359 albertel 7579: table#LC_title_bar td {
7580: background: $tabbg;
7581: }
1.795 www 7582:
1.911 bisitz 7583: table#LC_menubuttons img {
1.803 bisitz 7584: border: none;
1.346 albertel 7585: }
1.795 www 7586:
1.842 droeschl 7587: .LC_breadcrumbs_component {
1.911 bisitz 7588: float: right;
7589: margin: 0 1em;
1.357 albertel 7590: }
1.842 droeschl 7591: .LC_breadcrumbs_component img {
1.911 bisitz 7592: vertical-align: middle;
1.777 tempelho 7593: }
1.795 www 7594:
1.1243 raeburn 7595: .LC_breadcrumbs_hoverable {
7596: background: $sidebg;
7597: }
7598:
1.383 albertel 7599: td.LC_table_cell_checkbox {
7600: text-align: center;
7601: }
1.795 www 7602:
7603: .LC_fontsize_small {
1.911 bisitz 7604: font-size: 70%;
1.705 tempelho 7605: }
7606:
1.844 bisitz 7607: #LC_breadcrumbs {
1.911 bisitz 7608: clear:both;
7609: background: $sidebg;
7610: border-bottom: 1px solid $lg_border_color;
7611: line-height: 2.5em;
1.933 droeschl 7612: overflow: hidden;
1.911 bisitz 7613: margin: 0;
7614: padding: 0;
1.995 raeburn 7615: text-align: left;
1.819 tempelho 7616: }
1.862 bisitz 7617:
1.1098 bisitz 7618: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7619: clear:both;
7620: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7621: border: 1px solid $sidebg;
1.1098 bisitz 7622: margin: 0 0 10px 0;
1.966 bisitz 7623: padding: 3px;
1.995 raeburn 7624: text-align: left;
1.822 bisitz 7625: }
7626:
1.795 www 7627: .LC_fontsize_medium {
1.911 bisitz 7628: font-size: 85%;
1.705 tempelho 7629: }
7630:
1.795 www 7631: .LC_fontsize_large {
1.911 bisitz 7632: font-size: 120%;
1.705 tempelho 7633: }
7634:
1.346 albertel 7635: .LC_menubuttons_inline_text {
7636: color: $font;
1.698 harmsja 7637: font-size: 90%;
1.701 harmsja 7638: padding-left:3px;
1.346 albertel 7639: }
7640:
1.934 droeschl 7641: .LC_menubuttons_inline_text img{
7642: vertical-align: middle;
7643: }
7644:
1.1051 www 7645: li.LC_menubuttons_inline_text img {
1.951 onken 7646: cursor:pointer;
1.1002 droeschl 7647: text-decoration: none;
1.951 onken 7648: }
7649:
1.526 www 7650: .LC_menubuttons_link {
7651: text-decoration: none;
7652: }
1.795 www 7653:
1.522 albertel 7654: .LC_menubuttons_category {
1.521 www 7655: color: $font;
1.526 www 7656: background: $pgbg;
1.521 www 7657: font-size: larger;
7658: font-weight: bold;
7659: }
7660:
1.346 albertel 7661: td.LC_menubuttons_text {
1.911 bisitz 7662: color: $font;
1.346 albertel 7663: }
1.706 harmsja 7664:
1.346 albertel 7665: .LC_current_location {
7666: background: $tabbg;
7667: }
1.795 www 7668:
1.1286 raeburn 7669: td.LC_zero_height {
7670: line-height: 0;
7671: cellpadding: 0;
7672: }
7673:
1.938 bisitz 7674: table.LC_data_table {
1.347 albertel 7675: border: 1px solid #000000;
1.402 albertel 7676: border-collapse: separate;
1.426 albertel 7677: border-spacing: 1px;
1.610 albertel 7678: background: $pgbg;
1.347 albertel 7679: }
1.795 www 7680:
1.422 albertel 7681: .LC_data_table_dense {
7682: font-size: small;
7683: }
1.795 www 7684:
1.507 raeburn 7685: table.LC_nested_outer {
7686: border: 1px solid #000000;
1.589 raeburn 7687: border-collapse: collapse;
1.803 bisitz 7688: border-spacing: 0;
1.507 raeburn 7689: width: 100%;
7690: }
1.795 www 7691:
1.879 raeburn 7692: table.LC_innerpickbox,
1.507 raeburn 7693: table.LC_nested {
1.803 bisitz 7694: border: none;
1.589 raeburn 7695: border-collapse: collapse;
1.803 bisitz 7696: border-spacing: 0;
1.507 raeburn 7697: width: 100%;
7698: }
1.795 www 7699:
1.911 bisitz 7700: table.LC_data_table tr th,
7701: table.LC_calendar tr th,
1.879 raeburn 7702: table.LC_prior_tries tr th,
7703: table.LC_innerpickbox tr th {
1.349 albertel 7704: font-weight: bold;
7705: background-color: $data_table_head;
1.801 tempelho 7706: color:$fontmenu;
1.701 harmsja 7707: font-size:90%;
1.347 albertel 7708: }
1.795 www 7709:
1.879 raeburn 7710: table.LC_innerpickbox tr th,
7711: table.LC_innerpickbox tr td {
7712: vertical-align: top;
7713: }
7714:
1.711 raeburn 7715: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7716: background-color: #CCCCCC;
1.711 raeburn 7717: font-weight: bold;
7718: text-align: left;
7719: }
1.795 www 7720:
1.912 bisitz 7721: table.LC_data_table tr.LC_odd_row > td {
7722: background-color: $data_table_light;
7723: padding: 2px;
7724: vertical-align: top;
7725: }
7726:
1.809 bisitz 7727: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7728: background-color: $data_table_light;
1.912 bisitz 7729: vertical-align: top;
7730: }
7731:
7732: table.LC_data_table tr.LC_even_row > td {
7733: background-color: $data_table_dark;
1.425 albertel 7734: padding: 2px;
1.900 bisitz 7735: vertical-align: top;
1.347 albertel 7736: }
1.795 www 7737:
1.809 bisitz 7738: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7739: background-color: $data_table_dark;
1.900 bisitz 7740: vertical-align: top;
1.347 albertel 7741: }
1.795 www 7742:
1.425 albertel 7743: table.LC_data_table tr.LC_data_table_highlight td {
7744: background-color: $data_table_darker;
7745: }
1.795 www 7746:
1.639 raeburn 7747: table.LC_data_table tr td.LC_leftcol_header {
7748: background-color: $data_table_head;
7749: font-weight: bold;
7750: }
1.795 www 7751:
1.451 albertel 7752: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7753: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7754: font-weight: bold;
7755: font-style: italic;
7756: text-align: center;
7757: padding: 8px;
1.347 albertel 7758: }
1.795 www 7759:
1.1114 raeburn 7760: table.LC_data_table tr.LC_empty_row td,
7761: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7762: background-color: $sidebg;
7763: }
7764:
7765: table.LC_nested tr.LC_empty_row td {
7766: background-color: #FFFFFF;
7767: }
7768:
1.890 droeschl 7769: table.LC_caption {
7770: }
7771:
1.1469 raeburn 7772: caption.LC_caption_prefs {
7773: font-weight: normal;
7774: text-align: left;
7775: padding-bottom: 0.8em;
7776: }
7777:
1.507 raeburn 7778: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7779: padding: 4ex
7780: }
1.795 www 7781:
1.507 raeburn 7782: table.LC_nested_outer tr th {
7783: font-weight: bold;
1.801 tempelho 7784: color:$fontmenu;
1.507 raeburn 7785: background-color: $data_table_head;
1.701 harmsja 7786: font-size: small;
1.507 raeburn 7787: border-bottom: 1px solid #000000;
7788: }
1.795 www 7789:
1.507 raeburn 7790: table.LC_nested_outer tr td.LC_subheader {
7791: background-color: $data_table_head;
7792: font-weight: bold;
7793: font-size: small;
7794: border-bottom: 1px solid #000000;
7795: text-align: right;
1.451 albertel 7796: }
1.795 www 7797:
1.507 raeburn 7798: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7799: background-color: #CCCCCC;
1.451 albertel 7800: font-weight: bold;
7801: font-size: small;
1.507 raeburn 7802: text-align: center;
7803: }
1.795 www 7804:
1.589 raeburn 7805: table.LC_nested tr.LC_info_row td.LC_left_item,
7806: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7807: text-align: left;
1.451 albertel 7808: }
1.795 www 7809:
1.507 raeburn 7810: table.LC_nested td {
1.735 bisitz 7811: background-color: #FFFFFF;
1.451 albertel 7812: font-size: small;
1.507 raeburn 7813: }
1.795 www 7814:
1.507 raeburn 7815: table.LC_nested_outer tr th.LC_right_item,
7816: table.LC_nested tr.LC_info_row td.LC_right_item,
7817: table.LC_nested tr.LC_odd_row td.LC_right_item,
7818: table.LC_nested tr td.LC_right_item {
1.451 albertel 7819: text-align: right;
7820: }
7821:
1.507 raeburn 7822: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7823: background-color: #EEEEEE;
1.451 albertel 7824: }
7825:
1.473 raeburn 7826: table.LC_createuser {
7827: }
7828:
7829: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7830: font-size: small;
1.473 raeburn 7831: }
7832:
7833: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7834: background-color: #CCCCCC;
1.473 raeburn 7835: font-weight: bold;
7836: text-align: center;
7837: }
7838:
1.349 albertel 7839: table.LC_calendar {
7840: border: 1px solid #000000;
7841: border-collapse: collapse;
1.917 raeburn 7842: width: 98%;
1.349 albertel 7843: }
1.795 www 7844:
1.349 albertel 7845: table.LC_calendar_pickdate {
7846: font-size: xx-small;
7847: }
1.795 www 7848:
1.349 albertel 7849: table.LC_calendar tr td {
7850: border: 1px solid #000000;
7851: vertical-align: top;
1.917 raeburn 7852: width: 14%;
1.349 albertel 7853: }
1.795 www 7854:
1.349 albertel 7855: table.LC_calendar tr td.LC_calendar_day_empty {
7856: background-color: $data_table_dark;
7857: }
1.795 www 7858:
1.779 bisitz 7859: table.LC_calendar tr td.LC_calendar_day_current {
7860: background-color: $data_table_highlight;
1.777 tempelho 7861: }
1.795 www 7862:
1.938 bisitz 7863: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7864: background-color: $mail_new;
7865: }
1.795 www 7866:
1.938 bisitz 7867: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7868: background-color: $mail_new_hover;
7869: }
1.795 www 7870:
1.938 bisitz 7871: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7872: background-color: $mail_read;
7873: }
1.795 www 7874:
1.938 bisitz 7875: /*
7876: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7877: background-color: $mail_read_hover;
7878: }
1.938 bisitz 7879: */
1.795 www 7880:
1.938 bisitz 7881: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7882: background-color: $mail_replied;
7883: }
1.795 www 7884:
1.938 bisitz 7885: /*
7886: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7887: background-color: $mail_replied_hover;
7888: }
1.938 bisitz 7889: */
1.795 www 7890:
1.938 bisitz 7891: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7892: background-color: $mail_other;
7893: }
1.795 www 7894:
1.938 bisitz 7895: /*
7896: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7897: background-color: $mail_other_hover;
7898: }
1.938 bisitz 7899: */
1.494 raeburn 7900:
1.777 tempelho 7901: table.LC_data_table tr > td.LC_browser_file,
7902: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7903: background: #AAEE77;
1.389 albertel 7904: }
1.795 www 7905:
1.777 tempelho 7906: table.LC_data_table tr > td.LC_browser_file_locked,
7907: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7908: background: #FFAA99;
1.387 albertel 7909: }
1.795 www 7910:
1.777 tempelho 7911: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7912: background: #888888;
1.779 bisitz 7913: }
1.795 www 7914:
1.777 tempelho 7915: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7916: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7917: background: #F8F866;
1.777 tempelho 7918: }
1.795 www 7919:
1.696 bisitz 7920: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7921: background: #E0E8FF;
1.387 albertel 7922: }
1.696 bisitz 7923:
1.707 bisitz 7924: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7925: /* background: #77FF77; */
1.707 bisitz 7926: }
1.795 www 7927:
1.707 bisitz 7928: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7929: border-right: 8px solid #FFFF77;
1.707 bisitz 7930: }
1.795 www 7931:
1.707 bisitz 7932: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7933: border-right: 8px solid #FFAA77;
1.707 bisitz 7934: }
1.795 www 7935:
1.707 bisitz 7936: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7937: border-right: 8px solid #FF7777;
1.707 bisitz 7938: }
1.795 www 7939:
1.707 bisitz 7940: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7941: border-right: 8px solid #AAFF77;
1.707 bisitz 7942: }
1.795 www 7943:
1.707 bisitz 7944: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7945: border-right: 8px solid #11CC55;
1.707 bisitz 7946: }
7947:
1.1469 raeburn 7948: table.LC_data_table tr.LC_prefs_row {
7949: line-height: 250%;
7950: }
7951:
1.388 albertel 7952: span.LC_current_location {
1.701 harmsja 7953: font-size:larger;
1.388 albertel 7954: background: $pgbg;
7955: }
1.387 albertel 7956:
1.1029 www 7957: span.LC_current_nav_location {
7958: font-weight:bold;
7959: background: $sidebg;
7960: }
7961:
1.395 albertel 7962: span.LC_parm_menu_item {
7963: font-size: larger;
7964: }
1.795 www 7965:
1.395 albertel 7966: span.LC_parm_scope_all {
7967: color: red;
7968: }
1.795 www 7969:
1.395 albertel 7970: span.LC_parm_scope_folder {
7971: color: green;
7972: }
1.795 www 7973:
1.395 albertel 7974: span.LC_parm_scope_resource {
7975: color: orange;
7976: }
1.795 www 7977:
1.395 albertel 7978: span.LC_parm_part {
7979: color: blue;
7980: }
1.795 www 7981:
1.911 bisitz 7982: span.LC_parm_folder,
7983: span.LC_parm_symb {
1.395 albertel 7984: font-size: x-small;
7985: font-family: $mono;
7986: color: #AAAAAA;
7987: }
7988:
1.977 bisitz 7989: ul.LC_parm_parmlist li {
7990: display: inline-block;
7991: padding: 0.3em 0.8em;
7992: vertical-align: top;
7993: width: 150px;
7994: border-top:1px solid $lg_border_color;
7995: }
7996:
1.795 www 7997: td.LC_parm_overview_level_menu,
7998: td.LC_parm_overview_map_menu,
7999: td.LC_parm_overview_parm_selectors,
8000: td.LC_parm_overview_restrictions {
1.396 albertel 8001: border: 1px solid black;
8002: border-collapse: collapse;
8003: }
1.795 www 8004:
1.1285 raeburn 8005: span.LC_parm_recursive,
8006: td.LC_parm_recursive {
8007: font-weight: bold;
8008: font-size: smaller;
8009: }
8010:
1.396 albertel 8011: table.LC_parm_overview_restrictions td {
8012: border-width: 1px 4px 1px 4px;
8013: border-style: solid;
8014: border-color: $pgbg;
8015: text-align: center;
8016: }
1.795 www 8017:
1.396 albertel 8018: table.LC_parm_overview_restrictions th {
8019: background: $tabbg;
8020: border-width: 1px 4px 1px 4px;
8021: border-style: solid;
8022: border-color: $pgbg;
8023: }
1.795 www 8024:
1.1459 raeburn 8025: h1.LC_helpmenu {
8026: display: inline;
8027: font-size: 100%;
8028: font-weight: normal;
8029: line-height: 1em;
8030: margin: 0;
8031: padding: 0;
8032: border: 0;
1.398 albertel 8033: }
1.795 www 8034:
1.1456 raeburn 8035: .LC_helpdesk_headbox {
8036: border: 2px groove threedface;
8037: padding: 1em;
8038: }
8039:
8040: h1.LC_helpdesk_legend {
8041: float: left;
8042: margin: -1.7em 0 0;
8043: padding: 0 .5em;
1.397 albertel 8044: background: $pgbg;
1.1456 raeburn 8045: font-size: 1em;
8046: font-weight: bold;
8047: }
8048:
8049: h1.LC_helpdesk_title {
8050: display: inline;
8051: font-size: 1em;
8052: line-height: 2.5em;
8053: margin: 0;
1.803 bisitz 8054: padding: 0;
1.1456 raeburn 8055: vertical-align: bottom;
1.397 albertel 8056: }
1.795 www 8057:
1.1456 raeburn 8058: .LC_helpdesk_links {
8059: border: 1px solid black;
8060: padding: 3px;
1.397 albertel 8061: background: $tabbg;
1.399 albertel 8062: text-align: center;
8063: font-weight: bold;
1.1456 raeburn 8064: display: inline;
8065: margin-right: -6px;
8066: }
8067:
8068: .LC_helpdesk_img,
8069: .LC_helpdesk_text {
8070: padding: 0;
8071: margin: 0;
8072: border: 0;
8073: display: inline;
1.397 albertel 8074: }
1.396 albertel 8075:
1.1456 raeburn 8076: .LC_helpdesk_img a:link,
8077: .LC_helpdesk_img a:visited,
8078: .LC_helpdesk_img a:active,
8079: .LC_helpdesk_text a:link,
8080: .LC_helpdesk_text a:visited,
8081: .LC_helpdesk_text a:active {
1.397 albertel 8082: text-decoration: none;
8083: color: $font;
8084: }
1.795 www 8085:
1.1456 raeburn 8086: div.LC_helpdesk_text a:hover {
1.397 albertel 8087: text-decoration: underline;
8088: color: $vlink;
8089: }
1.396 albertel 8090:
1.417 albertel 8091: .LC_chrt_popup_exists {
8092: border: 1px solid #339933;
8093: margin: -1px;
8094: }
1.795 www 8095:
1.417 albertel 8096: .LC_chrt_popup_up {
8097: border: 1px solid yellow;
8098: margin: -1px;
8099: }
1.795 www 8100:
1.417 albertel 8101: .LC_chrt_popup {
8102: border: 1px solid #8888FF;
8103: background: #CCCCFF;
8104: }
1.795 www 8105:
1.421 albertel 8106: table.LC_pick_box {
8107: border-collapse: separate;
8108: background: white;
8109: border: 1px solid black;
8110: border-spacing: 1px;
8111: }
1.795 www 8112:
1.1454 raeburn 8113: table.LC_pick_box th.LC_pick_box_title {
1.850 bisitz 8114: background: $sidebg;
1.421 albertel 8115: font-weight: bold;
1.900 bisitz 8116: text-align: left;
1.740 bisitz 8117: vertical-align: top;
1.421 albertel 8118: width: 184px;
8119: padding: 8px;
8120: }
1.795 www 8121:
1.579 raeburn 8122: table.LC_pick_box td.LC_pick_box_value {
8123: text-align: left;
8124: padding: 8px;
8125: }
1.795 www 8126:
1.579 raeburn 8127: table.LC_pick_box td.LC_pick_box_select {
8128: text-align: left;
8129: padding: 8px;
8130: }
1.795 www 8131:
1.424 albertel 8132: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 8133: padding: 0;
1.421 albertel 8134: height: 1px;
8135: background: black;
8136: }
1.795 www 8137:
1.421 albertel 8138: table.LC_pick_box td.LC_pick_box_submit {
8139: text-align: right;
8140: }
1.795 www 8141:
1.579 raeburn 8142: table.LC_pick_box td.LC_evenrow_value {
8143: text-align: left;
8144: padding: 8px;
8145: background-color: $data_table_light;
8146: }
1.795 www 8147:
1.579 raeburn 8148: table.LC_pick_box td.LC_oddrow_value {
8149: text-align: left;
8150: padding: 8px;
8151: background-color: $data_table_light;
8152: }
1.795 www 8153:
1.579 raeburn 8154: span.LC_helpform_receipt_cat {
8155: font-weight: bold;
8156: }
1.795 www 8157:
1.424 albertel 8158: table.LC_group_priv_box {
8159: background: white;
8160: border: 1px solid black;
8161: border-spacing: 1px;
8162: }
1.795 www 8163:
1.424 albertel 8164: table.LC_group_priv_box td.LC_pick_box_title {
8165: background: $tabbg;
8166: font-weight: bold;
8167: text-align: right;
8168: width: 184px;
8169: }
1.795 www 8170:
1.424 albertel 8171: table.LC_group_priv_box td.LC_groups_fixed {
8172: background: $data_table_light;
8173: text-align: center;
8174: }
1.795 www 8175:
1.424 albertel 8176: table.LC_group_priv_box td.LC_groups_optional {
8177: background: $data_table_dark;
8178: text-align: center;
8179: }
1.795 www 8180:
1.424 albertel 8181: table.LC_group_priv_box td.LC_groups_functionality {
8182: background: $data_table_darker;
8183: text-align: center;
8184: font-weight: bold;
8185: }
1.795 www 8186:
1.424 albertel 8187: table.LC_group_priv td {
8188: text-align: left;
1.803 bisitz 8189: padding: 0;
1.424 albertel 8190: }
8191:
8192: .LC_navbuttons {
8193: margin: 2ex 0ex 2ex 0ex;
8194: }
1.795 www 8195:
1.423 albertel 8196: .LC_topic_bar {
8197: font-weight: bold;
8198: background: $tabbg;
1.918 wenzelju 8199: margin: 1em 0em 1em 2em;
1.805 bisitz 8200: padding: 3px;
1.918 wenzelju 8201: font-size: 1.2em;
1.423 albertel 8202: }
1.795 www 8203:
1.423 albertel 8204: .LC_topic_bar span {
1.918 wenzelju 8205: left: 0.5em;
8206: position: absolute;
1.423 albertel 8207: vertical-align: middle;
1.918 wenzelju 8208: font-size: 1.2em;
1.423 albertel 8209: }
1.795 www 8210:
1.423 albertel 8211: table.LC_course_group_status {
8212: margin: 20px;
8213: }
1.795 www 8214:
1.423 albertel 8215: table.LC_status_selector td {
8216: vertical-align: top;
8217: text-align: center;
1.424 albertel 8218: padding: 4px;
8219: }
1.795 www 8220:
1.599 albertel 8221: div.LC_feedback_link {
1.616 albertel 8222: clear: both;
1.829 kalberla 8223: background: $sidebg;
1.779 bisitz 8224: width: 100%;
1.829 kalberla 8225: padding-bottom: 10px;
8226: border: 1px $tabbg solid;
1.833 kalberla 8227: height: 22px;
8228: line-height: 22px;
8229: padding-top: 5px;
8230: }
8231:
8232: div.LC_feedback_link img {
8233: height: 22px;
1.867 kalberla 8234: vertical-align:middle;
1.829 kalberla 8235: }
8236:
1.911 bisitz 8237: div.LC_feedback_link a {
1.829 kalberla 8238: text-decoration: none;
1.489 raeburn 8239: }
1.795 www 8240:
1.867 kalberla 8241: div.LC_comblock {
1.911 bisitz 8242: display:inline;
1.867 kalberla 8243: color:$font;
8244: font-size:90%;
8245: }
8246:
8247: div.LC_feedback_link div.LC_comblock {
8248: padding-left:5px;
8249: }
8250:
8251: div.LC_feedback_link div.LC_comblock a {
8252: color:$font;
8253: }
8254:
1.489 raeburn 8255: span.LC_feedback_link {
1.858 bisitz 8256: /* background: $feedback_link_bg; */
1.599 albertel 8257: font-size: larger;
8258: }
1.795 www 8259:
1.599 albertel 8260: span.LC_message_link {
1.858 bisitz 8261: /* background: $feedback_link_bg; */
1.599 albertel 8262: font-size: larger;
8263: position: absolute;
8264: right: 1em;
1.489 raeburn 8265: }
1.421 albertel 8266:
1.515 albertel 8267: table.LC_prior_tries {
1.524 albertel 8268: border: 1px solid #000000;
8269: border-collapse: separate;
8270: border-spacing: 1px;
1.515 albertel 8271: }
1.523 albertel 8272:
1.515 albertel 8273: table.LC_prior_tries td {
1.524 albertel 8274: padding: 2px;
1.515 albertel 8275: }
1.523 albertel 8276:
8277: .LC_answer_correct {
1.795 www 8278: background: lightgreen;
8279: color: darkgreen;
8280: padding: 6px;
1.523 albertel 8281: }
1.795 www 8282:
1.523 albertel 8283: .LC_answer_charged_try {
1.797 www 8284: background: #FFAAAA;
1.795 www 8285: color: darkred;
8286: padding: 6px;
1.523 albertel 8287: }
1.795 www 8288:
1.779 bisitz 8289: .LC_answer_not_charged_try,
1.523 albertel 8290: .LC_answer_no_grade,
8291: .LC_answer_late {
1.795 www 8292: background: lightyellow;
1.523 albertel 8293: color: black;
1.795 www 8294: padding: 6px;
1.523 albertel 8295: }
1.795 www 8296:
1.523 albertel 8297: .LC_answer_previous {
1.795 www 8298: background: lightblue;
8299: color: darkblue;
8300: padding: 6px;
1.523 albertel 8301: }
1.795 www 8302:
1.779 bisitz 8303: .LC_answer_no_message {
1.777 tempelho 8304: background: #FFFFFF;
8305: color: black;
1.795 www 8306: padding: 6px;
1.779 bisitz 8307: }
1.795 www 8308:
1.1334 raeburn 8309: .LC_answer_unknown,
8310: .LC_answer_warning {
1.779 bisitz 8311: background: orange;
8312: color: black;
1.795 www 8313: padding: 6px;
1.777 tempelho 8314: }
1.795 www 8315:
1.1467 raeburn 8316: span.LC_prob_status {
8317: margin: 5px 0 0 0;
8318: padding: 0 5px 0 0;
8319: vertical-align: middle;
8320: }
8321:
8322: div.LC_prob_status_outer {
8323: display: inline-block;
8324: margin: -5px 0 0 0;
8325: padding: 0;
8326: }
8327:
8328: div.LC_prob_status_inner {
8329: display: inline-block;
8330: margin: 0 5px 0 0;
8331: padding: 5px;
1.1446 raeburn 8332: }
8333:
1.1468 raeburn 8334: caption.LC_filesub_status {
8335: text-align: left;
8336: font-weight: bold;
8337: }
8338:
1.1448 raeburn 8339: .LC_mail_actions {
8340: float: left;
8341: padding: 0;
8342: margin: 6px;
8343: }
8344:
8345: .LC_vertical_line {
8346: width: 1px;
8347: background-color: black;
8348: height: 4em;
8349: float: left;
8350: margin: 0;
8351: padding: 0;
8352: }
8353:
1.529 albertel 8354: span.LC_prior_numerical,
8355: span.LC_prior_string,
8356: span.LC_prior_custom,
8357: span.LC_prior_reaction,
8358: span.LC_prior_math {
1.925 bisitz 8359: font-family: $mono;
1.523 albertel 8360: white-space: pre;
8361: }
8362:
1.525 albertel 8363: span.LC_prior_string {
1.925 bisitz 8364: font-family: $mono;
1.525 albertel 8365: white-space: pre;
8366: }
8367:
1.523 albertel 8368: table.LC_prior_option {
8369: width: 100%;
8370: border-collapse: collapse;
8371: }
1.795 www 8372:
1.911 bisitz 8373: table.LC_prior_rank,
1.795 www 8374: table.LC_prior_match {
1.528 albertel 8375: border-collapse: collapse;
8376: }
1.795 www 8377:
1.528 albertel 8378: table.LC_prior_option tr td,
8379: table.LC_prior_rank tr td,
8380: table.LC_prior_match tr td {
1.524 albertel 8381: border: 1px solid #000000;
1.515 albertel 8382: }
8383:
1.855 bisitz 8384: .LC_nobreak {
1.544 albertel 8385: white-space: nowrap;
1.519 raeburn 8386: }
8387:
1.576 raeburn 8388: span.LC_cusr_emph {
8389: font-style: italic;
8390: }
8391:
1.633 raeburn 8392: span.LC_cusr_subheading {
8393: font-weight: normal;
8394: font-size: 85%;
8395: }
8396:
1.861 bisitz 8397: div.LC_docs_entry_move {
1.859 bisitz 8398: border: 1px solid #BBBBBB;
1.545 albertel 8399: background: #DDDDDD;
1.861 bisitz 8400: width: 22px;
1.859 bisitz 8401: padding: 1px;
8402: margin: 0;
1.545 albertel 8403: }
8404:
1.861 bisitz 8405: table.LC_data_table tr > td.LC_docs_entry_commands,
8406: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 8407: font-size: x-small;
8408: }
1.795 www 8409:
1.861 bisitz 8410: .LC_docs_entry_parameter {
8411: white-space: nowrap;
8412: }
8413:
1.544 albertel 8414: .LC_docs_copy {
1.545 albertel 8415: color: #000099;
1.544 albertel 8416: }
1.795 www 8417:
1.544 albertel 8418: .LC_docs_cut {
1.545 albertel 8419: color: #550044;
1.544 albertel 8420: }
1.795 www 8421:
1.544 albertel 8422: .LC_docs_rename {
1.545 albertel 8423: color: #009900;
1.544 albertel 8424: }
1.795 www 8425:
1.544 albertel 8426: .LC_docs_remove {
1.545 albertel 8427: color: #990000;
8428: }
8429:
1.1284 raeburn 8430: .LC_docs_alias {
8431: color: #440055;
8432: }
8433:
1.1286 raeburn 8434: .LC_domprefs_email,
1.1284 raeburn 8435: .LC_docs_alias_name,
1.547 albertel 8436: .LC_docs_reinit_warn,
8437: .LC_docs_ext_edit {
8438: font-size: x-small;
8439: }
8440:
1.545 albertel 8441: table.LC_docs_adddocs td,
8442: table.LC_docs_adddocs th {
8443: border: 1px solid #BBBBBB;
8444: padding: 4px;
8445: background: #DDDDDD;
1.543 albertel 8446: }
8447:
1.584 albertel 8448: table.LC_sty_begin {
8449: background: #BBFFBB;
8450: }
1.795 www 8451:
1.584 albertel 8452: table.LC_sty_end {
8453: background: #FFBBBB;
8454: }
8455:
1.589 raeburn 8456: table.LC_double_column {
1.803 bisitz 8457: border-width: 0;
1.589 raeburn 8458: border-collapse: collapse;
8459: width: 100%;
8460: padding: 2px;
8461: }
8462:
8463: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 8464: top: 2px;
1.589 raeburn 8465: left: 2px;
8466: width: 47%;
8467: vertical-align: top;
8468: }
8469:
8470: table.LC_double_column tr td.LC_right_col {
8471: top: 2px;
1.779 bisitz 8472: right: 2px;
1.589 raeburn 8473: width: 47%;
8474: vertical-align: top;
8475: }
8476:
1.591 raeburn 8477: div.LC_left_float {
8478: float: left;
8479: padding-right: 5%;
1.597 albertel 8480: padding-bottom: 4px;
1.591 raeburn 8481: }
8482:
8483: div.LC_clear_float_header {
1.597 albertel 8484: padding-bottom: 2px;
1.591 raeburn 8485: }
8486:
8487: div.LC_clear_float_footer {
1.597 albertel 8488: padding-top: 10px;
1.591 raeburn 8489: clear: both;
8490: }
8491:
1.597 albertel 8492: div.LC_grade_show_user {
1.941 bisitz 8493: /* border-left: 5px solid $sidebg; */
8494: border-top: 5px solid #000000;
8495: margin: 50px 0 0 0;
1.936 bisitz 8496: padding: 15px 0 5px 10px;
1.597 albertel 8497: }
1.795 www 8498:
1.936 bisitz 8499: div.LC_grade_show_user_odd_row {
1.941 bisitz 8500: /* border-left: 5px solid #000000; */
8501: }
8502:
8503: div.LC_grade_show_user div.LC_Box {
8504: margin-right: 50px;
1.597 albertel 8505: }
8506:
1.1461 raeburn 8507: div.LC_grade_show_user div.LC_Box table tr th {
8508: font-weight: normal;
8509: }
8510:
1.597 albertel 8511: div.LC_grade_submissions,
8512: div.LC_grade_message_center,
1.936 bisitz 8513: div.LC_grade_info_links {
1.597 albertel 8514: margin: 5px;
8515: width: 99%;
8516: background: #FFFFFF;
8517: }
1.795 www 8518:
1.597 albertel 8519: div.LC_grade_submissions_header,
1.936 bisitz 8520: div.LC_grade_message_center_header {
1.705 tempelho 8521: font-weight: bold;
8522: font-size: large;
1.597 albertel 8523: }
1.795 www 8524:
1.597 albertel 8525: div.LC_grade_submissions_body,
1.936 bisitz 8526: div.LC_grade_message_center_body {
1.597 albertel 8527: border: 1px solid black;
8528: width: 99%;
8529: background: #FFFFFF;
8530: }
1.795 www 8531:
1.613 albertel 8532: table.LC_scantron_action {
8533: width: 100%;
8534: }
1.795 www 8535:
1.613 albertel 8536: table.LC_scantron_action tr th {
1.698 harmsja 8537: font-weight:bold;
8538: font-style:normal;
1.613 albertel 8539: }
1.795 www 8540:
1.1461 raeburn 8541: div.LC_edit_problem_daxe_header {
8542: padding: 3px;
8543: background: $tabbg;
8544: z-index: 100;
8545: }
8546:
1.779 bisitz 8547: .LC_edit_problem_header,
1.614 albertel 8548: div.LC_edit_problem_footer {
1.705 tempelho 8549: font-weight: normal;
8550: font-size: medium;
1.602 albertel 8551: margin: 2px;
1.1060 bisitz 8552: background-color: $sidebg;
1.600 albertel 8553: }
1.795 www 8554:
1.600 albertel 8555: div.LC_edit_problem_header,
1.602 albertel 8556: div.LC_edit_problem_header div,
1.614 albertel 8557: div.LC_edit_problem_footer,
8558: div.LC_edit_problem_footer div,
1.602 albertel 8559: div.LC_edit_problem_editxml_header,
8560: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8561: z-index: 100;
1.600 albertel 8562: }
1.795 www 8563:
1.600 albertel 8564: div.LC_edit_problem_header_title {
1.705 tempelho 8565: font-weight: bold;
8566: font-size: larger;
1.602 albertel 8567: background: $tabbg;
8568: padding: 3px;
1.1060 bisitz 8569: margin: 0 0 5px 0;
1.602 albertel 8570: }
1.795 www 8571:
1.602 albertel 8572: table.LC_edit_problem_header_title {
8573: width: 100%;
1.600 albertel 8574: background: $tabbg;
1.602 albertel 8575: }
8576:
1.1205 golterma 8577: div.LC_edit_actionbar {
8578: background-color: $sidebg;
1.1218 droeschl 8579: margin: 0;
8580: padding: 0;
8581: line-height: 200%;
1.602 albertel 8582: }
1.795 www 8583:
1.1218 droeschl 8584: div.LC_edit_actionbar div{
8585: padding: 0;
8586: margin: 0;
8587: display: inline-block;
1.600 albertel 8588: }
1.795 www 8589:
1.1124 bisitz 8590: .LC_edit_opt {
8591: padding-left: 1em;
8592: white-space: nowrap;
8593: }
8594:
1.1152 golterma 8595: .LC_edit_problem_latexhelper{
8596: text-align: right;
8597: }
8598:
8599: #LC_edit_problem_colorful div{
8600: margin-left: 40px;
8601: }
8602:
1.1205 golterma 8603: #LC_edit_problem_codemirror div{
8604: margin-left: 0px;
8605: }
8606:
1.911 bisitz 8607: img.stift {
1.803 bisitz 8608: border-width: 0;
8609: vertical-align: middle;
1.677 riegler 8610: }
1.680 riegler 8611:
1.1460 raeburn 8612: div.LC_mainmenu {
8613: margin: 3px 2px 2px 1px;
8614: float: left;
1.777 tempelho 8615: }
1.795 www 8616:
1.716 raeburn 8617: div.LC_createcourse {
1.911 bisitz 8618: margin: 10px 10px 10px 10px;
1.716 raeburn 8619: }
8620:
1.917 raeburn 8621: .LC_dccid {
1.1130 raeburn 8622: float: right;
1.917 raeburn 8623: margin: 0.2em 0 0 0;
8624: padding: 0;
8625: font-size: 90%;
8626: display:none;
8627: }
8628:
1.897 wenzelju 8629: ol.LC_primary_menu a:hover,
1.721 harmsja 8630: ol#LC_MenuBreadcrumbs a:hover,
8631: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8632: ul#LC_secondary_menu a:hover,
1.721 harmsja 8633: .LC_FormSectionClearButton input:hover
1.795 www 8634: ul.LC_TabContent li:hover a {
1.952 onken 8635: color:$button_hover;
1.911 bisitz 8636: text-decoration:none;
1.693 droeschl 8637: }
8638:
1.779 bisitz 8639: h1 {
1.911 bisitz 8640: padding: 0;
8641: line-height:130%;
1.693 droeschl 8642: }
1.698 harmsja 8643:
1.911 bisitz 8644: h2,
8645: h3,
8646: h4,
8647: h5,
8648: h6 {
8649: margin: 5px 0 5px 0;
8650: padding: 0;
8651: line-height:130%;
1.693 droeschl 8652: }
1.795 www 8653:
8654: .LC_hcell {
1.911 bisitz 8655: padding:3px 15px 3px 15px;
8656: margin: 0;
8657: background-color:$tabbg;
8658: color:$fontmenu;
8659: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8660: }
1.795 www 8661:
1.840 bisitz 8662: .LC_Box > .LC_hcell {
1.911 bisitz 8663: margin: 0 -10px 10px -10px;
1.835 bisitz 8664: }
8665:
1.721 harmsja 8666: .LC_noBorder {
1.911 bisitz 8667: border: 0;
1.698 harmsja 8668: }
1.693 droeschl 8669:
1.721 harmsja 8670: .LC_FormSectionClearButton input {
1.911 bisitz 8671: background-color:transparent;
8672: border: none;
8673: cursor:pointer;
8674: text-decoration:underline;
1.693 droeschl 8675: }
1.763 bisitz 8676:
8677: .LC_help_open_topic {
1.911 bisitz 8678: color: #FFFFFF;
8679: background-color: #EEEEFF;
8680: margin: 1px;
8681: padding: 4px;
8682: border: 1px solid #000033;
8683: white-space: nowrap;
8684: /* vertical-align: middle; */
1.759 neumanie 8685: }
1.693 droeschl 8686:
1.911 bisitz 8687: dl,
8688: ul,
8689: div,
8690: fieldset {
8691: margin: 10px 10px 10px 0;
8692: /* overflow: hidden; */
1.693 droeschl 8693: }
1.795 www 8694:
1.1404 raeburn 8695: fieldset#LC_selectuser {
1.1460 raeburn 8696: margin: -1px 0 0 0;
8697: padding: 0;
8698: border: 0;
1.1404 raeburn 8699: }
8700:
1.1211 raeburn 8701: article.geogebraweb div {
8702: margin: 0;
8703: }
8704:
1.838 bisitz 8705: fieldset > legend {
1.911 bisitz 8706: font-weight: bold;
8707: padding: 0 5px 0 5px;
1.838 bisitz 8708: }
8709:
1.813 bisitz 8710: #LC_nav_bar {
1.911 bisitz 8711: float: left;
1.995 raeburn 8712: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8713: margin: 0 0 2px 0;
1.807 droeschl 8714: }
8715:
1.916 droeschl 8716: #LC_realm {
8717: margin: 0.2em 0 0 0;
8718: padding: 0;
8719: font-weight: bold;
8720: text-align: center;
1.995 raeburn 8721: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8722: }
8723:
1.911 bisitz 8724: #LC_nav_bar em {
8725: font-weight: bold;
8726: font-style: normal;
1.807 droeschl 8727: }
8728:
1.897 wenzelju 8729: ol.LC_primary_menu {
1.934 droeschl 8730: margin: 0;
1.1076 raeburn 8731: padding: 0;
1.807 droeschl 8732: }
8733:
1.852 droeschl 8734: ol#LC_PathBreadcrumbs {
1.911 bisitz 8735: margin: 0;
1.693 droeschl 8736: }
8737:
1.897 wenzelju 8738: ol.LC_primary_menu li {
1.1076 raeburn 8739: color: RGB(80, 80, 80);
8740: vertical-align: middle;
8741: text-align: left;
8742: list-style: none;
1.1205 golterma 8743: position: relative;
1.1076 raeburn 8744: float: left;
1.1205 golterma 8745: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8746: line-height: 1.5em;
1.1076 raeburn 8747: }
8748:
1.1205 golterma 8749: ol.LC_primary_menu li a,
8750: ol.LC_primary_menu li p {
1.1076 raeburn 8751: display: block;
8752: margin: 0;
8753: padding: 0 5px 0 10px;
8754: text-decoration: none;
8755: }
8756:
1.1205 golterma 8757: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8758: display: inline-block;
8759: width: 95%;
8760: text-align: left;
8761: }
8762:
8763: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8764: display: inline-block;
8765: width: 5%;
8766: float: right;
8767: text-align: right;
8768: font-size: 70%;
8769: }
8770:
8771: ol.LC_primary_menu ul {
1.1076 raeburn 8772: display: none;
1.1205 golterma 8773: width: 15em;
1.1076 raeburn 8774: background-color: $data_table_light;
1.1205 golterma 8775: position: absolute;
8776: top: 100%;
1.1076 raeburn 8777: }
8778:
1.1205 golterma 8779: ol.LC_primary_menu ul ul {
8780: left: 100%;
8781: top: 0;
8782: }
8783:
8784: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8785: display: block;
8786: position: absolute;
8787: margin: 0;
8788: padding: 0;
1.1078 raeburn 8789: z-index: 2;
1.1076 raeburn 8790: }
8791:
8792: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8793: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8794: font-size: 90%;
1.911 bisitz 8795: vertical-align: top;
1.1076 raeburn 8796: float: none;
1.1079 raeburn 8797: border-left: 1px solid black;
8798: border-right: 1px solid black;
1.1205 golterma 8799: /* A dark bottom border to visualize different menu options;
8800: overwritten in the create_submenu routine for the last border-bottom of the menu */
8801: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8802: }
8803:
1.1205 golterma 8804: ol.LC_primary_menu li li p:hover {
8805: color:$button_hover;
8806: text-decoration:none;
8807: background-color:$data_table_dark;
1.1076 raeburn 8808: }
8809:
8810: ol.LC_primary_menu li li a:hover {
8811: color:$button_hover;
8812: background-color:$data_table_dark;
1.693 droeschl 8813: }
8814:
1.1205 golterma 8815: /* Font-size equal to the size of the predecessors*/
8816: ol.LC_primary_menu li:hover li li {
8817: font-size: 100%;
8818: }
8819:
1.897 wenzelju 8820: ol.LC_primary_menu li img {
1.911 bisitz 8821: vertical-align: bottom;
1.934 droeschl 8822: height: 1.1em;
1.1077 raeburn 8823: margin: 0.2em 0 0 0;
1.693 droeschl 8824: }
8825:
1.897 wenzelju 8826: ol.LC_primary_menu a {
1.911 bisitz 8827: color: RGB(80, 80, 80);
8828: text-decoration: none;
1.693 droeschl 8829: }
1.795 www 8830:
1.949 droeschl 8831: ol.LC_primary_menu a.LC_new_message {
8832: font-weight:bold;
8833: color: darkred;
8834: }
8835:
1.975 raeburn 8836: ol.LC_docs_parameters {
8837: margin-left: 0;
8838: padding: 0;
8839: list-style: none;
8840: }
8841:
8842: ol.LC_docs_parameters li {
8843: margin: 0;
8844: padding-right: 20px;
8845: display: inline;
8846: }
8847:
1.976 raeburn 8848: ol.LC_docs_parameters li:before {
8849: content: "\\002022 \\0020";
8850: }
8851:
8852: li.LC_docs_parameters_title {
8853: font-weight: bold;
8854: }
8855:
8856: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8857: content: "";
8858: }
8859:
1.897 wenzelju 8860: ul#LC_secondary_menu {
1.1107 raeburn 8861: clear: right;
1.911 bisitz 8862: color: $fontmenu;
8863: background: $tabbg;
8864: list-style: none;
8865: padding: 0;
8866: margin: 0;
8867: width: 100%;
1.995 raeburn 8868: text-align: left;
1.1107 raeburn 8869: float: left;
1.808 droeschl 8870: }
8871:
1.897 wenzelju 8872: ul#LC_secondary_menu li {
1.911 bisitz 8873: font-weight: bold;
8874: line-height: 1.8em;
1.1107 raeburn 8875: border-right: 1px solid black;
8876: float: left;
8877: }
8878:
8879: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8880: background-color: $data_table_light;
8881: }
8882:
8883: ul#LC_secondary_menu li a {
1.911 bisitz 8884: padding: 0 0.8em;
1.1107 raeburn 8885: }
8886:
8887: ul#LC_secondary_menu li ul {
8888: display: none;
8889: }
8890:
8891: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8892: display: block;
8893: position: absolute;
8894: margin: 0;
8895: padding: 0;
8896: list-style:none;
8897: float: none;
8898: background-color: $data_table_light;
8899: z-index: 2;
8900: margin-left: -1px;
8901: }
8902:
8903: ul#LC_secondary_menu li ul li {
8904: font-size: 90%;
8905: vertical-align: top;
8906: border-left: 1px solid black;
1.911 bisitz 8907: border-right: 1px solid black;
1.1119 raeburn 8908: background-color: $data_table_light;
1.1107 raeburn 8909: list-style:none;
8910: float: none;
8911: }
8912:
8913: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8914: background-color: $data_table_dark;
1.807 droeschl 8915: }
8916:
1.847 tempelho 8917: ul.LC_TabContent {
1.911 bisitz 8918: display:block;
8919: background: $sidebg;
8920: border-bottom: solid 1px $lg_border_color;
8921: list-style:none;
1.1020 raeburn 8922: margin: -1px -10px 0 -10px;
1.911 bisitz 8923: padding: 0;
1.693 droeschl 8924: }
8925:
1.795 www 8926: ul.LC_TabContent li,
8927: ul.LC_TabContentBigger li {
1.911 bisitz 8928: float:left;
1.741 harmsja 8929: }
1.795 www 8930:
1.897 wenzelju 8931: ul#LC_secondary_menu li a {
1.911 bisitz 8932: color: $fontmenu;
8933: text-decoration: none;
1.693 droeschl 8934: }
1.795 www 8935:
1.721 harmsja 8936: ul.LC_TabContent {
1.952 onken 8937: min-height:20px;
1.721 harmsja 8938: }
1.795 www 8939:
8940: ul.LC_TabContent li {
1.911 bisitz 8941: vertical-align:middle;
1.959 onken 8942: padding: 0 16px 0 10px;
1.911 bisitz 8943: background-color:$tabbg;
8944: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8945: border-left: solid 1px $font;
1.721 harmsja 8946: }
1.795 www 8947:
1.847 tempelho 8948: ul.LC_TabContent .right {
1.911 bisitz 8949: float:right;
1.847 tempelho 8950: }
8951:
1.911 bisitz 8952: ul.LC_TabContent li a,
8953: ul.LC_TabContent li {
8954: color:rgb(47,47,47);
8955: text-decoration:none;
8956: font-size:95%;
8957: font-weight:bold;
1.952 onken 8958: min-height:20px;
8959: }
8960:
1.959 onken 8961: ul.LC_TabContent li a:hover,
8962: ul.LC_TabContent li a:focus {
1.952 onken 8963: color: $button_hover;
1.959 onken 8964: background:none;
8965: outline:none;
1.952 onken 8966: }
8967:
8968: ul.LC_TabContent li:hover {
8969: color: $button_hover;
8970: cursor:pointer;
1.721 harmsja 8971: }
1.795 www 8972:
1.911 bisitz 8973: ul.LC_TabContent li.active {
1.952 onken 8974: color: $font;
1.911 bisitz 8975: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8976: border-bottom:solid 1px #FFFFFF;
8977: cursor: default;
1.744 ehlerst 8978: }
1.795 www 8979:
1.959 onken 8980: ul.LC_TabContent li.active a {
8981: color:$font;
8982: background:#FFFFFF;
8983: outline: none;
8984: }
1.1047 raeburn 8985:
8986: ul.LC_TabContent li.goback {
8987: float: left;
8988: border-left: none;
8989: }
8990:
1.870 tempelho 8991: #maincoursedoc {
1.911 bisitz 8992: clear:both;
1.870 tempelho 8993: }
8994:
8995: ul.LC_TabContentBigger {
1.911 bisitz 8996: display:block;
8997: list-style:none;
8998: padding: 0;
1.870 tempelho 8999: }
9000:
1.795 www 9001: ul.LC_TabContentBigger li {
1.911 bisitz 9002: vertical-align:bottom;
9003: height: 30px;
9004: font-size:110%;
9005: font-weight:bold;
9006: color: #737373;
1.841 tempelho 9007: }
9008:
1.957 onken 9009: ul.LC_TabContentBigger li.active {
9010: position: relative;
9011: top: 1px;
9012: }
9013:
1.870 tempelho 9014: ul.LC_TabContentBigger li a {
1.911 bisitz 9015: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
9016: height: 30px;
9017: line-height: 30px;
9018: text-align: center;
9019: display: block;
9020: text-decoration: none;
1.958 onken 9021: outline: none;
1.741 harmsja 9022: }
1.795 www 9023:
1.870 tempelho 9024: ul.LC_TabContentBigger li.active a {
1.911 bisitz 9025: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
9026: color:$font;
1.744 ehlerst 9027: }
1.795 www 9028:
1.870 tempelho 9029: ul.LC_TabContentBigger li b {
1.911 bisitz 9030: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
9031: display: block;
9032: float: left;
9033: padding: 0 30px;
1.957 onken 9034: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 9035: }
9036:
1.956 onken 9037: ul.LC_TabContentBigger li:hover b {
9038: color:$button_hover;
9039: }
9040:
1.870 tempelho 9041: ul.LC_TabContentBigger li.active b {
1.911 bisitz 9042: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
9043: color:$font;
1.957 onken 9044: border: 0;
1.741 harmsja 9045: }
1.693 droeschl 9046:
1.870 tempelho 9047:
1.862 bisitz 9048: ul.LC_CourseBreadcrumbs {
9049: background: $sidebg;
1.1020 raeburn 9050: height: 2em;
1.862 bisitz 9051: padding-left: 10px;
1.1020 raeburn 9052: margin: 0;
1.862 bisitz 9053: list-style-position: inside;
9054: }
9055:
1.911 bisitz 9056: ol#LC_MenuBreadcrumbs,
1.862 bisitz 9057: ol#LC_PathBreadcrumbs {
1.911 bisitz 9058: padding-left: 10px;
9059: margin: 0;
1.933 droeschl 9060: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 9061: }
9062:
1.911 bisitz 9063: ol#LC_MenuBreadcrumbs li,
9064: ol#LC_PathBreadcrumbs li,
1.862 bisitz 9065: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 9066: display: inline;
1.933 droeschl 9067: white-space: normal;
1.693 droeschl 9068: }
9069:
1.823 bisitz 9070: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 9071: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 9072: text-decoration: none;
9073: font-size:90%;
1.693 droeschl 9074: }
1.795 www 9075:
1.969 droeschl 9076: ol#LC_MenuBreadcrumbs h1 {
9077: display: inline;
9078: font-size: 90%;
9079: line-height: 2.5em;
9080: margin: 0;
9081: padding: 0;
9082: }
9083:
1.795 www 9084: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 9085: text-decoration:none;
9086: font-size:100%;
9087: font-weight:bold;
1.693 droeschl 9088: }
1.795 www 9089:
1.840 bisitz 9090: .LC_Box {
1.911 bisitz 9091: border: solid 1px $lg_border_color;
9092: padding: 0 10px 10px 10px;
1.746 neumanie 9093: }
1.795 www 9094:
1.1020 raeburn 9095: .LC_DocsBox {
9096: border: solid 1px $lg_border_color;
9097: padding: 0 0 10px 10px;
9098: }
9099:
1.795 www 9100: .LC_AboutMe_Image {
1.911 bisitz 9101: float:left;
9102: margin-right:10px;
1.747 neumanie 9103: }
1.795 www 9104:
9105: .LC_Clear_AboutMe_Image {
1.911 bisitz 9106: clear:left;
1.747 neumanie 9107: }
1.795 www 9108:
1.721 harmsja 9109: dl.LC_ListStyleClean dt {
1.911 bisitz 9110: padding-right: 5px;
9111: display: table-header-group;
1.693 droeschl 9112: }
9113:
1.721 harmsja 9114: dl.LC_ListStyleClean dd {
1.911 bisitz 9115: display: table-row;
1.693 droeschl 9116: }
9117:
1.721 harmsja 9118: .LC_ListStyleClean,
9119: .LC_ListStyleSimple,
9120: .LC_ListStyleNormal,
1.795 www 9121: .LC_ListStyleSpecial {
1.911 bisitz 9122: /* display:block; */
9123: list-style-position: inside;
9124: list-style-type: none;
9125: overflow: hidden;
9126: padding: 0;
1.693 droeschl 9127: }
9128:
1.721 harmsja 9129: .LC_ListStyleSimple li,
9130: .LC_ListStyleSimple dd,
9131: .LC_ListStyleNormal li,
9132: .LC_ListStyleNormal dd,
9133: .LC_ListStyleSpecial li,
1.795 www 9134: .LC_ListStyleSpecial dd {
1.911 bisitz 9135: margin: 0;
9136: padding: 5px 5px 5px 10px;
9137: clear: both;
1.693 droeschl 9138: }
9139:
1.721 harmsja 9140: .LC_ListStyleClean li,
9141: .LC_ListStyleClean dd {
1.911 bisitz 9142: padding-top: 0;
9143: padding-bottom: 0;
1.693 droeschl 9144: }
9145:
1.721 harmsja 9146: .LC_ListStyleSimple dd,
1.795 www 9147: .LC_ListStyleSimple li {
1.911 bisitz 9148: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 9149: }
9150:
1.721 harmsja 9151: .LC_ListStyleSpecial li,
9152: .LC_ListStyleSpecial dd {
1.911 bisitz 9153: list-style-type: none;
9154: background-color: RGB(220, 220, 220);
9155: margin-bottom: 4px;
1.693 droeschl 9156: }
9157:
1.721 harmsja 9158: table.LC_SimpleTable {
1.911 bisitz 9159: margin:5px;
9160: border:solid 1px $lg_border_color;
1.795 www 9161: }
1.693 droeschl 9162:
1.721 harmsja 9163: table.LC_SimpleTable tr {
1.911 bisitz 9164: padding: 0;
9165: border:solid 1px $lg_border_color;
1.693 droeschl 9166: }
1.795 www 9167:
9168: table.LC_SimpleTable thead {
1.911 bisitz 9169: background:rgb(220,220,220);
1.693 droeschl 9170: }
9171:
1.721 harmsja 9172: div.LC_columnSection {
1.911 bisitz 9173: display: block;
9174: clear: both;
9175: overflow: hidden;
9176: margin: 0;
1.693 droeschl 9177: }
9178:
1.721 harmsja 9179: div.LC_columnSection>* {
1.911 bisitz 9180: float: left;
9181: margin: 10px 20px 10px 0;
9182: overflow:hidden;
1.693 droeschl 9183: }
1.721 harmsja 9184:
1.795 www 9185: table em {
1.911 bisitz 9186: font-weight: bold;
9187: font-style: normal;
1.748 schulted 9188: }
1.795 www 9189:
1.779 bisitz 9190: table.LC_tableBrowseRes,
1.795 www 9191: table.LC_tableOfContent {
1.911 bisitz 9192: border:none;
9193: border-spacing: 1px;
9194: padding: 3px;
9195: background-color: #FFFFFF;
9196: font-size: 90%;
1.753 droeschl 9197: }
1.789 droeschl 9198:
1.911 bisitz 9199: table.LC_tableOfContent {
9200: border-collapse: collapse;
1.789 droeschl 9201: }
9202:
1.771 droeschl 9203: table.LC_tableBrowseRes a,
1.768 schulted 9204: table.LC_tableOfContent a {
1.911 bisitz 9205: background-color: transparent;
9206: text-decoration: none;
1.753 droeschl 9207: }
9208:
1.795 www 9209: table.LC_tableOfContent img {
1.911 bisitz 9210: border: none;
9211: height: 1.3em;
9212: vertical-align: text-bottom;
9213: margin-right: 0.3em;
1.753 droeschl 9214: }
1.757 schulted 9215:
1.795 www 9216: a#LC_content_toolbar_firsthomework {
1.911 bisitz 9217: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 9218: }
9219:
1.795 www 9220: a#LC_content_toolbar_everything {
1.911 bisitz 9221: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 9222: }
9223:
1.795 www 9224: a#LC_content_toolbar_uncompleted {
1.911 bisitz 9225: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 9226: }
9227:
1.795 www 9228: #LC_content_toolbar_clearbubbles {
1.911 bisitz 9229: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 9230: }
9231:
1.795 www 9232: a#LC_content_toolbar_changefolder {
1.911 bisitz 9233: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 9234: }
9235:
1.795 www 9236: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 9237: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 9238: }
9239:
1.1043 raeburn 9240: a#LC_content_toolbar_edittoplevel {
9241: background-image:url(/res/adm/pages/edittoplevel.gif);
9242: }
9243:
1.1384 raeburn 9244: a#LC_content_toolbar_printout {
9245: background-image:url(/res/adm/pages/printout.gif);
9246: }
9247:
1.795 www 9248: ul#LC_toolbar li a:hover {
1.911 bisitz 9249: background-position: bottom center;
1.757 schulted 9250: }
9251:
1.795 www 9252: ul#LC_toolbar {
1.911 bisitz 9253: padding: 0;
9254: margin: 2px;
9255: list-style:none;
1.1449 raeburn 9256: display:inline;
1.911 bisitz 9257: background-color:white;
1.1082 raeburn 9258: overflow: auto;
1.757 schulted 9259: }
9260:
1.795 www 9261: ul#LC_toolbar li {
1.911 bisitz 9262: border:1px solid white;
9263: padding: 0;
9264: margin: 0;
9265: float: left;
9266: display:inline;
9267: vertical-align:middle;
1.1082 raeburn 9268: white-space: nowrap;
1.911 bisitz 9269: }
1.757 schulted 9270:
1.783 amueller 9271:
1.795 www 9272: a.LC_toolbarItem {
1.911 bisitz 9273: display:block;
9274: padding: 0;
9275: margin: 0;
9276: height: 32px;
9277: width: 32px;
9278: color:white;
9279: border: none;
9280: background-repeat:no-repeat;
9281: background-color:transparent;
1.757 schulted 9282: }
9283:
1.1449 raeburn 9284: .LC_navtools {
9285: display: inline-block;
9286: padding: 0;
9287: margin: 2px;
9288: vertical-align: middle;
9289: }
9290:
1.915 droeschl 9291: ul.LC_funclist {
9292: margin: 0;
9293: padding: 0.5em 1em 0.5em 0;
9294: }
9295:
1.933 droeschl 9296: ul.LC_funclist > li:first-child {
9297: font-weight:bold;
9298: margin-left:0.8em;
9299: }
9300:
1.915 droeschl 9301: ul.LC_funclist + ul.LC_funclist {
9302: /*
9303: left border as a seperator if we have more than
9304: one list
9305: */
9306: border-left: 1px solid $sidebg;
9307: /*
9308: this hides the left border behind the border of the
9309: outer box if element is wrapped to the next 'line'
9310: */
9311: margin-left: -1px;
9312: }
9313:
1.843 bisitz 9314: ul.LC_funclist li {
1.915 droeschl 9315: display: inline;
1.782 bisitz 9316: white-space: nowrap;
1.915 droeschl 9317: margin: 0 0 0 25px;
9318: line-height: 150%;
1.782 bisitz 9319: }
9320:
1.974 wenzelju 9321: .LC_hidden {
9322: display: none;
9323: }
9324:
1.1030 www 9325: .LCmodal-overlay {
9326: position:fixed;
9327: top:0;
9328: right:0;
9329: bottom:0;
9330: left:0;
9331: height:100%;
9332: width:100%;
9333: margin:0;
9334: padding:0;
9335: background:#999;
9336: opacity:.75;
9337: filter: alpha(opacity=75);
9338: -moz-opacity: 0.75;
9339: z-index:101;
9340: }
9341:
9342: * html .LCmodal-overlay {
9343: position: absolute;
9344: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
9345: }
9346:
9347: .LCmodal-window {
9348: position:fixed;
9349: top:50%;
9350: left:50%;
9351: margin:0;
9352: padding:0;
9353: z-index:102;
9354: }
9355:
9356: * html .LCmodal-window {
9357: position:absolute;
9358: }
9359:
9360: .LCclose-window {
9361: position:absolute;
9362: width:32px;
9363: height:32px;
9364: right:8px;
9365: top:8px;
9366: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
9367: text-indent:-99999px;
9368: overflow:hidden;
9369: cursor:pointer;
9370: }
9371:
1.1369 raeburn 9372: .LCisDisabled {
9373: cursor: not-allowed;
9374: opacity: 0.5;
9375: }
9376:
9377: a[aria-disabled="true"] {
9378: color: currentColor;
9379: display: inline-block; /* For IE11/ MS Edge bug */
9380: pointer-events: none;
9381: text-decoration: none;
9382: }
9383:
1.1335 raeburn 9384: pre.LC_wordwrap {
9385: white-space: pre-wrap;
9386: white-space: -moz-pre-wrap;
9387: white-space: -pre-wrap;
9388: white-space: -o-pre-wrap;
9389: word-wrap: break-word;
9390: }
9391:
1.1100 raeburn 9392: /*
1.1231 damieng 9393: styles used for response display
9394: */
1.1464 raeburn 9395: div.LC_radiofoil, div.LC_rankfoil, div.LC_optionfoil, div.LC_matchfoil, div.LC_login_links {
1.1231 damieng 9396: margin: .5em 0em .5em 0em;
9397: }
9398: table.LC_itemgroup {
9399: margin-top: 1em;
9400: }
9401:
1.1462 raeburn 9402: table.LC_itemgroup tr th {
9403: font-weight: normal;
9404: }
9405:
9406: fieldset.LC_webbubbles {
9407: margin: 2px 0 0 0;
9408: padding: 0;
9409: border: 0;
9410: }
9411:
9412: ul.LC_webbubbles {
9413: list-style: none;
9414: padding: 0;
9415: margin: 0;
9416: text-align: left;
9417: float: left;
9418: }
9419:
9420: ul.LC_webbubbles li {
9421: line-height: 1.8em;
9422: border: 1px solid black;
9423: padding: 0 2px 0 5px;
9424: margin: 0 0 0 -1px;
9425: float: left;
9426: }
9427:
1.1231 damieng 9428: /*
1.1100 raeburn 9429: styles used by TTH when "Default set of options to pass to tth/m
9430: when converting TeX" in course settings has been set
9431:
9432: option passed: -t
9433:
9434: */
9435:
9436: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
9437: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
9438: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
9439: td div.norm {line-height:normal;}
9440:
9441: /*
9442: option passed -y3
9443: */
9444:
9445: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
9446: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
9447: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
9448:
1.1230 damieng 9449: /*
9450: sections with roles, for content only
9451: */
9452: section[class^="role-"] {
9453: padding-left: 10px;
9454: padding-right: 5px;
9455: margin-top: 8px;
9456: margin-bottom: 8px;
9457: border: 1px solid #2A4;
9458: border-radius: 5px;
9459: box-shadow: 0px 1px 1px #BBB;
9460: }
9461: section[class^="role-"]>h1 {
9462: position: relative;
9463: margin: 0px;
9464: padding-top: 10px;
9465: padding-left: 40px;
9466: }
9467: section[class^="role-"]>h1:before {
9468: position: absolute;
9469: left: -5px;
9470: top: 5px;
9471: }
9472: section.role-activity>h1:before {
9473: content:url('/adm/daxe/images/section_icons/activity.png');
9474: }
9475: section.role-advice>h1:before {
9476: content:url('/adm/daxe/images/section_icons/advice.png');
9477: }
9478: section.role-bibliography>h1:before {
9479: content:url('/adm/daxe/images/section_icons/bibliography.png');
9480: }
9481: section.role-citation>h1:before {
9482: content:url('/adm/daxe/images/section_icons/citation.png');
9483: }
9484: section.role-conclusion>h1:before {
9485: content:url('/adm/daxe/images/section_icons/conclusion.png');
9486: }
9487: section.role-definition>h1:before {
9488: content:url('/adm/daxe/images/section_icons/definition.png');
9489: }
9490: section.role-demonstration>h1:before {
9491: content:url('/adm/daxe/images/section_icons/demonstration.png');
9492: }
9493: section.role-example>h1:before {
9494: content:url('/adm/daxe/images/section_icons/example.png');
9495: }
9496: section.role-explanation>h1:before {
9497: content:url('/adm/daxe/images/section_icons/explanation.png');
9498: }
9499: section.role-introduction>h1:before {
9500: content:url('/adm/daxe/images/section_icons/introduction.png');
9501: }
9502: section.role-method>h1:before {
9503: content:url('/adm/daxe/images/section_icons/method.png');
9504: }
9505: section.role-more_information>h1:before {
9506: content:url('/adm/daxe/images/section_icons/more_information.png');
9507: }
9508: section.role-objectives>h1:before {
9509: content:url('/adm/daxe/images/section_icons/objectives.png');
9510: }
9511: section.role-prerequisites>h1:before {
9512: content:url('/adm/daxe/images/section_icons/prerequisites.png');
9513: }
9514: section.role-remark>h1:before {
9515: content:url('/adm/daxe/images/section_icons/remark.png');
9516: }
9517: section.role-reminder>h1:before {
9518: content:url('/adm/daxe/images/section_icons/reminder.png');
9519: }
9520: section.role-summary>h1:before {
9521: content:url('/adm/daxe/images/section_icons/summary.png');
9522: }
9523: section.role-syntax>h1:before {
9524: content:url('/adm/daxe/images/section_icons/syntax.png');
9525: }
9526: section.role-warning>h1:before {
9527: content:url('/adm/daxe/images/section_icons/warning.png');
9528: }
9529:
1.1269 raeburn 9530: #LC_minitab_header {
9531: float:left;
9532: width:100%;
9533: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
9534: font-size:93%;
9535: line-height:normal;
9536: margin: 0.5em 0 0.5em 0;
9537: }
9538: #LC_minitab_header ul {
9539: margin:0;
9540: padding:10px 10px 0;
9541: list-style:none;
9542: }
9543: #LC_minitab_header li {
9544: float:left;
9545: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
9546: margin:0;
9547: padding:0 0 0 9px;
9548: }
9549: #LC_minitab_header a {
9550: display:block;
9551: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
9552: padding:5px 15px 4px 6px;
9553: }
9554: #LC_minitab_header #LC_current_minitab {
9555: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
9556: }
9557: #LC_minitab_header #LC_current_minitab a {
9558: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
9559: padding-bottom:5px;
9560: }
9561:
9562:
1.343 albertel 9563: END
9564: }
9565:
1.306 albertel 9566: =pod
9567:
9568: =item * &headtag()
9569:
9570: Returns a uniform footer for LON-CAPA web pages.
9571:
1.307 albertel 9572: Inputs: $title - optional title for the head
9573: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9574: $args - optional arguments
1.319 albertel 9575: force_register - if is true call registerurl so the remote is
9576: informed
1.415 albertel 9577: redirect -> array ref of
9578: 1- seconds before redirect occurs
9579: 2- url to redirect to
9580: 3- whether the side effect should occur
1.315 albertel 9581: (side effect of setting
9582: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9583: redirected to)
9584: 4- whether the redirect target should be
9585: the opener of the current (pop-up)
9586: window (side effect of setting
9587: $env{'internal.head.to_opener'} to
9588: 1, if true.
1.1388 raeburn 9589: 5- whether encrypt check should be skipped
1.352 albertel 9590: domain -> force to color decorate a page for a specific
9591: domain
9592: function -> force usage of a specific rolish color scheme
9593: bgcolor -> override the default page bgcolor
1.460 albertel 9594: no_auto_mt_title
9595: -> prevent &mt()ing the title arg
1.464 albertel 9596:
1.306 albertel 9597: =cut
9598:
9599: sub headtag {
1.313 albertel 9600: my ($title,$head_extra,$args) = @_;
1.306 albertel 9601:
1.363 albertel 9602: my $function = $args->{'function'} || &get_users_function();
9603: my $domain = $args->{'domain'} || &determinedomain();
9604: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9605: my $httphost = $args->{'use_absolute'};
1.418 albertel 9606: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9607: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9608: #time(),
1.418 albertel 9609: $env{'environment.color.timestamp'},
1.363 albertel 9610: $function,$domain,$bgcolor);
9611:
1.369 www 9612: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9613:
1.308 albertel 9614: my $result =
9615: '<head>'.
1.1160 raeburn 9616: &font_settings($args);
1.319 albertel 9617:
1.1188 raeburn 9618: my $inhibitprint;
9619: if ($args->{'print_suppress'}) {
9620: $inhibitprint = &print_suppression();
9621: }
1.1064 raeburn 9622:
1.1439 raeburn 9623: if (!$args->{'frameset'} && !$args->{'switchserver'}) {
1.461 albertel 9624: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9625: }
1.962 droeschl 9626: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9627: $result .= Apache::lonxml::display_title();
1.319 albertel 9628: }
1.436 albertel 9629: if (!$args->{'no_nav_bar'}
9630: && !$args->{'only_body'}
1.1438 raeburn 9631: && !$args->{'frameset'}
9632: && !$args->{'switchserver'}) {
1.1154 raeburn 9633: $result .= &help_menu_js($httphost);
1.1032 www 9634: $result.=&modal_window();
1.1038 www 9635: $result.=&togglebox_script();
1.1034 www 9636: $result.=&wishlist_window();
1.1041 www 9637: $result.=&LCprogressbarUpdate_script();
1.1034 www 9638: } else {
9639: if ($args->{'add_modal'}) {
9640: $result.=&modal_window();
9641: }
9642: if ($args->{'add_wishlist'}) {
9643: $result.=&wishlist_window();
9644: }
1.1038 www 9645: if ($args->{'add_togglebox'}) {
9646: $result.=&togglebox_script();
9647: }
1.1041 www 9648: if ($args->{'add_progressbar'}) {
9649: $result.=&LCprogressbarUpdate_script();
9650: }
1.436 albertel 9651: }
1.314 albertel 9652: if (ref($args->{'redirect'})) {
1.1388 raeburn 9653: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9654: if (!$skip_enc_check) {
9655: $url = &Apache::lonenc::check_encrypt($url);
9656: }
1.414 albertel 9657: if (!$inhibit_continue) {
9658: $env{'internal.head.redirect'} = $url;
9659: }
1.1386 raeburn 9660: $result.=<<"ADDMETA";
1.313 albertel 9661: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9662: ADDMETA
9663: if ($to_opener) {
9664: $env{'internal.head.to_opener'} = 1;
9665: my $dest = &js_escape($url);
9666: my $timeout = int($time * 1000);
9667: $result .=<<"ENDJS";
9668: <script type="text/javascript">
9669: // <![CDATA[
9670: function LC_To_Opener() {
9671: var dest = '$dest';
9672: if (dest != '') {
9673: if (window.opener != null && !window.opener.closed) {
9674: window.opener.location.href=dest;
9675: window.close();
9676: } else {
9677: window.location.href=dest;
9678: }
9679: }
9680: }
9681: \$(document).ready(function () {
9682: setTimeout('LC_To_Opener()',$timeout);
9683: });
9684: // ]]>
9685: </script>
9686: ENDJS
9687: } else {
9688: $result.=<<"ADDMETA";
1.344 albertel 9689: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9690: ADDMETA
1.1386 raeburn 9691: }
1.1210 raeburn 9692: } else {
9693: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9694: my $requrl = $env{'request.uri'};
9695: if ($requrl eq '') {
9696: $requrl = $ENV{'REQUEST_URI'};
9697: $requrl =~ s/\?.+$//;
9698: }
9699: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9700: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9701: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9702: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9703: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9704: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9705: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9706: my ($offload,$offloadoth);
1.1210 raeburn 9707: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9708: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9709: $offload = 1;
1.1353 raeburn 9710: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9711: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9712: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9713: $offloadoth = 1;
9714: $dom_in_use = $env{'user.domain'};
9715: }
9716: }
1.1340 raeburn 9717: }
9718: }
9719: unless ($offload) {
9720: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9721: if ($domdefs{'offloadoth'}{$lonhost}) {
9722: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9723: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9724: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9725: $offload = 1;
1.1352 raeburn 9726: $offloadoth = 1;
1.1340 raeburn 9727: $dom_in_use = $env{'user.domain'};
9728: }
1.1210 raeburn 9729: }
1.1340 raeburn 9730: }
9731: }
9732: }
9733: if ($offload) {
1.1358 raeburn 9734: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9735: if (($newserver eq '') && ($offloadoth)) {
9736: my @domains = &Apache::lonnet::current_machine_domains();
9737: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9738: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9739: }
9740: }
1.1340 raeburn 9741: if (($newserver) && ($newserver ne $lonhost)) {
9742: my $numsec = 5;
9743: my $timeout = $numsec * 1000;
9744: my ($newurl,$locknum,%locks,$msg);
9745: if ($env{'request.role.adv'}) {
9746: ($locknum,%locks) = &Apache::lonnet::get_locks();
9747: }
9748: my $disable_submit = 0;
9749: if ($requrl =~ /$LONCAPA::assess_re/) {
9750: $disable_submit = 1;
9751: }
9752: if ($locknum) {
9753: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9754: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9755: join(", ",sort(values(%locks)))."\n";
9756: if (&show_course()) {
9757: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9758: } else {
9759: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9760: }
1.1340 raeburn 9761: } else {
9762: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9763: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9764: }
9765: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9766: $newurl = '/adm/switchserver?otherserver='.$newserver;
9767: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9768: $newurl .= '&role='.$env{'request.role'};
9769: }
9770: if ($env{'request.symb'}) {
9771: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9772: if ($shownsymb =~ m{^/enc/}) {
9773: my $reqdmajor = 2;
9774: my $reqdminor = 11;
9775: my $reqdsubminor = 3;
9776: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9777: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9778: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9779: if (($major eq '' && $minor eq '') ||
9780: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9781: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9782: ($reqdsubminor > $subminor))))) {
9783: undef($shownsymb);
9784: }
1.1210 raeburn 9785: }
1.1340 raeburn 9786: if ($shownsymb) {
9787: &js_escape(\$shownsymb);
9788: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9789: }
1.1340 raeburn 9790: } else {
9791: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9792: &js_escape(\$shownurl);
9793: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9794: }
1.1340 raeburn 9795: }
9796: &js_escape(\$msg);
9797: $result.=<<OFFLOAD
1.1210 raeburn 9798: <meta http-equiv="pragma" content="no-cache" />
9799: <script type="text/javascript">
1.1215 raeburn 9800: // <![CDATA[
1.1210 raeburn 9801: function LC_Offload_Now() {
9802: var dest = "$newurl";
9803: if (dest != '') {
9804: window.location.href="$newurl";
9805: }
9806: }
1.1214 raeburn 9807: \$(document).ready(function () {
9808: window.alert('$msg');
9809: if ($disable_submit) {
1.1210 raeburn 9810: \$(".LC_hwk_submit").prop("disabled", true);
9811: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9812: }
9813: setTimeout('LC_Offload_Now()', $timeout);
9814: });
1.1215 raeburn 9815: // ]]>
1.1210 raeburn 9816: </script>
9817: OFFLOAD
9818: }
9819: }
9820: }
9821: }
9822: }
1.313 albertel 9823: }
1.306 albertel 9824: if (!defined($title)) {
9825: $title = 'The LearningOnline Network with CAPA';
9826: }
1.460 albertel 9827: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1432 raeburn 9828: if ($title =~ /^LON-CAPA\s+/) {
9829: $result .= '<title> '.$title.'</title>';
9830: } else {
9831: $result .= '<title> LON-CAPA '.$title.'</title>';
9832: }
9833: $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1168 raeburn 9834: if (!$args->{'frameset'}) {
9835: $result .= ' /';
9836: }
9837: $result .= '>'
1.1064 raeburn 9838: .$inhibitprint
1.414 albertel 9839: .$head_extra;
1.1242 raeburn 9840: my $clientmobile;
9841: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9842: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9843: } else {
9844: $clientmobile = $env{'browser.mobile'};
9845: }
9846: if ($clientmobile) {
1.1137 raeburn 9847: $result .= '
1.1435 raeburn 9848: <meta name="viewport" content="width=device-width, initial-scale=1.0">
1.1137 raeburn 9849: <meta name="apple-mobile-web-app-capable" content="yes" />';
9850: }
1.1455 raeburn 9851: $result .= '<meta name="google" content="notranslate"';
9852: if (!$args->{'frameset'}) {
9853: $result .= ' /';
9854: }
9855: $result .= '>'."\n";
1.962 droeschl 9856: return $result.'</head>';
1.306 albertel 9857: }
9858:
9859: =pod
9860:
1.340 albertel 9861: =item * &font_settings()
9862:
9863: Returns neccessary <meta> to set the proper encoding
9864:
1.1160 raeburn 9865: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9866:
9867: =cut
9868:
9869: sub font_settings {
1.1160 raeburn 9870: my ($args) = @_;
1.340 albertel 9871: my $headerstring='';
1.1160 raeburn 9872: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9873: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9874: $headerstring.=
9875: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9876: if (!$args->{'frameset'}) {
9877: $headerstring.= ' /';
9878: }
9879: $headerstring .= '>'."\n";
1.340 albertel 9880: }
9881: return $headerstring;
9882: }
9883:
1.341 albertel 9884: =pod
9885:
1.1064 raeburn 9886: =item * &print_suppression()
9887:
9888: In course context returns css which causes the body to be blank when media="print",
9889: if printout generation is unavailable for the current resource.
9890:
9891: This could be because:
9892:
9893: (a) printstartdate is in the future
9894:
9895: (b) printenddate is in the past
9896:
9897: (c) there is an active exam block with "printout"
9898: functionality blocked
9899:
9900: Users with pav, pfo or evb privileges are exempt.
9901:
9902: Inputs: none
9903:
9904: =cut
9905:
9906:
9907: sub print_suppression {
9908: my $noprint;
9909: if ($env{'request.course.id'}) {
9910: my $scope = $env{'request.course.id'};
9911: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9912: (&Apache::lonnet::allowed('pfo',$scope))) {
9913: return;
9914: }
9915: if ($env{'request.course.sec'} ne '') {
9916: $scope .= "/$env{'request.course.sec'}";
9917: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9918: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9919: return;
1.1064 raeburn 9920: }
9921: }
9922: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9923: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9924: my $clientip = &Apache::lonnet::get_requestor_ip();
9925: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9926: if ($blocked) {
9927: my $checkrole = "cm./$cdom/$cnum";
9928: if ($env{'request.course.sec'} ne '') {
9929: $checkrole .= "/$env{'request.course.sec'}";
9930: }
9931: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9932: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9933: $noprint = 1;
9934: }
9935: }
9936: unless ($noprint) {
9937: my $symb = &Apache::lonnet::symbread();
9938: if ($symb ne '') {
9939: my $navmap = Apache::lonnavmaps::navmap->new();
9940: if (ref($navmap)) {
9941: my $res = $navmap->getBySymb($symb);
9942: if (ref($res)) {
9943: if (!$res->resprintable()) {
9944: $noprint = 1;
9945: }
9946: }
9947: }
9948: }
9949: }
9950: if ($noprint) {
9951: return <<"ENDSTYLE";
9952: <style type="text/css" media="print">
9953: body { display:none }
9954: </style>
9955: ENDSTYLE
9956: }
9957: }
9958: return;
9959: }
9960:
9961: =pod
9962:
1.341 albertel 9963: =item * &xml_begin()
9964:
9965: Returns the needed doctype and <html>
9966:
9967: Inputs: none
9968:
9969: =cut
9970:
9971: sub xml_begin {
1.1168 raeburn 9972: my ($is_frameset) = @_;
1.341 albertel 9973: my $output='';
9974:
9975: if ($env{'browser.mathml'}) {
9976: $output='<?xml version="1.0"?>'
9977: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9978: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9979:
9980: # .'<!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">] >'
9981: .'<!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">'
9982: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9983: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9984: } elsif ($is_frameset) {
9985: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
1.1459 raeburn 9986: '<html lang="en">'."\n";
1.341 albertel 9987: } else {
1.1168 raeburn 9988: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9989: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9990: }
9991: return $output;
9992: }
1.340 albertel 9993:
9994: =pod
9995:
1.306 albertel 9996: =item * &start_page()
9997:
9998: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9999:
1.648 raeburn 10000: Inputs:
10001:
10002: =over 4
10003:
10004: $title - optional title for the page
10005:
10006: $head_extra - optional extra HTML to incude inside the <head>
10007:
10008: $args - additional optional args supported are:
10009:
10010: =over 8
10011:
10012: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 10013: arg on
1.814 bisitz 10014: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 10015: add_entries -> additional attributes to add to the <body>
10016: domain -> force to color decorate a page for a
1.317 albertel 10017: specific domain
1.648 raeburn 10018: function -> force usage of a specific rolish color
1.317 albertel 10019: scheme
1.648 raeburn 10020: redirect -> see &headtag()
10021: bgcolor -> override the default page bg color
10022: js_ready -> return a string ready for being used in
1.317 albertel 10023: a javascript writeln
1.648 raeburn 10024: html_encode -> return a string ready for being used in
1.320 albertel 10025: a html attribute
1.648 raeburn 10026: force_register -> if is true will turn on the &bodytag()
1.317 albertel 10027: $forcereg arg
1.648 raeburn 10028: frameset -> if true will start with a <frameset>
1.330 albertel 10029: rather than <body>
1.648 raeburn 10030: skip_phases -> hash ref of
1.338 albertel 10031: head -> skip the <html><head> generation
10032: body -> skip all <body> generation
1.648 raeburn 10033: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 10034: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 10035: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1437 raeburn 10036: bread_crumbs_style -> breadcrumbs are contained within <div id="LC_breadcrumbs">,
10037: and &standard_css() contains CSS for #LC_breadcrumbs, if you want
10038: to override those values, or add to them, specify the value to
10039: include in the style attribute to include in the div tag by using
10040: bread_crumbs_style (e.g., overflow: visible)
1.1272 raeburn 10041: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
10042: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 10043: group -> includes the current group, if page is for a
1.1274 raeburn 10044: specific group
10045: use_absolute -> for request for external resource or syllabus, this
10046: will contain https://<hostname> if server uses
10047: https (as per hosts.tab), but request is for http
10048: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 10049: links_disabled -> Links in primary and secondary menus are disabled
10050: (Can enable them once page has loaded - see lonroles.pm
10051: for an example).
1.1380 raeburn 10052: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 10053:
1.648 raeburn 10054: =back
1.460 albertel 10055:
1.648 raeburn 10056: =back
1.562 albertel 10057:
1.306 albertel 10058: =cut
10059:
10060: sub start_page {
1.309 albertel 10061: my ($title,$head_extra,$args) = @_;
1.318 albertel 10062: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 10063:
1.315 albertel 10064: $env{'internal.start_page'}++;
1.1359 raeburn 10065: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 10066:
1.338 albertel 10067: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 10068: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 10069: }
1.1316 raeburn 10070:
10071: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 10072: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
10073: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
10074: $args->{'no_primary_menu'} = 1;
10075: }
10076: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
10077: $args->{'no_inline_menu'} = 1;
10078: }
10079: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
10080: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
10081: }
10082: } else {
10083: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10084: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
10085: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
10086: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
10087: $args->{'no_primary_menu'} = 1;
10088: }
10089: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
10090: $args->{'no_inline_menu'} = 1;
10091: }
10092: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
10093: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
10094: }
10095: }
10096: }
1.1316 raeburn 10097: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
10098: $env{'course.'.$env{'request.course.id'}.'.domain'},
10099: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 10100: } elsif ($env{'request.course.id'}) {
10101: my $expiretime=600;
10102: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
10103: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
10104: }
10105: my ($deeplinkmenu,$menuref);
10106: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
10107: if ($menucoll) {
10108: if (ref($menuref) eq 'HASH') {
10109: %menu = %{$menuref};
10110: }
10111: if ($menu{'top'} eq 'n') {
10112: $args->{'no_primary_menu'} = 1;
10113: }
10114: if ($menu{'inline'} eq 'n') {
10115: unless (&Apache::lonnet::allowed('opa')) {
10116: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10117: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10118: my $crstype = &course_type();
10119: my $now = time;
10120: my $ccrole;
10121: if ($crstype eq 'Community') {
10122: $ccrole = 'co';
10123: } else {
10124: $ccrole = 'cc';
10125: }
10126: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
10127: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
10128: if ((($start) && ($start<0)) ||
10129: (($end) && ($end<$now)) ||
10130: (($start) && ($now<$start))) {
10131: $args->{'no_inline_menu'} = 1;
10132: }
10133: } else {
10134: $args->{'no_inline_menu'} = 1;
10135: }
10136: }
10137: }
10138: }
1.1316 raeburn 10139: }
1.1359 raeburn 10140:
1.1385 raeburn 10141: my $showncrumbs;
1.338 albertel 10142: if (! exists($args->{'skip_phases'}{'body'}) ) {
10143: if ($args->{'frameset'}) {
10144: my $attr_string = &make_attr_string($args->{'force_register'},
10145: $args->{'add_entries'});
10146: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 10147: } else {
10148: $result .=
10149: &bodytag($title,
10150: $args->{'function'}, $args->{'add_entries'},
10151: $args->{'only_body'}, $args->{'domain'},
10152: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 10153: $args->{'bgcolor'}, $args,
1.1385 raeburn 10154: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
10155: \%menu,\$showncrumbs);
1.831 bisitz 10156: }
1.330 albertel 10157: }
1.338 albertel 10158:
1.315 albertel 10159: if ($args->{'js_ready'}) {
1.713 kaisler 10160: $result = &js_ready($result);
1.315 albertel 10161: }
1.320 albertel 10162: if ($args->{'html_encode'}) {
1.713 kaisler 10163: $result = &html_encode($result);
10164: }
10165:
1.813 bisitz 10166: # Preparation for new and consistent functionlist at top of screen
10167: # if ($args->{'functionlist'}) {
10168: # $result .= &build_functionlist();
10169: #}
10170:
1.964 droeschl 10171: # Don't add anything more if only_body wanted or in const space
10172: return $result if $args->{'only_body'}
10173: || $env{'request.state'} eq 'construct';
1.813 bisitz 10174:
10175: #Breadcrumbs
1.758 kaisler 10176: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 10177: unless ($showncrumbs) {
1.758 kaisler 10178: &Apache::lonhtmlcommon::clear_breadcrumbs();
10179: #if any br links exists, add them to the breadcrumbs
10180: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
10181: foreach my $crumb (@{$args->{'bread_crumbs'}}){
10182: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
10183: }
10184: }
1.1096 raeburn 10185: # if @advtools array contains items add then to the breadcrumbs
10186: if (@advtools > 0) {
10187: &Apache::lonmenu::advtools_crumbs(@advtools);
10188: }
1.1272 raeburn 10189: my $menulink;
10190: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
10191: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 10192: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 10193: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
10194: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
10195: (!$env{'request.role.adv'}))) {
10196: $menulink = 0;
10197: } else {
10198: undef($menulink);
10199: }
1.1385 raeburn 10200: my $linkprotout;
10201: if ($env{'request.deeplink.login'}) {
10202: my $linkprotout = &Apache::lonmenu::linkprot_exit();
10203: if ($linkprotout) {
10204: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
10205: }
10206: }
1.758 kaisler 10207: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
10208: if(exists($args->{'bread_crumbs_component'})){
1.1437 raeburn 10209: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},
10210: '',$menulink,'',
10211: $args->{'bread_crumbs_style'});
1.1237 raeburn 10212: } else {
1.1437 raeburn 10213: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink,'',
10214: $args->{'bread_crumbs_style'});
1.758 kaisler 10215: }
1.1385 raeburn 10216: }
1.320 albertel 10217: }
1.315 albertel 10218: return $result;
1.306 albertel 10219: }
10220:
10221: sub end_page {
1.315 albertel 10222: my ($args) = @_;
10223: $env{'internal.end_page'}++;
1.330 albertel 10224: my $result;
1.335 albertel 10225: if ($args->{'discussion'}) {
10226: my ($target,$parser);
10227: if (ref($args->{'discussion'})) {
10228: ($target,$parser) =($args->{'discussion'}{'target'},
10229: $args->{'discussion'}{'parser'});
10230: }
10231: $result .= &Apache::lonxml::xmlend($target,$parser);
10232: }
1.330 albertel 10233: if ($args->{'frameset'}) {
10234: $result .= '</frameset>';
10235: } else {
1.635 raeburn 10236: $result .= &endbodytag($args);
1.330 albertel 10237: }
1.1080 raeburn 10238: unless ($args->{'notbody'}) {
10239: $result .= "\n</html>";
10240: }
1.330 albertel 10241:
1.315 albertel 10242: if ($args->{'js_ready'}) {
1.317 albertel 10243: $result = &js_ready($result);
1.315 albertel 10244: }
1.335 albertel 10245:
1.320 albertel 10246: if ($args->{'html_encode'}) {
10247: $result = &html_encode($result);
10248: }
1.335 albertel 10249:
1.315 albertel 10250: return $result;
10251: }
10252:
1.1359 raeburn 10253: sub menucoll_in_effect {
10254: my ($menucoll,$deeplinkmenu,%menu);
10255: if ($env{'request.course.id'}) {
10256: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 10257: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 10258: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 10259: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10260: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10261: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
10262: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
10263: my $navmap = Apache::lonnavmaps::navmap->new();
10264: if (ref($navmap)) {
10265: $deeplink = $navmap->get_mapparam(undef,
10266: &Apache::lonnet::declutter($env{'request.noversionuri'}),
10267: '0.deeplink');
1.1370 raeburn 10268: } else {
10269: $check_login_symb = 1;
1.1362 raeburn 10270: }
10271: } else {
1.1370 raeburn 10272: my $symb = &Apache::lonnet::symbread();
10273: if ($symb) {
10274: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
10275: } else {
10276: $check_login_symb = 1;
10277: }
1.1362 raeburn 10278: }
10279: } else {
1.1370 raeburn 10280: $check_login_symb = 1;
10281: }
10282: if ($check_login_symb) {
1.1362 raeburn 10283: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
10284: if ($deeplink_symb =~ /\.(page|sequence)$/) {
10285: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
10286: my $navmap = Apache::lonnavmaps::navmap->new();
10287: if (ref($navmap)) {
10288: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
10289: }
10290: } else {
10291: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
10292: }
10293: }
1.1359 raeburn 10294: if ($deeplink ne '') {
1.1378 raeburn 10295: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 10296: if ($display =~ /^\d+$/) {
10297: $deeplinkmenu = 1;
10298: $menucoll = $display;
10299: }
10300: }
10301: }
10302: if ($menucoll) {
10303: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
10304: }
10305: }
10306: return ($menucoll,$deeplinkmenu,\%menu);
10307: }
10308:
1.1362 raeburn 10309: sub deeplink_login_symb {
10310: my ($cnum,$cdom) = @_;
10311: my $login_symb;
10312: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 10313: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
10314: }
10315: return $login_symb;
10316: }
10317:
10318: sub symb_from_tinyurl {
10319: my ($url,$cnum,$cdom) = @_;
10320: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
10321: my $key = $1;
10322: my ($tinyurl,$login);
10323: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
10324: if (defined($cached)) {
10325: $tinyurl = $result;
10326: } else {
10327: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
10328: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
10329: if ($currtiny{$key} ne '') {
10330: $tinyurl = $currtiny{$key};
10331: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 10332: }
1.1364 raeburn 10333: }
10334: if ($tinyurl ne '') {
10335: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
10336: if (wantarray) {
10337: return ($cnumreq,$symb);
10338: } elsif ($cnumreq eq $cnum) {
10339: return $symb;
1.1362 raeburn 10340: }
10341: }
10342: }
1.1364 raeburn 10343: if (wantarray) {
10344: return ();
10345: } else {
10346: return;
10347: }
1.1362 raeburn 10348: }
10349:
1.1405 raeburn 10350: sub usable_exttools {
10351: my %tooltypes;
10352: if ($env{'request.course.id'}) {
10353: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
10354: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
10355: %tooltypes = (
10356: crs => 1,
10357: dom => 1,
10358: );
10359: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
10360: $tooltypes{'crs'} = 1;
10361: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
10362: $tooltypes{'dom'} = 1;
10363: }
10364: } else {
10365: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10366: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10367: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
10368: if ($crstype eq '') {
10369: $crstype = 'course';
10370: }
10371: if ($crstype eq 'course') {
10372: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
10373: $crstype = 'official';
10374: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
10375: $crstype = 'textbook';
10376: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
10377: $crstype = 'lti';
10378: } else {
10379: $crstype = 'unofficial';
10380: }
10381: }
10382: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
10383: if ($domdefaults{$crstype.'domexttool'}) {
10384: $tooltypes{'dom'} = 1;
10385: }
10386: if ($domdefaults{$crstype.'exttool'}) {
10387: $tooltypes{'crs'} = 1;
10388: }
10389: }
10390: }
10391: return %tooltypes;
10392: }
10393:
1.1034 www 10394: sub wishlist_window {
10395: return(<<'ENDWISHLIST');
1.1046 raeburn 10396: <script type="text/javascript">
1.1034 www 10397: // <![CDATA[
10398: // <!-- BEGIN LON-CAPA Internal
10399: function set_wishlistlink(title, path) {
10400: if (!title) {
10401: title = document.title;
10402: title = title.replace(/^LON-CAPA /,'');
10403: }
1.1175 raeburn 10404: title = encodeURIComponent(title);
1.1203 raeburn 10405: title = title.replace("'","\\\'");
1.1034 www 10406: if (!path) {
10407: path = location.pathname;
10408: }
1.1175 raeburn 10409: path = encodeURIComponent(path);
1.1203 raeburn 10410: path = path.replace("'","\\\'");
1.1034 www 10411: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
10412: 'wishlistNewLink','width=560,height=350,scrollbars=0');
10413: }
10414: // END LON-CAPA Internal -->
10415: // ]]>
10416: </script>
10417: ENDWISHLIST
10418: }
10419:
1.1030 www 10420: sub modal_window {
10421: return(<<'ENDMODAL');
1.1046 raeburn 10422: <script type="text/javascript">
1.1030 www 10423: // <![CDATA[
10424: // <!-- BEGIN LON-CAPA Internal
10425: var modalWindow = {
10426: parent:"body",
10427: windowId:null,
10428: content:null,
10429: width:null,
10430: height:null,
10431: close:function()
10432: {
10433: $(".LCmodal-window").remove();
10434: $(".LCmodal-overlay").remove();
10435: },
10436: open:function()
10437: {
10438: var modal = "";
10439: modal += "<div class=\"LCmodal-overlay\"></div>";
10440: 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;\">";
10441: modal += this.content;
10442: modal += "</div>";
10443:
10444: $(this.parent).append(modal);
10445:
10446: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
10447: $(".LCclose-window").click(function(){modalWindow.close();});
10448: $(".LCmodal-overlay").click(function(){modalWindow.close();});
10449: }
10450: };
1.1140 raeburn 10451: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 10452: {
1.1266 raeburn 10453: source = source.replace(/'/g,"'");
1.1030 www 10454: modalWindow.windowId = "myModal";
10455: modalWindow.width = width;
10456: modalWindow.height = height;
1.1196 raeburn 10457: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 10458: modalWindow.open();
1.1208 raeburn 10459: };
1.1030 www 10460: // END LON-CAPA Internal -->
10461: // ]]>
10462: </script>
10463: ENDMODAL
10464: }
10465:
10466: sub modal_link {
1.1140 raeburn 10467: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 10468: unless ($width) { $width=480; }
10469: unless ($height) { $height=400; }
1.1031 www 10470: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 10471: unless ($transparency) { $transparency='true'; }
10472:
1.1074 raeburn 10473: my $target_attr;
10474: if (defined($target)) {
10475: $target_attr = 'target="'.$target.'"';
10476: }
10477: return <<"ENDLINK";
1.1336 raeburn 10478: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 10479: ENDLINK
1.1030 www 10480: }
10481:
1.1032 www 10482: sub modal_adhoc_script {
1.1365 raeburn 10483: my ($funcname,$width,$height,$content,$possmathjax)=@_;
10484: my $mathjax;
10485: if ($possmathjax) {
10486: $mathjax = <<'ENDJAX';
10487: if (typeof MathJax == 'object') {
10488: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
10489: }
10490: ENDJAX
10491: }
1.1032 www 10492: return (<<ENDADHOC);
1.1046 raeburn 10493: <script type="text/javascript">
1.1032 www 10494: // <![CDATA[
10495: var $funcname = function()
10496: {
10497: modalWindow.windowId = "myModal";
10498: modalWindow.width = $width;
10499: modalWindow.height = $height;
10500: modalWindow.content = '$content';
10501: modalWindow.open();
1.1365 raeburn 10502: $mathjax
1.1032 www 10503: };
10504: // ]]>
10505: </script>
10506: ENDADHOC
10507: }
10508:
1.1041 www 10509: sub modal_adhoc_inner {
1.1365 raeburn 10510: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 10511: my $innerwidth=$width-20;
10512: $content=&js_ready(
1.1140 raeburn 10513: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
10514: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
10515: $content.
1.1041 www 10516: &end_scrollbox().
1.1140 raeburn 10517: &end_page()
1.1041 www 10518: );
1.1365 raeburn 10519: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 10520: }
10521:
10522: sub modal_adhoc_window {
1.1365 raeburn 10523: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
10524: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 10525: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
10526: }
10527:
10528: sub modal_adhoc_launch {
10529: my ($funcname,$width,$height,$content)=@_;
10530: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
10531: <script type="text/javascript">
10532: // <![CDATA[
10533: $funcname();
10534: // ]]>
10535: </script>
10536: ENDLAUNCH
10537: }
10538:
10539: sub modal_adhoc_close {
10540: return (<<ENDCLOSE);
10541: <script type="text/javascript">
10542: // <![CDATA[
10543: modalWindow.close();
10544: // ]]>
10545: </script>
10546: ENDCLOSE
10547: }
10548:
1.1038 www 10549: sub togglebox_script {
10550: return(<<ENDTOGGLE);
10551: <script type="text/javascript">
10552: // <![CDATA[
10553: function LCtoggleDisplay(id,hidetext,showtext) {
10554: link = document.getElementById(id + "link").childNodes[0];
10555: with (document.getElementById(id).style) {
10556: if (display == "none" ) {
10557: display = "inline";
10558: link.nodeValue = hidetext;
10559: } else {
10560: display = "none";
10561: link.nodeValue = showtext;
10562: }
10563: }
10564: }
10565: // ]]>
10566: </script>
10567: ENDTOGGLE
10568: }
10569:
1.1039 www 10570: sub start_togglebox {
10571: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
10572: unless ($heading) { $heading=''; } else { $heading.=' '; }
10573: unless ($showtext) { $showtext=&mt('show'); }
10574: unless ($hidetext) { $hidetext=&mt('hide'); }
10575: unless ($headerbg) { $headerbg='#FFFFFF'; }
10576: return &start_data_table().
10577: &start_data_table_header_row().
10578: '<td bgcolor="'.$headerbg.'">'.$heading.
10579: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
10580: $showtext.'\')">'.$showtext.'</a>]</td>'.
10581: &end_data_table_header_row().
10582: '<tr id="'.$id.'" style="display:none""><td>';
10583: }
10584:
10585: sub end_togglebox {
10586: return '</td></tr>'.&end_data_table();
10587: }
10588:
1.1041 www 10589: sub LCprogressbar_script {
1.1302 raeburn 10590: my ($id,$number_to_do)=@_;
10591: if ($number_to_do) {
10592: return(<<ENDPROGRESS);
1.1041 www 10593: <script type="text/javascript">
10594: // <![CDATA[
1.1045 www 10595: \$('#progressbar$id').progressbar({
1.1041 www 10596: value: 0,
10597: change: function(event, ui) {
10598: var newVal = \$(this).progressbar('option', 'value');
10599: \$('.pblabel', this).text(LCprogressTxt);
10600: }
10601: });
10602: // ]]>
10603: </script>
10604: ENDPROGRESS
1.1302 raeburn 10605: } else {
10606: return(<<ENDPROGRESS);
10607: <script type="text/javascript">
10608: // <![CDATA[
10609: \$('#progressbar$id').progressbar({
10610: value: false,
10611: create: function(event, ui) {
10612: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10613: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10614: }
10615: });
10616: // ]]>
10617: </script>
10618: ENDPROGRESS
10619: }
1.1041 www 10620: }
10621:
10622: sub LCprogressbarUpdate_script {
10623: return(<<ENDPROGRESSUPDATE);
10624: <style type="text/css">
10625: .ui-progressbar { position:relative; }
1.1302 raeburn 10626: .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 10627: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10628: </style>
10629: <script type="text/javascript">
10630: // <![CDATA[
1.1045 www 10631: var LCprogressTxt='---';
10632:
1.1302 raeburn 10633: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10634: LCprogressTxt=progresstext;
1.1302 raeburn 10635: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10636: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10637: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10638: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10639: } else {
10640: \$('#progressbar'+id).progressbar('value',percent);
10641: }
1.1041 www 10642: }
10643: // ]]>
10644: </script>
10645: ENDPROGRESSUPDATE
10646: }
10647:
1.1042 www 10648: my $LClastpercent;
1.1045 www 10649: my $LCidcnt;
10650: my $LCcurrentid;
1.1042 www 10651:
1.1041 www 10652: sub LCprogressbar {
1.1302 raeburn 10653: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10654: $LClastpercent=0;
1.1045 www 10655: $LCidcnt++;
10656: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10657: my ($starting,$content);
10658: if ($number_to_do) {
10659: $starting=&mt('Starting');
10660: $content=(<<ENDPROGBAR);
10661: $preamble
1.1045 www 10662: <div id="progressbar$LCcurrentid">
1.1041 www 10663: <span class="pblabel">$starting</span>
10664: </div>
10665: ENDPROGBAR
1.1302 raeburn 10666: } else {
10667: $starting=&mt('Loading...');
10668: $LClastpercent='false';
10669: $content=(<<ENDPROGBAR);
10670: $preamble
10671: <div id="progressbar$LCcurrentid">
10672: <div class="progress-label">$starting</div>
10673: </div>
10674: ENDPROGBAR
10675: }
10676: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10677: }
10678:
10679: sub LCprogressbarUpdate {
1.1302 raeburn 10680: my ($r,$val,$text,$number_to_do)=@_;
10681: if ($number_to_do) {
10682: unless ($val) {
10683: if ($LClastpercent) {
10684: $val=$LClastpercent;
10685: } else {
10686: $val=0;
10687: }
10688: }
10689: if ($val<0) { $val=0; }
10690: if ($val>100) { $val=0; }
10691: $LClastpercent=$val;
10692: unless ($text) { $text=$val.'%'; }
10693: } else {
10694: $val = 'false';
1.1042 www 10695: }
1.1041 www 10696: $text=&js_ready($text);
1.1044 www 10697: &r_print($r,<<ENDUPDATE);
1.1041 www 10698: <script type="text/javascript">
10699: // <![CDATA[
1.1302 raeburn 10700: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10701: // ]]>
10702: </script>
10703: ENDUPDATE
1.1035 www 10704: }
10705:
1.1042 www 10706: sub LCprogressbarClose {
10707: my ($r)=@_;
10708: $LClastpercent=0;
1.1044 www 10709: &r_print($r,<<ENDCLOSE);
1.1042 www 10710: <script type="text/javascript">
10711: // <![CDATA[
1.1045 www 10712: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10713: // ]]>
10714: </script>
10715: ENDCLOSE
1.1044 www 10716: }
10717:
10718: sub r_print {
10719: my ($r,$to_print)=@_;
10720: if ($r) {
10721: $r->print($to_print);
10722: $r->rflush();
10723: } else {
10724: print($to_print);
10725: }
1.1042 www 10726: }
10727:
1.320 albertel 10728: sub html_encode {
10729: my ($result) = @_;
10730:
1.322 albertel 10731: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10732:
10733: return $result;
10734: }
1.1044 www 10735:
1.317 albertel 10736: sub js_ready {
10737: my ($result) = @_;
10738:
1.323 albertel 10739: $result =~ s/[\n\r]/ /xmsg;
10740: $result =~ s/\\/\\\\/xmsg;
10741: $result =~ s/'/\\'/xmsg;
1.372 albertel 10742: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10743:
10744: return $result;
10745: }
10746:
1.315 albertel 10747: sub validate_page {
10748: if ( exists($env{'internal.start_page'})
1.316 albertel 10749: && $env{'internal.start_page'} > 1) {
10750: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10751: $env{'internal.start_page'}.' '.
1.316 albertel 10752: $ENV{'request.filename'});
1.315 albertel 10753: }
10754: if ( exists($env{'internal.end_page'})
1.316 albertel 10755: && $env{'internal.end_page'} > 1) {
10756: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10757: $env{'internal.end_page'}.' '.
1.316 albertel 10758: $env{'request.filename'});
1.315 albertel 10759: }
10760: if ( exists($env{'internal.start_page'})
10761: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10762: &Apache::lonnet::logthis('start_page called without end_page '.
10763: $env{'request.filename'});
1.315 albertel 10764: }
10765: if ( ! exists($env{'internal.start_page'})
10766: && exists($env{'internal.end_page'})) {
1.316 albertel 10767: &Apache::lonnet::logthis('end_page called without start_page'.
10768: $env{'request.filename'});
1.315 albertel 10769: }
1.306 albertel 10770: }
1.315 albertel 10771:
1.996 www 10772:
10773: sub start_scrollbox {
1.1140 raeburn 10774: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10775: unless ($outerwidth) { $outerwidth='520px'; }
10776: unless ($width) { $width='500px'; }
10777: unless ($height) { $height='200px'; }
1.1075 raeburn 10778: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10779: if ($id ne '') {
1.1140 raeburn 10780: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10781: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10782: }
1.1075 raeburn 10783: if ($bgcolor ne '') {
10784: $tdcol = "background-color: $bgcolor;";
10785: }
1.1137 raeburn 10786: my $nicescroll_js;
10787: if ($env{'browser.mobile'}) {
1.1140 raeburn 10788: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10789: }
10790: return <<"END";
10791: $nicescroll_js
10792:
10793: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10794: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10795: END
10796: }
10797:
10798: sub end_scrollbox {
10799: return '</div></td></tr></table>';
10800: }
10801:
10802: sub nicescroll_javascript {
10803: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10804: my %options;
10805: if (ref($cursor) eq 'HASH') {
10806: %options = %{$cursor};
10807: }
10808: unless ($options{'railalign'} =~ /^left|right$/) {
10809: $options{'railalign'} = 'left';
10810: }
10811: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10812: my $function = &get_users_function();
10813: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10814: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10815: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10816: }
1.1140 raeburn 10817: }
10818: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10819: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10820: $options{'cursoropacity'}='1.0';
10821: }
1.1140 raeburn 10822: } else {
10823: $options{'cursoropacity'}='1.0';
10824: }
10825: if ($options{'cursorfixedheight'} eq 'none') {
10826: delete($options{'cursorfixedheight'});
10827: } else {
10828: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10829: }
10830: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10831: delete($options{'railoffset'});
10832: }
10833: my @niceoptions;
10834: while (my($key,$value) = each(%options)) {
10835: if ($value =~ /^\{.+\}$/) {
10836: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10837: } else {
1.1140 raeburn 10838: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10839: }
1.1140 raeburn 10840: }
10841: my $nicescroll_js = '
1.1137 raeburn 10842: $(document).ready(
1.1140 raeburn 10843: function() {
10844: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10845: }
1.1137 raeburn 10846: );
10847: ';
1.1140 raeburn 10848: if ($framecheck) {
10849: $nicescroll_js .= '
10850: function expand_div(caller) {
10851: if (top === self) {
10852: document.getElementById("'.$id.'").style.width = "auto";
10853: document.getElementById("'.$id.'").style.height = "auto";
10854: } else {
10855: try {
10856: if (parent.frames) {
10857: if (parent.frames.length > 1) {
10858: var framesrc = parent.frames[1].location.href;
10859: var currsrc = framesrc.replace(/\#.*$/,"");
10860: if ((caller == "search") || (currsrc == "'.$location.'")) {
10861: document.getElementById("'.$id.'").style.width = "auto";
10862: document.getElementById("'.$id.'").style.height = "auto";
10863: }
10864: }
10865: }
10866: } catch (e) {
10867: return;
10868: }
1.1137 raeburn 10869: }
1.1140 raeburn 10870: return;
1.996 www 10871: }
1.1140 raeburn 10872: ';
10873: }
10874: if ($needjsready) {
10875: $nicescroll_js = '
10876: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10877: } else {
10878: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10879: }
10880: return $nicescroll_js;
1.996 www 10881: }
10882:
1.318 albertel 10883: sub simple_error_page {
1.1150 bisitz 10884: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10885: my %displayargs;
1.1151 raeburn 10886: if (ref($args) eq 'HASH') {
10887: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10888: if ($args->{'only_body'}) {
10889: $displayargs{'only_body'} = 1;
10890: }
10891: if ($args->{'no_nav_bar'}) {
10892: $displayargs{'no_nav_bar'} = 1;
10893: }
1.1151 raeburn 10894: } else {
10895: $msg = &mt($msg);
10896: }
1.1150 bisitz 10897:
1.318 albertel 10898: my $page =
1.1459 raeburn 10899: &Apache::loncommon::start_page($title,'',\%displayargs)."\n".
1.1460 raeburn 10900: '<div class="LC_landmark" style="clear:both" role="main">'.
1.1150 bisitz 10901: '<p class="LC_error">'.$msg.'</p>'.
1.1459 raeburn 10902: '</div>'.
1.318 albertel 10903: &Apache::loncommon::end_page();
10904: if (ref($r)) {
10905: $r->print($page);
1.327 albertel 10906: return;
1.318 albertel 10907: }
10908: return $page;
10909: }
1.347 albertel 10910:
10911: {
1.610 albertel 10912: my @row_count;
1.961 onken 10913:
10914: sub start_data_table_count {
10915: unshift(@row_count, 0);
10916: return;
10917: }
10918:
10919: sub end_data_table_count {
10920: shift(@row_count);
10921: return;
10922: }
10923:
1.1466 raeburn 10924: sub set_data_table_count {
10925: my ($count) = @_;
10926: unshift(@row_count,$count);
10927: }
10928:
1.347 albertel 10929: sub start_data_table {
1.1018 raeburn 10930: my ($add_class,$id) = @_;
1.422 albertel 10931: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10932: my $table_id;
10933: if (defined($id)) {
10934: $table_id = ' id="'.$id.'"';
10935: }
1.961 onken 10936: &start_data_table_count();
1.1018 raeburn 10937: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10938: }
10939:
10940: sub end_data_table {
1.961 onken 10941: &end_data_table_count();
1.389 albertel 10942: return '</table>'."\n";;
1.347 albertel 10943: }
10944:
10945: sub start_data_table_row {
1.974 wenzelju 10946: my ($add_class, $id) = @_;
1.610 albertel 10947: $row_count[0]++;
10948: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10949: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10950: $id = (' id="'.$id.'"') unless ($id eq '');
10951: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10952: }
1.471 banghart 10953:
10954: sub continue_data_table_row {
1.974 wenzelju 10955: my ($add_class, $id) = @_;
1.610 albertel 10956: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10957: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10958: $id = (' id="'.$id.'"') unless ($id eq '');
10959: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10960: }
1.347 albertel 10961:
10962: sub end_data_table_row {
1.389 albertel 10963: return '</tr>'."\n";;
1.347 albertel 10964: }
1.367 www 10965:
1.421 albertel 10966: sub start_data_table_empty_row {
1.707 bisitz 10967: # $row_count[0]++;
1.421 albertel 10968: return '<tr class="LC_empty_row" >'."\n";;
10969: }
10970:
10971: sub end_data_table_empty_row {
10972: return '</tr>'."\n";;
10973: }
10974:
1.367 www 10975: sub start_data_table_header_row {
1.1465 raeburn 10976: my ($add_class,$id) = @_;
10977: my $css_class = 'LC_header_row';
10978: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10979: $id = (' id="'.$id.'"') unless ($id eq '');
10980: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.367 www 10981: }
10982:
10983: sub end_data_table_header_row {
1.389 albertel 10984: return '</tr>'."\n";;
1.367 www 10985: }
1.890 droeschl 10986:
10987: sub data_table_caption {
1.1468 raeburn 10988: my ($caption,$css_class) = @_;
10989: return "<caption class=\"LC_caption $css_class\">$caption</caption>";
1.890 droeschl 10990: }
1.347 albertel 10991: }
10992:
1.548 albertel 10993: =pod
10994:
10995: =item * &inhibit_menu_check($arg)
10996:
10997: Checks for a inhibitmenu state and generates output to preserve it
10998:
10999: Inputs: $arg - can be any of
11000: - undef - in which case the return value is a string
11001: to add into arguments list of a uri
11002: - 'input' - in which case the return value is a HTML
11003: <form> <input> field of type hidden to
11004: preserve the value
11005: - a url - in which case the return value is the url with
11006: the neccesary cgi args added to preserve the
11007: inhibitmenu state
11008: - a ref to a url - no return value, but the string is
11009: updated to include the neccessary cgi
11010: args to preserve the inhibitmenu state
11011:
11012: =cut
11013:
11014: sub inhibit_menu_check {
11015: my ($arg) = @_;
11016: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
11017: if ($arg eq 'input') {
11018: if ($env{'form.inhibitmenu'}) {
11019: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
11020: } else {
11021: return
11022: }
11023: }
11024: if ($env{'form.inhibitmenu'}) {
11025: if (ref($arg)) {
11026: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
11027: } elsif ($arg eq '') {
11028: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
11029: } else {
11030: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
11031: }
11032: }
11033: if (!ref($arg)) {
11034: return $arg;
11035: }
11036: }
11037:
1.251 albertel 11038: ###############################################
1.182 matthew 11039:
11040: =pod
11041:
1.549 albertel 11042: =back
11043:
11044: =head1 User Information Routines
11045:
11046: =over 4
11047:
1.405 albertel 11048: =item * &get_users_function()
1.182 matthew 11049:
11050: Used by &bodytag to determine the current users primary role.
11051: Returns either 'student','coordinator','admin', or 'author'.
11052:
11053: =cut
11054:
11055: ###############################################
11056: sub get_users_function {
1.815 tempelho 11057: my $function = 'norole';
1.818 tempelho 11058: if ($env{'request.role'}=~/^(st)/) {
11059: $function='student';
11060: }
1.907 raeburn 11061: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 11062: $function='coordinator';
11063: }
1.258 albertel 11064: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 11065: $function='admin';
11066: }
1.826 bisitz 11067: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 11068: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 11069: $function='author';
11070: }
11071: return $function;
1.54 www 11072: }
1.99 www 11073:
11074: ###############################################
11075:
1.233 raeburn 11076: =pod
11077:
1.821 raeburn 11078: =item * &show_course()
11079:
11080: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
11081: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
11082:
11083: Inputs:
11084: None
11085:
11086: Outputs:
11087: Scalar: 1 if 'Course' to be used, 0 otherwise.
11088:
11089: =cut
11090:
11091: ###############################################
11092: sub show_course {
1.1408 raeburn 11093: my ($udom,$uname) = @_;
11094: if (($udom ne '') && ($uname ne '')) {
11095: if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
1.1410 raeburn 11096: if (&Apache::lonnet::is_advanced_user($udom,$uname)) {
1.1408 raeburn 11097: return 0;
11098: } else {
11099: return 1;
11100: }
11101: }
11102: }
1.821 raeburn 11103: my $course = !$env{'user.adv'};
11104: if (!$env{'user.adv'}) {
11105: foreach my $env (keys(%env)) {
11106: next if ($env !~ m/^user\.priv\./);
11107: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
11108: $course = 0;
11109: last;
11110: }
11111: }
11112: }
11113: return $course;
11114: }
11115:
11116: ###############################################
11117:
11118: =pod
11119:
1.542 raeburn 11120: =item * &check_user_status()
1.274 raeburn 11121:
11122: Determines current status of supplied role for a
11123: specific user. Roles can be active, previous or future.
11124:
11125: Inputs:
11126: user's domain, user's username, course's domain,
1.375 raeburn 11127: course's number, optional section ID.
1.274 raeburn 11128:
11129: Outputs:
11130: role status: active, previous or future.
11131:
11132: =cut
11133:
11134: sub check_user_status {
1.412 raeburn 11135: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 11136: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 11137: my @uroles = keys(%userinfo);
1.274 raeburn 11138: my $srchstr;
11139: my $active_chk = 'none';
1.412 raeburn 11140: my $now = time;
1.274 raeburn 11141: if (@uroles > 0) {
1.908 raeburn 11142: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 11143: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
11144: } else {
1.412 raeburn 11145: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
11146: }
11147: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 11148: my $role_end = 0;
11149: my $role_start = 0;
11150: $active_chk = 'active';
1.412 raeburn 11151: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
11152: $role_end = $1;
11153: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
11154: $role_start = $1;
1.274 raeburn 11155: }
11156: }
11157: if ($role_start > 0) {
1.412 raeburn 11158: if ($now < $role_start) {
1.274 raeburn 11159: $active_chk = 'future';
11160: }
11161: }
11162: if ($role_end > 0) {
1.412 raeburn 11163: if ($now > $role_end) {
1.274 raeburn 11164: $active_chk = 'previous';
11165: }
11166: }
11167: }
11168: }
11169: return $active_chk;
11170: }
11171:
11172: ###############################################
11173:
11174: =pod
11175:
1.405 albertel 11176: =item * &get_sections()
1.233 raeburn 11177:
11178: Determines all the sections for a course including
11179: sections with students and sections containing other roles.
1.419 raeburn 11180: Incoming parameters:
11181:
11182: 1. domain
11183: 2. course number
11184: 3. reference to array containing roles for which sections should
11185: be gathered (optional).
11186: 4. reference to array containing status types for which sections
11187: should be gathered (optional).
11188:
11189: If the third argument is undefined, sections are gathered for any role.
11190: If the fourth argument is undefined, sections are gathered for any status.
11191: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 11192:
1.374 raeburn 11193: Returns section hash (keys are section IDs, values are
11194: number of users in each section), subject to the
1.419 raeburn 11195: optional roles filter, optional status filter
1.233 raeburn 11196:
11197: =cut
11198:
11199: ###############################################
11200: sub get_sections {
1.419 raeburn 11201: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 11202: if (!defined($cdom) || !defined($cnum)) {
11203: my $cid = $env{'request.course.id'};
11204:
11205: return if (!defined($cid));
11206:
11207: $cdom = $env{'course.'.$cid.'.domain'};
11208: $cnum = $env{'course.'.$cid.'.num'};
11209: }
11210:
11211: my %sectioncount;
1.419 raeburn 11212: my $now = time;
1.240 albertel 11213:
1.1118 raeburn 11214: my $check_students = 1;
11215: my $only_students = 0;
11216: if (ref($possible_roles) eq 'ARRAY') {
11217: if (grep(/^st$/,@{$possible_roles})) {
11218: if (@{$possible_roles} == 1) {
11219: $only_students = 1;
11220: }
11221: } else {
11222: $check_students = 0;
11223: }
11224: }
11225:
11226: if ($check_students) {
1.276 albertel 11227: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 11228: my $sec_index = &Apache::loncoursedata::CL_SECTION();
11229: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 11230: my $start_index = &Apache::loncoursedata::CL_START();
11231: my $end_index = &Apache::loncoursedata::CL_END();
11232: my $status;
1.366 albertel 11233: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 11234: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
11235: $data->[$status_index],
11236: $data->[$start_index],
11237: $data->[$end_index]);
11238: if ($stu_status eq 'Active') {
11239: $status = 'active';
11240: } elsif ($end < $now) {
11241: $status = 'previous';
11242: } elsif ($start > $now) {
11243: $status = 'future';
11244: }
11245: if ($section ne '-1' && $section !~ /^\s*$/) {
11246: if ((!defined($possible_status)) || (($status ne '') &&
11247: (grep/^\Q$status\E$/,@{$possible_status}))) {
11248: $sectioncount{$section}++;
11249: }
1.240 albertel 11250: }
11251: }
11252: }
1.1118 raeburn 11253: if ($only_students) {
11254: return %sectioncount;
11255: }
1.240 albertel 11256: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11257: foreach my $user (sort(keys(%courseroles))) {
11258: if ($user !~ /^(\w{2})/) { next; }
11259: my ($role) = ($user =~ /^(\w{2})/);
11260: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 11261: my ($section,$status);
1.240 albertel 11262: if ($role eq 'cr' &&
11263: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
11264: $section=$1;
11265: }
11266: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
11267: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 11268: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
11269: if ($end == -1 && $start == -1) {
11270: next; #deleted role
11271: }
11272: if (!defined($possible_status)) {
11273: $sectioncount{$section}++;
11274: } else {
11275: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
11276: $status = 'active';
11277: } elsif ($end < $now) {
11278: $status = 'future';
11279: } elsif ($start > $now) {
11280: $status = 'previous';
11281: }
11282: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
11283: $sectioncount{$section}++;
11284: }
11285: }
1.233 raeburn 11286: }
1.366 albertel 11287: return %sectioncount;
1.233 raeburn 11288: }
11289:
1.274 raeburn 11290: ###############################################
1.294 raeburn 11291:
11292: =pod
1.405 albertel 11293:
11294: =item * &get_course_users()
11295:
1.275 raeburn 11296: Retrieves usernames:domains for users in the specified course
11297: with specific role(s), and access status.
11298:
11299: Incoming parameters:
1.277 albertel 11300: 1. course domain
11301: 2. course number
11302: 3. access status: users must have - either active,
1.275 raeburn 11303: previous, future, or all.
1.277 albertel 11304: 4. reference to array of permissible roles
1.288 raeburn 11305: 5. reference to array of section restrictions (optional)
11306: 6. reference to results object (hash of hashes).
11307: 7. reference to optional userdata hash
1.609 raeburn 11308: 8. reference to optional statushash
1.630 raeburn 11309: 9. flag if privileged users (except those set to unhide in
11310: course settings) should be excluded
1.609 raeburn 11311: Keys of top level results hash are roles.
1.275 raeburn 11312: Keys of inner hashes are username:domain, with
11313: values set to access type.
1.288 raeburn 11314: Optional userdata hash returns an array with arguments in the
11315: same order as loncoursedata::get_classlist() for student data.
11316:
1.609 raeburn 11317: Optional statushash returns
11318:
1.288 raeburn 11319: Entries for end, start, section and status are blank because
11320: of the possibility of multiple values for non-student roles.
11321:
1.275 raeburn 11322: =cut
1.405 albertel 11323:
1.275 raeburn 11324: ###############################################
1.405 albertel 11325:
1.275 raeburn 11326: sub get_course_users {
1.630 raeburn 11327: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 11328: my %idx = ();
1.419 raeburn 11329: my %seclists;
1.288 raeburn 11330:
11331: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
11332: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
11333: $idx{end} = &Apache::loncoursedata::CL_END();
11334: $idx{start} = &Apache::loncoursedata::CL_START();
11335: $idx{id} = &Apache::loncoursedata::CL_ID();
11336: $idx{section} = &Apache::loncoursedata::CL_SECTION();
11337: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
11338: $idx{status} = &Apache::loncoursedata::CL_STATUS();
11339:
1.290 albertel 11340: if (grep(/^st$/,@{$roles})) {
1.276 albertel 11341: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 11342: my $now = time;
1.277 albertel 11343: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 11344: my $match = 0;
1.412 raeburn 11345: my $secmatch = 0;
1.419 raeburn 11346: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 11347: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 11348: if ($section eq '') {
11349: $section = 'none';
11350: }
1.291 albertel 11351: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11352: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11353: $secmatch = 1;
11354: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 11355: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11356: $secmatch = 1;
11357: }
11358: } else {
1.419 raeburn 11359: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 11360: $secmatch = 1;
11361: }
1.290 albertel 11362: }
1.412 raeburn 11363: if (!$secmatch) {
11364: next;
11365: }
1.419 raeburn 11366: }
1.275 raeburn 11367: if (defined($$types{'active'})) {
1.288 raeburn 11368: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 11369: push(@{$$users{st}{$student}},'active');
1.288 raeburn 11370: $match = 1;
1.275 raeburn 11371: }
11372: }
11373: if (defined($$types{'previous'})) {
1.609 raeburn 11374: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 11375: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 11376: $match = 1;
1.275 raeburn 11377: }
11378: }
11379: if (defined($$types{'future'})) {
1.609 raeburn 11380: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 11381: push(@{$$users{st}{$student}},'future');
1.288 raeburn 11382: $match = 1;
1.275 raeburn 11383: }
11384: }
1.609 raeburn 11385: if ($match) {
11386: push(@{$seclists{$student}},$section);
11387: if (ref($userdata) eq 'HASH') {
11388: $$userdata{$student} = $$classlist{$student};
11389: }
11390: if (ref($statushash) eq 'HASH') {
11391: $statushash->{$student}{'st'}{$section} = $status;
11392: }
1.288 raeburn 11393: }
1.275 raeburn 11394: }
11395: }
1.412 raeburn 11396: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 11397: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11398: my $now = time;
1.609 raeburn 11399: my %displaystatus = ( previous => 'Expired',
11400: active => 'Active',
11401: future => 'Future',
11402: );
1.1121 raeburn 11403: my (%nothide,@possdoms);
1.630 raeburn 11404: if ($hidepriv) {
11405: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
11406: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
11407: if ($user !~ /:/) {
11408: $nothide{join(':',split(/[\@]/,$user))}=1;
11409: } else {
11410: $nothide{$user} = 1;
11411: }
11412: }
1.1121 raeburn 11413: my @possdoms = ($cdom);
11414: if ($coursehash{'checkforpriv'}) {
11415: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
11416: }
1.630 raeburn 11417: }
1.439 raeburn 11418: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 11419: my $match = 0;
1.412 raeburn 11420: my $secmatch = 0;
1.439 raeburn 11421: my $status;
1.412 raeburn 11422: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 11423: $user =~ s/:$//;
1.439 raeburn 11424: my ($end,$start) = split(/:/,$coursepersonnel{$person});
11425: if ($end == -1 || $start == -1) {
11426: next;
11427: }
11428: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
11429: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 11430: my ($uname,$udom) = split(/:/,$user);
11431: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11432: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11433: $secmatch = 1;
11434: } elsif ($usec eq '') {
1.420 albertel 11435: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11436: $secmatch = 1;
11437: }
11438: } else {
11439: if (grep(/^\Q$usec\E$/,@{$sections})) {
11440: $secmatch = 1;
11441: }
11442: }
11443: if (!$secmatch) {
11444: next;
11445: }
1.288 raeburn 11446: }
1.419 raeburn 11447: if ($usec eq '') {
11448: $usec = 'none';
11449: }
1.275 raeburn 11450: if ($uname ne '' && $udom ne '') {
1.630 raeburn 11451: if ($hidepriv) {
1.1121 raeburn 11452: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 11453: (!$nothide{$uname.':'.$udom})) {
11454: next;
11455: }
11456: }
1.503 raeburn 11457: if ($end > 0 && $end < $now) {
1.439 raeburn 11458: $status = 'previous';
11459: } elsif ($start > $now) {
11460: $status = 'future';
11461: } else {
11462: $status = 'active';
11463: }
1.277 albertel 11464: foreach my $type (keys(%{$types})) {
1.275 raeburn 11465: if ($status eq $type) {
1.420 albertel 11466: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 11467: push(@{$$users{$role}{$user}},$type);
11468: }
1.288 raeburn 11469: $match = 1;
11470: }
11471: }
1.419 raeburn 11472: if (($match) && (ref($userdata) eq 'HASH')) {
11473: if (!exists($$userdata{$uname.':'.$udom})) {
11474: &get_user_info($udom,$uname,\%idx,$userdata);
11475: }
1.420 albertel 11476: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 11477: push(@{$seclists{$uname.':'.$udom}},$usec);
11478: }
1.609 raeburn 11479: if (ref($statushash) eq 'HASH') {
11480: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
11481: }
1.275 raeburn 11482: }
11483: }
11484: }
11485: }
1.290 albertel 11486: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 11487: if ((defined($cdom)) && (defined($cnum))) {
11488: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
11489: if ( defined($csettings{'internal.courseowner'}) ) {
11490: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 11491: next if ($owner eq '');
11492: my ($ownername,$ownerdom);
11493: if ($owner =~ /^([^:]+):([^:]+)$/) {
11494: $ownername = $1;
11495: $ownerdom = $2;
11496: } else {
11497: $ownername = $owner;
11498: $ownerdom = $cdom;
11499: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 11500: }
11501: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 11502: if (defined($userdata) &&
1.609 raeburn 11503: !exists($$userdata{$owner})) {
11504: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
11505: if (!grep(/^none$/,@{$seclists{$owner}})) {
11506: push(@{$seclists{$owner}},'none');
11507: }
11508: if (ref($statushash) eq 'HASH') {
11509: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 11510: }
1.290 albertel 11511: }
1.279 raeburn 11512: }
11513: }
11514: }
1.419 raeburn 11515: foreach my $user (keys(%seclists)) {
11516: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
11517: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
11518: }
1.275 raeburn 11519: }
11520: return;
11521: }
11522:
1.288 raeburn 11523: sub get_user_info {
11524: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 11525: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
11526: &plainname($uname,$udom,'lastname');
1.291 albertel 11527: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 11528: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 11529: my %idhash = &Apache::lonnet::idrget($udom,($uname));
11530: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 11531: return;
11532: }
1.275 raeburn 11533:
1.472 raeburn 11534: ###############################################
11535:
11536: =pod
11537:
11538: =item * &get_user_quota()
11539:
1.1134 raeburn 11540: Retrieves quota assigned for storage of user files.
11541: Default is to report quota for portfolio files.
1.472 raeburn 11542:
11543: Incoming parameters:
11544: 1. user's username
11545: 2. user's domain
1.1134 raeburn 11546: 3. quota name - portfolio, author, or course
1.1136 raeburn 11547: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 11548: 4. crstype - official, unofficial, textbook, placement or community,
11549: if quota name is course
1.472 raeburn 11550:
11551: Returns:
1.1163 raeburn 11552: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 11553: 2. (Optional) Type of setting: custom or default
11554: (individually assigned or default for user's
11555: institutional status).
11556: 3. (Optional) - User's institutional status (e.g., faculty, staff
11557: or student - types as defined in localenroll::inst_usertypes
11558: for user's domain, which determines default quota for user.
11559: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 11560:
11561: If a value has been stored in the user's environment,
1.536 raeburn 11562: it will return that, otherwise it returns the maximal default
1.1134 raeburn 11563: defined for the user's institutional status(es) in the domain.
1.472 raeburn 11564:
11565: =cut
11566:
11567: ###############################################
11568:
11569:
11570: sub get_user_quota {
1.1136 raeburn 11571: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 11572: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 11573: if (!defined($udom)) {
11574: $udom = $env{'user.domain'};
11575: }
11576: if (!defined($uname)) {
11577: $uname = $env{'user.name'};
11578: }
11579: if (($udom eq '' || $uname eq '') ||
11580: ($udom eq 'public') && ($uname eq 'public')) {
11581: $quota = 0;
1.536 raeburn 11582: $quotatype = 'default';
11583: $defquota = 0;
1.472 raeburn 11584: } else {
1.536 raeburn 11585: my $inststatus;
1.1134 raeburn 11586: if ($quotaname eq 'course') {
11587: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
11588: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
11589: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
11590: } else {
11591: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
11592: $quota = $cenv{'internal.uploadquota'};
11593: }
1.536 raeburn 11594: } else {
1.1134 raeburn 11595: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
11596: if ($quotaname eq 'author') {
11597: $quota = $env{'environment.authorquota'};
11598: } else {
11599: $quota = $env{'environment.portfolioquota'};
11600: }
11601: $inststatus = $env{'environment.inststatus'};
11602: } else {
11603: my %userenv =
11604: &Apache::lonnet::get('environment',['portfolioquota',
11605: 'authorquota','inststatus'],$udom,$uname);
11606: my ($tmp) = keys(%userenv);
11607: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11608: if ($quotaname eq 'author') {
11609: $quota = $userenv{'authorquota'};
11610: } else {
11611: $quota = $userenv{'portfolioquota'};
11612: }
11613: $inststatus = $userenv{'inststatus'};
11614: } else {
11615: undef(%userenv);
11616: }
11617: }
11618: }
11619: if ($quota eq '' || wantarray) {
11620: if ($quotaname eq 'course') {
11621: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11622: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11623: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11624: ($crstype eq 'placement')) {
1.1136 raeburn 11625: $defquota = $domdefs{$crstype.'quota'};
11626: }
11627: if ($defquota eq '') {
11628: $defquota = 500;
11629: }
1.1134 raeburn 11630: } else {
11631: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11632: }
11633: if ($quota eq '') {
11634: $quota = $defquota;
11635: $quotatype = 'default';
11636: } else {
11637: $quotatype = 'custom';
11638: }
1.472 raeburn 11639: }
11640: }
1.536 raeburn 11641: if (wantarray) {
11642: return ($quota,$quotatype,$settingstatus,$defquota);
11643: } else {
11644: return $quota;
11645: }
1.472 raeburn 11646: }
11647:
11648: ###############################################
11649:
11650: =pod
11651:
11652: =item * &default_quota()
11653:
1.536 raeburn 11654: Retrieves default quota assigned for storage of user portfolio files,
11655: given an (optional) user's institutional status.
1.472 raeburn 11656:
11657: Incoming parameters:
1.1142 raeburn 11658:
1.472 raeburn 11659: 1. domain
1.536 raeburn 11660: 2. (Optional) institutional status(es). This is a : separated list of
11661: status types (e.g., faculty, staff, student etc.)
11662: which apply to the user for whom the default is being retrieved.
11663: If the institutional status string in undefined, the domain
1.1134 raeburn 11664: default quota will be returned.
11665: 3. quota name - portfolio, author, or course
11666: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11667:
11668: Returns:
1.1142 raeburn 11669:
1.1163 raeburn 11670: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11671: 2. (Optional) institutional type which determined the value of the
11672: default quota.
1.472 raeburn 11673:
11674: If a value has been stored in the domain's configuration db,
11675: it will return that, otherwise it returns 20 (for backwards
11676: compatibility with domains which have not set up a configuration
1.1163 raeburn 11677: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11678:
1.536 raeburn 11679: If the user's status includes multiple types (e.g., staff and student),
11680: the largest default quota which applies to the user determines the
11681: default quota returned.
11682:
1.472 raeburn 11683: =cut
11684:
11685: ###############################################
11686:
11687:
11688: sub default_quota {
1.1134 raeburn 11689: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11690: my ($defquota,$settingstatus);
11691: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11692: ['quotas'],$udom);
1.1134 raeburn 11693: my $key = 'defaultquota';
11694: if ($quotaname eq 'author') {
11695: $key = 'authorquota';
11696: }
1.622 raeburn 11697: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11698: if ($inststatus ne '') {
1.765 raeburn 11699: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11700: foreach my $item (@statuses) {
1.1134 raeburn 11701: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11702: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11703: if ($defquota eq '') {
1.1134 raeburn 11704: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11705: $settingstatus = $item;
1.1134 raeburn 11706: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11707: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11708: $settingstatus = $item;
11709: }
11710: }
1.1134 raeburn 11711: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11712: if ($quotahash{'quotas'}{$item} ne '') {
11713: if ($defquota eq '') {
11714: $defquota = $quotahash{'quotas'}{$item};
11715: $settingstatus = $item;
11716: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11717: $defquota = $quotahash{'quotas'}{$item};
11718: $settingstatus = $item;
11719: }
1.536 raeburn 11720: }
11721: }
11722: }
11723: }
11724: if ($defquota eq '') {
1.1134 raeburn 11725: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11726: $defquota = $quotahash{'quotas'}{$key}{'default'};
11727: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11728: $defquota = $quotahash{'quotas'}{'default'};
11729: }
1.536 raeburn 11730: $settingstatus = 'default';
1.1139 raeburn 11731: if ($defquota eq '') {
11732: if ($quotaname eq 'author') {
11733: $defquota = 500;
11734: }
11735: }
1.536 raeburn 11736: }
11737: } else {
11738: $settingstatus = 'default';
1.1134 raeburn 11739: if ($quotaname eq 'author') {
11740: $defquota = 500;
11741: } else {
11742: $defquota = 20;
11743: }
1.536 raeburn 11744: }
11745: if (wantarray) {
11746: return ($defquota,$settingstatus);
1.472 raeburn 11747: } else {
1.536 raeburn 11748: return $defquota;
1.472 raeburn 11749: }
11750: }
11751:
1.1135 raeburn 11752: ###############################################
11753:
11754: =pod
11755:
1.1136 raeburn 11756: =item * &excess_filesize_warning()
1.1135 raeburn 11757:
11758: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11759: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11760: space to be exceeded.
1.1136 raeburn 11761:
11762: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11763: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11764:
1.1165 raeburn 11765: Inputs: 7
1.1136 raeburn 11766: 1. username or coursenum
1.1135 raeburn 11767: 2. domain
1.1136 raeburn 11768: 3. context ('author' or 'course')
1.1135 raeburn 11769: 4. filename of file for which action is being requested
11770: 5. filesize (kB) of file
11771: 6. action being taken: copy or upload.
1.1237 raeburn 11772: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11773:
11774: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11775: otherwise return null.
11776:
11777: =back
1.1135 raeburn 11778:
11779: =cut
11780:
1.1136 raeburn 11781: sub excess_filesize_warning {
1.1165 raeburn 11782: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11783: my $current_disk_usage = 0;
1.1165 raeburn 11784: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11785: if ($context eq 'author') {
11786: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11787: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11788: } else {
11789: foreach my $subdir ('docs','supplemental') {
11790: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11791: }
11792: }
1.1135 raeburn 11793: $disk_quota = int($disk_quota * 1000);
11794: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11795: return '<p class="LC_warning">'.
1.1135 raeburn 11796: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11797: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11798: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11799: $disk_quota,$current_disk_usage).
11800: '</p>';
11801: }
11802: return;
11803: }
11804:
11805: ###############################################
11806:
11807:
1.1136 raeburn 11808:
11809:
1.384 raeburn 11810: sub get_secgrprole_info {
11811: my ($cdom,$cnum,$needroles,$type) = @_;
11812: my %sections_count = &get_sections($cdom,$cnum);
11813: my @sections = (sort {$a <=> $b} keys(%sections_count));
11814: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11815: my @groups = sort(keys(%curr_groups));
11816: my $allroles = [];
11817: my $rolehash;
11818: my $accesshash = {
11819: active => 'Currently has access',
11820: future => 'Will have future access',
11821: previous => 'Previously had access',
11822: };
11823: if ($needroles) {
11824: $rolehash = {'all' => 'all'};
1.385 albertel 11825: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11826: if (&Apache::lonnet::error(%user_roles)) {
11827: undef(%user_roles);
11828: }
11829: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11830: my ($role)=split(/\:/,$item,2);
11831: if ($role eq 'cr') { next; }
11832: if ($role =~ /^cr/) {
11833: $$rolehash{$role} = (split('/',$role))[3];
11834: } else {
11835: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11836: }
11837: }
11838: foreach my $key (sort(keys(%{$rolehash}))) {
11839: push(@{$allroles},$key);
11840: }
11841: push (@{$allroles},'st');
11842: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11843: }
11844: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11845: }
11846:
1.555 raeburn 11847: sub user_picker {
1.1279 raeburn 11848: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11849: my $currdom = $dom;
1.1253 raeburn 11850: my @alldoms = &Apache::lonnet::all_domains();
11851: if (@alldoms == 1) {
11852: my %domsrch = &Apache::lonnet::get_dom('configuration',
11853: ['directorysrch'],$alldoms[0]);
11854: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11855: my $showdom = $domdesc;
11856: if ($showdom eq '') {
11857: $showdom = $dom;
11858: }
11859: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11860: if ((!$domsrch{'directorysrch'}{'available'}) &&
11861: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11862: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11863: }
11864: }
11865: }
1.555 raeburn 11866: my %curr_selected = (
11867: srchin => 'dom',
1.580 raeburn 11868: srchby => 'lastname',
1.555 raeburn 11869: );
11870: my $srchterm;
1.625 raeburn 11871: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11872: if ($srch->{'srchby'} ne '') {
11873: $curr_selected{'srchby'} = $srch->{'srchby'};
11874: }
11875: if ($srch->{'srchin'} ne '') {
11876: $curr_selected{'srchin'} = $srch->{'srchin'};
11877: }
11878: if ($srch->{'srchtype'} ne '') {
11879: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11880: }
11881: if ($srch->{'srchdomain'} ne '') {
11882: $currdom = $srch->{'srchdomain'};
11883: }
11884: $srchterm = $srch->{'srchterm'};
11885: }
1.1222 damieng 11886: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11887: 'usr' => 'Search criteria',
1.563 raeburn 11888: 'doma' => 'Domain/institution to search',
1.558 albertel 11889: 'uname' => 'username',
11890: 'lastname' => 'last name',
1.555 raeburn 11891: 'lastfirst' => 'last name, first name',
1.558 albertel 11892: 'crs' => 'in this course',
1.576 raeburn 11893: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11894: 'alc' => 'all LON-CAPA',
1.573 raeburn 11895: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11896: 'exact' => 'is',
11897: 'contains' => 'contains',
1.569 raeburn 11898: 'begins' => 'begins with',
1.1222 damieng 11899: );
11900: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11901: 'youm' => "You must include some text to search for.",
11902: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11903: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11904: 'yomc' => "You must choose a domain when using an institutional directory search.",
11905: 'ymcd' => "You must choose a domain when using a domain search.",
11906: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11907: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11908: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11909: );
1.1222 damieng 11910: &html_escape(\%html_lt);
11911: &js_escape(\%js_lt);
1.1255 raeburn 11912: my $domform;
1.1277 raeburn 11913: my $allow_blank = 1;
1.1255 raeburn 11914: if ($fixeddom) {
1.1277 raeburn 11915: $allow_blank = 0;
11916: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11917: } else {
1.1287 raeburn 11918: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11919: my ($trusted,$untrusted);
1.1287 raeburn 11920: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11921: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11922: } elsif ($context eq 'author') {
1.1288 raeburn 11923: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11924: } elsif ($context eq 'domain') {
1.1288 raeburn 11925: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11926: }
1.1288 raeburn 11927: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11928: }
1.563 raeburn 11929: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11930:
11931: my @srchins = ('crs','dom','alc','instd');
11932:
11933: foreach my $option (@srchins) {
11934: # FIXME 'alc' option unavailable until
11935: # loncreateuser::print_user_query_page()
11936: # has been completed.
11937: next if ($option eq 'alc');
1.880 raeburn 11938: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11939: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11940: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11941: if ($curr_selected{'srchin'} eq $option) {
11942: $srchinsel .= '
1.1222 damieng 11943: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11944: } else {
11945: $srchinsel .= '
1.1222 damieng 11946: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11947: }
1.555 raeburn 11948: }
1.563 raeburn 11949: $srchinsel .= "\n </select>\n";
1.555 raeburn 11950:
11951: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11952: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11953: if ($curr_selected{'srchby'} eq $option) {
11954: $srchbysel .= '
1.1222 damieng 11955: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11956: } else {
11957: $srchbysel .= '
1.1222 damieng 11958: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11959: }
11960: }
11961: $srchbysel .= "\n </select>\n";
11962:
11963: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11964: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11965: if ($curr_selected{'srchtype'} eq $option) {
11966: $srchtypesel .= '
1.1222 damieng 11967: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11968: } else {
11969: $srchtypesel .= '
1.1222 damieng 11970: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11971: }
11972: }
11973: $srchtypesel .= "\n </select>\n";
11974:
1.558 albertel 11975: my ($newuserscript,$new_user_create);
1.994 raeburn 11976: my $context_dom = $env{'request.role.domain'};
11977: if ($context eq 'requestcrs') {
11978: if ($env{'form.coursedom'} ne '') {
11979: $context_dom = $env{'form.coursedom'};
11980: }
11981: }
1.556 raeburn 11982: if ($forcenewuser) {
1.576 raeburn 11983: if (ref($srch) eq 'HASH') {
1.994 raeburn 11984: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11985: if ($cancreate) {
11986: $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>';
11987: } else {
1.799 bisitz 11988: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11989: my %usertypetext = (
11990: official => 'institutional',
11991: unofficial => 'non-institutional',
11992: );
1.799 bisitz 11993: $new_user_create = '<p class="LC_warning">'
11994: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11995: .' '
11996: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11997: ,'<a href="'.$helplink.'">','</a>')
11998: .'</p><br />';
1.627 raeburn 11999: }
1.576 raeburn 12000: }
12001: }
12002:
1.556 raeburn 12003: $newuserscript = <<"ENDSCRIPT";
12004:
1.570 raeburn 12005: function setSearch(createnew,callingForm) {
1.556 raeburn 12006: if (createnew == 1) {
1.570 raeburn 12007: for (var i=0; i<callingForm.srchby.length; i++) {
12008: if (callingForm.srchby.options[i].value == 'uname') {
12009: callingForm.srchby.selectedIndex = i;
1.556 raeburn 12010: }
12011: }
1.570 raeburn 12012: for (var i=0; i<callingForm.srchin.length; i++) {
12013: if ( callingForm.srchin.options[i].value == 'dom') {
12014: callingForm.srchin.selectedIndex = i;
1.556 raeburn 12015: }
12016: }
1.570 raeburn 12017: for (var i=0; i<callingForm.srchtype.length; i++) {
12018: if (callingForm.srchtype.options[i].value == 'exact') {
12019: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 12020: }
12021: }
1.570 raeburn 12022: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 12023: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 12024: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 12025: }
12026: }
12027: }
12028: }
12029: ENDSCRIPT
1.558 albertel 12030:
1.556 raeburn 12031: }
12032:
1.555 raeburn 12033: my $output = <<"END_BLOCK";
1.556 raeburn 12034: <script type="text/javascript">
1.824 bisitz 12035: // <![CDATA[
1.570 raeburn 12036: function validateEntry(callingForm) {
1.558 albertel 12037:
1.556 raeburn 12038: var checkok = 1;
1.558 albertel 12039: var srchin;
1.570 raeburn 12040: for (var i=0; i<callingForm.srchin.length; i++) {
12041: if ( callingForm.srchin[i].checked ) {
12042: srchin = callingForm.srchin[i].value;
1.558 albertel 12043: }
12044: }
12045:
1.570 raeburn 12046: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
12047: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
12048: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
12049: var srchterm = callingForm.srchterm.value;
12050: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 12051: var msg = "";
12052:
12053: if (srchterm == "") {
12054: checkok = 0;
1.1222 damieng 12055: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 12056: }
12057:
1.569 raeburn 12058: if (srchtype== 'begins') {
12059: if (srchterm.length < 2) {
12060: checkok = 0;
1.1222 damieng 12061: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 12062: }
12063: }
12064:
1.556 raeburn 12065: if (srchtype== 'contains') {
12066: if (srchterm.length < 3) {
12067: checkok = 0;
1.1222 damieng 12068: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 12069: }
12070: }
12071: if (srchin == 'instd') {
12072: if (srchdomain == '') {
12073: checkok = 0;
1.1222 damieng 12074: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 12075: }
12076: }
12077: if (srchin == 'dom') {
12078: if (srchdomain == '') {
12079: checkok = 0;
1.1222 damieng 12080: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 12081: }
12082: }
12083: if (srchby == 'lastfirst') {
12084: if (srchterm.indexOf(",") == -1) {
12085: checkok = 0;
1.1222 damieng 12086: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 12087: }
12088: if (srchterm.indexOf(",") == srchterm.length -1) {
12089: checkok = 0;
1.1222 damieng 12090: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 12091: }
12092: }
12093: if (checkok == 0) {
1.1222 damieng 12094: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 12095: return;
12096: }
12097: if (checkok == 1) {
1.570 raeburn 12098: callingForm.submit();
1.556 raeburn 12099: }
12100: }
12101:
12102: $newuserscript
12103:
1.824 bisitz 12104: // ]]>
1.556 raeburn 12105: </script>
1.558 albertel 12106:
12107: $new_user_create
12108:
1.555 raeburn 12109: END_BLOCK
1.558 albertel 12110:
1.876 raeburn 12111: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 12112: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 12113: $domform.
12114: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 12115: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 12116: $srchbysel.
12117: $srchtypesel.
12118: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
12119: $srchinsel.
12120: &Apache::lonhtmlcommon::row_closure(1).
12121: &Apache::lonhtmlcommon::end_pick_box().
12122: '<br />';
1.1253 raeburn 12123: return ($output,1);
1.555 raeburn 12124: }
12125:
1.612 raeburn 12126: sub user_rule_check {
1.615 raeburn 12127: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 12128: my ($response,%inst_response);
1.612 raeburn 12129: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 12130: if (keys(%{$usershash}) > 1) {
12131: my (%by_username,%by_id,%userdoms);
12132: my $checkid;
12133: if (ref($checks) eq 'HASH') {
12134: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
12135: $checkid = 1;
12136: }
12137: }
12138: foreach my $user (keys(%{$usershash})) {
12139: my ($uname,$udom) = split(/:/,$user);
12140: if ($checkid) {
12141: if (ref($usershash->{$user}) eq 'HASH') {
12142: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 12143: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 12144: $userdoms{$udom} = 1;
1.1227 raeburn 12145: if (ref($inst_results) eq 'HASH') {
12146: $inst_results->{$uname.':'.$udom} = {};
12147: }
1.1226 raeburn 12148: }
12149: }
12150: } else {
12151: $by_username{$udom}{$uname} = 1;
12152: $userdoms{$udom} = 1;
1.1227 raeburn 12153: if (ref($inst_results) eq 'HASH') {
12154: $inst_results->{$uname.':'.$udom} = {};
12155: }
1.1226 raeburn 12156: }
12157: }
12158: foreach my $udom (keys(%userdoms)) {
12159: if (!$got_rules->{$udom}) {
12160: my %domconfig = &Apache::lonnet::get_dom('configuration',
12161: ['usercreation'],$udom);
12162: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12163: foreach my $item ('username','id') {
12164: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 12165: $$curr_rules{$udom}{$item} =
12166: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 12167: }
12168: }
12169: }
12170: $got_rules->{$udom} = 1;
12171: }
1.612 raeburn 12172: }
1.1226 raeburn 12173: if ($checkid) {
12174: foreach my $udom (keys(%by_id)) {
12175: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
12176: if ($outcome eq 'ok') {
1.1227 raeburn 12177: foreach my $id (keys(%{$by_id{$udom}})) {
12178: my $uname = $by_id{$udom}{$id};
12179: $inst_response{$uname.':'.$udom} = $outcome;
12180: }
1.1226 raeburn 12181: if (ref($results) eq 'HASH') {
12182: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 12183: if (exists($inst_response{$uname.':'.$udom})) {
12184: $inst_response{$uname.':'.$udom} = $outcome;
12185: $inst_results->{$uname.':'.$udom} = $results->{$uname};
12186: }
1.1226 raeburn 12187: }
12188: }
12189: }
1.612 raeburn 12190: }
1.615 raeburn 12191: } else {
1.1226 raeburn 12192: foreach my $udom (keys(%by_username)) {
12193: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
12194: if ($outcome eq 'ok') {
1.1227 raeburn 12195: foreach my $uname (keys(%{$by_username{$udom}})) {
12196: $inst_response{$uname.':'.$udom} = $outcome;
12197: }
1.1226 raeburn 12198: if (ref($results) eq 'HASH') {
12199: foreach my $uname (keys(%{$results})) {
12200: $inst_results->{$uname.':'.$udom} = $results->{$uname};
12201: }
12202: }
12203: }
12204: }
1.612 raeburn 12205: }
1.1226 raeburn 12206: } elsif (keys(%{$usershash}) == 1) {
12207: my $user = (keys(%{$usershash}))[0];
12208: my ($uname,$udom) = split(/:/,$user);
12209: if (($udom ne '') && ($uname ne '')) {
12210: if (ref($usershash->{$user}) eq 'HASH') {
12211: if (ref($checks) eq 'HASH') {
12212: if (defined($checks->{'username'})) {
12213: ($inst_response{$user},%{$inst_results->{$user}}) =
12214: &Apache::lonnet::get_instuser($udom,$uname);
12215: } elsif (defined($checks->{'id'})) {
12216: if ($usershash->{$user}->{'id'} ne '') {
12217: ($inst_response{$user},%{$inst_results->{$user}}) =
12218: &Apache::lonnet::get_instuser($udom,undef,
12219: $usershash->{$user}->{'id'});
12220: } else {
12221: ($inst_response{$user},%{$inst_results->{$user}}) =
12222: &Apache::lonnet::get_instuser($udom,$uname);
12223: }
1.585 raeburn 12224: }
1.1226 raeburn 12225: } else {
12226: ($inst_response{$user},%{$inst_results->{$user}}) =
12227: &Apache::lonnet::get_instuser($udom,$uname);
12228: return;
12229: }
12230: if (!$got_rules->{$udom}) {
12231: my %domconfig = &Apache::lonnet::get_dom('configuration',
12232: ['usercreation'],$udom);
12233: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12234: foreach my $item ('username','id') {
12235: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
12236: $$curr_rules{$udom}{$item} =
12237: $domconfig{'usercreation'}{$item.'_rule'};
12238: }
12239: }
12240: }
12241: $got_rules->{$udom} = 1;
1.585 raeburn 12242: }
12243: }
1.1226 raeburn 12244: } else {
12245: return;
12246: }
12247: } else {
12248: return;
12249: }
12250: foreach my $user (keys(%{$usershash})) {
12251: my ($uname,$udom) = split(/:/,$user);
12252: next if (($udom eq '') || ($uname eq ''));
12253: my $id;
1.1227 raeburn 12254: if (ref($inst_results) eq 'HASH') {
12255: if (ref($inst_results->{$user}) eq 'HASH') {
12256: $id = $inst_results->{$user}->{'id'};
12257: }
12258: }
12259: if ($id eq '') {
12260: if (ref($usershash->{$user})) {
12261: $id = $usershash->{$user}->{'id'};
12262: }
1.585 raeburn 12263: }
1.612 raeburn 12264: foreach my $item (keys(%{$checks})) {
12265: if (ref($$curr_rules{$udom}) eq 'HASH') {
12266: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
12267: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 12268: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
12269: $$curr_rules{$udom}{$item});
1.612 raeburn 12270: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
12271: if ($rule_check{$rule}) {
12272: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 12273: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 12274: if (ref($inst_results) eq 'HASH') {
12275: if (ref($inst_results->{$user}) eq 'HASH') {
12276: if (keys(%{$inst_results->{$user}}) == 0) {
12277: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 12278: } elsif ($item eq 'id') {
12279: if ($inst_results->{$user}->{'id'} eq '') {
12280: $$alerts{$item}{$udom}{$uname} = 1;
12281: }
1.615 raeburn 12282: }
1.612 raeburn 12283: }
12284: }
1.615 raeburn 12285: }
12286: last;
1.585 raeburn 12287: }
12288: }
12289: }
12290: }
12291: }
12292: }
12293: }
12294: }
1.612 raeburn 12295: return;
12296: }
12297:
12298: sub user_rule_formats {
12299: my ($domain,$domdesc,$curr_rules,$check) = @_;
12300: my %text = (
12301: 'username' => 'Usernames',
12302: 'id' => 'IDs',
12303: );
12304: my $output;
12305: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
12306: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
12307: if (@{$ruleorder} > 0) {
1.1102 raeburn 12308: $output = '<br />'.
12309: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
12310: '<span class="LC_cusr_emph">','</span>',$domdesc).
12311: ' <ul>';
1.612 raeburn 12312: foreach my $rule (@{$ruleorder}) {
12313: if (ref($curr_rules) eq 'ARRAY') {
12314: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
12315: if (ref($rules->{$rule}) eq 'HASH') {
12316: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
12317: $rules->{$rule}{'desc'}.'</li>';
12318: }
12319: }
12320: }
12321: }
12322: $output .= '</ul>';
12323: }
12324: }
12325: return $output;
12326: }
12327:
12328: sub instrule_disallow_msg {
1.615 raeburn 12329: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 12330: my $response;
12331: my %text = (
12332: item => 'username',
12333: items => 'usernames',
12334: match => 'matches',
12335: do => 'does',
12336: action => 'a username',
12337: one => 'one',
12338: );
12339: if ($count > 1) {
12340: $text{'item'} = 'usernames';
12341: $text{'match'} ='match';
12342: $text{'do'} = 'do';
12343: $text{'action'} = 'usernames',
12344: $text{'one'} = 'ones';
12345: }
12346: if ($checkitem eq 'id') {
12347: $text{'items'} = 'IDs';
12348: $text{'item'} = 'ID';
12349: $text{'action'} = 'an ID';
1.615 raeburn 12350: if ($count > 1) {
12351: $text{'item'} = 'IDs';
12352: $text{'action'} = 'IDs';
12353: }
1.612 raeburn 12354: }
1.674 bisitz 12355: $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 12356: if ($mode eq 'upload') {
12357: if ($checkitem eq 'username') {
12358: $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'}.");
12359: } elsif ($checkitem eq 'id') {
1.674 bisitz 12360: $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 12361: }
1.669 raeburn 12362: } elsif ($mode eq 'selfcreate') {
12363: if ($checkitem eq 'id') {
12364: $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.");
12365: }
1.615 raeburn 12366: } else {
12367: if ($checkitem eq 'username') {
12368: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
12369: } elsif ($checkitem eq 'id') {
12370: $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.");
12371: }
1.612 raeburn 12372: }
12373: return $response;
1.585 raeburn 12374: }
12375:
1.624 raeburn 12376: sub personal_data_fieldtitles {
12377: my %fieldtitles = &Apache::lonlocal::texthash (
12378: id => 'Student/Employee ID',
12379: permanentemail => 'E-mail address',
12380: lastname => 'Last Name',
12381: firstname => 'First Name',
12382: middlename => 'Middle Name',
12383: generation => 'Generation',
12384: gen => 'Generation',
1.765 raeburn 12385: inststatus => 'Affiliation',
1.624 raeburn 12386: );
12387: return %fieldtitles;
12388: }
12389:
1.642 raeburn 12390: sub sorted_inst_types {
12391: my ($dom) = @_;
1.1185 raeburn 12392: my ($usertypes,$order);
12393: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12394: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
12395: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
12396: $order = $domdefaults{'inststatus'}{'inststatusorder'};
12397: } else {
12398: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
12399: }
1.642 raeburn 12400: my $othertitle = &mt('All users');
12401: if ($env{'request.course.id'}) {
1.668 raeburn 12402: $othertitle = &mt('Any users');
1.642 raeburn 12403: }
12404: my @types;
12405: if (ref($order) eq 'ARRAY') {
12406: @types = @{$order};
12407: }
12408: if (@types == 0) {
12409: if (ref($usertypes) eq 'HASH') {
12410: @types = sort(keys(%{$usertypes}));
12411: }
12412: }
12413: if (keys(%{$usertypes}) > 0) {
12414: $othertitle = &mt('Other users');
12415: }
12416: return ($othertitle,$usertypes,\@types);
12417: }
12418:
1.645 raeburn 12419: sub get_institutional_codes {
1.1361 raeburn 12420: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 12421: # Get complete list of course sections to update
12422: my @currsections = ();
12423: my @currxlists = ();
1.1361 raeburn 12424: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 12425: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 12426: my $crskey = $crs.':'.$coursecode;
12427: @{$unclutteredsec{$crskey}} = ();
12428: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 12429:
12430: if ($$settings{'internal.sectionnums'} ne '') {
12431: @currsections = split(/,/,$$settings{'internal.sectionnums'});
12432: }
12433:
12434: if ($$settings{'internal.crosslistings'} ne '') {
12435: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
12436: }
12437:
12438: if (@currxlists > 0) {
1.1361 raeburn 12439: foreach my $xl (@currxlists) {
12440: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 12441: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 12442: push(@{$allcourses},$1);
1.645 raeburn 12443: $$LC_code{$1} = $2;
12444: }
12445: }
12446: }
12447: }
1.1361 raeburn 12448:
1.645 raeburn 12449: if (@currsections > 0) {
1.1361 raeburn 12450: foreach my $sec (@currsections) {
12451: if ($sec =~ m/^(\w+):(\w*)$/ ) {
12452: my $instsec = $1;
1.645 raeburn 12453: my $lc_sec = $2;
1.1361 raeburn 12454: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
12455: push(@{$unclutteredsec{$crskey}},$instsec);
12456: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
12457: }
12458: }
12459: }
12460: }
12461:
12462: if (@{$unclutteredsec{$crskey}} > 0) {
12463: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
12464: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
12465: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
12466: my $sec = $coursecode.$formattedsec{$crskey}[$i];
12467: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 12468: push(@{$allcourses},$sec);
1.1361 raeburn 12469: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 12470: }
12471: }
12472: }
12473: }
12474: return;
12475: }
12476:
1.971 raeburn 12477: sub get_standard_codeitems {
12478: return ('Year','Semester','Department','Number','Section');
12479: }
12480:
1.112 bowersj2 12481: =pod
12482:
1.780 raeburn 12483: =head1 Slot Helpers
12484:
12485: =over 4
12486:
12487: =item * sorted_slots()
12488:
1.1040 raeburn 12489: Sorts an array of slot names in order of an optional sort key,
12490: default sort is by slot start time (earliest first).
1.780 raeburn 12491:
12492: Inputs:
12493:
12494: =over 4
12495:
12496: slotsarr - Reference to array of unsorted slot names.
12497:
12498: slots - Reference to hash of hash, where outer hash keys are slot names.
12499:
1.1040 raeburn 12500: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
12501:
1.549 albertel 12502: =back
12503:
1.780 raeburn 12504: Returns:
12505:
12506: =over 4
12507:
1.1040 raeburn 12508: sorted - An array of slot names sorted by a specified sort key
12509: (default sort key is start time of the slot).
1.780 raeburn 12510:
12511: =back
12512:
12513: =cut
12514:
12515:
12516: sub sorted_slots {
1.1040 raeburn 12517: my ($slotsarr,$slots,$sortkey) = @_;
12518: if ($sortkey eq '') {
12519: $sortkey = 'starttime';
12520: }
1.780 raeburn 12521: my @sorted;
12522: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
12523: @sorted =
12524: sort {
12525: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 12526: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 12527: }
12528: if (ref($slots->{$a})) { return -1;}
12529: if (ref($slots->{$b})) { return 1;}
12530: return 0;
12531: } @{$slotsarr};
12532: }
12533: return @sorted;
12534: }
12535:
1.1040 raeburn 12536: =pod
12537:
12538: =item * get_future_slots()
12539:
12540: Inputs:
12541:
12542: =over 4
12543:
12544: cnum - course number
12545:
12546: cdom - course domain
12547:
12548: now - current UNIX time
12549:
12550: symb - optional symb
12551:
12552: =back
12553:
12554: Returns:
12555:
12556: =over 4
12557:
12558: sorted_reservable - ref to array of student_schedulable slots currently
12559: reservable, ordered by end date of reservation period.
12560:
12561: reservable_now - ref to hash of student_schedulable slots currently
12562: reservable.
12563:
12564: Keys in inner hash are:
12565: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12566: (b) endreserve: end date of reservation period.
12567: (c) uniqueperiod: start,end dates when slot is to be uniquely
12568: selected.
1.1040 raeburn 12569:
12570: sorted_future - ref to array of student_schedulable slots reservable in
12571: the future, ordered by start date of reservation period.
12572:
12573: future_reservable - ref to hash of student_schedulable slots reservable
12574: in the future.
12575:
12576: Keys in inner hash are:
12577: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12578: (b) startreserve: start date of reservation period.
12579: (c) uniqueperiod: start,end dates when slot is to be uniquely
12580: selected.
1.1040 raeburn 12581:
12582: =back
12583:
12584: =cut
12585:
12586: sub get_future_slots {
12587: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 12588: my $map;
12589: if ($symb) {
12590: ($map) = &Apache::lonnet::decode_symb($symb);
12591: }
1.1040 raeburn 12592: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
12593: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
12594: foreach my $slot (keys(%slots)) {
12595: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
12596: if ($symb) {
1.1229 raeburn 12597: if ($slots{$slot}->{'symb'} ne '') {
12598: my $canuse;
12599: my %oksymbs;
12600: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
12601: map { $oksymbs{$_} = 1; } @slotsymbs;
12602: if ($oksymbs{$symb}) {
12603: $canuse = 1;
12604: } else {
12605: foreach my $item (@slotsymbs) {
12606: if ($item =~ /\.(page|sequence)$/) {
12607: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12608: if (($map ne '') && ($map eq $sloturl)) {
12609: $canuse = 1;
12610: last;
12611: }
12612: }
12613: }
12614: }
12615: next unless ($canuse);
12616: }
1.1040 raeburn 12617: }
12618: if (($slots{$slot}->{'starttime'} > $now) &&
12619: ($slots{$slot}->{'endtime'} > $now)) {
12620: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12621: my $userallowed = 0;
12622: if ($slots{$slot}->{'allowedsections'}) {
12623: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12624: if (!defined($env{'request.role.sec'})
12625: && grep(/^No section assigned$/,@allowed_sec)) {
12626: $userallowed=1;
12627: } else {
12628: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12629: $userallowed=1;
12630: }
12631: }
12632: unless ($userallowed) {
12633: if (defined($env{'request.course.groups'})) {
12634: my @groups = split(/:/,$env{'request.course.groups'});
12635: foreach my $group (@groups) {
12636: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12637: $userallowed=1;
12638: last;
12639: }
12640: }
12641: }
12642: }
12643: }
12644: if ($slots{$slot}->{'allowedusers'}) {
12645: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12646: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12647: if (grep(/^\Q$user\E$/,@allowed_users)) {
12648: $userallowed = 1;
12649: }
12650: }
12651: next unless($userallowed);
12652: }
12653: my $startreserve = $slots{$slot}->{'startreserve'};
12654: my $endreserve = $slots{$slot}->{'endreserve'};
12655: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12656: my $uniqueperiod;
12657: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12658: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12659: }
1.1040 raeburn 12660: if (($startreserve < $now) &&
12661: (!$endreserve || $endreserve > $now)) {
12662: my $lastres = $endreserve;
12663: if (!$lastres) {
12664: $lastres = $slots{$slot}->{'starttime'};
12665: }
12666: $reservable_now{$slot} = {
12667: symb => $symb,
1.1250 raeburn 12668: endreserve => $lastres,
12669: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12670: };
12671: } elsif (($startreserve > $now) &&
12672: (!$endreserve || $endreserve > $startreserve)) {
12673: $future_reservable{$slot} = {
12674: symb => $symb,
1.1250 raeburn 12675: startreserve => $startreserve,
12676: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12677: };
12678: }
12679: }
12680: }
12681: my @unsorted_reservable = keys(%reservable_now);
12682: if (@unsorted_reservable > 0) {
12683: @sorted_reservable =
12684: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12685: }
12686: my @unsorted_future = keys(%future_reservable);
12687: if (@unsorted_future > 0) {
12688: @sorted_future =
12689: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12690: }
12691: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12692: }
1.780 raeburn 12693:
12694: =pod
12695:
1.1057 foxr 12696: =back
12697:
1.549 albertel 12698: =head1 HTTP Helpers
12699:
12700: =over 4
12701:
1.648 raeburn 12702: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12703:
1.258 albertel 12704: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12705: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12706: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12707:
12708: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12709: $possible_names is an ref to an array of form element names. As an example:
12710: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12711: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12712:
12713: =cut
1.1 albertel 12714:
1.6 albertel 12715: sub get_unprocessed_cgi {
1.25 albertel 12716: my ($query,$possible_names)= @_;
1.26 matthew 12717: # $Apache::lonxml::debug=1;
1.356 albertel 12718: foreach my $pair (split(/&/,$query)) {
12719: my ($name, $value) = split(/=/,$pair);
1.369 www 12720: $name = &unescape($name);
1.25 albertel 12721: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12722: $value =~ tr/+/ /;
12723: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12724: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12725: }
1.16 harris41 12726: }
1.6 albertel 12727: }
12728:
1.112 bowersj2 12729: =pod
12730:
1.648 raeburn 12731: =item * &cacheheader()
1.112 bowersj2 12732:
12733: returns cache-controlling header code
12734:
12735: =cut
12736:
1.7 albertel 12737: sub cacheheader {
1.258 albertel 12738: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12739: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12740: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12741: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12742: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12743: return $output;
1.7 albertel 12744: }
12745:
1.112 bowersj2 12746: =pod
12747:
1.648 raeburn 12748: =item * &no_cache($r)
1.112 bowersj2 12749:
12750: specifies header code to not have cache
12751:
12752: =cut
12753:
1.9 albertel 12754: sub no_cache {
1.216 albertel 12755: my ($r) = @_;
12756: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12757: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12758: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12759: $r->no_cache(1);
12760: $r->header_out("Expires" => $date);
12761: $r->header_out("Pragma" => "no-cache");
1.123 www 12762: }
12763:
12764: sub content_type {
1.181 albertel 12765: my ($r,$type,$charset) = @_;
1.299 foxr 12766: if ($r) {
12767: # Note that printout.pl calls this with undef for $r.
12768: &no_cache($r);
12769: }
1.258 albertel 12770: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12771: unless ($charset) {
12772: $charset=&Apache::lonlocal::current_encoding;
12773: }
12774: if ($charset) { $type.='; charset='.$charset; }
12775: if ($r) {
12776: $r->content_type($type);
12777: } else {
12778: print("Content-type: $type\n\n");
12779: }
1.9 albertel 12780: }
1.25 albertel 12781:
1.112 bowersj2 12782: =pod
12783:
1.648 raeburn 12784: =item * &add_to_env($name,$value)
1.112 bowersj2 12785:
1.258 albertel 12786: adds $name to the %env hash with value
1.112 bowersj2 12787: $value, if $name already exists, the entry is converted to an array
12788: reference and $value is added to the array.
12789:
12790: =cut
12791:
1.25 albertel 12792: sub add_to_env {
12793: my ($name,$value)=@_;
1.258 albertel 12794: if (defined($env{$name})) {
12795: if (ref($env{$name})) {
1.25 albertel 12796: #already have multiple values
1.258 albertel 12797: push(@{ $env{$name} },$value);
1.25 albertel 12798: } else {
12799: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12800: my $first=$env{$name};
12801: undef($env{$name});
12802: push(@{ $env{$name} },$first,$value);
1.25 albertel 12803: }
12804: } else {
1.258 albertel 12805: $env{$name}=$value;
1.25 albertel 12806: }
1.31 albertel 12807: }
1.149 albertel 12808:
12809: =pod
12810:
1.648 raeburn 12811: =item * &get_env_multiple($name)
1.149 albertel 12812:
1.258 albertel 12813: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12814: values may be defined and end up as an array ref.
12815:
12816: returns an array of values
12817:
12818: =cut
12819:
12820: sub get_env_multiple {
12821: my ($name) = @_;
12822: my @values;
1.258 albertel 12823: if (defined($env{$name})) {
1.149 albertel 12824: # exists is it an array
1.258 albertel 12825: if (ref($env{$name})) {
12826: @values=@{ $env{$name} };
1.149 albertel 12827: } else {
1.258 albertel 12828: $values[0]=$env{$name};
1.149 albertel 12829: }
12830: }
12831: return(@values);
12832: }
12833:
1.1249 damieng 12834: # Looks at given dependencies, and returns something depending on the context.
12835: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12836: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12837: # For all other contexts, returns ($output, $counter, $numpathchg).
12838: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12839: # $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
12840: # $numpathchg: integer with the number of cleaned up dependency paths.
12841: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12842: # \%mapping: hash reference clean path -> original path for all dependencies.
12843: # @param {string} actionurl - The path to the handler, indicative of the context.
12844: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12845: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12846: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12847: # @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
12848: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12849: sub ask_for_embedded_content {
1.1249 damieng 12850: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12851: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12852: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12853: %currsubfile,%unused,$rem);
1.1071 raeburn 12854: my $counter = 0;
12855: my $numnew = 0;
1.987 raeburn 12856: my $numremref = 0;
12857: my $numinvalid = 0;
12858: my $numpathchg = 0;
12859: my $numexisting = 0;
1.1071 raeburn 12860: my $numunused = 0;
12861: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12862: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12863: my $heading = &mt('Upload embedded files');
12864: my $buttontext = &mt('Upload');
12865:
1.1249 damieng 12866: # fills these variables based on the context:
12867: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12868: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12869: if ($env{'request.course.id'}) {
1.1123 raeburn 12870: if ($actionurl eq '/adm/dependencies') {
12871: $navmap = Apache::lonnavmaps::navmap->new();
12872: }
12873: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12874: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12875: }
1.1123 raeburn 12876: if (($actionurl eq '/adm/portfolio') ||
12877: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12878: my $current_path='/';
12879: if ($env{'form.currentpath'}) {
12880: $current_path = $env{'form.currentpath'};
12881: }
12882: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12883: $udom = $cdom;
12884: $uname = $cnum;
1.984 raeburn 12885: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12886: } else {
12887: $udom = $env{'user.domain'};
12888: $uname = $env{'user.name'};
12889: $url = '/userfiles/portfolio';
12890: }
1.987 raeburn 12891: $toplevel = $url.'/';
1.984 raeburn 12892: $url .= $current_path;
12893: $getpropath = 1;
1.987 raeburn 12894: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12895: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12896: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12897: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12898: $toplevel = $url;
1.984 raeburn 12899: if ($rest ne '') {
1.987 raeburn 12900: $url .= $rest;
12901: }
12902: } elsif ($actionurl eq '/adm/coursedocs') {
12903: if (ref($args) eq 'HASH') {
1.1071 raeburn 12904: $url = $args->{'docs_url'};
12905: $toplevel = $url;
1.1084 raeburn 12906: if ($args->{'context'} eq 'paste') {
12907: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12908: ($path) =
12909: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12910: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12911: $fileloc =~ s{^/}{};
12912: }
1.1071 raeburn 12913: }
1.1084 raeburn 12914: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12915: if ($env{'request.course.id'} ne '') {
12916: if (ref($args) eq 'HASH') {
12917: $url = $args->{'docs_url'};
12918: $title = $args->{'docs_title'};
1.1126 raeburn 12919: $toplevel = $url;
12920: unless ($toplevel =~ m{^/}) {
12921: $toplevel = "/$url";
12922: }
1.1085 raeburn 12923: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12924: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12925: $path = $1;
12926: } else {
12927: ($path) =
12928: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12929: }
1.1195 raeburn 12930: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12931: $fileloc = $toplevel;
12932: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12933: my ($udom,$uname,$fname) =
12934: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12935: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12936: } else {
12937: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12938: }
1.1071 raeburn 12939: $fileloc =~ s{^/}{};
12940: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12941: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12942: }
1.987 raeburn 12943: }
1.1123 raeburn 12944: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12945: $udom = $cdom;
12946: $uname = $cnum;
12947: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12948: $toplevel = $url;
12949: $path = $url;
12950: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12951: $fileloc =~ s{^/}{};
1.987 raeburn 12952: }
1.1249 damieng 12953:
12954: # parses the dependency paths to get some info
12955: # fills $newfiles, $mapping, $subdependencies, $dependencies
12956: # $newfiles: hash URL -> 1 for new files or external URLs
12957: # (will be completed later)
12958: # $mapping:
12959: # for external URLs: external URL -> external URL
12960: # for relative paths: clean path -> original path
12961: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12962: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12963: foreach my $file (keys(%{$allfiles})) {
12964: my $embed_file;
12965: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12966: $embed_file = $1;
12967: } else {
12968: $embed_file = $file;
12969: }
1.1158 raeburn 12970: my ($absolutepath,$cleaned_file);
12971: if ($embed_file =~ m{^\w+://}) {
12972: $cleaned_file = $embed_file;
1.1147 raeburn 12973: $newfiles{$cleaned_file} = 1;
12974: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12975: } else {
1.1158 raeburn 12976: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12977: if ($embed_file =~ m{^/}) {
12978: $absolutepath = $embed_file;
12979: }
1.1147 raeburn 12980: if ($cleaned_file =~ m{/}) {
12981: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12982: $path = &check_for_traversal($path,$url,$toplevel);
12983: my $item = $fname;
12984: if ($path ne '') {
12985: $item = $path.'/'.$fname;
12986: $subdependencies{$path}{$fname} = 1;
12987: } else {
12988: $dependencies{$item} = 1;
12989: }
12990: if ($absolutepath) {
12991: $mapping{$item} = $absolutepath;
12992: } else {
12993: $mapping{$item} = $embed_file;
12994: }
12995: } else {
12996: $dependencies{$embed_file} = 1;
12997: if ($absolutepath) {
1.1147 raeburn 12998: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12999: } else {
1.1147 raeburn 13000: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 13001: }
13002: }
1.984 raeburn 13003: }
13004: }
1.1249 damieng 13005:
13006: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
13007: # and lists
13008: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
13009: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
13010: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
13011: # the path had to be cleaned up
13012: # $existing: hash clean path -> 1 if the file exists
13013: # $numexisting: number of keys in $existing
13014: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
13015: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
13016: # dependency subdirectories that are
13017: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 13018: my $dirptr = 16384;
1.984 raeburn 13019: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 13020: $currsubfile{$path} = {};
1.1123 raeburn 13021: if (($actionurl eq '/adm/portfolio') ||
13022: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 13023: my ($sublistref,$listerror) =
13024: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
13025: if (ref($sublistref) eq 'ARRAY') {
13026: foreach my $line (@{$sublistref}) {
13027: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 13028: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 13029: }
1.984 raeburn 13030: }
1.987 raeburn 13031: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 13032: if (opendir(my $dir,$url.'/'.$path)) {
13033: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 13034: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
13035: }
1.1084 raeburn 13036: } elsif (($actionurl eq '/adm/dependencies') ||
13037: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 13038: ($args->{'context'} eq 'paste')) ||
13039: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 13040: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 13041: my $dir;
13042: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
13043: $dir = $fileloc;
13044: } else {
13045: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
13046: }
1.1071 raeburn 13047: if ($dir ne '') {
13048: my ($sublistref,$listerror) =
13049: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
13050: if (ref($sublistref) eq 'ARRAY') {
13051: foreach my $line (@{$sublistref}) {
13052: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
13053: undef,$mtime)=split(/\&/,$line,12);
13054: unless (($testdir&$dirptr) ||
13055: ($file_name =~ /^\.\.?$/)) {
13056: $currsubfile{$path}{$file_name} = [$size,$mtime];
13057: }
13058: }
13059: }
13060: }
1.984 raeburn 13061: }
13062: }
13063: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 13064: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 13065: my $item = $path.'/'.$file;
13066: unless ($mapping{$item} eq $item) {
13067: $pathchanges{$item} = 1;
13068: }
13069: $existing{$item} = 1;
13070: $numexisting ++;
13071: } else {
13072: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 13073: }
13074: }
1.1071 raeburn 13075: if ($actionurl eq '/adm/dependencies') {
13076: foreach my $path (keys(%currsubfile)) {
13077: if (ref($currsubfile{$path}) eq 'HASH') {
13078: foreach my $file (keys(%{$currsubfile{$path}})) {
13079: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 13080: next if (($rem ne '') &&
13081: (($env{"httpref.$rem"."$path/$file"} ne '') ||
13082: (ref($navmap) &&
13083: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
13084: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
13085: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 13086: $unused{$path.'/'.$file} = 1;
13087: }
13088: }
13089: }
13090: }
13091: }
1.984 raeburn 13092: }
1.1249 damieng 13093:
13094: # fills $currfile, hash file name -> 1 or [$size,$mtime]
13095: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 13096: my %currfile;
1.1123 raeburn 13097: if (($actionurl eq '/adm/portfolio') ||
13098: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 13099: my ($dirlistref,$listerror) =
13100: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
13101: if (ref($dirlistref) eq 'ARRAY') {
13102: foreach my $line (@{$dirlistref}) {
13103: my ($file_name,$rest) = split(/\&/,$line,2);
13104: $currfile{$file_name} = 1;
13105: }
1.984 raeburn 13106: }
1.987 raeburn 13107: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 13108: if (opendir(my $dir,$url)) {
1.987 raeburn 13109: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 13110: map {$currfile{$_} = 1;} @dir_list;
13111: }
1.1084 raeburn 13112: } elsif (($actionurl eq '/adm/dependencies') ||
13113: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 13114: ($args->{'context'} eq 'paste')) ||
13115: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 13116: if ($env{'request.course.id'} ne '') {
13117: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
13118: if ($dir ne '') {
13119: my ($dirlistref,$listerror) =
13120: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
13121: if (ref($dirlistref) eq 'ARRAY') {
13122: foreach my $line (@{$dirlistref}) {
13123: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
13124: $size,undef,$mtime)=split(/\&/,$line,12);
13125: unless (($testdir&$dirptr) ||
13126: ($file_name =~ /^\.\.?$/)) {
13127: $currfile{$file_name} = [$size,$mtime];
13128: }
13129: }
13130: }
13131: }
13132: }
1.984 raeburn 13133: }
1.1249 damieng 13134: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
13135: # are not in subdirectories, using $currfile
1.984 raeburn 13136: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 13137: if (exists($currfile{$file})) {
1.987 raeburn 13138: unless ($mapping{$file} eq $file) {
13139: $pathchanges{$file} = 1;
13140: }
13141: $existing{$file} = 1;
13142: $numexisting ++;
13143: } else {
1.984 raeburn 13144: $newfiles{$file} = 1;
13145: }
13146: }
1.1071 raeburn 13147: foreach my $file (keys(%currfile)) {
13148: unless (($file eq $filename) ||
13149: ($file eq $filename.'.bak') ||
13150: ($dependencies{$file})) {
1.1085 raeburn 13151: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 13152: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
13153: next if (($rem ne '') &&
13154: (($env{"httpref.$rem".$file} ne '') ||
13155: (ref($navmap) &&
13156: (($navmap->getResourceByUrl($rem.$file) ne '') ||
13157: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
13158: ($navmap->getResourceByUrl($rem.$1)))))));
13159: }
1.1085 raeburn 13160: }
1.1071 raeburn 13161: $unused{$file} = 1;
13162: }
13163: }
1.1249 damieng 13164:
13165: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 13166: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
13167: ($args->{'context'} eq 'paste')) {
13168: $counter = scalar(keys(%existing));
13169: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 13170: return ($output,$counter,$numpathchg,\%existing);
13171: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
13172: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
13173: $counter = scalar(keys(%existing));
13174: $numpathchg = scalar(keys(%pathchanges));
13175: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 13176: }
1.1249 damieng 13177:
13178: # returns HTML otherwise, with dependency results and to ask for more uploads
13179:
13180: # $upload_output: missing dependencies (with upload form)
13181: # $modify_output: uploaded dependencies (in use)
13182: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 13183: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 13184: if ($actionurl eq '/adm/dependencies') {
13185: next if ($embed_file =~ m{^\w+://});
13186: }
1.660 raeburn 13187: $upload_output .= &start_data_table_row().
1.1123 raeburn 13188: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 13189: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 13190: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 13191: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
13192: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 13193: }
1.1123 raeburn 13194: $upload_output .= '</td>';
1.1071 raeburn 13195: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 13196: $upload_output.='<td align="right">'.
13197: '<span class="LC_info LC_fontsize_medium">'.
13198: &mt("URL points to web address").'</span>';
1.987 raeburn 13199: $numremref++;
1.660 raeburn 13200: } elsif ($args->{'error_on_invalid_names'}
13201: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 13202: $upload_output.='<td align="right"><span class="LC_warning">'.
13203: &mt('Invalid characters').'</span>';
1.987 raeburn 13204: $numinvalid++;
1.660 raeburn 13205: } else {
1.1123 raeburn 13206: $upload_output .= '<td>'.
13207: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 13208: $embed_file,\%mapping,
1.1071 raeburn 13209: $allfiles,$codebase,'upload');
13210: $counter ++;
13211: $numnew ++;
1.987 raeburn 13212: }
13213: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
13214: }
13215: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 13216: if ($actionurl eq '/adm/dependencies') {
13217: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
13218: $modify_output .= &start_data_table_row().
13219: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
13220: '<img src="'.&icon($embed_file).'" border="0" />'.
13221: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
13222: '<td>'.$size.'</td>'.
13223: '<td>'.$mtime.'</td>'.
13224: '<td><label><input type="checkbox" name="mod_upload_dep" '.
13225: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
13226: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
13227: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
13228: &embedded_file_element('upload_embedded',$counter,
13229: $embed_file,\%mapping,
13230: $allfiles,$codebase,'modify').
13231: '</div></td>'.
13232: &end_data_table_row()."\n";
13233: $counter ++;
13234: } else {
13235: $upload_output .= &start_data_table_row().
1.1123 raeburn 13236: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
13237: '<span class="LC_filename">'.$embed_file.'</span></td>'.
13238: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 13239: &Apache::loncommon::end_data_table_row()."\n";
13240: }
13241: }
13242: my $delidx = $counter;
13243: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
13244: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
13245: $delete_output .= &start_data_table_row().
13246: '<td><img src="'.&icon($oldfile).'" />'.
13247: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
13248: '<td>'.$size.'</td>'.
13249: '<td>'.$mtime.'</td>'.
13250: '<td><label><input type="checkbox" name="del_upload_dep" '.
13251: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
13252: &embedded_file_element('upload_embedded',$delidx,
13253: $oldfile,\%mapping,$allfiles,
13254: $codebase,'delete').'</td>'.
13255: &end_data_table_row()."\n";
13256: $numunused ++;
13257: $delidx ++;
1.987 raeburn 13258: }
13259: if ($upload_output) {
13260: $upload_output = &start_data_table().
13261: $upload_output.
13262: &end_data_table()."\n";
13263: }
1.1071 raeburn 13264: if ($modify_output) {
13265: $modify_output = &start_data_table().
13266: &start_data_table_header_row().
13267: '<th>'.&mt('File').'</th>'.
13268: '<th>'.&mt('Size (KB)').'</th>'.
13269: '<th>'.&mt('Modified').'</th>'.
13270: '<th>'.&mt('Upload replacement?').'</th>'.
13271: &end_data_table_header_row().
13272: $modify_output.
13273: &end_data_table()."\n";
13274: }
13275: if ($delete_output) {
13276: $delete_output = &start_data_table().
13277: &start_data_table_header_row().
13278: '<th>'.&mt('File').'</th>'.
13279: '<th>'.&mt('Size (KB)').'</th>'.
13280: '<th>'.&mt('Modified').'</th>'.
13281: '<th>'.&mt('Delete?').'</th>'.
13282: &end_data_table_header_row().
13283: $delete_output.
13284: &end_data_table()."\n";
13285: }
1.987 raeburn 13286: my $applies = 0;
13287: if ($numremref) {
13288: $applies ++;
13289: }
13290: if ($numinvalid) {
13291: $applies ++;
13292: }
13293: if ($numexisting) {
13294: $applies ++;
13295: }
1.1071 raeburn 13296: if ($counter || $numunused) {
1.987 raeburn 13297: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
13298: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 13299: $state.'<h3>'.$heading.'</h3>';
13300: if ($actionurl eq '/adm/dependencies') {
13301: if ($numnew) {
13302: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
13303: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
13304: $upload_output.'<br />'."\n";
13305: }
13306: if ($numexisting) {
13307: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
13308: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
13309: $modify_output.'<br />'."\n";
13310: $buttontext = &mt('Save changes');
13311: }
13312: if ($numunused) {
13313: $output .= '<h4>'.&mt('Unused files').'</h4>'.
13314: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
13315: $delete_output.'<br />'."\n";
13316: $buttontext = &mt('Save changes');
13317: }
13318: } else {
13319: $output .= $upload_output.'<br />'."\n";
13320: }
13321: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
13322: $counter.'" />'."\n";
13323: if ($actionurl eq '/adm/dependencies') {
13324: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
13325: $numnew.'" />'."\n";
13326: } elsif ($actionurl eq '') {
1.987 raeburn 13327: $output .= '<input type="hidden" name="phase" value="three" />';
13328: }
13329: } elsif ($applies) {
13330: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
13331: if ($applies > 1) {
13332: $output .=
1.1123 raeburn 13333: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 13334: if ($numremref) {
13335: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
13336: }
13337: if ($numinvalid) {
13338: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
13339: }
13340: if ($numexisting) {
13341: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
13342: }
13343: $output .= '</ul><br />';
13344: } elsif ($numremref) {
13345: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
13346: } elsif ($numinvalid) {
13347: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
13348: } elsif ($numexisting) {
13349: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
13350: }
13351: $output .= $upload_output.'<br />';
13352: }
13353: my ($pathchange_output,$chgcount);
1.1071 raeburn 13354: $chgcount = $counter;
1.987 raeburn 13355: if (keys(%pathchanges) > 0) {
13356: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 13357: if ($counter) {
1.987 raeburn 13358: $output .= &embedded_file_element('pathchange',$chgcount,
13359: $embed_file,\%mapping,
1.1071 raeburn 13360: $allfiles,$codebase,'change');
1.987 raeburn 13361: } else {
13362: $pathchange_output .=
13363: &start_data_table_row().
13364: '<td><input type ="checkbox" name="namechange" value="'.
13365: $chgcount.'" checked="checked" /></td>'.
13366: '<td>'.$mapping{$embed_file}.'</td>'.
13367: '<td>'.$embed_file.
13368: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 13369: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 13370: '</td>'.&end_data_table_row();
1.660 raeburn 13371: }
1.987 raeburn 13372: $numpathchg ++;
13373: $chgcount ++;
1.660 raeburn 13374: }
13375: }
1.1127 raeburn 13376: if (($counter) || ($numunused)) {
1.987 raeburn 13377: if ($numpathchg) {
13378: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
13379: $numpathchg.'" />'."\n";
13380: }
13381: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
13382: ($actionurl eq '/adm/imsimport')) {
13383: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
13384: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
13385: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 13386: } elsif ($actionurl eq '/adm/dependencies') {
13387: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 13388: }
1.1123 raeburn 13389: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 13390: } elsif ($numpathchg) {
13391: my %pathchange = ();
13392: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
13393: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13394: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 13395: }
1.987 raeburn 13396: }
1.1071 raeburn 13397: return ($output,$counter,$numpathchg);
1.987 raeburn 13398: }
13399:
1.1147 raeburn 13400: =pod
13401:
13402: =item * clean_path($name)
13403:
13404: Performs clean-up of directories, subdirectories and filename in an
13405: embedded object, referenced in an HTML file which is being uploaded
13406: to a course or portfolio, where
13407: "Upload embedded images/multimedia files if HTML file" checkbox was
13408: checked.
13409:
13410: Clean-up is similar to replacements in lonnet::clean_filename()
13411: except each / between sub-directory and next level is preserved.
13412:
13413: =cut
13414:
13415: sub clean_path {
13416: my ($embed_file) = @_;
13417: $embed_file =~s{^/+}{};
13418: my @contents;
13419: if ($embed_file =~ m{/}) {
13420: @contents = split(/\//,$embed_file);
13421: } else {
13422: @contents = ($embed_file);
13423: }
13424: my $lastidx = scalar(@contents)-1;
13425: for (my $i=0; $i<=$lastidx; $i++) {
13426: $contents[$i]=~s{\\}{/}g;
13427: $contents[$i]=~s/\s+/\_/g;
13428: $contents[$i]=~s{[^/\w\.\-]}{}g;
13429: if ($i == $lastidx) {
13430: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
13431: }
13432: }
13433: if ($lastidx > 0) {
13434: return join('/',@contents);
13435: } else {
13436: return $contents[0];
13437: }
13438: }
13439:
1.987 raeburn 13440: sub embedded_file_element {
1.1071 raeburn 13441: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 13442: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
13443: (ref($codebase) eq 'HASH'));
13444: my $output;
1.1071 raeburn 13445: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 13446: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
13447: }
13448: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
13449: &escape($embed_file).'" />';
13450: unless (($context eq 'upload_embedded') &&
13451: ($mapping->{$embed_file} eq $embed_file)) {
13452: $output .='
13453: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
13454: }
13455: my $attrib;
13456: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
13457: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
13458: }
13459: $output .=
13460: "\n\t\t".
13461: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
13462: $attrib.'" />';
13463: if (exists($codebase->{$mapping->{$embed_file}})) {
13464: $output .=
13465: "\n\t\t".
13466: '<input name="codebase_'.$num.'" type="hidden" value="'.
13467: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 13468: }
1.987 raeburn 13469: return $output;
1.660 raeburn 13470: }
13471:
1.1071 raeburn 13472: sub get_dependency_details {
13473: my ($currfile,$currsubfile,$embed_file) = @_;
13474: my ($size,$mtime,$showsize,$showmtime);
13475: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
13476: if ($embed_file =~ m{/}) {
13477: my ($path,$fname) = split(/\//,$embed_file);
13478: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
13479: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
13480: }
13481: } else {
13482: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
13483: ($size,$mtime) = @{$currfile->{$embed_file}};
13484: }
13485: }
13486: $showsize = $size/1024.0;
13487: $showsize = sprintf("%.1f",$showsize);
13488: if ($mtime > 0) {
13489: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
13490: }
13491: }
13492: return ($showsize,$showmtime);
13493: }
13494:
13495: sub ask_embedded_js {
13496: return <<"END";
13497: <script type="text/javascript"">
13498: // <![CDATA[
13499: function toggleBrowse(counter) {
13500: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
13501: var fileid = document.getElementById('embedded_item_'+counter);
13502: var uploaddivid = document.getElementById('moduploaddep_'+counter);
13503: if (chkboxid.checked == true) {
13504: uploaddivid.style.display='block';
13505: } else {
13506: uploaddivid.style.display='none';
13507: fileid.value = '';
13508: }
13509: }
13510: // ]]>
13511: </script>
13512:
13513: END
13514: }
13515:
1.661 raeburn 13516: sub upload_embedded {
13517: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 13518: $current_disk_usage,$hiddenstate,$actionurl) = @_;
13519: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 13520: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
13521: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
13522: my $orig_uploaded_filename =
13523: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 13524: foreach my $type ('orig','ref','attrib','codebase') {
13525: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
13526: $env{'form.embedded_'.$type.'_'.$i} =
13527: &unescape($env{'form.embedded_'.$type.'_'.$i});
13528: }
13529: }
1.661 raeburn 13530: my ($path,$fname) =
13531: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
13532: # no path, whole string is fname
13533: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
13534: $fname = &Apache::lonnet::clean_filename($fname);
13535: # See if there is anything left
13536: next if ($fname eq '');
13537:
13538: # Check if file already exists as a file or directory.
13539: my ($state,$msg);
13540: if ($context eq 'portfolio') {
13541: my $port_path = $dirpath;
13542: if ($group ne '') {
13543: $port_path = "groups/$group/$port_path";
13544: }
1.987 raeburn 13545: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
13546: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 13547: $dir_root,$port_path,$disk_quota,
13548: $current_disk_usage,$uname,$udom);
13549: if ($state eq 'will_exceed_quota'
1.984 raeburn 13550: || $state eq 'file_locked') {
1.661 raeburn 13551: $output .= $msg;
13552: next;
13553: }
13554: } elsif (($context eq 'author') || ($context eq 'testbank')) {
13555: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
13556: if ($state eq 'exists') {
13557: $output .= $msg;
13558: next;
13559: }
13560: }
13561: # Check if extension is valid
13562: if (($fname =~ /\.(\w+)$/) &&
13563: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 13564: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
13565: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 13566: next;
13567: } elsif (($fname =~ /\.(\w+)$/) &&
13568: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 13569: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 13570: next;
13571: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 13572: $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 13573: next;
13574: }
13575: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 13576: my $subdir = $path;
13577: $subdir =~ s{/+$}{};
1.661 raeburn 13578: if ($context eq 'portfolio') {
1.984 raeburn 13579: my $result;
13580: if ($state eq 'existingfile') {
13581: $result=
13582: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 13583: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 13584: } else {
1.984 raeburn 13585: $result=
13586: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 13587: $dirpath.
1.1123 raeburn 13588: $env{'form.currentpath'}.$subdir);
1.984 raeburn 13589: if ($result !~ m|^/uploaded/|) {
13590: $output .= '<span class="LC_error">'
13591: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13592: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13593: .'</span><br />';
13594: next;
13595: } else {
1.987 raeburn 13596: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13597: $path.$fname.'</span>').'<br />';
1.984 raeburn 13598: }
1.661 raeburn 13599: }
1.1123 raeburn 13600: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 13601: my $extendedsubdir = $dirpath.'/'.$subdir;
13602: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 13603: my $result =
1.1126 raeburn 13604: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13605: if ($result !~ m|^/uploaded/|) {
13606: $output .= '<span class="LC_error">'
13607: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13608: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13609: .'</span><br />';
13610: next;
13611: } else {
13612: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13613: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13614: if ($context eq 'syllabus') {
13615: &Apache::lonnet::make_public_indefinitely($result);
13616: }
1.987 raeburn 13617: }
1.661 raeburn 13618: } else {
13619: # Save the file
13620: my $target = $env{'form.embedded_item_'.$i};
13621: my $fullpath = $dir_root.$dirpath.'/'.$path;
13622: my $dest = $fullpath.$fname;
13623: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13624: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13625: my $count;
13626: my $filepath = $dir_root;
1.1027 raeburn 13627: foreach my $subdir (@parts) {
13628: $filepath .= "/$subdir";
13629: if (!-e $filepath) {
1.661 raeburn 13630: mkdir($filepath,0770);
13631: }
13632: }
13633: my $fh;
13634: if (!open($fh,'>'.$dest)) {
13635: &Apache::lonnet::logthis('Failed to create '.$dest);
13636: $output .= '<span class="LC_error">'.
1.1071 raeburn 13637: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13638: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13639: '</span><br />';
13640: } else {
13641: if (!print $fh $env{'form.embedded_item_'.$i}) {
13642: &Apache::lonnet::logthis('Failed to write to '.$dest);
13643: $output .= '<span class="LC_error">'.
1.1071 raeburn 13644: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13645: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13646: '</span><br />';
13647: } else {
1.987 raeburn 13648: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13649: $url.'</span>').'<br />';
13650: unless ($context eq 'testbank') {
13651: $footer .= &mt('View embedded file: [_1]',
13652: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13653: }
13654: }
13655: close($fh);
13656: }
13657: }
13658: if ($env{'form.embedded_ref_'.$i}) {
13659: $pathchange{$i} = 1;
13660: }
13661: }
13662: if ($output) {
13663: $output = '<p>'.$output.'</p>';
13664: }
13665: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13666: $returnflag = 'ok';
1.1071 raeburn 13667: my $numpathchgs = scalar(keys(%pathchange));
13668: if ($numpathchgs > 0) {
1.987 raeburn 13669: if ($context eq 'portfolio') {
13670: $output .= '<p>'.&mt('or').'</p>';
13671: } elsif ($context eq 'testbank') {
1.1071 raeburn 13672: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13673: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13674: $returnflag = 'modify_orightml';
13675: }
13676: }
1.1071 raeburn 13677: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13678: }
13679:
13680: sub modify_html_form {
13681: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13682: my $end = 0;
13683: my $modifyform;
13684: if ($context eq 'upload_embedded') {
13685: return unless (ref($pathchange) eq 'HASH');
13686: if ($env{'form.number_embedded_items'}) {
13687: $end += $env{'form.number_embedded_items'};
13688: }
13689: if ($env{'form.number_pathchange_items'}) {
13690: $end += $env{'form.number_pathchange_items'};
13691: }
13692: if ($end) {
13693: for (my $i=0; $i<$end; $i++) {
13694: if ($i < $env{'form.number_embedded_items'}) {
13695: next unless($pathchange->{$i});
13696: }
13697: $modifyform .=
13698: &start_data_table_row().
13699: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13700: 'checked="checked" /></td>'.
13701: '<td>'.$env{'form.embedded_ref_'.$i}.
13702: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13703: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13704: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13705: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13706: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13707: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13708: '<td>'.$env{'form.embedded_orig_'.$i}.
13709: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13710: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13711: &end_data_table_row();
1.1071 raeburn 13712: }
1.987 raeburn 13713: }
13714: } else {
13715: $modifyform = $pathchgtable;
13716: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13717: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13718: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13719: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13720: }
13721: }
13722: if ($modifyform) {
1.1071 raeburn 13723: if ($actionurl eq '/adm/dependencies') {
13724: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13725: }
1.987 raeburn 13726: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13727: '<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".
13728: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13729: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13730: '</ol></p>'."\n".'<p>'.
13731: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13732: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13733: &start_data_table()."\n".
13734: &start_data_table_header_row().
13735: '<th>'.&mt('Change?').'</th>'.
13736: '<th>'.&mt('Current reference').'</th>'.
13737: '<th>'.&mt('Required reference').'</th>'.
13738: &end_data_table_header_row()."\n".
13739: $modifyform.
13740: &end_data_table().'<br />'."\n".$hiddenstate.
13741: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13742: '</form>'."\n";
13743: }
13744: return;
13745: }
13746:
13747: sub modify_html_refs {
1.1123 raeburn 13748: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13749: my $container;
13750: if ($context eq 'portfolio') {
13751: $container = $env{'form.container'};
13752: } elsif ($context eq 'coursedoc') {
13753: $container = $env{'form.primaryurl'};
1.1071 raeburn 13754: } elsif ($context eq 'manage_dependencies') {
13755: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13756: $container = "/$container";
1.1123 raeburn 13757: } elsif ($context eq 'syllabus') {
13758: $container = $url;
1.987 raeburn 13759: } else {
1.1027 raeburn 13760: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13761: }
13762: my (%allfiles,%codebase,$output,$content);
13763: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13764: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13765: if (wantarray) {
13766: return ('',0,0);
13767: } else {
13768: return;
13769: }
13770: }
13771: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13772: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13773: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13774: if (wantarray) {
13775: return ('',0,0);
13776: } else {
13777: return;
13778: }
13779: }
1.987 raeburn 13780: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13781: if ($content eq '-1') {
13782: if (wantarray) {
13783: return ('',0,0);
13784: } else {
13785: return;
13786: }
13787: }
1.987 raeburn 13788: } else {
1.1071 raeburn 13789: unless ($container =~ /^\Q$dir_root\E/) {
13790: if (wantarray) {
13791: return ('',0,0);
13792: } else {
13793: return;
13794: }
13795: }
1.1317 raeburn 13796: if (open(my $fh,'<',$container)) {
1.987 raeburn 13797: $content = join('', <$fh>);
13798: close($fh);
13799: } else {
1.1071 raeburn 13800: if (wantarray) {
13801: return ('',0,0);
13802: } else {
13803: return;
13804: }
1.987 raeburn 13805: }
13806: }
13807: my ($count,$codebasecount) = (0,0);
13808: my $mm = new File::MMagic;
13809: my $mime_type = $mm->checktype_contents($content);
13810: if ($mime_type eq 'text/html') {
13811: my $parse_result =
13812: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13813: \%codebase,\$content);
13814: if ($parse_result eq 'ok') {
13815: foreach my $i (@changes) {
13816: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13817: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13818: if ($allfiles{$ref}) {
13819: my $newname = $orig;
13820: my ($attrib_regexp,$codebase);
1.1006 raeburn 13821: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13822: if ($attrib_regexp =~ /:/) {
13823: $attrib_regexp =~ s/\:/|/g;
13824: }
13825: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13826: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13827: $count += $numchg;
1.1123 raeburn 13828: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13829: delete($allfiles{$ref});
1.987 raeburn 13830: }
13831: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13832: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13833: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13834: $codebasecount ++;
13835: }
13836: }
13837: }
1.1123 raeburn 13838: my $skiprewrites;
1.987 raeburn 13839: if ($count || $codebasecount) {
13840: my $saveresult;
1.1071 raeburn 13841: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13842: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13843: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13844: if ($url eq $container) {
13845: my ($fname) = ($container =~ m{/([^/]+)$});
13846: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13847: $count,'<span class="LC_filename">'.
1.1071 raeburn 13848: $fname.'</span>').'</p>';
1.987 raeburn 13849: } else {
13850: $output = '<p class="LC_error">'.
13851: &mt('Error: update failed for: [_1].',
13852: '<span class="LC_filename">'.
13853: $container.'</span>').'</p>';
13854: }
1.1123 raeburn 13855: if ($context eq 'syllabus') {
13856: unless ($saveresult eq 'ok') {
13857: $skiprewrites = 1;
13858: }
13859: }
1.987 raeburn 13860: } else {
1.1317 raeburn 13861: if (open(my $fh,'>',$container)) {
1.987 raeburn 13862: print $fh $content;
13863: close($fh);
13864: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13865: $count,'<span class="LC_filename">'.
13866: $container.'</span>').'</p>';
1.661 raeburn 13867: } else {
1.987 raeburn 13868: $output = '<p class="LC_error">'.
13869: &mt('Error: could not update [_1].',
13870: '<span class="LC_filename">'.
13871: $container.'</span>').'</p>';
1.661 raeburn 13872: }
13873: }
13874: }
1.1123 raeburn 13875: if (($context eq 'syllabus') && (!$skiprewrites)) {
13876: my ($actionurl,$state);
13877: $actionurl = "/public/$udom/$uname/syllabus";
13878: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13879: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13880: \%codebase,
13881: {'context' => 'rewrites',
13882: 'ignore_remote_references' => 1,});
13883: if (ref($mapping) eq 'HASH') {
13884: my $rewrites = 0;
13885: foreach my $key (keys(%{$mapping})) {
13886: next if ($key =~ m{^https?://});
13887: my $ref = $mapping->{$key};
13888: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13889: my $attrib;
13890: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13891: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13892: }
13893: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13894: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13895: $rewrites += $numchg;
13896: }
13897: }
13898: if ($rewrites) {
13899: my $saveresult;
13900: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13901: if ($url eq $container) {
13902: my ($fname) = ($container =~ m{/([^/]+)$});
13903: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13904: $count,'<span class="LC_filename">'.
13905: $fname.'</span>').'</p>';
13906: } else {
13907: $output .= '<p class="LC_error">'.
13908: &mt('Error: could not update links in [_1].',
13909: '<span class="LC_filename">'.
13910: $container.'</span>').'</p>';
13911:
13912: }
13913: }
13914: }
13915: }
1.987 raeburn 13916: } else {
13917: &logthis('Failed to parse '.$container.
13918: ' to modify references: '.$parse_result);
1.661 raeburn 13919: }
13920: }
1.1071 raeburn 13921: if (wantarray) {
13922: return ($output,$count,$codebasecount);
13923: } else {
13924: return $output;
13925: }
1.661 raeburn 13926: }
13927:
13928: sub check_for_existing {
13929: my ($path,$fname,$element) = @_;
13930: my ($state,$msg);
13931: if (-d $path.'/'.$fname) {
13932: $state = 'exists';
13933: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13934: } elsif (-e $path.'/'.$fname) {
13935: $state = 'exists';
13936: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13937: }
13938: if ($state eq 'exists') {
13939: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13940: }
13941: return ($state,$msg);
13942: }
13943:
13944: sub check_for_upload {
13945: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13946: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13947: my $filesize = length($env{'form.'.$element});
13948: if (!$filesize) {
13949: my $msg = '<span class="LC_error">'.
13950: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13951: '<span class="LC_filename">'.$fname.'</span>',
13952: $filesize).'<br />'.
1.1007 raeburn 13953: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13954: '</span>';
13955: return ('zero_bytes',$msg);
13956: }
13957: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13958: my $getpropath = 1;
1.1021 raeburn 13959: my ($dirlistref,$listerror) =
13960: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13961: my $found_file = 0;
13962: my $locked_file = 0;
1.991 raeburn 13963: my @lockers;
13964: my $navmap;
13965: if ($env{'request.course.id'}) {
13966: $navmap = Apache::lonnavmaps::navmap->new();
13967: }
1.1021 raeburn 13968: if (ref($dirlistref) eq 'ARRAY') {
13969: foreach my $line (@{$dirlistref}) {
13970: my ($file_name,$rest)=split(/\&/,$line,2);
13971: if ($file_name eq $fname){
13972: $file_name = $path.$file_name;
13973: if ($group ne '') {
13974: $file_name = $group.$file_name;
13975: }
13976: $found_file = 1;
13977: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13978: foreach my $lock (@lockers) {
13979: if (ref($lock) eq 'ARRAY') {
13980: my ($symb,$crsid) = @{$lock};
13981: if ($crsid eq $env{'request.course.id'}) {
13982: if (ref($navmap)) {
13983: my $res = $navmap->getBySymb($symb);
13984: foreach my $part (@{$res->parts()}) {
13985: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13986: unless (($slot_status == $res->RESERVED) ||
13987: ($slot_status == $res->RESERVED_LOCATION)) {
13988: $locked_file = 1;
13989: }
1.991 raeburn 13990: }
1.1021 raeburn 13991: } else {
13992: $locked_file = 1;
1.991 raeburn 13993: }
13994: } else {
13995: $locked_file = 1;
13996: }
13997: }
1.1021 raeburn 13998: }
13999: } else {
14000: my @info = split(/\&/,$rest);
14001: my $currsize = $info[6]/1000;
14002: if ($currsize < $filesize) {
14003: my $extra = $filesize - $currsize;
14004: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 14005: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 14006: &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.1179 bisitz 14007: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
14008: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
14009: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 14010: return ('will_exceed_quota',$msg);
14011: }
1.984 raeburn 14012: }
14013: }
1.661 raeburn 14014: }
14015: }
14016: }
14017: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 14018: my $msg = '<p class="LC_warning">'.
14019: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 14020: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 14021: return ('will_exceed_quota',$msg);
14022: } elsif ($found_file) {
14023: if ($locked_file) {
1.1179 bisitz 14024: my $msg = '<p class="LC_warning">';
1.661 raeburn 14025: $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.1179 bisitz 14026: $msg .= '</p>';
1.661 raeburn 14027: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
14028: return ('file_locked',$msg);
14029: } else {
1.1179 bisitz 14030: my $msg = '<p class="LC_error">';
1.984 raeburn 14031: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1179 bisitz 14032: $msg .= '</p>';
1.984 raeburn 14033: return ('existingfile',$msg);
1.661 raeburn 14034: }
14035: }
14036: }
14037:
1.987 raeburn 14038: sub check_for_traversal {
14039: my ($path,$url,$toplevel) = @_;
14040: my @parts=split(/\//,$path);
14041: my $cleanpath;
14042: my $fullpath = $url;
14043: for (my $i=0;$i<@parts;$i++) {
14044: next if ($parts[$i] eq '.');
14045: if ($parts[$i] eq '..') {
14046: $fullpath =~ s{([^/]+/)$}{};
14047: } else {
14048: $fullpath .= $parts[$i].'/';
14049: }
14050: }
14051: if ($fullpath =~ /^\Q$url\E(.*)$/) {
14052: $cleanpath = $1;
14053: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
14054: my $curr_toprel = $1;
14055: my @parts = split(/\//,$curr_toprel);
14056: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
14057: my @urlparts = split(/\//,$url_toprel);
14058: my $doubledots;
14059: my $startdiff = -1;
14060: for (my $i=0; $i<@urlparts; $i++) {
14061: if ($startdiff == -1) {
14062: unless ($urlparts[$i] eq $parts[$i]) {
14063: $startdiff = $i;
14064: $doubledots .= '../';
14065: }
14066: } else {
14067: $doubledots .= '../';
14068: }
14069: }
14070: if ($startdiff > -1) {
14071: $cleanpath = $doubledots;
14072: for (my $i=$startdiff; $i<@parts; $i++) {
14073: $cleanpath .= $parts[$i].'/';
14074: }
14075: }
14076: }
14077: $cleanpath =~ s{(/)$}{};
14078: return $cleanpath;
14079: }
1.31 albertel 14080:
1.1053 raeburn 14081: sub is_archive_file {
14082: my ($mimetype) = @_;
14083: if (($mimetype eq 'application/octet-stream') ||
14084: ($mimetype eq 'application/x-stuffit') ||
14085: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
14086: return 1;
14087: }
14088: return;
14089: }
14090:
14091: sub decompress_form {
1.1065 raeburn 14092: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 14093: my %lt = &Apache::lonlocal::texthash (
14094: this => 'This file is an archive file.',
1.1067 raeburn 14095: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 14096: itsc => 'Its contents are as follows:',
1.1053 raeburn 14097: youm => 'You may wish to extract its contents.',
14098: extr => 'Extract contents',
1.1067 raeburn 14099: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
14100: proa => 'Process automatically?',
1.1053 raeburn 14101: yes => 'Yes',
14102: no => 'No',
1.1067 raeburn 14103: fold => 'Title for folder containing movie',
14104: movi => 'Title for page containing embedded movie',
1.1053 raeburn 14105: );
1.1065 raeburn 14106: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 14107: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 14108: my $info = &list_archive_contents($fileloc,\@paths);
14109: if (@paths) {
14110: foreach my $path (@paths) {
14111: $path =~ s{^/}{};
1.1067 raeburn 14112: if ($path =~ m{^([^/]+)/$}) {
14113: $topdir = $1;
14114: }
1.1065 raeburn 14115: if ($path =~ m{^([^/]+)/}) {
14116: $toplevel{$1} = $path;
14117: } else {
14118: $toplevel{$path} = $path;
14119: }
14120: }
14121: }
1.1067 raeburn 14122: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 14123: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 14124: "$topdir/media/",
14125: "$topdir/media/$topdir.mp4",
14126: "$topdir/media/FirstFrame.png",
14127: "$topdir/media/player.swf",
14128: "$topdir/media/swfobject.js",
14129: "$topdir/media/expressInstall.swf");
1.1197 raeburn 14130: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 14131: "$topdir/$topdir.mp4",
14132: "$topdir/$topdir\_config.xml",
14133: "$topdir/$topdir\_controller.swf",
14134: "$topdir/$topdir\_embed.css",
14135: "$topdir/$topdir\_First_Frame.png",
14136: "$topdir/$topdir\_player.html",
14137: "$topdir/$topdir\_Thumbnails.png",
14138: "$topdir/playerProductInstall.swf",
14139: "$topdir/scripts/",
14140: "$topdir/scripts/config_xml.js",
14141: "$topdir/scripts/handlebars.js",
14142: "$topdir/scripts/jquery-1.7.1.min.js",
14143: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
14144: "$topdir/scripts/modernizr.js",
14145: "$topdir/scripts/player-min.js",
14146: "$topdir/scripts/swfobject.js",
14147: "$topdir/skins/",
14148: "$topdir/skins/configuration_express.xml",
14149: "$topdir/skins/express_show/",
14150: "$topdir/skins/express_show/player-min.css",
14151: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 14152: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
14153: "$topdir/$topdir.mp4",
14154: "$topdir/$topdir\_config.xml",
14155: "$topdir/$topdir\_controller.swf",
14156: "$topdir/$topdir\_embed.css",
14157: "$topdir/$topdir\_First_Frame.png",
14158: "$topdir/$topdir\_player.html",
14159: "$topdir/$topdir\_Thumbnails.png",
14160: "$topdir/playerProductInstall.swf",
14161: "$topdir/scripts/",
14162: "$topdir/scripts/config_xml.js",
14163: "$topdir/scripts/techsmith-smart-player.min.js",
14164: "$topdir/skins/",
14165: "$topdir/skins/configuration_express.xml",
14166: "$topdir/skins/express_show/",
14167: "$topdir/skins/express_show/spritesheet.min.css",
14168: "$topdir/skins/express_show/spritesheet.png",
14169: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 14170: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 14171: if (@diffs == 0) {
1.1164 raeburn 14172: $is_camtasia = 6;
14173: } else {
1.1197 raeburn 14174: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 14175: if (@diffs == 0) {
14176: $is_camtasia = 8;
1.1197 raeburn 14177: } else {
14178: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
14179: if (@diffs == 0) {
14180: $is_camtasia = 8;
14181: }
1.1164 raeburn 14182: }
1.1067 raeburn 14183: }
14184: }
14185: my $output;
14186: if ($is_camtasia) {
14187: $output = <<"ENDCAM";
14188: <script type="text/javascript" language="Javascript">
14189: // <![CDATA[
14190:
14191: function camtasiaToggle() {
14192: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
14193: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 14194: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 14195: document.getElementById('camtasia_titles').style.display='block';
14196: } else {
14197: document.getElementById('camtasia_titles').style.display='none';
14198: }
14199: }
14200: }
14201: return;
14202: }
14203:
14204: // ]]>
14205: </script>
14206: <p>$lt{'camt'}</p>
14207: ENDCAM
1.1065 raeburn 14208: } else {
1.1067 raeburn 14209: $output = '<p>'.$lt{'this'};
14210: if ($info eq '') {
14211: $output .= ' '.$lt{'youm'}.'</p>'."\n";
14212: } else {
14213: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
14214: '<div><pre>'.$info.'</pre></div>';
14215: }
1.1065 raeburn 14216: }
1.1067 raeburn 14217: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 14218: my $duplicates;
14219: my $num = 0;
14220: if (ref($dirlist) eq 'ARRAY') {
14221: foreach my $item (@{$dirlist}) {
14222: if (ref($item) eq 'ARRAY') {
14223: if (exists($toplevel{$item->[0]})) {
14224: $duplicates .=
14225: &start_data_table_row().
14226: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
14227: 'value="0" checked="checked" />'.&mt('No').'</label>'.
14228: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
14229: 'value="1" />'.&mt('Yes').'</label>'.
14230: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
14231: '<td>'.$item->[0].'</td>';
14232: if ($item->[2]) {
14233: $duplicates .= '<td>'.&mt('Directory').'</td>';
14234: } else {
14235: $duplicates .= '<td>'.&mt('File').'</td>';
14236: }
14237: $duplicates .= '<td>'.$item->[3].'</td>'.
14238: '<td>'.
14239: &Apache::lonlocal::locallocaltime($item->[4]).
14240: '</td>'.
14241: &end_data_table_row();
14242: $num ++;
14243: }
14244: }
14245: }
14246: }
14247: my $itemcount;
14248: if (@paths > 0) {
14249: $itemcount = scalar(@paths);
14250: } else {
14251: $itemcount = 1;
14252: }
1.1067 raeburn 14253: if ($is_camtasia) {
14254: $output .= $lt{'auto'}.'<br />'.
14255: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 14256: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 14257: $lt{'yes'}.'</label> <label>'.
14258: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
14259: $lt{'no'}.'</label></span><br />'.
14260: '<div id="camtasia_titles" style="display:block">'.
14261: &Apache::lonhtmlcommon::start_pick_box().
14262: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
14263: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
14264: &Apache::lonhtmlcommon::row_closure().
14265: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
14266: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
14267: &Apache::lonhtmlcommon::row_closure(1).
14268: &Apache::lonhtmlcommon::end_pick_box().
14269: '</div>';
14270: }
1.1065 raeburn 14271: $output .=
14272: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 14273: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
14274: "\n";
1.1065 raeburn 14275: if ($duplicates ne '') {
14276: $output .= '<p><span class="LC_warning">'.
14277: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
14278: &start_data_table().
14279: &start_data_table_header_row().
14280: '<th>'.&mt('Overwrite?').'</th>'.
14281: '<th>'.&mt('Name').'</th>'.
14282: '<th>'.&mt('Type').'</th>'.
14283: '<th>'.&mt('Size').'</th>'.
14284: '<th>'.&mt('Last modified').'</th>'.
14285: &end_data_table_header_row().
14286: $duplicates.
14287: &end_data_table().
14288: '</p>';
14289: }
1.1067 raeburn 14290: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 14291: if (ref($hiddenelements) eq 'HASH') {
14292: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
14293: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
14294: }
14295: }
14296: $output .= <<"END";
1.1067 raeburn 14297: <br />
1.1053 raeburn 14298: <input type="submit" name="decompress" value="$lt{'extr'}" />
14299: </form>
14300: $noextract
14301: END
14302: return $output;
14303: }
14304:
1.1065 raeburn 14305: sub decompression_utility {
14306: my ($program) = @_;
14307: my @utilities = ('tar','gunzip','bunzip2','unzip');
14308: my $location;
14309: if (grep(/^\Q$program\E$/,@utilities)) {
14310: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
14311: '/usr/sbin/') {
14312: if (-x $dir.$program) {
14313: $location = $dir.$program;
14314: last;
14315: }
14316: }
14317: }
14318: return $location;
14319: }
14320:
14321: sub list_archive_contents {
14322: my ($file,$pathsref) = @_;
14323: my (@cmd,$output);
14324: my $needsregexp;
14325: if ($file =~ /\.zip$/) {
14326: @cmd = (&decompression_utility('unzip'),"-l");
14327: $needsregexp = 1;
14328: } elsif (($file =~ m/\.tar\.gz$/) ||
14329: ($file =~ /\.tgz$/)) {
14330: @cmd = (&decompression_utility('tar'),"-ztf");
14331: } elsif ($file =~ /\.tar\.bz2$/) {
14332: @cmd = (&decompression_utility('tar'),"-jtf");
14333: } elsif ($file =~ m|\.tar$|) {
14334: @cmd = (&decompression_utility('tar'),"-tf");
14335: }
14336: if (@cmd) {
14337: undef($!);
14338: undef($@);
14339: if (open(my $fh,"-|", @cmd, $file)) {
14340: while (my $line = <$fh>) {
14341: $output .= $line;
14342: chomp($line);
14343: my $item;
14344: if ($needsregexp) {
14345: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
14346: } else {
14347: $item = $line;
14348: }
14349: if ($item ne '') {
14350: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
14351: push(@{$pathsref},$item);
14352: }
14353: }
14354: }
14355: close($fh);
14356: }
14357: }
14358: return $output;
14359: }
14360:
1.1053 raeburn 14361: sub decompress_uploaded_file {
14362: my ($file,$dir) = @_;
14363: &Apache::lonnet::appenv({'cgi.file' => $file});
14364: &Apache::lonnet::appenv({'cgi.dir' => $dir});
14365: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
14366: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
14367: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
14368: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
14369: my $decompressed = $env{'cgi.decompressed'};
14370: &Apache::lonnet::delenv('cgi.file');
14371: &Apache::lonnet::delenv('cgi.dir');
14372: &Apache::lonnet::delenv('cgi.decompressed');
14373: return ($decompressed,$result);
14374: }
14375:
1.1055 raeburn 14376: sub process_decompression {
14377: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 14378: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
14379: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14380: &mt('Unexpected file path.').'</p>'."\n";
14381: }
14382: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
14383: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14384: &mt('Unexpected course context.').'</p>'."\n";
14385: }
1.1293 raeburn 14386: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 14387: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14388: &mt('Filename contained unexpected characters.').'</p>'."\n";
14389: }
1.1055 raeburn 14390: my ($dir,$error,$warning,$output);
1.1180 raeburn 14391: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 14392: $error = &mt('Filename not a supported archive file type.').
14393: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 14394: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
14395: } else {
14396: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14397: if ($docuhome eq 'no_host') {
14398: $error = &mt('Could not determine home server for course.');
14399: } else {
14400: my @ids=&Apache::lonnet::current_machine_ids();
14401: my $currdir = "$dir_root/$destination";
14402: if (grep(/^\Q$docuhome\E$/,@ids)) {
14403: $dir = &LONCAPA::propath($docudom,$docuname).
14404: "$dir_root/$destination";
14405: } else {
14406: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
14407: "$dir_root/$docudom/$docuname/$destination";
14408: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
14409: $error = &mt('Archive file not found.');
14410: }
14411: }
1.1065 raeburn 14412: my (@to_overwrite,@to_skip);
14413: if ($env{'form.archive_overwrite_total'} > 0) {
14414: my $total = $env{'form.archive_overwrite_total'};
14415: for (my $i=0; $i<$total; $i++) {
14416: if ($env{'form.archive_overwrite_'.$i} == 1) {
14417: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
14418: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
14419: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
14420: }
14421: }
14422: }
14423: my $numskip = scalar(@to_skip);
1.1292 raeburn 14424: my $numoverwrite = scalar(@to_overwrite);
14425: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 14426: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
14427: } elsif ($dir eq '') {
1.1055 raeburn 14428: $error = &mt('Directory containing archive file unavailable.');
14429: } elsif (!$error) {
1.1065 raeburn 14430: my ($decompressed,$display);
1.1292 raeburn 14431: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 14432: my $tempdir = time.'_'.$$.int(rand(10000));
14433: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 14434: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
14435: ($decompressed,$display) =
14436: &decompress_uploaded_file($file,"$dir/$tempdir");
14437: foreach my $item (@to_skip) {
14438: if (($item ne '') && ($item !~ /\.\./)) {
14439: if (-f "$dir/$tempdir/$item") {
14440: unlink("$dir/$tempdir/$item");
14441: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 14442: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 14443: }
14444: }
14445: }
14446: foreach my $item (@to_overwrite) {
14447: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
14448: if (($item ne '') && ($item !~ /\.\./)) {
14449: if (-f "$dir/$item") {
14450: unlink("$dir/$item");
14451: } elsif (-d "$dir/$item") {
1.1300 raeburn 14452: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 14453: }
14454: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
14455: }
1.1065 raeburn 14456: }
14457: }
1.1292 raeburn 14458: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 14459: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 14460: }
1.1065 raeburn 14461: }
14462: } else {
14463: ($decompressed,$display) =
14464: &decompress_uploaded_file($file,$dir);
14465: }
1.1055 raeburn 14466: if ($decompressed eq 'ok') {
1.1065 raeburn 14467: $output = '<p class="LC_info">'.
14468: &mt('Files extracted successfully from archive.').
14469: '</p>'."\n";
1.1055 raeburn 14470: my ($warning,$result,@contents);
14471: my ($newdirlistref,$newlisterror) =
14472: &Apache::lonnet::dirlist($currdir,$docudom,
14473: $docuname,1);
14474: my (%is_dir,%changes,@newitems);
14475: my $dirptr = 16384;
1.1065 raeburn 14476: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 14477: foreach my $dir_line (@{$newdirlistref}) {
14478: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 14479: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 14480: push(@newitems,$item);
14481: if ($dirptr&$testdir) {
14482: $is_dir{$item} = 1;
14483: }
14484: $changes{$item} = 1;
14485: }
14486: }
14487: }
14488: if (keys(%changes) > 0) {
14489: foreach my $item (sort(@newitems)) {
14490: if ($changes{$item}) {
14491: push(@contents,$item);
14492: }
14493: }
14494: }
14495: if (@contents > 0) {
1.1067 raeburn 14496: my $wantform;
14497: unless ($env{'form.autoextract_camtasia'}) {
14498: $wantform = 1;
14499: }
1.1056 raeburn 14500: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 14501: my ($count,$datatable) = &get_extracted($docudom,$docuname,
14502: $currdir,\%is_dir,
14503: \%children,\%parent,
1.1056 raeburn 14504: \@contents,\%dirorder,
14505: \%titles,$wantform);
1.1055 raeburn 14506: if ($datatable ne '') {
14507: $output .= &archive_options_form('decompressed',$datatable,
14508: $count,$hiddenelem);
1.1065 raeburn 14509: my $startcount = 6;
1.1055 raeburn 14510: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 14511: \%titles,\%children);
1.1055 raeburn 14512: }
1.1067 raeburn 14513: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 14514: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 14515: my %displayed;
14516: my $total = 1;
14517: $env{'form.archive_directory'} = [];
14518: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
14519: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
14520: $path =~ s{/$}{};
14521: my $item;
14522: if ($path ne '') {
14523: $item = "$path/$titles{$i}";
14524: } else {
14525: $item = $titles{$i};
14526: }
14527: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
14528: if ($item eq $contents[0]) {
14529: push(@{$env{'form.archive_directory'}},$i);
14530: $env{'form.archive_'.$i} = 'display';
14531: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
14532: $displayed{'folder'} = $i;
1.1164 raeburn 14533: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
14534: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 14535: $env{'form.archive_'.$i} = 'display';
14536: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
14537: $displayed{'web'} = $i;
14538: } else {
1.1164 raeburn 14539: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
14540: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
14541: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 14542: push(@{$env{'form.archive_directory'}},$i);
14543: }
14544: $env{'form.archive_'.$i} = 'dependency';
14545: }
14546: $total ++;
14547: }
14548: for (my $i=1; $i<$total; $i++) {
14549: next if ($i == $displayed{'web'});
14550: next if ($i == $displayed{'folder'});
14551: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
14552: }
14553: $env{'form.phase'} = 'decompress_cleanup';
14554: $env{'form.archivedelete'} = 1;
14555: $env{'form.archive_count'} = $total-1;
14556: $output .=
14557: &process_extracted_files('coursedocs',$docudom,
14558: $docuname,$destination,
14559: $dir_root,$hiddenelem);
14560: }
1.1055 raeburn 14561: } else {
14562: $warning = &mt('No new items extracted from archive file.');
14563: }
14564: } else {
14565: $output = $display;
14566: $error = &mt('An error occurred during extraction from the archive file.');
14567: }
14568: }
14569: }
14570: }
14571: if ($error) {
14572: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14573: $error.'</p>'."\n";
14574: }
14575: if ($warning) {
14576: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14577: }
14578: return $output;
14579: }
14580:
14581: sub get_extracted {
1.1056 raeburn 14582: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
14583: $titles,$wantform) = @_;
1.1055 raeburn 14584: my $count = 0;
14585: my $depth = 0;
14586: my $datatable;
1.1056 raeburn 14587: my @hierarchy;
1.1055 raeburn 14588: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 14589: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
14590: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 14591: foreach my $item (@{$contents}) {
14592: $count ++;
1.1056 raeburn 14593: @{$dirorder->{$count}} = @hierarchy;
14594: $titles->{$count} = $item;
1.1055 raeburn 14595: &archive_hierarchy($depth,$count,$parent,$children);
14596: if ($wantform) {
14597: $datatable .= &archive_row($is_dir->{$item},$item,
14598: $currdir,$depth,$count);
14599: }
14600: if ($is_dir->{$item}) {
14601: $depth ++;
1.1056 raeburn 14602: push(@hierarchy,$count);
14603: $parent->{$depth} = $count;
1.1055 raeburn 14604: $datatable .=
14605: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14606: \$depth,\$count,\@hierarchy,$dirorder,
14607: $children,$parent,$titles,$wantform);
1.1055 raeburn 14608: $depth --;
1.1056 raeburn 14609: pop(@hierarchy);
1.1055 raeburn 14610: }
14611: }
14612: return ($count,$datatable);
14613: }
14614:
14615: sub recurse_extracted_archive {
1.1056 raeburn 14616: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14617: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14618: my $result='';
1.1056 raeburn 14619: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14620: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14621: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14622: return $result;
14623: }
14624: my $dirptr = 16384;
14625: my ($newdirlistref,$newlisterror) =
14626: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14627: if (ref($newdirlistref) eq 'ARRAY') {
14628: foreach my $dir_line (@{$newdirlistref}) {
14629: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14630: unless ($item =~ /^\.+$/) {
14631: $$count ++;
1.1056 raeburn 14632: @{$dirorder->{$$count}} = @{$hierarchy};
14633: $titles->{$$count} = $item;
1.1055 raeburn 14634: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14635:
1.1055 raeburn 14636: my $is_dir;
14637: if ($dirptr&$testdir) {
14638: $is_dir = 1;
14639: }
14640: if ($wantform) {
14641: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14642: }
14643: if ($is_dir) {
14644: $$depth ++;
1.1056 raeburn 14645: push(@{$hierarchy},$$count);
14646: $parent->{$$depth} = $$count;
1.1055 raeburn 14647: $result .=
14648: &recurse_extracted_archive("$currdir/$item",$docudom,
14649: $docuname,$depth,$count,
1.1056 raeburn 14650: $hierarchy,$dirorder,$children,
14651: $parent,$titles,$wantform);
1.1055 raeburn 14652: $$depth --;
1.1056 raeburn 14653: pop(@{$hierarchy});
1.1055 raeburn 14654: }
14655: }
14656: }
14657: }
14658: return $result;
14659: }
14660:
14661: sub archive_hierarchy {
14662: my ($depth,$count,$parent,$children) =@_;
14663: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14664: if (exists($parent->{$depth})) {
14665: $children->{$parent->{$depth}} .= $count.':';
14666: }
14667: }
14668: return;
14669: }
14670:
14671: sub archive_row {
14672: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14673: my ($name) = ($item =~ m{([^/]+)$});
14674: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14675: 'display' => 'Add as file',
1.1055 raeburn 14676: 'dependency' => 'Include as dependency',
14677: 'discard' => 'Discard',
14678: );
14679: if ($is_dir) {
1.1059 raeburn 14680: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14681: }
1.1056 raeburn 14682: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14683: my $offset = 0;
1.1055 raeburn 14684: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14685: $offset ++;
1.1065 raeburn 14686: if ($action ne 'display') {
14687: $offset ++;
14688: }
1.1055 raeburn 14689: $output .= '<td><span class="LC_nobreak">'.
14690: '<label><input type="radio" name="archive_'.$count.
14691: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14692: my $text = $choices{$action};
14693: if ($is_dir) {
14694: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14695: if ($action eq 'display') {
1.1059 raeburn 14696: $text = &mt('Add as folder');
1.1055 raeburn 14697: }
1.1056 raeburn 14698: } else {
14699: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14700:
14701: }
14702: $output .= ' /> '.$choices{$action}.'</label></span>';
14703: if ($action eq 'dependency') {
14704: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14705: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14706: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14707: '<option value=""></option>'."\n".
14708: '</select>'."\n".
14709: '</div>';
1.1059 raeburn 14710: } elsif ($action eq 'display') {
14711: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14712: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14713: '</div>';
1.1055 raeburn 14714: }
1.1056 raeburn 14715: $output .= '</td>';
1.1055 raeburn 14716: }
14717: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14718: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14719: for (my $i=0; $i<$depth; $i++) {
14720: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14721: }
14722: if ($is_dir) {
14723: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14724: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14725: } else {
14726: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14727: }
14728: $output .= ' '.$name.'</td>'."\n".
14729: &end_data_table_row();
14730: return $output;
14731: }
14732:
14733: sub archive_options_form {
1.1065 raeburn 14734: my ($form,$display,$count,$hiddenelem) = @_;
14735: my %lt = &Apache::lonlocal::texthash(
14736: perm => 'Permanently remove archive file?',
14737: hows => 'How should each extracted item be incorporated in the course?',
14738: cont => 'Content actions for all',
14739: addf => 'Add as folder/file',
14740: incd => 'Include as dependency for a displayed file',
14741: disc => 'Discard',
14742: no => 'No',
14743: yes => 'Yes',
14744: save => 'Save',
14745: );
14746: my $output = <<"END";
14747: <form name="$form" method="post" action="">
14748: <p><span class="LC_nobreak">$lt{'perm'}
14749: <label>
14750: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14751: </label>
14752:
14753: <label>
14754: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14755: </span>
14756: </p>
14757: <input type="hidden" name="phase" value="decompress_cleanup" />
14758: <br />$lt{'hows'}
14759: <div class="LC_columnSection">
14760: <fieldset>
14761: <legend>$lt{'cont'}</legend>
14762: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14763: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14764: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14765: </fieldset>
14766: </div>
14767: END
14768: return $output.
1.1055 raeburn 14769: &start_data_table()."\n".
1.1065 raeburn 14770: $display."\n".
1.1055 raeburn 14771: &end_data_table()."\n".
14772: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14773: $hiddenelem.
1.1065 raeburn 14774: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14775: '</form>';
14776: }
14777:
14778: sub archive_javascript {
1.1056 raeburn 14779: my ($startcount,$numitems,$titles,$children) = @_;
14780: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14781: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14782: my $scripttag = <<START;
14783: <script type="text/javascript">
14784: // <![CDATA[
14785:
14786: function checkAll(form,prefix) {
14787: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14788: for (var i=0; i < form.elements.length; i++) {
14789: var id = form.elements[i].id;
14790: if ((id != '') && (id != undefined)) {
14791: if (idstr.test(id)) {
14792: if (form.elements[i].type == 'radio') {
14793: form.elements[i].checked = true;
1.1056 raeburn 14794: var nostart = i-$startcount;
1.1059 raeburn 14795: var offset = nostart%7;
14796: var count = (nostart-offset)/7;
1.1056 raeburn 14797: dependencyCheck(form,count,offset);
1.1055 raeburn 14798: }
14799: }
14800: }
14801: }
14802: }
14803:
14804: function propagateCheck(form,count) {
14805: if (count > 0) {
1.1059 raeburn 14806: var startelement = $startcount + ((count-1) * 7);
14807: for (var j=1; j<6; j++) {
14808: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14809: var item = startelement + j;
14810: if (form.elements[item].type == 'radio') {
14811: if (form.elements[item].checked) {
14812: containerCheck(form,count,j);
14813: break;
14814: }
1.1055 raeburn 14815: }
14816: }
14817: }
14818: }
14819: }
14820:
14821: numitems = $numitems
1.1056 raeburn 14822: var titles = new Array(numitems);
14823: var parents = new Array(numitems);
1.1055 raeburn 14824: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14825: parents[i] = new Array;
1.1055 raeburn 14826: }
1.1059 raeburn 14827: var maintitle = '$maintitle';
1.1055 raeburn 14828:
14829: START
14830:
1.1056 raeburn 14831: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14832: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14833: for (my $i=0; $i<@contents; $i ++) {
14834: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14835: }
14836: }
14837:
1.1056 raeburn 14838: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14839: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14840: }
14841:
1.1055 raeburn 14842: $scripttag .= <<END;
14843:
14844: function containerCheck(form,count,offset) {
14845: if (count > 0) {
1.1056 raeburn 14846: dependencyCheck(form,count,offset);
1.1059 raeburn 14847: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14848: form.elements[item].checked = true;
14849: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14850: if (parents[count].length > 0) {
14851: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14852: containerCheck(form,parents[count][j],offset);
14853: }
14854: }
14855: }
14856: }
14857: }
14858:
14859: function dependencyCheck(form,count,offset) {
14860: if (count > 0) {
1.1059 raeburn 14861: var chosen = (offset+$startcount)+7*(count-1);
14862: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14863: var currtype = form.elements[depitem].type;
14864: if (form.elements[chosen].value == 'dependency') {
14865: document.getElementById('arc_depon_'+count).style.display='block';
14866: form.elements[depitem].options.length = 0;
14867: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14868: for (var i=1; i<=numitems; i++) {
14869: if (i == count) {
14870: continue;
14871: }
1.1059 raeburn 14872: var startelement = $startcount + (i-1) * 7;
14873: for (var j=1; j<6; j++) {
14874: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14875: var item = startelement + j;
14876: if (form.elements[item].type == 'radio') {
14877: if (form.elements[item].checked) {
14878: if (form.elements[item].value == 'display') {
14879: var n = form.elements[depitem].options.length;
14880: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14881: }
14882: }
14883: }
14884: }
14885: }
14886: }
14887: } else {
14888: document.getElementById('arc_depon_'+count).style.display='none';
14889: form.elements[depitem].options.length = 0;
14890: form.elements[depitem].options[0] = new Option('Select','',true,true);
14891: }
1.1059 raeburn 14892: titleCheck(form,count,offset);
1.1056 raeburn 14893: }
14894: }
14895:
14896: function propagateSelect(form,count,offset) {
14897: if (count > 0) {
1.1065 raeburn 14898: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14899: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14900: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14901: if (parents[count].length > 0) {
14902: for (var j=0; j<parents[count].length; j++) {
14903: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14904: }
14905: }
14906: }
14907: }
14908: }
1.1056 raeburn 14909:
14910: function containerSelect(form,count,offset,picked) {
14911: if (count > 0) {
1.1065 raeburn 14912: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14913: if (form.elements[item].type == 'radio') {
14914: if (form.elements[item].value == 'dependency') {
14915: if (form.elements[item+1].type == 'select-one') {
14916: for (var i=0; i<form.elements[item+1].options.length; i++) {
14917: if (form.elements[item+1].options[i].value == picked) {
14918: form.elements[item+1].selectedIndex = i;
14919: break;
14920: }
14921: }
14922: }
14923: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14924: if (parents[count].length > 0) {
14925: for (var j=0; j<parents[count].length; j++) {
14926: containerSelect(form,parents[count][j],offset,picked);
14927: }
14928: }
14929: }
14930: }
14931: }
14932: }
14933: }
14934:
1.1059 raeburn 14935: function titleCheck(form,count,offset) {
14936: if (count > 0) {
14937: var chosen = (offset+$startcount)+7*(count-1);
14938: var depitem = $startcount + ((count-1) * 7) + 2;
14939: var currtype = form.elements[depitem].type;
14940: if (form.elements[chosen].value == 'display') {
14941: document.getElementById('arc_title_'+count).style.display='block';
14942: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14943: document.getElementById('archive_title_'+count).value=maintitle;
14944: }
14945: } else {
14946: document.getElementById('arc_title_'+count).style.display='none';
14947: if (currtype == 'text') {
14948: document.getElementById('archive_title_'+count).value='';
14949: }
14950: }
14951: }
14952: return;
14953: }
14954:
1.1055 raeburn 14955: // ]]>
14956: </script>
14957: END
14958: return $scripttag;
14959: }
14960:
14961: sub process_extracted_files {
1.1067 raeburn 14962: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14963: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14964: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14965: my @ids=&Apache::lonnet::current_machine_ids();
14966: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14967: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14968: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14969: if (grep(/^\Q$docuhome\E$/,@ids)) {
14970: $prefix = &LONCAPA::propath($docudom,$docuname);
14971: $pathtocheck = "$dir_root/$destination";
14972: $dir = $dir_root;
14973: $ishome = 1;
14974: } else {
14975: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14976: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14977: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14978: }
14979: my $currdir = "$dir_root/$destination";
14980: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14981: if ($env{'form.folderpath'}) {
14982: my @items = split('&',$env{'form.folderpath'});
14983: $folders{'0'} = $items[-2];
1.1099 raeburn 14984: if ($env{'form.folderpath'} =~ /\:1$/) {
14985: $containers{'0'}='page';
14986: } else {
14987: $containers{'0'}='sequence';
14988: }
1.1055 raeburn 14989: }
14990: my @archdirs = &get_env_multiple('form.archive_directory');
14991: if ($numitems) {
14992: for (my $i=1; $i<=$numitems; $i++) {
14993: my $path = $env{'form.archive_content_'.$i};
14994: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14995: my $item = $1;
14996: $toplevelitems{$item} = $i;
14997: if (grep(/^\Q$i\E$/,@archdirs)) {
14998: $is_dir{$item} = 1;
14999: }
15000: }
15001: }
15002: }
1.1067 raeburn 15003: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 15004: if (keys(%toplevelitems) > 0) {
15005: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 15006: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
15007: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 15008: }
1.1066 raeburn 15009: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 15010: if ($numitems) {
15011: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 15012: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 15013: my $path = $env{'form.archive_content_'.$i};
15014: if ($path =~ /^\Q$pathtocheck\E/) {
15015: if ($env{'form.archive_'.$i} eq 'discard') {
15016: if ($prefix ne '' && $path ne '') {
15017: if (-e $prefix.$path) {
1.1066 raeburn 15018: if ((@archdirs > 0) &&
15019: (grep(/^\Q$i\E$/,@archdirs))) {
15020: $todeletedir{$prefix.$path} = 1;
15021: } else {
15022: $todelete{$prefix.$path} = 1;
15023: }
1.1055 raeburn 15024: }
15025: }
15026: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 15027: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 15028: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 15029: $docstitle = $env{'form.archive_title_'.$i};
15030: if ($docstitle eq '') {
15031: $docstitle = $title;
15032: }
1.1055 raeburn 15033: $outer = 0;
1.1056 raeburn 15034: if (ref($dirorder{$i}) eq 'ARRAY') {
15035: if (@{$dirorder{$i}} > 0) {
15036: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 15037: if ($env{'form.archive_'.$item} eq 'display') {
15038: $outer = $item;
15039: last;
15040: }
15041: }
15042: }
15043: }
15044: my ($errtext,$fatal) =
15045: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
15046: '/'.$folders{$outer}.'.'.
15047: $containers{$outer});
15048: next if ($fatal);
15049: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
15050: if ($context eq 'coursedocs') {
1.1056 raeburn 15051: $mapinner{$i} = time;
1.1055 raeburn 15052: $folders{$i} = 'default_'.$mapinner{$i};
15053: $containers{$i} = 'sequence';
15054: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
15055: $folders{$i}.'.'.$containers{$i};
15056: my $newidx = &LONCAPA::map::getresidx();
15057: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 15058: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 15059: push(@LONCAPA::map::order,$newidx);
15060: my ($outtext,$errtext) =
15061: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
15062: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 15063: '.'.$containers{$outer},1,1);
1.1056 raeburn 15064: $newseqid{$i} = $newidx;
1.1067 raeburn 15065: unless ($errtext) {
1.1294 raeburn 15066: $result .= '<li>'.&mt('Folder: [_1] added to course',
15067: &HTML::Entities::encode($docstitle,'<>&"')).
15068: '</li>'."\n";
1.1067 raeburn 15069: }
1.1055 raeburn 15070: }
15071: } else {
15072: if ($context eq 'coursedocs') {
15073: my $newidx=&LONCAPA::map::getresidx();
15074: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
15075: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
15076: $title;
1.1392 raeburn 15077: if (($outer !~ /\D/) &&
15078: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
15079: ($newidx !~ /\D/)) {
1.1294 raeburn 15080: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
15081: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
15082: }
15083: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
15084: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
15085: }
15086: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
15087: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
15088: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
15089: unless ($ishome) {
15090: my $fetch = "$newdest{$i}/$title";
15091: $fetch =~ s/^\Q$prefix$dir\E//;
15092: $prompttofetch{$fetch} = 1;
15093: }
1.1292 raeburn 15094: }
1.1067 raeburn 15095: }
1.1294 raeburn 15096: $LONCAPA::map::resources[$newidx]=
15097: $docstitle.':'.$url.':false:normal:res';
15098: push(@LONCAPA::map::order, $newidx);
15099: my ($outtext,$errtext)=
15100: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
15101: $docuname.'/'.$folders{$outer}.
15102: '.'.$containers{$outer},1,1);
15103: unless ($errtext) {
15104: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
15105: $result .= '<li>'.&mt('File: [_1] added to course',
15106: &HTML::Entities::encode($docstitle,'<>&"')).
15107: '</li>'."\n";
15108: }
1.1067 raeburn 15109: }
1.1294 raeburn 15110: } else {
15111: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
15112: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 15113: }
1.1055 raeburn 15114: }
15115: }
1.1086 raeburn 15116: }
15117: } else {
1.1294 raeburn 15118: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
15119: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 15120: }
15121: }
15122: for (my $i=1; $i<=$numitems; $i++) {
15123: next unless ($env{'form.archive_'.$i} eq 'dependency');
15124: my $path = $env{'form.archive_content_'.$i};
15125: if ($path =~ /^\Q$pathtocheck\E/) {
15126: my ($title) = ($path =~ m{/([^/]+)$});
15127: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
15128: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
15129: if (ref($dirorder{$i}) eq 'ARRAY') {
15130: my ($itemidx,$fullpath,$relpath);
15131: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
15132: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 15133: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 15134: if ($dirorder{$i}->[$j] eq $container) {
15135: $itemidx = $j;
1.1056 raeburn 15136: }
15137: }
1.1086 raeburn 15138: }
15139: if ($itemidx eq '') {
15140: $itemidx = 0;
15141: }
15142: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
15143: if ($mapinner{$referrer{$i}}) {
15144: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
15145: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
15146: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
15147: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
15148: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
15149: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
15150: if (!-e $fullpath) {
15151: mkdir($fullpath,0755);
1.1056 raeburn 15152: }
15153: }
1.1086 raeburn 15154: } else {
15155: last;
1.1056 raeburn 15156: }
1.1086 raeburn 15157: }
15158: }
15159: } elsif ($newdest{$referrer{$i}}) {
15160: $fullpath = $newdest{$referrer{$i}};
15161: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
15162: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
15163: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
15164: last;
15165: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
15166: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
15167: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
15168: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
15169: if (!-e $fullpath) {
15170: mkdir($fullpath,0755);
1.1056 raeburn 15171: }
15172: }
1.1086 raeburn 15173: } else {
15174: last;
1.1056 raeburn 15175: }
1.1055 raeburn 15176: }
15177: }
1.1086 raeburn 15178: if ($fullpath ne '') {
15179: if (-e "$prefix$path") {
1.1292 raeburn 15180: unless (rename("$prefix$path","$fullpath/$title")) {
15181: $warning .= &mt('Failed to rename dependency').'<br />';
15182: }
1.1086 raeburn 15183: }
15184: if (-e "$fullpath/$title") {
15185: my $showpath;
15186: if ($relpath ne '') {
15187: $showpath = "$relpath/$title";
15188: } else {
15189: $showpath = "/$title";
15190: }
1.1294 raeburn 15191: $result .= '<li>'.&mt('[_1] included as a dependency',
15192: &HTML::Entities::encode($showpath,'<>&"')).
15193: '</li>'."\n";
1.1292 raeburn 15194: unless ($ishome) {
15195: my $fetch = "$fullpath/$title";
15196: $fetch =~ s/^\Q$prefix$dir\E//;
15197: $prompttofetch{$fetch} = 1;
15198: }
1.1086 raeburn 15199: }
15200: }
1.1055 raeburn 15201: }
1.1086 raeburn 15202: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
15203: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 15204: &HTML::Entities::encode($path,'<>&"'),
15205: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
15206: '<br />';
1.1055 raeburn 15207: }
15208: } else {
1.1294 raeburn 15209: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 15210: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 15211: }
15212: }
15213: if (keys(%todelete)) {
15214: foreach my $key (keys(%todelete)) {
15215: unlink($key);
1.1066 raeburn 15216: }
15217: }
15218: if (keys(%todeletedir)) {
15219: foreach my $key (keys(%todeletedir)) {
15220: rmdir($key);
15221: }
15222: }
15223: foreach my $dir (sort(keys(%is_dir))) {
15224: if (($pathtocheck ne '') && ($dir ne '')) {
15225: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 15226: }
15227: }
1.1067 raeburn 15228: if ($result ne '') {
15229: $output .= '<ul>'."\n".
15230: $result."\n".
15231: '</ul>';
15232: }
15233: unless ($ishome) {
15234: my $replicationfail;
15235: foreach my $item (keys(%prompttofetch)) {
15236: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
15237: unless ($fetchresult eq 'ok') {
15238: $replicationfail .= '<li>'.$item.'</li>'."\n";
15239: }
15240: }
15241: if ($replicationfail) {
15242: $output .= '<p class="LC_error">'.
15243: &mt('Course home server failed to retrieve:').'<ul>'.
15244: $replicationfail.
15245: '</ul></p>';
15246: }
15247: }
1.1055 raeburn 15248: } else {
15249: $warning = &mt('No items found in archive.');
15250: }
15251: if ($error) {
15252: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
15253: $error.'</p>'."\n";
15254: }
15255: if ($warning) {
15256: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
15257: }
15258: return $output;
15259: }
15260:
1.1066 raeburn 15261: sub cleanup_empty_dirs {
15262: my ($path) = @_;
15263: if (($path ne '') && (-d $path)) {
15264: if (opendir(my $dirh,$path)) {
15265: my @dircontents = grep(!/^\./,readdir($dirh));
15266: my $numitems = 0;
15267: foreach my $item (@dircontents) {
15268: if (-d "$path/$item") {
1.1111 raeburn 15269: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 15270: if (-e "$path/$item") {
15271: $numitems ++;
15272: }
15273: } else {
15274: $numitems ++;
15275: }
15276: }
15277: if ($numitems == 0) {
15278: rmdir($path);
15279: }
15280: closedir($dirh);
15281: }
15282: }
15283: return;
15284: }
15285:
1.41 ng 15286: =pod
1.45 matthew 15287:
1.1162 raeburn 15288: =item * &get_folder_hierarchy()
1.1068 raeburn 15289:
15290: Provides hierarchy of names of folders/sub-folders containing the current
15291: item,
15292:
15293: Inputs: 3
15294: - $navmap - navmaps object
15295:
15296: - $map - url for map (either the trigger itself, or map containing
15297: the resource, which is the trigger).
15298:
15299: - $showitem - 1 => show title for map itself; 0 => do not show.
15300:
15301: Outputs: 1 @pathitems - array of folder/subfolder names.
15302:
15303: =cut
15304:
15305: sub get_folder_hierarchy {
15306: my ($navmap,$map,$showitem) = @_;
15307: my @pathitems;
15308: if (ref($navmap)) {
15309: my $mapres = $navmap->getResourceByUrl($map);
15310: if (ref($mapres)) {
15311: my $pcslist = $mapres->map_hierarchy();
15312: if ($pcslist ne '') {
15313: my @pcs = split(/,/,$pcslist);
15314: foreach my $pc (@pcs) {
15315: if ($pc == 1) {
1.1129 raeburn 15316: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 15317: } else {
15318: my $res = $navmap->getByMapPc($pc);
15319: if (ref($res)) {
15320: my $title = $res->compTitle();
15321: $title =~ s/\W+/_/g;
15322: if ($title ne '') {
15323: push(@pathitems,$title);
15324: }
15325: }
15326: }
15327: }
15328: }
1.1071 raeburn 15329: if ($showitem) {
15330: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 15331: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 15332: } else {
15333: my $maptitle = $mapres->compTitle();
15334: $maptitle =~ s/\W+/_/g;
15335: if ($maptitle ne '') {
15336: push(@pathitems,$maptitle);
15337: }
1.1068 raeburn 15338: }
15339: }
15340: }
15341: }
15342: return @pathitems;
15343: }
15344:
15345: =pod
15346:
1.1015 raeburn 15347: =item * &get_turnedin_filepath()
15348:
15349: Determines path in a user's portfolio file for storage of files uploaded
15350: to a specific essayresponse or dropbox item.
15351:
15352: Inputs: 3 required + 1 optional.
15353: $symb is symb for resource, $uname and $udom are for current user (required).
15354: $caller is optional (can be "submission", if routine is called when storing
15355: an upoaded file when "Submit Answer" button was pressed).
15356:
15357: Returns array containing $path and $multiresp.
15358: $path is path in portfolio. $multiresp is 1 if this resource contains more
15359: than one file upload item. Callers of routine should append partid as a
15360: subdirectory to $path in cases where $multiresp is 1.
15361:
15362: Called by: homework/essayresponse.pm and homework/structuretags.pm
15363:
15364: =cut
15365:
15366: sub get_turnedin_filepath {
15367: my ($symb,$uname,$udom,$caller) = @_;
15368: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
15369: my $turnindir;
15370: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
15371: $turnindir = $userhash{'turnindir'};
15372: my ($path,$multiresp);
15373: if ($turnindir eq '') {
15374: if ($caller eq 'submission') {
15375: $turnindir = &mt('turned in');
15376: $turnindir =~ s/\W+/_/g;
15377: my %newhash = (
15378: 'turnindir' => $turnindir,
15379: );
15380: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
15381: }
15382: }
15383: if ($turnindir ne '') {
15384: $path = '/'.$turnindir.'/';
15385: my ($multipart,$turnin,@pathitems);
15386: my $navmap = Apache::lonnavmaps::navmap->new();
15387: if (defined($navmap)) {
15388: my $mapres = $navmap->getResourceByUrl($map);
15389: if (ref($mapres)) {
15390: my $pcslist = $mapres->map_hierarchy();
15391: if ($pcslist ne '') {
15392: foreach my $pc (split(/,/,$pcslist)) {
15393: my $res = $navmap->getByMapPc($pc);
15394: if (ref($res)) {
15395: my $title = $res->compTitle();
15396: $title =~ s/\W+/_/g;
15397: if ($title ne '') {
1.1149 raeburn 15398: if (($pc > 1) && (length($title) > 12)) {
15399: $title = substr($title,0,12);
15400: }
1.1015 raeburn 15401: push(@pathitems,$title);
15402: }
15403: }
15404: }
15405: }
15406: my $maptitle = $mapres->compTitle();
15407: $maptitle =~ s/\W+/_/g;
15408: if ($maptitle ne '') {
1.1149 raeburn 15409: if (length($maptitle) > 12) {
15410: $maptitle = substr($maptitle,0,12);
15411: }
1.1015 raeburn 15412: push(@pathitems,$maptitle);
15413: }
15414: unless ($env{'request.state'} eq 'construct') {
15415: my $res = $navmap->getBySymb($symb);
15416: if (ref($res)) {
15417: my $partlist = $res->parts();
15418: my $totaluploads = 0;
15419: if (ref($partlist) eq 'ARRAY') {
15420: foreach my $part (@{$partlist}) {
15421: my @types = $res->responseType($part);
15422: my @ids = $res->responseIds($part);
15423: for (my $i=0; $i < scalar(@ids); $i++) {
15424: if ($types[$i] eq 'essay') {
15425: my $partid = $part.'_'.$ids[$i];
15426: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
15427: $totaluploads ++;
15428: }
15429: }
15430: }
15431: }
15432: if ($totaluploads > 1) {
15433: $multiresp = 1;
15434: }
15435: }
15436: }
15437: }
15438: } else {
15439: return;
15440: }
15441: } else {
15442: return;
15443: }
15444: my $restitle=&Apache::lonnet::gettitle($symb);
15445: $restitle =~ s/\W+/_/g;
15446: if ($restitle eq '') {
15447: $restitle = ($resurl =~ m{/[^/]+$});
15448: if ($restitle eq '') {
15449: $restitle = time;
15450: }
15451: }
1.1149 raeburn 15452: if (length($restitle) > 12) {
15453: $restitle = substr($restitle,0,12);
15454: }
1.1015 raeburn 15455: push(@pathitems,$restitle);
15456: $path .= join('/',@pathitems);
15457: }
15458: return ($path,$multiresp);
15459: }
15460:
15461: =pod
15462:
1.464 albertel 15463: =back
1.41 ng 15464:
1.112 bowersj2 15465: =head1 CSV Upload/Handling functions
1.38 albertel 15466:
1.41 ng 15467: =over 4
15468:
1.648 raeburn 15469: =item * &upfile_store($r)
1.41 ng 15470:
15471: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 15472: needs $env{'form.upfile'}
1.41 ng 15473: returns $datatoken to be put into hidden field
15474:
15475: =cut
1.31 albertel 15476:
15477: sub upfile_store {
15478: my $r=shift;
1.258 albertel 15479: $env{'form.upfile'}=~s/\r/\n/gs;
15480: $env{'form.upfile'}=~s/\f/\n/gs;
15481: $env{'form.upfile'}=~s/\n+/\n/gs;
15482: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 15483:
1.1299 raeburn 15484: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
15485: '_enroll_'.$env{'request.course.id'}.'_'.
15486: time.'_'.$$);
15487: return if ($datatoken eq '');
15488:
1.31 albertel 15489: {
1.158 raeburn 15490: my $datafile = $r->dir_config('lonDaemons').
15491: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15492: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 15493: print $fh $env{'form.upfile'};
1.158 raeburn 15494: close($fh);
15495: }
1.31 albertel 15496: }
15497: return $datatoken;
15498: }
15499:
1.56 matthew 15500: =pod
15501:
1.1290 raeburn 15502: =item * &load_tmp_file($r,$datatoken)
1.41 ng 15503:
15504: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 15505: $datatoken is the name to assign to the temporary file.
1.258 albertel 15506: sets $env{'form.upfile'} to the contents of the file
1.41 ng 15507:
15508: =cut
1.31 albertel 15509:
15510: sub load_tmp_file {
1.1290 raeburn 15511: my ($r,$datatoken) = @_;
15512: return if ($datatoken eq '');
1.31 albertel 15513: my @studentdata=();
15514: {
1.158 raeburn 15515: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 15516: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15517: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 15518: @studentdata=<$fh>;
15519: close($fh);
15520: }
1.31 albertel 15521: }
1.258 albertel 15522: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 15523: }
15524:
1.1290 raeburn 15525: sub valid_datatoken {
15526: my ($datatoken) = @_;
1.1325 raeburn 15527: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 15528: return $datatoken;
15529: }
15530: return;
15531: }
15532:
1.56 matthew 15533: =pod
15534:
1.648 raeburn 15535: =item * &upfile_record_sep()
1.41 ng 15536:
15537: Separate uploaded file into records
15538: returns array of records,
1.258 albertel 15539: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 15540:
15541: =cut
1.31 albertel 15542:
15543: sub upfile_record_sep {
1.258 albertel 15544: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 15545: } else {
1.248 albertel 15546: my @records;
1.258 albertel 15547: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 15548: if ($line=~/^\s*$/) { next; }
15549: push(@records,$line);
15550: }
15551: return @records;
1.31 albertel 15552: }
15553: }
15554:
1.56 matthew 15555: =pod
15556:
1.648 raeburn 15557: =item * &record_sep($record)
1.41 ng 15558:
1.258 albertel 15559: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 15560:
15561: =cut
15562:
1.263 www 15563: sub takeleft {
15564: my $index=shift;
15565: return substr('0000'.$index,-4,4);
15566: }
15567:
1.31 albertel 15568: sub record_sep {
15569: my $record=shift;
15570: my %components=();
1.258 albertel 15571: if ($env{'form.upfiletype'} eq 'xml') {
15572: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 15573: my $i=0;
1.356 albertel 15574: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 15575: $field=~s/^(\"|\')//;
15576: $field=~s/(\"|\')$//;
1.263 www 15577: $components{&takeleft($i)}=$field;
1.31 albertel 15578: $i++;
15579: }
1.258 albertel 15580: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 15581: my $i=0;
1.356 albertel 15582: foreach my $field (split(/\t/,$record)) {
1.31 albertel 15583: $field=~s/^(\"|\')//;
15584: $field=~s/(\"|\')$//;
1.263 www 15585: $components{&takeleft($i)}=$field;
1.31 albertel 15586: $i++;
15587: }
15588: } else {
1.561 www 15589: my $separator=',';
1.480 banghart 15590: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 15591: $separator=';';
1.480 banghart 15592: }
1.31 albertel 15593: my $i=0;
1.561 www 15594: # the character we are looking for to indicate the end of a quote or a record
15595: my $looking_for=$separator;
15596: # do not add the characters to the fields
15597: my $ignore=0;
15598: # we just encountered a separator (or the beginning of the record)
15599: my $just_found_separator=1;
15600: # store the field we are working on here
15601: my $field='';
15602: # work our way through all characters in record
15603: foreach my $character ($record=~/(.)/g) {
15604: if ($character eq $looking_for) {
15605: if ($character ne $separator) {
15606: # Found the end of a quote, again looking for separator
15607: $looking_for=$separator;
15608: $ignore=1;
15609: } else {
15610: # Found a separator, store away what we got
15611: $components{&takeleft($i)}=$field;
15612: $i++;
15613: $just_found_separator=1;
15614: $ignore=0;
15615: $field='';
15616: }
15617: next;
15618: }
15619: # single or double quotation marks after a separator indicate beginning of a quote
15620: # we are now looking for the end of the quote and need to ignore separators
15621: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15622: $looking_for=$character;
15623: next;
15624: }
15625: # ignore would be true after we reached the end of a quote
15626: if ($ignore) { next; }
15627: if (($just_found_separator) && ($character=~/\s/)) { next; }
15628: $field.=$character;
15629: $just_found_separator=0;
1.31 albertel 15630: }
1.561 www 15631: # catch the very last entry, since we never encountered the separator
15632: $components{&takeleft($i)}=$field;
1.31 albertel 15633: }
15634: return %components;
15635: }
15636:
1.144 matthew 15637: ######################################################
15638: ######################################################
15639:
1.56 matthew 15640: =pod
15641:
1.648 raeburn 15642: =item * &upfile_select_html()
1.41 ng 15643:
1.144 matthew 15644: Return HTML code to select a file from the users machine and specify
15645: the file type.
1.41 ng 15646:
15647: =cut
15648:
1.144 matthew 15649: ######################################################
15650: ######################################################
1.31 albertel 15651: sub upfile_select_html {
1.144 matthew 15652: my %Types = (
15653: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15654: semisv => &mt('Semicolon separated values'),
1.144 matthew 15655: space => &mt('Space separated'),
15656: tab => &mt('Tabulator separated'),
15657: # xml => &mt('HTML/XML'),
15658: );
15659: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15660: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15661: foreach my $type (sort(keys(%Types))) {
15662: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15663: }
15664: $Str .= "</select>\n";
15665: return $Str;
1.31 albertel 15666: }
15667:
1.301 albertel 15668: sub get_samples {
15669: my ($records,$toget) = @_;
15670: my @samples=({});
15671: my $got=0;
15672: foreach my $rec (@$records) {
15673: my %temp = &record_sep($rec);
15674: if (! grep(/\S/, values(%temp))) { next; }
15675: if (%temp) {
15676: $samples[$got]=\%temp;
15677: $got++;
15678: if ($got == $toget) { last; }
15679: }
15680: }
15681: return \@samples;
15682: }
15683:
1.144 matthew 15684: ######################################################
15685: ######################################################
15686:
1.56 matthew 15687: =pod
15688:
1.648 raeburn 15689: =item * &csv_print_samples($r,$records)
1.41 ng 15690:
15691: Prints a table of sample values from each column uploaded $r is an
15692: Apache Request ref, $records is an arrayref from
15693: &Apache::loncommon::upfile_record_sep
15694:
15695: =cut
15696:
1.144 matthew 15697: ######################################################
15698: ######################################################
1.31 albertel 15699: sub csv_print_samples {
15700: my ($r,$records) = @_;
1.662 bisitz 15701: my $samples = &get_samples($records,5);
1.301 albertel 15702:
1.594 raeburn 15703: $r->print(&mt('Samples').'<br />'.&start_data_table().
15704: &start_data_table_header_row());
1.356 albertel 15705: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15706: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15707: $r->print(&end_data_table_header_row());
1.301 albertel 15708: foreach my $hash (@$samples) {
1.594 raeburn 15709: $r->print(&start_data_table_row());
1.356 albertel 15710: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15711: $r->print('<td>');
1.356 albertel 15712: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15713: $r->print('</td>');
15714: }
1.594 raeburn 15715: $r->print(&end_data_table_row());
1.31 albertel 15716: }
1.594 raeburn 15717: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15718: }
15719:
1.144 matthew 15720: ######################################################
15721: ######################################################
15722:
1.56 matthew 15723: =pod
15724:
1.648 raeburn 15725: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15726:
15727: Prints a table to create associations between values and table columns.
1.144 matthew 15728:
1.41 ng 15729: $r is an Apache Request ref,
15730: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15731: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15732:
15733: =cut
15734:
1.144 matthew 15735: ######################################################
15736: ######################################################
1.31 albertel 15737: sub csv_print_select_table {
15738: my ($r,$records,$d) = @_;
1.301 albertel 15739: my $i=0;
15740: my $samples = &get_samples($records,1);
1.144 matthew 15741: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15742: &start_data_table().&start_data_table_header_row().
1.144 matthew 15743: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15744: '<th>'.&mt('Column').'</th>'.
15745: &end_data_table_header_row()."\n");
1.356 albertel 15746: foreach my $array_ref (@$d) {
15747: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15748: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15749:
1.875 bisitz 15750: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15751: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15752: $r->print('<option value="none"></option>');
1.356 albertel 15753: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15754: $r->print('<option value="'.$sample.'"'.
15755: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15756: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15757: }
1.594 raeburn 15758: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15759: $i++;
15760: }
1.594 raeburn 15761: $r->print(&end_data_table());
1.31 albertel 15762: $i--;
15763: return $i;
15764: }
1.56 matthew 15765:
1.144 matthew 15766: ######################################################
15767: ######################################################
15768:
1.56 matthew 15769: =pod
1.31 albertel 15770:
1.648 raeburn 15771: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15772:
15773: Prints a table of sample values from the upload and can make associate samples to internal names.
15774:
15775: $r is an Apache Request ref,
15776: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15777: $d is an array of 2 element arrays (internal name, displayed name)
15778:
15779: =cut
15780:
1.144 matthew 15781: ######################################################
15782: ######################################################
1.31 albertel 15783: sub csv_samples_select_table {
15784: my ($r,$records,$d) = @_;
15785: my $i=0;
1.144 matthew 15786: #
1.662 bisitz 15787: my $max_samples = 5;
15788: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15789: $r->print(&start_data_table().
15790: &start_data_table_header_row().'<th>'.
15791: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15792: &end_data_table_header_row());
1.301 albertel 15793:
15794: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15795: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15796: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15797: foreach my $option (@$d) {
15798: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15799: $r->print('<option value="'.$value.'"'.
1.253 albertel 15800: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15801: $display.'</option>');
1.31 albertel 15802: }
15803: $r->print('</select></td><td>');
1.662 bisitz 15804: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15805: if (defined($samples->[$line]{$key})) {
15806: $r->print($samples->[$line]{$key}."<br />\n");
15807: }
15808: }
1.594 raeburn 15809: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15810: $i++;
15811: }
1.594 raeburn 15812: $r->print(&end_data_table());
1.31 albertel 15813: $i--;
15814: return($i);
1.115 matthew 15815: }
15816:
1.144 matthew 15817: ######################################################
15818: ######################################################
15819:
1.115 matthew 15820: =pod
15821:
1.648 raeburn 15822: =item * &clean_excel_name($name)
1.115 matthew 15823:
15824: Returns a replacement for $name which does not contain any illegal characters.
15825:
15826: =cut
15827:
1.144 matthew 15828: ######################################################
15829: ######################################################
1.115 matthew 15830: sub clean_excel_name {
15831: my ($name) = @_;
15832: $name =~ s/[:\*\?\/\\]//g;
15833: if (length($name) > 31) {
15834: $name = substr($name,0,31);
15835: }
15836: return $name;
1.25 albertel 15837: }
1.84 albertel 15838:
1.85 albertel 15839: =pod
15840:
1.648 raeburn 15841: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15842:
15843: Returns either 1 or undef
15844:
15845: 1 if the part is to be hidden, undef if it is to be shown
15846:
15847: Arguments are:
15848:
15849: $id the id of the part to be checked
15850: $symb, optional the symb of the resource to check
15851: $udom, optional the domain of the user to check for
15852: $uname, optional the username of the user to check for
15853:
15854: =cut
1.84 albertel 15855:
15856: sub check_if_partid_hidden {
15857: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15858: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15859: $symb,$udom,$uname);
1.141 albertel 15860: my $truth=1;
15861: #if the string starts with !, then the list is the list to show not hide
15862: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15863: my @hiddenlist=split(/,/,$hiddenparts);
15864: foreach my $checkid (@hiddenlist) {
1.141 albertel 15865: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15866: }
1.141 albertel 15867: return !$truth;
1.84 albertel 15868: }
1.127 matthew 15869:
1.138 matthew 15870:
15871: ############################################################
15872: ############################################################
15873:
15874: =pod
15875:
1.157 matthew 15876: =back
15877:
1.138 matthew 15878: =head1 cgi-bin script and graphing routines
15879:
1.157 matthew 15880: =over 4
15881:
1.648 raeburn 15882: =item * &get_cgi_id()
1.138 matthew 15883:
15884: Inputs: none
15885:
15886: Returns an id which can be used to pass environment variables
15887: to various cgi-bin scripts. These environment variables will
15888: be removed from the users environment after a given time by
15889: the routine &Apache::lonnet::transfer_profile_to_env.
15890:
15891: =cut
15892:
15893: ############################################################
15894: ############################################################
1.152 albertel 15895: my $uniq=0;
1.136 matthew 15896: sub get_cgi_id {
1.154 albertel 15897: $uniq=($uniq+1)%100000;
1.280 albertel 15898: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15899: }
15900:
1.127 matthew 15901: ############################################################
15902: ############################################################
15903:
15904: =pod
15905:
1.648 raeburn 15906: =item * &DrawBarGraph()
1.127 matthew 15907:
1.138 matthew 15908: Facilitates the plotting of data in a (stacked) bar graph.
15909: Puts plot definition data into the users environment in order for
15910: graph.png to plot it. Returns an <img> tag for the plot.
15911: The bars on the plot are labeled '1','2',...,'n'.
15912:
15913: Inputs:
15914:
15915: =over 4
15916:
15917: =item $Title: string, the title of the plot
15918:
15919: =item $xlabel: string, text describing the X-axis of the plot
15920:
15921: =item $ylabel: string, text describing the Y-axis of the plot
15922:
15923: =item $Max: scalar, the maximum Y value to use in the plot
15924: If $Max is < any data point, the graph will not be rendered.
15925:
1.140 matthew 15926: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15927: they are plotted. If undefined, default values will be used.
15928:
1.178 matthew 15929: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15930:
1.138 matthew 15931: =item @Values: An array of array references. Each array reference holds data
15932: to be plotted in a stacked bar chart.
15933:
1.239 matthew 15934: =item If the final element of @Values is a hash reference the key/value
15935: pairs will be added to the graph definition.
15936:
1.138 matthew 15937: =back
15938:
15939: Returns:
15940:
15941: An <img> tag which references graph.png and the appropriate identifying
15942: information for the plot.
15943:
1.127 matthew 15944: =cut
15945:
15946: ############################################################
15947: ############################################################
1.134 matthew 15948: sub DrawBarGraph {
1.178 matthew 15949: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15950: #
15951: if (! defined($colors)) {
15952: $colors = ['#33ff00',
15953: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15954: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15955: ];
15956: }
1.228 matthew 15957: my $extra_settings = {};
15958: if (ref($Values[-1]) eq 'HASH') {
15959: $extra_settings = pop(@Values);
15960: }
1.127 matthew 15961: #
1.136 matthew 15962: my $identifier = &get_cgi_id();
15963: my $id = 'cgi.'.$identifier;
1.129 matthew 15964: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15965: return '';
15966: }
1.225 matthew 15967: #
15968: my @Labels;
15969: if (defined($labels)) {
15970: @Labels = @$labels;
15971: } else {
15972: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15973: push(@Labels,$i+1);
1.225 matthew 15974: }
15975: }
15976: #
1.129 matthew 15977: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15978: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15979: my %ValuesHash;
15980: my $NumSets=1;
15981: foreach my $array (@Values) {
15982: next if (! ref($array));
1.136 matthew 15983: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15984: join(',',@$array);
1.129 matthew 15985: }
1.127 matthew 15986: #
1.136 matthew 15987: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15988: if ($NumBars < 3) {
15989: $width = 120+$NumBars*32;
1.220 matthew 15990: $xskip = 1;
1.225 matthew 15991: $bar_width = 30;
15992: } elsif ($NumBars < 5) {
15993: $width = 120+$NumBars*20;
15994: $xskip = 1;
15995: $bar_width = 20;
1.220 matthew 15996: } elsif ($NumBars < 10) {
1.136 matthew 15997: $width = 120+$NumBars*15;
15998: $xskip = 1;
15999: $bar_width = 15;
16000: } elsif ($NumBars <= 25) {
16001: $width = 120+$NumBars*11;
16002: $xskip = 5;
16003: $bar_width = 8;
16004: } elsif ($NumBars <= 50) {
16005: $width = 120+$NumBars*8;
16006: $xskip = 5;
16007: $bar_width = 4;
16008: } else {
16009: $width = 120+$NumBars*8;
16010: $xskip = 5;
16011: $bar_width = 4;
16012: }
16013: #
1.137 matthew 16014: $Max = 1 if ($Max < 1);
16015: if ( int($Max) < $Max ) {
16016: $Max++;
16017: $Max = int($Max);
16018: }
1.127 matthew 16019: $Title = '' if (! defined($Title));
16020: $xlabel = '' if (! defined($xlabel));
16021: $ylabel = '' if (! defined($ylabel));
1.369 www 16022: $ValuesHash{$id.'.title'} = &escape($Title);
16023: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
16024: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 16025: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 16026: $ValuesHash{$id.'.NumBars'} = $NumBars;
16027: $ValuesHash{$id.'.NumSets'} = $NumSets;
16028: $ValuesHash{$id.'.PlotType'} = 'bar';
16029: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16030: $ValuesHash{$id.'.height'} = $height;
16031: $ValuesHash{$id.'.width'} = $width;
16032: $ValuesHash{$id.'.xskip'} = $xskip;
16033: $ValuesHash{$id.'.bar_width'} = $bar_width;
16034: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 16035: #
1.228 matthew 16036: # Deal with other parameters
16037: while (my ($key,$value) = each(%$extra_settings)) {
16038: $ValuesHash{$id.'.'.$key} = $value;
16039: }
16040: #
1.646 raeburn 16041: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 16042: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
16043: }
16044:
16045: ############################################################
16046: ############################################################
16047:
16048: =pod
16049:
1.648 raeburn 16050: =item * &DrawXYGraph()
1.137 matthew 16051:
1.138 matthew 16052: Facilitates the plotting of data in an XY graph.
16053: Puts plot definition data into the users environment in order for
16054: graph.png to plot it. Returns an <img> tag for the plot.
16055:
16056: Inputs:
16057:
16058: =over 4
16059:
16060: =item $Title: string, the title of the plot
16061:
16062: =item $xlabel: string, text describing the X-axis of the plot
16063:
16064: =item $ylabel: string, text describing the Y-axis of the plot
16065:
16066: =item $Max: scalar, the maximum Y value to use in the plot
16067: If $Max is < any data point, the graph will not be rendered.
16068:
16069: =item $colors: Array ref containing the hex color codes for the data to be
16070: plotted in. If undefined, default values will be used.
16071:
16072: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
16073:
16074: =item $Ydata: Array ref containing Array refs.
1.185 www 16075: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 16076:
16077: =item %Values: hash indicating or overriding any default values which are
16078: passed to graph.png.
16079: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
16080:
16081: =back
16082:
16083: Returns:
16084:
16085: An <img> tag which references graph.png and the appropriate identifying
16086: information for the plot.
16087:
1.137 matthew 16088: =cut
16089:
16090: ############################################################
16091: ############################################################
16092: sub DrawXYGraph {
16093: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
16094: #
16095: # Create the identifier for the graph
16096: my $identifier = &get_cgi_id();
16097: my $id = 'cgi.'.$identifier;
16098: #
16099: $Title = '' if (! defined($Title));
16100: $xlabel = '' if (! defined($xlabel));
16101: $ylabel = '' if (! defined($ylabel));
16102: my %ValuesHash =
16103: (
1.369 www 16104: $id.'.title' => &escape($Title),
16105: $id.'.xlabel' => &escape($xlabel),
16106: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 16107: $id.'.y_max_value'=> $Max,
16108: $id.'.labels' => join(',',@$Xlabels),
16109: $id.'.PlotType' => 'XY',
16110: );
16111: #
16112: if (defined($colors) && ref($colors) eq 'ARRAY') {
16113: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16114: }
16115: #
16116: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
16117: return '';
16118: }
16119: my $NumSets=1;
1.138 matthew 16120: foreach my $array (@{$Ydata}){
1.137 matthew 16121: next if (! ref($array));
16122: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
16123: }
1.138 matthew 16124: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 16125: #
16126: # Deal with other parameters
16127: while (my ($key,$value) = each(%Values)) {
16128: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 16129: }
16130: #
1.646 raeburn 16131: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 16132: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
16133: }
16134:
16135: ############################################################
16136: ############################################################
16137:
16138: =pod
16139:
1.648 raeburn 16140: =item * &DrawXYYGraph()
1.138 matthew 16141:
16142: Facilitates the plotting of data in an XY graph with two Y axes.
16143: Puts plot definition data into the users environment in order for
16144: graph.png to plot it. Returns an <img> tag for the plot.
16145:
16146: Inputs:
16147:
16148: =over 4
16149:
16150: =item $Title: string, the title of the plot
16151:
16152: =item $xlabel: string, text describing the X-axis of the plot
16153:
16154: =item $ylabel: string, text describing the Y-axis of the plot
16155:
16156: =item $colors: Array ref containing the hex color codes for the data to be
16157: plotted in. If undefined, default values will be used.
16158:
16159: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
16160:
16161: =item $Ydata1: The first data set
16162:
16163: =item $Min1: The minimum value of the left Y-axis
16164:
16165: =item $Max1: The maximum value of the left Y-axis
16166:
16167: =item $Ydata2: The second data set
16168:
16169: =item $Min2: The minimum value of the right Y-axis
16170:
16171: =item $Max2: The maximum value of the left Y-axis
16172:
16173: =item %Values: hash indicating or overriding any default values which are
16174: passed to graph.png.
16175: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
16176:
16177: =back
16178:
16179: Returns:
16180:
16181: An <img> tag which references graph.png and the appropriate identifying
16182: information for the plot.
1.136 matthew 16183:
16184: =cut
16185:
16186: ############################################################
16187: ############################################################
1.137 matthew 16188: sub DrawXYYGraph {
16189: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
16190: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 16191: #
16192: # Create the identifier for the graph
16193: my $identifier = &get_cgi_id();
16194: my $id = 'cgi.'.$identifier;
16195: #
16196: $Title = '' if (! defined($Title));
16197: $xlabel = '' if (! defined($xlabel));
16198: $ylabel = '' if (! defined($ylabel));
16199: my %ValuesHash =
16200: (
1.369 www 16201: $id.'.title' => &escape($Title),
16202: $id.'.xlabel' => &escape($xlabel),
16203: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 16204: $id.'.labels' => join(',',@$Xlabels),
16205: $id.'.PlotType' => 'XY',
16206: $id.'.NumSets' => 2,
1.137 matthew 16207: $id.'.two_axes' => 1,
16208: $id.'.y1_max_value' => $Max1,
16209: $id.'.y1_min_value' => $Min1,
16210: $id.'.y2_max_value' => $Max2,
16211: $id.'.y2_min_value' => $Min2,
1.136 matthew 16212: );
16213: #
1.137 matthew 16214: if (defined($colors) && ref($colors) eq 'ARRAY') {
16215: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16216: }
16217: #
16218: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
16219: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 16220: return '';
16221: }
16222: my $NumSets=1;
1.137 matthew 16223: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 16224: next if (! ref($array));
16225: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 16226: }
16227: #
16228: # Deal with other parameters
16229: while (my ($key,$value) = each(%Values)) {
16230: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 16231: }
16232: #
1.646 raeburn 16233: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 16234: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 16235: }
16236:
16237: ############################################################
16238: ############################################################
16239:
16240: =pod
16241:
1.157 matthew 16242: =back
16243:
1.139 matthew 16244: =head1 Statistics helper routines?
16245:
16246: Bad place for them but what the hell.
16247:
1.157 matthew 16248: =over 4
16249:
1.648 raeburn 16250: =item * &chartlink()
1.139 matthew 16251:
16252: Returns a link to the chart for a specific student.
16253:
16254: Inputs:
16255:
16256: =over 4
16257:
16258: =item $linktext: The text of the link
16259:
16260: =item $sname: The students username
16261:
16262: =item $sdomain: The students domain
16263:
16264: =back
16265:
1.157 matthew 16266: =back
16267:
1.139 matthew 16268: =cut
16269:
16270: ############################################################
16271: ############################################################
16272: sub chartlink {
16273: my ($linktext, $sname, $sdomain) = @_;
16274: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 16275: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 16276: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 16277: '">'.$linktext.'</a>';
1.153 matthew 16278: }
16279:
16280: #######################################################
16281: #######################################################
16282:
16283: =pod
16284:
16285: =head1 Course Environment Routines
1.157 matthew 16286:
16287: =over 4
1.153 matthew 16288:
1.648 raeburn 16289: =item * &restore_course_settings()
1.153 matthew 16290:
1.648 raeburn 16291: =item * &store_course_settings()
1.153 matthew 16292:
16293: Restores/Store indicated form parameters from the course environment.
16294: Will not overwrite existing values of the form parameters.
16295:
16296: Inputs:
16297: a scalar describing the data (e.g. 'chart', 'problem_analysis')
16298:
16299: a hash ref describing the data to be stored. For example:
16300:
16301: %Save_Parameters = ('Status' => 'scalar',
16302: 'chartoutputmode' => 'scalar',
16303: 'chartoutputdata' => 'scalar',
16304: 'Section' => 'array',
1.373 raeburn 16305: 'Group' => 'array',
1.153 matthew 16306: 'StudentData' => 'array',
16307: 'Maps' => 'array');
16308:
16309: Returns: both routines return nothing
16310:
1.631 raeburn 16311: =back
16312:
1.153 matthew 16313: =cut
16314:
16315: #######################################################
16316: #######################################################
16317: sub store_course_settings {
1.496 albertel 16318: return &store_settings($env{'request.course.id'},@_);
16319: }
16320:
16321: sub store_settings {
1.153 matthew 16322: # save to the environment
16323: # appenv the same items, just to be safe
1.300 albertel 16324: my $udom = $env{'user.domain'};
16325: my $uname = $env{'user.name'};
1.496 albertel 16326: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16327: my %SaveHash;
16328: my %AppHash;
16329: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 16330: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 16331: my $envname = 'environment.'.$basename;
1.258 albertel 16332: if (exists($env{'form.'.$setting})) {
1.153 matthew 16333: # Save this value away
16334: if ($type eq 'scalar' &&
1.258 albertel 16335: (! exists($env{$envname}) ||
16336: $env{$envname} ne $env{'form.'.$setting})) {
16337: $SaveHash{$basename} = $env{'form.'.$setting};
16338: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 16339: } elsif ($type eq 'array') {
16340: my $stored_form;
1.258 albertel 16341: if (ref($env{'form.'.$setting})) {
1.153 matthew 16342: $stored_form = join(',',
16343: map {
1.369 www 16344: &escape($_);
1.258 albertel 16345: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 16346: } else {
16347: $stored_form =
1.369 www 16348: &escape($env{'form.'.$setting});
1.153 matthew 16349: }
16350: # Determine if the array contents are the same.
1.258 albertel 16351: if ($stored_form ne $env{$envname}) {
1.153 matthew 16352: $SaveHash{$basename} = $stored_form;
16353: $AppHash{$envname} = $stored_form;
16354: }
16355: }
16356: }
16357: }
16358: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 16359: $udom,$uname);
1.153 matthew 16360: if ($put_result !~ /^(ok|delayed)/) {
16361: &Apache::lonnet::logthis('unable to save form parameters, '.
16362: 'got error:'.$put_result);
16363: }
16364: # Make sure these settings stick around in this session, too
1.646 raeburn 16365: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 16366: return;
16367: }
16368:
16369: sub restore_course_settings {
1.499 albertel 16370: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 16371: }
16372:
16373: sub restore_settings {
16374: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16375: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 16376: next if (exists($env{'form.'.$setting}));
1.496 albertel 16377: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 16378: '.'.$setting;
1.258 albertel 16379: if (exists($env{$envname})) {
1.153 matthew 16380: if ($type eq 'scalar') {
1.258 albertel 16381: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 16382: } elsif ($type eq 'array') {
1.258 albertel 16383: $env{'form.'.$setting} = [
1.153 matthew 16384: map {
1.369 www 16385: &unescape($_);
1.258 albertel 16386: } split(',',$env{$envname})
1.153 matthew 16387: ];
16388: }
16389: }
16390: }
1.127 matthew 16391: }
16392:
1.618 raeburn 16393: #######################################################
16394: #######################################################
16395:
16396: =pod
16397:
16398: =head1 Domain E-mail Routines
16399:
16400: =over 4
16401:
1.648 raeburn 16402: =item * &build_recipient_list()
1.618 raeburn 16403:
1.1144 raeburn 16404: Build recipient lists for following types of e-mail:
1.766 raeburn 16405: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 16406: (d) Help requests, (e) Course requests needing approval, (f) loncapa
16407: module change checking, student/employee ID conflict checks, as
16408: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
16409: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 16410:
16411: Inputs:
1.619 raeburn 16412: defmail (scalar - email address of default recipient),
1.1144 raeburn 16413: mailing type (scalar: errormail, packagesmail, helpdeskmail,
16414: requestsmail, updatesmail, or idconflictsmail).
16415:
1.619 raeburn 16416: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 16417:
1.619 raeburn 16418: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 16419: i.e., predates configuration by DC via domainprefs.pm
16420:
16421: $requname username of requester (if mailing type is helpdeskmail)
16422:
16423: $requdom domain of requester (if mailing type is helpdeskmail)
16424:
16425: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
16426:
1.618 raeburn 16427:
1.655 raeburn 16428: Returns: comma separated list of addresses to which to send e-mail.
16429:
16430: =back
1.618 raeburn 16431:
16432: =cut
16433:
16434: ############################################################
16435: ############################################################
16436: sub build_recipient_list {
1.1297 raeburn 16437: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 16438: my @recipients;
1.1270 raeburn 16439: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 16440: my %domconfig =
1.1270 raeburn 16441: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 16442: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 16443: if (exists($domconfig{'contacts'}{$mailing})) {
16444: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
16445: my @contacts = ('adminemail','supportemail');
16446: foreach my $item (@contacts) {
16447: if ($domconfig{'contacts'}{$mailing}{$item}) {
16448: my $addr = $domconfig{'contacts'}{$item};
16449: if (!grep(/^\Q$addr\E$/,@recipients)) {
16450: push(@recipients,$addr);
16451: }
1.619 raeburn 16452: }
1.1270 raeburn 16453: }
16454: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
16455: if ($mailing eq 'helpdeskmail') {
16456: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
16457: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
16458: my @ok_bccs;
16459: foreach my $bcc (@bccs) {
16460: $bcc =~ s/^\s+//g;
16461: $bcc =~ s/\s+$//g;
16462: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16463: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16464: push(@ok_bccs,$bcc);
16465: }
16466: }
16467: }
16468: if (@ok_bccs > 0) {
16469: $allbcc = join(', ',@ok_bccs);
16470: }
16471: }
16472: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 16473: }
16474: }
1.766 raeburn 16475: } elsif ($origmail ne '') {
1.1270 raeburn 16476: $lastresort = $origmail;
1.618 raeburn 16477: }
1.1297 raeburn 16478: if ($mailing eq 'helpdeskmail') {
16479: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
16480: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
16481: my ($inststatus,$inststatus_checked);
16482: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
16483: ($env{'user.domain'} ne 'public')) {
16484: $inststatus_checked = 1;
16485: $inststatus = $env{'environment.inststatus'};
16486: }
16487: unless ($inststatus_checked) {
16488: if (($requname ne '') && ($requdom ne '')) {
16489: if (($requname =~ /^$match_username$/) &&
16490: ($requdom =~ /^$match_domain$/) &&
16491: (&Apache::lonnet::domain($requdom))) {
16492: my $requhome = &Apache::lonnet::homeserver($requname,
16493: $requdom);
16494: unless ($requhome eq 'no_host') {
16495: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
16496: $inststatus = $userenv{'inststatus'};
16497: $inststatus_checked = 1;
16498: }
16499: }
16500: }
16501: }
16502: unless ($inststatus_checked) {
16503: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
16504: my %srch = (srchby => 'email',
16505: srchdomain => $defdom,
16506: srchterm => $reqemail,
16507: srchtype => 'exact');
16508: my %srch_results = &Apache::lonnet::usersearch(\%srch);
16509: foreach my $uname (keys(%srch_results)) {
16510: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16511: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16512: $inststatus_checked = 1;
16513: last;
16514: }
16515: }
16516: unless ($inststatus_checked) {
16517: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
16518: if ($dirsrchres eq 'ok') {
16519: foreach my $uname (keys(%srch_results)) {
16520: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16521: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16522: $inststatus_checked = 1;
16523: last;
16524: }
16525: }
16526: }
16527: }
16528: }
16529: }
16530: if ($inststatus ne '') {
16531: foreach my $status (split(/\:/,$inststatus)) {
16532: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
16533: my @contacts = ('adminemail','supportemail');
16534: foreach my $item (@contacts) {
16535: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
16536: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
16537: if (!grep(/^\Q$addr\E$/,@recipients)) {
16538: push(@recipients,$addr);
16539: }
16540: }
16541: }
16542: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
16543: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
16544: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
16545: my @ok_bccs;
16546: foreach my $bcc (@bccs) {
16547: $bcc =~ s/^\s+//g;
16548: $bcc =~ s/\s+$//g;
16549: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16550: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16551: push(@ok_bccs,$bcc);
16552: }
16553: }
16554: }
16555: if (@ok_bccs > 0) {
16556: $allbcc = join(', ',@ok_bccs);
16557: }
16558: }
16559: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
16560: last;
16561: }
16562: }
16563: }
16564: }
16565: }
1.619 raeburn 16566: } elsif ($origmail ne '') {
1.1270 raeburn 16567: $lastresort = $origmail;
16568: }
1.1297 raeburn 16569: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 16570: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
16571: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
16572: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
16573: my %what = (
16574: perlvar => 1,
16575: );
16576: my $primary = &Apache::lonnet::domain($defdom,'primary');
16577: if ($primary) {
16578: my $gotaddr;
16579: my ($result,$returnhash) =
16580: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
16581: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
16582: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
16583: $lastresort = $returnhash->{'lonSupportEMail'};
16584: $gotaddr = 1;
16585: }
16586: }
16587: unless ($gotaddr) {
16588: my $uintdom = &Apache::lonnet::internet_dom($primary);
16589: my $intdom = &Apache::lonnet::internet_dom($lonhost);
16590: unless ($uintdom eq $intdom) {
16591: my %domconfig =
16592: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
16593: if (ref($domconfig{'contacts'}) eq 'HASH') {
16594: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
16595: my @contacts = ('adminemail','supportemail');
16596: foreach my $item (@contacts) {
16597: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
16598: my $addr = $domconfig{'contacts'}{$item};
16599: if (!grep(/^\Q$addr\E$/,@recipients)) {
16600: push(@recipients,$addr);
16601: }
16602: }
16603: }
16604: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16605: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16606: }
16607: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16608: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16609: my @ok_bccs;
16610: foreach my $bcc (@bccs) {
16611: $bcc =~ s/^\s+//g;
16612: $bcc =~ s/\s+$//g;
16613: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16614: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16615: push(@ok_bccs,$bcc);
16616: }
16617: }
16618: }
16619: if (@ok_bccs > 0) {
16620: $allbcc = join(', ',@ok_bccs);
16621: }
16622: }
16623: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16624: }
16625: }
16626: }
16627: }
16628: }
16629: }
1.618 raeburn 16630: }
1.688 raeburn 16631: if (defined($defmail)) {
16632: if ($defmail ne '') {
16633: push(@recipients,$defmail);
16634: }
1.618 raeburn 16635: }
16636: if ($otheremails) {
1.619 raeburn 16637: my @others;
16638: if ($otheremails =~ /,/) {
16639: @others = split(/,/,$otheremails);
1.618 raeburn 16640: } else {
1.619 raeburn 16641: push(@others,$otheremails);
16642: }
16643: foreach my $addr (@others) {
16644: if (!grep(/^\Q$addr\E$/,@recipients)) {
16645: push(@recipients,$addr);
16646: }
1.618 raeburn 16647: }
16648: }
1.1298 raeburn 16649: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16650: if ((!@recipients) && ($lastresort ne '')) {
16651: push(@recipients,$lastresort);
16652: }
16653: } elsif ($lastresort ne '') {
16654: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16655: push(@recipients,$lastresort);
16656: }
16657: }
1.1271 raeburn 16658: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16659: if (wantarray) {
16660: return ($recipientlist,$allbcc,$addtext);
16661: } else {
16662: return $recipientlist;
16663: }
1.618 raeburn 16664: }
16665:
1.127 matthew 16666: ############################################################
16667: ############################################################
1.154 albertel 16668:
1.655 raeburn 16669: =pod
16670:
1.1224 musolffc 16671: =over 4
16672:
1.1223 musolffc 16673: =item * &mime_email()
16674:
16675: Sends an email with a possible attachment
16676:
16677: Inputs:
16678:
16679: =over 4
16680:
16681: from - Sender's email address
16682:
1.1343 raeburn 16683: replyto - Reply-To email address
16684:
1.1223 musolffc 16685: to - Email address of recipient
16686:
16687: subject - Subject of email
16688:
16689: body - Body of email
16690:
16691: cc_string - Carbon copy email address
16692:
16693: bcc - Blind carbon copy email address
16694:
16695: attachment_path - Path of file to be attached
16696:
16697: file_name - Name of file to be attached
16698:
16699: attachment_text - The body of an attachment of type "TEXT"
16700:
16701: =back
16702:
16703: =back
16704:
16705: =cut
16706:
16707: ############################################################
16708: ############################################################
16709:
16710: sub mime_email {
1.1343 raeburn 16711: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16712: $file_name,$attachment_text) = @_;
16713:
1.1223 musolffc 16714: my $msg = MIME::Lite->new(
16715: From => $from,
16716: To => $to,
16717: Subject => $subject,
16718: Type =>'TEXT',
16719: Data => $body,
16720: );
1.1343 raeburn 16721: if ($replyto ne '') {
16722: $msg->add("Reply-To" => $replyto);
16723: }
1.1223 musolffc 16724: if ($cc_string ne '') {
16725: $msg->add("Cc" => $cc_string);
16726: }
16727: if ($bcc ne '') {
16728: $msg->add("Bcc" => $bcc);
16729: }
16730: $msg->attr("content-type" => "text/plain");
16731: $msg->attr("content-type.charset" => "UTF-8");
16732: # Attach file if given
16733: if ($attachment_path) {
16734: unless ($file_name) {
16735: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16736: }
16737: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16738: $msg->attach(Type => $type,
16739: Path => $attachment_path,
16740: Filename => $file_name
16741: );
16742: # Otherwise attach text if given
16743: } elsif ($attachment_text) {
16744: $msg->attach(Type => 'TEXT',
16745: Data => $attachment_text);
16746: }
16747: # Send it
16748: $msg->send('sendmail');
16749: }
16750:
16751: ############################################################
16752: ############################################################
16753:
16754: =pod
16755:
1.655 raeburn 16756: =head1 Course Catalog Routines
16757:
16758: =over 4
16759:
16760: =item * &gather_categories()
16761:
16762: Converts category definitions - keys of categories hash stored in
16763: coursecategories in configuration.db on the primary library server in a
16764: domain - to an array. Also generates javascript and idx hash used to
16765: generate Domain Coordinator interface for editing Course Categories.
16766:
16767: Inputs:
1.663 raeburn 16768:
1.655 raeburn 16769: categories (reference to hash of category definitions).
1.663 raeburn 16770:
1.655 raeburn 16771: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16772: categories and subcategories).
1.663 raeburn 16773:
1.655 raeburn 16774: idx (reference to hash of counters used in Domain Coordinator interface for
16775: editing Course Categories).
1.663 raeburn 16776:
1.655 raeburn 16777: jsarray (reference to array of categories used to create Javascript arrays for
16778: Domain Coordinator interface for editing Course Categories).
16779:
16780: Returns: nothing
16781:
16782: Side effects: populates cats, idx and jsarray.
16783:
16784: =cut
16785:
16786: sub gather_categories {
16787: my ($categories,$cats,$idx,$jsarray) = @_;
16788: my %counters;
16789: my $num = 0;
16790: foreach my $item (keys(%{$categories})) {
16791: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16792: if ($container eq '' && $depth == 0) {
16793: $cats->[$depth][$categories->{$item}] = $cat;
16794: } else {
16795: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16796: }
16797: my ($escitem,$tail) = split(/:/,$item,2);
16798: if ($counters{$tail} eq '') {
16799: $counters{$tail} = $num;
16800: $num ++;
16801: }
16802: if (ref($idx) eq 'HASH') {
16803: $idx->{$item} = $counters{$tail};
16804: }
16805: if (ref($jsarray) eq 'ARRAY') {
16806: push(@{$jsarray->[$counters{$tail}]},$item);
16807: }
16808: }
16809: return;
16810: }
16811:
16812: =pod
16813:
16814: =item * &extract_categories()
16815:
16816: Used to generate breadcrumb trails for course categories.
16817:
16818: Inputs:
1.663 raeburn 16819:
1.655 raeburn 16820: categories (reference to hash of category definitions).
1.663 raeburn 16821:
1.655 raeburn 16822: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16823: categories and subcategories).
1.663 raeburn 16824:
1.655 raeburn 16825: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16826:
1.655 raeburn 16827: allitems (reference to hash - key is category key
16828: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16829:
1.655 raeburn 16830: idx (reference to hash of counters used in Domain Coordinator interface for
16831: editing Course Categories).
1.663 raeburn 16832:
1.655 raeburn 16833: jsarray (reference to array of categories used to create Javascript arrays for
16834: Domain Coordinator interface for editing Course Categories).
16835:
1.665 raeburn 16836: subcats (reference to hash of arrays containing all subcategories within each
16837: category, -recursive)
16838:
1.1321 raeburn 16839: maxd (reference to hash used to hold max depth for all top-level categories).
16840:
1.655 raeburn 16841: Returns: nothing
16842:
16843: Side effects: populates trails and allitems hash references.
16844:
16845: =cut
16846:
16847: sub extract_categories {
1.1321 raeburn 16848: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16849: if (ref($categories) eq 'HASH') {
16850: &gather_categories($categories,$cats,$idx,$jsarray);
16851: if (ref($cats->[0]) eq 'ARRAY') {
16852: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16853: my $name = $cats->[0][$i];
16854: my $item = &escape($name).'::0';
16855: my $trailstr;
16856: if ($name eq 'instcode') {
16857: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16858: } elsif ($name eq 'communities') {
16859: $trailstr = &mt('Communities');
1.1239 raeburn 16860: } elsif ($name eq 'placement') {
16861: $trailstr = &mt('Placement Tests');
1.655 raeburn 16862: } else {
16863: $trailstr = $name;
16864: }
16865: if ($allitems->{$item} eq '') {
16866: push(@{$trails},$trailstr);
16867: $allitems->{$item} = scalar(@{$trails})-1;
16868: }
16869: my @parents = ($name);
16870: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16871: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16872: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16873: if (ref($subcats) eq 'HASH') {
16874: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16875: }
1.1321 raeburn 16876: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16877: }
16878: } else {
16879: if (ref($subcats) eq 'HASH') {
16880: $subcats->{$item} = [];
1.655 raeburn 16881: }
1.1321 raeburn 16882: if (ref($maxd) eq 'HASH') {
16883: $maxd->{$name} = 1;
16884: }
1.655 raeburn 16885: }
16886: }
16887: }
16888: }
16889: return;
16890: }
16891:
16892: =pod
16893:
1.1162 raeburn 16894: =item * &recurse_categories()
1.655 raeburn 16895:
16896: Recursively used to generate breadcrumb trails for course categories.
16897:
16898: Inputs:
1.663 raeburn 16899:
1.655 raeburn 16900: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16901: categories and subcategories).
1.663 raeburn 16902:
1.655 raeburn 16903: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16904:
16905: category (current course category, for which breadcrumb trail is being generated).
16906:
16907: trails (reference to array of breadcrumb trails for each category).
16908:
1.655 raeburn 16909: allitems (reference to hash - key is category key
16910: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16911:
1.655 raeburn 16912: parents (array containing containers directories for current category,
16913: back to top level).
16914:
16915: Returns: nothing
16916:
16917: Side effects: populates trails and allitems hash references
16918:
16919: =cut
16920:
16921: sub recurse_categories {
1.1321 raeburn 16922: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16923: my $shallower = $depth - 1;
16924: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16925: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16926: my $name = $cats->[$depth]{$category}[$k];
16927: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16928: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16929: if ($allitems->{$item} eq '') {
16930: push(@{$trails},$trailstr);
16931: $allitems->{$item} = scalar(@{$trails})-1;
16932: }
16933: my $deeper = $depth+1;
16934: push(@{$parents},$category);
1.665 raeburn 16935: if (ref($subcats) eq 'HASH') {
16936: my $subcat = &escape($name).':'.$category.':'.$depth;
16937: for (my $j=@{$parents}; $j>=0; $j--) {
16938: my $higher;
16939: if ($j > 0) {
16940: $higher = &escape($parents->[$j]).':'.
16941: &escape($parents->[$j-1]).':'.$j;
16942: } else {
16943: $higher = &escape($parents->[$j]).'::'.$j;
16944: }
16945: push(@{$subcats->{$higher}},$subcat);
16946: }
16947: }
16948: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16949: $subcats,$maxd);
1.655 raeburn 16950: pop(@{$parents});
16951: }
16952: } else {
16953: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16954: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16955: if ($allitems->{$item} eq '') {
16956: push(@{$trails},$trailstr);
16957: $allitems->{$item} = scalar(@{$trails})-1;
16958: }
1.1321 raeburn 16959: if (ref($maxd) eq 'HASH') {
16960: if ($depth > $maxd->{$parents->[0]}) {
16961: $maxd->{$parents->[0]} = $depth;
16962: }
16963: }
1.655 raeburn 16964: }
16965: return;
16966: }
16967:
1.663 raeburn 16968: =pod
16969:
1.1162 raeburn 16970: =item * &assign_categories_table()
1.663 raeburn 16971:
16972: Create a datatable for display of hierarchical categories in a domain,
16973: with checkboxes to allow a course to be categorized.
16974:
16975: Inputs:
16976:
16977: cathash - reference to hash of categories defined for the domain (from
16978: configuration.db)
16979:
16980: currcat - scalar with an & separated list of categories assigned to a course.
16981:
1.919 raeburn 16982: type - scalar contains course type (Course or Community).
16983:
1.1260 raeburn 16984: disabled - scalar (optional) contains disabled="disabled" if input elements are
16985: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16986:
1.663 raeburn 16987: Returns: $output (markup to be displayed)
16988:
16989: =cut
16990:
16991: sub assign_categories_table {
1.1259 raeburn 16992: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16993: my $output;
16994: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16995: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16996: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16997: $maxdepth = scalar(@cats);
16998: if (@cats > 0) {
16999: my $itemcount = 0;
17000: if (ref($cats[0]) eq 'ARRAY') {
17001: my @currcategories;
17002: if ($currcat ne '') {
17003: @currcategories = split('&',$currcat);
17004: }
1.919 raeburn 17005: my $table;
1.663 raeburn 17006: for (my $i=0; $i<@{$cats[0]}; $i++) {
17007: my $parent = $cats[0][$i];
1.919 raeburn 17008: next if ($parent eq 'instcode');
17009: if ($type eq 'Community') {
17010: next unless ($parent eq 'communities');
1.1239 raeburn 17011: } elsif ($type eq 'Placement') {
17012: next unless ($parent eq 'placement');
1.919 raeburn 17013: } else {
1.1239 raeburn 17014: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 17015: }
1.663 raeburn 17016: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
17017: my $item = &escape($parent).'::0';
17018: my $checked = '';
17019: if (@currcategories > 0) {
17020: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 17021: $checked = ' checked="checked"';
1.663 raeburn 17022: }
17023: }
1.919 raeburn 17024: my $parent_title = $parent;
17025: if ($parent eq 'communities') {
17026: $parent_title = &mt('Communities');
1.1239 raeburn 17027: } elsif ($parent eq 'placement') {
17028: $parent_title = &mt('Placement Tests');
1.919 raeburn 17029: }
17030: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
17031: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 17032: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 17033: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 17034: my $depth = 1;
17035: push(@path,$parent);
1.1259 raeburn 17036: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 17037: pop(@path);
1.919 raeburn 17038: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 17039: $itemcount ++;
17040: }
1.919 raeburn 17041: if ($itemcount) {
17042: $output = &Apache::loncommon::start_data_table().
17043: $table.
17044: &Apache::loncommon::end_data_table();
17045: }
1.663 raeburn 17046: }
17047: }
17048: }
17049: return $output;
17050: }
17051:
17052: =pod
17053:
1.1162 raeburn 17054: =item * &assign_category_rows()
1.663 raeburn 17055:
17056: Create a datatable row for display of nested categories in a domain,
17057: with checkboxes to allow a course to be categorized,called recursively.
17058:
17059: Inputs:
17060:
17061: itemcount - track row number for alternating colors
17062:
17063: cats - reference to array of arrays/hashes which encapsulates hierarchy of
17064: categories and subcategories.
17065:
17066: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
17067:
17068: parent - parent of current category item
17069:
17070: path - Array containing all categories back up through the hierarchy from the
17071: current category to the top level.
17072:
17073: currcategories - reference to array of current categories assigned to the course
17074:
1.1260 raeburn 17075: disabled - scalar (optional) contains disabled="disabled" if input elements are
17076: to be readonly (e.g., Domain Helpdesk role viewing course settings).
17077:
1.663 raeburn 17078: Returns: $output (markup to be displayed).
17079:
17080: =cut
17081:
17082: sub assign_category_rows {
1.1259 raeburn 17083: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 17084: my ($text,$name,$item,$chgstr);
17085: if (ref($cats) eq 'ARRAY') {
17086: my $maxdepth = scalar(@{$cats});
17087: if (ref($cats->[$depth]) eq 'HASH') {
17088: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
17089: my $numchildren = @{$cats->[$depth]{$parent}};
17090: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 17091: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 17092: for (my $j=0; $j<$numchildren; $j++) {
17093: $name = $cats->[$depth]{$parent}[$j];
17094: $item = &escape($name).':'.&escape($parent).':'.$depth;
17095: my $deeper = $depth+1;
17096: my $checked = '';
17097: if (ref($currcategories) eq 'ARRAY') {
17098: if (@{$currcategories} > 0) {
17099: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 17100: $checked = ' checked="checked"';
1.663 raeburn 17101: }
17102: }
17103: }
1.664 raeburn 17104: $text .= '<tr><td><span class="LC_nobreak"><label>'.
17105: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 17106: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 17107: '<input type="hidden" name="catname" value="'.$name.'" />'.
17108: '</td><td>';
1.663 raeburn 17109: if (ref($path) eq 'ARRAY') {
17110: push(@{$path},$name);
1.1259 raeburn 17111: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 17112: pop(@{$path});
17113: }
17114: $text .= '</td></tr>';
17115: }
17116: $text .= '</table></td>';
17117: }
17118: }
17119: }
17120: return $text;
17121: }
17122:
1.1181 raeburn 17123: =pod
17124:
17125: =back
17126:
17127: =cut
17128:
1.655 raeburn 17129: ############################################################
17130: ############################################################
17131:
17132:
1.443 albertel 17133: sub commit_customrole {
1.1408 raeburn 17134: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
1.1399 raeburn 17135: my $result = &Apache::lonnet::assigncustomrole(
1.1408 raeburn 17136: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
17137: $context,$othdomby,$requester);
1.630 raeburn 17138: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 17139: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 17140: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
17141: if (wantarray) {
17142: return ($output,$result);
17143: } else {
17144: return $output;
17145: }
1.443 albertel 17146: }
17147:
17148: sub commit_standardrole {
1.1408 raeburn 17149: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
17150: $othdomby,$requester) = @_;
1.1399 raeburn 17151: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 17152: if ($context eq 'auto') {
17153: $linefeed = "\n";
17154: } else {
17155: $linefeed = "<br />\n";
17156: }
1.443 albertel 17157: if ($three eq 'st') {
1.1399 raeburn 17158: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1408 raeburn 17159: $one,$two,$sec,$context,$credits,$othdomby,
17160: $requester);
1.541 raeburn 17161: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 17162: ($result eq 'unknown_course') || ($result eq 'refused')) {
17163: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 17164: } else {
1.541 raeburn 17165: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 17166: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 17167: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
17168: if ($context eq 'auto') {
17169: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
17170: } else {
17171: $output .= '<b>'.$result.'</b>'.$linefeed.
17172: &mt('Add to classlist').': <b>ok</b>';
17173: }
17174: $output .= $linefeed;
1.443 albertel 17175: }
17176: } else {
17177: $output = &mt('Assigning').' '.$three.' in '.$url.
17178: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 17179: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1408 raeburn 17180: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
17181: '','',$context,$othdomby,$requester);
1.541 raeburn 17182: if ($context eq 'auto') {
17183: $output .= $result.$linefeed;
17184: } else {
17185: $output .= '<b>'.$result.'</b>'.$linefeed;
17186: }
1.443 albertel 17187: }
1.1399 raeburn 17188: if (wantarray) {
17189: return ($output,$result);
17190: } else {
17191: return $output;
17192: }
1.443 albertel 17193: }
17194:
17195: sub commit_studentrole {
1.1116 raeburn 17196: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
1.1408 raeburn 17197: $credits,$othdomby,$requester) = @_;
1.626 raeburn 17198: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 17199: if ($context eq 'auto') {
17200: $linefeed = "\n";
17201: } else {
17202: $linefeed = '<br />'."\n";
17203: }
1.443 albertel 17204: if (defined($one) && defined($two)) {
17205: my $cid=$one.'_'.$two;
17206: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
17207: my $secchange = 0;
17208: my $expire_role_result;
17209: my $modify_section_result;
1.628 raeburn 17210: if ($oldsec ne '-1') {
17211: if ($oldsec ne $sec) {
1.443 albertel 17212: $secchange = 1;
1.628 raeburn 17213: my $now = time;
1.443 albertel 17214: my $uurl='/'.$cid;
17215: $uurl=~s/\_/\//g;
17216: if ($oldsec) {
17217: $uurl.='/'.$oldsec;
17218: }
1.626 raeburn 17219: $oldsecurl = $uurl;
1.628 raeburn 17220: $expire_role_result =
1.1408 raeburn 17221: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
17222: '','','',$context,$othdomby,$requester);
17223: if ($env{'request.course.sec'} ne '') {
1.628 raeburn 17224: if ($expire_role_result eq 'refused') {
17225: my @roles = ('st');
17226: my @statuses = ('previous');
17227: my @roledoms = ($one);
17228: my $withsec = 1;
17229: my %roleshash =
17230: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
17231: \@statuses,\@roles,\@roledoms,$withsec);
17232: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
17233: my ($oldstart,$oldend) =
17234: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
17235: if ($oldend > 0 && $oldend <= $now) {
17236: $expire_role_result = 'ok';
17237: }
17238: }
17239: }
17240: }
1.443 albertel 17241: $result = $expire_role_result;
17242: }
17243: }
17244: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 17245: $modify_section_result =
17246: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
17247: undef,undef,undef,$sec,
17248: $end,$start,'','',$cid,
1.1408 raeburn 17249: '',$context,$credits,'',
17250: $othdomby,$requester);
1.443 albertel 17251: if ($modify_section_result =~ /^ok/) {
17252: if ($secchange == 1) {
1.628 raeburn 17253: if ($sec eq '') {
17254: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
17255: } else {
17256: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
17257: }
1.443 albertel 17258: } elsif ($oldsec eq '-1') {
1.628 raeburn 17259: if ($sec eq '') {
17260: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
17261: } else {
17262: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
17263: }
1.443 albertel 17264: } else {
1.628 raeburn 17265: if ($sec eq '') {
17266: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
17267: } else {
17268: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
17269: }
1.443 albertel 17270: }
17271: } else {
1.1115 raeburn 17272: if ($secchange) {
1.628 raeburn 17273: $$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;
17274: } else {
17275: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
17276: }
1.443 albertel 17277: }
17278: $result = $modify_section_result;
17279: } elsif ($secchange == 1) {
1.628 raeburn 17280: if ($oldsec eq '') {
1.1103 raeburn 17281: $$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 17282: } else {
17283: $$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;
17284: }
1.626 raeburn 17285: if ($expire_role_result eq 'refused') {
17286: my $newsecurl = '/'.$cid;
17287: $newsecurl =~ s/\_/\//g;
17288: if ($sec ne '') {
17289: $newsecurl.='/'.$sec;
17290: }
17291: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
17292: if ($sec eq '') {
17293: $$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;
17294: } else {
17295: $$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;
17296: }
17297: }
17298: }
1.443 albertel 17299: }
17300: } else {
1.626 raeburn 17301: $$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 17302: $result = "error: incomplete course id\n";
17303: }
17304: return $result;
17305: }
17306:
1.1108 raeburn 17307: sub show_role_extent {
17308: my ($scope,$context,$role) = @_;
17309: $scope =~ s{^/}{};
17310: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
17311: push(@courseroles,'co');
17312: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
17313: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
17314: $scope =~ s{/}{_};
17315: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
17316: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
17317: my ($audom,$auname) = split(/\//,$scope);
17318: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
17319: &Apache::loncommon::plainname($auname,$audom).'</span>');
17320: } else {
17321: $scope =~ s{/$}{};
17322: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
17323: &Apache::lonnet::domain($scope,'description').'</span>');
17324: }
17325: }
17326:
1.443 albertel 17327: ############################################################
17328: ############################################################
17329:
1.566 albertel 17330: sub check_clone {
1.578 raeburn 17331: my ($args,$linefeed) = @_;
1.566 albertel 17332: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
17333: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
17334: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 17335: my $clonetitle;
17336: my @clonemsg;
1.566 albertel 17337: my $can_clone = 0;
1.944 raeburn 17338: my $lctype = lc($args->{'crstype'});
1.908 raeburn 17339: if ($lctype ne 'community') {
17340: $lctype = 'course';
17341: }
1.566 albertel 17342: if ($clonehome eq 'no_host') {
1.944 raeburn 17343: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17344: push(@clonemsg,({
17345: mt => 'No new community created.',
17346: args => [],
17347: },
17348: {
17349: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
17350: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
17351: }));
1.908 raeburn 17352: } else {
1.1344 raeburn 17353: push(@clonemsg,({
17354: mt => 'No new course created.',
17355: args => [],
17356: },
17357: {
17358: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
17359: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17360: }));
17361: }
1.566 albertel 17362: } else {
17363: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 17364: $clonetitle = $clonedesc{'description'};
1.944 raeburn 17365: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 17366: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 17367: push(@clonemsg,({
17368: mt => 'No new community created.',
17369: args => [],
17370: },
17371: {
17372: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
17373: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17374: }));
17375: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 17376: }
17377: }
1.1262 raeburn 17378: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 17379: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 17380: $can_clone = 1;
17381: } else {
1.1221 raeburn 17382: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 17383: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 17384: if ($clonehash{'cloners'} eq '') {
17385: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
17386: if ($domdefs{'canclone'}) {
17387: unless ($domdefs{'canclone'} eq 'none') {
17388: if ($domdefs{'canclone'} eq 'domain') {
17389: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
17390: $can_clone = 1;
17391: }
17392: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17393: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
17394: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
17395: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
17396: $can_clone = 1;
17397: }
17398: }
17399: }
17400: }
1.578 raeburn 17401: } else {
1.1221 raeburn 17402: my @cloners = split(/,/,$clonehash{'cloners'});
17403: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 17404: $can_clone = 1;
1.1221 raeburn 17405: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 17406: $can_clone = 1;
1.1225 raeburn 17407: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
17408: $can_clone = 1;
1.1221 raeburn 17409: }
17410: unless ($can_clone) {
1.1225 raeburn 17411: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17412: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 17413: my (%gotdomdefaults,%gotcodedefaults);
17414: foreach my $cloner (@cloners) {
17415: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
17416: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
17417: my (%codedefaults,@code_order);
17418: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
17419: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
17420: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
17421: }
17422: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
17423: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
17424: }
17425: } else {
17426: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
17427: \%codedefaults,
17428: \@code_order);
17429: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
17430: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
17431: }
17432: if (@code_order > 0) {
17433: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
17434: $cloner,$clonehash{'internal.coursecode'},
17435: $args->{'crscode'})) {
17436: $can_clone = 1;
17437: last;
17438: }
17439: }
17440: }
17441: }
17442: }
1.1225 raeburn 17443: }
17444: }
17445: unless ($can_clone) {
17446: my $ccrole = 'cc';
17447: if ($args->{'crstype'} eq 'Community') {
17448: $ccrole = 'co';
17449: }
17450: my %roleshash =
17451: &Apache::lonnet::get_my_roles($args->{'ccuname'},
17452: $args->{'ccdomain'},
17453: 'userroles',['active'],[$ccrole],
17454: [$args->{'clonedomain'}]);
17455: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
17456: $can_clone = 1;
17457: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
17458: $args->{'ccuname'},$args->{'ccdomain'})) {
17459: $can_clone = 1;
1.1221 raeburn 17460: }
17461: }
17462: unless ($can_clone) {
17463: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17464: push(@clonemsg,({
17465: mt => 'No new community created.',
17466: args => [],
17467: },
17468: {
17469: 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]).',
17470: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17471: }));
1.942 raeburn 17472: } else {
1.1344 raeburn 17473: push(@clonemsg,({
17474: mt => 'No new course created.',
17475: args => [],
17476: },
17477: {
17478: 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]).',
17479: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17480: }));
1.1221 raeburn 17481: }
1.566 albertel 17482: }
1.578 raeburn 17483: }
1.566 albertel 17484: }
1.1344 raeburn 17485: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17486: }
17487:
1.444 albertel 17488: sub construct_course {
1.1262 raeburn 17489: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 17490: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
17491: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 17492: my $linefeed = '<br />'."\n";
17493: if ($context eq 'auto') {
17494: $linefeed = "\n";
17495: }
1.566 albertel 17496:
17497: #
17498: # Are we cloning?
17499: #
1.1344 raeburn 17500: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17501: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 17502: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 17503: if (!$can_clone) {
1.1344 raeburn 17504: return (0,$outcome,$clonemsgref);
1.566 albertel 17505: }
17506: }
17507:
1.444 albertel 17508: #
17509: # Open course
17510: #
1.1239 raeburn 17511: my $showncrstype;
17512: if ($args->{'crstype'} eq 'Placement') {
17513: $showncrstype = 'placement test';
17514: } else {
17515: $showncrstype = lc($args->{'crstype'});
17516: }
1.444 albertel 17517: my %cenv=();
17518: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
17519: $args->{'cdescr'},
17520: $args->{'curl'},
17521: $args->{'course_home'},
17522: $args->{'nonstandard'},
17523: $args->{'crscode'},
17524: $args->{'ccuname'}.':'.
17525: $args->{'ccdomain'},
1.882 raeburn 17526: $args->{'crstype'},
1.1344 raeburn 17527: $cnum,$context,$category,
17528: $callercontext);
1.444 albertel 17529:
17530: # Note: The testing routines depend on this being output; see
17531: # Utils::Course. This needs to at least be output as a comment
17532: # if anyone ever decides to not show this, and Utils::Course::new
17533: # will need to be suitably modified.
1.1344 raeburn 17534: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17535: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17536: } else {
17537: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17538: }
1.943 raeburn 17539: if ($$courseid =~ /^error:/) {
1.1344 raeburn 17540: return (0,$outcome,$clonemsgref);
1.943 raeburn 17541: }
17542:
1.444 albertel 17543: #
17544: # Check if created correctly
17545: #
1.479 albertel 17546: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 17547: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 17548: if ($crsuhome eq 'no_host') {
1.1344 raeburn 17549: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17550: $outcome .= &mt_user($user_lh,
17551: 'Course creation failed, unrecognized course home server.');
17552: } else {
17553: $outcome .= &mt('Course creation failed, unrecognized course home server.');
17554: }
17555: $outcome .= $linefeed;
17556: return (0,$outcome,$clonemsgref);
1.943 raeburn 17557: }
1.541 raeburn 17558: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 17559:
1.444 albertel 17560: #
1.566 albertel 17561: # Do the cloning
17562: #
1.1344 raeburn 17563: my @clonemsg;
1.566 albertel 17564: if ($can_clone && $cloneid) {
1.1344 raeburn 17565: push(@clonemsg,
17566: {
17567: mt => 'Created [_1] by cloning from [_2]',
17568: args => [$showncrstype,$clonetitle],
17569: });
1.566 albertel 17570: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 17571: # Copy all files
1.1344 raeburn 17572: my @info =
17573: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
17574: $args->{'dateshift'},$args->{'crscode'},
17575: $args->{'ccuname'}.':'.$args->{'ccdomain'},
17576: $args->{'tinyurls'});
17577: if (@info) {
17578: push(@clonemsg,@info);
17579: }
1.444 albertel 17580: # Restore URL
1.566 albertel 17581: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 17582: # Restore title
1.566 albertel 17583: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 17584: # Restore creation date, creator and creation context.
17585: $cenv{'internal.created'}=$oldcenv{'internal.created'};
17586: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
17587: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 17588: # Mark as cloned
1.566 albertel 17589: $cenv{'clonedfrom'}=$cloneid;
1.638 www 17590: # Need to clone grading mode
17591: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
17592: $cenv{'grading'}=$newenv{'grading'};
17593: # Do not clone these environment entries
17594: &Apache::lonnet::del('environment',
17595: ['default_enrollment_start_date',
17596: 'default_enrollment_end_date',
17597: 'question.email',
17598: 'policy.email',
17599: 'comment.email',
17600: 'pch.users.denied',
1.725 raeburn 17601: 'plc.users.denied',
17602: 'hidefromcat',
1.1121 raeburn 17603: 'checkforpriv',
1.1355 raeburn 17604: 'categories'],
1.638 www 17605: $$crsudom,$$crsunum);
1.1170 raeburn 17606: if ($args->{'textbook'}) {
17607: $cenv{'internal.textbook'} = $args->{'textbook'};
17608: }
1.444 albertel 17609: }
1.566 albertel 17610:
1.444 albertel 17611: #
17612: # Set environment (will override cloned, if existing)
17613: #
17614: my @sections = ();
17615: my @xlists = ();
17616: if ($args->{'crstype'}) {
17617: $cenv{'type'}=$args->{'crstype'};
17618: }
1.1371 raeburn 17619: if ($args->{'lti'}) {
17620: $cenv{'internal.lti'}=$args->{'lti'};
17621: }
1.444 albertel 17622: if ($args->{'crsid'}) {
17623: $cenv{'courseid'}=$args->{'crsid'};
17624: }
17625: if ($args->{'crscode'}) {
17626: $cenv{'internal.coursecode'}=$args->{'crscode'};
17627: }
17628: if ($args->{'crsquota'} ne '') {
17629: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17630: } else {
17631: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17632: }
17633: if ($args->{'ccuname'}) {
17634: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17635: ':'.$args->{'ccdomain'};
17636: } else {
17637: $cenv{'internal.courseowner'} = $args->{'curruser'};
17638: }
1.1116 raeburn 17639: if ($args->{'defaultcredits'}) {
17640: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17641: }
1.444 albertel 17642: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1412 raeburn 17643: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 17644: if ($args->{'crssections'}) {
17645: $cenv{'internal.sectionnums'} = '';
17646: if ($args->{'crssections'} =~ m/,/) {
17647: @sections = split/,/,$args->{'crssections'};
17648: } else {
17649: $sections[0] = $args->{'crssections'};
17650: }
17651: if (@sections > 0) {
17652: foreach my $item (@sections) {
17653: my ($sec,$gp) = split/:/,$item;
17654: my $class = $args->{'crscode'}.$sec;
17655: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17656: $cenv{'internal.sectionnums'} .= $item.',';
1.1412 raeburn 17657: if ($addcheck eq 'ok') {
17658: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17659: push(@oklcsecs,$gp);
17660: }
17661: } else {
1.1263 raeburn 17662: push(@badclasses,$class);
1.444 albertel 17663: }
17664: }
17665: $cenv{'internal.sectionnums'} =~ s/,$//;
17666: }
17667: }
17668: # do not hide course coordinator from staff listing,
17669: # even if privileged
17670: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17671: # add course coordinator's domain to domains to check for privileged users
17672: # if different to course domain
17673: if ($$crsudom ne $args->{'ccdomain'}) {
17674: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17675: }
1.444 albertel 17676: # add crosslistings
17677: if ($args->{'crsxlist'}) {
17678: $cenv{'internal.crosslistings'}='';
17679: if ($args->{'crsxlist'} =~ m/,/) {
17680: @xlists = split/,/,$args->{'crsxlist'};
17681: } else {
17682: $xlists[0] = $args->{'crsxlist'};
17683: }
17684: if (@xlists > 0) {
17685: foreach my $item (@xlists) {
17686: my ($xl,$gp) = split/:/,$item;
17687: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17688: $cenv{'internal.crosslistings'} .= $item.',';
1.1412 raeburn 17689: if ($addcheck eq 'ok') {
17690: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17691: push(@oklcsecs,$gp);
17692: }
17693: } else {
1.1263 raeburn 17694: push(@badclasses,$xl);
1.444 albertel 17695: }
17696: }
17697: $cenv{'internal.crosslistings'} =~ s/,$//;
17698: }
17699: }
17700: if ($args->{'autoadds'}) {
17701: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17702: }
17703: if ($args->{'autodrops'}) {
17704: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17705: }
17706: # check for notification of enrollment changes
17707: my @notified = ();
17708: if ($args->{'notify_owner'}) {
17709: if ($args->{'ccuname'} ne '') {
17710: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17711: }
17712: }
17713: if ($args->{'notify_dc'}) {
17714: if ($uname ne '') {
1.630 raeburn 17715: push(@notified,$uname.':'.$udom);
1.444 albertel 17716: }
17717: }
17718: if (@notified > 0) {
17719: my $notifylist;
17720: if (@notified > 1) {
17721: $notifylist = join(',',@notified);
17722: } else {
17723: $notifylist = $notified[0];
17724: }
17725: $cenv{'internal.notifylist'} = $notifylist;
17726: }
17727: if (@badclasses > 0) {
17728: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17729: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17730: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17731: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17732: );
1.1264 raeburn 17733: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17734: &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 17735: if ($context eq 'auto') {
17736: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17737: } else {
1.566 albertel 17738: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17739: }
17740: foreach my $item (@badclasses) {
1.541 raeburn 17741: if ($context eq 'auto') {
1.1261 raeburn 17742: $outcome .= " - $item\n";
1.541 raeburn 17743: } else {
1.1261 raeburn 17744: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17745: }
1.1261 raeburn 17746: }
17747: if ($context eq 'auto') {
17748: $outcome .= $linefeed;
17749: } else {
17750: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17751: }
1.444 albertel 17752: }
17753: if ($args->{'no_end_date'}) {
17754: $args->{'endaccess'} = 0;
17755: }
1.1412 raeburn 17756: # If an official course with institutional sections is created by cloning
17757: # an existing course, section-specific hiding of course totals in student's
17758: # view of grades as copied from cloned course, will be checked for valid
17759: # sections.
17760: if (($can_clone && $cloneid) &&
17761: ($cenv{'internal.coursecode'} ne '') &&
17762: ($cenv{'grading'} eq 'standard') &&
17763: ($cenv{'hidetotals'} ne '') &&
17764: ($cenv{'hidetotals'} ne 'all')) {
17765: my @hidesecs;
17766: my $deletehidetotals;
17767: if (@oklcsecs) {
17768: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
17769: if (grep(/^\Q$sec$/,@oklcsecs)) {
17770: push(@hidesecs,$sec);
17771: }
17772: }
17773: if (@hidesecs) {
17774: $cenv{'hidetotals'} = join(',',@hidesecs);
17775: } else {
17776: $deletehidetotals = 1;
17777: }
17778: } else {
17779: $deletehidetotals = 1;
17780: }
17781: if ($deletehidetotals) {
17782: delete($cenv{'hidetotals'});
17783: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
17784: }
17785: }
1.444 albertel 17786: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17787: $cenv{'internal.autoend'}=$args->{'enrollend'};
17788: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17789: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17790: if ($args->{'showphotos'}) {
17791: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17792: }
17793: $cenv{'internal.authtype'} = $args->{'authtype'};
17794: $cenv{'internal.autharg'} = $args->{'autharg'};
17795: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17796: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17797: 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');
17798: if ($context eq 'auto') {
17799: $outcome .= $krb_msg;
17800: } else {
1.566 albertel 17801: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17802: }
17803: $outcome .= $linefeed;
1.444 albertel 17804: }
17805: }
17806: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17807: if ($args->{'setpolicy'}) {
17808: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17809: }
17810: if ($args->{'setcontent'}) {
17811: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17812: }
1.1251 raeburn 17813: if ($args->{'setcomment'}) {
17814: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17815: }
1.444 albertel 17816: }
17817: if ($args->{'reshome'}) {
17818: $cenv{'reshome'}=$args->{'reshome'}.'/';
17819: $cenv{'reshome'}=~s/\/+$/\//;
17820: }
17821: #
17822: # course has keyed access
17823: #
17824: if ($args->{'setkeys'}) {
17825: $cenv{'keyaccess'}='yes';
17826: }
17827: # if specified, key authority is not course, but user
17828: # only active if keyaccess is yes
17829: if ($args->{'keyauth'}) {
1.487 albertel 17830: my ($user,$domain) = split(':',$args->{'keyauth'});
17831: $user = &LONCAPA::clean_username($user);
17832: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17833: if ($user ne '' && $domain ne '') {
1.487 albertel 17834: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17835: }
17836: }
17837:
1.1166 raeburn 17838: #
1.1167 raeburn 17839: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17840: #
17841: if ($args->{'uniquecode'}) {
17842: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17843: if ($code) {
17844: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17845: my %crsinfo =
17846: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17847: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17848: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17849: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17850: }
1.1166 raeburn 17851: if (ref($coderef)) {
17852: $$coderef = $code;
17853: }
17854: }
17855: }
17856:
1.444 albertel 17857: if ($args->{'disresdis'}) {
17858: $cenv{'pch.roles.denied'}='st';
17859: }
17860: if ($args->{'disablechat'}) {
17861: $cenv{'plc.roles.denied'}='st';
17862: }
17863:
17864: # Record we've not yet viewed the Course Initialization Helper for this
17865: # course
17866: $cenv{'course.helper.not.run'} = 1;
17867: #
17868: # Use new Randomseed
17869: #
17870: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17871: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17872: #
17873: # The encryption code and receipt prefix for this course
17874: #
17875: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17876: $cenv{'internal.encpref'}=100+int(9*rand(99));
17877: #
17878: # By default, use standard grading
17879: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17880:
1.541 raeburn 17881: $outcome .= $linefeed.&mt('Setting environment').': '.
17882: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17883: #
17884: # Open all assignments
17885: #
17886: if ($args->{'openall'}) {
1.1341 raeburn 17887: my $opendate = time;
17888: if ($args->{'openallfrom'} =~ /^\d+$/) {
17889: $opendate = $args->{'openallfrom'};
17890: }
1.444 albertel 17891: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17892: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17893: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17894: $outcome .= &mt('All assignments open starting [_1]',
17895: &Apache::lonlocal::locallocaltime($opendate)).': '.
17896: &Apache::lonnet::cput
17897: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17898: }
17899: #
17900: # Set first page
17901: #
17902: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17903: || ($cloneid)) {
17904: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17905:
17906: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17907: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17908:
1.444 albertel 17909: $outcome .= ($fatal?$errtext:'read ok').' - ';
17910: my $title; my $url;
17911: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17912: $title=&mt('Syllabus');
1.444 albertel 17913: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17914: } else {
1.963 raeburn 17915: $title=&mt('Table of Contents');
1.444 albertel 17916: $url='/adm/navmaps';
17917: }
1.445 albertel 17918:
17919: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17920: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17921:
17922: if ($errtext) { $fatal=2; }
1.541 raeburn 17923: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17924: }
1.566 albertel 17925:
1.1237 raeburn 17926: #
17927: # Set params for Placement Tests
17928: #
1.1239 raeburn 17929: if ($args->{'crstype'} eq 'Placement') {
17930: my %storecontent;
17931: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17932: my %defaults = (
17933: buttonshide => { value => 'yes',
17934: type => 'string_yesno',},
17935: type => { value => 'randomizetry',
17936: type => 'string_questiontype',},
17937: maxtries => { value => 1,
17938: type => 'int_pos',},
17939: problemstatus => { value => 'no',
17940: type => 'string_problemstatus',},
17941: );
17942: foreach my $key (keys(%defaults)) {
17943: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17944: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17945: }
1.1237 raeburn 17946: &Apache::lonnet::cput
17947: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17948: }
17949:
1.1344 raeburn 17950: return (1,$outcome,\@clonemsg);
1.444 albertel 17951: }
17952:
1.1166 raeburn 17953: sub make_unique_code {
17954: my ($cdom,$cnum) = @_;
17955: # get lock on uniquecodes db
17956: my $lockhash = {
17957: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17958: ':'.$env{'user.domain'},
17959: };
17960: my $tries = 0;
17961: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17962: my ($code,$error);
17963:
17964: while (($gotlock ne 'ok') && ($tries<3)) {
17965: $tries ++;
17966: sleep 1;
17967: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17968: }
17969: if ($gotlock eq 'ok') {
17970: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17971: my $gotcode;
17972: my $attempts = 0;
17973: while ((!$gotcode) && ($attempts < 100)) {
17974: $code = &generate_code();
17975: if (!exists($currcodes{$code})) {
17976: $gotcode = 1;
17977: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17978: $error = 'nostore';
17979: }
17980: }
17981: $attempts ++;
17982: }
17983: my @del_lock = ($cnum."\0".'uniquecodes');
17984: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17985: } else {
17986: $error = 'nolock';
17987: }
17988: return ($code,$error);
17989: }
17990:
17991: sub generate_code {
17992: my $code;
17993: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17994: for (my $i=0; $i<6; $i++) {
17995: my $lettnum = int (rand 2);
17996: my $item = '';
17997: if ($lettnum) {
17998: $item = $letts[int( rand(18) )];
17999: } else {
18000: $item = 1+int( rand(8) );
18001: }
18002: $code .= $item;
18003: }
18004: return $code;
18005: }
18006:
1.444 albertel 18007: ############################################################
18008: ############################################################
18009:
1.1237 raeburn 18010: # Community, Course and Placement Test
1.378 raeburn 18011: sub course_type {
18012: my ($cid) = @_;
18013: if (!defined($cid)) {
18014: $cid = $env{'request.course.id'};
18015: }
1.404 albertel 18016: if (defined($env{'course.'.$cid.'.type'})) {
18017: return $env{'course.'.$cid.'.type'};
1.378 raeburn 18018: } else {
18019: return 'Course';
1.377 raeburn 18020: }
18021: }
1.156 albertel 18022:
1.406 raeburn 18023: sub group_term {
18024: my $crstype = &course_type();
18025: my %names = (
18026: 'Course' => 'group',
1.865 raeburn 18027: 'Community' => 'group',
1.1237 raeburn 18028: 'Placement' => 'group',
1.406 raeburn 18029: );
18030: return $names{$crstype};
18031: }
18032:
1.902 raeburn 18033: sub course_types {
1.1310 raeburn 18034: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 18035: my %typename = (
18036: official => 'Official course',
18037: unofficial => 'Unofficial course',
18038: community => 'Community',
1.1165 raeburn 18039: textbook => 'Textbook course',
1.1237 raeburn 18040: placement => 'Placement test',
1.1310 raeburn 18041: lti => 'LTI provider',
1.902 raeburn 18042: );
18043: return (\@types,\%typename);
18044: }
18045:
1.156 albertel 18046: sub icon {
18047: my ($file)=@_;
1.505 albertel 18048: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 18049: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 18050: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 18051: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
18052: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
18053: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
18054: $curfext.".gif") {
18055: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
18056: $curfext.".gif";
18057: }
18058: }
1.249 albertel 18059: return &lonhttpdurl($iconname);
1.154 albertel 18060: }
1.84 albertel 18061:
1.575 albertel 18062: sub lonhttpdurl {
1.692 www 18063: #
18064: # Had been used for "small fry" static images on separate port 8080.
18065: # Modify here if lightweight http functionality desired again.
18066: # Currently eliminated due to increasing firewall issues.
18067: #
1.575 albertel 18068: my ($url)=@_;
1.692 www 18069: return $url;
1.215 albertel 18070: }
18071:
1.213 albertel 18072: sub connection_aborted {
18073: my ($r)=@_;
18074: $r->print(" ");$r->rflush();
18075: my $c = $r->connection;
18076: return $c->aborted();
18077: }
18078:
1.221 foxr 18079: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 18080: # strings as 'strings'.
18081: sub escape_single {
1.221 foxr 18082: my ($input) = @_;
1.223 albertel 18083: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 18084: $input =~ s/\'/\\\'/g; # Esacpe the 's....
18085: return $input;
18086: }
1.223 albertel 18087:
1.222 foxr 18088: # Same as escape_single, but escape's "'s This
18089: # can be used for "strings"
18090: sub escape_double {
18091: my ($input) = @_;
18092: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
18093: $input =~ s/\"/\\\"/g; # Esacpe the "s....
18094: return $input;
18095: }
1.223 albertel 18096:
1.222 foxr 18097: # Escapes the last element of a full URL.
18098: sub escape_url {
18099: my ($url) = @_;
1.238 raeburn 18100: my @urlslices = split(/\//, $url,-1);
1.369 www 18101: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 18102: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 18103: }
1.462 albertel 18104:
1.820 raeburn 18105: sub compare_arrays {
18106: my ($arrayref1,$arrayref2) = @_;
18107: my (@difference,%count);
18108: @difference = ();
18109: %count = ();
18110: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
18111: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
18112: foreach my $element (keys(%count)) {
18113: if ($count{$element} == 1) {
18114: push(@difference,$element);
18115: }
18116: }
18117: }
18118: return @difference;
18119: }
18120:
1.1322 raeburn 18121: sub lon_status_items {
18122: my %defaults = (
18123: E => 100,
18124: W => 4,
18125: N => 1,
1.1324 raeburn 18126: U => 5,
1.1322 raeburn 18127: threshold => 200,
18128: sysmail => 2500,
18129: );
18130: my %names = (
18131: E => 'Errors',
18132: W => 'Warnings',
18133: N => 'Notices',
1.1324 raeburn 18134: U => 'Unsent',
1.1322 raeburn 18135: );
18136: return (\%defaults,\%names);
18137: }
18138:
1.817 bisitz 18139: # -------------------------------------------------------- Initialize user login
1.462 albertel 18140: sub init_user_environment {
1.463 albertel 18141: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 18142: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
18143:
18144: my $public=($username eq 'public' && $domain eq 'public');
18145:
1.1415 raeburn 18146: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
18147: $coauthorenv);
1.462 albertel 18148: my $now=time;
18149:
18150: if ($public) {
18151: my $max_public=100;
18152: my $oldest;
18153: my $oldest_time=0;
18154: for(my $next=1;$next<=$max_public;$next++) {
18155: if (-e $lonids."/publicuser_$next.id") {
18156: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
18157: if ($mtime<$oldest_time || !$oldest_time) {
18158: $oldest_time=$mtime;
18159: $oldest=$next;
18160: }
18161: } else {
18162: $cookie="publicuser_$next";
18163: last;
18164: }
18165: }
18166: if (!$cookie) { $cookie="publicuser_$oldest"; }
18167: } else {
1.1275 raeburn 18168: # See if old ID present, if so, remove if this isn't a robot,
18169: # killing any existing non-robot sessions
1.463 albertel 18170: if (!$args->{'robot'}) {
18171: opendir(DIR,$lonids);
18172: while ($filename=readdir(DIR)) {
18173: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 18174: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
18175: &GDBM_READER(),0640)) {
1.1295 raeburn 18176: my $linkedfile;
1.1320 raeburn 18177: if (exists($oldenv{'user.linkedenv'})) {
18178: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 18179: }
1.1320 raeburn 18180: untie(%oldenv);
18181: if (unlink("$lonids/$filename")) {
18182: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
18183: if (-l "$lonids/$linkedfile.id") {
18184: unlink("$lonids/$linkedfile.id");
18185: }
1.1295 raeburn 18186: }
18187: }
18188: } else {
18189: unlink($lonids.'/'.$filename);
18190: }
1.463 albertel 18191: }
1.462 albertel 18192: }
1.463 albertel 18193: closedir(DIR);
1.1204 raeburn 18194: # If there is a undeleted lockfile for the user's paste buffer remove it.
18195: my $namespace = 'nohist_courseeditor';
18196: my $lockingkey = 'paste'."\0".'locked_num';
18197: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
18198: $domain,$username);
18199: if (exists($lockhash{$lockingkey})) {
18200: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
18201: unless ($delresult eq 'ok') {
18202: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
18203: }
18204: }
1.462 albertel 18205: }
18206: # Give them a new cookie
1.463 albertel 18207: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 18208: : $now.$$.int(rand(10000)));
1.463 albertel 18209: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 18210:
18211: # Initialize roles
18212:
1.1414 raeburn 18213: ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 18214: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 18215: }
18216: # ------------------------------------ Check browser type and MathML capability
18217:
1.1194 raeburn 18218: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
18219: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 18220:
18221: # ------------------------------------------------------------- Get environment
18222:
18223: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
18224: my ($tmp) = keys(%userenv);
1.1275 raeburn 18225: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 18226: undef(%userenv);
18227: }
18228: if (($userenv{'interface'}) && (!$form->{'interface'})) {
18229: $form->{'interface'}=$userenv{'interface'};
18230: }
18231: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
18232:
18233: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 18234: foreach my $option ('interface','localpath','localres') {
18235: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 18236: }
18237: # --------------------------------------------------------- Write first profile
18238:
18239: {
1.1350 raeburn 18240: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 18241: my %initial_env =
18242: ("user.name" => $username,
18243: "user.domain" => $domain,
18244: "user.home" => $authhost,
18245: "browser.type" => $clientbrowser,
18246: "browser.version" => $clientversion,
18247: "browser.mathml" => $clientmathml,
18248: "browser.unicode" => $clientunicode,
18249: "browser.os" => $clientos,
1.1137 raeburn 18250: "browser.mobile" => $clientmobile,
1.1141 raeburn 18251: "browser.info" => $clientinfo,
1.1194 raeburn 18252: "browser.osversion" => $clientosversion,
1.462 albertel 18253: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
18254: "request.course.fn" => '',
18255: "request.course.uri" => '',
18256: "request.course.sec" => '',
18257: "request.role" => 'cm',
18258: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 18259: "request.host" => $ip,);
1.462 albertel 18260:
18261: if ($form->{'localpath'}) {
18262: $initial_env{"browser.localpath"} = $form->{'localpath'};
18263: $initial_env{"browser.localres"} = $form->{'localres'};
18264: }
18265:
18266: if ($form->{'interface'}) {
18267: $form->{'interface'}=~s/\W//gs;
18268: $initial_env{"browser.interface"} = $form->{'interface'};
18269: $env{'browser.interface'}=$form->{'interface'};
18270: }
18271:
1.1157 raeburn 18272: if ($form->{'iptoken'}) {
18273: my $lonhost = $r->dir_config('lonHostID');
18274: $initial_env{"user.noloadbalance"} = $lonhost;
18275: $env{'user.noloadbalance'} = $lonhost;
18276: }
18277:
1.1268 raeburn 18278: if ($form->{'noloadbalance'}) {
18279: my @hosts = &Apache::lonnet::current_machine_ids();
18280: my $hosthere = $form->{'noloadbalance'};
18281: if (grep(/^\Q$hosthere\E$/,@hosts)) {
18282: $initial_env{"user.noloadbalance"} = $hosthere;
18283: $env{'user.noloadbalance'} = $hosthere;
18284: }
18285: }
18286:
1.1016 raeburn 18287: unless ($domain eq 'public') {
1.1273 raeburn 18288: my %is_adv = ( is_adv => $env{'user.adv'} );
18289: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
18290:
1.1414 raeburn 18291: foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
18292: $userenv{'availabletools.'.$tool} =
1.1273 raeburn 18293: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
18294: undef,\%userenv,\%domdef,\%is_adv);
18295: }
1.980 raeburn 18296:
1.1311 raeburn 18297: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 18298: $userenv{'canrequest.'.$crstype} =
18299: &Apache::lonnet::usertools_access($username,$domain,$crstype,
18300: 'reload','requestcourses',
18301: \%userenv,\%domdef,\%is_adv);
18302: }
1.724 raeburn 18303:
1.1418 raeburn 18304: if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
18305: (exists($userroles->{"user.role.au./$domain/"}))) {
18306: if ($userenv{'authoreditors'}) {
18307: $userenv{'editors'} = $userenv{'authoreditors'};
18308: } elsif ($domdef{'editors'} ne '') {
18309: $userenv{'editors'} = $domdef{'editors'};
18310: } else {
18311: $userenv{'editors'} = 'edit,xml';
18312: }
1.1431 raeburn 18313: if ($userenv{'authorarchive'}) {
18314: $userenv{'canarchive'} = 1;
18315: } elsif (($userenv{'authorarchive'} eq '') &&
18316: ($domdef{'archive'})) {
18317: $userenv{'canarchive'} = 1;
18318: }
1.1418 raeburn 18319: }
18320:
1.1273 raeburn 18321: $userenv{'canrequest.author'} =
18322: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
18323: 'reload','requestauthor',
1.980 raeburn 18324: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 18325: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
18326: $domain,$username);
18327: my $reqstatus = $reqauthor{'author_status'};
18328: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
18329: if (ref($reqauthor{'author'}) eq 'HASH') {
18330: $userenv{'requestauthorqueued'} = $reqstatus.':'.
18331: $reqauthor{'author'}{'timestamp'};
18332: }
1.1092 raeburn 18333: }
1.1287 raeburn 18334: my ($types,$typename) = &course_types();
18335: if (ref($types) eq 'ARRAY') {
18336: my @options = ('approval','validate','autolimit');
18337: my $optregex = join('|',@options);
18338: my (%willtrust,%trustchecked);
18339: foreach my $type (@{$types}) {
18340: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
18341: if ($dom_str ne '') {
18342: my $updatedstr = '';
18343: my @possdomains = split(',',$dom_str);
18344: foreach my $entry (@possdomains) {
18345: my ($extdom,$extopt) = split(':',$entry);
18346: unless ($trustchecked{$extdom}) {
18347: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
18348: $trustchecked{$extdom} = 1;
18349: }
18350: if ($willtrust{$extdom}) {
18351: $updatedstr .= $entry.',';
18352: }
18353: }
18354: $updatedstr =~ s/,$//;
18355: if ($updatedstr) {
18356: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
18357: } else {
18358: delete($userenv{'reqcrsotherdom.'.$type});
18359: }
18360: }
18361: }
18362: }
1.1092 raeburn 18363: }
1.462 albertel 18364: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 18365:
1.462 albertel 18366: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
18367: &GDBM_WRCREAT(),0640)) {
18368: &_add_to_env(\%disk_env,\%initial_env);
18369: &_add_to_env(\%disk_env,\%userenv,'environment.');
18370: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 18371: if (ref($firstaccenv) eq 'HASH') {
18372: &_add_to_env(\%disk_env,$firstaccenv);
18373: }
18374: if (ref($timerintenv) eq 'HASH') {
18375: &_add_to_env(\%disk_env,$timerintenv);
18376: }
1.1414 raeburn 18377: if (ref($coauthorenv) eq 'HASH') {
18378: if (keys(%{$coauthorenv})) {
18379: &_add_to_env(\%disk_env,$coauthorenv);
18380: }
18381: }
1.463 albertel 18382: if (ref($args->{'extra_env'})) {
18383: &_add_to_env(\%disk_env,$args->{'extra_env'});
18384: }
1.462 albertel 18385: untie(%disk_env);
18386: } else {
1.705 tempelho 18387: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
18388: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 18389: return 'error: '.$!;
18390: }
18391: }
18392: $env{'request.role'}='cm';
18393: $env{'request.role.adv'}=$env{'user.adv'};
18394: $env{'browser.type'}=$clientbrowser;
18395:
18396: return $cookie;
18397:
18398: }
18399:
18400: sub _add_to_env {
18401: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 18402: if (ref($env_data) eq 'HASH') {
18403: while (my ($key,$value) = each(%$env_data)) {
18404: $idf->{$prefix.$key} = $value;
18405: $env{$prefix.$key} = $value;
18406: }
1.462 albertel 18407: }
18408: }
18409:
1.685 tempelho 18410: # --- Get the symbolic name of a problem and the url
18411: sub get_symb {
18412: my ($request,$silent) = @_;
1.726 raeburn 18413: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 18414: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
18415: if ($symb eq '') {
18416: if (!$silent) {
1.1071 raeburn 18417: if (ref($request)) {
18418: $request->print("Unable to handle ambiguous references:$url:.");
18419: }
1.685 tempelho 18420: return ();
18421: }
18422: }
18423: &Apache::lonenc::check_decrypt(\$symb);
18424: return ($symb);
18425: }
18426:
18427: # --------------------------------------------------------------Get annotation
18428:
18429: sub get_annotation {
18430: my ($symb,$enc) = @_;
18431:
18432: my $key = $symb;
18433: if (!$enc) {
18434: $key =
18435: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
18436: }
18437: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
18438: return $annotation{$key};
18439: }
18440:
18441: sub clean_symb {
1.731 raeburn 18442: my ($symb,$delete_enc) = @_;
1.685 tempelho 18443:
18444: &Apache::lonenc::check_decrypt(\$symb);
18445: my $enc = $env{'request.enc'};
1.731 raeburn 18446: if ($delete_enc) {
1.730 raeburn 18447: delete($env{'request.enc'});
18448: }
1.685 tempelho 18449:
18450: return ($symb,$enc);
18451: }
1.462 albertel 18452:
1.1181 raeburn 18453: ############################################################
18454: ############################################################
18455:
18456: =pod
18457:
18458: =head1 Routines for building display used to search for courses
18459:
18460:
18461: =over 4
18462:
18463: =item * &build_filters()
18464:
18465: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 18466: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
18467: and quotacheck.pl
18468:
1.1181 raeburn 18469:
18470: Inputs:
18471:
18472: filterlist - anonymous array of fields to include as potential filters
18473:
18474: crstype - course type
18475:
18476: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
18477: to pop-open a course selector (will contain "extra element").
18478:
18479: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
18480:
18481: filter - anonymous hash of criteria and their values
18482:
18483: action - form action
18484:
18485: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
18486:
1.1182 raeburn 18487: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 18488:
18489: cloneruname - username of owner of new course who wants to clone
18490:
18491: clonerudom - domain of owner of new course who wants to clone
18492:
18493: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
18494:
18495: codetitlesref - reference to array of titles of components in institutional codes (official courses)
18496:
18497: codedom - domain
18498:
18499: formname - value of form element named "form".
18500:
18501: fixeddom - domain, if fixed.
18502:
18503: prevphase - value to assign to form element named "phase" when going back to the previous screen
18504:
18505: cnameelement - name of form element in form on opener page which will receive title of selected course
18506:
18507: cnumelement - name of form element in form on opener page which will receive courseID of selected course
18508:
18509: cdomelement - name of form element in form on opener page which will receive domain of selected course
18510:
18511: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
18512:
18513: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
18514:
18515: clonewarning - warning message about missing information for intended course owner when DC creates a course
18516:
1.1182 raeburn 18517:
1.1181 raeburn 18518: Returns: $output - HTML for display of search criteria, and hidden form elements.
18519:
1.1182 raeburn 18520:
1.1181 raeburn 18521: Side Effects: None
18522:
18523: =cut
18524:
18525: # ---------------------------------------------- search for courses based on last activity etc.
18526:
18527: sub build_filters {
18528: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
18529: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
18530: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
18531: $cnameelement,$cnumelement,$cdomelement,$setroles,
18532: $clonetext,$clonewarning) = @_;
1.1182 raeburn 18533: my ($list,$jscript);
1.1181 raeburn 18534: my $onchange = 'javascript:updateFilters(this)';
18535: my ($domainselectform,$sincefilterform,$createdfilterform,
18536: $ownerdomselectform,$persondomselectform,$instcodeform,
18537: $typeselectform,$instcodetitle);
18538: if ($formname eq '') {
18539: $formname = $caller;
18540: }
18541: foreach my $item (@{$filterlist}) {
18542: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
18543: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
18544: if ($item eq 'domainfilter') {
18545: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
18546: } elsif ($item eq 'coursefilter') {
18547: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
18548: } elsif ($item eq 'ownerfilter') {
18549: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18550: } elsif ($item eq 'ownerdomfilter') {
18551: $filter->{'ownerdomfilter'} =
18552: &LONCAPA::clean_domain($filter->{$item});
18553: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
18554: 'ownerdomfilter',1);
18555: } elsif ($item eq 'personfilter') {
18556: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18557: } elsif ($item eq 'persondomfilter') {
18558: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
18559: 'persondomfilter',1);
18560: } else {
18561: $filter->{$item} =~ s/\W//g;
18562: }
18563: if (!$filter->{$item}) {
18564: $filter->{$item} = '';
18565: }
18566: }
18567: if ($item eq 'domainfilter') {
18568: my $allow_blank = 1;
18569: if ($formname eq 'portform') {
18570: $allow_blank=0;
18571: } elsif ($formname eq 'studentform') {
18572: $allow_blank=0;
18573: }
18574: if ($fixeddom) {
18575: $domainselectform = '<input type="hidden" name="domainfilter"'.
18576: ' value="'.$codedom.'" />'.
18577: &Apache::lonnet::domain($codedom,'description');
18578: } else {
18579: $domainselectform = &select_dom_form($filter->{$item},
18580: 'domainfilter',
18581: $allow_blank,'',$onchange);
18582: }
18583: } else {
18584: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
18585: }
18586: }
18587:
18588: # last course activity filter and selection
18589: $sincefilterform = &timebased_select_form('sincefilter',$filter);
18590:
18591: # course created filter and selection
18592: if (exists($filter->{'createdfilter'})) {
18593: $createdfilterform = &timebased_select_form('createdfilter',$filter);
18594: }
18595:
1.1239 raeburn 18596: my $prefix = $crstype;
18597: if ($crstype eq 'Placement') {
18598: $prefix = 'Placement Test'
18599: }
1.1181 raeburn 18600: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 18601: 'cac' => "$prefix Activity",
18602: 'ccr' => "$prefix Created",
18603: 'cde' => "$prefix Title",
18604: 'cdo' => "$prefix Domain",
1.1181 raeburn 18605: 'ins' => 'Institutional Code',
18606: 'inc' => 'Institutional Categorization',
1.1239 raeburn 18607: 'cow' => "$prefix Owner/Co-owner",
18608: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 18609: 'cog' => 'Type',
18610: );
18611:
18612: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18613: my $typeval = 'Course';
18614: if ($crstype eq 'Community') {
18615: $typeval = 'Community';
1.1239 raeburn 18616: } elsif ($crstype eq 'Placement') {
18617: $typeval = 'Placement';
1.1181 raeburn 18618: }
18619: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
18620: } else {
18621: $typeselectform = '<select name="type" size="1"';
18622: if ($onchange) {
18623: $typeselectform .= ' onchange="'.$onchange.'"';
18624: }
18625: $typeselectform .= '>'."\n";
1.1237 raeburn 18626: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 18627: my $shown;
18628: if ($posstype eq 'Placement') {
18629: $shown = &mt('Placement Test');
18630: } else {
18631: $shown = &mt($posstype);
18632: }
1.1181 raeburn 18633: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 18634: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 18635: }
18636: $typeselectform.="</select>";
18637: }
18638:
18639: my ($cloneableonlyform,$cloneabletitle);
18640: if (exists($filter->{'cloneableonly'})) {
18641: my $cloneableon = '';
18642: my $cloneableoff = ' checked="checked"';
18643: if ($filter->{'cloneableonly'}) {
18644: $cloneableon = $cloneableoff;
18645: $cloneableoff = '';
18646: }
18647: $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>';
18648: if ($formname eq 'ccrs') {
1.1187 bisitz 18649: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 18650: } else {
18651: $cloneabletitle = &mt('Cloneable by you');
18652: }
18653: }
18654: my $officialjs;
18655: if ($crstype eq 'Course') {
18656: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 18657: # if (($fixeddom) || ($formname eq 'requestcrs') ||
18658: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
18659: if ($codedom) {
1.1181 raeburn 18660: $officialjs = 1;
18661: ($instcodeform,$jscript,$$numtitlesref) =
18662: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
18663: $officialjs,$codetitlesref);
18664: if ($jscript) {
1.1182 raeburn 18665: $jscript = '<script type="text/javascript">'."\n".
18666: '// <![CDATA['."\n".
18667: $jscript."\n".
18668: '// ]]>'."\n".
18669: '</script>'."\n";
1.1181 raeburn 18670: }
18671: }
18672: if ($instcodeform eq '') {
18673: $instcodeform =
18674: '<input type="text" name="instcodefilter" size="10" value="'.
18675: $list->{'instcodefilter'}.'" />';
18676: $instcodetitle = $lt{'ins'};
18677: } else {
18678: $instcodetitle = $lt{'inc'};
18679: }
18680: if ($fixeddom) {
18681: $instcodetitle .= '<br />('.$codedom.')';
18682: }
18683: }
18684: }
18685: my $output = qq|
18686: <form method="post" name="filterpicker" action="$action">
18687: <input type="hidden" name="form" value="$formname" />
18688: |;
18689: if ($formname eq 'modifycourse') {
18690: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18691: '<input type="hidden" name="prevphase" value="'.
18692: $prevphase.'" />'."\n";
1.1198 musolffc 18693: } elsif ($formname eq 'quotacheck') {
18694: $output .= qq|
18695: <input type="hidden" name="sortby" value="" />
18696: <input type="hidden" name="sortorder" value="" />
18697: |;
18698: } else {
1.1181 raeburn 18699: my $name_input;
18700: if ($cnameelement ne '') {
18701: $name_input = '<input type="hidden" name="cnameelement" value="'.
18702: $cnameelement.'" />';
18703: }
18704: $output .= qq|
1.1182 raeburn 18705: <input type="hidden" name="cnumelement" value="$cnumelement" />
18706: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18707: $name_input
18708: $roleelement
18709: $multelement
18710: $typeelement
18711: |;
18712: if ($formname eq 'portform') {
18713: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18714: }
18715: }
18716: if ($fixeddom) {
18717: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18718: }
18719: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18720: if ($sincefilterform) {
18721: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18722: .$sincefilterform
18723: .&Apache::lonhtmlcommon::row_closure();
18724: }
18725: if ($createdfilterform) {
18726: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18727: .$createdfilterform
18728: .&Apache::lonhtmlcommon::row_closure();
18729: }
18730: if ($domainselectform) {
18731: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18732: .$domainselectform
18733: .&Apache::lonhtmlcommon::row_closure();
18734: }
18735: if ($typeselectform) {
18736: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18737: $output .= $typeselectform;
18738: } else {
18739: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18740: .$typeselectform
18741: .&Apache::lonhtmlcommon::row_closure();
18742: }
18743: }
18744: if ($instcodeform) {
18745: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18746: .$instcodeform
18747: .&Apache::lonhtmlcommon::row_closure();
18748: }
18749: if (exists($filter->{'ownerfilter'})) {
18750: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18751: '<table><tr><td>'.&mt('Username').'<br />'.
18752: '<input type="text" name="ownerfilter" size="20" value="'.
18753: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18754: $ownerdomselectform.'</td></tr></table>'.
18755: &Apache::lonhtmlcommon::row_closure();
18756: }
18757: if (exists($filter->{'personfilter'})) {
18758: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18759: '<table><tr><td>'.&mt('Username').'<br />'.
18760: '<input type="text" name="personfilter" size="20" value="'.
18761: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18762: $persondomselectform.'</td></tr></table>'.
18763: &Apache::lonhtmlcommon::row_closure();
18764: }
18765: if (exists($filter->{'coursefilter'})) {
18766: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18767: .'<input type="text" name="coursefilter" size="25" value="'
18768: .$list->{'coursefilter'}.'" />'
18769: .&Apache::lonhtmlcommon::row_closure();
18770: }
18771: if ($cloneableonlyform) {
18772: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18773: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18774: }
18775: if (exists($filter->{'descriptfilter'})) {
18776: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18777: .'<input type="text" name="descriptfilter" size="40" value="'
18778: .$list->{'descriptfilter'}.'" />'
18779: .&Apache::lonhtmlcommon::row_closure(1);
18780: }
18781: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18782: '<input type="hidden" name="updater" value="" />'."\n".
18783: '<input type="submit" name="gosearch" value="'.
18784: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18785: return $jscript.$clonewarning.$output;
18786: }
18787:
18788: =pod
18789:
18790: =item * &timebased_select_form()
18791:
1.1182 raeburn 18792: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18793: filter e.g., Course Activity, Course Created, when searching for courses
18794: or communities
18795:
18796: Inputs:
18797:
18798: item - name of form element (sincefilter or createdfilter)
18799:
18800: filter - anonymous hash of criteria and their values
18801:
18802: Returns: HTML for a select box contained a blank, then six time selections,
18803: with value set in incoming form variables currently selected.
18804:
18805: Side Effects: None
18806:
18807: =cut
18808:
18809: sub timebased_select_form {
18810: my ($item,$filter) = @_;
18811: if (ref($filter) eq 'HASH') {
18812: $filter->{$item} =~ s/[^\d-]//g;
18813: if (!$filter->{$item}) { $filter->{$item}=-1; }
18814: return &select_form(
18815: $filter->{$item},
18816: $item,
18817: { '-1' => '',
18818: '86400' => &mt('today'),
18819: '604800' => &mt('last week'),
18820: '2592000' => &mt('last month'),
18821: '7776000' => &mt('last three months'),
18822: '15552000' => &mt('last six months'),
18823: '31104000' => &mt('last year'),
18824: 'select_form_order' =>
18825: ['-1','86400','604800','2592000','7776000',
18826: '15552000','31104000']});
18827: }
18828: }
18829:
18830: =pod
18831:
18832: =item * &js_changer()
18833:
18834: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18835: when course type or domain is changed, and also to hide 'Searching ...' on
18836: page load completion for page showing search result.
1.1181 raeburn 18837:
18838: Inputs: None
18839:
1.1183 raeburn 18840: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18841:
18842: Side Effects: None
18843:
18844: =cut
18845:
18846: sub js_changer {
18847: return <<ENDJS;
18848: <script type="text/javascript">
18849: // <![CDATA[
18850: function updateFilters(caller) {
18851: if (typeof(caller) != "undefined") {
18852: document.filterpicker.updater.value = caller.name;
18853: }
18854: document.filterpicker.submit();
18855: }
1.1183 raeburn 18856:
18857: function hideSearching() {
18858: if (document.getElementById('searching')) {
18859: document.getElementById('searching').style.display = 'none';
18860: }
18861: return;
18862: }
18863:
1.1181 raeburn 18864: // ]]>
18865: </script>
18866:
18867: ENDJS
18868: }
18869:
18870: =pod
18871:
1.1182 raeburn 18872: =item * &search_courses()
18873:
18874: Process selected filters form course search form and pass to lonnet::courseiddump
18875: to retrieve a hash for which keys are courseIDs which match the selected filters.
18876:
18877: Inputs:
18878:
18879: dom - domain being searched
18880:
18881: type - course type ('Course' or 'Community' or '.' if any).
18882:
18883: filter - anonymous hash of criteria and their values
18884:
18885: numtitles - for institutional codes - number of categories
18886:
18887: cloneruname - optional username of new course owner
18888:
18889: clonerudom - optional domain of new course owner
18890:
1.1221 raeburn 18891: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18892: (used when DC is using course creation form)
18893:
18894: codetitles - reference to array of titles of components in institutional codes (official courses).
18895:
1.1221 raeburn 18896: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18897: (and so can clone automatically)
18898:
18899: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18900:
18901: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18902: courses to clone
1.1182 raeburn 18903:
18904: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18905:
18906:
18907: Side Effects: None
18908:
18909: =cut
18910:
18911:
18912: sub search_courses {
1.1221 raeburn 18913: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18914: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18915: my (%courses,%showcourses,$cloner);
18916: if (($filter->{'ownerfilter'} ne '') ||
18917: ($filter->{'ownerdomfilter'} ne '')) {
18918: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18919: $filter->{'ownerdomfilter'};
18920: }
18921: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18922: if (!$filter->{$item}) {
18923: $filter->{$item}='.';
18924: }
18925: }
18926: my $now = time;
18927: my $timefilter =
18928: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18929: my ($createdbefore,$createdafter);
18930: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18931: $createdbefore = $now;
18932: $createdafter = $now-$filter->{'createdfilter'};
18933: }
18934: my ($instcodefilter,$regexpok);
18935: if ($numtitles) {
18936: if ($env{'form.official'} eq 'on') {
18937: $instcodefilter =
18938: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18939: $regexpok = 1;
18940: } elsif ($env{'form.official'} eq 'off') {
18941: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18942: unless ($instcodefilter eq '') {
18943: $regexpok = -1;
18944: }
18945: }
18946: } else {
18947: $instcodefilter = $filter->{'instcodefilter'};
18948: }
18949: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18950: if ($type eq '') { $type = '.'; }
18951:
18952: if (($clonerudom ne '') && ($cloneruname ne '')) {
18953: $cloner = $cloneruname.':'.$clonerudom;
18954: }
18955: %courses = &Apache::lonnet::courseiddump($dom,
18956: $filter->{'descriptfilter'},
18957: $timefilter,
18958: $instcodefilter,
18959: $filter->{'combownerfilter'},
18960: $filter->{'coursefilter'},
18961: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18962: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18963: $filter->{'cloneableonly'},
18964: $createdbefore,$createdafter,undef,
1.1221 raeburn 18965: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18966: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18967: my $ccrole;
18968: if ($type eq 'Community') {
18969: $ccrole = 'co';
18970: } else {
18971: $ccrole = 'cc';
18972: }
18973: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18974: $filter->{'persondomfilter'},
18975: 'userroles',undef,
18976: [$ccrole,'in','ad','ep','ta','cr'],
18977: $dom);
18978: foreach my $role (keys(%rolehash)) {
18979: my ($cnum,$cdom,$courserole) = split(':',$role);
18980: my $cid = $cdom.'_'.$cnum;
18981: if (exists($courses{$cid})) {
18982: if (ref($courses{$cid}) eq 'HASH') {
18983: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18984: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18985: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18986: }
18987: } else {
18988: $courses{$cid}{roles} = [$courserole];
18989: }
18990: $showcourses{$cid} = $courses{$cid};
18991: }
18992: }
18993: }
18994: %courses = %showcourses;
18995: }
18996: return %courses;
18997: }
18998:
18999: =pod
19000:
1.1181 raeburn 19001: =back
19002:
1.1207 raeburn 19003: =head1 Routines for version requirements for current course.
19004:
19005: =over 4
19006:
19007: =item * &check_release_required()
19008:
19009: Compares required LON-CAPA version with version on server, and
19010: if required version is newer looks for a server with the required version.
19011:
19012: Looks first at servers in user's owen domain; if none suitable, looks at
19013: servers in course's domain are permitted to host sessions for user's domain.
19014:
19015: Inputs:
19016:
19017: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
19018:
19019: $courseid - Course ID of current course
19020:
19021: $rolecode - User's current role in course (for switchserver query string).
19022:
19023: $required - LON-CAPA version needed by course (format: Major.Minor).
19024:
19025:
19026: Returns:
19027:
19028: $switchserver - query string tp append to /adm/switchserver call (if
19029: current server's LON-CAPA version is too old.
19030:
19031: $warning - Message is displayed if no suitable server could be found.
19032:
19033: =cut
19034:
19035: sub check_release_required {
19036: my ($loncaparev,$courseid,$rolecode,$required) = @_;
19037: my ($switchserver,$warning);
19038: if ($required ne '') {
19039: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
19040: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
19041: if ($reqdmajor ne '' && $reqdminor ne '') {
19042: my $otherserver;
19043: if (($major eq '' && $minor eq '') ||
19044: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
19045: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
19046: my $switchlcrev =
19047: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
19048: $userdomserver);
19049: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
19050: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
19051: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
19052: my $cdom = $env{'course.'.$courseid.'.domain'};
19053: if ($cdom ne $env{'user.domain'}) {
19054: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
19055: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
19056: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
19057: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
19058: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
19059: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
19060: my $canhost =
19061: &Apache::lonnet::can_host_session($env{'user.domain'},
19062: $coursedomserver,
19063: $remoterev,
19064: $udomdefaults{'remotesessions'},
19065: $defdomdefaults{'hostedsessions'});
19066:
19067: if ($canhost) {
19068: $otherserver = $coursedomserver;
19069: } else {
19070: $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.");
19071: }
19072: } else {
19073: $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).");
19074: }
19075: } else {
19076: $otherserver = $userdomserver;
19077: }
19078: }
19079: if ($otherserver ne '') {
19080: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
19081: }
19082: }
19083: }
19084: return ($switchserver,$warning);
19085: }
19086:
19087: =pod
19088:
19089: =item * &check_release_result()
19090:
19091: Inputs:
19092:
19093: $switchwarning - Warning message if no suitable server found to host session.
19094:
19095: $switchserver - query string to append to /adm/switchserver containing lonHostID
19096: and current role.
19097:
19098: Returns: HTML to display with information about requirement to switch server.
19099: Either displaying warning with link to Roles/Courses screen or
19100: display link to switchserver.
19101:
1.1181 raeburn 19102: =cut
19103:
1.1207 raeburn 19104: sub check_release_result {
19105: my ($switchwarning,$switchserver) = @_;
19106: my $output = &start_page('Selected course unavailable on this server').
1.1463 raeburn 19107: '<div class="LC_landmark" role="main"><p class="LC_warning">';
1.1207 raeburn 19108: if ($switchwarning) {
19109: $output .= $switchwarning.'<br /><a href="/adm/roles">';
19110: if (&show_course()) {
19111: $output .= &mt('Display courses');
19112: } else {
19113: $output .= &mt('Display roles');
19114: }
19115: $output .= '</a>';
19116: } elsif ($switchserver) {
19117: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
19118: '<br />'.
19119: '<a href="/adm/switchserver?'.$switchserver.'">'.
19120: &mt('Switch Server').
19121: '</a>';
19122: }
1.1463 raeburn 19123: $output .= '</p></div>'.&end_page();
1.1207 raeburn 19124: return $output;
19125: }
19126:
19127: =pod
19128:
19129: =item * &needs_coursereinit()
19130:
19131: Determine if course contents stored for user's session needs to be
19132: refreshed, because content has changed since "Big Hash" last tied.
19133:
19134: Check for change is made if time last checked is more than 10 minutes ago
19135: (by default).
19136:
19137: Inputs:
19138:
19139: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
19140:
19141: $interval (optional) - Time which may elapse (in s) between last check for content
19142: change in current course. (default: 600 s).
19143:
19144: Returns: an array; first element is:
19145:
19146: =over 4
19147:
19148: 'switch' - if content updates mean user's session
19149: needs to be switched to a server running a newer LON-CAPA version
19150:
19151: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
19152: on current server hosting user's session
19153:
19154: '' - if no action required.
19155:
19156: =back
19157:
19158: If first item element is 'switch':
19159:
19160: second item is $switchwarning - Warning message if no suitable server found to host session.
19161:
19162: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
19163: and current role.
19164:
19165: otherwise: no other elements returned.
19166:
19167: =back
19168:
19169: =cut
19170:
19171: sub needs_coursereinit {
19172: my ($loncaparev,$interval) = @_;
19173: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
19174: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19175: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
19176: my $now = time;
19177: if ($interval eq '') {
19178: $interval = 600;
19179: }
19180: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 19181: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 19182: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19183: if ($blocked) {
19184: return ();
19185: }
1.1391 raeburn 19186: my $update;
19187: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
19188: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
19189: if ($lastmainchange > $env{'request.course.tied'}) {
19190: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
19191: if ($needswitch) {
19192: return ('switch',$switchwarning,$switchserver);
19193: }
19194: $update = 'main';
19195: }
19196: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
19197: if ($update) {
19198: $update = 'both';
19199: } else {
19200: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
19201: if ($needswitch) {
19202: return ('switch',$switchwarning,$switchserver);
19203: } else {
19204: $update = 'supp';
1.1207 raeburn 19205: }
19206: }
1.1391 raeburn 19207: }
1.1453 raeburn 19208: return ($update);
1.1391 raeburn 19209: }
19210: return ();
19211: }
19212:
19213: sub switch_for_update {
19214: my ($loncaparev,$cdom,$cnum) = @_;
19215: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
19216: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
19217: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
19218: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
19219: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
19220: $curr_reqd_hash{'internal.releaserequired'}});
19221: my ($switchserver,$switchwarning) =
19222: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
19223: $curr_reqd_hash{'internal.releaserequired'});
19224: if ($switchwarning ne '' || $switchserver ne '') {
19225: return ('switch',$switchwarning,$switchserver);
19226: }
1.1207 raeburn 19227: }
19228: }
19229: return ();
19230: }
1.1181 raeburn 19231:
1.1083 raeburn 19232: sub update_content_constraints {
1.1395 raeburn 19233: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 19234: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
19235: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 19236: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 19237: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 19238: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 19239: if ($item eq 'resourcetag') {
19240: if ($name eq 'responsetype') {
19241: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
19242: }
1.1307 raeburn 19243: } elsif ($item eq 'course') {
19244: if ($name eq 'courserestype') {
19245: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
19246: }
1.1083 raeburn 19247: }
19248: }
19249: my $navmap = Apache::lonnavmaps::navmap->new();
19250: if (defined($navmap)) {
1.1307 raeburn 19251: my (%allresponses,%allcrsrestypes);
19252: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
19253: if ($res->is_tool()) {
19254: if ($allcrsrestypes{'exttool'}) {
19255: $allcrsrestypes{'exttool'} ++;
19256: } else {
19257: $allcrsrestypes{'exttool'} = 1;
19258: }
19259: next;
19260: }
1.1083 raeburn 19261: my %responses = $res->responseTypes();
19262: foreach my $key (keys(%responses)) {
19263: next unless(exists($checkresponsetypes{$key}));
19264: $allresponses{$key} += $responses{$key};
19265: }
19266: }
19267: foreach my $key (keys(%allresponses)) {
19268: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
19269: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19270: ($reqdmajor,$reqdminor) = ($major,$minor);
19271: }
19272: }
1.1307 raeburn 19273: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 19274: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 19275: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19276: ($reqdmajor,$reqdminor) = ($major,$minor);
19277: }
19278: }
1.1083 raeburn 19279: undef($navmap);
19280: }
1.1391 raeburn 19281: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 19282: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
19283: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19284: ($reqdmajor,$reqdminor) = ($major,$minor);
19285: }
19286: }
1.1083 raeburn 19287: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
19288: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
19289: }
19290: return;
19291: }
19292:
1.1110 raeburn 19293: sub allmaps_incourse {
19294: my ($cdom,$cnum,$chome,$cid) = @_;
19295: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
19296: $cid = $env{'request.course.id'};
19297: $cdom = $env{'course.'.$cid.'.domain'};
19298: $cnum = $env{'course.'.$cid.'.num'};
19299: $chome = $env{'course.'.$cid.'.home'};
19300: }
19301: my %allmaps = ();
19302: my $lastchange =
19303: &Apache::lonnet::get_coursechange($cdom,$cnum);
19304: if ($lastchange > $env{'request.course.tied'}) {
19305: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
19306: unless ($ferr) {
1.1395 raeburn 19307: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 19308: }
19309: }
19310: my $navmap = Apache::lonnavmaps::navmap->new();
19311: if (defined($navmap)) {
19312: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
19313: $allmaps{$res->src()} = 1;
19314: }
19315: }
19316: return \%allmaps;
19317: }
19318:
1.1083 raeburn 19319: sub parse_supplemental_title {
19320: my ($title) = @_;
19321:
19322: my ($foldertitle,$renametitle);
19323: if ($title =~ /&&&/) {
19324: $title = &HTML::Entites::decode($title);
19325: }
19326: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
19327: $renametitle=$4;
19328: my ($time,$uname,$udom) = ($1,$2,$3);
19329: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
19330: my $name = &plainname($uname,$udom);
19331: $name = &HTML::Entities::encode($name,'"<>&\'');
19332: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 19333: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 19334: if ($foldertitle ne '') {
1.1401 raeburn 19335: $title .= ': <br />'.$foldertitle;
19336: }
1.1083 raeburn 19337: }
19338: if (wantarray) {
19339: return ($title,$foldertitle,$renametitle);
19340: }
19341: return $title;
19342: }
19343:
1.1395 raeburn 19344: sub get_supplemental {
19345: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
19346: my $hashid=$cnum.':'.$cdom;
19347: my ($supplemental,$cached,$set_httprefs);
19348: unless ($ignorecache) {
19349: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
19350: }
19351: unless (defined($cached)) {
19352: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
19353: unless ($chome eq 'no_host') {
19354: my @order = @LONCAPA::map::order;
19355: my @resources = @LONCAPA::map::resources;
19356: my @resparms = @LONCAPA::map::resparms;
19357: my @zombies = @LONCAPA::map::zombies;
19358: my ($errors,%ids,%hidden);
19359: $errors =
19360: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
19361: $errors,$possdel,\%ids,\%hidden);
19362: @LONCAPA::map::order = @order;
19363: @LONCAPA::map::resources = @resources;
19364: @LONCAPA::map::resparms = @resparms;
19365: @LONCAPA::map::zombies = @zombies;
19366: $set_httprefs = 1;
19367: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19368: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19369: }
19370: $supplemental = {
19371: ids => \%ids,
19372: hidden => \%hidden,
19373: };
19374: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
19375: }
19376: }
19377: return ($supplemental,$set_httprefs);
19378: }
19379:
1.1143 raeburn 19380: sub recurse_supplemental {
1.1391 raeburn 19381: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
19382: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
19383: my $mapnum;
19384: if ($suppmap eq 'supplemental.sequence') {
19385: $mapnum = 0;
19386: } else {
19387: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
19388: }
1.1143 raeburn 19389: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
19390: if ($fatal) {
19391: $errors ++;
19392: } else {
1.1389 raeburn 19393: my @order = @LONCAPA::map::order;
19394: if (@order > 0) {
19395: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 19396: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 19397: foreach my $idx (@order) {
19398: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 19399: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 19400: my $id = $mapnum.':'.$idx;
19401: push(@{$suppids->{$src}},$id);
19402: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
19403: $hiddensupp->{$id} = 1;
19404: }
1.1146 raeburn 19405: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 19406: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
19407: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 19408: } else {
1.1391 raeburn 19409: my $allowed;
19410: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
19411: $allowed = 1;
19412: } elsif ($possdel) {
19413: foreach my $item (@{$suppids->{$src}}) {
19414: next if ($item eq $id);
19415: unless ($hiddensupp->{$item}) {
19416: $allowed = 1;
19417: last;
19418: }
19419: }
19420: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
19421: &Apache::lonnet::delenv('httpref.'.$src);
19422: }
19423: }
19424: if ($allowed && (!exists($env{'httpref.'.$src}))) {
19425: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 19426: }
1.1143 raeburn 19427: }
19428: }
19429: }
19430: }
19431: }
19432: }
1.1391 raeburn 19433: return $errors;
19434: }
19435:
19436: sub set_supp_httprefs {
19437: my ($cnum,$cdom,$supplemental,$possdel) = @_;
19438: if (ref($supplemental) eq 'HASH') {
19439: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
19440: foreach my $src (keys(%{$supplemental->{'ids'}})) {
19441: next if ($src =~ /\.sequence$/);
19442: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
19443: my $allowed;
19444: if ($env{'request.role.adv'}) {
19445: $allowed = 1;
19446: } else {
19447: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
19448: unless ($supplemental->{'hidden'}->{$id}) {
19449: $allowed = 1;
19450: last;
19451: }
19452: }
19453: }
19454: if (exists($env{'httpref.'.$src})) {
19455: if ($possdel) {
19456: unless ($allowed) {
19457: &Apache::lonnet::delenv('httpref.'.$src);
19458: }
19459: }
19460: } elsif ($allowed) {
19461: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
19462: }
19463: }
19464: }
19465: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19466: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19467: }
19468: }
19469: }
19470: }
19471:
19472: sub get_supp_parameter {
19473: my ($resparm,$name)=@_;
19474: return if ($resparm eq '');
19475: my $value=undef;
19476: my $ptype=undef;
19477: foreach (split('&&&',$resparm)) {
19478: my ($thistype,$thisname,$thisvalue)=split('___',$_);
19479: if ($thisname eq $name) {
19480: $value=$thisvalue;
19481: $ptype=$thistype;
19482: }
19483: }
19484: return $value;
1.1143 raeburn 19485: }
19486:
1.1101 raeburn 19487: sub symb_to_docspath {
1.1267 raeburn 19488: my ($symb,$navmapref) = @_;
19489: return unless ($symb && ref($navmapref));
1.1101 raeburn 19490: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
19491: if ($resurl=~/\.(sequence|page)$/) {
19492: $mapurl=$resurl;
19493: } elsif ($resurl eq 'adm/navmaps') {
19494: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
19495: }
19496: my $mapresobj;
1.1267 raeburn 19497: unless (ref($$navmapref)) {
19498: $$navmapref = Apache::lonnavmaps::navmap->new();
19499: }
19500: if (ref($$navmapref)) {
19501: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 19502: }
19503: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
19504: my $type=$2;
19505: my $path;
19506: if (ref($mapresobj)) {
19507: my $pcslist = $mapresobj->map_hierarchy();
19508: if ($pcslist ne '') {
19509: foreach my $pc (split(/,/,$pcslist)) {
19510: next if ($pc <= 1);
1.1267 raeburn 19511: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 19512: if (ref($res)) {
19513: my $thisurl = $res->src();
19514: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
19515: my $thistitle = $res->title();
19516: $path .= '&'.
19517: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 19518: &escape($thistitle).
1.1101 raeburn 19519: ':'.$res->randompick().
19520: ':'.$res->randomout().
19521: ':'.$res->encrypted().
19522: ':'.$res->randomorder().
19523: ':'.$res->is_page();
19524: }
19525: }
19526: }
19527: $path =~ s/^\&//;
19528: my $maptitle = $mapresobj->title();
19529: if ($mapurl eq 'default') {
1.1129 raeburn 19530: $maptitle = 'Main Content';
1.1101 raeburn 19531: }
19532: $path .= (($path ne '')? '&' : '').
19533: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19534: &escape($maptitle).
1.1101 raeburn 19535: ':'.$mapresobj->randompick().
19536: ':'.$mapresobj->randomout().
19537: ':'.$mapresobj->encrypted().
19538: ':'.$mapresobj->randomorder().
19539: ':'.$mapresobj->is_page();
19540: } else {
19541: my $maptitle = &Apache::lonnet::gettitle($mapurl);
19542: my $ispage = (($type eq 'page')? 1 : '');
19543: if ($mapurl eq 'default') {
1.1129 raeburn 19544: $maptitle = 'Main Content';
1.1101 raeburn 19545: }
19546: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19547: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 19548: }
19549: unless ($mapurl eq 'default') {
19550: $path = 'default&'.
1.1146 raeburn 19551: &escape('Main Content').
1.1101 raeburn 19552: ':::::&'.$path;
19553: }
19554: return $path;
19555: }
19556:
1.1393 raeburn 19557: sub validate_folderpath {
19558: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
19559: if ($env{'form.folderpath'} ne '') {
19560: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 19561: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 19562: for (my $i=0; $i<@items; $i++) {
19563: my $odd = $i%2;
19564: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
19565: $badpath = 1;
1.1394 raeburn 19566: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 19567: my $idx = $i-1;
1.1394 raeburn 19568: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
19569: my $esc_name = $1;
19570: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
19571: $supppath .= '&'.$esc_name;
19572: $changed = 1;
19573: } else {
19574: $supppath .= '&'.$items[$i];
19575: }
19576: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
19577: $changed = 1;
1.1393 raeburn 19578: my $is_hidden;
19579: unless ($got_supp) {
1.1395 raeburn 19580: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 19581: if (ref($supplemental) eq 'HASH') {
19582: if (ref($supplemental->{'hidden'}) eq 'HASH') {
19583: %supphidden = %{$supplemental->{'hidden'}};
19584: }
19585: if (ref($supplemental->{'ids'}) eq 'HASH') {
19586: %suppids = %{$supplemental->{'ids'}};
19587: }
19588: }
19589: $got_supp = 1;
19590: }
19591: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
19592: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
19593: if ($supphidden{$mapid}) {
19594: $is_hidden = 1;
19595: }
19596: }
1.1394 raeburn 19597: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
19598: } else {
19599: $supppath .= '&'.$items[$i];
1.1393 raeburn 19600: }
19601: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
19602: $badpath = 1;
1.1394 raeburn 19603: } elsif ($supplementalflag) {
1.1393 raeburn 19604: $supppath .= '&'.$items[$i];
19605: }
19606: last if ($badpath);
19607: }
19608: if ($badpath) {
19609: delete($env{'form.folderpath'});
1.1394 raeburn 19610: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 19611: $supppath =~ s/^\&//;
19612: $env{'form.folderpath'} = $supppath;
19613: }
19614: }
19615: return;
19616: }
19617:
1.1094 raeburn 19618: sub captcha_display {
1.1327 raeburn 19619: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19620: my ($output,$error);
1.1234 raeburn 19621: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 19622: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19623: if ($captcha eq 'original') {
1.1094 raeburn 19624: $output = &create_captcha();
19625: unless ($output) {
1.1172 raeburn 19626: $error = 'captcha';
1.1094 raeburn 19627: }
19628: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19629: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 19630: unless ($output) {
1.1172 raeburn 19631: $error = 'recaptcha';
1.1094 raeburn 19632: }
19633: }
1.1234 raeburn 19634: return ($output,$error,$captcha,$version);
1.1094 raeburn 19635: }
19636:
19637: sub captcha_response {
1.1327 raeburn 19638: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19639: my ($captcha_chk,$captcha_error);
1.1327 raeburn 19640: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19641: if ($captcha eq 'original') {
1.1094 raeburn 19642: ($captcha_chk,$captcha_error) = &check_captcha();
19643: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19644: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 19645: } else {
19646: $captcha_chk = 1;
19647: }
19648: return ($captcha_chk,$captcha_error);
19649: }
19650:
19651: sub get_captcha_config {
1.1327 raeburn 19652: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 19653: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 19654: my $hostname = &Apache::lonnet::hostname($lonhost);
19655: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
19656: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 19657: if ($context eq 'usercreation') {
19658: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
19659: if (ref($domconfig{$context}) eq 'HASH') {
19660: $hashtocheck = $domconfig{$context}{'cancreate'};
19661: if (ref($hashtocheck) eq 'HASH') {
19662: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
19663: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
19664: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
19665: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
19666: }
19667: if ($privkey && $pubkey) {
19668: $captcha = 'recaptcha';
1.1234 raeburn 19669: $version = $hashtocheck->{'recaptchaversion'};
19670: if ($version ne '2') {
19671: $version = 1;
19672: }
1.1095 raeburn 19673: } else {
19674: $captcha = 'original';
19675: }
19676: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19677: $captcha = 'original';
19678: }
1.1094 raeburn 19679: }
1.1095 raeburn 19680: } else {
19681: $captcha = 'captcha';
19682: }
19683: } elsif ($context eq 'login') {
19684: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19685: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19686: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19687: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19688: if ($privkey && $pubkey) {
19689: $captcha = 'recaptcha';
1.1234 raeburn 19690: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19691: if ($version ne '2') {
19692: $version = 1;
19693: }
1.1095 raeburn 19694: } else {
19695: $captcha = 'original';
1.1094 raeburn 19696: }
1.1095 raeburn 19697: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19698: $captcha = 'original';
1.1094 raeburn 19699: }
1.1327 raeburn 19700: } elsif ($context eq 'passwords') {
19701: if ($dom_in_effect) {
19702: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19703: if ($passwdconf{'captcha'} eq 'recaptcha') {
19704: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19705: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19706: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19707: }
19708: if ($privkey && $pubkey) {
19709: $captcha = 'recaptcha';
19710: $version = $passwdconf{'recaptchaversion'};
19711: if ($version ne '2') {
19712: $version = 1;
19713: }
19714: } else {
19715: $captcha = 'original';
19716: }
19717: } elsif ($passwdconf{'captcha'} ne 'notused') {
19718: $captcha = 'original';
19719: }
19720: }
19721: }
1.1234 raeburn 19722: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19723: }
19724:
19725: sub create_captcha {
19726: my %captcha_params = &captcha_settings();
19727: my ($output,$maxtries,$tries) = ('',10,0);
19728: while ($tries < $maxtries) {
19729: $tries ++;
19730: my $captcha = Authen::Captcha->new (
19731: output_folder => $captcha_params{'output_dir'},
19732: data_folder => $captcha_params{'db_dir'},
19733: );
19734: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19735:
19736: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19737: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19738: '<span class="LC_nobreak">'.
1.1453 raeburn 19739: '<label>'.&mt('Type in the letters/numbers shown below').' '.
1.1463 raeburn 19740: '<input type="text" size="5" name="code" value="" autocomplete="new-password" aria-required="true" />'.
1.1453 raeburn 19741: '</label></span><br />'.
1.1176 raeburn 19742: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19743: last;
19744: }
19745: }
1.1323 raeburn 19746: if ($output eq '') {
19747: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19748: }
1.1094 raeburn 19749: return $output;
19750: }
19751:
19752: sub captcha_settings {
19753: my %captcha_params = (
19754: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19755: www_output_dir => "/captchaspool",
19756: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19757: numchars => '5',
19758: );
19759: return %captcha_params;
19760: }
19761:
19762: sub check_captcha {
19763: my ($captcha_chk,$captcha_error);
19764: my $code = $env{'form.code'};
19765: my $md5sum = $env{'form.crypt'};
19766: my %captcha_params = &captcha_settings();
19767: my $captcha = Authen::Captcha->new(
19768: output_folder => $captcha_params{'output_dir'},
19769: data_folder => $captcha_params{'db_dir'},
19770: );
1.1109 raeburn 19771: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19772: my %captcha_hash = (
19773: 0 => 'Code not checked (file error)',
19774: -1 => 'Failed: code expired',
19775: -2 => 'Failed: invalid code (not in database)',
19776: -3 => 'Failed: invalid code (code does not match crypt)',
19777: );
19778: if ($captcha_chk != 1) {
19779: $captcha_error = $captcha_hash{$captcha_chk}
19780: }
19781: return ($captcha_chk,$captcha_error);
19782: }
19783:
19784: sub create_recaptcha {
1.1234 raeburn 19785: my ($pubkey,$version) = @_;
19786: if ($version >= 2) {
1.1367 raeburn 19787: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19788: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19789: } else {
19790: my $use_ssl;
19791: if ($ENV{'SERVER_PORT'} == 443) {
19792: $use_ssl = 1;
19793: }
19794: my $captcha = Captcha::reCAPTCHA->new;
19795: return $captcha->get_options_setter({theme => 'white'})."\n".
19796: $captcha->get_html($pubkey,undef,$use_ssl).
19797: &mt('If the text is hard to read, [_1] will replace them.',
19798: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19799: '<br /><br />';
19800: }
1.1094 raeburn 19801: }
19802:
19803: sub check_recaptcha {
1.1234 raeburn 19804: my ($privkey,$version) = @_;
1.1094 raeburn 19805: my $captcha_chk;
1.1350 raeburn 19806: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19807: if ($version >= 2) {
19808: my %info = (
19809: secret => $privkey,
19810: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19811: remoteip => $ip,
1.1234 raeburn 19812: );
1.1280 raeburn 19813: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19814: $request->content(join('&',map {
19815: my $name = escape($_);
19816: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19817: ? join("&$name=", map {escape($_) } @{$info{$_}})
19818: : &escape($info{$_}) );
19819: } keys(%info)));
19820: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19821: if ($response->is_success) {
19822: my $data = JSON::DWIW->from_json($response->decoded_content);
19823: if (ref($data) eq 'HASH') {
19824: if ($data->{'success'}) {
19825: $captcha_chk = 1;
19826: }
19827: }
19828: }
19829: } else {
19830: my $captcha = Captcha::reCAPTCHA->new;
19831: my $captcha_result =
19832: $captcha->check_answer(
19833: $privkey,
1.1350 raeburn 19834: $ip,
1.1234 raeburn 19835: $env{'form.recaptcha_challenge_field'},
19836: $env{'form.recaptcha_response_field'},
19837: );
19838: if ($captcha_result->{is_valid}) {
19839: $captcha_chk = 1;
19840: }
1.1094 raeburn 19841: }
19842: return $captcha_chk;
19843: }
19844:
1.1174 raeburn 19845: sub emailusername_info {
1.1244 raeburn 19846: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19847: my %titles = &Apache::lonlocal::texthash (
19848: lastname => 'Last Name',
19849: firstname => 'First Name',
19850: institution => 'School/college/university',
19851: location => "School's city, state/province, country",
19852: web => "School's web address",
19853: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19854: id => 'Student/Employee ID',
1.1174 raeburn 19855: );
19856: return (\@fields,\%titles);
19857: }
19858:
1.1161 raeburn 19859: sub cleanup_html {
19860: my ($incoming) = @_;
19861: my $outgoing;
19862: if ($incoming ne '') {
19863: $outgoing = $incoming;
19864: $outgoing =~ s/;/;/g;
19865: $outgoing =~ s/\#/#/g;
19866: $outgoing =~ s/\&/&/g;
19867: $outgoing =~ s/</</g;
19868: $outgoing =~ s/>/>/g;
19869: $outgoing =~ s/\(/(/g;
19870: $outgoing =~ s/\)/)/g;
19871: $outgoing =~ s/"/"/g;
19872: $outgoing =~ s/'/'/g;
19873: $outgoing =~ s/\$/$/g;
19874: $outgoing =~ s{/}{/}g;
19875: $outgoing =~ s/=/=/g;
19876: $outgoing =~ s/\\/\/g
19877: }
19878: return $outgoing;
19879: }
19880:
1.1190 musolffc 19881: # Checks for critical messages and returns a redirect url if one exists.
19882: # $interval indicates how often to check for messages.
1.1282 raeburn 19883: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19884: sub critical_redirect {
1.1282 raeburn 19885: my ($interval,$context) = @_;
1.1356 raeburn 19886: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19887: return ();
19888: }
1.1190 musolffc 19889: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19890: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19891: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19892: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19893: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19894: if ($blocked) {
19895: my $checkrole = "cm./$cdom/$cnum";
19896: if ($env{'request.course.sec'} ne '') {
19897: $checkrole .= "/$env{'request.course.sec'}";
19898: }
19899: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19900: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19901: return;
19902: }
19903: }
19904: }
1.1190 musolffc 19905: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19906: $env{'user.name'});
19907: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19908: my $redirecturl;
1.1190 musolffc 19909: if ($what[0]) {
1.1356 raeburn 19910: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19911: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19912: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19913: return (1, $url);
1.1190 musolffc 19914: }
1.1191 raeburn 19915: }
19916: }
19917: return ();
1.1190 musolffc 19918: }
19919:
1.1174 raeburn 19920: # Use:
19921: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19922: #
19923: ##################################################
19924: # password associated functions #
19925: ##################################################
19926: sub des_keys {
19927: # Make a new key for DES encryption.
19928: # Each key has two parts which are returned separately.
19929: # Please note: Each key must be passed through the &hex function
19930: # before it is output to the web browser. The hex versions cannot
19931: # be used to decrypt.
19932: my @hexstr=('0','1','2','3','4','5','6','7',
19933: '8','9','a','b','c','d','e','f');
19934: my $lkey='';
19935: for (0..7) {
19936: $lkey.=$hexstr[rand(15)];
19937: }
19938: my $ukey='';
19939: for (0..7) {
19940: $ukey.=$hexstr[rand(15)];
19941: }
19942: return ($lkey,$ukey);
19943: }
19944:
19945: sub des_decrypt {
19946: my ($key,$cyphertext) = @_;
19947: my $keybin=pack("H16",$key);
19948: my $cypher;
19949: if ($Crypt::DES::VERSION>=2.03) {
19950: $cypher=new Crypt::DES $keybin;
19951: } else {
19952: $cypher=new DES $keybin;
19953: }
1.1233 raeburn 19954: my $plaintext='';
19955: my $cypherlength = length($cyphertext);
19956: my $numchunks = int($cypherlength/32);
19957: for (my $j=0; $j<$numchunks; $j++) {
19958: my $start = $j*32;
19959: my $cypherblock = substr($cyphertext,$start,32);
19960: my $chunk =
19961: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19962: $chunk .=
19963: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19964: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19965: $plaintext .= $chunk;
19966: }
1.1174 raeburn 19967: return $plaintext;
19968: }
19969:
1.1344 raeburn 19970: sub get_requested_shorturls {
1.1309 raeburn 19971: my ($cdom,$cnum,$navmap) = @_;
19972: return unless (ref($navmap));
1.1344 raeburn 19973: my ($numnew,$errors);
1.1309 raeburn 19974: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19975: if (@toshorten) {
19976: my (%maps,%resources,%titles);
19977: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19978: 'shorturls',$cdom,$cnum);
19979: if (keys(%resources)) {
1.1344 raeburn 19980: my %tocreate;
1.1309 raeburn 19981: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19982: my $symb = $resources{$item};
19983: if ($symb) {
19984: $tocreate{$cnum.'&'.$symb} = 1;
19985: }
19986: }
1.1344 raeburn 19987: if (keys(%tocreate)) {
19988: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19989: \%tocreate);
19990: }
1.1309 raeburn 19991: }
1.1344 raeburn 19992: }
19993: return ($numnew,$errors);
19994: }
19995:
19996: sub make_short_symbs {
19997: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19998: my ($numnew,@errors);
19999: if (ref($tocreateref) eq 'HASH') {
20000: my %tocreate = %{$tocreateref};
1.1309 raeburn 20001: if (keys(%tocreate)) {
20002: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
20003: my $su = Short::URL->new(no_vowels => 1);
20004: my $init = '';
20005: my (%newunique,%addcourse,%courseonly,%failed);
20006: # get lock on tiny db
20007: my $now = time;
1.1344 raeburn 20008: if ($lockuser eq '') {
20009: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
20010: }
1.1309 raeburn 20011: my $lockhash = {
1.1344 raeburn 20012: "lock\0$now" => $lockuser,
1.1309 raeburn 20013: };
20014: my $tries = 0;
20015: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
20016: my ($code,$error);
20017: while (($gotlock ne 'ok') && ($tries<3)) {
20018: $tries ++;
20019: sleep 1;
1.1319 raeburn 20020: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 20021: }
20022: if ($gotlock eq 'ok') {
20023: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
20024: \%addcourse,\%courseonly,\%failed);
20025: if (keys(%failed)) {
20026: my $numfailed = scalar(keys(%failed));
20027: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
20028: }
20029: if (keys(%newunique)) {
20030: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
20031: if ($putres eq 'ok') {
20032: $numnew = scalar(keys(%newunique));
20033: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
20034: unless ($newputres eq 'ok') {
20035: push(@errors,&mt('error: could not store course look-up of short URLs'));
20036: }
20037: } else {
20038: push(@errors,&mt('error: could not store unique six character URLs'));
20039: }
20040: }
20041: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
20042: unless ($dellockres eq 'ok') {
20043: push(@errors,&mt('error: could not release lockfile'));
20044: }
20045: } else {
20046: push(@errors,&mt('error: could not obtain lockfile'));
20047: }
20048: if (keys(%courseonly)) {
20049: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
20050: if ($result ne 'ok') {
20051: push(@errors,&mt('error: could not update course look-up of short URLs'));
20052: }
20053: }
20054: }
20055: }
20056: return ($numnew,\@errors);
20057: }
20058:
20059: sub shorten_symbs {
20060: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
20061: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
20062: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
20063: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
20064: my (%possibles,%collisions);
20065: foreach my $key (keys(%{$tocreate})) {
20066: my $num = String::CRC32::crc32($key);
20067: my $tiny = $su->encode($num,$init);
20068: if ($tiny) {
20069: $possibles{$tiny} = $key;
20070: }
20071: }
20072: if (!$init) {
20073: $init = 1;
20074: } else {
20075: $init ++;
20076: }
20077: if (keys(%possibles)) {
20078: my @posstiny = keys(%possibles);
20079: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
20080: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
20081: if (keys(%currtiny)) {
20082: foreach my $key (keys(%currtiny)) {
20083: next if ($currtiny{$key} eq '');
20084: if ($currtiny{$key} eq $possibles{$key}) {
20085: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
20086: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
20087: $courseonly->{$tsymb} = $key;
20088: }
20089: } else {
20090: $collisions{$possibles{$key}} = 1;
20091: }
20092: delete($possibles{$key});
20093: }
20094: }
20095: foreach my $key (keys(%possibles)) {
20096: $newunique->{$key} = $possibles{$key};
20097: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
20098: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
20099: $addcourse->{$tsymb} = $key;
20100: }
20101: }
20102: }
20103: if (keys(%collisions)) {
20104: if ($init <5) {
20105: if (!$init) {
20106: $init = 1;
20107: } else {
20108: $init ++;
20109: }
20110: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
20111: $newunique,$addcourse,$courseonly,$failed);
20112: } else {
20113: foreach my $key (keys(%collisions)) {
20114: $failed->{$key} = 1;
20115: }
20116: }
20117: }
20118: return $init;
20119: }
20120:
1.1328 raeburn 20121: sub is_nonframeable {
1.1329 raeburn 20122: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
20123: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 20124: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 20125:
20126: $remprotocol = lc($remprotocol);
20127: $remhost = lc($remhost);
20128: my $remport = 80;
20129: if ($remprotocol eq 'https') {
20130: $remport = 443;
20131: }
1.1330 raeburn 20132: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 20133: if ($cached) {
20134: unless ($nocache) {
20135: if ($result) {
20136: return 1;
20137: } else {
20138: return 0;
20139: }
20140: }
20141: }
1.1328 raeburn 20142: my $uselink;
20143: my $request = new HTTP::Request('HEAD',$url);
20144: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
20145: if ($response->is_success()) {
20146: my $secpolicy = lc($response->header('content-security-policy'));
20147: my $xframeop = lc($response->header('x-frame-options'));
20148: $secpolicy =~ s/^\s+|\s+$//g;
20149: $xframeop =~ s/^\s+|\s+$//g;
20150: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 20151: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 20152: my ($origin,$protocol,$port);
20153: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
20154: $port = $ENV{'SERVER_PORT'};
20155: } else {
20156: $port = 80;
20157: }
20158: if ($absolute eq '') {
20159: $protocol = 'http:';
20160: if ($port == 443) {
20161: $protocol = 'https:';
20162: }
20163: $origin = $protocol.'//'.lc($hostname);
20164: } else {
20165: $origin = lc($absolute);
20166: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
20167: }
20168: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
20169: my $framepolicy = $1;
20170: $framepolicy =~ s/^\s+|\s+$//g;
20171: my @policies = split(/\s+/,$framepolicy);
20172: if (@policies) {
20173: if (grep(/^\Q'none'\E$/,@policies)) {
20174: $uselink = 1;
20175: } else {
20176: $uselink = 1;
20177: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
20178: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
20179: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
20180: undef($uselink);
20181: }
20182: if ($uselink) {
20183: if (grep(/^\Q'self'\E$/,@policies)) {
20184: if (($origin ne '') && ($remotehost eq $origin)) {
20185: undef($uselink);
20186: }
20187: }
20188: }
20189: if ($uselink) {
20190: my @possok;
20191: if ($ip ne '') {
20192: push(@possok,$ip);
20193: }
20194: my $hoststr = '';
20195: foreach my $part (reverse(split(/\./,$hostname))) {
20196: if ($hoststr eq '') {
20197: $hoststr = $part;
20198: } else {
20199: $hoststr = "$part.$hoststr";
20200: }
20201: if ($hoststr eq $hostname) {
20202: push(@possok,$hostname);
20203: } else {
20204: push(@possok,"*.$hoststr");
20205: }
20206: }
20207: if (@possok) {
20208: foreach my $poss (@possok) {
20209: last if (!$uselink);
20210: foreach my $policy (@policies) {
20211: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
20212: undef($uselink);
20213: last;
20214: }
20215: }
20216: }
20217: }
20218: }
20219: }
20220: }
20221: } elsif ($xframeop ne '') {
20222: $uselink = 1;
20223: my @policies = split(/\s*,\s*/,$xframeop);
20224: if (@policies) {
20225: unless (grep(/^deny$/,@policies)) {
20226: if ($origin ne '') {
20227: if (grep(/^sameorigin$/,@policies)) {
20228: if ($remotehost eq $origin) {
20229: undef($uselink);
20230: }
20231: }
20232: if ($uselink) {
20233: foreach my $policy (@policies) {
20234: if ($policy =~ /^allow-from\s*(.+)$/) {
20235: my $allowfrom = $1;
20236: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
20237: undef($uselink);
20238: last;
20239: }
20240: }
20241: }
20242: }
20243: }
20244: }
20245: }
20246: }
20247: }
20248: }
1.1329 raeburn 20249: if ($nocache) {
20250: if ($cached) {
20251: my $devalidate;
20252: if ($uselink && !$result) {
20253: $devalidate = 1;
20254: } elsif (!$uselink && $result) {
20255: $devalidate = 1;
20256: }
20257: if ($devalidate) {
20258: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
20259: }
20260: }
20261: } else {
20262: if ($uselink) {
20263: $result = 1;
20264: } else {
20265: $result = 0;
20266: }
20267: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
20268: }
1.1328 raeburn 20269: return $uselink;
20270: }
20271:
1.1359 raeburn 20272: sub page_menu {
20273: my ($menucolls,$menunum) = @_;
20274: my %menu;
20275: foreach my $item (split(/;/,$menucolls)) {
20276: my ($num,$value) = split(/\%/,$item);
20277: if ($num eq $menunum) {
20278: my @entries = split(/\&/,$value);
20279: foreach my $entry (@entries) {
20280: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 20281: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 20282: $menu{$name} = $fields;
20283: } else {
20284: my @shown;
20285: if ($fields =~ /,/) {
20286: @shown = split(/,/,$fields);
20287: } else {
20288: @shown = ($fields);
20289: }
20290: if (@shown) {
20291: foreach my $field (@shown) {
20292: next if ($field eq '');
20293: $menu{$field} = 1;
20294: }
20295: }
20296: }
20297: }
20298: }
20299: }
20300: return %menu;
20301: }
20302:
1.112 bowersj2 20303: 1;
20304: __END__;
1.41 ng 20305:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>