Annotation of loncom/interface/loncommon.pm, revision 1.1458
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1458 ! raeburn 4: # $Id: loncommon.pm,v 1.1457 2025/02/18 02:38: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,
1.1450 raeburn 1177: $suffix,
1178: $haslabel
1.36 matthew 1179: ) = @_;
1180: my $second = "document.$formname.$secondselectname";
1181: my $first = "document.$formname.$firstselectname";
1182: # output the javascript to do the changing
1183: my $result = '';
1.776 bisitz 1184: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1185: $result.="// <![CDATA[\n";
1.1245 raeburn 1186: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1187: $" = '","';
1188: my $debug = '';
1189: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1190: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1191: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1192: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1193: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1194: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1195: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1196: @s2values = @{$hashref->{$s1}->{'order'}};
1197: }
1.36 matthew 1198: $result.="\"@s2values\");\n";
1.1245 raeburn 1199: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1200: my @s2texts;
1201: foreach my $value (@s2values) {
1.1263 raeburn 1202: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1203: }
1204: $result.="\"@s2texts\");\n";
1205: }
1206: $"=' ';
1207: $result.= <<"END";
1208:
1.1245 raeburn 1209: function select1${suffix}_changed() {
1.36 matthew 1210: // Determine new choice
1.1245 raeburn 1211: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1212: // update select2
1.1245 raeburn 1213: var values = select2data${suffix}[newvalue].values;
1214: var texts = select2data${suffix}[newvalue].texts;
1215: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1216: var i;
1217: // out with the old
1.1245 raeburn 1218: $second.options.length = 0;
1219: // in with the new
1.36 matthew 1220: for (i=0;i<values.length; i++) {
1221: $second.options[i] = new Option(values[i]);
1.143 matthew 1222: $second.options[i].value = values[i];
1.36 matthew 1223: $second.options[i].text = texts[i];
1224: if (values[i] == select2def) {
1225: $second.options[i].selected = true;
1226: }
1227: }
1228: }
1.824 bisitz 1229: // ]]>
1.36 matthew 1230: </script>
1231: END
1232: # output the initial values for the selection lists
1.1245 raeburn 1233: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1234: my @order = sort(keys(%{$hashref}));
1235: if (ref($menuorder) eq 'ARRAY') {
1236: @order = @{$menuorder};
1237: }
1238: foreach my $value (@order) {
1.36 matthew 1239: $result.=" <option value=\"$value\" ";
1.253 albertel 1240: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1241: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1242: }
1243: $result .= "</select>\n";
1.1450 raeburn 1244: if ($haslabel) {
1245: $result .= '</label>';
1246: }
1.1400 raeburn 1247: my %select2;
1248: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1249: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1250: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1251: }
1252: }
1.1450 raeburn 1253: if ($middletext ne '') {
1.1452 raeburn 1254: $result .= '<label>'.$middletext;
1.1450 raeburn 1255: }
1.1115 raeburn 1256: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1257: if ($onchangesecond) {
1258: $result .= ' onchange="'.$onchangesecond.'"';
1259: }
1260: $result .= ">\n";
1.36 matthew 1261: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1262:
1263: my @secondorder = sort(keys(%select2));
1264: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1265: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1266: }
1267: foreach my $value (@secondorder) {
1.36 matthew 1268: $result.=" <option value=\"$value\" ";
1.253 albertel 1269: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1270: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1271: }
1272: $result .= "</select>\n";
1.1450 raeburn 1273: if ($middletext ne '') {
1274: $result .= '</label>';
1275: }
1.36 matthew 1276: # return $debug;
1277: return $result;
1278: } # end of sub linked_select_forms {
1279:
1.45 matthew 1280: =pod
1.44 bowersj2 1281:
1.1381 raeburn 1282: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1283:
1.112 bowersj2 1284: Returns a string corresponding to an HTML link to the given help
1285: $topic, where $topic corresponds to the name of a .tex file in
1286: /home/httpd/html/adm/help/tex, with underscores replaced by
1287: spaces.
1288:
1289: $text will optionally be linked to the same topic, allowing you to
1290: link text in addition to the graphic. If you do not want to link
1291: text, but wish to specify one of the later parameters, pass an
1292: empty string.
1293:
1294: $stayOnPage is a value that will be interpreted as a boolean. If true,
1295: the link will not open a new window. If false, the link will open
1296: a new window using Javascript. (Default is false.)
1297:
1298: $width and $height are optional numerical parameters that will
1299: override the width and height of the popped up window, which may
1.973 raeburn 1300: be useful for certain help topics with big pictures included.
1301:
1302: $imgid is the id of the img tag used for the help icon. This may be
1303: used in a javascript call to switch the image src. See
1304: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1305:
1.1381 raeburn 1306: $links_target will optionally be set to a target (_top, _parent or _self).
1307:
1.44 bowersj2 1308: =cut
1309:
1310: sub help_open_topic {
1.1381 raeburn 1311: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1312: $text = "" if (not defined $text);
1.44 bowersj2 1313: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1314: $width = 500 if (not defined $width);
1.44 bowersj2 1315: $height = 400 if (not defined $height);
1316: my $filename = $topic;
1317: $filename =~ s/ /_/g;
1318:
1.48 bowersj2 1319: my $template = "";
1320: my $link;
1.572 banghart 1321:
1.159 www 1322: $topic=~s/\W/\_/g;
1.44 bowersj2 1323:
1.572 banghart 1324: if (!$stayOnPage) {
1.1033 www 1325: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1326: } elsif ($stayOnPage eq 'popup') {
1327: $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 1328: } else {
1.48 bowersj2 1329: $link = "/adm/help/${filename}.hlp";
1330: }
1331:
1332: # Add the text
1.1314 raeburn 1333: my $target = ' target="_top"';
1.1381 raeburn 1334: if ($links_target) {
1335: $target = ' target="'.$links_target.'"';
1336: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1337: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1338: $target = '';
1.1378 raeburn 1339: }
1.1380 raeburn 1340: if ($text ne "") {
1.763 bisitz 1341: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1342: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1343: .$text.'</a>';
1.48 bowersj2 1344: }
1345:
1.763 bisitz 1346: # (Always) Add the graphic
1.179 matthew 1347: my $title = &mt('Online Help');
1.667 raeburn 1348: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1349: if ($imgid ne '') {
1350: $imgid = ' id="'.$imgid.'"';
1351: }
1.1314 raeburn 1352: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1353: .'<img src="'.$helpicon.'" border="0"'
1354: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1355: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1356: .' /></a>';
1357: if ($text ne "") {
1358: $template.='</span>';
1359: }
1.44 bowersj2 1360: return $template;
1361:
1.106 bowersj2 1362: }
1363:
1364: # This is a quicky function for Latex cheatsheet editing, since it
1365: # appears in at least four places
1366: sub helpLatexCheatsheet {
1.1037 www 1367: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1368: my $out;
1.106 bowersj2 1369: my $addOther = '';
1.732 raeburn 1370: if ($topic) {
1.1037 www 1371: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1372: }
1373: $out = '<span>' # Start cheatsheet
1374: .$addOther
1375: .'<span>'
1.1037 www 1376: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1377: .'</span> <span>'
1.1037 www 1378: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1379: .'</span>';
1.732 raeburn 1380: unless ($not_author) {
1.1186 kruse 1381: $out .= '<span>'
1382: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1383: .'</span> <span>'
1.1424 raeburn 1384: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.763 bisitz 1385: .'</span>';
1.732 raeburn 1386: }
1.763 bisitz 1387: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1388: return $out;
1.172 www 1389: }
1390:
1.430 albertel 1391: sub general_help {
1392: my $helptopic='Student_Intro';
1393: if ($env{'request.role'}=~/^(ca|au)/) {
1394: $helptopic='Authoring_Intro';
1.907 raeburn 1395: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1396: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1397: } elsif ($env{'request.role'}=~/^dc/) {
1398: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1399: }
1400: return $helptopic;
1401: }
1402:
1403: sub update_help_link {
1404: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1405: my $origurl = $ENV{'REQUEST_URI'};
1406: $origurl=~s|^/~|/priv/|;
1407: my $timestamp = time;
1408: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1409: $$datum = &escape($$datum);
1410: }
1411:
1412: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1413: my $output .= <<"ENDOUTPUT";
1414: <script type="text/javascript">
1.824 bisitz 1415: // <![CDATA[
1.430 albertel 1416: banner_link = '$banner_link';
1.824 bisitz 1417: // ]]>
1.430 albertel 1418: </script>
1419: ENDOUTPUT
1420: return $output;
1421: }
1422:
1423: # now just updates the help link and generates a blue icon
1.193 raeburn 1424: sub help_open_menu {
1.1381 raeburn 1425: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1426: = @_;
1.949 droeschl 1427: $stayOnPage = 1;
1.430 albertel 1428: my $output;
1429: if ($component_help) {
1430: if (!$text) {
1431: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1432: $width,$height,'',$links_target);
1.430 albertel 1433: } else {
1434: my $help_text;
1435: $help_text=&unescape($topic);
1436: $output='<table><tr><td>'.
1437: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1438: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1439: }
1440: }
1441: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1442: return $output.$banner_link;
1443: }
1444:
1445: sub top_nav_help {
1.1369 raeburn 1446: my ($text,$linkattr) = @_;
1.436 albertel 1447: $text = &mt($text);
1.949 droeschl 1448: my $stay_on_page = 1;
1449:
1.1168 raeburn 1450: my ($link,$banner_link);
1451: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1452: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1453: : "javascript:helpMenu('open')";
1454: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1455: }
1.201 raeburn 1456: my $title = &mt('Get help');
1.1168 raeburn 1457: if ($link) {
1458: return <<"END";
1.436 albertel 1459: $banner_link
1.1369 raeburn 1460: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1461: END
1.1168 raeburn 1462: } else {
1463: return ' '.$text.' ';
1464: }
1.436 albertel 1465: }
1466:
1467: sub help_menu_js {
1.1154 raeburn 1468: my ($httphost) = @_;
1.949 droeschl 1469: my $stayOnPage = 1;
1.436 albertel 1470: my $width = 620;
1471: my $height = 600;
1.430 albertel 1472: my $helptopic=&general_help();
1.1154 raeburn 1473: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1474: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1475: my $start_page =
1476: &Apache::loncommon::start_page('Help Menu', undef,
1477: {'frameset' => 1,
1478: 'js_ready' => 1,
1.1154 raeburn 1479: 'use_absolute' => $httphost,
1.331 albertel 1480: 'add_entries' => {
1.1168 raeburn 1481: 'border' => '0',
1.579 raeburn 1482: 'rows' => "110,*",},});
1.331 albertel 1483: my $end_page =
1484: &Apache::loncommon::end_page({'frameset' => 1,
1485: 'js_ready' => 1,});
1486:
1.436 albertel 1487: my $template .= <<"ENDTEMPLATE";
1488: <script type="text/javascript">
1.877 bisitz 1489: // <![CDATA[
1.253 albertel 1490: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1491: var banner_link = '';
1.243 raeburn 1492: function helpMenu(target) {
1493: var caller = this;
1494: if (target == 'open') {
1495: var newWindow = null;
1496: try {
1.262 albertel 1497: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1498: }
1499: catch(error) {
1500: writeHelp(caller);
1501: return;
1502: }
1503: if (newWindow) {
1504: caller = newWindow;
1505: }
1.193 raeburn 1506: }
1.243 raeburn 1507: writeHelp(caller);
1508: return;
1509: }
1510: function writeHelp(caller) {
1.1168 raeburn 1511: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1512: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1513: caller.document.close();
1514: caller.focus();
1.193 raeburn 1515: }
1.877 bisitz 1516: // END LON-CAPA Internal -->
1.253 albertel 1517: // ]]>
1.436 albertel 1518: </script>
1.193 raeburn 1519: ENDTEMPLATE
1520: return $template;
1521: }
1522:
1.172 www 1523: sub help_open_bug {
1524: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1525: unless ($env{'user.adv'}) { return ''; }
1.172 www 1526: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1527: $text = "" if (not defined $text);
1528: $stayOnPage=1;
1.184 albertel 1529: $width = 600 if (not defined $width);
1530: $height = 600 if (not defined $height);
1.172 www 1531:
1532: $topic=~s/\W+/\+/g;
1533: my $link='';
1534: my $template='';
1.379 albertel 1535: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1536: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1537: if (!$stayOnPage)
1538: {
1539: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1540: }
1541: else
1542: {
1543: $link = $url;
1544: }
1.1314 raeburn 1545:
1.1382 raeburn 1546: my $target = '_top';
1547: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1548: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1549: $target = '_blank';
1.1378 raeburn 1550: }
1.1382 raeburn 1551:
1.172 www 1552: # Add the text
1553: if ($text ne "")
1554: {
1555: $template .=
1556: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1557: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1558: }
1559:
1560: # Add the graphic
1.179 matthew 1561: my $title = &mt('Report a Bug');
1.215 albertel 1562: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1563: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1564: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1565: ENDTEMPLATE
1566: if ($text ne '') { $template.='</td></tr></table>' };
1567: return $template;
1568:
1569: }
1570:
1571: sub help_open_faq {
1572: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1573: unless ($env{'user.adv'}) { return ''; }
1.172 www 1574: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1575: $text = "" if (not defined $text);
1576: $stayOnPage=1;
1577: $width = 350 if (not defined $width);
1578: $height = 400 if (not defined $height);
1579:
1580: $topic=~s/\W+/\+/g;
1581: my $link='';
1582: my $template='';
1583: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1584: if (!$stayOnPage)
1585: {
1586: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1587: }
1588: else
1589: {
1590: $link = $url;
1591: }
1592:
1593: # Add the text
1594: if ($text ne "")
1595: {
1596: $template .=
1.173 www 1597: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1598: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1599: }
1600:
1601: # Add the graphic
1.179 matthew 1602: my $title = &mt('View the FAQ');
1.215 albertel 1603: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1604: $template .= <<"ENDTEMPLATE";
1.436 albertel 1605: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1606: ENDTEMPLATE
1607: if ($text ne '') { $template.='</td></tr></table>' };
1608: return $template;
1609:
1.44 bowersj2 1610: }
1.37 matthew 1611:
1.180 matthew 1612: ###############################################################
1613: ###############################################################
1614:
1.45 matthew 1615: =pod
1616:
1.648 raeburn 1617: =item * &change_content_javascript():
1.256 matthew 1618:
1619: This and the next function allow you to create small sections of an
1620: otherwise static HTML page that you can update on the fly with
1621: Javascript, even in Netscape 4.
1622:
1623: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1624: must be written to the HTML page once. It will prove the Javascript
1625: function "change(name, content)". Calling the change function with the
1626: name of the section
1627: you want to update, matching the name passed to C<changable_area>, and
1628: the new content you want to put in there, will put the content into
1629: that area.
1630:
1631: B<Note>: Netscape 4 only reserves enough space for the changable area
1632: to contain room for the original contents. You need to "make space"
1633: for whatever changes you wish to make, and be B<sure> to check your
1634: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1635: it's adequate for updating a one-line status display, but little more.
1636: This script will set the space to 100% width, so you only need to
1637: worry about height in Netscape 4.
1638:
1639: Modern browsers are much less limiting, and if you can commit to the
1640: user not using Netscape 4, this feature may be used freely with
1641: pretty much any HTML.
1642:
1643: =cut
1644:
1645: sub change_content_javascript {
1646: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1647: if ($env{'browser.type'} eq 'netscape' &&
1648: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1649: return (<<NETSCAPE4);
1650: function change(name, content) {
1651: doc = document.layers[name+"___escape"].layers[0].document;
1652: doc.open();
1653: doc.write(content);
1654: doc.close();
1655: }
1656: NETSCAPE4
1657: } else {
1658: # Otherwise, we need to use semi-standards-compliant code
1659: # (technically, "innerHTML" isn't standard but the equivalent
1660: # is really scary, and every useful browser supports it
1661: return (<<DOMBASED);
1662: function change(name, content) {
1663: element = document.getElementById(name);
1664: element.innerHTML = content;
1665: }
1666: DOMBASED
1667: }
1668: }
1669:
1670: =pod
1671:
1.648 raeburn 1672: =item * &changable_area($name,$origContent):
1.256 matthew 1673:
1674: This provides a "changable area" that can be modified on the fly via
1675: the Javascript code provided in C<change_content_javascript>. $name is
1676: the name you will use to reference the area later; do not repeat the
1677: same name on a given HTML page more then once. $origContent is what
1678: the area will originally contain, which can be left blank.
1679:
1680: =cut
1681:
1682: sub changable_area {
1683: my ($name, $origContent) = @_;
1684:
1.258 albertel 1685: if ($env{'browser.type'} eq 'netscape' &&
1686: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1687: # If this is netscape 4, we need to use the Layer tag
1688: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1689: } else {
1690: return "<span id='$name'>$origContent</span>";
1691: }
1692: }
1693:
1694: =pod
1695:
1.648 raeburn 1696: =item * &viewport_geometry_js
1.590 raeburn 1697:
1698: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1699:
1700: =cut
1701:
1702:
1703: sub viewport_geometry_js {
1704: return <<"GEOMETRY";
1705: var Geometry = {};
1706: function init_geometry() {
1707: if (Geometry.init) { return };
1708: Geometry.init=1;
1709: if (window.innerHeight) {
1710: Geometry.getViewportHeight = function() { return window.innerHeight; };
1711: Geometry.getViewportWidth = function() { return window.innerWidth; };
1712: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1713: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1714: }
1715: else if (document.documentElement && document.documentElement.clientHeight) {
1716: Geometry.getViewportHeight =
1717: function() { return document.documentElement.clientHeight; };
1718: Geometry.getViewportWidth =
1719: function() { return document.documentElement.clientWidth; };
1720:
1721: Geometry.getHorizontalScroll =
1722: function() { return document.documentElement.scrollLeft; };
1723: Geometry.getVerticalScroll =
1724: function() { return document.documentElement.scrollTop; };
1725: }
1726: else if (document.body.clientHeight) {
1727: Geometry.getViewportHeight =
1728: function() { return document.body.clientHeight; };
1729: Geometry.getViewportWidth =
1730: function() { return document.body.clientWidth; };
1731: Geometry.getHorizontalScroll =
1732: function() { return document.body.scrollLeft; };
1733: Geometry.getVerticalScroll =
1734: function() { return document.body.scrollTop; };
1735: }
1736: }
1737:
1738: GEOMETRY
1739: }
1740:
1741: =pod
1742:
1.648 raeburn 1743: =item * &viewport_size_js()
1.590 raeburn 1744:
1745: 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.
1746:
1747: =cut
1748:
1749: sub viewport_size_js {
1750: my $geometry = &viewport_geometry_js();
1751: return <<"DIMS";
1752:
1753: $geometry
1754:
1755: function getViewportDims(width,height) {
1756: init_geometry();
1757: width.value = Geometry.getViewportWidth();
1758: height.value = Geometry.getViewportHeight();
1759: return;
1760: }
1761:
1762: DIMS
1763: }
1764:
1765: =pod
1766:
1.648 raeburn 1767: =item * &resize_textarea_js()
1.565 albertel 1768:
1769: emits the needed javascript to resize a textarea to be as big as possible
1770:
1771: creates a function resize_textrea that takes two IDs first should be
1772: the id of the element to resize, second should be the id of a div that
1773: surrounds everything that comes after the textarea, this routine needs
1774: to be attached to the <body> for the onload and onresize events.
1775:
1776: =cut
1777:
1778: sub resize_textarea_js {
1.590 raeburn 1779: my $geometry = &viewport_geometry_js();
1.565 albertel 1780: return <<"RESIZE";
1781: <script type="text/javascript">
1.824 bisitz 1782: // <![CDATA[
1.590 raeburn 1783: $geometry
1.565 albertel 1784:
1.588 albertel 1785: function getX(element) {
1786: var x = 0;
1787: while (element) {
1788: x += element.offsetLeft;
1789: element = element.offsetParent;
1790: }
1791: return x;
1792: }
1793: function getY(element) {
1794: var y = 0;
1795: while (element) {
1796: y += element.offsetTop;
1797: element = element.offsetParent;
1798: }
1799: return y;
1800: }
1801:
1802:
1.565 albertel 1803: function resize_textarea(textarea_id,bottom_id) {
1804: init_geometry();
1805: var textarea = document.getElementById(textarea_id);
1806: //alert(textarea);
1807:
1.588 albertel 1808: var textarea_top = getY(textarea);
1.565 albertel 1809: var textarea_height = textarea.offsetHeight;
1810: var bottom = document.getElementById(bottom_id);
1.588 albertel 1811: var bottom_top = getY(bottom);
1.565 albertel 1812: var bottom_height = bottom.offsetHeight;
1813: var window_height = Geometry.getViewportHeight();
1.588 albertel 1814: var fudge = 23;
1.565 albertel 1815: var new_height = window_height-fudge-textarea_top-bottom_height;
1816: if (new_height < 300) {
1817: new_height = 300;
1818: }
1819: textarea.style.height=new_height+'px';
1820: }
1.824 bisitz 1821: // ]]>
1.565 albertel 1822: </script>
1823: RESIZE
1824:
1825: }
1826:
1.1205 golterma 1827: sub colorfuleditor_js {
1.1248 raeburn 1828: my $browse_or_search;
1829: my $respath;
1830: my ($cnum,$cdom) = &crsauthor_url();
1831: if ($cnum) {
1832: $respath = "/res/$cdom/$cnum/";
1833: my %js_lt = &Apache::lonlocal::texthash(
1834: sunm => 'Sub-directory name',
1835: save => 'Save page to make this permanent',
1836: );
1837: &js_escape(\%js_lt);
1.1400 raeburn 1838: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1839: $browse_or_search = <<"END";
1840:
1.1400 raeburn 1841: $showfile_js
1842:
1.1248 raeburn 1843: function toggleChooser(form,element,titleid,only,search) {
1844: var disp = 'none';
1845: if (document.getElementById('chooser_'+element)) {
1846: var curr = document.getElementById('chooser_'+element).style.display;
1847: if (curr == 'none') {
1848: disp='inline';
1849: if (form.elements['chooser_'+element].length) {
1850: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1851: form.elements['chooser_'+element][i].checked = false;
1852: }
1853: }
1854: toggleResImport(form,element);
1855: }
1856: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1857: var dirsel = '';
1858: var filesel = '';
1859: if (document.getElementById('chooser_'+element+'_crsres')) {
1860: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1861: if (currcrsres == 'none') {
1862: dirsel = 'coursepath_'+element;
1863: var filesel = 'coursefile_'+element;
1864: var include;
1865: if (document.getElementById('crsres_include_'+element)) {
1866: include = document.getElementById('crsres_include_'+element).value;
1867: }
1.1402 raeburn 1868: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 1869: }
1870: }
1871: if (document.getElementById('chooser_'+element+'_upload')) {
1872: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1873: if (currcrsupload == 'none') {
1874: dirsel = 'crsauthorpath_'+element;
1875: filesel = '';
1.1402 raeburn 1876: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 1877: }
1878: }
1.1248 raeburn 1879: }
1880: }
1881:
1.1400 raeburn 1882: function toggleCrsFile(form,element) {
1.1248 raeburn 1883: if (document.getElementById('chooser_'+element+'_crsres')) {
1884: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1885: if (curr == 'none') {
1.1400 raeburn 1886: if (document.getElementById('coursepath_'+element)) {
1887: var numdirs;
1888: if (document.getElementById('coursepath_'+element).length) {
1889: numdirs = document.getElementById('coursepath_'+element).length;
1890: }
1.1402 raeburn 1891: if ((document.getElementById('hascrsres_'+element)) &&
1892: (document.getElementById('nocrsres_'+element))) {
1893: if (numdirs) {
1894: document.getElementById('hascrsres_'+element).style.display='inline-block';
1895: document.getElementById('nocrsres_'+element).style.display='none';
1896: } else {
1897: document.getElementById('hascrsres_'+element).style.display='none';
1898: document.getElementById('nocrsres_'+element).style.display='inline-block';
1899: }
1900: }
1.1248 raeburn 1901: form.elements['coursepath_'+element].selectedIndex = 0;
1902: if (numdirs > 1) {
1.1400 raeburn 1903: var selelem = form.elements['coursefile_'+element];
1904: var i, len = selelem.options.length -1;
1905: if (len >=0) {
1906: for (i = len; i >= 0; i--) {
1907: selelem.remove(i);
1908: }
1909: selelem.options[0] = new Option('','');
1910: }
1.1248 raeburn 1911: }
1912: }
1.1400 raeburn 1913: }
1.1248 raeburn 1914: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1915: }
1916: if (document.getElementById('chooser_'+element+'_upload')) {
1917: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1918: if (document.getElementById('uploadcrsres_'+element)) {
1919: document.getElementById('uploadcrsres_'+element).value = '';
1920: }
1921: }
1922: return;
1923: }
1924:
1.1400 raeburn 1925: function toggleCrsUpload(form,element) {
1.1248 raeburn 1926: if (document.getElementById('chooser_'+element+'_crsres')) {
1927: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1928: }
1929: if (document.getElementById('chooser_'+element+'_upload')) {
1930: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1931: if (curr == 'none') {
1.1400 raeburn 1932: form.elements['newsubdir_'+element][0].checked = true;
1933: toggleNewsubdir(form,element);
1934: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1935: if (document.getElementById('uploadcrsres_'+element)) {
1936: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1937: }
1938: }
1939: }
1940: return;
1941: }
1942:
1943: function toggleResImport(form,element) {
1944: var choices = new Array('crsres','upload');
1945: for (var i=0; i<choices.length; i++) {
1946: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1947: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1948: }
1949: }
1950: }
1951:
1952: function toggleNewsubdir(form,element) {
1953: var newsub = form.elements['newsubdir_'+element];
1954: if (newsub) {
1955: if (newsub.length) {
1956: for (var j=0; j<newsub.length; j++) {
1957: if (newsub[j].checked) {
1958: if (document.getElementById('newsubdirname_'+element)) {
1959: if (newsub[j].value == '1') {
1960: document.getElementById('newsubdirname_'+element).type = "text";
1961: if (document.getElementById('newsubdir_'+element)) {
1962: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1963: }
1964: } else {
1965: document.getElementById('newsubdirname_'+element).type = "hidden";
1966: document.getElementById('newsubdirname_'+element).value = "";
1967: document.getElementById('newsubdir_'+element).innerHTML = "";
1968: }
1969: }
1970: break;
1971: }
1972: }
1973: }
1974: }
1975: }
1976:
1977: function updateCrsFile(form,element) {
1978: var directory = form.elements['coursepath_'+element];
1979: var filename = form.elements['coursefile_'+element];
1980: var path = directory.options[directory.selectedIndex].value;
1981: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1982: if (file != '') {
1983: form.elements[element].value = '$respath';
1984: if (path == '/') {
1985: form.elements[element].value += file;
1986: } else {
1987: form.elements[element].value += path+'/'+file;
1988: }
1989: unClean();
1990: if (document.getElementById('previewimg_'+element)) {
1991: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1992: var newsrc = document.getElementById('previewimg_'+element).src;
1993: }
1994: if (document.getElementById('showimg_'+element)) {
1995: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1996: }
1.1248 raeburn 1997: }
1998: toggleChooser(form,element);
1999: return;
2000: }
2001:
2002: function uploadDone(suffix,name) {
2003: if (name) {
2004: document.forms["lonhomework"].elements[suffix].value = name;
2005: unClean();
2006: toggleChooser(document.forms["lonhomework"],suffix);
2007: }
2008: }
2009:
2010: \$(document).ready(function(){
2011:
2012: \$(document).delegate('form :submit', 'click', function( event ) {
2013: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2014: var buttonId = this.id;
2015: var suffix = buttonId.toString();
2016: suffix = suffix.replace(/^crsupload_/,'');
2017: event.preventDefault();
2018: document.lonhomework.target = 'crsupload_target_'+suffix;
2019: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2020: \$(this.form).submit();
2021: document.lonhomework.target = '';
2022: if (document.getElementById('crsuploadto_'+suffix)) {
2023: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2024: }
2025: return false;
2026: }
2027: });
2028: });
2029: END
2030: }
1.1205 golterma 2031: return <<"COLORFULEDIT"
2032: <script type="text/javascript">
2033: // <![CDATA[>
2034: function fold_box(curDepth, lastresource){
2035:
2036: // we need a list because there can be several blocks you need to fold in one tag
2037: var block = document.getElementsByName('foldblock_'+curDepth);
2038: // but there is only one folding button per tag
2039: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2040:
2041: if(block.item(0).style.display == 'none'){
2042:
2043: foldbutton.value = '@{[&mt("Hide")]}';
2044: for (i = 0; i < block.length; i++){
2045: block.item(i).style.display = '';
2046: }
2047: }else{
2048:
2049: foldbutton.value = '@{[&mt("Show")]}';
2050: for (i = 0; i < block.length; i++){
2051: // block.item(i).style.visibility = 'collapse';
2052: block.item(i).style.display = 'none';
2053: }
2054: };
2055: saveState(lastresource);
2056: }
2057:
2058: function saveState (lastresource) {
2059:
2060: var tag_list = getTagList();
2061: if(tag_list != null){
2062: var timestamp = new Date().getTime();
2063: var key = lastresource;
2064:
2065: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2066: // starting with timestamp
2067: var value = timestamp+';';
2068:
2069: // building the list of key-value pairs
2070: for(var i = 0; i < tag_list.length; i++){
2071: value += tag_list[i]+',';
2072: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2073: }
2074:
2075: // only iterate whole storage if nothing to override
2076: if(localStorage.getItem(key) == null){
2077:
2078: // prevent storage from growing large
2079: if(localStorage.length > 50){
2080: var regex_getTimestamp = /^(?:\d)+;/;
2081: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2082: var oldest_key;
2083:
2084: for(var i = 1; i < localStorage.length; i++){
2085: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2086: oldest_key = localStorage.key(i);
2087: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2088: }
2089: }
2090: localStorage.removeItem(oldest_key);
2091: }
2092: }
2093: localStorage.setItem(key,value);
2094: }
2095: }
2096:
2097: // restore folding status of blocks (on page load)
2098: function restoreState (lastresource) {
2099: if(localStorage.getItem(lastresource) != null){
2100: var key = lastresource;
2101: var value = localStorage.getItem(key);
2102: var regex_delTimestamp = /^\d+;/;
2103:
2104: value.replace(regex_delTimestamp, '');
2105:
2106: var valueArr = value.split(';');
2107: var pairs;
2108: var elements;
2109: for (var i = 0; i < valueArr.length; i++){
2110: pairs = valueArr[i].split(',');
2111: elements = document.getElementsByName(pairs[0]);
2112:
2113: for (var j = 0; j < elements.length; j++){
2114: elements[j].style.display = pairs[1];
2115: if (pairs[1] == "none"){
2116: var regex_id = /([_\\d]+)\$/;
2117: regex_id.exec(pairs[0]);
2118: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2119: }
2120: }
2121: }
2122: }
2123: }
2124:
2125: function getTagList () {
2126:
2127: var stringToSearch = document.lonhomework.innerHTML;
2128:
2129: var ret = new Array();
2130: var regex_findBlock = /(foldblock_.*?)"/g;
2131: var tag_list = stringToSearch.match(regex_findBlock);
2132:
2133: if(tag_list != null){
2134: for(var i = 0; i < tag_list.length; i++){
2135: ret.push(tag_list[i].replace(/"/, ''));
2136: }
2137: }
2138: return ret;
2139: }
2140:
2141: function saveScrollPosition (resource) {
2142: var tag_list = getTagList();
2143:
2144: // we dont always want to jump to the first block
2145: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2146: if(\$(window).scrollTop() > 170){
2147: if(tag_list != null){
2148: var result;
2149: for(var i = 0; i < tag_list.length; i++){
2150: if(isElementInViewport(tag_list[i])){
2151: result += tag_list[i]+';';
2152: }
2153: }
2154: sessionStorage.setItem('anchor_'+resource, result);
2155: }
2156: } else {
2157: // we dont need to save zero, just delete the item to leave everything tidy
2158: sessionStorage.removeItem('anchor_'+resource);
2159: }
2160: }
2161:
2162: function restoreScrollPosition(resource){
2163:
2164: var elem = sessionStorage.getItem('anchor_'+resource);
2165: if(elem != null){
2166: var tag_list = elem.split(';');
2167: var elem_list;
2168:
2169: for(var i = 0; i < tag_list.length; i++){
2170: elem_list = document.getElementsByName(tag_list[i]);
2171:
2172: if(elem_list.length > 0){
2173: elem = elem_list[0];
2174: break;
2175: }
2176: }
2177: elem.scrollIntoView();
2178: }
2179: }
2180:
2181: function isElementInViewport(el) {
2182:
2183: // change to last element instead of first
2184: var elem = document.getElementsByName(el);
2185: var rect = elem[0].getBoundingClientRect();
2186:
2187: return (
2188: rect.top >= 0 &&
2189: rect.left >= 0 &&
2190: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2191: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2192: );
2193: }
2194:
2195: function autosize(depth){
2196: var cmInst = window['cm'+depth];
2197: var fitsizeButton = document.getElementById('fitsize'+depth);
2198:
2199: // is fixed size, switching to dynamic
2200: if (sessionStorage.getItem("autosized_"+depth) == null) {
2201: cmInst.setSize("","auto");
2202: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2203: sessionStorage.setItem("autosized_"+depth, "yes");
2204:
2205: // is dynamic size, switching to fixed
2206: } else {
2207: cmInst.setSize("","300px");
2208: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2209: sessionStorage.removeItem("autosized_"+depth);
2210: }
2211: }
2212:
1.1248 raeburn 2213: $browse_or_search
1.1205 golterma 2214:
2215: // ]]>
2216: </script>
2217: COLORFULEDIT
2218: }
2219:
2220: sub xmleditor_js {
2221: return <<XMLEDIT
2222: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2223: <script type="text/javascript">
2224: // <![CDATA[>
2225:
2226: function saveScrollPosition (resource) {
2227:
2228: var scrollPos = \$(window).scrollTop();
2229: sessionStorage.setItem(resource,scrollPos);
2230: }
2231:
2232: function restoreScrollPosition(resource){
2233:
2234: var scrollPos = sessionStorage.getItem(resource);
2235: \$(window).scrollTop(scrollPos);
2236: }
2237:
2238: // unless internet explorer
2239: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2240:
2241: \$(document).ready(function() {
2242: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2243: });
2244: }
2245:
2246: // inserts text at cursor position into codemirror (xml editor only)
2247: function insertText(text){
2248: cm.focus();
2249: var curPos = cm.getCursor();
2250: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2251: }
2252: // ]]>
2253: </script>
2254: XMLEDIT
2255: }
2256:
2257: sub insert_folding_button {
2258: my $curDepth = $Apache::lonxml::curdepth;
2259: my $lastresource = $env{'request.ambiguous'};
2260:
2261: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2262: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2263: }
2264:
1.1248 raeburn 2265: sub crsauthor_url {
2266: my ($url) = @_;
2267: if ($url eq '') {
2268: $url = $ENV{'REQUEST_URI'};
2269: }
2270: my ($cnum,$cdom);
2271: if ($env{'request.course.id'}) {
2272: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2273: if ($audom ne '' && $auname ne '') {
2274: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2275: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2276: $cnum = $auname;
2277: $cdom = $audom;
2278: }
2279: }
2280: }
2281: return ($cnum,$cdom);
2282: }
2283:
2284: sub import_crsauthor_form {
1.1400 raeburn 2285: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2286: return (0) unless ($env{'request.course.id'});
2287: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2288: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2289: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2290: return (0) unless (($cnum ne '') && ($cdom ne ''));
2291: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2292: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2293:
1.1248 raeburn 2294: if (grep(/^\Q$crshome\E$/,@ids)) {
2295: $is_home = 1;
2296: }
1.1400 raeburn 2297: $toppath = "/priv/$cdom/$cnum";
2298: my $nonemptydir = 1;
2299: my $js_only;
2300: if ($only) {
2301: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2302: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2303: }
2304: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2305: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2306: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2307: my %lt = &Apache::lonlocal::texthash (
2308: fnam => 'Filename',
2309: dire => 'Directory',
1.1400 raeburn 2310: se => 'Select',
1.1248 raeburn 2311: );
1.1450 raeburn 2312: $output = '<label>'.$lt{'dire'}.': '.
1.1400 raeburn 2313: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2314: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2315: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2316: if ($files{'/'}) {
2317: $output .= '<option value="/">/</option>'."\n";
2318: }
1.1400 raeburn 2319: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2320: next if ($key eq '/');
1.1400 raeburn 2321: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2322: }
1.1450 raeburn 2323: $output .= '</select></label><br /><label>'."\n".
1.1402 raeburn 2324: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2325: '<option value="" selected="selected"></option>'."\n".
1.1450 raeburn 2326: '</select></label>'."\n".
1.1402 raeburn 2327: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2328: return ($numdirs,$output);
2329: }
2330:
2331: sub show_crsfiles_js {
2332: my $excluderef = &Apache::lonnet::priv_exclude();
2333: my $se = &js_escape(&mt('Select'));
2334: my $exclude;
2335: if (ref($excluderef) eq 'HASH') {
2336: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2337: }
2338: my $js = <<"END";
2339:
2340:
1.1402 raeburn 2341: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2342: var relpath = '';
2343: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2344: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2345: if (currdir == '') {
2346: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2347: selelem = form.elements[filesel];
2348: var j, numfiles = selelem.options.length -1;
2349: if (numfiles >=0) {
2350: for (j = numfiles; j >= 0; j--) {
2351: selelem.remove(j);
2352: }
2353: }
2354: if (selelem.options.length == 0) {
2355: selelem.options[selelem.options.length] = new Option('','');
2356: selelem.selectedIndex = 0;
1.1248 raeburn 2357: }
2358: }
1.1400 raeburn 2359: return;
2360: } else {
2361: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2362: }
2363: }
1.1400 raeburn 2364: var http = new XMLHttpRequest();
2365: var url = "/adm/courseauthor";
2366: var crsrole = "$env{'request.role'}";
2367: var exclude = '';
2368: if (exc) {
2369: exclude = '$exclude';
2370: }
1.1402 raeburn 2371: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2372: http.open("POST", url, true);
2373: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2374: http.onreadystatechange = function() {
2375: if (http.readyState == 4 && http.status == 200) {
2376: var data = JSON.parse(http.responseText);
2377: var selelem;
2378: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2379: if (Array.isArray(data.dirs)) {
2380: selelem = form.elements[dirsel];
2381: var i, numdirs = selelem.options.length -1;
2382: if (numdirs >=0) {
2383: for (i = numdirs; i >= 0; i--) {
2384: selelem.remove(i);
2385: }
2386: }
2387: var len = data.dirs.length;
2388: if (len) {
1.1402 raeburn 2389: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2390: var j;
2391: for (j = 0; j < len; j++) {
2392: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2393: }
2394: selelem.selectedIndex = 0;
2395: }
2396: if (!setfile) {
2397: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2398: selelem = form.elements[filesel];
2399: var j, numfiles = selelem.options.length -1;
2400: if (numfiles >=0) {
2401: for (j = numfiles; j >= 0; j--) {
2402: selelem.remove(j);
2403: }
2404: }
2405: if (selelem.options.length == 0) {
2406: selelem.options[selelem.options.length] = new Option('','');
2407: selelem.selectedIndex = 0;
2408: }
2409: }
2410: }
2411: }
2412: }
2413: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2414: selelem = form.elements[filesel];
2415: var i, numfiles = selelem.options.length -1;
2416: if (numfiles >=0) {
2417: for (i = numfiles; i >= 0; i--) {
2418: selelem.remove(i);
2419: }
2420: }
2421: var x;
2422: for (x in data.files) {
2423: if (Array.isArray(data.files[x])) {
2424: if (data.files[x].length > 1) {
2425: selelem.options[selelem.options.length] = new Option('$se','');
2426: }
2427: var len = data.files[x].length;
2428: if (len) {
2429: var k;
2430: for (k = 0; k < len; k++) {
2431: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2432: }
2433: selelem.selectedIndex = 0;
2434: }
2435: }
2436: }
2437: if (selelem.options.length == 0) {
2438: selelem.options[selelem.options.length] = new Option('','');
2439: selelem.selectedIndex = 0;
2440: }
1.1248 raeburn 2441: }
2442: }
2443: }
1.1400 raeburn 2444: http.send(params);
1.1248 raeburn 2445: }
1.1400 raeburn 2446: END
1.1248 raeburn 2447: }
2448:
1.1426 raeburn 2449: sub crsauthor_rights {
2450: my ($rightsfile,$path,$docroot,$cnum,$cdom) = @_;
2451: my $sourcerights = "$path/$rightsfile";
2452: my $now = time;
2453: if (!-e $sourcerights) {
2454: my $cid = $cdom.'_'.$cnum;
2455: if (!-e "$docroot/priv/$cdom") {
2456: mkdir("$docroot/priv/$cdom",0755);
2457: }
2458: if (!-e "$docroot/priv/$cdom/$cnum") {
2459: mkdir("$docroot/priv/$cdom/$cnum",0755);
2460: }
2461: if (open(my $fh,">$sourcerights")) {
2462: print $fh <<END;
2463: <accessrule effect="deny" realm="" type="course" role="" />
2464: <accessrule effect="allow" realm="$cid" type="course" role="" />
2465: END
2466: close($fh);
2467: }
2468: }
2469: if (!-e "$sourcerights.meta") {
2470: if (open(my $fh,">$sourcerights.meta")) {
2471: my $author=$env{'environment.firstname'}.' '.
2472: $env{'environment.middlename'}.' '.
2473: $env{'environment.lastname'}.' '.
2474: $env{'environment.generation'};
2475: $author =~ s/\s+$//;
2476: print $fh <<"END";
2477:
2478: <abstract></abstract>
2479: <author>$author</author>
2480: <authorspace>$cnum:$cdom</authorspace>
2481: <copyright>private</copyright>
2482: <creationdate>$now</creationdate>
2483: <customdistributionfile></customdistributionfile>
2484: <dependencies></dependencies>
2485: <domain>$cdom</domain>
2486: <highestgradelevel>0</highestgradelevel>
2487: <keywords></keywords>
1.1445 raeburn 2488: <language>notset</language>
1.1426 raeburn 2489: <lastrevisiondate>$now</lastrevisiondate>
2490: <lowestgradelevel>0</lowestgradelevel>
2491: <mime>rights</mime>
2492: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
2493: <notes></notes>
2494: <obsolete></obsolete>
2495: <obsoletereplacement></obsoletereplacement>
2496: <owner>$cnum:$cdom</owner>
2497: <rule>deny:::course,allow:$cid::course</rule>
2498: <sourceavail></sourceavail>
2499: <standards></standards>
2500: <subject></subject>
2501: <title>Course Authoring Rights</title>
2502: END
2503: close($fh);
2504: }
2505: }
2506: return;
2507: }
2508:
1.565 albertel 2509: =pod
2510:
1.1420 raeburn 2511: =item * &iframe_wrapper_headjs()
2512:
1.1425 raeburn 2513: emits javascript containing two global vars to facilitate handling of resizing
2514: by code in iframe_wrapper_resizejs() used when an iframe is present in a page
2515: with standard LON-CAPA menus.
2516:
2517: =cut
2518:
1.1420 raeburn 2519: #
2520: # Where iframe is in use, if window.onload() executes before the custom resize function
2521: # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
2522: # are used to ensure document.ready() triggers a call to resize, so the iframe contents
2523: # do not obscure the Functions menu.
2524: #
2525:
2526: sub iframe_wrapper_headjs {
2527: return <<"ENDJS";
2528: <script type="text/javascript">
2529: // <![CDATA[
2530: var LCnotready = 0;
2531: var LCresizedef = 0;
2532: // ]]>
2533: </script>
2534:
2535: ENDJS
2536:
2537: }
2538:
2539: =pod
2540:
2541: =item * &iframe_wrapper_resizejs()
2542:
1.1425 raeburn 2543: emits javascript used to handle resizing for a page containing
2544: an iframe, to ensure that the iframe does not obscure any
2545: standard LON-CAPA menu items.
2546:
2547: =back
2548:
2549: =cut
2550:
1.1420 raeburn 2551: #
2552: # jQuery to use when iframe is in use and a page resize occurs.
2553: # This script will ensure that the iframe does not obscure any
2554: # standard LON-CAPA inline menus (primary, secondary, and/or
2555: # breadcrumbs and Functions menus. Expects javascript from
2556: # &iframe_wrapper_headjs() to be in head portion of the web page,
2557: # e.g., by inclusion in second arg passed to &start_page().
2558: #
2559:
2560: sub iframe_wrapper_resizejs {
2561: my $offset = 5;
2562: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
2563: if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
2564: $offset = 0;
2565: }
2566: return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
2567: \$(document).ready( function() {
2568: \$(window).unbind('resize').resize(function(){
2569: var header = null;
2570: var offset = $offset;
2571: var height = 0;
2572: var hdrtop = 0;
1.1421 raeburn 2573: if (\$('div.LC_menus_content:first').length) {
2574: if (\$('div.LC_menus_content:first').hasClass ("shown")) {
2575: header = \$('div.LC_menus_content:first');
1.1423 raeburn 2576: offset = 12;
1.1421 raeburn 2577: }
2578: } else if (\$('div.LC_head_subbox:first').length) {
1.1420 raeburn 2579: header = \$('div.LC_head_subbox:first');
2580: offset = 9;
2581: } else {
2582: if (\$('#LC_breadcrumbs').length) {
2583: header = \$('#LC_breadcrumbs');
2584: }
2585: }
2586: if (header != null && header.length) {
2587: height = header.height();
2588: hdrtop = header.position().top;
2589: }
2590: var pos = height + hdrtop + offset;
2591: \$('.LC_iframecontainer').css('top', pos);
2592: });
2593: LCresizedef = 1;
2594: if (LCnotready == 1) {
2595: LCnotready = 0;
2596: \$(window).trigger('resize');
2597: }
2598: });
2599: window.onload = function(){
2600: if (LCresizedef) {
2601: LCnotready = 0;
2602: \$(window).trigger('resize');
2603: } else {
2604: LCnotready = 1;
2605: }
2606: };
2607: SCRIPT
2608:
2609: }
2610:
2611: =pod
2612:
1.256 matthew 2613: =head1 Excel and CSV file utility routines
2614:
2615: =cut
2616:
2617: ###############################################################
2618: ###############################################################
2619:
2620: =pod
2621:
1.1162 raeburn 2622: =over 4
2623:
1.648 raeburn 2624: =item * &csv_translate($text)
1.37 matthew 2625:
1.185 www 2626: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2627: format.
2628:
2629: =cut
2630:
1.180 matthew 2631: ###############################################################
2632: ###############################################################
1.37 matthew 2633: sub csv_translate {
2634: my $text = shift;
2635: $text =~ s/\"/\"\"/g;
1.209 albertel 2636: $text =~ s/\n/ /g;
1.37 matthew 2637: return $text;
2638: }
1.180 matthew 2639:
2640: ###############################################################
2641: ###############################################################
2642:
2643: =pod
2644:
1.648 raeburn 2645: =item * &define_excel_formats()
1.180 matthew 2646:
2647: Define some commonly used Excel cell formats.
2648:
2649: Currently supported formats:
2650:
2651: =over 4
2652:
2653: =item header
2654:
2655: =item bold
2656:
2657: =item h1
2658:
2659: =item h2
2660:
2661: =item h3
2662:
1.256 matthew 2663: =item h4
2664:
2665: =item i
2666:
1.180 matthew 2667: =item date
2668:
2669: =back
2670:
2671: Inputs: $workbook
2672:
2673: Returns: $format, a hash reference.
2674:
1.1057 foxr 2675:
1.180 matthew 2676: =cut
2677:
2678: ###############################################################
2679: ###############################################################
2680: sub define_excel_formats {
2681: my ($workbook) = @_;
2682: my $format;
2683: $format->{'header'} = $workbook->add_format(bold => 1,
2684: bottom => 1,
2685: align => 'center');
2686: $format->{'bold'} = $workbook->add_format(bold=>1);
2687: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2688: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2689: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2690: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2691: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2692: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2693: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2694: return $format;
2695: }
2696:
2697: ###############################################################
2698: ###############################################################
1.113 bowersj2 2699:
2700: =pod
2701:
1.648 raeburn 2702: =item * &create_workbook()
1.255 matthew 2703:
2704: Create an Excel worksheet. If it fails, output message on the
2705: request object and return undefs.
2706:
2707: Inputs: Apache request object
2708:
2709: Returns (undef) on failure,
2710: Excel worksheet object, scalar with filename, and formats
2711: from &Apache::loncommon::define_excel_formats on success
2712:
2713: =cut
2714:
2715: ###############################################################
2716: ###############################################################
2717: sub create_workbook {
2718: my ($r) = @_;
2719: #
2720: # Create the excel spreadsheet
2721: my $filename = '/prtspool/'.
1.258 albertel 2722: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2723: time.'_'.rand(1000000000).'.xls';
2724: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2725: if (! defined($workbook)) {
2726: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2727: $r->print(
2728: '<p class="LC_error">'
2729: .&mt('Problems occurred in creating the new Excel file.')
2730: .' '.&mt('This error has been logged.')
2731: .' '.&mt('Please alert your LON-CAPA administrator.')
2732: .'</p>'
2733: );
1.255 matthew 2734: return (undef);
2735: }
2736: #
1.1014 foxr 2737: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2738: #
2739: my $format = &Apache::loncommon::define_excel_formats($workbook);
2740: return ($workbook,$filename,$format);
2741: }
2742:
2743: ###############################################################
2744: ###############################################################
2745:
2746: =pod
2747:
1.648 raeburn 2748: =item * &create_text_file()
1.113 bowersj2 2749:
1.542 raeburn 2750: Create a file to write to and eventually make available to the user.
1.256 matthew 2751: If file creation fails, outputs an error message on the request object and
2752: return undefs.
1.113 bowersj2 2753:
1.256 matthew 2754: Inputs: Apache request object, and file suffix
1.113 bowersj2 2755:
1.256 matthew 2756: Returns (undef) on failure,
2757: Filehandle and filename on success.
1.113 bowersj2 2758:
2759: =cut
2760:
1.256 matthew 2761: ###############################################################
2762: ###############################################################
2763: sub create_text_file {
2764: my ($r,$suffix) = @_;
2765: if (! defined($suffix)) { $suffix = 'txt'; };
2766: my $fh;
2767: my $filename = '/prtspool/'.
1.258 albertel 2768: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2769: time.'_'.rand(1000000000).'.'.$suffix;
2770: $fh = Apache::File->new('>/home/httpd'.$filename);
2771: if (! defined($fh)) {
2772: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2773: $r->print(
2774: '<p class="LC_error">'
2775: .&mt('Problems occurred in creating the output file.')
2776: .' '.&mt('This error has been logged.')
2777: .' '.&mt('Please alert your LON-CAPA administrator.')
2778: .'</p>'
2779: );
1.113 bowersj2 2780: }
1.256 matthew 2781: return ($fh,$filename)
1.113 bowersj2 2782: }
2783:
2784:
1.256 matthew 2785: =pod
1.113 bowersj2 2786:
2787: =back
2788:
2789: =cut
1.37 matthew 2790:
2791: ###############################################################
1.33 matthew 2792: ## Home server <option> list generating code ##
2793: ###############################################################
1.35 matthew 2794:
1.169 www 2795: # ------------------------------------------
2796:
2797: sub domain_select {
1.1289 raeburn 2798: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2799: my @possdoms;
2800: if (ref($incdoms) eq 'ARRAY') {
2801: @possdoms = @{$incdoms};
2802: } else {
2803: @possdoms = &Apache::lonnet::all_domains();
2804: }
2805:
1.169 www 2806: my %domains=map {
1.514 albertel 2807: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2808: } @possdoms;
2809:
2810: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2811: foreach my $dom (@{$excdoms}) {
2812: delete($domains{$dom});
2813: }
2814: }
2815:
1.169 www 2816: if ($multiple) {
2817: $domains{''}=&mt('Any domain');
1.550 albertel 2818: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2819: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2820: } else {
1.550 albertel 2821: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2822: return &select_form($name,$value,\%domains);
1.169 www 2823: }
2824: }
2825:
1.282 albertel 2826: #-------------------------------------------
2827:
2828: =pod
2829:
1.519 raeburn 2830: =head1 Routines for form select boxes
2831:
2832: =over 4
2833:
1.648 raeburn 2834: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2835:
2836: Returns a string containing a <select> element int multiple mode
2837:
2838:
2839: Args:
2840: $name - name of the <select> element
1.506 raeburn 2841: $value - scalar or array ref of values that should already be selected
1.282 albertel 2842: $size - number of rows long the select element is
1.283 albertel 2843: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2844: (shown text should already have been &mt())
1.506 raeburn 2845: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2846:
1.282 albertel 2847: =cut
2848:
2849: #-------------------------------------------
1.169 www 2850: sub multiple_select_form {
1.284 albertel 2851: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2852: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2853: my $output='';
1.191 matthew 2854: if (! defined($size)) {
2855: $size = 4;
1.283 albertel 2856: if (scalar(keys(%$hash))<4) {
2857: $size = scalar(keys(%$hash));
1.191 matthew 2858: }
2859: }
1.734 bisitz 2860: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2861: my @order;
1.506 raeburn 2862: if (ref($order) eq 'ARRAY') {
2863: @order = @{$order};
2864: } else {
2865: @order = sort(keys(%$hash));
1.501 banghart 2866: }
2867: if (exists($$hash{'select_form_order'})) {
2868: @order = @{$$hash{'select_form_order'}};
2869: }
2870:
1.284 albertel 2871: foreach my $key (@order) {
1.356 albertel 2872: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2873: $output.='selected="selected" ' if ($selected{$key});
2874: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2875: }
2876: $output.="</select>\n";
2877: return $output;
2878: }
2879:
1.88 www 2880: #-------------------------------------------
2881:
2882: =pod
2883:
1.1254 raeburn 2884: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2885:
2886: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2887: allow a user to select options from a ref to a hash containing:
2888: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2889: a javascript onchange item, e.g., onchange="this.form.submit();".
2890: An optional arg -- $readonly -- if true will cause the select form
2891: to be disabled, e.g., for the case where an instructor has a section-
2892: specific role, and is viewing/modifying parameters.
1.970 raeburn 2893:
1.88 www 2894: See lonrights.pm for an example invocation and use.
2895:
2896: =cut
2897:
2898: #-------------------------------------------
2899: sub select_form {
1.1228 raeburn 2900: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2901: return unless (ref($hashref) eq 'HASH');
2902: if ($onchange) {
2903: $onchange = ' onchange="'.$onchange.'"';
2904: }
1.1228 raeburn 2905: my $disabled;
2906: if ($readonly) {
2907: $disabled = ' disabled="disabled"';
2908: }
2909: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2910: my @keys;
1.970 raeburn 2911: if (exists($hashref->{'select_form_order'})) {
2912: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2913: } else {
1.970 raeburn 2914: @keys=sort(keys(%{$hashref}));
1.128 albertel 2915: }
1.356 albertel 2916: foreach my $key (@keys) {
2917: $selectform.=
2918: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2919: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2920: ">".$hashref->{$key}."</option>\n";
1.88 www 2921: }
2922: $selectform.="</select>";
2923: return $selectform;
2924: }
2925:
1.475 www 2926: # For display filters
2927:
2928: sub display_filter {
1.1074 raeburn 2929: my ($context) = @_;
1.475 www 2930: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2931: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2932: my $phraseinput = 'hidden';
2933: my $includeinput = 'hidden';
2934: my ($checked,$includetypestext);
2935: if ($env{'form.displayfilter'} eq 'containing') {
2936: $phraseinput = 'text';
2937: if ($context eq 'parmslog') {
2938: $includeinput = 'checkbox';
2939: if ($env{'form.includetypes'}) {
2940: $checked = ' checked="checked"';
2941: }
2942: $includetypestext = &mt('Include parameter types');
2943: }
2944: } else {
2945: $includetypestext = ' ';
2946: }
2947: my ($additional,$secondid,$thirdid);
2948: if ($context eq 'parmslog') {
2949: $additional =
2950: '<label><input type="'.$includeinput.'" name="includetypes"'.
2951: $checked.' name="includetypes" value="1" id="includetypes" />'.
2952: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2953: '</label>';
2954: $secondid = 'includetypes';
2955: $thirdid = 'includetypestext';
2956: }
2957: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2958: '$secondid','$thirdid')";
2959: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2960: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2961: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2962: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2963: &mt('Filter: [_1]',
1.477 www 2964: &select_form($env{'form.displayfilter'},
2965: 'displayfilter',
1.970 raeburn 2966: {'currentfolder' => 'Current folder/page',
1.477 www 2967: 'containing' => 'Containing phrase',
1.1074 raeburn 2968: 'none' => 'None'},$onchange)).' '.
2969: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2970: &HTML::Entities::encode($env{'form.containingphrase'}).
2971: '" />'.$additional;
2972: }
2973:
2974: sub display_filter_js {
2975: my $includetext = &mt('Include parameter types');
2976: return <<"ENDJS";
2977:
2978: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2979: var firstType = 'hidden';
2980: if (setter.options[setter.selectedIndex].value == 'containing') {
2981: firstType = 'text';
2982: }
2983: firstObject = document.getElementById(firstid);
2984: if (typeof(firstObject) == 'object') {
2985: if (firstObject.type != firstType) {
2986: changeInputType(firstObject,firstType);
2987: }
2988: }
2989: if (context == 'parmslog') {
2990: var secondType = 'hidden';
2991: if (firstType == 'text') {
2992: secondType = 'checkbox';
2993: }
2994: secondObject = document.getElementById(secondid);
2995: if (typeof(secondObject) == 'object') {
2996: if (secondObject.type != secondType) {
2997: changeInputType(secondObject,secondType);
2998: }
2999: }
3000: var textItem = document.getElementById(thirdid);
3001: var currtext = textItem.innerHTML;
3002: var newtext;
3003: if (firstType == 'text') {
3004: newtext = '$includetext';
3005: } else {
3006: newtext = ' ';
3007: }
3008: if (currtext != newtext) {
3009: textItem.innerHTML = newtext;
3010: }
3011: }
3012: return;
3013: }
3014:
3015: function changeInputType(oldObject,newType) {
3016: var newObject = document.createElement('input');
3017: newObject.type = newType;
3018: if (oldObject.size) {
3019: newObject.size = oldObject.size;
3020: }
3021: if (oldObject.value) {
3022: newObject.value = oldObject.value;
3023: }
3024: if (oldObject.name) {
3025: newObject.name = oldObject.name;
3026: }
3027: if (oldObject.id) {
3028: newObject.id = oldObject.id;
3029: }
3030: oldObject.parentNode.replaceChild(newObject,oldObject);
3031: return;
3032: }
3033:
3034: ENDJS
1.475 www 3035: }
3036:
1.167 www 3037: sub gradeleveldescription {
3038: my $gradelevel=shift;
3039: my %gradelevels=(0 => 'Not specified',
3040: 1 => 'Grade 1',
3041: 2 => 'Grade 2',
3042: 3 => 'Grade 3',
3043: 4 => 'Grade 4',
3044: 5 => 'Grade 5',
3045: 6 => 'Grade 6',
3046: 7 => 'Grade 7',
3047: 8 => 'Grade 8',
3048: 9 => 'Grade 9',
3049: 10 => 'Grade 10',
3050: 11 => 'Grade 11',
3051: 12 => 'Grade 12',
3052: 13 => 'Grade 13',
3053: 14 => '100 Level',
3054: 15 => '200 Level',
3055: 16 => '300 Level',
3056: 17 => '400 Level',
3057: 18 => 'Graduate Level');
3058: return &mt($gradelevels{$gradelevel});
3059: }
3060:
1.163 www 3061: sub select_level_form {
3062: my ($deflevel,$name)=@_;
3063: unless ($deflevel) { $deflevel=0; }
1.167 www 3064: my $selectform = "<select name=\"$name\" size=\"1\">\n";
3065: for (my $i=0; $i<=18; $i++) {
3066: $selectform.="<option value=\"$i\" ".
1.253 albertel 3067: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 3068: ">".&gradeleveldescription($i)."</option>\n";
3069: }
3070: $selectform.="</select>";
3071: return $selectform;
1.163 www 3072: }
1.167 www 3073:
1.35 matthew 3074: #-------------------------------------------
3075:
1.45 matthew 3076: =pod
3077:
1.1453 raeburn 3078: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled,$id)
1.35 matthew 3079:
3080: Returns a string containing a <select name='$name' size='1'> form to
3081: allow a user to select the domain to preform an operation in.
3082: See loncreateuser.pm for an example invocation and use.
3083:
1.90 www 3084: If the $includeempty flag is set, it also includes an empty choice ("no domain
3085: selected");
3086:
1.743 raeburn 3087: If the $showdomdesc flag is set, the domain name is followed by the domain description.
3088:
1.910 raeburn 3089: 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.
3090:
1.1121 raeburn 3091: The optional $incdoms is a reference to an array of domains which will be the only available options.
3092:
3093: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 3094:
1.1256 raeburn 3095: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
3096:
1.1453 raeburn 3097: The option $id argument is the value (if any) to set as the (unique) id attribute for the select tag.
3098:
1.35 matthew 3099: =cut
3100:
3101: #-------------------------------------------
1.34 matthew 3102: sub select_dom_form {
1.1453 raeburn 3103: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled,$id) = @_;
1.872 raeburn 3104: if ($onchange) {
1.874 raeburn 3105: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 3106: }
1.1256 raeburn 3107: if ($disabled) {
3108: $disabled = ' disabled="disabled"';
3109: }
1.1453 raeburn 3110: if ($id ne '') {
3111: $id = ' id="'.$id.'"';
3112: }
1.1121 raeburn 3113: my (@domains,%exclude);
1.910 raeburn 3114: if (ref($incdoms) eq 'ARRAY') {
3115: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
3116: } else {
3117: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
3118: }
1.90 www 3119: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 3120: if (ref($excdoms) eq 'ARRAY') {
3121: map { $exclude{$_} = 1; } @{$excdoms};
3122: }
1.1453 raeburn 3123: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled$id>\n";
1.356 albertel 3124: foreach my $dom (@domains) {
1.1121 raeburn 3125: next if ($exclude{$dom});
1.356 albertel 3126: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 3127: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
3128: if ($showdomdesc) {
3129: if ($dom ne '') {
3130: my $domdesc = &Apache::lonnet::domain($dom,'description');
3131: if ($domdesc ne '') {
3132: $selectdomain .= ' ('.$domdesc.')';
3133: }
3134: }
3135: }
3136: $selectdomain .= "</option>\n";
1.34 matthew 3137: }
3138: $selectdomain.="</select>";
3139: return $selectdomain;
3140: }
3141:
1.35 matthew 3142: #-------------------------------------------
3143:
1.45 matthew 3144: =pod
3145:
1.648 raeburn 3146: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 3147:
1.586 raeburn 3148: input: 4 arguments (two required, two optional) -
3149: $domain - domain of new user
3150: $name - name of form element
3151: $default - Value of 'default' causes a default item to be first
3152: option, and selected by default.
3153: $hide - Value of 'hide' causes hiding of the name of the server,
3154: if 1 server found, or default, if 0 found.
1.594 raeburn 3155: output: returns 2 items:
1.586 raeburn 3156: (a) form element which contains either:
3157: (i) <select name="$name">
3158: <option value="$hostid1">$hostid $servers{$hostid}</option>
3159: <option value="$hostid2">$hostid $servers{$hostid}</option>
3160: </select>
3161: form item if there are multiple library servers in $domain, or
3162: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
3163: if there is only one library server in $domain.
3164:
3165: (b) number of library servers found.
3166:
3167: See loncreateuser.pm for example of use.
1.35 matthew 3168:
3169: =cut
3170:
3171: #-------------------------------------------
1.586 raeburn 3172: sub home_server_form_item {
3173: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 3174: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 3175: my $result;
3176: my $numlib = keys(%servers);
3177: if ($numlib > 1) {
3178: $result .= '<select name="'.$name.'" />'."\n";
3179: if ($default) {
1.804 bisitz 3180: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3181: '</option>'."\n";
3182: }
3183: foreach my $hostid (sort(keys(%servers))) {
3184: $result.= '<option value="'.$hostid.'">'.
3185: $hostid.' '.$servers{$hostid}."</option>\n";
3186: }
3187: $result .= '</select>'."\n";
3188: } elsif ($numlib == 1) {
3189: my $hostid;
3190: foreach my $item (keys(%servers)) {
3191: $hostid = $item;
3192: }
3193: $result .= '<input type="hidden" name="'.$name.'" value="'.
3194: $hostid.'" />';
3195: if (!$hide) {
3196: $result .= $hostid.' '.$servers{$hostid};
3197: }
3198: $result .= "\n";
3199: } elsif ($default) {
3200: $result .= '<input type="hidden" name="'.$name.
3201: '" value="default" />';
3202: if (!$hide) {
3203: $result .= &mt('default');
3204: }
3205: $result .= "\n";
1.33 matthew 3206: }
1.586 raeburn 3207: return ($result,$numlib);
1.33 matthew 3208: }
1.112 bowersj2 3209:
3210: =pod
3211:
1.534 albertel 3212: =back
3213:
1.112 bowersj2 3214: =cut
1.87 matthew 3215:
3216: ###############################################################
1.112 bowersj2 3217: ## Decoding User Agent ##
1.87 matthew 3218: ###############################################################
3219:
3220: =pod
3221:
1.112 bowersj2 3222: =head1 Decoding the User Agent
3223:
3224: =over 4
3225:
3226: =item * &decode_user_agent()
1.87 matthew 3227:
3228: Inputs: $r
3229:
3230: Outputs:
3231:
3232: =over 4
3233:
1.112 bowersj2 3234: =item * $httpbrowser
1.87 matthew 3235:
1.112 bowersj2 3236: =item * $clientbrowser
1.87 matthew 3237:
1.112 bowersj2 3238: =item * $clientversion
1.87 matthew 3239:
1.112 bowersj2 3240: =item * $clientmathml
1.87 matthew 3241:
1.112 bowersj2 3242: =item * $clientunicode
1.87 matthew 3243:
1.112 bowersj2 3244: =item * $clientos
1.87 matthew 3245:
1.1137 raeburn 3246: =item * $clientmobile
3247:
1.1141 raeburn 3248: =item * $clientinfo
3249:
1.1194 raeburn 3250: =item * $clientosversion
3251:
1.87 matthew 3252: =back
3253:
1.157 matthew 3254: =back
3255:
1.87 matthew 3256: =cut
3257:
3258: ###############################################################
3259: ###############################################################
3260: sub decode_user_agent {
1.247 albertel 3261: my ($r)=@_;
1.87 matthew 3262: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3263: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3264: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3265: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3266: my $clientbrowser='unknown';
3267: my $clientversion='0';
3268: my $clientmathml='';
3269: my $clientunicode='0';
1.1137 raeburn 3270: my $clientmobile=0;
1.1194 raeburn 3271: my $clientosversion='';
1.87 matthew 3272: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3273: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3274: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3275: $clientbrowser=$bname;
3276: $httpbrowser=~/$vreg/i;
3277: $clientversion=$1;
3278: $clientmathml=($clientversion>=$minv);
3279: $clientunicode=($clientversion>=$univ);
3280: }
3281: }
3282: my $clientos='unknown';
1.1141 raeburn 3283: my $clientinfo;
1.87 matthew 3284: if (($httpbrowser=~/linux/i) ||
3285: ($httpbrowser=~/unix/i) ||
3286: ($httpbrowser=~/ux/i) ||
3287: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3288: if (($httpbrowser=~/vax/i) ||
3289: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3290: if ($httpbrowser=~/next/i) { $clientos='next'; }
3291: if (($httpbrowser=~/mac/i) ||
3292: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3293: if ($httpbrowser=~/win/i) {
3294: $clientos='win';
3295: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3296: $clientosversion = $1;
3297: }
3298: }
1.87 matthew 3299: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3300: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3301: $clientmobile=lc($1);
3302: }
1.1141 raeburn 3303: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3304: $clientinfo = 'firefox-'.$1;
3305: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3306: $clientinfo = 'chromeframe-'.$1;
3307: }
1.87 matthew 3308: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3309: $clientunicode,$clientos,$clientmobile,$clientinfo,
3310: $clientosversion);
1.87 matthew 3311: }
3312:
1.32 matthew 3313: ###############################################################
3314: ## Authentication changing form generation subroutines ##
3315: ###############################################################
3316: ##
3317: ## All of the authform_xxxxxxx subroutines take their inputs in a
3318: ## hash, and have reasonable default values.
3319: ##
3320: ## formname = the name given in the <form> tag.
1.35 matthew 3321: #-------------------------------------------
3322:
1.45 matthew 3323: =pod
3324:
1.112 bowersj2 3325: =head1 Authentication Routines
3326:
3327: =over 4
3328:
1.648 raeburn 3329: =item * &authform_xxxxxx()
1.35 matthew 3330:
3331: The authform_xxxxxx subroutines provide javascript and html forms which
3332: handle some of the conveniences required for authentication forms.
3333: This is not an optimal method, but it works.
3334:
3335: =over 4
3336:
1.112 bowersj2 3337: =item * authform_header
1.35 matthew 3338:
1.112 bowersj2 3339: =item * authform_authorwarning
1.35 matthew 3340:
1.112 bowersj2 3341: =item * authform_nochange
1.35 matthew 3342:
1.112 bowersj2 3343: =item * authform_kerberos
1.35 matthew 3344:
1.112 bowersj2 3345: =item * authform_internal
1.35 matthew 3346:
1.112 bowersj2 3347: =item * authform_filesystem
1.35 matthew 3348:
1.1310 raeburn 3349: =item * authform_lti
3350:
1.35 matthew 3351: =back
3352:
1.648 raeburn 3353: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3354:
1.35 matthew 3355: =cut
3356:
3357: #-------------------------------------------
1.32 matthew 3358: sub authform_header{
3359: my %in = (
3360: formname => 'cu',
1.80 albertel 3361: kerb_def_dom => '',
1.32 matthew 3362: @_,
3363: );
3364: $in{'formname'} = 'document.' . $in{'formname'};
3365: my $result='';
1.80 albertel 3366:
3367: #---------------------------------------------- Code for upper case translation
3368: my $Javascript_toUpperCase;
3369: unless ($in{kerb_def_dom}) {
3370: $Javascript_toUpperCase =<<"END";
3371: switch (choice) {
3372: case 'krb': currentform.elements[choicearg].value =
3373: currentform.elements[choicearg].value.toUpperCase();
3374: break;
3375: default:
3376: }
3377: END
3378: } else {
3379: $Javascript_toUpperCase = "";
3380: }
3381:
1.165 raeburn 3382: my $radioval = "'nochange'";
1.591 raeburn 3383: if (defined($in{'curr_authtype'})) {
3384: if ($in{'curr_authtype'} ne '') {
3385: $radioval = "'".$in{'curr_authtype'}."arg'";
3386: }
1.174 matthew 3387: }
1.165 raeburn 3388: my $argfield = 'null';
1.591 raeburn 3389: if (defined($in{'mode'})) {
1.165 raeburn 3390: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3391: if (defined($in{'curr_autharg'})) {
3392: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3393: $argfield = "'$in{'curr_autharg'}'";
3394: }
3395: }
3396: }
3397: }
3398:
1.32 matthew 3399: $result.=<<"END";
3400: var current = new Object();
1.165 raeburn 3401: current.radiovalue = $radioval;
3402: current.argfield = $argfield;
1.32 matthew 3403:
3404: function changed_radio(choice,currentform) {
3405: var choicearg = choice + 'arg';
3406: // If a radio button in changed, we need to change the argfield
3407: if (current.radiovalue != choice) {
3408: current.radiovalue = choice;
3409: if (current.argfield != null) {
3410: currentform.elements[current.argfield].value = '';
3411: }
3412: if (choice == 'nochange') {
3413: current.argfield = null;
3414: } else {
3415: current.argfield = choicearg;
3416: switch(choice) {
3417: case 'krb':
3418: currentform.elements[current.argfield].value =
3419: "$in{'kerb_def_dom'}";
3420: break;
3421: default:
3422: break;
3423: }
3424: }
3425: }
3426: return;
3427: }
1.22 www 3428:
1.32 matthew 3429: function changed_text(choice,currentform) {
3430: var choicearg = choice + 'arg';
3431: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3432: $Javascript_toUpperCase
1.32 matthew 3433: // clear old field
3434: if ((current.argfield != choicearg) && (current.argfield != null)) {
3435: currentform.elements[current.argfield].value = '';
3436: }
3437: current.argfield = choicearg;
3438: }
3439: set_auth_radio_buttons(choice,currentform);
3440: return;
1.20 www 3441: }
1.32 matthew 3442:
3443: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3444: var numauthchoices = currentform.login.length;
3445: if (typeof numauthchoices == "undefined") {
3446: return;
3447: }
1.32 matthew 3448: var i=0;
1.986 raeburn 3449: while (i < numauthchoices) {
1.32 matthew 3450: if (currentform.login[i].value == newvalue) { break; }
3451: i++;
3452: }
1.986 raeburn 3453: if (i == numauthchoices) {
1.32 matthew 3454: return;
3455: }
3456: current.radiovalue = newvalue;
3457: currentform.login[i].checked = true;
3458: return;
3459: }
3460: END
3461: return $result;
3462: }
3463:
1.1106 raeburn 3464: sub authform_authorwarning {
1.32 matthew 3465: my $result='';
1.144 matthew 3466: $result='<i>'.
3467: &mt('As a general rule, only authors or co-authors should be '.
3468: 'filesystem authenticated '.
3469: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3470: return $result;
3471: }
3472:
1.1106 raeburn 3473: sub authform_nochange {
1.32 matthew 3474: my %in = (
3475: formname => 'document.cu',
3476: kerb_def_dom => 'MSU.EDU',
3477: @_,
3478: );
1.1106 raeburn 3479: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3480: my $result;
1.1104 raeburn 3481: if (!$authnum) {
1.1105 raeburn 3482: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3483: } else {
3484: $result = '<label>'.&mt('[_1] Do not change login data',
3485: '<input type="radio" name="login" value="nochange" '.
3486: 'checked="checked" onclick="'.
1.281 albertel 3487: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3488: '</label>';
1.586 raeburn 3489: }
1.32 matthew 3490: return $result;
3491: }
3492:
1.591 raeburn 3493: sub authform_kerberos {
1.32 matthew 3494: my %in = (
3495: formname => 'document.cu',
3496: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3497: kerb_def_auth => 'krb4',
1.32 matthew 3498: @_,
3499: );
1.586 raeburn 3500: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3501: $autharg,$jscall,$disabled);
1.1106 raeburn 3502: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3503: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3504: $check5 = ' checked="checked"';
1.80 albertel 3505: } else {
1.772 bisitz 3506: $check4 = ' checked="checked"';
1.80 albertel 3507: }
1.1259 raeburn 3508: if ($in{'readonly'}) {
3509: $disabled = ' disabled="disabled"';
3510: }
1.165 raeburn 3511: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3512: if (defined($in{'curr_authtype'})) {
3513: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3514: $krbcheck = ' checked="checked"';
1.623 raeburn 3515: if (defined($in{'mode'})) {
3516: if ($in{'mode'} eq 'modifyuser') {
3517: $krbcheck = '';
3518: }
3519: }
1.591 raeburn 3520: if (defined($in{'curr_kerb_ver'})) {
3521: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3522: $check5 = ' checked="checked"';
1.591 raeburn 3523: $check4 = '';
3524: } else {
1.772 bisitz 3525: $check4 = ' checked="checked"';
1.591 raeburn 3526: $check5 = '';
3527: }
1.586 raeburn 3528: }
1.591 raeburn 3529: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3530: $krbarg = $in{'curr_autharg'};
3531: }
1.586 raeburn 3532: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3533: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3534: $result =
3535: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3536: $in{'curr_autharg'},$krbver);
3537: } else {
3538: $result =
3539: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3540: }
3541: return $result;
3542: }
3543: }
3544: } else {
3545: if ($authnum == 1) {
1.784 bisitz 3546: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3547: }
3548: }
1.586 raeburn 3549: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3550: return;
1.587 raeburn 3551: } elsif ($authtype eq '') {
1.591 raeburn 3552: if (defined($in{'mode'})) {
1.587 raeburn 3553: if ($in{'mode'} eq 'modifycourse') {
3554: if ($authnum == 1) {
1.1259 raeburn 3555: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3556: }
3557: }
3558: }
1.586 raeburn 3559: }
3560: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3561: if ($authtype eq '') {
3562: $authtype = '<input type="radio" name="login" value="krb" '.
3563: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3564: $krbcheck.$disabled.' />';
1.586 raeburn 3565: }
3566: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3567: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3568: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3569: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3570: $in{'curr_authtype'} eq 'krb4')) {
3571: $result .= &mt
1.144 matthew 3572: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3573: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3574: '<label>'.$authtype,
1.281 albertel 3575: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3576: 'value="'.$krbarg.'" '.
1.1259 raeburn 3577: 'onchange="'.$jscall.'"'.$disabled.' />',
3578: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3579: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3580: '</label>');
1.586 raeburn 3581: } elsif ($can_assign{'krb4'}) {
3582: $result .= &mt
3583: ('[_1] Kerberos authenticated with domain [_2] '.
3584: '[_3] Version 4 [_4]',
3585: '<label>'.$authtype,
3586: '</label><input type="text" size="10" name="krbarg" '.
3587: 'value="'.$krbarg.'" '.
1.1259 raeburn 3588: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3589: '<label><input type="hidden" name="krbver" value="4" />',
3590: '</label>');
3591: } elsif ($can_assign{'krb5'}) {
3592: $result .= &mt
3593: ('[_1] Kerberos authenticated with domain [_2] '.
3594: '[_3] Version 5 [_4]',
3595: '<label>'.$authtype,
3596: '</label><input type="text" size="10" name="krbarg" '.
3597: 'value="'.$krbarg.'" '.
1.1259 raeburn 3598: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3599: '<label><input type="hidden" name="krbver" value="5" />',
3600: '</label>');
3601: }
1.32 matthew 3602: return $result;
3603: }
3604:
1.1106 raeburn 3605: sub authform_internal {
1.586 raeburn 3606: my %in = (
1.32 matthew 3607: formname => 'document.cu',
3608: kerb_def_dom => 'MSU.EDU',
3609: @_,
3610: );
1.1259 raeburn 3611: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3612: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3613: if ($in{'readonly'}) {
3614: $disabled = ' disabled="disabled"';
3615: }
1.591 raeburn 3616: if (defined($in{'curr_authtype'})) {
3617: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3618: if ($can_assign{'int'}) {
1.772 bisitz 3619: $intcheck = 'checked="checked" ';
1.623 raeburn 3620: if (defined($in{'mode'})) {
3621: if ($in{'mode'} eq 'modifyuser') {
3622: $intcheck = '';
3623: }
3624: }
1.591 raeburn 3625: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3626: $intarg = $in{'curr_autharg'};
3627: }
3628: } else {
3629: $result = &mt('Currently internally authenticated.');
3630: return $result;
1.165 raeburn 3631: }
3632: }
1.586 raeburn 3633: } else {
3634: if ($authnum == 1) {
1.784 bisitz 3635: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3636: }
3637: }
3638: if (!$can_assign{'int'}) {
3639: return;
1.587 raeburn 3640: } elsif ($authtype eq '') {
1.591 raeburn 3641: if (defined($in{'mode'})) {
1.587 raeburn 3642: if ($in{'mode'} eq 'modifycourse') {
3643: if ($authnum == 1) {
1.1259 raeburn 3644: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3645: }
3646: }
3647: }
1.165 raeburn 3648: }
1.586 raeburn 3649: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3650: if ($authtype eq '') {
3651: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3652: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3653: }
1.605 bisitz 3654: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3655: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3656: $result = &mt
1.144 matthew 3657: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3658: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3659: $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 3660: return $result;
3661: }
3662:
1.1104 raeburn 3663: sub authform_local {
1.32 matthew 3664: my %in = (
3665: formname => 'document.cu',
3666: kerb_def_dom => 'MSU.EDU',
3667: @_,
3668: );
1.1259 raeburn 3669: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3670: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3671: if ($in{'readonly'}) {
3672: $disabled = ' disabled="disabled"';
3673: }
1.591 raeburn 3674: if (defined($in{'curr_authtype'})) {
3675: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3676: if ($can_assign{'loc'}) {
1.772 bisitz 3677: $loccheck = 'checked="checked" ';
1.623 raeburn 3678: if (defined($in{'mode'})) {
3679: if ($in{'mode'} eq 'modifyuser') {
3680: $loccheck = '';
3681: }
3682: }
1.591 raeburn 3683: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3684: $locarg = $in{'curr_autharg'};
3685: }
3686: } else {
3687: $result = &mt('Currently using local (institutional) authentication.');
3688: return $result;
1.165 raeburn 3689: }
3690: }
1.586 raeburn 3691: } else {
3692: if ($authnum == 1) {
1.784 bisitz 3693: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3694: }
3695: }
3696: if (!$can_assign{'loc'}) {
3697: return;
1.587 raeburn 3698: } elsif ($authtype eq '') {
1.591 raeburn 3699: if (defined($in{'mode'})) {
1.587 raeburn 3700: if ($in{'mode'} eq 'modifycourse') {
3701: if ($authnum == 1) {
1.1259 raeburn 3702: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3703: }
3704: }
3705: }
1.165 raeburn 3706: }
1.586 raeburn 3707: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3708: if ($authtype eq '') {
3709: $authtype = '<input type="radio" name="login" value="loc" '.
3710: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3711: $jscall.'"'.$disabled.' />';
1.586 raeburn 3712: }
3713: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3714: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3715: $result = &mt('[_1] Local Authentication with argument [_2]',
3716: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3717: return $result;
3718: }
3719:
1.1106 raeburn 3720: sub authform_filesystem {
1.32 matthew 3721: my %in = (
3722: formname => 'document.cu',
3723: kerb_def_dom => 'MSU.EDU',
3724: @_,
3725: );
1.1259 raeburn 3726: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3727: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3728: if ($in{'readonly'}) {
3729: $disabled = ' disabled="disabled"';
3730: }
1.591 raeburn 3731: if (defined($in{'curr_authtype'})) {
3732: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3733: if ($can_assign{'fsys'}) {
1.772 bisitz 3734: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3735: if (defined($in{'mode'})) {
3736: if ($in{'mode'} eq 'modifyuser') {
3737: $fsyscheck = '';
3738: }
3739: }
1.586 raeburn 3740: } else {
3741: $result = &mt('Currently Filesystem Authenticated.');
3742: return $result;
1.1259 raeburn 3743: }
1.586 raeburn 3744: }
3745: } else {
3746: if ($authnum == 1) {
1.784 bisitz 3747: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3748: }
3749: }
3750: if (!$can_assign{'fsys'}) {
3751: return;
1.587 raeburn 3752: } elsif ($authtype eq '') {
1.591 raeburn 3753: if (defined($in{'mode'})) {
1.587 raeburn 3754: if ($in{'mode'} eq 'modifycourse') {
3755: if ($authnum == 1) {
1.1259 raeburn 3756: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3757: }
3758: }
3759: }
1.586 raeburn 3760: }
3761: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3762: if ($authtype eq '') {
3763: $authtype = '<input type="radio" name="login" value="fsys" '.
3764: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3765: $jscall.'"'.$disabled.' />';
1.586 raeburn 3766: }
1.1310 raeburn 3767: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3768: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3769: $result = &mt
1.144 matthew 3770: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3771: '<label>'.$authtype,'</label>'.$autharg);
3772: return $result;
3773: }
3774:
3775: sub authform_lti {
3776: my %in = (
3777: formname => 'document.cu',
3778: kerb_def_dom => 'MSU.EDU',
3779: @_,
3780: );
3781: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3782: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3783: if ($in{'readonly'}) {
3784: $disabled = ' disabled="disabled"';
3785: }
3786: if (defined($in{'curr_authtype'})) {
3787: if ($in{'curr_authtype'} eq 'lti') {
3788: if ($can_assign{'lti'}) {
3789: $lticheck = 'checked="checked" ';
3790: if (defined($in{'mode'})) {
3791: if ($in{'mode'} eq 'modifyuser') {
3792: $lticheck = '';
3793: }
3794: }
3795: } else {
3796: $result = &mt('Currently LTI Authenticated.');
3797: return $result;
3798: }
3799: }
3800: } else {
3801: if ($authnum == 1) {
3802: $authtype = '<input type="hidden" name="login" value="lti" />';
3803: }
3804: }
3805: if (!$can_assign{'lti'}) {
3806: return;
3807: } elsif ($authtype eq '') {
3808: if (defined($in{'mode'})) {
3809: if ($in{'mode'} eq 'modifycourse') {
3810: if ($authnum == 1) {
3811: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3812: }
3813: }
3814: }
3815: }
3816: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3817: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3818: $authtype = '<input type="radio" name="login" value="lti" '.
3819: $lticheck.' onchange="'.$jscall.'" onclick="'.
3820: $jscall.'"'.$disabled.' />';
3821: }
3822: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3823: if ($authtype) {
3824: $result = &mt('[_1] LTI Authenticated',
3825: '<label>'.$authtype.'</label>'.$autharg);
3826: } else {
3827: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3828: $autharg;
3829: }
1.32 matthew 3830: return $result;
3831: }
3832:
1.586 raeburn 3833: sub get_assignable_auth {
3834: my ($dom) = @_;
3835: if ($dom eq '') {
3836: $dom = $env{'request.role.domain'};
3837: }
3838: my %can_assign = (
3839: krb4 => 1,
3840: krb5 => 1,
3841: int => 1,
3842: loc => 1,
1.1310 raeburn 3843: lti => 1,
1.586 raeburn 3844: );
3845: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3846: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3847: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3848: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3849: my $context;
3850: if ($env{'request.role'} =~ /^au/) {
3851: $context = 'author';
1.1259 raeburn 3852: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3853: $context = 'domain';
3854: } elsif ($env{'request.course.id'}) {
3855: $context = 'course';
3856: }
3857: if ($context) {
3858: if (ref($authhash->{$context}) eq 'HASH') {
3859: %can_assign = %{$authhash->{$context}};
3860: }
3861: }
3862: }
3863: }
3864: my $authnum = 0;
3865: foreach my $key (keys(%can_assign)) {
3866: if ($can_assign{$key}) {
3867: $authnum ++;
3868: }
3869: }
3870: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3871: $authnum --;
3872: }
3873: return ($authnum,%can_assign);
3874: }
3875:
1.1331 raeburn 3876: sub check_passwd_rules {
3877: my ($domain,$plainpass) = @_;
3878: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3879: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3880: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3881: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3882: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3883: if ($passwdconf{'min'} > $min) {
3884: $min = $passwdconf{'min'};
3885: }
1.1331 raeburn 3886: }
3887: if ($passwdconf{'max'} =~ /^\d+$/) {
3888: $max = $passwdconf{'max'};
3889: }
3890: @chars = @{$passwdconf{'chars'}};
3891: }
3892: if (($min) && (length($plainpass) < $min)) {
3893: push(@brokerule,'min');
3894: }
3895: if (($max) && (length($plainpass) > $max)) {
3896: push(@brokerule,'max');
3897: }
3898: if (@chars) {
3899: my %rules;
3900: map { $rules{$_} = 1; } @chars;
3901: if ($rules{'uc'}) {
3902: unless ($plainpass =~ /[A-Z]/) {
3903: push(@brokerule,'uc');
3904: }
3905: }
3906: if ($rules{'lc'}) {
1.1332 raeburn 3907: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3908: push(@brokerule,'lc');
3909: }
3910: }
3911: if ($rules{'num'}) {
3912: unless ($plainpass =~ /\d/) {
3913: push(@brokerule,'num');
3914: }
3915: }
3916: if ($rules{'spec'}) {
3917: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3918: push(@brokerule,'spec');
3919: }
3920: }
3921: }
3922: if (@brokerule) {
3923: my %rulenames = &Apache::lonlocal::texthash(
3924: uc => 'At least one upper case letter',
3925: lc => 'At least one lower case letter',
3926: num => 'At least one number',
3927: spec => 'At least one non-alphanumeric',
3928: );
3929: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3930: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3931: $rulenames{'num'} .= ': 0123456789';
3932: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3933: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3934: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3935: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3936: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3937: if (grep(/^$rule$/,@brokerule)) {
3938: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3939: }
3940: }
3941: $warning .= '</ul>';
3942: }
1.1332 raeburn 3943: if (wantarray) {
3944: return @brokerule;
3945: }
1.1331 raeburn 3946: return $warning;
3947: }
3948:
1.1376 raeburn 3949: sub passwd_validation_js {
1.1377 raeburn 3950: my ($currpasswdval,$domain,$context,$id) = @_;
3951: my (%passwdconf,$alertmsg);
3952: if ($context eq 'linkprot') {
3953: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3954: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3955: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3956: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3957: }
3958: }
3959: if ($id eq 'add') {
3960: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3961: } elsif ($id =~ /^\d+$/) {
3962: my $pos = $id+1;
3963: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3964: } else {
3965: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3966: }
1.1434 raeburn 3967: } elsif ($context eq 'ltitools') {
3968: my %domconfig = &Apache::lonnet::get_dom('configuration',['toolsec'],$domain);
3969: if (ref($domconfig{'toolsec'}) eq 'HASH') {
3970: if (ref($domconfig{'toolsec'}{'rules'}) eq 'HASH') {
3971: %passwdconf = %{$domconfig{'toolsec'}{'rules'}};
3972: }
3973: }
3974: if ($id eq 'add') {
3975: $alertmsg = &mt('Secret for added external tool did not satisfy requirement(s):').'\n\n';
3976: } elsif ($id =~ /^\d+$/) {
3977: my $pos = $id+1;
3978: $alertmsg = &mt('Secret for external tool [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3979: } else {
3980: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3981: }
1.1377 raeburn 3982: } else {
3983: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3984: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3985: }
1.1376 raeburn 3986: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3987: $numrules = 0;
3988: $min = $Apache::lonnet::passwdmin;
3989: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3990: if ($passwdconf{'min'} =~ /^\d+$/) {
3991: if ($passwdconf{'min'} > $min) {
3992: $min = $passwdconf{'min'};
3993: }
3994: }
3995: if ($passwdconf{'max'} =~ /^\d+$/) {
3996: $max = $passwdconf{'max'};
3997: $numrules ++;
3998: }
3999: @chars = @{$passwdconf{'chars'}};
4000: if (@chars) {
4001: $numrules ++;
4002: }
4003: }
4004: if ($min > 0) {
4005: $numrules ++;
4006: }
4007: if (($min > 0) || ($max ne '') || (@chars > 0)) {
4008: if ($min) {
4009: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
4010: }
4011: if ($max) {
4012: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
4013: }
4014: my (@charalerts,@charrules);
4015: if (@chars) {
4016: if (grep(/^uc$/,@chars)) {
4017: push(@charalerts,&mt('contain at least one upper case letter'));
4018: push(@charrules,'uc');
4019: }
4020: if (grep(/^lc$/,@chars)) {
4021: push(@charalerts,&mt('contain at least one lower case letter'));
4022: push(@charrules,'lc');
4023: }
4024: if (grep(/^num$/,@chars)) {
4025: push(@charalerts,&mt('contain at least one number'));
4026: push(@charrules,'num');
4027: }
4028: if (grep(/^spec$/,@chars)) {
4029: push(@charalerts,&mt('contain at least one non-alphanumeric'));
4030: push(@charrules,'spec');
4031: }
4032: }
4033: $intargjs = qq| var rulesmsg = '';\n|.
4034: qq| var currpwval = $currpasswdval;\n|;
4035: if ($min) {
4036: $intargjs .= qq|
4037: if (currpwval.length < $min) {
4038: rulesmsg += ' - $alert{min}';
4039: }
4040: |;
4041: }
4042: if ($max) {
4043: $intargjs .= qq|
4044: if (currpwval.length > $max) {
4045: rulesmsg += ' - $alert{max}';
4046: }
4047: |;
4048: }
4049: if (@chars > 0) {
4050: my $charrulestr = '"'.join('","',@charrules).'"';
4051: my $charalertstr = '"'.join('","',@charalerts).'"';
4052: $intargjs .= qq| var brokerules = new Array();\n|.
4053: qq| var charrules = new Array($charrulestr);\n|.
4054: qq| var charalerts = new Array($charalertstr);\n|;
4055: my %rules;
4056: map { $rules{$_} = 1; } @chars;
4057: if ($rules{'uc'}) {
4058: $intargjs .= qq|
4059: var ucRegExp = /[A-Z]/;
4060: if (!ucRegExp.test(currpwval)) {
4061: brokerules.push('uc');
4062: }
4063: |;
4064: }
4065: if ($rules{'lc'}) {
4066: $intargjs .= qq|
4067: var lcRegExp = /[a-z]/;
4068: if (!lcRegExp.test(currpwval)) {
4069: brokerules.push('lc');
4070: }
4071: |;
4072: }
4073: if ($rules{'num'}) {
4074: $intargjs .= qq|
4075: var numRegExp = /[0-9]/;
4076: if (!numRegExp.test(currpwval)) {
4077: brokerules.push('num');
4078: }
4079: |;
4080: }
4081: if ($rules{'spec'}) {
4082: $intargjs .= q|
4083: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
4084: if (!specRegExp.test(currpwval)) {
4085: brokerules.push('spec');
4086: }
4087: |;
4088: }
4089: $intargjs .= qq|
4090: if (brokerules.length > 0) {
4091: for (var i=0; i<brokerules.length; i++) {
4092: for (var j=0; j<charrules.length; j++) {
4093: if (brokerules[i] == charrules[j]) {
4094: rulesmsg += ' - '+charalerts[j]+'\\n';
4095: break;
4096: }
4097: }
4098: }
4099: }
4100: |;
4101: }
4102: $intargjs .= qq|
4103: if (rulesmsg != '') {
4104: rulesmsg = '$alertmsg'+rulesmsg;
4105: alert(rulesmsg);
4106: return false;
4107: }
4108: |;
4109: }
4110: return ($numrules,$intargjs);
4111: }
4112:
1.80 albertel 4113: ###############################################################
4114: ## Get Kerberos Defaults for Domain ##
4115: ###############################################################
4116: ##
4117: ## Returns default kerberos version and an associated argument
4118: ## as listed in file domain.tab. If not listed, provides
4119: ## appropriate default domain and kerberos version.
4120: ##
4121: #-------------------------------------------
4122:
4123: =pod
4124:
1.648 raeburn 4125: =item * &get_kerberos_defaults()
1.80 albertel 4126:
4127: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 4128: version and domain. If not found, it defaults to version 4 and the
4129: domain of the server.
1.80 albertel 4130:
1.648 raeburn 4131: =over 4
4132:
1.80 albertel 4133: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
4134:
1.648 raeburn 4135: =back
4136:
4137: =back
4138:
1.80 albertel 4139: =cut
4140:
4141: #-------------------------------------------
4142: sub get_kerberos_defaults {
4143: my $domain=shift;
1.641 raeburn 4144: my ($krbdef,$krbdefdom);
4145: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
4146: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
4147: $krbdef = $domdefaults{'auth_def'};
4148: $krbdefdom = $domdefaults{'auth_arg_def'};
4149: } else {
1.80 albertel 4150: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
4151: my $krbdefdom=$1;
4152: $krbdefdom=~tr/a-z/A-Z/;
4153: $krbdef = "krb4";
4154: }
4155: return ($krbdef,$krbdefdom);
4156: }
1.112 bowersj2 4157:
1.32 matthew 4158:
1.46 matthew 4159: ###############################################################
4160: ## Thesaurus Functions ##
4161: ###############################################################
1.20 www 4162:
1.46 matthew 4163: =pod
1.20 www 4164:
1.112 bowersj2 4165: =head1 Thesaurus Functions
4166:
4167: =over 4
4168:
1.648 raeburn 4169: =item * &initialize_keywords()
1.46 matthew 4170:
4171: Initializes the package variable %Keywords if it is empty. Uses the
4172: package variable $thesaurus_db_file.
4173:
4174: =cut
4175:
4176: ###################################################
4177:
4178: sub initialize_keywords {
4179: return 1 if (scalar keys(%Keywords));
4180: # If we are here, %Keywords is empty, so fill it up
4181: # Make sure the file we need exists...
4182: if (! -e $thesaurus_db_file) {
4183: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
4184: " failed because it does not exist");
4185: return 0;
4186: }
4187: # Set up the hash as a database
4188: my %thesaurus_db;
4189: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4190: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4191: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
4192: $thesaurus_db_file);
4193: return 0;
4194: }
4195: # Get the average number of appearances of a word.
4196: my $avecount = $thesaurus_db{'average.count'};
4197: # Put keywords (those that appear > average) into %Keywords
4198: while (my ($word,$data)=each (%thesaurus_db)) {
4199: my ($count,undef) = split /:/,$data;
4200: $Keywords{$word}++ if ($count > $avecount);
4201: }
4202: untie %thesaurus_db;
4203: # Remove special values from %Keywords.
1.356 albertel 4204: foreach my $value ('total.count','average.count') {
4205: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4206: }
1.46 matthew 4207: return 1;
4208: }
4209:
4210: ###################################################
4211:
4212: =pod
4213:
1.648 raeburn 4214: =item * &keyword($word)
1.46 matthew 4215:
4216: Returns true if $word is a keyword. A keyword is a word that appears more
4217: than the average number of times in the thesaurus database. Calls
4218: &initialize_keywords
4219:
4220: =cut
4221:
4222: ###################################################
1.20 www 4223:
4224: sub keyword {
1.46 matthew 4225: return if (!&initialize_keywords());
4226: my $word=lc(shift());
4227: $word=~s/\W//g;
4228: return exists($Keywords{$word});
1.20 www 4229: }
1.46 matthew 4230:
4231: ###############################################################
4232:
4233: =pod
1.20 www 4234:
1.648 raeburn 4235: =item * &get_related_words()
1.46 matthew 4236:
1.160 matthew 4237: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4238: an array of words. If the keyword is not in the thesaurus, an empty array
4239: will be returned. The order of the words returned is determined by the
4240: database which holds them.
4241:
4242: Uses global $thesaurus_db_file.
4243:
1.1057 foxr 4244:
1.46 matthew 4245: =cut
4246:
4247: ###############################################################
4248: sub get_related_words {
4249: my $keyword = shift;
4250: my %thesaurus_db;
4251: if (! -e $thesaurus_db_file) {
4252: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4253: "failed because the file does not exist");
4254: return ();
4255: }
4256: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4257: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4258: return ();
4259: }
4260: my @Words=();
1.429 www 4261: my $count=0;
1.46 matthew 4262: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4263: # The first element is the number of times
4264: # the word appears. We do not need it now.
1.429 www 4265: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4266: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4267: my $threshold=$mostfrequentcount/10;
4268: foreach my $possibleword (@RelatedWords) {
4269: my ($word,$wordcount)=split(/\,/,$possibleword);
4270: if ($wordcount>$threshold) {
4271: push(@Words,$word);
4272: $count++;
4273: if ($count>10) { last; }
4274: }
1.20 www 4275: }
4276: }
1.46 matthew 4277: untie %thesaurus_db;
4278: return @Words;
1.14 harris41 4279: }
1.1090 foxr 4280: ###############################################################
4281: #
4282: # Spell checking
4283: #
4284:
4285: =pod
4286:
1.1142 raeburn 4287: =back
4288:
1.1090 foxr 4289: =head1 Spell checking
4290:
4291: =over 4
4292:
4293: =item * &check_spelling($wordlist $language)
4294:
4295: Takes a string containing words and feeds it to an external
4296: spellcheck program via a pipeline. Returns a string containing
4297: them mis-spelled words.
4298:
4299: Parameters:
4300:
4301: =over 4
4302:
4303: =item - $wordlist
4304:
4305: String that will be fed into the spellcheck program.
4306:
4307: =item - $language
4308:
4309: Language string that specifies the language for which the spell
4310: check will be performed.
4311:
4312: =back
4313:
4314: =back
4315:
4316: Note: This sub assumes that aspell is installed.
4317:
4318:
4319: =cut
4320:
1.46 matthew 4321:
1.1090 foxr 4322: sub check_spelling {
4323: my ($wordlist, $language) = @_;
1.1091 foxr 4324: my @misspellings;
4325:
4326: # Generate the speller and set the langauge.
4327: # if explicitly selected:
1.1090 foxr 4328:
1.1091 foxr 4329: my $speller = Text::Aspell->new;
1.1090 foxr 4330: if ($language) {
1.1091 foxr 4331: $speller->set_option('lang', $language);
1.1090 foxr 4332: }
4333:
1.1091 foxr 4334: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4335:
1.1091 foxr 4336: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4337:
1.1091 foxr 4338: foreach my $word (@words) {
4339: if(! $speller->check($word)) {
4340: push(@misspellings, $word);
1.1090 foxr 4341: }
4342: }
1.1091 foxr 4343: return join(' ', @misspellings);
4344:
1.1090 foxr 4345: }
4346:
1.61 www 4347: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4348: =pod
4349:
1.112 bowersj2 4350: =head1 User Name Functions
4351:
4352: =over 4
4353:
1.648 raeburn 4354: =item * &plainname($uname,$udom,$first)
1.81 albertel 4355:
1.112 bowersj2 4356: Takes a users logon name and returns it as a string in
1.226 albertel 4357: "first middle last generation" form
4358: if $first is set to 'lastname' then it returns it as
4359: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4360:
4361: =cut
1.61 www 4362:
1.295 www 4363:
1.81 albertel 4364: ###############################################################
1.61 www 4365: sub plainname {
1.226 albertel 4366: my ($uname,$udom,$first)=@_;
1.537 albertel 4367: return if (!defined($uname) || !defined($udom));
1.295 www 4368: my %names=&getnames($uname,$udom);
1.226 albertel 4369: my $name=&Apache::lonnet::format_name($names{'firstname'},
4370: $names{'middlename'},
4371: $names{'lastname'},
4372: $names{'generation'},$first);
4373: $name=~s/^\s+//;
1.62 www 4374: $name=~s/\s+$//;
4375: $name=~s/\s+/ /g;
1.353 albertel 4376: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4377: return $name;
1.61 www 4378: }
1.66 www 4379:
4380: # -------------------------------------------------------------------- Nickname
1.81 albertel 4381: =pod
4382:
1.648 raeburn 4383: =item * &nickname($uname,$udom)
1.81 albertel 4384:
4385: Gets a users name and returns it as a string as
4386:
4387: ""nickname""
1.66 www 4388:
1.81 albertel 4389: if the user has a nickname or
4390:
4391: "first middle last generation"
4392:
4393: if the user does not
4394:
4395: =cut
1.66 www 4396:
4397: sub nickname {
4398: my ($uname,$udom)=@_;
1.537 albertel 4399: return if (!defined($uname) || !defined($udom));
1.295 www 4400: my %names=&getnames($uname,$udom);
1.68 albertel 4401: my $name=$names{'nickname'};
1.66 www 4402: if ($name) {
4403: $name='"'.$name.'"';
4404: } else {
4405: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4406: $names{'lastname'}.' '.$names{'generation'};
4407: $name=~s/\s+$//;
4408: $name=~s/\s+/ /g;
4409: }
4410: return $name;
4411: }
4412:
1.295 www 4413: sub getnames {
4414: my ($uname,$udom)=@_;
1.537 albertel 4415: return if (!defined($uname) || !defined($udom));
1.433 albertel 4416: if ($udom eq 'public' && $uname eq 'public') {
4417: return ('lastname' => &mt('Public'));
4418: }
1.295 www 4419: my $id=$uname.':'.$udom;
4420: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4421: if ($cached) {
4422: return %{$names};
4423: } else {
4424: my %loadnames=&Apache::lonnet::get('environment',
4425: ['firstname','middlename','lastname','generation','nickname'],
4426: $udom,$uname);
4427: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4428: return %loadnames;
4429: }
4430: }
1.61 www 4431:
1.542 raeburn 4432: # -------------------------------------------------------------------- getemails
1.648 raeburn 4433:
1.542 raeburn 4434: =pod
4435:
1.648 raeburn 4436: =item * &getemails($uname,$udom)
1.542 raeburn 4437:
4438: Gets a user's email information and returns it as a hash with keys:
4439: notification, critnotification, permanentemail
4440:
4441: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4442: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4443:
1.648 raeburn 4444:
1.542 raeburn 4445: =cut
4446:
1.648 raeburn 4447:
1.466 albertel 4448: sub getemails {
4449: my ($uname,$udom)=@_;
4450: if ($udom eq 'public' && $uname eq 'public') {
4451: return;
4452: }
1.467 www 4453: if (!$udom) { $udom=$env{'user.domain'}; }
4454: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4455: my $id=$uname.':'.$udom;
4456: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4457: if ($cached) {
4458: return %{$names};
4459: } else {
4460: my %loadnames=&Apache::lonnet::get('environment',
4461: ['notification','critnotification',
4462: 'permanentemail'],
4463: $udom,$uname);
4464: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4465: return %loadnames;
4466: }
4467: }
4468:
1.551 albertel 4469: sub flush_email_cache {
4470: my ($uname,$udom)=@_;
4471: if (!$udom) { $udom =$env{'user.domain'}; }
4472: if (!$uname) { $uname=$env{'user.name'}; }
4473: return if ($udom eq 'public' && $uname eq 'public');
4474: my $id=$uname.':'.$udom;
4475: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4476: }
4477:
1.728 raeburn 4478: # -------------------------------------------------------------------- getlangs
4479:
4480: =pod
4481:
4482: =item * &getlangs($uname,$udom)
4483:
4484: Gets a user's language preference and returns it as a hash with key:
4485: language.
4486:
4487: =cut
4488:
4489:
4490: sub getlangs {
4491: my ($uname,$udom) = @_;
4492: if (!$udom) { $udom =$env{'user.domain'}; }
4493: if (!$uname) { $uname=$env{'user.name'}; }
4494: my $id=$uname.':'.$udom;
4495: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4496: if ($cached) {
4497: return %{$langs};
4498: } else {
4499: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4500: $udom,$uname);
4501: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4502: return %loadlangs;
4503: }
4504: }
4505:
4506: sub flush_langs_cache {
4507: my ($uname,$udom)=@_;
4508: if (!$udom) { $udom =$env{'user.domain'}; }
4509: if (!$uname) { $uname=$env{'user.name'}; }
4510: return if ($udom eq 'public' && $uname eq 'public');
4511: my $id=$uname.':'.$udom;
4512: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4513: }
4514:
1.61 www 4515: # ------------------------------------------------------------------ Screenname
1.81 albertel 4516:
4517: =pod
4518:
1.648 raeburn 4519: =item * &screenname($uname,$udom)
1.81 albertel 4520:
4521: Gets a users screenname and returns it as a string
4522:
4523: =cut
1.61 www 4524:
4525: sub screenname {
4526: my ($uname,$udom)=@_;
1.258 albertel 4527: if ($uname eq $env{'user.name'} &&
4528: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4529: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4530: return $names{'screenname'};
1.62 www 4531: }
4532:
1.212 albertel 4533:
1.802 bisitz 4534: # ------------------------------------------------------------- Confirm Wrapper
4535: =pod
4536:
1.1142 raeburn 4537: =item * &confirmwrapper($message)
1.802 bisitz 4538:
4539: Wrap messages about completion of operation in box
4540:
4541: =cut
4542:
4543: sub confirmwrapper {
4544: my ($message)=@_;
4545: if ($message) {
4546: return "\n".'<div class="LC_confirm_box">'."\n"
4547: .$message."\n"
4548: .'</div>'."\n";
4549: } else {
4550: return $message;
4551: }
4552: }
4553:
1.62 www 4554: # ------------------------------------------------------------- Message Wrapper
4555:
4556: sub messagewrapper {
1.369 www 4557: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4558: return
1.441 albertel 4559: '<a href="/adm/email?compose=individual&'.
4560: 'recname='.$username.'&recdom='.$domain.
4561: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4562: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4563: }
1.802 bisitz 4564:
1.74 www 4565: # --------------------------------------------------------------- Notes Wrapper
4566:
4567: sub noteswrapper {
4568: my ($link,$un,$do)=@_;
4569: return
1.896 amueller 4570: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4571: }
1.802 bisitz 4572:
1.62 www 4573: # ------------------------------------------------------------- Aboutme Wrapper
4574:
4575: sub aboutmewrapper {
1.1070 raeburn 4576: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4577: if (!defined($username) && !defined($domain)) {
4578: return;
4579: }
1.1096 raeburn 4580: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4581: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4582: }
4583:
4584: # ------------------------------------------------------------ Syllabus Wrapper
4585:
4586: sub syllabuswrapper {
1.707 bisitz 4587: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4588: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4589: }
1.14 harris41 4590:
1.1397 raeburn 4591: # -----------------------------------------------------------------------------
4592:
1.1396 raeburn 4593: sub aboutme_on {
4594: my ($uname,$udom)=@_;
4595: unless ($uname) { $uname=$env{'user.name'}; }
4596: unless ($udom) { $udom=$env{'user.domain'}; }
4597: return if ($udom eq 'public' && $uname eq 'public');
4598: my $hashkey=$uname.':'.$udom;
4599: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4600: if ($cached) {
4601: return $aboutme;
4602: }
4603: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4604: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4605: return $aboutme;
4606: }
4607:
4608: sub devalidate_aboutme_cache {
4609: my ($uname,$udom)=@_;
4610: if (!$udom) { $udom =$env{'user.domain'}; }
4611: if (!$uname) { $uname=$env{'user.name'}; }
4612: return if ($udom eq 'public' && $uname eq 'public');
4613: my $id=$uname.':'.$udom;
4614: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4615: }
4616:
1.208 matthew 4617: sub track_student_link {
1.887 raeburn 4618: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4619: my $link ="/adm/trackstudent?";
1.208 matthew 4620: my $title = 'View recent activity';
4621: if (defined($sname) && $sname !~ /^\s*$/ &&
4622: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4623: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4624: $title .= ' of this student';
1.268 albertel 4625: }
1.208 matthew 4626: if (defined($target) && $target !~ /^\s*$/) {
4627: $target = qq{target="$target"};
4628: } else {
4629: $target = '';
4630: }
1.268 albertel 4631: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4632: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4633: $title = &mt($title);
4634: $linktext = &mt($linktext);
1.448 albertel 4635: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4636: &help_open_topic('View_recent_activity');
1.208 matthew 4637: }
4638:
1.781 raeburn 4639: sub slot_reservations_link {
4640: my ($linktext,$sname,$sdom,$target) = @_;
4641: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4642: my $title = 'View slot reservation history';
4643: if (defined($sname) && $sname !~ /^\s*$/ &&
4644: defined($sdom) && $sdom !~ /^\s*$/) {
4645: $link .= "&uname=$sname&udom=$sdom";
4646: $title .= ' of this student';
4647: }
4648: if (defined($target) && $target !~ /^\s*$/) {
4649: $target = qq{target="$target"};
4650: } else {
4651: $target = '';
4652: }
4653: $title = &mt($title);
4654: $linktext = &mt($linktext);
4655: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4656: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4657:
4658: }
4659:
1.508 www 4660: # ===================================================== Display a student photo
4661:
4662:
1.509 albertel 4663: sub student_image_tag {
1.508 www 4664: my ($domain,$user)=@_;
4665: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4666: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4667: return '<img src="'.$imgsrc.'" align="right" />';
4668: } else {
4669: return '';
4670: }
4671: }
4672:
1.112 bowersj2 4673: =pod
4674:
4675: =back
4676:
4677: =head1 Access .tab File Data
4678:
4679: =over 4
4680:
1.648 raeburn 4681: =item * &languageids()
1.112 bowersj2 4682:
4683: returns list of all language ids
4684:
4685: =cut
4686:
1.14 harris41 4687: sub languageids {
1.16 harris41 4688: return sort(keys(%language));
1.14 harris41 4689: }
4690:
1.112 bowersj2 4691: =pod
4692:
1.648 raeburn 4693: =item * &languagedescription()
1.112 bowersj2 4694:
4695: returns description of a specified language id
4696:
4697: =cut
4698:
1.14 harris41 4699: sub languagedescription {
1.125 www 4700: my $code=shift;
4701: return ($supported_language{$code}?'* ':'').
4702: $language{$code}.
1.126 www 4703: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4704: }
4705:
1.1048 foxr 4706: =pod
4707:
4708: =item * &plainlanguagedescription
4709:
4710: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4711: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4712:
4713: =cut
4714:
1.145 www 4715: sub plainlanguagedescription {
4716: my $code=shift;
4717: return $language{$code};
4718: }
4719:
1.1048 foxr 4720: =pod
4721:
4722: =item * &supportedlanguagecode
4723:
4724: Returns the supported language code (e.g. sptutf maps to pt) given a language
4725: code.
4726:
4727: =cut
4728:
1.145 www 4729: sub supportedlanguagecode {
4730: my $code=shift;
4731: return $supported_language{$code};
1.97 www 4732: }
4733:
1.112 bowersj2 4734: =pod
4735:
1.1048 foxr 4736: =item * &latexlanguage()
4737:
4738: Given a language key code returns the correspondnig language to use
4739: to select the correct hyphenation on LaTeX printouts. This is undef if there
4740: is no supported hyphenation for the language code.
4741:
4742: =cut
4743:
4744: sub latexlanguage {
4745: my $code = shift;
4746: return $latex_language{$code};
4747: }
4748:
4749: =pod
4750:
4751: =item * &latexhyphenation()
4752:
4753: Same as above but what's supplied is the language as it might be stored
4754: in the metadata.
4755:
4756: =cut
4757:
4758: sub latexhyphenation {
4759: my $key = shift;
4760: return $latex_language_bykey{$key};
4761: }
4762:
4763: =pod
4764:
1.648 raeburn 4765: =item * ©rightids()
1.112 bowersj2 4766:
4767: returns list of all copyrights
4768:
4769: =cut
4770:
4771: sub copyrightids {
4772: return sort(keys(%cprtag));
4773: }
4774:
4775: =pod
4776:
1.648 raeburn 4777: =item * ©rightdescription()
1.112 bowersj2 4778:
4779: returns description of a specified copyright id
4780:
4781: =cut
4782:
4783: sub copyrightdescription {
1.166 www 4784: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4785: }
1.197 matthew 4786:
4787: =pod
4788:
1.648 raeburn 4789: =item * &source_copyrightids()
1.192 taceyjo1 4790:
4791: returns list of all source copyrights
4792:
4793: =cut
4794:
4795: sub source_copyrightids {
4796: return sort(keys(%scprtag));
4797: }
4798:
4799: =pod
4800:
1.648 raeburn 4801: =item * &source_copyrightdescription()
1.192 taceyjo1 4802:
4803: returns description of a specified source copyright id
4804:
4805: =cut
4806:
4807: sub source_copyrightdescription {
4808: return &mt($scprtag{shift(@_)});
4809: }
1.112 bowersj2 4810:
4811: =pod
4812:
1.648 raeburn 4813: =item * &filecategories()
1.112 bowersj2 4814:
4815: returns list of all file categories
4816:
4817: =cut
4818:
4819: sub filecategories {
4820: return sort(keys(%category_extensions));
4821: }
4822:
4823: =pod
4824:
1.648 raeburn 4825: =item * &filecategorytypes()
1.112 bowersj2 4826:
4827: returns list of file types belonging to a given file
4828: category
4829:
4830: =cut
4831:
4832: sub filecategorytypes {
1.356 albertel 4833: my ($cat) = @_;
1.1248 raeburn 4834: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4835: return @{$category_extensions{lc($cat)}};
4836: } else {
4837: return ();
4838: }
1.112 bowersj2 4839: }
4840:
4841: =pod
4842:
1.648 raeburn 4843: =item * &fileembstyle()
1.112 bowersj2 4844:
4845: returns embedding style for a specified file type
4846:
4847: =cut
4848:
4849: sub fileembstyle {
4850: return $fe{lc(shift(@_))};
1.169 www 4851: }
4852:
1.351 www 4853: sub filemimetype {
4854: return $fm{lc(shift(@_))};
4855: }
4856:
1.169 www 4857:
4858: sub filecategoryselect {
4859: my ($name,$value)=@_;
1.189 matthew 4860: return &select_form($value,$name,
1.970 raeburn 4861: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4862: }
4863:
4864: =pod
4865:
1.648 raeburn 4866: =item * &filedescription()
1.112 bowersj2 4867:
4868: returns description for a specified file type
4869:
4870: =cut
4871:
4872: sub filedescription {
1.188 matthew 4873: my $file_description = $fd{lc(shift())};
4874: $file_description =~ s:([\[\]]):~$1:g;
4875: return &mt($file_description);
1.112 bowersj2 4876: }
4877:
4878: =pod
4879:
1.648 raeburn 4880: =item * &filedescriptionex()
1.112 bowersj2 4881:
4882: returns description for a specified file type with
4883: extra formatting
4884:
4885: =cut
4886:
4887: sub filedescriptionex {
4888: my $ex=shift;
1.188 matthew 4889: my $file_description = $fd{lc($ex)};
4890: $file_description =~ s:([\[\]]):~$1:g;
4891: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4892: }
4893:
4894: # End of .tab access
4895: =pod
4896:
4897: =back
4898:
4899: =cut
4900:
4901: # ------------------------------------------------------------------ File Types
4902: sub fileextensions {
4903: return sort(keys(%fe));
4904: }
4905:
1.97 www 4906: # ----------------------------------------------------------- Display Languages
4907: # returns a hash with all desired display languages
4908: #
4909:
4910: sub display_languages {
4911: my %languages=();
1.695 raeburn 4912: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4913: $languages{$lang}=1;
1.97 www 4914: }
4915: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4916: if ($env{'form.displaylanguage'}) {
1.356 albertel 4917: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4918: $languages{$lang}=1;
1.97 www 4919: }
4920: }
4921: return %languages;
1.14 harris41 4922: }
4923:
1.582 albertel 4924: sub languages {
4925: my ($possible_langs) = @_;
1.695 raeburn 4926: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4927: if (!ref($possible_langs)) {
4928: if( wantarray ) {
4929: return @preferred_langs;
4930: } else {
4931: return $preferred_langs[0];
4932: }
4933: }
4934: my %possibilities = map { $_ => 1 } (@$possible_langs);
4935: my @preferred_possibilities;
4936: foreach my $preferred_lang (@preferred_langs) {
4937: if (exists($possibilities{$preferred_lang})) {
4938: push(@preferred_possibilities, $preferred_lang);
4939: }
4940: }
4941: if( wantarray ) {
4942: return @preferred_possibilities;
4943: }
4944: return $preferred_possibilities[0];
4945: }
4946:
1.742 raeburn 4947: sub user_lang {
4948: my ($touname,$toudom,$fromcid) = @_;
4949: my @userlangs;
4950: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4951: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4952: $env{'course.'.$fromcid.'.languages'}));
4953: } else {
4954: my %langhash = &getlangs($touname,$toudom);
4955: if ($langhash{'languages'} ne '') {
4956: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4957: } else {
4958: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4959: if ($domdefs{'lang_def'} ne '') {
4960: @userlangs = ($domdefs{'lang_def'});
4961: }
4962: }
4963: }
4964: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4965: my $user_lh = Apache::localize->get_handle(@languages);
4966: return $user_lh;
4967: }
4968:
4969:
1.112 bowersj2 4970: ###############################################################
4971: ## Student Answer Attempts ##
4972: ###############################################################
4973:
4974: =pod
4975:
4976: =head1 Alternate Problem Views
4977:
4978: =over 4
4979:
1.648 raeburn 4980: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4981: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4982:
4983: Return string with previous attempt on problem. Arguments:
4984:
4985: =over 4
4986:
4987: =item * $symb: Problem, including path
4988:
4989: =item * $username: username of the desired student
4990:
4991: =item * $domain: domain of the desired student
1.14 harris41 4992:
1.112 bowersj2 4993: =item * $course: Course ID
1.14 harris41 4994:
1.112 bowersj2 4995: =item * $getattempt: Leave blank for all attempts, otherwise put
4996: something
1.14 harris41 4997:
1.112 bowersj2 4998: =item * $regexp: if string matches this regexp, the string will be
4999: sent to $gradesub
1.14 harris41 5000:
1.112 bowersj2 5001: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 5002:
1.1199 raeburn 5003: =item * $usec: section of the desired student
5004:
5005: =item * $identifier: counter for student (multiple students one problem) or
5006: problem (one student; whole sequence).
5007:
1.112 bowersj2 5008: =back
1.14 harris41 5009:
1.112 bowersj2 5010: The output string is a table containing all desired attempts, if any.
1.16 harris41 5011:
1.112 bowersj2 5012: =cut
1.1 albertel 5013:
5014: sub get_previous_attempt {
1.1199 raeburn 5015: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 5016: my $prevattempts='';
1.43 ng 5017: no strict 'refs';
1.1 albertel 5018: if ($symb) {
1.3 albertel 5019: my (%returnhash)=
5020: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 5021: if ($returnhash{'version'}) {
5022: my %lasthash=();
5023: my $version;
5024: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 5025: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
5026: if ($key =~ /\.rawrndseed$/) {
5027: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
5028: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
5029: } else {
5030: $lasthash{$key}=$returnhash{$version.':'.$key};
5031: }
1.19 harris41 5032: }
1.1 albertel 5033: }
1.596 albertel 5034: $prevattempts=&start_data_table().&start_data_table_header_row();
5035: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 5036: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 5037: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 5038: foreach my $key (sort(keys(%lasthash))) {
5039: my ($ign,@parts) = split(/\./,$key);
1.41 ng 5040: if ($#parts > 0) {
1.31 albertel 5041: my $data=$parts[-1];
1.989 raeburn 5042: next if ($data eq 'foilorder');
1.31 albertel 5043: pop(@parts);
1.1010 www 5044: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 5045: if ($data eq 'type') {
5046: unless ($showsurv) {
5047: my $id = join(',',@parts);
5048: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 5049: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
5050: $lasthidden{$ign.'.'.$id} = 1;
5051: }
1.945 raeburn 5052: }
1.1199 raeburn 5053: if ($identifier ne '') {
5054: my $id = join(',',@parts);
5055: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
5056: $domain,$username,$usec,undef,$course) =~ /^no/) {
5057: $hidestatus{$ign.'.'.$id} = 1;
5058: }
5059: }
5060: } elsif ($data eq 'regrader') {
5061: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 5062: my $id = join(',',@parts);
5063: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 5064: }
1.1010 www 5065: }
1.31 albertel 5066: } else {
1.41 ng 5067: if ($#parts == 0) {
5068: $prevattempts.='<th>'.$parts[0].'</th>';
5069: } else {
5070: $prevattempts.='<th>'.$ign.'</th>';
5071: }
1.31 albertel 5072: }
1.16 harris41 5073: }
1.596 albertel 5074: $prevattempts.=&end_data_table_header_row();
1.40 ng 5075: if ($getattempt eq '') {
1.1199 raeburn 5076: my (%solved,%resets,%probstatus);
1.1200 raeburn 5077: if (($identifier ne '') && (keys(%regraded) > 0)) {
5078: for ($version=1;$version<=$returnhash{'version'};$version++) {
5079: foreach my $id (keys(%regraded)) {
5080: if (($returnhash{$version.':'.$id.'.regrader'}) &&
5081: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
5082: ($returnhash{$version.':'.$id.'.award'} eq '')) {
5083: push(@{$resets{$id}},$version);
1.1199 raeburn 5084: }
5085: }
5086: }
1.1200 raeburn 5087: }
5088: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 5089: my (@hidden,@unsolved);
1.945 raeburn 5090: if (%typeparts) {
5091: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 5092: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
5093: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 5094: push(@hidden,$id);
1.1199 raeburn 5095: } elsif ($identifier ne '') {
5096: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
5097: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
5098: ($hidestatus{$id})) {
1.1200 raeburn 5099: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 5100: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
5101: push(@{$solved{$id}},$version);
5102: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
5103: (ref($solved{$id}) eq 'ARRAY')) {
5104: my $skip;
5105: if (ref($resets{$id}) eq 'ARRAY') {
5106: foreach my $reset (@{$resets{$id}}) {
5107: if ($reset > $solved{$id}[-1]) {
5108: $skip=1;
5109: last;
5110: }
5111: }
5112: }
5113: unless ($skip) {
5114: my ($ign,$partslist) = split(/\./,$id,2);
5115: push(@unsolved,$partslist);
5116: }
5117: }
5118: }
1.945 raeburn 5119: }
5120: }
5121: }
5122: $prevattempts.=&start_data_table_row().
1.1199 raeburn 5123: '<td>'.&mt('Transaction [_1]',$version);
5124: if (@unsolved) {
5125: $prevattempts .= '<span class="LC_nobreak"><label>'.
5126: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
5127: &mt('Hide').'</label></span>';
5128: }
5129: $prevattempts .= '</td>';
1.945 raeburn 5130: if (@hidden) {
5131: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5132: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5133: my $hide;
5134: foreach my $id (@hidden) {
5135: if ($key =~ /^\Q$id\E/) {
5136: $hide = 1;
5137: last;
5138: }
5139: }
5140: if ($hide) {
5141: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5142: if (($data eq 'award') || ($data eq 'awarddetail')) {
5143: my $value = &format_previous_attempt_value($key,
5144: $returnhash{$version.':'.$key});
1.1173 kruse 5145: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5146: } else {
5147: $prevattempts.='<td> </td>';
5148: }
5149: } else {
5150: if ($key =~ /\./) {
1.1212 raeburn 5151: my $value = $returnhash{$version.':'.$key};
5152: if ($key =~ /\.rndseed$/) {
5153: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5154: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5155: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5156: }
5157: }
5158: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5159: ' </td>';
1.945 raeburn 5160: } else {
5161: $prevattempts.='<td> </td>';
5162: }
5163: }
5164: }
5165: } else {
5166: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5167: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 5168: my $value = $returnhash{$version.':'.$key};
5169: if ($key =~ /\.rndseed$/) {
5170: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5171: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5172: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5173: }
5174: }
5175: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5176: ' </td>';
1.945 raeburn 5177: }
5178: }
5179: $prevattempts.=&end_data_table_row();
1.40 ng 5180: }
1.1 albertel 5181: }
1.945 raeburn 5182: my @currhidden = keys(%lasthidden);
1.596 albertel 5183: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 5184: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5185: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5186: if (%typeparts) {
5187: my $hidden;
5188: foreach my $id (@currhidden) {
5189: if ($key =~ /^\Q$id\E/) {
5190: $hidden = 1;
5191: last;
5192: }
5193: }
5194: if ($hidden) {
5195: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5196: if (($data eq 'award') || ($data eq 'awarddetail')) {
5197: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5198: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5199: $value = &$gradesub($value);
5200: }
1.1173 kruse 5201: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5202: } else {
5203: $prevattempts.='<td> </td>';
5204: }
5205: } else {
5206: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5207: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5208: $value = &$gradesub($value);
5209: }
1.1173 kruse 5210: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5211: }
5212: } else {
5213: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5214: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5215: $value = &$gradesub($value);
5216: }
1.1173 kruse 5217: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5218: }
1.16 harris41 5219: }
1.596 albertel 5220: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5221: } else {
1.1305 raeburn 5222: my $msg;
5223: if ($symb =~ /ext\.tool$/) {
5224: $msg = &mt('No grade passed back.');
5225: } else {
5226: $msg = &mt('Nothing submitted - no attempts.');
5227: }
1.596 albertel 5228: $prevattempts=
5229: &start_data_table().&start_data_table_row().
1.1305 raeburn 5230: '<td>'.$msg.'</td>'.
1.596 albertel 5231: &end_data_table_row().&end_data_table();
1.1 albertel 5232: }
5233: } else {
1.596 albertel 5234: $prevattempts=
5235: &start_data_table().&start_data_table_row().
5236: '<td>'.&mt('No data.').'</td>'.
5237: &end_data_table_row().&end_data_table();
1.1 albertel 5238: }
1.10 albertel 5239: }
5240:
1.581 albertel 5241: sub format_previous_attempt_value {
5242: my ($key,$value) = @_;
1.1011 www 5243: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5244: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5245: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5246: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5247: } elsif ($key =~ /answerstring$/) {
5248: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5249: my @answer = %answers;
5250: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5251: my @anskeys = sort(keys(%answers));
5252: if (@anskeys == 1) {
5253: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5254: if ($answer =~ m{\0}) {
5255: $answer =~ s{\0}{,}g;
1.988 raeburn 5256: }
5257: my $tag_internal_answer_name = 'INTERNAL';
5258: if ($anskeys[0] eq $tag_internal_answer_name) {
5259: $value = $answer;
5260: } else {
5261: $value = $anskeys[0].'='.$answer;
5262: }
5263: } else {
5264: foreach my $ans (@anskeys) {
5265: my $answer = $answers{$ans};
1.1001 raeburn 5266: if ($answer =~ m{\0}) {
5267: $answer =~ s{\0}{,}g;
1.988 raeburn 5268: }
5269: $value .= $ans.'='.$answer.'<br />';;
5270: }
5271: }
1.581 albertel 5272: } else {
1.1173 kruse 5273: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5274: }
5275: return $value;
5276: }
5277:
5278:
1.107 albertel 5279: sub relative_to_absolute {
5280: my ($url,$output)=@_;
5281: my $parser=HTML::TokeParser->new(\$output);
5282: my $token;
5283: my $thisdir=$url;
5284: my @rlinks=();
5285: while ($token=$parser->get_token) {
5286: if ($token->[0] eq 'S') {
5287: if ($token->[1] eq 'a') {
5288: if ($token->[2]->{'href'}) {
5289: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5290: }
5291: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5292: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5293: } elsif ($token->[1] eq 'base') {
5294: $thisdir=$token->[2]->{'href'};
5295: }
5296: }
5297: }
5298: $thisdir=~s-/[^/]*$--;
1.356 albertel 5299: foreach my $link (@rlinks) {
1.726 raeburn 5300: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5301: ($link=~/^\//) ||
5302: ($link=~/^javascript:/i) ||
5303: ($link=~/^mailto:/i) ||
5304: ($link=~/^\#/)) {
5305: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5306: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5307: }
5308: }
5309: # -------------------------------------------------- Deal with Applet codebases
5310: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5311: return $output;
5312: }
5313:
1.112 bowersj2 5314: =pod
5315:
1.648 raeburn 5316: =item * &get_student_view()
1.112 bowersj2 5317:
5318: show a snapshot of what student was looking at
5319:
5320: =cut
5321:
1.10 albertel 5322: sub get_student_view {
1.186 albertel 5323: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5324: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5325: my (%form);
1.10 albertel 5326: my @elements=('symb','courseid','domain','username');
5327: foreach my $element (@elements) {
1.186 albertel 5328: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5329: }
1.186 albertel 5330: if (defined($moreenv)) {
5331: %form=(%form,%{$moreenv});
5332: }
1.236 albertel 5333: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5334: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5335: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5336: $feedurl =~ s{^/adm/wrapper}{};
5337: }
1.650 www 5338: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5339: $userview=~s/\<body[^\>]*\>//gi;
5340: $userview=~s/\<\/body\>//gi;
5341: $userview=~s/\<html\>//gi;
5342: $userview=~s/\<\/html\>//gi;
5343: $userview=~s/\<head\>//gi;
5344: $userview=~s/\<\/head\>//gi;
5345: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5346: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5347: if (wantarray) {
5348: return ($userview,$response);
5349: } else {
5350: return $userview;
5351: }
5352: }
5353:
5354: sub get_student_view_with_retries {
5355: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5356:
5357: my $ok = 0; # True if we got a good response.
5358: my $content;
5359: my $response;
5360:
5361: # Try to get the student_view done. within the retries count:
5362:
5363: do {
5364: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5365: $ok = $response->is_success;
5366: if (!$ok) {
5367: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5368: }
5369: $retries--;
5370: } while (!$ok && ($retries > 0));
5371:
5372: if (!$ok) {
5373: $content = ''; # On error return an empty content.
5374: }
1.651 www 5375: if (wantarray) {
5376: return ($content, $response);
5377: } else {
5378: return $content;
5379: }
1.11 albertel 5380: }
5381:
1.1349 raeburn 5382: sub css_links {
5383: my ($currsymb,$level) = @_;
5384: my ($links,@symbs,%cssrefs,%httpref);
5385: if ($level eq 'map') {
5386: my $navmap = Apache::lonnavmaps::navmap->new();
5387: if (ref($navmap)) {
5388: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5389: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5390: foreach my $res (@resources) {
5391: if (ref($res) && $res->symb()) {
5392: push(@symbs,$res->symb());
5393: }
5394: }
5395: }
5396: } else {
5397: @symbs = ($currsymb);
5398: }
5399: foreach my $symb (@symbs) {
5400: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5401: if ($css_href =~ /\S/) {
5402: unless ($css_href =~ m{https?://}) {
5403: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5404: my $proburl = &Apache::lonnet::clutter($url);
5405: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5406: unless ($css_href =~ m{^/}) {
5407: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5408: }
5409: if ($css_href =~ m{^/(res|uploaded)/}) {
5410: unless (($httpref{'httpref.'.$css_href}) ||
5411: (&Apache::lonnet::is_on_map($css_href))) {
5412: my $thisurl = $proburl;
5413: if ($env{'httpref.'.$proburl}) {
5414: $thisurl = $env{'httpref.'.$proburl};
5415: }
5416: $httpref{'httpref.'.$css_href} = $thisurl;
5417: }
5418: }
5419: }
5420: $cssrefs{$css_href} = 1;
5421: }
5422: }
5423: if (keys(%httpref)) {
5424: &Apache::lonnet::appenv(\%httpref);
5425: }
5426: if (keys(%cssrefs)) {
5427: foreach my $css_href (keys(%cssrefs)) {
5428: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5429: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5430: }
5431: }
5432: return $links;
5433: }
5434:
1.112 bowersj2 5435: =pod
5436:
1.648 raeburn 5437: =item * &get_student_answers()
1.112 bowersj2 5438:
5439: show a snapshot of how student was answering problem
5440:
5441: =cut
5442:
1.11 albertel 5443: sub get_student_answers {
1.100 sakharuk 5444: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5445: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5446: my (%moreenv);
1.11 albertel 5447: my @elements=('symb','courseid','domain','username');
5448: foreach my $element (@elements) {
1.186 albertel 5449: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5450: }
1.186 albertel 5451: $moreenv{'grade_target'}='answer';
5452: %moreenv=(%form,%moreenv);
1.497 raeburn 5453: $feedurl = &Apache::lonnet::clutter($feedurl);
5454: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5455: return $userview;
1.1 albertel 5456: }
1.116 albertel 5457:
5458: =pod
5459:
5460: =item * &submlink()
5461:
1.242 albertel 5462: Inputs: $text $uname $udom $symb $target
1.116 albertel 5463:
5464: Returns: A link to grades.pm such as to see the SUBM view of a student
5465:
5466: =cut
5467:
5468: ###############################################
5469: sub submlink {
1.242 albertel 5470: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5471: if (!($uname && $udom)) {
5472: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5473: &Apache::lonnet::whichuser($symb);
1.116 albertel 5474: if (!$symb) { $symb=$cursymb; }
5475: }
1.254 matthew 5476: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5477: $symb=&escape($symb);
1.960 bisitz 5478: if ($target) { $target=" target=\"$target\""; }
5479: return
5480: '<a href="/adm/grades?command=submission'.
5481: '&symb='.$symb.
5482: '&student='.$uname.
5483: '&userdom='.$udom.'"'.
5484: $target.'>'.$text.'</a>';
1.242 albertel 5485: }
5486: ##############################################
5487:
5488: =pod
5489:
5490: =item * &pgrdlink()
5491:
5492: Inputs: $text $uname $udom $symb $target
5493:
5494: Returns: A link to grades.pm such as to see the PGRD view of a student
5495:
5496: =cut
5497:
5498: ###############################################
5499: sub pgrdlink {
5500: my $link=&submlink(@_);
5501: $link=~s/(&command=submission)/$1&showgrading=yes/;
5502: return $link;
5503: }
5504: ##############################################
5505:
5506: =pod
5507:
5508: =item * &pprmlink()
5509:
5510: Inputs: $text $uname $udom $symb $target
5511:
5512: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5513: student and a specific resource
1.242 albertel 5514:
5515: =cut
5516:
5517: ###############################################
5518: sub pprmlink {
5519: my ($text,$uname,$udom,$symb,$target)=@_;
5520: if (!($uname && $udom)) {
5521: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5522: &Apache::lonnet::whichuser($symb);
1.242 albertel 5523: if (!$symb) { $symb=$cursymb; }
5524: }
1.254 matthew 5525: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5526: $symb=&escape($symb);
1.242 albertel 5527: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5528: return '<a href="/adm/parmset?command=set&'.
5529: 'symb='.$symb.'&uname='.$uname.
5530: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5531: }
5532: ##############################################
1.37 matthew 5533:
1.112 bowersj2 5534: =pod
5535:
5536: =back
5537:
5538: =cut
5539:
1.37 matthew 5540: ###############################################
1.51 www 5541:
5542:
5543: sub timehash {
1.687 raeburn 5544: my ($thistime) = @_;
5545: my $timezone = &Apache::lonlocal::gettimezone();
5546: my $dt = DateTime->from_epoch(epoch => $thistime)
5547: ->set_time_zone($timezone);
5548: my $wday = $dt->day_of_week();
5549: if ($wday == 7) { $wday = 0; }
5550: return ( 'second' => $dt->second(),
5551: 'minute' => $dt->minute(),
5552: 'hour' => $dt->hour(),
5553: 'day' => $dt->day_of_month(),
5554: 'month' => $dt->month(),
5555: 'year' => $dt->year(),
5556: 'weekday' => $wday,
5557: 'dayyear' => $dt->day_of_year(),
5558: 'dlsav' => $dt->is_dst() );
1.51 www 5559: }
5560:
1.370 www 5561: sub utc_string {
5562: my ($date)=@_;
1.371 www 5563: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5564: }
5565:
1.51 www 5566: sub maketime {
5567: my %th=@_;
1.687 raeburn 5568: my ($epoch_time,$timezone,$dt);
5569: $timezone = &Apache::lonlocal::gettimezone();
5570: eval {
5571: $dt = DateTime->new( year => $th{'year'},
5572: month => $th{'month'},
5573: day => $th{'day'},
5574: hour => $th{'hour'},
5575: minute => $th{'minute'},
5576: second => $th{'second'},
5577: time_zone => $timezone,
5578: );
5579: };
5580: if (!$@) {
5581: $epoch_time = $dt->epoch;
5582: if ($epoch_time) {
5583: return $epoch_time;
5584: }
5585: }
1.51 www 5586: return POSIX::mktime(
5587: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5588: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5589: }
5590:
5591: #########################################
1.51 www 5592:
5593: sub findallcourses {
1.482 raeburn 5594: my ($roles,$uname,$udom) = @_;
1.355 albertel 5595: my %roles;
5596: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5597: my %courses;
1.51 www 5598: my $now=time;
1.482 raeburn 5599: if (!defined($uname)) {
5600: $uname = $env{'user.name'};
5601: }
5602: if (!defined($udom)) {
5603: $udom = $env{'user.domain'};
5604: }
5605: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5606: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5607: if (!%roles) {
5608: %roles = (
5609: cc => 1,
1.907 raeburn 5610: co => 1,
1.482 raeburn 5611: in => 1,
5612: ep => 1,
5613: ta => 1,
5614: cr => 1,
5615: st => 1,
5616: );
5617: }
5618: foreach my $entry (keys(%roleshash)) {
5619: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5620: if ($trole =~ /^cr/) {
5621: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5622: } else {
5623: next if (!exists($roles{$trole}));
5624: }
5625: if ($tend) {
5626: next if ($tend < $now);
5627: }
5628: if ($tstart) {
5629: next if ($tstart > $now);
5630: }
1.1058 raeburn 5631: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5632: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5633: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5634: if ($secpart eq '') {
5635: ($cnum,$role) = split(/_/,$cnumpart);
5636: $sec = 'none';
1.1058 raeburn 5637: $value .= $cnum.'/';
1.482 raeburn 5638: } else {
5639: $cnum = $cnumpart;
5640: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5641: $value .= $cnum.'/'.$sec;
5642: }
5643: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5644: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5645: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5646: }
5647: } else {
5648: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5649: }
1.482 raeburn 5650: }
5651: } else {
5652: foreach my $key (keys(%env)) {
1.483 albertel 5653: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5654: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5655: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5656: next if ($role eq 'ca' || $role eq 'aa');
5657: next if (%roles && !exists($roles{$role}));
5658: my ($starttime,$endtime)=split(/\./,$env{$key});
5659: my $active=1;
5660: if ($starttime) {
5661: if ($now<$starttime) { $active=0; }
5662: }
5663: if ($endtime) {
5664: if ($now>$endtime) { $active=0; }
5665: }
5666: if ($active) {
1.1058 raeburn 5667: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5668: if ($sec eq '') {
5669: $sec = 'none';
1.1058 raeburn 5670: } else {
5671: $value .= $sec;
5672: }
5673: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5674: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5675: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5676: }
5677: } else {
5678: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5679: }
1.474 raeburn 5680: }
5681: }
1.51 www 5682: }
5683: }
1.474 raeburn 5684: return %courses;
1.51 www 5685: }
1.37 matthew 5686:
1.54 www 5687: ###############################################
1.474 raeburn 5688:
5689: sub blockcheck {
1.1372 raeburn 5690: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5691: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5692: my ($has_evb,$check_ipaccess);
5693: my $dom = $env{'user.domain'};
5694: if ($env{'request.course.id'}) {
5695: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5696: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5697: my $checkrole = "cm./$cdom/$cnum";
5698: my $sec = $env{'request.course.sec'};
5699: if ($sec ne '') {
5700: $checkrole .= "/$sec";
5701: }
5702: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5703: ($env{'request.role'} !~ /^st/)) {
5704: $has_evb = 1;
5705: }
5706: unless ($has_evb) {
5707: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
1.1444 raeburn 5708: ($activity eq 'index') || ($activity eq 'boards') || ($activity eq 'groups') ||
5709: ($activity eq 'chat')) {
1.1372 raeburn 5710: if ($udom eq $cdom) {
5711: $check_ipaccess = 1;
5712: }
5713: }
5714: }
1.1375 raeburn 5715: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5716: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5717: my $checkrole;
5718: if ($env{'request.role.domain'} eq '') {
5719: $checkrole = "cm./$env{'user.domain'}/";
5720: } else {
5721: $checkrole = "cm./$env{'request.role.domain'}/";
5722: }
5723: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5724: $has_evb = 1;
5725: }
1.1372 raeburn 5726: }
5727: unless ($has_evb || $check_ipaccess) {
5728: my @machinedoms = &Apache::lonnet::current_machine_domains();
5729: if (($dom eq 'public') && ($activity eq 'port')) {
5730: $dom = $udom;
5731: }
5732: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5733: $check_ipaccess = 1;
5734: } else {
5735: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5736: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5737: my $prim = &Apache::lonnet::domain($dom,'primary');
5738: my $intdom = &Apache::lonnet::internet_dom($prim);
5739: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5740: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5741: $check_ipaccess = 1;
5742: }
5743: }
5744: }
5745: }
5746: if ($check_ipaccess) {
5747: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5748: unless (defined($cached)) {
5749: my %domconfig =
5750: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5751: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5752: }
5753: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5754: foreach my $id (keys(%{$ipaccessref})) {
5755: if (ref($ipaccessref->{$id}) eq 'HASH') {
5756: my $range = $ipaccessref->{$id}->{'ip'};
5757: if ($range) {
5758: if (&Apache::lonnet::ip_match($clientip,$range)) {
5759: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5760: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5761: return ('','','',$id,$dom);
5762: last;
5763: }
5764: }
5765: }
5766: }
5767: }
5768: }
5769: }
5770: }
1.1373 raeburn 5771: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5772: return ();
5773: }
1.1372 raeburn 5774: }
1.1189 raeburn 5775: if (defined($udom) && defined($uname)) {
5776: # If uname and udom are for a course, check for blocks in the course.
5777: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5778: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5779: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5780: return ($startblock,$endblock,$triggerblock);
5781: }
5782: } else {
1.490 raeburn 5783: $udom = $env{'user.domain'};
5784: $uname = $env{'user.name'};
5785: }
5786:
1.502 raeburn 5787: my $startblock = 0;
5788: my $endblock = 0;
1.1062 raeburn 5789: my $triggerblock = '';
1.1373 raeburn 5790: my %live_courses;
5791: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5792: %live_courses = &findallcourses(undef,$uname,$udom);
5793: }
1.474 raeburn 5794:
1.490 raeburn 5795: # If uname is for a user, and activity is course-specific, i.e.,
5796: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5797:
1.490 raeburn 5798: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5799: $activity eq 'groups' || $activity eq 'printout' ||
1.1444 raeburn 5800: $activity eq 'search' || $activity eq 'index' ||
5801: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5802: ($env{'request.course.id'})) {
1.490 raeburn 5803: foreach my $key (keys(%live_courses)) {
5804: if ($key ne $env{'request.course.id'}) {
5805: delete($live_courses{$key});
5806: }
5807: }
5808: }
5809:
5810: my $otheruser = 0;
5811: my %own_courses;
5812: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5813: # Resource belongs to user other than current user.
5814: $otheruser = 1;
5815: # Gather courses for current user
5816: %own_courses =
5817: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5818: }
5819:
5820: # Gather active course roles - course coordinator, instructor,
5821: # exam proctor, ta, student, or custom role.
1.474 raeburn 5822:
5823: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5824: my ($cdom,$cnum);
5825: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5826: $cdom = $env{'course.'.$course.'.domain'};
5827: $cnum = $env{'course.'.$course.'.num'};
5828: } else {
1.490 raeburn 5829: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5830: }
5831: my $no_ownblock = 0;
5832: my $no_userblock = 0;
1.533 raeburn 5833: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5834: # Check if current user has 'evb' priv for this
5835: if (defined($own_courses{$course})) {
5836: foreach my $sec (keys(%{$own_courses{$course}})) {
5837: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5838: if ($sec ne 'none') {
5839: $checkrole .= '/'.$sec;
5840: }
5841: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5842: $no_ownblock = 1;
5843: last;
5844: }
5845: }
5846: }
5847: # if they have 'evb' priv and are currently not playing student
5848: next if (($no_ownblock) &&
5849: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5850: }
1.474 raeburn 5851: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5852: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5853: if ($sec ne 'none') {
1.482 raeburn 5854: $checkrole .= '/'.$sec;
1.474 raeburn 5855: }
1.490 raeburn 5856: if ($otheruser) {
5857: # Resource belongs to user other than current user.
5858: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5859: my (%allroles,%userroles);
5860: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5861: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5862: my ($trole,$tdom,$tnum,$tsec);
5863: if ($entry =~ /^cr/) {
5864: ($trole,$tdom,$tnum,$tsec) =
5865: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5866: } else {
5867: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5868: }
5869: my ($spec,$area,$trest);
5870: $area = '/'.$tdom.'/'.$tnum;
5871: $trest = $tnum;
5872: if ($tsec ne '') {
5873: $area .= '/'.$tsec;
5874: $trest .= '/'.$tsec;
5875: }
5876: $spec = $trole.'.'.$area;
5877: if ($trole =~ /^cr/) {
5878: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5879: $tdom,$spec,$trest,$area);
5880: } else {
5881: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5882: $tdom,$spec,$trest,$area);
5883: }
5884: }
1.1276 raeburn 5885: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5886: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5887: if ($1) {
5888: $no_userblock = 1;
5889: last;
5890: }
1.486 raeburn 5891: }
5892: }
1.490 raeburn 5893: } else {
5894: # Resource belongs to current user
5895: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5896: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5897: $no_ownblock = 1;
5898: last;
5899: }
1.474 raeburn 5900: }
5901: }
5902: # if they have the evb priv and are currently not playing student
1.482 raeburn 5903: next if (($no_ownblock) &&
1.491 albertel 5904: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5905: next if ($no_userblock);
1.474 raeburn 5906:
1.1303 raeburn 5907: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5908: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5909:
1.1062 raeburn 5910: my ($start,$end,$trigger) =
1.1347 raeburn 5911: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5912: if (($start != 0) &&
5913: (($startblock == 0) || ($startblock > $start))) {
5914: $startblock = $start;
1.1062 raeburn 5915: if ($trigger ne '') {
5916: $triggerblock = $trigger;
5917: }
1.502 raeburn 5918: }
5919: if (($end != 0) &&
5920: (($endblock == 0) || ($endblock < $end))) {
5921: $endblock = $end;
1.1062 raeburn 5922: if ($trigger ne '') {
5923: $triggerblock = $trigger;
5924: }
1.502 raeburn 5925: }
1.490 raeburn 5926: }
1.1062 raeburn 5927: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5928: }
5929:
5930: sub get_blocks {
1.1347 raeburn 5931: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5932: my $startblock = 0;
5933: my $endblock = 0;
1.1062 raeburn 5934: my $triggerblock = '';
1.490 raeburn 5935: my $course = $cdom.'_'.$cnum;
5936: $setters->{$course} = {};
5937: $setters->{$course}{'staff'} = [];
5938: $setters->{$course}{'times'} = [];
1.1062 raeburn 5939: $setters->{$course}{'triggers'} = [];
5940: my (@blockers,%triggered);
5941: my $now = time;
5942: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5943: if ($activity eq 'docs') {
1.1348 raeburn 5944: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5945: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5946: $blocked = 1;
5947: $nosymbcache = 1;
1.1348 raeburn 5948: $noenccheck = 1;
1.1347 raeburn 5949: }
1.1348 raeburn 5950: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5951: foreach my $block (@blockers) {
5952: if ($block =~ /^firstaccess____(.+)$/) {
5953: my $item = $1;
5954: my $type = 'map';
5955: my $timersymb = $item;
5956: if ($item eq 'course') {
5957: $type = 'course';
5958: } elsif ($item =~ /___\d+___/) {
5959: $type = 'resource';
5960: } else {
5961: $timersymb = &Apache::lonnet::symbread($item);
5962: }
5963: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5964: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5965: $triggered{$block} = {
5966: start => $start,
5967: end => $end,
5968: type => $type,
5969: };
5970: }
5971: }
5972: } else {
5973: foreach my $block (keys(%commblocks)) {
5974: if ($block =~ m/^(\d+)____(\d+)$/) {
5975: my ($start,$end) = ($1,$2);
5976: if ($start <= time && $end >= time) {
5977: if (ref($commblocks{$block}) eq 'HASH') {
5978: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5979: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5980: unless(grep(/^\Q$block\E$/,@blockers)) {
5981: push(@blockers,$block);
5982: }
5983: }
5984: }
5985: }
5986: }
5987: } elsif ($block =~ /^firstaccess____(.+)$/) {
5988: my $item = $1;
5989: my $timersymb = $item;
5990: my $type = 'map';
5991: if ($item eq 'course') {
5992: $type = 'course';
5993: } elsif ($item =~ /___\d+___/) {
5994: $type = 'resource';
5995: } else {
5996: $timersymb = &Apache::lonnet::symbread($item);
5997: }
5998: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5999: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
6000: if ($start && $end) {
6001: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 6002: if (ref($commblocks{$block}) eq 'HASH') {
6003: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
6004: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
6005: unless(grep(/^\Q$block\E$/,@blockers)) {
6006: push(@blockers,$block);
6007: $triggered{$block} = {
6008: start => $start,
6009: end => $end,
6010: type => $type,
6011: };
6012: }
6013: }
6014: }
1.1062 raeburn 6015: }
6016: }
1.490 raeburn 6017: }
1.1062 raeburn 6018: }
6019: }
6020: }
6021: foreach my $blocker (@blockers) {
6022: my ($staff_name,$staff_dom,$title,$blocks) =
6023: &parse_block_record($commblocks{$blocker});
6024: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
6025: my ($start,$end,$triggertype);
6026: if ($blocker =~ m/^(\d+)____(\d+)$/) {
6027: ($start,$end) = ($1,$2);
6028: } elsif (ref($triggered{$blocker}) eq 'HASH') {
6029: $start = $triggered{$blocker}{'start'};
6030: $end = $triggered{$blocker}{'end'};
6031: $triggertype = $triggered{$blocker}{'type'};
6032: }
6033: if ($start) {
6034: push(@{$$setters{$course}{'times'}}, [$start,$end]);
6035: if ($triggertype) {
6036: push(@{$$setters{$course}{'triggers'}},$triggertype);
6037: } else {
6038: push(@{$$setters{$course}{'triggers'}},0);
6039: }
6040: if ( ($startblock == 0) || ($startblock > $start) ) {
6041: $startblock = $start;
6042: if ($triggertype) {
6043: $triggerblock = $blocker;
1.474 raeburn 6044: }
6045: }
1.1062 raeburn 6046: if ( ($endblock == 0) || ($endblock < $end) ) {
6047: $endblock = $end;
6048: if ($triggertype) {
6049: $triggerblock = $blocker;
6050: }
6051: }
1.474 raeburn 6052: }
6053: }
1.1062 raeburn 6054: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 6055: }
6056:
6057: sub parse_block_record {
6058: my ($record) = @_;
6059: my ($setuname,$setudom,$title,$blocks);
6060: if (ref($record) eq 'HASH') {
6061: ($setuname,$setudom) = split(/:/,$record->{'setter'});
6062: $title = &unescape($record->{'event'});
6063: $blocks = $record->{'blocks'};
6064: } else {
6065: my @data = split(/:/,$record,3);
6066: if (scalar(@data) eq 2) {
6067: $title = $data[1];
6068: ($setuname,$setudom) = split(/@/,$data[0]);
6069: } else {
6070: ($setuname,$setudom,$title) = @data;
6071: }
6072: $blocks = { 'com' => 'on' };
6073: }
6074: return ($setuname,$setudom,$title,$blocks);
6075: }
6076:
1.854 kalberla 6077: sub blocking_status {
1.1372 raeburn 6078: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 6079: my %setters;
1.890 droeschl 6080:
1.1061 raeburn 6081: # check for active blocking
1.1372 raeburn 6082: if ($clientip eq '') {
6083: $clientip = &Apache::lonnet::get_requestor_ip();
6084: }
6085: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
6086: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 6087: my $blocked = 0;
1.1372 raeburn 6088: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 6089: $blocked = 1;
6090: }
1.890 droeschl 6091:
1.1061 raeburn 6092: # caller just wants to know whether a block is active
6093: if (!wantarray) { return $blocked; }
6094:
6095: # build a link to a popup window containing the details
6096: my $querystring = "?activity=$activity";
1.1351 raeburn 6097: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
6098: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 6099: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
6100: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 6101: } elsif ($activity eq 'docs') {
1.1347 raeburn 6102: my $showurl = &Apache::lonenc::check_encrypt($url);
6103: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
6104: if ($symb) {
6105: my $showsymb = &Apache::lonenc::check_encrypt($symb);
6106: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
6107: }
1.1062 raeburn 6108: }
1.1061 raeburn 6109:
6110: my $output .= <<'END_MYBLOCK';
6111: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
6112: var options = "width=" + w + ",height=" + h + ",";
6113: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
6114: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
6115: var newWin = window.open(url, wdwName, options);
6116: newWin.focus();
6117: }
1.890 droeschl 6118: END_MYBLOCK
1.854 kalberla 6119:
1.1061 raeburn 6120: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 6121:
1.1061 raeburn 6122: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 6123: my $text = &mt('Communication Blocked');
1.1217 raeburn 6124: my $class = 'LC_comblock';
1.1062 raeburn 6125: if ($activity eq 'docs') {
6126: $text = &mt('Content Access Blocked');
1.1217 raeburn 6127: $class = '';
1.1063 raeburn 6128: } elsif ($activity eq 'printout') {
6129: $text = &mt('Printing Blocked');
1.1232 raeburn 6130: } elsif ($activity eq 'passwd') {
6131: $text = &mt('Password Changing Blocked');
1.1345 raeburn 6132: } elsif ($activity eq 'grades') {
6133: $text = &mt('Gradebook Blocked');
1.1346 raeburn 6134: } elsif ($activity eq 'search') {
6135: $text = &mt('Search Blocked');
1.1444 raeburn 6136: } elsif ($activity eq 'index') {
6137: $text = &mt('Content Index Blocked');
1.1282 raeburn 6138: } elsif ($activity eq 'alert') {
6139: $text = &mt('Checking Critical Messages Blocked');
6140: } elsif ($activity eq 'reinit') {
6141: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 6142: } elsif ($activity eq 'about') {
6143: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 6144: } elsif ($activity eq 'wishlist') {
6145: $text = &mt('Access to Stored Links Blocked');
6146: } elsif ($activity eq 'annotate') {
6147: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 6148: }
1.1061 raeburn 6149: $output .= <<"END_BLOCK";
1.1217 raeburn 6150: <div class='$class'>
1.869 kalberla 6151: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6152: title='$text'>
6153: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 6154: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6155: title='$text'>$text</a>
1.867 kalberla 6156: </div>
6157:
6158: END_BLOCK
1.474 raeburn 6159:
1.1061 raeburn 6160: return ($blocked, $output);
1.854 kalberla 6161: }
1.490 raeburn 6162:
1.60 matthew 6163: ###############################################
6164:
1.682 raeburn 6165: sub check_ip_acc {
1.1201 raeburn 6166: my ($acc,$clientip)=@_;
1.682 raeburn 6167: &Apache::lonxml::debug("acc is $acc");
6168: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
6169: return 1;
6170: }
1.1339 raeburn 6171: my ($ip,$allowed);
6172: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
6173: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
6174: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
6175: } else {
1.1350 raeburn 6176: my $remote_ip = &Apache::lonnet::get_requestor_ip();
6177: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 6178: }
1.682 raeburn 6179:
6180: my $name;
1.1219 raeburn 6181: my %access = (
6182: allowfrom => 1,
6183: denyfrom => 0,
6184: );
6185: my @allows;
6186: my @denies;
6187: foreach my $item (split(',',$acc)) {
6188: $item =~ s/^\s*//;
6189: $item =~ s/\s*$//;
6190: my $pattern;
6191: if ($item =~ /^\!(.+)$/) {
6192: push(@denies,$1);
6193: } else {
6194: push(@allows,$item);
6195: }
6196: }
6197: my $numdenies = scalar(@denies);
6198: my $numallows = scalar(@allows);
6199: my $count = 0;
6200: foreach my $pattern (@denies,@allows) {
6201: $count ++;
6202: my $acctype = 'allowfrom';
6203: if ($count <= $numdenies) {
6204: $acctype = 'denyfrom';
6205: }
1.682 raeburn 6206: if ($pattern =~ /\*$/) {
6207: #35.8.*
6208: $pattern=~s/\*//;
1.1219 raeburn 6209: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6210: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6211: #35.8.3.[34-56]
6212: my $low=$2;
6213: my $high=$3;
6214: $pattern=$1;
6215: if ($ip =~ /^\Q$pattern\E/) {
6216: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6217: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6218: }
6219: } elsif ($pattern =~ /^\*/) {
6220: #*.msu.edu
6221: $pattern=~s/\*//;
6222: if (!defined($name)) {
6223: use Socket;
6224: my $netaddr=inet_aton($ip);
6225: ($name)=gethostbyaddr($netaddr,AF_INET);
6226: }
1.1219 raeburn 6227: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6228: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6229: #127.0.0.1
1.1219 raeburn 6230: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6231: } else {
6232: #some.name.com
6233: if (!defined($name)) {
6234: use Socket;
6235: my $netaddr=inet_aton($ip);
6236: ($name)=gethostbyaddr($netaddr,AF_INET);
6237: }
1.1219 raeburn 6238: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6239: }
6240: if ($allowed =~ /^(0|1)$/) { last; }
6241: }
6242: if ($allowed eq '') {
6243: if ($numdenies && !$numallows) {
6244: $allowed = 1;
6245: } else {
6246: $allowed = 0;
1.682 raeburn 6247: }
6248: }
6249: return $allowed;
6250: }
6251:
6252: ###############################################
6253:
1.60 matthew 6254: =pod
6255:
1.112 bowersj2 6256: =head1 Domain Template Functions
6257:
6258: =over 4
6259:
6260: =item * &determinedomain()
1.60 matthew 6261:
6262: Inputs: $domain (usually will be undef)
6263:
1.63 www 6264: Returns: Determines which domain should be used for designs
1.60 matthew 6265:
6266: =cut
1.54 www 6267:
1.60 matthew 6268: ###############################################
1.63 www 6269: sub determinedomain {
6270: my $domain=shift;
1.531 albertel 6271: if (! $domain) {
1.60 matthew 6272: # Determine domain if we have not been given one
1.893 raeburn 6273: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6274: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6275: if ($env{'request.role.domain'}) {
6276: $domain=$env{'request.role.domain'};
1.60 matthew 6277: }
6278: }
1.63 www 6279: return $domain;
6280: }
6281: ###############################################
1.517 raeburn 6282:
1.518 albertel 6283: sub devalidate_domconfig_cache {
6284: my ($udom)=@_;
6285: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6286: }
6287:
6288: # ---------------------- Get domain configuration for a domain
6289: sub get_domainconf {
6290: my ($udom) = @_;
6291: my $cachetime=1800;
6292: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6293: if (defined($cached)) { return %{$result}; }
6294:
6295: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6296: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6297: my (%designhash,%legacy);
1.518 albertel 6298: if (keys(%domconfig) > 0) {
6299: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6300: if (keys(%{$domconfig{'login'}})) {
6301: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6302: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6303: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6304: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6305: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6306: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6307: if ($key eq 'loginvia') {
6308: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6309: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6310: $designhash{$udom.'.login.loginvia'} = $server;
6311: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6312:
6313: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6314: } else {
6315: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6316: }
1.948 raeburn 6317: }
1.1208 raeburn 6318: } elsif ($key eq 'headtag') {
6319: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6320: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6321: }
1.946 raeburn 6322: }
1.1208 raeburn 6323: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6324: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6325: }
1.946 raeburn 6326: }
6327: }
6328: }
1.1366 raeburn 6329: } elsif ($key eq 'saml') {
6330: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6331: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6332: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6333: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6334: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6335: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6336: }
6337: }
6338: }
6339: }
1.946 raeburn 6340: } else {
6341: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6342: $designhash{$udom.'.login.'.$key.'_'.$img} =
6343: $domconfig{'login'}{$key}{$img};
6344: }
1.699 raeburn 6345: }
6346: } else {
6347: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6348: }
1.632 raeburn 6349: }
6350: } else {
6351: $legacy{'login'} = 1;
1.518 albertel 6352: }
1.632 raeburn 6353: } else {
6354: $legacy{'login'} = 1;
1.518 albertel 6355: }
6356: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6357: if (keys(%{$domconfig{'rolecolors'}})) {
6358: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6359: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6360: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6361: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6362: }
1.518 albertel 6363: }
6364: }
1.632 raeburn 6365: } else {
6366: $legacy{'rolecolors'} = 1;
1.518 albertel 6367: }
1.632 raeburn 6368: } else {
6369: $legacy{'rolecolors'} = 1;
1.518 albertel 6370: }
1.948 raeburn 6371: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6372: if ($domconfig{'autoenroll'}{'co-owners'}) {
6373: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6374: }
6375: }
1.632 raeburn 6376: if (keys(%legacy) > 0) {
6377: my %legacyhash = &get_legacy_domconf($udom);
6378: foreach my $item (keys(%legacyhash)) {
6379: if ($item =~ /^\Q$udom\E\.login/) {
6380: if ($legacy{'login'}) {
6381: $designhash{$item} = $legacyhash{$item};
6382: }
6383: } else {
6384: if ($legacy{'rolecolors'}) {
6385: $designhash{$item} = $legacyhash{$item};
6386: }
1.518 albertel 6387: }
6388: }
6389: }
1.632 raeburn 6390: } else {
6391: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6392: }
6393: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6394: $cachetime);
6395: return %designhash;
6396: }
6397:
1.632 raeburn 6398: sub get_legacy_domconf {
6399: my ($udom) = @_;
6400: my %legacyhash;
6401: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6402: my $designfile = $designdir.'/'.$udom.'.tab';
6403: if (-e $designfile) {
1.1317 raeburn 6404: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6405: while (my $line = <$fh>) {
6406: next if ($line =~ /^\#/);
6407: chomp($line);
6408: my ($key,$val)=(split(/\=/,$line));
6409: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6410: }
6411: close($fh);
6412: }
6413: }
1.1026 raeburn 6414: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6415: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6416: }
6417: return %legacyhash;
6418: }
6419:
1.63 www 6420: =pod
6421:
1.112 bowersj2 6422: =item * &domainlogo()
1.63 www 6423:
6424: Inputs: $domain (usually will be undef)
6425:
6426: Returns: A link to a domain logo, if the domain logo exists.
6427: If the domain logo does not exist, a description of the domain.
6428:
6429: =cut
1.112 bowersj2 6430:
1.63 www 6431: ###############################################
6432: sub domainlogo {
1.517 raeburn 6433: my $domain = &determinedomain(shift);
1.518 albertel 6434: my %designhash = &get_domainconf($domain);
1.517 raeburn 6435: # See if there is a logo
6436: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6437: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6438: if ($imgsrc =~ m{^/(adm|res)/}) {
6439: if ($imgsrc =~ m{^/res/}) {
6440: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6441: &Apache::lonnet::repcopy($local_name);
6442: }
6443: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6444: }
6445: my $alttext = $domain;
6446: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6447: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6448: }
6449: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6450: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6451: return &Apache::lonnet::domain($domain,'description');
1.59 www 6452: } else {
1.60 matthew 6453: return '';
1.59 www 6454: }
6455: }
1.63 www 6456: ##############################################
6457:
6458: =pod
6459:
1.112 bowersj2 6460: =item * &designparm()
1.63 www 6461:
6462: Inputs: $which parameter; $domain (usually will be undef)
6463:
6464: Returns: value of designparamter $which
6465:
6466: =cut
1.112 bowersj2 6467:
1.397 albertel 6468:
1.400 albertel 6469: ##############################################
1.397 albertel 6470: sub designparm {
6471: my ($which,$domain)=@_;
6472: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6473: return $env{'environment.color.'.$which};
1.96 www 6474: }
1.63 www 6475: $domain=&determinedomain($domain);
1.1016 raeburn 6476: my %domdesign;
6477: unless ($domain eq 'public') {
6478: %domdesign = &get_domainconf($domain);
6479: }
1.520 raeburn 6480: my $output;
1.517 raeburn 6481: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6482: $output = $domdesign{$domain.'.'.$which};
1.63 www 6483: } else {
1.520 raeburn 6484: $output = $defaultdesign{$which};
6485: }
6486: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6487: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6488: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6489: if ($output =~ m{^/res/}) {
6490: my $local_name = &Apache::lonnet::filelocation('',$output);
6491: &Apache::lonnet::repcopy($local_name);
6492: }
1.520 raeburn 6493: $output = &lonhttpdurl($output);
6494: }
1.63 www 6495: }
1.520 raeburn 6496: return $output;
1.63 www 6497: }
1.59 www 6498:
1.822 bisitz 6499: ##############################################
6500: =pod
6501:
1.832 bisitz 6502: =item * &authorspace()
6503:
1.1028 raeburn 6504: Inputs: $url (usually will be undef).
1.832 bisitz 6505:
1.1132 raeburn 6506: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6507: directory being viewed (or for which action is being taken).
6508: If $url is provided, and begins /priv/<domain>/<uname>
6509: the path will be that portion of the $context argument.
6510: Otherwise the path will be for the author space of the current
6511: user when the current role is author, or for that of the
6512: co-author/assistant co-author space when the current role
6513: is co-author or assistant co-author.
1.832 bisitz 6514:
6515: =cut
6516:
6517: sub authorspace {
1.1028 raeburn 6518: my ($url) = @_;
6519: if ($url ne '') {
6520: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6521: return $1;
6522: }
6523: }
1.832 bisitz 6524: my $caname = '';
1.1024 www 6525: my $cadom = '';
1.1028 raeburn 6526: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6527: ($cadom,$caname) =
1.832 bisitz 6528: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6529: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6530: $caname = $env{'user.name'};
1.1024 www 6531: $cadom = $env{'user.domain'};
1.832 bisitz 6532: }
1.1028 raeburn 6533: if (($caname ne '') && ($cadom ne '')) {
6534: return "/priv/$cadom/$caname/";
6535: }
6536: return;
1.832 bisitz 6537: }
6538:
6539: ##############################################
6540: =pod
6541:
1.822 bisitz 6542: =item * &head_subbox()
6543:
6544: Inputs: $content (contains HTML code with page functions, etc.)
6545:
6546: Returns: HTML div with $content
6547: To be included in page header
6548:
6549: =cut
6550:
6551: sub head_subbox {
6552: my ($content)=@_;
6553: my $output =
1.993 raeburn 6554: '<div class="LC_head_subbox">'
1.822 bisitz 6555: .$content
6556: .'</div>'
6557: }
6558:
6559: ##############################################
6560: =pod
6561:
6562: =item * &CSTR_pageheader()
6563:
1.1026 raeburn 6564: Input: (optional) filename from which breadcrumb trail is built.
6565: In most cases no input as needed, as $env{'request.filename'}
6566: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6567: frameset flag
6568: If page header is being requested for use in a frameset, then
6569: the second (option) argument -- frameset will be true, and
6570: the target attribute set for links should be target="_parent".
1.1433 raeburn 6571: If $title is supplied as the third arg, that will be used to
1.1407 raeburn 6572: the left of the breadcrumbs tail for the current path.
1.822 bisitz 6573:
6574: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6575: To be included on Authoring Space pages
1.822 bisitz 6576:
6577: =cut
6578:
6579: sub CSTR_pageheader {
1.1407 raeburn 6580: my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 6581: if ($trailfile eq '') {
6582: $trailfile = $env{'request.filename'};
6583: }
6584:
6585: # this is for resources; directories have customtitle, and crumbs
6586: # and select recent are created in lonpubdir.pm
6587:
6588: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6589: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6590: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6591: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6592: $formaction =~ s{/+}{/}g;
1.822 bisitz 6593:
6594: my $parentpath = '';
6595: my $lastitem = '';
6596: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6597: $parentpath = $1;
6598: $lastitem = $2;
6599: } else {
6600: $lastitem = $thisdisfn;
6601: }
1.921 bisitz 6602:
1.1406 raeburn 6603: my $crsauthor;
1.1246 raeburn 6604: if (($env{'request.course.id'}) &&
6605: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6606: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6607: $crsauthor = 1;
1.1406 raeburn 6608: if ($title eq '') {
6609: $title = &mt('Course Authoring Space');
6610: }
6611: } elsif ($title eq '') {
1.1246 raeburn 6612: $title = &mt('Authoring Space');
6613: }
6614:
1.1379 raeburn 6615: my ($target,$crumbtarget) = (' target="_top"','_top');
6616: if ($frameset) {
6617: $target = ' target="_parent"';
6618: $crumbtarget = '_parent';
6619: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6620: $target = '';
6621: $crumbtarget = '';
1.1379 raeburn 6622: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6623: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6624: $crumbtarget = $env{'request.deeplink.target'};
6625: }
1.1313 raeburn 6626:
1.921 bisitz 6627: my $output =
1.1407 raeburn 6628: '<div>'
1.822 bisitz 6629: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6630: .'<b>'.$title.'</b> '
1.1314 raeburn 6631: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6632: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6633:
6634: if ($lastitem) {
6635: $output .=
6636: '<span class="LC_filename">'
6637: .$lastitem
6638: .'</span>';
6639: }
1.1245 raeburn 6640:
1.1246 raeburn 6641: if ($crsauthor) {
1.1379 raeburn 6642: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6643: } else {
6644: $output .=
6645: '<br />'
1.1314 raeburn 6646: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6647: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6648: .'</form>'
1.1379 raeburn 6649: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6650: }
1.1407 raeburn 6651: $output .= '</div>';
1.921 bisitz 6652:
6653: return $output;
1.822 bisitz 6654: }
6655:
1.1419 raeburn 6656: ##############################################
6657: =pod
6658:
6659: =item * &nocodemirror()
6660:
6661: Input: None
6662:
6663: Returns: 1 if CodeMirror is deactivated based on
6664: user's preference, or domain default,
6665: if user indicated use of default.
6666:
6667: =cut
6668:
1.1416 raeburn 6669: sub nocodemirror {
6670: my $nocodem = $env{'environment.nocodemirror'};
6671: unless ($nocodem) {
6672: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6673: if ($domdefs{'nocodemirror'}) {
6674: $nocodem = 'yes';
6675: }
6676: }
1.1417 raeburn 6677: if ($nocodem eq 'yes') {
6678: return 1;
6679: }
6680: return;
1.1416 raeburn 6681: }
6682:
1.1419 raeburn 6683: ##############################################
6684: =pod
6685:
6686: =item * &permitted_editors()
6687:
1.1422 raeburn 6688: Input: $uri (optional)
1.1419 raeburn 6689:
6690: Returns: %editors hash in which keys are editors
1.1429 raeburn 6691: permitted in current Authoring Space,
6692: or in current course for web pages
6693: created in a course.
6694:
1.1419 raeburn 6695: Value for each key is 1. Possible keys
1.1429 raeburn 6696: are: edit, xml, and daxe.
6697:
6698: For a regular Authoring Space, if no specific
1.1419 raeburn 6699: set of editors has been set for the Author
6700: who owns the Authoring Space, then the
6701: domain default will be used. If no domain
6702: default has been set, then the keys will be
6703: edit and xml.
6704:
1.1429 raeburn 6705: For a course author, or for web pages created
6706: in a course, if no specific set of editors has
6707: been set for the course, then the domain
6708: course default will be used. If no domain
6709: course default has been set, then the keys
6710: will be edit and xml.
6711:
1.1419 raeburn 6712: =cut
6713:
1.1418 raeburn 6714: sub permitted_editors {
1.1422 raeburn 6715: my ($uri) = @_;
1.1429 raeburn 6716: my ($is_author,$is_coauthor,$is_course,$auname,$audom,%editors);
1.1418 raeburn 6717: if ($env{'request.role'} =~ m{^au\./}) {
6718: $is_author = 1;
6719: } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6720: ($audom,$auname) = ($1,$2);
6721: if (($audom ne '') && ($auname ne '')) {
6722: if (($env{'user.domain'} eq $audom) &&
6723: ($env{'user.name'} eq $auname)) {
6724: $is_author = 1;
6725: } else {
6726: $is_coauthor = 1;
6727: }
6728: }
6729: } elsif ($env{'request.course.id'}) {
1.1429 raeburn 6730: my ($cdom,$cnum);
6731: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6732: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6733: if (($env{'request.editurl'} =~ m{^/priv/\Q$cdom/$cnum\E/}) ||
1.1430 raeburn 6734: ($env{'request.editurl'} =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}) ||
6735: ($uri =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/})) {
1.1429 raeburn 6736: $is_course = 1;
6737: } elsif ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
1.1418 raeburn 6738: ($audom,$auname) = ($1,$2);
6739: } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6740: ($audom,$auname) = ($1,$2);
1.1422 raeburn 6741: } elsif (($uri eq '/daxesave') &&
1.1429 raeburn 6742: (($env{'form.path'} =~ m{^/daxeopen/priv/\Q$cdom/$cnum\E/}) ||
6743: ($env{'form.path'} =~ m{^/daxeopen/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}))) {
6744: $is_course = 1;
6745: } elsif (($uri eq '/daxesave') &&
1.1422 raeburn 6746: ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {
6747: ($audom,$auname) = ($1,$2);
1.1418 raeburn 6748: }
1.1429 raeburn 6749: unless ($is_course) {
6750: if (($audom ne '') && ($auname ne '')) {
6751: if (($env{'user.domain'} eq $audom) &&
6752: ($env{'user.name'} eq $auname)) {
6753: $is_author = 1;
6754: } else {
6755: $is_coauthor = 1;
6756: }
1.1418 raeburn 6757: }
6758: }
6759: }
6760: if ($is_author) {
6761: if (exists($env{'environment.editors'})) {
6762: map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6763: } else {
6764: %editors = ( edit => 1,
6765: xml => 1,
6766: );
6767: }
6768: } elsif ($is_coauthor) {
6769: if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6770: map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6771: } else {
6772: %editors = ( edit => 1,
6773: xml => 1,
6774: );
6775: }
1.1429 raeburn 6776: } elsif ($is_course) {
6777: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.crseditors'})) {
6778: map { $editors{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.crseditors'});
6779: } else {
6780: my %domdefaults = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
6781: if (exists($domdefaults{'crseditors'})) {
6782: map { $editors{$_} = 1; } split(/,/,$domdefaults{'crseditors'});
6783: } else {
6784: %editors = ( edit => 1,
6785: xml => 1,
6786: );
6787: }
6788: }
1.1418 raeburn 6789: } else {
6790: %editors = ( edit => 1,
6791: xml => 1,
6792: );
6793: }
6794: return %editors;
6795: }
6796:
1.60 matthew 6797: ###############################################
6798: ###############################################
6799:
6800: =pod
6801:
1.112 bowersj2 6802: =back
6803:
1.549 albertel 6804: =head1 HTML Helpers
1.112 bowersj2 6805:
6806: =over 4
6807:
6808: =item * &bodytag()
1.60 matthew 6809:
6810: Returns a uniform header for LON-CAPA web pages.
6811:
6812: Inputs:
6813:
1.112 bowersj2 6814: =over 4
6815:
6816: =item * $title, A title to be displayed on the page.
6817:
6818: =item * $function, the current role (can be undef).
6819:
6820: =item * $addentries, extra parameters for the <body> tag.
6821:
6822: =item * $bodyonly, if defined, only return the <body> tag.
6823:
6824: =item * $domain, if defined, force a given domain.
6825:
6826: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6827: text interface only)
1.60 matthew 6828:
1.814 bisitz 6829: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6830: navigational links
1.317 albertel 6831:
1.338 albertel 6832: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6833:
1.460 albertel 6834: =item * $args, optional argument valid values are
6835: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6836: use_absolute -> for external resource or syllabus, this will
6837: contain https://<hostname> if server uses
6838: https (as per hosts.tab), but request is for http
6839: hostname -> hostname, from $r->hostname().
1.460 albertel 6840:
1.1096 raeburn 6841: =item * $advtoolsref, optional argument, ref to an array containing
6842: inlineremote items to be added in "Functions" menu below
6843: breadcrumbs.
6844:
1.1316 raeburn 6845: =item * $ltiscope, optional argument, will be one of: resource, map or
6846: course, if LON-CAPA is in LTI Provider context. Value is
6847: the scope of use, i.e., launch was for access to a single, a map
6848: or the entire course.
6849:
6850: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6851: context, this will contain the URL for the landing item in
6852: the course, after launch from an LTI Consumer
6853:
1.1318 raeburn 6854: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6855: context, this will contain a reference to hash of items
6856: to be included in the page header and/or inline menu.
6857:
1.1385 raeburn 6858: =item * $menucoll, optional argument, if specific menu collection is in
6859: effect, either set as the default for the course, or set for
6860: the deeplink paramater for $env{'request.deeplink.login'}
6861: then $menucoll will be the number of that collection.
6862:
6863: =item * $menuref, optional argument, reference to a hash, containing the
6864: menu options included for the menu in effect, based on the
6865: configuration for the numbered menu collection in use.
6866:
6867: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6868: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6869: if so, $showncrumbsref is set there to 1, and will propagate back
6870: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6871: being called a second time.
6872:
1.112 bowersj2 6873: =back
6874:
1.60 matthew 6875: Returns: A uniform header for LON-CAPA web pages.
6876: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6877: If $bodyonly is undef or zero, an html string containing a <body> tag and
6878: other decorations will be returned.
6879:
6880: =cut
6881:
1.54 www 6882: sub bodytag {
1.831 bisitz 6883: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6884: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6885: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6886:
1.954 raeburn 6887: my $public;
6888: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6889: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6890: $public = 1;
6891: }
1.460 albertel 6892: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6893: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6894: my $hostname = $args->{'hostname'};
1.339 albertel 6895:
1.183 matthew 6896: $function = &get_users_function() if (!$function);
1.339 albertel 6897: my $font = &designparm($function.'.font',$domain);
6898: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6899:
1.803 bisitz 6900: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6901: 'bgcolor' => $pgbg,
1.339 albertel 6902: 'text' => $font,
6903: 'alink' => &designparm($function.'.alink',$domain),
6904: 'vlink' => &designparm($function.'.vlink',$domain),
6905: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6906: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6907:
1.63 www 6908: # role and realm
1.1178 raeburn 6909: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6910: if ($realm) {
6911: $realm = '/'.$realm;
6912: }
1.1357 raeburn 6913: if ($role eq 'ca') {
1.479 albertel 6914: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6915: $realm = &plainname($rname,$rdom);
1.378 raeburn 6916: }
1.55 www 6917: # realm
1.1357 raeburn 6918: my ($cid,$sec);
1.258 albertel 6919: if ($env{'request.course.id'}) {
1.1357 raeburn 6920: $cid = $env{'request.course.id'};
6921: if ($env{'request.course.sec'}) {
6922: $sec = $env{'request.course.sec'};
6923: }
6924: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6925: if (&Apache::lonnet::is_course($1,$2)) {
6926: $cid = $1.'_'.$2;
6927: $sec = $3;
6928: }
6929: }
6930: if ($cid) {
1.378 raeburn 6931: if ($env{'request.role'} !~ /^cr/) {
6932: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6933: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6934: if ($env{'request.role.desc'}) {
6935: $role = $env{'request.role.desc'};
6936: } else {
6937: $role = &mt('Helpdesk[_1]',' '.$2);
6938: }
1.1257 raeburn 6939: } else {
6940: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6941: }
1.1357 raeburn 6942: if ($sec) {
6943: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6944: }
1.1357 raeburn 6945: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6946: } else {
6947: $role = &Apache::lonnet::plaintext($role);
1.54 www 6948: }
1.433 albertel 6949:
1.438 albertel 6950: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6951:
1.101 www 6952: # construct main body tag
1.359 albertel 6953: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6954: &Apache::lontexconvert::init_math_support();
1.252 albertel 6955:
1.1131 raeburn 6956: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6957:
1.1130 raeburn 6958: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6959: return $bodytag;
1.1130 raeburn 6960: }
1.359 albertel 6961:
1.954 raeburn 6962: if ($public) {
1.433 albertel 6963: undef($role);
6964: }
1.1318 raeburn 6965:
1.1359 raeburn 6966: my $showcrstitle = 1;
1.1357 raeburn 6967: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6968: if (ref($ltimenu) eq 'HASH') {
6969: unless ($ltimenu->{'role'}) {
6970: undef($role);
6971: }
6972: unless ($ltimenu->{'coursetitle'}) {
1.1359 raeburn 6973: $showcrstitle = 0;
6974: }
6975: }
6976: } elsif (($cid) && ($menucoll)) {
6977: if (ref($menuref) eq 'HASH') {
6978: unless ($menuref->{'role'}) {
6979: undef($role);
6980: }
6981: unless ($menuref->{'crs'}) {
6982: $showcrstitle = 0;
1.1318 raeburn 6983: }
6984: }
6985: }
6986:
1.762 bisitz 6987: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6988: #
6989: # Extra info if you are the DC
6990: my $dc_info = '';
1.1359 raeburn 6991: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6992: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6993: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6994: $dc_info =~ s/\s+$//;
1.359 albertel 6995: }
6996:
1.1237 raeburn 6997: my $crstype;
1.1357 raeburn 6998: if ($cid) {
6999: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 7000: } elsif ($args->{'crstype'}) {
7001: $crstype = $args->{'crstype'};
7002: }
7003: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
7004: undef($role);
7005: } else {
1.1242 raeburn 7006: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 7007: }
1.853 droeschl 7008:
1.903 droeschl 7009: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
7010:
7011: # if ($env{'request.state'} eq 'construct') {
7012: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
7013: # }
7014:
1.1440 raeburn 7015: my $need_endlcint;
7016: unless ($args->{'switchserver'}) {
7017: $bodytag .= Apache::lonhtmlcommon::scripttag(
7018: Apache::lonmenu::utilityfunctions($httphost), 'start');
7019: $need_endlcint = 1;
7020: }
1.359 albertel 7021:
1.1427 raeburn 7022: my $collapsible;
1.1423 raeburn 7023: if ($args->{'collapsible_header'} ne '') {
1.1427 raeburn 7024: $collapsible = 1;
7025: my ($menustate,$tiptext,$divclass);
7026: if ($args->{'start_collapsed'}) {
7027: $menustate = 'collapsed';
7028: $tiptext = 'display';
7029: $divclass = 'hidden';
7030: } else {
7031: $menustate = 'expanded';
7032: $tiptext = 'hide';
7033: $divclass = 'shown';
7034: }
7035: my $alttext = &mt('menu state: '.$menustate);
7036: my $tooltip = &mt($tiptext.' standard menus');
1.1421 raeburn 7037: $bodytag .= <<"END";
7038: <div id="LC_expandingContainer" style="display:inline;">
7039: <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
1.1427 raeburn 7040: <a href="#" style="text-decoration:none;"><img class="LC_collapsible_indicator" alt="$alttext" title="$tooltip" src="/res/adm/pages/$menustate.png" style="border:0;margin:0;padding:0;max-width:100%;height:auto" /></a></div>
7041: <div class="LC_menus_content $divclass">
1.1421 raeburn 7042: END
7043: }
1.1318 raeburn 7044: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 7045: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 7046: $args->{'links_disabled'},
1.1421 raeburn 7047: $args->{'links_target'},
1.1427 raeburn 7048: $collapsible);
1.1454 raeburn 7049: my $labeltext = &HTML::Entities::encode(&mt('Primary links'));
1.1318 raeburn 7050: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
7051: if ($dc_info) {
7052: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
7053: }
1.1456 raeburn 7054: $bodytag .= qq|<div id="LC_nav_bar" role="navigation" aria-label="$labeltext">$left $role</div>|;
1.1454 raeburn 7055: unless (($realm eq '') && ($dc_info eq '')) {
7056: $bodytag .= qq|<div id="LC_realm" role="complementary"><em>$realm</em> $dc_info</div>|;
7057: }
1.1440 raeburn 7058: if ($need_endlcint) {
7059: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7060: }
1.1318 raeburn 7061: return $bodytag;
7062: }
1.894 droeschl 7063:
1.1457 raeburn 7064: $bodytag .= '<div class="LC_landmark" style="margin: 3px 0 0 0;" role="navigation" aria-label="'.$labeltext.'">';
1.1318 raeburn 7065: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
7066: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
7067: }
1.916 droeschl 7068:
1.1454 raeburn 7069: $bodytag .= $right.'</div>';
1.852 droeschl 7070:
1.1318 raeburn 7071: if ($dc_info) {
7072: $dc_info = &dc_courseid_toggle($dc_info);
7073: }
1.1454 raeburn 7074: unless (($realm eq '') && ($dc_info eq '')) {
1.1457 raeburn 7075: $bodytag .= qq|<div id="LC_realm" role="complementary">$realm $dc_info</div>|;
1.1454 raeburn 7076: }
1.1457 raeburn 7077: $bodytag .= qq|<div style="clear: both; margin: 5px 0 0 0;"></div>|;
1.917 raeburn 7078: }
1.916 droeschl 7079:
1.1169 raeburn 7080: #if directed to not display the secondary menu, don't.
1.1168 raeburn 7081: if ($args->{'no_secondary_menu'}) {
1.1440 raeburn 7082: if ($need_endlcint) {
7083: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7084: }
1.1168 raeburn 7085: return $bodytag;
7086: }
1.1169 raeburn 7087: #don't show menus for public users
1.954 raeburn 7088: if (!$public){
1.1318 raeburn 7089: unless ($args->{'no_inline_menu'}) {
7090: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 7091: $args->{'no_primary_menu'},
1.1369 raeburn 7092: $menucoll,$menuref,
1.1380 raeburn 7093: $args->{'links_disabled'},
7094: $args->{'links_target'});
1.1318 raeburn 7095: }
1.903 droeschl 7096: $bodytag .= Apache::lonmenu::serverform();
1.1440 raeburn 7097: if ($need_endlcint) {
7098: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7099: }
1.920 raeburn 7100: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 7101: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 7102: $args->{'bread_crumbs'},'','',$hostname,
7103: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 7104: } elsif ($forcereg) {
7105: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 7106: $args->{'group'},$args->{'hide_buttons'},
7107: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 7108: } else {
7109: $bodytag .=
7110: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
7111: $forcereg,$args->{'group'},
7112: $args->{'bread_crumbs'},
1.1274 raeburn 7113: $advtoolsref,'',$hostname);
1.920 raeburn 7114: }
1.1440 raeburn 7115: } else {
7116: # this is to separate menu from content when there's no secondary
1.1441 raeburn 7117: # menu. Especially needed for publicly accessible resources.
1.903 droeschl 7118: $bodytag .= '<hr style="clear:both" />';
1.1440 raeburn 7119: if ($need_endlcint) {
7120: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7121: }
1.235 raeburn 7122: }
1.1423 raeburn 7123: if ($args->{'collapsible_header'} ne '') {
7124: $bodytag .= $args->{'collapsible_header'}.
7125: '<div id="LC_collapsible_separator"></div>'.
1.1421 raeburn 7126: '</div></div>';
7127: }
1.235 raeburn 7128: return $bodytag;
1.182 matthew 7129: }
7130:
1.917 raeburn 7131: sub dc_courseid_toggle {
7132: my ($dc_info) = @_;
1.980 raeburn 7133: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 7134: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 7135: &mt('(More ...)').'</a></span>'.
7136: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
7137: }
7138:
1.330 albertel 7139: sub make_attr_string {
7140: my ($register,$attr_ref) = @_;
7141:
7142: if ($attr_ref && !ref($attr_ref)) {
7143: die("addentries Must be a hash ref ".
7144: join(':',caller(1))." ".
7145: join(':',caller(0))." ");
7146: }
7147:
7148: if ($register) {
1.339 albertel 7149: my ($on_load,$on_unload);
7150: foreach my $key (keys(%{$attr_ref})) {
7151: if (lc($key) eq 'onload') {
7152: $on_load.=$attr_ref->{$key}.';';
7153: delete($attr_ref->{$key});
7154:
7155: } elsif (lc($key) eq 'onunload') {
7156: $on_unload.=$attr_ref->{$key}.';';
7157: delete($attr_ref->{$key});
7158: }
7159: }
1.953 droeschl 7160: $attr_ref->{'onload'} = $on_load;
7161: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 7162: }
1.339 albertel 7163:
1.330 albertel 7164: my $attr_string;
1.1159 raeburn 7165: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 7166: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
7167: }
7168: return $attr_string;
7169: }
7170:
7171:
1.182 matthew 7172: ###############################################
1.251 albertel 7173: ###############################################
7174:
7175: =pod
7176:
7177: =item * &endbodytag()
7178:
7179: Returns a uniform footer for LON-CAPA web pages.
7180:
1.635 raeburn 7181: Inputs: 1 - optional reference to an args hash
7182: If in the hash, key for noredirectlink has a value which evaluates to true,
7183: a 'Continue' link is not displayed if the page contains an
7184: internal redirect in the <head></head> section,
7185: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 7186:
7187: =cut
7188:
7189: sub endbodytag {
1.635 raeburn 7190: my ($args) = @_;
1.1080 raeburn 7191: my $endbodytag;
7192: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
7193: $endbodytag='</body>';
7194: }
1.315 albertel 7195: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 7196: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 7197: my ($endbodyjs,$idattr);
7198: if ($env{'internal.head.to_opener'}) {
7199: my $linkid = 'LC_continue_link';
7200: $idattr = ' id="'.$linkid.'"';
7201: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
7202: $endbodyjs=<<ENDJS;
7203: <script type="text/javascript">
7204: // <![CDATA[
7205: function ebFunction(evt) {
7206: evt.preventDefault();
7207: var dest = '$redirect_for_js';
7208: if (window.opener != null && !window.opener.closed) {
7209: window.opener.location.href=dest;
7210: window.close();
7211: } else {
7212: window.location.href=dest;
7213: }
7214: return false;
7215: }
7216:
7217: \$(document).ready(function () {
7218: if (document.getElementById('$linkid')) {
7219: var clickelem = document.getElementById('$linkid');
7220: clickelem.addEventListener('click',ebFunction,false);
7221: }
7222: });
7223: // ]]>
7224: </script>
7225: ENDJS
7226: }
1.635 raeburn 7227: $endbodytag=
1.1386 raeburn 7228: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 7229: &mt('Continue').'</a>'.
7230: $endbodytag;
7231: }
1.315 albertel 7232: }
1.1411 raeburn 7233: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
7234: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
7235: }
1.251 albertel 7236: return $endbodytag;
7237: }
7238:
1.352 albertel 7239: =pod
7240:
7241: =item * &standard_css()
7242:
7243: Returns a style sheet
7244:
7245: Inputs: (all optional)
7246: domain -> force to color decorate a page for a specific
7247: domain
7248: function -> force usage of a specific rolish color scheme
7249: bgcolor -> override the default page bgcolor
7250:
7251: =cut
7252:
1.343 albertel 7253: sub standard_css {
1.345 albertel 7254: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 7255: $function = &get_users_function() if (!$function);
7256: my $tabbg = &designparm($function.'.tabbg', $domain);
7257: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 7258: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 7259: #second colour for later usage
1.345 albertel 7260: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 7261: my $pgbg_or_bgcolor =
7262: $bgcolor ||
1.352 albertel 7263: &designparm($function.'.pgbg', $domain);
1.382 albertel 7264: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 7265: my $alink = &designparm($function.'.alink', $domain);
7266: my $vlink = &designparm($function.'.vlink', $domain);
7267: my $link = &designparm($function.'.link', $domain);
7268:
1.602 albertel 7269: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 7270: my $mono = 'monospace';
1.850 bisitz 7271: my $data_table_head = $sidebg;
7272: my $data_table_light = '#FAFAFA';
1.1060 bisitz 7273: my $data_table_dark = '#E0E0E0';
1.470 banghart 7274: my $data_table_darker = '#CCCCCC';
1.349 albertel 7275: my $data_table_highlight = '#FFFF00';
1.352 albertel 7276: my $mail_new = '#FFBB77';
7277: my $mail_new_hover = '#DD9955';
7278: my $mail_read = '#BBBB77';
7279: my $mail_read_hover = '#999944';
7280: my $mail_replied = '#AAAA88';
7281: my $mail_replied_hover = '#888855';
7282: my $mail_other = '#99BBBB';
7283: my $mail_other_hover = '#669999';
1.391 albertel 7284: my $table_header = '#DDDDDD';
1.489 raeburn 7285: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 7286: my $lg_border_color = '#C8C8C8';
1.952 onken 7287: my $button_hover = '#BF2317';
1.392 albertel 7288:
1.608 albertel 7289: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 7290: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
7291: : '0 3px 0 4px';
1.448 albertel 7292:
1.523 albertel 7293:
1.343 albertel 7294: return <<END;
1.947 droeschl 7295:
7296: /* needed for iframe to allow 100% height in FF */
7297: body, html {
7298: margin: 0;
7299: padding: 0 0.5%;
7300: height: 99%; /* to avoid scrollbars */
7301: }
7302:
1.795 www 7303: body {
1.911 bisitz 7304: font-family: $sans;
7305: line-height:130%;
7306: font-size:0.83em;
7307: color:$font;
1.1436 raeburn 7308: background-color: $pgbg_or_bgcolor;
1.795 www 7309: }
7310:
1.959 onken 7311: a:focus,
7312: a:focus img {
1.795 www 7313: color: red;
7314: }
1.698 harmsja 7315:
1.911 bisitz 7316: form, .inline {
7317: display: inline;
1.795 www 7318: }
1.721 harmsja 7319:
1.1453 raeburn 7320: .LC_landmark {
7321: margin: 0;
7322: padding: 0;
7323: border: none;
7324: }
7325:
1.1443 raeburn 7326: .LC_visually_hidden:not(:focus):not(:active) {
7327: clip-path: inset(50%);
7328: height: 1px;
7329: overflow: hidden;
7330: position: absolute;
7331: white-space: nowrap;
7332: width: 1px;
7333: display: inline;
7334: }
7335:
1.1453 raeburn 7336: .LC_heading_2 {
7337: font-size: 1.17em;
7338: }
7339:
1.1458 ! raeburn 7340: .LC_heading_3 {
! 7341: font-size: 1.0em;
! 7342: }
! 7343:
1.1421 raeburn 7344: .LC_menus_content.shown{
1.1428 raeburn 7345: display: block;
1.1421 raeburn 7346: }
7347:
7348: .LC_menus_content.hidden {
7349: display: none;
7350: }
7351:
1.795 www 7352: .LC_right {
1.911 bisitz 7353: text-align:right;
1.795 www 7354: }
7355:
1.1449 raeburn 7356: .LC_center {
7357: text-align:center;
7358: }
7359:
1.795 www 7360: .LC_middle {
1.911 bisitz 7361: vertical-align:middle;
1.795 www 7362: }
1.721 harmsja 7363:
1.1130 raeburn 7364: .LC_floatleft {
7365: float: left;
7366: }
7367:
7368: .LC_floatright {
7369: float: right;
7370: }
7371:
1.911 bisitz 7372: .LC_400Box {
7373: width:400px;
7374: }
1.721 harmsja 7375:
1.1421 raeburn 7376: #LC_collapsible_separator {
7377: border: 1px solid black;
7378: width: 99.9%;
7379: height: 0px;
7380: }
7381:
1.947 droeschl 7382: .LC_iframecontainer {
7383: width: 98%;
7384: margin: 0;
7385: position: fixed;
7386: top: 8.5em;
7387: bottom: 0;
7388: }
7389:
7390: .LC_iframecontainer iframe{
7391: border: none;
7392: width: 100%;
7393: height: 100%;
7394: }
7395:
1.778 bisitz 7396: .LC_filename {
7397: font-family: $mono;
7398: white-space:pre;
1.921 bisitz 7399: font-size: 120%;
1.778 bisitz 7400: }
7401:
7402: .LC_fileicon {
7403: border: none;
7404: height: 1.3em;
7405: vertical-align: text-bottom;
7406: margin-right: 0.3em;
7407: text-decoration:none;
7408: }
7409:
1.1008 www 7410: .LC_setting {
7411: text-decoration:underline;
7412: }
7413:
1.350 albertel 7414: .LC_error {
7415: color: red;
7416: }
1.795 www 7417:
1.1097 bisitz 7418: .LC_warning {
7419: color: darkorange;
7420: }
7421:
1.457 albertel 7422: .LC_diff_removed {
1.733 bisitz 7423: color: red;
1.394 albertel 7424: }
1.532 albertel 7425:
7426: .LC_info,
1.457 albertel 7427: .LC_success,
7428: .LC_diff_added {
1.350 albertel 7429: color: green;
7430: }
1.795 www 7431:
1.802 bisitz 7432: div.LC_confirm_box {
7433: background-color: #FAFAFA;
7434: border: 1px solid $lg_border_color;
7435: margin-right: 0;
7436: padding: 5px;
7437: }
7438:
7439: div.LC_confirm_box .LC_error img,
7440: div.LC_confirm_box .LC_success img {
7441: vertical-align: middle;
7442: }
7443:
1.1242 raeburn 7444: .LC_maxwidth {
7445: max-width: 100%;
7446: height: auto;
7447: }
7448:
1.1243 raeburn 7449: .LC_textsize_mobile {
7450: \@media only screen and (max-device-width: 480px) {
7451: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7452: }
7453: }
7454:
1.440 albertel 7455: .LC_icon {
1.771 droeschl 7456: border: none;
1.790 droeschl 7457: vertical-align: middle;
1.771 droeschl 7458: }
7459:
1.543 albertel 7460: .LC_docs_spacer {
7461: width: 25px;
7462: height: 1px;
1.771 droeschl 7463: border: none;
1.543 albertel 7464: }
1.346 albertel 7465:
1.532 albertel 7466: .LC_internal_info {
1.735 bisitz 7467: color: #999999;
1.532 albertel 7468: }
7469:
1.794 www 7470: .LC_discussion {
1.1050 www 7471: background: $data_table_dark;
1.911 bisitz 7472: border: 1px solid black;
7473: margin: 2px;
1.794 www 7474: }
7475:
7476: .LC_disc_action_left {
1.1050 www 7477: background: $sidebg;
1.911 bisitz 7478: text-align: left;
1.1050 www 7479: padding: 4px;
7480: margin: 2px;
1.794 www 7481: }
7482:
7483: .LC_disc_action_right {
1.1050 www 7484: background: $sidebg;
1.911 bisitz 7485: text-align: right;
1.1050 www 7486: padding: 4px;
7487: margin: 2px;
1.794 www 7488: }
7489:
7490: .LC_disc_new_item {
1.911 bisitz 7491: background: white;
7492: border: 2px solid red;
1.1050 www 7493: margin: 4px;
7494: padding: 4px;
1.794 www 7495: }
7496:
7497: .LC_disc_old_item {
1.911 bisitz 7498: background: white;
1.1050 www 7499: margin: 4px;
7500: padding: 4px;
1.794 www 7501: }
7502:
1.458 albertel 7503: table.LC_pastsubmission {
7504: border: 1px solid black;
7505: margin: 2px;
7506: }
7507:
1.924 bisitz 7508: table#LC_menubuttons {
1.345 albertel 7509: width: 100%;
7510: background: $pgbg;
1.392 albertel 7511: border: 2px;
1.402 albertel 7512: border-collapse: separate;
1.803 bisitz 7513: padding: 0;
1.345 albertel 7514: }
1.392 albertel 7515:
1.801 tempelho 7516: table#LC_title_bar a {
7517: color: $fontmenu;
7518: }
1.836 bisitz 7519:
1.807 droeschl 7520: table#LC_title_bar {
1.819 tempelho 7521: clear: both;
1.836 bisitz 7522: display: none;
1.807 droeschl 7523: }
7524:
1.795 www 7525: table#LC_title_bar,
1.933 droeschl 7526: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7527: table#LC_title_bar.LC_with_remote {
1.359 albertel 7528: width: 100%;
1.392 albertel 7529: border-color: $pgbg;
7530: border-style: solid;
7531: border-width: $border;
1.379 albertel 7532: background: $pgbg;
1.801 tempelho 7533: color: $fontmenu;
1.392 albertel 7534: border-collapse: collapse;
1.803 bisitz 7535: padding: 0;
1.819 tempelho 7536: margin: 0;
1.359 albertel 7537: }
1.795 www 7538:
1.933 droeschl 7539: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7540: margin: 0;
7541: padding: 0;
1.933 droeschl 7542: position: relative;
7543: list-style: none;
1.913 droeschl 7544: }
1.933 droeschl 7545: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7546: display: inline;
7547: }
1.933 droeschl 7548:
7549: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7550: padding: 0;
1.933 droeschl 7551: margin: 0;
7552: float: left;
1.913 droeschl 7553: }
1.933 droeschl 7554: .LC_breadcrumb_tools_tools {
7555: padding: 0;
7556: margin: 0;
1.913 droeschl 7557: float: right;
7558: }
7559:
1.1240 raeburn 7560: .LC_placement_prog {
7561: padding-right: 20px;
7562: font-weight: bold;
7563: font-size: 90%;
7564: }
7565:
1.359 albertel 7566: table#LC_title_bar td {
7567: background: $tabbg;
7568: }
1.795 www 7569:
1.911 bisitz 7570: table#LC_menubuttons img {
1.803 bisitz 7571: border: none;
1.346 albertel 7572: }
1.795 www 7573:
1.842 droeschl 7574: .LC_breadcrumbs_component {
1.911 bisitz 7575: float: right;
7576: margin: 0 1em;
1.357 albertel 7577: }
1.842 droeschl 7578: .LC_breadcrumbs_component img {
1.911 bisitz 7579: vertical-align: middle;
1.777 tempelho 7580: }
1.795 www 7581:
1.1243 raeburn 7582: .LC_breadcrumbs_hoverable {
7583: background: $sidebg;
7584: }
7585:
1.383 albertel 7586: td.LC_table_cell_checkbox {
7587: text-align: center;
7588: }
1.795 www 7589:
7590: .LC_fontsize_small {
1.911 bisitz 7591: font-size: 70%;
1.705 tempelho 7592: }
7593:
1.844 bisitz 7594: #LC_breadcrumbs {
1.911 bisitz 7595: clear:both;
7596: background: $sidebg;
7597: border-bottom: 1px solid $lg_border_color;
7598: line-height: 2.5em;
1.933 droeschl 7599: overflow: hidden;
1.911 bisitz 7600: margin: 0;
7601: padding: 0;
1.995 raeburn 7602: text-align: left;
1.819 tempelho 7603: }
1.862 bisitz 7604:
1.1098 bisitz 7605: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7606: clear:both;
7607: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7608: border: 1px solid $sidebg;
1.1098 bisitz 7609: margin: 0 0 10px 0;
1.966 bisitz 7610: padding: 3px;
1.995 raeburn 7611: text-align: left;
1.822 bisitz 7612: }
7613:
1.795 www 7614: .LC_fontsize_medium {
1.911 bisitz 7615: font-size: 85%;
1.705 tempelho 7616: }
7617:
1.795 www 7618: .LC_fontsize_large {
1.911 bisitz 7619: font-size: 120%;
1.705 tempelho 7620: }
7621:
1.346 albertel 7622: .LC_menubuttons_inline_text {
7623: color: $font;
1.698 harmsja 7624: font-size: 90%;
1.701 harmsja 7625: padding-left:3px;
1.346 albertel 7626: }
7627:
1.934 droeschl 7628: .LC_menubuttons_inline_text img{
7629: vertical-align: middle;
7630: }
7631:
1.1051 www 7632: li.LC_menubuttons_inline_text img {
1.951 onken 7633: cursor:pointer;
1.1002 droeschl 7634: text-decoration: none;
1.951 onken 7635: }
7636:
1.526 www 7637: .LC_menubuttons_link {
7638: text-decoration: none;
7639: }
1.795 www 7640:
1.522 albertel 7641: .LC_menubuttons_category {
1.521 www 7642: color: $font;
1.526 www 7643: background: $pgbg;
1.521 www 7644: font-size: larger;
7645: font-weight: bold;
7646: }
7647:
1.346 albertel 7648: td.LC_menubuttons_text {
1.911 bisitz 7649: color: $font;
1.346 albertel 7650: }
1.706 harmsja 7651:
1.346 albertel 7652: .LC_current_location {
7653: background: $tabbg;
7654: }
1.795 www 7655:
1.1286 raeburn 7656: td.LC_zero_height {
7657: line-height: 0;
7658: cellpadding: 0;
7659: }
7660:
1.938 bisitz 7661: table.LC_data_table {
1.347 albertel 7662: border: 1px solid #000000;
1.402 albertel 7663: border-collapse: separate;
1.426 albertel 7664: border-spacing: 1px;
1.610 albertel 7665: background: $pgbg;
1.347 albertel 7666: }
1.795 www 7667:
1.422 albertel 7668: .LC_data_table_dense {
7669: font-size: small;
7670: }
1.795 www 7671:
1.507 raeburn 7672: table.LC_nested_outer {
7673: border: 1px solid #000000;
1.589 raeburn 7674: border-collapse: collapse;
1.803 bisitz 7675: border-spacing: 0;
1.507 raeburn 7676: width: 100%;
7677: }
1.795 www 7678:
1.879 raeburn 7679: table.LC_innerpickbox,
1.507 raeburn 7680: table.LC_nested {
1.803 bisitz 7681: border: none;
1.589 raeburn 7682: border-collapse: collapse;
1.803 bisitz 7683: border-spacing: 0;
1.507 raeburn 7684: width: 100%;
7685: }
1.795 www 7686:
1.911 bisitz 7687: table.LC_data_table tr th,
7688: table.LC_calendar tr th,
1.879 raeburn 7689: table.LC_prior_tries tr th,
7690: table.LC_innerpickbox tr th {
1.349 albertel 7691: font-weight: bold;
7692: background-color: $data_table_head;
1.801 tempelho 7693: color:$fontmenu;
1.701 harmsja 7694: font-size:90%;
1.347 albertel 7695: }
1.795 www 7696:
1.879 raeburn 7697: table.LC_innerpickbox tr th,
7698: table.LC_innerpickbox tr td {
7699: vertical-align: top;
7700: }
7701:
1.711 raeburn 7702: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7703: background-color: #CCCCCC;
1.711 raeburn 7704: font-weight: bold;
7705: text-align: left;
7706: }
1.795 www 7707:
1.912 bisitz 7708: table.LC_data_table tr.LC_odd_row > td {
7709: background-color: $data_table_light;
7710: padding: 2px;
7711: vertical-align: top;
7712: }
7713:
1.809 bisitz 7714: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7715: background-color: $data_table_light;
1.912 bisitz 7716: vertical-align: top;
7717: }
7718:
7719: table.LC_data_table tr.LC_even_row > td {
7720: background-color: $data_table_dark;
1.425 albertel 7721: padding: 2px;
1.900 bisitz 7722: vertical-align: top;
1.347 albertel 7723: }
1.795 www 7724:
1.809 bisitz 7725: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7726: background-color: $data_table_dark;
1.900 bisitz 7727: vertical-align: top;
1.347 albertel 7728: }
1.795 www 7729:
1.425 albertel 7730: table.LC_data_table tr.LC_data_table_highlight td {
7731: background-color: $data_table_darker;
7732: }
1.795 www 7733:
1.639 raeburn 7734: table.LC_data_table tr td.LC_leftcol_header {
7735: background-color: $data_table_head;
7736: font-weight: bold;
7737: }
1.795 www 7738:
1.451 albertel 7739: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7740: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7741: font-weight: bold;
7742: font-style: italic;
7743: text-align: center;
7744: padding: 8px;
1.347 albertel 7745: }
1.795 www 7746:
1.1114 raeburn 7747: table.LC_data_table tr.LC_empty_row td,
7748: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7749: background-color: $sidebg;
7750: }
7751:
7752: table.LC_nested tr.LC_empty_row td {
7753: background-color: #FFFFFF;
7754: }
7755:
1.890 droeschl 7756: table.LC_caption {
7757: }
7758:
1.507 raeburn 7759: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7760: padding: 4ex
7761: }
1.795 www 7762:
1.507 raeburn 7763: table.LC_nested_outer tr th {
7764: font-weight: bold;
1.801 tempelho 7765: color:$fontmenu;
1.507 raeburn 7766: background-color: $data_table_head;
1.701 harmsja 7767: font-size: small;
1.507 raeburn 7768: border-bottom: 1px solid #000000;
7769: }
1.795 www 7770:
1.507 raeburn 7771: table.LC_nested_outer tr td.LC_subheader {
7772: background-color: $data_table_head;
7773: font-weight: bold;
7774: font-size: small;
7775: border-bottom: 1px solid #000000;
7776: text-align: right;
1.451 albertel 7777: }
1.795 www 7778:
1.507 raeburn 7779: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7780: background-color: #CCCCCC;
1.451 albertel 7781: font-weight: bold;
7782: font-size: small;
1.507 raeburn 7783: text-align: center;
7784: }
1.795 www 7785:
1.589 raeburn 7786: table.LC_nested tr.LC_info_row td.LC_left_item,
7787: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7788: text-align: left;
1.451 albertel 7789: }
1.795 www 7790:
1.507 raeburn 7791: table.LC_nested td {
1.735 bisitz 7792: background-color: #FFFFFF;
1.451 albertel 7793: font-size: small;
1.507 raeburn 7794: }
1.795 www 7795:
1.507 raeburn 7796: table.LC_nested_outer tr th.LC_right_item,
7797: table.LC_nested tr.LC_info_row td.LC_right_item,
7798: table.LC_nested tr.LC_odd_row td.LC_right_item,
7799: table.LC_nested tr td.LC_right_item {
1.451 albertel 7800: text-align: right;
7801: }
7802:
1.507 raeburn 7803: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7804: background-color: #EEEEEE;
1.451 albertel 7805: }
7806:
1.473 raeburn 7807: table.LC_createuser {
7808: }
7809:
7810: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7811: font-size: small;
1.473 raeburn 7812: }
7813:
7814: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7815: background-color: #CCCCCC;
1.473 raeburn 7816: font-weight: bold;
7817: text-align: center;
7818: }
7819:
1.349 albertel 7820: table.LC_calendar {
7821: border: 1px solid #000000;
7822: border-collapse: collapse;
1.917 raeburn 7823: width: 98%;
1.349 albertel 7824: }
1.795 www 7825:
1.349 albertel 7826: table.LC_calendar_pickdate {
7827: font-size: xx-small;
7828: }
1.795 www 7829:
1.349 albertel 7830: table.LC_calendar tr td {
7831: border: 1px solid #000000;
7832: vertical-align: top;
1.917 raeburn 7833: width: 14%;
1.349 albertel 7834: }
1.795 www 7835:
1.349 albertel 7836: table.LC_calendar tr td.LC_calendar_day_empty {
7837: background-color: $data_table_dark;
7838: }
1.795 www 7839:
1.779 bisitz 7840: table.LC_calendar tr td.LC_calendar_day_current {
7841: background-color: $data_table_highlight;
1.777 tempelho 7842: }
1.795 www 7843:
1.938 bisitz 7844: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7845: background-color: $mail_new;
7846: }
1.795 www 7847:
1.938 bisitz 7848: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7849: background-color: $mail_new_hover;
7850: }
1.795 www 7851:
1.938 bisitz 7852: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7853: background-color: $mail_read;
7854: }
1.795 www 7855:
1.938 bisitz 7856: /*
7857: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7858: background-color: $mail_read_hover;
7859: }
1.938 bisitz 7860: */
1.795 www 7861:
1.938 bisitz 7862: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7863: background-color: $mail_replied;
7864: }
1.795 www 7865:
1.938 bisitz 7866: /*
7867: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7868: background-color: $mail_replied_hover;
7869: }
1.938 bisitz 7870: */
1.795 www 7871:
1.938 bisitz 7872: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7873: background-color: $mail_other;
7874: }
1.795 www 7875:
1.938 bisitz 7876: /*
7877: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7878: background-color: $mail_other_hover;
7879: }
1.938 bisitz 7880: */
1.494 raeburn 7881:
1.777 tempelho 7882: table.LC_data_table tr > td.LC_browser_file,
7883: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7884: background: #AAEE77;
1.389 albertel 7885: }
1.795 www 7886:
1.777 tempelho 7887: table.LC_data_table tr > td.LC_browser_file_locked,
7888: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7889: background: #FFAA99;
1.387 albertel 7890: }
1.795 www 7891:
1.777 tempelho 7892: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7893: background: #888888;
1.779 bisitz 7894: }
1.795 www 7895:
1.777 tempelho 7896: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7897: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7898: background: #F8F866;
1.777 tempelho 7899: }
1.795 www 7900:
1.696 bisitz 7901: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7902: background: #E0E8FF;
1.387 albertel 7903: }
1.696 bisitz 7904:
1.707 bisitz 7905: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7906: /* background: #77FF77; */
1.707 bisitz 7907: }
1.795 www 7908:
1.707 bisitz 7909: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7910: border-right: 8px solid #FFFF77;
1.707 bisitz 7911: }
1.795 www 7912:
1.707 bisitz 7913: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7914: border-right: 8px solid #FFAA77;
1.707 bisitz 7915: }
1.795 www 7916:
1.707 bisitz 7917: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7918: border-right: 8px solid #FF7777;
1.707 bisitz 7919: }
1.795 www 7920:
1.707 bisitz 7921: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7922: border-right: 8px solid #AAFF77;
1.707 bisitz 7923: }
1.795 www 7924:
1.707 bisitz 7925: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7926: border-right: 8px solid #11CC55;
1.707 bisitz 7927: }
7928:
1.388 albertel 7929: span.LC_current_location {
1.701 harmsja 7930: font-size:larger;
1.388 albertel 7931: background: $pgbg;
7932: }
1.387 albertel 7933:
1.1029 www 7934: span.LC_current_nav_location {
7935: font-weight:bold;
7936: background: $sidebg;
7937: }
7938:
1.395 albertel 7939: span.LC_parm_menu_item {
7940: font-size: larger;
7941: }
1.795 www 7942:
1.395 albertel 7943: span.LC_parm_scope_all {
7944: color: red;
7945: }
1.795 www 7946:
1.395 albertel 7947: span.LC_parm_scope_folder {
7948: color: green;
7949: }
1.795 www 7950:
1.395 albertel 7951: span.LC_parm_scope_resource {
7952: color: orange;
7953: }
1.795 www 7954:
1.395 albertel 7955: span.LC_parm_part {
7956: color: blue;
7957: }
1.795 www 7958:
1.911 bisitz 7959: span.LC_parm_folder,
7960: span.LC_parm_symb {
1.395 albertel 7961: font-size: x-small;
7962: font-family: $mono;
7963: color: #AAAAAA;
7964: }
7965:
1.977 bisitz 7966: ul.LC_parm_parmlist li {
7967: display: inline-block;
7968: padding: 0.3em 0.8em;
7969: vertical-align: top;
7970: width: 150px;
7971: border-top:1px solid $lg_border_color;
7972: }
7973:
1.795 www 7974: td.LC_parm_overview_level_menu,
7975: td.LC_parm_overview_map_menu,
7976: td.LC_parm_overview_parm_selectors,
7977: td.LC_parm_overview_restrictions {
1.396 albertel 7978: border: 1px solid black;
7979: border-collapse: collapse;
7980: }
1.795 www 7981:
1.1285 raeburn 7982: span.LC_parm_recursive,
7983: td.LC_parm_recursive {
7984: font-weight: bold;
7985: font-size: smaller;
7986: }
7987:
1.396 albertel 7988: table.LC_parm_overview_restrictions td {
7989: border-width: 1px 4px 1px 4px;
7990: border-style: solid;
7991: border-color: $pgbg;
7992: text-align: center;
7993: }
1.795 www 7994:
1.396 albertel 7995: table.LC_parm_overview_restrictions th {
7996: background: $tabbg;
7997: border-width: 1px 4px 1px 4px;
7998: border-style: solid;
7999: border-color: $pgbg;
8000: }
1.795 www 8001:
1.398 albertel 8002: table#LC_helpmenu {
1.803 bisitz 8003: border: none;
1.398 albertel 8004: height: 55px;
1.803 bisitz 8005: border-spacing: 0;
1.398 albertel 8006: }
8007:
8008: table#LC_helpmenu fieldset legend {
8009: font-size: larger;
8010: }
1.795 www 8011:
1.1456 raeburn 8012: .LC_helpdesk_headbox {
8013: border: 2px groove threedface;
8014: padding: 1em;
8015: }
8016:
8017: h1.LC_helpdesk_legend {
8018: float: left;
8019: margin: -1.7em 0 0;
8020: padding: 0 .5em;
1.397 albertel 8021: background: $pgbg;
1.1456 raeburn 8022: font-size: 1em;
8023: font-weight: bold;
8024: }
8025:
8026: h1.LC_helpdesk_title {
8027: display: inline;
8028: font-size: 1em;
8029: line-height: 2.5em;
8030: margin: 0;
1.803 bisitz 8031: padding: 0;
1.1456 raeburn 8032: vertical-align: bottom;
1.397 albertel 8033: }
1.795 www 8034:
1.1456 raeburn 8035: .LC_helpdesk_links {
8036: border: 1px solid black;
8037: padding: 3px;
1.397 albertel 8038: background: $tabbg;
1.399 albertel 8039: text-align: center;
8040: font-weight: bold;
1.1456 raeburn 8041: display: inline;
8042: margin-right: -6px;
8043: }
8044:
8045: .LC_helpdesk_img,
8046: .LC_helpdesk_text {
8047: padding: 0;
8048: margin: 0;
8049: border: 0;
8050: display: inline;
1.397 albertel 8051: }
1.396 albertel 8052:
1.1456 raeburn 8053: .LC_helpdesk_img a:link,
8054: .LC_helpdesk_img a:visited,
8055: .LC_helpdesk_img a:active,
8056: .LC_helpdesk_text a:link,
8057: .LC_helpdesk_text a:visited,
8058: .LC_helpdesk_text a:active {
1.397 albertel 8059: text-decoration: none;
8060: color: $font;
8061: }
1.795 www 8062:
1.1456 raeburn 8063: div.LC_helpdesk_text a:hover {
1.397 albertel 8064: text-decoration: underline;
8065: color: $vlink;
8066: }
1.396 albertel 8067:
1.417 albertel 8068: .LC_chrt_popup_exists {
8069: border: 1px solid #339933;
8070: margin: -1px;
8071: }
1.795 www 8072:
1.417 albertel 8073: .LC_chrt_popup_up {
8074: border: 1px solid yellow;
8075: margin: -1px;
8076: }
1.795 www 8077:
1.417 albertel 8078: .LC_chrt_popup {
8079: border: 1px solid #8888FF;
8080: background: #CCCCFF;
8081: }
1.795 www 8082:
1.421 albertel 8083: table.LC_pick_box {
8084: border-collapse: separate;
8085: background: white;
8086: border: 1px solid black;
8087: border-spacing: 1px;
8088: }
1.795 www 8089:
1.1454 raeburn 8090: table.LC_pick_box th.LC_pick_box_title {
1.850 bisitz 8091: background: $sidebg;
1.421 albertel 8092: font-weight: bold;
1.900 bisitz 8093: text-align: left;
1.740 bisitz 8094: vertical-align: top;
1.421 albertel 8095: width: 184px;
8096: padding: 8px;
8097: }
1.795 www 8098:
1.579 raeburn 8099: table.LC_pick_box td.LC_pick_box_value {
8100: text-align: left;
8101: padding: 8px;
8102: }
1.795 www 8103:
1.579 raeburn 8104: table.LC_pick_box td.LC_pick_box_select {
8105: text-align: left;
8106: padding: 8px;
8107: }
1.795 www 8108:
1.424 albertel 8109: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 8110: padding: 0;
1.421 albertel 8111: height: 1px;
8112: background: black;
8113: }
1.795 www 8114:
1.421 albertel 8115: table.LC_pick_box td.LC_pick_box_submit {
8116: text-align: right;
8117: }
1.795 www 8118:
1.579 raeburn 8119: table.LC_pick_box td.LC_evenrow_value {
8120: text-align: left;
8121: padding: 8px;
8122: background-color: $data_table_light;
8123: }
1.795 www 8124:
1.579 raeburn 8125: table.LC_pick_box td.LC_oddrow_value {
8126: text-align: left;
8127: padding: 8px;
8128: background-color: $data_table_light;
8129: }
1.795 www 8130:
1.579 raeburn 8131: span.LC_helpform_receipt_cat {
8132: font-weight: bold;
8133: }
1.795 www 8134:
1.424 albertel 8135: table.LC_group_priv_box {
8136: background: white;
8137: border: 1px solid black;
8138: border-spacing: 1px;
8139: }
1.795 www 8140:
1.424 albertel 8141: table.LC_group_priv_box td.LC_pick_box_title {
8142: background: $tabbg;
8143: font-weight: bold;
8144: text-align: right;
8145: width: 184px;
8146: }
1.795 www 8147:
1.424 albertel 8148: table.LC_group_priv_box td.LC_groups_fixed {
8149: background: $data_table_light;
8150: text-align: center;
8151: }
1.795 www 8152:
1.424 albertel 8153: table.LC_group_priv_box td.LC_groups_optional {
8154: background: $data_table_dark;
8155: text-align: center;
8156: }
1.795 www 8157:
1.424 albertel 8158: table.LC_group_priv_box td.LC_groups_functionality {
8159: background: $data_table_darker;
8160: text-align: center;
8161: font-weight: bold;
8162: }
1.795 www 8163:
1.424 albertel 8164: table.LC_group_priv td {
8165: text-align: left;
1.803 bisitz 8166: padding: 0;
1.424 albertel 8167: }
8168:
8169: .LC_navbuttons {
8170: margin: 2ex 0ex 2ex 0ex;
8171: }
1.795 www 8172:
1.423 albertel 8173: .LC_topic_bar {
8174: font-weight: bold;
8175: background: $tabbg;
1.918 wenzelju 8176: margin: 1em 0em 1em 2em;
1.805 bisitz 8177: padding: 3px;
1.918 wenzelju 8178: font-size: 1.2em;
1.423 albertel 8179: }
1.795 www 8180:
1.423 albertel 8181: .LC_topic_bar span {
1.918 wenzelju 8182: left: 0.5em;
8183: position: absolute;
1.423 albertel 8184: vertical-align: middle;
1.918 wenzelju 8185: font-size: 1.2em;
1.423 albertel 8186: }
1.795 www 8187:
1.423 albertel 8188: table.LC_course_group_status {
8189: margin: 20px;
8190: }
1.795 www 8191:
1.423 albertel 8192: table.LC_status_selector td {
8193: vertical-align: top;
8194: text-align: center;
1.424 albertel 8195: padding: 4px;
8196: }
1.795 www 8197:
1.599 albertel 8198: div.LC_feedback_link {
1.616 albertel 8199: clear: both;
1.829 kalberla 8200: background: $sidebg;
1.779 bisitz 8201: width: 100%;
1.829 kalberla 8202: padding-bottom: 10px;
8203: border: 1px $tabbg solid;
1.833 kalberla 8204: height: 22px;
8205: line-height: 22px;
8206: padding-top: 5px;
8207: }
8208:
8209: div.LC_feedback_link img {
8210: height: 22px;
1.867 kalberla 8211: vertical-align:middle;
1.829 kalberla 8212: }
8213:
1.911 bisitz 8214: div.LC_feedback_link a {
1.829 kalberla 8215: text-decoration: none;
1.489 raeburn 8216: }
1.795 www 8217:
1.867 kalberla 8218: div.LC_comblock {
1.911 bisitz 8219: display:inline;
1.867 kalberla 8220: color:$font;
8221: font-size:90%;
8222: }
8223:
8224: div.LC_feedback_link div.LC_comblock {
8225: padding-left:5px;
8226: }
8227:
8228: div.LC_feedback_link div.LC_comblock a {
8229: color:$font;
8230: }
8231:
1.489 raeburn 8232: span.LC_feedback_link {
1.858 bisitz 8233: /* background: $feedback_link_bg; */
1.599 albertel 8234: font-size: larger;
8235: }
1.795 www 8236:
1.599 albertel 8237: span.LC_message_link {
1.858 bisitz 8238: /* background: $feedback_link_bg; */
1.599 albertel 8239: font-size: larger;
8240: position: absolute;
8241: right: 1em;
1.489 raeburn 8242: }
1.421 albertel 8243:
1.515 albertel 8244: table.LC_prior_tries {
1.524 albertel 8245: border: 1px solid #000000;
8246: border-collapse: separate;
8247: border-spacing: 1px;
1.515 albertel 8248: }
1.523 albertel 8249:
1.515 albertel 8250: table.LC_prior_tries td {
1.524 albertel 8251: padding: 2px;
1.515 albertel 8252: }
1.523 albertel 8253:
8254: .LC_answer_correct {
1.795 www 8255: background: lightgreen;
8256: color: darkgreen;
8257: padding: 6px;
1.523 albertel 8258: }
1.795 www 8259:
1.523 albertel 8260: .LC_answer_charged_try {
1.797 www 8261: background: #FFAAAA;
1.795 www 8262: color: darkred;
8263: padding: 6px;
1.523 albertel 8264: }
1.795 www 8265:
1.779 bisitz 8266: .LC_answer_not_charged_try,
1.523 albertel 8267: .LC_answer_no_grade,
8268: .LC_answer_late {
1.795 www 8269: background: lightyellow;
1.523 albertel 8270: color: black;
1.795 www 8271: padding: 6px;
1.523 albertel 8272: }
1.795 www 8273:
1.523 albertel 8274: .LC_answer_previous {
1.795 www 8275: background: lightblue;
8276: color: darkblue;
8277: padding: 6px;
1.523 albertel 8278: }
1.795 www 8279:
1.779 bisitz 8280: .LC_answer_no_message {
1.777 tempelho 8281: background: #FFFFFF;
8282: color: black;
1.795 www 8283: padding: 6px;
1.779 bisitz 8284: }
1.795 www 8285:
1.1334 raeburn 8286: .LC_answer_unknown,
8287: .LC_answer_warning {
1.779 bisitz 8288: background: orange;
8289: color: black;
1.795 www 8290: padding: 6px;
1.777 tempelho 8291: }
1.795 www 8292:
1.1446 raeburn 8293: .LC_prob_status {
1.1447 raeburn 8294: margin-top: 5px;
1.1446 raeburn 8295: padding-top: 0;
8296: padding-left: 0;
8297: padding-bottom: 0;
8298: padding-right: 5px;
8299: }
8300:
1.1448 raeburn 8301: .LC_mail_actions {
8302: float: left;
8303: padding: 0;
8304: margin: 6px;
8305: }
8306:
8307: .LC_vertical_line {
8308: width: 1px;
8309: background-color: black;
8310: height: 4em;
8311: float: left;
8312: margin: 0;
8313: padding: 0;
8314: }
8315:
1.529 albertel 8316: span.LC_prior_numerical,
8317: span.LC_prior_string,
8318: span.LC_prior_custom,
8319: span.LC_prior_reaction,
8320: span.LC_prior_math {
1.925 bisitz 8321: font-family: $mono;
1.523 albertel 8322: white-space: pre;
8323: }
8324:
1.525 albertel 8325: span.LC_prior_string {
1.925 bisitz 8326: font-family: $mono;
1.525 albertel 8327: white-space: pre;
8328: }
8329:
1.523 albertel 8330: table.LC_prior_option {
8331: width: 100%;
8332: border-collapse: collapse;
8333: }
1.795 www 8334:
1.911 bisitz 8335: table.LC_prior_rank,
1.795 www 8336: table.LC_prior_match {
1.528 albertel 8337: border-collapse: collapse;
8338: }
1.795 www 8339:
1.528 albertel 8340: table.LC_prior_option tr td,
8341: table.LC_prior_rank tr td,
8342: table.LC_prior_match tr td {
1.524 albertel 8343: border: 1px solid #000000;
1.515 albertel 8344: }
8345:
1.855 bisitz 8346: .LC_nobreak {
1.544 albertel 8347: white-space: nowrap;
1.519 raeburn 8348: }
8349:
1.576 raeburn 8350: span.LC_cusr_emph {
8351: font-style: italic;
8352: }
8353:
1.633 raeburn 8354: span.LC_cusr_subheading {
8355: font-weight: normal;
8356: font-size: 85%;
8357: }
8358:
1.861 bisitz 8359: div.LC_docs_entry_move {
1.859 bisitz 8360: border: 1px solid #BBBBBB;
1.545 albertel 8361: background: #DDDDDD;
1.861 bisitz 8362: width: 22px;
1.859 bisitz 8363: padding: 1px;
8364: margin: 0;
1.545 albertel 8365: }
8366:
1.861 bisitz 8367: table.LC_data_table tr > td.LC_docs_entry_commands,
8368: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 8369: font-size: x-small;
8370: }
1.795 www 8371:
1.861 bisitz 8372: .LC_docs_entry_parameter {
8373: white-space: nowrap;
8374: }
8375:
1.544 albertel 8376: .LC_docs_copy {
1.545 albertel 8377: color: #000099;
1.544 albertel 8378: }
1.795 www 8379:
1.544 albertel 8380: .LC_docs_cut {
1.545 albertel 8381: color: #550044;
1.544 albertel 8382: }
1.795 www 8383:
1.544 albertel 8384: .LC_docs_rename {
1.545 albertel 8385: color: #009900;
1.544 albertel 8386: }
1.795 www 8387:
1.544 albertel 8388: .LC_docs_remove {
1.545 albertel 8389: color: #990000;
8390: }
8391:
1.1284 raeburn 8392: .LC_docs_alias {
8393: color: #440055;
8394: }
8395:
1.1286 raeburn 8396: .LC_domprefs_email,
1.1284 raeburn 8397: .LC_docs_alias_name,
1.547 albertel 8398: .LC_docs_reinit_warn,
8399: .LC_docs_ext_edit {
8400: font-size: x-small;
8401: }
8402:
1.545 albertel 8403: table.LC_docs_adddocs td,
8404: table.LC_docs_adddocs th {
8405: border: 1px solid #BBBBBB;
8406: padding: 4px;
8407: background: #DDDDDD;
1.543 albertel 8408: }
8409:
1.584 albertel 8410: table.LC_sty_begin {
8411: background: #BBFFBB;
8412: }
1.795 www 8413:
1.584 albertel 8414: table.LC_sty_end {
8415: background: #FFBBBB;
8416: }
8417:
1.589 raeburn 8418: table.LC_double_column {
1.803 bisitz 8419: border-width: 0;
1.589 raeburn 8420: border-collapse: collapse;
8421: width: 100%;
8422: padding: 2px;
8423: }
8424:
8425: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 8426: top: 2px;
1.589 raeburn 8427: left: 2px;
8428: width: 47%;
8429: vertical-align: top;
8430: }
8431:
8432: table.LC_double_column tr td.LC_right_col {
8433: top: 2px;
1.779 bisitz 8434: right: 2px;
1.589 raeburn 8435: width: 47%;
8436: vertical-align: top;
8437: }
8438:
1.591 raeburn 8439: div.LC_left_float {
8440: float: left;
8441: padding-right: 5%;
1.597 albertel 8442: padding-bottom: 4px;
1.591 raeburn 8443: }
8444:
8445: div.LC_clear_float_header {
1.597 albertel 8446: padding-bottom: 2px;
1.591 raeburn 8447: }
8448:
8449: div.LC_clear_float_footer {
1.597 albertel 8450: padding-top: 10px;
1.591 raeburn 8451: clear: both;
8452: }
8453:
1.597 albertel 8454: div.LC_grade_show_user {
1.941 bisitz 8455: /* border-left: 5px solid $sidebg; */
8456: border-top: 5px solid #000000;
8457: margin: 50px 0 0 0;
1.936 bisitz 8458: padding: 15px 0 5px 10px;
1.597 albertel 8459: }
1.795 www 8460:
1.936 bisitz 8461: div.LC_grade_show_user_odd_row {
1.941 bisitz 8462: /* border-left: 5px solid #000000; */
8463: }
8464:
8465: div.LC_grade_show_user div.LC_Box {
8466: margin-right: 50px;
1.597 albertel 8467: }
8468:
8469: div.LC_grade_submissions,
8470: div.LC_grade_message_center,
1.936 bisitz 8471: div.LC_grade_info_links {
1.597 albertel 8472: margin: 5px;
8473: width: 99%;
8474: background: #FFFFFF;
8475: }
1.795 www 8476:
1.597 albertel 8477: div.LC_grade_submissions_header,
1.936 bisitz 8478: div.LC_grade_message_center_header {
1.705 tempelho 8479: font-weight: bold;
8480: font-size: large;
1.597 albertel 8481: }
1.795 www 8482:
1.597 albertel 8483: div.LC_grade_submissions_body,
1.936 bisitz 8484: div.LC_grade_message_center_body {
1.597 albertel 8485: border: 1px solid black;
8486: width: 99%;
8487: background: #FFFFFF;
8488: }
1.795 www 8489:
1.613 albertel 8490: table.LC_scantron_action {
8491: width: 100%;
8492: }
1.795 www 8493:
1.613 albertel 8494: table.LC_scantron_action tr th {
1.698 harmsja 8495: font-weight:bold;
8496: font-style:normal;
1.613 albertel 8497: }
1.795 www 8498:
1.779 bisitz 8499: .LC_edit_problem_header,
1.614 albertel 8500: div.LC_edit_problem_footer {
1.705 tempelho 8501: font-weight: normal;
8502: font-size: medium;
1.602 albertel 8503: margin: 2px;
1.1060 bisitz 8504: background-color: $sidebg;
1.600 albertel 8505: }
1.795 www 8506:
1.600 albertel 8507: div.LC_edit_problem_header,
1.602 albertel 8508: div.LC_edit_problem_header div,
1.614 albertel 8509: div.LC_edit_problem_footer,
8510: div.LC_edit_problem_footer div,
1.602 albertel 8511: div.LC_edit_problem_editxml_header,
8512: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8513: z-index: 100;
1.600 albertel 8514: }
1.795 www 8515:
1.600 albertel 8516: div.LC_edit_problem_header_title {
1.705 tempelho 8517: font-weight: bold;
8518: font-size: larger;
1.602 albertel 8519: background: $tabbg;
8520: padding: 3px;
1.1060 bisitz 8521: margin: 0 0 5px 0;
1.602 albertel 8522: }
1.795 www 8523:
1.602 albertel 8524: table.LC_edit_problem_header_title {
8525: width: 100%;
1.600 albertel 8526: background: $tabbg;
1.602 albertel 8527: }
8528:
1.1205 golterma 8529: div.LC_edit_actionbar {
8530: background-color: $sidebg;
1.1218 droeschl 8531: margin: 0;
8532: padding: 0;
8533: line-height: 200%;
1.602 albertel 8534: }
1.795 www 8535:
1.1218 droeschl 8536: div.LC_edit_actionbar div{
8537: padding: 0;
8538: margin: 0;
8539: display: inline-block;
1.600 albertel 8540: }
1.795 www 8541:
1.1124 bisitz 8542: .LC_edit_opt {
8543: padding-left: 1em;
8544: white-space: nowrap;
8545: }
8546:
1.1152 golterma 8547: .LC_edit_problem_latexhelper{
8548: text-align: right;
8549: }
8550:
8551: #LC_edit_problem_colorful div{
8552: margin-left: 40px;
8553: }
8554:
1.1205 golterma 8555: #LC_edit_problem_codemirror div{
8556: margin-left: 0px;
8557: }
8558:
1.911 bisitz 8559: img.stift {
1.803 bisitz 8560: border-width: 0;
8561: vertical-align: middle;
1.677 riegler 8562: }
1.680 riegler 8563:
1.923 bisitz 8564: table td.LC_mainmenu_col_fieldset {
1.680 riegler 8565: vertical-align: top;
1.777 tempelho 8566: }
1.795 www 8567:
1.716 raeburn 8568: div.LC_createcourse {
1.911 bisitz 8569: margin: 10px 10px 10px 10px;
1.716 raeburn 8570: }
8571:
1.917 raeburn 8572: .LC_dccid {
1.1130 raeburn 8573: float: right;
1.917 raeburn 8574: margin: 0.2em 0 0 0;
8575: padding: 0;
8576: font-size: 90%;
8577: display:none;
8578: }
8579:
1.897 wenzelju 8580: ol.LC_primary_menu a:hover,
1.721 harmsja 8581: ol#LC_MenuBreadcrumbs a:hover,
8582: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8583: ul#LC_secondary_menu a:hover,
1.721 harmsja 8584: .LC_FormSectionClearButton input:hover
1.795 www 8585: ul.LC_TabContent li:hover a {
1.952 onken 8586: color:$button_hover;
1.911 bisitz 8587: text-decoration:none;
1.693 droeschl 8588: }
8589:
1.779 bisitz 8590: h1 {
1.911 bisitz 8591: padding: 0;
8592: line-height:130%;
1.693 droeschl 8593: }
1.698 harmsja 8594:
1.911 bisitz 8595: h2,
8596: h3,
8597: h4,
8598: h5,
8599: h6 {
8600: margin: 5px 0 5px 0;
8601: padding: 0;
8602: line-height:130%;
1.693 droeschl 8603: }
1.795 www 8604:
8605: .LC_hcell {
1.911 bisitz 8606: padding:3px 15px 3px 15px;
8607: margin: 0;
8608: background-color:$tabbg;
8609: color:$fontmenu;
8610: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8611: }
1.795 www 8612:
1.840 bisitz 8613: .LC_Box > .LC_hcell {
1.911 bisitz 8614: margin: 0 -10px 10px -10px;
1.835 bisitz 8615: }
8616:
1.721 harmsja 8617: .LC_noBorder {
1.911 bisitz 8618: border: 0;
1.698 harmsja 8619: }
1.693 droeschl 8620:
1.721 harmsja 8621: .LC_FormSectionClearButton input {
1.911 bisitz 8622: background-color:transparent;
8623: border: none;
8624: cursor:pointer;
8625: text-decoration:underline;
1.693 droeschl 8626: }
1.763 bisitz 8627:
8628: .LC_help_open_topic {
1.911 bisitz 8629: color: #FFFFFF;
8630: background-color: #EEEEFF;
8631: margin: 1px;
8632: padding: 4px;
8633: border: 1px solid #000033;
8634: white-space: nowrap;
8635: /* vertical-align: middle; */
1.759 neumanie 8636: }
1.693 droeschl 8637:
1.911 bisitz 8638: dl,
8639: ul,
8640: div,
8641: fieldset {
8642: margin: 10px 10px 10px 0;
8643: /* overflow: hidden; */
1.693 droeschl 8644: }
1.795 www 8645:
1.1404 raeburn 8646: fieldset#LC_selectuser {
8647: margin: 0;
8648: padding: 0;
8649: }
8650:
1.1211 raeburn 8651: article.geogebraweb div {
8652: margin: 0;
8653: }
8654:
1.838 bisitz 8655: fieldset > legend {
1.911 bisitz 8656: font-weight: bold;
8657: padding: 0 5px 0 5px;
1.838 bisitz 8658: }
8659:
1.813 bisitz 8660: #LC_nav_bar {
1.911 bisitz 8661: float: left;
1.995 raeburn 8662: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8663: margin: 0 0 2px 0;
1.807 droeschl 8664: }
8665:
1.916 droeschl 8666: #LC_realm {
8667: margin: 0.2em 0 0 0;
8668: padding: 0;
8669: font-weight: bold;
8670: text-align: center;
1.995 raeburn 8671: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8672: }
8673:
1.911 bisitz 8674: #LC_nav_bar em {
8675: font-weight: bold;
8676: font-style: normal;
1.807 droeschl 8677: }
8678:
1.897 wenzelju 8679: ol.LC_primary_menu {
1.934 droeschl 8680: margin: 0;
1.1076 raeburn 8681: padding: 0;
1.807 droeschl 8682: }
8683:
1.852 droeschl 8684: ol#LC_PathBreadcrumbs {
1.911 bisitz 8685: margin: 0;
1.693 droeschl 8686: }
8687:
1.897 wenzelju 8688: ol.LC_primary_menu li {
1.1076 raeburn 8689: color: RGB(80, 80, 80);
8690: vertical-align: middle;
8691: text-align: left;
8692: list-style: none;
1.1205 golterma 8693: position: relative;
1.1076 raeburn 8694: float: left;
1.1205 golterma 8695: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8696: line-height: 1.5em;
1.1076 raeburn 8697: }
8698:
1.1205 golterma 8699: ol.LC_primary_menu li a,
8700: ol.LC_primary_menu li p {
1.1076 raeburn 8701: display: block;
8702: margin: 0;
8703: padding: 0 5px 0 10px;
8704: text-decoration: none;
8705: }
8706:
1.1205 golterma 8707: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8708: display: inline-block;
8709: width: 95%;
8710: text-align: left;
8711: }
8712:
8713: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8714: display: inline-block;
8715: width: 5%;
8716: float: right;
8717: text-align: right;
8718: font-size: 70%;
8719: }
8720:
8721: ol.LC_primary_menu ul {
1.1076 raeburn 8722: display: none;
1.1205 golterma 8723: width: 15em;
1.1076 raeburn 8724: background-color: $data_table_light;
1.1205 golterma 8725: position: absolute;
8726: top: 100%;
1.1076 raeburn 8727: }
8728:
1.1205 golterma 8729: ol.LC_primary_menu ul ul {
8730: left: 100%;
8731: top: 0;
8732: }
8733:
8734: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8735: display: block;
8736: position: absolute;
8737: margin: 0;
8738: padding: 0;
1.1078 raeburn 8739: z-index: 2;
1.1076 raeburn 8740: }
8741:
8742: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8743: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8744: font-size: 90%;
1.911 bisitz 8745: vertical-align: top;
1.1076 raeburn 8746: float: none;
1.1079 raeburn 8747: border-left: 1px solid black;
8748: border-right: 1px solid black;
1.1205 golterma 8749: /* A dark bottom border to visualize different menu options;
8750: overwritten in the create_submenu routine for the last border-bottom of the menu */
8751: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8752: }
8753:
1.1205 golterma 8754: ol.LC_primary_menu li li p:hover {
8755: color:$button_hover;
8756: text-decoration:none;
8757: background-color:$data_table_dark;
1.1076 raeburn 8758: }
8759:
8760: ol.LC_primary_menu li li a:hover {
8761: color:$button_hover;
8762: background-color:$data_table_dark;
1.693 droeschl 8763: }
8764:
1.1205 golterma 8765: /* Font-size equal to the size of the predecessors*/
8766: ol.LC_primary_menu li:hover li li {
8767: font-size: 100%;
8768: }
8769:
1.897 wenzelju 8770: ol.LC_primary_menu li img {
1.911 bisitz 8771: vertical-align: bottom;
1.934 droeschl 8772: height: 1.1em;
1.1077 raeburn 8773: margin: 0.2em 0 0 0;
1.693 droeschl 8774: }
8775:
1.897 wenzelju 8776: ol.LC_primary_menu a {
1.911 bisitz 8777: color: RGB(80, 80, 80);
8778: text-decoration: none;
1.693 droeschl 8779: }
1.795 www 8780:
1.949 droeschl 8781: ol.LC_primary_menu a.LC_new_message {
8782: font-weight:bold;
8783: color: darkred;
8784: }
8785:
1.975 raeburn 8786: ol.LC_docs_parameters {
8787: margin-left: 0;
8788: padding: 0;
8789: list-style: none;
8790: }
8791:
8792: ol.LC_docs_parameters li {
8793: margin: 0;
8794: padding-right: 20px;
8795: display: inline;
8796: }
8797:
1.976 raeburn 8798: ol.LC_docs_parameters li:before {
8799: content: "\\002022 \\0020";
8800: }
8801:
8802: li.LC_docs_parameters_title {
8803: font-weight: bold;
8804: }
8805:
8806: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8807: content: "";
8808: }
8809:
1.897 wenzelju 8810: ul#LC_secondary_menu {
1.1107 raeburn 8811: clear: right;
1.911 bisitz 8812: color: $fontmenu;
8813: background: $tabbg;
8814: list-style: none;
8815: padding: 0;
8816: margin: 0;
8817: width: 100%;
1.995 raeburn 8818: text-align: left;
1.1107 raeburn 8819: float: left;
1.808 droeschl 8820: }
8821:
1.897 wenzelju 8822: ul#LC_secondary_menu li {
1.911 bisitz 8823: font-weight: bold;
8824: line-height: 1.8em;
1.1107 raeburn 8825: border-right: 1px solid black;
8826: float: left;
8827: }
8828:
8829: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8830: background-color: $data_table_light;
8831: }
8832:
8833: ul#LC_secondary_menu li a {
1.911 bisitz 8834: padding: 0 0.8em;
1.1107 raeburn 8835: }
8836:
8837: ul#LC_secondary_menu li ul {
8838: display: none;
8839: }
8840:
8841: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8842: display: block;
8843: position: absolute;
8844: margin: 0;
8845: padding: 0;
8846: list-style:none;
8847: float: none;
8848: background-color: $data_table_light;
8849: z-index: 2;
8850: margin-left: -1px;
8851: }
8852:
8853: ul#LC_secondary_menu li ul li {
8854: font-size: 90%;
8855: vertical-align: top;
8856: border-left: 1px solid black;
1.911 bisitz 8857: border-right: 1px solid black;
1.1119 raeburn 8858: background-color: $data_table_light;
1.1107 raeburn 8859: list-style:none;
8860: float: none;
8861: }
8862:
8863: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8864: background-color: $data_table_dark;
1.807 droeschl 8865: }
8866:
1.847 tempelho 8867: ul.LC_TabContent {
1.911 bisitz 8868: display:block;
8869: background: $sidebg;
8870: border-bottom: solid 1px $lg_border_color;
8871: list-style:none;
1.1020 raeburn 8872: margin: -1px -10px 0 -10px;
1.911 bisitz 8873: padding: 0;
1.693 droeschl 8874: }
8875:
1.795 www 8876: ul.LC_TabContent li,
8877: ul.LC_TabContentBigger li {
1.911 bisitz 8878: float:left;
1.741 harmsja 8879: }
1.795 www 8880:
1.897 wenzelju 8881: ul#LC_secondary_menu li a {
1.911 bisitz 8882: color: $fontmenu;
8883: text-decoration: none;
1.693 droeschl 8884: }
1.795 www 8885:
1.721 harmsja 8886: ul.LC_TabContent {
1.952 onken 8887: min-height:20px;
1.721 harmsja 8888: }
1.795 www 8889:
8890: ul.LC_TabContent li {
1.911 bisitz 8891: vertical-align:middle;
1.959 onken 8892: padding: 0 16px 0 10px;
1.911 bisitz 8893: background-color:$tabbg;
8894: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8895: border-left: solid 1px $font;
1.721 harmsja 8896: }
1.795 www 8897:
1.847 tempelho 8898: ul.LC_TabContent .right {
1.911 bisitz 8899: float:right;
1.847 tempelho 8900: }
8901:
1.911 bisitz 8902: ul.LC_TabContent li a,
8903: ul.LC_TabContent li {
8904: color:rgb(47,47,47);
8905: text-decoration:none;
8906: font-size:95%;
8907: font-weight:bold;
1.952 onken 8908: min-height:20px;
8909: }
8910:
1.959 onken 8911: ul.LC_TabContent li a:hover,
8912: ul.LC_TabContent li a:focus {
1.952 onken 8913: color: $button_hover;
1.959 onken 8914: background:none;
8915: outline:none;
1.952 onken 8916: }
8917:
8918: ul.LC_TabContent li:hover {
8919: color: $button_hover;
8920: cursor:pointer;
1.721 harmsja 8921: }
1.795 www 8922:
1.911 bisitz 8923: ul.LC_TabContent li.active {
1.952 onken 8924: color: $font;
1.911 bisitz 8925: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8926: border-bottom:solid 1px #FFFFFF;
8927: cursor: default;
1.744 ehlerst 8928: }
1.795 www 8929:
1.959 onken 8930: ul.LC_TabContent li.active a {
8931: color:$font;
8932: background:#FFFFFF;
8933: outline: none;
8934: }
1.1047 raeburn 8935:
8936: ul.LC_TabContent li.goback {
8937: float: left;
8938: border-left: none;
8939: }
8940:
1.870 tempelho 8941: #maincoursedoc {
1.911 bisitz 8942: clear:both;
1.870 tempelho 8943: }
8944:
8945: ul.LC_TabContentBigger {
1.911 bisitz 8946: display:block;
8947: list-style:none;
8948: padding: 0;
1.870 tempelho 8949: }
8950:
1.795 www 8951: ul.LC_TabContentBigger li {
1.911 bisitz 8952: vertical-align:bottom;
8953: height: 30px;
8954: font-size:110%;
8955: font-weight:bold;
8956: color: #737373;
1.841 tempelho 8957: }
8958:
1.957 onken 8959: ul.LC_TabContentBigger li.active {
8960: position: relative;
8961: top: 1px;
8962: }
8963:
1.870 tempelho 8964: ul.LC_TabContentBigger li a {
1.911 bisitz 8965: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8966: height: 30px;
8967: line-height: 30px;
8968: text-align: center;
8969: display: block;
8970: text-decoration: none;
1.958 onken 8971: outline: none;
1.741 harmsja 8972: }
1.795 www 8973:
1.870 tempelho 8974: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8975: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8976: color:$font;
1.744 ehlerst 8977: }
1.795 www 8978:
1.870 tempelho 8979: ul.LC_TabContentBigger li b {
1.911 bisitz 8980: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8981: display: block;
8982: float: left;
8983: padding: 0 30px;
1.957 onken 8984: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8985: }
8986:
1.956 onken 8987: ul.LC_TabContentBigger li:hover b {
8988: color:$button_hover;
8989: }
8990:
1.870 tempelho 8991: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8992: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8993: color:$font;
1.957 onken 8994: border: 0;
1.741 harmsja 8995: }
1.693 droeschl 8996:
1.870 tempelho 8997:
1.862 bisitz 8998: ul.LC_CourseBreadcrumbs {
8999: background: $sidebg;
1.1020 raeburn 9000: height: 2em;
1.862 bisitz 9001: padding-left: 10px;
1.1020 raeburn 9002: margin: 0;
1.862 bisitz 9003: list-style-position: inside;
9004: }
9005:
1.911 bisitz 9006: ol#LC_MenuBreadcrumbs,
1.862 bisitz 9007: ol#LC_PathBreadcrumbs {
1.911 bisitz 9008: padding-left: 10px;
9009: margin: 0;
1.933 droeschl 9010: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 9011: }
9012:
1.911 bisitz 9013: ol#LC_MenuBreadcrumbs li,
9014: ol#LC_PathBreadcrumbs li,
1.862 bisitz 9015: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 9016: display: inline;
1.933 droeschl 9017: white-space: normal;
1.693 droeschl 9018: }
9019:
1.823 bisitz 9020: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 9021: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 9022: text-decoration: none;
9023: font-size:90%;
1.693 droeschl 9024: }
1.795 www 9025:
1.969 droeschl 9026: ol#LC_MenuBreadcrumbs h1 {
9027: display: inline;
9028: font-size: 90%;
9029: line-height: 2.5em;
9030: margin: 0;
9031: padding: 0;
9032: }
9033:
1.795 www 9034: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 9035: text-decoration:none;
9036: font-size:100%;
9037: font-weight:bold;
1.693 droeschl 9038: }
1.795 www 9039:
1.840 bisitz 9040: .LC_Box {
1.911 bisitz 9041: border: solid 1px $lg_border_color;
9042: padding: 0 10px 10px 10px;
1.746 neumanie 9043: }
1.795 www 9044:
1.1020 raeburn 9045: .LC_DocsBox {
9046: border: solid 1px $lg_border_color;
9047: padding: 0 0 10px 10px;
9048: }
9049:
1.795 www 9050: .LC_AboutMe_Image {
1.911 bisitz 9051: float:left;
9052: margin-right:10px;
1.747 neumanie 9053: }
1.795 www 9054:
9055: .LC_Clear_AboutMe_Image {
1.911 bisitz 9056: clear:left;
1.747 neumanie 9057: }
1.795 www 9058:
1.721 harmsja 9059: dl.LC_ListStyleClean dt {
1.911 bisitz 9060: padding-right: 5px;
9061: display: table-header-group;
1.693 droeschl 9062: }
9063:
1.721 harmsja 9064: dl.LC_ListStyleClean dd {
1.911 bisitz 9065: display: table-row;
1.693 droeschl 9066: }
9067:
1.721 harmsja 9068: .LC_ListStyleClean,
9069: .LC_ListStyleSimple,
9070: .LC_ListStyleNormal,
1.795 www 9071: .LC_ListStyleSpecial {
1.911 bisitz 9072: /* display:block; */
9073: list-style-position: inside;
9074: list-style-type: none;
9075: overflow: hidden;
9076: padding: 0;
1.693 droeschl 9077: }
9078:
1.721 harmsja 9079: .LC_ListStyleSimple li,
9080: .LC_ListStyleSimple dd,
9081: .LC_ListStyleNormal li,
9082: .LC_ListStyleNormal dd,
9083: .LC_ListStyleSpecial li,
1.795 www 9084: .LC_ListStyleSpecial dd {
1.911 bisitz 9085: margin: 0;
9086: padding: 5px 5px 5px 10px;
9087: clear: both;
1.693 droeschl 9088: }
9089:
1.721 harmsja 9090: .LC_ListStyleClean li,
9091: .LC_ListStyleClean dd {
1.911 bisitz 9092: padding-top: 0;
9093: padding-bottom: 0;
1.693 droeschl 9094: }
9095:
1.721 harmsja 9096: .LC_ListStyleSimple dd,
1.795 www 9097: .LC_ListStyleSimple li {
1.911 bisitz 9098: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 9099: }
9100:
1.721 harmsja 9101: .LC_ListStyleSpecial li,
9102: .LC_ListStyleSpecial dd {
1.911 bisitz 9103: list-style-type: none;
9104: background-color: RGB(220, 220, 220);
9105: margin-bottom: 4px;
1.693 droeschl 9106: }
9107:
1.721 harmsja 9108: table.LC_SimpleTable {
1.911 bisitz 9109: margin:5px;
9110: border:solid 1px $lg_border_color;
1.795 www 9111: }
1.693 droeschl 9112:
1.721 harmsja 9113: table.LC_SimpleTable tr {
1.911 bisitz 9114: padding: 0;
9115: border:solid 1px $lg_border_color;
1.693 droeschl 9116: }
1.795 www 9117:
9118: table.LC_SimpleTable thead {
1.911 bisitz 9119: background:rgb(220,220,220);
1.693 droeschl 9120: }
9121:
1.721 harmsja 9122: div.LC_columnSection {
1.911 bisitz 9123: display: block;
9124: clear: both;
9125: overflow: hidden;
9126: margin: 0;
1.693 droeschl 9127: }
9128:
1.721 harmsja 9129: div.LC_columnSection>* {
1.911 bisitz 9130: float: left;
9131: margin: 10px 20px 10px 0;
9132: overflow:hidden;
1.693 droeschl 9133: }
1.721 harmsja 9134:
1.795 www 9135: table em {
1.911 bisitz 9136: font-weight: bold;
9137: font-style: normal;
1.748 schulted 9138: }
1.795 www 9139:
1.779 bisitz 9140: table.LC_tableBrowseRes,
1.795 www 9141: table.LC_tableOfContent {
1.911 bisitz 9142: border:none;
9143: border-spacing: 1px;
9144: padding: 3px;
9145: background-color: #FFFFFF;
9146: font-size: 90%;
1.753 droeschl 9147: }
1.789 droeschl 9148:
1.911 bisitz 9149: table.LC_tableOfContent {
9150: border-collapse: collapse;
1.789 droeschl 9151: }
9152:
1.771 droeschl 9153: table.LC_tableBrowseRes a,
1.768 schulted 9154: table.LC_tableOfContent a {
1.911 bisitz 9155: background-color: transparent;
9156: text-decoration: none;
1.753 droeschl 9157: }
9158:
1.795 www 9159: table.LC_tableOfContent img {
1.911 bisitz 9160: border: none;
9161: height: 1.3em;
9162: vertical-align: text-bottom;
9163: margin-right: 0.3em;
1.753 droeschl 9164: }
1.757 schulted 9165:
1.795 www 9166: a#LC_content_toolbar_firsthomework {
1.911 bisitz 9167: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 9168: }
9169:
1.795 www 9170: a#LC_content_toolbar_everything {
1.911 bisitz 9171: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 9172: }
9173:
1.795 www 9174: a#LC_content_toolbar_uncompleted {
1.911 bisitz 9175: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 9176: }
9177:
1.795 www 9178: #LC_content_toolbar_clearbubbles {
1.911 bisitz 9179: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 9180: }
9181:
1.795 www 9182: a#LC_content_toolbar_changefolder {
1.911 bisitz 9183: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 9184: }
9185:
1.795 www 9186: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 9187: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 9188: }
9189:
1.1043 raeburn 9190: a#LC_content_toolbar_edittoplevel {
9191: background-image:url(/res/adm/pages/edittoplevel.gif);
9192: }
9193:
1.1384 raeburn 9194: a#LC_content_toolbar_printout {
9195: background-image:url(/res/adm/pages/printout.gif);
9196: }
9197:
1.795 www 9198: ul#LC_toolbar li a:hover {
1.911 bisitz 9199: background-position: bottom center;
1.757 schulted 9200: }
9201:
1.795 www 9202: ul#LC_toolbar {
1.911 bisitz 9203: padding: 0;
9204: margin: 2px;
9205: list-style:none;
1.1449 raeburn 9206: display:inline;
1.911 bisitz 9207: background-color:white;
1.1082 raeburn 9208: overflow: auto;
1.757 schulted 9209: }
9210:
1.795 www 9211: ul#LC_toolbar li {
1.911 bisitz 9212: border:1px solid white;
9213: padding: 0;
9214: margin: 0;
9215: float: left;
9216: display:inline;
9217: vertical-align:middle;
1.1082 raeburn 9218: white-space: nowrap;
1.911 bisitz 9219: }
1.757 schulted 9220:
1.783 amueller 9221:
1.795 www 9222: a.LC_toolbarItem {
1.911 bisitz 9223: display:block;
9224: padding: 0;
9225: margin: 0;
9226: height: 32px;
9227: width: 32px;
9228: color:white;
9229: border: none;
9230: background-repeat:no-repeat;
9231: background-color:transparent;
1.757 schulted 9232: }
9233:
1.1449 raeburn 9234: .LC_navtools {
9235: display: inline-block;
9236: padding: 0;
9237: margin: 2px;
9238: vertical-align: middle;
9239: }
9240:
1.915 droeschl 9241: ul.LC_funclist {
9242: margin: 0;
9243: padding: 0.5em 1em 0.5em 0;
9244: }
9245:
1.933 droeschl 9246: ul.LC_funclist > li:first-child {
9247: font-weight:bold;
9248: margin-left:0.8em;
9249: }
9250:
1.915 droeschl 9251: ul.LC_funclist + ul.LC_funclist {
9252: /*
9253: left border as a seperator if we have more than
9254: one list
9255: */
9256: border-left: 1px solid $sidebg;
9257: /*
9258: this hides the left border behind the border of the
9259: outer box if element is wrapped to the next 'line'
9260: */
9261: margin-left: -1px;
9262: }
9263:
1.843 bisitz 9264: ul.LC_funclist li {
1.915 droeschl 9265: display: inline;
1.782 bisitz 9266: white-space: nowrap;
1.915 droeschl 9267: margin: 0 0 0 25px;
9268: line-height: 150%;
1.782 bisitz 9269: }
9270:
1.974 wenzelju 9271: .LC_hidden {
9272: display: none;
9273: }
9274:
1.1030 www 9275: .LCmodal-overlay {
9276: position:fixed;
9277: top:0;
9278: right:0;
9279: bottom:0;
9280: left:0;
9281: height:100%;
9282: width:100%;
9283: margin:0;
9284: padding:0;
9285: background:#999;
9286: opacity:.75;
9287: filter: alpha(opacity=75);
9288: -moz-opacity: 0.75;
9289: z-index:101;
9290: }
9291:
9292: * html .LCmodal-overlay {
9293: position: absolute;
9294: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
9295: }
9296:
9297: .LCmodal-window {
9298: position:fixed;
9299: top:50%;
9300: left:50%;
9301: margin:0;
9302: padding:0;
9303: z-index:102;
9304: }
9305:
9306: * html .LCmodal-window {
9307: position:absolute;
9308: }
9309:
9310: .LCclose-window {
9311: position:absolute;
9312: width:32px;
9313: height:32px;
9314: right:8px;
9315: top:8px;
9316: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
9317: text-indent:-99999px;
9318: overflow:hidden;
9319: cursor:pointer;
9320: }
9321:
1.1369 raeburn 9322: .LCisDisabled {
9323: cursor: not-allowed;
9324: opacity: 0.5;
9325: }
9326:
9327: a[aria-disabled="true"] {
9328: color: currentColor;
9329: display: inline-block; /* For IE11/ MS Edge bug */
9330: pointer-events: none;
9331: text-decoration: none;
9332: }
9333:
1.1335 raeburn 9334: pre.LC_wordwrap {
9335: white-space: pre-wrap;
9336: white-space: -moz-pre-wrap;
9337: white-space: -pre-wrap;
9338: white-space: -o-pre-wrap;
9339: word-wrap: break-word;
9340: }
9341:
1.1100 raeburn 9342: /*
1.1231 damieng 9343: styles used for response display
9344: */
9345: div.LC_radiofoil, div.LC_rankfoil {
9346: margin: .5em 0em .5em 0em;
9347: }
9348: table.LC_itemgroup {
9349: margin-top: 1em;
9350: }
9351:
9352: /*
1.1100 raeburn 9353: styles used by TTH when "Default set of options to pass to tth/m
9354: when converting TeX" in course settings has been set
9355:
9356: option passed: -t
9357:
9358: */
9359:
9360: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
9361: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
9362: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
9363: td div.norm {line-height:normal;}
9364:
9365: /*
9366: option passed -y3
9367: */
9368:
9369: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
9370: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
9371: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
9372:
1.1230 damieng 9373: /*
9374: sections with roles, for content only
9375: */
9376: section[class^="role-"] {
9377: padding-left: 10px;
9378: padding-right: 5px;
9379: margin-top: 8px;
9380: margin-bottom: 8px;
9381: border: 1px solid #2A4;
9382: border-radius: 5px;
9383: box-shadow: 0px 1px 1px #BBB;
9384: }
9385: section[class^="role-"]>h1 {
9386: position: relative;
9387: margin: 0px;
9388: padding-top: 10px;
9389: padding-left: 40px;
9390: }
9391: section[class^="role-"]>h1:before {
9392: position: absolute;
9393: left: -5px;
9394: top: 5px;
9395: }
9396: section.role-activity>h1:before {
9397: content:url('/adm/daxe/images/section_icons/activity.png');
9398: }
9399: section.role-advice>h1:before {
9400: content:url('/adm/daxe/images/section_icons/advice.png');
9401: }
9402: section.role-bibliography>h1:before {
9403: content:url('/adm/daxe/images/section_icons/bibliography.png');
9404: }
9405: section.role-citation>h1:before {
9406: content:url('/adm/daxe/images/section_icons/citation.png');
9407: }
9408: section.role-conclusion>h1:before {
9409: content:url('/adm/daxe/images/section_icons/conclusion.png');
9410: }
9411: section.role-definition>h1:before {
9412: content:url('/adm/daxe/images/section_icons/definition.png');
9413: }
9414: section.role-demonstration>h1:before {
9415: content:url('/adm/daxe/images/section_icons/demonstration.png');
9416: }
9417: section.role-example>h1:before {
9418: content:url('/adm/daxe/images/section_icons/example.png');
9419: }
9420: section.role-explanation>h1:before {
9421: content:url('/adm/daxe/images/section_icons/explanation.png');
9422: }
9423: section.role-introduction>h1:before {
9424: content:url('/adm/daxe/images/section_icons/introduction.png');
9425: }
9426: section.role-method>h1:before {
9427: content:url('/adm/daxe/images/section_icons/method.png');
9428: }
9429: section.role-more_information>h1:before {
9430: content:url('/adm/daxe/images/section_icons/more_information.png');
9431: }
9432: section.role-objectives>h1:before {
9433: content:url('/adm/daxe/images/section_icons/objectives.png');
9434: }
9435: section.role-prerequisites>h1:before {
9436: content:url('/adm/daxe/images/section_icons/prerequisites.png');
9437: }
9438: section.role-remark>h1:before {
9439: content:url('/adm/daxe/images/section_icons/remark.png');
9440: }
9441: section.role-reminder>h1:before {
9442: content:url('/adm/daxe/images/section_icons/reminder.png');
9443: }
9444: section.role-summary>h1:before {
9445: content:url('/adm/daxe/images/section_icons/summary.png');
9446: }
9447: section.role-syntax>h1:before {
9448: content:url('/adm/daxe/images/section_icons/syntax.png');
9449: }
9450: section.role-warning>h1:before {
9451: content:url('/adm/daxe/images/section_icons/warning.png');
9452: }
9453:
1.1269 raeburn 9454: #LC_minitab_header {
9455: float:left;
9456: width:100%;
9457: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
9458: font-size:93%;
9459: line-height:normal;
9460: margin: 0.5em 0 0.5em 0;
9461: }
9462: #LC_minitab_header ul {
9463: margin:0;
9464: padding:10px 10px 0;
9465: list-style:none;
9466: }
9467: #LC_minitab_header li {
9468: float:left;
9469: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
9470: margin:0;
9471: padding:0 0 0 9px;
9472: }
9473: #LC_minitab_header a {
9474: display:block;
9475: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
9476: padding:5px 15px 4px 6px;
9477: }
9478: #LC_minitab_header #LC_current_minitab {
9479: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
9480: }
9481: #LC_minitab_header #LC_current_minitab a {
9482: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
9483: padding-bottom:5px;
9484: }
9485:
9486:
1.343 albertel 9487: END
9488: }
9489:
1.306 albertel 9490: =pod
9491:
9492: =item * &headtag()
9493:
9494: Returns a uniform footer for LON-CAPA web pages.
9495:
1.307 albertel 9496: Inputs: $title - optional title for the head
9497: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9498: $args - optional arguments
1.319 albertel 9499: force_register - if is true call registerurl so the remote is
9500: informed
1.415 albertel 9501: redirect -> array ref of
9502: 1- seconds before redirect occurs
9503: 2- url to redirect to
9504: 3- whether the side effect should occur
1.315 albertel 9505: (side effect of setting
9506: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9507: redirected to)
9508: 4- whether the redirect target should be
9509: the opener of the current (pop-up)
9510: window (side effect of setting
9511: $env{'internal.head.to_opener'} to
9512: 1, if true.
1.1388 raeburn 9513: 5- whether encrypt check should be skipped
1.352 albertel 9514: domain -> force to color decorate a page for a specific
9515: domain
9516: function -> force usage of a specific rolish color scheme
9517: bgcolor -> override the default page bgcolor
1.460 albertel 9518: no_auto_mt_title
9519: -> prevent &mt()ing the title arg
1.464 albertel 9520:
1.306 albertel 9521: =cut
9522:
9523: sub headtag {
1.313 albertel 9524: my ($title,$head_extra,$args) = @_;
1.306 albertel 9525:
1.363 albertel 9526: my $function = $args->{'function'} || &get_users_function();
9527: my $domain = $args->{'domain'} || &determinedomain();
9528: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9529: my $httphost = $args->{'use_absolute'};
1.418 albertel 9530: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9531: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9532: #time(),
1.418 albertel 9533: $env{'environment.color.timestamp'},
1.363 albertel 9534: $function,$domain,$bgcolor);
9535:
1.369 www 9536: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9537:
1.308 albertel 9538: my $result =
9539: '<head>'.
1.1160 raeburn 9540: &font_settings($args);
1.319 albertel 9541:
1.1188 raeburn 9542: my $inhibitprint;
9543: if ($args->{'print_suppress'}) {
9544: $inhibitprint = &print_suppression();
9545: }
1.1064 raeburn 9546:
1.1439 raeburn 9547: if (!$args->{'frameset'} && !$args->{'switchserver'}) {
1.461 albertel 9548: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9549: }
1.962 droeschl 9550: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9551: $result .= Apache::lonxml::display_title();
1.319 albertel 9552: }
1.436 albertel 9553: if (!$args->{'no_nav_bar'}
9554: && !$args->{'only_body'}
1.1438 raeburn 9555: && !$args->{'frameset'}
9556: && !$args->{'switchserver'}) {
1.1154 raeburn 9557: $result .= &help_menu_js($httphost);
1.1032 www 9558: $result.=&modal_window();
1.1038 www 9559: $result.=&togglebox_script();
1.1034 www 9560: $result.=&wishlist_window();
1.1041 www 9561: $result.=&LCprogressbarUpdate_script();
1.1034 www 9562: } else {
9563: if ($args->{'add_modal'}) {
9564: $result.=&modal_window();
9565: }
9566: if ($args->{'add_wishlist'}) {
9567: $result.=&wishlist_window();
9568: }
1.1038 www 9569: if ($args->{'add_togglebox'}) {
9570: $result.=&togglebox_script();
9571: }
1.1041 www 9572: if ($args->{'add_progressbar'}) {
9573: $result.=&LCprogressbarUpdate_script();
9574: }
1.436 albertel 9575: }
1.314 albertel 9576: if (ref($args->{'redirect'})) {
1.1388 raeburn 9577: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9578: if (!$skip_enc_check) {
9579: $url = &Apache::lonenc::check_encrypt($url);
9580: }
1.414 albertel 9581: if (!$inhibit_continue) {
9582: $env{'internal.head.redirect'} = $url;
9583: }
1.1386 raeburn 9584: $result.=<<"ADDMETA";
1.313 albertel 9585: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9586: ADDMETA
9587: if ($to_opener) {
9588: $env{'internal.head.to_opener'} = 1;
9589: my $dest = &js_escape($url);
9590: my $timeout = int($time * 1000);
9591: $result .=<<"ENDJS";
9592: <script type="text/javascript">
9593: // <![CDATA[
9594: function LC_To_Opener() {
9595: var dest = '$dest';
9596: if (dest != '') {
9597: if (window.opener != null && !window.opener.closed) {
9598: window.opener.location.href=dest;
9599: window.close();
9600: } else {
9601: window.location.href=dest;
9602: }
9603: }
9604: }
9605: \$(document).ready(function () {
9606: setTimeout('LC_To_Opener()',$timeout);
9607: });
9608: // ]]>
9609: </script>
9610: ENDJS
9611: } else {
9612: $result.=<<"ADDMETA";
1.344 albertel 9613: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9614: ADDMETA
1.1386 raeburn 9615: }
1.1210 raeburn 9616: } else {
9617: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9618: my $requrl = $env{'request.uri'};
9619: if ($requrl eq '') {
9620: $requrl = $ENV{'REQUEST_URI'};
9621: $requrl =~ s/\?.+$//;
9622: }
9623: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9624: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9625: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9626: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9627: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9628: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9629: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9630: my ($offload,$offloadoth);
1.1210 raeburn 9631: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9632: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9633: $offload = 1;
1.1353 raeburn 9634: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9635: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9636: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9637: $offloadoth = 1;
9638: $dom_in_use = $env{'user.domain'};
9639: }
9640: }
1.1340 raeburn 9641: }
9642: }
9643: unless ($offload) {
9644: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9645: if ($domdefs{'offloadoth'}{$lonhost}) {
9646: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9647: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9648: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9649: $offload = 1;
1.1352 raeburn 9650: $offloadoth = 1;
1.1340 raeburn 9651: $dom_in_use = $env{'user.domain'};
9652: }
1.1210 raeburn 9653: }
1.1340 raeburn 9654: }
9655: }
9656: }
9657: if ($offload) {
1.1358 raeburn 9658: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9659: if (($newserver eq '') && ($offloadoth)) {
9660: my @domains = &Apache::lonnet::current_machine_domains();
9661: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9662: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9663: }
9664: }
1.1340 raeburn 9665: if (($newserver) && ($newserver ne $lonhost)) {
9666: my $numsec = 5;
9667: my $timeout = $numsec * 1000;
9668: my ($newurl,$locknum,%locks,$msg);
9669: if ($env{'request.role.adv'}) {
9670: ($locknum,%locks) = &Apache::lonnet::get_locks();
9671: }
9672: my $disable_submit = 0;
9673: if ($requrl =~ /$LONCAPA::assess_re/) {
9674: $disable_submit = 1;
9675: }
9676: if ($locknum) {
9677: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9678: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9679: join(", ",sort(values(%locks)))."\n";
9680: if (&show_course()) {
9681: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9682: } else {
9683: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9684: }
1.1340 raeburn 9685: } else {
9686: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9687: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9688: }
9689: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9690: $newurl = '/adm/switchserver?otherserver='.$newserver;
9691: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9692: $newurl .= '&role='.$env{'request.role'};
9693: }
9694: if ($env{'request.symb'}) {
9695: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9696: if ($shownsymb =~ m{^/enc/}) {
9697: my $reqdmajor = 2;
9698: my $reqdminor = 11;
9699: my $reqdsubminor = 3;
9700: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9701: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9702: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9703: if (($major eq '' && $minor eq '') ||
9704: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9705: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9706: ($reqdsubminor > $subminor))))) {
9707: undef($shownsymb);
9708: }
1.1210 raeburn 9709: }
1.1340 raeburn 9710: if ($shownsymb) {
9711: &js_escape(\$shownsymb);
9712: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9713: }
1.1340 raeburn 9714: } else {
9715: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9716: &js_escape(\$shownurl);
9717: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9718: }
1.1340 raeburn 9719: }
9720: &js_escape(\$msg);
9721: $result.=<<OFFLOAD
1.1210 raeburn 9722: <meta http-equiv="pragma" content="no-cache" />
9723: <script type="text/javascript">
1.1215 raeburn 9724: // <![CDATA[
1.1210 raeburn 9725: function LC_Offload_Now() {
9726: var dest = "$newurl";
9727: if (dest != '') {
9728: window.location.href="$newurl";
9729: }
9730: }
1.1214 raeburn 9731: \$(document).ready(function () {
9732: window.alert('$msg');
9733: if ($disable_submit) {
1.1210 raeburn 9734: \$(".LC_hwk_submit").prop("disabled", true);
9735: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9736: }
9737: setTimeout('LC_Offload_Now()', $timeout);
9738: });
1.1215 raeburn 9739: // ]]>
1.1210 raeburn 9740: </script>
9741: OFFLOAD
9742: }
9743: }
9744: }
9745: }
9746: }
1.313 albertel 9747: }
1.306 albertel 9748: if (!defined($title)) {
9749: $title = 'The LearningOnline Network with CAPA';
9750: }
1.460 albertel 9751: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1432 raeburn 9752: if ($title =~ /^LON-CAPA\s+/) {
9753: $result .= '<title> '.$title.'</title>';
9754: } else {
9755: $result .= '<title> LON-CAPA '.$title.'</title>';
9756: }
9757: $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1168 raeburn 9758: if (!$args->{'frameset'}) {
9759: $result .= ' /';
9760: }
9761: $result .= '>'
1.1064 raeburn 9762: .$inhibitprint
1.414 albertel 9763: .$head_extra;
1.1242 raeburn 9764: my $clientmobile;
9765: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9766: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9767: } else {
9768: $clientmobile = $env{'browser.mobile'};
9769: }
9770: if ($clientmobile) {
1.1137 raeburn 9771: $result .= '
1.1435 raeburn 9772: <meta name="viewport" content="width=device-width, initial-scale=1.0">
1.1137 raeburn 9773: <meta name="apple-mobile-web-app-capable" content="yes" />';
9774: }
1.1455 raeburn 9775: $result .= '<meta name="google" content="notranslate"';
9776: if (!$args->{'frameset'}) {
9777: $result .= ' /';
9778: }
9779: $result .= '>'."\n";
1.962 droeschl 9780: return $result.'</head>';
1.306 albertel 9781: }
9782:
9783: =pod
9784:
1.340 albertel 9785: =item * &font_settings()
9786:
9787: Returns neccessary <meta> to set the proper encoding
9788:
1.1160 raeburn 9789: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9790:
9791: =cut
9792:
9793: sub font_settings {
1.1160 raeburn 9794: my ($args) = @_;
1.340 albertel 9795: my $headerstring='';
1.1160 raeburn 9796: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9797: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9798: $headerstring.=
9799: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9800: if (!$args->{'frameset'}) {
9801: $headerstring.= ' /';
9802: }
9803: $headerstring .= '>'."\n";
1.340 albertel 9804: }
9805: return $headerstring;
9806: }
9807:
1.341 albertel 9808: =pod
9809:
1.1064 raeburn 9810: =item * &print_suppression()
9811:
9812: In course context returns css which causes the body to be blank when media="print",
9813: if printout generation is unavailable for the current resource.
9814:
9815: This could be because:
9816:
9817: (a) printstartdate is in the future
9818:
9819: (b) printenddate is in the past
9820:
9821: (c) there is an active exam block with "printout"
9822: functionality blocked
9823:
9824: Users with pav, pfo or evb privileges are exempt.
9825:
9826: Inputs: none
9827:
9828: =cut
9829:
9830:
9831: sub print_suppression {
9832: my $noprint;
9833: if ($env{'request.course.id'}) {
9834: my $scope = $env{'request.course.id'};
9835: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9836: (&Apache::lonnet::allowed('pfo',$scope))) {
9837: return;
9838: }
9839: if ($env{'request.course.sec'} ne '') {
9840: $scope .= "/$env{'request.course.sec'}";
9841: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9842: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9843: return;
1.1064 raeburn 9844: }
9845: }
9846: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9847: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9848: my $clientip = &Apache::lonnet::get_requestor_ip();
9849: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9850: if ($blocked) {
9851: my $checkrole = "cm./$cdom/$cnum";
9852: if ($env{'request.course.sec'} ne '') {
9853: $checkrole .= "/$env{'request.course.sec'}";
9854: }
9855: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9856: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9857: $noprint = 1;
9858: }
9859: }
9860: unless ($noprint) {
9861: my $symb = &Apache::lonnet::symbread();
9862: if ($symb ne '') {
9863: my $navmap = Apache::lonnavmaps::navmap->new();
9864: if (ref($navmap)) {
9865: my $res = $navmap->getBySymb($symb);
9866: if (ref($res)) {
9867: if (!$res->resprintable()) {
9868: $noprint = 1;
9869: }
9870: }
9871: }
9872: }
9873: }
9874: if ($noprint) {
9875: return <<"ENDSTYLE";
9876: <style type="text/css" media="print">
9877: body { display:none }
9878: </style>
9879: ENDSTYLE
9880: }
9881: }
9882: return;
9883: }
9884:
9885: =pod
9886:
1.341 albertel 9887: =item * &xml_begin()
9888:
9889: Returns the needed doctype and <html>
9890:
9891: Inputs: none
9892:
9893: =cut
9894:
9895: sub xml_begin {
1.1168 raeburn 9896: my ($is_frameset) = @_;
1.341 albertel 9897: my $output='';
9898:
9899: if ($env{'browser.mathml'}) {
9900: $output='<?xml version="1.0"?>'
9901: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9902: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9903:
9904: # .'<!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">] >'
9905: .'<!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">'
9906: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9907: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9908: } elsif ($is_frameset) {
9909: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9910: '<html>'."\n";
1.341 albertel 9911: } else {
1.1168 raeburn 9912: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9913: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9914: }
9915: return $output;
9916: }
1.340 albertel 9917:
9918: =pod
9919:
1.306 albertel 9920: =item * &start_page()
9921:
9922: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9923:
1.648 raeburn 9924: Inputs:
9925:
9926: =over 4
9927:
9928: $title - optional title for the page
9929:
9930: $head_extra - optional extra HTML to incude inside the <head>
9931:
9932: $args - additional optional args supported are:
9933:
9934: =over 8
9935:
9936: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9937: arg on
1.814 bisitz 9938: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9939: add_entries -> additional attributes to add to the <body>
9940: domain -> force to color decorate a page for a
1.317 albertel 9941: specific domain
1.648 raeburn 9942: function -> force usage of a specific rolish color
1.317 albertel 9943: scheme
1.648 raeburn 9944: redirect -> see &headtag()
9945: bgcolor -> override the default page bg color
9946: js_ready -> return a string ready for being used in
1.317 albertel 9947: a javascript writeln
1.648 raeburn 9948: html_encode -> return a string ready for being used in
1.320 albertel 9949: a html attribute
1.648 raeburn 9950: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9951: $forcereg arg
1.648 raeburn 9952: frameset -> if true will start with a <frameset>
1.330 albertel 9953: rather than <body>
1.648 raeburn 9954: skip_phases -> hash ref of
1.338 albertel 9955: head -> skip the <html><head> generation
9956: body -> skip all <body> generation
1.648 raeburn 9957: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9958: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9959: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1437 raeburn 9960: bread_crumbs_style -> breadcrumbs are contained within <div id="LC_breadcrumbs">,
9961: and &standard_css() contains CSS for #LC_breadcrumbs, if you want
9962: to override those values, or add to them, specify the value to
9963: include in the style attribute to include in the div tag by using
9964: bread_crumbs_style (e.g., overflow: visible)
1.1272 raeburn 9965: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9966: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9967: group -> includes the current group, if page is for a
1.1274 raeburn 9968: specific group
9969: use_absolute -> for request for external resource or syllabus, this
9970: will contain https://<hostname> if server uses
9971: https (as per hosts.tab), but request is for http
9972: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9973: links_disabled -> Links in primary and secondary menus are disabled
9974: (Can enable them once page has loaded - see lonroles.pm
9975: for an example).
1.1380 raeburn 9976: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9977:
1.648 raeburn 9978: =back
1.460 albertel 9979:
1.648 raeburn 9980: =back
1.562 albertel 9981:
1.306 albertel 9982: =cut
9983:
9984: sub start_page {
1.309 albertel 9985: my ($title,$head_extra,$args) = @_;
1.318 albertel 9986: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9987:
1.315 albertel 9988: $env{'internal.start_page'}++;
1.1359 raeburn 9989: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9990:
1.338 albertel 9991: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9992: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9993: }
1.1316 raeburn 9994:
9995: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9996: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9997: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9998: $args->{'no_primary_menu'} = 1;
9999: }
10000: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
10001: $args->{'no_inline_menu'} = 1;
10002: }
10003: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
10004: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
10005: }
10006: } else {
10007: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10008: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
10009: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
10010: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
10011: $args->{'no_primary_menu'} = 1;
10012: }
10013: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
10014: $args->{'no_inline_menu'} = 1;
10015: }
10016: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
10017: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
10018: }
10019: }
10020: }
1.1316 raeburn 10021: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
10022: $env{'course.'.$env{'request.course.id'}.'.domain'},
10023: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 10024: } elsif ($env{'request.course.id'}) {
10025: my $expiretime=600;
10026: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
10027: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
10028: }
10029: my ($deeplinkmenu,$menuref);
10030: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
10031: if ($menucoll) {
10032: if (ref($menuref) eq 'HASH') {
10033: %menu = %{$menuref};
10034: }
10035: if ($menu{'top'} eq 'n') {
10036: $args->{'no_primary_menu'} = 1;
10037: }
10038: if ($menu{'inline'} eq 'n') {
10039: unless (&Apache::lonnet::allowed('opa')) {
10040: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10041: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10042: my $crstype = &course_type();
10043: my $now = time;
10044: my $ccrole;
10045: if ($crstype eq 'Community') {
10046: $ccrole = 'co';
10047: } else {
10048: $ccrole = 'cc';
10049: }
10050: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
10051: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
10052: if ((($start) && ($start<0)) ||
10053: (($end) && ($end<$now)) ||
10054: (($start) && ($now<$start))) {
10055: $args->{'no_inline_menu'} = 1;
10056: }
10057: } else {
10058: $args->{'no_inline_menu'} = 1;
10059: }
10060: }
10061: }
10062: }
1.1316 raeburn 10063: }
1.1359 raeburn 10064:
1.1385 raeburn 10065: my $showncrumbs;
1.338 albertel 10066: if (! exists($args->{'skip_phases'}{'body'}) ) {
10067: if ($args->{'frameset'}) {
10068: my $attr_string = &make_attr_string($args->{'force_register'},
10069: $args->{'add_entries'});
10070: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 10071: } else {
10072: $result .=
10073: &bodytag($title,
10074: $args->{'function'}, $args->{'add_entries'},
10075: $args->{'only_body'}, $args->{'domain'},
10076: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 10077: $args->{'bgcolor'}, $args,
1.1385 raeburn 10078: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
10079: \%menu,\$showncrumbs);
1.831 bisitz 10080: }
1.330 albertel 10081: }
1.338 albertel 10082:
1.315 albertel 10083: if ($args->{'js_ready'}) {
1.713 kaisler 10084: $result = &js_ready($result);
1.315 albertel 10085: }
1.320 albertel 10086: if ($args->{'html_encode'}) {
1.713 kaisler 10087: $result = &html_encode($result);
10088: }
10089:
1.813 bisitz 10090: # Preparation for new and consistent functionlist at top of screen
10091: # if ($args->{'functionlist'}) {
10092: # $result .= &build_functionlist();
10093: #}
10094:
1.964 droeschl 10095: # Don't add anything more if only_body wanted or in const space
10096: return $result if $args->{'only_body'}
10097: || $env{'request.state'} eq 'construct';
1.813 bisitz 10098:
10099: #Breadcrumbs
1.758 kaisler 10100: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 10101: unless ($showncrumbs) {
1.758 kaisler 10102: &Apache::lonhtmlcommon::clear_breadcrumbs();
10103: #if any br links exists, add them to the breadcrumbs
10104: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
10105: foreach my $crumb (@{$args->{'bread_crumbs'}}){
10106: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
10107: }
10108: }
1.1096 raeburn 10109: # if @advtools array contains items add then to the breadcrumbs
10110: if (@advtools > 0) {
10111: &Apache::lonmenu::advtools_crumbs(@advtools);
10112: }
1.1272 raeburn 10113: my $menulink;
10114: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
10115: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 10116: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 10117: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
10118: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
10119: (!$env{'request.role.adv'}))) {
10120: $menulink = 0;
10121: } else {
10122: undef($menulink);
10123: }
1.1385 raeburn 10124: my $linkprotout;
10125: if ($env{'request.deeplink.login'}) {
10126: my $linkprotout = &Apache::lonmenu::linkprot_exit();
10127: if ($linkprotout) {
10128: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
10129: }
10130: }
1.758 kaisler 10131: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
10132: if(exists($args->{'bread_crumbs_component'})){
1.1437 raeburn 10133: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},
10134: '',$menulink,'',
10135: $args->{'bread_crumbs_style'});
1.1237 raeburn 10136: } else {
1.1437 raeburn 10137: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink,'',
10138: $args->{'bread_crumbs_style'});
1.758 kaisler 10139: }
1.1385 raeburn 10140: }
1.320 albertel 10141: }
1.315 albertel 10142: return $result;
1.306 albertel 10143: }
10144:
10145: sub end_page {
1.315 albertel 10146: my ($args) = @_;
10147: $env{'internal.end_page'}++;
1.330 albertel 10148: my $result;
1.335 albertel 10149: if ($args->{'discussion'}) {
10150: my ($target,$parser);
10151: if (ref($args->{'discussion'})) {
10152: ($target,$parser) =($args->{'discussion'}{'target'},
10153: $args->{'discussion'}{'parser'});
10154: }
10155: $result .= &Apache::lonxml::xmlend($target,$parser);
10156: }
1.330 albertel 10157: if ($args->{'frameset'}) {
10158: $result .= '</frameset>';
10159: } else {
1.635 raeburn 10160: $result .= &endbodytag($args);
1.330 albertel 10161: }
1.1080 raeburn 10162: unless ($args->{'notbody'}) {
10163: $result .= "\n</html>";
10164: }
1.330 albertel 10165:
1.315 albertel 10166: if ($args->{'js_ready'}) {
1.317 albertel 10167: $result = &js_ready($result);
1.315 albertel 10168: }
1.335 albertel 10169:
1.320 albertel 10170: if ($args->{'html_encode'}) {
10171: $result = &html_encode($result);
10172: }
1.335 albertel 10173:
1.315 albertel 10174: return $result;
10175: }
10176:
1.1359 raeburn 10177: sub menucoll_in_effect {
10178: my ($menucoll,$deeplinkmenu,%menu);
10179: if ($env{'request.course.id'}) {
10180: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 10181: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 10182: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 10183: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10184: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10185: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
10186: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
10187: my $navmap = Apache::lonnavmaps::navmap->new();
10188: if (ref($navmap)) {
10189: $deeplink = $navmap->get_mapparam(undef,
10190: &Apache::lonnet::declutter($env{'request.noversionuri'}),
10191: '0.deeplink');
1.1370 raeburn 10192: } else {
10193: $check_login_symb = 1;
1.1362 raeburn 10194: }
10195: } else {
1.1370 raeburn 10196: my $symb = &Apache::lonnet::symbread();
10197: if ($symb) {
10198: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
10199: } else {
10200: $check_login_symb = 1;
10201: }
1.1362 raeburn 10202: }
10203: } else {
1.1370 raeburn 10204: $check_login_symb = 1;
10205: }
10206: if ($check_login_symb) {
1.1362 raeburn 10207: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
10208: if ($deeplink_symb =~ /\.(page|sequence)$/) {
10209: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
10210: my $navmap = Apache::lonnavmaps::navmap->new();
10211: if (ref($navmap)) {
10212: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
10213: }
10214: } else {
10215: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
10216: }
10217: }
1.1359 raeburn 10218: if ($deeplink ne '') {
1.1378 raeburn 10219: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 10220: if ($display =~ /^\d+$/) {
10221: $deeplinkmenu = 1;
10222: $menucoll = $display;
10223: }
10224: }
10225: }
10226: if ($menucoll) {
10227: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
10228: }
10229: }
10230: return ($menucoll,$deeplinkmenu,\%menu);
10231: }
10232:
1.1362 raeburn 10233: sub deeplink_login_symb {
10234: my ($cnum,$cdom) = @_;
10235: my $login_symb;
10236: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 10237: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
10238: }
10239: return $login_symb;
10240: }
10241:
10242: sub symb_from_tinyurl {
10243: my ($url,$cnum,$cdom) = @_;
10244: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
10245: my $key = $1;
10246: my ($tinyurl,$login);
10247: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
10248: if (defined($cached)) {
10249: $tinyurl = $result;
10250: } else {
10251: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
10252: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
10253: if ($currtiny{$key} ne '') {
10254: $tinyurl = $currtiny{$key};
10255: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 10256: }
1.1364 raeburn 10257: }
10258: if ($tinyurl ne '') {
10259: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
10260: if (wantarray) {
10261: return ($cnumreq,$symb);
10262: } elsif ($cnumreq eq $cnum) {
10263: return $symb;
1.1362 raeburn 10264: }
10265: }
10266: }
1.1364 raeburn 10267: if (wantarray) {
10268: return ();
10269: } else {
10270: return;
10271: }
1.1362 raeburn 10272: }
10273:
1.1405 raeburn 10274: sub usable_exttools {
10275: my %tooltypes;
10276: if ($env{'request.course.id'}) {
10277: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
10278: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
10279: %tooltypes = (
10280: crs => 1,
10281: dom => 1,
10282: );
10283: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
10284: $tooltypes{'crs'} = 1;
10285: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
10286: $tooltypes{'dom'} = 1;
10287: }
10288: } else {
10289: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10290: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10291: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
10292: if ($crstype eq '') {
10293: $crstype = 'course';
10294: }
10295: if ($crstype eq 'course') {
10296: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
10297: $crstype = 'official';
10298: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
10299: $crstype = 'textbook';
10300: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
10301: $crstype = 'lti';
10302: } else {
10303: $crstype = 'unofficial';
10304: }
10305: }
10306: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
10307: if ($domdefaults{$crstype.'domexttool'}) {
10308: $tooltypes{'dom'} = 1;
10309: }
10310: if ($domdefaults{$crstype.'exttool'}) {
10311: $tooltypes{'crs'} = 1;
10312: }
10313: }
10314: }
10315: return %tooltypes;
10316: }
10317:
1.1034 www 10318: sub wishlist_window {
10319: return(<<'ENDWISHLIST');
1.1046 raeburn 10320: <script type="text/javascript">
1.1034 www 10321: // <![CDATA[
10322: // <!-- BEGIN LON-CAPA Internal
10323: function set_wishlistlink(title, path) {
10324: if (!title) {
10325: title = document.title;
10326: title = title.replace(/^LON-CAPA /,'');
10327: }
1.1175 raeburn 10328: title = encodeURIComponent(title);
1.1203 raeburn 10329: title = title.replace("'","\\\'");
1.1034 www 10330: if (!path) {
10331: path = location.pathname;
10332: }
1.1175 raeburn 10333: path = encodeURIComponent(path);
1.1203 raeburn 10334: path = path.replace("'","\\\'");
1.1034 www 10335: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
10336: 'wishlistNewLink','width=560,height=350,scrollbars=0');
10337: }
10338: // END LON-CAPA Internal -->
10339: // ]]>
10340: </script>
10341: ENDWISHLIST
10342: }
10343:
1.1030 www 10344: sub modal_window {
10345: return(<<'ENDMODAL');
1.1046 raeburn 10346: <script type="text/javascript">
1.1030 www 10347: // <![CDATA[
10348: // <!-- BEGIN LON-CAPA Internal
10349: var modalWindow = {
10350: parent:"body",
10351: windowId:null,
10352: content:null,
10353: width:null,
10354: height:null,
10355: close:function()
10356: {
10357: $(".LCmodal-window").remove();
10358: $(".LCmodal-overlay").remove();
10359: },
10360: open:function()
10361: {
10362: var modal = "";
10363: modal += "<div class=\"LCmodal-overlay\"></div>";
10364: 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;\">";
10365: modal += this.content;
10366: modal += "</div>";
10367:
10368: $(this.parent).append(modal);
10369:
10370: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
10371: $(".LCclose-window").click(function(){modalWindow.close();});
10372: $(".LCmodal-overlay").click(function(){modalWindow.close();});
10373: }
10374: };
1.1140 raeburn 10375: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 10376: {
1.1266 raeburn 10377: source = source.replace(/'/g,"'");
1.1030 www 10378: modalWindow.windowId = "myModal";
10379: modalWindow.width = width;
10380: modalWindow.height = height;
1.1196 raeburn 10381: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 10382: modalWindow.open();
1.1208 raeburn 10383: };
1.1030 www 10384: // END LON-CAPA Internal -->
10385: // ]]>
10386: </script>
10387: ENDMODAL
10388: }
10389:
10390: sub modal_link {
1.1140 raeburn 10391: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 10392: unless ($width) { $width=480; }
10393: unless ($height) { $height=400; }
1.1031 www 10394: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 10395: unless ($transparency) { $transparency='true'; }
10396:
1.1074 raeburn 10397: my $target_attr;
10398: if (defined($target)) {
10399: $target_attr = 'target="'.$target.'"';
10400: }
10401: return <<"ENDLINK";
1.1336 raeburn 10402: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 10403: ENDLINK
1.1030 www 10404: }
10405:
1.1032 www 10406: sub modal_adhoc_script {
1.1365 raeburn 10407: my ($funcname,$width,$height,$content,$possmathjax)=@_;
10408: my $mathjax;
10409: if ($possmathjax) {
10410: $mathjax = <<'ENDJAX';
10411: if (typeof MathJax == 'object') {
10412: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
10413: }
10414: ENDJAX
10415: }
1.1032 www 10416: return (<<ENDADHOC);
1.1046 raeburn 10417: <script type="text/javascript">
1.1032 www 10418: // <![CDATA[
10419: var $funcname = function()
10420: {
10421: modalWindow.windowId = "myModal";
10422: modalWindow.width = $width;
10423: modalWindow.height = $height;
10424: modalWindow.content = '$content';
10425: modalWindow.open();
1.1365 raeburn 10426: $mathjax
1.1032 www 10427: };
10428: // ]]>
10429: </script>
10430: ENDADHOC
10431: }
10432:
1.1041 www 10433: sub modal_adhoc_inner {
1.1365 raeburn 10434: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 10435: my $innerwidth=$width-20;
10436: $content=&js_ready(
1.1140 raeburn 10437: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
10438: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
10439: $content.
1.1041 www 10440: &end_scrollbox().
1.1140 raeburn 10441: &end_page()
1.1041 www 10442: );
1.1365 raeburn 10443: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 10444: }
10445:
10446: sub modal_adhoc_window {
1.1365 raeburn 10447: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
10448: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 10449: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
10450: }
10451:
10452: sub modal_adhoc_launch {
10453: my ($funcname,$width,$height,$content)=@_;
10454: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
10455: <script type="text/javascript">
10456: // <![CDATA[
10457: $funcname();
10458: // ]]>
10459: </script>
10460: ENDLAUNCH
10461: }
10462:
10463: sub modal_adhoc_close {
10464: return (<<ENDCLOSE);
10465: <script type="text/javascript">
10466: // <![CDATA[
10467: modalWindow.close();
10468: // ]]>
10469: </script>
10470: ENDCLOSE
10471: }
10472:
1.1038 www 10473: sub togglebox_script {
10474: return(<<ENDTOGGLE);
10475: <script type="text/javascript">
10476: // <![CDATA[
10477: function LCtoggleDisplay(id,hidetext,showtext) {
10478: link = document.getElementById(id + "link").childNodes[0];
10479: with (document.getElementById(id).style) {
10480: if (display == "none" ) {
10481: display = "inline";
10482: link.nodeValue = hidetext;
10483: } else {
10484: display = "none";
10485: link.nodeValue = showtext;
10486: }
10487: }
10488: }
10489: // ]]>
10490: </script>
10491: ENDTOGGLE
10492: }
10493:
1.1039 www 10494: sub start_togglebox {
10495: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
10496: unless ($heading) { $heading=''; } else { $heading.=' '; }
10497: unless ($showtext) { $showtext=&mt('show'); }
10498: unless ($hidetext) { $hidetext=&mt('hide'); }
10499: unless ($headerbg) { $headerbg='#FFFFFF'; }
10500: return &start_data_table().
10501: &start_data_table_header_row().
10502: '<td bgcolor="'.$headerbg.'">'.$heading.
10503: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
10504: $showtext.'\')">'.$showtext.'</a>]</td>'.
10505: &end_data_table_header_row().
10506: '<tr id="'.$id.'" style="display:none""><td>';
10507: }
10508:
10509: sub end_togglebox {
10510: return '</td></tr>'.&end_data_table();
10511: }
10512:
1.1041 www 10513: sub LCprogressbar_script {
1.1302 raeburn 10514: my ($id,$number_to_do)=@_;
10515: if ($number_to_do) {
10516: return(<<ENDPROGRESS);
1.1041 www 10517: <script type="text/javascript">
10518: // <![CDATA[
1.1045 www 10519: \$('#progressbar$id').progressbar({
1.1041 www 10520: value: 0,
10521: change: function(event, ui) {
10522: var newVal = \$(this).progressbar('option', 'value');
10523: \$('.pblabel', this).text(LCprogressTxt);
10524: }
10525: });
10526: // ]]>
10527: </script>
10528: ENDPROGRESS
1.1302 raeburn 10529: } else {
10530: return(<<ENDPROGRESS);
10531: <script type="text/javascript">
10532: // <![CDATA[
10533: \$('#progressbar$id').progressbar({
10534: value: false,
10535: create: function(event, ui) {
10536: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10537: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10538: }
10539: });
10540: // ]]>
10541: </script>
10542: ENDPROGRESS
10543: }
1.1041 www 10544: }
10545:
10546: sub LCprogressbarUpdate_script {
10547: return(<<ENDPROGRESSUPDATE);
10548: <style type="text/css">
10549: .ui-progressbar { position:relative; }
1.1302 raeburn 10550: .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 10551: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10552: </style>
10553: <script type="text/javascript">
10554: // <![CDATA[
1.1045 www 10555: var LCprogressTxt='---';
10556:
1.1302 raeburn 10557: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10558: LCprogressTxt=progresstext;
1.1302 raeburn 10559: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10560: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10561: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10562: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10563: } else {
10564: \$('#progressbar'+id).progressbar('value',percent);
10565: }
1.1041 www 10566: }
10567: // ]]>
10568: </script>
10569: ENDPROGRESSUPDATE
10570: }
10571:
1.1042 www 10572: my $LClastpercent;
1.1045 www 10573: my $LCidcnt;
10574: my $LCcurrentid;
1.1042 www 10575:
1.1041 www 10576: sub LCprogressbar {
1.1302 raeburn 10577: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10578: $LClastpercent=0;
1.1045 www 10579: $LCidcnt++;
10580: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10581: my ($starting,$content);
10582: if ($number_to_do) {
10583: $starting=&mt('Starting');
10584: $content=(<<ENDPROGBAR);
10585: $preamble
1.1045 www 10586: <div id="progressbar$LCcurrentid">
1.1041 www 10587: <span class="pblabel">$starting</span>
10588: </div>
10589: ENDPROGBAR
1.1302 raeburn 10590: } else {
10591: $starting=&mt('Loading...');
10592: $LClastpercent='false';
10593: $content=(<<ENDPROGBAR);
10594: $preamble
10595: <div id="progressbar$LCcurrentid">
10596: <div class="progress-label">$starting</div>
10597: </div>
10598: ENDPROGBAR
10599: }
10600: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10601: }
10602:
10603: sub LCprogressbarUpdate {
1.1302 raeburn 10604: my ($r,$val,$text,$number_to_do)=@_;
10605: if ($number_to_do) {
10606: unless ($val) {
10607: if ($LClastpercent) {
10608: $val=$LClastpercent;
10609: } else {
10610: $val=0;
10611: }
10612: }
10613: if ($val<0) { $val=0; }
10614: if ($val>100) { $val=0; }
10615: $LClastpercent=$val;
10616: unless ($text) { $text=$val.'%'; }
10617: } else {
10618: $val = 'false';
1.1042 www 10619: }
1.1041 www 10620: $text=&js_ready($text);
1.1044 www 10621: &r_print($r,<<ENDUPDATE);
1.1041 www 10622: <script type="text/javascript">
10623: // <![CDATA[
1.1302 raeburn 10624: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10625: // ]]>
10626: </script>
10627: ENDUPDATE
1.1035 www 10628: }
10629:
1.1042 www 10630: sub LCprogressbarClose {
10631: my ($r)=@_;
10632: $LClastpercent=0;
1.1044 www 10633: &r_print($r,<<ENDCLOSE);
1.1042 www 10634: <script type="text/javascript">
10635: // <![CDATA[
1.1045 www 10636: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10637: // ]]>
10638: </script>
10639: ENDCLOSE
1.1044 www 10640: }
10641:
10642: sub r_print {
10643: my ($r,$to_print)=@_;
10644: if ($r) {
10645: $r->print($to_print);
10646: $r->rflush();
10647: } else {
10648: print($to_print);
10649: }
1.1042 www 10650: }
10651:
1.320 albertel 10652: sub html_encode {
10653: my ($result) = @_;
10654:
1.322 albertel 10655: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10656:
10657: return $result;
10658: }
1.1044 www 10659:
1.317 albertel 10660: sub js_ready {
10661: my ($result) = @_;
10662:
1.323 albertel 10663: $result =~ s/[\n\r]/ /xmsg;
10664: $result =~ s/\\/\\\\/xmsg;
10665: $result =~ s/'/\\'/xmsg;
1.372 albertel 10666: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10667:
10668: return $result;
10669: }
10670:
1.315 albertel 10671: sub validate_page {
10672: if ( exists($env{'internal.start_page'})
1.316 albertel 10673: && $env{'internal.start_page'} > 1) {
10674: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10675: $env{'internal.start_page'}.' '.
1.316 albertel 10676: $ENV{'request.filename'});
1.315 albertel 10677: }
10678: if ( exists($env{'internal.end_page'})
1.316 albertel 10679: && $env{'internal.end_page'} > 1) {
10680: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10681: $env{'internal.end_page'}.' '.
1.316 albertel 10682: $env{'request.filename'});
1.315 albertel 10683: }
10684: if ( exists($env{'internal.start_page'})
10685: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10686: &Apache::lonnet::logthis('start_page called without end_page '.
10687: $env{'request.filename'});
1.315 albertel 10688: }
10689: if ( ! exists($env{'internal.start_page'})
10690: && exists($env{'internal.end_page'})) {
1.316 albertel 10691: &Apache::lonnet::logthis('end_page called without start_page'.
10692: $env{'request.filename'});
1.315 albertel 10693: }
1.306 albertel 10694: }
1.315 albertel 10695:
1.996 www 10696:
10697: sub start_scrollbox {
1.1140 raeburn 10698: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10699: unless ($outerwidth) { $outerwidth='520px'; }
10700: unless ($width) { $width='500px'; }
10701: unless ($height) { $height='200px'; }
1.1075 raeburn 10702: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10703: if ($id ne '') {
1.1140 raeburn 10704: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10705: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10706: }
1.1075 raeburn 10707: if ($bgcolor ne '') {
10708: $tdcol = "background-color: $bgcolor;";
10709: }
1.1137 raeburn 10710: my $nicescroll_js;
10711: if ($env{'browser.mobile'}) {
1.1140 raeburn 10712: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10713: }
10714: return <<"END";
10715: $nicescroll_js
10716:
10717: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10718: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10719: END
10720: }
10721:
10722: sub end_scrollbox {
10723: return '</div></td></tr></table>';
10724: }
10725:
10726: sub nicescroll_javascript {
10727: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10728: my %options;
10729: if (ref($cursor) eq 'HASH') {
10730: %options = %{$cursor};
10731: }
10732: unless ($options{'railalign'} =~ /^left|right$/) {
10733: $options{'railalign'} = 'left';
10734: }
10735: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10736: my $function = &get_users_function();
10737: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10738: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10739: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10740: }
1.1140 raeburn 10741: }
10742: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10743: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10744: $options{'cursoropacity'}='1.0';
10745: }
1.1140 raeburn 10746: } else {
10747: $options{'cursoropacity'}='1.0';
10748: }
10749: if ($options{'cursorfixedheight'} eq 'none') {
10750: delete($options{'cursorfixedheight'});
10751: } else {
10752: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10753: }
10754: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10755: delete($options{'railoffset'});
10756: }
10757: my @niceoptions;
10758: while (my($key,$value) = each(%options)) {
10759: if ($value =~ /^\{.+\}$/) {
10760: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10761: } else {
1.1140 raeburn 10762: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10763: }
1.1140 raeburn 10764: }
10765: my $nicescroll_js = '
1.1137 raeburn 10766: $(document).ready(
1.1140 raeburn 10767: function() {
10768: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10769: }
1.1137 raeburn 10770: );
10771: ';
1.1140 raeburn 10772: if ($framecheck) {
10773: $nicescroll_js .= '
10774: function expand_div(caller) {
10775: if (top === self) {
10776: document.getElementById("'.$id.'").style.width = "auto";
10777: document.getElementById("'.$id.'").style.height = "auto";
10778: } else {
10779: try {
10780: if (parent.frames) {
10781: if (parent.frames.length > 1) {
10782: var framesrc = parent.frames[1].location.href;
10783: var currsrc = framesrc.replace(/\#.*$/,"");
10784: if ((caller == "search") || (currsrc == "'.$location.'")) {
10785: document.getElementById("'.$id.'").style.width = "auto";
10786: document.getElementById("'.$id.'").style.height = "auto";
10787: }
10788: }
10789: }
10790: } catch (e) {
10791: return;
10792: }
1.1137 raeburn 10793: }
1.1140 raeburn 10794: return;
1.996 www 10795: }
1.1140 raeburn 10796: ';
10797: }
10798: if ($needjsready) {
10799: $nicescroll_js = '
10800: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10801: } else {
10802: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10803: }
10804: return $nicescroll_js;
1.996 www 10805: }
10806:
1.318 albertel 10807: sub simple_error_page {
1.1150 bisitz 10808: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10809: my %displayargs;
1.1151 raeburn 10810: if (ref($args) eq 'HASH') {
10811: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10812: if ($args->{'only_body'}) {
10813: $displayargs{'only_body'} = 1;
10814: }
10815: if ($args->{'no_nav_bar'}) {
10816: $displayargs{'no_nav_bar'} = 1;
10817: }
1.1151 raeburn 10818: } else {
10819: $msg = &mt($msg);
10820: }
1.1150 bisitz 10821:
1.318 albertel 10822: my $page =
1.1304 raeburn 10823: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10824: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10825: &Apache::loncommon::end_page();
10826: if (ref($r)) {
10827: $r->print($page);
1.327 albertel 10828: return;
1.318 albertel 10829: }
10830: return $page;
10831: }
1.347 albertel 10832:
10833: {
1.610 albertel 10834: my @row_count;
1.961 onken 10835:
10836: sub start_data_table_count {
10837: unshift(@row_count, 0);
10838: return;
10839: }
10840:
10841: sub end_data_table_count {
10842: shift(@row_count);
10843: return;
10844: }
10845:
1.347 albertel 10846: sub start_data_table {
1.1018 raeburn 10847: my ($add_class,$id) = @_;
1.422 albertel 10848: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10849: my $table_id;
10850: if (defined($id)) {
10851: $table_id = ' id="'.$id.'"';
10852: }
1.961 onken 10853: &start_data_table_count();
1.1018 raeburn 10854: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10855: }
10856:
10857: sub end_data_table {
1.961 onken 10858: &end_data_table_count();
1.389 albertel 10859: return '</table>'."\n";;
1.347 albertel 10860: }
10861:
10862: sub start_data_table_row {
1.974 wenzelju 10863: my ($add_class, $id) = @_;
1.610 albertel 10864: $row_count[0]++;
10865: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10866: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10867: $id = (' id="'.$id.'"') unless ($id eq '');
10868: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10869: }
1.471 banghart 10870:
10871: sub continue_data_table_row {
1.974 wenzelju 10872: my ($add_class, $id) = @_;
1.610 albertel 10873: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10874: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10875: $id = (' id="'.$id.'"') unless ($id eq '');
10876: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10877: }
1.347 albertel 10878:
10879: sub end_data_table_row {
1.389 albertel 10880: return '</tr>'."\n";;
1.347 albertel 10881: }
1.367 www 10882:
1.421 albertel 10883: sub start_data_table_empty_row {
1.707 bisitz 10884: # $row_count[0]++;
1.421 albertel 10885: return '<tr class="LC_empty_row" >'."\n";;
10886: }
10887:
10888: sub end_data_table_empty_row {
10889: return '</tr>'."\n";;
10890: }
10891:
1.367 www 10892: sub start_data_table_header_row {
1.389 albertel 10893: return '<tr class="LC_header_row">'."\n";;
1.367 www 10894: }
10895:
10896: sub end_data_table_header_row {
1.389 albertel 10897: return '</tr>'."\n";;
1.367 www 10898: }
1.890 droeschl 10899:
10900: sub data_table_caption {
10901: my $caption = shift;
10902: return "<caption class=\"LC_caption\">$caption</caption>";
10903: }
1.347 albertel 10904: }
10905:
1.548 albertel 10906: =pod
10907:
10908: =item * &inhibit_menu_check($arg)
10909:
10910: Checks for a inhibitmenu state and generates output to preserve it
10911:
10912: Inputs: $arg - can be any of
10913: - undef - in which case the return value is a string
10914: to add into arguments list of a uri
10915: - 'input' - in which case the return value is a HTML
10916: <form> <input> field of type hidden to
10917: preserve the value
10918: - a url - in which case the return value is the url with
10919: the neccesary cgi args added to preserve the
10920: inhibitmenu state
10921: - a ref to a url - no return value, but the string is
10922: updated to include the neccessary cgi
10923: args to preserve the inhibitmenu state
10924:
10925: =cut
10926:
10927: sub inhibit_menu_check {
10928: my ($arg) = @_;
10929: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10930: if ($arg eq 'input') {
10931: if ($env{'form.inhibitmenu'}) {
10932: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10933: } else {
10934: return
10935: }
10936: }
10937: if ($env{'form.inhibitmenu'}) {
10938: if (ref($arg)) {
10939: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10940: } elsif ($arg eq '') {
10941: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10942: } else {
10943: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10944: }
10945: }
10946: if (!ref($arg)) {
10947: return $arg;
10948: }
10949: }
10950:
1.251 albertel 10951: ###############################################
1.182 matthew 10952:
10953: =pod
10954:
1.549 albertel 10955: =back
10956:
10957: =head1 User Information Routines
10958:
10959: =over 4
10960:
1.405 albertel 10961: =item * &get_users_function()
1.182 matthew 10962:
10963: Used by &bodytag to determine the current users primary role.
10964: Returns either 'student','coordinator','admin', or 'author'.
10965:
10966: =cut
10967:
10968: ###############################################
10969: sub get_users_function {
1.815 tempelho 10970: my $function = 'norole';
1.818 tempelho 10971: if ($env{'request.role'}=~/^(st)/) {
10972: $function='student';
10973: }
1.907 raeburn 10974: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10975: $function='coordinator';
10976: }
1.258 albertel 10977: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10978: $function='admin';
10979: }
1.826 bisitz 10980: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10981: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10982: $function='author';
10983: }
10984: return $function;
1.54 www 10985: }
1.99 www 10986:
10987: ###############################################
10988:
1.233 raeburn 10989: =pod
10990:
1.821 raeburn 10991: =item * &show_course()
10992:
10993: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10994: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10995:
10996: Inputs:
10997: None
10998:
10999: Outputs:
11000: Scalar: 1 if 'Course' to be used, 0 otherwise.
11001:
11002: =cut
11003:
11004: ###############################################
11005: sub show_course {
1.1408 raeburn 11006: my ($udom,$uname) = @_;
11007: if (($udom ne '') && ($uname ne '')) {
11008: if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
1.1410 raeburn 11009: if (&Apache::lonnet::is_advanced_user($udom,$uname)) {
1.1408 raeburn 11010: return 0;
11011: } else {
11012: return 1;
11013: }
11014: }
11015: }
1.821 raeburn 11016: my $course = !$env{'user.adv'};
11017: if (!$env{'user.adv'}) {
11018: foreach my $env (keys(%env)) {
11019: next if ($env !~ m/^user\.priv\./);
11020: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
11021: $course = 0;
11022: last;
11023: }
11024: }
11025: }
11026: return $course;
11027: }
11028:
11029: ###############################################
11030:
11031: =pod
11032:
1.542 raeburn 11033: =item * &check_user_status()
1.274 raeburn 11034:
11035: Determines current status of supplied role for a
11036: specific user. Roles can be active, previous or future.
11037:
11038: Inputs:
11039: user's domain, user's username, course's domain,
1.375 raeburn 11040: course's number, optional section ID.
1.274 raeburn 11041:
11042: Outputs:
11043: role status: active, previous or future.
11044:
11045: =cut
11046:
11047: sub check_user_status {
1.412 raeburn 11048: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 11049: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 11050: my @uroles = keys(%userinfo);
1.274 raeburn 11051: my $srchstr;
11052: my $active_chk = 'none';
1.412 raeburn 11053: my $now = time;
1.274 raeburn 11054: if (@uroles > 0) {
1.908 raeburn 11055: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 11056: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
11057: } else {
1.412 raeburn 11058: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
11059: }
11060: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 11061: my $role_end = 0;
11062: my $role_start = 0;
11063: $active_chk = 'active';
1.412 raeburn 11064: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
11065: $role_end = $1;
11066: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
11067: $role_start = $1;
1.274 raeburn 11068: }
11069: }
11070: if ($role_start > 0) {
1.412 raeburn 11071: if ($now < $role_start) {
1.274 raeburn 11072: $active_chk = 'future';
11073: }
11074: }
11075: if ($role_end > 0) {
1.412 raeburn 11076: if ($now > $role_end) {
1.274 raeburn 11077: $active_chk = 'previous';
11078: }
11079: }
11080: }
11081: }
11082: return $active_chk;
11083: }
11084:
11085: ###############################################
11086:
11087: =pod
11088:
1.405 albertel 11089: =item * &get_sections()
1.233 raeburn 11090:
11091: Determines all the sections for a course including
11092: sections with students and sections containing other roles.
1.419 raeburn 11093: Incoming parameters:
11094:
11095: 1. domain
11096: 2. course number
11097: 3. reference to array containing roles for which sections should
11098: be gathered (optional).
11099: 4. reference to array containing status types for which sections
11100: should be gathered (optional).
11101:
11102: If the third argument is undefined, sections are gathered for any role.
11103: If the fourth argument is undefined, sections are gathered for any status.
11104: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 11105:
1.374 raeburn 11106: Returns section hash (keys are section IDs, values are
11107: number of users in each section), subject to the
1.419 raeburn 11108: optional roles filter, optional status filter
1.233 raeburn 11109:
11110: =cut
11111:
11112: ###############################################
11113: sub get_sections {
1.419 raeburn 11114: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 11115: if (!defined($cdom) || !defined($cnum)) {
11116: my $cid = $env{'request.course.id'};
11117:
11118: return if (!defined($cid));
11119:
11120: $cdom = $env{'course.'.$cid.'.domain'};
11121: $cnum = $env{'course.'.$cid.'.num'};
11122: }
11123:
11124: my %sectioncount;
1.419 raeburn 11125: my $now = time;
1.240 albertel 11126:
1.1118 raeburn 11127: my $check_students = 1;
11128: my $only_students = 0;
11129: if (ref($possible_roles) eq 'ARRAY') {
11130: if (grep(/^st$/,@{$possible_roles})) {
11131: if (@{$possible_roles} == 1) {
11132: $only_students = 1;
11133: }
11134: } else {
11135: $check_students = 0;
11136: }
11137: }
11138:
11139: if ($check_students) {
1.276 albertel 11140: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 11141: my $sec_index = &Apache::loncoursedata::CL_SECTION();
11142: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 11143: my $start_index = &Apache::loncoursedata::CL_START();
11144: my $end_index = &Apache::loncoursedata::CL_END();
11145: my $status;
1.366 albertel 11146: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 11147: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
11148: $data->[$status_index],
11149: $data->[$start_index],
11150: $data->[$end_index]);
11151: if ($stu_status eq 'Active') {
11152: $status = 'active';
11153: } elsif ($end < $now) {
11154: $status = 'previous';
11155: } elsif ($start > $now) {
11156: $status = 'future';
11157: }
11158: if ($section ne '-1' && $section !~ /^\s*$/) {
11159: if ((!defined($possible_status)) || (($status ne '') &&
11160: (grep/^\Q$status\E$/,@{$possible_status}))) {
11161: $sectioncount{$section}++;
11162: }
1.240 albertel 11163: }
11164: }
11165: }
1.1118 raeburn 11166: if ($only_students) {
11167: return %sectioncount;
11168: }
1.240 albertel 11169: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11170: foreach my $user (sort(keys(%courseroles))) {
11171: if ($user !~ /^(\w{2})/) { next; }
11172: my ($role) = ($user =~ /^(\w{2})/);
11173: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 11174: my ($section,$status);
1.240 albertel 11175: if ($role eq 'cr' &&
11176: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
11177: $section=$1;
11178: }
11179: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
11180: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 11181: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
11182: if ($end == -1 && $start == -1) {
11183: next; #deleted role
11184: }
11185: if (!defined($possible_status)) {
11186: $sectioncount{$section}++;
11187: } else {
11188: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
11189: $status = 'active';
11190: } elsif ($end < $now) {
11191: $status = 'future';
11192: } elsif ($start > $now) {
11193: $status = 'previous';
11194: }
11195: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
11196: $sectioncount{$section}++;
11197: }
11198: }
1.233 raeburn 11199: }
1.366 albertel 11200: return %sectioncount;
1.233 raeburn 11201: }
11202:
1.274 raeburn 11203: ###############################################
1.294 raeburn 11204:
11205: =pod
1.405 albertel 11206:
11207: =item * &get_course_users()
11208:
1.275 raeburn 11209: Retrieves usernames:domains for users in the specified course
11210: with specific role(s), and access status.
11211:
11212: Incoming parameters:
1.277 albertel 11213: 1. course domain
11214: 2. course number
11215: 3. access status: users must have - either active,
1.275 raeburn 11216: previous, future, or all.
1.277 albertel 11217: 4. reference to array of permissible roles
1.288 raeburn 11218: 5. reference to array of section restrictions (optional)
11219: 6. reference to results object (hash of hashes).
11220: 7. reference to optional userdata hash
1.609 raeburn 11221: 8. reference to optional statushash
1.630 raeburn 11222: 9. flag if privileged users (except those set to unhide in
11223: course settings) should be excluded
1.609 raeburn 11224: Keys of top level results hash are roles.
1.275 raeburn 11225: Keys of inner hashes are username:domain, with
11226: values set to access type.
1.288 raeburn 11227: Optional userdata hash returns an array with arguments in the
11228: same order as loncoursedata::get_classlist() for student data.
11229:
1.609 raeburn 11230: Optional statushash returns
11231:
1.288 raeburn 11232: Entries for end, start, section and status are blank because
11233: of the possibility of multiple values for non-student roles.
11234:
1.275 raeburn 11235: =cut
1.405 albertel 11236:
1.275 raeburn 11237: ###############################################
1.405 albertel 11238:
1.275 raeburn 11239: sub get_course_users {
1.630 raeburn 11240: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 11241: my %idx = ();
1.419 raeburn 11242: my %seclists;
1.288 raeburn 11243:
11244: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
11245: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
11246: $idx{end} = &Apache::loncoursedata::CL_END();
11247: $idx{start} = &Apache::loncoursedata::CL_START();
11248: $idx{id} = &Apache::loncoursedata::CL_ID();
11249: $idx{section} = &Apache::loncoursedata::CL_SECTION();
11250: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
11251: $idx{status} = &Apache::loncoursedata::CL_STATUS();
11252:
1.290 albertel 11253: if (grep(/^st$/,@{$roles})) {
1.276 albertel 11254: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 11255: my $now = time;
1.277 albertel 11256: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 11257: my $match = 0;
1.412 raeburn 11258: my $secmatch = 0;
1.419 raeburn 11259: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 11260: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 11261: if ($section eq '') {
11262: $section = 'none';
11263: }
1.291 albertel 11264: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11265: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11266: $secmatch = 1;
11267: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 11268: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11269: $secmatch = 1;
11270: }
11271: } else {
1.419 raeburn 11272: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 11273: $secmatch = 1;
11274: }
1.290 albertel 11275: }
1.412 raeburn 11276: if (!$secmatch) {
11277: next;
11278: }
1.419 raeburn 11279: }
1.275 raeburn 11280: if (defined($$types{'active'})) {
1.288 raeburn 11281: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 11282: push(@{$$users{st}{$student}},'active');
1.288 raeburn 11283: $match = 1;
1.275 raeburn 11284: }
11285: }
11286: if (defined($$types{'previous'})) {
1.609 raeburn 11287: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 11288: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 11289: $match = 1;
1.275 raeburn 11290: }
11291: }
11292: if (defined($$types{'future'})) {
1.609 raeburn 11293: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 11294: push(@{$$users{st}{$student}},'future');
1.288 raeburn 11295: $match = 1;
1.275 raeburn 11296: }
11297: }
1.609 raeburn 11298: if ($match) {
11299: push(@{$seclists{$student}},$section);
11300: if (ref($userdata) eq 'HASH') {
11301: $$userdata{$student} = $$classlist{$student};
11302: }
11303: if (ref($statushash) eq 'HASH') {
11304: $statushash->{$student}{'st'}{$section} = $status;
11305: }
1.288 raeburn 11306: }
1.275 raeburn 11307: }
11308: }
1.412 raeburn 11309: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 11310: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11311: my $now = time;
1.609 raeburn 11312: my %displaystatus = ( previous => 'Expired',
11313: active => 'Active',
11314: future => 'Future',
11315: );
1.1121 raeburn 11316: my (%nothide,@possdoms);
1.630 raeburn 11317: if ($hidepriv) {
11318: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
11319: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
11320: if ($user !~ /:/) {
11321: $nothide{join(':',split(/[\@]/,$user))}=1;
11322: } else {
11323: $nothide{$user} = 1;
11324: }
11325: }
1.1121 raeburn 11326: my @possdoms = ($cdom);
11327: if ($coursehash{'checkforpriv'}) {
11328: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
11329: }
1.630 raeburn 11330: }
1.439 raeburn 11331: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 11332: my $match = 0;
1.412 raeburn 11333: my $secmatch = 0;
1.439 raeburn 11334: my $status;
1.412 raeburn 11335: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 11336: $user =~ s/:$//;
1.439 raeburn 11337: my ($end,$start) = split(/:/,$coursepersonnel{$person});
11338: if ($end == -1 || $start == -1) {
11339: next;
11340: }
11341: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
11342: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 11343: my ($uname,$udom) = split(/:/,$user);
11344: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11345: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11346: $secmatch = 1;
11347: } elsif ($usec eq '') {
1.420 albertel 11348: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11349: $secmatch = 1;
11350: }
11351: } else {
11352: if (grep(/^\Q$usec\E$/,@{$sections})) {
11353: $secmatch = 1;
11354: }
11355: }
11356: if (!$secmatch) {
11357: next;
11358: }
1.288 raeburn 11359: }
1.419 raeburn 11360: if ($usec eq '') {
11361: $usec = 'none';
11362: }
1.275 raeburn 11363: if ($uname ne '' && $udom ne '') {
1.630 raeburn 11364: if ($hidepriv) {
1.1121 raeburn 11365: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 11366: (!$nothide{$uname.':'.$udom})) {
11367: next;
11368: }
11369: }
1.503 raeburn 11370: if ($end > 0 && $end < $now) {
1.439 raeburn 11371: $status = 'previous';
11372: } elsif ($start > $now) {
11373: $status = 'future';
11374: } else {
11375: $status = 'active';
11376: }
1.277 albertel 11377: foreach my $type (keys(%{$types})) {
1.275 raeburn 11378: if ($status eq $type) {
1.420 albertel 11379: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 11380: push(@{$$users{$role}{$user}},$type);
11381: }
1.288 raeburn 11382: $match = 1;
11383: }
11384: }
1.419 raeburn 11385: if (($match) && (ref($userdata) eq 'HASH')) {
11386: if (!exists($$userdata{$uname.':'.$udom})) {
11387: &get_user_info($udom,$uname,\%idx,$userdata);
11388: }
1.420 albertel 11389: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 11390: push(@{$seclists{$uname.':'.$udom}},$usec);
11391: }
1.609 raeburn 11392: if (ref($statushash) eq 'HASH') {
11393: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
11394: }
1.275 raeburn 11395: }
11396: }
11397: }
11398: }
1.290 albertel 11399: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 11400: if ((defined($cdom)) && (defined($cnum))) {
11401: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
11402: if ( defined($csettings{'internal.courseowner'}) ) {
11403: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 11404: next if ($owner eq '');
11405: my ($ownername,$ownerdom);
11406: if ($owner =~ /^([^:]+):([^:]+)$/) {
11407: $ownername = $1;
11408: $ownerdom = $2;
11409: } else {
11410: $ownername = $owner;
11411: $ownerdom = $cdom;
11412: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 11413: }
11414: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 11415: if (defined($userdata) &&
1.609 raeburn 11416: !exists($$userdata{$owner})) {
11417: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
11418: if (!grep(/^none$/,@{$seclists{$owner}})) {
11419: push(@{$seclists{$owner}},'none');
11420: }
11421: if (ref($statushash) eq 'HASH') {
11422: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 11423: }
1.290 albertel 11424: }
1.279 raeburn 11425: }
11426: }
11427: }
1.419 raeburn 11428: foreach my $user (keys(%seclists)) {
11429: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
11430: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
11431: }
1.275 raeburn 11432: }
11433: return;
11434: }
11435:
1.288 raeburn 11436: sub get_user_info {
11437: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 11438: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
11439: &plainname($uname,$udom,'lastname');
1.291 albertel 11440: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 11441: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 11442: my %idhash = &Apache::lonnet::idrget($udom,($uname));
11443: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 11444: return;
11445: }
1.275 raeburn 11446:
1.472 raeburn 11447: ###############################################
11448:
11449: =pod
11450:
11451: =item * &get_user_quota()
11452:
1.1134 raeburn 11453: Retrieves quota assigned for storage of user files.
11454: Default is to report quota for portfolio files.
1.472 raeburn 11455:
11456: Incoming parameters:
11457: 1. user's username
11458: 2. user's domain
1.1134 raeburn 11459: 3. quota name - portfolio, author, or course
1.1136 raeburn 11460: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 11461: 4. crstype - official, unofficial, textbook, placement or community,
11462: if quota name is course
1.472 raeburn 11463:
11464: Returns:
1.1163 raeburn 11465: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 11466: 2. (Optional) Type of setting: custom or default
11467: (individually assigned or default for user's
11468: institutional status).
11469: 3. (Optional) - User's institutional status (e.g., faculty, staff
11470: or student - types as defined in localenroll::inst_usertypes
11471: for user's domain, which determines default quota for user.
11472: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 11473:
11474: If a value has been stored in the user's environment,
1.536 raeburn 11475: it will return that, otherwise it returns the maximal default
1.1134 raeburn 11476: defined for the user's institutional status(es) in the domain.
1.472 raeburn 11477:
11478: =cut
11479:
11480: ###############################################
11481:
11482:
11483: sub get_user_quota {
1.1136 raeburn 11484: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 11485: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 11486: if (!defined($udom)) {
11487: $udom = $env{'user.domain'};
11488: }
11489: if (!defined($uname)) {
11490: $uname = $env{'user.name'};
11491: }
11492: if (($udom eq '' || $uname eq '') ||
11493: ($udom eq 'public') && ($uname eq 'public')) {
11494: $quota = 0;
1.536 raeburn 11495: $quotatype = 'default';
11496: $defquota = 0;
1.472 raeburn 11497: } else {
1.536 raeburn 11498: my $inststatus;
1.1134 raeburn 11499: if ($quotaname eq 'course') {
11500: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
11501: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
11502: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
11503: } else {
11504: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
11505: $quota = $cenv{'internal.uploadquota'};
11506: }
1.536 raeburn 11507: } else {
1.1134 raeburn 11508: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
11509: if ($quotaname eq 'author') {
11510: $quota = $env{'environment.authorquota'};
11511: } else {
11512: $quota = $env{'environment.portfolioquota'};
11513: }
11514: $inststatus = $env{'environment.inststatus'};
11515: } else {
11516: my %userenv =
11517: &Apache::lonnet::get('environment',['portfolioquota',
11518: 'authorquota','inststatus'],$udom,$uname);
11519: my ($tmp) = keys(%userenv);
11520: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11521: if ($quotaname eq 'author') {
11522: $quota = $userenv{'authorquota'};
11523: } else {
11524: $quota = $userenv{'portfolioquota'};
11525: }
11526: $inststatus = $userenv{'inststatus'};
11527: } else {
11528: undef(%userenv);
11529: }
11530: }
11531: }
11532: if ($quota eq '' || wantarray) {
11533: if ($quotaname eq 'course') {
11534: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11535: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11536: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11537: ($crstype eq 'placement')) {
1.1136 raeburn 11538: $defquota = $domdefs{$crstype.'quota'};
11539: }
11540: if ($defquota eq '') {
11541: $defquota = 500;
11542: }
1.1134 raeburn 11543: } else {
11544: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11545: }
11546: if ($quota eq '') {
11547: $quota = $defquota;
11548: $quotatype = 'default';
11549: } else {
11550: $quotatype = 'custom';
11551: }
1.472 raeburn 11552: }
11553: }
1.536 raeburn 11554: if (wantarray) {
11555: return ($quota,$quotatype,$settingstatus,$defquota);
11556: } else {
11557: return $quota;
11558: }
1.472 raeburn 11559: }
11560:
11561: ###############################################
11562:
11563: =pod
11564:
11565: =item * &default_quota()
11566:
1.536 raeburn 11567: Retrieves default quota assigned for storage of user portfolio files,
11568: given an (optional) user's institutional status.
1.472 raeburn 11569:
11570: Incoming parameters:
1.1142 raeburn 11571:
1.472 raeburn 11572: 1. domain
1.536 raeburn 11573: 2. (Optional) institutional status(es). This is a : separated list of
11574: status types (e.g., faculty, staff, student etc.)
11575: which apply to the user for whom the default is being retrieved.
11576: If the institutional status string in undefined, the domain
1.1134 raeburn 11577: default quota will be returned.
11578: 3. quota name - portfolio, author, or course
11579: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11580:
11581: Returns:
1.1142 raeburn 11582:
1.1163 raeburn 11583: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11584: 2. (Optional) institutional type which determined the value of the
11585: default quota.
1.472 raeburn 11586:
11587: If a value has been stored in the domain's configuration db,
11588: it will return that, otherwise it returns 20 (for backwards
11589: compatibility with domains which have not set up a configuration
1.1163 raeburn 11590: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11591:
1.536 raeburn 11592: If the user's status includes multiple types (e.g., staff and student),
11593: the largest default quota which applies to the user determines the
11594: default quota returned.
11595:
1.472 raeburn 11596: =cut
11597:
11598: ###############################################
11599:
11600:
11601: sub default_quota {
1.1134 raeburn 11602: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11603: my ($defquota,$settingstatus);
11604: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11605: ['quotas'],$udom);
1.1134 raeburn 11606: my $key = 'defaultquota';
11607: if ($quotaname eq 'author') {
11608: $key = 'authorquota';
11609: }
1.622 raeburn 11610: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11611: if ($inststatus ne '') {
1.765 raeburn 11612: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11613: foreach my $item (@statuses) {
1.1134 raeburn 11614: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11615: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11616: if ($defquota eq '') {
1.1134 raeburn 11617: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11618: $settingstatus = $item;
1.1134 raeburn 11619: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11620: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11621: $settingstatus = $item;
11622: }
11623: }
1.1134 raeburn 11624: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11625: if ($quotahash{'quotas'}{$item} ne '') {
11626: if ($defquota eq '') {
11627: $defquota = $quotahash{'quotas'}{$item};
11628: $settingstatus = $item;
11629: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11630: $defquota = $quotahash{'quotas'}{$item};
11631: $settingstatus = $item;
11632: }
1.536 raeburn 11633: }
11634: }
11635: }
11636: }
11637: if ($defquota eq '') {
1.1134 raeburn 11638: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11639: $defquota = $quotahash{'quotas'}{$key}{'default'};
11640: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11641: $defquota = $quotahash{'quotas'}{'default'};
11642: }
1.536 raeburn 11643: $settingstatus = 'default';
1.1139 raeburn 11644: if ($defquota eq '') {
11645: if ($quotaname eq 'author') {
11646: $defquota = 500;
11647: }
11648: }
1.536 raeburn 11649: }
11650: } else {
11651: $settingstatus = 'default';
1.1134 raeburn 11652: if ($quotaname eq 'author') {
11653: $defquota = 500;
11654: } else {
11655: $defquota = 20;
11656: }
1.536 raeburn 11657: }
11658: if (wantarray) {
11659: return ($defquota,$settingstatus);
1.472 raeburn 11660: } else {
1.536 raeburn 11661: return $defquota;
1.472 raeburn 11662: }
11663: }
11664:
1.1135 raeburn 11665: ###############################################
11666:
11667: =pod
11668:
1.1136 raeburn 11669: =item * &excess_filesize_warning()
1.1135 raeburn 11670:
11671: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11672: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11673: space to be exceeded.
1.1136 raeburn 11674:
11675: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11676: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11677:
1.1165 raeburn 11678: Inputs: 7
1.1136 raeburn 11679: 1. username or coursenum
1.1135 raeburn 11680: 2. domain
1.1136 raeburn 11681: 3. context ('author' or 'course')
1.1135 raeburn 11682: 4. filename of file for which action is being requested
11683: 5. filesize (kB) of file
11684: 6. action being taken: copy or upload.
1.1237 raeburn 11685: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11686:
11687: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11688: otherwise return null.
11689:
11690: =back
1.1135 raeburn 11691:
11692: =cut
11693:
1.1136 raeburn 11694: sub excess_filesize_warning {
1.1165 raeburn 11695: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11696: my $current_disk_usage = 0;
1.1165 raeburn 11697: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11698: if ($context eq 'author') {
11699: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11700: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11701: } else {
11702: foreach my $subdir ('docs','supplemental') {
11703: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11704: }
11705: }
1.1135 raeburn 11706: $disk_quota = int($disk_quota * 1000);
11707: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11708: return '<p class="LC_warning">'.
1.1135 raeburn 11709: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11710: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11711: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11712: $disk_quota,$current_disk_usage).
11713: '</p>';
11714: }
11715: return;
11716: }
11717:
11718: ###############################################
11719:
11720:
1.1136 raeburn 11721:
11722:
1.384 raeburn 11723: sub get_secgrprole_info {
11724: my ($cdom,$cnum,$needroles,$type) = @_;
11725: my %sections_count = &get_sections($cdom,$cnum);
11726: my @sections = (sort {$a <=> $b} keys(%sections_count));
11727: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11728: my @groups = sort(keys(%curr_groups));
11729: my $allroles = [];
11730: my $rolehash;
11731: my $accesshash = {
11732: active => 'Currently has access',
11733: future => 'Will have future access',
11734: previous => 'Previously had access',
11735: };
11736: if ($needroles) {
11737: $rolehash = {'all' => 'all'};
1.385 albertel 11738: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11739: if (&Apache::lonnet::error(%user_roles)) {
11740: undef(%user_roles);
11741: }
11742: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11743: my ($role)=split(/\:/,$item,2);
11744: if ($role eq 'cr') { next; }
11745: if ($role =~ /^cr/) {
11746: $$rolehash{$role} = (split('/',$role))[3];
11747: } else {
11748: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11749: }
11750: }
11751: foreach my $key (sort(keys(%{$rolehash}))) {
11752: push(@{$allroles},$key);
11753: }
11754: push (@{$allroles},'st');
11755: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11756: }
11757: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11758: }
11759:
1.555 raeburn 11760: sub user_picker {
1.1279 raeburn 11761: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11762: my $currdom = $dom;
1.1253 raeburn 11763: my @alldoms = &Apache::lonnet::all_domains();
11764: if (@alldoms == 1) {
11765: my %domsrch = &Apache::lonnet::get_dom('configuration',
11766: ['directorysrch'],$alldoms[0]);
11767: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11768: my $showdom = $domdesc;
11769: if ($showdom eq '') {
11770: $showdom = $dom;
11771: }
11772: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11773: if ((!$domsrch{'directorysrch'}{'available'}) &&
11774: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11775: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11776: }
11777: }
11778: }
1.555 raeburn 11779: my %curr_selected = (
11780: srchin => 'dom',
1.580 raeburn 11781: srchby => 'lastname',
1.555 raeburn 11782: );
11783: my $srchterm;
1.625 raeburn 11784: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11785: if ($srch->{'srchby'} ne '') {
11786: $curr_selected{'srchby'} = $srch->{'srchby'};
11787: }
11788: if ($srch->{'srchin'} ne '') {
11789: $curr_selected{'srchin'} = $srch->{'srchin'};
11790: }
11791: if ($srch->{'srchtype'} ne '') {
11792: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11793: }
11794: if ($srch->{'srchdomain'} ne '') {
11795: $currdom = $srch->{'srchdomain'};
11796: }
11797: $srchterm = $srch->{'srchterm'};
11798: }
1.1222 damieng 11799: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11800: 'usr' => 'Search criteria',
1.563 raeburn 11801: 'doma' => 'Domain/institution to search',
1.558 albertel 11802: 'uname' => 'username',
11803: 'lastname' => 'last name',
1.555 raeburn 11804: 'lastfirst' => 'last name, first name',
1.558 albertel 11805: 'crs' => 'in this course',
1.576 raeburn 11806: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11807: 'alc' => 'all LON-CAPA',
1.573 raeburn 11808: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11809: 'exact' => 'is',
11810: 'contains' => 'contains',
1.569 raeburn 11811: 'begins' => 'begins with',
1.1222 damieng 11812: );
11813: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11814: 'youm' => "You must include some text to search for.",
11815: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11816: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11817: 'yomc' => "You must choose a domain when using an institutional directory search.",
11818: 'ymcd' => "You must choose a domain when using a domain search.",
11819: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11820: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11821: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11822: );
1.1222 damieng 11823: &html_escape(\%html_lt);
11824: &js_escape(\%js_lt);
1.1255 raeburn 11825: my $domform;
1.1277 raeburn 11826: my $allow_blank = 1;
1.1255 raeburn 11827: if ($fixeddom) {
1.1277 raeburn 11828: $allow_blank = 0;
11829: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11830: } else {
1.1287 raeburn 11831: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11832: my ($trusted,$untrusted);
1.1287 raeburn 11833: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11834: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11835: } elsif ($context eq 'author') {
1.1288 raeburn 11836: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11837: } elsif ($context eq 'domain') {
1.1288 raeburn 11838: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11839: }
1.1288 raeburn 11840: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11841: }
1.563 raeburn 11842: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11843:
11844: my @srchins = ('crs','dom','alc','instd');
11845:
11846: foreach my $option (@srchins) {
11847: # FIXME 'alc' option unavailable until
11848: # loncreateuser::print_user_query_page()
11849: # has been completed.
11850: next if ($option eq 'alc');
1.880 raeburn 11851: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11852: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11853: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11854: if ($curr_selected{'srchin'} eq $option) {
11855: $srchinsel .= '
1.1222 damieng 11856: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11857: } else {
11858: $srchinsel .= '
1.1222 damieng 11859: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11860: }
1.555 raeburn 11861: }
1.563 raeburn 11862: $srchinsel .= "\n </select>\n";
1.555 raeburn 11863:
11864: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11865: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11866: if ($curr_selected{'srchby'} eq $option) {
11867: $srchbysel .= '
1.1222 damieng 11868: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11869: } else {
11870: $srchbysel .= '
1.1222 damieng 11871: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11872: }
11873: }
11874: $srchbysel .= "\n </select>\n";
11875:
11876: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11877: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11878: if ($curr_selected{'srchtype'} eq $option) {
11879: $srchtypesel .= '
1.1222 damieng 11880: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11881: } else {
11882: $srchtypesel .= '
1.1222 damieng 11883: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11884: }
11885: }
11886: $srchtypesel .= "\n </select>\n";
11887:
1.558 albertel 11888: my ($newuserscript,$new_user_create);
1.994 raeburn 11889: my $context_dom = $env{'request.role.domain'};
11890: if ($context eq 'requestcrs') {
11891: if ($env{'form.coursedom'} ne '') {
11892: $context_dom = $env{'form.coursedom'};
11893: }
11894: }
1.556 raeburn 11895: if ($forcenewuser) {
1.576 raeburn 11896: if (ref($srch) eq 'HASH') {
1.994 raeburn 11897: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11898: if ($cancreate) {
11899: $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>';
11900: } else {
1.799 bisitz 11901: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11902: my %usertypetext = (
11903: official => 'institutional',
11904: unofficial => 'non-institutional',
11905: );
1.799 bisitz 11906: $new_user_create = '<p class="LC_warning">'
11907: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11908: .' '
11909: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11910: ,'<a href="'.$helplink.'">','</a>')
11911: .'</p><br />';
1.627 raeburn 11912: }
1.576 raeburn 11913: }
11914: }
11915:
1.556 raeburn 11916: $newuserscript = <<"ENDSCRIPT";
11917:
1.570 raeburn 11918: function setSearch(createnew,callingForm) {
1.556 raeburn 11919: if (createnew == 1) {
1.570 raeburn 11920: for (var i=0; i<callingForm.srchby.length; i++) {
11921: if (callingForm.srchby.options[i].value == 'uname') {
11922: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11923: }
11924: }
1.570 raeburn 11925: for (var i=0; i<callingForm.srchin.length; i++) {
11926: if ( callingForm.srchin.options[i].value == 'dom') {
11927: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11928: }
11929: }
1.570 raeburn 11930: for (var i=0; i<callingForm.srchtype.length; i++) {
11931: if (callingForm.srchtype.options[i].value == 'exact') {
11932: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11933: }
11934: }
1.570 raeburn 11935: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11936: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11937: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11938: }
11939: }
11940: }
11941: }
11942: ENDSCRIPT
1.558 albertel 11943:
1.556 raeburn 11944: }
11945:
1.555 raeburn 11946: my $output = <<"END_BLOCK";
1.556 raeburn 11947: <script type="text/javascript">
1.824 bisitz 11948: // <![CDATA[
1.570 raeburn 11949: function validateEntry(callingForm) {
1.558 albertel 11950:
1.556 raeburn 11951: var checkok = 1;
1.558 albertel 11952: var srchin;
1.570 raeburn 11953: for (var i=0; i<callingForm.srchin.length; i++) {
11954: if ( callingForm.srchin[i].checked ) {
11955: srchin = callingForm.srchin[i].value;
1.558 albertel 11956: }
11957: }
11958:
1.570 raeburn 11959: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11960: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11961: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11962: var srchterm = callingForm.srchterm.value;
11963: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11964: var msg = "";
11965:
11966: if (srchterm == "") {
11967: checkok = 0;
1.1222 damieng 11968: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11969: }
11970:
1.569 raeburn 11971: if (srchtype== 'begins') {
11972: if (srchterm.length < 2) {
11973: checkok = 0;
1.1222 damieng 11974: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11975: }
11976: }
11977:
1.556 raeburn 11978: if (srchtype== 'contains') {
11979: if (srchterm.length < 3) {
11980: checkok = 0;
1.1222 damieng 11981: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11982: }
11983: }
11984: if (srchin == 'instd') {
11985: if (srchdomain == '') {
11986: checkok = 0;
1.1222 damieng 11987: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11988: }
11989: }
11990: if (srchin == 'dom') {
11991: if (srchdomain == '') {
11992: checkok = 0;
1.1222 damieng 11993: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11994: }
11995: }
11996: if (srchby == 'lastfirst') {
11997: if (srchterm.indexOf(",") == -1) {
11998: checkok = 0;
1.1222 damieng 11999: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 12000: }
12001: if (srchterm.indexOf(",") == srchterm.length -1) {
12002: checkok = 0;
1.1222 damieng 12003: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 12004: }
12005: }
12006: if (checkok == 0) {
1.1222 damieng 12007: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 12008: return;
12009: }
12010: if (checkok == 1) {
1.570 raeburn 12011: callingForm.submit();
1.556 raeburn 12012: }
12013: }
12014:
12015: $newuserscript
12016:
1.824 bisitz 12017: // ]]>
1.556 raeburn 12018: </script>
1.558 albertel 12019:
12020: $new_user_create
12021:
1.555 raeburn 12022: END_BLOCK
1.558 albertel 12023:
1.876 raeburn 12024: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 12025: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 12026: $domform.
12027: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 12028: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 12029: $srchbysel.
12030: $srchtypesel.
12031: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
12032: $srchinsel.
12033: &Apache::lonhtmlcommon::row_closure(1).
12034: &Apache::lonhtmlcommon::end_pick_box().
12035: '<br />';
1.1253 raeburn 12036: return ($output,1);
1.555 raeburn 12037: }
12038:
1.612 raeburn 12039: sub user_rule_check {
1.615 raeburn 12040: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 12041: my ($response,%inst_response);
1.612 raeburn 12042: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 12043: if (keys(%{$usershash}) > 1) {
12044: my (%by_username,%by_id,%userdoms);
12045: my $checkid;
12046: if (ref($checks) eq 'HASH') {
12047: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
12048: $checkid = 1;
12049: }
12050: }
12051: foreach my $user (keys(%{$usershash})) {
12052: my ($uname,$udom) = split(/:/,$user);
12053: if ($checkid) {
12054: if (ref($usershash->{$user}) eq 'HASH') {
12055: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 12056: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 12057: $userdoms{$udom} = 1;
1.1227 raeburn 12058: if (ref($inst_results) eq 'HASH') {
12059: $inst_results->{$uname.':'.$udom} = {};
12060: }
1.1226 raeburn 12061: }
12062: }
12063: } else {
12064: $by_username{$udom}{$uname} = 1;
12065: $userdoms{$udom} = 1;
1.1227 raeburn 12066: if (ref($inst_results) eq 'HASH') {
12067: $inst_results->{$uname.':'.$udom} = {};
12068: }
1.1226 raeburn 12069: }
12070: }
12071: foreach my $udom (keys(%userdoms)) {
12072: if (!$got_rules->{$udom}) {
12073: my %domconfig = &Apache::lonnet::get_dom('configuration',
12074: ['usercreation'],$udom);
12075: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12076: foreach my $item ('username','id') {
12077: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 12078: $$curr_rules{$udom}{$item} =
12079: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 12080: }
12081: }
12082: }
12083: $got_rules->{$udom} = 1;
12084: }
1.612 raeburn 12085: }
1.1226 raeburn 12086: if ($checkid) {
12087: foreach my $udom (keys(%by_id)) {
12088: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
12089: if ($outcome eq 'ok') {
1.1227 raeburn 12090: foreach my $id (keys(%{$by_id{$udom}})) {
12091: my $uname = $by_id{$udom}{$id};
12092: $inst_response{$uname.':'.$udom} = $outcome;
12093: }
1.1226 raeburn 12094: if (ref($results) eq 'HASH') {
12095: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 12096: if (exists($inst_response{$uname.':'.$udom})) {
12097: $inst_response{$uname.':'.$udom} = $outcome;
12098: $inst_results->{$uname.':'.$udom} = $results->{$uname};
12099: }
1.1226 raeburn 12100: }
12101: }
12102: }
1.612 raeburn 12103: }
1.615 raeburn 12104: } else {
1.1226 raeburn 12105: foreach my $udom (keys(%by_username)) {
12106: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
12107: if ($outcome eq 'ok') {
1.1227 raeburn 12108: foreach my $uname (keys(%{$by_username{$udom}})) {
12109: $inst_response{$uname.':'.$udom} = $outcome;
12110: }
1.1226 raeburn 12111: if (ref($results) eq 'HASH') {
12112: foreach my $uname (keys(%{$results})) {
12113: $inst_results->{$uname.':'.$udom} = $results->{$uname};
12114: }
12115: }
12116: }
12117: }
1.612 raeburn 12118: }
1.1226 raeburn 12119: } elsif (keys(%{$usershash}) == 1) {
12120: my $user = (keys(%{$usershash}))[0];
12121: my ($uname,$udom) = split(/:/,$user);
12122: if (($udom ne '') && ($uname ne '')) {
12123: if (ref($usershash->{$user}) eq 'HASH') {
12124: if (ref($checks) eq 'HASH') {
12125: if (defined($checks->{'username'})) {
12126: ($inst_response{$user},%{$inst_results->{$user}}) =
12127: &Apache::lonnet::get_instuser($udom,$uname);
12128: } elsif (defined($checks->{'id'})) {
12129: if ($usershash->{$user}->{'id'} ne '') {
12130: ($inst_response{$user},%{$inst_results->{$user}}) =
12131: &Apache::lonnet::get_instuser($udom,undef,
12132: $usershash->{$user}->{'id'});
12133: } else {
12134: ($inst_response{$user},%{$inst_results->{$user}}) =
12135: &Apache::lonnet::get_instuser($udom,$uname);
12136: }
1.585 raeburn 12137: }
1.1226 raeburn 12138: } else {
12139: ($inst_response{$user},%{$inst_results->{$user}}) =
12140: &Apache::lonnet::get_instuser($udom,$uname);
12141: return;
12142: }
12143: if (!$got_rules->{$udom}) {
12144: my %domconfig = &Apache::lonnet::get_dom('configuration',
12145: ['usercreation'],$udom);
12146: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12147: foreach my $item ('username','id') {
12148: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
12149: $$curr_rules{$udom}{$item} =
12150: $domconfig{'usercreation'}{$item.'_rule'};
12151: }
12152: }
12153: }
12154: $got_rules->{$udom} = 1;
1.585 raeburn 12155: }
12156: }
1.1226 raeburn 12157: } else {
12158: return;
12159: }
12160: } else {
12161: return;
12162: }
12163: foreach my $user (keys(%{$usershash})) {
12164: my ($uname,$udom) = split(/:/,$user);
12165: next if (($udom eq '') || ($uname eq ''));
12166: my $id;
1.1227 raeburn 12167: if (ref($inst_results) eq 'HASH') {
12168: if (ref($inst_results->{$user}) eq 'HASH') {
12169: $id = $inst_results->{$user}->{'id'};
12170: }
12171: }
12172: if ($id eq '') {
12173: if (ref($usershash->{$user})) {
12174: $id = $usershash->{$user}->{'id'};
12175: }
1.585 raeburn 12176: }
1.612 raeburn 12177: foreach my $item (keys(%{$checks})) {
12178: if (ref($$curr_rules{$udom}) eq 'HASH') {
12179: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
12180: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 12181: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
12182: $$curr_rules{$udom}{$item});
1.612 raeburn 12183: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
12184: if ($rule_check{$rule}) {
12185: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 12186: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 12187: if (ref($inst_results) eq 'HASH') {
12188: if (ref($inst_results->{$user}) eq 'HASH') {
12189: if (keys(%{$inst_results->{$user}}) == 0) {
12190: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 12191: } elsif ($item eq 'id') {
12192: if ($inst_results->{$user}->{'id'} eq '') {
12193: $$alerts{$item}{$udom}{$uname} = 1;
12194: }
1.615 raeburn 12195: }
1.612 raeburn 12196: }
12197: }
1.615 raeburn 12198: }
12199: last;
1.585 raeburn 12200: }
12201: }
12202: }
12203: }
12204: }
12205: }
12206: }
12207: }
1.612 raeburn 12208: return;
12209: }
12210:
12211: sub user_rule_formats {
12212: my ($domain,$domdesc,$curr_rules,$check) = @_;
12213: my %text = (
12214: 'username' => 'Usernames',
12215: 'id' => 'IDs',
12216: );
12217: my $output;
12218: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
12219: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
12220: if (@{$ruleorder} > 0) {
1.1102 raeburn 12221: $output = '<br />'.
12222: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
12223: '<span class="LC_cusr_emph">','</span>',$domdesc).
12224: ' <ul>';
1.612 raeburn 12225: foreach my $rule (@{$ruleorder}) {
12226: if (ref($curr_rules) eq 'ARRAY') {
12227: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
12228: if (ref($rules->{$rule}) eq 'HASH') {
12229: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
12230: $rules->{$rule}{'desc'}.'</li>';
12231: }
12232: }
12233: }
12234: }
12235: $output .= '</ul>';
12236: }
12237: }
12238: return $output;
12239: }
12240:
12241: sub instrule_disallow_msg {
1.615 raeburn 12242: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 12243: my $response;
12244: my %text = (
12245: item => 'username',
12246: items => 'usernames',
12247: match => 'matches',
12248: do => 'does',
12249: action => 'a username',
12250: one => 'one',
12251: );
12252: if ($count > 1) {
12253: $text{'item'} = 'usernames';
12254: $text{'match'} ='match';
12255: $text{'do'} = 'do';
12256: $text{'action'} = 'usernames',
12257: $text{'one'} = 'ones';
12258: }
12259: if ($checkitem eq 'id') {
12260: $text{'items'} = 'IDs';
12261: $text{'item'} = 'ID';
12262: $text{'action'} = 'an ID';
1.615 raeburn 12263: if ($count > 1) {
12264: $text{'item'} = 'IDs';
12265: $text{'action'} = 'IDs';
12266: }
1.612 raeburn 12267: }
1.674 bisitz 12268: $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 12269: if ($mode eq 'upload') {
12270: if ($checkitem eq 'username') {
12271: $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'}.");
12272: } elsif ($checkitem eq 'id') {
1.674 bisitz 12273: $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 12274: }
1.669 raeburn 12275: } elsif ($mode eq 'selfcreate') {
12276: if ($checkitem eq 'id') {
12277: $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.");
12278: }
1.615 raeburn 12279: } else {
12280: if ($checkitem eq 'username') {
12281: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
12282: } elsif ($checkitem eq 'id') {
12283: $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.");
12284: }
1.612 raeburn 12285: }
12286: return $response;
1.585 raeburn 12287: }
12288:
1.624 raeburn 12289: sub personal_data_fieldtitles {
12290: my %fieldtitles = &Apache::lonlocal::texthash (
12291: id => 'Student/Employee ID',
12292: permanentemail => 'E-mail address',
12293: lastname => 'Last Name',
12294: firstname => 'First Name',
12295: middlename => 'Middle Name',
12296: generation => 'Generation',
12297: gen => 'Generation',
1.765 raeburn 12298: inststatus => 'Affiliation',
1.624 raeburn 12299: );
12300: return %fieldtitles;
12301: }
12302:
1.642 raeburn 12303: sub sorted_inst_types {
12304: my ($dom) = @_;
1.1185 raeburn 12305: my ($usertypes,$order);
12306: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12307: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
12308: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
12309: $order = $domdefaults{'inststatus'}{'inststatusorder'};
12310: } else {
12311: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
12312: }
1.642 raeburn 12313: my $othertitle = &mt('All users');
12314: if ($env{'request.course.id'}) {
1.668 raeburn 12315: $othertitle = &mt('Any users');
1.642 raeburn 12316: }
12317: my @types;
12318: if (ref($order) eq 'ARRAY') {
12319: @types = @{$order};
12320: }
12321: if (@types == 0) {
12322: if (ref($usertypes) eq 'HASH') {
12323: @types = sort(keys(%{$usertypes}));
12324: }
12325: }
12326: if (keys(%{$usertypes}) > 0) {
12327: $othertitle = &mt('Other users');
12328: }
12329: return ($othertitle,$usertypes,\@types);
12330: }
12331:
1.645 raeburn 12332: sub get_institutional_codes {
1.1361 raeburn 12333: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 12334: # Get complete list of course sections to update
12335: my @currsections = ();
12336: my @currxlists = ();
1.1361 raeburn 12337: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 12338: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 12339: my $crskey = $crs.':'.$coursecode;
12340: @{$unclutteredsec{$crskey}} = ();
12341: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 12342:
12343: if ($$settings{'internal.sectionnums'} ne '') {
12344: @currsections = split(/,/,$$settings{'internal.sectionnums'});
12345: }
12346:
12347: if ($$settings{'internal.crosslistings'} ne '') {
12348: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
12349: }
12350:
12351: if (@currxlists > 0) {
1.1361 raeburn 12352: foreach my $xl (@currxlists) {
12353: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 12354: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 12355: push(@{$allcourses},$1);
1.645 raeburn 12356: $$LC_code{$1} = $2;
12357: }
12358: }
12359: }
12360: }
1.1361 raeburn 12361:
1.645 raeburn 12362: if (@currsections > 0) {
1.1361 raeburn 12363: foreach my $sec (@currsections) {
12364: if ($sec =~ m/^(\w+):(\w*)$/ ) {
12365: my $instsec = $1;
1.645 raeburn 12366: my $lc_sec = $2;
1.1361 raeburn 12367: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
12368: push(@{$unclutteredsec{$crskey}},$instsec);
12369: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
12370: }
12371: }
12372: }
12373: }
12374:
12375: if (@{$unclutteredsec{$crskey}} > 0) {
12376: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
12377: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
12378: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
12379: my $sec = $coursecode.$formattedsec{$crskey}[$i];
12380: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 12381: push(@{$allcourses},$sec);
1.1361 raeburn 12382: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 12383: }
12384: }
12385: }
12386: }
12387: return;
12388: }
12389:
1.971 raeburn 12390: sub get_standard_codeitems {
12391: return ('Year','Semester','Department','Number','Section');
12392: }
12393:
1.112 bowersj2 12394: =pod
12395:
1.780 raeburn 12396: =head1 Slot Helpers
12397:
12398: =over 4
12399:
12400: =item * sorted_slots()
12401:
1.1040 raeburn 12402: Sorts an array of slot names in order of an optional sort key,
12403: default sort is by slot start time (earliest first).
1.780 raeburn 12404:
12405: Inputs:
12406:
12407: =over 4
12408:
12409: slotsarr - Reference to array of unsorted slot names.
12410:
12411: slots - Reference to hash of hash, where outer hash keys are slot names.
12412:
1.1040 raeburn 12413: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
12414:
1.549 albertel 12415: =back
12416:
1.780 raeburn 12417: Returns:
12418:
12419: =over 4
12420:
1.1040 raeburn 12421: sorted - An array of slot names sorted by a specified sort key
12422: (default sort key is start time of the slot).
1.780 raeburn 12423:
12424: =back
12425:
12426: =cut
12427:
12428:
12429: sub sorted_slots {
1.1040 raeburn 12430: my ($slotsarr,$slots,$sortkey) = @_;
12431: if ($sortkey eq '') {
12432: $sortkey = 'starttime';
12433: }
1.780 raeburn 12434: my @sorted;
12435: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
12436: @sorted =
12437: sort {
12438: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 12439: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 12440: }
12441: if (ref($slots->{$a})) { return -1;}
12442: if (ref($slots->{$b})) { return 1;}
12443: return 0;
12444: } @{$slotsarr};
12445: }
12446: return @sorted;
12447: }
12448:
1.1040 raeburn 12449: =pod
12450:
12451: =item * get_future_slots()
12452:
12453: Inputs:
12454:
12455: =over 4
12456:
12457: cnum - course number
12458:
12459: cdom - course domain
12460:
12461: now - current UNIX time
12462:
12463: symb - optional symb
12464:
12465: =back
12466:
12467: Returns:
12468:
12469: =over 4
12470:
12471: sorted_reservable - ref to array of student_schedulable slots currently
12472: reservable, ordered by end date of reservation period.
12473:
12474: reservable_now - ref to hash of student_schedulable slots currently
12475: reservable.
12476:
12477: Keys in inner hash are:
12478: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12479: (b) endreserve: end date of reservation period.
12480: (c) uniqueperiod: start,end dates when slot is to be uniquely
12481: selected.
1.1040 raeburn 12482:
12483: sorted_future - ref to array of student_schedulable slots reservable in
12484: the future, ordered by start date of reservation period.
12485:
12486: future_reservable - ref to hash of student_schedulable slots reservable
12487: in the future.
12488:
12489: Keys in inner hash are:
12490: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12491: (b) startreserve: start date of reservation period.
12492: (c) uniqueperiod: start,end dates when slot is to be uniquely
12493: selected.
1.1040 raeburn 12494:
12495: =back
12496:
12497: =cut
12498:
12499: sub get_future_slots {
12500: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 12501: my $map;
12502: if ($symb) {
12503: ($map) = &Apache::lonnet::decode_symb($symb);
12504: }
1.1040 raeburn 12505: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
12506: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
12507: foreach my $slot (keys(%slots)) {
12508: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
12509: if ($symb) {
1.1229 raeburn 12510: if ($slots{$slot}->{'symb'} ne '') {
12511: my $canuse;
12512: my %oksymbs;
12513: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
12514: map { $oksymbs{$_} = 1; } @slotsymbs;
12515: if ($oksymbs{$symb}) {
12516: $canuse = 1;
12517: } else {
12518: foreach my $item (@slotsymbs) {
12519: if ($item =~ /\.(page|sequence)$/) {
12520: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12521: if (($map ne '') && ($map eq $sloturl)) {
12522: $canuse = 1;
12523: last;
12524: }
12525: }
12526: }
12527: }
12528: next unless ($canuse);
12529: }
1.1040 raeburn 12530: }
12531: if (($slots{$slot}->{'starttime'} > $now) &&
12532: ($slots{$slot}->{'endtime'} > $now)) {
12533: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12534: my $userallowed = 0;
12535: if ($slots{$slot}->{'allowedsections'}) {
12536: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12537: if (!defined($env{'request.role.sec'})
12538: && grep(/^No section assigned$/,@allowed_sec)) {
12539: $userallowed=1;
12540: } else {
12541: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12542: $userallowed=1;
12543: }
12544: }
12545: unless ($userallowed) {
12546: if (defined($env{'request.course.groups'})) {
12547: my @groups = split(/:/,$env{'request.course.groups'});
12548: foreach my $group (@groups) {
12549: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12550: $userallowed=1;
12551: last;
12552: }
12553: }
12554: }
12555: }
12556: }
12557: if ($slots{$slot}->{'allowedusers'}) {
12558: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12559: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12560: if (grep(/^\Q$user\E$/,@allowed_users)) {
12561: $userallowed = 1;
12562: }
12563: }
12564: next unless($userallowed);
12565: }
12566: my $startreserve = $slots{$slot}->{'startreserve'};
12567: my $endreserve = $slots{$slot}->{'endreserve'};
12568: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12569: my $uniqueperiod;
12570: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12571: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12572: }
1.1040 raeburn 12573: if (($startreserve < $now) &&
12574: (!$endreserve || $endreserve > $now)) {
12575: my $lastres = $endreserve;
12576: if (!$lastres) {
12577: $lastres = $slots{$slot}->{'starttime'};
12578: }
12579: $reservable_now{$slot} = {
12580: symb => $symb,
1.1250 raeburn 12581: endreserve => $lastres,
12582: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12583: };
12584: } elsif (($startreserve > $now) &&
12585: (!$endreserve || $endreserve > $startreserve)) {
12586: $future_reservable{$slot} = {
12587: symb => $symb,
1.1250 raeburn 12588: startreserve => $startreserve,
12589: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12590: };
12591: }
12592: }
12593: }
12594: my @unsorted_reservable = keys(%reservable_now);
12595: if (@unsorted_reservable > 0) {
12596: @sorted_reservable =
12597: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12598: }
12599: my @unsorted_future = keys(%future_reservable);
12600: if (@unsorted_future > 0) {
12601: @sorted_future =
12602: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12603: }
12604: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12605: }
1.780 raeburn 12606:
12607: =pod
12608:
1.1057 foxr 12609: =back
12610:
1.549 albertel 12611: =head1 HTTP Helpers
12612:
12613: =over 4
12614:
1.648 raeburn 12615: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12616:
1.258 albertel 12617: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12618: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12619: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12620:
12621: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12622: $possible_names is an ref to an array of form element names. As an example:
12623: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12624: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12625:
12626: =cut
1.1 albertel 12627:
1.6 albertel 12628: sub get_unprocessed_cgi {
1.25 albertel 12629: my ($query,$possible_names)= @_;
1.26 matthew 12630: # $Apache::lonxml::debug=1;
1.356 albertel 12631: foreach my $pair (split(/&/,$query)) {
12632: my ($name, $value) = split(/=/,$pair);
1.369 www 12633: $name = &unescape($name);
1.25 albertel 12634: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12635: $value =~ tr/+/ /;
12636: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12637: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12638: }
1.16 harris41 12639: }
1.6 albertel 12640: }
12641:
1.112 bowersj2 12642: =pod
12643:
1.648 raeburn 12644: =item * &cacheheader()
1.112 bowersj2 12645:
12646: returns cache-controlling header code
12647:
12648: =cut
12649:
1.7 albertel 12650: sub cacheheader {
1.258 albertel 12651: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12652: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12653: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12654: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12655: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12656: return $output;
1.7 albertel 12657: }
12658:
1.112 bowersj2 12659: =pod
12660:
1.648 raeburn 12661: =item * &no_cache($r)
1.112 bowersj2 12662:
12663: specifies header code to not have cache
12664:
12665: =cut
12666:
1.9 albertel 12667: sub no_cache {
1.216 albertel 12668: my ($r) = @_;
12669: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12670: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12671: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12672: $r->no_cache(1);
12673: $r->header_out("Expires" => $date);
12674: $r->header_out("Pragma" => "no-cache");
1.123 www 12675: }
12676:
12677: sub content_type {
1.181 albertel 12678: my ($r,$type,$charset) = @_;
1.299 foxr 12679: if ($r) {
12680: # Note that printout.pl calls this with undef for $r.
12681: &no_cache($r);
12682: }
1.258 albertel 12683: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12684: unless ($charset) {
12685: $charset=&Apache::lonlocal::current_encoding;
12686: }
12687: if ($charset) { $type.='; charset='.$charset; }
12688: if ($r) {
12689: $r->content_type($type);
12690: } else {
12691: print("Content-type: $type\n\n");
12692: }
1.9 albertel 12693: }
1.25 albertel 12694:
1.112 bowersj2 12695: =pod
12696:
1.648 raeburn 12697: =item * &add_to_env($name,$value)
1.112 bowersj2 12698:
1.258 albertel 12699: adds $name to the %env hash with value
1.112 bowersj2 12700: $value, if $name already exists, the entry is converted to an array
12701: reference and $value is added to the array.
12702:
12703: =cut
12704:
1.25 albertel 12705: sub add_to_env {
12706: my ($name,$value)=@_;
1.258 albertel 12707: if (defined($env{$name})) {
12708: if (ref($env{$name})) {
1.25 albertel 12709: #already have multiple values
1.258 albertel 12710: push(@{ $env{$name} },$value);
1.25 albertel 12711: } else {
12712: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12713: my $first=$env{$name};
12714: undef($env{$name});
12715: push(@{ $env{$name} },$first,$value);
1.25 albertel 12716: }
12717: } else {
1.258 albertel 12718: $env{$name}=$value;
1.25 albertel 12719: }
1.31 albertel 12720: }
1.149 albertel 12721:
12722: =pod
12723:
1.648 raeburn 12724: =item * &get_env_multiple($name)
1.149 albertel 12725:
1.258 albertel 12726: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12727: values may be defined and end up as an array ref.
12728:
12729: returns an array of values
12730:
12731: =cut
12732:
12733: sub get_env_multiple {
12734: my ($name) = @_;
12735: my @values;
1.258 albertel 12736: if (defined($env{$name})) {
1.149 albertel 12737: # exists is it an array
1.258 albertel 12738: if (ref($env{$name})) {
12739: @values=@{ $env{$name} };
1.149 albertel 12740: } else {
1.258 albertel 12741: $values[0]=$env{$name};
1.149 albertel 12742: }
12743: }
12744: return(@values);
12745: }
12746:
1.1249 damieng 12747: # Looks at given dependencies, and returns something depending on the context.
12748: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12749: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12750: # For all other contexts, returns ($output, $counter, $numpathchg).
12751: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12752: # $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.
12753: # $numpathchg: integer with the number of cleaned up dependency paths.
12754: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12755: # \%mapping: hash reference clean path -> original path for all dependencies.
12756: # @param {string} actionurl - The path to the handler, indicative of the context.
12757: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12758: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12759: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12760: # @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)
12761: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12762: sub ask_for_embedded_content {
1.1249 damieng 12763: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12764: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12765: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12766: %currsubfile,%unused,$rem);
1.1071 raeburn 12767: my $counter = 0;
12768: my $numnew = 0;
1.987 raeburn 12769: my $numremref = 0;
12770: my $numinvalid = 0;
12771: my $numpathchg = 0;
12772: my $numexisting = 0;
1.1071 raeburn 12773: my $numunused = 0;
12774: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12775: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12776: my $heading = &mt('Upload embedded files');
12777: my $buttontext = &mt('Upload');
12778:
1.1249 damieng 12779: # fills these variables based on the context:
12780: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12781: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12782: if ($env{'request.course.id'}) {
1.1123 raeburn 12783: if ($actionurl eq '/adm/dependencies') {
12784: $navmap = Apache::lonnavmaps::navmap->new();
12785: }
12786: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12787: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12788: }
1.1123 raeburn 12789: if (($actionurl eq '/adm/portfolio') ||
12790: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12791: my $current_path='/';
12792: if ($env{'form.currentpath'}) {
12793: $current_path = $env{'form.currentpath'};
12794: }
12795: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12796: $udom = $cdom;
12797: $uname = $cnum;
1.984 raeburn 12798: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12799: } else {
12800: $udom = $env{'user.domain'};
12801: $uname = $env{'user.name'};
12802: $url = '/userfiles/portfolio';
12803: }
1.987 raeburn 12804: $toplevel = $url.'/';
1.984 raeburn 12805: $url .= $current_path;
12806: $getpropath = 1;
1.987 raeburn 12807: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12808: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12809: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12810: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12811: $toplevel = $url;
1.984 raeburn 12812: if ($rest ne '') {
1.987 raeburn 12813: $url .= $rest;
12814: }
12815: } elsif ($actionurl eq '/adm/coursedocs') {
12816: if (ref($args) eq 'HASH') {
1.1071 raeburn 12817: $url = $args->{'docs_url'};
12818: $toplevel = $url;
1.1084 raeburn 12819: if ($args->{'context'} eq 'paste') {
12820: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12821: ($path) =
12822: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12823: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12824: $fileloc =~ s{^/}{};
12825: }
1.1071 raeburn 12826: }
1.1084 raeburn 12827: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12828: if ($env{'request.course.id'} ne '') {
12829: if (ref($args) eq 'HASH') {
12830: $url = $args->{'docs_url'};
12831: $title = $args->{'docs_title'};
1.1126 raeburn 12832: $toplevel = $url;
12833: unless ($toplevel =~ m{^/}) {
12834: $toplevel = "/$url";
12835: }
1.1085 raeburn 12836: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12837: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12838: $path = $1;
12839: } else {
12840: ($path) =
12841: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12842: }
1.1195 raeburn 12843: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12844: $fileloc = $toplevel;
12845: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12846: my ($udom,$uname,$fname) =
12847: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12848: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12849: } else {
12850: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12851: }
1.1071 raeburn 12852: $fileloc =~ s{^/}{};
12853: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12854: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12855: }
1.987 raeburn 12856: }
1.1123 raeburn 12857: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12858: $udom = $cdom;
12859: $uname = $cnum;
12860: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12861: $toplevel = $url;
12862: $path = $url;
12863: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12864: $fileloc =~ s{^/}{};
1.987 raeburn 12865: }
1.1249 damieng 12866:
12867: # parses the dependency paths to get some info
12868: # fills $newfiles, $mapping, $subdependencies, $dependencies
12869: # $newfiles: hash URL -> 1 for new files or external URLs
12870: # (will be completed later)
12871: # $mapping:
12872: # for external URLs: external URL -> external URL
12873: # for relative paths: clean path -> original path
12874: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12875: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12876: foreach my $file (keys(%{$allfiles})) {
12877: my $embed_file;
12878: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12879: $embed_file = $1;
12880: } else {
12881: $embed_file = $file;
12882: }
1.1158 raeburn 12883: my ($absolutepath,$cleaned_file);
12884: if ($embed_file =~ m{^\w+://}) {
12885: $cleaned_file = $embed_file;
1.1147 raeburn 12886: $newfiles{$cleaned_file} = 1;
12887: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12888: } else {
1.1158 raeburn 12889: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12890: if ($embed_file =~ m{^/}) {
12891: $absolutepath = $embed_file;
12892: }
1.1147 raeburn 12893: if ($cleaned_file =~ m{/}) {
12894: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12895: $path = &check_for_traversal($path,$url,$toplevel);
12896: my $item = $fname;
12897: if ($path ne '') {
12898: $item = $path.'/'.$fname;
12899: $subdependencies{$path}{$fname} = 1;
12900: } else {
12901: $dependencies{$item} = 1;
12902: }
12903: if ($absolutepath) {
12904: $mapping{$item} = $absolutepath;
12905: } else {
12906: $mapping{$item} = $embed_file;
12907: }
12908: } else {
12909: $dependencies{$embed_file} = 1;
12910: if ($absolutepath) {
1.1147 raeburn 12911: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12912: } else {
1.1147 raeburn 12913: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12914: }
12915: }
1.984 raeburn 12916: }
12917: }
1.1249 damieng 12918:
12919: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12920: # and lists
12921: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12922: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12923: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12924: # the path had to be cleaned up
12925: # $existing: hash clean path -> 1 if the file exists
12926: # $numexisting: number of keys in $existing
12927: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12928: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12929: # dependency subdirectories that are
12930: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12931: my $dirptr = 16384;
1.984 raeburn 12932: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12933: $currsubfile{$path} = {};
1.1123 raeburn 12934: if (($actionurl eq '/adm/portfolio') ||
12935: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12936: my ($sublistref,$listerror) =
12937: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12938: if (ref($sublistref) eq 'ARRAY') {
12939: foreach my $line (@{$sublistref}) {
12940: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12941: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12942: }
1.984 raeburn 12943: }
1.987 raeburn 12944: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12945: if (opendir(my $dir,$url.'/'.$path)) {
12946: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12947: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12948: }
1.1084 raeburn 12949: } elsif (($actionurl eq '/adm/dependencies') ||
12950: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12951: ($args->{'context'} eq 'paste')) ||
12952: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12953: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12954: my $dir;
12955: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12956: $dir = $fileloc;
12957: } else {
12958: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12959: }
1.1071 raeburn 12960: if ($dir ne '') {
12961: my ($sublistref,$listerror) =
12962: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12963: if (ref($sublistref) eq 'ARRAY') {
12964: foreach my $line (@{$sublistref}) {
12965: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12966: undef,$mtime)=split(/\&/,$line,12);
12967: unless (($testdir&$dirptr) ||
12968: ($file_name =~ /^\.\.?$/)) {
12969: $currsubfile{$path}{$file_name} = [$size,$mtime];
12970: }
12971: }
12972: }
12973: }
1.984 raeburn 12974: }
12975: }
12976: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12977: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12978: my $item = $path.'/'.$file;
12979: unless ($mapping{$item} eq $item) {
12980: $pathchanges{$item} = 1;
12981: }
12982: $existing{$item} = 1;
12983: $numexisting ++;
12984: } else {
12985: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12986: }
12987: }
1.1071 raeburn 12988: if ($actionurl eq '/adm/dependencies') {
12989: foreach my $path (keys(%currsubfile)) {
12990: if (ref($currsubfile{$path}) eq 'HASH') {
12991: foreach my $file (keys(%{$currsubfile{$path}})) {
12992: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12993: next if (($rem ne '') &&
12994: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12995: (ref($navmap) &&
12996: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12997: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12998: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12999: $unused{$path.'/'.$file} = 1;
13000: }
13001: }
13002: }
13003: }
13004: }
1.984 raeburn 13005: }
1.1249 damieng 13006:
13007: # fills $currfile, hash file name -> 1 or [$size,$mtime]
13008: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 13009: my %currfile;
1.1123 raeburn 13010: if (($actionurl eq '/adm/portfolio') ||
13011: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 13012: my ($dirlistref,$listerror) =
13013: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
13014: if (ref($dirlistref) eq 'ARRAY') {
13015: foreach my $line (@{$dirlistref}) {
13016: my ($file_name,$rest) = split(/\&/,$line,2);
13017: $currfile{$file_name} = 1;
13018: }
1.984 raeburn 13019: }
1.987 raeburn 13020: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 13021: if (opendir(my $dir,$url)) {
1.987 raeburn 13022: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 13023: map {$currfile{$_} = 1;} @dir_list;
13024: }
1.1084 raeburn 13025: } elsif (($actionurl eq '/adm/dependencies') ||
13026: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 13027: ($args->{'context'} eq 'paste')) ||
13028: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 13029: if ($env{'request.course.id'} ne '') {
13030: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
13031: if ($dir ne '') {
13032: my ($dirlistref,$listerror) =
13033: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
13034: if (ref($dirlistref) eq 'ARRAY') {
13035: foreach my $line (@{$dirlistref}) {
13036: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
13037: $size,undef,$mtime)=split(/\&/,$line,12);
13038: unless (($testdir&$dirptr) ||
13039: ($file_name =~ /^\.\.?$/)) {
13040: $currfile{$file_name} = [$size,$mtime];
13041: }
13042: }
13043: }
13044: }
13045: }
1.984 raeburn 13046: }
1.1249 damieng 13047: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
13048: # are not in subdirectories, using $currfile
1.984 raeburn 13049: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 13050: if (exists($currfile{$file})) {
1.987 raeburn 13051: unless ($mapping{$file} eq $file) {
13052: $pathchanges{$file} = 1;
13053: }
13054: $existing{$file} = 1;
13055: $numexisting ++;
13056: } else {
1.984 raeburn 13057: $newfiles{$file} = 1;
13058: }
13059: }
1.1071 raeburn 13060: foreach my $file (keys(%currfile)) {
13061: unless (($file eq $filename) ||
13062: ($file eq $filename.'.bak') ||
13063: ($dependencies{$file})) {
1.1085 raeburn 13064: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 13065: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
13066: next if (($rem ne '') &&
13067: (($env{"httpref.$rem".$file} ne '') ||
13068: (ref($navmap) &&
13069: (($navmap->getResourceByUrl($rem.$file) ne '') ||
13070: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
13071: ($navmap->getResourceByUrl($rem.$1)))))));
13072: }
1.1085 raeburn 13073: }
1.1071 raeburn 13074: $unused{$file} = 1;
13075: }
13076: }
1.1249 damieng 13077:
13078: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 13079: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
13080: ($args->{'context'} eq 'paste')) {
13081: $counter = scalar(keys(%existing));
13082: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 13083: return ($output,$counter,$numpathchg,\%existing);
13084: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
13085: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
13086: $counter = scalar(keys(%existing));
13087: $numpathchg = scalar(keys(%pathchanges));
13088: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 13089: }
1.1249 damieng 13090:
13091: # returns HTML otherwise, with dependency results and to ask for more uploads
13092:
13093: # $upload_output: missing dependencies (with upload form)
13094: # $modify_output: uploaded dependencies (in use)
13095: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 13096: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 13097: if ($actionurl eq '/adm/dependencies') {
13098: next if ($embed_file =~ m{^\w+://});
13099: }
1.660 raeburn 13100: $upload_output .= &start_data_table_row().
1.1123 raeburn 13101: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 13102: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 13103: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 13104: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
13105: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 13106: }
1.1123 raeburn 13107: $upload_output .= '</td>';
1.1071 raeburn 13108: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 13109: $upload_output.='<td align="right">'.
13110: '<span class="LC_info LC_fontsize_medium">'.
13111: &mt("URL points to web address").'</span>';
1.987 raeburn 13112: $numremref++;
1.660 raeburn 13113: } elsif ($args->{'error_on_invalid_names'}
13114: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 13115: $upload_output.='<td align="right"><span class="LC_warning">'.
13116: &mt('Invalid characters').'</span>';
1.987 raeburn 13117: $numinvalid++;
1.660 raeburn 13118: } else {
1.1123 raeburn 13119: $upload_output .= '<td>'.
13120: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 13121: $embed_file,\%mapping,
1.1071 raeburn 13122: $allfiles,$codebase,'upload');
13123: $counter ++;
13124: $numnew ++;
1.987 raeburn 13125: }
13126: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
13127: }
13128: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 13129: if ($actionurl eq '/adm/dependencies') {
13130: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
13131: $modify_output .= &start_data_table_row().
13132: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
13133: '<img src="'.&icon($embed_file).'" border="0" />'.
13134: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
13135: '<td>'.$size.'</td>'.
13136: '<td>'.$mtime.'</td>'.
13137: '<td><label><input type="checkbox" name="mod_upload_dep" '.
13138: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
13139: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
13140: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
13141: &embedded_file_element('upload_embedded',$counter,
13142: $embed_file,\%mapping,
13143: $allfiles,$codebase,'modify').
13144: '</div></td>'.
13145: &end_data_table_row()."\n";
13146: $counter ++;
13147: } else {
13148: $upload_output .= &start_data_table_row().
1.1123 raeburn 13149: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
13150: '<span class="LC_filename">'.$embed_file.'</span></td>'.
13151: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 13152: &Apache::loncommon::end_data_table_row()."\n";
13153: }
13154: }
13155: my $delidx = $counter;
13156: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
13157: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
13158: $delete_output .= &start_data_table_row().
13159: '<td><img src="'.&icon($oldfile).'" />'.
13160: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
13161: '<td>'.$size.'</td>'.
13162: '<td>'.$mtime.'</td>'.
13163: '<td><label><input type="checkbox" name="del_upload_dep" '.
13164: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
13165: &embedded_file_element('upload_embedded',$delidx,
13166: $oldfile,\%mapping,$allfiles,
13167: $codebase,'delete').'</td>'.
13168: &end_data_table_row()."\n";
13169: $numunused ++;
13170: $delidx ++;
1.987 raeburn 13171: }
13172: if ($upload_output) {
13173: $upload_output = &start_data_table().
13174: $upload_output.
13175: &end_data_table()."\n";
13176: }
1.1071 raeburn 13177: if ($modify_output) {
13178: $modify_output = &start_data_table().
13179: &start_data_table_header_row().
13180: '<th>'.&mt('File').'</th>'.
13181: '<th>'.&mt('Size (KB)').'</th>'.
13182: '<th>'.&mt('Modified').'</th>'.
13183: '<th>'.&mt('Upload replacement?').'</th>'.
13184: &end_data_table_header_row().
13185: $modify_output.
13186: &end_data_table()."\n";
13187: }
13188: if ($delete_output) {
13189: $delete_output = &start_data_table().
13190: &start_data_table_header_row().
13191: '<th>'.&mt('File').'</th>'.
13192: '<th>'.&mt('Size (KB)').'</th>'.
13193: '<th>'.&mt('Modified').'</th>'.
13194: '<th>'.&mt('Delete?').'</th>'.
13195: &end_data_table_header_row().
13196: $delete_output.
13197: &end_data_table()."\n";
13198: }
1.987 raeburn 13199: my $applies = 0;
13200: if ($numremref) {
13201: $applies ++;
13202: }
13203: if ($numinvalid) {
13204: $applies ++;
13205: }
13206: if ($numexisting) {
13207: $applies ++;
13208: }
1.1071 raeburn 13209: if ($counter || $numunused) {
1.987 raeburn 13210: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
13211: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 13212: $state.'<h3>'.$heading.'</h3>';
13213: if ($actionurl eq '/adm/dependencies') {
13214: if ($numnew) {
13215: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
13216: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
13217: $upload_output.'<br />'."\n";
13218: }
13219: if ($numexisting) {
13220: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
13221: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
13222: $modify_output.'<br />'."\n";
13223: $buttontext = &mt('Save changes');
13224: }
13225: if ($numunused) {
13226: $output .= '<h4>'.&mt('Unused files').'</h4>'.
13227: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
13228: $delete_output.'<br />'."\n";
13229: $buttontext = &mt('Save changes');
13230: }
13231: } else {
13232: $output .= $upload_output.'<br />'."\n";
13233: }
13234: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
13235: $counter.'" />'."\n";
13236: if ($actionurl eq '/adm/dependencies') {
13237: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
13238: $numnew.'" />'."\n";
13239: } elsif ($actionurl eq '') {
1.987 raeburn 13240: $output .= '<input type="hidden" name="phase" value="three" />';
13241: }
13242: } elsif ($applies) {
13243: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
13244: if ($applies > 1) {
13245: $output .=
1.1123 raeburn 13246: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 13247: if ($numremref) {
13248: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
13249: }
13250: if ($numinvalid) {
13251: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
13252: }
13253: if ($numexisting) {
13254: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
13255: }
13256: $output .= '</ul><br />';
13257: } elsif ($numremref) {
13258: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
13259: } elsif ($numinvalid) {
13260: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
13261: } elsif ($numexisting) {
13262: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
13263: }
13264: $output .= $upload_output.'<br />';
13265: }
13266: my ($pathchange_output,$chgcount);
1.1071 raeburn 13267: $chgcount = $counter;
1.987 raeburn 13268: if (keys(%pathchanges) > 0) {
13269: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 13270: if ($counter) {
1.987 raeburn 13271: $output .= &embedded_file_element('pathchange',$chgcount,
13272: $embed_file,\%mapping,
1.1071 raeburn 13273: $allfiles,$codebase,'change');
1.987 raeburn 13274: } else {
13275: $pathchange_output .=
13276: &start_data_table_row().
13277: '<td><input type ="checkbox" name="namechange" value="'.
13278: $chgcount.'" checked="checked" /></td>'.
13279: '<td>'.$mapping{$embed_file}.'</td>'.
13280: '<td>'.$embed_file.
13281: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 13282: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 13283: '</td>'.&end_data_table_row();
1.660 raeburn 13284: }
1.987 raeburn 13285: $numpathchg ++;
13286: $chgcount ++;
1.660 raeburn 13287: }
13288: }
1.1127 raeburn 13289: if (($counter) || ($numunused)) {
1.987 raeburn 13290: if ($numpathchg) {
13291: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
13292: $numpathchg.'" />'."\n";
13293: }
13294: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
13295: ($actionurl eq '/adm/imsimport')) {
13296: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
13297: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
13298: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 13299: } elsif ($actionurl eq '/adm/dependencies') {
13300: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 13301: }
1.1123 raeburn 13302: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 13303: } elsif ($numpathchg) {
13304: my %pathchange = ();
13305: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
13306: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13307: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 13308: }
1.987 raeburn 13309: }
1.1071 raeburn 13310: return ($output,$counter,$numpathchg);
1.987 raeburn 13311: }
13312:
1.1147 raeburn 13313: =pod
13314:
13315: =item * clean_path($name)
13316:
13317: Performs clean-up of directories, subdirectories and filename in an
13318: embedded object, referenced in an HTML file which is being uploaded
13319: to a course or portfolio, where
13320: "Upload embedded images/multimedia files if HTML file" checkbox was
13321: checked.
13322:
13323: Clean-up is similar to replacements in lonnet::clean_filename()
13324: except each / between sub-directory and next level is preserved.
13325:
13326: =cut
13327:
13328: sub clean_path {
13329: my ($embed_file) = @_;
13330: $embed_file =~s{^/+}{};
13331: my @contents;
13332: if ($embed_file =~ m{/}) {
13333: @contents = split(/\//,$embed_file);
13334: } else {
13335: @contents = ($embed_file);
13336: }
13337: my $lastidx = scalar(@contents)-1;
13338: for (my $i=0; $i<=$lastidx; $i++) {
13339: $contents[$i]=~s{\\}{/}g;
13340: $contents[$i]=~s/\s+/\_/g;
13341: $contents[$i]=~s{[^/\w\.\-]}{}g;
13342: if ($i == $lastidx) {
13343: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
13344: }
13345: }
13346: if ($lastidx > 0) {
13347: return join('/',@contents);
13348: } else {
13349: return $contents[0];
13350: }
13351: }
13352:
1.987 raeburn 13353: sub embedded_file_element {
1.1071 raeburn 13354: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 13355: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
13356: (ref($codebase) eq 'HASH'));
13357: my $output;
1.1071 raeburn 13358: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 13359: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
13360: }
13361: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
13362: &escape($embed_file).'" />';
13363: unless (($context eq 'upload_embedded') &&
13364: ($mapping->{$embed_file} eq $embed_file)) {
13365: $output .='
13366: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
13367: }
13368: my $attrib;
13369: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
13370: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
13371: }
13372: $output .=
13373: "\n\t\t".
13374: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
13375: $attrib.'" />';
13376: if (exists($codebase->{$mapping->{$embed_file}})) {
13377: $output .=
13378: "\n\t\t".
13379: '<input name="codebase_'.$num.'" type="hidden" value="'.
13380: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 13381: }
1.987 raeburn 13382: return $output;
1.660 raeburn 13383: }
13384:
1.1071 raeburn 13385: sub get_dependency_details {
13386: my ($currfile,$currsubfile,$embed_file) = @_;
13387: my ($size,$mtime,$showsize,$showmtime);
13388: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
13389: if ($embed_file =~ m{/}) {
13390: my ($path,$fname) = split(/\//,$embed_file);
13391: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
13392: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
13393: }
13394: } else {
13395: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
13396: ($size,$mtime) = @{$currfile->{$embed_file}};
13397: }
13398: }
13399: $showsize = $size/1024.0;
13400: $showsize = sprintf("%.1f",$showsize);
13401: if ($mtime > 0) {
13402: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
13403: }
13404: }
13405: return ($showsize,$showmtime);
13406: }
13407:
13408: sub ask_embedded_js {
13409: return <<"END";
13410: <script type="text/javascript"">
13411: // <![CDATA[
13412: function toggleBrowse(counter) {
13413: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
13414: var fileid = document.getElementById('embedded_item_'+counter);
13415: var uploaddivid = document.getElementById('moduploaddep_'+counter);
13416: if (chkboxid.checked == true) {
13417: uploaddivid.style.display='block';
13418: } else {
13419: uploaddivid.style.display='none';
13420: fileid.value = '';
13421: }
13422: }
13423: // ]]>
13424: </script>
13425:
13426: END
13427: }
13428:
1.661 raeburn 13429: sub upload_embedded {
13430: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 13431: $current_disk_usage,$hiddenstate,$actionurl) = @_;
13432: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 13433: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
13434: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
13435: my $orig_uploaded_filename =
13436: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 13437: foreach my $type ('orig','ref','attrib','codebase') {
13438: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
13439: $env{'form.embedded_'.$type.'_'.$i} =
13440: &unescape($env{'form.embedded_'.$type.'_'.$i});
13441: }
13442: }
1.661 raeburn 13443: my ($path,$fname) =
13444: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
13445: # no path, whole string is fname
13446: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
13447: $fname = &Apache::lonnet::clean_filename($fname);
13448: # See if there is anything left
13449: next if ($fname eq '');
13450:
13451: # Check if file already exists as a file or directory.
13452: my ($state,$msg);
13453: if ($context eq 'portfolio') {
13454: my $port_path = $dirpath;
13455: if ($group ne '') {
13456: $port_path = "groups/$group/$port_path";
13457: }
1.987 raeburn 13458: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
13459: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 13460: $dir_root,$port_path,$disk_quota,
13461: $current_disk_usage,$uname,$udom);
13462: if ($state eq 'will_exceed_quota'
1.984 raeburn 13463: || $state eq 'file_locked') {
1.661 raeburn 13464: $output .= $msg;
13465: next;
13466: }
13467: } elsif (($context eq 'author') || ($context eq 'testbank')) {
13468: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
13469: if ($state eq 'exists') {
13470: $output .= $msg;
13471: next;
13472: }
13473: }
13474: # Check if extension is valid
13475: if (($fname =~ /\.(\w+)$/) &&
13476: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 13477: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
13478: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 13479: next;
13480: } elsif (($fname =~ /\.(\w+)$/) &&
13481: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 13482: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 13483: next;
13484: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 13485: $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 13486: next;
13487: }
13488: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 13489: my $subdir = $path;
13490: $subdir =~ s{/+$}{};
1.661 raeburn 13491: if ($context eq 'portfolio') {
1.984 raeburn 13492: my $result;
13493: if ($state eq 'existingfile') {
13494: $result=
13495: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 13496: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 13497: } else {
1.984 raeburn 13498: $result=
13499: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 13500: $dirpath.
1.1123 raeburn 13501: $env{'form.currentpath'}.$subdir);
1.984 raeburn 13502: if ($result !~ m|^/uploaded/|) {
13503: $output .= '<span class="LC_error">'
13504: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13505: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13506: .'</span><br />';
13507: next;
13508: } else {
1.987 raeburn 13509: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13510: $path.$fname.'</span>').'<br />';
1.984 raeburn 13511: }
1.661 raeburn 13512: }
1.1123 raeburn 13513: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 13514: my $extendedsubdir = $dirpath.'/'.$subdir;
13515: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 13516: my $result =
1.1126 raeburn 13517: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13518: if ($result !~ m|^/uploaded/|) {
13519: $output .= '<span class="LC_error">'
13520: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13521: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13522: .'</span><br />';
13523: next;
13524: } else {
13525: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13526: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13527: if ($context eq 'syllabus') {
13528: &Apache::lonnet::make_public_indefinitely($result);
13529: }
1.987 raeburn 13530: }
1.661 raeburn 13531: } else {
13532: # Save the file
13533: my $target = $env{'form.embedded_item_'.$i};
13534: my $fullpath = $dir_root.$dirpath.'/'.$path;
13535: my $dest = $fullpath.$fname;
13536: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13537: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13538: my $count;
13539: my $filepath = $dir_root;
1.1027 raeburn 13540: foreach my $subdir (@parts) {
13541: $filepath .= "/$subdir";
13542: if (!-e $filepath) {
1.661 raeburn 13543: mkdir($filepath,0770);
13544: }
13545: }
13546: my $fh;
13547: if (!open($fh,'>'.$dest)) {
13548: &Apache::lonnet::logthis('Failed to create '.$dest);
13549: $output .= '<span class="LC_error">'.
1.1071 raeburn 13550: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13551: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13552: '</span><br />';
13553: } else {
13554: if (!print $fh $env{'form.embedded_item_'.$i}) {
13555: &Apache::lonnet::logthis('Failed to write to '.$dest);
13556: $output .= '<span class="LC_error">'.
1.1071 raeburn 13557: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13558: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13559: '</span><br />';
13560: } else {
1.987 raeburn 13561: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13562: $url.'</span>').'<br />';
13563: unless ($context eq 'testbank') {
13564: $footer .= &mt('View embedded file: [_1]',
13565: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13566: }
13567: }
13568: close($fh);
13569: }
13570: }
13571: if ($env{'form.embedded_ref_'.$i}) {
13572: $pathchange{$i} = 1;
13573: }
13574: }
13575: if ($output) {
13576: $output = '<p>'.$output.'</p>';
13577: }
13578: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13579: $returnflag = 'ok';
1.1071 raeburn 13580: my $numpathchgs = scalar(keys(%pathchange));
13581: if ($numpathchgs > 0) {
1.987 raeburn 13582: if ($context eq 'portfolio') {
13583: $output .= '<p>'.&mt('or').'</p>';
13584: } elsif ($context eq 'testbank') {
1.1071 raeburn 13585: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13586: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13587: $returnflag = 'modify_orightml';
13588: }
13589: }
1.1071 raeburn 13590: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13591: }
13592:
13593: sub modify_html_form {
13594: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13595: my $end = 0;
13596: my $modifyform;
13597: if ($context eq 'upload_embedded') {
13598: return unless (ref($pathchange) eq 'HASH');
13599: if ($env{'form.number_embedded_items'}) {
13600: $end += $env{'form.number_embedded_items'};
13601: }
13602: if ($env{'form.number_pathchange_items'}) {
13603: $end += $env{'form.number_pathchange_items'};
13604: }
13605: if ($end) {
13606: for (my $i=0; $i<$end; $i++) {
13607: if ($i < $env{'form.number_embedded_items'}) {
13608: next unless($pathchange->{$i});
13609: }
13610: $modifyform .=
13611: &start_data_table_row().
13612: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13613: 'checked="checked" /></td>'.
13614: '<td>'.$env{'form.embedded_ref_'.$i}.
13615: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13616: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13617: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13618: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13619: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13620: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13621: '<td>'.$env{'form.embedded_orig_'.$i}.
13622: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13623: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13624: &end_data_table_row();
1.1071 raeburn 13625: }
1.987 raeburn 13626: }
13627: } else {
13628: $modifyform = $pathchgtable;
13629: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13630: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13631: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13632: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13633: }
13634: }
13635: if ($modifyform) {
1.1071 raeburn 13636: if ($actionurl eq '/adm/dependencies') {
13637: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13638: }
1.987 raeburn 13639: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13640: '<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".
13641: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13642: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13643: '</ol></p>'."\n".'<p>'.
13644: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13645: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13646: &start_data_table()."\n".
13647: &start_data_table_header_row().
13648: '<th>'.&mt('Change?').'</th>'.
13649: '<th>'.&mt('Current reference').'</th>'.
13650: '<th>'.&mt('Required reference').'</th>'.
13651: &end_data_table_header_row()."\n".
13652: $modifyform.
13653: &end_data_table().'<br />'."\n".$hiddenstate.
13654: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13655: '</form>'."\n";
13656: }
13657: return;
13658: }
13659:
13660: sub modify_html_refs {
1.1123 raeburn 13661: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13662: my $container;
13663: if ($context eq 'portfolio') {
13664: $container = $env{'form.container'};
13665: } elsif ($context eq 'coursedoc') {
13666: $container = $env{'form.primaryurl'};
1.1071 raeburn 13667: } elsif ($context eq 'manage_dependencies') {
13668: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13669: $container = "/$container";
1.1123 raeburn 13670: } elsif ($context eq 'syllabus') {
13671: $container = $url;
1.987 raeburn 13672: } else {
1.1027 raeburn 13673: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13674: }
13675: my (%allfiles,%codebase,$output,$content);
13676: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13677: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13678: if (wantarray) {
13679: return ('',0,0);
13680: } else {
13681: return;
13682: }
13683: }
13684: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13685: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13686: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13687: if (wantarray) {
13688: return ('',0,0);
13689: } else {
13690: return;
13691: }
13692: }
1.987 raeburn 13693: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13694: if ($content eq '-1') {
13695: if (wantarray) {
13696: return ('',0,0);
13697: } else {
13698: return;
13699: }
13700: }
1.987 raeburn 13701: } else {
1.1071 raeburn 13702: unless ($container =~ /^\Q$dir_root\E/) {
13703: if (wantarray) {
13704: return ('',0,0);
13705: } else {
13706: return;
13707: }
13708: }
1.1317 raeburn 13709: if (open(my $fh,'<',$container)) {
1.987 raeburn 13710: $content = join('', <$fh>);
13711: close($fh);
13712: } else {
1.1071 raeburn 13713: if (wantarray) {
13714: return ('',0,0);
13715: } else {
13716: return;
13717: }
1.987 raeburn 13718: }
13719: }
13720: my ($count,$codebasecount) = (0,0);
13721: my $mm = new File::MMagic;
13722: my $mime_type = $mm->checktype_contents($content);
13723: if ($mime_type eq 'text/html') {
13724: my $parse_result =
13725: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13726: \%codebase,\$content);
13727: if ($parse_result eq 'ok') {
13728: foreach my $i (@changes) {
13729: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13730: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13731: if ($allfiles{$ref}) {
13732: my $newname = $orig;
13733: my ($attrib_regexp,$codebase);
1.1006 raeburn 13734: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13735: if ($attrib_regexp =~ /:/) {
13736: $attrib_regexp =~ s/\:/|/g;
13737: }
13738: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13739: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13740: $count += $numchg;
1.1123 raeburn 13741: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13742: delete($allfiles{$ref});
1.987 raeburn 13743: }
13744: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13745: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13746: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13747: $codebasecount ++;
13748: }
13749: }
13750: }
1.1123 raeburn 13751: my $skiprewrites;
1.987 raeburn 13752: if ($count || $codebasecount) {
13753: my $saveresult;
1.1071 raeburn 13754: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13755: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13756: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13757: if ($url eq $container) {
13758: my ($fname) = ($container =~ m{/([^/]+)$});
13759: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13760: $count,'<span class="LC_filename">'.
1.1071 raeburn 13761: $fname.'</span>').'</p>';
1.987 raeburn 13762: } else {
13763: $output = '<p class="LC_error">'.
13764: &mt('Error: update failed for: [_1].',
13765: '<span class="LC_filename">'.
13766: $container.'</span>').'</p>';
13767: }
1.1123 raeburn 13768: if ($context eq 'syllabus') {
13769: unless ($saveresult eq 'ok') {
13770: $skiprewrites = 1;
13771: }
13772: }
1.987 raeburn 13773: } else {
1.1317 raeburn 13774: if (open(my $fh,'>',$container)) {
1.987 raeburn 13775: print $fh $content;
13776: close($fh);
13777: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13778: $count,'<span class="LC_filename">'.
13779: $container.'</span>').'</p>';
1.661 raeburn 13780: } else {
1.987 raeburn 13781: $output = '<p class="LC_error">'.
13782: &mt('Error: could not update [_1].',
13783: '<span class="LC_filename">'.
13784: $container.'</span>').'</p>';
1.661 raeburn 13785: }
13786: }
13787: }
1.1123 raeburn 13788: if (($context eq 'syllabus') && (!$skiprewrites)) {
13789: my ($actionurl,$state);
13790: $actionurl = "/public/$udom/$uname/syllabus";
13791: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13792: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13793: \%codebase,
13794: {'context' => 'rewrites',
13795: 'ignore_remote_references' => 1,});
13796: if (ref($mapping) eq 'HASH') {
13797: my $rewrites = 0;
13798: foreach my $key (keys(%{$mapping})) {
13799: next if ($key =~ m{^https?://});
13800: my $ref = $mapping->{$key};
13801: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13802: my $attrib;
13803: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13804: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13805: }
13806: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13807: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13808: $rewrites += $numchg;
13809: }
13810: }
13811: if ($rewrites) {
13812: my $saveresult;
13813: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13814: if ($url eq $container) {
13815: my ($fname) = ($container =~ m{/([^/]+)$});
13816: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13817: $count,'<span class="LC_filename">'.
13818: $fname.'</span>').'</p>';
13819: } else {
13820: $output .= '<p class="LC_error">'.
13821: &mt('Error: could not update links in [_1].',
13822: '<span class="LC_filename">'.
13823: $container.'</span>').'</p>';
13824:
13825: }
13826: }
13827: }
13828: }
1.987 raeburn 13829: } else {
13830: &logthis('Failed to parse '.$container.
13831: ' to modify references: '.$parse_result);
1.661 raeburn 13832: }
13833: }
1.1071 raeburn 13834: if (wantarray) {
13835: return ($output,$count,$codebasecount);
13836: } else {
13837: return $output;
13838: }
1.661 raeburn 13839: }
13840:
13841: sub check_for_existing {
13842: my ($path,$fname,$element) = @_;
13843: my ($state,$msg);
13844: if (-d $path.'/'.$fname) {
13845: $state = 'exists';
13846: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13847: } elsif (-e $path.'/'.$fname) {
13848: $state = 'exists';
13849: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13850: }
13851: if ($state eq 'exists') {
13852: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13853: }
13854: return ($state,$msg);
13855: }
13856:
13857: sub check_for_upload {
13858: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13859: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13860: my $filesize = length($env{'form.'.$element});
13861: if (!$filesize) {
13862: my $msg = '<span class="LC_error">'.
13863: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13864: '<span class="LC_filename">'.$fname.'</span>',
13865: $filesize).'<br />'.
1.1007 raeburn 13866: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13867: '</span>';
13868: return ('zero_bytes',$msg);
13869: }
13870: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13871: my $getpropath = 1;
1.1021 raeburn 13872: my ($dirlistref,$listerror) =
13873: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13874: my $found_file = 0;
13875: my $locked_file = 0;
1.991 raeburn 13876: my @lockers;
13877: my $navmap;
13878: if ($env{'request.course.id'}) {
13879: $navmap = Apache::lonnavmaps::navmap->new();
13880: }
1.1021 raeburn 13881: if (ref($dirlistref) eq 'ARRAY') {
13882: foreach my $line (@{$dirlistref}) {
13883: my ($file_name,$rest)=split(/\&/,$line,2);
13884: if ($file_name eq $fname){
13885: $file_name = $path.$file_name;
13886: if ($group ne '') {
13887: $file_name = $group.$file_name;
13888: }
13889: $found_file = 1;
13890: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13891: foreach my $lock (@lockers) {
13892: if (ref($lock) eq 'ARRAY') {
13893: my ($symb,$crsid) = @{$lock};
13894: if ($crsid eq $env{'request.course.id'}) {
13895: if (ref($navmap)) {
13896: my $res = $navmap->getBySymb($symb);
13897: foreach my $part (@{$res->parts()}) {
13898: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13899: unless (($slot_status == $res->RESERVED) ||
13900: ($slot_status == $res->RESERVED_LOCATION)) {
13901: $locked_file = 1;
13902: }
1.991 raeburn 13903: }
1.1021 raeburn 13904: } else {
13905: $locked_file = 1;
1.991 raeburn 13906: }
13907: } else {
13908: $locked_file = 1;
13909: }
13910: }
1.1021 raeburn 13911: }
13912: } else {
13913: my @info = split(/\&/,$rest);
13914: my $currsize = $info[6]/1000;
13915: if ($currsize < $filesize) {
13916: my $extra = $filesize - $currsize;
13917: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13918: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13919: &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 13920: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13921: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13922: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13923: return ('will_exceed_quota',$msg);
13924: }
1.984 raeburn 13925: }
13926: }
1.661 raeburn 13927: }
13928: }
13929: }
13930: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13931: my $msg = '<p class="LC_warning">'.
13932: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13933: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13934: return ('will_exceed_quota',$msg);
13935: } elsif ($found_file) {
13936: if ($locked_file) {
1.1179 bisitz 13937: my $msg = '<p class="LC_warning">';
1.661 raeburn 13938: $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 13939: $msg .= '</p>';
1.661 raeburn 13940: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13941: return ('file_locked',$msg);
13942: } else {
1.1179 bisitz 13943: my $msg = '<p class="LC_error">';
1.984 raeburn 13944: $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 13945: $msg .= '</p>';
1.984 raeburn 13946: return ('existingfile',$msg);
1.661 raeburn 13947: }
13948: }
13949: }
13950:
1.987 raeburn 13951: sub check_for_traversal {
13952: my ($path,$url,$toplevel) = @_;
13953: my @parts=split(/\//,$path);
13954: my $cleanpath;
13955: my $fullpath = $url;
13956: for (my $i=0;$i<@parts;$i++) {
13957: next if ($parts[$i] eq '.');
13958: if ($parts[$i] eq '..') {
13959: $fullpath =~ s{([^/]+/)$}{};
13960: } else {
13961: $fullpath .= $parts[$i].'/';
13962: }
13963: }
13964: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13965: $cleanpath = $1;
13966: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13967: my $curr_toprel = $1;
13968: my @parts = split(/\//,$curr_toprel);
13969: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13970: my @urlparts = split(/\//,$url_toprel);
13971: my $doubledots;
13972: my $startdiff = -1;
13973: for (my $i=0; $i<@urlparts; $i++) {
13974: if ($startdiff == -1) {
13975: unless ($urlparts[$i] eq $parts[$i]) {
13976: $startdiff = $i;
13977: $doubledots .= '../';
13978: }
13979: } else {
13980: $doubledots .= '../';
13981: }
13982: }
13983: if ($startdiff > -1) {
13984: $cleanpath = $doubledots;
13985: for (my $i=$startdiff; $i<@parts; $i++) {
13986: $cleanpath .= $parts[$i].'/';
13987: }
13988: }
13989: }
13990: $cleanpath =~ s{(/)$}{};
13991: return $cleanpath;
13992: }
1.31 albertel 13993:
1.1053 raeburn 13994: sub is_archive_file {
13995: my ($mimetype) = @_;
13996: if (($mimetype eq 'application/octet-stream') ||
13997: ($mimetype eq 'application/x-stuffit') ||
13998: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13999: return 1;
14000: }
14001: return;
14002: }
14003:
14004: sub decompress_form {
1.1065 raeburn 14005: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 14006: my %lt = &Apache::lonlocal::texthash (
14007: this => 'This file is an archive file.',
1.1067 raeburn 14008: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 14009: itsc => 'Its contents are as follows:',
1.1053 raeburn 14010: youm => 'You may wish to extract its contents.',
14011: extr => 'Extract contents',
1.1067 raeburn 14012: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
14013: proa => 'Process automatically?',
1.1053 raeburn 14014: yes => 'Yes',
14015: no => 'No',
1.1067 raeburn 14016: fold => 'Title for folder containing movie',
14017: movi => 'Title for page containing embedded movie',
1.1053 raeburn 14018: );
1.1065 raeburn 14019: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 14020: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 14021: my $info = &list_archive_contents($fileloc,\@paths);
14022: if (@paths) {
14023: foreach my $path (@paths) {
14024: $path =~ s{^/}{};
1.1067 raeburn 14025: if ($path =~ m{^([^/]+)/$}) {
14026: $topdir = $1;
14027: }
1.1065 raeburn 14028: if ($path =~ m{^([^/]+)/}) {
14029: $toplevel{$1} = $path;
14030: } else {
14031: $toplevel{$path} = $path;
14032: }
14033: }
14034: }
1.1067 raeburn 14035: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 14036: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 14037: "$topdir/media/",
14038: "$topdir/media/$topdir.mp4",
14039: "$topdir/media/FirstFrame.png",
14040: "$topdir/media/player.swf",
14041: "$topdir/media/swfobject.js",
14042: "$topdir/media/expressInstall.swf");
1.1197 raeburn 14043: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 14044: "$topdir/$topdir.mp4",
14045: "$topdir/$topdir\_config.xml",
14046: "$topdir/$topdir\_controller.swf",
14047: "$topdir/$topdir\_embed.css",
14048: "$topdir/$topdir\_First_Frame.png",
14049: "$topdir/$topdir\_player.html",
14050: "$topdir/$topdir\_Thumbnails.png",
14051: "$topdir/playerProductInstall.swf",
14052: "$topdir/scripts/",
14053: "$topdir/scripts/config_xml.js",
14054: "$topdir/scripts/handlebars.js",
14055: "$topdir/scripts/jquery-1.7.1.min.js",
14056: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
14057: "$topdir/scripts/modernizr.js",
14058: "$topdir/scripts/player-min.js",
14059: "$topdir/scripts/swfobject.js",
14060: "$topdir/skins/",
14061: "$topdir/skins/configuration_express.xml",
14062: "$topdir/skins/express_show/",
14063: "$topdir/skins/express_show/player-min.css",
14064: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 14065: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
14066: "$topdir/$topdir.mp4",
14067: "$topdir/$topdir\_config.xml",
14068: "$topdir/$topdir\_controller.swf",
14069: "$topdir/$topdir\_embed.css",
14070: "$topdir/$topdir\_First_Frame.png",
14071: "$topdir/$topdir\_player.html",
14072: "$topdir/$topdir\_Thumbnails.png",
14073: "$topdir/playerProductInstall.swf",
14074: "$topdir/scripts/",
14075: "$topdir/scripts/config_xml.js",
14076: "$topdir/scripts/techsmith-smart-player.min.js",
14077: "$topdir/skins/",
14078: "$topdir/skins/configuration_express.xml",
14079: "$topdir/skins/express_show/",
14080: "$topdir/skins/express_show/spritesheet.min.css",
14081: "$topdir/skins/express_show/spritesheet.png",
14082: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 14083: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 14084: if (@diffs == 0) {
1.1164 raeburn 14085: $is_camtasia = 6;
14086: } else {
1.1197 raeburn 14087: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 14088: if (@diffs == 0) {
14089: $is_camtasia = 8;
1.1197 raeburn 14090: } else {
14091: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
14092: if (@diffs == 0) {
14093: $is_camtasia = 8;
14094: }
1.1164 raeburn 14095: }
1.1067 raeburn 14096: }
14097: }
14098: my $output;
14099: if ($is_camtasia) {
14100: $output = <<"ENDCAM";
14101: <script type="text/javascript" language="Javascript">
14102: // <![CDATA[
14103:
14104: function camtasiaToggle() {
14105: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
14106: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 14107: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 14108: document.getElementById('camtasia_titles').style.display='block';
14109: } else {
14110: document.getElementById('camtasia_titles').style.display='none';
14111: }
14112: }
14113: }
14114: return;
14115: }
14116:
14117: // ]]>
14118: </script>
14119: <p>$lt{'camt'}</p>
14120: ENDCAM
1.1065 raeburn 14121: } else {
1.1067 raeburn 14122: $output = '<p>'.$lt{'this'};
14123: if ($info eq '') {
14124: $output .= ' '.$lt{'youm'}.'</p>'."\n";
14125: } else {
14126: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
14127: '<div><pre>'.$info.'</pre></div>';
14128: }
1.1065 raeburn 14129: }
1.1067 raeburn 14130: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 14131: my $duplicates;
14132: my $num = 0;
14133: if (ref($dirlist) eq 'ARRAY') {
14134: foreach my $item (@{$dirlist}) {
14135: if (ref($item) eq 'ARRAY') {
14136: if (exists($toplevel{$item->[0]})) {
14137: $duplicates .=
14138: &start_data_table_row().
14139: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
14140: 'value="0" checked="checked" />'.&mt('No').'</label>'.
14141: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
14142: 'value="1" />'.&mt('Yes').'</label>'.
14143: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
14144: '<td>'.$item->[0].'</td>';
14145: if ($item->[2]) {
14146: $duplicates .= '<td>'.&mt('Directory').'</td>';
14147: } else {
14148: $duplicates .= '<td>'.&mt('File').'</td>';
14149: }
14150: $duplicates .= '<td>'.$item->[3].'</td>'.
14151: '<td>'.
14152: &Apache::lonlocal::locallocaltime($item->[4]).
14153: '</td>'.
14154: &end_data_table_row();
14155: $num ++;
14156: }
14157: }
14158: }
14159: }
14160: my $itemcount;
14161: if (@paths > 0) {
14162: $itemcount = scalar(@paths);
14163: } else {
14164: $itemcount = 1;
14165: }
1.1067 raeburn 14166: if ($is_camtasia) {
14167: $output .= $lt{'auto'}.'<br />'.
14168: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 14169: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 14170: $lt{'yes'}.'</label> <label>'.
14171: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
14172: $lt{'no'}.'</label></span><br />'.
14173: '<div id="camtasia_titles" style="display:block">'.
14174: &Apache::lonhtmlcommon::start_pick_box().
14175: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
14176: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
14177: &Apache::lonhtmlcommon::row_closure().
14178: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
14179: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
14180: &Apache::lonhtmlcommon::row_closure(1).
14181: &Apache::lonhtmlcommon::end_pick_box().
14182: '</div>';
14183: }
1.1065 raeburn 14184: $output .=
14185: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 14186: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
14187: "\n";
1.1065 raeburn 14188: if ($duplicates ne '') {
14189: $output .= '<p><span class="LC_warning">'.
14190: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
14191: &start_data_table().
14192: &start_data_table_header_row().
14193: '<th>'.&mt('Overwrite?').'</th>'.
14194: '<th>'.&mt('Name').'</th>'.
14195: '<th>'.&mt('Type').'</th>'.
14196: '<th>'.&mt('Size').'</th>'.
14197: '<th>'.&mt('Last modified').'</th>'.
14198: &end_data_table_header_row().
14199: $duplicates.
14200: &end_data_table().
14201: '</p>';
14202: }
1.1067 raeburn 14203: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 14204: if (ref($hiddenelements) eq 'HASH') {
14205: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
14206: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
14207: }
14208: }
14209: $output .= <<"END";
1.1067 raeburn 14210: <br />
1.1053 raeburn 14211: <input type="submit" name="decompress" value="$lt{'extr'}" />
14212: </form>
14213: $noextract
14214: END
14215: return $output;
14216: }
14217:
1.1065 raeburn 14218: sub decompression_utility {
14219: my ($program) = @_;
14220: my @utilities = ('tar','gunzip','bunzip2','unzip');
14221: my $location;
14222: if (grep(/^\Q$program\E$/,@utilities)) {
14223: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
14224: '/usr/sbin/') {
14225: if (-x $dir.$program) {
14226: $location = $dir.$program;
14227: last;
14228: }
14229: }
14230: }
14231: return $location;
14232: }
14233:
14234: sub list_archive_contents {
14235: my ($file,$pathsref) = @_;
14236: my (@cmd,$output);
14237: my $needsregexp;
14238: if ($file =~ /\.zip$/) {
14239: @cmd = (&decompression_utility('unzip'),"-l");
14240: $needsregexp = 1;
14241: } elsif (($file =~ m/\.tar\.gz$/) ||
14242: ($file =~ /\.tgz$/)) {
14243: @cmd = (&decompression_utility('tar'),"-ztf");
14244: } elsif ($file =~ /\.tar\.bz2$/) {
14245: @cmd = (&decompression_utility('tar'),"-jtf");
14246: } elsif ($file =~ m|\.tar$|) {
14247: @cmd = (&decompression_utility('tar'),"-tf");
14248: }
14249: if (@cmd) {
14250: undef($!);
14251: undef($@);
14252: if (open(my $fh,"-|", @cmd, $file)) {
14253: while (my $line = <$fh>) {
14254: $output .= $line;
14255: chomp($line);
14256: my $item;
14257: if ($needsregexp) {
14258: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
14259: } else {
14260: $item = $line;
14261: }
14262: if ($item ne '') {
14263: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
14264: push(@{$pathsref},$item);
14265: }
14266: }
14267: }
14268: close($fh);
14269: }
14270: }
14271: return $output;
14272: }
14273:
1.1053 raeburn 14274: sub decompress_uploaded_file {
14275: my ($file,$dir) = @_;
14276: &Apache::lonnet::appenv({'cgi.file' => $file});
14277: &Apache::lonnet::appenv({'cgi.dir' => $dir});
14278: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
14279: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
14280: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
14281: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
14282: my $decompressed = $env{'cgi.decompressed'};
14283: &Apache::lonnet::delenv('cgi.file');
14284: &Apache::lonnet::delenv('cgi.dir');
14285: &Apache::lonnet::delenv('cgi.decompressed');
14286: return ($decompressed,$result);
14287: }
14288:
1.1055 raeburn 14289: sub process_decompression {
14290: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 14291: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
14292: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14293: &mt('Unexpected file path.').'</p>'."\n";
14294: }
14295: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
14296: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14297: &mt('Unexpected course context.').'</p>'."\n";
14298: }
1.1293 raeburn 14299: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 14300: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14301: &mt('Filename contained unexpected characters.').'</p>'."\n";
14302: }
1.1055 raeburn 14303: my ($dir,$error,$warning,$output);
1.1180 raeburn 14304: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 14305: $error = &mt('Filename not a supported archive file type.').
14306: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 14307: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
14308: } else {
14309: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14310: if ($docuhome eq 'no_host') {
14311: $error = &mt('Could not determine home server for course.');
14312: } else {
14313: my @ids=&Apache::lonnet::current_machine_ids();
14314: my $currdir = "$dir_root/$destination";
14315: if (grep(/^\Q$docuhome\E$/,@ids)) {
14316: $dir = &LONCAPA::propath($docudom,$docuname).
14317: "$dir_root/$destination";
14318: } else {
14319: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
14320: "$dir_root/$docudom/$docuname/$destination";
14321: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
14322: $error = &mt('Archive file not found.');
14323: }
14324: }
1.1065 raeburn 14325: my (@to_overwrite,@to_skip);
14326: if ($env{'form.archive_overwrite_total'} > 0) {
14327: my $total = $env{'form.archive_overwrite_total'};
14328: for (my $i=0; $i<$total; $i++) {
14329: if ($env{'form.archive_overwrite_'.$i} == 1) {
14330: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
14331: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
14332: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
14333: }
14334: }
14335: }
14336: my $numskip = scalar(@to_skip);
1.1292 raeburn 14337: my $numoverwrite = scalar(@to_overwrite);
14338: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 14339: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
14340: } elsif ($dir eq '') {
1.1055 raeburn 14341: $error = &mt('Directory containing archive file unavailable.');
14342: } elsif (!$error) {
1.1065 raeburn 14343: my ($decompressed,$display);
1.1292 raeburn 14344: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 14345: my $tempdir = time.'_'.$$.int(rand(10000));
14346: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 14347: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
14348: ($decompressed,$display) =
14349: &decompress_uploaded_file($file,"$dir/$tempdir");
14350: foreach my $item (@to_skip) {
14351: if (($item ne '') && ($item !~ /\.\./)) {
14352: if (-f "$dir/$tempdir/$item") {
14353: unlink("$dir/$tempdir/$item");
14354: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 14355: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 14356: }
14357: }
14358: }
14359: foreach my $item (@to_overwrite) {
14360: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
14361: if (($item ne '') && ($item !~ /\.\./)) {
14362: if (-f "$dir/$item") {
14363: unlink("$dir/$item");
14364: } elsif (-d "$dir/$item") {
1.1300 raeburn 14365: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 14366: }
14367: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
14368: }
1.1065 raeburn 14369: }
14370: }
1.1292 raeburn 14371: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 14372: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 14373: }
1.1065 raeburn 14374: }
14375: } else {
14376: ($decompressed,$display) =
14377: &decompress_uploaded_file($file,$dir);
14378: }
1.1055 raeburn 14379: if ($decompressed eq 'ok') {
1.1065 raeburn 14380: $output = '<p class="LC_info">'.
14381: &mt('Files extracted successfully from archive.').
14382: '</p>'."\n";
1.1055 raeburn 14383: my ($warning,$result,@contents);
14384: my ($newdirlistref,$newlisterror) =
14385: &Apache::lonnet::dirlist($currdir,$docudom,
14386: $docuname,1);
14387: my (%is_dir,%changes,@newitems);
14388: my $dirptr = 16384;
1.1065 raeburn 14389: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 14390: foreach my $dir_line (@{$newdirlistref}) {
14391: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 14392: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 14393: push(@newitems,$item);
14394: if ($dirptr&$testdir) {
14395: $is_dir{$item} = 1;
14396: }
14397: $changes{$item} = 1;
14398: }
14399: }
14400: }
14401: if (keys(%changes) > 0) {
14402: foreach my $item (sort(@newitems)) {
14403: if ($changes{$item}) {
14404: push(@contents,$item);
14405: }
14406: }
14407: }
14408: if (@contents > 0) {
1.1067 raeburn 14409: my $wantform;
14410: unless ($env{'form.autoextract_camtasia'}) {
14411: $wantform = 1;
14412: }
1.1056 raeburn 14413: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 14414: my ($count,$datatable) = &get_extracted($docudom,$docuname,
14415: $currdir,\%is_dir,
14416: \%children,\%parent,
1.1056 raeburn 14417: \@contents,\%dirorder,
14418: \%titles,$wantform);
1.1055 raeburn 14419: if ($datatable ne '') {
14420: $output .= &archive_options_form('decompressed',$datatable,
14421: $count,$hiddenelem);
1.1065 raeburn 14422: my $startcount = 6;
1.1055 raeburn 14423: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 14424: \%titles,\%children);
1.1055 raeburn 14425: }
1.1067 raeburn 14426: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 14427: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 14428: my %displayed;
14429: my $total = 1;
14430: $env{'form.archive_directory'} = [];
14431: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
14432: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
14433: $path =~ s{/$}{};
14434: my $item;
14435: if ($path ne '') {
14436: $item = "$path/$titles{$i}";
14437: } else {
14438: $item = $titles{$i};
14439: }
14440: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
14441: if ($item eq $contents[0]) {
14442: push(@{$env{'form.archive_directory'}},$i);
14443: $env{'form.archive_'.$i} = 'display';
14444: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
14445: $displayed{'folder'} = $i;
1.1164 raeburn 14446: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
14447: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 14448: $env{'form.archive_'.$i} = 'display';
14449: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
14450: $displayed{'web'} = $i;
14451: } else {
1.1164 raeburn 14452: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
14453: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
14454: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 14455: push(@{$env{'form.archive_directory'}},$i);
14456: }
14457: $env{'form.archive_'.$i} = 'dependency';
14458: }
14459: $total ++;
14460: }
14461: for (my $i=1; $i<$total; $i++) {
14462: next if ($i == $displayed{'web'});
14463: next if ($i == $displayed{'folder'});
14464: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
14465: }
14466: $env{'form.phase'} = 'decompress_cleanup';
14467: $env{'form.archivedelete'} = 1;
14468: $env{'form.archive_count'} = $total-1;
14469: $output .=
14470: &process_extracted_files('coursedocs',$docudom,
14471: $docuname,$destination,
14472: $dir_root,$hiddenelem);
14473: }
1.1055 raeburn 14474: } else {
14475: $warning = &mt('No new items extracted from archive file.');
14476: }
14477: } else {
14478: $output = $display;
14479: $error = &mt('An error occurred during extraction from the archive file.');
14480: }
14481: }
14482: }
14483: }
14484: if ($error) {
14485: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14486: $error.'</p>'."\n";
14487: }
14488: if ($warning) {
14489: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14490: }
14491: return $output;
14492: }
14493:
14494: sub get_extracted {
1.1056 raeburn 14495: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
14496: $titles,$wantform) = @_;
1.1055 raeburn 14497: my $count = 0;
14498: my $depth = 0;
14499: my $datatable;
1.1056 raeburn 14500: my @hierarchy;
1.1055 raeburn 14501: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 14502: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
14503: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 14504: foreach my $item (@{$contents}) {
14505: $count ++;
1.1056 raeburn 14506: @{$dirorder->{$count}} = @hierarchy;
14507: $titles->{$count} = $item;
1.1055 raeburn 14508: &archive_hierarchy($depth,$count,$parent,$children);
14509: if ($wantform) {
14510: $datatable .= &archive_row($is_dir->{$item},$item,
14511: $currdir,$depth,$count);
14512: }
14513: if ($is_dir->{$item}) {
14514: $depth ++;
1.1056 raeburn 14515: push(@hierarchy,$count);
14516: $parent->{$depth} = $count;
1.1055 raeburn 14517: $datatable .=
14518: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14519: \$depth,\$count,\@hierarchy,$dirorder,
14520: $children,$parent,$titles,$wantform);
1.1055 raeburn 14521: $depth --;
1.1056 raeburn 14522: pop(@hierarchy);
1.1055 raeburn 14523: }
14524: }
14525: return ($count,$datatable);
14526: }
14527:
14528: sub recurse_extracted_archive {
1.1056 raeburn 14529: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14530: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14531: my $result='';
1.1056 raeburn 14532: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14533: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14534: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14535: return $result;
14536: }
14537: my $dirptr = 16384;
14538: my ($newdirlistref,$newlisterror) =
14539: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14540: if (ref($newdirlistref) eq 'ARRAY') {
14541: foreach my $dir_line (@{$newdirlistref}) {
14542: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14543: unless ($item =~ /^\.+$/) {
14544: $$count ++;
1.1056 raeburn 14545: @{$dirorder->{$$count}} = @{$hierarchy};
14546: $titles->{$$count} = $item;
1.1055 raeburn 14547: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14548:
1.1055 raeburn 14549: my $is_dir;
14550: if ($dirptr&$testdir) {
14551: $is_dir = 1;
14552: }
14553: if ($wantform) {
14554: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14555: }
14556: if ($is_dir) {
14557: $$depth ++;
1.1056 raeburn 14558: push(@{$hierarchy},$$count);
14559: $parent->{$$depth} = $$count;
1.1055 raeburn 14560: $result .=
14561: &recurse_extracted_archive("$currdir/$item",$docudom,
14562: $docuname,$depth,$count,
1.1056 raeburn 14563: $hierarchy,$dirorder,$children,
14564: $parent,$titles,$wantform);
1.1055 raeburn 14565: $$depth --;
1.1056 raeburn 14566: pop(@{$hierarchy});
1.1055 raeburn 14567: }
14568: }
14569: }
14570: }
14571: return $result;
14572: }
14573:
14574: sub archive_hierarchy {
14575: my ($depth,$count,$parent,$children) =@_;
14576: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14577: if (exists($parent->{$depth})) {
14578: $children->{$parent->{$depth}} .= $count.':';
14579: }
14580: }
14581: return;
14582: }
14583:
14584: sub archive_row {
14585: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14586: my ($name) = ($item =~ m{([^/]+)$});
14587: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14588: 'display' => 'Add as file',
1.1055 raeburn 14589: 'dependency' => 'Include as dependency',
14590: 'discard' => 'Discard',
14591: );
14592: if ($is_dir) {
1.1059 raeburn 14593: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14594: }
1.1056 raeburn 14595: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14596: my $offset = 0;
1.1055 raeburn 14597: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14598: $offset ++;
1.1065 raeburn 14599: if ($action ne 'display') {
14600: $offset ++;
14601: }
1.1055 raeburn 14602: $output .= '<td><span class="LC_nobreak">'.
14603: '<label><input type="radio" name="archive_'.$count.
14604: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14605: my $text = $choices{$action};
14606: if ($is_dir) {
14607: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14608: if ($action eq 'display') {
1.1059 raeburn 14609: $text = &mt('Add as folder');
1.1055 raeburn 14610: }
1.1056 raeburn 14611: } else {
14612: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14613:
14614: }
14615: $output .= ' /> '.$choices{$action}.'</label></span>';
14616: if ($action eq 'dependency') {
14617: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14618: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14619: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14620: '<option value=""></option>'."\n".
14621: '</select>'."\n".
14622: '</div>';
1.1059 raeburn 14623: } elsif ($action eq 'display') {
14624: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14625: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14626: '</div>';
1.1055 raeburn 14627: }
1.1056 raeburn 14628: $output .= '</td>';
1.1055 raeburn 14629: }
14630: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14631: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14632: for (my $i=0; $i<$depth; $i++) {
14633: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14634: }
14635: if ($is_dir) {
14636: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14637: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14638: } else {
14639: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14640: }
14641: $output .= ' '.$name.'</td>'."\n".
14642: &end_data_table_row();
14643: return $output;
14644: }
14645:
14646: sub archive_options_form {
1.1065 raeburn 14647: my ($form,$display,$count,$hiddenelem) = @_;
14648: my %lt = &Apache::lonlocal::texthash(
14649: perm => 'Permanently remove archive file?',
14650: hows => 'How should each extracted item be incorporated in the course?',
14651: cont => 'Content actions for all',
14652: addf => 'Add as folder/file',
14653: incd => 'Include as dependency for a displayed file',
14654: disc => 'Discard',
14655: no => 'No',
14656: yes => 'Yes',
14657: save => 'Save',
14658: );
14659: my $output = <<"END";
14660: <form name="$form" method="post" action="">
14661: <p><span class="LC_nobreak">$lt{'perm'}
14662: <label>
14663: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14664: </label>
14665:
14666: <label>
14667: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14668: </span>
14669: </p>
14670: <input type="hidden" name="phase" value="decompress_cleanup" />
14671: <br />$lt{'hows'}
14672: <div class="LC_columnSection">
14673: <fieldset>
14674: <legend>$lt{'cont'}</legend>
14675: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14676: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14677: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14678: </fieldset>
14679: </div>
14680: END
14681: return $output.
1.1055 raeburn 14682: &start_data_table()."\n".
1.1065 raeburn 14683: $display."\n".
1.1055 raeburn 14684: &end_data_table()."\n".
14685: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14686: $hiddenelem.
1.1065 raeburn 14687: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14688: '</form>';
14689: }
14690:
14691: sub archive_javascript {
1.1056 raeburn 14692: my ($startcount,$numitems,$titles,$children) = @_;
14693: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14694: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14695: my $scripttag = <<START;
14696: <script type="text/javascript">
14697: // <![CDATA[
14698:
14699: function checkAll(form,prefix) {
14700: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14701: for (var i=0; i < form.elements.length; i++) {
14702: var id = form.elements[i].id;
14703: if ((id != '') && (id != undefined)) {
14704: if (idstr.test(id)) {
14705: if (form.elements[i].type == 'radio') {
14706: form.elements[i].checked = true;
1.1056 raeburn 14707: var nostart = i-$startcount;
1.1059 raeburn 14708: var offset = nostart%7;
14709: var count = (nostart-offset)/7;
1.1056 raeburn 14710: dependencyCheck(form,count,offset);
1.1055 raeburn 14711: }
14712: }
14713: }
14714: }
14715: }
14716:
14717: function propagateCheck(form,count) {
14718: if (count > 0) {
1.1059 raeburn 14719: var startelement = $startcount + ((count-1) * 7);
14720: for (var j=1; j<6; j++) {
14721: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14722: var item = startelement + j;
14723: if (form.elements[item].type == 'radio') {
14724: if (form.elements[item].checked) {
14725: containerCheck(form,count,j);
14726: break;
14727: }
1.1055 raeburn 14728: }
14729: }
14730: }
14731: }
14732: }
14733:
14734: numitems = $numitems
1.1056 raeburn 14735: var titles = new Array(numitems);
14736: var parents = new Array(numitems);
1.1055 raeburn 14737: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14738: parents[i] = new Array;
1.1055 raeburn 14739: }
1.1059 raeburn 14740: var maintitle = '$maintitle';
1.1055 raeburn 14741:
14742: START
14743:
1.1056 raeburn 14744: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14745: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14746: for (my $i=0; $i<@contents; $i ++) {
14747: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14748: }
14749: }
14750:
1.1056 raeburn 14751: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14752: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14753: }
14754:
1.1055 raeburn 14755: $scripttag .= <<END;
14756:
14757: function containerCheck(form,count,offset) {
14758: if (count > 0) {
1.1056 raeburn 14759: dependencyCheck(form,count,offset);
1.1059 raeburn 14760: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14761: form.elements[item].checked = true;
14762: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14763: if (parents[count].length > 0) {
14764: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14765: containerCheck(form,parents[count][j],offset);
14766: }
14767: }
14768: }
14769: }
14770: }
14771:
14772: function dependencyCheck(form,count,offset) {
14773: if (count > 0) {
1.1059 raeburn 14774: var chosen = (offset+$startcount)+7*(count-1);
14775: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14776: var currtype = form.elements[depitem].type;
14777: if (form.elements[chosen].value == 'dependency') {
14778: document.getElementById('arc_depon_'+count).style.display='block';
14779: form.elements[depitem].options.length = 0;
14780: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14781: for (var i=1; i<=numitems; i++) {
14782: if (i == count) {
14783: continue;
14784: }
1.1059 raeburn 14785: var startelement = $startcount + (i-1) * 7;
14786: for (var j=1; j<6; j++) {
14787: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14788: var item = startelement + j;
14789: if (form.elements[item].type == 'radio') {
14790: if (form.elements[item].checked) {
14791: if (form.elements[item].value == 'display') {
14792: var n = form.elements[depitem].options.length;
14793: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14794: }
14795: }
14796: }
14797: }
14798: }
14799: }
14800: } else {
14801: document.getElementById('arc_depon_'+count).style.display='none';
14802: form.elements[depitem].options.length = 0;
14803: form.elements[depitem].options[0] = new Option('Select','',true,true);
14804: }
1.1059 raeburn 14805: titleCheck(form,count,offset);
1.1056 raeburn 14806: }
14807: }
14808:
14809: function propagateSelect(form,count,offset) {
14810: if (count > 0) {
1.1065 raeburn 14811: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14812: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14813: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14814: if (parents[count].length > 0) {
14815: for (var j=0; j<parents[count].length; j++) {
14816: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14817: }
14818: }
14819: }
14820: }
14821: }
1.1056 raeburn 14822:
14823: function containerSelect(form,count,offset,picked) {
14824: if (count > 0) {
1.1065 raeburn 14825: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14826: if (form.elements[item].type == 'radio') {
14827: if (form.elements[item].value == 'dependency') {
14828: if (form.elements[item+1].type == 'select-one') {
14829: for (var i=0; i<form.elements[item+1].options.length; i++) {
14830: if (form.elements[item+1].options[i].value == picked) {
14831: form.elements[item+1].selectedIndex = i;
14832: break;
14833: }
14834: }
14835: }
14836: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14837: if (parents[count].length > 0) {
14838: for (var j=0; j<parents[count].length; j++) {
14839: containerSelect(form,parents[count][j],offset,picked);
14840: }
14841: }
14842: }
14843: }
14844: }
14845: }
14846: }
14847:
1.1059 raeburn 14848: function titleCheck(form,count,offset) {
14849: if (count > 0) {
14850: var chosen = (offset+$startcount)+7*(count-1);
14851: var depitem = $startcount + ((count-1) * 7) + 2;
14852: var currtype = form.elements[depitem].type;
14853: if (form.elements[chosen].value == 'display') {
14854: document.getElementById('arc_title_'+count).style.display='block';
14855: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14856: document.getElementById('archive_title_'+count).value=maintitle;
14857: }
14858: } else {
14859: document.getElementById('arc_title_'+count).style.display='none';
14860: if (currtype == 'text') {
14861: document.getElementById('archive_title_'+count).value='';
14862: }
14863: }
14864: }
14865: return;
14866: }
14867:
1.1055 raeburn 14868: // ]]>
14869: </script>
14870: END
14871: return $scripttag;
14872: }
14873:
14874: sub process_extracted_files {
1.1067 raeburn 14875: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14876: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14877: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14878: my @ids=&Apache::lonnet::current_machine_ids();
14879: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14880: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14881: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14882: if (grep(/^\Q$docuhome\E$/,@ids)) {
14883: $prefix = &LONCAPA::propath($docudom,$docuname);
14884: $pathtocheck = "$dir_root/$destination";
14885: $dir = $dir_root;
14886: $ishome = 1;
14887: } else {
14888: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14889: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14890: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14891: }
14892: my $currdir = "$dir_root/$destination";
14893: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14894: if ($env{'form.folderpath'}) {
14895: my @items = split('&',$env{'form.folderpath'});
14896: $folders{'0'} = $items[-2];
1.1099 raeburn 14897: if ($env{'form.folderpath'} =~ /\:1$/) {
14898: $containers{'0'}='page';
14899: } else {
14900: $containers{'0'}='sequence';
14901: }
1.1055 raeburn 14902: }
14903: my @archdirs = &get_env_multiple('form.archive_directory');
14904: if ($numitems) {
14905: for (my $i=1; $i<=$numitems; $i++) {
14906: my $path = $env{'form.archive_content_'.$i};
14907: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14908: my $item = $1;
14909: $toplevelitems{$item} = $i;
14910: if (grep(/^\Q$i\E$/,@archdirs)) {
14911: $is_dir{$item} = 1;
14912: }
14913: }
14914: }
14915: }
1.1067 raeburn 14916: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14917: if (keys(%toplevelitems) > 0) {
14918: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14919: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14920: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14921: }
1.1066 raeburn 14922: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14923: if ($numitems) {
14924: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14925: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14926: my $path = $env{'form.archive_content_'.$i};
14927: if ($path =~ /^\Q$pathtocheck\E/) {
14928: if ($env{'form.archive_'.$i} eq 'discard') {
14929: if ($prefix ne '' && $path ne '') {
14930: if (-e $prefix.$path) {
1.1066 raeburn 14931: if ((@archdirs > 0) &&
14932: (grep(/^\Q$i\E$/,@archdirs))) {
14933: $todeletedir{$prefix.$path} = 1;
14934: } else {
14935: $todelete{$prefix.$path} = 1;
14936: }
1.1055 raeburn 14937: }
14938: }
14939: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14940: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14941: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14942: $docstitle = $env{'form.archive_title_'.$i};
14943: if ($docstitle eq '') {
14944: $docstitle = $title;
14945: }
1.1055 raeburn 14946: $outer = 0;
1.1056 raeburn 14947: if (ref($dirorder{$i}) eq 'ARRAY') {
14948: if (@{$dirorder{$i}} > 0) {
14949: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14950: if ($env{'form.archive_'.$item} eq 'display') {
14951: $outer = $item;
14952: last;
14953: }
14954: }
14955: }
14956: }
14957: my ($errtext,$fatal) =
14958: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14959: '/'.$folders{$outer}.'.'.
14960: $containers{$outer});
14961: next if ($fatal);
14962: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14963: if ($context eq 'coursedocs') {
1.1056 raeburn 14964: $mapinner{$i} = time;
1.1055 raeburn 14965: $folders{$i} = 'default_'.$mapinner{$i};
14966: $containers{$i} = 'sequence';
14967: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14968: $folders{$i}.'.'.$containers{$i};
14969: my $newidx = &LONCAPA::map::getresidx();
14970: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14971: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14972: push(@LONCAPA::map::order,$newidx);
14973: my ($outtext,$errtext) =
14974: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14975: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14976: '.'.$containers{$outer},1,1);
1.1056 raeburn 14977: $newseqid{$i} = $newidx;
1.1067 raeburn 14978: unless ($errtext) {
1.1294 raeburn 14979: $result .= '<li>'.&mt('Folder: [_1] added to course',
14980: &HTML::Entities::encode($docstitle,'<>&"')).
14981: '</li>'."\n";
1.1067 raeburn 14982: }
1.1055 raeburn 14983: }
14984: } else {
14985: if ($context eq 'coursedocs') {
14986: my $newidx=&LONCAPA::map::getresidx();
14987: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14988: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14989: $title;
1.1392 raeburn 14990: if (($outer !~ /\D/) &&
14991: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14992: ($newidx !~ /\D/)) {
1.1294 raeburn 14993: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14994: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14995: }
14996: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14997: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14998: }
14999: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
15000: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
15001: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
15002: unless ($ishome) {
15003: my $fetch = "$newdest{$i}/$title";
15004: $fetch =~ s/^\Q$prefix$dir\E//;
15005: $prompttofetch{$fetch} = 1;
15006: }
1.1292 raeburn 15007: }
1.1067 raeburn 15008: }
1.1294 raeburn 15009: $LONCAPA::map::resources[$newidx]=
15010: $docstitle.':'.$url.':false:normal:res';
15011: push(@LONCAPA::map::order, $newidx);
15012: my ($outtext,$errtext)=
15013: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
15014: $docuname.'/'.$folders{$outer}.
15015: '.'.$containers{$outer},1,1);
15016: unless ($errtext) {
15017: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
15018: $result .= '<li>'.&mt('File: [_1] added to course',
15019: &HTML::Entities::encode($docstitle,'<>&"')).
15020: '</li>'."\n";
15021: }
1.1067 raeburn 15022: }
1.1294 raeburn 15023: } else {
15024: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
15025: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 15026: }
1.1055 raeburn 15027: }
15028: }
1.1086 raeburn 15029: }
15030: } else {
1.1294 raeburn 15031: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
15032: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 15033: }
15034: }
15035: for (my $i=1; $i<=$numitems; $i++) {
15036: next unless ($env{'form.archive_'.$i} eq 'dependency');
15037: my $path = $env{'form.archive_content_'.$i};
15038: if ($path =~ /^\Q$pathtocheck\E/) {
15039: my ($title) = ($path =~ m{/([^/]+)$});
15040: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
15041: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
15042: if (ref($dirorder{$i}) eq 'ARRAY') {
15043: my ($itemidx,$fullpath,$relpath);
15044: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
15045: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 15046: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 15047: if ($dirorder{$i}->[$j] eq $container) {
15048: $itemidx = $j;
1.1056 raeburn 15049: }
15050: }
1.1086 raeburn 15051: }
15052: if ($itemidx eq '') {
15053: $itemidx = 0;
15054: }
15055: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
15056: if ($mapinner{$referrer{$i}}) {
15057: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
15058: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
15059: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
15060: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
15061: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
15062: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
15063: if (!-e $fullpath) {
15064: mkdir($fullpath,0755);
1.1056 raeburn 15065: }
15066: }
1.1086 raeburn 15067: } else {
15068: last;
1.1056 raeburn 15069: }
1.1086 raeburn 15070: }
15071: }
15072: } elsif ($newdest{$referrer{$i}}) {
15073: $fullpath = $newdest{$referrer{$i}};
15074: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
15075: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
15076: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
15077: last;
15078: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
15079: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
15080: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
15081: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
15082: if (!-e $fullpath) {
15083: mkdir($fullpath,0755);
1.1056 raeburn 15084: }
15085: }
1.1086 raeburn 15086: } else {
15087: last;
1.1056 raeburn 15088: }
1.1055 raeburn 15089: }
15090: }
1.1086 raeburn 15091: if ($fullpath ne '') {
15092: if (-e "$prefix$path") {
1.1292 raeburn 15093: unless (rename("$prefix$path","$fullpath/$title")) {
15094: $warning .= &mt('Failed to rename dependency').'<br />';
15095: }
1.1086 raeburn 15096: }
15097: if (-e "$fullpath/$title") {
15098: my $showpath;
15099: if ($relpath ne '') {
15100: $showpath = "$relpath/$title";
15101: } else {
15102: $showpath = "/$title";
15103: }
1.1294 raeburn 15104: $result .= '<li>'.&mt('[_1] included as a dependency',
15105: &HTML::Entities::encode($showpath,'<>&"')).
15106: '</li>'."\n";
1.1292 raeburn 15107: unless ($ishome) {
15108: my $fetch = "$fullpath/$title";
15109: $fetch =~ s/^\Q$prefix$dir\E//;
15110: $prompttofetch{$fetch} = 1;
15111: }
1.1086 raeburn 15112: }
15113: }
1.1055 raeburn 15114: }
1.1086 raeburn 15115: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
15116: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 15117: &HTML::Entities::encode($path,'<>&"'),
15118: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
15119: '<br />';
1.1055 raeburn 15120: }
15121: } else {
1.1294 raeburn 15122: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 15123: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 15124: }
15125: }
15126: if (keys(%todelete)) {
15127: foreach my $key (keys(%todelete)) {
15128: unlink($key);
1.1066 raeburn 15129: }
15130: }
15131: if (keys(%todeletedir)) {
15132: foreach my $key (keys(%todeletedir)) {
15133: rmdir($key);
15134: }
15135: }
15136: foreach my $dir (sort(keys(%is_dir))) {
15137: if (($pathtocheck ne '') && ($dir ne '')) {
15138: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 15139: }
15140: }
1.1067 raeburn 15141: if ($result ne '') {
15142: $output .= '<ul>'."\n".
15143: $result."\n".
15144: '</ul>';
15145: }
15146: unless ($ishome) {
15147: my $replicationfail;
15148: foreach my $item (keys(%prompttofetch)) {
15149: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
15150: unless ($fetchresult eq 'ok') {
15151: $replicationfail .= '<li>'.$item.'</li>'."\n";
15152: }
15153: }
15154: if ($replicationfail) {
15155: $output .= '<p class="LC_error">'.
15156: &mt('Course home server failed to retrieve:').'<ul>'.
15157: $replicationfail.
15158: '</ul></p>';
15159: }
15160: }
1.1055 raeburn 15161: } else {
15162: $warning = &mt('No items found in archive.');
15163: }
15164: if ($error) {
15165: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
15166: $error.'</p>'."\n";
15167: }
15168: if ($warning) {
15169: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
15170: }
15171: return $output;
15172: }
15173:
1.1066 raeburn 15174: sub cleanup_empty_dirs {
15175: my ($path) = @_;
15176: if (($path ne '') && (-d $path)) {
15177: if (opendir(my $dirh,$path)) {
15178: my @dircontents = grep(!/^\./,readdir($dirh));
15179: my $numitems = 0;
15180: foreach my $item (@dircontents) {
15181: if (-d "$path/$item") {
1.1111 raeburn 15182: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 15183: if (-e "$path/$item") {
15184: $numitems ++;
15185: }
15186: } else {
15187: $numitems ++;
15188: }
15189: }
15190: if ($numitems == 0) {
15191: rmdir($path);
15192: }
15193: closedir($dirh);
15194: }
15195: }
15196: return;
15197: }
15198:
1.41 ng 15199: =pod
1.45 matthew 15200:
1.1162 raeburn 15201: =item * &get_folder_hierarchy()
1.1068 raeburn 15202:
15203: Provides hierarchy of names of folders/sub-folders containing the current
15204: item,
15205:
15206: Inputs: 3
15207: - $navmap - navmaps object
15208:
15209: - $map - url for map (either the trigger itself, or map containing
15210: the resource, which is the trigger).
15211:
15212: - $showitem - 1 => show title for map itself; 0 => do not show.
15213:
15214: Outputs: 1 @pathitems - array of folder/subfolder names.
15215:
15216: =cut
15217:
15218: sub get_folder_hierarchy {
15219: my ($navmap,$map,$showitem) = @_;
15220: my @pathitems;
15221: if (ref($navmap)) {
15222: my $mapres = $navmap->getResourceByUrl($map);
15223: if (ref($mapres)) {
15224: my $pcslist = $mapres->map_hierarchy();
15225: if ($pcslist ne '') {
15226: my @pcs = split(/,/,$pcslist);
15227: foreach my $pc (@pcs) {
15228: if ($pc == 1) {
1.1129 raeburn 15229: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 15230: } else {
15231: my $res = $navmap->getByMapPc($pc);
15232: if (ref($res)) {
15233: my $title = $res->compTitle();
15234: $title =~ s/\W+/_/g;
15235: if ($title ne '') {
15236: push(@pathitems,$title);
15237: }
15238: }
15239: }
15240: }
15241: }
1.1071 raeburn 15242: if ($showitem) {
15243: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 15244: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 15245: } else {
15246: my $maptitle = $mapres->compTitle();
15247: $maptitle =~ s/\W+/_/g;
15248: if ($maptitle ne '') {
15249: push(@pathitems,$maptitle);
15250: }
1.1068 raeburn 15251: }
15252: }
15253: }
15254: }
15255: return @pathitems;
15256: }
15257:
15258: =pod
15259:
1.1015 raeburn 15260: =item * &get_turnedin_filepath()
15261:
15262: Determines path in a user's portfolio file for storage of files uploaded
15263: to a specific essayresponse or dropbox item.
15264:
15265: Inputs: 3 required + 1 optional.
15266: $symb is symb for resource, $uname and $udom are for current user (required).
15267: $caller is optional (can be "submission", if routine is called when storing
15268: an upoaded file when "Submit Answer" button was pressed).
15269:
15270: Returns array containing $path and $multiresp.
15271: $path is path in portfolio. $multiresp is 1 if this resource contains more
15272: than one file upload item. Callers of routine should append partid as a
15273: subdirectory to $path in cases where $multiresp is 1.
15274:
15275: Called by: homework/essayresponse.pm and homework/structuretags.pm
15276:
15277: =cut
15278:
15279: sub get_turnedin_filepath {
15280: my ($symb,$uname,$udom,$caller) = @_;
15281: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
15282: my $turnindir;
15283: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
15284: $turnindir = $userhash{'turnindir'};
15285: my ($path,$multiresp);
15286: if ($turnindir eq '') {
15287: if ($caller eq 'submission') {
15288: $turnindir = &mt('turned in');
15289: $turnindir =~ s/\W+/_/g;
15290: my %newhash = (
15291: 'turnindir' => $turnindir,
15292: );
15293: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
15294: }
15295: }
15296: if ($turnindir ne '') {
15297: $path = '/'.$turnindir.'/';
15298: my ($multipart,$turnin,@pathitems);
15299: my $navmap = Apache::lonnavmaps::navmap->new();
15300: if (defined($navmap)) {
15301: my $mapres = $navmap->getResourceByUrl($map);
15302: if (ref($mapres)) {
15303: my $pcslist = $mapres->map_hierarchy();
15304: if ($pcslist ne '') {
15305: foreach my $pc (split(/,/,$pcslist)) {
15306: my $res = $navmap->getByMapPc($pc);
15307: if (ref($res)) {
15308: my $title = $res->compTitle();
15309: $title =~ s/\W+/_/g;
15310: if ($title ne '') {
1.1149 raeburn 15311: if (($pc > 1) && (length($title) > 12)) {
15312: $title = substr($title,0,12);
15313: }
1.1015 raeburn 15314: push(@pathitems,$title);
15315: }
15316: }
15317: }
15318: }
15319: my $maptitle = $mapres->compTitle();
15320: $maptitle =~ s/\W+/_/g;
15321: if ($maptitle ne '') {
1.1149 raeburn 15322: if (length($maptitle) > 12) {
15323: $maptitle = substr($maptitle,0,12);
15324: }
1.1015 raeburn 15325: push(@pathitems,$maptitle);
15326: }
15327: unless ($env{'request.state'} eq 'construct') {
15328: my $res = $navmap->getBySymb($symb);
15329: if (ref($res)) {
15330: my $partlist = $res->parts();
15331: my $totaluploads = 0;
15332: if (ref($partlist) eq 'ARRAY') {
15333: foreach my $part (@{$partlist}) {
15334: my @types = $res->responseType($part);
15335: my @ids = $res->responseIds($part);
15336: for (my $i=0; $i < scalar(@ids); $i++) {
15337: if ($types[$i] eq 'essay') {
15338: my $partid = $part.'_'.$ids[$i];
15339: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
15340: $totaluploads ++;
15341: }
15342: }
15343: }
15344: }
15345: if ($totaluploads > 1) {
15346: $multiresp = 1;
15347: }
15348: }
15349: }
15350: }
15351: } else {
15352: return;
15353: }
15354: } else {
15355: return;
15356: }
15357: my $restitle=&Apache::lonnet::gettitle($symb);
15358: $restitle =~ s/\W+/_/g;
15359: if ($restitle eq '') {
15360: $restitle = ($resurl =~ m{/[^/]+$});
15361: if ($restitle eq '') {
15362: $restitle = time;
15363: }
15364: }
1.1149 raeburn 15365: if (length($restitle) > 12) {
15366: $restitle = substr($restitle,0,12);
15367: }
1.1015 raeburn 15368: push(@pathitems,$restitle);
15369: $path .= join('/',@pathitems);
15370: }
15371: return ($path,$multiresp);
15372: }
15373:
15374: =pod
15375:
1.464 albertel 15376: =back
1.41 ng 15377:
1.112 bowersj2 15378: =head1 CSV Upload/Handling functions
1.38 albertel 15379:
1.41 ng 15380: =over 4
15381:
1.648 raeburn 15382: =item * &upfile_store($r)
1.41 ng 15383:
15384: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 15385: needs $env{'form.upfile'}
1.41 ng 15386: returns $datatoken to be put into hidden field
15387:
15388: =cut
1.31 albertel 15389:
15390: sub upfile_store {
15391: my $r=shift;
1.258 albertel 15392: $env{'form.upfile'}=~s/\r/\n/gs;
15393: $env{'form.upfile'}=~s/\f/\n/gs;
15394: $env{'form.upfile'}=~s/\n+/\n/gs;
15395: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 15396:
1.1299 raeburn 15397: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
15398: '_enroll_'.$env{'request.course.id'}.'_'.
15399: time.'_'.$$);
15400: return if ($datatoken eq '');
15401:
1.31 albertel 15402: {
1.158 raeburn 15403: my $datafile = $r->dir_config('lonDaemons').
15404: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15405: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 15406: print $fh $env{'form.upfile'};
1.158 raeburn 15407: close($fh);
15408: }
1.31 albertel 15409: }
15410: return $datatoken;
15411: }
15412:
1.56 matthew 15413: =pod
15414:
1.1290 raeburn 15415: =item * &load_tmp_file($r,$datatoken)
1.41 ng 15416:
15417: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 15418: $datatoken is the name to assign to the temporary file.
1.258 albertel 15419: sets $env{'form.upfile'} to the contents of the file
1.41 ng 15420:
15421: =cut
1.31 albertel 15422:
15423: sub load_tmp_file {
1.1290 raeburn 15424: my ($r,$datatoken) = @_;
15425: return if ($datatoken eq '');
1.31 albertel 15426: my @studentdata=();
15427: {
1.158 raeburn 15428: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 15429: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15430: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 15431: @studentdata=<$fh>;
15432: close($fh);
15433: }
1.31 albertel 15434: }
1.258 albertel 15435: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 15436: }
15437:
1.1290 raeburn 15438: sub valid_datatoken {
15439: my ($datatoken) = @_;
1.1325 raeburn 15440: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 15441: return $datatoken;
15442: }
15443: return;
15444: }
15445:
1.56 matthew 15446: =pod
15447:
1.648 raeburn 15448: =item * &upfile_record_sep()
1.41 ng 15449:
15450: Separate uploaded file into records
15451: returns array of records,
1.258 albertel 15452: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 15453:
15454: =cut
1.31 albertel 15455:
15456: sub upfile_record_sep {
1.258 albertel 15457: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 15458: } else {
1.248 albertel 15459: my @records;
1.258 albertel 15460: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 15461: if ($line=~/^\s*$/) { next; }
15462: push(@records,$line);
15463: }
15464: return @records;
1.31 albertel 15465: }
15466: }
15467:
1.56 matthew 15468: =pod
15469:
1.648 raeburn 15470: =item * &record_sep($record)
1.41 ng 15471:
1.258 albertel 15472: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 15473:
15474: =cut
15475:
1.263 www 15476: sub takeleft {
15477: my $index=shift;
15478: return substr('0000'.$index,-4,4);
15479: }
15480:
1.31 albertel 15481: sub record_sep {
15482: my $record=shift;
15483: my %components=();
1.258 albertel 15484: if ($env{'form.upfiletype'} eq 'xml') {
15485: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 15486: my $i=0;
1.356 albertel 15487: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 15488: $field=~s/^(\"|\')//;
15489: $field=~s/(\"|\')$//;
1.263 www 15490: $components{&takeleft($i)}=$field;
1.31 albertel 15491: $i++;
15492: }
1.258 albertel 15493: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 15494: my $i=0;
1.356 albertel 15495: foreach my $field (split(/\t/,$record)) {
1.31 albertel 15496: $field=~s/^(\"|\')//;
15497: $field=~s/(\"|\')$//;
1.263 www 15498: $components{&takeleft($i)}=$field;
1.31 albertel 15499: $i++;
15500: }
15501: } else {
1.561 www 15502: my $separator=',';
1.480 banghart 15503: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 15504: $separator=';';
1.480 banghart 15505: }
1.31 albertel 15506: my $i=0;
1.561 www 15507: # the character we are looking for to indicate the end of a quote or a record
15508: my $looking_for=$separator;
15509: # do not add the characters to the fields
15510: my $ignore=0;
15511: # we just encountered a separator (or the beginning of the record)
15512: my $just_found_separator=1;
15513: # store the field we are working on here
15514: my $field='';
15515: # work our way through all characters in record
15516: foreach my $character ($record=~/(.)/g) {
15517: if ($character eq $looking_for) {
15518: if ($character ne $separator) {
15519: # Found the end of a quote, again looking for separator
15520: $looking_for=$separator;
15521: $ignore=1;
15522: } else {
15523: # Found a separator, store away what we got
15524: $components{&takeleft($i)}=$field;
15525: $i++;
15526: $just_found_separator=1;
15527: $ignore=0;
15528: $field='';
15529: }
15530: next;
15531: }
15532: # single or double quotation marks after a separator indicate beginning of a quote
15533: # we are now looking for the end of the quote and need to ignore separators
15534: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15535: $looking_for=$character;
15536: next;
15537: }
15538: # ignore would be true after we reached the end of a quote
15539: if ($ignore) { next; }
15540: if (($just_found_separator) && ($character=~/\s/)) { next; }
15541: $field.=$character;
15542: $just_found_separator=0;
1.31 albertel 15543: }
1.561 www 15544: # catch the very last entry, since we never encountered the separator
15545: $components{&takeleft($i)}=$field;
1.31 albertel 15546: }
15547: return %components;
15548: }
15549:
1.144 matthew 15550: ######################################################
15551: ######################################################
15552:
1.56 matthew 15553: =pod
15554:
1.648 raeburn 15555: =item * &upfile_select_html()
1.41 ng 15556:
1.144 matthew 15557: Return HTML code to select a file from the users machine and specify
15558: the file type.
1.41 ng 15559:
15560: =cut
15561:
1.144 matthew 15562: ######################################################
15563: ######################################################
1.31 albertel 15564: sub upfile_select_html {
1.144 matthew 15565: my %Types = (
15566: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15567: semisv => &mt('Semicolon separated values'),
1.144 matthew 15568: space => &mt('Space separated'),
15569: tab => &mt('Tabulator separated'),
15570: # xml => &mt('HTML/XML'),
15571: );
15572: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15573: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15574: foreach my $type (sort(keys(%Types))) {
15575: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15576: }
15577: $Str .= "</select>\n";
15578: return $Str;
1.31 albertel 15579: }
15580:
1.301 albertel 15581: sub get_samples {
15582: my ($records,$toget) = @_;
15583: my @samples=({});
15584: my $got=0;
15585: foreach my $rec (@$records) {
15586: my %temp = &record_sep($rec);
15587: if (! grep(/\S/, values(%temp))) { next; }
15588: if (%temp) {
15589: $samples[$got]=\%temp;
15590: $got++;
15591: if ($got == $toget) { last; }
15592: }
15593: }
15594: return \@samples;
15595: }
15596:
1.144 matthew 15597: ######################################################
15598: ######################################################
15599:
1.56 matthew 15600: =pod
15601:
1.648 raeburn 15602: =item * &csv_print_samples($r,$records)
1.41 ng 15603:
15604: Prints a table of sample values from each column uploaded $r is an
15605: Apache Request ref, $records is an arrayref from
15606: &Apache::loncommon::upfile_record_sep
15607:
15608: =cut
15609:
1.144 matthew 15610: ######################################################
15611: ######################################################
1.31 albertel 15612: sub csv_print_samples {
15613: my ($r,$records) = @_;
1.662 bisitz 15614: my $samples = &get_samples($records,5);
1.301 albertel 15615:
1.594 raeburn 15616: $r->print(&mt('Samples').'<br />'.&start_data_table().
15617: &start_data_table_header_row());
1.356 albertel 15618: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15619: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15620: $r->print(&end_data_table_header_row());
1.301 albertel 15621: foreach my $hash (@$samples) {
1.594 raeburn 15622: $r->print(&start_data_table_row());
1.356 albertel 15623: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15624: $r->print('<td>');
1.356 albertel 15625: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15626: $r->print('</td>');
15627: }
1.594 raeburn 15628: $r->print(&end_data_table_row());
1.31 albertel 15629: }
1.594 raeburn 15630: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15631: }
15632:
1.144 matthew 15633: ######################################################
15634: ######################################################
15635:
1.56 matthew 15636: =pod
15637:
1.648 raeburn 15638: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15639:
15640: Prints a table to create associations between values and table columns.
1.144 matthew 15641:
1.41 ng 15642: $r is an Apache Request ref,
15643: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15644: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15645:
15646: =cut
15647:
1.144 matthew 15648: ######################################################
15649: ######################################################
1.31 albertel 15650: sub csv_print_select_table {
15651: my ($r,$records,$d) = @_;
1.301 albertel 15652: my $i=0;
15653: my $samples = &get_samples($records,1);
1.144 matthew 15654: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15655: &start_data_table().&start_data_table_header_row().
1.144 matthew 15656: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15657: '<th>'.&mt('Column').'</th>'.
15658: &end_data_table_header_row()."\n");
1.356 albertel 15659: foreach my $array_ref (@$d) {
15660: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15661: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15662:
1.875 bisitz 15663: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15664: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15665: $r->print('<option value="none"></option>');
1.356 albertel 15666: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15667: $r->print('<option value="'.$sample.'"'.
15668: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15669: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15670: }
1.594 raeburn 15671: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15672: $i++;
15673: }
1.594 raeburn 15674: $r->print(&end_data_table());
1.31 albertel 15675: $i--;
15676: return $i;
15677: }
1.56 matthew 15678:
1.144 matthew 15679: ######################################################
15680: ######################################################
15681:
1.56 matthew 15682: =pod
1.31 albertel 15683:
1.648 raeburn 15684: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15685:
15686: Prints a table of sample values from the upload and can make associate samples to internal names.
15687:
15688: $r is an Apache Request ref,
15689: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15690: $d is an array of 2 element arrays (internal name, displayed name)
15691:
15692: =cut
15693:
1.144 matthew 15694: ######################################################
15695: ######################################################
1.31 albertel 15696: sub csv_samples_select_table {
15697: my ($r,$records,$d) = @_;
15698: my $i=0;
1.144 matthew 15699: #
1.662 bisitz 15700: my $max_samples = 5;
15701: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15702: $r->print(&start_data_table().
15703: &start_data_table_header_row().'<th>'.
15704: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15705: &end_data_table_header_row());
1.301 albertel 15706:
15707: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15708: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15709: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15710: foreach my $option (@$d) {
15711: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15712: $r->print('<option value="'.$value.'"'.
1.253 albertel 15713: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15714: $display.'</option>');
1.31 albertel 15715: }
15716: $r->print('</select></td><td>');
1.662 bisitz 15717: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15718: if (defined($samples->[$line]{$key})) {
15719: $r->print($samples->[$line]{$key}."<br />\n");
15720: }
15721: }
1.594 raeburn 15722: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15723: $i++;
15724: }
1.594 raeburn 15725: $r->print(&end_data_table());
1.31 albertel 15726: $i--;
15727: return($i);
1.115 matthew 15728: }
15729:
1.144 matthew 15730: ######################################################
15731: ######################################################
15732:
1.115 matthew 15733: =pod
15734:
1.648 raeburn 15735: =item * &clean_excel_name($name)
1.115 matthew 15736:
15737: Returns a replacement for $name which does not contain any illegal characters.
15738:
15739: =cut
15740:
1.144 matthew 15741: ######################################################
15742: ######################################################
1.115 matthew 15743: sub clean_excel_name {
15744: my ($name) = @_;
15745: $name =~ s/[:\*\?\/\\]//g;
15746: if (length($name) > 31) {
15747: $name = substr($name,0,31);
15748: }
15749: return $name;
1.25 albertel 15750: }
1.84 albertel 15751:
1.85 albertel 15752: =pod
15753:
1.648 raeburn 15754: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15755:
15756: Returns either 1 or undef
15757:
15758: 1 if the part is to be hidden, undef if it is to be shown
15759:
15760: Arguments are:
15761:
15762: $id the id of the part to be checked
15763: $symb, optional the symb of the resource to check
15764: $udom, optional the domain of the user to check for
15765: $uname, optional the username of the user to check for
15766:
15767: =cut
1.84 albertel 15768:
15769: sub check_if_partid_hidden {
15770: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15771: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15772: $symb,$udom,$uname);
1.141 albertel 15773: my $truth=1;
15774: #if the string starts with !, then the list is the list to show not hide
15775: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15776: my @hiddenlist=split(/,/,$hiddenparts);
15777: foreach my $checkid (@hiddenlist) {
1.141 albertel 15778: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15779: }
1.141 albertel 15780: return !$truth;
1.84 albertel 15781: }
1.127 matthew 15782:
1.138 matthew 15783:
15784: ############################################################
15785: ############################################################
15786:
15787: =pod
15788:
1.157 matthew 15789: =back
15790:
1.138 matthew 15791: =head1 cgi-bin script and graphing routines
15792:
1.157 matthew 15793: =over 4
15794:
1.648 raeburn 15795: =item * &get_cgi_id()
1.138 matthew 15796:
15797: Inputs: none
15798:
15799: Returns an id which can be used to pass environment variables
15800: to various cgi-bin scripts. These environment variables will
15801: be removed from the users environment after a given time by
15802: the routine &Apache::lonnet::transfer_profile_to_env.
15803:
15804: =cut
15805:
15806: ############################################################
15807: ############################################################
1.152 albertel 15808: my $uniq=0;
1.136 matthew 15809: sub get_cgi_id {
1.154 albertel 15810: $uniq=($uniq+1)%100000;
1.280 albertel 15811: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15812: }
15813:
1.127 matthew 15814: ############################################################
15815: ############################################################
15816:
15817: =pod
15818:
1.648 raeburn 15819: =item * &DrawBarGraph()
1.127 matthew 15820:
1.138 matthew 15821: Facilitates the plotting of data in a (stacked) bar graph.
15822: Puts plot definition data into the users environment in order for
15823: graph.png to plot it. Returns an <img> tag for the plot.
15824: The bars on the plot are labeled '1','2',...,'n'.
15825:
15826: Inputs:
15827:
15828: =over 4
15829:
15830: =item $Title: string, the title of the plot
15831:
15832: =item $xlabel: string, text describing the X-axis of the plot
15833:
15834: =item $ylabel: string, text describing the Y-axis of the plot
15835:
15836: =item $Max: scalar, the maximum Y value to use in the plot
15837: If $Max is < any data point, the graph will not be rendered.
15838:
1.140 matthew 15839: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15840: they are plotted. If undefined, default values will be used.
15841:
1.178 matthew 15842: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15843:
1.138 matthew 15844: =item @Values: An array of array references. Each array reference holds data
15845: to be plotted in a stacked bar chart.
15846:
1.239 matthew 15847: =item If the final element of @Values is a hash reference the key/value
15848: pairs will be added to the graph definition.
15849:
1.138 matthew 15850: =back
15851:
15852: Returns:
15853:
15854: An <img> tag which references graph.png and the appropriate identifying
15855: information for the plot.
15856:
1.127 matthew 15857: =cut
15858:
15859: ############################################################
15860: ############################################################
1.134 matthew 15861: sub DrawBarGraph {
1.178 matthew 15862: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15863: #
15864: if (! defined($colors)) {
15865: $colors = ['#33ff00',
15866: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15867: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15868: ];
15869: }
1.228 matthew 15870: my $extra_settings = {};
15871: if (ref($Values[-1]) eq 'HASH') {
15872: $extra_settings = pop(@Values);
15873: }
1.127 matthew 15874: #
1.136 matthew 15875: my $identifier = &get_cgi_id();
15876: my $id = 'cgi.'.$identifier;
1.129 matthew 15877: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15878: return '';
15879: }
1.225 matthew 15880: #
15881: my @Labels;
15882: if (defined($labels)) {
15883: @Labels = @$labels;
15884: } else {
15885: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15886: push(@Labels,$i+1);
1.225 matthew 15887: }
15888: }
15889: #
1.129 matthew 15890: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15891: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15892: my %ValuesHash;
15893: my $NumSets=1;
15894: foreach my $array (@Values) {
15895: next if (! ref($array));
1.136 matthew 15896: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15897: join(',',@$array);
1.129 matthew 15898: }
1.127 matthew 15899: #
1.136 matthew 15900: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15901: if ($NumBars < 3) {
15902: $width = 120+$NumBars*32;
1.220 matthew 15903: $xskip = 1;
1.225 matthew 15904: $bar_width = 30;
15905: } elsif ($NumBars < 5) {
15906: $width = 120+$NumBars*20;
15907: $xskip = 1;
15908: $bar_width = 20;
1.220 matthew 15909: } elsif ($NumBars < 10) {
1.136 matthew 15910: $width = 120+$NumBars*15;
15911: $xskip = 1;
15912: $bar_width = 15;
15913: } elsif ($NumBars <= 25) {
15914: $width = 120+$NumBars*11;
15915: $xskip = 5;
15916: $bar_width = 8;
15917: } elsif ($NumBars <= 50) {
15918: $width = 120+$NumBars*8;
15919: $xskip = 5;
15920: $bar_width = 4;
15921: } else {
15922: $width = 120+$NumBars*8;
15923: $xskip = 5;
15924: $bar_width = 4;
15925: }
15926: #
1.137 matthew 15927: $Max = 1 if ($Max < 1);
15928: if ( int($Max) < $Max ) {
15929: $Max++;
15930: $Max = int($Max);
15931: }
1.127 matthew 15932: $Title = '' if (! defined($Title));
15933: $xlabel = '' if (! defined($xlabel));
15934: $ylabel = '' if (! defined($ylabel));
1.369 www 15935: $ValuesHash{$id.'.title'} = &escape($Title);
15936: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15937: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15938: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15939: $ValuesHash{$id.'.NumBars'} = $NumBars;
15940: $ValuesHash{$id.'.NumSets'} = $NumSets;
15941: $ValuesHash{$id.'.PlotType'} = 'bar';
15942: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15943: $ValuesHash{$id.'.height'} = $height;
15944: $ValuesHash{$id.'.width'} = $width;
15945: $ValuesHash{$id.'.xskip'} = $xskip;
15946: $ValuesHash{$id.'.bar_width'} = $bar_width;
15947: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15948: #
1.228 matthew 15949: # Deal with other parameters
15950: while (my ($key,$value) = each(%$extra_settings)) {
15951: $ValuesHash{$id.'.'.$key} = $value;
15952: }
15953: #
1.646 raeburn 15954: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15955: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15956: }
15957:
15958: ############################################################
15959: ############################################################
15960:
15961: =pod
15962:
1.648 raeburn 15963: =item * &DrawXYGraph()
1.137 matthew 15964:
1.138 matthew 15965: Facilitates the plotting of data in an XY graph.
15966: Puts plot definition data into the users environment in order for
15967: graph.png to plot it. Returns an <img> tag for the plot.
15968:
15969: Inputs:
15970:
15971: =over 4
15972:
15973: =item $Title: string, the title of the plot
15974:
15975: =item $xlabel: string, text describing the X-axis of the plot
15976:
15977: =item $ylabel: string, text describing the Y-axis of the plot
15978:
15979: =item $Max: scalar, the maximum Y value to use in the plot
15980: If $Max is < any data point, the graph will not be rendered.
15981:
15982: =item $colors: Array ref containing the hex color codes for the data to be
15983: plotted in. If undefined, default values will be used.
15984:
15985: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15986:
15987: =item $Ydata: Array ref containing Array refs.
1.185 www 15988: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15989:
15990: =item %Values: hash indicating or overriding any default values which are
15991: passed to graph.png.
15992: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15993:
15994: =back
15995:
15996: Returns:
15997:
15998: An <img> tag which references graph.png and the appropriate identifying
15999: information for the plot.
16000:
1.137 matthew 16001: =cut
16002:
16003: ############################################################
16004: ############################################################
16005: sub DrawXYGraph {
16006: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
16007: #
16008: # Create the identifier for the graph
16009: my $identifier = &get_cgi_id();
16010: my $id = 'cgi.'.$identifier;
16011: #
16012: $Title = '' if (! defined($Title));
16013: $xlabel = '' if (! defined($xlabel));
16014: $ylabel = '' if (! defined($ylabel));
16015: my %ValuesHash =
16016: (
1.369 www 16017: $id.'.title' => &escape($Title),
16018: $id.'.xlabel' => &escape($xlabel),
16019: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 16020: $id.'.y_max_value'=> $Max,
16021: $id.'.labels' => join(',',@$Xlabels),
16022: $id.'.PlotType' => 'XY',
16023: );
16024: #
16025: if (defined($colors) && ref($colors) eq 'ARRAY') {
16026: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16027: }
16028: #
16029: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
16030: return '';
16031: }
16032: my $NumSets=1;
1.138 matthew 16033: foreach my $array (@{$Ydata}){
1.137 matthew 16034: next if (! ref($array));
16035: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
16036: }
1.138 matthew 16037: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 16038: #
16039: # Deal with other parameters
16040: while (my ($key,$value) = each(%Values)) {
16041: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 16042: }
16043: #
1.646 raeburn 16044: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 16045: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
16046: }
16047:
16048: ############################################################
16049: ############################################################
16050:
16051: =pod
16052:
1.648 raeburn 16053: =item * &DrawXYYGraph()
1.138 matthew 16054:
16055: Facilitates the plotting of data in an XY graph with two Y axes.
16056: Puts plot definition data into the users environment in order for
16057: graph.png to plot it. Returns an <img> tag for the plot.
16058:
16059: Inputs:
16060:
16061: =over 4
16062:
16063: =item $Title: string, the title of the plot
16064:
16065: =item $xlabel: string, text describing the X-axis of the plot
16066:
16067: =item $ylabel: string, text describing the Y-axis of the plot
16068:
16069: =item $colors: Array ref containing the hex color codes for the data to be
16070: plotted in. If undefined, default values will be used.
16071:
16072: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
16073:
16074: =item $Ydata1: The first data set
16075:
16076: =item $Min1: The minimum value of the left Y-axis
16077:
16078: =item $Max1: The maximum value of the left Y-axis
16079:
16080: =item $Ydata2: The second data set
16081:
16082: =item $Min2: The minimum value of the right Y-axis
16083:
16084: =item $Max2: The maximum value of the left Y-axis
16085:
16086: =item %Values: hash indicating or overriding any default values which are
16087: passed to graph.png.
16088: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
16089:
16090: =back
16091:
16092: Returns:
16093:
16094: An <img> tag which references graph.png and the appropriate identifying
16095: information for the plot.
1.136 matthew 16096:
16097: =cut
16098:
16099: ############################################################
16100: ############################################################
1.137 matthew 16101: sub DrawXYYGraph {
16102: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
16103: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 16104: #
16105: # Create the identifier for the graph
16106: my $identifier = &get_cgi_id();
16107: my $id = 'cgi.'.$identifier;
16108: #
16109: $Title = '' if (! defined($Title));
16110: $xlabel = '' if (! defined($xlabel));
16111: $ylabel = '' if (! defined($ylabel));
16112: my %ValuesHash =
16113: (
1.369 www 16114: $id.'.title' => &escape($Title),
16115: $id.'.xlabel' => &escape($xlabel),
16116: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 16117: $id.'.labels' => join(',',@$Xlabels),
16118: $id.'.PlotType' => 'XY',
16119: $id.'.NumSets' => 2,
1.137 matthew 16120: $id.'.two_axes' => 1,
16121: $id.'.y1_max_value' => $Max1,
16122: $id.'.y1_min_value' => $Min1,
16123: $id.'.y2_max_value' => $Max2,
16124: $id.'.y2_min_value' => $Min2,
1.136 matthew 16125: );
16126: #
1.137 matthew 16127: if (defined($colors) && ref($colors) eq 'ARRAY') {
16128: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16129: }
16130: #
16131: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
16132: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 16133: return '';
16134: }
16135: my $NumSets=1;
1.137 matthew 16136: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 16137: next if (! ref($array));
16138: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 16139: }
16140: #
16141: # Deal with other parameters
16142: while (my ($key,$value) = each(%Values)) {
16143: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 16144: }
16145: #
1.646 raeburn 16146: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 16147: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 16148: }
16149:
16150: ############################################################
16151: ############################################################
16152:
16153: =pod
16154:
1.157 matthew 16155: =back
16156:
1.139 matthew 16157: =head1 Statistics helper routines?
16158:
16159: Bad place for them but what the hell.
16160:
1.157 matthew 16161: =over 4
16162:
1.648 raeburn 16163: =item * &chartlink()
1.139 matthew 16164:
16165: Returns a link to the chart for a specific student.
16166:
16167: Inputs:
16168:
16169: =over 4
16170:
16171: =item $linktext: The text of the link
16172:
16173: =item $sname: The students username
16174:
16175: =item $sdomain: The students domain
16176:
16177: =back
16178:
1.157 matthew 16179: =back
16180:
1.139 matthew 16181: =cut
16182:
16183: ############################################################
16184: ############################################################
16185: sub chartlink {
16186: my ($linktext, $sname, $sdomain) = @_;
16187: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 16188: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 16189: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 16190: '">'.$linktext.'</a>';
1.153 matthew 16191: }
16192:
16193: #######################################################
16194: #######################################################
16195:
16196: =pod
16197:
16198: =head1 Course Environment Routines
1.157 matthew 16199:
16200: =over 4
1.153 matthew 16201:
1.648 raeburn 16202: =item * &restore_course_settings()
1.153 matthew 16203:
1.648 raeburn 16204: =item * &store_course_settings()
1.153 matthew 16205:
16206: Restores/Store indicated form parameters from the course environment.
16207: Will not overwrite existing values of the form parameters.
16208:
16209: Inputs:
16210: a scalar describing the data (e.g. 'chart', 'problem_analysis')
16211:
16212: a hash ref describing the data to be stored. For example:
16213:
16214: %Save_Parameters = ('Status' => 'scalar',
16215: 'chartoutputmode' => 'scalar',
16216: 'chartoutputdata' => 'scalar',
16217: 'Section' => 'array',
1.373 raeburn 16218: 'Group' => 'array',
1.153 matthew 16219: 'StudentData' => 'array',
16220: 'Maps' => 'array');
16221:
16222: Returns: both routines return nothing
16223:
1.631 raeburn 16224: =back
16225:
1.153 matthew 16226: =cut
16227:
16228: #######################################################
16229: #######################################################
16230: sub store_course_settings {
1.496 albertel 16231: return &store_settings($env{'request.course.id'},@_);
16232: }
16233:
16234: sub store_settings {
1.153 matthew 16235: # save to the environment
16236: # appenv the same items, just to be safe
1.300 albertel 16237: my $udom = $env{'user.domain'};
16238: my $uname = $env{'user.name'};
1.496 albertel 16239: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16240: my %SaveHash;
16241: my %AppHash;
16242: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 16243: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 16244: my $envname = 'environment.'.$basename;
1.258 albertel 16245: if (exists($env{'form.'.$setting})) {
1.153 matthew 16246: # Save this value away
16247: if ($type eq 'scalar' &&
1.258 albertel 16248: (! exists($env{$envname}) ||
16249: $env{$envname} ne $env{'form.'.$setting})) {
16250: $SaveHash{$basename} = $env{'form.'.$setting};
16251: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 16252: } elsif ($type eq 'array') {
16253: my $stored_form;
1.258 albertel 16254: if (ref($env{'form.'.$setting})) {
1.153 matthew 16255: $stored_form = join(',',
16256: map {
1.369 www 16257: &escape($_);
1.258 albertel 16258: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 16259: } else {
16260: $stored_form =
1.369 www 16261: &escape($env{'form.'.$setting});
1.153 matthew 16262: }
16263: # Determine if the array contents are the same.
1.258 albertel 16264: if ($stored_form ne $env{$envname}) {
1.153 matthew 16265: $SaveHash{$basename} = $stored_form;
16266: $AppHash{$envname} = $stored_form;
16267: }
16268: }
16269: }
16270: }
16271: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 16272: $udom,$uname);
1.153 matthew 16273: if ($put_result !~ /^(ok|delayed)/) {
16274: &Apache::lonnet::logthis('unable to save form parameters, '.
16275: 'got error:'.$put_result);
16276: }
16277: # Make sure these settings stick around in this session, too
1.646 raeburn 16278: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 16279: return;
16280: }
16281:
16282: sub restore_course_settings {
1.499 albertel 16283: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 16284: }
16285:
16286: sub restore_settings {
16287: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16288: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 16289: next if (exists($env{'form.'.$setting}));
1.496 albertel 16290: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 16291: '.'.$setting;
1.258 albertel 16292: if (exists($env{$envname})) {
1.153 matthew 16293: if ($type eq 'scalar') {
1.258 albertel 16294: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 16295: } elsif ($type eq 'array') {
1.258 albertel 16296: $env{'form.'.$setting} = [
1.153 matthew 16297: map {
1.369 www 16298: &unescape($_);
1.258 albertel 16299: } split(',',$env{$envname})
1.153 matthew 16300: ];
16301: }
16302: }
16303: }
1.127 matthew 16304: }
16305:
1.618 raeburn 16306: #######################################################
16307: #######################################################
16308:
16309: =pod
16310:
16311: =head1 Domain E-mail Routines
16312:
16313: =over 4
16314:
1.648 raeburn 16315: =item * &build_recipient_list()
1.618 raeburn 16316:
1.1144 raeburn 16317: Build recipient lists for following types of e-mail:
1.766 raeburn 16318: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 16319: (d) Help requests, (e) Course requests needing approval, (f) loncapa
16320: module change checking, student/employee ID conflict checks, as
16321: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
16322: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 16323:
16324: Inputs:
1.619 raeburn 16325: defmail (scalar - email address of default recipient),
1.1144 raeburn 16326: mailing type (scalar: errormail, packagesmail, helpdeskmail,
16327: requestsmail, updatesmail, or idconflictsmail).
16328:
1.619 raeburn 16329: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 16330:
1.619 raeburn 16331: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 16332: i.e., predates configuration by DC via domainprefs.pm
16333:
16334: $requname username of requester (if mailing type is helpdeskmail)
16335:
16336: $requdom domain of requester (if mailing type is helpdeskmail)
16337:
16338: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
16339:
1.618 raeburn 16340:
1.655 raeburn 16341: Returns: comma separated list of addresses to which to send e-mail.
16342:
16343: =back
1.618 raeburn 16344:
16345: =cut
16346:
16347: ############################################################
16348: ############################################################
16349: sub build_recipient_list {
1.1297 raeburn 16350: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 16351: my @recipients;
1.1270 raeburn 16352: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 16353: my %domconfig =
1.1270 raeburn 16354: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 16355: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 16356: if (exists($domconfig{'contacts'}{$mailing})) {
16357: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
16358: my @contacts = ('adminemail','supportemail');
16359: foreach my $item (@contacts) {
16360: if ($domconfig{'contacts'}{$mailing}{$item}) {
16361: my $addr = $domconfig{'contacts'}{$item};
16362: if (!grep(/^\Q$addr\E$/,@recipients)) {
16363: push(@recipients,$addr);
16364: }
1.619 raeburn 16365: }
1.1270 raeburn 16366: }
16367: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
16368: if ($mailing eq 'helpdeskmail') {
16369: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
16370: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
16371: my @ok_bccs;
16372: foreach my $bcc (@bccs) {
16373: $bcc =~ s/^\s+//g;
16374: $bcc =~ s/\s+$//g;
16375: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16376: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16377: push(@ok_bccs,$bcc);
16378: }
16379: }
16380: }
16381: if (@ok_bccs > 0) {
16382: $allbcc = join(', ',@ok_bccs);
16383: }
16384: }
16385: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 16386: }
16387: }
1.766 raeburn 16388: } elsif ($origmail ne '') {
1.1270 raeburn 16389: $lastresort = $origmail;
1.618 raeburn 16390: }
1.1297 raeburn 16391: if ($mailing eq 'helpdeskmail') {
16392: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
16393: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
16394: my ($inststatus,$inststatus_checked);
16395: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
16396: ($env{'user.domain'} ne 'public')) {
16397: $inststatus_checked = 1;
16398: $inststatus = $env{'environment.inststatus'};
16399: }
16400: unless ($inststatus_checked) {
16401: if (($requname ne '') && ($requdom ne '')) {
16402: if (($requname =~ /^$match_username$/) &&
16403: ($requdom =~ /^$match_domain$/) &&
16404: (&Apache::lonnet::domain($requdom))) {
16405: my $requhome = &Apache::lonnet::homeserver($requname,
16406: $requdom);
16407: unless ($requhome eq 'no_host') {
16408: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
16409: $inststatus = $userenv{'inststatus'};
16410: $inststatus_checked = 1;
16411: }
16412: }
16413: }
16414: }
16415: unless ($inststatus_checked) {
16416: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
16417: my %srch = (srchby => 'email',
16418: srchdomain => $defdom,
16419: srchterm => $reqemail,
16420: srchtype => 'exact');
16421: my %srch_results = &Apache::lonnet::usersearch(\%srch);
16422: foreach my $uname (keys(%srch_results)) {
16423: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16424: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16425: $inststatus_checked = 1;
16426: last;
16427: }
16428: }
16429: unless ($inststatus_checked) {
16430: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
16431: if ($dirsrchres eq 'ok') {
16432: foreach my $uname (keys(%srch_results)) {
16433: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16434: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16435: $inststatus_checked = 1;
16436: last;
16437: }
16438: }
16439: }
16440: }
16441: }
16442: }
16443: if ($inststatus ne '') {
16444: foreach my $status (split(/\:/,$inststatus)) {
16445: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
16446: my @contacts = ('adminemail','supportemail');
16447: foreach my $item (@contacts) {
16448: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
16449: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
16450: if (!grep(/^\Q$addr\E$/,@recipients)) {
16451: push(@recipients,$addr);
16452: }
16453: }
16454: }
16455: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
16456: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
16457: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
16458: my @ok_bccs;
16459: foreach my $bcc (@bccs) {
16460: $bcc =~ s/^\s+//g;
16461: $bcc =~ s/\s+$//g;
16462: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16463: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16464: push(@ok_bccs,$bcc);
16465: }
16466: }
16467: }
16468: if (@ok_bccs > 0) {
16469: $allbcc = join(', ',@ok_bccs);
16470: }
16471: }
16472: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
16473: last;
16474: }
16475: }
16476: }
16477: }
16478: }
1.619 raeburn 16479: } elsif ($origmail ne '') {
1.1270 raeburn 16480: $lastresort = $origmail;
16481: }
1.1297 raeburn 16482: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 16483: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
16484: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
16485: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
16486: my %what = (
16487: perlvar => 1,
16488: );
16489: my $primary = &Apache::lonnet::domain($defdom,'primary');
16490: if ($primary) {
16491: my $gotaddr;
16492: my ($result,$returnhash) =
16493: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
16494: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
16495: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
16496: $lastresort = $returnhash->{'lonSupportEMail'};
16497: $gotaddr = 1;
16498: }
16499: }
16500: unless ($gotaddr) {
16501: my $uintdom = &Apache::lonnet::internet_dom($primary);
16502: my $intdom = &Apache::lonnet::internet_dom($lonhost);
16503: unless ($uintdom eq $intdom) {
16504: my %domconfig =
16505: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
16506: if (ref($domconfig{'contacts'}) eq 'HASH') {
16507: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
16508: my @contacts = ('adminemail','supportemail');
16509: foreach my $item (@contacts) {
16510: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
16511: my $addr = $domconfig{'contacts'}{$item};
16512: if (!grep(/^\Q$addr\E$/,@recipients)) {
16513: push(@recipients,$addr);
16514: }
16515: }
16516: }
16517: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16518: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16519: }
16520: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16521: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16522: my @ok_bccs;
16523: foreach my $bcc (@bccs) {
16524: $bcc =~ s/^\s+//g;
16525: $bcc =~ s/\s+$//g;
16526: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16527: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16528: push(@ok_bccs,$bcc);
16529: }
16530: }
16531: }
16532: if (@ok_bccs > 0) {
16533: $allbcc = join(', ',@ok_bccs);
16534: }
16535: }
16536: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16537: }
16538: }
16539: }
16540: }
16541: }
16542: }
1.618 raeburn 16543: }
1.688 raeburn 16544: if (defined($defmail)) {
16545: if ($defmail ne '') {
16546: push(@recipients,$defmail);
16547: }
1.618 raeburn 16548: }
16549: if ($otheremails) {
1.619 raeburn 16550: my @others;
16551: if ($otheremails =~ /,/) {
16552: @others = split(/,/,$otheremails);
1.618 raeburn 16553: } else {
1.619 raeburn 16554: push(@others,$otheremails);
16555: }
16556: foreach my $addr (@others) {
16557: if (!grep(/^\Q$addr\E$/,@recipients)) {
16558: push(@recipients,$addr);
16559: }
1.618 raeburn 16560: }
16561: }
1.1298 raeburn 16562: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16563: if ((!@recipients) && ($lastresort ne '')) {
16564: push(@recipients,$lastresort);
16565: }
16566: } elsif ($lastresort ne '') {
16567: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16568: push(@recipients,$lastresort);
16569: }
16570: }
1.1271 raeburn 16571: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16572: if (wantarray) {
16573: return ($recipientlist,$allbcc,$addtext);
16574: } else {
16575: return $recipientlist;
16576: }
1.618 raeburn 16577: }
16578:
1.127 matthew 16579: ############################################################
16580: ############################################################
1.154 albertel 16581:
1.655 raeburn 16582: =pod
16583:
1.1224 musolffc 16584: =over 4
16585:
1.1223 musolffc 16586: =item * &mime_email()
16587:
16588: Sends an email with a possible attachment
16589:
16590: Inputs:
16591:
16592: =over 4
16593:
16594: from - Sender's email address
16595:
1.1343 raeburn 16596: replyto - Reply-To email address
16597:
1.1223 musolffc 16598: to - Email address of recipient
16599:
16600: subject - Subject of email
16601:
16602: body - Body of email
16603:
16604: cc_string - Carbon copy email address
16605:
16606: bcc - Blind carbon copy email address
16607:
16608: attachment_path - Path of file to be attached
16609:
16610: file_name - Name of file to be attached
16611:
16612: attachment_text - The body of an attachment of type "TEXT"
16613:
16614: =back
16615:
16616: =back
16617:
16618: =cut
16619:
16620: ############################################################
16621: ############################################################
16622:
16623: sub mime_email {
1.1343 raeburn 16624: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16625: $file_name,$attachment_text) = @_;
16626:
1.1223 musolffc 16627: my $msg = MIME::Lite->new(
16628: From => $from,
16629: To => $to,
16630: Subject => $subject,
16631: Type =>'TEXT',
16632: Data => $body,
16633: );
1.1343 raeburn 16634: if ($replyto ne '') {
16635: $msg->add("Reply-To" => $replyto);
16636: }
1.1223 musolffc 16637: if ($cc_string ne '') {
16638: $msg->add("Cc" => $cc_string);
16639: }
16640: if ($bcc ne '') {
16641: $msg->add("Bcc" => $bcc);
16642: }
16643: $msg->attr("content-type" => "text/plain");
16644: $msg->attr("content-type.charset" => "UTF-8");
16645: # Attach file if given
16646: if ($attachment_path) {
16647: unless ($file_name) {
16648: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16649: }
16650: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16651: $msg->attach(Type => $type,
16652: Path => $attachment_path,
16653: Filename => $file_name
16654: );
16655: # Otherwise attach text if given
16656: } elsif ($attachment_text) {
16657: $msg->attach(Type => 'TEXT',
16658: Data => $attachment_text);
16659: }
16660: # Send it
16661: $msg->send('sendmail');
16662: }
16663:
16664: ############################################################
16665: ############################################################
16666:
16667: =pod
16668:
1.655 raeburn 16669: =head1 Course Catalog Routines
16670:
16671: =over 4
16672:
16673: =item * &gather_categories()
16674:
16675: Converts category definitions - keys of categories hash stored in
16676: coursecategories in configuration.db on the primary library server in a
16677: domain - to an array. Also generates javascript and idx hash used to
16678: generate Domain Coordinator interface for editing Course Categories.
16679:
16680: Inputs:
1.663 raeburn 16681:
1.655 raeburn 16682: categories (reference to hash of category definitions).
1.663 raeburn 16683:
1.655 raeburn 16684: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16685: categories and subcategories).
1.663 raeburn 16686:
1.655 raeburn 16687: idx (reference to hash of counters used in Domain Coordinator interface for
16688: editing Course Categories).
1.663 raeburn 16689:
1.655 raeburn 16690: jsarray (reference to array of categories used to create Javascript arrays for
16691: Domain Coordinator interface for editing Course Categories).
16692:
16693: Returns: nothing
16694:
16695: Side effects: populates cats, idx and jsarray.
16696:
16697: =cut
16698:
16699: sub gather_categories {
16700: my ($categories,$cats,$idx,$jsarray) = @_;
16701: my %counters;
16702: my $num = 0;
16703: foreach my $item (keys(%{$categories})) {
16704: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16705: if ($container eq '' && $depth == 0) {
16706: $cats->[$depth][$categories->{$item}] = $cat;
16707: } else {
16708: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16709: }
16710: my ($escitem,$tail) = split(/:/,$item,2);
16711: if ($counters{$tail} eq '') {
16712: $counters{$tail} = $num;
16713: $num ++;
16714: }
16715: if (ref($idx) eq 'HASH') {
16716: $idx->{$item} = $counters{$tail};
16717: }
16718: if (ref($jsarray) eq 'ARRAY') {
16719: push(@{$jsarray->[$counters{$tail}]},$item);
16720: }
16721: }
16722: return;
16723: }
16724:
16725: =pod
16726:
16727: =item * &extract_categories()
16728:
16729: Used to generate breadcrumb trails for course categories.
16730:
16731: Inputs:
1.663 raeburn 16732:
1.655 raeburn 16733: categories (reference to hash of category definitions).
1.663 raeburn 16734:
1.655 raeburn 16735: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16736: categories and subcategories).
1.663 raeburn 16737:
1.655 raeburn 16738: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16739:
1.655 raeburn 16740: allitems (reference to hash - key is category key
16741: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16742:
1.655 raeburn 16743: idx (reference to hash of counters used in Domain Coordinator interface for
16744: editing Course Categories).
1.663 raeburn 16745:
1.655 raeburn 16746: jsarray (reference to array of categories used to create Javascript arrays for
16747: Domain Coordinator interface for editing Course Categories).
16748:
1.665 raeburn 16749: subcats (reference to hash of arrays containing all subcategories within each
16750: category, -recursive)
16751:
1.1321 raeburn 16752: maxd (reference to hash used to hold max depth for all top-level categories).
16753:
1.655 raeburn 16754: Returns: nothing
16755:
16756: Side effects: populates trails and allitems hash references.
16757:
16758: =cut
16759:
16760: sub extract_categories {
1.1321 raeburn 16761: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16762: if (ref($categories) eq 'HASH') {
16763: &gather_categories($categories,$cats,$idx,$jsarray);
16764: if (ref($cats->[0]) eq 'ARRAY') {
16765: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16766: my $name = $cats->[0][$i];
16767: my $item = &escape($name).'::0';
16768: my $trailstr;
16769: if ($name eq 'instcode') {
16770: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16771: } elsif ($name eq 'communities') {
16772: $trailstr = &mt('Communities');
1.1239 raeburn 16773: } elsif ($name eq 'placement') {
16774: $trailstr = &mt('Placement Tests');
1.655 raeburn 16775: } else {
16776: $trailstr = $name;
16777: }
16778: if ($allitems->{$item} eq '') {
16779: push(@{$trails},$trailstr);
16780: $allitems->{$item} = scalar(@{$trails})-1;
16781: }
16782: my @parents = ($name);
16783: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16784: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16785: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16786: if (ref($subcats) eq 'HASH') {
16787: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16788: }
1.1321 raeburn 16789: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16790: }
16791: } else {
16792: if (ref($subcats) eq 'HASH') {
16793: $subcats->{$item} = [];
1.655 raeburn 16794: }
1.1321 raeburn 16795: if (ref($maxd) eq 'HASH') {
16796: $maxd->{$name} = 1;
16797: }
1.655 raeburn 16798: }
16799: }
16800: }
16801: }
16802: return;
16803: }
16804:
16805: =pod
16806:
1.1162 raeburn 16807: =item * &recurse_categories()
1.655 raeburn 16808:
16809: Recursively used to generate breadcrumb trails for course categories.
16810:
16811: Inputs:
1.663 raeburn 16812:
1.655 raeburn 16813: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16814: categories and subcategories).
1.663 raeburn 16815:
1.655 raeburn 16816: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16817:
16818: category (current course category, for which breadcrumb trail is being generated).
16819:
16820: trails (reference to array of breadcrumb trails for each category).
16821:
1.655 raeburn 16822: allitems (reference to hash - key is category key
16823: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16824:
1.655 raeburn 16825: parents (array containing containers directories for current category,
16826: back to top level).
16827:
16828: Returns: nothing
16829:
16830: Side effects: populates trails and allitems hash references
16831:
16832: =cut
16833:
16834: sub recurse_categories {
1.1321 raeburn 16835: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16836: my $shallower = $depth - 1;
16837: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16838: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16839: my $name = $cats->[$depth]{$category}[$k];
16840: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16841: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16842: if ($allitems->{$item} eq '') {
16843: push(@{$trails},$trailstr);
16844: $allitems->{$item} = scalar(@{$trails})-1;
16845: }
16846: my $deeper = $depth+1;
16847: push(@{$parents},$category);
1.665 raeburn 16848: if (ref($subcats) eq 'HASH') {
16849: my $subcat = &escape($name).':'.$category.':'.$depth;
16850: for (my $j=@{$parents}; $j>=0; $j--) {
16851: my $higher;
16852: if ($j > 0) {
16853: $higher = &escape($parents->[$j]).':'.
16854: &escape($parents->[$j-1]).':'.$j;
16855: } else {
16856: $higher = &escape($parents->[$j]).'::'.$j;
16857: }
16858: push(@{$subcats->{$higher}},$subcat);
16859: }
16860: }
16861: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16862: $subcats,$maxd);
1.655 raeburn 16863: pop(@{$parents});
16864: }
16865: } else {
16866: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16867: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16868: if ($allitems->{$item} eq '') {
16869: push(@{$trails},$trailstr);
16870: $allitems->{$item} = scalar(@{$trails})-1;
16871: }
1.1321 raeburn 16872: if (ref($maxd) eq 'HASH') {
16873: if ($depth > $maxd->{$parents->[0]}) {
16874: $maxd->{$parents->[0]} = $depth;
16875: }
16876: }
1.655 raeburn 16877: }
16878: return;
16879: }
16880:
1.663 raeburn 16881: =pod
16882:
1.1162 raeburn 16883: =item * &assign_categories_table()
1.663 raeburn 16884:
16885: Create a datatable for display of hierarchical categories in a domain,
16886: with checkboxes to allow a course to be categorized.
16887:
16888: Inputs:
16889:
16890: cathash - reference to hash of categories defined for the domain (from
16891: configuration.db)
16892:
16893: currcat - scalar with an & separated list of categories assigned to a course.
16894:
1.919 raeburn 16895: type - scalar contains course type (Course or Community).
16896:
1.1260 raeburn 16897: disabled - scalar (optional) contains disabled="disabled" if input elements are
16898: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16899:
1.663 raeburn 16900: Returns: $output (markup to be displayed)
16901:
16902: =cut
16903:
16904: sub assign_categories_table {
1.1259 raeburn 16905: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16906: my $output;
16907: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16908: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16909: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16910: $maxdepth = scalar(@cats);
16911: if (@cats > 0) {
16912: my $itemcount = 0;
16913: if (ref($cats[0]) eq 'ARRAY') {
16914: my @currcategories;
16915: if ($currcat ne '') {
16916: @currcategories = split('&',$currcat);
16917: }
1.919 raeburn 16918: my $table;
1.663 raeburn 16919: for (my $i=0; $i<@{$cats[0]}; $i++) {
16920: my $parent = $cats[0][$i];
1.919 raeburn 16921: next if ($parent eq 'instcode');
16922: if ($type eq 'Community') {
16923: next unless ($parent eq 'communities');
1.1239 raeburn 16924: } elsif ($type eq 'Placement') {
16925: next unless ($parent eq 'placement');
1.919 raeburn 16926: } else {
1.1239 raeburn 16927: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16928: }
1.663 raeburn 16929: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16930: my $item = &escape($parent).'::0';
16931: my $checked = '';
16932: if (@currcategories > 0) {
16933: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16934: $checked = ' checked="checked"';
1.663 raeburn 16935: }
16936: }
1.919 raeburn 16937: my $parent_title = $parent;
16938: if ($parent eq 'communities') {
16939: $parent_title = &mt('Communities');
1.1239 raeburn 16940: } elsif ($parent eq 'placement') {
16941: $parent_title = &mt('Placement Tests');
1.919 raeburn 16942: }
16943: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16944: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16945: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16946: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16947: my $depth = 1;
16948: push(@path,$parent);
1.1259 raeburn 16949: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16950: pop(@path);
1.919 raeburn 16951: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16952: $itemcount ++;
16953: }
1.919 raeburn 16954: if ($itemcount) {
16955: $output = &Apache::loncommon::start_data_table().
16956: $table.
16957: &Apache::loncommon::end_data_table();
16958: }
1.663 raeburn 16959: }
16960: }
16961: }
16962: return $output;
16963: }
16964:
16965: =pod
16966:
1.1162 raeburn 16967: =item * &assign_category_rows()
1.663 raeburn 16968:
16969: Create a datatable row for display of nested categories in a domain,
16970: with checkboxes to allow a course to be categorized,called recursively.
16971:
16972: Inputs:
16973:
16974: itemcount - track row number for alternating colors
16975:
16976: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16977: categories and subcategories.
16978:
16979: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16980:
16981: parent - parent of current category item
16982:
16983: path - Array containing all categories back up through the hierarchy from the
16984: current category to the top level.
16985:
16986: currcategories - reference to array of current categories assigned to the course
16987:
1.1260 raeburn 16988: disabled - scalar (optional) contains disabled="disabled" if input elements are
16989: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16990:
1.663 raeburn 16991: Returns: $output (markup to be displayed).
16992:
16993: =cut
16994:
16995: sub assign_category_rows {
1.1259 raeburn 16996: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16997: my ($text,$name,$item,$chgstr);
16998: if (ref($cats) eq 'ARRAY') {
16999: my $maxdepth = scalar(@{$cats});
17000: if (ref($cats->[$depth]) eq 'HASH') {
17001: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
17002: my $numchildren = @{$cats->[$depth]{$parent}};
17003: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 17004: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 17005: for (my $j=0; $j<$numchildren; $j++) {
17006: $name = $cats->[$depth]{$parent}[$j];
17007: $item = &escape($name).':'.&escape($parent).':'.$depth;
17008: my $deeper = $depth+1;
17009: my $checked = '';
17010: if (ref($currcategories) eq 'ARRAY') {
17011: if (@{$currcategories} > 0) {
17012: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 17013: $checked = ' checked="checked"';
1.663 raeburn 17014: }
17015: }
17016: }
1.664 raeburn 17017: $text .= '<tr><td><span class="LC_nobreak"><label>'.
17018: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 17019: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 17020: '<input type="hidden" name="catname" value="'.$name.'" />'.
17021: '</td><td>';
1.663 raeburn 17022: if (ref($path) eq 'ARRAY') {
17023: push(@{$path},$name);
1.1259 raeburn 17024: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 17025: pop(@{$path});
17026: }
17027: $text .= '</td></tr>';
17028: }
17029: $text .= '</table></td>';
17030: }
17031: }
17032: }
17033: return $text;
17034: }
17035:
1.1181 raeburn 17036: =pod
17037:
17038: =back
17039:
17040: =cut
17041:
1.655 raeburn 17042: ############################################################
17043: ############################################################
17044:
17045:
1.443 albertel 17046: sub commit_customrole {
1.1408 raeburn 17047: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
1.1399 raeburn 17048: my $result = &Apache::lonnet::assigncustomrole(
1.1408 raeburn 17049: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
17050: $context,$othdomby,$requester);
1.630 raeburn 17051: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 17052: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 17053: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
17054: if (wantarray) {
17055: return ($output,$result);
17056: } else {
17057: return $output;
17058: }
1.443 albertel 17059: }
17060:
17061: sub commit_standardrole {
1.1408 raeburn 17062: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
17063: $othdomby,$requester) = @_;
1.1399 raeburn 17064: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 17065: if ($context eq 'auto') {
17066: $linefeed = "\n";
17067: } else {
17068: $linefeed = "<br />\n";
17069: }
1.443 albertel 17070: if ($three eq 'st') {
1.1399 raeburn 17071: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1408 raeburn 17072: $one,$two,$sec,$context,$credits,$othdomby,
17073: $requester);
1.541 raeburn 17074: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 17075: ($result eq 'unknown_course') || ($result eq 'refused')) {
17076: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 17077: } else {
1.541 raeburn 17078: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 17079: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 17080: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
17081: if ($context eq 'auto') {
17082: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
17083: } else {
17084: $output .= '<b>'.$result.'</b>'.$linefeed.
17085: &mt('Add to classlist').': <b>ok</b>';
17086: }
17087: $output .= $linefeed;
1.443 albertel 17088: }
17089: } else {
17090: $output = &mt('Assigning').' '.$three.' in '.$url.
17091: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 17092: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1408 raeburn 17093: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
17094: '','',$context,$othdomby,$requester);
1.541 raeburn 17095: if ($context eq 'auto') {
17096: $output .= $result.$linefeed;
17097: } else {
17098: $output .= '<b>'.$result.'</b>'.$linefeed;
17099: }
1.443 albertel 17100: }
1.1399 raeburn 17101: if (wantarray) {
17102: return ($output,$result);
17103: } else {
17104: return $output;
17105: }
1.443 albertel 17106: }
17107:
17108: sub commit_studentrole {
1.1116 raeburn 17109: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
1.1408 raeburn 17110: $credits,$othdomby,$requester) = @_;
1.626 raeburn 17111: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 17112: if ($context eq 'auto') {
17113: $linefeed = "\n";
17114: } else {
17115: $linefeed = '<br />'."\n";
17116: }
1.443 albertel 17117: if (defined($one) && defined($two)) {
17118: my $cid=$one.'_'.$two;
17119: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
17120: my $secchange = 0;
17121: my $expire_role_result;
17122: my $modify_section_result;
1.628 raeburn 17123: if ($oldsec ne '-1') {
17124: if ($oldsec ne $sec) {
1.443 albertel 17125: $secchange = 1;
1.628 raeburn 17126: my $now = time;
1.443 albertel 17127: my $uurl='/'.$cid;
17128: $uurl=~s/\_/\//g;
17129: if ($oldsec) {
17130: $uurl.='/'.$oldsec;
17131: }
1.626 raeburn 17132: $oldsecurl = $uurl;
1.628 raeburn 17133: $expire_role_result =
1.1408 raeburn 17134: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
17135: '','','',$context,$othdomby,$requester);
17136: if ($env{'request.course.sec'} ne '') {
1.628 raeburn 17137: if ($expire_role_result eq 'refused') {
17138: my @roles = ('st');
17139: my @statuses = ('previous');
17140: my @roledoms = ($one);
17141: my $withsec = 1;
17142: my %roleshash =
17143: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
17144: \@statuses,\@roles,\@roledoms,$withsec);
17145: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
17146: my ($oldstart,$oldend) =
17147: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
17148: if ($oldend > 0 && $oldend <= $now) {
17149: $expire_role_result = 'ok';
17150: }
17151: }
17152: }
17153: }
1.443 albertel 17154: $result = $expire_role_result;
17155: }
17156: }
17157: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 17158: $modify_section_result =
17159: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
17160: undef,undef,undef,$sec,
17161: $end,$start,'','',$cid,
1.1408 raeburn 17162: '',$context,$credits,'',
17163: $othdomby,$requester);
1.443 albertel 17164: if ($modify_section_result =~ /^ok/) {
17165: if ($secchange == 1) {
1.628 raeburn 17166: if ($sec eq '') {
17167: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
17168: } else {
17169: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
17170: }
1.443 albertel 17171: } elsif ($oldsec eq '-1') {
1.628 raeburn 17172: if ($sec eq '') {
17173: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
17174: } else {
17175: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
17176: }
1.443 albertel 17177: } else {
1.628 raeburn 17178: if ($sec eq '') {
17179: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
17180: } else {
17181: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
17182: }
1.443 albertel 17183: }
17184: } else {
1.1115 raeburn 17185: if ($secchange) {
1.628 raeburn 17186: $$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;
17187: } else {
17188: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
17189: }
1.443 albertel 17190: }
17191: $result = $modify_section_result;
17192: } elsif ($secchange == 1) {
1.628 raeburn 17193: if ($oldsec eq '') {
1.1103 raeburn 17194: $$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 17195: } else {
17196: $$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;
17197: }
1.626 raeburn 17198: if ($expire_role_result eq 'refused') {
17199: my $newsecurl = '/'.$cid;
17200: $newsecurl =~ s/\_/\//g;
17201: if ($sec ne '') {
17202: $newsecurl.='/'.$sec;
17203: }
17204: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
17205: if ($sec eq '') {
17206: $$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;
17207: } else {
17208: $$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;
17209: }
17210: }
17211: }
1.443 albertel 17212: }
17213: } else {
1.626 raeburn 17214: $$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 17215: $result = "error: incomplete course id\n";
17216: }
17217: return $result;
17218: }
17219:
1.1108 raeburn 17220: sub show_role_extent {
17221: my ($scope,$context,$role) = @_;
17222: $scope =~ s{^/}{};
17223: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
17224: push(@courseroles,'co');
17225: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
17226: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
17227: $scope =~ s{/}{_};
17228: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
17229: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
17230: my ($audom,$auname) = split(/\//,$scope);
17231: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
17232: &Apache::loncommon::plainname($auname,$audom).'</span>');
17233: } else {
17234: $scope =~ s{/$}{};
17235: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
17236: &Apache::lonnet::domain($scope,'description').'</span>');
17237: }
17238: }
17239:
1.443 albertel 17240: ############################################################
17241: ############################################################
17242:
1.566 albertel 17243: sub check_clone {
1.578 raeburn 17244: my ($args,$linefeed) = @_;
1.566 albertel 17245: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
17246: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
17247: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 17248: my $clonetitle;
17249: my @clonemsg;
1.566 albertel 17250: my $can_clone = 0;
1.944 raeburn 17251: my $lctype = lc($args->{'crstype'});
1.908 raeburn 17252: if ($lctype ne 'community') {
17253: $lctype = 'course';
17254: }
1.566 albertel 17255: if ($clonehome eq 'no_host') {
1.944 raeburn 17256: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17257: push(@clonemsg,({
17258: mt => 'No new community created.',
17259: args => [],
17260: },
17261: {
17262: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
17263: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
17264: }));
1.908 raeburn 17265: } else {
1.1344 raeburn 17266: push(@clonemsg,({
17267: mt => 'No new course created.',
17268: args => [],
17269: },
17270: {
17271: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
17272: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17273: }));
17274: }
1.566 albertel 17275: } else {
17276: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 17277: $clonetitle = $clonedesc{'description'};
1.944 raeburn 17278: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 17279: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 17280: push(@clonemsg,({
17281: mt => 'No new community created.',
17282: args => [],
17283: },
17284: {
17285: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
17286: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17287: }));
17288: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 17289: }
17290: }
1.1262 raeburn 17291: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 17292: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 17293: $can_clone = 1;
17294: } else {
1.1221 raeburn 17295: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 17296: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 17297: if ($clonehash{'cloners'} eq '') {
17298: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
17299: if ($domdefs{'canclone'}) {
17300: unless ($domdefs{'canclone'} eq 'none') {
17301: if ($domdefs{'canclone'} eq 'domain') {
17302: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
17303: $can_clone = 1;
17304: }
17305: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17306: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
17307: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
17308: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
17309: $can_clone = 1;
17310: }
17311: }
17312: }
17313: }
1.578 raeburn 17314: } else {
1.1221 raeburn 17315: my @cloners = split(/,/,$clonehash{'cloners'});
17316: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 17317: $can_clone = 1;
1.1221 raeburn 17318: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 17319: $can_clone = 1;
1.1225 raeburn 17320: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
17321: $can_clone = 1;
1.1221 raeburn 17322: }
17323: unless ($can_clone) {
1.1225 raeburn 17324: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17325: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 17326: my (%gotdomdefaults,%gotcodedefaults);
17327: foreach my $cloner (@cloners) {
17328: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
17329: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
17330: my (%codedefaults,@code_order);
17331: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
17332: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
17333: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
17334: }
17335: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
17336: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
17337: }
17338: } else {
17339: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
17340: \%codedefaults,
17341: \@code_order);
17342: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
17343: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
17344: }
17345: if (@code_order > 0) {
17346: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
17347: $cloner,$clonehash{'internal.coursecode'},
17348: $args->{'crscode'})) {
17349: $can_clone = 1;
17350: last;
17351: }
17352: }
17353: }
17354: }
17355: }
1.1225 raeburn 17356: }
17357: }
17358: unless ($can_clone) {
17359: my $ccrole = 'cc';
17360: if ($args->{'crstype'} eq 'Community') {
17361: $ccrole = 'co';
17362: }
17363: my %roleshash =
17364: &Apache::lonnet::get_my_roles($args->{'ccuname'},
17365: $args->{'ccdomain'},
17366: 'userroles',['active'],[$ccrole],
17367: [$args->{'clonedomain'}]);
17368: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
17369: $can_clone = 1;
17370: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
17371: $args->{'ccuname'},$args->{'ccdomain'})) {
17372: $can_clone = 1;
1.1221 raeburn 17373: }
17374: }
17375: unless ($can_clone) {
17376: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17377: push(@clonemsg,({
17378: mt => 'No new community created.',
17379: args => [],
17380: },
17381: {
17382: 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]).',
17383: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17384: }));
1.942 raeburn 17385: } else {
1.1344 raeburn 17386: push(@clonemsg,({
17387: mt => 'No new course created.',
17388: args => [],
17389: },
17390: {
17391: 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]).',
17392: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17393: }));
1.1221 raeburn 17394: }
1.566 albertel 17395: }
1.578 raeburn 17396: }
1.566 albertel 17397: }
1.1344 raeburn 17398: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17399: }
17400:
1.444 albertel 17401: sub construct_course {
1.1262 raeburn 17402: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 17403: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
17404: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 17405: my $linefeed = '<br />'."\n";
17406: if ($context eq 'auto') {
17407: $linefeed = "\n";
17408: }
1.566 albertel 17409:
17410: #
17411: # Are we cloning?
17412: #
1.1344 raeburn 17413: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17414: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 17415: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 17416: if (!$can_clone) {
1.1344 raeburn 17417: return (0,$outcome,$clonemsgref);
1.566 albertel 17418: }
17419: }
17420:
1.444 albertel 17421: #
17422: # Open course
17423: #
1.1239 raeburn 17424: my $showncrstype;
17425: if ($args->{'crstype'} eq 'Placement') {
17426: $showncrstype = 'placement test';
17427: } else {
17428: $showncrstype = lc($args->{'crstype'});
17429: }
1.444 albertel 17430: my %cenv=();
17431: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
17432: $args->{'cdescr'},
17433: $args->{'curl'},
17434: $args->{'course_home'},
17435: $args->{'nonstandard'},
17436: $args->{'crscode'},
17437: $args->{'ccuname'}.':'.
17438: $args->{'ccdomain'},
1.882 raeburn 17439: $args->{'crstype'},
1.1344 raeburn 17440: $cnum,$context,$category,
17441: $callercontext);
1.444 albertel 17442:
17443: # Note: The testing routines depend on this being output; see
17444: # Utils::Course. This needs to at least be output as a comment
17445: # if anyone ever decides to not show this, and Utils::Course::new
17446: # will need to be suitably modified.
1.1344 raeburn 17447: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17448: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17449: } else {
17450: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17451: }
1.943 raeburn 17452: if ($$courseid =~ /^error:/) {
1.1344 raeburn 17453: return (0,$outcome,$clonemsgref);
1.943 raeburn 17454: }
17455:
1.444 albertel 17456: #
17457: # Check if created correctly
17458: #
1.479 albertel 17459: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 17460: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 17461: if ($crsuhome eq 'no_host') {
1.1344 raeburn 17462: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17463: $outcome .= &mt_user($user_lh,
17464: 'Course creation failed, unrecognized course home server.');
17465: } else {
17466: $outcome .= &mt('Course creation failed, unrecognized course home server.');
17467: }
17468: $outcome .= $linefeed;
17469: return (0,$outcome,$clonemsgref);
1.943 raeburn 17470: }
1.541 raeburn 17471: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 17472:
1.444 albertel 17473: #
1.566 albertel 17474: # Do the cloning
17475: #
1.1344 raeburn 17476: my @clonemsg;
1.566 albertel 17477: if ($can_clone && $cloneid) {
1.1344 raeburn 17478: push(@clonemsg,
17479: {
17480: mt => 'Created [_1] by cloning from [_2]',
17481: args => [$showncrstype,$clonetitle],
17482: });
1.566 albertel 17483: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 17484: # Copy all files
1.1344 raeburn 17485: my @info =
17486: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
17487: $args->{'dateshift'},$args->{'crscode'},
17488: $args->{'ccuname'}.':'.$args->{'ccdomain'},
17489: $args->{'tinyurls'});
17490: if (@info) {
17491: push(@clonemsg,@info);
17492: }
1.444 albertel 17493: # Restore URL
1.566 albertel 17494: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 17495: # Restore title
1.566 albertel 17496: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 17497: # Restore creation date, creator and creation context.
17498: $cenv{'internal.created'}=$oldcenv{'internal.created'};
17499: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
17500: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 17501: # Mark as cloned
1.566 albertel 17502: $cenv{'clonedfrom'}=$cloneid;
1.638 www 17503: # Need to clone grading mode
17504: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
17505: $cenv{'grading'}=$newenv{'grading'};
17506: # Do not clone these environment entries
17507: &Apache::lonnet::del('environment',
17508: ['default_enrollment_start_date',
17509: 'default_enrollment_end_date',
17510: 'question.email',
17511: 'policy.email',
17512: 'comment.email',
17513: 'pch.users.denied',
1.725 raeburn 17514: 'plc.users.denied',
17515: 'hidefromcat',
1.1121 raeburn 17516: 'checkforpriv',
1.1355 raeburn 17517: 'categories'],
1.638 www 17518: $$crsudom,$$crsunum);
1.1170 raeburn 17519: if ($args->{'textbook'}) {
17520: $cenv{'internal.textbook'} = $args->{'textbook'};
17521: }
1.444 albertel 17522: }
1.566 albertel 17523:
1.444 albertel 17524: #
17525: # Set environment (will override cloned, if existing)
17526: #
17527: my @sections = ();
17528: my @xlists = ();
17529: if ($args->{'crstype'}) {
17530: $cenv{'type'}=$args->{'crstype'};
17531: }
1.1371 raeburn 17532: if ($args->{'lti'}) {
17533: $cenv{'internal.lti'}=$args->{'lti'};
17534: }
1.444 albertel 17535: if ($args->{'crsid'}) {
17536: $cenv{'courseid'}=$args->{'crsid'};
17537: }
17538: if ($args->{'crscode'}) {
17539: $cenv{'internal.coursecode'}=$args->{'crscode'};
17540: }
17541: if ($args->{'crsquota'} ne '') {
17542: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17543: } else {
17544: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17545: }
17546: if ($args->{'ccuname'}) {
17547: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17548: ':'.$args->{'ccdomain'};
17549: } else {
17550: $cenv{'internal.courseowner'} = $args->{'curruser'};
17551: }
1.1116 raeburn 17552: if ($args->{'defaultcredits'}) {
17553: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17554: }
1.444 albertel 17555: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1412 raeburn 17556: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 17557: if ($args->{'crssections'}) {
17558: $cenv{'internal.sectionnums'} = '';
17559: if ($args->{'crssections'} =~ m/,/) {
17560: @sections = split/,/,$args->{'crssections'};
17561: } else {
17562: $sections[0] = $args->{'crssections'};
17563: }
17564: if (@sections > 0) {
17565: foreach my $item (@sections) {
17566: my ($sec,$gp) = split/:/,$item;
17567: my $class = $args->{'crscode'}.$sec;
17568: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17569: $cenv{'internal.sectionnums'} .= $item.',';
1.1412 raeburn 17570: if ($addcheck eq 'ok') {
17571: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17572: push(@oklcsecs,$gp);
17573: }
17574: } else {
1.1263 raeburn 17575: push(@badclasses,$class);
1.444 albertel 17576: }
17577: }
17578: $cenv{'internal.sectionnums'} =~ s/,$//;
17579: }
17580: }
17581: # do not hide course coordinator from staff listing,
17582: # even if privileged
17583: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17584: # add course coordinator's domain to domains to check for privileged users
17585: # if different to course domain
17586: if ($$crsudom ne $args->{'ccdomain'}) {
17587: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17588: }
1.444 albertel 17589: # add crosslistings
17590: if ($args->{'crsxlist'}) {
17591: $cenv{'internal.crosslistings'}='';
17592: if ($args->{'crsxlist'} =~ m/,/) {
17593: @xlists = split/,/,$args->{'crsxlist'};
17594: } else {
17595: $xlists[0] = $args->{'crsxlist'};
17596: }
17597: if (@xlists > 0) {
17598: foreach my $item (@xlists) {
17599: my ($xl,$gp) = split/:/,$item;
17600: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17601: $cenv{'internal.crosslistings'} .= $item.',';
1.1412 raeburn 17602: if ($addcheck eq 'ok') {
17603: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17604: push(@oklcsecs,$gp);
17605: }
17606: } else {
1.1263 raeburn 17607: push(@badclasses,$xl);
1.444 albertel 17608: }
17609: }
17610: $cenv{'internal.crosslistings'} =~ s/,$//;
17611: }
17612: }
17613: if ($args->{'autoadds'}) {
17614: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17615: }
17616: if ($args->{'autodrops'}) {
17617: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17618: }
17619: # check for notification of enrollment changes
17620: my @notified = ();
17621: if ($args->{'notify_owner'}) {
17622: if ($args->{'ccuname'} ne '') {
17623: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17624: }
17625: }
17626: if ($args->{'notify_dc'}) {
17627: if ($uname ne '') {
1.630 raeburn 17628: push(@notified,$uname.':'.$udom);
1.444 albertel 17629: }
17630: }
17631: if (@notified > 0) {
17632: my $notifylist;
17633: if (@notified > 1) {
17634: $notifylist = join(',',@notified);
17635: } else {
17636: $notifylist = $notified[0];
17637: }
17638: $cenv{'internal.notifylist'} = $notifylist;
17639: }
17640: if (@badclasses > 0) {
17641: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17642: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17643: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17644: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17645: );
1.1264 raeburn 17646: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17647: &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 17648: if ($context eq 'auto') {
17649: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17650: } else {
1.566 albertel 17651: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17652: }
17653: foreach my $item (@badclasses) {
1.541 raeburn 17654: if ($context eq 'auto') {
1.1261 raeburn 17655: $outcome .= " - $item\n";
1.541 raeburn 17656: } else {
1.1261 raeburn 17657: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17658: }
1.1261 raeburn 17659: }
17660: if ($context eq 'auto') {
17661: $outcome .= $linefeed;
17662: } else {
17663: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17664: }
1.444 albertel 17665: }
17666: if ($args->{'no_end_date'}) {
17667: $args->{'endaccess'} = 0;
17668: }
1.1412 raeburn 17669: # If an official course with institutional sections is created by cloning
17670: # an existing course, section-specific hiding of course totals in student's
17671: # view of grades as copied from cloned course, will be checked for valid
17672: # sections.
17673: if (($can_clone && $cloneid) &&
17674: ($cenv{'internal.coursecode'} ne '') &&
17675: ($cenv{'grading'} eq 'standard') &&
17676: ($cenv{'hidetotals'} ne '') &&
17677: ($cenv{'hidetotals'} ne 'all')) {
17678: my @hidesecs;
17679: my $deletehidetotals;
17680: if (@oklcsecs) {
17681: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
17682: if (grep(/^\Q$sec$/,@oklcsecs)) {
17683: push(@hidesecs,$sec);
17684: }
17685: }
17686: if (@hidesecs) {
17687: $cenv{'hidetotals'} = join(',',@hidesecs);
17688: } else {
17689: $deletehidetotals = 1;
17690: }
17691: } else {
17692: $deletehidetotals = 1;
17693: }
17694: if ($deletehidetotals) {
17695: delete($cenv{'hidetotals'});
17696: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
17697: }
17698: }
1.444 albertel 17699: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17700: $cenv{'internal.autoend'}=$args->{'enrollend'};
17701: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17702: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17703: if ($args->{'showphotos'}) {
17704: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17705: }
17706: $cenv{'internal.authtype'} = $args->{'authtype'};
17707: $cenv{'internal.autharg'} = $args->{'autharg'};
17708: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17709: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17710: 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');
17711: if ($context eq 'auto') {
17712: $outcome .= $krb_msg;
17713: } else {
1.566 albertel 17714: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17715: }
17716: $outcome .= $linefeed;
1.444 albertel 17717: }
17718: }
17719: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17720: if ($args->{'setpolicy'}) {
17721: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17722: }
17723: if ($args->{'setcontent'}) {
17724: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17725: }
1.1251 raeburn 17726: if ($args->{'setcomment'}) {
17727: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17728: }
1.444 albertel 17729: }
17730: if ($args->{'reshome'}) {
17731: $cenv{'reshome'}=$args->{'reshome'}.'/';
17732: $cenv{'reshome'}=~s/\/+$/\//;
17733: }
17734: #
17735: # course has keyed access
17736: #
17737: if ($args->{'setkeys'}) {
17738: $cenv{'keyaccess'}='yes';
17739: }
17740: # if specified, key authority is not course, but user
17741: # only active if keyaccess is yes
17742: if ($args->{'keyauth'}) {
1.487 albertel 17743: my ($user,$domain) = split(':',$args->{'keyauth'});
17744: $user = &LONCAPA::clean_username($user);
17745: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17746: if ($user ne '' && $domain ne '') {
1.487 albertel 17747: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17748: }
17749: }
17750:
1.1166 raeburn 17751: #
1.1167 raeburn 17752: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17753: #
17754: if ($args->{'uniquecode'}) {
17755: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17756: if ($code) {
17757: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17758: my %crsinfo =
17759: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17760: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17761: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17762: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17763: }
1.1166 raeburn 17764: if (ref($coderef)) {
17765: $$coderef = $code;
17766: }
17767: }
17768: }
17769:
1.444 albertel 17770: if ($args->{'disresdis'}) {
17771: $cenv{'pch.roles.denied'}='st';
17772: }
17773: if ($args->{'disablechat'}) {
17774: $cenv{'plc.roles.denied'}='st';
17775: }
17776:
17777: # Record we've not yet viewed the Course Initialization Helper for this
17778: # course
17779: $cenv{'course.helper.not.run'} = 1;
17780: #
17781: # Use new Randomseed
17782: #
17783: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17784: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17785: #
17786: # The encryption code and receipt prefix for this course
17787: #
17788: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17789: $cenv{'internal.encpref'}=100+int(9*rand(99));
17790: #
17791: # By default, use standard grading
17792: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17793:
1.541 raeburn 17794: $outcome .= $linefeed.&mt('Setting environment').': '.
17795: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17796: #
17797: # Open all assignments
17798: #
17799: if ($args->{'openall'}) {
1.1341 raeburn 17800: my $opendate = time;
17801: if ($args->{'openallfrom'} =~ /^\d+$/) {
17802: $opendate = $args->{'openallfrom'};
17803: }
1.444 albertel 17804: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17805: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17806: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17807: $outcome .= &mt('All assignments open starting [_1]',
17808: &Apache::lonlocal::locallocaltime($opendate)).': '.
17809: &Apache::lonnet::cput
17810: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17811: }
17812: #
17813: # Set first page
17814: #
17815: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17816: || ($cloneid)) {
17817: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17818:
17819: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17820: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17821:
1.444 albertel 17822: $outcome .= ($fatal?$errtext:'read ok').' - ';
17823: my $title; my $url;
17824: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17825: $title=&mt('Syllabus');
1.444 albertel 17826: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17827: } else {
1.963 raeburn 17828: $title=&mt('Table of Contents');
1.444 albertel 17829: $url='/adm/navmaps';
17830: }
1.445 albertel 17831:
17832: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17833: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17834:
17835: if ($errtext) { $fatal=2; }
1.541 raeburn 17836: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17837: }
1.566 albertel 17838:
1.1237 raeburn 17839: #
17840: # Set params for Placement Tests
17841: #
1.1239 raeburn 17842: if ($args->{'crstype'} eq 'Placement') {
17843: my %storecontent;
17844: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17845: my %defaults = (
17846: buttonshide => { value => 'yes',
17847: type => 'string_yesno',},
17848: type => { value => 'randomizetry',
17849: type => 'string_questiontype',},
17850: maxtries => { value => 1,
17851: type => 'int_pos',},
17852: problemstatus => { value => 'no',
17853: type => 'string_problemstatus',},
17854: );
17855: foreach my $key (keys(%defaults)) {
17856: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17857: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17858: }
1.1237 raeburn 17859: &Apache::lonnet::cput
17860: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17861: }
17862:
1.1344 raeburn 17863: return (1,$outcome,\@clonemsg);
1.444 albertel 17864: }
17865:
1.1166 raeburn 17866: sub make_unique_code {
17867: my ($cdom,$cnum) = @_;
17868: # get lock on uniquecodes db
17869: my $lockhash = {
17870: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17871: ':'.$env{'user.domain'},
17872: };
17873: my $tries = 0;
17874: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17875: my ($code,$error);
17876:
17877: while (($gotlock ne 'ok') && ($tries<3)) {
17878: $tries ++;
17879: sleep 1;
17880: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17881: }
17882: if ($gotlock eq 'ok') {
17883: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17884: my $gotcode;
17885: my $attempts = 0;
17886: while ((!$gotcode) && ($attempts < 100)) {
17887: $code = &generate_code();
17888: if (!exists($currcodes{$code})) {
17889: $gotcode = 1;
17890: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17891: $error = 'nostore';
17892: }
17893: }
17894: $attempts ++;
17895: }
17896: my @del_lock = ($cnum."\0".'uniquecodes');
17897: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17898: } else {
17899: $error = 'nolock';
17900: }
17901: return ($code,$error);
17902: }
17903:
17904: sub generate_code {
17905: my $code;
17906: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17907: for (my $i=0; $i<6; $i++) {
17908: my $lettnum = int (rand 2);
17909: my $item = '';
17910: if ($lettnum) {
17911: $item = $letts[int( rand(18) )];
17912: } else {
17913: $item = 1+int( rand(8) );
17914: }
17915: $code .= $item;
17916: }
17917: return $code;
17918: }
17919:
1.444 albertel 17920: ############################################################
17921: ############################################################
17922:
1.1237 raeburn 17923: # Community, Course and Placement Test
1.378 raeburn 17924: sub course_type {
17925: my ($cid) = @_;
17926: if (!defined($cid)) {
17927: $cid = $env{'request.course.id'};
17928: }
1.404 albertel 17929: if (defined($env{'course.'.$cid.'.type'})) {
17930: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17931: } else {
17932: return 'Course';
1.377 raeburn 17933: }
17934: }
1.156 albertel 17935:
1.406 raeburn 17936: sub group_term {
17937: my $crstype = &course_type();
17938: my %names = (
17939: 'Course' => 'group',
1.865 raeburn 17940: 'Community' => 'group',
1.1237 raeburn 17941: 'Placement' => 'group',
1.406 raeburn 17942: );
17943: return $names{$crstype};
17944: }
17945:
1.902 raeburn 17946: sub course_types {
1.1310 raeburn 17947: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17948: my %typename = (
17949: official => 'Official course',
17950: unofficial => 'Unofficial course',
17951: community => 'Community',
1.1165 raeburn 17952: textbook => 'Textbook course',
1.1237 raeburn 17953: placement => 'Placement test',
1.1310 raeburn 17954: lti => 'LTI provider',
1.902 raeburn 17955: );
17956: return (\@types,\%typename);
17957: }
17958:
1.156 albertel 17959: sub icon {
17960: my ($file)=@_;
1.505 albertel 17961: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17962: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17963: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17964: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17965: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17966: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17967: $curfext.".gif") {
17968: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17969: $curfext.".gif";
17970: }
17971: }
1.249 albertel 17972: return &lonhttpdurl($iconname);
1.154 albertel 17973: }
1.84 albertel 17974:
1.575 albertel 17975: sub lonhttpdurl {
1.692 www 17976: #
17977: # Had been used for "small fry" static images on separate port 8080.
17978: # Modify here if lightweight http functionality desired again.
17979: # Currently eliminated due to increasing firewall issues.
17980: #
1.575 albertel 17981: my ($url)=@_;
1.692 www 17982: return $url;
1.215 albertel 17983: }
17984:
1.213 albertel 17985: sub connection_aborted {
17986: my ($r)=@_;
17987: $r->print(" ");$r->rflush();
17988: my $c = $r->connection;
17989: return $c->aborted();
17990: }
17991:
1.221 foxr 17992: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17993: # strings as 'strings'.
17994: sub escape_single {
1.221 foxr 17995: my ($input) = @_;
1.223 albertel 17996: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17997: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17998: return $input;
17999: }
1.223 albertel 18000:
1.222 foxr 18001: # Same as escape_single, but escape's "'s This
18002: # can be used for "strings"
18003: sub escape_double {
18004: my ($input) = @_;
18005: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
18006: $input =~ s/\"/\\\"/g; # Esacpe the "s....
18007: return $input;
18008: }
1.223 albertel 18009:
1.222 foxr 18010: # Escapes the last element of a full URL.
18011: sub escape_url {
18012: my ($url) = @_;
1.238 raeburn 18013: my @urlslices = split(/\//, $url,-1);
1.369 www 18014: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 18015: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 18016: }
1.462 albertel 18017:
1.820 raeburn 18018: sub compare_arrays {
18019: my ($arrayref1,$arrayref2) = @_;
18020: my (@difference,%count);
18021: @difference = ();
18022: %count = ();
18023: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
18024: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
18025: foreach my $element (keys(%count)) {
18026: if ($count{$element} == 1) {
18027: push(@difference,$element);
18028: }
18029: }
18030: }
18031: return @difference;
18032: }
18033:
1.1322 raeburn 18034: sub lon_status_items {
18035: my %defaults = (
18036: E => 100,
18037: W => 4,
18038: N => 1,
1.1324 raeburn 18039: U => 5,
1.1322 raeburn 18040: threshold => 200,
18041: sysmail => 2500,
18042: );
18043: my %names = (
18044: E => 'Errors',
18045: W => 'Warnings',
18046: N => 'Notices',
1.1324 raeburn 18047: U => 'Unsent',
1.1322 raeburn 18048: );
18049: return (\%defaults,\%names);
18050: }
18051:
1.817 bisitz 18052: # -------------------------------------------------------- Initialize user login
1.462 albertel 18053: sub init_user_environment {
1.463 albertel 18054: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 18055: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
18056:
18057: my $public=($username eq 'public' && $domain eq 'public');
18058:
1.1415 raeburn 18059: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
18060: $coauthorenv);
1.462 albertel 18061: my $now=time;
18062:
18063: if ($public) {
18064: my $max_public=100;
18065: my $oldest;
18066: my $oldest_time=0;
18067: for(my $next=1;$next<=$max_public;$next++) {
18068: if (-e $lonids."/publicuser_$next.id") {
18069: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
18070: if ($mtime<$oldest_time || !$oldest_time) {
18071: $oldest_time=$mtime;
18072: $oldest=$next;
18073: }
18074: } else {
18075: $cookie="publicuser_$next";
18076: last;
18077: }
18078: }
18079: if (!$cookie) { $cookie="publicuser_$oldest"; }
18080: } else {
1.1275 raeburn 18081: # See if old ID present, if so, remove if this isn't a robot,
18082: # killing any existing non-robot sessions
1.463 albertel 18083: if (!$args->{'robot'}) {
18084: opendir(DIR,$lonids);
18085: while ($filename=readdir(DIR)) {
18086: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 18087: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
18088: &GDBM_READER(),0640)) {
1.1295 raeburn 18089: my $linkedfile;
1.1320 raeburn 18090: if (exists($oldenv{'user.linkedenv'})) {
18091: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 18092: }
1.1320 raeburn 18093: untie(%oldenv);
18094: if (unlink("$lonids/$filename")) {
18095: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
18096: if (-l "$lonids/$linkedfile.id") {
18097: unlink("$lonids/$linkedfile.id");
18098: }
1.1295 raeburn 18099: }
18100: }
18101: } else {
18102: unlink($lonids.'/'.$filename);
18103: }
1.463 albertel 18104: }
1.462 albertel 18105: }
1.463 albertel 18106: closedir(DIR);
1.1204 raeburn 18107: # If there is a undeleted lockfile for the user's paste buffer remove it.
18108: my $namespace = 'nohist_courseeditor';
18109: my $lockingkey = 'paste'."\0".'locked_num';
18110: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
18111: $domain,$username);
18112: if (exists($lockhash{$lockingkey})) {
18113: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
18114: unless ($delresult eq 'ok') {
18115: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
18116: }
18117: }
1.462 albertel 18118: }
18119: # Give them a new cookie
1.463 albertel 18120: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 18121: : $now.$$.int(rand(10000)));
1.463 albertel 18122: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 18123:
18124: # Initialize roles
18125:
1.1414 raeburn 18126: ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 18127: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 18128: }
18129: # ------------------------------------ Check browser type and MathML capability
18130:
1.1194 raeburn 18131: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
18132: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 18133:
18134: # ------------------------------------------------------------- Get environment
18135:
18136: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
18137: my ($tmp) = keys(%userenv);
1.1275 raeburn 18138: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 18139: undef(%userenv);
18140: }
18141: if (($userenv{'interface'}) && (!$form->{'interface'})) {
18142: $form->{'interface'}=$userenv{'interface'};
18143: }
18144: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
18145:
18146: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 18147: foreach my $option ('interface','localpath','localres') {
18148: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 18149: }
18150: # --------------------------------------------------------- Write first profile
18151:
18152: {
1.1350 raeburn 18153: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 18154: my %initial_env =
18155: ("user.name" => $username,
18156: "user.domain" => $domain,
18157: "user.home" => $authhost,
18158: "browser.type" => $clientbrowser,
18159: "browser.version" => $clientversion,
18160: "browser.mathml" => $clientmathml,
18161: "browser.unicode" => $clientunicode,
18162: "browser.os" => $clientos,
1.1137 raeburn 18163: "browser.mobile" => $clientmobile,
1.1141 raeburn 18164: "browser.info" => $clientinfo,
1.1194 raeburn 18165: "browser.osversion" => $clientosversion,
1.462 albertel 18166: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
18167: "request.course.fn" => '',
18168: "request.course.uri" => '',
18169: "request.course.sec" => '',
18170: "request.role" => 'cm',
18171: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 18172: "request.host" => $ip,);
1.462 albertel 18173:
18174: if ($form->{'localpath'}) {
18175: $initial_env{"browser.localpath"} = $form->{'localpath'};
18176: $initial_env{"browser.localres"} = $form->{'localres'};
18177: }
18178:
18179: if ($form->{'interface'}) {
18180: $form->{'interface'}=~s/\W//gs;
18181: $initial_env{"browser.interface"} = $form->{'interface'};
18182: $env{'browser.interface'}=$form->{'interface'};
18183: }
18184:
1.1157 raeburn 18185: if ($form->{'iptoken'}) {
18186: my $lonhost = $r->dir_config('lonHostID');
18187: $initial_env{"user.noloadbalance"} = $lonhost;
18188: $env{'user.noloadbalance'} = $lonhost;
18189: }
18190:
1.1268 raeburn 18191: if ($form->{'noloadbalance'}) {
18192: my @hosts = &Apache::lonnet::current_machine_ids();
18193: my $hosthere = $form->{'noloadbalance'};
18194: if (grep(/^\Q$hosthere\E$/,@hosts)) {
18195: $initial_env{"user.noloadbalance"} = $hosthere;
18196: $env{'user.noloadbalance'} = $hosthere;
18197: }
18198: }
18199:
1.1016 raeburn 18200: unless ($domain eq 'public') {
1.1273 raeburn 18201: my %is_adv = ( is_adv => $env{'user.adv'} );
18202: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
18203:
1.1414 raeburn 18204: foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
18205: $userenv{'availabletools.'.$tool} =
1.1273 raeburn 18206: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
18207: undef,\%userenv,\%domdef,\%is_adv);
18208: }
1.980 raeburn 18209:
1.1311 raeburn 18210: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 18211: $userenv{'canrequest.'.$crstype} =
18212: &Apache::lonnet::usertools_access($username,$domain,$crstype,
18213: 'reload','requestcourses',
18214: \%userenv,\%domdef,\%is_adv);
18215: }
1.724 raeburn 18216:
1.1418 raeburn 18217: if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
18218: (exists($userroles->{"user.role.au./$domain/"}))) {
18219: if ($userenv{'authoreditors'}) {
18220: $userenv{'editors'} = $userenv{'authoreditors'};
18221: } elsif ($domdef{'editors'} ne '') {
18222: $userenv{'editors'} = $domdef{'editors'};
18223: } else {
18224: $userenv{'editors'} = 'edit,xml';
18225: }
1.1431 raeburn 18226: if ($userenv{'authorarchive'}) {
18227: $userenv{'canarchive'} = 1;
18228: } elsif (($userenv{'authorarchive'} eq '') &&
18229: ($domdef{'archive'})) {
18230: $userenv{'canarchive'} = 1;
18231: }
1.1418 raeburn 18232: }
18233:
1.1273 raeburn 18234: $userenv{'canrequest.author'} =
18235: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
18236: 'reload','requestauthor',
1.980 raeburn 18237: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 18238: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
18239: $domain,$username);
18240: my $reqstatus = $reqauthor{'author_status'};
18241: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
18242: if (ref($reqauthor{'author'}) eq 'HASH') {
18243: $userenv{'requestauthorqueued'} = $reqstatus.':'.
18244: $reqauthor{'author'}{'timestamp'};
18245: }
1.1092 raeburn 18246: }
1.1287 raeburn 18247: my ($types,$typename) = &course_types();
18248: if (ref($types) eq 'ARRAY') {
18249: my @options = ('approval','validate','autolimit');
18250: my $optregex = join('|',@options);
18251: my (%willtrust,%trustchecked);
18252: foreach my $type (@{$types}) {
18253: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
18254: if ($dom_str ne '') {
18255: my $updatedstr = '';
18256: my @possdomains = split(',',$dom_str);
18257: foreach my $entry (@possdomains) {
18258: my ($extdom,$extopt) = split(':',$entry);
18259: unless ($trustchecked{$extdom}) {
18260: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
18261: $trustchecked{$extdom} = 1;
18262: }
18263: if ($willtrust{$extdom}) {
18264: $updatedstr .= $entry.',';
18265: }
18266: }
18267: $updatedstr =~ s/,$//;
18268: if ($updatedstr) {
18269: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
18270: } else {
18271: delete($userenv{'reqcrsotherdom.'.$type});
18272: }
18273: }
18274: }
18275: }
1.1092 raeburn 18276: }
1.462 albertel 18277: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 18278:
1.462 albertel 18279: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
18280: &GDBM_WRCREAT(),0640)) {
18281: &_add_to_env(\%disk_env,\%initial_env);
18282: &_add_to_env(\%disk_env,\%userenv,'environment.');
18283: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 18284: if (ref($firstaccenv) eq 'HASH') {
18285: &_add_to_env(\%disk_env,$firstaccenv);
18286: }
18287: if (ref($timerintenv) eq 'HASH') {
18288: &_add_to_env(\%disk_env,$timerintenv);
18289: }
1.1414 raeburn 18290: if (ref($coauthorenv) eq 'HASH') {
18291: if (keys(%{$coauthorenv})) {
18292: &_add_to_env(\%disk_env,$coauthorenv);
18293: }
18294: }
1.463 albertel 18295: if (ref($args->{'extra_env'})) {
18296: &_add_to_env(\%disk_env,$args->{'extra_env'});
18297: }
1.462 albertel 18298: untie(%disk_env);
18299: } else {
1.705 tempelho 18300: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
18301: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 18302: return 'error: '.$!;
18303: }
18304: }
18305: $env{'request.role'}='cm';
18306: $env{'request.role.adv'}=$env{'user.adv'};
18307: $env{'browser.type'}=$clientbrowser;
18308:
18309: return $cookie;
18310:
18311: }
18312:
18313: sub _add_to_env {
18314: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 18315: if (ref($env_data) eq 'HASH') {
18316: while (my ($key,$value) = each(%$env_data)) {
18317: $idf->{$prefix.$key} = $value;
18318: $env{$prefix.$key} = $value;
18319: }
1.462 albertel 18320: }
18321: }
18322:
1.685 tempelho 18323: # --- Get the symbolic name of a problem and the url
18324: sub get_symb {
18325: my ($request,$silent) = @_;
1.726 raeburn 18326: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 18327: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
18328: if ($symb eq '') {
18329: if (!$silent) {
1.1071 raeburn 18330: if (ref($request)) {
18331: $request->print("Unable to handle ambiguous references:$url:.");
18332: }
1.685 tempelho 18333: return ();
18334: }
18335: }
18336: &Apache::lonenc::check_decrypt(\$symb);
18337: return ($symb);
18338: }
18339:
18340: # --------------------------------------------------------------Get annotation
18341:
18342: sub get_annotation {
18343: my ($symb,$enc) = @_;
18344:
18345: my $key = $symb;
18346: if (!$enc) {
18347: $key =
18348: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
18349: }
18350: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
18351: return $annotation{$key};
18352: }
18353:
18354: sub clean_symb {
1.731 raeburn 18355: my ($symb,$delete_enc) = @_;
1.685 tempelho 18356:
18357: &Apache::lonenc::check_decrypt(\$symb);
18358: my $enc = $env{'request.enc'};
1.731 raeburn 18359: if ($delete_enc) {
1.730 raeburn 18360: delete($env{'request.enc'});
18361: }
1.685 tempelho 18362:
18363: return ($symb,$enc);
18364: }
1.462 albertel 18365:
1.1181 raeburn 18366: ############################################################
18367: ############################################################
18368:
18369: =pod
18370:
18371: =head1 Routines for building display used to search for courses
18372:
18373:
18374: =over 4
18375:
18376: =item * &build_filters()
18377:
18378: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 18379: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
18380: and quotacheck.pl
18381:
1.1181 raeburn 18382:
18383: Inputs:
18384:
18385: filterlist - anonymous array of fields to include as potential filters
18386:
18387: crstype - course type
18388:
18389: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
18390: to pop-open a course selector (will contain "extra element").
18391:
18392: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
18393:
18394: filter - anonymous hash of criteria and their values
18395:
18396: action - form action
18397:
18398: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
18399:
1.1182 raeburn 18400: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 18401:
18402: cloneruname - username of owner of new course who wants to clone
18403:
18404: clonerudom - domain of owner of new course who wants to clone
18405:
18406: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
18407:
18408: codetitlesref - reference to array of titles of components in institutional codes (official courses)
18409:
18410: codedom - domain
18411:
18412: formname - value of form element named "form".
18413:
18414: fixeddom - domain, if fixed.
18415:
18416: prevphase - value to assign to form element named "phase" when going back to the previous screen
18417:
18418: cnameelement - name of form element in form on opener page which will receive title of selected course
18419:
18420: cnumelement - name of form element in form on opener page which will receive courseID of selected course
18421:
18422: cdomelement - name of form element in form on opener page which will receive domain of selected course
18423:
18424: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
18425:
18426: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
18427:
18428: clonewarning - warning message about missing information for intended course owner when DC creates a course
18429:
1.1182 raeburn 18430:
1.1181 raeburn 18431: Returns: $output - HTML for display of search criteria, and hidden form elements.
18432:
1.1182 raeburn 18433:
1.1181 raeburn 18434: Side Effects: None
18435:
18436: =cut
18437:
18438: # ---------------------------------------------- search for courses based on last activity etc.
18439:
18440: sub build_filters {
18441: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
18442: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
18443: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
18444: $cnameelement,$cnumelement,$cdomelement,$setroles,
18445: $clonetext,$clonewarning) = @_;
1.1182 raeburn 18446: my ($list,$jscript);
1.1181 raeburn 18447: my $onchange = 'javascript:updateFilters(this)';
18448: my ($domainselectform,$sincefilterform,$createdfilterform,
18449: $ownerdomselectform,$persondomselectform,$instcodeform,
18450: $typeselectform,$instcodetitle);
18451: if ($formname eq '') {
18452: $formname = $caller;
18453: }
18454: foreach my $item (@{$filterlist}) {
18455: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
18456: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
18457: if ($item eq 'domainfilter') {
18458: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
18459: } elsif ($item eq 'coursefilter') {
18460: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
18461: } elsif ($item eq 'ownerfilter') {
18462: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18463: } elsif ($item eq 'ownerdomfilter') {
18464: $filter->{'ownerdomfilter'} =
18465: &LONCAPA::clean_domain($filter->{$item});
18466: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
18467: 'ownerdomfilter',1);
18468: } elsif ($item eq 'personfilter') {
18469: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18470: } elsif ($item eq 'persondomfilter') {
18471: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
18472: 'persondomfilter',1);
18473: } else {
18474: $filter->{$item} =~ s/\W//g;
18475: }
18476: if (!$filter->{$item}) {
18477: $filter->{$item} = '';
18478: }
18479: }
18480: if ($item eq 'domainfilter') {
18481: my $allow_blank = 1;
18482: if ($formname eq 'portform') {
18483: $allow_blank=0;
18484: } elsif ($formname eq 'studentform') {
18485: $allow_blank=0;
18486: }
18487: if ($fixeddom) {
18488: $domainselectform = '<input type="hidden" name="domainfilter"'.
18489: ' value="'.$codedom.'" />'.
18490: &Apache::lonnet::domain($codedom,'description');
18491: } else {
18492: $domainselectform = &select_dom_form($filter->{$item},
18493: 'domainfilter',
18494: $allow_blank,'',$onchange);
18495: }
18496: } else {
18497: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
18498: }
18499: }
18500:
18501: # last course activity filter and selection
18502: $sincefilterform = &timebased_select_form('sincefilter',$filter);
18503:
18504: # course created filter and selection
18505: if (exists($filter->{'createdfilter'})) {
18506: $createdfilterform = &timebased_select_form('createdfilter',$filter);
18507: }
18508:
1.1239 raeburn 18509: my $prefix = $crstype;
18510: if ($crstype eq 'Placement') {
18511: $prefix = 'Placement Test'
18512: }
1.1181 raeburn 18513: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 18514: 'cac' => "$prefix Activity",
18515: 'ccr' => "$prefix Created",
18516: 'cde' => "$prefix Title",
18517: 'cdo' => "$prefix Domain",
1.1181 raeburn 18518: 'ins' => 'Institutional Code',
18519: 'inc' => 'Institutional Categorization',
1.1239 raeburn 18520: 'cow' => "$prefix Owner/Co-owner",
18521: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 18522: 'cog' => 'Type',
18523: );
18524:
18525: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18526: my $typeval = 'Course';
18527: if ($crstype eq 'Community') {
18528: $typeval = 'Community';
1.1239 raeburn 18529: } elsif ($crstype eq 'Placement') {
18530: $typeval = 'Placement';
1.1181 raeburn 18531: }
18532: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
18533: } else {
18534: $typeselectform = '<select name="type" size="1"';
18535: if ($onchange) {
18536: $typeselectform .= ' onchange="'.$onchange.'"';
18537: }
18538: $typeselectform .= '>'."\n";
1.1237 raeburn 18539: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 18540: my $shown;
18541: if ($posstype eq 'Placement') {
18542: $shown = &mt('Placement Test');
18543: } else {
18544: $shown = &mt($posstype);
18545: }
1.1181 raeburn 18546: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 18547: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 18548: }
18549: $typeselectform.="</select>";
18550: }
18551:
18552: my ($cloneableonlyform,$cloneabletitle);
18553: if (exists($filter->{'cloneableonly'})) {
18554: my $cloneableon = '';
18555: my $cloneableoff = ' checked="checked"';
18556: if ($filter->{'cloneableonly'}) {
18557: $cloneableon = $cloneableoff;
18558: $cloneableoff = '';
18559: }
18560: $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>';
18561: if ($formname eq 'ccrs') {
1.1187 bisitz 18562: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 18563: } else {
18564: $cloneabletitle = &mt('Cloneable by you');
18565: }
18566: }
18567: my $officialjs;
18568: if ($crstype eq 'Course') {
18569: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 18570: # if (($fixeddom) || ($formname eq 'requestcrs') ||
18571: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
18572: if ($codedom) {
1.1181 raeburn 18573: $officialjs = 1;
18574: ($instcodeform,$jscript,$$numtitlesref) =
18575: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
18576: $officialjs,$codetitlesref);
18577: if ($jscript) {
1.1182 raeburn 18578: $jscript = '<script type="text/javascript">'."\n".
18579: '// <![CDATA['."\n".
18580: $jscript."\n".
18581: '// ]]>'."\n".
18582: '</script>'."\n";
1.1181 raeburn 18583: }
18584: }
18585: if ($instcodeform eq '') {
18586: $instcodeform =
18587: '<input type="text" name="instcodefilter" size="10" value="'.
18588: $list->{'instcodefilter'}.'" />';
18589: $instcodetitle = $lt{'ins'};
18590: } else {
18591: $instcodetitle = $lt{'inc'};
18592: }
18593: if ($fixeddom) {
18594: $instcodetitle .= '<br />('.$codedom.')';
18595: }
18596: }
18597: }
18598: my $output = qq|
18599: <form method="post" name="filterpicker" action="$action">
18600: <input type="hidden" name="form" value="$formname" />
18601: |;
18602: if ($formname eq 'modifycourse') {
18603: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18604: '<input type="hidden" name="prevphase" value="'.
18605: $prevphase.'" />'."\n";
1.1198 musolffc 18606: } elsif ($formname eq 'quotacheck') {
18607: $output .= qq|
18608: <input type="hidden" name="sortby" value="" />
18609: <input type="hidden" name="sortorder" value="" />
18610: |;
18611: } else {
1.1181 raeburn 18612: my $name_input;
18613: if ($cnameelement ne '') {
18614: $name_input = '<input type="hidden" name="cnameelement" value="'.
18615: $cnameelement.'" />';
18616: }
18617: $output .= qq|
1.1182 raeburn 18618: <input type="hidden" name="cnumelement" value="$cnumelement" />
18619: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18620: $name_input
18621: $roleelement
18622: $multelement
18623: $typeelement
18624: |;
18625: if ($formname eq 'portform') {
18626: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18627: }
18628: }
18629: if ($fixeddom) {
18630: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18631: }
18632: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18633: if ($sincefilterform) {
18634: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18635: .$sincefilterform
18636: .&Apache::lonhtmlcommon::row_closure();
18637: }
18638: if ($createdfilterform) {
18639: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18640: .$createdfilterform
18641: .&Apache::lonhtmlcommon::row_closure();
18642: }
18643: if ($domainselectform) {
18644: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18645: .$domainselectform
18646: .&Apache::lonhtmlcommon::row_closure();
18647: }
18648: if ($typeselectform) {
18649: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18650: $output .= $typeselectform;
18651: } else {
18652: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18653: .$typeselectform
18654: .&Apache::lonhtmlcommon::row_closure();
18655: }
18656: }
18657: if ($instcodeform) {
18658: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18659: .$instcodeform
18660: .&Apache::lonhtmlcommon::row_closure();
18661: }
18662: if (exists($filter->{'ownerfilter'})) {
18663: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18664: '<table><tr><td>'.&mt('Username').'<br />'.
18665: '<input type="text" name="ownerfilter" size="20" value="'.
18666: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18667: $ownerdomselectform.'</td></tr></table>'.
18668: &Apache::lonhtmlcommon::row_closure();
18669: }
18670: if (exists($filter->{'personfilter'})) {
18671: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18672: '<table><tr><td>'.&mt('Username').'<br />'.
18673: '<input type="text" name="personfilter" size="20" value="'.
18674: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18675: $persondomselectform.'</td></tr></table>'.
18676: &Apache::lonhtmlcommon::row_closure();
18677: }
18678: if (exists($filter->{'coursefilter'})) {
18679: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18680: .'<input type="text" name="coursefilter" size="25" value="'
18681: .$list->{'coursefilter'}.'" />'
18682: .&Apache::lonhtmlcommon::row_closure();
18683: }
18684: if ($cloneableonlyform) {
18685: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18686: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18687: }
18688: if (exists($filter->{'descriptfilter'})) {
18689: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18690: .'<input type="text" name="descriptfilter" size="40" value="'
18691: .$list->{'descriptfilter'}.'" />'
18692: .&Apache::lonhtmlcommon::row_closure(1);
18693: }
18694: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18695: '<input type="hidden" name="updater" value="" />'."\n".
18696: '<input type="submit" name="gosearch" value="'.
18697: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18698: return $jscript.$clonewarning.$output;
18699: }
18700:
18701: =pod
18702:
18703: =item * &timebased_select_form()
18704:
1.1182 raeburn 18705: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18706: filter e.g., Course Activity, Course Created, when searching for courses
18707: or communities
18708:
18709: Inputs:
18710:
18711: item - name of form element (sincefilter or createdfilter)
18712:
18713: filter - anonymous hash of criteria and their values
18714:
18715: Returns: HTML for a select box contained a blank, then six time selections,
18716: with value set in incoming form variables currently selected.
18717:
18718: Side Effects: None
18719:
18720: =cut
18721:
18722: sub timebased_select_form {
18723: my ($item,$filter) = @_;
18724: if (ref($filter) eq 'HASH') {
18725: $filter->{$item} =~ s/[^\d-]//g;
18726: if (!$filter->{$item}) { $filter->{$item}=-1; }
18727: return &select_form(
18728: $filter->{$item},
18729: $item,
18730: { '-1' => '',
18731: '86400' => &mt('today'),
18732: '604800' => &mt('last week'),
18733: '2592000' => &mt('last month'),
18734: '7776000' => &mt('last three months'),
18735: '15552000' => &mt('last six months'),
18736: '31104000' => &mt('last year'),
18737: 'select_form_order' =>
18738: ['-1','86400','604800','2592000','7776000',
18739: '15552000','31104000']});
18740: }
18741: }
18742:
18743: =pod
18744:
18745: =item * &js_changer()
18746:
18747: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18748: when course type or domain is changed, and also to hide 'Searching ...' on
18749: page load completion for page showing search result.
1.1181 raeburn 18750:
18751: Inputs: None
18752:
1.1183 raeburn 18753: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18754:
18755: Side Effects: None
18756:
18757: =cut
18758:
18759: sub js_changer {
18760: return <<ENDJS;
18761: <script type="text/javascript">
18762: // <![CDATA[
18763: function updateFilters(caller) {
18764: if (typeof(caller) != "undefined") {
18765: document.filterpicker.updater.value = caller.name;
18766: }
18767: document.filterpicker.submit();
18768: }
1.1183 raeburn 18769:
18770: function hideSearching() {
18771: if (document.getElementById('searching')) {
18772: document.getElementById('searching').style.display = 'none';
18773: }
18774: return;
18775: }
18776:
1.1181 raeburn 18777: // ]]>
18778: </script>
18779:
18780: ENDJS
18781: }
18782:
18783: =pod
18784:
1.1182 raeburn 18785: =item * &search_courses()
18786:
18787: Process selected filters form course search form and pass to lonnet::courseiddump
18788: to retrieve a hash for which keys are courseIDs which match the selected filters.
18789:
18790: Inputs:
18791:
18792: dom - domain being searched
18793:
18794: type - course type ('Course' or 'Community' or '.' if any).
18795:
18796: filter - anonymous hash of criteria and their values
18797:
18798: numtitles - for institutional codes - number of categories
18799:
18800: cloneruname - optional username of new course owner
18801:
18802: clonerudom - optional domain of new course owner
18803:
1.1221 raeburn 18804: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18805: (used when DC is using course creation form)
18806:
18807: codetitles - reference to array of titles of components in institutional codes (official courses).
18808:
1.1221 raeburn 18809: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18810: (and so can clone automatically)
18811:
18812: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18813:
18814: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18815: courses to clone
1.1182 raeburn 18816:
18817: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18818:
18819:
18820: Side Effects: None
18821:
18822: =cut
18823:
18824:
18825: sub search_courses {
1.1221 raeburn 18826: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18827: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18828: my (%courses,%showcourses,$cloner);
18829: if (($filter->{'ownerfilter'} ne '') ||
18830: ($filter->{'ownerdomfilter'} ne '')) {
18831: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18832: $filter->{'ownerdomfilter'};
18833: }
18834: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18835: if (!$filter->{$item}) {
18836: $filter->{$item}='.';
18837: }
18838: }
18839: my $now = time;
18840: my $timefilter =
18841: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18842: my ($createdbefore,$createdafter);
18843: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18844: $createdbefore = $now;
18845: $createdafter = $now-$filter->{'createdfilter'};
18846: }
18847: my ($instcodefilter,$regexpok);
18848: if ($numtitles) {
18849: if ($env{'form.official'} eq 'on') {
18850: $instcodefilter =
18851: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18852: $regexpok = 1;
18853: } elsif ($env{'form.official'} eq 'off') {
18854: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18855: unless ($instcodefilter eq '') {
18856: $regexpok = -1;
18857: }
18858: }
18859: } else {
18860: $instcodefilter = $filter->{'instcodefilter'};
18861: }
18862: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18863: if ($type eq '') { $type = '.'; }
18864:
18865: if (($clonerudom ne '') && ($cloneruname ne '')) {
18866: $cloner = $cloneruname.':'.$clonerudom;
18867: }
18868: %courses = &Apache::lonnet::courseiddump($dom,
18869: $filter->{'descriptfilter'},
18870: $timefilter,
18871: $instcodefilter,
18872: $filter->{'combownerfilter'},
18873: $filter->{'coursefilter'},
18874: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18875: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18876: $filter->{'cloneableonly'},
18877: $createdbefore,$createdafter,undef,
1.1221 raeburn 18878: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18879: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18880: my $ccrole;
18881: if ($type eq 'Community') {
18882: $ccrole = 'co';
18883: } else {
18884: $ccrole = 'cc';
18885: }
18886: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18887: $filter->{'persondomfilter'},
18888: 'userroles',undef,
18889: [$ccrole,'in','ad','ep','ta','cr'],
18890: $dom);
18891: foreach my $role (keys(%rolehash)) {
18892: my ($cnum,$cdom,$courserole) = split(':',$role);
18893: my $cid = $cdom.'_'.$cnum;
18894: if (exists($courses{$cid})) {
18895: if (ref($courses{$cid}) eq 'HASH') {
18896: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18897: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18898: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18899: }
18900: } else {
18901: $courses{$cid}{roles} = [$courserole];
18902: }
18903: $showcourses{$cid} = $courses{$cid};
18904: }
18905: }
18906: }
18907: %courses = %showcourses;
18908: }
18909: return %courses;
18910: }
18911:
18912: =pod
18913:
1.1181 raeburn 18914: =back
18915:
1.1207 raeburn 18916: =head1 Routines for version requirements for current course.
18917:
18918: =over 4
18919:
18920: =item * &check_release_required()
18921:
18922: Compares required LON-CAPA version with version on server, and
18923: if required version is newer looks for a server with the required version.
18924:
18925: Looks first at servers in user's owen domain; if none suitable, looks at
18926: servers in course's domain are permitted to host sessions for user's domain.
18927:
18928: Inputs:
18929:
18930: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18931:
18932: $courseid - Course ID of current course
18933:
18934: $rolecode - User's current role in course (for switchserver query string).
18935:
18936: $required - LON-CAPA version needed by course (format: Major.Minor).
18937:
18938:
18939: Returns:
18940:
18941: $switchserver - query string tp append to /adm/switchserver call (if
18942: current server's LON-CAPA version is too old.
18943:
18944: $warning - Message is displayed if no suitable server could be found.
18945:
18946: =cut
18947:
18948: sub check_release_required {
18949: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18950: my ($switchserver,$warning);
18951: if ($required ne '') {
18952: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18953: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18954: if ($reqdmajor ne '' && $reqdminor ne '') {
18955: my $otherserver;
18956: if (($major eq '' && $minor eq '') ||
18957: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18958: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18959: my $switchlcrev =
18960: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18961: $userdomserver);
18962: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18963: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18964: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18965: my $cdom = $env{'course.'.$courseid.'.domain'};
18966: if ($cdom ne $env{'user.domain'}) {
18967: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18968: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18969: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18970: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18971: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18972: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18973: my $canhost =
18974: &Apache::lonnet::can_host_session($env{'user.domain'},
18975: $coursedomserver,
18976: $remoterev,
18977: $udomdefaults{'remotesessions'},
18978: $defdomdefaults{'hostedsessions'});
18979:
18980: if ($canhost) {
18981: $otherserver = $coursedomserver;
18982: } else {
18983: $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.");
18984: }
18985: } else {
18986: $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).");
18987: }
18988: } else {
18989: $otherserver = $userdomserver;
18990: }
18991: }
18992: if ($otherserver ne '') {
18993: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18994: }
18995: }
18996: }
18997: return ($switchserver,$warning);
18998: }
18999:
19000: =pod
19001:
19002: =item * &check_release_result()
19003:
19004: Inputs:
19005:
19006: $switchwarning - Warning message if no suitable server found to host session.
19007:
19008: $switchserver - query string to append to /adm/switchserver containing lonHostID
19009: and current role.
19010:
19011: Returns: HTML to display with information about requirement to switch server.
19012: Either displaying warning with link to Roles/Courses screen or
19013: display link to switchserver.
19014:
1.1181 raeburn 19015: =cut
19016:
1.1207 raeburn 19017: sub check_release_result {
19018: my ($switchwarning,$switchserver) = @_;
19019: my $output = &start_page('Selected course unavailable on this server').
19020: '<p class="LC_warning">';
19021: if ($switchwarning) {
19022: $output .= $switchwarning.'<br /><a href="/adm/roles">';
19023: if (&show_course()) {
19024: $output .= &mt('Display courses');
19025: } else {
19026: $output .= &mt('Display roles');
19027: }
19028: $output .= '</a>';
19029: } elsif ($switchserver) {
19030: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
19031: '<br />'.
19032: '<a href="/adm/switchserver?'.$switchserver.'">'.
19033: &mt('Switch Server').
19034: '</a>';
19035: }
19036: $output .= '</p>'.&end_page();
19037: return $output;
19038: }
19039:
19040: =pod
19041:
19042: =item * &needs_coursereinit()
19043:
19044: Determine if course contents stored for user's session needs to be
19045: refreshed, because content has changed since "Big Hash" last tied.
19046:
19047: Check for change is made if time last checked is more than 10 minutes ago
19048: (by default).
19049:
19050: Inputs:
19051:
19052: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
19053:
19054: $interval (optional) - Time which may elapse (in s) between last check for content
19055: change in current course. (default: 600 s).
19056:
19057: Returns: an array; first element is:
19058:
19059: =over 4
19060:
19061: 'switch' - if content updates mean user's session
19062: needs to be switched to a server running a newer LON-CAPA version
19063:
19064: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
19065: on current server hosting user's session
19066:
19067: '' - if no action required.
19068:
19069: =back
19070:
19071: If first item element is 'switch':
19072:
19073: second item is $switchwarning - Warning message if no suitable server found to host session.
19074:
19075: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
19076: and current role.
19077:
19078: otherwise: no other elements returned.
19079:
19080: =back
19081:
19082: =cut
19083:
19084: sub needs_coursereinit {
19085: my ($loncaparev,$interval) = @_;
19086: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
19087: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19088: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
19089: my $now = time;
19090: if ($interval eq '') {
19091: $interval = 600;
19092: }
19093: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 19094: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 19095: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19096: if ($blocked) {
19097: return ();
19098: }
1.1391 raeburn 19099: my $update;
19100: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
19101: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
19102: if ($lastmainchange > $env{'request.course.tied'}) {
19103: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
19104: if ($needswitch) {
19105: return ('switch',$switchwarning,$switchserver);
19106: }
19107: $update = 'main';
19108: }
19109: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
19110: if ($update) {
19111: $update = 'both';
19112: } else {
19113: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
19114: if ($needswitch) {
19115: return ('switch',$switchwarning,$switchserver);
19116: } else {
19117: $update = 'supp';
1.1207 raeburn 19118: }
19119: }
1.1391 raeburn 19120: }
1.1453 raeburn 19121: return ($update);
1.1391 raeburn 19122: }
19123: return ();
19124: }
19125:
19126: sub switch_for_update {
19127: my ($loncaparev,$cdom,$cnum) = @_;
19128: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
19129: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
19130: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
19131: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
19132: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
19133: $curr_reqd_hash{'internal.releaserequired'}});
19134: my ($switchserver,$switchwarning) =
19135: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
19136: $curr_reqd_hash{'internal.releaserequired'});
19137: if ($switchwarning ne '' || $switchserver ne '') {
19138: return ('switch',$switchwarning,$switchserver);
19139: }
1.1207 raeburn 19140: }
19141: }
19142: return ();
19143: }
1.1181 raeburn 19144:
1.1083 raeburn 19145: sub update_content_constraints {
1.1395 raeburn 19146: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 19147: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
19148: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 19149: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 19150: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 19151: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 19152: if ($item eq 'resourcetag') {
19153: if ($name eq 'responsetype') {
19154: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
19155: }
1.1307 raeburn 19156: } elsif ($item eq 'course') {
19157: if ($name eq 'courserestype') {
19158: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
19159: }
1.1083 raeburn 19160: }
19161: }
19162: my $navmap = Apache::lonnavmaps::navmap->new();
19163: if (defined($navmap)) {
1.1307 raeburn 19164: my (%allresponses,%allcrsrestypes);
19165: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
19166: if ($res->is_tool()) {
19167: if ($allcrsrestypes{'exttool'}) {
19168: $allcrsrestypes{'exttool'} ++;
19169: } else {
19170: $allcrsrestypes{'exttool'} = 1;
19171: }
19172: next;
19173: }
1.1083 raeburn 19174: my %responses = $res->responseTypes();
19175: foreach my $key (keys(%responses)) {
19176: next unless(exists($checkresponsetypes{$key}));
19177: $allresponses{$key} += $responses{$key};
19178: }
19179: }
19180: foreach my $key (keys(%allresponses)) {
19181: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
19182: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19183: ($reqdmajor,$reqdminor) = ($major,$minor);
19184: }
19185: }
1.1307 raeburn 19186: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 19187: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 19188: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19189: ($reqdmajor,$reqdminor) = ($major,$minor);
19190: }
19191: }
1.1083 raeburn 19192: undef($navmap);
19193: }
1.1391 raeburn 19194: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 19195: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
19196: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19197: ($reqdmajor,$reqdminor) = ($major,$minor);
19198: }
19199: }
1.1083 raeburn 19200: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
19201: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
19202: }
19203: return;
19204: }
19205:
1.1110 raeburn 19206: sub allmaps_incourse {
19207: my ($cdom,$cnum,$chome,$cid) = @_;
19208: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
19209: $cid = $env{'request.course.id'};
19210: $cdom = $env{'course.'.$cid.'.domain'};
19211: $cnum = $env{'course.'.$cid.'.num'};
19212: $chome = $env{'course.'.$cid.'.home'};
19213: }
19214: my %allmaps = ();
19215: my $lastchange =
19216: &Apache::lonnet::get_coursechange($cdom,$cnum);
19217: if ($lastchange > $env{'request.course.tied'}) {
19218: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
19219: unless ($ferr) {
1.1395 raeburn 19220: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 19221: }
19222: }
19223: my $navmap = Apache::lonnavmaps::navmap->new();
19224: if (defined($navmap)) {
19225: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
19226: $allmaps{$res->src()} = 1;
19227: }
19228: }
19229: return \%allmaps;
19230: }
19231:
1.1083 raeburn 19232: sub parse_supplemental_title {
19233: my ($title) = @_;
19234:
19235: my ($foldertitle,$renametitle);
19236: if ($title =~ /&&&/) {
19237: $title = &HTML::Entites::decode($title);
19238: }
19239: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
19240: $renametitle=$4;
19241: my ($time,$uname,$udom) = ($1,$2,$3);
19242: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
19243: my $name = &plainname($uname,$udom);
19244: $name = &HTML::Entities::encode($name,'"<>&\'');
19245: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 19246: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 19247: if ($foldertitle ne '') {
1.1401 raeburn 19248: $title .= ': <br />'.$foldertitle;
19249: }
1.1083 raeburn 19250: }
19251: if (wantarray) {
19252: return ($title,$foldertitle,$renametitle);
19253: }
19254: return $title;
19255: }
19256:
1.1395 raeburn 19257: sub get_supplemental {
19258: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
19259: my $hashid=$cnum.':'.$cdom;
19260: my ($supplemental,$cached,$set_httprefs);
19261: unless ($ignorecache) {
19262: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
19263: }
19264: unless (defined($cached)) {
19265: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
19266: unless ($chome eq 'no_host') {
19267: my @order = @LONCAPA::map::order;
19268: my @resources = @LONCAPA::map::resources;
19269: my @resparms = @LONCAPA::map::resparms;
19270: my @zombies = @LONCAPA::map::zombies;
19271: my ($errors,%ids,%hidden);
19272: $errors =
19273: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
19274: $errors,$possdel,\%ids,\%hidden);
19275: @LONCAPA::map::order = @order;
19276: @LONCAPA::map::resources = @resources;
19277: @LONCAPA::map::resparms = @resparms;
19278: @LONCAPA::map::zombies = @zombies;
19279: $set_httprefs = 1;
19280: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19281: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19282: }
19283: $supplemental = {
19284: ids => \%ids,
19285: hidden => \%hidden,
19286: };
19287: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
19288: }
19289: }
19290: return ($supplemental,$set_httprefs);
19291: }
19292:
1.1143 raeburn 19293: sub recurse_supplemental {
1.1391 raeburn 19294: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
19295: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
19296: my $mapnum;
19297: if ($suppmap eq 'supplemental.sequence') {
19298: $mapnum = 0;
19299: } else {
19300: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
19301: }
1.1143 raeburn 19302: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
19303: if ($fatal) {
19304: $errors ++;
19305: } else {
1.1389 raeburn 19306: my @order = @LONCAPA::map::order;
19307: if (@order > 0) {
19308: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 19309: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 19310: foreach my $idx (@order) {
19311: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 19312: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 19313: my $id = $mapnum.':'.$idx;
19314: push(@{$suppids->{$src}},$id);
19315: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
19316: $hiddensupp->{$id} = 1;
19317: }
1.1146 raeburn 19318: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 19319: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
19320: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 19321: } else {
1.1391 raeburn 19322: my $allowed;
19323: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
19324: $allowed = 1;
19325: } elsif ($possdel) {
19326: foreach my $item (@{$suppids->{$src}}) {
19327: next if ($item eq $id);
19328: unless ($hiddensupp->{$item}) {
19329: $allowed = 1;
19330: last;
19331: }
19332: }
19333: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
19334: &Apache::lonnet::delenv('httpref.'.$src);
19335: }
19336: }
19337: if ($allowed && (!exists($env{'httpref.'.$src}))) {
19338: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 19339: }
1.1143 raeburn 19340: }
19341: }
19342: }
19343: }
19344: }
19345: }
1.1391 raeburn 19346: return $errors;
19347: }
19348:
19349: sub set_supp_httprefs {
19350: my ($cnum,$cdom,$supplemental,$possdel) = @_;
19351: if (ref($supplemental) eq 'HASH') {
19352: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
19353: foreach my $src (keys(%{$supplemental->{'ids'}})) {
19354: next if ($src =~ /\.sequence$/);
19355: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
19356: my $allowed;
19357: if ($env{'request.role.adv'}) {
19358: $allowed = 1;
19359: } else {
19360: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
19361: unless ($supplemental->{'hidden'}->{$id}) {
19362: $allowed = 1;
19363: last;
19364: }
19365: }
19366: }
19367: if (exists($env{'httpref.'.$src})) {
19368: if ($possdel) {
19369: unless ($allowed) {
19370: &Apache::lonnet::delenv('httpref.'.$src);
19371: }
19372: }
19373: } elsif ($allowed) {
19374: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
19375: }
19376: }
19377: }
19378: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19379: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19380: }
19381: }
19382: }
19383: }
19384:
19385: sub get_supp_parameter {
19386: my ($resparm,$name)=@_;
19387: return if ($resparm eq '');
19388: my $value=undef;
19389: my $ptype=undef;
19390: foreach (split('&&&',$resparm)) {
19391: my ($thistype,$thisname,$thisvalue)=split('___',$_);
19392: if ($thisname eq $name) {
19393: $value=$thisvalue;
19394: $ptype=$thistype;
19395: }
19396: }
19397: return $value;
1.1143 raeburn 19398: }
19399:
1.1101 raeburn 19400: sub symb_to_docspath {
1.1267 raeburn 19401: my ($symb,$navmapref) = @_;
19402: return unless ($symb && ref($navmapref));
1.1101 raeburn 19403: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
19404: if ($resurl=~/\.(sequence|page)$/) {
19405: $mapurl=$resurl;
19406: } elsif ($resurl eq 'adm/navmaps') {
19407: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
19408: }
19409: my $mapresobj;
1.1267 raeburn 19410: unless (ref($$navmapref)) {
19411: $$navmapref = Apache::lonnavmaps::navmap->new();
19412: }
19413: if (ref($$navmapref)) {
19414: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 19415: }
19416: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
19417: my $type=$2;
19418: my $path;
19419: if (ref($mapresobj)) {
19420: my $pcslist = $mapresobj->map_hierarchy();
19421: if ($pcslist ne '') {
19422: foreach my $pc (split(/,/,$pcslist)) {
19423: next if ($pc <= 1);
1.1267 raeburn 19424: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 19425: if (ref($res)) {
19426: my $thisurl = $res->src();
19427: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
19428: my $thistitle = $res->title();
19429: $path .= '&'.
19430: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 19431: &escape($thistitle).
1.1101 raeburn 19432: ':'.$res->randompick().
19433: ':'.$res->randomout().
19434: ':'.$res->encrypted().
19435: ':'.$res->randomorder().
19436: ':'.$res->is_page();
19437: }
19438: }
19439: }
19440: $path =~ s/^\&//;
19441: my $maptitle = $mapresobj->title();
19442: if ($mapurl eq 'default') {
1.1129 raeburn 19443: $maptitle = 'Main Content';
1.1101 raeburn 19444: }
19445: $path .= (($path ne '')? '&' : '').
19446: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19447: &escape($maptitle).
1.1101 raeburn 19448: ':'.$mapresobj->randompick().
19449: ':'.$mapresobj->randomout().
19450: ':'.$mapresobj->encrypted().
19451: ':'.$mapresobj->randomorder().
19452: ':'.$mapresobj->is_page();
19453: } else {
19454: my $maptitle = &Apache::lonnet::gettitle($mapurl);
19455: my $ispage = (($type eq 'page')? 1 : '');
19456: if ($mapurl eq 'default') {
1.1129 raeburn 19457: $maptitle = 'Main Content';
1.1101 raeburn 19458: }
19459: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19460: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 19461: }
19462: unless ($mapurl eq 'default') {
19463: $path = 'default&'.
1.1146 raeburn 19464: &escape('Main Content').
1.1101 raeburn 19465: ':::::&'.$path;
19466: }
19467: return $path;
19468: }
19469:
1.1393 raeburn 19470: sub validate_folderpath {
19471: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
19472: if ($env{'form.folderpath'} ne '') {
19473: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 19474: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 19475: for (my $i=0; $i<@items; $i++) {
19476: my $odd = $i%2;
19477: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
19478: $badpath = 1;
1.1394 raeburn 19479: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 19480: my $idx = $i-1;
1.1394 raeburn 19481: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
19482: my $esc_name = $1;
19483: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
19484: $supppath .= '&'.$esc_name;
19485: $changed = 1;
19486: } else {
19487: $supppath .= '&'.$items[$i];
19488: }
19489: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
19490: $changed = 1;
1.1393 raeburn 19491: my $is_hidden;
19492: unless ($got_supp) {
1.1395 raeburn 19493: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 19494: if (ref($supplemental) eq 'HASH') {
19495: if (ref($supplemental->{'hidden'}) eq 'HASH') {
19496: %supphidden = %{$supplemental->{'hidden'}};
19497: }
19498: if (ref($supplemental->{'ids'}) eq 'HASH') {
19499: %suppids = %{$supplemental->{'ids'}};
19500: }
19501: }
19502: $got_supp = 1;
19503: }
19504: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
19505: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
19506: if ($supphidden{$mapid}) {
19507: $is_hidden = 1;
19508: }
19509: }
1.1394 raeburn 19510: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
19511: } else {
19512: $supppath .= '&'.$items[$i];
1.1393 raeburn 19513: }
19514: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
19515: $badpath = 1;
1.1394 raeburn 19516: } elsif ($supplementalflag) {
1.1393 raeburn 19517: $supppath .= '&'.$items[$i];
19518: }
19519: last if ($badpath);
19520: }
19521: if ($badpath) {
19522: delete($env{'form.folderpath'});
1.1394 raeburn 19523: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 19524: $supppath =~ s/^\&//;
19525: $env{'form.folderpath'} = $supppath;
19526: }
19527: }
19528: return;
19529: }
19530:
1.1094 raeburn 19531: sub captcha_display {
1.1327 raeburn 19532: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19533: my ($output,$error);
1.1234 raeburn 19534: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 19535: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19536: if ($captcha eq 'original') {
1.1094 raeburn 19537: $output = &create_captcha();
19538: unless ($output) {
1.1172 raeburn 19539: $error = 'captcha';
1.1094 raeburn 19540: }
19541: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19542: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 19543: unless ($output) {
1.1172 raeburn 19544: $error = 'recaptcha';
1.1094 raeburn 19545: }
19546: }
1.1234 raeburn 19547: return ($output,$error,$captcha,$version);
1.1094 raeburn 19548: }
19549:
19550: sub captcha_response {
1.1327 raeburn 19551: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19552: my ($captcha_chk,$captcha_error);
1.1327 raeburn 19553: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19554: if ($captcha eq 'original') {
1.1094 raeburn 19555: ($captcha_chk,$captcha_error) = &check_captcha();
19556: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19557: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 19558: } else {
19559: $captcha_chk = 1;
19560: }
19561: return ($captcha_chk,$captcha_error);
19562: }
19563:
19564: sub get_captcha_config {
1.1327 raeburn 19565: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 19566: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 19567: my $hostname = &Apache::lonnet::hostname($lonhost);
19568: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
19569: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 19570: if ($context eq 'usercreation') {
19571: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
19572: if (ref($domconfig{$context}) eq 'HASH') {
19573: $hashtocheck = $domconfig{$context}{'cancreate'};
19574: if (ref($hashtocheck) eq 'HASH') {
19575: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
19576: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
19577: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
19578: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
19579: }
19580: if ($privkey && $pubkey) {
19581: $captcha = 'recaptcha';
1.1234 raeburn 19582: $version = $hashtocheck->{'recaptchaversion'};
19583: if ($version ne '2') {
19584: $version = 1;
19585: }
1.1095 raeburn 19586: } else {
19587: $captcha = 'original';
19588: }
19589: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19590: $captcha = 'original';
19591: }
1.1094 raeburn 19592: }
1.1095 raeburn 19593: } else {
19594: $captcha = 'captcha';
19595: }
19596: } elsif ($context eq 'login') {
19597: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19598: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19599: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19600: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19601: if ($privkey && $pubkey) {
19602: $captcha = 'recaptcha';
1.1234 raeburn 19603: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19604: if ($version ne '2') {
19605: $version = 1;
19606: }
1.1095 raeburn 19607: } else {
19608: $captcha = 'original';
1.1094 raeburn 19609: }
1.1095 raeburn 19610: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19611: $captcha = 'original';
1.1094 raeburn 19612: }
1.1327 raeburn 19613: } elsif ($context eq 'passwords') {
19614: if ($dom_in_effect) {
19615: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19616: if ($passwdconf{'captcha'} eq 'recaptcha') {
19617: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19618: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19619: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19620: }
19621: if ($privkey && $pubkey) {
19622: $captcha = 'recaptcha';
19623: $version = $passwdconf{'recaptchaversion'};
19624: if ($version ne '2') {
19625: $version = 1;
19626: }
19627: } else {
19628: $captcha = 'original';
19629: }
19630: } elsif ($passwdconf{'captcha'} ne 'notused') {
19631: $captcha = 'original';
19632: }
19633: }
19634: }
1.1234 raeburn 19635: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19636: }
19637:
19638: sub create_captcha {
19639: my %captcha_params = &captcha_settings();
19640: my ($output,$maxtries,$tries) = ('',10,0);
19641: while ($tries < $maxtries) {
19642: $tries ++;
19643: my $captcha = Authen::Captcha->new (
19644: output_folder => $captcha_params{'output_dir'},
19645: data_folder => $captcha_params{'db_dir'},
19646: );
19647: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19648:
19649: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19650: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19651: '<span class="LC_nobreak">'.
1.1453 raeburn 19652: '<label>'.&mt('Type in the letters/numbers shown below').' '.
1.1390 raeburn 19653: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1453 raeburn 19654: '</label></span><br />'.
1.1176 raeburn 19655: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19656: last;
19657: }
19658: }
1.1323 raeburn 19659: if ($output eq '') {
19660: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19661: }
1.1094 raeburn 19662: return $output;
19663: }
19664:
19665: sub captcha_settings {
19666: my %captcha_params = (
19667: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19668: www_output_dir => "/captchaspool",
19669: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19670: numchars => '5',
19671: );
19672: return %captcha_params;
19673: }
19674:
19675: sub check_captcha {
19676: my ($captcha_chk,$captcha_error);
19677: my $code = $env{'form.code'};
19678: my $md5sum = $env{'form.crypt'};
19679: my %captcha_params = &captcha_settings();
19680: my $captcha = Authen::Captcha->new(
19681: output_folder => $captcha_params{'output_dir'},
19682: data_folder => $captcha_params{'db_dir'},
19683: );
1.1109 raeburn 19684: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19685: my %captcha_hash = (
19686: 0 => 'Code not checked (file error)',
19687: -1 => 'Failed: code expired',
19688: -2 => 'Failed: invalid code (not in database)',
19689: -3 => 'Failed: invalid code (code does not match crypt)',
19690: );
19691: if ($captcha_chk != 1) {
19692: $captcha_error = $captcha_hash{$captcha_chk}
19693: }
19694: return ($captcha_chk,$captcha_error);
19695: }
19696:
19697: sub create_recaptcha {
1.1234 raeburn 19698: my ($pubkey,$version) = @_;
19699: if ($version >= 2) {
1.1367 raeburn 19700: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19701: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19702: } else {
19703: my $use_ssl;
19704: if ($ENV{'SERVER_PORT'} == 443) {
19705: $use_ssl = 1;
19706: }
19707: my $captcha = Captcha::reCAPTCHA->new;
19708: return $captcha->get_options_setter({theme => 'white'})."\n".
19709: $captcha->get_html($pubkey,undef,$use_ssl).
19710: &mt('If the text is hard to read, [_1] will replace them.',
19711: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19712: '<br /><br />';
19713: }
1.1094 raeburn 19714: }
19715:
19716: sub check_recaptcha {
1.1234 raeburn 19717: my ($privkey,$version) = @_;
1.1094 raeburn 19718: my $captcha_chk;
1.1350 raeburn 19719: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19720: if ($version >= 2) {
19721: my %info = (
19722: secret => $privkey,
19723: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19724: remoteip => $ip,
1.1234 raeburn 19725: );
1.1280 raeburn 19726: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19727: $request->content(join('&',map {
19728: my $name = escape($_);
19729: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19730: ? join("&$name=", map {escape($_) } @{$info{$_}})
19731: : &escape($info{$_}) );
19732: } keys(%info)));
19733: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19734: if ($response->is_success) {
19735: my $data = JSON::DWIW->from_json($response->decoded_content);
19736: if (ref($data) eq 'HASH') {
19737: if ($data->{'success'}) {
19738: $captcha_chk = 1;
19739: }
19740: }
19741: }
19742: } else {
19743: my $captcha = Captcha::reCAPTCHA->new;
19744: my $captcha_result =
19745: $captcha->check_answer(
19746: $privkey,
1.1350 raeburn 19747: $ip,
1.1234 raeburn 19748: $env{'form.recaptcha_challenge_field'},
19749: $env{'form.recaptcha_response_field'},
19750: );
19751: if ($captcha_result->{is_valid}) {
19752: $captcha_chk = 1;
19753: }
1.1094 raeburn 19754: }
19755: return $captcha_chk;
19756: }
19757:
1.1174 raeburn 19758: sub emailusername_info {
1.1244 raeburn 19759: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19760: my %titles = &Apache::lonlocal::texthash (
19761: lastname => 'Last Name',
19762: firstname => 'First Name',
19763: institution => 'School/college/university',
19764: location => "School's city, state/province, country",
19765: web => "School's web address",
19766: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19767: id => 'Student/Employee ID',
1.1174 raeburn 19768: );
19769: return (\@fields,\%titles);
19770: }
19771:
1.1161 raeburn 19772: sub cleanup_html {
19773: my ($incoming) = @_;
19774: my $outgoing;
19775: if ($incoming ne '') {
19776: $outgoing = $incoming;
19777: $outgoing =~ s/;/;/g;
19778: $outgoing =~ s/\#/#/g;
19779: $outgoing =~ s/\&/&/g;
19780: $outgoing =~ s/</</g;
19781: $outgoing =~ s/>/>/g;
19782: $outgoing =~ s/\(/(/g;
19783: $outgoing =~ s/\)/)/g;
19784: $outgoing =~ s/"/"/g;
19785: $outgoing =~ s/'/'/g;
19786: $outgoing =~ s/\$/$/g;
19787: $outgoing =~ s{/}{/}g;
19788: $outgoing =~ s/=/=/g;
19789: $outgoing =~ s/\\/\/g
19790: }
19791: return $outgoing;
19792: }
19793:
1.1190 musolffc 19794: # Checks for critical messages and returns a redirect url if one exists.
19795: # $interval indicates how often to check for messages.
1.1282 raeburn 19796: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19797: sub critical_redirect {
1.1282 raeburn 19798: my ($interval,$context) = @_;
1.1356 raeburn 19799: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19800: return ();
19801: }
1.1190 musolffc 19802: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19803: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19804: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19805: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19806: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19807: if ($blocked) {
19808: my $checkrole = "cm./$cdom/$cnum";
19809: if ($env{'request.course.sec'} ne '') {
19810: $checkrole .= "/$env{'request.course.sec'}";
19811: }
19812: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19813: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19814: return;
19815: }
19816: }
19817: }
1.1190 musolffc 19818: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19819: $env{'user.name'});
19820: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19821: my $redirecturl;
1.1190 musolffc 19822: if ($what[0]) {
1.1356 raeburn 19823: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19824: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19825: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19826: return (1, $url);
1.1190 musolffc 19827: }
1.1191 raeburn 19828: }
19829: }
19830: return ();
1.1190 musolffc 19831: }
19832:
1.1174 raeburn 19833: # Use:
19834: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19835: #
19836: ##################################################
19837: # password associated functions #
19838: ##################################################
19839: sub des_keys {
19840: # Make a new key for DES encryption.
19841: # Each key has two parts which are returned separately.
19842: # Please note: Each key must be passed through the &hex function
19843: # before it is output to the web browser. The hex versions cannot
19844: # be used to decrypt.
19845: my @hexstr=('0','1','2','3','4','5','6','7',
19846: '8','9','a','b','c','d','e','f');
19847: my $lkey='';
19848: for (0..7) {
19849: $lkey.=$hexstr[rand(15)];
19850: }
19851: my $ukey='';
19852: for (0..7) {
19853: $ukey.=$hexstr[rand(15)];
19854: }
19855: return ($lkey,$ukey);
19856: }
19857:
19858: sub des_decrypt {
19859: my ($key,$cyphertext) = @_;
19860: my $keybin=pack("H16",$key);
19861: my $cypher;
19862: if ($Crypt::DES::VERSION>=2.03) {
19863: $cypher=new Crypt::DES $keybin;
19864: } else {
19865: $cypher=new DES $keybin;
19866: }
1.1233 raeburn 19867: my $plaintext='';
19868: my $cypherlength = length($cyphertext);
19869: my $numchunks = int($cypherlength/32);
19870: for (my $j=0; $j<$numchunks; $j++) {
19871: my $start = $j*32;
19872: my $cypherblock = substr($cyphertext,$start,32);
19873: my $chunk =
19874: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19875: $chunk .=
19876: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19877: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19878: $plaintext .= $chunk;
19879: }
1.1174 raeburn 19880: return $plaintext;
19881: }
19882:
1.1344 raeburn 19883: sub get_requested_shorturls {
1.1309 raeburn 19884: my ($cdom,$cnum,$navmap) = @_;
19885: return unless (ref($navmap));
1.1344 raeburn 19886: my ($numnew,$errors);
1.1309 raeburn 19887: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19888: if (@toshorten) {
19889: my (%maps,%resources,%titles);
19890: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19891: 'shorturls',$cdom,$cnum);
19892: if (keys(%resources)) {
1.1344 raeburn 19893: my %tocreate;
1.1309 raeburn 19894: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19895: my $symb = $resources{$item};
19896: if ($symb) {
19897: $tocreate{$cnum.'&'.$symb} = 1;
19898: }
19899: }
1.1344 raeburn 19900: if (keys(%tocreate)) {
19901: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19902: \%tocreate);
19903: }
1.1309 raeburn 19904: }
1.1344 raeburn 19905: }
19906: return ($numnew,$errors);
19907: }
19908:
19909: sub make_short_symbs {
19910: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19911: my ($numnew,@errors);
19912: if (ref($tocreateref) eq 'HASH') {
19913: my %tocreate = %{$tocreateref};
1.1309 raeburn 19914: if (keys(%tocreate)) {
19915: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19916: my $su = Short::URL->new(no_vowels => 1);
19917: my $init = '';
19918: my (%newunique,%addcourse,%courseonly,%failed);
19919: # get lock on tiny db
19920: my $now = time;
1.1344 raeburn 19921: if ($lockuser eq '') {
19922: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
19923: }
1.1309 raeburn 19924: my $lockhash = {
1.1344 raeburn 19925: "lock\0$now" => $lockuser,
1.1309 raeburn 19926: };
19927: my $tries = 0;
19928: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19929: my ($code,$error);
19930: while (($gotlock ne 'ok') && ($tries<3)) {
19931: $tries ++;
19932: sleep 1;
1.1319 raeburn 19933: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 19934: }
19935: if ($gotlock eq 'ok') {
19936: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19937: \%addcourse,\%courseonly,\%failed);
19938: if (keys(%failed)) {
19939: my $numfailed = scalar(keys(%failed));
19940: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19941: }
19942: if (keys(%newunique)) {
19943: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19944: if ($putres eq 'ok') {
19945: $numnew = scalar(keys(%newunique));
19946: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19947: unless ($newputres eq 'ok') {
19948: push(@errors,&mt('error: could not store course look-up of short URLs'));
19949: }
19950: } else {
19951: push(@errors,&mt('error: could not store unique six character URLs'));
19952: }
19953: }
19954: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19955: unless ($dellockres eq 'ok') {
19956: push(@errors,&mt('error: could not release lockfile'));
19957: }
19958: } else {
19959: push(@errors,&mt('error: could not obtain lockfile'));
19960: }
19961: if (keys(%courseonly)) {
19962: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19963: if ($result ne 'ok') {
19964: push(@errors,&mt('error: could not update course look-up of short URLs'));
19965: }
19966: }
19967: }
19968: }
19969: return ($numnew,\@errors);
19970: }
19971:
19972: sub shorten_symbs {
19973: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19974: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19975: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19976: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19977: my (%possibles,%collisions);
19978: foreach my $key (keys(%{$tocreate})) {
19979: my $num = String::CRC32::crc32($key);
19980: my $tiny = $su->encode($num,$init);
19981: if ($tiny) {
19982: $possibles{$tiny} = $key;
19983: }
19984: }
19985: if (!$init) {
19986: $init = 1;
19987: } else {
19988: $init ++;
19989: }
19990: if (keys(%possibles)) {
19991: my @posstiny = keys(%possibles);
19992: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19993: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19994: if (keys(%currtiny)) {
19995: foreach my $key (keys(%currtiny)) {
19996: next if ($currtiny{$key} eq '');
19997: if ($currtiny{$key} eq $possibles{$key}) {
19998: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19999: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
20000: $courseonly->{$tsymb} = $key;
20001: }
20002: } else {
20003: $collisions{$possibles{$key}} = 1;
20004: }
20005: delete($possibles{$key});
20006: }
20007: }
20008: foreach my $key (keys(%possibles)) {
20009: $newunique->{$key} = $possibles{$key};
20010: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
20011: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
20012: $addcourse->{$tsymb} = $key;
20013: }
20014: }
20015: }
20016: if (keys(%collisions)) {
20017: if ($init <5) {
20018: if (!$init) {
20019: $init = 1;
20020: } else {
20021: $init ++;
20022: }
20023: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
20024: $newunique,$addcourse,$courseonly,$failed);
20025: } else {
20026: foreach my $key (keys(%collisions)) {
20027: $failed->{$key} = 1;
20028: }
20029: }
20030: }
20031: return $init;
20032: }
20033:
1.1328 raeburn 20034: sub is_nonframeable {
1.1329 raeburn 20035: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
20036: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 20037: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 20038:
20039: $remprotocol = lc($remprotocol);
20040: $remhost = lc($remhost);
20041: my $remport = 80;
20042: if ($remprotocol eq 'https') {
20043: $remport = 443;
20044: }
1.1330 raeburn 20045: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 20046: if ($cached) {
20047: unless ($nocache) {
20048: if ($result) {
20049: return 1;
20050: } else {
20051: return 0;
20052: }
20053: }
20054: }
1.1328 raeburn 20055: my $uselink;
20056: my $request = new HTTP::Request('HEAD',$url);
20057: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
20058: if ($response->is_success()) {
20059: my $secpolicy = lc($response->header('content-security-policy'));
20060: my $xframeop = lc($response->header('x-frame-options'));
20061: $secpolicy =~ s/^\s+|\s+$//g;
20062: $xframeop =~ s/^\s+|\s+$//g;
20063: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 20064: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 20065: my ($origin,$protocol,$port);
20066: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
20067: $port = $ENV{'SERVER_PORT'};
20068: } else {
20069: $port = 80;
20070: }
20071: if ($absolute eq '') {
20072: $protocol = 'http:';
20073: if ($port == 443) {
20074: $protocol = 'https:';
20075: }
20076: $origin = $protocol.'//'.lc($hostname);
20077: } else {
20078: $origin = lc($absolute);
20079: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
20080: }
20081: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
20082: my $framepolicy = $1;
20083: $framepolicy =~ s/^\s+|\s+$//g;
20084: my @policies = split(/\s+/,$framepolicy);
20085: if (@policies) {
20086: if (grep(/^\Q'none'\E$/,@policies)) {
20087: $uselink = 1;
20088: } else {
20089: $uselink = 1;
20090: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
20091: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
20092: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
20093: undef($uselink);
20094: }
20095: if ($uselink) {
20096: if (grep(/^\Q'self'\E$/,@policies)) {
20097: if (($origin ne '') && ($remotehost eq $origin)) {
20098: undef($uselink);
20099: }
20100: }
20101: }
20102: if ($uselink) {
20103: my @possok;
20104: if ($ip ne '') {
20105: push(@possok,$ip);
20106: }
20107: my $hoststr = '';
20108: foreach my $part (reverse(split(/\./,$hostname))) {
20109: if ($hoststr eq '') {
20110: $hoststr = $part;
20111: } else {
20112: $hoststr = "$part.$hoststr";
20113: }
20114: if ($hoststr eq $hostname) {
20115: push(@possok,$hostname);
20116: } else {
20117: push(@possok,"*.$hoststr");
20118: }
20119: }
20120: if (@possok) {
20121: foreach my $poss (@possok) {
20122: last if (!$uselink);
20123: foreach my $policy (@policies) {
20124: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
20125: undef($uselink);
20126: last;
20127: }
20128: }
20129: }
20130: }
20131: }
20132: }
20133: }
20134: } elsif ($xframeop ne '') {
20135: $uselink = 1;
20136: my @policies = split(/\s*,\s*/,$xframeop);
20137: if (@policies) {
20138: unless (grep(/^deny$/,@policies)) {
20139: if ($origin ne '') {
20140: if (grep(/^sameorigin$/,@policies)) {
20141: if ($remotehost eq $origin) {
20142: undef($uselink);
20143: }
20144: }
20145: if ($uselink) {
20146: foreach my $policy (@policies) {
20147: if ($policy =~ /^allow-from\s*(.+)$/) {
20148: my $allowfrom = $1;
20149: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
20150: undef($uselink);
20151: last;
20152: }
20153: }
20154: }
20155: }
20156: }
20157: }
20158: }
20159: }
20160: }
20161: }
1.1329 raeburn 20162: if ($nocache) {
20163: if ($cached) {
20164: my $devalidate;
20165: if ($uselink && !$result) {
20166: $devalidate = 1;
20167: } elsif (!$uselink && $result) {
20168: $devalidate = 1;
20169: }
20170: if ($devalidate) {
20171: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
20172: }
20173: }
20174: } else {
20175: if ($uselink) {
20176: $result = 1;
20177: } else {
20178: $result = 0;
20179: }
20180: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
20181: }
1.1328 raeburn 20182: return $uselink;
20183: }
20184:
1.1359 raeburn 20185: sub page_menu {
20186: my ($menucolls,$menunum) = @_;
20187: my %menu;
20188: foreach my $item (split(/;/,$menucolls)) {
20189: my ($num,$value) = split(/\%/,$item);
20190: if ($num eq $menunum) {
20191: my @entries = split(/\&/,$value);
20192: foreach my $entry (@entries) {
20193: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 20194: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 20195: $menu{$name} = $fields;
20196: } else {
20197: my @shown;
20198: if ($fields =~ /,/) {
20199: @shown = split(/,/,$fields);
20200: } else {
20201: @shown = ($fields);
20202: }
20203: if (@shown) {
20204: foreach my $field (@shown) {
20205: next if ($field eq '');
20206: $menu{$field} = 1;
20207: }
20208: }
20209: }
20210: }
20211: }
20212: }
20213: return %menu;
20214: }
20215:
1.112 bowersj2 20216: 1;
20217: __END__;
1.41 ng 20218:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>