Annotation of loncom/interface/loncommon.pm, revision 1.1421
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1421 ! raeburn 4: # $Id: loncommon.pm,v 1.1420 2023/11/18 21:50:06 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)=@_;
969: my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";
1.659 raeburn 970: if ($includeempty) {
971: $output .= '<option value=""';
972: if (($selected eq '') || ($selected eq 'local')) {
973: $output .= ' selected="selected" ';
974: }
975: $output .= '> </option>';
976: }
1.657 raeburn 977: my @timezones = DateTime::TimeZone->all_names;
978: foreach my $tzone (@timezones) {
979: $output.= '<option value="'.$tzone.'"';
980: if ($tzone eq $selected) {
981: $output.=' selected="selected"';
982: }
983: $output.=">$tzone</option>\n";
1.656 www 984: }
985: $output.="</select>";
986: return $output;
987: }
1.273 raeburn 988:
1.687 raeburn 989: sub select_datelocale {
1.1256 raeburn 990: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
991: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 992: if ($includeempty) {
993: $output .= '<option value=""';
994: if ($selected eq '') {
995: $output .= ' selected="selected" ';
996: }
997: $output .= '> </option>';
998: }
1.1241 raeburn 999: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 1000: my (@possibles,%locale_names);
1.1241 raeburn 1001: my @locales = DateTime::Locale->ids();
1002: foreach my $id (@locales) {
1003: if ($id ne '') {
1004: my ($en_terr,$native_terr);
1005: my $loc = DateTime::Locale->load($id);
1006: if (ref($loc)) {
1007: $en_terr = $loc->name();
1008: $native_terr = $loc->native_name();
1.687 raeburn 1009: if (grep(/^en$/,@languages) || !@languages) {
1010: if ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: } elsif ($native_terr ne '') {
1013: $locale_names{$id} = $native_terr;
1014: }
1015: } else {
1016: if ($native_terr ne '') {
1017: $locale_names{$id} = $native_terr.' ';
1018: } elsif ($en_terr ne '') {
1019: $locale_names{$id} = '('.$en_terr.')';
1020: }
1021: }
1.1220 raeburn 1022: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1023: push(@possibles,$id);
1024: }
1.687 raeburn 1025: }
1026: }
1027: foreach my $item (sort(@possibles)) {
1028: $output.= '<option value="'.$item.'"';
1029: if ($item eq $selected) {
1030: $output.=' selected="selected"';
1031: }
1032: $output.=">$item";
1033: if ($locale_names{$item} ne '') {
1.1220 raeburn 1034: $output.=' '.$locale_names{$item};
1.687 raeburn 1035: }
1036: $output.="</option>\n";
1037: }
1038: $output.="</select>";
1039: return $output;
1040: }
1041:
1.792 raeburn 1042: sub select_language {
1.1256 raeburn 1043: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1044: my %langchoices;
1045: if ($includeempty) {
1.1117 raeburn 1046: %langchoices = ('' => 'No language preference');
1.792 raeburn 1047: }
1048: foreach my $id (&languageids()) {
1049: my $code = &supportedlanguagecode($id);
1050: if ($code) {
1051: $langchoices{$code} = &plainlanguagedescription($id);
1052: }
1053: }
1.1117 raeburn 1054: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1055: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1056: }
1057:
1.42 matthew 1058: =pod
1.36 matthew 1059:
1.1088 foxr 1060:
1061: =item * &list_languages()
1062:
1063: Returns an array reference that is suitable for use in language prompters.
1064: Each array element is itself a two element array. The first element
1065: is the language code. The second element a descsriptiuon of the
1066: language itself. This is suitable for use in e.g.
1067: &Apache::edit::select_arg (once dereferenced that is).
1068:
1069: =cut
1070:
1071: sub list_languages {
1072: my @lang_choices;
1073:
1074: foreach my $id (&languageids()) {
1075: my $code = &supportedlanguagecode($id);
1076: if ($code) {
1077: my $selector = $supported_codes{$id};
1078: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1079: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1080: }
1081: }
1082: return \@lang_choices;
1083: }
1084:
1085: =pod
1086:
1.648 raeburn 1087: =item * &linked_select_forms(...)
1.36 matthew 1088:
1089: linked_select_forms returns a string containing a <script></script> block
1090: and html for two <select> menus. The select menus will be linked in that
1091: changing the value of the first menu will result in new values being placed
1092: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1093: order unless a defined order is provided.
1.36 matthew 1094:
1095: linked_select_forms takes the following ordered inputs:
1096:
1097: =over 4
1098:
1.112 bowersj2 1099: =item * $formname, the name of the <form> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1102:
1.112 bowersj2 1103: =item * $firstdefault, the default value for the first menu
1.36 matthew 1104:
1.112 bowersj2 1105: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1106:
1.112 bowersj2 1107: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1108:
1.112 bowersj2 1109: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1110:
1.609 raeburn 1111: =item * $menuorder, the order of values in the first menu
1112:
1.1115 raeburn 1113: =item * $onchangefirst, additional javascript call to execute for an onchange
1114: event for the first <select> tag
1115:
1116: =item * $onchangesecond, additional javascript call to execute for an onchange
1117: event for the second <select> tag
1118:
1.1245 raeburn 1119: =item * $suffix, to differentiate separate uses of select2data javascript
1120: objects in a page.
1121:
1.41 ng 1122: =back
1123:
1.36 matthew 1124: Below is an example of such a hash. Only the 'text', 'default', and
1125: 'select2' keys must appear as stated. keys(%menu) are the possible
1126: values for the first select menu. The text that coincides with the
1.41 ng 1127: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1128: and text for the second menu are given in the hash pointed to by
1129: $menu{$choice1}->{'select2'}.
1130:
1.112 bowersj2 1131: my %menu = ( A1 => { text =>"Choice A1" ,
1132: default => "B3",
1133: select2 => {
1134: B1 => "Choice B1",
1135: B2 => "Choice B2",
1136: B3 => "Choice B3",
1137: B4 => "Choice B4"
1.609 raeburn 1138: },
1139: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1140: },
1141: A2 => { text =>"Choice A2" ,
1142: default => "C2",
1143: select2 => {
1144: C1 => "Choice C1",
1145: C2 => "Choice C2",
1146: C3 => "Choice C3"
1.609 raeburn 1147: },
1148: order => ['C2','C1','C3'],
1.112 bowersj2 1149: },
1150: A3 => { text =>"Choice A3" ,
1151: default => "D6",
1152: select2 => {
1153: D1 => "Choice D1",
1154: D2 => "Choice D2",
1155: D3 => "Choice D3",
1156: D4 => "Choice D4",
1157: D5 => "Choice D5",
1158: D6 => "Choice D6",
1159: D7 => "Choice D7"
1.609 raeburn 1160: },
1161: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1162: }
1163: );
1.36 matthew 1164:
1165: =cut
1166:
1167: sub linked_select_forms {
1168: my ($formname,
1169: $middletext,
1170: $firstdefault,
1171: $firstselectname,
1172: $secondselectname,
1.609 raeburn 1173: $hashref,
1174: $menuorder,
1.1115 raeburn 1175: $onchangefirst,
1.1245 raeburn 1176: $onchangesecond,
1177: $suffix
1.36 matthew 1178: ) = @_;
1179: my $second = "document.$formname.$secondselectname";
1180: my $first = "document.$formname.$firstselectname";
1181: # output the javascript to do the changing
1182: my $result = '';
1.776 bisitz 1183: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1184: $result.="// <![CDATA[\n";
1.1245 raeburn 1185: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1186: $" = '","';
1187: my $debug = '';
1188: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1189: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1190: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1191: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1192: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1193: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1194: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1195: @s2values = @{$hashref->{$s1}->{'order'}};
1196: }
1.36 matthew 1197: $result.="\"@s2values\");\n";
1.1245 raeburn 1198: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1199: my @s2texts;
1200: foreach my $value (@s2values) {
1.1263 raeburn 1201: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1202: }
1203: $result.="\"@s2texts\");\n";
1204: }
1205: $"=' ';
1206: $result.= <<"END";
1207:
1.1245 raeburn 1208: function select1${suffix}_changed() {
1.36 matthew 1209: // Determine new choice
1.1245 raeburn 1210: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1211: // update select2
1.1245 raeburn 1212: var values = select2data${suffix}[newvalue].values;
1213: var texts = select2data${suffix}[newvalue].texts;
1214: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1215: var i;
1216: // out with the old
1.1245 raeburn 1217: $second.options.length = 0;
1218: // in with the new
1.36 matthew 1219: for (i=0;i<values.length; i++) {
1220: $second.options[i] = new Option(values[i]);
1.143 matthew 1221: $second.options[i].value = values[i];
1.36 matthew 1222: $second.options[i].text = texts[i];
1223: if (values[i] == select2def) {
1224: $second.options[i].selected = true;
1225: }
1226: }
1227: }
1.824 bisitz 1228: // ]]>
1.36 matthew 1229: </script>
1230: END
1231: # output the initial values for the selection lists
1.1245 raeburn 1232: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1233: my @order = sort(keys(%{$hashref}));
1234: if (ref($menuorder) eq 'ARRAY') {
1235: @order = @{$menuorder};
1236: }
1237: foreach my $value (@order) {
1.36 matthew 1238: $result.=" <option value=\"$value\" ";
1.253 albertel 1239: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1240: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1241: }
1242: $result .= "</select>\n";
1.1400 raeburn 1243: my %select2;
1244: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1245: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1246: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1247: }
1248: }
1.36 matthew 1249: $result .= $middletext;
1.1115 raeburn 1250: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1251: if ($onchangesecond) {
1252: $result .= ' onchange="'.$onchangesecond.'"';
1253: }
1254: $result .= ">\n";
1.36 matthew 1255: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1256:
1257: my @secondorder = sort(keys(%select2));
1258: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1259: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1260: }
1261: foreach my $value (@secondorder) {
1.36 matthew 1262: $result.=" <option value=\"$value\" ";
1.253 albertel 1263: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1264: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1265: }
1266: $result .= "</select>\n";
1267: # return $debug;
1268: return $result;
1269: } # end of sub linked_select_forms {
1270:
1.45 matthew 1271: =pod
1.44 bowersj2 1272:
1.1381 raeburn 1273: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1274:
1.112 bowersj2 1275: Returns a string corresponding to an HTML link to the given help
1276: $topic, where $topic corresponds to the name of a .tex file in
1277: /home/httpd/html/adm/help/tex, with underscores replaced by
1278: spaces.
1279:
1280: $text will optionally be linked to the same topic, allowing you to
1281: link text in addition to the graphic. If you do not want to link
1282: text, but wish to specify one of the later parameters, pass an
1283: empty string.
1284:
1285: $stayOnPage is a value that will be interpreted as a boolean. If true,
1286: the link will not open a new window. If false, the link will open
1287: a new window using Javascript. (Default is false.)
1288:
1289: $width and $height are optional numerical parameters that will
1290: override the width and height of the popped up window, which may
1.973 raeburn 1291: be useful for certain help topics with big pictures included.
1292:
1293: $imgid is the id of the img tag used for the help icon. This may be
1294: used in a javascript call to switch the image src. See
1295: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1296:
1.1381 raeburn 1297: $links_target will optionally be set to a target (_top, _parent or _self).
1298:
1.44 bowersj2 1299: =cut
1300:
1301: sub help_open_topic {
1.1381 raeburn 1302: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1303: $text = "" if (not defined $text);
1.44 bowersj2 1304: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1305: $width = 500 if (not defined $width);
1.44 bowersj2 1306: $height = 400 if (not defined $height);
1307: my $filename = $topic;
1308: $filename =~ s/ /_/g;
1309:
1.48 bowersj2 1310: my $template = "";
1311: my $link;
1.572 banghart 1312:
1.159 www 1313: $topic=~s/\W/\_/g;
1.44 bowersj2 1314:
1.572 banghart 1315: if (!$stayOnPage) {
1.1033 www 1316: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1317: } elsif ($stayOnPage eq 'popup') {
1318: $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 1319: } else {
1.48 bowersj2 1320: $link = "/adm/help/${filename}.hlp";
1321: }
1322:
1323: # Add the text
1.1314 raeburn 1324: my $target = ' target="_top"';
1.1381 raeburn 1325: if ($links_target) {
1326: $target = ' target="'.$links_target.'"';
1327: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1328: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1329: $target = '';
1.1378 raeburn 1330: }
1.1380 raeburn 1331: if ($text ne "") {
1.763 bisitz 1332: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1333: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1334: .$text.'</a>';
1.48 bowersj2 1335: }
1336:
1.763 bisitz 1337: # (Always) Add the graphic
1.179 matthew 1338: my $title = &mt('Online Help');
1.667 raeburn 1339: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1340: if ($imgid ne '') {
1341: $imgid = ' id="'.$imgid.'"';
1342: }
1.1314 raeburn 1343: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1344: .'<img src="'.$helpicon.'" border="0"'
1345: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1346: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1347: .' /></a>';
1348: if ($text ne "") {
1349: $template.='</span>';
1350: }
1.44 bowersj2 1351: return $template;
1352:
1.106 bowersj2 1353: }
1354:
1355: # This is a quicky function for Latex cheatsheet editing, since it
1356: # appears in at least four places
1357: sub helpLatexCheatsheet {
1.1037 www 1358: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1359: my $out;
1.106 bowersj2 1360: my $addOther = '';
1.732 raeburn 1361: if ($topic) {
1.1037 www 1362: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1363: }
1364: $out = '<span>' # Start cheatsheet
1365: .$addOther
1366: .'<span>'
1.1037 www 1367: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1368: .'</span> <span>'
1.1037 www 1369: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1370: .'</span>';
1.732 raeburn 1371: unless ($not_author) {
1.1186 kruse 1372: $out .= '<span>'
1373: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1374: .'</span> <span>'
1375: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1376: .'</span>';
1.732 raeburn 1377: }
1.763 bisitz 1378: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1379: return $out;
1.172 www 1380: }
1381:
1.430 albertel 1382: sub general_help {
1383: my $helptopic='Student_Intro';
1384: if ($env{'request.role'}=~/^(ca|au)/) {
1385: $helptopic='Authoring_Intro';
1.907 raeburn 1386: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1387: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1388: } elsif ($env{'request.role'}=~/^dc/) {
1389: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1390: }
1391: return $helptopic;
1392: }
1393:
1394: sub update_help_link {
1395: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1396: my $origurl = $ENV{'REQUEST_URI'};
1397: $origurl=~s|^/~|/priv/|;
1398: my $timestamp = time;
1399: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1400: $$datum = &escape($$datum);
1401: }
1402:
1403: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1404: my $output .= <<"ENDOUTPUT";
1405: <script type="text/javascript">
1.824 bisitz 1406: // <![CDATA[
1.430 albertel 1407: banner_link = '$banner_link';
1.824 bisitz 1408: // ]]>
1.430 albertel 1409: </script>
1410: ENDOUTPUT
1411: return $output;
1412: }
1413:
1414: # now just updates the help link and generates a blue icon
1.193 raeburn 1415: sub help_open_menu {
1.1381 raeburn 1416: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1417: = @_;
1.949 droeschl 1418: $stayOnPage = 1;
1.430 albertel 1419: my $output;
1420: if ($component_help) {
1421: if (!$text) {
1422: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1423: $width,$height,'',$links_target);
1.430 albertel 1424: } else {
1425: my $help_text;
1426: $help_text=&unescape($topic);
1427: $output='<table><tr><td>'.
1428: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1429: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1430: }
1431: }
1432: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1433: return $output.$banner_link;
1434: }
1435:
1436: sub top_nav_help {
1.1369 raeburn 1437: my ($text,$linkattr) = @_;
1.436 albertel 1438: $text = &mt($text);
1.949 droeschl 1439: my $stay_on_page = 1;
1440:
1.1168 raeburn 1441: my ($link,$banner_link);
1442: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1443: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1444: : "javascript:helpMenu('open')";
1445: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1446: }
1.201 raeburn 1447: my $title = &mt('Get help');
1.1168 raeburn 1448: if ($link) {
1449: return <<"END";
1.436 albertel 1450: $banner_link
1.1369 raeburn 1451: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1452: END
1.1168 raeburn 1453: } else {
1454: return ' '.$text.' ';
1455: }
1.436 albertel 1456: }
1457:
1458: sub help_menu_js {
1.1154 raeburn 1459: my ($httphost) = @_;
1.949 droeschl 1460: my $stayOnPage = 1;
1.436 albertel 1461: my $width = 620;
1462: my $height = 600;
1.430 albertel 1463: my $helptopic=&general_help();
1.1154 raeburn 1464: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1465: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1466: my $start_page =
1467: &Apache::loncommon::start_page('Help Menu', undef,
1468: {'frameset' => 1,
1469: 'js_ready' => 1,
1.1154 raeburn 1470: 'use_absolute' => $httphost,
1.331 albertel 1471: 'add_entries' => {
1.1168 raeburn 1472: 'border' => '0',
1.579 raeburn 1473: 'rows' => "110,*",},});
1.331 albertel 1474: my $end_page =
1475: &Apache::loncommon::end_page({'frameset' => 1,
1476: 'js_ready' => 1,});
1477:
1.436 albertel 1478: my $template .= <<"ENDTEMPLATE";
1479: <script type="text/javascript">
1.877 bisitz 1480: // <![CDATA[
1.253 albertel 1481: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1482: var banner_link = '';
1.243 raeburn 1483: function helpMenu(target) {
1484: var caller = this;
1485: if (target == 'open') {
1486: var newWindow = null;
1487: try {
1.262 albertel 1488: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1489: }
1490: catch(error) {
1491: writeHelp(caller);
1492: return;
1493: }
1494: if (newWindow) {
1495: caller = newWindow;
1496: }
1.193 raeburn 1497: }
1.243 raeburn 1498: writeHelp(caller);
1499: return;
1500: }
1501: function writeHelp(caller) {
1.1168 raeburn 1502: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1503: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1504: caller.document.close();
1505: caller.focus();
1.193 raeburn 1506: }
1.877 bisitz 1507: // END LON-CAPA Internal -->
1.253 albertel 1508: // ]]>
1.436 albertel 1509: </script>
1.193 raeburn 1510: ENDTEMPLATE
1511: return $template;
1512: }
1513:
1.172 www 1514: sub help_open_bug {
1515: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1516: unless ($env{'user.adv'}) { return ''; }
1.172 www 1517: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1518: $text = "" if (not defined $text);
1519: $stayOnPage=1;
1.184 albertel 1520: $width = 600 if (not defined $width);
1521: $height = 600 if (not defined $height);
1.172 www 1522:
1523: $topic=~s/\W+/\+/g;
1524: my $link='';
1525: my $template='';
1.379 albertel 1526: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1527: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1528: if (!$stayOnPage)
1529: {
1530: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1531: }
1532: else
1533: {
1534: $link = $url;
1535: }
1.1314 raeburn 1536:
1.1382 raeburn 1537: my $target = '_top';
1538: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1539: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1540: $target = '_blank';
1.1378 raeburn 1541: }
1.1382 raeburn 1542:
1.172 www 1543: # Add the text
1544: if ($text ne "")
1545: {
1546: $template .=
1547: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1548: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1549: }
1550:
1551: # Add the graphic
1.179 matthew 1552: my $title = &mt('Report a Bug');
1.215 albertel 1553: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1554: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1555: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1556: ENDTEMPLATE
1557: if ($text ne '') { $template.='</td></tr></table>' };
1558: return $template;
1559:
1560: }
1561:
1562: sub help_open_faq {
1563: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1564: unless ($env{'user.adv'}) { return ''; }
1.172 www 1565: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1566: $text = "" if (not defined $text);
1567: $stayOnPage=1;
1568: $width = 350 if (not defined $width);
1569: $height = 400 if (not defined $height);
1570:
1571: $topic=~s/\W+/\+/g;
1572: my $link='';
1573: my $template='';
1574: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1575: if (!$stayOnPage)
1576: {
1577: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1578: }
1579: else
1580: {
1581: $link = $url;
1582: }
1583:
1584: # Add the text
1585: if ($text ne "")
1586: {
1587: $template .=
1.173 www 1588: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1589: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1590: }
1591:
1592: # Add the graphic
1.179 matthew 1593: my $title = &mt('View the FAQ');
1.215 albertel 1594: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1595: $template .= <<"ENDTEMPLATE";
1.436 albertel 1596: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1597: ENDTEMPLATE
1598: if ($text ne '') { $template.='</td></tr></table>' };
1599: return $template;
1600:
1.44 bowersj2 1601: }
1.37 matthew 1602:
1.180 matthew 1603: ###############################################################
1604: ###############################################################
1605:
1.45 matthew 1606: =pod
1607:
1.648 raeburn 1608: =item * &change_content_javascript():
1.256 matthew 1609:
1610: This and the next function allow you to create small sections of an
1611: otherwise static HTML page that you can update on the fly with
1612: Javascript, even in Netscape 4.
1613:
1614: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1615: must be written to the HTML page once. It will prove the Javascript
1616: function "change(name, content)". Calling the change function with the
1617: name of the section
1618: you want to update, matching the name passed to C<changable_area>, and
1619: the new content you want to put in there, will put the content into
1620: that area.
1621:
1622: B<Note>: Netscape 4 only reserves enough space for the changable area
1623: to contain room for the original contents. You need to "make space"
1624: for whatever changes you wish to make, and be B<sure> to check your
1625: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1626: it's adequate for updating a one-line status display, but little more.
1627: This script will set the space to 100% width, so you only need to
1628: worry about height in Netscape 4.
1629:
1630: Modern browsers are much less limiting, and if you can commit to the
1631: user not using Netscape 4, this feature may be used freely with
1632: pretty much any HTML.
1633:
1634: =cut
1635:
1636: sub change_content_javascript {
1637: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1638: if ($env{'browser.type'} eq 'netscape' &&
1639: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1640: return (<<NETSCAPE4);
1641: function change(name, content) {
1642: doc = document.layers[name+"___escape"].layers[0].document;
1643: doc.open();
1644: doc.write(content);
1645: doc.close();
1646: }
1647: NETSCAPE4
1648: } else {
1649: # Otherwise, we need to use semi-standards-compliant code
1650: # (technically, "innerHTML" isn't standard but the equivalent
1651: # is really scary, and every useful browser supports it
1652: return (<<DOMBASED);
1653: function change(name, content) {
1654: element = document.getElementById(name);
1655: element.innerHTML = content;
1656: }
1657: DOMBASED
1658: }
1659: }
1660:
1661: =pod
1662:
1.648 raeburn 1663: =item * &changable_area($name,$origContent):
1.256 matthew 1664:
1665: This provides a "changable area" that can be modified on the fly via
1666: the Javascript code provided in C<change_content_javascript>. $name is
1667: the name you will use to reference the area later; do not repeat the
1668: same name on a given HTML page more then once. $origContent is what
1669: the area will originally contain, which can be left blank.
1670:
1671: =cut
1672:
1673: sub changable_area {
1674: my ($name, $origContent) = @_;
1675:
1.258 albertel 1676: if ($env{'browser.type'} eq 'netscape' &&
1677: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1678: # If this is netscape 4, we need to use the Layer tag
1679: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1680: } else {
1681: return "<span id='$name'>$origContent</span>";
1682: }
1683: }
1684:
1685: =pod
1686:
1.648 raeburn 1687: =item * &viewport_geometry_js
1.590 raeburn 1688:
1689: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1690:
1691: =cut
1692:
1693:
1694: sub viewport_geometry_js {
1695: return <<"GEOMETRY";
1696: var Geometry = {};
1697: function init_geometry() {
1698: if (Geometry.init) { return };
1699: Geometry.init=1;
1700: if (window.innerHeight) {
1701: Geometry.getViewportHeight = function() { return window.innerHeight; };
1702: Geometry.getViewportWidth = function() { return window.innerWidth; };
1703: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1704: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1705: }
1706: else if (document.documentElement && document.documentElement.clientHeight) {
1707: Geometry.getViewportHeight =
1708: function() { return document.documentElement.clientHeight; };
1709: Geometry.getViewportWidth =
1710: function() { return document.documentElement.clientWidth; };
1711:
1712: Geometry.getHorizontalScroll =
1713: function() { return document.documentElement.scrollLeft; };
1714: Geometry.getVerticalScroll =
1715: function() { return document.documentElement.scrollTop; };
1716: }
1717: else if (document.body.clientHeight) {
1718: Geometry.getViewportHeight =
1719: function() { return document.body.clientHeight; };
1720: Geometry.getViewportWidth =
1721: function() { return document.body.clientWidth; };
1722: Geometry.getHorizontalScroll =
1723: function() { return document.body.scrollLeft; };
1724: Geometry.getVerticalScroll =
1725: function() { return document.body.scrollTop; };
1726: }
1727: }
1728:
1729: GEOMETRY
1730: }
1731:
1732: =pod
1733:
1.648 raeburn 1734: =item * &viewport_size_js()
1.590 raeburn 1735:
1736: 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.
1737:
1738: =cut
1739:
1740: sub viewport_size_js {
1741: my $geometry = &viewport_geometry_js();
1742: return <<"DIMS";
1743:
1744: $geometry
1745:
1746: function getViewportDims(width,height) {
1747: init_geometry();
1748: width.value = Geometry.getViewportWidth();
1749: height.value = Geometry.getViewportHeight();
1750: return;
1751: }
1752:
1753: DIMS
1754: }
1755:
1756: =pod
1757:
1.648 raeburn 1758: =item * &resize_textarea_js()
1.565 albertel 1759:
1760: emits the needed javascript to resize a textarea to be as big as possible
1761:
1762: creates a function resize_textrea that takes two IDs first should be
1763: the id of the element to resize, second should be the id of a div that
1764: surrounds everything that comes after the textarea, this routine needs
1765: to be attached to the <body> for the onload and onresize events.
1766:
1.648 raeburn 1767: =back
1.565 albertel 1768:
1769: =cut
1770:
1771: sub resize_textarea_js {
1.590 raeburn 1772: my $geometry = &viewport_geometry_js();
1.565 albertel 1773: return <<"RESIZE";
1774: <script type="text/javascript">
1.824 bisitz 1775: // <![CDATA[
1.590 raeburn 1776: $geometry
1.565 albertel 1777:
1.588 albertel 1778: function getX(element) {
1779: var x = 0;
1780: while (element) {
1781: x += element.offsetLeft;
1782: element = element.offsetParent;
1783: }
1784: return x;
1785: }
1786: function getY(element) {
1787: var y = 0;
1788: while (element) {
1789: y += element.offsetTop;
1790: element = element.offsetParent;
1791: }
1792: return y;
1793: }
1794:
1795:
1.565 albertel 1796: function resize_textarea(textarea_id,bottom_id) {
1797: init_geometry();
1798: var textarea = document.getElementById(textarea_id);
1799: //alert(textarea);
1800:
1.588 albertel 1801: var textarea_top = getY(textarea);
1.565 albertel 1802: var textarea_height = textarea.offsetHeight;
1803: var bottom = document.getElementById(bottom_id);
1.588 albertel 1804: var bottom_top = getY(bottom);
1.565 albertel 1805: var bottom_height = bottom.offsetHeight;
1806: var window_height = Geometry.getViewportHeight();
1.588 albertel 1807: var fudge = 23;
1.565 albertel 1808: var new_height = window_height-fudge-textarea_top-bottom_height;
1809: if (new_height < 300) {
1810: new_height = 300;
1811: }
1812: textarea.style.height=new_height+'px';
1813: }
1.824 bisitz 1814: // ]]>
1.565 albertel 1815: </script>
1816: RESIZE
1817:
1818: }
1819:
1.1205 golterma 1820: sub colorfuleditor_js {
1.1248 raeburn 1821: my $browse_or_search;
1822: my $respath;
1823: my ($cnum,$cdom) = &crsauthor_url();
1824: if ($cnum) {
1825: $respath = "/res/$cdom/$cnum/";
1826: my %js_lt = &Apache::lonlocal::texthash(
1827: sunm => 'Sub-directory name',
1828: save => 'Save page to make this permanent',
1829: );
1830: &js_escape(\%js_lt);
1.1400 raeburn 1831: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1832: $browse_or_search = <<"END";
1833:
1.1400 raeburn 1834: $showfile_js
1835:
1.1248 raeburn 1836: function toggleChooser(form,element,titleid,only,search) {
1837: var disp = 'none';
1838: if (document.getElementById('chooser_'+element)) {
1839: var curr = document.getElementById('chooser_'+element).style.display;
1840: if (curr == 'none') {
1841: disp='inline';
1842: if (form.elements['chooser_'+element].length) {
1843: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1844: form.elements['chooser_'+element][i].checked = false;
1845: }
1846: }
1847: toggleResImport(form,element);
1848: }
1849: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1850: var dirsel = '';
1851: var filesel = '';
1852: if (document.getElementById('chooser_'+element+'_crsres')) {
1853: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1854: if (currcrsres == 'none') {
1855: dirsel = 'coursepath_'+element;
1856: var filesel = 'coursefile_'+element;
1857: var include;
1858: if (document.getElementById('crsres_include_'+element)) {
1859: include = document.getElementById('crsres_include_'+element).value;
1860: }
1.1402 raeburn 1861: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 1862: }
1863: }
1864: if (document.getElementById('chooser_'+element+'_upload')) {
1865: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1866: if (currcrsupload == 'none') {
1867: dirsel = 'crsauthorpath_'+element;
1868: filesel = '';
1.1402 raeburn 1869: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 1870: }
1871: }
1.1248 raeburn 1872: }
1873: }
1874:
1.1400 raeburn 1875: function toggleCrsFile(form,element) {
1.1248 raeburn 1876: if (document.getElementById('chooser_'+element+'_crsres')) {
1877: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1878: if (curr == 'none') {
1.1400 raeburn 1879: if (document.getElementById('coursepath_'+element)) {
1880: var numdirs;
1881: if (document.getElementById('coursepath_'+element).length) {
1882: numdirs = document.getElementById('coursepath_'+element).length;
1883: }
1.1402 raeburn 1884: if ((document.getElementById('hascrsres_'+element)) &&
1885: (document.getElementById('nocrsres_'+element))) {
1886: if (numdirs) {
1887: document.getElementById('hascrsres_'+element).style.display='inline-block';
1888: document.getElementById('nocrsres_'+element).style.display='none';
1889: } else {
1890: document.getElementById('hascrsres_'+element).style.display='none';
1891: document.getElementById('nocrsres_'+element).style.display='inline-block';
1892: }
1893: }
1.1248 raeburn 1894: form.elements['coursepath_'+element].selectedIndex = 0;
1895: if (numdirs > 1) {
1.1400 raeburn 1896: var selelem = form.elements['coursefile_'+element];
1897: var i, len = selelem.options.length -1;
1898: if (len >=0) {
1899: for (i = len; i >= 0; i--) {
1900: selelem.remove(i);
1901: }
1902: selelem.options[0] = new Option('','');
1903: }
1.1248 raeburn 1904: }
1905: }
1.1400 raeburn 1906: }
1.1248 raeburn 1907: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1908: }
1909: if (document.getElementById('chooser_'+element+'_upload')) {
1910: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1911: if (document.getElementById('uploadcrsres_'+element)) {
1912: document.getElementById('uploadcrsres_'+element).value = '';
1913: }
1914: }
1915: return;
1916: }
1917:
1.1400 raeburn 1918: function toggleCrsUpload(form,element) {
1.1248 raeburn 1919: if (document.getElementById('chooser_'+element+'_crsres')) {
1920: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1921: }
1922: if (document.getElementById('chooser_'+element+'_upload')) {
1923: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1924: if (curr == 'none') {
1.1400 raeburn 1925: form.elements['newsubdir_'+element][0].checked = true;
1926: toggleNewsubdir(form,element);
1927: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1928: if (document.getElementById('uploadcrsres_'+element)) {
1929: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1930: }
1931: }
1932: }
1933: return;
1934: }
1935:
1936: function toggleResImport(form,element) {
1937: var choices = new Array('crsres','upload');
1938: for (var i=0; i<choices.length; i++) {
1939: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1940: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1941: }
1942: }
1943: }
1944:
1945: function toggleNewsubdir(form,element) {
1946: var newsub = form.elements['newsubdir_'+element];
1947: if (newsub) {
1948: if (newsub.length) {
1949: for (var j=0; j<newsub.length; j++) {
1950: if (newsub[j].checked) {
1951: if (document.getElementById('newsubdirname_'+element)) {
1952: if (newsub[j].value == '1') {
1953: document.getElementById('newsubdirname_'+element).type = "text";
1954: if (document.getElementById('newsubdir_'+element)) {
1955: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1956: }
1957: } else {
1958: document.getElementById('newsubdirname_'+element).type = "hidden";
1959: document.getElementById('newsubdirname_'+element).value = "";
1960: document.getElementById('newsubdir_'+element).innerHTML = "";
1961: }
1962: }
1963: break;
1964: }
1965: }
1966: }
1967: }
1968: }
1969:
1970: function updateCrsFile(form,element) {
1971: var directory = form.elements['coursepath_'+element];
1972: var filename = form.elements['coursefile_'+element];
1973: var path = directory.options[directory.selectedIndex].value;
1974: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1975: if (file != '') {
1976: form.elements[element].value = '$respath';
1977: if (path == '/') {
1978: form.elements[element].value += file;
1979: } else {
1980: form.elements[element].value += path+'/'+file;
1981: }
1982: unClean();
1983: if (document.getElementById('previewimg_'+element)) {
1984: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1985: var newsrc = document.getElementById('previewimg_'+element).src;
1986: }
1987: if (document.getElementById('showimg_'+element)) {
1988: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1989: }
1.1248 raeburn 1990: }
1991: toggleChooser(form,element);
1992: return;
1993: }
1994:
1995: function uploadDone(suffix,name) {
1996: if (name) {
1997: document.forms["lonhomework"].elements[suffix].value = name;
1998: unClean();
1999: toggleChooser(document.forms["lonhomework"],suffix);
2000: }
2001: }
2002:
2003: \$(document).ready(function(){
2004:
2005: \$(document).delegate('form :submit', 'click', function( event ) {
2006: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2007: var buttonId = this.id;
2008: var suffix = buttonId.toString();
2009: suffix = suffix.replace(/^crsupload_/,'');
2010: event.preventDefault();
2011: document.lonhomework.target = 'crsupload_target_'+suffix;
2012: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2013: \$(this.form).submit();
2014: document.lonhomework.target = '';
2015: if (document.getElementById('crsuploadto_'+suffix)) {
2016: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2017: }
2018: return false;
2019: }
2020: });
2021: });
2022: END
2023: }
1.1205 golterma 2024: return <<"COLORFULEDIT"
2025: <script type="text/javascript">
2026: // <![CDATA[>
2027: function fold_box(curDepth, lastresource){
2028:
2029: // we need a list because there can be several blocks you need to fold in one tag
2030: var block = document.getElementsByName('foldblock_'+curDepth);
2031: // but there is only one folding button per tag
2032: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2033:
2034: if(block.item(0).style.display == 'none'){
2035:
2036: foldbutton.value = '@{[&mt("Hide")]}';
2037: for (i = 0; i < block.length; i++){
2038: block.item(i).style.display = '';
2039: }
2040: }else{
2041:
2042: foldbutton.value = '@{[&mt("Show")]}';
2043: for (i = 0; i < block.length; i++){
2044: // block.item(i).style.visibility = 'collapse';
2045: block.item(i).style.display = 'none';
2046: }
2047: };
2048: saveState(lastresource);
2049: }
2050:
2051: function saveState (lastresource) {
2052:
2053: var tag_list = getTagList();
2054: if(tag_list != null){
2055: var timestamp = new Date().getTime();
2056: var key = lastresource;
2057:
2058: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2059: // starting with timestamp
2060: var value = timestamp+';';
2061:
2062: // building the list of key-value pairs
2063: for(var i = 0; i < tag_list.length; i++){
2064: value += tag_list[i]+',';
2065: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2066: }
2067:
2068: // only iterate whole storage if nothing to override
2069: if(localStorage.getItem(key) == null){
2070:
2071: // prevent storage from growing large
2072: if(localStorage.length > 50){
2073: var regex_getTimestamp = /^(?:\d)+;/;
2074: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2075: var oldest_key;
2076:
2077: for(var i = 1; i < localStorage.length; i++){
2078: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2079: oldest_key = localStorage.key(i);
2080: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2081: }
2082: }
2083: localStorage.removeItem(oldest_key);
2084: }
2085: }
2086: localStorage.setItem(key,value);
2087: }
2088: }
2089:
2090: // restore folding status of blocks (on page load)
2091: function restoreState (lastresource) {
2092: if(localStorage.getItem(lastresource) != null){
2093: var key = lastresource;
2094: var value = localStorage.getItem(key);
2095: var regex_delTimestamp = /^\d+;/;
2096:
2097: value.replace(regex_delTimestamp, '');
2098:
2099: var valueArr = value.split(';');
2100: var pairs;
2101: var elements;
2102: for (var i = 0; i < valueArr.length; i++){
2103: pairs = valueArr[i].split(',');
2104: elements = document.getElementsByName(pairs[0]);
2105:
2106: for (var j = 0; j < elements.length; j++){
2107: elements[j].style.display = pairs[1];
2108: if (pairs[1] == "none"){
2109: var regex_id = /([_\\d]+)\$/;
2110: regex_id.exec(pairs[0]);
2111: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2112: }
2113: }
2114: }
2115: }
2116: }
2117:
2118: function getTagList () {
2119:
2120: var stringToSearch = document.lonhomework.innerHTML;
2121:
2122: var ret = new Array();
2123: var regex_findBlock = /(foldblock_.*?)"/g;
2124: var tag_list = stringToSearch.match(regex_findBlock);
2125:
2126: if(tag_list != null){
2127: for(var i = 0; i < tag_list.length; i++){
2128: ret.push(tag_list[i].replace(/"/, ''));
2129: }
2130: }
2131: return ret;
2132: }
2133:
2134: function saveScrollPosition (resource) {
2135: var tag_list = getTagList();
2136:
2137: // we dont always want to jump to the first block
2138: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2139: if(\$(window).scrollTop() > 170){
2140: if(tag_list != null){
2141: var result;
2142: for(var i = 0; i < tag_list.length; i++){
2143: if(isElementInViewport(tag_list[i])){
2144: result += tag_list[i]+';';
2145: }
2146: }
2147: sessionStorage.setItem('anchor_'+resource, result);
2148: }
2149: } else {
2150: // we dont need to save zero, just delete the item to leave everything tidy
2151: sessionStorage.removeItem('anchor_'+resource);
2152: }
2153: }
2154:
2155: function restoreScrollPosition(resource){
2156:
2157: var elem = sessionStorage.getItem('anchor_'+resource);
2158: if(elem != null){
2159: var tag_list = elem.split(';');
2160: var elem_list;
2161:
2162: for(var i = 0; i < tag_list.length; i++){
2163: elem_list = document.getElementsByName(tag_list[i]);
2164:
2165: if(elem_list.length > 0){
2166: elem = elem_list[0];
2167: break;
2168: }
2169: }
2170: elem.scrollIntoView();
2171: }
2172: }
2173:
2174: function isElementInViewport(el) {
2175:
2176: // change to last element instead of first
2177: var elem = document.getElementsByName(el);
2178: var rect = elem[0].getBoundingClientRect();
2179:
2180: return (
2181: rect.top >= 0 &&
2182: rect.left >= 0 &&
2183: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2184: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2185: );
2186: }
2187:
2188: function autosize(depth){
2189: var cmInst = window['cm'+depth];
2190: var fitsizeButton = document.getElementById('fitsize'+depth);
2191:
2192: // is fixed size, switching to dynamic
2193: if (sessionStorage.getItem("autosized_"+depth) == null) {
2194: cmInst.setSize("","auto");
2195: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2196: sessionStorage.setItem("autosized_"+depth, "yes");
2197:
2198: // is dynamic size, switching to fixed
2199: } else {
2200: cmInst.setSize("","300px");
2201: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2202: sessionStorage.removeItem("autosized_"+depth);
2203: }
2204: }
2205:
1.1248 raeburn 2206: $browse_or_search
1.1205 golterma 2207:
2208: // ]]>
2209: </script>
2210: COLORFULEDIT
2211: }
2212:
2213: sub xmleditor_js {
2214: return <<XMLEDIT
2215: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2216: <script type="text/javascript">
2217: // <![CDATA[>
2218:
2219: function saveScrollPosition (resource) {
2220:
2221: var scrollPos = \$(window).scrollTop();
2222: sessionStorage.setItem(resource,scrollPos);
2223: }
2224:
2225: function restoreScrollPosition(resource){
2226:
2227: var scrollPos = sessionStorage.getItem(resource);
2228: \$(window).scrollTop(scrollPos);
2229: }
2230:
2231: // unless internet explorer
2232: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2233:
2234: \$(document).ready(function() {
2235: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2236: });
2237: }
2238:
2239: // inserts text at cursor position into codemirror (xml editor only)
2240: function insertText(text){
2241: cm.focus();
2242: var curPos = cm.getCursor();
2243: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2244: }
2245: // ]]>
2246: </script>
2247: XMLEDIT
2248: }
2249:
2250: sub insert_folding_button {
2251: my $curDepth = $Apache::lonxml::curdepth;
2252: my $lastresource = $env{'request.ambiguous'};
2253:
2254: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2255: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2256: }
2257:
1.1248 raeburn 2258: sub crsauthor_url {
2259: my ($url) = @_;
2260: if ($url eq '') {
2261: $url = $ENV{'REQUEST_URI'};
2262: }
2263: my ($cnum,$cdom);
2264: if ($env{'request.course.id'}) {
2265: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2266: if ($audom ne '' && $auname ne '') {
2267: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2268: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2269: $cnum = $auname;
2270: $cdom = $audom;
2271: }
2272: }
2273: }
2274: return ($cnum,$cdom);
2275: }
2276:
2277: sub import_crsauthor_form {
1.1400 raeburn 2278: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2279: return (0) unless ($env{'request.course.id'});
2280: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2281: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2282: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2283: return (0) unless (($cnum ne '') && ($cdom ne ''));
2284: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2285: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2286:
1.1248 raeburn 2287: if (grep(/^\Q$crshome\E$/,@ids)) {
2288: $is_home = 1;
2289: }
1.1400 raeburn 2290: $toppath = "/priv/$cdom/$cnum";
2291: my $nonemptydir = 1;
2292: my $js_only;
2293: if ($only) {
2294: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2295: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2296: }
2297: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2298: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2299: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2300: my %lt = &Apache::lonlocal::texthash (
2301: fnam => 'Filename',
2302: dire => 'Directory',
1.1400 raeburn 2303: se => 'Select',
1.1248 raeburn 2304: );
1.1402 raeburn 2305: $output = $lt{'dire'}.': '.
1.1400 raeburn 2306: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2307: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2308: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2309: if ($files{'/'}) {
2310: $output .= '<option value="/">/</option>'."\n";
2311: }
1.1400 raeburn 2312: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2313: next if ($key eq '/');
1.1400 raeburn 2314: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2315: }
2316: $output .= '</select><br />'."\n".
1.1402 raeburn 2317: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2318: '<option value="" selected="selected"></option>'."\n".
1.1402 raeburn 2319: '</select>'."\n".
2320: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2321: return ($numdirs,$output);
2322: }
2323:
2324: sub show_crsfiles_js {
2325: my $excluderef = &Apache::lonnet::priv_exclude();
2326: my $se = &js_escape(&mt('Select'));
2327: my $exclude;
2328: if (ref($excluderef) eq 'HASH') {
2329: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2330: }
2331: my $js = <<"END";
2332:
2333:
1.1402 raeburn 2334: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2335: var relpath = '';
2336: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2337: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2338: if (currdir == '') {
2339: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2340: selelem = form.elements[filesel];
2341: var j, numfiles = selelem.options.length -1;
2342: if (numfiles >=0) {
2343: for (j = numfiles; j >= 0; j--) {
2344: selelem.remove(j);
2345: }
2346: }
2347: if (selelem.options.length == 0) {
2348: selelem.options[selelem.options.length] = new Option('','');
2349: selelem.selectedIndex = 0;
1.1248 raeburn 2350: }
2351: }
1.1400 raeburn 2352: return;
2353: } else {
2354: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2355: }
2356: }
1.1400 raeburn 2357: var http = new XMLHttpRequest();
2358: var url = "/adm/courseauthor";
2359: var crsrole = "$env{'request.role'}";
2360: var exclude = '';
2361: if (exc) {
2362: exclude = '$exclude';
2363: }
1.1402 raeburn 2364: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2365: http.open("POST", url, true);
2366: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2367: http.onreadystatechange = function() {
2368: if (http.readyState == 4 && http.status == 200) {
2369: var data = JSON.parse(http.responseText);
2370: var selelem;
2371: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2372: if (Array.isArray(data.dirs)) {
2373: selelem = form.elements[dirsel];
2374: var i, numdirs = selelem.options.length -1;
2375: if (numdirs >=0) {
2376: for (i = numdirs; i >= 0; i--) {
2377: selelem.remove(i);
2378: }
2379: }
2380: var len = data.dirs.length;
2381: if (len) {
1.1402 raeburn 2382: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2383: var j;
2384: for (j = 0; j < len; j++) {
2385: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2386: }
2387: selelem.selectedIndex = 0;
2388: }
2389: if (!setfile) {
2390: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2391: selelem = form.elements[filesel];
2392: var j, numfiles = selelem.options.length -1;
2393: if (numfiles >=0) {
2394: for (j = numfiles; j >= 0; j--) {
2395: selelem.remove(j);
2396: }
2397: }
2398: if (selelem.options.length == 0) {
2399: selelem.options[selelem.options.length] = new Option('','');
2400: selelem.selectedIndex = 0;
2401: }
2402: }
2403: }
2404: }
2405: }
2406: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2407: selelem = form.elements[filesel];
2408: var i, numfiles = selelem.options.length -1;
2409: if (numfiles >=0) {
2410: for (i = numfiles; i >= 0; i--) {
2411: selelem.remove(i);
2412: }
2413: }
2414: var x;
2415: for (x in data.files) {
2416: if (Array.isArray(data.files[x])) {
2417: if (data.files[x].length > 1) {
2418: selelem.options[selelem.options.length] = new Option('$se','');
2419: }
2420: var len = data.files[x].length;
2421: if (len) {
2422: var k;
2423: for (k = 0; k < len; k++) {
2424: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2425: }
2426: selelem.selectedIndex = 0;
2427: }
2428: }
2429: }
2430: if (selelem.options.length == 0) {
2431: selelem.options[selelem.options.length] = new Option('','');
2432: selelem.selectedIndex = 0;
2433: }
1.1248 raeburn 2434: }
2435: }
2436: }
1.1400 raeburn 2437: http.send(params);
1.1248 raeburn 2438: }
1.1400 raeburn 2439: END
1.1248 raeburn 2440: }
2441:
1.565 albertel 2442: =pod
2443:
1.1420 raeburn 2444: =item * &iframe_wrapper_headjs()
2445:
2446: #
2447: # Where iframe is in use, if window.onload() executes before the custom resize function
2448: # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
2449: # are used to ensure document.ready() triggers a call to resize, so the iframe contents
2450: # do not obscure the Functions menu.
2451: #
2452:
2453: =back
2454:
2455: =cut
2456:
2457:
2458: sub iframe_wrapper_headjs {
2459: return <<"ENDJS";
2460: <script type="text/javascript">
2461: // <![CDATA[
2462: var LCnotready = 0;
2463: var LCresizedef = 0;
2464: // ]]>
2465: </script>
2466:
2467: ENDJS
2468:
2469: }
2470:
2471: =pod
2472:
2473: =item * &iframe_wrapper_resizejs()
2474:
2475: #
2476: # jQuery to use when iframe is in use and a page resize occurs.
2477: # This script will ensure that the iframe does not obscure any
2478: # standard LON-CAPA inline menus (primary, secondary, and/or
2479: # breadcrumbs and Functions menus. Expects javascript from
2480: # &iframe_wrapper_headjs() to be in head portion of the web page,
2481: # e.g., by inclusion in second arg passed to &start_page().
2482: #
2483:
2484: =back
2485:
2486: =cut
2487:
2488: sub iframe_wrapper_resizejs {
2489: my $offset = 5;
2490: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
2491: if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
2492: $offset = 0;
2493: }
2494: return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
2495: \$(document).ready( function() {
2496: \$(window).unbind('resize').resize(function(){
2497: var header = null;
2498: var offset = $offset;
2499: var height = 0;
2500: var hdrtop = 0;
1.1421 ! raeburn 2501: if (\$('div.LC_menus_content:first').length) {
! 2502: if (\$('div.LC_menus_content:first').hasClass ("shown")) {
! 2503: header = \$('div.LC_menus_content:first');
! 2504: offset = 9;
! 2505: }
! 2506: } else if (\$('div.LC_head_subbox:first').length) {
1.1420 raeburn 2507: header = \$('div.LC_head_subbox:first');
2508: offset = 9;
2509: } else {
2510: if (\$('#LC_breadcrumbs').length) {
2511: header = \$('#LC_breadcrumbs');
2512: }
2513: }
2514: if (header != null && header.length) {
2515: height = header.height();
2516: hdrtop = header.position().top;
2517: }
2518: var pos = height + hdrtop + offset;
2519: \$('.LC_iframecontainer').css('top', pos);
2520: });
2521: LCresizedef = 1;
2522: if (LCnotready == 1) {
2523: LCnotready = 0;
2524: \$(window).trigger('resize');
2525: }
2526: });
2527: window.onload = function(){
2528: if (LCresizedef) {
2529: LCnotready = 0;
2530: \$(window).trigger('resize');
2531: } else {
2532: LCnotready = 1;
2533: }
2534: };
2535: SCRIPT
2536:
2537: }
2538:
2539: =pod
2540:
1.256 matthew 2541: =head1 Excel and CSV file utility routines
2542:
2543: =cut
2544:
2545: ###############################################################
2546: ###############################################################
2547:
2548: =pod
2549:
1.1162 raeburn 2550: =over 4
2551:
1.648 raeburn 2552: =item * &csv_translate($text)
1.37 matthew 2553:
1.185 www 2554: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2555: format.
2556:
2557: =cut
2558:
1.180 matthew 2559: ###############################################################
2560: ###############################################################
1.37 matthew 2561: sub csv_translate {
2562: my $text = shift;
2563: $text =~ s/\"/\"\"/g;
1.209 albertel 2564: $text =~ s/\n/ /g;
1.37 matthew 2565: return $text;
2566: }
1.180 matthew 2567:
2568: ###############################################################
2569: ###############################################################
2570:
2571: =pod
2572:
1.648 raeburn 2573: =item * &define_excel_formats()
1.180 matthew 2574:
2575: Define some commonly used Excel cell formats.
2576:
2577: Currently supported formats:
2578:
2579: =over 4
2580:
2581: =item header
2582:
2583: =item bold
2584:
2585: =item h1
2586:
2587: =item h2
2588:
2589: =item h3
2590:
1.256 matthew 2591: =item h4
2592:
2593: =item i
2594:
1.180 matthew 2595: =item date
2596:
2597: =back
2598:
2599: Inputs: $workbook
2600:
2601: Returns: $format, a hash reference.
2602:
1.1057 foxr 2603:
1.180 matthew 2604: =cut
2605:
2606: ###############################################################
2607: ###############################################################
2608: sub define_excel_formats {
2609: my ($workbook) = @_;
2610: my $format;
2611: $format->{'header'} = $workbook->add_format(bold => 1,
2612: bottom => 1,
2613: align => 'center');
2614: $format->{'bold'} = $workbook->add_format(bold=>1);
2615: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2616: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2617: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2618: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2619: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2620: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2621: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2622: return $format;
2623: }
2624:
2625: ###############################################################
2626: ###############################################################
1.113 bowersj2 2627:
2628: =pod
2629:
1.648 raeburn 2630: =item * &create_workbook()
1.255 matthew 2631:
2632: Create an Excel worksheet. If it fails, output message on the
2633: request object and return undefs.
2634:
2635: Inputs: Apache request object
2636:
2637: Returns (undef) on failure,
2638: Excel worksheet object, scalar with filename, and formats
2639: from &Apache::loncommon::define_excel_formats on success
2640:
2641: =cut
2642:
2643: ###############################################################
2644: ###############################################################
2645: sub create_workbook {
2646: my ($r) = @_;
2647: #
2648: # Create the excel spreadsheet
2649: my $filename = '/prtspool/'.
1.258 albertel 2650: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2651: time.'_'.rand(1000000000).'.xls';
2652: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2653: if (! defined($workbook)) {
2654: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2655: $r->print(
2656: '<p class="LC_error">'
2657: .&mt('Problems occurred in creating the new Excel file.')
2658: .' '.&mt('This error has been logged.')
2659: .' '.&mt('Please alert your LON-CAPA administrator.')
2660: .'</p>'
2661: );
1.255 matthew 2662: return (undef);
2663: }
2664: #
1.1014 foxr 2665: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2666: #
2667: my $format = &Apache::loncommon::define_excel_formats($workbook);
2668: return ($workbook,$filename,$format);
2669: }
2670:
2671: ###############################################################
2672: ###############################################################
2673:
2674: =pod
2675:
1.648 raeburn 2676: =item * &create_text_file()
1.113 bowersj2 2677:
1.542 raeburn 2678: Create a file to write to and eventually make available to the user.
1.256 matthew 2679: If file creation fails, outputs an error message on the request object and
2680: return undefs.
1.113 bowersj2 2681:
1.256 matthew 2682: Inputs: Apache request object, and file suffix
1.113 bowersj2 2683:
1.256 matthew 2684: Returns (undef) on failure,
2685: Filehandle and filename on success.
1.113 bowersj2 2686:
2687: =cut
2688:
1.256 matthew 2689: ###############################################################
2690: ###############################################################
2691: sub create_text_file {
2692: my ($r,$suffix) = @_;
2693: if (! defined($suffix)) { $suffix = 'txt'; };
2694: my $fh;
2695: my $filename = '/prtspool/'.
1.258 albertel 2696: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2697: time.'_'.rand(1000000000).'.'.$suffix;
2698: $fh = Apache::File->new('>/home/httpd'.$filename);
2699: if (! defined($fh)) {
2700: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2701: $r->print(
2702: '<p class="LC_error">'
2703: .&mt('Problems occurred in creating the output file.')
2704: .' '.&mt('This error has been logged.')
2705: .' '.&mt('Please alert your LON-CAPA administrator.')
2706: .'</p>'
2707: );
1.113 bowersj2 2708: }
1.256 matthew 2709: return ($fh,$filename)
1.113 bowersj2 2710: }
2711:
2712:
1.256 matthew 2713: =pod
1.113 bowersj2 2714:
2715: =back
2716:
2717: =cut
1.37 matthew 2718:
2719: ###############################################################
1.33 matthew 2720: ## Home server <option> list generating code ##
2721: ###############################################################
1.35 matthew 2722:
1.169 www 2723: # ------------------------------------------
2724:
2725: sub domain_select {
1.1289 raeburn 2726: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2727: my @possdoms;
2728: if (ref($incdoms) eq 'ARRAY') {
2729: @possdoms = @{$incdoms};
2730: } else {
2731: @possdoms = &Apache::lonnet::all_domains();
2732: }
2733:
1.169 www 2734: my %domains=map {
1.514 albertel 2735: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2736: } @possdoms;
2737:
2738: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2739: foreach my $dom (@{$excdoms}) {
2740: delete($domains{$dom});
2741: }
2742: }
2743:
1.169 www 2744: if ($multiple) {
2745: $domains{''}=&mt('Any domain');
1.550 albertel 2746: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2747: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2748: } else {
1.550 albertel 2749: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2750: return &select_form($name,$value,\%domains);
1.169 www 2751: }
2752: }
2753:
1.282 albertel 2754: #-------------------------------------------
2755:
2756: =pod
2757:
1.519 raeburn 2758: =head1 Routines for form select boxes
2759:
2760: =over 4
2761:
1.648 raeburn 2762: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2763:
2764: Returns a string containing a <select> element int multiple mode
2765:
2766:
2767: Args:
2768: $name - name of the <select> element
1.506 raeburn 2769: $value - scalar or array ref of values that should already be selected
1.282 albertel 2770: $size - number of rows long the select element is
1.283 albertel 2771: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2772: (shown text should already have been &mt())
1.506 raeburn 2773: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2774:
1.282 albertel 2775: =cut
2776:
2777: #-------------------------------------------
1.169 www 2778: sub multiple_select_form {
1.284 albertel 2779: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2780: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2781: my $output='';
1.191 matthew 2782: if (! defined($size)) {
2783: $size = 4;
1.283 albertel 2784: if (scalar(keys(%$hash))<4) {
2785: $size = scalar(keys(%$hash));
1.191 matthew 2786: }
2787: }
1.734 bisitz 2788: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2789: my @order;
1.506 raeburn 2790: if (ref($order) eq 'ARRAY') {
2791: @order = @{$order};
2792: } else {
2793: @order = sort(keys(%$hash));
1.501 banghart 2794: }
2795: if (exists($$hash{'select_form_order'})) {
2796: @order = @{$$hash{'select_form_order'}};
2797: }
2798:
1.284 albertel 2799: foreach my $key (@order) {
1.356 albertel 2800: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2801: $output.='selected="selected" ' if ($selected{$key});
2802: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2803: }
2804: $output.="</select>\n";
2805: return $output;
2806: }
2807:
1.88 www 2808: #-------------------------------------------
2809:
2810: =pod
2811:
1.1254 raeburn 2812: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2813:
2814: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2815: allow a user to select options from a ref to a hash containing:
2816: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2817: a javascript onchange item, e.g., onchange="this.form.submit();".
2818: An optional arg -- $readonly -- if true will cause the select form
2819: to be disabled, e.g., for the case where an instructor has a section-
2820: specific role, and is viewing/modifying parameters.
1.970 raeburn 2821:
1.88 www 2822: See lonrights.pm for an example invocation and use.
2823:
2824: =cut
2825:
2826: #-------------------------------------------
2827: sub select_form {
1.1228 raeburn 2828: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2829: return unless (ref($hashref) eq 'HASH');
2830: if ($onchange) {
2831: $onchange = ' onchange="'.$onchange.'"';
2832: }
1.1228 raeburn 2833: my $disabled;
2834: if ($readonly) {
2835: $disabled = ' disabled="disabled"';
2836: }
2837: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2838: my @keys;
1.970 raeburn 2839: if (exists($hashref->{'select_form_order'})) {
2840: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2841: } else {
1.970 raeburn 2842: @keys=sort(keys(%{$hashref}));
1.128 albertel 2843: }
1.356 albertel 2844: foreach my $key (@keys) {
2845: $selectform.=
2846: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2847: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2848: ">".$hashref->{$key}."</option>\n";
1.88 www 2849: }
2850: $selectform.="</select>";
2851: return $selectform;
2852: }
2853:
1.475 www 2854: # For display filters
2855:
2856: sub display_filter {
1.1074 raeburn 2857: my ($context) = @_;
1.475 www 2858: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2859: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2860: my $phraseinput = 'hidden';
2861: my $includeinput = 'hidden';
2862: my ($checked,$includetypestext);
2863: if ($env{'form.displayfilter'} eq 'containing') {
2864: $phraseinput = 'text';
2865: if ($context eq 'parmslog') {
2866: $includeinput = 'checkbox';
2867: if ($env{'form.includetypes'}) {
2868: $checked = ' checked="checked"';
2869: }
2870: $includetypestext = &mt('Include parameter types');
2871: }
2872: } else {
2873: $includetypestext = ' ';
2874: }
2875: my ($additional,$secondid,$thirdid);
2876: if ($context eq 'parmslog') {
2877: $additional =
2878: '<label><input type="'.$includeinput.'" name="includetypes"'.
2879: $checked.' name="includetypes" value="1" id="includetypes" />'.
2880: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2881: '</label>';
2882: $secondid = 'includetypes';
2883: $thirdid = 'includetypestext';
2884: }
2885: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2886: '$secondid','$thirdid')";
2887: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2888: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2889: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2890: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2891: &mt('Filter: [_1]',
1.477 www 2892: &select_form($env{'form.displayfilter'},
2893: 'displayfilter',
1.970 raeburn 2894: {'currentfolder' => 'Current folder/page',
1.477 www 2895: 'containing' => 'Containing phrase',
1.1074 raeburn 2896: 'none' => 'None'},$onchange)).' '.
2897: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2898: &HTML::Entities::encode($env{'form.containingphrase'}).
2899: '" />'.$additional;
2900: }
2901:
2902: sub display_filter_js {
2903: my $includetext = &mt('Include parameter types');
2904: return <<"ENDJS";
2905:
2906: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2907: var firstType = 'hidden';
2908: if (setter.options[setter.selectedIndex].value == 'containing') {
2909: firstType = 'text';
2910: }
2911: firstObject = document.getElementById(firstid);
2912: if (typeof(firstObject) == 'object') {
2913: if (firstObject.type != firstType) {
2914: changeInputType(firstObject,firstType);
2915: }
2916: }
2917: if (context == 'parmslog') {
2918: var secondType = 'hidden';
2919: if (firstType == 'text') {
2920: secondType = 'checkbox';
2921: }
2922: secondObject = document.getElementById(secondid);
2923: if (typeof(secondObject) == 'object') {
2924: if (secondObject.type != secondType) {
2925: changeInputType(secondObject,secondType);
2926: }
2927: }
2928: var textItem = document.getElementById(thirdid);
2929: var currtext = textItem.innerHTML;
2930: var newtext;
2931: if (firstType == 'text') {
2932: newtext = '$includetext';
2933: } else {
2934: newtext = ' ';
2935: }
2936: if (currtext != newtext) {
2937: textItem.innerHTML = newtext;
2938: }
2939: }
2940: return;
2941: }
2942:
2943: function changeInputType(oldObject,newType) {
2944: var newObject = document.createElement('input');
2945: newObject.type = newType;
2946: if (oldObject.size) {
2947: newObject.size = oldObject.size;
2948: }
2949: if (oldObject.value) {
2950: newObject.value = oldObject.value;
2951: }
2952: if (oldObject.name) {
2953: newObject.name = oldObject.name;
2954: }
2955: if (oldObject.id) {
2956: newObject.id = oldObject.id;
2957: }
2958: oldObject.parentNode.replaceChild(newObject,oldObject);
2959: return;
2960: }
2961:
2962: ENDJS
1.475 www 2963: }
2964:
1.167 www 2965: sub gradeleveldescription {
2966: my $gradelevel=shift;
2967: my %gradelevels=(0 => 'Not specified',
2968: 1 => 'Grade 1',
2969: 2 => 'Grade 2',
2970: 3 => 'Grade 3',
2971: 4 => 'Grade 4',
2972: 5 => 'Grade 5',
2973: 6 => 'Grade 6',
2974: 7 => 'Grade 7',
2975: 8 => 'Grade 8',
2976: 9 => 'Grade 9',
2977: 10 => 'Grade 10',
2978: 11 => 'Grade 11',
2979: 12 => 'Grade 12',
2980: 13 => 'Grade 13',
2981: 14 => '100 Level',
2982: 15 => '200 Level',
2983: 16 => '300 Level',
2984: 17 => '400 Level',
2985: 18 => 'Graduate Level');
2986: return &mt($gradelevels{$gradelevel});
2987: }
2988:
1.163 www 2989: sub select_level_form {
2990: my ($deflevel,$name)=@_;
2991: unless ($deflevel) { $deflevel=0; }
1.167 www 2992: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2993: for (my $i=0; $i<=18; $i++) {
2994: $selectform.="<option value=\"$i\" ".
1.253 albertel 2995: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2996: ">".&gradeleveldescription($i)."</option>\n";
2997: }
2998: $selectform.="</select>";
2999: return $selectform;
1.163 www 3000: }
1.167 www 3001:
1.35 matthew 3002: #-------------------------------------------
3003:
1.45 matthew 3004: =pod
3005:
1.1256 raeburn 3006: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 3007:
3008: Returns a string containing a <select name='$name' size='1'> form to
3009: allow a user to select the domain to preform an operation in.
3010: See loncreateuser.pm for an example invocation and use.
3011:
1.90 www 3012: If the $includeempty flag is set, it also includes an empty choice ("no domain
3013: selected");
3014:
1.743 raeburn 3015: If the $showdomdesc flag is set, the domain name is followed by the domain description.
3016:
1.910 raeburn 3017: 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.
3018:
1.1121 raeburn 3019: The optional $incdoms is a reference to an array of domains which will be the only available options.
3020:
3021: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 3022:
1.1256 raeburn 3023: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
3024:
1.35 matthew 3025: =cut
3026:
3027: #-------------------------------------------
1.34 matthew 3028: sub select_dom_form {
1.1256 raeburn 3029: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 3030: if ($onchange) {
1.874 raeburn 3031: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 3032: }
1.1256 raeburn 3033: if ($disabled) {
3034: $disabled = ' disabled="disabled"';
3035: }
1.1121 raeburn 3036: my (@domains,%exclude);
1.910 raeburn 3037: if (ref($incdoms) eq 'ARRAY') {
3038: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
3039: } else {
3040: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
3041: }
1.90 www 3042: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 3043: if (ref($excdoms) eq 'ARRAY') {
3044: map { $exclude{$_} = 1; } @{$excdoms};
3045: }
1.1256 raeburn 3046: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 3047: foreach my $dom (@domains) {
1.1121 raeburn 3048: next if ($exclude{$dom});
1.356 albertel 3049: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 3050: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
3051: if ($showdomdesc) {
3052: if ($dom ne '') {
3053: my $domdesc = &Apache::lonnet::domain($dom,'description');
3054: if ($domdesc ne '') {
3055: $selectdomain .= ' ('.$domdesc.')';
3056: }
3057: }
3058: }
3059: $selectdomain .= "</option>\n";
1.34 matthew 3060: }
3061: $selectdomain.="</select>";
3062: return $selectdomain;
3063: }
3064:
1.35 matthew 3065: #-------------------------------------------
3066:
1.45 matthew 3067: =pod
3068:
1.648 raeburn 3069: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 3070:
1.586 raeburn 3071: input: 4 arguments (two required, two optional) -
3072: $domain - domain of new user
3073: $name - name of form element
3074: $default - Value of 'default' causes a default item to be first
3075: option, and selected by default.
3076: $hide - Value of 'hide' causes hiding of the name of the server,
3077: if 1 server found, or default, if 0 found.
1.594 raeburn 3078: output: returns 2 items:
1.586 raeburn 3079: (a) form element which contains either:
3080: (i) <select name="$name">
3081: <option value="$hostid1">$hostid $servers{$hostid}</option>
3082: <option value="$hostid2">$hostid $servers{$hostid}</option>
3083: </select>
3084: form item if there are multiple library servers in $domain, or
3085: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
3086: if there is only one library server in $domain.
3087:
3088: (b) number of library servers found.
3089:
3090: See loncreateuser.pm for example of use.
1.35 matthew 3091:
3092: =cut
3093:
3094: #-------------------------------------------
1.586 raeburn 3095: sub home_server_form_item {
3096: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 3097: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 3098: my $result;
3099: my $numlib = keys(%servers);
3100: if ($numlib > 1) {
3101: $result .= '<select name="'.$name.'" />'."\n";
3102: if ($default) {
1.804 bisitz 3103: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3104: '</option>'."\n";
3105: }
3106: foreach my $hostid (sort(keys(%servers))) {
3107: $result.= '<option value="'.$hostid.'">'.
3108: $hostid.' '.$servers{$hostid}."</option>\n";
3109: }
3110: $result .= '</select>'."\n";
3111: } elsif ($numlib == 1) {
3112: my $hostid;
3113: foreach my $item (keys(%servers)) {
3114: $hostid = $item;
3115: }
3116: $result .= '<input type="hidden" name="'.$name.'" value="'.
3117: $hostid.'" />';
3118: if (!$hide) {
3119: $result .= $hostid.' '.$servers{$hostid};
3120: }
3121: $result .= "\n";
3122: } elsif ($default) {
3123: $result .= '<input type="hidden" name="'.$name.
3124: '" value="default" />';
3125: if (!$hide) {
3126: $result .= &mt('default');
3127: }
3128: $result .= "\n";
1.33 matthew 3129: }
1.586 raeburn 3130: return ($result,$numlib);
1.33 matthew 3131: }
1.112 bowersj2 3132:
3133: =pod
3134:
1.534 albertel 3135: =back
3136:
1.112 bowersj2 3137: =cut
1.87 matthew 3138:
3139: ###############################################################
1.112 bowersj2 3140: ## Decoding User Agent ##
1.87 matthew 3141: ###############################################################
3142:
3143: =pod
3144:
1.112 bowersj2 3145: =head1 Decoding the User Agent
3146:
3147: =over 4
3148:
3149: =item * &decode_user_agent()
1.87 matthew 3150:
3151: Inputs: $r
3152:
3153: Outputs:
3154:
3155: =over 4
3156:
1.112 bowersj2 3157: =item * $httpbrowser
1.87 matthew 3158:
1.112 bowersj2 3159: =item * $clientbrowser
1.87 matthew 3160:
1.112 bowersj2 3161: =item * $clientversion
1.87 matthew 3162:
1.112 bowersj2 3163: =item * $clientmathml
1.87 matthew 3164:
1.112 bowersj2 3165: =item * $clientunicode
1.87 matthew 3166:
1.112 bowersj2 3167: =item * $clientos
1.87 matthew 3168:
1.1137 raeburn 3169: =item * $clientmobile
3170:
1.1141 raeburn 3171: =item * $clientinfo
3172:
1.1194 raeburn 3173: =item * $clientosversion
3174:
1.87 matthew 3175: =back
3176:
1.157 matthew 3177: =back
3178:
1.87 matthew 3179: =cut
3180:
3181: ###############################################################
3182: ###############################################################
3183: sub decode_user_agent {
1.247 albertel 3184: my ($r)=@_;
1.87 matthew 3185: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3186: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3187: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3188: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3189: my $clientbrowser='unknown';
3190: my $clientversion='0';
3191: my $clientmathml='';
3192: my $clientunicode='0';
1.1137 raeburn 3193: my $clientmobile=0;
1.1194 raeburn 3194: my $clientosversion='';
1.87 matthew 3195: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3196: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3197: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3198: $clientbrowser=$bname;
3199: $httpbrowser=~/$vreg/i;
3200: $clientversion=$1;
3201: $clientmathml=($clientversion>=$minv);
3202: $clientunicode=($clientversion>=$univ);
3203: }
3204: }
3205: my $clientos='unknown';
1.1141 raeburn 3206: my $clientinfo;
1.87 matthew 3207: if (($httpbrowser=~/linux/i) ||
3208: ($httpbrowser=~/unix/i) ||
3209: ($httpbrowser=~/ux/i) ||
3210: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3211: if (($httpbrowser=~/vax/i) ||
3212: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3213: if ($httpbrowser=~/next/i) { $clientos='next'; }
3214: if (($httpbrowser=~/mac/i) ||
3215: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3216: if ($httpbrowser=~/win/i) {
3217: $clientos='win';
3218: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3219: $clientosversion = $1;
3220: }
3221: }
1.87 matthew 3222: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3223: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3224: $clientmobile=lc($1);
3225: }
1.1141 raeburn 3226: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3227: $clientinfo = 'firefox-'.$1;
3228: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3229: $clientinfo = 'chromeframe-'.$1;
3230: }
1.87 matthew 3231: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3232: $clientunicode,$clientos,$clientmobile,$clientinfo,
3233: $clientosversion);
1.87 matthew 3234: }
3235:
1.32 matthew 3236: ###############################################################
3237: ## Authentication changing form generation subroutines ##
3238: ###############################################################
3239: ##
3240: ## All of the authform_xxxxxxx subroutines take their inputs in a
3241: ## hash, and have reasonable default values.
3242: ##
3243: ## formname = the name given in the <form> tag.
1.35 matthew 3244: #-------------------------------------------
3245:
1.45 matthew 3246: =pod
3247:
1.112 bowersj2 3248: =head1 Authentication Routines
3249:
3250: =over 4
3251:
1.648 raeburn 3252: =item * &authform_xxxxxx()
1.35 matthew 3253:
3254: The authform_xxxxxx subroutines provide javascript and html forms which
3255: handle some of the conveniences required for authentication forms.
3256: This is not an optimal method, but it works.
3257:
3258: =over 4
3259:
1.112 bowersj2 3260: =item * authform_header
1.35 matthew 3261:
1.112 bowersj2 3262: =item * authform_authorwarning
1.35 matthew 3263:
1.112 bowersj2 3264: =item * authform_nochange
1.35 matthew 3265:
1.112 bowersj2 3266: =item * authform_kerberos
1.35 matthew 3267:
1.112 bowersj2 3268: =item * authform_internal
1.35 matthew 3269:
1.112 bowersj2 3270: =item * authform_filesystem
1.35 matthew 3271:
1.1310 raeburn 3272: =item * authform_lti
3273:
1.35 matthew 3274: =back
3275:
1.648 raeburn 3276: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3277:
1.35 matthew 3278: =cut
3279:
3280: #-------------------------------------------
1.32 matthew 3281: sub authform_header{
3282: my %in = (
3283: formname => 'cu',
1.80 albertel 3284: kerb_def_dom => '',
1.32 matthew 3285: @_,
3286: );
3287: $in{'formname'} = 'document.' . $in{'formname'};
3288: my $result='';
1.80 albertel 3289:
3290: #---------------------------------------------- Code for upper case translation
3291: my $Javascript_toUpperCase;
3292: unless ($in{kerb_def_dom}) {
3293: $Javascript_toUpperCase =<<"END";
3294: switch (choice) {
3295: case 'krb': currentform.elements[choicearg].value =
3296: currentform.elements[choicearg].value.toUpperCase();
3297: break;
3298: default:
3299: }
3300: END
3301: } else {
3302: $Javascript_toUpperCase = "";
3303: }
3304:
1.165 raeburn 3305: my $radioval = "'nochange'";
1.591 raeburn 3306: if (defined($in{'curr_authtype'})) {
3307: if ($in{'curr_authtype'} ne '') {
3308: $radioval = "'".$in{'curr_authtype'}."arg'";
3309: }
1.174 matthew 3310: }
1.165 raeburn 3311: my $argfield = 'null';
1.591 raeburn 3312: if (defined($in{'mode'})) {
1.165 raeburn 3313: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3314: if (defined($in{'curr_autharg'})) {
3315: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3316: $argfield = "'$in{'curr_autharg'}'";
3317: }
3318: }
3319: }
3320: }
3321:
1.32 matthew 3322: $result.=<<"END";
3323: var current = new Object();
1.165 raeburn 3324: current.radiovalue = $radioval;
3325: current.argfield = $argfield;
1.32 matthew 3326:
3327: function changed_radio(choice,currentform) {
3328: var choicearg = choice + 'arg';
3329: // If a radio button in changed, we need to change the argfield
3330: if (current.radiovalue != choice) {
3331: current.radiovalue = choice;
3332: if (current.argfield != null) {
3333: currentform.elements[current.argfield].value = '';
3334: }
3335: if (choice == 'nochange') {
3336: current.argfield = null;
3337: } else {
3338: current.argfield = choicearg;
3339: switch(choice) {
3340: case 'krb':
3341: currentform.elements[current.argfield].value =
3342: "$in{'kerb_def_dom'}";
3343: break;
3344: default:
3345: break;
3346: }
3347: }
3348: }
3349: return;
3350: }
1.22 www 3351:
1.32 matthew 3352: function changed_text(choice,currentform) {
3353: var choicearg = choice + 'arg';
3354: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3355: $Javascript_toUpperCase
1.32 matthew 3356: // clear old field
3357: if ((current.argfield != choicearg) && (current.argfield != null)) {
3358: currentform.elements[current.argfield].value = '';
3359: }
3360: current.argfield = choicearg;
3361: }
3362: set_auth_radio_buttons(choice,currentform);
3363: return;
1.20 www 3364: }
1.32 matthew 3365:
3366: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3367: var numauthchoices = currentform.login.length;
3368: if (typeof numauthchoices == "undefined") {
3369: return;
3370: }
1.32 matthew 3371: var i=0;
1.986 raeburn 3372: while (i < numauthchoices) {
1.32 matthew 3373: if (currentform.login[i].value == newvalue) { break; }
3374: i++;
3375: }
1.986 raeburn 3376: if (i == numauthchoices) {
1.32 matthew 3377: return;
3378: }
3379: current.radiovalue = newvalue;
3380: currentform.login[i].checked = true;
3381: return;
3382: }
3383: END
3384: return $result;
3385: }
3386:
1.1106 raeburn 3387: sub authform_authorwarning {
1.32 matthew 3388: my $result='';
1.144 matthew 3389: $result='<i>'.
3390: &mt('As a general rule, only authors or co-authors should be '.
3391: 'filesystem authenticated '.
3392: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3393: return $result;
3394: }
3395:
1.1106 raeburn 3396: sub authform_nochange {
1.32 matthew 3397: my %in = (
3398: formname => 'document.cu',
3399: kerb_def_dom => 'MSU.EDU',
3400: @_,
3401: );
1.1106 raeburn 3402: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3403: my $result;
1.1104 raeburn 3404: if (!$authnum) {
1.1105 raeburn 3405: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3406: } else {
3407: $result = '<label>'.&mt('[_1] Do not change login data',
3408: '<input type="radio" name="login" value="nochange" '.
3409: 'checked="checked" onclick="'.
1.281 albertel 3410: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3411: '</label>';
1.586 raeburn 3412: }
1.32 matthew 3413: return $result;
3414: }
3415:
1.591 raeburn 3416: sub authform_kerberos {
1.32 matthew 3417: my %in = (
3418: formname => 'document.cu',
3419: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3420: kerb_def_auth => 'krb4',
1.32 matthew 3421: @_,
3422: );
1.586 raeburn 3423: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3424: $autharg,$jscall,$disabled);
1.1106 raeburn 3425: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3426: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3427: $check5 = ' checked="checked"';
1.80 albertel 3428: } else {
1.772 bisitz 3429: $check4 = ' checked="checked"';
1.80 albertel 3430: }
1.1259 raeburn 3431: if ($in{'readonly'}) {
3432: $disabled = ' disabled="disabled"';
3433: }
1.165 raeburn 3434: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3435: if (defined($in{'curr_authtype'})) {
3436: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3437: $krbcheck = ' checked="checked"';
1.623 raeburn 3438: if (defined($in{'mode'})) {
3439: if ($in{'mode'} eq 'modifyuser') {
3440: $krbcheck = '';
3441: }
3442: }
1.591 raeburn 3443: if (defined($in{'curr_kerb_ver'})) {
3444: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3445: $check5 = ' checked="checked"';
1.591 raeburn 3446: $check4 = '';
3447: } else {
1.772 bisitz 3448: $check4 = ' checked="checked"';
1.591 raeburn 3449: $check5 = '';
3450: }
1.586 raeburn 3451: }
1.591 raeburn 3452: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3453: $krbarg = $in{'curr_autharg'};
3454: }
1.586 raeburn 3455: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3456: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3457: $result =
3458: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3459: $in{'curr_autharg'},$krbver);
3460: } else {
3461: $result =
3462: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3463: }
3464: return $result;
3465: }
3466: }
3467: } else {
3468: if ($authnum == 1) {
1.784 bisitz 3469: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3470: }
3471: }
1.586 raeburn 3472: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3473: return;
1.587 raeburn 3474: } elsif ($authtype eq '') {
1.591 raeburn 3475: if (defined($in{'mode'})) {
1.587 raeburn 3476: if ($in{'mode'} eq 'modifycourse') {
3477: if ($authnum == 1) {
1.1259 raeburn 3478: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3479: }
3480: }
3481: }
1.586 raeburn 3482: }
3483: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3484: if ($authtype eq '') {
3485: $authtype = '<input type="radio" name="login" value="krb" '.
3486: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3487: $krbcheck.$disabled.' />';
1.586 raeburn 3488: }
3489: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3490: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3491: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3492: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3493: $in{'curr_authtype'} eq 'krb4')) {
3494: $result .= &mt
1.144 matthew 3495: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3496: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3497: '<label>'.$authtype,
1.281 albertel 3498: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3499: 'value="'.$krbarg.'" '.
1.1259 raeburn 3500: 'onchange="'.$jscall.'"'.$disabled.' />',
3501: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3502: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3503: '</label>');
1.586 raeburn 3504: } elsif ($can_assign{'krb4'}) {
3505: $result .= &mt
3506: ('[_1] Kerberos authenticated with domain [_2] '.
3507: '[_3] Version 4 [_4]',
3508: '<label>'.$authtype,
3509: '</label><input type="text" size="10" name="krbarg" '.
3510: 'value="'.$krbarg.'" '.
1.1259 raeburn 3511: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3512: '<label><input type="hidden" name="krbver" value="4" />',
3513: '</label>');
3514: } elsif ($can_assign{'krb5'}) {
3515: $result .= &mt
3516: ('[_1] Kerberos authenticated with domain [_2] '.
3517: '[_3] Version 5 [_4]',
3518: '<label>'.$authtype,
3519: '</label><input type="text" size="10" name="krbarg" '.
3520: 'value="'.$krbarg.'" '.
1.1259 raeburn 3521: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3522: '<label><input type="hidden" name="krbver" value="5" />',
3523: '</label>');
3524: }
1.32 matthew 3525: return $result;
3526: }
3527:
1.1106 raeburn 3528: sub authform_internal {
1.586 raeburn 3529: my %in = (
1.32 matthew 3530: formname => 'document.cu',
3531: kerb_def_dom => 'MSU.EDU',
3532: @_,
3533: );
1.1259 raeburn 3534: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3535: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3536: if ($in{'readonly'}) {
3537: $disabled = ' disabled="disabled"';
3538: }
1.591 raeburn 3539: if (defined($in{'curr_authtype'})) {
3540: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3541: if ($can_assign{'int'}) {
1.772 bisitz 3542: $intcheck = 'checked="checked" ';
1.623 raeburn 3543: if (defined($in{'mode'})) {
3544: if ($in{'mode'} eq 'modifyuser') {
3545: $intcheck = '';
3546: }
3547: }
1.591 raeburn 3548: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3549: $intarg = $in{'curr_autharg'};
3550: }
3551: } else {
3552: $result = &mt('Currently internally authenticated.');
3553: return $result;
1.165 raeburn 3554: }
3555: }
1.586 raeburn 3556: } else {
3557: if ($authnum == 1) {
1.784 bisitz 3558: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3559: }
3560: }
3561: if (!$can_assign{'int'}) {
3562: return;
1.587 raeburn 3563: } elsif ($authtype eq '') {
1.591 raeburn 3564: if (defined($in{'mode'})) {
1.587 raeburn 3565: if ($in{'mode'} eq 'modifycourse') {
3566: if ($authnum == 1) {
1.1259 raeburn 3567: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3568: }
3569: }
3570: }
1.165 raeburn 3571: }
1.586 raeburn 3572: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3573: if ($authtype eq '') {
3574: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3575: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3576: }
1.605 bisitz 3577: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3578: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3579: $result = &mt
1.144 matthew 3580: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3581: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3582: $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 3583: return $result;
3584: }
3585:
1.1104 raeburn 3586: sub authform_local {
1.32 matthew 3587: my %in = (
3588: formname => 'document.cu',
3589: kerb_def_dom => 'MSU.EDU',
3590: @_,
3591: );
1.1259 raeburn 3592: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3593: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3594: if ($in{'readonly'}) {
3595: $disabled = ' disabled="disabled"';
3596: }
1.591 raeburn 3597: if (defined($in{'curr_authtype'})) {
3598: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3599: if ($can_assign{'loc'}) {
1.772 bisitz 3600: $loccheck = 'checked="checked" ';
1.623 raeburn 3601: if (defined($in{'mode'})) {
3602: if ($in{'mode'} eq 'modifyuser') {
3603: $loccheck = '';
3604: }
3605: }
1.591 raeburn 3606: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3607: $locarg = $in{'curr_autharg'};
3608: }
3609: } else {
3610: $result = &mt('Currently using local (institutional) authentication.');
3611: return $result;
1.165 raeburn 3612: }
3613: }
1.586 raeburn 3614: } else {
3615: if ($authnum == 1) {
1.784 bisitz 3616: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3617: }
3618: }
3619: if (!$can_assign{'loc'}) {
3620: return;
1.587 raeburn 3621: } elsif ($authtype eq '') {
1.591 raeburn 3622: if (defined($in{'mode'})) {
1.587 raeburn 3623: if ($in{'mode'} eq 'modifycourse') {
3624: if ($authnum == 1) {
1.1259 raeburn 3625: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3626: }
3627: }
3628: }
1.165 raeburn 3629: }
1.586 raeburn 3630: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3631: if ($authtype eq '') {
3632: $authtype = '<input type="radio" name="login" value="loc" '.
3633: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3634: $jscall.'"'.$disabled.' />';
1.586 raeburn 3635: }
3636: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3637: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3638: $result = &mt('[_1] Local Authentication with argument [_2]',
3639: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3640: return $result;
3641: }
3642:
1.1106 raeburn 3643: sub authform_filesystem {
1.32 matthew 3644: my %in = (
3645: formname => 'document.cu',
3646: kerb_def_dom => 'MSU.EDU',
3647: @_,
3648: );
1.1259 raeburn 3649: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3650: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3651: if ($in{'readonly'}) {
3652: $disabled = ' disabled="disabled"';
3653: }
1.591 raeburn 3654: if (defined($in{'curr_authtype'})) {
3655: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3656: if ($can_assign{'fsys'}) {
1.772 bisitz 3657: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3658: if (defined($in{'mode'})) {
3659: if ($in{'mode'} eq 'modifyuser') {
3660: $fsyscheck = '';
3661: }
3662: }
1.586 raeburn 3663: } else {
3664: $result = &mt('Currently Filesystem Authenticated.');
3665: return $result;
1.1259 raeburn 3666: }
1.586 raeburn 3667: }
3668: } else {
3669: if ($authnum == 1) {
1.784 bisitz 3670: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3671: }
3672: }
3673: if (!$can_assign{'fsys'}) {
3674: return;
1.587 raeburn 3675: } elsif ($authtype eq '') {
1.591 raeburn 3676: if (defined($in{'mode'})) {
1.587 raeburn 3677: if ($in{'mode'} eq 'modifycourse') {
3678: if ($authnum == 1) {
1.1259 raeburn 3679: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3680: }
3681: }
3682: }
1.586 raeburn 3683: }
3684: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3685: if ($authtype eq '') {
3686: $authtype = '<input type="radio" name="login" value="fsys" '.
3687: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3688: $jscall.'"'.$disabled.' />';
1.586 raeburn 3689: }
1.1310 raeburn 3690: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3691: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3692: $result = &mt
1.144 matthew 3693: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3694: '<label>'.$authtype,'</label>'.$autharg);
3695: return $result;
3696: }
3697:
3698: sub authform_lti {
3699: my %in = (
3700: formname => 'document.cu',
3701: kerb_def_dom => 'MSU.EDU',
3702: @_,
3703: );
3704: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3705: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3706: if ($in{'readonly'}) {
3707: $disabled = ' disabled="disabled"';
3708: }
3709: if (defined($in{'curr_authtype'})) {
3710: if ($in{'curr_authtype'} eq 'lti') {
3711: if ($can_assign{'lti'}) {
3712: $lticheck = 'checked="checked" ';
3713: if (defined($in{'mode'})) {
3714: if ($in{'mode'} eq 'modifyuser') {
3715: $lticheck = '';
3716: }
3717: }
3718: } else {
3719: $result = &mt('Currently LTI Authenticated.');
3720: return $result;
3721: }
3722: }
3723: } else {
3724: if ($authnum == 1) {
3725: $authtype = '<input type="hidden" name="login" value="lti" />';
3726: }
3727: }
3728: if (!$can_assign{'lti'}) {
3729: return;
3730: } elsif ($authtype eq '') {
3731: if (defined($in{'mode'})) {
3732: if ($in{'mode'} eq 'modifycourse') {
3733: if ($authnum == 1) {
3734: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3735: }
3736: }
3737: }
3738: }
3739: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3740: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3741: $authtype = '<input type="radio" name="login" value="lti" '.
3742: $lticheck.' onchange="'.$jscall.'" onclick="'.
3743: $jscall.'"'.$disabled.' />';
3744: }
3745: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3746: if ($authtype) {
3747: $result = &mt('[_1] LTI Authenticated',
3748: '<label>'.$authtype.'</label>'.$autharg);
3749: } else {
3750: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3751: $autharg;
3752: }
1.32 matthew 3753: return $result;
3754: }
3755:
1.586 raeburn 3756: sub get_assignable_auth {
3757: my ($dom) = @_;
3758: if ($dom eq '') {
3759: $dom = $env{'request.role.domain'};
3760: }
3761: my %can_assign = (
3762: krb4 => 1,
3763: krb5 => 1,
3764: int => 1,
3765: loc => 1,
1.1310 raeburn 3766: lti => 1,
1.586 raeburn 3767: );
3768: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3769: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3770: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3771: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3772: my $context;
3773: if ($env{'request.role'} =~ /^au/) {
3774: $context = 'author';
1.1259 raeburn 3775: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3776: $context = 'domain';
3777: } elsif ($env{'request.course.id'}) {
3778: $context = 'course';
3779: }
3780: if ($context) {
3781: if (ref($authhash->{$context}) eq 'HASH') {
3782: %can_assign = %{$authhash->{$context}};
3783: }
3784: }
3785: }
3786: }
3787: my $authnum = 0;
3788: foreach my $key (keys(%can_assign)) {
3789: if ($can_assign{$key}) {
3790: $authnum ++;
3791: }
3792: }
3793: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3794: $authnum --;
3795: }
3796: return ($authnum,%can_assign);
3797: }
3798:
1.1331 raeburn 3799: sub check_passwd_rules {
3800: my ($domain,$plainpass) = @_;
3801: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3802: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3803: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3804: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3805: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3806: if ($passwdconf{'min'} > $min) {
3807: $min = $passwdconf{'min'};
3808: }
1.1331 raeburn 3809: }
3810: if ($passwdconf{'max'} =~ /^\d+$/) {
3811: $max = $passwdconf{'max'};
3812: }
3813: @chars = @{$passwdconf{'chars'}};
3814: }
3815: if (($min) && (length($plainpass) < $min)) {
3816: push(@brokerule,'min');
3817: }
3818: if (($max) && (length($plainpass) > $max)) {
3819: push(@brokerule,'max');
3820: }
3821: if (@chars) {
3822: my %rules;
3823: map { $rules{$_} = 1; } @chars;
3824: if ($rules{'uc'}) {
3825: unless ($plainpass =~ /[A-Z]/) {
3826: push(@brokerule,'uc');
3827: }
3828: }
3829: if ($rules{'lc'}) {
1.1332 raeburn 3830: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3831: push(@brokerule,'lc');
3832: }
3833: }
3834: if ($rules{'num'}) {
3835: unless ($plainpass =~ /\d/) {
3836: push(@brokerule,'num');
3837: }
3838: }
3839: if ($rules{'spec'}) {
3840: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3841: push(@brokerule,'spec');
3842: }
3843: }
3844: }
3845: if (@brokerule) {
3846: my %rulenames = &Apache::lonlocal::texthash(
3847: uc => 'At least one upper case letter',
3848: lc => 'At least one lower case letter',
3849: num => 'At least one number',
3850: spec => 'At least one non-alphanumeric',
3851: );
3852: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3853: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3854: $rulenames{'num'} .= ': 0123456789';
3855: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3856: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3857: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3858: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3859: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3860: if (grep(/^$rule$/,@brokerule)) {
3861: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3862: }
3863: }
3864: $warning .= '</ul>';
3865: }
1.1332 raeburn 3866: if (wantarray) {
3867: return @brokerule;
3868: }
1.1331 raeburn 3869: return $warning;
3870: }
3871:
1.1376 raeburn 3872: sub passwd_validation_js {
1.1377 raeburn 3873: my ($currpasswdval,$domain,$context,$id) = @_;
3874: my (%passwdconf,$alertmsg);
3875: if ($context eq 'linkprot') {
3876: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3877: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3878: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3879: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3880: }
3881: }
3882: if ($id eq 'add') {
3883: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3884: } elsif ($id =~ /^\d+$/) {
3885: my $pos = $id+1;
3886: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3887: } else {
3888: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3889: }
3890: } else {
3891: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3892: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3893: }
1.1376 raeburn 3894: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3895: $numrules = 0;
3896: $min = $Apache::lonnet::passwdmin;
3897: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3898: if ($passwdconf{'min'} =~ /^\d+$/) {
3899: if ($passwdconf{'min'} > $min) {
3900: $min = $passwdconf{'min'};
3901: }
3902: }
3903: if ($passwdconf{'max'} =~ /^\d+$/) {
3904: $max = $passwdconf{'max'};
3905: $numrules ++;
3906: }
3907: @chars = @{$passwdconf{'chars'}};
3908: if (@chars) {
3909: $numrules ++;
3910: }
3911: }
3912: if ($min > 0) {
3913: $numrules ++;
3914: }
3915: if (($min > 0) || ($max ne '') || (@chars > 0)) {
3916: if ($min) {
3917: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3918: }
3919: if ($max) {
3920: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3921: }
3922: my (@charalerts,@charrules);
3923: if (@chars) {
3924: if (grep(/^uc$/,@chars)) {
3925: push(@charalerts,&mt('contain at least one upper case letter'));
3926: push(@charrules,'uc');
3927: }
3928: if (grep(/^lc$/,@chars)) {
3929: push(@charalerts,&mt('contain at least one lower case letter'));
3930: push(@charrules,'lc');
3931: }
3932: if (grep(/^num$/,@chars)) {
3933: push(@charalerts,&mt('contain at least one number'));
3934: push(@charrules,'num');
3935: }
3936: if (grep(/^spec$/,@chars)) {
3937: push(@charalerts,&mt('contain at least one non-alphanumeric'));
3938: push(@charrules,'spec');
3939: }
3940: }
3941: $intargjs = qq| var rulesmsg = '';\n|.
3942: qq| var currpwval = $currpasswdval;\n|;
3943: if ($min) {
3944: $intargjs .= qq|
3945: if (currpwval.length < $min) {
3946: rulesmsg += ' - $alert{min}';
3947: }
3948: |;
3949: }
3950: if ($max) {
3951: $intargjs .= qq|
3952: if (currpwval.length > $max) {
3953: rulesmsg += ' - $alert{max}';
3954: }
3955: |;
3956: }
3957: if (@chars > 0) {
3958: my $charrulestr = '"'.join('","',@charrules).'"';
3959: my $charalertstr = '"'.join('","',@charalerts).'"';
3960: $intargjs .= qq| var brokerules = new Array();\n|.
3961: qq| var charrules = new Array($charrulestr);\n|.
3962: qq| var charalerts = new Array($charalertstr);\n|;
3963: my %rules;
3964: map { $rules{$_} = 1; } @chars;
3965: if ($rules{'uc'}) {
3966: $intargjs .= qq|
3967: var ucRegExp = /[A-Z]/;
3968: if (!ucRegExp.test(currpwval)) {
3969: brokerules.push('uc');
3970: }
3971: |;
3972: }
3973: if ($rules{'lc'}) {
3974: $intargjs .= qq|
3975: var lcRegExp = /[a-z]/;
3976: if (!lcRegExp.test(currpwval)) {
3977: brokerules.push('lc');
3978: }
3979: |;
3980: }
3981: if ($rules{'num'}) {
3982: $intargjs .= qq|
3983: var numRegExp = /[0-9]/;
3984: if (!numRegExp.test(currpwval)) {
3985: brokerules.push('num');
3986: }
3987: |;
3988: }
3989: if ($rules{'spec'}) {
3990: $intargjs .= q|
3991: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3992: if (!specRegExp.test(currpwval)) {
3993: brokerules.push('spec');
3994: }
3995: |;
3996: }
3997: $intargjs .= qq|
3998: if (brokerules.length > 0) {
3999: for (var i=0; i<brokerules.length; i++) {
4000: for (var j=0; j<charrules.length; j++) {
4001: if (brokerules[i] == charrules[j]) {
4002: rulesmsg += ' - '+charalerts[j]+'\\n';
4003: break;
4004: }
4005: }
4006: }
4007: }
4008: |;
4009: }
4010: $intargjs .= qq|
4011: if (rulesmsg != '') {
4012: rulesmsg = '$alertmsg'+rulesmsg;
4013: alert(rulesmsg);
4014: return false;
4015: }
4016: |;
4017: }
4018: return ($numrules,$intargjs);
4019: }
4020:
1.80 albertel 4021: ###############################################################
4022: ## Get Kerberos Defaults for Domain ##
4023: ###############################################################
4024: ##
4025: ## Returns default kerberos version and an associated argument
4026: ## as listed in file domain.tab. If not listed, provides
4027: ## appropriate default domain and kerberos version.
4028: ##
4029: #-------------------------------------------
4030:
4031: =pod
4032:
1.648 raeburn 4033: =item * &get_kerberos_defaults()
1.80 albertel 4034:
4035: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 4036: version and domain. If not found, it defaults to version 4 and the
4037: domain of the server.
1.80 albertel 4038:
1.648 raeburn 4039: =over 4
4040:
1.80 albertel 4041: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
4042:
1.648 raeburn 4043: =back
4044:
4045: =back
4046:
1.80 albertel 4047: =cut
4048:
4049: #-------------------------------------------
4050: sub get_kerberos_defaults {
4051: my $domain=shift;
1.641 raeburn 4052: my ($krbdef,$krbdefdom);
4053: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
4054: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
4055: $krbdef = $domdefaults{'auth_def'};
4056: $krbdefdom = $domdefaults{'auth_arg_def'};
4057: } else {
1.80 albertel 4058: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
4059: my $krbdefdom=$1;
4060: $krbdefdom=~tr/a-z/A-Z/;
4061: $krbdef = "krb4";
4062: }
4063: return ($krbdef,$krbdefdom);
4064: }
1.112 bowersj2 4065:
1.32 matthew 4066:
1.46 matthew 4067: ###############################################################
4068: ## Thesaurus Functions ##
4069: ###############################################################
1.20 www 4070:
1.46 matthew 4071: =pod
1.20 www 4072:
1.112 bowersj2 4073: =head1 Thesaurus Functions
4074:
4075: =over 4
4076:
1.648 raeburn 4077: =item * &initialize_keywords()
1.46 matthew 4078:
4079: Initializes the package variable %Keywords if it is empty. Uses the
4080: package variable $thesaurus_db_file.
4081:
4082: =cut
4083:
4084: ###################################################
4085:
4086: sub initialize_keywords {
4087: return 1 if (scalar keys(%Keywords));
4088: # If we are here, %Keywords is empty, so fill it up
4089: # Make sure the file we need exists...
4090: if (! -e $thesaurus_db_file) {
4091: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
4092: " failed because it does not exist");
4093: return 0;
4094: }
4095: # Set up the hash as a database
4096: my %thesaurus_db;
4097: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4098: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4099: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
4100: $thesaurus_db_file);
4101: return 0;
4102: }
4103: # Get the average number of appearances of a word.
4104: my $avecount = $thesaurus_db{'average.count'};
4105: # Put keywords (those that appear > average) into %Keywords
4106: while (my ($word,$data)=each (%thesaurus_db)) {
4107: my ($count,undef) = split /:/,$data;
4108: $Keywords{$word}++ if ($count > $avecount);
4109: }
4110: untie %thesaurus_db;
4111: # Remove special values from %Keywords.
1.356 albertel 4112: foreach my $value ('total.count','average.count') {
4113: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4114: }
1.46 matthew 4115: return 1;
4116: }
4117:
4118: ###################################################
4119:
4120: =pod
4121:
1.648 raeburn 4122: =item * &keyword($word)
1.46 matthew 4123:
4124: Returns true if $word is a keyword. A keyword is a word that appears more
4125: than the average number of times in the thesaurus database. Calls
4126: &initialize_keywords
4127:
4128: =cut
4129:
4130: ###################################################
1.20 www 4131:
4132: sub keyword {
1.46 matthew 4133: return if (!&initialize_keywords());
4134: my $word=lc(shift());
4135: $word=~s/\W//g;
4136: return exists($Keywords{$word});
1.20 www 4137: }
1.46 matthew 4138:
4139: ###############################################################
4140:
4141: =pod
1.20 www 4142:
1.648 raeburn 4143: =item * &get_related_words()
1.46 matthew 4144:
1.160 matthew 4145: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4146: an array of words. If the keyword is not in the thesaurus, an empty array
4147: will be returned. The order of the words returned is determined by the
4148: database which holds them.
4149:
4150: Uses global $thesaurus_db_file.
4151:
1.1057 foxr 4152:
1.46 matthew 4153: =cut
4154:
4155: ###############################################################
4156: sub get_related_words {
4157: my $keyword = shift;
4158: my %thesaurus_db;
4159: if (! -e $thesaurus_db_file) {
4160: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4161: "failed because the file does not exist");
4162: return ();
4163: }
4164: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4165: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4166: return ();
4167: }
4168: my @Words=();
1.429 www 4169: my $count=0;
1.46 matthew 4170: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4171: # The first element is the number of times
4172: # the word appears. We do not need it now.
1.429 www 4173: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4174: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4175: my $threshold=$mostfrequentcount/10;
4176: foreach my $possibleword (@RelatedWords) {
4177: my ($word,$wordcount)=split(/\,/,$possibleword);
4178: if ($wordcount>$threshold) {
4179: push(@Words,$word);
4180: $count++;
4181: if ($count>10) { last; }
4182: }
1.20 www 4183: }
4184: }
1.46 matthew 4185: untie %thesaurus_db;
4186: return @Words;
1.14 harris41 4187: }
1.1090 foxr 4188: ###############################################################
4189: #
4190: # Spell checking
4191: #
4192:
4193: =pod
4194:
1.1142 raeburn 4195: =back
4196:
1.1090 foxr 4197: =head1 Spell checking
4198:
4199: =over 4
4200:
4201: =item * &check_spelling($wordlist $language)
4202:
4203: Takes a string containing words and feeds it to an external
4204: spellcheck program via a pipeline. Returns a string containing
4205: them mis-spelled words.
4206:
4207: Parameters:
4208:
4209: =over 4
4210:
4211: =item - $wordlist
4212:
4213: String that will be fed into the spellcheck program.
4214:
4215: =item - $language
4216:
4217: Language string that specifies the language for which the spell
4218: check will be performed.
4219:
4220: =back
4221:
4222: =back
4223:
4224: Note: This sub assumes that aspell is installed.
4225:
4226:
4227: =cut
4228:
1.46 matthew 4229:
1.1090 foxr 4230: sub check_spelling {
4231: my ($wordlist, $language) = @_;
1.1091 foxr 4232: my @misspellings;
4233:
4234: # Generate the speller and set the langauge.
4235: # if explicitly selected:
1.1090 foxr 4236:
1.1091 foxr 4237: my $speller = Text::Aspell->new;
1.1090 foxr 4238: if ($language) {
1.1091 foxr 4239: $speller->set_option('lang', $language);
1.1090 foxr 4240: }
4241:
1.1091 foxr 4242: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4243:
1.1091 foxr 4244: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4245:
1.1091 foxr 4246: foreach my $word (@words) {
4247: if(! $speller->check($word)) {
4248: push(@misspellings, $word);
1.1090 foxr 4249: }
4250: }
1.1091 foxr 4251: return join(' ', @misspellings);
4252:
1.1090 foxr 4253: }
4254:
1.61 www 4255: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4256: =pod
4257:
1.112 bowersj2 4258: =head1 User Name Functions
4259:
4260: =over 4
4261:
1.648 raeburn 4262: =item * &plainname($uname,$udom,$first)
1.81 albertel 4263:
1.112 bowersj2 4264: Takes a users logon name and returns it as a string in
1.226 albertel 4265: "first middle last generation" form
4266: if $first is set to 'lastname' then it returns it as
4267: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4268:
4269: =cut
1.61 www 4270:
1.295 www 4271:
1.81 albertel 4272: ###############################################################
1.61 www 4273: sub plainname {
1.226 albertel 4274: my ($uname,$udom,$first)=@_;
1.537 albertel 4275: return if (!defined($uname) || !defined($udom));
1.295 www 4276: my %names=&getnames($uname,$udom);
1.226 albertel 4277: my $name=&Apache::lonnet::format_name($names{'firstname'},
4278: $names{'middlename'},
4279: $names{'lastname'},
4280: $names{'generation'},$first);
4281: $name=~s/^\s+//;
1.62 www 4282: $name=~s/\s+$//;
4283: $name=~s/\s+/ /g;
1.353 albertel 4284: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4285: return $name;
1.61 www 4286: }
1.66 www 4287:
4288: # -------------------------------------------------------------------- Nickname
1.81 albertel 4289: =pod
4290:
1.648 raeburn 4291: =item * &nickname($uname,$udom)
1.81 albertel 4292:
4293: Gets a users name and returns it as a string as
4294:
4295: ""nickname""
1.66 www 4296:
1.81 albertel 4297: if the user has a nickname or
4298:
4299: "first middle last generation"
4300:
4301: if the user does not
4302:
4303: =cut
1.66 www 4304:
4305: sub nickname {
4306: my ($uname,$udom)=@_;
1.537 albertel 4307: return if (!defined($uname) || !defined($udom));
1.295 www 4308: my %names=&getnames($uname,$udom);
1.68 albertel 4309: my $name=$names{'nickname'};
1.66 www 4310: if ($name) {
4311: $name='"'.$name.'"';
4312: } else {
4313: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4314: $names{'lastname'}.' '.$names{'generation'};
4315: $name=~s/\s+$//;
4316: $name=~s/\s+/ /g;
4317: }
4318: return $name;
4319: }
4320:
1.295 www 4321: sub getnames {
4322: my ($uname,$udom)=@_;
1.537 albertel 4323: return if (!defined($uname) || !defined($udom));
1.433 albertel 4324: if ($udom eq 'public' && $uname eq 'public') {
4325: return ('lastname' => &mt('Public'));
4326: }
1.295 www 4327: my $id=$uname.':'.$udom;
4328: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4329: if ($cached) {
4330: return %{$names};
4331: } else {
4332: my %loadnames=&Apache::lonnet::get('environment',
4333: ['firstname','middlename','lastname','generation','nickname'],
4334: $udom,$uname);
4335: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4336: return %loadnames;
4337: }
4338: }
1.61 www 4339:
1.542 raeburn 4340: # -------------------------------------------------------------------- getemails
1.648 raeburn 4341:
1.542 raeburn 4342: =pod
4343:
1.648 raeburn 4344: =item * &getemails($uname,$udom)
1.542 raeburn 4345:
4346: Gets a user's email information and returns it as a hash with keys:
4347: notification, critnotification, permanentemail
4348:
4349: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4350: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4351:
1.648 raeburn 4352:
1.542 raeburn 4353: =cut
4354:
1.648 raeburn 4355:
1.466 albertel 4356: sub getemails {
4357: my ($uname,$udom)=@_;
4358: if ($udom eq 'public' && $uname eq 'public') {
4359: return;
4360: }
1.467 www 4361: if (!$udom) { $udom=$env{'user.domain'}; }
4362: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4363: my $id=$uname.':'.$udom;
4364: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4365: if ($cached) {
4366: return %{$names};
4367: } else {
4368: my %loadnames=&Apache::lonnet::get('environment',
4369: ['notification','critnotification',
4370: 'permanentemail'],
4371: $udom,$uname);
4372: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4373: return %loadnames;
4374: }
4375: }
4376:
1.551 albertel 4377: sub flush_email_cache {
4378: my ($uname,$udom)=@_;
4379: if (!$udom) { $udom =$env{'user.domain'}; }
4380: if (!$uname) { $uname=$env{'user.name'}; }
4381: return if ($udom eq 'public' && $uname eq 'public');
4382: my $id=$uname.':'.$udom;
4383: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4384: }
4385:
1.728 raeburn 4386: # -------------------------------------------------------------------- getlangs
4387:
4388: =pod
4389:
4390: =item * &getlangs($uname,$udom)
4391:
4392: Gets a user's language preference and returns it as a hash with key:
4393: language.
4394:
4395: =cut
4396:
4397:
4398: sub getlangs {
4399: my ($uname,$udom) = @_;
4400: if (!$udom) { $udom =$env{'user.domain'}; }
4401: if (!$uname) { $uname=$env{'user.name'}; }
4402: my $id=$uname.':'.$udom;
4403: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4404: if ($cached) {
4405: return %{$langs};
4406: } else {
4407: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4408: $udom,$uname);
4409: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4410: return %loadlangs;
4411: }
4412: }
4413:
4414: sub flush_langs_cache {
4415: my ($uname,$udom)=@_;
4416: if (!$udom) { $udom =$env{'user.domain'}; }
4417: if (!$uname) { $uname=$env{'user.name'}; }
4418: return if ($udom eq 'public' && $uname eq 'public');
4419: my $id=$uname.':'.$udom;
4420: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4421: }
4422:
1.61 www 4423: # ------------------------------------------------------------------ Screenname
1.81 albertel 4424:
4425: =pod
4426:
1.648 raeburn 4427: =item * &screenname($uname,$udom)
1.81 albertel 4428:
4429: Gets a users screenname and returns it as a string
4430:
4431: =cut
1.61 www 4432:
4433: sub screenname {
4434: my ($uname,$udom)=@_;
1.258 albertel 4435: if ($uname eq $env{'user.name'} &&
4436: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4437: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4438: return $names{'screenname'};
1.62 www 4439: }
4440:
1.212 albertel 4441:
1.802 bisitz 4442: # ------------------------------------------------------------- Confirm Wrapper
4443: =pod
4444:
1.1142 raeburn 4445: =item * &confirmwrapper($message)
1.802 bisitz 4446:
4447: Wrap messages about completion of operation in box
4448:
4449: =cut
4450:
4451: sub confirmwrapper {
4452: my ($message)=@_;
4453: if ($message) {
4454: return "\n".'<div class="LC_confirm_box">'."\n"
4455: .$message."\n"
4456: .'</div>'."\n";
4457: } else {
4458: return $message;
4459: }
4460: }
4461:
1.62 www 4462: # ------------------------------------------------------------- Message Wrapper
4463:
4464: sub messagewrapper {
1.369 www 4465: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4466: return
1.441 albertel 4467: '<a href="/adm/email?compose=individual&'.
4468: 'recname='.$username.'&recdom='.$domain.
4469: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4470: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4471: }
1.802 bisitz 4472:
1.74 www 4473: # --------------------------------------------------------------- Notes Wrapper
4474:
4475: sub noteswrapper {
4476: my ($link,$un,$do)=@_;
4477: return
1.896 amueller 4478: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4479: }
1.802 bisitz 4480:
1.62 www 4481: # ------------------------------------------------------------- Aboutme Wrapper
4482:
4483: sub aboutmewrapper {
1.1070 raeburn 4484: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4485: if (!defined($username) && !defined($domain)) {
4486: return;
4487: }
1.1096 raeburn 4488: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4489: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4490: }
4491:
4492: # ------------------------------------------------------------ Syllabus Wrapper
4493:
4494: sub syllabuswrapper {
1.707 bisitz 4495: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4496: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4497: }
1.14 harris41 4498:
1.1397 raeburn 4499: # -----------------------------------------------------------------------------
4500:
1.1396 raeburn 4501: sub aboutme_on {
4502: my ($uname,$udom)=@_;
4503: unless ($uname) { $uname=$env{'user.name'}; }
4504: unless ($udom) { $udom=$env{'user.domain'}; }
4505: return if ($udom eq 'public' && $uname eq 'public');
4506: my $hashkey=$uname.':'.$udom;
4507: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4508: if ($cached) {
4509: return $aboutme;
4510: }
4511: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4512: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4513: return $aboutme;
4514: }
4515:
4516: sub devalidate_aboutme_cache {
4517: my ($uname,$udom)=@_;
4518: if (!$udom) { $udom =$env{'user.domain'}; }
4519: if (!$uname) { $uname=$env{'user.name'}; }
4520: return if ($udom eq 'public' && $uname eq 'public');
4521: my $id=$uname.':'.$udom;
4522: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4523: }
4524:
1.208 matthew 4525: sub track_student_link {
1.887 raeburn 4526: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4527: my $link ="/adm/trackstudent?";
1.208 matthew 4528: my $title = 'View recent activity';
4529: if (defined($sname) && $sname !~ /^\s*$/ &&
4530: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4531: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4532: $title .= ' of this student';
1.268 albertel 4533: }
1.208 matthew 4534: if (defined($target) && $target !~ /^\s*$/) {
4535: $target = qq{target="$target"};
4536: } else {
4537: $target = '';
4538: }
1.268 albertel 4539: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4540: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4541: $title = &mt($title);
4542: $linktext = &mt($linktext);
1.448 albertel 4543: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4544: &help_open_topic('View_recent_activity');
1.208 matthew 4545: }
4546:
1.781 raeburn 4547: sub slot_reservations_link {
4548: my ($linktext,$sname,$sdom,$target) = @_;
4549: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4550: my $title = 'View slot reservation history';
4551: if (defined($sname) && $sname !~ /^\s*$/ &&
4552: defined($sdom) && $sdom !~ /^\s*$/) {
4553: $link .= "&uname=$sname&udom=$sdom";
4554: $title .= ' of this student';
4555: }
4556: if (defined($target) && $target !~ /^\s*$/) {
4557: $target = qq{target="$target"};
4558: } else {
4559: $target = '';
4560: }
4561: $title = &mt($title);
4562: $linktext = &mt($linktext);
4563: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4564: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4565:
4566: }
4567:
1.508 www 4568: # ===================================================== Display a student photo
4569:
4570:
1.509 albertel 4571: sub student_image_tag {
1.508 www 4572: my ($domain,$user)=@_;
4573: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4574: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4575: return '<img src="'.$imgsrc.'" align="right" />';
4576: } else {
4577: return '';
4578: }
4579: }
4580:
1.112 bowersj2 4581: =pod
4582:
4583: =back
4584:
4585: =head1 Access .tab File Data
4586:
4587: =over 4
4588:
1.648 raeburn 4589: =item * &languageids()
1.112 bowersj2 4590:
4591: returns list of all language ids
4592:
4593: =cut
4594:
1.14 harris41 4595: sub languageids {
1.16 harris41 4596: return sort(keys(%language));
1.14 harris41 4597: }
4598:
1.112 bowersj2 4599: =pod
4600:
1.648 raeburn 4601: =item * &languagedescription()
1.112 bowersj2 4602:
4603: returns description of a specified language id
4604:
4605: =cut
4606:
1.14 harris41 4607: sub languagedescription {
1.125 www 4608: my $code=shift;
4609: return ($supported_language{$code}?'* ':'').
4610: $language{$code}.
1.126 www 4611: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4612: }
4613:
1.1048 foxr 4614: =pod
4615:
4616: =item * &plainlanguagedescription
4617:
4618: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4619: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4620:
4621: =cut
4622:
1.145 www 4623: sub plainlanguagedescription {
4624: my $code=shift;
4625: return $language{$code};
4626: }
4627:
1.1048 foxr 4628: =pod
4629:
4630: =item * &supportedlanguagecode
4631:
4632: Returns the supported language code (e.g. sptutf maps to pt) given a language
4633: code.
4634:
4635: =cut
4636:
1.145 www 4637: sub supportedlanguagecode {
4638: my $code=shift;
4639: return $supported_language{$code};
1.97 www 4640: }
4641:
1.112 bowersj2 4642: =pod
4643:
1.1048 foxr 4644: =item * &latexlanguage()
4645:
4646: Given a language key code returns the correspondnig language to use
4647: to select the correct hyphenation on LaTeX printouts. This is undef if there
4648: is no supported hyphenation for the language code.
4649:
4650: =cut
4651:
4652: sub latexlanguage {
4653: my $code = shift;
4654: return $latex_language{$code};
4655: }
4656:
4657: =pod
4658:
4659: =item * &latexhyphenation()
4660:
4661: Same as above but what's supplied is the language as it might be stored
4662: in the metadata.
4663:
4664: =cut
4665:
4666: sub latexhyphenation {
4667: my $key = shift;
4668: return $latex_language_bykey{$key};
4669: }
4670:
4671: =pod
4672:
1.648 raeburn 4673: =item * ©rightids()
1.112 bowersj2 4674:
4675: returns list of all copyrights
4676:
4677: =cut
4678:
4679: sub copyrightids {
4680: return sort(keys(%cprtag));
4681: }
4682:
4683: =pod
4684:
1.648 raeburn 4685: =item * ©rightdescription()
1.112 bowersj2 4686:
4687: returns description of a specified copyright id
4688:
4689: =cut
4690:
4691: sub copyrightdescription {
1.166 www 4692: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4693: }
1.197 matthew 4694:
4695: =pod
4696:
1.648 raeburn 4697: =item * &source_copyrightids()
1.192 taceyjo1 4698:
4699: returns list of all source copyrights
4700:
4701: =cut
4702:
4703: sub source_copyrightids {
4704: return sort(keys(%scprtag));
4705: }
4706:
4707: =pod
4708:
1.648 raeburn 4709: =item * &source_copyrightdescription()
1.192 taceyjo1 4710:
4711: returns description of a specified source copyright id
4712:
4713: =cut
4714:
4715: sub source_copyrightdescription {
4716: return &mt($scprtag{shift(@_)});
4717: }
1.112 bowersj2 4718:
4719: =pod
4720:
1.648 raeburn 4721: =item * &filecategories()
1.112 bowersj2 4722:
4723: returns list of all file categories
4724:
4725: =cut
4726:
4727: sub filecategories {
4728: return sort(keys(%category_extensions));
4729: }
4730:
4731: =pod
4732:
1.648 raeburn 4733: =item * &filecategorytypes()
1.112 bowersj2 4734:
4735: returns list of file types belonging to a given file
4736: category
4737:
4738: =cut
4739:
4740: sub filecategorytypes {
1.356 albertel 4741: my ($cat) = @_;
1.1248 raeburn 4742: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4743: return @{$category_extensions{lc($cat)}};
4744: } else {
4745: return ();
4746: }
1.112 bowersj2 4747: }
4748:
4749: =pod
4750:
1.648 raeburn 4751: =item * &fileembstyle()
1.112 bowersj2 4752:
4753: returns embedding style for a specified file type
4754:
4755: =cut
4756:
4757: sub fileembstyle {
4758: return $fe{lc(shift(@_))};
1.169 www 4759: }
4760:
1.351 www 4761: sub filemimetype {
4762: return $fm{lc(shift(@_))};
4763: }
4764:
1.169 www 4765:
4766: sub filecategoryselect {
4767: my ($name,$value)=@_;
1.189 matthew 4768: return &select_form($value,$name,
1.970 raeburn 4769: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4770: }
4771:
4772: =pod
4773:
1.648 raeburn 4774: =item * &filedescription()
1.112 bowersj2 4775:
4776: returns description for a specified file type
4777:
4778: =cut
4779:
4780: sub filedescription {
1.188 matthew 4781: my $file_description = $fd{lc(shift())};
4782: $file_description =~ s:([\[\]]):~$1:g;
4783: return &mt($file_description);
1.112 bowersj2 4784: }
4785:
4786: =pod
4787:
1.648 raeburn 4788: =item * &filedescriptionex()
1.112 bowersj2 4789:
4790: returns description for a specified file type with
4791: extra formatting
4792:
4793: =cut
4794:
4795: sub filedescriptionex {
4796: my $ex=shift;
1.188 matthew 4797: my $file_description = $fd{lc($ex)};
4798: $file_description =~ s:([\[\]]):~$1:g;
4799: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4800: }
4801:
4802: # End of .tab access
4803: =pod
4804:
4805: =back
4806:
4807: =cut
4808:
4809: # ------------------------------------------------------------------ File Types
4810: sub fileextensions {
4811: return sort(keys(%fe));
4812: }
4813:
1.97 www 4814: # ----------------------------------------------------------- Display Languages
4815: # returns a hash with all desired display languages
4816: #
4817:
4818: sub display_languages {
4819: my %languages=();
1.695 raeburn 4820: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4821: $languages{$lang}=1;
1.97 www 4822: }
4823: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4824: if ($env{'form.displaylanguage'}) {
1.356 albertel 4825: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4826: $languages{$lang}=1;
1.97 www 4827: }
4828: }
4829: return %languages;
1.14 harris41 4830: }
4831:
1.582 albertel 4832: sub languages {
4833: my ($possible_langs) = @_;
1.695 raeburn 4834: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4835: if (!ref($possible_langs)) {
4836: if( wantarray ) {
4837: return @preferred_langs;
4838: } else {
4839: return $preferred_langs[0];
4840: }
4841: }
4842: my %possibilities = map { $_ => 1 } (@$possible_langs);
4843: my @preferred_possibilities;
4844: foreach my $preferred_lang (@preferred_langs) {
4845: if (exists($possibilities{$preferred_lang})) {
4846: push(@preferred_possibilities, $preferred_lang);
4847: }
4848: }
4849: if( wantarray ) {
4850: return @preferred_possibilities;
4851: }
4852: return $preferred_possibilities[0];
4853: }
4854:
1.742 raeburn 4855: sub user_lang {
4856: my ($touname,$toudom,$fromcid) = @_;
4857: my @userlangs;
4858: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4859: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4860: $env{'course.'.$fromcid.'.languages'}));
4861: } else {
4862: my %langhash = &getlangs($touname,$toudom);
4863: if ($langhash{'languages'} ne '') {
4864: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4865: } else {
4866: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4867: if ($domdefs{'lang_def'} ne '') {
4868: @userlangs = ($domdefs{'lang_def'});
4869: }
4870: }
4871: }
4872: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4873: my $user_lh = Apache::localize->get_handle(@languages);
4874: return $user_lh;
4875: }
4876:
4877:
1.112 bowersj2 4878: ###############################################################
4879: ## Student Answer Attempts ##
4880: ###############################################################
4881:
4882: =pod
4883:
4884: =head1 Alternate Problem Views
4885:
4886: =over 4
4887:
1.648 raeburn 4888: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4889: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4890:
4891: Return string with previous attempt on problem. Arguments:
4892:
4893: =over 4
4894:
4895: =item * $symb: Problem, including path
4896:
4897: =item * $username: username of the desired student
4898:
4899: =item * $domain: domain of the desired student
1.14 harris41 4900:
1.112 bowersj2 4901: =item * $course: Course ID
1.14 harris41 4902:
1.112 bowersj2 4903: =item * $getattempt: Leave blank for all attempts, otherwise put
4904: something
1.14 harris41 4905:
1.112 bowersj2 4906: =item * $regexp: if string matches this regexp, the string will be
4907: sent to $gradesub
1.14 harris41 4908:
1.112 bowersj2 4909: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4910:
1.1199 raeburn 4911: =item * $usec: section of the desired student
4912:
4913: =item * $identifier: counter for student (multiple students one problem) or
4914: problem (one student; whole sequence).
4915:
1.112 bowersj2 4916: =back
1.14 harris41 4917:
1.112 bowersj2 4918: The output string is a table containing all desired attempts, if any.
1.16 harris41 4919:
1.112 bowersj2 4920: =cut
1.1 albertel 4921:
4922: sub get_previous_attempt {
1.1199 raeburn 4923: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4924: my $prevattempts='';
1.43 ng 4925: no strict 'refs';
1.1 albertel 4926: if ($symb) {
1.3 albertel 4927: my (%returnhash)=
4928: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4929: if ($returnhash{'version'}) {
4930: my %lasthash=();
4931: my $version;
4932: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4933: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4934: if ($key =~ /\.rawrndseed$/) {
4935: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4936: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4937: } else {
4938: $lasthash{$key}=$returnhash{$version.':'.$key};
4939: }
1.19 harris41 4940: }
1.1 albertel 4941: }
1.596 albertel 4942: $prevattempts=&start_data_table().&start_data_table_header_row();
4943: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4944: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4945: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4946: foreach my $key (sort(keys(%lasthash))) {
4947: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4948: if ($#parts > 0) {
1.31 albertel 4949: my $data=$parts[-1];
1.989 raeburn 4950: next if ($data eq 'foilorder');
1.31 albertel 4951: pop(@parts);
1.1010 www 4952: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4953: if ($data eq 'type') {
4954: unless ($showsurv) {
4955: my $id = join(',',@parts);
4956: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4957: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4958: $lasthidden{$ign.'.'.$id} = 1;
4959: }
1.945 raeburn 4960: }
1.1199 raeburn 4961: if ($identifier ne '') {
4962: my $id = join(',',@parts);
4963: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4964: $domain,$username,$usec,undef,$course) =~ /^no/) {
4965: $hidestatus{$ign.'.'.$id} = 1;
4966: }
4967: }
4968: } elsif ($data eq 'regrader') {
4969: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4970: my $id = join(',',@parts);
4971: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4972: }
1.1010 www 4973: }
1.31 albertel 4974: } else {
1.41 ng 4975: if ($#parts == 0) {
4976: $prevattempts.='<th>'.$parts[0].'</th>';
4977: } else {
4978: $prevattempts.='<th>'.$ign.'</th>';
4979: }
1.31 albertel 4980: }
1.16 harris41 4981: }
1.596 albertel 4982: $prevattempts.=&end_data_table_header_row();
1.40 ng 4983: if ($getattempt eq '') {
1.1199 raeburn 4984: my (%solved,%resets,%probstatus);
1.1200 raeburn 4985: if (($identifier ne '') && (keys(%regraded) > 0)) {
4986: for ($version=1;$version<=$returnhash{'version'};$version++) {
4987: foreach my $id (keys(%regraded)) {
4988: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4989: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4990: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4991: push(@{$resets{$id}},$version);
1.1199 raeburn 4992: }
4993: }
4994: }
1.1200 raeburn 4995: }
4996: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4997: my (@hidden,@unsolved);
1.945 raeburn 4998: if (%typeparts) {
4999: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 5000: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
5001: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 5002: push(@hidden,$id);
1.1199 raeburn 5003: } elsif ($identifier ne '') {
5004: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
5005: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
5006: ($hidestatus{$id})) {
1.1200 raeburn 5007: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 5008: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
5009: push(@{$solved{$id}},$version);
5010: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
5011: (ref($solved{$id}) eq 'ARRAY')) {
5012: my $skip;
5013: if (ref($resets{$id}) eq 'ARRAY') {
5014: foreach my $reset (@{$resets{$id}}) {
5015: if ($reset > $solved{$id}[-1]) {
5016: $skip=1;
5017: last;
5018: }
5019: }
5020: }
5021: unless ($skip) {
5022: my ($ign,$partslist) = split(/\./,$id,2);
5023: push(@unsolved,$partslist);
5024: }
5025: }
5026: }
1.945 raeburn 5027: }
5028: }
5029: }
5030: $prevattempts.=&start_data_table_row().
1.1199 raeburn 5031: '<td>'.&mt('Transaction [_1]',$version);
5032: if (@unsolved) {
5033: $prevattempts .= '<span class="LC_nobreak"><label>'.
5034: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
5035: &mt('Hide').'</label></span>';
5036: }
5037: $prevattempts .= '</td>';
1.945 raeburn 5038: if (@hidden) {
5039: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5040: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5041: my $hide;
5042: foreach my $id (@hidden) {
5043: if ($key =~ /^\Q$id\E/) {
5044: $hide = 1;
5045: last;
5046: }
5047: }
5048: if ($hide) {
5049: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5050: if (($data eq 'award') || ($data eq 'awarddetail')) {
5051: my $value = &format_previous_attempt_value($key,
5052: $returnhash{$version.':'.$key});
1.1173 kruse 5053: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5054: } else {
5055: $prevattempts.='<td> </td>';
5056: }
5057: } else {
5058: if ($key =~ /\./) {
1.1212 raeburn 5059: my $value = $returnhash{$version.':'.$key};
5060: if ($key =~ /\.rndseed$/) {
5061: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5062: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5063: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5064: }
5065: }
5066: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5067: ' </td>';
1.945 raeburn 5068: } else {
5069: $prevattempts.='<td> </td>';
5070: }
5071: }
5072: }
5073: } else {
5074: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5075: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 5076: my $value = $returnhash{$version.':'.$key};
5077: if ($key =~ /\.rndseed$/) {
5078: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5079: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5080: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5081: }
5082: }
5083: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5084: ' </td>';
1.945 raeburn 5085: }
5086: }
5087: $prevattempts.=&end_data_table_row();
1.40 ng 5088: }
1.1 albertel 5089: }
1.945 raeburn 5090: my @currhidden = keys(%lasthidden);
1.596 albertel 5091: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 5092: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5093: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5094: if (%typeparts) {
5095: my $hidden;
5096: foreach my $id (@currhidden) {
5097: if ($key =~ /^\Q$id\E/) {
5098: $hidden = 1;
5099: last;
5100: }
5101: }
5102: if ($hidden) {
5103: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5104: if (($data eq 'award') || ($data eq 'awarddetail')) {
5105: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5106: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5107: $value = &$gradesub($value);
5108: }
1.1173 kruse 5109: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5110: } else {
5111: $prevattempts.='<td> </td>';
5112: }
5113: } else {
5114: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5115: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5116: $value = &$gradesub($value);
5117: }
1.1173 kruse 5118: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5119: }
5120: } else {
5121: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5122: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5123: $value = &$gradesub($value);
5124: }
1.1173 kruse 5125: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5126: }
1.16 harris41 5127: }
1.596 albertel 5128: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5129: } else {
1.1305 raeburn 5130: my $msg;
5131: if ($symb =~ /ext\.tool$/) {
5132: $msg = &mt('No grade passed back.');
5133: } else {
5134: $msg = &mt('Nothing submitted - no attempts.');
5135: }
1.596 albertel 5136: $prevattempts=
5137: &start_data_table().&start_data_table_row().
1.1305 raeburn 5138: '<td>'.$msg.'</td>'.
1.596 albertel 5139: &end_data_table_row().&end_data_table();
1.1 albertel 5140: }
5141: } else {
1.596 albertel 5142: $prevattempts=
5143: &start_data_table().&start_data_table_row().
5144: '<td>'.&mt('No data.').'</td>'.
5145: &end_data_table_row().&end_data_table();
1.1 albertel 5146: }
1.10 albertel 5147: }
5148:
1.581 albertel 5149: sub format_previous_attempt_value {
5150: my ($key,$value) = @_;
1.1011 www 5151: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5152: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5153: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5154: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5155: } elsif ($key =~ /answerstring$/) {
5156: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5157: my @answer = %answers;
5158: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5159: my @anskeys = sort(keys(%answers));
5160: if (@anskeys == 1) {
5161: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5162: if ($answer =~ m{\0}) {
5163: $answer =~ s{\0}{,}g;
1.988 raeburn 5164: }
5165: my $tag_internal_answer_name = 'INTERNAL';
5166: if ($anskeys[0] eq $tag_internal_answer_name) {
5167: $value = $answer;
5168: } else {
5169: $value = $anskeys[0].'='.$answer;
5170: }
5171: } else {
5172: foreach my $ans (@anskeys) {
5173: my $answer = $answers{$ans};
1.1001 raeburn 5174: if ($answer =~ m{\0}) {
5175: $answer =~ s{\0}{,}g;
1.988 raeburn 5176: }
5177: $value .= $ans.'='.$answer.'<br />';;
5178: }
5179: }
1.581 albertel 5180: } else {
1.1173 kruse 5181: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5182: }
5183: return $value;
5184: }
5185:
5186:
1.107 albertel 5187: sub relative_to_absolute {
5188: my ($url,$output)=@_;
5189: my $parser=HTML::TokeParser->new(\$output);
5190: my $token;
5191: my $thisdir=$url;
5192: my @rlinks=();
5193: while ($token=$parser->get_token) {
5194: if ($token->[0] eq 'S') {
5195: if ($token->[1] eq 'a') {
5196: if ($token->[2]->{'href'}) {
5197: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5198: }
5199: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5200: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5201: } elsif ($token->[1] eq 'base') {
5202: $thisdir=$token->[2]->{'href'};
5203: }
5204: }
5205: }
5206: $thisdir=~s-/[^/]*$--;
1.356 albertel 5207: foreach my $link (@rlinks) {
1.726 raeburn 5208: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5209: ($link=~/^\//) ||
5210: ($link=~/^javascript:/i) ||
5211: ($link=~/^mailto:/i) ||
5212: ($link=~/^\#/)) {
5213: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5214: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5215: }
5216: }
5217: # -------------------------------------------------- Deal with Applet codebases
5218: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5219: return $output;
5220: }
5221:
1.112 bowersj2 5222: =pod
5223:
1.648 raeburn 5224: =item * &get_student_view()
1.112 bowersj2 5225:
5226: show a snapshot of what student was looking at
5227:
5228: =cut
5229:
1.10 albertel 5230: sub get_student_view {
1.186 albertel 5231: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5232: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5233: my (%form);
1.10 albertel 5234: my @elements=('symb','courseid','domain','username');
5235: foreach my $element (@elements) {
1.186 albertel 5236: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5237: }
1.186 albertel 5238: if (defined($moreenv)) {
5239: %form=(%form,%{$moreenv});
5240: }
1.236 albertel 5241: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5242: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5243: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5244: $feedurl =~ s{^/adm/wrapper}{};
5245: }
1.650 www 5246: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5247: $userview=~s/\<body[^\>]*\>//gi;
5248: $userview=~s/\<\/body\>//gi;
5249: $userview=~s/\<html\>//gi;
5250: $userview=~s/\<\/html\>//gi;
5251: $userview=~s/\<head\>//gi;
5252: $userview=~s/\<\/head\>//gi;
5253: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5254: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5255: if (wantarray) {
5256: return ($userview,$response);
5257: } else {
5258: return $userview;
5259: }
5260: }
5261:
5262: sub get_student_view_with_retries {
5263: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5264:
5265: my $ok = 0; # True if we got a good response.
5266: my $content;
5267: my $response;
5268:
5269: # Try to get the student_view done. within the retries count:
5270:
5271: do {
5272: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5273: $ok = $response->is_success;
5274: if (!$ok) {
5275: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5276: }
5277: $retries--;
5278: } while (!$ok && ($retries > 0));
5279:
5280: if (!$ok) {
5281: $content = ''; # On error return an empty content.
5282: }
1.651 www 5283: if (wantarray) {
5284: return ($content, $response);
5285: } else {
5286: return $content;
5287: }
1.11 albertel 5288: }
5289:
1.1349 raeburn 5290: sub css_links {
5291: my ($currsymb,$level) = @_;
5292: my ($links,@symbs,%cssrefs,%httpref);
5293: if ($level eq 'map') {
5294: my $navmap = Apache::lonnavmaps::navmap->new();
5295: if (ref($navmap)) {
5296: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5297: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5298: foreach my $res (@resources) {
5299: if (ref($res) && $res->symb()) {
5300: push(@symbs,$res->symb());
5301: }
5302: }
5303: }
5304: } else {
5305: @symbs = ($currsymb);
5306: }
5307: foreach my $symb (@symbs) {
5308: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5309: if ($css_href =~ /\S/) {
5310: unless ($css_href =~ m{https?://}) {
5311: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5312: my $proburl = &Apache::lonnet::clutter($url);
5313: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5314: unless ($css_href =~ m{^/}) {
5315: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5316: }
5317: if ($css_href =~ m{^/(res|uploaded)/}) {
5318: unless (($httpref{'httpref.'.$css_href}) ||
5319: (&Apache::lonnet::is_on_map($css_href))) {
5320: my $thisurl = $proburl;
5321: if ($env{'httpref.'.$proburl}) {
5322: $thisurl = $env{'httpref.'.$proburl};
5323: }
5324: $httpref{'httpref.'.$css_href} = $thisurl;
5325: }
5326: }
5327: }
5328: $cssrefs{$css_href} = 1;
5329: }
5330: }
5331: if (keys(%httpref)) {
5332: &Apache::lonnet::appenv(\%httpref);
5333: }
5334: if (keys(%cssrefs)) {
5335: foreach my $css_href (keys(%cssrefs)) {
5336: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5337: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5338: }
5339: }
5340: return $links;
5341: }
5342:
1.112 bowersj2 5343: =pod
5344:
1.648 raeburn 5345: =item * &get_student_answers()
1.112 bowersj2 5346:
5347: show a snapshot of how student was answering problem
5348:
5349: =cut
5350:
1.11 albertel 5351: sub get_student_answers {
1.100 sakharuk 5352: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5353: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5354: my (%moreenv);
1.11 albertel 5355: my @elements=('symb','courseid','domain','username');
5356: foreach my $element (@elements) {
1.186 albertel 5357: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5358: }
1.186 albertel 5359: $moreenv{'grade_target'}='answer';
5360: %moreenv=(%form,%moreenv);
1.497 raeburn 5361: $feedurl = &Apache::lonnet::clutter($feedurl);
5362: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5363: return $userview;
1.1 albertel 5364: }
1.116 albertel 5365:
5366: =pod
5367:
5368: =item * &submlink()
5369:
1.242 albertel 5370: Inputs: $text $uname $udom $symb $target
1.116 albertel 5371:
5372: Returns: A link to grades.pm such as to see the SUBM view of a student
5373:
5374: =cut
5375:
5376: ###############################################
5377: sub submlink {
1.242 albertel 5378: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5379: if (!($uname && $udom)) {
5380: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5381: &Apache::lonnet::whichuser($symb);
1.116 albertel 5382: if (!$symb) { $symb=$cursymb; }
5383: }
1.254 matthew 5384: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5385: $symb=&escape($symb);
1.960 bisitz 5386: if ($target) { $target=" target=\"$target\""; }
5387: return
5388: '<a href="/adm/grades?command=submission'.
5389: '&symb='.$symb.
5390: '&student='.$uname.
5391: '&userdom='.$udom.'"'.
5392: $target.'>'.$text.'</a>';
1.242 albertel 5393: }
5394: ##############################################
5395:
5396: =pod
5397:
5398: =item * &pgrdlink()
5399:
5400: Inputs: $text $uname $udom $symb $target
5401:
5402: Returns: A link to grades.pm such as to see the PGRD view of a student
5403:
5404: =cut
5405:
5406: ###############################################
5407: sub pgrdlink {
5408: my $link=&submlink(@_);
5409: $link=~s/(&command=submission)/$1&showgrading=yes/;
5410: return $link;
5411: }
5412: ##############################################
5413:
5414: =pod
5415:
5416: =item * &pprmlink()
5417:
5418: Inputs: $text $uname $udom $symb $target
5419:
5420: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5421: student and a specific resource
1.242 albertel 5422:
5423: =cut
5424:
5425: ###############################################
5426: sub pprmlink {
5427: my ($text,$uname,$udom,$symb,$target)=@_;
5428: if (!($uname && $udom)) {
5429: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5430: &Apache::lonnet::whichuser($symb);
1.242 albertel 5431: if (!$symb) { $symb=$cursymb; }
5432: }
1.254 matthew 5433: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5434: $symb=&escape($symb);
1.242 albertel 5435: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5436: return '<a href="/adm/parmset?command=set&'.
5437: 'symb='.$symb.'&uname='.$uname.
5438: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5439: }
5440: ##############################################
1.37 matthew 5441:
1.112 bowersj2 5442: =pod
5443:
5444: =back
5445:
5446: =cut
5447:
1.37 matthew 5448: ###############################################
1.51 www 5449:
5450:
5451: sub timehash {
1.687 raeburn 5452: my ($thistime) = @_;
5453: my $timezone = &Apache::lonlocal::gettimezone();
5454: my $dt = DateTime->from_epoch(epoch => $thistime)
5455: ->set_time_zone($timezone);
5456: my $wday = $dt->day_of_week();
5457: if ($wday == 7) { $wday = 0; }
5458: return ( 'second' => $dt->second(),
5459: 'minute' => $dt->minute(),
5460: 'hour' => $dt->hour(),
5461: 'day' => $dt->day_of_month(),
5462: 'month' => $dt->month(),
5463: 'year' => $dt->year(),
5464: 'weekday' => $wday,
5465: 'dayyear' => $dt->day_of_year(),
5466: 'dlsav' => $dt->is_dst() );
1.51 www 5467: }
5468:
1.370 www 5469: sub utc_string {
5470: my ($date)=@_;
1.371 www 5471: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5472: }
5473:
1.51 www 5474: sub maketime {
5475: my %th=@_;
1.687 raeburn 5476: my ($epoch_time,$timezone,$dt);
5477: $timezone = &Apache::lonlocal::gettimezone();
5478: eval {
5479: $dt = DateTime->new( year => $th{'year'},
5480: month => $th{'month'},
5481: day => $th{'day'},
5482: hour => $th{'hour'},
5483: minute => $th{'minute'},
5484: second => $th{'second'},
5485: time_zone => $timezone,
5486: );
5487: };
5488: if (!$@) {
5489: $epoch_time = $dt->epoch;
5490: if ($epoch_time) {
5491: return $epoch_time;
5492: }
5493: }
1.51 www 5494: return POSIX::mktime(
5495: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5496: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5497: }
5498:
5499: #########################################
1.51 www 5500:
5501: sub findallcourses {
1.482 raeburn 5502: my ($roles,$uname,$udom) = @_;
1.355 albertel 5503: my %roles;
5504: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5505: my %courses;
1.51 www 5506: my $now=time;
1.482 raeburn 5507: if (!defined($uname)) {
5508: $uname = $env{'user.name'};
5509: }
5510: if (!defined($udom)) {
5511: $udom = $env{'user.domain'};
5512: }
5513: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5514: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5515: if (!%roles) {
5516: %roles = (
5517: cc => 1,
1.907 raeburn 5518: co => 1,
1.482 raeburn 5519: in => 1,
5520: ep => 1,
5521: ta => 1,
5522: cr => 1,
5523: st => 1,
5524: );
5525: }
5526: foreach my $entry (keys(%roleshash)) {
5527: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5528: if ($trole =~ /^cr/) {
5529: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5530: } else {
5531: next if (!exists($roles{$trole}));
5532: }
5533: if ($tend) {
5534: next if ($tend < $now);
5535: }
5536: if ($tstart) {
5537: next if ($tstart > $now);
5538: }
1.1058 raeburn 5539: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5540: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5541: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5542: if ($secpart eq '') {
5543: ($cnum,$role) = split(/_/,$cnumpart);
5544: $sec = 'none';
1.1058 raeburn 5545: $value .= $cnum.'/';
1.482 raeburn 5546: } else {
5547: $cnum = $cnumpart;
5548: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5549: $value .= $cnum.'/'.$sec;
5550: }
5551: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5552: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5553: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5554: }
5555: } else {
5556: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5557: }
1.482 raeburn 5558: }
5559: } else {
5560: foreach my $key (keys(%env)) {
1.483 albertel 5561: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5562: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5563: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5564: next if ($role eq 'ca' || $role eq 'aa');
5565: next if (%roles && !exists($roles{$role}));
5566: my ($starttime,$endtime)=split(/\./,$env{$key});
5567: my $active=1;
5568: if ($starttime) {
5569: if ($now<$starttime) { $active=0; }
5570: }
5571: if ($endtime) {
5572: if ($now>$endtime) { $active=0; }
5573: }
5574: if ($active) {
1.1058 raeburn 5575: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5576: if ($sec eq '') {
5577: $sec = 'none';
1.1058 raeburn 5578: } else {
5579: $value .= $sec;
5580: }
5581: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5582: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5583: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5584: }
5585: } else {
5586: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5587: }
1.474 raeburn 5588: }
5589: }
1.51 www 5590: }
5591: }
1.474 raeburn 5592: return %courses;
1.51 www 5593: }
1.37 matthew 5594:
1.54 www 5595: ###############################################
1.474 raeburn 5596:
5597: sub blockcheck {
1.1372 raeburn 5598: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5599: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5600: my ($has_evb,$check_ipaccess);
5601: my $dom = $env{'user.domain'};
5602: if ($env{'request.course.id'}) {
5603: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5604: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5605: my $checkrole = "cm./$cdom/$cnum";
5606: my $sec = $env{'request.course.sec'};
5607: if ($sec ne '') {
5608: $checkrole .= "/$sec";
5609: }
5610: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5611: ($env{'request.role'} !~ /^st/)) {
5612: $has_evb = 1;
5613: }
5614: unless ($has_evb) {
5615: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5616: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5617: if ($udom eq $cdom) {
5618: $check_ipaccess = 1;
5619: }
5620: }
5621: }
1.1375 raeburn 5622: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5623: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5624: my $checkrole;
5625: if ($env{'request.role.domain'} eq '') {
5626: $checkrole = "cm./$env{'user.domain'}/";
5627: } else {
5628: $checkrole = "cm./$env{'request.role.domain'}/";
5629: }
5630: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5631: $has_evb = 1;
5632: }
1.1372 raeburn 5633: }
5634: unless ($has_evb || $check_ipaccess) {
5635: my @machinedoms = &Apache::lonnet::current_machine_domains();
5636: if (($dom eq 'public') && ($activity eq 'port')) {
5637: $dom = $udom;
5638: }
5639: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5640: $check_ipaccess = 1;
5641: } else {
5642: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5643: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5644: my $prim = &Apache::lonnet::domain($dom,'primary');
5645: my $intdom = &Apache::lonnet::internet_dom($prim);
5646: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5647: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5648: $check_ipaccess = 1;
5649: }
5650: }
5651: }
5652: }
5653: if ($check_ipaccess) {
5654: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5655: unless (defined($cached)) {
5656: my %domconfig =
5657: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5658: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5659: }
5660: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5661: foreach my $id (keys(%{$ipaccessref})) {
5662: if (ref($ipaccessref->{$id}) eq 'HASH') {
5663: my $range = $ipaccessref->{$id}->{'ip'};
5664: if ($range) {
5665: if (&Apache::lonnet::ip_match($clientip,$range)) {
5666: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5667: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5668: return ('','','',$id,$dom);
5669: last;
5670: }
5671: }
5672: }
5673: }
5674: }
5675: }
5676: }
5677: }
1.1373 raeburn 5678: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5679: return ();
5680: }
1.1372 raeburn 5681: }
1.1189 raeburn 5682: if (defined($udom) && defined($uname)) {
5683: # If uname and udom are for a course, check for blocks in the course.
5684: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5685: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5686: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5687: return ($startblock,$endblock,$triggerblock);
5688: }
5689: } else {
1.490 raeburn 5690: $udom = $env{'user.domain'};
5691: $uname = $env{'user.name'};
5692: }
5693:
1.502 raeburn 5694: my $startblock = 0;
5695: my $endblock = 0;
1.1062 raeburn 5696: my $triggerblock = '';
1.1373 raeburn 5697: my %live_courses;
5698: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5699: %live_courses = &findallcourses(undef,$uname,$udom);
5700: }
1.474 raeburn 5701:
1.490 raeburn 5702: # If uname is for a user, and activity is course-specific, i.e.,
5703: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5704:
1.490 raeburn 5705: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5706: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5707: $activity eq 'search' || $activity eq 'reinit' ||
5708: $activity eq 'alert') &&
1.1189 raeburn 5709: ($env{'request.course.id'})) {
1.490 raeburn 5710: foreach my $key (keys(%live_courses)) {
5711: if ($key ne $env{'request.course.id'}) {
5712: delete($live_courses{$key});
5713: }
5714: }
5715: }
5716:
5717: my $otheruser = 0;
5718: my %own_courses;
5719: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5720: # Resource belongs to user other than current user.
5721: $otheruser = 1;
5722: # Gather courses for current user
5723: %own_courses =
5724: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5725: }
5726:
5727: # Gather active course roles - course coordinator, instructor,
5728: # exam proctor, ta, student, or custom role.
1.474 raeburn 5729:
5730: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5731: my ($cdom,$cnum);
5732: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5733: $cdom = $env{'course.'.$course.'.domain'};
5734: $cnum = $env{'course.'.$course.'.num'};
5735: } else {
1.490 raeburn 5736: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5737: }
5738: my $no_ownblock = 0;
5739: my $no_userblock = 0;
1.533 raeburn 5740: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5741: # Check if current user has 'evb' priv for this
5742: if (defined($own_courses{$course})) {
5743: foreach my $sec (keys(%{$own_courses{$course}})) {
5744: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5745: if ($sec ne 'none') {
5746: $checkrole .= '/'.$sec;
5747: }
5748: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5749: $no_ownblock = 1;
5750: last;
5751: }
5752: }
5753: }
5754: # if they have 'evb' priv and are currently not playing student
5755: next if (($no_ownblock) &&
5756: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5757: }
1.474 raeburn 5758: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5759: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5760: if ($sec ne 'none') {
1.482 raeburn 5761: $checkrole .= '/'.$sec;
1.474 raeburn 5762: }
1.490 raeburn 5763: if ($otheruser) {
5764: # Resource belongs to user other than current user.
5765: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5766: my (%allroles,%userroles);
5767: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5768: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5769: my ($trole,$tdom,$tnum,$tsec);
5770: if ($entry =~ /^cr/) {
5771: ($trole,$tdom,$tnum,$tsec) =
5772: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5773: } else {
5774: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5775: }
5776: my ($spec,$area,$trest);
5777: $area = '/'.$tdom.'/'.$tnum;
5778: $trest = $tnum;
5779: if ($tsec ne '') {
5780: $area .= '/'.$tsec;
5781: $trest .= '/'.$tsec;
5782: }
5783: $spec = $trole.'.'.$area;
5784: if ($trole =~ /^cr/) {
5785: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5786: $tdom,$spec,$trest,$area);
5787: } else {
5788: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5789: $tdom,$spec,$trest,$area);
5790: }
5791: }
1.1276 raeburn 5792: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5793: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5794: if ($1) {
5795: $no_userblock = 1;
5796: last;
5797: }
1.486 raeburn 5798: }
5799: }
1.490 raeburn 5800: } else {
5801: # Resource belongs to current user
5802: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5803: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5804: $no_ownblock = 1;
5805: last;
5806: }
1.474 raeburn 5807: }
5808: }
5809: # if they have the evb priv and are currently not playing student
1.482 raeburn 5810: next if (($no_ownblock) &&
1.491 albertel 5811: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5812: next if ($no_userblock);
1.474 raeburn 5813:
1.1303 raeburn 5814: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5815: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5816:
1.1062 raeburn 5817: my ($start,$end,$trigger) =
1.1347 raeburn 5818: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5819: if (($start != 0) &&
5820: (($startblock == 0) || ($startblock > $start))) {
5821: $startblock = $start;
1.1062 raeburn 5822: if ($trigger ne '') {
5823: $triggerblock = $trigger;
5824: }
1.502 raeburn 5825: }
5826: if (($end != 0) &&
5827: (($endblock == 0) || ($endblock < $end))) {
5828: $endblock = $end;
1.1062 raeburn 5829: if ($trigger ne '') {
5830: $triggerblock = $trigger;
5831: }
1.502 raeburn 5832: }
1.490 raeburn 5833: }
1.1062 raeburn 5834: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5835: }
5836:
5837: sub get_blocks {
1.1347 raeburn 5838: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5839: my $startblock = 0;
5840: my $endblock = 0;
1.1062 raeburn 5841: my $triggerblock = '';
1.490 raeburn 5842: my $course = $cdom.'_'.$cnum;
5843: $setters->{$course} = {};
5844: $setters->{$course}{'staff'} = [];
5845: $setters->{$course}{'times'} = [];
1.1062 raeburn 5846: $setters->{$course}{'triggers'} = [];
5847: my (@blockers,%triggered);
5848: my $now = time;
5849: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5850: if ($activity eq 'docs') {
1.1348 raeburn 5851: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5852: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5853: $blocked = 1;
5854: $nosymbcache = 1;
1.1348 raeburn 5855: $noenccheck = 1;
1.1347 raeburn 5856: }
1.1348 raeburn 5857: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5858: foreach my $block (@blockers) {
5859: if ($block =~ /^firstaccess____(.+)$/) {
5860: my $item = $1;
5861: my $type = 'map';
5862: my $timersymb = $item;
5863: if ($item eq 'course') {
5864: $type = 'course';
5865: } elsif ($item =~ /___\d+___/) {
5866: $type = 'resource';
5867: } else {
5868: $timersymb = &Apache::lonnet::symbread($item);
5869: }
5870: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5871: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5872: $triggered{$block} = {
5873: start => $start,
5874: end => $end,
5875: type => $type,
5876: };
5877: }
5878: }
5879: } else {
5880: foreach my $block (keys(%commblocks)) {
5881: if ($block =~ m/^(\d+)____(\d+)$/) {
5882: my ($start,$end) = ($1,$2);
5883: if ($start <= time && $end >= time) {
5884: if (ref($commblocks{$block}) eq 'HASH') {
5885: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5886: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5887: unless(grep(/^\Q$block\E$/,@blockers)) {
5888: push(@blockers,$block);
5889: }
5890: }
5891: }
5892: }
5893: }
5894: } elsif ($block =~ /^firstaccess____(.+)$/) {
5895: my $item = $1;
5896: my $timersymb = $item;
5897: my $type = 'map';
5898: if ($item eq 'course') {
5899: $type = 'course';
5900: } elsif ($item =~ /___\d+___/) {
5901: $type = 'resource';
5902: } else {
5903: $timersymb = &Apache::lonnet::symbread($item);
5904: }
5905: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5906: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5907: if ($start && $end) {
5908: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5909: if (ref($commblocks{$block}) eq 'HASH') {
5910: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5911: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5912: unless(grep(/^\Q$block\E$/,@blockers)) {
5913: push(@blockers,$block);
5914: $triggered{$block} = {
5915: start => $start,
5916: end => $end,
5917: type => $type,
5918: };
5919: }
5920: }
5921: }
1.1062 raeburn 5922: }
5923: }
1.490 raeburn 5924: }
1.1062 raeburn 5925: }
5926: }
5927: }
5928: foreach my $blocker (@blockers) {
5929: my ($staff_name,$staff_dom,$title,$blocks) =
5930: &parse_block_record($commblocks{$blocker});
5931: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5932: my ($start,$end,$triggertype);
5933: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5934: ($start,$end) = ($1,$2);
5935: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5936: $start = $triggered{$blocker}{'start'};
5937: $end = $triggered{$blocker}{'end'};
5938: $triggertype = $triggered{$blocker}{'type'};
5939: }
5940: if ($start) {
5941: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5942: if ($triggertype) {
5943: push(@{$$setters{$course}{'triggers'}},$triggertype);
5944: } else {
5945: push(@{$$setters{$course}{'triggers'}},0);
5946: }
5947: if ( ($startblock == 0) || ($startblock > $start) ) {
5948: $startblock = $start;
5949: if ($triggertype) {
5950: $triggerblock = $blocker;
1.474 raeburn 5951: }
5952: }
1.1062 raeburn 5953: if ( ($endblock == 0) || ($endblock < $end) ) {
5954: $endblock = $end;
5955: if ($triggertype) {
5956: $triggerblock = $blocker;
5957: }
5958: }
1.474 raeburn 5959: }
5960: }
1.1062 raeburn 5961: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5962: }
5963:
5964: sub parse_block_record {
5965: my ($record) = @_;
5966: my ($setuname,$setudom,$title,$blocks);
5967: if (ref($record) eq 'HASH') {
5968: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5969: $title = &unescape($record->{'event'});
5970: $blocks = $record->{'blocks'};
5971: } else {
5972: my @data = split(/:/,$record,3);
5973: if (scalar(@data) eq 2) {
5974: $title = $data[1];
5975: ($setuname,$setudom) = split(/@/,$data[0]);
5976: } else {
5977: ($setuname,$setudom,$title) = @data;
5978: }
5979: $blocks = { 'com' => 'on' };
5980: }
5981: return ($setuname,$setudom,$title,$blocks);
5982: }
5983:
1.854 kalberla 5984: sub blocking_status {
1.1372 raeburn 5985: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5986: my %setters;
1.890 droeschl 5987:
1.1061 raeburn 5988: # check for active blocking
1.1372 raeburn 5989: if ($clientip eq '') {
5990: $clientip = &Apache::lonnet::get_requestor_ip();
5991: }
5992: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5993: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5994: my $blocked = 0;
1.1372 raeburn 5995: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5996: $blocked = 1;
5997: }
1.890 droeschl 5998:
1.1061 raeburn 5999: # caller just wants to know whether a block is active
6000: if (!wantarray) { return $blocked; }
6001:
6002: # build a link to a popup window containing the details
6003: my $querystring = "?activity=$activity";
1.1351 raeburn 6004: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
6005: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 6006: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
6007: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 6008: } elsif ($activity eq 'docs') {
1.1347 raeburn 6009: my $showurl = &Apache::lonenc::check_encrypt($url);
6010: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
6011: if ($symb) {
6012: my $showsymb = &Apache::lonenc::check_encrypt($symb);
6013: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
6014: }
1.1062 raeburn 6015: }
1.1061 raeburn 6016:
6017: my $output .= <<'END_MYBLOCK';
6018: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
6019: var options = "width=" + w + ",height=" + h + ",";
6020: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
6021: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
6022: var newWin = window.open(url, wdwName, options);
6023: newWin.focus();
6024: }
1.890 droeschl 6025: END_MYBLOCK
1.854 kalberla 6026:
1.1061 raeburn 6027: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 6028:
1.1061 raeburn 6029: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 6030: my $text = &mt('Communication Blocked');
1.1217 raeburn 6031: my $class = 'LC_comblock';
1.1062 raeburn 6032: if ($activity eq 'docs') {
6033: $text = &mt('Content Access Blocked');
1.1217 raeburn 6034: $class = '';
1.1063 raeburn 6035: } elsif ($activity eq 'printout') {
6036: $text = &mt('Printing Blocked');
1.1232 raeburn 6037: } elsif ($activity eq 'passwd') {
6038: $text = &mt('Password Changing Blocked');
1.1345 raeburn 6039: } elsif ($activity eq 'grades') {
6040: $text = &mt('Gradebook Blocked');
1.1346 raeburn 6041: } elsif ($activity eq 'search') {
6042: $text = &mt('Search Blocked');
1.1282 raeburn 6043: } elsif ($activity eq 'alert') {
6044: $text = &mt('Checking Critical Messages Blocked');
6045: } elsif ($activity eq 'reinit') {
6046: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 6047: } elsif ($activity eq 'about') {
6048: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 6049: } elsif ($activity eq 'wishlist') {
6050: $text = &mt('Access to Stored Links Blocked');
6051: } elsif ($activity eq 'annotate') {
6052: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 6053: }
1.1061 raeburn 6054: $output .= <<"END_BLOCK";
1.1217 raeburn 6055: <div class='$class'>
1.869 kalberla 6056: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6057: title='$text'>
6058: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 6059: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6060: title='$text'>$text</a>
1.867 kalberla 6061: </div>
6062:
6063: END_BLOCK
1.474 raeburn 6064:
1.1061 raeburn 6065: return ($blocked, $output);
1.854 kalberla 6066: }
1.490 raeburn 6067:
1.60 matthew 6068: ###############################################
6069:
1.682 raeburn 6070: sub check_ip_acc {
1.1201 raeburn 6071: my ($acc,$clientip)=@_;
1.682 raeburn 6072: &Apache::lonxml::debug("acc is $acc");
6073: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
6074: return 1;
6075: }
1.1339 raeburn 6076: my ($ip,$allowed);
6077: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
6078: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
6079: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
6080: } else {
1.1350 raeburn 6081: my $remote_ip = &Apache::lonnet::get_requestor_ip();
6082: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 6083: }
1.682 raeburn 6084:
6085: my $name;
1.1219 raeburn 6086: my %access = (
6087: allowfrom => 1,
6088: denyfrom => 0,
6089: );
6090: my @allows;
6091: my @denies;
6092: foreach my $item (split(',',$acc)) {
6093: $item =~ s/^\s*//;
6094: $item =~ s/\s*$//;
6095: my $pattern;
6096: if ($item =~ /^\!(.+)$/) {
6097: push(@denies,$1);
6098: } else {
6099: push(@allows,$item);
6100: }
6101: }
6102: my $numdenies = scalar(@denies);
6103: my $numallows = scalar(@allows);
6104: my $count = 0;
6105: foreach my $pattern (@denies,@allows) {
6106: $count ++;
6107: my $acctype = 'allowfrom';
6108: if ($count <= $numdenies) {
6109: $acctype = 'denyfrom';
6110: }
1.682 raeburn 6111: if ($pattern =~ /\*$/) {
6112: #35.8.*
6113: $pattern=~s/\*//;
1.1219 raeburn 6114: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6115: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6116: #35.8.3.[34-56]
6117: my $low=$2;
6118: my $high=$3;
6119: $pattern=$1;
6120: if ($ip =~ /^\Q$pattern\E/) {
6121: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6122: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6123: }
6124: } elsif ($pattern =~ /^\*/) {
6125: #*.msu.edu
6126: $pattern=~s/\*//;
6127: if (!defined($name)) {
6128: use Socket;
6129: my $netaddr=inet_aton($ip);
6130: ($name)=gethostbyaddr($netaddr,AF_INET);
6131: }
1.1219 raeburn 6132: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6133: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6134: #127.0.0.1
1.1219 raeburn 6135: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6136: } else {
6137: #some.name.com
6138: if (!defined($name)) {
6139: use Socket;
6140: my $netaddr=inet_aton($ip);
6141: ($name)=gethostbyaddr($netaddr,AF_INET);
6142: }
1.1219 raeburn 6143: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6144: }
6145: if ($allowed =~ /^(0|1)$/) { last; }
6146: }
6147: if ($allowed eq '') {
6148: if ($numdenies && !$numallows) {
6149: $allowed = 1;
6150: } else {
6151: $allowed = 0;
1.682 raeburn 6152: }
6153: }
6154: return $allowed;
6155: }
6156:
6157: ###############################################
6158:
1.60 matthew 6159: =pod
6160:
1.112 bowersj2 6161: =head1 Domain Template Functions
6162:
6163: =over 4
6164:
6165: =item * &determinedomain()
1.60 matthew 6166:
6167: Inputs: $domain (usually will be undef)
6168:
1.63 www 6169: Returns: Determines which domain should be used for designs
1.60 matthew 6170:
6171: =cut
1.54 www 6172:
1.60 matthew 6173: ###############################################
1.63 www 6174: sub determinedomain {
6175: my $domain=shift;
1.531 albertel 6176: if (! $domain) {
1.60 matthew 6177: # Determine domain if we have not been given one
1.893 raeburn 6178: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6179: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6180: if ($env{'request.role.domain'}) {
6181: $domain=$env{'request.role.domain'};
1.60 matthew 6182: }
6183: }
1.63 www 6184: return $domain;
6185: }
6186: ###############################################
1.517 raeburn 6187:
1.518 albertel 6188: sub devalidate_domconfig_cache {
6189: my ($udom)=@_;
6190: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6191: }
6192:
6193: # ---------------------- Get domain configuration for a domain
6194: sub get_domainconf {
6195: my ($udom) = @_;
6196: my $cachetime=1800;
6197: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6198: if (defined($cached)) { return %{$result}; }
6199:
6200: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6201: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6202: my (%designhash,%legacy);
1.518 albertel 6203: if (keys(%domconfig) > 0) {
6204: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6205: if (keys(%{$domconfig{'login'}})) {
6206: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6207: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6208: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6209: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6210: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6211: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6212: if ($key eq 'loginvia') {
6213: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6214: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6215: $designhash{$udom.'.login.loginvia'} = $server;
6216: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6217:
6218: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6219: } else {
6220: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6221: }
1.948 raeburn 6222: }
1.1208 raeburn 6223: } elsif ($key eq 'headtag') {
6224: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6225: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6226: }
1.946 raeburn 6227: }
1.1208 raeburn 6228: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6229: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6230: }
1.946 raeburn 6231: }
6232: }
6233: }
1.1366 raeburn 6234: } elsif ($key eq 'saml') {
6235: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6236: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6237: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6238: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6239: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6240: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6241: }
6242: }
6243: }
6244: }
1.946 raeburn 6245: } else {
6246: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6247: $designhash{$udom.'.login.'.$key.'_'.$img} =
6248: $domconfig{'login'}{$key}{$img};
6249: }
1.699 raeburn 6250: }
6251: } else {
6252: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6253: }
1.632 raeburn 6254: }
6255: } else {
6256: $legacy{'login'} = 1;
1.518 albertel 6257: }
1.632 raeburn 6258: } else {
6259: $legacy{'login'} = 1;
1.518 albertel 6260: }
6261: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6262: if (keys(%{$domconfig{'rolecolors'}})) {
6263: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6264: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6265: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6266: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6267: }
1.518 albertel 6268: }
6269: }
1.632 raeburn 6270: } else {
6271: $legacy{'rolecolors'} = 1;
1.518 albertel 6272: }
1.632 raeburn 6273: } else {
6274: $legacy{'rolecolors'} = 1;
1.518 albertel 6275: }
1.948 raeburn 6276: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6277: if ($domconfig{'autoenroll'}{'co-owners'}) {
6278: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6279: }
6280: }
1.632 raeburn 6281: if (keys(%legacy) > 0) {
6282: my %legacyhash = &get_legacy_domconf($udom);
6283: foreach my $item (keys(%legacyhash)) {
6284: if ($item =~ /^\Q$udom\E\.login/) {
6285: if ($legacy{'login'}) {
6286: $designhash{$item} = $legacyhash{$item};
6287: }
6288: } else {
6289: if ($legacy{'rolecolors'}) {
6290: $designhash{$item} = $legacyhash{$item};
6291: }
1.518 albertel 6292: }
6293: }
6294: }
1.632 raeburn 6295: } else {
6296: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6297: }
6298: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6299: $cachetime);
6300: return %designhash;
6301: }
6302:
1.632 raeburn 6303: sub get_legacy_domconf {
6304: my ($udom) = @_;
6305: my %legacyhash;
6306: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6307: my $designfile = $designdir.'/'.$udom.'.tab';
6308: if (-e $designfile) {
1.1317 raeburn 6309: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6310: while (my $line = <$fh>) {
6311: next if ($line =~ /^\#/);
6312: chomp($line);
6313: my ($key,$val)=(split(/\=/,$line));
6314: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6315: }
6316: close($fh);
6317: }
6318: }
1.1026 raeburn 6319: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6320: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6321: }
6322: return %legacyhash;
6323: }
6324:
1.63 www 6325: =pod
6326:
1.112 bowersj2 6327: =item * &domainlogo()
1.63 www 6328:
6329: Inputs: $domain (usually will be undef)
6330:
6331: Returns: A link to a domain logo, if the domain logo exists.
6332: If the domain logo does not exist, a description of the domain.
6333:
6334: =cut
1.112 bowersj2 6335:
1.63 www 6336: ###############################################
6337: sub domainlogo {
1.517 raeburn 6338: my $domain = &determinedomain(shift);
1.518 albertel 6339: my %designhash = &get_domainconf($domain);
1.517 raeburn 6340: # See if there is a logo
6341: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6342: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6343: if ($imgsrc =~ m{^/(adm|res)/}) {
6344: if ($imgsrc =~ m{^/res/}) {
6345: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6346: &Apache::lonnet::repcopy($local_name);
6347: }
6348: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6349: }
6350: my $alttext = $domain;
6351: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6352: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6353: }
6354: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6355: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6356: return &Apache::lonnet::domain($domain,'description');
1.59 www 6357: } else {
1.60 matthew 6358: return '';
1.59 www 6359: }
6360: }
1.63 www 6361: ##############################################
6362:
6363: =pod
6364:
1.112 bowersj2 6365: =item * &designparm()
1.63 www 6366:
6367: Inputs: $which parameter; $domain (usually will be undef)
6368:
6369: Returns: value of designparamter $which
6370:
6371: =cut
1.112 bowersj2 6372:
1.397 albertel 6373:
1.400 albertel 6374: ##############################################
1.397 albertel 6375: sub designparm {
6376: my ($which,$domain)=@_;
6377: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6378: return $env{'environment.color.'.$which};
1.96 www 6379: }
1.63 www 6380: $domain=&determinedomain($domain);
1.1016 raeburn 6381: my %domdesign;
6382: unless ($domain eq 'public') {
6383: %domdesign = &get_domainconf($domain);
6384: }
1.520 raeburn 6385: my $output;
1.517 raeburn 6386: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6387: $output = $domdesign{$domain.'.'.$which};
1.63 www 6388: } else {
1.520 raeburn 6389: $output = $defaultdesign{$which};
6390: }
6391: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6392: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6393: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6394: if ($output =~ m{^/res/}) {
6395: my $local_name = &Apache::lonnet::filelocation('',$output);
6396: &Apache::lonnet::repcopy($local_name);
6397: }
1.520 raeburn 6398: $output = &lonhttpdurl($output);
6399: }
1.63 www 6400: }
1.520 raeburn 6401: return $output;
1.63 www 6402: }
1.59 www 6403:
1.822 bisitz 6404: ##############################################
6405: =pod
6406:
1.832 bisitz 6407: =item * &authorspace()
6408:
1.1028 raeburn 6409: Inputs: $url (usually will be undef).
1.832 bisitz 6410:
1.1132 raeburn 6411: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6412: directory being viewed (or for which action is being taken).
6413: If $url is provided, and begins /priv/<domain>/<uname>
6414: the path will be that portion of the $context argument.
6415: Otherwise the path will be for the author space of the current
6416: user when the current role is author, or for that of the
6417: co-author/assistant co-author space when the current role
6418: is co-author or assistant co-author.
1.832 bisitz 6419:
6420: =cut
6421:
6422: sub authorspace {
1.1028 raeburn 6423: my ($url) = @_;
6424: if ($url ne '') {
6425: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6426: return $1;
6427: }
6428: }
1.832 bisitz 6429: my $caname = '';
1.1024 www 6430: my $cadom = '';
1.1028 raeburn 6431: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6432: ($cadom,$caname) =
1.832 bisitz 6433: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6434: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6435: $caname = $env{'user.name'};
1.1024 www 6436: $cadom = $env{'user.domain'};
1.832 bisitz 6437: }
1.1028 raeburn 6438: if (($caname ne '') && ($cadom ne '')) {
6439: return "/priv/$cadom/$caname/";
6440: }
6441: return;
1.832 bisitz 6442: }
6443:
6444: ##############################################
6445: =pod
6446:
1.822 bisitz 6447: =item * &head_subbox()
6448:
6449: Inputs: $content (contains HTML code with page functions, etc.)
6450:
6451: Returns: HTML div with $content
6452: To be included in page header
6453:
6454: =cut
6455:
6456: sub head_subbox {
6457: my ($content)=@_;
6458: my $output =
1.993 raeburn 6459: '<div class="LC_head_subbox">'
1.822 bisitz 6460: .$content
6461: .'</div>'
6462: }
6463:
6464: ##############################################
6465: =pod
6466:
6467: =item * &CSTR_pageheader()
6468:
1.1026 raeburn 6469: Input: (optional) filename from which breadcrumb trail is built.
6470: In most cases no input as needed, as $env{'request.filename'}
6471: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6472: frameset flag
6473: If page header is being requested for use in a frameset, then
6474: the second (option) argument -- frameset will be true, and
6475: the target attribute set for links should be target="_parent".
1.1407 raeburn 6476: If $title is supplied as the thitd arg, that will be used to
6477: the left of the breadcrumbs tail for the current path.
1.822 bisitz 6478:
6479: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6480: To be included on Authoring Space pages
1.822 bisitz 6481:
6482: =cut
6483:
6484: sub CSTR_pageheader {
1.1407 raeburn 6485: my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 6486: if ($trailfile eq '') {
6487: $trailfile = $env{'request.filename'};
6488: }
6489:
6490: # this is for resources; directories have customtitle, and crumbs
6491: # and select recent are created in lonpubdir.pm
6492:
6493: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6494: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6495: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6496: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6497: $formaction =~ s{/+}{/}g;
1.822 bisitz 6498:
6499: my $parentpath = '';
6500: my $lastitem = '';
6501: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6502: $parentpath = $1;
6503: $lastitem = $2;
6504: } else {
6505: $lastitem = $thisdisfn;
6506: }
1.921 bisitz 6507:
1.1406 raeburn 6508: my $crsauthor;
1.1246 raeburn 6509: if (($env{'request.course.id'}) &&
6510: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6511: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6512: $crsauthor = 1;
1.1406 raeburn 6513: if ($title eq '') {
6514: $title = &mt('Course Authoring Space');
6515: }
6516: } elsif ($title eq '') {
1.1246 raeburn 6517: $title = &mt('Authoring Space');
6518: }
6519:
1.1379 raeburn 6520: my ($target,$crumbtarget) = (' target="_top"','_top');
6521: if ($frameset) {
6522: $target = ' target="_parent"';
6523: $crumbtarget = '_parent';
6524: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6525: $target = '';
6526: $crumbtarget = '';
1.1379 raeburn 6527: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6528: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6529: $crumbtarget = $env{'request.deeplink.target'};
6530: }
1.1313 raeburn 6531:
1.921 bisitz 6532: my $output =
1.1407 raeburn 6533: '<div>'
1.822 bisitz 6534: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6535: .'<b>'.$title.'</b> '
1.1314 raeburn 6536: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6537: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6538:
6539: if ($lastitem) {
6540: $output .=
6541: '<span class="LC_filename">'
6542: .$lastitem
6543: .'</span>';
6544: }
1.1245 raeburn 6545:
1.1246 raeburn 6546: if ($crsauthor) {
1.1379 raeburn 6547: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6548: } else {
6549: $output .=
6550: '<br />'
1.1314 raeburn 6551: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6552: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6553: .'</form>'
1.1379 raeburn 6554: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6555: }
1.1407 raeburn 6556: $output .= '</div>';
1.921 bisitz 6557:
6558: return $output;
1.822 bisitz 6559: }
6560:
1.1419 raeburn 6561: ##############################################
6562: =pod
6563:
6564: =item * &nocodemirror()
6565:
6566: Input: None
6567:
6568: Returns: 1 if CodeMirror is deactivated based on
6569: user's preference, or domain default,
6570: if user indicated use of default.
6571:
6572: =cut
6573:
1.1416 raeburn 6574: sub nocodemirror {
6575: my $nocodem = $env{'environment.nocodemirror'};
6576: unless ($nocodem) {
6577: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6578: if ($domdefs{'nocodemirror'}) {
6579: $nocodem = 'yes';
6580: }
6581: }
1.1417 raeburn 6582: if ($nocodem eq 'yes') {
6583: return 1;
6584: }
6585: return;
1.1416 raeburn 6586: }
6587:
1.1419 raeburn 6588: ##############################################
6589: =pod
6590:
6591: =item * &permitted_editors()
6592:
6593: Input: None
6594:
6595: Returns: %editors hash in which keys are editors
6596: permitted in current Authoring Space.
6597: Value for each key is 1. Possible keys
6598: are: edit, xml, and daxe. If no specific
6599: set of editors has been set for the Author
6600: who owns the Authoring Space, then the
6601: domain default will be used. If no domain
6602: default has been set, then the keys will be
6603: edit and xml.
6604:
6605: =cut
6606:
1.1418 raeburn 6607: sub permitted_editors {
6608: my ($is_author,$is_coauthor,$auname,$audom,%editors);
6609: if ($env{'request.role'} =~ m{^au\./}) {
6610: $is_author = 1;
6611: } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6612: ($audom,$auname) = ($1,$2);
6613: if (($audom ne '') && ($auname ne '')) {
6614: if (($env{'user.domain'} eq $audom) &&
6615: ($env{'user.name'} eq $auname)) {
6616: $is_author = 1;
6617: } else {
6618: $is_coauthor = 1;
6619: }
6620: }
6621: } elsif ($env{'request.course.id'}) {
6622: if ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6623: ($audom,$auname) = ($1,$2);
6624: } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6625: ($audom,$auname) = ($1,$2);
6626: }
6627: if (($audom ne '') && ($auname ne '')) {
6628: if (($env{'user.domain'} eq $audom) &&
6629: ($env{'user.name'} eq $auname)) {
6630: $is_author = 1;
6631: } else {
6632: $is_coauthor = 1;
6633: }
6634: }
6635: }
6636: if ($is_author) {
6637: if (exists($env{'environment.editors'})) {
6638: map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6639: } else {
6640: %editors = ( edit => 1,
6641: xml => 1,
6642: );
6643: }
6644: } elsif ($is_coauthor) {
6645: if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6646: map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6647: } else {
6648: %editors = ( edit => 1,
6649: xml => 1,
6650: );
6651: }
6652: } else {
6653: %editors = ( edit => 1,
6654: xml => 1,
6655: );
6656: }
6657: return %editors;
6658: }
6659:
1.60 matthew 6660: ###############################################
6661: ###############################################
6662:
6663: =pod
6664:
1.112 bowersj2 6665: =back
6666:
1.549 albertel 6667: =head1 HTML Helpers
1.112 bowersj2 6668:
6669: =over 4
6670:
6671: =item * &bodytag()
1.60 matthew 6672:
6673: Returns a uniform header for LON-CAPA web pages.
6674:
6675: Inputs:
6676:
1.112 bowersj2 6677: =over 4
6678:
6679: =item * $title, A title to be displayed on the page.
6680:
6681: =item * $function, the current role (can be undef).
6682:
6683: =item * $addentries, extra parameters for the <body> tag.
6684:
6685: =item * $bodyonly, if defined, only return the <body> tag.
6686:
6687: =item * $domain, if defined, force a given domain.
6688:
6689: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6690: text interface only)
1.60 matthew 6691:
1.814 bisitz 6692: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6693: navigational links
1.317 albertel 6694:
1.338 albertel 6695: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6696:
1.460 albertel 6697: =item * $args, optional argument valid values are
6698: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6699: use_absolute -> for external resource or syllabus, this will
6700: contain https://<hostname> if server uses
6701: https (as per hosts.tab), but request is for http
6702: hostname -> hostname, from $r->hostname().
1.460 albertel 6703:
1.1096 raeburn 6704: =item * $advtoolsref, optional argument, ref to an array containing
6705: inlineremote items to be added in "Functions" menu below
6706: breadcrumbs.
6707:
1.1316 raeburn 6708: =item * $ltiscope, optional argument, will be one of: resource, map or
6709: course, if LON-CAPA is in LTI Provider context. Value is
6710: the scope of use, i.e., launch was for access to a single, a map
6711: or the entire course.
6712:
6713: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6714: context, this will contain the URL for the landing item in
6715: the course, after launch from an LTI Consumer
6716:
1.1318 raeburn 6717: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6718: context, this will contain a reference to hash of items
6719: to be included in the page header and/or inline menu.
6720:
1.1385 raeburn 6721: =item * $menucoll, optional argument, if specific menu collection is in
6722: effect, either set as the default for the course, or set for
6723: the deeplink paramater for $env{'request.deeplink.login'}
6724: then $menucoll will be the number of that collection.
6725:
6726: =item * $menuref, optional argument, reference to a hash, containing the
6727: menu options included for the menu in effect, based on the
6728: configuration for the numbered menu collection in use.
6729:
6730: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6731: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6732: if so, $showncrumbsref is set there to 1, and will propagate back
6733: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6734: being called a second time.
6735:
1.112 bowersj2 6736: =back
6737:
1.60 matthew 6738: Returns: A uniform header for LON-CAPA web pages.
6739: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6740: If $bodyonly is undef or zero, an html string containing a <body> tag and
6741: other decorations will be returned.
6742:
6743: =cut
6744:
1.54 www 6745: sub bodytag {
1.831 bisitz 6746: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6747: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6748: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6749:
1.954 raeburn 6750: my $public;
6751: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6752: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6753: $public = 1;
6754: }
1.460 albertel 6755: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6756: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6757: my $hostname = $args->{'hostname'};
1.339 albertel 6758:
1.183 matthew 6759: $function = &get_users_function() if (!$function);
1.339 albertel 6760: my $img = &designparm($function.'.img',$domain);
6761: my $font = &designparm($function.'.font',$domain);
6762: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6763:
1.803 bisitz 6764: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6765: 'bgcolor' => $pgbg,
1.339 albertel 6766: 'text' => $font,
6767: 'alink' => &designparm($function.'.alink',$domain),
6768: 'vlink' => &designparm($function.'.vlink',$domain),
6769: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6770: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6771:
1.63 www 6772: # role and realm
1.1178 raeburn 6773: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6774: if ($realm) {
6775: $realm = '/'.$realm;
6776: }
1.1357 raeburn 6777: if ($role eq 'ca') {
1.479 albertel 6778: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6779: $realm = &plainname($rname,$rdom);
1.378 raeburn 6780: }
1.55 www 6781: # realm
1.1357 raeburn 6782: my ($cid,$sec);
1.258 albertel 6783: if ($env{'request.course.id'}) {
1.1357 raeburn 6784: $cid = $env{'request.course.id'};
6785: if ($env{'request.course.sec'}) {
6786: $sec = $env{'request.course.sec'};
6787: }
6788: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6789: if (&Apache::lonnet::is_course($1,$2)) {
6790: $cid = $1.'_'.$2;
6791: $sec = $3;
6792: }
6793: }
6794: if ($cid) {
1.378 raeburn 6795: if ($env{'request.role'} !~ /^cr/) {
6796: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6797: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6798: if ($env{'request.role.desc'}) {
6799: $role = $env{'request.role.desc'};
6800: } else {
6801: $role = &mt('Helpdesk[_1]',' '.$2);
6802: }
1.1257 raeburn 6803: } else {
6804: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6805: }
1.1357 raeburn 6806: if ($sec) {
6807: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6808: }
1.1357 raeburn 6809: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6810: } else {
6811: $role = &Apache::lonnet::plaintext($role);
1.54 www 6812: }
1.433 albertel 6813:
1.359 albertel 6814: if (!$realm) { $realm=' '; }
1.330 albertel 6815:
1.438 albertel 6816: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6817:
1.101 www 6818: # construct main body tag
1.359 albertel 6819: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6820: &Apache::lontexconvert::init_math_support();
1.252 albertel 6821:
1.1131 raeburn 6822: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6823:
1.1130 raeburn 6824: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6825: return $bodytag;
1.1130 raeburn 6826: }
1.359 albertel 6827:
1.954 raeburn 6828: if ($public) {
1.433 albertel 6829: undef($role);
6830: }
1.1318 raeburn 6831:
1.1359 raeburn 6832: my $showcrstitle = 1;
1.1357 raeburn 6833: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6834: if (ref($ltimenu) eq 'HASH') {
6835: unless ($ltimenu->{'role'}) {
6836: undef($role);
6837: }
6838: unless ($ltimenu->{'coursetitle'}) {
6839: $realm=' ';
1.1359 raeburn 6840: $showcrstitle = 0;
6841: }
6842: }
6843: } elsif (($cid) && ($menucoll)) {
6844: if (ref($menuref) eq 'HASH') {
6845: unless ($menuref->{'role'}) {
6846: undef($role);
6847: }
6848: unless ($menuref->{'crs'}) {
6849: $realm=' ';
6850: $showcrstitle = 0;
1.1318 raeburn 6851: }
6852: }
6853: }
6854:
1.762 bisitz 6855: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6856: #
6857: # Extra info if you are the DC
6858: my $dc_info = '';
1.1359 raeburn 6859: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6860: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6861: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6862: $dc_info =~ s/\s+$//;
1.359 albertel 6863: }
6864:
1.1237 raeburn 6865: my $crstype;
1.1357 raeburn 6866: if ($cid) {
6867: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6868: } elsif ($args->{'crstype'}) {
6869: $crstype = $args->{'crstype'};
6870: }
6871: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6872: undef($role);
6873: } else {
1.1242 raeburn 6874: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6875: }
1.853 droeschl 6876:
1.903 droeschl 6877: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6878:
6879: # if ($env{'request.state'} eq 'construct') {
6880: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6881: # }
6882:
1.1130 raeburn 6883: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6884: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6885:
1.1421 ! raeburn 6886: if ($args->{'collapsible_header'}) {
! 6887: my $alttext = &mt('menu state: collapsed');
! 6888: my $tooltip = &mt('display standard menus');
! 6889: $bodytag .= <<"END";
! 6890: <div id="LC_expandingContainer" style="display:inline;">
! 6891: <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
! 6892: <a href="#" style="text-decoration:none;"><img class="LC_collapsible_indicator" alt="$alttext" title="$tooltip" src="/res/adm/pages/collapsed.png" style="border:0;margin:0;padding:0;max-width:100%;height:auto" /></a></div>
! 6893: <div class="LC_menus_content hidden">
! 6894: END
! 6895: }
1.1318 raeburn 6896: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6897: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 6898: $args->{'links_disabled'},
1.1421 ! raeburn 6899: $args->{'links_target'},
! 6900: $args->{'collapsible_header'});
1.359 albertel 6901:
1.1318 raeburn 6902: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6903: if ($dc_info) {
6904: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6905: }
6906: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6907: <em>$realm</em> $dc_info</div>|;
6908: return $bodytag;
6909: }
1.894 droeschl 6910:
1.1318 raeburn 6911: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6912: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6913: }
1.916 droeschl 6914:
1.1318 raeburn 6915: $bodytag .= $right;
1.852 droeschl 6916:
1.1318 raeburn 6917: if ($dc_info) {
6918: $dc_info = &dc_courseid_toggle($dc_info);
6919: }
6920: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6921: }
1.916 droeschl 6922:
1.1169 raeburn 6923: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6924: if ($args->{'no_secondary_menu'}) {
6925: return $bodytag;
6926: }
1.1169 raeburn 6927: #don't show menus for public users
1.954 raeburn 6928: if (!$public){
1.1318 raeburn 6929: unless ($args->{'no_inline_menu'}) {
6930: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6931: $args->{'no_primary_menu'},
1.1369 raeburn 6932: $menucoll,$menuref,
1.1380 raeburn 6933: $args->{'links_disabled'},
6934: $args->{'links_target'});
1.1318 raeburn 6935: }
1.903 droeschl 6936: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6937: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6938: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6939: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 6940: $args->{'bread_crumbs'},'','',$hostname,
6941: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6942: } elsif ($forcereg) {
6943: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 6944: $args->{'group'},$args->{'hide_buttons'},
6945: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6946: } else {
6947: $bodytag .=
6948: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6949: $forcereg,$args->{'group'},
6950: $args->{'bread_crumbs'},
1.1274 raeburn 6951: $advtoolsref,'',$hostname);
1.920 raeburn 6952: }
1.903 droeschl 6953: }else{
6954: # this is to seperate menu from content when there's no secondary
6955: # menu. Especially needed for public accessible ressources.
6956: $bodytag .= '<hr style="clear:both" />';
6957: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6958: }
1.1421 ! raeburn 6959: if ($args->{'collapsible_header'}) {
! 6960: $bodytag .= '<div id="LC_collapsible_separator"></div>'.
! 6961: '</div></div>';
! 6962: }
1.235 raeburn 6963: return $bodytag;
1.182 matthew 6964: }
6965:
1.917 raeburn 6966: sub dc_courseid_toggle {
6967: my ($dc_info) = @_;
1.980 raeburn 6968: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6969: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6970: &mt('(More ...)').'</a></span>'.
6971: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6972: }
6973:
1.330 albertel 6974: sub make_attr_string {
6975: my ($register,$attr_ref) = @_;
6976:
6977: if ($attr_ref && !ref($attr_ref)) {
6978: die("addentries Must be a hash ref ".
6979: join(':',caller(1))." ".
6980: join(':',caller(0))." ");
6981: }
6982:
6983: if ($register) {
1.339 albertel 6984: my ($on_load,$on_unload);
6985: foreach my $key (keys(%{$attr_ref})) {
6986: if (lc($key) eq 'onload') {
6987: $on_load.=$attr_ref->{$key}.';';
6988: delete($attr_ref->{$key});
6989:
6990: } elsif (lc($key) eq 'onunload') {
6991: $on_unload.=$attr_ref->{$key}.';';
6992: delete($attr_ref->{$key});
6993: }
6994: }
1.953 droeschl 6995: $attr_ref->{'onload'} = $on_load;
6996: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6997: }
1.339 albertel 6998:
1.330 albertel 6999: my $attr_string;
1.1159 raeburn 7000: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 7001: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
7002: }
7003: return $attr_string;
7004: }
7005:
7006:
1.182 matthew 7007: ###############################################
1.251 albertel 7008: ###############################################
7009:
7010: =pod
7011:
7012: =item * &endbodytag()
7013:
7014: Returns a uniform footer for LON-CAPA web pages.
7015:
1.635 raeburn 7016: Inputs: 1 - optional reference to an args hash
7017: If in the hash, key for noredirectlink has a value which evaluates to true,
7018: a 'Continue' link is not displayed if the page contains an
7019: internal redirect in the <head></head> section,
7020: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 7021:
7022: =cut
7023:
7024: sub endbodytag {
1.635 raeburn 7025: my ($args) = @_;
1.1080 raeburn 7026: my $endbodytag;
7027: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
7028: $endbodytag='</body>';
7029: }
1.315 albertel 7030: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 7031: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 7032: my ($endbodyjs,$idattr);
7033: if ($env{'internal.head.to_opener'}) {
7034: my $linkid = 'LC_continue_link';
7035: $idattr = ' id="'.$linkid.'"';
7036: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
7037: $endbodyjs=<<ENDJS;
7038: <script type="text/javascript">
7039: // <![CDATA[
7040: function ebFunction(evt) {
7041: evt.preventDefault();
7042: var dest = '$redirect_for_js';
7043: if (window.opener != null && !window.opener.closed) {
7044: window.opener.location.href=dest;
7045: window.close();
7046: } else {
7047: window.location.href=dest;
7048: }
7049: return false;
7050: }
7051:
7052: \$(document).ready(function () {
7053: if (document.getElementById('$linkid')) {
7054: var clickelem = document.getElementById('$linkid');
7055: clickelem.addEventListener('click',ebFunction,false);
7056: }
7057: });
7058: // ]]>
7059: </script>
7060: ENDJS
7061: }
1.635 raeburn 7062: $endbodytag=
1.1386 raeburn 7063: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 7064: &mt('Continue').'</a>'.
7065: $endbodytag;
7066: }
1.315 albertel 7067: }
1.1411 raeburn 7068: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
7069: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
7070: }
1.251 albertel 7071: return $endbodytag;
7072: }
7073:
1.352 albertel 7074: =pod
7075:
7076: =item * &standard_css()
7077:
7078: Returns a style sheet
7079:
7080: Inputs: (all optional)
7081: domain -> force to color decorate a page for a specific
7082: domain
7083: function -> force usage of a specific rolish color scheme
7084: bgcolor -> override the default page bgcolor
7085:
7086: =cut
7087:
1.343 albertel 7088: sub standard_css {
1.345 albertel 7089: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 7090: $function = &get_users_function() if (!$function);
7091: my $img = &designparm($function.'.img', $domain);
7092: my $tabbg = &designparm($function.'.tabbg', $domain);
7093: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 7094: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 7095: #second colour for later usage
1.345 albertel 7096: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 7097: my $pgbg_or_bgcolor =
7098: $bgcolor ||
1.352 albertel 7099: &designparm($function.'.pgbg', $domain);
1.382 albertel 7100: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 7101: my $alink = &designparm($function.'.alink', $domain);
7102: my $vlink = &designparm($function.'.vlink', $domain);
7103: my $link = &designparm($function.'.link', $domain);
7104:
1.602 albertel 7105: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 7106: my $mono = 'monospace';
1.850 bisitz 7107: my $data_table_head = $sidebg;
7108: my $data_table_light = '#FAFAFA';
1.1060 bisitz 7109: my $data_table_dark = '#E0E0E0';
1.470 banghart 7110: my $data_table_darker = '#CCCCCC';
1.349 albertel 7111: my $data_table_highlight = '#FFFF00';
1.352 albertel 7112: my $mail_new = '#FFBB77';
7113: my $mail_new_hover = '#DD9955';
7114: my $mail_read = '#BBBB77';
7115: my $mail_read_hover = '#999944';
7116: my $mail_replied = '#AAAA88';
7117: my $mail_replied_hover = '#888855';
7118: my $mail_other = '#99BBBB';
7119: my $mail_other_hover = '#669999';
1.391 albertel 7120: my $table_header = '#DDDDDD';
1.489 raeburn 7121: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 7122: my $lg_border_color = '#C8C8C8';
1.952 onken 7123: my $button_hover = '#BF2317';
1.392 albertel 7124:
1.608 albertel 7125: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 7126: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
7127: : '0 3px 0 4px';
1.448 albertel 7128:
1.523 albertel 7129:
1.343 albertel 7130: return <<END;
1.947 droeschl 7131:
7132: /* needed for iframe to allow 100% height in FF */
7133: body, html {
7134: margin: 0;
7135: padding: 0 0.5%;
7136: height: 99%; /* to avoid scrollbars */
7137: }
7138:
1.795 www 7139: body {
1.911 bisitz 7140: font-family: $sans;
7141: line-height:130%;
7142: font-size:0.83em;
7143: color:$font;
1.795 www 7144: }
7145:
1.959 onken 7146: a:focus,
7147: a:focus img {
1.795 www 7148: color: red;
7149: }
1.698 harmsja 7150:
1.911 bisitz 7151: form, .inline {
7152: display: inline;
1.795 www 7153: }
1.721 harmsja 7154:
1.1421 ! raeburn 7155: .LC_menus_content.shown{
! 7156: display: inline;
! 7157: }
! 7158:
! 7159: .LC_menus_content.hidden {
! 7160: display: none;
! 7161: }
! 7162:
1.795 www 7163: .LC_right {
1.911 bisitz 7164: text-align:right;
1.795 www 7165: }
7166:
7167: .LC_middle {
1.911 bisitz 7168: vertical-align:middle;
1.795 www 7169: }
1.721 harmsja 7170:
1.1130 raeburn 7171: .LC_floatleft {
7172: float: left;
7173: }
7174:
7175: .LC_floatright {
7176: float: right;
7177: }
7178:
1.911 bisitz 7179: .LC_400Box {
7180: width:400px;
7181: }
1.721 harmsja 7182:
1.1421 ! raeburn 7183: #LC_collapsible_separator {
! 7184: border: 1px solid black;
! 7185: width: 99.9%;
! 7186: height: 0px;
! 7187: }
! 7188:
1.947 droeschl 7189: .LC_iframecontainer {
7190: width: 98%;
7191: margin: 0;
7192: position: fixed;
7193: top: 8.5em;
7194: bottom: 0;
7195: }
7196:
7197: .LC_iframecontainer iframe{
7198: border: none;
7199: width: 100%;
7200: height: 100%;
7201: }
7202:
1.778 bisitz 7203: .LC_filename {
7204: font-family: $mono;
7205: white-space:pre;
1.921 bisitz 7206: font-size: 120%;
1.778 bisitz 7207: }
7208:
7209: .LC_fileicon {
7210: border: none;
7211: height: 1.3em;
7212: vertical-align: text-bottom;
7213: margin-right: 0.3em;
7214: text-decoration:none;
7215: }
7216:
1.1008 www 7217: .LC_setting {
7218: text-decoration:underline;
7219: }
7220:
1.350 albertel 7221: .LC_error {
7222: color: red;
7223: }
1.795 www 7224:
1.1097 bisitz 7225: .LC_warning {
7226: color: darkorange;
7227: }
7228:
1.457 albertel 7229: .LC_diff_removed {
1.733 bisitz 7230: color: red;
1.394 albertel 7231: }
1.532 albertel 7232:
7233: .LC_info,
1.457 albertel 7234: .LC_success,
7235: .LC_diff_added {
1.350 albertel 7236: color: green;
7237: }
1.795 www 7238:
1.802 bisitz 7239: div.LC_confirm_box {
7240: background-color: #FAFAFA;
7241: border: 1px solid $lg_border_color;
7242: margin-right: 0;
7243: padding: 5px;
7244: }
7245:
7246: div.LC_confirm_box .LC_error img,
7247: div.LC_confirm_box .LC_success img {
7248: vertical-align: middle;
7249: }
7250:
1.1242 raeburn 7251: .LC_maxwidth {
7252: max-width: 100%;
7253: height: auto;
7254: }
7255:
1.1243 raeburn 7256: .LC_textsize_mobile {
7257: \@media only screen and (max-device-width: 480px) {
7258: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7259: }
7260: }
7261:
1.440 albertel 7262: .LC_icon {
1.771 droeschl 7263: border: none;
1.790 droeschl 7264: vertical-align: middle;
1.771 droeschl 7265: }
7266:
1.543 albertel 7267: .LC_docs_spacer {
7268: width: 25px;
7269: height: 1px;
1.771 droeschl 7270: border: none;
1.543 albertel 7271: }
1.346 albertel 7272:
1.532 albertel 7273: .LC_internal_info {
1.735 bisitz 7274: color: #999999;
1.532 albertel 7275: }
7276:
1.794 www 7277: .LC_discussion {
1.1050 www 7278: background: $data_table_dark;
1.911 bisitz 7279: border: 1px solid black;
7280: margin: 2px;
1.794 www 7281: }
7282:
7283: .LC_disc_action_left {
1.1050 www 7284: background: $sidebg;
1.911 bisitz 7285: text-align: left;
1.1050 www 7286: padding: 4px;
7287: margin: 2px;
1.794 www 7288: }
7289:
7290: .LC_disc_action_right {
1.1050 www 7291: background: $sidebg;
1.911 bisitz 7292: text-align: right;
1.1050 www 7293: padding: 4px;
7294: margin: 2px;
1.794 www 7295: }
7296:
7297: .LC_disc_new_item {
1.911 bisitz 7298: background: white;
7299: border: 2px solid red;
1.1050 www 7300: margin: 4px;
7301: padding: 4px;
1.794 www 7302: }
7303:
7304: .LC_disc_old_item {
1.911 bisitz 7305: background: white;
1.1050 www 7306: margin: 4px;
7307: padding: 4px;
1.794 www 7308: }
7309:
1.458 albertel 7310: table.LC_pastsubmission {
7311: border: 1px solid black;
7312: margin: 2px;
7313: }
7314:
1.924 bisitz 7315: table#LC_menubuttons {
1.345 albertel 7316: width: 100%;
7317: background: $pgbg;
1.392 albertel 7318: border: 2px;
1.402 albertel 7319: border-collapse: separate;
1.803 bisitz 7320: padding: 0;
1.345 albertel 7321: }
1.392 albertel 7322:
1.801 tempelho 7323: table#LC_title_bar a {
7324: color: $fontmenu;
7325: }
1.836 bisitz 7326:
1.807 droeschl 7327: table#LC_title_bar {
1.819 tempelho 7328: clear: both;
1.836 bisitz 7329: display: none;
1.807 droeschl 7330: }
7331:
1.795 www 7332: table#LC_title_bar,
1.933 droeschl 7333: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7334: table#LC_title_bar.LC_with_remote {
1.359 albertel 7335: width: 100%;
1.392 albertel 7336: border-color: $pgbg;
7337: border-style: solid;
7338: border-width: $border;
1.379 albertel 7339: background: $pgbg;
1.801 tempelho 7340: color: $fontmenu;
1.392 albertel 7341: border-collapse: collapse;
1.803 bisitz 7342: padding: 0;
1.819 tempelho 7343: margin: 0;
1.359 albertel 7344: }
1.795 www 7345:
1.933 droeschl 7346: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7347: margin: 0;
7348: padding: 0;
1.933 droeschl 7349: position: relative;
7350: list-style: none;
1.913 droeschl 7351: }
1.933 droeschl 7352: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7353: display: inline;
7354: }
1.933 droeschl 7355:
7356: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7357: padding: 0;
1.933 droeschl 7358: margin: 0;
7359: float: left;
1.913 droeschl 7360: }
1.933 droeschl 7361: .LC_breadcrumb_tools_tools {
7362: padding: 0;
7363: margin: 0;
1.913 droeschl 7364: float: right;
7365: }
7366:
1.1240 raeburn 7367: .LC_placement_prog {
7368: padding-right: 20px;
7369: font-weight: bold;
7370: font-size: 90%;
7371: }
7372:
1.359 albertel 7373: table#LC_title_bar td {
7374: background: $tabbg;
7375: }
1.795 www 7376:
1.911 bisitz 7377: table#LC_menubuttons img {
1.803 bisitz 7378: border: none;
1.346 albertel 7379: }
1.795 www 7380:
1.842 droeschl 7381: .LC_breadcrumbs_component {
1.911 bisitz 7382: float: right;
7383: margin: 0 1em;
1.357 albertel 7384: }
1.842 droeschl 7385: .LC_breadcrumbs_component img {
1.911 bisitz 7386: vertical-align: middle;
1.777 tempelho 7387: }
1.795 www 7388:
1.1243 raeburn 7389: .LC_breadcrumbs_hoverable {
7390: background: $sidebg;
7391: }
7392:
1.383 albertel 7393: td.LC_table_cell_checkbox {
7394: text-align: center;
7395: }
1.795 www 7396:
7397: .LC_fontsize_small {
1.911 bisitz 7398: font-size: 70%;
1.705 tempelho 7399: }
7400:
1.844 bisitz 7401: #LC_breadcrumbs {
1.911 bisitz 7402: clear:both;
7403: background: $sidebg;
7404: border-bottom: 1px solid $lg_border_color;
7405: line-height: 2.5em;
1.933 droeschl 7406: overflow: hidden;
1.911 bisitz 7407: margin: 0;
7408: padding: 0;
1.995 raeburn 7409: text-align: left;
1.819 tempelho 7410: }
1.862 bisitz 7411:
1.1098 bisitz 7412: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7413: clear:both;
7414: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7415: border: 1px solid $sidebg;
1.1098 bisitz 7416: margin: 0 0 10px 0;
1.966 bisitz 7417: padding: 3px;
1.995 raeburn 7418: text-align: left;
1.822 bisitz 7419: }
7420:
1.795 www 7421: .LC_fontsize_medium {
1.911 bisitz 7422: font-size: 85%;
1.705 tempelho 7423: }
7424:
1.795 www 7425: .LC_fontsize_large {
1.911 bisitz 7426: font-size: 120%;
1.705 tempelho 7427: }
7428:
1.346 albertel 7429: .LC_menubuttons_inline_text {
7430: color: $font;
1.698 harmsja 7431: font-size: 90%;
1.701 harmsja 7432: padding-left:3px;
1.346 albertel 7433: }
7434:
1.934 droeschl 7435: .LC_menubuttons_inline_text img{
7436: vertical-align: middle;
7437: }
7438:
1.1051 www 7439: li.LC_menubuttons_inline_text img {
1.951 onken 7440: cursor:pointer;
1.1002 droeschl 7441: text-decoration: none;
1.951 onken 7442: }
7443:
1.526 www 7444: .LC_menubuttons_link {
7445: text-decoration: none;
7446: }
1.795 www 7447:
1.522 albertel 7448: .LC_menubuttons_category {
1.521 www 7449: color: $font;
1.526 www 7450: background: $pgbg;
1.521 www 7451: font-size: larger;
7452: font-weight: bold;
7453: }
7454:
1.346 albertel 7455: td.LC_menubuttons_text {
1.911 bisitz 7456: color: $font;
1.346 albertel 7457: }
1.706 harmsja 7458:
1.346 albertel 7459: .LC_current_location {
7460: background: $tabbg;
7461: }
1.795 www 7462:
1.1286 raeburn 7463: td.LC_zero_height {
7464: line-height: 0;
7465: cellpadding: 0;
7466: }
7467:
1.938 bisitz 7468: table.LC_data_table {
1.347 albertel 7469: border: 1px solid #000000;
1.402 albertel 7470: border-collapse: separate;
1.426 albertel 7471: border-spacing: 1px;
1.610 albertel 7472: background: $pgbg;
1.347 albertel 7473: }
1.795 www 7474:
1.422 albertel 7475: .LC_data_table_dense {
7476: font-size: small;
7477: }
1.795 www 7478:
1.507 raeburn 7479: table.LC_nested_outer {
7480: border: 1px solid #000000;
1.589 raeburn 7481: border-collapse: collapse;
1.803 bisitz 7482: border-spacing: 0;
1.507 raeburn 7483: width: 100%;
7484: }
1.795 www 7485:
1.879 raeburn 7486: table.LC_innerpickbox,
1.507 raeburn 7487: table.LC_nested {
1.803 bisitz 7488: border: none;
1.589 raeburn 7489: border-collapse: collapse;
1.803 bisitz 7490: border-spacing: 0;
1.507 raeburn 7491: width: 100%;
7492: }
1.795 www 7493:
1.911 bisitz 7494: table.LC_data_table tr th,
7495: table.LC_calendar tr th,
1.879 raeburn 7496: table.LC_prior_tries tr th,
7497: table.LC_innerpickbox tr th {
1.349 albertel 7498: font-weight: bold;
7499: background-color: $data_table_head;
1.801 tempelho 7500: color:$fontmenu;
1.701 harmsja 7501: font-size:90%;
1.347 albertel 7502: }
1.795 www 7503:
1.879 raeburn 7504: table.LC_innerpickbox tr th,
7505: table.LC_innerpickbox tr td {
7506: vertical-align: top;
7507: }
7508:
1.711 raeburn 7509: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7510: background-color: #CCCCCC;
1.711 raeburn 7511: font-weight: bold;
7512: text-align: left;
7513: }
1.795 www 7514:
1.912 bisitz 7515: table.LC_data_table tr.LC_odd_row > td {
7516: background-color: $data_table_light;
7517: padding: 2px;
7518: vertical-align: top;
7519: }
7520:
1.809 bisitz 7521: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7522: background-color: $data_table_light;
1.912 bisitz 7523: vertical-align: top;
7524: }
7525:
7526: table.LC_data_table tr.LC_even_row > td {
7527: background-color: $data_table_dark;
1.425 albertel 7528: padding: 2px;
1.900 bisitz 7529: vertical-align: top;
1.347 albertel 7530: }
1.795 www 7531:
1.809 bisitz 7532: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7533: background-color: $data_table_dark;
1.900 bisitz 7534: vertical-align: top;
1.347 albertel 7535: }
1.795 www 7536:
1.425 albertel 7537: table.LC_data_table tr.LC_data_table_highlight td {
7538: background-color: $data_table_darker;
7539: }
1.795 www 7540:
1.639 raeburn 7541: table.LC_data_table tr td.LC_leftcol_header {
7542: background-color: $data_table_head;
7543: font-weight: bold;
7544: }
1.795 www 7545:
1.451 albertel 7546: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7547: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7548: font-weight: bold;
7549: font-style: italic;
7550: text-align: center;
7551: padding: 8px;
1.347 albertel 7552: }
1.795 www 7553:
1.1114 raeburn 7554: table.LC_data_table tr.LC_empty_row td,
7555: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7556: background-color: $sidebg;
7557: }
7558:
7559: table.LC_nested tr.LC_empty_row td {
7560: background-color: #FFFFFF;
7561: }
7562:
1.890 droeschl 7563: table.LC_caption {
7564: }
7565:
1.507 raeburn 7566: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7567: padding: 4ex
7568: }
1.795 www 7569:
1.507 raeburn 7570: table.LC_nested_outer tr th {
7571: font-weight: bold;
1.801 tempelho 7572: color:$fontmenu;
1.507 raeburn 7573: background-color: $data_table_head;
1.701 harmsja 7574: font-size: small;
1.507 raeburn 7575: border-bottom: 1px solid #000000;
7576: }
1.795 www 7577:
1.507 raeburn 7578: table.LC_nested_outer tr td.LC_subheader {
7579: background-color: $data_table_head;
7580: font-weight: bold;
7581: font-size: small;
7582: border-bottom: 1px solid #000000;
7583: text-align: right;
1.451 albertel 7584: }
1.795 www 7585:
1.507 raeburn 7586: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7587: background-color: #CCCCCC;
1.451 albertel 7588: font-weight: bold;
7589: font-size: small;
1.507 raeburn 7590: text-align: center;
7591: }
1.795 www 7592:
1.589 raeburn 7593: table.LC_nested tr.LC_info_row td.LC_left_item,
7594: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7595: text-align: left;
1.451 albertel 7596: }
1.795 www 7597:
1.507 raeburn 7598: table.LC_nested td {
1.735 bisitz 7599: background-color: #FFFFFF;
1.451 albertel 7600: font-size: small;
1.507 raeburn 7601: }
1.795 www 7602:
1.507 raeburn 7603: table.LC_nested_outer tr th.LC_right_item,
7604: table.LC_nested tr.LC_info_row td.LC_right_item,
7605: table.LC_nested tr.LC_odd_row td.LC_right_item,
7606: table.LC_nested tr td.LC_right_item {
1.451 albertel 7607: text-align: right;
7608: }
7609:
1.507 raeburn 7610: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7611: background-color: #EEEEEE;
1.451 albertel 7612: }
7613:
1.473 raeburn 7614: table.LC_createuser {
7615: }
7616:
7617: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7618: font-size: small;
1.473 raeburn 7619: }
7620:
7621: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7622: background-color: #CCCCCC;
1.473 raeburn 7623: font-weight: bold;
7624: text-align: center;
7625: }
7626:
1.349 albertel 7627: table.LC_calendar {
7628: border: 1px solid #000000;
7629: border-collapse: collapse;
1.917 raeburn 7630: width: 98%;
1.349 albertel 7631: }
1.795 www 7632:
1.349 albertel 7633: table.LC_calendar_pickdate {
7634: font-size: xx-small;
7635: }
1.795 www 7636:
1.349 albertel 7637: table.LC_calendar tr td {
7638: border: 1px solid #000000;
7639: vertical-align: top;
1.917 raeburn 7640: width: 14%;
1.349 albertel 7641: }
1.795 www 7642:
1.349 albertel 7643: table.LC_calendar tr td.LC_calendar_day_empty {
7644: background-color: $data_table_dark;
7645: }
1.795 www 7646:
1.779 bisitz 7647: table.LC_calendar tr td.LC_calendar_day_current {
7648: background-color: $data_table_highlight;
1.777 tempelho 7649: }
1.795 www 7650:
1.938 bisitz 7651: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7652: background-color: $mail_new;
7653: }
1.795 www 7654:
1.938 bisitz 7655: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7656: background-color: $mail_new_hover;
7657: }
1.795 www 7658:
1.938 bisitz 7659: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7660: background-color: $mail_read;
7661: }
1.795 www 7662:
1.938 bisitz 7663: /*
7664: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7665: background-color: $mail_read_hover;
7666: }
1.938 bisitz 7667: */
1.795 www 7668:
1.938 bisitz 7669: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7670: background-color: $mail_replied;
7671: }
1.795 www 7672:
1.938 bisitz 7673: /*
7674: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7675: background-color: $mail_replied_hover;
7676: }
1.938 bisitz 7677: */
1.795 www 7678:
1.938 bisitz 7679: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7680: background-color: $mail_other;
7681: }
1.795 www 7682:
1.938 bisitz 7683: /*
7684: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7685: background-color: $mail_other_hover;
7686: }
1.938 bisitz 7687: */
1.494 raeburn 7688:
1.777 tempelho 7689: table.LC_data_table tr > td.LC_browser_file,
7690: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7691: background: #AAEE77;
1.389 albertel 7692: }
1.795 www 7693:
1.777 tempelho 7694: table.LC_data_table tr > td.LC_browser_file_locked,
7695: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7696: background: #FFAA99;
1.387 albertel 7697: }
1.795 www 7698:
1.777 tempelho 7699: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7700: background: #888888;
1.779 bisitz 7701: }
1.795 www 7702:
1.777 tempelho 7703: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7704: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7705: background: #F8F866;
1.777 tempelho 7706: }
1.795 www 7707:
1.696 bisitz 7708: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7709: background: #E0E8FF;
1.387 albertel 7710: }
1.696 bisitz 7711:
1.707 bisitz 7712: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7713: /* background: #77FF77; */
1.707 bisitz 7714: }
1.795 www 7715:
1.707 bisitz 7716: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7717: border-right: 8px solid #FFFF77;
1.707 bisitz 7718: }
1.795 www 7719:
1.707 bisitz 7720: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7721: border-right: 8px solid #FFAA77;
1.707 bisitz 7722: }
1.795 www 7723:
1.707 bisitz 7724: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7725: border-right: 8px solid #FF7777;
1.707 bisitz 7726: }
1.795 www 7727:
1.707 bisitz 7728: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7729: border-right: 8px solid #AAFF77;
1.707 bisitz 7730: }
1.795 www 7731:
1.707 bisitz 7732: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7733: border-right: 8px solid #11CC55;
1.707 bisitz 7734: }
7735:
1.388 albertel 7736: span.LC_current_location {
1.701 harmsja 7737: font-size:larger;
1.388 albertel 7738: background: $pgbg;
7739: }
1.387 albertel 7740:
1.1029 www 7741: span.LC_current_nav_location {
7742: font-weight:bold;
7743: background: $sidebg;
7744: }
7745:
1.395 albertel 7746: span.LC_parm_menu_item {
7747: font-size: larger;
7748: }
1.795 www 7749:
1.395 albertel 7750: span.LC_parm_scope_all {
7751: color: red;
7752: }
1.795 www 7753:
1.395 albertel 7754: span.LC_parm_scope_folder {
7755: color: green;
7756: }
1.795 www 7757:
1.395 albertel 7758: span.LC_parm_scope_resource {
7759: color: orange;
7760: }
1.795 www 7761:
1.395 albertel 7762: span.LC_parm_part {
7763: color: blue;
7764: }
1.795 www 7765:
1.911 bisitz 7766: span.LC_parm_folder,
7767: span.LC_parm_symb {
1.395 albertel 7768: font-size: x-small;
7769: font-family: $mono;
7770: color: #AAAAAA;
7771: }
7772:
1.977 bisitz 7773: ul.LC_parm_parmlist li {
7774: display: inline-block;
7775: padding: 0.3em 0.8em;
7776: vertical-align: top;
7777: width: 150px;
7778: border-top:1px solid $lg_border_color;
7779: }
7780:
1.795 www 7781: td.LC_parm_overview_level_menu,
7782: td.LC_parm_overview_map_menu,
7783: td.LC_parm_overview_parm_selectors,
7784: td.LC_parm_overview_restrictions {
1.396 albertel 7785: border: 1px solid black;
7786: border-collapse: collapse;
7787: }
1.795 www 7788:
1.1285 raeburn 7789: span.LC_parm_recursive,
7790: td.LC_parm_recursive {
7791: font-weight: bold;
7792: font-size: smaller;
7793: }
7794:
1.396 albertel 7795: table.LC_parm_overview_restrictions td {
7796: border-width: 1px 4px 1px 4px;
7797: border-style: solid;
7798: border-color: $pgbg;
7799: text-align: center;
7800: }
1.795 www 7801:
1.396 albertel 7802: table.LC_parm_overview_restrictions th {
7803: background: $tabbg;
7804: border-width: 1px 4px 1px 4px;
7805: border-style: solid;
7806: border-color: $pgbg;
7807: }
1.795 www 7808:
1.398 albertel 7809: table#LC_helpmenu {
1.803 bisitz 7810: border: none;
1.398 albertel 7811: height: 55px;
1.803 bisitz 7812: border-spacing: 0;
1.398 albertel 7813: }
7814:
7815: table#LC_helpmenu fieldset legend {
7816: font-size: larger;
7817: }
1.795 www 7818:
1.397 albertel 7819: table#LC_helpmenu_links {
7820: width: 100%;
7821: border: 1px solid black;
7822: background: $pgbg;
1.803 bisitz 7823: padding: 0;
1.397 albertel 7824: border-spacing: 1px;
7825: }
1.795 www 7826:
1.397 albertel 7827: table#LC_helpmenu_links tr td {
7828: padding: 1px;
7829: background: $tabbg;
1.399 albertel 7830: text-align: center;
7831: font-weight: bold;
1.397 albertel 7832: }
1.396 albertel 7833:
1.795 www 7834: table#LC_helpmenu_links a:link,
7835: table#LC_helpmenu_links a:visited,
1.397 albertel 7836: table#LC_helpmenu_links a:active {
7837: text-decoration: none;
7838: color: $font;
7839: }
1.795 www 7840:
1.397 albertel 7841: table#LC_helpmenu_links a:hover {
7842: text-decoration: underline;
7843: color: $vlink;
7844: }
1.396 albertel 7845:
1.417 albertel 7846: .LC_chrt_popup_exists {
7847: border: 1px solid #339933;
7848: margin: -1px;
7849: }
1.795 www 7850:
1.417 albertel 7851: .LC_chrt_popup_up {
7852: border: 1px solid yellow;
7853: margin: -1px;
7854: }
1.795 www 7855:
1.417 albertel 7856: .LC_chrt_popup {
7857: border: 1px solid #8888FF;
7858: background: #CCCCFF;
7859: }
1.795 www 7860:
1.421 albertel 7861: table.LC_pick_box {
7862: border-collapse: separate;
7863: background: white;
7864: border: 1px solid black;
7865: border-spacing: 1px;
7866: }
1.795 www 7867:
1.421 albertel 7868: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7869: background: $sidebg;
1.421 albertel 7870: font-weight: bold;
1.900 bisitz 7871: text-align: left;
1.740 bisitz 7872: vertical-align: top;
1.421 albertel 7873: width: 184px;
7874: padding: 8px;
7875: }
1.795 www 7876:
1.579 raeburn 7877: table.LC_pick_box td.LC_pick_box_value {
7878: text-align: left;
7879: padding: 8px;
7880: }
1.795 www 7881:
1.579 raeburn 7882: table.LC_pick_box td.LC_pick_box_select {
7883: text-align: left;
7884: padding: 8px;
7885: }
1.795 www 7886:
1.424 albertel 7887: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7888: padding: 0;
1.421 albertel 7889: height: 1px;
7890: background: black;
7891: }
1.795 www 7892:
1.421 albertel 7893: table.LC_pick_box td.LC_pick_box_submit {
7894: text-align: right;
7895: }
1.795 www 7896:
1.579 raeburn 7897: table.LC_pick_box td.LC_evenrow_value {
7898: text-align: left;
7899: padding: 8px;
7900: background-color: $data_table_light;
7901: }
1.795 www 7902:
1.579 raeburn 7903: table.LC_pick_box td.LC_oddrow_value {
7904: text-align: left;
7905: padding: 8px;
7906: background-color: $data_table_light;
7907: }
1.795 www 7908:
1.579 raeburn 7909: span.LC_helpform_receipt_cat {
7910: font-weight: bold;
7911: }
1.795 www 7912:
1.424 albertel 7913: table.LC_group_priv_box {
7914: background: white;
7915: border: 1px solid black;
7916: border-spacing: 1px;
7917: }
1.795 www 7918:
1.424 albertel 7919: table.LC_group_priv_box td.LC_pick_box_title {
7920: background: $tabbg;
7921: font-weight: bold;
7922: text-align: right;
7923: width: 184px;
7924: }
1.795 www 7925:
1.424 albertel 7926: table.LC_group_priv_box td.LC_groups_fixed {
7927: background: $data_table_light;
7928: text-align: center;
7929: }
1.795 www 7930:
1.424 albertel 7931: table.LC_group_priv_box td.LC_groups_optional {
7932: background: $data_table_dark;
7933: text-align: center;
7934: }
1.795 www 7935:
1.424 albertel 7936: table.LC_group_priv_box td.LC_groups_functionality {
7937: background: $data_table_darker;
7938: text-align: center;
7939: font-weight: bold;
7940: }
1.795 www 7941:
1.424 albertel 7942: table.LC_group_priv td {
7943: text-align: left;
1.803 bisitz 7944: padding: 0;
1.424 albertel 7945: }
7946:
7947: .LC_navbuttons {
7948: margin: 2ex 0ex 2ex 0ex;
7949: }
1.795 www 7950:
1.423 albertel 7951: .LC_topic_bar {
7952: font-weight: bold;
7953: background: $tabbg;
1.918 wenzelju 7954: margin: 1em 0em 1em 2em;
1.805 bisitz 7955: padding: 3px;
1.918 wenzelju 7956: font-size: 1.2em;
1.423 albertel 7957: }
1.795 www 7958:
1.423 albertel 7959: .LC_topic_bar span {
1.918 wenzelju 7960: left: 0.5em;
7961: position: absolute;
1.423 albertel 7962: vertical-align: middle;
1.918 wenzelju 7963: font-size: 1.2em;
1.423 albertel 7964: }
1.795 www 7965:
1.423 albertel 7966: table.LC_course_group_status {
7967: margin: 20px;
7968: }
1.795 www 7969:
1.423 albertel 7970: table.LC_status_selector td {
7971: vertical-align: top;
7972: text-align: center;
1.424 albertel 7973: padding: 4px;
7974: }
1.795 www 7975:
1.599 albertel 7976: div.LC_feedback_link {
1.616 albertel 7977: clear: both;
1.829 kalberla 7978: background: $sidebg;
1.779 bisitz 7979: width: 100%;
1.829 kalberla 7980: padding-bottom: 10px;
7981: border: 1px $tabbg solid;
1.833 kalberla 7982: height: 22px;
7983: line-height: 22px;
7984: padding-top: 5px;
7985: }
7986:
7987: div.LC_feedback_link img {
7988: height: 22px;
1.867 kalberla 7989: vertical-align:middle;
1.829 kalberla 7990: }
7991:
1.911 bisitz 7992: div.LC_feedback_link a {
1.829 kalberla 7993: text-decoration: none;
1.489 raeburn 7994: }
1.795 www 7995:
1.867 kalberla 7996: div.LC_comblock {
1.911 bisitz 7997: display:inline;
1.867 kalberla 7998: color:$font;
7999: font-size:90%;
8000: }
8001:
8002: div.LC_feedback_link div.LC_comblock {
8003: padding-left:5px;
8004: }
8005:
8006: div.LC_feedback_link div.LC_comblock a {
8007: color:$font;
8008: }
8009:
1.489 raeburn 8010: span.LC_feedback_link {
1.858 bisitz 8011: /* background: $feedback_link_bg; */
1.599 albertel 8012: font-size: larger;
8013: }
1.795 www 8014:
1.599 albertel 8015: span.LC_message_link {
1.858 bisitz 8016: /* background: $feedback_link_bg; */
1.599 albertel 8017: font-size: larger;
8018: position: absolute;
8019: right: 1em;
1.489 raeburn 8020: }
1.421 albertel 8021:
1.515 albertel 8022: table.LC_prior_tries {
1.524 albertel 8023: border: 1px solid #000000;
8024: border-collapse: separate;
8025: border-spacing: 1px;
1.515 albertel 8026: }
1.523 albertel 8027:
1.515 albertel 8028: table.LC_prior_tries td {
1.524 albertel 8029: padding: 2px;
1.515 albertel 8030: }
1.523 albertel 8031:
8032: .LC_answer_correct {
1.795 www 8033: background: lightgreen;
8034: color: darkgreen;
8035: padding: 6px;
1.523 albertel 8036: }
1.795 www 8037:
1.523 albertel 8038: .LC_answer_charged_try {
1.797 www 8039: background: #FFAAAA;
1.795 www 8040: color: darkred;
8041: padding: 6px;
1.523 albertel 8042: }
1.795 www 8043:
1.779 bisitz 8044: .LC_answer_not_charged_try,
1.523 albertel 8045: .LC_answer_no_grade,
8046: .LC_answer_late {
1.795 www 8047: background: lightyellow;
1.523 albertel 8048: color: black;
1.795 www 8049: padding: 6px;
1.523 albertel 8050: }
1.795 www 8051:
1.523 albertel 8052: .LC_answer_previous {
1.795 www 8053: background: lightblue;
8054: color: darkblue;
8055: padding: 6px;
1.523 albertel 8056: }
1.795 www 8057:
1.779 bisitz 8058: .LC_answer_no_message {
1.777 tempelho 8059: background: #FFFFFF;
8060: color: black;
1.795 www 8061: padding: 6px;
1.779 bisitz 8062: }
1.795 www 8063:
1.1334 raeburn 8064: .LC_answer_unknown,
8065: .LC_answer_warning {
1.779 bisitz 8066: background: orange;
8067: color: black;
1.795 www 8068: padding: 6px;
1.777 tempelho 8069: }
1.795 www 8070:
1.529 albertel 8071: span.LC_prior_numerical,
8072: span.LC_prior_string,
8073: span.LC_prior_custom,
8074: span.LC_prior_reaction,
8075: span.LC_prior_math {
1.925 bisitz 8076: font-family: $mono;
1.523 albertel 8077: white-space: pre;
8078: }
8079:
1.525 albertel 8080: span.LC_prior_string {
1.925 bisitz 8081: font-family: $mono;
1.525 albertel 8082: white-space: pre;
8083: }
8084:
1.523 albertel 8085: table.LC_prior_option {
8086: width: 100%;
8087: border-collapse: collapse;
8088: }
1.795 www 8089:
1.911 bisitz 8090: table.LC_prior_rank,
1.795 www 8091: table.LC_prior_match {
1.528 albertel 8092: border-collapse: collapse;
8093: }
1.795 www 8094:
1.528 albertel 8095: table.LC_prior_option tr td,
8096: table.LC_prior_rank tr td,
8097: table.LC_prior_match tr td {
1.524 albertel 8098: border: 1px solid #000000;
1.515 albertel 8099: }
8100:
1.855 bisitz 8101: .LC_nobreak {
1.544 albertel 8102: white-space: nowrap;
1.519 raeburn 8103: }
8104:
1.576 raeburn 8105: span.LC_cusr_emph {
8106: font-style: italic;
8107: }
8108:
1.633 raeburn 8109: span.LC_cusr_subheading {
8110: font-weight: normal;
8111: font-size: 85%;
8112: }
8113:
1.861 bisitz 8114: div.LC_docs_entry_move {
1.859 bisitz 8115: border: 1px solid #BBBBBB;
1.545 albertel 8116: background: #DDDDDD;
1.861 bisitz 8117: width: 22px;
1.859 bisitz 8118: padding: 1px;
8119: margin: 0;
1.545 albertel 8120: }
8121:
1.861 bisitz 8122: table.LC_data_table tr > td.LC_docs_entry_commands,
8123: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 8124: font-size: x-small;
8125: }
1.795 www 8126:
1.861 bisitz 8127: .LC_docs_entry_parameter {
8128: white-space: nowrap;
8129: }
8130:
1.544 albertel 8131: .LC_docs_copy {
1.545 albertel 8132: color: #000099;
1.544 albertel 8133: }
1.795 www 8134:
1.544 albertel 8135: .LC_docs_cut {
1.545 albertel 8136: color: #550044;
1.544 albertel 8137: }
1.795 www 8138:
1.544 albertel 8139: .LC_docs_rename {
1.545 albertel 8140: color: #009900;
1.544 albertel 8141: }
1.795 www 8142:
1.544 albertel 8143: .LC_docs_remove {
1.545 albertel 8144: color: #990000;
8145: }
8146:
1.1284 raeburn 8147: .LC_docs_alias {
8148: color: #440055;
8149: }
8150:
1.1286 raeburn 8151: .LC_domprefs_email,
1.1284 raeburn 8152: .LC_docs_alias_name,
1.547 albertel 8153: .LC_docs_reinit_warn,
8154: .LC_docs_ext_edit {
8155: font-size: x-small;
8156: }
8157:
1.545 albertel 8158: table.LC_docs_adddocs td,
8159: table.LC_docs_adddocs th {
8160: border: 1px solid #BBBBBB;
8161: padding: 4px;
8162: background: #DDDDDD;
1.543 albertel 8163: }
8164:
1.584 albertel 8165: table.LC_sty_begin {
8166: background: #BBFFBB;
8167: }
1.795 www 8168:
1.584 albertel 8169: table.LC_sty_end {
8170: background: #FFBBBB;
8171: }
8172:
1.589 raeburn 8173: table.LC_double_column {
1.803 bisitz 8174: border-width: 0;
1.589 raeburn 8175: border-collapse: collapse;
8176: width: 100%;
8177: padding: 2px;
8178: }
8179:
8180: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 8181: top: 2px;
1.589 raeburn 8182: left: 2px;
8183: width: 47%;
8184: vertical-align: top;
8185: }
8186:
8187: table.LC_double_column tr td.LC_right_col {
8188: top: 2px;
1.779 bisitz 8189: right: 2px;
1.589 raeburn 8190: width: 47%;
8191: vertical-align: top;
8192: }
8193:
1.591 raeburn 8194: div.LC_left_float {
8195: float: left;
8196: padding-right: 5%;
1.597 albertel 8197: padding-bottom: 4px;
1.591 raeburn 8198: }
8199:
8200: div.LC_clear_float_header {
1.597 albertel 8201: padding-bottom: 2px;
1.591 raeburn 8202: }
8203:
8204: div.LC_clear_float_footer {
1.597 albertel 8205: padding-top: 10px;
1.591 raeburn 8206: clear: both;
8207: }
8208:
1.597 albertel 8209: div.LC_grade_show_user {
1.941 bisitz 8210: /* border-left: 5px solid $sidebg; */
8211: border-top: 5px solid #000000;
8212: margin: 50px 0 0 0;
1.936 bisitz 8213: padding: 15px 0 5px 10px;
1.597 albertel 8214: }
1.795 www 8215:
1.936 bisitz 8216: div.LC_grade_show_user_odd_row {
1.941 bisitz 8217: /* border-left: 5px solid #000000; */
8218: }
8219:
8220: div.LC_grade_show_user div.LC_Box {
8221: margin-right: 50px;
1.597 albertel 8222: }
8223:
8224: div.LC_grade_submissions,
8225: div.LC_grade_message_center,
1.936 bisitz 8226: div.LC_grade_info_links {
1.597 albertel 8227: margin: 5px;
8228: width: 99%;
8229: background: #FFFFFF;
8230: }
1.795 www 8231:
1.597 albertel 8232: div.LC_grade_submissions_header,
1.936 bisitz 8233: div.LC_grade_message_center_header {
1.705 tempelho 8234: font-weight: bold;
8235: font-size: large;
1.597 albertel 8236: }
1.795 www 8237:
1.597 albertel 8238: div.LC_grade_submissions_body,
1.936 bisitz 8239: div.LC_grade_message_center_body {
1.597 albertel 8240: border: 1px solid black;
8241: width: 99%;
8242: background: #FFFFFF;
8243: }
1.795 www 8244:
1.613 albertel 8245: table.LC_scantron_action {
8246: width: 100%;
8247: }
1.795 www 8248:
1.613 albertel 8249: table.LC_scantron_action tr th {
1.698 harmsja 8250: font-weight:bold;
8251: font-style:normal;
1.613 albertel 8252: }
1.795 www 8253:
1.779 bisitz 8254: .LC_edit_problem_header,
1.614 albertel 8255: div.LC_edit_problem_footer {
1.705 tempelho 8256: font-weight: normal;
8257: font-size: medium;
1.602 albertel 8258: margin: 2px;
1.1060 bisitz 8259: background-color: $sidebg;
1.600 albertel 8260: }
1.795 www 8261:
1.600 albertel 8262: div.LC_edit_problem_header,
1.602 albertel 8263: div.LC_edit_problem_header div,
1.614 albertel 8264: div.LC_edit_problem_footer,
8265: div.LC_edit_problem_footer div,
1.602 albertel 8266: div.LC_edit_problem_editxml_header,
8267: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8268: z-index: 100;
1.600 albertel 8269: }
1.795 www 8270:
1.600 albertel 8271: div.LC_edit_problem_header_title {
1.705 tempelho 8272: font-weight: bold;
8273: font-size: larger;
1.602 albertel 8274: background: $tabbg;
8275: padding: 3px;
1.1060 bisitz 8276: margin: 0 0 5px 0;
1.602 albertel 8277: }
1.795 www 8278:
1.602 albertel 8279: table.LC_edit_problem_header_title {
8280: width: 100%;
1.600 albertel 8281: background: $tabbg;
1.602 albertel 8282: }
8283:
1.1205 golterma 8284: div.LC_edit_actionbar {
8285: background-color: $sidebg;
1.1218 droeschl 8286: margin: 0;
8287: padding: 0;
8288: line-height: 200%;
1.602 albertel 8289: }
1.795 www 8290:
1.1218 droeschl 8291: div.LC_edit_actionbar div{
8292: padding: 0;
8293: margin: 0;
8294: display: inline-block;
1.600 albertel 8295: }
1.795 www 8296:
1.1124 bisitz 8297: .LC_edit_opt {
8298: padding-left: 1em;
8299: white-space: nowrap;
8300: }
8301:
1.1152 golterma 8302: .LC_edit_problem_latexhelper{
8303: text-align: right;
8304: }
8305:
8306: #LC_edit_problem_colorful div{
8307: margin-left: 40px;
8308: }
8309:
1.1205 golterma 8310: #LC_edit_problem_codemirror div{
8311: margin-left: 0px;
8312: }
8313:
1.911 bisitz 8314: img.stift {
1.803 bisitz 8315: border-width: 0;
8316: vertical-align: middle;
1.677 riegler 8317: }
1.680 riegler 8318:
1.923 bisitz 8319: table td.LC_mainmenu_col_fieldset {
1.680 riegler 8320: vertical-align: top;
1.777 tempelho 8321: }
1.795 www 8322:
1.716 raeburn 8323: div.LC_createcourse {
1.911 bisitz 8324: margin: 10px 10px 10px 10px;
1.716 raeburn 8325: }
8326:
1.917 raeburn 8327: .LC_dccid {
1.1130 raeburn 8328: float: right;
1.917 raeburn 8329: margin: 0.2em 0 0 0;
8330: padding: 0;
8331: font-size: 90%;
8332: display:none;
8333: }
8334:
1.897 wenzelju 8335: ol.LC_primary_menu a:hover,
1.721 harmsja 8336: ol#LC_MenuBreadcrumbs a:hover,
8337: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8338: ul#LC_secondary_menu a:hover,
1.721 harmsja 8339: .LC_FormSectionClearButton input:hover
1.795 www 8340: ul.LC_TabContent li:hover a {
1.952 onken 8341: color:$button_hover;
1.911 bisitz 8342: text-decoration:none;
1.693 droeschl 8343: }
8344:
1.779 bisitz 8345: h1 {
1.911 bisitz 8346: padding: 0;
8347: line-height:130%;
1.693 droeschl 8348: }
1.698 harmsja 8349:
1.911 bisitz 8350: h2,
8351: h3,
8352: h4,
8353: h5,
8354: h6 {
8355: margin: 5px 0 5px 0;
8356: padding: 0;
8357: line-height:130%;
1.693 droeschl 8358: }
1.795 www 8359:
8360: .LC_hcell {
1.911 bisitz 8361: padding:3px 15px 3px 15px;
8362: margin: 0;
8363: background-color:$tabbg;
8364: color:$fontmenu;
8365: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8366: }
1.795 www 8367:
1.840 bisitz 8368: .LC_Box > .LC_hcell {
1.911 bisitz 8369: margin: 0 -10px 10px -10px;
1.835 bisitz 8370: }
8371:
1.721 harmsja 8372: .LC_noBorder {
1.911 bisitz 8373: border: 0;
1.698 harmsja 8374: }
1.693 droeschl 8375:
1.721 harmsja 8376: .LC_FormSectionClearButton input {
1.911 bisitz 8377: background-color:transparent;
8378: border: none;
8379: cursor:pointer;
8380: text-decoration:underline;
1.693 droeschl 8381: }
1.763 bisitz 8382:
8383: .LC_help_open_topic {
1.911 bisitz 8384: color: #FFFFFF;
8385: background-color: #EEEEFF;
8386: margin: 1px;
8387: padding: 4px;
8388: border: 1px solid #000033;
8389: white-space: nowrap;
8390: /* vertical-align: middle; */
1.759 neumanie 8391: }
1.693 droeschl 8392:
1.911 bisitz 8393: dl,
8394: ul,
8395: div,
8396: fieldset {
8397: margin: 10px 10px 10px 0;
8398: /* overflow: hidden; */
1.693 droeschl 8399: }
1.795 www 8400:
1.1404 raeburn 8401: fieldset#LC_selectuser {
8402: margin: 0;
8403: padding: 0;
8404: }
8405:
1.1211 raeburn 8406: article.geogebraweb div {
8407: margin: 0;
8408: }
8409:
1.838 bisitz 8410: fieldset > legend {
1.911 bisitz 8411: font-weight: bold;
8412: padding: 0 5px 0 5px;
1.838 bisitz 8413: }
8414:
1.813 bisitz 8415: #LC_nav_bar {
1.911 bisitz 8416: float: left;
1.995 raeburn 8417: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8418: margin: 0 0 2px 0;
1.807 droeschl 8419: }
8420:
1.916 droeschl 8421: #LC_realm {
8422: margin: 0.2em 0 0 0;
8423: padding: 0;
8424: font-weight: bold;
8425: text-align: center;
1.995 raeburn 8426: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8427: }
8428:
1.911 bisitz 8429: #LC_nav_bar em {
8430: font-weight: bold;
8431: font-style: normal;
1.807 droeschl 8432: }
8433:
1.897 wenzelju 8434: ol.LC_primary_menu {
1.934 droeschl 8435: margin: 0;
1.1076 raeburn 8436: padding: 0;
1.807 droeschl 8437: }
8438:
1.852 droeschl 8439: ol#LC_PathBreadcrumbs {
1.911 bisitz 8440: margin: 0;
1.693 droeschl 8441: }
8442:
1.897 wenzelju 8443: ol.LC_primary_menu li {
1.1076 raeburn 8444: color: RGB(80, 80, 80);
8445: vertical-align: middle;
8446: text-align: left;
8447: list-style: none;
1.1205 golterma 8448: position: relative;
1.1076 raeburn 8449: float: left;
1.1205 golterma 8450: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8451: line-height: 1.5em;
1.1076 raeburn 8452: }
8453:
1.1205 golterma 8454: ol.LC_primary_menu li a,
8455: ol.LC_primary_menu li p {
1.1076 raeburn 8456: display: block;
8457: margin: 0;
8458: padding: 0 5px 0 10px;
8459: text-decoration: none;
8460: }
8461:
1.1205 golterma 8462: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8463: display: inline-block;
8464: width: 95%;
8465: text-align: left;
8466: }
8467:
8468: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8469: display: inline-block;
8470: width: 5%;
8471: float: right;
8472: text-align: right;
8473: font-size: 70%;
8474: }
8475:
8476: ol.LC_primary_menu ul {
1.1076 raeburn 8477: display: none;
1.1205 golterma 8478: width: 15em;
1.1076 raeburn 8479: background-color: $data_table_light;
1.1205 golterma 8480: position: absolute;
8481: top: 100%;
1.1076 raeburn 8482: }
8483:
1.1205 golterma 8484: ol.LC_primary_menu ul ul {
8485: left: 100%;
8486: top: 0;
8487: }
8488:
8489: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8490: display: block;
8491: position: absolute;
8492: margin: 0;
8493: padding: 0;
1.1078 raeburn 8494: z-index: 2;
1.1076 raeburn 8495: }
8496:
8497: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8498: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8499: font-size: 90%;
1.911 bisitz 8500: vertical-align: top;
1.1076 raeburn 8501: float: none;
1.1079 raeburn 8502: border-left: 1px solid black;
8503: border-right: 1px solid black;
1.1205 golterma 8504: /* A dark bottom border to visualize different menu options;
8505: overwritten in the create_submenu routine for the last border-bottom of the menu */
8506: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8507: }
8508:
1.1205 golterma 8509: ol.LC_primary_menu li li p:hover {
8510: color:$button_hover;
8511: text-decoration:none;
8512: background-color:$data_table_dark;
1.1076 raeburn 8513: }
8514:
8515: ol.LC_primary_menu li li a:hover {
8516: color:$button_hover;
8517: background-color:$data_table_dark;
1.693 droeschl 8518: }
8519:
1.1205 golterma 8520: /* Font-size equal to the size of the predecessors*/
8521: ol.LC_primary_menu li:hover li li {
8522: font-size: 100%;
8523: }
8524:
1.897 wenzelju 8525: ol.LC_primary_menu li img {
1.911 bisitz 8526: vertical-align: bottom;
1.934 droeschl 8527: height: 1.1em;
1.1077 raeburn 8528: margin: 0.2em 0 0 0;
1.693 droeschl 8529: }
8530:
1.897 wenzelju 8531: ol.LC_primary_menu a {
1.911 bisitz 8532: color: RGB(80, 80, 80);
8533: text-decoration: none;
1.693 droeschl 8534: }
1.795 www 8535:
1.949 droeschl 8536: ol.LC_primary_menu a.LC_new_message {
8537: font-weight:bold;
8538: color: darkred;
8539: }
8540:
1.975 raeburn 8541: ol.LC_docs_parameters {
8542: margin-left: 0;
8543: padding: 0;
8544: list-style: none;
8545: }
8546:
8547: ol.LC_docs_parameters li {
8548: margin: 0;
8549: padding-right: 20px;
8550: display: inline;
8551: }
8552:
1.976 raeburn 8553: ol.LC_docs_parameters li:before {
8554: content: "\\002022 \\0020";
8555: }
8556:
8557: li.LC_docs_parameters_title {
8558: font-weight: bold;
8559: }
8560:
8561: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8562: content: "";
8563: }
8564:
1.897 wenzelju 8565: ul#LC_secondary_menu {
1.1107 raeburn 8566: clear: right;
1.911 bisitz 8567: color: $fontmenu;
8568: background: $tabbg;
8569: list-style: none;
8570: padding: 0;
8571: margin: 0;
8572: width: 100%;
1.995 raeburn 8573: text-align: left;
1.1107 raeburn 8574: float: left;
1.808 droeschl 8575: }
8576:
1.897 wenzelju 8577: ul#LC_secondary_menu li {
1.911 bisitz 8578: font-weight: bold;
8579: line-height: 1.8em;
1.1107 raeburn 8580: border-right: 1px solid black;
8581: float: left;
8582: }
8583:
8584: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8585: background-color: $data_table_light;
8586: }
8587:
8588: ul#LC_secondary_menu li a {
1.911 bisitz 8589: padding: 0 0.8em;
1.1107 raeburn 8590: }
8591:
8592: ul#LC_secondary_menu li ul {
8593: display: none;
8594: }
8595:
8596: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8597: display: block;
8598: position: absolute;
8599: margin: 0;
8600: padding: 0;
8601: list-style:none;
8602: float: none;
8603: background-color: $data_table_light;
8604: z-index: 2;
8605: margin-left: -1px;
8606: }
8607:
8608: ul#LC_secondary_menu li ul li {
8609: font-size: 90%;
8610: vertical-align: top;
8611: border-left: 1px solid black;
1.911 bisitz 8612: border-right: 1px solid black;
1.1119 raeburn 8613: background-color: $data_table_light;
1.1107 raeburn 8614: list-style:none;
8615: float: none;
8616: }
8617:
8618: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8619: background-color: $data_table_dark;
1.807 droeschl 8620: }
8621:
1.847 tempelho 8622: ul.LC_TabContent {
1.911 bisitz 8623: display:block;
8624: background: $sidebg;
8625: border-bottom: solid 1px $lg_border_color;
8626: list-style:none;
1.1020 raeburn 8627: margin: -1px -10px 0 -10px;
1.911 bisitz 8628: padding: 0;
1.693 droeschl 8629: }
8630:
1.795 www 8631: ul.LC_TabContent li,
8632: ul.LC_TabContentBigger li {
1.911 bisitz 8633: float:left;
1.741 harmsja 8634: }
1.795 www 8635:
1.897 wenzelju 8636: ul#LC_secondary_menu li a {
1.911 bisitz 8637: color: $fontmenu;
8638: text-decoration: none;
1.693 droeschl 8639: }
1.795 www 8640:
1.721 harmsja 8641: ul.LC_TabContent {
1.952 onken 8642: min-height:20px;
1.721 harmsja 8643: }
1.795 www 8644:
8645: ul.LC_TabContent li {
1.911 bisitz 8646: vertical-align:middle;
1.959 onken 8647: padding: 0 16px 0 10px;
1.911 bisitz 8648: background-color:$tabbg;
8649: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8650: border-left: solid 1px $font;
1.721 harmsja 8651: }
1.795 www 8652:
1.847 tempelho 8653: ul.LC_TabContent .right {
1.911 bisitz 8654: float:right;
1.847 tempelho 8655: }
8656:
1.911 bisitz 8657: ul.LC_TabContent li a,
8658: ul.LC_TabContent li {
8659: color:rgb(47,47,47);
8660: text-decoration:none;
8661: font-size:95%;
8662: font-weight:bold;
1.952 onken 8663: min-height:20px;
8664: }
8665:
1.959 onken 8666: ul.LC_TabContent li a:hover,
8667: ul.LC_TabContent li a:focus {
1.952 onken 8668: color: $button_hover;
1.959 onken 8669: background:none;
8670: outline:none;
1.952 onken 8671: }
8672:
8673: ul.LC_TabContent li:hover {
8674: color: $button_hover;
8675: cursor:pointer;
1.721 harmsja 8676: }
1.795 www 8677:
1.911 bisitz 8678: ul.LC_TabContent li.active {
1.952 onken 8679: color: $font;
1.911 bisitz 8680: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8681: border-bottom:solid 1px #FFFFFF;
8682: cursor: default;
1.744 ehlerst 8683: }
1.795 www 8684:
1.959 onken 8685: ul.LC_TabContent li.active a {
8686: color:$font;
8687: background:#FFFFFF;
8688: outline: none;
8689: }
1.1047 raeburn 8690:
8691: ul.LC_TabContent li.goback {
8692: float: left;
8693: border-left: none;
8694: }
8695:
1.870 tempelho 8696: #maincoursedoc {
1.911 bisitz 8697: clear:both;
1.870 tempelho 8698: }
8699:
8700: ul.LC_TabContentBigger {
1.911 bisitz 8701: display:block;
8702: list-style:none;
8703: padding: 0;
1.870 tempelho 8704: }
8705:
1.795 www 8706: ul.LC_TabContentBigger li {
1.911 bisitz 8707: vertical-align:bottom;
8708: height: 30px;
8709: font-size:110%;
8710: font-weight:bold;
8711: color: #737373;
1.841 tempelho 8712: }
8713:
1.957 onken 8714: ul.LC_TabContentBigger li.active {
8715: position: relative;
8716: top: 1px;
8717: }
8718:
1.870 tempelho 8719: ul.LC_TabContentBigger li a {
1.911 bisitz 8720: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8721: height: 30px;
8722: line-height: 30px;
8723: text-align: center;
8724: display: block;
8725: text-decoration: none;
1.958 onken 8726: outline: none;
1.741 harmsja 8727: }
1.795 www 8728:
1.870 tempelho 8729: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8730: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8731: color:$font;
1.744 ehlerst 8732: }
1.795 www 8733:
1.870 tempelho 8734: ul.LC_TabContentBigger li b {
1.911 bisitz 8735: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8736: display: block;
8737: float: left;
8738: padding: 0 30px;
1.957 onken 8739: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8740: }
8741:
1.956 onken 8742: ul.LC_TabContentBigger li:hover b {
8743: color:$button_hover;
8744: }
8745:
1.870 tempelho 8746: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8747: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8748: color:$font;
1.957 onken 8749: border: 0;
1.741 harmsja 8750: }
1.693 droeschl 8751:
1.870 tempelho 8752:
1.862 bisitz 8753: ul.LC_CourseBreadcrumbs {
8754: background: $sidebg;
1.1020 raeburn 8755: height: 2em;
1.862 bisitz 8756: padding-left: 10px;
1.1020 raeburn 8757: margin: 0;
1.862 bisitz 8758: list-style-position: inside;
8759: }
8760:
1.911 bisitz 8761: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8762: ol#LC_PathBreadcrumbs {
1.911 bisitz 8763: padding-left: 10px;
8764: margin: 0;
1.933 droeschl 8765: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8766: }
8767:
1.911 bisitz 8768: ol#LC_MenuBreadcrumbs li,
8769: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8770: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8771: display: inline;
1.933 droeschl 8772: white-space: normal;
1.693 droeschl 8773: }
8774:
1.823 bisitz 8775: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8776: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8777: text-decoration: none;
8778: font-size:90%;
1.693 droeschl 8779: }
1.795 www 8780:
1.969 droeschl 8781: ol#LC_MenuBreadcrumbs h1 {
8782: display: inline;
8783: font-size: 90%;
8784: line-height: 2.5em;
8785: margin: 0;
8786: padding: 0;
8787: }
8788:
1.795 www 8789: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8790: text-decoration:none;
8791: font-size:100%;
8792: font-weight:bold;
1.693 droeschl 8793: }
1.795 www 8794:
1.840 bisitz 8795: .LC_Box {
1.911 bisitz 8796: border: solid 1px $lg_border_color;
8797: padding: 0 10px 10px 10px;
1.746 neumanie 8798: }
1.795 www 8799:
1.1020 raeburn 8800: .LC_DocsBox {
8801: border: solid 1px $lg_border_color;
8802: padding: 0 0 10px 10px;
8803: }
8804:
1.795 www 8805: .LC_AboutMe_Image {
1.911 bisitz 8806: float:left;
8807: margin-right:10px;
1.747 neumanie 8808: }
1.795 www 8809:
8810: .LC_Clear_AboutMe_Image {
1.911 bisitz 8811: clear:left;
1.747 neumanie 8812: }
1.795 www 8813:
1.721 harmsja 8814: dl.LC_ListStyleClean dt {
1.911 bisitz 8815: padding-right: 5px;
8816: display: table-header-group;
1.693 droeschl 8817: }
8818:
1.721 harmsja 8819: dl.LC_ListStyleClean dd {
1.911 bisitz 8820: display: table-row;
1.693 droeschl 8821: }
8822:
1.721 harmsja 8823: .LC_ListStyleClean,
8824: .LC_ListStyleSimple,
8825: .LC_ListStyleNormal,
1.795 www 8826: .LC_ListStyleSpecial {
1.911 bisitz 8827: /* display:block; */
8828: list-style-position: inside;
8829: list-style-type: none;
8830: overflow: hidden;
8831: padding: 0;
1.693 droeschl 8832: }
8833:
1.721 harmsja 8834: .LC_ListStyleSimple li,
8835: .LC_ListStyleSimple dd,
8836: .LC_ListStyleNormal li,
8837: .LC_ListStyleNormal dd,
8838: .LC_ListStyleSpecial li,
1.795 www 8839: .LC_ListStyleSpecial dd {
1.911 bisitz 8840: margin: 0;
8841: padding: 5px 5px 5px 10px;
8842: clear: both;
1.693 droeschl 8843: }
8844:
1.721 harmsja 8845: .LC_ListStyleClean li,
8846: .LC_ListStyleClean dd {
1.911 bisitz 8847: padding-top: 0;
8848: padding-bottom: 0;
1.693 droeschl 8849: }
8850:
1.721 harmsja 8851: .LC_ListStyleSimple dd,
1.795 www 8852: .LC_ListStyleSimple li {
1.911 bisitz 8853: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8854: }
8855:
1.721 harmsja 8856: .LC_ListStyleSpecial li,
8857: .LC_ListStyleSpecial dd {
1.911 bisitz 8858: list-style-type: none;
8859: background-color: RGB(220, 220, 220);
8860: margin-bottom: 4px;
1.693 droeschl 8861: }
8862:
1.721 harmsja 8863: table.LC_SimpleTable {
1.911 bisitz 8864: margin:5px;
8865: border:solid 1px $lg_border_color;
1.795 www 8866: }
1.693 droeschl 8867:
1.721 harmsja 8868: table.LC_SimpleTable tr {
1.911 bisitz 8869: padding: 0;
8870: border:solid 1px $lg_border_color;
1.693 droeschl 8871: }
1.795 www 8872:
8873: table.LC_SimpleTable thead {
1.911 bisitz 8874: background:rgb(220,220,220);
1.693 droeschl 8875: }
8876:
1.721 harmsja 8877: div.LC_columnSection {
1.911 bisitz 8878: display: block;
8879: clear: both;
8880: overflow: hidden;
8881: margin: 0;
1.693 droeschl 8882: }
8883:
1.721 harmsja 8884: div.LC_columnSection>* {
1.911 bisitz 8885: float: left;
8886: margin: 10px 20px 10px 0;
8887: overflow:hidden;
1.693 droeschl 8888: }
1.721 harmsja 8889:
1.795 www 8890: table em {
1.911 bisitz 8891: font-weight: bold;
8892: font-style: normal;
1.748 schulted 8893: }
1.795 www 8894:
1.779 bisitz 8895: table.LC_tableBrowseRes,
1.795 www 8896: table.LC_tableOfContent {
1.911 bisitz 8897: border:none;
8898: border-spacing: 1px;
8899: padding: 3px;
8900: background-color: #FFFFFF;
8901: font-size: 90%;
1.753 droeschl 8902: }
1.789 droeschl 8903:
1.911 bisitz 8904: table.LC_tableOfContent {
8905: border-collapse: collapse;
1.789 droeschl 8906: }
8907:
1.771 droeschl 8908: table.LC_tableBrowseRes a,
1.768 schulted 8909: table.LC_tableOfContent a {
1.911 bisitz 8910: background-color: transparent;
8911: text-decoration: none;
1.753 droeschl 8912: }
8913:
1.795 www 8914: table.LC_tableOfContent img {
1.911 bisitz 8915: border: none;
8916: height: 1.3em;
8917: vertical-align: text-bottom;
8918: margin-right: 0.3em;
1.753 droeschl 8919: }
1.757 schulted 8920:
1.795 www 8921: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8922: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8923: }
8924:
1.795 www 8925: a#LC_content_toolbar_everything {
1.911 bisitz 8926: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8927: }
8928:
1.795 www 8929: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8930: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8931: }
8932:
1.795 www 8933: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8934: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8935: }
8936:
1.795 www 8937: a#LC_content_toolbar_changefolder {
1.911 bisitz 8938: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8939: }
8940:
1.795 www 8941: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8942: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8943: }
8944:
1.1043 raeburn 8945: a#LC_content_toolbar_edittoplevel {
8946: background-image:url(/res/adm/pages/edittoplevel.gif);
8947: }
8948:
1.1384 raeburn 8949: a#LC_content_toolbar_printout {
8950: background-image:url(/res/adm/pages/printout.gif);
8951: }
8952:
1.795 www 8953: ul#LC_toolbar li a:hover {
1.911 bisitz 8954: background-position: bottom center;
1.757 schulted 8955: }
8956:
1.795 www 8957: ul#LC_toolbar {
1.911 bisitz 8958: padding: 0;
8959: margin: 2px;
8960: list-style:none;
8961: position:relative;
8962: background-color:white;
1.1082 raeburn 8963: overflow: auto;
1.757 schulted 8964: }
8965:
1.795 www 8966: ul#LC_toolbar li {
1.911 bisitz 8967: border:1px solid white;
8968: padding: 0;
8969: margin: 0;
8970: float: left;
8971: display:inline;
8972: vertical-align:middle;
1.1082 raeburn 8973: white-space: nowrap;
1.911 bisitz 8974: }
1.757 schulted 8975:
1.783 amueller 8976:
1.795 www 8977: a.LC_toolbarItem {
1.911 bisitz 8978: display:block;
8979: padding: 0;
8980: margin: 0;
8981: height: 32px;
8982: width: 32px;
8983: color:white;
8984: border: none;
8985: background-repeat:no-repeat;
8986: background-color:transparent;
1.757 schulted 8987: }
8988:
1.915 droeschl 8989: ul.LC_funclist {
8990: margin: 0;
8991: padding: 0.5em 1em 0.5em 0;
8992: }
8993:
1.933 droeschl 8994: ul.LC_funclist > li:first-child {
8995: font-weight:bold;
8996: margin-left:0.8em;
8997: }
8998:
1.915 droeschl 8999: ul.LC_funclist + ul.LC_funclist {
9000: /*
9001: left border as a seperator if we have more than
9002: one list
9003: */
9004: border-left: 1px solid $sidebg;
9005: /*
9006: this hides the left border behind the border of the
9007: outer box if element is wrapped to the next 'line'
9008: */
9009: margin-left: -1px;
9010: }
9011:
1.843 bisitz 9012: ul.LC_funclist li {
1.915 droeschl 9013: display: inline;
1.782 bisitz 9014: white-space: nowrap;
1.915 droeschl 9015: margin: 0 0 0 25px;
9016: line-height: 150%;
1.782 bisitz 9017: }
9018:
1.974 wenzelju 9019: .LC_hidden {
9020: display: none;
9021: }
9022:
1.1030 www 9023: .LCmodal-overlay {
9024: position:fixed;
9025: top:0;
9026: right:0;
9027: bottom:0;
9028: left:0;
9029: height:100%;
9030: width:100%;
9031: margin:0;
9032: padding:0;
9033: background:#999;
9034: opacity:.75;
9035: filter: alpha(opacity=75);
9036: -moz-opacity: 0.75;
9037: z-index:101;
9038: }
9039:
9040: * html .LCmodal-overlay {
9041: position: absolute;
9042: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
9043: }
9044:
9045: .LCmodal-window {
9046: position:fixed;
9047: top:50%;
9048: left:50%;
9049: margin:0;
9050: padding:0;
9051: z-index:102;
9052: }
9053:
9054: * html .LCmodal-window {
9055: position:absolute;
9056: }
9057:
9058: .LCclose-window {
9059: position:absolute;
9060: width:32px;
9061: height:32px;
9062: right:8px;
9063: top:8px;
9064: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
9065: text-indent:-99999px;
9066: overflow:hidden;
9067: cursor:pointer;
9068: }
9069:
1.1369 raeburn 9070: .LCisDisabled {
9071: cursor: not-allowed;
9072: opacity: 0.5;
9073: }
9074:
9075: a[aria-disabled="true"] {
9076: color: currentColor;
9077: display: inline-block; /* For IE11/ MS Edge bug */
9078: pointer-events: none;
9079: text-decoration: none;
9080: }
9081:
1.1335 raeburn 9082: pre.LC_wordwrap {
9083: white-space: pre-wrap;
9084: white-space: -moz-pre-wrap;
9085: white-space: -pre-wrap;
9086: white-space: -o-pre-wrap;
9087: word-wrap: break-word;
9088: }
9089:
1.1100 raeburn 9090: /*
1.1231 damieng 9091: styles used for response display
9092: */
9093: div.LC_radiofoil, div.LC_rankfoil {
9094: margin: .5em 0em .5em 0em;
9095: }
9096: table.LC_itemgroup {
9097: margin-top: 1em;
9098: }
9099:
9100: /*
1.1100 raeburn 9101: styles used by TTH when "Default set of options to pass to tth/m
9102: when converting TeX" in course settings has been set
9103:
9104: option passed: -t
9105:
9106: */
9107:
9108: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
9109: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
9110: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
9111: td div.norm {line-height:normal;}
9112:
9113: /*
9114: option passed -y3
9115: */
9116:
9117: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
9118: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
9119: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
9120:
1.1230 damieng 9121: /*
9122: sections with roles, for content only
9123: */
9124: section[class^="role-"] {
9125: padding-left: 10px;
9126: padding-right: 5px;
9127: margin-top: 8px;
9128: margin-bottom: 8px;
9129: border: 1px solid #2A4;
9130: border-radius: 5px;
9131: box-shadow: 0px 1px 1px #BBB;
9132: }
9133: section[class^="role-"]>h1 {
9134: position: relative;
9135: margin: 0px;
9136: padding-top: 10px;
9137: padding-left: 40px;
9138: }
9139: section[class^="role-"]>h1:before {
9140: position: absolute;
9141: left: -5px;
9142: top: 5px;
9143: }
9144: section.role-activity>h1:before {
9145: content:url('/adm/daxe/images/section_icons/activity.png');
9146: }
9147: section.role-advice>h1:before {
9148: content:url('/adm/daxe/images/section_icons/advice.png');
9149: }
9150: section.role-bibliography>h1:before {
9151: content:url('/adm/daxe/images/section_icons/bibliography.png');
9152: }
9153: section.role-citation>h1:before {
9154: content:url('/adm/daxe/images/section_icons/citation.png');
9155: }
9156: section.role-conclusion>h1:before {
9157: content:url('/adm/daxe/images/section_icons/conclusion.png');
9158: }
9159: section.role-definition>h1:before {
9160: content:url('/adm/daxe/images/section_icons/definition.png');
9161: }
9162: section.role-demonstration>h1:before {
9163: content:url('/adm/daxe/images/section_icons/demonstration.png');
9164: }
9165: section.role-example>h1:before {
9166: content:url('/adm/daxe/images/section_icons/example.png');
9167: }
9168: section.role-explanation>h1:before {
9169: content:url('/adm/daxe/images/section_icons/explanation.png');
9170: }
9171: section.role-introduction>h1:before {
9172: content:url('/adm/daxe/images/section_icons/introduction.png');
9173: }
9174: section.role-method>h1:before {
9175: content:url('/adm/daxe/images/section_icons/method.png');
9176: }
9177: section.role-more_information>h1:before {
9178: content:url('/adm/daxe/images/section_icons/more_information.png');
9179: }
9180: section.role-objectives>h1:before {
9181: content:url('/adm/daxe/images/section_icons/objectives.png');
9182: }
9183: section.role-prerequisites>h1:before {
9184: content:url('/adm/daxe/images/section_icons/prerequisites.png');
9185: }
9186: section.role-remark>h1:before {
9187: content:url('/adm/daxe/images/section_icons/remark.png');
9188: }
9189: section.role-reminder>h1:before {
9190: content:url('/adm/daxe/images/section_icons/reminder.png');
9191: }
9192: section.role-summary>h1:before {
9193: content:url('/adm/daxe/images/section_icons/summary.png');
9194: }
9195: section.role-syntax>h1:before {
9196: content:url('/adm/daxe/images/section_icons/syntax.png');
9197: }
9198: section.role-warning>h1:before {
9199: content:url('/adm/daxe/images/section_icons/warning.png');
9200: }
9201:
1.1269 raeburn 9202: #LC_minitab_header {
9203: float:left;
9204: width:100%;
9205: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
9206: font-size:93%;
9207: line-height:normal;
9208: margin: 0.5em 0 0.5em 0;
9209: }
9210: #LC_minitab_header ul {
9211: margin:0;
9212: padding:10px 10px 0;
9213: list-style:none;
9214: }
9215: #LC_minitab_header li {
9216: float:left;
9217: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
9218: margin:0;
9219: padding:0 0 0 9px;
9220: }
9221: #LC_minitab_header a {
9222: display:block;
9223: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
9224: padding:5px 15px 4px 6px;
9225: }
9226: #LC_minitab_header #LC_current_minitab {
9227: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
9228: }
9229: #LC_minitab_header #LC_current_minitab a {
9230: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
9231: padding-bottom:5px;
9232: }
9233:
9234:
1.343 albertel 9235: END
9236: }
9237:
1.306 albertel 9238: =pod
9239:
9240: =item * &headtag()
9241:
9242: Returns a uniform footer for LON-CAPA web pages.
9243:
1.307 albertel 9244: Inputs: $title - optional title for the head
9245: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9246: $args - optional arguments
1.319 albertel 9247: force_register - if is true call registerurl so the remote is
9248: informed
1.415 albertel 9249: redirect -> array ref of
9250: 1- seconds before redirect occurs
9251: 2- url to redirect to
9252: 3- whether the side effect should occur
1.315 albertel 9253: (side effect of setting
9254: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9255: redirected to)
9256: 4- whether the redirect target should be
9257: the opener of the current (pop-up)
9258: window (side effect of setting
9259: $env{'internal.head.to_opener'} to
9260: 1, if true.
1.1388 raeburn 9261: 5- whether encrypt check should be skipped
1.352 albertel 9262: domain -> force to color decorate a page for a specific
9263: domain
9264: function -> force usage of a specific rolish color scheme
9265: bgcolor -> override the default page bgcolor
1.460 albertel 9266: no_auto_mt_title
9267: -> prevent &mt()ing the title arg
1.464 albertel 9268:
1.306 albertel 9269: =cut
9270:
9271: sub headtag {
1.313 albertel 9272: my ($title,$head_extra,$args) = @_;
1.306 albertel 9273:
1.363 albertel 9274: my $function = $args->{'function'} || &get_users_function();
9275: my $domain = $args->{'domain'} || &determinedomain();
9276: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9277: my $httphost = $args->{'use_absolute'};
1.418 albertel 9278: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9279: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9280: #time(),
1.418 albertel 9281: $env{'environment.color.timestamp'},
1.363 albertel 9282: $function,$domain,$bgcolor);
9283:
1.369 www 9284: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9285:
1.308 albertel 9286: my $result =
9287: '<head>'.
1.1160 raeburn 9288: &font_settings($args);
1.319 albertel 9289:
1.1188 raeburn 9290: my $inhibitprint;
9291: if ($args->{'print_suppress'}) {
9292: $inhibitprint = &print_suppression();
9293: }
1.1064 raeburn 9294:
1.461 albertel 9295: if (!$args->{'frameset'}) {
9296: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9297: }
1.962 droeschl 9298: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9299: $result .= Apache::lonxml::display_title();
1.319 albertel 9300: }
1.436 albertel 9301: if (!$args->{'no_nav_bar'}
9302: && !$args->{'only_body'}
9303: && !$args->{'frameset'}) {
1.1154 raeburn 9304: $result .= &help_menu_js($httphost);
1.1032 www 9305: $result.=&modal_window();
1.1038 www 9306: $result.=&togglebox_script();
1.1034 www 9307: $result.=&wishlist_window();
1.1041 www 9308: $result.=&LCprogressbarUpdate_script();
1.1034 www 9309: } else {
9310: if ($args->{'add_modal'}) {
9311: $result.=&modal_window();
9312: }
9313: if ($args->{'add_wishlist'}) {
9314: $result.=&wishlist_window();
9315: }
1.1038 www 9316: if ($args->{'add_togglebox'}) {
9317: $result.=&togglebox_script();
9318: }
1.1041 www 9319: if ($args->{'add_progressbar'}) {
9320: $result.=&LCprogressbarUpdate_script();
9321: }
1.436 albertel 9322: }
1.314 albertel 9323: if (ref($args->{'redirect'})) {
1.1388 raeburn 9324: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9325: if (!$skip_enc_check) {
9326: $url = &Apache::lonenc::check_encrypt($url);
9327: }
1.414 albertel 9328: if (!$inhibit_continue) {
9329: $env{'internal.head.redirect'} = $url;
9330: }
1.1386 raeburn 9331: $result.=<<"ADDMETA";
1.313 albertel 9332: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9333: ADDMETA
9334: if ($to_opener) {
9335: $env{'internal.head.to_opener'} = 1;
9336: my $dest = &js_escape($url);
9337: my $timeout = int($time * 1000);
9338: $result .=<<"ENDJS";
9339: <script type="text/javascript">
9340: // <![CDATA[
9341: function LC_To_Opener() {
9342: var dest = '$dest';
9343: if (dest != '') {
9344: if (window.opener != null && !window.opener.closed) {
9345: window.opener.location.href=dest;
9346: window.close();
9347: } else {
9348: window.location.href=dest;
9349: }
9350: }
9351: }
9352: \$(document).ready(function () {
9353: setTimeout('LC_To_Opener()',$timeout);
9354: });
9355: // ]]>
9356: </script>
9357: ENDJS
9358: } else {
9359: $result.=<<"ADDMETA";
1.344 albertel 9360: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9361: ADDMETA
1.1386 raeburn 9362: }
1.1210 raeburn 9363: } else {
9364: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9365: my $requrl = $env{'request.uri'};
9366: if ($requrl eq '') {
9367: $requrl = $ENV{'REQUEST_URI'};
9368: $requrl =~ s/\?.+$//;
9369: }
9370: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9371: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9372: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9373: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9374: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9375: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9376: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9377: my ($offload,$offloadoth);
1.1210 raeburn 9378: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9379: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9380: $offload = 1;
1.1353 raeburn 9381: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9382: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9383: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9384: $offloadoth = 1;
9385: $dom_in_use = $env{'user.domain'};
9386: }
9387: }
1.1340 raeburn 9388: }
9389: }
9390: unless ($offload) {
9391: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9392: if ($domdefs{'offloadoth'}{$lonhost}) {
9393: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9394: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9395: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9396: $offload = 1;
1.1352 raeburn 9397: $offloadoth = 1;
1.1340 raeburn 9398: $dom_in_use = $env{'user.domain'};
9399: }
1.1210 raeburn 9400: }
1.1340 raeburn 9401: }
9402: }
9403: }
9404: if ($offload) {
1.1358 raeburn 9405: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9406: if (($newserver eq '') && ($offloadoth)) {
9407: my @domains = &Apache::lonnet::current_machine_domains();
9408: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9409: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9410: }
9411: }
1.1340 raeburn 9412: if (($newserver) && ($newserver ne $lonhost)) {
9413: my $numsec = 5;
9414: my $timeout = $numsec * 1000;
9415: my ($newurl,$locknum,%locks,$msg);
9416: if ($env{'request.role.adv'}) {
9417: ($locknum,%locks) = &Apache::lonnet::get_locks();
9418: }
9419: my $disable_submit = 0;
9420: if ($requrl =~ /$LONCAPA::assess_re/) {
9421: $disable_submit = 1;
9422: }
9423: if ($locknum) {
9424: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9425: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9426: join(", ",sort(values(%locks)))."\n";
9427: if (&show_course()) {
9428: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9429: } else {
9430: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9431: }
1.1340 raeburn 9432: } else {
9433: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9434: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9435: }
9436: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9437: $newurl = '/adm/switchserver?otherserver='.$newserver;
9438: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9439: $newurl .= '&role='.$env{'request.role'};
9440: }
9441: if ($env{'request.symb'}) {
9442: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9443: if ($shownsymb =~ m{^/enc/}) {
9444: my $reqdmajor = 2;
9445: my $reqdminor = 11;
9446: my $reqdsubminor = 3;
9447: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9448: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9449: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9450: if (($major eq '' && $minor eq '') ||
9451: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9452: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9453: ($reqdsubminor > $subminor))))) {
9454: undef($shownsymb);
9455: }
1.1210 raeburn 9456: }
1.1340 raeburn 9457: if ($shownsymb) {
9458: &js_escape(\$shownsymb);
9459: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9460: }
1.1340 raeburn 9461: } else {
9462: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9463: &js_escape(\$shownurl);
9464: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9465: }
1.1340 raeburn 9466: }
9467: &js_escape(\$msg);
9468: $result.=<<OFFLOAD
1.1210 raeburn 9469: <meta http-equiv="pragma" content="no-cache" />
9470: <script type="text/javascript">
1.1215 raeburn 9471: // <![CDATA[
1.1210 raeburn 9472: function LC_Offload_Now() {
9473: var dest = "$newurl";
9474: if (dest != '') {
9475: window.location.href="$newurl";
9476: }
9477: }
1.1214 raeburn 9478: \$(document).ready(function () {
9479: window.alert('$msg');
9480: if ($disable_submit) {
1.1210 raeburn 9481: \$(".LC_hwk_submit").prop("disabled", true);
9482: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9483: }
9484: setTimeout('LC_Offload_Now()', $timeout);
9485: });
1.1215 raeburn 9486: // ]]>
1.1210 raeburn 9487: </script>
9488: OFFLOAD
9489: }
9490: }
9491: }
9492: }
9493: }
1.313 albertel 9494: }
1.306 albertel 9495: if (!defined($title)) {
9496: $title = 'The LearningOnline Network with CAPA';
9497: }
1.460 albertel 9498: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9499: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9500: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9501: if (!$args->{'frameset'}) {
9502: $result .= ' /';
9503: }
9504: $result .= '>'
1.1064 raeburn 9505: .$inhibitprint
1.414 albertel 9506: .$head_extra;
1.1242 raeburn 9507: my $clientmobile;
9508: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9509: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9510: } else {
9511: $clientmobile = $env{'browser.mobile'};
9512: }
9513: if ($clientmobile) {
1.1137 raeburn 9514: $result .= '
9515: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9516: <meta name="apple-mobile-web-app-capable" content="yes" />';
9517: }
1.1278 raeburn 9518: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9519: return $result.'</head>';
1.306 albertel 9520: }
9521:
9522: =pod
9523:
1.340 albertel 9524: =item * &font_settings()
9525:
9526: Returns neccessary <meta> to set the proper encoding
9527:
1.1160 raeburn 9528: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9529:
9530: =cut
9531:
9532: sub font_settings {
1.1160 raeburn 9533: my ($args) = @_;
1.340 albertel 9534: my $headerstring='';
1.1160 raeburn 9535: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9536: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9537: $headerstring.=
9538: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9539: if (!$args->{'frameset'}) {
9540: $headerstring.= ' /';
9541: }
9542: $headerstring .= '>'."\n";
1.340 albertel 9543: }
9544: return $headerstring;
9545: }
9546:
1.341 albertel 9547: =pod
9548:
1.1064 raeburn 9549: =item * &print_suppression()
9550:
9551: In course context returns css which causes the body to be blank when media="print",
9552: if printout generation is unavailable for the current resource.
9553:
9554: This could be because:
9555:
9556: (a) printstartdate is in the future
9557:
9558: (b) printenddate is in the past
9559:
9560: (c) there is an active exam block with "printout"
9561: functionality blocked
9562:
9563: Users with pav, pfo or evb privileges are exempt.
9564:
9565: Inputs: none
9566:
9567: =cut
9568:
9569:
9570: sub print_suppression {
9571: my $noprint;
9572: if ($env{'request.course.id'}) {
9573: my $scope = $env{'request.course.id'};
9574: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9575: (&Apache::lonnet::allowed('pfo',$scope))) {
9576: return;
9577: }
9578: if ($env{'request.course.sec'} ne '') {
9579: $scope .= "/$env{'request.course.sec'}";
9580: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9581: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9582: return;
1.1064 raeburn 9583: }
9584: }
9585: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9586: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9587: my $clientip = &Apache::lonnet::get_requestor_ip();
9588: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9589: if ($blocked) {
9590: my $checkrole = "cm./$cdom/$cnum";
9591: if ($env{'request.course.sec'} ne '') {
9592: $checkrole .= "/$env{'request.course.sec'}";
9593: }
9594: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9595: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9596: $noprint = 1;
9597: }
9598: }
9599: unless ($noprint) {
9600: my $symb = &Apache::lonnet::symbread();
9601: if ($symb ne '') {
9602: my $navmap = Apache::lonnavmaps::navmap->new();
9603: if (ref($navmap)) {
9604: my $res = $navmap->getBySymb($symb);
9605: if (ref($res)) {
9606: if (!$res->resprintable()) {
9607: $noprint = 1;
9608: }
9609: }
9610: }
9611: }
9612: }
9613: if ($noprint) {
9614: return <<"ENDSTYLE";
9615: <style type="text/css" media="print">
9616: body { display:none }
9617: </style>
9618: ENDSTYLE
9619: }
9620: }
9621: return;
9622: }
9623:
9624: =pod
9625:
1.341 albertel 9626: =item * &xml_begin()
9627:
9628: Returns the needed doctype and <html>
9629:
9630: Inputs: none
9631:
9632: =cut
9633:
9634: sub xml_begin {
1.1168 raeburn 9635: my ($is_frameset) = @_;
1.341 albertel 9636: my $output='';
9637:
9638: if ($env{'browser.mathml'}) {
9639: $output='<?xml version="1.0"?>'
9640: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9641: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9642:
9643: # .'<!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">] >'
9644: .'<!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">'
9645: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9646: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9647: } elsif ($is_frameset) {
9648: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9649: '<html>'."\n";
1.341 albertel 9650: } else {
1.1168 raeburn 9651: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9652: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9653: }
9654: return $output;
9655: }
1.340 albertel 9656:
9657: =pod
9658:
1.306 albertel 9659: =item * &start_page()
9660:
9661: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9662:
1.648 raeburn 9663: Inputs:
9664:
9665: =over 4
9666:
9667: $title - optional title for the page
9668:
9669: $head_extra - optional extra HTML to incude inside the <head>
9670:
9671: $args - additional optional args supported are:
9672:
9673: =over 8
9674:
9675: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9676: arg on
1.814 bisitz 9677: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9678: add_entries -> additional attributes to add to the <body>
9679: domain -> force to color decorate a page for a
1.317 albertel 9680: specific domain
1.648 raeburn 9681: function -> force usage of a specific rolish color
1.317 albertel 9682: scheme
1.648 raeburn 9683: redirect -> see &headtag()
9684: bgcolor -> override the default page bg color
9685: js_ready -> return a string ready for being used in
1.317 albertel 9686: a javascript writeln
1.648 raeburn 9687: html_encode -> return a string ready for being used in
1.320 albertel 9688: a html attribute
1.648 raeburn 9689: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9690: $forcereg arg
1.648 raeburn 9691: frameset -> if true will start with a <frameset>
1.330 albertel 9692: rather than <body>
1.648 raeburn 9693: skip_phases -> hash ref of
1.338 albertel 9694: head -> skip the <html><head> generation
9695: body -> skip all <body> generation
1.648 raeburn 9696: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9697: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9698: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9699: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9700: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9701: group -> includes the current group, if page is for a
1.1274 raeburn 9702: specific group
9703: use_absolute -> for request for external resource or syllabus, this
9704: will contain https://<hostname> if server uses
9705: https (as per hosts.tab), but request is for http
9706: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9707: links_disabled -> Links in primary and secondary menus are disabled
9708: (Can enable them once page has loaded - see lonroles.pm
9709: for an example).
1.1380 raeburn 9710: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9711:
1.648 raeburn 9712: =back
1.460 albertel 9713:
1.648 raeburn 9714: =back
1.562 albertel 9715:
1.306 albertel 9716: =cut
9717:
9718: sub start_page {
1.309 albertel 9719: my ($title,$head_extra,$args) = @_;
1.318 albertel 9720: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9721:
1.315 albertel 9722: $env{'internal.start_page'}++;
1.1359 raeburn 9723: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9724:
1.338 albertel 9725: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9726: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9727: }
1.1316 raeburn 9728:
9729: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9730: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9731: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9732: $args->{'no_primary_menu'} = 1;
9733: }
9734: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9735: $args->{'no_inline_menu'} = 1;
9736: }
9737: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9738: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9739: }
9740: } else {
9741: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9742: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9743: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9744: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9745: $args->{'no_primary_menu'} = 1;
9746: }
9747: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9748: $args->{'no_inline_menu'} = 1;
9749: }
9750: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9751: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9752: }
9753: }
9754: }
1.1316 raeburn 9755: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9756: $env{'course.'.$env{'request.course.id'}.'.domain'},
9757: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9758: } elsif ($env{'request.course.id'}) {
9759: my $expiretime=600;
9760: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9761: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9762: }
9763: my ($deeplinkmenu,$menuref);
9764: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9765: if ($menucoll) {
9766: if (ref($menuref) eq 'HASH') {
9767: %menu = %{$menuref};
9768: }
9769: if ($menu{'top'} eq 'n') {
9770: $args->{'no_primary_menu'} = 1;
9771: }
9772: if ($menu{'inline'} eq 'n') {
9773: unless (&Apache::lonnet::allowed('opa')) {
9774: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9775: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9776: my $crstype = &course_type();
9777: my $now = time;
9778: my $ccrole;
9779: if ($crstype eq 'Community') {
9780: $ccrole = 'co';
9781: } else {
9782: $ccrole = 'cc';
9783: }
9784: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9785: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9786: if ((($start) && ($start<0)) ||
9787: (($end) && ($end<$now)) ||
9788: (($start) && ($now<$start))) {
9789: $args->{'no_inline_menu'} = 1;
9790: }
9791: } else {
9792: $args->{'no_inline_menu'} = 1;
9793: }
9794: }
9795: }
9796: }
1.1316 raeburn 9797: }
1.1359 raeburn 9798:
1.1385 raeburn 9799: my $showncrumbs;
1.338 albertel 9800: if (! exists($args->{'skip_phases'}{'body'}) ) {
9801: if ($args->{'frameset'}) {
9802: my $attr_string = &make_attr_string($args->{'force_register'},
9803: $args->{'add_entries'});
9804: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9805: } else {
9806: $result .=
9807: &bodytag($title,
9808: $args->{'function'}, $args->{'add_entries'},
9809: $args->{'only_body'}, $args->{'domain'},
9810: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9811: $args->{'bgcolor'}, $args,
1.1385 raeburn 9812: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
9813: \%menu,\$showncrumbs);
1.831 bisitz 9814: }
1.330 albertel 9815: }
1.338 albertel 9816:
1.315 albertel 9817: if ($args->{'js_ready'}) {
1.713 kaisler 9818: $result = &js_ready($result);
1.315 albertel 9819: }
1.320 albertel 9820: if ($args->{'html_encode'}) {
1.713 kaisler 9821: $result = &html_encode($result);
9822: }
9823:
1.813 bisitz 9824: # Preparation for new and consistent functionlist at top of screen
9825: # if ($args->{'functionlist'}) {
9826: # $result .= &build_functionlist();
9827: #}
9828:
1.964 droeschl 9829: # Don't add anything more if only_body wanted or in const space
9830: return $result if $args->{'only_body'}
9831: || $env{'request.state'} eq 'construct';
1.813 bisitz 9832:
9833: #Breadcrumbs
1.758 kaisler 9834: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 9835: unless ($showncrumbs) {
1.758 kaisler 9836: &Apache::lonhtmlcommon::clear_breadcrumbs();
9837: #if any br links exists, add them to the breadcrumbs
9838: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9839: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9840: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9841: }
9842: }
1.1096 raeburn 9843: # if @advtools array contains items add then to the breadcrumbs
9844: if (@advtools > 0) {
9845: &Apache::lonmenu::advtools_crumbs(@advtools);
9846: }
1.1272 raeburn 9847: my $menulink;
9848: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9849: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9850: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9851: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9852: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9853: (!$env{'request.role.adv'}))) {
9854: $menulink = 0;
9855: } else {
9856: undef($menulink);
9857: }
1.1385 raeburn 9858: my $linkprotout;
9859: if ($env{'request.deeplink.login'}) {
9860: my $linkprotout = &Apache::lonmenu::linkprot_exit();
9861: if ($linkprotout) {
9862: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9863: }
9864: }
1.758 kaisler 9865: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9866: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9867: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9868: } else {
1.1272 raeburn 9869: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9870: }
1.1385 raeburn 9871: }
1.320 albertel 9872: }
1.315 albertel 9873: return $result;
1.306 albertel 9874: }
9875:
9876: sub end_page {
1.315 albertel 9877: my ($args) = @_;
9878: $env{'internal.end_page'}++;
1.330 albertel 9879: my $result;
1.335 albertel 9880: if ($args->{'discussion'}) {
9881: my ($target,$parser);
9882: if (ref($args->{'discussion'})) {
9883: ($target,$parser) =($args->{'discussion'}{'target'},
9884: $args->{'discussion'}{'parser'});
9885: }
9886: $result .= &Apache::lonxml::xmlend($target,$parser);
9887: }
1.330 albertel 9888: if ($args->{'frameset'}) {
9889: $result .= '</frameset>';
9890: } else {
1.635 raeburn 9891: $result .= &endbodytag($args);
1.330 albertel 9892: }
1.1080 raeburn 9893: unless ($args->{'notbody'}) {
9894: $result .= "\n</html>";
9895: }
1.330 albertel 9896:
1.315 albertel 9897: if ($args->{'js_ready'}) {
1.317 albertel 9898: $result = &js_ready($result);
1.315 albertel 9899: }
1.335 albertel 9900:
1.320 albertel 9901: if ($args->{'html_encode'}) {
9902: $result = &html_encode($result);
9903: }
1.335 albertel 9904:
1.315 albertel 9905: return $result;
9906: }
9907:
1.1359 raeburn 9908: sub menucoll_in_effect {
9909: my ($menucoll,$deeplinkmenu,%menu);
9910: if ($env{'request.course.id'}) {
9911: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9912: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9913: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9914: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9915: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9916: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9917: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9918: my $navmap = Apache::lonnavmaps::navmap->new();
9919: if (ref($navmap)) {
9920: $deeplink = $navmap->get_mapparam(undef,
9921: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9922: '0.deeplink');
1.1370 raeburn 9923: } else {
9924: $check_login_symb = 1;
1.1362 raeburn 9925: }
9926: } else {
1.1370 raeburn 9927: my $symb = &Apache::lonnet::symbread();
9928: if ($symb) {
9929: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9930: } else {
9931: $check_login_symb = 1;
9932: }
1.1362 raeburn 9933: }
9934: } else {
1.1370 raeburn 9935: $check_login_symb = 1;
9936: }
9937: if ($check_login_symb) {
1.1362 raeburn 9938: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9939: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9940: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9941: my $navmap = Apache::lonnavmaps::navmap->new();
9942: if (ref($navmap)) {
9943: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9944: }
9945: } else {
9946: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9947: }
9948: }
1.1359 raeburn 9949: if ($deeplink ne '') {
1.1378 raeburn 9950: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 9951: if ($display =~ /^\d+$/) {
9952: $deeplinkmenu = 1;
9953: $menucoll = $display;
9954: }
9955: }
9956: }
9957: if ($menucoll) {
9958: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9959: }
9960: }
9961: return ($menucoll,$deeplinkmenu,\%menu);
9962: }
9963:
1.1362 raeburn 9964: sub deeplink_login_symb {
9965: my ($cnum,$cdom) = @_;
9966: my $login_symb;
9967: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9968: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9969: }
9970: return $login_symb;
9971: }
9972:
9973: sub symb_from_tinyurl {
9974: my ($url,$cnum,$cdom) = @_;
9975: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9976: my $key = $1;
9977: my ($tinyurl,$login);
9978: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9979: if (defined($cached)) {
9980: $tinyurl = $result;
9981: } else {
9982: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9983: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9984: if ($currtiny{$key} ne '') {
9985: $tinyurl = $currtiny{$key};
9986: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9987: }
1.1364 raeburn 9988: }
9989: if ($tinyurl ne '') {
9990: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9991: if (wantarray) {
9992: return ($cnumreq,$symb);
9993: } elsif ($cnumreq eq $cnum) {
9994: return $symb;
1.1362 raeburn 9995: }
9996: }
9997: }
1.1364 raeburn 9998: if (wantarray) {
9999: return ();
10000: } else {
10001: return;
10002: }
1.1362 raeburn 10003: }
10004:
1.1405 raeburn 10005: sub usable_exttools {
10006: my %tooltypes;
10007: if ($env{'request.course.id'}) {
10008: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
10009: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
10010: %tooltypes = (
10011: crs => 1,
10012: dom => 1,
10013: );
10014: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
10015: $tooltypes{'crs'} = 1;
10016: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
10017: $tooltypes{'dom'} = 1;
10018: }
10019: } else {
10020: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10021: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10022: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
10023: if ($crstype eq '') {
10024: $crstype = 'course';
10025: }
10026: if ($crstype eq 'course') {
10027: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
10028: $crstype = 'official';
10029: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
10030: $crstype = 'textbook';
10031: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
10032: $crstype = 'lti';
10033: } else {
10034: $crstype = 'unofficial';
10035: }
10036: }
10037: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
10038: if ($domdefaults{$crstype.'domexttool'}) {
10039: $tooltypes{'dom'} = 1;
10040: }
10041: if ($domdefaults{$crstype.'exttool'}) {
10042: $tooltypes{'crs'} = 1;
10043: }
10044: }
10045: }
10046: return %tooltypes;
10047: }
10048:
1.1034 www 10049: sub wishlist_window {
10050: return(<<'ENDWISHLIST');
1.1046 raeburn 10051: <script type="text/javascript">
1.1034 www 10052: // <![CDATA[
10053: // <!-- BEGIN LON-CAPA Internal
10054: function set_wishlistlink(title, path) {
10055: if (!title) {
10056: title = document.title;
10057: title = title.replace(/^LON-CAPA /,'');
10058: }
1.1175 raeburn 10059: title = encodeURIComponent(title);
1.1203 raeburn 10060: title = title.replace("'","\\\'");
1.1034 www 10061: if (!path) {
10062: path = location.pathname;
10063: }
1.1175 raeburn 10064: path = encodeURIComponent(path);
1.1203 raeburn 10065: path = path.replace("'","\\\'");
1.1034 www 10066: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
10067: 'wishlistNewLink','width=560,height=350,scrollbars=0');
10068: }
10069: // END LON-CAPA Internal -->
10070: // ]]>
10071: </script>
10072: ENDWISHLIST
10073: }
10074:
1.1030 www 10075: sub modal_window {
10076: return(<<'ENDMODAL');
1.1046 raeburn 10077: <script type="text/javascript">
1.1030 www 10078: // <![CDATA[
10079: // <!-- BEGIN LON-CAPA Internal
10080: var modalWindow = {
10081: parent:"body",
10082: windowId:null,
10083: content:null,
10084: width:null,
10085: height:null,
10086: close:function()
10087: {
10088: $(".LCmodal-window").remove();
10089: $(".LCmodal-overlay").remove();
10090: },
10091: open:function()
10092: {
10093: var modal = "";
10094: modal += "<div class=\"LCmodal-overlay\"></div>";
10095: 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;\">";
10096: modal += this.content;
10097: modal += "</div>";
10098:
10099: $(this.parent).append(modal);
10100:
10101: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
10102: $(".LCclose-window").click(function(){modalWindow.close();});
10103: $(".LCmodal-overlay").click(function(){modalWindow.close();});
10104: }
10105: };
1.1140 raeburn 10106: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 10107: {
1.1266 raeburn 10108: source = source.replace(/'/g,"'");
1.1030 www 10109: modalWindow.windowId = "myModal";
10110: modalWindow.width = width;
10111: modalWindow.height = height;
1.1196 raeburn 10112: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 10113: modalWindow.open();
1.1208 raeburn 10114: };
1.1030 www 10115: // END LON-CAPA Internal -->
10116: // ]]>
10117: </script>
10118: ENDMODAL
10119: }
10120:
10121: sub modal_link {
1.1140 raeburn 10122: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 10123: unless ($width) { $width=480; }
10124: unless ($height) { $height=400; }
1.1031 www 10125: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 10126: unless ($transparency) { $transparency='true'; }
10127:
1.1074 raeburn 10128: my $target_attr;
10129: if (defined($target)) {
10130: $target_attr = 'target="'.$target.'"';
10131: }
10132: return <<"ENDLINK";
1.1336 raeburn 10133: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 10134: ENDLINK
1.1030 www 10135: }
10136:
1.1032 www 10137: sub modal_adhoc_script {
1.1365 raeburn 10138: my ($funcname,$width,$height,$content,$possmathjax)=@_;
10139: my $mathjax;
10140: if ($possmathjax) {
10141: $mathjax = <<'ENDJAX';
10142: if (typeof MathJax == 'object') {
10143: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
10144: }
10145: ENDJAX
10146: }
1.1032 www 10147: return (<<ENDADHOC);
1.1046 raeburn 10148: <script type="text/javascript">
1.1032 www 10149: // <![CDATA[
10150: var $funcname = function()
10151: {
10152: modalWindow.windowId = "myModal";
10153: modalWindow.width = $width;
10154: modalWindow.height = $height;
10155: modalWindow.content = '$content';
10156: modalWindow.open();
1.1365 raeburn 10157: $mathjax
1.1032 www 10158: };
10159: // ]]>
10160: </script>
10161: ENDADHOC
10162: }
10163:
1.1041 www 10164: sub modal_adhoc_inner {
1.1365 raeburn 10165: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 10166: my $innerwidth=$width-20;
10167: $content=&js_ready(
1.1140 raeburn 10168: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
10169: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
10170: $content.
1.1041 www 10171: &end_scrollbox().
1.1140 raeburn 10172: &end_page()
1.1041 www 10173: );
1.1365 raeburn 10174: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 10175: }
10176:
10177: sub modal_adhoc_window {
1.1365 raeburn 10178: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
10179: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 10180: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
10181: }
10182:
10183: sub modal_adhoc_launch {
10184: my ($funcname,$width,$height,$content)=@_;
10185: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
10186: <script type="text/javascript">
10187: // <![CDATA[
10188: $funcname();
10189: // ]]>
10190: </script>
10191: ENDLAUNCH
10192: }
10193:
10194: sub modal_adhoc_close {
10195: return (<<ENDCLOSE);
10196: <script type="text/javascript">
10197: // <![CDATA[
10198: modalWindow.close();
10199: // ]]>
10200: </script>
10201: ENDCLOSE
10202: }
10203:
1.1038 www 10204: sub togglebox_script {
10205: return(<<ENDTOGGLE);
10206: <script type="text/javascript">
10207: // <![CDATA[
10208: function LCtoggleDisplay(id,hidetext,showtext) {
10209: link = document.getElementById(id + "link").childNodes[0];
10210: with (document.getElementById(id).style) {
10211: if (display == "none" ) {
10212: display = "inline";
10213: link.nodeValue = hidetext;
10214: } else {
10215: display = "none";
10216: link.nodeValue = showtext;
10217: }
10218: }
10219: }
10220: // ]]>
10221: </script>
10222: ENDTOGGLE
10223: }
10224:
1.1039 www 10225: sub start_togglebox {
10226: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
10227: unless ($heading) { $heading=''; } else { $heading.=' '; }
10228: unless ($showtext) { $showtext=&mt('show'); }
10229: unless ($hidetext) { $hidetext=&mt('hide'); }
10230: unless ($headerbg) { $headerbg='#FFFFFF'; }
10231: return &start_data_table().
10232: &start_data_table_header_row().
10233: '<td bgcolor="'.$headerbg.'">'.$heading.
10234: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
10235: $showtext.'\')">'.$showtext.'</a>]</td>'.
10236: &end_data_table_header_row().
10237: '<tr id="'.$id.'" style="display:none""><td>';
10238: }
10239:
10240: sub end_togglebox {
10241: return '</td></tr>'.&end_data_table();
10242: }
10243:
1.1041 www 10244: sub LCprogressbar_script {
1.1302 raeburn 10245: my ($id,$number_to_do)=@_;
10246: if ($number_to_do) {
10247: return(<<ENDPROGRESS);
1.1041 www 10248: <script type="text/javascript">
10249: // <![CDATA[
1.1045 www 10250: \$('#progressbar$id').progressbar({
1.1041 www 10251: value: 0,
10252: change: function(event, ui) {
10253: var newVal = \$(this).progressbar('option', 'value');
10254: \$('.pblabel', this).text(LCprogressTxt);
10255: }
10256: });
10257: // ]]>
10258: </script>
10259: ENDPROGRESS
1.1302 raeburn 10260: } else {
10261: return(<<ENDPROGRESS);
10262: <script type="text/javascript">
10263: // <![CDATA[
10264: \$('#progressbar$id').progressbar({
10265: value: false,
10266: create: function(event, ui) {
10267: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10268: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10269: }
10270: });
10271: // ]]>
10272: </script>
10273: ENDPROGRESS
10274: }
1.1041 www 10275: }
10276:
10277: sub LCprogressbarUpdate_script {
10278: return(<<ENDPROGRESSUPDATE);
10279: <style type="text/css">
10280: .ui-progressbar { position:relative; }
1.1302 raeburn 10281: .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 10282: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10283: </style>
10284: <script type="text/javascript">
10285: // <![CDATA[
1.1045 www 10286: var LCprogressTxt='---';
10287:
1.1302 raeburn 10288: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10289: LCprogressTxt=progresstext;
1.1302 raeburn 10290: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10291: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10292: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10293: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10294: } else {
10295: \$('#progressbar'+id).progressbar('value',percent);
10296: }
1.1041 www 10297: }
10298: // ]]>
10299: </script>
10300: ENDPROGRESSUPDATE
10301: }
10302:
1.1042 www 10303: my $LClastpercent;
1.1045 www 10304: my $LCidcnt;
10305: my $LCcurrentid;
1.1042 www 10306:
1.1041 www 10307: sub LCprogressbar {
1.1302 raeburn 10308: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10309: $LClastpercent=0;
1.1045 www 10310: $LCidcnt++;
10311: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10312: my ($starting,$content);
10313: if ($number_to_do) {
10314: $starting=&mt('Starting');
10315: $content=(<<ENDPROGBAR);
10316: $preamble
1.1045 www 10317: <div id="progressbar$LCcurrentid">
1.1041 www 10318: <span class="pblabel">$starting</span>
10319: </div>
10320: ENDPROGBAR
1.1302 raeburn 10321: } else {
10322: $starting=&mt('Loading...');
10323: $LClastpercent='false';
10324: $content=(<<ENDPROGBAR);
10325: $preamble
10326: <div id="progressbar$LCcurrentid">
10327: <div class="progress-label">$starting</div>
10328: </div>
10329: ENDPROGBAR
10330: }
10331: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10332: }
10333:
10334: sub LCprogressbarUpdate {
1.1302 raeburn 10335: my ($r,$val,$text,$number_to_do)=@_;
10336: if ($number_to_do) {
10337: unless ($val) {
10338: if ($LClastpercent) {
10339: $val=$LClastpercent;
10340: } else {
10341: $val=0;
10342: }
10343: }
10344: if ($val<0) { $val=0; }
10345: if ($val>100) { $val=0; }
10346: $LClastpercent=$val;
10347: unless ($text) { $text=$val.'%'; }
10348: } else {
10349: $val = 'false';
1.1042 www 10350: }
1.1041 www 10351: $text=&js_ready($text);
1.1044 www 10352: &r_print($r,<<ENDUPDATE);
1.1041 www 10353: <script type="text/javascript">
10354: // <![CDATA[
1.1302 raeburn 10355: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10356: // ]]>
10357: </script>
10358: ENDUPDATE
1.1035 www 10359: }
10360:
1.1042 www 10361: sub LCprogressbarClose {
10362: my ($r)=@_;
10363: $LClastpercent=0;
1.1044 www 10364: &r_print($r,<<ENDCLOSE);
1.1042 www 10365: <script type="text/javascript">
10366: // <![CDATA[
1.1045 www 10367: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10368: // ]]>
10369: </script>
10370: ENDCLOSE
1.1044 www 10371: }
10372:
10373: sub r_print {
10374: my ($r,$to_print)=@_;
10375: if ($r) {
10376: $r->print($to_print);
10377: $r->rflush();
10378: } else {
10379: print($to_print);
10380: }
1.1042 www 10381: }
10382:
1.320 albertel 10383: sub html_encode {
10384: my ($result) = @_;
10385:
1.322 albertel 10386: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10387:
10388: return $result;
10389: }
1.1044 www 10390:
1.317 albertel 10391: sub js_ready {
10392: my ($result) = @_;
10393:
1.323 albertel 10394: $result =~ s/[\n\r]/ /xmsg;
10395: $result =~ s/\\/\\\\/xmsg;
10396: $result =~ s/'/\\'/xmsg;
1.372 albertel 10397: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10398:
10399: return $result;
10400: }
10401:
1.315 albertel 10402: sub validate_page {
10403: if ( exists($env{'internal.start_page'})
1.316 albertel 10404: && $env{'internal.start_page'} > 1) {
10405: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10406: $env{'internal.start_page'}.' '.
1.316 albertel 10407: $ENV{'request.filename'});
1.315 albertel 10408: }
10409: if ( exists($env{'internal.end_page'})
1.316 albertel 10410: && $env{'internal.end_page'} > 1) {
10411: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10412: $env{'internal.end_page'}.' '.
1.316 albertel 10413: $env{'request.filename'});
1.315 albertel 10414: }
10415: if ( exists($env{'internal.start_page'})
10416: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10417: &Apache::lonnet::logthis('start_page called without end_page '.
10418: $env{'request.filename'});
1.315 albertel 10419: }
10420: if ( ! exists($env{'internal.start_page'})
10421: && exists($env{'internal.end_page'})) {
1.316 albertel 10422: &Apache::lonnet::logthis('end_page called without start_page'.
10423: $env{'request.filename'});
1.315 albertel 10424: }
1.306 albertel 10425: }
1.315 albertel 10426:
1.996 www 10427:
10428: sub start_scrollbox {
1.1140 raeburn 10429: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10430: unless ($outerwidth) { $outerwidth='520px'; }
10431: unless ($width) { $width='500px'; }
10432: unless ($height) { $height='200px'; }
1.1075 raeburn 10433: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10434: if ($id ne '') {
1.1140 raeburn 10435: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10436: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10437: }
1.1075 raeburn 10438: if ($bgcolor ne '') {
10439: $tdcol = "background-color: $bgcolor;";
10440: }
1.1137 raeburn 10441: my $nicescroll_js;
10442: if ($env{'browser.mobile'}) {
1.1140 raeburn 10443: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10444: }
10445: return <<"END";
10446: $nicescroll_js
10447:
10448: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10449: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10450: END
10451: }
10452:
10453: sub end_scrollbox {
10454: return '</div></td></tr></table>';
10455: }
10456:
10457: sub nicescroll_javascript {
10458: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10459: my %options;
10460: if (ref($cursor) eq 'HASH') {
10461: %options = %{$cursor};
10462: }
10463: unless ($options{'railalign'} =~ /^left|right$/) {
10464: $options{'railalign'} = 'left';
10465: }
10466: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10467: my $function = &get_users_function();
10468: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10469: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10470: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10471: }
1.1140 raeburn 10472: }
10473: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10474: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10475: $options{'cursoropacity'}='1.0';
10476: }
1.1140 raeburn 10477: } else {
10478: $options{'cursoropacity'}='1.0';
10479: }
10480: if ($options{'cursorfixedheight'} eq 'none') {
10481: delete($options{'cursorfixedheight'});
10482: } else {
10483: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10484: }
10485: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10486: delete($options{'railoffset'});
10487: }
10488: my @niceoptions;
10489: while (my($key,$value) = each(%options)) {
10490: if ($value =~ /^\{.+\}$/) {
10491: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10492: } else {
1.1140 raeburn 10493: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10494: }
1.1140 raeburn 10495: }
10496: my $nicescroll_js = '
1.1137 raeburn 10497: $(document).ready(
1.1140 raeburn 10498: function() {
10499: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10500: }
1.1137 raeburn 10501: );
10502: ';
1.1140 raeburn 10503: if ($framecheck) {
10504: $nicescroll_js .= '
10505: function expand_div(caller) {
10506: if (top === self) {
10507: document.getElementById("'.$id.'").style.width = "auto";
10508: document.getElementById("'.$id.'").style.height = "auto";
10509: } else {
10510: try {
10511: if (parent.frames) {
10512: if (parent.frames.length > 1) {
10513: var framesrc = parent.frames[1].location.href;
10514: var currsrc = framesrc.replace(/\#.*$/,"");
10515: if ((caller == "search") || (currsrc == "'.$location.'")) {
10516: document.getElementById("'.$id.'").style.width = "auto";
10517: document.getElementById("'.$id.'").style.height = "auto";
10518: }
10519: }
10520: }
10521: } catch (e) {
10522: return;
10523: }
1.1137 raeburn 10524: }
1.1140 raeburn 10525: return;
1.996 www 10526: }
1.1140 raeburn 10527: ';
10528: }
10529: if ($needjsready) {
10530: $nicescroll_js = '
10531: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10532: } else {
10533: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10534: }
10535: return $nicescroll_js;
1.996 www 10536: }
10537:
1.318 albertel 10538: sub simple_error_page {
1.1150 bisitz 10539: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10540: my %displayargs;
1.1151 raeburn 10541: if (ref($args) eq 'HASH') {
10542: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10543: if ($args->{'only_body'}) {
10544: $displayargs{'only_body'} = 1;
10545: }
10546: if ($args->{'no_nav_bar'}) {
10547: $displayargs{'no_nav_bar'} = 1;
10548: }
1.1151 raeburn 10549: } else {
10550: $msg = &mt($msg);
10551: }
1.1150 bisitz 10552:
1.318 albertel 10553: my $page =
1.1304 raeburn 10554: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10555: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10556: &Apache::loncommon::end_page();
10557: if (ref($r)) {
10558: $r->print($page);
1.327 albertel 10559: return;
1.318 albertel 10560: }
10561: return $page;
10562: }
1.347 albertel 10563:
10564: {
1.610 albertel 10565: my @row_count;
1.961 onken 10566:
10567: sub start_data_table_count {
10568: unshift(@row_count, 0);
10569: return;
10570: }
10571:
10572: sub end_data_table_count {
10573: shift(@row_count);
10574: return;
10575: }
10576:
1.347 albertel 10577: sub start_data_table {
1.1018 raeburn 10578: my ($add_class,$id) = @_;
1.422 albertel 10579: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10580: my $table_id;
10581: if (defined($id)) {
10582: $table_id = ' id="'.$id.'"';
10583: }
1.961 onken 10584: &start_data_table_count();
1.1018 raeburn 10585: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10586: }
10587:
10588: sub end_data_table {
1.961 onken 10589: &end_data_table_count();
1.389 albertel 10590: return '</table>'."\n";;
1.347 albertel 10591: }
10592:
10593: sub start_data_table_row {
1.974 wenzelju 10594: my ($add_class, $id) = @_;
1.610 albertel 10595: $row_count[0]++;
10596: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10597: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10598: $id = (' id="'.$id.'"') unless ($id eq '');
10599: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10600: }
1.471 banghart 10601:
10602: sub continue_data_table_row {
1.974 wenzelju 10603: my ($add_class, $id) = @_;
1.610 albertel 10604: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10605: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10606: $id = (' id="'.$id.'"') unless ($id eq '');
10607: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10608: }
1.347 albertel 10609:
10610: sub end_data_table_row {
1.389 albertel 10611: return '</tr>'."\n";;
1.347 albertel 10612: }
1.367 www 10613:
1.421 albertel 10614: sub start_data_table_empty_row {
1.707 bisitz 10615: # $row_count[0]++;
1.421 albertel 10616: return '<tr class="LC_empty_row" >'."\n";;
10617: }
10618:
10619: sub end_data_table_empty_row {
10620: return '</tr>'."\n";;
10621: }
10622:
1.367 www 10623: sub start_data_table_header_row {
1.389 albertel 10624: return '<tr class="LC_header_row">'."\n";;
1.367 www 10625: }
10626:
10627: sub end_data_table_header_row {
1.389 albertel 10628: return '</tr>'."\n";;
1.367 www 10629: }
1.890 droeschl 10630:
10631: sub data_table_caption {
10632: my $caption = shift;
10633: return "<caption class=\"LC_caption\">$caption</caption>";
10634: }
1.347 albertel 10635: }
10636:
1.548 albertel 10637: =pod
10638:
10639: =item * &inhibit_menu_check($arg)
10640:
10641: Checks for a inhibitmenu state and generates output to preserve it
10642:
10643: Inputs: $arg - can be any of
10644: - undef - in which case the return value is a string
10645: to add into arguments list of a uri
10646: - 'input' - in which case the return value is a HTML
10647: <form> <input> field of type hidden to
10648: preserve the value
10649: - a url - in which case the return value is the url with
10650: the neccesary cgi args added to preserve the
10651: inhibitmenu state
10652: - a ref to a url - no return value, but the string is
10653: updated to include the neccessary cgi
10654: args to preserve the inhibitmenu state
10655:
10656: =cut
10657:
10658: sub inhibit_menu_check {
10659: my ($arg) = @_;
10660: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10661: if ($arg eq 'input') {
10662: if ($env{'form.inhibitmenu'}) {
10663: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10664: } else {
10665: return
10666: }
10667: }
10668: if ($env{'form.inhibitmenu'}) {
10669: if (ref($arg)) {
10670: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10671: } elsif ($arg eq '') {
10672: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10673: } else {
10674: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10675: }
10676: }
10677: if (!ref($arg)) {
10678: return $arg;
10679: }
10680: }
10681:
1.251 albertel 10682: ###############################################
1.182 matthew 10683:
10684: =pod
10685:
1.549 albertel 10686: =back
10687:
10688: =head1 User Information Routines
10689:
10690: =over 4
10691:
1.405 albertel 10692: =item * &get_users_function()
1.182 matthew 10693:
10694: Used by &bodytag to determine the current users primary role.
10695: Returns either 'student','coordinator','admin', or 'author'.
10696:
10697: =cut
10698:
10699: ###############################################
10700: sub get_users_function {
1.815 tempelho 10701: my $function = 'norole';
1.818 tempelho 10702: if ($env{'request.role'}=~/^(st)/) {
10703: $function='student';
10704: }
1.907 raeburn 10705: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10706: $function='coordinator';
10707: }
1.258 albertel 10708: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10709: $function='admin';
10710: }
1.826 bisitz 10711: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10712: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10713: $function='author';
10714: }
10715: return $function;
1.54 www 10716: }
1.99 www 10717:
10718: ###############################################
10719:
1.233 raeburn 10720: =pod
10721:
1.821 raeburn 10722: =item * &show_course()
10723:
10724: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10725: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10726:
10727: Inputs:
10728: None
10729:
10730: Outputs:
10731: Scalar: 1 if 'Course' to be used, 0 otherwise.
10732:
10733: =cut
10734:
10735: ###############################################
10736: sub show_course {
1.1408 raeburn 10737: my ($udom,$uname) = @_;
10738: if (($udom ne '') && ($uname ne '')) {
10739: if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
1.1410 raeburn 10740: if (&Apache::lonnet::is_advanced_user($udom,$uname)) {
1.1408 raeburn 10741: return 0;
10742: } else {
10743: return 1;
10744: }
10745: }
10746: }
1.821 raeburn 10747: my $course = !$env{'user.adv'};
10748: if (!$env{'user.adv'}) {
10749: foreach my $env (keys(%env)) {
10750: next if ($env !~ m/^user\.priv\./);
10751: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10752: $course = 0;
10753: last;
10754: }
10755: }
10756: }
10757: return $course;
10758: }
10759:
10760: ###############################################
10761:
10762: =pod
10763:
1.542 raeburn 10764: =item * &check_user_status()
1.274 raeburn 10765:
10766: Determines current status of supplied role for a
10767: specific user. Roles can be active, previous or future.
10768:
10769: Inputs:
10770: user's domain, user's username, course's domain,
1.375 raeburn 10771: course's number, optional section ID.
1.274 raeburn 10772:
10773: Outputs:
10774: role status: active, previous or future.
10775:
10776: =cut
10777:
10778: sub check_user_status {
1.412 raeburn 10779: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10780: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10781: my @uroles = keys(%userinfo);
1.274 raeburn 10782: my $srchstr;
10783: my $active_chk = 'none';
1.412 raeburn 10784: my $now = time;
1.274 raeburn 10785: if (@uroles > 0) {
1.908 raeburn 10786: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10787: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10788: } else {
1.412 raeburn 10789: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10790: }
10791: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10792: my $role_end = 0;
10793: my $role_start = 0;
10794: $active_chk = 'active';
1.412 raeburn 10795: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10796: $role_end = $1;
10797: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10798: $role_start = $1;
1.274 raeburn 10799: }
10800: }
10801: if ($role_start > 0) {
1.412 raeburn 10802: if ($now < $role_start) {
1.274 raeburn 10803: $active_chk = 'future';
10804: }
10805: }
10806: if ($role_end > 0) {
1.412 raeburn 10807: if ($now > $role_end) {
1.274 raeburn 10808: $active_chk = 'previous';
10809: }
10810: }
10811: }
10812: }
10813: return $active_chk;
10814: }
10815:
10816: ###############################################
10817:
10818: =pod
10819:
1.405 albertel 10820: =item * &get_sections()
1.233 raeburn 10821:
10822: Determines all the sections for a course including
10823: sections with students and sections containing other roles.
1.419 raeburn 10824: Incoming parameters:
10825:
10826: 1. domain
10827: 2. course number
10828: 3. reference to array containing roles for which sections should
10829: be gathered (optional).
10830: 4. reference to array containing status types for which sections
10831: should be gathered (optional).
10832:
10833: If the third argument is undefined, sections are gathered for any role.
10834: If the fourth argument is undefined, sections are gathered for any status.
10835: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10836:
1.374 raeburn 10837: Returns section hash (keys are section IDs, values are
10838: number of users in each section), subject to the
1.419 raeburn 10839: optional roles filter, optional status filter
1.233 raeburn 10840:
10841: =cut
10842:
10843: ###############################################
10844: sub get_sections {
1.419 raeburn 10845: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10846: if (!defined($cdom) || !defined($cnum)) {
10847: my $cid = $env{'request.course.id'};
10848:
10849: return if (!defined($cid));
10850:
10851: $cdom = $env{'course.'.$cid.'.domain'};
10852: $cnum = $env{'course.'.$cid.'.num'};
10853: }
10854:
10855: my %sectioncount;
1.419 raeburn 10856: my $now = time;
1.240 albertel 10857:
1.1118 raeburn 10858: my $check_students = 1;
10859: my $only_students = 0;
10860: if (ref($possible_roles) eq 'ARRAY') {
10861: if (grep(/^st$/,@{$possible_roles})) {
10862: if (@{$possible_roles} == 1) {
10863: $only_students = 1;
10864: }
10865: } else {
10866: $check_students = 0;
10867: }
10868: }
10869:
10870: if ($check_students) {
1.276 albertel 10871: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10872: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10873: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10874: my $start_index = &Apache::loncoursedata::CL_START();
10875: my $end_index = &Apache::loncoursedata::CL_END();
10876: my $status;
1.366 albertel 10877: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10878: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10879: $data->[$status_index],
10880: $data->[$start_index],
10881: $data->[$end_index]);
10882: if ($stu_status eq 'Active') {
10883: $status = 'active';
10884: } elsif ($end < $now) {
10885: $status = 'previous';
10886: } elsif ($start > $now) {
10887: $status = 'future';
10888: }
10889: if ($section ne '-1' && $section !~ /^\s*$/) {
10890: if ((!defined($possible_status)) || (($status ne '') &&
10891: (grep/^\Q$status\E$/,@{$possible_status}))) {
10892: $sectioncount{$section}++;
10893: }
1.240 albertel 10894: }
10895: }
10896: }
1.1118 raeburn 10897: if ($only_students) {
10898: return %sectioncount;
10899: }
1.240 albertel 10900: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10901: foreach my $user (sort(keys(%courseroles))) {
10902: if ($user !~ /^(\w{2})/) { next; }
10903: my ($role) = ($user =~ /^(\w{2})/);
10904: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10905: my ($section,$status);
1.240 albertel 10906: if ($role eq 'cr' &&
10907: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10908: $section=$1;
10909: }
10910: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10911: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10912: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10913: if ($end == -1 && $start == -1) {
10914: next; #deleted role
10915: }
10916: if (!defined($possible_status)) {
10917: $sectioncount{$section}++;
10918: } else {
10919: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10920: $status = 'active';
10921: } elsif ($end < $now) {
10922: $status = 'future';
10923: } elsif ($start > $now) {
10924: $status = 'previous';
10925: }
10926: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10927: $sectioncount{$section}++;
10928: }
10929: }
1.233 raeburn 10930: }
1.366 albertel 10931: return %sectioncount;
1.233 raeburn 10932: }
10933:
1.274 raeburn 10934: ###############################################
1.294 raeburn 10935:
10936: =pod
1.405 albertel 10937:
10938: =item * &get_course_users()
10939:
1.275 raeburn 10940: Retrieves usernames:domains for users in the specified course
10941: with specific role(s), and access status.
10942:
10943: Incoming parameters:
1.277 albertel 10944: 1. course domain
10945: 2. course number
10946: 3. access status: users must have - either active,
1.275 raeburn 10947: previous, future, or all.
1.277 albertel 10948: 4. reference to array of permissible roles
1.288 raeburn 10949: 5. reference to array of section restrictions (optional)
10950: 6. reference to results object (hash of hashes).
10951: 7. reference to optional userdata hash
1.609 raeburn 10952: 8. reference to optional statushash
1.630 raeburn 10953: 9. flag if privileged users (except those set to unhide in
10954: course settings) should be excluded
1.609 raeburn 10955: Keys of top level results hash are roles.
1.275 raeburn 10956: Keys of inner hashes are username:domain, with
10957: values set to access type.
1.288 raeburn 10958: Optional userdata hash returns an array with arguments in the
10959: same order as loncoursedata::get_classlist() for student data.
10960:
1.609 raeburn 10961: Optional statushash returns
10962:
1.288 raeburn 10963: Entries for end, start, section and status are blank because
10964: of the possibility of multiple values for non-student roles.
10965:
1.275 raeburn 10966: =cut
1.405 albertel 10967:
1.275 raeburn 10968: ###############################################
1.405 albertel 10969:
1.275 raeburn 10970: sub get_course_users {
1.630 raeburn 10971: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10972: my %idx = ();
1.419 raeburn 10973: my %seclists;
1.288 raeburn 10974:
10975: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10976: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10977: $idx{end} = &Apache::loncoursedata::CL_END();
10978: $idx{start} = &Apache::loncoursedata::CL_START();
10979: $idx{id} = &Apache::loncoursedata::CL_ID();
10980: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10981: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10982: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10983:
1.290 albertel 10984: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10985: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10986: my $now = time;
1.277 albertel 10987: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10988: my $match = 0;
1.412 raeburn 10989: my $secmatch = 0;
1.419 raeburn 10990: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10991: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10992: if ($section eq '') {
10993: $section = 'none';
10994: }
1.291 albertel 10995: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10996: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10997: $secmatch = 1;
10998: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10999: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11000: $secmatch = 1;
11001: }
11002: } else {
1.419 raeburn 11003: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 11004: $secmatch = 1;
11005: }
1.290 albertel 11006: }
1.412 raeburn 11007: if (!$secmatch) {
11008: next;
11009: }
1.419 raeburn 11010: }
1.275 raeburn 11011: if (defined($$types{'active'})) {
1.288 raeburn 11012: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 11013: push(@{$$users{st}{$student}},'active');
1.288 raeburn 11014: $match = 1;
1.275 raeburn 11015: }
11016: }
11017: if (defined($$types{'previous'})) {
1.609 raeburn 11018: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 11019: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 11020: $match = 1;
1.275 raeburn 11021: }
11022: }
11023: if (defined($$types{'future'})) {
1.609 raeburn 11024: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 11025: push(@{$$users{st}{$student}},'future');
1.288 raeburn 11026: $match = 1;
1.275 raeburn 11027: }
11028: }
1.609 raeburn 11029: if ($match) {
11030: push(@{$seclists{$student}},$section);
11031: if (ref($userdata) eq 'HASH') {
11032: $$userdata{$student} = $$classlist{$student};
11033: }
11034: if (ref($statushash) eq 'HASH') {
11035: $statushash->{$student}{'st'}{$section} = $status;
11036: }
1.288 raeburn 11037: }
1.275 raeburn 11038: }
11039: }
1.412 raeburn 11040: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 11041: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11042: my $now = time;
1.609 raeburn 11043: my %displaystatus = ( previous => 'Expired',
11044: active => 'Active',
11045: future => 'Future',
11046: );
1.1121 raeburn 11047: my (%nothide,@possdoms);
1.630 raeburn 11048: if ($hidepriv) {
11049: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
11050: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
11051: if ($user !~ /:/) {
11052: $nothide{join(':',split(/[\@]/,$user))}=1;
11053: } else {
11054: $nothide{$user} = 1;
11055: }
11056: }
1.1121 raeburn 11057: my @possdoms = ($cdom);
11058: if ($coursehash{'checkforpriv'}) {
11059: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
11060: }
1.630 raeburn 11061: }
1.439 raeburn 11062: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 11063: my $match = 0;
1.412 raeburn 11064: my $secmatch = 0;
1.439 raeburn 11065: my $status;
1.412 raeburn 11066: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 11067: $user =~ s/:$//;
1.439 raeburn 11068: my ($end,$start) = split(/:/,$coursepersonnel{$person});
11069: if ($end == -1 || $start == -1) {
11070: next;
11071: }
11072: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
11073: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 11074: my ($uname,$udom) = split(/:/,$user);
11075: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11076: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11077: $secmatch = 1;
11078: } elsif ($usec eq '') {
1.420 albertel 11079: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11080: $secmatch = 1;
11081: }
11082: } else {
11083: if (grep(/^\Q$usec\E$/,@{$sections})) {
11084: $secmatch = 1;
11085: }
11086: }
11087: if (!$secmatch) {
11088: next;
11089: }
1.288 raeburn 11090: }
1.419 raeburn 11091: if ($usec eq '') {
11092: $usec = 'none';
11093: }
1.275 raeburn 11094: if ($uname ne '' && $udom ne '') {
1.630 raeburn 11095: if ($hidepriv) {
1.1121 raeburn 11096: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 11097: (!$nothide{$uname.':'.$udom})) {
11098: next;
11099: }
11100: }
1.503 raeburn 11101: if ($end > 0 && $end < $now) {
1.439 raeburn 11102: $status = 'previous';
11103: } elsif ($start > $now) {
11104: $status = 'future';
11105: } else {
11106: $status = 'active';
11107: }
1.277 albertel 11108: foreach my $type (keys(%{$types})) {
1.275 raeburn 11109: if ($status eq $type) {
1.420 albertel 11110: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 11111: push(@{$$users{$role}{$user}},$type);
11112: }
1.288 raeburn 11113: $match = 1;
11114: }
11115: }
1.419 raeburn 11116: if (($match) && (ref($userdata) eq 'HASH')) {
11117: if (!exists($$userdata{$uname.':'.$udom})) {
11118: &get_user_info($udom,$uname,\%idx,$userdata);
11119: }
1.420 albertel 11120: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 11121: push(@{$seclists{$uname.':'.$udom}},$usec);
11122: }
1.609 raeburn 11123: if (ref($statushash) eq 'HASH') {
11124: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
11125: }
1.275 raeburn 11126: }
11127: }
11128: }
11129: }
1.290 albertel 11130: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 11131: if ((defined($cdom)) && (defined($cnum))) {
11132: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
11133: if ( defined($csettings{'internal.courseowner'}) ) {
11134: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 11135: next if ($owner eq '');
11136: my ($ownername,$ownerdom);
11137: if ($owner =~ /^([^:]+):([^:]+)$/) {
11138: $ownername = $1;
11139: $ownerdom = $2;
11140: } else {
11141: $ownername = $owner;
11142: $ownerdom = $cdom;
11143: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 11144: }
11145: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 11146: if (defined($userdata) &&
1.609 raeburn 11147: !exists($$userdata{$owner})) {
11148: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
11149: if (!grep(/^none$/,@{$seclists{$owner}})) {
11150: push(@{$seclists{$owner}},'none');
11151: }
11152: if (ref($statushash) eq 'HASH') {
11153: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 11154: }
1.290 albertel 11155: }
1.279 raeburn 11156: }
11157: }
11158: }
1.419 raeburn 11159: foreach my $user (keys(%seclists)) {
11160: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
11161: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
11162: }
1.275 raeburn 11163: }
11164: return;
11165: }
11166:
1.288 raeburn 11167: sub get_user_info {
11168: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 11169: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
11170: &plainname($uname,$udom,'lastname');
1.291 albertel 11171: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 11172: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 11173: my %idhash = &Apache::lonnet::idrget($udom,($uname));
11174: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 11175: return;
11176: }
1.275 raeburn 11177:
1.472 raeburn 11178: ###############################################
11179:
11180: =pod
11181:
11182: =item * &get_user_quota()
11183:
1.1134 raeburn 11184: Retrieves quota assigned for storage of user files.
11185: Default is to report quota for portfolio files.
1.472 raeburn 11186:
11187: Incoming parameters:
11188: 1. user's username
11189: 2. user's domain
1.1134 raeburn 11190: 3. quota name - portfolio, author, or course
1.1136 raeburn 11191: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 11192: 4. crstype - official, unofficial, textbook, placement or community,
11193: if quota name is course
1.472 raeburn 11194:
11195: Returns:
1.1163 raeburn 11196: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 11197: 2. (Optional) Type of setting: custom or default
11198: (individually assigned or default for user's
11199: institutional status).
11200: 3. (Optional) - User's institutional status (e.g., faculty, staff
11201: or student - types as defined in localenroll::inst_usertypes
11202: for user's domain, which determines default quota for user.
11203: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 11204:
11205: If a value has been stored in the user's environment,
1.536 raeburn 11206: it will return that, otherwise it returns the maximal default
1.1134 raeburn 11207: defined for the user's institutional status(es) in the domain.
1.472 raeburn 11208:
11209: =cut
11210:
11211: ###############################################
11212:
11213:
11214: sub get_user_quota {
1.1136 raeburn 11215: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 11216: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 11217: if (!defined($udom)) {
11218: $udom = $env{'user.domain'};
11219: }
11220: if (!defined($uname)) {
11221: $uname = $env{'user.name'};
11222: }
11223: if (($udom eq '' || $uname eq '') ||
11224: ($udom eq 'public') && ($uname eq 'public')) {
11225: $quota = 0;
1.536 raeburn 11226: $quotatype = 'default';
11227: $defquota = 0;
1.472 raeburn 11228: } else {
1.536 raeburn 11229: my $inststatus;
1.1134 raeburn 11230: if ($quotaname eq 'course') {
11231: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
11232: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
11233: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
11234: } else {
11235: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
11236: $quota = $cenv{'internal.uploadquota'};
11237: }
1.536 raeburn 11238: } else {
1.1134 raeburn 11239: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
11240: if ($quotaname eq 'author') {
11241: $quota = $env{'environment.authorquota'};
11242: } else {
11243: $quota = $env{'environment.portfolioquota'};
11244: }
11245: $inststatus = $env{'environment.inststatus'};
11246: } else {
11247: my %userenv =
11248: &Apache::lonnet::get('environment',['portfolioquota',
11249: 'authorquota','inststatus'],$udom,$uname);
11250: my ($tmp) = keys(%userenv);
11251: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11252: if ($quotaname eq 'author') {
11253: $quota = $userenv{'authorquota'};
11254: } else {
11255: $quota = $userenv{'portfolioquota'};
11256: }
11257: $inststatus = $userenv{'inststatus'};
11258: } else {
11259: undef(%userenv);
11260: }
11261: }
11262: }
11263: if ($quota eq '' || wantarray) {
11264: if ($quotaname eq 'course') {
11265: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11266: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11267: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11268: ($crstype eq 'placement')) {
1.1136 raeburn 11269: $defquota = $domdefs{$crstype.'quota'};
11270: }
11271: if ($defquota eq '') {
11272: $defquota = 500;
11273: }
1.1134 raeburn 11274: } else {
11275: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11276: }
11277: if ($quota eq '') {
11278: $quota = $defquota;
11279: $quotatype = 'default';
11280: } else {
11281: $quotatype = 'custom';
11282: }
1.472 raeburn 11283: }
11284: }
1.536 raeburn 11285: if (wantarray) {
11286: return ($quota,$quotatype,$settingstatus,$defquota);
11287: } else {
11288: return $quota;
11289: }
1.472 raeburn 11290: }
11291:
11292: ###############################################
11293:
11294: =pod
11295:
11296: =item * &default_quota()
11297:
1.536 raeburn 11298: Retrieves default quota assigned for storage of user portfolio files,
11299: given an (optional) user's institutional status.
1.472 raeburn 11300:
11301: Incoming parameters:
1.1142 raeburn 11302:
1.472 raeburn 11303: 1. domain
1.536 raeburn 11304: 2. (Optional) institutional status(es). This is a : separated list of
11305: status types (e.g., faculty, staff, student etc.)
11306: which apply to the user for whom the default is being retrieved.
11307: If the institutional status string in undefined, the domain
1.1134 raeburn 11308: default quota will be returned.
11309: 3. quota name - portfolio, author, or course
11310: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11311:
11312: Returns:
1.1142 raeburn 11313:
1.1163 raeburn 11314: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11315: 2. (Optional) institutional type which determined the value of the
11316: default quota.
1.472 raeburn 11317:
11318: If a value has been stored in the domain's configuration db,
11319: it will return that, otherwise it returns 20 (for backwards
11320: compatibility with domains which have not set up a configuration
1.1163 raeburn 11321: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11322:
1.536 raeburn 11323: If the user's status includes multiple types (e.g., staff and student),
11324: the largest default quota which applies to the user determines the
11325: default quota returned.
11326:
1.472 raeburn 11327: =cut
11328:
11329: ###############################################
11330:
11331:
11332: sub default_quota {
1.1134 raeburn 11333: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11334: my ($defquota,$settingstatus);
11335: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11336: ['quotas'],$udom);
1.1134 raeburn 11337: my $key = 'defaultquota';
11338: if ($quotaname eq 'author') {
11339: $key = 'authorquota';
11340: }
1.622 raeburn 11341: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11342: if ($inststatus ne '') {
1.765 raeburn 11343: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11344: foreach my $item (@statuses) {
1.1134 raeburn 11345: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11346: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11347: if ($defquota eq '') {
1.1134 raeburn 11348: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11349: $settingstatus = $item;
1.1134 raeburn 11350: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11351: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11352: $settingstatus = $item;
11353: }
11354: }
1.1134 raeburn 11355: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11356: if ($quotahash{'quotas'}{$item} ne '') {
11357: if ($defquota eq '') {
11358: $defquota = $quotahash{'quotas'}{$item};
11359: $settingstatus = $item;
11360: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11361: $defquota = $quotahash{'quotas'}{$item};
11362: $settingstatus = $item;
11363: }
1.536 raeburn 11364: }
11365: }
11366: }
11367: }
11368: if ($defquota eq '') {
1.1134 raeburn 11369: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11370: $defquota = $quotahash{'quotas'}{$key}{'default'};
11371: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11372: $defquota = $quotahash{'quotas'}{'default'};
11373: }
1.536 raeburn 11374: $settingstatus = 'default';
1.1139 raeburn 11375: if ($defquota eq '') {
11376: if ($quotaname eq 'author') {
11377: $defquota = 500;
11378: }
11379: }
1.536 raeburn 11380: }
11381: } else {
11382: $settingstatus = 'default';
1.1134 raeburn 11383: if ($quotaname eq 'author') {
11384: $defquota = 500;
11385: } else {
11386: $defquota = 20;
11387: }
1.536 raeburn 11388: }
11389: if (wantarray) {
11390: return ($defquota,$settingstatus);
1.472 raeburn 11391: } else {
1.536 raeburn 11392: return $defquota;
1.472 raeburn 11393: }
11394: }
11395:
1.1135 raeburn 11396: ###############################################
11397:
11398: =pod
11399:
1.1136 raeburn 11400: =item * &excess_filesize_warning()
1.1135 raeburn 11401:
11402: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11403: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11404: space to be exceeded.
1.1136 raeburn 11405:
11406: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11407: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11408:
1.1165 raeburn 11409: Inputs: 7
1.1136 raeburn 11410: 1. username or coursenum
1.1135 raeburn 11411: 2. domain
1.1136 raeburn 11412: 3. context ('author' or 'course')
1.1135 raeburn 11413: 4. filename of file for which action is being requested
11414: 5. filesize (kB) of file
11415: 6. action being taken: copy or upload.
1.1237 raeburn 11416: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11417:
11418: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11419: otherwise return null.
11420:
11421: =back
1.1135 raeburn 11422:
11423: =cut
11424:
1.1136 raeburn 11425: sub excess_filesize_warning {
1.1165 raeburn 11426: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11427: my $current_disk_usage = 0;
1.1165 raeburn 11428: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11429: if ($context eq 'author') {
11430: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11431: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11432: } else {
11433: foreach my $subdir ('docs','supplemental') {
11434: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11435: }
11436: }
1.1135 raeburn 11437: $disk_quota = int($disk_quota * 1000);
11438: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11439: return '<p class="LC_warning">'.
1.1135 raeburn 11440: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11441: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11442: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11443: $disk_quota,$current_disk_usage).
11444: '</p>';
11445: }
11446: return;
11447: }
11448:
11449: ###############################################
11450:
11451:
1.1136 raeburn 11452:
11453:
1.384 raeburn 11454: sub get_secgrprole_info {
11455: my ($cdom,$cnum,$needroles,$type) = @_;
11456: my %sections_count = &get_sections($cdom,$cnum);
11457: my @sections = (sort {$a <=> $b} keys(%sections_count));
11458: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11459: my @groups = sort(keys(%curr_groups));
11460: my $allroles = [];
11461: my $rolehash;
11462: my $accesshash = {
11463: active => 'Currently has access',
11464: future => 'Will have future access',
11465: previous => 'Previously had access',
11466: };
11467: if ($needroles) {
11468: $rolehash = {'all' => 'all'};
1.385 albertel 11469: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11470: if (&Apache::lonnet::error(%user_roles)) {
11471: undef(%user_roles);
11472: }
11473: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11474: my ($role)=split(/\:/,$item,2);
11475: if ($role eq 'cr') { next; }
11476: if ($role =~ /^cr/) {
11477: $$rolehash{$role} = (split('/',$role))[3];
11478: } else {
11479: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11480: }
11481: }
11482: foreach my $key (sort(keys(%{$rolehash}))) {
11483: push(@{$allroles},$key);
11484: }
11485: push (@{$allroles},'st');
11486: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11487: }
11488: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11489: }
11490:
1.555 raeburn 11491: sub user_picker {
1.1279 raeburn 11492: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11493: my $currdom = $dom;
1.1253 raeburn 11494: my @alldoms = &Apache::lonnet::all_domains();
11495: if (@alldoms == 1) {
11496: my %domsrch = &Apache::lonnet::get_dom('configuration',
11497: ['directorysrch'],$alldoms[0]);
11498: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11499: my $showdom = $domdesc;
11500: if ($showdom eq '') {
11501: $showdom = $dom;
11502: }
11503: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11504: if ((!$domsrch{'directorysrch'}{'available'}) &&
11505: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11506: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11507: }
11508: }
11509: }
1.555 raeburn 11510: my %curr_selected = (
11511: srchin => 'dom',
1.580 raeburn 11512: srchby => 'lastname',
1.555 raeburn 11513: );
11514: my $srchterm;
1.625 raeburn 11515: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11516: if ($srch->{'srchby'} ne '') {
11517: $curr_selected{'srchby'} = $srch->{'srchby'};
11518: }
11519: if ($srch->{'srchin'} ne '') {
11520: $curr_selected{'srchin'} = $srch->{'srchin'};
11521: }
11522: if ($srch->{'srchtype'} ne '') {
11523: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11524: }
11525: if ($srch->{'srchdomain'} ne '') {
11526: $currdom = $srch->{'srchdomain'};
11527: }
11528: $srchterm = $srch->{'srchterm'};
11529: }
1.1222 damieng 11530: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11531: 'usr' => 'Search criteria',
1.563 raeburn 11532: 'doma' => 'Domain/institution to search',
1.558 albertel 11533: 'uname' => 'username',
11534: 'lastname' => 'last name',
1.555 raeburn 11535: 'lastfirst' => 'last name, first name',
1.558 albertel 11536: 'crs' => 'in this course',
1.576 raeburn 11537: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11538: 'alc' => 'all LON-CAPA',
1.573 raeburn 11539: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11540: 'exact' => 'is',
11541: 'contains' => 'contains',
1.569 raeburn 11542: 'begins' => 'begins with',
1.1222 damieng 11543: );
11544: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11545: 'youm' => "You must include some text to search for.",
11546: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11547: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11548: 'yomc' => "You must choose a domain when using an institutional directory search.",
11549: 'ymcd' => "You must choose a domain when using a domain search.",
11550: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11551: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11552: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11553: );
1.1222 damieng 11554: &html_escape(\%html_lt);
11555: &js_escape(\%js_lt);
1.1255 raeburn 11556: my $domform;
1.1277 raeburn 11557: my $allow_blank = 1;
1.1255 raeburn 11558: if ($fixeddom) {
1.1277 raeburn 11559: $allow_blank = 0;
11560: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11561: } else {
1.1287 raeburn 11562: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11563: my ($trusted,$untrusted);
1.1287 raeburn 11564: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11565: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11566: } elsif ($context eq 'author') {
1.1288 raeburn 11567: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11568: } elsif ($context eq 'domain') {
1.1288 raeburn 11569: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11570: }
1.1288 raeburn 11571: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11572: }
1.563 raeburn 11573: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11574:
11575: my @srchins = ('crs','dom','alc','instd');
11576:
11577: foreach my $option (@srchins) {
11578: # FIXME 'alc' option unavailable until
11579: # loncreateuser::print_user_query_page()
11580: # has been completed.
11581: next if ($option eq 'alc');
1.880 raeburn 11582: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11583: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11584: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11585: if ($curr_selected{'srchin'} eq $option) {
11586: $srchinsel .= '
1.1222 damieng 11587: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11588: } else {
11589: $srchinsel .= '
1.1222 damieng 11590: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11591: }
1.555 raeburn 11592: }
1.563 raeburn 11593: $srchinsel .= "\n </select>\n";
1.555 raeburn 11594:
11595: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11596: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11597: if ($curr_selected{'srchby'} eq $option) {
11598: $srchbysel .= '
1.1222 damieng 11599: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11600: } else {
11601: $srchbysel .= '
1.1222 damieng 11602: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11603: }
11604: }
11605: $srchbysel .= "\n </select>\n";
11606:
11607: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11608: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11609: if ($curr_selected{'srchtype'} eq $option) {
11610: $srchtypesel .= '
1.1222 damieng 11611: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11612: } else {
11613: $srchtypesel .= '
1.1222 damieng 11614: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11615: }
11616: }
11617: $srchtypesel .= "\n </select>\n";
11618:
1.558 albertel 11619: my ($newuserscript,$new_user_create);
1.994 raeburn 11620: my $context_dom = $env{'request.role.domain'};
11621: if ($context eq 'requestcrs') {
11622: if ($env{'form.coursedom'} ne '') {
11623: $context_dom = $env{'form.coursedom'};
11624: }
11625: }
1.556 raeburn 11626: if ($forcenewuser) {
1.576 raeburn 11627: if (ref($srch) eq 'HASH') {
1.994 raeburn 11628: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11629: if ($cancreate) {
11630: $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>';
11631: } else {
1.799 bisitz 11632: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11633: my %usertypetext = (
11634: official => 'institutional',
11635: unofficial => 'non-institutional',
11636: );
1.799 bisitz 11637: $new_user_create = '<p class="LC_warning">'
11638: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11639: .' '
11640: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11641: ,'<a href="'.$helplink.'">','</a>')
11642: .'</p><br />';
1.627 raeburn 11643: }
1.576 raeburn 11644: }
11645: }
11646:
1.556 raeburn 11647: $newuserscript = <<"ENDSCRIPT";
11648:
1.570 raeburn 11649: function setSearch(createnew,callingForm) {
1.556 raeburn 11650: if (createnew == 1) {
1.570 raeburn 11651: for (var i=0; i<callingForm.srchby.length; i++) {
11652: if (callingForm.srchby.options[i].value == 'uname') {
11653: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11654: }
11655: }
1.570 raeburn 11656: for (var i=0; i<callingForm.srchin.length; i++) {
11657: if ( callingForm.srchin.options[i].value == 'dom') {
11658: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11659: }
11660: }
1.570 raeburn 11661: for (var i=0; i<callingForm.srchtype.length; i++) {
11662: if (callingForm.srchtype.options[i].value == 'exact') {
11663: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11664: }
11665: }
1.570 raeburn 11666: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11667: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11668: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11669: }
11670: }
11671: }
11672: }
11673: ENDSCRIPT
1.558 albertel 11674:
1.556 raeburn 11675: }
11676:
1.555 raeburn 11677: my $output = <<"END_BLOCK";
1.556 raeburn 11678: <script type="text/javascript">
1.824 bisitz 11679: // <![CDATA[
1.570 raeburn 11680: function validateEntry(callingForm) {
1.558 albertel 11681:
1.556 raeburn 11682: var checkok = 1;
1.558 albertel 11683: var srchin;
1.570 raeburn 11684: for (var i=0; i<callingForm.srchin.length; i++) {
11685: if ( callingForm.srchin[i].checked ) {
11686: srchin = callingForm.srchin[i].value;
1.558 albertel 11687: }
11688: }
11689:
1.570 raeburn 11690: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11691: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11692: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11693: var srchterm = callingForm.srchterm.value;
11694: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11695: var msg = "";
11696:
11697: if (srchterm == "") {
11698: checkok = 0;
1.1222 damieng 11699: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11700: }
11701:
1.569 raeburn 11702: if (srchtype== 'begins') {
11703: if (srchterm.length < 2) {
11704: checkok = 0;
1.1222 damieng 11705: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11706: }
11707: }
11708:
1.556 raeburn 11709: if (srchtype== 'contains') {
11710: if (srchterm.length < 3) {
11711: checkok = 0;
1.1222 damieng 11712: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11713: }
11714: }
11715: if (srchin == 'instd') {
11716: if (srchdomain == '') {
11717: checkok = 0;
1.1222 damieng 11718: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11719: }
11720: }
11721: if (srchin == 'dom') {
11722: if (srchdomain == '') {
11723: checkok = 0;
1.1222 damieng 11724: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11725: }
11726: }
11727: if (srchby == 'lastfirst') {
11728: if (srchterm.indexOf(",") == -1) {
11729: checkok = 0;
1.1222 damieng 11730: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11731: }
11732: if (srchterm.indexOf(",") == srchterm.length -1) {
11733: checkok = 0;
1.1222 damieng 11734: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11735: }
11736: }
11737: if (checkok == 0) {
1.1222 damieng 11738: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11739: return;
11740: }
11741: if (checkok == 1) {
1.570 raeburn 11742: callingForm.submit();
1.556 raeburn 11743: }
11744: }
11745:
11746: $newuserscript
11747:
1.824 bisitz 11748: // ]]>
1.556 raeburn 11749: </script>
1.558 albertel 11750:
11751: $new_user_create
11752:
1.555 raeburn 11753: END_BLOCK
1.558 albertel 11754:
1.876 raeburn 11755: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11756: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11757: $domform.
11758: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11759: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11760: $srchbysel.
11761: $srchtypesel.
11762: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11763: $srchinsel.
11764: &Apache::lonhtmlcommon::row_closure(1).
11765: &Apache::lonhtmlcommon::end_pick_box().
11766: '<br />';
1.1253 raeburn 11767: return ($output,1);
1.555 raeburn 11768: }
11769:
1.612 raeburn 11770: sub user_rule_check {
1.615 raeburn 11771: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11772: my ($response,%inst_response);
1.612 raeburn 11773: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11774: if (keys(%{$usershash}) > 1) {
11775: my (%by_username,%by_id,%userdoms);
11776: my $checkid;
11777: if (ref($checks) eq 'HASH') {
11778: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11779: $checkid = 1;
11780: }
11781: }
11782: foreach my $user (keys(%{$usershash})) {
11783: my ($uname,$udom) = split(/:/,$user);
11784: if ($checkid) {
11785: if (ref($usershash->{$user}) eq 'HASH') {
11786: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11787: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11788: $userdoms{$udom} = 1;
1.1227 raeburn 11789: if (ref($inst_results) eq 'HASH') {
11790: $inst_results->{$uname.':'.$udom} = {};
11791: }
1.1226 raeburn 11792: }
11793: }
11794: } else {
11795: $by_username{$udom}{$uname} = 1;
11796: $userdoms{$udom} = 1;
1.1227 raeburn 11797: if (ref($inst_results) eq 'HASH') {
11798: $inst_results->{$uname.':'.$udom} = {};
11799: }
1.1226 raeburn 11800: }
11801: }
11802: foreach my $udom (keys(%userdoms)) {
11803: if (!$got_rules->{$udom}) {
11804: my %domconfig = &Apache::lonnet::get_dom('configuration',
11805: ['usercreation'],$udom);
11806: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11807: foreach my $item ('username','id') {
11808: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11809: $$curr_rules{$udom}{$item} =
11810: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11811: }
11812: }
11813: }
11814: $got_rules->{$udom} = 1;
11815: }
1.612 raeburn 11816: }
1.1226 raeburn 11817: if ($checkid) {
11818: foreach my $udom (keys(%by_id)) {
11819: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11820: if ($outcome eq 'ok') {
1.1227 raeburn 11821: foreach my $id (keys(%{$by_id{$udom}})) {
11822: my $uname = $by_id{$udom}{$id};
11823: $inst_response{$uname.':'.$udom} = $outcome;
11824: }
1.1226 raeburn 11825: if (ref($results) eq 'HASH') {
11826: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11827: if (exists($inst_response{$uname.':'.$udom})) {
11828: $inst_response{$uname.':'.$udom} = $outcome;
11829: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11830: }
1.1226 raeburn 11831: }
11832: }
11833: }
1.612 raeburn 11834: }
1.615 raeburn 11835: } else {
1.1226 raeburn 11836: foreach my $udom (keys(%by_username)) {
11837: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11838: if ($outcome eq 'ok') {
1.1227 raeburn 11839: foreach my $uname (keys(%{$by_username{$udom}})) {
11840: $inst_response{$uname.':'.$udom} = $outcome;
11841: }
1.1226 raeburn 11842: if (ref($results) eq 'HASH') {
11843: foreach my $uname (keys(%{$results})) {
11844: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11845: }
11846: }
11847: }
11848: }
1.612 raeburn 11849: }
1.1226 raeburn 11850: } elsif (keys(%{$usershash}) == 1) {
11851: my $user = (keys(%{$usershash}))[0];
11852: my ($uname,$udom) = split(/:/,$user);
11853: if (($udom ne '') && ($uname ne '')) {
11854: if (ref($usershash->{$user}) eq 'HASH') {
11855: if (ref($checks) eq 'HASH') {
11856: if (defined($checks->{'username'})) {
11857: ($inst_response{$user},%{$inst_results->{$user}}) =
11858: &Apache::lonnet::get_instuser($udom,$uname);
11859: } elsif (defined($checks->{'id'})) {
11860: if ($usershash->{$user}->{'id'} ne '') {
11861: ($inst_response{$user},%{$inst_results->{$user}}) =
11862: &Apache::lonnet::get_instuser($udom,undef,
11863: $usershash->{$user}->{'id'});
11864: } else {
11865: ($inst_response{$user},%{$inst_results->{$user}}) =
11866: &Apache::lonnet::get_instuser($udom,$uname);
11867: }
1.585 raeburn 11868: }
1.1226 raeburn 11869: } else {
11870: ($inst_response{$user},%{$inst_results->{$user}}) =
11871: &Apache::lonnet::get_instuser($udom,$uname);
11872: return;
11873: }
11874: if (!$got_rules->{$udom}) {
11875: my %domconfig = &Apache::lonnet::get_dom('configuration',
11876: ['usercreation'],$udom);
11877: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11878: foreach my $item ('username','id') {
11879: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11880: $$curr_rules{$udom}{$item} =
11881: $domconfig{'usercreation'}{$item.'_rule'};
11882: }
11883: }
11884: }
11885: $got_rules->{$udom} = 1;
1.585 raeburn 11886: }
11887: }
1.1226 raeburn 11888: } else {
11889: return;
11890: }
11891: } else {
11892: return;
11893: }
11894: foreach my $user (keys(%{$usershash})) {
11895: my ($uname,$udom) = split(/:/,$user);
11896: next if (($udom eq '') || ($uname eq ''));
11897: my $id;
1.1227 raeburn 11898: if (ref($inst_results) eq 'HASH') {
11899: if (ref($inst_results->{$user}) eq 'HASH') {
11900: $id = $inst_results->{$user}->{'id'};
11901: }
11902: }
11903: if ($id eq '') {
11904: if (ref($usershash->{$user})) {
11905: $id = $usershash->{$user}->{'id'};
11906: }
1.585 raeburn 11907: }
1.612 raeburn 11908: foreach my $item (keys(%{$checks})) {
11909: if (ref($$curr_rules{$udom}) eq 'HASH') {
11910: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11911: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11912: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11913: $$curr_rules{$udom}{$item});
1.612 raeburn 11914: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11915: if ($rule_check{$rule}) {
11916: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11917: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11918: if (ref($inst_results) eq 'HASH') {
11919: if (ref($inst_results->{$user}) eq 'HASH') {
11920: if (keys(%{$inst_results->{$user}}) == 0) {
11921: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11922: } elsif ($item eq 'id') {
11923: if ($inst_results->{$user}->{'id'} eq '') {
11924: $$alerts{$item}{$udom}{$uname} = 1;
11925: }
1.615 raeburn 11926: }
1.612 raeburn 11927: }
11928: }
1.615 raeburn 11929: }
11930: last;
1.585 raeburn 11931: }
11932: }
11933: }
11934: }
11935: }
11936: }
11937: }
11938: }
1.612 raeburn 11939: return;
11940: }
11941:
11942: sub user_rule_formats {
11943: my ($domain,$domdesc,$curr_rules,$check) = @_;
11944: my %text = (
11945: 'username' => 'Usernames',
11946: 'id' => 'IDs',
11947: );
11948: my $output;
11949: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11950: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11951: if (@{$ruleorder} > 0) {
1.1102 raeburn 11952: $output = '<br />'.
11953: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11954: '<span class="LC_cusr_emph">','</span>',$domdesc).
11955: ' <ul>';
1.612 raeburn 11956: foreach my $rule (@{$ruleorder}) {
11957: if (ref($curr_rules) eq 'ARRAY') {
11958: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11959: if (ref($rules->{$rule}) eq 'HASH') {
11960: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11961: $rules->{$rule}{'desc'}.'</li>';
11962: }
11963: }
11964: }
11965: }
11966: $output .= '</ul>';
11967: }
11968: }
11969: return $output;
11970: }
11971:
11972: sub instrule_disallow_msg {
1.615 raeburn 11973: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11974: my $response;
11975: my %text = (
11976: item => 'username',
11977: items => 'usernames',
11978: match => 'matches',
11979: do => 'does',
11980: action => 'a username',
11981: one => 'one',
11982: );
11983: if ($count > 1) {
11984: $text{'item'} = 'usernames';
11985: $text{'match'} ='match';
11986: $text{'do'} = 'do';
11987: $text{'action'} = 'usernames',
11988: $text{'one'} = 'ones';
11989: }
11990: if ($checkitem eq 'id') {
11991: $text{'items'} = 'IDs';
11992: $text{'item'} = 'ID';
11993: $text{'action'} = 'an ID';
1.615 raeburn 11994: if ($count > 1) {
11995: $text{'item'} = 'IDs';
11996: $text{'action'} = 'IDs';
11997: }
1.612 raeburn 11998: }
1.674 bisitz 11999: $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 12000: if ($mode eq 'upload') {
12001: if ($checkitem eq 'username') {
12002: $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'}.");
12003: } elsif ($checkitem eq 'id') {
1.674 bisitz 12004: $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 12005: }
1.669 raeburn 12006: } elsif ($mode eq 'selfcreate') {
12007: if ($checkitem eq 'id') {
12008: $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.");
12009: }
1.615 raeburn 12010: } else {
12011: if ($checkitem eq 'username') {
12012: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
12013: } elsif ($checkitem eq 'id') {
12014: $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.");
12015: }
1.612 raeburn 12016: }
12017: return $response;
1.585 raeburn 12018: }
12019:
1.624 raeburn 12020: sub personal_data_fieldtitles {
12021: my %fieldtitles = &Apache::lonlocal::texthash (
12022: id => 'Student/Employee ID',
12023: permanentemail => 'E-mail address',
12024: lastname => 'Last Name',
12025: firstname => 'First Name',
12026: middlename => 'Middle Name',
12027: generation => 'Generation',
12028: gen => 'Generation',
1.765 raeburn 12029: inststatus => 'Affiliation',
1.624 raeburn 12030: );
12031: return %fieldtitles;
12032: }
12033:
1.642 raeburn 12034: sub sorted_inst_types {
12035: my ($dom) = @_;
1.1185 raeburn 12036: my ($usertypes,$order);
12037: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12038: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
12039: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
12040: $order = $domdefaults{'inststatus'}{'inststatusorder'};
12041: } else {
12042: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
12043: }
1.642 raeburn 12044: my $othertitle = &mt('All users');
12045: if ($env{'request.course.id'}) {
1.668 raeburn 12046: $othertitle = &mt('Any users');
1.642 raeburn 12047: }
12048: my @types;
12049: if (ref($order) eq 'ARRAY') {
12050: @types = @{$order};
12051: }
12052: if (@types == 0) {
12053: if (ref($usertypes) eq 'HASH') {
12054: @types = sort(keys(%{$usertypes}));
12055: }
12056: }
12057: if (keys(%{$usertypes}) > 0) {
12058: $othertitle = &mt('Other users');
12059: }
12060: return ($othertitle,$usertypes,\@types);
12061: }
12062:
1.645 raeburn 12063: sub get_institutional_codes {
1.1361 raeburn 12064: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 12065: # Get complete list of course sections to update
12066: my @currsections = ();
12067: my @currxlists = ();
1.1361 raeburn 12068: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 12069: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 12070: my $crskey = $crs.':'.$coursecode;
12071: @{$unclutteredsec{$crskey}} = ();
12072: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 12073:
12074: if ($$settings{'internal.sectionnums'} ne '') {
12075: @currsections = split(/,/,$$settings{'internal.sectionnums'});
12076: }
12077:
12078: if ($$settings{'internal.crosslistings'} ne '') {
12079: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
12080: }
12081:
12082: if (@currxlists > 0) {
1.1361 raeburn 12083: foreach my $xl (@currxlists) {
12084: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 12085: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 12086: push(@{$allcourses},$1);
1.645 raeburn 12087: $$LC_code{$1} = $2;
12088: }
12089: }
12090: }
12091: }
1.1361 raeburn 12092:
1.645 raeburn 12093: if (@currsections > 0) {
1.1361 raeburn 12094: foreach my $sec (@currsections) {
12095: if ($sec =~ m/^(\w+):(\w*)$/ ) {
12096: my $instsec = $1;
1.645 raeburn 12097: my $lc_sec = $2;
1.1361 raeburn 12098: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
12099: push(@{$unclutteredsec{$crskey}},$instsec);
12100: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
12101: }
12102: }
12103: }
12104: }
12105:
12106: if (@{$unclutteredsec{$crskey}} > 0) {
12107: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
12108: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
12109: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
12110: my $sec = $coursecode.$formattedsec{$crskey}[$i];
12111: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 12112: push(@{$allcourses},$sec);
1.1361 raeburn 12113: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 12114: }
12115: }
12116: }
12117: }
12118: return;
12119: }
12120:
1.971 raeburn 12121: sub get_standard_codeitems {
12122: return ('Year','Semester','Department','Number','Section');
12123: }
12124:
1.112 bowersj2 12125: =pod
12126:
1.780 raeburn 12127: =head1 Slot Helpers
12128:
12129: =over 4
12130:
12131: =item * sorted_slots()
12132:
1.1040 raeburn 12133: Sorts an array of slot names in order of an optional sort key,
12134: default sort is by slot start time (earliest first).
1.780 raeburn 12135:
12136: Inputs:
12137:
12138: =over 4
12139:
12140: slotsarr - Reference to array of unsorted slot names.
12141:
12142: slots - Reference to hash of hash, where outer hash keys are slot names.
12143:
1.1040 raeburn 12144: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
12145:
1.549 albertel 12146: =back
12147:
1.780 raeburn 12148: Returns:
12149:
12150: =over 4
12151:
1.1040 raeburn 12152: sorted - An array of slot names sorted by a specified sort key
12153: (default sort key is start time of the slot).
1.780 raeburn 12154:
12155: =back
12156:
12157: =cut
12158:
12159:
12160: sub sorted_slots {
1.1040 raeburn 12161: my ($slotsarr,$slots,$sortkey) = @_;
12162: if ($sortkey eq '') {
12163: $sortkey = 'starttime';
12164: }
1.780 raeburn 12165: my @sorted;
12166: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
12167: @sorted =
12168: sort {
12169: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 12170: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 12171: }
12172: if (ref($slots->{$a})) { return -1;}
12173: if (ref($slots->{$b})) { return 1;}
12174: return 0;
12175: } @{$slotsarr};
12176: }
12177: return @sorted;
12178: }
12179:
1.1040 raeburn 12180: =pod
12181:
12182: =item * get_future_slots()
12183:
12184: Inputs:
12185:
12186: =over 4
12187:
12188: cnum - course number
12189:
12190: cdom - course domain
12191:
12192: now - current UNIX time
12193:
12194: symb - optional symb
12195:
12196: =back
12197:
12198: Returns:
12199:
12200: =over 4
12201:
12202: sorted_reservable - ref to array of student_schedulable slots currently
12203: reservable, ordered by end date of reservation period.
12204:
12205: reservable_now - ref to hash of student_schedulable slots currently
12206: reservable.
12207:
12208: Keys in inner hash are:
12209: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12210: (b) endreserve: end date of reservation period.
12211: (c) uniqueperiod: start,end dates when slot is to be uniquely
12212: selected.
1.1040 raeburn 12213:
12214: sorted_future - ref to array of student_schedulable slots reservable in
12215: the future, ordered by start date of reservation period.
12216:
12217: future_reservable - ref to hash of student_schedulable slots reservable
12218: in the future.
12219:
12220: Keys in inner hash are:
12221: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12222: (b) startreserve: start date of reservation period.
12223: (c) uniqueperiod: start,end dates when slot is to be uniquely
12224: selected.
1.1040 raeburn 12225:
12226: =back
12227:
12228: =cut
12229:
12230: sub get_future_slots {
12231: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 12232: my $map;
12233: if ($symb) {
12234: ($map) = &Apache::lonnet::decode_symb($symb);
12235: }
1.1040 raeburn 12236: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
12237: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
12238: foreach my $slot (keys(%slots)) {
12239: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
12240: if ($symb) {
1.1229 raeburn 12241: if ($slots{$slot}->{'symb'} ne '') {
12242: my $canuse;
12243: my %oksymbs;
12244: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
12245: map { $oksymbs{$_} = 1; } @slotsymbs;
12246: if ($oksymbs{$symb}) {
12247: $canuse = 1;
12248: } else {
12249: foreach my $item (@slotsymbs) {
12250: if ($item =~ /\.(page|sequence)$/) {
12251: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12252: if (($map ne '') && ($map eq $sloturl)) {
12253: $canuse = 1;
12254: last;
12255: }
12256: }
12257: }
12258: }
12259: next unless ($canuse);
12260: }
1.1040 raeburn 12261: }
12262: if (($slots{$slot}->{'starttime'} > $now) &&
12263: ($slots{$slot}->{'endtime'} > $now)) {
12264: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12265: my $userallowed = 0;
12266: if ($slots{$slot}->{'allowedsections'}) {
12267: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12268: if (!defined($env{'request.role.sec'})
12269: && grep(/^No section assigned$/,@allowed_sec)) {
12270: $userallowed=1;
12271: } else {
12272: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12273: $userallowed=1;
12274: }
12275: }
12276: unless ($userallowed) {
12277: if (defined($env{'request.course.groups'})) {
12278: my @groups = split(/:/,$env{'request.course.groups'});
12279: foreach my $group (@groups) {
12280: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12281: $userallowed=1;
12282: last;
12283: }
12284: }
12285: }
12286: }
12287: }
12288: if ($slots{$slot}->{'allowedusers'}) {
12289: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12290: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12291: if (grep(/^\Q$user\E$/,@allowed_users)) {
12292: $userallowed = 1;
12293: }
12294: }
12295: next unless($userallowed);
12296: }
12297: my $startreserve = $slots{$slot}->{'startreserve'};
12298: my $endreserve = $slots{$slot}->{'endreserve'};
12299: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12300: my $uniqueperiod;
12301: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12302: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12303: }
1.1040 raeburn 12304: if (($startreserve < $now) &&
12305: (!$endreserve || $endreserve > $now)) {
12306: my $lastres = $endreserve;
12307: if (!$lastres) {
12308: $lastres = $slots{$slot}->{'starttime'};
12309: }
12310: $reservable_now{$slot} = {
12311: symb => $symb,
1.1250 raeburn 12312: endreserve => $lastres,
12313: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12314: };
12315: } elsif (($startreserve > $now) &&
12316: (!$endreserve || $endreserve > $startreserve)) {
12317: $future_reservable{$slot} = {
12318: symb => $symb,
1.1250 raeburn 12319: startreserve => $startreserve,
12320: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12321: };
12322: }
12323: }
12324: }
12325: my @unsorted_reservable = keys(%reservable_now);
12326: if (@unsorted_reservable > 0) {
12327: @sorted_reservable =
12328: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12329: }
12330: my @unsorted_future = keys(%future_reservable);
12331: if (@unsorted_future > 0) {
12332: @sorted_future =
12333: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12334: }
12335: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12336: }
1.780 raeburn 12337:
12338: =pod
12339:
1.1057 foxr 12340: =back
12341:
1.549 albertel 12342: =head1 HTTP Helpers
12343:
12344: =over 4
12345:
1.648 raeburn 12346: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12347:
1.258 albertel 12348: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12349: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12350: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12351:
12352: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12353: $possible_names is an ref to an array of form element names. As an example:
12354: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12355: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12356:
12357: =cut
1.1 albertel 12358:
1.6 albertel 12359: sub get_unprocessed_cgi {
1.25 albertel 12360: my ($query,$possible_names)= @_;
1.26 matthew 12361: # $Apache::lonxml::debug=1;
1.356 albertel 12362: foreach my $pair (split(/&/,$query)) {
12363: my ($name, $value) = split(/=/,$pair);
1.369 www 12364: $name = &unescape($name);
1.25 albertel 12365: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12366: $value =~ tr/+/ /;
12367: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12368: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12369: }
1.16 harris41 12370: }
1.6 albertel 12371: }
12372:
1.112 bowersj2 12373: =pod
12374:
1.648 raeburn 12375: =item * &cacheheader()
1.112 bowersj2 12376:
12377: returns cache-controlling header code
12378:
12379: =cut
12380:
1.7 albertel 12381: sub cacheheader {
1.258 albertel 12382: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12383: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12384: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12385: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12386: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12387: return $output;
1.7 albertel 12388: }
12389:
1.112 bowersj2 12390: =pod
12391:
1.648 raeburn 12392: =item * &no_cache($r)
1.112 bowersj2 12393:
12394: specifies header code to not have cache
12395:
12396: =cut
12397:
1.9 albertel 12398: sub no_cache {
1.216 albertel 12399: my ($r) = @_;
12400: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12401: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12402: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12403: $r->no_cache(1);
12404: $r->header_out("Expires" => $date);
12405: $r->header_out("Pragma" => "no-cache");
1.123 www 12406: }
12407:
12408: sub content_type {
1.181 albertel 12409: my ($r,$type,$charset) = @_;
1.299 foxr 12410: if ($r) {
12411: # Note that printout.pl calls this with undef for $r.
12412: &no_cache($r);
12413: }
1.258 albertel 12414: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12415: unless ($charset) {
12416: $charset=&Apache::lonlocal::current_encoding;
12417: }
12418: if ($charset) { $type.='; charset='.$charset; }
12419: if ($r) {
12420: $r->content_type($type);
12421: } else {
12422: print("Content-type: $type\n\n");
12423: }
1.9 albertel 12424: }
1.25 albertel 12425:
1.112 bowersj2 12426: =pod
12427:
1.648 raeburn 12428: =item * &add_to_env($name,$value)
1.112 bowersj2 12429:
1.258 albertel 12430: adds $name to the %env hash with value
1.112 bowersj2 12431: $value, if $name already exists, the entry is converted to an array
12432: reference and $value is added to the array.
12433:
12434: =cut
12435:
1.25 albertel 12436: sub add_to_env {
12437: my ($name,$value)=@_;
1.258 albertel 12438: if (defined($env{$name})) {
12439: if (ref($env{$name})) {
1.25 albertel 12440: #already have multiple values
1.258 albertel 12441: push(@{ $env{$name} },$value);
1.25 albertel 12442: } else {
12443: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12444: my $first=$env{$name};
12445: undef($env{$name});
12446: push(@{ $env{$name} },$first,$value);
1.25 albertel 12447: }
12448: } else {
1.258 albertel 12449: $env{$name}=$value;
1.25 albertel 12450: }
1.31 albertel 12451: }
1.149 albertel 12452:
12453: =pod
12454:
1.648 raeburn 12455: =item * &get_env_multiple($name)
1.149 albertel 12456:
1.258 albertel 12457: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12458: values may be defined and end up as an array ref.
12459:
12460: returns an array of values
12461:
12462: =cut
12463:
12464: sub get_env_multiple {
12465: my ($name) = @_;
12466: my @values;
1.258 albertel 12467: if (defined($env{$name})) {
1.149 albertel 12468: # exists is it an array
1.258 albertel 12469: if (ref($env{$name})) {
12470: @values=@{ $env{$name} };
1.149 albertel 12471: } else {
1.258 albertel 12472: $values[0]=$env{$name};
1.149 albertel 12473: }
12474: }
12475: return(@values);
12476: }
12477:
1.1249 damieng 12478: # Looks at given dependencies, and returns something depending on the context.
12479: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12480: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12481: # For all other contexts, returns ($output, $counter, $numpathchg).
12482: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12483: # $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.
12484: # $numpathchg: integer with the number of cleaned up dependency paths.
12485: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12486: # \%mapping: hash reference clean path -> original path for all dependencies.
12487: # @param {string} actionurl - The path to the handler, indicative of the context.
12488: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12489: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12490: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12491: # @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)
12492: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12493: sub ask_for_embedded_content {
1.1249 damieng 12494: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12495: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12496: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12497: %currsubfile,%unused,$rem);
1.1071 raeburn 12498: my $counter = 0;
12499: my $numnew = 0;
1.987 raeburn 12500: my $numremref = 0;
12501: my $numinvalid = 0;
12502: my $numpathchg = 0;
12503: my $numexisting = 0;
1.1071 raeburn 12504: my $numunused = 0;
12505: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12506: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12507: my $heading = &mt('Upload embedded files');
12508: my $buttontext = &mt('Upload');
12509:
1.1249 damieng 12510: # fills these variables based on the context:
12511: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12512: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12513: if ($env{'request.course.id'}) {
1.1123 raeburn 12514: if ($actionurl eq '/adm/dependencies') {
12515: $navmap = Apache::lonnavmaps::navmap->new();
12516: }
12517: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12518: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12519: }
1.1123 raeburn 12520: if (($actionurl eq '/adm/portfolio') ||
12521: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12522: my $current_path='/';
12523: if ($env{'form.currentpath'}) {
12524: $current_path = $env{'form.currentpath'};
12525: }
12526: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12527: $udom = $cdom;
12528: $uname = $cnum;
1.984 raeburn 12529: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12530: } else {
12531: $udom = $env{'user.domain'};
12532: $uname = $env{'user.name'};
12533: $url = '/userfiles/portfolio';
12534: }
1.987 raeburn 12535: $toplevel = $url.'/';
1.984 raeburn 12536: $url .= $current_path;
12537: $getpropath = 1;
1.987 raeburn 12538: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12539: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12540: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12541: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12542: $toplevel = $url;
1.984 raeburn 12543: if ($rest ne '') {
1.987 raeburn 12544: $url .= $rest;
12545: }
12546: } elsif ($actionurl eq '/adm/coursedocs') {
12547: if (ref($args) eq 'HASH') {
1.1071 raeburn 12548: $url = $args->{'docs_url'};
12549: $toplevel = $url;
1.1084 raeburn 12550: if ($args->{'context'} eq 'paste') {
12551: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12552: ($path) =
12553: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12554: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12555: $fileloc =~ s{^/}{};
12556: }
1.1071 raeburn 12557: }
1.1084 raeburn 12558: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12559: if ($env{'request.course.id'} ne '') {
12560: if (ref($args) eq 'HASH') {
12561: $url = $args->{'docs_url'};
12562: $title = $args->{'docs_title'};
1.1126 raeburn 12563: $toplevel = $url;
12564: unless ($toplevel =~ m{^/}) {
12565: $toplevel = "/$url";
12566: }
1.1085 raeburn 12567: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12568: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12569: $path = $1;
12570: } else {
12571: ($path) =
12572: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12573: }
1.1195 raeburn 12574: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12575: $fileloc = $toplevel;
12576: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12577: my ($udom,$uname,$fname) =
12578: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12579: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12580: } else {
12581: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12582: }
1.1071 raeburn 12583: $fileloc =~ s{^/}{};
12584: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12585: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12586: }
1.987 raeburn 12587: }
1.1123 raeburn 12588: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12589: $udom = $cdom;
12590: $uname = $cnum;
12591: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12592: $toplevel = $url;
12593: $path = $url;
12594: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12595: $fileloc =~ s{^/}{};
1.987 raeburn 12596: }
1.1249 damieng 12597:
12598: # parses the dependency paths to get some info
12599: # fills $newfiles, $mapping, $subdependencies, $dependencies
12600: # $newfiles: hash URL -> 1 for new files or external URLs
12601: # (will be completed later)
12602: # $mapping:
12603: # for external URLs: external URL -> external URL
12604: # for relative paths: clean path -> original path
12605: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12606: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12607: foreach my $file (keys(%{$allfiles})) {
12608: my $embed_file;
12609: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12610: $embed_file = $1;
12611: } else {
12612: $embed_file = $file;
12613: }
1.1158 raeburn 12614: my ($absolutepath,$cleaned_file);
12615: if ($embed_file =~ m{^\w+://}) {
12616: $cleaned_file = $embed_file;
1.1147 raeburn 12617: $newfiles{$cleaned_file} = 1;
12618: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12619: } else {
1.1158 raeburn 12620: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12621: if ($embed_file =~ m{^/}) {
12622: $absolutepath = $embed_file;
12623: }
1.1147 raeburn 12624: if ($cleaned_file =~ m{/}) {
12625: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12626: $path = &check_for_traversal($path,$url,$toplevel);
12627: my $item = $fname;
12628: if ($path ne '') {
12629: $item = $path.'/'.$fname;
12630: $subdependencies{$path}{$fname} = 1;
12631: } else {
12632: $dependencies{$item} = 1;
12633: }
12634: if ($absolutepath) {
12635: $mapping{$item} = $absolutepath;
12636: } else {
12637: $mapping{$item} = $embed_file;
12638: }
12639: } else {
12640: $dependencies{$embed_file} = 1;
12641: if ($absolutepath) {
1.1147 raeburn 12642: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12643: } else {
1.1147 raeburn 12644: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12645: }
12646: }
1.984 raeburn 12647: }
12648: }
1.1249 damieng 12649:
12650: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12651: # and lists
12652: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12653: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12654: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12655: # the path had to be cleaned up
12656: # $existing: hash clean path -> 1 if the file exists
12657: # $numexisting: number of keys in $existing
12658: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12659: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12660: # dependency subdirectories that are
12661: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12662: my $dirptr = 16384;
1.984 raeburn 12663: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12664: $currsubfile{$path} = {};
1.1123 raeburn 12665: if (($actionurl eq '/adm/portfolio') ||
12666: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12667: my ($sublistref,$listerror) =
12668: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12669: if (ref($sublistref) eq 'ARRAY') {
12670: foreach my $line (@{$sublistref}) {
12671: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12672: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12673: }
1.984 raeburn 12674: }
1.987 raeburn 12675: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12676: if (opendir(my $dir,$url.'/'.$path)) {
12677: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12678: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12679: }
1.1084 raeburn 12680: } elsif (($actionurl eq '/adm/dependencies') ||
12681: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12682: ($args->{'context'} eq 'paste')) ||
12683: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12684: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12685: my $dir;
12686: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12687: $dir = $fileloc;
12688: } else {
12689: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12690: }
1.1071 raeburn 12691: if ($dir ne '') {
12692: my ($sublistref,$listerror) =
12693: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12694: if (ref($sublistref) eq 'ARRAY') {
12695: foreach my $line (@{$sublistref}) {
12696: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12697: undef,$mtime)=split(/\&/,$line,12);
12698: unless (($testdir&$dirptr) ||
12699: ($file_name =~ /^\.\.?$/)) {
12700: $currsubfile{$path}{$file_name} = [$size,$mtime];
12701: }
12702: }
12703: }
12704: }
1.984 raeburn 12705: }
12706: }
12707: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12708: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12709: my $item = $path.'/'.$file;
12710: unless ($mapping{$item} eq $item) {
12711: $pathchanges{$item} = 1;
12712: }
12713: $existing{$item} = 1;
12714: $numexisting ++;
12715: } else {
12716: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12717: }
12718: }
1.1071 raeburn 12719: if ($actionurl eq '/adm/dependencies') {
12720: foreach my $path (keys(%currsubfile)) {
12721: if (ref($currsubfile{$path}) eq 'HASH') {
12722: foreach my $file (keys(%{$currsubfile{$path}})) {
12723: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12724: next if (($rem ne '') &&
12725: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12726: (ref($navmap) &&
12727: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12728: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12729: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12730: $unused{$path.'/'.$file} = 1;
12731: }
12732: }
12733: }
12734: }
12735: }
1.984 raeburn 12736: }
1.1249 damieng 12737:
12738: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12739: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12740: my %currfile;
1.1123 raeburn 12741: if (($actionurl eq '/adm/portfolio') ||
12742: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12743: my ($dirlistref,$listerror) =
12744: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12745: if (ref($dirlistref) eq 'ARRAY') {
12746: foreach my $line (@{$dirlistref}) {
12747: my ($file_name,$rest) = split(/\&/,$line,2);
12748: $currfile{$file_name} = 1;
12749: }
1.984 raeburn 12750: }
1.987 raeburn 12751: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12752: if (opendir(my $dir,$url)) {
1.987 raeburn 12753: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12754: map {$currfile{$_} = 1;} @dir_list;
12755: }
1.1084 raeburn 12756: } elsif (($actionurl eq '/adm/dependencies') ||
12757: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12758: ($args->{'context'} eq 'paste')) ||
12759: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12760: if ($env{'request.course.id'} ne '') {
12761: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12762: if ($dir ne '') {
12763: my ($dirlistref,$listerror) =
12764: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12765: if (ref($dirlistref) eq 'ARRAY') {
12766: foreach my $line (@{$dirlistref}) {
12767: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12768: $size,undef,$mtime)=split(/\&/,$line,12);
12769: unless (($testdir&$dirptr) ||
12770: ($file_name =~ /^\.\.?$/)) {
12771: $currfile{$file_name} = [$size,$mtime];
12772: }
12773: }
12774: }
12775: }
12776: }
1.984 raeburn 12777: }
1.1249 damieng 12778: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12779: # are not in subdirectories, using $currfile
1.984 raeburn 12780: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12781: if (exists($currfile{$file})) {
1.987 raeburn 12782: unless ($mapping{$file} eq $file) {
12783: $pathchanges{$file} = 1;
12784: }
12785: $existing{$file} = 1;
12786: $numexisting ++;
12787: } else {
1.984 raeburn 12788: $newfiles{$file} = 1;
12789: }
12790: }
1.1071 raeburn 12791: foreach my $file (keys(%currfile)) {
12792: unless (($file eq $filename) ||
12793: ($file eq $filename.'.bak') ||
12794: ($dependencies{$file})) {
1.1085 raeburn 12795: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12796: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12797: next if (($rem ne '') &&
12798: (($env{"httpref.$rem".$file} ne '') ||
12799: (ref($navmap) &&
12800: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12801: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12802: ($navmap->getResourceByUrl($rem.$1)))))));
12803: }
1.1085 raeburn 12804: }
1.1071 raeburn 12805: $unused{$file} = 1;
12806: }
12807: }
1.1249 damieng 12808:
12809: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12810: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12811: ($args->{'context'} eq 'paste')) {
12812: $counter = scalar(keys(%existing));
12813: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12814: return ($output,$counter,$numpathchg,\%existing);
12815: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12816: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12817: $counter = scalar(keys(%existing));
12818: $numpathchg = scalar(keys(%pathchanges));
12819: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12820: }
1.1249 damieng 12821:
12822: # returns HTML otherwise, with dependency results and to ask for more uploads
12823:
12824: # $upload_output: missing dependencies (with upload form)
12825: # $modify_output: uploaded dependencies (in use)
12826: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12827: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12828: if ($actionurl eq '/adm/dependencies') {
12829: next if ($embed_file =~ m{^\w+://});
12830: }
1.660 raeburn 12831: $upload_output .= &start_data_table_row().
1.1123 raeburn 12832: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12833: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12834: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12835: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12836: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12837: }
1.1123 raeburn 12838: $upload_output .= '</td>';
1.1071 raeburn 12839: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12840: $upload_output.='<td align="right">'.
12841: '<span class="LC_info LC_fontsize_medium">'.
12842: &mt("URL points to web address").'</span>';
1.987 raeburn 12843: $numremref++;
1.660 raeburn 12844: } elsif ($args->{'error_on_invalid_names'}
12845: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12846: $upload_output.='<td align="right"><span class="LC_warning">'.
12847: &mt('Invalid characters').'</span>';
1.987 raeburn 12848: $numinvalid++;
1.660 raeburn 12849: } else {
1.1123 raeburn 12850: $upload_output .= '<td>'.
12851: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12852: $embed_file,\%mapping,
1.1071 raeburn 12853: $allfiles,$codebase,'upload');
12854: $counter ++;
12855: $numnew ++;
1.987 raeburn 12856: }
12857: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12858: }
12859: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12860: if ($actionurl eq '/adm/dependencies') {
12861: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12862: $modify_output .= &start_data_table_row().
12863: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12864: '<img src="'.&icon($embed_file).'" border="0" />'.
12865: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12866: '<td>'.$size.'</td>'.
12867: '<td>'.$mtime.'</td>'.
12868: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12869: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12870: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12871: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12872: &embedded_file_element('upload_embedded',$counter,
12873: $embed_file,\%mapping,
12874: $allfiles,$codebase,'modify').
12875: '</div></td>'.
12876: &end_data_table_row()."\n";
12877: $counter ++;
12878: } else {
12879: $upload_output .= &start_data_table_row().
1.1123 raeburn 12880: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12881: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12882: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12883: &Apache::loncommon::end_data_table_row()."\n";
12884: }
12885: }
12886: my $delidx = $counter;
12887: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12888: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12889: $delete_output .= &start_data_table_row().
12890: '<td><img src="'.&icon($oldfile).'" />'.
12891: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12892: '<td>'.$size.'</td>'.
12893: '<td>'.$mtime.'</td>'.
12894: '<td><label><input type="checkbox" name="del_upload_dep" '.
12895: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12896: &embedded_file_element('upload_embedded',$delidx,
12897: $oldfile,\%mapping,$allfiles,
12898: $codebase,'delete').'</td>'.
12899: &end_data_table_row()."\n";
12900: $numunused ++;
12901: $delidx ++;
1.987 raeburn 12902: }
12903: if ($upload_output) {
12904: $upload_output = &start_data_table().
12905: $upload_output.
12906: &end_data_table()."\n";
12907: }
1.1071 raeburn 12908: if ($modify_output) {
12909: $modify_output = &start_data_table().
12910: &start_data_table_header_row().
12911: '<th>'.&mt('File').'</th>'.
12912: '<th>'.&mt('Size (KB)').'</th>'.
12913: '<th>'.&mt('Modified').'</th>'.
12914: '<th>'.&mt('Upload replacement?').'</th>'.
12915: &end_data_table_header_row().
12916: $modify_output.
12917: &end_data_table()."\n";
12918: }
12919: if ($delete_output) {
12920: $delete_output = &start_data_table().
12921: &start_data_table_header_row().
12922: '<th>'.&mt('File').'</th>'.
12923: '<th>'.&mt('Size (KB)').'</th>'.
12924: '<th>'.&mt('Modified').'</th>'.
12925: '<th>'.&mt('Delete?').'</th>'.
12926: &end_data_table_header_row().
12927: $delete_output.
12928: &end_data_table()."\n";
12929: }
1.987 raeburn 12930: my $applies = 0;
12931: if ($numremref) {
12932: $applies ++;
12933: }
12934: if ($numinvalid) {
12935: $applies ++;
12936: }
12937: if ($numexisting) {
12938: $applies ++;
12939: }
1.1071 raeburn 12940: if ($counter || $numunused) {
1.987 raeburn 12941: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12942: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12943: $state.'<h3>'.$heading.'</h3>';
12944: if ($actionurl eq '/adm/dependencies') {
12945: if ($numnew) {
12946: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12947: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12948: $upload_output.'<br />'."\n";
12949: }
12950: if ($numexisting) {
12951: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12952: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12953: $modify_output.'<br />'."\n";
12954: $buttontext = &mt('Save changes');
12955: }
12956: if ($numunused) {
12957: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12958: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12959: $delete_output.'<br />'."\n";
12960: $buttontext = &mt('Save changes');
12961: }
12962: } else {
12963: $output .= $upload_output.'<br />'."\n";
12964: }
12965: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12966: $counter.'" />'."\n";
12967: if ($actionurl eq '/adm/dependencies') {
12968: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12969: $numnew.'" />'."\n";
12970: } elsif ($actionurl eq '') {
1.987 raeburn 12971: $output .= '<input type="hidden" name="phase" value="three" />';
12972: }
12973: } elsif ($applies) {
12974: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12975: if ($applies > 1) {
12976: $output .=
1.1123 raeburn 12977: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12978: if ($numremref) {
12979: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12980: }
12981: if ($numinvalid) {
12982: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12983: }
12984: if ($numexisting) {
12985: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12986: }
12987: $output .= '</ul><br />';
12988: } elsif ($numremref) {
12989: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12990: } elsif ($numinvalid) {
12991: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12992: } elsif ($numexisting) {
12993: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12994: }
12995: $output .= $upload_output.'<br />';
12996: }
12997: my ($pathchange_output,$chgcount);
1.1071 raeburn 12998: $chgcount = $counter;
1.987 raeburn 12999: if (keys(%pathchanges) > 0) {
13000: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 13001: if ($counter) {
1.987 raeburn 13002: $output .= &embedded_file_element('pathchange',$chgcount,
13003: $embed_file,\%mapping,
1.1071 raeburn 13004: $allfiles,$codebase,'change');
1.987 raeburn 13005: } else {
13006: $pathchange_output .=
13007: &start_data_table_row().
13008: '<td><input type ="checkbox" name="namechange" value="'.
13009: $chgcount.'" checked="checked" /></td>'.
13010: '<td>'.$mapping{$embed_file}.'</td>'.
13011: '<td>'.$embed_file.
13012: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 13013: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 13014: '</td>'.&end_data_table_row();
1.660 raeburn 13015: }
1.987 raeburn 13016: $numpathchg ++;
13017: $chgcount ++;
1.660 raeburn 13018: }
13019: }
1.1127 raeburn 13020: if (($counter) || ($numunused)) {
1.987 raeburn 13021: if ($numpathchg) {
13022: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
13023: $numpathchg.'" />'."\n";
13024: }
13025: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
13026: ($actionurl eq '/adm/imsimport')) {
13027: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
13028: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
13029: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 13030: } elsif ($actionurl eq '/adm/dependencies') {
13031: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 13032: }
1.1123 raeburn 13033: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 13034: } elsif ($numpathchg) {
13035: my %pathchange = ();
13036: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
13037: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13038: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 13039: }
1.987 raeburn 13040: }
1.1071 raeburn 13041: return ($output,$counter,$numpathchg);
1.987 raeburn 13042: }
13043:
1.1147 raeburn 13044: =pod
13045:
13046: =item * clean_path($name)
13047:
13048: Performs clean-up of directories, subdirectories and filename in an
13049: embedded object, referenced in an HTML file which is being uploaded
13050: to a course or portfolio, where
13051: "Upload embedded images/multimedia files if HTML file" checkbox was
13052: checked.
13053:
13054: Clean-up is similar to replacements in lonnet::clean_filename()
13055: except each / between sub-directory and next level is preserved.
13056:
13057: =cut
13058:
13059: sub clean_path {
13060: my ($embed_file) = @_;
13061: $embed_file =~s{^/+}{};
13062: my @contents;
13063: if ($embed_file =~ m{/}) {
13064: @contents = split(/\//,$embed_file);
13065: } else {
13066: @contents = ($embed_file);
13067: }
13068: my $lastidx = scalar(@contents)-1;
13069: for (my $i=0; $i<=$lastidx; $i++) {
13070: $contents[$i]=~s{\\}{/}g;
13071: $contents[$i]=~s/\s+/\_/g;
13072: $contents[$i]=~s{[^/\w\.\-]}{}g;
13073: if ($i == $lastidx) {
13074: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
13075: }
13076: }
13077: if ($lastidx > 0) {
13078: return join('/',@contents);
13079: } else {
13080: return $contents[0];
13081: }
13082: }
13083:
1.987 raeburn 13084: sub embedded_file_element {
1.1071 raeburn 13085: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 13086: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
13087: (ref($codebase) eq 'HASH'));
13088: my $output;
1.1071 raeburn 13089: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 13090: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
13091: }
13092: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
13093: &escape($embed_file).'" />';
13094: unless (($context eq 'upload_embedded') &&
13095: ($mapping->{$embed_file} eq $embed_file)) {
13096: $output .='
13097: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
13098: }
13099: my $attrib;
13100: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
13101: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
13102: }
13103: $output .=
13104: "\n\t\t".
13105: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
13106: $attrib.'" />';
13107: if (exists($codebase->{$mapping->{$embed_file}})) {
13108: $output .=
13109: "\n\t\t".
13110: '<input name="codebase_'.$num.'" type="hidden" value="'.
13111: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 13112: }
1.987 raeburn 13113: return $output;
1.660 raeburn 13114: }
13115:
1.1071 raeburn 13116: sub get_dependency_details {
13117: my ($currfile,$currsubfile,$embed_file) = @_;
13118: my ($size,$mtime,$showsize,$showmtime);
13119: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
13120: if ($embed_file =~ m{/}) {
13121: my ($path,$fname) = split(/\//,$embed_file);
13122: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
13123: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
13124: }
13125: } else {
13126: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
13127: ($size,$mtime) = @{$currfile->{$embed_file}};
13128: }
13129: }
13130: $showsize = $size/1024.0;
13131: $showsize = sprintf("%.1f",$showsize);
13132: if ($mtime > 0) {
13133: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
13134: }
13135: }
13136: return ($showsize,$showmtime);
13137: }
13138:
13139: sub ask_embedded_js {
13140: return <<"END";
13141: <script type="text/javascript"">
13142: // <![CDATA[
13143: function toggleBrowse(counter) {
13144: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
13145: var fileid = document.getElementById('embedded_item_'+counter);
13146: var uploaddivid = document.getElementById('moduploaddep_'+counter);
13147: if (chkboxid.checked == true) {
13148: uploaddivid.style.display='block';
13149: } else {
13150: uploaddivid.style.display='none';
13151: fileid.value = '';
13152: }
13153: }
13154: // ]]>
13155: </script>
13156:
13157: END
13158: }
13159:
1.661 raeburn 13160: sub upload_embedded {
13161: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 13162: $current_disk_usage,$hiddenstate,$actionurl) = @_;
13163: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 13164: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
13165: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
13166: my $orig_uploaded_filename =
13167: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 13168: foreach my $type ('orig','ref','attrib','codebase') {
13169: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
13170: $env{'form.embedded_'.$type.'_'.$i} =
13171: &unescape($env{'form.embedded_'.$type.'_'.$i});
13172: }
13173: }
1.661 raeburn 13174: my ($path,$fname) =
13175: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
13176: # no path, whole string is fname
13177: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
13178: $fname = &Apache::lonnet::clean_filename($fname);
13179: # See if there is anything left
13180: next if ($fname eq '');
13181:
13182: # Check if file already exists as a file or directory.
13183: my ($state,$msg);
13184: if ($context eq 'portfolio') {
13185: my $port_path = $dirpath;
13186: if ($group ne '') {
13187: $port_path = "groups/$group/$port_path";
13188: }
1.987 raeburn 13189: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
13190: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 13191: $dir_root,$port_path,$disk_quota,
13192: $current_disk_usage,$uname,$udom);
13193: if ($state eq 'will_exceed_quota'
1.984 raeburn 13194: || $state eq 'file_locked') {
1.661 raeburn 13195: $output .= $msg;
13196: next;
13197: }
13198: } elsif (($context eq 'author') || ($context eq 'testbank')) {
13199: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
13200: if ($state eq 'exists') {
13201: $output .= $msg;
13202: next;
13203: }
13204: }
13205: # Check if extension is valid
13206: if (($fname =~ /\.(\w+)$/) &&
13207: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 13208: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
13209: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 13210: next;
13211: } elsif (($fname =~ /\.(\w+)$/) &&
13212: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 13213: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 13214: next;
13215: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 13216: $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 13217: next;
13218: }
13219: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 13220: my $subdir = $path;
13221: $subdir =~ s{/+$}{};
1.661 raeburn 13222: if ($context eq 'portfolio') {
1.984 raeburn 13223: my $result;
13224: if ($state eq 'existingfile') {
13225: $result=
13226: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 13227: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 13228: } else {
1.984 raeburn 13229: $result=
13230: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 13231: $dirpath.
1.1123 raeburn 13232: $env{'form.currentpath'}.$subdir);
1.984 raeburn 13233: if ($result !~ m|^/uploaded/|) {
13234: $output .= '<span class="LC_error">'
13235: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13236: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13237: .'</span><br />';
13238: next;
13239: } else {
1.987 raeburn 13240: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13241: $path.$fname.'</span>').'<br />';
1.984 raeburn 13242: }
1.661 raeburn 13243: }
1.1123 raeburn 13244: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 13245: my $extendedsubdir = $dirpath.'/'.$subdir;
13246: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 13247: my $result =
1.1126 raeburn 13248: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13249: if ($result !~ m|^/uploaded/|) {
13250: $output .= '<span class="LC_error">'
13251: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13252: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13253: .'</span><br />';
13254: next;
13255: } else {
13256: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13257: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13258: if ($context eq 'syllabus') {
13259: &Apache::lonnet::make_public_indefinitely($result);
13260: }
1.987 raeburn 13261: }
1.661 raeburn 13262: } else {
13263: # Save the file
13264: my $target = $env{'form.embedded_item_'.$i};
13265: my $fullpath = $dir_root.$dirpath.'/'.$path;
13266: my $dest = $fullpath.$fname;
13267: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13268: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13269: my $count;
13270: my $filepath = $dir_root;
1.1027 raeburn 13271: foreach my $subdir (@parts) {
13272: $filepath .= "/$subdir";
13273: if (!-e $filepath) {
1.661 raeburn 13274: mkdir($filepath,0770);
13275: }
13276: }
13277: my $fh;
13278: if (!open($fh,'>'.$dest)) {
13279: &Apache::lonnet::logthis('Failed to create '.$dest);
13280: $output .= '<span class="LC_error">'.
1.1071 raeburn 13281: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13282: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13283: '</span><br />';
13284: } else {
13285: if (!print $fh $env{'form.embedded_item_'.$i}) {
13286: &Apache::lonnet::logthis('Failed to write to '.$dest);
13287: $output .= '<span class="LC_error">'.
1.1071 raeburn 13288: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13289: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13290: '</span><br />';
13291: } else {
1.987 raeburn 13292: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13293: $url.'</span>').'<br />';
13294: unless ($context eq 'testbank') {
13295: $footer .= &mt('View embedded file: [_1]',
13296: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13297: }
13298: }
13299: close($fh);
13300: }
13301: }
13302: if ($env{'form.embedded_ref_'.$i}) {
13303: $pathchange{$i} = 1;
13304: }
13305: }
13306: if ($output) {
13307: $output = '<p>'.$output.'</p>';
13308: }
13309: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13310: $returnflag = 'ok';
1.1071 raeburn 13311: my $numpathchgs = scalar(keys(%pathchange));
13312: if ($numpathchgs > 0) {
1.987 raeburn 13313: if ($context eq 'portfolio') {
13314: $output .= '<p>'.&mt('or').'</p>';
13315: } elsif ($context eq 'testbank') {
1.1071 raeburn 13316: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13317: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13318: $returnflag = 'modify_orightml';
13319: }
13320: }
1.1071 raeburn 13321: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13322: }
13323:
13324: sub modify_html_form {
13325: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13326: my $end = 0;
13327: my $modifyform;
13328: if ($context eq 'upload_embedded') {
13329: return unless (ref($pathchange) eq 'HASH');
13330: if ($env{'form.number_embedded_items'}) {
13331: $end += $env{'form.number_embedded_items'};
13332: }
13333: if ($env{'form.number_pathchange_items'}) {
13334: $end += $env{'form.number_pathchange_items'};
13335: }
13336: if ($end) {
13337: for (my $i=0; $i<$end; $i++) {
13338: if ($i < $env{'form.number_embedded_items'}) {
13339: next unless($pathchange->{$i});
13340: }
13341: $modifyform .=
13342: &start_data_table_row().
13343: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13344: 'checked="checked" /></td>'.
13345: '<td>'.$env{'form.embedded_ref_'.$i}.
13346: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13347: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13348: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13349: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13350: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13351: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13352: '<td>'.$env{'form.embedded_orig_'.$i}.
13353: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13354: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13355: &end_data_table_row();
1.1071 raeburn 13356: }
1.987 raeburn 13357: }
13358: } else {
13359: $modifyform = $pathchgtable;
13360: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13361: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13362: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13363: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13364: }
13365: }
13366: if ($modifyform) {
1.1071 raeburn 13367: if ($actionurl eq '/adm/dependencies') {
13368: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13369: }
1.987 raeburn 13370: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13371: '<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".
13372: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13373: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13374: '</ol></p>'."\n".'<p>'.
13375: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13376: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13377: &start_data_table()."\n".
13378: &start_data_table_header_row().
13379: '<th>'.&mt('Change?').'</th>'.
13380: '<th>'.&mt('Current reference').'</th>'.
13381: '<th>'.&mt('Required reference').'</th>'.
13382: &end_data_table_header_row()."\n".
13383: $modifyform.
13384: &end_data_table().'<br />'."\n".$hiddenstate.
13385: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13386: '</form>'."\n";
13387: }
13388: return;
13389: }
13390:
13391: sub modify_html_refs {
1.1123 raeburn 13392: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13393: my $container;
13394: if ($context eq 'portfolio') {
13395: $container = $env{'form.container'};
13396: } elsif ($context eq 'coursedoc') {
13397: $container = $env{'form.primaryurl'};
1.1071 raeburn 13398: } elsif ($context eq 'manage_dependencies') {
13399: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13400: $container = "/$container";
1.1123 raeburn 13401: } elsif ($context eq 'syllabus') {
13402: $container = $url;
1.987 raeburn 13403: } else {
1.1027 raeburn 13404: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13405: }
13406: my (%allfiles,%codebase,$output,$content);
13407: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13408: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13409: if (wantarray) {
13410: return ('',0,0);
13411: } else {
13412: return;
13413: }
13414: }
13415: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13416: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13417: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13418: if (wantarray) {
13419: return ('',0,0);
13420: } else {
13421: return;
13422: }
13423: }
1.987 raeburn 13424: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13425: if ($content eq '-1') {
13426: if (wantarray) {
13427: return ('',0,0);
13428: } else {
13429: return;
13430: }
13431: }
1.987 raeburn 13432: } else {
1.1071 raeburn 13433: unless ($container =~ /^\Q$dir_root\E/) {
13434: if (wantarray) {
13435: return ('',0,0);
13436: } else {
13437: return;
13438: }
13439: }
1.1317 raeburn 13440: if (open(my $fh,'<',$container)) {
1.987 raeburn 13441: $content = join('', <$fh>);
13442: close($fh);
13443: } else {
1.1071 raeburn 13444: if (wantarray) {
13445: return ('',0,0);
13446: } else {
13447: return;
13448: }
1.987 raeburn 13449: }
13450: }
13451: my ($count,$codebasecount) = (0,0);
13452: my $mm = new File::MMagic;
13453: my $mime_type = $mm->checktype_contents($content);
13454: if ($mime_type eq 'text/html') {
13455: my $parse_result =
13456: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13457: \%codebase,\$content);
13458: if ($parse_result eq 'ok') {
13459: foreach my $i (@changes) {
13460: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13461: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13462: if ($allfiles{$ref}) {
13463: my $newname = $orig;
13464: my ($attrib_regexp,$codebase);
1.1006 raeburn 13465: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13466: if ($attrib_regexp =~ /:/) {
13467: $attrib_regexp =~ s/\:/|/g;
13468: }
13469: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13470: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13471: $count += $numchg;
1.1123 raeburn 13472: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13473: delete($allfiles{$ref});
1.987 raeburn 13474: }
13475: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13476: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13477: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13478: $codebasecount ++;
13479: }
13480: }
13481: }
1.1123 raeburn 13482: my $skiprewrites;
1.987 raeburn 13483: if ($count || $codebasecount) {
13484: my $saveresult;
1.1071 raeburn 13485: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13486: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13487: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13488: if ($url eq $container) {
13489: my ($fname) = ($container =~ m{/([^/]+)$});
13490: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13491: $count,'<span class="LC_filename">'.
1.1071 raeburn 13492: $fname.'</span>').'</p>';
1.987 raeburn 13493: } else {
13494: $output = '<p class="LC_error">'.
13495: &mt('Error: update failed for: [_1].',
13496: '<span class="LC_filename">'.
13497: $container.'</span>').'</p>';
13498: }
1.1123 raeburn 13499: if ($context eq 'syllabus') {
13500: unless ($saveresult eq 'ok') {
13501: $skiprewrites = 1;
13502: }
13503: }
1.987 raeburn 13504: } else {
1.1317 raeburn 13505: if (open(my $fh,'>',$container)) {
1.987 raeburn 13506: print $fh $content;
13507: close($fh);
13508: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13509: $count,'<span class="LC_filename">'.
13510: $container.'</span>').'</p>';
1.661 raeburn 13511: } else {
1.987 raeburn 13512: $output = '<p class="LC_error">'.
13513: &mt('Error: could not update [_1].',
13514: '<span class="LC_filename">'.
13515: $container.'</span>').'</p>';
1.661 raeburn 13516: }
13517: }
13518: }
1.1123 raeburn 13519: if (($context eq 'syllabus') && (!$skiprewrites)) {
13520: my ($actionurl,$state);
13521: $actionurl = "/public/$udom/$uname/syllabus";
13522: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13523: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13524: \%codebase,
13525: {'context' => 'rewrites',
13526: 'ignore_remote_references' => 1,});
13527: if (ref($mapping) eq 'HASH') {
13528: my $rewrites = 0;
13529: foreach my $key (keys(%{$mapping})) {
13530: next if ($key =~ m{^https?://});
13531: my $ref = $mapping->{$key};
13532: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13533: my $attrib;
13534: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13535: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13536: }
13537: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13538: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13539: $rewrites += $numchg;
13540: }
13541: }
13542: if ($rewrites) {
13543: my $saveresult;
13544: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13545: if ($url eq $container) {
13546: my ($fname) = ($container =~ m{/([^/]+)$});
13547: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13548: $count,'<span class="LC_filename">'.
13549: $fname.'</span>').'</p>';
13550: } else {
13551: $output .= '<p class="LC_error">'.
13552: &mt('Error: could not update links in [_1].',
13553: '<span class="LC_filename">'.
13554: $container.'</span>').'</p>';
13555:
13556: }
13557: }
13558: }
13559: }
1.987 raeburn 13560: } else {
13561: &logthis('Failed to parse '.$container.
13562: ' to modify references: '.$parse_result);
1.661 raeburn 13563: }
13564: }
1.1071 raeburn 13565: if (wantarray) {
13566: return ($output,$count,$codebasecount);
13567: } else {
13568: return $output;
13569: }
1.661 raeburn 13570: }
13571:
13572: sub check_for_existing {
13573: my ($path,$fname,$element) = @_;
13574: my ($state,$msg);
13575: if (-d $path.'/'.$fname) {
13576: $state = 'exists';
13577: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13578: } elsif (-e $path.'/'.$fname) {
13579: $state = 'exists';
13580: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13581: }
13582: if ($state eq 'exists') {
13583: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13584: }
13585: return ($state,$msg);
13586: }
13587:
13588: sub check_for_upload {
13589: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13590: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13591: my $filesize = length($env{'form.'.$element});
13592: if (!$filesize) {
13593: my $msg = '<span class="LC_error">'.
13594: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13595: '<span class="LC_filename">'.$fname.'</span>',
13596: $filesize).'<br />'.
1.1007 raeburn 13597: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13598: '</span>';
13599: return ('zero_bytes',$msg);
13600: }
13601: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13602: my $getpropath = 1;
1.1021 raeburn 13603: my ($dirlistref,$listerror) =
13604: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13605: my $found_file = 0;
13606: my $locked_file = 0;
1.991 raeburn 13607: my @lockers;
13608: my $navmap;
13609: if ($env{'request.course.id'}) {
13610: $navmap = Apache::lonnavmaps::navmap->new();
13611: }
1.1021 raeburn 13612: if (ref($dirlistref) eq 'ARRAY') {
13613: foreach my $line (@{$dirlistref}) {
13614: my ($file_name,$rest)=split(/\&/,$line,2);
13615: if ($file_name eq $fname){
13616: $file_name = $path.$file_name;
13617: if ($group ne '') {
13618: $file_name = $group.$file_name;
13619: }
13620: $found_file = 1;
13621: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13622: foreach my $lock (@lockers) {
13623: if (ref($lock) eq 'ARRAY') {
13624: my ($symb,$crsid) = @{$lock};
13625: if ($crsid eq $env{'request.course.id'}) {
13626: if (ref($navmap)) {
13627: my $res = $navmap->getBySymb($symb);
13628: foreach my $part (@{$res->parts()}) {
13629: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13630: unless (($slot_status == $res->RESERVED) ||
13631: ($slot_status == $res->RESERVED_LOCATION)) {
13632: $locked_file = 1;
13633: }
1.991 raeburn 13634: }
1.1021 raeburn 13635: } else {
13636: $locked_file = 1;
1.991 raeburn 13637: }
13638: } else {
13639: $locked_file = 1;
13640: }
13641: }
1.1021 raeburn 13642: }
13643: } else {
13644: my @info = split(/\&/,$rest);
13645: my $currsize = $info[6]/1000;
13646: if ($currsize < $filesize) {
13647: my $extra = $filesize - $currsize;
13648: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13649: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13650: &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 13651: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13652: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13653: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13654: return ('will_exceed_quota',$msg);
13655: }
1.984 raeburn 13656: }
13657: }
1.661 raeburn 13658: }
13659: }
13660: }
13661: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13662: my $msg = '<p class="LC_warning">'.
13663: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13664: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13665: return ('will_exceed_quota',$msg);
13666: } elsif ($found_file) {
13667: if ($locked_file) {
1.1179 bisitz 13668: my $msg = '<p class="LC_warning">';
1.661 raeburn 13669: $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 13670: $msg .= '</p>';
1.661 raeburn 13671: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13672: return ('file_locked',$msg);
13673: } else {
1.1179 bisitz 13674: my $msg = '<p class="LC_error">';
1.984 raeburn 13675: $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 13676: $msg .= '</p>';
1.984 raeburn 13677: return ('existingfile',$msg);
1.661 raeburn 13678: }
13679: }
13680: }
13681:
1.987 raeburn 13682: sub check_for_traversal {
13683: my ($path,$url,$toplevel) = @_;
13684: my @parts=split(/\//,$path);
13685: my $cleanpath;
13686: my $fullpath = $url;
13687: for (my $i=0;$i<@parts;$i++) {
13688: next if ($parts[$i] eq '.');
13689: if ($parts[$i] eq '..') {
13690: $fullpath =~ s{([^/]+/)$}{};
13691: } else {
13692: $fullpath .= $parts[$i].'/';
13693: }
13694: }
13695: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13696: $cleanpath = $1;
13697: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13698: my $curr_toprel = $1;
13699: my @parts = split(/\//,$curr_toprel);
13700: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13701: my @urlparts = split(/\//,$url_toprel);
13702: my $doubledots;
13703: my $startdiff = -1;
13704: for (my $i=0; $i<@urlparts; $i++) {
13705: if ($startdiff == -1) {
13706: unless ($urlparts[$i] eq $parts[$i]) {
13707: $startdiff = $i;
13708: $doubledots .= '../';
13709: }
13710: } else {
13711: $doubledots .= '../';
13712: }
13713: }
13714: if ($startdiff > -1) {
13715: $cleanpath = $doubledots;
13716: for (my $i=$startdiff; $i<@parts; $i++) {
13717: $cleanpath .= $parts[$i].'/';
13718: }
13719: }
13720: }
13721: $cleanpath =~ s{(/)$}{};
13722: return $cleanpath;
13723: }
1.31 albertel 13724:
1.1053 raeburn 13725: sub is_archive_file {
13726: my ($mimetype) = @_;
13727: if (($mimetype eq 'application/octet-stream') ||
13728: ($mimetype eq 'application/x-stuffit') ||
13729: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13730: return 1;
13731: }
13732: return;
13733: }
13734:
13735: sub decompress_form {
1.1065 raeburn 13736: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13737: my %lt = &Apache::lonlocal::texthash (
13738: this => 'This file is an archive file.',
1.1067 raeburn 13739: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13740: itsc => 'Its contents are as follows:',
1.1053 raeburn 13741: youm => 'You may wish to extract its contents.',
13742: extr => 'Extract contents',
1.1067 raeburn 13743: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13744: proa => 'Process automatically?',
1.1053 raeburn 13745: yes => 'Yes',
13746: no => 'No',
1.1067 raeburn 13747: fold => 'Title for folder containing movie',
13748: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13749: );
1.1065 raeburn 13750: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13751: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13752: my $info = &list_archive_contents($fileloc,\@paths);
13753: if (@paths) {
13754: foreach my $path (@paths) {
13755: $path =~ s{^/}{};
1.1067 raeburn 13756: if ($path =~ m{^([^/]+)/$}) {
13757: $topdir = $1;
13758: }
1.1065 raeburn 13759: if ($path =~ m{^([^/]+)/}) {
13760: $toplevel{$1} = $path;
13761: } else {
13762: $toplevel{$path} = $path;
13763: }
13764: }
13765: }
1.1067 raeburn 13766: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13767: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13768: "$topdir/media/",
13769: "$topdir/media/$topdir.mp4",
13770: "$topdir/media/FirstFrame.png",
13771: "$topdir/media/player.swf",
13772: "$topdir/media/swfobject.js",
13773: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13774: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13775: "$topdir/$topdir.mp4",
13776: "$topdir/$topdir\_config.xml",
13777: "$topdir/$topdir\_controller.swf",
13778: "$topdir/$topdir\_embed.css",
13779: "$topdir/$topdir\_First_Frame.png",
13780: "$topdir/$topdir\_player.html",
13781: "$topdir/$topdir\_Thumbnails.png",
13782: "$topdir/playerProductInstall.swf",
13783: "$topdir/scripts/",
13784: "$topdir/scripts/config_xml.js",
13785: "$topdir/scripts/handlebars.js",
13786: "$topdir/scripts/jquery-1.7.1.min.js",
13787: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13788: "$topdir/scripts/modernizr.js",
13789: "$topdir/scripts/player-min.js",
13790: "$topdir/scripts/swfobject.js",
13791: "$topdir/skins/",
13792: "$topdir/skins/configuration_express.xml",
13793: "$topdir/skins/express_show/",
13794: "$topdir/skins/express_show/player-min.css",
13795: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13796: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13797: "$topdir/$topdir.mp4",
13798: "$topdir/$topdir\_config.xml",
13799: "$topdir/$topdir\_controller.swf",
13800: "$topdir/$topdir\_embed.css",
13801: "$topdir/$topdir\_First_Frame.png",
13802: "$topdir/$topdir\_player.html",
13803: "$topdir/$topdir\_Thumbnails.png",
13804: "$topdir/playerProductInstall.swf",
13805: "$topdir/scripts/",
13806: "$topdir/scripts/config_xml.js",
13807: "$topdir/scripts/techsmith-smart-player.min.js",
13808: "$topdir/skins/",
13809: "$topdir/skins/configuration_express.xml",
13810: "$topdir/skins/express_show/",
13811: "$topdir/skins/express_show/spritesheet.min.css",
13812: "$topdir/skins/express_show/spritesheet.png",
13813: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13814: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13815: if (@diffs == 0) {
1.1164 raeburn 13816: $is_camtasia = 6;
13817: } else {
1.1197 raeburn 13818: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13819: if (@diffs == 0) {
13820: $is_camtasia = 8;
1.1197 raeburn 13821: } else {
13822: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13823: if (@diffs == 0) {
13824: $is_camtasia = 8;
13825: }
1.1164 raeburn 13826: }
1.1067 raeburn 13827: }
13828: }
13829: my $output;
13830: if ($is_camtasia) {
13831: $output = <<"ENDCAM";
13832: <script type="text/javascript" language="Javascript">
13833: // <![CDATA[
13834:
13835: function camtasiaToggle() {
13836: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13837: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13838: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13839: document.getElementById('camtasia_titles').style.display='block';
13840: } else {
13841: document.getElementById('camtasia_titles').style.display='none';
13842: }
13843: }
13844: }
13845: return;
13846: }
13847:
13848: // ]]>
13849: </script>
13850: <p>$lt{'camt'}</p>
13851: ENDCAM
1.1065 raeburn 13852: } else {
1.1067 raeburn 13853: $output = '<p>'.$lt{'this'};
13854: if ($info eq '') {
13855: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13856: } else {
13857: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13858: '<div><pre>'.$info.'</pre></div>';
13859: }
1.1065 raeburn 13860: }
1.1067 raeburn 13861: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13862: my $duplicates;
13863: my $num = 0;
13864: if (ref($dirlist) eq 'ARRAY') {
13865: foreach my $item (@{$dirlist}) {
13866: if (ref($item) eq 'ARRAY') {
13867: if (exists($toplevel{$item->[0]})) {
13868: $duplicates .=
13869: &start_data_table_row().
13870: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13871: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13872: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13873: 'value="1" />'.&mt('Yes').'</label>'.
13874: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13875: '<td>'.$item->[0].'</td>';
13876: if ($item->[2]) {
13877: $duplicates .= '<td>'.&mt('Directory').'</td>';
13878: } else {
13879: $duplicates .= '<td>'.&mt('File').'</td>';
13880: }
13881: $duplicates .= '<td>'.$item->[3].'</td>'.
13882: '<td>'.
13883: &Apache::lonlocal::locallocaltime($item->[4]).
13884: '</td>'.
13885: &end_data_table_row();
13886: $num ++;
13887: }
13888: }
13889: }
13890: }
13891: my $itemcount;
13892: if (@paths > 0) {
13893: $itemcount = scalar(@paths);
13894: } else {
13895: $itemcount = 1;
13896: }
1.1067 raeburn 13897: if ($is_camtasia) {
13898: $output .= $lt{'auto'}.'<br />'.
13899: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13900: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13901: $lt{'yes'}.'</label> <label>'.
13902: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13903: $lt{'no'}.'</label></span><br />'.
13904: '<div id="camtasia_titles" style="display:block">'.
13905: &Apache::lonhtmlcommon::start_pick_box().
13906: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13907: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13908: &Apache::lonhtmlcommon::row_closure().
13909: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13910: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13911: &Apache::lonhtmlcommon::row_closure(1).
13912: &Apache::lonhtmlcommon::end_pick_box().
13913: '</div>';
13914: }
1.1065 raeburn 13915: $output .=
13916: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13917: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13918: "\n";
1.1065 raeburn 13919: if ($duplicates ne '') {
13920: $output .= '<p><span class="LC_warning">'.
13921: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13922: &start_data_table().
13923: &start_data_table_header_row().
13924: '<th>'.&mt('Overwrite?').'</th>'.
13925: '<th>'.&mt('Name').'</th>'.
13926: '<th>'.&mt('Type').'</th>'.
13927: '<th>'.&mt('Size').'</th>'.
13928: '<th>'.&mt('Last modified').'</th>'.
13929: &end_data_table_header_row().
13930: $duplicates.
13931: &end_data_table().
13932: '</p>';
13933: }
1.1067 raeburn 13934: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13935: if (ref($hiddenelements) eq 'HASH') {
13936: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13937: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13938: }
13939: }
13940: $output .= <<"END";
1.1067 raeburn 13941: <br />
1.1053 raeburn 13942: <input type="submit" name="decompress" value="$lt{'extr'}" />
13943: </form>
13944: $noextract
13945: END
13946: return $output;
13947: }
13948:
1.1065 raeburn 13949: sub decompression_utility {
13950: my ($program) = @_;
13951: my @utilities = ('tar','gunzip','bunzip2','unzip');
13952: my $location;
13953: if (grep(/^\Q$program\E$/,@utilities)) {
13954: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13955: '/usr/sbin/') {
13956: if (-x $dir.$program) {
13957: $location = $dir.$program;
13958: last;
13959: }
13960: }
13961: }
13962: return $location;
13963: }
13964:
13965: sub list_archive_contents {
13966: my ($file,$pathsref) = @_;
13967: my (@cmd,$output);
13968: my $needsregexp;
13969: if ($file =~ /\.zip$/) {
13970: @cmd = (&decompression_utility('unzip'),"-l");
13971: $needsregexp = 1;
13972: } elsif (($file =~ m/\.tar\.gz$/) ||
13973: ($file =~ /\.tgz$/)) {
13974: @cmd = (&decompression_utility('tar'),"-ztf");
13975: } elsif ($file =~ /\.tar\.bz2$/) {
13976: @cmd = (&decompression_utility('tar'),"-jtf");
13977: } elsif ($file =~ m|\.tar$|) {
13978: @cmd = (&decompression_utility('tar'),"-tf");
13979: }
13980: if (@cmd) {
13981: undef($!);
13982: undef($@);
13983: if (open(my $fh,"-|", @cmd, $file)) {
13984: while (my $line = <$fh>) {
13985: $output .= $line;
13986: chomp($line);
13987: my $item;
13988: if ($needsregexp) {
13989: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13990: } else {
13991: $item = $line;
13992: }
13993: if ($item ne '') {
13994: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13995: push(@{$pathsref},$item);
13996: }
13997: }
13998: }
13999: close($fh);
14000: }
14001: }
14002: return $output;
14003: }
14004:
1.1053 raeburn 14005: sub decompress_uploaded_file {
14006: my ($file,$dir) = @_;
14007: &Apache::lonnet::appenv({'cgi.file' => $file});
14008: &Apache::lonnet::appenv({'cgi.dir' => $dir});
14009: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
14010: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
14011: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
14012: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
14013: my $decompressed = $env{'cgi.decompressed'};
14014: &Apache::lonnet::delenv('cgi.file');
14015: &Apache::lonnet::delenv('cgi.dir');
14016: &Apache::lonnet::delenv('cgi.decompressed');
14017: return ($decompressed,$result);
14018: }
14019:
1.1055 raeburn 14020: sub process_decompression {
14021: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 14022: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
14023: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14024: &mt('Unexpected file path.').'</p>'."\n";
14025: }
14026: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
14027: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14028: &mt('Unexpected course context.').'</p>'."\n";
14029: }
1.1293 raeburn 14030: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 14031: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14032: &mt('Filename contained unexpected characters.').'</p>'."\n";
14033: }
1.1055 raeburn 14034: my ($dir,$error,$warning,$output);
1.1180 raeburn 14035: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 14036: $error = &mt('Filename not a supported archive file type.').
14037: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 14038: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
14039: } else {
14040: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14041: if ($docuhome eq 'no_host') {
14042: $error = &mt('Could not determine home server for course.');
14043: } else {
14044: my @ids=&Apache::lonnet::current_machine_ids();
14045: my $currdir = "$dir_root/$destination";
14046: if (grep(/^\Q$docuhome\E$/,@ids)) {
14047: $dir = &LONCAPA::propath($docudom,$docuname).
14048: "$dir_root/$destination";
14049: } else {
14050: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
14051: "$dir_root/$docudom/$docuname/$destination";
14052: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
14053: $error = &mt('Archive file not found.');
14054: }
14055: }
1.1065 raeburn 14056: my (@to_overwrite,@to_skip);
14057: if ($env{'form.archive_overwrite_total'} > 0) {
14058: my $total = $env{'form.archive_overwrite_total'};
14059: for (my $i=0; $i<$total; $i++) {
14060: if ($env{'form.archive_overwrite_'.$i} == 1) {
14061: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
14062: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
14063: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
14064: }
14065: }
14066: }
14067: my $numskip = scalar(@to_skip);
1.1292 raeburn 14068: my $numoverwrite = scalar(@to_overwrite);
14069: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 14070: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
14071: } elsif ($dir eq '') {
1.1055 raeburn 14072: $error = &mt('Directory containing archive file unavailable.');
14073: } elsif (!$error) {
1.1065 raeburn 14074: my ($decompressed,$display);
1.1292 raeburn 14075: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 14076: my $tempdir = time.'_'.$$.int(rand(10000));
14077: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 14078: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
14079: ($decompressed,$display) =
14080: &decompress_uploaded_file($file,"$dir/$tempdir");
14081: foreach my $item (@to_skip) {
14082: if (($item ne '') && ($item !~ /\.\./)) {
14083: if (-f "$dir/$tempdir/$item") {
14084: unlink("$dir/$tempdir/$item");
14085: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 14086: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 14087: }
14088: }
14089: }
14090: foreach my $item (@to_overwrite) {
14091: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
14092: if (($item ne '') && ($item !~ /\.\./)) {
14093: if (-f "$dir/$item") {
14094: unlink("$dir/$item");
14095: } elsif (-d "$dir/$item") {
1.1300 raeburn 14096: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 14097: }
14098: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
14099: }
1.1065 raeburn 14100: }
14101: }
1.1292 raeburn 14102: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 14103: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 14104: }
1.1065 raeburn 14105: }
14106: } else {
14107: ($decompressed,$display) =
14108: &decompress_uploaded_file($file,$dir);
14109: }
1.1055 raeburn 14110: if ($decompressed eq 'ok') {
1.1065 raeburn 14111: $output = '<p class="LC_info">'.
14112: &mt('Files extracted successfully from archive.').
14113: '</p>'."\n";
1.1055 raeburn 14114: my ($warning,$result,@contents);
14115: my ($newdirlistref,$newlisterror) =
14116: &Apache::lonnet::dirlist($currdir,$docudom,
14117: $docuname,1);
14118: my (%is_dir,%changes,@newitems);
14119: my $dirptr = 16384;
1.1065 raeburn 14120: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 14121: foreach my $dir_line (@{$newdirlistref}) {
14122: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 14123: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 14124: push(@newitems,$item);
14125: if ($dirptr&$testdir) {
14126: $is_dir{$item} = 1;
14127: }
14128: $changes{$item} = 1;
14129: }
14130: }
14131: }
14132: if (keys(%changes) > 0) {
14133: foreach my $item (sort(@newitems)) {
14134: if ($changes{$item}) {
14135: push(@contents,$item);
14136: }
14137: }
14138: }
14139: if (@contents > 0) {
1.1067 raeburn 14140: my $wantform;
14141: unless ($env{'form.autoextract_camtasia'}) {
14142: $wantform = 1;
14143: }
1.1056 raeburn 14144: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 14145: my ($count,$datatable) = &get_extracted($docudom,$docuname,
14146: $currdir,\%is_dir,
14147: \%children,\%parent,
1.1056 raeburn 14148: \@contents,\%dirorder,
14149: \%titles,$wantform);
1.1055 raeburn 14150: if ($datatable ne '') {
14151: $output .= &archive_options_form('decompressed',$datatable,
14152: $count,$hiddenelem);
1.1065 raeburn 14153: my $startcount = 6;
1.1055 raeburn 14154: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 14155: \%titles,\%children);
1.1055 raeburn 14156: }
1.1067 raeburn 14157: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 14158: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 14159: my %displayed;
14160: my $total = 1;
14161: $env{'form.archive_directory'} = [];
14162: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
14163: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
14164: $path =~ s{/$}{};
14165: my $item;
14166: if ($path ne '') {
14167: $item = "$path/$titles{$i}";
14168: } else {
14169: $item = $titles{$i};
14170: }
14171: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
14172: if ($item eq $contents[0]) {
14173: push(@{$env{'form.archive_directory'}},$i);
14174: $env{'form.archive_'.$i} = 'display';
14175: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
14176: $displayed{'folder'} = $i;
1.1164 raeburn 14177: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
14178: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 14179: $env{'form.archive_'.$i} = 'display';
14180: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
14181: $displayed{'web'} = $i;
14182: } else {
1.1164 raeburn 14183: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
14184: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
14185: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 14186: push(@{$env{'form.archive_directory'}},$i);
14187: }
14188: $env{'form.archive_'.$i} = 'dependency';
14189: }
14190: $total ++;
14191: }
14192: for (my $i=1; $i<$total; $i++) {
14193: next if ($i == $displayed{'web'});
14194: next if ($i == $displayed{'folder'});
14195: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
14196: }
14197: $env{'form.phase'} = 'decompress_cleanup';
14198: $env{'form.archivedelete'} = 1;
14199: $env{'form.archive_count'} = $total-1;
14200: $output .=
14201: &process_extracted_files('coursedocs',$docudom,
14202: $docuname,$destination,
14203: $dir_root,$hiddenelem);
14204: }
1.1055 raeburn 14205: } else {
14206: $warning = &mt('No new items extracted from archive file.');
14207: }
14208: } else {
14209: $output = $display;
14210: $error = &mt('An error occurred during extraction from the archive file.');
14211: }
14212: }
14213: }
14214: }
14215: if ($error) {
14216: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14217: $error.'</p>'."\n";
14218: }
14219: if ($warning) {
14220: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14221: }
14222: return $output;
14223: }
14224:
14225: sub get_extracted {
1.1056 raeburn 14226: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
14227: $titles,$wantform) = @_;
1.1055 raeburn 14228: my $count = 0;
14229: my $depth = 0;
14230: my $datatable;
1.1056 raeburn 14231: my @hierarchy;
1.1055 raeburn 14232: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 14233: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
14234: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 14235: foreach my $item (@{$contents}) {
14236: $count ++;
1.1056 raeburn 14237: @{$dirorder->{$count}} = @hierarchy;
14238: $titles->{$count} = $item;
1.1055 raeburn 14239: &archive_hierarchy($depth,$count,$parent,$children);
14240: if ($wantform) {
14241: $datatable .= &archive_row($is_dir->{$item},$item,
14242: $currdir,$depth,$count);
14243: }
14244: if ($is_dir->{$item}) {
14245: $depth ++;
1.1056 raeburn 14246: push(@hierarchy,$count);
14247: $parent->{$depth} = $count;
1.1055 raeburn 14248: $datatable .=
14249: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14250: \$depth,\$count,\@hierarchy,$dirorder,
14251: $children,$parent,$titles,$wantform);
1.1055 raeburn 14252: $depth --;
1.1056 raeburn 14253: pop(@hierarchy);
1.1055 raeburn 14254: }
14255: }
14256: return ($count,$datatable);
14257: }
14258:
14259: sub recurse_extracted_archive {
1.1056 raeburn 14260: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14261: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14262: my $result='';
1.1056 raeburn 14263: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14264: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14265: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14266: return $result;
14267: }
14268: my $dirptr = 16384;
14269: my ($newdirlistref,$newlisterror) =
14270: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14271: if (ref($newdirlistref) eq 'ARRAY') {
14272: foreach my $dir_line (@{$newdirlistref}) {
14273: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14274: unless ($item =~ /^\.+$/) {
14275: $$count ++;
1.1056 raeburn 14276: @{$dirorder->{$$count}} = @{$hierarchy};
14277: $titles->{$$count} = $item;
1.1055 raeburn 14278: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14279:
1.1055 raeburn 14280: my $is_dir;
14281: if ($dirptr&$testdir) {
14282: $is_dir = 1;
14283: }
14284: if ($wantform) {
14285: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14286: }
14287: if ($is_dir) {
14288: $$depth ++;
1.1056 raeburn 14289: push(@{$hierarchy},$$count);
14290: $parent->{$$depth} = $$count;
1.1055 raeburn 14291: $result .=
14292: &recurse_extracted_archive("$currdir/$item",$docudom,
14293: $docuname,$depth,$count,
1.1056 raeburn 14294: $hierarchy,$dirorder,$children,
14295: $parent,$titles,$wantform);
1.1055 raeburn 14296: $$depth --;
1.1056 raeburn 14297: pop(@{$hierarchy});
1.1055 raeburn 14298: }
14299: }
14300: }
14301: }
14302: return $result;
14303: }
14304:
14305: sub archive_hierarchy {
14306: my ($depth,$count,$parent,$children) =@_;
14307: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14308: if (exists($parent->{$depth})) {
14309: $children->{$parent->{$depth}} .= $count.':';
14310: }
14311: }
14312: return;
14313: }
14314:
14315: sub archive_row {
14316: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14317: my ($name) = ($item =~ m{([^/]+)$});
14318: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14319: 'display' => 'Add as file',
1.1055 raeburn 14320: 'dependency' => 'Include as dependency',
14321: 'discard' => 'Discard',
14322: );
14323: if ($is_dir) {
1.1059 raeburn 14324: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14325: }
1.1056 raeburn 14326: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14327: my $offset = 0;
1.1055 raeburn 14328: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14329: $offset ++;
1.1065 raeburn 14330: if ($action ne 'display') {
14331: $offset ++;
14332: }
1.1055 raeburn 14333: $output .= '<td><span class="LC_nobreak">'.
14334: '<label><input type="radio" name="archive_'.$count.
14335: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14336: my $text = $choices{$action};
14337: if ($is_dir) {
14338: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14339: if ($action eq 'display') {
1.1059 raeburn 14340: $text = &mt('Add as folder');
1.1055 raeburn 14341: }
1.1056 raeburn 14342: } else {
14343: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14344:
14345: }
14346: $output .= ' /> '.$choices{$action}.'</label></span>';
14347: if ($action eq 'dependency') {
14348: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14349: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14350: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14351: '<option value=""></option>'."\n".
14352: '</select>'."\n".
14353: '</div>';
1.1059 raeburn 14354: } elsif ($action eq 'display') {
14355: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14356: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14357: '</div>';
1.1055 raeburn 14358: }
1.1056 raeburn 14359: $output .= '</td>';
1.1055 raeburn 14360: }
14361: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14362: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14363: for (my $i=0; $i<$depth; $i++) {
14364: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14365: }
14366: if ($is_dir) {
14367: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14368: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14369: } else {
14370: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14371: }
14372: $output .= ' '.$name.'</td>'."\n".
14373: &end_data_table_row();
14374: return $output;
14375: }
14376:
14377: sub archive_options_form {
1.1065 raeburn 14378: my ($form,$display,$count,$hiddenelem) = @_;
14379: my %lt = &Apache::lonlocal::texthash(
14380: perm => 'Permanently remove archive file?',
14381: hows => 'How should each extracted item be incorporated in the course?',
14382: cont => 'Content actions for all',
14383: addf => 'Add as folder/file',
14384: incd => 'Include as dependency for a displayed file',
14385: disc => 'Discard',
14386: no => 'No',
14387: yes => 'Yes',
14388: save => 'Save',
14389: );
14390: my $output = <<"END";
14391: <form name="$form" method="post" action="">
14392: <p><span class="LC_nobreak">$lt{'perm'}
14393: <label>
14394: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14395: </label>
14396:
14397: <label>
14398: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14399: </span>
14400: </p>
14401: <input type="hidden" name="phase" value="decompress_cleanup" />
14402: <br />$lt{'hows'}
14403: <div class="LC_columnSection">
14404: <fieldset>
14405: <legend>$lt{'cont'}</legend>
14406: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14407: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14408: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14409: </fieldset>
14410: </div>
14411: END
14412: return $output.
1.1055 raeburn 14413: &start_data_table()."\n".
1.1065 raeburn 14414: $display."\n".
1.1055 raeburn 14415: &end_data_table()."\n".
14416: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14417: $hiddenelem.
1.1065 raeburn 14418: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14419: '</form>';
14420: }
14421:
14422: sub archive_javascript {
1.1056 raeburn 14423: my ($startcount,$numitems,$titles,$children) = @_;
14424: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14425: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14426: my $scripttag = <<START;
14427: <script type="text/javascript">
14428: // <![CDATA[
14429:
14430: function checkAll(form,prefix) {
14431: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14432: for (var i=0; i < form.elements.length; i++) {
14433: var id = form.elements[i].id;
14434: if ((id != '') && (id != undefined)) {
14435: if (idstr.test(id)) {
14436: if (form.elements[i].type == 'radio') {
14437: form.elements[i].checked = true;
1.1056 raeburn 14438: var nostart = i-$startcount;
1.1059 raeburn 14439: var offset = nostart%7;
14440: var count = (nostart-offset)/7;
1.1056 raeburn 14441: dependencyCheck(form,count,offset);
1.1055 raeburn 14442: }
14443: }
14444: }
14445: }
14446: }
14447:
14448: function propagateCheck(form,count) {
14449: if (count > 0) {
1.1059 raeburn 14450: var startelement = $startcount + ((count-1) * 7);
14451: for (var j=1; j<6; j++) {
14452: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14453: var item = startelement + j;
14454: if (form.elements[item].type == 'radio') {
14455: if (form.elements[item].checked) {
14456: containerCheck(form,count,j);
14457: break;
14458: }
1.1055 raeburn 14459: }
14460: }
14461: }
14462: }
14463: }
14464:
14465: numitems = $numitems
1.1056 raeburn 14466: var titles = new Array(numitems);
14467: var parents = new Array(numitems);
1.1055 raeburn 14468: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14469: parents[i] = new Array;
1.1055 raeburn 14470: }
1.1059 raeburn 14471: var maintitle = '$maintitle';
1.1055 raeburn 14472:
14473: START
14474:
1.1056 raeburn 14475: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14476: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14477: for (my $i=0; $i<@contents; $i ++) {
14478: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14479: }
14480: }
14481:
1.1056 raeburn 14482: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14483: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14484: }
14485:
1.1055 raeburn 14486: $scripttag .= <<END;
14487:
14488: function containerCheck(form,count,offset) {
14489: if (count > 0) {
1.1056 raeburn 14490: dependencyCheck(form,count,offset);
1.1059 raeburn 14491: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14492: form.elements[item].checked = true;
14493: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14494: if (parents[count].length > 0) {
14495: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14496: containerCheck(form,parents[count][j],offset);
14497: }
14498: }
14499: }
14500: }
14501: }
14502:
14503: function dependencyCheck(form,count,offset) {
14504: if (count > 0) {
1.1059 raeburn 14505: var chosen = (offset+$startcount)+7*(count-1);
14506: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14507: var currtype = form.elements[depitem].type;
14508: if (form.elements[chosen].value == 'dependency') {
14509: document.getElementById('arc_depon_'+count).style.display='block';
14510: form.elements[depitem].options.length = 0;
14511: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14512: for (var i=1; i<=numitems; i++) {
14513: if (i == count) {
14514: continue;
14515: }
1.1059 raeburn 14516: var startelement = $startcount + (i-1) * 7;
14517: for (var j=1; j<6; j++) {
14518: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14519: var item = startelement + j;
14520: if (form.elements[item].type == 'radio') {
14521: if (form.elements[item].checked) {
14522: if (form.elements[item].value == 'display') {
14523: var n = form.elements[depitem].options.length;
14524: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14525: }
14526: }
14527: }
14528: }
14529: }
14530: }
14531: } else {
14532: document.getElementById('arc_depon_'+count).style.display='none';
14533: form.elements[depitem].options.length = 0;
14534: form.elements[depitem].options[0] = new Option('Select','',true,true);
14535: }
1.1059 raeburn 14536: titleCheck(form,count,offset);
1.1056 raeburn 14537: }
14538: }
14539:
14540: function propagateSelect(form,count,offset) {
14541: if (count > 0) {
1.1065 raeburn 14542: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14543: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14544: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14545: if (parents[count].length > 0) {
14546: for (var j=0; j<parents[count].length; j++) {
14547: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14548: }
14549: }
14550: }
14551: }
14552: }
1.1056 raeburn 14553:
14554: function containerSelect(form,count,offset,picked) {
14555: if (count > 0) {
1.1065 raeburn 14556: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14557: if (form.elements[item].type == 'radio') {
14558: if (form.elements[item].value == 'dependency') {
14559: if (form.elements[item+1].type == 'select-one') {
14560: for (var i=0; i<form.elements[item+1].options.length; i++) {
14561: if (form.elements[item+1].options[i].value == picked) {
14562: form.elements[item+1].selectedIndex = i;
14563: break;
14564: }
14565: }
14566: }
14567: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14568: if (parents[count].length > 0) {
14569: for (var j=0; j<parents[count].length; j++) {
14570: containerSelect(form,parents[count][j],offset,picked);
14571: }
14572: }
14573: }
14574: }
14575: }
14576: }
14577: }
14578:
1.1059 raeburn 14579: function titleCheck(form,count,offset) {
14580: if (count > 0) {
14581: var chosen = (offset+$startcount)+7*(count-1);
14582: var depitem = $startcount + ((count-1) * 7) + 2;
14583: var currtype = form.elements[depitem].type;
14584: if (form.elements[chosen].value == 'display') {
14585: document.getElementById('arc_title_'+count).style.display='block';
14586: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14587: document.getElementById('archive_title_'+count).value=maintitle;
14588: }
14589: } else {
14590: document.getElementById('arc_title_'+count).style.display='none';
14591: if (currtype == 'text') {
14592: document.getElementById('archive_title_'+count).value='';
14593: }
14594: }
14595: }
14596: return;
14597: }
14598:
1.1055 raeburn 14599: // ]]>
14600: </script>
14601: END
14602: return $scripttag;
14603: }
14604:
14605: sub process_extracted_files {
1.1067 raeburn 14606: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14607: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14608: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14609: my @ids=&Apache::lonnet::current_machine_ids();
14610: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14611: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14612: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14613: if (grep(/^\Q$docuhome\E$/,@ids)) {
14614: $prefix = &LONCAPA::propath($docudom,$docuname);
14615: $pathtocheck = "$dir_root/$destination";
14616: $dir = $dir_root;
14617: $ishome = 1;
14618: } else {
14619: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14620: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14621: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14622: }
14623: my $currdir = "$dir_root/$destination";
14624: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14625: if ($env{'form.folderpath'}) {
14626: my @items = split('&',$env{'form.folderpath'});
14627: $folders{'0'} = $items[-2];
1.1099 raeburn 14628: if ($env{'form.folderpath'} =~ /\:1$/) {
14629: $containers{'0'}='page';
14630: } else {
14631: $containers{'0'}='sequence';
14632: }
1.1055 raeburn 14633: }
14634: my @archdirs = &get_env_multiple('form.archive_directory');
14635: if ($numitems) {
14636: for (my $i=1; $i<=$numitems; $i++) {
14637: my $path = $env{'form.archive_content_'.$i};
14638: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14639: my $item = $1;
14640: $toplevelitems{$item} = $i;
14641: if (grep(/^\Q$i\E$/,@archdirs)) {
14642: $is_dir{$item} = 1;
14643: }
14644: }
14645: }
14646: }
1.1067 raeburn 14647: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14648: if (keys(%toplevelitems) > 0) {
14649: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14650: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14651: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14652: }
1.1066 raeburn 14653: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14654: if ($numitems) {
14655: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14656: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14657: my $path = $env{'form.archive_content_'.$i};
14658: if ($path =~ /^\Q$pathtocheck\E/) {
14659: if ($env{'form.archive_'.$i} eq 'discard') {
14660: if ($prefix ne '' && $path ne '') {
14661: if (-e $prefix.$path) {
1.1066 raeburn 14662: if ((@archdirs > 0) &&
14663: (grep(/^\Q$i\E$/,@archdirs))) {
14664: $todeletedir{$prefix.$path} = 1;
14665: } else {
14666: $todelete{$prefix.$path} = 1;
14667: }
1.1055 raeburn 14668: }
14669: }
14670: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14671: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14672: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14673: $docstitle = $env{'form.archive_title_'.$i};
14674: if ($docstitle eq '') {
14675: $docstitle = $title;
14676: }
1.1055 raeburn 14677: $outer = 0;
1.1056 raeburn 14678: if (ref($dirorder{$i}) eq 'ARRAY') {
14679: if (@{$dirorder{$i}} > 0) {
14680: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14681: if ($env{'form.archive_'.$item} eq 'display') {
14682: $outer = $item;
14683: last;
14684: }
14685: }
14686: }
14687: }
14688: my ($errtext,$fatal) =
14689: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14690: '/'.$folders{$outer}.'.'.
14691: $containers{$outer});
14692: next if ($fatal);
14693: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14694: if ($context eq 'coursedocs') {
1.1056 raeburn 14695: $mapinner{$i} = time;
1.1055 raeburn 14696: $folders{$i} = 'default_'.$mapinner{$i};
14697: $containers{$i} = 'sequence';
14698: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14699: $folders{$i}.'.'.$containers{$i};
14700: my $newidx = &LONCAPA::map::getresidx();
14701: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14702: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14703: push(@LONCAPA::map::order,$newidx);
14704: my ($outtext,$errtext) =
14705: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14706: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14707: '.'.$containers{$outer},1,1);
1.1056 raeburn 14708: $newseqid{$i} = $newidx;
1.1067 raeburn 14709: unless ($errtext) {
1.1294 raeburn 14710: $result .= '<li>'.&mt('Folder: [_1] added to course',
14711: &HTML::Entities::encode($docstitle,'<>&"')).
14712: '</li>'."\n";
1.1067 raeburn 14713: }
1.1055 raeburn 14714: }
14715: } else {
14716: if ($context eq 'coursedocs') {
14717: my $newidx=&LONCAPA::map::getresidx();
14718: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14719: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14720: $title;
1.1392 raeburn 14721: if (($outer !~ /\D/) &&
14722: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14723: ($newidx !~ /\D/)) {
1.1294 raeburn 14724: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14725: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14726: }
14727: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14728: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14729: }
14730: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14731: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14732: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14733: unless ($ishome) {
14734: my $fetch = "$newdest{$i}/$title";
14735: $fetch =~ s/^\Q$prefix$dir\E//;
14736: $prompttofetch{$fetch} = 1;
14737: }
1.1292 raeburn 14738: }
1.1067 raeburn 14739: }
1.1294 raeburn 14740: $LONCAPA::map::resources[$newidx]=
14741: $docstitle.':'.$url.':false:normal:res';
14742: push(@LONCAPA::map::order, $newidx);
14743: my ($outtext,$errtext)=
14744: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14745: $docuname.'/'.$folders{$outer}.
14746: '.'.$containers{$outer},1,1);
14747: unless ($errtext) {
14748: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14749: $result .= '<li>'.&mt('File: [_1] added to course',
14750: &HTML::Entities::encode($docstitle,'<>&"')).
14751: '</li>'."\n";
14752: }
1.1067 raeburn 14753: }
1.1294 raeburn 14754: } else {
14755: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14756: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14757: }
1.1055 raeburn 14758: }
14759: }
1.1086 raeburn 14760: }
14761: } else {
1.1294 raeburn 14762: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14763: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14764: }
14765: }
14766: for (my $i=1; $i<=$numitems; $i++) {
14767: next unless ($env{'form.archive_'.$i} eq 'dependency');
14768: my $path = $env{'form.archive_content_'.$i};
14769: if ($path =~ /^\Q$pathtocheck\E/) {
14770: my ($title) = ($path =~ m{/([^/]+)$});
14771: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14772: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14773: if (ref($dirorder{$i}) eq 'ARRAY') {
14774: my ($itemidx,$fullpath,$relpath);
14775: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14776: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14777: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14778: if ($dirorder{$i}->[$j] eq $container) {
14779: $itemidx = $j;
1.1056 raeburn 14780: }
14781: }
1.1086 raeburn 14782: }
14783: if ($itemidx eq '') {
14784: $itemidx = 0;
14785: }
14786: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14787: if ($mapinner{$referrer{$i}}) {
14788: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14789: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14790: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14791: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14792: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14793: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14794: if (!-e $fullpath) {
14795: mkdir($fullpath,0755);
1.1056 raeburn 14796: }
14797: }
1.1086 raeburn 14798: } else {
14799: last;
1.1056 raeburn 14800: }
1.1086 raeburn 14801: }
14802: }
14803: } elsif ($newdest{$referrer{$i}}) {
14804: $fullpath = $newdest{$referrer{$i}};
14805: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14806: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14807: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14808: last;
14809: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14810: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14811: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14812: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14813: if (!-e $fullpath) {
14814: mkdir($fullpath,0755);
1.1056 raeburn 14815: }
14816: }
1.1086 raeburn 14817: } else {
14818: last;
1.1056 raeburn 14819: }
1.1055 raeburn 14820: }
14821: }
1.1086 raeburn 14822: if ($fullpath ne '') {
14823: if (-e "$prefix$path") {
1.1292 raeburn 14824: unless (rename("$prefix$path","$fullpath/$title")) {
14825: $warning .= &mt('Failed to rename dependency').'<br />';
14826: }
1.1086 raeburn 14827: }
14828: if (-e "$fullpath/$title") {
14829: my $showpath;
14830: if ($relpath ne '') {
14831: $showpath = "$relpath/$title";
14832: } else {
14833: $showpath = "/$title";
14834: }
1.1294 raeburn 14835: $result .= '<li>'.&mt('[_1] included as a dependency',
14836: &HTML::Entities::encode($showpath,'<>&"')).
14837: '</li>'."\n";
1.1292 raeburn 14838: unless ($ishome) {
14839: my $fetch = "$fullpath/$title";
14840: $fetch =~ s/^\Q$prefix$dir\E//;
14841: $prompttofetch{$fetch} = 1;
14842: }
1.1086 raeburn 14843: }
14844: }
1.1055 raeburn 14845: }
1.1086 raeburn 14846: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14847: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14848: &HTML::Entities::encode($path,'<>&"'),
14849: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14850: '<br />';
1.1055 raeburn 14851: }
14852: } else {
1.1294 raeburn 14853: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14854: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14855: }
14856: }
14857: if (keys(%todelete)) {
14858: foreach my $key (keys(%todelete)) {
14859: unlink($key);
1.1066 raeburn 14860: }
14861: }
14862: if (keys(%todeletedir)) {
14863: foreach my $key (keys(%todeletedir)) {
14864: rmdir($key);
14865: }
14866: }
14867: foreach my $dir (sort(keys(%is_dir))) {
14868: if (($pathtocheck ne '') && ($dir ne '')) {
14869: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14870: }
14871: }
1.1067 raeburn 14872: if ($result ne '') {
14873: $output .= '<ul>'."\n".
14874: $result."\n".
14875: '</ul>';
14876: }
14877: unless ($ishome) {
14878: my $replicationfail;
14879: foreach my $item (keys(%prompttofetch)) {
14880: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14881: unless ($fetchresult eq 'ok') {
14882: $replicationfail .= '<li>'.$item.'</li>'."\n";
14883: }
14884: }
14885: if ($replicationfail) {
14886: $output .= '<p class="LC_error">'.
14887: &mt('Course home server failed to retrieve:').'<ul>'.
14888: $replicationfail.
14889: '</ul></p>';
14890: }
14891: }
1.1055 raeburn 14892: } else {
14893: $warning = &mt('No items found in archive.');
14894: }
14895: if ($error) {
14896: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14897: $error.'</p>'."\n";
14898: }
14899: if ($warning) {
14900: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14901: }
14902: return $output;
14903: }
14904:
1.1066 raeburn 14905: sub cleanup_empty_dirs {
14906: my ($path) = @_;
14907: if (($path ne '') && (-d $path)) {
14908: if (opendir(my $dirh,$path)) {
14909: my @dircontents = grep(!/^\./,readdir($dirh));
14910: my $numitems = 0;
14911: foreach my $item (@dircontents) {
14912: if (-d "$path/$item") {
1.1111 raeburn 14913: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14914: if (-e "$path/$item") {
14915: $numitems ++;
14916: }
14917: } else {
14918: $numitems ++;
14919: }
14920: }
14921: if ($numitems == 0) {
14922: rmdir($path);
14923: }
14924: closedir($dirh);
14925: }
14926: }
14927: return;
14928: }
14929:
1.41 ng 14930: =pod
1.45 matthew 14931:
1.1162 raeburn 14932: =item * &get_folder_hierarchy()
1.1068 raeburn 14933:
14934: Provides hierarchy of names of folders/sub-folders containing the current
14935: item,
14936:
14937: Inputs: 3
14938: - $navmap - navmaps object
14939:
14940: - $map - url for map (either the trigger itself, or map containing
14941: the resource, which is the trigger).
14942:
14943: - $showitem - 1 => show title for map itself; 0 => do not show.
14944:
14945: Outputs: 1 @pathitems - array of folder/subfolder names.
14946:
14947: =cut
14948:
14949: sub get_folder_hierarchy {
14950: my ($navmap,$map,$showitem) = @_;
14951: my @pathitems;
14952: if (ref($navmap)) {
14953: my $mapres = $navmap->getResourceByUrl($map);
14954: if (ref($mapres)) {
14955: my $pcslist = $mapres->map_hierarchy();
14956: if ($pcslist ne '') {
14957: my @pcs = split(/,/,$pcslist);
14958: foreach my $pc (@pcs) {
14959: if ($pc == 1) {
1.1129 raeburn 14960: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14961: } else {
14962: my $res = $navmap->getByMapPc($pc);
14963: if (ref($res)) {
14964: my $title = $res->compTitle();
14965: $title =~ s/\W+/_/g;
14966: if ($title ne '') {
14967: push(@pathitems,$title);
14968: }
14969: }
14970: }
14971: }
14972: }
1.1071 raeburn 14973: if ($showitem) {
14974: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14975: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14976: } else {
14977: my $maptitle = $mapres->compTitle();
14978: $maptitle =~ s/\W+/_/g;
14979: if ($maptitle ne '') {
14980: push(@pathitems,$maptitle);
14981: }
1.1068 raeburn 14982: }
14983: }
14984: }
14985: }
14986: return @pathitems;
14987: }
14988:
14989: =pod
14990:
1.1015 raeburn 14991: =item * &get_turnedin_filepath()
14992:
14993: Determines path in a user's portfolio file for storage of files uploaded
14994: to a specific essayresponse or dropbox item.
14995:
14996: Inputs: 3 required + 1 optional.
14997: $symb is symb for resource, $uname and $udom are for current user (required).
14998: $caller is optional (can be "submission", if routine is called when storing
14999: an upoaded file when "Submit Answer" button was pressed).
15000:
15001: Returns array containing $path and $multiresp.
15002: $path is path in portfolio. $multiresp is 1 if this resource contains more
15003: than one file upload item. Callers of routine should append partid as a
15004: subdirectory to $path in cases where $multiresp is 1.
15005:
15006: Called by: homework/essayresponse.pm and homework/structuretags.pm
15007:
15008: =cut
15009:
15010: sub get_turnedin_filepath {
15011: my ($symb,$uname,$udom,$caller) = @_;
15012: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
15013: my $turnindir;
15014: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
15015: $turnindir = $userhash{'turnindir'};
15016: my ($path,$multiresp);
15017: if ($turnindir eq '') {
15018: if ($caller eq 'submission') {
15019: $turnindir = &mt('turned in');
15020: $turnindir =~ s/\W+/_/g;
15021: my %newhash = (
15022: 'turnindir' => $turnindir,
15023: );
15024: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
15025: }
15026: }
15027: if ($turnindir ne '') {
15028: $path = '/'.$turnindir.'/';
15029: my ($multipart,$turnin,@pathitems);
15030: my $navmap = Apache::lonnavmaps::navmap->new();
15031: if (defined($navmap)) {
15032: my $mapres = $navmap->getResourceByUrl($map);
15033: if (ref($mapres)) {
15034: my $pcslist = $mapres->map_hierarchy();
15035: if ($pcslist ne '') {
15036: foreach my $pc (split(/,/,$pcslist)) {
15037: my $res = $navmap->getByMapPc($pc);
15038: if (ref($res)) {
15039: my $title = $res->compTitle();
15040: $title =~ s/\W+/_/g;
15041: if ($title ne '') {
1.1149 raeburn 15042: if (($pc > 1) && (length($title) > 12)) {
15043: $title = substr($title,0,12);
15044: }
1.1015 raeburn 15045: push(@pathitems,$title);
15046: }
15047: }
15048: }
15049: }
15050: my $maptitle = $mapres->compTitle();
15051: $maptitle =~ s/\W+/_/g;
15052: if ($maptitle ne '') {
1.1149 raeburn 15053: if (length($maptitle) > 12) {
15054: $maptitle = substr($maptitle,0,12);
15055: }
1.1015 raeburn 15056: push(@pathitems,$maptitle);
15057: }
15058: unless ($env{'request.state'} eq 'construct') {
15059: my $res = $navmap->getBySymb($symb);
15060: if (ref($res)) {
15061: my $partlist = $res->parts();
15062: my $totaluploads = 0;
15063: if (ref($partlist) eq 'ARRAY') {
15064: foreach my $part (@{$partlist}) {
15065: my @types = $res->responseType($part);
15066: my @ids = $res->responseIds($part);
15067: for (my $i=0; $i < scalar(@ids); $i++) {
15068: if ($types[$i] eq 'essay') {
15069: my $partid = $part.'_'.$ids[$i];
15070: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
15071: $totaluploads ++;
15072: }
15073: }
15074: }
15075: }
15076: if ($totaluploads > 1) {
15077: $multiresp = 1;
15078: }
15079: }
15080: }
15081: }
15082: } else {
15083: return;
15084: }
15085: } else {
15086: return;
15087: }
15088: my $restitle=&Apache::lonnet::gettitle($symb);
15089: $restitle =~ s/\W+/_/g;
15090: if ($restitle eq '') {
15091: $restitle = ($resurl =~ m{/[^/]+$});
15092: if ($restitle eq '') {
15093: $restitle = time;
15094: }
15095: }
1.1149 raeburn 15096: if (length($restitle) > 12) {
15097: $restitle = substr($restitle,0,12);
15098: }
1.1015 raeburn 15099: push(@pathitems,$restitle);
15100: $path .= join('/',@pathitems);
15101: }
15102: return ($path,$multiresp);
15103: }
15104:
15105: =pod
15106:
1.464 albertel 15107: =back
1.41 ng 15108:
1.112 bowersj2 15109: =head1 CSV Upload/Handling functions
1.38 albertel 15110:
1.41 ng 15111: =over 4
15112:
1.648 raeburn 15113: =item * &upfile_store($r)
1.41 ng 15114:
15115: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 15116: needs $env{'form.upfile'}
1.41 ng 15117: returns $datatoken to be put into hidden field
15118:
15119: =cut
1.31 albertel 15120:
15121: sub upfile_store {
15122: my $r=shift;
1.258 albertel 15123: $env{'form.upfile'}=~s/\r/\n/gs;
15124: $env{'form.upfile'}=~s/\f/\n/gs;
15125: $env{'form.upfile'}=~s/\n+/\n/gs;
15126: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 15127:
1.1299 raeburn 15128: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
15129: '_enroll_'.$env{'request.course.id'}.'_'.
15130: time.'_'.$$);
15131: return if ($datatoken eq '');
15132:
1.31 albertel 15133: {
1.158 raeburn 15134: my $datafile = $r->dir_config('lonDaemons').
15135: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15136: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 15137: print $fh $env{'form.upfile'};
1.158 raeburn 15138: close($fh);
15139: }
1.31 albertel 15140: }
15141: return $datatoken;
15142: }
15143:
1.56 matthew 15144: =pod
15145:
1.1290 raeburn 15146: =item * &load_tmp_file($r,$datatoken)
1.41 ng 15147:
15148: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 15149: $datatoken is the name to assign to the temporary file.
1.258 albertel 15150: sets $env{'form.upfile'} to the contents of the file
1.41 ng 15151:
15152: =cut
1.31 albertel 15153:
15154: sub load_tmp_file {
1.1290 raeburn 15155: my ($r,$datatoken) = @_;
15156: return if ($datatoken eq '');
1.31 albertel 15157: my @studentdata=();
15158: {
1.158 raeburn 15159: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 15160: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15161: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 15162: @studentdata=<$fh>;
15163: close($fh);
15164: }
1.31 albertel 15165: }
1.258 albertel 15166: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 15167: }
15168:
1.1290 raeburn 15169: sub valid_datatoken {
15170: my ($datatoken) = @_;
1.1325 raeburn 15171: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 15172: return $datatoken;
15173: }
15174: return;
15175: }
15176:
1.56 matthew 15177: =pod
15178:
1.648 raeburn 15179: =item * &upfile_record_sep()
1.41 ng 15180:
15181: Separate uploaded file into records
15182: returns array of records,
1.258 albertel 15183: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 15184:
15185: =cut
1.31 albertel 15186:
15187: sub upfile_record_sep {
1.258 albertel 15188: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 15189: } else {
1.248 albertel 15190: my @records;
1.258 albertel 15191: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 15192: if ($line=~/^\s*$/) { next; }
15193: push(@records,$line);
15194: }
15195: return @records;
1.31 albertel 15196: }
15197: }
15198:
1.56 matthew 15199: =pod
15200:
1.648 raeburn 15201: =item * &record_sep($record)
1.41 ng 15202:
1.258 albertel 15203: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 15204:
15205: =cut
15206:
1.263 www 15207: sub takeleft {
15208: my $index=shift;
15209: return substr('0000'.$index,-4,4);
15210: }
15211:
1.31 albertel 15212: sub record_sep {
15213: my $record=shift;
15214: my %components=();
1.258 albertel 15215: if ($env{'form.upfiletype'} eq 'xml') {
15216: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 15217: my $i=0;
1.356 albertel 15218: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 15219: $field=~s/^(\"|\')//;
15220: $field=~s/(\"|\')$//;
1.263 www 15221: $components{&takeleft($i)}=$field;
1.31 albertel 15222: $i++;
15223: }
1.258 albertel 15224: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 15225: my $i=0;
1.356 albertel 15226: foreach my $field (split(/\t/,$record)) {
1.31 albertel 15227: $field=~s/^(\"|\')//;
15228: $field=~s/(\"|\')$//;
1.263 www 15229: $components{&takeleft($i)}=$field;
1.31 albertel 15230: $i++;
15231: }
15232: } else {
1.561 www 15233: my $separator=',';
1.480 banghart 15234: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 15235: $separator=';';
1.480 banghart 15236: }
1.31 albertel 15237: my $i=0;
1.561 www 15238: # the character we are looking for to indicate the end of a quote or a record
15239: my $looking_for=$separator;
15240: # do not add the characters to the fields
15241: my $ignore=0;
15242: # we just encountered a separator (or the beginning of the record)
15243: my $just_found_separator=1;
15244: # store the field we are working on here
15245: my $field='';
15246: # work our way through all characters in record
15247: foreach my $character ($record=~/(.)/g) {
15248: if ($character eq $looking_for) {
15249: if ($character ne $separator) {
15250: # Found the end of a quote, again looking for separator
15251: $looking_for=$separator;
15252: $ignore=1;
15253: } else {
15254: # Found a separator, store away what we got
15255: $components{&takeleft($i)}=$field;
15256: $i++;
15257: $just_found_separator=1;
15258: $ignore=0;
15259: $field='';
15260: }
15261: next;
15262: }
15263: # single or double quotation marks after a separator indicate beginning of a quote
15264: # we are now looking for the end of the quote and need to ignore separators
15265: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15266: $looking_for=$character;
15267: next;
15268: }
15269: # ignore would be true after we reached the end of a quote
15270: if ($ignore) { next; }
15271: if (($just_found_separator) && ($character=~/\s/)) { next; }
15272: $field.=$character;
15273: $just_found_separator=0;
1.31 albertel 15274: }
1.561 www 15275: # catch the very last entry, since we never encountered the separator
15276: $components{&takeleft($i)}=$field;
1.31 albertel 15277: }
15278: return %components;
15279: }
15280:
1.144 matthew 15281: ######################################################
15282: ######################################################
15283:
1.56 matthew 15284: =pod
15285:
1.648 raeburn 15286: =item * &upfile_select_html()
1.41 ng 15287:
1.144 matthew 15288: Return HTML code to select a file from the users machine and specify
15289: the file type.
1.41 ng 15290:
15291: =cut
15292:
1.144 matthew 15293: ######################################################
15294: ######################################################
1.31 albertel 15295: sub upfile_select_html {
1.144 matthew 15296: my %Types = (
15297: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15298: semisv => &mt('Semicolon separated values'),
1.144 matthew 15299: space => &mt('Space separated'),
15300: tab => &mt('Tabulator separated'),
15301: # xml => &mt('HTML/XML'),
15302: );
15303: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15304: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15305: foreach my $type (sort(keys(%Types))) {
15306: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15307: }
15308: $Str .= "</select>\n";
15309: return $Str;
1.31 albertel 15310: }
15311:
1.301 albertel 15312: sub get_samples {
15313: my ($records,$toget) = @_;
15314: my @samples=({});
15315: my $got=0;
15316: foreach my $rec (@$records) {
15317: my %temp = &record_sep($rec);
15318: if (! grep(/\S/, values(%temp))) { next; }
15319: if (%temp) {
15320: $samples[$got]=\%temp;
15321: $got++;
15322: if ($got == $toget) { last; }
15323: }
15324: }
15325: return \@samples;
15326: }
15327:
1.144 matthew 15328: ######################################################
15329: ######################################################
15330:
1.56 matthew 15331: =pod
15332:
1.648 raeburn 15333: =item * &csv_print_samples($r,$records)
1.41 ng 15334:
15335: Prints a table of sample values from each column uploaded $r is an
15336: Apache Request ref, $records is an arrayref from
15337: &Apache::loncommon::upfile_record_sep
15338:
15339: =cut
15340:
1.144 matthew 15341: ######################################################
15342: ######################################################
1.31 albertel 15343: sub csv_print_samples {
15344: my ($r,$records) = @_;
1.662 bisitz 15345: my $samples = &get_samples($records,5);
1.301 albertel 15346:
1.594 raeburn 15347: $r->print(&mt('Samples').'<br />'.&start_data_table().
15348: &start_data_table_header_row());
1.356 albertel 15349: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15350: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15351: $r->print(&end_data_table_header_row());
1.301 albertel 15352: foreach my $hash (@$samples) {
1.594 raeburn 15353: $r->print(&start_data_table_row());
1.356 albertel 15354: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15355: $r->print('<td>');
1.356 albertel 15356: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15357: $r->print('</td>');
15358: }
1.594 raeburn 15359: $r->print(&end_data_table_row());
1.31 albertel 15360: }
1.594 raeburn 15361: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15362: }
15363:
1.144 matthew 15364: ######################################################
15365: ######################################################
15366:
1.56 matthew 15367: =pod
15368:
1.648 raeburn 15369: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15370:
15371: Prints a table to create associations between values and table columns.
1.144 matthew 15372:
1.41 ng 15373: $r is an Apache Request ref,
15374: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15375: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15376:
15377: =cut
15378:
1.144 matthew 15379: ######################################################
15380: ######################################################
1.31 albertel 15381: sub csv_print_select_table {
15382: my ($r,$records,$d) = @_;
1.301 albertel 15383: my $i=0;
15384: my $samples = &get_samples($records,1);
1.144 matthew 15385: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15386: &start_data_table().&start_data_table_header_row().
1.144 matthew 15387: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15388: '<th>'.&mt('Column').'</th>'.
15389: &end_data_table_header_row()."\n");
1.356 albertel 15390: foreach my $array_ref (@$d) {
15391: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15392: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15393:
1.875 bisitz 15394: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15395: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15396: $r->print('<option value="none"></option>');
1.356 albertel 15397: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15398: $r->print('<option value="'.$sample.'"'.
15399: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15400: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15401: }
1.594 raeburn 15402: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15403: $i++;
15404: }
1.594 raeburn 15405: $r->print(&end_data_table());
1.31 albertel 15406: $i--;
15407: return $i;
15408: }
1.56 matthew 15409:
1.144 matthew 15410: ######################################################
15411: ######################################################
15412:
1.56 matthew 15413: =pod
1.31 albertel 15414:
1.648 raeburn 15415: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15416:
15417: Prints a table of sample values from the upload and can make associate samples to internal names.
15418:
15419: $r is an Apache Request ref,
15420: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15421: $d is an array of 2 element arrays (internal name, displayed name)
15422:
15423: =cut
15424:
1.144 matthew 15425: ######################################################
15426: ######################################################
1.31 albertel 15427: sub csv_samples_select_table {
15428: my ($r,$records,$d) = @_;
15429: my $i=0;
1.144 matthew 15430: #
1.662 bisitz 15431: my $max_samples = 5;
15432: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15433: $r->print(&start_data_table().
15434: &start_data_table_header_row().'<th>'.
15435: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15436: &end_data_table_header_row());
1.301 albertel 15437:
15438: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15439: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15440: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15441: foreach my $option (@$d) {
15442: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15443: $r->print('<option value="'.$value.'"'.
1.253 albertel 15444: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15445: $display.'</option>');
1.31 albertel 15446: }
15447: $r->print('</select></td><td>');
1.662 bisitz 15448: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15449: if (defined($samples->[$line]{$key})) {
15450: $r->print($samples->[$line]{$key}."<br />\n");
15451: }
15452: }
1.594 raeburn 15453: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15454: $i++;
15455: }
1.594 raeburn 15456: $r->print(&end_data_table());
1.31 albertel 15457: $i--;
15458: return($i);
1.115 matthew 15459: }
15460:
1.144 matthew 15461: ######################################################
15462: ######################################################
15463:
1.115 matthew 15464: =pod
15465:
1.648 raeburn 15466: =item * &clean_excel_name($name)
1.115 matthew 15467:
15468: Returns a replacement for $name which does not contain any illegal characters.
15469:
15470: =cut
15471:
1.144 matthew 15472: ######################################################
15473: ######################################################
1.115 matthew 15474: sub clean_excel_name {
15475: my ($name) = @_;
15476: $name =~ s/[:\*\?\/\\]//g;
15477: if (length($name) > 31) {
15478: $name = substr($name,0,31);
15479: }
15480: return $name;
1.25 albertel 15481: }
1.84 albertel 15482:
1.85 albertel 15483: =pod
15484:
1.648 raeburn 15485: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15486:
15487: Returns either 1 or undef
15488:
15489: 1 if the part is to be hidden, undef if it is to be shown
15490:
15491: Arguments are:
15492:
15493: $id the id of the part to be checked
15494: $symb, optional the symb of the resource to check
15495: $udom, optional the domain of the user to check for
15496: $uname, optional the username of the user to check for
15497:
15498: =cut
1.84 albertel 15499:
15500: sub check_if_partid_hidden {
15501: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15502: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15503: $symb,$udom,$uname);
1.141 albertel 15504: my $truth=1;
15505: #if the string starts with !, then the list is the list to show not hide
15506: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15507: my @hiddenlist=split(/,/,$hiddenparts);
15508: foreach my $checkid (@hiddenlist) {
1.141 albertel 15509: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15510: }
1.141 albertel 15511: return !$truth;
1.84 albertel 15512: }
1.127 matthew 15513:
1.138 matthew 15514:
15515: ############################################################
15516: ############################################################
15517:
15518: =pod
15519:
1.157 matthew 15520: =back
15521:
1.138 matthew 15522: =head1 cgi-bin script and graphing routines
15523:
1.157 matthew 15524: =over 4
15525:
1.648 raeburn 15526: =item * &get_cgi_id()
1.138 matthew 15527:
15528: Inputs: none
15529:
15530: Returns an id which can be used to pass environment variables
15531: to various cgi-bin scripts. These environment variables will
15532: be removed from the users environment after a given time by
15533: the routine &Apache::lonnet::transfer_profile_to_env.
15534:
15535: =cut
15536:
15537: ############################################################
15538: ############################################################
1.152 albertel 15539: my $uniq=0;
1.136 matthew 15540: sub get_cgi_id {
1.154 albertel 15541: $uniq=($uniq+1)%100000;
1.280 albertel 15542: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15543: }
15544:
1.127 matthew 15545: ############################################################
15546: ############################################################
15547:
15548: =pod
15549:
1.648 raeburn 15550: =item * &DrawBarGraph()
1.127 matthew 15551:
1.138 matthew 15552: Facilitates the plotting of data in a (stacked) bar graph.
15553: Puts plot definition data into the users environment in order for
15554: graph.png to plot it. Returns an <img> tag for the plot.
15555: The bars on the plot are labeled '1','2',...,'n'.
15556:
15557: Inputs:
15558:
15559: =over 4
15560:
15561: =item $Title: string, the title of the plot
15562:
15563: =item $xlabel: string, text describing the X-axis of the plot
15564:
15565: =item $ylabel: string, text describing the Y-axis of the plot
15566:
15567: =item $Max: scalar, the maximum Y value to use in the plot
15568: If $Max is < any data point, the graph will not be rendered.
15569:
1.140 matthew 15570: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15571: they are plotted. If undefined, default values will be used.
15572:
1.178 matthew 15573: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15574:
1.138 matthew 15575: =item @Values: An array of array references. Each array reference holds data
15576: to be plotted in a stacked bar chart.
15577:
1.239 matthew 15578: =item If the final element of @Values is a hash reference the key/value
15579: pairs will be added to the graph definition.
15580:
1.138 matthew 15581: =back
15582:
15583: Returns:
15584:
15585: An <img> tag which references graph.png and the appropriate identifying
15586: information for the plot.
15587:
1.127 matthew 15588: =cut
15589:
15590: ############################################################
15591: ############################################################
1.134 matthew 15592: sub DrawBarGraph {
1.178 matthew 15593: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15594: #
15595: if (! defined($colors)) {
15596: $colors = ['#33ff00',
15597: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15598: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15599: ];
15600: }
1.228 matthew 15601: my $extra_settings = {};
15602: if (ref($Values[-1]) eq 'HASH') {
15603: $extra_settings = pop(@Values);
15604: }
1.127 matthew 15605: #
1.136 matthew 15606: my $identifier = &get_cgi_id();
15607: my $id = 'cgi.'.$identifier;
1.129 matthew 15608: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15609: return '';
15610: }
1.225 matthew 15611: #
15612: my @Labels;
15613: if (defined($labels)) {
15614: @Labels = @$labels;
15615: } else {
15616: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15617: push(@Labels,$i+1);
1.225 matthew 15618: }
15619: }
15620: #
1.129 matthew 15621: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15622: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15623: my %ValuesHash;
15624: my $NumSets=1;
15625: foreach my $array (@Values) {
15626: next if (! ref($array));
1.136 matthew 15627: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15628: join(',',@$array);
1.129 matthew 15629: }
1.127 matthew 15630: #
1.136 matthew 15631: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15632: if ($NumBars < 3) {
15633: $width = 120+$NumBars*32;
1.220 matthew 15634: $xskip = 1;
1.225 matthew 15635: $bar_width = 30;
15636: } elsif ($NumBars < 5) {
15637: $width = 120+$NumBars*20;
15638: $xskip = 1;
15639: $bar_width = 20;
1.220 matthew 15640: } elsif ($NumBars < 10) {
1.136 matthew 15641: $width = 120+$NumBars*15;
15642: $xskip = 1;
15643: $bar_width = 15;
15644: } elsif ($NumBars <= 25) {
15645: $width = 120+$NumBars*11;
15646: $xskip = 5;
15647: $bar_width = 8;
15648: } elsif ($NumBars <= 50) {
15649: $width = 120+$NumBars*8;
15650: $xskip = 5;
15651: $bar_width = 4;
15652: } else {
15653: $width = 120+$NumBars*8;
15654: $xskip = 5;
15655: $bar_width = 4;
15656: }
15657: #
1.137 matthew 15658: $Max = 1 if ($Max < 1);
15659: if ( int($Max) < $Max ) {
15660: $Max++;
15661: $Max = int($Max);
15662: }
1.127 matthew 15663: $Title = '' if (! defined($Title));
15664: $xlabel = '' if (! defined($xlabel));
15665: $ylabel = '' if (! defined($ylabel));
1.369 www 15666: $ValuesHash{$id.'.title'} = &escape($Title);
15667: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15668: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15669: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15670: $ValuesHash{$id.'.NumBars'} = $NumBars;
15671: $ValuesHash{$id.'.NumSets'} = $NumSets;
15672: $ValuesHash{$id.'.PlotType'} = 'bar';
15673: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15674: $ValuesHash{$id.'.height'} = $height;
15675: $ValuesHash{$id.'.width'} = $width;
15676: $ValuesHash{$id.'.xskip'} = $xskip;
15677: $ValuesHash{$id.'.bar_width'} = $bar_width;
15678: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15679: #
1.228 matthew 15680: # Deal with other parameters
15681: while (my ($key,$value) = each(%$extra_settings)) {
15682: $ValuesHash{$id.'.'.$key} = $value;
15683: }
15684: #
1.646 raeburn 15685: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15686: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15687: }
15688:
15689: ############################################################
15690: ############################################################
15691:
15692: =pod
15693:
1.648 raeburn 15694: =item * &DrawXYGraph()
1.137 matthew 15695:
1.138 matthew 15696: Facilitates the plotting of data in an XY graph.
15697: Puts plot definition data into the users environment in order for
15698: graph.png to plot it. Returns an <img> tag for the plot.
15699:
15700: Inputs:
15701:
15702: =over 4
15703:
15704: =item $Title: string, the title of the plot
15705:
15706: =item $xlabel: string, text describing the X-axis of the plot
15707:
15708: =item $ylabel: string, text describing the Y-axis of the plot
15709:
15710: =item $Max: scalar, the maximum Y value to use in the plot
15711: If $Max is < any data point, the graph will not be rendered.
15712:
15713: =item $colors: Array ref containing the hex color codes for the data to be
15714: plotted in. If undefined, default values will be used.
15715:
15716: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15717:
15718: =item $Ydata: Array ref containing Array refs.
1.185 www 15719: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15720:
15721: =item %Values: hash indicating or overriding any default values which are
15722: passed to graph.png.
15723: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15724:
15725: =back
15726:
15727: Returns:
15728:
15729: An <img> tag which references graph.png and the appropriate identifying
15730: information for the plot.
15731:
1.137 matthew 15732: =cut
15733:
15734: ############################################################
15735: ############################################################
15736: sub DrawXYGraph {
15737: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15738: #
15739: # Create the identifier for the graph
15740: my $identifier = &get_cgi_id();
15741: my $id = 'cgi.'.$identifier;
15742: #
15743: $Title = '' if (! defined($Title));
15744: $xlabel = '' if (! defined($xlabel));
15745: $ylabel = '' if (! defined($ylabel));
15746: my %ValuesHash =
15747: (
1.369 www 15748: $id.'.title' => &escape($Title),
15749: $id.'.xlabel' => &escape($xlabel),
15750: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15751: $id.'.y_max_value'=> $Max,
15752: $id.'.labels' => join(',',@$Xlabels),
15753: $id.'.PlotType' => 'XY',
15754: );
15755: #
15756: if (defined($colors) && ref($colors) eq 'ARRAY') {
15757: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15758: }
15759: #
15760: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15761: return '';
15762: }
15763: my $NumSets=1;
1.138 matthew 15764: foreach my $array (@{$Ydata}){
1.137 matthew 15765: next if (! ref($array));
15766: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15767: }
1.138 matthew 15768: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15769: #
15770: # Deal with other parameters
15771: while (my ($key,$value) = each(%Values)) {
15772: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15773: }
15774: #
1.646 raeburn 15775: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15776: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15777: }
15778:
15779: ############################################################
15780: ############################################################
15781:
15782: =pod
15783:
1.648 raeburn 15784: =item * &DrawXYYGraph()
1.138 matthew 15785:
15786: Facilitates the plotting of data in an XY graph with two Y axes.
15787: Puts plot definition data into the users environment in order for
15788: graph.png to plot it. Returns an <img> tag for the plot.
15789:
15790: Inputs:
15791:
15792: =over 4
15793:
15794: =item $Title: string, the title of the plot
15795:
15796: =item $xlabel: string, text describing the X-axis of the plot
15797:
15798: =item $ylabel: string, text describing the Y-axis of the plot
15799:
15800: =item $colors: Array ref containing the hex color codes for the data to be
15801: plotted in. If undefined, default values will be used.
15802:
15803: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15804:
15805: =item $Ydata1: The first data set
15806:
15807: =item $Min1: The minimum value of the left Y-axis
15808:
15809: =item $Max1: The maximum value of the left Y-axis
15810:
15811: =item $Ydata2: The second data set
15812:
15813: =item $Min2: The minimum value of the right Y-axis
15814:
15815: =item $Max2: The maximum value of the left Y-axis
15816:
15817: =item %Values: hash indicating or overriding any default values which are
15818: passed to graph.png.
15819: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15820:
15821: =back
15822:
15823: Returns:
15824:
15825: An <img> tag which references graph.png and the appropriate identifying
15826: information for the plot.
1.136 matthew 15827:
15828: =cut
15829:
15830: ############################################################
15831: ############################################################
1.137 matthew 15832: sub DrawXYYGraph {
15833: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15834: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15835: #
15836: # Create the identifier for the graph
15837: my $identifier = &get_cgi_id();
15838: my $id = 'cgi.'.$identifier;
15839: #
15840: $Title = '' if (! defined($Title));
15841: $xlabel = '' if (! defined($xlabel));
15842: $ylabel = '' if (! defined($ylabel));
15843: my %ValuesHash =
15844: (
1.369 www 15845: $id.'.title' => &escape($Title),
15846: $id.'.xlabel' => &escape($xlabel),
15847: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15848: $id.'.labels' => join(',',@$Xlabels),
15849: $id.'.PlotType' => 'XY',
15850: $id.'.NumSets' => 2,
1.137 matthew 15851: $id.'.two_axes' => 1,
15852: $id.'.y1_max_value' => $Max1,
15853: $id.'.y1_min_value' => $Min1,
15854: $id.'.y2_max_value' => $Max2,
15855: $id.'.y2_min_value' => $Min2,
1.136 matthew 15856: );
15857: #
1.137 matthew 15858: if (defined($colors) && ref($colors) eq 'ARRAY') {
15859: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15860: }
15861: #
15862: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15863: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15864: return '';
15865: }
15866: my $NumSets=1;
1.137 matthew 15867: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15868: next if (! ref($array));
15869: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15870: }
15871: #
15872: # Deal with other parameters
15873: while (my ($key,$value) = each(%Values)) {
15874: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15875: }
15876: #
1.646 raeburn 15877: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15878: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15879: }
15880:
15881: ############################################################
15882: ############################################################
15883:
15884: =pod
15885:
1.157 matthew 15886: =back
15887:
1.139 matthew 15888: =head1 Statistics helper routines?
15889:
15890: Bad place for them but what the hell.
15891:
1.157 matthew 15892: =over 4
15893:
1.648 raeburn 15894: =item * &chartlink()
1.139 matthew 15895:
15896: Returns a link to the chart for a specific student.
15897:
15898: Inputs:
15899:
15900: =over 4
15901:
15902: =item $linktext: The text of the link
15903:
15904: =item $sname: The students username
15905:
15906: =item $sdomain: The students domain
15907:
15908: =back
15909:
1.157 matthew 15910: =back
15911:
1.139 matthew 15912: =cut
15913:
15914: ############################################################
15915: ############################################################
15916: sub chartlink {
15917: my ($linktext, $sname, $sdomain) = @_;
15918: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15919: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15920: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15921: '">'.$linktext.'</a>';
1.153 matthew 15922: }
15923:
15924: #######################################################
15925: #######################################################
15926:
15927: =pod
15928:
15929: =head1 Course Environment Routines
1.157 matthew 15930:
15931: =over 4
1.153 matthew 15932:
1.648 raeburn 15933: =item * &restore_course_settings()
1.153 matthew 15934:
1.648 raeburn 15935: =item * &store_course_settings()
1.153 matthew 15936:
15937: Restores/Store indicated form parameters from the course environment.
15938: Will not overwrite existing values of the form parameters.
15939:
15940: Inputs:
15941: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15942:
15943: a hash ref describing the data to be stored. For example:
15944:
15945: %Save_Parameters = ('Status' => 'scalar',
15946: 'chartoutputmode' => 'scalar',
15947: 'chartoutputdata' => 'scalar',
15948: 'Section' => 'array',
1.373 raeburn 15949: 'Group' => 'array',
1.153 matthew 15950: 'StudentData' => 'array',
15951: 'Maps' => 'array');
15952:
15953: Returns: both routines return nothing
15954:
1.631 raeburn 15955: =back
15956:
1.153 matthew 15957: =cut
15958:
15959: #######################################################
15960: #######################################################
15961: sub store_course_settings {
1.496 albertel 15962: return &store_settings($env{'request.course.id'},@_);
15963: }
15964:
15965: sub store_settings {
1.153 matthew 15966: # save to the environment
15967: # appenv the same items, just to be safe
1.300 albertel 15968: my $udom = $env{'user.domain'};
15969: my $uname = $env{'user.name'};
1.496 albertel 15970: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15971: my %SaveHash;
15972: my %AppHash;
15973: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15974: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15975: my $envname = 'environment.'.$basename;
1.258 albertel 15976: if (exists($env{'form.'.$setting})) {
1.153 matthew 15977: # Save this value away
15978: if ($type eq 'scalar' &&
1.258 albertel 15979: (! exists($env{$envname}) ||
15980: $env{$envname} ne $env{'form.'.$setting})) {
15981: $SaveHash{$basename} = $env{'form.'.$setting};
15982: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15983: } elsif ($type eq 'array') {
15984: my $stored_form;
1.258 albertel 15985: if (ref($env{'form.'.$setting})) {
1.153 matthew 15986: $stored_form = join(',',
15987: map {
1.369 www 15988: &escape($_);
1.258 albertel 15989: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15990: } else {
15991: $stored_form =
1.369 www 15992: &escape($env{'form.'.$setting});
1.153 matthew 15993: }
15994: # Determine if the array contents are the same.
1.258 albertel 15995: if ($stored_form ne $env{$envname}) {
1.153 matthew 15996: $SaveHash{$basename} = $stored_form;
15997: $AppHash{$envname} = $stored_form;
15998: }
15999: }
16000: }
16001: }
16002: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 16003: $udom,$uname);
1.153 matthew 16004: if ($put_result !~ /^(ok|delayed)/) {
16005: &Apache::lonnet::logthis('unable to save form parameters, '.
16006: 'got error:'.$put_result);
16007: }
16008: # Make sure these settings stick around in this session, too
1.646 raeburn 16009: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 16010: return;
16011: }
16012:
16013: sub restore_course_settings {
1.499 albertel 16014: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 16015: }
16016:
16017: sub restore_settings {
16018: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16019: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 16020: next if (exists($env{'form.'.$setting}));
1.496 albertel 16021: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 16022: '.'.$setting;
1.258 albertel 16023: if (exists($env{$envname})) {
1.153 matthew 16024: if ($type eq 'scalar') {
1.258 albertel 16025: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 16026: } elsif ($type eq 'array') {
1.258 albertel 16027: $env{'form.'.$setting} = [
1.153 matthew 16028: map {
1.369 www 16029: &unescape($_);
1.258 albertel 16030: } split(',',$env{$envname})
1.153 matthew 16031: ];
16032: }
16033: }
16034: }
1.127 matthew 16035: }
16036:
1.618 raeburn 16037: #######################################################
16038: #######################################################
16039:
16040: =pod
16041:
16042: =head1 Domain E-mail Routines
16043:
16044: =over 4
16045:
1.648 raeburn 16046: =item * &build_recipient_list()
1.618 raeburn 16047:
1.1144 raeburn 16048: Build recipient lists for following types of e-mail:
1.766 raeburn 16049: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 16050: (d) Help requests, (e) Course requests needing approval, (f) loncapa
16051: module change checking, student/employee ID conflict checks, as
16052: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
16053: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 16054:
16055: Inputs:
1.619 raeburn 16056: defmail (scalar - email address of default recipient),
1.1144 raeburn 16057: mailing type (scalar: errormail, packagesmail, helpdeskmail,
16058: requestsmail, updatesmail, or idconflictsmail).
16059:
1.619 raeburn 16060: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 16061:
1.619 raeburn 16062: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 16063: i.e., predates configuration by DC via domainprefs.pm
16064:
16065: $requname username of requester (if mailing type is helpdeskmail)
16066:
16067: $requdom domain of requester (if mailing type is helpdeskmail)
16068:
16069: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
16070:
1.618 raeburn 16071:
1.655 raeburn 16072: Returns: comma separated list of addresses to which to send e-mail.
16073:
16074: =back
1.618 raeburn 16075:
16076: =cut
16077:
16078: ############################################################
16079: ############################################################
16080: sub build_recipient_list {
1.1297 raeburn 16081: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 16082: my @recipients;
1.1270 raeburn 16083: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 16084: my %domconfig =
1.1270 raeburn 16085: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 16086: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 16087: if (exists($domconfig{'contacts'}{$mailing})) {
16088: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
16089: my @contacts = ('adminemail','supportemail');
16090: foreach my $item (@contacts) {
16091: if ($domconfig{'contacts'}{$mailing}{$item}) {
16092: my $addr = $domconfig{'contacts'}{$item};
16093: if (!grep(/^\Q$addr\E$/,@recipients)) {
16094: push(@recipients,$addr);
16095: }
1.619 raeburn 16096: }
1.1270 raeburn 16097: }
16098: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
16099: if ($mailing eq 'helpdeskmail') {
16100: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
16101: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
16102: my @ok_bccs;
16103: foreach my $bcc (@bccs) {
16104: $bcc =~ s/^\s+//g;
16105: $bcc =~ s/\s+$//g;
16106: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16107: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16108: push(@ok_bccs,$bcc);
16109: }
16110: }
16111: }
16112: if (@ok_bccs > 0) {
16113: $allbcc = join(', ',@ok_bccs);
16114: }
16115: }
16116: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 16117: }
16118: }
1.766 raeburn 16119: } elsif ($origmail ne '') {
1.1270 raeburn 16120: $lastresort = $origmail;
1.618 raeburn 16121: }
1.1297 raeburn 16122: if ($mailing eq 'helpdeskmail') {
16123: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
16124: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
16125: my ($inststatus,$inststatus_checked);
16126: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
16127: ($env{'user.domain'} ne 'public')) {
16128: $inststatus_checked = 1;
16129: $inststatus = $env{'environment.inststatus'};
16130: }
16131: unless ($inststatus_checked) {
16132: if (($requname ne '') && ($requdom ne '')) {
16133: if (($requname =~ /^$match_username$/) &&
16134: ($requdom =~ /^$match_domain$/) &&
16135: (&Apache::lonnet::domain($requdom))) {
16136: my $requhome = &Apache::lonnet::homeserver($requname,
16137: $requdom);
16138: unless ($requhome eq 'no_host') {
16139: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
16140: $inststatus = $userenv{'inststatus'};
16141: $inststatus_checked = 1;
16142: }
16143: }
16144: }
16145: }
16146: unless ($inststatus_checked) {
16147: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
16148: my %srch = (srchby => 'email',
16149: srchdomain => $defdom,
16150: srchterm => $reqemail,
16151: srchtype => 'exact');
16152: my %srch_results = &Apache::lonnet::usersearch(\%srch);
16153: foreach my $uname (keys(%srch_results)) {
16154: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16155: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16156: $inststatus_checked = 1;
16157: last;
16158: }
16159: }
16160: unless ($inststatus_checked) {
16161: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
16162: if ($dirsrchres eq 'ok') {
16163: foreach my $uname (keys(%srch_results)) {
16164: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16165: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16166: $inststatus_checked = 1;
16167: last;
16168: }
16169: }
16170: }
16171: }
16172: }
16173: }
16174: if ($inststatus ne '') {
16175: foreach my $status (split(/\:/,$inststatus)) {
16176: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
16177: my @contacts = ('adminemail','supportemail');
16178: foreach my $item (@contacts) {
16179: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
16180: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
16181: if (!grep(/^\Q$addr\E$/,@recipients)) {
16182: push(@recipients,$addr);
16183: }
16184: }
16185: }
16186: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
16187: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
16188: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
16189: my @ok_bccs;
16190: foreach my $bcc (@bccs) {
16191: $bcc =~ s/^\s+//g;
16192: $bcc =~ s/\s+$//g;
16193: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16194: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16195: push(@ok_bccs,$bcc);
16196: }
16197: }
16198: }
16199: if (@ok_bccs > 0) {
16200: $allbcc = join(', ',@ok_bccs);
16201: }
16202: }
16203: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
16204: last;
16205: }
16206: }
16207: }
16208: }
16209: }
1.619 raeburn 16210: } elsif ($origmail ne '') {
1.1270 raeburn 16211: $lastresort = $origmail;
16212: }
1.1297 raeburn 16213: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 16214: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
16215: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
16216: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
16217: my %what = (
16218: perlvar => 1,
16219: );
16220: my $primary = &Apache::lonnet::domain($defdom,'primary');
16221: if ($primary) {
16222: my $gotaddr;
16223: my ($result,$returnhash) =
16224: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
16225: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
16226: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
16227: $lastresort = $returnhash->{'lonSupportEMail'};
16228: $gotaddr = 1;
16229: }
16230: }
16231: unless ($gotaddr) {
16232: my $uintdom = &Apache::lonnet::internet_dom($primary);
16233: my $intdom = &Apache::lonnet::internet_dom($lonhost);
16234: unless ($uintdom eq $intdom) {
16235: my %domconfig =
16236: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
16237: if (ref($domconfig{'contacts'}) eq 'HASH') {
16238: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
16239: my @contacts = ('adminemail','supportemail');
16240: foreach my $item (@contacts) {
16241: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
16242: my $addr = $domconfig{'contacts'}{$item};
16243: if (!grep(/^\Q$addr\E$/,@recipients)) {
16244: push(@recipients,$addr);
16245: }
16246: }
16247: }
16248: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16249: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16250: }
16251: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16252: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16253: my @ok_bccs;
16254: foreach my $bcc (@bccs) {
16255: $bcc =~ s/^\s+//g;
16256: $bcc =~ s/\s+$//g;
16257: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16258: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16259: push(@ok_bccs,$bcc);
16260: }
16261: }
16262: }
16263: if (@ok_bccs > 0) {
16264: $allbcc = join(', ',@ok_bccs);
16265: }
16266: }
16267: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16268: }
16269: }
16270: }
16271: }
16272: }
16273: }
1.618 raeburn 16274: }
1.688 raeburn 16275: if (defined($defmail)) {
16276: if ($defmail ne '') {
16277: push(@recipients,$defmail);
16278: }
1.618 raeburn 16279: }
16280: if ($otheremails) {
1.619 raeburn 16281: my @others;
16282: if ($otheremails =~ /,/) {
16283: @others = split(/,/,$otheremails);
1.618 raeburn 16284: } else {
1.619 raeburn 16285: push(@others,$otheremails);
16286: }
16287: foreach my $addr (@others) {
16288: if (!grep(/^\Q$addr\E$/,@recipients)) {
16289: push(@recipients,$addr);
16290: }
1.618 raeburn 16291: }
16292: }
1.1298 raeburn 16293: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16294: if ((!@recipients) && ($lastresort ne '')) {
16295: push(@recipients,$lastresort);
16296: }
16297: } elsif ($lastresort ne '') {
16298: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16299: push(@recipients,$lastresort);
16300: }
16301: }
1.1271 raeburn 16302: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16303: if (wantarray) {
16304: return ($recipientlist,$allbcc,$addtext);
16305: } else {
16306: return $recipientlist;
16307: }
1.618 raeburn 16308: }
16309:
1.127 matthew 16310: ############################################################
16311: ############################################################
1.154 albertel 16312:
1.655 raeburn 16313: =pod
16314:
1.1224 musolffc 16315: =over 4
16316:
1.1223 musolffc 16317: =item * &mime_email()
16318:
16319: Sends an email with a possible attachment
16320:
16321: Inputs:
16322:
16323: =over 4
16324:
16325: from - Sender's email address
16326:
1.1343 raeburn 16327: replyto - Reply-To email address
16328:
1.1223 musolffc 16329: to - Email address of recipient
16330:
16331: subject - Subject of email
16332:
16333: body - Body of email
16334:
16335: cc_string - Carbon copy email address
16336:
16337: bcc - Blind carbon copy email address
16338:
16339: attachment_path - Path of file to be attached
16340:
16341: file_name - Name of file to be attached
16342:
16343: attachment_text - The body of an attachment of type "TEXT"
16344:
16345: =back
16346:
16347: =back
16348:
16349: =cut
16350:
16351: ############################################################
16352: ############################################################
16353:
16354: sub mime_email {
1.1343 raeburn 16355: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16356: $file_name,$attachment_text) = @_;
16357:
1.1223 musolffc 16358: my $msg = MIME::Lite->new(
16359: From => $from,
16360: To => $to,
16361: Subject => $subject,
16362: Type =>'TEXT',
16363: Data => $body,
16364: );
1.1343 raeburn 16365: if ($replyto ne '') {
16366: $msg->add("Reply-To" => $replyto);
16367: }
1.1223 musolffc 16368: if ($cc_string ne '') {
16369: $msg->add("Cc" => $cc_string);
16370: }
16371: if ($bcc ne '') {
16372: $msg->add("Bcc" => $bcc);
16373: }
16374: $msg->attr("content-type" => "text/plain");
16375: $msg->attr("content-type.charset" => "UTF-8");
16376: # Attach file if given
16377: if ($attachment_path) {
16378: unless ($file_name) {
16379: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16380: }
16381: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16382: $msg->attach(Type => $type,
16383: Path => $attachment_path,
16384: Filename => $file_name
16385: );
16386: # Otherwise attach text if given
16387: } elsif ($attachment_text) {
16388: $msg->attach(Type => 'TEXT',
16389: Data => $attachment_text);
16390: }
16391: # Send it
16392: $msg->send('sendmail');
16393: }
16394:
16395: ############################################################
16396: ############################################################
16397:
16398: =pod
16399:
1.655 raeburn 16400: =head1 Course Catalog Routines
16401:
16402: =over 4
16403:
16404: =item * &gather_categories()
16405:
16406: Converts category definitions - keys of categories hash stored in
16407: coursecategories in configuration.db on the primary library server in a
16408: domain - to an array. Also generates javascript and idx hash used to
16409: generate Domain Coordinator interface for editing Course Categories.
16410:
16411: Inputs:
1.663 raeburn 16412:
1.655 raeburn 16413: categories (reference to hash of category definitions).
1.663 raeburn 16414:
1.655 raeburn 16415: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16416: categories and subcategories).
1.663 raeburn 16417:
1.655 raeburn 16418: idx (reference to hash of counters used in Domain Coordinator interface for
16419: editing Course Categories).
1.663 raeburn 16420:
1.655 raeburn 16421: jsarray (reference to array of categories used to create Javascript arrays for
16422: Domain Coordinator interface for editing Course Categories).
16423:
16424: Returns: nothing
16425:
16426: Side effects: populates cats, idx and jsarray.
16427:
16428: =cut
16429:
16430: sub gather_categories {
16431: my ($categories,$cats,$idx,$jsarray) = @_;
16432: my %counters;
16433: my $num = 0;
16434: foreach my $item (keys(%{$categories})) {
16435: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16436: if ($container eq '' && $depth == 0) {
16437: $cats->[$depth][$categories->{$item}] = $cat;
16438: } else {
16439: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16440: }
16441: my ($escitem,$tail) = split(/:/,$item,2);
16442: if ($counters{$tail} eq '') {
16443: $counters{$tail} = $num;
16444: $num ++;
16445: }
16446: if (ref($idx) eq 'HASH') {
16447: $idx->{$item} = $counters{$tail};
16448: }
16449: if (ref($jsarray) eq 'ARRAY') {
16450: push(@{$jsarray->[$counters{$tail}]},$item);
16451: }
16452: }
16453: return;
16454: }
16455:
16456: =pod
16457:
16458: =item * &extract_categories()
16459:
16460: Used to generate breadcrumb trails for course categories.
16461:
16462: Inputs:
1.663 raeburn 16463:
1.655 raeburn 16464: categories (reference to hash of category definitions).
1.663 raeburn 16465:
1.655 raeburn 16466: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16467: categories and subcategories).
1.663 raeburn 16468:
1.655 raeburn 16469: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16470:
1.655 raeburn 16471: allitems (reference to hash - key is category key
16472: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16473:
1.655 raeburn 16474: idx (reference to hash of counters used in Domain Coordinator interface for
16475: editing Course Categories).
1.663 raeburn 16476:
1.655 raeburn 16477: jsarray (reference to array of categories used to create Javascript arrays for
16478: Domain Coordinator interface for editing Course Categories).
16479:
1.665 raeburn 16480: subcats (reference to hash of arrays containing all subcategories within each
16481: category, -recursive)
16482:
1.1321 raeburn 16483: maxd (reference to hash used to hold max depth for all top-level categories).
16484:
1.655 raeburn 16485: Returns: nothing
16486:
16487: Side effects: populates trails and allitems hash references.
16488:
16489: =cut
16490:
16491: sub extract_categories {
1.1321 raeburn 16492: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16493: if (ref($categories) eq 'HASH') {
16494: &gather_categories($categories,$cats,$idx,$jsarray);
16495: if (ref($cats->[0]) eq 'ARRAY') {
16496: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16497: my $name = $cats->[0][$i];
16498: my $item = &escape($name).'::0';
16499: my $trailstr;
16500: if ($name eq 'instcode') {
16501: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16502: } elsif ($name eq 'communities') {
16503: $trailstr = &mt('Communities');
1.1239 raeburn 16504: } elsif ($name eq 'placement') {
16505: $trailstr = &mt('Placement Tests');
1.655 raeburn 16506: } else {
16507: $trailstr = $name;
16508: }
16509: if ($allitems->{$item} eq '') {
16510: push(@{$trails},$trailstr);
16511: $allitems->{$item} = scalar(@{$trails})-1;
16512: }
16513: my @parents = ($name);
16514: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16515: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16516: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16517: if (ref($subcats) eq 'HASH') {
16518: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16519: }
1.1321 raeburn 16520: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16521: }
16522: } else {
16523: if (ref($subcats) eq 'HASH') {
16524: $subcats->{$item} = [];
1.655 raeburn 16525: }
1.1321 raeburn 16526: if (ref($maxd) eq 'HASH') {
16527: $maxd->{$name} = 1;
16528: }
1.655 raeburn 16529: }
16530: }
16531: }
16532: }
16533: return;
16534: }
16535:
16536: =pod
16537:
1.1162 raeburn 16538: =item * &recurse_categories()
1.655 raeburn 16539:
16540: Recursively used to generate breadcrumb trails for course categories.
16541:
16542: Inputs:
1.663 raeburn 16543:
1.655 raeburn 16544: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16545: categories and subcategories).
1.663 raeburn 16546:
1.655 raeburn 16547: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16548:
16549: category (current course category, for which breadcrumb trail is being generated).
16550:
16551: trails (reference to array of breadcrumb trails for each category).
16552:
1.655 raeburn 16553: allitems (reference to hash - key is category key
16554: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16555:
1.655 raeburn 16556: parents (array containing containers directories for current category,
16557: back to top level).
16558:
16559: Returns: nothing
16560:
16561: Side effects: populates trails and allitems hash references
16562:
16563: =cut
16564:
16565: sub recurse_categories {
1.1321 raeburn 16566: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16567: my $shallower = $depth - 1;
16568: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16569: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16570: my $name = $cats->[$depth]{$category}[$k];
16571: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16572: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16573: if ($allitems->{$item} eq '') {
16574: push(@{$trails},$trailstr);
16575: $allitems->{$item} = scalar(@{$trails})-1;
16576: }
16577: my $deeper = $depth+1;
16578: push(@{$parents},$category);
1.665 raeburn 16579: if (ref($subcats) eq 'HASH') {
16580: my $subcat = &escape($name).':'.$category.':'.$depth;
16581: for (my $j=@{$parents}; $j>=0; $j--) {
16582: my $higher;
16583: if ($j > 0) {
16584: $higher = &escape($parents->[$j]).':'.
16585: &escape($parents->[$j-1]).':'.$j;
16586: } else {
16587: $higher = &escape($parents->[$j]).'::'.$j;
16588: }
16589: push(@{$subcats->{$higher}},$subcat);
16590: }
16591: }
16592: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16593: $subcats,$maxd);
1.655 raeburn 16594: pop(@{$parents});
16595: }
16596: } else {
16597: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16598: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16599: if ($allitems->{$item} eq '') {
16600: push(@{$trails},$trailstr);
16601: $allitems->{$item} = scalar(@{$trails})-1;
16602: }
1.1321 raeburn 16603: if (ref($maxd) eq 'HASH') {
16604: if ($depth > $maxd->{$parents->[0]}) {
16605: $maxd->{$parents->[0]} = $depth;
16606: }
16607: }
1.655 raeburn 16608: }
16609: return;
16610: }
16611:
1.663 raeburn 16612: =pod
16613:
1.1162 raeburn 16614: =item * &assign_categories_table()
1.663 raeburn 16615:
16616: Create a datatable for display of hierarchical categories in a domain,
16617: with checkboxes to allow a course to be categorized.
16618:
16619: Inputs:
16620:
16621: cathash - reference to hash of categories defined for the domain (from
16622: configuration.db)
16623:
16624: currcat - scalar with an & separated list of categories assigned to a course.
16625:
1.919 raeburn 16626: type - scalar contains course type (Course or Community).
16627:
1.1260 raeburn 16628: disabled - scalar (optional) contains disabled="disabled" if input elements are
16629: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16630:
1.663 raeburn 16631: Returns: $output (markup to be displayed)
16632:
16633: =cut
16634:
16635: sub assign_categories_table {
1.1259 raeburn 16636: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16637: my $output;
16638: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16639: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16640: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16641: $maxdepth = scalar(@cats);
16642: if (@cats > 0) {
16643: my $itemcount = 0;
16644: if (ref($cats[0]) eq 'ARRAY') {
16645: my @currcategories;
16646: if ($currcat ne '') {
16647: @currcategories = split('&',$currcat);
16648: }
1.919 raeburn 16649: my $table;
1.663 raeburn 16650: for (my $i=0; $i<@{$cats[0]}; $i++) {
16651: my $parent = $cats[0][$i];
1.919 raeburn 16652: next if ($parent eq 'instcode');
16653: if ($type eq 'Community') {
16654: next unless ($parent eq 'communities');
1.1239 raeburn 16655: } elsif ($type eq 'Placement') {
16656: next unless ($parent eq 'placement');
1.919 raeburn 16657: } else {
1.1239 raeburn 16658: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16659: }
1.663 raeburn 16660: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16661: my $item = &escape($parent).'::0';
16662: my $checked = '';
16663: if (@currcategories > 0) {
16664: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16665: $checked = ' checked="checked"';
1.663 raeburn 16666: }
16667: }
1.919 raeburn 16668: my $parent_title = $parent;
16669: if ($parent eq 'communities') {
16670: $parent_title = &mt('Communities');
1.1239 raeburn 16671: } elsif ($parent eq 'placement') {
16672: $parent_title = &mt('Placement Tests');
1.919 raeburn 16673: }
16674: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16675: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16676: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16677: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16678: my $depth = 1;
16679: push(@path,$parent);
1.1259 raeburn 16680: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16681: pop(@path);
1.919 raeburn 16682: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16683: $itemcount ++;
16684: }
1.919 raeburn 16685: if ($itemcount) {
16686: $output = &Apache::loncommon::start_data_table().
16687: $table.
16688: &Apache::loncommon::end_data_table();
16689: }
1.663 raeburn 16690: }
16691: }
16692: }
16693: return $output;
16694: }
16695:
16696: =pod
16697:
1.1162 raeburn 16698: =item * &assign_category_rows()
1.663 raeburn 16699:
16700: Create a datatable row for display of nested categories in a domain,
16701: with checkboxes to allow a course to be categorized,called recursively.
16702:
16703: Inputs:
16704:
16705: itemcount - track row number for alternating colors
16706:
16707: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16708: categories and subcategories.
16709:
16710: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16711:
16712: parent - parent of current category item
16713:
16714: path - Array containing all categories back up through the hierarchy from the
16715: current category to the top level.
16716:
16717: currcategories - reference to array of current categories assigned to the course
16718:
1.1260 raeburn 16719: disabled - scalar (optional) contains disabled="disabled" if input elements are
16720: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16721:
1.663 raeburn 16722: Returns: $output (markup to be displayed).
16723:
16724: =cut
16725:
16726: sub assign_category_rows {
1.1259 raeburn 16727: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16728: my ($text,$name,$item,$chgstr);
16729: if (ref($cats) eq 'ARRAY') {
16730: my $maxdepth = scalar(@{$cats});
16731: if (ref($cats->[$depth]) eq 'HASH') {
16732: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16733: my $numchildren = @{$cats->[$depth]{$parent}};
16734: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16735: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16736: for (my $j=0; $j<$numchildren; $j++) {
16737: $name = $cats->[$depth]{$parent}[$j];
16738: $item = &escape($name).':'.&escape($parent).':'.$depth;
16739: my $deeper = $depth+1;
16740: my $checked = '';
16741: if (ref($currcategories) eq 'ARRAY') {
16742: if (@{$currcategories} > 0) {
16743: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16744: $checked = ' checked="checked"';
1.663 raeburn 16745: }
16746: }
16747: }
1.664 raeburn 16748: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16749: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16750: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16751: '<input type="hidden" name="catname" value="'.$name.'" />'.
16752: '</td><td>';
1.663 raeburn 16753: if (ref($path) eq 'ARRAY') {
16754: push(@{$path},$name);
1.1259 raeburn 16755: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16756: pop(@{$path});
16757: }
16758: $text .= '</td></tr>';
16759: }
16760: $text .= '</table></td>';
16761: }
16762: }
16763: }
16764: return $text;
16765: }
16766:
1.1181 raeburn 16767: =pod
16768:
16769: =back
16770:
16771: =cut
16772:
1.655 raeburn 16773: ############################################################
16774: ############################################################
16775:
16776:
1.443 albertel 16777: sub commit_customrole {
1.1408 raeburn 16778: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
1.1399 raeburn 16779: my $result = &Apache::lonnet::assigncustomrole(
1.1408 raeburn 16780: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
16781: $context,$othdomby,$requester);
1.630 raeburn 16782: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16783: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 16784: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
16785: if (wantarray) {
16786: return ($output,$result);
16787: } else {
16788: return $output;
16789: }
1.443 albertel 16790: }
16791:
16792: sub commit_standardrole {
1.1408 raeburn 16793: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
16794: $othdomby,$requester) = @_;
1.1399 raeburn 16795: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 16796: if ($context eq 'auto') {
16797: $linefeed = "\n";
16798: } else {
16799: $linefeed = "<br />\n";
16800: }
1.443 albertel 16801: if ($three eq 'st') {
1.1399 raeburn 16802: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1408 raeburn 16803: $one,$two,$sec,$context,$credits,$othdomby,
16804: $requester);
1.541 raeburn 16805: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16806: ($result eq 'unknown_course') || ($result eq 'refused')) {
16807: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16808: } else {
1.541 raeburn 16809: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16810: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16811: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16812: if ($context eq 'auto') {
16813: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16814: } else {
16815: $output .= '<b>'.$result.'</b>'.$linefeed.
16816: &mt('Add to classlist').': <b>ok</b>';
16817: }
16818: $output .= $linefeed;
1.443 albertel 16819: }
16820: } else {
16821: $output = &mt('Assigning').' '.$three.' in '.$url.
16822: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16823: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1408 raeburn 16824: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
16825: '','',$context,$othdomby,$requester);
1.541 raeburn 16826: if ($context eq 'auto') {
16827: $output .= $result.$linefeed;
16828: } else {
16829: $output .= '<b>'.$result.'</b>'.$linefeed;
16830: }
1.443 albertel 16831: }
1.1399 raeburn 16832: if (wantarray) {
16833: return ($output,$result);
16834: } else {
16835: return $output;
16836: }
1.443 albertel 16837: }
16838:
16839: sub commit_studentrole {
1.1116 raeburn 16840: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
1.1408 raeburn 16841: $credits,$othdomby,$requester) = @_;
1.626 raeburn 16842: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16843: if ($context eq 'auto') {
16844: $linefeed = "\n";
16845: } else {
16846: $linefeed = '<br />'."\n";
16847: }
1.443 albertel 16848: if (defined($one) && defined($two)) {
16849: my $cid=$one.'_'.$two;
16850: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16851: my $secchange = 0;
16852: my $expire_role_result;
16853: my $modify_section_result;
1.628 raeburn 16854: if ($oldsec ne '-1') {
16855: if ($oldsec ne $sec) {
1.443 albertel 16856: $secchange = 1;
1.628 raeburn 16857: my $now = time;
1.443 albertel 16858: my $uurl='/'.$cid;
16859: $uurl=~s/\_/\//g;
16860: if ($oldsec) {
16861: $uurl.='/'.$oldsec;
16862: }
1.626 raeburn 16863: $oldsecurl = $uurl;
1.628 raeburn 16864: $expire_role_result =
1.1408 raeburn 16865: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
16866: '','','',$context,$othdomby,$requester);
16867: if ($env{'request.course.sec'} ne '') {
1.628 raeburn 16868: if ($expire_role_result eq 'refused') {
16869: my @roles = ('st');
16870: my @statuses = ('previous');
16871: my @roledoms = ($one);
16872: my $withsec = 1;
16873: my %roleshash =
16874: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16875: \@statuses,\@roles,\@roledoms,$withsec);
16876: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16877: my ($oldstart,$oldend) =
16878: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16879: if ($oldend > 0 && $oldend <= $now) {
16880: $expire_role_result = 'ok';
16881: }
16882: }
16883: }
16884: }
1.443 albertel 16885: $result = $expire_role_result;
16886: }
16887: }
16888: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16889: $modify_section_result =
16890: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16891: undef,undef,undef,$sec,
16892: $end,$start,'','',$cid,
1.1408 raeburn 16893: '',$context,$credits,'',
16894: $othdomby,$requester);
1.443 albertel 16895: if ($modify_section_result =~ /^ok/) {
16896: if ($secchange == 1) {
1.628 raeburn 16897: if ($sec eq '') {
16898: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16899: } else {
16900: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16901: }
1.443 albertel 16902: } elsif ($oldsec eq '-1') {
1.628 raeburn 16903: if ($sec eq '') {
16904: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16905: } else {
16906: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16907: }
1.443 albertel 16908: } else {
1.628 raeburn 16909: if ($sec eq '') {
16910: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16911: } else {
16912: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16913: }
1.443 albertel 16914: }
16915: } else {
1.1115 raeburn 16916: if ($secchange) {
1.628 raeburn 16917: $$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;
16918: } else {
16919: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16920: }
1.443 albertel 16921: }
16922: $result = $modify_section_result;
16923: } elsif ($secchange == 1) {
1.628 raeburn 16924: if ($oldsec eq '') {
1.1103 raeburn 16925: $$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 16926: } else {
16927: $$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;
16928: }
1.626 raeburn 16929: if ($expire_role_result eq 'refused') {
16930: my $newsecurl = '/'.$cid;
16931: $newsecurl =~ s/\_/\//g;
16932: if ($sec ne '') {
16933: $newsecurl.='/'.$sec;
16934: }
16935: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16936: if ($sec eq '') {
16937: $$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;
16938: } else {
16939: $$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;
16940: }
16941: }
16942: }
1.443 albertel 16943: }
16944: } else {
1.626 raeburn 16945: $$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 16946: $result = "error: incomplete course id\n";
16947: }
16948: return $result;
16949: }
16950:
1.1108 raeburn 16951: sub show_role_extent {
16952: my ($scope,$context,$role) = @_;
16953: $scope =~ s{^/}{};
16954: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16955: push(@courseroles,'co');
16956: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16957: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16958: $scope =~ s{/}{_};
16959: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16960: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16961: my ($audom,$auname) = split(/\//,$scope);
16962: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16963: &Apache::loncommon::plainname($auname,$audom).'</span>');
16964: } else {
16965: $scope =~ s{/$}{};
16966: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16967: &Apache::lonnet::domain($scope,'description').'</span>');
16968: }
16969: }
16970:
1.443 albertel 16971: ############################################################
16972: ############################################################
16973:
1.566 albertel 16974: sub check_clone {
1.578 raeburn 16975: my ($args,$linefeed) = @_;
1.566 albertel 16976: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16977: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16978: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16979: my $clonetitle;
16980: my @clonemsg;
1.566 albertel 16981: my $can_clone = 0;
1.944 raeburn 16982: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16983: if ($lctype ne 'community') {
16984: $lctype = 'course';
16985: }
1.566 albertel 16986: if ($clonehome eq 'no_host') {
1.944 raeburn 16987: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16988: push(@clonemsg,({
16989: mt => 'No new community created.',
16990: args => [],
16991: },
16992: {
16993: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16994: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16995: }));
1.908 raeburn 16996: } else {
1.1344 raeburn 16997: push(@clonemsg,({
16998: mt => 'No new course created.',
16999: args => [],
17000: },
17001: {
17002: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
17003: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17004: }));
17005: }
1.566 albertel 17006: } else {
17007: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 17008: $clonetitle = $clonedesc{'description'};
1.944 raeburn 17009: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 17010: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 17011: push(@clonemsg,({
17012: mt => 'No new community created.',
17013: args => [],
17014: },
17015: {
17016: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
17017: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17018: }));
17019: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 17020: }
17021: }
1.1262 raeburn 17022: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 17023: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 17024: $can_clone = 1;
17025: } else {
1.1221 raeburn 17026: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 17027: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 17028: if ($clonehash{'cloners'} eq '') {
17029: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
17030: if ($domdefs{'canclone'}) {
17031: unless ($domdefs{'canclone'} eq 'none') {
17032: if ($domdefs{'canclone'} eq 'domain') {
17033: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
17034: $can_clone = 1;
17035: }
17036: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17037: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
17038: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
17039: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
17040: $can_clone = 1;
17041: }
17042: }
17043: }
17044: }
1.578 raeburn 17045: } else {
1.1221 raeburn 17046: my @cloners = split(/,/,$clonehash{'cloners'});
17047: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 17048: $can_clone = 1;
1.1221 raeburn 17049: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 17050: $can_clone = 1;
1.1225 raeburn 17051: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
17052: $can_clone = 1;
1.1221 raeburn 17053: }
17054: unless ($can_clone) {
1.1225 raeburn 17055: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17056: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 17057: my (%gotdomdefaults,%gotcodedefaults);
17058: foreach my $cloner (@cloners) {
17059: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
17060: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
17061: my (%codedefaults,@code_order);
17062: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
17063: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
17064: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
17065: }
17066: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
17067: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
17068: }
17069: } else {
17070: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
17071: \%codedefaults,
17072: \@code_order);
17073: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
17074: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
17075: }
17076: if (@code_order > 0) {
17077: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
17078: $cloner,$clonehash{'internal.coursecode'},
17079: $args->{'crscode'})) {
17080: $can_clone = 1;
17081: last;
17082: }
17083: }
17084: }
17085: }
17086: }
1.1225 raeburn 17087: }
17088: }
17089: unless ($can_clone) {
17090: my $ccrole = 'cc';
17091: if ($args->{'crstype'} eq 'Community') {
17092: $ccrole = 'co';
17093: }
17094: my %roleshash =
17095: &Apache::lonnet::get_my_roles($args->{'ccuname'},
17096: $args->{'ccdomain'},
17097: 'userroles',['active'],[$ccrole],
17098: [$args->{'clonedomain'}]);
17099: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
17100: $can_clone = 1;
17101: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
17102: $args->{'ccuname'},$args->{'ccdomain'})) {
17103: $can_clone = 1;
1.1221 raeburn 17104: }
17105: }
17106: unless ($can_clone) {
17107: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17108: push(@clonemsg,({
17109: mt => 'No new community created.',
17110: args => [],
17111: },
17112: {
17113: 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]).',
17114: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17115: }));
1.942 raeburn 17116: } else {
1.1344 raeburn 17117: push(@clonemsg,({
17118: mt => 'No new course created.',
17119: args => [],
17120: },
17121: {
17122: 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]).',
17123: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17124: }));
1.1221 raeburn 17125: }
1.566 albertel 17126: }
1.578 raeburn 17127: }
1.566 albertel 17128: }
1.1344 raeburn 17129: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17130: }
17131:
1.444 albertel 17132: sub construct_course {
1.1262 raeburn 17133: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 17134: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
17135: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 17136: my $linefeed = '<br />'."\n";
17137: if ($context eq 'auto') {
17138: $linefeed = "\n";
17139: }
1.566 albertel 17140:
17141: #
17142: # Are we cloning?
17143: #
1.1344 raeburn 17144: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17145: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 17146: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 17147: if (!$can_clone) {
1.1344 raeburn 17148: return (0,$outcome,$clonemsgref);
1.566 albertel 17149: }
17150: }
17151:
1.444 albertel 17152: #
17153: # Open course
17154: #
1.1239 raeburn 17155: my $showncrstype;
17156: if ($args->{'crstype'} eq 'Placement') {
17157: $showncrstype = 'placement test';
17158: } else {
17159: $showncrstype = lc($args->{'crstype'});
17160: }
1.444 albertel 17161: my %cenv=();
17162: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
17163: $args->{'cdescr'},
17164: $args->{'curl'},
17165: $args->{'course_home'},
17166: $args->{'nonstandard'},
17167: $args->{'crscode'},
17168: $args->{'ccuname'}.':'.
17169: $args->{'ccdomain'},
1.882 raeburn 17170: $args->{'crstype'},
1.1344 raeburn 17171: $cnum,$context,$category,
17172: $callercontext);
1.444 albertel 17173:
17174: # Note: The testing routines depend on this being output; see
17175: # Utils::Course. This needs to at least be output as a comment
17176: # if anyone ever decides to not show this, and Utils::Course::new
17177: # will need to be suitably modified.
1.1344 raeburn 17178: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17179: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17180: } else {
17181: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17182: }
1.943 raeburn 17183: if ($$courseid =~ /^error:/) {
1.1344 raeburn 17184: return (0,$outcome,$clonemsgref);
1.943 raeburn 17185: }
17186:
1.444 albertel 17187: #
17188: # Check if created correctly
17189: #
1.479 albertel 17190: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 17191: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 17192: if ($crsuhome eq 'no_host') {
1.1344 raeburn 17193: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17194: $outcome .= &mt_user($user_lh,
17195: 'Course creation failed, unrecognized course home server.');
17196: } else {
17197: $outcome .= &mt('Course creation failed, unrecognized course home server.');
17198: }
17199: $outcome .= $linefeed;
17200: return (0,$outcome,$clonemsgref);
1.943 raeburn 17201: }
1.541 raeburn 17202: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 17203:
1.444 albertel 17204: #
1.566 albertel 17205: # Do the cloning
17206: #
1.1344 raeburn 17207: my @clonemsg;
1.566 albertel 17208: if ($can_clone && $cloneid) {
1.1344 raeburn 17209: push(@clonemsg,
17210: {
17211: mt => 'Created [_1] by cloning from [_2]',
17212: args => [$showncrstype,$clonetitle],
17213: });
1.566 albertel 17214: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 17215: # Copy all files
1.1344 raeburn 17216: my @info =
17217: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
17218: $args->{'dateshift'},$args->{'crscode'},
17219: $args->{'ccuname'}.':'.$args->{'ccdomain'},
17220: $args->{'tinyurls'});
17221: if (@info) {
17222: push(@clonemsg,@info);
17223: }
1.444 albertel 17224: # Restore URL
1.566 albertel 17225: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 17226: # Restore title
1.566 albertel 17227: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 17228: # Restore creation date, creator and creation context.
17229: $cenv{'internal.created'}=$oldcenv{'internal.created'};
17230: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
17231: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 17232: # Mark as cloned
1.566 albertel 17233: $cenv{'clonedfrom'}=$cloneid;
1.638 www 17234: # Need to clone grading mode
17235: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
17236: $cenv{'grading'}=$newenv{'grading'};
17237: # Do not clone these environment entries
17238: &Apache::lonnet::del('environment',
17239: ['default_enrollment_start_date',
17240: 'default_enrollment_end_date',
17241: 'question.email',
17242: 'policy.email',
17243: 'comment.email',
17244: 'pch.users.denied',
1.725 raeburn 17245: 'plc.users.denied',
17246: 'hidefromcat',
1.1121 raeburn 17247: 'checkforpriv',
1.1355 raeburn 17248: 'categories'],
1.638 www 17249: $$crsudom,$$crsunum);
1.1170 raeburn 17250: if ($args->{'textbook'}) {
17251: $cenv{'internal.textbook'} = $args->{'textbook'};
17252: }
1.444 albertel 17253: }
1.566 albertel 17254:
1.444 albertel 17255: #
17256: # Set environment (will override cloned, if existing)
17257: #
17258: my @sections = ();
17259: my @xlists = ();
17260: if ($args->{'crstype'}) {
17261: $cenv{'type'}=$args->{'crstype'};
17262: }
1.1371 raeburn 17263: if ($args->{'lti'}) {
17264: $cenv{'internal.lti'}=$args->{'lti'};
17265: }
1.444 albertel 17266: if ($args->{'crsid'}) {
17267: $cenv{'courseid'}=$args->{'crsid'};
17268: }
17269: if ($args->{'crscode'}) {
17270: $cenv{'internal.coursecode'}=$args->{'crscode'};
17271: }
17272: if ($args->{'crsquota'} ne '') {
17273: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17274: } else {
17275: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17276: }
17277: if ($args->{'ccuname'}) {
17278: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17279: ':'.$args->{'ccdomain'};
17280: } else {
17281: $cenv{'internal.courseowner'} = $args->{'curruser'};
17282: }
1.1116 raeburn 17283: if ($args->{'defaultcredits'}) {
17284: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17285: }
1.444 albertel 17286: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1412 raeburn 17287: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 17288: if ($args->{'crssections'}) {
17289: $cenv{'internal.sectionnums'} = '';
17290: if ($args->{'crssections'} =~ m/,/) {
17291: @sections = split/,/,$args->{'crssections'};
17292: } else {
17293: $sections[0] = $args->{'crssections'};
17294: }
17295: if (@sections > 0) {
17296: foreach my $item (@sections) {
17297: my ($sec,$gp) = split/:/,$item;
17298: my $class = $args->{'crscode'}.$sec;
17299: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17300: $cenv{'internal.sectionnums'} .= $item.',';
1.1412 raeburn 17301: if ($addcheck eq 'ok') {
17302: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17303: push(@oklcsecs,$gp);
17304: }
17305: } else {
1.1263 raeburn 17306: push(@badclasses,$class);
1.444 albertel 17307: }
17308: }
17309: $cenv{'internal.sectionnums'} =~ s/,$//;
17310: }
17311: }
17312: # do not hide course coordinator from staff listing,
17313: # even if privileged
17314: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17315: # add course coordinator's domain to domains to check for privileged users
17316: # if different to course domain
17317: if ($$crsudom ne $args->{'ccdomain'}) {
17318: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17319: }
1.444 albertel 17320: # add crosslistings
17321: if ($args->{'crsxlist'}) {
17322: $cenv{'internal.crosslistings'}='';
17323: if ($args->{'crsxlist'} =~ m/,/) {
17324: @xlists = split/,/,$args->{'crsxlist'};
17325: } else {
17326: $xlists[0] = $args->{'crsxlist'};
17327: }
17328: if (@xlists > 0) {
17329: foreach my $item (@xlists) {
17330: my ($xl,$gp) = split/:/,$item;
17331: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17332: $cenv{'internal.crosslistings'} .= $item.',';
1.1412 raeburn 17333: if ($addcheck eq 'ok') {
17334: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17335: push(@oklcsecs,$gp);
17336: }
17337: } else {
1.1263 raeburn 17338: push(@badclasses,$xl);
1.444 albertel 17339: }
17340: }
17341: $cenv{'internal.crosslistings'} =~ s/,$//;
17342: }
17343: }
17344: if ($args->{'autoadds'}) {
17345: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17346: }
17347: if ($args->{'autodrops'}) {
17348: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17349: }
17350: # check for notification of enrollment changes
17351: my @notified = ();
17352: if ($args->{'notify_owner'}) {
17353: if ($args->{'ccuname'} ne '') {
17354: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17355: }
17356: }
17357: if ($args->{'notify_dc'}) {
17358: if ($uname ne '') {
1.630 raeburn 17359: push(@notified,$uname.':'.$udom);
1.444 albertel 17360: }
17361: }
17362: if (@notified > 0) {
17363: my $notifylist;
17364: if (@notified > 1) {
17365: $notifylist = join(',',@notified);
17366: } else {
17367: $notifylist = $notified[0];
17368: }
17369: $cenv{'internal.notifylist'} = $notifylist;
17370: }
17371: if (@badclasses > 0) {
17372: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17373: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17374: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17375: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17376: );
1.1264 raeburn 17377: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17378: &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 17379: if ($context eq 'auto') {
17380: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17381: } else {
1.566 albertel 17382: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17383: }
17384: foreach my $item (@badclasses) {
1.541 raeburn 17385: if ($context eq 'auto') {
1.1261 raeburn 17386: $outcome .= " - $item\n";
1.541 raeburn 17387: } else {
1.1261 raeburn 17388: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17389: }
1.1261 raeburn 17390: }
17391: if ($context eq 'auto') {
17392: $outcome .= $linefeed;
17393: } else {
17394: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17395: }
1.444 albertel 17396: }
17397: if ($args->{'no_end_date'}) {
17398: $args->{'endaccess'} = 0;
17399: }
1.1412 raeburn 17400: # If an official course with institutional sections is created by cloning
17401: # an existing course, section-specific hiding of course totals in student's
17402: # view of grades as copied from cloned course, will be checked for valid
17403: # sections.
17404: if (($can_clone && $cloneid) &&
17405: ($cenv{'internal.coursecode'} ne '') &&
17406: ($cenv{'grading'} eq 'standard') &&
17407: ($cenv{'hidetotals'} ne '') &&
17408: ($cenv{'hidetotals'} ne 'all')) {
17409: my @hidesecs;
17410: my $deletehidetotals;
17411: if (@oklcsecs) {
17412: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
17413: if (grep(/^\Q$sec$/,@oklcsecs)) {
17414: push(@hidesecs,$sec);
17415: }
17416: }
17417: if (@hidesecs) {
17418: $cenv{'hidetotals'} = join(',',@hidesecs);
17419: } else {
17420: $deletehidetotals = 1;
17421: }
17422: } else {
17423: $deletehidetotals = 1;
17424: }
17425: if ($deletehidetotals) {
17426: delete($cenv{'hidetotals'});
17427: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
17428: }
17429: }
1.444 albertel 17430: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17431: $cenv{'internal.autoend'}=$args->{'enrollend'};
17432: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17433: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17434: if ($args->{'showphotos'}) {
17435: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17436: }
17437: $cenv{'internal.authtype'} = $args->{'authtype'};
17438: $cenv{'internal.autharg'} = $args->{'autharg'};
17439: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17440: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17441: 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');
17442: if ($context eq 'auto') {
17443: $outcome .= $krb_msg;
17444: } else {
1.566 albertel 17445: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17446: }
17447: $outcome .= $linefeed;
1.444 albertel 17448: }
17449: }
17450: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17451: if ($args->{'setpolicy'}) {
17452: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17453: }
17454: if ($args->{'setcontent'}) {
17455: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17456: }
1.1251 raeburn 17457: if ($args->{'setcomment'}) {
17458: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17459: }
1.444 albertel 17460: }
17461: if ($args->{'reshome'}) {
17462: $cenv{'reshome'}=$args->{'reshome'}.'/';
17463: $cenv{'reshome'}=~s/\/+$/\//;
17464: }
17465: #
17466: # course has keyed access
17467: #
17468: if ($args->{'setkeys'}) {
17469: $cenv{'keyaccess'}='yes';
17470: }
17471: # if specified, key authority is not course, but user
17472: # only active if keyaccess is yes
17473: if ($args->{'keyauth'}) {
1.487 albertel 17474: my ($user,$domain) = split(':',$args->{'keyauth'});
17475: $user = &LONCAPA::clean_username($user);
17476: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17477: if ($user ne '' && $domain ne '') {
1.487 albertel 17478: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17479: }
17480: }
17481:
1.1166 raeburn 17482: #
1.1167 raeburn 17483: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17484: #
17485: if ($args->{'uniquecode'}) {
17486: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17487: if ($code) {
17488: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17489: my %crsinfo =
17490: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17491: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17492: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17493: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17494: }
1.1166 raeburn 17495: if (ref($coderef)) {
17496: $$coderef = $code;
17497: }
17498: }
17499: }
17500:
1.444 albertel 17501: if ($args->{'disresdis'}) {
17502: $cenv{'pch.roles.denied'}='st';
17503: }
17504: if ($args->{'disablechat'}) {
17505: $cenv{'plc.roles.denied'}='st';
17506: }
17507:
17508: # Record we've not yet viewed the Course Initialization Helper for this
17509: # course
17510: $cenv{'course.helper.not.run'} = 1;
17511: #
17512: # Use new Randomseed
17513: #
17514: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17515: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17516: #
17517: # The encryption code and receipt prefix for this course
17518: #
17519: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17520: $cenv{'internal.encpref'}=100+int(9*rand(99));
17521: #
17522: # By default, use standard grading
17523: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17524:
1.541 raeburn 17525: $outcome .= $linefeed.&mt('Setting environment').': '.
17526: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17527: #
17528: # Open all assignments
17529: #
17530: if ($args->{'openall'}) {
1.1341 raeburn 17531: my $opendate = time;
17532: if ($args->{'openallfrom'} =~ /^\d+$/) {
17533: $opendate = $args->{'openallfrom'};
17534: }
1.444 albertel 17535: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17536: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17537: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17538: $outcome .= &mt('All assignments open starting [_1]',
17539: &Apache::lonlocal::locallocaltime($opendate)).': '.
17540: &Apache::lonnet::cput
17541: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17542: }
17543: #
17544: # Set first page
17545: #
17546: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17547: || ($cloneid)) {
17548: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17549:
17550: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17551: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17552:
1.444 albertel 17553: $outcome .= ($fatal?$errtext:'read ok').' - ';
17554: my $title; my $url;
17555: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17556: $title=&mt('Syllabus');
1.444 albertel 17557: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17558: } else {
1.963 raeburn 17559: $title=&mt('Table of Contents');
1.444 albertel 17560: $url='/adm/navmaps';
17561: }
1.445 albertel 17562:
17563: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17564: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17565:
17566: if ($errtext) { $fatal=2; }
1.541 raeburn 17567: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17568: }
1.566 albertel 17569:
1.1237 raeburn 17570: #
17571: # Set params for Placement Tests
17572: #
1.1239 raeburn 17573: if ($args->{'crstype'} eq 'Placement') {
17574: my %storecontent;
17575: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17576: my %defaults = (
17577: buttonshide => { value => 'yes',
17578: type => 'string_yesno',},
17579: type => { value => 'randomizetry',
17580: type => 'string_questiontype',},
17581: maxtries => { value => 1,
17582: type => 'int_pos',},
17583: problemstatus => { value => 'no',
17584: type => 'string_problemstatus',},
17585: );
17586: foreach my $key (keys(%defaults)) {
17587: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17588: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17589: }
1.1237 raeburn 17590: &Apache::lonnet::cput
17591: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17592: }
17593:
1.1344 raeburn 17594: return (1,$outcome,\@clonemsg);
1.444 albertel 17595: }
17596:
1.1166 raeburn 17597: sub make_unique_code {
17598: my ($cdom,$cnum) = @_;
17599: # get lock on uniquecodes db
17600: my $lockhash = {
17601: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17602: ':'.$env{'user.domain'},
17603: };
17604: my $tries = 0;
17605: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17606: my ($code,$error);
17607:
17608: while (($gotlock ne 'ok') && ($tries<3)) {
17609: $tries ++;
17610: sleep 1;
17611: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17612: }
17613: if ($gotlock eq 'ok') {
17614: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17615: my $gotcode;
17616: my $attempts = 0;
17617: while ((!$gotcode) && ($attempts < 100)) {
17618: $code = &generate_code();
17619: if (!exists($currcodes{$code})) {
17620: $gotcode = 1;
17621: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17622: $error = 'nostore';
17623: }
17624: }
17625: $attempts ++;
17626: }
17627: my @del_lock = ($cnum."\0".'uniquecodes');
17628: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17629: } else {
17630: $error = 'nolock';
17631: }
17632: return ($code,$error);
17633: }
17634:
17635: sub generate_code {
17636: my $code;
17637: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17638: for (my $i=0; $i<6; $i++) {
17639: my $lettnum = int (rand 2);
17640: my $item = '';
17641: if ($lettnum) {
17642: $item = $letts[int( rand(18) )];
17643: } else {
17644: $item = 1+int( rand(8) );
17645: }
17646: $code .= $item;
17647: }
17648: return $code;
17649: }
17650:
1.444 albertel 17651: ############################################################
17652: ############################################################
17653:
1.1237 raeburn 17654: # Community, Course and Placement Test
1.378 raeburn 17655: sub course_type {
17656: my ($cid) = @_;
17657: if (!defined($cid)) {
17658: $cid = $env{'request.course.id'};
17659: }
1.404 albertel 17660: if (defined($env{'course.'.$cid.'.type'})) {
17661: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17662: } else {
17663: return 'Course';
1.377 raeburn 17664: }
17665: }
1.156 albertel 17666:
1.406 raeburn 17667: sub group_term {
17668: my $crstype = &course_type();
17669: my %names = (
17670: 'Course' => 'group',
1.865 raeburn 17671: 'Community' => 'group',
1.1237 raeburn 17672: 'Placement' => 'group',
1.406 raeburn 17673: );
17674: return $names{$crstype};
17675: }
17676:
1.902 raeburn 17677: sub course_types {
1.1310 raeburn 17678: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17679: my %typename = (
17680: official => 'Official course',
17681: unofficial => 'Unofficial course',
17682: community => 'Community',
1.1165 raeburn 17683: textbook => 'Textbook course',
1.1237 raeburn 17684: placement => 'Placement test',
1.1310 raeburn 17685: lti => 'LTI provider',
1.902 raeburn 17686: );
17687: return (\@types,\%typename);
17688: }
17689:
1.156 albertel 17690: sub icon {
17691: my ($file)=@_;
1.505 albertel 17692: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17693: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17694: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17695: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17696: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17697: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17698: $curfext.".gif") {
17699: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17700: $curfext.".gif";
17701: }
17702: }
1.249 albertel 17703: return &lonhttpdurl($iconname);
1.154 albertel 17704: }
1.84 albertel 17705:
1.575 albertel 17706: sub lonhttpdurl {
1.692 www 17707: #
17708: # Had been used for "small fry" static images on separate port 8080.
17709: # Modify here if lightweight http functionality desired again.
17710: # Currently eliminated due to increasing firewall issues.
17711: #
1.575 albertel 17712: my ($url)=@_;
1.692 www 17713: return $url;
1.215 albertel 17714: }
17715:
1.213 albertel 17716: sub connection_aborted {
17717: my ($r)=@_;
17718: $r->print(" ");$r->rflush();
17719: my $c = $r->connection;
17720: return $c->aborted();
17721: }
17722:
1.221 foxr 17723: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17724: # strings as 'strings'.
17725: sub escape_single {
1.221 foxr 17726: my ($input) = @_;
1.223 albertel 17727: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17728: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17729: return $input;
17730: }
1.223 albertel 17731:
1.222 foxr 17732: # Same as escape_single, but escape's "'s This
17733: # can be used for "strings"
17734: sub escape_double {
17735: my ($input) = @_;
17736: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17737: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17738: return $input;
17739: }
1.223 albertel 17740:
1.222 foxr 17741: # Escapes the last element of a full URL.
17742: sub escape_url {
17743: my ($url) = @_;
1.238 raeburn 17744: my @urlslices = split(/\//, $url,-1);
1.369 www 17745: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17746: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17747: }
1.462 albertel 17748:
1.820 raeburn 17749: sub compare_arrays {
17750: my ($arrayref1,$arrayref2) = @_;
17751: my (@difference,%count);
17752: @difference = ();
17753: %count = ();
17754: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17755: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17756: foreach my $element (keys(%count)) {
17757: if ($count{$element} == 1) {
17758: push(@difference,$element);
17759: }
17760: }
17761: }
17762: return @difference;
17763: }
17764:
1.1322 raeburn 17765: sub lon_status_items {
17766: my %defaults = (
17767: E => 100,
17768: W => 4,
17769: N => 1,
1.1324 raeburn 17770: U => 5,
1.1322 raeburn 17771: threshold => 200,
17772: sysmail => 2500,
17773: );
17774: my %names = (
17775: E => 'Errors',
17776: W => 'Warnings',
17777: N => 'Notices',
1.1324 raeburn 17778: U => 'Unsent',
1.1322 raeburn 17779: );
17780: return (\%defaults,\%names);
17781: }
17782:
1.817 bisitz 17783: # -------------------------------------------------------- Initialize user login
1.462 albertel 17784: sub init_user_environment {
1.463 albertel 17785: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17786: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17787:
17788: my $public=($username eq 'public' && $domain eq 'public');
17789:
1.1415 raeburn 17790: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17791: $coauthorenv);
1.462 albertel 17792: my $now=time;
17793:
17794: if ($public) {
17795: my $max_public=100;
17796: my $oldest;
17797: my $oldest_time=0;
17798: for(my $next=1;$next<=$max_public;$next++) {
17799: if (-e $lonids."/publicuser_$next.id") {
17800: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17801: if ($mtime<$oldest_time || !$oldest_time) {
17802: $oldest_time=$mtime;
17803: $oldest=$next;
17804: }
17805: } else {
17806: $cookie="publicuser_$next";
17807: last;
17808: }
17809: }
17810: if (!$cookie) { $cookie="publicuser_$oldest"; }
17811: } else {
1.1275 raeburn 17812: # See if old ID present, if so, remove if this isn't a robot,
17813: # killing any existing non-robot sessions
1.463 albertel 17814: if (!$args->{'robot'}) {
17815: opendir(DIR,$lonids);
17816: while ($filename=readdir(DIR)) {
17817: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17818: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17819: &GDBM_READER(),0640)) {
1.1295 raeburn 17820: my $linkedfile;
1.1320 raeburn 17821: if (exists($oldenv{'user.linkedenv'})) {
17822: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17823: }
1.1320 raeburn 17824: untie(%oldenv);
17825: if (unlink("$lonids/$filename")) {
17826: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17827: if (-l "$lonids/$linkedfile.id") {
17828: unlink("$lonids/$linkedfile.id");
17829: }
1.1295 raeburn 17830: }
17831: }
17832: } else {
17833: unlink($lonids.'/'.$filename);
17834: }
1.463 albertel 17835: }
1.462 albertel 17836: }
1.463 albertel 17837: closedir(DIR);
1.1204 raeburn 17838: # If there is a undeleted lockfile for the user's paste buffer remove it.
17839: my $namespace = 'nohist_courseeditor';
17840: my $lockingkey = 'paste'."\0".'locked_num';
17841: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17842: $domain,$username);
17843: if (exists($lockhash{$lockingkey})) {
17844: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17845: unless ($delresult eq 'ok') {
17846: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17847: }
17848: }
1.462 albertel 17849: }
17850: # Give them a new cookie
1.463 albertel 17851: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17852: : $now.$$.int(rand(10000)));
1.463 albertel 17853: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17854:
17855: # Initialize roles
17856:
1.1414 raeburn 17857: ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17858: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17859: }
17860: # ------------------------------------ Check browser type and MathML capability
17861:
1.1194 raeburn 17862: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17863: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17864:
17865: # ------------------------------------------------------------- Get environment
17866:
17867: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17868: my ($tmp) = keys(%userenv);
1.1275 raeburn 17869: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17870: undef(%userenv);
17871: }
17872: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17873: $form->{'interface'}=$userenv{'interface'};
17874: }
17875: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17876:
17877: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17878: foreach my $option ('interface','localpath','localres') {
17879: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17880: }
17881: # --------------------------------------------------------- Write first profile
17882:
17883: {
1.1350 raeburn 17884: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17885: my %initial_env =
17886: ("user.name" => $username,
17887: "user.domain" => $domain,
17888: "user.home" => $authhost,
17889: "browser.type" => $clientbrowser,
17890: "browser.version" => $clientversion,
17891: "browser.mathml" => $clientmathml,
17892: "browser.unicode" => $clientunicode,
17893: "browser.os" => $clientos,
1.1137 raeburn 17894: "browser.mobile" => $clientmobile,
1.1141 raeburn 17895: "browser.info" => $clientinfo,
1.1194 raeburn 17896: "browser.osversion" => $clientosversion,
1.462 albertel 17897: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17898: "request.course.fn" => '',
17899: "request.course.uri" => '',
17900: "request.course.sec" => '',
17901: "request.role" => 'cm',
17902: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17903: "request.host" => $ip,);
1.462 albertel 17904:
17905: if ($form->{'localpath'}) {
17906: $initial_env{"browser.localpath"} = $form->{'localpath'};
17907: $initial_env{"browser.localres"} = $form->{'localres'};
17908: }
17909:
17910: if ($form->{'interface'}) {
17911: $form->{'interface'}=~s/\W//gs;
17912: $initial_env{"browser.interface"} = $form->{'interface'};
17913: $env{'browser.interface'}=$form->{'interface'};
17914: }
17915:
1.1157 raeburn 17916: if ($form->{'iptoken'}) {
17917: my $lonhost = $r->dir_config('lonHostID');
17918: $initial_env{"user.noloadbalance"} = $lonhost;
17919: $env{'user.noloadbalance'} = $lonhost;
17920: }
17921:
1.1268 raeburn 17922: if ($form->{'noloadbalance'}) {
17923: my @hosts = &Apache::lonnet::current_machine_ids();
17924: my $hosthere = $form->{'noloadbalance'};
17925: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17926: $initial_env{"user.noloadbalance"} = $hosthere;
17927: $env{'user.noloadbalance'} = $hosthere;
17928: }
17929: }
17930:
1.1016 raeburn 17931: unless ($domain eq 'public') {
1.1273 raeburn 17932: my %is_adv = ( is_adv => $env{'user.adv'} );
17933: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17934:
1.1414 raeburn 17935: foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
17936: $userenv{'availabletools.'.$tool} =
1.1273 raeburn 17937: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17938: undef,\%userenv,\%domdef,\%is_adv);
17939: }
1.980 raeburn 17940:
1.1311 raeburn 17941: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17942: $userenv{'canrequest.'.$crstype} =
17943: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17944: 'reload','requestcourses',
17945: \%userenv,\%domdef,\%is_adv);
17946: }
1.724 raeburn 17947:
1.1418 raeburn 17948: if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
17949: (exists($userroles->{"user.role.au./$domain/"}))) {
17950: if ($userenv{'authoreditors'}) {
17951: $userenv{'editors'} = $userenv{'authoreditors'};
17952: } elsif ($domdef{'editors'} ne '') {
17953: $userenv{'editors'} = $domdef{'editors'};
17954: } else {
17955: $userenv{'editors'} = 'edit,xml';
17956: }
17957: }
17958:
1.1273 raeburn 17959: $userenv{'canrequest.author'} =
17960: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17961: 'reload','requestauthor',
1.980 raeburn 17962: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17963: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17964: $domain,$username);
17965: my $reqstatus = $reqauthor{'author_status'};
17966: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17967: if (ref($reqauthor{'author'}) eq 'HASH') {
17968: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17969: $reqauthor{'author'}{'timestamp'};
17970: }
1.1092 raeburn 17971: }
1.1287 raeburn 17972: my ($types,$typename) = &course_types();
17973: if (ref($types) eq 'ARRAY') {
17974: my @options = ('approval','validate','autolimit');
17975: my $optregex = join('|',@options);
17976: my (%willtrust,%trustchecked);
17977: foreach my $type (@{$types}) {
17978: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17979: if ($dom_str ne '') {
17980: my $updatedstr = '';
17981: my @possdomains = split(',',$dom_str);
17982: foreach my $entry (@possdomains) {
17983: my ($extdom,$extopt) = split(':',$entry);
17984: unless ($trustchecked{$extdom}) {
17985: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17986: $trustchecked{$extdom} = 1;
17987: }
17988: if ($willtrust{$extdom}) {
17989: $updatedstr .= $entry.',';
17990: }
17991: }
17992: $updatedstr =~ s/,$//;
17993: if ($updatedstr) {
17994: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17995: } else {
17996: delete($userenv{'reqcrsotherdom.'.$type});
17997: }
17998: }
17999: }
18000: }
1.1092 raeburn 18001: }
1.462 albertel 18002: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 18003:
1.462 albertel 18004: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
18005: &GDBM_WRCREAT(),0640)) {
18006: &_add_to_env(\%disk_env,\%initial_env);
18007: &_add_to_env(\%disk_env,\%userenv,'environment.');
18008: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 18009: if (ref($firstaccenv) eq 'HASH') {
18010: &_add_to_env(\%disk_env,$firstaccenv);
18011: }
18012: if (ref($timerintenv) eq 'HASH') {
18013: &_add_to_env(\%disk_env,$timerintenv);
18014: }
1.1414 raeburn 18015: if (ref($coauthorenv) eq 'HASH') {
18016: if (keys(%{$coauthorenv})) {
18017: &_add_to_env(\%disk_env,$coauthorenv);
18018: }
18019: }
1.463 albertel 18020: if (ref($args->{'extra_env'})) {
18021: &_add_to_env(\%disk_env,$args->{'extra_env'});
18022: }
1.462 albertel 18023: untie(%disk_env);
18024: } else {
1.705 tempelho 18025: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
18026: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 18027: return 'error: '.$!;
18028: }
18029: }
18030: $env{'request.role'}='cm';
18031: $env{'request.role.adv'}=$env{'user.adv'};
18032: $env{'browser.type'}=$clientbrowser;
18033:
18034: return $cookie;
18035:
18036: }
18037:
18038: sub _add_to_env {
18039: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 18040: if (ref($env_data) eq 'HASH') {
18041: while (my ($key,$value) = each(%$env_data)) {
18042: $idf->{$prefix.$key} = $value;
18043: $env{$prefix.$key} = $value;
18044: }
1.462 albertel 18045: }
18046: }
18047:
1.685 tempelho 18048: # --- Get the symbolic name of a problem and the url
18049: sub get_symb {
18050: my ($request,$silent) = @_;
1.726 raeburn 18051: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 18052: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
18053: if ($symb eq '') {
18054: if (!$silent) {
1.1071 raeburn 18055: if (ref($request)) {
18056: $request->print("Unable to handle ambiguous references:$url:.");
18057: }
1.685 tempelho 18058: return ();
18059: }
18060: }
18061: &Apache::lonenc::check_decrypt(\$symb);
18062: return ($symb);
18063: }
18064:
18065: # --------------------------------------------------------------Get annotation
18066:
18067: sub get_annotation {
18068: my ($symb,$enc) = @_;
18069:
18070: my $key = $symb;
18071: if (!$enc) {
18072: $key =
18073: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
18074: }
18075: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
18076: return $annotation{$key};
18077: }
18078:
18079: sub clean_symb {
1.731 raeburn 18080: my ($symb,$delete_enc) = @_;
1.685 tempelho 18081:
18082: &Apache::lonenc::check_decrypt(\$symb);
18083: my $enc = $env{'request.enc'};
1.731 raeburn 18084: if ($delete_enc) {
1.730 raeburn 18085: delete($env{'request.enc'});
18086: }
1.685 tempelho 18087:
18088: return ($symb,$enc);
18089: }
1.462 albertel 18090:
1.1181 raeburn 18091: ############################################################
18092: ############################################################
18093:
18094: =pod
18095:
18096: =head1 Routines for building display used to search for courses
18097:
18098:
18099: =over 4
18100:
18101: =item * &build_filters()
18102:
18103: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 18104: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
18105: and quotacheck.pl
18106:
1.1181 raeburn 18107:
18108: Inputs:
18109:
18110: filterlist - anonymous array of fields to include as potential filters
18111:
18112: crstype - course type
18113:
18114: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
18115: to pop-open a course selector (will contain "extra element").
18116:
18117: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
18118:
18119: filter - anonymous hash of criteria and their values
18120:
18121: action - form action
18122:
18123: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
18124:
1.1182 raeburn 18125: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 18126:
18127: cloneruname - username of owner of new course who wants to clone
18128:
18129: clonerudom - domain of owner of new course who wants to clone
18130:
18131: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
18132:
18133: codetitlesref - reference to array of titles of components in institutional codes (official courses)
18134:
18135: codedom - domain
18136:
18137: formname - value of form element named "form".
18138:
18139: fixeddom - domain, if fixed.
18140:
18141: prevphase - value to assign to form element named "phase" when going back to the previous screen
18142:
18143: cnameelement - name of form element in form on opener page which will receive title of selected course
18144:
18145: cnumelement - name of form element in form on opener page which will receive courseID of selected course
18146:
18147: cdomelement - name of form element in form on opener page which will receive domain of selected course
18148:
18149: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
18150:
18151: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
18152:
18153: clonewarning - warning message about missing information for intended course owner when DC creates a course
18154:
1.1182 raeburn 18155:
1.1181 raeburn 18156: Returns: $output - HTML for display of search criteria, and hidden form elements.
18157:
1.1182 raeburn 18158:
1.1181 raeburn 18159: Side Effects: None
18160:
18161: =cut
18162:
18163: # ---------------------------------------------- search for courses based on last activity etc.
18164:
18165: sub build_filters {
18166: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
18167: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
18168: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
18169: $cnameelement,$cnumelement,$cdomelement,$setroles,
18170: $clonetext,$clonewarning) = @_;
1.1182 raeburn 18171: my ($list,$jscript);
1.1181 raeburn 18172: my $onchange = 'javascript:updateFilters(this)';
18173: my ($domainselectform,$sincefilterform,$createdfilterform,
18174: $ownerdomselectform,$persondomselectform,$instcodeform,
18175: $typeselectform,$instcodetitle);
18176: if ($formname eq '') {
18177: $formname = $caller;
18178: }
18179: foreach my $item (@{$filterlist}) {
18180: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
18181: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
18182: if ($item eq 'domainfilter') {
18183: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
18184: } elsif ($item eq 'coursefilter') {
18185: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
18186: } elsif ($item eq 'ownerfilter') {
18187: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18188: } elsif ($item eq 'ownerdomfilter') {
18189: $filter->{'ownerdomfilter'} =
18190: &LONCAPA::clean_domain($filter->{$item});
18191: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
18192: 'ownerdomfilter',1);
18193: } elsif ($item eq 'personfilter') {
18194: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18195: } elsif ($item eq 'persondomfilter') {
18196: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
18197: 'persondomfilter',1);
18198: } else {
18199: $filter->{$item} =~ s/\W//g;
18200: }
18201: if (!$filter->{$item}) {
18202: $filter->{$item} = '';
18203: }
18204: }
18205: if ($item eq 'domainfilter') {
18206: my $allow_blank = 1;
18207: if ($formname eq 'portform') {
18208: $allow_blank=0;
18209: } elsif ($formname eq 'studentform') {
18210: $allow_blank=0;
18211: }
18212: if ($fixeddom) {
18213: $domainselectform = '<input type="hidden" name="domainfilter"'.
18214: ' value="'.$codedom.'" />'.
18215: &Apache::lonnet::domain($codedom,'description');
18216: } else {
18217: $domainselectform = &select_dom_form($filter->{$item},
18218: 'domainfilter',
18219: $allow_blank,'',$onchange);
18220: }
18221: } else {
18222: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
18223: }
18224: }
18225:
18226: # last course activity filter and selection
18227: $sincefilterform = &timebased_select_form('sincefilter',$filter);
18228:
18229: # course created filter and selection
18230: if (exists($filter->{'createdfilter'})) {
18231: $createdfilterform = &timebased_select_form('createdfilter',$filter);
18232: }
18233:
1.1239 raeburn 18234: my $prefix = $crstype;
18235: if ($crstype eq 'Placement') {
18236: $prefix = 'Placement Test'
18237: }
1.1181 raeburn 18238: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 18239: 'cac' => "$prefix Activity",
18240: 'ccr' => "$prefix Created",
18241: 'cde' => "$prefix Title",
18242: 'cdo' => "$prefix Domain",
1.1181 raeburn 18243: 'ins' => 'Institutional Code',
18244: 'inc' => 'Institutional Categorization',
1.1239 raeburn 18245: 'cow' => "$prefix Owner/Co-owner",
18246: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 18247: 'cog' => 'Type',
18248: );
18249:
18250: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18251: my $typeval = 'Course';
18252: if ($crstype eq 'Community') {
18253: $typeval = 'Community';
1.1239 raeburn 18254: } elsif ($crstype eq 'Placement') {
18255: $typeval = 'Placement';
1.1181 raeburn 18256: }
18257: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
18258: } else {
18259: $typeselectform = '<select name="type" size="1"';
18260: if ($onchange) {
18261: $typeselectform .= ' onchange="'.$onchange.'"';
18262: }
18263: $typeselectform .= '>'."\n";
1.1237 raeburn 18264: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 18265: my $shown;
18266: if ($posstype eq 'Placement') {
18267: $shown = &mt('Placement Test');
18268: } else {
18269: $shown = &mt($posstype);
18270: }
1.1181 raeburn 18271: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 18272: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 18273: }
18274: $typeselectform.="</select>";
18275: }
18276:
18277: my ($cloneableonlyform,$cloneabletitle);
18278: if (exists($filter->{'cloneableonly'})) {
18279: my $cloneableon = '';
18280: my $cloneableoff = ' checked="checked"';
18281: if ($filter->{'cloneableonly'}) {
18282: $cloneableon = $cloneableoff;
18283: $cloneableoff = '';
18284: }
18285: $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>';
18286: if ($formname eq 'ccrs') {
1.1187 bisitz 18287: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 18288: } else {
18289: $cloneabletitle = &mt('Cloneable by you');
18290: }
18291: }
18292: my $officialjs;
18293: if ($crstype eq 'Course') {
18294: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 18295: # if (($fixeddom) || ($formname eq 'requestcrs') ||
18296: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
18297: if ($codedom) {
1.1181 raeburn 18298: $officialjs = 1;
18299: ($instcodeform,$jscript,$$numtitlesref) =
18300: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
18301: $officialjs,$codetitlesref);
18302: if ($jscript) {
1.1182 raeburn 18303: $jscript = '<script type="text/javascript">'."\n".
18304: '// <![CDATA['."\n".
18305: $jscript."\n".
18306: '// ]]>'."\n".
18307: '</script>'."\n";
1.1181 raeburn 18308: }
18309: }
18310: if ($instcodeform eq '') {
18311: $instcodeform =
18312: '<input type="text" name="instcodefilter" size="10" value="'.
18313: $list->{'instcodefilter'}.'" />';
18314: $instcodetitle = $lt{'ins'};
18315: } else {
18316: $instcodetitle = $lt{'inc'};
18317: }
18318: if ($fixeddom) {
18319: $instcodetitle .= '<br />('.$codedom.')';
18320: }
18321: }
18322: }
18323: my $output = qq|
18324: <form method="post" name="filterpicker" action="$action">
18325: <input type="hidden" name="form" value="$formname" />
18326: |;
18327: if ($formname eq 'modifycourse') {
18328: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18329: '<input type="hidden" name="prevphase" value="'.
18330: $prevphase.'" />'."\n";
1.1198 musolffc 18331: } elsif ($formname eq 'quotacheck') {
18332: $output .= qq|
18333: <input type="hidden" name="sortby" value="" />
18334: <input type="hidden" name="sortorder" value="" />
18335: |;
18336: } else {
1.1181 raeburn 18337: my $name_input;
18338: if ($cnameelement ne '') {
18339: $name_input = '<input type="hidden" name="cnameelement" value="'.
18340: $cnameelement.'" />';
18341: }
18342: $output .= qq|
1.1182 raeburn 18343: <input type="hidden" name="cnumelement" value="$cnumelement" />
18344: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18345: $name_input
18346: $roleelement
18347: $multelement
18348: $typeelement
18349: |;
18350: if ($formname eq 'portform') {
18351: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18352: }
18353: }
18354: if ($fixeddom) {
18355: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18356: }
18357: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18358: if ($sincefilterform) {
18359: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18360: .$sincefilterform
18361: .&Apache::lonhtmlcommon::row_closure();
18362: }
18363: if ($createdfilterform) {
18364: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18365: .$createdfilterform
18366: .&Apache::lonhtmlcommon::row_closure();
18367: }
18368: if ($domainselectform) {
18369: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18370: .$domainselectform
18371: .&Apache::lonhtmlcommon::row_closure();
18372: }
18373: if ($typeselectform) {
18374: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18375: $output .= $typeselectform;
18376: } else {
18377: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18378: .$typeselectform
18379: .&Apache::lonhtmlcommon::row_closure();
18380: }
18381: }
18382: if ($instcodeform) {
18383: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18384: .$instcodeform
18385: .&Apache::lonhtmlcommon::row_closure();
18386: }
18387: if (exists($filter->{'ownerfilter'})) {
18388: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18389: '<table><tr><td>'.&mt('Username').'<br />'.
18390: '<input type="text" name="ownerfilter" size="20" value="'.
18391: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18392: $ownerdomselectform.'</td></tr></table>'.
18393: &Apache::lonhtmlcommon::row_closure();
18394: }
18395: if (exists($filter->{'personfilter'})) {
18396: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18397: '<table><tr><td>'.&mt('Username').'<br />'.
18398: '<input type="text" name="personfilter" size="20" value="'.
18399: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18400: $persondomselectform.'</td></tr></table>'.
18401: &Apache::lonhtmlcommon::row_closure();
18402: }
18403: if (exists($filter->{'coursefilter'})) {
18404: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18405: .'<input type="text" name="coursefilter" size="25" value="'
18406: .$list->{'coursefilter'}.'" />'
18407: .&Apache::lonhtmlcommon::row_closure();
18408: }
18409: if ($cloneableonlyform) {
18410: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18411: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18412: }
18413: if (exists($filter->{'descriptfilter'})) {
18414: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18415: .'<input type="text" name="descriptfilter" size="40" value="'
18416: .$list->{'descriptfilter'}.'" />'
18417: .&Apache::lonhtmlcommon::row_closure(1);
18418: }
18419: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18420: '<input type="hidden" name="updater" value="" />'."\n".
18421: '<input type="submit" name="gosearch" value="'.
18422: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18423: return $jscript.$clonewarning.$output;
18424: }
18425:
18426: =pod
18427:
18428: =item * &timebased_select_form()
18429:
1.1182 raeburn 18430: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18431: filter e.g., Course Activity, Course Created, when searching for courses
18432: or communities
18433:
18434: Inputs:
18435:
18436: item - name of form element (sincefilter or createdfilter)
18437:
18438: filter - anonymous hash of criteria and their values
18439:
18440: Returns: HTML for a select box contained a blank, then six time selections,
18441: with value set in incoming form variables currently selected.
18442:
18443: Side Effects: None
18444:
18445: =cut
18446:
18447: sub timebased_select_form {
18448: my ($item,$filter) = @_;
18449: if (ref($filter) eq 'HASH') {
18450: $filter->{$item} =~ s/[^\d-]//g;
18451: if (!$filter->{$item}) { $filter->{$item}=-1; }
18452: return &select_form(
18453: $filter->{$item},
18454: $item,
18455: { '-1' => '',
18456: '86400' => &mt('today'),
18457: '604800' => &mt('last week'),
18458: '2592000' => &mt('last month'),
18459: '7776000' => &mt('last three months'),
18460: '15552000' => &mt('last six months'),
18461: '31104000' => &mt('last year'),
18462: 'select_form_order' =>
18463: ['-1','86400','604800','2592000','7776000',
18464: '15552000','31104000']});
18465: }
18466: }
18467:
18468: =pod
18469:
18470: =item * &js_changer()
18471:
18472: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18473: when course type or domain is changed, and also to hide 'Searching ...' on
18474: page load completion for page showing search result.
1.1181 raeburn 18475:
18476: Inputs: None
18477:
1.1183 raeburn 18478: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18479:
18480: Side Effects: None
18481:
18482: =cut
18483:
18484: sub js_changer {
18485: return <<ENDJS;
18486: <script type="text/javascript">
18487: // <![CDATA[
18488: function updateFilters(caller) {
18489: if (typeof(caller) != "undefined") {
18490: document.filterpicker.updater.value = caller.name;
18491: }
18492: document.filterpicker.submit();
18493: }
1.1183 raeburn 18494:
18495: function hideSearching() {
18496: if (document.getElementById('searching')) {
18497: document.getElementById('searching').style.display = 'none';
18498: }
18499: return;
18500: }
18501:
1.1181 raeburn 18502: // ]]>
18503: </script>
18504:
18505: ENDJS
18506: }
18507:
18508: =pod
18509:
1.1182 raeburn 18510: =item * &search_courses()
18511:
18512: Process selected filters form course search form and pass to lonnet::courseiddump
18513: to retrieve a hash for which keys are courseIDs which match the selected filters.
18514:
18515: Inputs:
18516:
18517: dom - domain being searched
18518:
18519: type - course type ('Course' or 'Community' or '.' if any).
18520:
18521: filter - anonymous hash of criteria and their values
18522:
18523: numtitles - for institutional codes - number of categories
18524:
18525: cloneruname - optional username of new course owner
18526:
18527: clonerudom - optional domain of new course owner
18528:
1.1221 raeburn 18529: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18530: (used when DC is using course creation form)
18531:
18532: codetitles - reference to array of titles of components in institutional codes (official courses).
18533:
1.1221 raeburn 18534: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18535: (and so can clone automatically)
18536:
18537: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18538:
18539: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18540: courses to clone
1.1182 raeburn 18541:
18542: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18543:
18544:
18545: Side Effects: None
18546:
18547: =cut
18548:
18549:
18550: sub search_courses {
1.1221 raeburn 18551: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18552: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18553: my (%courses,%showcourses,$cloner);
18554: if (($filter->{'ownerfilter'} ne '') ||
18555: ($filter->{'ownerdomfilter'} ne '')) {
18556: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18557: $filter->{'ownerdomfilter'};
18558: }
18559: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18560: if (!$filter->{$item}) {
18561: $filter->{$item}='.';
18562: }
18563: }
18564: my $now = time;
18565: my $timefilter =
18566: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18567: my ($createdbefore,$createdafter);
18568: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18569: $createdbefore = $now;
18570: $createdafter = $now-$filter->{'createdfilter'};
18571: }
18572: my ($instcodefilter,$regexpok);
18573: if ($numtitles) {
18574: if ($env{'form.official'} eq 'on') {
18575: $instcodefilter =
18576: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18577: $regexpok = 1;
18578: } elsif ($env{'form.official'} eq 'off') {
18579: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18580: unless ($instcodefilter eq '') {
18581: $regexpok = -1;
18582: }
18583: }
18584: } else {
18585: $instcodefilter = $filter->{'instcodefilter'};
18586: }
18587: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18588: if ($type eq '') { $type = '.'; }
18589:
18590: if (($clonerudom ne '') && ($cloneruname ne '')) {
18591: $cloner = $cloneruname.':'.$clonerudom;
18592: }
18593: %courses = &Apache::lonnet::courseiddump($dom,
18594: $filter->{'descriptfilter'},
18595: $timefilter,
18596: $instcodefilter,
18597: $filter->{'combownerfilter'},
18598: $filter->{'coursefilter'},
18599: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18600: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18601: $filter->{'cloneableonly'},
18602: $createdbefore,$createdafter,undef,
1.1221 raeburn 18603: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18604: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18605: my $ccrole;
18606: if ($type eq 'Community') {
18607: $ccrole = 'co';
18608: } else {
18609: $ccrole = 'cc';
18610: }
18611: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18612: $filter->{'persondomfilter'},
18613: 'userroles',undef,
18614: [$ccrole,'in','ad','ep','ta','cr'],
18615: $dom);
18616: foreach my $role (keys(%rolehash)) {
18617: my ($cnum,$cdom,$courserole) = split(':',$role);
18618: my $cid = $cdom.'_'.$cnum;
18619: if (exists($courses{$cid})) {
18620: if (ref($courses{$cid}) eq 'HASH') {
18621: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18622: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18623: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18624: }
18625: } else {
18626: $courses{$cid}{roles} = [$courserole];
18627: }
18628: $showcourses{$cid} = $courses{$cid};
18629: }
18630: }
18631: }
18632: %courses = %showcourses;
18633: }
18634: return %courses;
18635: }
18636:
18637: =pod
18638:
1.1181 raeburn 18639: =back
18640:
1.1207 raeburn 18641: =head1 Routines for version requirements for current course.
18642:
18643: =over 4
18644:
18645: =item * &check_release_required()
18646:
18647: Compares required LON-CAPA version with version on server, and
18648: if required version is newer looks for a server with the required version.
18649:
18650: Looks first at servers in user's owen domain; if none suitable, looks at
18651: servers in course's domain are permitted to host sessions for user's domain.
18652:
18653: Inputs:
18654:
18655: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18656:
18657: $courseid - Course ID of current course
18658:
18659: $rolecode - User's current role in course (for switchserver query string).
18660:
18661: $required - LON-CAPA version needed by course (format: Major.Minor).
18662:
18663:
18664: Returns:
18665:
18666: $switchserver - query string tp append to /adm/switchserver call (if
18667: current server's LON-CAPA version is too old.
18668:
18669: $warning - Message is displayed if no suitable server could be found.
18670:
18671: =cut
18672:
18673: sub check_release_required {
18674: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18675: my ($switchserver,$warning);
18676: if ($required ne '') {
18677: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18678: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18679: if ($reqdmajor ne '' && $reqdminor ne '') {
18680: my $otherserver;
18681: if (($major eq '' && $minor eq '') ||
18682: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18683: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18684: my $switchlcrev =
18685: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18686: $userdomserver);
18687: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18688: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18689: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18690: my $cdom = $env{'course.'.$courseid.'.domain'};
18691: if ($cdom ne $env{'user.domain'}) {
18692: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18693: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18694: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18695: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18696: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18697: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18698: my $canhost =
18699: &Apache::lonnet::can_host_session($env{'user.domain'},
18700: $coursedomserver,
18701: $remoterev,
18702: $udomdefaults{'remotesessions'},
18703: $defdomdefaults{'hostedsessions'});
18704:
18705: if ($canhost) {
18706: $otherserver = $coursedomserver;
18707: } else {
18708: $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.");
18709: }
18710: } else {
18711: $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).");
18712: }
18713: } else {
18714: $otherserver = $userdomserver;
18715: }
18716: }
18717: if ($otherserver ne '') {
18718: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18719: }
18720: }
18721: }
18722: return ($switchserver,$warning);
18723: }
18724:
18725: =pod
18726:
18727: =item * &check_release_result()
18728:
18729: Inputs:
18730:
18731: $switchwarning - Warning message if no suitable server found to host session.
18732:
18733: $switchserver - query string to append to /adm/switchserver containing lonHostID
18734: and current role.
18735:
18736: Returns: HTML to display with information about requirement to switch server.
18737: Either displaying warning with link to Roles/Courses screen or
18738: display link to switchserver.
18739:
1.1181 raeburn 18740: =cut
18741:
1.1207 raeburn 18742: sub check_release_result {
18743: my ($switchwarning,$switchserver) = @_;
18744: my $output = &start_page('Selected course unavailable on this server').
18745: '<p class="LC_warning">';
18746: if ($switchwarning) {
18747: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18748: if (&show_course()) {
18749: $output .= &mt('Display courses');
18750: } else {
18751: $output .= &mt('Display roles');
18752: }
18753: $output .= '</a>';
18754: } elsif ($switchserver) {
18755: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18756: '<br />'.
18757: '<a href="/adm/switchserver?'.$switchserver.'">'.
18758: &mt('Switch Server').
18759: '</a>';
18760: }
18761: $output .= '</p>'.&end_page();
18762: return $output;
18763: }
18764:
18765: =pod
18766:
18767: =item * &needs_coursereinit()
18768:
18769: Determine if course contents stored for user's session needs to be
18770: refreshed, because content has changed since "Big Hash" last tied.
18771:
18772: Check for change is made if time last checked is more than 10 minutes ago
18773: (by default).
18774:
18775: Inputs:
18776:
18777: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18778:
18779: $interval (optional) - Time which may elapse (in s) between last check for content
18780: change in current course. (default: 600 s).
18781:
18782: Returns: an array; first element is:
18783:
18784: =over 4
18785:
18786: 'switch' - if content updates mean user's session
18787: needs to be switched to a server running a newer LON-CAPA version
18788:
18789: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18790: on current server hosting user's session
18791:
18792: '' - if no action required.
18793:
18794: =back
18795:
18796: If first item element is 'switch':
18797:
18798: second item is $switchwarning - Warning message if no suitable server found to host session.
18799:
18800: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18801: and current role.
18802:
18803: otherwise: no other elements returned.
18804:
18805: =back
18806:
18807: =cut
18808:
18809: sub needs_coursereinit {
18810: my ($loncaparev,$interval) = @_;
18811: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18812: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18813: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18814: my $now = time;
18815: if ($interval eq '') {
18816: $interval = 600;
18817: }
18818: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18819: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18820: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18821: if ($blocked) {
18822: return ();
18823: }
1.1391 raeburn 18824: my $update;
18825: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18826: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18827: if ($lastmainchange > $env{'request.course.tied'}) {
18828: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18829: if ($needswitch) {
18830: return ('switch',$switchwarning,$switchserver);
18831: }
18832: $update = 'main';
18833: }
18834: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18835: if ($update) {
18836: $update = 'both';
18837: } else {
18838: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18839: if ($needswitch) {
18840: return ('switch',$switchwarning,$switchserver);
18841: } else {
18842: $update = 'supp';
1.1207 raeburn 18843: }
18844: }
1.1391 raeburn 18845: return ($update);
18846: }
18847: }
18848: return ();
18849: }
18850:
18851: sub switch_for_update {
18852: my ($loncaparev,$cdom,$cnum) = @_;
18853: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18854: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18855: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18856: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18857: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18858: $curr_reqd_hash{'internal.releaserequired'}});
18859: my ($switchserver,$switchwarning) =
18860: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18861: $curr_reqd_hash{'internal.releaserequired'});
18862: if ($switchwarning ne '' || $switchserver ne '') {
18863: return ('switch',$switchwarning,$switchserver);
18864: }
1.1207 raeburn 18865: }
18866: }
18867: return ();
18868: }
1.1181 raeburn 18869:
1.1083 raeburn 18870: sub update_content_constraints {
1.1395 raeburn 18871: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 18872: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18873: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18874: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18875: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18876: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18877: if ($item eq 'resourcetag') {
18878: if ($name eq 'responsetype') {
18879: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18880: }
1.1307 raeburn 18881: } elsif ($item eq 'course') {
18882: if ($name eq 'courserestype') {
18883: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18884: }
1.1083 raeburn 18885: }
18886: }
18887: my $navmap = Apache::lonnavmaps::navmap->new();
18888: if (defined($navmap)) {
1.1307 raeburn 18889: my (%allresponses,%allcrsrestypes);
18890: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18891: if ($res->is_tool()) {
18892: if ($allcrsrestypes{'exttool'}) {
18893: $allcrsrestypes{'exttool'} ++;
18894: } else {
18895: $allcrsrestypes{'exttool'} = 1;
18896: }
18897: next;
18898: }
1.1083 raeburn 18899: my %responses = $res->responseTypes();
18900: foreach my $key (keys(%responses)) {
18901: next unless(exists($checkresponsetypes{$key}));
18902: $allresponses{$key} += $responses{$key};
18903: }
18904: }
18905: foreach my $key (keys(%allresponses)) {
18906: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18907: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18908: ($reqdmajor,$reqdminor) = ($major,$minor);
18909: }
18910: }
1.1307 raeburn 18911: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18912: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18913: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18914: ($reqdmajor,$reqdminor) = ($major,$minor);
18915: }
18916: }
1.1083 raeburn 18917: undef($navmap);
18918: }
1.1391 raeburn 18919: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 18920: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18921: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18922: ($reqdmajor,$reqdminor) = ($major,$minor);
18923: }
18924: }
1.1083 raeburn 18925: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18926: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18927: }
18928: return;
18929: }
18930:
1.1110 raeburn 18931: sub allmaps_incourse {
18932: my ($cdom,$cnum,$chome,$cid) = @_;
18933: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18934: $cid = $env{'request.course.id'};
18935: $cdom = $env{'course.'.$cid.'.domain'};
18936: $cnum = $env{'course.'.$cid.'.num'};
18937: $chome = $env{'course.'.$cid.'.home'};
18938: }
18939: my %allmaps = ();
18940: my $lastchange =
18941: &Apache::lonnet::get_coursechange($cdom,$cnum);
18942: if ($lastchange > $env{'request.course.tied'}) {
18943: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18944: unless ($ferr) {
1.1395 raeburn 18945: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 18946: }
18947: }
18948: my $navmap = Apache::lonnavmaps::navmap->new();
18949: if (defined($navmap)) {
18950: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18951: $allmaps{$res->src()} = 1;
18952: }
18953: }
18954: return \%allmaps;
18955: }
18956:
1.1083 raeburn 18957: sub parse_supplemental_title {
18958: my ($title) = @_;
18959:
18960: my ($foldertitle,$renametitle);
18961: if ($title =~ /&&&/) {
18962: $title = &HTML::Entites::decode($title);
18963: }
18964: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18965: $renametitle=$4;
18966: my ($time,$uname,$udom) = ($1,$2,$3);
18967: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18968: my $name = &plainname($uname,$udom);
18969: $name = &HTML::Entities::encode($name,'"<>&\'');
18970: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 18971: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 18972: if ($foldertitle ne '') {
1.1401 raeburn 18973: $title .= ': <br />'.$foldertitle;
18974: }
1.1083 raeburn 18975: }
18976: if (wantarray) {
18977: return ($title,$foldertitle,$renametitle);
18978: }
18979: return $title;
18980: }
18981:
1.1395 raeburn 18982: sub get_supplemental {
18983: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18984: my $hashid=$cnum.':'.$cdom;
18985: my ($supplemental,$cached,$set_httprefs);
18986: unless ($ignorecache) {
18987: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18988: }
18989: unless (defined($cached)) {
18990: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18991: unless ($chome eq 'no_host') {
18992: my @order = @LONCAPA::map::order;
18993: my @resources = @LONCAPA::map::resources;
18994: my @resparms = @LONCAPA::map::resparms;
18995: my @zombies = @LONCAPA::map::zombies;
18996: my ($errors,%ids,%hidden);
18997: $errors =
18998: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18999: $errors,$possdel,\%ids,\%hidden);
19000: @LONCAPA::map::order = @order;
19001: @LONCAPA::map::resources = @resources;
19002: @LONCAPA::map::resparms = @resparms;
19003: @LONCAPA::map::zombies = @zombies;
19004: $set_httprefs = 1;
19005: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19006: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19007: }
19008: $supplemental = {
19009: ids => \%ids,
19010: hidden => \%hidden,
19011: };
19012: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
19013: }
19014: }
19015: return ($supplemental,$set_httprefs);
19016: }
19017:
1.1143 raeburn 19018: sub recurse_supplemental {
1.1391 raeburn 19019: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
19020: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
19021: my $mapnum;
19022: if ($suppmap eq 'supplemental.sequence') {
19023: $mapnum = 0;
19024: } else {
19025: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
19026: }
1.1143 raeburn 19027: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
19028: if ($fatal) {
19029: $errors ++;
19030: } else {
1.1389 raeburn 19031: my @order = @LONCAPA::map::order;
19032: if (@order > 0) {
19033: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 19034: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 19035: foreach my $idx (@order) {
19036: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 19037: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 19038: my $id = $mapnum.':'.$idx;
19039: push(@{$suppids->{$src}},$id);
19040: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
19041: $hiddensupp->{$id} = 1;
19042: }
1.1146 raeburn 19043: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 19044: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
19045: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 19046: } else {
1.1391 raeburn 19047: my $allowed;
19048: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
19049: $allowed = 1;
19050: } elsif ($possdel) {
19051: foreach my $item (@{$suppids->{$src}}) {
19052: next if ($item eq $id);
19053: unless ($hiddensupp->{$item}) {
19054: $allowed = 1;
19055: last;
19056: }
19057: }
19058: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
19059: &Apache::lonnet::delenv('httpref.'.$src);
19060: }
19061: }
19062: if ($allowed && (!exists($env{'httpref.'.$src}))) {
19063: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 19064: }
1.1143 raeburn 19065: }
19066: }
19067: }
19068: }
19069: }
19070: }
1.1391 raeburn 19071: return $errors;
19072: }
19073:
19074: sub set_supp_httprefs {
19075: my ($cnum,$cdom,$supplemental,$possdel) = @_;
19076: if (ref($supplemental) eq 'HASH') {
19077: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
19078: foreach my $src (keys(%{$supplemental->{'ids'}})) {
19079: next if ($src =~ /\.sequence$/);
19080: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
19081: my $allowed;
19082: if ($env{'request.role.adv'}) {
19083: $allowed = 1;
19084: } else {
19085: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
19086: unless ($supplemental->{'hidden'}->{$id}) {
19087: $allowed = 1;
19088: last;
19089: }
19090: }
19091: }
19092: if (exists($env{'httpref.'.$src})) {
19093: if ($possdel) {
19094: unless ($allowed) {
19095: &Apache::lonnet::delenv('httpref.'.$src);
19096: }
19097: }
19098: } elsif ($allowed) {
19099: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
19100: }
19101: }
19102: }
19103: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19104: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19105: }
19106: }
19107: }
19108: }
19109:
19110: sub get_supp_parameter {
19111: my ($resparm,$name)=@_;
19112: return if ($resparm eq '');
19113: my $value=undef;
19114: my $ptype=undef;
19115: foreach (split('&&&',$resparm)) {
19116: my ($thistype,$thisname,$thisvalue)=split('___',$_);
19117: if ($thisname eq $name) {
19118: $value=$thisvalue;
19119: $ptype=$thistype;
19120: }
19121: }
19122: return $value;
1.1143 raeburn 19123: }
19124:
1.1101 raeburn 19125: sub symb_to_docspath {
1.1267 raeburn 19126: my ($symb,$navmapref) = @_;
19127: return unless ($symb && ref($navmapref));
1.1101 raeburn 19128: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
19129: if ($resurl=~/\.(sequence|page)$/) {
19130: $mapurl=$resurl;
19131: } elsif ($resurl eq 'adm/navmaps') {
19132: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
19133: }
19134: my $mapresobj;
1.1267 raeburn 19135: unless (ref($$navmapref)) {
19136: $$navmapref = Apache::lonnavmaps::navmap->new();
19137: }
19138: if (ref($$navmapref)) {
19139: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 19140: }
19141: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
19142: my $type=$2;
19143: my $path;
19144: if (ref($mapresobj)) {
19145: my $pcslist = $mapresobj->map_hierarchy();
19146: if ($pcslist ne '') {
19147: foreach my $pc (split(/,/,$pcslist)) {
19148: next if ($pc <= 1);
1.1267 raeburn 19149: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 19150: if (ref($res)) {
19151: my $thisurl = $res->src();
19152: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
19153: my $thistitle = $res->title();
19154: $path .= '&'.
19155: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 19156: &escape($thistitle).
1.1101 raeburn 19157: ':'.$res->randompick().
19158: ':'.$res->randomout().
19159: ':'.$res->encrypted().
19160: ':'.$res->randomorder().
19161: ':'.$res->is_page();
19162: }
19163: }
19164: }
19165: $path =~ s/^\&//;
19166: my $maptitle = $mapresobj->title();
19167: if ($mapurl eq 'default') {
1.1129 raeburn 19168: $maptitle = 'Main Content';
1.1101 raeburn 19169: }
19170: $path .= (($path ne '')? '&' : '').
19171: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19172: &escape($maptitle).
1.1101 raeburn 19173: ':'.$mapresobj->randompick().
19174: ':'.$mapresobj->randomout().
19175: ':'.$mapresobj->encrypted().
19176: ':'.$mapresobj->randomorder().
19177: ':'.$mapresobj->is_page();
19178: } else {
19179: my $maptitle = &Apache::lonnet::gettitle($mapurl);
19180: my $ispage = (($type eq 'page')? 1 : '');
19181: if ($mapurl eq 'default') {
1.1129 raeburn 19182: $maptitle = 'Main Content';
1.1101 raeburn 19183: }
19184: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19185: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 19186: }
19187: unless ($mapurl eq 'default') {
19188: $path = 'default&'.
1.1146 raeburn 19189: &escape('Main Content').
1.1101 raeburn 19190: ':::::&'.$path;
19191: }
19192: return $path;
19193: }
19194:
1.1393 raeburn 19195: sub validate_folderpath {
19196: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
19197: if ($env{'form.folderpath'} ne '') {
19198: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 19199: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 19200: for (my $i=0; $i<@items; $i++) {
19201: my $odd = $i%2;
19202: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
19203: $badpath = 1;
1.1394 raeburn 19204: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 19205: my $idx = $i-1;
1.1394 raeburn 19206: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
19207: my $esc_name = $1;
19208: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
19209: $supppath .= '&'.$esc_name;
19210: $changed = 1;
19211: } else {
19212: $supppath .= '&'.$items[$i];
19213: }
19214: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
19215: $changed = 1;
1.1393 raeburn 19216: my $is_hidden;
19217: unless ($got_supp) {
1.1395 raeburn 19218: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 19219: if (ref($supplemental) eq 'HASH') {
19220: if (ref($supplemental->{'hidden'}) eq 'HASH') {
19221: %supphidden = %{$supplemental->{'hidden'}};
19222: }
19223: if (ref($supplemental->{'ids'}) eq 'HASH') {
19224: %suppids = %{$supplemental->{'ids'}};
19225: }
19226: }
19227: $got_supp = 1;
19228: }
19229: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
19230: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
19231: if ($supphidden{$mapid}) {
19232: $is_hidden = 1;
19233: }
19234: }
1.1394 raeburn 19235: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
19236: } else {
19237: $supppath .= '&'.$items[$i];
1.1393 raeburn 19238: }
19239: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
19240: $badpath = 1;
1.1394 raeburn 19241: } elsif ($supplementalflag) {
1.1393 raeburn 19242: $supppath .= '&'.$items[$i];
19243: }
19244: last if ($badpath);
19245: }
19246: if ($badpath) {
19247: delete($env{'form.folderpath'});
1.1394 raeburn 19248: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 19249: $supppath =~ s/^\&//;
19250: $env{'form.folderpath'} = $supppath;
19251: }
19252: }
19253: return;
19254: }
19255:
1.1094 raeburn 19256: sub captcha_display {
1.1327 raeburn 19257: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19258: my ($output,$error);
1.1234 raeburn 19259: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 19260: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19261: if ($captcha eq 'original') {
1.1094 raeburn 19262: $output = &create_captcha();
19263: unless ($output) {
1.1172 raeburn 19264: $error = 'captcha';
1.1094 raeburn 19265: }
19266: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19267: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 19268: unless ($output) {
1.1172 raeburn 19269: $error = 'recaptcha';
1.1094 raeburn 19270: }
19271: }
1.1234 raeburn 19272: return ($output,$error,$captcha,$version);
1.1094 raeburn 19273: }
19274:
19275: sub captcha_response {
1.1327 raeburn 19276: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19277: my ($captcha_chk,$captcha_error);
1.1327 raeburn 19278: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19279: if ($captcha eq 'original') {
1.1094 raeburn 19280: ($captcha_chk,$captcha_error) = &check_captcha();
19281: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19282: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 19283: } else {
19284: $captcha_chk = 1;
19285: }
19286: return ($captcha_chk,$captcha_error);
19287: }
19288:
19289: sub get_captcha_config {
1.1327 raeburn 19290: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 19291: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 19292: my $hostname = &Apache::lonnet::hostname($lonhost);
19293: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
19294: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 19295: if ($context eq 'usercreation') {
19296: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
19297: if (ref($domconfig{$context}) eq 'HASH') {
19298: $hashtocheck = $domconfig{$context}{'cancreate'};
19299: if (ref($hashtocheck) eq 'HASH') {
19300: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
19301: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
19302: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
19303: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
19304: }
19305: if ($privkey && $pubkey) {
19306: $captcha = 'recaptcha';
1.1234 raeburn 19307: $version = $hashtocheck->{'recaptchaversion'};
19308: if ($version ne '2') {
19309: $version = 1;
19310: }
1.1095 raeburn 19311: } else {
19312: $captcha = 'original';
19313: }
19314: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19315: $captcha = 'original';
19316: }
1.1094 raeburn 19317: }
1.1095 raeburn 19318: } else {
19319: $captcha = 'captcha';
19320: }
19321: } elsif ($context eq 'login') {
19322: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19323: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19324: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19325: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19326: if ($privkey && $pubkey) {
19327: $captcha = 'recaptcha';
1.1234 raeburn 19328: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19329: if ($version ne '2') {
19330: $version = 1;
19331: }
1.1095 raeburn 19332: } else {
19333: $captcha = 'original';
1.1094 raeburn 19334: }
1.1095 raeburn 19335: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19336: $captcha = 'original';
1.1094 raeburn 19337: }
1.1327 raeburn 19338: } elsif ($context eq 'passwords') {
19339: if ($dom_in_effect) {
19340: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19341: if ($passwdconf{'captcha'} eq 'recaptcha') {
19342: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19343: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19344: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19345: }
19346: if ($privkey && $pubkey) {
19347: $captcha = 'recaptcha';
19348: $version = $passwdconf{'recaptchaversion'};
19349: if ($version ne '2') {
19350: $version = 1;
19351: }
19352: } else {
19353: $captcha = 'original';
19354: }
19355: } elsif ($passwdconf{'captcha'} ne 'notused') {
19356: $captcha = 'original';
19357: }
19358: }
19359: }
1.1234 raeburn 19360: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19361: }
19362:
19363: sub create_captcha {
19364: my %captcha_params = &captcha_settings();
19365: my ($output,$maxtries,$tries) = ('',10,0);
19366: while ($tries < $maxtries) {
19367: $tries ++;
19368: my $captcha = Authen::Captcha->new (
19369: output_folder => $captcha_params{'output_dir'},
19370: data_folder => $captcha_params{'db_dir'},
19371: );
19372: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19373:
19374: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19375: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19376: '<span class="LC_nobreak">'.
1.1094 raeburn 19377: &mt('Type in the letters/numbers shown below').' '.
1.1390 raeburn 19378: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1367 raeburn 19379: '</span><br />'.
1.1176 raeburn 19380: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19381: last;
19382: }
19383: }
1.1323 raeburn 19384: if ($output eq '') {
19385: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19386: }
1.1094 raeburn 19387: return $output;
19388: }
19389:
19390: sub captcha_settings {
19391: my %captcha_params = (
19392: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19393: www_output_dir => "/captchaspool",
19394: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19395: numchars => '5',
19396: );
19397: return %captcha_params;
19398: }
19399:
19400: sub check_captcha {
19401: my ($captcha_chk,$captcha_error);
19402: my $code = $env{'form.code'};
19403: my $md5sum = $env{'form.crypt'};
19404: my %captcha_params = &captcha_settings();
19405: my $captcha = Authen::Captcha->new(
19406: output_folder => $captcha_params{'output_dir'},
19407: data_folder => $captcha_params{'db_dir'},
19408: );
1.1109 raeburn 19409: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19410: my %captcha_hash = (
19411: 0 => 'Code not checked (file error)',
19412: -1 => 'Failed: code expired',
19413: -2 => 'Failed: invalid code (not in database)',
19414: -3 => 'Failed: invalid code (code does not match crypt)',
19415: );
19416: if ($captcha_chk != 1) {
19417: $captcha_error = $captcha_hash{$captcha_chk}
19418: }
19419: return ($captcha_chk,$captcha_error);
19420: }
19421:
19422: sub create_recaptcha {
1.1234 raeburn 19423: my ($pubkey,$version) = @_;
19424: if ($version >= 2) {
1.1367 raeburn 19425: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19426: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19427: } else {
19428: my $use_ssl;
19429: if ($ENV{'SERVER_PORT'} == 443) {
19430: $use_ssl = 1;
19431: }
19432: my $captcha = Captcha::reCAPTCHA->new;
19433: return $captcha->get_options_setter({theme => 'white'})."\n".
19434: $captcha->get_html($pubkey,undef,$use_ssl).
19435: &mt('If the text is hard to read, [_1] will replace them.',
19436: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19437: '<br /><br />';
19438: }
1.1094 raeburn 19439: }
19440:
19441: sub check_recaptcha {
1.1234 raeburn 19442: my ($privkey,$version) = @_;
1.1094 raeburn 19443: my $captcha_chk;
1.1350 raeburn 19444: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19445: if ($version >= 2) {
19446: my %info = (
19447: secret => $privkey,
19448: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19449: remoteip => $ip,
1.1234 raeburn 19450: );
1.1280 raeburn 19451: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19452: $request->content(join('&',map {
19453: my $name = escape($_);
19454: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19455: ? join("&$name=", map {escape($_) } @{$info{$_}})
19456: : &escape($info{$_}) );
19457: } keys(%info)));
19458: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19459: if ($response->is_success) {
19460: my $data = JSON::DWIW->from_json($response->decoded_content);
19461: if (ref($data) eq 'HASH') {
19462: if ($data->{'success'}) {
19463: $captcha_chk = 1;
19464: }
19465: }
19466: }
19467: } else {
19468: my $captcha = Captcha::reCAPTCHA->new;
19469: my $captcha_result =
19470: $captcha->check_answer(
19471: $privkey,
1.1350 raeburn 19472: $ip,
1.1234 raeburn 19473: $env{'form.recaptcha_challenge_field'},
19474: $env{'form.recaptcha_response_field'},
19475: );
19476: if ($captcha_result->{is_valid}) {
19477: $captcha_chk = 1;
19478: }
1.1094 raeburn 19479: }
19480: return $captcha_chk;
19481: }
19482:
1.1174 raeburn 19483: sub emailusername_info {
1.1244 raeburn 19484: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19485: my %titles = &Apache::lonlocal::texthash (
19486: lastname => 'Last Name',
19487: firstname => 'First Name',
19488: institution => 'School/college/university',
19489: location => "School's city, state/province, country",
19490: web => "School's web address",
19491: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19492: id => 'Student/Employee ID',
1.1174 raeburn 19493: );
19494: return (\@fields,\%titles);
19495: }
19496:
1.1161 raeburn 19497: sub cleanup_html {
19498: my ($incoming) = @_;
19499: my $outgoing;
19500: if ($incoming ne '') {
19501: $outgoing = $incoming;
19502: $outgoing =~ s/;/;/g;
19503: $outgoing =~ s/\#/#/g;
19504: $outgoing =~ s/\&/&/g;
19505: $outgoing =~ s/</</g;
19506: $outgoing =~ s/>/>/g;
19507: $outgoing =~ s/\(/(/g;
19508: $outgoing =~ s/\)/)/g;
19509: $outgoing =~ s/"/"/g;
19510: $outgoing =~ s/'/'/g;
19511: $outgoing =~ s/\$/$/g;
19512: $outgoing =~ s{/}{/}g;
19513: $outgoing =~ s/=/=/g;
19514: $outgoing =~ s/\\/\/g
19515: }
19516: return $outgoing;
19517: }
19518:
1.1190 musolffc 19519: # Checks for critical messages and returns a redirect url if one exists.
19520: # $interval indicates how often to check for messages.
1.1282 raeburn 19521: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19522: sub critical_redirect {
1.1282 raeburn 19523: my ($interval,$context) = @_;
1.1356 raeburn 19524: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19525: return ();
19526: }
1.1190 musolffc 19527: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19528: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19529: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19530: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19531: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19532: if ($blocked) {
19533: my $checkrole = "cm./$cdom/$cnum";
19534: if ($env{'request.course.sec'} ne '') {
19535: $checkrole .= "/$env{'request.course.sec'}";
19536: }
19537: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19538: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19539: return;
19540: }
19541: }
19542: }
1.1190 musolffc 19543: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19544: $env{'user.name'});
19545: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19546: my $redirecturl;
1.1190 musolffc 19547: if ($what[0]) {
1.1356 raeburn 19548: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19549: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19550: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19551: return (1, $url);
1.1190 musolffc 19552: }
1.1191 raeburn 19553: }
19554: }
19555: return ();
1.1190 musolffc 19556: }
19557:
1.1174 raeburn 19558: # Use:
19559: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19560: #
19561: ##################################################
19562: # password associated functions #
19563: ##################################################
19564: sub des_keys {
19565: # Make a new key for DES encryption.
19566: # Each key has two parts which are returned separately.
19567: # Please note: Each key must be passed through the &hex function
19568: # before it is output to the web browser. The hex versions cannot
19569: # be used to decrypt.
19570: my @hexstr=('0','1','2','3','4','5','6','7',
19571: '8','9','a','b','c','d','e','f');
19572: my $lkey='';
19573: for (0..7) {
19574: $lkey.=$hexstr[rand(15)];
19575: }
19576: my $ukey='';
19577: for (0..7) {
19578: $ukey.=$hexstr[rand(15)];
19579: }
19580: return ($lkey,$ukey);
19581: }
19582:
19583: sub des_decrypt {
19584: my ($key,$cyphertext) = @_;
19585: my $keybin=pack("H16",$key);
19586: my $cypher;
19587: if ($Crypt::DES::VERSION>=2.03) {
19588: $cypher=new Crypt::DES $keybin;
19589: } else {
19590: $cypher=new DES $keybin;
19591: }
1.1233 raeburn 19592: my $plaintext='';
19593: my $cypherlength = length($cyphertext);
19594: my $numchunks = int($cypherlength/32);
19595: for (my $j=0; $j<$numchunks; $j++) {
19596: my $start = $j*32;
19597: my $cypherblock = substr($cyphertext,$start,32);
19598: my $chunk =
19599: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19600: $chunk .=
19601: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19602: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19603: $plaintext .= $chunk;
19604: }
1.1174 raeburn 19605: return $plaintext;
19606: }
19607:
1.1344 raeburn 19608: sub get_requested_shorturls {
1.1309 raeburn 19609: my ($cdom,$cnum,$navmap) = @_;
19610: return unless (ref($navmap));
1.1344 raeburn 19611: my ($numnew,$errors);
1.1309 raeburn 19612: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19613: if (@toshorten) {
19614: my (%maps,%resources,%titles);
19615: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19616: 'shorturls',$cdom,$cnum);
19617: if (keys(%resources)) {
1.1344 raeburn 19618: my %tocreate;
1.1309 raeburn 19619: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19620: my $symb = $resources{$item};
19621: if ($symb) {
19622: $tocreate{$cnum.'&'.$symb} = 1;
19623: }
19624: }
1.1344 raeburn 19625: if (keys(%tocreate)) {
19626: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19627: \%tocreate);
19628: }
1.1309 raeburn 19629: }
1.1344 raeburn 19630: }
19631: return ($numnew,$errors);
19632: }
19633:
19634: sub make_short_symbs {
19635: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19636: my ($numnew,@errors);
19637: if (ref($tocreateref) eq 'HASH') {
19638: my %tocreate = %{$tocreateref};
1.1309 raeburn 19639: if (keys(%tocreate)) {
19640: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19641: my $su = Short::URL->new(no_vowels => 1);
19642: my $init = '';
19643: my (%newunique,%addcourse,%courseonly,%failed);
19644: # get lock on tiny db
19645: my $now = time;
1.1344 raeburn 19646: if ($lockuser eq '') {
19647: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
19648: }
1.1309 raeburn 19649: my $lockhash = {
1.1344 raeburn 19650: "lock\0$now" => $lockuser,
1.1309 raeburn 19651: };
19652: my $tries = 0;
19653: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19654: my ($code,$error);
19655: while (($gotlock ne 'ok') && ($tries<3)) {
19656: $tries ++;
19657: sleep 1;
1.1319 raeburn 19658: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 19659: }
19660: if ($gotlock eq 'ok') {
19661: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19662: \%addcourse,\%courseonly,\%failed);
19663: if (keys(%failed)) {
19664: my $numfailed = scalar(keys(%failed));
19665: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19666: }
19667: if (keys(%newunique)) {
19668: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19669: if ($putres eq 'ok') {
19670: $numnew = scalar(keys(%newunique));
19671: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19672: unless ($newputres eq 'ok') {
19673: push(@errors,&mt('error: could not store course look-up of short URLs'));
19674: }
19675: } else {
19676: push(@errors,&mt('error: could not store unique six character URLs'));
19677: }
19678: }
19679: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19680: unless ($dellockres eq 'ok') {
19681: push(@errors,&mt('error: could not release lockfile'));
19682: }
19683: } else {
19684: push(@errors,&mt('error: could not obtain lockfile'));
19685: }
19686: if (keys(%courseonly)) {
19687: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19688: if ($result ne 'ok') {
19689: push(@errors,&mt('error: could not update course look-up of short URLs'));
19690: }
19691: }
19692: }
19693: }
19694: return ($numnew,\@errors);
19695: }
19696:
19697: sub shorten_symbs {
19698: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19699: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19700: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19701: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19702: my (%possibles,%collisions);
19703: foreach my $key (keys(%{$tocreate})) {
19704: my $num = String::CRC32::crc32($key);
19705: my $tiny = $su->encode($num,$init);
19706: if ($tiny) {
19707: $possibles{$tiny} = $key;
19708: }
19709: }
19710: if (!$init) {
19711: $init = 1;
19712: } else {
19713: $init ++;
19714: }
19715: if (keys(%possibles)) {
19716: my @posstiny = keys(%possibles);
19717: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19718: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19719: if (keys(%currtiny)) {
19720: foreach my $key (keys(%currtiny)) {
19721: next if ($currtiny{$key} eq '');
19722: if ($currtiny{$key} eq $possibles{$key}) {
19723: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19724: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19725: $courseonly->{$tsymb} = $key;
19726: }
19727: } else {
19728: $collisions{$possibles{$key}} = 1;
19729: }
19730: delete($possibles{$key});
19731: }
19732: }
19733: foreach my $key (keys(%possibles)) {
19734: $newunique->{$key} = $possibles{$key};
19735: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19736: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19737: $addcourse->{$tsymb} = $key;
19738: }
19739: }
19740: }
19741: if (keys(%collisions)) {
19742: if ($init <5) {
19743: if (!$init) {
19744: $init = 1;
19745: } else {
19746: $init ++;
19747: }
19748: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19749: $newunique,$addcourse,$courseonly,$failed);
19750: } else {
19751: foreach my $key (keys(%collisions)) {
19752: $failed->{$key} = 1;
19753: }
19754: }
19755: }
19756: return $init;
19757: }
19758:
1.1328 raeburn 19759: sub is_nonframeable {
1.1329 raeburn 19760: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19761: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 19762: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 19763:
19764: $remprotocol = lc($remprotocol);
19765: $remhost = lc($remhost);
19766: my $remport = 80;
19767: if ($remprotocol eq 'https') {
19768: $remport = 443;
19769: }
1.1330 raeburn 19770: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 19771: if ($cached) {
19772: unless ($nocache) {
19773: if ($result) {
19774: return 1;
19775: } else {
19776: return 0;
19777: }
19778: }
19779: }
1.1328 raeburn 19780: my $uselink;
19781: my $request = new HTTP::Request('HEAD',$url);
19782: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
19783: if ($response->is_success()) {
19784: my $secpolicy = lc($response->header('content-security-policy'));
19785: my $xframeop = lc($response->header('x-frame-options'));
19786: $secpolicy =~ s/^\s+|\s+$//g;
19787: $xframeop =~ s/^\s+|\s+$//g;
19788: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 19789: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 19790: my ($origin,$protocol,$port);
19791: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19792: $port = $ENV{'SERVER_PORT'};
19793: } else {
19794: $port = 80;
19795: }
19796: if ($absolute eq '') {
19797: $protocol = 'http:';
19798: if ($port == 443) {
19799: $protocol = 'https:';
19800: }
19801: $origin = $protocol.'//'.lc($hostname);
19802: } else {
19803: $origin = lc($absolute);
19804: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19805: }
19806: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19807: my $framepolicy = $1;
19808: $framepolicy =~ s/^\s+|\s+$//g;
19809: my @policies = split(/\s+/,$framepolicy);
19810: if (@policies) {
19811: if (grep(/^\Q'none'\E$/,@policies)) {
19812: $uselink = 1;
19813: } else {
19814: $uselink = 1;
19815: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19816: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19817: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19818: undef($uselink);
19819: }
19820: if ($uselink) {
19821: if (grep(/^\Q'self'\E$/,@policies)) {
19822: if (($origin ne '') && ($remotehost eq $origin)) {
19823: undef($uselink);
19824: }
19825: }
19826: }
19827: if ($uselink) {
19828: my @possok;
19829: if ($ip ne '') {
19830: push(@possok,$ip);
19831: }
19832: my $hoststr = '';
19833: foreach my $part (reverse(split(/\./,$hostname))) {
19834: if ($hoststr eq '') {
19835: $hoststr = $part;
19836: } else {
19837: $hoststr = "$part.$hoststr";
19838: }
19839: if ($hoststr eq $hostname) {
19840: push(@possok,$hostname);
19841: } else {
19842: push(@possok,"*.$hoststr");
19843: }
19844: }
19845: if (@possok) {
19846: foreach my $poss (@possok) {
19847: last if (!$uselink);
19848: foreach my $policy (@policies) {
19849: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19850: undef($uselink);
19851: last;
19852: }
19853: }
19854: }
19855: }
19856: }
19857: }
19858: }
19859: } elsif ($xframeop ne '') {
19860: $uselink = 1;
19861: my @policies = split(/\s*,\s*/,$xframeop);
19862: if (@policies) {
19863: unless (grep(/^deny$/,@policies)) {
19864: if ($origin ne '') {
19865: if (grep(/^sameorigin$/,@policies)) {
19866: if ($remotehost eq $origin) {
19867: undef($uselink);
19868: }
19869: }
19870: if ($uselink) {
19871: foreach my $policy (@policies) {
19872: if ($policy =~ /^allow-from\s*(.+)$/) {
19873: my $allowfrom = $1;
19874: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19875: undef($uselink);
19876: last;
19877: }
19878: }
19879: }
19880: }
19881: }
19882: }
19883: }
19884: }
19885: }
19886: }
1.1329 raeburn 19887: if ($nocache) {
19888: if ($cached) {
19889: my $devalidate;
19890: if ($uselink && !$result) {
19891: $devalidate = 1;
19892: } elsif (!$uselink && $result) {
19893: $devalidate = 1;
19894: }
19895: if ($devalidate) {
19896: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19897: }
19898: }
19899: } else {
19900: if ($uselink) {
19901: $result = 1;
19902: } else {
19903: $result = 0;
19904: }
19905: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19906: }
1.1328 raeburn 19907: return $uselink;
19908: }
19909:
1.1359 raeburn 19910: sub page_menu {
19911: my ($menucolls,$menunum) = @_;
19912: my %menu;
19913: foreach my $item (split(/;/,$menucolls)) {
19914: my ($num,$value) = split(/\%/,$item);
19915: if ($num eq $menunum) {
19916: my @entries = split(/\&/,$value);
19917: foreach my $entry (@entries) {
19918: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19919: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19920: $menu{$name} = $fields;
19921: } else {
19922: my @shown;
19923: if ($fields =~ /,/) {
19924: @shown = split(/,/,$fields);
19925: } else {
19926: @shown = ($fields);
19927: }
19928: if (@shown) {
19929: foreach my $field (@shown) {
19930: next if ($field eq '');
19931: $menu{$field} = 1;
19932: }
19933: }
19934: }
19935: }
19936: }
19937: }
19938: return %menu;
19939: }
19940:
1.112 bowersj2 19941: 1;
19942: __END__;
1.41 ng 19943:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>