Annotation of loncom/interface/loncommon.pm, revision 1.1417
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1417 ! raeburn 4: # $Id: loncommon.pm,v 1.1416 2023/11/11 18:50:51 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.1383 raeburn 64: use Apache::lonnavmaps();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1409 raeburn 74: use LONCAPA::ltiutils;
1.1280 raeburn 75: use LONCAPA::LWPReq;
1.1395 raeburn 76: use LONCAPA::map();
1.1328 raeburn 77: use HTTP::Request;
1.657 raeburn 78: use DateTime::TimeZone;
1.1241 raeburn 79: use DateTime::Locale;
1.1220 raeburn 80: use Encode();
1.1091 foxr 81: use Text::Aspell;
1.1094 raeburn 82: use Authen::Captcha;
83: use Captcha::reCAPTCHA;
1.1234 raeburn 84: use JSON::DWIW;
1.1174 raeburn 85: use Crypt::DES;
86: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 87: use MIME::Lite;
88: use MIME::Types;
1.1292 raeburn 89: use File::Copy();
1.1300 raeburn 90: use File::Path();
1.1309 raeburn 91: use String::CRC32();
92: use Short::URL();
1.117 www 93:
1.517 raeburn 94: # ---------------------------------------------- Designs
95: use vars qw(%defaultdesign);
96:
1.22 www 97: my $readit;
98:
1.517 raeburn 99:
1.157 matthew 100: ##
101: ## Global Variables
102: ##
1.46 matthew 103:
1.643 foxr 104:
105: # ----------------------------------------------- SSI with retries:
106: #
107:
108: =pod
109:
1.648 raeburn 110: =head1 Server Side include with retries:
1.643 foxr 111:
112: =over 4
113:
1.648 raeburn 114: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 115:
116: Performs an ssi with some number of retries. Retries continue either
117: until the result is ok or until the retry count supplied by the
118: caller is exhausted.
119:
120: Inputs:
1.648 raeburn 121:
122: =over 4
123:
1.643 foxr 124: resource - Identifies the resource to insert.
1.648 raeburn 125:
1.643 foxr 126: retries - Count of the number of retries allowed.
1.648 raeburn 127:
1.643 foxr 128: form - Hash that identifies the rendering options.
129:
1.648 raeburn 130: =back
131:
132: Returns:
133:
134: =over 4
135:
1.643 foxr 136: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 137:
1.643 foxr 138: response - The response from the last attempt (which may or may not have been successful.
139:
1.648 raeburn 140: =back
141:
142: =back
143:
1.643 foxr 144: =cut
145:
146: sub ssi_with_retries {
147: my ($resource, $retries, %form) = @_;
148:
149:
150: my $ok = 0; # True if we got a good response.
151: my $content;
152: my $response;
153:
154: # Try to get the ssi done. within the retries count:
155:
156: do {
157: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
158: $ok = $response->is_success;
1.650 www 159: if (!$ok) {
160: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
161: }
1.643 foxr 162: $retries--;
163: } while (!$ok && ($retries > 0));
164:
165: if (!$ok) {
166: $content = ''; # On error return an empty content.
167: }
168: return ($content, $response);
169:
170: }
171:
172:
173:
1.20 www 174: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 175: my %language;
1.124 www 176: my %supported_language;
1.1088 foxr 177: my %supported_codes;
1.1048 foxr 178: my %latex_language; # For choosing hyphenation in <transl..>
179: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 180: my %cprtag;
1.192 taceyjo1 181: my %scprtag;
1.351 www 182: my %fe; my %fd; my %fm;
1.41 ng 183: my %category_extensions;
1.12 harris41 184:
1.46 matthew 185: # ---------------------------------------------- Thesaurus variables
1.144 matthew 186: #
187: # %Keywords:
188: # A hash used by &keyword to determine if a word is considered a keyword.
189: # $thesaurus_db_file
190: # Scalar containing the full path to the thesaurus database.
1.46 matthew 191:
192: my %Keywords;
193: my $thesaurus_db_file;
194:
1.144 matthew 195: #
196: # Initialize values from language.tab, copyright.tab, filetypes.tab,
197: # thesaurus.tab, and filecategories.tab.
198: #
1.18 www 199: BEGIN {
1.46 matthew 200: # Variable initialization
201: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
202: #
1.22 www 203: unless ($readit) {
1.12 harris41 204: # ------------------------------------------------------------------- languages
205: {
1.158 raeburn 206: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
207: '/language.tab';
1.1317 raeburn 208: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 209: while (my $line = <$fh>) {
210: next if ($line=~/^\#/);
211: chomp($line);
1.1088 foxr 212: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 213: $language{$key}=$val.' - '.$enc;
214: if ($sup) {
215: $supported_language{$key}=$sup;
1.1088 foxr 216: $supported_codes{$key} = $code;
1.158 raeburn 217: }
1.1048 foxr 218: if ($latex) {
219: $latex_language_bykey{$key} = $latex;
1.1088 foxr 220: $latex_language{$code} = $latex;
1.1048 foxr 221: }
1.158 raeburn 222: }
223: close($fh);
224: }
1.12 harris41 225: }
226: # ------------------------------------------------------------------ copyrights
227: {
1.158 raeburn 228: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
229: '/copyright.tab';
1.1317 raeburn 230: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 231: while (my $line = <$fh>) {
232: next if ($line=~/^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 235: $cprtag{$key}=$val;
236: }
237: close($fh);
238: }
1.12 harris41 239: }
1.351 www 240: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 241: {
242: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
243: '/source_copyright.tab';
1.1317 raeburn 244: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 249: $scprtag{$key}=$val;
250: }
251: close($fh);
252: }
253: }
1.63 www 254:
1.517 raeburn 255: # -------------------------------------------------------------- default domain designs
1.63 www 256: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 257: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 258: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 259: while (my $line = <$fh>) {
260: next if ($line =~ /^\#/);
261: chomp($line);
262: my ($key,$val)=(split(/\=/,$line));
263: if ($val) { $defaultdesign{$key}=$val; }
264: }
265: close($fh);
1.63 www 266: }
267:
1.15 harris41 268: # ------------------------------------------------------------- file categories
269: {
1.158 raeburn 270: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filecategories.tab';
1.1317 raeburn 272: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 277: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 278: }
279: close($fh);
280: }
281:
1.15 harris41 282: }
1.12 harris41 283: # ------------------------------------------------------------------ file types
284: {
1.158 raeburn 285: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
286: '/filetypes.tab';
1.1317 raeburn 287: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 288: while (my $line = <$fh>) {
289: next if ($line =~ /^\#/);
290: chomp($line);
291: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 292: if ($descr ne '') {
293: $fe{$ending}=lc($emb);
294: $fd{$ending}=$descr;
1.351 www 295: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 296: }
297: }
298: close($fh);
299: }
1.12 harris41 300: }
1.22 www 301: &Apache::lonnet::logthis(
1.705 tempelho 302: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 303: $readit=1;
1.46 matthew 304: } # end of unless($readit)
1.32 matthew 305:
306: }
1.112 bowersj2 307:
1.42 matthew 308: ###############################################################
309: ## HTML and Javascript Helper Functions ##
310: ###############################################################
311:
312: =pod
313:
1.112 bowersj2 314: =head1 HTML and Javascript Functions
1.42 matthew 315:
1.112 bowersj2 316: =over 4
317:
1.648 raeburn 318: =item * &browser_and_searcher_javascript()
1.112 bowersj2 319:
320: X<browsing, javascript>X<searching, javascript>Returns a string
321: containing javascript with two functions, C<openbrowser> and
322: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
323: tags.
1.42 matthew 324:
1.648 raeburn 325: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 326:
327: inputs: formname, elementname, only, omit
328:
329: formname and elementname indicate the name of the html form and name of
330: the element that the results of the browsing selection are to be placed in.
331:
332: Specifying 'only' will restrict the browser to displaying only files
1.185 www 333: with the given extension. Can be a comma separated list.
1.42 matthew 334:
335: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 336: with the given extension. Can be a comma separated list.
1.42 matthew 337:
1.648 raeburn 338: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 339:
340: Inputs: formname, elementname
341:
342: formname and elementname specify the name of the html form and the name
343: of the element the selection from the search results will be placed in.
1.542 raeburn 344:
1.42 matthew 345: =cut
346:
347: sub browser_and_searcher_javascript {
1.199 albertel 348: my ($mode)=@_;
349: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 350: my $resurl=&escape_single(&lastresurl());
1.42 matthew 351: return <<END;
1.219 albertel 352: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 353: var editbrowser = null;
1.135 albertel 354: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 355: var url = '$resurl/?';
1.42 matthew 356: if (editbrowser == null) {
357: url += 'launch=1&';
358: }
359: url += 'catalogmode=interactive&';
1.199 albertel 360: url += 'mode=$mode&';
1.611 albertel 361: url += 'inhibitmenu=yes&';
1.42 matthew 362: url += 'form=' + formname + '&';
363: if (only != null) {
364: url += 'only=' + only + '&';
1.217 albertel 365: } else {
366: url += 'only=&';
367: }
1.42 matthew 368: if (omit != null) {
369: url += 'omit=' + omit + '&';
1.217 albertel 370: } else {
371: url += 'omit=&';
372: }
1.135 albertel 373: if (titleelement != null) {
374: url += 'titleelement=' + titleelement + '&';
1.217 albertel 375: } else {
376: url += 'titleelement=&';
377: }
1.42 matthew 378: url += 'element=' + elementname + '';
379: var title = 'Browser';
1.435 albertel 380: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 381: options += ',width=700,height=600';
382: editbrowser = open(url,title,options,'1');
383: editbrowser.focus();
384: }
385: var editsearcher;
1.135 albertel 386: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 387: var url = '/adm/searchcat?';
388: if (editsearcher == null) {
389: url += 'launch=1&';
390: }
391: url += 'catalogmode=interactive&';
1.199 albertel 392: url += 'mode=$mode&';
1.42 matthew 393: url += 'form=' + formname + '&';
1.135 albertel 394: if (titleelement != null) {
395: url += 'titleelement=' + titleelement + '&';
1.217 albertel 396: } else {
397: url += 'titleelement=&';
398: }
1.42 matthew 399: url += 'element=' + elementname + '';
400: var title = 'Search';
1.435 albertel 401: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 402: options += ',width=700,height=600';
403: editsearcher = open(url,title,options,'1');
404: editsearcher.focus();
405: }
1.219 albertel 406: // END LON-CAPA Internal -->
1.42 matthew 407: END
1.170 www 408: }
409:
410: sub lastresurl {
1.258 albertel 411: if ($env{'environment.lastresurl'}) {
412: return $env{'environment.lastresurl'}
1.170 www 413: } else {
414: return '/res';
415: }
416: }
417:
418: sub storeresurl {
419: my $resurl=&Apache::lonnet::clutter(shift);
420: unless ($resurl=~/^\/res/) { return 0; }
421: $resurl=~s/\/$//;
422: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 423: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 424: return 1;
1.42 matthew 425: }
426:
1.74 www 427: sub studentbrowser_javascript {
1.111 www 428: unless (
1.258 albertel 429: (($env{'request.course.id'}) &&
1.302 albertel 430: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
431: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
432: '/'.$env{'request.course.sec'})
433: ))
1.258 albertel 434: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 435: ) { return ''; }
1.74 www 436: return (<<'ENDSTDBRW');
1.776 bisitz 437: <script type="text/javascript" language="Javascript">
1.824 bisitz 438: // <![CDATA[
1.74 www 439: var stdeditbrowser;
1.1413 raeburn 440: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv,uident) {
1.74 www 441: var url = '/adm/pickstudent?';
442: var filter;
1.558 albertel 443: if (!ignorefilter) {
444: eval('filter=document.'+formname+'.'+uname+'.value;');
445: }
1.74 www 446: if (filter != null) {
447: if (filter != '') {
448: url += 'filter='+filter+'&';
449: }
450: }
451: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 452: '&udomelement='+udom+
453: '&clicker='+clicker;
1.111 www 454: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 455: if (courseadv == 'condition') {
456: if (document.getElementById('courseadv')) {
457: courseadv = document.getElementById('courseadv').value;
458: }
459: }
460: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.1413 raeburn 461: if (uident !== '') { url+="&identelement="+uident; }
1.102 www 462: var title = 'Student_Browser';
1.74 www 463: var options = 'scrollbars=1,resizable=1,menubar=0';
464: options += ',width=700,height=600';
465: stdeditbrowser = open(url,title,options,'1');
466: stdeditbrowser.focus();
467: }
1.824 bisitz 468: // ]]>
1.74 www 469: </script>
470: ENDSTDBRW
471: }
1.42 matthew 472:
1.1003 www 473: sub resourcebrowser_javascript {
474: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 475: return (<<'ENDRESBRW');
1.1003 www 476: <script type="text/javascript" language="Javascript">
477: // <![CDATA[
478: var reseditbrowser;
1.1004 www 479: function openresbrowser(formname,reslink) {
1.1005 www 480: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 481: var title = 'Resource_Browser';
482: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 483: options += ',width=700,height=500';
1.1004 www 484: reseditbrowser = open(url,title,options,'1');
485: reseditbrowser.focus();
1.1003 www 486: }
487: // ]]>
488: </script>
1.1004 www 489: ENDRESBRW
1.1003 www 490: }
491:
1.74 www 492: sub selectstudent_link {
1.1413 raeburn 493: my ($form,$unameele,$udomele,$courseadv,$clickerid,$identelem)=@_;
1.999 www 494: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
495: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
496: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 497: if ($env{'request.course.id'}) {
1.302 albertel 498: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
499: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
500: '/'.$env{'request.course.sec'})) {
1.111 www 501: return '';
502: }
1.999 www 503: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 504: if ($courseadv eq 'only') {
505: $callargs .= ",'',1,'$courseadv'";
506: } elsif ($courseadv eq 'none') {
507: $callargs .= ",'','','$courseadv'";
508: } elsif ($courseadv eq 'condition') {
509: $callargs .= ",'','','$courseadv'";
1.1413 raeburn 510: } elsif ($identelem ne '') {
511: $callargs .= ",'','',''";
512: }
513: if ($identelem ne '') {
514: $callargs .= ",'".&Apache::lonhtmlcommon::entity_encode($identelem)."'";
1.793 raeburn 515: }
516: return '<span class="LC_nobreak">'.
517: '<a href="javascript:openstdbrowser('.$callargs.');">'.
518: &mt('Select User').'</a></span>';
1.74 www 519: }
1.258 albertel 520: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 521: $callargs .= ",'',1";
1.793 raeburn 522: return '<span class="LC_nobreak">'.
523: '<a href="javascript:openstdbrowser('.$callargs.');">'.
524: &mt('Select User').'</a></span>';
1.111 www 525: }
526: return '';
1.91 www 527: }
528:
1.1004 www 529: sub selectresource_link {
530: my ($form,$reslink,$arg)=@_;
531:
532: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
533: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
534: unless ($env{'request.course.id'}) { return $arg; }
535: return '<span class="LC_nobreak">'.
536: '<a href="javascript:openresbrowser('.$callargs.');">'.
537: $arg.'</a></span>';
538: }
539:
540:
541:
1.653 raeburn 542: sub authorbrowser_javascript {
543: return <<"ENDAUTHORBRW";
1.776 bisitz 544: <script type="text/javascript" language="JavaScript">
1.824 bisitz 545: // <![CDATA[
1.653 raeburn 546: var stdeditbrowser;
547:
548: function openauthorbrowser(formname,udom) {
549: var url = '/adm/pickauthor?';
550: url += 'form='+formname+'&roledom='+udom;
551: var title = 'Author_Browser';
552: var options = 'scrollbars=1,resizable=1,menubar=0';
553: options += ',width=700,height=600';
554: stdeditbrowser = open(url,title,options,'1');
555: stdeditbrowser.focus();
556: }
557:
1.824 bisitz 558: // ]]>
1.653 raeburn 559: </script>
560: ENDAUTHORBRW
561: }
562:
1.91 www 563: sub coursebrowser_javascript {
1.1116 raeburn 564: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 565: $credits_element,$instcode) = @_;
1.932 raeburn 566: my $wintitle = 'Course_Browser';
1.931 raeburn 567: if ($crstype eq 'Community') {
1.932 raeburn 568: $wintitle = 'Community_Browser';
1.909 raeburn 569: }
1.876 raeburn 570: my $id_functions = &javascript_index_functions();
571: my $output = '
1.776 bisitz 572: <script type="text/javascript" language="JavaScript">
1.824 bisitz 573: // <![CDATA[
1.468 raeburn 574: var stdeditbrowser;'."\n";
1.876 raeburn 575:
576: $output .= <<"ENDSTDBRW";
1.909 raeburn 577: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 578: var url = '/adm/pickcourse?';
1.895 raeburn 579: var formid = getFormIdByName(formname);
1.876 raeburn 580: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 581: if (domainfilter != null) {
582: if (domainfilter != '') {
583: url += 'domainfilter='+domainfilter+'&';
584: }
585: }
1.91 www 586: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 587: '&cdomelement='+udom+
588: '&cnameelement='+desc;
1.468 raeburn 589: if (extra_element !=null && extra_element != '') {
1.594 raeburn 590: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 591: url += '&roleelement='+extra_element;
592: if (domainfilter == null || domainfilter == '') {
593: url += '&domainfilter='+extra_element;
594: }
1.234 raeburn 595: }
1.468 raeburn 596: else {
597: if (formname == 'portform') {
598: url += '&setroles='+extra_element;
1.800 raeburn 599: } else {
600: if (formname == 'rules') {
601: url += '&fixeddom='+extra_element;
602: }
1.468 raeburn 603: }
604: }
1.230 raeburn 605: }
1.909 raeburn 606: if (type != null && type != '') {
607: url += '&type='+type;
608: }
609: if (type_elem != null && type_elem != '') {
610: url += '&typeelement='+type_elem;
611: }
1.872 raeburn 612: if (formname == 'ccrs') {
613: var ownername = document.forms[formid].ccuname.value;
614: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 615: url += '&cloner='+ownername+':'+ownerdom;
616: if (type == 'Course') {
617: url += '&crscode='+document.forms[formid].crscode.value;
618: }
1.1221 raeburn 619: }
620: if (formname == 'requestcrs') {
621: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 622: }
1.293 raeburn 623: if (multflag !=null && multflag != '') {
624: url += '&multiple='+multflag;
625: }
1.909 raeburn 626: var title = '$wintitle';
1.91 www 627: var options = 'scrollbars=1,resizable=1,menubar=0';
628: options += ',width=700,height=600';
629: stdeditbrowser = open(url,title,options,'1');
630: stdeditbrowser.focus();
631: }
1.876 raeburn 632: $id_functions
633: ENDSTDBRW
1.1116 raeburn 634: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
635: $output .= &setsec_javascript($sec_element,$formname,$role_element,
636: $credits_element);
1.876 raeburn 637: }
638: $output .= '
639: // ]]>
640: </script>';
641: return $output;
642: }
643:
644: sub javascript_index_functions {
645: return <<"ENDJS";
646:
647: function getFormIdByName(formname) {
648: for (var i=0;i<document.forms.length;i++) {
649: if (document.forms[i].name == formname) {
650: return i;
651: }
652: }
653: return -1;
654: }
655:
656: function getIndexByName(formid,item) {
657: for (var i=0;i<document.forms[formid].elements.length;i++) {
658: if (document.forms[formid].elements[i].name == item) {
659: return i;
660: }
661: }
662: return -1;
663: }
1.468 raeburn 664:
1.876 raeburn 665: function getDomainFromSelectbox(formname,udom) {
666: var userdom;
667: var formid = getFormIdByName(formname);
668: if (formid > -1) {
669: var domid = getIndexByName(formid,udom);
670: if (domid > -1) {
671: if (document.forms[formid].elements[domid].type == 'select-one') {
672: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
673: }
674: if (document.forms[formid].elements[domid].type == 'hidden') {
675: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 676: }
677: }
678: }
1.876 raeburn 679: return userdom;
680: }
681:
682: ENDJS
1.468 raeburn 683:
1.876 raeburn 684: }
685:
1.1017 raeburn 686: sub javascript_array_indexof {
1.1018 raeburn 687: return <<ENDJS;
1.1017 raeburn 688: <script type="text/javascript" language="JavaScript">
689: // <![CDATA[
690:
691: if (!Array.prototype.indexOf) {
692: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
693: "use strict";
694: if (this === void 0 || this === null) {
695: throw new TypeError();
696: }
697: var t = Object(this);
698: var len = t.length >>> 0;
699: if (len === 0) {
700: return -1;
701: }
702: var n = 0;
703: if (arguments.length > 0) {
704: n = Number(arguments[1]);
1.1088 foxr 705: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 706: n = 0;
707: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
708: n = (n > 0 || -1) * Math.floor(Math.abs(n));
709: }
710: }
711: if (n >= len) {
712: return -1;
713: }
714: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
715: for (; k < len; k++) {
716: if (k in t && t[k] === searchElement) {
717: return k;
718: }
719: }
720: return -1;
721: }
722: }
723:
724: // ]]>
725: </script>
726:
727: ENDJS
728:
729: }
730:
1.876 raeburn 731: sub userbrowser_javascript {
732: my $id_functions = &javascript_index_functions();
733: return <<"ENDUSERBRW";
734:
1.888 raeburn 735: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 736: var url = '/adm/pickuser?';
737: var userdom = getDomainFromSelectbox(formname,udom);
738: if (userdom != null) {
739: if (userdom != '') {
740: url += 'srchdom='+userdom+'&';
741: }
742: }
743: url += 'form=' + formname + '&unameelement='+uname+
744: '&udomelement='+udom+
745: '&ulastelement='+ulast+
746: '&ufirstelement='+ufirst+
747: '&uemailelement='+uemail+
1.881 raeburn 748: '&hideudomelement='+hideudom+
749: '&coursedom='+crsdom;
1.888 raeburn 750: if ((caller != null) && (caller != undefined)) {
751: url += '&caller='+caller;
752: }
1.876 raeburn 753: var title = 'User_Browser';
754: var options = 'scrollbars=1,resizable=1,menubar=0';
755: options += ',width=700,height=600';
756: var stdeditbrowser = open(url,title,options,'1');
757: stdeditbrowser.focus();
758: }
759:
1.888 raeburn 760: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 761: var formid = getFormIdByName(formname);
762: if (formid > -1) {
1.888 raeburn 763: var unameid = getIndexByName(formid,uname);
1.876 raeburn 764: var domid = getIndexByName(formid,udom);
765: var hidedomid = getIndexByName(formid,origdom);
766: if (hidedomid > -1) {
767: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 768: var unameval = document.forms[formid].elements[unameid].value;
769: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
770: if (domid > -1) {
771: var slct = document.forms[formid].elements[domid];
772: if (slct.type == 'select-one') {
773: var i;
774: for (i=0;i<slct.length;i++) {
775: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
776: }
777: }
778: if (slct.type == 'hidden') {
779: slct.value = fixeddom;
1.876 raeburn 780: }
781: }
1.468 raeburn 782: }
783: }
784: }
1.876 raeburn 785: return;
786: }
787:
788: $id_functions
789: ENDUSERBRW
1.468 raeburn 790: }
791:
792: sub setsec_javascript {
1.1116 raeburn 793: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 794: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
795: $communityrolestr);
796: if ($role_element ne '') {
797: my @allroles = ('st','ta','ep','in','ad');
798: foreach my $crstype ('Course','Community') {
799: if ($crstype eq 'Community') {
800: foreach my $role (@allroles) {
801: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
802: }
803: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
804: } else {
805: foreach my $role (@allroles) {
806: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
807: }
808: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
809: }
810: }
811: $rolestr = '"'.join('","',@allroles).'"';
812: $courserolestr = '"'.join('","',@courserolenames).'"';
813: $communityrolestr = '"'.join('","',@communityrolenames).'"';
814: }
1.468 raeburn 815: my $setsections = qq|
816: function setSect(sectionlist) {
1.629 raeburn 817: var sectionsArray = new Array();
818: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
819: sectionsArray = sectionlist.split(",");
820: }
1.468 raeburn 821: var numSections = sectionsArray.length;
822: document.$formname.$sec_element.length = 0;
823: if (numSections == 0) {
824: document.$formname.$sec_element.multiple=false;
825: document.$formname.$sec_element.size=1;
826: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
827: } else {
828: if (numSections == 1) {
829: document.$formname.$sec_element.multiple=false;
830: document.$formname.$sec_element.size=1;
831: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
832: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
833: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
834: } else {
835: for (var i=0; i<numSections; i++) {
836: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
837: }
838: document.$formname.$sec_element.multiple=true
839: if (numSections < 3) {
840: document.$formname.$sec_element.size=numSections;
841: } else {
842: document.$formname.$sec_element.size=3;
843: }
844: document.$formname.$sec_element.options[0].selected = false
845: }
846: }
1.91 www 847: }
1.905 raeburn 848:
849: function setRole(crstype) {
1.468 raeburn 850: |;
1.905 raeburn 851: if ($role_element eq '') {
852: $setsections .= ' return;
853: }
854: ';
855: } else {
856: $setsections .= qq|
857: var elementLength = document.$formname.$role_element.length;
858: var allroles = Array($rolestr);
859: var courserolenames = Array($courserolestr);
860: var communityrolenames = Array($communityrolestr);
861: if (elementLength != undefined) {
862: if (document.$formname.$role_element.options[5].value == 'cc') {
863: if (crstype == 'Course') {
864: return;
865: } else {
866: allroles[5] = 'co';
867: for (var i=0; i<6; i++) {
868: document.$formname.$role_element.options[i].value = allroles[i];
869: document.$formname.$role_element.options[i].text = communityrolenames[i];
870: }
871: }
872: } else {
873: if (crstype == 'Community') {
874: return;
875: } else {
876: allroles[5] = 'cc';
877: for (var i=0; i<6; i++) {
878: document.$formname.$role_element.options[i].value = allroles[i];
879: document.$formname.$role_element.options[i].text = courserolenames[i];
880: }
881: }
882: }
883: }
884: return;
885: }
886: |;
887: }
1.1116 raeburn 888: if ($credits_element) {
889: $setsections .= qq|
890: function setCredits(defaultcredits) {
891: document.$formname.$credits_element.value = defaultcredits;
892: return;
893: }
894: |;
895: }
1.468 raeburn 896: return $setsections;
897: }
898:
1.91 www 899: sub selectcourse_link {
1.909 raeburn 900: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
901: $typeelement) = @_;
902: my $type = $selecttype;
1.871 raeburn 903: my $linktext = &mt('Select Course');
904: if ($selecttype eq 'Community') {
1.909 raeburn 905: $linktext = &mt('Select Community');
1.1239 raeburn 906: } elsif ($selecttype eq 'Placement') {
907: $linktext = &mt('Select Placement Test');
1.906 raeburn 908: } elsif ($selecttype eq 'Course/Community') {
909: $linktext = &mt('Select Course/Community');
1.909 raeburn 910: $type = '';
1.1019 raeburn 911: } elsif ($selecttype eq 'Select') {
912: $linktext = &mt('Select');
913: $type = '';
1.871 raeburn 914: }
1.787 bisitz 915: return '<span class="LC_nobreak">'
916: ."<a href='"
917: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
918: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 919: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 920: ."'>".$linktext.'</a>'
1.787 bisitz 921: .'</span>';
1.74 www 922: }
1.42 matthew 923:
1.653 raeburn 924: sub selectauthor_link {
925: my ($form,$udom)=@_;
926: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
927: &mt('Select Author').'</a>';
928: }
929:
1.876 raeburn 930: sub selectuser_link {
1.881 raeburn 931: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 932: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 933: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 934: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 935: ');">'.$linktext.'</a>';
1.876 raeburn 936: }
937:
1.273 raeburn 938: sub check_uncheck_jscript {
939: my $jscript = <<"ENDSCRT";
940: function checkAll(field) {
941: if (field.length > 0) {
942: for (i = 0; i < field.length; i++) {
1.1093 raeburn 943: if (!field[i].disabled) {
944: field[i].checked = true;
945: }
1.273 raeburn 946: }
947: } else {
1.1093 raeburn 948: if (!field.disabled) {
949: field.checked = true;
950: }
1.273 raeburn 951: }
952: }
953:
954: function uncheckAll(field) {
955: if (field.length > 0) {
956: for (i = 0; i < field.length; i++) {
957: field[i].checked = false ;
1.543 albertel 958: }
959: } else {
1.273 raeburn 960: field.checked = false ;
961: }
962: }
963: ENDSCRT
964: return $jscript;
965: }
966:
1.656 www 967: sub select_timezone {
1.1387 raeburn 968: my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
969: my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";
1.659 raeburn 970: if ($includeempty) {
971: $output .= '<option value=""';
972: if (($selected eq '') || ($selected eq 'local')) {
973: $output .= ' selected="selected" ';
974: }
975: $output .= '> </option>';
976: }
1.657 raeburn 977: my @timezones = DateTime::TimeZone->all_names;
978: foreach my $tzone (@timezones) {
979: $output.= '<option value="'.$tzone.'"';
980: if ($tzone eq $selected) {
981: $output.=' selected="selected"';
982: }
983: $output.=">$tzone</option>\n";
1.656 www 984: }
985: $output.="</select>";
986: return $output;
987: }
1.273 raeburn 988:
1.687 raeburn 989: sub select_datelocale {
1.1256 raeburn 990: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
991: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 992: if ($includeempty) {
993: $output .= '<option value=""';
994: if ($selected eq '') {
995: $output .= ' selected="selected" ';
996: }
997: $output .= '> </option>';
998: }
1.1241 raeburn 999: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 1000: my (@possibles,%locale_names);
1.1241 raeburn 1001: my @locales = DateTime::Locale->ids();
1002: foreach my $id (@locales) {
1003: if ($id ne '') {
1004: my ($en_terr,$native_terr);
1005: my $loc = DateTime::Locale->load($id);
1006: if (ref($loc)) {
1007: $en_terr = $loc->name();
1008: $native_terr = $loc->native_name();
1.687 raeburn 1009: if (grep(/^en$/,@languages) || !@languages) {
1010: if ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: } elsif ($native_terr ne '') {
1013: $locale_names{$id} = $native_terr;
1014: }
1015: } else {
1016: if ($native_terr ne '') {
1017: $locale_names{$id} = $native_terr.' ';
1018: } elsif ($en_terr ne '') {
1019: $locale_names{$id} = '('.$en_terr.')';
1020: }
1021: }
1.1220 raeburn 1022: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1023: push(@possibles,$id);
1024: }
1.687 raeburn 1025: }
1026: }
1027: foreach my $item (sort(@possibles)) {
1028: $output.= '<option value="'.$item.'"';
1029: if ($item eq $selected) {
1030: $output.=' selected="selected"';
1031: }
1032: $output.=">$item";
1033: if ($locale_names{$item} ne '') {
1.1220 raeburn 1034: $output.=' '.$locale_names{$item};
1.687 raeburn 1035: }
1036: $output.="</option>\n";
1037: }
1038: $output.="</select>";
1039: return $output;
1040: }
1041:
1.792 raeburn 1042: sub select_language {
1.1256 raeburn 1043: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1044: my %langchoices;
1045: if ($includeempty) {
1.1117 raeburn 1046: %langchoices = ('' => 'No language preference');
1.792 raeburn 1047: }
1048: foreach my $id (&languageids()) {
1049: my $code = &supportedlanguagecode($id);
1050: if ($code) {
1051: $langchoices{$code} = &plainlanguagedescription($id);
1052: }
1053: }
1.1117 raeburn 1054: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1055: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1056: }
1057:
1.42 matthew 1058: =pod
1.36 matthew 1059:
1.1088 foxr 1060:
1061: =item * &list_languages()
1062:
1063: Returns an array reference that is suitable for use in language prompters.
1064: Each array element is itself a two element array. The first element
1065: is the language code. The second element a descsriptiuon of the
1066: language itself. This is suitable for use in e.g.
1067: &Apache::edit::select_arg (once dereferenced that is).
1068:
1069: =cut
1070:
1071: sub list_languages {
1072: my @lang_choices;
1073:
1074: foreach my $id (&languageids()) {
1075: my $code = &supportedlanguagecode($id);
1076: if ($code) {
1077: my $selector = $supported_codes{$id};
1078: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1079: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1080: }
1081: }
1082: return \@lang_choices;
1083: }
1084:
1085: =pod
1086:
1.648 raeburn 1087: =item * &linked_select_forms(...)
1.36 matthew 1088:
1089: linked_select_forms returns a string containing a <script></script> block
1090: and html for two <select> menus. The select menus will be linked in that
1091: changing the value of the first menu will result in new values being placed
1092: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1093: order unless a defined order is provided.
1.36 matthew 1094:
1095: linked_select_forms takes the following ordered inputs:
1096:
1097: =over 4
1098:
1.112 bowersj2 1099: =item * $formname, the name of the <form> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1102:
1.112 bowersj2 1103: =item * $firstdefault, the default value for the first menu
1.36 matthew 1104:
1.112 bowersj2 1105: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1106:
1.112 bowersj2 1107: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1108:
1.112 bowersj2 1109: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1110:
1.609 raeburn 1111: =item * $menuorder, the order of values in the first menu
1112:
1.1115 raeburn 1113: =item * $onchangefirst, additional javascript call to execute for an onchange
1114: event for the first <select> tag
1115:
1116: =item * $onchangesecond, additional javascript call to execute for an onchange
1117: event for the second <select> tag
1118:
1.1245 raeburn 1119: =item * $suffix, to differentiate separate uses of select2data javascript
1120: objects in a page.
1121:
1.41 ng 1122: =back
1123:
1.36 matthew 1124: Below is an example of such a hash. Only the 'text', 'default', and
1125: 'select2' keys must appear as stated. keys(%menu) are the possible
1126: values for the first select menu. The text that coincides with the
1.41 ng 1127: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1128: and text for the second menu are given in the hash pointed to by
1129: $menu{$choice1}->{'select2'}.
1130:
1.112 bowersj2 1131: my %menu = ( A1 => { text =>"Choice A1" ,
1132: default => "B3",
1133: select2 => {
1134: B1 => "Choice B1",
1135: B2 => "Choice B2",
1136: B3 => "Choice B3",
1137: B4 => "Choice B4"
1.609 raeburn 1138: },
1139: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1140: },
1141: A2 => { text =>"Choice A2" ,
1142: default => "C2",
1143: select2 => {
1144: C1 => "Choice C1",
1145: C2 => "Choice C2",
1146: C3 => "Choice C3"
1.609 raeburn 1147: },
1148: order => ['C2','C1','C3'],
1.112 bowersj2 1149: },
1150: A3 => { text =>"Choice A3" ,
1151: default => "D6",
1152: select2 => {
1153: D1 => "Choice D1",
1154: D2 => "Choice D2",
1155: D3 => "Choice D3",
1156: D4 => "Choice D4",
1157: D5 => "Choice D5",
1158: D6 => "Choice D6",
1159: D7 => "Choice D7"
1.609 raeburn 1160: },
1161: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1162: }
1163: );
1.36 matthew 1164:
1165: =cut
1166:
1167: sub linked_select_forms {
1168: my ($formname,
1169: $middletext,
1170: $firstdefault,
1171: $firstselectname,
1172: $secondselectname,
1.609 raeburn 1173: $hashref,
1174: $menuorder,
1.1115 raeburn 1175: $onchangefirst,
1.1245 raeburn 1176: $onchangesecond,
1177: $suffix
1.36 matthew 1178: ) = @_;
1179: my $second = "document.$formname.$secondselectname";
1180: my $first = "document.$formname.$firstselectname";
1181: # output the javascript to do the changing
1182: my $result = '';
1.776 bisitz 1183: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1184: $result.="// <![CDATA[\n";
1.1245 raeburn 1185: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1186: $" = '","';
1187: my $debug = '';
1188: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1189: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1190: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1191: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1192: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1193: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1194: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1195: @s2values = @{$hashref->{$s1}->{'order'}};
1196: }
1.36 matthew 1197: $result.="\"@s2values\");\n";
1.1245 raeburn 1198: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1199: my @s2texts;
1200: foreach my $value (@s2values) {
1.1263 raeburn 1201: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1202: }
1203: $result.="\"@s2texts\");\n";
1204: }
1205: $"=' ';
1206: $result.= <<"END";
1207:
1.1245 raeburn 1208: function select1${suffix}_changed() {
1.36 matthew 1209: // Determine new choice
1.1245 raeburn 1210: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1211: // update select2
1.1245 raeburn 1212: var values = select2data${suffix}[newvalue].values;
1213: var texts = select2data${suffix}[newvalue].texts;
1214: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1215: var i;
1216: // out with the old
1.1245 raeburn 1217: $second.options.length = 0;
1218: // in with the new
1.36 matthew 1219: for (i=0;i<values.length; i++) {
1220: $second.options[i] = new Option(values[i]);
1.143 matthew 1221: $second.options[i].value = values[i];
1.36 matthew 1222: $second.options[i].text = texts[i];
1223: if (values[i] == select2def) {
1224: $second.options[i].selected = true;
1225: }
1226: }
1227: }
1.824 bisitz 1228: // ]]>
1.36 matthew 1229: </script>
1230: END
1231: # output the initial values for the selection lists
1.1245 raeburn 1232: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1233: my @order = sort(keys(%{$hashref}));
1234: if (ref($menuorder) eq 'ARRAY') {
1235: @order = @{$menuorder};
1236: }
1237: foreach my $value (@order) {
1.36 matthew 1238: $result.=" <option value=\"$value\" ";
1.253 albertel 1239: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1240: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1241: }
1242: $result .= "</select>\n";
1.1400 raeburn 1243: my %select2;
1244: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1245: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1246: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1247: }
1248: }
1.36 matthew 1249: $result .= $middletext;
1.1115 raeburn 1250: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1251: if ($onchangesecond) {
1252: $result .= ' onchange="'.$onchangesecond.'"';
1253: }
1254: $result .= ">\n";
1.36 matthew 1255: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1256:
1257: my @secondorder = sort(keys(%select2));
1258: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1259: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1260: }
1261: foreach my $value (@secondorder) {
1.36 matthew 1262: $result.=" <option value=\"$value\" ";
1.253 albertel 1263: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1264: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1265: }
1266: $result .= "</select>\n";
1267: # return $debug;
1268: return $result;
1269: } # end of sub linked_select_forms {
1270:
1.45 matthew 1271: =pod
1.44 bowersj2 1272:
1.1381 raeburn 1273: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1274:
1.112 bowersj2 1275: Returns a string corresponding to an HTML link to the given help
1276: $topic, where $topic corresponds to the name of a .tex file in
1277: /home/httpd/html/adm/help/tex, with underscores replaced by
1278: spaces.
1279:
1280: $text will optionally be linked to the same topic, allowing you to
1281: link text in addition to the graphic. If you do not want to link
1282: text, but wish to specify one of the later parameters, pass an
1283: empty string.
1284:
1285: $stayOnPage is a value that will be interpreted as a boolean. If true,
1286: the link will not open a new window. If false, the link will open
1287: a new window using Javascript. (Default is false.)
1288:
1289: $width and $height are optional numerical parameters that will
1290: override the width and height of the popped up window, which may
1.973 raeburn 1291: be useful for certain help topics with big pictures included.
1292:
1293: $imgid is the id of the img tag used for the help icon. This may be
1294: used in a javascript call to switch the image src. See
1295: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1296:
1.1381 raeburn 1297: $links_target will optionally be set to a target (_top, _parent or _self).
1298:
1.44 bowersj2 1299: =cut
1300:
1301: sub help_open_topic {
1.1381 raeburn 1302: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1303: $text = "" if (not defined $text);
1.44 bowersj2 1304: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1305: $width = 500 if (not defined $width);
1.44 bowersj2 1306: $height = 400 if (not defined $height);
1307: my $filename = $topic;
1308: $filename =~ s/ /_/g;
1309:
1.48 bowersj2 1310: my $template = "";
1311: my $link;
1.572 banghart 1312:
1.159 www 1313: $topic=~s/\W/\_/g;
1.44 bowersj2 1314:
1.572 banghart 1315: if (!$stayOnPage) {
1.1033 www 1316: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1317: } elsif ($stayOnPage eq 'popup') {
1318: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1319: } else {
1.48 bowersj2 1320: $link = "/adm/help/${filename}.hlp";
1321: }
1322:
1323: # Add the text
1.1314 raeburn 1324: my $target = ' target="_top"';
1.1381 raeburn 1325: if ($links_target) {
1326: $target = ' target="'.$links_target.'"';
1327: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1328: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1329: $target = '';
1.1378 raeburn 1330: }
1.1380 raeburn 1331: if ($text ne "") {
1.763 bisitz 1332: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1333: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1334: .$text.'</a>';
1.48 bowersj2 1335: }
1336:
1.763 bisitz 1337: # (Always) Add the graphic
1.179 matthew 1338: my $title = &mt('Online Help');
1.667 raeburn 1339: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1340: if ($imgid ne '') {
1341: $imgid = ' id="'.$imgid.'"';
1342: }
1.1314 raeburn 1343: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1344: .'<img src="'.$helpicon.'" border="0"'
1345: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1346: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1347: .' /></a>';
1348: if ($text ne "") {
1349: $template.='</span>';
1350: }
1.44 bowersj2 1351: return $template;
1352:
1.106 bowersj2 1353: }
1354:
1355: # This is a quicky function for Latex cheatsheet editing, since it
1356: # appears in at least four places
1357: sub helpLatexCheatsheet {
1.1037 www 1358: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1359: my $out;
1.106 bowersj2 1360: my $addOther = '';
1.732 raeburn 1361: if ($topic) {
1.1037 www 1362: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1363: }
1364: $out = '<span>' # Start cheatsheet
1365: .$addOther
1366: .'<span>'
1.1037 www 1367: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1368: .'</span> <span>'
1.1037 www 1369: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1370: .'</span>';
1.732 raeburn 1371: unless ($not_author) {
1.1186 kruse 1372: $out .= '<span>'
1373: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1374: .'</span> <span>'
1375: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1376: .'</span>';
1.732 raeburn 1377: }
1.763 bisitz 1378: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1379: return $out;
1.172 www 1380: }
1381:
1.430 albertel 1382: sub general_help {
1383: my $helptopic='Student_Intro';
1384: if ($env{'request.role'}=~/^(ca|au)/) {
1385: $helptopic='Authoring_Intro';
1.907 raeburn 1386: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1387: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1388: } elsif ($env{'request.role'}=~/^dc/) {
1389: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1390: }
1391: return $helptopic;
1392: }
1393:
1394: sub update_help_link {
1395: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1396: my $origurl = $ENV{'REQUEST_URI'};
1397: $origurl=~s|^/~|/priv/|;
1398: my $timestamp = time;
1399: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1400: $$datum = &escape($$datum);
1401: }
1402:
1403: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1404: my $output .= <<"ENDOUTPUT";
1405: <script type="text/javascript">
1.824 bisitz 1406: // <![CDATA[
1.430 albertel 1407: banner_link = '$banner_link';
1.824 bisitz 1408: // ]]>
1.430 albertel 1409: </script>
1410: ENDOUTPUT
1411: return $output;
1412: }
1413:
1414: # now just updates the help link and generates a blue icon
1.193 raeburn 1415: sub help_open_menu {
1.1381 raeburn 1416: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1417: = @_;
1.949 droeschl 1418: $stayOnPage = 1;
1.430 albertel 1419: my $output;
1420: if ($component_help) {
1421: if (!$text) {
1422: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1423: $width,$height,'',$links_target);
1.430 albertel 1424: } else {
1425: my $help_text;
1426: $help_text=&unescape($topic);
1427: $output='<table><tr><td>'.
1428: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1429: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1430: }
1431: }
1432: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1433: return $output.$banner_link;
1434: }
1435:
1436: sub top_nav_help {
1.1369 raeburn 1437: my ($text,$linkattr) = @_;
1.436 albertel 1438: $text = &mt($text);
1.949 droeschl 1439: my $stay_on_page = 1;
1440:
1.1168 raeburn 1441: my ($link,$banner_link);
1442: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1443: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1444: : "javascript:helpMenu('open')";
1445: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1446: }
1.201 raeburn 1447: my $title = &mt('Get help');
1.1168 raeburn 1448: if ($link) {
1449: return <<"END";
1.436 albertel 1450: $banner_link
1.1369 raeburn 1451: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1452: END
1.1168 raeburn 1453: } else {
1454: return ' '.$text.' ';
1455: }
1.436 albertel 1456: }
1457:
1458: sub help_menu_js {
1.1154 raeburn 1459: my ($httphost) = @_;
1.949 droeschl 1460: my $stayOnPage = 1;
1.436 albertel 1461: my $width = 620;
1462: my $height = 600;
1.430 albertel 1463: my $helptopic=&general_help();
1.1154 raeburn 1464: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1465: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1466: my $start_page =
1467: &Apache::loncommon::start_page('Help Menu', undef,
1468: {'frameset' => 1,
1469: 'js_ready' => 1,
1.1154 raeburn 1470: 'use_absolute' => $httphost,
1.331 albertel 1471: 'add_entries' => {
1.1168 raeburn 1472: 'border' => '0',
1.579 raeburn 1473: 'rows' => "110,*",},});
1.331 albertel 1474: my $end_page =
1475: &Apache::loncommon::end_page({'frameset' => 1,
1476: 'js_ready' => 1,});
1477:
1.436 albertel 1478: my $template .= <<"ENDTEMPLATE";
1479: <script type="text/javascript">
1.877 bisitz 1480: // <![CDATA[
1.253 albertel 1481: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1482: var banner_link = '';
1.243 raeburn 1483: function helpMenu(target) {
1484: var caller = this;
1485: if (target == 'open') {
1486: var newWindow = null;
1487: try {
1.262 albertel 1488: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1489: }
1490: catch(error) {
1491: writeHelp(caller);
1492: return;
1493: }
1494: if (newWindow) {
1495: caller = newWindow;
1496: }
1.193 raeburn 1497: }
1.243 raeburn 1498: writeHelp(caller);
1499: return;
1500: }
1501: function writeHelp(caller) {
1.1168 raeburn 1502: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1503: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1504: caller.document.close();
1505: caller.focus();
1.193 raeburn 1506: }
1.877 bisitz 1507: // END LON-CAPA Internal -->
1.253 albertel 1508: // ]]>
1.436 albertel 1509: </script>
1.193 raeburn 1510: ENDTEMPLATE
1511: return $template;
1512: }
1513:
1.172 www 1514: sub help_open_bug {
1515: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1516: unless ($env{'user.adv'}) { return ''; }
1.172 www 1517: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1518: $text = "" if (not defined $text);
1519: $stayOnPage=1;
1.184 albertel 1520: $width = 600 if (not defined $width);
1521: $height = 600 if (not defined $height);
1.172 www 1522:
1523: $topic=~s/\W+/\+/g;
1524: my $link='';
1525: my $template='';
1.379 albertel 1526: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1527: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1528: if (!$stayOnPage)
1529: {
1530: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1531: }
1532: else
1533: {
1534: $link = $url;
1535: }
1.1314 raeburn 1536:
1.1382 raeburn 1537: my $target = '_top';
1538: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1539: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1540: $target = '_blank';
1.1378 raeburn 1541: }
1.1382 raeburn 1542:
1.172 www 1543: # Add the text
1544: if ($text ne "")
1545: {
1546: $template .=
1547: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1548: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1549: }
1550:
1551: # Add the graphic
1.179 matthew 1552: my $title = &mt('Report a Bug');
1.215 albertel 1553: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1554: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1555: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1556: ENDTEMPLATE
1557: if ($text ne '') { $template.='</td></tr></table>' };
1558: return $template;
1559:
1560: }
1561:
1562: sub help_open_faq {
1563: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1564: unless ($env{'user.adv'}) { return ''; }
1.172 www 1565: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1566: $text = "" if (not defined $text);
1567: $stayOnPage=1;
1568: $width = 350 if (not defined $width);
1569: $height = 400 if (not defined $height);
1570:
1571: $topic=~s/\W+/\+/g;
1572: my $link='';
1573: my $template='';
1574: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1575: if (!$stayOnPage)
1576: {
1577: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1578: }
1579: else
1580: {
1581: $link = $url;
1582: }
1583:
1584: # Add the text
1585: if ($text ne "")
1586: {
1587: $template .=
1.173 www 1588: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1589: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1590: }
1591:
1592: # Add the graphic
1.179 matthew 1593: my $title = &mt('View the FAQ');
1.215 albertel 1594: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1595: $template .= <<"ENDTEMPLATE";
1.436 albertel 1596: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1597: ENDTEMPLATE
1598: if ($text ne '') { $template.='</td></tr></table>' };
1599: return $template;
1600:
1.44 bowersj2 1601: }
1.37 matthew 1602:
1.180 matthew 1603: ###############################################################
1604: ###############################################################
1605:
1.45 matthew 1606: =pod
1607:
1.648 raeburn 1608: =item * &change_content_javascript():
1.256 matthew 1609:
1610: This and the next function allow you to create small sections of an
1611: otherwise static HTML page that you can update on the fly with
1612: Javascript, even in Netscape 4.
1613:
1614: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1615: must be written to the HTML page once. It will prove the Javascript
1616: function "change(name, content)". Calling the change function with the
1617: name of the section
1618: you want to update, matching the name passed to C<changable_area>, and
1619: the new content you want to put in there, will put the content into
1620: that area.
1621:
1622: B<Note>: Netscape 4 only reserves enough space for the changable area
1623: to contain room for the original contents. You need to "make space"
1624: for whatever changes you wish to make, and be B<sure> to check your
1625: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1626: it's adequate for updating a one-line status display, but little more.
1627: This script will set the space to 100% width, so you only need to
1628: worry about height in Netscape 4.
1629:
1630: Modern browsers are much less limiting, and if you can commit to the
1631: user not using Netscape 4, this feature may be used freely with
1632: pretty much any HTML.
1633:
1634: =cut
1635:
1636: sub change_content_javascript {
1637: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1638: if ($env{'browser.type'} eq 'netscape' &&
1639: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1640: return (<<NETSCAPE4);
1641: function change(name, content) {
1642: doc = document.layers[name+"___escape"].layers[0].document;
1643: doc.open();
1644: doc.write(content);
1645: doc.close();
1646: }
1647: NETSCAPE4
1648: } else {
1649: # Otherwise, we need to use semi-standards-compliant code
1650: # (technically, "innerHTML" isn't standard but the equivalent
1651: # is really scary, and every useful browser supports it
1652: return (<<DOMBASED);
1653: function change(name, content) {
1654: element = document.getElementById(name);
1655: element.innerHTML = content;
1656: }
1657: DOMBASED
1658: }
1659: }
1660:
1661: =pod
1662:
1.648 raeburn 1663: =item * &changable_area($name,$origContent):
1.256 matthew 1664:
1665: This provides a "changable area" that can be modified on the fly via
1666: the Javascript code provided in C<change_content_javascript>. $name is
1667: the name you will use to reference the area later; do not repeat the
1668: same name on a given HTML page more then once. $origContent is what
1669: the area will originally contain, which can be left blank.
1670:
1671: =cut
1672:
1673: sub changable_area {
1674: my ($name, $origContent) = @_;
1675:
1.258 albertel 1676: if ($env{'browser.type'} eq 'netscape' &&
1677: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1678: # If this is netscape 4, we need to use the Layer tag
1679: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1680: } else {
1681: return "<span id='$name'>$origContent</span>";
1682: }
1683: }
1684:
1685: =pod
1686:
1.648 raeburn 1687: =item * &viewport_geometry_js
1.590 raeburn 1688:
1689: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1690:
1691: =cut
1692:
1693:
1694: sub viewport_geometry_js {
1695: return <<"GEOMETRY";
1696: var Geometry = {};
1697: function init_geometry() {
1698: if (Geometry.init) { return };
1699: Geometry.init=1;
1700: if (window.innerHeight) {
1701: Geometry.getViewportHeight = function() { return window.innerHeight; };
1702: Geometry.getViewportWidth = function() { return window.innerWidth; };
1703: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1704: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1705: }
1706: else if (document.documentElement && document.documentElement.clientHeight) {
1707: Geometry.getViewportHeight =
1708: function() { return document.documentElement.clientHeight; };
1709: Geometry.getViewportWidth =
1710: function() { return document.documentElement.clientWidth; };
1711:
1712: Geometry.getHorizontalScroll =
1713: function() { return document.documentElement.scrollLeft; };
1714: Geometry.getVerticalScroll =
1715: function() { return document.documentElement.scrollTop; };
1716: }
1717: else if (document.body.clientHeight) {
1718: Geometry.getViewportHeight =
1719: function() { return document.body.clientHeight; };
1720: Geometry.getViewportWidth =
1721: function() { return document.body.clientWidth; };
1722: Geometry.getHorizontalScroll =
1723: function() { return document.body.scrollLeft; };
1724: Geometry.getVerticalScroll =
1725: function() { return document.body.scrollTop; };
1726: }
1727: }
1728:
1729: GEOMETRY
1730: }
1731:
1732: =pod
1733:
1.648 raeburn 1734: =item * &viewport_size_js()
1.590 raeburn 1735:
1736: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1737:
1738: =cut
1739:
1740: sub viewport_size_js {
1741: my $geometry = &viewport_geometry_js();
1742: return <<"DIMS";
1743:
1744: $geometry
1745:
1746: function getViewportDims(width,height) {
1747: init_geometry();
1748: width.value = Geometry.getViewportWidth();
1749: height.value = Geometry.getViewportHeight();
1750: return;
1751: }
1752:
1753: DIMS
1754: }
1755:
1756: =pod
1757:
1.648 raeburn 1758: =item * &resize_textarea_js()
1.565 albertel 1759:
1760: emits the needed javascript to resize a textarea to be as big as possible
1761:
1762: creates a function resize_textrea that takes two IDs first should be
1763: the id of the element to resize, second should be the id of a div that
1764: surrounds everything that comes after the textarea, this routine needs
1765: to be attached to the <body> for the onload and onresize events.
1766:
1.648 raeburn 1767: =back
1.565 albertel 1768:
1769: =cut
1770:
1771: sub resize_textarea_js {
1.590 raeburn 1772: my $geometry = &viewport_geometry_js();
1.565 albertel 1773: return <<"RESIZE";
1774: <script type="text/javascript">
1.824 bisitz 1775: // <![CDATA[
1.590 raeburn 1776: $geometry
1.565 albertel 1777:
1.588 albertel 1778: function getX(element) {
1779: var x = 0;
1780: while (element) {
1781: x += element.offsetLeft;
1782: element = element.offsetParent;
1783: }
1784: return x;
1785: }
1786: function getY(element) {
1787: var y = 0;
1788: while (element) {
1789: y += element.offsetTop;
1790: element = element.offsetParent;
1791: }
1792: return y;
1793: }
1794:
1795:
1.565 albertel 1796: function resize_textarea(textarea_id,bottom_id) {
1797: init_geometry();
1798: var textarea = document.getElementById(textarea_id);
1799: //alert(textarea);
1800:
1.588 albertel 1801: var textarea_top = getY(textarea);
1.565 albertel 1802: var textarea_height = textarea.offsetHeight;
1803: var bottom = document.getElementById(bottom_id);
1.588 albertel 1804: var bottom_top = getY(bottom);
1.565 albertel 1805: var bottom_height = bottom.offsetHeight;
1806: var window_height = Geometry.getViewportHeight();
1.588 albertel 1807: var fudge = 23;
1.565 albertel 1808: var new_height = window_height-fudge-textarea_top-bottom_height;
1809: if (new_height < 300) {
1810: new_height = 300;
1811: }
1812: textarea.style.height=new_height+'px';
1813: }
1.824 bisitz 1814: // ]]>
1.565 albertel 1815: </script>
1816: RESIZE
1817:
1818: }
1819:
1.1205 golterma 1820: sub colorfuleditor_js {
1.1248 raeburn 1821: my $browse_or_search;
1822: my $respath;
1823: my ($cnum,$cdom) = &crsauthor_url();
1824: if ($cnum) {
1825: $respath = "/res/$cdom/$cnum/";
1826: my %js_lt = &Apache::lonlocal::texthash(
1827: sunm => 'Sub-directory name',
1828: save => 'Save page to make this permanent',
1829: );
1830: &js_escape(\%js_lt);
1.1400 raeburn 1831: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1832: $browse_or_search = <<"END";
1833:
1.1400 raeburn 1834: $showfile_js
1835:
1.1248 raeburn 1836: function toggleChooser(form,element,titleid,only,search) {
1837: var disp = 'none';
1838: if (document.getElementById('chooser_'+element)) {
1839: var curr = document.getElementById('chooser_'+element).style.display;
1840: if (curr == 'none') {
1841: disp='inline';
1842: if (form.elements['chooser_'+element].length) {
1843: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1844: form.elements['chooser_'+element][i].checked = false;
1845: }
1846: }
1847: toggleResImport(form,element);
1848: }
1849: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1850: var dirsel = '';
1851: var filesel = '';
1852: if (document.getElementById('chooser_'+element+'_crsres')) {
1853: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1854: if (currcrsres == 'none') {
1855: dirsel = 'coursepath_'+element;
1856: var filesel = 'coursefile_'+element;
1857: var include;
1858: if (document.getElementById('crsres_include_'+element)) {
1859: include = document.getElementById('crsres_include_'+element).value;
1860: }
1.1402 raeburn 1861: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 1862: }
1863: }
1864: if (document.getElementById('chooser_'+element+'_upload')) {
1865: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1866: if (currcrsupload == 'none') {
1867: dirsel = 'crsauthorpath_'+element;
1868: filesel = '';
1.1402 raeburn 1869: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 1870: }
1871: }
1.1248 raeburn 1872: }
1873: }
1874:
1.1400 raeburn 1875: function toggleCrsFile(form,element) {
1.1248 raeburn 1876: if (document.getElementById('chooser_'+element+'_crsres')) {
1877: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1878: if (curr == 'none') {
1.1400 raeburn 1879: if (document.getElementById('coursepath_'+element)) {
1880: var numdirs;
1881: if (document.getElementById('coursepath_'+element).length) {
1882: numdirs = document.getElementById('coursepath_'+element).length;
1883: }
1.1402 raeburn 1884: if ((document.getElementById('hascrsres_'+element)) &&
1885: (document.getElementById('nocrsres_'+element))) {
1886: if (numdirs) {
1887: document.getElementById('hascrsres_'+element).style.display='inline-block';
1888: document.getElementById('nocrsres_'+element).style.display='none';
1889: } else {
1890: document.getElementById('hascrsres_'+element).style.display='none';
1891: document.getElementById('nocrsres_'+element).style.display='inline-block';
1892: }
1893: }
1.1248 raeburn 1894: form.elements['coursepath_'+element].selectedIndex = 0;
1895: if (numdirs > 1) {
1.1400 raeburn 1896: var selelem = form.elements['coursefile_'+element];
1897: var i, len = selelem.options.length -1;
1898: if (len >=0) {
1899: for (i = len; i >= 0; i--) {
1900: selelem.remove(i);
1901: }
1902: selelem.options[0] = new Option('','');
1903: }
1.1248 raeburn 1904: }
1905: }
1.1400 raeburn 1906: }
1.1248 raeburn 1907: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1908: }
1909: if (document.getElementById('chooser_'+element+'_upload')) {
1910: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1911: if (document.getElementById('uploadcrsres_'+element)) {
1912: document.getElementById('uploadcrsres_'+element).value = '';
1913: }
1914: }
1915: return;
1916: }
1917:
1.1400 raeburn 1918: function toggleCrsUpload(form,element) {
1.1248 raeburn 1919: if (document.getElementById('chooser_'+element+'_crsres')) {
1920: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1921: }
1922: if (document.getElementById('chooser_'+element+'_upload')) {
1923: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1924: if (curr == 'none') {
1.1400 raeburn 1925: form.elements['newsubdir_'+element][0].checked = true;
1926: toggleNewsubdir(form,element);
1927: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1928: if (document.getElementById('uploadcrsres_'+element)) {
1929: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1930: }
1931: }
1932: }
1933: return;
1934: }
1935:
1936: function toggleResImport(form,element) {
1937: var choices = new Array('crsres','upload');
1938: for (var i=0; i<choices.length; i++) {
1939: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1940: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1941: }
1942: }
1943: }
1944:
1945: function toggleNewsubdir(form,element) {
1946: var newsub = form.elements['newsubdir_'+element];
1947: if (newsub) {
1948: if (newsub.length) {
1949: for (var j=0; j<newsub.length; j++) {
1950: if (newsub[j].checked) {
1951: if (document.getElementById('newsubdirname_'+element)) {
1952: if (newsub[j].value == '1') {
1953: document.getElementById('newsubdirname_'+element).type = "text";
1954: if (document.getElementById('newsubdir_'+element)) {
1955: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1956: }
1957: } else {
1958: document.getElementById('newsubdirname_'+element).type = "hidden";
1959: document.getElementById('newsubdirname_'+element).value = "";
1960: document.getElementById('newsubdir_'+element).innerHTML = "";
1961: }
1962: }
1963: break;
1964: }
1965: }
1966: }
1967: }
1968: }
1969:
1970: function updateCrsFile(form,element) {
1971: var directory = form.elements['coursepath_'+element];
1972: var filename = form.elements['coursefile_'+element];
1973: var path = directory.options[directory.selectedIndex].value;
1974: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1975: if (file != '') {
1976: form.elements[element].value = '$respath';
1977: if (path == '/') {
1978: form.elements[element].value += file;
1979: } else {
1980: form.elements[element].value += path+'/'+file;
1981: }
1982: unClean();
1983: if (document.getElementById('previewimg_'+element)) {
1984: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1985: var newsrc = document.getElementById('previewimg_'+element).src;
1986: }
1987: if (document.getElementById('showimg_'+element)) {
1988: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1989: }
1.1248 raeburn 1990: }
1991: toggleChooser(form,element);
1992: return;
1993: }
1994:
1995: function uploadDone(suffix,name) {
1996: if (name) {
1997: document.forms["lonhomework"].elements[suffix].value = name;
1998: unClean();
1999: toggleChooser(document.forms["lonhomework"],suffix);
2000: }
2001: }
2002:
2003: \$(document).ready(function(){
2004:
2005: \$(document).delegate('form :submit', 'click', function( event ) {
2006: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2007: var buttonId = this.id;
2008: var suffix = buttonId.toString();
2009: suffix = suffix.replace(/^crsupload_/,'');
2010: event.preventDefault();
2011: document.lonhomework.target = 'crsupload_target_'+suffix;
2012: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2013: \$(this.form).submit();
2014: document.lonhomework.target = '';
2015: if (document.getElementById('crsuploadto_'+suffix)) {
2016: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2017: }
2018: return false;
2019: }
2020: });
2021: });
2022: END
2023: }
1.1205 golterma 2024: return <<"COLORFULEDIT"
2025: <script type="text/javascript">
2026: // <![CDATA[>
2027: function fold_box(curDepth, lastresource){
2028:
2029: // we need a list because there can be several blocks you need to fold in one tag
2030: var block = document.getElementsByName('foldblock_'+curDepth);
2031: // but there is only one folding button per tag
2032: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2033:
2034: if(block.item(0).style.display == 'none'){
2035:
2036: foldbutton.value = '@{[&mt("Hide")]}';
2037: for (i = 0; i < block.length; i++){
2038: block.item(i).style.display = '';
2039: }
2040: }else{
2041:
2042: foldbutton.value = '@{[&mt("Show")]}';
2043: for (i = 0; i < block.length; i++){
2044: // block.item(i).style.visibility = 'collapse';
2045: block.item(i).style.display = 'none';
2046: }
2047: };
2048: saveState(lastresource);
2049: }
2050:
2051: function saveState (lastresource) {
2052:
2053: var tag_list = getTagList();
2054: if(tag_list != null){
2055: var timestamp = new Date().getTime();
2056: var key = lastresource;
2057:
2058: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2059: // starting with timestamp
2060: var value = timestamp+';';
2061:
2062: // building the list of key-value pairs
2063: for(var i = 0; i < tag_list.length; i++){
2064: value += tag_list[i]+',';
2065: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2066: }
2067:
2068: // only iterate whole storage if nothing to override
2069: if(localStorage.getItem(key) == null){
2070:
2071: // prevent storage from growing large
2072: if(localStorage.length > 50){
2073: var regex_getTimestamp = /^(?:\d)+;/;
2074: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2075: var oldest_key;
2076:
2077: for(var i = 1; i < localStorage.length; i++){
2078: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2079: oldest_key = localStorage.key(i);
2080: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2081: }
2082: }
2083: localStorage.removeItem(oldest_key);
2084: }
2085: }
2086: localStorage.setItem(key,value);
2087: }
2088: }
2089:
2090: // restore folding status of blocks (on page load)
2091: function restoreState (lastresource) {
2092: if(localStorage.getItem(lastresource) != null){
2093: var key = lastresource;
2094: var value = localStorage.getItem(key);
2095: var regex_delTimestamp = /^\d+;/;
2096:
2097: value.replace(regex_delTimestamp, '');
2098:
2099: var valueArr = value.split(';');
2100: var pairs;
2101: var elements;
2102: for (var i = 0; i < valueArr.length; i++){
2103: pairs = valueArr[i].split(',');
2104: elements = document.getElementsByName(pairs[0]);
2105:
2106: for (var j = 0; j < elements.length; j++){
2107: elements[j].style.display = pairs[1];
2108: if (pairs[1] == "none"){
2109: var regex_id = /([_\\d]+)\$/;
2110: regex_id.exec(pairs[0]);
2111: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2112: }
2113: }
2114: }
2115: }
2116: }
2117:
2118: function getTagList () {
2119:
2120: var stringToSearch = document.lonhomework.innerHTML;
2121:
2122: var ret = new Array();
2123: var regex_findBlock = /(foldblock_.*?)"/g;
2124: var tag_list = stringToSearch.match(regex_findBlock);
2125:
2126: if(tag_list != null){
2127: for(var i = 0; i < tag_list.length; i++){
2128: ret.push(tag_list[i].replace(/"/, ''));
2129: }
2130: }
2131: return ret;
2132: }
2133:
2134: function saveScrollPosition (resource) {
2135: var tag_list = getTagList();
2136:
2137: // we dont always want to jump to the first block
2138: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2139: if(\$(window).scrollTop() > 170){
2140: if(tag_list != null){
2141: var result;
2142: for(var i = 0; i < tag_list.length; i++){
2143: if(isElementInViewport(tag_list[i])){
2144: result += tag_list[i]+';';
2145: }
2146: }
2147: sessionStorage.setItem('anchor_'+resource, result);
2148: }
2149: } else {
2150: // we dont need to save zero, just delete the item to leave everything tidy
2151: sessionStorage.removeItem('anchor_'+resource);
2152: }
2153: }
2154:
2155: function restoreScrollPosition(resource){
2156:
2157: var elem = sessionStorage.getItem('anchor_'+resource);
2158: if(elem != null){
2159: var tag_list = elem.split(';');
2160: var elem_list;
2161:
2162: for(var i = 0; i < tag_list.length; i++){
2163: elem_list = document.getElementsByName(tag_list[i]);
2164:
2165: if(elem_list.length > 0){
2166: elem = elem_list[0];
2167: break;
2168: }
2169: }
2170: elem.scrollIntoView();
2171: }
2172: }
2173:
2174: function isElementInViewport(el) {
2175:
2176: // change to last element instead of first
2177: var elem = document.getElementsByName(el);
2178: var rect = elem[0].getBoundingClientRect();
2179:
2180: return (
2181: rect.top >= 0 &&
2182: rect.left >= 0 &&
2183: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2184: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2185: );
2186: }
2187:
2188: function autosize(depth){
2189: var cmInst = window['cm'+depth];
2190: var fitsizeButton = document.getElementById('fitsize'+depth);
2191:
2192: // is fixed size, switching to dynamic
2193: if (sessionStorage.getItem("autosized_"+depth) == null) {
2194: cmInst.setSize("","auto");
2195: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2196: sessionStorage.setItem("autosized_"+depth, "yes");
2197:
2198: // is dynamic size, switching to fixed
2199: } else {
2200: cmInst.setSize("","300px");
2201: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2202: sessionStorage.removeItem("autosized_"+depth);
2203: }
2204: }
2205:
1.1248 raeburn 2206: $browse_or_search
1.1205 golterma 2207:
2208: // ]]>
2209: </script>
2210: COLORFULEDIT
2211: }
2212:
2213: sub xmleditor_js {
2214: return <<XMLEDIT
2215: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2216: <script type="text/javascript">
2217: // <![CDATA[>
2218:
2219: function saveScrollPosition (resource) {
2220:
2221: var scrollPos = \$(window).scrollTop();
2222: sessionStorage.setItem(resource,scrollPos);
2223: }
2224:
2225: function restoreScrollPosition(resource){
2226:
2227: var scrollPos = sessionStorage.getItem(resource);
2228: \$(window).scrollTop(scrollPos);
2229: }
2230:
2231: // unless internet explorer
2232: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2233:
2234: \$(document).ready(function() {
2235: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2236: });
2237: }
2238:
2239: // inserts text at cursor position into codemirror (xml editor only)
2240: function insertText(text){
2241: cm.focus();
2242: var curPos = cm.getCursor();
2243: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2244: }
2245: // ]]>
2246: </script>
2247: XMLEDIT
2248: }
2249:
2250: sub insert_folding_button {
2251: my $curDepth = $Apache::lonxml::curdepth;
2252: my $lastresource = $env{'request.ambiguous'};
2253:
2254: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2255: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2256: }
2257:
1.1248 raeburn 2258: sub crsauthor_url {
2259: my ($url) = @_;
2260: if ($url eq '') {
2261: $url = $ENV{'REQUEST_URI'};
2262: }
2263: my ($cnum,$cdom);
2264: if ($env{'request.course.id'}) {
2265: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2266: if ($audom ne '' && $auname ne '') {
2267: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2268: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2269: $cnum = $auname;
2270: $cdom = $audom;
2271: }
2272: }
2273: }
2274: return ($cnum,$cdom);
2275: }
2276:
2277: sub import_crsauthor_form {
1.1400 raeburn 2278: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2279: return (0) unless ($env{'request.course.id'});
2280: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2281: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2282: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2283: return (0) unless (($cnum ne '') && ($cdom ne ''));
2284: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2285: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2286:
1.1248 raeburn 2287: if (grep(/^\Q$crshome\E$/,@ids)) {
2288: $is_home = 1;
2289: }
1.1400 raeburn 2290: $toppath = "/priv/$cdom/$cnum";
2291: my $nonemptydir = 1;
2292: my $js_only;
2293: if ($only) {
2294: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2295: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2296: }
2297: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2298: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2299: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2300: my %lt = &Apache::lonlocal::texthash (
2301: fnam => 'Filename',
2302: dire => 'Directory',
1.1400 raeburn 2303: se => 'Select',
1.1248 raeburn 2304: );
1.1402 raeburn 2305: $output = $lt{'dire'}.': '.
1.1400 raeburn 2306: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2307: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2308: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2309: if ($files{'/'}) {
2310: $output .= '<option value="/">/</option>'."\n";
2311: }
1.1400 raeburn 2312: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2313: next if ($key eq '/');
1.1400 raeburn 2314: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2315: }
2316: $output .= '</select><br />'."\n".
1.1402 raeburn 2317: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2318: '<option value="" selected="selected"></option>'."\n".
1.1402 raeburn 2319: '</select>'."\n".
2320: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2321: return ($numdirs,$output);
2322: }
2323:
2324: sub show_crsfiles_js {
2325: my $excluderef = &Apache::lonnet::priv_exclude();
2326: my $se = &js_escape(&mt('Select'));
2327: my $exclude;
2328: if (ref($excluderef) eq 'HASH') {
2329: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2330: }
2331: my $js = <<"END";
2332:
2333:
1.1402 raeburn 2334: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2335: var relpath = '';
2336: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2337: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2338: if (currdir == '') {
2339: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2340: selelem = form.elements[filesel];
2341: var j, numfiles = selelem.options.length -1;
2342: if (numfiles >=0) {
2343: for (j = numfiles; j >= 0; j--) {
2344: selelem.remove(j);
2345: }
2346: }
2347: if (selelem.options.length == 0) {
2348: selelem.options[selelem.options.length] = new Option('','');
2349: selelem.selectedIndex = 0;
1.1248 raeburn 2350: }
2351: }
1.1400 raeburn 2352: return;
2353: } else {
2354: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2355: }
2356: }
1.1400 raeburn 2357: var http = new XMLHttpRequest();
2358: var url = "/adm/courseauthor";
2359: var crsrole = "$env{'request.role'}";
2360: var exclude = '';
2361: if (exc) {
2362: exclude = '$exclude';
2363: }
1.1402 raeburn 2364: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2365: http.open("POST", url, true);
2366: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2367: http.onreadystatechange = function() {
2368: if (http.readyState == 4 && http.status == 200) {
2369: var data = JSON.parse(http.responseText);
2370: var selelem;
2371: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2372: if (Array.isArray(data.dirs)) {
2373: selelem = form.elements[dirsel];
2374: var i, numdirs = selelem.options.length -1;
2375: if (numdirs >=0) {
2376: for (i = numdirs; i >= 0; i--) {
2377: selelem.remove(i);
2378: }
2379: }
2380: var len = data.dirs.length;
2381: if (len) {
1.1402 raeburn 2382: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2383: var j;
2384: for (j = 0; j < len; j++) {
2385: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2386: }
2387: selelem.selectedIndex = 0;
2388: }
2389: if (!setfile) {
2390: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2391: selelem = form.elements[filesel];
2392: var j, numfiles = selelem.options.length -1;
2393: if (numfiles >=0) {
2394: for (j = numfiles; j >= 0; j--) {
2395: selelem.remove(j);
2396: }
2397: }
2398: if (selelem.options.length == 0) {
2399: selelem.options[selelem.options.length] = new Option('','');
2400: selelem.selectedIndex = 0;
2401: }
2402: }
2403: }
2404: }
2405: }
2406: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2407: selelem = form.elements[filesel];
2408: var i, numfiles = selelem.options.length -1;
2409: if (numfiles >=0) {
2410: for (i = numfiles; i >= 0; i--) {
2411: selelem.remove(i);
2412: }
2413: }
2414: var x;
2415: for (x in data.files) {
2416: if (Array.isArray(data.files[x])) {
2417: if (data.files[x].length > 1) {
2418: selelem.options[selelem.options.length] = new Option('$se','');
2419: }
2420: var len = data.files[x].length;
2421: if (len) {
2422: var k;
2423: for (k = 0; k < len; k++) {
2424: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2425: }
2426: selelem.selectedIndex = 0;
2427: }
2428: }
2429: }
2430: if (selelem.options.length == 0) {
2431: selelem.options[selelem.options.length] = new Option('','');
2432: selelem.selectedIndex = 0;
2433: }
1.1248 raeburn 2434: }
2435: }
2436: }
1.1400 raeburn 2437: http.send(params);
1.1248 raeburn 2438: }
1.1400 raeburn 2439: END
1.1248 raeburn 2440: }
2441:
1.565 albertel 2442: =pod
2443:
1.256 matthew 2444: =head1 Excel and CSV file utility routines
2445:
2446: =cut
2447:
2448: ###############################################################
2449: ###############################################################
2450:
2451: =pod
2452:
1.1162 raeburn 2453: =over 4
2454:
1.648 raeburn 2455: =item * &csv_translate($text)
1.37 matthew 2456:
1.185 www 2457: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2458: format.
2459:
2460: =cut
2461:
1.180 matthew 2462: ###############################################################
2463: ###############################################################
1.37 matthew 2464: sub csv_translate {
2465: my $text = shift;
2466: $text =~ s/\"/\"\"/g;
1.209 albertel 2467: $text =~ s/\n/ /g;
1.37 matthew 2468: return $text;
2469: }
1.180 matthew 2470:
2471: ###############################################################
2472: ###############################################################
2473:
2474: =pod
2475:
1.648 raeburn 2476: =item * &define_excel_formats()
1.180 matthew 2477:
2478: Define some commonly used Excel cell formats.
2479:
2480: Currently supported formats:
2481:
2482: =over 4
2483:
2484: =item header
2485:
2486: =item bold
2487:
2488: =item h1
2489:
2490: =item h2
2491:
2492: =item h3
2493:
1.256 matthew 2494: =item h4
2495:
2496: =item i
2497:
1.180 matthew 2498: =item date
2499:
2500: =back
2501:
2502: Inputs: $workbook
2503:
2504: Returns: $format, a hash reference.
2505:
1.1057 foxr 2506:
1.180 matthew 2507: =cut
2508:
2509: ###############################################################
2510: ###############################################################
2511: sub define_excel_formats {
2512: my ($workbook) = @_;
2513: my $format;
2514: $format->{'header'} = $workbook->add_format(bold => 1,
2515: bottom => 1,
2516: align => 'center');
2517: $format->{'bold'} = $workbook->add_format(bold=>1);
2518: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2519: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2520: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2521: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2522: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2523: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2524: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2525: return $format;
2526: }
2527:
2528: ###############################################################
2529: ###############################################################
1.113 bowersj2 2530:
2531: =pod
2532:
1.648 raeburn 2533: =item * &create_workbook()
1.255 matthew 2534:
2535: Create an Excel worksheet. If it fails, output message on the
2536: request object and return undefs.
2537:
2538: Inputs: Apache request object
2539:
2540: Returns (undef) on failure,
2541: Excel worksheet object, scalar with filename, and formats
2542: from &Apache::loncommon::define_excel_formats on success
2543:
2544: =cut
2545:
2546: ###############################################################
2547: ###############################################################
2548: sub create_workbook {
2549: my ($r) = @_;
2550: #
2551: # Create the excel spreadsheet
2552: my $filename = '/prtspool/'.
1.258 albertel 2553: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2554: time.'_'.rand(1000000000).'.xls';
2555: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2556: if (! defined($workbook)) {
2557: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2558: $r->print(
2559: '<p class="LC_error">'
2560: .&mt('Problems occurred in creating the new Excel file.')
2561: .' '.&mt('This error has been logged.')
2562: .' '.&mt('Please alert your LON-CAPA administrator.')
2563: .'</p>'
2564: );
1.255 matthew 2565: return (undef);
2566: }
2567: #
1.1014 foxr 2568: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2569: #
2570: my $format = &Apache::loncommon::define_excel_formats($workbook);
2571: return ($workbook,$filename,$format);
2572: }
2573:
2574: ###############################################################
2575: ###############################################################
2576:
2577: =pod
2578:
1.648 raeburn 2579: =item * &create_text_file()
1.113 bowersj2 2580:
1.542 raeburn 2581: Create a file to write to and eventually make available to the user.
1.256 matthew 2582: If file creation fails, outputs an error message on the request object and
2583: return undefs.
1.113 bowersj2 2584:
1.256 matthew 2585: Inputs: Apache request object, and file suffix
1.113 bowersj2 2586:
1.256 matthew 2587: Returns (undef) on failure,
2588: Filehandle and filename on success.
1.113 bowersj2 2589:
2590: =cut
2591:
1.256 matthew 2592: ###############################################################
2593: ###############################################################
2594: sub create_text_file {
2595: my ($r,$suffix) = @_;
2596: if (! defined($suffix)) { $suffix = 'txt'; };
2597: my $fh;
2598: my $filename = '/prtspool/'.
1.258 albertel 2599: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2600: time.'_'.rand(1000000000).'.'.$suffix;
2601: $fh = Apache::File->new('>/home/httpd'.$filename);
2602: if (! defined($fh)) {
2603: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2604: $r->print(
2605: '<p class="LC_error">'
2606: .&mt('Problems occurred in creating the output file.')
2607: .' '.&mt('This error has been logged.')
2608: .' '.&mt('Please alert your LON-CAPA administrator.')
2609: .'</p>'
2610: );
1.113 bowersj2 2611: }
1.256 matthew 2612: return ($fh,$filename)
1.113 bowersj2 2613: }
2614:
2615:
1.256 matthew 2616: =pod
1.113 bowersj2 2617:
2618: =back
2619:
2620: =cut
1.37 matthew 2621:
2622: ###############################################################
1.33 matthew 2623: ## Home server <option> list generating code ##
2624: ###############################################################
1.35 matthew 2625:
1.169 www 2626: # ------------------------------------------
2627:
2628: sub domain_select {
1.1289 raeburn 2629: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2630: my @possdoms;
2631: if (ref($incdoms) eq 'ARRAY') {
2632: @possdoms = @{$incdoms};
2633: } else {
2634: @possdoms = &Apache::lonnet::all_domains();
2635: }
2636:
1.169 www 2637: my %domains=map {
1.514 albertel 2638: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2639: } @possdoms;
2640:
2641: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2642: foreach my $dom (@{$excdoms}) {
2643: delete($domains{$dom});
2644: }
2645: }
2646:
1.169 www 2647: if ($multiple) {
2648: $domains{''}=&mt('Any domain');
1.550 albertel 2649: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2650: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2651: } else {
1.550 albertel 2652: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2653: return &select_form($name,$value,\%domains);
1.169 www 2654: }
2655: }
2656:
1.282 albertel 2657: #-------------------------------------------
2658:
2659: =pod
2660:
1.519 raeburn 2661: =head1 Routines for form select boxes
2662:
2663: =over 4
2664:
1.648 raeburn 2665: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2666:
2667: Returns a string containing a <select> element int multiple mode
2668:
2669:
2670: Args:
2671: $name - name of the <select> element
1.506 raeburn 2672: $value - scalar or array ref of values that should already be selected
1.282 albertel 2673: $size - number of rows long the select element is
1.283 albertel 2674: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2675: (shown text should already have been &mt())
1.506 raeburn 2676: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2677:
1.282 albertel 2678: =cut
2679:
2680: #-------------------------------------------
1.169 www 2681: sub multiple_select_form {
1.284 albertel 2682: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2683: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2684: my $output='';
1.191 matthew 2685: if (! defined($size)) {
2686: $size = 4;
1.283 albertel 2687: if (scalar(keys(%$hash))<4) {
2688: $size = scalar(keys(%$hash));
1.191 matthew 2689: }
2690: }
1.734 bisitz 2691: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2692: my @order;
1.506 raeburn 2693: if (ref($order) eq 'ARRAY') {
2694: @order = @{$order};
2695: } else {
2696: @order = sort(keys(%$hash));
1.501 banghart 2697: }
2698: if (exists($$hash{'select_form_order'})) {
2699: @order = @{$$hash{'select_form_order'}};
2700: }
2701:
1.284 albertel 2702: foreach my $key (@order) {
1.356 albertel 2703: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2704: $output.='selected="selected" ' if ($selected{$key});
2705: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2706: }
2707: $output.="</select>\n";
2708: return $output;
2709: }
2710:
1.88 www 2711: #-------------------------------------------
2712:
2713: =pod
2714:
1.1254 raeburn 2715: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2716:
2717: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2718: allow a user to select options from a ref to a hash containing:
2719: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2720: a javascript onchange item, e.g., onchange="this.form.submit();".
2721: An optional arg -- $readonly -- if true will cause the select form
2722: to be disabled, e.g., for the case where an instructor has a section-
2723: specific role, and is viewing/modifying parameters.
1.970 raeburn 2724:
1.88 www 2725: See lonrights.pm for an example invocation and use.
2726:
2727: =cut
2728:
2729: #-------------------------------------------
2730: sub select_form {
1.1228 raeburn 2731: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2732: return unless (ref($hashref) eq 'HASH');
2733: if ($onchange) {
2734: $onchange = ' onchange="'.$onchange.'"';
2735: }
1.1228 raeburn 2736: my $disabled;
2737: if ($readonly) {
2738: $disabled = ' disabled="disabled"';
2739: }
2740: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2741: my @keys;
1.970 raeburn 2742: if (exists($hashref->{'select_form_order'})) {
2743: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2744: } else {
1.970 raeburn 2745: @keys=sort(keys(%{$hashref}));
1.128 albertel 2746: }
1.356 albertel 2747: foreach my $key (@keys) {
2748: $selectform.=
2749: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2750: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2751: ">".$hashref->{$key}."</option>\n";
1.88 www 2752: }
2753: $selectform.="</select>";
2754: return $selectform;
2755: }
2756:
1.475 www 2757: # For display filters
2758:
2759: sub display_filter {
1.1074 raeburn 2760: my ($context) = @_;
1.475 www 2761: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2762: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2763: my $phraseinput = 'hidden';
2764: my $includeinput = 'hidden';
2765: my ($checked,$includetypestext);
2766: if ($env{'form.displayfilter'} eq 'containing') {
2767: $phraseinput = 'text';
2768: if ($context eq 'parmslog') {
2769: $includeinput = 'checkbox';
2770: if ($env{'form.includetypes'}) {
2771: $checked = ' checked="checked"';
2772: }
2773: $includetypestext = &mt('Include parameter types');
2774: }
2775: } else {
2776: $includetypestext = ' ';
2777: }
2778: my ($additional,$secondid,$thirdid);
2779: if ($context eq 'parmslog') {
2780: $additional =
2781: '<label><input type="'.$includeinput.'" name="includetypes"'.
2782: $checked.' name="includetypes" value="1" id="includetypes" />'.
2783: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2784: '</label>';
2785: $secondid = 'includetypes';
2786: $thirdid = 'includetypestext';
2787: }
2788: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2789: '$secondid','$thirdid')";
2790: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2791: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2792: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2793: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2794: &mt('Filter: [_1]',
1.477 www 2795: &select_form($env{'form.displayfilter'},
2796: 'displayfilter',
1.970 raeburn 2797: {'currentfolder' => 'Current folder/page',
1.477 www 2798: 'containing' => 'Containing phrase',
1.1074 raeburn 2799: 'none' => 'None'},$onchange)).' '.
2800: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2801: &HTML::Entities::encode($env{'form.containingphrase'}).
2802: '" />'.$additional;
2803: }
2804:
2805: sub display_filter_js {
2806: my $includetext = &mt('Include parameter types');
2807: return <<"ENDJS";
2808:
2809: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2810: var firstType = 'hidden';
2811: if (setter.options[setter.selectedIndex].value == 'containing') {
2812: firstType = 'text';
2813: }
2814: firstObject = document.getElementById(firstid);
2815: if (typeof(firstObject) == 'object') {
2816: if (firstObject.type != firstType) {
2817: changeInputType(firstObject,firstType);
2818: }
2819: }
2820: if (context == 'parmslog') {
2821: var secondType = 'hidden';
2822: if (firstType == 'text') {
2823: secondType = 'checkbox';
2824: }
2825: secondObject = document.getElementById(secondid);
2826: if (typeof(secondObject) == 'object') {
2827: if (secondObject.type != secondType) {
2828: changeInputType(secondObject,secondType);
2829: }
2830: }
2831: var textItem = document.getElementById(thirdid);
2832: var currtext = textItem.innerHTML;
2833: var newtext;
2834: if (firstType == 'text') {
2835: newtext = '$includetext';
2836: } else {
2837: newtext = ' ';
2838: }
2839: if (currtext != newtext) {
2840: textItem.innerHTML = newtext;
2841: }
2842: }
2843: return;
2844: }
2845:
2846: function changeInputType(oldObject,newType) {
2847: var newObject = document.createElement('input');
2848: newObject.type = newType;
2849: if (oldObject.size) {
2850: newObject.size = oldObject.size;
2851: }
2852: if (oldObject.value) {
2853: newObject.value = oldObject.value;
2854: }
2855: if (oldObject.name) {
2856: newObject.name = oldObject.name;
2857: }
2858: if (oldObject.id) {
2859: newObject.id = oldObject.id;
2860: }
2861: oldObject.parentNode.replaceChild(newObject,oldObject);
2862: return;
2863: }
2864:
2865: ENDJS
1.475 www 2866: }
2867:
1.167 www 2868: sub gradeleveldescription {
2869: my $gradelevel=shift;
2870: my %gradelevels=(0 => 'Not specified',
2871: 1 => 'Grade 1',
2872: 2 => 'Grade 2',
2873: 3 => 'Grade 3',
2874: 4 => 'Grade 4',
2875: 5 => 'Grade 5',
2876: 6 => 'Grade 6',
2877: 7 => 'Grade 7',
2878: 8 => 'Grade 8',
2879: 9 => 'Grade 9',
2880: 10 => 'Grade 10',
2881: 11 => 'Grade 11',
2882: 12 => 'Grade 12',
2883: 13 => 'Grade 13',
2884: 14 => '100 Level',
2885: 15 => '200 Level',
2886: 16 => '300 Level',
2887: 17 => '400 Level',
2888: 18 => 'Graduate Level');
2889: return &mt($gradelevels{$gradelevel});
2890: }
2891:
1.163 www 2892: sub select_level_form {
2893: my ($deflevel,$name)=@_;
2894: unless ($deflevel) { $deflevel=0; }
1.167 www 2895: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2896: for (my $i=0; $i<=18; $i++) {
2897: $selectform.="<option value=\"$i\" ".
1.253 albertel 2898: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2899: ">".&gradeleveldescription($i)."</option>\n";
2900: }
2901: $selectform.="</select>";
2902: return $selectform;
1.163 www 2903: }
1.167 www 2904:
1.35 matthew 2905: #-------------------------------------------
2906:
1.45 matthew 2907: =pod
2908:
1.1256 raeburn 2909: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2910:
2911: Returns a string containing a <select name='$name' size='1'> form to
2912: allow a user to select the domain to preform an operation in.
2913: See loncreateuser.pm for an example invocation and use.
2914:
1.90 www 2915: If the $includeempty flag is set, it also includes an empty choice ("no domain
2916: selected");
2917:
1.743 raeburn 2918: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2919:
1.910 raeburn 2920: 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.
2921:
1.1121 raeburn 2922: The optional $incdoms is a reference to an array of domains which will be the only available options.
2923:
2924: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2925:
1.1256 raeburn 2926: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2927:
1.35 matthew 2928: =cut
2929:
2930: #-------------------------------------------
1.34 matthew 2931: sub select_dom_form {
1.1256 raeburn 2932: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2933: if ($onchange) {
1.874 raeburn 2934: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2935: }
1.1256 raeburn 2936: if ($disabled) {
2937: $disabled = ' disabled="disabled"';
2938: }
1.1121 raeburn 2939: my (@domains,%exclude);
1.910 raeburn 2940: if (ref($incdoms) eq 'ARRAY') {
2941: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2942: } else {
2943: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2944: }
1.90 www 2945: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2946: if (ref($excdoms) eq 'ARRAY') {
2947: map { $exclude{$_} = 1; } @{$excdoms};
2948: }
1.1256 raeburn 2949: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2950: foreach my $dom (@domains) {
1.1121 raeburn 2951: next if ($exclude{$dom});
1.356 albertel 2952: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2953: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2954: if ($showdomdesc) {
2955: if ($dom ne '') {
2956: my $domdesc = &Apache::lonnet::domain($dom,'description');
2957: if ($domdesc ne '') {
2958: $selectdomain .= ' ('.$domdesc.')';
2959: }
2960: }
2961: }
2962: $selectdomain .= "</option>\n";
1.34 matthew 2963: }
2964: $selectdomain.="</select>";
2965: return $selectdomain;
2966: }
2967:
1.35 matthew 2968: #-------------------------------------------
2969:
1.45 matthew 2970: =pod
2971:
1.648 raeburn 2972: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2973:
1.586 raeburn 2974: input: 4 arguments (two required, two optional) -
2975: $domain - domain of new user
2976: $name - name of form element
2977: $default - Value of 'default' causes a default item to be first
2978: option, and selected by default.
2979: $hide - Value of 'hide' causes hiding of the name of the server,
2980: if 1 server found, or default, if 0 found.
1.594 raeburn 2981: output: returns 2 items:
1.586 raeburn 2982: (a) form element which contains either:
2983: (i) <select name="$name">
2984: <option value="$hostid1">$hostid $servers{$hostid}</option>
2985: <option value="$hostid2">$hostid $servers{$hostid}</option>
2986: </select>
2987: form item if there are multiple library servers in $domain, or
2988: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2989: if there is only one library server in $domain.
2990:
2991: (b) number of library servers found.
2992:
2993: See loncreateuser.pm for example of use.
1.35 matthew 2994:
2995: =cut
2996:
2997: #-------------------------------------------
1.586 raeburn 2998: sub home_server_form_item {
2999: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 3000: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 3001: my $result;
3002: my $numlib = keys(%servers);
3003: if ($numlib > 1) {
3004: $result .= '<select name="'.$name.'" />'."\n";
3005: if ($default) {
1.804 bisitz 3006: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3007: '</option>'."\n";
3008: }
3009: foreach my $hostid (sort(keys(%servers))) {
3010: $result.= '<option value="'.$hostid.'">'.
3011: $hostid.' '.$servers{$hostid}."</option>\n";
3012: }
3013: $result .= '</select>'."\n";
3014: } elsif ($numlib == 1) {
3015: my $hostid;
3016: foreach my $item (keys(%servers)) {
3017: $hostid = $item;
3018: }
3019: $result .= '<input type="hidden" name="'.$name.'" value="'.
3020: $hostid.'" />';
3021: if (!$hide) {
3022: $result .= $hostid.' '.$servers{$hostid};
3023: }
3024: $result .= "\n";
3025: } elsif ($default) {
3026: $result .= '<input type="hidden" name="'.$name.
3027: '" value="default" />';
3028: if (!$hide) {
3029: $result .= &mt('default');
3030: }
3031: $result .= "\n";
1.33 matthew 3032: }
1.586 raeburn 3033: return ($result,$numlib);
1.33 matthew 3034: }
1.112 bowersj2 3035:
3036: =pod
3037:
1.534 albertel 3038: =back
3039:
1.112 bowersj2 3040: =cut
1.87 matthew 3041:
3042: ###############################################################
1.112 bowersj2 3043: ## Decoding User Agent ##
1.87 matthew 3044: ###############################################################
3045:
3046: =pod
3047:
1.112 bowersj2 3048: =head1 Decoding the User Agent
3049:
3050: =over 4
3051:
3052: =item * &decode_user_agent()
1.87 matthew 3053:
3054: Inputs: $r
3055:
3056: Outputs:
3057:
3058: =over 4
3059:
1.112 bowersj2 3060: =item * $httpbrowser
1.87 matthew 3061:
1.112 bowersj2 3062: =item * $clientbrowser
1.87 matthew 3063:
1.112 bowersj2 3064: =item * $clientversion
1.87 matthew 3065:
1.112 bowersj2 3066: =item * $clientmathml
1.87 matthew 3067:
1.112 bowersj2 3068: =item * $clientunicode
1.87 matthew 3069:
1.112 bowersj2 3070: =item * $clientos
1.87 matthew 3071:
1.1137 raeburn 3072: =item * $clientmobile
3073:
1.1141 raeburn 3074: =item * $clientinfo
3075:
1.1194 raeburn 3076: =item * $clientosversion
3077:
1.87 matthew 3078: =back
3079:
1.157 matthew 3080: =back
3081:
1.87 matthew 3082: =cut
3083:
3084: ###############################################################
3085: ###############################################################
3086: sub decode_user_agent {
1.247 albertel 3087: my ($r)=@_;
1.87 matthew 3088: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3089: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3090: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3091: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3092: my $clientbrowser='unknown';
3093: my $clientversion='0';
3094: my $clientmathml='';
3095: my $clientunicode='0';
1.1137 raeburn 3096: my $clientmobile=0;
1.1194 raeburn 3097: my $clientosversion='';
1.87 matthew 3098: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3099: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3100: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3101: $clientbrowser=$bname;
3102: $httpbrowser=~/$vreg/i;
3103: $clientversion=$1;
3104: $clientmathml=($clientversion>=$minv);
3105: $clientunicode=($clientversion>=$univ);
3106: }
3107: }
3108: my $clientos='unknown';
1.1141 raeburn 3109: my $clientinfo;
1.87 matthew 3110: if (($httpbrowser=~/linux/i) ||
3111: ($httpbrowser=~/unix/i) ||
3112: ($httpbrowser=~/ux/i) ||
3113: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3114: if (($httpbrowser=~/vax/i) ||
3115: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3116: if ($httpbrowser=~/next/i) { $clientos='next'; }
3117: if (($httpbrowser=~/mac/i) ||
3118: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3119: if ($httpbrowser=~/win/i) {
3120: $clientos='win';
3121: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3122: $clientosversion = $1;
3123: }
3124: }
1.87 matthew 3125: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3126: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3127: $clientmobile=lc($1);
3128: }
1.1141 raeburn 3129: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3130: $clientinfo = 'firefox-'.$1;
3131: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3132: $clientinfo = 'chromeframe-'.$1;
3133: }
1.87 matthew 3134: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3135: $clientunicode,$clientos,$clientmobile,$clientinfo,
3136: $clientosversion);
1.87 matthew 3137: }
3138:
1.32 matthew 3139: ###############################################################
3140: ## Authentication changing form generation subroutines ##
3141: ###############################################################
3142: ##
3143: ## All of the authform_xxxxxxx subroutines take their inputs in a
3144: ## hash, and have reasonable default values.
3145: ##
3146: ## formname = the name given in the <form> tag.
1.35 matthew 3147: #-------------------------------------------
3148:
1.45 matthew 3149: =pod
3150:
1.112 bowersj2 3151: =head1 Authentication Routines
3152:
3153: =over 4
3154:
1.648 raeburn 3155: =item * &authform_xxxxxx()
1.35 matthew 3156:
3157: The authform_xxxxxx subroutines provide javascript and html forms which
3158: handle some of the conveniences required for authentication forms.
3159: This is not an optimal method, but it works.
3160:
3161: =over 4
3162:
1.112 bowersj2 3163: =item * authform_header
1.35 matthew 3164:
1.112 bowersj2 3165: =item * authform_authorwarning
1.35 matthew 3166:
1.112 bowersj2 3167: =item * authform_nochange
1.35 matthew 3168:
1.112 bowersj2 3169: =item * authform_kerberos
1.35 matthew 3170:
1.112 bowersj2 3171: =item * authform_internal
1.35 matthew 3172:
1.112 bowersj2 3173: =item * authform_filesystem
1.35 matthew 3174:
1.1310 raeburn 3175: =item * authform_lti
3176:
1.35 matthew 3177: =back
3178:
1.648 raeburn 3179: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3180:
1.35 matthew 3181: =cut
3182:
3183: #-------------------------------------------
1.32 matthew 3184: sub authform_header{
3185: my %in = (
3186: formname => 'cu',
1.80 albertel 3187: kerb_def_dom => '',
1.32 matthew 3188: @_,
3189: );
3190: $in{'formname'} = 'document.' . $in{'formname'};
3191: my $result='';
1.80 albertel 3192:
3193: #---------------------------------------------- Code for upper case translation
3194: my $Javascript_toUpperCase;
3195: unless ($in{kerb_def_dom}) {
3196: $Javascript_toUpperCase =<<"END";
3197: switch (choice) {
3198: case 'krb': currentform.elements[choicearg].value =
3199: currentform.elements[choicearg].value.toUpperCase();
3200: break;
3201: default:
3202: }
3203: END
3204: } else {
3205: $Javascript_toUpperCase = "";
3206: }
3207:
1.165 raeburn 3208: my $radioval = "'nochange'";
1.591 raeburn 3209: if (defined($in{'curr_authtype'})) {
3210: if ($in{'curr_authtype'} ne '') {
3211: $radioval = "'".$in{'curr_authtype'}."arg'";
3212: }
1.174 matthew 3213: }
1.165 raeburn 3214: my $argfield = 'null';
1.591 raeburn 3215: if (defined($in{'mode'})) {
1.165 raeburn 3216: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3217: if (defined($in{'curr_autharg'})) {
3218: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3219: $argfield = "'$in{'curr_autharg'}'";
3220: }
3221: }
3222: }
3223: }
3224:
1.32 matthew 3225: $result.=<<"END";
3226: var current = new Object();
1.165 raeburn 3227: current.radiovalue = $radioval;
3228: current.argfield = $argfield;
1.32 matthew 3229:
3230: function changed_radio(choice,currentform) {
3231: var choicearg = choice + 'arg';
3232: // If a radio button in changed, we need to change the argfield
3233: if (current.radiovalue != choice) {
3234: current.radiovalue = choice;
3235: if (current.argfield != null) {
3236: currentform.elements[current.argfield].value = '';
3237: }
3238: if (choice == 'nochange') {
3239: current.argfield = null;
3240: } else {
3241: current.argfield = choicearg;
3242: switch(choice) {
3243: case 'krb':
3244: currentform.elements[current.argfield].value =
3245: "$in{'kerb_def_dom'}";
3246: break;
3247: default:
3248: break;
3249: }
3250: }
3251: }
3252: return;
3253: }
1.22 www 3254:
1.32 matthew 3255: function changed_text(choice,currentform) {
3256: var choicearg = choice + 'arg';
3257: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3258: $Javascript_toUpperCase
1.32 matthew 3259: // clear old field
3260: if ((current.argfield != choicearg) && (current.argfield != null)) {
3261: currentform.elements[current.argfield].value = '';
3262: }
3263: current.argfield = choicearg;
3264: }
3265: set_auth_radio_buttons(choice,currentform);
3266: return;
1.20 www 3267: }
1.32 matthew 3268:
3269: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3270: var numauthchoices = currentform.login.length;
3271: if (typeof numauthchoices == "undefined") {
3272: return;
3273: }
1.32 matthew 3274: var i=0;
1.986 raeburn 3275: while (i < numauthchoices) {
1.32 matthew 3276: if (currentform.login[i].value == newvalue) { break; }
3277: i++;
3278: }
1.986 raeburn 3279: if (i == numauthchoices) {
1.32 matthew 3280: return;
3281: }
3282: current.radiovalue = newvalue;
3283: currentform.login[i].checked = true;
3284: return;
3285: }
3286: END
3287: return $result;
3288: }
3289:
1.1106 raeburn 3290: sub authform_authorwarning {
1.32 matthew 3291: my $result='';
1.144 matthew 3292: $result='<i>'.
3293: &mt('As a general rule, only authors or co-authors should be '.
3294: 'filesystem authenticated '.
3295: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3296: return $result;
3297: }
3298:
1.1106 raeburn 3299: sub authform_nochange {
1.32 matthew 3300: my %in = (
3301: formname => 'document.cu',
3302: kerb_def_dom => 'MSU.EDU',
3303: @_,
3304: );
1.1106 raeburn 3305: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3306: my $result;
1.1104 raeburn 3307: if (!$authnum) {
1.1105 raeburn 3308: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3309: } else {
3310: $result = '<label>'.&mt('[_1] Do not change login data',
3311: '<input type="radio" name="login" value="nochange" '.
3312: 'checked="checked" onclick="'.
1.281 albertel 3313: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3314: '</label>';
1.586 raeburn 3315: }
1.32 matthew 3316: return $result;
3317: }
3318:
1.591 raeburn 3319: sub authform_kerberos {
1.32 matthew 3320: my %in = (
3321: formname => 'document.cu',
3322: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3323: kerb_def_auth => 'krb4',
1.32 matthew 3324: @_,
3325: );
1.586 raeburn 3326: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3327: $autharg,$jscall,$disabled);
1.1106 raeburn 3328: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3329: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3330: $check5 = ' checked="checked"';
1.80 albertel 3331: } else {
1.772 bisitz 3332: $check4 = ' checked="checked"';
1.80 albertel 3333: }
1.1259 raeburn 3334: if ($in{'readonly'}) {
3335: $disabled = ' disabled="disabled"';
3336: }
1.165 raeburn 3337: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3338: if (defined($in{'curr_authtype'})) {
3339: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3340: $krbcheck = ' checked="checked"';
1.623 raeburn 3341: if (defined($in{'mode'})) {
3342: if ($in{'mode'} eq 'modifyuser') {
3343: $krbcheck = '';
3344: }
3345: }
1.591 raeburn 3346: if (defined($in{'curr_kerb_ver'})) {
3347: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3348: $check5 = ' checked="checked"';
1.591 raeburn 3349: $check4 = '';
3350: } else {
1.772 bisitz 3351: $check4 = ' checked="checked"';
1.591 raeburn 3352: $check5 = '';
3353: }
1.586 raeburn 3354: }
1.591 raeburn 3355: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3356: $krbarg = $in{'curr_autharg'};
3357: }
1.586 raeburn 3358: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3359: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3360: $result =
3361: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3362: $in{'curr_autharg'},$krbver);
3363: } else {
3364: $result =
3365: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3366: }
3367: return $result;
3368: }
3369: }
3370: } else {
3371: if ($authnum == 1) {
1.784 bisitz 3372: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3373: }
3374: }
1.586 raeburn 3375: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3376: return;
1.587 raeburn 3377: } elsif ($authtype eq '') {
1.591 raeburn 3378: if (defined($in{'mode'})) {
1.587 raeburn 3379: if ($in{'mode'} eq 'modifycourse') {
3380: if ($authnum == 1) {
1.1259 raeburn 3381: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3382: }
3383: }
3384: }
1.586 raeburn 3385: }
3386: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3387: if ($authtype eq '') {
3388: $authtype = '<input type="radio" name="login" value="krb" '.
3389: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3390: $krbcheck.$disabled.' />';
1.586 raeburn 3391: }
3392: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3393: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3394: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3395: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3396: $in{'curr_authtype'} eq 'krb4')) {
3397: $result .= &mt
1.144 matthew 3398: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3399: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3400: '<label>'.$authtype,
1.281 albertel 3401: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3402: 'value="'.$krbarg.'" '.
1.1259 raeburn 3403: 'onchange="'.$jscall.'"'.$disabled.' />',
3404: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3405: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3406: '</label>');
1.586 raeburn 3407: } elsif ($can_assign{'krb4'}) {
3408: $result .= &mt
3409: ('[_1] Kerberos authenticated with domain [_2] '.
3410: '[_3] Version 4 [_4]',
3411: '<label>'.$authtype,
3412: '</label><input type="text" size="10" name="krbarg" '.
3413: 'value="'.$krbarg.'" '.
1.1259 raeburn 3414: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3415: '<label><input type="hidden" name="krbver" value="4" />',
3416: '</label>');
3417: } elsif ($can_assign{'krb5'}) {
3418: $result .= &mt
3419: ('[_1] Kerberos authenticated with domain [_2] '.
3420: '[_3] Version 5 [_4]',
3421: '<label>'.$authtype,
3422: '</label><input type="text" size="10" name="krbarg" '.
3423: 'value="'.$krbarg.'" '.
1.1259 raeburn 3424: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3425: '<label><input type="hidden" name="krbver" value="5" />',
3426: '</label>');
3427: }
1.32 matthew 3428: return $result;
3429: }
3430:
1.1106 raeburn 3431: sub authform_internal {
1.586 raeburn 3432: my %in = (
1.32 matthew 3433: formname => 'document.cu',
3434: kerb_def_dom => 'MSU.EDU',
3435: @_,
3436: );
1.1259 raeburn 3437: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3438: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3439: if ($in{'readonly'}) {
3440: $disabled = ' disabled="disabled"';
3441: }
1.591 raeburn 3442: if (defined($in{'curr_authtype'})) {
3443: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3444: if ($can_assign{'int'}) {
1.772 bisitz 3445: $intcheck = 'checked="checked" ';
1.623 raeburn 3446: if (defined($in{'mode'})) {
3447: if ($in{'mode'} eq 'modifyuser') {
3448: $intcheck = '';
3449: }
3450: }
1.591 raeburn 3451: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3452: $intarg = $in{'curr_autharg'};
3453: }
3454: } else {
3455: $result = &mt('Currently internally authenticated.');
3456: return $result;
1.165 raeburn 3457: }
3458: }
1.586 raeburn 3459: } else {
3460: if ($authnum == 1) {
1.784 bisitz 3461: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3462: }
3463: }
3464: if (!$can_assign{'int'}) {
3465: return;
1.587 raeburn 3466: } elsif ($authtype eq '') {
1.591 raeburn 3467: if (defined($in{'mode'})) {
1.587 raeburn 3468: if ($in{'mode'} eq 'modifycourse') {
3469: if ($authnum == 1) {
1.1259 raeburn 3470: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3471: }
3472: }
3473: }
1.165 raeburn 3474: }
1.586 raeburn 3475: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3476: if ($authtype eq '') {
3477: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3478: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3479: }
1.605 bisitz 3480: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3481: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3482: $result = &mt
1.144 matthew 3483: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3484: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3485: $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 3486: return $result;
3487: }
3488:
1.1104 raeburn 3489: sub authform_local {
1.32 matthew 3490: my %in = (
3491: formname => 'document.cu',
3492: kerb_def_dom => 'MSU.EDU',
3493: @_,
3494: );
1.1259 raeburn 3495: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3496: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3497: if ($in{'readonly'}) {
3498: $disabled = ' disabled="disabled"';
3499: }
1.591 raeburn 3500: if (defined($in{'curr_authtype'})) {
3501: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3502: if ($can_assign{'loc'}) {
1.772 bisitz 3503: $loccheck = 'checked="checked" ';
1.623 raeburn 3504: if (defined($in{'mode'})) {
3505: if ($in{'mode'} eq 'modifyuser') {
3506: $loccheck = '';
3507: }
3508: }
1.591 raeburn 3509: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3510: $locarg = $in{'curr_autharg'};
3511: }
3512: } else {
3513: $result = &mt('Currently using local (institutional) authentication.');
3514: return $result;
1.165 raeburn 3515: }
3516: }
1.586 raeburn 3517: } else {
3518: if ($authnum == 1) {
1.784 bisitz 3519: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3520: }
3521: }
3522: if (!$can_assign{'loc'}) {
3523: return;
1.587 raeburn 3524: } elsif ($authtype eq '') {
1.591 raeburn 3525: if (defined($in{'mode'})) {
1.587 raeburn 3526: if ($in{'mode'} eq 'modifycourse') {
3527: if ($authnum == 1) {
1.1259 raeburn 3528: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3529: }
3530: }
3531: }
1.165 raeburn 3532: }
1.586 raeburn 3533: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3534: if ($authtype eq '') {
3535: $authtype = '<input type="radio" name="login" value="loc" '.
3536: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3537: $jscall.'"'.$disabled.' />';
1.586 raeburn 3538: }
3539: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3540: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3541: $result = &mt('[_1] Local Authentication with argument [_2]',
3542: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3543: return $result;
3544: }
3545:
1.1106 raeburn 3546: sub authform_filesystem {
1.32 matthew 3547: my %in = (
3548: formname => 'document.cu',
3549: kerb_def_dom => 'MSU.EDU',
3550: @_,
3551: );
1.1259 raeburn 3552: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3553: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3554: if ($in{'readonly'}) {
3555: $disabled = ' disabled="disabled"';
3556: }
1.591 raeburn 3557: if (defined($in{'curr_authtype'})) {
3558: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3559: if ($can_assign{'fsys'}) {
1.772 bisitz 3560: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3561: if (defined($in{'mode'})) {
3562: if ($in{'mode'} eq 'modifyuser') {
3563: $fsyscheck = '';
3564: }
3565: }
1.586 raeburn 3566: } else {
3567: $result = &mt('Currently Filesystem Authenticated.');
3568: return $result;
1.1259 raeburn 3569: }
1.586 raeburn 3570: }
3571: } else {
3572: if ($authnum == 1) {
1.784 bisitz 3573: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3574: }
3575: }
3576: if (!$can_assign{'fsys'}) {
3577: return;
1.587 raeburn 3578: } elsif ($authtype eq '') {
1.591 raeburn 3579: if (defined($in{'mode'})) {
1.587 raeburn 3580: if ($in{'mode'} eq 'modifycourse') {
3581: if ($authnum == 1) {
1.1259 raeburn 3582: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3583: }
3584: }
3585: }
1.586 raeburn 3586: }
3587: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3588: if ($authtype eq '') {
3589: $authtype = '<input type="radio" name="login" value="fsys" '.
3590: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3591: $jscall.'"'.$disabled.' />';
1.586 raeburn 3592: }
1.1310 raeburn 3593: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3594: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3595: $result = &mt
1.144 matthew 3596: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3597: '<label>'.$authtype,'</label>'.$autharg);
3598: return $result;
3599: }
3600:
3601: sub authform_lti {
3602: my %in = (
3603: formname => 'document.cu',
3604: kerb_def_dom => 'MSU.EDU',
3605: @_,
3606: );
3607: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3608: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3609: if ($in{'readonly'}) {
3610: $disabled = ' disabled="disabled"';
3611: }
3612: if (defined($in{'curr_authtype'})) {
3613: if ($in{'curr_authtype'} eq 'lti') {
3614: if ($can_assign{'lti'}) {
3615: $lticheck = 'checked="checked" ';
3616: if (defined($in{'mode'})) {
3617: if ($in{'mode'} eq 'modifyuser') {
3618: $lticheck = '';
3619: }
3620: }
3621: } else {
3622: $result = &mt('Currently LTI Authenticated.');
3623: return $result;
3624: }
3625: }
3626: } else {
3627: if ($authnum == 1) {
3628: $authtype = '<input type="hidden" name="login" value="lti" />';
3629: }
3630: }
3631: if (!$can_assign{'lti'}) {
3632: return;
3633: } elsif ($authtype eq '') {
3634: if (defined($in{'mode'})) {
3635: if ($in{'mode'} eq 'modifycourse') {
3636: if ($authnum == 1) {
3637: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3638: }
3639: }
3640: }
3641: }
3642: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3643: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3644: $authtype = '<input type="radio" name="login" value="lti" '.
3645: $lticheck.' onchange="'.$jscall.'" onclick="'.
3646: $jscall.'"'.$disabled.' />';
3647: }
3648: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3649: if ($authtype) {
3650: $result = &mt('[_1] LTI Authenticated',
3651: '<label>'.$authtype.'</label>'.$autharg);
3652: } else {
3653: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3654: $autharg;
3655: }
1.32 matthew 3656: return $result;
3657: }
3658:
1.586 raeburn 3659: sub get_assignable_auth {
3660: my ($dom) = @_;
3661: if ($dom eq '') {
3662: $dom = $env{'request.role.domain'};
3663: }
3664: my %can_assign = (
3665: krb4 => 1,
3666: krb5 => 1,
3667: int => 1,
3668: loc => 1,
1.1310 raeburn 3669: lti => 1,
1.586 raeburn 3670: );
3671: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3672: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3673: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3674: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3675: my $context;
3676: if ($env{'request.role'} =~ /^au/) {
3677: $context = 'author';
1.1259 raeburn 3678: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3679: $context = 'domain';
3680: } elsif ($env{'request.course.id'}) {
3681: $context = 'course';
3682: }
3683: if ($context) {
3684: if (ref($authhash->{$context}) eq 'HASH') {
3685: %can_assign = %{$authhash->{$context}};
3686: }
3687: }
3688: }
3689: }
3690: my $authnum = 0;
3691: foreach my $key (keys(%can_assign)) {
3692: if ($can_assign{$key}) {
3693: $authnum ++;
3694: }
3695: }
3696: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3697: $authnum --;
3698: }
3699: return ($authnum,%can_assign);
3700: }
3701:
1.1331 raeburn 3702: sub check_passwd_rules {
3703: my ($domain,$plainpass) = @_;
3704: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3705: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3706: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3707: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3708: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3709: if ($passwdconf{'min'} > $min) {
3710: $min = $passwdconf{'min'};
3711: }
1.1331 raeburn 3712: }
3713: if ($passwdconf{'max'} =~ /^\d+$/) {
3714: $max = $passwdconf{'max'};
3715: }
3716: @chars = @{$passwdconf{'chars'}};
3717: }
3718: if (($min) && (length($plainpass) < $min)) {
3719: push(@brokerule,'min');
3720: }
3721: if (($max) && (length($plainpass) > $max)) {
3722: push(@brokerule,'max');
3723: }
3724: if (@chars) {
3725: my %rules;
3726: map { $rules{$_} = 1; } @chars;
3727: if ($rules{'uc'}) {
3728: unless ($plainpass =~ /[A-Z]/) {
3729: push(@brokerule,'uc');
3730: }
3731: }
3732: if ($rules{'lc'}) {
1.1332 raeburn 3733: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3734: push(@brokerule,'lc');
3735: }
3736: }
3737: if ($rules{'num'}) {
3738: unless ($plainpass =~ /\d/) {
3739: push(@brokerule,'num');
3740: }
3741: }
3742: if ($rules{'spec'}) {
3743: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3744: push(@brokerule,'spec');
3745: }
3746: }
3747: }
3748: if (@brokerule) {
3749: my %rulenames = &Apache::lonlocal::texthash(
3750: uc => 'At least one upper case letter',
3751: lc => 'At least one lower case letter',
3752: num => 'At least one number',
3753: spec => 'At least one non-alphanumeric',
3754: );
3755: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3756: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3757: $rulenames{'num'} .= ': 0123456789';
3758: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3759: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3760: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3761: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3762: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3763: if (grep(/^$rule$/,@brokerule)) {
3764: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3765: }
3766: }
3767: $warning .= '</ul>';
3768: }
1.1332 raeburn 3769: if (wantarray) {
3770: return @brokerule;
3771: }
1.1331 raeburn 3772: return $warning;
3773: }
3774:
1.1376 raeburn 3775: sub passwd_validation_js {
1.1377 raeburn 3776: my ($currpasswdval,$domain,$context,$id) = @_;
3777: my (%passwdconf,$alertmsg);
3778: if ($context eq 'linkprot') {
3779: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3780: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3781: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3782: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3783: }
3784: }
3785: if ($id eq 'add') {
3786: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3787: } elsif ($id =~ /^\d+$/) {
3788: my $pos = $id+1;
3789: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3790: } else {
3791: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3792: }
3793: } else {
3794: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3795: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3796: }
1.1376 raeburn 3797: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3798: $numrules = 0;
3799: $min = $Apache::lonnet::passwdmin;
3800: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3801: if ($passwdconf{'min'} =~ /^\d+$/) {
3802: if ($passwdconf{'min'} > $min) {
3803: $min = $passwdconf{'min'};
3804: }
3805: }
3806: if ($passwdconf{'max'} =~ /^\d+$/) {
3807: $max = $passwdconf{'max'};
3808: $numrules ++;
3809: }
3810: @chars = @{$passwdconf{'chars'}};
3811: if (@chars) {
3812: $numrules ++;
3813: }
3814: }
3815: if ($min > 0) {
3816: $numrules ++;
3817: }
3818: if (($min > 0) || ($max ne '') || (@chars > 0)) {
3819: if ($min) {
3820: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3821: }
3822: if ($max) {
3823: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3824: }
3825: my (@charalerts,@charrules);
3826: if (@chars) {
3827: if (grep(/^uc$/,@chars)) {
3828: push(@charalerts,&mt('contain at least one upper case letter'));
3829: push(@charrules,'uc');
3830: }
3831: if (grep(/^lc$/,@chars)) {
3832: push(@charalerts,&mt('contain at least one lower case letter'));
3833: push(@charrules,'lc');
3834: }
3835: if (grep(/^num$/,@chars)) {
3836: push(@charalerts,&mt('contain at least one number'));
3837: push(@charrules,'num');
3838: }
3839: if (grep(/^spec$/,@chars)) {
3840: push(@charalerts,&mt('contain at least one non-alphanumeric'));
3841: push(@charrules,'spec');
3842: }
3843: }
3844: $intargjs = qq| var rulesmsg = '';\n|.
3845: qq| var currpwval = $currpasswdval;\n|;
3846: if ($min) {
3847: $intargjs .= qq|
3848: if (currpwval.length < $min) {
3849: rulesmsg += ' - $alert{min}';
3850: }
3851: |;
3852: }
3853: if ($max) {
3854: $intargjs .= qq|
3855: if (currpwval.length > $max) {
3856: rulesmsg += ' - $alert{max}';
3857: }
3858: |;
3859: }
3860: if (@chars > 0) {
3861: my $charrulestr = '"'.join('","',@charrules).'"';
3862: my $charalertstr = '"'.join('","',@charalerts).'"';
3863: $intargjs .= qq| var brokerules = new Array();\n|.
3864: qq| var charrules = new Array($charrulestr);\n|.
3865: qq| var charalerts = new Array($charalertstr);\n|;
3866: my %rules;
3867: map { $rules{$_} = 1; } @chars;
3868: if ($rules{'uc'}) {
3869: $intargjs .= qq|
3870: var ucRegExp = /[A-Z]/;
3871: if (!ucRegExp.test(currpwval)) {
3872: brokerules.push('uc');
3873: }
3874: |;
3875: }
3876: if ($rules{'lc'}) {
3877: $intargjs .= qq|
3878: var lcRegExp = /[a-z]/;
3879: if (!lcRegExp.test(currpwval)) {
3880: brokerules.push('lc');
3881: }
3882: |;
3883: }
3884: if ($rules{'num'}) {
3885: $intargjs .= qq|
3886: var numRegExp = /[0-9]/;
3887: if (!numRegExp.test(currpwval)) {
3888: brokerules.push('num');
3889: }
3890: |;
3891: }
3892: if ($rules{'spec'}) {
3893: $intargjs .= q|
3894: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3895: if (!specRegExp.test(currpwval)) {
3896: brokerules.push('spec');
3897: }
3898: |;
3899: }
3900: $intargjs .= qq|
3901: if (brokerules.length > 0) {
3902: for (var i=0; i<brokerules.length; i++) {
3903: for (var j=0; j<charrules.length; j++) {
3904: if (brokerules[i] == charrules[j]) {
3905: rulesmsg += ' - '+charalerts[j]+'\\n';
3906: break;
3907: }
3908: }
3909: }
3910: }
3911: |;
3912: }
3913: $intargjs .= qq|
3914: if (rulesmsg != '') {
3915: rulesmsg = '$alertmsg'+rulesmsg;
3916: alert(rulesmsg);
3917: return false;
3918: }
3919: |;
3920: }
3921: return ($numrules,$intargjs);
3922: }
3923:
1.80 albertel 3924: ###############################################################
3925: ## Get Kerberos Defaults for Domain ##
3926: ###############################################################
3927: ##
3928: ## Returns default kerberos version and an associated argument
3929: ## as listed in file domain.tab. If not listed, provides
3930: ## appropriate default domain and kerberos version.
3931: ##
3932: #-------------------------------------------
3933:
3934: =pod
3935:
1.648 raeburn 3936: =item * &get_kerberos_defaults()
1.80 albertel 3937:
3938: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3939: version and domain. If not found, it defaults to version 4 and the
3940: domain of the server.
1.80 albertel 3941:
1.648 raeburn 3942: =over 4
3943:
1.80 albertel 3944: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3945:
1.648 raeburn 3946: =back
3947:
3948: =back
3949:
1.80 albertel 3950: =cut
3951:
3952: #-------------------------------------------
3953: sub get_kerberos_defaults {
3954: my $domain=shift;
1.641 raeburn 3955: my ($krbdef,$krbdefdom);
3956: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3957: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3958: $krbdef = $domdefaults{'auth_def'};
3959: $krbdefdom = $domdefaults{'auth_arg_def'};
3960: } else {
1.80 albertel 3961: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3962: my $krbdefdom=$1;
3963: $krbdefdom=~tr/a-z/A-Z/;
3964: $krbdef = "krb4";
3965: }
3966: return ($krbdef,$krbdefdom);
3967: }
1.112 bowersj2 3968:
1.32 matthew 3969:
1.46 matthew 3970: ###############################################################
3971: ## Thesaurus Functions ##
3972: ###############################################################
1.20 www 3973:
1.46 matthew 3974: =pod
1.20 www 3975:
1.112 bowersj2 3976: =head1 Thesaurus Functions
3977:
3978: =over 4
3979:
1.648 raeburn 3980: =item * &initialize_keywords()
1.46 matthew 3981:
3982: Initializes the package variable %Keywords if it is empty. Uses the
3983: package variable $thesaurus_db_file.
3984:
3985: =cut
3986:
3987: ###################################################
3988:
3989: sub initialize_keywords {
3990: return 1 if (scalar keys(%Keywords));
3991: # If we are here, %Keywords is empty, so fill it up
3992: # Make sure the file we need exists...
3993: if (! -e $thesaurus_db_file) {
3994: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3995: " failed because it does not exist");
3996: return 0;
3997: }
3998: # Set up the hash as a database
3999: my %thesaurus_db;
4000: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4001: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4002: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
4003: $thesaurus_db_file);
4004: return 0;
4005: }
4006: # Get the average number of appearances of a word.
4007: my $avecount = $thesaurus_db{'average.count'};
4008: # Put keywords (those that appear > average) into %Keywords
4009: while (my ($word,$data)=each (%thesaurus_db)) {
4010: my ($count,undef) = split /:/,$data;
4011: $Keywords{$word}++ if ($count > $avecount);
4012: }
4013: untie %thesaurus_db;
4014: # Remove special values from %Keywords.
1.356 albertel 4015: foreach my $value ('total.count','average.count') {
4016: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4017: }
1.46 matthew 4018: return 1;
4019: }
4020:
4021: ###################################################
4022:
4023: =pod
4024:
1.648 raeburn 4025: =item * &keyword($word)
1.46 matthew 4026:
4027: Returns true if $word is a keyword. A keyword is a word that appears more
4028: than the average number of times in the thesaurus database. Calls
4029: &initialize_keywords
4030:
4031: =cut
4032:
4033: ###################################################
1.20 www 4034:
4035: sub keyword {
1.46 matthew 4036: return if (!&initialize_keywords());
4037: my $word=lc(shift());
4038: $word=~s/\W//g;
4039: return exists($Keywords{$word});
1.20 www 4040: }
1.46 matthew 4041:
4042: ###############################################################
4043:
4044: =pod
1.20 www 4045:
1.648 raeburn 4046: =item * &get_related_words()
1.46 matthew 4047:
1.160 matthew 4048: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4049: an array of words. If the keyword is not in the thesaurus, an empty array
4050: will be returned. The order of the words returned is determined by the
4051: database which holds them.
4052:
4053: Uses global $thesaurus_db_file.
4054:
1.1057 foxr 4055:
1.46 matthew 4056: =cut
4057:
4058: ###############################################################
4059: sub get_related_words {
4060: my $keyword = shift;
4061: my %thesaurus_db;
4062: if (! -e $thesaurus_db_file) {
4063: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4064: "failed because the file does not exist");
4065: return ();
4066: }
4067: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4068: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4069: return ();
4070: }
4071: my @Words=();
1.429 www 4072: my $count=0;
1.46 matthew 4073: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4074: # The first element is the number of times
4075: # the word appears. We do not need it now.
1.429 www 4076: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4077: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4078: my $threshold=$mostfrequentcount/10;
4079: foreach my $possibleword (@RelatedWords) {
4080: my ($word,$wordcount)=split(/\,/,$possibleword);
4081: if ($wordcount>$threshold) {
4082: push(@Words,$word);
4083: $count++;
4084: if ($count>10) { last; }
4085: }
1.20 www 4086: }
4087: }
1.46 matthew 4088: untie %thesaurus_db;
4089: return @Words;
1.14 harris41 4090: }
1.1090 foxr 4091: ###############################################################
4092: #
4093: # Spell checking
4094: #
4095:
4096: =pod
4097:
1.1142 raeburn 4098: =back
4099:
1.1090 foxr 4100: =head1 Spell checking
4101:
4102: =over 4
4103:
4104: =item * &check_spelling($wordlist $language)
4105:
4106: Takes a string containing words and feeds it to an external
4107: spellcheck program via a pipeline. Returns a string containing
4108: them mis-spelled words.
4109:
4110: Parameters:
4111:
4112: =over 4
4113:
4114: =item - $wordlist
4115:
4116: String that will be fed into the spellcheck program.
4117:
4118: =item - $language
4119:
4120: Language string that specifies the language for which the spell
4121: check will be performed.
4122:
4123: =back
4124:
4125: =back
4126:
4127: Note: This sub assumes that aspell is installed.
4128:
4129:
4130: =cut
4131:
1.46 matthew 4132:
1.1090 foxr 4133: sub check_spelling {
4134: my ($wordlist, $language) = @_;
1.1091 foxr 4135: my @misspellings;
4136:
4137: # Generate the speller and set the langauge.
4138: # if explicitly selected:
1.1090 foxr 4139:
1.1091 foxr 4140: my $speller = Text::Aspell->new;
1.1090 foxr 4141: if ($language) {
1.1091 foxr 4142: $speller->set_option('lang', $language);
1.1090 foxr 4143: }
4144:
1.1091 foxr 4145: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4146:
1.1091 foxr 4147: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4148:
1.1091 foxr 4149: foreach my $word (@words) {
4150: if(! $speller->check($word)) {
4151: push(@misspellings, $word);
1.1090 foxr 4152: }
4153: }
1.1091 foxr 4154: return join(' ', @misspellings);
4155:
1.1090 foxr 4156: }
4157:
1.61 www 4158: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4159: =pod
4160:
1.112 bowersj2 4161: =head1 User Name Functions
4162:
4163: =over 4
4164:
1.648 raeburn 4165: =item * &plainname($uname,$udom,$first)
1.81 albertel 4166:
1.112 bowersj2 4167: Takes a users logon name and returns it as a string in
1.226 albertel 4168: "first middle last generation" form
4169: if $first is set to 'lastname' then it returns it as
4170: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4171:
4172: =cut
1.61 www 4173:
1.295 www 4174:
1.81 albertel 4175: ###############################################################
1.61 www 4176: sub plainname {
1.226 albertel 4177: my ($uname,$udom,$first)=@_;
1.537 albertel 4178: return if (!defined($uname) || !defined($udom));
1.295 www 4179: my %names=&getnames($uname,$udom);
1.226 albertel 4180: my $name=&Apache::lonnet::format_name($names{'firstname'},
4181: $names{'middlename'},
4182: $names{'lastname'},
4183: $names{'generation'},$first);
4184: $name=~s/^\s+//;
1.62 www 4185: $name=~s/\s+$//;
4186: $name=~s/\s+/ /g;
1.353 albertel 4187: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4188: return $name;
1.61 www 4189: }
1.66 www 4190:
4191: # -------------------------------------------------------------------- Nickname
1.81 albertel 4192: =pod
4193:
1.648 raeburn 4194: =item * &nickname($uname,$udom)
1.81 albertel 4195:
4196: Gets a users name and returns it as a string as
4197:
4198: ""nickname""
1.66 www 4199:
1.81 albertel 4200: if the user has a nickname or
4201:
4202: "first middle last generation"
4203:
4204: if the user does not
4205:
4206: =cut
1.66 www 4207:
4208: sub nickname {
4209: my ($uname,$udom)=@_;
1.537 albertel 4210: return if (!defined($uname) || !defined($udom));
1.295 www 4211: my %names=&getnames($uname,$udom);
1.68 albertel 4212: my $name=$names{'nickname'};
1.66 www 4213: if ($name) {
4214: $name='"'.$name.'"';
4215: } else {
4216: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4217: $names{'lastname'}.' '.$names{'generation'};
4218: $name=~s/\s+$//;
4219: $name=~s/\s+/ /g;
4220: }
4221: return $name;
4222: }
4223:
1.295 www 4224: sub getnames {
4225: my ($uname,$udom)=@_;
1.537 albertel 4226: return if (!defined($uname) || !defined($udom));
1.433 albertel 4227: if ($udom eq 'public' && $uname eq 'public') {
4228: return ('lastname' => &mt('Public'));
4229: }
1.295 www 4230: my $id=$uname.':'.$udom;
4231: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4232: if ($cached) {
4233: return %{$names};
4234: } else {
4235: my %loadnames=&Apache::lonnet::get('environment',
4236: ['firstname','middlename','lastname','generation','nickname'],
4237: $udom,$uname);
4238: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4239: return %loadnames;
4240: }
4241: }
1.61 www 4242:
1.542 raeburn 4243: # -------------------------------------------------------------------- getemails
1.648 raeburn 4244:
1.542 raeburn 4245: =pod
4246:
1.648 raeburn 4247: =item * &getemails($uname,$udom)
1.542 raeburn 4248:
4249: Gets a user's email information and returns it as a hash with keys:
4250: notification, critnotification, permanentemail
4251:
4252: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4253: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4254:
1.648 raeburn 4255:
1.542 raeburn 4256: =cut
4257:
1.648 raeburn 4258:
1.466 albertel 4259: sub getemails {
4260: my ($uname,$udom)=@_;
4261: if ($udom eq 'public' && $uname eq 'public') {
4262: return;
4263: }
1.467 www 4264: if (!$udom) { $udom=$env{'user.domain'}; }
4265: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4266: my $id=$uname.':'.$udom;
4267: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4268: if ($cached) {
4269: return %{$names};
4270: } else {
4271: my %loadnames=&Apache::lonnet::get('environment',
4272: ['notification','critnotification',
4273: 'permanentemail'],
4274: $udom,$uname);
4275: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4276: return %loadnames;
4277: }
4278: }
4279:
1.551 albertel 4280: sub flush_email_cache {
4281: my ($uname,$udom)=@_;
4282: if (!$udom) { $udom =$env{'user.domain'}; }
4283: if (!$uname) { $uname=$env{'user.name'}; }
4284: return if ($udom eq 'public' && $uname eq 'public');
4285: my $id=$uname.':'.$udom;
4286: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4287: }
4288:
1.728 raeburn 4289: # -------------------------------------------------------------------- getlangs
4290:
4291: =pod
4292:
4293: =item * &getlangs($uname,$udom)
4294:
4295: Gets a user's language preference and returns it as a hash with key:
4296: language.
4297:
4298: =cut
4299:
4300:
4301: sub getlangs {
4302: my ($uname,$udom) = @_;
4303: if (!$udom) { $udom =$env{'user.domain'}; }
4304: if (!$uname) { $uname=$env{'user.name'}; }
4305: my $id=$uname.':'.$udom;
4306: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4307: if ($cached) {
4308: return %{$langs};
4309: } else {
4310: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4311: $udom,$uname);
4312: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4313: return %loadlangs;
4314: }
4315: }
4316:
4317: sub flush_langs_cache {
4318: my ($uname,$udom)=@_;
4319: if (!$udom) { $udom =$env{'user.domain'}; }
4320: if (!$uname) { $uname=$env{'user.name'}; }
4321: return if ($udom eq 'public' && $uname eq 'public');
4322: my $id=$uname.':'.$udom;
4323: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4324: }
4325:
1.61 www 4326: # ------------------------------------------------------------------ Screenname
1.81 albertel 4327:
4328: =pod
4329:
1.648 raeburn 4330: =item * &screenname($uname,$udom)
1.81 albertel 4331:
4332: Gets a users screenname and returns it as a string
4333:
4334: =cut
1.61 www 4335:
4336: sub screenname {
4337: my ($uname,$udom)=@_;
1.258 albertel 4338: if ($uname eq $env{'user.name'} &&
4339: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4340: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4341: return $names{'screenname'};
1.62 www 4342: }
4343:
1.212 albertel 4344:
1.802 bisitz 4345: # ------------------------------------------------------------- Confirm Wrapper
4346: =pod
4347:
1.1142 raeburn 4348: =item * &confirmwrapper($message)
1.802 bisitz 4349:
4350: Wrap messages about completion of operation in box
4351:
4352: =cut
4353:
4354: sub confirmwrapper {
4355: my ($message)=@_;
4356: if ($message) {
4357: return "\n".'<div class="LC_confirm_box">'."\n"
4358: .$message."\n"
4359: .'</div>'."\n";
4360: } else {
4361: return $message;
4362: }
4363: }
4364:
1.62 www 4365: # ------------------------------------------------------------- Message Wrapper
4366:
4367: sub messagewrapper {
1.369 www 4368: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4369: return
1.441 albertel 4370: '<a href="/adm/email?compose=individual&'.
4371: 'recname='.$username.'&recdom='.$domain.
4372: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4373: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4374: }
1.802 bisitz 4375:
1.74 www 4376: # --------------------------------------------------------------- Notes Wrapper
4377:
4378: sub noteswrapper {
4379: my ($link,$un,$do)=@_;
4380: return
1.896 amueller 4381: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4382: }
1.802 bisitz 4383:
1.62 www 4384: # ------------------------------------------------------------- Aboutme Wrapper
4385:
4386: sub aboutmewrapper {
1.1070 raeburn 4387: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4388: if (!defined($username) && !defined($domain)) {
4389: return;
4390: }
1.1096 raeburn 4391: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4392: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4393: }
4394:
4395: # ------------------------------------------------------------ Syllabus Wrapper
4396:
4397: sub syllabuswrapper {
1.707 bisitz 4398: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4399: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4400: }
1.14 harris41 4401:
1.1397 raeburn 4402: # -----------------------------------------------------------------------------
4403:
1.1396 raeburn 4404: sub aboutme_on {
4405: my ($uname,$udom)=@_;
4406: unless ($uname) { $uname=$env{'user.name'}; }
4407: unless ($udom) { $udom=$env{'user.domain'}; }
4408: return if ($udom eq 'public' && $uname eq 'public');
4409: my $hashkey=$uname.':'.$udom;
4410: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4411: if ($cached) {
4412: return $aboutme;
4413: }
4414: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4415: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4416: return $aboutme;
4417: }
4418:
4419: sub devalidate_aboutme_cache {
4420: my ($uname,$udom)=@_;
4421: if (!$udom) { $udom =$env{'user.domain'}; }
4422: if (!$uname) { $uname=$env{'user.name'}; }
4423: return if ($udom eq 'public' && $uname eq 'public');
4424: my $id=$uname.':'.$udom;
4425: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4426: }
4427:
1.208 matthew 4428: sub track_student_link {
1.887 raeburn 4429: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4430: my $link ="/adm/trackstudent?";
1.208 matthew 4431: my $title = 'View recent activity';
4432: if (defined($sname) && $sname !~ /^\s*$/ &&
4433: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4434: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4435: $title .= ' of this student';
1.268 albertel 4436: }
1.208 matthew 4437: if (defined($target) && $target !~ /^\s*$/) {
4438: $target = qq{target="$target"};
4439: } else {
4440: $target = '';
4441: }
1.268 albertel 4442: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4443: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4444: $title = &mt($title);
4445: $linktext = &mt($linktext);
1.448 albertel 4446: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4447: &help_open_topic('View_recent_activity');
1.208 matthew 4448: }
4449:
1.781 raeburn 4450: sub slot_reservations_link {
4451: my ($linktext,$sname,$sdom,$target) = @_;
4452: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4453: my $title = 'View slot reservation history';
4454: if (defined($sname) && $sname !~ /^\s*$/ &&
4455: defined($sdom) && $sdom !~ /^\s*$/) {
4456: $link .= "&uname=$sname&udom=$sdom";
4457: $title .= ' of this student';
4458: }
4459: if (defined($target) && $target !~ /^\s*$/) {
4460: $target = qq{target="$target"};
4461: } else {
4462: $target = '';
4463: }
4464: $title = &mt($title);
4465: $linktext = &mt($linktext);
4466: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4467: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4468:
4469: }
4470:
1.508 www 4471: # ===================================================== Display a student photo
4472:
4473:
1.509 albertel 4474: sub student_image_tag {
1.508 www 4475: my ($domain,$user)=@_;
4476: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4477: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4478: return '<img src="'.$imgsrc.'" align="right" />';
4479: } else {
4480: return '';
4481: }
4482: }
4483:
1.112 bowersj2 4484: =pod
4485:
4486: =back
4487:
4488: =head1 Access .tab File Data
4489:
4490: =over 4
4491:
1.648 raeburn 4492: =item * &languageids()
1.112 bowersj2 4493:
4494: returns list of all language ids
4495:
4496: =cut
4497:
1.14 harris41 4498: sub languageids {
1.16 harris41 4499: return sort(keys(%language));
1.14 harris41 4500: }
4501:
1.112 bowersj2 4502: =pod
4503:
1.648 raeburn 4504: =item * &languagedescription()
1.112 bowersj2 4505:
4506: returns description of a specified language id
4507:
4508: =cut
4509:
1.14 harris41 4510: sub languagedescription {
1.125 www 4511: my $code=shift;
4512: return ($supported_language{$code}?'* ':'').
4513: $language{$code}.
1.126 www 4514: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4515: }
4516:
1.1048 foxr 4517: =pod
4518:
4519: =item * &plainlanguagedescription
4520:
4521: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4522: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4523:
4524: =cut
4525:
1.145 www 4526: sub plainlanguagedescription {
4527: my $code=shift;
4528: return $language{$code};
4529: }
4530:
1.1048 foxr 4531: =pod
4532:
4533: =item * &supportedlanguagecode
4534:
4535: Returns the supported language code (e.g. sptutf maps to pt) given a language
4536: code.
4537:
4538: =cut
4539:
1.145 www 4540: sub supportedlanguagecode {
4541: my $code=shift;
4542: return $supported_language{$code};
1.97 www 4543: }
4544:
1.112 bowersj2 4545: =pod
4546:
1.1048 foxr 4547: =item * &latexlanguage()
4548:
4549: Given a language key code returns the correspondnig language to use
4550: to select the correct hyphenation on LaTeX printouts. This is undef if there
4551: is no supported hyphenation for the language code.
4552:
4553: =cut
4554:
4555: sub latexlanguage {
4556: my $code = shift;
4557: return $latex_language{$code};
4558: }
4559:
4560: =pod
4561:
4562: =item * &latexhyphenation()
4563:
4564: Same as above but what's supplied is the language as it might be stored
4565: in the metadata.
4566:
4567: =cut
4568:
4569: sub latexhyphenation {
4570: my $key = shift;
4571: return $latex_language_bykey{$key};
4572: }
4573:
4574: =pod
4575:
1.648 raeburn 4576: =item * ©rightids()
1.112 bowersj2 4577:
4578: returns list of all copyrights
4579:
4580: =cut
4581:
4582: sub copyrightids {
4583: return sort(keys(%cprtag));
4584: }
4585:
4586: =pod
4587:
1.648 raeburn 4588: =item * ©rightdescription()
1.112 bowersj2 4589:
4590: returns description of a specified copyright id
4591:
4592: =cut
4593:
4594: sub copyrightdescription {
1.166 www 4595: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4596: }
1.197 matthew 4597:
4598: =pod
4599:
1.648 raeburn 4600: =item * &source_copyrightids()
1.192 taceyjo1 4601:
4602: returns list of all source copyrights
4603:
4604: =cut
4605:
4606: sub source_copyrightids {
4607: return sort(keys(%scprtag));
4608: }
4609:
4610: =pod
4611:
1.648 raeburn 4612: =item * &source_copyrightdescription()
1.192 taceyjo1 4613:
4614: returns description of a specified source copyright id
4615:
4616: =cut
4617:
4618: sub source_copyrightdescription {
4619: return &mt($scprtag{shift(@_)});
4620: }
1.112 bowersj2 4621:
4622: =pod
4623:
1.648 raeburn 4624: =item * &filecategories()
1.112 bowersj2 4625:
4626: returns list of all file categories
4627:
4628: =cut
4629:
4630: sub filecategories {
4631: return sort(keys(%category_extensions));
4632: }
4633:
4634: =pod
4635:
1.648 raeburn 4636: =item * &filecategorytypes()
1.112 bowersj2 4637:
4638: returns list of file types belonging to a given file
4639: category
4640:
4641: =cut
4642:
4643: sub filecategorytypes {
1.356 albertel 4644: my ($cat) = @_;
1.1248 raeburn 4645: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4646: return @{$category_extensions{lc($cat)}};
4647: } else {
4648: return ();
4649: }
1.112 bowersj2 4650: }
4651:
4652: =pod
4653:
1.648 raeburn 4654: =item * &fileembstyle()
1.112 bowersj2 4655:
4656: returns embedding style for a specified file type
4657:
4658: =cut
4659:
4660: sub fileembstyle {
4661: return $fe{lc(shift(@_))};
1.169 www 4662: }
4663:
1.351 www 4664: sub filemimetype {
4665: return $fm{lc(shift(@_))};
4666: }
4667:
1.169 www 4668:
4669: sub filecategoryselect {
4670: my ($name,$value)=@_;
1.189 matthew 4671: return &select_form($value,$name,
1.970 raeburn 4672: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4673: }
4674:
4675: =pod
4676:
1.648 raeburn 4677: =item * &filedescription()
1.112 bowersj2 4678:
4679: returns description for a specified file type
4680:
4681: =cut
4682:
4683: sub filedescription {
1.188 matthew 4684: my $file_description = $fd{lc(shift())};
4685: $file_description =~ s:([\[\]]):~$1:g;
4686: return &mt($file_description);
1.112 bowersj2 4687: }
4688:
4689: =pod
4690:
1.648 raeburn 4691: =item * &filedescriptionex()
1.112 bowersj2 4692:
4693: returns description for a specified file type with
4694: extra formatting
4695:
4696: =cut
4697:
4698: sub filedescriptionex {
4699: my $ex=shift;
1.188 matthew 4700: my $file_description = $fd{lc($ex)};
4701: $file_description =~ s:([\[\]]):~$1:g;
4702: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4703: }
4704:
4705: # End of .tab access
4706: =pod
4707:
4708: =back
4709:
4710: =cut
4711:
4712: # ------------------------------------------------------------------ File Types
4713: sub fileextensions {
4714: return sort(keys(%fe));
4715: }
4716:
1.97 www 4717: # ----------------------------------------------------------- Display Languages
4718: # returns a hash with all desired display languages
4719: #
4720:
4721: sub display_languages {
4722: my %languages=();
1.695 raeburn 4723: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4724: $languages{$lang}=1;
1.97 www 4725: }
4726: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4727: if ($env{'form.displaylanguage'}) {
1.356 albertel 4728: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4729: $languages{$lang}=1;
1.97 www 4730: }
4731: }
4732: return %languages;
1.14 harris41 4733: }
4734:
1.582 albertel 4735: sub languages {
4736: my ($possible_langs) = @_;
1.695 raeburn 4737: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4738: if (!ref($possible_langs)) {
4739: if( wantarray ) {
4740: return @preferred_langs;
4741: } else {
4742: return $preferred_langs[0];
4743: }
4744: }
4745: my %possibilities = map { $_ => 1 } (@$possible_langs);
4746: my @preferred_possibilities;
4747: foreach my $preferred_lang (@preferred_langs) {
4748: if (exists($possibilities{$preferred_lang})) {
4749: push(@preferred_possibilities, $preferred_lang);
4750: }
4751: }
4752: if( wantarray ) {
4753: return @preferred_possibilities;
4754: }
4755: return $preferred_possibilities[0];
4756: }
4757:
1.742 raeburn 4758: sub user_lang {
4759: my ($touname,$toudom,$fromcid) = @_;
4760: my @userlangs;
4761: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4762: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4763: $env{'course.'.$fromcid.'.languages'}));
4764: } else {
4765: my %langhash = &getlangs($touname,$toudom);
4766: if ($langhash{'languages'} ne '') {
4767: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4768: } else {
4769: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4770: if ($domdefs{'lang_def'} ne '') {
4771: @userlangs = ($domdefs{'lang_def'});
4772: }
4773: }
4774: }
4775: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4776: my $user_lh = Apache::localize->get_handle(@languages);
4777: return $user_lh;
4778: }
4779:
4780:
1.112 bowersj2 4781: ###############################################################
4782: ## Student Answer Attempts ##
4783: ###############################################################
4784:
4785: =pod
4786:
4787: =head1 Alternate Problem Views
4788:
4789: =over 4
4790:
1.648 raeburn 4791: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4792: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4793:
4794: Return string with previous attempt on problem. Arguments:
4795:
4796: =over 4
4797:
4798: =item * $symb: Problem, including path
4799:
4800: =item * $username: username of the desired student
4801:
4802: =item * $domain: domain of the desired student
1.14 harris41 4803:
1.112 bowersj2 4804: =item * $course: Course ID
1.14 harris41 4805:
1.112 bowersj2 4806: =item * $getattempt: Leave blank for all attempts, otherwise put
4807: something
1.14 harris41 4808:
1.112 bowersj2 4809: =item * $regexp: if string matches this regexp, the string will be
4810: sent to $gradesub
1.14 harris41 4811:
1.112 bowersj2 4812: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4813:
1.1199 raeburn 4814: =item * $usec: section of the desired student
4815:
4816: =item * $identifier: counter for student (multiple students one problem) or
4817: problem (one student; whole sequence).
4818:
1.112 bowersj2 4819: =back
1.14 harris41 4820:
1.112 bowersj2 4821: The output string is a table containing all desired attempts, if any.
1.16 harris41 4822:
1.112 bowersj2 4823: =cut
1.1 albertel 4824:
4825: sub get_previous_attempt {
1.1199 raeburn 4826: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4827: my $prevattempts='';
1.43 ng 4828: no strict 'refs';
1.1 albertel 4829: if ($symb) {
1.3 albertel 4830: my (%returnhash)=
4831: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4832: if ($returnhash{'version'}) {
4833: my %lasthash=();
4834: my $version;
4835: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4836: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4837: if ($key =~ /\.rawrndseed$/) {
4838: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4839: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4840: } else {
4841: $lasthash{$key}=$returnhash{$version.':'.$key};
4842: }
1.19 harris41 4843: }
1.1 albertel 4844: }
1.596 albertel 4845: $prevattempts=&start_data_table().&start_data_table_header_row();
4846: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4847: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4848: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4849: foreach my $key (sort(keys(%lasthash))) {
4850: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4851: if ($#parts > 0) {
1.31 albertel 4852: my $data=$parts[-1];
1.989 raeburn 4853: next if ($data eq 'foilorder');
1.31 albertel 4854: pop(@parts);
1.1010 www 4855: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4856: if ($data eq 'type') {
4857: unless ($showsurv) {
4858: my $id = join(',',@parts);
4859: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4860: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4861: $lasthidden{$ign.'.'.$id} = 1;
4862: }
1.945 raeburn 4863: }
1.1199 raeburn 4864: if ($identifier ne '') {
4865: my $id = join(',',@parts);
4866: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4867: $domain,$username,$usec,undef,$course) =~ /^no/) {
4868: $hidestatus{$ign.'.'.$id} = 1;
4869: }
4870: }
4871: } elsif ($data eq 'regrader') {
4872: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4873: my $id = join(',',@parts);
4874: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4875: }
1.1010 www 4876: }
1.31 albertel 4877: } else {
1.41 ng 4878: if ($#parts == 0) {
4879: $prevattempts.='<th>'.$parts[0].'</th>';
4880: } else {
4881: $prevattempts.='<th>'.$ign.'</th>';
4882: }
1.31 albertel 4883: }
1.16 harris41 4884: }
1.596 albertel 4885: $prevattempts.=&end_data_table_header_row();
1.40 ng 4886: if ($getattempt eq '') {
1.1199 raeburn 4887: my (%solved,%resets,%probstatus);
1.1200 raeburn 4888: if (($identifier ne '') && (keys(%regraded) > 0)) {
4889: for ($version=1;$version<=$returnhash{'version'};$version++) {
4890: foreach my $id (keys(%regraded)) {
4891: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4892: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4893: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4894: push(@{$resets{$id}},$version);
1.1199 raeburn 4895: }
4896: }
4897: }
1.1200 raeburn 4898: }
4899: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4900: my (@hidden,@unsolved);
1.945 raeburn 4901: if (%typeparts) {
4902: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4903: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4904: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4905: push(@hidden,$id);
1.1199 raeburn 4906: } elsif ($identifier ne '') {
4907: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4908: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4909: ($hidestatus{$id})) {
1.1200 raeburn 4910: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4911: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4912: push(@{$solved{$id}},$version);
4913: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4914: (ref($solved{$id}) eq 'ARRAY')) {
4915: my $skip;
4916: if (ref($resets{$id}) eq 'ARRAY') {
4917: foreach my $reset (@{$resets{$id}}) {
4918: if ($reset > $solved{$id}[-1]) {
4919: $skip=1;
4920: last;
4921: }
4922: }
4923: }
4924: unless ($skip) {
4925: my ($ign,$partslist) = split(/\./,$id,2);
4926: push(@unsolved,$partslist);
4927: }
4928: }
4929: }
1.945 raeburn 4930: }
4931: }
4932: }
4933: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4934: '<td>'.&mt('Transaction [_1]',$version);
4935: if (@unsolved) {
4936: $prevattempts .= '<span class="LC_nobreak"><label>'.
4937: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4938: &mt('Hide').'</label></span>';
4939: }
4940: $prevattempts .= '</td>';
1.945 raeburn 4941: if (@hidden) {
4942: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4943: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4944: my $hide;
4945: foreach my $id (@hidden) {
4946: if ($key =~ /^\Q$id\E/) {
4947: $hide = 1;
4948: last;
4949: }
4950: }
4951: if ($hide) {
4952: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4953: if (($data eq 'award') || ($data eq 'awarddetail')) {
4954: my $value = &format_previous_attempt_value($key,
4955: $returnhash{$version.':'.$key});
1.1173 kruse 4956: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4957: } else {
4958: $prevattempts.='<td> </td>';
4959: }
4960: } else {
4961: if ($key =~ /\./) {
1.1212 raeburn 4962: my $value = $returnhash{$version.':'.$key};
4963: if ($key =~ /\.rndseed$/) {
4964: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4965: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4966: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4967: }
4968: }
4969: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4970: ' </td>';
1.945 raeburn 4971: } else {
4972: $prevattempts.='<td> </td>';
4973: }
4974: }
4975: }
4976: } else {
4977: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4978: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4979: my $value = $returnhash{$version.':'.$key};
4980: if ($key =~ /\.rndseed$/) {
4981: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4982: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4983: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4984: }
4985: }
4986: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4987: ' </td>';
1.945 raeburn 4988: }
4989: }
4990: $prevattempts.=&end_data_table_row();
1.40 ng 4991: }
1.1 albertel 4992: }
1.945 raeburn 4993: my @currhidden = keys(%lasthidden);
1.596 albertel 4994: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4995: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4996: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4997: if (%typeparts) {
4998: my $hidden;
4999: foreach my $id (@currhidden) {
5000: if ($key =~ /^\Q$id\E/) {
5001: $hidden = 1;
5002: last;
5003: }
5004: }
5005: if ($hidden) {
5006: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5007: if (($data eq 'award') || ($data eq 'awarddetail')) {
5008: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5009: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5010: $value = &$gradesub($value);
5011: }
1.1173 kruse 5012: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5013: } else {
5014: $prevattempts.='<td> </td>';
5015: }
5016: } else {
5017: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5018: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5019: $value = &$gradesub($value);
5020: }
1.1173 kruse 5021: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5022: }
5023: } else {
5024: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5025: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5026: $value = &$gradesub($value);
5027: }
1.1173 kruse 5028: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5029: }
1.16 harris41 5030: }
1.596 albertel 5031: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5032: } else {
1.1305 raeburn 5033: my $msg;
5034: if ($symb =~ /ext\.tool$/) {
5035: $msg = &mt('No grade passed back.');
5036: } else {
5037: $msg = &mt('Nothing submitted - no attempts.');
5038: }
1.596 albertel 5039: $prevattempts=
5040: &start_data_table().&start_data_table_row().
1.1305 raeburn 5041: '<td>'.$msg.'</td>'.
1.596 albertel 5042: &end_data_table_row().&end_data_table();
1.1 albertel 5043: }
5044: } else {
1.596 albertel 5045: $prevattempts=
5046: &start_data_table().&start_data_table_row().
5047: '<td>'.&mt('No data.').'</td>'.
5048: &end_data_table_row().&end_data_table();
1.1 albertel 5049: }
1.10 albertel 5050: }
5051:
1.581 albertel 5052: sub format_previous_attempt_value {
5053: my ($key,$value) = @_;
1.1011 www 5054: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5055: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5056: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5057: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5058: } elsif ($key =~ /answerstring$/) {
5059: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5060: my @answer = %answers;
5061: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5062: my @anskeys = sort(keys(%answers));
5063: if (@anskeys == 1) {
5064: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5065: if ($answer =~ m{\0}) {
5066: $answer =~ s{\0}{,}g;
1.988 raeburn 5067: }
5068: my $tag_internal_answer_name = 'INTERNAL';
5069: if ($anskeys[0] eq $tag_internal_answer_name) {
5070: $value = $answer;
5071: } else {
5072: $value = $anskeys[0].'='.$answer;
5073: }
5074: } else {
5075: foreach my $ans (@anskeys) {
5076: my $answer = $answers{$ans};
1.1001 raeburn 5077: if ($answer =~ m{\0}) {
5078: $answer =~ s{\0}{,}g;
1.988 raeburn 5079: }
5080: $value .= $ans.'='.$answer.'<br />';;
5081: }
5082: }
1.581 albertel 5083: } else {
1.1173 kruse 5084: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5085: }
5086: return $value;
5087: }
5088:
5089:
1.107 albertel 5090: sub relative_to_absolute {
5091: my ($url,$output)=@_;
5092: my $parser=HTML::TokeParser->new(\$output);
5093: my $token;
5094: my $thisdir=$url;
5095: my @rlinks=();
5096: while ($token=$parser->get_token) {
5097: if ($token->[0] eq 'S') {
5098: if ($token->[1] eq 'a') {
5099: if ($token->[2]->{'href'}) {
5100: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5101: }
5102: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5103: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5104: } elsif ($token->[1] eq 'base') {
5105: $thisdir=$token->[2]->{'href'};
5106: }
5107: }
5108: }
5109: $thisdir=~s-/[^/]*$--;
1.356 albertel 5110: foreach my $link (@rlinks) {
1.726 raeburn 5111: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5112: ($link=~/^\//) ||
5113: ($link=~/^javascript:/i) ||
5114: ($link=~/^mailto:/i) ||
5115: ($link=~/^\#/)) {
5116: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5117: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5118: }
5119: }
5120: # -------------------------------------------------- Deal with Applet codebases
5121: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5122: return $output;
5123: }
5124:
1.112 bowersj2 5125: =pod
5126:
1.648 raeburn 5127: =item * &get_student_view()
1.112 bowersj2 5128:
5129: show a snapshot of what student was looking at
5130:
5131: =cut
5132:
1.10 albertel 5133: sub get_student_view {
1.186 albertel 5134: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5135: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5136: my (%form);
1.10 albertel 5137: my @elements=('symb','courseid','domain','username');
5138: foreach my $element (@elements) {
1.186 albertel 5139: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5140: }
1.186 albertel 5141: if (defined($moreenv)) {
5142: %form=(%form,%{$moreenv});
5143: }
1.236 albertel 5144: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5145: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5146: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5147: $feedurl =~ s{^/adm/wrapper}{};
5148: }
1.650 www 5149: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5150: $userview=~s/\<body[^\>]*\>//gi;
5151: $userview=~s/\<\/body\>//gi;
5152: $userview=~s/\<html\>//gi;
5153: $userview=~s/\<\/html\>//gi;
5154: $userview=~s/\<head\>//gi;
5155: $userview=~s/\<\/head\>//gi;
5156: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5157: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5158: if (wantarray) {
5159: return ($userview,$response);
5160: } else {
5161: return $userview;
5162: }
5163: }
5164:
5165: sub get_student_view_with_retries {
5166: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5167:
5168: my $ok = 0; # True if we got a good response.
5169: my $content;
5170: my $response;
5171:
5172: # Try to get the student_view done. within the retries count:
5173:
5174: do {
5175: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5176: $ok = $response->is_success;
5177: if (!$ok) {
5178: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5179: }
5180: $retries--;
5181: } while (!$ok && ($retries > 0));
5182:
5183: if (!$ok) {
5184: $content = ''; # On error return an empty content.
5185: }
1.651 www 5186: if (wantarray) {
5187: return ($content, $response);
5188: } else {
5189: return $content;
5190: }
1.11 albertel 5191: }
5192:
1.1349 raeburn 5193: sub css_links {
5194: my ($currsymb,$level) = @_;
5195: my ($links,@symbs,%cssrefs,%httpref);
5196: if ($level eq 'map') {
5197: my $navmap = Apache::lonnavmaps::navmap->new();
5198: if (ref($navmap)) {
5199: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5200: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5201: foreach my $res (@resources) {
5202: if (ref($res) && $res->symb()) {
5203: push(@symbs,$res->symb());
5204: }
5205: }
5206: }
5207: } else {
5208: @symbs = ($currsymb);
5209: }
5210: foreach my $symb (@symbs) {
5211: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5212: if ($css_href =~ /\S/) {
5213: unless ($css_href =~ m{https?://}) {
5214: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5215: my $proburl = &Apache::lonnet::clutter($url);
5216: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5217: unless ($css_href =~ m{^/}) {
5218: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5219: }
5220: if ($css_href =~ m{^/(res|uploaded)/}) {
5221: unless (($httpref{'httpref.'.$css_href}) ||
5222: (&Apache::lonnet::is_on_map($css_href))) {
5223: my $thisurl = $proburl;
5224: if ($env{'httpref.'.$proburl}) {
5225: $thisurl = $env{'httpref.'.$proburl};
5226: }
5227: $httpref{'httpref.'.$css_href} = $thisurl;
5228: }
5229: }
5230: }
5231: $cssrefs{$css_href} = 1;
5232: }
5233: }
5234: if (keys(%httpref)) {
5235: &Apache::lonnet::appenv(\%httpref);
5236: }
5237: if (keys(%cssrefs)) {
5238: foreach my $css_href (keys(%cssrefs)) {
5239: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5240: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5241: }
5242: }
5243: return $links;
5244: }
5245:
1.112 bowersj2 5246: =pod
5247:
1.648 raeburn 5248: =item * &get_student_answers()
1.112 bowersj2 5249:
5250: show a snapshot of how student was answering problem
5251:
5252: =cut
5253:
1.11 albertel 5254: sub get_student_answers {
1.100 sakharuk 5255: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5256: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5257: my (%moreenv);
1.11 albertel 5258: my @elements=('symb','courseid','domain','username');
5259: foreach my $element (@elements) {
1.186 albertel 5260: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5261: }
1.186 albertel 5262: $moreenv{'grade_target'}='answer';
5263: %moreenv=(%form,%moreenv);
1.497 raeburn 5264: $feedurl = &Apache::lonnet::clutter($feedurl);
5265: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5266: return $userview;
1.1 albertel 5267: }
1.116 albertel 5268:
5269: =pod
5270:
5271: =item * &submlink()
5272:
1.242 albertel 5273: Inputs: $text $uname $udom $symb $target
1.116 albertel 5274:
5275: Returns: A link to grades.pm such as to see the SUBM view of a student
5276:
5277: =cut
5278:
5279: ###############################################
5280: sub submlink {
1.242 albertel 5281: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5282: if (!($uname && $udom)) {
5283: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5284: &Apache::lonnet::whichuser($symb);
1.116 albertel 5285: if (!$symb) { $symb=$cursymb; }
5286: }
1.254 matthew 5287: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5288: $symb=&escape($symb);
1.960 bisitz 5289: if ($target) { $target=" target=\"$target\""; }
5290: return
5291: '<a href="/adm/grades?command=submission'.
5292: '&symb='.$symb.
5293: '&student='.$uname.
5294: '&userdom='.$udom.'"'.
5295: $target.'>'.$text.'</a>';
1.242 albertel 5296: }
5297: ##############################################
5298:
5299: =pod
5300:
5301: =item * &pgrdlink()
5302:
5303: Inputs: $text $uname $udom $symb $target
5304:
5305: Returns: A link to grades.pm such as to see the PGRD view of a student
5306:
5307: =cut
5308:
5309: ###############################################
5310: sub pgrdlink {
5311: my $link=&submlink(@_);
5312: $link=~s/(&command=submission)/$1&showgrading=yes/;
5313: return $link;
5314: }
5315: ##############################################
5316:
5317: =pod
5318:
5319: =item * &pprmlink()
5320:
5321: Inputs: $text $uname $udom $symb $target
5322:
5323: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5324: student and a specific resource
1.242 albertel 5325:
5326: =cut
5327:
5328: ###############################################
5329: sub pprmlink {
5330: my ($text,$uname,$udom,$symb,$target)=@_;
5331: if (!($uname && $udom)) {
5332: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5333: &Apache::lonnet::whichuser($symb);
1.242 albertel 5334: if (!$symb) { $symb=$cursymb; }
5335: }
1.254 matthew 5336: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5337: $symb=&escape($symb);
1.242 albertel 5338: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5339: return '<a href="/adm/parmset?command=set&'.
5340: 'symb='.$symb.'&uname='.$uname.
5341: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5342: }
5343: ##############################################
1.37 matthew 5344:
1.112 bowersj2 5345: =pod
5346:
5347: =back
5348:
5349: =cut
5350:
1.37 matthew 5351: ###############################################
1.51 www 5352:
5353:
5354: sub timehash {
1.687 raeburn 5355: my ($thistime) = @_;
5356: my $timezone = &Apache::lonlocal::gettimezone();
5357: my $dt = DateTime->from_epoch(epoch => $thistime)
5358: ->set_time_zone($timezone);
5359: my $wday = $dt->day_of_week();
5360: if ($wday == 7) { $wday = 0; }
5361: return ( 'second' => $dt->second(),
5362: 'minute' => $dt->minute(),
5363: 'hour' => $dt->hour(),
5364: 'day' => $dt->day_of_month(),
5365: 'month' => $dt->month(),
5366: 'year' => $dt->year(),
5367: 'weekday' => $wday,
5368: 'dayyear' => $dt->day_of_year(),
5369: 'dlsav' => $dt->is_dst() );
1.51 www 5370: }
5371:
1.370 www 5372: sub utc_string {
5373: my ($date)=@_;
1.371 www 5374: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5375: }
5376:
1.51 www 5377: sub maketime {
5378: my %th=@_;
1.687 raeburn 5379: my ($epoch_time,$timezone,$dt);
5380: $timezone = &Apache::lonlocal::gettimezone();
5381: eval {
5382: $dt = DateTime->new( year => $th{'year'},
5383: month => $th{'month'},
5384: day => $th{'day'},
5385: hour => $th{'hour'},
5386: minute => $th{'minute'},
5387: second => $th{'second'},
5388: time_zone => $timezone,
5389: );
5390: };
5391: if (!$@) {
5392: $epoch_time = $dt->epoch;
5393: if ($epoch_time) {
5394: return $epoch_time;
5395: }
5396: }
1.51 www 5397: return POSIX::mktime(
5398: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5399: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5400: }
5401:
5402: #########################################
1.51 www 5403:
5404: sub findallcourses {
1.482 raeburn 5405: my ($roles,$uname,$udom) = @_;
1.355 albertel 5406: my %roles;
5407: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5408: my %courses;
1.51 www 5409: my $now=time;
1.482 raeburn 5410: if (!defined($uname)) {
5411: $uname = $env{'user.name'};
5412: }
5413: if (!defined($udom)) {
5414: $udom = $env{'user.domain'};
5415: }
5416: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5417: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5418: if (!%roles) {
5419: %roles = (
5420: cc => 1,
1.907 raeburn 5421: co => 1,
1.482 raeburn 5422: in => 1,
5423: ep => 1,
5424: ta => 1,
5425: cr => 1,
5426: st => 1,
5427: );
5428: }
5429: foreach my $entry (keys(%roleshash)) {
5430: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5431: if ($trole =~ /^cr/) {
5432: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5433: } else {
5434: next if (!exists($roles{$trole}));
5435: }
5436: if ($tend) {
5437: next if ($tend < $now);
5438: }
5439: if ($tstart) {
5440: next if ($tstart > $now);
5441: }
1.1058 raeburn 5442: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5443: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5444: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5445: if ($secpart eq '') {
5446: ($cnum,$role) = split(/_/,$cnumpart);
5447: $sec = 'none';
1.1058 raeburn 5448: $value .= $cnum.'/';
1.482 raeburn 5449: } else {
5450: $cnum = $cnumpart;
5451: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5452: $value .= $cnum.'/'.$sec;
5453: }
5454: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5455: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5456: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5457: }
5458: } else {
5459: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5460: }
1.482 raeburn 5461: }
5462: } else {
5463: foreach my $key (keys(%env)) {
1.483 albertel 5464: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5465: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5466: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5467: next if ($role eq 'ca' || $role eq 'aa');
5468: next if (%roles && !exists($roles{$role}));
5469: my ($starttime,$endtime)=split(/\./,$env{$key});
5470: my $active=1;
5471: if ($starttime) {
5472: if ($now<$starttime) { $active=0; }
5473: }
5474: if ($endtime) {
5475: if ($now>$endtime) { $active=0; }
5476: }
5477: if ($active) {
1.1058 raeburn 5478: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5479: if ($sec eq '') {
5480: $sec = 'none';
1.1058 raeburn 5481: } else {
5482: $value .= $sec;
5483: }
5484: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5485: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5486: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5487: }
5488: } else {
5489: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5490: }
1.474 raeburn 5491: }
5492: }
1.51 www 5493: }
5494: }
1.474 raeburn 5495: return %courses;
1.51 www 5496: }
1.37 matthew 5497:
1.54 www 5498: ###############################################
1.474 raeburn 5499:
5500: sub blockcheck {
1.1372 raeburn 5501: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5502: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5503: my ($has_evb,$check_ipaccess);
5504: my $dom = $env{'user.domain'};
5505: if ($env{'request.course.id'}) {
5506: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5507: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5508: my $checkrole = "cm./$cdom/$cnum";
5509: my $sec = $env{'request.course.sec'};
5510: if ($sec ne '') {
5511: $checkrole .= "/$sec";
5512: }
5513: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5514: ($env{'request.role'} !~ /^st/)) {
5515: $has_evb = 1;
5516: }
5517: unless ($has_evb) {
5518: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5519: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5520: if ($udom eq $cdom) {
5521: $check_ipaccess = 1;
5522: }
5523: }
5524: }
1.1375 raeburn 5525: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5526: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5527: my $checkrole;
5528: if ($env{'request.role.domain'} eq '') {
5529: $checkrole = "cm./$env{'user.domain'}/";
5530: } else {
5531: $checkrole = "cm./$env{'request.role.domain'}/";
5532: }
5533: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5534: $has_evb = 1;
5535: }
1.1372 raeburn 5536: }
5537: unless ($has_evb || $check_ipaccess) {
5538: my @machinedoms = &Apache::lonnet::current_machine_domains();
5539: if (($dom eq 'public') && ($activity eq 'port')) {
5540: $dom = $udom;
5541: }
5542: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5543: $check_ipaccess = 1;
5544: } else {
5545: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5546: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5547: my $prim = &Apache::lonnet::domain($dom,'primary');
5548: my $intdom = &Apache::lonnet::internet_dom($prim);
5549: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5550: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5551: $check_ipaccess = 1;
5552: }
5553: }
5554: }
5555: }
5556: if ($check_ipaccess) {
5557: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5558: unless (defined($cached)) {
5559: my %domconfig =
5560: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5561: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5562: }
5563: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5564: foreach my $id (keys(%{$ipaccessref})) {
5565: if (ref($ipaccessref->{$id}) eq 'HASH') {
5566: my $range = $ipaccessref->{$id}->{'ip'};
5567: if ($range) {
5568: if (&Apache::lonnet::ip_match($clientip,$range)) {
5569: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5570: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5571: return ('','','',$id,$dom);
5572: last;
5573: }
5574: }
5575: }
5576: }
5577: }
5578: }
5579: }
5580: }
1.1373 raeburn 5581: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5582: return ();
5583: }
1.1372 raeburn 5584: }
1.1189 raeburn 5585: if (defined($udom) && defined($uname)) {
5586: # If uname and udom are for a course, check for blocks in the course.
5587: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5588: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5589: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5590: return ($startblock,$endblock,$triggerblock);
5591: }
5592: } else {
1.490 raeburn 5593: $udom = $env{'user.domain'};
5594: $uname = $env{'user.name'};
5595: }
5596:
1.502 raeburn 5597: my $startblock = 0;
5598: my $endblock = 0;
1.1062 raeburn 5599: my $triggerblock = '';
1.1373 raeburn 5600: my %live_courses;
5601: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5602: %live_courses = &findallcourses(undef,$uname,$udom);
5603: }
1.474 raeburn 5604:
1.490 raeburn 5605: # If uname is for a user, and activity is course-specific, i.e.,
5606: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5607:
1.490 raeburn 5608: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5609: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5610: $activity eq 'search' || $activity eq 'reinit' ||
5611: $activity eq 'alert') &&
1.1189 raeburn 5612: ($env{'request.course.id'})) {
1.490 raeburn 5613: foreach my $key (keys(%live_courses)) {
5614: if ($key ne $env{'request.course.id'}) {
5615: delete($live_courses{$key});
5616: }
5617: }
5618: }
5619:
5620: my $otheruser = 0;
5621: my %own_courses;
5622: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5623: # Resource belongs to user other than current user.
5624: $otheruser = 1;
5625: # Gather courses for current user
5626: %own_courses =
5627: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5628: }
5629:
5630: # Gather active course roles - course coordinator, instructor,
5631: # exam proctor, ta, student, or custom role.
1.474 raeburn 5632:
5633: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5634: my ($cdom,$cnum);
5635: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5636: $cdom = $env{'course.'.$course.'.domain'};
5637: $cnum = $env{'course.'.$course.'.num'};
5638: } else {
1.490 raeburn 5639: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5640: }
5641: my $no_ownblock = 0;
5642: my $no_userblock = 0;
1.533 raeburn 5643: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5644: # Check if current user has 'evb' priv for this
5645: if (defined($own_courses{$course})) {
5646: foreach my $sec (keys(%{$own_courses{$course}})) {
5647: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5648: if ($sec ne 'none') {
5649: $checkrole .= '/'.$sec;
5650: }
5651: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5652: $no_ownblock = 1;
5653: last;
5654: }
5655: }
5656: }
5657: # if they have 'evb' priv and are currently not playing student
5658: next if (($no_ownblock) &&
5659: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5660: }
1.474 raeburn 5661: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5662: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5663: if ($sec ne 'none') {
1.482 raeburn 5664: $checkrole .= '/'.$sec;
1.474 raeburn 5665: }
1.490 raeburn 5666: if ($otheruser) {
5667: # Resource belongs to user other than current user.
5668: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5669: my (%allroles,%userroles);
5670: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5671: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5672: my ($trole,$tdom,$tnum,$tsec);
5673: if ($entry =~ /^cr/) {
5674: ($trole,$tdom,$tnum,$tsec) =
5675: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5676: } else {
5677: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5678: }
5679: my ($spec,$area,$trest);
5680: $area = '/'.$tdom.'/'.$tnum;
5681: $trest = $tnum;
5682: if ($tsec ne '') {
5683: $area .= '/'.$tsec;
5684: $trest .= '/'.$tsec;
5685: }
5686: $spec = $trole.'.'.$area;
5687: if ($trole =~ /^cr/) {
5688: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5689: $tdom,$spec,$trest,$area);
5690: } else {
5691: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5692: $tdom,$spec,$trest,$area);
5693: }
5694: }
1.1276 raeburn 5695: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5696: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5697: if ($1) {
5698: $no_userblock = 1;
5699: last;
5700: }
1.486 raeburn 5701: }
5702: }
1.490 raeburn 5703: } else {
5704: # Resource belongs to current user
5705: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5706: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5707: $no_ownblock = 1;
5708: last;
5709: }
1.474 raeburn 5710: }
5711: }
5712: # if they have the evb priv and are currently not playing student
1.482 raeburn 5713: next if (($no_ownblock) &&
1.491 albertel 5714: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5715: next if ($no_userblock);
1.474 raeburn 5716:
1.1303 raeburn 5717: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5718: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5719:
1.1062 raeburn 5720: my ($start,$end,$trigger) =
1.1347 raeburn 5721: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5722: if (($start != 0) &&
5723: (($startblock == 0) || ($startblock > $start))) {
5724: $startblock = $start;
1.1062 raeburn 5725: if ($trigger ne '') {
5726: $triggerblock = $trigger;
5727: }
1.502 raeburn 5728: }
5729: if (($end != 0) &&
5730: (($endblock == 0) || ($endblock < $end))) {
5731: $endblock = $end;
1.1062 raeburn 5732: if ($trigger ne '') {
5733: $triggerblock = $trigger;
5734: }
1.502 raeburn 5735: }
1.490 raeburn 5736: }
1.1062 raeburn 5737: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5738: }
5739:
5740: sub get_blocks {
1.1347 raeburn 5741: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5742: my $startblock = 0;
5743: my $endblock = 0;
1.1062 raeburn 5744: my $triggerblock = '';
1.490 raeburn 5745: my $course = $cdom.'_'.$cnum;
5746: $setters->{$course} = {};
5747: $setters->{$course}{'staff'} = [];
5748: $setters->{$course}{'times'} = [];
1.1062 raeburn 5749: $setters->{$course}{'triggers'} = [];
5750: my (@blockers,%triggered);
5751: my $now = time;
5752: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5753: if ($activity eq 'docs') {
1.1348 raeburn 5754: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5755: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5756: $blocked = 1;
5757: $nosymbcache = 1;
1.1348 raeburn 5758: $noenccheck = 1;
1.1347 raeburn 5759: }
1.1348 raeburn 5760: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5761: foreach my $block (@blockers) {
5762: if ($block =~ /^firstaccess____(.+)$/) {
5763: my $item = $1;
5764: my $type = 'map';
5765: my $timersymb = $item;
5766: if ($item eq 'course') {
5767: $type = 'course';
5768: } elsif ($item =~ /___\d+___/) {
5769: $type = 'resource';
5770: } else {
5771: $timersymb = &Apache::lonnet::symbread($item);
5772: }
5773: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5774: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5775: $triggered{$block} = {
5776: start => $start,
5777: end => $end,
5778: type => $type,
5779: };
5780: }
5781: }
5782: } else {
5783: foreach my $block (keys(%commblocks)) {
5784: if ($block =~ m/^(\d+)____(\d+)$/) {
5785: my ($start,$end) = ($1,$2);
5786: if ($start <= time && $end >= time) {
5787: if (ref($commblocks{$block}) eq 'HASH') {
5788: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5789: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5790: unless(grep(/^\Q$block\E$/,@blockers)) {
5791: push(@blockers,$block);
5792: }
5793: }
5794: }
5795: }
5796: }
5797: } elsif ($block =~ /^firstaccess____(.+)$/) {
5798: my $item = $1;
5799: my $timersymb = $item;
5800: my $type = 'map';
5801: if ($item eq 'course') {
5802: $type = 'course';
5803: } elsif ($item =~ /___\d+___/) {
5804: $type = 'resource';
5805: } else {
5806: $timersymb = &Apache::lonnet::symbread($item);
5807: }
5808: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5809: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5810: if ($start && $end) {
5811: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5812: if (ref($commblocks{$block}) eq 'HASH') {
5813: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5814: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5815: unless(grep(/^\Q$block\E$/,@blockers)) {
5816: push(@blockers,$block);
5817: $triggered{$block} = {
5818: start => $start,
5819: end => $end,
5820: type => $type,
5821: };
5822: }
5823: }
5824: }
1.1062 raeburn 5825: }
5826: }
1.490 raeburn 5827: }
1.1062 raeburn 5828: }
5829: }
5830: }
5831: foreach my $blocker (@blockers) {
5832: my ($staff_name,$staff_dom,$title,$blocks) =
5833: &parse_block_record($commblocks{$blocker});
5834: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5835: my ($start,$end,$triggertype);
5836: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5837: ($start,$end) = ($1,$2);
5838: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5839: $start = $triggered{$blocker}{'start'};
5840: $end = $triggered{$blocker}{'end'};
5841: $triggertype = $triggered{$blocker}{'type'};
5842: }
5843: if ($start) {
5844: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5845: if ($triggertype) {
5846: push(@{$$setters{$course}{'triggers'}},$triggertype);
5847: } else {
5848: push(@{$$setters{$course}{'triggers'}},0);
5849: }
5850: if ( ($startblock == 0) || ($startblock > $start) ) {
5851: $startblock = $start;
5852: if ($triggertype) {
5853: $triggerblock = $blocker;
1.474 raeburn 5854: }
5855: }
1.1062 raeburn 5856: if ( ($endblock == 0) || ($endblock < $end) ) {
5857: $endblock = $end;
5858: if ($triggertype) {
5859: $triggerblock = $blocker;
5860: }
5861: }
1.474 raeburn 5862: }
5863: }
1.1062 raeburn 5864: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5865: }
5866:
5867: sub parse_block_record {
5868: my ($record) = @_;
5869: my ($setuname,$setudom,$title,$blocks);
5870: if (ref($record) eq 'HASH') {
5871: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5872: $title = &unescape($record->{'event'});
5873: $blocks = $record->{'blocks'};
5874: } else {
5875: my @data = split(/:/,$record,3);
5876: if (scalar(@data) eq 2) {
5877: $title = $data[1];
5878: ($setuname,$setudom) = split(/@/,$data[0]);
5879: } else {
5880: ($setuname,$setudom,$title) = @data;
5881: }
5882: $blocks = { 'com' => 'on' };
5883: }
5884: return ($setuname,$setudom,$title,$blocks);
5885: }
5886:
1.854 kalberla 5887: sub blocking_status {
1.1372 raeburn 5888: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5889: my %setters;
1.890 droeschl 5890:
1.1061 raeburn 5891: # check for active blocking
1.1372 raeburn 5892: if ($clientip eq '') {
5893: $clientip = &Apache::lonnet::get_requestor_ip();
5894: }
5895: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5896: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5897: my $blocked = 0;
1.1372 raeburn 5898: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5899: $blocked = 1;
5900: }
1.890 droeschl 5901:
1.1061 raeburn 5902: # caller just wants to know whether a block is active
5903: if (!wantarray) { return $blocked; }
5904:
5905: # build a link to a popup window containing the details
5906: my $querystring = "?activity=$activity";
1.1351 raeburn 5907: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5908: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5909: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5910: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5911: } elsif ($activity eq 'docs') {
1.1347 raeburn 5912: my $showurl = &Apache::lonenc::check_encrypt($url);
5913: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5914: if ($symb) {
5915: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5916: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5917: }
1.1062 raeburn 5918: }
1.1061 raeburn 5919:
5920: my $output .= <<'END_MYBLOCK';
5921: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5922: var options = "width=" + w + ",height=" + h + ",";
5923: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5924: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5925: var newWin = window.open(url, wdwName, options);
5926: newWin.focus();
5927: }
1.890 droeschl 5928: END_MYBLOCK
1.854 kalberla 5929:
1.1061 raeburn 5930: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5931:
1.1061 raeburn 5932: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5933: my $text = &mt('Communication Blocked');
1.1217 raeburn 5934: my $class = 'LC_comblock';
1.1062 raeburn 5935: if ($activity eq 'docs') {
5936: $text = &mt('Content Access Blocked');
1.1217 raeburn 5937: $class = '';
1.1063 raeburn 5938: } elsif ($activity eq 'printout') {
5939: $text = &mt('Printing Blocked');
1.1232 raeburn 5940: } elsif ($activity eq 'passwd') {
5941: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5942: } elsif ($activity eq 'grades') {
5943: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5944: } elsif ($activity eq 'search') {
5945: $text = &mt('Search Blocked');
1.1282 raeburn 5946: } elsif ($activity eq 'alert') {
5947: $text = &mt('Checking Critical Messages Blocked');
5948: } elsif ($activity eq 'reinit') {
5949: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5950: } elsif ($activity eq 'about') {
5951: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5952: } elsif ($activity eq 'wishlist') {
5953: $text = &mt('Access to Stored Links Blocked');
5954: } elsif ($activity eq 'annotate') {
5955: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5956: }
1.1061 raeburn 5957: $output .= <<"END_BLOCK";
1.1217 raeburn 5958: <div class='$class'>
1.869 kalberla 5959: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5960: title='$text'>
5961: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5962: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5963: title='$text'>$text</a>
1.867 kalberla 5964: </div>
5965:
5966: END_BLOCK
1.474 raeburn 5967:
1.1061 raeburn 5968: return ($blocked, $output);
1.854 kalberla 5969: }
1.490 raeburn 5970:
1.60 matthew 5971: ###############################################
5972:
1.682 raeburn 5973: sub check_ip_acc {
1.1201 raeburn 5974: my ($acc,$clientip)=@_;
1.682 raeburn 5975: &Apache::lonxml::debug("acc is $acc");
5976: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5977: return 1;
5978: }
1.1339 raeburn 5979: my ($ip,$allowed);
5980: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5981: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5982: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5983: } else {
1.1350 raeburn 5984: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5985: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5986: }
1.682 raeburn 5987:
5988: my $name;
1.1219 raeburn 5989: my %access = (
5990: allowfrom => 1,
5991: denyfrom => 0,
5992: );
5993: my @allows;
5994: my @denies;
5995: foreach my $item (split(',',$acc)) {
5996: $item =~ s/^\s*//;
5997: $item =~ s/\s*$//;
5998: my $pattern;
5999: if ($item =~ /^\!(.+)$/) {
6000: push(@denies,$1);
6001: } else {
6002: push(@allows,$item);
6003: }
6004: }
6005: my $numdenies = scalar(@denies);
6006: my $numallows = scalar(@allows);
6007: my $count = 0;
6008: foreach my $pattern (@denies,@allows) {
6009: $count ++;
6010: my $acctype = 'allowfrom';
6011: if ($count <= $numdenies) {
6012: $acctype = 'denyfrom';
6013: }
1.682 raeburn 6014: if ($pattern =~ /\*$/) {
6015: #35.8.*
6016: $pattern=~s/\*//;
1.1219 raeburn 6017: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6018: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6019: #35.8.3.[34-56]
6020: my $low=$2;
6021: my $high=$3;
6022: $pattern=$1;
6023: if ($ip =~ /^\Q$pattern\E/) {
6024: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6025: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6026: }
6027: } elsif ($pattern =~ /^\*/) {
6028: #*.msu.edu
6029: $pattern=~s/\*//;
6030: if (!defined($name)) {
6031: use Socket;
6032: my $netaddr=inet_aton($ip);
6033: ($name)=gethostbyaddr($netaddr,AF_INET);
6034: }
1.1219 raeburn 6035: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6036: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6037: #127.0.0.1
1.1219 raeburn 6038: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6039: } else {
6040: #some.name.com
6041: if (!defined($name)) {
6042: use Socket;
6043: my $netaddr=inet_aton($ip);
6044: ($name)=gethostbyaddr($netaddr,AF_INET);
6045: }
1.1219 raeburn 6046: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6047: }
6048: if ($allowed =~ /^(0|1)$/) { last; }
6049: }
6050: if ($allowed eq '') {
6051: if ($numdenies && !$numallows) {
6052: $allowed = 1;
6053: } else {
6054: $allowed = 0;
1.682 raeburn 6055: }
6056: }
6057: return $allowed;
6058: }
6059:
6060: ###############################################
6061:
1.60 matthew 6062: =pod
6063:
1.112 bowersj2 6064: =head1 Domain Template Functions
6065:
6066: =over 4
6067:
6068: =item * &determinedomain()
1.60 matthew 6069:
6070: Inputs: $domain (usually will be undef)
6071:
1.63 www 6072: Returns: Determines which domain should be used for designs
1.60 matthew 6073:
6074: =cut
1.54 www 6075:
1.60 matthew 6076: ###############################################
1.63 www 6077: sub determinedomain {
6078: my $domain=shift;
1.531 albertel 6079: if (! $domain) {
1.60 matthew 6080: # Determine domain if we have not been given one
1.893 raeburn 6081: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6082: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6083: if ($env{'request.role.domain'}) {
6084: $domain=$env{'request.role.domain'};
1.60 matthew 6085: }
6086: }
1.63 www 6087: return $domain;
6088: }
6089: ###############################################
1.517 raeburn 6090:
1.518 albertel 6091: sub devalidate_domconfig_cache {
6092: my ($udom)=@_;
6093: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6094: }
6095:
6096: # ---------------------- Get domain configuration for a domain
6097: sub get_domainconf {
6098: my ($udom) = @_;
6099: my $cachetime=1800;
6100: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6101: if (defined($cached)) { return %{$result}; }
6102:
6103: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6104: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6105: my (%designhash,%legacy);
1.518 albertel 6106: if (keys(%domconfig) > 0) {
6107: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6108: if (keys(%{$domconfig{'login'}})) {
6109: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6110: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6111: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6112: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6113: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6114: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6115: if ($key eq 'loginvia') {
6116: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6117: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6118: $designhash{$udom.'.login.loginvia'} = $server;
6119: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6120:
6121: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6122: } else {
6123: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6124: }
1.948 raeburn 6125: }
1.1208 raeburn 6126: } elsif ($key eq 'headtag') {
6127: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6128: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6129: }
1.946 raeburn 6130: }
1.1208 raeburn 6131: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6132: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6133: }
1.946 raeburn 6134: }
6135: }
6136: }
1.1366 raeburn 6137: } elsif ($key eq 'saml') {
6138: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6139: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6140: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6141: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6142: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6143: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6144: }
6145: }
6146: }
6147: }
1.946 raeburn 6148: } else {
6149: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6150: $designhash{$udom.'.login.'.$key.'_'.$img} =
6151: $domconfig{'login'}{$key}{$img};
6152: }
1.699 raeburn 6153: }
6154: } else {
6155: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6156: }
1.632 raeburn 6157: }
6158: } else {
6159: $legacy{'login'} = 1;
1.518 albertel 6160: }
1.632 raeburn 6161: } else {
6162: $legacy{'login'} = 1;
1.518 albertel 6163: }
6164: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6165: if (keys(%{$domconfig{'rolecolors'}})) {
6166: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6167: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6168: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6169: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6170: }
1.518 albertel 6171: }
6172: }
1.632 raeburn 6173: } else {
6174: $legacy{'rolecolors'} = 1;
1.518 albertel 6175: }
1.632 raeburn 6176: } else {
6177: $legacy{'rolecolors'} = 1;
1.518 albertel 6178: }
1.948 raeburn 6179: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6180: if ($domconfig{'autoenroll'}{'co-owners'}) {
6181: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6182: }
6183: }
1.632 raeburn 6184: if (keys(%legacy) > 0) {
6185: my %legacyhash = &get_legacy_domconf($udom);
6186: foreach my $item (keys(%legacyhash)) {
6187: if ($item =~ /^\Q$udom\E\.login/) {
6188: if ($legacy{'login'}) {
6189: $designhash{$item} = $legacyhash{$item};
6190: }
6191: } else {
6192: if ($legacy{'rolecolors'}) {
6193: $designhash{$item} = $legacyhash{$item};
6194: }
1.518 albertel 6195: }
6196: }
6197: }
1.632 raeburn 6198: } else {
6199: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6200: }
6201: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6202: $cachetime);
6203: return %designhash;
6204: }
6205:
1.632 raeburn 6206: sub get_legacy_domconf {
6207: my ($udom) = @_;
6208: my %legacyhash;
6209: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6210: my $designfile = $designdir.'/'.$udom.'.tab';
6211: if (-e $designfile) {
1.1317 raeburn 6212: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6213: while (my $line = <$fh>) {
6214: next if ($line =~ /^\#/);
6215: chomp($line);
6216: my ($key,$val)=(split(/\=/,$line));
6217: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6218: }
6219: close($fh);
6220: }
6221: }
1.1026 raeburn 6222: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6223: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6224: }
6225: return %legacyhash;
6226: }
6227:
1.63 www 6228: =pod
6229:
1.112 bowersj2 6230: =item * &domainlogo()
1.63 www 6231:
6232: Inputs: $domain (usually will be undef)
6233:
6234: Returns: A link to a domain logo, if the domain logo exists.
6235: If the domain logo does not exist, a description of the domain.
6236:
6237: =cut
1.112 bowersj2 6238:
1.63 www 6239: ###############################################
6240: sub domainlogo {
1.517 raeburn 6241: my $domain = &determinedomain(shift);
1.518 albertel 6242: my %designhash = &get_domainconf($domain);
1.517 raeburn 6243: # See if there is a logo
6244: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6245: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6246: if ($imgsrc =~ m{^/(adm|res)/}) {
6247: if ($imgsrc =~ m{^/res/}) {
6248: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6249: &Apache::lonnet::repcopy($local_name);
6250: }
6251: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6252: }
6253: my $alttext = $domain;
6254: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6255: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6256: }
6257: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6258: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6259: return &Apache::lonnet::domain($domain,'description');
1.59 www 6260: } else {
1.60 matthew 6261: return '';
1.59 www 6262: }
6263: }
1.63 www 6264: ##############################################
6265:
6266: =pod
6267:
1.112 bowersj2 6268: =item * &designparm()
1.63 www 6269:
6270: Inputs: $which parameter; $domain (usually will be undef)
6271:
6272: Returns: value of designparamter $which
6273:
6274: =cut
1.112 bowersj2 6275:
1.397 albertel 6276:
1.400 albertel 6277: ##############################################
1.397 albertel 6278: sub designparm {
6279: my ($which,$domain)=@_;
6280: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6281: return $env{'environment.color.'.$which};
1.96 www 6282: }
1.63 www 6283: $domain=&determinedomain($domain);
1.1016 raeburn 6284: my %domdesign;
6285: unless ($domain eq 'public') {
6286: %domdesign = &get_domainconf($domain);
6287: }
1.520 raeburn 6288: my $output;
1.517 raeburn 6289: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6290: $output = $domdesign{$domain.'.'.$which};
1.63 www 6291: } else {
1.520 raeburn 6292: $output = $defaultdesign{$which};
6293: }
6294: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6295: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6296: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6297: if ($output =~ m{^/res/}) {
6298: my $local_name = &Apache::lonnet::filelocation('',$output);
6299: &Apache::lonnet::repcopy($local_name);
6300: }
1.520 raeburn 6301: $output = &lonhttpdurl($output);
6302: }
1.63 www 6303: }
1.520 raeburn 6304: return $output;
1.63 www 6305: }
1.59 www 6306:
1.822 bisitz 6307: ##############################################
6308: =pod
6309:
1.832 bisitz 6310: =item * &authorspace()
6311:
1.1028 raeburn 6312: Inputs: $url (usually will be undef).
1.832 bisitz 6313:
1.1132 raeburn 6314: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6315: directory being viewed (or for which action is being taken).
6316: If $url is provided, and begins /priv/<domain>/<uname>
6317: the path will be that portion of the $context argument.
6318: Otherwise the path will be for the author space of the current
6319: user when the current role is author, or for that of the
6320: co-author/assistant co-author space when the current role
6321: is co-author or assistant co-author.
1.832 bisitz 6322:
6323: =cut
6324:
6325: sub authorspace {
1.1028 raeburn 6326: my ($url) = @_;
6327: if ($url ne '') {
6328: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6329: return $1;
6330: }
6331: }
1.832 bisitz 6332: my $caname = '';
1.1024 www 6333: my $cadom = '';
1.1028 raeburn 6334: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6335: ($cadom,$caname) =
1.832 bisitz 6336: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6337: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6338: $caname = $env{'user.name'};
1.1024 www 6339: $cadom = $env{'user.domain'};
1.832 bisitz 6340: }
1.1028 raeburn 6341: if (($caname ne '') && ($cadom ne '')) {
6342: return "/priv/$cadom/$caname/";
6343: }
6344: return;
1.832 bisitz 6345: }
6346:
6347: ##############################################
6348: =pod
6349:
1.822 bisitz 6350: =item * &head_subbox()
6351:
6352: Inputs: $content (contains HTML code with page functions, etc.)
6353:
6354: Returns: HTML div with $content
6355: To be included in page header
6356:
6357: =cut
6358:
6359: sub head_subbox {
6360: my ($content)=@_;
6361: my $output =
1.993 raeburn 6362: '<div class="LC_head_subbox">'
1.822 bisitz 6363: .$content
6364: .'</div>'
6365: }
6366:
6367: ##############################################
6368: =pod
6369:
6370: =item * &CSTR_pageheader()
6371:
1.1026 raeburn 6372: Input: (optional) filename from which breadcrumb trail is built.
6373: In most cases no input as needed, as $env{'request.filename'}
6374: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6375: frameset flag
6376: If page header is being requested for use in a frameset, then
6377: the second (option) argument -- frameset will be true, and
6378: the target attribute set for links should be target="_parent".
1.1407 raeburn 6379: If $title is supplied as the thitd arg, that will be used to
6380: the left of the breadcrumbs tail for the current path.
1.822 bisitz 6381:
6382: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6383: To be included on Authoring Space pages
1.822 bisitz 6384:
6385: =cut
6386:
6387: sub CSTR_pageheader {
1.1407 raeburn 6388: my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 6389: if ($trailfile eq '') {
6390: $trailfile = $env{'request.filename'};
6391: }
6392:
6393: # this is for resources; directories have customtitle, and crumbs
6394: # and select recent are created in lonpubdir.pm
6395:
6396: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6397: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6398: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6399: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6400: $formaction =~ s{/+}{/}g;
1.822 bisitz 6401:
6402: my $parentpath = '';
6403: my $lastitem = '';
6404: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6405: $parentpath = $1;
6406: $lastitem = $2;
6407: } else {
6408: $lastitem = $thisdisfn;
6409: }
1.921 bisitz 6410:
1.1406 raeburn 6411: my $crsauthor;
1.1246 raeburn 6412: if (($env{'request.course.id'}) &&
6413: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6414: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6415: $crsauthor = 1;
1.1406 raeburn 6416: if ($title eq '') {
6417: $title = &mt('Course Authoring Space');
6418: }
6419: } elsif ($title eq '') {
1.1246 raeburn 6420: $title = &mt('Authoring Space');
6421: }
6422:
1.1379 raeburn 6423: my ($target,$crumbtarget) = (' target="_top"','_top');
6424: if ($frameset) {
6425: $target = ' target="_parent"';
6426: $crumbtarget = '_parent';
6427: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6428: $target = '';
6429: $crumbtarget = '';
1.1379 raeburn 6430: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6431: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6432: $crumbtarget = $env{'request.deeplink.target'};
6433: }
1.1313 raeburn 6434:
1.921 bisitz 6435: my $output =
1.1407 raeburn 6436: '<div>'
1.822 bisitz 6437: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6438: .'<b>'.$title.'</b> '
1.1314 raeburn 6439: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6440: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6441:
6442: if ($lastitem) {
6443: $output .=
6444: '<span class="LC_filename">'
6445: .$lastitem
6446: .'</span>';
6447: }
1.1245 raeburn 6448:
1.1246 raeburn 6449: if ($crsauthor) {
1.1379 raeburn 6450: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6451: } else {
6452: $output .=
6453: '<br />'
1.1314 raeburn 6454: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6455: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6456: .'</form>'
1.1379 raeburn 6457: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6458: }
1.1407 raeburn 6459: $output .= '</div>';
1.921 bisitz 6460:
6461: return $output;
1.822 bisitz 6462: }
6463:
1.1416 raeburn 6464: sub nocodemirror {
6465: my $nocodem = $env{'environment.nocodemirror'};
6466: unless ($nocodem) {
6467: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6468: if ($domdefs{'nocodemirror'}) {
6469: $nocodem = 'yes';
6470: }
6471: }
1.1417 ! raeburn 6472: if ($nocodem eq 'yes') {
! 6473: return 1;
! 6474: }
! 6475: return;
1.1416 raeburn 6476: }
6477:
1.60 matthew 6478: ###############################################
6479: ###############################################
6480:
6481: =pod
6482:
1.112 bowersj2 6483: =back
6484:
1.549 albertel 6485: =head1 HTML Helpers
1.112 bowersj2 6486:
6487: =over 4
6488:
6489: =item * &bodytag()
1.60 matthew 6490:
6491: Returns a uniform header for LON-CAPA web pages.
6492:
6493: Inputs:
6494:
1.112 bowersj2 6495: =over 4
6496:
6497: =item * $title, A title to be displayed on the page.
6498:
6499: =item * $function, the current role (can be undef).
6500:
6501: =item * $addentries, extra parameters for the <body> tag.
6502:
6503: =item * $bodyonly, if defined, only return the <body> tag.
6504:
6505: =item * $domain, if defined, force a given domain.
6506:
6507: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6508: text interface only)
1.60 matthew 6509:
1.814 bisitz 6510: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6511: navigational links
1.317 albertel 6512:
1.338 albertel 6513: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6514:
1.460 albertel 6515: =item * $args, optional argument valid values are
6516: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6517: use_absolute -> for external resource or syllabus, this will
6518: contain https://<hostname> if server uses
6519: https (as per hosts.tab), but request is for http
6520: hostname -> hostname, from $r->hostname().
1.460 albertel 6521:
1.1096 raeburn 6522: =item * $advtoolsref, optional argument, ref to an array containing
6523: inlineremote items to be added in "Functions" menu below
6524: breadcrumbs.
6525:
1.1316 raeburn 6526: =item * $ltiscope, optional argument, will be one of: resource, map or
6527: course, if LON-CAPA is in LTI Provider context. Value is
6528: the scope of use, i.e., launch was for access to a single, a map
6529: or the entire course.
6530:
6531: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6532: context, this will contain the URL for the landing item in
6533: the course, after launch from an LTI Consumer
6534:
1.1318 raeburn 6535: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6536: context, this will contain a reference to hash of items
6537: to be included in the page header and/or inline menu.
6538:
1.1385 raeburn 6539: =item * $menucoll, optional argument, if specific menu collection is in
6540: effect, either set as the default for the course, or set for
6541: the deeplink paramater for $env{'request.deeplink.login'}
6542: then $menucoll will be the number of that collection.
6543:
6544: =item * $menuref, optional argument, reference to a hash, containing the
6545: menu options included for the menu in effect, based on the
6546: configuration for the numbered menu collection in use.
6547:
6548: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6549: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6550: if so, $showncrumbsref is set there to 1, and will propagate back
6551: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6552: being called a second time.
6553:
1.112 bowersj2 6554: =back
6555:
1.60 matthew 6556: Returns: A uniform header for LON-CAPA web pages.
6557: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6558: If $bodyonly is undef or zero, an html string containing a <body> tag and
6559: other decorations will be returned.
6560:
6561: =cut
6562:
1.54 www 6563: sub bodytag {
1.831 bisitz 6564: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6565: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6566: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6567:
1.954 raeburn 6568: my $public;
6569: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6570: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6571: $public = 1;
6572: }
1.460 albertel 6573: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6574: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6575: my $hostname = $args->{'hostname'};
1.339 albertel 6576:
1.183 matthew 6577: $function = &get_users_function() if (!$function);
1.339 albertel 6578: my $img = &designparm($function.'.img',$domain);
6579: my $font = &designparm($function.'.font',$domain);
6580: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6581:
1.803 bisitz 6582: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6583: 'bgcolor' => $pgbg,
1.339 albertel 6584: 'text' => $font,
6585: 'alink' => &designparm($function.'.alink',$domain),
6586: 'vlink' => &designparm($function.'.vlink',$domain),
6587: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6588: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6589:
1.63 www 6590: # role and realm
1.1178 raeburn 6591: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6592: if ($realm) {
6593: $realm = '/'.$realm;
6594: }
1.1357 raeburn 6595: if ($role eq 'ca') {
1.479 albertel 6596: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6597: $realm = &plainname($rname,$rdom);
1.378 raeburn 6598: }
1.55 www 6599: # realm
1.1357 raeburn 6600: my ($cid,$sec);
1.258 albertel 6601: if ($env{'request.course.id'}) {
1.1357 raeburn 6602: $cid = $env{'request.course.id'};
6603: if ($env{'request.course.sec'}) {
6604: $sec = $env{'request.course.sec'};
6605: }
6606: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6607: if (&Apache::lonnet::is_course($1,$2)) {
6608: $cid = $1.'_'.$2;
6609: $sec = $3;
6610: }
6611: }
6612: if ($cid) {
1.378 raeburn 6613: if ($env{'request.role'} !~ /^cr/) {
6614: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6615: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6616: if ($env{'request.role.desc'}) {
6617: $role = $env{'request.role.desc'};
6618: } else {
6619: $role = &mt('Helpdesk[_1]',' '.$2);
6620: }
1.1257 raeburn 6621: } else {
6622: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6623: }
1.1357 raeburn 6624: if ($sec) {
6625: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6626: }
1.1357 raeburn 6627: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6628: } else {
6629: $role = &Apache::lonnet::plaintext($role);
1.54 www 6630: }
1.433 albertel 6631:
1.359 albertel 6632: if (!$realm) { $realm=' '; }
1.330 albertel 6633:
1.438 albertel 6634: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6635:
1.101 www 6636: # construct main body tag
1.359 albertel 6637: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6638: &Apache::lontexconvert::init_math_support();
1.252 albertel 6639:
1.1131 raeburn 6640: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6641:
1.1130 raeburn 6642: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6643: return $bodytag;
1.1130 raeburn 6644: }
1.359 albertel 6645:
1.954 raeburn 6646: if ($public) {
1.433 albertel 6647: undef($role);
6648: }
1.1318 raeburn 6649:
1.1359 raeburn 6650: my $showcrstitle = 1;
1.1357 raeburn 6651: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6652: if (ref($ltimenu) eq 'HASH') {
6653: unless ($ltimenu->{'role'}) {
6654: undef($role);
6655: }
6656: unless ($ltimenu->{'coursetitle'}) {
6657: $realm=' ';
1.1359 raeburn 6658: $showcrstitle = 0;
6659: }
6660: }
6661: } elsif (($cid) && ($menucoll)) {
6662: if (ref($menuref) eq 'HASH') {
6663: unless ($menuref->{'role'}) {
6664: undef($role);
6665: }
6666: unless ($menuref->{'crs'}) {
6667: $realm=' ';
6668: $showcrstitle = 0;
1.1318 raeburn 6669: }
6670: }
6671: }
6672:
1.762 bisitz 6673: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6674: #
6675: # Extra info if you are the DC
6676: my $dc_info = '';
1.1359 raeburn 6677: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6678: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6679: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6680: $dc_info =~ s/\s+$//;
1.359 albertel 6681: }
6682:
1.1237 raeburn 6683: my $crstype;
1.1357 raeburn 6684: if ($cid) {
6685: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6686: } elsif ($args->{'crstype'}) {
6687: $crstype = $args->{'crstype'};
6688: }
6689: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6690: undef($role);
6691: } else {
1.1242 raeburn 6692: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6693: }
1.853 droeschl 6694:
1.903 droeschl 6695: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6696:
6697: # if ($env{'request.state'} eq 'construct') {
6698: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6699: # }
6700:
1.1130 raeburn 6701: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6702: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6703:
1.1318 raeburn 6704: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6705: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 6706: $args->{'links_disabled'},
6707: $args->{'links_target'});
1.359 albertel 6708:
1.1318 raeburn 6709: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6710: if ($dc_info) {
6711: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6712: }
6713: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6714: <em>$realm</em> $dc_info</div>|;
6715: return $bodytag;
6716: }
1.894 droeschl 6717:
1.1318 raeburn 6718: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6719: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6720: }
1.916 droeschl 6721:
1.1318 raeburn 6722: $bodytag .= $right;
1.852 droeschl 6723:
1.1318 raeburn 6724: if ($dc_info) {
6725: $dc_info = &dc_courseid_toggle($dc_info);
6726: }
6727: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6728: }
1.916 droeschl 6729:
1.1169 raeburn 6730: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6731: if ($args->{'no_secondary_menu'}) {
6732: return $bodytag;
6733: }
1.1169 raeburn 6734: #don't show menus for public users
1.954 raeburn 6735: if (!$public){
1.1318 raeburn 6736: unless ($args->{'no_inline_menu'}) {
6737: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6738: $args->{'no_primary_menu'},
1.1369 raeburn 6739: $menucoll,$menuref,
1.1380 raeburn 6740: $args->{'links_disabled'},
6741: $args->{'links_target'});
1.1318 raeburn 6742: }
1.903 droeschl 6743: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6744: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6745: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6746: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 6747: $args->{'bread_crumbs'},'','',$hostname,
6748: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6749: } elsif ($forcereg) {
6750: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 6751: $args->{'group'},$args->{'hide_buttons'},
6752: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6753: } else {
6754: $bodytag .=
6755: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6756: $forcereg,$args->{'group'},
6757: $args->{'bread_crumbs'},
1.1274 raeburn 6758: $advtoolsref,'',$hostname);
1.920 raeburn 6759: }
1.903 droeschl 6760: }else{
6761: # this is to seperate menu from content when there's no secondary
6762: # menu. Especially needed for public accessible ressources.
6763: $bodytag .= '<hr style="clear:both" />';
6764: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6765: }
1.903 droeschl 6766:
1.235 raeburn 6767: return $bodytag;
1.182 matthew 6768: }
6769:
1.917 raeburn 6770: sub dc_courseid_toggle {
6771: my ($dc_info) = @_;
1.980 raeburn 6772: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6773: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6774: &mt('(More ...)').'</a></span>'.
6775: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6776: }
6777:
1.330 albertel 6778: sub make_attr_string {
6779: my ($register,$attr_ref) = @_;
6780:
6781: if ($attr_ref && !ref($attr_ref)) {
6782: die("addentries Must be a hash ref ".
6783: join(':',caller(1))." ".
6784: join(':',caller(0))." ");
6785: }
6786:
6787: if ($register) {
1.339 albertel 6788: my ($on_load,$on_unload);
6789: foreach my $key (keys(%{$attr_ref})) {
6790: if (lc($key) eq 'onload') {
6791: $on_load.=$attr_ref->{$key}.';';
6792: delete($attr_ref->{$key});
6793:
6794: } elsif (lc($key) eq 'onunload') {
6795: $on_unload.=$attr_ref->{$key}.';';
6796: delete($attr_ref->{$key});
6797: }
6798: }
1.953 droeschl 6799: $attr_ref->{'onload'} = $on_load;
6800: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6801: }
1.339 albertel 6802:
1.330 albertel 6803: my $attr_string;
1.1159 raeburn 6804: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6805: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6806: }
6807: return $attr_string;
6808: }
6809:
6810:
1.182 matthew 6811: ###############################################
1.251 albertel 6812: ###############################################
6813:
6814: =pod
6815:
6816: =item * &endbodytag()
6817:
6818: Returns a uniform footer for LON-CAPA web pages.
6819:
1.635 raeburn 6820: Inputs: 1 - optional reference to an args hash
6821: If in the hash, key for noredirectlink has a value which evaluates to true,
6822: a 'Continue' link is not displayed if the page contains an
6823: internal redirect in the <head></head> section,
6824: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6825:
6826: =cut
6827:
6828: sub endbodytag {
1.635 raeburn 6829: my ($args) = @_;
1.1080 raeburn 6830: my $endbodytag;
6831: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6832: $endbodytag='</body>';
6833: }
1.315 albertel 6834: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6835: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 6836: my ($endbodyjs,$idattr);
6837: if ($env{'internal.head.to_opener'}) {
6838: my $linkid = 'LC_continue_link';
6839: $idattr = ' id="'.$linkid.'"';
6840: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6841: $endbodyjs=<<ENDJS;
6842: <script type="text/javascript">
6843: // <![CDATA[
6844: function ebFunction(evt) {
6845: evt.preventDefault();
6846: var dest = '$redirect_for_js';
6847: if (window.opener != null && !window.opener.closed) {
6848: window.opener.location.href=dest;
6849: window.close();
6850: } else {
6851: window.location.href=dest;
6852: }
6853: return false;
6854: }
6855:
6856: \$(document).ready(function () {
6857: if (document.getElementById('$linkid')) {
6858: var clickelem = document.getElementById('$linkid');
6859: clickelem.addEventListener('click',ebFunction,false);
6860: }
6861: });
6862: // ]]>
6863: </script>
6864: ENDJS
6865: }
1.635 raeburn 6866: $endbodytag=
1.1386 raeburn 6867: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6868: &mt('Continue').'</a>'.
6869: $endbodytag;
6870: }
1.315 albertel 6871: }
1.1411 raeburn 6872: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6873: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6874: }
1.251 albertel 6875: return $endbodytag;
6876: }
6877:
1.352 albertel 6878: =pod
6879:
6880: =item * &standard_css()
6881:
6882: Returns a style sheet
6883:
6884: Inputs: (all optional)
6885: domain -> force to color decorate a page for a specific
6886: domain
6887: function -> force usage of a specific rolish color scheme
6888: bgcolor -> override the default page bgcolor
6889:
6890: =cut
6891:
1.343 albertel 6892: sub standard_css {
1.345 albertel 6893: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6894: $function = &get_users_function() if (!$function);
6895: my $img = &designparm($function.'.img', $domain);
6896: my $tabbg = &designparm($function.'.tabbg', $domain);
6897: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6898: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6899: #second colour for later usage
1.345 albertel 6900: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6901: my $pgbg_or_bgcolor =
6902: $bgcolor ||
1.352 albertel 6903: &designparm($function.'.pgbg', $domain);
1.382 albertel 6904: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6905: my $alink = &designparm($function.'.alink', $domain);
6906: my $vlink = &designparm($function.'.vlink', $domain);
6907: my $link = &designparm($function.'.link', $domain);
6908:
1.602 albertel 6909: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6910: my $mono = 'monospace';
1.850 bisitz 6911: my $data_table_head = $sidebg;
6912: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6913: my $data_table_dark = '#E0E0E0';
1.470 banghart 6914: my $data_table_darker = '#CCCCCC';
1.349 albertel 6915: my $data_table_highlight = '#FFFF00';
1.352 albertel 6916: my $mail_new = '#FFBB77';
6917: my $mail_new_hover = '#DD9955';
6918: my $mail_read = '#BBBB77';
6919: my $mail_read_hover = '#999944';
6920: my $mail_replied = '#AAAA88';
6921: my $mail_replied_hover = '#888855';
6922: my $mail_other = '#99BBBB';
6923: my $mail_other_hover = '#669999';
1.391 albertel 6924: my $table_header = '#DDDDDD';
1.489 raeburn 6925: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6926: my $lg_border_color = '#C8C8C8';
1.952 onken 6927: my $button_hover = '#BF2317';
1.392 albertel 6928:
1.608 albertel 6929: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6930: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6931: : '0 3px 0 4px';
1.448 albertel 6932:
1.523 albertel 6933:
1.343 albertel 6934: return <<END;
1.947 droeschl 6935:
6936: /* needed for iframe to allow 100% height in FF */
6937: body, html {
6938: margin: 0;
6939: padding: 0 0.5%;
6940: height: 99%; /* to avoid scrollbars */
6941: }
6942:
1.795 www 6943: body {
1.911 bisitz 6944: font-family: $sans;
6945: line-height:130%;
6946: font-size:0.83em;
6947: color:$font;
1.795 www 6948: }
6949:
1.959 onken 6950: a:focus,
6951: a:focus img {
1.795 www 6952: color: red;
6953: }
1.698 harmsja 6954:
1.911 bisitz 6955: form, .inline {
6956: display: inline;
1.795 www 6957: }
1.721 harmsja 6958:
1.795 www 6959: .LC_right {
1.911 bisitz 6960: text-align:right;
1.795 www 6961: }
6962:
6963: .LC_middle {
1.911 bisitz 6964: vertical-align:middle;
1.795 www 6965: }
1.721 harmsja 6966:
1.1130 raeburn 6967: .LC_floatleft {
6968: float: left;
6969: }
6970:
6971: .LC_floatright {
6972: float: right;
6973: }
6974:
1.911 bisitz 6975: .LC_400Box {
6976: width:400px;
6977: }
1.721 harmsja 6978:
1.947 droeschl 6979: .LC_iframecontainer {
6980: width: 98%;
6981: margin: 0;
6982: position: fixed;
6983: top: 8.5em;
6984: bottom: 0;
6985: }
6986:
6987: .LC_iframecontainer iframe{
6988: border: none;
6989: width: 100%;
6990: height: 100%;
6991: }
6992:
1.778 bisitz 6993: .LC_filename {
6994: font-family: $mono;
6995: white-space:pre;
1.921 bisitz 6996: font-size: 120%;
1.778 bisitz 6997: }
6998:
6999: .LC_fileicon {
7000: border: none;
7001: height: 1.3em;
7002: vertical-align: text-bottom;
7003: margin-right: 0.3em;
7004: text-decoration:none;
7005: }
7006:
1.1008 www 7007: .LC_setting {
7008: text-decoration:underline;
7009: }
7010:
1.350 albertel 7011: .LC_error {
7012: color: red;
7013: }
1.795 www 7014:
1.1097 bisitz 7015: .LC_warning {
7016: color: darkorange;
7017: }
7018:
1.457 albertel 7019: .LC_diff_removed {
1.733 bisitz 7020: color: red;
1.394 albertel 7021: }
1.532 albertel 7022:
7023: .LC_info,
1.457 albertel 7024: .LC_success,
7025: .LC_diff_added {
1.350 albertel 7026: color: green;
7027: }
1.795 www 7028:
1.802 bisitz 7029: div.LC_confirm_box {
7030: background-color: #FAFAFA;
7031: border: 1px solid $lg_border_color;
7032: margin-right: 0;
7033: padding: 5px;
7034: }
7035:
7036: div.LC_confirm_box .LC_error img,
7037: div.LC_confirm_box .LC_success img {
7038: vertical-align: middle;
7039: }
7040:
1.1242 raeburn 7041: .LC_maxwidth {
7042: max-width: 100%;
7043: height: auto;
7044: }
7045:
1.1243 raeburn 7046: .LC_textsize_mobile {
7047: \@media only screen and (max-device-width: 480px) {
7048: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7049: }
7050: }
7051:
1.440 albertel 7052: .LC_icon {
1.771 droeschl 7053: border: none;
1.790 droeschl 7054: vertical-align: middle;
1.771 droeschl 7055: }
7056:
1.543 albertel 7057: .LC_docs_spacer {
7058: width: 25px;
7059: height: 1px;
1.771 droeschl 7060: border: none;
1.543 albertel 7061: }
1.346 albertel 7062:
1.532 albertel 7063: .LC_internal_info {
1.735 bisitz 7064: color: #999999;
1.532 albertel 7065: }
7066:
1.794 www 7067: .LC_discussion {
1.1050 www 7068: background: $data_table_dark;
1.911 bisitz 7069: border: 1px solid black;
7070: margin: 2px;
1.794 www 7071: }
7072:
7073: .LC_disc_action_left {
1.1050 www 7074: background: $sidebg;
1.911 bisitz 7075: text-align: left;
1.1050 www 7076: padding: 4px;
7077: margin: 2px;
1.794 www 7078: }
7079:
7080: .LC_disc_action_right {
1.1050 www 7081: background: $sidebg;
1.911 bisitz 7082: text-align: right;
1.1050 www 7083: padding: 4px;
7084: margin: 2px;
1.794 www 7085: }
7086:
7087: .LC_disc_new_item {
1.911 bisitz 7088: background: white;
7089: border: 2px solid red;
1.1050 www 7090: margin: 4px;
7091: padding: 4px;
1.794 www 7092: }
7093:
7094: .LC_disc_old_item {
1.911 bisitz 7095: background: white;
1.1050 www 7096: margin: 4px;
7097: padding: 4px;
1.794 www 7098: }
7099:
1.458 albertel 7100: table.LC_pastsubmission {
7101: border: 1px solid black;
7102: margin: 2px;
7103: }
7104:
1.924 bisitz 7105: table#LC_menubuttons {
1.345 albertel 7106: width: 100%;
7107: background: $pgbg;
1.392 albertel 7108: border: 2px;
1.402 albertel 7109: border-collapse: separate;
1.803 bisitz 7110: padding: 0;
1.345 albertel 7111: }
1.392 albertel 7112:
1.801 tempelho 7113: table#LC_title_bar a {
7114: color: $fontmenu;
7115: }
1.836 bisitz 7116:
1.807 droeschl 7117: table#LC_title_bar {
1.819 tempelho 7118: clear: both;
1.836 bisitz 7119: display: none;
1.807 droeschl 7120: }
7121:
1.795 www 7122: table#LC_title_bar,
1.933 droeschl 7123: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7124: table#LC_title_bar.LC_with_remote {
1.359 albertel 7125: width: 100%;
1.392 albertel 7126: border-color: $pgbg;
7127: border-style: solid;
7128: border-width: $border;
1.379 albertel 7129: background: $pgbg;
1.801 tempelho 7130: color: $fontmenu;
1.392 albertel 7131: border-collapse: collapse;
1.803 bisitz 7132: padding: 0;
1.819 tempelho 7133: margin: 0;
1.359 albertel 7134: }
1.795 www 7135:
1.933 droeschl 7136: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7137: margin: 0;
7138: padding: 0;
1.933 droeschl 7139: position: relative;
7140: list-style: none;
1.913 droeschl 7141: }
1.933 droeschl 7142: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7143: display: inline;
7144: }
1.933 droeschl 7145:
7146: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7147: padding: 0;
1.933 droeschl 7148: margin: 0;
7149: float: left;
1.913 droeschl 7150: }
1.933 droeschl 7151: .LC_breadcrumb_tools_tools {
7152: padding: 0;
7153: margin: 0;
1.913 droeschl 7154: float: right;
7155: }
7156:
1.1240 raeburn 7157: .LC_placement_prog {
7158: padding-right: 20px;
7159: font-weight: bold;
7160: font-size: 90%;
7161: }
7162:
1.359 albertel 7163: table#LC_title_bar td {
7164: background: $tabbg;
7165: }
1.795 www 7166:
1.911 bisitz 7167: table#LC_menubuttons img {
1.803 bisitz 7168: border: none;
1.346 albertel 7169: }
1.795 www 7170:
1.842 droeschl 7171: .LC_breadcrumbs_component {
1.911 bisitz 7172: float: right;
7173: margin: 0 1em;
1.357 albertel 7174: }
1.842 droeschl 7175: .LC_breadcrumbs_component img {
1.911 bisitz 7176: vertical-align: middle;
1.777 tempelho 7177: }
1.795 www 7178:
1.1243 raeburn 7179: .LC_breadcrumbs_hoverable {
7180: background: $sidebg;
7181: }
7182:
1.383 albertel 7183: td.LC_table_cell_checkbox {
7184: text-align: center;
7185: }
1.795 www 7186:
7187: .LC_fontsize_small {
1.911 bisitz 7188: font-size: 70%;
1.705 tempelho 7189: }
7190:
1.844 bisitz 7191: #LC_breadcrumbs {
1.911 bisitz 7192: clear:both;
7193: background: $sidebg;
7194: border-bottom: 1px solid $lg_border_color;
7195: line-height: 2.5em;
1.933 droeschl 7196: overflow: hidden;
1.911 bisitz 7197: margin: 0;
7198: padding: 0;
1.995 raeburn 7199: text-align: left;
1.819 tempelho 7200: }
1.862 bisitz 7201:
1.1098 bisitz 7202: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7203: clear:both;
7204: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7205: border: 1px solid $sidebg;
1.1098 bisitz 7206: margin: 0 0 10px 0;
1.966 bisitz 7207: padding: 3px;
1.995 raeburn 7208: text-align: left;
1.822 bisitz 7209: }
7210:
1.795 www 7211: .LC_fontsize_medium {
1.911 bisitz 7212: font-size: 85%;
1.705 tempelho 7213: }
7214:
1.795 www 7215: .LC_fontsize_large {
1.911 bisitz 7216: font-size: 120%;
1.705 tempelho 7217: }
7218:
1.346 albertel 7219: .LC_menubuttons_inline_text {
7220: color: $font;
1.698 harmsja 7221: font-size: 90%;
1.701 harmsja 7222: padding-left:3px;
1.346 albertel 7223: }
7224:
1.934 droeschl 7225: .LC_menubuttons_inline_text img{
7226: vertical-align: middle;
7227: }
7228:
1.1051 www 7229: li.LC_menubuttons_inline_text img {
1.951 onken 7230: cursor:pointer;
1.1002 droeschl 7231: text-decoration: none;
1.951 onken 7232: }
7233:
1.526 www 7234: .LC_menubuttons_link {
7235: text-decoration: none;
7236: }
1.795 www 7237:
1.522 albertel 7238: .LC_menubuttons_category {
1.521 www 7239: color: $font;
1.526 www 7240: background: $pgbg;
1.521 www 7241: font-size: larger;
7242: font-weight: bold;
7243: }
7244:
1.346 albertel 7245: td.LC_menubuttons_text {
1.911 bisitz 7246: color: $font;
1.346 albertel 7247: }
1.706 harmsja 7248:
1.346 albertel 7249: .LC_current_location {
7250: background: $tabbg;
7251: }
1.795 www 7252:
1.1286 raeburn 7253: td.LC_zero_height {
7254: line-height: 0;
7255: cellpadding: 0;
7256: }
7257:
1.938 bisitz 7258: table.LC_data_table {
1.347 albertel 7259: border: 1px solid #000000;
1.402 albertel 7260: border-collapse: separate;
1.426 albertel 7261: border-spacing: 1px;
1.610 albertel 7262: background: $pgbg;
1.347 albertel 7263: }
1.795 www 7264:
1.422 albertel 7265: .LC_data_table_dense {
7266: font-size: small;
7267: }
1.795 www 7268:
1.507 raeburn 7269: table.LC_nested_outer {
7270: border: 1px solid #000000;
1.589 raeburn 7271: border-collapse: collapse;
1.803 bisitz 7272: border-spacing: 0;
1.507 raeburn 7273: width: 100%;
7274: }
1.795 www 7275:
1.879 raeburn 7276: table.LC_innerpickbox,
1.507 raeburn 7277: table.LC_nested {
1.803 bisitz 7278: border: none;
1.589 raeburn 7279: border-collapse: collapse;
1.803 bisitz 7280: border-spacing: 0;
1.507 raeburn 7281: width: 100%;
7282: }
1.795 www 7283:
1.911 bisitz 7284: table.LC_data_table tr th,
7285: table.LC_calendar tr th,
1.879 raeburn 7286: table.LC_prior_tries tr th,
7287: table.LC_innerpickbox tr th {
1.349 albertel 7288: font-weight: bold;
7289: background-color: $data_table_head;
1.801 tempelho 7290: color:$fontmenu;
1.701 harmsja 7291: font-size:90%;
1.347 albertel 7292: }
1.795 www 7293:
1.879 raeburn 7294: table.LC_innerpickbox tr th,
7295: table.LC_innerpickbox tr td {
7296: vertical-align: top;
7297: }
7298:
1.711 raeburn 7299: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7300: background-color: #CCCCCC;
1.711 raeburn 7301: font-weight: bold;
7302: text-align: left;
7303: }
1.795 www 7304:
1.912 bisitz 7305: table.LC_data_table tr.LC_odd_row > td {
7306: background-color: $data_table_light;
7307: padding: 2px;
7308: vertical-align: top;
7309: }
7310:
1.809 bisitz 7311: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7312: background-color: $data_table_light;
1.912 bisitz 7313: vertical-align: top;
7314: }
7315:
7316: table.LC_data_table tr.LC_even_row > td {
7317: background-color: $data_table_dark;
1.425 albertel 7318: padding: 2px;
1.900 bisitz 7319: vertical-align: top;
1.347 albertel 7320: }
1.795 www 7321:
1.809 bisitz 7322: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7323: background-color: $data_table_dark;
1.900 bisitz 7324: vertical-align: top;
1.347 albertel 7325: }
1.795 www 7326:
1.425 albertel 7327: table.LC_data_table tr.LC_data_table_highlight td {
7328: background-color: $data_table_darker;
7329: }
1.795 www 7330:
1.639 raeburn 7331: table.LC_data_table tr td.LC_leftcol_header {
7332: background-color: $data_table_head;
7333: font-weight: bold;
7334: }
1.795 www 7335:
1.451 albertel 7336: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7337: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7338: font-weight: bold;
7339: font-style: italic;
7340: text-align: center;
7341: padding: 8px;
1.347 albertel 7342: }
1.795 www 7343:
1.1114 raeburn 7344: table.LC_data_table tr.LC_empty_row td,
7345: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7346: background-color: $sidebg;
7347: }
7348:
7349: table.LC_nested tr.LC_empty_row td {
7350: background-color: #FFFFFF;
7351: }
7352:
1.890 droeschl 7353: table.LC_caption {
7354: }
7355:
1.507 raeburn 7356: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7357: padding: 4ex
7358: }
1.795 www 7359:
1.507 raeburn 7360: table.LC_nested_outer tr th {
7361: font-weight: bold;
1.801 tempelho 7362: color:$fontmenu;
1.507 raeburn 7363: background-color: $data_table_head;
1.701 harmsja 7364: font-size: small;
1.507 raeburn 7365: border-bottom: 1px solid #000000;
7366: }
1.795 www 7367:
1.507 raeburn 7368: table.LC_nested_outer tr td.LC_subheader {
7369: background-color: $data_table_head;
7370: font-weight: bold;
7371: font-size: small;
7372: border-bottom: 1px solid #000000;
7373: text-align: right;
1.451 albertel 7374: }
1.795 www 7375:
1.507 raeburn 7376: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7377: background-color: #CCCCCC;
1.451 albertel 7378: font-weight: bold;
7379: font-size: small;
1.507 raeburn 7380: text-align: center;
7381: }
1.795 www 7382:
1.589 raeburn 7383: table.LC_nested tr.LC_info_row td.LC_left_item,
7384: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7385: text-align: left;
1.451 albertel 7386: }
1.795 www 7387:
1.507 raeburn 7388: table.LC_nested td {
1.735 bisitz 7389: background-color: #FFFFFF;
1.451 albertel 7390: font-size: small;
1.507 raeburn 7391: }
1.795 www 7392:
1.507 raeburn 7393: table.LC_nested_outer tr th.LC_right_item,
7394: table.LC_nested tr.LC_info_row td.LC_right_item,
7395: table.LC_nested tr.LC_odd_row td.LC_right_item,
7396: table.LC_nested tr td.LC_right_item {
1.451 albertel 7397: text-align: right;
7398: }
7399:
1.507 raeburn 7400: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7401: background-color: #EEEEEE;
1.451 albertel 7402: }
7403:
1.473 raeburn 7404: table.LC_createuser {
7405: }
7406:
7407: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7408: font-size: small;
1.473 raeburn 7409: }
7410:
7411: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7412: background-color: #CCCCCC;
1.473 raeburn 7413: font-weight: bold;
7414: text-align: center;
7415: }
7416:
1.349 albertel 7417: table.LC_calendar {
7418: border: 1px solid #000000;
7419: border-collapse: collapse;
1.917 raeburn 7420: width: 98%;
1.349 albertel 7421: }
1.795 www 7422:
1.349 albertel 7423: table.LC_calendar_pickdate {
7424: font-size: xx-small;
7425: }
1.795 www 7426:
1.349 albertel 7427: table.LC_calendar tr td {
7428: border: 1px solid #000000;
7429: vertical-align: top;
1.917 raeburn 7430: width: 14%;
1.349 albertel 7431: }
1.795 www 7432:
1.349 albertel 7433: table.LC_calendar tr td.LC_calendar_day_empty {
7434: background-color: $data_table_dark;
7435: }
1.795 www 7436:
1.779 bisitz 7437: table.LC_calendar tr td.LC_calendar_day_current {
7438: background-color: $data_table_highlight;
1.777 tempelho 7439: }
1.795 www 7440:
1.938 bisitz 7441: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7442: background-color: $mail_new;
7443: }
1.795 www 7444:
1.938 bisitz 7445: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7446: background-color: $mail_new_hover;
7447: }
1.795 www 7448:
1.938 bisitz 7449: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7450: background-color: $mail_read;
7451: }
1.795 www 7452:
1.938 bisitz 7453: /*
7454: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7455: background-color: $mail_read_hover;
7456: }
1.938 bisitz 7457: */
1.795 www 7458:
1.938 bisitz 7459: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7460: background-color: $mail_replied;
7461: }
1.795 www 7462:
1.938 bisitz 7463: /*
7464: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7465: background-color: $mail_replied_hover;
7466: }
1.938 bisitz 7467: */
1.795 www 7468:
1.938 bisitz 7469: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7470: background-color: $mail_other;
7471: }
1.795 www 7472:
1.938 bisitz 7473: /*
7474: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7475: background-color: $mail_other_hover;
7476: }
1.938 bisitz 7477: */
1.494 raeburn 7478:
1.777 tempelho 7479: table.LC_data_table tr > td.LC_browser_file,
7480: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7481: background: #AAEE77;
1.389 albertel 7482: }
1.795 www 7483:
1.777 tempelho 7484: table.LC_data_table tr > td.LC_browser_file_locked,
7485: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7486: background: #FFAA99;
1.387 albertel 7487: }
1.795 www 7488:
1.777 tempelho 7489: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7490: background: #888888;
1.779 bisitz 7491: }
1.795 www 7492:
1.777 tempelho 7493: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7494: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7495: background: #F8F866;
1.777 tempelho 7496: }
1.795 www 7497:
1.696 bisitz 7498: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7499: background: #E0E8FF;
1.387 albertel 7500: }
1.696 bisitz 7501:
1.707 bisitz 7502: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7503: /* background: #77FF77; */
1.707 bisitz 7504: }
1.795 www 7505:
1.707 bisitz 7506: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7507: border-right: 8px solid #FFFF77;
1.707 bisitz 7508: }
1.795 www 7509:
1.707 bisitz 7510: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7511: border-right: 8px solid #FFAA77;
1.707 bisitz 7512: }
1.795 www 7513:
1.707 bisitz 7514: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7515: border-right: 8px solid #FF7777;
1.707 bisitz 7516: }
1.795 www 7517:
1.707 bisitz 7518: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7519: border-right: 8px solid #AAFF77;
1.707 bisitz 7520: }
1.795 www 7521:
1.707 bisitz 7522: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7523: border-right: 8px solid #11CC55;
1.707 bisitz 7524: }
7525:
1.388 albertel 7526: span.LC_current_location {
1.701 harmsja 7527: font-size:larger;
1.388 albertel 7528: background: $pgbg;
7529: }
1.387 albertel 7530:
1.1029 www 7531: span.LC_current_nav_location {
7532: font-weight:bold;
7533: background: $sidebg;
7534: }
7535:
1.395 albertel 7536: span.LC_parm_menu_item {
7537: font-size: larger;
7538: }
1.795 www 7539:
1.395 albertel 7540: span.LC_parm_scope_all {
7541: color: red;
7542: }
1.795 www 7543:
1.395 albertel 7544: span.LC_parm_scope_folder {
7545: color: green;
7546: }
1.795 www 7547:
1.395 albertel 7548: span.LC_parm_scope_resource {
7549: color: orange;
7550: }
1.795 www 7551:
1.395 albertel 7552: span.LC_parm_part {
7553: color: blue;
7554: }
1.795 www 7555:
1.911 bisitz 7556: span.LC_parm_folder,
7557: span.LC_parm_symb {
1.395 albertel 7558: font-size: x-small;
7559: font-family: $mono;
7560: color: #AAAAAA;
7561: }
7562:
1.977 bisitz 7563: ul.LC_parm_parmlist li {
7564: display: inline-block;
7565: padding: 0.3em 0.8em;
7566: vertical-align: top;
7567: width: 150px;
7568: border-top:1px solid $lg_border_color;
7569: }
7570:
1.795 www 7571: td.LC_parm_overview_level_menu,
7572: td.LC_parm_overview_map_menu,
7573: td.LC_parm_overview_parm_selectors,
7574: td.LC_parm_overview_restrictions {
1.396 albertel 7575: border: 1px solid black;
7576: border-collapse: collapse;
7577: }
1.795 www 7578:
1.1285 raeburn 7579: span.LC_parm_recursive,
7580: td.LC_parm_recursive {
7581: font-weight: bold;
7582: font-size: smaller;
7583: }
7584:
1.396 albertel 7585: table.LC_parm_overview_restrictions td {
7586: border-width: 1px 4px 1px 4px;
7587: border-style: solid;
7588: border-color: $pgbg;
7589: text-align: center;
7590: }
1.795 www 7591:
1.396 albertel 7592: table.LC_parm_overview_restrictions th {
7593: background: $tabbg;
7594: border-width: 1px 4px 1px 4px;
7595: border-style: solid;
7596: border-color: $pgbg;
7597: }
1.795 www 7598:
1.398 albertel 7599: table#LC_helpmenu {
1.803 bisitz 7600: border: none;
1.398 albertel 7601: height: 55px;
1.803 bisitz 7602: border-spacing: 0;
1.398 albertel 7603: }
7604:
7605: table#LC_helpmenu fieldset legend {
7606: font-size: larger;
7607: }
1.795 www 7608:
1.397 albertel 7609: table#LC_helpmenu_links {
7610: width: 100%;
7611: border: 1px solid black;
7612: background: $pgbg;
1.803 bisitz 7613: padding: 0;
1.397 albertel 7614: border-spacing: 1px;
7615: }
1.795 www 7616:
1.397 albertel 7617: table#LC_helpmenu_links tr td {
7618: padding: 1px;
7619: background: $tabbg;
1.399 albertel 7620: text-align: center;
7621: font-weight: bold;
1.397 albertel 7622: }
1.396 albertel 7623:
1.795 www 7624: table#LC_helpmenu_links a:link,
7625: table#LC_helpmenu_links a:visited,
1.397 albertel 7626: table#LC_helpmenu_links a:active {
7627: text-decoration: none;
7628: color: $font;
7629: }
1.795 www 7630:
1.397 albertel 7631: table#LC_helpmenu_links a:hover {
7632: text-decoration: underline;
7633: color: $vlink;
7634: }
1.396 albertel 7635:
1.417 albertel 7636: .LC_chrt_popup_exists {
7637: border: 1px solid #339933;
7638: margin: -1px;
7639: }
1.795 www 7640:
1.417 albertel 7641: .LC_chrt_popup_up {
7642: border: 1px solid yellow;
7643: margin: -1px;
7644: }
1.795 www 7645:
1.417 albertel 7646: .LC_chrt_popup {
7647: border: 1px solid #8888FF;
7648: background: #CCCCFF;
7649: }
1.795 www 7650:
1.421 albertel 7651: table.LC_pick_box {
7652: border-collapse: separate;
7653: background: white;
7654: border: 1px solid black;
7655: border-spacing: 1px;
7656: }
1.795 www 7657:
1.421 albertel 7658: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7659: background: $sidebg;
1.421 albertel 7660: font-weight: bold;
1.900 bisitz 7661: text-align: left;
1.740 bisitz 7662: vertical-align: top;
1.421 albertel 7663: width: 184px;
7664: padding: 8px;
7665: }
1.795 www 7666:
1.579 raeburn 7667: table.LC_pick_box td.LC_pick_box_value {
7668: text-align: left;
7669: padding: 8px;
7670: }
1.795 www 7671:
1.579 raeburn 7672: table.LC_pick_box td.LC_pick_box_select {
7673: text-align: left;
7674: padding: 8px;
7675: }
1.795 www 7676:
1.424 albertel 7677: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7678: padding: 0;
1.421 albertel 7679: height: 1px;
7680: background: black;
7681: }
1.795 www 7682:
1.421 albertel 7683: table.LC_pick_box td.LC_pick_box_submit {
7684: text-align: right;
7685: }
1.795 www 7686:
1.579 raeburn 7687: table.LC_pick_box td.LC_evenrow_value {
7688: text-align: left;
7689: padding: 8px;
7690: background-color: $data_table_light;
7691: }
1.795 www 7692:
1.579 raeburn 7693: table.LC_pick_box td.LC_oddrow_value {
7694: text-align: left;
7695: padding: 8px;
7696: background-color: $data_table_light;
7697: }
1.795 www 7698:
1.579 raeburn 7699: span.LC_helpform_receipt_cat {
7700: font-weight: bold;
7701: }
1.795 www 7702:
1.424 albertel 7703: table.LC_group_priv_box {
7704: background: white;
7705: border: 1px solid black;
7706: border-spacing: 1px;
7707: }
1.795 www 7708:
1.424 albertel 7709: table.LC_group_priv_box td.LC_pick_box_title {
7710: background: $tabbg;
7711: font-weight: bold;
7712: text-align: right;
7713: width: 184px;
7714: }
1.795 www 7715:
1.424 albertel 7716: table.LC_group_priv_box td.LC_groups_fixed {
7717: background: $data_table_light;
7718: text-align: center;
7719: }
1.795 www 7720:
1.424 albertel 7721: table.LC_group_priv_box td.LC_groups_optional {
7722: background: $data_table_dark;
7723: text-align: center;
7724: }
1.795 www 7725:
1.424 albertel 7726: table.LC_group_priv_box td.LC_groups_functionality {
7727: background: $data_table_darker;
7728: text-align: center;
7729: font-weight: bold;
7730: }
1.795 www 7731:
1.424 albertel 7732: table.LC_group_priv td {
7733: text-align: left;
1.803 bisitz 7734: padding: 0;
1.424 albertel 7735: }
7736:
7737: .LC_navbuttons {
7738: margin: 2ex 0ex 2ex 0ex;
7739: }
1.795 www 7740:
1.423 albertel 7741: .LC_topic_bar {
7742: font-weight: bold;
7743: background: $tabbg;
1.918 wenzelju 7744: margin: 1em 0em 1em 2em;
1.805 bisitz 7745: padding: 3px;
1.918 wenzelju 7746: font-size: 1.2em;
1.423 albertel 7747: }
1.795 www 7748:
1.423 albertel 7749: .LC_topic_bar span {
1.918 wenzelju 7750: left: 0.5em;
7751: position: absolute;
1.423 albertel 7752: vertical-align: middle;
1.918 wenzelju 7753: font-size: 1.2em;
1.423 albertel 7754: }
1.795 www 7755:
1.423 albertel 7756: table.LC_course_group_status {
7757: margin: 20px;
7758: }
1.795 www 7759:
1.423 albertel 7760: table.LC_status_selector td {
7761: vertical-align: top;
7762: text-align: center;
1.424 albertel 7763: padding: 4px;
7764: }
1.795 www 7765:
1.599 albertel 7766: div.LC_feedback_link {
1.616 albertel 7767: clear: both;
1.829 kalberla 7768: background: $sidebg;
1.779 bisitz 7769: width: 100%;
1.829 kalberla 7770: padding-bottom: 10px;
7771: border: 1px $tabbg solid;
1.833 kalberla 7772: height: 22px;
7773: line-height: 22px;
7774: padding-top: 5px;
7775: }
7776:
7777: div.LC_feedback_link img {
7778: height: 22px;
1.867 kalberla 7779: vertical-align:middle;
1.829 kalberla 7780: }
7781:
1.911 bisitz 7782: div.LC_feedback_link a {
1.829 kalberla 7783: text-decoration: none;
1.489 raeburn 7784: }
1.795 www 7785:
1.867 kalberla 7786: div.LC_comblock {
1.911 bisitz 7787: display:inline;
1.867 kalberla 7788: color:$font;
7789: font-size:90%;
7790: }
7791:
7792: div.LC_feedback_link div.LC_comblock {
7793: padding-left:5px;
7794: }
7795:
7796: div.LC_feedback_link div.LC_comblock a {
7797: color:$font;
7798: }
7799:
1.489 raeburn 7800: span.LC_feedback_link {
1.858 bisitz 7801: /* background: $feedback_link_bg; */
1.599 albertel 7802: font-size: larger;
7803: }
1.795 www 7804:
1.599 albertel 7805: span.LC_message_link {
1.858 bisitz 7806: /* background: $feedback_link_bg; */
1.599 albertel 7807: font-size: larger;
7808: position: absolute;
7809: right: 1em;
1.489 raeburn 7810: }
1.421 albertel 7811:
1.515 albertel 7812: table.LC_prior_tries {
1.524 albertel 7813: border: 1px solid #000000;
7814: border-collapse: separate;
7815: border-spacing: 1px;
1.515 albertel 7816: }
1.523 albertel 7817:
1.515 albertel 7818: table.LC_prior_tries td {
1.524 albertel 7819: padding: 2px;
1.515 albertel 7820: }
1.523 albertel 7821:
7822: .LC_answer_correct {
1.795 www 7823: background: lightgreen;
7824: color: darkgreen;
7825: padding: 6px;
1.523 albertel 7826: }
1.795 www 7827:
1.523 albertel 7828: .LC_answer_charged_try {
1.797 www 7829: background: #FFAAAA;
1.795 www 7830: color: darkred;
7831: padding: 6px;
1.523 albertel 7832: }
1.795 www 7833:
1.779 bisitz 7834: .LC_answer_not_charged_try,
1.523 albertel 7835: .LC_answer_no_grade,
7836: .LC_answer_late {
1.795 www 7837: background: lightyellow;
1.523 albertel 7838: color: black;
1.795 www 7839: padding: 6px;
1.523 albertel 7840: }
1.795 www 7841:
1.523 albertel 7842: .LC_answer_previous {
1.795 www 7843: background: lightblue;
7844: color: darkblue;
7845: padding: 6px;
1.523 albertel 7846: }
1.795 www 7847:
1.779 bisitz 7848: .LC_answer_no_message {
1.777 tempelho 7849: background: #FFFFFF;
7850: color: black;
1.795 www 7851: padding: 6px;
1.779 bisitz 7852: }
1.795 www 7853:
1.1334 raeburn 7854: .LC_answer_unknown,
7855: .LC_answer_warning {
1.779 bisitz 7856: background: orange;
7857: color: black;
1.795 www 7858: padding: 6px;
1.777 tempelho 7859: }
1.795 www 7860:
1.529 albertel 7861: span.LC_prior_numerical,
7862: span.LC_prior_string,
7863: span.LC_prior_custom,
7864: span.LC_prior_reaction,
7865: span.LC_prior_math {
1.925 bisitz 7866: font-family: $mono;
1.523 albertel 7867: white-space: pre;
7868: }
7869:
1.525 albertel 7870: span.LC_prior_string {
1.925 bisitz 7871: font-family: $mono;
1.525 albertel 7872: white-space: pre;
7873: }
7874:
1.523 albertel 7875: table.LC_prior_option {
7876: width: 100%;
7877: border-collapse: collapse;
7878: }
1.795 www 7879:
1.911 bisitz 7880: table.LC_prior_rank,
1.795 www 7881: table.LC_prior_match {
1.528 albertel 7882: border-collapse: collapse;
7883: }
1.795 www 7884:
1.528 albertel 7885: table.LC_prior_option tr td,
7886: table.LC_prior_rank tr td,
7887: table.LC_prior_match tr td {
1.524 albertel 7888: border: 1px solid #000000;
1.515 albertel 7889: }
7890:
1.855 bisitz 7891: .LC_nobreak {
1.544 albertel 7892: white-space: nowrap;
1.519 raeburn 7893: }
7894:
1.576 raeburn 7895: span.LC_cusr_emph {
7896: font-style: italic;
7897: }
7898:
1.633 raeburn 7899: span.LC_cusr_subheading {
7900: font-weight: normal;
7901: font-size: 85%;
7902: }
7903:
1.861 bisitz 7904: div.LC_docs_entry_move {
1.859 bisitz 7905: border: 1px solid #BBBBBB;
1.545 albertel 7906: background: #DDDDDD;
1.861 bisitz 7907: width: 22px;
1.859 bisitz 7908: padding: 1px;
7909: margin: 0;
1.545 albertel 7910: }
7911:
1.861 bisitz 7912: table.LC_data_table tr > td.LC_docs_entry_commands,
7913: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7914: font-size: x-small;
7915: }
1.795 www 7916:
1.861 bisitz 7917: .LC_docs_entry_parameter {
7918: white-space: nowrap;
7919: }
7920:
1.544 albertel 7921: .LC_docs_copy {
1.545 albertel 7922: color: #000099;
1.544 albertel 7923: }
1.795 www 7924:
1.544 albertel 7925: .LC_docs_cut {
1.545 albertel 7926: color: #550044;
1.544 albertel 7927: }
1.795 www 7928:
1.544 albertel 7929: .LC_docs_rename {
1.545 albertel 7930: color: #009900;
1.544 albertel 7931: }
1.795 www 7932:
1.544 albertel 7933: .LC_docs_remove {
1.545 albertel 7934: color: #990000;
7935: }
7936:
1.1284 raeburn 7937: .LC_docs_alias {
7938: color: #440055;
7939: }
7940:
1.1286 raeburn 7941: .LC_domprefs_email,
1.1284 raeburn 7942: .LC_docs_alias_name,
1.547 albertel 7943: .LC_docs_reinit_warn,
7944: .LC_docs_ext_edit {
7945: font-size: x-small;
7946: }
7947:
1.545 albertel 7948: table.LC_docs_adddocs td,
7949: table.LC_docs_adddocs th {
7950: border: 1px solid #BBBBBB;
7951: padding: 4px;
7952: background: #DDDDDD;
1.543 albertel 7953: }
7954:
1.584 albertel 7955: table.LC_sty_begin {
7956: background: #BBFFBB;
7957: }
1.795 www 7958:
1.584 albertel 7959: table.LC_sty_end {
7960: background: #FFBBBB;
7961: }
7962:
1.589 raeburn 7963: table.LC_double_column {
1.803 bisitz 7964: border-width: 0;
1.589 raeburn 7965: border-collapse: collapse;
7966: width: 100%;
7967: padding: 2px;
7968: }
7969:
7970: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7971: top: 2px;
1.589 raeburn 7972: left: 2px;
7973: width: 47%;
7974: vertical-align: top;
7975: }
7976:
7977: table.LC_double_column tr td.LC_right_col {
7978: top: 2px;
1.779 bisitz 7979: right: 2px;
1.589 raeburn 7980: width: 47%;
7981: vertical-align: top;
7982: }
7983:
1.591 raeburn 7984: div.LC_left_float {
7985: float: left;
7986: padding-right: 5%;
1.597 albertel 7987: padding-bottom: 4px;
1.591 raeburn 7988: }
7989:
7990: div.LC_clear_float_header {
1.597 albertel 7991: padding-bottom: 2px;
1.591 raeburn 7992: }
7993:
7994: div.LC_clear_float_footer {
1.597 albertel 7995: padding-top: 10px;
1.591 raeburn 7996: clear: both;
7997: }
7998:
1.597 albertel 7999: div.LC_grade_show_user {
1.941 bisitz 8000: /* border-left: 5px solid $sidebg; */
8001: border-top: 5px solid #000000;
8002: margin: 50px 0 0 0;
1.936 bisitz 8003: padding: 15px 0 5px 10px;
1.597 albertel 8004: }
1.795 www 8005:
1.936 bisitz 8006: div.LC_grade_show_user_odd_row {
1.941 bisitz 8007: /* border-left: 5px solid #000000; */
8008: }
8009:
8010: div.LC_grade_show_user div.LC_Box {
8011: margin-right: 50px;
1.597 albertel 8012: }
8013:
8014: div.LC_grade_submissions,
8015: div.LC_grade_message_center,
1.936 bisitz 8016: div.LC_grade_info_links {
1.597 albertel 8017: margin: 5px;
8018: width: 99%;
8019: background: #FFFFFF;
8020: }
1.795 www 8021:
1.597 albertel 8022: div.LC_grade_submissions_header,
1.936 bisitz 8023: div.LC_grade_message_center_header {
1.705 tempelho 8024: font-weight: bold;
8025: font-size: large;
1.597 albertel 8026: }
1.795 www 8027:
1.597 albertel 8028: div.LC_grade_submissions_body,
1.936 bisitz 8029: div.LC_grade_message_center_body {
1.597 albertel 8030: border: 1px solid black;
8031: width: 99%;
8032: background: #FFFFFF;
8033: }
1.795 www 8034:
1.613 albertel 8035: table.LC_scantron_action {
8036: width: 100%;
8037: }
1.795 www 8038:
1.613 albertel 8039: table.LC_scantron_action tr th {
1.698 harmsja 8040: font-weight:bold;
8041: font-style:normal;
1.613 albertel 8042: }
1.795 www 8043:
1.779 bisitz 8044: .LC_edit_problem_header,
1.614 albertel 8045: div.LC_edit_problem_footer {
1.705 tempelho 8046: font-weight: normal;
8047: font-size: medium;
1.602 albertel 8048: margin: 2px;
1.1060 bisitz 8049: background-color: $sidebg;
1.600 albertel 8050: }
1.795 www 8051:
1.600 albertel 8052: div.LC_edit_problem_header,
1.602 albertel 8053: div.LC_edit_problem_header div,
1.614 albertel 8054: div.LC_edit_problem_footer,
8055: div.LC_edit_problem_footer div,
1.602 albertel 8056: div.LC_edit_problem_editxml_header,
8057: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8058: z-index: 100;
1.600 albertel 8059: }
1.795 www 8060:
1.600 albertel 8061: div.LC_edit_problem_header_title {
1.705 tempelho 8062: font-weight: bold;
8063: font-size: larger;
1.602 albertel 8064: background: $tabbg;
8065: padding: 3px;
1.1060 bisitz 8066: margin: 0 0 5px 0;
1.602 albertel 8067: }
1.795 www 8068:
1.602 albertel 8069: table.LC_edit_problem_header_title {
8070: width: 100%;
1.600 albertel 8071: background: $tabbg;
1.602 albertel 8072: }
8073:
1.1205 golterma 8074: div.LC_edit_actionbar {
8075: background-color: $sidebg;
1.1218 droeschl 8076: margin: 0;
8077: padding: 0;
8078: line-height: 200%;
1.602 albertel 8079: }
1.795 www 8080:
1.1218 droeschl 8081: div.LC_edit_actionbar div{
8082: padding: 0;
8083: margin: 0;
8084: display: inline-block;
1.600 albertel 8085: }
1.795 www 8086:
1.1124 bisitz 8087: .LC_edit_opt {
8088: padding-left: 1em;
8089: white-space: nowrap;
8090: }
8091:
1.1152 golterma 8092: .LC_edit_problem_latexhelper{
8093: text-align: right;
8094: }
8095:
8096: #LC_edit_problem_colorful div{
8097: margin-left: 40px;
8098: }
8099:
1.1205 golterma 8100: #LC_edit_problem_codemirror div{
8101: margin-left: 0px;
8102: }
8103:
1.911 bisitz 8104: img.stift {
1.803 bisitz 8105: border-width: 0;
8106: vertical-align: middle;
1.677 riegler 8107: }
1.680 riegler 8108:
1.923 bisitz 8109: table td.LC_mainmenu_col_fieldset {
1.680 riegler 8110: vertical-align: top;
1.777 tempelho 8111: }
1.795 www 8112:
1.716 raeburn 8113: div.LC_createcourse {
1.911 bisitz 8114: margin: 10px 10px 10px 10px;
1.716 raeburn 8115: }
8116:
1.917 raeburn 8117: .LC_dccid {
1.1130 raeburn 8118: float: right;
1.917 raeburn 8119: margin: 0.2em 0 0 0;
8120: padding: 0;
8121: font-size: 90%;
8122: display:none;
8123: }
8124:
1.897 wenzelju 8125: ol.LC_primary_menu a:hover,
1.721 harmsja 8126: ol#LC_MenuBreadcrumbs a:hover,
8127: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8128: ul#LC_secondary_menu a:hover,
1.721 harmsja 8129: .LC_FormSectionClearButton input:hover
1.795 www 8130: ul.LC_TabContent li:hover a {
1.952 onken 8131: color:$button_hover;
1.911 bisitz 8132: text-decoration:none;
1.693 droeschl 8133: }
8134:
1.779 bisitz 8135: h1 {
1.911 bisitz 8136: padding: 0;
8137: line-height:130%;
1.693 droeschl 8138: }
1.698 harmsja 8139:
1.911 bisitz 8140: h2,
8141: h3,
8142: h4,
8143: h5,
8144: h6 {
8145: margin: 5px 0 5px 0;
8146: padding: 0;
8147: line-height:130%;
1.693 droeschl 8148: }
1.795 www 8149:
8150: .LC_hcell {
1.911 bisitz 8151: padding:3px 15px 3px 15px;
8152: margin: 0;
8153: background-color:$tabbg;
8154: color:$fontmenu;
8155: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8156: }
1.795 www 8157:
1.840 bisitz 8158: .LC_Box > .LC_hcell {
1.911 bisitz 8159: margin: 0 -10px 10px -10px;
1.835 bisitz 8160: }
8161:
1.721 harmsja 8162: .LC_noBorder {
1.911 bisitz 8163: border: 0;
1.698 harmsja 8164: }
1.693 droeschl 8165:
1.721 harmsja 8166: .LC_FormSectionClearButton input {
1.911 bisitz 8167: background-color:transparent;
8168: border: none;
8169: cursor:pointer;
8170: text-decoration:underline;
1.693 droeschl 8171: }
1.763 bisitz 8172:
8173: .LC_help_open_topic {
1.911 bisitz 8174: color: #FFFFFF;
8175: background-color: #EEEEFF;
8176: margin: 1px;
8177: padding: 4px;
8178: border: 1px solid #000033;
8179: white-space: nowrap;
8180: /* vertical-align: middle; */
1.759 neumanie 8181: }
1.693 droeschl 8182:
1.911 bisitz 8183: dl,
8184: ul,
8185: div,
8186: fieldset {
8187: margin: 10px 10px 10px 0;
8188: /* overflow: hidden; */
1.693 droeschl 8189: }
1.795 www 8190:
1.1404 raeburn 8191: fieldset#LC_selectuser {
8192: margin: 0;
8193: padding: 0;
8194: }
8195:
1.1211 raeburn 8196: article.geogebraweb div {
8197: margin: 0;
8198: }
8199:
1.838 bisitz 8200: fieldset > legend {
1.911 bisitz 8201: font-weight: bold;
8202: padding: 0 5px 0 5px;
1.838 bisitz 8203: }
8204:
1.813 bisitz 8205: #LC_nav_bar {
1.911 bisitz 8206: float: left;
1.995 raeburn 8207: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8208: margin: 0 0 2px 0;
1.807 droeschl 8209: }
8210:
1.916 droeschl 8211: #LC_realm {
8212: margin: 0.2em 0 0 0;
8213: padding: 0;
8214: font-weight: bold;
8215: text-align: center;
1.995 raeburn 8216: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8217: }
8218:
1.911 bisitz 8219: #LC_nav_bar em {
8220: font-weight: bold;
8221: font-style: normal;
1.807 droeschl 8222: }
8223:
1.897 wenzelju 8224: ol.LC_primary_menu {
1.934 droeschl 8225: margin: 0;
1.1076 raeburn 8226: padding: 0;
1.807 droeschl 8227: }
8228:
1.852 droeschl 8229: ol#LC_PathBreadcrumbs {
1.911 bisitz 8230: margin: 0;
1.693 droeschl 8231: }
8232:
1.897 wenzelju 8233: ol.LC_primary_menu li {
1.1076 raeburn 8234: color: RGB(80, 80, 80);
8235: vertical-align: middle;
8236: text-align: left;
8237: list-style: none;
1.1205 golterma 8238: position: relative;
1.1076 raeburn 8239: float: left;
1.1205 golterma 8240: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8241: line-height: 1.5em;
1.1076 raeburn 8242: }
8243:
1.1205 golterma 8244: ol.LC_primary_menu li a,
8245: ol.LC_primary_menu li p {
1.1076 raeburn 8246: display: block;
8247: margin: 0;
8248: padding: 0 5px 0 10px;
8249: text-decoration: none;
8250: }
8251:
1.1205 golterma 8252: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8253: display: inline-block;
8254: width: 95%;
8255: text-align: left;
8256: }
8257:
8258: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8259: display: inline-block;
8260: width: 5%;
8261: float: right;
8262: text-align: right;
8263: font-size: 70%;
8264: }
8265:
8266: ol.LC_primary_menu ul {
1.1076 raeburn 8267: display: none;
1.1205 golterma 8268: width: 15em;
1.1076 raeburn 8269: background-color: $data_table_light;
1.1205 golterma 8270: position: absolute;
8271: top: 100%;
1.1076 raeburn 8272: }
8273:
1.1205 golterma 8274: ol.LC_primary_menu ul ul {
8275: left: 100%;
8276: top: 0;
8277: }
8278:
8279: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8280: display: block;
8281: position: absolute;
8282: margin: 0;
8283: padding: 0;
1.1078 raeburn 8284: z-index: 2;
1.1076 raeburn 8285: }
8286:
8287: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8288: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8289: font-size: 90%;
1.911 bisitz 8290: vertical-align: top;
1.1076 raeburn 8291: float: none;
1.1079 raeburn 8292: border-left: 1px solid black;
8293: border-right: 1px solid black;
1.1205 golterma 8294: /* A dark bottom border to visualize different menu options;
8295: overwritten in the create_submenu routine for the last border-bottom of the menu */
8296: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8297: }
8298:
1.1205 golterma 8299: ol.LC_primary_menu li li p:hover {
8300: color:$button_hover;
8301: text-decoration:none;
8302: background-color:$data_table_dark;
1.1076 raeburn 8303: }
8304:
8305: ol.LC_primary_menu li li a:hover {
8306: color:$button_hover;
8307: background-color:$data_table_dark;
1.693 droeschl 8308: }
8309:
1.1205 golterma 8310: /* Font-size equal to the size of the predecessors*/
8311: ol.LC_primary_menu li:hover li li {
8312: font-size: 100%;
8313: }
8314:
1.897 wenzelju 8315: ol.LC_primary_menu li img {
1.911 bisitz 8316: vertical-align: bottom;
1.934 droeschl 8317: height: 1.1em;
1.1077 raeburn 8318: margin: 0.2em 0 0 0;
1.693 droeschl 8319: }
8320:
1.897 wenzelju 8321: ol.LC_primary_menu a {
1.911 bisitz 8322: color: RGB(80, 80, 80);
8323: text-decoration: none;
1.693 droeschl 8324: }
1.795 www 8325:
1.949 droeschl 8326: ol.LC_primary_menu a.LC_new_message {
8327: font-weight:bold;
8328: color: darkred;
8329: }
8330:
1.975 raeburn 8331: ol.LC_docs_parameters {
8332: margin-left: 0;
8333: padding: 0;
8334: list-style: none;
8335: }
8336:
8337: ol.LC_docs_parameters li {
8338: margin: 0;
8339: padding-right: 20px;
8340: display: inline;
8341: }
8342:
1.976 raeburn 8343: ol.LC_docs_parameters li:before {
8344: content: "\\002022 \\0020";
8345: }
8346:
8347: li.LC_docs_parameters_title {
8348: font-weight: bold;
8349: }
8350:
8351: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8352: content: "";
8353: }
8354:
1.897 wenzelju 8355: ul#LC_secondary_menu {
1.1107 raeburn 8356: clear: right;
1.911 bisitz 8357: color: $fontmenu;
8358: background: $tabbg;
8359: list-style: none;
8360: padding: 0;
8361: margin: 0;
8362: width: 100%;
1.995 raeburn 8363: text-align: left;
1.1107 raeburn 8364: float: left;
1.808 droeschl 8365: }
8366:
1.897 wenzelju 8367: ul#LC_secondary_menu li {
1.911 bisitz 8368: font-weight: bold;
8369: line-height: 1.8em;
1.1107 raeburn 8370: border-right: 1px solid black;
8371: float: left;
8372: }
8373:
8374: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8375: background-color: $data_table_light;
8376: }
8377:
8378: ul#LC_secondary_menu li a {
1.911 bisitz 8379: padding: 0 0.8em;
1.1107 raeburn 8380: }
8381:
8382: ul#LC_secondary_menu li ul {
8383: display: none;
8384: }
8385:
8386: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8387: display: block;
8388: position: absolute;
8389: margin: 0;
8390: padding: 0;
8391: list-style:none;
8392: float: none;
8393: background-color: $data_table_light;
8394: z-index: 2;
8395: margin-left: -1px;
8396: }
8397:
8398: ul#LC_secondary_menu li ul li {
8399: font-size: 90%;
8400: vertical-align: top;
8401: border-left: 1px solid black;
1.911 bisitz 8402: border-right: 1px solid black;
1.1119 raeburn 8403: background-color: $data_table_light;
1.1107 raeburn 8404: list-style:none;
8405: float: none;
8406: }
8407:
8408: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8409: background-color: $data_table_dark;
1.807 droeschl 8410: }
8411:
1.847 tempelho 8412: ul.LC_TabContent {
1.911 bisitz 8413: display:block;
8414: background: $sidebg;
8415: border-bottom: solid 1px $lg_border_color;
8416: list-style:none;
1.1020 raeburn 8417: margin: -1px -10px 0 -10px;
1.911 bisitz 8418: padding: 0;
1.693 droeschl 8419: }
8420:
1.795 www 8421: ul.LC_TabContent li,
8422: ul.LC_TabContentBigger li {
1.911 bisitz 8423: float:left;
1.741 harmsja 8424: }
1.795 www 8425:
1.897 wenzelju 8426: ul#LC_secondary_menu li a {
1.911 bisitz 8427: color: $fontmenu;
8428: text-decoration: none;
1.693 droeschl 8429: }
1.795 www 8430:
1.721 harmsja 8431: ul.LC_TabContent {
1.952 onken 8432: min-height:20px;
1.721 harmsja 8433: }
1.795 www 8434:
8435: ul.LC_TabContent li {
1.911 bisitz 8436: vertical-align:middle;
1.959 onken 8437: padding: 0 16px 0 10px;
1.911 bisitz 8438: background-color:$tabbg;
8439: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8440: border-left: solid 1px $font;
1.721 harmsja 8441: }
1.795 www 8442:
1.847 tempelho 8443: ul.LC_TabContent .right {
1.911 bisitz 8444: float:right;
1.847 tempelho 8445: }
8446:
1.911 bisitz 8447: ul.LC_TabContent li a,
8448: ul.LC_TabContent li {
8449: color:rgb(47,47,47);
8450: text-decoration:none;
8451: font-size:95%;
8452: font-weight:bold;
1.952 onken 8453: min-height:20px;
8454: }
8455:
1.959 onken 8456: ul.LC_TabContent li a:hover,
8457: ul.LC_TabContent li a:focus {
1.952 onken 8458: color: $button_hover;
1.959 onken 8459: background:none;
8460: outline:none;
1.952 onken 8461: }
8462:
8463: ul.LC_TabContent li:hover {
8464: color: $button_hover;
8465: cursor:pointer;
1.721 harmsja 8466: }
1.795 www 8467:
1.911 bisitz 8468: ul.LC_TabContent li.active {
1.952 onken 8469: color: $font;
1.911 bisitz 8470: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8471: border-bottom:solid 1px #FFFFFF;
8472: cursor: default;
1.744 ehlerst 8473: }
1.795 www 8474:
1.959 onken 8475: ul.LC_TabContent li.active a {
8476: color:$font;
8477: background:#FFFFFF;
8478: outline: none;
8479: }
1.1047 raeburn 8480:
8481: ul.LC_TabContent li.goback {
8482: float: left;
8483: border-left: none;
8484: }
8485:
1.870 tempelho 8486: #maincoursedoc {
1.911 bisitz 8487: clear:both;
1.870 tempelho 8488: }
8489:
8490: ul.LC_TabContentBigger {
1.911 bisitz 8491: display:block;
8492: list-style:none;
8493: padding: 0;
1.870 tempelho 8494: }
8495:
1.795 www 8496: ul.LC_TabContentBigger li {
1.911 bisitz 8497: vertical-align:bottom;
8498: height: 30px;
8499: font-size:110%;
8500: font-weight:bold;
8501: color: #737373;
1.841 tempelho 8502: }
8503:
1.957 onken 8504: ul.LC_TabContentBigger li.active {
8505: position: relative;
8506: top: 1px;
8507: }
8508:
1.870 tempelho 8509: ul.LC_TabContentBigger li a {
1.911 bisitz 8510: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8511: height: 30px;
8512: line-height: 30px;
8513: text-align: center;
8514: display: block;
8515: text-decoration: none;
1.958 onken 8516: outline: none;
1.741 harmsja 8517: }
1.795 www 8518:
1.870 tempelho 8519: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8520: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8521: color:$font;
1.744 ehlerst 8522: }
1.795 www 8523:
1.870 tempelho 8524: ul.LC_TabContentBigger li b {
1.911 bisitz 8525: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8526: display: block;
8527: float: left;
8528: padding: 0 30px;
1.957 onken 8529: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8530: }
8531:
1.956 onken 8532: ul.LC_TabContentBigger li:hover b {
8533: color:$button_hover;
8534: }
8535:
1.870 tempelho 8536: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8537: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8538: color:$font;
1.957 onken 8539: border: 0;
1.741 harmsja 8540: }
1.693 droeschl 8541:
1.870 tempelho 8542:
1.862 bisitz 8543: ul.LC_CourseBreadcrumbs {
8544: background: $sidebg;
1.1020 raeburn 8545: height: 2em;
1.862 bisitz 8546: padding-left: 10px;
1.1020 raeburn 8547: margin: 0;
1.862 bisitz 8548: list-style-position: inside;
8549: }
8550:
1.911 bisitz 8551: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8552: ol#LC_PathBreadcrumbs {
1.911 bisitz 8553: padding-left: 10px;
8554: margin: 0;
1.933 droeschl 8555: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8556: }
8557:
1.911 bisitz 8558: ol#LC_MenuBreadcrumbs li,
8559: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8560: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8561: display: inline;
1.933 droeschl 8562: white-space: normal;
1.693 droeschl 8563: }
8564:
1.823 bisitz 8565: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8566: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8567: text-decoration: none;
8568: font-size:90%;
1.693 droeschl 8569: }
1.795 www 8570:
1.969 droeschl 8571: ol#LC_MenuBreadcrumbs h1 {
8572: display: inline;
8573: font-size: 90%;
8574: line-height: 2.5em;
8575: margin: 0;
8576: padding: 0;
8577: }
8578:
1.795 www 8579: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8580: text-decoration:none;
8581: font-size:100%;
8582: font-weight:bold;
1.693 droeschl 8583: }
1.795 www 8584:
1.840 bisitz 8585: .LC_Box {
1.911 bisitz 8586: border: solid 1px $lg_border_color;
8587: padding: 0 10px 10px 10px;
1.746 neumanie 8588: }
1.795 www 8589:
1.1020 raeburn 8590: .LC_DocsBox {
8591: border: solid 1px $lg_border_color;
8592: padding: 0 0 10px 10px;
8593: }
8594:
1.795 www 8595: .LC_AboutMe_Image {
1.911 bisitz 8596: float:left;
8597: margin-right:10px;
1.747 neumanie 8598: }
1.795 www 8599:
8600: .LC_Clear_AboutMe_Image {
1.911 bisitz 8601: clear:left;
1.747 neumanie 8602: }
1.795 www 8603:
1.721 harmsja 8604: dl.LC_ListStyleClean dt {
1.911 bisitz 8605: padding-right: 5px;
8606: display: table-header-group;
1.693 droeschl 8607: }
8608:
1.721 harmsja 8609: dl.LC_ListStyleClean dd {
1.911 bisitz 8610: display: table-row;
1.693 droeschl 8611: }
8612:
1.721 harmsja 8613: .LC_ListStyleClean,
8614: .LC_ListStyleSimple,
8615: .LC_ListStyleNormal,
1.795 www 8616: .LC_ListStyleSpecial {
1.911 bisitz 8617: /* display:block; */
8618: list-style-position: inside;
8619: list-style-type: none;
8620: overflow: hidden;
8621: padding: 0;
1.693 droeschl 8622: }
8623:
1.721 harmsja 8624: .LC_ListStyleSimple li,
8625: .LC_ListStyleSimple dd,
8626: .LC_ListStyleNormal li,
8627: .LC_ListStyleNormal dd,
8628: .LC_ListStyleSpecial li,
1.795 www 8629: .LC_ListStyleSpecial dd {
1.911 bisitz 8630: margin: 0;
8631: padding: 5px 5px 5px 10px;
8632: clear: both;
1.693 droeschl 8633: }
8634:
1.721 harmsja 8635: .LC_ListStyleClean li,
8636: .LC_ListStyleClean dd {
1.911 bisitz 8637: padding-top: 0;
8638: padding-bottom: 0;
1.693 droeschl 8639: }
8640:
1.721 harmsja 8641: .LC_ListStyleSimple dd,
1.795 www 8642: .LC_ListStyleSimple li {
1.911 bisitz 8643: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8644: }
8645:
1.721 harmsja 8646: .LC_ListStyleSpecial li,
8647: .LC_ListStyleSpecial dd {
1.911 bisitz 8648: list-style-type: none;
8649: background-color: RGB(220, 220, 220);
8650: margin-bottom: 4px;
1.693 droeschl 8651: }
8652:
1.721 harmsja 8653: table.LC_SimpleTable {
1.911 bisitz 8654: margin:5px;
8655: border:solid 1px $lg_border_color;
1.795 www 8656: }
1.693 droeschl 8657:
1.721 harmsja 8658: table.LC_SimpleTable tr {
1.911 bisitz 8659: padding: 0;
8660: border:solid 1px $lg_border_color;
1.693 droeschl 8661: }
1.795 www 8662:
8663: table.LC_SimpleTable thead {
1.911 bisitz 8664: background:rgb(220,220,220);
1.693 droeschl 8665: }
8666:
1.721 harmsja 8667: div.LC_columnSection {
1.911 bisitz 8668: display: block;
8669: clear: both;
8670: overflow: hidden;
8671: margin: 0;
1.693 droeschl 8672: }
8673:
1.721 harmsja 8674: div.LC_columnSection>* {
1.911 bisitz 8675: float: left;
8676: margin: 10px 20px 10px 0;
8677: overflow:hidden;
1.693 droeschl 8678: }
1.721 harmsja 8679:
1.795 www 8680: table em {
1.911 bisitz 8681: font-weight: bold;
8682: font-style: normal;
1.748 schulted 8683: }
1.795 www 8684:
1.779 bisitz 8685: table.LC_tableBrowseRes,
1.795 www 8686: table.LC_tableOfContent {
1.911 bisitz 8687: border:none;
8688: border-spacing: 1px;
8689: padding: 3px;
8690: background-color: #FFFFFF;
8691: font-size: 90%;
1.753 droeschl 8692: }
1.789 droeschl 8693:
1.911 bisitz 8694: table.LC_tableOfContent {
8695: border-collapse: collapse;
1.789 droeschl 8696: }
8697:
1.771 droeschl 8698: table.LC_tableBrowseRes a,
1.768 schulted 8699: table.LC_tableOfContent a {
1.911 bisitz 8700: background-color: transparent;
8701: text-decoration: none;
1.753 droeschl 8702: }
8703:
1.795 www 8704: table.LC_tableOfContent img {
1.911 bisitz 8705: border: none;
8706: height: 1.3em;
8707: vertical-align: text-bottom;
8708: margin-right: 0.3em;
1.753 droeschl 8709: }
1.757 schulted 8710:
1.795 www 8711: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8712: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8713: }
8714:
1.795 www 8715: a#LC_content_toolbar_everything {
1.911 bisitz 8716: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8717: }
8718:
1.795 www 8719: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8720: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8721: }
8722:
1.795 www 8723: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8724: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8725: }
8726:
1.795 www 8727: a#LC_content_toolbar_changefolder {
1.911 bisitz 8728: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8729: }
8730:
1.795 www 8731: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8732: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8733: }
8734:
1.1043 raeburn 8735: a#LC_content_toolbar_edittoplevel {
8736: background-image:url(/res/adm/pages/edittoplevel.gif);
8737: }
8738:
1.1384 raeburn 8739: a#LC_content_toolbar_printout {
8740: background-image:url(/res/adm/pages/printout.gif);
8741: }
8742:
1.795 www 8743: ul#LC_toolbar li a:hover {
1.911 bisitz 8744: background-position: bottom center;
1.757 schulted 8745: }
8746:
1.795 www 8747: ul#LC_toolbar {
1.911 bisitz 8748: padding: 0;
8749: margin: 2px;
8750: list-style:none;
8751: position:relative;
8752: background-color:white;
1.1082 raeburn 8753: overflow: auto;
1.757 schulted 8754: }
8755:
1.795 www 8756: ul#LC_toolbar li {
1.911 bisitz 8757: border:1px solid white;
8758: padding: 0;
8759: margin: 0;
8760: float: left;
8761: display:inline;
8762: vertical-align:middle;
1.1082 raeburn 8763: white-space: nowrap;
1.911 bisitz 8764: }
1.757 schulted 8765:
1.783 amueller 8766:
1.795 www 8767: a.LC_toolbarItem {
1.911 bisitz 8768: display:block;
8769: padding: 0;
8770: margin: 0;
8771: height: 32px;
8772: width: 32px;
8773: color:white;
8774: border: none;
8775: background-repeat:no-repeat;
8776: background-color:transparent;
1.757 schulted 8777: }
8778:
1.915 droeschl 8779: ul.LC_funclist {
8780: margin: 0;
8781: padding: 0.5em 1em 0.5em 0;
8782: }
8783:
1.933 droeschl 8784: ul.LC_funclist > li:first-child {
8785: font-weight:bold;
8786: margin-left:0.8em;
8787: }
8788:
1.915 droeschl 8789: ul.LC_funclist + ul.LC_funclist {
8790: /*
8791: left border as a seperator if we have more than
8792: one list
8793: */
8794: border-left: 1px solid $sidebg;
8795: /*
8796: this hides the left border behind the border of the
8797: outer box if element is wrapped to the next 'line'
8798: */
8799: margin-left: -1px;
8800: }
8801:
1.843 bisitz 8802: ul.LC_funclist li {
1.915 droeschl 8803: display: inline;
1.782 bisitz 8804: white-space: nowrap;
1.915 droeschl 8805: margin: 0 0 0 25px;
8806: line-height: 150%;
1.782 bisitz 8807: }
8808:
1.974 wenzelju 8809: .LC_hidden {
8810: display: none;
8811: }
8812:
1.1030 www 8813: .LCmodal-overlay {
8814: position:fixed;
8815: top:0;
8816: right:0;
8817: bottom:0;
8818: left:0;
8819: height:100%;
8820: width:100%;
8821: margin:0;
8822: padding:0;
8823: background:#999;
8824: opacity:.75;
8825: filter: alpha(opacity=75);
8826: -moz-opacity: 0.75;
8827: z-index:101;
8828: }
8829:
8830: * html .LCmodal-overlay {
8831: position: absolute;
8832: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8833: }
8834:
8835: .LCmodal-window {
8836: position:fixed;
8837: top:50%;
8838: left:50%;
8839: margin:0;
8840: padding:0;
8841: z-index:102;
8842: }
8843:
8844: * html .LCmodal-window {
8845: position:absolute;
8846: }
8847:
8848: .LCclose-window {
8849: position:absolute;
8850: width:32px;
8851: height:32px;
8852: right:8px;
8853: top:8px;
8854: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8855: text-indent:-99999px;
8856: overflow:hidden;
8857: cursor:pointer;
8858: }
8859:
1.1369 raeburn 8860: .LCisDisabled {
8861: cursor: not-allowed;
8862: opacity: 0.5;
8863: }
8864:
8865: a[aria-disabled="true"] {
8866: color: currentColor;
8867: display: inline-block; /* For IE11/ MS Edge bug */
8868: pointer-events: none;
8869: text-decoration: none;
8870: }
8871:
1.1335 raeburn 8872: pre.LC_wordwrap {
8873: white-space: pre-wrap;
8874: white-space: -moz-pre-wrap;
8875: white-space: -pre-wrap;
8876: white-space: -o-pre-wrap;
8877: word-wrap: break-word;
8878: }
8879:
1.1100 raeburn 8880: /*
1.1231 damieng 8881: styles used for response display
8882: */
8883: div.LC_radiofoil, div.LC_rankfoil {
8884: margin: .5em 0em .5em 0em;
8885: }
8886: table.LC_itemgroup {
8887: margin-top: 1em;
8888: }
8889:
8890: /*
1.1100 raeburn 8891: styles used by TTH when "Default set of options to pass to tth/m
8892: when converting TeX" in course settings has been set
8893:
8894: option passed: -t
8895:
8896: */
8897:
8898: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8899: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8900: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8901: td div.norm {line-height:normal;}
8902:
8903: /*
8904: option passed -y3
8905: */
8906:
8907: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8908: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8909: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8910:
1.1230 damieng 8911: /*
8912: sections with roles, for content only
8913: */
8914: section[class^="role-"] {
8915: padding-left: 10px;
8916: padding-right: 5px;
8917: margin-top: 8px;
8918: margin-bottom: 8px;
8919: border: 1px solid #2A4;
8920: border-radius: 5px;
8921: box-shadow: 0px 1px 1px #BBB;
8922: }
8923: section[class^="role-"]>h1 {
8924: position: relative;
8925: margin: 0px;
8926: padding-top: 10px;
8927: padding-left: 40px;
8928: }
8929: section[class^="role-"]>h1:before {
8930: position: absolute;
8931: left: -5px;
8932: top: 5px;
8933: }
8934: section.role-activity>h1:before {
8935: content:url('/adm/daxe/images/section_icons/activity.png');
8936: }
8937: section.role-advice>h1:before {
8938: content:url('/adm/daxe/images/section_icons/advice.png');
8939: }
8940: section.role-bibliography>h1:before {
8941: content:url('/adm/daxe/images/section_icons/bibliography.png');
8942: }
8943: section.role-citation>h1:before {
8944: content:url('/adm/daxe/images/section_icons/citation.png');
8945: }
8946: section.role-conclusion>h1:before {
8947: content:url('/adm/daxe/images/section_icons/conclusion.png');
8948: }
8949: section.role-definition>h1:before {
8950: content:url('/adm/daxe/images/section_icons/definition.png');
8951: }
8952: section.role-demonstration>h1:before {
8953: content:url('/adm/daxe/images/section_icons/demonstration.png');
8954: }
8955: section.role-example>h1:before {
8956: content:url('/adm/daxe/images/section_icons/example.png');
8957: }
8958: section.role-explanation>h1:before {
8959: content:url('/adm/daxe/images/section_icons/explanation.png');
8960: }
8961: section.role-introduction>h1:before {
8962: content:url('/adm/daxe/images/section_icons/introduction.png');
8963: }
8964: section.role-method>h1:before {
8965: content:url('/adm/daxe/images/section_icons/method.png');
8966: }
8967: section.role-more_information>h1:before {
8968: content:url('/adm/daxe/images/section_icons/more_information.png');
8969: }
8970: section.role-objectives>h1:before {
8971: content:url('/adm/daxe/images/section_icons/objectives.png');
8972: }
8973: section.role-prerequisites>h1:before {
8974: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8975: }
8976: section.role-remark>h1:before {
8977: content:url('/adm/daxe/images/section_icons/remark.png');
8978: }
8979: section.role-reminder>h1:before {
8980: content:url('/adm/daxe/images/section_icons/reminder.png');
8981: }
8982: section.role-summary>h1:before {
8983: content:url('/adm/daxe/images/section_icons/summary.png');
8984: }
8985: section.role-syntax>h1:before {
8986: content:url('/adm/daxe/images/section_icons/syntax.png');
8987: }
8988: section.role-warning>h1:before {
8989: content:url('/adm/daxe/images/section_icons/warning.png');
8990: }
8991:
1.1269 raeburn 8992: #LC_minitab_header {
8993: float:left;
8994: width:100%;
8995: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8996: font-size:93%;
8997: line-height:normal;
8998: margin: 0.5em 0 0.5em 0;
8999: }
9000: #LC_minitab_header ul {
9001: margin:0;
9002: padding:10px 10px 0;
9003: list-style:none;
9004: }
9005: #LC_minitab_header li {
9006: float:left;
9007: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
9008: margin:0;
9009: padding:0 0 0 9px;
9010: }
9011: #LC_minitab_header a {
9012: display:block;
9013: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
9014: padding:5px 15px 4px 6px;
9015: }
9016: #LC_minitab_header #LC_current_minitab {
9017: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
9018: }
9019: #LC_minitab_header #LC_current_minitab a {
9020: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
9021: padding-bottom:5px;
9022: }
9023:
9024:
1.343 albertel 9025: END
9026: }
9027:
1.306 albertel 9028: =pod
9029:
9030: =item * &headtag()
9031:
9032: Returns a uniform footer for LON-CAPA web pages.
9033:
1.307 albertel 9034: Inputs: $title - optional title for the head
9035: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9036: $args - optional arguments
1.319 albertel 9037: force_register - if is true call registerurl so the remote is
9038: informed
1.415 albertel 9039: redirect -> array ref of
9040: 1- seconds before redirect occurs
9041: 2- url to redirect to
9042: 3- whether the side effect should occur
1.315 albertel 9043: (side effect of setting
9044: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9045: redirected to)
9046: 4- whether the redirect target should be
9047: the opener of the current (pop-up)
9048: window (side effect of setting
9049: $env{'internal.head.to_opener'} to
9050: 1, if true.
1.1388 raeburn 9051: 5- whether encrypt check should be skipped
1.352 albertel 9052: domain -> force to color decorate a page for a specific
9053: domain
9054: function -> force usage of a specific rolish color scheme
9055: bgcolor -> override the default page bgcolor
1.460 albertel 9056: no_auto_mt_title
9057: -> prevent &mt()ing the title arg
1.464 albertel 9058:
1.306 albertel 9059: =cut
9060:
9061: sub headtag {
1.313 albertel 9062: my ($title,$head_extra,$args) = @_;
1.306 albertel 9063:
1.363 albertel 9064: my $function = $args->{'function'} || &get_users_function();
9065: my $domain = $args->{'domain'} || &determinedomain();
9066: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9067: my $httphost = $args->{'use_absolute'};
1.418 albertel 9068: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9069: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9070: #time(),
1.418 albertel 9071: $env{'environment.color.timestamp'},
1.363 albertel 9072: $function,$domain,$bgcolor);
9073:
1.369 www 9074: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9075:
1.308 albertel 9076: my $result =
9077: '<head>'.
1.1160 raeburn 9078: &font_settings($args);
1.319 albertel 9079:
1.1188 raeburn 9080: my $inhibitprint;
9081: if ($args->{'print_suppress'}) {
9082: $inhibitprint = &print_suppression();
9083: }
1.1064 raeburn 9084:
1.461 albertel 9085: if (!$args->{'frameset'}) {
9086: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9087: }
1.962 droeschl 9088: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9089: $result .= Apache::lonxml::display_title();
1.319 albertel 9090: }
1.436 albertel 9091: if (!$args->{'no_nav_bar'}
9092: && !$args->{'only_body'}
9093: && !$args->{'frameset'}) {
1.1154 raeburn 9094: $result .= &help_menu_js($httphost);
1.1032 www 9095: $result.=&modal_window();
1.1038 www 9096: $result.=&togglebox_script();
1.1034 www 9097: $result.=&wishlist_window();
1.1041 www 9098: $result.=&LCprogressbarUpdate_script();
1.1034 www 9099: } else {
9100: if ($args->{'add_modal'}) {
9101: $result.=&modal_window();
9102: }
9103: if ($args->{'add_wishlist'}) {
9104: $result.=&wishlist_window();
9105: }
1.1038 www 9106: if ($args->{'add_togglebox'}) {
9107: $result.=&togglebox_script();
9108: }
1.1041 www 9109: if ($args->{'add_progressbar'}) {
9110: $result.=&LCprogressbarUpdate_script();
9111: }
1.436 albertel 9112: }
1.314 albertel 9113: if (ref($args->{'redirect'})) {
1.1388 raeburn 9114: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9115: if (!$skip_enc_check) {
9116: $url = &Apache::lonenc::check_encrypt($url);
9117: }
1.414 albertel 9118: if (!$inhibit_continue) {
9119: $env{'internal.head.redirect'} = $url;
9120: }
1.1386 raeburn 9121: $result.=<<"ADDMETA";
1.313 albertel 9122: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9123: ADDMETA
9124: if ($to_opener) {
9125: $env{'internal.head.to_opener'} = 1;
9126: my $dest = &js_escape($url);
9127: my $timeout = int($time * 1000);
9128: $result .=<<"ENDJS";
9129: <script type="text/javascript">
9130: // <![CDATA[
9131: function LC_To_Opener() {
9132: var dest = '$dest';
9133: if (dest != '') {
9134: if (window.opener != null && !window.opener.closed) {
9135: window.opener.location.href=dest;
9136: window.close();
9137: } else {
9138: window.location.href=dest;
9139: }
9140: }
9141: }
9142: \$(document).ready(function () {
9143: setTimeout('LC_To_Opener()',$timeout);
9144: });
9145: // ]]>
9146: </script>
9147: ENDJS
9148: } else {
9149: $result.=<<"ADDMETA";
1.344 albertel 9150: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9151: ADDMETA
1.1386 raeburn 9152: }
1.1210 raeburn 9153: } else {
9154: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9155: my $requrl = $env{'request.uri'};
9156: if ($requrl eq '') {
9157: $requrl = $ENV{'REQUEST_URI'};
9158: $requrl =~ s/\?.+$//;
9159: }
9160: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9161: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9162: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9163: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9164: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9165: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9166: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9167: my ($offload,$offloadoth);
1.1210 raeburn 9168: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9169: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9170: $offload = 1;
1.1353 raeburn 9171: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9172: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9173: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9174: $offloadoth = 1;
9175: $dom_in_use = $env{'user.domain'};
9176: }
9177: }
1.1340 raeburn 9178: }
9179: }
9180: unless ($offload) {
9181: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9182: if ($domdefs{'offloadoth'}{$lonhost}) {
9183: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9184: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9185: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9186: $offload = 1;
1.1352 raeburn 9187: $offloadoth = 1;
1.1340 raeburn 9188: $dom_in_use = $env{'user.domain'};
9189: }
1.1210 raeburn 9190: }
1.1340 raeburn 9191: }
9192: }
9193: }
9194: if ($offload) {
1.1358 raeburn 9195: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9196: if (($newserver eq '') && ($offloadoth)) {
9197: my @domains = &Apache::lonnet::current_machine_domains();
9198: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9199: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9200: }
9201: }
1.1340 raeburn 9202: if (($newserver) && ($newserver ne $lonhost)) {
9203: my $numsec = 5;
9204: my $timeout = $numsec * 1000;
9205: my ($newurl,$locknum,%locks,$msg);
9206: if ($env{'request.role.adv'}) {
9207: ($locknum,%locks) = &Apache::lonnet::get_locks();
9208: }
9209: my $disable_submit = 0;
9210: if ($requrl =~ /$LONCAPA::assess_re/) {
9211: $disable_submit = 1;
9212: }
9213: if ($locknum) {
9214: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9215: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9216: join(", ",sort(values(%locks)))."\n";
9217: if (&show_course()) {
9218: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9219: } else {
9220: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9221: }
1.1340 raeburn 9222: } else {
9223: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9224: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9225: }
9226: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9227: $newurl = '/adm/switchserver?otherserver='.$newserver;
9228: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9229: $newurl .= '&role='.$env{'request.role'};
9230: }
9231: if ($env{'request.symb'}) {
9232: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9233: if ($shownsymb =~ m{^/enc/}) {
9234: my $reqdmajor = 2;
9235: my $reqdminor = 11;
9236: my $reqdsubminor = 3;
9237: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9238: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9239: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9240: if (($major eq '' && $minor eq '') ||
9241: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9242: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9243: ($reqdsubminor > $subminor))))) {
9244: undef($shownsymb);
9245: }
1.1210 raeburn 9246: }
1.1340 raeburn 9247: if ($shownsymb) {
9248: &js_escape(\$shownsymb);
9249: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9250: }
1.1340 raeburn 9251: } else {
9252: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9253: &js_escape(\$shownurl);
9254: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9255: }
1.1340 raeburn 9256: }
9257: &js_escape(\$msg);
9258: $result.=<<OFFLOAD
1.1210 raeburn 9259: <meta http-equiv="pragma" content="no-cache" />
9260: <script type="text/javascript">
1.1215 raeburn 9261: // <![CDATA[
1.1210 raeburn 9262: function LC_Offload_Now() {
9263: var dest = "$newurl";
9264: if (dest != '') {
9265: window.location.href="$newurl";
9266: }
9267: }
1.1214 raeburn 9268: \$(document).ready(function () {
9269: window.alert('$msg');
9270: if ($disable_submit) {
1.1210 raeburn 9271: \$(".LC_hwk_submit").prop("disabled", true);
9272: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9273: }
9274: setTimeout('LC_Offload_Now()', $timeout);
9275: });
1.1215 raeburn 9276: // ]]>
1.1210 raeburn 9277: </script>
9278: OFFLOAD
9279: }
9280: }
9281: }
9282: }
9283: }
1.313 albertel 9284: }
1.306 albertel 9285: if (!defined($title)) {
9286: $title = 'The LearningOnline Network with CAPA';
9287: }
1.460 albertel 9288: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9289: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9290: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9291: if (!$args->{'frameset'}) {
9292: $result .= ' /';
9293: }
9294: $result .= '>'
1.1064 raeburn 9295: .$inhibitprint
1.414 albertel 9296: .$head_extra;
1.1242 raeburn 9297: my $clientmobile;
9298: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9299: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9300: } else {
9301: $clientmobile = $env{'browser.mobile'};
9302: }
9303: if ($clientmobile) {
1.1137 raeburn 9304: $result .= '
9305: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9306: <meta name="apple-mobile-web-app-capable" content="yes" />';
9307: }
1.1278 raeburn 9308: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9309: return $result.'</head>';
1.306 albertel 9310: }
9311:
9312: =pod
9313:
1.340 albertel 9314: =item * &font_settings()
9315:
9316: Returns neccessary <meta> to set the proper encoding
9317:
1.1160 raeburn 9318: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9319:
9320: =cut
9321:
9322: sub font_settings {
1.1160 raeburn 9323: my ($args) = @_;
1.340 albertel 9324: my $headerstring='';
1.1160 raeburn 9325: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9326: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9327: $headerstring.=
9328: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9329: if (!$args->{'frameset'}) {
9330: $headerstring.= ' /';
9331: }
9332: $headerstring .= '>'."\n";
1.340 albertel 9333: }
9334: return $headerstring;
9335: }
9336:
1.341 albertel 9337: =pod
9338:
1.1064 raeburn 9339: =item * &print_suppression()
9340:
9341: In course context returns css which causes the body to be blank when media="print",
9342: if printout generation is unavailable for the current resource.
9343:
9344: This could be because:
9345:
9346: (a) printstartdate is in the future
9347:
9348: (b) printenddate is in the past
9349:
9350: (c) there is an active exam block with "printout"
9351: functionality blocked
9352:
9353: Users with pav, pfo or evb privileges are exempt.
9354:
9355: Inputs: none
9356:
9357: =cut
9358:
9359:
9360: sub print_suppression {
9361: my $noprint;
9362: if ($env{'request.course.id'}) {
9363: my $scope = $env{'request.course.id'};
9364: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9365: (&Apache::lonnet::allowed('pfo',$scope))) {
9366: return;
9367: }
9368: if ($env{'request.course.sec'} ne '') {
9369: $scope .= "/$env{'request.course.sec'}";
9370: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9371: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9372: return;
1.1064 raeburn 9373: }
9374: }
9375: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9376: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9377: my $clientip = &Apache::lonnet::get_requestor_ip();
9378: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9379: if ($blocked) {
9380: my $checkrole = "cm./$cdom/$cnum";
9381: if ($env{'request.course.sec'} ne '') {
9382: $checkrole .= "/$env{'request.course.sec'}";
9383: }
9384: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9385: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9386: $noprint = 1;
9387: }
9388: }
9389: unless ($noprint) {
9390: my $symb = &Apache::lonnet::symbread();
9391: if ($symb ne '') {
9392: my $navmap = Apache::lonnavmaps::navmap->new();
9393: if (ref($navmap)) {
9394: my $res = $navmap->getBySymb($symb);
9395: if (ref($res)) {
9396: if (!$res->resprintable()) {
9397: $noprint = 1;
9398: }
9399: }
9400: }
9401: }
9402: }
9403: if ($noprint) {
9404: return <<"ENDSTYLE";
9405: <style type="text/css" media="print">
9406: body { display:none }
9407: </style>
9408: ENDSTYLE
9409: }
9410: }
9411: return;
9412: }
9413:
9414: =pod
9415:
1.341 albertel 9416: =item * &xml_begin()
9417:
9418: Returns the needed doctype and <html>
9419:
9420: Inputs: none
9421:
9422: =cut
9423:
9424: sub xml_begin {
1.1168 raeburn 9425: my ($is_frameset) = @_;
1.341 albertel 9426: my $output='';
9427:
9428: if ($env{'browser.mathml'}) {
9429: $output='<?xml version="1.0"?>'
9430: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9431: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9432:
9433: # .'<!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">] >'
9434: .'<!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">'
9435: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9436: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9437: } elsif ($is_frameset) {
9438: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9439: '<html>'."\n";
1.341 albertel 9440: } else {
1.1168 raeburn 9441: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9442: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9443: }
9444: return $output;
9445: }
1.340 albertel 9446:
9447: =pod
9448:
1.306 albertel 9449: =item * &start_page()
9450:
9451: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9452:
1.648 raeburn 9453: Inputs:
9454:
9455: =over 4
9456:
9457: $title - optional title for the page
9458:
9459: $head_extra - optional extra HTML to incude inside the <head>
9460:
9461: $args - additional optional args supported are:
9462:
9463: =over 8
9464:
9465: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9466: arg on
1.814 bisitz 9467: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9468: add_entries -> additional attributes to add to the <body>
9469: domain -> force to color decorate a page for a
1.317 albertel 9470: specific domain
1.648 raeburn 9471: function -> force usage of a specific rolish color
1.317 albertel 9472: scheme
1.648 raeburn 9473: redirect -> see &headtag()
9474: bgcolor -> override the default page bg color
9475: js_ready -> return a string ready for being used in
1.317 albertel 9476: a javascript writeln
1.648 raeburn 9477: html_encode -> return a string ready for being used in
1.320 albertel 9478: a html attribute
1.648 raeburn 9479: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9480: $forcereg arg
1.648 raeburn 9481: frameset -> if true will start with a <frameset>
1.330 albertel 9482: rather than <body>
1.648 raeburn 9483: skip_phases -> hash ref of
1.338 albertel 9484: head -> skip the <html><head> generation
9485: body -> skip all <body> generation
1.648 raeburn 9486: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9487: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9488: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9489: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9490: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9491: group -> includes the current group, if page is for a
1.1274 raeburn 9492: specific group
9493: use_absolute -> for request for external resource or syllabus, this
9494: will contain https://<hostname> if server uses
9495: https (as per hosts.tab), but request is for http
9496: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9497: links_disabled -> Links in primary and secondary menus are disabled
9498: (Can enable them once page has loaded - see lonroles.pm
9499: for an example).
1.1380 raeburn 9500: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9501:
1.648 raeburn 9502: =back
1.460 albertel 9503:
1.648 raeburn 9504: =back
1.562 albertel 9505:
1.306 albertel 9506: =cut
9507:
9508: sub start_page {
1.309 albertel 9509: my ($title,$head_extra,$args) = @_;
1.318 albertel 9510: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9511:
1.315 albertel 9512: $env{'internal.start_page'}++;
1.1359 raeburn 9513: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9514:
1.338 albertel 9515: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9516: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9517: }
1.1316 raeburn 9518:
9519: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9520: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9521: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9522: $args->{'no_primary_menu'} = 1;
9523: }
9524: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9525: $args->{'no_inline_menu'} = 1;
9526: }
9527: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9528: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9529: }
9530: } else {
9531: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9532: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9533: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9534: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9535: $args->{'no_primary_menu'} = 1;
9536: }
9537: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9538: $args->{'no_inline_menu'} = 1;
9539: }
9540: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9541: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9542: }
9543: }
9544: }
1.1316 raeburn 9545: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9546: $env{'course.'.$env{'request.course.id'}.'.domain'},
9547: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9548: } elsif ($env{'request.course.id'}) {
9549: my $expiretime=600;
9550: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9551: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9552: }
9553: my ($deeplinkmenu,$menuref);
9554: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9555: if ($menucoll) {
9556: if (ref($menuref) eq 'HASH') {
9557: %menu = %{$menuref};
9558: }
9559: if ($menu{'top'} eq 'n') {
9560: $args->{'no_primary_menu'} = 1;
9561: }
9562: if ($menu{'inline'} eq 'n') {
9563: unless (&Apache::lonnet::allowed('opa')) {
9564: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9565: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9566: my $crstype = &course_type();
9567: my $now = time;
9568: my $ccrole;
9569: if ($crstype eq 'Community') {
9570: $ccrole = 'co';
9571: } else {
9572: $ccrole = 'cc';
9573: }
9574: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9575: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9576: if ((($start) && ($start<0)) ||
9577: (($end) && ($end<$now)) ||
9578: (($start) && ($now<$start))) {
9579: $args->{'no_inline_menu'} = 1;
9580: }
9581: } else {
9582: $args->{'no_inline_menu'} = 1;
9583: }
9584: }
9585: }
9586: }
1.1316 raeburn 9587: }
1.1359 raeburn 9588:
1.1385 raeburn 9589: my $showncrumbs;
1.338 albertel 9590: if (! exists($args->{'skip_phases'}{'body'}) ) {
9591: if ($args->{'frameset'}) {
9592: my $attr_string = &make_attr_string($args->{'force_register'},
9593: $args->{'add_entries'});
9594: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9595: } else {
9596: $result .=
9597: &bodytag($title,
9598: $args->{'function'}, $args->{'add_entries'},
9599: $args->{'only_body'}, $args->{'domain'},
9600: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9601: $args->{'bgcolor'}, $args,
1.1385 raeburn 9602: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
9603: \%menu,\$showncrumbs);
1.831 bisitz 9604: }
1.330 albertel 9605: }
1.338 albertel 9606:
1.315 albertel 9607: if ($args->{'js_ready'}) {
1.713 kaisler 9608: $result = &js_ready($result);
1.315 albertel 9609: }
1.320 albertel 9610: if ($args->{'html_encode'}) {
1.713 kaisler 9611: $result = &html_encode($result);
9612: }
9613:
1.813 bisitz 9614: # Preparation for new and consistent functionlist at top of screen
9615: # if ($args->{'functionlist'}) {
9616: # $result .= &build_functionlist();
9617: #}
9618:
1.964 droeschl 9619: # Don't add anything more if only_body wanted or in const space
9620: return $result if $args->{'only_body'}
9621: || $env{'request.state'} eq 'construct';
1.813 bisitz 9622:
9623: #Breadcrumbs
1.758 kaisler 9624: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 9625: unless ($showncrumbs) {
1.758 kaisler 9626: &Apache::lonhtmlcommon::clear_breadcrumbs();
9627: #if any br links exists, add them to the breadcrumbs
9628: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9629: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9630: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9631: }
9632: }
1.1096 raeburn 9633: # if @advtools array contains items add then to the breadcrumbs
9634: if (@advtools > 0) {
9635: &Apache::lonmenu::advtools_crumbs(@advtools);
9636: }
1.1272 raeburn 9637: my $menulink;
9638: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9639: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9640: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9641: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9642: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9643: (!$env{'request.role.adv'}))) {
9644: $menulink = 0;
9645: } else {
9646: undef($menulink);
9647: }
1.1385 raeburn 9648: my $linkprotout;
9649: if ($env{'request.deeplink.login'}) {
9650: my $linkprotout = &Apache::lonmenu::linkprot_exit();
9651: if ($linkprotout) {
9652: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9653: }
9654: }
1.758 kaisler 9655: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9656: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9657: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9658: } else {
1.1272 raeburn 9659: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9660: }
1.1385 raeburn 9661: }
1.320 albertel 9662: }
1.315 albertel 9663: return $result;
1.306 albertel 9664: }
9665:
9666: sub end_page {
1.315 albertel 9667: my ($args) = @_;
9668: $env{'internal.end_page'}++;
1.330 albertel 9669: my $result;
1.335 albertel 9670: if ($args->{'discussion'}) {
9671: my ($target,$parser);
9672: if (ref($args->{'discussion'})) {
9673: ($target,$parser) =($args->{'discussion'}{'target'},
9674: $args->{'discussion'}{'parser'});
9675: }
9676: $result .= &Apache::lonxml::xmlend($target,$parser);
9677: }
1.330 albertel 9678: if ($args->{'frameset'}) {
9679: $result .= '</frameset>';
9680: } else {
1.635 raeburn 9681: $result .= &endbodytag($args);
1.330 albertel 9682: }
1.1080 raeburn 9683: unless ($args->{'notbody'}) {
9684: $result .= "\n</html>";
9685: }
1.330 albertel 9686:
1.315 albertel 9687: if ($args->{'js_ready'}) {
1.317 albertel 9688: $result = &js_ready($result);
1.315 albertel 9689: }
1.335 albertel 9690:
1.320 albertel 9691: if ($args->{'html_encode'}) {
9692: $result = &html_encode($result);
9693: }
1.335 albertel 9694:
1.315 albertel 9695: return $result;
9696: }
9697:
1.1359 raeburn 9698: sub menucoll_in_effect {
9699: my ($menucoll,$deeplinkmenu,%menu);
9700: if ($env{'request.course.id'}) {
9701: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9702: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9703: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9704: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9705: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9706: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9707: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9708: my $navmap = Apache::lonnavmaps::navmap->new();
9709: if (ref($navmap)) {
9710: $deeplink = $navmap->get_mapparam(undef,
9711: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9712: '0.deeplink');
1.1370 raeburn 9713: } else {
9714: $check_login_symb = 1;
1.1362 raeburn 9715: }
9716: } else {
1.1370 raeburn 9717: my $symb = &Apache::lonnet::symbread();
9718: if ($symb) {
9719: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9720: } else {
9721: $check_login_symb = 1;
9722: }
1.1362 raeburn 9723: }
9724: } else {
1.1370 raeburn 9725: $check_login_symb = 1;
9726: }
9727: if ($check_login_symb) {
1.1362 raeburn 9728: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9729: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9730: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9731: my $navmap = Apache::lonnavmaps::navmap->new();
9732: if (ref($navmap)) {
9733: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9734: }
9735: } else {
9736: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9737: }
9738: }
1.1359 raeburn 9739: if ($deeplink ne '') {
1.1378 raeburn 9740: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 9741: if ($display =~ /^\d+$/) {
9742: $deeplinkmenu = 1;
9743: $menucoll = $display;
9744: }
9745: }
9746: }
9747: if ($menucoll) {
9748: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9749: }
9750: }
9751: return ($menucoll,$deeplinkmenu,\%menu);
9752: }
9753:
1.1362 raeburn 9754: sub deeplink_login_symb {
9755: my ($cnum,$cdom) = @_;
9756: my $login_symb;
9757: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9758: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9759: }
9760: return $login_symb;
9761: }
9762:
9763: sub symb_from_tinyurl {
9764: my ($url,$cnum,$cdom) = @_;
9765: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9766: my $key = $1;
9767: my ($tinyurl,$login);
9768: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9769: if (defined($cached)) {
9770: $tinyurl = $result;
9771: } else {
9772: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9773: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9774: if ($currtiny{$key} ne '') {
9775: $tinyurl = $currtiny{$key};
9776: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9777: }
1.1364 raeburn 9778: }
9779: if ($tinyurl ne '') {
9780: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9781: if (wantarray) {
9782: return ($cnumreq,$symb);
9783: } elsif ($cnumreq eq $cnum) {
9784: return $symb;
1.1362 raeburn 9785: }
9786: }
9787: }
1.1364 raeburn 9788: if (wantarray) {
9789: return ();
9790: } else {
9791: return;
9792: }
1.1362 raeburn 9793: }
9794:
1.1405 raeburn 9795: sub usable_exttools {
9796: my %tooltypes;
9797: if ($env{'request.course.id'}) {
9798: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9799: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9800: %tooltypes = (
9801: crs => 1,
9802: dom => 1,
9803: );
9804: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9805: $tooltypes{'crs'} = 1;
9806: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9807: $tooltypes{'dom'} = 1;
9808: }
9809: } else {
9810: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9811: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9812: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9813: if ($crstype eq '') {
9814: $crstype = 'course';
9815: }
9816: if ($crstype eq 'course') {
9817: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9818: $crstype = 'official';
9819: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9820: $crstype = 'textbook';
9821: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9822: $crstype = 'lti';
9823: } else {
9824: $crstype = 'unofficial';
9825: }
9826: }
9827: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9828: if ($domdefaults{$crstype.'domexttool'}) {
9829: $tooltypes{'dom'} = 1;
9830: }
9831: if ($domdefaults{$crstype.'exttool'}) {
9832: $tooltypes{'crs'} = 1;
9833: }
9834: }
9835: }
9836: return %tooltypes;
9837: }
9838:
1.1034 www 9839: sub wishlist_window {
9840: return(<<'ENDWISHLIST');
1.1046 raeburn 9841: <script type="text/javascript">
1.1034 www 9842: // <![CDATA[
9843: // <!-- BEGIN LON-CAPA Internal
9844: function set_wishlistlink(title, path) {
9845: if (!title) {
9846: title = document.title;
9847: title = title.replace(/^LON-CAPA /,'');
9848: }
1.1175 raeburn 9849: title = encodeURIComponent(title);
1.1203 raeburn 9850: title = title.replace("'","\\\'");
1.1034 www 9851: if (!path) {
9852: path = location.pathname;
9853: }
1.1175 raeburn 9854: path = encodeURIComponent(path);
1.1203 raeburn 9855: path = path.replace("'","\\\'");
1.1034 www 9856: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9857: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9858: }
9859: // END LON-CAPA Internal -->
9860: // ]]>
9861: </script>
9862: ENDWISHLIST
9863: }
9864:
1.1030 www 9865: sub modal_window {
9866: return(<<'ENDMODAL');
1.1046 raeburn 9867: <script type="text/javascript">
1.1030 www 9868: // <![CDATA[
9869: // <!-- BEGIN LON-CAPA Internal
9870: var modalWindow = {
9871: parent:"body",
9872: windowId:null,
9873: content:null,
9874: width:null,
9875: height:null,
9876: close:function()
9877: {
9878: $(".LCmodal-window").remove();
9879: $(".LCmodal-overlay").remove();
9880: },
9881: open:function()
9882: {
9883: var modal = "";
9884: modal += "<div class=\"LCmodal-overlay\"></div>";
9885: 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;\">";
9886: modal += this.content;
9887: modal += "</div>";
9888:
9889: $(this.parent).append(modal);
9890:
9891: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9892: $(".LCclose-window").click(function(){modalWindow.close();});
9893: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9894: }
9895: };
1.1140 raeburn 9896: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9897: {
1.1266 raeburn 9898: source = source.replace(/'/g,"'");
1.1030 www 9899: modalWindow.windowId = "myModal";
9900: modalWindow.width = width;
9901: modalWindow.height = height;
1.1196 raeburn 9902: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9903: modalWindow.open();
1.1208 raeburn 9904: };
1.1030 www 9905: // END LON-CAPA Internal -->
9906: // ]]>
9907: </script>
9908: ENDMODAL
9909: }
9910:
9911: sub modal_link {
1.1140 raeburn 9912: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9913: unless ($width) { $width=480; }
9914: unless ($height) { $height=400; }
1.1031 www 9915: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9916: unless ($transparency) { $transparency='true'; }
9917:
1.1074 raeburn 9918: my $target_attr;
9919: if (defined($target)) {
9920: $target_attr = 'target="'.$target.'"';
9921: }
9922: return <<"ENDLINK";
1.1336 raeburn 9923: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9924: ENDLINK
1.1030 www 9925: }
9926:
1.1032 www 9927: sub modal_adhoc_script {
1.1365 raeburn 9928: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9929: my $mathjax;
9930: if ($possmathjax) {
9931: $mathjax = <<'ENDJAX';
9932: if (typeof MathJax == 'object') {
9933: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9934: }
9935: ENDJAX
9936: }
1.1032 www 9937: return (<<ENDADHOC);
1.1046 raeburn 9938: <script type="text/javascript">
1.1032 www 9939: // <![CDATA[
9940: var $funcname = function()
9941: {
9942: modalWindow.windowId = "myModal";
9943: modalWindow.width = $width;
9944: modalWindow.height = $height;
9945: modalWindow.content = '$content';
9946: modalWindow.open();
1.1365 raeburn 9947: $mathjax
1.1032 www 9948: };
9949: // ]]>
9950: </script>
9951: ENDADHOC
9952: }
9953:
1.1041 www 9954: sub modal_adhoc_inner {
1.1365 raeburn 9955: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9956: my $innerwidth=$width-20;
9957: $content=&js_ready(
1.1140 raeburn 9958: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9959: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9960: $content.
1.1041 www 9961: &end_scrollbox().
1.1140 raeburn 9962: &end_page()
1.1041 www 9963: );
1.1365 raeburn 9964: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9965: }
9966:
9967: sub modal_adhoc_window {
1.1365 raeburn 9968: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9969: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9970: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9971: }
9972:
9973: sub modal_adhoc_launch {
9974: my ($funcname,$width,$height,$content)=@_;
9975: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9976: <script type="text/javascript">
9977: // <![CDATA[
9978: $funcname();
9979: // ]]>
9980: </script>
9981: ENDLAUNCH
9982: }
9983:
9984: sub modal_adhoc_close {
9985: return (<<ENDCLOSE);
9986: <script type="text/javascript">
9987: // <![CDATA[
9988: modalWindow.close();
9989: // ]]>
9990: </script>
9991: ENDCLOSE
9992: }
9993:
1.1038 www 9994: sub togglebox_script {
9995: return(<<ENDTOGGLE);
9996: <script type="text/javascript">
9997: // <![CDATA[
9998: function LCtoggleDisplay(id,hidetext,showtext) {
9999: link = document.getElementById(id + "link").childNodes[0];
10000: with (document.getElementById(id).style) {
10001: if (display == "none" ) {
10002: display = "inline";
10003: link.nodeValue = hidetext;
10004: } else {
10005: display = "none";
10006: link.nodeValue = showtext;
10007: }
10008: }
10009: }
10010: // ]]>
10011: </script>
10012: ENDTOGGLE
10013: }
10014:
1.1039 www 10015: sub start_togglebox {
10016: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
10017: unless ($heading) { $heading=''; } else { $heading.=' '; }
10018: unless ($showtext) { $showtext=&mt('show'); }
10019: unless ($hidetext) { $hidetext=&mt('hide'); }
10020: unless ($headerbg) { $headerbg='#FFFFFF'; }
10021: return &start_data_table().
10022: &start_data_table_header_row().
10023: '<td bgcolor="'.$headerbg.'">'.$heading.
10024: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
10025: $showtext.'\')">'.$showtext.'</a>]</td>'.
10026: &end_data_table_header_row().
10027: '<tr id="'.$id.'" style="display:none""><td>';
10028: }
10029:
10030: sub end_togglebox {
10031: return '</td></tr>'.&end_data_table();
10032: }
10033:
1.1041 www 10034: sub LCprogressbar_script {
1.1302 raeburn 10035: my ($id,$number_to_do)=@_;
10036: if ($number_to_do) {
10037: return(<<ENDPROGRESS);
1.1041 www 10038: <script type="text/javascript">
10039: // <![CDATA[
1.1045 www 10040: \$('#progressbar$id').progressbar({
1.1041 www 10041: value: 0,
10042: change: function(event, ui) {
10043: var newVal = \$(this).progressbar('option', 'value');
10044: \$('.pblabel', this).text(LCprogressTxt);
10045: }
10046: });
10047: // ]]>
10048: </script>
10049: ENDPROGRESS
1.1302 raeburn 10050: } else {
10051: return(<<ENDPROGRESS);
10052: <script type="text/javascript">
10053: // <![CDATA[
10054: \$('#progressbar$id').progressbar({
10055: value: false,
10056: create: function(event, ui) {
10057: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10058: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10059: }
10060: });
10061: // ]]>
10062: </script>
10063: ENDPROGRESS
10064: }
1.1041 www 10065: }
10066:
10067: sub LCprogressbarUpdate_script {
10068: return(<<ENDPROGRESSUPDATE);
10069: <style type="text/css">
10070: .ui-progressbar { position:relative; }
1.1302 raeburn 10071: .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 10072: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10073: </style>
10074: <script type="text/javascript">
10075: // <![CDATA[
1.1045 www 10076: var LCprogressTxt='---';
10077:
1.1302 raeburn 10078: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10079: LCprogressTxt=progresstext;
1.1302 raeburn 10080: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10081: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10082: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10083: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10084: } else {
10085: \$('#progressbar'+id).progressbar('value',percent);
10086: }
1.1041 www 10087: }
10088: // ]]>
10089: </script>
10090: ENDPROGRESSUPDATE
10091: }
10092:
1.1042 www 10093: my $LClastpercent;
1.1045 www 10094: my $LCidcnt;
10095: my $LCcurrentid;
1.1042 www 10096:
1.1041 www 10097: sub LCprogressbar {
1.1302 raeburn 10098: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10099: $LClastpercent=0;
1.1045 www 10100: $LCidcnt++;
10101: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10102: my ($starting,$content);
10103: if ($number_to_do) {
10104: $starting=&mt('Starting');
10105: $content=(<<ENDPROGBAR);
10106: $preamble
1.1045 www 10107: <div id="progressbar$LCcurrentid">
1.1041 www 10108: <span class="pblabel">$starting</span>
10109: </div>
10110: ENDPROGBAR
1.1302 raeburn 10111: } else {
10112: $starting=&mt('Loading...');
10113: $LClastpercent='false';
10114: $content=(<<ENDPROGBAR);
10115: $preamble
10116: <div id="progressbar$LCcurrentid">
10117: <div class="progress-label">$starting</div>
10118: </div>
10119: ENDPROGBAR
10120: }
10121: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10122: }
10123:
10124: sub LCprogressbarUpdate {
1.1302 raeburn 10125: my ($r,$val,$text,$number_to_do)=@_;
10126: if ($number_to_do) {
10127: unless ($val) {
10128: if ($LClastpercent) {
10129: $val=$LClastpercent;
10130: } else {
10131: $val=0;
10132: }
10133: }
10134: if ($val<0) { $val=0; }
10135: if ($val>100) { $val=0; }
10136: $LClastpercent=$val;
10137: unless ($text) { $text=$val.'%'; }
10138: } else {
10139: $val = 'false';
1.1042 www 10140: }
1.1041 www 10141: $text=&js_ready($text);
1.1044 www 10142: &r_print($r,<<ENDUPDATE);
1.1041 www 10143: <script type="text/javascript">
10144: // <![CDATA[
1.1302 raeburn 10145: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10146: // ]]>
10147: </script>
10148: ENDUPDATE
1.1035 www 10149: }
10150:
1.1042 www 10151: sub LCprogressbarClose {
10152: my ($r)=@_;
10153: $LClastpercent=0;
1.1044 www 10154: &r_print($r,<<ENDCLOSE);
1.1042 www 10155: <script type="text/javascript">
10156: // <![CDATA[
1.1045 www 10157: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10158: // ]]>
10159: </script>
10160: ENDCLOSE
1.1044 www 10161: }
10162:
10163: sub r_print {
10164: my ($r,$to_print)=@_;
10165: if ($r) {
10166: $r->print($to_print);
10167: $r->rflush();
10168: } else {
10169: print($to_print);
10170: }
1.1042 www 10171: }
10172:
1.320 albertel 10173: sub html_encode {
10174: my ($result) = @_;
10175:
1.322 albertel 10176: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10177:
10178: return $result;
10179: }
1.1044 www 10180:
1.317 albertel 10181: sub js_ready {
10182: my ($result) = @_;
10183:
1.323 albertel 10184: $result =~ s/[\n\r]/ /xmsg;
10185: $result =~ s/\\/\\\\/xmsg;
10186: $result =~ s/'/\\'/xmsg;
1.372 albertel 10187: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10188:
10189: return $result;
10190: }
10191:
1.315 albertel 10192: sub validate_page {
10193: if ( exists($env{'internal.start_page'})
1.316 albertel 10194: && $env{'internal.start_page'} > 1) {
10195: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10196: $env{'internal.start_page'}.' '.
1.316 albertel 10197: $ENV{'request.filename'});
1.315 albertel 10198: }
10199: if ( exists($env{'internal.end_page'})
1.316 albertel 10200: && $env{'internal.end_page'} > 1) {
10201: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10202: $env{'internal.end_page'}.' '.
1.316 albertel 10203: $env{'request.filename'});
1.315 albertel 10204: }
10205: if ( exists($env{'internal.start_page'})
10206: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10207: &Apache::lonnet::logthis('start_page called without end_page '.
10208: $env{'request.filename'});
1.315 albertel 10209: }
10210: if ( ! exists($env{'internal.start_page'})
10211: && exists($env{'internal.end_page'})) {
1.316 albertel 10212: &Apache::lonnet::logthis('end_page called without start_page'.
10213: $env{'request.filename'});
1.315 albertel 10214: }
1.306 albertel 10215: }
1.315 albertel 10216:
1.996 www 10217:
10218: sub start_scrollbox {
1.1140 raeburn 10219: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10220: unless ($outerwidth) { $outerwidth='520px'; }
10221: unless ($width) { $width='500px'; }
10222: unless ($height) { $height='200px'; }
1.1075 raeburn 10223: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10224: if ($id ne '') {
1.1140 raeburn 10225: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10226: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10227: }
1.1075 raeburn 10228: if ($bgcolor ne '') {
10229: $tdcol = "background-color: $bgcolor;";
10230: }
1.1137 raeburn 10231: my $nicescroll_js;
10232: if ($env{'browser.mobile'}) {
1.1140 raeburn 10233: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10234: }
10235: return <<"END";
10236: $nicescroll_js
10237:
10238: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10239: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10240: END
10241: }
10242:
10243: sub end_scrollbox {
10244: return '</div></td></tr></table>';
10245: }
10246:
10247: sub nicescroll_javascript {
10248: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10249: my %options;
10250: if (ref($cursor) eq 'HASH') {
10251: %options = %{$cursor};
10252: }
10253: unless ($options{'railalign'} =~ /^left|right$/) {
10254: $options{'railalign'} = 'left';
10255: }
10256: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10257: my $function = &get_users_function();
10258: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10259: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10260: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10261: }
1.1140 raeburn 10262: }
10263: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10264: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10265: $options{'cursoropacity'}='1.0';
10266: }
1.1140 raeburn 10267: } else {
10268: $options{'cursoropacity'}='1.0';
10269: }
10270: if ($options{'cursorfixedheight'} eq 'none') {
10271: delete($options{'cursorfixedheight'});
10272: } else {
10273: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10274: }
10275: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10276: delete($options{'railoffset'});
10277: }
10278: my @niceoptions;
10279: while (my($key,$value) = each(%options)) {
10280: if ($value =~ /^\{.+\}$/) {
10281: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10282: } else {
1.1140 raeburn 10283: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10284: }
1.1140 raeburn 10285: }
10286: my $nicescroll_js = '
1.1137 raeburn 10287: $(document).ready(
1.1140 raeburn 10288: function() {
10289: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10290: }
1.1137 raeburn 10291: );
10292: ';
1.1140 raeburn 10293: if ($framecheck) {
10294: $nicescroll_js .= '
10295: function expand_div(caller) {
10296: if (top === self) {
10297: document.getElementById("'.$id.'").style.width = "auto";
10298: document.getElementById("'.$id.'").style.height = "auto";
10299: } else {
10300: try {
10301: if (parent.frames) {
10302: if (parent.frames.length > 1) {
10303: var framesrc = parent.frames[1].location.href;
10304: var currsrc = framesrc.replace(/\#.*$/,"");
10305: if ((caller == "search") || (currsrc == "'.$location.'")) {
10306: document.getElementById("'.$id.'").style.width = "auto";
10307: document.getElementById("'.$id.'").style.height = "auto";
10308: }
10309: }
10310: }
10311: } catch (e) {
10312: return;
10313: }
1.1137 raeburn 10314: }
1.1140 raeburn 10315: return;
1.996 www 10316: }
1.1140 raeburn 10317: ';
10318: }
10319: if ($needjsready) {
10320: $nicescroll_js = '
10321: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10322: } else {
10323: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10324: }
10325: return $nicescroll_js;
1.996 www 10326: }
10327:
1.318 albertel 10328: sub simple_error_page {
1.1150 bisitz 10329: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10330: my %displayargs;
1.1151 raeburn 10331: if (ref($args) eq 'HASH') {
10332: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10333: if ($args->{'only_body'}) {
10334: $displayargs{'only_body'} = 1;
10335: }
10336: if ($args->{'no_nav_bar'}) {
10337: $displayargs{'no_nav_bar'} = 1;
10338: }
1.1151 raeburn 10339: } else {
10340: $msg = &mt($msg);
10341: }
1.1150 bisitz 10342:
1.318 albertel 10343: my $page =
1.1304 raeburn 10344: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10345: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10346: &Apache::loncommon::end_page();
10347: if (ref($r)) {
10348: $r->print($page);
1.327 albertel 10349: return;
1.318 albertel 10350: }
10351: return $page;
10352: }
1.347 albertel 10353:
10354: {
1.610 albertel 10355: my @row_count;
1.961 onken 10356:
10357: sub start_data_table_count {
10358: unshift(@row_count, 0);
10359: return;
10360: }
10361:
10362: sub end_data_table_count {
10363: shift(@row_count);
10364: return;
10365: }
10366:
1.347 albertel 10367: sub start_data_table {
1.1018 raeburn 10368: my ($add_class,$id) = @_;
1.422 albertel 10369: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10370: my $table_id;
10371: if (defined($id)) {
10372: $table_id = ' id="'.$id.'"';
10373: }
1.961 onken 10374: &start_data_table_count();
1.1018 raeburn 10375: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10376: }
10377:
10378: sub end_data_table {
1.961 onken 10379: &end_data_table_count();
1.389 albertel 10380: return '</table>'."\n";;
1.347 albertel 10381: }
10382:
10383: sub start_data_table_row {
1.974 wenzelju 10384: my ($add_class, $id) = @_;
1.610 albertel 10385: $row_count[0]++;
10386: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10387: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10388: $id = (' id="'.$id.'"') unless ($id eq '');
10389: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10390: }
1.471 banghart 10391:
10392: sub continue_data_table_row {
1.974 wenzelju 10393: my ($add_class, $id) = @_;
1.610 albertel 10394: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10395: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10396: $id = (' id="'.$id.'"') unless ($id eq '');
10397: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10398: }
1.347 albertel 10399:
10400: sub end_data_table_row {
1.389 albertel 10401: return '</tr>'."\n";;
1.347 albertel 10402: }
1.367 www 10403:
1.421 albertel 10404: sub start_data_table_empty_row {
1.707 bisitz 10405: # $row_count[0]++;
1.421 albertel 10406: return '<tr class="LC_empty_row" >'."\n";;
10407: }
10408:
10409: sub end_data_table_empty_row {
10410: return '</tr>'."\n";;
10411: }
10412:
1.367 www 10413: sub start_data_table_header_row {
1.389 albertel 10414: return '<tr class="LC_header_row">'."\n";;
1.367 www 10415: }
10416:
10417: sub end_data_table_header_row {
1.389 albertel 10418: return '</tr>'."\n";;
1.367 www 10419: }
1.890 droeschl 10420:
10421: sub data_table_caption {
10422: my $caption = shift;
10423: return "<caption class=\"LC_caption\">$caption</caption>";
10424: }
1.347 albertel 10425: }
10426:
1.548 albertel 10427: =pod
10428:
10429: =item * &inhibit_menu_check($arg)
10430:
10431: Checks for a inhibitmenu state and generates output to preserve it
10432:
10433: Inputs: $arg - can be any of
10434: - undef - in which case the return value is a string
10435: to add into arguments list of a uri
10436: - 'input' - in which case the return value is a HTML
10437: <form> <input> field of type hidden to
10438: preserve the value
10439: - a url - in which case the return value is the url with
10440: the neccesary cgi args added to preserve the
10441: inhibitmenu state
10442: - a ref to a url - no return value, but the string is
10443: updated to include the neccessary cgi
10444: args to preserve the inhibitmenu state
10445:
10446: =cut
10447:
10448: sub inhibit_menu_check {
10449: my ($arg) = @_;
10450: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10451: if ($arg eq 'input') {
10452: if ($env{'form.inhibitmenu'}) {
10453: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10454: } else {
10455: return
10456: }
10457: }
10458: if ($env{'form.inhibitmenu'}) {
10459: if (ref($arg)) {
10460: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10461: } elsif ($arg eq '') {
10462: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10463: } else {
10464: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10465: }
10466: }
10467: if (!ref($arg)) {
10468: return $arg;
10469: }
10470: }
10471:
1.251 albertel 10472: ###############################################
1.182 matthew 10473:
10474: =pod
10475:
1.549 albertel 10476: =back
10477:
10478: =head1 User Information Routines
10479:
10480: =over 4
10481:
1.405 albertel 10482: =item * &get_users_function()
1.182 matthew 10483:
10484: Used by &bodytag to determine the current users primary role.
10485: Returns either 'student','coordinator','admin', or 'author'.
10486:
10487: =cut
10488:
10489: ###############################################
10490: sub get_users_function {
1.815 tempelho 10491: my $function = 'norole';
1.818 tempelho 10492: if ($env{'request.role'}=~/^(st)/) {
10493: $function='student';
10494: }
1.907 raeburn 10495: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10496: $function='coordinator';
10497: }
1.258 albertel 10498: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10499: $function='admin';
10500: }
1.826 bisitz 10501: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10502: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10503: $function='author';
10504: }
10505: return $function;
1.54 www 10506: }
1.99 www 10507:
10508: ###############################################
10509:
1.233 raeburn 10510: =pod
10511:
1.821 raeburn 10512: =item * &show_course()
10513:
10514: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10515: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10516:
10517: Inputs:
10518: None
10519:
10520: Outputs:
10521: Scalar: 1 if 'Course' to be used, 0 otherwise.
10522:
10523: =cut
10524:
10525: ###############################################
10526: sub show_course {
1.1408 raeburn 10527: my ($udom,$uname) = @_;
10528: if (($udom ne '') && ($uname ne '')) {
10529: if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
1.1410 raeburn 10530: if (&Apache::lonnet::is_advanced_user($udom,$uname)) {
1.1408 raeburn 10531: return 0;
10532: } else {
10533: return 1;
10534: }
10535: }
10536: }
1.821 raeburn 10537: my $course = !$env{'user.adv'};
10538: if (!$env{'user.adv'}) {
10539: foreach my $env (keys(%env)) {
10540: next if ($env !~ m/^user\.priv\./);
10541: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10542: $course = 0;
10543: last;
10544: }
10545: }
10546: }
10547: return $course;
10548: }
10549:
10550: ###############################################
10551:
10552: =pod
10553:
1.542 raeburn 10554: =item * &check_user_status()
1.274 raeburn 10555:
10556: Determines current status of supplied role for a
10557: specific user. Roles can be active, previous or future.
10558:
10559: Inputs:
10560: user's domain, user's username, course's domain,
1.375 raeburn 10561: course's number, optional section ID.
1.274 raeburn 10562:
10563: Outputs:
10564: role status: active, previous or future.
10565:
10566: =cut
10567:
10568: sub check_user_status {
1.412 raeburn 10569: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10570: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10571: my @uroles = keys(%userinfo);
1.274 raeburn 10572: my $srchstr;
10573: my $active_chk = 'none';
1.412 raeburn 10574: my $now = time;
1.274 raeburn 10575: if (@uroles > 0) {
1.908 raeburn 10576: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10577: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10578: } else {
1.412 raeburn 10579: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10580: }
10581: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10582: my $role_end = 0;
10583: my $role_start = 0;
10584: $active_chk = 'active';
1.412 raeburn 10585: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10586: $role_end = $1;
10587: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10588: $role_start = $1;
1.274 raeburn 10589: }
10590: }
10591: if ($role_start > 0) {
1.412 raeburn 10592: if ($now < $role_start) {
1.274 raeburn 10593: $active_chk = 'future';
10594: }
10595: }
10596: if ($role_end > 0) {
1.412 raeburn 10597: if ($now > $role_end) {
1.274 raeburn 10598: $active_chk = 'previous';
10599: }
10600: }
10601: }
10602: }
10603: return $active_chk;
10604: }
10605:
10606: ###############################################
10607:
10608: =pod
10609:
1.405 albertel 10610: =item * &get_sections()
1.233 raeburn 10611:
10612: Determines all the sections for a course including
10613: sections with students and sections containing other roles.
1.419 raeburn 10614: Incoming parameters:
10615:
10616: 1. domain
10617: 2. course number
10618: 3. reference to array containing roles for which sections should
10619: be gathered (optional).
10620: 4. reference to array containing status types for which sections
10621: should be gathered (optional).
10622:
10623: If the third argument is undefined, sections are gathered for any role.
10624: If the fourth argument is undefined, sections are gathered for any status.
10625: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10626:
1.374 raeburn 10627: Returns section hash (keys are section IDs, values are
10628: number of users in each section), subject to the
1.419 raeburn 10629: optional roles filter, optional status filter
1.233 raeburn 10630:
10631: =cut
10632:
10633: ###############################################
10634: sub get_sections {
1.419 raeburn 10635: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10636: if (!defined($cdom) || !defined($cnum)) {
10637: my $cid = $env{'request.course.id'};
10638:
10639: return if (!defined($cid));
10640:
10641: $cdom = $env{'course.'.$cid.'.domain'};
10642: $cnum = $env{'course.'.$cid.'.num'};
10643: }
10644:
10645: my %sectioncount;
1.419 raeburn 10646: my $now = time;
1.240 albertel 10647:
1.1118 raeburn 10648: my $check_students = 1;
10649: my $only_students = 0;
10650: if (ref($possible_roles) eq 'ARRAY') {
10651: if (grep(/^st$/,@{$possible_roles})) {
10652: if (@{$possible_roles} == 1) {
10653: $only_students = 1;
10654: }
10655: } else {
10656: $check_students = 0;
10657: }
10658: }
10659:
10660: if ($check_students) {
1.276 albertel 10661: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10662: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10663: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10664: my $start_index = &Apache::loncoursedata::CL_START();
10665: my $end_index = &Apache::loncoursedata::CL_END();
10666: my $status;
1.366 albertel 10667: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10668: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10669: $data->[$status_index],
10670: $data->[$start_index],
10671: $data->[$end_index]);
10672: if ($stu_status eq 'Active') {
10673: $status = 'active';
10674: } elsif ($end < $now) {
10675: $status = 'previous';
10676: } elsif ($start > $now) {
10677: $status = 'future';
10678: }
10679: if ($section ne '-1' && $section !~ /^\s*$/) {
10680: if ((!defined($possible_status)) || (($status ne '') &&
10681: (grep/^\Q$status\E$/,@{$possible_status}))) {
10682: $sectioncount{$section}++;
10683: }
1.240 albertel 10684: }
10685: }
10686: }
1.1118 raeburn 10687: if ($only_students) {
10688: return %sectioncount;
10689: }
1.240 albertel 10690: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10691: foreach my $user (sort(keys(%courseroles))) {
10692: if ($user !~ /^(\w{2})/) { next; }
10693: my ($role) = ($user =~ /^(\w{2})/);
10694: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10695: my ($section,$status);
1.240 albertel 10696: if ($role eq 'cr' &&
10697: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10698: $section=$1;
10699: }
10700: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10701: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10702: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10703: if ($end == -1 && $start == -1) {
10704: next; #deleted role
10705: }
10706: if (!defined($possible_status)) {
10707: $sectioncount{$section}++;
10708: } else {
10709: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10710: $status = 'active';
10711: } elsif ($end < $now) {
10712: $status = 'future';
10713: } elsif ($start > $now) {
10714: $status = 'previous';
10715: }
10716: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10717: $sectioncount{$section}++;
10718: }
10719: }
1.233 raeburn 10720: }
1.366 albertel 10721: return %sectioncount;
1.233 raeburn 10722: }
10723:
1.274 raeburn 10724: ###############################################
1.294 raeburn 10725:
10726: =pod
1.405 albertel 10727:
10728: =item * &get_course_users()
10729:
1.275 raeburn 10730: Retrieves usernames:domains for users in the specified course
10731: with specific role(s), and access status.
10732:
10733: Incoming parameters:
1.277 albertel 10734: 1. course domain
10735: 2. course number
10736: 3. access status: users must have - either active,
1.275 raeburn 10737: previous, future, or all.
1.277 albertel 10738: 4. reference to array of permissible roles
1.288 raeburn 10739: 5. reference to array of section restrictions (optional)
10740: 6. reference to results object (hash of hashes).
10741: 7. reference to optional userdata hash
1.609 raeburn 10742: 8. reference to optional statushash
1.630 raeburn 10743: 9. flag if privileged users (except those set to unhide in
10744: course settings) should be excluded
1.609 raeburn 10745: Keys of top level results hash are roles.
1.275 raeburn 10746: Keys of inner hashes are username:domain, with
10747: values set to access type.
1.288 raeburn 10748: Optional userdata hash returns an array with arguments in the
10749: same order as loncoursedata::get_classlist() for student data.
10750:
1.609 raeburn 10751: Optional statushash returns
10752:
1.288 raeburn 10753: Entries for end, start, section and status are blank because
10754: of the possibility of multiple values for non-student roles.
10755:
1.275 raeburn 10756: =cut
1.405 albertel 10757:
1.275 raeburn 10758: ###############################################
1.405 albertel 10759:
1.275 raeburn 10760: sub get_course_users {
1.630 raeburn 10761: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10762: my %idx = ();
1.419 raeburn 10763: my %seclists;
1.288 raeburn 10764:
10765: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10766: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10767: $idx{end} = &Apache::loncoursedata::CL_END();
10768: $idx{start} = &Apache::loncoursedata::CL_START();
10769: $idx{id} = &Apache::loncoursedata::CL_ID();
10770: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10771: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10772: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10773:
1.290 albertel 10774: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10775: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10776: my $now = time;
1.277 albertel 10777: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10778: my $match = 0;
1.412 raeburn 10779: my $secmatch = 0;
1.419 raeburn 10780: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10781: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10782: if ($section eq '') {
10783: $section = 'none';
10784: }
1.291 albertel 10785: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10786: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10787: $secmatch = 1;
10788: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10789: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10790: $secmatch = 1;
10791: }
10792: } else {
1.419 raeburn 10793: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10794: $secmatch = 1;
10795: }
1.290 albertel 10796: }
1.412 raeburn 10797: if (!$secmatch) {
10798: next;
10799: }
1.419 raeburn 10800: }
1.275 raeburn 10801: if (defined($$types{'active'})) {
1.288 raeburn 10802: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10803: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10804: $match = 1;
1.275 raeburn 10805: }
10806: }
10807: if (defined($$types{'previous'})) {
1.609 raeburn 10808: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10809: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10810: $match = 1;
1.275 raeburn 10811: }
10812: }
10813: if (defined($$types{'future'})) {
1.609 raeburn 10814: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10815: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10816: $match = 1;
1.275 raeburn 10817: }
10818: }
1.609 raeburn 10819: if ($match) {
10820: push(@{$seclists{$student}},$section);
10821: if (ref($userdata) eq 'HASH') {
10822: $$userdata{$student} = $$classlist{$student};
10823: }
10824: if (ref($statushash) eq 'HASH') {
10825: $statushash->{$student}{'st'}{$section} = $status;
10826: }
1.288 raeburn 10827: }
1.275 raeburn 10828: }
10829: }
1.412 raeburn 10830: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10831: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10832: my $now = time;
1.609 raeburn 10833: my %displaystatus = ( previous => 'Expired',
10834: active => 'Active',
10835: future => 'Future',
10836: );
1.1121 raeburn 10837: my (%nothide,@possdoms);
1.630 raeburn 10838: if ($hidepriv) {
10839: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10840: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10841: if ($user !~ /:/) {
10842: $nothide{join(':',split(/[\@]/,$user))}=1;
10843: } else {
10844: $nothide{$user} = 1;
10845: }
10846: }
1.1121 raeburn 10847: my @possdoms = ($cdom);
10848: if ($coursehash{'checkforpriv'}) {
10849: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10850: }
1.630 raeburn 10851: }
1.439 raeburn 10852: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10853: my $match = 0;
1.412 raeburn 10854: my $secmatch = 0;
1.439 raeburn 10855: my $status;
1.412 raeburn 10856: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10857: $user =~ s/:$//;
1.439 raeburn 10858: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10859: if ($end == -1 || $start == -1) {
10860: next;
10861: }
10862: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10863: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10864: my ($uname,$udom) = split(/:/,$user);
10865: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10866: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10867: $secmatch = 1;
10868: } elsif ($usec eq '') {
1.420 albertel 10869: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10870: $secmatch = 1;
10871: }
10872: } else {
10873: if (grep(/^\Q$usec\E$/,@{$sections})) {
10874: $secmatch = 1;
10875: }
10876: }
10877: if (!$secmatch) {
10878: next;
10879: }
1.288 raeburn 10880: }
1.419 raeburn 10881: if ($usec eq '') {
10882: $usec = 'none';
10883: }
1.275 raeburn 10884: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10885: if ($hidepriv) {
1.1121 raeburn 10886: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10887: (!$nothide{$uname.':'.$udom})) {
10888: next;
10889: }
10890: }
1.503 raeburn 10891: if ($end > 0 && $end < $now) {
1.439 raeburn 10892: $status = 'previous';
10893: } elsif ($start > $now) {
10894: $status = 'future';
10895: } else {
10896: $status = 'active';
10897: }
1.277 albertel 10898: foreach my $type (keys(%{$types})) {
1.275 raeburn 10899: if ($status eq $type) {
1.420 albertel 10900: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10901: push(@{$$users{$role}{$user}},$type);
10902: }
1.288 raeburn 10903: $match = 1;
10904: }
10905: }
1.419 raeburn 10906: if (($match) && (ref($userdata) eq 'HASH')) {
10907: if (!exists($$userdata{$uname.':'.$udom})) {
10908: &get_user_info($udom,$uname,\%idx,$userdata);
10909: }
1.420 albertel 10910: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10911: push(@{$seclists{$uname.':'.$udom}},$usec);
10912: }
1.609 raeburn 10913: if (ref($statushash) eq 'HASH') {
10914: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10915: }
1.275 raeburn 10916: }
10917: }
10918: }
10919: }
1.290 albertel 10920: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10921: if ((defined($cdom)) && (defined($cnum))) {
10922: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10923: if ( defined($csettings{'internal.courseowner'}) ) {
10924: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10925: next if ($owner eq '');
10926: my ($ownername,$ownerdom);
10927: if ($owner =~ /^([^:]+):([^:]+)$/) {
10928: $ownername = $1;
10929: $ownerdom = $2;
10930: } else {
10931: $ownername = $owner;
10932: $ownerdom = $cdom;
10933: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10934: }
10935: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10936: if (defined($userdata) &&
1.609 raeburn 10937: !exists($$userdata{$owner})) {
10938: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10939: if (!grep(/^none$/,@{$seclists{$owner}})) {
10940: push(@{$seclists{$owner}},'none');
10941: }
10942: if (ref($statushash) eq 'HASH') {
10943: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10944: }
1.290 albertel 10945: }
1.279 raeburn 10946: }
10947: }
10948: }
1.419 raeburn 10949: foreach my $user (keys(%seclists)) {
10950: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10951: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10952: }
1.275 raeburn 10953: }
10954: return;
10955: }
10956:
1.288 raeburn 10957: sub get_user_info {
10958: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10959: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10960: &plainname($uname,$udom,'lastname');
1.291 albertel 10961: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10962: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10963: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10964: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10965: return;
10966: }
1.275 raeburn 10967:
1.472 raeburn 10968: ###############################################
10969:
10970: =pod
10971:
10972: =item * &get_user_quota()
10973:
1.1134 raeburn 10974: Retrieves quota assigned for storage of user files.
10975: Default is to report quota for portfolio files.
1.472 raeburn 10976:
10977: Incoming parameters:
10978: 1. user's username
10979: 2. user's domain
1.1134 raeburn 10980: 3. quota name - portfolio, author, or course
1.1136 raeburn 10981: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10982: 4. crstype - official, unofficial, textbook, placement or community,
10983: if quota name is course
1.472 raeburn 10984:
10985: Returns:
1.1163 raeburn 10986: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10987: 2. (Optional) Type of setting: custom or default
10988: (individually assigned or default for user's
10989: institutional status).
10990: 3. (Optional) - User's institutional status (e.g., faculty, staff
10991: or student - types as defined in localenroll::inst_usertypes
10992: for user's domain, which determines default quota for user.
10993: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10994:
10995: If a value has been stored in the user's environment,
1.536 raeburn 10996: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10997: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10998:
10999: =cut
11000:
11001: ###############################################
11002:
11003:
11004: sub get_user_quota {
1.1136 raeburn 11005: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 11006: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 11007: if (!defined($udom)) {
11008: $udom = $env{'user.domain'};
11009: }
11010: if (!defined($uname)) {
11011: $uname = $env{'user.name'};
11012: }
11013: if (($udom eq '' || $uname eq '') ||
11014: ($udom eq 'public') && ($uname eq 'public')) {
11015: $quota = 0;
1.536 raeburn 11016: $quotatype = 'default';
11017: $defquota = 0;
1.472 raeburn 11018: } else {
1.536 raeburn 11019: my $inststatus;
1.1134 raeburn 11020: if ($quotaname eq 'course') {
11021: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
11022: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
11023: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
11024: } else {
11025: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
11026: $quota = $cenv{'internal.uploadquota'};
11027: }
1.536 raeburn 11028: } else {
1.1134 raeburn 11029: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
11030: if ($quotaname eq 'author') {
11031: $quota = $env{'environment.authorquota'};
11032: } else {
11033: $quota = $env{'environment.portfolioquota'};
11034: }
11035: $inststatus = $env{'environment.inststatus'};
11036: } else {
11037: my %userenv =
11038: &Apache::lonnet::get('environment',['portfolioquota',
11039: 'authorquota','inststatus'],$udom,$uname);
11040: my ($tmp) = keys(%userenv);
11041: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11042: if ($quotaname eq 'author') {
11043: $quota = $userenv{'authorquota'};
11044: } else {
11045: $quota = $userenv{'portfolioquota'};
11046: }
11047: $inststatus = $userenv{'inststatus'};
11048: } else {
11049: undef(%userenv);
11050: }
11051: }
11052: }
11053: if ($quota eq '' || wantarray) {
11054: if ($quotaname eq 'course') {
11055: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11056: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11057: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11058: ($crstype eq 'placement')) {
1.1136 raeburn 11059: $defquota = $domdefs{$crstype.'quota'};
11060: }
11061: if ($defquota eq '') {
11062: $defquota = 500;
11063: }
1.1134 raeburn 11064: } else {
11065: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11066: }
11067: if ($quota eq '') {
11068: $quota = $defquota;
11069: $quotatype = 'default';
11070: } else {
11071: $quotatype = 'custom';
11072: }
1.472 raeburn 11073: }
11074: }
1.536 raeburn 11075: if (wantarray) {
11076: return ($quota,$quotatype,$settingstatus,$defquota);
11077: } else {
11078: return $quota;
11079: }
1.472 raeburn 11080: }
11081:
11082: ###############################################
11083:
11084: =pod
11085:
11086: =item * &default_quota()
11087:
1.536 raeburn 11088: Retrieves default quota assigned for storage of user portfolio files,
11089: given an (optional) user's institutional status.
1.472 raeburn 11090:
11091: Incoming parameters:
1.1142 raeburn 11092:
1.472 raeburn 11093: 1. domain
1.536 raeburn 11094: 2. (Optional) institutional status(es). This is a : separated list of
11095: status types (e.g., faculty, staff, student etc.)
11096: which apply to the user for whom the default is being retrieved.
11097: If the institutional status string in undefined, the domain
1.1134 raeburn 11098: default quota will be returned.
11099: 3. quota name - portfolio, author, or course
11100: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11101:
11102: Returns:
1.1142 raeburn 11103:
1.1163 raeburn 11104: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11105: 2. (Optional) institutional type which determined the value of the
11106: default quota.
1.472 raeburn 11107:
11108: If a value has been stored in the domain's configuration db,
11109: it will return that, otherwise it returns 20 (for backwards
11110: compatibility with domains which have not set up a configuration
1.1163 raeburn 11111: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11112:
1.536 raeburn 11113: If the user's status includes multiple types (e.g., staff and student),
11114: the largest default quota which applies to the user determines the
11115: default quota returned.
11116:
1.472 raeburn 11117: =cut
11118:
11119: ###############################################
11120:
11121:
11122: sub default_quota {
1.1134 raeburn 11123: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11124: my ($defquota,$settingstatus);
11125: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11126: ['quotas'],$udom);
1.1134 raeburn 11127: my $key = 'defaultquota';
11128: if ($quotaname eq 'author') {
11129: $key = 'authorquota';
11130: }
1.622 raeburn 11131: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11132: if ($inststatus ne '') {
1.765 raeburn 11133: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11134: foreach my $item (@statuses) {
1.1134 raeburn 11135: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11136: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11137: if ($defquota eq '') {
1.1134 raeburn 11138: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11139: $settingstatus = $item;
1.1134 raeburn 11140: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11141: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11142: $settingstatus = $item;
11143: }
11144: }
1.1134 raeburn 11145: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11146: if ($quotahash{'quotas'}{$item} ne '') {
11147: if ($defquota eq '') {
11148: $defquota = $quotahash{'quotas'}{$item};
11149: $settingstatus = $item;
11150: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11151: $defquota = $quotahash{'quotas'}{$item};
11152: $settingstatus = $item;
11153: }
1.536 raeburn 11154: }
11155: }
11156: }
11157: }
11158: if ($defquota eq '') {
1.1134 raeburn 11159: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11160: $defquota = $quotahash{'quotas'}{$key}{'default'};
11161: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11162: $defquota = $quotahash{'quotas'}{'default'};
11163: }
1.536 raeburn 11164: $settingstatus = 'default';
1.1139 raeburn 11165: if ($defquota eq '') {
11166: if ($quotaname eq 'author') {
11167: $defquota = 500;
11168: }
11169: }
1.536 raeburn 11170: }
11171: } else {
11172: $settingstatus = 'default';
1.1134 raeburn 11173: if ($quotaname eq 'author') {
11174: $defquota = 500;
11175: } else {
11176: $defquota = 20;
11177: }
1.536 raeburn 11178: }
11179: if (wantarray) {
11180: return ($defquota,$settingstatus);
1.472 raeburn 11181: } else {
1.536 raeburn 11182: return $defquota;
1.472 raeburn 11183: }
11184: }
11185:
1.1135 raeburn 11186: ###############################################
11187:
11188: =pod
11189:
1.1136 raeburn 11190: =item * &excess_filesize_warning()
1.1135 raeburn 11191:
11192: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11193: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11194: space to be exceeded.
1.1136 raeburn 11195:
11196: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11197: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11198:
1.1165 raeburn 11199: Inputs: 7
1.1136 raeburn 11200: 1. username or coursenum
1.1135 raeburn 11201: 2. domain
1.1136 raeburn 11202: 3. context ('author' or 'course')
1.1135 raeburn 11203: 4. filename of file for which action is being requested
11204: 5. filesize (kB) of file
11205: 6. action being taken: copy or upload.
1.1237 raeburn 11206: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11207:
11208: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11209: otherwise return null.
11210:
11211: =back
1.1135 raeburn 11212:
11213: =cut
11214:
1.1136 raeburn 11215: sub excess_filesize_warning {
1.1165 raeburn 11216: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11217: my $current_disk_usage = 0;
1.1165 raeburn 11218: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11219: if ($context eq 'author') {
11220: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11221: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11222: } else {
11223: foreach my $subdir ('docs','supplemental') {
11224: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11225: }
11226: }
1.1135 raeburn 11227: $disk_quota = int($disk_quota * 1000);
11228: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11229: return '<p class="LC_warning">'.
1.1135 raeburn 11230: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11231: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11232: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11233: $disk_quota,$current_disk_usage).
11234: '</p>';
11235: }
11236: return;
11237: }
11238:
11239: ###############################################
11240:
11241:
1.1136 raeburn 11242:
11243:
1.384 raeburn 11244: sub get_secgrprole_info {
11245: my ($cdom,$cnum,$needroles,$type) = @_;
11246: my %sections_count = &get_sections($cdom,$cnum);
11247: my @sections = (sort {$a <=> $b} keys(%sections_count));
11248: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11249: my @groups = sort(keys(%curr_groups));
11250: my $allroles = [];
11251: my $rolehash;
11252: my $accesshash = {
11253: active => 'Currently has access',
11254: future => 'Will have future access',
11255: previous => 'Previously had access',
11256: };
11257: if ($needroles) {
11258: $rolehash = {'all' => 'all'};
1.385 albertel 11259: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11260: if (&Apache::lonnet::error(%user_roles)) {
11261: undef(%user_roles);
11262: }
11263: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11264: my ($role)=split(/\:/,$item,2);
11265: if ($role eq 'cr') { next; }
11266: if ($role =~ /^cr/) {
11267: $$rolehash{$role} = (split('/',$role))[3];
11268: } else {
11269: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11270: }
11271: }
11272: foreach my $key (sort(keys(%{$rolehash}))) {
11273: push(@{$allroles},$key);
11274: }
11275: push (@{$allroles},'st');
11276: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11277: }
11278: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11279: }
11280:
1.555 raeburn 11281: sub user_picker {
1.1279 raeburn 11282: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11283: my $currdom = $dom;
1.1253 raeburn 11284: my @alldoms = &Apache::lonnet::all_domains();
11285: if (@alldoms == 1) {
11286: my %domsrch = &Apache::lonnet::get_dom('configuration',
11287: ['directorysrch'],$alldoms[0]);
11288: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11289: my $showdom = $domdesc;
11290: if ($showdom eq '') {
11291: $showdom = $dom;
11292: }
11293: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11294: if ((!$domsrch{'directorysrch'}{'available'}) &&
11295: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11296: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11297: }
11298: }
11299: }
1.555 raeburn 11300: my %curr_selected = (
11301: srchin => 'dom',
1.580 raeburn 11302: srchby => 'lastname',
1.555 raeburn 11303: );
11304: my $srchterm;
1.625 raeburn 11305: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11306: if ($srch->{'srchby'} ne '') {
11307: $curr_selected{'srchby'} = $srch->{'srchby'};
11308: }
11309: if ($srch->{'srchin'} ne '') {
11310: $curr_selected{'srchin'} = $srch->{'srchin'};
11311: }
11312: if ($srch->{'srchtype'} ne '') {
11313: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11314: }
11315: if ($srch->{'srchdomain'} ne '') {
11316: $currdom = $srch->{'srchdomain'};
11317: }
11318: $srchterm = $srch->{'srchterm'};
11319: }
1.1222 damieng 11320: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11321: 'usr' => 'Search criteria',
1.563 raeburn 11322: 'doma' => 'Domain/institution to search',
1.558 albertel 11323: 'uname' => 'username',
11324: 'lastname' => 'last name',
1.555 raeburn 11325: 'lastfirst' => 'last name, first name',
1.558 albertel 11326: 'crs' => 'in this course',
1.576 raeburn 11327: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11328: 'alc' => 'all LON-CAPA',
1.573 raeburn 11329: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11330: 'exact' => 'is',
11331: 'contains' => 'contains',
1.569 raeburn 11332: 'begins' => 'begins with',
1.1222 damieng 11333: );
11334: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11335: 'youm' => "You must include some text to search for.",
11336: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11337: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11338: 'yomc' => "You must choose a domain when using an institutional directory search.",
11339: 'ymcd' => "You must choose a domain when using a domain search.",
11340: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11341: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11342: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11343: );
1.1222 damieng 11344: &html_escape(\%html_lt);
11345: &js_escape(\%js_lt);
1.1255 raeburn 11346: my $domform;
1.1277 raeburn 11347: my $allow_blank = 1;
1.1255 raeburn 11348: if ($fixeddom) {
1.1277 raeburn 11349: $allow_blank = 0;
11350: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11351: } else {
1.1287 raeburn 11352: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11353: my ($trusted,$untrusted);
1.1287 raeburn 11354: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11355: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11356: } elsif ($context eq 'author') {
1.1288 raeburn 11357: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11358: } elsif ($context eq 'domain') {
1.1288 raeburn 11359: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11360: }
1.1288 raeburn 11361: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11362: }
1.563 raeburn 11363: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11364:
11365: my @srchins = ('crs','dom','alc','instd');
11366:
11367: foreach my $option (@srchins) {
11368: # FIXME 'alc' option unavailable until
11369: # loncreateuser::print_user_query_page()
11370: # has been completed.
11371: next if ($option eq 'alc');
1.880 raeburn 11372: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11373: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11374: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11375: if ($curr_selected{'srchin'} eq $option) {
11376: $srchinsel .= '
1.1222 damieng 11377: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11378: } else {
11379: $srchinsel .= '
1.1222 damieng 11380: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11381: }
1.555 raeburn 11382: }
1.563 raeburn 11383: $srchinsel .= "\n </select>\n";
1.555 raeburn 11384:
11385: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11386: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11387: if ($curr_selected{'srchby'} eq $option) {
11388: $srchbysel .= '
1.1222 damieng 11389: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11390: } else {
11391: $srchbysel .= '
1.1222 damieng 11392: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11393: }
11394: }
11395: $srchbysel .= "\n </select>\n";
11396:
11397: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11398: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11399: if ($curr_selected{'srchtype'} eq $option) {
11400: $srchtypesel .= '
1.1222 damieng 11401: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11402: } else {
11403: $srchtypesel .= '
1.1222 damieng 11404: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11405: }
11406: }
11407: $srchtypesel .= "\n </select>\n";
11408:
1.558 albertel 11409: my ($newuserscript,$new_user_create);
1.994 raeburn 11410: my $context_dom = $env{'request.role.domain'};
11411: if ($context eq 'requestcrs') {
11412: if ($env{'form.coursedom'} ne '') {
11413: $context_dom = $env{'form.coursedom'};
11414: }
11415: }
1.556 raeburn 11416: if ($forcenewuser) {
1.576 raeburn 11417: if (ref($srch) eq 'HASH') {
1.994 raeburn 11418: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11419: if ($cancreate) {
11420: $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>';
11421: } else {
1.799 bisitz 11422: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11423: my %usertypetext = (
11424: official => 'institutional',
11425: unofficial => 'non-institutional',
11426: );
1.799 bisitz 11427: $new_user_create = '<p class="LC_warning">'
11428: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11429: .' '
11430: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11431: ,'<a href="'.$helplink.'">','</a>')
11432: .'</p><br />';
1.627 raeburn 11433: }
1.576 raeburn 11434: }
11435: }
11436:
1.556 raeburn 11437: $newuserscript = <<"ENDSCRIPT";
11438:
1.570 raeburn 11439: function setSearch(createnew,callingForm) {
1.556 raeburn 11440: if (createnew == 1) {
1.570 raeburn 11441: for (var i=0; i<callingForm.srchby.length; i++) {
11442: if (callingForm.srchby.options[i].value == 'uname') {
11443: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11444: }
11445: }
1.570 raeburn 11446: for (var i=0; i<callingForm.srchin.length; i++) {
11447: if ( callingForm.srchin.options[i].value == 'dom') {
11448: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11449: }
11450: }
1.570 raeburn 11451: for (var i=0; i<callingForm.srchtype.length; i++) {
11452: if (callingForm.srchtype.options[i].value == 'exact') {
11453: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11454: }
11455: }
1.570 raeburn 11456: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11457: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11458: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11459: }
11460: }
11461: }
11462: }
11463: ENDSCRIPT
1.558 albertel 11464:
1.556 raeburn 11465: }
11466:
1.555 raeburn 11467: my $output = <<"END_BLOCK";
1.556 raeburn 11468: <script type="text/javascript">
1.824 bisitz 11469: // <![CDATA[
1.570 raeburn 11470: function validateEntry(callingForm) {
1.558 albertel 11471:
1.556 raeburn 11472: var checkok = 1;
1.558 albertel 11473: var srchin;
1.570 raeburn 11474: for (var i=0; i<callingForm.srchin.length; i++) {
11475: if ( callingForm.srchin[i].checked ) {
11476: srchin = callingForm.srchin[i].value;
1.558 albertel 11477: }
11478: }
11479:
1.570 raeburn 11480: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11481: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11482: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11483: var srchterm = callingForm.srchterm.value;
11484: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11485: var msg = "";
11486:
11487: if (srchterm == "") {
11488: checkok = 0;
1.1222 damieng 11489: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11490: }
11491:
1.569 raeburn 11492: if (srchtype== 'begins') {
11493: if (srchterm.length < 2) {
11494: checkok = 0;
1.1222 damieng 11495: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11496: }
11497: }
11498:
1.556 raeburn 11499: if (srchtype== 'contains') {
11500: if (srchterm.length < 3) {
11501: checkok = 0;
1.1222 damieng 11502: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11503: }
11504: }
11505: if (srchin == 'instd') {
11506: if (srchdomain == '') {
11507: checkok = 0;
1.1222 damieng 11508: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11509: }
11510: }
11511: if (srchin == 'dom') {
11512: if (srchdomain == '') {
11513: checkok = 0;
1.1222 damieng 11514: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11515: }
11516: }
11517: if (srchby == 'lastfirst') {
11518: if (srchterm.indexOf(",") == -1) {
11519: checkok = 0;
1.1222 damieng 11520: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11521: }
11522: if (srchterm.indexOf(",") == srchterm.length -1) {
11523: checkok = 0;
1.1222 damieng 11524: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11525: }
11526: }
11527: if (checkok == 0) {
1.1222 damieng 11528: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11529: return;
11530: }
11531: if (checkok == 1) {
1.570 raeburn 11532: callingForm.submit();
1.556 raeburn 11533: }
11534: }
11535:
11536: $newuserscript
11537:
1.824 bisitz 11538: // ]]>
1.556 raeburn 11539: </script>
1.558 albertel 11540:
11541: $new_user_create
11542:
1.555 raeburn 11543: END_BLOCK
1.558 albertel 11544:
1.876 raeburn 11545: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11546: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11547: $domform.
11548: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11549: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11550: $srchbysel.
11551: $srchtypesel.
11552: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11553: $srchinsel.
11554: &Apache::lonhtmlcommon::row_closure(1).
11555: &Apache::lonhtmlcommon::end_pick_box().
11556: '<br />';
1.1253 raeburn 11557: return ($output,1);
1.555 raeburn 11558: }
11559:
1.612 raeburn 11560: sub user_rule_check {
1.615 raeburn 11561: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11562: my ($response,%inst_response);
1.612 raeburn 11563: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11564: if (keys(%{$usershash}) > 1) {
11565: my (%by_username,%by_id,%userdoms);
11566: my $checkid;
11567: if (ref($checks) eq 'HASH') {
11568: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11569: $checkid = 1;
11570: }
11571: }
11572: foreach my $user (keys(%{$usershash})) {
11573: my ($uname,$udom) = split(/:/,$user);
11574: if ($checkid) {
11575: if (ref($usershash->{$user}) eq 'HASH') {
11576: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11577: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11578: $userdoms{$udom} = 1;
1.1227 raeburn 11579: if (ref($inst_results) eq 'HASH') {
11580: $inst_results->{$uname.':'.$udom} = {};
11581: }
1.1226 raeburn 11582: }
11583: }
11584: } else {
11585: $by_username{$udom}{$uname} = 1;
11586: $userdoms{$udom} = 1;
1.1227 raeburn 11587: if (ref($inst_results) eq 'HASH') {
11588: $inst_results->{$uname.':'.$udom} = {};
11589: }
1.1226 raeburn 11590: }
11591: }
11592: foreach my $udom (keys(%userdoms)) {
11593: if (!$got_rules->{$udom}) {
11594: my %domconfig = &Apache::lonnet::get_dom('configuration',
11595: ['usercreation'],$udom);
11596: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11597: foreach my $item ('username','id') {
11598: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11599: $$curr_rules{$udom}{$item} =
11600: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11601: }
11602: }
11603: }
11604: $got_rules->{$udom} = 1;
11605: }
1.612 raeburn 11606: }
1.1226 raeburn 11607: if ($checkid) {
11608: foreach my $udom (keys(%by_id)) {
11609: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11610: if ($outcome eq 'ok') {
1.1227 raeburn 11611: foreach my $id (keys(%{$by_id{$udom}})) {
11612: my $uname = $by_id{$udom}{$id};
11613: $inst_response{$uname.':'.$udom} = $outcome;
11614: }
1.1226 raeburn 11615: if (ref($results) eq 'HASH') {
11616: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11617: if (exists($inst_response{$uname.':'.$udom})) {
11618: $inst_response{$uname.':'.$udom} = $outcome;
11619: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11620: }
1.1226 raeburn 11621: }
11622: }
11623: }
1.612 raeburn 11624: }
1.615 raeburn 11625: } else {
1.1226 raeburn 11626: foreach my $udom (keys(%by_username)) {
11627: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11628: if ($outcome eq 'ok') {
1.1227 raeburn 11629: foreach my $uname (keys(%{$by_username{$udom}})) {
11630: $inst_response{$uname.':'.$udom} = $outcome;
11631: }
1.1226 raeburn 11632: if (ref($results) eq 'HASH') {
11633: foreach my $uname (keys(%{$results})) {
11634: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11635: }
11636: }
11637: }
11638: }
1.612 raeburn 11639: }
1.1226 raeburn 11640: } elsif (keys(%{$usershash}) == 1) {
11641: my $user = (keys(%{$usershash}))[0];
11642: my ($uname,$udom) = split(/:/,$user);
11643: if (($udom ne '') && ($uname ne '')) {
11644: if (ref($usershash->{$user}) eq 'HASH') {
11645: if (ref($checks) eq 'HASH') {
11646: if (defined($checks->{'username'})) {
11647: ($inst_response{$user},%{$inst_results->{$user}}) =
11648: &Apache::lonnet::get_instuser($udom,$uname);
11649: } elsif (defined($checks->{'id'})) {
11650: if ($usershash->{$user}->{'id'} ne '') {
11651: ($inst_response{$user},%{$inst_results->{$user}}) =
11652: &Apache::lonnet::get_instuser($udom,undef,
11653: $usershash->{$user}->{'id'});
11654: } else {
11655: ($inst_response{$user},%{$inst_results->{$user}}) =
11656: &Apache::lonnet::get_instuser($udom,$uname);
11657: }
1.585 raeburn 11658: }
1.1226 raeburn 11659: } else {
11660: ($inst_response{$user},%{$inst_results->{$user}}) =
11661: &Apache::lonnet::get_instuser($udom,$uname);
11662: return;
11663: }
11664: if (!$got_rules->{$udom}) {
11665: my %domconfig = &Apache::lonnet::get_dom('configuration',
11666: ['usercreation'],$udom);
11667: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11668: foreach my $item ('username','id') {
11669: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11670: $$curr_rules{$udom}{$item} =
11671: $domconfig{'usercreation'}{$item.'_rule'};
11672: }
11673: }
11674: }
11675: $got_rules->{$udom} = 1;
1.585 raeburn 11676: }
11677: }
1.1226 raeburn 11678: } else {
11679: return;
11680: }
11681: } else {
11682: return;
11683: }
11684: foreach my $user (keys(%{$usershash})) {
11685: my ($uname,$udom) = split(/:/,$user);
11686: next if (($udom eq '') || ($uname eq ''));
11687: my $id;
1.1227 raeburn 11688: if (ref($inst_results) eq 'HASH') {
11689: if (ref($inst_results->{$user}) eq 'HASH') {
11690: $id = $inst_results->{$user}->{'id'};
11691: }
11692: }
11693: if ($id eq '') {
11694: if (ref($usershash->{$user})) {
11695: $id = $usershash->{$user}->{'id'};
11696: }
1.585 raeburn 11697: }
1.612 raeburn 11698: foreach my $item (keys(%{$checks})) {
11699: if (ref($$curr_rules{$udom}) eq 'HASH') {
11700: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11701: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11702: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11703: $$curr_rules{$udom}{$item});
1.612 raeburn 11704: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11705: if ($rule_check{$rule}) {
11706: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11707: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11708: if (ref($inst_results) eq 'HASH') {
11709: if (ref($inst_results->{$user}) eq 'HASH') {
11710: if (keys(%{$inst_results->{$user}}) == 0) {
11711: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11712: } elsif ($item eq 'id') {
11713: if ($inst_results->{$user}->{'id'} eq '') {
11714: $$alerts{$item}{$udom}{$uname} = 1;
11715: }
1.615 raeburn 11716: }
1.612 raeburn 11717: }
11718: }
1.615 raeburn 11719: }
11720: last;
1.585 raeburn 11721: }
11722: }
11723: }
11724: }
11725: }
11726: }
11727: }
11728: }
1.612 raeburn 11729: return;
11730: }
11731:
11732: sub user_rule_formats {
11733: my ($domain,$domdesc,$curr_rules,$check) = @_;
11734: my %text = (
11735: 'username' => 'Usernames',
11736: 'id' => 'IDs',
11737: );
11738: my $output;
11739: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11740: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11741: if (@{$ruleorder} > 0) {
1.1102 raeburn 11742: $output = '<br />'.
11743: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11744: '<span class="LC_cusr_emph">','</span>',$domdesc).
11745: ' <ul>';
1.612 raeburn 11746: foreach my $rule (@{$ruleorder}) {
11747: if (ref($curr_rules) eq 'ARRAY') {
11748: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11749: if (ref($rules->{$rule}) eq 'HASH') {
11750: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11751: $rules->{$rule}{'desc'}.'</li>';
11752: }
11753: }
11754: }
11755: }
11756: $output .= '</ul>';
11757: }
11758: }
11759: return $output;
11760: }
11761:
11762: sub instrule_disallow_msg {
1.615 raeburn 11763: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11764: my $response;
11765: my %text = (
11766: item => 'username',
11767: items => 'usernames',
11768: match => 'matches',
11769: do => 'does',
11770: action => 'a username',
11771: one => 'one',
11772: );
11773: if ($count > 1) {
11774: $text{'item'} = 'usernames';
11775: $text{'match'} ='match';
11776: $text{'do'} = 'do';
11777: $text{'action'} = 'usernames',
11778: $text{'one'} = 'ones';
11779: }
11780: if ($checkitem eq 'id') {
11781: $text{'items'} = 'IDs';
11782: $text{'item'} = 'ID';
11783: $text{'action'} = 'an ID';
1.615 raeburn 11784: if ($count > 1) {
11785: $text{'item'} = 'IDs';
11786: $text{'action'} = 'IDs';
11787: }
1.612 raeburn 11788: }
1.674 bisitz 11789: $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 11790: if ($mode eq 'upload') {
11791: if ($checkitem eq 'username') {
11792: $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'}.");
11793: } elsif ($checkitem eq 'id') {
1.674 bisitz 11794: $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 11795: }
1.669 raeburn 11796: } elsif ($mode eq 'selfcreate') {
11797: if ($checkitem eq 'id') {
11798: $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.");
11799: }
1.615 raeburn 11800: } else {
11801: if ($checkitem eq 'username') {
11802: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11803: } elsif ($checkitem eq 'id') {
11804: $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.");
11805: }
1.612 raeburn 11806: }
11807: return $response;
1.585 raeburn 11808: }
11809:
1.624 raeburn 11810: sub personal_data_fieldtitles {
11811: my %fieldtitles = &Apache::lonlocal::texthash (
11812: id => 'Student/Employee ID',
11813: permanentemail => 'E-mail address',
11814: lastname => 'Last Name',
11815: firstname => 'First Name',
11816: middlename => 'Middle Name',
11817: generation => 'Generation',
11818: gen => 'Generation',
1.765 raeburn 11819: inststatus => 'Affiliation',
1.624 raeburn 11820: );
11821: return %fieldtitles;
11822: }
11823:
1.642 raeburn 11824: sub sorted_inst_types {
11825: my ($dom) = @_;
1.1185 raeburn 11826: my ($usertypes,$order);
11827: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11828: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11829: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11830: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11831: } else {
11832: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11833: }
1.642 raeburn 11834: my $othertitle = &mt('All users');
11835: if ($env{'request.course.id'}) {
1.668 raeburn 11836: $othertitle = &mt('Any users');
1.642 raeburn 11837: }
11838: my @types;
11839: if (ref($order) eq 'ARRAY') {
11840: @types = @{$order};
11841: }
11842: if (@types == 0) {
11843: if (ref($usertypes) eq 'HASH') {
11844: @types = sort(keys(%{$usertypes}));
11845: }
11846: }
11847: if (keys(%{$usertypes}) > 0) {
11848: $othertitle = &mt('Other users');
11849: }
11850: return ($othertitle,$usertypes,\@types);
11851: }
11852:
1.645 raeburn 11853: sub get_institutional_codes {
1.1361 raeburn 11854: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11855: # Get complete list of course sections to update
11856: my @currsections = ();
11857: my @currxlists = ();
1.1361 raeburn 11858: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11859: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11860: my $crskey = $crs.':'.$coursecode;
11861: @{$unclutteredsec{$crskey}} = ();
11862: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11863:
11864: if ($$settings{'internal.sectionnums'} ne '') {
11865: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11866: }
11867:
11868: if ($$settings{'internal.crosslistings'} ne '') {
11869: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11870: }
11871:
11872: if (@currxlists > 0) {
1.1361 raeburn 11873: foreach my $xl (@currxlists) {
11874: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11875: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11876: push(@{$allcourses},$1);
1.645 raeburn 11877: $$LC_code{$1} = $2;
11878: }
11879: }
11880: }
11881: }
1.1361 raeburn 11882:
1.645 raeburn 11883: if (@currsections > 0) {
1.1361 raeburn 11884: foreach my $sec (@currsections) {
11885: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11886: my $instsec = $1;
1.645 raeburn 11887: my $lc_sec = $2;
1.1361 raeburn 11888: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11889: push(@{$unclutteredsec{$crskey}},$instsec);
11890: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11891: }
11892: }
11893: }
11894: }
11895:
11896: if (@{$unclutteredsec{$crskey}} > 0) {
11897: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11898: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11899: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11900: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11901: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11902: push(@{$allcourses},$sec);
1.1361 raeburn 11903: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11904: }
11905: }
11906: }
11907: }
11908: return;
11909: }
11910:
1.971 raeburn 11911: sub get_standard_codeitems {
11912: return ('Year','Semester','Department','Number','Section');
11913: }
11914:
1.112 bowersj2 11915: =pod
11916:
1.780 raeburn 11917: =head1 Slot Helpers
11918:
11919: =over 4
11920:
11921: =item * sorted_slots()
11922:
1.1040 raeburn 11923: Sorts an array of slot names in order of an optional sort key,
11924: default sort is by slot start time (earliest first).
1.780 raeburn 11925:
11926: Inputs:
11927:
11928: =over 4
11929:
11930: slotsarr - Reference to array of unsorted slot names.
11931:
11932: slots - Reference to hash of hash, where outer hash keys are slot names.
11933:
1.1040 raeburn 11934: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11935:
1.549 albertel 11936: =back
11937:
1.780 raeburn 11938: Returns:
11939:
11940: =over 4
11941:
1.1040 raeburn 11942: sorted - An array of slot names sorted by a specified sort key
11943: (default sort key is start time of the slot).
1.780 raeburn 11944:
11945: =back
11946:
11947: =cut
11948:
11949:
11950: sub sorted_slots {
1.1040 raeburn 11951: my ($slotsarr,$slots,$sortkey) = @_;
11952: if ($sortkey eq '') {
11953: $sortkey = 'starttime';
11954: }
1.780 raeburn 11955: my @sorted;
11956: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11957: @sorted =
11958: sort {
11959: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11960: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11961: }
11962: if (ref($slots->{$a})) { return -1;}
11963: if (ref($slots->{$b})) { return 1;}
11964: return 0;
11965: } @{$slotsarr};
11966: }
11967: return @sorted;
11968: }
11969:
1.1040 raeburn 11970: =pod
11971:
11972: =item * get_future_slots()
11973:
11974: Inputs:
11975:
11976: =over 4
11977:
11978: cnum - course number
11979:
11980: cdom - course domain
11981:
11982: now - current UNIX time
11983:
11984: symb - optional symb
11985:
11986: =back
11987:
11988: Returns:
11989:
11990: =over 4
11991:
11992: sorted_reservable - ref to array of student_schedulable slots currently
11993: reservable, ordered by end date of reservation period.
11994:
11995: reservable_now - ref to hash of student_schedulable slots currently
11996: reservable.
11997:
11998: Keys in inner hash are:
11999: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12000: (b) endreserve: end date of reservation period.
12001: (c) uniqueperiod: start,end dates when slot is to be uniquely
12002: selected.
1.1040 raeburn 12003:
12004: sorted_future - ref to array of student_schedulable slots reservable in
12005: the future, ordered by start date of reservation period.
12006:
12007: future_reservable - ref to hash of student_schedulable slots reservable
12008: in the future.
12009:
12010: Keys in inner hash are:
12011: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12012: (b) startreserve: start date of reservation period.
12013: (c) uniqueperiod: start,end dates when slot is to be uniquely
12014: selected.
1.1040 raeburn 12015:
12016: =back
12017:
12018: =cut
12019:
12020: sub get_future_slots {
12021: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 12022: my $map;
12023: if ($symb) {
12024: ($map) = &Apache::lonnet::decode_symb($symb);
12025: }
1.1040 raeburn 12026: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
12027: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
12028: foreach my $slot (keys(%slots)) {
12029: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
12030: if ($symb) {
1.1229 raeburn 12031: if ($slots{$slot}->{'symb'} ne '') {
12032: my $canuse;
12033: my %oksymbs;
12034: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
12035: map { $oksymbs{$_} = 1; } @slotsymbs;
12036: if ($oksymbs{$symb}) {
12037: $canuse = 1;
12038: } else {
12039: foreach my $item (@slotsymbs) {
12040: if ($item =~ /\.(page|sequence)$/) {
12041: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12042: if (($map ne '') && ($map eq $sloturl)) {
12043: $canuse = 1;
12044: last;
12045: }
12046: }
12047: }
12048: }
12049: next unless ($canuse);
12050: }
1.1040 raeburn 12051: }
12052: if (($slots{$slot}->{'starttime'} > $now) &&
12053: ($slots{$slot}->{'endtime'} > $now)) {
12054: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12055: my $userallowed = 0;
12056: if ($slots{$slot}->{'allowedsections'}) {
12057: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12058: if (!defined($env{'request.role.sec'})
12059: && grep(/^No section assigned$/,@allowed_sec)) {
12060: $userallowed=1;
12061: } else {
12062: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12063: $userallowed=1;
12064: }
12065: }
12066: unless ($userallowed) {
12067: if (defined($env{'request.course.groups'})) {
12068: my @groups = split(/:/,$env{'request.course.groups'});
12069: foreach my $group (@groups) {
12070: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12071: $userallowed=1;
12072: last;
12073: }
12074: }
12075: }
12076: }
12077: }
12078: if ($slots{$slot}->{'allowedusers'}) {
12079: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12080: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12081: if (grep(/^\Q$user\E$/,@allowed_users)) {
12082: $userallowed = 1;
12083: }
12084: }
12085: next unless($userallowed);
12086: }
12087: my $startreserve = $slots{$slot}->{'startreserve'};
12088: my $endreserve = $slots{$slot}->{'endreserve'};
12089: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12090: my $uniqueperiod;
12091: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12092: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12093: }
1.1040 raeburn 12094: if (($startreserve < $now) &&
12095: (!$endreserve || $endreserve > $now)) {
12096: my $lastres = $endreserve;
12097: if (!$lastres) {
12098: $lastres = $slots{$slot}->{'starttime'};
12099: }
12100: $reservable_now{$slot} = {
12101: symb => $symb,
1.1250 raeburn 12102: endreserve => $lastres,
12103: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12104: };
12105: } elsif (($startreserve > $now) &&
12106: (!$endreserve || $endreserve > $startreserve)) {
12107: $future_reservable{$slot} = {
12108: symb => $symb,
1.1250 raeburn 12109: startreserve => $startreserve,
12110: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12111: };
12112: }
12113: }
12114: }
12115: my @unsorted_reservable = keys(%reservable_now);
12116: if (@unsorted_reservable > 0) {
12117: @sorted_reservable =
12118: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12119: }
12120: my @unsorted_future = keys(%future_reservable);
12121: if (@unsorted_future > 0) {
12122: @sorted_future =
12123: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12124: }
12125: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12126: }
1.780 raeburn 12127:
12128: =pod
12129:
1.1057 foxr 12130: =back
12131:
1.549 albertel 12132: =head1 HTTP Helpers
12133:
12134: =over 4
12135:
1.648 raeburn 12136: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12137:
1.258 albertel 12138: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12139: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12140: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12141:
12142: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12143: $possible_names is an ref to an array of form element names. As an example:
12144: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12145: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12146:
12147: =cut
1.1 albertel 12148:
1.6 albertel 12149: sub get_unprocessed_cgi {
1.25 albertel 12150: my ($query,$possible_names)= @_;
1.26 matthew 12151: # $Apache::lonxml::debug=1;
1.356 albertel 12152: foreach my $pair (split(/&/,$query)) {
12153: my ($name, $value) = split(/=/,$pair);
1.369 www 12154: $name = &unescape($name);
1.25 albertel 12155: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12156: $value =~ tr/+/ /;
12157: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12158: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12159: }
1.16 harris41 12160: }
1.6 albertel 12161: }
12162:
1.112 bowersj2 12163: =pod
12164:
1.648 raeburn 12165: =item * &cacheheader()
1.112 bowersj2 12166:
12167: returns cache-controlling header code
12168:
12169: =cut
12170:
1.7 albertel 12171: sub cacheheader {
1.258 albertel 12172: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12173: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12174: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12175: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12176: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12177: return $output;
1.7 albertel 12178: }
12179:
1.112 bowersj2 12180: =pod
12181:
1.648 raeburn 12182: =item * &no_cache($r)
1.112 bowersj2 12183:
12184: specifies header code to not have cache
12185:
12186: =cut
12187:
1.9 albertel 12188: sub no_cache {
1.216 albertel 12189: my ($r) = @_;
12190: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12191: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12192: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12193: $r->no_cache(1);
12194: $r->header_out("Expires" => $date);
12195: $r->header_out("Pragma" => "no-cache");
1.123 www 12196: }
12197:
12198: sub content_type {
1.181 albertel 12199: my ($r,$type,$charset) = @_;
1.299 foxr 12200: if ($r) {
12201: # Note that printout.pl calls this with undef for $r.
12202: &no_cache($r);
12203: }
1.258 albertel 12204: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12205: unless ($charset) {
12206: $charset=&Apache::lonlocal::current_encoding;
12207: }
12208: if ($charset) { $type.='; charset='.$charset; }
12209: if ($r) {
12210: $r->content_type($type);
12211: } else {
12212: print("Content-type: $type\n\n");
12213: }
1.9 albertel 12214: }
1.25 albertel 12215:
1.112 bowersj2 12216: =pod
12217:
1.648 raeburn 12218: =item * &add_to_env($name,$value)
1.112 bowersj2 12219:
1.258 albertel 12220: adds $name to the %env hash with value
1.112 bowersj2 12221: $value, if $name already exists, the entry is converted to an array
12222: reference and $value is added to the array.
12223:
12224: =cut
12225:
1.25 albertel 12226: sub add_to_env {
12227: my ($name,$value)=@_;
1.258 albertel 12228: if (defined($env{$name})) {
12229: if (ref($env{$name})) {
1.25 albertel 12230: #already have multiple values
1.258 albertel 12231: push(@{ $env{$name} },$value);
1.25 albertel 12232: } else {
12233: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12234: my $first=$env{$name};
12235: undef($env{$name});
12236: push(@{ $env{$name} },$first,$value);
1.25 albertel 12237: }
12238: } else {
1.258 albertel 12239: $env{$name}=$value;
1.25 albertel 12240: }
1.31 albertel 12241: }
1.149 albertel 12242:
12243: =pod
12244:
1.648 raeburn 12245: =item * &get_env_multiple($name)
1.149 albertel 12246:
1.258 albertel 12247: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12248: values may be defined and end up as an array ref.
12249:
12250: returns an array of values
12251:
12252: =cut
12253:
12254: sub get_env_multiple {
12255: my ($name) = @_;
12256: my @values;
1.258 albertel 12257: if (defined($env{$name})) {
1.149 albertel 12258: # exists is it an array
1.258 albertel 12259: if (ref($env{$name})) {
12260: @values=@{ $env{$name} };
1.149 albertel 12261: } else {
1.258 albertel 12262: $values[0]=$env{$name};
1.149 albertel 12263: }
12264: }
12265: return(@values);
12266: }
12267:
1.1249 damieng 12268: # Looks at given dependencies, and returns something depending on the context.
12269: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12270: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12271: # For all other contexts, returns ($output, $counter, $numpathchg).
12272: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12273: # $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.
12274: # $numpathchg: integer with the number of cleaned up dependency paths.
12275: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12276: # \%mapping: hash reference clean path -> original path for all dependencies.
12277: # @param {string} actionurl - The path to the handler, indicative of the context.
12278: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12279: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12280: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12281: # @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)
12282: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12283: sub ask_for_embedded_content {
1.1249 damieng 12284: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12285: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12286: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12287: %currsubfile,%unused,$rem);
1.1071 raeburn 12288: my $counter = 0;
12289: my $numnew = 0;
1.987 raeburn 12290: my $numremref = 0;
12291: my $numinvalid = 0;
12292: my $numpathchg = 0;
12293: my $numexisting = 0;
1.1071 raeburn 12294: my $numunused = 0;
12295: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12296: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12297: my $heading = &mt('Upload embedded files');
12298: my $buttontext = &mt('Upload');
12299:
1.1249 damieng 12300: # fills these variables based on the context:
12301: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12302: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12303: if ($env{'request.course.id'}) {
1.1123 raeburn 12304: if ($actionurl eq '/adm/dependencies') {
12305: $navmap = Apache::lonnavmaps::navmap->new();
12306: }
12307: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12308: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12309: }
1.1123 raeburn 12310: if (($actionurl eq '/adm/portfolio') ||
12311: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12312: my $current_path='/';
12313: if ($env{'form.currentpath'}) {
12314: $current_path = $env{'form.currentpath'};
12315: }
12316: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12317: $udom = $cdom;
12318: $uname = $cnum;
1.984 raeburn 12319: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12320: } else {
12321: $udom = $env{'user.domain'};
12322: $uname = $env{'user.name'};
12323: $url = '/userfiles/portfolio';
12324: }
1.987 raeburn 12325: $toplevel = $url.'/';
1.984 raeburn 12326: $url .= $current_path;
12327: $getpropath = 1;
1.987 raeburn 12328: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12329: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12330: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12331: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12332: $toplevel = $url;
1.984 raeburn 12333: if ($rest ne '') {
1.987 raeburn 12334: $url .= $rest;
12335: }
12336: } elsif ($actionurl eq '/adm/coursedocs') {
12337: if (ref($args) eq 'HASH') {
1.1071 raeburn 12338: $url = $args->{'docs_url'};
12339: $toplevel = $url;
1.1084 raeburn 12340: if ($args->{'context'} eq 'paste') {
12341: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12342: ($path) =
12343: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12344: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12345: $fileloc =~ s{^/}{};
12346: }
1.1071 raeburn 12347: }
1.1084 raeburn 12348: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12349: if ($env{'request.course.id'} ne '') {
12350: if (ref($args) eq 'HASH') {
12351: $url = $args->{'docs_url'};
12352: $title = $args->{'docs_title'};
1.1126 raeburn 12353: $toplevel = $url;
12354: unless ($toplevel =~ m{^/}) {
12355: $toplevel = "/$url";
12356: }
1.1085 raeburn 12357: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12358: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12359: $path = $1;
12360: } else {
12361: ($path) =
12362: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12363: }
1.1195 raeburn 12364: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12365: $fileloc = $toplevel;
12366: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12367: my ($udom,$uname,$fname) =
12368: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12369: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12370: } else {
12371: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12372: }
1.1071 raeburn 12373: $fileloc =~ s{^/}{};
12374: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12375: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12376: }
1.987 raeburn 12377: }
1.1123 raeburn 12378: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12379: $udom = $cdom;
12380: $uname = $cnum;
12381: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12382: $toplevel = $url;
12383: $path = $url;
12384: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12385: $fileloc =~ s{^/}{};
1.987 raeburn 12386: }
1.1249 damieng 12387:
12388: # parses the dependency paths to get some info
12389: # fills $newfiles, $mapping, $subdependencies, $dependencies
12390: # $newfiles: hash URL -> 1 for new files or external URLs
12391: # (will be completed later)
12392: # $mapping:
12393: # for external URLs: external URL -> external URL
12394: # for relative paths: clean path -> original path
12395: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12396: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12397: foreach my $file (keys(%{$allfiles})) {
12398: my $embed_file;
12399: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12400: $embed_file = $1;
12401: } else {
12402: $embed_file = $file;
12403: }
1.1158 raeburn 12404: my ($absolutepath,$cleaned_file);
12405: if ($embed_file =~ m{^\w+://}) {
12406: $cleaned_file = $embed_file;
1.1147 raeburn 12407: $newfiles{$cleaned_file} = 1;
12408: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12409: } else {
1.1158 raeburn 12410: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12411: if ($embed_file =~ m{^/}) {
12412: $absolutepath = $embed_file;
12413: }
1.1147 raeburn 12414: if ($cleaned_file =~ m{/}) {
12415: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12416: $path = &check_for_traversal($path,$url,$toplevel);
12417: my $item = $fname;
12418: if ($path ne '') {
12419: $item = $path.'/'.$fname;
12420: $subdependencies{$path}{$fname} = 1;
12421: } else {
12422: $dependencies{$item} = 1;
12423: }
12424: if ($absolutepath) {
12425: $mapping{$item} = $absolutepath;
12426: } else {
12427: $mapping{$item} = $embed_file;
12428: }
12429: } else {
12430: $dependencies{$embed_file} = 1;
12431: if ($absolutepath) {
1.1147 raeburn 12432: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12433: } else {
1.1147 raeburn 12434: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12435: }
12436: }
1.984 raeburn 12437: }
12438: }
1.1249 damieng 12439:
12440: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12441: # and lists
12442: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12443: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12444: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12445: # the path had to be cleaned up
12446: # $existing: hash clean path -> 1 if the file exists
12447: # $numexisting: number of keys in $existing
12448: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12449: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12450: # dependency subdirectories that are
12451: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12452: my $dirptr = 16384;
1.984 raeburn 12453: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12454: $currsubfile{$path} = {};
1.1123 raeburn 12455: if (($actionurl eq '/adm/portfolio') ||
12456: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12457: my ($sublistref,$listerror) =
12458: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12459: if (ref($sublistref) eq 'ARRAY') {
12460: foreach my $line (@{$sublistref}) {
12461: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12462: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12463: }
1.984 raeburn 12464: }
1.987 raeburn 12465: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12466: if (opendir(my $dir,$url.'/'.$path)) {
12467: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12468: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12469: }
1.1084 raeburn 12470: } elsif (($actionurl eq '/adm/dependencies') ||
12471: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12472: ($args->{'context'} eq 'paste')) ||
12473: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12474: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12475: my $dir;
12476: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12477: $dir = $fileloc;
12478: } else {
12479: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12480: }
1.1071 raeburn 12481: if ($dir ne '') {
12482: my ($sublistref,$listerror) =
12483: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12484: if (ref($sublistref) eq 'ARRAY') {
12485: foreach my $line (@{$sublistref}) {
12486: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12487: undef,$mtime)=split(/\&/,$line,12);
12488: unless (($testdir&$dirptr) ||
12489: ($file_name =~ /^\.\.?$/)) {
12490: $currsubfile{$path}{$file_name} = [$size,$mtime];
12491: }
12492: }
12493: }
12494: }
1.984 raeburn 12495: }
12496: }
12497: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12498: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12499: my $item = $path.'/'.$file;
12500: unless ($mapping{$item} eq $item) {
12501: $pathchanges{$item} = 1;
12502: }
12503: $existing{$item} = 1;
12504: $numexisting ++;
12505: } else {
12506: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12507: }
12508: }
1.1071 raeburn 12509: if ($actionurl eq '/adm/dependencies') {
12510: foreach my $path (keys(%currsubfile)) {
12511: if (ref($currsubfile{$path}) eq 'HASH') {
12512: foreach my $file (keys(%{$currsubfile{$path}})) {
12513: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12514: next if (($rem ne '') &&
12515: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12516: (ref($navmap) &&
12517: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12518: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12519: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12520: $unused{$path.'/'.$file} = 1;
12521: }
12522: }
12523: }
12524: }
12525: }
1.984 raeburn 12526: }
1.1249 damieng 12527:
12528: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12529: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12530: my %currfile;
1.1123 raeburn 12531: if (($actionurl eq '/adm/portfolio') ||
12532: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12533: my ($dirlistref,$listerror) =
12534: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12535: if (ref($dirlistref) eq 'ARRAY') {
12536: foreach my $line (@{$dirlistref}) {
12537: my ($file_name,$rest) = split(/\&/,$line,2);
12538: $currfile{$file_name} = 1;
12539: }
1.984 raeburn 12540: }
1.987 raeburn 12541: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12542: if (opendir(my $dir,$url)) {
1.987 raeburn 12543: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12544: map {$currfile{$_} = 1;} @dir_list;
12545: }
1.1084 raeburn 12546: } elsif (($actionurl eq '/adm/dependencies') ||
12547: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12548: ($args->{'context'} eq 'paste')) ||
12549: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12550: if ($env{'request.course.id'} ne '') {
12551: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12552: if ($dir ne '') {
12553: my ($dirlistref,$listerror) =
12554: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12555: if (ref($dirlistref) eq 'ARRAY') {
12556: foreach my $line (@{$dirlistref}) {
12557: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12558: $size,undef,$mtime)=split(/\&/,$line,12);
12559: unless (($testdir&$dirptr) ||
12560: ($file_name =~ /^\.\.?$/)) {
12561: $currfile{$file_name} = [$size,$mtime];
12562: }
12563: }
12564: }
12565: }
12566: }
1.984 raeburn 12567: }
1.1249 damieng 12568: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12569: # are not in subdirectories, using $currfile
1.984 raeburn 12570: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12571: if (exists($currfile{$file})) {
1.987 raeburn 12572: unless ($mapping{$file} eq $file) {
12573: $pathchanges{$file} = 1;
12574: }
12575: $existing{$file} = 1;
12576: $numexisting ++;
12577: } else {
1.984 raeburn 12578: $newfiles{$file} = 1;
12579: }
12580: }
1.1071 raeburn 12581: foreach my $file (keys(%currfile)) {
12582: unless (($file eq $filename) ||
12583: ($file eq $filename.'.bak') ||
12584: ($dependencies{$file})) {
1.1085 raeburn 12585: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12586: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12587: next if (($rem ne '') &&
12588: (($env{"httpref.$rem".$file} ne '') ||
12589: (ref($navmap) &&
12590: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12591: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12592: ($navmap->getResourceByUrl($rem.$1)))))));
12593: }
1.1085 raeburn 12594: }
1.1071 raeburn 12595: $unused{$file} = 1;
12596: }
12597: }
1.1249 damieng 12598:
12599: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12600: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12601: ($args->{'context'} eq 'paste')) {
12602: $counter = scalar(keys(%existing));
12603: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12604: return ($output,$counter,$numpathchg,\%existing);
12605: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12606: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12607: $counter = scalar(keys(%existing));
12608: $numpathchg = scalar(keys(%pathchanges));
12609: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12610: }
1.1249 damieng 12611:
12612: # returns HTML otherwise, with dependency results and to ask for more uploads
12613:
12614: # $upload_output: missing dependencies (with upload form)
12615: # $modify_output: uploaded dependencies (in use)
12616: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12617: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12618: if ($actionurl eq '/adm/dependencies') {
12619: next if ($embed_file =~ m{^\w+://});
12620: }
1.660 raeburn 12621: $upload_output .= &start_data_table_row().
1.1123 raeburn 12622: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12623: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12624: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12625: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12626: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12627: }
1.1123 raeburn 12628: $upload_output .= '</td>';
1.1071 raeburn 12629: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12630: $upload_output.='<td align="right">'.
12631: '<span class="LC_info LC_fontsize_medium">'.
12632: &mt("URL points to web address").'</span>';
1.987 raeburn 12633: $numremref++;
1.660 raeburn 12634: } elsif ($args->{'error_on_invalid_names'}
12635: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12636: $upload_output.='<td align="right"><span class="LC_warning">'.
12637: &mt('Invalid characters').'</span>';
1.987 raeburn 12638: $numinvalid++;
1.660 raeburn 12639: } else {
1.1123 raeburn 12640: $upload_output .= '<td>'.
12641: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12642: $embed_file,\%mapping,
1.1071 raeburn 12643: $allfiles,$codebase,'upload');
12644: $counter ++;
12645: $numnew ++;
1.987 raeburn 12646: }
12647: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12648: }
12649: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12650: if ($actionurl eq '/adm/dependencies') {
12651: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12652: $modify_output .= &start_data_table_row().
12653: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12654: '<img src="'.&icon($embed_file).'" border="0" />'.
12655: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12656: '<td>'.$size.'</td>'.
12657: '<td>'.$mtime.'</td>'.
12658: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12659: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12660: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12661: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12662: &embedded_file_element('upload_embedded',$counter,
12663: $embed_file,\%mapping,
12664: $allfiles,$codebase,'modify').
12665: '</div></td>'.
12666: &end_data_table_row()."\n";
12667: $counter ++;
12668: } else {
12669: $upload_output .= &start_data_table_row().
1.1123 raeburn 12670: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12671: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12672: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12673: &Apache::loncommon::end_data_table_row()."\n";
12674: }
12675: }
12676: my $delidx = $counter;
12677: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12678: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12679: $delete_output .= &start_data_table_row().
12680: '<td><img src="'.&icon($oldfile).'" />'.
12681: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12682: '<td>'.$size.'</td>'.
12683: '<td>'.$mtime.'</td>'.
12684: '<td><label><input type="checkbox" name="del_upload_dep" '.
12685: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12686: &embedded_file_element('upload_embedded',$delidx,
12687: $oldfile,\%mapping,$allfiles,
12688: $codebase,'delete').'</td>'.
12689: &end_data_table_row()."\n";
12690: $numunused ++;
12691: $delidx ++;
1.987 raeburn 12692: }
12693: if ($upload_output) {
12694: $upload_output = &start_data_table().
12695: $upload_output.
12696: &end_data_table()."\n";
12697: }
1.1071 raeburn 12698: if ($modify_output) {
12699: $modify_output = &start_data_table().
12700: &start_data_table_header_row().
12701: '<th>'.&mt('File').'</th>'.
12702: '<th>'.&mt('Size (KB)').'</th>'.
12703: '<th>'.&mt('Modified').'</th>'.
12704: '<th>'.&mt('Upload replacement?').'</th>'.
12705: &end_data_table_header_row().
12706: $modify_output.
12707: &end_data_table()."\n";
12708: }
12709: if ($delete_output) {
12710: $delete_output = &start_data_table().
12711: &start_data_table_header_row().
12712: '<th>'.&mt('File').'</th>'.
12713: '<th>'.&mt('Size (KB)').'</th>'.
12714: '<th>'.&mt('Modified').'</th>'.
12715: '<th>'.&mt('Delete?').'</th>'.
12716: &end_data_table_header_row().
12717: $delete_output.
12718: &end_data_table()."\n";
12719: }
1.987 raeburn 12720: my $applies = 0;
12721: if ($numremref) {
12722: $applies ++;
12723: }
12724: if ($numinvalid) {
12725: $applies ++;
12726: }
12727: if ($numexisting) {
12728: $applies ++;
12729: }
1.1071 raeburn 12730: if ($counter || $numunused) {
1.987 raeburn 12731: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12732: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12733: $state.'<h3>'.$heading.'</h3>';
12734: if ($actionurl eq '/adm/dependencies') {
12735: if ($numnew) {
12736: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12737: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12738: $upload_output.'<br />'."\n";
12739: }
12740: if ($numexisting) {
12741: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12742: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12743: $modify_output.'<br />'."\n";
12744: $buttontext = &mt('Save changes');
12745: }
12746: if ($numunused) {
12747: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12748: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12749: $delete_output.'<br />'."\n";
12750: $buttontext = &mt('Save changes');
12751: }
12752: } else {
12753: $output .= $upload_output.'<br />'."\n";
12754: }
12755: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12756: $counter.'" />'."\n";
12757: if ($actionurl eq '/adm/dependencies') {
12758: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12759: $numnew.'" />'."\n";
12760: } elsif ($actionurl eq '') {
1.987 raeburn 12761: $output .= '<input type="hidden" name="phase" value="three" />';
12762: }
12763: } elsif ($applies) {
12764: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12765: if ($applies > 1) {
12766: $output .=
1.1123 raeburn 12767: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12768: if ($numremref) {
12769: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12770: }
12771: if ($numinvalid) {
12772: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12773: }
12774: if ($numexisting) {
12775: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12776: }
12777: $output .= '</ul><br />';
12778: } elsif ($numremref) {
12779: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12780: } elsif ($numinvalid) {
12781: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12782: } elsif ($numexisting) {
12783: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12784: }
12785: $output .= $upload_output.'<br />';
12786: }
12787: my ($pathchange_output,$chgcount);
1.1071 raeburn 12788: $chgcount = $counter;
1.987 raeburn 12789: if (keys(%pathchanges) > 0) {
12790: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12791: if ($counter) {
1.987 raeburn 12792: $output .= &embedded_file_element('pathchange',$chgcount,
12793: $embed_file,\%mapping,
1.1071 raeburn 12794: $allfiles,$codebase,'change');
1.987 raeburn 12795: } else {
12796: $pathchange_output .=
12797: &start_data_table_row().
12798: '<td><input type ="checkbox" name="namechange" value="'.
12799: $chgcount.'" checked="checked" /></td>'.
12800: '<td>'.$mapping{$embed_file}.'</td>'.
12801: '<td>'.$embed_file.
12802: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12803: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12804: '</td>'.&end_data_table_row();
1.660 raeburn 12805: }
1.987 raeburn 12806: $numpathchg ++;
12807: $chgcount ++;
1.660 raeburn 12808: }
12809: }
1.1127 raeburn 12810: if (($counter) || ($numunused)) {
1.987 raeburn 12811: if ($numpathchg) {
12812: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12813: $numpathchg.'" />'."\n";
12814: }
12815: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12816: ($actionurl eq '/adm/imsimport')) {
12817: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12818: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12819: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12820: } elsif ($actionurl eq '/adm/dependencies') {
12821: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12822: }
1.1123 raeburn 12823: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12824: } elsif ($numpathchg) {
12825: my %pathchange = ();
12826: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12827: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12828: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12829: }
1.987 raeburn 12830: }
1.1071 raeburn 12831: return ($output,$counter,$numpathchg);
1.987 raeburn 12832: }
12833:
1.1147 raeburn 12834: =pod
12835:
12836: =item * clean_path($name)
12837:
12838: Performs clean-up of directories, subdirectories and filename in an
12839: embedded object, referenced in an HTML file which is being uploaded
12840: to a course or portfolio, where
12841: "Upload embedded images/multimedia files if HTML file" checkbox was
12842: checked.
12843:
12844: Clean-up is similar to replacements in lonnet::clean_filename()
12845: except each / between sub-directory and next level is preserved.
12846:
12847: =cut
12848:
12849: sub clean_path {
12850: my ($embed_file) = @_;
12851: $embed_file =~s{^/+}{};
12852: my @contents;
12853: if ($embed_file =~ m{/}) {
12854: @contents = split(/\//,$embed_file);
12855: } else {
12856: @contents = ($embed_file);
12857: }
12858: my $lastidx = scalar(@contents)-1;
12859: for (my $i=0; $i<=$lastidx; $i++) {
12860: $contents[$i]=~s{\\}{/}g;
12861: $contents[$i]=~s/\s+/\_/g;
12862: $contents[$i]=~s{[^/\w\.\-]}{}g;
12863: if ($i == $lastidx) {
12864: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12865: }
12866: }
12867: if ($lastidx > 0) {
12868: return join('/',@contents);
12869: } else {
12870: return $contents[0];
12871: }
12872: }
12873:
1.987 raeburn 12874: sub embedded_file_element {
1.1071 raeburn 12875: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12876: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12877: (ref($codebase) eq 'HASH'));
12878: my $output;
1.1071 raeburn 12879: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12880: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12881: }
12882: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12883: &escape($embed_file).'" />';
12884: unless (($context eq 'upload_embedded') &&
12885: ($mapping->{$embed_file} eq $embed_file)) {
12886: $output .='
12887: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12888: }
12889: my $attrib;
12890: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12891: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12892: }
12893: $output .=
12894: "\n\t\t".
12895: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12896: $attrib.'" />';
12897: if (exists($codebase->{$mapping->{$embed_file}})) {
12898: $output .=
12899: "\n\t\t".
12900: '<input name="codebase_'.$num.'" type="hidden" value="'.
12901: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12902: }
1.987 raeburn 12903: return $output;
1.660 raeburn 12904: }
12905:
1.1071 raeburn 12906: sub get_dependency_details {
12907: my ($currfile,$currsubfile,$embed_file) = @_;
12908: my ($size,$mtime,$showsize,$showmtime);
12909: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12910: if ($embed_file =~ m{/}) {
12911: my ($path,$fname) = split(/\//,$embed_file);
12912: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12913: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12914: }
12915: } else {
12916: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12917: ($size,$mtime) = @{$currfile->{$embed_file}};
12918: }
12919: }
12920: $showsize = $size/1024.0;
12921: $showsize = sprintf("%.1f",$showsize);
12922: if ($mtime > 0) {
12923: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12924: }
12925: }
12926: return ($showsize,$showmtime);
12927: }
12928:
12929: sub ask_embedded_js {
12930: return <<"END";
12931: <script type="text/javascript"">
12932: // <![CDATA[
12933: function toggleBrowse(counter) {
12934: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12935: var fileid = document.getElementById('embedded_item_'+counter);
12936: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12937: if (chkboxid.checked == true) {
12938: uploaddivid.style.display='block';
12939: } else {
12940: uploaddivid.style.display='none';
12941: fileid.value = '';
12942: }
12943: }
12944: // ]]>
12945: </script>
12946:
12947: END
12948: }
12949:
1.661 raeburn 12950: sub upload_embedded {
12951: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12952: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12953: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12954: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12955: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12956: my $orig_uploaded_filename =
12957: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12958: foreach my $type ('orig','ref','attrib','codebase') {
12959: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12960: $env{'form.embedded_'.$type.'_'.$i} =
12961: &unescape($env{'form.embedded_'.$type.'_'.$i});
12962: }
12963: }
1.661 raeburn 12964: my ($path,$fname) =
12965: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12966: # no path, whole string is fname
12967: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12968: $fname = &Apache::lonnet::clean_filename($fname);
12969: # See if there is anything left
12970: next if ($fname eq '');
12971:
12972: # Check if file already exists as a file or directory.
12973: my ($state,$msg);
12974: if ($context eq 'portfolio') {
12975: my $port_path = $dirpath;
12976: if ($group ne '') {
12977: $port_path = "groups/$group/$port_path";
12978: }
1.987 raeburn 12979: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12980: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12981: $dir_root,$port_path,$disk_quota,
12982: $current_disk_usage,$uname,$udom);
12983: if ($state eq 'will_exceed_quota'
1.984 raeburn 12984: || $state eq 'file_locked') {
1.661 raeburn 12985: $output .= $msg;
12986: next;
12987: }
12988: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12989: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12990: if ($state eq 'exists') {
12991: $output .= $msg;
12992: next;
12993: }
12994: }
12995: # Check if extension is valid
12996: if (($fname =~ /\.(\w+)$/) &&
12997: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12998: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12999: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 13000: next;
13001: } elsif (($fname =~ /\.(\w+)$/) &&
13002: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 13003: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 13004: next;
13005: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 13006: $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 13007: next;
13008: }
13009: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 13010: my $subdir = $path;
13011: $subdir =~ s{/+$}{};
1.661 raeburn 13012: if ($context eq 'portfolio') {
1.984 raeburn 13013: my $result;
13014: if ($state eq 'existingfile') {
13015: $result=
13016: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 13017: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 13018: } else {
1.984 raeburn 13019: $result=
13020: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 13021: $dirpath.
1.1123 raeburn 13022: $env{'form.currentpath'}.$subdir);
1.984 raeburn 13023: if ($result !~ m|^/uploaded/|) {
13024: $output .= '<span class="LC_error">'
13025: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13026: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13027: .'</span><br />';
13028: next;
13029: } else {
1.987 raeburn 13030: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13031: $path.$fname.'</span>').'<br />';
1.984 raeburn 13032: }
1.661 raeburn 13033: }
1.1123 raeburn 13034: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 13035: my $extendedsubdir = $dirpath.'/'.$subdir;
13036: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 13037: my $result =
1.1126 raeburn 13038: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13039: if ($result !~ m|^/uploaded/|) {
13040: $output .= '<span class="LC_error">'
13041: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13042: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13043: .'</span><br />';
13044: next;
13045: } else {
13046: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13047: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13048: if ($context eq 'syllabus') {
13049: &Apache::lonnet::make_public_indefinitely($result);
13050: }
1.987 raeburn 13051: }
1.661 raeburn 13052: } else {
13053: # Save the file
13054: my $target = $env{'form.embedded_item_'.$i};
13055: my $fullpath = $dir_root.$dirpath.'/'.$path;
13056: my $dest = $fullpath.$fname;
13057: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13058: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13059: my $count;
13060: my $filepath = $dir_root;
1.1027 raeburn 13061: foreach my $subdir (@parts) {
13062: $filepath .= "/$subdir";
13063: if (!-e $filepath) {
1.661 raeburn 13064: mkdir($filepath,0770);
13065: }
13066: }
13067: my $fh;
13068: if (!open($fh,'>'.$dest)) {
13069: &Apache::lonnet::logthis('Failed to create '.$dest);
13070: $output .= '<span class="LC_error">'.
1.1071 raeburn 13071: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13072: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13073: '</span><br />';
13074: } else {
13075: if (!print $fh $env{'form.embedded_item_'.$i}) {
13076: &Apache::lonnet::logthis('Failed to write to '.$dest);
13077: $output .= '<span class="LC_error">'.
1.1071 raeburn 13078: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13079: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13080: '</span><br />';
13081: } else {
1.987 raeburn 13082: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13083: $url.'</span>').'<br />';
13084: unless ($context eq 'testbank') {
13085: $footer .= &mt('View embedded file: [_1]',
13086: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13087: }
13088: }
13089: close($fh);
13090: }
13091: }
13092: if ($env{'form.embedded_ref_'.$i}) {
13093: $pathchange{$i} = 1;
13094: }
13095: }
13096: if ($output) {
13097: $output = '<p>'.$output.'</p>';
13098: }
13099: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13100: $returnflag = 'ok';
1.1071 raeburn 13101: my $numpathchgs = scalar(keys(%pathchange));
13102: if ($numpathchgs > 0) {
1.987 raeburn 13103: if ($context eq 'portfolio') {
13104: $output .= '<p>'.&mt('or').'</p>';
13105: } elsif ($context eq 'testbank') {
1.1071 raeburn 13106: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13107: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13108: $returnflag = 'modify_orightml';
13109: }
13110: }
1.1071 raeburn 13111: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13112: }
13113:
13114: sub modify_html_form {
13115: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13116: my $end = 0;
13117: my $modifyform;
13118: if ($context eq 'upload_embedded') {
13119: return unless (ref($pathchange) eq 'HASH');
13120: if ($env{'form.number_embedded_items'}) {
13121: $end += $env{'form.number_embedded_items'};
13122: }
13123: if ($env{'form.number_pathchange_items'}) {
13124: $end += $env{'form.number_pathchange_items'};
13125: }
13126: if ($end) {
13127: for (my $i=0; $i<$end; $i++) {
13128: if ($i < $env{'form.number_embedded_items'}) {
13129: next unless($pathchange->{$i});
13130: }
13131: $modifyform .=
13132: &start_data_table_row().
13133: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13134: 'checked="checked" /></td>'.
13135: '<td>'.$env{'form.embedded_ref_'.$i}.
13136: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13137: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13138: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13139: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13140: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13141: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13142: '<td>'.$env{'form.embedded_orig_'.$i}.
13143: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13144: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13145: &end_data_table_row();
1.1071 raeburn 13146: }
1.987 raeburn 13147: }
13148: } else {
13149: $modifyform = $pathchgtable;
13150: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13151: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13152: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13153: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13154: }
13155: }
13156: if ($modifyform) {
1.1071 raeburn 13157: if ($actionurl eq '/adm/dependencies') {
13158: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13159: }
1.987 raeburn 13160: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13161: '<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".
13162: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13163: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13164: '</ol></p>'."\n".'<p>'.
13165: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13166: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13167: &start_data_table()."\n".
13168: &start_data_table_header_row().
13169: '<th>'.&mt('Change?').'</th>'.
13170: '<th>'.&mt('Current reference').'</th>'.
13171: '<th>'.&mt('Required reference').'</th>'.
13172: &end_data_table_header_row()."\n".
13173: $modifyform.
13174: &end_data_table().'<br />'."\n".$hiddenstate.
13175: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13176: '</form>'."\n";
13177: }
13178: return;
13179: }
13180:
13181: sub modify_html_refs {
1.1123 raeburn 13182: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13183: my $container;
13184: if ($context eq 'portfolio') {
13185: $container = $env{'form.container'};
13186: } elsif ($context eq 'coursedoc') {
13187: $container = $env{'form.primaryurl'};
1.1071 raeburn 13188: } elsif ($context eq 'manage_dependencies') {
13189: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13190: $container = "/$container";
1.1123 raeburn 13191: } elsif ($context eq 'syllabus') {
13192: $container = $url;
1.987 raeburn 13193: } else {
1.1027 raeburn 13194: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13195: }
13196: my (%allfiles,%codebase,$output,$content);
13197: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13198: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13199: if (wantarray) {
13200: return ('',0,0);
13201: } else {
13202: return;
13203: }
13204: }
13205: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13206: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13207: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13208: if (wantarray) {
13209: return ('',0,0);
13210: } else {
13211: return;
13212: }
13213: }
1.987 raeburn 13214: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13215: if ($content eq '-1') {
13216: if (wantarray) {
13217: return ('',0,0);
13218: } else {
13219: return;
13220: }
13221: }
1.987 raeburn 13222: } else {
1.1071 raeburn 13223: unless ($container =~ /^\Q$dir_root\E/) {
13224: if (wantarray) {
13225: return ('',0,0);
13226: } else {
13227: return;
13228: }
13229: }
1.1317 raeburn 13230: if (open(my $fh,'<',$container)) {
1.987 raeburn 13231: $content = join('', <$fh>);
13232: close($fh);
13233: } else {
1.1071 raeburn 13234: if (wantarray) {
13235: return ('',0,0);
13236: } else {
13237: return;
13238: }
1.987 raeburn 13239: }
13240: }
13241: my ($count,$codebasecount) = (0,0);
13242: my $mm = new File::MMagic;
13243: my $mime_type = $mm->checktype_contents($content);
13244: if ($mime_type eq 'text/html') {
13245: my $parse_result =
13246: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13247: \%codebase,\$content);
13248: if ($parse_result eq 'ok') {
13249: foreach my $i (@changes) {
13250: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13251: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13252: if ($allfiles{$ref}) {
13253: my $newname = $orig;
13254: my ($attrib_regexp,$codebase);
1.1006 raeburn 13255: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13256: if ($attrib_regexp =~ /:/) {
13257: $attrib_regexp =~ s/\:/|/g;
13258: }
13259: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13260: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13261: $count += $numchg;
1.1123 raeburn 13262: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13263: delete($allfiles{$ref});
1.987 raeburn 13264: }
13265: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13266: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13267: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13268: $codebasecount ++;
13269: }
13270: }
13271: }
1.1123 raeburn 13272: my $skiprewrites;
1.987 raeburn 13273: if ($count || $codebasecount) {
13274: my $saveresult;
1.1071 raeburn 13275: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13276: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13277: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13278: if ($url eq $container) {
13279: my ($fname) = ($container =~ m{/([^/]+)$});
13280: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13281: $count,'<span class="LC_filename">'.
1.1071 raeburn 13282: $fname.'</span>').'</p>';
1.987 raeburn 13283: } else {
13284: $output = '<p class="LC_error">'.
13285: &mt('Error: update failed for: [_1].',
13286: '<span class="LC_filename">'.
13287: $container.'</span>').'</p>';
13288: }
1.1123 raeburn 13289: if ($context eq 'syllabus') {
13290: unless ($saveresult eq 'ok') {
13291: $skiprewrites = 1;
13292: }
13293: }
1.987 raeburn 13294: } else {
1.1317 raeburn 13295: if (open(my $fh,'>',$container)) {
1.987 raeburn 13296: print $fh $content;
13297: close($fh);
13298: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13299: $count,'<span class="LC_filename">'.
13300: $container.'</span>').'</p>';
1.661 raeburn 13301: } else {
1.987 raeburn 13302: $output = '<p class="LC_error">'.
13303: &mt('Error: could not update [_1].',
13304: '<span class="LC_filename">'.
13305: $container.'</span>').'</p>';
1.661 raeburn 13306: }
13307: }
13308: }
1.1123 raeburn 13309: if (($context eq 'syllabus') && (!$skiprewrites)) {
13310: my ($actionurl,$state);
13311: $actionurl = "/public/$udom/$uname/syllabus";
13312: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13313: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13314: \%codebase,
13315: {'context' => 'rewrites',
13316: 'ignore_remote_references' => 1,});
13317: if (ref($mapping) eq 'HASH') {
13318: my $rewrites = 0;
13319: foreach my $key (keys(%{$mapping})) {
13320: next if ($key =~ m{^https?://});
13321: my $ref = $mapping->{$key};
13322: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13323: my $attrib;
13324: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13325: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13326: }
13327: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13328: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13329: $rewrites += $numchg;
13330: }
13331: }
13332: if ($rewrites) {
13333: my $saveresult;
13334: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13335: if ($url eq $container) {
13336: my ($fname) = ($container =~ m{/([^/]+)$});
13337: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13338: $count,'<span class="LC_filename">'.
13339: $fname.'</span>').'</p>';
13340: } else {
13341: $output .= '<p class="LC_error">'.
13342: &mt('Error: could not update links in [_1].',
13343: '<span class="LC_filename">'.
13344: $container.'</span>').'</p>';
13345:
13346: }
13347: }
13348: }
13349: }
1.987 raeburn 13350: } else {
13351: &logthis('Failed to parse '.$container.
13352: ' to modify references: '.$parse_result);
1.661 raeburn 13353: }
13354: }
1.1071 raeburn 13355: if (wantarray) {
13356: return ($output,$count,$codebasecount);
13357: } else {
13358: return $output;
13359: }
1.661 raeburn 13360: }
13361:
13362: sub check_for_existing {
13363: my ($path,$fname,$element) = @_;
13364: my ($state,$msg);
13365: if (-d $path.'/'.$fname) {
13366: $state = 'exists';
13367: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13368: } elsif (-e $path.'/'.$fname) {
13369: $state = 'exists';
13370: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13371: }
13372: if ($state eq 'exists') {
13373: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13374: }
13375: return ($state,$msg);
13376: }
13377:
13378: sub check_for_upload {
13379: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13380: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13381: my $filesize = length($env{'form.'.$element});
13382: if (!$filesize) {
13383: my $msg = '<span class="LC_error">'.
13384: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13385: '<span class="LC_filename">'.$fname.'</span>',
13386: $filesize).'<br />'.
1.1007 raeburn 13387: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13388: '</span>';
13389: return ('zero_bytes',$msg);
13390: }
13391: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13392: my $getpropath = 1;
1.1021 raeburn 13393: my ($dirlistref,$listerror) =
13394: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13395: my $found_file = 0;
13396: my $locked_file = 0;
1.991 raeburn 13397: my @lockers;
13398: my $navmap;
13399: if ($env{'request.course.id'}) {
13400: $navmap = Apache::lonnavmaps::navmap->new();
13401: }
1.1021 raeburn 13402: if (ref($dirlistref) eq 'ARRAY') {
13403: foreach my $line (@{$dirlistref}) {
13404: my ($file_name,$rest)=split(/\&/,$line,2);
13405: if ($file_name eq $fname){
13406: $file_name = $path.$file_name;
13407: if ($group ne '') {
13408: $file_name = $group.$file_name;
13409: }
13410: $found_file = 1;
13411: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13412: foreach my $lock (@lockers) {
13413: if (ref($lock) eq 'ARRAY') {
13414: my ($symb,$crsid) = @{$lock};
13415: if ($crsid eq $env{'request.course.id'}) {
13416: if (ref($navmap)) {
13417: my $res = $navmap->getBySymb($symb);
13418: foreach my $part (@{$res->parts()}) {
13419: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13420: unless (($slot_status == $res->RESERVED) ||
13421: ($slot_status == $res->RESERVED_LOCATION)) {
13422: $locked_file = 1;
13423: }
1.991 raeburn 13424: }
1.1021 raeburn 13425: } else {
13426: $locked_file = 1;
1.991 raeburn 13427: }
13428: } else {
13429: $locked_file = 1;
13430: }
13431: }
1.1021 raeburn 13432: }
13433: } else {
13434: my @info = split(/\&/,$rest);
13435: my $currsize = $info[6]/1000;
13436: if ($currsize < $filesize) {
13437: my $extra = $filesize - $currsize;
13438: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13439: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13440: &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 13441: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13442: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13443: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13444: return ('will_exceed_quota',$msg);
13445: }
1.984 raeburn 13446: }
13447: }
1.661 raeburn 13448: }
13449: }
13450: }
13451: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13452: my $msg = '<p class="LC_warning">'.
13453: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13454: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13455: return ('will_exceed_quota',$msg);
13456: } elsif ($found_file) {
13457: if ($locked_file) {
1.1179 bisitz 13458: my $msg = '<p class="LC_warning">';
1.661 raeburn 13459: $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 13460: $msg .= '</p>';
1.661 raeburn 13461: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13462: return ('file_locked',$msg);
13463: } else {
1.1179 bisitz 13464: my $msg = '<p class="LC_error">';
1.984 raeburn 13465: $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 13466: $msg .= '</p>';
1.984 raeburn 13467: return ('existingfile',$msg);
1.661 raeburn 13468: }
13469: }
13470: }
13471:
1.987 raeburn 13472: sub check_for_traversal {
13473: my ($path,$url,$toplevel) = @_;
13474: my @parts=split(/\//,$path);
13475: my $cleanpath;
13476: my $fullpath = $url;
13477: for (my $i=0;$i<@parts;$i++) {
13478: next if ($parts[$i] eq '.');
13479: if ($parts[$i] eq '..') {
13480: $fullpath =~ s{([^/]+/)$}{};
13481: } else {
13482: $fullpath .= $parts[$i].'/';
13483: }
13484: }
13485: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13486: $cleanpath = $1;
13487: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13488: my $curr_toprel = $1;
13489: my @parts = split(/\//,$curr_toprel);
13490: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13491: my @urlparts = split(/\//,$url_toprel);
13492: my $doubledots;
13493: my $startdiff = -1;
13494: for (my $i=0; $i<@urlparts; $i++) {
13495: if ($startdiff == -1) {
13496: unless ($urlparts[$i] eq $parts[$i]) {
13497: $startdiff = $i;
13498: $doubledots .= '../';
13499: }
13500: } else {
13501: $doubledots .= '../';
13502: }
13503: }
13504: if ($startdiff > -1) {
13505: $cleanpath = $doubledots;
13506: for (my $i=$startdiff; $i<@parts; $i++) {
13507: $cleanpath .= $parts[$i].'/';
13508: }
13509: }
13510: }
13511: $cleanpath =~ s{(/)$}{};
13512: return $cleanpath;
13513: }
1.31 albertel 13514:
1.1053 raeburn 13515: sub is_archive_file {
13516: my ($mimetype) = @_;
13517: if (($mimetype eq 'application/octet-stream') ||
13518: ($mimetype eq 'application/x-stuffit') ||
13519: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13520: return 1;
13521: }
13522: return;
13523: }
13524:
13525: sub decompress_form {
1.1065 raeburn 13526: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13527: my %lt = &Apache::lonlocal::texthash (
13528: this => 'This file is an archive file.',
1.1067 raeburn 13529: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13530: itsc => 'Its contents are as follows:',
1.1053 raeburn 13531: youm => 'You may wish to extract its contents.',
13532: extr => 'Extract contents',
1.1067 raeburn 13533: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13534: proa => 'Process automatically?',
1.1053 raeburn 13535: yes => 'Yes',
13536: no => 'No',
1.1067 raeburn 13537: fold => 'Title for folder containing movie',
13538: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13539: );
1.1065 raeburn 13540: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13541: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13542: my $info = &list_archive_contents($fileloc,\@paths);
13543: if (@paths) {
13544: foreach my $path (@paths) {
13545: $path =~ s{^/}{};
1.1067 raeburn 13546: if ($path =~ m{^([^/]+)/$}) {
13547: $topdir = $1;
13548: }
1.1065 raeburn 13549: if ($path =~ m{^([^/]+)/}) {
13550: $toplevel{$1} = $path;
13551: } else {
13552: $toplevel{$path} = $path;
13553: }
13554: }
13555: }
1.1067 raeburn 13556: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13557: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13558: "$topdir/media/",
13559: "$topdir/media/$topdir.mp4",
13560: "$topdir/media/FirstFrame.png",
13561: "$topdir/media/player.swf",
13562: "$topdir/media/swfobject.js",
13563: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13564: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13565: "$topdir/$topdir.mp4",
13566: "$topdir/$topdir\_config.xml",
13567: "$topdir/$topdir\_controller.swf",
13568: "$topdir/$topdir\_embed.css",
13569: "$topdir/$topdir\_First_Frame.png",
13570: "$topdir/$topdir\_player.html",
13571: "$topdir/$topdir\_Thumbnails.png",
13572: "$topdir/playerProductInstall.swf",
13573: "$topdir/scripts/",
13574: "$topdir/scripts/config_xml.js",
13575: "$topdir/scripts/handlebars.js",
13576: "$topdir/scripts/jquery-1.7.1.min.js",
13577: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13578: "$topdir/scripts/modernizr.js",
13579: "$topdir/scripts/player-min.js",
13580: "$topdir/scripts/swfobject.js",
13581: "$topdir/skins/",
13582: "$topdir/skins/configuration_express.xml",
13583: "$topdir/skins/express_show/",
13584: "$topdir/skins/express_show/player-min.css",
13585: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13586: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13587: "$topdir/$topdir.mp4",
13588: "$topdir/$topdir\_config.xml",
13589: "$topdir/$topdir\_controller.swf",
13590: "$topdir/$topdir\_embed.css",
13591: "$topdir/$topdir\_First_Frame.png",
13592: "$topdir/$topdir\_player.html",
13593: "$topdir/$topdir\_Thumbnails.png",
13594: "$topdir/playerProductInstall.swf",
13595: "$topdir/scripts/",
13596: "$topdir/scripts/config_xml.js",
13597: "$topdir/scripts/techsmith-smart-player.min.js",
13598: "$topdir/skins/",
13599: "$topdir/skins/configuration_express.xml",
13600: "$topdir/skins/express_show/",
13601: "$topdir/skins/express_show/spritesheet.min.css",
13602: "$topdir/skins/express_show/spritesheet.png",
13603: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13604: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13605: if (@diffs == 0) {
1.1164 raeburn 13606: $is_camtasia = 6;
13607: } else {
1.1197 raeburn 13608: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13609: if (@diffs == 0) {
13610: $is_camtasia = 8;
1.1197 raeburn 13611: } else {
13612: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13613: if (@diffs == 0) {
13614: $is_camtasia = 8;
13615: }
1.1164 raeburn 13616: }
1.1067 raeburn 13617: }
13618: }
13619: my $output;
13620: if ($is_camtasia) {
13621: $output = <<"ENDCAM";
13622: <script type="text/javascript" language="Javascript">
13623: // <![CDATA[
13624:
13625: function camtasiaToggle() {
13626: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13627: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13628: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13629: document.getElementById('camtasia_titles').style.display='block';
13630: } else {
13631: document.getElementById('camtasia_titles').style.display='none';
13632: }
13633: }
13634: }
13635: return;
13636: }
13637:
13638: // ]]>
13639: </script>
13640: <p>$lt{'camt'}</p>
13641: ENDCAM
1.1065 raeburn 13642: } else {
1.1067 raeburn 13643: $output = '<p>'.$lt{'this'};
13644: if ($info eq '') {
13645: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13646: } else {
13647: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13648: '<div><pre>'.$info.'</pre></div>';
13649: }
1.1065 raeburn 13650: }
1.1067 raeburn 13651: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13652: my $duplicates;
13653: my $num = 0;
13654: if (ref($dirlist) eq 'ARRAY') {
13655: foreach my $item (@{$dirlist}) {
13656: if (ref($item) eq 'ARRAY') {
13657: if (exists($toplevel{$item->[0]})) {
13658: $duplicates .=
13659: &start_data_table_row().
13660: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13661: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13662: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13663: 'value="1" />'.&mt('Yes').'</label>'.
13664: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13665: '<td>'.$item->[0].'</td>';
13666: if ($item->[2]) {
13667: $duplicates .= '<td>'.&mt('Directory').'</td>';
13668: } else {
13669: $duplicates .= '<td>'.&mt('File').'</td>';
13670: }
13671: $duplicates .= '<td>'.$item->[3].'</td>'.
13672: '<td>'.
13673: &Apache::lonlocal::locallocaltime($item->[4]).
13674: '</td>'.
13675: &end_data_table_row();
13676: $num ++;
13677: }
13678: }
13679: }
13680: }
13681: my $itemcount;
13682: if (@paths > 0) {
13683: $itemcount = scalar(@paths);
13684: } else {
13685: $itemcount = 1;
13686: }
1.1067 raeburn 13687: if ($is_camtasia) {
13688: $output .= $lt{'auto'}.'<br />'.
13689: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13690: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13691: $lt{'yes'}.'</label> <label>'.
13692: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13693: $lt{'no'}.'</label></span><br />'.
13694: '<div id="camtasia_titles" style="display:block">'.
13695: &Apache::lonhtmlcommon::start_pick_box().
13696: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13697: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13698: &Apache::lonhtmlcommon::row_closure().
13699: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13700: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13701: &Apache::lonhtmlcommon::row_closure(1).
13702: &Apache::lonhtmlcommon::end_pick_box().
13703: '</div>';
13704: }
1.1065 raeburn 13705: $output .=
13706: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13707: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13708: "\n";
1.1065 raeburn 13709: if ($duplicates ne '') {
13710: $output .= '<p><span class="LC_warning">'.
13711: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13712: &start_data_table().
13713: &start_data_table_header_row().
13714: '<th>'.&mt('Overwrite?').'</th>'.
13715: '<th>'.&mt('Name').'</th>'.
13716: '<th>'.&mt('Type').'</th>'.
13717: '<th>'.&mt('Size').'</th>'.
13718: '<th>'.&mt('Last modified').'</th>'.
13719: &end_data_table_header_row().
13720: $duplicates.
13721: &end_data_table().
13722: '</p>';
13723: }
1.1067 raeburn 13724: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13725: if (ref($hiddenelements) eq 'HASH') {
13726: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13727: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13728: }
13729: }
13730: $output .= <<"END";
1.1067 raeburn 13731: <br />
1.1053 raeburn 13732: <input type="submit" name="decompress" value="$lt{'extr'}" />
13733: </form>
13734: $noextract
13735: END
13736: return $output;
13737: }
13738:
1.1065 raeburn 13739: sub decompression_utility {
13740: my ($program) = @_;
13741: my @utilities = ('tar','gunzip','bunzip2','unzip');
13742: my $location;
13743: if (grep(/^\Q$program\E$/,@utilities)) {
13744: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13745: '/usr/sbin/') {
13746: if (-x $dir.$program) {
13747: $location = $dir.$program;
13748: last;
13749: }
13750: }
13751: }
13752: return $location;
13753: }
13754:
13755: sub list_archive_contents {
13756: my ($file,$pathsref) = @_;
13757: my (@cmd,$output);
13758: my $needsregexp;
13759: if ($file =~ /\.zip$/) {
13760: @cmd = (&decompression_utility('unzip'),"-l");
13761: $needsregexp = 1;
13762: } elsif (($file =~ m/\.tar\.gz$/) ||
13763: ($file =~ /\.tgz$/)) {
13764: @cmd = (&decompression_utility('tar'),"-ztf");
13765: } elsif ($file =~ /\.tar\.bz2$/) {
13766: @cmd = (&decompression_utility('tar'),"-jtf");
13767: } elsif ($file =~ m|\.tar$|) {
13768: @cmd = (&decompression_utility('tar'),"-tf");
13769: }
13770: if (@cmd) {
13771: undef($!);
13772: undef($@);
13773: if (open(my $fh,"-|", @cmd, $file)) {
13774: while (my $line = <$fh>) {
13775: $output .= $line;
13776: chomp($line);
13777: my $item;
13778: if ($needsregexp) {
13779: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13780: } else {
13781: $item = $line;
13782: }
13783: if ($item ne '') {
13784: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13785: push(@{$pathsref},$item);
13786: }
13787: }
13788: }
13789: close($fh);
13790: }
13791: }
13792: return $output;
13793: }
13794:
1.1053 raeburn 13795: sub decompress_uploaded_file {
13796: my ($file,$dir) = @_;
13797: &Apache::lonnet::appenv({'cgi.file' => $file});
13798: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13799: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13800: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13801: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13802: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13803: my $decompressed = $env{'cgi.decompressed'};
13804: &Apache::lonnet::delenv('cgi.file');
13805: &Apache::lonnet::delenv('cgi.dir');
13806: &Apache::lonnet::delenv('cgi.decompressed');
13807: return ($decompressed,$result);
13808: }
13809:
1.1055 raeburn 13810: sub process_decompression {
13811: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13812: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13813: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13814: &mt('Unexpected file path.').'</p>'."\n";
13815: }
13816: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13817: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13818: &mt('Unexpected course context.').'</p>'."\n";
13819: }
1.1293 raeburn 13820: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13821: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13822: &mt('Filename contained unexpected characters.').'</p>'."\n";
13823: }
1.1055 raeburn 13824: my ($dir,$error,$warning,$output);
1.1180 raeburn 13825: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13826: $error = &mt('Filename not a supported archive file type.').
13827: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13828: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13829: } else {
13830: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13831: if ($docuhome eq 'no_host') {
13832: $error = &mt('Could not determine home server for course.');
13833: } else {
13834: my @ids=&Apache::lonnet::current_machine_ids();
13835: my $currdir = "$dir_root/$destination";
13836: if (grep(/^\Q$docuhome\E$/,@ids)) {
13837: $dir = &LONCAPA::propath($docudom,$docuname).
13838: "$dir_root/$destination";
13839: } else {
13840: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13841: "$dir_root/$docudom/$docuname/$destination";
13842: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13843: $error = &mt('Archive file not found.');
13844: }
13845: }
1.1065 raeburn 13846: my (@to_overwrite,@to_skip);
13847: if ($env{'form.archive_overwrite_total'} > 0) {
13848: my $total = $env{'form.archive_overwrite_total'};
13849: for (my $i=0; $i<$total; $i++) {
13850: if ($env{'form.archive_overwrite_'.$i} == 1) {
13851: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13852: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13853: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13854: }
13855: }
13856: }
13857: my $numskip = scalar(@to_skip);
1.1292 raeburn 13858: my $numoverwrite = scalar(@to_overwrite);
13859: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13860: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13861: } elsif ($dir eq '') {
1.1055 raeburn 13862: $error = &mt('Directory containing archive file unavailable.');
13863: } elsif (!$error) {
1.1065 raeburn 13864: my ($decompressed,$display);
1.1292 raeburn 13865: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13866: my $tempdir = time.'_'.$$.int(rand(10000));
13867: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13868: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13869: ($decompressed,$display) =
13870: &decompress_uploaded_file($file,"$dir/$tempdir");
13871: foreach my $item (@to_skip) {
13872: if (($item ne '') && ($item !~ /\.\./)) {
13873: if (-f "$dir/$tempdir/$item") {
13874: unlink("$dir/$tempdir/$item");
13875: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13876: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13877: }
13878: }
13879: }
13880: foreach my $item (@to_overwrite) {
13881: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13882: if (($item ne '') && ($item !~ /\.\./)) {
13883: if (-f "$dir/$item") {
13884: unlink("$dir/$item");
13885: } elsif (-d "$dir/$item") {
1.1300 raeburn 13886: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13887: }
13888: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13889: }
1.1065 raeburn 13890: }
13891: }
1.1292 raeburn 13892: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13893: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13894: }
1.1065 raeburn 13895: }
13896: } else {
13897: ($decompressed,$display) =
13898: &decompress_uploaded_file($file,$dir);
13899: }
1.1055 raeburn 13900: if ($decompressed eq 'ok') {
1.1065 raeburn 13901: $output = '<p class="LC_info">'.
13902: &mt('Files extracted successfully from archive.').
13903: '</p>'."\n";
1.1055 raeburn 13904: my ($warning,$result,@contents);
13905: my ($newdirlistref,$newlisterror) =
13906: &Apache::lonnet::dirlist($currdir,$docudom,
13907: $docuname,1);
13908: my (%is_dir,%changes,@newitems);
13909: my $dirptr = 16384;
1.1065 raeburn 13910: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13911: foreach my $dir_line (@{$newdirlistref}) {
13912: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13913: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13914: push(@newitems,$item);
13915: if ($dirptr&$testdir) {
13916: $is_dir{$item} = 1;
13917: }
13918: $changes{$item} = 1;
13919: }
13920: }
13921: }
13922: if (keys(%changes) > 0) {
13923: foreach my $item (sort(@newitems)) {
13924: if ($changes{$item}) {
13925: push(@contents,$item);
13926: }
13927: }
13928: }
13929: if (@contents > 0) {
1.1067 raeburn 13930: my $wantform;
13931: unless ($env{'form.autoextract_camtasia'}) {
13932: $wantform = 1;
13933: }
1.1056 raeburn 13934: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13935: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13936: $currdir,\%is_dir,
13937: \%children,\%parent,
1.1056 raeburn 13938: \@contents,\%dirorder,
13939: \%titles,$wantform);
1.1055 raeburn 13940: if ($datatable ne '') {
13941: $output .= &archive_options_form('decompressed',$datatable,
13942: $count,$hiddenelem);
1.1065 raeburn 13943: my $startcount = 6;
1.1055 raeburn 13944: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13945: \%titles,\%children);
1.1055 raeburn 13946: }
1.1067 raeburn 13947: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13948: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13949: my %displayed;
13950: my $total = 1;
13951: $env{'form.archive_directory'} = [];
13952: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13953: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13954: $path =~ s{/$}{};
13955: my $item;
13956: if ($path ne '') {
13957: $item = "$path/$titles{$i}";
13958: } else {
13959: $item = $titles{$i};
13960: }
13961: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13962: if ($item eq $contents[0]) {
13963: push(@{$env{'form.archive_directory'}},$i);
13964: $env{'form.archive_'.$i} = 'display';
13965: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13966: $displayed{'folder'} = $i;
1.1164 raeburn 13967: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13968: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13969: $env{'form.archive_'.$i} = 'display';
13970: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13971: $displayed{'web'} = $i;
13972: } else {
1.1164 raeburn 13973: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13974: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13975: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13976: push(@{$env{'form.archive_directory'}},$i);
13977: }
13978: $env{'form.archive_'.$i} = 'dependency';
13979: }
13980: $total ++;
13981: }
13982: for (my $i=1; $i<$total; $i++) {
13983: next if ($i == $displayed{'web'});
13984: next if ($i == $displayed{'folder'});
13985: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13986: }
13987: $env{'form.phase'} = 'decompress_cleanup';
13988: $env{'form.archivedelete'} = 1;
13989: $env{'form.archive_count'} = $total-1;
13990: $output .=
13991: &process_extracted_files('coursedocs',$docudom,
13992: $docuname,$destination,
13993: $dir_root,$hiddenelem);
13994: }
1.1055 raeburn 13995: } else {
13996: $warning = &mt('No new items extracted from archive file.');
13997: }
13998: } else {
13999: $output = $display;
14000: $error = &mt('An error occurred during extraction from the archive file.');
14001: }
14002: }
14003: }
14004: }
14005: if ($error) {
14006: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14007: $error.'</p>'."\n";
14008: }
14009: if ($warning) {
14010: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14011: }
14012: return $output;
14013: }
14014:
14015: sub get_extracted {
1.1056 raeburn 14016: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
14017: $titles,$wantform) = @_;
1.1055 raeburn 14018: my $count = 0;
14019: my $depth = 0;
14020: my $datatable;
1.1056 raeburn 14021: my @hierarchy;
1.1055 raeburn 14022: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 14023: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
14024: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 14025: foreach my $item (@{$contents}) {
14026: $count ++;
1.1056 raeburn 14027: @{$dirorder->{$count}} = @hierarchy;
14028: $titles->{$count} = $item;
1.1055 raeburn 14029: &archive_hierarchy($depth,$count,$parent,$children);
14030: if ($wantform) {
14031: $datatable .= &archive_row($is_dir->{$item},$item,
14032: $currdir,$depth,$count);
14033: }
14034: if ($is_dir->{$item}) {
14035: $depth ++;
1.1056 raeburn 14036: push(@hierarchy,$count);
14037: $parent->{$depth} = $count;
1.1055 raeburn 14038: $datatable .=
14039: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14040: \$depth,\$count,\@hierarchy,$dirorder,
14041: $children,$parent,$titles,$wantform);
1.1055 raeburn 14042: $depth --;
1.1056 raeburn 14043: pop(@hierarchy);
1.1055 raeburn 14044: }
14045: }
14046: return ($count,$datatable);
14047: }
14048:
14049: sub recurse_extracted_archive {
1.1056 raeburn 14050: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14051: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14052: my $result='';
1.1056 raeburn 14053: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14054: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14055: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14056: return $result;
14057: }
14058: my $dirptr = 16384;
14059: my ($newdirlistref,$newlisterror) =
14060: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14061: if (ref($newdirlistref) eq 'ARRAY') {
14062: foreach my $dir_line (@{$newdirlistref}) {
14063: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14064: unless ($item =~ /^\.+$/) {
14065: $$count ++;
1.1056 raeburn 14066: @{$dirorder->{$$count}} = @{$hierarchy};
14067: $titles->{$$count} = $item;
1.1055 raeburn 14068: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14069:
1.1055 raeburn 14070: my $is_dir;
14071: if ($dirptr&$testdir) {
14072: $is_dir = 1;
14073: }
14074: if ($wantform) {
14075: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14076: }
14077: if ($is_dir) {
14078: $$depth ++;
1.1056 raeburn 14079: push(@{$hierarchy},$$count);
14080: $parent->{$$depth} = $$count;
1.1055 raeburn 14081: $result .=
14082: &recurse_extracted_archive("$currdir/$item",$docudom,
14083: $docuname,$depth,$count,
1.1056 raeburn 14084: $hierarchy,$dirorder,$children,
14085: $parent,$titles,$wantform);
1.1055 raeburn 14086: $$depth --;
1.1056 raeburn 14087: pop(@{$hierarchy});
1.1055 raeburn 14088: }
14089: }
14090: }
14091: }
14092: return $result;
14093: }
14094:
14095: sub archive_hierarchy {
14096: my ($depth,$count,$parent,$children) =@_;
14097: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14098: if (exists($parent->{$depth})) {
14099: $children->{$parent->{$depth}} .= $count.':';
14100: }
14101: }
14102: return;
14103: }
14104:
14105: sub archive_row {
14106: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14107: my ($name) = ($item =~ m{([^/]+)$});
14108: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14109: 'display' => 'Add as file',
1.1055 raeburn 14110: 'dependency' => 'Include as dependency',
14111: 'discard' => 'Discard',
14112: );
14113: if ($is_dir) {
1.1059 raeburn 14114: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14115: }
1.1056 raeburn 14116: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14117: my $offset = 0;
1.1055 raeburn 14118: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14119: $offset ++;
1.1065 raeburn 14120: if ($action ne 'display') {
14121: $offset ++;
14122: }
1.1055 raeburn 14123: $output .= '<td><span class="LC_nobreak">'.
14124: '<label><input type="radio" name="archive_'.$count.
14125: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14126: my $text = $choices{$action};
14127: if ($is_dir) {
14128: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14129: if ($action eq 'display') {
1.1059 raeburn 14130: $text = &mt('Add as folder');
1.1055 raeburn 14131: }
1.1056 raeburn 14132: } else {
14133: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14134:
14135: }
14136: $output .= ' /> '.$choices{$action}.'</label></span>';
14137: if ($action eq 'dependency') {
14138: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14139: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14140: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14141: '<option value=""></option>'."\n".
14142: '</select>'."\n".
14143: '</div>';
1.1059 raeburn 14144: } elsif ($action eq 'display') {
14145: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14146: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14147: '</div>';
1.1055 raeburn 14148: }
1.1056 raeburn 14149: $output .= '</td>';
1.1055 raeburn 14150: }
14151: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14152: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14153: for (my $i=0; $i<$depth; $i++) {
14154: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14155: }
14156: if ($is_dir) {
14157: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14158: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14159: } else {
14160: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14161: }
14162: $output .= ' '.$name.'</td>'."\n".
14163: &end_data_table_row();
14164: return $output;
14165: }
14166:
14167: sub archive_options_form {
1.1065 raeburn 14168: my ($form,$display,$count,$hiddenelem) = @_;
14169: my %lt = &Apache::lonlocal::texthash(
14170: perm => 'Permanently remove archive file?',
14171: hows => 'How should each extracted item be incorporated in the course?',
14172: cont => 'Content actions for all',
14173: addf => 'Add as folder/file',
14174: incd => 'Include as dependency for a displayed file',
14175: disc => 'Discard',
14176: no => 'No',
14177: yes => 'Yes',
14178: save => 'Save',
14179: );
14180: my $output = <<"END";
14181: <form name="$form" method="post" action="">
14182: <p><span class="LC_nobreak">$lt{'perm'}
14183: <label>
14184: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14185: </label>
14186:
14187: <label>
14188: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14189: </span>
14190: </p>
14191: <input type="hidden" name="phase" value="decompress_cleanup" />
14192: <br />$lt{'hows'}
14193: <div class="LC_columnSection">
14194: <fieldset>
14195: <legend>$lt{'cont'}</legend>
14196: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14197: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14198: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14199: </fieldset>
14200: </div>
14201: END
14202: return $output.
1.1055 raeburn 14203: &start_data_table()."\n".
1.1065 raeburn 14204: $display."\n".
1.1055 raeburn 14205: &end_data_table()."\n".
14206: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14207: $hiddenelem.
1.1065 raeburn 14208: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14209: '</form>';
14210: }
14211:
14212: sub archive_javascript {
1.1056 raeburn 14213: my ($startcount,$numitems,$titles,$children) = @_;
14214: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14215: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14216: my $scripttag = <<START;
14217: <script type="text/javascript">
14218: // <![CDATA[
14219:
14220: function checkAll(form,prefix) {
14221: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14222: for (var i=0; i < form.elements.length; i++) {
14223: var id = form.elements[i].id;
14224: if ((id != '') && (id != undefined)) {
14225: if (idstr.test(id)) {
14226: if (form.elements[i].type == 'radio') {
14227: form.elements[i].checked = true;
1.1056 raeburn 14228: var nostart = i-$startcount;
1.1059 raeburn 14229: var offset = nostart%7;
14230: var count = (nostart-offset)/7;
1.1056 raeburn 14231: dependencyCheck(form,count,offset);
1.1055 raeburn 14232: }
14233: }
14234: }
14235: }
14236: }
14237:
14238: function propagateCheck(form,count) {
14239: if (count > 0) {
1.1059 raeburn 14240: var startelement = $startcount + ((count-1) * 7);
14241: for (var j=1; j<6; j++) {
14242: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14243: var item = startelement + j;
14244: if (form.elements[item].type == 'radio') {
14245: if (form.elements[item].checked) {
14246: containerCheck(form,count,j);
14247: break;
14248: }
1.1055 raeburn 14249: }
14250: }
14251: }
14252: }
14253: }
14254:
14255: numitems = $numitems
1.1056 raeburn 14256: var titles = new Array(numitems);
14257: var parents = new Array(numitems);
1.1055 raeburn 14258: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14259: parents[i] = new Array;
1.1055 raeburn 14260: }
1.1059 raeburn 14261: var maintitle = '$maintitle';
1.1055 raeburn 14262:
14263: START
14264:
1.1056 raeburn 14265: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14266: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14267: for (my $i=0; $i<@contents; $i ++) {
14268: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14269: }
14270: }
14271:
1.1056 raeburn 14272: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14273: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14274: }
14275:
1.1055 raeburn 14276: $scripttag .= <<END;
14277:
14278: function containerCheck(form,count,offset) {
14279: if (count > 0) {
1.1056 raeburn 14280: dependencyCheck(form,count,offset);
1.1059 raeburn 14281: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14282: form.elements[item].checked = true;
14283: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14284: if (parents[count].length > 0) {
14285: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14286: containerCheck(form,parents[count][j],offset);
14287: }
14288: }
14289: }
14290: }
14291: }
14292:
14293: function dependencyCheck(form,count,offset) {
14294: if (count > 0) {
1.1059 raeburn 14295: var chosen = (offset+$startcount)+7*(count-1);
14296: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14297: var currtype = form.elements[depitem].type;
14298: if (form.elements[chosen].value == 'dependency') {
14299: document.getElementById('arc_depon_'+count).style.display='block';
14300: form.elements[depitem].options.length = 0;
14301: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14302: for (var i=1; i<=numitems; i++) {
14303: if (i == count) {
14304: continue;
14305: }
1.1059 raeburn 14306: var startelement = $startcount + (i-1) * 7;
14307: for (var j=1; j<6; j++) {
14308: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14309: var item = startelement + j;
14310: if (form.elements[item].type == 'radio') {
14311: if (form.elements[item].checked) {
14312: if (form.elements[item].value == 'display') {
14313: var n = form.elements[depitem].options.length;
14314: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14315: }
14316: }
14317: }
14318: }
14319: }
14320: }
14321: } else {
14322: document.getElementById('arc_depon_'+count).style.display='none';
14323: form.elements[depitem].options.length = 0;
14324: form.elements[depitem].options[0] = new Option('Select','',true,true);
14325: }
1.1059 raeburn 14326: titleCheck(form,count,offset);
1.1056 raeburn 14327: }
14328: }
14329:
14330: function propagateSelect(form,count,offset) {
14331: if (count > 0) {
1.1065 raeburn 14332: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14333: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14334: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14335: if (parents[count].length > 0) {
14336: for (var j=0; j<parents[count].length; j++) {
14337: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14338: }
14339: }
14340: }
14341: }
14342: }
1.1056 raeburn 14343:
14344: function containerSelect(form,count,offset,picked) {
14345: if (count > 0) {
1.1065 raeburn 14346: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14347: if (form.elements[item].type == 'radio') {
14348: if (form.elements[item].value == 'dependency') {
14349: if (form.elements[item+1].type == 'select-one') {
14350: for (var i=0; i<form.elements[item+1].options.length; i++) {
14351: if (form.elements[item+1].options[i].value == picked) {
14352: form.elements[item+1].selectedIndex = i;
14353: break;
14354: }
14355: }
14356: }
14357: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14358: if (parents[count].length > 0) {
14359: for (var j=0; j<parents[count].length; j++) {
14360: containerSelect(form,parents[count][j],offset,picked);
14361: }
14362: }
14363: }
14364: }
14365: }
14366: }
14367: }
14368:
1.1059 raeburn 14369: function titleCheck(form,count,offset) {
14370: if (count > 0) {
14371: var chosen = (offset+$startcount)+7*(count-1);
14372: var depitem = $startcount + ((count-1) * 7) + 2;
14373: var currtype = form.elements[depitem].type;
14374: if (form.elements[chosen].value == 'display') {
14375: document.getElementById('arc_title_'+count).style.display='block';
14376: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14377: document.getElementById('archive_title_'+count).value=maintitle;
14378: }
14379: } else {
14380: document.getElementById('arc_title_'+count).style.display='none';
14381: if (currtype == 'text') {
14382: document.getElementById('archive_title_'+count).value='';
14383: }
14384: }
14385: }
14386: return;
14387: }
14388:
1.1055 raeburn 14389: // ]]>
14390: </script>
14391: END
14392: return $scripttag;
14393: }
14394:
14395: sub process_extracted_files {
1.1067 raeburn 14396: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14397: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14398: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14399: my @ids=&Apache::lonnet::current_machine_ids();
14400: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14401: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14402: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14403: if (grep(/^\Q$docuhome\E$/,@ids)) {
14404: $prefix = &LONCAPA::propath($docudom,$docuname);
14405: $pathtocheck = "$dir_root/$destination";
14406: $dir = $dir_root;
14407: $ishome = 1;
14408: } else {
14409: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14410: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14411: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14412: }
14413: my $currdir = "$dir_root/$destination";
14414: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14415: if ($env{'form.folderpath'}) {
14416: my @items = split('&',$env{'form.folderpath'});
14417: $folders{'0'} = $items[-2];
1.1099 raeburn 14418: if ($env{'form.folderpath'} =~ /\:1$/) {
14419: $containers{'0'}='page';
14420: } else {
14421: $containers{'0'}='sequence';
14422: }
1.1055 raeburn 14423: }
14424: my @archdirs = &get_env_multiple('form.archive_directory');
14425: if ($numitems) {
14426: for (my $i=1; $i<=$numitems; $i++) {
14427: my $path = $env{'form.archive_content_'.$i};
14428: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14429: my $item = $1;
14430: $toplevelitems{$item} = $i;
14431: if (grep(/^\Q$i\E$/,@archdirs)) {
14432: $is_dir{$item} = 1;
14433: }
14434: }
14435: }
14436: }
1.1067 raeburn 14437: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14438: if (keys(%toplevelitems) > 0) {
14439: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14440: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14441: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14442: }
1.1066 raeburn 14443: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14444: if ($numitems) {
14445: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14446: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14447: my $path = $env{'form.archive_content_'.$i};
14448: if ($path =~ /^\Q$pathtocheck\E/) {
14449: if ($env{'form.archive_'.$i} eq 'discard') {
14450: if ($prefix ne '' && $path ne '') {
14451: if (-e $prefix.$path) {
1.1066 raeburn 14452: if ((@archdirs > 0) &&
14453: (grep(/^\Q$i\E$/,@archdirs))) {
14454: $todeletedir{$prefix.$path} = 1;
14455: } else {
14456: $todelete{$prefix.$path} = 1;
14457: }
1.1055 raeburn 14458: }
14459: }
14460: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14461: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14462: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14463: $docstitle = $env{'form.archive_title_'.$i};
14464: if ($docstitle eq '') {
14465: $docstitle = $title;
14466: }
1.1055 raeburn 14467: $outer = 0;
1.1056 raeburn 14468: if (ref($dirorder{$i}) eq 'ARRAY') {
14469: if (@{$dirorder{$i}} > 0) {
14470: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14471: if ($env{'form.archive_'.$item} eq 'display') {
14472: $outer = $item;
14473: last;
14474: }
14475: }
14476: }
14477: }
14478: my ($errtext,$fatal) =
14479: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14480: '/'.$folders{$outer}.'.'.
14481: $containers{$outer});
14482: next if ($fatal);
14483: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14484: if ($context eq 'coursedocs') {
1.1056 raeburn 14485: $mapinner{$i} = time;
1.1055 raeburn 14486: $folders{$i} = 'default_'.$mapinner{$i};
14487: $containers{$i} = 'sequence';
14488: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14489: $folders{$i}.'.'.$containers{$i};
14490: my $newidx = &LONCAPA::map::getresidx();
14491: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14492: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14493: push(@LONCAPA::map::order,$newidx);
14494: my ($outtext,$errtext) =
14495: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14496: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14497: '.'.$containers{$outer},1,1);
1.1056 raeburn 14498: $newseqid{$i} = $newidx;
1.1067 raeburn 14499: unless ($errtext) {
1.1294 raeburn 14500: $result .= '<li>'.&mt('Folder: [_1] added to course',
14501: &HTML::Entities::encode($docstitle,'<>&"')).
14502: '</li>'."\n";
1.1067 raeburn 14503: }
1.1055 raeburn 14504: }
14505: } else {
14506: if ($context eq 'coursedocs') {
14507: my $newidx=&LONCAPA::map::getresidx();
14508: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14509: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14510: $title;
1.1392 raeburn 14511: if (($outer !~ /\D/) &&
14512: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14513: ($newidx !~ /\D/)) {
1.1294 raeburn 14514: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14515: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14516: }
14517: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14518: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14519: }
14520: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14521: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14522: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14523: unless ($ishome) {
14524: my $fetch = "$newdest{$i}/$title";
14525: $fetch =~ s/^\Q$prefix$dir\E//;
14526: $prompttofetch{$fetch} = 1;
14527: }
1.1292 raeburn 14528: }
1.1067 raeburn 14529: }
1.1294 raeburn 14530: $LONCAPA::map::resources[$newidx]=
14531: $docstitle.':'.$url.':false:normal:res';
14532: push(@LONCAPA::map::order, $newidx);
14533: my ($outtext,$errtext)=
14534: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14535: $docuname.'/'.$folders{$outer}.
14536: '.'.$containers{$outer},1,1);
14537: unless ($errtext) {
14538: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14539: $result .= '<li>'.&mt('File: [_1] added to course',
14540: &HTML::Entities::encode($docstitle,'<>&"')).
14541: '</li>'."\n";
14542: }
1.1067 raeburn 14543: }
1.1294 raeburn 14544: } else {
14545: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14546: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14547: }
1.1055 raeburn 14548: }
14549: }
1.1086 raeburn 14550: }
14551: } else {
1.1294 raeburn 14552: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14553: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14554: }
14555: }
14556: for (my $i=1; $i<=$numitems; $i++) {
14557: next unless ($env{'form.archive_'.$i} eq 'dependency');
14558: my $path = $env{'form.archive_content_'.$i};
14559: if ($path =~ /^\Q$pathtocheck\E/) {
14560: my ($title) = ($path =~ m{/([^/]+)$});
14561: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14562: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14563: if (ref($dirorder{$i}) eq 'ARRAY') {
14564: my ($itemidx,$fullpath,$relpath);
14565: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14566: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14567: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14568: if ($dirorder{$i}->[$j] eq $container) {
14569: $itemidx = $j;
1.1056 raeburn 14570: }
14571: }
1.1086 raeburn 14572: }
14573: if ($itemidx eq '') {
14574: $itemidx = 0;
14575: }
14576: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14577: if ($mapinner{$referrer{$i}}) {
14578: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14579: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14580: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14581: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14582: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14583: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14584: if (!-e $fullpath) {
14585: mkdir($fullpath,0755);
1.1056 raeburn 14586: }
14587: }
1.1086 raeburn 14588: } else {
14589: last;
1.1056 raeburn 14590: }
1.1086 raeburn 14591: }
14592: }
14593: } elsif ($newdest{$referrer{$i}}) {
14594: $fullpath = $newdest{$referrer{$i}};
14595: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14596: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14597: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14598: last;
14599: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14600: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14601: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14602: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14603: if (!-e $fullpath) {
14604: mkdir($fullpath,0755);
1.1056 raeburn 14605: }
14606: }
1.1086 raeburn 14607: } else {
14608: last;
1.1056 raeburn 14609: }
1.1055 raeburn 14610: }
14611: }
1.1086 raeburn 14612: if ($fullpath ne '') {
14613: if (-e "$prefix$path") {
1.1292 raeburn 14614: unless (rename("$prefix$path","$fullpath/$title")) {
14615: $warning .= &mt('Failed to rename dependency').'<br />';
14616: }
1.1086 raeburn 14617: }
14618: if (-e "$fullpath/$title") {
14619: my $showpath;
14620: if ($relpath ne '') {
14621: $showpath = "$relpath/$title";
14622: } else {
14623: $showpath = "/$title";
14624: }
1.1294 raeburn 14625: $result .= '<li>'.&mt('[_1] included as a dependency',
14626: &HTML::Entities::encode($showpath,'<>&"')).
14627: '</li>'."\n";
1.1292 raeburn 14628: unless ($ishome) {
14629: my $fetch = "$fullpath/$title";
14630: $fetch =~ s/^\Q$prefix$dir\E//;
14631: $prompttofetch{$fetch} = 1;
14632: }
1.1086 raeburn 14633: }
14634: }
1.1055 raeburn 14635: }
1.1086 raeburn 14636: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14637: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14638: &HTML::Entities::encode($path,'<>&"'),
14639: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14640: '<br />';
1.1055 raeburn 14641: }
14642: } else {
1.1294 raeburn 14643: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14644: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14645: }
14646: }
14647: if (keys(%todelete)) {
14648: foreach my $key (keys(%todelete)) {
14649: unlink($key);
1.1066 raeburn 14650: }
14651: }
14652: if (keys(%todeletedir)) {
14653: foreach my $key (keys(%todeletedir)) {
14654: rmdir($key);
14655: }
14656: }
14657: foreach my $dir (sort(keys(%is_dir))) {
14658: if (($pathtocheck ne '') && ($dir ne '')) {
14659: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14660: }
14661: }
1.1067 raeburn 14662: if ($result ne '') {
14663: $output .= '<ul>'."\n".
14664: $result."\n".
14665: '</ul>';
14666: }
14667: unless ($ishome) {
14668: my $replicationfail;
14669: foreach my $item (keys(%prompttofetch)) {
14670: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14671: unless ($fetchresult eq 'ok') {
14672: $replicationfail .= '<li>'.$item.'</li>'."\n";
14673: }
14674: }
14675: if ($replicationfail) {
14676: $output .= '<p class="LC_error">'.
14677: &mt('Course home server failed to retrieve:').'<ul>'.
14678: $replicationfail.
14679: '</ul></p>';
14680: }
14681: }
1.1055 raeburn 14682: } else {
14683: $warning = &mt('No items found in archive.');
14684: }
14685: if ($error) {
14686: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14687: $error.'</p>'."\n";
14688: }
14689: if ($warning) {
14690: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14691: }
14692: return $output;
14693: }
14694:
1.1066 raeburn 14695: sub cleanup_empty_dirs {
14696: my ($path) = @_;
14697: if (($path ne '') && (-d $path)) {
14698: if (opendir(my $dirh,$path)) {
14699: my @dircontents = grep(!/^\./,readdir($dirh));
14700: my $numitems = 0;
14701: foreach my $item (@dircontents) {
14702: if (-d "$path/$item") {
1.1111 raeburn 14703: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14704: if (-e "$path/$item") {
14705: $numitems ++;
14706: }
14707: } else {
14708: $numitems ++;
14709: }
14710: }
14711: if ($numitems == 0) {
14712: rmdir($path);
14713: }
14714: closedir($dirh);
14715: }
14716: }
14717: return;
14718: }
14719:
1.41 ng 14720: =pod
1.45 matthew 14721:
1.1162 raeburn 14722: =item * &get_folder_hierarchy()
1.1068 raeburn 14723:
14724: Provides hierarchy of names of folders/sub-folders containing the current
14725: item,
14726:
14727: Inputs: 3
14728: - $navmap - navmaps object
14729:
14730: - $map - url for map (either the trigger itself, or map containing
14731: the resource, which is the trigger).
14732:
14733: - $showitem - 1 => show title for map itself; 0 => do not show.
14734:
14735: Outputs: 1 @pathitems - array of folder/subfolder names.
14736:
14737: =cut
14738:
14739: sub get_folder_hierarchy {
14740: my ($navmap,$map,$showitem) = @_;
14741: my @pathitems;
14742: if (ref($navmap)) {
14743: my $mapres = $navmap->getResourceByUrl($map);
14744: if (ref($mapres)) {
14745: my $pcslist = $mapres->map_hierarchy();
14746: if ($pcslist ne '') {
14747: my @pcs = split(/,/,$pcslist);
14748: foreach my $pc (@pcs) {
14749: if ($pc == 1) {
1.1129 raeburn 14750: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14751: } else {
14752: my $res = $navmap->getByMapPc($pc);
14753: if (ref($res)) {
14754: my $title = $res->compTitle();
14755: $title =~ s/\W+/_/g;
14756: if ($title ne '') {
14757: push(@pathitems,$title);
14758: }
14759: }
14760: }
14761: }
14762: }
1.1071 raeburn 14763: if ($showitem) {
14764: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14765: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14766: } else {
14767: my $maptitle = $mapres->compTitle();
14768: $maptitle =~ s/\W+/_/g;
14769: if ($maptitle ne '') {
14770: push(@pathitems,$maptitle);
14771: }
1.1068 raeburn 14772: }
14773: }
14774: }
14775: }
14776: return @pathitems;
14777: }
14778:
14779: =pod
14780:
1.1015 raeburn 14781: =item * &get_turnedin_filepath()
14782:
14783: Determines path in a user's portfolio file for storage of files uploaded
14784: to a specific essayresponse or dropbox item.
14785:
14786: Inputs: 3 required + 1 optional.
14787: $symb is symb for resource, $uname and $udom are for current user (required).
14788: $caller is optional (can be "submission", if routine is called when storing
14789: an upoaded file when "Submit Answer" button was pressed).
14790:
14791: Returns array containing $path and $multiresp.
14792: $path is path in portfolio. $multiresp is 1 if this resource contains more
14793: than one file upload item. Callers of routine should append partid as a
14794: subdirectory to $path in cases where $multiresp is 1.
14795:
14796: Called by: homework/essayresponse.pm and homework/structuretags.pm
14797:
14798: =cut
14799:
14800: sub get_turnedin_filepath {
14801: my ($symb,$uname,$udom,$caller) = @_;
14802: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14803: my $turnindir;
14804: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14805: $turnindir = $userhash{'turnindir'};
14806: my ($path,$multiresp);
14807: if ($turnindir eq '') {
14808: if ($caller eq 'submission') {
14809: $turnindir = &mt('turned in');
14810: $turnindir =~ s/\W+/_/g;
14811: my %newhash = (
14812: 'turnindir' => $turnindir,
14813: );
14814: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14815: }
14816: }
14817: if ($turnindir ne '') {
14818: $path = '/'.$turnindir.'/';
14819: my ($multipart,$turnin,@pathitems);
14820: my $navmap = Apache::lonnavmaps::navmap->new();
14821: if (defined($navmap)) {
14822: my $mapres = $navmap->getResourceByUrl($map);
14823: if (ref($mapres)) {
14824: my $pcslist = $mapres->map_hierarchy();
14825: if ($pcslist ne '') {
14826: foreach my $pc (split(/,/,$pcslist)) {
14827: my $res = $navmap->getByMapPc($pc);
14828: if (ref($res)) {
14829: my $title = $res->compTitle();
14830: $title =~ s/\W+/_/g;
14831: if ($title ne '') {
1.1149 raeburn 14832: if (($pc > 1) && (length($title) > 12)) {
14833: $title = substr($title,0,12);
14834: }
1.1015 raeburn 14835: push(@pathitems,$title);
14836: }
14837: }
14838: }
14839: }
14840: my $maptitle = $mapres->compTitle();
14841: $maptitle =~ s/\W+/_/g;
14842: if ($maptitle ne '') {
1.1149 raeburn 14843: if (length($maptitle) > 12) {
14844: $maptitle = substr($maptitle,0,12);
14845: }
1.1015 raeburn 14846: push(@pathitems,$maptitle);
14847: }
14848: unless ($env{'request.state'} eq 'construct') {
14849: my $res = $navmap->getBySymb($symb);
14850: if (ref($res)) {
14851: my $partlist = $res->parts();
14852: my $totaluploads = 0;
14853: if (ref($partlist) eq 'ARRAY') {
14854: foreach my $part (@{$partlist}) {
14855: my @types = $res->responseType($part);
14856: my @ids = $res->responseIds($part);
14857: for (my $i=0; $i < scalar(@ids); $i++) {
14858: if ($types[$i] eq 'essay') {
14859: my $partid = $part.'_'.$ids[$i];
14860: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14861: $totaluploads ++;
14862: }
14863: }
14864: }
14865: }
14866: if ($totaluploads > 1) {
14867: $multiresp = 1;
14868: }
14869: }
14870: }
14871: }
14872: } else {
14873: return;
14874: }
14875: } else {
14876: return;
14877: }
14878: my $restitle=&Apache::lonnet::gettitle($symb);
14879: $restitle =~ s/\W+/_/g;
14880: if ($restitle eq '') {
14881: $restitle = ($resurl =~ m{/[^/]+$});
14882: if ($restitle eq '') {
14883: $restitle = time;
14884: }
14885: }
1.1149 raeburn 14886: if (length($restitle) > 12) {
14887: $restitle = substr($restitle,0,12);
14888: }
1.1015 raeburn 14889: push(@pathitems,$restitle);
14890: $path .= join('/',@pathitems);
14891: }
14892: return ($path,$multiresp);
14893: }
14894:
14895: =pod
14896:
1.464 albertel 14897: =back
1.41 ng 14898:
1.112 bowersj2 14899: =head1 CSV Upload/Handling functions
1.38 albertel 14900:
1.41 ng 14901: =over 4
14902:
1.648 raeburn 14903: =item * &upfile_store($r)
1.41 ng 14904:
14905: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14906: needs $env{'form.upfile'}
1.41 ng 14907: returns $datatoken to be put into hidden field
14908:
14909: =cut
1.31 albertel 14910:
14911: sub upfile_store {
14912: my $r=shift;
1.258 albertel 14913: $env{'form.upfile'}=~s/\r/\n/gs;
14914: $env{'form.upfile'}=~s/\f/\n/gs;
14915: $env{'form.upfile'}=~s/\n+/\n/gs;
14916: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14917:
1.1299 raeburn 14918: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14919: '_enroll_'.$env{'request.course.id'}.'_'.
14920: time.'_'.$$);
14921: return if ($datatoken eq '');
14922:
1.31 albertel 14923: {
1.158 raeburn 14924: my $datafile = $r->dir_config('lonDaemons').
14925: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14926: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14927: print $fh $env{'form.upfile'};
1.158 raeburn 14928: close($fh);
14929: }
1.31 albertel 14930: }
14931: return $datatoken;
14932: }
14933:
1.56 matthew 14934: =pod
14935:
1.1290 raeburn 14936: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14937:
14938: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14939: $datatoken is the name to assign to the temporary file.
1.258 albertel 14940: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14941:
14942: =cut
1.31 albertel 14943:
14944: sub load_tmp_file {
1.1290 raeburn 14945: my ($r,$datatoken) = @_;
14946: return if ($datatoken eq '');
1.31 albertel 14947: my @studentdata=();
14948: {
1.158 raeburn 14949: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14950: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14951: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14952: @studentdata=<$fh>;
14953: close($fh);
14954: }
1.31 albertel 14955: }
1.258 albertel 14956: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14957: }
14958:
1.1290 raeburn 14959: sub valid_datatoken {
14960: my ($datatoken) = @_;
1.1325 raeburn 14961: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14962: return $datatoken;
14963: }
14964: return;
14965: }
14966:
1.56 matthew 14967: =pod
14968:
1.648 raeburn 14969: =item * &upfile_record_sep()
1.41 ng 14970:
14971: Separate uploaded file into records
14972: returns array of records,
1.258 albertel 14973: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14974:
14975: =cut
1.31 albertel 14976:
14977: sub upfile_record_sep {
1.258 albertel 14978: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14979: } else {
1.248 albertel 14980: my @records;
1.258 albertel 14981: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14982: if ($line=~/^\s*$/) { next; }
14983: push(@records,$line);
14984: }
14985: return @records;
1.31 albertel 14986: }
14987: }
14988:
1.56 matthew 14989: =pod
14990:
1.648 raeburn 14991: =item * &record_sep($record)
1.41 ng 14992:
1.258 albertel 14993: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14994:
14995: =cut
14996:
1.263 www 14997: sub takeleft {
14998: my $index=shift;
14999: return substr('0000'.$index,-4,4);
15000: }
15001:
1.31 albertel 15002: sub record_sep {
15003: my $record=shift;
15004: my %components=();
1.258 albertel 15005: if ($env{'form.upfiletype'} eq 'xml') {
15006: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 15007: my $i=0;
1.356 albertel 15008: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 15009: $field=~s/^(\"|\')//;
15010: $field=~s/(\"|\')$//;
1.263 www 15011: $components{&takeleft($i)}=$field;
1.31 albertel 15012: $i++;
15013: }
1.258 albertel 15014: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 15015: my $i=0;
1.356 albertel 15016: foreach my $field (split(/\t/,$record)) {
1.31 albertel 15017: $field=~s/^(\"|\')//;
15018: $field=~s/(\"|\')$//;
1.263 www 15019: $components{&takeleft($i)}=$field;
1.31 albertel 15020: $i++;
15021: }
15022: } else {
1.561 www 15023: my $separator=',';
1.480 banghart 15024: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 15025: $separator=';';
1.480 banghart 15026: }
1.31 albertel 15027: my $i=0;
1.561 www 15028: # the character we are looking for to indicate the end of a quote or a record
15029: my $looking_for=$separator;
15030: # do not add the characters to the fields
15031: my $ignore=0;
15032: # we just encountered a separator (or the beginning of the record)
15033: my $just_found_separator=1;
15034: # store the field we are working on here
15035: my $field='';
15036: # work our way through all characters in record
15037: foreach my $character ($record=~/(.)/g) {
15038: if ($character eq $looking_for) {
15039: if ($character ne $separator) {
15040: # Found the end of a quote, again looking for separator
15041: $looking_for=$separator;
15042: $ignore=1;
15043: } else {
15044: # Found a separator, store away what we got
15045: $components{&takeleft($i)}=$field;
15046: $i++;
15047: $just_found_separator=1;
15048: $ignore=0;
15049: $field='';
15050: }
15051: next;
15052: }
15053: # single or double quotation marks after a separator indicate beginning of a quote
15054: # we are now looking for the end of the quote and need to ignore separators
15055: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15056: $looking_for=$character;
15057: next;
15058: }
15059: # ignore would be true after we reached the end of a quote
15060: if ($ignore) { next; }
15061: if (($just_found_separator) && ($character=~/\s/)) { next; }
15062: $field.=$character;
15063: $just_found_separator=0;
1.31 albertel 15064: }
1.561 www 15065: # catch the very last entry, since we never encountered the separator
15066: $components{&takeleft($i)}=$field;
1.31 albertel 15067: }
15068: return %components;
15069: }
15070:
1.144 matthew 15071: ######################################################
15072: ######################################################
15073:
1.56 matthew 15074: =pod
15075:
1.648 raeburn 15076: =item * &upfile_select_html()
1.41 ng 15077:
1.144 matthew 15078: Return HTML code to select a file from the users machine and specify
15079: the file type.
1.41 ng 15080:
15081: =cut
15082:
1.144 matthew 15083: ######################################################
15084: ######################################################
1.31 albertel 15085: sub upfile_select_html {
1.144 matthew 15086: my %Types = (
15087: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15088: semisv => &mt('Semicolon separated values'),
1.144 matthew 15089: space => &mt('Space separated'),
15090: tab => &mt('Tabulator separated'),
15091: # xml => &mt('HTML/XML'),
15092: );
15093: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15094: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15095: foreach my $type (sort(keys(%Types))) {
15096: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15097: }
15098: $Str .= "</select>\n";
15099: return $Str;
1.31 albertel 15100: }
15101:
1.301 albertel 15102: sub get_samples {
15103: my ($records,$toget) = @_;
15104: my @samples=({});
15105: my $got=0;
15106: foreach my $rec (@$records) {
15107: my %temp = &record_sep($rec);
15108: if (! grep(/\S/, values(%temp))) { next; }
15109: if (%temp) {
15110: $samples[$got]=\%temp;
15111: $got++;
15112: if ($got == $toget) { last; }
15113: }
15114: }
15115: return \@samples;
15116: }
15117:
1.144 matthew 15118: ######################################################
15119: ######################################################
15120:
1.56 matthew 15121: =pod
15122:
1.648 raeburn 15123: =item * &csv_print_samples($r,$records)
1.41 ng 15124:
15125: Prints a table of sample values from each column uploaded $r is an
15126: Apache Request ref, $records is an arrayref from
15127: &Apache::loncommon::upfile_record_sep
15128:
15129: =cut
15130:
1.144 matthew 15131: ######################################################
15132: ######################################################
1.31 albertel 15133: sub csv_print_samples {
15134: my ($r,$records) = @_;
1.662 bisitz 15135: my $samples = &get_samples($records,5);
1.301 albertel 15136:
1.594 raeburn 15137: $r->print(&mt('Samples').'<br />'.&start_data_table().
15138: &start_data_table_header_row());
1.356 albertel 15139: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15140: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15141: $r->print(&end_data_table_header_row());
1.301 albertel 15142: foreach my $hash (@$samples) {
1.594 raeburn 15143: $r->print(&start_data_table_row());
1.356 albertel 15144: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15145: $r->print('<td>');
1.356 albertel 15146: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15147: $r->print('</td>');
15148: }
1.594 raeburn 15149: $r->print(&end_data_table_row());
1.31 albertel 15150: }
1.594 raeburn 15151: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15152: }
15153:
1.144 matthew 15154: ######################################################
15155: ######################################################
15156:
1.56 matthew 15157: =pod
15158:
1.648 raeburn 15159: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15160:
15161: Prints a table to create associations between values and table columns.
1.144 matthew 15162:
1.41 ng 15163: $r is an Apache Request ref,
15164: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15165: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15166:
15167: =cut
15168:
1.144 matthew 15169: ######################################################
15170: ######################################################
1.31 albertel 15171: sub csv_print_select_table {
15172: my ($r,$records,$d) = @_;
1.301 albertel 15173: my $i=0;
15174: my $samples = &get_samples($records,1);
1.144 matthew 15175: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15176: &start_data_table().&start_data_table_header_row().
1.144 matthew 15177: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15178: '<th>'.&mt('Column').'</th>'.
15179: &end_data_table_header_row()."\n");
1.356 albertel 15180: foreach my $array_ref (@$d) {
15181: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15182: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15183:
1.875 bisitz 15184: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15185: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15186: $r->print('<option value="none"></option>');
1.356 albertel 15187: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15188: $r->print('<option value="'.$sample.'"'.
15189: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15190: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15191: }
1.594 raeburn 15192: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15193: $i++;
15194: }
1.594 raeburn 15195: $r->print(&end_data_table());
1.31 albertel 15196: $i--;
15197: return $i;
15198: }
1.56 matthew 15199:
1.144 matthew 15200: ######################################################
15201: ######################################################
15202:
1.56 matthew 15203: =pod
1.31 albertel 15204:
1.648 raeburn 15205: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15206:
15207: Prints a table of sample values from the upload and can make associate samples to internal names.
15208:
15209: $r is an Apache Request ref,
15210: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15211: $d is an array of 2 element arrays (internal name, displayed name)
15212:
15213: =cut
15214:
1.144 matthew 15215: ######################################################
15216: ######################################################
1.31 albertel 15217: sub csv_samples_select_table {
15218: my ($r,$records,$d) = @_;
15219: my $i=0;
1.144 matthew 15220: #
1.662 bisitz 15221: my $max_samples = 5;
15222: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15223: $r->print(&start_data_table().
15224: &start_data_table_header_row().'<th>'.
15225: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15226: &end_data_table_header_row());
1.301 albertel 15227:
15228: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15229: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15230: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15231: foreach my $option (@$d) {
15232: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15233: $r->print('<option value="'.$value.'"'.
1.253 albertel 15234: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15235: $display.'</option>');
1.31 albertel 15236: }
15237: $r->print('</select></td><td>');
1.662 bisitz 15238: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15239: if (defined($samples->[$line]{$key})) {
15240: $r->print($samples->[$line]{$key}."<br />\n");
15241: }
15242: }
1.594 raeburn 15243: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15244: $i++;
15245: }
1.594 raeburn 15246: $r->print(&end_data_table());
1.31 albertel 15247: $i--;
15248: return($i);
1.115 matthew 15249: }
15250:
1.144 matthew 15251: ######################################################
15252: ######################################################
15253:
1.115 matthew 15254: =pod
15255:
1.648 raeburn 15256: =item * &clean_excel_name($name)
1.115 matthew 15257:
15258: Returns a replacement for $name which does not contain any illegal characters.
15259:
15260: =cut
15261:
1.144 matthew 15262: ######################################################
15263: ######################################################
1.115 matthew 15264: sub clean_excel_name {
15265: my ($name) = @_;
15266: $name =~ s/[:\*\?\/\\]//g;
15267: if (length($name) > 31) {
15268: $name = substr($name,0,31);
15269: }
15270: return $name;
1.25 albertel 15271: }
1.84 albertel 15272:
1.85 albertel 15273: =pod
15274:
1.648 raeburn 15275: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15276:
15277: Returns either 1 or undef
15278:
15279: 1 if the part is to be hidden, undef if it is to be shown
15280:
15281: Arguments are:
15282:
15283: $id the id of the part to be checked
15284: $symb, optional the symb of the resource to check
15285: $udom, optional the domain of the user to check for
15286: $uname, optional the username of the user to check for
15287:
15288: =cut
1.84 albertel 15289:
15290: sub check_if_partid_hidden {
15291: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15292: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15293: $symb,$udom,$uname);
1.141 albertel 15294: my $truth=1;
15295: #if the string starts with !, then the list is the list to show not hide
15296: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15297: my @hiddenlist=split(/,/,$hiddenparts);
15298: foreach my $checkid (@hiddenlist) {
1.141 albertel 15299: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15300: }
1.141 albertel 15301: return !$truth;
1.84 albertel 15302: }
1.127 matthew 15303:
1.138 matthew 15304:
15305: ############################################################
15306: ############################################################
15307:
15308: =pod
15309:
1.157 matthew 15310: =back
15311:
1.138 matthew 15312: =head1 cgi-bin script and graphing routines
15313:
1.157 matthew 15314: =over 4
15315:
1.648 raeburn 15316: =item * &get_cgi_id()
1.138 matthew 15317:
15318: Inputs: none
15319:
15320: Returns an id which can be used to pass environment variables
15321: to various cgi-bin scripts. These environment variables will
15322: be removed from the users environment after a given time by
15323: the routine &Apache::lonnet::transfer_profile_to_env.
15324:
15325: =cut
15326:
15327: ############################################################
15328: ############################################################
1.152 albertel 15329: my $uniq=0;
1.136 matthew 15330: sub get_cgi_id {
1.154 albertel 15331: $uniq=($uniq+1)%100000;
1.280 albertel 15332: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15333: }
15334:
1.127 matthew 15335: ############################################################
15336: ############################################################
15337:
15338: =pod
15339:
1.648 raeburn 15340: =item * &DrawBarGraph()
1.127 matthew 15341:
1.138 matthew 15342: Facilitates the plotting of data in a (stacked) bar graph.
15343: Puts plot definition data into the users environment in order for
15344: graph.png to plot it. Returns an <img> tag for the plot.
15345: The bars on the plot are labeled '1','2',...,'n'.
15346:
15347: Inputs:
15348:
15349: =over 4
15350:
15351: =item $Title: string, the title of the plot
15352:
15353: =item $xlabel: string, text describing the X-axis of the plot
15354:
15355: =item $ylabel: string, text describing the Y-axis of the plot
15356:
15357: =item $Max: scalar, the maximum Y value to use in the plot
15358: If $Max is < any data point, the graph will not be rendered.
15359:
1.140 matthew 15360: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15361: they are plotted. If undefined, default values will be used.
15362:
1.178 matthew 15363: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15364:
1.138 matthew 15365: =item @Values: An array of array references. Each array reference holds data
15366: to be plotted in a stacked bar chart.
15367:
1.239 matthew 15368: =item If the final element of @Values is a hash reference the key/value
15369: pairs will be added to the graph definition.
15370:
1.138 matthew 15371: =back
15372:
15373: Returns:
15374:
15375: An <img> tag which references graph.png and the appropriate identifying
15376: information for the plot.
15377:
1.127 matthew 15378: =cut
15379:
15380: ############################################################
15381: ############################################################
1.134 matthew 15382: sub DrawBarGraph {
1.178 matthew 15383: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15384: #
15385: if (! defined($colors)) {
15386: $colors = ['#33ff00',
15387: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15388: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15389: ];
15390: }
1.228 matthew 15391: my $extra_settings = {};
15392: if (ref($Values[-1]) eq 'HASH') {
15393: $extra_settings = pop(@Values);
15394: }
1.127 matthew 15395: #
1.136 matthew 15396: my $identifier = &get_cgi_id();
15397: my $id = 'cgi.'.$identifier;
1.129 matthew 15398: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15399: return '';
15400: }
1.225 matthew 15401: #
15402: my @Labels;
15403: if (defined($labels)) {
15404: @Labels = @$labels;
15405: } else {
15406: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15407: push(@Labels,$i+1);
1.225 matthew 15408: }
15409: }
15410: #
1.129 matthew 15411: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15412: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15413: my %ValuesHash;
15414: my $NumSets=1;
15415: foreach my $array (@Values) {
15416: next if (! ref($array));
1.136 matthew 15417: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15418: join(',',@$array);
1.129 matthew 15419: }
1.127 matthew 15420: #
1.136 matthew 15421: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15422: if ($NumBars < 3) {
15423: $width = 120+$NumBars*32;
1.220 matthew 15424: $xskip = 1;
1.225 matthew 15425: $bar_width = 30;
15426: } elsif ($NumBars < 5) {
15427: $width = 120+$NumBars*20;
15428: $xskip = 1;
15429: $bar_width = 20;
1.220 matthew 15430: } elsif ($NumBars < 10) {
1.136 matthew 15431: $width = 120+$NumBars*15;
15432: $xskip = 1;
15433: $bar_width = 15;
15434: } elsif ($NumBars <= 25) {
15435: $width = 120+$NumBars*11;
15436: $xskip = 5;
15437: $bar_width = 8;
15438: } elsif ($NumBars <= 50) {
15439: $width = 120+$NumBars*8;
15440: $xskip = 5;
15441: $bar_width = 4;
15442: } else {
15443: $width = 120+$NumBars*8;
15444: $xskip = 5;
15445: $bar_width = 4;
15446: }
15447: #
1.137 matthew 15448: $Max = 1 if ($Max < 1);
15449: if ( int($Max) < $Max ) {
15450: $Max++;
15451: $Max = int($Max);
15452: }
1.127 matthew 15453: $Title = '' if (! defined($Title));
15454: $xlabel = '' if (! defined($xlabel));
15455: $ylabel = '' if (! defined($ylabel));
1.369 www 15456: $ValuesHash{$id.'.title'} = &escape($Title);
15457: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15458: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15459: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15460: $ValuesHash{$id.'.NumBars'} = $NumBars;
15461: $ValuesHash{$id.'.NumSets'} = $NumSets;
15462: $ValuesHash{$id.'.PlotType'} = 'bar';
15463: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15464: $ValuesHash{$id.'.height'} = $height;
15465: $ValuesHash{$id.'.width'} = $width;
15466: $ValuesHash{$id.'.xskip'} = $xskip;
15467: $ValuesHash{$id.'.bar_width'} = $bar_width;
15468: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15469: #
1.228 matthew 15470: # Deal with other parameters
15471: while (my ($key,$value) = each(%$extra_settings)) {
15472: $ValuesHash{$id.'.'.$key} = $value;
15473: }
15474: #
1.646 raeburn 15475: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15476: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15477: }
15478:
15479: ############################################################
15480: ############################################################
15481:
15482: =pod
15483:
1.648 raeburn 15484: =item * &DrawXYGraph()
1.137 matthew 15485:
1.138 matthew 15486: Facilitates the plotting of data in an XY graph.
15487: Puts plot definition data into the users environment in order for
15488: graph.png to plot it. Returns an <img> tag for the plot.
15489:
15490: Inputs:
15491:
15492: =over 4
15493:
15494: =item $Title: string, the title of the plot
15495:
15496: =item $xlabel: string, text describing the X-axis of the plot
15497:
15498: =item $ylabel: string, text describing the Y-axis of the plot
15499:
15500: =item $Max: scalar, the maximum Y value to use in the plot
15501: If $Max is < any data point, the graph will not be rendered.
15502:
15503: =item $colors: Array ref containing the hex color codes for the data to be
15504: plotted in. If undefined, default values will be used.
15505:
15506: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15507:
15508: =item $Ydata: Array ref containing Array refs.
1.185 www 15509: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15510:
15511: =item %Values: hash indicating or overriding any default values which are
15512: passed to graph.png.
15513: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15514:
15515: =back
15516:
15517: Returns:
15518:
15519: An <img> tag which references graph.png and the appropriate identifying
15520: information for the plot.
15521:
1.137 matthew 15522: =cut
15523:
15524: ############################################################
15525: ############################################################
15526: sub DrawXYGraph {
15527: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15528: #
15529: # Create the identifier for the graph
15530: my $identifier = &get_cgi_id();
15531: my $id = 'cgi.'.$identifier;
15532: #
15533: $Title = '' if (! defined($Title));
15534: $xlabel = '' if (! defined($xlabel));
15535: $ylabel = '' if (! defined($ylabel));
15536: my %ValuesHash =
15537: (
1.369 www 15538: $id.'.title' => &escape($Title),
15539: $id.'.xlabel' => &escape($xlabel),
15540: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15541: $id.'.y_max_value'=> $Max,
15542: $id.'.labels' => join(',',@$Xlabels),
15543: $id.'.PlotType' => 'XY',
15544: );
15545: #
15546: if (defined($colors) && ref($colors) eq 'ARRAY') {
15547: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15548: }
15549: #
15550: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15551: return '';
15552: }
15553: my $NumSets=1;
1.138 matthew 15554: foreach my $array (@{$Ydata}){
1.137 matthew 15555: next if (! ref($array));
15556: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15557: }
1.138 matthew 15558: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15559: #
15560: # Deal with other parameters
15561: while (my ($key,$value) = each(%Values)) {
15562: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15563: }
15564: #
1.646 raeburn 15565: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15566: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15567: }
15568:
15569: ############################################################
15570: ############################################################
15571:
15572: =pod
15573:
1.648 raeburn 15574: =item * &DrawXYYGraph()
1.138 matthew 15575:
15576: Facilitates the plotting of data in an XY graph with two Y axes.
15577: Puts plot definition data into the users environment in order for
15578: graph.png to plot it. Returns an <img> tag for the plot.
15579:
15580: Inputs:
15581:
15582: =over 4
15583:
15584: =item $Title: string, the title of the plot
15585:
15586: =item $xlabel: string, text describing the X-axis of the plot
15587:
15588: =item $ylabel: string, text describing the Y-axis of the plot
15589:
15590: =item $colors: Array ref containing the hex color codes for the data to be
15591: plotted in. If undefined, default values will be used.
15592:
15593: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15594:
15595: =item $Ydata1: The first data set
15596:
15597: =item $Min1: The minimum value of the left Y-axis
15598:
15599: =item $Max1: The maximum value of the left Y-axis
15600:
15601: =item $Ydata2: The second data set
15602:
15603: =item $Min2: The minimum value of the right Y-axis
15604:
15605: =item $Max2: The maximum value of the left Y-axis
15606:
15607: =item %Values: hash indicating or overriding any default values which are
15608: passed to graph.png.
15609: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15610:
15611: =back
15612:
15613: Returns:
15614:
15615: An <img> tag which references graph.png and the appropriate identifying
15616: information for the plot.
1.136 matthew 15617:
15618: =cut
15619:
15620: ############################################################
15621: ############################################################
1.137 matthew 15622: sub DrawXYYGraph {
15623: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15624: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15625: #
15626: # Create the identifier for the graph
15627: my $identifier = &get_cgi_id();
15628: my $id = 'cgi.'.$identifier;
15629: #
15630: $Title = '' if (! defined($Title));
15631: $xlabel = '' if (! defined($xlabel));
15632: $ylabel = '' if (! defined($ylabel));
15633: my %ValuesHash =
15634: (
1.369 www 15635: $id.'.title' => &escape($Title),
15636: $id.'.xlabel' => &escape($xlabel),
15637: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15638: $id.'.labels' => join(',',@$Xlabels),
15639: $id.'.PlotType' => 'XY',
15640: $id.'.NumSets' => 2,
1.137 matthew 15641: $id.'.two_axes' => 1,
15642: $id.'.y1_max_value' => $Max1,
15643: $id.'.y1_min_value' => $Min1,
15644: $id.'.y2_max_value' => $Max2,
15645: $id.'.y2_min_value' => $Min2,
1.136 matthew 15646: );
15647: #
1.137 matthew 15648: if (defined($colors) && ref($colors) eq 'ARRAY') {
15649: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15650: }
15651: #
15652: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15653: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15654: return '';
15655: }
15656: my $NumSets=1;
1.137 matthew 15657: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15658: next if (! ref($array));
15659: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15660: }
15661: #
15662: # Deal with other parameters
15663: while (my ($key,$value) = each(%Values)) {
15664: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15665: }
15666: #
1.646 raeburn 15667: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15668: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15669: }
15670:
15671: ############################################################
15672: ############################################################
15673:
15674: =pod
15675:
1.157 matthew 15676: =back
15677:
1.139 matthew 15678: =head1 Statistics helper routines?
15679:
15680: Bad place for them but what the hell.
15681:
1.157 matthew 15682: =over 4
15683:
1.648 raeburn 15684: =item * &chartlink()
1.139 matthew 15685:
15686: Returns a link to the chart for a specific student.
15687:
15688: Inputs:
15689:
15690: =over 4
15691:
15692: =item $linktext: The text of the link
15693:
15694: =item $sname: The students username
15695:
15696: =item $sdomain: The students domain
15697:
15698: =back
15699:
1.157 matthew 15700: =back
15701:
1.139 matthew 15702: =cut
15703:
15704: ############################################################
15705: ############################################################
15706: sub chartlink {
15707: my ($linktext, $sname, $sdomain) = @_;
15708: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15709: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15710: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15711: '">'.$linktext.'</a>';
1.153 matthew 15712: }
15713:
15714: #######################################################
15715: #######################################################
15716:
15717: =pod
15718:
15719: =head1 Course Environment Routines
1.157 matthew 15720:
15721: =over 4
1.153 matthew 15722:
1.648 raeburn 15723: =item * &restore_course_settings()
1.153 matthew 15724:
1.648 raeburn 15725: =item * &store_course_settings()
1.153 matthew 15726:
15727: Restores/Store indicated form parameters from the course environment.
15728: Will not overwrite existing values of the form parameters.
15729:
15730: Inputs:
15731: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15732:
15733: a hash ref describing the data to be stored. For example:
15734:
15735: %Save_Parameters = ('Status' => 'scalar',
15736: 'chartoutputmode' => 'scalar',
15737: 'chartoutputdata' => 'scalar',
15738: 'Section' => 'array',
1.373 raeburn 15739: 'Group' => 'array',
1.153 matthew 15740: 'StudentData' => 'array',
15741: 'Maps' => 'array');
15742:
15743: Returns: both routines return nothing
15744:
1.631 raeburn 15745: =back
15746:
1.153 matthew 15747: =cut
15748:
15749: #######################################################
15750: #######################################################
15751: sub store_course_settings {
1.496 albertel 15752: return &store_settings($env{'request.course.id'},@_);
15753: }
15754:
15755: sub store_settings {
1.153 matthew 15756: # save to the environment
15757: # appenv the same items, just to be safe
1.300 albertel 15758: my $udom = $env{'user.domain'};
15759: my $uname = $env{'user.name'};
1.496 albertel 15760: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15761: my %SaveHash;
15762: my %AppHash;
15763: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15764: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15765: my $envname = 'environment.'.$basename;
1.258 albertel 15766: if (exists($env{'form.'.$setting})) {
1.153 matthew 15767: # Save this value away
15768: if ($type eq 'scalar' &&
1.258 albertel 15769: (! exists($env{$envname}) ||
15770: $env{$envname} ne $env{'form.'.$setting})) {
15771: $SaveHash{$basename} = $env{'form.'.$setting};
15772: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15773: } elsif ($type eq 'array') {
15774: my $stored_form;
1.258 albertel 15775: if (ref($env{'form.'.$setting})) {
1.153 matthew 15776: $stored_form = join(',',
15777: map {
1.369 www 15778: &escape($_);
1.258 albertel 15779: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15780: } else {
15781: $stored_form =
1.369 www 15782: &escape($env{'form.'.$setting});
1.153 matthew 15783: }
15784: # Determine if the array contents are the same.
1.258 albertel 15785: if ($stored_form ne $env{$envname}) {
1.153 matthew 15786: $SaveHash{$basename} = $stored_form;
15787: $AppHash{$envname} = $stored_form;
15788: }
15789: }
15790: }
15791: }
15792: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15793: $udom,$uname);
1.153 matthew 15794: if ($put_result !~ /^(ok|delayed)/) {
15795: &Apache::lonnet::logthis('unable to save form parameters, '.
15796: 'got error:'.$put_result);
15797: }
15798: # Make sure these settings stick around in this session, too
1.646 raeburn 15799: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15800: return;
15801: }
15802:
15803: sub restore_course_settings {
1.499 albertel 15804: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15805: }
15806:
15807: sub restore_settings {
15808: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15809: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15810: next if (exists($env{'form.'.$setting}));
1.496 albertel 15811: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15812: '.'.$setting;
1.258 albertel 15813: if (exists($env{$envname})) {
1.153 matthew 15814: if ($type eq 'scalar') {
1.258 albertel 15815: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15816: } elsif ($type eq 'array') {
1.258 albertel 15817: $env{'form.'.$setting} = [
1.153 matthew 15818: map {
1.369 www 15819: &unescape($_);
1.258 albertel 15820: } split(',',$env{$envname})
1.153 matthew 15821: ];
15822: }
15823: }
15824: }
1.127 matthew 15825: }
15826:
1.618 raeburn 15827: #######################################################
15828: #######################################################
15829:
15830: =pod
15831:
15832: =head1 Domain E-mail Routines
15833:
15834: =over 4
15835:
1.648 raeburn 15836: =item * &build_recipient_list()
1.618 raeburn 15837:
1.1144 raeburn 15838: Build recipient lists for following types of e-mail:
1.766 raeburn 15839: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15840: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15841: module change checking, student/employee ID conflict checks, as
15842: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15843: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15844:
15845: Inputs:
1.619 raeburn 15846: defmail (scalar - email address of default recipient),
1.1144 raeburn 15847: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15848: requestsmail, updatesmail, or idconflictsmail).
15849:
1.619 raeburn 15850: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15851:
1.619 raeburn 15852: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15853: i.e., predates configuration by DC via domainprefs.pm
15854:
15855: $requname username of requester (if mailing type is helpdeskmail)
15856:
15857: $requdom domain of requester (if mailing type is helpdeskmail)
15858:
15859: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15860:
1.618 raeburn 15861:
1.655 raeburn 15862: Returns: comma separated list of addresses to which to send e-mail.
15863:
15864: =back
1.618 raeburn 15865:
15866: =cut
15867:
15868: ############################################################
15869: ############################################################
15870: sub build_recipient_list {
1.1297 raeburn 15871: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15872: my @recipients;
1.1270 raeburn 15873: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15874: my %domconfig =
1.1270 raeburn 15875: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15876: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15877: if (exists($domconfig{'contacts'}{$mailing})) {
15878: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15879: my @contacts = ('adminemail','supportemail');
15880: foreach my $item (@contacts) {
15881: if ($domconfig{'contacts'}{$mailing}{$item}) {
15882: my $addr = $domconfig{'contacts'}{$item};
15883: if (!grep(/^\Q$addr\E$/,@recipients)) {
15884: push(@recipients,$addr);
15885: }
1.619 raeburn 15886: }
1.1270 raeburn 15887: }
15888: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15889: if ($mailing eq 'helpdeskmail') {
15890: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15891: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15892: my @ok_bccs;
15893: foreach my $bcc (@bccs) {
15894: $bcc =~ s/^\s+//g;
15895: $bcc =~ s/\s+$//g;
15896: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15897: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15898: push(@ok_bccs,$bcc);
15899: }
15900: }
15901: }
15902: if (@ok_bccs > 0) {
15903: $allbcc = join(', ',@ok_bccs);
15904: }
15905: }
15906: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15907: }
15908: }
1.766 raeburn 15909: } elsif ($origmail ne '') {
1.1270 raeburn 15910: $lastresort = $origmail;
1.618 raeburn 15911: }
1.1297 raeburn 15912: if ($mailing eq 'helpdeskmail') {
15913: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15914: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15915: my ($inststatus,$inststatus_checked);
15916: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15917: ($env{'user.domain'} ne 'public')) {
15918: $inststatus_checked = 1;
15919: $inststatus = $env{'environment.inststatus'};
15920: }
15921: unless ($inststatus_checked) {
15922: if (($requname ne '') && ($requdom ne '')) {
15923: if (($requname =~ /^$match_username$/) &&
15924: ($requdom =~ /^$match_domain$/) &&
15925: (&Apache::lonnet::domain($requdom))) {
15926: my $requhome = &Apache::lonnet::homeserver($requname,
15927: $requdom);
15928: unless ($requhome eq 'no_host') {
15929: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15930: $inststatus = $userenv{'inststatus'};
15931: $inststatus_checked = 1;
15932: }
15933: }
15934: }
15935: }
15936: unless ($inststatus_checked) {
15937: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15938: my %srch = (srchby => 'email',
15939: srchdomain => $defdom,
15940: srchterm => $reqemail,
15941: srchtype => 'exact');
15942: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15943: foreach my $uname (keys(%srch_results)) {
15944: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15945: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15946: $inststatus_checked = 1;
15947: last;
15948: }
15949: }
15950: unless ($inststatus_checked) {
15951: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15952: if ($dirsrchres eq 'ok') {
15953: foreach my $uname (keys(%srch_results)) {
15954: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15955: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15956: $inststatus_checked = 1;
15957: last;
15958: }
15959: }
15960: }
15961: }
15962: }
15963: }
15964: if ($inststatus ne '') {
15965: foreach my $status (split(/\:/,$inststatus)) {
15966: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15967: my @contacts = ('adminemail','supportemail');
15968: foreach my $item (@contacts) {
15969: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15970: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15971: if (!grep(/^\Q$addr\E$/,@recipients)) {
15972: push(@recipients,$addr);
15973: }
15974: }
15975: }
15976: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15977: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15978: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15979: my @ok_bccs;
15980: foreach my $bcc (@bccs) {
15981: $bcc =~ s/^\s+//g;
15982: $bcc =~ s/\s+$//g;
15983: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15984: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15985: push(@ok_bccs,$bcc);
15986: }
15987: }
15988: }
15989: if (@ok_bccs > 0) {
15990: $allbcc = join(', ',@ok_bccs);
15991: }
15992: }
15993: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15994: last;
15995: }
15996: }
15997: }
15998: }
15999: }
1.619 raeburn 16000: } elsif ($origmail ne '') {
1.1270 raeburn 16001: $lastresort = $origmail;
16002: }
1.1297 raeburn 16003: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 16004: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
16005: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
16006: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
16007: my %what = (
16008: perlvar => 1,
16009: );
16010: my $primary = &Apache::lonnet::domain($defdom,'primary');
16011: if ($primary) {
16012: my $gotaddr;
16013: my ($result,$returnhash) =
16014: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
16015: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
16016: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
16017: $lastresort = $returnhash->{'lonSupportEMail'};
16018: $gotaddr = 1;
16019: }
16020: }
16021: unless ($gotaddr) {
16022: my $uintdom = &Apache::lonnet::internet_dom($primary);
16023: my $intdom = &Apache::lonnet::internet_dom($lonhost);
16024: unless ($uintdom eq $intdom) {
16025: my %domconfig =
16026: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
16027: if (ref($domconfig{'contacts'}) eq 'HASH') {
16028: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
16029: my @contacts = ('adminemail','supportemail');
16030: foreach my $item (@contacts) {
16031: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
16032: my $addr = $domconfig{'contacts'}{$item};
16033: if (!grep(/^\Q$addr\E$/,@recipients)) {
16034: push(@recipients,$addr);
16035: }
16036: }
16037: }
16038: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16039: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16040: }
16041: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16042: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16043: my @ok_bccs;
16044: foreach my $bcc (@bccs) {
16045: $bcc =~ s/^\s+//g;
16046: $bcc =~ s/\s+$//g;
16047: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16048: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16049: push(@ok_bccs,$bcc);
16050: }
16051: }
16052: }
16053: if (@ok_bccs > 0) {
16054: $allbcc = join(', ',@ok_bccs);
16055: }
16056: }
16057: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16058: }
16059: }
16060: }
16061: }
16062: }
16063: }
1.618 raeburn 16064: }
1.688 raeburn 16065: if (defined($defmail)) {
16066: if ($defmail ne '') {
16067: push(@recipients,$defmail);
16068: }
1.618 raeburn 16069: }
16070: if ($otheremails) {
1.619 raeburn 16071: my @others;
16072: if ($otheremails =~ /,/) {
16073: @others = split(/,/,$otheremails);
1.618 raeburn 16074: } else {
1.619 raeburn 16075: push(@others,$otheremails);
16076: }
16077: foreach my $addr (@others) {
16078: if (!grep(/^\Q$addr\E$/,@recipients)) {
16079: push(@recipients,$addr);
16080: }
1.618 raeburn 16081: }
16082: }
1.1298 raeburn 16083: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16084: if ((!@recipients) && ($lastresort ne '')) {
16085: push(@recipients,$lastresort);
16086: }
16087: } elsif ($lastresort ne '') {
16088: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16089: push(@recipients,$lastresort);
16090: }
16091: }
1.1271 raeburn 16092: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16093: if (wantarray) {
16094: return ($recipientlist,$allbcc,$addtext);
16095: } else {
16096: return $recipientlist;
16097: }
1.618 raeburn 16098: }
16099:
1.127 matthew 16100: ############################################################
16101: ############################################################
1.154 albertel 16102:
1.655 raeburn 16103: =pod
16104:
1.1224 musolffc 16105: =over 4
16106:
1.1223 musolffc 16107: =item * &mime_email()
16108:
16109: Sends an email with a possible attachment
16110:
16111: Inputs:
16112:
16113: =over 4
16114:
16115: from - Sender's email address
16116:
1.1343 raeburn 16117: replyto - Reply-To email address
16118:
1.1223 musolffc 16119: to - Email address of recipient
16120:
16121: subject - Subject of email
16122:
16123: body - Body of email
16124:
16125: cc_string - Carbon copy email address
16126:
16127: bcc - Blind carbon copy email address
16128:
16129: attachment_path - Path of file to be attached
16130:
16131: file_name - Name of file to be attached
16132:
16133: attachment_text - The body of an attachment of type "TEXT"
16134:
16135: =back
16136:
16137: =back
16138:
16139: =cut
16140:
16141: ############################################################
16142: ############################################################
16143:
16144: sub mime_email {
1.1343 raeburn 16145: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16146: $file_name,$attachment_text) = @_;
16147:
1.1223 musolffc 16148: my $msg = MIME::Lite->new(
16149: From => $from,
16150: To => $to,
16151: Subject => $subject,
16152: Type =>'TEXT',
16153: Data => $body,
16154: );
1.1343 raeburn 16155: if ($replyto ne '') {
16156: $msg->add("Reply-To" => $replyto);
16157: }
1.1223 musolffc 16158: if ($cc_string ne '') {
16159: $msg->add("Cc" => $cc_string);
16160: }
16161: if ($bcc ne '') {
16162: $msg->add("Bcc" => $bcc);
16163: }
16164: $msg->attr("content-type" => "text/plain");
16165: $msg->attr("content-type.charset" => "UTF-8");
16166: # Attach file if given
16167: if ($attachment_path) {
16168: unless ($file_name) {
16169: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16170: }
16171: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16172: $msg->attach(Type => $type,
16173: Path => $attachment_path,
16174: Filename => $file_name
16175: );
16176: # Otherwise attach text if given
16177: } elsif ($attachment_text) {
16178: $msg->attach(Type => 'TEXT',
16179: Data => $attachment_text);
16180: }
16181: # Send it
16182: $msg->send('sendmail');
16183: }
16184:
16185: ############################################################
16186: ############################################################
16187:
16188: =pod
16189:
1.655 raeburn 16190: =head1 Course Catalog Routines
16191:
16192: =over 4
16193:
16194: =item * &gather_categories()
16195:
16196: Converts category definitions - keys of categories hash stored in
16197: coursecategories in configuration.db on the primary library server in a
16198: domain - to an array. Also generates javascript and idx hash used to
16199: generate Domain Coordinator interface for editing Course Categories.
16200:
16201: Inputs:
1.663 raeburn 16202:
1.655 raeburn 16203: categories (reference to hash of category definitions).
1.663 raeburn 16204:
1.655 raeburn 16205: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16206: categories and subcategories).
1.663 raeburn 16207:
1.655 raeburn 16208: idx (reference to hash of counters used in Domain Coordinator interface for
16209: editing Course Categories).
1.663 raeburn 16210:
1.655 raeburn 16211: jsarray (reference to array of categories used to create Javascript arrays for
16212: Domain Coordinator interface for editing Course Categories).
16213:
16214: Returns: nothing
16215:
16216: Side effects: populates cats, idx and jsarray.
16217:
16218: =cut
16219:
16220: sub gather_categories {
16221: my ($categories,$cats,$idx,$jsarray) = @_;
16222: my %counters;
16223: my $num = 0;
16224: foreach my $item (keys(%{$categories})) {
16225: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16226: if ($container eq '' && $depth == 0) {
16227: $cats->[$depth][$categories->{$item}] = $cat;
16228: } else {
16229: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16230: }
16231: my ($escitem,$tail) = split(/:/,$item,2);
16232: if ($counters{$tail} eq '') {
16233: $counters{$tail} = $num;
16234: $num ++;
16235: }
16236: if (ref($idx) eq 'HASH') {
16237: $idx->{$item} = $counters{$tail};
16238: }
16239: if (ref($jsarray) eq 'ARRAY') {
16240: push(@{$jsarray->[$counters{$tail}]},$item);
16241: }
16242: }
16243: return;
16244: }
16245:
16246: =pod
16247:
16248: =item * &extract_categories()
16249:
16250: Used to generate breadcrumb trails for course categories.
16251:
16252: Inputs:
1.663 raeburn 16253:
1.655 raeburn 16254: categories (reference to hash of category definitions).
1.663 raeburn 16255:
1.655 raeburn 16256: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16257: categories and subcategories).
1.663 raeburn 16258:
1.655 raeburn 16259: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16260:
1.655 raeburn 16261: allitems (reference to hash - key is category key
16262: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16263:
1.655 raeburn 16264: idx (reference to hash of counters used in Domain Coordinator interface for
16265: editing Course Categories).
1.663 raeburn 16266:
1.655 raeburn 16267: jsarray (reference to array of categories used to create Javascript arrays for
16268: Domain Coordinator interface for editing Course Categories).
16269:
1.665 raeburn 16270: subcats (reference to hash of arrays containing all subcategories within each
16271: category, -recursive)
16272:
1.1321 raeburn 16273: maxd (reference to hash used to hold max depth for all top-level categories).
16274:
1.655 raeburn 16275: Returns: nothing
16276:
16277: Side effects: populates trails and allitems hash references.
16278:
16279: =cut
16280:
16281: sub extract_categories {
1.1321 raeburn 16282: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16283: if (ref($categories) eq 'HASH') {
16284: &gather_categories($categories,$cats,$idx,$jsarray);
16285: if (ref($cats->[0]) eq 'ARRAY') {
16286: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16287: my $name = $cats->[0][$i];
16288: my $item = &escape($name).'::0';
16289: my $trailstr;
16290: if ($name eq 'instcode') {
16291: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16292: } elsif ($name eq 'communities') {
16293: $trailstr = &mt('Communities');
1.1239 raeburn 16294: } elsif ($name eq 'placement') {
16295: $trailstr = &mt('Placement Tests');
1.655 raeburn 16296: } else {
16297: $trailstr = $name;
16298: }
16299: if ($allitems->{$item} eq '') {
16300: push(@{$trails},$trailstr);
16301: $allitems->{$item} = scalar(@{$trails})-1;
16302: }
16303: my @parents = ($name);
16304: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16305: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16306: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16307: if (ref($subcats) eq 'HASH') {
16308: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16309: }
1.1321 raeburn 16310: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16311: }
16312: } else {
16313: if (ref($subcats) eq 'HASH') {
16314: $subcats->{$item} = [];
1.655 raeburn 16315: }
1.1321 raeburn 16316: if (ref($maxd) eq 'HASH') {
16317: $maxd->{$name} = 1;
16318: }
1.655 raeburn 16319: }
16320: }
16321: }
16322: }
16323: return;
16324: }
16325:
16326: =pod
16327:
1.1162 raeburn 16328: =item * &recurse_categories()
1.655 raeburn 16329:
16330: Recursively used to generate breadcrumb trails for course categories.
16331:
16332: Inputs:
1.663 raeburn 16333:
1.655 raeburn 16334: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16335: categories and subcategories).
1.663 raeburn 16336:
1.655 raeburn 16337: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16338:
16339: category (current course category, for which breadcrumb trail is being generated).
16340:
16341: trails (reference to array of breadcrumb trails for each category).
16342:
1.655 raeburn 16343: allitems (reference to hash - key is category key
16344: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16345:
1.655 raeburn 16346: parents (array containing containers directories for current category,
16347: back to top level).
16348:
16349: Returns: nothing
16350:
16351: Side effects: populates trails and allitems hash references
16352:
16353: =cut
16354:
16355: sub recurse_categories {
1.1321 raeburn 16356: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16357: my $shallower = $depth - 1;
16358: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16359: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16360: my $name = $cats->[$depth]{$category}[$k];
16361: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16362: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16363: if ($allitems->{$item} eq '') {
16364: push(@{$trails},$trailstr);
16365: $allitems->{$item} = scalar(@{$trails})-1;
16366: }
16367: my $deeper = $depth+1;
16368: push(@{$parents},$category);
1.665 raeburn 16369: if (ref($subcats) eq 'HASH') {
16370: my $subcat = &escape($name).':'.$category.':'.$depth;
16371: for (my $j=@{$parents}; $j>=0; $j--) {
16372: my $higher;
16373: if ($j > 0) {
16374: $higher = &escape($parents->[$j]).':'.
16375: &escape($parents->[$j-1]).':'.$j;
16376: } else {
16377: $higher = &escape($parents->[$j]).'::'.$j;
16378: }
16379: push(@{$subcats->{$higher}},$subcat);
16380: }
16381: }
16382: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16383: $subcats,$maxd);
1.655 raeburn 16384: pop(@{$parents});
16385: }
16386: } else {
16387: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16388: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16389: if ($allitems->{$item} eq '') {
16390: push(@{$trails},$trailstr);
16391: $allitems->{$item} = scalar(@{$trails})-1;
16392: }
1.1321 raeburn 16393: if (ref($maxd) eq 'HASH') {
16394: if ($depth > $maxd->{$parents->[0]}) {
16395: $maxd->{$parents->[0]} = $depth;
16396: }
16397: }
1.655 raeburn 16398: }
16399: return;
16400: }
16401:
1.663 raeburn 16402: =pod
16403:
1.1162 raeburn 16404: =item * &assign_categories_table()
1.663 raeburn 16405:
16406: Create a datatable for display of hierarchical categories in a domain,
16407: with checkboxes to allow a course to be categorized.
16408:
16409: Inputs:
16410:
16411: cathash - reference to hash of categories defined for the domain (from
16412: configuration.db)
16413:
16414: currcat - scalar with an & separated list of categories assigned to a course.
16415:
1.919 raeburn 16416: type - scalar contains course type (Course or Community).
16417:
1.1260 raeburn 16418: disabled - scalar (optional) contains disabled="disabled" if input elements are
16419: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16420:
1.663 raeburn 16421: Returns: $output (markup to be displayed)
16422:
16423: =cut
16424:
16425: sub assign_categories_table {
1.1259 raeburn 16426: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16427: my $output;
16428: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16429: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16430: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16431: $maxdepth = scalar(@cats);
16432: if (@cats > 0) {
16433: my $itemcount = 0;
16434: if (ref($cats[0]) eq 'ARRAY') {
16435: my @currcategories;
16436: if ($currcat ne '') {
16437: @currcategories = split('&',$currcat);
16438: }
1.919 raeburn 16439: my $table;
1.663 raeburn 16440: for (my $i=0; $i<@{$cats[0]}; $i++) {
16441: my $parent = $cats[0][$i];
1.919 raeburn 16442: next if ($parent eq 'instcode');
16443: if ($type eq 'Community') {
16444: next unless ($parent eq 'communities');
1.1239 raeburn 16445: } elsif ($type eq 'Placement') {
16446: next unless ($parent eq 'placement');
1.919 raeburn 16447: } else {
1.1239 raeburn 16448: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16449: }
1.663 raeburn 16450: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16451: my $item = &escape($parent).'::0';
16452: my $checked = '';
16453: if (@currcategories > 0) {
16454: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16455: $checked = ' checked="checked"';
1.663 raeburn 16456: }
16457: }
1.919 raeburn 16458: my $parent_title = $parent;
16459: if ($parent eq 'communities') {
16460: $parent_title = &mt('Communities');
1.1239 raeburn 16461: } elsif ($parent eq 'placement') {
16462: $parent_title = &mt('Placement Tests');
1.919 raeburn 16463: }
16464: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16465: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16466: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16467: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16468: my $depth = 1;
16469: push(@path,$parent);
1.1259 raeburn 16470: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16471: pop(@path);
1.919 raeburn 16472: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16473: $itemcount ++;
16474: }
1.919 raeburn 16475: if ($itemcount) {
16476: $output = &Apache::loncommon::start_data_table().
16477: $table.
16478: &Apache::loncommon::end_data_table();
16479: }
1.663 raeburn 16480: }
16481: }
16482: }
16483: return $output;
16484: }
16485:
16486: =pod
16487:
1.1162 raeburn 16488: =item * &assign_category_rows()
1.663 raeburn 16489:
16490: Create a datatable row for display of nested categories in a domain,
16491: with checkboxes to allow a course to be categorized,called recursively.
16492:
16493: Inputs:
16494:
16495: itemcount - track row number for alternating colors
16496:
16497: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16498: categories and subcategories.
16499:
16500: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16501:
16502: parent - parent of current category item
16503:
16504: path - Array containing all categories back up through the hierarchy from the
16505: current category to the top level.
16506:
16507: currcategories - reference to array of current categories assigned to the course
16508:
1.1260 raeburn 16509: disabled - scalar (optional) contains disabled="disabled" if input elements are
16510: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16511:
1.663 raeburn 16512: Returns: $output (markup to be displayed).
16513:
16514: =cut
16515:
16516: sub assign_category_rows {
1.1259 raeburn 16517: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16518: my ($text,$name,$item,$chgstr);
16519: if (ref($cats) eq 'ARRAY') {
16520: my $maxdepth = scalar(@{$cats});
16521: if (ref($cats->[$depth]) eq 'HASH') {
16522: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16523: my $numchildren = @{$cats->[$depth]{$parent}};
16524: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16525: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16526: for (my $j=0; $j<$numchildren; $j++) {
16527: $name = $cats->[$depth]{$parent}[$j];
16528: $item = &escape($name).':'.&escape($parent).':'.$depth;
16529: my $deeper = $depth+1;
16530: my $checked = '';
16531: if (ref($currcategories) eq 'ARRAY') {
16532: if (@{$currcategories} > 0) {
16533: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16534: $checked = ' checked="checked"';
1.663 raeburn 16535: }
16536: }
16537: }
1.664 raeburn 16538: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16539: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16540: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16541: '<input type="hidden" name="catname" value="'.$name.'" />'.
16542: '</td><td>';
1.663 raeburn 16543: if (ref($path) eq 'ARRAY') {
16544: push(@{$path},$name);
1.1259 raeburn 16545: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16546: pop(@{$path});
16547: }
16548: $text .= '</td></tr>';
16549: }
16550: $text .= '</table></td>';
16551: }
16552: }
16553: }
16554: return $text;
16555: }
16556:
1.1181 raeburn 16557: =pod
16558:
16559: =back
16560:
16561: =cut
16562:
1.655 raeburn 16563: ############################################################
16564: ############################################################
16565:
16566:
1.443 albertel 16567: sub commit_customrole {
1.1408 raeburn 16568: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
1.1399 raeburn 16569: my $result = &Apache::lonnet::assigncustomrole(
1.1408 raeburn 16570: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
16571: $context,$othdomby,$requester);
1.630 raeburn 16572: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16573: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 16574: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
16575: if (wantarray) {
16576: return ($output,$result);
16577: } else {
16578: return $output;
16579: }
1.443 albertel 16580: }
16581:
16582: sub commit_standardrole {
1.1408 raeburn 16583: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
16584: $othdomby,$requester) = @_;
1.1399 raeburn 16585: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 16586: if ($context eq 'auto') {
16587: $linefeed = "\n";
16588: } else {
16589: $linefeed = "<br />\n";
16590: }
1.443 albertel 16591: if ($three eq 'st') {
1.1399 raeburn 16592: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1408 raeburn 16593: $one,$two,$sec,$context,$credits,$othdomby,
16594: $requester);
1.541 raeburn 16595: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16596: ($result eq 'unknown_course') || ($result eq 'refused')) {
16597: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16598: } else {
1.541 raeburn 16599: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16600: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16601: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16602: if ($context eq 'auto') {
16603: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16604: } else {
16605: $output .= '<b>'.$result.'</b>'.$linefeed.
16606: &mt('Add to classlist').': <b>ok</b>';
16607: }
16608: $output .= $linefeed;
1.443 albertel 16609: }
16610: } else {
16611: $output = &mt('Assigning').' '.$three.' in '.$url.
16612: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16613: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1408 raeburn 16614: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
16615: '','',$context,$othdomby,$requester);
1.541 raeburn 16616: if ($context eq 'auto') {
16617: $output .= $result.$linefeed;
16618: } else {
16619: $output .= '<b>'.$result.'</b>'.$linefeed;
16620: }
1.443 albertel 16621: }
1.1399 raeburn 16622: if (wantarray) {
16623: return ($output,$result);
16624: } else {
16625: return $output;
16626: }
1.443 albertel 16627: }
16628:
16629: sub commit_studentrole {
1.1116 raeburn 16630: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
1.1408 raeburn 16631: $credits,$othdomby,$requester) = @_;
1.626 raeburn 16632: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16633: if ($context eq 'auto') {
16634: $linefeed = "\n";
16635: } else {
16636: $linefeed = '<br />'."\n";
16637: }
1.443 albertel 16638: if (defined($one) && defined($two)) {
16639: my $cid=$one.'_'.$two;
16640: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16641: my $secchange = 0;
16642: my $expire_role_result;
16643: my $modify_section_result;
1.628 raeburn 16644: if ($oldsec ne '-1') {
16645: if ($oldsec ne $sec) {
1.443 albertel 16646: $secchange = 1;
1.628 raeburn 16647: my $now = time;
1.443 albertel 16648: my $uurl='/'.$cid;
16649: $uurl=~s/\_/\//g;
16650: if ($oldsec) {
16651: $uurl.='/'.$oldsec;
16652: }
1.626 raeburn 16653: $oldsecurl = $uurl;
1.628 raeburn 16654: $expire_role_result =
1.1408 raeburn 16655: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
16656: '','','',$context,$othdomby,$requester);
16657: if ($env{'request.course.sec'} ne '') {
1.628 raeburn 16658: if ($expire_role_result eq 'refused') {
16659: my @roles = ('st');
16660: my @statuses = ('previous');
16661: my @roledoms = ($one);
16662: my $withsec = 1;
16663: my %roleshash =
16664: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16665: \@statuses,\@roles,\@roledoms,$withsec);
16666: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16667: my ($oldstart,$oldend) =
16668: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16669: if ($oldend > 0 && $oldend <= $now) {
16670: $expire_role_result = 'ok';
16671: }
16672: }
16673: }
16674: }
1.443 albertel 16675: $result = $expire_role_result;
16676: }
16677: }
16678: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16679: $modify_section_result =
16680: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16681: undef,undef,undef,$sec,
16682: $end,$start,'','',$cid,
1.1408 raeburn 16683: '',$context,$credits,'',
16684: $othdomby,$requester);
1.443 albertel 16685: if ($modify_section_result =~ /^ok/) {
16686: if ($secchange == 1) {
1.628 raeburn 16687: if ($sec eq '') {
16688: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16689: } else {
16690: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16691: }
1.443 albertel 16692: } elsif ($oldsec eq '-1') {
1.628 raeburn 16693: if ($sec eq '') {
16694: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16695: } else {
16696: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16697: }
1.443 albertel 16698: } else {
1.628 raeburn 16699: if ($sec eq '') {
16700: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16701: } else {
16702: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16703: }
1.443 albertel 16704: }
16705: } else {
1.1115 raeburn 16706: if ($secchange) {
1.628 raeburn 16707: $$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;
16708: } else {
16709: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16710: }
1.443 albertel 16711: }
16712: $result = $modify_section_result;
16713: } elsif ($secchange == 1) {
1.628 raeburn 16714: if ($oldsec eq '') {
1.1103 raeburn 16715: $$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 16716: } else {
16717: $$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;
16718: }
1.626 raeburn 16719: if ($expire_role_result eq 'refused') {
16720: my $newsecurl = '/'.$cid;
16721: $newsecurl =~ s/\_/\//g;
16722: if ($sec ne '') {
16723: $newsecurl.='/'.$sec;
16724: }
16725: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16726: if ($sec eq '') {
16727: $$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;
16728: } else {
16729: $$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;
16730: }
16731: }
16732: }
1.443 albertel 16733: }
16734: } else {
1.626 raeburn 16735: $$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 16736: $result = "error: incomplete course id\n";
16737: }
16738: return $result;
16739: }
16740:
1.1108 raeburn 16741: sub show_role_extent {
16742: my ($scope,$context,$role) = @_;
16743: $scope =~ s{^/}{};
16744: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16745: push(@courseroles,'co');
16746: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16747: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16748: $scope =~ s{/}{_};
16749: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16750: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16751: my ($audom,$auname) = split(/\//,$scope);
16752: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16753: &Apache::loncommon::plainname($auname,$audom).'</span>');
16754: } else {
16755: $scope =~ s{/$}{};
16756: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16757: &Apache::lonnet::domain($scope,'description').'</span>');
16758: }
16759: }
16760:
1.443 albertel 16761: ############################################################
16762: ############################################################
16763:
1.566 albertel 16764: sub check_clone {
1.578 raeburn 16765: my ($args,$linefeed) = @_;
1.566 albertel 16766: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16767: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16768: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16769: my $clonetitle;
16770: my @clonemsg;
1.566 albertel 16771: my $can_clone = 0;
1.944 raeburn 16772: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16773: if ($lctype ne 'community') {
16774: $lctype = 'course';
16775: }
1.566 albertel 16776: if ($clonehome eq 'no_host') {
1.944 raeburn 16777: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16778: push(@clonemsg,({
16779: mt => 'No new community created.',
16780: args => [],
16781: },
16782: {
16783: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16784: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16785: }));
1.908 raeburn 16786: } else {
1.1344 raeburn 16787: push(@clonemsg,({
16788: mt => 'No new course created.',
16789: args => [],
16790: },
16791: {
16792: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16793: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16794: }));
16795: }
1.566 albertel 16796: } else {
16797: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16798: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16799: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16800: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16801: push(@clonemsg,({
16802: mt => 'No new community created.',
16803: args => [],
16804: },
16805: {
16806: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16807: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16808: }));
16809: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16810: }
16811: }
1.1262 raeburn 16812: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16813: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16814: $can_clone = 1;
16815: } else {
1.1221 raeburn 16816: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16817: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16818: if ($clonehash{'cloners'} eq '') {
16819: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16820: if ($domdefs{'canclone'}) {
16821: unless ($domdefs{'canclone'} eq 'none') {
16822: if ($domdefs{'canclone'} eq 'domain') {
16823: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16824: $can_clone = 1;
16825: }
16826: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16827: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16828: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16829: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16830: $can_clone = 1;
16831: }
16832: }
16833: }
16834: }
1.578 raeburn 16835: } else {
1.1221 raeburn 16836: my @cloners = split(/,/,$clonehash{'cloners'});
16837: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16838: $can_clone = 1;
1.1221 raeburn 16839: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16840: $can_clone = 1;
1.1225 raeburn 16841: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16842: $can_clone = 1;
1.1221 raeburn 16843: }
16844: unless ($can_clone) {
1.1225 raeburn 16845: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16846: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16847: my (%gotdomdefaults,%gotcodedefaults);
16848: foreach my $cloner (@cloners) {
16849: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16850: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16851: my (%codedefaults,@code_order);
16852: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16853: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16854: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16855: }
16856: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16857: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16858: }
16859: } else {
16860: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16861: \%codedefaults,
16862: \@code_order);
16863: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16864: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16865: }
16866: if (@code_order > 0) {
16867: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16868: $cloner,$clonehash{'internal.coursecode'},
16869: $args->{'crscode'})) {
16870: $can_clone = 1;
16871: last;
16872: }
16873: }
16874: }
16875: }
16876: }
1.1225 raeburn 16877: }
16878: }
16879: unless ($can_clone) {
16880: my $ccrole = 'cc';
16881: if ($args->{'crstype'} eq 'Community') {
16882: $ccrole = 'co';
16883: }
16884: my %roleshash =
16885: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16886: $args->{'ccdomain'},
16887: 'userroles',['active'],[$ccrole],
16888: [$args->{'clonedomain'}]);
16889: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16890: $can_clone = 1;
16891: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16892: $args->{'ccuname'},$args->{'ccdomain'})) {
16893: $can_clone = 1;
1.1221 raeburn 16894: }
16895: }
16896: unless ($can_clone) {
16897: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16898: push(@clonemsg,({
16899: mt => 'No new community created.',
16900: args => [],
16901: },
16902: {
16903: 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]).',
16904: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16905: }));
1.942 raeburn 16906: } else {
1.1344 raeburn 16907: push(@clonemsg,({
16908: mt => 'No new course created.',
16909: args => [],
16910: },
16911: {
16912: 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]).',
16913: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16914: }));
1.1221 raeburn 16915: }
1.566 albertel 16916: }
1.578 raeburn 16917: }
1.566 albertel 16918: }
1.1344 raeburn 16919: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16920: }
16921:
1.444 albertel 16922: sub construct_course {
1.1262 raeburn 16923: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16924: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16925: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16926: my $linefeed = '<br />'."\n";
16927: if ($context eq 'auto') {
16928: $linefeed = "\n";
16929: }
1.566 albertel 16930:
16931: #
16932: # Are we cloning?
16933: #
1.1344 raeburn 16934: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16935: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16936: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16937: if (!$can_clone) {
1.1344 raeburn 16938: return (0,$outcome,$clonemsgref);
1.566 albertel 16939: }
16940: }
16941:
1.444 albertel 16942: #
16943: # Open course
16944: #
1.1239 raeburn 16945: my $showncrstype;
16946: if ($args->{'crstype'} eq 'Placement') {
16947: $showncrstype = 'placement test';
16948: } else {
16949: $showncrstype = lc($args->{'crstype'});
16950: }
1.444 albertel 16951: my %cenv=();
16952: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16953: $args->{'cdescr'},
16954: $args->{'curl'},
16955: $args->{'course_home'},
16956: $args->{'nonstandard'},
16957: $args->{'crscode'},
16958: $args->{'ccuname'}.':'.
16959: $args->{'ccdomain'},
1.882 raeburn 16960: $args->{'crstype'},
1.1344 raeburn 16961: $cnum,$context,$category,
16962: $callercontext);
1.444 albertel 16963:
16964: # Note: The testing routines depend on this being output; see
16965: # Utils::Course. This needs to at least be output as a comment
16966: # if anyone ever decides to not show this, and Utils::Course::new
16967: # will need to be suitably modified.
1.1344 raeburn 16968: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16969: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16970: } else {
16971: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16972: }
1.943 raeburn 16973: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16974: return (0,$outcome,$clonemsgref);
1.943 raeburn 16975: }
16976:
1.444 albertel 16977: #
16978: # Check if created correctly
16979: #
1.479 albertel 16980: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16981: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16982: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16983: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16984: $outcome .= &mt_user($user_lh,
16985: 'Course creation failed, unrecognized course home server.');
16986: } else {
16987: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16988: }
16989: $outcome .= $linefeed;
16990: return (0,$outcome,$clonemsgref);
1.943 raeburn 16991: }
1.541 raeburn 16992: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16993:
1.444 albertel 16994: #
1.566 albertel 16995: # Do the cloning
16996: #
1.1344 raeburn 16997: my @clonemsg;
1.566 albertel 16998: if ($can_clone && $cloneid) {
1.1344 raeburn 16999: push(@clonemsg,
17000: {
17001: mt => 'Created [_1] by cloning from [_2]',
17002: args => [$showncrstype,$clonetitle],
17003: });
1.566 albertel 17004: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 17005: # Copy all files
1.1344 raeburn 17006: my @info =
17007: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
17008: $args->{'dateshift'},$args->{'crscode'},
17009: $args->{'ccuname'}.':'.$args->{'ccdomain'},
17010: $args->{'tinyurls'});
17011: if (@info) {
17012: push(@clonemsg,@info);
17013: }
1.444 albertel 17014: # Restore URL
1.566 albertel 17015: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 17016: # Restore title
1.566 albertel 17017: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 17018: # Restore creation date, creator and creation context.
17019: $cenv{'internal.created'}=$oldcenv{'internal.created'};
17020: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
17021: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 17022: # Mark as cloned
1.566 albertel 17023: $cenv{'clonedfrom'}=$cloneid;
1.638 www 17024: # Need to clone grading mode
17025: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
17026: $cenv{'grading'}=$newenv{'grading'};
17027: # Do not clone these environment entries
17028: &Apache::lonnet::del('environment',
17029: ['default_enrollment_start_date',
17030: 'default_enrollment_end_date',
17031: 'question.email',
17032: 'policy.email',
17033: 'comment.email',
17034: 'pch.users.denied',
1.725 raeburn 17035: 'plc.users.denied',
17036: 'hidefromcat',
1.1121 raeburn 17037: 'checkforpriv',
1.1355 raeburn 17038: 'categories'],
1.638 www 17039: $$crsudom,$$crsunum);
1.1170 raeburn 17040: if ($args->{'textbook'}) {
17041: $cenv{'internal.textbook'} = $args->{'textbook'};
17042: }
1.444 albertel 17043: }
1.566 albertel 17044:
1.444 albertel 17045: #
17046: # Set environment (will override cloned, if existing)
17047: #
17048: my @sections = ();
17049: my @xlists = ();
17050: if ($args->{'crstype'}) {
17051: $cenv{'type'}=$args->{'crstype'};
17052: }
1.1371 raeburn 17053: if ($args->{'lti'}) {
17054: $cenv{'internal.lti'}=$args->{'lti'};
17055: }
1.444 albertel 17056: if ($args->{'crsid'}) {
17057: $cenv{'courseid'}=$args->{'crsid'};
17058: }
17059: if ($args->{'crscode'}) {
17060: $cenv{'internal.coursecode'}=$args->{'crscode'};
17061: }
17062: if ($args->{'crsquota'} ne '') {
17063: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17064: } else {
17065: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17066: }
17067: if ($args->{'ccuname'}) {
17068: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17069: ':'.$args->{'ccdomain'};
17070: } else {
17071: $cenv{'internal.courseowner'} = $args->{'curruser'};
17072: }
1.1116 raeburn 17073: if ($args->{'defaultcredits'}) {
17074: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17075: }
1.444 albertel 17076: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1412 raeburn 17077: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 17078: if ($args->{'crssections'}) {
17079: $cenv{'internal.sectionnums'} = '';
17080: if ($args->{'crssections'} =~ m/,/) {
17081: @sections = split/,/,$args->{'crssections'};
17082: } else {
17083: $sections[0] = $args->{'crssections'};
17084: }
17085: if (@sections > 0) {
17086: foreach my $item (@sections) {
17087: my ($sec,$gp) = split/:/,$item;
17088: my $class = $args->{'crscode'}.$sec;
17089: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17090: $cenv{'internal.sectionnums'} .= $item.',';
1.1412 raeburn 17091: if ($addcheck eq 'ok') {
17092: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17093: push(@oklcsecs,$gp);
17094: }
17095: } else {
1.1263 raeburn 17096: push(@badclasses,$class);
1.444 albertel 17097: }
17098: }
17099: $cenv{'internal.sectionnums'} =~ s/,$//;
17100: }
17101: }
17102: # do not hide course coordinator from staff listing,
17103: # even if privileged
17104: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17105: # add course coordinator's domain to domains to check for privileged users
17106: # if different to course domain
17107: if ($$crsudom ne $args->{'ccdomain'}) {
17108: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17109: }
1.444 albertel 17110: # add crosslistings
17111: if ($args->{'crsxlist'}) {
17112: $cenv{'internal.crosslistings'}='';
17113: if ($args->{'crsxlist'} =~ m/,/) {
17114: @xlists = split/,/,$args->{'crsxlist'};
17115: } else {
17116: $xlists[0] = $args->{'crsxlist'};
17117: }
17118: if (@xlists > 0) {
17119: foreach my $item (@xlists) {
17120: my ($xl,$gp) = split/:/,$item;
17121: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17122: $cenv{'internal.crosslistings'} .= $item.',';
1.1412 raeburn 17123: if ($addcheck eq 'ok') {
17124: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17125: push(@oklcsecs,$gp);
17126: }
17127: } else {
1.1263 raeburn 17128: push(@badclasses,$xl);
1.444 albertel 17129: }
17130: }
17131: $cenv{'internal.crosslistings'} =~ s/,$//;
17132: }
17133: }
17134: if ($args->{'autoadds'}) {
17135: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17136: }
17137: if ($args->{'autodrops'}) {
17138: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17139: }
17140: # check for notification of enrollment changes
17141: my @notified = ();
17142: if ($args->{'notify_owner'}) {
17143: if ($args->{'ccuname'} ne '') {
17144: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17145: }
17146: }
17147: if ($args->{'notify_dc'}) {
17148: if ($uname ne '') {
1.630 raeburn 17149: push(@notified,$uname.':'.$udom);
1.444 albertel 17150: }
17151: }
17152: if (@notified > 0) {
17153: my $notifylist;
17154: if (@notified > 1) {
17155: $notifylist = join(',',@notified);
17156: } else {
17157: $notifylist = $notified[0];
17158: }
17159: $cenv{'internal.notifylist'} = $notifylist;
17160: }
17161: if (@badclasses > 0) {
17162: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17163: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17164: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17165: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17166: );
1.1264 raeburn 17167: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17168: &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 17169: if ($context eq 'auto') {
17170: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17171: } else {
1.566 albertel 17172: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17173: }
17174: foreach my $item (@badclasses) {
1.541 raeburn 17175: if ($context eq 'auto') {
1.1261 raeburn 17176: $outcome .= " - $item\n";
1.541 raeburn 17177: } else {
1.1261 raeburn 17178: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17179: }
1.1261 raeburn 17180: }
17181: if ($context eq 'auto') {
17182: $outcome .= $linefeed;
17183: } else {
17184: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17185: }
1.444 albertel 17186: }
17187: if ($args->{'no_end_date'}) {
17188: $args->{'endaccess'} = 0;
17189: }
1.1412 raeburn 17190: # If an official course with institutional sections is created by cloning
17191: # an existing course, section-specific hiding of course totals in student's
17192: # view of grades as copied from cloned course, will be checked for valid
17193: # sections.
17194: if (($can_clone && $cloneid) &&
17195: ($cenv{'internal.coursecode'} ne '') &&
17196: ($cenv{'grading'} eq 'standard') &&
17197: ($cenv{'hidetotals'} ne '') &&
17198: ($cenv{'hidetotals'} ne 'all')) {
17199: my @hidesecs;
17200: my $deletehidetotals;
17201: if (@oklcsecs) {
17202: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
17203: if (grep(/^\Q$sec$/,@oklcsecs)) {
17204: push(@hidesecs,$sec);
17205: }
17206: }
17207: if (@hidesecs) {
17208: $cenv{'hidetotals'} = join(',',@hidesecs);
17209: } else {
17210: $deletehidetotals = 1;
17211: }
17212: } else {
17213: $deletehidetotals = 1;
17214: }
17215: if ($deletehidetotals) {
17216: delete($cenv{'hidetotals'});
17217: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
17218: }
17219: }
1.444 albertel 17220: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17221: $cenv{'internal.autoend'}=$args->{'enrollend'};
17222: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17223: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17224: if ($args->{'showphotos'}) {
17225: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17226: }
17227: $cenv{'internal.authtype'} = $args->{'authtype'};
17228: $cenv{'internal.autharg'} = $args->{'autharg'};
17229: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17230: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17231: 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');
17232: if ($context eq 'auto') {
17233: $outcome .= $krb_msg;
17234: } else {
1.566 albertel 17235: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17236: }
17237: $outcome .= $linefeed;
1.444 albertel 17238: }
17239: }
17240: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17241: if ($args->{'setpolicy'}) {
17242: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17243: }
17244: if ($args->{'setcontent'}) {
17245: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17246: }
1.1251 raeburn 17247: if ($args->{'setcomment'}) {
17248: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17249: }
1.444 albertel 17250: }
17251: if ($args->{'reshome'}) {
17252: $cenv{'reshome'}=$args->{'reshome'}.'/';
17253: $cenv{'reshome'}=~s/\/+$/\//;
17254: }
17255: #
17256: # course has keyed access
17257: #
17258: if ($args->{'setkeys'}) {
17259: $cenv{'keyaccess'}='yes';
17260: }
17261: # if specified, key authority is not course, but user
17262: # only active if keyaccess is yes
17263: if ($args->{'keyauth'}) {
1.487 albertel 17264: my ($user,$domain) = split(':',$args->{'keyauth'});
17265: $user = &LONCAPA::clean_username($user);
17266: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17267: if ($user ne '' && $domain ne '') {
1.487 albertel 17268: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17269: }
17270: }
17271:
1.1166 raeburn 17272: #
1.1167 raeburn 17273: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17274: #
17275: if ($args->{'uniquecode'}) {
17276: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17277: if ($code) {
17278: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17279: my %crsinfo =
17280: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17281: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17282: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17283: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17284: }
1.1166 raeburn 17285: if (ref($coderef)) {
17286: $$coderef = $code;
17287: }
17288: }
17289: }
17290:
1.444 albertel 17291: if ($args->{'disresdis'}) {
17292: $cenv{'pch.roles.denied'}='st';
17293: }
17294: if ($args->{'disablechat'}) {
17295: $cenv{'plc.roles.denied'}='st';
17296: }
17297:
17298: # Record we've not yet viewed the Course Initialization Helper for this
17299: # course
17300: $cenv{'course.helper.not.run'} = 1;
17301: #
17302: # Use new Randomseed
17303: #
17304: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17305: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17306: #
17307: # The encryption code and receipt prefix for this course
17308: #
17309: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17310: $cenv{'internal.encpref'}=100+int(9*rand(99));
17311: #
17312: # By default, use standard grading
17313: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17314:
1.541 raeburn 17315: $outcome .= $linefeed.&mt('Setting environment').': '.
17316: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17317: #
17318: # Open all assignments
17319: #
17320: if ($args->{'openall'}) {
1.1341 raeburn 17321: my $opendate = time;
17322: if ($args->{'openallfrom'} =~ /^\d+$/) {
17323: $opendate = $args->{'openallfrom'};
17324: }
1.444 albertel 17325: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17326: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17327: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17328: $outcome .= &mt('All assignments open starting [_1]',
17329: &Apache::lonlocal::locallocaltime($opendate)).': '.
17330: &Apache::lonnet::cput
17331: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17332: }
17333: #
17334: # Set first page
17335: #
17336: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17337: || ($cloneid)) {
17338: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17339:
17340: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17341: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17342:
1.444 albertel 17343: $outcome .= ($fatal?$errtext:'read ok').' - ';
17344: my $title; my $url;
17345: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17346: $title=&mt('Syllabus');
1.444 albertel 17347: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17348: } else {
1.963 raeburn 17349: $title=&mt('Table of Contents');
1.444 albertel 17350: $url='/adm/navmaps';
17351: }
1.445 albertel 17352:
17353: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17354: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17355:
17356: if ($errtext) { $fatal=2; }
1.541 raeburn 17357: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17358: }
1.566 albertel 17359:
1.1237 raeburn 17360: #
17361: # Set params for Placement Tests
17362: #
1.1239 raeburn 17363: if ($args->{'crstype'} eq 'Placement') {
17364: my %storecontent;
17365: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17366: my %defaults = (
17367: buttonshide => { value => 'yes',
17368: type => 'string_yesno',},
17369: type => { value => 'randomizetry',
17370: type => 'string_questiontype',},
17371: maxtries => { value => 1,
17372: type => 'int_pos',},
17373: problemstatus => { value => 'no',
17374: type => 'string_problemstatus',},
17375: );
17376: foreach my $key (keys(%defaults)) {
17377: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17378: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17379: }
1.1237 raeburn 17380: &Apache::lonnet::cput
17381: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17382: }
17383:
1.1344 raeburn 17384: return (1,$outcome,\@clonemsg);
1.444 albertel 17385: }
17386:
1.1166 raeburn 17387: sub make_unique_code {
17388: my ($cdom,$cnum) = @_;
17389: # get lock on uniquecodes db
17390: my $lockhash = {
17391: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17392: ':'.$env{'user.domain'},
17393: };
17394: my $tries = 0;
17395: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17396: my ($code,$error);
17397:
17398: while (($gotlock ne 'ok') && ($tries<3)) {
17399: $tries ++;
17400: sleep 1;
17401: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17402: }
17403: if ($gotlock eq 'ok') {
17404: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17405: my $gotcode;
17406: my $attempts = 0;
17407: while ((!$gotcode) && ($attempts < 100)) {
17408: $code = &generate_code();
17409: if (!exists($currcodes{$code})) {
17410: $gotcode = 1;
17411: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17412: $error = 'nostore';
17413: }
17414: }
17415: $attempts ++;
17416: }
17417: my @del_lock = ($cnum."\0".'uniquecodes');
17418: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17419: } else {
17420: $error = 'nolock';
17421: }
17422: return ($code,$error);
17423: }
17424:
17425: sub generate_code {
17426: my $code;
17427: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17428: for (my $i=0; $i<6; $i++) {
17429: my $lettnum = int (rand 2);
17430: my $item = '';
17431: if ($lettnum) {
17432: $item = $letts[int( rand(18) )];
17433: } else {
17434: $item = 1+int( rand(8) );
17435: }
17436: $code .= $item;
17437: }
17438: return $code;
17439: }
17440:
1.444 albertel 17441: ############################################################
17442: ############################################################
17443:
1.1237 raeburn 17444: # Community, Course and Placement Test
1.378 raeburn 17445: sub course_type {
17446: my ($cid) = @_;
17447: if (!defined($cid)) {
17448: $cid = $env{'request.course.id'};
17449: }
1.404 albertel 17450: if (defined($env{'course.'.$cid.'.type'})) {
17451: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17452: } else {
17453: return 'Course';
1.377 raeburn 17454: }
17455: }
1.156 albertel 17456:
1.406 raeburn 17457: sub group_term {
17458: my $crstype = &course_type();
17459: my %names = (
17460: 'Course' => 'group',
1.865 raeburn 17461: 'Community' => 'group',
1.1237 raeburn 17462: 'Placement' => 'group',
1.406 raeburn 17463: );
17464: return $names{$crstype};
17465: }
17466:
1.902 raeburn 17467: sub course_types {
1.1310 raeburn 17468: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17469: my %typename = (
17470: official => 'Official course',
17471: unofficial => 'Unofficial course',
17472: community => 'Community',
1.1165 raeburn 17473: textbook => 'Textbook course',
1.1237 raeburn 17474: placement => 'Placement test',
1.1310 raeburn 17475: lti => 'LTI provider',
1.902 raeburn 17476: );
17477: return (\@types,\%typename);
17478: }
17479:
1.156 albertel 17480: sub icon {
17481: my ($file)=@_;
1.505 albertel 17482: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17483: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17484: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17485: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17486: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17487: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17488: $curfext.".gif") {
17489: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17490: $curfext.".gif";
17491: }
17492: }
1.249 albertel 17493: return &lonhttpdurl($iconname);
1.154 albertel 17494: }
1.84 albertel 17495:
1.575 albertel 17496: sub lonhttpdurl {
1.692 www 17497: #
17498: # Had been used for "small fry" static images on separate port 8080.
17499: # Modify here if lightweight http functionality desired again.
17500: # Currently eliminated due to increasing firewall issues.
17501: #
1.575 albertel 17502: my ($url)=@_;
1.692 www 17503: return $url;
1.215 albertel 17504: }
17505:
1.213 albertel 17506: sub connection_aborted {
17507: my ($r)=@_;
17508: $r->print(" ");$r->rflush();
17509: my $c = $r->connection;
17510: return $c->aborted();
17511: }
17512:
1.221 foxr 17513: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17514: # strings as 'strings'.
17515: sub escape_single {
1.221 foxr 17516: my ($input) = @_;
1.223 albertel 17517: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17518: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17519: return $input;
17520: }
1.223 albertel 17521:
1.222 foxr 17522: # Same as escape_single, but escape's "'s This
17523: # can be used for "strings"
17524: sub escape_double {
17525: my ($input) = @_;
17526: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17527: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17528: return $input;
17529: }
1.223 albertel 17530:
1.222 foxr 17531: # Escapes the last element of a full URL.
17532: sub escape_url {
17533: my ($url) = @_;
1.238 raeburn 17534: my @urlslices = split(/\//, $url,-1);
1.369 www 17535: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17536: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17537: }
1.462 albertel 17538:
1.820 raeburn 17539: sub compare_arrays {
17540: my ($arrayref1,$arrayref2) = @_;
17541: my (@difference,%count);
17542: @difference = ();
17543: %count = ();
17544: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17545: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17546: foreach my $element (keys(%count)) {
17547: if ($count{$element} == 1) {
17548: push(@difference,$element);
17549: }
17550: }
17551: }
17552: return @difference;
17553: }
17554:
1.1322 raeburn 17555: sub lon_status_items {
17556: my %defaults = (
17557: E => 100,
17558: W => 4,
17559: N => 1,
1.1324 raeburn 17560: U => 5,
1.1322 raeburn 17561: threshold => 200,
17562: sysmail => 2500,
17563: );
17564: my %names = (
17565: E => 'Errors',
17566: W => 'Warnings',
17567: N => 'Notices',
1.1324 raeburn 17568: U => 'Unsent',
1.1322 raeburn 17569: );
17570: return (\%defaults,\%names);
17571: }
17572:
1.817 bisitz 17573: # -------------------------------------------------------- Initialize user login
1.462 albertel 17574: sub init_user_environment {
1.463 albertel 17575: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17576: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17577:
17578: my $public=($username eq 'public' && $domain eq 'public');
17579:
1.1415 raeburn 17580: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17581: $coauthorenv);
1.462 albertel 17582: my $now=time;
17583:
17584: if ($public) {
17585: my $max_public=100;
17586: my $oldest;
17587: my $oldest_time=0;
17588: for(my $next=1;$next<=$max_public;$next++) {
17589: if (-e $lonids."/publicuser_$next.id") {
17590: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17591: if ($mtime<$oldest_time || !$oldest_time) {
17592: $oldest_time=$mtime;
17593: $oldest=$next;
17594: }
17595: } else {
17596: $cookie="publicuser_$next";
17597: last;
17598: }
17599: }
17600: if (!$cookie) { $cookie="publicuser_$oldest"; }
17601: } else {
1.1275 raeburn 17602: # See if old ID present, if so, remove if this isn't a robot,
17603: # killing any existing non-robot sessions
1.463 albertel 17604: if (!$args->{'robot'}) {
17605: opendir(DIR,$lonids);
17606: while ($filename=readdir(DIR)) {
17607: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17608: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17609: &GDBM_READER(),0640)) {
1.1295 raeburn 17610: my $linkedfile;
1.1320 raeburn 17611: if (exists($oldenv{'user.linkedenv'})) {
17612: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17613: }
1.1320 raeburn 17614: untie(%oldenv);
17615: if (unlink("$lonids/$filename")) {
17616: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17617: if (-l "$lonids/$linkedfile.id") {
17618: unlink("$lonids/$linkedfile.id");
17619: }
1.1295 raeburn 17620: }
17621: }
17622: } else {
17623: unlink($lonids.'/'.$filename);
17624: }
1.463 albertel 17625: }
1.462 albertel 17626: }
1.463 albertel 17627: closedir(DIR);
1.1204 raeburn 17628: # If there is a undeleted lockfile for the user's paste buffer remove it.
17629: my $namespace = 'nohist_courseeditor';
17630: my $lockingkey = 'paste'."\0".'locked_num';
17631: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17632: $domain,$username);
17633: if (exists($lockhash{$lockingkey})) {
17634: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17635: unless ($delresult eq 'ok') {
17636: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17637: }
17638: }
1.462 albertel 17639: }
17640: # Give them a new cookie
1.463 albertel 17641: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17642: : $now.$$.int(rand(10000)));
1.463 albertel 17643: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17644:
17645: # Initialize roles
17646:
1.1414 raeburn 17647: ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17648: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17649: }
17650: # ------------------------------------ Check browser type and MathML capability
17651:
1.1194 raeburn 17652: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17653: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17654:
17655: # ------------------------------------------------------------- Get environment
17656:
17657: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17658: my ($tmp) = keys(%userenv);
1.1275 raeburn 17659: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17660: undef(%userenv);
17661: }
17662: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17663: $form->{'interface'}=$userenv{'interface'};
17664: }
17665: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17666:
17667: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17668: foreach my $option ('interface','localpath','localres') {
17669: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17670: }
17671: # --------------------------------------------------------- Write first profile
17672:
17673: {
1.1350 raeburn 17674: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17675: my %initial_env =
17676: ("user.name" => $username,
17677: "user.domain" => $domain,
17678: "user.home" => $authhost,
17679: "browser.type" => $clientbrowser,
17680: "browser.version" => $clientversion,
17681: "browser.mathml" => $clientmathml,
17682: "browser.unicode" => $clientunicode,
17683: "browser.os" => $clientos,
1.1137 raeburn 17684: "browser.mobile" => $clientmobile,
1.1141 raeburn 17685: "browser.info" => $clientinfo,
1.1194 raeburn 17686: "browser.osversion" => $clientosversion,
1.462 albertel 17687: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17688: "request.course.fn" => '',
17689: "request.course.uri" => '',
17690: "request.course.sec" => '',
17691: "request.role" => 'cm',
17692: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17693: "request.host" => $ip,);
1.462 albertel 17694:
17695: if ($form->{'localpath'}) {
17696: $initial_env{"browser.localpath"} = $form->{'localpath'};
17697: $initial_env{"browser.localres"} = $form->{'localres'};
17698: }
17699:
17700: if ($form->{'interface'}) {
17701: $form->{'interface'}=~s/\W//gs;
17702: $initial_env{"browser.interface"} = $form->{'interface'};
17703: $env{'browser.interface'}=$form->{'interface'};
17704: }
17705:
1.1157 raeburn 17706: if ($form->{'iptoken'}) {
17707: my $lonhost = $r->dir_config('lonHostID');
17708: $initial_env{"user.noloadbalance"} = $lonhost;
17709: $env{'user.noloadbalance'} = $lonhost;
17710: }
17711:
1.1268 raeburn 17712: if ($form->{'noloadbalance'}) {
17713: my @hosts = &Apache::lonnet::current_machine_ids();
17714: my $hosthere = $form->{'noloadbalance'};
17715: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17716: $initial_env{"user.noloadbalance"} = $hosthere;
17717: $env{'user.noloadbalance'} = $hosthere;
17718: }
17719: }
17720:
1.1016 raeburn 17721: unless ($domain eq 'public') {
1.1273 raeburn 17722: my %is_adv = ( is_adv => $env{'user.adv'} );
17723: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17724:
1.1414 raeburn 17725: foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
17726: $userenv{'availabletools.'.$tool} =
1.1273 raeburn 17727: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17728: undef,\%userenv,\%domdef,\%is_adv);
17729: }
1.980 raeburn 17730:
1.1311 raeburn 17731: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17732: $userenv{'canrequest.'.$crstype} =
17733: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17734: 'reload','requestcourses',
17735: \%userenv,\%domdef,\%is_adv);
17736: }
1.724 raeburn 17737:
1.1273 raeburn 17738: $userenv{'canrequest.author'} =
17739: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17740: 'reload','requestauthor',
1.980 raeburn 17741: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17742: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17743: $domain,$username);
17744: my $reqstatus = $reqauthor{'author_status'};
17745: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17746: if (ref($reqauthor{'author'}) eq 'HASH') {
17747: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17748: $reqauthor{'author'}{'timestamp'};
17749: }
1.1092 raeburn 17750: }
1.1287 raeburn 17751: my ($types,$typename) = &course_types();
17752: if (ref($types) eq 'ARRAY') {
17753: my @options = ('approval','validate','autolimit');
17754: my $optregex = join('|',@options);
17755: my (%willtrust,%trustchecked);
17756: foreach my $type (@{$types}) {
17757: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17758: if ($dom_str ne '') {
17759: my $updatedstr = '';
17760: my @possdomains = split(',',$dom_str);
17761: foreach my $entry (@possdomains) {
17762: my ($extdom,$extopt) = split(':',$entry);
17763: unless ($trustchecked{$extdom}) {
17764: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17765: $trustchecked{$extdom} = 1;
17766: }
17767: if ($willtrust{$extdom}) {
17768: $updatedstr .= $entry.',';
17769: }
17770: }
17771: $updatedstr =~ s/,$//;
17772: if ($updatedstr) {
17773: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17774: } else {
17775: delete($userenv{'reqcrsotherdom.'.$type});
17776: }
17777: }
17778: }
17779: }
1.1092 raeburn 17780: }
1.462 albertel 17781: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17782:
1.462 albertel 17783: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17784: &GDBM_WRCREAT(),0640)) {
17785: &_add_to_env(\%disk_env,\%initial_env);
17786: &_add_to_env(\%disk_env,\%userenv,'environment.');
17787: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17788: if (ref($firstaccenv) eq 'HASH') {
17789: &_add_to_env(\%disk_env,$firstaccenv);
17790: }
17791: if (ref($timerintenv) eq 'HASH') {
17792: &_add_to_env(\%disk_env,$timerintenv);
17793: }
1.1414 raeburn 17794: if (ref($coauthorenv) eq 'HASH') {
17795: if (keys(%{$coauthorenv})) {
17796: &_add_to_env(\%disk_env,$coauthorenv);
17797: }
17798: }
1.463 albertel 17799: if (ref($args->{'extra_env'})) {
17800: &_add_to_env(\%disk_env,$args->{'extra_env'});
17801: }
1.462 albertel 17802: untie(%disk_env);
17803: } else {
1.705 tempelho 17804: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17805: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17806: return 'error: '.$!;
17807: }
17808: }
17809: $env{'request.role'}='cm';
17810: $env{'request.role.adv'}=$env{'user.adv'};
17811: $env{'browser.type'}=$clientbrowser;
17812:
17813: return $cookie;
17814:
17815: }
17816:
17817: sub _add_to_env {
17818: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17819: if (ref($env_data) eq 'HASH') {
17820: while (my ($key,$value) = each(%$env_data)) {
17821: $idf->{$prefix.$key} = $value;
17822: $env{$prefix.$key} = $value;
17823: }
1.462 albertel 17824: }
17825: }
17826:
1.685 tempelho 17827: # --- Get the symbolic name of a problem and the url
17828: sub get_symb {
17829: my ($request,$silent) = @_;
1.726 raeburn 17830: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17831: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17832: if ($symb eq '') {
17833: if (!$silent) {
1.1071 raeburn 17834: if (ref($request)) {
17835: $request->print("Unable to handle ambiguous references:$url:.");
17836: }
1.685 tempelho 17837: return ();
17838: }
17839: }
17840: &Apache::lonenc::check_decrypt(\$symb);
17841: return ($symb);
17842: }
17843:
17844: # --------------------------------------------------------------Get annotation
17845:
17846: sub get_annotation {
17847: my ($symb,$enc) = @_;
17848:
17849: my $key = $symb;
17850: if (!$enc) {
17851: $key =
17852: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17853: }
17854: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17855: return $annotation{$key};
17856: }
17857:
17858: sub clean_symb {
1.731 raeburn 17859: my ($symb,$delete_enc) = @_;
1.685 tempelho 17860:
17861: &Apache::lonenc::check_decrypt(\$symb);
17862: my $enc = $env{'request.enc'};
1.731 raeburn 17863: if ($delete_enc) {
1.730 raeburn 17864: delete($env{'request.enc'});
17865: }
1.685 tempelho 17866:
17867: return ($symb,$enc);
17868: }
1.462 albertel 17869:
1.1181 raeburn 17870: ############################################################
17871: ############################################################
17872:
17873: =pod
17874:
17875: =head1 Routines for building display used to search for courses
17876:
17877:
17878: =over 4
17879:
17880: =item * &build_filters()
17881:
17882: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17883: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17884: and quotacheck.pl
17885:
1.1181 raeburn 17886:
17887: Inputs:
17888:
17889: filterlist - anonymous array of fields to include as potential filters
17890:
17891: crstype - course type
17892:
17893: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17894: to pop-open a course selector (will contain "extra element").
17895:
17896: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17897:
17898: filter - anonymous hash of criteria and their values
17899:
17900: action - form action
17901:
17902: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17903:
1.1182 raeburn 17904: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17905:
17906: cloneruname - username of owner of new course who wants to clone
17907:
17908: clonerudom - domain of owner of new course who wants to clone
17909:
17910: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17911:
17912: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17913:
17914: codedom - domain
17915:
17916: formname - value of form element named "form".
17917:
17918: fixeddom - domain, if fixed.
17919:
17920: prevphase - value to assign to form element named "phase" when going back to the previous screen
17921:
17922: cnameelement - name of form element in form on opener page which will receive title of selected course
17923:
17924: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17925:
17926: cdomelement - name of form element in form on opener page which will receive domain of selected course
17927:
17928: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17929:
17930: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17931:
17932: clonewarning - warning message about missing information for intended course owner when DC creates a course
17933:
1.1182 raeburn 17934:
1.1181 raeburn 17935: Returns: $output - HTML for display of search criteria, and hidden form elements.
17936:
1.1182 raeburn 17937:
1.1181 raeburn 17938: Side Effects: None
17939:
17940: =cut
17941:
17942: # ---------------------------------------------- search for courses based on last activity etc.
17943:
17944: sub build_filters {
17945: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17946: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17947: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17948: $cnameelement,$cnumelement,$cdomelement,$setroles,
17949: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17950: my ($list,$jscript);
1.1181 raeburn 17951: my $onchange = 'javascript:updateFilters(this)';
17952: my ($domainselectform,$sincefilterform,$createdfilterform,
17953: $ownerdomselectform,$persondomselectform,$instcodeform,
17954: $typeselectform,$instcodetitle);
17955: if ($formname eq '') {
17956: $formname = $caller;
17957: }
17958: foreach my $item (@{$filterlist}) {
17959: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17960: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17961: if ($item eq 'domainfilter') {
17962: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17963: } elsif ($item eq 'coursefilter') {
17964: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17965: } elsif ($item eq 'ownerfilter') {
17966: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17967: } elsif ($item eq 'ownerdomfilter') {
17968: $filter->{'ownerdomfilter'} =
17969: &LONCAPA::clean_domain($filter->{$item});
17970: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17971: 'ownerdomfilter',1);
17972: } elsif ($item eq 'personfilter') {
17973: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17974: } elsif ($item eq 'persondomfilter') {
17975: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17976: 'persondomfilter',1);
17977: } else {
17978: $filter->{$item} =~ s/\W//g;
17979: }
17980: if (!$filter->{$item}) {
17981: $filter->{$item} = '';
17982: }
17983: }
17984: if ($item eq 'domainfilter') {
17985: my $allow_blank = 1;
17986: if ($formname eq 'portform') {
17987: $allow_blank=0;
17988: } elsif ($formname eq 'studentform') {
17989: $allow_blank=0;
17990: }
17991: if ($fixeddom) {
17992: $domainselectform = '<input type="hidden" name="domainfilter"'.
17993: ' value="'.$codedom.'" />'.
17994: &Apache::lonnet::domain($codedom,'description');
17995: } else {
17996: $domainselectform = &select_dom_form($filter->{$item},
17997: 'domainfilter',
17998: $allow_blank,'',$onchange);
17999: }
18000: } else {
18001: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
18002: }
18003: }
18004:
18005: # last course activity filter and selection
18006: $sincefilterform = &timebased_select_form('sincefilter',$filter);
18007:
18008: # course created filter and selection
18009: if (exists($filter->{'createdfilter'})) {
18010: $createdfilterform = &timebased_select_form('createdfilter',$filter);
18011: }
18012:
1.1239 raeburn 18013: my $prefix = $crstype;
18014: if ($crstype eq 'Placement') {
18015: $prefix = 'Placement Test'
18016: }
1.1181 raeburn 18017: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 18018: 'cac' => "$prefix Activity",
18019: 'ccr' => "$prefix Created",
18020: 'cde' => "$prefix Title",
18021: 'cdo' => "$prefix Domain",
1.1181 raeburn 18022: 'ins' => 'Institutional Code',
18023: 'inc' => 'Institutional Categorization',
1.1239 raeburn 18024: 'cow' => "$prefix Owner/Co-owner",
18025: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 18026: 'cog' => 'Type',
18027: );
18028:
18029: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18030: my $typeval = 'Course';
18031: if ($crstype eq 'Community') {
18032: $typeval = 'Community';
1.1239 raeburn 18033: } elsif ($crstype eq 'Placement') {
18034: $typeval = 'Placement';
1.1181 raeburn 18035: }
18036: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
18037: } else {
18038: $typeselectform = '<select name="type" size="1"';
18039: if ($onchange) {
18040: $typeselectform .= ' onchange="'.$onchange.'"';
18041: }
18042: $typeselectform .= '>'."\n";
1.1237 raeburn 18043: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 18044: my $shown;
18045: if ($posstype eq 'Placement') {
18046: $shown = &mt('Placement Test');
18047: } else {
18048: $shown = &mt($posstype);
18049: }
1.1181 raeburn 18050: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 18051: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 18052: }
18053: $typeselectform.="</select>";
18054: }
18055:
18056: my ($cloneableonlyform,$cloneabletitle);
18057: if (exists($filter->{'cloneableonly'})) {
18058: my $cloneableon = '';
18059: my $cloneableoff = ' checked="checked"';
18060: if ($filter->{'cloneableonly'}) {
18061: $cloneableon = $cloneableoff;
18062: $cloneableoff = '';
18063: }
18064: $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>';
18065: if ($formname eq 'ccrs') {
1.1187 bisitz 18066: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 18067: } else {
18068: $cloneabletitle = &mt('Cloneable by you');
18069: }
18070: }
18071: my $officialjs;
18072: if ($crstype eq 'Course') {
18073: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 18074: # if (($fixeddom) || ($formname eq 'requestcrs') ||
18075: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
18076: if ($codedom) {
1.1181 raeburn 18077: $officialjs = 1;
18078: ($instcodeform,$jscript,$$numtitlesref) =
18079: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
18080: $officialjs,$codetitlesref);
18081: if ($jscript) {
1.1182 raeburn 18082: $jscript = '<script type="text/javascript">'."\n".
18083: '// <![CDATA['."\n".
18084: $jscript."\n".
18085: '// ]]>'."\n".
18086: '</script>'."\n";
1.1181 raeburn 18087: }
18088: }
18089: if ($instcodeform eq '') {
18090: $instcodeform =
18091: '<input type="text" name="instcodefilter" size="10" value="'.
18092: $list->{'instcodefilter'}.'" />';
18093: $instcodetitle = $lt{'ins'};
18094: } else {
18095: $instcodetitle = $lt{'inc'};
18096: }
18097: if ($fixeddom) {
18098: $instcodetitle .= '<br />('.$codedom.')';
18099: }
18100: }
18101: }
18102: my $output = qq|
18103: <form method="post" name="filterpicker" action="$action">
18104: <input type="hidden" name="form" value="$formname" />
18105: |;
18106: if ($formname eq 'modifycourse') {
18107: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18108: '<input type="hidden" name="prevphase" value="'.
18109: $prevphase.'" />'."\n";
1.1198 musolffc 18110: } elsif ($formname eq 'quotacheck') {
18111: $output .= qq|
18112: <input type="hidden" name="sortby" value="" />
18113: <input type="hidden" name="sortorder" value="" />
18114: |;
18115: } else {
1.1181 raeburn 18116: my $name_input;
18117: if ($cnameelement ne '') {
18118: $name_input = '<input type="hidden" name="cnameelement" value="'.
18119: $cnameelement.'" />';
18120: }
18121: $output .= qq|
1.1182 raeburn 18122: <input type="hidden" name="cnumelement" value="$cnumelement" />
18123: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18124: $name_input
18125: $roleelement
18126: $multelement
18127: $typeelement
18128: |;
18129: if ($formname eq 'portform') {
18130: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18131: }
18132: }
18133: if ($fixeddom) {
18134: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18135: }
18136: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18137: if ($sincefilterform) {
18138: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18139: .$sincefilterform
18140: .&Apache::lonhtmlcommon::row_closure();
18141: }
18142: if ($createdfilterform) {
18143: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18144: .$createdfilterform
18145: .&Apache::lonhtmlcommon::row_closure();
18146: }
18147: if ($domainselectform) {
18148: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18149: .$domainselectform
18150: .&Apache::lonhtmlcommon::row_closure();
18151: }
18152: if ($typeselectform) {
18153: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18154: $output .= $typeselectform;
18155: } else {
18156: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18157: .$typeselectform
18158: .&Apache::lonhtmlcommon::row_closure();
18159: }
18160: }
18161: if ($instcodeform) {
18162: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18163: .$instcodeform
18164: .&Apache::lonhtmlcommon::row_closure();
18165: }
18166: if (exists($filter->{'ownerfilter'})) {
18167: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18168: '<table><tr><td>'.&mt('Username').'<br />'.
18169: '<input type="text" name="ownerfilter" size="20" value="'.
18170: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18171: $ownerdomselectform.'</td></tr></table>'.
18172: &Apache::lonhtmlcommon::row_closure();
18173: }
18174: if (exists($filter->{'personfilter'})) {
18175: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18176: '<table><tr><td>'.&mt('Username').'<br />'.
18177: '<input type="text" name="personfilter" size="20" value="'.
18178: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18179: $persondomselectform.'</td></tr></table>'.
18180: &Apache::lonhtmlcommon::row_closure();
18181: }
18182: if (exists($filter->{'coursefilter'})) {
18183: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18184: .'<input type="text" name="coursefilter" size="25" value="'
18185: .$list->{'coursefilter'}.'" />'
18186: .&Apache::lonhtmlcommon::row_closure();
18187: }
18188: if ($cloneableonlyform) {
18189: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18190: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18191: }
18192: if (exists($filter->{'descriptfilter'})) {
18193: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18194: .'<input type="text" name="descriptfilter" size="40" value="'
18195: .$list->{'descriptfilter'}.'" />'
18196: .&Apache::lonhtmlcommon::row_closure(1);
18197: }
18198: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18199: '<input type="hidden" name="updater" value="" />'."\n".
18200: '<input type="submit" name="gosearch" value="'.
18201: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18202: return $jscript.$clonewarning.$output;
18203: }
18204:
18205: =pod
18206:
18207: =item * &timebased_select_form()
18208:
1.1182 raeburn 18209: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18210: filter e.g., Course Activity, Course Created, when searching for courses
18211: or communities
18212:
18213: Inputs:
18214:
18215: item - name of form element (sincefilter or createdfilter)
18216:
18217: filter - anonymous hash of criteria and their values
18218:
18219: Returns: HTML for a select box contained a blank, then six time selections,
18220: with value set in incoming form variables currently selected.
18221:
18222: Side Effects: None
18223:
18224: =cut
18225:
18226: sub timebased_select_form {
18227: my ($item,$filter) = @_;
18228: if (ref($filter) eq 'HASH') {
18229: $filter->{$item} =~ s/[^\d-]//g;
18230: if (!$filter->{$item}) { $filter->{$item}=-1; }
18231: return &select_form(
18232: $filter->{$item},
18233: $item,
18234: { '-1' => '',
18235: '86400' => &mt('today'),
18236: '604800' => &mt('last week'),
18237: '2592000' => &mt('last month'),
18238: '7776000' => &mt('last three months'),
18239: '15552000' => &mt('last six months'),
18240: '31104000' => &mt('last year'),
18241: 'select_form_order' =>
18242: ['-1','86400','604800','2592000','7776000',
18243: '15552000','31104000']});
18244: }
18245: }
18246:
18247: =pod
18248:
18249: =item * &js_changer()
18250:
18251: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18252: when course type or domain is changed, and also to hide 'Searching ...' on
18253: page load completion for page showing search result.
1.1181 raeburn 18254:
18255: Inputs: None
18256:
1.1183 raeburn 18257: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18258:
18259: Side Effects: None
18260:
18261: =cut
18262:
18263: sub js_changer {
18264: return <<ENDJS;
18265: <script type="text/javascript">
18266: // <![CDATA[
18267: function updateFilters(caller) {
18268: if (typeof(caller) != "undefined") {
18269: document.filterpicker.updater.value = caller.name;
18270: }
18271: document.filterpicker.submit();
18272: }
1.1183 raeburn 18273:
18274: function hideSearching() {
18275: if (document.getElementById('searching')) {
18276: document.getElementById('searching').style.display = 'none';
18277: }
18278: return;
18279: }
18280:
1.1181 raeburn 18281: // ]]>
18282: </script>
18283:
18284: ENDJS
18285: }
18286:
18287: =pod
18288:
1.1182 raeburn 18289: =item * &search_courses()
18290:
18291: Process selected filters form course search form and pass to lonnet::courseiddump
18292: to retrieve a hash for which keys are courseIDs which match the selected filters.
18293:
18294: Inputs:
18295:
18296: dom - domain being searched
18297:
18298: type - course type ('Course' or 'Community' or '.' if any).
18299:
18300: filter - anonymous hash of criteria and their values
18301:
18302: numtitles - for institutional codes - number of categories
18303:
18304: cloneruname - optional username of new course owner
18305:
18306: clonerudom - optional domain of new course owner
18307:
1.1221 raeburn 18308: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18309: (used when DC is using course creation form)
18310:
18311: codetitles - reference to array of titles of components in institutional codes (official courses).
18312:
1.1221 raeburn 18313: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18314: (and so can clone automatically)
18315:
18316: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18317:
18318: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18319: courses to clone
1.1182 raeburn 18320:
18321: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18322:
18323:
18324: Side Effects: None
18325:
18326: =cut
18327:
18328:
18329: sub search_courses {
1.1221 raeburn 18330: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18331: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18332: my (%courses,%showcourses,$cloner);
18333: if (($filter->{'ownerfilter'} ne '') ||
18334: ($filter->{'ownerdomfilter'} ne '')) {
18335: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18336: $filter->{'ownerdomfilter'};
18337: }
18338: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18339: if (!$filter->{$item}) {
18340: $filter->{$item}='.';
18341: }
18342: }
18343: my $now = time;
18344: my $timefilter =
18345: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18346: my ($createdbefore,$createdafter);
18347: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18348: $createdbefore = $now;
18349: $createdafter = $now-$filter->{'createdfilter'};
18350: }
18351: my ($instcodefilter,$regexpok);
18352: if ($numtitles) {
18353: if ($env{'form.official'} eq 'on') {
18354: $instcodefilter =
18355: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18356: $regexpok = 1;
18357: } elsif ($env{'form.official'} eq 'off') {
18358: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18359: unless ($instcodefilter eq '') {
18360: $regexpok = -1;
18361: }
18362: }
18363: } else {
18364: $instcodefilter = $filter->{'instcodefilter'};
18365: }
18366: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18367: if ($type eq '') { $type = '.'; }
18368:
18369: if (($clonerudom ne '') && ($cloneruname ne '')) {
18370: $cloner = $cloneruname.':'.$clonerudom;
18371: }
18372: %courses = &Apache::lonnet::courseiddump($dom,
18373: $filter->{'descriptfilter'},
18374: $timefilter,
18375: $instcodefilter,
18376: $filter->{'combownerfilter'},
18377: $filter->{'coursefilter'},
18378: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18379: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18380: $filter->{'cloneableonly'},
18381: $createdbefore,$createdafter,undef,
1.1221 raeburn 18382: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18383: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18384: my $ccrole;
18385: if ($type eq 'Community') {
18386: $ccrole = 'co';
18387: } else {
18388: $ccrole = 'cc';
18389: }
18390: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18391: $filter->{'persondomfilter'},
18392: 'userroles',undef,
18393: [$ccrole,'in','ad','ep','ta','cr'],
18394: $dom);
18395: foreach my $role (keys(%rolehash)) {
18396: my ($cnum,$cdom,$courserole) = split(':',$role);
18397: my $cid = $cdom.'_'.$cnum;
18398: if (exists($courses{$cid})) {
18399: if (ref($courses{$cid}) eq 'HASH') {
18400: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18401: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18402: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18403: }
18404: } else {
18405: $courses{$cid}{roles} = [$courserole];
18406: }
18407: $showcourses{$cid} = $courses{$cid};
18408: }
18409: }
18410: }
18411: %courses = %showcourses;
18412: }
18413: return %courses;
18414: }
18415:
18416: =pod
18417:
1.1181 raeburn 18418: =back
18419:
1.1207 raeburn 18420: =head1 Routines for version requirements for current course.
18421:
18422: =over 4
18423:
18424: =item * &check_release_required()
18425:
18426: Compares required LON-CAPA version with version on server, and
18427: if required version is newer looks for a server with the required version.
18428:
18429: Looks first at servers in user's owen domain; if none suitable, looks at
18430: servers in course's domain are permitted to host sessions for user's domain.
18431:
18432: Inputs:
18433:
18434: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18435:
18436: $courseid - Course ID of current course
18437:
18438: $rolecode - User's current role in course (for switchserver query string).
18439:
18440: $required - LON-CAPA version needed by course (format: Major.Minor).
18441:
18442:
18443: Returns:
18444:
18445: $switchserver - query string tp append to /adm/switchserver call (if
18446: current server's LON-CAPA version is too old.
18447:
18448: $warning - Message is displayed if no suitable server could be found.
18449:
18450: =cut
18451:
18452: sub check_release_required {
18453: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18454: my ($switchserver,$warning);
18455: if ($required ne '') {
18456: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18457: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18458: if ($reqdmajor ne '' && $reqdminor ne '') {
18459: my $otherserver;
18460: if (($major eq '' && $minor eq '') ||
18461: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18462: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18463: my $switchlcrev =
18464: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18465: $userdomserver);
18466: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18467: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18468: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18469: my $cdom = $env{'course.'.$courseid.'.domain'};
18470: if ($cdom ne $env{'user.domain'}) {
18471: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18472: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18473: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18474: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18475: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18476: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18477: my $canhost =
18478: &Apache::lonnet::can_host_session($env{'user.domain'},
18479: $coursedomserver,
18480: $remoterev,
18481: $udomdefaults{'remotesessions'},
18482: $defdomdefaults{'hostedsessions'});
18483:
18484: if ($canhost) {
18485: $otherserver = $coursedomserver;
18486: } else {
18487: $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.");
18488: }
18489: } else {
18490: $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).");
18491: }
18492: } else {
18493: $otherserver = $userdomserver;
18494: }
18495: }
18496: if ($otherserver ne '') {
18497: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18498: }
18499: }
18500: }
18501: return ($switchserver,$warning);
18502: }
18503:
18504: =pod
18505:
18506: =item * &check_release_result()
18507:
18508: Inputs:
18509:
18510: $switchwarning - Warning message if no suitable server found to host session.
18511:
18512: $switchserver - query string to append to /adm/switchserver containing lonHostID
18513: and current role.
18514:
18515: Returns: HTML to display with information about requirement to switch server.
18516: Either displaying warning with link to Roles/Courses screen or
18517: display link to switchserver.
18518:
1.1181 raeburn 18519: =cut
18520:
1.1207 raeburn 18521: sub check_release_result {
18522: my ($switchwarning,$switchserver) = @_;
18523: my $output = &start_page('Selected course unavailable on this server').
18524: '<p class="LC_warning">';
18525: if ($switchwarning) {
18526: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18527: if (&show_course()) {
18528: $output .= &mt('Display courses');
18529: } else {
18530: $output .= &mt('Display roles');
18531: }
18532: $output .= '</a>';
18533: } elsif ($switchserver) {
18534: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18535: '<br />'.
18536: '<a href="/adm/switchserver?'.$switchserver.'">'.
18537: &mt('Switch Server').
18538: '</a>';
18539: }
18540: $output .= '</p>'.&end_page();
18541: return $output;
18542: }
18543:
18544: =pod
18545:
18546: =item * &needs_coursereinit()
18547:
18548: Determine if course contents stored for user's session needs to be
18549: refreshed, because content has changed since "Big Hash" last tied.
18550:
18551: Check for change is made if time last checked is more than 10 minutes ago
18552: (by default).
18553:
18554: Inputs:
18555:
18556: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18557:
18558: $interval (optional) - Time which may elapse (in s) between last check for content
18559: change in current course. (default: 600 s).
18560:
18561: Returns: an array; first element is:
18562:
18563: =over 4
18564:
18565: 'switch' - if content updates mean user's session
18566: needs to be switched to a server running a newer LON-CAPA version
18567:
18568: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18569: on current server hosting user's session
18570:
18571: '' - if no action required.
18572:
18573: =back
18574:
18575: If first item element is 'switch':
18576:
18577: second item is $switchwarning - Warning message if no suitable server found to host session.
18578:
18579: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18580: and current role.
18581:
18582: otherwise: no other elements returned.
18583:
18584: =back
18585:
18586: =cut
18587:
18588: sub needs_coursereinit {
18589: my ($loncaparev,$interval) = @_;
18590: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18591: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18592: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18593: my $now = time;
18594: if ($interval eq '') {
18595: $interval = 600;
18596: }
18597: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18598: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18599: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18600: if ($blocked) {
18601: return ();
18602: }
1.1391 raeburn 18603: my $update;
18604: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18605: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18606: if ($lastmainchange > $env{'request.course.tied'}) {
18607: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18608: if ($needswitch) {
18609: return ('switch',$switchwarning,$switchserver);
18610: }
18611: $update = 'main';
18612: }
18613: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18614: if ($update) {
18615: $update = 'both';
18616: } else {
18617: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18618: if ($needswitch) {
18619: return ('switch',$switchwarning,$switchserver);
18620: } else {
18621: $update = 'supp';
1.1207 raeburn 18622: }
18623: }
1.1391 raeburn 18624: return ($update);
18625: }
18626: }
18627: return ();
18628: }
18629:
18630: sub switch_for_update {
18631: my ($loncaparev,$cdom,$cnum) = @_;
18632: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18633: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18634: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18635: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18636: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18637: $curr_reqd_hash{'internal.releaserequired'}});
18638: my ($switchserver,$switchwarning) =
18639: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18640: $curr_reqd_hash{'internal.releaserequired'});
18641: if ($switchwarning ne '' || $switchserver ne '') {
18642: return ('switch',$switchwarning,$switchserver);
18643: }
1.1207 raeburn 18644: }
18645: }
18646: return ();
18647: }
1.1181 raeburn 18648:
1.1083 raeburn 18649: sub update_content_constraints {
1.1395 raeburn 18650: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 18651: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18652: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18653: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18654: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18655: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18656: if ($item eq 'resourcetag') {
18657: if ($name eq 'responsetype') {
18658: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18659: }
1.1307 raeburn 18660: } elsif ($item eq 'course') {
18661: if ($name eq 'courserestype') {
18662: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18663: }
1.1083 raeburn 18664: }
18665: }
18666: my $navmap = Apache::lonnavmaps::navmap->new();
18667: if (defined($navmap)) {
1.1307 raeburn 18668: my (%allresponses,%allcrsrestypes);
18669: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18670: if ($res->is_tool()) {
18671: if ($allcrsrestypes{'exttool'}) {
18672: $allcrsrestypes{'exttool'} ++;
18673: } else {
18674: $allcrsrestypes{'exttool'} = 1;
18675: }
18676: next;
18677: }
1.1083 raeburn 18678: my %responses = $res->responseTypes();
18679: foreach my $key (keys(%responses)) {
18680: next unless(exists($checkresponsetypes{$key}));
18681: $allresponses{$key} += $responses{$key};
18682: }
18683: }
18684: foreach my $key (keys(%allresponses)) {
18685: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18686: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18687: ($reqdmajor,$reqdminor) = ($major,$minor);
18688: }
18689: }
1.1307 raeburn 18690: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18691: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18692: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18693: ($reqdmajor,$reqdminor) = ($major,$minor);
18694: }
18695: }
1.1083 raeburn 18696: undef($navmap);
18697: }
1.1391 raeburn 18698: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 18699: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18700: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18701: ($reqdmajor,$reqdminor) = ($major,$minor);
18702: }
18703: }
1.1083 raeburn 18704: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18705: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18706: }
18707: return;
18708: }
18709:
1.1110 raeburn 18710: sub allmaps_incourse {
18711: my ($cdom,$cnum,$chome,$cid) = @_;
18712: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18713: $cid = $env{'request.course.id'};
18714: $cdom = $env{'course.'.$cid.'.domain'};
18715: $cnum = $env{'course.'.$cid.'.num'};
18716: $chome = $env{'course.'.$cid.'.home'};
18717: }
18718: my %allmaps = ();
18719: my $lastchange =
18720: &Apache::lonnet::get_coursechange($cdom,$cnum);
18721: if ($lastchange > $env{'request.course.tied'}) {
18722: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18723: unless ($ferr) {
1.1395 raeburn 18724: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 18725: }
18726: }
18727: my $navmap = Apache::lonnavmaps::navmap->new();
18728: if (defined($navmap)) {
18729: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18730: $allmaps{$res->src()} = 1;
18731: }
18732: }
18733: return \%allmaps;
18734: }
18735:
1.1083 raeburn 18736: sub parse_supplemental_title {
18737: my ($title) = @_;
18738:
18739: my ($foldertitle,$renametitle);
18740: if ($title =~ /&&&/) {
18741: $title = &HTML::Entites::decode($title);
18742: }
18743: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18744: $renametitle=$4;
18745: my ($time,$uname,$udom) = ($1,$2,$3);
18746: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18747: my $name = &plainname($uname,$udom);
18748: $name = &HTML::Entities::encode($name,'"<>&\'');
18749: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 18750: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 18751: if ($foldertitle ne '') {
1.1401 raeburn 18752: $title .= ': <br />'.$foldertitle;
18753: }
1.1083 raeburn 18754: }
18755: if (wantarray) {
18756: return ($title,$foldertitle,$renametitle);
18757: }
18758: return $title;
18759: }
18760:
1.1395 raeburn 18761: sub get_supplemental {
18762: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18763: my $hashid=$cnum.':'.$cdom;
18764: my ($supplemental,$cached,$set_httprefs);
18765: unless ($ignorecache) {
18766: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18767: }
18768: unless (defined($cached)) {
18769: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18770: unless ($chome eq 'no_host') {
18771: my @order = @LONCAPA::map::order;
18772: my @resources = @LONCAPA::map::resources;
18773: my @resparms = @LONCAPA::map::resparms;
18774: my @zombies = @LONCAPA::map::zombies;
18775: my ($errors,%ids,%hidden);
18776: $errors =
18777: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18778: $errors,$possdel,\%ids,\%hidden);
18779: @LONCAPA::map::order = @order;
18780: @LONCAPA::map::resources = @resources;
18781: @LONCAPA::map::resparms = @resparms;
18782: @LONCAPA::map::zombies = @zombies;
18783: $set_httprefs = 1;
18784: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18785: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18786: }
18787: $supplemental = {
18788: ids => \%ids,
18789: hidden => \%hidden,
18790: };
18791: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18792: }
18793: }
18794: return ($supplemental,$set_httprefs);
18795: }
18796:
1.1143 raeburn 18797: sub recurse_supplemental {
1.1391 raeburn 18798: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18799: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18800: my $mapnum;
18801: if ($suppmap eq 'supplemental.sequence') {
18802: $mapnum = 0;
18803: } else {
18804: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18805: }
1.1143 raeburn 18806: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18807: if ($fatal) {
18808: $errors ++;
18809: } else {
1.1389 raeburn 18810: my @order = @LONCAPA::map::order;
18811: if (@order > 0) {
18812: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 18813: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 18814: foreach my $idx (@order) {
18815: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 18816: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 18817: my $id = $mapnum.':'.$idx;
18818: push(@{$suppids->{$src}},$id);
18819: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18820: $hiddensupp->{$id} = 1;
18821: }
1.1146 raeburn 18822: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 18823: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18824: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 18825: } else {
1.1391 raeburn 18826: my $allowed;
18827: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18828: $allowed = 1;
18829: } elsif ($possdel) {
18830: foreach my $item (@{$suppids->{$src}}) {
18831: next if ($item eq $id);
18832: unless ($hiddensupp->{$item}) {
18833: $allowed = 1;
18834: last;
18835: }
18836: }
18837: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18838: &Apache::lonnet::delenv('httpref.'.$src);
18839: }
18840: }
18841: if ($allowed && (!exists($env{'httpref.'.$src}))) {
18842: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 18843: }
1.1143 raeburn 18844: }
18845: }
18846: }
18847: }
18848: }
18849: }
1.1391 raeburn 18850: return $errors;
18851: }
18852:
18853: sub set_supp_httprefs {
18854: my ($cnum,$cdom,$supplemental,$possdel) = @_;
18855: if (ref($supplemental) eq 'HASH') {
18856: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18857: foreach my $src (keys(%{$supplemental->{'ids'}})) {
18858: next if ($src =~ /\.sequence$/);
18859: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18860: my $allowed;
18861: if ($env{'request.role.adv'}) {
18862: $allowed = 1;
18863: } else {
18864: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18865: unless ($supplemental->{'hidden'}->{$id}) {
18866: $allowed = 1;
18867: last;
18868: }
18869: }
18870: }
18871: if (exists($env{'httpref.'.$src})) {
18872: if ($possdel) {
18873: unless ($allowed) {
18874: &Apache::lonnet::delenv('httpref.'.$src);
18875: }
18876: }
18877: } elsif ($allowed) {
18878: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18879: }
18880: }
18881: }
18882: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18883: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18884: }
18885: }
18886: }
18887: }
18888:
18889: sub get_supp_parameter {
18890: my ($resparm,$name)=@_;
18891: return if ($resparm eq '');
18892: my $value=undef;
18893: my $ptype=undef;
18894: foreach (split('&&&',$resparm)) {
18895: my ($thistype,$thisname,$thisvalue)=split('___',$_);
18896: if ($thisname eq $name) {
18897: $value=$thisvalue;
18898: $ptype=$thistype;
18899: }
18900: }
18901: return $value;
1.1143 raeburn 18902: }
18903:
1.1101 raeburn 18904: sub symb_to_docspath {
1.1267 raeburn 18905: my ($symb,$navmapref) = @_;
18906: return unless ($symb && ref($navmapref));
1.1101 raeburn 18907: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18908: if ($resurl=~/\.(sequence|page)$/) {
18909: $mapurl=$resurl;
18910: } elsif ($resurl eq 'adm/navmaps') {
18911: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18912: }
18913: my $mapresobj;
1.1267 raeburn 18914: unless (ref($$navmapref)) {
18915: $$navmapref = Apache::lonnavmaps::navmap->new();
18916: }
18917: if (ref($$navmapref)) {
18918: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18919: }
18920: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18921: my $type=$2;
18922: my $path;
18923: if (ref($mapresobj)) {
18924: my $pcslist = $mapresobj->map_hierarchy();
18925: if ($pcslist ne '') {
18926: foreach my $pc (split(/,/,$pcslist)) {
18927: next if ($pc <= 1);
1.1267 raeburn 18928: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18929: if (ref($res)) {
18930: my $thisurl = $res->src();
18931: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18932: my $thistitle = $res->title();
18933: $path .= '&'.
18934: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18935: &escape($thistitle).
1.1101 raeburn 18936: ':'.$res->randompick().
18937: ':'.$res->randomout().
18938: ':'.$res->encrypted().
18939: ':'.$res->randomorder().
18940: ':'.$res->is_page();
18941: }
18942: }
18943: }
18944: $path =~ s/^\&//;
18945: my $maptitle = $mapresobj->title();
18946: if ($mapurl eq 'default') {
1.1129 raeburn 18947: $maptitle = 'Main Content';
1.1101 raeburn 18948: }
18949: $path .= (($path ne '')? '&' : '').
18950: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18951: &escape($maptitle).
1.1101 raeburn 18952: ':'.$mapresobj->randompick().
18953: ':'.$mapresobj->randomout().
18954: ':'.$mapresobj->encrypted().
18955: ':'.$mapresobj->randomorder().
18956: ':'.$mapresobj->is_page();
18957: } else {
18958: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18959: my $ispage = (($type eq 'page')? 1 : '');
18960: if ($mapurl eq 'default') {
1.1129 raeburn 18961: $maptitle = 'Main Content';
1.1101 raeburn 18962: }
18963: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18964: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18965: }
18966: unless ($mapurl eq 'default') {
18967: $path = 'default&'.
1.1146 raeburn 18968: &escape('Main Content').
1.1101 raeburn 18969: ':::::&'.$path;
18970: }
18971: return $path;
18972: }
18973:
1.1393 raeburn 18974: sub validate_folderpath {
18975: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18976: if ($env{'form.folderpath'} ne '') {
18977: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 18978: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 18979: for (my $i=0; $i<@items; $i++) {
18980: my $odd = $i%2;
18981: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18982: $badpath = 1;
1.1394 raeburn 18983: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 18984: my $idx = $i-1;
1.1394 raeburn 18985: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18986: my $esc_name = $1;
18987: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18988: $supppath .= '&'.$esc_name;
18989: $changed = 1;
18990: } else {
18991: $supppath .= '&'.$items[$i];
18992: }
18993: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18994: $changed = 1;
1.1393 raeburn 18995: my $is_hidden;
18996: unless ($got_supp) {
1.1395 raeburn 18997: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 18998: if (ref($supplemental) eq 'HASH') {
18999: if (ref($supplemental->{'hidden'}) eq 'HASH') {
19000: %supphidden = %{$supplemental->{'hidden'}};
19001: }
19002: if (ref($supplemental->{'ids'}) eq 'HASH') {
19003: %suppids = %{$supplemental->{'ids'}};
19004: }
19005: }
19006: $got_supp = 1;
19007: }
19008: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
19009: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
19010: if ($supphidden{$mapid}) {
19011: $is_hidden = 1;
19012: }
19013: }
1.1394 raeburn 19014: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
19015: } else {
19016: $supppath .= '&'.$items[$i];
1.1393 raeburn 19017: }
19018: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
19019: $badpath = 1;
1.1394 raeburn 19020: } elsif ($supplementalflag) {
1.1393 raeburn 19021: $supppath .= '&'.$items[$i];
19022: }
19023: last if ($badpath);
19024: }
19025: if ($badpath) {
19026: delete($env{'form.folderpath'});
1.1394 raeburn 19027: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 19028: $supppath =~ s/^\&//;
19029: $env{'form.folderpath'} = $supppath;
19030: }
19031: }
19032: return;
19033: }
19034:
1.1094 raeburn 19035: sub captcha_display {
1.1327 raeburn 19036: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19037: my ($output,$error);
1.1234 raeburn 19038: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 19039: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19040: if ($captcha eq 'original') {
1.1094 raeburn 19041: $output = &create_captcha();
19042: unless ($output) {
1.1172 raeburn 19043: $error = 'captcha';
1.1094 raeburn 19044: }
19045: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19046: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 19047: unless ($output) {
1.1172 raeburn 19048: $error = 'recaptcha';
1.1094 raeburn 19049: }
19050: }
1.1234 raeburn 19051: return ($output,$error,$captcha,$version);
1.1094 raeburn 19052: }
19053:
19054: sub captcha_response {
1.1327 raeburn 19055: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19056: my ($captcha_chk,$captcha_error);
1.1327 raeburn 19057: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19058: if ($captcha eq 'original') {
1.1094 raeburn 19059: ($captcha_chk,$captcha_error) = &check_captcha();
19060: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19061: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 19062: } else {
19063: $captcha_chk = 1;
19064: }
19065: return ($captcha_chk,$captcha_error);
19066: }
19067:
19068: sub get_captcha_config {
1.1327 raeburn 19069: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 19070: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 19071: my $hostname = &Apache::lonnet::hostname($lonhost);
19072: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
19073: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 19074: if ($context eq 'usercreation') {
19075: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
19076: if (ref($domconfig{$context}) eq 'HASH') {
19077: $hashtocheck = $domconfig{$context}{'cancreate'};
19078: if (ref($hashtocheck) eq 'HASH') {
19079: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
19080: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
19081: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
19082: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
19083: }
19084: if ($privkey && $pubkey) {
19085: $captcha = 'recaptcha';
1.1234 raeburn 19086: $version = $hashtocheck->{'recaptchaversion'};
19087: if ($version ne '2') {
19088: $version = 1;
19089: }
1.1095 raeburn 19090: } else {
19091: $captcha = 'original';
19092: }
19093: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19094: $captcha = 'original';
19095: }
1.1094 raeburn 19096: }
1.1095 raeburn 19097: } else {
19098: $captcha = 'captcha';
19099: }
19100: } elsif ($context eq 'login') {
19101: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19102: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19103: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19104: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19105: if ($privkey && $pubkey) {
19106: $captcha = 'recaptcha';
1.1234 raeburn 19107: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19108: if ($version ne '2') {
19109: $version = 1;
19110: }
1.1095 raeburn 19111: } else {
19112: $captcha = 'original';
1.1094 raeburn 19113: }
1.1095 raeburn 19114: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19115: $captcha = 'original';
1.1094 raeburn 19116: }
1.1327 raeburn 19117: } elsif ($context eq 'passwords') {
19118: if ($dom_in_effect) {
19119: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19120: if ($passwdconf{'captcha'} eq 'recaptcha') {
19121: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19122: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19123: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19124: }
19125: if ($privkey && $pubkey) {
19126: $captcha = 'recaptcha';
19127: $version = $passwdconf{'recaptchaversion'};
19128: if ($version ne '2') {
19129: $version = 1;
19130: }
19131: } else {
19132: $captcha = 'original';
19133: }
19134: } elsif ($passwdconf{'captcha'} ne 'notused') {
19135: $captcha = 'original';
19136: }
19137: }
19138: }
1.1234 raeburn 19139: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19140: }
19141:
19142: sub create_captcha {
19143: my %captcha_params = &captcha_settings();
19144: my ($output,$maxtries,$tries) = ('',10,0);
19145: while ($tries < $maxtries) {
19146: $tries ++;
19147: my $captcha = Authen::Captcha->new (
19148: output_folder => $captcha_params{'output_dir'},
19149: data_folder => $captcha_params{'db_dir'},
19150: );
19151: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19152:
19153: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19154: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19155: '<span class="LC_nobreak">'.
1.1094 raeburn 19156: &mt('Type in the letters/numbers shown below').' '.
1.1390 raeburn 19157: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1367 raeburn 19158: '</span><br />'.
1.1176 raeburn 19159: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19160: last;
19161: }
19162: }
1.1323 raeburn 19163: if ($output eq '') {
19164: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19165: }
1.1094 raeburn 19166: return $output;
19167: }
19168:
19169: sub captcha_settings {
19170: my %captcha_params = (
19171: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19172: www_output_dir => "/captchaspool",
19173: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19174: numchars => '5',
19175: );
19176: return %captcha_params;
19177: }
19178:
19179: sub check_captcha {
19180: my ($captcha_chk,$captcha_error);
19181: my $code = $env{'form.code'};
19182: my $md5sum = $env{'form.crypt'};
19183: my %captcha_params = &captcha_settings();
19184: my $captcha = Authen::Captcha->new(
19185: output_folder => $captcha_params{'output_dir'},
19186: data_folder => $captcha_params{'db_dir'},
19187: );
1.1109 raeburn 19188: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19189: my %captcha_hash = (
19190: 0 => 'Code not checked (file error)',
19191: -1 => 'Failed: code expired',
19192: -2 => 'Failed: invalid code (not in database)',
19193: -3 => 'Failed: invalid code (code does not match crypt)',
19194: );
19195: if ($captcha_chk != 1) {
19196: $captcha_error = $captcha_hash{$captcha_chk}
19197: }
19198: return ($captcha_chk,$captcha_error);
19199: }
19200:
19201: sub create_recaptcha {
1.1234 raeburn 19202: my ($pubkey,$version) = @_;
19203: if ($version >= 2) {
1.1367 raeburn 19204: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19205: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19206: } else {
19207: my $use_ssl;
19208: if ($ENV{'SERVER_PORT'} == 443) {
19209: $use_ssl = 1;
19210: }
19211: my $captcha = Captcha::reCAPTCHA->new;
19212: return $captcha->get_options_setter({theme => 'white'})."\n".
19213: $captcha->get_html($pubkey,undef,$use_ssl).
19214: &mt('If the text is hard to read, [_1] will replace them.',
19215: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19216: '<br /><br />';
19217: }
1.1094 raeburn 19218: }
19219:
19220: sub check_recaptcha {
1.1234 raeburn 19221: my ($privkey,$version) = @_;
1.1094 raeburn 19222: my $captcha_chk;
1.1350 raeburn 19223: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19224: if ($version >= 2) {
19225: my %info = (
19226: secret => $privkey,
19227: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19228: remoteip => $ip,
1.1234 raeburn 19229: );
1.1280 raeburn 19230: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19231: $request->content(join('&',map {
19232: my $name = escape($_);
19233: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19234: ? join("&$name=", map {escape($_) } @{$info{$_}})
19235: : &escape($info{$_}) );
19236: } keys(%info)));
19237: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19238: if ($response->is_success) {
19239: my $data = JSON::DWIW->from_json($response->decoded_content);
19240: if (ref($data) eq 'HASH') {
19241: if ($data->{'success'}) {
19242: $captcha_chk = 1;
19243: }
19244: }
19245: }
19246: } else {
19247: my $captcha = Captcha::reCAPTCHA->new;
19248: my $captcha_result =
19249: $captcha->check_answer(
19250: $privkey,
1.1350 raeburn 19251: $ip,
1.1234 raeburn 19252: $env{'form.recaptcha_challenge_field'},
19253: $env{'form.recaptcha_response_field'},
19254: );
19255: if ($captcha_result->{is_valid}) {
19256: $captcha_chk = 1;
19257: }
1.1094 raeburn 19258: }
19259: return $captcha_chk;
19260: }
19261:
1.1174 raeburn 19262: sub emailusername_info {
1.1244 raeburn 19263: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19264: my %titles = &Apache::lonlocal::texthash (
19265: lastname => 'Last Name',
19266: firstname => 'First Name',
19267: institution => 'School/college/university',
19268: location => "School's city, state/province, country",
19269: web => "School's web address",
19270: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19271: id => 'Student/Employee ID',
1.1174 raeburn 19272: );
19273: return (\@fields,\%titles);
19274: }
19275:
1.1161 raeburn 19276: sub cleanup_html {
19277: my ($incoming) = @_;
19278: my $outgoing;
19279: if ($incoming ne '') {
19280: $outgoing = $incoming;
19281: $outgoing =~ s/;/;/g;
19282: $outgoing =~ s/\#/#/g;
19283: $outgoing =~ s/\&/&/g;
19284: $outgoing =~ s/</</g;
19285: $outgoing =~ s/>/>/g;
19286: $outgoing =~ s/\(/(/g;
19287: $outgoing =~ s/\)/)/g;
19288: $outgoing =~ s/"/"/g;
19289: $outgoing =~ s/'/'/g;
19290: $outgoing =~ s/\$/$/g;
19291: $outgoing =~ s{/}{/}g;
19292: $outgoing =~ s/=/=/g;
19293: $outgoing =~ s/\\/\/g
19294: }
19295: return $outgoing;
19296: }
19297:
1.1190 musolffc 19298: # Checks for critical messages and returns a redirect url if one exists.
19299: # $interval indicates how often to check for messages.
1.1282 raeburn 19300: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19301: sub critical_redirect {
1.1282 raeburn 19302: my ($interval,$context) = @_;
1.1356 raeburn 19303: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19304: return ();
19305: }
1.1190 musolffc 19306: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19307: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19308: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19309: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19310: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19311: if ($blocked) {
19312: my $checkrole = "cm./$cdom/$cnum";
19313: if ($env{'request.course.sec'} ne '') {
19314: $checkrole .= "/$env{'request.course.sec'}";
19315: }
19316: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19317: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19318: return;
19319: }
19320: }
19321: }
1.1190 musolffc 19322: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19323: $env{'user.name'});
19324: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19325: my $redirecturl;
1.1190 musolffc 19326: if ($what[0]) {
1.1356 raeburn 19327: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19328: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19329: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19330: return (1, $url);
1.1190 musolffc 19331: }
1.1191 raeburn 19332: }
19333: }
19334: return ();
1.1190 musolffc 19335: }
19336:
1.1174 raeburn 19337: # Use:
19338: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19339: #
19340: ##################################################
19341: # password associated functions #
19342: ##################################################
19343: sub des_keys {
19344: # Make a new key for DES encryption.
19345: # Each key has two parts which are returned separately.
19346: # Please note: Each key must be passed through the &hex function
19347: # before it is output to the web browser. The hex versions cannot
19348: # be used to decrypt.
19349: my @hexstr=('0','1','2','3','4','5','6','7',
19350: '8','9','a','b','c','d','e','f');
19351: my $lkey='';
19352: for (0..7) {
19353: $lkey.=$hexstr[rand(15)];
19354: }
19355: my $ukey='';
19356: for (0..7) {
19357: $ukey.=$hexstr[rand(15)];
19358: }
19359: return ($lkey,$ukey);
19360: }
19361:
19362: sub des_decrypt {
19363: my ($key,$cyphertext) = @_;
19364: my $keybin=pack("H16",$key);
19365: my $cypher;
19366: if ($Crypt::DES::VERSION>=2.03) {
19367: $cypher=new Crypt::DES $keybin;
19368: } else {
19369: $cypher=new DES $keybin;
19370: }
1.1233 raeburn 19371: my $plaintext='';
19372: my $cypherlength = length($cyphertext);
19373: my $numchunks = int($cypherlength/32);
19374: for (my $j=0; $j<$numchunks; $j++) {
19375: my $start = $j*32;
19376: my $cypherblock = substr($cyphertext,$start,32);
19377: my $chunk =
19378: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19379: $chunk .=
19380: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19381: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19382: $plaintext .= $chunk;
19383: }
1.1174 raeburn 19384: return $plaintext;
19385: }
19386:
1.1344 raeburn 19387: sub get_requested_shorturls {
1.1309 raeburn 19388: my ($cdom,$cnum,$navmap) = @_;
19389: return unless (ref($navmap));
1.1344 raeburn 19390: my ($numnew,$errors);
1.1309 raeburn 19391: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19392: if (@toshorten) {
19393: my (%maps,%resources,%titles);
19394: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19395: 'shorturls',$cdom,$cnum);
19396: if (keys(%resources)) {
1.1344 raeburn 19397: my %tocreate;
1.1309 raeburn 19398: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19399: my $symb = $resources{$item};
19400: if ($symb) {
19401: $tocreate{$cnum.'&'.$symb} = 1;
19402: }
19403: }
1.1344 raeburn 19404: if (keys(%tocreate)) {
19405: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19406: \%tocreate);
19407: }
1.1309 raeburn 19408: }
1.1344 raeburn 19409: }
19410: return ($numnew,$errors);
19411: }
19412:
19413: sub make_short_symbs {
19414: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19415: my ($numnew,@errors);
19416: if (ref($tocreateref) eq 'HASH') {
19417: my %tocreate = %{$tocreateref};
1.1309 raeburn 19418: if (keys(%tocreate)) {
19419: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19420: my $su = Short::URL->new(no_vowels => 1);
19421: my $init = '';
19422: my (%newunique,%addcourse,%courseonly,%failed);
19423: # get lock on tiny db
19424: my $now = time;
1.1344 raeburn 19425: if ($lockuser eq '') {
19426: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
19427: }
1.1309 raeburn 19428: my $lockhash = {
1.1344 raeburn 19429: "lock\0$now" => $lockuser,
1.1309 raeburn 19430: };
19431: my $tries = 0;
19432: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19433: my ($code,$error);
19434: while (($gotlock ne 'ok') && ($tries<3)) {
19435: $tries ++;
19436: sleep 1;
1.1319 raeburn 19437: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 19438: }
19439: if ($gotlock eq 'ok') {
19440: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19441: \%addcourse,\%courseonly,\%failed);
19442: if (keys(%failed)) {
19443: my $numfailed = scalar(keys(%failed));
19444: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19445: }
19446: if (keys(%newunique)) {
19447: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19448: if ($putres eq 'ok') {
19449: $numnew = scalar(keys(%newunique));
19450: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19451: unless ($newputres eq 'ok') {
19452: push(@errors,&mt('error: could not store course look-up of short URLs'));
19453: }
19454: } else {
19455: push(@errors,&mt('error: could not store unique six character URLs'));
19456: }
19457: }
19458: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19459: unless ($dellockres eq 'ok') {
19460: push(@errors,&mt('error: could not release lockfile'));
19461: }
19462: } else {
19463: push(@errors,&mt('error: could not obtain lockfile'));
19464: }
19465: if (keys(%courseonly)) {
19466: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19467: if ($result ne 'ok') {
19468: push(@errors,&mt('error: could not update course look-up of short URLs'));
19469: }
19470: }
19471: }
19472: }
19473: return ($numnew,\@errors);
19474: }
19475:
19476: sub shorten_symbs {
19477: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19478: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19479: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19480: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19481: my (%possibles,%collisions);
19482: foreach my $key (keys(%{$tocreate})) {
19483: my $num = String::CRC32::crc32($key);
19484: my $tiny = $su->encode($num,$init);
19485: if ($tiny) {
19486: $possibles{$tiny} = $key;
19487: }
19488: }
19489: if (!$init) {
19490: $init = 1;
19491: } else {
19492: $init ++;
19493: }
19494: if (keys(%possibles)) {
19495: my @posstiny = keys(%possibles);
19496: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19497: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19498: if (keys(%currtiny)) {
19499: foreach my $key (keys(%currtiny)) {
19500: next if ($currtiny{$key} eq '');
19501: if ($currtiny{$key} eq $possibles{$key}) {
19502: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19503: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19504: $courseonly->{$tsymb} = $key;
19505: }
19506: } else {
19507: $collisions{$possibles{$key}} = 1;
19508: }
19509: delete($possibles{$key});
19510: }
19511: }
19512: foreach my $key (keys(%possibles)) {
19513: $newunique->{$key} = $possibles{$key};
19514: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19515: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19516: $addcourse->{$tsymb} = $key;
19517: }
19518: }
19519: }
19520: if (keys(%collisions)) {
19521: if ($init <5) {
19522: if (!$init) {
19523: $init = 1;
19524: } else {
19525: $init ++;
19526: }
19527: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19528: $newunique,$addcourse,$courseonly,$failed);
19529: } else {
19530: foreach my $key (keys(%collisions)) {
19531: $failed->{$key} = 1;
19532: }
19533: }
19534: }
19535: return $init;
19536: }
19537:
1.1328 raeburn 19538: sub is_nonframeable {
1.1329 raeburn 19539: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19540: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 19541: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 19542:
19543: $remprotocol = lc($remprotocol);
19544: $remhost = lc($remhost);
19545: my $remport = 80;
19546: if ($remprotocol eq 'https') {
19547: $remport = 443;
19548: }
1.1330 raeburn 19549: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 19550: if ($cached) {
19551: unless ($nocache) {
19552: if ($result) {
19553: return 1;
19554: } else {
19555: return 0;
19556: }
19557: }
19558: }
1.1328 raeburn 19559: my $uselink;
19560: my $request = new HTTP::Request('HEAD',$url);
19561: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
19562: if ($response->is_success()) {
19563: my $secpolicy = lc($response->header('content-security-policy'));
19564: my $xframeop = lc($response->header('x-frame-options'));
19565: $secpolicy =~ s/^\s+|\s+$//g;
19566: $xframeop =~ s/^\s+|\s+$//g;
19567: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 19568: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 19569: my ($origin,$protocol,$port);
19570: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19571: $port = $ENV{'SERVER_PORT'};
19572: } else {
19573: $port = 80;
19574: }
19575: if ($absolute eq '') {
19576: $protocol = 'http:';
19577: if ($port == 443) {
19578: $protocol = 'https:';
19579: }
19580: $origin = $protocol.'//'.lc($hostname);
19581: } else {
19582: $origin = lc($absolute);
19583: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19584: }
19585: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19586: my $framepolicy = $1;
19587: $framepolicy =~ s/^\s+|\s+$//g;
19588: my @policies = split(/\s+/,$framepolicy);
19589: if (@policies) {
19590: if (grep(/^\Q'none'\E$/,@policies)) {
19591: $uselink = 1;
19592: } else {
19593: $uselink = 1;
19594: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19595: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19596: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19597: undef($uselink);
19598: }
19599: if ($uselink) {
19600: if (grep(/^\Q'self'\E$/,@policies)) {
19601: if (($origin ne '') && ($remotehost eq $origin)) {
19602: undef($uselink);
19603: }
19604: }
19605: }
19606: if ($uselink) {
19607: my @possok;
19608: if ($ip ne '') {
19609: push(@possok,$ip);
19610: }
19611: my $hoststr = '';
19612: foreach my $part (reverse(split(/\./,$hostname))) {
19613: if ($hoststr eq '') {
19614: $hoststr = $part;
19615: } else {
19616: $hoststr = "$part.$hoststr";
19617: }
19618: if ($hoststr eq $hostname) {
19619: push(@possok,$hostname);
19620: } else {
19621: push(@possok,"*.$hoststr");
19622: }
19623: }
19624: if (@possok) {
19625: foreach my $poss (@possok) {
19626: last if (!$uselink);
19627: foreach my $policy (@policies) {
19628: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19629: undef($uselink);
19630: last;
19631: }
19632: }
19633: }
19634: }
19635: }
19636: }
19637: }
19638: } elsif ($xframeop ne '') {
19639: $uselink = 1;
19640: my @policies = split(/\s*,\s*/,$xframeop);
19641: if (@policies) {
19642: unless (grep(/^deny$/,@policies)) {
19643: if ($origin ne '') {
19644: if (grep(/^sameorigin$/,@policies)) {
19645: if ($remotehost eq $origin) {
19646: undef($uselink);
19647: }
19648: }
19649: if ($uselink) {
19650: foreach my $policy (@policies) {
19651: if ($policy =~ /^allow-from\s*(.+)$/) {
19652: my $allowfrom = $1;
19653: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19654: undef($uselink);
19655: last;
19656: }
19657: }
19658: }
19659: }
19660: }
19661: }
19662: }
19663: }
19664: }
19665: }
1.1329 raeburn 19666: if ($nocache) {
19667: if ($cached) {
19668: my $devalidate;
19669: if ($uselink && !$result) {
19670: $devalidate = 1;
19671: } elsif (!$uselink && $result) {
19672: $devalidate = 1;
19673: }
19674: if ($devalidate) {
19675: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19676: }
19677: }
19678: } else {
19679: if ($uselink) {
19680: $result = 1;
19681: } else {
19682: $result = 0;
19683: }
19684: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19685: }
1.1328 raeburn 19686: return $uselink;
19687: }
19688:
1.1359 raeburn 19689: sub page_menu {
19690: my ($menucolls,$menunum) = @_;
19691: my %menu;
19692: foreach my $item (split(/;/,$menucolls)) {
19693: my ($num,$value) = split(/\%/,$item);
19694: if ($num eq $menunum) {
19695: my @entries = split(/\&/,$value);
19696: foreach my $entry (@entries) {
19697: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19698: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19699: $menu{$name} = $fields;
19700: } else {
19701: my @shown;
19702: if ($fields =~ /,/) {
19703: @shown = split(/,/,$fields);
19704: } else {
19705: @shown = ($fields);
19706: }
19707: if (@shown) {
19708: foreach my $field (@shown) {
19709: next if ($field eq '');
19710: $menu{$field} = 1;
19711: }
19712: }
19713: }
19714: }
19715: }
19716: }
19717: return %menu;
19718: }
19719:
1.112 bowersj2 19720: 1;
19721: __END__;
1.41 ng 19722:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>